xref: /petsc/src/dm/impls/plex/tests/ex44.c (revision b1b17bd547dd4caae783b804fcef58fccbbc4eab)
1 static const char help[] = "Tests for mesh extrusion";
2 
3 #include <petscdmplex.h>
4 
5 typedef struct {
6   char     bdLabel[PETSC_MAX_PATH_LEN]; /* The boundary label name */
7   PetscInt Nbd;                         /* The number of boundary markers to extrude, 0 for all */
8   PetscInt bd[64];                      /* The boundary markers to be extruded */
9 } AppCtx;
10 
11 PETSC_EXTERN PetscErrorCode pyramidNormal(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar[], void *);
12 
13 /* The pyramid apex is at (0.5, 0.5, -1) */
14 PetscErrorCode pyramidNormal(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt r, PetscScalar u[], void *ctx)
15 {
16   PetscReal apex[3] = {0.5, 0.5, -1.0};
17   PetscInt  d;
18 
19   for (d = 0;   d < dim; ++d) u[d] = x[d] - apex[d];
20   for (d = dim; d < 3;   ++d) u[d] = 0.0  - apex[d];
21   return 0;
22 }
23 
24 static PetscErrorCode ProcessOptions(MPI_Comm comm, AppCtx *options)
25 {
26   PetscInt       n = 64;
27   PetscBool      flg;
28 
29   PetscFunctionBeginUser;
30   PetscCall(PetscStrcpy(options->bdLabel, "marker"));
31   PetscOptionsBegin(comm, "", "Parallel Mesh Adaptation Options", "DMPLEX");
32   PetscCall(PetscOptionsString("-label", "The boundary label name", "ex44.c", options->bdLabel, options->bdLabel, sizeof(options->bdLabel), NULL));
33   PetscCall(PetscOptionsIntArray("-bd", "The boundaries to be extruded", "ex44.c", options->bd, &n, &flg));
34   options->Nbd = flg ? n : 0;
35   PetscOptionsEnd();
36   PetscFunctionReturn(0);
37 }
38 
39 static PetscErrorCode CreateMesh(MPI_Comm comm, AppCtx *ctx, DM *dm)
40 {
41   PetscFunctionBegin;
42   PetscCall(DMCreate(comm, dm));
43   PetscCall(DMSetType(*dm, DMPLEX));
44   PetscCall(DMSetFromOptions(*dm));
45   PetscCall(DMViewFromOptions(*dm, NULL, "-dm_view"));
46   PetscFunctionReturn(0);
47 }
48 
49 static PetscErrorCode CreateAdaptLabel(DM dm, AppCtx *ctx, DMLabel *adaptLabel)
50 {
51   DMLabel  label;
52   PetscInt b;
53 
54   PetscFunctionBegin;
55   if (!ctx->Nbd) {*adaptLabel = NULL; PetscFunctionReturn(0);}
56   PetscCall(DMGetLabel(dm, ctx->bdLabel, &label));
57   PetscCall(DMLabelCreate(PETSC_COMM_SELF, "Adaptation Label", adaptLabel));
58   for (b = 0; b < ctx->Nbd; ++b) {
59     IS              bdIS;
60     const PetscInt *points;
61     PetscInt        n, i;
62 
63     PetscCall(DMLabelGetStratumIS(label, ctx->bd[b], &bdIS));
64     if (!bdIS) continue;
65     PetscCall(ISGetLocalSize(bdIS, &n));
66     PetscCall(ISGetIndices(bdIS, &points));
67     for (i = 0; i < n; ++i) {PetscCall(DMLabelSetValue(*adaptLabel, points[i], DM_ADAPT_REFINE));}
68     PetscCall(ISRestoreIndices(bdIS, &points));
69     PetscCall(ISDestroy(&bdIS));
70   }
71   PetscFunctionReturn(0);
72 }
73 
74 int main(int argc, char **argv)
75 {
76   DM      dm, dma;
77   DMLabel adaptLabel;
78   AppCtx  ctx;
79 
80   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
81   PetscCall(ProcessOptions(PETSC_COMM_WORLD, &ctx));
82   PetscCall(CreateMesh(PETSC_COMM_WORLD, &ctx, &dm));
83   PetscCall(CreateAdaptLabel(dm, &ctx, &adaptLabel));
84   if (adaptLabel) {PetscCall(DMAdaptLabel(dm, adaptLabel, &dma));}
85   else            {PetscCall(DMExtrude(dm, 3, &dma));}
86   PetscCall(PetscObjectSetName((PetscObject) dma, "Adapted Mesh"));
87   PetscCall(DMLabelDestroy(&adaptLabel));
88   PetscCall(DMDestroy(&dm));
89   PetscCall(DMViewFromOptions(dma, NULL, "-adapt_dm_view"));
90   PetscCall(DMDestroy(&dma));
91   PetscCall(PetscFinalize());
92   return 0;
93 }
94 
95 /*TEST
96 
97   test:
98     suffix: tri_tensor_0
99     requires: triangle
100     args: -dm_plex_transform_extrude_use_tensor {{0 1}separate output} \
101           -dm_view -adapt_dm_view -dm_plex_check_all
102 
103   test:
104     suffix: quad_tensor_0
105     args: -dm_plex_simplex 0 -dm_plex_transform_extrude_use_tensor {{0 1}separate output} \
106           -dm_view -adapt_dm_view -dm_plex_check_all
107 
108   test:
109     suffix: quad_normal_0
110     args: -dm_plex_simplex 0 -dm_plex_transform_extrude_normal 0,1,1 \
111           -dm_view -adapt_dm_view -dm_plex_check_all
112 
113   test:
114     suffix: quad_normal_1
115     args: -dm_plex_simplex 0 -dm_plex_transform_extrude_normal_function pyramidNormal \
116           -dm_view -adapt_dm_view -dm_plex_check_all
117 
118   test:
119     suffix: quad_symmetric_0
120     args: -dm_plex_simplex 0 -dm_plex_transform_extrude_symmetric \
121           -dm_view -adapt_dm_view -dm_plex_check_all
122 
123   testset:
124     args: -dm_adaptor cellrefiner -dm_plex_transform_type extrude \
125           -dm_view -adapt_dm_view
126 
127     test:
128       suffix: quad_adapt_0
129       args: -dm_plex_simplex 0 -dm_plex_box_faces 2,2 -dm_plex_separate_marker -bd 1,3 \
130             -dm_plex_transform_extrude_thickness 0.5
131 
132 TEST*/
133