xref: /petsc/src/dm/impls/stag/tests/ex32.c (revision 609caa7c8c030312b00807b4f015fd827bb80932)
1 static char help[] = "Test DMStagRestrictSimple()\n\n";
2 
3 #include <petscdmstag.h>
4 
main(int argc,char ** argv)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;
11 
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));
32 
33   PetscCall(DMCreateGlobalVector(dmf, &gf));
34   PetscCall(VecSet(gf, 1.0));
35   PetscCall(DMCreateLocalVector(dmf, &lf));
36   PetscCall(DMGlobalToLocal(dmf, gf, INSERT_VALUES, lf));
37 
38   PetscCall(DMCreateGlobalVector(dmc, &gc));
39   PetscCall(DMCreateLocalVector(dmc, &lc));
40 
41   PetscCall(DMStagRestrictSimple(dmf, lf, dmc, lc));
42 
43   PetscCall(DMLocalToGlobal(dmc, lc, INSERT_VALUES, gc));
44 
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 }
57 
58 /*TEST
59 
60    test:
61       suffix: 1d
62       nsize: 1
63       args: -dim 1
64       output_file: output/empty.out
65 
66    test:
67       suffix: 1d_par
68       nsize: 4
69       args: -dim 1
70       output_file: output/empty.out
71 
72    test:
73       suffix: 1d_ratio
74       nsize: 1
75       args: -dim 1 -stag_refine_x 3
76       output_file: output/empty.out
77 
78    test:
79       suffix: 2d
80       nsize: 1
81       args: -dim 2
82       output_file: output/empty.out
83 
84    test:
85       suffix: 2d_par
86       nsize: 2
87       args: -dim 2
88       output_file: output/empty.out
89 
90    test:
91       suffix: 2d_par_2
92       nsize: 8
93       args: -dim 2
94       output_file: output/empty.out
95 
96    test:
97       suffix: 2d_ratio
98       nsize: 1
99       args: -dim 2 -stag_refine_x 3 -stag_refine_y 4
100       output_file: output/empty.out
101 
102    test:
103       suffix: 3d
104       nsize: 1
105       args: -dim 3
106       output_file: output/empty.out
107 
108    test:
109       suffix: 3d_par
110       nsize: 2
111       args: -dim 3
112       output_file: output/empty.out
113 
114    test:
115       suffix: 3d_ratio
116       nsize: 1
117       args: -dim 3 -stag_refine_x 3 -stag_refine_y 4 -stag_refine_z 5
118       output_file: output/empty.out
119 TEST*/
120