Actual source code: dmperiodicity.c

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

  3: #include <petscdmplex.h>

  5: /*@C
  6:   DMGetPeriodicity - Get the description of mesh periodicity

  8:   Not collective

 10:   Input Parameter:
 11: . dm - The `DM` object

 13:   Output Parameters:
 14: + maxCell - Over distances greater than this, we can assume a point has crossed over to another sheet, when trying to localize cell coordinates
 15: . Lstart  - If we assume the mesh is a torus, this is the start of each coordinate, or `NULL` for 0.0
 16: - L       - If we assume the mesh is a torus, this is the length of each coordinate, otherwise it is < 0.0

 18:   Level: developer

 20: .seealso: `DM`
 21: @*/
 22: PetscErrorCode DMGetPeriodicity(DM dm, const PetscReal *maxCell[], const PetscReal *Lstart[], const PetscReal *L[])
 23: {
 24:   PetscFunctionBegin;
 26:   if (maxCell) *maxCell = dm->maxCell;
 27:   if (Lstart) *Lstart = dm->Lstart;
 28:   if (L) *L = dm->L;
 29:   PetscFunctionReturn(PETSC_SUCCESS);
 30: }

 32: /*@
 33:   DMSetPeriodicity - Set the description of mesh periodicity

 35:   Logically Collective

 37:   Input Parameters:
 38: + dm      - The `DM` object
 39: . maxCell - Over distances greater than this, we can assume a point has crossed over to another sheet, when trying to localize cell coordinates. Pass `NULL` to remove such information.
 40: . Lstart  - If we assume the mesh is a torus, this is the start of each coordinate, or `NULL` for 0.0
 41: - L       - If we assume the mesh is a torus, this is the length of each coordinate, otherwise it is < 0.0

 43:   Level: developer

 45: .seealso: `DM`, `DMGetPeriodicity()`
 46: @*/
 47: PetscErrorCode DMSetPeriodicity(DM dm, const PetscReal maxCell[], const PetscReal Lstart[], const PetscReal L[])
 48: {
 49:   PetscInt dim, d;

 51:   PetscFunctionBegin;
 53:   if (maxCell) PetscAssertPointer(maxCell, 2);
 54:   if (Lstart) PetscAssertPointer(Lstart, 3);
 55:   if (L) PetscAssertPointer(L, 4);
 56:   PetscCall(DMGetDimension(dm, &dim));
 57:   if (maxCell) {
 58:     if (!dm->maxCell) PetscCall(PetscMalloc1(dim, &dm->maxCell));
 59:     for (d = 0; d < dim; ++d) dm->maxCell[d] = maxCell[d];
 60:   } else { /* remove maxCell information to disable automatic computation of localized vertices */
 61:     PetscCall(PetscFree(dm->maxCell));
 62:     dm->maxCell = NULL;
 63:   }
 64:   if (Lstart) {
 65:     if (!dm->Lstart) PetscCall(PetscMalloc1(dim, &dm->Lstart));
 66:     for (d = 0; d < dim; ++d) dm->Lstart[d] = Lstart[d];
 67:   } else { /* remove L information to disable automatic computation of localized vertices */
 68:     PetscCall(PetscFree(dm->Lstart));
 69:     dm->Lstart = NULL;
 70:   }
 71:   if (L) {
 72:     if (!dm->L) PetscCall(PetscMalloc1(dim, &dm->L));
 73:     for (d = 0; d < dim; ++d) dm->L[d] = L[d];
 74:   } else { /* remove L information to disable automatic computation of localized vertices */
 75:     PetscCall(PetscFree(dm->L));
 76:     dm->L = NULL;
 77:   }
 78:   PetscCheck((dm->maxCell && dm->L) || (!dm->maxCell && !dm->L), PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "Cannot set only one of maxCell/L");
 79:   PetscFunctionReturn(PETSC_SUCCESS);
 80: }

 82: /*@
 83:   DMLocalizeCoordinate - If a mesh is periodic (a torus with lengths L_i, some of which can be infinite), project the coordinate onto [0, L_i) in each dimension.

 85:   Input Parameters:
 86: + dm       - The `DM`
 87: . in       - The input coordinate point (dim numbers)
 88: - endpoint - Include the endpoint L_i

 90:   Output Parameter:
 91: . out - The localized coordinate point (dim numbers)

 93:   Level: developer

 95: .seealso: `DM`, `DMLocalizeCoordinates()`, `DMLocalizeAddCoordinate()`
 96: @*/
 97: PetscErrorCode DMLocalizeCoordinate(DM dm, const PetscScalar in[], PetscBool endpoint, PetscScalar out[])
 98: {
 99:   PetscInt dim, d;

101:   PetscFunctionBegin;
102:   PetscCall(DMGetCoordinateDim(dm, &dim));
103:   if (!dm->maxCell) {
104:     for (d = 0; d < dim; ++d) out[d] = in[d];
105:   } else {
106:     if (endpoint) {
107:       for (d = 0; d < dim; ++d) {
108:         if ((PetscAbsReal(PetscRealPart(in[d]) / dm->L[d] - PetscFloorReal(PetscRealPart(in[d]) / dm->L[d])) < PETSC_SMALL) && (PetscRealPart(in[d]) / dm->L[d] > PETSC_SMALL)) {
109:           out[d] = in[d] - dm->L[d] * (PetscFloorReal(PetscRealPart(in[d]) / dm->L[d]) - 1);
110:         } else {
111:           out[d] = in[d] - dm->L[d] * PetscFloorReal(PetscRealPart(in[d]) / dm->L[d]);
112:         }
113:       }
114:     } else {
115:       for (d = 0; d < dim; ++d) out[d] = in[d] - dm->L[d] * PetscFloorReal(PetscRealPart(in[d]) / dm->L[d]);
116:     }
117:   }
118:   PetscFunctionReturn(PETSC_SUCCESS);
119: }

