Actual source code: ex4.c
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: {
8: PetscInt dim;
9: PetscBool flg;
10: DM dm;
11: Vec coord;
13: PetscFunctionBeginUser;
14: PetscCall(PetscInitialize(&argc, &argv, NULL, help));
15: PetscCall(PetscOptionsGetInt(NULL, NULL, "-dim", &dim, &flg));
16: PetscCheck(flg, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Supply -dim option with value 1, 2, or 3");
18: if (dim == 1) {
19: PetscCall(DMStagCreate1d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, 2, 2, 3, DMSTAG_STENCIL_BOX, 1, NULL, &dm));
20: } else if (dim == 2) {
21: PetscCall(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));
22: } else if (dim == 3) {
23: PetscCall(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));
24: } else SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Supply -dim option with value 1, 2, or 3");
26: PetscCall(DMSetFromOptions(dm));
27: PetscCall(DMSetUp(dm));
28: PetscCall(DMView(dm, PETSC_VIEWER_STDOUT_WORLD));
29: PetscCall(DMStagSetUniformCoordinatesExplicit(dm, 1.0, 3.0, 1.0, 3.0, 1.0, 3.0));
30: PetscCall(DMGetCoordinates(dm, &coord));
31: PetscCall(VecView(coord, PETSC_VIEWER_STDOUT_WORLD));
32: PetscCall(DMDestroy(&dm));
33: PetscCall(PetscFinalize());
34: return 0;
35: }
37: /*TEST
39: test:
40: suffix: 1d_1
41: nsize: 1
42: args: -dim 1
44: test:
45: suffix: 1d_2
46: nsize: 2
47: args: -dim 1
49: test:
50: suffix: 2d_1
51: nsize: 1
52: args: -dim 2
54: test:
55: suffix: 2d_2
56: nsize: 4
57: args: -dim 2
59: test:
60: suffix: 3d_1
61: nsize: 1
62: args: -dim 3
64: test:
65: suffix: 3d_2
66: nsize: 8
67: args: -dim 3
69: TEST*/