Actual source code: ex7.c

  1: static char help[] = "Create a Plex sphere from quads and create a P1 section\n\n";

  3: #include <petscdmplex.h>

  5: static PetscErrorCode SetupSection(DM dm)
  6: {
  7:   PetscSection   s;
  8:   PetscInt       vStart, vEnd, v;

 12:   DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);
 13:   PetscSectionCreate(PetscObjectComm((PetscObject) dm), &s);
 14:   PetscSectionSetNumFields(s, 1);
 15:   PetscSectionSetFieldComponents(s, 0, 1);
 16:   PetscSectionSetChart(s, vStart, vEnd);
 17:   for (v = vStart; v < vEnd; ++v) {
 18:     PetscSectionSetDof(s, v, 1);
 19:     PetscSectionSetFieldDof(s, v, 0, 1);
 20:   }
 21:   PetscSectionSetUp(s);
 22:   DMSetLocalSection(dm, s);
 23:   PetscSectionDestroy(&s);
 24:   return(0);
 25: }

 27: int main(int argc, char **argv)
 28: {
 29:   DM             dm;
 30:   Vec            u;

 33:   PetscInitialize(&argc, &argv, NULL,help);if (ierr) return ierr;
 34:   DMCreate(PETSC_COMM_WORLD, &dm);
 35:   DMSetType(dm, DMPLEX);
 36:   DMSetFromOptions(dm);
 37:   PetscObjectSetName((PetscObject) dm, "Sphere");
 38:   DMViewFromOptions(dm, NULL, "-dm_view");

 40:   SetupSection(dm);
 41:   DMGetGlobalVector(dm, &u);
 42:   VecSet(u, 2);
 43:   VecViewFromOptions(u, NULL, "-vec_view");
 44:   DMRestoreGlobalVector(dm, &u);
 45:   DMDestroy(&dm);
 46:   PetscFinalize();
 47:   return ierr;
 48: }

 50: /*TEST

 52:   testset:
 53:     requires: !__float128
 54:     args: -dm_plex_shape sphere -dm_view

 56:     test:
 57:       suffix: 2d_quad
 58:       args: -dm_plex_simplex 0

 60:     test:
 61:       suffix: 2d_tri
 62:       args:

 64:     test:
 65:       suffix: 3d_tri
 66:       args: -dm_plex_dim 3

 68:   testset:
 69:     requires: !__float128
 70:     args: -dm_plex_shape sphere -dm_distribute -petscpartitioner_type simple -dm_view

 72:     test:
 73:       suffix: 2d_quad_parallel
 74:       nsize: 2
 75:       args: -dm_plex_simplex 0

 77:     test:
 78:       suffix: 2d_tri_parallel
 79:       nsize: 2

 81:     test:
 82:       suffix: 3d_tri_parallel
 83:       nsize: 2
 84:       args: -dm_plex_dim 3

 86: TEST*/