xref: /petsc/src/dm/impls/plex/tests/ex32.c (revision 5f80ce2ab25dff0f4601e710601cbbcecf323266)
1c4762a1bSJed Brown static char help[] = "Tests for periodic mesh output\n\n";
2c4762a1bSJed Brown 
3c4762a1bSJed Brown #include <petscdmplex.h>
4c4762a1bSJed Brown 
530602db0SMatthew G. Knepley PetscErrorCode CheckMesh(DM dm)
6c4762a1bSJed Brown {
7*5f80ce2aSJacob Faibussowitsch   PetscReal detJ, J[9];
8c4762a1bSJed Brown   PetscReal vol;
9*5f80ce2aSJacob Faibussowitsch   PetscInt  dim, depth, cStart, cEnd, c;
10c4762a1bSJed Brown 
11c4762a1bSJed Brown   PetscFunctionBegin;
12*5f80ce2aSJacob Faibussowitsch   CHKERRQ(DMGetDimension(dm, &dim));
13*5f80ce2aSJacob Faibussowitsch   CHKERRQ(DMPlexGetDepth(dm, &depth));
14*5f80ce2aSJacob Faibussowitsch   CHKERRQ(DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd));
15c4762a1bSJed Brown   for (c = cStart; c < cEnd; ++c) {
16*5f80ce2aSJacob Faibussowitsch     CHKERRQ(DMPlexComputeCellGeometryFEM(dm, c, NULL, NULL, J, NULL, &detJ));
17*5f80ce2aSJacob Faibussowitsch     PetscCheck(detJ > 0.0,PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Mesh cell %" PetscInt_FMT " is inverted, |J| = %g", c, detJ);
18c4762a1bSJed Brown     if (depth > 1) {
19*5f80ce2aSJacob Faibussowitsch       CHKERRQ(DMPlexComputeCellGeometryFVM(dm, c, &vol, NULL, NULL));
20*5f80ce2aSJacob Faibussowitsch       PetscCheck(vol > 0.0,PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Mesh cell %" PetscInt_FMT " is inverted, vol = %g", c, vol);
21c4762a1bSJed Brown     }
22c4762a1bSJed Brown   }
23c4762a1bSJed Brown   PetscFunctionReturn(0);
24c4762a1bSJed Brown }
25c4762a1bSJed Brown 
2630602db0SMatthew G. Knepley PetscErrorCode CreateMesh(MPI_Comm comm, DM *dm)
27c4762a1bSJed Brown {
28c4762a1bSJed Brown   PetscFunctionBegin;
29*5f80ce2aSJacob Faibussowitsch   CHKERRQ(DMCreate(comm, dm));
30*5f80ce2aSJacob Faibussowitsch   CHKERRQ(DMSetType(*dm, DMPLEX));
31*5f80ce2aSJacob Faibussowitsch   CHKERRQ(DMSetFromOptions(*dm));
32*5f80ce2aSJacob Faibussowitsch   CHKERRQ(DMViewFromOptions(*dm, NULL, "-dm_view"));
33c4762a1bSJed Brown   PetscFunctionReturn(0);
34c4762a1bSJed Brown }
35c4762a1bSJed Brown 
36c4762a1bSJed Brown int main(int argc, char **argv)
37c4762a1bSJed Brown {
3830602db0SMatthew G. Knepley   DM             dm;
39c4762a1bSJed Brown   PetscErrorCode ierr;
40c4762a1bSJed Brown 
41c4762a1bSJed Brown   ierr = PetscInitialize(&argc, &argv, NULL,help);if (ierr) return ierr;
42*5f80ce2aSJacob Faibussowitsch   CHKERRQ(CreateMesh(PETSC_COMM_WORLD, &dm));
43*5f80ce2aSJacob Faibussowitsch   CHKERRQ(CheckMesh(dm));
44*5f80ce2aSJacob Faibussowitsch   CHKERRQ(DMDestroy(&dm));
45c4762a1bSJed Brown   ierr = PetscFinalize();
46c4762a1bSJed Brown   return ierr;
47c4762a1bSJed Brown }
48c4762a1bSJed Brown 
49c4762a1bSJed Brown /*TEST
50c4762a1bSJed Brown 
51c4762a1bSJed Brown   test:
52c4762a1bSJed Brown     suffix: 0
5330602db0SMatthew G. Knepley     args: -dm_plex_simplex 0 -dm_plex_box_faces 3,1,0 -dm_plex_box_bd periodic,none -dm_view ::ascii_info_detail
54c4762a1bSJed Brown   test:
55c4762a1bSJed Brown     suffix: 1
56c4762a1bSJed Brown     nsize: 2
57e600fa54SMatthew G. Knepley     args: -dm_plex_simplex 0 -dm_plex_box_faces 3,1,0 -dm_plex_box_bd periodic,none -petscpartitioner_type simple -dm_view ::ascii_info_detail
58c4762a1bSJed Brown   test:
59c4762a1bSJed Brown     suffix: 2
60c4762a1bSJed Brown     nsize: 2
61e600fa54SMatthew G. Knepley     args: -dm_plex_simplex 0 -dm_plex_box_faces 6,2,0 -dm_plex_box_bd periodic,none -petscpartitioner_type simple -dm_view ::ascii_info_detail
62c4762a1bSJed Brown   test:
63c4762a1bSJed Brown     suffix: 3
64c4762a1bSJed Brown     nsize: 4
65e600fa54SMatthew G. Knepley     args: -dm_plex_simplex 0 -dm_plex_box_faces 6,2,0 -dm_plex_box_bd periodic,none -petscpartitioner_type simple -dm_view ::ascii_info_detail
66c4762a1bSJed Brown   test:
67c4762a1bSJed Brown     suffix: 4
68c4762a1bSJed Brown     nsize: 2
69e600fa54SMatthew G. Knepley     args: -dm_plex_simplex 0 -dm_plex_box_faces 3,1,0 -dm_plex_box_bd periodic,none -dm_plex_periodic_cut -petscpartitioner_type simple -dm_view ::ascii_info_detail
70c4762a1bSJed Brown   test:
71c4762a1bSJed Brown     suffix: 5
72c4762a1bSJed Brown     nsize: 2
73e600fa54SMatthew G. Knepley     args: -dm_plex_simplex 0 -dm_plex_box_faces 6,2,0 -dm_plex_box_bd periodic,none -dm_plex_periodic_cut -petscpartitioner_type simple -dm_view ::ascii_info_detail
74c4762a1bSJed Brown   test:
75c4762a1bSJed Brown     suffix: 6
76c4762a1bSJed Brown     nsize: 4
77e600fa54SMatthew G. Knepley     args: -dm_plex_simplex 0 -dm_plex_box_faces 6,2,0 -dm_plex_box_bd periodic,none -dm_plex_periodic_cut -petscpartitioner_type simple -dm_view ::ascii_info_detail
78c4762a1bSJed Brown 
79c4762a1bSJed Brown TEST*/
80