xref: /petsc/src/dm/impls/plex/tests/ex61.c (revision 0baf8eba40dbc839082666f9f7396a225d6f663c)
1 const char help[] = "Test boundary condition insertion";
2 
3 #include <petscdmplex.h>
4 
5 static PetscErrorCode set_one(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[], void *ctx)
6 {
7   PetscFunctionBegin;
8   bcval[0] = 1.;
9   PetscFunctionReturn(PETSC_SUCCESS);
10 }
11 
12 static PetscErrorCode set_two(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[], void *ctx)
13 {
14   PetscFunctionBegin;
15   bcval[0] = 2.;
16   PetscFunctionReturn(PETSC_SUCCESS);
17 }
18 
19 int main(int argc, char **argv)
20 {
21   DM       dm;
22   DMLabel  label;
23   PetscInt in_value  = 1;
24   PetscInt out_value = 3;
25   PetscInt comps[]   = {0};
26   PetscFE  fe;
27   Vec      localVec;
28 
29   PetscFunctionBeginUser;
30   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
31   PetscCall(DMPlexCreateBoxMesh(PETSC_COMM_WORLD, 2, PETSC_FALSE, NULL, NULL, NULL, NULL, PETSC_TRUE, 0, PETSC_TRUE, &dm));
32   PetscCall(DMGetLabel(dm, "Face Sets", &label));
33   PetscCall(PetscFECreateLagrange(PETSC_COMM_WORLD, 2, 1, PETSC_FALSE, 1, PETSC_DETERMINE, &fe));
34   PetscCall(DMAddField(dm, NULL, (PetscObject)fe));
35   PetscCall(PetscFEDestroy(&fe));
36   PetscCall(DMCreateDS(dm));
37   PetscCall(DMAddBoundary(dm, DM_BC_ESSENTIAL, "inflow condition", label, 1, &in_value, 0, 1, comps, (void (*)(void))set_one, NULL, NULL, NULL));
38   PetscCall(DMAddBoundary(dm, DM_BC_ESSENTIAL, "outflow condition", label, 1, &out_value, 0, 1, comps, (void (*)(void))set_two, NULL, NULL, NULL));
39   PetscCall(DMCreateLocalVector(dm, &localVec));
40   PetscCall(VecSet(localVec, 0.));
41   PetscCall(DMPlexInsertBoundaryValues(dm, PETSC_TRUE, localVec, 0.0, NULL, NULL, NULL));
42   PetscCall(VecView(localVec, NULL));
43   PetscCall(VecDestroy(&localVec));
44   PetscCall(DMDestroy(&dm));
45   PetscCall(PetscFinalize());
46   return 0;
47 }
48 
49 /*TEST
50 
51   test:
52     suffix: 0
53 
54 TEST*/
55