13a074057SBarry Smith #include <petsc/private/dmpleximpl.h> /*I "petscdmplex.h" I*/ 23a074057SBarry Smith 30fdc7489SMatthew Knepley #ifdef PETSC_HAVE_EGADS 40fdc7489SMatthew Knepley #include <egads.h> 55552b385SBrandon #include <egads_lite.h> 60fdc7489SMatthew Knepley #endif 70fdc7489SMatthew Knepley 8b83bf3d7SVaclav Hapla #if defined(PETSC_HAVE_TETGEN_TETLIBRARY_NEEDED) 9b83bf3d7SVaclav Hapla #define TETLIBRARY 10b83bf3d7SVaclav Hapla #endif 11f22e26b7SPierre Jolivet #if defined(__clang__) 12f22e26b7SPierre Jolivet #pragma clang diagnostic push 13f22e26b7SPierre Jolivet #pragma clang diagnostic ignored "-Wunused-parameter" 14f22e26b7SPierre Jolivet #pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" 15f22e26b7SPierre Jolivet #elif defined(__GNUC__) || defined(__GNUG__) 16f22e26b7SPierre Jolivet #pragma GCC diagnostic push 17f22e26b7SPierre Jolivet #pragma GCC diagnostic ignored "-Wunused-parameter" 18f22e26b7SPierre Jolivet #endif 193a074057SBarry Smith #include <tetgen.h> 20f22e26b7SPierre Jolivet #if defined(__clang__) 21f22e26b7SPierre Jolivet #pragma clang diagnostic pop 22f22e26b7SPierre Jolivet #elif defined(__GNUC__) || defined(__GNUG__) 23f22e26b7SPierre Jolivet #pragma GCC diagnostic pop 24f22e26b7SPierre Jolivet #endif 253a074057SBarry Smith 263a074057SBarry Smith /* This is to fix the tetrahedron orientation from TetGen */ 27d71ae5a4SJacob Faibussowitsch static PetscErrorCode DMPlexInvertCells_Tetgen(PetscInt numCells, PetscInt numCorners, PetscInt cells[]) 28d71ae5a4SJacob Faibussowitsch { 293a074057SBarry Smith PetscInt bound = numCells * numCorners, coff; 303a074057SBarry Smith 313a074057SBarry Smith PetscFunctionBegin; 329371c9d4SSatish Balay #define SWAP(a, b) \ 339371c9d4SSatish Balay do { \ 349371c9d4SSatish Balay PetscInt tmp = (a); \ 359371c9d4SSatish Balay (a) = (b); \ 369371c9d4SSatish Balay (b) = tmp; \ 379371c9d4SSatish Balay } while (0) 3896ca5757SLisandro Dalcin for (coff = 0; coff < bound; coff += numCorners) SWAP(cells[coff], cells[coff + 1]); 3996ca5757SLisandro Dalcin #undef SWAP 403ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 413a074057SBarry Smith } 423a074057SBarry Smith 43d71ae5a4SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode DMPlexGenerate_Tetgen(DM boundary, PetscBool interpolate, DM *dm) 44d71ae5a4SJacob Faibussowitsch { 453a074057SBarry Smith MPI_Comm comm; 463a074057SBarry Smith const PetscInt dim = 3; 473a074057SBarry Smith ::tetgenio in; 483a074057SBarry Smith ::tetgenio out; 499318fe57SMatthew G. Knepley PetscContainer modelObj; 500fdc7489SMatthew Knepley DMUniversalLabel universal; 51af226901SMatthew G. Knepley PetscInt vStart, vEnd, v, eStart, eEnd, e, fStart, fEnd, f, defVal; 520fdc7489SMatthew Knepley DMPlexInterpolatedFlag isInterpolated; 533a074057SBarry Smith PetscMPIInt rank; 54196d9482SMatthew G. Knepley PetscBool flg; 55196d9482SMatthew G. Knepley char opts[64]; 563a074057SBarry Smith 573a074057SBarry Smith PetscFunctionBegin; 589566063dSJacob Faibussowitsch PetscCall(PetscObjectGetComm((PetscObject)boundary, &comm)); 599566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_rank(comm, &rank)); 609566063dSJacob Faibussowitsch PetscCall(DMPlexIsInterpolatedCollective(boundary, &isInterpolated)); 619566063dSJacob Faibussowitsch PetscCall(DMUniversalLabelCreate(boundary, &universal)); 62af226901SMatthew G. Knepley PetscCall(DMLabelGetDefaultValue(universal->label, &defVal)); 63196d9482SMatthew G. Knepley PetscCall(PetscOptionsGetString(((PetscObject)boundary)->options, ((PetscObject)boundary)->prefix, "-dm_plex_generate_tetgen_opts", opts, sizeof(opts), &flg)); 64196d9482SMatthew G. Knepley if (flg) PetscCall(DMPlexTetgenSetOptions(boundary, opts)); 653a074057SBarry Smith 669566063dSJacob Faibussowitsch PetscCall(DMPlexGetDepthStratum(boundary, 0, &vStart, &vEnd)); 673a074057SBarry Smith in.numberofpoints = vEnd - vStart; 683a074057SBarry Smith if (in.numberofpoints > 0) { 693a074057SBarry Smith PetscSection coordSection; 703a074057SBarry Smith Vec coordinates; 710fdc7489SMatthew Knepley const PetscScalar *array; 723a074057SBarry Smith 733a074057SBarry Smith in.pointlist = new double[in.numberofpoints * dim]; 743a074057SBarry Smith in.pointmarkerlist = new int[in.numberofpoints]; 753a074057SBarry Smith 7641e9d8b5SMatthew G. Knepley PetscCall(PetscArrayzero(in.pointmarkerlist, (size_t)in.numberofpoints)); 779566063dSJacob Faibussowitsch PetscCall(DMGetCoordinatesLocal(boundary, &coordinates)); 789566063dSJacob Faibussowitsch PetscCall(DMGetCoordinateSection(boundary, &coordSection)); 799566063dSJacob Faibussowitsch PetscCall(VecGetArrayRead(coordinates, &array)); 803a074057SBarry Smith for (v = vStart; v < vEnd; ++v) { 813a074057SBarry Smith const PetscInt idx = v - vStart; 820fdc7489SMatthew Knepley PetscInt off, d, val; 833a074057SBarry Smith 849566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(coordSection, v, &off)); 853a074057SBarry Smith for (d = 0; d < dim; ++d) in.pointlist[idx * dim + d] = PetscRealPart(array[off + d]); 869566063dSJacob Faibussowitsch PetscCall(DMLabelGetValue(universal->label, v, &val)); 87af226901SMatthew G. Knepley if (val != defVal) in.pointmarkerlist[idx] = (int)val; 883a074057SBarry Smith } 899566063dSJacob Faibussowitsch PetscCall(VecRestoreArrayRead(coordinates, &array)); 903a074057SBarry Smith } 913a074057SBarry Smith 929566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(boundary, 1, &eStart, &eEnd)); 930fdc7489SMatthew Knepley in.numberofedges = eEnd - eStart; 940fdc7489SMatthew Knepley if (isInterpolated == DMPLEX_INTERPOLATED_FULL && in.numberofedges > 0) { 950fdc7489SMatthew Knepley in.edgelist = new int[in.numberofedges * 2]; 960fdc7489SMatthew Knepley in.edgemarkerlist = new int[in.numberofedges]; 970fdc7489SMatthew Knepley for (e = eStart; e < eEnd; ++e) { 980fdc7489SMatthew Knepley const PetscInt idx = e - eStart; 990fdc7489SMatthew Knepley const PetscInt *cone; 1000fdc7489SMatthew Knepley PetscInt coneSize, val; 1010fdc7489SMatthew Knepley 1029566063dSJacob Faibussowitsch PetscCall(DMPlexGetConeSize(boundary, e, &coneSize)); 1039566063dSJacob Faibussowitsch PetscCall(DMPlexGetCone(boundary, e, &cone)); 1040fdc7489SMatthew Knepley in.edgelist[idx * 2] = cone[0] - vStart; 1050fdc7489SMatthew Knepley in.edgelist[idx * 2 + 1] = cone[1] - vStart; 1060fdc7489SMatthew Knepley 1079566063dSJacob Faibussowitsch PetscCall(DMLabelGetValue(universal->label, e, &val)); 108af226901SMatthew G. Knepley if (val != defVal) in.edgemarkerlist[idx] = (int)val; 1090fdc7489SMatthew Knepley } 1100fdc7489SMatthew Knepley } 1110fdc7489SMatthew Knepley 1129566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(boundary, 0, &fStart, &fEnd)); 1133a074057SBarry Smith in.numberoffacets = fEnd - fStart; 1143a074057SBarry Smith if (in.numberoffacets > 0) { 1153a074057SBarry Smith in.facetlist = new tetgenio::facet[in.numberoffacets]; 1163a074057SBarry Smith in.facetmarkerlist = new int[in.numberoffacets]; 1173a074057SBarry Smith for (f = fStart; f < fEnd; ++f) { 1183a074057SBarry Smith const PetscInt idx = f - fStart; 119f22e26b7SPierre Jolivet PetscInt *points = nullptr, numPoints, p, numVertices = 0, v, val = -1; 1203a074057SBarry Smith 1213a074057SBarry Smith in.facetlist[idx].numberofpolygons = 1; 1223a074057SBarry Smith in.facetlist[idx].polygonlist = new tetgenio::polygon[in.facetlist[idx].numberofpolygons]; 1233a074057SBarry Smith in.facetlist[idx].numberofholes = 0; 124f22e26b7SPierre Jolivet in.facetlist[idx].holelist = nullptr; 1253a074057SBarry Smith 1269566063dSJacob Faibussowitsch PetscCall(DMPlexGetTransitiveClosure(boundary, f, PETSC_TRUE, &numPoints, &points)); 1273a074057SBarry Smith for (p = 0; p < numPoints * 2; p += 2) { 1283a074057SBarry Smith const PetscInt point = points[p]; 1293a074057SBarry Smith if ((point >= vStart) && (point < vEnd)) points[numVertices++] = point; 1303a074057SBarry Smith } 1313a074057SBarry Smith 1323a074057SBarry Smith tetgenio::polygon *poly = in.facetlist[idx].polygonlist; 1333a074057SBarry Smith poly->numberofvertices = numVertices; 1343a074057SBarry Smith poly->vertexlist = new int[poly->numberofvertices]; 1353a074057SBarry Smith for (v = 0; v < numVertices; ++v) { 1363a074057SBarry Smith const PetscInt vIdx = points[v] - vStart; 1373a074057SBarry Smith poly->vertexlist[v] = vIdx; 1383a074057SBarry Smith } 1399566063dSJacob Faibussowitsch PetscCall(DMLabelGetValue(universal->label, f, &val)); 140af226901SMatthew G. Knepley if (val != defVal) in.facetmarkerlist[idx] = (int)val; 1419566063dSJacob Faibussowitsch PetscCall(DMPlexRestoreTransitiveClosure(boundary, f, PETSC_TRUE, &numPoints, &points)); 1423a074057SBarry Smith } 1433a074057SBarry Smith } 144dd400576SPatrick Sanan if (rank == 0) { 1450fdc7489SMatthew Knepley DM_Plex *mesh = (DM_Plex *)boundary->data; 1463a074057SBarry Smith char args[32]; 1473a074057SBarry Smith 1483a074057SBarry Smith /* Take away 'Q' for verbose output */ 1490fdc7489SMatthew Knepley #ifdef PETSC_HAVE_EGADS 1505552b385SBrandon PetscCall(PetscStrncpy(args, "pYqezQY", sizeof(args))); 1510fdc7489SMatthew Knepley #else 152c6a7a370SJeremy L Thompson PetscCall(PetscStrncpy(args, "pqezQ", sizeof(args))); 1530fdc7489SMatthew Knepley #endif 1549371c9d4SSatish Balay if (mesh->tetgenOpts) { 1559371c9d4SSatish Balay ::tetrahedralize(mesh->tetgenOpts, &in, &out); 1569371c9d4SSatish Balay } else { 1579371c9d4SSatish Balay ::tetrahedralize(args, &in, &out); 1589371c9d4SSatish Balay } 1593a074057SBarry Smith } 1603a074057SBarry Smith { 1613a074057SBarry Smith const PetscInt numCorners = 4; 1623a074057SBarry Smith const PetscInt numCells = out.numberoftetrahedra; 1633a074057SBarry Smith const PetscInt numVertices = out.numberofpoints; 164f22e26b7SPierre Jolivet PetscReal *meshCoords = nullptr; 165f22e26b7SPierre Jolivet PetscInt *cells = nullptr; 166a4a685f2SJacob Faibussowitsch 167a4a685f2SJacob Faibussowitsch if (sizeof(PetscReal) == sizeof(out.pointlist[0])) { 168a4a685f2SJacob Faibussowitsch meshCoords = (PetscReal *)out.pointlist; 169a4a685f2SJacob Faibussowitsch } else { 170a4a685f2SJacob Faibussowitsch PetscInt i; 171a4a685f2SJacob Faibussowitsch 172a4a685f2SJacob Faibussowitsch meshCoords = new PetscReal[dim * numVertices]; 1730fdc7489SMatthew Knepley for (i = 0; i < dim * numVertices; ++i) meshCoords[i] = (PetscReal)out.pointlist[i]; 174a4a685f2SJacob Faibussowitsch } 175a4a685f2SJacob Faibussowitsch if (sizeof(PetscInt) == sizeof(out.tetrahedronlist[0])) { 176a4a685f2SJacob Faibussowitsch cells = (PetscInt *)out.tetrahedronlist; 177a4a685f2SJacob Faibussowitsch } else { 178a4a685f2SJacob Faibussowitsch PetscInt i; 179a4a685f2SJacob Faibussowitsch 180a4a685f2SJacob Faibussowitsch cells = new PetscInt[numCells * numCorners]; 1810fdc7489SMatthew Knepley for (i = 0; i < numCells * numCorners; i++) cells[i] = (PetscInt)out.tetrahedronlist[i]; 182a4a685f2SJacob Faibussowitsch } 1833a074057SBarry Smith 1849566063dSJacob Faibussowitsch PetscCall(DMPlexInvertCells_Tetgen(numCells, numCorners, cells)); 1859566063dSJacob Faibussowitsch PetscCall(DMPlexCreateFromCellListPetsc(comm, dim, numCells, numVertices, numCorners, interpolate, cells, dim, meshCoords, dm)); 1860fdc7489SMatthew Knepley 1873a074057SBarry Smith /* Set labels */ 1889566063dSJacob Faibussowitsch PetscCall(DMUniversalLabelCreateLabels(universal, PETSC_TRUE, *dm)); 1893a074057SBarry Smith for (v = 0; v < numVertices; ++v) { 19048a46eb9SPierre Jolivet if (out.pointmarkerlist[v]) PetscCall(DMUniversalLabelSetLabelValue(universal, *dm, PETSC_TRUE, v + numCells, out.pointmarkerlist[v])); 1913a074057SBarry Smith } 1923a074057SBarry Smith if (interpolate) { 1933a074057SBarry Smith PetscInt e; 1943a074057SBarry Smith 1953a074057SBarry Smith for (e = 0; e < out.numberofedges; e++) { 1963a074057SBarry Smith if (out.edgemarkerlist[e]) { 1973a074057SBarry Smith const PetscInt vertices[2] = {out.edgelist[e * 2 + 0] + numCells, out.edgelist[e * 2 + 1] + numCells}; 1983a074057SBarry Smith const PetscInt *edges; 1993a074057SBarry Smith PetscInt numEdges; 2003a074057SBarry Smith 2019566063dSJacob Faibussowitsch PetscCall(DMPlexGetJoin(*dm, 2, vertices, &numEdges, &edges)); 20263a3b9bcSJacob Faibussowitsch PetscCheck(numEdges == 1, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Two vertices must cover only one edge, not %" PetscInt_FMT, numEdges); 2039566063dSJacob Faibussowitsch PetscCall(DMUniversalLabelSetLabelValue(universal, *dm, PETSC_TRUE, edges[0], out.edgemarkerlist[e])); 2049566063dSJacob Faibussowitsch PetscCall(DMPlexRestoreJoin(*dm, 2, vertices, &numEdges, &edges)); 2053a074057SBarry Smith } 2063a074057SBarry Smith } 2073a074057SBarry Smith for (f = 0; f < out.numberoftrifaces; f++) { 2083a074057SBarry Smith if (out.trifacemarkerlist[f]) { 2093a074057SBarry Smith const PetscInt vertices[3] = {out.trifacelist[f * 3 + 0] + numCells, out.trifacelist[f * 3 + 1] + numCells, out.trifacelist[f * 3 + 2] + numCells}; 2103a074057SBarry Smith const PetscInt *faces; 2113a074057SBarry Smith PetscInt numFaces; 2123a074057SBarry Smith 2139566063dSJacob Faibussowitsch PetscCall(DMPlexGetFullJoin(*dm, 3, vertices, &numFaces, &faces)); 21463a3b9bcSJacob Faibussowitsch PetscCheck(numFaces == 1, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Three vertices must cover only one face, not %" PetscInt_FMT, numFaces); 2159566063dSJacob Faibussowitsch PetscCall(DMUniversalLabelSetLabelValue(universal, *dm, PETSC_TRUE, faces[0], out.trifacemarkerlist[f])); 2169566063dSJacob Faibussowitsch PetscCall(DMPlexRestoreJoin(*dm, 3, vertices, &numFaces, &faces)); 2173a074057SBarry Smith } 2183a074057SBarry Smith } 2193a074057SBarry Smith } 2200fdc7489SMatthew Knepley 2219566063dSJacob Faibussowitsch PetscCall(PetscObjectQuery((PetscObject)boundary, "EGADS Model", (PetscObject *)&modelObj)); 2223a7d0413SPierre Jolivet if (!modelObj) PetscCall(PetscObjectQuery((PetscObject)boundary, "EGADSlite Model", (PetscObject *)&modelObj)); 2235552b385SBrandon 2249318fe57SMatthew G. Knepley if (modelObj) { 2250fdc7489SMatthew Knepley #ifdef PETSC_HAVE_EGADS 2260fdc7489SMatthew Knepley DMLabel bodyLabel; 2270fdc7489SMatthew Knepley PetscInt cStart, cEnd, c, eStart, eEnd, fStart, fEnd; 228c1cad2e7SMatthew G. Knepley PetscBool islite = PETSC_FALSE; 2290fdc7489SMatthew Knepley ego *bodies; 2300fdc7489SMatthew Knepley ego model, geom; 2310fdc7489SMatthew Knepley int Nb, oclass, mtype, *senses; 2320fdc7489SMatthew Knepley 2335552b385SBrandon PetscCall(DMPlexCopyEGADSInfo_Internal(boundary, *dm)); 2345552b385SBrandon 2355552b385SBrandon // Get Attached EGADS Model from Original DMPlex 2369566063dSJacob Faibussowitsch PetscCall(PetscObjectQuery((PetscObject)boundary, "EGADS Model", (PetscObject *)&modelObj)); 237c1cad2e7SMatthew G. Knepley if (modelObj) { 238*2a8381b2SBarry Smith PetscCall(PetscContainerGetPointer(modelObj, &model)); 239f22e26b7SPierre Jolivet PetscCall(EG_getTopology(model, &geom, &oclass, &mtype, nullptr, &Nb, &bodies, &senses)); 240c1cad2e7SMatthew G. Knepley } else { 2415552b385SBrandon PetscCall(PetscObjectQuery((PetscObject)boundary, "EGADSlite Model", (PetscObject *)&modelObj)); 242c1cad2e7SMatthew G. Knepley if (modelObj) { 243*2a8381b2SBarry Smith PetscCall(PetscContainerGetPointer(modelObj, &model)); 244f22e26b7SPierre Jolivet PetscCall(EGlite_getTopology(model, &geom, &oclass, &mtype, nullptr, &Nb, &bodies, &senses)); 245c1cad2e7SMatthew G. Knepley islite = PETSC_TRUE; 246c1cad2e7SMatthew G. Knepley } 247c1cad2e7SMatthew G. Knepley } 248c1cad2e7SMatthew G. Knepley if (!modelObj) goto skip_egads; 2490fdc7489SMatthew Knepley 2500fdc7489SMatthew Knepley /* Set Cell Labels */ 2519566063dSJacob Faibussowitsch PetscCall(DMGetLabel(*dm, "EGADS Body ID", &bodyLabel)); 2529566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(*dm, 0, &cStart, &cEnd)); 2539566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(*dm, 1, &fStart, &fEnd)); 2549566063dSJacob Faibussowitsch PetscCall(DMPlexGetDepthStratum(*dm, 1, &eStart, &eEnd)); 2550fdc7489SMatthew Knepley 2560fdc7489SMatthew Knepley for (c = cStart; c < cEnd; ++c) { 2570fdc7489SMatthew Knepley PetscReal centroid[3] = {0., 0., 0.}; 2580fdc7489SMatthew Knepley PetscInt b; 2590fdc7489SMatthew Knepley 26035cb6cd3SPierre Jolivet /* Determine what body the cell's centroid is located in */ 2610fdc7489SMatthew Knepley if (!interpolate) { 2620fdc7489SMatthew Knepley PetscSection coordSection; 2630fdc7489SMatthew Knepley Vec coordinates; 264f22e26b7SPierre Jolivet PetscScalar *coords = nullptr; 2650fdc7489SMatthew Knepley PetscInt coordSize, s, d; 2660fdc7489SMatthew Knepley 2679566063dSJacob Faibussowitsch PetscCall(DMGetCoordinatesLocal(*dm, &coordinates)); 2689566063dSJacob Faibussowitsch PetscCall(DMGetCoordinateSection(*dm, &coordSection)); 2699566063dSJacob Faibussowitsch PetscCall(DMPlexVecGetClosure(*dm, coordSection, coordinates, c, &coordSize, &coords)); 2709371c9d4SSatish Balay for (s = 0; s < coordSize; ++s) 2719371c9d4SSatish Balay for (d = 0; d < dim; ++d) centroid[d] += coords[s * dim + d]; 2729566063dSJacob Faibussowitsch PetscCall(DMPlexVecRestoreClosure(*dm, coordSection, coordinates, c, &coordSize, &coords)); 273f22e26b7SPierre Jolivet } else PetscCall(DMPlexComputeCellGeometryFVM(*dm, c, nullptr, centroid, nullptr)); 2740fdc7489SMatthew Knepley for (b = 0; b < Nb; ++b) { 2759371c9d4SSatish Balay if (islite) { 2769371c9d4SSatish Balay if (EGlite_inTopology(bodies[b], centroid) == EGADS_SUCCESS) break; 2779371c9d4SSatish Balay } else { 2789371c9d4SSatish Balay if (EG_inTopology(bodies[b], centroid) == EGADS_SUCCESS) break; 2799371c9d4SSatish Balay } 2800fdc7489SMatthew Knepley } 2810fdc7489SMatthew Knepley if (b < Nb) { 2820fdc7489SMatthew Knepley PetscInt cval = b, eVal, fVal; 283f22e26b7SPierre Jolivet PetscInt *closure = nullptr, Ncl, cl; 2840fdc7489SMatthew Knepley 2859566063dSJacob Faibussowitsch PetscCall(DMLabelSetValue(bodyLabel, c, cval)); 2869566063dSJacob Faibussowitsch PetscCall(DMPlexGetTransitiveClosure(*dm, c, PETSC_TRUE, &Ncl, &closure)); 2870fdc7489SMatthew Knepley for (cl = 0; cl < Ncl; cl += 2) { 2880fdc7489SMatthew Knepley const PetscInt p = closure[cl]; 2890fdc7489SMatthew Knepley 2900fdc7489SMatthew Knepley if (p >= eStart && p < eEnd) { 2919566063dSJacob Faibussowitsch PetscCall(DMLabelGetValue(bodyLabel, p, &eVal)); 2929566063dSJacob Faibussowitsch if (eVal < 0) PetscCall(DMLabelSetValue(bodyLabel, p, cval)); 2930fdc7489SMatthew Knepley } 2940fdc7489SMatthew Knepley if (p >= fStart && p < fEnd) { 2959566063dSJacob Faibussowitsch PetscCall(DMLabelGetValue(bodyLabel, p, &fVal)); 2969566063dSJacob Faibussowitsch if (fVal < 0) PetscCall(DMLabelSetValue(bodyLabel, p, cval)); 2970fdc7489SMatthew Knepley } 2980fdc7489SMatthew Knepley } 2999566063dSJacob Faibussowitsch PetscCall(DMPlexRestoreTransitiveClosure(*dm, c, PETSC_TRUE, &Ncl, &closure)); 3000fdc7489SMatthew Knepley } 3010fdc7489SMatthew Knepley } 302c1cad2e7SMatthew G. Knepley skip_egads:; 3030fdc7489SMatthew Knepley #endif 3049318fe57SMatthew G. Knepley } 3059566063dSJacob Faibussowitsch PetscCall(DMPlexSetRefinementUniform(*dm, PETSC_FALSE)); 3063a074057SBarry Smith } 3079566063dSJacob Faibussowitsch PetscCall(DMUniversalLabelDestroy(&universal)); 3083ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3093a074057SBarry Smith } 3103a074057SBarry Smith 311d71ae5a4SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode DMPlexRefine_Tetgen(DM dm, double *maxVolumes, DM *dmRefined) 312d71ae5a4SJacob Faibussowitsch { 3133a074057SBarry Smith MPI_Comm comm; 3143a074057SBarry Smith const PetscInt dim = 3; 3153a074057SBarry Smith ::tetgenio in; 3163a074057SBarry Smith ::tetgenio out; 3179318fe57SMatthew G. Knepley PetscContainer modelObj; 3180fdc7489SMatthew Knepley DMUniversalLabel universal; 319af226901SMatthew G. Knepley PetscInt vStart, vEnd, v, eStart, eEnd, e, fStart, fEnd, f, cStart, cEnd, c, defVal; 3200fdc7489SMatthew Knepley DMPlexInterpolatedFlag isInterpolated; 3213a074057SBarry Smith PetscMPIInt rank; 3223a074057SBarry Smith 3233a074057SBarry Smith PetscFunctionBegin; 3249566063dSJacob Faibussowitsch PetscCall(PetscObjectGetComm((PetscObject)dm, &comm)); 3259566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_rank(comm, &rank)); 3269566063dSJacob Faibussowitsch PetscCall(DMPlexIsInterpolatedCollective(dm, &isInterpolated)); 3279566063dSJacob Faibussowitsch PetscCall(DMUniversalLabelCreate(dm, &universal)); 328af226901SMatthew G. Knepley PetscCall(DMLabelGetDefaultValue(universal->label, &defVal)); 3293a074057SBarry Smith 3309566063dSJacob Faibussowitsch PetscCall(DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd)); 3313a074057SBarry Smith in.numberofpoints = vEnd - vStart; 3323a074057SBarry Smith if (in.numberofpoints > 0) { 3333a074057SBarry Smith PetscSection coordSection; 3343a074057SBarry Smith Vec coordinates; 3353a074057SBarry Smith PetscScalar *array; 3363a074057SBarry Smith 3373a074057SBarry Smith in.pointlist = new double[in.numberofpoints * dim]; 3383a074057SBarry Smith in.pointmarkerlist = new int[in.numberofpoints]; 3393a074057SBarry Smith 34041e9d8b5SMatthew G. Knepley PetscCall(PetscArrayzero(in.pointmarkerlist, (size_t)in.numberofpoints)); 3419566063dSJacob Faibussowitsch PetscCall(DMGetCoordinatesLocal(dm, &coordinates)); 3429566063dSJacob Faibussowitsch PetscCall(DMGetCoordinateSection(dm, &coordSection)); 3439566063dSJacob Faibussowitsch PetscCall(VecGetArray(coordinates, &array)); 3443a074057SBarry Smith for (v = vStart; v < vEnd; ++v) { 3453a074057SBarry Smith const PetscInt idx = v - vStart; 3460fdc7489SMatthew Knepley PetscInt off, d, val; 3473a074057SBarry Smith 3489566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(coordSection, v, &off)); 3493a074057SBarry Smith for (d = 0; d < dim; ++d) in.pointlist[idx * dim + d] = PetscRealPart(array[off + d]); 3509566063dSJacob Faibussowitsch PetscCall(DMLabelGetValue(universal->label, v, &val)); 351af226901SMatthew G. Knepley if (val != defVal) in.pointmarkerlist[idx] = (int)val; 3523a074057SBarry Smith } 3539566063dSJacob Faibussowitsch PetscCall(VecRestoreArray(coordinates, &array)); 3543a074057SBarry Smith } 3553a074057SBarry Smith 3569566063dSJacob Faibussowitsch PetscCall(DMPlexGetDepthStratum(dm, 1, &eStart, &eEnd)); 3570fdc7489SMatthew Knepley in.numberofedges = eEnd - eStart; 3580fdc7489SMatthew Knepley if (isInterpolated == DMPLEX_INTERPOLATED_FULL && in.numberofedges > 0) { 3590fdc7489SMatthew Knepley in.edgelist = new int[in.numberofedges * 2]; 3600fdc7489SMatthew Knepley in.edgemarkerlist = new int[in.numberofedges]; 3610fdc7489SMatthew Knepley for (e = eStart; e < eEnd; ++e) { 3620fdc7489SMatthew Knepley const PetscInt idx = e - eStart; 3630fdc7489SMatthew Knepley const PetscInt *cone; 3640fdc7489SMatthew Knepley PetscInt coneSize, val; 3650fdc7489SMatthew Knepley 3669566063dSJacob Faibussowitsch PetscCall(DMPlexGetConeSize(dm, e, &coneSize)); 3679566063dSJacob Faibussowitsch PetscCall(DMPlexGetCone(dm, e, &cone)); 3680fdc7489SMatthew Knepley in.edgelist[idx * 2] = cone[0] - vStart; 3690fdc7489SMatthew Knepley in.edgelist[idx * 2 + 1] = cone[1] - vStart; 3700fdc7489SMatthew Knepley 3719566063dSJacob Faibussowitsch PetscCall(DMLabelGetValue(universal->label, e, &val)); 372af226901SMatthew G. Knepley if (val != defVal) in.edgemarkerlist[idx] = (int)val; 3730fdc7489SMatthew Knepley } 3740fdc7489SMatthew Knepley } 3750fdc7489SMatthew Knepley 3769566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(dm, 1, &fStart, &fEnd)); 3770fdc7489SMatthew Knepley in.numberoffacets = fEnd - fStart; 3780fdc7489SMatthew Knepley if (isInterpolated == DMPLEX_INTERPOLATED_FULL && in.numberoffacets > 0) { 3790fdc7489SMatthew Knepley in.facetlist = new tetgenio::facet[in.numberoffacets]; 3800fdc7489SMatthew Knepley in.facetmarkerlist = new int[in.numberoffacets]; 3810fdc7489SMatthew Knepley for (f = fStart; f < fEnd; ++f) { 3820fdc7489SMatthew Knepley const PetscInt idx = f - fStart; 383f22e26b7SPierre Jolivet PetscInt *points = nullptr, numPoints, p, numVertices = 0, v, val; 3840fdc7489SMatthew Knepley 3850fdc7489SMatthew Knepley in.facetlist[idx].numberofpolygons = 1; 3860fdc7489SMatthew Knepley in.facetlist[idx].polygonlist = new tetgenio::polygon[in.facetlist[idx].numberofpolygons]; 3870fdc7489SMatthew Knepley in.facetlist[idx].numberofholes = 0; 388f22e26b7SPierre Jolivet in.facetlist[idx].holelist = nullptr; 3890fdc7489SMatthew Knepley 3909566063dSJacob Faibussowitsch PetscCall(DMPlexGetTransitiveClosure(dm, f, PETSC_TRUE, &numPoints, &points)); 3910fdc7489SMatthew Knepley for (p = 0; p < numPoints * 2; p += 2) { 3920fdc7489SMatthew Knepley const PetscInt point = points[p]; 3930fdc7489SMatthew Knepley if ((point >= vStart) && (point < vEnd)) points[numVertices++] = point; 3940fdc7489SMatthew Knepley } 3950fdc7489SMatthew Knepley 3960fdc7489SMatthew Knepley tetgenio::polygon *poly = in.facetlist[idx].polygonlist; 3970fdc7489SMatthew Knepley poly->numberofvertices = numVertices; 3980fdc7489SMatthew Knepley poly->vertexlist = new int[poly->numberofvertices]; 3990fdc7489SMatthew Knepley for (v = 0; v < numVertices; ++v) { 4000fdc7489SMatthew Knepley const PetscInt vIdx = points[v] - vStart; 4010fdc7489SMatthew Knepley poly->vertexlist[v] = vIdx; 4020fdc7489SMatthew Knepley } 4030fdc7489SMatthew Knepley 4049566063dSJacob Faibussowitsch PetscCall(DMLabelGetValue(universal->label, f, &val)); 405af226901SMatthew G. Knepley if (val != defVal) in.facetmarkerlist[idx] = (int)val; 4060fdc7489SMatthew Knepley 4079566063dSJacob Faibussowitsch PetscCall(DMPlexRestoreTransitiveClosure(dm, f, PETSC_TRUE, &numPoints, &points)); 4080fdc7489SMatthew Knepley } 4090fdc7489SMatthew Knepley } 4100fdc7489SMatthew Knepley 4119566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd)); 4123a074057SBarry Smith in.numberofcorners = 4; 4133a074057SBarry Smith in.numberoftetrahedra = cEnd - cStart; 4143a074057SBarry Smith in.tetrahedronvolumelist = (double *)maxVolumes; 4153a074057SBarry Smith if (in.numberoftetrahedra > 0) { 4163a074057SBarry Smith in.tetrahedronlist = new int[in.numberoftetrahedra * in.numberofcorners]; 4173a074057SBarry Smith for (c = cStart; c < cEnd; ++c) { 4183a074057SBarry Smith const PetscInt idx = c - cStart; 419f22e26b7SPierre Jolivet PetscInt *closure = nullptr; 4203a074057SBarry Smith PetscInt closureSize; 4213a074057SBarry Smith 4229566063dSJacob Faibussowitsch PetscCall(DMPlexGetTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure)); 42363a3b9bcSJacob Faibussowitsch PetscCheck(!(closureSize != 5) || !(closureSize != 15), comm, PETSC_ERR_ARG_WRONG, "Mesh has cell which is not a tetrahedron, %" PetscInt_FMT " vertices in closure", closureSize); 4240fdc7489SMatthew Knepley for (v = 0; v < 4; ++v) in.tetrahedronlist[idx * in.numberofcorners + v] = closure[(v + closureSize - 4) * 2] - vStart; 4259566063dSJacob Faibussowitsch PetscCall(DMPlexRestoreTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure)); 4263a074057SBarry Smith } 4273a074057SBarry Smith } 4280fdc7489SMatthew Knepley 429dd400576SPatrick Sanan if (rank == 0) { 4303a074057SBarry Smith char args[32]; 4313a074057SBarry Smith 4323a074057SBarry Smith /* Take away 'Q' for verbose output */ 433c6a7a370SJeremy L Thompson PetscCall(PetscStrncpy(args, "qezQra", sizeof(args))); 4343a074057SBarry Smith ::tetrahedralize(args, &in, &out); 4353a074057SBarry Smith } 4363a074057SBarry Smith 437f22e26b7SPierre Jolivet in.tetrahedronvolumelist = nullptr; 4383a074057SBarry Smith { 4393a074057SBarry Smith const PetscInt numCorners = 4; 4403a074057SBarry Smith const PetscInt numCells = out.numberoftetrahedra; 4413a074057SBarry Smith const PetscInt numVertices = out.numberofpoints; 442f22e26b7SPierre Jolivet PetscReal *meshCoords = nullptr; 443f22e26b7SPierre Jolivet PetscInt *cells = nullptr; 4440fdc7489SMatthew Knepley PetscBool interpolate = isInterpolated == DMPLEX_INTERPOLATED_FULL ? PETSC_TRUE : PETSC_FALSE; 4453a074057SBarry Smith 446a4a685f2SJacob Faibussowitsch if (sizeof(PetscReal) == sizeof(out.pointlist[0])) { 447a4a685f2SJacob Faibussowitsch meshCoords = (PetscReal *)out.pointlist; 448a4a685f2SJacob Faibussowitsch } else { 449a4a685f2SJacob Faibussowitsch PetscInt i; 450a4a685f2SJacob Faibussowitsch 451a4a685f2SJacob Faibussowitsch meshCoords = new PetscReal[dim * numVertices]; 4520fdc7489SMatthew Knepley for (i = 0; i < dim * numVertices; ++i) meshCoords[i] = (PetscReal)out.pointlist[i]; 453a4a685f2SJacob Faibussowitsch } 454a4a685f2SJacob Faibussowitsch if (sizeof(PetscInt) == sizeof(out.tetrahedronlist[0])) { 455a4a685f2SJacob Faibussowitsch cells = (PetscInt *)out.tetrahedronlist; 456a4a685f2SJacob Faibussowitsch } else { 457a4a685f2SJacob Faibussowitsch PetscInt i; 458a4a685f2SJacob Faibussowitsch 459a4a685f2SJacob Faibussowitsch cells = new PetscInt[numCells * numCorners]; 4600fdc7489SMatthew Knepley for (i = 0; i < numCells * numCorners; ++i) cells[i] = (PetscInt)out.tetrahedronlist[i]; 461a4a685f2SJacob Faibussowitsch } 462a4a685f2SJacob Faibussowitsch 4639566063dSJacob Faibussowitsch PetscCall(DMPlexInvertCells_Tetgen(numCells, numCorners, cells)); 4649566063dSJacob Faibussowitsch PetscCall(DMPlexCreateFromCellListPetsc(comm, dim, numCells, numVertices, numCorners, interpolate, cells, dim, meshCoords, dmRefined)); 465ad540459SPierre Jolivet if (sizeof(PetscReal) != sizeof(out.pointlist[0])) delete[] meshCoords; 466ad540459SPierre Jolivet if (sizeof(PetscInt) != sizeof(out.tetrahedronlist[0])) delete[] cells; 4670fdc7489SMatthew Knepley 4683a074057SBarry Smith /* Set labels */ 4699566063dSJacob Faibussowitsch PetscCall(DMUniversalLabelCreateLabels(universal, PETSC_TRUE, *dmRefined)); 4703a074057SBarry Smith for (v = 0; v < numVertices; ++v) { 47148a46eb9SPierre Jolivet if (out.pointmarkerlist[v]) PetscCall(DMUniversalLabelSetLabelValue(universal, *dmRefined, PETSC_TRUE, v + numCells, out.pointmarkerlist[v])); 4723a074057SBarry Smith } 4733a074057SBarry Smith if (interpolate) { 4740fdc7489SMatthew Knepley PetscInt e, f; 4753a074057SBarry Smith 4760fdc7489SMatthew Knepley for (e = 0; e < out.numberofedges; ++e) { 4773a074057SBarry Smith if (out.edgemarkerlist[e]) { 4783a074057SBarry Smith const PetscInt vertices[2] = {out.edgelist[e * 2 + 0] + numCells, out.edgelist[e * 2 + 1] + numCells}; 4793a074057SBarry Smith const PetscInt *edges; 4803a074057SBarry Smith PetscInt numEdges; 4813a074057SBarry Smith 4829566063dSJacob Faibussowitsch PetscCall(DMPlexGetJoin(*dmRefined, 2, vertices, &numEdges, &edges)); 48363a3b9bcSJacob Faibussowitsch PetscCheck(numEdges == 1, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Two vertices must cover only one edge, not %" PetscInt_FMT, numEdges); 4849566063dSJacob Faibussowitsch PetscCall(DMUniversalLabelSetLabelValue(universal, *dmRefined, PETSC_TRUE, edges[0], out.edgemarkerlist[e])); 4859566063dSJacob Faibussowitsch PetscCall(DMPlexRestoreJoin(*dmRefined, 2, vertices, &numEdges, &edges)); 4863a074057SBarry Smith } 4873a074057SBarry Smith } 4880fdc7489SMatthew Knepley for (f = 0; f < out.numberoftrifaces; ++f) { 4893a074057SBarry Smith if (out.trifacemarkerlist[f]) { 4903a074057SBarry Smith const PetscInt vertices[3] = {out.trifacelist[f * 3 + 0] + numCells, out.trifacelist[f * 3 + 1] + numCells, out.trifacelist[f * 3 + 2] + numCells}; 4913a074057SBarry Smith const PetscInt *faces; 4923a074057SBarry Smith PetscInt numFaces; 4933a074057SBarry Smith 4949566063dSJacob Faibussowitsch PetscCall(DMPlexGetFullJoin(*dmRefined, 3, vertices, &numFaces, &faces)); 49563a3b9bcSJacob Faibussowitsch PetscCheck(numFaces == 1, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Three vertices must cover only one face, not %" PetscInt_FMT, numFaces); 4969566063dSJacob Faibussowitsch PetscCall(DMUniversalLabelSetLabelValue(universal, *dmRefined, PETSC_TRUE, faces[0], out.trifacemarkerlist[f])); 4979566063dSJacob Faibussowitsch PetscCall(DMPlexRestoreJoin(*dmRefined, 3, vertices, &numFaces, &faces)); 4983a074057SBarry Smith } 4993a074057SBarry Smith } 5003a074057SBarry Smith } 5010fdc7489SMatthew Knepley 5029566063dSJacob Faibussowitsch PetscCall(PetscObjectQuery((PetscObject)dm, "EGADS Model", (PetscObject *)&modelObj)); 5039318fe57SMatthew G. Knepley if (modelObj) { 5040fdc7489SMatthew Knepley #ifdef PETSC_HAVE_EGADS 5050fdc7489SMatthew Knepley DMLabel bodyLabel; 5060fdc7489SMatthew Knepley PetscInt cStart, cEnd, c, eStart, eEnd, fStart, fEnd; 507c1cad2e7SMatthew G. Knepley PetscBool islite = PETSC_FALSE; 5080fdc7489SMatthew Knepley ego *bodies; 5090fdc7489SMatthew Knepley ego model, geom; 5100fdc7489SMatthew Knepley int Nb, oclass, mtype, *senses; 5110fdc7489SMatthew Knepley 5125552b385SBrandon PetscCall(DMPlexCopyEGADSInfo_Internal(dm, *dmRefined)); 5135552b385SBrandon 5140fdc7489SMatthew Knepley /* Get Attached EGADS Model from Original DMPlex */ 5159566063dSJacob Faibussowitsch PetscCall(PetscObjectQuery((PetscObject)dm, "EGADS Model", (PetscObject *)&modelObj)); 516c1cad2e7SMatthew G. Knepley if (modelObj) { 517*2a8381b2SBarry Smith PetscCall(PetscContainerGetPointer(modelObj, &model)); 518f22e26b7SPierre Jolivet PetscCall(EG_getTopology(model, &geom, &oclass, &mtype, nullptr, &Nb, &bodies, &senses)); 519c1cad2e7SMatthew G. Knepley } else { 5205552b385SBrandon PetscCall(PetscObjectQuery((PetscObject)dm, "EGADSlite Model", (PetscObject *)&modelObj)); 521c1cad2e7SMatthew G. Knepley if (modelObj) { 522*2a8381b2SBarry Smith PetscCall(PetscContainerGetPointer(modelObj, &model)); 523f22e26b7SPierre Jolivet PetscCall(EGlite_getTopology(model, &geom, &oclass, &mtype, nullptr, &Nb, &bodies, &senses)); 524c1cad2e7SMatthew G. Knepley islite = PETSC_TRUE; 525c1cad2e7SMatthew G. Knepley } 526c1cad2e7SMatthew G. Knepley } 527c1cad2e7SMatthew G. Knepley if (!modelObj) goto skip_egads; 5280fdc7489SMatthew Knepley 5290fdc7489SMatthew Knepley /* Set Cell Labels */ 5309566063dSJacob Faibussowitsch PetscCall(DMGetLabel(*dmRefined, "EGADS Body ID", &bodyLabel)); 5319566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(*dmRefined, 0, &cStart, &cEnd)); 5329566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(*dmRefined, 1, &fStart, &fEnd)); 5339566063dSJacob Faibussowitsch PetscCall(DMPlexGetDepthStratum(*dmRefined, 1, &eStart, &eEnd)); 5340fdc7489SMatthew Knepley 5350fdc7489SMatthew Knepley for (c = cStart; c < cEnd; ++c) { 5360fdc7489SMatthew Knepley PetscReal centroid[3] = {0., 0., 0.}; 5370fdc7489SMatthew Knepley PetscInt b; 5380fdc7489SMatthew Knepley 53935cb6cd3SPierre Jolivet /* Determine what body the cell's centroid is located in */ 5400fdc7489SMatthew Knepley if (!interpolate) { 5410fdc7489SMatthew Knepley PetscSection coordSection; 5420fdc7489SMatthew Knepley Vec coordinates; 543f22e26b7SPierre Jolivet PetscScalar *coords = nullptr; 5440fdc7489SMatthew Knepley PetscInt coordSize, s, d; 5450fdc7489SMatthew Knepley 5469566063dSJacob Faibussowitsch PetscCall(DMGetCoordinatesLocal(*dmRefined, &coordinates)); 5479566063dSJacob Faibussowitsch PetscCall(DMGetCoordinateSection(*dmRefined, &coordSection)); 5489566063dSJacob Faibussowitsch PetscCall(DMPlexVecGetClosure(*dmRefined, coordSection, coordinates, c, &coordSize, &coords)); 5499371c9d4SSatish Balay for (s = 0; s < coordSize; ++s) 5509371c9d4SSatish Balay for (d = 0; d < dim; ++d) centroid[d] += coords[s * dim + d]; 5519566063dSJacob Faibussowitsch PetscCall(DMPlexVecRestoreClosure(*dmRefined, coordSection, coordinates, c, &coordSize, &coords)); 552f22e26b7SPierre Jolivet } else PetscCall(DMPlexComputeCellGeometryFVM(*dmRefined, c, nullptr, centroid, nullptr)); 5530fdc7489SMatthew Knepley for (b = 0; b < Nb; ++b) { 5549371c9d4SSatish Balay if (islite) { 5559371c9d4SSatish Balay if (EGlite_inTopology(bodies[b], centroid) == EGADS_SUCCESS) break; 5569371c9d4SSatish Balay } else { 5579371c9d4SSatish Balay if (EG_inTopology(bodies[b], centroid) == EGADS_SUCCESS) break; 5589371c9d4SSatish Balay } 5590fdc7489SMatthew Knepley } 5600fdc7489SMatthew Knepley if (b < Nb) { 5610fdc7489SMatthew Knepley PetscInt cval = b, eVal, fVal; 562f22e26b7SPierre Jolivet PetscInt *closure = nullptr, Ncl, cl; 5630fdc7489SMatthew Knepley 5649566063dSJacob Faibussowitsch PetscCall(DMLabelSetValue(bodyLabel, c, cval)); 5659566063dSJacob Faibussowitsch PetscCall(DMPlexGetTransitiveClosure(*dmRefined, c, PETSC_TRUE, &Ncl, &closure)); 5660fdc7489SMatthew Knepley for (cl = 0; cl < Ncl; cl += 2) { 5670fdc7489SMatthew Knepley const PetscInt p = closure[cl]; 5680fdc7489SMatthew Knepley 5690fdc7489SMatthew Knepley if (p >= eStart && p < eEnd) { 5709566063dSJacob Faibussowitsch PetscCall(DMLabelGetValue(bodyLabel, p, &eVal)); 5719566063dSJacob Faibussowitsch if (eVal < 0) PetscCall(DMLabelSetValue(bodyLabel, p, cval)); 5720fdc7489SMatthew Knepley } 5730fdc7489SMatthew Knepley if (p >= fStart && p < fEnd) { 5749566063dSJacob Faibussowitsch PetscCall(DMLabelGetValue(bodyLabel, p, &fVal)); 5759566063dSJacob Faibussowitsch if (fVal < 0) PetscCall(DMLabelSetValue(bodyLabel, p, cval)); 5760fdc7489SMatthew Knepley } 5770fdc7489SMatthew Knepley } 5789566063dSJacob Faibussowitsch PetscCall(DMPlexRestoreTransitiveClosure(*dmRefined, c, PETSC_TRUE, &Ncl, &closure)); 5790fdc7489SMatthew Knepley } 5800fdc7489SMatthew Knepley } 581c1cad2e7SMatthew G. Knepley skip_egads:; 5820fdc7489SMatthew Knepley #endif 5839318fe57SMatthew G. Knepley } 5849566063dSJacob Faibussowitsch PetscCall(DMPlexSetRefinementUniform(*dmRefined, PETSC_FALSE)); 5853a074057SBarry Smith } 5863ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 5873a074057SBarry Smith } 588