[petsc-users] DOF in DMDACreate3d and staggered grid

TAY wee-beng zonexo at gmail.com
Sun Jun 17 07:26:52 CDT 2012


On 16/6/2012 9:24 AM, Jed Brown wrote:
>
> It depends how you want to solve the problem. I usually group all dofs 
> together. There is a 2D Stokes+Thermodynamics example in SNES ex30 (or 
> 31?).
>

I tried to understand ex30. I have some questions since it's in C and 
I'm using to Fortran programming.

Supposed I have a field - u,v,w,p, so in order to use them, I do the 
following:
/
type field

real u,v,w,p

end type field

type(field), pointer :: field1(:,:,:)    -> make a derived variable/

Also:
/
Vec field_local,field_global

call DMDACreate3d with dof = 4

call DMCreateGlobalVector(da, field_local,ierr)

call DMCreateLocalVector(da,field_global,ierr)

call DMGetLocalVector(da, field_local,ierr)    ->    To insert values

call DMDAVecGetArrayF90(da, field_local,field1,ierr)

do k = zs, zs + zm - 1

do j = ys, ys + ym -1

     do i = xs, xs + xm - 1

         field1(i,j,k)%u = ...     ->    evaluate u,v,w,p etc

     end do

end do

call DMDAVecRestoreArrayF90(da,field_local,field1,ierr)

call DMLocalToGlobalBegin(da,field_local,INSERT_VALUES,field_global,ierr)

call DMLocalToGlobalEnd(da,field_local,INSERT_VALUES,field_global,ierr)

call DMRestoreLocalVector(da,field_local,ierr)/

Is this the correct way?

Also, supposed I now want to solve my u,v,w momentum eqns. Although 
they're not coupled together, I believe it's faster if I assemble them 
into 1 big matrix.

So for Ax = b, x = 
(field(1,1,1)%u,field(1,1,1)%v,field(1,1,1)%w,field(2,1,1)%u.... )

For b, do I duplicate a Vec similar to field_local?

What about matrix A? Do I use the MatSetValuesStencil?

Lastly, the type field contains u,v,w and p. However, I'm only solving 
u,v,w. Do I have to skip some values or use identity matrix to solve it?

Thanks!



> On Jun 16, 2012 8:11 AM, "TAY wee-beng" <zonexo at gmail.com 
> <mailto:zonexo at gmail.com>> wrote:
>
>     Hi,
>
>     I'm abit unclear about dof used in DMDACreate3d. If I have u,v,w
>     for my CFD code, does it mean that I should have dof = 3? Or can i
>     create 3 local/global vector using DMCreateGlobalVector and
>     DMCreateLocalVector to define u,v,w?
>
>     Does it matter if I'm using staggered grids? Also, if I am only
>     using PETSc for u,v,w (and not pressure, which uses HYPRE), does
>     it mean a difference?
>
>     I remember there 's an example using staggered grid somewhere but
>     I can't find it now. May I know which PETSc 's example it is?
>
>     Thanks!
>
>     -- 
>     Yours sincerely,
>
>     TAY wee-beng
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120617/aae65435/attachment.html>


More information about the petsc-users mailing list