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:   PetscBool localized;

269:   PetscFunctionBegin;
271:   PetscAssertPointer(areLocalized, 2);
272:   PetscCall(DMGetCoordinatesLocalizedLocal(dm, &localized));
273:   PetscCallMPI(MPIU_Allreduce(&localized, areLocalized, 1, MPI_C_BOOL, MPI_LOR, PetscObjectComm((PetscObject)dm)));
274:   PetscFunctionReturn(PETSC_SUCCESS);
275: }

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

280:   Not collective

282:   Input Parameter:
283: . dm - The `DM`

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

288:   Level: intermediate

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

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

304:   Collective

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

310:   Level: intermediate

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

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

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

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

335:   Collective

337:   Input Parameter:
338: . dm - The `DM`

340:   Level: developer

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

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

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

388:   PetscCall(PetscSectionCreate(comm, &csDG));
389:   PetscCall(PetscSectionSetNumFields(csDG, 1));
390:   PetscCall(PetscSectionGetFieldComponents(cs, 0, &Nc));
391:   PetscCall(PetscSectionSetFieldComponents(csDG, 0, Nc));
392:   PetscCall(PetscSectionSetChart(csDG, newStart, newEnd));
393:   PetscCheck(bs == Nc, comm, PETSC_ERR_ARG_INCOMP, "Coordinate block size %" PetscInt_FMT " != %" PetscInt_FMT " number of components", bs, Nc);
394:   for (PetscInt d = 0; d < Nc; ++d) {
395:     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);
396:   }

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

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

408:       PetscCall(DMPlexGetCellType(plex, c, &ct));
409:       if (ct == DM_POLYTOPE_FV_GHOST) continue;
410:       PetscCall(DMPlexVecGetClosure(cplex, cs, coordinates, c, &dof, &cellCoords));
411:       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);
412:       for (d = 0; d < Nc; ++d) anchor[d] = cellCoords[d];
413:       for (p = 0; p < dof / Nc; ++p) {
414:         PetscCall(DMLocalizeCoordinate_Internal(dm, Nc, anchor, &cellCoords[p * Nc], localized));
415:         for (d = 0; d < Nc; ++d)
416:           if (cellCoords[p * Nc + d] != localized[d]) break;
417:         if (d < Nc) break;
418:       }
419:       if (p < dof / Nc) useDG = PETSC_TRUE;
420:       if (p < dof / Nc || !sparseLocalize) {
421:         PetscCall(PetscSectionSetDof(csDG, c, dof));
422:         PetscCall(PetscSectionSetFieldDof(csDG, c, 0, dof));
423:       }
424:       PetscCall(DMPlexVecRestoreClosure(cplex, cs, coordinates, c, &dof, &cellCoords));
425:     }
426:   }
427:   PetscCallMPI(MPIU_Allreduce(&useDG, &useDGGlobal, 1, MPI_C_BOOL, MPI_LOR, comm));
428:   if (!useDGGlobal) goto end;

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

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

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

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

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

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

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