Actual source code: ex16.c

  1: static char help[] = "Test DMStag refinement and coarsening\n\n";

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

  6: int main(int argc, char **argv)
  7: {
  8:   DM        dm, dmCoarsened, dmRefined;
  9:   PetscInt  dim;
 10:   PetscBool flg;

 12:   /* Create a DMStag object */
 13:   PetscFunctionBeginUser;
 14:   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
 15:   PetscCall(PetscOptionsGetInt(NULL, NULL, "-dim", &dim, &flg));
 16:   if (!flg) {
 17:     PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Supply -dim option\n"));
 18:     return 1;
 19:   }
 20:   if (dim == 1) {
 21:     PetscCall(DMStagCreate1d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, 8, 2, 3, DMSTAG_STENCIL_BOX, 1, NULL, &dm));
 22:   } else if (dim == 2) {
 23:     PetscCall(DMStagCreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, 4, 6, PETSC_DECIDE, PETSC_DECIDE, 2, 1, 1, DMSTAG_STENCIL_BOX, 1, NULL, NULL, &dm));
 24:   } else if (dim == 3) {
 25:     PetscCall(DMStagCreate3d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, 4, 4, 6, PETSC_DECIDE, PETSC_DECIDE, PETSC_DECIDE, 1, 1, 1, 1, DMSTAG_STENCIL_BOX, 1, NULL, NULL, NULL, &dm));
 26:   } else {
 27:     PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Supply -dim option with value 1, 2, or 3\n"));
 28:     return 1;
 29:   }
 30:   PetscCall(DMSetFromOptions(dm));
 31:   PetscCall(DMSetUp(dm));
 32:   PetscCall(DMView(dm, PETSC_VIEWER_STDOUT_WORLD));

 34:   /* Create a refined DMStag object */
 35:   PetscCall(DMRefine(dm, PetscObjectComm((PetscObject)dm), &dmRefined));
 36:   PetscCall(DMView(dmRefined, PETSC_VIEWER_STDOUT_WORLD));

 38:   /* Create a coarsened DMStag object */
 39:   PetscCall(DMCoarsen(dm, PetscObjectComm((PetscObject)dm), &dmCoarsened));
 40:   PetscCall(DMView(dmCoarsened, PETSC_VIEWER_STDOUT_WORLD));

 42:   PetscCall(DMDestroy(&dmCoarsened));
 43:   PetscCall(DMDestroy(&dmRefined));
 44:   PetscCall(DMDestroy(&dm));
 45:   PetscCall(PetscFinalize());
 46:   return 0;
 47: }

 49: /*TEST

 51:    test:
 52:       suffix: 1
 53:       nsize: 1
 54:       args: -dim 1 -stag_grid_x 2

 56:    test:
 57:       suffix: 2
 58:       nsize: 1
 59:       args: -dim 2 -stag_grid_x 6 -stag_grid_y 4

 61:    test:
 62:       suffix: 3
 63:       nsize: 6
 64:       args: -dim 3 -stag_grid_x 6 -stag_grid_y 4 -stag_grid_z 4

 66:    test:
 67:       suffix: 4
 68:       nsize: 2
 69:       args: -dim 1 -stag_grid_x 8

 71:    test:
 72:       suffix: 5
 73:       nsize: 4
 74:       args: -dim 2 -stag_grid_x 4 -stag_grid_y 8

 76:    test:
 77:       suffix: 6
 78:       nsize: 12
 79:       args: -dim 3 -stag_grid_x 4 -stag_grid_y 4 -stag_grid_z 12

 81:    test:
 82:       suffix: 7
 83:       nsize: 3
 84:       args: -dim 1 -stag_grid_x 9 -stag_refine_x 3

 86:    test:
 87:       suffix: 8
 88:       nsize: 6
 89:       args: -dim 2 -stag_grid_x 9 -stag_grid_y 8 -stag_refine_x 3 -stag_refine_y 4

 91:    test:
 92:       suffix: 9
 93:       nsize: 12
 94:       args: -dim 3 -stag_grid_x 6 -stag_grid_y 12 -stag_grid_z 24 -stag_refine_x 2 -stag_refine_y 3 -stag_refine_z 4

 96: TEST*/