1 static char help[] = "Test DMStag refinement and coarsening\n\n";
2
3 #include <petscdm.h>
4 #include <petscdmstag.h>
5
main(int argc,char ** argv)6 int main(int argc, char **argv)
7 {
8 DM dm, dmCoarsened, dmRefined;
9 PetscInt dim;
10 PetscBool flg;
11
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));
33
34 /* Create a refined DMStag object */
35 PetscCall(DMRefine(dm, PetscObjectComm((PetscObject)dm), &dmRefined));
36 PetscCall(DMView(dmRefined, PETSC_VIEWER_STDOUT_WORLD));
37
38 /* Create a coarsened DMStag object */
39 PetscCall(DMCoarsen(dm, PetscObjectComm((PetscObject)dm), &dmCoarsened));
40 PetscCall(DMView(dmCoarsened, PETSC_VIEWER_STDOUT_WORLD));
41
42 PetscCall(DMDestroy(&dmCoarsened));
43 PetscCall(DMDestroy(&dmRefined));
44 PetscCall(DMDestroy(&dm));
45 PetscCall(PetscFinalize());
46 return 0;
47 }
48
49 /*TEST
50
51 test:
52 suffix: 1
53 nsize: 1
54 args: -dim 1 -stag_grid_x 2
55
56 test:
57 suffix: 2
58 nsize: 1
59 args: -dim 2 -stag_grid_x 6 -stag_grid_y 4
60
61 test:
62 suffix: 3
63 nsize: 6
64 args: -dim 3 -stag_grid_x 6 -stag_grid_y 4 -stag_grid_z 4
65
66 test:
67 suffix: 4
68 nsize: 2
69 args: -dim 1 -stag_grid_x 8
70
71 test:
72 suffix: 5
73 nsize: 4
74 args: -dim 2 -stag_grid_x 4 -stag_grid_y 8
75
76 test:
77 suffix: 6
78 nsize: 12
79 args: -dim 3 -stag_grid_x 4 -stag_grid_y 4 -stag_grid_z 12
80
81 test:
82 suffix: 7
83 nsize: 3
84 args: -dim 1 -stag_grid_x 9 -stag_refine_x 3
85
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
90
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
95
96 TEST*/
97