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;
11: DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);
12: PetscSectionCreate(PetscObjectComm((PetscObject)dm), &s);
13: PetscSectionSetNumFields(s, 1);
14: PetscSectionSetFieldComponents(s, 0, 1);
15: PetscSectionSetChart(s, vStart, vEnd);
16: for (v = vStart; v < vEnd; ++v) {
17: PetscSectionSetDof(s, v, 1);
18: PetscSectionSetFieldDof(s, v, 0, 1);
19: }
20: PetscSectionSetUp(s);
21: DMSetLocalSection(dm, s);
22: PetscSectionDestroy(&s);
23: return 0;
24: }
26: int main(int argc, char **argv)
27: {
28: DM dm;
29: Vec u;
32: PetscInitialize(&argc, &argv, NULL, help);
33: DMCreate(PETSC_COMM_WORLD, &dm);
34: DMSetType(dm, DMPLEX);
35: DMSetFromOptions(dm);
36: PetscObjectSetName((PetscObject)dm, "Sphere");
37: DMViewFromOptions(dm, NULL, "-dm_view");
39: SetupSection(dm);
40: DMGetGlobalVector(dm, &u);
41: VecSet(u, 2);
42: VecViewFromOptions(u, NULL, "-vec_view");
43: DMRestoreGlobalVector(dm, &u);
44: DMDestroy(&dm);
45: PetscFinalize();
46: return 0;
47: }
49: /*TEST
51: testset:
52: requires: !__float128
53: args: -dm_plex_shape sphere -dm_view
55: test:
56: suffix: 2d_quad
57: args: -dm_plex_simplex 0
59: test:
60: suffix: 2d_tri
61: args:
63: test:
64: suffix: 3d_tri
65: args: -dm_plex_dim 3
67: testset:
68: requires: !__float128
69: args: -dm_plex_shape sphere -petscpartitioner_type simple -dm_view
71: test:
72: suffix: 2d_quad_parallel
73: nsize: 2
74: args: -dm_plex_simplex 0
76: test:
77: suffix: 2d_tri_parallel
78: nsize: 2
80: test:
81: suffix: 3d_tri_parallel
82: nsize: 2
83: args: -dm_plex_dim 3
85: TEST*/