xref: /petsc/src/dm/impls/forest/tutorials/ex1.c (revision 9371c9d470a9602b6d10a8bf50c9b2280a79e45a)
1 static char help[] = "Create and view a forest mesh\n\n";
2 
3 #include <petscdmforest.h>
4 #include <petscdmplex.h>
5 #include <petscoptions.h>
6 
7 int main(int argc, char **argv) {
8   DM          dm;
9   char        typeString[256] = {'\0'};
10   PetscViewer viewer          = NULL;
11   PetscBool   conv            = PETSC_FALSE;
12 
13   PetscFunctionBeginUser;
14   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
15   PetscCall(DMCreate(PETSC_COMM_WORLD, &dm));
16   PetscCall(PetscStrncpy(typeString, DMFOREST, 256));
17   PetscOptionsBegin(PETSC_COMM_WORLD, NULL, "DM Forest example options", NULL);
18   PetscCall(PetscOptionsString("-dm_type", "The type of the dm", NULL, DMFOREST, typeString, sizeof(typeString), NULL));
19   PetscCall(PetscOptionsBool("-test_convert", "Test conversion to DMPLEX", NULL, conv, &conv, NULL));
20   PetscOptionsEnd();
21   PetscCall(DMSetType(dm, (DMType)typeString));
22   PetscCall(DMSetFromOptions(dm));
23   PetscCall(DMSetUp(dm));
24   PetscCall(DMViewFromOptions(dm, NULL, "-dm_view"));
25   PetscCall(PetscViewerDestroy(&viewer));
26   if (conv) {
27     DM dmConv;
28 
29     PetscCall(DMConvert(dm, DMPLEX, &dmConv));
30     PetscCall(DMLocalizeCoordinates(dmConv));
31     PetscCall(DMViewFromOptions(dmConv, NULL, "-dm_conv_view"));
32     PetscCall(DMPlexCheckCellShape(dmConv, PETSC_FALSE, PETSC_DETERMINE));
33     PetscCall(DMDestroy(&dmConv));
34   }
35   PetscCall(DMDestroy(&dm));
36   PetscCall(PetscFinalize());
37   return 0;
38 }
39 
40 /*TEST
41 
42       test:
43         output_file: output/ex1_moebius.out
44         suffix: p4est_topology_moebius
45         nsize: 3
46         args: -dm_type p4est -dm_forest_topology moebius -dm_view vtk:moebius.vtu
47         requires: p4est !complex
48 
49       test:
50         output_file: output/ex1_moebius.out
51         suffix: p4est_topology_moebius_convert
52         nsize: 3
53         args: -dm_type p4est -dm_forest_topology moebius -test_convert -dm_conv_view vtk:moebiusconv.vtu
54         requires: p4est !complex
55 
56       test:
57         output_file: output/ex1_shell.out
58         suffix: p4est_topology_shell
59         nsize: 3
60         args: -dm_type p8est -dm_forest_topology shell -dm_view vtk:shell.vtu
61         requires: p4est !complex
62 
63       test:
64         TODO: broken
65         output_file: output/ex1_shell.out
66         suffix: p4est_topology_shell_convert
67         nsize: 3
68         args: -dm_type p8est -dm_forest_topology shell -test_convert -dm_conv_view vtk:shellconv.vtu
69         requires: p4est !complex
70 
71       test:
72         TODO: broken
73         output_file: output/ex1_sphere.out
74         suffix: p4est_topology_sphere_convert
75         nsize: 3
76         args: -dm_type p8est -dm_forest_topology sphere -dm_view vtk:sphere.vtu  -dm_forest_initial_refinement 1 -dm_forest_maximum_refinement 1 -test_convert -dm_conv_view vtk:sphereconv.vtu
77         requires: p4est !complex
78 
79       test:
80         output_file: output/ex1_brick.out
81         suffix: p4est_topology_brick
82         nsize: 3
83         args: -dm_type p8est -dm_forest_topology brick -dm_p4est_brick_size 2,3,5 -dm_view vtk:brick.vtu
84         requires: p4est !complex
85 
86       test:
87         output_file: output/ex1_brick_periodic_glvis.out
88         suffix: p4est_topology_brick_periodic_glvis
89         args: -dm_type p8est -dm_forest_topology brick -dm_p4est_brick_size 3,4,5 -dm_p4est_brick_periodicity 0,1,0 -test_convert -dm_conv_view glvis:
90         requires: p4est
91 
92       test:
93         output_file: output/ex1_brick.out
94         suffix: p4est_topology_brick_periodic_2d
95         nsize: 3
96         args: -dm_type p4est -dm_forest_topology brick -dm_p4est_brick_size 5,6 -dm_p4est_brick_periodicity 1,0 -test_convert -dm_forest_initial_refinement 0 -dm_forest_maximum_refinement 2 -dm_p4est_refine_pattern hash
97         requires: p4est
98 
99       test:
100         output_file: output/ex1_brick.out
101         suffix: p4est_topology_brick_periodic_3d
102         nsize: 3
103         args: -dm_type p8est -dm_forest_topology brick -dm_p4est_brick_size 5,6,1 -dm_p4est_brick_periodicity 0,1,0 -test_convert -dm_forest_initial_refinement 0 -dm_forest_maximum_refinement 2 -dm_p4est_refine_pattern hash
104         requires: p4est
105 
106 TEST*/
107