Actual source code: plexcoarsen.c

      1: #include <petsc/private/dmpleximpl.h>

      3: PetscErrorCode DMCoarsen_Plex(DM dm, MPI_Comm comm, DM *dmCoarsened)
      4: {
      5:   PetscFunctionBegin;
      6:   if (!dm->coarseMesh) PetscCall(DMPlexCoarsen_Internal(dm, NULL, NULL, NULL, &dm->coarseMesh));
      7:   PetscCall(PetscObjectReference((PetscObject)dm->coarseMesh));
      8:   *dmCoarsened = dm->coarseMesh;
      9:   PetscFunctionReturn(PETSC_SUCCESS);
     10: }

     12: PetscErrorCode DMCoarsenHierarchy_Plex(DM dm, PetscInt nlevels, DM dmCoarsened[])
     13: {
     14:   DM        rdm = dm;
     15:   PetscInt  c;
     16:   PetscBool localized;

     18:   PetscFunctionBegin;
     19:   PetscCall(DMGetCoordinatesLocalized(dm, &localized));
     20:   for (c = nlevels - 1; c >= 0; --c) {
     21:     PetscCall(DMCoarsen(rdm, PetscObjectComm((PetscObject)dm), &dmCoarsened[c]));
     22:     PetscCall(DMCopyDisc(rdm, dmCoarsened[c]));
     23:     if (localized) PetscCall(DMLocalizeCoordinates(dmCoarsened[c]));
     24:     PetscCall(DMSetCoarseDM(rdm, dmCoarsened[c]));
     25:     rdm = dmCoarsened[c];
     26:   }
     27:   PetscFunctionReturn(PETSC_SUCCESS);
     28: }