xref: /petsc/src/dm/impls/plex/tests/ex38.c (revision fdf6c4e30aafdbc795e4f76379caa977fd5cdf5a)
1 const char help[] = "Test DMPlexInsertBoundaryValues with DMPlexSetClosurePermutationTensor.\n";
2 
3 #include <petscdmplex.h>
4 
5 static PetscErrorCode bc_func(PetscInt dim, PetscReal time,
6                      const PetscReal coords[], PetscInt num_comp_u,
7                      PetscScalar *u, void *ctx)
8 {
9   PetscFunctionBeginUser;
10   for (PetscInt i=0; i<num_comp_u; i++) u[i] = coords[i];
11   PetscFunctionReturn(0);
12 }
13 
14 int main(int argc,char **argv)
15 {
16   DM        dm;
17   PetscFE   fe;
18   Vec       U_loc;
19   PetscInt  dim, order = 1;
20   PetscBool tensorCoords = PETSC_TRUE;
21 
22   /* Initialize PETSc */
23   PetscCall(PetscInitialize(&argc,&argv,NULL,help));
24   PetscCall(PetscOptionsGetBool(NULL, NULL, "-tensor_coords", &tensorCoords, NULL));
25   PetscCall(DMCreate(PETSC_COMM_WORLD, &dm));
26   PetscCall(DMSetType(dm, DMPLEX));
27   PetscCall(DMSetFromOptions(dm));
28 
29   PetscCall(DMGetDimension(dm, &dim));
30   PetscCall(PetscFECreateLagrange(PETSC_COMM_WORLD, dim, dim, PETSC_FALSE, order, order, &fe));
31   PetscCall(DMAddField(dm, NULL, (PetscObject)fe));
32   PetscCall(PetscFEDestroy(&fe));
33   PetscCall(DMCreateDS(dm));
34 
35   PetscCall(DMViewFromOptions(dm, NULL, "-dm_view"));
36 
37   DMLabel label;
38   PetscInt marker_ids[] = {1};
39   PetscCall(DMGetLabel(dm, "marker", &label));
40   PetscCall(DMAddBoundary(dm, DM_BC_ESSENTIAL, "mms", label, 1, marker_ids, 0, 0, NULL, (void(*)(void))bc_func, NULL, NULL, NULL));
41   PetscCall(DMPlexSetClosurePermutationTensor(dm, PETSC_DETERMINE, NULL));
42   {
43     DM cdm;
44     PetscCall(DMGetCoordinateDM(dm, &cdm));
45     if (tensorCoords) PetscCall(DMPlexSetClosurePermutationTensor(cdm, PETSC_DETERMINE, NULL));
46   }
47 
48   PetscCall(DMCreateLocalVector(dm, &U_loc));
49   PetscCall(DMPlexInsertBoundaryValues(dm, PETSC_TRUE, U_loc, 1., NULL, NULL, NULL));
50   PetscCall(VecViewFromOptions(U_loc, NULL, "-u_loc_vec_view"));
51   PetscCall(VecDestroy(&U_loc));
52   PetscCall(DMDestroy(&dm));
53   PetscCall(PetscFinalize());
54   return 0;
55 }
56 
57 /*TEST
58   test:
59     suffix: 2d
60     args: -dm_plex_simplex 0 -dm_plex_dim 2 -dm_plex_box_faces 3,3 -u_loc_vec_view
61   test:
62     suffix: 3d
63     args: -dm_plex_simplex 0 -dm_plex_dim 3 -dm_plex_box_faces 3,3,3 -u_loc_vec_view
64 TEST*/
65