Actual source code: dmperiodicity.c

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

  3: #include <petscdmplex.h>

  5: /*@
  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 PetscCall(PetscFree(dm->maxCell)); /* remove maxCell information to disable automatic computation of localized vertices */
 61:   if (Lstart) {
 62:     if (!dm->Lstart) PetscCall(PetscMalloc1(dim, &dm->Lstart));
 63:     for (d = 0; d < dim; ++d) dm->Lstart[d] = Lstart[d];
 64:   } else PetscCall(PetscFree(dm->Lstart)); /* remove L information to disable automatic computation of localized vertices */
 65:   if (L) {
 66:     if (!dm->L) PetscCall(PetscMalloc1(dim, &dm->L));
 67:     for (d = 0; d < dim; ++d) dm->L[d] = L[d];
 68:   } else PetscCall(PetscFree(dm->L)); /* remove L information to disable automatic computation of localized vertices */
 69:   PetscCheck((dm->maxCell && dm->L) || (!dm->maxCell && !dm->L), PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "Cannot set only one of maxCell/L");
 70:   PetscFunctionReturn(PETSC_SUCCESS);
 71: }

 73: /*@
 74:   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.

 76:   Input Parameters:
 77: + dm       - The `DM`
 78: . in       - The input coordinate point (dim numbers)
 79: - endpoint - Include the endpoint L_i

 81:   Output Parameter:
 82: . out - The localized coordinate point (dim numbers)

 84:   Level: developer

 86: .seealso: `DM`, `DMLocalizeCoordinates()`, `DMLocalizeAddCoordinate()`
 87: @*/
 88: PetscErrorCode DMLocalizeCoordinate(DM dm, const PetscScalar in[], PetscBool endpoint, PetscScalar out[])
 89: {
 90:   PetscInt dim, d;

 92:   PetscFunctionBegin;
 93:   PetscCall(DMGetCoordinateDim(dm, &dim));
 94:   if (!dm->maxCell) {
 95:     for (d = 0; d < dim; ++d) out[d] = in[d];
 96:   } else {
 97:     if (endpoint) {
 98:       for (d = 0; d < dim; ++d) {
 99:         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)) {
100:           out[d] = in[d] - dm->L[d] * (PetscFloorReal(PetscRealPart(in[d]) / dm->L[d]) - 1);
101:         } else {
102:           out[d] = in[d] - dm->L[d] * PetscFloorReal(PetscRealPart(in[d]) / dm->L[d]);
103:         }
104:       }
105:     } else {
106:       for (d = 0; d < dim; ++d) out[d] = in[d] - dm->L[d] * PetscFloorReal(PetscRealPart(in[d]) / dm->L[d]);
107:     }
108:   }
109:   PetscFunctionReturn(PETSC_SUCCESS);
110: }

112: static PetscErrorCode DMLocalizeCoordinatePerDimension_Internal(DM dm, PetscInt d, const PetscScalar anchor[], const PetscScalar in[], PetscScalar out[])
113: {
114:   PetscFunctionBegin;
115:   if ((dm->L[d] > 0.0) && (PetscAbsScalar(anchor[d] - in[d]) > dm->maxCell[d])) {
116:     out[d] = PetscRealPart(anchor[d]) > PetscRealPart(in[d]) ? dm->L[d] + in[d] : in[d] - dm->L[d];
117:   } else {
118:     out[d] = in[d];
119:   }
120:   PetscFunctionReturn(PETSC_SUCCESS);
121: }

123: /*
124:   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.

126:   Input Parameters:
127: + dm     - The `DM`
128: . dim    - The spatial dimension
129: . anchor - The anchor point, the input point can be no more than maxCell away from it
130: - in     - The input coordinate point (dim numbers)

132:   Output Parameter:
133: . out - The localized coordinate point (dim numbers)

135:   Level: developer

137:   Note:
138:   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

140: .seealso: `DM`, `DMLocalizeCoordinates()`, `DMLocalizeAddCoordinate()`
141: */
142: PetscErrorCode DMLocalizeCoordinate_Internal(DM dm, PetscInt dim, const PetscScalar anchor[], const PetscScalar in[], PetscScalar out[])
143: {
144:   PetscInt d;

146:   PetscFunctionBegin;
147:   if (!dm->maxCell) {
148:     for (d = 0; d < dim; ++d) out[d] = in[d];
149:   } else {
150:     for (d = 0; d < dim; ++d) PetscCall(DMLocalizeCoordinatePerDimension_Internal(dm, d, anchor, in, out));
151:   }
152:   PetscFunctionReturn(PETSC_SUCCESS);
153: }

