Actual source code: ex48.c
1: static char help[] = "Tests for VecGetValuesSection / VecSetValuesSection \n\n";
3: #include <petscdmplex.h>
5: int main(int argc, char **argv)
6: {
7: DM dm;
8: Vec v;
9: PetscSection section;
10: PetscScalar val[2];
11: PetscInt pStart, pEnd, p;
13: PetscInitialize(&argc, &argv, NULL, help);
15: DMCreate(PETSC_COMM_WORLD, &dm);
16: DMSetType(dm, DMPLEX);
17: DMSetFromOptions(dm);
18: DMViewFromOptions(dm, NULL, "-d_view");
20: PetscSectionCreate(PetscObjectComm((PetscObject)dm), §ion);
21: DMPlexGetChart(dm, &pStart, &pEnd);
22: PetscSectionSetChart(section, pStart, pEnd);
23: DMPlexGetHeightStratum(dm, 0, &pStart, &pEnd);
24: for (p = pStart; p < pEnd; p++) PetscSectionSetDof(section, p, 1);
25: DMPlexGetDepthStratum(dm, 0, &pStart, &pEnd);
26: for (p = pStart; p < pEnd; p++) PetscSectionSetDof(section, p, 2);
27: PetscSectionSetUp(section);
28: DMSetLocalSection(dm, section);
29: PetscSectionViewFromOptions(section, NULL, "-s_view");
31: DMCreateGlobalVector(dm, &v);
32: VecViewFromOptions(v, NULL, "-v_view");
34: /* look through all cells and change "cell values" */
35: DMPlexGetChart(dm, &pStart, &pEnd);
36: for (p = pStart; p < pEnd; ++p) {
37: PetscInt dof;
39: PetscSectionGetDof(section, p, &dof);
40: for (PetscInt d = 0; d < dof; ++d) val[d] = 100 * p + d;
41: VecSetValuesSection(v, section, p, val, INSERT_VALUES);
42: }
43: VecView(v, PETSC_VIEWER_STDOUT_WORLD);
45: for (p = pStart; p < pEnd; ++p) {
46: PetscScalar *x;
47: PetscInt dof;
49: PetscSectionGetDof(section, p, &dof);
50: VecGetValuesSection(v, section, p, &x);
51: PetscPrintf(PETSC_COMM_SELF, "Point #%" PetscInt_FMT " %" PetscInt_FMT " dof\n", p, dof);
52: }
54: VecDestroy(&v);
55: PetscSectionDestroy(§ion);
56: DMDestroy(&dm);
57: PetscFinalize();
58: return 0;
59: }
61: /*TEST
63: test:
64: suffix: 0
65: args: -dm_plex_filename ${wPETSC_DIR}/share/petsc/datafiles/meshes/quads-q2.msh
67: TEST*/