Actual source code: ex17.c
1: static char help[] = "Test DMStag IS computation\n\n";
3: #include <petscdm.h>
4: #include <petscdmstag.h>
6: int main(int argc, char **argv)
7: {
8: DM dm;
9: PetscInt dim, dof0, dof1, dof2, dof3;
10: PetscBool flg;
12: /* Create a DMStag object */
13: PetscFunctionBeginUser;
14: PetscCall(PetscInitialize(&argc, &argv, (char *)0, 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, 1, 1, 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, 0, 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, 2, 3, 3, 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: PetscCall(DMStagGetDOF(dm, &dof0, &dof1, &dof2, &dof3));
35: {
36: IS is;
37: DMStagStencil s;
38: s.c = 0;
39: s.loc = DMSTAG_ELEMENT;
40: PetscCall(DMStagCreateISFromStencils(dm, 1, &s, &is));
41: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Test 1\n"));
42: PetscCall(ISView(is, PETSC_VIEWER_STDOUT_WORLD));
43: PetscCall(ISDestroy(&is));
44: }
45: {
46: IS is;
47: DMStagStencil s;
48: s.c = 0;
49: s.loc = DMSTAG_RIGHT;
50: PetscCall(DMStagCreateISFromStencils(dm, 1, &s, &is));
51: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Test 2\n"));
52: PetscCall(ISView(is, PETSC_VIEWER_STDOUT_WORLD));
53: PetscCall(ISDestroy(&is));
54: }
55: if (dim > 1) {
56: IS is;
57: DMStagStencil s[2];
58: s[0].c = 0;
59: s[0].loc = DMSTAG_DOWN;
60: s[1].c = 0;
61: s[1].loc = DMSTAG_LEFT;
62: PetscCall(DMStagCreateISFromStencils(dm, 2, s, &is));
63: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Test 3\n"));
64: PetscCall(ISView(is, PETSC_VIEWER_STDOUT_WORLD));
65: PetscCall(ISDestroy(&is));
66: }
67: if (dim == 2 && dof1 > 1) {
68: IS is;
69: DMStagStencil s[5];
70: s[0].c = 0;
71: s[0].loc = DMSTAG_DOWN;
72: s[1].c = 0;
73: s[1].loc = DMSTAG_DOWN; /* redundant, should be ignored */
74: s[2].c = 0;
75: s[2].loc = DMSTAG_LEFT;
76: s[3].c = 0;
77: s[3].loc = DMSTAG_RIGHT; /* redundant, should be ignored */
78: s[4].c = 1;
79: s[4].loc = DMSTAG_RIGHT;
80: PetscCall(DMStagCreateISFromStencils(dm, 5, s, &is));
81: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Test 4\n"));
82: PetscCall(ISView(is, PETSC_VIEWER_STDOUT_WORLD));
83: PetscCall(ISDestroy(&is));
84: }
85: if (dim == 3 && dof0 > 1) {
86: IS is;
87: DMStagStencil s[3];
88: s[0].c = 0;
89: s[0].loc = DMSTAG_BACK_DOWN_LEFT;
90: s[1].c = 0;
91: s[1].loc = DMSTAG_FRONT_UP_RIGHT; /* redundant, should be ignored */
92: s[2].c = 1;
93: s[2].loc = DMSTAG_FRONT_DOWN_RIGHT;
94: PetscCall(DMStagCreateISFromStencils(dm, 3, s, &is));
95: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Test 5\n"));
96: PetscCall(ISView(is, PETSC_VIEWER_STDOUT_WORLD));
97: PetscCall(ISDestroy(&is));
98: }
99: if (dim == 3) {
100: IS is;
101: DMStagStencil s[4];
103: s[0].c = 0;
104: s[0].loc = DMSTAG_ELEMENT;
105: s[1].c = 0;
106: s[1].loc = DMSTAG_BACK_LEFT;
107: s[2].c = 0;
108: s[2].loc = DMSTAG_BACK_DOWN_LEFT;
109: s[3].c = 0;
110: s[3].loc = DMSTAG_DOWN;
111: PetscCall(DMStagCreateISFromStencils(dm, 4, s, &is));
112: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Test 6\n"));
113: PetscCall(ISView(is, PETSC_VIEWER_STDOUT_WORLD));
114: PetscCall(ISDestroy(&is));
115: }
117: PetscCall(DMDestroy(&dm));
118: PetscCall(PetscFinalize());
119: return 0;
120: }
122: /*TEST
124: test:
125: suffix: 1
126: nsize: 1
127: args: -dim 2
129: test:
130: suffix: 2
131: nsize: 1
132: args: -dim 2
134: test:
135: suffix: 3
136: nsize: 2
137: args: -dim 2 -stag_dof_1 2
139: test:
140: suffix: 4
141: nsize: 1
142: args: -dim 3 -stag_dof_0 3
144: test:
145: suffix: 5
146: nsize: 2
147: args: -dim 3 -stag_dof_0 2
149: test:
150: suffix: 6
151: nsize: 1
152: args: -dim 1
154: test:
155: suffix: 7
156: nsize: 2
157: args: -dim 1
159: TEST*/