xref: /petsc/src/dm/impls/plex/plexcoarsen.c (revision 9566063d113dddea24716c546802770db7481bc0)
1919ab0a2SMatthew G. Knepley #include <petsc/private/dmpleximpl.h>   /*I      "petscdmplex.h"   I*/
29f3102b2SMatthew G. Knepley 
3919ab0a2SMatthew G. Knepley PetscErrorCode DMCoarsen_Plex(DM dm, MPI_Comm comm, DM *dmCoarsened)
4919ab0a2SMatthew G. Knepley {
5919ab0a2SMatthew G. Knepley   PetscFunctionBegin;
6*9566063dSJacob Faibussowitsch   if (!dm->coarseMesh) PetscCall(DMPlexCoarsen_Internal(dm, NULL, NULL, NULL, &dm->coarseMesh));
7*9566063dSJacob Faibussowitsch   PetscCall(PetscObjectReference((PetscObject) dm->coarseMesh));
8a8fb8f29SToby Isaac   *dmCoarsened = dm->coarseMesh;
9919ab0a2SMatthew G. Knepley   PetscFunctionReturn(0);
10919ab0a2SMatthew G. Knepley }
11b653a561SMatthew G. Knepley 
12b653a561SMatthew G. Knepley PetscErrorCode DMCoarsenHierarchy_Plex(DM dm, PetscInt nlevels, DM dmCoarsened[])
13b653a561SMatthew G. Knepley {
14b653a561SMatthew G. Knepley   DM             rdm = dm;
15b653a561SMatthew G. Knepley   PetscInt       c;
160d1cd5e0SMatthew G. Knepley   PetscBool      localized;
17b653a561SMatthew G. Knepley 
18b653a561SMatthew G. Knepley   PetscFunctionBegin;
19*9566063dSJacob Faibussowitsch   PetscCall(DMGetCoordinatesLocalized(dm, &localized));
20b653a561SMatthew G. Knepley   for (c = nlevels-1; c >= 0; --c) {
21*9566063dSJacob Faibussowitsch     PetscCall(DMCoarsen(rdm, PetscObjectComm((PetscObject) dm), &dmCoarsened[c]));
22*9566063dSJacob Faibussowitsch     PetscCall(DMCopyDisc(rdm, dmCoarsened[c]));
23*9566063dSJacob Faibussowitsch     if (localized) PetscCall(DMLocalizeCoordinates(dmCoarsened[c]));
24*9566063dSJacob Faibussowitsch     PetscCall(DMSetCoarseDM(rdm, dmCoarsened[c]));
25b653a561SMatthew G. Knepley     rdm  = dmCoarsened[c];
26b653a561SMatthew G. Knepley   }
27b653a561SMatthew G. Knepley   PetscFunctionReturn(0);
28b653a561SMatthew G. Knepley }
29