Actual source code: ex40.c

petsc-3.11.4 2019-09-28
Report Typos and Errors

  2: static char help[] = "Tests mirror boundary conditions in 2-d.\n\n";

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

  7: int main(int argc,char **argv)
  8: {
 10:   PetscInt       M = 8, N = 8,stencil_width = 1, dof = 1,m,n,xstart,ystart,i,j,c;
 11:   DM             da;
 12:   Vec            global,local;
 13:   PetscScalar    ***vglobal;
 14:   PetscViewer    sview;

 16:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
 17:   PetscOptionsGetInt(NULL,0,"-stencil_width",&stencil_width,0);
 18:   PetscOptionsGetInt(NULL,0,"-dof",&dof,0);

 20:   DMDACreate2d(PETSC_COMM_WORLD,DM_BOUNDARY_MIRROR,DM_BOUNDARY_MIRROR,DMDA_STENCIL_STAR,M,N,PETSC_DECIDE,PETSC_DECIDE,dof,stencil_width,NULL,NULL,&da);
 21:   DMSetFromOptions(da);
 22:   DMSetUp(da);
 23:   DMDAGetCorners(da,&xstart,&ystart,0,&m,&n,0);

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

 36:   DMCreateLocalVector(da,&local);
 37:   DMGlobalToLocalBegin(da,global,INSERT_VALUES,local);
 38:   DMGlobalToLocalEnd(da,global,INSERT_VALUES,local);

 40:   PetscViewerGetSubViewer(PETSC_VIEWER_STDOUT_WORLD,PETSC_COMM_SELF,&sview);
 41:   VecView(local,sview);
 42:   PetscViewerRestoreSubViewer(PETSC_VIEWER_STDOUT_WORLD,PETSC_COMM_SELF,&sview);
 43:   PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);
 44:   VecView(global,PETSC_VIEWER_STDOUT_WORLD);

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

 50:   PetscFinalize();
 51:   return ierr;
 52: }







 60: /*TEST

 62:    test:

 64:    test:
 65:       suffix: 2
 66:       nsize: 4
 67:       filter: grep -v "Vec Object"

 69: TEST*/