[petsc-users] Question about DMDA local vector and global vector

Danyang Su danyang.su at gmail.com
Tue May 20 13:31:57 CDT 2014


Hi All,

I use DMDA for a flow problem and found the local vector and global 
vector does not match for 2D and 3D problem when dof >1.

For example, the mesh is as follows:

|proc 1|   proc 2 |   proc 3  |
|7  8  9|16 17 18|25 26 27|
|4  5  6|13 14 15|22 23 24|
|1  2  3|10 11 12|19 20 21|

/The following functions are used to create DMDA object, global vector 
and local vector./

call DMDACreate2d(Petsc_Comm_World,DMDA_BOUNDARY_NONE,     &
                      DMDA_BOUNDARY_NONE, DMDA_STENCIL_BOX,             &
nvxgbl,nvzgbl,PETSC_DECIDE,PETSC_DECIDE,          &
                      dmda_flow%dof, dmda_flow%swidth,                  &
PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,            &
                      dmda_flow%da,ierr)
call DMCreateGlobalVector(dmda_flow%da,x_flow,ierr)
call VecDuplicate(x_flow,b_flow,ierr)
call DMCreateLocalVector(dmda_flow%da,x_flow_loc,ierr)
call VecDuplicate(x_flow_loc,b_flow_loc,ierr)

/The following functions are used to compute the function (b_flow_loc)/

call VecGetArrayF90(b_flow_loc, vecpointer, ierr)
vecpointer = (compute the values here...)
call VecRestoreArrayF90(b_flow_loc,vecpointer,ierr)
call DMLocalToGlobalBegin(dmda_flow%,b_flow_loc,INSERT_VALUES, &
                           b_flow,ierr)
call DMLocalToGlobalEnd(dmda_flow%,b_flow_loc,INSERT_VALUES, &
                           b_flow,ierr)


/The data of local vector b_flow_loc for proc1, proc2 and proc3 are as 
follows (just an example, without ghost value)/
proc 1  proc 2   proc 3
   1        10        19
   2        11        20
   3        12        21
   4        13        22
   5        14        23
   6        15        24
   ...      ...       ...

/But the global vector b_flow from Vecview shows that the data is stored 
as follows (left column). I thought the global vector b_flow is like the 
right column. Is anything wrong here?/

Process [0]            Process [0]
1                              1
2                              2
3                              3
10                            4
11                            5
12                            6
...                              ...
Process [1]            Process [1]
4                              10
5                              11
6                              12
13                            13
14                            14
15                            15
...                              ...
Process [2]            Process [2]
...                            ...

Though the data distribution is different from what I thought before, 
the code works well for 1D problem and most of the 2D and 3D problem, 
but failed in newton iteration for some 2D problem with dof > 1. I use 
KSP solver, not SNES solver at present.

Thanks and regards,

Danyang


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20140520/bd4ba9d8/attachment.html>


More information about the petsc-users mailing list