Actual source code: ex32.c
1: static char help[] = "Test DMStagRestrictSimple()\n\n";
3: #include <petscdmstag.h>
5: int main(int argc, char **argv)
6: {
7: DM dmf, dmc;
8: Vec gf, gc, lf, lc;
9: PetscInt dim, size;
10: PetscReal norm;
12: PetscFunctionBeginUser;
13: PetscCall(PetscInitialize(&argc, &argv, NULL, help));
14: dim = 2;
15: PetscCall(PetscOptionsGetInt(NULL, NULL, "-dim", &dim, NULL));
16: switch (dim) {
17: case 1:
18: PetscCall(DMStagCreate1d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, 4, 2, 3, DMSTAG_STENCIL_BOX, 1, NULL, &dmc));
19: break;
20: case 2:
21: PetscCall(DMStagCreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, 4, 8, PETSC_DECIDE, PETSC_DECIDE, 2, 3, 4, DMSTAG_STENCIL_BOX, 1, NULL, NULL, &dmc));
22: break;
23: case 3:
24: PetscCall(DMStagCreate3d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, 2, 4, 6, PETSC_DECIDE, PETSC_DECIDE, PETSC_DECIDE, 2, 3, 4, 3, DMSTAG_STENCIL_BOX, 1, NULL, NULL, NULL, &dmc));
25: break;
26: default:
27: SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_SUP, "Not Implemented!");
28: }
29: PetscCall(DMSetFromOptions(dmc));
30: PetscCall(DMSetUp(dmc));
31: PetscCall(DMRefine(dmc, MPI_COMM_NULL, &dmf));
33: PetscCall(DMCreateGlobalVector(dmf, &gf));
34: PetscCall(VecSet(gf, 1.0));
35: PetscCall(DMCreateLocalVector(dmf, &lf));
36: PetscCall(DMGlobalToLocal(dmf, gf, INSERT_VALUES, lf));
38: PetscCall(DMCreateGlobalVector(dmc, &gc));
39: PetscCall(DMCreateLocalVector(dmc, &lc));
41: PetscCall(DMStagRestrictSimple(dmf, lf, dmc, lc));
43: PetscCall(DMLocalToGlobal(dmc, lc, INSERT_VALUES, gc));
45: PetscCall(VecGetSize(gc, &size));
46: PetscCall(VecNorm(gc, NORM_1, &norm));
47: PetscCheck((norm - size) / (PetscReal)size <= PETSC_MACHINE_EPSILON * 10.0, PetscObjectComm((PetscObject)dmc), PETSC_ERR_PLIB, "Numerical test failed");
48: PetscCall(VecDestroy(&gc));
49: PetscCall(VecDestroy(&gf));
50: PetscCall(VecDestroy(&lc));
51: PetscCall(VecDestroy(&lf));
52: PetscCall(DMDestroy(&dmc));
53: PetscCall(DMDestroy(&dmf));
54: PetscCall(PetscFinalize());
55: return 0;
56: }
58: /*TEST
60: test:
61: suffix: 1d
62: nsize: 1
63: args: -dim 1
65: test:
66: suffix: 1d_par
67: nsize: 4
68: args: -dim 1
69: output_file: output/ex32_1d.out
71: test:
72: suffix: 1d_ratio
73: nsize: 1
74: args: -dim 1 -stag_refine_x 3
75: output_file: output/ex32_1d.out
77: test:
78: suffix: 2d
79: nsize: 1
80: args: -dim 2
81: output_file: output/ex32_1d.out
83: test:
84: suffix: 2d_par
85: nsize: 2
86: args: -dim 2
87: output_file: output/ex32_1d.out
89: test:
90: suffix: 2d_par_2
91: nsize: 8
92: args: -dim 2
93: output_file: output/ex32_1d.out
95: test:
96: suffix: 2d_ratio
97: nsize: 1
98: args: -dim 2 -stag_refine_x 3 -stag_refine_y 4
99: output_file: output/ex32_1d.out
101: test:
102: suffix: 3d
103: nsize: 1
104: args: -dim 3
105: output_file: output/ex32_1d.out
107: test:
108: suffix: 3d_par
109: nsize: 2
110: args: -dim 3
111: output_file: output/ex32_1d.out
113: test:
114: suffix: 3d_ratio
115: nsize: 1
116: args: -dim 3 -stag_refine_x 3 -stag_refine_y 4 -stag_refine_z 5
117: output_file: output/ex32_1d.out
118: TEST*/