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