Actual source code: ex4.c

petsc-3.11.1 2019-04-12
Report Typos and Errors
  1: static char help[] = "Test DMStag explicit coordinate routines";

  3:  #include <petscdm.h>
  4:  #include <petscdmstag.h>

  6: int main(int argc,char **argv)
  7: {
  9:   PetscInt       dim;
 10:   PetscBool      flg;
 11:   DM             dm;
 12:   Vec            coord;

 14:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
 15:   PetscOptionsGetInt(NULL,NULL,"-dim",&dim,&flg);
 16:   if (!flg) {
 17:     PetscPrintf(PETSC_COMM_WORLD,"Supply -dim option\n");
 18:     return 1;
 19:   }
 20:   if (dim == 1) {
 21:     DMStagCreate1d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,2,2,3,DMSTAG_STENCIL_BOX,1,NULL,&dm);
 22:   } else if (dim == 2) {
 23:     DMStagCreate2d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,2,2,PETSC_DECIDE,PETSC_DECIDE,2,3,4,DMSTAG_STENCIL_BOX,1,NULL,NULL,&dm);
 24:   } else if (dim == 3) {
 25:     DMStagCreate3d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,2,2,2,PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,2,3,4,5,DMSTAG_STENCIL_BOX,1,NULL,NULL,NULL,&dm);
 26:   } else {
 27:     PetscPrintf(PETSC_COMM_WORLD,"Supply -dim option with value 1, 2, or 3\n");
 28:     return 1;
 29:   }
 30:   DMSetFromOptions(dm);
 31:   DMSetUp(dm);
 32:   DMView(dm,PETSC_VIEWER_STDOUT_WORLD);
 33:   DMStagSetUniformCoordinatesExplicit(dm,1.0,3.0,1.0,3.0,1.0,3.0);
 34:   DMGetCoordinates(dm,&coord);
 35:   VecView(coord,PETSC_VIEWER_STDOUT_WORLD);
 36:   DMDestroy(&dm);
 37:   PetscFinalize();
 38:   return ierr;
 39: }

 41: /*TEST

 43:    test:
 44:       suffix: 1d_1
 45:       nsize: 1
 46:       args: -dim 1

 48:    test:
 49:       suffix: 1d_2
 50:       nsize: 2
 51:       args: -dim 1

 53:    test:
 54:       suffix: 2d_1
 55:       nsize: 1
 56:       args: -dim 2

 58:    test:
 59:       suffix: 2d_2
 60:       nsize: 4
 61:       args: -dim 2

 63:    test:
 64:       suffix: 3d_1
 65:       nsize: 1
 66:       args: -dim 3

 68:    test:
 69:       suffix: 3d_2
 70:       nsize: 8
 71:       args: -dim 3

 73: TEST*/