Actual source code: ex41.c

petsc-3.4.2 2013-07-02
  2: static char help[] = "Tests mirror boundary conditions in 3-d.\n\n";

  4: #include <petscdmda.h>

  8: int main(int argc,char **argv)
  9: {
 11:   PetscInt       M = -2, N = -3, P = 4,stencil_width = 1, dof = 1,m,n,p,xstart,ystart,zstart,i,j,k,c;
 12:   DM             da;
 13:   Vec            global,local;
 14:   PetscScalar    ****vglobal;

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

 19:   PetscOptionsGetInt(0,"-stencil_width",&stencil_width,0);
 20:   PetscOptionsGetInt(0,"-dof",&dof,0);

 22:   DMDACreate3d(PETSC_COMM_WORLD,DMDA_BOUNDARY_MIRROR,DMDA_BOUNDARY_MIRROR,DMDA_BOUNDARY_MIRROR,DMDA_STENCIL_STAR,M,N,P,PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,dof,stencil_width,NULL,NULL,NULL,&da);
 23:   DMDAGetCorners(da,&xstart,&ystart,&zstart,&m,&n,&p);

 25:   DMCreateGlobalVector(da,&global);
 26:   DMDAVecGetArrayDOF(da,global,&vglobal);
 27:   for (k=zstart; k<zstart+p; k++) {
 28:     for (j=ystart; j<ystart+n; j++) {
 29:       for (i=xstart; i<xstart+m; i++) {
 30:         for (c=0; c<dof; c++) {
 31:           vglobal[k][j][i][c] = 1000*k + 100*j + 10*(i+1) + c;
 32:         }
 33:       }
 34:     }
 35:   }
 36:   DMDAVecRestoreArrayDOF(da,global,&vglobal);

 38:   DMCreateLocalVector(da,&local);
 39:   DMGlobalToLocalBegin(da,global,INSERT_VALUES,local);
 40:   DMGlobalToLocalEnd(da,global,INSERT_VALUES,local);

 42:   PetscSequentialPhaseBegin(PETSC_COMM_WORLD,1);
 43:   VecView(local,PETSC_VIEWER_STDOUT_SELF);
 44:   PetscSequentialPhaseEnd(PETSC_COMM_WORLD,1);
 45:   VecView(global,PETSC_VIEWER_STDOUT_WORLD);

 47:   DMDestroy(&da);
 48:   VecDestroy(&local);
 49:   VecDestroy(&global);

 51:   PetscFinalize();
 52:   return 0;
 53: }