#include <petsc.h>static char help[] = "dmplex";
int main(int argc, char **argv)
{
PetscCall(PetscInitialize(&argc, &argv, NULL, help));
DM dm, dm_dist;
PetscSection section;
PetscInt cStart, cEndInterior, cEnd, rank;
PetscInt nc[3] = {3, 3, 3};
PetscReal upper[3] = {1, 1, 1};
PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank));
DMPlexCreateBoxMesh(PETSC_COMM_WORLD, 3, PETSC_FALSE, nc, NULL, upper, NULL, PETSC_TRUE, &dm);
DMViewFromOptions(dm, NULL, "-dm1_view");
PetscCall(DMSetFromOptions(dm));
DMViewFromOptions(dm, NULL, "-dm2_view");
PetscCall(DMPlexGetDepthStratum(dm, 3, &cStart, &cEnd));
DMPlexComputeCellTypes(dm);
PetscCall(DMPlexGetCellTypeStratum(dm, DM_POLYTOPE_INTERIOR_GHOST, &cEndInterior, NULL));
PetscPrintf(PETSC_COMM_SELF, "Before Distribution Rank: %d, cStart: %d, cEndInterior: %d, cEnd: %d\n", rank, cStart,
cEndInterior, cEnd);
PetscInt nField = 1, nDof = 3, field = 0;
PetscCall(PetscSectionCreate(PETSC_COMM_WORLD, §ion));
PetscSectionSetNumFields(section, nField);
PetscCall(PetscSectionSetChart(section, cStart, cEnd));
for (PetscInt p = cStart; p < cEnd; p++)
{
PetscCall(PetscSectionSetFieldDof(section, p, field, nDof));
PetscCall(PetscSectionSetDof(section, p, nDof));
}
PetscCall(PetscSectionSetUp(section));
DMSetLocalSection(dm, section);
DMViewFromOptions(dm, NULL, "-dm3_view");
DMSetAdjacency(dm, field, PETSC_TRUE, PETSC_TRUE);
DMViewFromOptions(dm, NULL, "-dm4_view");
PetscCall(DMPlexDistribute(dm, 1, NULL, &dm_dist));
if (dm_dist)
{
DMDestroy(&dm);
dm = dm_dist;
}
DMViewFromOptions(dm, NULL, "-dm5_view");
PetscCall(DMPlexGetDepthStratum(dm, 3, &cStart, &cEnd));
DMPlexComputeCellTypes(dm);
PetscCall(DMPlexGetCellTypeStratum(dm, DM_POLYTOPE_FV_GHOST, &cEndInterior, NULL));
PetscPrintf(PETSC_COMM_SELF, "After Distribution Rank: %d, cStart: %d, cEndInterior: %d, cEnd: %d\n", rank, cStart,
cEndInterior, cEnd);
DMDestroy(&dm);
PetscCall(PetscFinalize());
} Guer.