155: PetscErrorCode DMLocalizeCoordinateReal_Internal(DM dm, PetscInt dim, const PetscReal anchor[], const PetscReal in[], PetscReal out[])
156: {
157:   PetscInt d;

159:   PetscFunctionBegin;
160:   if (!dm->maxCell) {
161:     for (d = 0; d < dim; ++d) out[d] = in[d];
162:   } else {
163:     for (d = 0; d < dim; ++d) {
164:       if ((dm->L[d] > 0.0) && (PetscAbsReal(anchor[d] - in[d]) > dm->maxCell[d])) {
165:         out[d] = anchor[d] > in[d] ? dm->L[d] + in[d] : in[d] - dm->L[d];
166:       } else {
167:         out[d] = in[d];
168:       }
169:     }
170:   }
171:   PetscFunctionReturn(PETSC_SUCCESS);
172: }

174: /*
175:   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.

177:   Input Parameters:
178: + dm     - The `DM`
179: . dim    - The spatial dimension
180: . anchor - The anchor point, the input point can be no more than maxCell away from it
181: . in     - The input coordinate delta (dim numbers)
182: - out    - The input coordinate point (dim numbers)

184:   Output Parameter:
185: . out    - The localized coordinate in + out

187:   Level: developer

189:   Note:
190:   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

192: .seealso: `DM`, `DMLocalizeCoordinates()`, `DMLocalizeCoordinate()`
193: */
194: PetscErrorCode DMLocalizeAddCoordinate_Internal(DM dm, PetscInt dim, const PetscScalar anchor[], const PetscScalar in[], PetscScalar out[])
195: {
196:   PetscFunctionBegin;
197:   if (!dm->maxCell) {
198:     for (PetscInt d = 0; d < dim; ++d) out[d] += in[d];
199:   } else {
200:     for (PetscInt d = 0; d < dim; ++d) {
201:       const PetscReal maxC = dm->maxCell[d];

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

206:         if (PetscAbsScalar(newCoord - anchor[d]) > maxC)
207:           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]));
208:         out[d] += newCoord;
209:       } else {
210:         out[d] += in[d];
211:       }
212:     }
213:   }
214:   PetscFunctionReturn(PETSC_SUCCESS);
215: }

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

220:   Not Collective

222:   Input Parameter:
223: . dm - The `DM`

225:   Output Parameter:
226: . areLocalized - `PETSC_TRUE` if localized

228:   Level: developer

230: .seealso: `DM`, `DMLocalizeCoordinates()`, `DMGetCoordinatesLocalized()`, `DMSetPeriodicity()`
231: @*/
232: PetscErrorCode DMGetCoordinatesLocalizedLocal(DM dm, PetscBool *areLocalized)
233: {
234:   PetscFunctionBegin;
236:   PetscAssertPointer(areLocalized, 2);
237:   *areLocalized = dm->coordinates[1].dim < 0 ? PETSC_FALSE : PETSC_TRUE;
238:   PetscFunctionReturn(PETSC_SUCCESS);
239: }

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

244:   Collective

246:   Input Parameter:
247: . dm - The `DM`

249:   Output Parameter:
250: . areLocalized - `PETSC_TRUE` if localized

252:   Level: developer

254: .seealso: `DM`, `DMLocalizeCoordinates()`, `DMSetPeriodicity()`, `DMGetCoordinatesLocalizedLocal()`
255: @*/
256: PetscErrorCode DMGetCoordinatesLocalized(DM dm, PetscBool *areLocalized)
257: {
258:   PetscFunctionBegin;
260:   PetscAssertPointer(areLocalized, 2);
261:   PetscCall(DMGetCoordinatesLocalizedLocal(dm, areLocalized));
262:   PetscCallMPI(MPIU_Allreduce(MPI_IN_PLACE, areLocalized, 1, MPI_C_BOOL, MPI_LOR, PetscObjectComm((PetscObject)dm)));
263:   PetscFunctionReturn(PETSC_SUCCESS);
264: }

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

269:   Not collective

271:   Input Parameter:
272: . dm - The `DM`

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