121: static PetscErrorCode DMLocalizeCoordinatePerDimension_Internal(DM dm, PetscInt d, const PetscScalar anchor[], const PetscScalar in[], PetscScalar out[])
122: {
123:   PetscFunctionBegin;
124:   if ((dm->L[d] > 0.0) && (PetscAbsScalar(anchor[d] - in[d]) > dm->maxCell[d])) {
125:     out[d] = PetscRealPart(anchor[d]) > PetscRealPart(in[d]) ? dm->L[d] + in[d] : in[d] - dm->L[d];
126:   } else {
127:     out[d] = in[d];
128:   }
129:   PetscFunctionReturn(PETSC_SUCCESS);
130: }

132: /*
133:   DMLocalizeCoordinate_Internal - If a mesh is periodic, and the input point is far from the anchor, pick the coordinate sheet of the torus which moves it closer.

135:   Input Parameters:
136: + dm     - The `DM`
137: . dim    - The spatial dimension
138: . anchor - The anchor point, the input point can be no more than maxCell away from it
139: - in     - The input coordinate point (dim numbers)

141:   Output Parameter:
142: . out - The localized coordinate point (dim numbers)

144:   Level: developer

146:   Note:
147:   This is meant to get a set of coordinates close to each other, as in a cell. The anchor is usually the one of the vertices on a containing cell

149: .seealso: `DM`, `DMLocalizeCoordinates()`, `DMLocalizeAddCoordinate()`
150: */
151: PetscErrorCode DMLocalizeCoordinate_Internal(DM dm, PetscInt dim, const PetscScalar anchor[], const PetscScalar in[], PetscScalar out[])
152: {
153:   PetscInt d;

155:   PetscFunctionBegin;
156:   if (!dm->maxCell) {
157:     for (d = 0; d < dim; ++d) out[d] = in[d];
158:   } else {
159:     for (d = 0; d < dim; ++d) PetscCall(DMLocalizeCoordinatePerDimension_Internal(dm, d, anchor, in, out));
160:   }
161:   PetscFunctionReturn(PETSC_SUCCESS);
162: }

164: PetscErrorCode DMLocalizeCoordinateReal_Internal(DM dm, PetscInt dim, const PetscReal anchor[], const PetscReal in[], PetscReal out[])
165: {
166:   PetscInt d;

168:   PetscFunctionBegin;
169:   if (!dm->maxCell) {
170:     for (d = 0; d < dim; ++d) out[d] = in[d];
171:   } else {
172:     for (d = 0; d < dim; ++d) {
173:       if ((dm->L[d] > 0.0) && (PetscAbsReal(anchor[d] - in[d]) > dm->maxCell[d])) {
174:         out[d] = anchor[d] > in[d] ? dm->L[d] + in[d] : in[d] - dm->L[d];
175:       } else {
176:         out[d] = in[d];
177:       }
178:     }
179:   }
180:   PetscFunctionReturn(PETSC_SUCCESS);
181: }

