[petsc-users] Multi-DOF DMDA Vec

Barry Smith bsmith at mcs.anl.gov
Fri Jun 13 13:59:08 CDT 2014


On Jun 13, 2014, at 1:43 PM, Jed Brown <jed at jedbrown.org> wrote:

> Anush Krishnan <anush at bu.edu> writes:
> 
>> Hello petsc-users,
>> 
>> I created a vector using DMDACreate with 3 degrees of freedom. Is it
>> possible for me to access each vector corresponding to a degree of freedom?
>> Seeing that I need to access the array as [k][j][i][dof], does it mean that
>> the values of each component are not contiguous?
> 
> The values are interlaced.  This is generally better for memory
> performance (cache reuse).  See, for example, the PETSc-FUN3D papers or
> the various discretization frameworks that rediscover this every once in
> a while.

     You can pull out a single set of DOF with VecStrideGather() and put it back with VecStrideScatter() see also VecStrideGatherAll(), VecStrideScatterAll() also see VecStrideNorm() etc.

> 
>> Also, what is the difference between DMDAVecGetArray and DMDAVecGetArrayDOF?
> 
> With DMDAVecGetArray for multi-component problems, you usually write
> 
>  typedef struct {PetscScalar u,v,w;} Field;
>  Field ***x;
>  DMDAVecGetArray(dm,X,&x);
>  ...
>  x[k][j][i].u = 1;
> 
> With DMDAVecGetArrayDOF, you use an extra set of indices instead of the
> struct.



More information about the petsc-users mailing list