277:   Level: intermediate

279: .seealso: `DMSetSparseLocalize()`, `DMLocalizeCoordinates()`, `DMSetPeriodicity()`
280: @*/
281: PetscErrorCode DMGetSparseLocalize(DM dm, PetscBool *sparse)
282: {
283:   PetscFunctionBegin;
285:   PetscAssertPointer(sparse, 2);
286:   *sparse = dm->sparseLocalize;
287:   PetscFunctionReturn(PETSC_SUCCESS);
288: }

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

293:   Collective

295:   Input Parameters:
296: + dm     - The `DM`
297: - sparse - `PETSC_TRUE` if only cells near the periodic boundary are localized

299:   Level: intermediate

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

304: .seealso: `DMGetSparseLocalize()`, `DMLocalizeCoordinates()`, `DMSetPeriodicity()`
305: @*/
306: PetscErrorCode DMSetSparseLocalize(DM dm, PetscBool sparse)
307: {
308:   PetscBool prevSparse, areLocalized;

310:   PetscFunctionBegin;
313:   // Blow away previously localized coordinates if they were created with the other sparse localize option
314:   PetscCall(DMGetSparseLocalize(dm, &prevSparse));
315:   PetscCall(DMGetCoordinatesLocalized(dm, &areLocalized));
316:   if (prevSparse != sparse && areLocalized) PetscCall(DMDestroyCoordinates_Internal(&dm->coordinates[1]));
317:   dm->sparseLocalize = sparse;
318:   PetscFunctionReturn(PETSC_SUCCESS);
319: }

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

324:   Collective

326:   Input Parameter:
327: . dm - The `DM`

329:   Level: developer

331: .seealso: `DM`, `DMSetPeriodicity()`, `DMLocalizeCoordinate()`, `DMLocalizeAddCoordinate()`
332: @*/
333: PetscErrorCode DMLocalizeCoordinates(DM dm)
334: {
335:   DM               cdm, cdgdm, cplex, plex;
336:   PetscSection     cs, csDG;
337:   Vec              coordinates, cVec;
338:   PetscScalar     *coordsDG, *anchor, *localized;
339:   const PetscReal *Lstart, *L, *maxCell;
340:   PetscInt         Nc, vStart, vEnd, sStart, sEnd, newStart = PETSC_INT_MAX, newEnd = PETSC_INT_MIN, bs, coordSize;
341:   PetscBool        isLocalized, sparseLocalize, useDG = PETSC_FALSE;
342:   PetscInt         maxHeight = 0, h;
343:   PetscInt        *pStart = NULL, *pEnd = NULL;
344:   MPI_Comm         comm;

346:   PetscFunctionBegin;
348:   PetscCall(DMGetPeriodicity(dm, &maxCell, &Lstart, &L));
349:   PetscCall(DMGetSparseLocalize(dm, &sparseLocalize));
350:   /* Cannot automatically localize without L and maxCell right now */
351:   if (!L) PetscFunctionReturn(PETSC_SUCCESS);
352:   PetscCall(PetscObjectGetComm((PetscObject)dm, &comm));
353:   PetscCall(DMGetCoordinatesLocalized(dm, &isLocalized));
354:   if (isLocalized) PetscFunctionReturn(PETSC_SUCCESS);

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

377:   PetscCall(PetscSectionCreate(comm, &csDG));
378:   PetscCall(PetscSectionSetNumFields(csDG, 1));
379:   PetscCall(PetscSectionGetFieldComponents(cs, 0, &Nc));
380:   PetscCall(PetscSectionSetFieldComponents(csDG, 0, Nc));
381:   PetscCall(PetscSectionSetChart(csDG, newStart, newEnd));
382:   PetscCheck(bs == Nc, comm, PETSC_ERR_ARG_INCOMP, "Coordinate block size %" PetscInt_FMT " != %" PetscInt_FMT " number of components", bs, Nc);
383:   for (PetscInt d = 0; d < Nc; ++d) {
384:     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);
385:   }