183: /*
184:   DMLocalizeAddCoordinate_Internal - If a mesh is periodic, and the input point is far from the anchor, pick the coordinate sheet of the torus which moves it closer.

186:   Input Parameters:
187: + dm     - The `DM`
188: . dim    - The spatial dimension
189: . anchor - The anchor point, the input point can be no more than maxCell away from it
190: . in     - The input coordinate delta (dim numbers)
191: - out    - The input coordinate point (dim numbers)

193:   Output Parameter:
194: . out    - The localized coordinate in + out

196:   Level: developer

198:   Note:
199:   This is meant to get a set of coordinates close to each other, as in a cell. The anchor is usually one of the vertices on a containing cell

201: .seealso: `DM`, `DMLocalizeCoordinates()`, `DMLocalizeCoordinate()`
202: */
203: PetscErrorCode DMLocalizeAddCoordinate_Internal(DM dm, PetscInt dim, const PetscScalar anchor[], const PetscScalar in[], PetscScalar out[])
204: {
205:   PetscFunctionBegin;
206:   if (!dm->maxCell) {
207:     for (PetscInt d = 0; d < dim; ++d) out[d] += in[d];
208:   } else {
209:     for (PetscInt d = 0; d < dim; ++d) {
210:       const PetscReal maxC = dm->maxCell[d];

212:       if ((dm->L[d] > 0.0) && (PetscAbsScalar(anchor[d] - in[d]) > maxC)) {
213:         const PetscScalar newCoord = PetscRealPart(anchor[d]) > PetscRealPart(in[d]) ? dm->L[d] + in[d] : in[d] - dm->L[d];

215:         if (PetscAbsScalar(newCoord - anchor[d]) > maxC)
216:           SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "%" PetscInt_FMT "-Coordinate %g more than %g away from anchor %g", d, (double)PetscRealPart(in[d]), (double)maxC, (double)PetscRealPart(anchor[d]));
217:         out[d] += newCoord;
218:       } else {
219:         out[d] += in[d];
220:       }
221:     }
222:   }
223:   PetscFunctionReturn(PETSC_SUCCESS);
224: }

226: /*@
227:   DMGetCoordinatesLocalizedLocal - Check if the `DM` coordinates have been localized for cells on this process

229:   Not Collective

231:   Input Parameter:
232: . dm - The `DM`

234:   Output Parameter:
235: . areLocalized - `PETSC_TRUE` if localized

237:   Level: developer

239: .seealso: `DM`, `DMLocalizeCoordinates()`, `DMGetCoordinatesLocalized()`, `DMSetPeriodicity()`
240: @*/
241: PetscErrorCode DMGetCoordinatesLocalizedLocal(DM dm, PetscBool *areLocalized)
242: {
243:   PetscFunctionBegin;
245:   PetscAssertPointer(areLocalized, 2);
246:   *areLocalized = dm->coordinates[1].dim < 0 ? PETSC_FALSE : PETSC_TRUE;
247:   PetscFunctionReturn(PETSC_SUCCESS);
248: }

250: /*@
251:   DMGetCoordinatesLocalized - Check if the `DM` coordinates have been localized for cells

253:   Collective

255:   Input Parameter:
256: . dm - The `DM`

258:   Output Parameter:
259: . areLocalized - `PETSC_TRUE` if localized

261:   Level: developer

263: .seealso: `DM`, `DMLocalizeCoordinates()`, `DMSetPeriodicity()`, `DMGetCoordinatesLocalizedLocal()`
264: @*/
265: PetscErrorCode DMGetCoordinatesLocalized(DM dm, PetscBool *areLocalized)
266: {
267:   PetscFunctionBegin;
269:   PetscAssertPointer(areLocalized, 2);
270:   PetscCall(DMGetCoordinatesLocalizedLocal(dm, areLocalized));
271:   PetscCallMPI(MPIU_Allreduce(MPI_IN_PLACE, areLocalized, 1, MPI_C_BOOL, MPI_LOR, PetscObjectComm((PetscObject)dm)));
272:   PetscFunctionReturn(PETSC_SUCCESS);
273: }

