xref: /petsc/src/dm/impls/stag/tests/ex4.c (revision 732aec7a18f2199fb53bb9a2f3aef439a834ce31)
1 static char help[] = "Test DMStag explicit coordinate routines";
2 
3 #include <petscdm.h>
4 #include <petscdmstag.h>
5 
main(int argc,char ** argv)6 int main(int argc, char **argv)
7 {
8   PetscInt  dim;
9   PetscBool flg;
10   DM        dm;
11   Vec       coord;
12 
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");
17 
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");
25 
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 }
36 
37 /*TEST
38 
39    test:
40       suffix: 1d_1
41       nsize: 1
42       args: -dim 1
43 
44    test:
45       suffix: 1d_2
46       nsize: 2
47       args: -dim 1
48 
49    test:
50       suffix: 2d_1
51       nsize: 1
52       args: -dim 2
53 
54    test:
55       suffix: 2d_2
56       nsize: 4
57       args: -dim 2
58 
59    test:
60       suffix: 3d_1
61       nsize: 1
62       args: -dim 3
63 
64    test:
65       suffix: 3d_2
66       nsize: 8
67       args: -dim 3
68 
69 TEST*/
70