Actual source code: ex25.c

petsc-3.8.4 2018-03-24
Report Typos and Errors

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

  4:  #include <petscdm.h>
  5:  #include <petscdmda.h>

  7: int main(int argc,char **argv)
  8: {
  9:   PetscInt       M = 6,N = 5,P = 4, m = PETSC_DECIDE,n = PETSC_DECIDE,p = PETSC_DECIDE,i,j,k,is,js,ks,in,jen,kn;
 11:   DM             da;
 12:   Vec            local,global;
 13:   PetscScalar    ****l;

 15:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
 16:   /* Create distributed array and get vectors */
 17:   DMDACreate3d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DMDA_STENCIL_BOX,M,N,P,m,n,p,2,1,NULL,NULL,NULL,&da);
 18:   DMSetFromOptions(da);
 19:   DMSetUp(da);
 20:   DMCreateGlobalVector(da,&global);
 21:   DMCreateLocalVector(da,&local);

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

 37:   VecView(global,PETSC_VIEWER_STDOUT_WORLD);

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