Date: 2013-07-02T14:46:18+00:00

Actual source code: ex24.c
petsc-3.4.2 2013-07-02

      2: static char help[] = "Tests DMDALocalToGlocal() for dof > 1\n\n";

      4: #include <petscdmda.h>

      8: int main(int argc,char **argv)
      9: {
     10:   PetscInt       M = 6,N = 5,m = PETSC_DECIDE,n = PETSC_DECIDE,i,j,is,js,in,jen;
     12:   DM             da;
     13:   Vec            local,global;
     14:   PetscScalar    ***l;

     16:   PetscInitialize(&argc,&argv,(char*)0,help);

     18:   /* Create distributed array and get vectors */
     19:   DMDACreate2d(PETSC_COMM_WORLD, DMDA_BOUNDARY_NONE, DMDA_BOUNDARY_NONE,DMDA_STENCIL_BOX,M,N,m,n,3,1,NULL,NULL,&da);
     20:   DMCreateGlobalVector(da,&global);
     21:   DMCreateLocalVector(da,&local);

     23:   DMDAGetCorners(da,&is,&js,0,&in,&jen,0);
     24:   DMDAVecGetArrayDOF(da,local,&l);
     25:   for (i=is; i<is+in; i++) {
     26:     for (j=js; j<js+jen; j++) {
     27:       l[j][i][0] = 3*(i + j*M);
     28:       l[j][i][1] = 3*(i + j*M) + 1;
     29:       l[j][i][2] = 3*(i + j*M) + 2;
     30:     }
     31:   }
     32:   DMDAVecRestoreArrayDOF(da,local,&l);
     33:   DMLocalToGlobalBegin(da,local,ADD_VALUES,global);
     34:   DMLocalToGlobalEnd(da,local,ADD_VALUES,global);

     36:   VecView(global,PETSC_VIEWER_STDOUT_WORLD);

     38:   /* Free memory */
     39:   VecDestroy(&local);
     40:   VecDestroy(&global);
     41:   DMDestroy(&da);
     42:   PetscFinalize();
     43:   return 0;
     44: }