Actual source code: ex39.c
petsc-3.12.4 2020-02-04
Report Typos and Errors

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

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

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

     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:   DMDACreate1d(PETSC_COMM_WORLD,DM_BOUNDARY_MIRROR,M,dof,stencil_width,NULL,&da);
     21:   DMSetFromOptions(da);
     22:   DMSetUp(da);
     23:   DMDAGetCorners(da,&xstart,0,0,&m,0,0);

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

     34:   DMCreateLocalVector(da,&local);
     35:   DMGlobalToLocalBegin(da,global,INSERT_VALUES,local);
     36:   DMGlobalToLocalEnd(da,global,INSERT_VALUES,local);

     38:   PetscViewerGetSubViewer(PETSC_VIEWER_STDOUT_WORLD,PETSC_COMM_SELF,&sviewer);
     39:   VecView(local,sviewer);
     40:   PetscViewerRestoreSubViewer(PETSC_VIEWER_STDOUT_WORLD,PETSC_COMM_SELF,&sviewer);
     41:   PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);
     42:   VecView(global,PETSC_VIEWER_STDOUT_WORLD);

     44:   DMDestroy(&da);
     45:   VecDestroy(&local);
     46:   VecDestroy(&global);

     48:   PetscFinalize();
     49:   return ierr;
     50: }

     52: /*TEST

     54:    test:

     56:    test:
     57:       suffix: 2
     58:       nsize: 2
     59:       filter: grep -v "Vec Object"

     61: TEST*/