387:   PetscCall(DMGetWorkArray(dm, 2 * Nc, MPIU_SCALAR, &anchor));
388:   localized = &anchor[Nc];
389:   for (h = 0; h <= maxHeight; h++) {
390:     PetscInt cStart = pStart[h], cEnd = pEnd[h], c;

392:     for (c = cStart; c < cEnd; ++c) {
393:       PetscScalar   *cellCoords = NULL;
394:       DMPolytopeType ct;
395:       PetscInt       dof, d, p;

397:       PetscCall(DMPlexGetCellType(plex, c, &ct));
398:       if (ct == DM_POLYTOPE_FV_GHOST) continue;
399:       PetscCall(DMPlexVecGetClosure(cplex, cs, coordinates, c, &dof, &cellCoords));
400:       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);
401:       for (d = 0; d < Nc; ++d) anchor[d] = cellCoords[d];
402:       for (p = 0; p < dof / Nc; ++p) {
403:         PetscCall(DMLocalizeCoordinate_Internal(dm, Nc, anchor, &cellCoords[p * Nc], localized));
404:         for (d = 0; d < Nc; ++d)
405:           if (cellCoords[p * Nc + d] != localized[d]) break;
406:         if (d < Nc) break;
407:       }
408:       if (p < dof / Nc) useDG = PETSC_TRUE;
409:       if (p < dof / Nc || !sparseLocalize) {
410:         PetscCall(PetscSectionSetDof(csDG, c, dof));
411:         PetscCall(PetscSectionSetFieldDof(csDG, c, 0, dof));
412:       }
413:       PetscCall(DMPlexVecRestoreClosure(cplex, cs, coordinates, c, &dof, &cellCoords));
414:     }
415:   }
416:   PetscCallMPI(MPIU_Allreduce(MPI_IN_PLACE, &useDG, 1, MPI_C_BOOL, MPI_LOR, comm));
417:   if (!useDG) goto end;

419:   PetscCall(PetscSectionSetUp(csDG));
420:   PetscCall(PetscSectionGetStorageSize(csDG, &coordSize));
421:   PetscCall(VecCreate(PETSC_COMM_SELF, &cVec));
422:   PetscCall(PetscObjectSetName((PetscObject)cVec, "coordinates"));
423:   PetscCall(VecSetBlockSize(cVec, bs));
424:   PetscCall(VecSetSizes(cVec, coordSize, PETSC_DETERMINE));
425:   PetscCall(VecSetType(cVec, VECSTANDARD));
426:   PetscCall(VecGetArray(cVec, &coordsDG));
427:   for (h = 0; h <= maxHeight; h++) {
428:     PetscInt cStart = pStart[h], cEnd = pEnd[h], c;

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

434:       PetscCall(PetscSectionGetDof(csDG, c, &cdof));
435:       if (!cdof) continue;
436:       PetscCall(DMPlexVecGetClosure(cplex, cs, coordinates, c, &dof, &cellCoords));
437:       PetscCall(PetscSectionGetOffset(csDG, c, &offDG));
438:       // Select an anchor for each dimension
439:       // TODO The coordinates are set in closure order, which might not be the tensor order
440:       for (d = 0; d < Nc; ++d) {
441:         const PetscReal start = Lstart ? Lstart[d] : 0.;

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

475:     PetscCall(DMGetField(cdm, 0, NULL, (PetscObject *)&fe));
476:     PetscCall(PetscObjectGetClassId((PetscObject)fe, &id));
477:     if (id == PETSCFE_CLASSID) {
478:       PetscSpace P;
479:       PetscInt   degree;

481:       PetscCall(PetscFEGetBasisSpace(fe, &P));
482:       PetscCall(PetscSpaceGetDegree(P, &degree, NULL));
483:       PetscCall(DMPlexCreateCoordinateSpace(dm, degree, PETSC_TRUE, PETSC_FALSE));
484:     }
485:   }
486:   PetscCall(DMSetCellCoordinateSection(dm, PETSC_DETERMINE, csDG));
487:   PetscCall(DMSetCellCoordinatesLocal(dm, cVec));
488:   PetscCall(VecDestroy(&cVec));

490: end:
491:   PetscCall(DMRestoreWorkArray(dm, 2 * bs, MPIU_SCALAR, &anchor));
492:   PetscCall(DMRestoreWorkArray(dm, 2 * (maxHeight + 1), MPIU_INT, &pStart));
493:   PetscCall(PetscSectionDestroy(&csDG));
494:   PetscCall(DMDestroy(&plex));
495:   PetscCall(DMDestroy(&cplex));
496:   PetscFunctionReturn(PETSC_SUCCESS);
497: }