275: /*@
276:   DMGetSparseLocalize - Check if the `DM` coordinates should be localized only for cells near the periodic boundary.

278:   Not collective

280:   Input Parameter:
281: . dm - The `DM`

283:   Output Parameter:
284: . sparse - `PETSC_TRUE` if only cells near the periodic boundary are localized

286:   Level: intermediate

288: .seealso: `DMSetSparseLocalize()`, `DMLocalizeCoordinates()`, `DMSetPeriodicity()`
289: @*/
290: PetscErrorCode DMGetSparseLocalize(DM dm, PetscBool *sparse)
291: {
292:   PetscFunctionBegin;
294:   PetscAssertPointer(sparse, 2);
295:   *sparse = dm->sparseLocalize;
296:   PetscFunctionReturn(PETSC_SUCCESS);
297: }

299: /*@
300:   DMSetSparseLocalize - Set the flag indicating that `DM` coordinates should be localized only for cells near the periodic boundary.

302:   Collective

304:   Input Parameters:
305: + dm     - The `DM`
306: - sparse - `PETSC_TRUE` if only cells near the periodic boundary are localized

308:   Level: intermediate

310:   Note:
311:   If previous cell coordinates existed with a different sparse localization then these will be destroyed.

313: .seealso: `DMGetSparseLocalize()`, `DMLocalizeCoordinates()`, `DMSetPeriodicity()`
314: @*/
315: PetscErrorCode DMSetSparseLocalize(DM dm, PetscBool sparse)
316: {
317:   PetscBool prevSparse, areLocalized;

319:   PetscFunctionBegin;
322:   // Blow away previously localized coordinates if they were created with the other sparse localize option
323:   PetscCall(DMGetSparseLocalize(dm, &prevSparse));
324:   PetscCall(DMGetCoordinatesLocalized(dm, &areLocalized));
325:   if (prevSparse != sparse && areLocalized) PetscCall(DMDestroyCoordinates_Internal(&dm->coordinates[1]));
326:   dm->sparseLocalize = sparse;
327:   PetscFunctionReturn(PETSC_SUCCESS);
328: }

