xref: /petsc/src/dm/impls/forest/tutorials/ex1.c (revision b122ec5aa1bd4469eb4e0673542fb7de3f411254)
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   PetscErrorCode ierr;
14c4762a1bSJed Brown 
15*b122ec5aSJacob Faibussowitsch   CHKERRQ(PetscInitialize(&argc, &argv, NULL,help));
165f80ce2aSJacob Faibussowitsch   CHKERRQ(DMCreate(PETSC_COMM_WORLD, &dm));
175f80ce2aSJacob Faibussowitsch   CHKERRQ(PetscStrncpy(typeString,DMFOREST,256));
18c4762a1bSJed Brown   ierr = PetscOptionsBegin(PETSC_COMM_WORLD,NULL,"DM Forest example options",NULL);CHKERRQ(ierr);
195f80ce2aSJacob Faibussowitsch   CHKERRQ(PetscOptionsString("-dm_type","The type of the dm",NULL,DMFOREST,typeString,sizeof(typeString),NULL));
205f80ce2aSJacob Faibussowitsch   CHKERRQ(PetscOptionsBool("-test_convert","Test conversion to DMPLEX",NULL,conv,&conv,NULL));
21c4762a1bSJed Brown   ierr = PetscOptionsEnd();CHKERRQ(ierr);
225f80ce2aSJacob Faibussowitsch   CHKERRQ(DMSetType(dm,(DMType) typeString));
235f80ce2aSJacob Faibussowitsch   CHKERRQ(DMSetFromOptions(dm));
245f80ce2aSJacob Faibussowitsch   CHKERRQ(DMSetUp(dm));
255f80ce2aSJacob Faibussowitsch   CHKERRQ(DMViewFromOptions(dm,NULL,"-dm_view"));
265f80ce2aSJacob Faibussowitsch   CHKERRQ(PetscViewerDestroy(&viewer));
27c4762a1bSJed Brown   if (conv) {
28c4762a1bSJed Brown     DM dmConv;
29c4762a1bSJed Brown 
305f80ce2aSJacob Faibussowitsch     CHKERRQ(DMConvert(dm,DMPLEX,&dmConv));
315f80ce2aSJacob Faibussowitsch     CHKERRQ(DMLocalizeCoordinates(dmConv));
325f80ce2aSJacob Faibussowitsch     CHKERRQ(DMViewFromOptions(dmConv,NULL,"-dm_conv_view"));
335f80ce2aSJacob Faibussowitsch     CHKERRQ(DMPlexCheckCellShape(dmConv,PETSC_FALSE,PETSC_DETERMINE));
345f80ce2aSJacob Faibussowitsch     CHKERRQ(DMDestroy(&dmConv));
35c4762a1bSJed Brown   }
365f80ce2aSJacob Faibussowitsch   CHKERRQ(DMDestroy(&dm));
37*b122ec5aSJacob Faibussowitsch   CHKERRQ(PetscFinalize());
38*b122ec5aSJacob Faibussowitsch   return 0;
39c4762a1bSJed Brown }
40c4762a1bSJed Brown 
41c4762a1bSJed Brown /*TEST
42c4762a1bSJed Brown 
43c4762a1bSJed Brown       test:
44c4762a1bSJed Brown         output_file: output/ex1_moebius.out
45c4762a1bSJed Brown         suffix: p4est_topology_moebius
46c4762a1bSJed Brown         nsize: 3
47c4762a1bSJed Brown         args: -dm_type p4est -dm_forest_topology moebius -dm_view vtk:moebius.vtu
48c4762a1bSJed Brown         requires: p4est !complex
49c4762a1bSJed Brown 
50c4762a1bSJed Brown       test:
51c4762a1bSJed Brown         output_file: output/ex1_moebius.out
52c4762a1bSJed Brown         suffix: p4est_topology_moebius_convert
53c4762a1bSJed Brown         nsize: 3
54c4762a1bSJed Brown         args: -dm_type p4est -dm_forest_topology moebius -test_convert -dm_conv_view vtk:moebiusconv.vtu
55c4762a1bSJed Brown         requires: p4est !complex
56c4762a1bSJed Brown 
57c4762a1bSJed Brown       test:
58c4762a1bSJed Brown         output_file: output/ex1_shell.out
59c4762a1bSJed Brown         suffix: p4est_topology_shell
60c4762a1bSJed Brown         nsize: 3
61c4762a1bSJed Brown         args: -dm_type p8est -dm_forest_topology shell -dm_view vtk:shell.vtu
62c4762a1bSJed Brown         requires: p4est !complex
63c4762a1bSJed Brown 
64c4762a1bSJed Brown       test:
65c4762a1bSJed Brown         TODO: broken
66c4762a1bSJed Brown         output_file: output/ex1_shell.out
67c4762a1bSJed Brown         suffix: p4est_topology_shell_convert
68c4762a1bSJed Brown         nsize: 3
69c4762a1bSJed Brown         args: -dm_type p8est -dm_forest_topology shell -test_convert -dm_conv_view vtk:shellconv.vtu
70c4762a1bSJed Brown         requires: p4est !complex
71c4762a1bSJed Brown 
72c4762a1bSJed Brown       test:
73c4762a1bSJed Brown         TODO: broken
74c4762a1bSJed Brown         output_file: output/ex1_sphere.out
75c4762a1bSJed Brown         suffix: p4est_topology_sphere_convert
76c4762a1bSJed Brown         nsize: 3
77c4762a1bSJed 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
78c4762a1bSJed Brown         requires: p4est !complex
79c4762a1bSJed Brown 
80c4762a1bSJed Brown       test:
81c4762a1bSJed Brown         output_file: output/ex1_brick.out
82c4762a1bSJed Brown         suffix: p4est_topology_brick
83c4762a1bSJed Brown         nsize: 3
84c4762a1bSJed Brown         args: -dm_type p8est -dm_forest_topology brick -dm_p4est_brick_size 2,3,5 -dm_view vtk:brick.vtu
85c4762a1bSJed Brown         requires: p4est !complex
86c4762a1bSJed Brown 
87c4762a1bSJed Brown       test:
88c4762a1bSJed Brown         output_file: output/ex1_brick_periodic_glvis.out
89c4762a1bSJed Brown         suffix: p4est_topology_brick_periodic_glvis
90c4762a1bSJed 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:
91c4762a1bSJed Brown         requires: p4est
92c4762a1bSJed Brown 
93c4762a1bSJed Brown       test:
94c4762a1bSJed Brown         output_file: output/ex1_brick.out
95c4762a1bSJed Brown         suffix: p4est_topology_brick_periodic_2d
96c4762a1bSJed Brown         nsize: 3
97c4762a1bSJed 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
98c4762a1bSJed Brown         requires: p4est
99c4762a1bSJed Brown 
100c4762a1bSJed Brown       test:
101c4762a1bSJed Brown         output_file: output/ex1_brick.out
102c4762a1bSJed Brown         suffix: p4est_topology_brick_periodic_3d
103c4762a1bSJed Brown         nsize: 3
104c4762a1bSJed 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
105c4762a1bSJed Brown         requires: p4est
106c4762a1bSJed Brown 
107c4762a1bSJed Brown TEST*/
108