Actual source code: ex61.c

  1: const char help[] = "Test boundary condition insertion";

  3: #include <petscdmplex.h>

  5: static PetscErrorCode set_one(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[], void *ctx)
  6: {
  7:   bcval[0] = 1.;
  8:   return 0;
  9: }

 11: static PetscErrorCode set_two(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[], void *ctx)
 12: {
 13:   bcval[0] = 2.;
 14:   return 0;
 15: }

 17: int main(int argc, char **argv)
 18: {
 19:   DM       dm;
 20:   DMLabel  label;
 21:   PetscInt in_value  = 1;
 22:   PetscInt out_value = 3;
 23:   PetscInt comps[]   = {0};
 24:   PetscFE  fe;
 25:   Vec      localVec;

 28:   PetscInitialize(&argc, &argv, NULL, help);
 29:   DMPlexCreateBoxMesh(PETSC_COMM_WORLD, 2, PETSC_FALSE, NULL, NULL, NULL, NULL, PETSC_TRUE, &dm);
 30:   DMGetLabel(dm, "Face Sets", &label);
 31:   PetscFECreateLagrange(PETSC_COMM_WORLD, 2, 1, PETSC_FALSE, 1, PETSC_DETERMINE, &fe);
 32:   DMAddField(dm, NULL, (PetscObject)fe);
 33:   PetscFEDestroy(&fe);
 34:   DMCreateDS(dm);
 35:   DMAddBoundary(dm, DM_BC_ESSENTIAL, "inflow condition", label, 1, &in_value, 0, 1, comps, (void (*)(void))set_one, NULL, NULL, NULL);
 36:   DMAddBoundary(dm, DM_BC_ESSENTIAL, "outflow condition", label, 1, &out_value, 0, 1, comps, (void (*)(void))set_two, NULL, NULL, NULL);
 37:   DMCreateLocalVector(dm, &localVec);
 38:   VecSet(localVec, 0.);
 39:   DMPlexInsertBoundaryValues(dm, PETSC_TRUE, localVec, 0.0, NULL, NULL, NULL);
 40:   VecView(localVec, NULL);
 41:   VecDestroy(&localVec);
 42:   DMDestroy(&dm);
 43:   PetscFinalize();
 44:   return 0;
 45: }

 47: /*TEST

 49:   test:
 50:     suffix: 0

 52: TEST*/