330: /*@
331:   DMLocalizeCoordinates - If a mesh is periodic, create local coordinates for cells having periodic faces

333:   Collective

335:   Input Parameter:
336: . dm - The `DM`

338:   Level: developer

340: .seealso: `DM`, `DMSetPeriodicity()`, `DMLocalizeCoordinate()`, `DMLocalizeAddCoordinate()`
341: @*/
342: PetscErrorCode DMLocalizeCoordinates(DM dm)
343: {
344:   DM               cdm, cdgdm, cplex, plex;
345:   PetscSection     cs, csDG;
346:   Vec              coordinates, cVec;
347:   PetscScalar     *coordsDG, *anchor, *localized;
348:   const PetscReal *Lstart, *L, *maxCell;
349:   PetscInt         Nc, vStart, vEnd, sStart, sEnd, newStart = PETSC_INT_MAX, newEnd = PETSC_INT_MIN, bs, coordSize;
350:   PetscBool        isLocalized, sparseLocalize, useDG = PETSC_FALSE;
351:   PetscInt         maxHeight = 0, h;
352:   PetscInt        *pStart = NULL, *pEnd = NULL;
353:   MPI_Comm         comm;

355:   PetscFunctionBegin;
357:   PetscCall(DMGetPeriodicity(dm, &maxCell, &Lstart, &L));
358:   PetscCall(DMGetSparseLocalize(dm, &sparseLocalize));
359:   /* Cannot automatically localize without L and maxCell right now */
360:   if (!L) PetscFunctionReturn(PETSC_SUCCESS);
361:   PetscCall(PetscObjectGetComm((PetscObject)dm, &comm));
362:   PetscCall(DMGetCoordinatesLocalized(dm, &isLocalized));
363:   if (isLocalized) PetscFunctionReturn(PETSC_SUCCESS);

365:   PetscCall(DMGetCoordinateDM(dm, &cdm));
366:   PetscCall(DMConvert(dm, DMPLEX, &plex));
367:   PetscCall(DMConvert(cdm, DMPLEX, &cplex));
368:   PetscCheck(cplex, comm, PETSC_ERR_ARG_WRONG, "Coordinate localization requires a DMPLEX coordinate DM");
369:   PetscCall(DMPlexGetDepthStratum(cplex, 0, &vStart, &vEnd));
370:   PetscCall(DMPlexGetMaxProjectionHeight(cplex, &maxHeight));
371:   PetscCall(DMGetWorkArray(dm, 2 * (maxHeight + 1), MPIU_INT, &pStart));
372:   pEnd     = &pStart[maxHeight + 1];
373:   newStart = vStart;
374:   newEnd   = vEnd;
375:   for (h = 0; h <= maxHeight; h++) {
376:     PetscCall(DMPlexGetHeightStratum(cplex, h, &pStart[h], &pEnd[h]));
377:     newStart = PetscMin(newStart, pStart[h]);
378:     newEnd   = PetscMax(newEnd, pEnd[h]);
379:   }
380:   PetscCall(DMGetCoordinatesLocal(dm, &coordinates));
381:   PetscCheck(coordinates, comm, PETSC_ERR_SUP, "Missing local coordinate vector");
382:   PetscCall(DMGetCoordinateSection(dm, &cs));
383:   PetscCall(VecGetBlockSize(coordinates, &bs));
384:   PetscCall(PetscSectionGetChart(cs, &sStart, &sEnd));

386:   PetscCall(PetscSectionCreate(comm, &csDG));
387:   PetscCall(PetscSectionSetNumFields(csDG, 1));
388:   PetscCall(PetscSectionGetFieldComponents(cs, 0, &Nc));
389:   PetscCall(PetscSectionSetFieldComponents(csDG, 0, Nc));
390:   PetscCall(PetscSectionSetChart(csDG, newStart, newEnd));
391:   PetscCheck(bs == Nc, comm, PETSC_ERR_ARG_INCOMP, "Coordinate block size %" PetscInt_FMT " != %" PetscInt_FMT " number of components", bs, Nc);
392:   for (PetscInt d = 0; d < Nc; ++d) {
393:     PetscCheck(L[d] < 0. || (maxCell[d] > 0. && maxCell[d] < 2 * L[d]), comm, PETSC_ERR_ARG_INCOMP, "Periodic length %g > max cell size %g in dimension %" PetscInt_FMT, (double)L[d], (double)maxCell[d], d);
394:   }

396:   PetscCall(DMGetWorkArray(dm, 2 * Nc, MPIU_SCALAR, &anchor));
397:   localized = &anchor[Nc];
398:   for (h = 0; h <= maxHeight; h++) {
399:     PetscInt cStart = pStart[h], cEnd = pEnd[h], c;

401:     for (c = cStart; c < cEnd; ++c) {
402:       PetscScalar   *cellCoords = NULL;
403:       DMPolytopeType ct;
404:       PetscInt       dof, d, p;

406:       PetscCall(DMPlexGetCellType(plex, c, &ct));
407:       if (ct == DM_POLYTOPE_FV_GHOST) continue;
408:       PetscCall(DMPlexVecGetClosure(cplex, cs, coordinates, c, &dof, &cellCoords));
409:       PetscCheck(!(dof % Nc), comm, PETSC_ERR_ARG_INCOMP, "Coordinate size on cell %" PetscInt_FMT " closure %" PetscInt_FMT " not divisible by %" PetscInt_FMT " number of components", c, dof, Nc);
410:       for (d = 0; d < Nc; ++d) anchor[d] = cellCoords[d];
411:       for (p = 0; p < dof / Nc; ++p) {
412:         PetscCall(DMLocalizeCoordinate_Internal(dm, Nc, anchor, &cellCoords[p * Nc], localized));
413:         for (d = 0; d < Nc; ++d)
414:           if (cellCoords[p * Nc + d] != localized[d]) break;
415:         if (d < Nc) break;
416:       }
417:       if (p < dof / Nc) useDG = PETSC_TRUE;
418:       if (p < dof / Nc || !sparseLocalize) {
419:         PetscCall(PetscSectionSetDof(csDG, c, dof));
420:         PetscCall(PetscSectionSetFieldDof(csDG, c, 0, dof));
421:       }
422:       PetscCall(DMPlexVecRestoreClosure(cplex, cs, coordinates, c, &dof, &cellCoords));
423:     }
424:   }
425:   PetscCallMPI(MPIU_Allreduce(MPI_IN_PLACE, &useDG, 1, MPI_C_BOOL, MPI_LOR, comm));
426:   if (!useDG) goto end;

428:   PetscCall(PetscSectionSetUp(csDG));
429:   PetscCall(PetscSectionGetStorageSize(csDG, &coordSize));
430:   PetscCall(VecCreate(PETSC_COMM_SELF, &cVec));
431:   PetscCall(PetscObjectSetName((PetscObject)cVec, "coordinates"));
432:   PetscCall(VecSetBlockSize(cVec, bs));
433:   PetscCall(VecSetSizes(cVec, coordSize, PETSC_DETERMINE));
434:   PetscCall(VecSetType(cVec, VECSTANDARD));
435:   PetscCall(VecGetArray(cVec, &coordsDG));
436:   for (h = 0; h <= maxHeight; h++) {
437:     PetscInt cStart = pStart[h], cEnd = pEnd[h], c;

439:     for (c = cStart; c < cEnd; ++c) {
440:       PetscScalar *cellCoords = NULL;
441:       PetscInt     p          = 0, q, dof, cdof, d, offDG;

443:       PetscCall(PetscSectionGetDof(csDG, c, &cdof));
444:       if (!cdof) continue;
445:       PetscCall(DMPlexVecGetClosure(cplex, cs, coordinates, c, &dof, &cellCoords));
446:       PetscCall(PetscSectionGetOffset(csDG, c, &offDG));
447:       // Select an anchor for each dimension
448:       // TODO The coordinates are set in closure order, which might not be the tensor order
449:       for (d = 0; d < Nc; ++d) {
450:         const PetscReal start = Lstart ? Lstart[d] : 0.;

452:         for (q = 0; q < dof / Nc; ++q) {
453:           anchor[d] = cellCoords[q * Nc + d];
454:           // Map anchor into [Lstart, Lstart+L)
455:           if (L[d] > 0.0) {
456:             if (PetscRealPart(anchor[d]) < start) anchor[d] += L[d];
457:             else if (PetscRealPart(anchor[d]) > start + L[d]) anchor[d] -= L[d];
458:             PetscCheck(PetscRealPart(anchor[d]) >= start && PetscRealPart(anchor[d]) < start + L[d], PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Anchor %g out of bounds for dimension %" PetscInt_FMT, (double)PetscRealPart(anchor[d]), d);
459:           }
460:           for (p = 0; p < dof / Nc; ++p) {
461:             PetscCall(DMLocalizeCoordinatePerDimension_Internal(dm, d, anchor, &cellCoords[p * Nc], &coordsDG[offDG + p * Nc]));
462:             // We need the cell to fit into the torus [lower, lower+L)
463:             if (L[d] > 0. && ((PetscRealPart(coordsDG[offDG + p * Nc + d]) < start) || (PetscRealPart(coordsDG[offDG + p * Nc + d]) > start + L[d]))) break;
464:           }
465:           // Suitable anchor found, continue
466:           if (p == dof / Nc) break;
467:         }
468:         // No suitable anchor found, abort
469:         if (q == dof / Nc) break;
470:       }
471:       PetscCheck(d == Nc, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Cell %" PetscInt_FMT " does not fit into the torus %s[0, L]", c, Lstart ? "Lstart + " : "");
472:       PetscCall(DMPlexVecRestoreClosure(cplex, cs, coordinates, c, &dof, &cellCoords));
473:     }
474:   }
475:   PetscCall(VecRestoreArray(cVec, &coordsDG));
476:   PetscUseTypeMethod(dm, createcellcoordinatedm, &cdgdm);
477:   PetscCall(DMSetCellCoordinateDM(dm, cdgdm));
478:   PetscCall(DMDestroy(&cdgdm));
479:   // Convert the discretization
480:   {
481:     PetscFE      fe;
482:     PetscClassId id;

484:     PetscCall(DMGetField(cdm, 0, NULL, (PetscObject *)&fe));
485:     PetscCall(PetscObjectGetClassId((PetscObject)fe, &id));
486:     if (id == PETSCFE_CLASSID) {
487:       PetscSpace P;
488:       PetscInt   degree;

490:       PetscCall(PetscFEGetBasisSpace(fe, &P));
491:       PetscCall(PetscSpaceGetDegree(P, &degree, NULL));
492:       PetscCall(DMPlexCreateCoordinateSpace(dm, degree, PETSC_TRUE, PETSC_FALSE));
493:     }
494:   }
495:   PetscCall(DMSetCellCoordinateSection(dm, PETSC_DETERMINE, csDG));
496:   PetscCall(DMSetCellCoordinatesLocal(dm, cVec));
497:   PetscCall(VecDestroy(&cVec));

499: end:
500:   PetscCall(DMRestoreWorkArray(dm, 2 * bs, MPIU_SCALAR, &anchor));
501:   PetscCall(DMRestoreWorkArray(dm, 2 * (maxHeight + 1), MPIU_INT, &pStart));
502:   PetscCall(PetscSectionDestroy(&csDG));
503:   PetscCall(DMDestroy(&plex));
504:   PetscCall(DMDestroy(&cplex));
505:   PetscFunctionReturn(PETSC_SUCCESS);
506: }