Actual source code: ex38.c

  1: const char help[] = "Test DMPlexInsertBoundaryValues with DMPlexSetClosurePermutationTensor.\n";

  3: #include <petscdmplex.h>

  5: static PetscErrorCode bc_func(PetscInt dim, PetscReal time, const PetscReal coords[], PetscInt num_comp_u, PetscScalar *u, void *ctx)
  6: {
  8:   for (PetscInt i = 0; i < num_comp_u; i++) u[i] = coords[i];
  9:   return 0;
 10: }

 12: int main(int argc, char **argv)
 13: {
 14:   DM        dm;
 15:   PetscFE   fe;
 16:   Vec       U_loc;
 17:   PetscInt  dim, order = 1;
 18:   PetscBool tensorCoords = PETSC_TRUE;

 20:   /* Initialize PETSc */
 22:   PetscInitialize(&argc, &argv, NULL, help);
 23:   PetscOptionsGetBool(NULL, NULL, "-tensor_coords", &tensorCoords, NULL);
 24:   DMCreate(PETSC_COMM_WORLD, &dm);
 25:   DMSetType(dm, DMPLEX);
 26:   DMSetFromOptions(dm);

 28:   DMGetDimension(dm, &dim);
 29:   PetscFECreateLagrange(PETSC_COMM_WORLD, dim, dim, PETSC_FALSE, order, order, &fe);
 30:   DMAddField(dm, NULL, (PetscObject)fe);
 31:   PetscFEDestroy(&fe);
 32:   DMCreateDS(dm);

 34:   DMViewFromOptions(dm, NULL, "-dm_view");

 36:   DMLabel  label;
 37:   PetscInt marker_ids[] = {1};
 38:   DMGetLabel(dm, "marker", &label);
 39:   DMAddBoundary(dm, DM_BC_ESSENTIAL, "mms", label, 1, marker_ids, 0, 0, NULL, (void (*)(void))bc_func, NULL, NULL, NULL);
 40:   DMPlexSetClosurePermutationTensor(dm, PETSC_DETERMINE, NULL);
 41:   {
 42:     DM cdm;
 43:     DMGetCoordinateDM(dm, &cdm);
 44:     if (tensorCoords) DMPlexSetClosurePermutationTensor(cdm, PETSC_DETERMINE, NULL);
 45:   }

 47:   DMCreateLocalVector(dm, &U_loc);
 48:   DMPlexInsertBoundaryValues(dm, PETSC_TRUE, U_loc, 1., NULL, NULL, NULL);
 49:   VecViewFromOptions(U_loc, NULL, "-u_loc_vec_view");
 50:   VecDestroy(&U_loc);
 51:   DMDestroy(&dm);
 52:   PetscFinalize();
 53:   return 0;
 54: }

 56: /*TEST
 57:   test:
 58:     suffix: 2d
 59:     args: -dm_plex_simplex 0 -dm_plex_dim 2 -dm_plex_box_faces 3,3 -u_loc_vec_view
 60:   test:
 61:     suffix: 3d
 62:     args: -dm_plex_simplex 0 -dm_plex_dim 3 -dm_plex_box_faces 3,3,3 -u_loc_vec_view
 63: TEST*/