1af0996ceSBarry Smith #include <petsc/private/dmpleximpl.h> /*I "petscdmplex.h" I*/ 2c58f1c22SToby Isaac #include <petsc/private/dmlabelimpl.h> /*I "petscdmlabel.h" I*/ 30c312b8eSJed Brown #include <petscsf.h> 4e6ccafaeSMatthew G Knepley 5e752be1aSMatthew G. Knepley static PetscErrorCode DMPlexMarkBoundaryFaces_Internal(DM dm, PetscInt val, PetscInt cellHeight, DMLabel label) 630560a7bSMatthew G. Knepley { 730560a7bSMatthew G. Knepley PetscInt fStart, fEnd, f; 830560a7bSMatthew G. Knepley PetscErrorCode ierr; 930560a7bSMatthew G. Knepley 1030560a7bSMatthew G. Knepley PetscFunctionBegin; 1130560a7bSMatthew G. Knepley ierr = DMPlexGetHeightStratum(dm, cellHeight+1, &fStart, &fEnd);CHKERRQ(ierr); 1230560a7bSMatthew G. Knepley for (f = fStart; f < fEnd; ++f) { 1330560a7bSMatthew G. Knepley PetscInt supportSize; 1430560a7bSMatthew G. Knepley 1530560a7bSMatthew G. Knepley ierr = DMPlexGetSupportSize(dm, f, &supportSize);CHKERRQ(ierr); 16e752be1aSMatthew G. Knepley if (supportSize == 1) { 17e752be1aSMatthew G. Knepley if (val < 0) { 18e752be1aSMatthew G. Knepley PetscInt *closure = NULL; 19e752be1aSMatthew G. Knepley PetscInt clSize, cl, cval; 20e752be1aSMatthew G. Knepley 21e752be1aSMatthew G. Knepley ierr = DMPlexGetTransitiveClosure(dm, f, PETSC_TRUE, &clSize, &closure);CHKERRQ(ierr); 22e752be1aSMatthew G. Knepley for (cl = 0; cl < clSize*2; cl += 2) { 23e752be1aSMatthew G. Knepley ierr = DMLabelGetValue(label, closure[cl], &cval);CHKERRQ(ierr); 24e752be1aSMatthew G. Knepley if (cval < 0) continue; 25e752be1aSMatthew G. Knepley ierr = DMLabelSetValue(label, f, cval);CHKERRQ(ierr); 26e752be1aSMatthew G. Knepley break; 27e752be1aSMatthew G. Knepley } 28e752be1aSMatthew G. Knepley if (cl == clSize*2) {ierr = DMLabelSetValue(label, f, 1);CHKERRQ(ierr);} 29e752be1aSMatthew G. Knepley ierr = DMPlexRestoreTransitiveClosure(dm, f, PETSC_TRUE, &clSize, &closure);CHKERRQ(ierr); 30e752be1aSMatthew G. Knepley } else { 31e752be1aSMatthew G. Knepley ierr = DMLabelSetValue(label, f, val);CHKERRQ(ierr); 32e752be1aSMatthew G. Knepley } 33e752be1aSMatthew G. Knepley } 3430560a7bSMatthew G. Knepley } 3530560a7bSMatthew G. Knepley PetscFunctionReturn(0); 3630560a7bSMatthew G. Knepley } 3730560a7bSMatthew G. Knepley 38cd0c2139SMatthew G Knepley /*@ 39cd0c2139SMatthew G Knepley DMPlexMarkBoundaryFaces - Mark all faces on the boundary 40cd0c2139SMatthew G Knepley 41cd0c2139SMatthew G Knepley Not Collective 42cd0c2139SMatthew G Knepley 43cd0c2139SMatthew G Knepley Input Parameter: 44e752be1aSMatthew G. Knepley + dm - The original DM 45e752be1aSMatthew G. Knepley - val - The marker value, or PETSC_DETERMINE to use some value in the closure (or 1 if none are found) 46cd0c2139SMatthew G Knepley 47cd0c2139SMatthew G Knepley Output Parameter: 48e752be1aSMatthew G. Knepley . label - The DMLabel marking boundary faces with the given value 49cd0c2139SMatthew G Knepley 50cd0c2139SMatthew G Knepley Level: developer 51cd0c2139SMatthew G Knepley 52c58f1c22SToby Isaac .seealso: DMLabelCreate(), DMCreateLabel() 5309f723d9SJed Brown @*/ 54e752be1aSMatthew G. Knepley PetscErrorCode DMPlexMarkBoundaryFaces(DM dm, PetscInt val, DMLabel label) 55cd0c2139SMatthew G Knepley { 56827c4036SVaclav Hapla DMPlexInterpolatedFlag flg; 57cd0c2139SMatthew G Knepley PetscErrorCode ierr; 58cd0c2139SMatthew G Knepley 59cd0c2139SMatthew G Knepley PetscFunctionBegin; 60827c4036SVaclav Hapla PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 61827c4036SVaclav Hapla ierr = DMPlexIsInterpolated(dm, &flg);CHKERRQ(ierr); 62827c4036SVaclav Hapla if (flg != DMPLEX_INTERPOLATED_FULL) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "DM is not fully interpolated on this rank"); 63e752be1aSMatthew G. Knepley ierr = DMPlexMarkBoundaryFaces_Internal(dm, val, 0, label);CHKERRQ(ierr); 64cd0c2139SMatthew G Knepley PetscFunctionReturn(0); 65cd0c2139SMatthew G Knepley } 66cd0c2139SMatthew G Knepley 67c08575a3SMatthew G. Knepley static PetscErrorCode DMPlexLabelComplete_Internal(DM dm, DMLabel label, PetscBool completeCells) 68b0bf5782SToby Isaac { 69b0bf5782SToby Isaac IS valueIS; 70ac51f24eSSander Arens PetscSF sfPoint; 71b0bf5782SToby Isaac const PetscInt *values; 72ac51f24eSSander Arens PetscInt numValues, v, cStart, cEnd, nroots; 73b0bf5782SToby Isaac PetscErrorCode ierr; 74b0bf5782SToby Isaac 75b0bf5782SToby Isaac PetscFunctionBegin; 76b0bf5782SToby Isaac ierr = DMLabelGetNumValues(label, &numValues);CHKERRQ(ierr); 77b0bf5782SToby Isaac ierr = DMLabelGetValueIS(label, &valueIS);CHKERRQ(ierr); 78b0bf5782SToby Isaac ierr = DMPlexGetHeightStratum(dm,0,&cStart,&cEnd);CHKERRQ(ierr); 79b0bf5782SToby Isaac ierr = ISGetIndices(valueIS, &values);CHKERRQ(ierr); 80b0bf5782SToby Isaac for (v = 0; v < numValues; ++v) { 81b0bf5782SToby Isaac IS pointIS; 82b0bf5782SToby Isaac const PetscInt *points; 83b0bf5782SToby Isaac PetscInt numPoints, p; 84b0bf5782SToby Isaac 85b0bf5782SToby Isaac ierr = DMLabelGetStratumSize(label, values[v], &numPoints);CHKERRQ(ierr); 86b0bf5782SToby Isaac ierr = DMLabelGetStratumIS(label, values[v], &pointIS);CHKERRQ(ierr); 87b0bf5782SToby Isaac ierr = ISGetIndices(pointIS, &points);CHKERRQ(ierr); 88b0bf5782SToby Isaac for (p = 0; p < numPoints; ++p) { 89b0bf5782SToby Isaac PetscInt q = points[p]; 90b0bf5782SToby Isaac PetscInt *closure = NULL; 91b0bf5782SToby Isaac PetscInt closureSize, c; 92b0bf5782SToby Isaac 93b0bf5782SToby Isaac if (cStart <= q && q < cEnd && !completeCells) { /* skip cells */ 94b0bf5782SToby Isaac continue; 95b0bf5782SToby Isaac } 96b0bf5782SToby Isaac ierr = DMPlexGetTransitiveClosure(dm, q, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 97b0bf5782SToby Isaac for (c = 0; c < closureSize*2; c += 2) { 98b0bf5782SToby Isaac ierr = DMLabelSetValue(label, closure[c], values[v]);CHKERRQ(ierr); 99b0bf5782SToby Isaac } 100b0bf5782SToby Isaac ierr = DMPlexRestoreTransitiveClosure(dm, q, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 101b0bf5782SToby Isaac } 102b0bf5782SToby Isaac ierr = ISRestoreIndices(pointIS, &points);CHKERRQ(ierr); 103b0bf5782SToby Isaac ierr = ISDestroy(&pointIS);CHKERRQ(ierr); 104b0bf5782SToby Isaac } 105b0bf5782SToby Isaac ierr = ISRestoreIndices(valueIS, &values);CHKERRQ(ierr); 106b0bf5782SToby Isaac ierr = ISDestroy(&valueIS);CHKERRQ(ierr); 107ac51f24eSSander Arens ierr = DMGetPointSF(dm, &sfPoint);CHKERRQ(ierr); 108ac51f24eSSander Arens ierr = PetscSFGetGraph(sfPoint, &nroots, NULL, NULL, NULL);CHKERRQ(ierr); 109ac51f24eSSander Arens if (nroots >= 0) { 11026279d81SSanderA DMLabel lblRoots, lblLeaves; 11126279d81SSanderA IS valueIS, pointIS; 11226279d81SSanderA const PetscInt *values; 11326279d81SSanderA PetscInt numValues, v; 11426279d81SSanderA PetscErrorCode ierr; 11526279d81SSanderA 11626279d81SSanderA ierr = DMGetPointSF(dm, &sfPoint);CHKERRQ(ierr); 11726279d81SSanderA /* Pull point contributions from remote leaves into local roots */ 11826279d81SSanderA ierr = DMLabelGather(label, sfPoint, &lblLeaves);CHKERRQ(ierr); 11926279d81SSanderA ierr = DMLabelGetValueIS(lblLeaves, &valueIS);CHKERRQ(ierr); 12026279d81SSanderA ierr = ISGetLocalSize(valueIS, &numValues);CHKERRQ(ierr); 12126279d81SSanderA ierr = ISGetIndices(valueIS, &values);CHKERRQ(ierr); 12226279d81SSanderA for (v = 0; v < numValues; ++v) { 12326279d81SSanderA const PetscInt value = values[v]; 12426279d81SSanderA 12526279d81SSanderA ierr = DMLabelGetStratumIS(lblLeaves, value, &pointIS);CHKERRQ(ierr); 12626279d81SSanderA ierr = DMLabelInsertIS(label, pointIS, value);CHKERRQ(ierr); 12726279d81SSanderA ierr = ISDestroy(&pointIS);CHKERRQ(ierr); 12826279d81SSanderA } 12926279d81SSanderA ierr = ISRestoreIndices(valueIS, &values);CHKERRQ(ierr); 13026279d81SSanderA ierr = ISDestroy(&valueIS);CHKERRQ(ierr); 13126279d81SSanderA ierr = DMLabelDestroy(&lblLeaves);CHKERRQ(ierr); 13226279d81SSanderA /* Push point contributions from roots into remote leaves */ 13326279d81SSanderA ierr = DMLabelDistribute(label, sfPoint, &lblRoots);CHKERRQ(ierr); 13426279d81SSanderA ierr = DMLabelGetValueIS(lblRoots, &valueIS);CHKERRQ(ierr); 13526279d81SSanderA ierr = ISGetLocalSize(valueIS, &numValues);CHKERRQ(ierr); 13626279d81SSanderA ierr = ISGetIndices(valueIS, &values);CHKERRQ(ierr); 13726279d81SSanderA for (v = 0; v < numValues; ++v) { 13826279d81SSanderA const PetscInt value = values[v]; 13926279d81SSanderA 14026279d81SSanderA ierr = DMLabelGetStratumIS(lblRoots, value, &pointIS);CHKERRQ(ierr); 14126279d81SSanderA ierr = DMLabelInsertIS(label, pointIS, value);CHKERRQ(ierr); 14226279d81SSanderA ierr = ISDestroy(&pointIS);CHKERRQ(ierr); 14326279d81SSanderA } 14426279d81SSanderA ierr = ISRestoreIndices(valueIS, &values);CHKERRQ(ierr); 14526279d81SSanderA ierr = ISDestroy(&valueIS);CHKERRQ(ierr); 14626279d81SSanderA ierr = DMLabelDestroy(&lblRoots);CHKERRQ(ierr); 14726279d81SSanderA } 148b0bf5782SToby Isaac PetscFunctionReturn(0); 149b0bf5782SToby Isaac } 150b0bf5782SToby Isaac 1512be2b188SMatthew G Knepley /*@ 1522be2b188SMatthew G Knepley DMPlexLabelComplete - Starting with a label marking points on a surface, we add the transitive closure to the surface 1532be2b188SMatthew G Knepley 1542be2b188SMatthew G Knepley Input Parameters: 1552be2b188SMatthew G Knepley + dm - The DM 1562be2b188SMatthew G Knepley - label - A DMLabel marking the surface points 1572be2b188SMatthew G Knepley 1582be2b188SMatthew G Knepley Output Parameter: 1592be2b188SMatthew G Knepley . label - A DMLabel marking all surface points in the transitive closure 1602be2b188SMatthew G Knepley 1612be2b188SMatthew G Knepley Level: developer 1622be2b188SMatthew G Knepley 1632be2b188SMatthew G Knepley .seealso: DMPlexLabelCohesiveComplete() 1642be2b188SMatthew G Knepley @*/ 1652be2b188SMatthew G Knepley PetscErrorCode DMPlexLabelComplete(DM dm, DMLabel label) 1662be2b188SMatthew G Knepley { 1672be2b188SMatthew G Knepley PetscErrorCode ierr; 1682be2b188SMatthew G Knepley 1692be2b188SMatthew G Knepley PetscFunctionBegin; 170b0bf5782SToby Isaac ierr = DMPlexLabelComplete_Internal(dm, label, PETSC_TRUE);CHKERRQ(ierr); 1712be2b188SMatthew G Knepley PetscFunctionReturn(0); 1722be2b188SMatthew G Knepley } 1732be2b188SMatthew G Knepley 1746cf0e42fSMatthew G. Knepley /*@ 175a6e0b375SMatthew G. Knepley DMPlexLabelAddCells - Starting with a label marking points on a surface, we add a cell for each point 1766cf0e42fSMatthew G. Knepley 1776cf0e42fSMatthew G. Knepley Input Parameters: 1786cf0e42fSMatthew G. Knepley + dm - The DM 1796cf0e42fSMatthew G. Knepley - label - A DMLabel marking the surface points 1806cf0e42fSMatthew G. Knepley 1816cf0e42fSMatthew G. Knepley Output Parameter: 1826cf0e42fSMatthew G. Knepley . label - A DMLabel incorporating cells 1836cf0e42fSMatthew G. Knepley 1846cf0e42fSMatthew G. Knepley Level: developer 1856cf0e42fSMatthew G. Knepley 1866cf0e42fSMatthew G. Knepley Note: The cells allow FEM boundary conditions to be applied using the cell geometry 1876cf0e42fSMatthew G. Knepley 188a6e0b375SMatthew G. Knepley .seealso: DMPlexLabelAddFaceCells(), DMPlexLabelComplete(), DMPlexLabelCohesiveComplete() 1896cf0e42fSMatthew G. Knepley @*/ 1906cf0e42fSMatthew G. Knepley PetscErrorCode DMPlexLabelAddCells(DM dm, DMLabel label) 1916cf0e42fSMatthew G. Knepley { 1926cf0e42fSMatthew G. Knepley IS valueIS; 1936cf0e42fSMatthew G. Knepley const PetscInt *values; 194485ad865SMatthew G. Knepley PetscInt numValues, v, cStart, cEnd; 1956cf0e42fSMatthew G. Knepley PetscErrorCode ierr; 1966cf0e42fSMatthew G. Knepley 1976cf0e42fSMatthew G. Knepley PetscFunctionBegin; 198485ad865SMatthew G. Knepley ierr = DMPlexGetInteriorCellStratum(dm, &cStart, &cEnd);CHKERRQ(ierr); 1996cf0e42fSMatthew G. Knepley ierr = DMLabelGetNumValues(label, &numValues);CHKERRQ(ierr); 2006cf0e42fSMatthew G. Knepley ierr = DMLabelGetValueIS(label, &valueIS);CHKERRQ(ierr); 2016cf0e42fSMatthew G. Knepley ierr = ISGetIndices(valueIS, &values);CHKERRQ(ierr); 2026cf0e42fSMatthew G. Knepley for (v = 0; v < numValues; ++v) { 2036cf0e42fSMatthew G. Knepley IS pointIS; 2046cf0e42fSMatthew G. Knepley const PetscInt *points; 2056cf0e42fSMatthew G. Knepley PetscInt numPoints, p; 2066cf0e42fSMatthew G. Knepley 2076cf0e42fSMatthew G. Knepley ierr = DMLabelGetStratumSize(label, values[v], &numPoints);CHKERRQ(ierr); 2086cf0e42fSMatthew G. Knepley ierr = DMLabelGetStratumIS(label, values[v], &pointIS);CHKERRQ(ierr); 2096cf0e42fSMatthew G. Knepley ierr = ISGetIndices(pointIS, &points);CHKERRQ(ierr); 2106cf0e42fSMatthew G. Knepley for (p = 0; p < numPoints; ++p) { 2116cf0e42fSMatthew G. Knepley PetscInt *closure = NULL; 212a6e0b375SMatthew G. Knepley PetscInt closureSize, cl; 2136cf0e42fSMatthew G. Knepley 2146cf0e42fSMatthew G. Knepley ierr = DMPlexGetTransitiveClosure(dm, points[p], PETSC_FALSE, &closureSize, &closure);CHKERRQ(ierr); 21522eabd52SMatthew G. Knepley for (cl = closureSize-1; cl > 0; --cl) { 216a6e0b375SMatthew G. Knepley const PetscInt cell = closure[cl*2]; 217a6e0b375SMatthew G. Knepley if ((cell >= cStart) && (cell < cEnd)) {ierr = DMLabelSetValue(label, cell, values[v]);CHKERRQ(ierr); break;} 21822eabd52SMatthew G. Knepley } 2196cf0e42fSMatthew G. Knepley ierr = DMPlexRestoreTransitiveClosure(dm, points[p], PETSC_FALSE, &closureSize, &closure);CHKERRQ(ierr); 2206cf0e42fSMatthew G. Knepley } 2216cf0e42fSMatthew G. Knepley ierr = ISRestoreIndices(pointIS, &points);CHKERRQ(ierr); 2226cf0e42fSMatthew G. Knepley ierr = ISDestroy(&pointIS);CHKERRQ(ierr); 2236cf0e42fSMatthew G. Knepley } 2246cf0e42fSMatthew G. Knepley ierr = ISRestoreIndices(valueIS, &values);CHKERRQ(ierr); 2256cf0e42fSMatthew G. Knepley ierr = ISDestroy(&valueIS);CHKERRQ(ierr); 2266cf0e42fSMatthew G. Knepley PetscFunctionReturn(0); 2276cf0e42fSMatthew G. Knepley } 2286cf0e42fSMatthew G. Knepley 229f402d5e4SToby Isaac /*@ 230a6e0b375SMatthew G. Knepley DMPlexLabelAddFaceCells - Starting with a label marking faces on a surface, we add a cell for each face 231a6e0b375SMatthew G. Knepley 232a6e0b375SMatthew G. Knepley Input Parameters: 233a6e0b375SMatthew G. Knepley + dm - The DM 234a6e0b375SMatthew G. Knepley - label - A DMLabel marking the surface points 235a6e0b375SMatthew G. Knepley 236a6e0b375SMatthew G. Knepley Output Parameter: 237a6e0b375SMatthew G. Knepley . label - A DMLabel incorporating cells 238a6e0b375SMatthew G. Knepley 239a6e0b375SMatthew G. Knepley Level: developer 240a6e0b375SMatthew G. Knepley 241a6e0b375SMatthew G. Knepley Note: The cells allow FEM boundary conditions to be applied using the cell geometry 242a6e0b375SMatthew G. Knepley 243a6e0b375SMatthew G. Knepley .seealso: DMPlexLabelAddCells(), DMPlexLabelComplete(), DMPlexLabelCohesiveComplete() 244a6e0b375SMatthew G. Knepley @*/ 245a6e0b375SMatthew G. Knepley PetscErrorCode DMPlexLabelAddFaceCells(DM dm, DMLabel label) 246a6e0b375SMatthew G. Knepley { 247a6e0b375SMatthew G. Knepley IS valueIS; 248a6e0b375SMatthew G. Knepley const PetscInt *values; 249a6e0b375SMatthew G. Knepley PetscInt numValues, v, cStart, cEnd, fStart, fEnd; 250a6e0b375SMatthew G. Knepley PetscErrorCode ierr; 251a6e0b375SMatthew G. Knepley 252a6e0b375SMatthew G. Knepley PetscFunctionBegin; 253a6e0b375SMatthew G. Knepley ierr = DMPlexGetInteriorCellStratum(dm, &cStart, &cEnd);CHKERRQ(ierr); 254a6e0b375SMatthew G. Knepley ierr = DMPlexGetHeightStratum(dm, 1, &fStart, &fEnd);CHKERRQ(ierr); 255a6e0b375SMatthew G. Knepley ierr = DMLabelGetNumValues(label, &numValues);CHKERRQ(ierr); 256a6e0b375SMatthew G. Knepley ierr = DMLabelGetValueIS(label, &valueIS);CHKERRQ(ierr); 257a6e0b375SMatthew G. Knepley ierr = ISGetIndices(valueIS, &values);CHKERRQ(ierr); 258a6e0b375SMatthew G. Knepley for (v = 0; v < numValues; ++v) { 259a6e0b375SMatthew G. Knepley IS pointIS; 260a6e0b375SMatthew G. Knepley const PetscInt *points; 261a6e0b375SMatthew G. Knepley PetscInt numPoints, p; 262a6e0b375SMatthew G. Knepley 263a6e0b375SMatthew G. Knepley ierr = DMLabelGetStratumSize(label, values[v], &numPoints);CHKERRQ(ierr); 264a6e0b375SMatthew G. Knepley ierr = DMLabelGetStratumIS(label, values[v], &pointIS);CHKERRQ(ierr); 265a6e0b375SMatthew G. Knepley ierr = ISGetIndices(pointIS, &points);CHKERRQ(ierr); 266a6e0b375SMatthew G. Knepley for (p = 0; p < numPoints; ++p) { 267a6e0b375SMatthew G. Knepley const PetscInt face = points[p]; 268a6e0b375SMatthew G. Knepley PetscInt *closure = NULL; 269a6e0b375SMatthew G. Knepley PetscInt closureSize, cl; 270a6e0b375SMatthew G. Knepley 271a6e0b375SMatthew G. Knepley if ((face < fStart) || (face >= fEnd)) continue; 272a6e0b375SMatthew G. Knepley ierr = DMPlexGetTransitiveClosure(dm, face, PETSC_FALSE, &closureSize, &closure);CHKERRQ(ierr); 273a6e0b375SMatthew G. Knepley for (cl = closureSize-1; cl > 0; --cl) { 274a6e0b375SMatthew G. Knepley const PetscInt cell = closure[cl*2]; 275a6e0b375SMatthew G. Knepley if ((cell >= cStart) && (cell < cEnd)) {ierr = DMLabelSetValue(label, cell, values[v]);CHKERRQ(ierr); break;} 276a6e0b375SMatthew G. Knepley } 277a6e0b375SMatthew G. Knepley ierr = DMPlexRestoreTransitiveClosure(dm, face, PETSC_FALSE, &closureSize, &closure);CHKERRQ(ierr); 278a6e0b375SMatthew G. Knepley } 279a6e0b375SMatthew G. Knepley ierr = ISRestoreIndices(pointIS, &points);CHKERRQ(ierr); 280a6e0b375SMatthew G. Knepley ierr = ISDestroy(&pointIS);CHKERRQ(ierr); 281a6e0b375SMatthew G. Knepley } 282a6e0b375SMatthew G. Knepley ierr = ISRestoreIndices(valueIS, &values);CHKERRQ(ierr); 283a6e0b375SMatthew G. Knepley ierr = ISDestroy(&valueIS);CHKERRQ(ierr); 284a6e0b375SMatthew G. Knepley PetscFunctionReturn(0); 285a6e0b375SMatthew G. Knepley } 286a6e0b375SMatthew G. Knepley 287a6e0b375SMatthew G. Knepley /*@ 288f402d5e4SToby Isaac DMPlexLabelClearCells - Remove cells from a label 289f402d5e4SToby Isaac 290f402d5e4SToby Isaac Input Parameters: 291f402d5e4SToby Isaac + dm - The DM 292f402d5e4SToby Isaac - label - A DMLabel marking surface points and their adjacent cells 293f402d5e4SToby Isaac 294f402d5e4SToby Isaac Output Parameter: 295f402d5e4SToby Isaac . label - A DMLabel without cells 296f402d5e4SToby Isaac 297f402d5e4SToby Isaac Level: developer 298f402d5e4SToby Isaac 299a6e0b375SMatthew G. Knepley Note: This undoes DMPlexLabelAddCells() or DMPlexLabelAddFaceCells() 300f402d5e4SToby Isaac 301f402d5e4SToby Isaac .seealso: DMPlexLabelComplete(), DMPlexLabelCohesiveComplete(), DMPlexLabelAddCells() 302f402d5e4SToby Isaac @*/ 303f402d5e4SToby Isaac PetscErrorCode DMPlexLabelClearCells(DM dm, DMLabel label) 304f402d5e4SToby Isaac { 305f402d5e4SToby Isaac IS valueIS; 306f402d5e4SToby Isaac const PetscInt *values; 307485ad865SMatthew G. Knepley PetscInt numValues, v, cStart, cEnd; 308f402d5e4SToby Isaac PetscErrorCode ierr; 309f402d5e4SToby Isaac 310f402d5e4SToby Isaac PetscFunctionBegin; 311485ad865SMatthew G. Knepley ierr = DMPlexGetInteriorCellStratum(dm, &cStart, &cEnd);CHKERRQ(ierr); 312f402d5e4SToby Isaac ierr = DMLabelGetNumValues(label, &numValues);CHKERRQ(ierr); 313f402d5e4SToby Isaac ierr = DMLabelGetValueIS(label, &valueIS);CHKERRQ(ierr); 314f402d5e4SToby Isaac ierr = ISGetIndices(valueIS, &values);CHKERRQ(ierr); 315f402d5e4SToby Isaac for (v = 0; v < numValues; ++v) { 316f402d5e4SToby Isaac IS pointIS; 317f402d5e4SToby Isaac const PetscInt *points; 318f402d5e4SToby Isaac PetscInt numPoints, p; 319f402d5e4SToby Isaac 320f402d5e4SToby Isaac ierr = DMLabelGetStratumSize(label, values[v], &numPoints);CHKERRQ(ierr); 321f402d5e4SToby Isaac ierr = DMLabelGetStratumIS(label, values[v], &pointIS);CHKERRQ(ierr); 322f402d5e4SToby Isaac ierr = ISGetIndices(pointIS, &points);CHKERRQ(ierr); 323f402d5e4SToby Isaac for (p = 0; p < numPoints; ++p) { 324f402d5e4SToby Isaac PetscInt point = points[p]; 325f402d5e4SToby Isaac 326f402d5e4SToby Isaac if (point >= cStart && point < cEnd) { 327f402d5e4SToby Isaac ierr = DMLabelClearValue(label,point,values[v]);CHKERRQ(ierr); 328f402d5e4SToby Isaac } 329f402d5e4SToby Isaac } 330f402d5e4SToby Isaac ierr = ISRestoreIndices(pointIS, &points);CHKERRQ(ierr); 331f402d5e4SToby Isaac ierr = ISDestroy(&pointIS);CHKERRQ(ierr); 332f402d5e4SToby Isaac } 333f402d5e4SToby Isaac ierr = ISRestoreIndices(valueIS, &values);CHKERRQ(ierr); 334f402d5e4SToby Isaac ierr = ISDestroy(&valueIS);CHKERRQ(ierr); 335f402d5e4SToby Isaac PetscFunctionReturn(0); 336f402d5e4SToby Isaac } 337f402d5e4SToby Isaac 33859eef20bSToby Isaac /* take (oldEnd, added) pairs, ordered by height and convert them to (oldstart, newstart) pairs, ordered by ascending 33959eef20bSToby Isaac * index (skipping first, which is (0,0)) */ 3402582d50cSToby Isaac PETSC_STATIC_INLINE PetscErrorCode DMPlexShiftPointSetUp_Internal(PetscInt depth, PetscInt depthShift[]) 341cd0c2139SMatthew G Knepley { 3422582d50cSToby Isaac PetscInt d, off = 0; 3432582d50cSToby Isaac 3442582d50cSToby Isaac PetscFunctionBegin; 34559eef20bSToby Isaac /* sort by (oldend): yes this is an O(n^2) sort, we expect depth <= 3 */ 3460974a383SToby Isaac for (d = 0; d < depth; d++) { 3472582d50cSToby Isaac PetscInt firstd = d; 3480974a383SToby Isaac PetscInt firstStart = depthShift[2*d]; 3492582d50cSToby Isaac PetscInt e; 3502582d50cSToby Isaac 3512582d50cSToby Isaac for (e = d+1; e <= depth; e++) { 3522582d50cSToby Isaac if (depthShift[2*e] < firstStart) { 3532582d50cSToby Isaac firstd = e; 3542582d50cSToby Isaac firstStart = depthShift[2*d]; 3552582d50cSToby Isaac } 3562582d50cSToby Isaac } 3572582d50cSToby Isaac if (firstd != d) { 3582582d50cSToby Isaac PetscInt swap[2]; 3592582d50cSToby Isaac 3602582d50cSToby Isaac e = firstd; 3612582d50cSToby Isaac swap[0] = depthShift[2*d]; 3622582d50cSToby Isaac swap[1] = depthShift[2*d+1]; 3632582d50cSToby Isaac depthShift[2*d] = depthShift[2*e]; 3642582d50cSToby Isaac depthShift[2*d+1] = depthShift[2*e+1]; 3652582d50cSToby Isaac depthShift[2*e] = swap[0]; 3662582d50cSToby Isaac depthShift[2*e+1] = swap[1]; 3672582d50cSToby Isaac } 3682582d50cSToby Isaac } 3692582d50cSToby Isaac /* convert (oldstart, added) to (oldstart, newstart) */ 3700974a383SToby Isaac for (d = 0; d <= depth; d++) { 3712582d50cSToby Isaac off += depthShift[2*d+1]; 37259eef20bSToby Isaac depthShift[2*d+1] = depthShift[2*d] + off; 3732582d50cSToby Isaac } 3742582d50cSToby Isaac PetscFunctionReturn(0); 3752582d50cSToby Isaac } 3762582d50cSToby Isaac 3772582d50cSToby Isaac /* depthShift is a list of (old, new) pairs */ 3782582d50cSToby Isaac PETSC_STATIC_INLINE PetscInt DMPlexShiftPoint_Internal(PetscInt p, PetscInt depth, PetscInt depthShift[]) 3792582d50cSToby Isaac { 3802582d50cSToby Isaac PetscInt d; 3812582d50cSToby Isaac PetscInt newOff = 0; 3822582d50cSToby Isaac 3832582d50cSToby Isaac for (d = 0; d <= depth; d++) { 3842582d50cSToby Isaac if (p < depthShift[2*d]) return p + newOff; 3852582d50cSToby Isaac else newOff = depthShift[2*d+1] - depthShift[2*d]; 3862582d50cSToby Isaac } 3870974a383SToby Isaac return p + newOff; 3882582d50cSToby Isaac } 3892582d50cSToby Isaac 3902582d50cSToby Isaac /* depthShift is a list of (old, new) pairs */ 3912582d50cSToby Isaac PETSC_STATIC_INLINE PetscInt DMPlexShiftPointInverse_Internal(PetscInt p, PetscInt depth, PetscInt depthShift[]) 3922582d50cSToby Isaac { 3932582d50cSToby Isaac PetscInt d; 3942582d50cSToby Isaac PetscInt newOff = 0; 3952582d50cSToby Isaac 3962582d50cSToby Isaac for (d = 0; d <= depth; d++) { 3972582d50cSToby Isaac if (p < depthShift[2*d+1]) return p + newOff; 3982582d50cSToby Isaac else newOff = depthShift[2*d] - depthShift[2*d+1]; 3992582d50cSToby Isaac } 4000974a383SToby Isaac return p + newOff; 401cd0c2139SMatthew G Knepley } 402cd0c2139SMatthew G Knepley 403cd0c2139SMatthew G Knepley static PetscErrorCode DMPlexShiftSizes_Internal(DM dm, PetscInt depthShift[], DM dmNew) 404cd0c2139SMatthew G Knepley { 405cd0c2139SMatthew G Knepley PetscInt depth = 0, d, pStart, pEnd, p; 406fa8e8ae5SToby Isaac DMLabel depthLabel; 407cd0c2139SMatthew G Knepley PetscErrorCode ierr; 408cd0c2139SMatthew G Knepley 409cd0c2139SMatthew G Knepley PetscFunctionBegin; 410cd0c2139SMatthew G Knepley ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 411cd0c2139SMatthew G Knepley if (depth < 0) PetscFunctionReturn(0); 412cd0c2139SMatthew G Knepley /* Step 1: Expand chart */ 413cd0c2139SMatthew G Knepley ierr = DMPlexGetChart(dm, &pStart, &pEnd);CHKERRQ(ierr); 4140974a383SToby Isaac pEnd = DMPlexShiftPoint_Internal(pEnd,depth,depthShift); 415cd0c2139SMatthew G Knepley ierr = DMPlexSetChart(dmNew, pStart, pEnd);CHKERRQ(ierr); 416fa8e8ae5SToby Isaac ierr = DMCreateLabel(dmNew,"depth");CHKERRQ(ierr); 417fa8e8ae5SToby Isaac ierr = DMPlexGetDepthLabel(dmNew,&depthLabel);CHKERRQ(ierr); 418cd0c2139SMatthew G Knepley /* Step 2: Set cone and support sizes */ 419cd0c2139SMatthew G Knepley for (d = 0; d <= depth; ++d) { 420fa8e8ae5SToby Isaac PetscInt pStartNew, pEndNew; 421fa8e8ae5SToby Isaac IS pIS; 422fa8e8ae5SToby Isaac 423cd0c2139SMatthew G Knepley ierr = DMPlexGetDepthStratum(dm, d, &pStart, &pEnd);CHKERRQ(ierr); 424fa8e8ae5SToby Isaac pStartNew = DMPlexShiftPoint_Internal(pStart, depth, depthShift); 425fa8e8ae5SToby Isaac pEndNew = DMPlexShiftPoint_Internal(pEnd, depth, depthShift); 426fa8e8ae5SToby Isaac ierr = ISCreateStride(PETSC_COMM_SELF, pEndNew - pStartNew, pStartNew, 1, &pIS);CHKERRQ(ierr); 427fa8e8ae5SToby Isaac ierr = DMLabelSetStratumIS(depthLabel, d, pIS);CHKERRQ(ierr); 428fa8e8ae5SToby Isaac ierr = ISDestroy(&pIS);CHKERRQ(ierr); 429cd0c2139SMatthew G Knepley for (p = pStart; p < pEnd; ++p) { 4302582d50cSToby Isaac PetscInt newp = DMPlexShiftPoint_Internal(p, depth, depthShift); 431cd0c2139SMatthew G Knepley PetscInt size; 432cd0c2139SMatthew G Knepley 433cd0c2139SMatthew G Knepley ierr = DMPlexGetConeSize(dm, p, &size);CHKERRQ(ierr); 434cd0c2139SMatthew G Knepley ierr = DMPlexSetConeSize(dmNew, newp, size);CHKERRQ(ierr); 435cd0c2139SMatthew G Knepley ierr = DMPlexGetSupportSize(dm, p, &size);CHKERRQ(ierr); 436cd0c2139SMatthew G Knepley ierr = DMPlexSetSupportSize(dmNew, newp, size);CHKERRQ(ierr); 437cd0c2139SMatthew G Knepley } 438cd0c2139SMatthew G Knepley } 439cd0c2139SMatthew G Knepley PetscFunctionReturn(0); 440cd0c2139SMatthew G Knepley } 441cd0c2139SMatthew G Knepley 442cd0c2139SMatthew G Knepley static PetscErrorCode DMPlexShiftPoints_Internal(DM dm, PetscInt depthShift[], DM dmNew) 443cd0c2139SMatthew G Knepley { 4442582d50cSToby Isaac PetscInt *newpoints; 4452582d50cSToby Isaac PetscInt depth = 0, maxConeSize, maxSupportSize, maxConeSizeNew, maxSupportSizeNew, pStart, pEnd, p; 446cd0c2139SMatthew G Knepley PetscErrorCode ierr; 447cd0c2139SMatthew G Knepley 448cd0c2139SMatthew G Knepley PetscFunctionBegin; 449cd0c2139SMatthew G Knepley ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 450cd0c2139SMatthew G Knepley if (depth < 0) PetscFunctionReturn(0); 451cd0c2139SMatthew G Knepley ierr = DMPlexGetMaxSizes(dm, &maxConeSize, &maxSupportSize);CHKERRQ(ierr); 452dcbb62e8SMatthew G. Knepley ierr = DMPlexGetMaxSizes(dmNew, &maxConeSizeNew, &maxSupportSizeNew);CHKERRQ(ierr); 4532582d50cSToby Isaac ierr = PetscMalloc1(PetscMax(PetscMax(maxConeSize, maxSupportSize), PetscMax(maxConeSizeNew, maxSupportSizeNew)),&newpoints);CHKERRQ(ierr); 454cd0c2139SMatthew G Knepley /* Step 5: Set cones and supports */ 455cd0c2139SMatthew G Knepley ierr = DMPlexGetChart(dm, &pStart, &pEnd);CHKERRQ(ierr); 456cd0c2139SMatthew G Knepley for (p = pStart; p < pEnd; ++p) { 457cd0c2139SMatthew G Knepley const PetscInt *points = NULL, *orientations = NULL; 4582582d50cSToby Isaac PetscInt size,sizeNew, i, newp = DMPlexShiftPoint_Internal(p, depth, depthShift); 459cd0c2139SMatthew G Knepley 460cd0c2139SMatthew G Knepley ierr = DMPlexGetConeSize(dm, p, &size);CHKERRQ(ierr); 461cd0c2139SMatthew G Knepley ierr = DMPlexGetCone(dm, p, &points);CHKERRQ(ierr); 462cd0c2139SMatthew G Knepley ierr = DMPlexGetConeOrientation(dm, p, &orientations);CHKERRQ(ierr); 463cd0c2139SMatthew G Knepley for (i = 0; i < size; ++i) { 4642582d50cSToby Isaac newpoints[i] = DMPlexShiftPoint_Internal(points[i], depth, depthShift); 465cd0c2139SMatthew G Knepley } 466cd0c2139SMatthew G Knepley ierr = DMPlexSetCone(dmNew, newp, newpoints);CHKERRQ(ierr); 467cd0c2139SMatthew G Knepley ierr = DMPlexSetConeOrientation(dmNew, newp, orientations);CHKERRQ(ierr); 468cd0c2139SMatthew G Knepley ierr = DMPlexGetSupportSize(dm, p, &size);CHKERRQ(ierr); 469dcbb62e8SMatthew G. Knepley ierr = DMPlexGetSupportSize(dmNew, newp, &sizeNew);CHKERRQ(ierr); 470cd0c2139SMatthew G Knepley ierr = DMPlexGetSupport(dm, p, &points);CHKERRQ(ierr); 471cd0c2139SMatthew G Knepley for (i = 0; i < size; ++i) { 4722582d50cSToby Isaac newpoints[i] = DMPlexShiftPoint_Internal(points[i], depth, depthShift); 473cd0c2139SMatthew G Knepley } 474dcbb62e8SMatthew G. Knepley for (i = size; i < sizeNew; ++i) newpoints[i] = 0; 475cd0c2139SMatthew G Knepley ierr = DMPlexSetSupport(dmNew, newp, newpoints);CHKERRQ(ierr); 476cd0c2139SMatthew G Knepley } 4772582d50cSToby Isaac ierr = PetscFree(newpoints);CHKERRQ(ierr); 478cd0c2139SMatthew G Knepley PetscFunctionReturn(0); 479cd0c2139SMatthew G Knepley } 480cd0c2139SMatthew G Knepley 481cd0c2139SMatthew G Knepley static PetscErrorCode DMPlexShiftCoordinates_Internal(DM dm, PetscInt depthShift[], DM dmNew) 482cd0c2139SMatthew G Knepley { 483cd0c2139SMatthew G Knepley PetscSection coordSection, newCoordSection; 484cd0c2139SMatthew G Knepley Vec coordinates, newCoordinates; 485cd0c2139SMatthew G Knepley PetscScalar *coords, *newCoords; 486f2b8cce1SMatthew G. Knepley PetscInt coordSize, sStart, sEnd; 487f2b8cce1SMatthew G. Knepley PetscInt dim, depth = 0, cStart, cEnd, cStartNew, cEndNew, c, vStart, vEnd, vStartNew, vEndNew, v; 488f2b8cce1SMatthew G. Knepley PetscBool hasCells; 489cd0c2139SMatthew G Knepley PetscErrorCode ierr; 490cd0c2139SMatthew G Knepley 491cd0c2139SMatthew G Knepley PetscFunctionBegin; 492f2b8cce1SMatthew G. Knepley ierr = DMGetCoordinateDim(dm, &dim);CHKERRQ(ierr); 493c0e8cf5fSMatthew G. Knepley ierr = DMSetCoordinateDim(dmNew, dim);CHKERRQ(ierr); 494cd0c2139SMatthew G Knepley ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 495cd0c2139SMatthew G Knepley /* Step 8: Convert coordinates */ 496cd0c2139SMatthew G Knepley ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr); 497f2b8cce1SMatthew G. Knepley ierr = DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd);CHKERRQ(ierr); 498cd0c2139SMatthew G Knepley ierr = DMPlexGetDepthStratum(dmNew, 0, &vStartNew, &vEndNew);CHKERRQ(ierr); 499f2b8cce1SMatthew G. Knepley ierr = DMPlexGetHeightStratum(dmNew, 0, &cStartNew, &cEndNew);CHKERRQ(ierr); 50069d8a9ceSMatthew G. Knepley ierr = DMGetCoordinateSection(dm, &coordSection);CHKERRQ(ierr); 501cd0c2139SMatthew G Knepley ierr = PetscSectionCreate(PetscObjectComm((PetscObject)dm), &newCoordSection);CHKERRQ(ierr); 502cd0c2139SMatthew G Knepley ierr = PetscSectionSetNumFields(newCoordSection, 1);CHKERRQ(ierr); 503cd0c2139SMatthew G Knepley ierr = PetscSectionSetFieldComponents(newCoordSection, 0, dim);CHKERRQ(ierr); 504f2b8cce1SMatthew G. Knepley ierr = PetscSectionGetChart(coordSection, &sStart, &sEnd);CHKERRQ(ierr); 505f2b8cce1SMatthew G. Knepley hasCells = sStart == cStart ? PETSC_TRUE : PETSC_FALSE; 506f2b8cce1SMatthew G. Knepley ierr = PetscSectionSetChart(newCoordSection, hasCells ? cStartNew : vStartNew, vEndNew);CHKERRQ(ierr); 507f2b8cce1SMatthew G. Knepley if (hasCells) { 508f2b8cce1SMatthew G. Knepley for (c = cStart; c < cEnd; ++c) { 509f2b8cce1SMatthew G. Knepley PetscInt cNew = DMPlexShiftPoint_Internal(c, depth, depthShift), dof; 510f2b8cce1SMatthew G. Knepley 511f2b8cce1SMatthew G. Knepley ierr = PetscSectionGetDof(coordSection, c, &dof);CHKERRQ(ierr); 512f2b8cce1SMatthew G. Knepley ierr = PetscSectionSetDof(newCoordSection, cNew, dof);CHKERRQ(ierr); 513f2b8cce1SMatthew G. Knepley ierr = PetscSectionSetFieldDof(newCoordSection, cNew, 0, dof);CHKERRQ(ierr); 514f2b8cce1SMatthew G. Knepley } 515f2b8cce1SMatthew G. Knepley } 516cd0c2139SMatthew G Knepley for (v = vStartNew; v < vEndNew; ++v) { 517cd0c2139SMatthew G Knepley ierr = PetscSectionSetDof(newCoordSection, v, dim);CHKERRQ(ierr); 518cd0c2139SMatthew G Knepley ierr = PetscSectionSetFieldDof(newCoordSection, v, 0, dim);CHKERRQ(ierr); 519cd0c2139SMatthew G Knepley } 520cd0c2139SMatthew G Knepley ierr = PetscSectionSetUp(newCoordSection);CHKERRQ(ierr); 52146e270d4SMatthew G. Knepley ierr = DMSetCoordinateSection(dmNew, PETSC_DETERMINE, newCoordSection);CHKERRQ(ierr); 522cd0c2139SMatthew G Knepley ierr = PetscSectionGetStorageSize(newCoordSection, &coordSize);CHKERRQ(ierr); 5238b9ced59SLisandro Dalcin ierr = VecCreate(PETSC_COMM_SELF, &newCoordinates);CHKERRQ(ierr); 524cd0c2139SMatthew G Knepley ierr = PetscObjectSetName((PetscObject) newCoordinates, "coordinates");CHKERRQ(ierr); 525cd0c2139SMatthew G Knepley ierr = VecSetSizes(newCoordinates, coordSize, PETSC_DETERMINE);CHKERRQ(ierr); 5264e90ef8eSMatthew G. Knepley ierr = VecSetBlockSize(newCoordinates, dim);CHKERRQ(ierr); 5272eb5907fSJed Brown ierr = VecSetType(newCoordinates,VECSTANDARD);CHKERRQ(ierr); 528cd0c2139SMatthew G Knepley ierr = DMSetCoordinatesLocal(dmNew, newCoordinates);CHKERRQ(ierr); 529cd0c2139SMatthew G Knepley ierr = DMGetCoordinatesLocal(dm, &coordinates);CHKERRQ(ierr); 530cd0c2139SMatthew G Knepley ierr = VecGetArray(coordinates, &coords);CHKERRQ(ierr); 531cd0c2139SMatthew G Knepley ierr = VecGetArray(newCoordinates, &newCoords);CHKERRQ(ierr); 532f2b8cce1SMatthew G. Knepley if (hasCells) { 533f2b8cce1SMatthew G. Knepley for (c = cStart; c < cEnd; ++c) { 534f2b8cce1SMatthew G. Knepley PetscInt cNew = DMPlexShiftPoint_Internal(c, depth, depthShift), dof, off, noff, d; 535f2b8cce1SMatthew G. Knepley 536f2b8cce1SMatthew G. Knepley ierr = PetscSectionGetDof(coordSection, c, &dof);CHKERRQ(ierr); 537f2b8cce1SMatthew G. Knepley ierr = PetscSectionGetOffset(coordSection, c, &off);CHKERRQ(ierr); 538f2b8cce1SMatthew G. Knepley ierr = PetscSectionGetOffset(newCoordSection, cNew, &noff);CHKERRQ(ierr); 539f2b8cce1SMatthew G. Knepley for (d = 0; d < dof; ++d) newCoords[noff+d] = coords[off+d]; 540f2b8cce1SMatthew G. Knepley } 541f2b8cce1SMatthew G. Knepley } 542cd0c2139SMatthew G Knepley for (v = vStart; v < vEnd; ++v) { 543cd0c2139SMatthew G Knepley PetscInt dof, off, noff, d; 544cd0c2139SMatthew G Knepley 545cd0c2139SMatthew G Knepley ierr = PetscSectionGetDof(coordSection, v, &dof);CHKERRQ(ierr); 546cd0c2139SMatthew G Knepley ierr = PetscSectionGetOffset(coordSection, v, &off);CHKERRQ(ierr); 5472582d50cSToby Isaac ierr = PetscSectionGetOffset(newCoordSection, DMPlexShiftPoint_Internal(v, depth, depthShift), &noff);CHKERRQ(ierr); 548f2b8cce1SMatthew G. Knepley for (d = 0; d < dof; ++d) newCoords[noff+d] = coords[off+d]; 549cd0c2139SMatthew G Knepley } 550cd0c2139SMatthew G Knepley ierr = VecRestoreArray(coordinates, &coords);CHKERRQ(ierr); 551cd0c2139SMatthew G Knepley ierr = VecRestoreArray(newCoordinates, &newCoords);CHKERRQ(ierr); 552cd0c2139SMatthew G Knepley ierr = VecDestroy(&newCoordinates);CHKERRQ(ierr); 553cd0c2139SMatthew G Knepley ierr = PetscSectionDestroy(&newCoordSection);CHKERRQ(ierr); 554cd0c2139SMatthew G Knepley PetscFunctionReturn(0); 555cd0c2139SMatthew G Knepley } 556cd0c2139SMatthew G Knepley 557cd0c2139SMatthew G Knepley static PetscErrorCode DMPlexShiftSF_Internal(DM dm, PetscInt depthShift[], DM dmNew) 558cd0c2139SMatthew G Knepley { 5592582d50cSToby Isaac PetscInt depth = 0; 560cd0c2139SMatthew G Knepley PetscSF sfPoint, sfPointNew; 561cd0c2139SMatthew G Knepley const PetscSFNode *remotePoints; 562cd0c2139SMatthew G Knepley PetscSFNode *gremotePoints; 563cd0c2139SMatthew G Knepley const PetscInt *localPoints; 564cd0c2139SMatthew G Knepley PetscInt *glocalPoints, *newLocation, *newRemoteLocation; 565cd0c2139SMatthew G Knepley PetscInt numRoots, numLeaves, l, pStart, pEnd, totShift = 0; 566cd0c2139SMatthew G Knepley PetscErrorCode ierr; 567cd0c2139SMatthew G Knepley 568cd0c2139SMatthew G Knepley PetscFunctionBegin; 569cd0c2139SMatthew G Knepley ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 570cd0c2139SMatthew G Knepley /* Step 9: Convert pointSF */ 571cd0c2139SMatthew G Knepley ierr = DMGetPointSF(dm, &sfPoint);CHKERRQ(ierr); 572cd0c2139SMatthew G Knepley ierr = DMGetPointSF(dmNew, &sfPointNew);CHKERRQ(ierr); 573cd0c2139SMatthew G Knepley ierr = DMPlexGetChart(dm, &pStart, &pEnd);CHKERRQ(ierr); 574cd0c2139SMatthew G Knepley ierr = PetscSFGetGraph(sfPoint, &numRoots, &numLeaves, &localPoints, &remotePoints);CHKERRQ(ierr); 5756e21efdcSToby Isaac totShift = DMPlexShiftPoint_Internal(pEnd,depth,depthShift) - pEnd; 576cd0c2139SMatthew G Knepley if (numRoots >= 0) { 577dcca6d9dSJed Brown ierr = PetscMalloc2(numRoots,&newLocation,pEnd-pStart,&newRemoteLocation);CHKERRQ(ierr); 5782582d50cSToby Isaac for (l=0; l<numRoots; l++) newLocation[l] = DMPlexShiftPoint_Internal(l, depth, depthShift); 579cd0c2139SMatthew G Knepley ierr = PetscSFBcastBegin(sfPoint, MPIU_INT, newLocation, newRemoteLocation);CHKERRQ(ierr); 580cd0c2139SMatthew G Knepley ierr = PetscSFBcastEnd(sfPoint, MPIU_INT, newLocation, newRemoteLocation);CHKERRQ(ierr); 581785e854fSJed Brown ierr = PetscMalloc1(numLeaves, &glocalPoints);CHKERRQ(ierr); 582785e854fSJed Brown ierr = PetscMalloc1(numLeaves, &gremotePoints);CHKERRQ(ierr); 583cd0c2139SMatthew G Knepley for (l = 0; l < numLeaves; ++l) { 5842582d50cSToby Isaac glocalPoints[l] = DMPlexShiftPoint_Internal(localPoints[l], depth, depthShift); 585cd0c2139SMatthew G Knepley gremotePoints[l].rank = remotePoints[l].rank; 586cd0c2139SMatthew G Knepley gremotePoints[l].index = newRemoteLocation[localPoints[l]]; 587cd0c2139SMatthew G Knepley } 588cd0c2139SMatthew G Knepley ierr = PetscFree2(newLocation,newRemoteLocation);CHKERRQ(ierr); 589cd0c2139SMatthew G Knepley ierr = PetscSFSetGraph(sfPointNew, numRoots + totShift, numLeaves, glocalPoints, PETSC_OWN_POINTER, gremotePoints, PETSC_OWN_POINTER);CHKERRQ(ierr); 590cd0c2139SMatthew G Knepley } 591cd0c2139SMatthew G Knepley PetscFunctionReturn(0); 592cd0c2139SMatthew G Knepley } 593cd0c2139SMatthew G Knepley 594cd0c2139SMatthew G Knepley static PetscErrorCode DMPlexShiftLabels_Internal(DM dm, PetscInt depthShift[], DM dmNew) 595cd0c2139SMatthew G Knepley { 596cd0c2139SMatthew G Knepley PetscSF sfPoint; 597cd0c2139SMatthew G Knepley DMLabel vtkLabel, ghostLabel; 598cd0c2139SMatthew G Knepley const PetscSFNode *leafRemote; 599cd0c2139SMatthew G Knepley const PetscInt *leafLocal; 6002582d50cSToby Isaac PetscInt depth = 0, numLeaves, numLabels, l, cStart, cEnd, c, fStart, fEnd, f; 601cd0c2139SMatthew G Knepley PetscMPIInt rank; 602cd0c2139SMatthew G Knepley PetscErrorCode ierr; 603cd0c2139SMatthew G Knepley 604cd0c2139SMatthew G Knepley PetscFunctionBegin; 605cd0c2139SMatthew G Knepley ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 606cd0c2139SMatthew G Knepley /* Step 10: Convert labels */ 607c58f1c22SToby Isaac ierr = DMGetNumLabels(dm, &numLabels);CHKERRQ(ierr); 608cd0c2139SMatthew G Knepley for (l = 0; l < numLabels; ++l) { 609cd0c2139SMatthew G Knepley DMLabel label, newlabel; 610cd0c2139SMatthew G Knepley const char *lname; 611fa8e8ae5SToby Isaac PetscBool isDepth, isDim; 612cd0c2139SMatthew G Knepley IS valueIS; 613cd0c2139SMatthew G Knepley const PetscInt *values; 614cd0c2139SMatthew G Knepley PetscInt numValues, val; 615cd0c2139SMatthew G Knepley 616c58f1c22SToby Isaac ierr = DMGetLabelName(dm, l, &lname);CHKERRQ(ierr); 617cd0c2139SMatthew G Knepley ierr = PetscStrcmp(lname, "depth", &isDepth);CHKERRQ(ierr); 618cd0c2139SMatthew G Knepley if (isDepth) continue; 619fa8e8ae5SToby Isaac ierr = PetscStrcmp(lname, "dim", &isDim);CHKERRQ(ierr); 620fa8e8ae5SToby Isaac if (isDim) continue; 621c58f1c22SToby Isaac ierr = DMCreateLabel(dmNew, lname);CHKERRQ(ierr); 622c58f1c22SToby Isaac ierr = DMGetLabel(dm, lname, &label);CHKERRQ(ierr); 623c58f1c22SToby Isaac ierr = DMGetLabel(dmNew, lname, &newlabel);CHKERRQ(ierr); 62464a6a1a4SToby Isaac ierr = DMLabelGetDefaultValue(label,&val);CHKERRQ(ierr); 62564a6a1a4SToby Isaac ierr = DMLabelSetDefaultValue(newlabel,val);CHKERRQ(ierr); 626cd0c2139SMatthew G Knepley ierr = DMLabelGetValueIS(label, &valueIS);CHKERRQ(ierr); 627cd0c2139SMatthew G Knepley ierr = ISGetLocalSize(valueIS, &numValues);CHKERRQ(ierr); 628cd0c2139SMatthew G Knepley ierr = ISGetIndices(valueIS, &values);CHKERRQ(ierr); 629cd0c2139SMatthew G Knepley for (val = 0; val < numValues; ++val) { 630cd0c2139SMatthew G Knepley IS pointIS; 631cd0c2139SMatthew G Knepley const PetscInt *points; 632cd0c2139SMatthew G Knepley PetscInt numPoints, p; 633cd0c2139SMatthew G Knepley 634cd0c2139SMatthew G Knepley ierr = DMLabelGetStratumIS(label, values[val], &pointIS);CHKERRQ(ierr); 635cd0c2139SMatthew G Knepley ierr = ISGetLocalSize(pointIS, &numPoints);CHKERRQ(ierr); 636cd0c2139SMatthew G Knepley ierr = ISGetIndices(pointIS, &points);CHKERRQ(ierr); 637cd0c2139SMatthew G Knepley for (p = 0; p < numPoints; ++p) { 6382582d50cSToby Isaac const PetscInt newpoint = DMPlexShiftPoint_Internal(points[p], depth, depthShift); 639cd0c2139SMatthew G Knepley 640cd0c2139SMatthew G Knepley ierr = DMLabelSetValue(newlabel, newpoint, values[val]);CHKERRQ(ierr); 641cd0c2139SMatthew G Knepley } 642cd0c2139SMatthew G Knepley ierr = ISRestoreIndices(pointIS, &points);CHKERRQ(ierr); 643cd0c2139SMatthew G Knepley ierr = ISDestroy(&pointIS);CHKERRQ(ierr); 644cd0c2139SMatthew G Knepley } 645cd0c2139SMatthew G Knepley ierr = ISRestoreIndices(valueIS, &values);CHKERRQ(ierr); 646cd0c2139SMatthew G Knepley ierr = ISDestroy(&valueIS);CHKERRQ(ierr); 647cd0c2139SMatthew G Knepley } 648cd0c2139SMatthew G Knepley /* Step 11: Make label for output (vtk) and to mark ghost points (ghost) */ 649cd0c2139SMatthew G Knepley ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)dm), &rank);CHKERRQ(ierr); 650cd0c2139SMatthew G Knepley ierr = DMGetPointSF(dm, &sfPoint);CHKERRQ(ierr); 651cd0c2139SMatthew G Knepley ierr = DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd);CHKERRQ(ierr); 652cd0c2139SMatthew G Knepley ierr = PetscSFGetGraph(sfPoint, NULL, &numLeaves, &leafLocal, &leafRemote);CHKERRQ(ierr); 653c58f1c22SToby Isaac ierr = DMCreateLabel(dmNew, "vtk");CHKERRQ(ierr); 654c58f1c22SToby Isaac ierr = DMCreateLabel(dmNew, "ghost");CHKERRQ(ierr); 655c58f1c22SToby Isaac ierr = DMGetLabel(dmNew, "vtk", &vtkLabel);CHKERRQ(ierr); 656c58f1c22SToby Isaac ierr = DMGetLabel(dmNew, "ghost", &ghostLabel);CHKERRQ(ierr); 657cd0c2139SMatthew G Knepley for (l = 0, c = cStart; l < numLeaves && c < cEnd; ++l, ++c) { 658cd0c2139SMatthew G Knepley for (; c < leafLocal[l] && c < cEnd; ++c) { 659cd0c2139SMatthew G Knepley ierr = DMLabelSetValue(vtkLabel, c, 1);CHKERRQ(ierr); 660cd0c2139SMatthew G Knepley } 661cd0c2139SMatthew G Knepley if (leafLocal[l] >= cEnd) break; 662cd0c2139SMatthew G Knepley if (leafRemote[l].rank == rank) { 663cd0c2139SMatthew G Knepley ierr = DMLabelSetValue(vtkLabel, c, 1);CHKERRQ(ierr); 664cd0c2139SMatthew G Knepley } else { 665cd0c2139SMatthew G Knepley ierr = DMLabelSetValue(ghostLabel, c, 2);CHKERRQ(ierr); 666cd0c2139SMatthew G Knepley } 667cd0c2139SMatthew G Knepley } 668cd0c2139SMatthew G Knepley for (; c < cEnd; ++c) { 669cd0c2139SMatthew G Knepley ierr = DMLabelSetValue(vtkLabel, c, 1);CHKERRQ(ierr); 670cd0c2139SMatthew G Knepley } 671cd0c2139SMatthew G Knepley ierr = DMPlexGetHeightStratum(dmNew, 1, &fStart, &fEnd);CHKERRQ(ierr); 672cd0c2139SMatthew G Knepley for (f = fStart; f < fEnd; ++f) { 673cd0c2139SMatthew G Knepley PetscInt numCells; 674cd0c2139SMatthew G Knepley 675cd0c2139SMatthew G Knepley ierr = DMPlexGetSupportSize(dmNew, f, &numCells);CHKERRQ(ierr); 676cd0c2139SMatthew G Knepley if (numCells < 2) { 677cd0c2139SMatthew G Knepley ierr = DMLabelSetValue(ghostLabel, f, 1);CHKERRQ(ierr); 678cd0c2139SMatthew G Knepley } else { 679cd0c2139SMatthew G Knepley const PetscInt *cells = NULL; 680cd0c2139SMatthew G Knepley PetscInt vA, vB; 681cd0c2139SMatthew G Knepley 682cd0c2139SMatthew G Knepley ierr = DMPlexGetSupport(dmNew, f, &cells);CHKERRQ(ierr); 683cd0c2139SMatthew G Knepley ierr = DMLabelGetValue(vtkLabel, cells[0], &vA);CHKERRQ(ierr); 684cd0c2139SMatthew G Knepley ierr = DMLabelGetValue(vtkLabel, cells[1], &vB);CHKERRQ(ierr); 68590664b96SToby Isaac if (vA != 1 && vB != 1) {ierr = DMLabelSetValue(ghostLabel, f, 1);CHKERRQ(ierr);} 686cd0c2139SMatthew G Knepley } 687cd0c2139SMatthew G Knepley } 688cd0c2139SMatthew G Knepley PetscFunctionReturn(0); 689cd0c2139SMatthew G Knepley } 690cd0c2139SMatthew G Knepley 691ca04dac2SToby Isaac static PetscErrorCode DMPlexShiftTree_Internal(DM dm, PetscInt depthShift[], DM dmNew) 692ca04dac2SToby Isaac { 693ca04dac2SToby Isaac DM refTree; 694ca04dac2SToby Isaac PetscSection pSec; 695ca04dac2SToby Isaac PetscInt *parents, *childIDs; 696ca04dac2SToby Isaac PetscErrorCode ierr; 697ca04dac2SToby Isaac 698ca04dac2SToby Isaac PetscFunctionBegin; 699ca04dac2SToby Isaac ierr = DMPlexGetReferenceTree(dm,&refTree);CHKERRQ(ierr); 700ca04dac2SToby Isaac ierr = DMPlexSetReferenceTree(dmNew,refTree);CHKERRQ(ierr); 701ca04dac2SToby Isaac ierr = DMPlexGetTree(dm,&pSec,&parents,&childIDs,NULL,NULL);CHKERRQ(ierr); 702ca04dac2SToby Isaac if (pSec) { 7032582d50cSToby Isaac PetscInt p, pStart, pEnd, *parentsShifted, pStartShifted, pEndShifted, depth; 704fb4630b5SToby Isaac PetscInt *childIDsShifted; 705ca04dac2SToby Isaac PetscSection pSecShifted; 706ca04dac2SToby Isaac 707ca04dac2SToby Isaac ierr = PetscSectionGetChart(pSec,&pStart,&pEnd);CHKERRQ(ierr); 708ca04dac2SToby Isaac ierr = DMPlexGetDepth(dm,&depth);CHKERRQ(ierr); 7092582d50cSToby Isaac pStartShifted = DMPlexShiftPoint_Internal(pStart,depth,depthShift); 7102582d50cSToby Isaac pEndShifted = DMPlexShiftPoint_Internal(pEnd,depth,depthShift); 711fb4630b5SToby Isaac ierr = PetscMalloc2(pEndShifted - pStartShifted,&parentsShifted,pEndShifted-pStartShifted,&childIDsShifted);CHKERRQ(ierr); 712ca04dac2SToby Isaac ierr = PetscSectionCreate(PetscObjectComm((PetscObject)dmNew),&pSecShifted);CHKERRQ(ierr); 713ca04dac2SToby Isaac ierr = PetscSectionSetChart(pSecShifted,pStartShifted,pEndShifted);CHKERRQ(ierr); 714ca04dac2SToby Isaac for (p = pStartShifted; p < pEndShifted; p++) { 715fb4630b5SToby Isaac /* start off assuming no children */ 716fb4630b5SToby Isaac ierr = PetscSectionSetDof(pSecShifted,p,0);CHKERRQ(ierr); 717fb4630b5SToby Isaac } 718fb4630b5SToby Isaac for (p = pStart; p < pEnd; p++) { 719fb4630b5SToby Isaac PetscInt dof; 720fb4630b5SToby Isaac PetscInt pNew = DMPlexShiftPoint_Internal(p,depth,depthShift); 721ca04dac2SToby Isaac 722ca04dac2SToby Isaac ierr = PetscSectionGetDof(pSec,p,&dof);CHKERRQ(ierr); 723fb4630b5SToby Isaac ierr = PetscSectionSetDof(pSecShifted,pNew,dof);CHKERRQ(ierr); 724ca04dac2SToby Isaac } 725ca04dac2SToby Isaac ierr = PetscSectionSetUp(pSecShifted);CHKERRQ(ierr); 726fb4630b5SToby Isaac for (p = pStart; p < pEnd; p++) { 727fb4630b5SToby Isaac PetscInt dof; 728fb4630b5SToby Isaac PetscInt pNew = DMPlexShiftPoint_Internal(p,depth,depthShift); 729fb4630b5SToby Isaac 730fb4630b5SToby Isaac ierr = PetscSectionGetDof(pSec,p,&dof);CHKERRQ(ierr); 731fb4630b5SToby Isaac if (dof) { 732fb4630b5SToby Isaac PetscInt off, offNew; 733fb4630b5SToby Isaac 734fb4630b5SToby Isaac ierr = PetscSectionGetOffset(pSec,p,&off);CHKERRQ(ierr); 735fb4630b5SToby Isaac ierr = PetscSectionGetOffset(pSecShifted,pNew,&offNew);CHKERRQ(ierr); 736fb4630b5SToby Isaac parentsShifted[offNew] = DMPlexShiftPoint_Internal(parents[off],depth,depthShift); 737fb4630b5SToby Isaac childIDsShifted[offNew] = childIDs[off]; 738fb4630b5SToby Isaac } 739fb4630b5SToby Isaac } 740fb4630b5SToby Isaac ierr = DMPlexSetTree(dmNew,pSecShifted,parentsShifted,childIDsShifted);CHKERRQ(ierr); 741fb4630b5SToby Isaac ierr = PetscFree2(parentsShifted,childIDsShifted);CHKERRQ(ierr); 742e6885bbbSToby Isaac ierr = PetscSectionDestroy(&pSecShifted);CHKERRQ(ierr); 743ca04dac2SToby Isaac } 744ca04dac2SToby Isaac PetscFunctionReturn(0); 745ca04dac2SToby Isaac } 746ca04dac2SToby Isaac 747cd0c2139SMatthew G Knepley static PetscErrorCode DMPlexConstructGhostCells_Internal(DM dm, DMLabel label, PetscInt *numGhostCells, DM gdm) 748cd0c2139SMatthew G Knepley { 749da97024aSMatthew G. Knepley PetscSF sf; 750cd0c2139SMatthew G Knepley IS valueIS; 751da97024aSMatthew G. Knepley const PetscInt *values, *leaves; 752cd0c2139SMatthew G Knepley PetscInt *depthShift; 7532582d50cSToby Isaac PetscInt d, depth = 0, nleaves, loc, Ng, numFS, fs, fStart, fEnd, ghostCell, cEnd, c; 75490b157c4SStefano Zampini PetscBool isper; 75590b157c4SStefano Zampini const PetscReal *maxCell, *L; 75690b157c4SStefano Zampini const DMBoundaryType *bd; 757cd0c2139SMatthew G Knepley PetscErrorCode ierr; 758cd0c2139SMatthew G Knepley 759cd0c2139SMatthew G Knepley PetscFunctionBegin; 760da97024aSMatthew G. Knepley ierr = DMGetPointSF(dm, &sf);CHKERRQ(ierr); 761da97024aSMatthew G. Knepley ierr = PetscSFGetGraph(sf, NULL, &nleaves, &leaves, NULL);CHKERRQ(ierr); 762da97024aSMatthew G. Knepley nleaves = PetscMax(0, nleaves); 76346c796b9SMatthew G. Knepley ierr = DMPlexGetHeightStratum(dm, 1, &fStart, &fEnd);CHKERRQ(ierr); 764cd0c2139SMatthew G Knepley /* Count ghost cells */ 765cd0c2139SMatthew G Knepley ierr = DMLabelGetValueIS(label, &valueIS);CHKERRQ(ierr); 766cd0c2139SMatthew G Knepley ierr = ISGetLocalSize(valueIS, &numFS);CHKERRQ(ierr); 767cd0c2139SMatthew G Knepley ierr = ISGetIndices(valueIS, &values);CHKERRQ(ierr); 7684a6cfa73SMatthew G. Knepley Ng = 0; 769cd0c2139SMatthew G Knepley for (fs = 0; fs < numFS; ++fs) { 77046c796b9SMatthew G. Knepley IS faceIS; 77146c796b9SMatthew G. Knepley const PetscInt *faces; 77246c796b9SMatthew G. Knepley PetscInt numFaces, f, numBdFaces = 0; 773cd0c2139SMatthew G Knepley 77446c796b9SMatthew G. Knepley ierr = DMLabelGetStratumIS(label, values[fs], &faceIS);CHKERRQ(ierr); 77546c796b9SMatthew G. Knepley ierr = ISGetLocalSize(faceIS, &numFaces);CHKERRQ(ierr); 77646c796b9SMatthew G. Knepley ierr = ISGetIndices(faceIS, &faces);CHKERRQ(ierr); 77746c796b9SMatthew G. Knepley for (f = 0; f < numFaces; ++f) { 778ca04dac2SToby Isaac PetscInt numChildren; 779ca04dac2SToby Isaac 780da97024aSMatthew G. Knepley ierr = PetscFindInt(faces[f], nleaves, leaves, &loc);CHKERRQ(ierr); 781ca04dac2SToby Isaac ierr = DMPlexGetTreeChildren(dm,faces[f],&numChildren,NULL);CHKERRQ(ierr); 782ca04dac2SToby Isaac /* non-local and ancestors points don't get to register ghosts */ 783ca04dac2SToby Isaac if (loc >= 0 || numChildren) continue; 78446c796b9SMatthew G. Knepley if ((faces[f] >= fStart) && (faces[f] < fEnd)) ++numBdFaces; 78546c796b9SMatthew G. Knepley } 7864a6cfa73SMatthew G. Knepley Ng += numBdFaces; 787*ba2698f1SMatthew G. Knepley ierr = ISRestoreIndices(faceIS, &faces);CHKERRQ(ierr); 78846c796b9SMatthew G. Knepley ierr = ISDestroy(&faceIS);CHKERRQ(ierr); 789cd0c2139SMatthew G Knepley } 790cd0c2139SMatthew G Knepley ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 7912582d50cSToby Isaac ierr = PetscMalloc1(2*(depth+1), &depthShift);CHKERRQ(ierr); 7922582d50cSToby Isaac for (d = 0; d <= depth; d++) { 79359eef20bSToby Isaac PetscInt dEnd; 7942582d50cSToby Isaac 7950974a383SToby Isaac ierr = DMPlexGetDepthStratum(dm,d,NULL,&dEnd);CHKERRQ(ierr); 79659eef20bSToby Isaac depthShift[2*d] = dEnd; 7972582d50cSToby Isaac depthShift[2*d+1] = 0; 7982582d50cSToby Isaac } 7992582d50cSToby Isaac if (depth >= 0) depthShift[2*depth+1] = Ng; 8002582d50cSToby Isaac ierr = DMPlexShiftPointSetUp_Internal(depth,depthShift);CHKERRQ(ierr); 801cd0c2139SMatthew G Knepley ierr = DMPlexShiftSizes_Internal(dm, depthShift, gdm);CHKERRQ(ierr); 802cd0c2139SMatthew G Knepley /* Step 3: Set cone/support sizes for new points */ 803cd0c2139SMatthew G Knepley ierr = DMPlexGetHeightStratum(dm, 0, NULL, &cEnd);CHKERRQ(ierr); 804485ad865SMatthew G. Knepley ierr = DMPlexSetGhostCellStratum(gdm, cEnd, PETSC_DETERMINE);CHKERRQ(ierr); 8054a6cfa73SMatthew G. Knepley for (c = cEnd; c < cEnd + Ng; ++c) { 806cd0c2139SMatthew G Knepley ierr = DMPlexSetConeSize(gdm, c, 1);CHKERRQ(ierr); 807cd0c2139SMatthew G Knepley } 808cd0c2139SMatthew G Knepley for (fs = 0; fs < numFS; ++fs) { 809cd0c2139SMatthew G Knepley IS faceIS; 810cd0c2139SMatthew G Knepley const PetscInt *faces; 811cd0c2139SMatthew G Knepley PetscInt numFaces, f; 812cd0c2139SMatthew G Knepley 813cd0c2139SMatthew G Knepley ierr = DMLabelGetStratumIS(label, values[fs], &faceIS);CHKERRQ(ierr); 814cd0c2139SMatthew G Knepley ierr = ISGetLocalSize(faceIS, &numFaces);CHKERRQ(ierr); 815cd0c2139SMatthew G Knepley ierr = ISGetIndices(faceIS, &faces);CHKERRQ(ierr); 816cd0c2139SMatthew G Knepley for (f = 0; f < numFaces; ++f) { 817ca04dac2SToby Isaac PetscInt size, numChildren; 818cd0c2139SMatthew G Knepley 819da97024aSMatthew G. Knepley ierr = PetscFindInt(faces[f], nleaves, leaves, &loc);CHKERRQ(ierr); 820ca04dac2SToby Isaac ierr = DMPlexGetTreeChildren(dm,faces[f],&numChildren,NULL);CHKERRQ(ierr); 821ca04dac2SToby Isaac if (loc >= 0 || numChildren) continue; 82246c796b9SMatthew G. Knepley if ((faces[f] < fStart) || (faces[f] >= fEnd)) continue; 823cd0c2139SMatthew G Knepley ierr = DMPlexGetSupportSize(dm, faces[f], &size);CHKERRQ(ierr); 8244553fd90SToby Isaac if (size != 1) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "DM has boundary face %d with %d support cells", faces[f], size); 8254a6cfa73SMatthew G. Knepley ierr = DMPlexSetSupportSize(gdm, faces[f] + Ng, 2);CHKERRQ(ierr); 826cd0c2139SMatthew G Knepley } 827cd0c2139SMatthew G Knepley ierr = ISRestoreIndices(faceIS, &faces);CHKERRQ(ierr); 828cd0c2139SMatthew G Knepley ierr = ISDestroy(&faceIS);CHKERRQ(ierr); 829cd0c2139SMatthew G Knepley } 830cd0c2139SMatthew G Knepley /* Step 4: Setup ghosted DM */ 831cd0c2139SMatthew G Knepley ierr = DMSetUp(gdm);CHKERRQ(ierr); 832cd0c2139SMatthew G Knepley ierr = DMPlexShiftPoints_Internal(dm, depthShift, gdm);CHKERRQ(ierr); 833cd0c2139SMatthew G Knepley /* Step 6: Set cones and supports for new points */ 834cd0c2139SMatthew G Knepley ghostCell = cEnd; 835cd0c2139SMatthew G Knepley for (fs = 0; fs < numFS; ++fs) { 836cd0c2139SMatthew G Knepley IS faceIS; 837cd0c2139SMatthew G Knepley const PetscInt *faces; 838cd0c2139SMatthew G Knepley PetscInt numFaces, f; 839cd0c2139SMatthew G Knepley 840cd0c2139SMatthew G Knepley ierr = DMLabelGetStratumIS(label, values[fs], &faceIS);CHKERRQ(ierr); 841cd0c2139SMatthew G Knepley ierr = ISGetLocalSize(faceIS, &numFaces);CHKERRQ(ierr); 842cd0c2139SMatthew G Knepley ierr = ISGetIndices(faceIS, &faces);CHKERRQ(ierr); 84346c796b9SMatthew G. Knepley for (f = 0; f < numFaces; ++f) { 844ca04dac2SToby Isaac PetscInt newFace = faces[f] + Ng, numChildren; 845cd0c2139SMatthew G Knepley 846da97024aSMatthew G. Knepley ierr = PetscFindInt(faces[f], nleaves, leaves, &loc);CHKERRQ(ierr); 847ca04dac2SToby Isaac ierr = DMPlexGetTreeChildren(dm,faces[f],&numChildren,NULL);CHKERRQ(ierr); 848ca04dac2SToby Isaac if (loc >= 0 || numChildren) continue; 84946c796b9SMatthew G. Knepley if ((faces[f] < fStart) || (faces[f] >= fEnd)) continue; 850cd0c2139SMatthew G Knepley ierr = DMPlexSetCone(gdm, ghostCell, &newFace);CHKERRQ(ierr); 851cd0c2139SMatthew G Knepley ierr = DMPlexInsertSupport(gdm, newFace, 1, ghostCell);CHKERRQ(ierr); 85246c796b9SMatthew G. Knepley ++ghostCell; 853cd0c2139SMatthew G Knepley } 854cd0c2139SMatthew G Knepley ierr = ISRestoreIndices(faceIS, &faces);CHKERRQ(ierr); 855cd0c2139SMatthew G Knepley ierr = ISDestroy(&faceIS);CHKERRQ(ierr); 856cd0c2139SMatthew G Knepley } 857cd0c2139SMatthew G Knepley ierr = ISRestoreIndices(valueIS, &values);CHKERRQ(ierr); 858cd0c2139SMatthew G Knepley ierr = ISDestroy(&valueIS);CHKERRQ(ierr); 859cd0c2139SMatthew G Knepley ierr = DMPlexShiftCoordinates_Internal(dm, depthShift, gdm);CHKERRQ(ierr); 860cd0c2139SMatthew G Knepley ierr = DMPlexShiftSF_Internal(dm, depthShift, gdm);CHKERRQ(ierr); 861cd0c2139SMatthew G Knepley ierr = DMPlexShiftLabels_Internal(dm, depthShift, gdm);CHKERRQ(ierr); 862ca04dac2SToby Isaac ierr = DMPlexShiftTree_Internal(dm, depthShift, gdm);CHKERRQ(ierr); 863cd0c2139SMatthew G Knepley ierr = PetscFree(depthShift);CHKERRQ(ierr); 864966c7b3fSMatthew G. Knepley /* Step 7: Periodicity */ 86590b157c4SStefano Zampini ierr = DMGetPeriodicity(dm, &isper, &maxCell, &L, &bd);CHKERRQ(ierr); 86690b157c4SStefano Zampini ierr = DMSetPeriodicity(gdm, isper, maxCell, L, bd);CHKERRQ(ierr); 8674a6cfa73SMatthew G. Knepley if (numGhostCells) *numGhostCells = Ng; 868cd0c2139SMatthew G Knepley PetscFunctionReturn(0); 869cd0c2139SMatthew G Knepley } 870cd0c2139SMatthew G Knepley 871cd0c2139SMatthew G Knepley /*@C 872cd0c2139SMatthew G Knepley DMPlexConstructGhostCells - Construct ghost cells which connect to every boundary face 873cd0c2139SMatthew G Knepley 874cd0c2139SMatthew G Knepley Collective on dm 875cd0c2139SMatthew G Knepley 876cd0c2139SMatthew G Knepley Input Parameters: 877cd0c2139SMatthew G Knepley + dm - The original DM 878cd0c2139SMatthew G Knepley - labelName - The label specifying the boundary faces, or "Face Sets" if this is NULL 879cd0c2139SMatthew G Knepley 880cd0c2139SMatthew G Knepley Output Parameters: 881cd0c2139SMatthew G Knepley + numGhostCells - The number of ghost cells added to the DM 882cd0c2139SMatthew G Knepley - dmGhosted - The new DM 883cd0c2139SMatthew G Knepley 884cd0c2139SMatthew G Knepley Note: If no label exists of that name, one will be created marking all boundary faces 885cd0c2139SMatthew G Knepley 886cd0c2139SMatthew G Knepley Level: developer 887cd0c2139SMatthew G Knepley 888cd0c2139SMatthew G Knepley .seealso: DMCreate() 88931266bc0SMatthew G. Knepley @*/ 890cd0c2139SMatthew G Knepley PetscErrorCode DMPlexConstructGhostCells(DM dm, const char labelName[], PetscInt *numGhostCells, DM *dmGhosted) 891cd0c2139SMatthew G Knepley { 892cd0c2139SMatthew G Knepley DM gdm; 893cd0c2139SMatthew G Knepley DMLabel label; 894cd0c2139SMatthew G Knepley const char *name = labelName ? labelName : "Face Sets"; 895d80ece95SMatthew G. Knepley PetscInt dim, Ng = 0, cMax, fMax, eMax, vMax; 896b0441da4SMatthew G. Knepley PetscBool useCone, useClosure; 897cd0c2139SMatthew G Knepley PetscErrorCode ierr; 898cd0c2139SMatthew G Knepley 899cd0c2139SMatthew G Knepley PetscFunctionBegin; 900cd0c2139SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 9014a6cfa73SMatthew G. Knepley if (numGhostCells) PetscValidPointer(numGhostCells, 3); 902cd0c2139SMatthew G Knepley PetscValidPointer(dmGhosted, 4); 903cd0c2139SMatthew G Knepley ierr = DMCreate(PetscObjectComm((PetscObject)dm), &gdm);CHKERRQ(ierr); 904cd0c2139SMatthew G Knepley ierr = DMSetType(gdm, DMPLEX);CHKERRQ(ierr); 905c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 906c73cfb54SMatthew G. Knepley ierr = DMSetDimension(gdm, dim);CHKERRQ(ierr); 907b0441da4SMatthew G. Knepley ierr = DMGetBasicAdjacency(dm, &useCone, &useClosure);CHKERRQ(ierr); 908b0441da4SMatthew G. Knepley ierr = DMSetBasicAdjacency(gdm, useCone, useClosure);CHKERRQ(ierr); 909c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 910cd0c2139SMatthew G Knepley if (!label) { 911cd0c2139SMatthew G Knepley /* Get label for boundary faces */ 912c58f1c22SToby Isaac ierr = DMCreateLabel(dm, name);CHKERRQ(ierr); 913c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 914e752be1aSMatthew G. Knepley ierr = DMPlexMarkBoundaryFaces(dm, 1, label);CHKERRQ(ierr); 915cd0c2139SMatthew G Knepley } 916d80ece95SMatthew G. Knepley ierr = DMPlexConstructGhostCells_Internal(dm, label, &Ng, gdm);CHKERRQ(ierr); 917a6ba4734SToby Isaac ierr = DMCopyBoundary(dm, gdm);CHKERRQ(ierr); 918b0441da4SMatthew G. Knepley ierr = DMCopyDisc(dm, gdm);CHKERRQ(ierr); 919d80ece95SMatthew G. Knepley /* Copy the hybrid bounds */ 920d80ece95SMatthew G. Knepley ierr = DMPlexGetHybridBounds(dm, &cMax, &fMax, &eMax, &vMax);CHKERRQ(ierr); 921d80ece95SMatthew G. Knepley if (fMax >= 0) fMax += Ng; 922d80ece95SMatthew G. Knepley if (eMax >= 0) eMax += Ng; 923d80ece95SMatthew G. Knepley if (vMax >= 0) vMax += Ng; 924d80ece95SMatthew G. Knepley ierr = DMPlexSetHybridBounds(gdm, cMax, fMax, eMax, vMax);CHKERRQ(ierr); 925cad26855SMatthew G. Knepley gdm->setfromoptionscalled = dm->setfromoptionscalled; 926d80ece95SMatthew G. Knepley if (numGhostCells) *numGhostCells = Ng; 927cd0c2139SMatthew G Knepley *dmGhosted = gdm; 928cd0c2139SMatthew G Knepley PetscFunctionReturn(0); 929cd0c2139SMatthew G Knepley } 930cd0c2139SMatthew G Knepley 931607ab7a9SMatthew G. Knepley /* 932faedd622SMatthew G. Knepley We are adding three kinds of points here: 933607ab7a9SMatthew G. Knepley Replicated: Copies of points which exist in the mesh, such as vertices identified across a fault 934faedd622SMatthew G. Knepley Non-replicated: Points which exist on the fault, but are not replicated 935607ab7a9SMatthew G. Knepley Hybrid: Entirely new points, such as cohesive cells 936a6ae58d1SMatthew G. Knepley 937a6ae58d1SMatthew G. Knepley When creating subsequent cohesive cells, we shift the old hybrid cells to the end of the numbering at 938a6ae58d1SMatthew G. Knepley each depth so that the new split/hybrid points can be inserted as a block. 939607ab7a9SMatthew G. Knepley */ 9407db7e0a7SMatthew G. Knepley static PetscErrorCode DMPlexConstructCohesiveCells_Internal(DM dm, DMLabel label, DMLabel splitLabel, DM sdm) 941cd0c2139SMatthew G Knepley { 942cd0c2139SMatthew G Knepley MPI_Comm comm; 943607ab7a9SMatthew G. Knepley IS valueIS; 944607ab7a9SMatthew G. Knepley PetscInt numSP = 0; /* The number of depths for which we have replicated points */ 945607ab7a9SMatthew G. Knepley const PetscInt *values; /* List of depths for which we have replicated points */ 94618c5995bSMatthew G. Knepley IS *splitIS; 94718c5995bSMatthew G. Knepley IS *unsplitIS; 948607ab7a9SMatthew G. Knepley PetscInt *numSplitPoints; /* The number of replicated points at each depth */ 94918c5995bSMatthew G. Knepley PetscInt *numUnsplitPoints; /* The number of non-replicated points at each depth which still give rise to hybrid points */ 95036dbac82SMatthew G. Knepley PetscInt *numHybridPoints; /* The number of new hybrid points at each depth */ 95136dbac82SMatthew G. Knepley PetscInt *numHybridPointsOld; /* The number of existing hybrid points at each depth */ 952607ab7a9SMatthew G. Knepley const PetscInt **splitPoints; /* Replicated points for each depth */ 95318c5995bSMatthew G. Knepley const PetscInt **unsplitPoints; /* Non-replicated points for each depth */ 954cd0c2139SMatthew G Knepley PetscSection coordSection; 955cd0c2139SMatthew G Knepley Vec coordinates; 956cd0c2139SMatthew G Knepley PetscScalar *coords; 957a6ae58d1SMatthew G. Knepley PetscInt *depthMax; /* The first hybrid point at each depth in the original mesh */ 958a6ae58d1SMatthew G. Knepley PetscInt *depthEnd; /* The point limit at each depth in the original mesh */ 959607ab7a9SMatthew G. Knepley PetscInt *depthShift; /* Number of replicated+hybrid points at each depth */ 960607ab7a9SMatthew G. Knepley PetscInt *pMaxNew; /* The first replicated point at each depth in the new mesh, hybrids come after this */ 961607ab7a9SMatthew G. Knepley PetscInt *coneNew, *coneONew, *supportNew; 96218c5995bSMatthew G. Knepley PetscInt shift = 100, shift2 = 200, depth = 0, dep, dim, d, sp, maxConeSize, maxSupportSize, maxConeSizeNew, maxSupportSizeNew, numLabels, vStart, vEnd, pEnd, p, v; 963cd0c2139SMatthew G Knepley PetscErrorCode ierr; 964cd0c2139SMatthew G Knepley 965cd0c2139SMatthew G Knepley PetscFunctionBegin; 966cd0c2139SMatthew G Knepley ierr = PetscObjectGetComm((PetscObject)dm,&comm);CHKERRQ(ierr); 967c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 968607ab7a9SMatthew G. Knepley ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 969fd4b9f15SMatthew G. Knepley ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr); 970cd0c2139SMatthew G Knepley /* Count split points and add cohesive cells */ 971607ab7a9SMatthew G. Knepley ierr = DMPlexGetMaxSizes(dm, &maxConeSize, &maxSupportSize);CHKERRQ(ierr); 9722582d50cSToby Isaac ierr = PetscMalloc5(depth+1,&depthMax,depth+1,&depthEnd,2*(depth+1),&depthShift,depth+1,&pMaxNew,depth+1,&numHybridPointsOld);CHKERRQ(ierr); 973dcca6d9dSJed Brown ierr = PetscMalloc7(depth+1,&splitIS,depth+1,&unsplitIS,depth+1,&numSplitPoints,depth+1,&numUnsplitPoints,depth+1,&numHybridPoints,depth+1,&splitPoints,depth+1,&unsplitPoints);CHKERRQ(ierr); 974a6ae58d1SMatthew G. Knepley ierr = DMPlexGetHybridBounds(dm, depth >= 0 ? &depthMax[depth] : NULL, depth>1 ? &depthMax[depth-1] : NULL, depth>2 ? &depthMax[1] : NULL, depth >= 0 ? &depthMax[0] : NULL);CHKERRQ(ierr); 975607ab7a9SMatthew G. Knepley for (d = 0; d <= depth; ++d) { 976607ab7a9SMatthew G. Knepley ierr = DMPlexGetDepthStratum(dm, d, NULL, &pMaxNew[d]);CHKERRQ(ierr); 977a6ae58d1SMatthew G. Knepley depthEnd[d] = pMaxNew[d]; 978a6ae58d1SMatthew G. Knepley depthMax[d] = depthMax[d] < 0 ? depthEnd[d] : depthMax[d]; 979607ab7a9SMatthew G. Knepley numSplitPoints[d] = 0; 98018c5995bSMatthew G. Knepley numUnsplitPoints[d] = 0; 981607ab7a9SMatthew G. Knepley numHybridPoints[d] = 0; 982a6ae58d1SMatthew G. Knepley numHybridPointsOld[d] = depthMax[d] < 0 ? 0 : depthEnd[d] - depthMax[d]; 983607ab7a9SMatthew G. Knepley splitPoints[d] = NULL; 98418c5995bSMatthew G. Knepley unsplitPoints[d] = NULL; 98518c5995bSMatthew G. Knepley splitIS[d] = NULL; 98618c5995bSMatthew G. Knepley unsplitIS[d] = NULL; 98759eef20bSToby Isaac /* we are shifting the existing hybrid points with the stratum behind them, so 98859eef20bSToby Isaac * the split comes at the end of the normal points, i.e., at depthMax[d] */ 98959eef20bSToby Isaac depthShift[2*d] = depthMax[d]; 99059eef20bSToby Isaac depthShift[2*d+1] = 0; 991607ab7a9SMatthew G. Knepley } 992cd0c2139SMatthew G Knepley if (label) { 993cd0c2139SMatthew G Knepley ierr = DMLabelGetValueIS(label, &valueIS);CHKERRQ(ierr); 994cd0c2139SMatthew G Knepley ierr = ISGetLocalSize(valueIS, &numSP);CHKERRQ(ierr); 995cd0c2139SMatthew G Knepley ierr = ISGetIndices(valueIS, &values);CHKERRQ(ierr); 996cd0c2139SMatthew G Knepley } 997cd0c2139SMatthew G Knepley for (sp = 0; sp < numSP; ++sp) { 998cd0c2139SMatthew G Knepley const PetscInt dep = values[sp]; 999cd0c2139SMatthew G Knepley 1000cd0c2139SMatthew G Knepley if ((dep < 0) || (dep > depth)) continue; 100118c5995bSMatthew G. Knepley ierr = DMLabelGetStratumIS(label, dep, &splitIS[dep]);CHKERRQ(ierr); 100218c5995bSMatthew G. Knepley if (splitIS[dep]) { 100318c5995bSMatthew G. Knepley ierr = ISGetLocalSize(splitIS[dep], &numSplitPoints[dep]);CHKERRQ(ierr); 100418c5995bSMatthew G. Knepley ierr = ISGetIndices(splitIS[dep], &splitPoints[dep]);CHKERRQ(ierr); 100518c5995bSMatthew G. Knepley } 100618c5995bSMatthew G. Knepley ierr = DMLabelGetStratumIS(label, shift2+dep, &unsplitIS[dep]);CHKERRQ(ierr); 100718c5995bSMatthew G. Knepley if (unsplitIS[dep]) { 100818c5995bSMatthew G. Knepley ierr = ISGetLocalSize(unsplitIS[dep], &numUnsplitPoints[dep]);CHKERRQ(ierr); 100918c5995bSMatthew G. Knepley ierr = ISGetIndices(unsplitIS[dep], &unsplitPoints[dep]);CHKERRQ(ierr); 1010cd0c2139SMatthew G Knepley } 1011cd0c2139SMatthew G Knepley } 1012607ab7a9SMatthew G. Knepley /* Calculate number of hybrid points */ 101318c5995bSMatthew G. Knepley for (d = 1; d <= depth; ++d) numHybridPoints[d] = numSplitPoints[d-1] + numUnsplitPoints[d-1]; /* There is a hybrid cell/face/edge for every split face/edge/vertex */ 10142582d50cSToby Isaac for (d = 0; d <= depth; ++d) depthShift[2*d+1] = numSplitPoints[d] + numHybridPoints[d]; 10153d3eaba7SBarry Smith ierr = DMPlexShiftPointSetUp_Internal(depth,depthShift);CHKERRQ(ierr); 101659eef20bSToby Isaac /* the end of the points in this stratum that come before the new points: 101759eef20bSToby Isaac * shifting pMaxNew[d] gets the new start of the next stratum, then count back the old hybrid points and the newly 101859eef20bSToby Isaac * added points */ 10192582d50cSToby Isaac for (d = 0; d <= depth; ++d) pMaxNew[d] = DMPlexShiftPoint_Internal(pMaxNew[d],depth,depthShift) - (numHybridPointsOld[d] + numSplitPoints[d] + numHybridPoints[d]); 1020cd0c2139SMatthew G Knepley ierr = DMPlexShiftSizes_Internal(dm, depthShift, sdm);CHKERRQ(ierr); 1021cd0c2139SMatthew G Knepley /* Step 3: Set cone/support sizes for new points */ 1022cd0c2139SMatthew G Knepley for (dep = 0; dep <= depth; ++dep) { 1023cd0c2139SMatthew G Knepley for (p = 0; p < numSplitPoints[dep]; ++p) { 1024cd0c2139SMatthew G Knepley const PetscInt oldp = splitPoints[dep][p]; 10252582d50cSToby Isaac const PetscInt newp = DMPlexShiftPoint_Internal(oldp, depth, depthShift) /*oldp + depthOffset[dep]*/; 10264c367dbcSMatthew G. Knepley const PetscInt splitp = p + pMaxNew[dep]; 1027cd0c2139SMatthew G Knepley const PetscInt *support; 10284c367dbcSMatthew G. Knepley PetscInt coneSize, supportSize, qf, qn, qp, e; 1029cd0c2139SMatthew G Knepley 1030cd0c2139SMatthew G Knepley ierr = DMPlexGetConeSize(dm, oldp, &coneSize);CHKERRQ(ierr); 1031cd0c2139SMatthew G Knepley ierr = DMPlexSetConeSize(sdm, splitp, coneSize);CHKERRQ(ierr); 1032cd0c2139SMatthew G Knepley ierr = DMPlexGetSupportSize(dm, oldp, &supportSize);CHKERRQ(ierr); 1033cd0c2139SMatthew G Knepley ierr = DMPlexSetSupportSize(sdm, splitp, supportSize);CHKERRQ(ierr); 1034cd0c2139SMatthew G Knepley if (dep == depth-1) { 10354c367dbcSMatthew G. Knepley const PetscInt hybcell = p + pMaxNew[dep+1] + numSplitPoints[dep+1]; 10364c367dbcSMatthew G. Knepley 1037cd0c2139SMatthew G Knepley /* Add cohesive cells, they are prisms */ 10384c367dbcSMatthew G. Knepley ierr = DMPlexSetConeSize(sdm, hybcell, 2 + coneSize);CHKERRQ(ierr); 1039cd0c2139SMatthew G Knepley } else if (dep == 0) { 10404c367dbcSMatthew G. Knepley const PetscInt hybedge = p + pMaxNew[dep+1] + numSplitPoints[dep+1]; 1041cd0c2139SMatthew G Knepley 1042cd0c2139SMatthew G Knepley ierr = DMPlexGetSupport(dm, oldp, &support);CHKERRQ(ierr); 10434c367dbcSMatthew G. Knepley for (e = 0, qn = 0, qp = 0, qf = 0; e < supportSize; ++e) { 1044cd0c2139SMatthew G Knepley PetscInt val; 1045cd0c2139SMatthew G Knepley 1046cd0c2139SMatthew G Knepley ierr = DMLabelGetValue(label, support[e], &val);CHKERRQ(ierr); 10474c367dbcSMatthew G. Knepley if (val == 1) ++qf; 10484c367dbcSMatthew G. Knepley if ((val == 1) || (val == (shift + 1))) ++qn; 10494c367dbcSMatthew G. Knepley if ((val == 1) || (val == -(shift + 1))) ++qp; 1050cd0c2139SMatthew G Knepley } 10514c367dbcSMatthew G. Knepley /* Split old vertex: Edges into original vertex and new cohesive edge */ 10524c367dbcSMatthew G. Knepley ierr = DMPlexSetSupportSize(sdm, newp, qn+1);CHKERRQ(ierr); 10534c367dbcSMatthew G. Knepley /* Split new vertex: Edges into split vertex and new cohesive edge */ 10544c367dbcSMatthew G. Knepley ierr = DMPlexSetSupportSize(sdm, splitp, qp+1);CHKERRQ(ierr); 10554c367dbcSMatthew G. Knepley /* Add hybrid edge */ 10564c367dbcSMatthew G. Knepley ierr = DMPlexSetConeSize(sdm, hybedge, 2);CHKERRQ(ierr); 10574c367dbcSMatthew G. Knepley ierr = DMPlexSetSupportSize(sdm, hybedge, qf);CHKERRQ(ierr); 1058cd0c2139SMatthew G Knepley } else if (dep == dim-2) { 10594c367dbcSMatthew G. Knepley const PetscInt hybface = p + pMaxNew[dep+1] + numSplitPoints[dep+1]; 10604c367dbcSMatthew G. Knepley 1061cd0c2139SMatthew G Knepley ierr = DMPlexGetSupport(dm, oldp, &support);CHKERRQ(ierr); 10624c367dbcSMatthew G. Knepley for (e = 0, qn = 0, qp = 0, qf = 0; e < supportSize; ++e) { 1063cd0c2139SMatthew G Knepley PetscInt val; 1064cd0c2139SMatthew G Knepley 1065cd0c2139SMatthew G Knepley ierr = DMLabelGetValue(label, support[e], &val);CHKERRQ(ierr); 10664c367dbcSMatthew G. Knepley if (val == dim-1) ++qf; 10674c367dbcSMatthew G. Knepley if ((val == dim-1) || (val == (shift + dim-1))) ++qn; 10684c367dbcSMatthew G. Knepley if ((val == dim-1) || (val == -(shift + dim-1))) ++qp; 1069cd0c2139SMatthew G Knepley } 10704c367dbcSMatthew G. Knepley /* Split old edge: Faces into original edge and cohesive face (positive side?) */ 10714c367dbcSMatthew G. Knepley ierr = DMPlexSetSupportSize(sdm, newp, qn+1);CHKERRQ(ierr); 10724c367dbcSMatthew G. Knepley /* Split new edge: Faces into split edge and cohesive face (negative side?) */ 10734c367dbcSMatthew G. Knepley ierr = DMPlexSetSupportSize(sdm, splitp, qp+1);CHKERRQ(ierr); 10744c367dbcSMatthew G. Knepley /* Add hybrid face */ 10754c367dbcSMatthew G. Knepley ierr = DMPlexSetConeSize(sdm, hybface, 4);CHKERRQ(ierr); 10764c367dbcSMatthew G. Knepley ierr = DMPlexSetSupportSize(sdm, hybface, qf);CHKERRQ(ierr); 1077cd0c2139SMatthew G Knepley } 1078cd0c2139SMatthew G Knepley } 1079cd0c2139SMatthew G Knepley } 108018c5995bSMatthew G. Knepley for (dep = 0; dep <= depth; ++dep) { 108118c5995bSMatthew G. Knepley for (p = 0; p < numUnsplitPoints[dep]; ++p) { 108218c5995bSMatthew G. Knepley const PetscInt oldp = unsplitPoints[dep][p]; 10832582d50cSToby Isaac const PetscInt newp = DMPlexShiftPoint_Internal(oldp, depth, depthShift) /*oldp + depthOffset[dep]*/; 108418c5995bSMatthew G. Knepley const PetscInt *support; 1085da1dd7e4SMatthew G. Knepley PetscInt coneSize, supportSize, qf, e, s; 108618c5995bSMatthew G. Knepley 108718c5995bSMatthew G. Knepley ierr = DMPlexGetConeSize(dm, oldp, &coneSize);CHKERRQ(ierr); 108818c5995bSMatthew G. Knepley ierr = DMPlexGetSupportSize(dm, oldp, &supportSize);CHKERRQ(ierr); 108939254ff6SMatthew G. Knepley ierr = DMPlexGetSupport(dm, oldp, &support);CHKERRQ(ierr); 109018c5995bSMatthew G. Knepley if (dep == 0) { 109118c5995bSMatthew G. Knepley const PetscInt hybedge = p + pMaxNew[dep+1] + numSplitPoints[dep+1] + numSplitPoints[dep]; 109218c5995bSMatthew G. Knepley 109339254ff6SMatthew G. Knepley /* Unsplit vertex: Edges into original vertex, split edges, and new cohesive edge twice */ 109439254ff6SMatthew G. Knepley for (s = 0, qf = 0; s < supportSize; ++s, ++qf) { 109539254ff6SMatthew G. Knepley ierr = PetscFindInt(support[s], numSplitPoints[dep+1], splitPoints[dep+1], &e);CHKERRQ(ierr); 109639254ff6SMatthew G. Knepley if (e >= 0) ++qf; 109739254ff6SMatthew G. Knepley } 109839254ff6SMatthew G. Knepley ierr = DMPlexSetSupportSize(sdm, newp, qf+2);CHKERRQ(ierr); 109918c5995bSMatthew G. Knepley /* Add hybrid edge */ 110018c5995bSMatthew G. Knepley ierr = DMPlexSetConeSize(sdm, hybedge, 2);CHKERRQ(ierr); 1101e1757548SMatthew G. Knepley for (e = 0, qf = 0; e < supportSize; ++e) { 1102e1757548SMatthew G. Knepley PetscInt val; 1103e1757548SMatthew G. Knepley 1104e1757548SMatthew G. Knepley ierr = DMLabelGetValue(label, support[e], &val);CHKERRQ(ierr); 1105e1757548SMatthew G. Knepley /* Split and unsplit edges produce hybrid faces */ 1106da1dd7e4SMatthew G. Knepley if (val == 1) ++qf; 1107da1dd7e4SMatthew G. Knepley if (val == (shift2 + 1)) ++qf; 1108e1757548SMatthew G. Knepley } 1109e1757548SMatthew G. Knepley ierr = DMPlexSetSupportSize(sdm, hybedge, qf);CHKERRQ(ierr); 111018c5995bSMatthew G. Knepley } else if (dep == dim-2) { 111118c5995bSMatthew G. Knepley const PetscInt hybface = p + pMaxNew[dep+1] + numSplitPoints[dep+1] + numSplitPoints[dep]; 1112cd0c2139SMatthew G Knepley PetscInt val; 1113cd0c2139SMatthew G Knepley 1114da1dd7e4SMatthew G. Knepley for (e = 0, qf = 0; e < supportSize; ++e) { 1115cd0c2139SMatthew G Knepley ierr = DMLabelGetValue(label, support[e], &val);CHKERRQ(ierr); 1116da1dd7e4SMatthew G. Knepley if (val == dim-1) qf += 2; 1117da1dd7e4SMatthew G. Knepley else ++qf; 1118cd0c2139SMatthew G Knepley } 111918c5995bSMatthew G. Knepley /* Unsplit edge: Faces into original edge, split face, and cohesive face twice */ 1120da1dd7e4SMatthew G. Knepley ierr = DMPlexSetSupportSize(sdm, newp, qf+2);CHKERRQ(ierr); 112118c5995bSMatthew G. Knepley /* Add hybrid face */ 1122da1dd7e4SMatthew G. Knepley for (e = 0, qf = 0; e < supportSize; ++e) { 1123da1dd7e4SMatthew G. Knepley ierr = DMLabelGetValue(label, support[e], &val);CHKERRQ(ierr); 1124da1dd7e4SMatthew G. Knepley if (val == dim-1) ++qf; 1125da1dd7e4SMatthew G. Knepley } 112618c5995bSMatthew G. Knepley ierr = DMPlexSetConeSize(sdm, hybface, 4);CHKERRQ(ierr); 1127da1dd7e4SMatthew G. Knepley ierr = DMPlexSetSupportSize(sdm, hybface, qf);CHKERRQ(ierr); 1128cd0c2139SMatthew G Knepley } 1129cd0c2139SMatthew G Knepley } 1130cd0c2139SMatthew G Knepley } 1131cd0c2139SMatthew G Knepley /* Step 4: Setup split DM */ 1132cd0c2139SMatthew G Knepley ierr = DMSetUp(sdm);CHKERRQ(ierr); 1133cd0c2139SMatthew G Knepley ierr = DMPlexShiftPoints_Internal(dm, depthShift, sdm);CHKERRQ(ierr); 1134dcbb62e8SMatthew G. Knepley ierr = DMPlexGetMaxSizes(sdm, &maxConeSizeNew, &maxSupportSizeNew);CHKERRQ(ierr); 1135dcca6d9dSJed Brown ierr = PetscMalloc3(PetscMax(maxConeSize, maxConeSizeNew)*3,&coneNew,PetscMax(maxConeSize, maxConeSizeNew)*3,&coneONew,PetscMax(maxSupportSize, maxSupportSizeNew),&supportNew);CHKERRQ(ierr); 1136cd0c2139SMatthew G Knepley /* Step 6: Set cones and supports for new points */ 1137cd0c2139SMatthew G Knepley for (dep = 0; dep <= depth; ++dep) { 1138cd0c2139SMatthew G Knepley for (p = 0; p < numSplitPoints[dep]; ++p) { 1139cd0c2139SMatthew G Knepley const PetscInt oldp = splitPoints[dep][p]; 11402582d50cSToby Isaac const PetscInt newp = DMPlexShiftPoint_Internal(oldp, depth, depthShift) /*oldp + depthOffset[dep]*/; 11414c367dbcSMatthew G. Knepley const PetscInt splitp = p + pMaxNew[dep]; 1142cd0c2139SMatthew G Knepley const PetscInt *cone, *support, *ornt; 11434c367dbcSMatthew G. Knepley PetscInt coneSize, supportSize, q, qf, qn, qp, v, e, s; 1144cd0c2139SMatthew G Knepley 1145cd0c2139SMatthew G Knepley ierr = DMPlexGetConeSize(dm, oldp, &coneSize);CHKERRQ(ierr); 1146cd0c2139SMatthew G Knepley ierr = DMPlexGetCone(dm, oldp, &cone);CHKERRQ(ierr); 1147cd0c2139SMatthew G Knepley ierr = DMPlexGetConeOrientation(dm, oldp, &ornt);CHKERRQ(ierr); 1148cd0c2139SMatthew G Knepley ierr = DMPlexGetSupportSize(dm, oldp, &supportSize);CHKERRQ(ierr); 1149cd0c2139SMatthew G Knepley ierr = DMPlexGetSupport(dm, oldp, &support);CHKERRQ(ierr); 1150cd0c2139SMatthew G Knepley if (dep == depth-1) { 115196a07cd0SMatthew G. Knepley PetscBool hasUnsplit = PETSC_FALSE; 11524c367dbcSMatthew G. Knepley const PetscInt hybcell = p + pMaxNew[dep+1] + numSplitPoints[dep+1]; 1153cd0c2139SMatthew G Knepley const PetscInt *supportF; 1154cd0c2139SMatthew G Knepley 1155cd0c2139SMatthew G Knepley /* Split face: copy in old face to new face to start */ 1156cd0c2139SMatthew G Knepley ierr = DMPlexGetSupport(sdm, newp, &supportF);CHKERRQ(ierr); 1157cd0c2139SMatthew G Knepley ierr = DMPlexSetSupport(sdm, splitp, supportF);CHKERRQ(ierr); 1158cd0c2139SMatthew G Knepley /* Split old face: old vertices/edges in cone so no change */ 1159cd0c2139SMatthew G Knepley /* Split new face: new vertices/edges in cone */ 1160cd0c2139SMatthew G Knepley for (q = 0; q < coneSize; ++q) { 11614c367dbcSMatthew G. Knepley ierr = PetscFindInt(cone[q], numSplitPoints[dep-1], splitPoints[dep-1], &v);CHKERRQ(ierr); 116218c5995bSMatthew G. Knepley if (v < 0) { 116318c5995bSMatthew G. Knepley ierr = PetscFindInt(cone[q], numUnsplitPoints[dep-1], unsplitPoints[dep-1], &v);CHKERRQ(ierr); 116418c5995bSMatthew G. Knepley if (v < 0) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Could not locate point %d in split or unsplit points of depth %d", cone[q], dep-1); 11652582d50cSToby Isaac coneNew[2+q] = DMPlexShiftPoint_Internal(cone[q], depth, depthShift) /*cone[q] + depthOffset[dep-1]*/; 116696a07cd0SMatthew G. Knepley hasUnsplit = PETSC_TRUE; 116718c5995bSMatthew G. Knepley } else { 11684c367dbcSMatthew G. Knepley coneNew[2+q] = v + pMaxNew[dep-1]; 1169163235baSMatthew G. Knepley if (dep > 1) { 1170163235baSMatthew G. Knepley const PetscInt *econe; 1171163235baSMatthew G. Knepley PetscInt econeSize, r, vs, vu; 1172163235baSMatthew G. Knepley 1173163235baSMatthew G. Knepley ierr = DMPlexGetConeSize(dm, cone[q], &econeSize);CHKERRQ(ierr); 1174163235baSMatthew G. Knepley ierr = DMPlexGetCone(dm, cone[q], &econe);CHKERRQ(ierr); 1175163235baSMatthew G. Knepley for (r = 0; r < econeSize; ++r) { 1176163235baSMatthew G. Knepley ierr = PetscFindInt(econe[r], numSplitPoints[dep-2], splitPoints[dep-2], &vs);CHKERRQ(ierr); 1177163235baSMatthew G. Knepley ierr = PetscFindInt(econe[r], numUnsplitPoints[dep-2], unsplitPoints[dep-2], &vu);CHKERRQ(ierr); 1178163235baSMatthew G. Knepley if (vs >= 0) continue; 1179163235baSMatthew G. Knepley if (vu < 0) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Could not locate point %d in split or unsplit points of depth %d", econe[r], dep-2); 1180163235baSMatthew G. Knepley hasUnsplit = PETSC_TRUE; 1181163235baSMatthew G. Knepley } 1182163235baSMatthew G. Knepley } 1183cd0c2139SMatthew G Knepley } 1184cd0c2139SMatthew G Knepley } 1185cd0c2139SMatthew G Knepley ierr = DMPlexSetCone(sdm, splitp, &coneNew[2]);CHKERRQ(ierr); 1186cd0c2139SMatthew G Knepley ierr = DMPlexSetConeOrientation(sdm, splitp, ornt);CHKERRQ(ierr); 1187e537020bSMatthew G. Knepley /* Face support */ 1188cd0c2139SMatthew G Knepley for (s = 0; s < supportSize; ++s) { 1189cd0c2139SMatthew G Knepley PetscInt val; 1190cd0c2139SMatthew G Knepley 1191cd0c2139SMatthew G Knepley ierr = DMLabelGetValue(label, support[s], &val);CHKERRQ(ierr); 1192cd0c2139SMatthew G Knepley if (val < 0) { 1193cd0c2139SMatthew G Knepley /* Split old face: Replace negative side cell with cohesive cell */ 11944c367dbcSMatthew G. Knepley ierr = DMPlexInsertSupport(sdm, newp, s, hybcell);CHKERRQ(ierr); 1195cd0c2139SMatthew G Knepley } else { 1196cd0c2139SMatthew G Knepley /* Split new face: Replace positive side cell with cohesive cell */ 11974c367dbcSMatthew G. Knepley ierr = DMPlexInsertSupport(sdm, splitp, s, hybcell);CHKERRQ(ierr); 1198e537020bSMatthew G. Knepley /* Get orientation for cohesive face */ 1199e537020bSMatthew G. Knepley { 1200e537020bSMatthew G. Knepley const PetscInt *ncone, *nconeO; 1201e537020bSMatthew G. Knepley PetscInt nconeSize, nc; 1202e537020bSMatthew G. Knepley 1203e537020bSMatthew G. Knepley ierr = DMPlexGetConeSize(dm, support[s], &nconeSize);CHKERRQ(ierr); 1204e537020bSMatthew G. Knepley ierr = DMPlexGetCone(dm, support[s], &ncone);CHKERRQ(ierr); 1205e537020bSMatthew G. Knepley ierr = DMPlexGetConeOrientation(dm, support[s], &nconeO);CHKERRQ(ierr); 1206e537020bSMatthew G. Knepley for (nc = 0; nc < nconeSize; ++nc) { 1207e537020bSMatthew G. Knepley if (ncone[nc] == oldp) { 1208e537020bSMatthew G. Knepley coneONew[0] = nconeO[nc]; 1209e537020bSMatthew G. Knepley break; 1210cd0c2139SMatthew G Knepley } 1211cd0c2139SMatthew G Knepley } 1212e537020bSMatthew G. Knepley if (nc >= nconeSize) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Could not locate face %d in neighboring cell %d", oldp, support[s]); 1213e537020bSMatthew G. Knepley } 1214e537020bSMatthew G. Knepley } 1215e537020bSMatthew G. Knepley } 12164c367dbcSMatthew G. Knepley /* Cohesive cell: Old and new split face, then new cohesive faces */ 1217fd4b9f15SMatthew G. Knepley coneNew[0] = newp; /* Extracted negative side orientation above */ 12184c367dbcSMatthew G. Knepley coneNew[1] = splitp; 12194c367dbcSMatthew G. Knepley coneONew[1] = coneONew[0]; 1220e537020bSMatthew G. Knepley for (q = 0; q < coneSize; ++q) { 122118c5995bSMatthew G. Knepley ierr = PetscFindInt(cone[q], numSplitPoints[dep-1], splitPoints[dep-1], &v);CHKERRQ(ierr); 122218c5995bSMatthew G. Knepley if (v < 0) { 122318c5995bSMatthew G. Knepley ierr = PetscFindInt(cone[q], numUnsplitPoints[dep-1], unsplitPoints[dep-1], &v);CHKERRQ(ierr); 122418c5995bSMatthew G. Knepley coneNew[2+q] = v + pMaxNew[dep] + numSplitPoints[dep] + numSplitPoints[dep-1]; 122518c5995bSMatthew G. Knepley coneONew[2+q] = 0; 122618c5995bSMatthew G. Knepley } else { 122718c5995bSMatthew G. Knepley coneNew[2+q] = v + pMaxNew[dep] + numSplitPoints[dep]; 122818c5995bSMatthew G. Knepley } 1229e537020bSMatthew G. Knepley coneONew[2+q] = 0; 1230e537020bSMatthew G. Knepley } 12314c367dbcSMatthew G. Knepley ierr = DMPlexSetCone(sdm, hybcell, coneNew);CHKERRQ(ierr); 12324c367dbcSMatthew G. Knepley ierr = DMPlexSetConeOrientation(sdm, hybcell, coneONew);CHKERRQ(ierr); 123396a07cd0SMatthew G. Knepley /* Label the hybrid cells on the boundary of the split */ 123496a07cd0SMatthew G. Knepley if (hasUnsplit) {ierr = DMLabelSetValue(label, -hybcell, dim);CHKERRQ(ierr);} 1235cd0c2139SMatthew G Knepley } else if (dep == 0) { 12364c367dbcSMatthew G. Knepley const PetscInt hybedge = p + pMaxNew[dep+1] + numSplitPoints[dep+1]; 1237cd0c2139SMatthew G Knepley 1238cd0c2139SMatthew G Knepley /* Split old vertex: Edges in old split faces and new cohesive edge */ 12394c367dbcSMatthew G. Knepley for (e = 0, qn = 0; e < supportSize; ++e) { 1240cd0c2139SMatthew G Knepley PetscInt val; 1241cd0c2139SMatthew G Knepley 1242cd0c2139SMatthew G Knepley ierr = DMLabelGetValue(label, support[e], &val);CHKERRQ(ierr); 1243cd0c2139SMatthew G Knepley if ((val == 1) || (val == (shift + 1))) { 12442582d50cSToby Isaac supportNew[qn++] = DMPlexShiftPoint_Internal(support[e], depth, depthShift) /*support[e] + depthOffset[dep+1]*/; 1245cd0c2139SMatthew G Knepley } 1246cd0c2139SMatthew G Knepley } 12474c367dbcSMatthew G. Knepley supportNew[qn] = hybedge; 1248cd0c2139SMatthew G Knepley ierr = DMPlexSetSupport(sdm, newp, supportNew);CHKERRQ(ierr); 1249cd0c2139SMatthew G Knepley /* Split new vertex: Edges in new split faces and new cohesive edge */ 12504c367dbcSMatthew G. Knepley for (e = 0, qp = 0; e < supportSize; ++e) { 1251cd0c2139SMatthew G Knepley PetscInt val, edge; 1252cd0c2139SMatthew G Knepley 1253cd0c2139SMatthew G Knepley ierr = DMLabelGetValue(label, support[e], &val);CHKERRQ(ierr); 1254cd0c2139SMatthew G Knepley if (val == 1) { 12554c367dbcSMatthew G. Knepley ierr = PetscFindInt(support[e], numSplitPoints[dep+1], splitPoints[dep+1], &edge);CHKERRQ(ierr); 1256cd0c2139SMatthew G Knepley if (edge < 0) SETERRQ1(comm, PETSC_ERR_ARG_WRONG, "Edge %d is not a split edge", support[e]); 12574c367dbcSMatthew G. Knepley supportNew[qp++] = edge + pMaxNew[dep+1]; 1258cd0c2139SMatthew G Knepley } else if (val == -(shift + 1)) { 12592582d50cSToby Isaac supportNew[qp++] = DMPlexShiftPoint_Internal(support[e], depth, depthShift) /*support[e] + depthOffset[dep+1]*/; 1260cd0c2139SMatthew G Knepley } 1261cd0c2139SMatthew G Knepley } 12624c367dbcSMatthew G. Knepley supportNew[qp] = hybedge; 1263cd0c2139SMatthew G Knepley ierr = DMPlexSetSupport(sdm, splitp, supportNew);CHKERRQ(ierr); 12644c367dbcSMatthew G. Knepley /* Hybrid edge: Old and new split vertex */ 1265cd0c2139SMatthew G Knepley coneNew[0] = newp; 1266cd0c2139SMatthew G Knepley coneNew[1] = splitp; 12674c367dbcSMatthew G. Knepley ierr = DMPlexSetCone(sdm, hybedge, coneNew);CHKERRQ(ierr); 12684c367dbcSMatthew G. Knepley for (e = 0, qf = 0; e < supportSize; ++e) { 12694c367dbcSMatthew G. Knepley PetscInt val, edge; 12704c367dbcSMatthew G. Knepley 12714c367dbcSMatthew G. Knepley ierr = DMLabelGetValue(label, support[e], &val);CHKERRQ(ierr); 12724c367dbcSMatthew G. Knepley if (val == 1) { 12734c367dbcSMatthew G. Knepley ierr = PetscFindInt(support[e], numSplitPoints[dep+1], splitPoints[dep+1], &edge);CHKERRQ(ierr); 12744c367dbcSMatthew G. Knepley if (edge < 0) SETERRQ1(comm, PETSC_ERR_ARG_WRONG, "Edge %d is not a split edge", support[e]); 12754c367dbcSMatthew G. Knepley supportNew[qf++] = edge + pMaxNew[dep+2] + numSplitPoints[dep+2]; 12764c367dbcSMatthew G. Knepley } 12774c367dbcSMatthew G. Knepley } 12784c367dbcSMatthew G. Knepley ierr = DMPlexSetSupport(sdm, hybedge, supportNew);CHKERRQ(ierr); 1279cd0c2139SMatthew G Knepley } else if (dep == dim-2) { 12804c367dbcSMatthew G. Knepley const PetscInt hybface = p + pMaxNew[dep+1] + numSplitPoints[dep+1]; 12814c367dbcSMatthew G. Knepley 1282cd0c2139SMatthew G Knepley /* Split old edge: old vertices in cone so no change */ 1283cd0c2139SMatthew G Knepley /* Split new edge: new vertices in cone */ 1284cd0c2139SMatthew G Knepley for (q = 0; q < coneSize; ++q) { 12854c367dbcSMatthew G. Knepley ierr = PetscFindInt(cone[q], numSplitPoints[dep-1], splitPoints[dep-1], &v);CHKERRQ(ierr); 1286e1757548SMatthew G. Knepley if (v < 0) { 1287e1757548SMatthew G. Knepley ierr = PetscFindInt(cone[q], numUnsplitPoints[dep-1], unsplitPoints[dep-1], &v);CHKERRQ(ierr); 1288e1757548SMatthew G. Knepley if (v < 0) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Could not locate point %d in split or unsplit points of depth %d", cone[q], dep-1); 12892582d50cSToby Isaac coneNew[q] = DMPlexShiftPoint_Internal(cone[q], depth, depthShift) /*cone[q] + depthOffset[dep-1]*/; 1290e1757548SMatthew G. Knepley } else { 12914c367dbcSMatthew G. Knepley coneNew[q] = v + pMaxNew[dep-1]; 1292cd0c2139SMatthew G Knepley } 1293e1757548SMatthew G. Knepley } 1294cd0c2139SMatthew G Knepley ierr = DMPlexSetCone(sdm, splitp, coneNew);CHKERRQ(ierr); 1295cd0c2139SMatthew G Knepley /* Split old edge: Faces in positive side cells and old split faces */ 1296cd0c2139SMatthew G Knepley for (e = 0, q = 0; e < supportSize; ++e) { 1297cd0c2139SMatthew G Knepley PetscInt val; 1298cd0c2139SMatthew G Knepley 1299cd0c2139SMatthew G Knepley ierr = DMLabelGetValue(label, support[e], &val);CHKERRQ(ierr); 13004c367dbcSMatthew G. Knepley if (val == dim-1) { 13012582d50cSToby Isaac supportNew[q++] = DMPlexShiftPoint_Internal(support[e], depth, depthShift) /*support[e] + depthOffset[dep+1]*/; 13024c367dbcSMatthew G. Knepley } else if (val == (shift + dim-1)) { 13032582d50cSToby Isaac supportNew[q++] = DMPlexShiftPoint_Internal(support[e], depth, depthShift) /*support[e] + depthOffset[dep+1]*/; 1304cd0c2139SMatthew G Knepley } 1305cd0c2139SMatthew G Knepley } 1306b279cd2aSMatthew G. Knepley supportNew[q++] = p + pMaxNew[dep+1] + numSplitPoints[dep+1]; 1307cd0c2139SMatthew G Knepley ierr = DMPlexSetSupport(sdm, newp, supportNew);CHKERRQ(ierr); 1308cd0c2139SMatthew G Knepley /* Split new edge: Faces in negative side cells and new split faces */ 1309cd0c2139SMatthew G Knepley for (e = 0, q = 0; e < supportSize; ++e) { 1310cd0c2139SMatthew G Knepley PetscInt val, face; 1311cd0c2139SMatthew G Knepley 1312cd0c2139SMatthew G Knepley ierr = DMLabelGetValue(label, support[e], &val);CHKERRQ(ierr); 1313cd0c2139SMatthew G Knepley if (val == dim-1) { 13144c367dbcSMatthew G. Knepley ierr = PetscFindInt(support[e], numSplitPoints[dep+1], splitPoints[dep+1], &face);CHKERRQ(ierr); 1315cd0c2139SMatthew G Knepley if (face < 0) SETERRQ1(comm, PETSC_ERR_ARG_WRONG, "Face %d is not a split face", support[e]); 13164c367dbcSMatthew G. Knepley supportNew[q++] = face + pMaxNew[dep+1]; 1317cd0c2139SMatthew G Knepley } else if (val == -(shift + dim-1)) { 13182582d50cSToby Isaac supportNew[q++] = DMPlexShiftPoint_Internal(support[e], depth, depthShift) /*support[e] + depthOffset[dep+1]*/; 1319cd0c2139SMatthew G Knepley } 1320cd0c2139SMatthew G Knepley } 1321b279cd2aSMatthew G. Knepley supportNew[q++] = p + pMaxNew[dep+1] + numSplitPoints[dep+1]; 1322cd0c2139SMatthew G Knepley ierr = DMPlexSetSupport(sdm, splitp, supportNew);CHKERRQ(ierr); 13234c367dbcSMatthew G. Knepley /* Hybrid face */ 13244c367dbcSMatthew G. Knepley coneNew[0] = newp; 13254c367dbcSMatthew G. Knepley coneNew[1] = splitp; 13264c367dbcSMatthew G. Knepley for (v = 0; v < coneSize; ++v) { 13274c367dbcSMatthew G. Knepley PetscInt vertex; 13284c367dbcSMatthew G. Knepley ierr = PetscFindInt(cone[v], numSplitPoints[dep-1], splitPoints[dep-1], &vertex);CHKERRQ(ierr); 1329e1757548SMatthew G. Knepley if (vertex < 0) { 1330e1757548SMatthew G. Knepley ierr = PetscFindInt(cone[v], numUnsplitPoints[dep-1], unsplitPoints[dep-1], &vertex);CHKERRQ(ierr); 1331e1757548SMatthew G. Knepley if (vertex < 0) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Could not locate point %d in split or unsplit points of depth %d", cone[v], dep-1); 1332e1757548SMatthew G. Knepley coneNew[2+v] = vertex + pMaxNew[dep] + numSplitPoints[dep] + numSplitPoints[dep-1]; 1333e1757548SMatthew G. Knepley } else { 13344c367dbcSMatthew G. Knepley coneNew[2+v] = vertex + pMaxNew[dep] + numSplitPoints[dep]; 13354c367dbcSMatthew G. Knepley } 1336e1757548SMatthew G. Knepley } 13374c367dbcSMatthew G. Knepley ierr = DMPlexSetCone(sdm, hybface, coneNew);CHKERRQ(ierr); 13384c367dbcSMatthew G. Knepley for (e = 0, qf = 0; e < supportSize; ++e) { 13394c367dbcSMatthew G. Knepley PetscInt val, face; 13404c367dbcSMatthew G. Knepley 13414c367dbcSMatthew G. Knepley ierr = DMLabelGetValue(label, support[e], &val);CHKERRQ(ierr); 13424c367dbcSMatthew G. Knepley if (val == dim-1) { 13434c367dbcSMatthew G. Knepley ierr = PetscFindInt(support[e], numSplitPoints[dep+1], splitPoints[dep+1], &face);CHKERRQ(ierr); 13444c367dbcSMatthew G. Knepley if (face < 0) SETERRQ1(comm, PETSC_ERR_ARG_WRONG, "Face %d is not a split face", support[e]); 13454c367dbcSMatthew G. Knepley supportNew[qf++] = face + pMaxNew[dep+2] + numSplitPoints[dep+2]; 13464c367dbcSMatthew G. Knepley } 13474c367dbcSMatthew G. Knepley } 13484c367dbcSMatthew G. Knepley ierr = DMPlexSetSupport(sdm, hybface, supportNew);CHKERRQ(ierr); 1349cd0c2139SMatthew G Knepley } 1350cd0c2139SMatthew G Knepley } 1351cd0c2139SMatthew G Knepley } 135218c5995bSMatthew G. Knepley for (dep = 0; dep <= depth; ++dep) { 135318c5995bSMatthew G. Knepley for (p = 0; p < numUnsplitPoints[dep]; ++p) { 135418c5995bSMatthew G. Knepley const PetscInt oldp = unsplitPoints[dep][p]; 13552582d50cSToby Isaac const PetscInt newp = DMPlexShiftPoint_Internal(oldp, depth, depthShift) /*oldp + depthOffset[dep]*/; 135618c5995bSMatthew G. Knepley const PetscInt *cone, *support, *ornt; 1357e1757548SMatthew G. Knepley PetscInt coneSize, supportSize, supportSizeNew, q, qf, e, f, s; 135818c5995bSMatthew G. Knepley 135918c5995bSMatthew G. Knepley ierr = DMPlexGetConeSize(dm, oldp, &coneSize);CHKERRQ(ierr); 136018c5995bSMatthew G. Knepley ierr = DMPlexGetCone(dm, oldp, &cone);CHKERRQ(ierr); 136118c5995bSMatthew G. Knepley ierr = DMPlexGetConeOrientation(dm, oldp, &ornt);CHKERRQ(ierr); 136218c5995bSMatthew G. Knepley ierr = DMPlexGetSupportSize(dm, oldp, &supportSize);CHKERRQ(ierr); 136318c5995bSMatthew G. Knepley ierr = DMPlexGetSupport(dm, oldp, &support);CHKERRQ(ierr); 136418c5995bSMatthew G. Knepley if (dep == 0) { 136518c5995bSMatthew G. Knepley const PetscInt hybedge = p + pMaxNew[dep+1] + numSplitPoints[dep+1] + numSplitPoints[dep]; 136618c5995bSMatthew G. Knepley 136718c5995bSMatthew G. Knepley /* Unsplit vertex */ 136818c5995bSMatthew G. Knepley ierr = DMPlexGetSupportSize(sdm, newp, &supportSizeNew);CHKERRQ(ierr); 136918c5995bSMatthew G. Knepley for (s = 0, q = 0; s < supportSize; ++s) { 13702582d50cSToby Isaac supportNew[q++] = DMPlexShiftPoint_Internal(support[s], depth, depthShift) /*support[s] + depthOffset[dep+1]*/; 137118c5995bSMatthew G. Knepley ierr = PetscFindInt(support[s], numSplitPoints[dep+1], splitPoints[dep+1], &e);CHKERRQ(ierr); 137218c5995bSMatthew G. Knepley if (e >= 0) { 137318c5995bSMatthew G. Knepley supportNew[q++] = e + pMaxNew[dep+1]; 137418c5995bSMatthew G. Knepley } 137518c5995bSMatthew G. Knepley } 137618c5995bSMatthew G. Knepley supportNew[q++] = hybedge; 137718c5995bSMatthew G. Knepley supportNew[q++] = hybedge; 137818c5995bSMatthew G. Knepley if (q != supportSizeNew) SETERRQ3(comm, PETSC_ERR_ARG_WRONG, "Support size %d != %d for vertex %d", q, supportSizeNew, newp); 137918c5995bSMatthew G. Knepley ierr = DMPlexSetSupport(sdm, newp, supportNew);CHKERRQ(ierr); 138018c5995bSMatthew G. Knepley /* Hybrid edge */ 138118c5995bSMatthew G. Knepley coneNew[0] = newp; 138218c5995bSMatthew G. Knepley coneNew[1] = newp; 138318c5995bSMatthew G. Knepley ierr = DMPlexSetCone(sdm, hybedge, coneNew);CHKERRQ(ierr); 138418c5995bSMatthew G. Knepley for (e = 0, qf = 0; e < supportSize; ++e) { 138518c5995bSMatthew G. Knepley PetscInt val, edge; 138618c5995bSMatthew G. Knepley 138718c5995bSMatthew G. Knepley ierr = DMLabelGetValue(label, support[e], &val);CHKERRQ(ierr); 138818c5995bSMatthew G. Knepley if (val == 1) { 138918c5995bSMatthew G. Knepley ierr = PetscFindInt(support[e], numSplitPoints[dep+1], splitPoints[dep+1], &edge);CHKERRQ(ierr); 139018c5995bSMatthew G. Knepley if (edge < 0) SETERRQ1(comm, PETSC_ERR_ARG_WRONG, "Edge %d is not a split edge", support[e]); 139118c5995bSMatthew G. Knepley supportNew[qf++] = edge + pMaxNew[dep+2] + numSplitPoints[dep+2]; 1392e1757548SMatthew G. Knepley } else if (val == (shift2 + 1)) { 1393e1757548SMatthew G. Knepley ierr = PetscFindInt(support[e], numUnsplitPoints[dep+1], unsplitPoints[dep+1], &edge);CHKERRQ(ierr); 1394e1757548SMatthew G. Knepley if (edge < 0) SETERRQ1(comm, PETSC_ERR_ARG_WRONG, "Edge %d is not a unsplit edge", support[e]); 1395e1757548SMatthew G. Knepley supportNew[qf++] = edge + pMaxNew[dep+2] + numSplitPoints[dep+2] + numSplitPoints[dep+1]; 139618c5995bSMatthew G. Knepley } 139718c5995bSMatthew G. Knepley } 139818c5995bSMatthew G. Knepley ierr = DMPlexSetSupport(sdm, hybedge, supportNew);CHKERRQ(ierr); 1399e1757548SMatthew G. Knepley } else if (dep == dim-2) { 1400e1757548SMatthew G. Knepley const PetscInt hybface = p + pMaxNew[dep+1] + numSplitPoints[dep+1] + numSplitPoints[dep]; 1401e1757548SMatthew G. Knepley 1402da1dd7e4SMatthew G. Knepley /* Unsplit edge: Faces into original edge, split face, and hybrid face twice */ 1403e1757548SMatthew G. Knepley for (f = 0, qf = 0; f < supportSize; ++f) { 1404e1757548SMatthew G. Knepley PetscInt val, face; 1405e1757548SMatthew G. Knepley 1406e1757548SMatthew G. Knepley ierr = DMLabelGetValue(label, support[f], &val);CHKERRQ(ierr); 1407e1757548SMatthew G. Knepley if (val == dim-1) { 1408e1757548SMatthew G. Knepley ierr = PetscFindInt(support[f], numSplitPoints[dep+1], splitPoints[dep+1], &face);CHKERRQ(ierr); 1409e1757548SMatthew G. Knepley if (face < 0) SETERRQ1(comm, PETSC_ERR_ARG_WRONG, "Face %d is not a split face", support[f]); 14102582d50cSToby Isaac supportNew[qf++] = DMPlexShiftPoint_Internal(support[f], depth, depthShift) /*support[f] + depthOffset[dep+1]*/; 1411e1757548SMatthew G. Knepley supportNew[qf++] = face + pMaxNew[dep+1]; 1412e1757548SMatthew G. Knepley } else { 14132582d50cSToby Isaac supportNew[qf++] = DMPlexShiftPoint_Internal(support[f], depth, depthShift) /*support[f] + depthOffset[dep+1]*/; 1414e1757548SMatthew G. Knepley } 1415e1757548SMatthew G. Knepley } 1416e1757548SMatthew G. Knepley supportNew[qf++] = hybface; 1417e1757548SMatthew G. Knepley supportNew[qf++] = hybface; 1418da1dd7e4SMatthew G. Knepley ierr = DMPlexGetSupportSize(sdm, newp, &supportSizeNew);CHKERRQ(ierr); 1419da1dd7e4SMatthew G. Knepley if (qf != supportSizeNew) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Support size for unsplit edge %d is %d != %d\n", newp, qf, supportSizeNew); 1420e1757548SMatthew G. Knepley ierr = DMPlexSetSupport(sdm, newp, supportNew);CHKERRQ(ierr); 1421e1757548SMatthew G. Knepley /* Add hybrid face */ 1422e1757548SMatthew G. Knepley coneNew[0] = newp; 1423212cc919SMatthew G. Knepley coneNew[1] = newp; 1424e1757548SMatthew G. Knepley ierr = PetscFindInt(cone[0], numUnsplitPoints[dep-1], unsplitPoints[dep-1], &v);CHKERRQ(ierr); 1425e1757548SMatthew G. Knepley if (v < 0) SETERRQ1(comm, PETSC_ERR_ARG_WRONG, "Vertex %d is not an unsplit vertex", cone[0]); 1426212cc919SMatthew G. Knepley coneNew[2] = v + pMaxNew[dep] + numSplitPoints[dep] + numSplitPoints[dep-1]; 1427e1757548SMatthew G. Knepley ierr = PetscFindInt(cone[1], numUnsplitPoints[dep-1], unsplitPoints[dep-1], &v);CHKERRQ(ierr); 1428e1757548SMatthew G. Knepley if (v < 0) SETERRQ1(comm, PETSC_ERR_ARG_WRONG, "Vertex %d is not an unsplit vertex", cone[1]); 1429e1757548SMatthew G. Knepley coneNew[3] = v + pMaxNew[dep] + numSplitPoints[dep] + numSplitPoints[dep-1]; 1430e1757548SMatthew G. Knepley ierr = DMPlexSetCone(sdm, hybface, coneNew);CHKERRQ(ierr); 1431da1dd7e4SMatthew G. Knepley for (f = 0, qf = 0; f < supportSize; ++f) { 1432da1dd7e4SMatthew G. Knepley PetscInt val, face; 1433da1dd7e4SMatthew G. Knepley 1434da1dd7e4SMatthew G. Knepley ierr = DMLabelGetValue(label, support[f], &val);CHKERRQ(ierr); 1435da1dd7e4SMatthew G. Knepley if (val == dim-1) { 1436da1dd7e4SMatthew G. Knepley ierr = PetscFindInt(support[f], numSplitPoints[dep+1], splitPoints[dep+1], &face);CHKERRQ(ierr); 1437da1dd7e4SMatthew G. Knepley supportNew[qf++] = face + pMaxNew[dep+2] + numSplitPoints[dep+2]; 1438da1dd7e4SMatthew G. Knepley } 1439da1dd7e4SMatthew G. Knepley } 1440da1dd7e4SMatthew G. Knepley ierr = DMPlexGetSupportSize(sdm, hybface, &supportSizeNew);CHKERRQ(ierr); 1441da1dd7e4SMatthew G. Knepley if (qf != supportSizeNew) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Support size for hybrid face %d is %d != %d\n", hybface, qf, supportSizeNew); 1442e1757548SMatthew G. Knepley ierr = DMPlexSetSupport(sdm, hybface, supportNew);CHKERRQ(ierr); 1443cd0c2139SMatthew G Knepley } 1444cd0c2139SMatthew G Knepley } 1445cd0c2139SMatthew G Knepley } 1446cd0c2139SMatthew G Knepley /* Step 6b: Replace split points in negative side cones */ 1447cd0c2139SMatthew G Knepley for (sp = 0; sp < numSP; ++sp) { 1448cd0c2139SMatthew G Knepley PetscInt dep = values[sp]; 1449cd0c2139SMatthew G Knepley IS pIS; 1450cd0c2139SMatthew G Knepley PetscInt numPoints; 1451cd0c2139SMatthew G Knepley const PetscInt *points; 1452cd0c2139SMatthew G Knepley 1453cd0c2139SMatthew G Knepley if (dep >= 0) continue; 1454cd0c2139SMatthew G Knepley ierr = DMLabelGetStratumIS(label, dep, &pIS);CHKERRQ(ierr); 1455cd0c2139SMatthew G Knepley if (!pIS) continue; 1456cd0c2139SMatthew G Knepley dep = -dep - shift; 1457cd0c2139SMatthew G Knepley ierr = ISGetLocalSize(pIS, &numPoints);CHKERRQ(ierr); 1458cd0c2139SMatthew G Knepley ierr = ISGetIndices(pIS, &points);CHKERRQ(ierr); 1459cd0c2139SMatthew G Knepley for (p = 0; p < numPoints; ++p) { 1460cd0c2139SMatthew G Knepley const PetscInt oldp = points[p]; 14612582d50cSToby Isaac const PetscInt newp = DMPlexShiftPoint_Internal(oldp, depth, depthShift) /*depthOffset[dep] + oldp*/; 1462cd0c2139SMatthew G Knepley const PetscInt *cone; 1463cd0c2139SMatthew G Knepley PetscInt coneSize, c; 146450cf782dSMatthew G. Knepley /* PetscBool replaced = PETSC_FALSE; */ 1465cd0c2139SMatthew G Knepley 1466cd0c2139SMatthew G Knepley /* Negative edge: replace split vertex */ 1467cd0c2139SMatthew G Knepley /* Negative cell: replace split face */ 1468cd0c2139SMatthew G Knepley ierr = DMPlexGetConeSize(sdm, newp, &coneSize);CHKERRQ(ierr); 1469cd0c2139SMatthew G Knepley ierr = DMPlexGetCone(sdm, newp, &cone);CHKERRQ(ierr); 1470cd0c2139SMatthew G Knepley for (c = 0; c < coneSize; ++c) { 1471e38fbfedSToby Isaac const PetscInt coldp = DMPlexShiftPointInverse_Internal(cone[c],depth,depthShift); 1472cd0c2139SMatthew G Knepley PetscInt csplitp, cp, val; 1473cd0c2139SMatthew G Knepley 1474cd0c2139SMatthew G Knepley ierr = DMLabelGetValue(label, coldp, &val);CHKERRQ(ierr); 1475cd0c2139SMatthew G Knepley if (val == dep-1) { 1476cd0c2139SMatthew G Knepley ierr = PetscFindInt(coldp, numSplitPoints[dep-1], splitPoints[dep-1], &cp);CHKERRQ(ierr); 1477cd0c2139SMatthew G Knepley if (cp < 0) SETERRQ2(comm, PETSC_ERR_ARG_WRONG, "Point %d is not a split point of dimension %d", oldp, dep-1); 1478cd0c2139SMatthew G Knepley csplitp = pMaxNew[dep-1] + cp; 1479cd0c2139SMatthew G Knepley ierr = DMPlexInsertCone(sdm, newp, c, csplitp);CHKERRQ(ierr); 148050cf782dSMatthew G. Knepley /* replaced = PETSC_TRUE; */ 1481cd0c2139SMatthew G Knepley } 1482cd0c2139SMatthew G Knepley } 14834a189a86SMatthew G. Knepley /* Cells with only a vertex or edge on the submesh have no replacement */ 14844a189a86SMatthew G. Knepley /* if (!replaced) SETERRQ1(comm, PETSC_ERR_ARG_WRONG, "The cone of point %d does not contain split points", oldp); */ 1485cd0c2139SMatthew G Knepley } 1486cd0c2139SMatthew G Knepley ierr = ISRestoreIndices(pIS, &points);CHKERRQ(ierr); 1487cd0c2139SMatthew G Knepley ierr = ISDestroy(&pIS);CHKERRQ(ierr); 1488cd0c2139SMatthew G Knepley } 1489fa8e8ae5SToby Isaac /* Step 7: Coordinates */ 1490cd0c2139SMatthew G Knepley ierr = DMPlexShiftCoordinates_Internal(dm, depthShift, sdm);CHKERRQ(ierr); 149169d8a9ceSMatthew G. Knepley ierr = DMGetCoordinateSection(sdm, &coordSection);CHKERRQ(ierr); 1492cd0c2139SMatthew G Knepley ierr = DMGetCoordinatesLocal(sdm, &coordinates);CHKERRQ(ierr); 1493cd0c2139SMatthew G Knepley ierr = VecGetArray(coordinates, &coords);CHKERRQ(ierr); 1494cd0c2139SMatthew G Knepley for (v = 0; v < (numSplitPoints ? numSplitPoints[0] : 0); ++v) { 14952582d50cSToby Isaac const PetscInt newp = DMPlexShiftPoint_Internal(splitPoints[0][v], depth, depthShift) /*depthOffset[0] + splitPoints[0][v]*/; 1496cd0c2139SMatthew G Knepley const PetscInt splitp = pMaxNew[0] + v; 1497cd0c2139SMatthew G Knepley PetscInt dof, off, soff, d; 1498cd0c2139SMatthew G Knepley 1499cd0c2139SMatthew G Knepley ierr = PetscSectionGetDof(coordSection, newp, &dof);CHKERRQ(ierr); 1500cd0c2139SMatthew G Knepley ierr = PetscSectionGetOffset(coordSection, newp, &off);CHKERRQ(ierr); 1501cd0c2139SMatthew G Knepley ierr = PetscSectionGetOffset(coordSection, splitp, &soff);CHKERRQ(ierr); 1502cd0c2139SMatthew G Knepley for (d = 0; d < dof; ++d) coords[soff+d] = coords[off+d]; 1503cd0c2139SMatthew G Knepley } 1504cd0c2139SMatthew G Knepley ierr = VecRestoreArray(coordinates, &coords);CHKERRQ(ierr); 1505fa8e8ae5SToby Isaac /* Step 8: SF, if I can figure this out we can split the mesh in parallel */ 1506cd0c2139SMatthew G Knepley ierr = DMPlexShiftSF_Internal(dm, depthShift, sdm);CHKERRQ(ierr); 1507fa8e8ae5SToby Isaac /* Step 9: Labels */ 1508cd0c2139SMatthew G Knepley ierr = DMPlexShiftLabels_Internal(dm, depthShift, sdm);CHKERRQ(ierr); 1509c58f1c22SToby Isaac ierr = DMGetNumLabels(sdm, &numLabels);CHKERRQ(ierr); 1510cd0c2139SMatthew G Knepley for (dep = 0; dep <= depth; ++dep) { 1511cd0c2139SMatthew G Knepley for (p = 0; p < numSplitPoints[dep]; ++p) { 15122582d50cSToby Isaac const PetscInt newp = DMPlexShiftPoint_Internal(splitPoints[dep][p], depth, depthShift) /*depthOffset[dep] + splitPoints[dep][p]*/; 1513cd0c2139SMatthew G Knepley const PetscInt splitp = pMaxNew[dep] + p; 1514cd0c2139SMatthew G Knepley PetscInt l; 1515cd0c2139SMatthew G Knepley 15167db7e0a7SMatthew G. Knepley if (splitLabel) { 15177db7e0a7SMatthew G. Knepley const PetscInt val = 100 + dep; 15187db7e0a7SMatthew G. Knepley 15197db7e0a7SMatthew G. Knepley ierr = DMLabelSetValue(splitLabel, newp, val);CHKERRQ(ierr); 15207db7e0a7SMatthew G. Knepley ierr = DMLabelSetValue(splitLabel, splitp, -val);CHKERRQ(ierr); 15217db7e0a7SMatthew G. Knepley } 1522cd0c2139SMatthew G Knepley for (l = 0; l < numLabels; ++l) { 1523cd0c2139SMatthew G Knepley DMLabel mlabel; 1524cd0c2139SMatthew G Knepley const char *lname; 1525cd0c2139SMatthew G Knepley PetscInt val; 15269a356370SMatthew G. Knepley PetscBool isDepth; 1527cd0c2139SMatthew G Knepley 1528c58f1c22SToby Isaac ierr = DMGetLabelName(sdm, l, &lname);CHKERRQ(ierr); 15299a356370SMatthew G. Knepley ierr = PetscStrcmp(lname, "depth", &isDepth);CHKERRQ(ierr); 15309a356370SMatthew G. Knepley if (isDepth) continue; 1531c58f1c22SToby Isaac ierr = DMGetLabel(sdm, lname, &mlabel);CHKERRQ(ierr); 1532cd0c2139SMatthew G Knepley ierr = DMLabelGetValue(mlabel, newp, &val);CHKERRQ(ierr); 1533cd0c2139SMatthew G Knepley if (val >= 0) { 1534cd0c2139SMatthew G Knepley ierr = DMLabelSetValue(mlabel, splitp, val);CHKERRQ(ierr); 1535cd0c2139SMatthew G Knepley } 1536cd0c2139SMatthew G Knepley } 1537cd0c2139SMatthew G Knepley } 1538cd0c2139SMatthew G Knepley } 1539cd0c2139SMatthew G Knepley for (sp = 0; sp < numSP; ++sp) { 1540cd0c2139SMatthew G Knepley const PetscInt dep = values[sp]; 1541cd0c2139SMatthew G Knepley 1542cd0c2139SMatthew G Knepley if ((dep < 0) || (dep > depth)) continue; 154318c5995bSMatthew G. Knepley if (splitIS[dep]) {ierr = ISRestoreIndices(splitIS[dep], &splitPoints[dep]);CHKERRQ(ierr);} 154418c5995bSMatthew G. Knepley ierr = ISDestroy(&splitIS[dep]);CHKERRQ(ierr); 154518c5995bSMatthew G. Knepley if (unsplitIS[dep]) {ierr = ISRestoreIndices(unsplitIS[dep], &unsplitPoints[dep]);CHKERRQ(ierr);} 154618c5995bSMatthew G. Knepley ierr = ISDestroy(&unsplitIS[dep]);CHKERRQ(ierr); 1547cd0c2139SMatthew G Knepley } 1548cd0c2139SMatthew G Knepley if (label) { 1549cd0c2139SMatthew G Knepley ierr = ISRestoreIndices(valueIS, &values);CHKERRQ(ierr); 1550cd0c2139SMatthew G Knepley ierr = ISDestroy(&valueIS);CHKERRQ(ierr); 1551cd0c2139SMatthew G Knepley } 15520d4d4d06SMatthew G. Knepley for (d = 0; d <= depth; ++d) { 15530d4d4d06SMatthew G. Knepley ierr = DMPlexGetDepthStratum(sdm, d, NULL, &pEnd);CHKERRQ(ierr); 155436dbac82SMatthew G. Knepley pMaxNew[d] = pEnd - numHybridPoints[d] - numHybridPointsOld[d]; 15550d4d4d06SMatthew G. Knepley } 15560e49e2e2SMatthew G. Knepley ierr = DMPlexSetHybridBounds(sdm, depth >= 0 ? pMaxNew[depth] : PETSC_DETERMINE, depth>1 ? pMaxNew[depth-1] : PETSC_DETERMINE, depth>2 ? pMaxNew[1] : PETSC_DETERMINE, depth >= 0 ? pMaxNew[0] : PETSC_DETERMINE);CHKERRQ(ierr); 1557dcbb62e8SMatthew G. Knepley ierr = PetscFree3(coneNew, coneONew, supportNew);CHKERRQ(ierr); 15582582d50cSToby Isaac ierr = PetscFree5(depthMax, depthEnd, depthShift, pMaxNew, numHybridPointsOld);CHKERRQ(ierr); 155918c5995bSMatthew G. Knepley ierr = PetscFree7(splitIS, unsplitIS, numSplitPoints, numUnsplitPoints, numHybridPoints, splitPoints, unsplitPoints);CHKERRQ(ierr); 1560cd0c2139SMatthew G Knepley PetscFunctionReturn(0); 1561cd0c2139SMatthew G Knepley } 1562cd0c2139SMatthew G Knepley 1563cd0c2139SMatthew G Knepley /*@C 1564cd0c2139SMatthew G Knepley DMPlexConstructCohesiveCells - Construct cohesive cells which split the face along an internal interface 1565cd0c2139SMatthew G Knepley 1566cd0c2139SMatthew G Knepley Collective on dm 1567cd0c2139SMatthew G Knepley 1568cd0c2139SMatthew G Knepley Input Parameters: 1569cd0c2139SMatthew G Knepley + dm - The original DM 157053156dfcSMatthew G. Knepley - label - The label specifying the boundary faces (this could be auto-generated) 1571cd0c2139SMatthew G Knepley 1572cd0c2139SMatthew G Knepley Output Parameters: 15737db7e0a7SMatthew G. Knepley + splitLabel - The label containing the split points, or NULL if no output is desired 1574cd0c2139SMatthew G Knepley - dmSplit - The new DM 1575cd0c2139SMatthew G Knepley 1576cd0c2139SMatthew G Knepley Level: developer 1577cd0c2139SMatthew G Knepley 15782be2b188SMatthew G Knepley .seealso: DMCreate(), DMPlexLabelCohesiveComplete() 1579cd0c2139SMatthew G Knepley @*/ 15807db7e0a7SMatthew G. Knepley PetscErrorCode DMPlexConstructCohesiveCells(DM dm, DMLabel label, DMLabel splitLabel, DM *dmSplit) 1581cd0c2139SMatthew G Knepley { 1582cd0c2139SMatthew G Knepley DM sdm; 1583cd0c2139SMatthew G Knepley PetscInt dim; 1584cd0c2139SMatthew G Knepley PetscErrorCode ierr; 1585cd0c2139SMatthew G Knepley 1586cd0c2139SMatthew G Knepley PetscFunctionBegin; 1587cd0c2139SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 158853156dfcSMatthew G. Knepley PetscValidPointer(dmSplit, 3); 1589cd0c2139SMatthew G Knepley ierr = DMCreate(PetscObjectComm((PetscObject)dm), &sdm);CHKERRQ(ierr); 1590cd0c2139SMatthew G Knepley ierr = DMSetType(sdm, DMPLEX);CHKERRQ(ierr); 1591c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 1592c73cfb54SMatthew G. Knepley ierr = DMSetDimension(sdm, dim);CHKERRQ(ierr); 1593cd0c2139SMatthew G Knepley switch (dim) { 1594cd0c2139SMatthew G Knepley case 2: 1595cd0c2139SMatthew G Knepley case 3: 15967db7e0a7SMatthew G. Knepley ierr = DMPlexConstructCohesiveCells_Internal(dm, label, splitLabel, sdm);CHKERRQ(ierr); 1597cd0c2139SMatthew G Knepley break; 1598cd0c2139SMatthew G Knepley default: 1599cd0c2139SMatthew G Knepley SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Cannot construct cohesive cells for dimension %d", dim); 1600cd0c2139SMatthew G Knepley } 1601cd0c2139SMatthew G Knepley *dmSplit = sdm; 1602cd0c2139SMatthew G Knepley PetscFunctionReturn(0); 1603cd0c2139SMatthew G Knepley } 1604cd0c2139SMatthew G Knepley 16050f66a230SMatthew G. Knepley /* Returns the side of the surface for a given cell with a face on the surface */ 16060f66a230SMatthew G. Knepley static PetscErrorCode GetSurfaceSide_Static(DM dm, DM subdm, PetscInt numSubpoints, const PetscInt *subpoints, PetscInt cell, PetscInt face, PetscBool *pos) 16070f66a230SMatthew G. Knepley { 16080f66a230SMatthew G. Knepley const PetscInt *cone, *ornt; 16090f66a230SMatthew G. Knepley PetscInt dim, coneSize, c; 16100f66a230SMatthew G. Knepley PetscErrorCode ierr; 16110f66a230SMatthew G. Knepley 16120f66a230SMatthew G. Knepley PetscFunctionBegin; 16130f66a230SMatthew G. Knepley *pos = PETSC_TRUE; 1614c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 16150f66a230SMatthew G. Knepley ierr = DMPlexGetConeSize(dm, cell, &coneSize);CHKERRQ(ierr); 16160f66a230SMatthew G. Knepley ierr = DMPlexGetCone(dm, cell, &cone);CHKERRQ(ierr); 16170f66a230SMatthew G. Knepley ierr = DMPlexGetConeOrientation(dm, cell, &ornt);CHKERRQ(ierr); 16180f66a230SMatthew G. Knepley for (c = 0; c < coneSize; ++c) { 16190f66a230SMatthew G. Knepley if (cone[c] == face) { 16200f66a230SMatthew G. Knepley PetscInt o = ornt[c]; 16210f66a230SMatthew G. Knepley 16220f66a230SMatthew G. Knepley if (subdm) { 16230f66a230SMatthew G. Knepley const PetscInt *subcone, *subornt; 16240f66a230SMatthew G. Knepley PetscInt subpoint, subface, subconeSize, sc; 16250f66a230SMatthew G. Knepley 16260f66a230SMatthew G. Knepley ierr = PetscFindInt(cell, numSubpoints, subpoints, &subpoint);CHKERRQ(ierr); 16270f66a230SMatthew G. Knepley ierr = PetscFindInt(face, numSubpoints, subpoints, &subface);CHKERRQ(ierr); 16280f66a230SMatthew G. Knepley ierr = DMPlexGetConeSize(subdm, subpoint, &subconeSize);CHKERRQ(ierr); 16290f66a230SMatthew G. Knepley ierr = DMPlexGetCone(subdm, subpoint, &subcone);CHKERRQ(ierr); 16300f66a230SMatthew G. Knepley ierr = DMPlexGetConeOrientation(subdm, subpoint, &subornt);CHKERRQ(ierr); 16310f66a230SMatthew G. Knepley for (sc = 0; sc < subconeSize; ++sc) { 16320f66a230SMatthew G. Knepley if (subcone[sc] == subface) { 16330f66a230SMatthew G. Knepley o = subornt[0]; 16340f66a230SMatthew G. Knepley break; 16350f66a230SMatthew G. Knepley } 16360f66a230SMatthew G. Knepley } 16370f66a230SMatthew G. Knepley if (sc >= subconeSize) SETERRQ4(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Could not find subpoint %d (%d) in cone for subpoint %d (%d)", subface, face, subpoint, cell); 16380f66a230SMatthew G. Knepley } 16390f66a230SMatthew G. Knepley if (o >= 0) *pos = PETSC_TRUE; 16400f66a230SMatthew G. Knepley else *pos = PETSC_FALSE; 16410f66a230SMatthew G. Knepley break; 16420f66a230SMatthew G. Knepley } 16430f66a230SMatthew G. Knepley } 16440f66a230SMatthew G. Knepley if (c == coneSize) SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "Cell %d in split face %d support does not have it in the cone", cell, face); 16450f66a230SMatthew G. Knepley PetscFunctionReturn(0); 16460f66a230SMatthew G. Knepley } 16470f66a230SMatthew G. Knepley 1648cd0c2139SMatthew G Knepley /*@ 16490f66a230SMatthew G. Knepley DMPlexLabelCohesiveComplete - Starting with a label marking points on an internal surface, we add all other mesh pieces 1650cd0c2139SMatthew G Knepley to complete the surface 1651cd0c2139SMatthew G Knepley 1652cd0c2139SMatthew G Knepley Input Parameters: 1653cd0c2139SMatthew G Knepley + dm - The DM 16540f66a230SMatthew G. Knepley . label - A DMLabel marking the surface 16550f66a230SMatthew G. Knepley . blabel - A DMLabel marking the vertices on the boundary which will not be duplicated, or NULL to find them automatically 1656bb55d314SMatthew G. Knepley . flip - Flag to flip the submesh normal and replace points on the other side 165747946fd8SMatthew G. Knepley - subdm - The subDM associated with the label, or NULL 1658cd0c2139SMatthew G Knepley 1659cd0c2139SMatthew G Knepley Output Parameter: 1660cd0c2139SMatthew G Knepley . label - A DMLabel marking all surface points 1661cd0c2139SMatthew G Knepley 16620f66a230SMatthew G. Knepley Note: The vertices in blabel are called "unsplit" in the terminology from hybrid cell creation. 16630f66a230SMatthew G. Knepley 1664cd0c2139SMatthew G Knepley Level: developer 1665cd0c2139SMatthew G Knepley 16662be2b188SMatthew G Knepley .seealso: DMPlexConstructCohesiveCells(), DMPlexLabelComplete() 1667cd0c2139SMatthew G Knepley @*/ 16680f66a230SMatthew G. Knepley PetscErrorCode DMPlexLabelCohesiveComplete(DM dm, DMLabel label, DMLabel blabel, PetscBool flip, DM subdm) 1669cd0c2139SMatthew G Knepley { 1670d90583fdSMatthew G. Knepley DMLabel depthLabel; 16718630cb1aSMatthew G. Knepley IS dimIS, subpointIS = NULL, facePosIS, faceNegIS, crossEdgeIS = NULL; 167247946fd8SMatthew G. Knepley const PetscInt *points, *subpoints; 1673bb55d314SMatthew G. Knepley const PetscInt rev = flip ? -1 : 1; 1674370472baSMatthew G. Knepley PetscInt *pMax; 1675370472baSMatthew G. Knepley PetscInt shift = 100, shift2 = 200, dim, depth, pSize, dep, cStart, cEnd, cMax, fStart, fEnd, vStart, vEnd, numPoints, numSubpoints, p, val; 1676cd0c2139SMatthew G Knepley PetscErrorCode ierr; 1677cd0c2139SMatthew G Knepley 1678cd0c2139SMatthew G Knepley PetscFunctionBegin; 1679370472baSMatthew G. Knepley ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 1680370472baSMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 1681370472baSMatthew G. Knepley pSize = PetscMax(depth, dim) + 1; 1682370472baSMatthew G. Knepley ierr = PetscMalloc1(pSize,&pMax);CHKERRQ(ierr); 1683370472baSMatthew G. Knepley ierr = DMPlexGetHybridBounds(dm, depth >= 0 ? &pMax[depth] : NULL, depth>1 ? &pMax[depth-1] : NULL, depth>2 ? &pMax[1] : NULL, &pMax[0]);CHKERRQ(ierr); 1684d90583fdSMatthew G. Knepley ierr = DMPlexGetDepthLabel(dm, &depthLabel);CHKERRQ(ierr); 1685c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 168647946fd8SMatthew G. Knepley if (subdm) { 168747946fd8SMatthew G. Knepley ierr = DMPlexCreateSubpointIS(subdm, &subpointIS);CHKERRQ(ierr); 168847946fd8SMatthew G. Knepley if (subpointIS) { 168947946fd8SMatthew G. Knepley ierr = ISGetLocalSize(subpointIS, &numSubpoints);CHKERRQ(ierr); 169047946fd8SMatthew G. Knepley ierr = ISGetIndices(subpointIS, &subpoints);CHKERRQ(ierr); 169147946fd8SMatthew G. Knepley } 169247946fd8SMatthew G. Knepley } 1693d7c8f101SMatthew G. Knepley /* Mark cell on the fault, and its faces which touch the fault: cell orientation for face gives the side of the fault */ 1694cd0c2139SMatthew G Knepley ierr = DMLabelGetStratumIS(label, dim-1, &dimIS);CHKERRQ(ierr); 1695dc86033cSMatthew G. Knepley if (!dimIS) { 1696dc86033cSMatthew G. Knepley ierr = PetscFree(pMax);CHKERRQ(ierr); 16978630cb1aSMatthew G. Knepley ierr = ISDestroy(&subpointIS);CHKERRQ(ierr); 1698dc86033cSMatthew G. Knepley PetscFunctionReturn(0); 1699dc86033cSMatthew G. Knepley } 1700cd0c2139SMatthew G Knepley ierr = ISGetLocalSize(dimIS, &numPoints);CHKERRQ(ierr); 1701cd0c2139SMatthew G Knepley ierr = ISGetIndices(dimIS, &points);CHKERRQ(ierr); 1702d7c8f101SMatthew G. Knepley for (p = 0; p < numPoints; ++p) { /* Loop over fault faces */ 1703cd0c2139SMatthew G Knepley const PetscInt *support; 1704cd0c2139SMatthew G Knepley PetscInt supportSize, s; 1705cd0c2139SMatthew G Knepley 1706cd0c2139SMatthew G Knepley ierr = DMPlexGetSupportSize(dm, points[p], &supportSize);CHKERRQ(ierr); 1707c4419245SMatthew G. Knepley #if 0 1708c4419245SMatthew G. Knepley if (supportSize != 2) { 1709c4419245SMatthew G. Knepley const PetscInt *lp; 1710c4419245SMatthew G. Knepley PetscInt Nlp, pind; 1711c4419245SMatthew G. Knepley 1712c4419245SMatthew G. Knepley /* Check that for a cell with a single support face, that face is in the SF */ 1713c4419245SMatthew G. Knepley /* THis check only works for the remote side. We would need root side information */ 1714c4419245SMatthew G. Knepley ierr = PetscSFGetGraph(dm->sf, NULL, &Nlp, &lp, NULL);CHKERRQ(ierr); 1715c4419245SMatthew G. Knepley ierr = PetscFindInt(points[p], Nlp, lp, &pind);CHKERRQ(ierr); 1716c4419245SMatthew G. Knepley if (pind < 0) SETERRQ2(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "Split face %d has %d != 2 supports, and the face is not shared with another process", points[p], supportSize); 1717c4419245SMatthew G. Knepley } 1718c4419245SMatthew G. Knepley #endif 1719cd0c2139SMatthew G Knepley ierr = DMPlexGetSupport(dm, points[p], &support);CHKERRQ(ierr); 1720cd0c2139SMatthew G Knepley for (s = 0; s < supportSize; ++s) { 17210f66a230SMatthew G. Knepley const PetscInt *cone; 1722cd0c2139SMatthew G Knepley PetscInt coneSize, c; 17230f66a230SMatthew G. Knepley PetscBool pos; 1724cd0c2139SMatthew G Knepley 17250f66a230SMatthew G. Knepley ierr = GetSurfaceSide_Static(dm, subdm, numSubpoints, subpoints, support[s], points[p], &pos);CHKERRQ(ierr); 17260f66a230SMatthew G. Knepley if (pos) {ierr = DMLabelSetValue(label, support[s], rev*(shift+dim));CHKERRQ(ierr);} 17270f66a230SMatthew G. Knepley else {ierr = DMLabelSetValue(label, support[s], -rev*(shift+dim));CHKERRQ(ierr);} 17280f66a230SMatthew G. Knepley if (rev < 0) pos = !pos ? PETSC_TRUE : PETSC_FALSE; 17290f66a230SMatthew G. Knepley /* Put faces touching the fault in the label */ 1730cd0c2139SMatthew G Knepley ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr); 1731cd0c2139SMatthew G Knepley ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr); 1732cd0c2139SMatthew G Knepley for (c = 0; c < coneSize; ++c) { 1733cd0c2139SMatthew G Knepley const PetscInt point = cone[c]; 1734cd0c2139SMatthew G Knepley 1735cd0c2139SMatthew G Knepley ierr = DMLabelGetValue(label, point, &val);CHKERRQ(ierr); 1736cd0c2139SMatthew G Knepley if (val == -1) { 1737cd0c2139SMatthew G Knepley PetscInt *closure = NULL; 1738cd0c2139SMatthew G Knepley PetscInt closureSize, cl; 1739cd0c2139SMatthew G Knepley 1740cd0c2139SMatthew G Knepley ierr = DMPlexGetTransitiveClosure(dm, point, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 1741cd0c2139SMatthew G Knepley for (cl = 0; cl < closureSize*2; cl += 2) { 1742cd0c2139SMatthew G Knepley const PetscInt clp = closure[cl]; 1743a0541d8aSMatthew G. Knepley PetscInt bval = -1; 1744cd0c2139SMatthew G Knepley 1745cd0c2139SMatthew G Knepley ierr = DMLabelGetValue(label, clp, &val);CHKERRQ(ierr); 1746a0541d8aSMatthew G. Knepley if (blabel) {ierr = DMLabelGetValue(blabel, clp, &bval);CHKERRQ(ierr);} 1747a0541d8aSMatthew G. Knepley if ((val >= 0) && (val < dim-1) && (bval < 0)) { 1748cd0c2139SMatthew G Knepley ierr = DMLabelSetValue(label, point, pos == PETSC_TRUE ? shift+dim-1 : -(shift+dim-1));CHKERRQ(ierr); 1749cd0c2139SMatthew G Knepley break; 1750cd0c2139SMatthew G Knepley } 1751cd0c2139SMatthew G Knepley } 1752cd0c2139SMatthew G Knepley ierr = DMPlexRestoreTransitiveClosure(dm, point, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 1753cd0c2139SMatthew G Knepley } 1754cd0c2139SMatthew G Knepley } 1755cd0c2139SMatthew G Knepley } 1756cd0c2139SMatthew G Knepley } 17570f66a230SMatthew G. Knepley ierr = ISRestoreIndices(dimIS, &points);CHKERRQ(ierr); 17580f66a230SMatthew G. Knepley ierr = ISDestroy(&dimIS);CHKERRQ(ierr); 175947946fd8SMatthew G. Knepley if (subpointIS) {ierr = ISRestoreIndices(subpointIS, &subpoints);CHKERRQ(ierr);} 176047946fd8SMatthew G. Knepley ierr = ISDestroy(&subpointIS);CHKERRQ(ierr); 1761a0541d8aSMatthew G. Knepley /* Mark boundary points as unsplit */ 176286200784SMatthew G. Knepley if (blabel) { 1763a0541d8aSMatthew G. Knepley ierr = DMLabelGetStratumIS(blabel, 1, &dimIS);CHKERRQ(ierr); 1764a0541d8aSMatthew G. Knepley ierr = ISGetLocalSize(dimIS, &numPoints);CHKERRQ(ierr); 1765a0541d8aSMatthew G. Knepley ierr = ISGetIndices(dimIS, &points);CHKERRQ(ierr); 1766a0541d8aSMatthew G. Knepley for (p = 0; p < numPoints; ++p) { 1767a0541d8aSMatthew G. Knepley const PetscInt point = points[p]; 1768a0541d8aSMatthew G. Knepley PetscInt val, bval; 1769a0541d8aSMatthew G. Knepley 1770a0541d8aSMatthew G. Knepley ierr = DMLabelGetValue(blabel, point, &bval);CHKERRQ(ierr); 1771a0541d8aSMatthew G. Knepley if (bval >= 0) { 1772f7019248SMatthew G. Knepley ierr = DMLabelGetValue(label, point, &val);CHKERRQ(ierr); 1773f7019248SMatthew G. Knepley if ((val < 0) || (val > dim)) { 1774f7019248SMatthew G. Knepley /* This could be a point added from splitting a vertex on an adjacent fault, otherwise its just wrong */ 1775f7019248SMatthew G. Knepley ierr = DMLabelClearValue(blabel, point, bval);CHKERRQ(ierr); 1776f7019248SMatthew G. Knepley } 1777f7019248SMatthew G. Knepley } 1778f7019248SMatthew G. Knepley } 1779f7019248SMatthew G. Knepley for (p = 0; p < numPoints; ++p) { 1780f7019248SMatthew G. Knepley const PetscInt point = points[p]; 1781f7019248SMatthew G. Knepley PetscInt val, bval; 1782f7019248SMatthew G. Knepley 1783f7019248SMatthew G. Knepley ierr = DMLabelGetValue(blabel, point, &bval);CHKERRQ(ierr); 1784f7019248SMatthew G. Knepley if (bval >= 0) { 178586200784SMatthew G. Knepley const PetscInt *cone, *support; 178686200784SMatthew G. Knepley PetscInt coneSize, supportSize, s, valA, valB, valE; 178786200784SMatthew G. Knepley 1788a0541d8aSMatthew G. Knepley /* Mark as unsplit */ 1789a0541d8aSMatthew G. Knepley ierr = DMLabelGetValue(label, point, &val);CHKERRQ(ierr); 1790a0541d8aSMatthew G. Knepley if ((val < 0) || (val > dim)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Point %d has label value %d, should be part of the fault", point, val); 1791a0541d8aSMatthew G. Knepley ierr = DMLabelClearValue(label, point, val);CHKERRQ(ierr); 1792a0541d8aSMatthew G. Knepley ierr = DMLabelSetValue(label, point, shift2+val);CHKERRQ(ierr); 17932c06a818SMatthew G. Knepley /* Check for cross-edge 17942c06a818SMatthew G. Knepley A cross-edge has endpoints which are both on the boundary of the surface, but the edge itself is not. */ 179586200784SMatthew G. Knepley if (val != 0) continue; 179686200784SMatthew G. Knepley ierr = DMPlexGetSupport(dm, point, &support);CHKERRQ(ierr); 179786200784SMatthew G. Knepley ierr = DMPlexGetSupportSize(dm, point, &supportSize);CHKERRQ(ierr); 179886200784SMatthew G. Knepley for (s = 0; s < supportSize; ++s) { 179986200784SMatthew G. Knepley ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr); 180086200784SMatthew G. Knepley ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr); 180186200784SMatthew G. Knepley if (coneSize != 2) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Edge %D has %D vertices != 2", support[s], coneSize); 180286200784SMatthew G. Knepley ierr = DMLabelGetValue(blabel, cone[0], &valA);CHKERRQ(ierr); 180386200784SMatthew G. Knepley ierr = DMLabelGetValue(blabel, cone[1], &valB);CHKERRQ(ierr); 180486200784SMatthew G. Knepley ierr = DMLabelGetValue(blabel, support[s], &valE);CHKERRQ(ierr); 180509816f77SMatthew G. Knepley if ((valE < 0) && (valA >= 0) && (valB >= 0) && (cone[0] != cone[1])) {ierr = DMLabelSetValue(blabel, support[s], 2);CHKERRQ(ierr);} 180686200784SMatthew G. Knepley } 1807a0541d8aSMatthew G. Knepley } 1808a0541d8aSMatthew G. Knepley } 1809a0541d8aSMatthew G. Knepley ierr = ISRestoreIndices(dimIS, &points);CHKERRQ(ierr); 1810a0541d8aSMatthew G. Knepley ierr = ISDestroy(&dimIS);CHKERRQ(ierr); 1811a0541d8aSMatthew G. Knepley } 1812cd0c2139SMatthew G Knepley /* Search for other cells/faces/edges connected to the fault by a vertex */ 1813c4d480a2SMatthew G. Knepley ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr); 1814cd0c2139SMatthew G Knepley ierr = DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd);CHKERRQ(ierr); 1815d24f5ce5SMatthew G. Knepley ierr = DMPlexGetHybridBounds(dm, &cMax, NULL, NULL, NULL);CHKERRQ(ierr); 1816d24f5ce5SMatthew G. Knepley cMax = cMax < 0 ? cEnd : cMax; 18170f66a230SMatthew G. Knepley ierr = DMPlexGetHeightStratum(dm, 1, &fStart, &fEnd);CHKERRQ(ierr); 1818cd0c2139SMatthew G Knepley ierr = DMLabelGetStratumIS(label, 0, &dimIS);CHKERRQ(ierr); 181986200784SMatthew G. Knepley if (blabel) {ierr = DMLabelGetStratumIS(blabel, 2, &crossEdgeIS);CHKERRQ(ierr);} 182086200784SMatthew G. Knepley if (dimIS && crossEdgeIS) { 182186200784SMatthew G. Knepley IS vertIS = dimIS; 182286200784SMatthew G. Knepley 182386200784SMatthew G. Knepley ierr = ISExpand(vertIS, crossEdgeIS, &dimIS);CHKERRQ(ierr); 182486200784SMatthew G. Knepley ierr = ISDestroy(&crossEdgeIS);CHKERRQ(ierr); 182586200784SMatthew G. Knepley ierr = ISDestroy(&vertIS);CHKERRQ(ierr); 182686200784SMatthew G. Knepley } 1827dc86033cSMatthew G. Knepley if (!dimIS) { 1828dc86033cSMatthew G. Knepley ierr = PetscFree(pMax);CHKERRQ(ierr); 1829dc86033cSMatthew G. Knepley PetscFunctionReturn(0); 1830dc86033cSMatthew G. Knepley } 1831cd0c2139SMatthew G Knepley ierr = ISGetLocalSize(dimIS, &numPoints);CHKERRQ(ierr); 1832cd0c2139SMatthew G Knepley ierr = ISGetIndices(dimIS, &points);CHKERRQ(ierr); 1833d7c8f101SMatthew G. Knepley for (p = 0; p < numPoints; ++p) { /* Loop over fault vertices */ 1834cd0c2139SMatthew G Knepley PetscInt *star = NULL; 183586200784SMatthew G. Knepley PetscInt starSize, s; 1836cd0c2139SMatthew G Knepley PetscInt again = 1; /* 0: Finished 1: Keep iterating after a change 2: No change */ 1837cd0c2139SMatthew G Knepley 1838d4622b2cSMatthew G. Knepley /* All points connected to the fault are inside a cell, so at the top level we will only check cells */ 1839cd0c2139SMatthew G Knepley ierr = DMPlexGetTransitiveClosure(dm, points[p], PETSC_FALSE, &starSize, &star);CHKERRQ(ierr); 1840cd0c2139SMatthew G Knepley while (again) { 1841cd0c2139SMatthew G Knepley if (again > 1) SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Could not classify all cells connected to the fault"); 1842cd0c2139SMatthew G Knepley again = 0; 1843cd0c2139SMatthew G Knepley for (s = 0; s < starSize*2; s += 2) { 1844cd0c2139SMatthew G Knepley const PetscInt point = star[s]; 1845cd0c2139SMatthew G Knepley const PetscInt *cone; 1846cd0c2139SMatthew G Knepley PetscInt coneSize, c; 1847cd0c2139SMatthew G Knepley 1848d24f5ce5SMatthew G. Knepley if ((point < cStart) || (point >= cMax)) continue; 1849cd0c2139SMatthew G Knepley ierr = DMLabelGetValue(label, point, &val);CHKERRQ(ierr); 1850cd0c2139SMatthew G Knepley if (val != -1) continue; 1851d4622b2cSMatthew G. Knepley again = again == 1 ? 1 : 2; 1852cd0c2139SMatthew G Knepley ierr = DMPlexGetConeSize(dm, point, &coneSize);CHKERRQ(ierr); 1853cd0c2139SMatthew G Knepley ierr = DMPlexGetCone(dm, point, &cone);CHKERRQ(ierr); 1854cd0c2139SMatthew G Knepley for (c = 0; c < coneSize; ++c) { 1855cd0c2139SMatthew G Knepley ierr = DMLabelGetValue(label, cone[c], &val);CHKERRQ(ierr); 1856cd0c2139SMatthew G Knepley if (val != -1) { 1857d7c8f101SMatthew G. Knepley const PetscInt *ccone; 1858166d9d0cSMatthew G. Knepley PetscInt cconeSize, cc, side; 1859d7c8f101SMatthew G. Knepley 1860db8edaafSMatthew G. Knepley if (PetscAbs(val) < shift) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Face %d on cell %d has an invalid label %d", cone[c], point, val); 186137a6de01SMatthew G. Knepley if (val > 0) side = 1; 186237a6de01SMatthew G. Knepley else side = -1; 186337a6de01SMatthew G. Knepley ierr = DMLabelSetValue(label, point, side*(shift+dim));CHKERRQ(ierr); 1864d7c8f101SMatthew G. Knepley /* Mark cell faces which touch the fault */ 1865d7c8f101SMatthew G. Knepley ierr = DMPlexGetConeSize(dm, point, &cconeSize);CHKERRQ(ierr); 1866d7c8f101SMatthew G. Knepley ierr = DMPlexGetCone(dm, point, &ccone);CHKERRQ(ierr); 1867d7c8f101SMatthew G. Knepley for (cc = 0; cc < cconeSize; ++cc) { 1868d7c8f101SMatthew G. Knepley PetscInt *closure = NULL; 1869d7c8f101SMatthew G. Knepley PetscInt closureSize, cl; 1870d7c8f101SMatthew G. Knepley 1871166d9d0cSMatthew G. Knepley ierr = DMLabelGetValue(label, ccone[cc], &val);CHKERRQ(ierr); 1872166d9d0cSMatthew G. Knepley if (val != -1) continue; 1873d7c8f101SMatthew G. Knepley ierr = DMPlexGetTransitiveClosure(dm, ccone[cc], PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 1874d4622b2cSMatthew G. Knepley for (cl = 0; cl < closureSize*2; cl += 2) { 1875d7c8f101SMatthew G. Knepley const PetscInt clp = closure[cl]; 1876d7c8f101SMatthew G. Knepley 1877d7c8f101SMatthew G. Knepley ierr = DMLabelGetValue(label, clp, &val);CHKERRQ(ierr); 1878d7c8f101SMatthew G. Knepley if (val == -1) continue; 1879d7c8f101SMatthew G. Knepley ierr = DMLabelSetValue(label, ccone[cc], side*(shift+dim-1));CHKERRQ(ierr); 188037a6de01SMatthew G. Knepley break; 188137a6de01SMatthew G. Knepley } 1882d7c8f101SMatthew G. Knepley ierr = DMPlexRestoreTransitiveClosure(dm, ccone[cc], PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 1883cd0c2139SMatthew G Knepley } 1884cd0c2139SMatthew G Knepley again = 1; 1885cd0c2139SMatthew G Knepley break; 1886cd0c2139SMatthew G Knepley } 1887cd0c2139SMatthew G Knepley } 1888cd0c2139SMatthew G Knepley } 1889cd0c2139SMatthew G Knepley } 1890cd0c2139SMatthew G Knepley /* Classify the rest by cell membership */ 1891cd0c2139SMatthew G Knepley for (s = 0; s < starSize*2; s += 2) { 1892cd0c2139SMatthew G Knepley const PetscInt point = star[s]; 1893cd0c2139SMatthew G Knepley 1894cd0c2139SMatthew G Knepley ierr = DMLabelGetValue(label, point, &val);CHKERRQ(ierr); 1895cd0c2139SMatthew G Knepley if (val == -1) { 1896cd0c2139SMatthew G Knepley PetscInt *sstar = NULL; 1897cd0c2139SMatthew G Knepley PetscInt sstarSize, ss; 1898cd0c2139SMatthew G Knepley PetscBool marked = PETSC_FALSE; 1899cd0c2139SMatthew G Knepley 1900cd0c2139SMatthew G Knepley ierr = DMPlexGetTransitiveClosure(dm, point, PETSC_FALSE, &sstarSize, &sstar);CHKERRQ(ierr); 1901cd0c2139SMatthew G Knepley for (ss = 0; ss < sstarSize*2; ss += 2) { 1902cd0c2139SMatthew G Knepley const PetscInt spoint = sstar[ss]; 1903cd0c2139SMatthew G Knepley 1904d24f5ce5SMatthew G. Knepley if ((spoint < cStart) || (spoint >= cMax)) continue; 1905cd0c2139SMatthew G Knepley ierr = DMLabelGetValue(label, spoint, &val);CHKERRQ(ierr); 1906cd0c2139SMatthew G Knepley if (val == -1) SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Cell %d in star of %d does not have a valid label", spoint, point); 1907d90583fdSMatthew G. Knepley ierr = DMLabelGetValue(depthLabel, point, &dep);CHKERRQ(ierr); 1908cd0c2139SMatthew G Knepley if (val > 0) { 1909cd0c2139SMatthew G Knepley ierr = DMLabelSetValue(label, point, shift+dep);CHKERRQ(ierr); 1910cd0c2139SMatthew G Knepley } else { 1911cd0c2139SMatthew G Knepley ierr = DMLabelSetValue(label, point, -(shift+dep));CHKERRQ(ierr); 1912cd0c2139SMatthew G Knepley } 1913cd0c2139SMatthew G Knepley marked = PETSC_TRUE; 1914cd0c2139SMatthew G Knepley break; 1915cd0c2139SMatthew G Knepley } 1916cd0c2139SMatthew G Knepley ierr = DMPlexRestoreTransitiveClosure(dm, point, PETSC_FALSE, &sstarSize, &sstar);CHKERRQ(ierr); 1917370472baSMatthew G. Knepley ierr = DMLabelGetValue(depthLabel, point, &dep);CHKERRQ(ierr); 1918370472baSMatthew G. Knepley if (point < pMax[dep] && !marked) SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d could not be classified", point); 1919cd0c2139SMatthew G Knepley } 1920cd0c2139SMatthew G Knepley } 1921cd0c2139SMatthew G Knepley ierr = DMPlexRestoreTransitiveClosure(dm, points[p], PETSC_FALSE, &starSize, &star);CHKERRQ(ierr); 1922cd0c2139SMatthew G Knepley } 1923cd0c2139SMatthew G Knepley ierr = ISRestoreIndices(dimIS, &points);CHKERRQ(ierr); 1924cd0c2139SMatthew G Knepley ierr = ISDestroy(&dimIS);CHKERRQ(ierr); 192518c5995bSMatthew G. Knepley /* If any faces touching the fault divide cells on either side, split them */ 192618c5995bSMatthew G. Knepley ierr = DMLabelGetStratumIS(label, shift+dim-1, &facePosIS);CHKERRQ(ierr); 192718c5995bSMatthew G. Knepley ierr = DMLabelGetStratumIS(label, -(shift+dim-1), &faceNegIS);CHKERRQ(ierr); 192818c5995bSMatthew G. Knepley ierr = ISExpand(facePosIS, faceNegIS, &dimIS);CHKERRQ(ierr); 192918c5995bSMatthew G. Knepley ierr = ISDestroy(&facePosIS);CHKERRQ(ierr); 193018c5995bSMatthew G. Knepley ierr = ISDestroy(&faceNegIS);CHKERRQ(ierr); 193118c5995bSMatthew G. Knepley ierr = ISGetLocalSize(dimIS, &numPoints);CHKERRQ(ierr); 193218c5995bSMatthew G. Knepley ierr = ISGetIndices(dimIS, &points);CHKERRQ(ierr); 193318c5995bSMatthew G. Knepley for (p = 0; p < numPoints; ++p) { 193418c5995bSMatthew G. Knepley const PetscInt point = points[p]; 193518c5995bSMatthew G. Knepley const PetscInt *support; 193618c5995bSMatthew G. Knepley PetscInt supportSize, valA, valB; 193718c5995bSMatthew G. Knepley 193818c5995bSMatthew G. Knepley ierr = DMPlexGetSupportSize(dm, point, &supportSize);CHKERRQ(ierr); 193918c5995bSMatthew G. Knepley if (supportSize != 2) continue; 194018c5995bSMatthew G. Knepley ierr = DMPlexGetSupport(dm, point, &support);CHKERRQ(ierr); 194118c5995bSMatthew G. Knepley ierr = DMLabelGetValue(label, support[0], &valA);CHKERRQ(ierr); 194218c5995bSMatthew G. Knepley ierr = DMLabelGetValue(label, support[1], &valB);CHKERRQ(ierr); 194318c5995bSMatthew G. Knepley if ((valA == -1) || (valB == -1)) continue; 194418c5995bSMatthew G. Knepley if (valA*valB > 0) continue; 194518c5995bSMatthew G. Knepley /* Split the face */ 194618c5995bSMatthew G. Knepley ierr = DMLabelGetValue(label, point, &valA);CHKERRQ(ierr); 194718c5995bSMatthew G. Knepley ierr = DMLabelClearValue(label, point, valA);CHKERRQ(ierr); 194818c5995bSMatthew G. Knepley ierr = DMLabelSetValue(label, point, dim-1);CHKERRQ(ierr); 1949e1757548SMatthew G. Knepley /* Label its closure: 1950e1757548SMatthew G. Knepley unmarked: label as unsplit 1951e1757548SMatthew G. Knepley incident: relabel as split 1952e1757548SMatthew G. Knepley split: do nothing 1953e1757548SMatthew G. Knepley */ 195418c5995bSMatthew G. Knepley { 195518c5995bSMatthew G. Knepley PetscInt *closure = NULL; 195618c5995bSMatthew G. Knepley PetscInt closureSize, cl; 195718c5995bSMatthew G. Knepley 195818c5995bSMatthew G. Knepley ierr = DMPlexGetTransitiveClosure(dm, point, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 195918c5995bSMatthew G. Knepley for (cl = 0; cl < closureSize*2; cl += 2) { 196018c5995bSMatthew G. Knepley ierr = DMLabelGetValue(label, closure[cl], &valA);CHKERRQ(ierr); 19618771c1d3SMatthew G. Knepley if (valA == -1) { /* Mark as unsplit */ 196218c5995bSMatthew G. Knepley ierr = DMLabelGetValue(depthLabel, closure[cl], &dep);CHKERRQ(ierr); 196318c5995bSMatthew G. Knepley ierr = DMLabelSetValue(label, closure[cl], shift2+dep);CHKERRQ(ierr); 19648771c1d3SMatthew G. Knepley } else if (((valA >= shift) && (valA < shift2)) || ((valA <= -shift) && (valA > -shift2))) { 1965e1757548SMatthew G. Knepley ierr = DMLabelGetValue(depthLabel, closure[cl], &dep);CHKERRQ(ierr); 1966e1757548SMatthew G. Knepley ierr = DMLabelClearValue(label, closure[cl], valA);CHKERRQ(ierr); 1967e1757548SMatthew G. Knepley ierr = DMLabelSetValue(label, closure[cl], dep);CHKERRQ(ierr); 1968e1757548SMatthew G. Knepley } 196918c5995bSMatthew G. Knepley } 197018c5995bSMatthew G. Knepley ierr = DMPlexRestoreTransitiveClosure(dm, point, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 197118c5995bSMatthew G. Knepley } 197218c5995bSMatthew G. Knepley } 197318c5995bSMatthew G. Knepley ierr = ISRestoreIndices(dimIS, &points);CHKERRQ(ierr); 197418c5995bSMatthew G. Knepley ierr = ISDestroy(&dimIS);CHKERRQ(ierr); 1975370472baSMatthew G. Knepley ierr = PetscFree(pMax);CHKERRQ(ierr); 1976cd0c2139SMatthew G Knepley PetscFunctionReturn(0); 1977cd0c2139SMatthew G Knepley } 1978cd0c2139SMatthew G Knepley 1979720e594eSMatthew G. Knepley /* Check that no cell have all vertices on the fault */ 1980720e594eSMatthew G. Knepley PetscErrorCode DMPlexCheckValidSubmesh_Private(DM dm, DMLabel label, DM subdm) 1981720e594eSMatthew G. Knepley { 1982720e594eSMatthew G. Knepley IS subpointIS; 1983720e594eSMatthew G. Knepley const PetscInt *dmpoints; 1984720e594eSMatthew G. Knepley PetscInt defaultValue, cStart, cEnd, c, vStart, vEnd; 1985720e594eSMatthew G. Knepley PetscErrorCode ierr; 1986720e594eSMatthew G. Knepley 1987720e594eSMatthew G. Knepley PetscFunctionBegin; 1988720e594eSMatthew G. Knepley if (!label) PetscFunctionReturn(0); 1989720e594eSMatthew G. Knepley ierr = DMLabelGetDefaultValue(label, &defaultValue);CHKERRQ(ierr); 1990720e594eSMatthew G. Knepley ierr = DMPlexCreateSubpointIS(subdm, &subpointIS);CHKERRQ(ierr); 1991720e594eSMatthew G. Knepley if (!subpointIS) PetscFunctionReturn(0); 1992720e594eSMatthew G. Knepley ierr = DMPlexGetHeightStratum(subdm, 0, &cStart, &cEnd);CHKERRQ(ierr); 1993720e594eSMatthew G. Knepley ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr); 1994720e594eSMatthew G. Knepley ierr = ISGetIndices(subpointIS, &dmpoints);CHKERRQ(ierr); 1995720e594eSMatthew G. Knepley for (c = cStart; c < cEnd; ++c) { 1996720e594eSMatthew G. Knepley PetscBool invalidCell = PETSC_TRUE; 1997720e594eSMatthew G. Knepley PetscInt *closure = NULL; 1998720e594eSMatthew G. Knepley PetscInt closureSize, cl; 1999720e594eSMatthew G. Knepley 2000720e594eSMatthew G. Knepley ierr = DMPlexGetTransitiveClosure(dm, dmpoints[c], PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 2001720e594eSMatthew G. Knepley for (cl = 0; cl < closureSize*2; cl += 2) { 2002720e594eSMatthew G. Knepley PetscInt value = 0; 2003720e594eSMatthew G. Knepley 2004720e594eSMatthew G. Knepley if ((closure[cl] < vStart) || (closure[cl] >= vEnd)) continue; 2005720e594eSMatthew G. Knepley ierr = DMLabelGetValue(label, closure[cl], &value);CHKERRQ(ierr); 2006720e594eSMatthew G. Knepley if (value == defaultValue) {invalidCell = PETSC_FALSE; break;} 2007720e594eSMatthew G. Knepley } 2008720e594eSMatthew G. Knepley ierr = DMPlexRestoreTransitiveClosure(dm, dmpoints[c], PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 2009720e594eSMatthew G. Knepley if (invalidCell) { 2010720e594eSMatthew G. Knepley ierr = ISRestoreIndices(subpointIS, &dmpoints);CHKERRQ(ierr); 2011720e594eSMatthew G. Knepley ierr = ISDestroy(&subpointIS);CHKERRQ(ierr); 2012720e594eSMatthew G. Knepley ierr = DMDestroy(&subdm);CHKERRQ(ierr); 2013720e594eSMatthew G. Knepley SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Ambiguous submesh. Cell %D has all of its vertices on the submesh.", dmpoints[c]); 2014720e594eSMatthew G. Knepley } 2015720e594eSMatthew G. Knepley } 2016720e594eSMatthew G. Knepley ierr = ISRestoreIndices(subpointIS, &dmpoints);CHKERRQ(ierr); 2017720e594eSMatthew G. Knepley ierr = ISDestroy(&subpointIS);CHKERRQ(ierr); 2018720e594eSMatthew G. Knepley PetscFunctionReturn(0); 2019720e594eSMatthew G. Knepley } 2020720e594eSMatthew G. Knepley 2021720e594eSMatthew G. Knepley 2022c08575a3SMatthew G. Knepley /*@ 20233cf72582SMatthew G. Knepley DMPlexCreateHybridMesh - Create a mesh with hybrid cells along an internal interface 20243cf72582SMatthew G. Knepley 20253cf72582SMatthew G. Knepley Collective on dm 20263cf72582SMatthew G. Knepley 20273cf72582SMatthew G. Knepley Input Parameters: 20283cf72582SMatthew G. Knepley + dm - The original DM 2029720e594eSMatthew G. Knepley . label - The label specifying the interface vertices 2030720e594eSMatthew G. Knepley - bdlabel - The optional label specifying the interface boundary vertices 20313cf72582SMatthew G. Knepley 20323cf72582SMatthew G. Knepley Output Parameters: 20337db7e0a7SMatthew G. Knepley + hybridLabel - The label fully marking the interface, or NULL if no output is desired 20347db7e0a7SMatthew G. Knepley . splitLabel - The label containing the split points, or NULL if no output is desired 2035720e594eSMatthew G. Knepley . dmInterface - The new interface DM, or NULL 2036720e594eSMatthew G. Knepley - dmHybrid - The new DM with cohesive cells 20373cf72582SMatthew G. Knepley 20386eccb800SMatthew Knepley Note: The hybridLabel indicates what parts of the original mesh impinged on the on division surface. For points 20396eccb800SMatthew Knepley directly on the division surface, they are labeled with their dimension, so an edge 7 on the division surface would be 20406eccb800SMatthew Knepley 7 (1) in hybridLabel. For points that impinge from the positive side, they are labeled with 100+dim, so an edge 6 with 20416eccb800SMatthew Knepley one vertex 3 on the surface would be 6 (101) and 3 (0) in hybridLabel. If an edge 9 from the negative side of the 20426eccb800SMatthew Knepley surface also hits vertex 3, it would be 9 (-101) in hybridLabel. 20436eccb800SMatthew Knepley 20446eccb800SMatthew Knepley The splitLabel indicates what points in the new hybrid mesh were the result of splitting points in the original 20456eccb800SMatthew Knepley mesh. The label value is +=100+dim for each point. For example, if two edges 10 and 14 in the hybrid resulting from 20466eccb800SMatthew Knepley splitting an edge in the original mesh, you would have 10 (101) and 14 (-101) in the splitLabel. 20476eccb800SMatthew Knepley 20486eccb800SMatthew Knepley The dmInterface is a DM built from the original division surface. It has a label which can be retrieved using 20496eccb800SMatthew Knepley DMPlexGetSubpointMap() which maps each point back to the point in the surface of the original mesh. 20506eccb800SMatthew Knepley 20513cf72582SMatthew G. Knepley Level: developer 20523cf72582SMatthew G. Knepley 20536eccb800SMatthew Knepley .seealso: DMPlexConstructCohesiveCells(), DMPlexLabelCohesiveComplete(), DMPlexGetSubpointMap(), DMCreate() 20543cf72582SMatthew G. Knepley @*/ 20557db7e0a7SMatthew G. Knepley PetscErrorCode DMPlexCreateHybridMesh(DM dm, DMLabel label, DMLabel bdlabel, DMLabel *hybridLabel, DMLabel *splitLabel, DM *dmInterface, DM *dmHybrid) 20563cf72582SMatthew G. Knepley { 20573cf72582SMatthew G. Knepley DM idm; 20587db7e0a7SMatthew G. Knepley DMLabel subpointMap, hlabel, slabel = NULL; 20593cf72582SMatthew G. Knepley PetscInt dim; 20603cf72582SMatthew G. Knepley PetscErrorCode ierr; 20613cf72582SMatthew G. Knepley 20623cf72582SMatthew G. Knepley PetscFunctionBegin; 20633cf72582SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 2064720e594eSMatthew G. Knepley if (bdlabel) PetscValidPointer(bdlabel, 3); 2065720e594eSMatthew G. Knepley if (hybridLabel) PetscValidPointer(hybridLabel, 4); 20667db7e0a7SMatthew G. Knepley if (splitLabel) PetscValidPointer(splitLabel, 5); 20677db7e0a7SMatthew G. Knepley if (dmInterface) PetscValidPointer(dmInterface, 6); 20687db7e0a7SMatthew G. Knepley PetscValidPointer(dmHybrid, 7); 2069c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 2070158acfadSMatthew G. Knepley ierr = DMPlexCreateSubmesh(dm, label, 1, PETSC_FALSE, &idm);CHKERRQ(ierr); 2071720e594eSMatthew G. Knepley ierr = DMPlexCheckValidSubmesh_Private(dm, label, idm);CHKERRQ(ierr); 20723cf72582SMatthew G. Knepley ierr = DMPlexOrient(idm);CHKERRQ(ierr); 20733cf72582SMatthew G. Knepley ierr = DMPlexGetSubpointMap(idm, &subpointMap);CHKERRQ(ierr); 20743cf72582SMatthew G. Knepley ierr = DMLabelDuplicate(subpointMap, &hlabel);CHKERRQ(ierr); 20753cf72582SMatthew G. Knepley ierr = DMLabelClearStratum(hlabel, dim);CHKERRQ(ierr); 20767db7e0a7SMatthew G. Knepley if (splitLabel) { 20777db7e0a7SMatthew G. Knepley const char *name; 20787db7e0a7SMatthew G. Knepley char sname[PETSC_MAX_PATH_LEN]; 20797db7e0a7SMatthew G. Knepley 2080d67d17b1SMatthew G. Knepley ierr = PetscObjectGetName((PetscObject) hlabel, &name);CHKERRQ(ierr); 20817db7e0a7SMatthew G. Knepley ierr = PetscStrncpy(sname, name, PETSC_MAX_PATH_LEN);CHKERRQ(ierr); 20827db7e0a7SMatthew G. Knepley ierr = PetscStrcat(sname, " split");CHKERRQ(ierr); 2083d67d17b1SMatthew G. Knepley ierr = DMLabelCreate(PETSC_COMM_SELF, sname, &slabel);CHKERRQ(ierr); 20847db7e0a7SMatthew G. Knepley } 2085720e594eSMatthew G. Knepley ierr = DMPlexLabelCohesiveComplete(dm, hlabel, bdlabel, PETSC_FALSE, idm);CHKERRQ(ierr); 2086720e594eSMatthew G. Knepley if (dmInterface) {*dmInterface = idm;} 2087720e594eSMatthew G. Knepley else {ierr = DMDestroy(&idm);CHKERRQ(ierr);} 20887db7e0a7SMatthew G. Knepley ierr = DMPlexConstructCohesiveCells(dm, hlabel, slabel, dmHybrid);CHKERRQ(ierr); 20893cf72582SMatthew G. Knepley if (hybridLabel) *hybridLabel = hlabel; 209053aa2e23SMatthew G. Knepley else {ierr = DMLabelDestroy(&hlabel);CHKERRQ(ierr);} 20917db7e0a7SMatthew G. Knepley if (splitLabel) *splitLabel = slabel; 2092cd0c2139SMatthew G Knepley PetscFunctionReturn(0); 2093cd0c2139SMatthew G Knepley } 2094cd0c2139SMatthew G Knepley 2095efa14ee0SMatthew G Knepley /* Here we need the explicit assumption that: 2096efa14ee0SMatthew G Knepley 2097efa14ee0SMatthew G Knepley For any marked cell, the marked vertices constitute a single face 2098efa14ee0SMatthew G Knepley */ 2099830e53efSMatthew G. Knepley static PetscErrorCode DMPlexMarkSubmesh_Uninterpolated(DM dm, DMLabel vertexLabel, PetscInt value, DMLabel subpointMap, PetscInt *numFaces, PetscInt *nFV, DM subdm) 2100efa14ee0SMatthew G Knepley { 2101fed694aaSMatthew G. Knepley IS subvertexIS = NULL; 2102efa14ee0SMatthew G Knepley const PetscInt *subvertices; 210377d178adSMatthew G. Knepley PetscInt *pStart, *pEnd, *pMax, pSize; 2104efa14ee0SMatthew G Knepley PetscInt depth, dim, d, numSubVerticesInitial = 0, v; 2105efa14ee0SMatthew G Knepley PetscErrorCode ierr; 2106efa14ee0SMatthew G Knepley 2107efa14ee0SMatthew G Knepley PetscFunctionBegin; 2108efa14ee0SMatthew G Knepley *numFaces = 0; 2109efa14ee0SMatthew G Knepley *nFV = 0; 2110efa14ee0SMatthew G Knepley ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 2111c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 211277d178adSMatthew G. Knepley pSize = PetscMax(depth, dim) + 1; 2113dcca6d9dSJed Brown ierr = PetscMalloc3(pSize,&pStart,pSize,&pEnd,pSize,&pMax);CHKERRQ(ierr); 2114d92e47f8SMatthew G. Knepley ierr = DMPlexGetHybridBounds(dm, depth >= 0 ? &pMax[depth] : NULL, depth>1 ? &pMax[depth-1] : NULL, depth>2 ? &pMax[1] : NULL, &pMax[0]);CHKERRQ(ierr); 2115efa14ee0SMatthew G Knepley for (d = 0; d <= depth; ++d) { 2116efa14ee0SMatthew G Knepley ierr = DMPlexGetDepthStratum(dm, d, &pStart[d], &pEnd[d]);CHKERRQ(ierr); 2117efa14ee0SMatthew G Knepley if (pMax[d] >= 0) pEnd[d] = PetscMin(pEnd[d], pMax[d]); 2118efa14ee0SMatthew G Knepley } 2119efa14ee0SMatthew G Knepley /* Loop over initial vertices and mark all faces in the collective star() */ 2120fed694aaSMatthew G. Knepley if (vertexLabel) {ierr = DMLabelGetStratumIS(vertexLabel, value, &subvertexIS);CHKERRQ(ierr);} 2121efa14ee0SMatthew G Knepley if (subvertexIS) { 2122efa14ee0SMatthew G Knepley ierr = ISGetSize(subvertexIS, &numSubVerticesInitial);CHKERRQ(ierr); 2123efa14ee0SMatthew G Knepley ierr = ISGetIndices(subvertexIS, &subvertices);CHKERRQ(ierr); 2124efa14ee0SMatthew G Knepley } 2125efa14ee0SMatthew G Knepley for (v = 0; v < numSubVerticesInitial; ++v) { 2126efa14ee0SMatthew G Knepley const PetscInt vertex = subvertices[v]; 21270298fd71SBarry Smith PetscInt *star = NULL; 2128efa14ee0SMatthew G Knepley PetscInt starSize, s, numCells = 0, c; 2129efa14ee0SMatthew G Knepley 2130efa14ee0SMatthew G Knepley ierr = DMPlexGetTransitiveClosure(dm, vertex, PETSC_FALSE, &starSize, &star);CHKERRQ(ierr); 2131efa14ee0SMatthew G Knepley for (s = 0; s < starSize*2; s += 2) { 2132efa14ee0SMatthew G Knepley const PetscInt point = star[s]; 2133efa14ee0SMatthew G Knepley if ((point >= pStart[depth]) && (point < pEnd[depth])) star[numCells++] = point; 2134efa14ee0SMatthew G Knepley } 2135efa14ee0SMatthew G Knepley for (c = 0; c < numCells; ++c) { 2136efa14ee0SMatthew G Knepley const PetscInt cell = star[c]; 21370298fd71SBarry Smith PetscInt *closure = NULL; 2138efa14ee0SMatthew G Knepley PetscInt closureSize, cl; 2139efa14ee0SMatthew G Knepley PetscInt cellLoc, numCorners = 0, faceSize = 0; 2140efa14ee0SMatthew G Knepley 2141efa14ee0SMatthew G Knepley ierr = DMLabelGetValue(subpointMap, cell, &cellLoc);CHKERRQ(ierr); 214265560c7fSMatthew G Knepley if (cellLoc == 2) continue; 214382f516ccSBarry Smith if (cellLoc >= 0) SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Cell %d has dimension %d in the surface label", cell, cellLoc); 2144efa14ee0SMatthew G Knepley ierr = DMPlexGetTransitiveClosure(dm, cell, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 2145efa14ee0SMatthew G Knepley for (cl = 0; cl < closureSize*2; cl += 2) { 2146efa14ee0SMatthew G Knepley const PetscInt point = closure[cl]; 2147efa14ee0SMatthew G Knepley PetscInt vertexLoc; 2148efa14ee0SMatthew G Knepley 2149efa14ee0SMatthew G Knepley if ((point >= pStart[0]) && (point < pEnd[0])) { 2150efa14ee0SMatthew G Knepley ++numCorners; 2151efa14ee0SMatthew G Knepley ierr = DMLabelGetValue(vertexLabel, point, &vertexLoc);CHKERRQ(ierr); 2152830e53efSMatthew G. Knepley if (vertexLoc == value) closure[faceSize++] = point; 2153efa14ee0SMatthew G Knepley } 2154efa14ee0SMatthew G Knepley } 215518ad9376SMatthew G. Knepley if (!(*nFV)) {ierr = DMPlexGetNumFaceVertices(dm, dim, numCorners, nFV);CHKERRQ(ierr);} 215682f516ccSBarry Smith if (faceSize > *nFV) SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "Invalid submesh: Too many vertices %d of an element on the surface", faceSize); 2157efa14ee0SMatthew G Knepley if (faceSize == *nFV) { 2158007baee2SMatthew G. Knepley const PetscInt *cells = NULL; 2159007baee2SMatthew G. Knepley PetscInt numCells, nc; 2160007baee2SMatthew G. Knepley 2161efa14ee0SMatthew G Knepley ++(*numFaces); 2162efa14ee0SMatthew G Knepley for (cl = 0; cl < faceSize; ++cl) { 2163efa14ee0SMatthew G Knepley ierr = DMLabelSetValue(subpointMap, closure[cl], 0);CHKERRQ(ierr); 2164efa14ee0SMatthew G Knepley } 2165007baee2SMatthew G. Knepley ierr = DMPlexGetJoin(dm, faceSize, closure, &numCells, &cells);CHKERRQ(ierr); 2166007baee2SMatthew G. Knepley for (nc = 0; nc < numCells; ++nc) { 2167007baee2SMatthew G. Knepley ierr = DMLabelSetValue(subpointMap, cells[nc], 2);CHKERRQ(ierr); 2168007baee2SMatthew G. Knepley } 2169007baee2SMatthew G. Knepley ierr = DMPlexRestoreJoin(dm, faceSize, closure, &numCells, &cells);CHKERRQ(ierr); 2170efa14ee0SMatthew G Knepley } 2171efa14ee0SMatthew G Knepley ierr = DMPlexRestoreTransitiveClosure(dm, cell, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 2172efa14ee0SMatthew G Knepley } 2173efa14ee0SMatthew G Knepley ierr = DMPlexRestoreTransitiveClosure(dm, vertex, PETSC_FALSE, &starSize, &star);CHKERRQ(ierr); 2174efa14ee0SMatthew G Knepley } 2175efa14ee0SMatthew G Knepley if (subvertexIS) { 2176efa14ee0SMatthew G Knepley ierr = ISRestoreIndices(subvertexIS, &subvertices);CHKERRQ(ierr); 2177efa14ee0SMatthew G Knepley } 2178efa14ee0SMatthew G Knepley ierr = ISDestroy(&subvertexIS);CHKERRQ(ierr); 2179efa14ee0SMatthew G Knepley ierr = PetscFree3(pStart,pEnd,pMax);CHKERRQ(ierr); 2180efa14ee0SMatthew G Knepley PetscFunctionReturn(0); 2181efa14ee0SMatthew G Knepley } 2182efa14ee0SMatthew G Knepley 2183158acfadSMatthew G. Knepley static PetscErrorCode DMPlexMarkSubmesh_Interpolated(DM dm, DMLabel vertexLabel, PetscInt value, PetscBool markedFaces, DMLabel subpointMap, DM subdm) 2184efa14ee0SMatthew G Knepley { 218534b4c39eSMatthew G. Knepley IS subvertexIS = NULL; 2186efa14ee0SMatthew G Knepley const PetscInt *subvertices; 2187efa14ee0SMatthew G Knepley PetscInt *pStart, *pEnd, *pMax; 2188efa14ee0SMatthew G Knepley PetscInt dim, d, numSubVerticesInitial = 0, v; 2189efa14ee0SMatthew G Knepley PetscErrorCode ierr; 2190efa14ee0SMatthew G Knepley 2191efa14ee0SMatthew G Knepley PetscFunctionBegin; 2192c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 2193dcca6d9dSJed Brown ierr = PetscMalloc3(dim+1,&pStart,dim+1,&pEnd,dim+1,&pMax);CHKERRQ(ierr); 21940298fd71SBarry Smith ierr = DMPlexGetHybridBounds(dm, &pMax[dim], dim>1 ? &pMax[dim-1] : NULL, dim > 2 ? &pMax[1] : NULL, &pMax[0]);CHKERRQ(ierr); 2195efa14ee0SMatthew G Knepley for (d = 0; d <= dim; ++d) { 2196efa14ee0SMatthew G Knepley ierr = DMPlexGetDepthStratum(dm, d, &pStart[d], &pEnd[d]);CHKERRQ(ierr); 2197efa14ee0SMatthew G Knepley if (pMax[d] >= 0) pEnd[d] = PetscMin(pEnd[d], pMax[d]); 2198efa14ee0SMatthew G Knepley } 2199efa14ee0SMatthew G Knepley /* Loop over initial vertices and mark all faces in the collective star() */ 220034b4c39eSMatthew G. Knepley if (vertexLabel) { 2201830e53efSMatthew G. Knepley ierr = DMLabelGetStratumIS(vertexLabel, value, &subvertexIS);CHKERRQ(ierr); 2202efa14ee0SMatthew G Knepley if (subvertexIS) { 2203efa14ee0SMatthew G Knepley ierr = ISGetSize(subvertexIS, &numSubVerticesInitial);CHKERRQ(ierr); 2204efa14ee0SMatthew G Knepley ierr = ISGetIndices(subvertexIS, &subvertices);CHKERRQ(ierr); 2205efa14ee0SMatthew G Knepley } 220634b4c39eSMatthew G. Knepley } 2207efa14ee0SMatthew G Knepley for (v = 0; v < numSubVerticesInitial; ++v) { 2208efa14ee0SMatthew G Knepley const PetscInt vertex = subvertices[v]; 22090298fd71SBarry Smith PetscInt *star = NULL; 2210efa14ee0SMatthew G Knepley PetscInt starSize, s, numFaces = 0, f; 2211efa14ee0SMatthew G Knepley 2212efa14ee0SMatthew G Knepley ierr = DMPlexGetTransitiveClosure(dm, vertex, PETSC_FALSE, &starSize, &star);CHKERRQ(ierr); 2213efa14ee0SMatthew G Knepley for (s = 0; s < starSize*2; s += 2) { 2214efa14ee0SMatthew G Knepley const PetscInt point = star[s]; 2215158acfadSMatthew G. Knepley PetscInt faceLoc; 2216158acfadSMatthew G. Knepley 2217158acfadSMatthew G. Knepley if ((point >= pStart[dim-1]) && (point < pEnd[dim-1])) { 2218158acfadSMatthew G. Knepley if (markedFaces) { 2219158acfadSMatthew G. Knepley ierr = DMLabelGetValue(vertexLabel, point, &faceLoc);CHKERRQ(ierr); 2220158acfadSMatthew G. Knepley if (faceLoc < 0) continue; 2221158acfadSMatthew G. Knepley } 2222158acfadSMatthew G. Knepley star[numFaces++] = point; 2223158acfadSMatthew G. Knepley } 2224efa14ee0SMatthew G Knepley } 2225efa14ee0SMatthew G Knepley for (f = 0; f < numFaces; ++f) { 2226efa14ee0SMatthew G Knepley const PetscInt face = star[f]; 22270298fd71SBarry Smith PetscInt *closure = NULL; 2228efa14ee0SMatthew G Knepley PetscInt closureSize, c; 2229efa14ee0SMatthew G Knepley PetscInt faceLoc; 2230efa14ee0SMatthew G Knepley 2231efa14ee0SMatthew G Knepley ierr = DMLabelGetValue(subpointMap, face, &faceLoc);CHKERRQ(ierr); 2232efa14ee0SMatthew G Knepley if (faceLoc == dim-1) continue; 223382f516ccSBarry Smith if (faceLoc >= 0) SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Face %d has dimension %d in the surface label", face, faceLoc); 2234efa14ee0SMatthew G Knepley ierr = DMPlexGetTransitiveClosure(dm, face, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 2235efa14ee0SMatthew G Knepley for (c = 0; c < closureSize*2; c += 2) { 2236efa14ee0SMatthew G Knepley const PetscInt point = closure[c]; 2237efa14ee0SMatthew G Knepley PetscInt vertexLoc; 2238efa14ee0SMatthew G Knepley 2239efa14ee0SMatthew G Knepley if ((point >= pStart[0]) && (point < pEnd[0])) { 2240efa14ee0SMatthew G Knepley ierr = DMLabelGetValue(vertexLabel, point, &vertexLoc);CHKERRQ(ierr); 2241830e53efSMatthew G. Knepley if (vertexLoc != value) break; 2242efa14ee0SMatthew G Knepley } 2243efa14ee0SMatthew G Knepley } 2244efa14ee0SMatthew G Knepley if (c == closureSize*2) { 2245efa14ee0SMatthew G Knepley const PetscInt *support; 2246efa14ee0SMatthew G Knepley PetscInt supportSize, s; 2247efa14ee0SMatthew G Knepley 2248efa14ee0SMatthew G Knepley for (c = 0; c < closureSize*2; c += 2) { 2249efa14ee0SMatthew G Knepley const PetscInt point = closure[c]; 2250efa14ee0SMatthew G Knepley 2251efa14ee0SMatthew G Knepley for (d = 0; d < dim; ++d) { 2252efa14ee0SMatthew G Knepley if ((point >= pStart[d]) && (point < pEnd[d])) { 2253efa14ee0SMatthew G Knepley ierr = DMLabelSetValue(subpointMap, point, d);CHKERRQ(ierr); 2254efa14ee0SMatthew G Knepley break; 2255efa14ee0SMatthew G Knepley } 2256efa14ee0SMatthew G Knepley } 2257efa14ee0SMatthew G Knepley } 2258efa14ee0SMatthew G Knepley ierr = DMPlexGetSupportSize(dm, face, &supportSize);CHKERRQ(ierr); 2259efa14ee0SMatthew G Knepley ierr = DMPlexGetSupport(dm, face, &support);CHKERRQ(ierr); 2260efa14ee0SMatthew G Knepley for (s = 0; s < supportSize; ++s) { 2261efa14ee0SMatthew G Knepley ierr = DMLabelSetValue(subpointMap, support[s], dim);CHKERRQ(ierr); 2262efa14ee0SMatthew G Knepley } 2263efa14ee0SMatthew G Knepley } 2264efa14ee0SMatthew G Knepley ierr = DMPlexRestoreTransitiveClosure(dm, face, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 2265efa14ee0SMatthew G Knepley } 2266efa14ee0SMatthew G Knepley ierr = DMPlexRestoreTransitiveClosure(dm, vertex, PETSC_FALSE, &starSize, &star);CHKERRQ(ierr); 2267efa14ee0SMatthew G Knepley } 226834b4c39eSMatthew G. Knepley if (subvertexIS) {ierr = ISRestoreIndices(subvertexIS, &subvertices);CHKERRQ(ierr);} 2269efa14ee0SMatthew G Knepley ierr = ISDestroy(&subvertexIS);CHKERRQ(ierr); 2270efa14ee0SMatthew G Knepley ierr = PetscFree3(pStart,pEnd,pMax);CHKERRQ(ierr); 2271efa14ee0SMatthew G Knepley PetscFunctionReturn(0); 2272efa14ee0SMatthew G Knepley } 2273efa14ee0SMatthew G Knepley 227427c04023SMatthew G. Knepley static PetscErrorCode DMPlexMarkCohesiveSubmesh_Uninterpolated(DM dm, PetscBool hasLagrange, const char labelname[], PetscInt value, DMLabel subpointMap, PetscInt *numFaces, PetscInt *nFV, PetscInt *subCells[], DM subdm) 2275766ab985SMatthew G. Knepley { 227627c04023SMatthew G. Knepley DMLabel label = NULL; 2277766ab985SMatthew G. Knepley const PetscInt *cone; 22789fc93327SToby Isaac PetscInt dim, cMax, cEnd, c, subc = 0, p, coneSize = -1; 2279766ab985SMatthew G. Knepley PetscErrorCode ierr; 2280766ab985SMatthew G. Knepley 2281812bfc34SJed Brown PetscFunctionBegin; 2282c0ed958bSJed Brown *numFaces = 0; 2283c0ed958bSJed Brown *nFV = 0; 2284c58f1c22SToby Isaac if (labelname) {ierr = DMGetLabel(dm, labelname, &label);CHKERRQ(ierr);} 2285fed694aaSMatthew G. Knepley *subCells = NULL; 2286c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 2287766ab985SMatthew G. Knepley ierr = DMPlexGetHeightStratum(dm, 0, NULL, &cEnd);CHKERRQ(ierr); 2288766ab985SMatthew G. Knepley ierr = DMPlexGetHybridBounds(dm, &cMax, NULL, NULL, NULL);CHKERRQ(ierr); 2289766ab985SMatthew G. Knepley if (cMax < 0) PetscFunctionReturn(0); 229027c04023SMatthew G. Knepley if (label) { 229127c04023SMatthew G. Knepley for (c = cMax; c < cEnd; ++c) { 229227c04023SMatthew G. Knepley PetscInt val; 229327c04023SMatthew G. Knepley 229427c04023SMatthew G. Knepley ierr = DMLabelGetValue(label, c, &val);CHKERRQ(ierr); 229527c04023SMatthew G. Knepley if (val == value) { 229627c04023SMatthew G. Knepley ++(*numFaces); 229727c04023SMatthew G. Knepley ierr = DMPlexGetConeSize(dm, c, &coneSize);CHKERRQ(ierr); 229827c04023SMatthew G. Knepley } 229927c04023SMatthew G. Knepley } 230027c04023SMatthew G. Knepley } else { 2301766ab985SMatthew G. Knepley *numFaces = cEnd - cMax; 230227c04023SMatthew G. Knepley ierr = DMPlexGetConeSize(dm, cMax, &coneSize);CHKERRQ(ierr); 230327c04023SMatthew G. Knepley } 2304785e854fSJed Brown ierr = PetscMalloc1(*numFaces *2, subCells);CHKERRQ(ierr); 23059fc93327SToby Isaac if (!(*numFaces)) PetscFunctionReturn(0); 23069fc93327SToby Isaac *nFV = hasLagrange ? coneSize/3 : coneSize/2; 2307766ab985SMatthew G. Knepley for (c = cMax; c < cEnd; ++c) { 2308766ab985SMatthew G. Knepley const PetscInt *cells; 2309766ab985SMatthew G. Knepley PetscInt numCells; 2310766ab985SMatthew G. Knepley 231127c04023SMatthew G. Knepley if (label) { 231227c04023SMatthew G. Knepley PetscInt val; 231327c04023SMatthew G. Knepley 231427c04023SMatthew G. Knepley ierr = DMLabelGetValue(label, c, &val);CHKERRQ(ierr); 231527c04023SMatthew G. Knepley if (val != value) continue; 231627c04023SMatthew G. Knepley } 2317766ab985SMatthew G. Knepley ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr); 2318766ab985SMatthew G. Knepley for (p = 0; p < *nFV; ++p) { 2319766ab985SMatthew G. Knepley ierr = DMLabelSetValue(subpointMap, cone[p], 0);CHKERRQ(ierr); 2320766ab985SMatthew G. Knepley } 2321766ab985SMatthew G. Knepley /* Negative face */ 2322766ab985SMatthew G. Knepley ierr = DMPlexGetJoin(dm, *nFV, cone, &numCells, &cells);CHKERRQ(ierr); 232327234c99SMatthew G. Knepley /* Not true in parallel 232427234c99SMatthew G. Knepley if (numCells != 2) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Cohesive cells should separate two cells"); */ 2325766ab985SMatthew G. Knepley for (p = 0; p < numCells; ++p) { 2326766ab985SMatthew G. Knepley ierr = DMLabelSetValue(subpointMap, cells[p], 2);CHKERRQ(ierr); 232727234c99SMatthew G. Knepley (*subCells)[subc++] = cells[p]; 2328766ab985SMatthew G. Knepley } 2329766ab985SMatthew G. Knepley ierr = DMPlexRestoreJoin(dm, *nFV, cone, &numCells, &cells);CHKERRQ(ierr); 2330766ab985SMatthew G. Knepley /* Positive face is not included */ 2331766ab985SMatthew G. Knepley } 2332766ab985SMatthew G. Knepley PetscFunctionReturn(0); 2333766ab985SMatthew G. Knepley } 2334766ab985SMatthew G. Knepley 23353982b651SMatthew G. Knepley static PetscErrorCode DMPlexMarkCohesiveSubmesh_Interpolated(DM dm, DMLabel label, PetscInt value, DMLabel subpointMap, DM subdm) 2336766ab985SMatthew G. Knepley { 2337766ab985SMatthew G. Knepley PetscInt *pStart, *pEnd; 2338766ab985SMatthew G. Knepley PetscInt dim, cMax, cEnd, c, d; 2339766ab985SMatthew G. Knepley PetscErrorCode ierr; 2340766ab985SMatthew G. Knepley 2341812bfc34SJed Brown PetscFunctionBegin; 2342c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 2343766ab985SMatthew G. Knepley ierr = DMPlexGetHeightStratum(dm, 0, NULL, &cEnd);CHKERRQ(ierr); 2344766ab985SMatthew G. Knepley ierr = DMPlexGetHybridBounds(dm, &cMax, NULL, NULL, NULL);CHKERRQ(ierr); 2345766ab985SMatthew G. Knepley if (cMax < 0) PetscFunctionReturn(0); 2346dcca6d9dSJed Brown ierr = PetscMalloc2(dim+1,&pStart,dim+1,&pEnd);CHKERRQ(ierr); 2347b3154360SMatthew G. Knepley for (d = 0; d <= dim; ++d) {ierr = DMPlexGetDepthStratum(dm, d, &pStart[d], &pEnd[d]);CHKERRQ(ierr);} 2348766ab985SMatthew G. Knepley for (c = cMax; c < cEnd; ++c) { 2349766ab985SMatthew G. Knepley const PetscInt *cone; 2350766ab985SMatthew G. Knepley PetscInt *closure = NULL; 2351b3154360SMatthew G. Knepley PetscInt fconeSize, coneSize, closureSize, cl, val; 2352766ab985SMatthew G. Knepley 235327c04023SMatthew G. Knepley if (label) { 235427c04023SMatthew G. Knepley ierr = DMLabelGetValue(label, c, &val);CHKERRQ(ierr); 235527c04023SMatthew G. Knepley if (val != value) continue; 235627c04023SMatthew G. Knepley } 2357766ab985SMatthew G. Knepley ierr = DMPlexGetConeSize(dm, c, &coneSize);CHKERRQ(ierr); 2358766ab985SMatthew G. Knepley ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr); 2359b3154360SMatthew G. Knepley ierr = DMPlexGetConeSize(dm, cone[0], &fconeSize);CHKERRQ(ierr); 2360b3154360SMatthew G. Knepley if (coneSize != (fconeSize ? fconeSize : 1) + 2) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Cohesive cells should separate two cells"); 2361b3154360SMatthew G. Knepley /* Negative face */ 2362766ab985SMatthew G. Knepley ierr = DMPlexGetTransitiveClosure(dm, cone[0], PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 2363766ab985SMatthew G. Knepley for (cl = 0; cl < closureSize*2; cl += 2) { 2364766ab985SMatthew G. Knepley const PetscInt point = closure[cl]; 2365766ab985SMatthew G. Knepley 2366766ab985SMatthew G. Knepley for (d = 0; d <= dim; ++d) { 2367766ab985SMatthew G. Knepley if ((point >= pStart[d]) && (point < pEnd[d])) { 2368766ab985SMatthew G. Knepley ierr = DMLabelSetValue(subpointMap, point, d);CHKERRQ(ierr); 2369766ab985SMatthew G. Knepley break; 2370766ab985SMatthew G. Knepley } 2371766ab985SMatthew G. Knepley } 2372766ab985SMatthew G. Knepley } 2373766ab985SMatthew G. Knepley ierr = DMPlexRestoreTransitiveClosure(dm, cone[0], PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 2374766ab985SMatthew G. Knepley /* Cells -- positive face is not included */ 2375766ab985SMatthew G. Knepley for (cl = 0; cl < 1; ++cl) { 2376766ab985SMatthew G. Knepley const PetscInt *support; 2377766ab985SMatthew G. Knepley PetscInt supportSize, s; 2378766ab985SMatthew G. Knepley 2379766ab985SMatthew G. Knepley ierr = DMPlexGetSupportSize(dm, cone[cl], &supportSize);CHKERRQ(ierr); 2380711de394SMatthew G. Knepley /* if (supportSize != 2) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Cohesive faces should separate two cells"); */ 2381766ab985SMatthew G. Knepley ierr = DMPlexGetSupport(dm, cone[cl], &support);CHKERRQ(ierr); 2382766ab985SMatthew G. Knepley for (s = 0; s < supportSize; ++s) { 2383766ab985SMatthew G. Knepley ierr = DMLabelSetValue(subpointMap, support[s], dim);CHKERRQ(ierr); 2384766ab985SMatthew G. Knepley } 2385766ab985SMatthew G. Knepley } 2386766ab985SMatthew G. Knepley } 2387766ab985SMatthew G. Knepley ierr = PetscFree2(pStart, pEnd);CHKERRQ(ierr); 2388766ab985SMatthew G. Knepley PetscFunctionReturn(0); 2389766ab985SMatthew G. Knepley } 2390766ab985SMatthew G. Knepley 2391c08575a3SMatthew G. Knepley static PetscErrorCode DMPlexGetFaceOrientation(DM dm, PetscInt cell, PetscInt numCorners, PetscInt indices[], PetscInt oppositeVertex, PetscInt origVertices[], PetscInt faceVertices[], PetscBool *posOriented) 2392e6ccafaeSMatthew G Knepley { 239382f516ccSBarry Smith MPI_Comm comm; 2394e6ccafaeSMatthew G Knepley PetscBool posOrient = PETSC_FALSE; 2395e6ccafaeSMatthew G Knepley const PetscInt debug = 0; 2396e6ccafaeSMatthew G Knepley PetscInt cellDim, faceSize, f; 2397e6ccafaeSMatthew G Knepley PetscErrorCode ierr; 2398e6ccafaeSMatthew G Knepley 239982f516ccSBarry Smith PetscFunctionBegin; 240082f516ccSBarry Smith ierr = PetscObjectGetComm((PetscObject)dm,&comm);CHKERRQ(ierr); 2401c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &cellDim);CHKERRQ(ierr); 2402367003a6SStefano Zampini if (debug) {ierr = PetscPrintf(comm, "cellDim: %d numCorners: %d\n", cellDim, numCorners);CHKERRQ(ierr);} 2403e6ccafaeSMatthew G Knepley 2404ddeab2a6SMatthew G. Knepley if (cellDim == 1 && numCorners == 2) { 2405ddeab2a6SMatthew G. Knepley /* Triangle */ 2406e6ccafaeSMatthew G Knepley faceSize = numCorners-1; 2407e6ccafaeSMatthew G Knepley posOrient = !(oppositeVertex%2) ? PETSC_TRUE : PETSC_FALSE; 2408ddeab2a6SMatthew G. Knepley } else if (cellDim == 2 && numCorners == 3) { 2409ddeab2a6SMatthew G. Knepley /* Triangle */ 2410ddeab2a6SMatthew G. Knepley faceSize = numCorners-1; 2411ddeab2a6SMatthew G. Knepley posOrient = !(oppositeVertex%2) ? PETSC_TRUE : PETSC_FALSE; 2412ddeab2a6SMatthew G. Knepley } else if (cellDim == 3 && numCorners == 4) { 2413ddeab2a6SMatthew G. Knepley /* Tetrahedron */ 2414ddeab2a6SMatthew G. Knepley faceSize = numCorners-1; 2415ddeab2a6SMatthew G. Knepley posOrient = (oppositeVertex%2) ? PETSC_TRUE : PETSC_FALSE; 2416e6ccafaeSMatthew G Knepley } else if (cellDim == 1 && numCorners == 3) { 2417e6ccafaeSMatthew G Knepley /* Quadratic line */ 2418e6ccafaeSMatthew G Knepley faceSize = 1; 2419e6ccafaeSMatthew G Knepley posOrient = PETSC_TRUE; 2420e6ccafaeSMatthew G Knepley } else if (cellDim == 2 && numCorners == 4) { 2421e6ccafaeSMatthew G Knepley /* Quads */ 2422e6ccafaeSMatthew G Knepley faceSize = 2; 2423e6ccafaeSMatthew G Knepley if ((indices[1] > indices[0]) && (indices[1] - indices[0] == 1)) { 2424e6ccafaeSMatthew G Knepley posOrient = PETSC_TRUE; 2425e6ccafaeSMatthew G Knepley } else if ((indices[0] == 3) && (indices[1] == 0)) { 2426e6ccafaeSMatthew G Knepley posOrient = PETSC_TRUE; 2427e6ccafaeSMatthew G Knepley } else { 2428e6ccafaeSMatthew G Knepley if (((indices[0] > indices[1]) && (indices[0] - indices[1] == 1)) || ((indices[0] == 0) && (indices[1] == 3))) { 2429e6ccafaeSMatthew G Knepley posOrient = PETSC_FALSE; 2430e6ccafaeSMatthew G Knepley } else SETERRQ(comm, PETSC_ERR_ARG_WRONG, "Invalid quad crossedge"); 2431e6ccafaeSMatthew G Knepley } 2432e6ccafaeSMatthew G Knepley } else if (cellDim == 2 && numCorners == 6) { 2433e6ccafaeSMatthew G Knepley /* Quadratic triangle (I hate this) */ 2434e6ccafaeSMatthew G Knepley /* Edges are determined by the first 2 vertices (corners of edges) */ 2435e6ccafaeSMatthew G Knepley const PetscInt faceSizeTri = 3; 2436e6ccafaeSMatthew G Knepley PetscInt sortedIndices[3], i, iFace; 2437e6ccafaeSMatthew G Knepley PetscBool found = PETSC_FALSE; 2438e6ccafaeSMatthew G Knepley PetscInt faceVerticesTriSorted[9] = { 2439e6ccafaeSMatthew G Knepley 0, 3, 4, /* bottom */ 2440e6ccafaeSMatthew G Knepley 1, 4, 5, /* right */ 2441e6ccafaeSMatthew G Knepley 2, 3, 5, /* left */ 2442e6ccafaeSMatthew G Knepley }; 2443e6ccafaeSMatthew G Knepley PetscInt faceVerticesTri[9] = { 2444e6ccafaeSMatthew G Knepley 0, 3, 4, /* bottom */ 2445e6ccafaeSMatthew G Knepley 1, 4, 5, /* right */ 2446e6ccafaeSMatthew G Knepley 2, 5, 3, /* left */ 2447e6ccafaeSMatthew G Knepley }; 2448e6ccafaeSMatthew G Knepley 2449e6ccafaeSMatthew G Knepley for (i = 0; i < faceSizeTri; ++i) sortedIndices[i] = indices[i]; 2450e6ccafaeSMatthew G Knepley ierr = PetscSortInt(faceSizeTri, sortedIndices);CHKERRQ(ierr); 2451e6ccafaeSMatthew G Knepley for (iFace = 0; iFace < 3; ++iFace) { 2452e6ccafaeSMatthew G Knepley const PetscInt ii = iFace*faceSizeTri; 2453e6ccafaeSMatthew G Knepley PetscInt fVertex, cVertex; 2454e6ccafaeSMatthew G Knepley 2455e6ccafaeSMatthew G Knepley if ((sortedIndices[0] == faceVerticesTriSorted[ii+0]) && 2456e6ccafaeSMatthew G Knepley (sortedIndices[1] == faceVerticesTriSorted[ii+1])) { 2457e6ccafaeSMatthew G Knepley for (fVertex = 0; fVertex < faceSizeTri; ++fVertex) { 2458e6ccafaeSMatthew G Knepley for (cVertex = 0; cVertex < faceSizeTri; ++cVertex) { 2459e6ccafaeSMatthew G Knepley if (indices[cVertex] == faceVerticesTri[ii+fVertex]) { 2460e6ccafaeSMatthew G Knepley faceVertices[fVertex] = origVertices[cVertex]; 2461e6ccafaeSMatthew G Knepley break; 2462e6ccafaeSMatthew G Knepley } 2463e6ccafaeSMatthew G Knepley } 2464e6ccafaeSMatthew G Knepley } 2465e6ccafaeSMatthew G Knepley found = PETSC_TRUE; 2466e6ccafaeSMatthew G Knepley break; 2467e6ccafaeSMatthew G Knepley } 2468e6ccafaeSMatthew G Knepley } 2469e6ccafaeSMatthew G Knepley if (!found) SETERRQ(comm, PETSC_ERR_ARG_WRONG, "Invalid tri crossface"); 2470e6ccafaeSMatthew G Knepley if (posOriented) *posOriented = PETSC_TRUE; 2471e6ccafaeSMatthew G Knepley PetscFunctionReturn(0); 2472e6ccafaeSMatthew G Knepley } else if (cellDim == 2 && numCorners == 9) { 2473e6ccafaeSMatthew G Knepley /* Quadratic quad (I hate this) */ 2474e6ccafaeSMatthew G Knepley /* Edges are determined by the first 2 vertices (corners of edges) */ 2475e6ccafaeSMatthew G Knepley const PetscInt faceSizeQuad = 3; 2476e6ccafaeSMatthew G Knepley PetscInt sortedIndices[3], i, iFace; 2477e6ccafaeSMatthew G Knepley PetscBool found = PETSC_FALSE; 2478e6ccafaeSMatthew G Knepley PetscInt faceVerticesQuadSorted[12] = { 2479e6ccafaeSMatthew G Knepley 0, 1, 4, /* bottom */ 2480e6ccafaeSMatthew G Knepley 1, 2, 5, /* right */ 2481e6ccafaeSMatthew G Knepley 2, 3, 6, /* top */ 2482e6ccafaeSMatthew G Knepley 0, 3, 7, /* left */ 2483e6ccafaeSMatthew G Knepley }; 2484e6ccafaeSMatthew G Knepley PetscInt faceVerticesQuad[12] = { 2485e6ccafaeSMatthew G Knepley 0, 1, 4, /* bottom */ 2486e6ccafaeSMatthew G Knepley 1, 2, 5, /* right */ 2487e6ccafaeSMatthew G Knepley 2, 3, 6, /* top */ 2488e6ccafaeSMatthew G Knepley 3, 0, 7, /* left */ 2489e6ccafaeSMatthew G Knepley }; 2490e6ccafaeSMatthew G Knepley 2491e6ccafaeSMatthew G Knepley for (i = 0; i < faceSizeQuad; ++i) sortedIndices[i] = indices[i]; 2492e6ccafaeSMatthew G Knepley ierr = PetscSortInt(faceSizeQuad, sortedIndices);CHKERRQ(ierr); 2493e6ccafaeSMatthew G Knepley for (iFace = 0; iFace < 4; ++iFace) { 2494e6ccafaeSMatthew G Knepley const PetscInt ii = iFace*faceSizeQuad; 2495e6ccafaeSMatthew G Knepley PetscInt fVertex, cVertex; 2496e6ccafaeSMatthew G Knepley 2497e6ccafaeSMatthew G Knepley if ((sortedIndices[0] == faceVerticesQuadSorted[ii+0]) && 2498e6ccafaeSMatthew G Knepley (sortedIndices[1] == faceVerticesQuadSorted[ii+1])) { 2499e6ccafaeSMatthew G Knepley for (fVertex = 0; fVertex < faceSizeQuad; ++fVertex) { 2500e6ccafaeSMatthew G Knepley for (cVertex = 0; cVertex < faceSizeQuad; ++cVertex) { 2501e6ccafaeSMatthew G Knepley if (indices[cVertex] == faceVerticesQuad[ii+fVertex]) { 2502e6ccafaeSMatthew G Knepley faceVertices[fVertex] = origVertices[cVertex]; 2503e6ccafaeSMatthew G Knepley break; 2504e6ccafaeSMatthew G Knepley } 2505e6ccafaeSMatthew G Knepley } 2506e6ccafaeSMatthew G Knepley } 2507e6ccafaeSMatthew G Knepley found = PETSC_TRUE; 2508e6ccafaeSMatthew G Knepley break; 2509e6ccafaeSMatthew G Knepley } 2510e6ccafaeSMatthew G Knepley } 2511e6ccafaeSMatthew G Knepley if (!found) SETERRQ(comm, PETSC_ERR_ARG_WRONG, "Invalid quad crossface"); 2512e6ccafaeSMatthew G Knepley if (posOriented) *posOriented = PETSC_TRUE; 2513e6ccafaeSMatthew G Knepley PetscFunctionReturn(0); 2514e6ccafaeSMatthew G Knepley } else if (cellDim == 3 && numCorners == 8) { 2515e6ccafaeSMatthew G Knepley /* Hexes 2516e6ccafaeSMatthew G Knepley A hex is two oriented quads with the normal of the first 2517e6ccafaeSMatthew G Knepley pointing up at the second. 2518e6ccafaeSMatthew G Knepley 2519e6ccafaeSMatthew G Knepley 7---6 2520e6ccafaeSMatthew G Knepley /| /| 2521e6ccafaeSMatthew G Knepley 4---5 | 2522ddeab2a6SMatthew G. Knepley | 1-|-2 2523e6ccafaeSMatthew G Knepley |/ |/ 2524ddeab2a6SMatthew G. Knepley 0---3 2525e6ccafaeSMatthew G Knepley 2526e6ccafaeSMatthew G Knepley Faces are determined by the first 4 vertices (corners of faces) */ 2527e6ccafaeSMatthew G Knepley const PetscInt faceSizeHex = 4; 2528e6ccafaeSMatthew G Knepley PetscInt sortedIndices[4], i, iFace; 2529e6ccafaeSMatthew G Knepley PetscBool found = PETSC_FALSE; 2530e6ccafaeSMatthew G Knepley PetscInt faceVerticesHexSorted[24] = { 2531e6ccafaeSMatthew G Knepley 0, 1, 2, 3, /* bottom */ 2532e6ccafaeSMatthew G Knepley 4, 5, 6, 7, /* top */ 2533ddeab2a6SMatthew G. Knepley 0, 3, 4, 5, /* front */ 2534ddeab2a6SMatthew G. Knepley 2, 3, 5, 6, /* right */ 2535ddeab2a6SMatthew G. Knepley 1, 2, 6, 7, /* back */ 2536ddeab2a6SMatthew G. Knepley 0, 1, 4, 7, /* left */ 2537e6ccafaeSMatthew G Knepley }; 2538e6ccafaeSMatthew G Knepley PetscInt faceVerticesHex[24] = { 2539ddeab2a6SMatthew G. Knepley 1, 2, 3, 0, /* bottom */ 2540e6ccafaeSMatthew G Knepley 4, 5, 6, 7, /* top */ 2541ddeab2a6SMatthew G. Knepley 0, 3, 5, 4, /* front */ 2542ddeab2a6SMatthew G. Knepley 3, 2, 6, 5, /* right */ 2543ddeab2a6SMatthew G. Knepley 2, 1, 7, 6, /* back */ 2544ddeab2a6SMatthew G. Knepley 1, 0, 4, 7, /* left */ 2545e6ccafaeSMatthew G Knepley }; 2546e6ccafaeSMatthew G Knepley 2547e6ccafaeSMatthew G Knepley for (i = 0; i < faceSizeHex; ++i) sortedIndices[i] = indices[i]; 2548e6ccafaeSMatthew G Knepley ierr = PetscSortInt(faceSizeHex, sortedIndices);CHKERRQ(ierr); 2549e6ccafaeSMatthew G Knepley for (iFace = 0; iFace < 6; ++iFace) { 2550e6ccafaeSMatthew G Knepley const PetscInt ii = iFace*faceSizeHex; 2551e6ccafaeSMatthew G Knepley PetscInt fVertex, cVertex; 2552e6ccafaeSMatthew G Knepley 2553e6ccafaeSMatthew G Knepley if ((sortedIndices[0] == faceVerticesHexSorted[ii+0]) && 2554e6ccafaeSMatthew G Knepley (sortedIndices[1] == faceVerticesHexSorted[ii+1]) && 2555e6ccafaeSMatthew G Knepley (sortedIndices[2] == faceVerticesHexSorted[ii+2]) && 2556e6ccafaeSMatthew G Knepley (sortedIndices[3] == faceVerticesHexSorted[ii+3])) { 2557e6ccafaeSMatthew G Knepley for (fVertex = 0; fVertex < faceSizeHex; ++fVertex) { 2558e6ccafaeSMatthew G Knepley for (cVertex = 0; cVertex < faceSizeHex; ++cVertex) { 2559e6ccafaeSMatthew G Knepley if (indices[cVertex] == faceVerticesHex[ii+fVertex]) { 2560e6ccafaeSMatthew G Knepley faceVertices[fVertex] = origVertices[cVertex]; 2561e6ccafaeSMatthew G Knepley break; 2562e6ccafaeSMatthew G Knepley } 2563e6ccafaeSMatthew G Knepley } 2564e6ccafaeSMatthew G Knepley } 2565e6ccafaeSMatthew G Knepley found = PETSC_TRUE; 2566e6ccafaeSMatthew G Knepley break; 2567e6ccafaeSMatthew G Knepley } 2568e6ccafaeSMatthew G Knepley } 2569e6ccafaeSMatthew G Knepley if (!found) SETERRQ(comm, PETSC_ERR_ARG_WRONG, "Invalid hex crossface"); 2570e6ccafaeSMatthew G Knepley if (posOriented) *posOriented = PETSC_TRUE; 2571e6ccafaeSMatthew G Knepley PetscFunctionReturn(0); 2572e6ccafaeSMatthew G Knepley } else if (cellDim == 3 && numCorners == 10) { 2573e6ccafaeSMatthew G Knepley /* Quadratic tet */ 2574e6ccafaeSMatthew G Knepley /* Faces are determined by the first 3 vertices (corners of faces) */ 2575e6ccafaeSMatthew G Knepley const PetscInt faceSizeTet = 6; 2576e6ccafaeSMatthew G Knepley PetscInt sortedIndices[6], i, iFace; 2577e6ccafaeSMatthew G Knepley PetscBool found = PETSC_FALSE; 2578e6ccafaeSMatthew G Knepley PetscInt faceVerticesTetSorted[24] = { 2579e6ccafaeSMatthew G Knepley 0, 1, 2, 6, 7, 8, /* bottom */ 2580e6ccafaeSMatthew G Knepley 0, 3, 4, 6, 7, 9, /* front */ 2581e6ccafaeSMatthew G Knepley 1, 4, 5, 7, 8, 9, /* right */ 2582e6ccafaeSMatthew G Knepley 2, 3, 5, 6, 8, 9, /* left */ 2583e6ccafaeSMatthew G Knepley }; 2584e6ccafaeSMatthew G Knepley PetscInt faceVerticesTet[24] = { 2585e6ccafaeSMatthew G Knepley 0, 1, 2, 6, 7, 8, /* bottom */ 2586e6ccafaeSMatthew G Knepley 0, 4, 3, 6, 7, 9, /* front */ 2587e6ccafaeSMatthew G Knepley 1, 5, 4, 7, 8, 9, /* right */ 2588e6ccafaeSMatthew G Knepley 2, 3, 5, 8, 6, 9, /* left */ 2589e6ccafaeSMatthew G Knepley }; 2590e6ccafaeSMatthew G Knepley 2591e6ccafaeSMatthew G Knepley for (i = 0; i < faceSizeTet; ++i) sortedIndices[i] = indices[i]; 2592e6ccafaeSMatthew G Knepley ierr = PetscSortInt(faceSizeTet, sortedIndices);CHKERRQ(ierr); 2593e6ccafaeSMatthew G Knepley for (iFace=0; iFace < 4; ++iFace) { 2594e6ccafaeSMatthew G Knepley const PetscInt ii = iFace*faceSizeTet; 2595e6ccafaeSMatthew G Knepley PetscInt fVertex, cVertex; 2596e6ccafaeSMatthew G Knepley 2597e6ccafaeSMatthew G Knepley if ((sortedIndices[0] == faceVerticesTetSorted[ii+0]) && 2598e6ccafaeSMatthew G Knepley (sortedIndices[1] == faceVerticesTetSorted[ii+1]) && 2599e6ccafaeSMatthew G Knepley (sortedIndices[2] == faceVerticesTetSorted[ii+2]) && 2600e6ccafaeSMatthew G Knepley (sortedIndices[3] == faceVerticesTetSorted[ii+3])) { 2601e6ccafaeSMatthew G Knepley for (fVertex = 0; fVertex < faceSizeTet; ++fVertex) { 2602e6ccafaeSMatthew G Knepley for (cVertex = 0; cVertex < faceSizeTet; ++cVertex) { 2603e6ccafaeSMatthew G Knepley if (indices[cVertex] == faceVerticesTet[ii+fVertex]) { 2604e6ccafaeSMatthew G Knepley faceVertices[fVertex] = origVertices[cVertex]; 2605e6ccafaeSMatthew G Knepley break; 2606e6ccafaeSMatthew G Knepley } 2607e6ccafaeSMatthew G Knepley } 2608e6ccafaeSMatthew G Knepley } 2609e6ccafaeSMatthew G Knepley found = PETSC_TRUE; 2610e6ccafaeSMatthew G Knepley break; 2611e6ccafaeSMatthew G Knepley } 2612e6ccafaeSMatthew G Knepley } 2613e6ccafaeSMatthew G Knepley if (!found) SETERRQ(comm, PETSC_ERR_ARG_WRONG, "Invalid tet crossface"); 2614e6ccafaeSMatthew G Knepley if (posOriented) *posOriented = PETSC_TRUE; 2615e6ccafaeSMatthew G Knepley PetscFunctionReturn(0); 2616e6ccafaeSMatthew G Knepley } else if (cellDim == 3 && numCorners == 27) { 2617e6ccafaeSMatthew G Knepley /* Quadratic hexes (I hate this) 2618e6ccafaeSMatthew G Knepley A hex is two oriented quads with the normal of the first 2619e6ccafaeSMatthew G Knepley pointing up at the second. 2620e6ccafaeSMatthew G Knepley 2621e6ccafaeSMatthew G Knepley 7---6 2622e6ccafaeSMatthew G Knepley /| /| 2623e6ccafaeSMatthew G Knepley 4---5 | 2624e6ccafaeSMatthew G Knepley | 3-|-2 2625e6ccafaeSMatthew G Knepley |/ |/ 2626e6ccafaeSMatthew G Knepley 0---1 2627e6ccafaeSMatthew G Knepley 2628e6ccafaeSMatthew G Knepley Faces are determined by the first 4 vertices (corners of faces) */ 2629e6ccafaeSMatthew G Knepley const PetscInt faceSizeQuadHex = 9; 2630e6ccafaeSMatthew G Knepley PetscInt sortedIndices[9], i, iFace; 2631e6ccafaeSMatthew G Knepley PetscBool found = PETSC_FALSE; 2632e6ccafaeSMatthew G Knepley PetscInt faceVerticesQuadHexSorted[54] = { 2633e6ccafaeSMatthew G Knepley 0, 1, 2, 3, 8, 9, 10, 11, 24, /* bottom */ 2634e6ccafaeSMatthew G Knepley 4, 5, 6, 7, 12, 13, 14, 15, 25, /* top */ 2635e6ccafaeSMatthew G Knepley 0, 1, 4, 5, 8, 12, 16, 17, 22, /* front */ 2636e6ccafaeSMatthew G Knepley 1, 2, 5, 6, 9, 13, 17, 18, 21, /* right */ 2637e6ccafaeSMatthew G Knepley 2, 3, 6, 7, 10, 14, 18, 19, 23, /* back */ 2638e6ccafaeSMatthew G Knepley 0, 3, 4, 7, 11, 15, 16, 19, 20, /* left */ 2639e6ccafaeSMatthew G Knepley }; 2640e6ccafaeSMatthew G Knepley PetscInt faceVerticesQuadHex[54] = { 2641e6ccafaeSMatthew G Knepley 3, 2, 1, 0, 10, 9, 8, 11, 24, /* bottom */ 2642e6ccafaeSMatthew G Knepley 4, 5, 6, 7, 12, 13, 14, 15, 25, /* top */ 2643e6ccafaeSMatthew G Knepley 0, 1, 5, 4, 8, 17, 12, 16, 22, /* front */ 2644e6ccafaeSMatthew G Knepley 1, 2, 6, 5, 9, 18, 13, 17, 21, /* right */ 2645e6ccafaeSMatthew G Knepley 2, 3, 7, 6, 10, 19, 14, 18, 23, /* back */ 2646e6ccafaeSMatthew G Knepley 3, 0, 4, 7, 11, 16, 15, 19, 20 /* left */ 2647e6ccafaeSMatthew G Knepley }; 2648e6ccafaeSMatthew G Knepley 2649e6ccafaeSMatthew G Knepley for (i = 0; i < faceSizeQuadHex; ++i) sortedIndices[i] = indices[i]; 2650e6ccafaeSMatthew G Knepley ierr = PetscSortInt(faceSizeQuadHex, sortedIndices);CHKERRQ(ierr); 2651e6ccafaeSMatthew G Knepley for (iFace = 0; iFace < 6; ++iFace) { 2652e6ccafaeSMatthew G Knepley const PetscInt ii = iFace*faceSizeQuadHex; 2653e6ccafaeSMatthew G Knepley PetscInt fVertex, cVertex; 2654e6ccafaeSMatthew G Knepley 2655e6ccafaeSMatthew G Knepley if ((sortedIndices[0] == faceVerticesQuadHexSorted[ii+0]) && 2656e6ccafaeSMatthew G Knepley (sortedIndices[1] == faceVerticesQuadHexSorted[ii+1]) && 2657e6ccafaeSMatthew G Knepley (sortedIndices[2] == faceVerticesQuadHexSorted[ii+2]) && 2658e6ccafaeSMatthew G Knepley (sortedIndices[3] == faceVerticesQuadHexSorted[ii+3])) { 2659e6ccafaeSMatthew G Knepley for (fVertex = 0; fVertex < faceSizeQuadHex; ++fVertex) { 2660e6ccafaeSMatthew G Knepley for (cVertex = 0; cVertex < faceSizeQuadHex; ++cVertex) { 2661e6ccafaeSMatthew G Knepley if (indices[cVertex] == faceVerticesQuadHex[ii+fVertex]) { 2662e6ccafaeSMatthew G Knepley faceVertices[fVertex] = origVertices[cVertex]; 2663e6ccafaeSMatthew G Knepley break; 2664e6ccafaeSMatthew G Knepley } 2665e6ccafaeSMatthew G Knepley } 2666e6ccafaeSMatthew G Knepley } 2667e6ccafaeSMatthew G Knepley found = PETSC_TRUE; 2668e6ccafaeSMatthew G Knepley break; 2669e6ccafaeSMatthew G Knepley } 2670e6ccafaeSMatthew G Knepley } 2671e6ccafaeSMatthew G Knepley if (!found) SETERRQ(comm, PETSC_ERR_ARG_WRONG, "Invalid hex crossface"); 2672e6ccafaeSMatthew G Knepley if (posOriented) *posOriented = PETSC_TRUE; 2673e6ccafaeSMatthew G Knepley PetscFunctionReturn(0); 2674e6ccafaeSMatthew G Knepley } else SETERRQ(comm, PETSC_ERR_ARG_WRONG, "Unknown cell type for faceOrientation()."); 2675e6ccafaeSMatthew G Knepley if (!posOrient) { 2676e6ccafaeSMatthew G Knepley if (debug) {ierr = PetscPrintf(comm, " Reversing initial face orientation\n");CHKERRQ(ierr);} 2677e6ccafaeSMatthew G Knepley for (f = 0; f < faceSize; ++f) faceVertices[f] = origVertices[faceSize-1 - f]; 2678e6ccafaeSMatthew G Knepley } else { 2679e6ccafaeSMatthew G Knepley if (debug) {ierr = PetscPrintf(comm, " Keeping initial face orientation\n");CHKERRQ(ierr);} 2680e6ccafaeSMatthew G Knepley for (f = 0; f < faceSize; ++f) faceVertices[f] = origVertices[f]; 2681e6ccafaeSMatthew G Knepley } 2682e6ccafaeSMatthew G Knepley if (posOriented) *posOriented = posOrient; 2683e6ccafaeSMatthew G Knepley PetscFunctionReturn(0); 2684e6ccafaeSMatthew G Knepley } 2685e6ccafaeSMatthew G Knepley 2686c08575a3SMatthew G. Knepley /*@ 2687c08575a3SMatthew G. Knepley DMPlexGetOrientedFace - Given a cell and a face, as a set of vertices, return the oriented face, as a set of vertices, 2688c08575a3SMatthew G. Knepley in faceVertices. The orientation is such that the face normal points out of the cell 2689c08575a3SMatthew G. Knepley 2690c08575a3SMatthew G. Knepley Not collective 2691c08575a3SMatthew G. Knepley 2692c08575a3SMatthew G. Knepley Input Parameters: 2693c08575a3SMatthew G. Knepley + dm - The original mesh 2694c08575a3SMatthew G. Knepley . cell - The cell mesh point 2695c08575a3SMatthew G. Knepley . faceSize - The number of vertices on the face 2696c08575a3SMatthew G. Knepley . face - The face vertices 2697c08575a3SMatthew G. Knepley . numCorners - The number of vertices on the cell 2698c08575a3SMatthew G. Knepley . indices - Local numbering of face vertices in cell cone 2699c08575a3SMatthew G. Knepley - origVertices - Original face vertices 2700c08575a3SMatthew G. Knepley 2701c08575a3SMatthew G. Knepley Output Parameter: 2702c08575a3SMatthew G. Knepley + faceVertices - The face vertices properly oriented 2703c08575a3SMatthew G. Knepley - posOriented - PETSC_TRUE if the face was oriented with outward normal 2704c08575a3SMatthew G. Knepley 2705c08575a3SMatthew G. Knepley Level: developer 2706c08575a3SMatthew G. Knepley 2707c08575a3SMatthew G. Knepley .seealso: DMPlexGetCone() 2708c08575a3SMatthew G. Knepley @*/ 2709e6ccafaeSMatthew G Knepley PetscErrorCode DMPlexGetOrientedFace(DM dm, PetscInt cell, PetscInt faceSize, const PetscInt face[], PetscInt numCorners, PetscInt indices[], PetscInt origVertices[], PetscInt faceVertices[], PetscBool *posOriented) 2710e6ccafaeSMatthew G Knepley { 27110298fd71SBarry Smith const PetscInt *cone = NULL; 2712e6ccafaeSMatthew G Knepley PetscInt coneSize, v, f, v2; 2713e6ccafaeSMatthew G Knepley PetscInt oppositeVertex = -1; 2714e6ccafaeSMatthew G Knepley PetscErrorCode ierr; 2715e6ccafaeSMatthew G Knepley 2716e6ccafaeSMatthew G Knepley PetscFunctionBegin; 2717e6ccafaeSMatthew G Knepley ierr = DMPlexGetConeSize(dm, cell, &coneSize);CHKERRQ(ierr); 2718e6ccafaeSMatthew G Knepley ierr = DMPlexGetCone(dm, cell, &cone);CHKERRQ(ierr); 2719e6ccafaeSMatthew G Knepley for (v = 0, v2 = 0; v < coneSize; ++v) { 2720e6ccafaeSMatthew G Knepley PetscBool found = PETSC_FALSE; 2721e6ccafaeSMatthew G Knepley 2722e6ccafaeSMatthew G Knepley for (f = 0; f < faceSize; ++f) { 2723e6ccafaeSMatthew G Knepley if (face[f] == cone[v]) { 2724e6ccafaeSMatthew G Knepley found = PETSC_TRUE; break; 2725e6ccafaeSMatthew G Knepley } 2726e6ccafaeSMatthew G Knepley } 2727e6ccafaeSMatthew G Knepley if (found) { 2728e6ccafaeSMatthew G Knepley indices[v2] = v; 2729e6ccafaeSMatthew G Knepley origVertices[v2] = cone[v]; 2730e6ccafaeSMatthew G Knepley ++v2; 2731e6ccafaeSMatthew G Knepley } else { 2732e6ccafaeSMatthew G Knepley oppositeVertex = v; 2733e6ccafaeSMatthew G Knepley } 2734e6ccafaeSMatthew G Knepley } 2735e6ccafaeSMatthew G Knepley ierr = DMPlexGetFaceOrientation(dm, cell, numCorners, indices, oppositeVertex, origVertices, faceVertices, posOriented);CHKERRQ(ierr); 2736e6ccafaeSMatthew G Knepley PetscFunctionReturn(0); 2737e6ccafaeSMatthew G Knepley } 2738e6ccafaeSMatthew G Knepley 2739e6ccafaeSMatthew G Knepley /* 2740cd0c2139SMatthew G Knepley DMPlexInsertFace_Internal - Puts a face into the mesh 2741e6ccafaeSMatthew G Knepley 2742e6ccafaeSMatthew G Knepley Not collective 2743e6ccafaeSMatthew G Knepley 2744e6ccafaeSMatthew G Knepley Input Parameters: 2745e6ccafaeSMatthew G Knepley + dm - The DMPlex 2746e6ccafaeSMatthew G Knepley . numFaceVertex - The number of vertices in the face 2747e6ccafaeSMatthew G Knepley . faceVertices - The vertices in the face for dm 2748e6ccafaeSMatthew G Knepley . subfaceVertices - The vertices in the face for subdm 2749e6ccafaeSMatthew G Knepley . numCorners - The number of vertices in the cell 2750e6ccafaeSMatthew G Knepley . cell - A cell in dm containing the face 2751e6ccafaeSMatthew G Knepley . subcell - A cell in subdm containing the face 2752e6ccafaeSMatthew G Knepley . firstFace - First face in the mesh 2753e6ccafaeSMatthew G Knepley - newFacePoint - Next face in the mesh 2754e6ccafaeSMatthew G Knepley 2755e6ccafaeSMatthew G Knepley Output Parameters: 2756e6ccafaeSMatthew G Knepley . newFacePoint - Contains next face point number on input, updated on output 2757e6ccafaeSMatthew G Knepley 2758e6ccafaeSMatthew G Knepley Level: developer 2759e6ccafaeSMatthew G Knepley */ 2760cd0c2139SMatthew G Knepley static PetscErrorCode DMPlexInsertFace_Internal(DM dm, DM subdm, PetscInt numFaceVertices, const PetscInt faceVertices[], const PetscInt subfaceVertices[], PetscInt numCorners, PetscInt cell, PetscInt subcell, PetscInt firstFace, PetscInt *newFacePoint) 2761e6ccafaeSMatthew G Knepley { 276282f516ccSBarry Smith MPI_Comm comm; 2763e6ccafaeSMatthew G Knepley DM_Plex *submesh = (DM_Plex*) subdm->data; 2764e6ccafaeSMatthew G Knepley const PetscInt *faces; 2765e6ccafaeSMatthew G Knepley PetscInt numFaces, coneSize; 2766e6ccafaeSMatthew G Knepley PetscErrorCode ierr; 2767e6ccafaeSMatthew G Knepley 2768e6ccafaeSMatthew G Knepley PetscFunctionBegin; 276982f516ccSBarry Smith ierr = PetscObjectGetComm((PetscObject)dm,&comm);CHKERRQ(ierr); 2770e6ccafaeSMatthew G Knepley ierr = DMPlexGetConeSize(subdm, subcell, &coneSize);CHKERRQ(ierr); 2771e6ccafaeSMatthew G Knepley if (coneSize != 1) SETERRQ2(comm, PETSC_ERR_ARG_OUTOFRANGE, "Cone size of cell %d is %d != 1", cell, coneSize); 2772e6ccafaeSMatthew G Knepley #if 0 2773e6ccafaeSMatthew G Knepley /* Cannot use this because support() has not been constructed yet */ 2774e6ccafaeSMatthew G Knepley ierr = DMPlexGetJoin(subdm, numFaceVertices, subfaceVertices, &numFaces, &faces);CHKERRQ(ierr); 2775e6ccafaeSMatthew G Knepley #else 2776e6ccafaeSMatthew G Knepley { 2777e6ccafaeSMatthew G Knepley PetscInt f; 2778e6ccafaeSMatthew G Knepley 2779e6ccafaeSMatthew G Knepley numFaces = 0; 278069291d52SBarry Smith ierr = DMGetWorkArray(subdm, 1, MPIU_INT, (void **) &faces);CHKERRQ(ierr); 2781e6ccafaeSMatthew G Knepley for (f = firstFace; f < *newFacePoint; ++f) { 2782e6ccafaeSMatthew G Knepley PetscInt dof, off, d; 2783e6ccafaeSMatthew G Knepley 2784e6ccafaeSMatthew G Knepley ierr = PetscSectionGetDof(submesh->coneSection, f, &dof);CHKERRQ(ierr); 2785e6ccafaeSMatthew G Knepley ierr = PetscSectionGetOffset(submesh->coneSection, f, &off);CHKERRQ(ierr); 2786e6ccafaeSMatthew G Knepley /* Yes, I know this is quadratic, but I expect the sizes to be <5 */ 2787e6ccafaeSMatthew G Knepley for (d = 0; d < dof; ++d) { 2788e6ccafaeSMatthew G Knepley const PetscInt p = submesh->cones[off+d]; 2789e6ccafaeSMatthew G Knepley PetscInt v; 2790e6ccafaeSMatthew G Knepley 2791e6ccafaeSMatthew G Knepley for (v = 0; v < numFaceVertices; ++v) { 2792e6ccafaeSMatthew G Knepley if (subfaceVertices[v] == p) break; 2793e6ccafaeSMatthew G Knepley } 2794e6ccafaeSMatthew G Knepley if (v == numFaceVertices) break; 2795e6ccafaeSMatthew G Knepley } 2796e6ccafaeSMatthew G Knepley if (d == dof) { 2797e6ccafaeSMatthew G Knepley numFaces = 1; 2798e6ccafaeSMatthew G Knepley ((PetscInt*) faces)[0] = f; 2799e6ccafaeSMatthew G Knepley } 2800e6ccafaeSMatthew G Knepley } 2801e6ccafaeSMatthew G Knepley } 2802e6ccafaeSMatthew G Knepley #endif 2803e6ccafaeSMatthew G Knepley if (numFaces > 1) SETERRQ1(comm, PETSC_ERR_ARG_WRONG, "Vertex set had %d faces, not one", numFaces); 2804e6ccafaeSMatthew G Knepley else if (numFaces == 1) { 2805e6ccafaeSMatthew G Knepley /* Add the other cell neighbor for this face */ 2806766ab985SMatthew G. Knepley ierr = DMPlexSetCone(subdm, subcell, faces);CHKERRQ(ierr); 2807e6ccafaeSMatthew G Knepley } else { 2808e6ccafaeSMatthew G Knepley PetscInt *indices, *origVertices, *orientedVertices, *orientedSubVertices, v, ov; 2809e6ccafaeSMatthew G Knepley PetscBool posOriented; 2810e6ccafaeSMatthew G Knepley 281169291d52SBarry Smith ierr = DMGetWorkArray(subdm, 4*numFaceVertices * sizeof(PetscInt), MPIU_INT, &orientedVertices);CHKERRQ(ierr); 2812e6ccafaeSMatthew G Knepley origVertices = &orientedVertices[numFaceVertices]; 2813e6ccafaeSMatthew G Knepley indices = &orientedVertices[numFaceVertices*2]; 2814e6ccafaeSMatthew G Knepley orientedSubVertices = &orientedVertices[numFaceVertices*3]; 2815e6ccafaeSMatthew G Knepley ierr = DMPlexGetOrientedFace(dm, cell, numFaceVertices, faceVertices, numCorners, indices, origVertices, orientedVertices, &posOriented);CHKERRQ(ierr); 2816e6ccafaeSMatthew G Knepley /* TODO: I know that routine should return a permutation, not the indices */ 2817e6ccafaeSMatthew G Knepley for (v = 0; v < numFaceVertices; ++v) { 2818e6ccafaeSMatthew G Knepley const PetscInt vertex = faceVertices[v], subvertex = subfaceVertices[v]; 2819e6ccafaeSMatthew G Knepley for (ov = 0; ov < numFaceVertices; ++ov) { 2820e6ccafaeSMatthew G Knepley if (orientedVertices[ov] == vertex) { 2821e6ccafaeSMatthew G Knepley orientedSubVertices[ov] = subvertex; 2822e6ccafaeSMatthew G Knepley break; 2823e6ccafaeSMatthew G Knepley } 2824e6ccafaeSMatthew G Knepley } 2825e6ccafaeSMatthew G Knepley if (ov == numFaceVertices) SETERRQ1(comm, PETSC_ERR_PLIB, "Could not find face vertex %d in orientated set", vertex); 2826e6ccafaeSMatthew G Knepley } 2827e6ccafaeSMatthew G Knepley ierr = DMPlexSetCone(subdm, *newFacePoint, orientedSubVertices);CHKERRQ(ierr); 2828e6ccafaeSMatthew G Knepley ierr = DMPlexSetCone(subdm, subcell, newFacePoint);CHKERRQ(ierr); 282969291d52SBarry Smith ierr = DMRestoreWorkArray(subdm, 4*numFaceVertices * sizeof(PetscInt), MPIU_INT, &orientedVertices);CHKERRQ(ierr); 2830e6ccafaeSMatthew G Knepley ++(*newFacePoint); 2831e6ccafaeSMatthew G Knepley } 2832ef07cca7SMatthew G. Knepley #if 0 2833e6ccafaeSMatthew G Knepley ierr = DMPlexRestoreJoin(subdm, numFaceVertices, subfaceVertices, &numFaces, &faces);CHKERRQ(ierr); 2834ef07cca7SMatthew G. Knepley #else 283569291d52SBarry Smith ierr = DMRestoreWorkArray(subdm, 1, MPIU_INT, (void **) &faces);CHKERRQ(ierr); 2836ef07cca7SMatthew G. Knepley #endif 2837e6ccafaeSMatthew G Knepley PetscFunctionReturn(0); 2838e6ccafaeSMatthew G Knepley } 2839e6ccafaeSMatthew G Knepley 284053156dfcSMatthew G. Knepley static PetscErrorCode DMPlexCreateSubmesh_Uninterpolated(DM dm, DMLabel vertexLabel, PetscInt value, DM subdm) 2841e6ccafaeSMatthew G Knepley { 284282f516ccSBarry Smith MPI_Comm comm; 284353156dfcSMatthew G. Knepley DMLabel subpointMap; 2844efa14ee0SMatthew G Knepley IS subvertexIS, subcellIS; 2845efa14ee0SMatthew G Knepley const PetscInt *subVertices, *subCells; 2846efa14ee0SMatthew G Knepley PetscInt numSubVertices, firstSubVertex, numSubCells; 2847fed694aaSMatthew G. Knepley PetscInt *subface, maxConeSize, numSubFaces = 0, firstSubFace, newFacePoint, nFV = 0; 2848efa14ee0SMatthew G Knepley PetscInt vStart, vEnd, c, f; 2849e6ccafaeSMatthew G Knepley PetscErrorCode ierr; 2850e6ccafaeSMatthew G Knepley 2851e6ccafaeSMatthew G Knepley PetscFunctionBegin; 285282f516ccSBarry Smith ierr = PetscObjectGetComm((PetscObject)dm,&comm);CHKERRQ(ierr); 2853efa14ee0SMatthew G Knepley /* Create subpointMap which marks the submesh */ 2854d67d17b1SMatthew G. Knepley ierr = DMLabelCreate(PETSC_COMM_SELF, "subpoint_map", &subpointMap);CHKERRQ(ierr); 2855efa14ee0SMatthew G Knepley ierr = DMPlexSetSubpointMap(subdm, subpointMap);CHKERRQ(ierr); 2856efa14ee0SMatthew G Knepley ierr = DMLabelDestroy(&subpointMap);CHKERRQ(ierr); 285753156dfcSMatthew G. Knepley if (vertexLabel) {ierr = DMPlexMarkSubmesh_Uninterpolated(dm, vertexLabel, value, subpointMap, &numSubFaces, &nFV, subdm);CHKERRQ(ierr);} 2858efa14ee0SMatthew G Knepley /* Setup chart */ 2859efa14ee0SMatthew G Knepley ierr = DMLabelGetStratumSize(subpointMap, 0, &numSubVertices);CHKERRQ(ierr); 2860efa14ee0SMatthew G Knepley ierr = DMLabelGetStratumSize(subpointMap, 2, &numSubCells);CHKERRQ(ierr); 2861efa14ee0SMatthew G Knepley ierr = DMPlexSetChart(subdm, 0, numSubCells+numSubFaces+numSubVertices);CHKERRQ(ierr); 2862efa14ee0SMatthew G Knepley ierr = DMPlexSetVTKCellHeight(subdm, 1);CHKERRQ(ierr); 2863e6ccafaeSMatthew G Knepley /* Set cone sizes */ 2864e6ccafaeSMatthew G Knepley firstSubVertex = numSubCells; 2865efa14ee0SMatthew G Knepley firstSubFace = numSubCells+numSubVertices; 2866e6ccafaeSMatthew G Knepley newFacePoint = firstSubFace; 2867efa14ee0SMatthew G Knepley ierr = DMLabelGetStratumIS(subpointMap, 0, &subvertexIS);CHKERRQ(ierr); 2868efa14ee0SMatthew G Knepley if (subvertexIS) {ierr = ISGetIndices(subvertexIS, &subVertices);CHKERRQ(ierr);} 2869efa14ee0SMatthew G Knepley ierr = DMLabelGetStratumIS(subpointMap, 2, &subcellIS);CHKERRQ(ierr); 2870efa14ee0SMatthew G Knepley if (subcellIS) {ierr = ISGetIndices(subcellIS, &subCells);CHKERRQ(ierr);} 2871e6ccafaeSMatthew G Knepley for (c = 0; c < numSubCells; ++c) { 2872e6ccafaeSMatthew G Knepley ierr = DMPlexSetConeSize(subdm, c, 1);CHKERRQ(ierr); 2873e6ccafaeSMatthew G Knepley } 2874e6ccafaeSMatthew G Knepley for (f = firstSubFace; f < firstSubFace+numSubFaces; ++f) { 2875e6ccafaeSMatthew G Knepley ierr = DMPlexSetConeSize(subdm, f, nFV);CHKERRQ(ierr); 2876e6ccafaeSMatthew G Knepley } 2877e6ccafaeSMatthew G Knepley ierr = DMSetUp(subdm);CHKERRQ(ierr); 2878e6ccafaeSMatthew G Knepley /* Create face cones */ 2879efa14ee0SMatthew G Knepley ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr); 28800298fd71SBarry Smith ierr = DMPlexGetMaxSizes(dm, &maxConeSize, NULL);CHKERRQ(ierr); 288169291d52SBarry Smith ierr = DMGetWorkArray(subdm, maxConeSize, MPIU_INT, (void**) &subface);CHKERRQ(ierr); 2882e6ccafaeSMatthew G Knepley for (c = 0; c < numSubCells; ++c) { 2883e6ccafaeSMatthew G Knepley const PetscInt cell = subCells[c]; 2884efa14ee0SMatthew G Knepley const PetscInt subcell = c; 28850298fd71SBarry Smith PetscInt *closure = NULL; 2886efa14ee0SMatthew G Knepley PetscInt closureSize, cl, numCorners = 0, faceSize = 0; 2887e6ccafaeSMatthew G Knepley 2888e6ccafaeSMatthew G Knepley ierr = DMPlexGetTransitiveClosure(dm, cell, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 2889efa14ee0SMatthew G Knepley for (cl = 0; cl < closureSize*2; cl += 2) { 2890efa14ee0SMatthew G Knepley const PetscInt point = closure[cl]; 2891e6ccafaeSMatthew G Knepley PetscInt subVertex; 2892e6ccafaeSMatthew G Knepley 2893efa14ee0SMatthew G Knepley if ((point >= vStart) && (point < vEnd)) { 2894efa14ee0SMatthew G Knepley ++numCorners; 2895efa14ee0SMatthew G Knepley ierr = PetscFindInt(point, numSubVertices, subVertices, &subVertex);CHKERRQ(ierr); 2896efa14ee0SMatthew G Knepley if (subVertex >= 0) { 2897efa14ee0SMatthew G Knepley closure[faceSize] = point; 289865560c7fSMatthew G Knepley subface[faceSize] = firstSubVertex+subVertex; 2899e6ccafaeSMatthew G Knepley ++faceSize; 2900e6ccafaeSMatthew G Knepley } 2901e6ccafaeSMatthew G Knepley } 2902e6ccafaeSMatthew G Knepley } 2903efa14ee0SMatthew G Knepley if (faceSize > nFV) SETERRQ1(comm, PETSC_ERR_ARG_WRONG, "Invalid submesh: Too many vertices %d of an element on the surface", faceSize); 2904efa14ee0SMatthew G Knepley if (faceSize == nFV) { 2905cd0c2139SMatthew G Knepley ierr = DMPlexInsertFace_Internal(dm, subdm, faceSize, closure, subface, numCorners, cell, subcell, firstSubFace, &newFacePoint);CHKERRQ(ierr); 2906e6ccafaeSMatthew G Knepley } 290765560c7fSMatthew G Knepley ierr = DMPlexRestoreTransitiveClosure(dm, cell, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 2908e6ccafaeSMatthew G Knepley } 290969291d52SBarry Smith ierr = DMRestoreWorkArray(subdm, maxConeSize, MPIU_INT, (void**) &subface);CHKERRQ(ierr); 2910e6ccafaeSMatthew G Knepley ierr = DMPlexSymmetrize(subdm);CHKERRQ(ierr); 2911e6ccafaeSMatthew G Knepley ierr = DMPlexStratify(subdm);CHKERRQ(ierr); 2912e6ccafaeSMatthew G Knepley /* Build coordinates */ 2913efa14ee0SMatthew G Knepley { 2914efa14ee0SMatthew G Knepley PetscSection coordSection, subCoordSection; 2915efa14ee0SMatthew G Knepley Vec coordinates, subCoordinates; 2916efa14ee0SMatthew G Knepley PetscScalar *coords, *subCoords; 2917285d324eSMatthew G. Knepley PetscInt numComp, coordSize, v; 291824640c55SToby Isaac const char *name; 2919efa14ee0SMatthew G Knepley 292069d8a9ceSMatthew G. Knepley ierr = DMGetCoordinateSection(dm, &coordSection);CHKERRQ(ierr); 2921e6ccafaeSMatthew G Knepley ierr = DMGetCoordinatesLocal(dm, &coordinates);CHKERRQ(ierr); 292269d8a9ceSMatthew G. Knepley ierr = DMGetCoordinateSection(subdm, &subCoordSection);CHKERRQ(ierr); 2923285d324eSMatthew G. Knepley ierr = PetscSectionSetNumFields(subCoordSection, 1);CHKERRQ(ierr); 2924285d324eSMatthew G. Knepley ierr = PetscSectionGetFieldComponents(coordSection, 0, &numComp);CHKERRQ(ierr); 2925285d324eSMatthew G. Knepley ierr = PetscSectionSetFieldComponents(subCoordSection, 0, numComp);CHKERRQ(ierr); 2926efa14ee0SMatthew G Knepley ierr = PetscSectionSetChart(subCoordSection, firstSubVertex, firstSubVertex+numSubVertices);CHKERRQ(ierr); 2927efa14ee0SMatthew G Knepley for (v = 0; v < numSubVertices; ++v) { 2928efa14ee0SMatthew G Knepley const PetscInt vertex = subVertices[v]; 2929efa14ee0SMatthew G Knepley const PetscInt subvertex = firstSubVertex+v; 2930efa14ee0SMatthew G Knepley PetscInt dof; 2931efa14ee0SMatthew G Knepley 2932efa14ee0SMatthew G Knepley ierr = PetscSectionGetDof(coordSection, vertex, &dof);CHKERRQ(ierr); 2933efa14ee0SMatthew G Knepley ierr = PetscSectionSetDof(subCoordSection, subvertex, dof);CHKERRQ(ierr); 2934285d324eSMatthew G. Knepley ierr = PetscSectionSetFieldDof(subCoordSection, subvertex, 0, dof);CHKERRQ(ierr); 2935e6ccafaeSMatthew G Knepley } 2936e6ccafaeSMatthew G Knepley ierr = PetscSectionSetUp(subCoordSection);CHKERRQ(ierr); 2937e6ccafaeSMatthew G Knepley ierr = PetscSectionGetStorageSize(subCoordSection, &coordSize);CHKERRQ(ierr); 29388b9ced59SLisandro Dalcin ierr = VecCreate(PETSC_COMM_SELF, &subCoordinates);CHKERRQ(ierr); 293924640c55SToby Isaac ierr = PetscObjectGetName((PetscObject)coordinates,&name);CHKERRQ(ierr); 294024640c55SToby Isaac ierr = PetscObjectSetName((PetscObject)subCoordinates,name);CHKERRQ(ierr); 2941e6ccafaeSMatthew G Knepley ierr = VecSetSizes(subCoordinates, coordSize, PETSC_DETERMINE);CHKERRQ(ierr); 29422eb5907fSJed Brown ierr = VecSetType(subCoordinates,VECSTANDARD);CHKERRQ(ierr); 2943830e53efSMatthew G. Knepley if (coordSize) { 2944e6ccafaeSMatthew G Knepley ierr = VecGetArray(coordinates, &coords);CHKERRQ(ierr); 2945e6ccafaeSMatthew G Knepley ierr = VecGetArray(subCoordinates, &subCoords);CHKERRQ(ierr); 2946efa14ee0SMatthew G Knepley for (v = 0; v < numSubVertices; ++v) { 2947efa14ee0SMatthew G Knepley const PetscInt vertex = subVertices[v]; 2948efa14ee0SMatthew G Knepley const PetscInt subvertex = firstSubVertex+v; 2949efa14ee0SMatthew G Knepley PetscInt dof, off, sdof, soff, d; 2950e6ccafaeSMatthew G Knepley 2951e6ccafaeSMatthew G Knepley ierr = PetscSectionGetDof(coordSection, vertex, &dof);CHKERRQ(ierr); 2952e6ccafaeSMatthew G Knepley ierr = PetscSectionGetOffset(coordSection, vertex, &off);CHKERRQ(ierr); 2953efa14ee0SMatthew G Knepley ierr = PetscSectionGetDof(subCoordSection, subvertex, &sdof);CHKERRQ(ierr); 2954efa14ee0SMatthew G Knepley ierr = PetscSectionGetOffset(subCoordSection, subvertex, &soff);CHKERRQ(ierr); 2955efa14ee0SMatthew G Knepley if (dof != sdof) SETERRQ4(comm, PETSC_ERR_PLIB, "Coordinate dimension %d on subvertex %d, vertex %d should be %d", sdof, subvertex, vertex, dof); 2956e6ccafaeSMatthew G Knepley for (d = 0; d < dof; ++d) subCoords[soff+d] = coords[off+d]; 2957e6ccafaeSMatthew G Knepley } 2958e6ccafaeSMatthew G Knepley ierr = VecRestoreArray(coordinates, &coords);CHKERRQ(ierr); 2959e6ccafaeSMatthew G Knepley ierr = VecRestoreArray(subCoordinates, &subCoords);CHKERRQ(ierr); 29603b399e24SMatthew G. Knepley } 2961e6ccafaeSMatthew G Knepley ierr = DMSetCoordinatesLocal(subdm, subCoordinates);CHKERRQ(ierr); 2962e6ccafaeSMatthew G Knepley ierr = VecDestroy(&subCoordinates);CHKERRQ(ierr); 2963e6ccafaeSMatthew G Knepley } 2964efa14ee0SMatthew G Knepley /* Cleanup */ 2965efa14ee0SMatthew G Knepley if (subvertexIS) {ierr = ISRestoreIndices(subvertexIS, &subVertices);CHKERRQ(ierr);} 2966efa14ee0SMatthew G Knepley ierr = ISDestroy(&subvertexIS);CHKERRQ(ierr); 2967efa14ee0SMatthew G Knepley if (subcellIS) {ierr = ISRestoreIndices(subcellIS, &subCells);CHKERRQ(ierr);} 2968efa14ee0SMatthew G Knepley ierr = ISDestroy(&subcellIS);CHKERRQ(ierr); 2969e6ccafaeSMatthew G Knepley PetscFunctionReturn(0); 2970e6ccafaeSMatthew G Knepley } 2971e6ccafaeSMatthew G Knepley 29723982b651SMatthew G. Knepley PETSC_STATIC_INLINE PetscInt DMPlexFilterPoint_Internal(PetscInt point, PetscInt firstSubPoint, PetscInt numSubPoints, const PetscInt subPoints[]) 29733982b651SMatthew G. Knepley { 29743982b651SMatthew G. Knepley PetscInt subPoint; 29753982b651SMatthew G. Knepley PetscErrorCode ierr; 29763982b651SMatthew G. Knepley 29773982b651SMatthew G. Knepley ierr = PetscFindInt(point, numSubPoints, subPoints, &subPoint); if (ierr < 0) return ierr; 29783982b651SMatthew G. Knepley return subPoint < 0 ? subPoint : firstSubPoint+subPoint; 29793982b651SMatthew G. Knepley } 29803982b651SMatthew G. Knepley 2981158acfadSMatthew G. Knepley static PetscErrorCode DMPlexCreateSubmeshGeneric_Interpolated(DM dm, DMLabel label, PetscInt value, PetscBool markedFaces, PetscBool isCohesive, PetscInt cellHeight, DM subdm) 2982e6ccafaeSMatthew G Knepley { 298382f516ccSBarry Smith MPI_Comm comm; 298453156dfcSMatthew G. Knepley DMLabel subpointMap; 2985efa14ee0SMatthew G Knepley IS *subpointIS; 2986efa14ee0SMatthew G Knepley const PetscInt **subpoints; 29873982b651SMatthew G. Knepley PetscInt *numSubPoints, *firstSubPoint, *coneNew, *orntNew; 29880d366550SMatthew G. Knepley PetscInt totSubPoints = 0, maxConeSize, cMax, cEnd, dim, p, d, v; 29890d366550SMatthew G. Knepley PetscMPIInt rank; 2990e6ccafaeSMatthew G Knepley PetscErrorCode ierr; 2991e6ccafaeSMatthew G Knepley 2992e6ccafaeSMatthew G Knepley PetscFunctionBegin; 299382f516ccSBarry Smith ierr = PetscObjectGetComm((PetscObject)dm,&comm);CHKERRQ(ierr); 29940d366550SMatthew G. Knepley ierr = MPI_Comm_rank(comm, &rank);CHKERRQ(ierr); 2995efa14ee0SMatthew G Knepley /* Create subpointMap which marks the submesh */ 2996d67d17b1SMatthew G. Knepley ierr = DMLabelCreate(PETSC_COMM_SELF, "subpoint_map", &subpointMap);CHKERRQ(ierr); 2997efa14ee0SMatthew G Knepley ierr = DMPlexSetSubpointMap(subdm, subpointMap);CHKERRQ(ierr); 2998bec263e5SMatthew G. Knepley if (cellHeight) { 29993982b651SMatthew G. Knepley if (isCohesive) {ierr = DMPlexMarkCohesiveSubmesh_Interpolated(dm, label, value, subpointMap, subdm);CHKERRQ(ierr);} 3000158acfadSMatthew G. Knepley else {ierr = DMPlexMarkSubmesh_Interpolated(dm, label, value, markedFaces, subpointMap, subdm);CHKERRQ(ierr);} 3001bec263e5SMatthew G. Knepley } else { 3002bec263e5SMatthew G. Knepley DMLabel depth; 3003bec263e5SMatthew G. Knepley IS pointIS; 3004bec263e5SMatthew G. Knepley const PetscInt *points; 3005bec263e5SMatthew G. Knepley PetscInt numPoints; 3006bec263e5SMatthew G. Knepley 3007bec263e5SMatthew G. Knepley ierr = DMPlexGetDepthLabel(dm, &depth);CHKERRQ(ierr); 3008bec263e5SMatthew G. Knepley ierr = DMLabelGetStratumSize(label, value, &numPoints);CHKERRQ(ierr); 3009bec263e5SMatthew G. Knepley ierr = DMLabelGetStratumIS(label, value, &pointIS);CHKERRQ(ierr); 3010bec263e5SMatthew G. Knepley ierr = ISGetIndices(pointIS, &points);CHKERRQ(ierr); 3011bec263e5SMatthew G. Knepley for (p = 0; p < numPoints; ++p) { 3012bec263e5SMatthew G. Knepley PetscInt *closure = NULL; 3013bec263e5SMatthew G. Knepley PetscInt closureSize, c, pdim; 3014bec263e5SMatthew G. Knepley 3015bec263e5SMatthew G. Knepley ierr = DMPlexGetTransitiveClosure(dm, points[p], PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 3016bec263e5SMatthew G. Knepley for (c = 0; c < closureSize*2; c += 2) { 3017bec263e5SMatthew G. Knepley ierr = DMLabelGetValue(depth, closure[c], &pdim);CHKERRQ(ierr); 3018bec263e5SMatthew G. Knepley ierr = DMLabelSetValue(subpointMap, closure[c], pdim);CHKERRQ(ierr); 3019bec263e5SMatthew G. Knepley } 3020bec263e5SMatthew G. Knepley ierr = DMPlexRestoreTransitiveClosure(dm, points[p], PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 3021bec263e5SMatthew G. Knepley } 3022bec263e5SMatthew G. Knepley ierr = ISRestoreIndices(pointIS, &points);CHKERRQ(ierr); 3023bec263e5SMatthew G. Knepley ierr = ISDestroy(&pointIS);CHKERRQ(ierr); 3024bec263e5SMatthew G. Knepley } 30250d366550SMatthew G. Knepley ierr = DMPlexGetHeightStratum(dm, 0, NULL, &cEnd);CHKERRQ(ierr); 30260d366550SMatthew G. Knepley ierr = DMPlexGetHybridBounds(dm, &cMax, NULL, NULL, NULL);CHKERRQ(ierr); 30270d366550SMatthew G. Knepley cMax = (cMax < 0) ? cEnd : cMax; 3028efa14ee0SMatthew G Knepley /* Setup chart */ 3029c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 3030dcca6d9dSJed Brown ierr = PetscMalloc4(dim+1,&numSubPoints,dim+1,&firstSubPoint,dim+1,&subpointIS,dim+1,&subpoints);CHKERRQ(ierr); 3031e6ccafaeSMatthew G Knepley for (d = 0; d <= dim; ++d) { 3032e6ccafaeSMatthew G Knepley ierr = DMLabelGetStratumSize(subpointMap, d, &numSubPoints[d]);CHKERRQ(ierr); 3033e6ccafaeSMatthew G Knepley totSubPoints += numSubPoints[d]; 3034e6ccafaeSMatthew G Knepley } 3035e6ccafaeSMatthew G Knepley ierr = DMPlexSetChart(subdm, 0, totSubPoints);CHKERRQ(ierr); 3036bec263e5SMatthew G. Knepley ierr = DMPlexSetVTKCellHeight(subdm, cellHeight);CHKERRQ(ierr); 3037e6ccafaeSMatthew G Knepley /* Set cone sizes */ 3038e6ccafaeSMatthew G Knepley firstSubPoint[dim] = 0; 3039e6ccafaeSMatthew G Knepley firstSubPoint[0] = firstSubPoint[dim] + numSubPoints[dim]; 3040e6ccafaeSMatthew G Knepley if (dim > 1) {firstSubPoint[dim-1] = firstSubPoint[0] + numSubPoints[0];} 3041e6ccafaeSMatthew G Knepley if (dim > 2) {firstSubPoint[dim-2] = firstSubPoint[dim-1] + numSubPoints[dim-1];} 3042e6ccafaeSMatthew G Knepley for (d = 0; d <= dim; ++d) { 3043e6ccafaeSMatthew G Knepley ierr = DMLabelGetStratumIS(subpointMap, d, &subpointIS[d]);CHKERRQ(ierr); 30440ae02aa4SMatthew G. Knepley if (subpointIS[d]) {ierr = ISGetIndices(subpointIS[d], &subpoints[d]);CHKERRQ(ierr);} 3045e6ccafaeSMatthew G Knepley } 3046e6ccafaeSMatthew G Knepley for (d = 0; d <= dim; ++d) { 3047e6ccafaeSMatthew G Knepley for (p = 0; p < numSubPoints[d]; ++p) { 3048e6ccafaeSMatthew G Knepley const PetscInt point = subpoints[d][p]; 3049e6ccafaeSMatthew G Knepley const PetscInt subpoint = firstSubPoint[d] + p; 3050e6ccafaeSMatthew G Knepley const PetscInt *cone; 3051e6ccafaeSMatthew G Knepley PetscInt coneSize, coneSizeNew, c, val; 3052e6ccafaeSMatthew G Knepley 3053e6ccafaeSMatthew G Knepley ierr = DMPlexGetConeSize(dm, point, &coneSize);CHKERRQ(ierr); 3054e6ccafaeSMatthew G Knepley ierr = DMPlexSetConeSize(subdm, subpoint, coneSize);CHKERRQ(ierr); 3055bec263e5SMatthew G. Knepley if (cellHeight && (d == dim)) { 3056e6ccafaeSMatthew G Knepley ierr = DMPlexGetCone(dm, point, &cone);CHKERRQ(ierr); 3057e6ccafaeSMatthew G Knepley for (c = 0, coneSizeNew = 0; c < coneSize; ++c) { 3058e6ccafaeSMatthew G Knepley ierr = DMLabelGetValue(subpointMap, cone[c], &val);CHKERRQ(ierr); 3059e6ccafaeSMatthew G Knepley if (val >= 0) coneSizeNew++; 3060e6ccafaeSMatthew G Knepley } 3061e6ccafaeSMatthew G Knepley ierr = DMPlexSetConeSize(subdm, subpoint, coneSizeNew);CHKERRQ(ierr); 3062e6ccafaeSMatthew G Knepley } 3063e6ccafaeSMatthew G Knepley } 3064e6ccafaeSMatthew G Knepley } 3065d67d17b1SMatthew G. Knepley ierr = DMLabelDestroy(&subpointMap);CHKERRQ(ierr); 3066e6ccafaeSMatthew G Knepley ierr = DMSetUp(subdm);CHKERRQ(ierr); 3067e6ccafaeSMatthew G Knepley /* Set cones */ 30680298fd71SBarry Smith ierr = DMPlexGetMaxSizes(dm, &maxConeSize, NULL);CHKERRQ(ierr); 30693982b651SMatthew G. Knepley ierr = PetscMalloc2(maxConeSize,&coneNew,maxConeSize,&orntNew);CHKERRQ(ierr); 3070e6ccafaeSMatthew G Knepley for (d = 0; d <= dim; ++d) { 3071e6ccafaeSMatthew G Knepley for (p = 0; p < numSubPoints[d]; ++p) { 3072e6ccafaeSMatthew G Knepley const PetscInt point = subpoints[d][p]; 3073e6ccafaeSMatthew G Knepley const PetscInt subpoint = firstSubPoint[d] + p; 30740e49e2e2SMatthew G. Knepley const PetscInt *cone, *ornt; 30750d366550SMatthew G. Knepley PetscInt coneSize, subconeSize, coneSizeNew, c, subc, fornt = 0; 3076e6ccafaeSMatthew G Knepley 30770d366550SMatthew G. Knepley if (d == dim-1) { 30780d366550SMatthew G. Knepley const PetscInt *support, *cone, *ornt; 30790d366550SMatthew G. Knepley PetscInt supportSize, coneSize, s, subc; 30800d366550SMatthew G. Knepley 30810d366550SMatthew G. Knepley ierr = DMPlexGetSupport(dm, point, &support);CHKERRQ(ierr); 30820d366550SMatthew G. Knepley ierr = DMPlexGetSupportSize(dm, point, &supportSize);CHKERRQ(ierr); 30830d366550SMatthew G. Knepley for (s = 0; s < supportSize; ++s) { 30840d366550SMatthew G. Knepley if ((support[s] < cMax) || (support[s] >= cEnd)) continue; 30850d366550SMatthew G. Knepley ierr = PetscFindInt(support[s], numSubPoints[d+1], subpoints[d+1], &subc);CHKERRQ(ierr); 30860d366550SMatthew G. Knepley if (subc >= 0) { 30870d366550SMatthew G. Knepley const PetscInt ccell = subpoints[d+1][subc]; 30880d366550SMatthew G. Knepley 30897f79407eSBarry Smith ierr = DMPlexGetCone(dm, ccell, &cone);CHKERRQ(ierr); 30907f79407eSBarry Smith ierr = DMPlexGetConeSize(dm, ccell, &coneSize);CHKERRQ(ierr); 30917f79407eSBarry Smith ierr = DMPlexGetConeOrientation(dm, ccell, &ornt);CHKERRQ(ierr); 30920d366550SMatthew G. Knepley for (c = 0; c < coneSize; ++c) { 30930d366550SMatthew G. Knepley if (cone[c] == point) { 30940d366550SMatthew G. Knepley fornt = ornt[c]; 30950d366550SMatthew G. Knepley break; 30960d366550SMatthew G. Knepley } 30970d366550SMatthew G. Knepley } 30980d366550SMatthew G. Knepley break; 30990d366550SMatthew G. Knepley } 31000d366550SMatthew G. Knepley } 31010d366550SMatthew G. Knepley } 3102e6ccafaeSMatthew G Knepley ierr = DMPlexGetConeSize(dm, point, &coneSize);CHKERRQ(ierr); 3103e6ccafaeSMatthew G Knepley ierr = DMPlexGetConeSize(subdm, subpoint, &subconeSize);CHKERRQ(ierr); 3104e6ccafaeSMatthew G Knepley ierr = DMPlexGetCone(dm, point, &cone);CHKERRQ(ierr); 31050e49e2e2SMatthew G. Knepley ierr = DMPlexGetConeOrientation(dm, point, &ornt);CHKERRQ(ierr); 3106e6ccafaeSMatthew G Knepley for (c = 0, coneSizeNew = 0; c < coneSize; ++c) { 3107e6ccafaeSMatthew G Knepley ierr = PetscFindInt(cone[c], numSubPoints[d-1], subpoints[d-1], &subc);CHKERRQ(ierr); 310801a2673eSMatthew G. Knepley if (subc >= 0) { 310901a2673eSMatthew G. Knepley coneNew[coneSizeNew] = firstSubPoint[d-1] + subc; 31103982b651SMatthew G. Knepley orntNew[coneSizeNew] = ornt[c]; 311101a2673eSMatthew G. Knepley ++coneSizeNew; 311201a2673eSMatthew G. Knepley } 3113e6ccafaeSMatthew G Knepley } 3114e6ccafaeSMatthew G Knepley if (coneSizeNew != subconeSize) SETERRQ2(comm, PETSC_ERR_PLIB, "Number of cone points located %d does not match subcone size %d", coneSizeNew, subconeSize); 31150d366550SMatthew G. Knepley if (fornt < 0) { 31160d366550SMatthew G. Knepley /* This should be replaced by a call to DMPlexReverseCell() */ 31170d366550SMatthew G. Knepley #if 0 3118a129c400SMatthew G. Knepley ierr = DMPlexReverseCell(subdm, subpoint);CHKERRQ(ierr); 3119a129c400SMatthew G. Knepley #else 3120c0b40891SMatthew G. Knepley for (c = 0; c < coneSizeNew/2 + coneSizeNew%2; ++c) { 3121a129c400SMatthew G. Knepley PetscInt faceSize, tmp; 31220d366550SMatthew G. Knepley 31230d366550SMatthew G. Knepley tmp = coneNew[c]; 31240d366550SMatthew G. Knepley coneNew[c] = coneNew[coneSizeNew-1-c]; 31250d366550SMatthew G. Knepley coneNew[coneSizeNew-1-c] = tmp; 3126a129c400SMatthew G. Knepley ierr = DMPlexGetConeSize(dm, cone[c], &faceSize);CHKERRQ(ierr); 3127a129c400SMatthew G. Knepley tmp = orntNew[c] >= 0 ? -(faceSize-orntNew[c]) : faceSize+orntNew[c]; 3128a129c400SMatthew G. Knepley orntNew[c] = orntNew[coneSizeNew-1-c] >= 0 ? -(faceSize-orntNew[coneSizeNew-1-c]) : faceSize+orntNew[coneSizeNew-1-c]; 31290d366550SMatthew G. Knepley orntNew[coneSizeNew-1-c] = tmp; 31300d366550SMatthew G. Knepley } 31310d366550SMatthew G. Knepley } 3132e6ccafaeSMatthew G Knepley ierr = DMPlexSetCone(subdm, subpoint, coneNew);CHKERRQ(ierr); 31333982b651SMatthew G. Knepley ierr = DMPlexSetConeOrientation(subdm, subpoint, orntNew);CHKERRQ(ierr); 3134a129c400SMatthew G. Knepley #endif 3135e6ccafaeSMatthew G Knepley } 3136e6ccafaeSMatthew G Knepley } 31373982b651SMatthew G. Knepley ierr = PetscFree2(coneNew,orntNew);CHKERRQ(ierr); 3138e6ccafaeSMatthew G Knepley ierr = DMPlexSymmetrize(subdm);CHKERRQ(ierr); 3139e6ccafaeSMatthew G Knepley ierr = DMPlexStratify(subdm);CHKERRQ(ierr); 3140e6ccafaeSMatthew G Knepley /* Build coordinates */ 3141e6ccafaeSMatthew G Knepley { 3142e6ccafaeSMatthew G Knepley PetscSection coordSection, subCoordSection; 3143e6ccafaeSMatthew G Knepley Vec coordinates, subCoordinates; 3144e6ccafaeSMatthew G Knepley PetscScalar *coords, *subCoords; 3145c0e8cf5fSMatthew G. Knepley PetscInt cdim, numComp, coordSize; 314624640c55SToby Isaac const char *name; 3147e6ccafaeSMatthew G Knepley 3148c0e8cf5fSMatthew G. Knepley ierr = DMGetCoordinateDim(dm, &cdim);CHKERRQ(ierr); 314969d8a9ceSMatthew G. Knepley ierr = DMGetCoordinateSection(dm, &coordSection);CHKERRQ(ierr); 3150e6ccafaeSMatthew G Knepley ierr = DMGetCoordinatesLocal(dm, &coordinates);CHKERRQ(ierr); 315169d8a9ceSMatthew G. Knepley ierr = DMGetCoordinateSection(subdm, &subCoordSection);CHKERRQ(ierr); 3152285d324eSMatthew G. Knepley ierr = PetscSectionSetNumFields(subCoordSection, 1);CHKERRQ(ierr); 3153285d324eSMatthew G. Knepley ierr = PetscSectionGetFieldComponents(coordSection, 0, &numComp);CHKERRQ(ierr); 3154285d324eSMatthew G. Knepley ierr = PetscSectionSetFieldComponents(subCoordSection, 0, numComp);CHKERRQ(ierr); 3155e6ccafaeSMatthew G Knepley ierr = PetscSectionSetChart(subCoordSection, firstSubPoint[0], firstSubPoint[0]+numSubPoints[0]);CHKERRQ(ierr); 3156e6ccafaeSMatthew G Knepley for (v = 0; v < numSubPoints[0]; ++v) { 3157e6ccafaeSMatthew G Knepley const PetscInt vertex = subpoints[0][v]; 3158e6ccafaeSMatthew G Knepley const PetscInt subvertex = firstSubPoint[0]+v; 3159e6ccafaeSMatthew G Knepley PetscInt dof; 3160e6ccafaeSMatthew G Knepley 3161e6ccafaeSMatthew G Knepley ierr = PetscSectionGetDof(coordSection, vertex, &dof);CHKERRQ(ierr); 3162e6ccafaeSMatthew G Knepley ierr = PetscSectionSetDof(subCoordSection, subvertex, dof);CHKERRQ(ierr); 3163285d324eSMatthew G. Knepley ierr = PetscSectionSetFieldDof(subCoordSection, subvertex, 0, dof);CHKERRQ(ierr); 3164e6ccafaeSMatthew G Knepley } 3165e6ccafaeSMatthew G Knepley ierr = PetscSectionSetUp(subCoordSection);CHKERRQ(ierr); 3166e6ccafaeSMatthew G Knepley ierr = PetscSectionGetStorageSize(subCoordSection, &coordSize);CHKERRQ(ierr); 31678b9ced59SLisandro Dalcin ierr = VecCreate(PETSC_COMM_SELF, &subCoordinates);CHKERRQ(ierr); 316824640c55SToby Isaac ierr = PetscObjectGetName((PetscObject)coordinates,&name);CHKERRQ(ierr); 316924640c55SToby Isaac ierr = PetscObjectSetName((PetscObject)subCoordinates,name);CHKERRQ(ierr); 3170e6ccafaeSMatthew G Knepley ierr = VecSetSizes(subCoordinates, coordSize, PETSC_DETERMINE);CHKERRQ(ierr); 3171c0e8cf5fSMatthew G. Knepley ierr = VecSetBlockSize(subCoordinates, cdim);CHKERRQ(ierr); 31722eb5907fSJed Brown ierr = VecSetType(subCoordinates,VECSTANDARD);CHKERRQ(ierr); 3173e6ccafaeSMatthew G Knepley ierr = VecGetArray(coordinates, &coords);CHKERRQ(ierr); 3174e6ccafaeSMatthew G Knepley ierr = VecGetArray(subCoordinates, &subCoords);CHKERRQ(ierr); 3175e6ccafaeSMatthew G Knepley for (v = 0; v < numSubPoints[0]; ++v) { 3176e6ccafaeSMatthew G Knepley const PetscInt vertex = subpoints[0][v]; 3177e6ccafaeSMatthew G Knepley const PetscInt subvertex = firstSubPoint[0]+v; 3178e6ccafaeSMatthew G Knepley PetscInt dof, off, sdof, soff, d; 3179e6ccafaeSMatthew G Knepley 3180e6ccafaeSMatthew G Knepley ierr = PetscSectionGetDof(coordSection, vertex, &dof);CHKERRQ(ierr); 3181e6ccafaeSMatthew G Knepley ierr = PetscSectionGetOffset(coordSection, vertex, &off);CHKERRQ(ierr); 3182e6ccafaeSMatthew G Knepley ierr = PetscSectionGetDof(subCoordSection, subvertex, &sdof);CHKERRQ(ierr); 3183e6ccafaeSMatthew G Knepley ierr = PetscSectionGetOffset(subCoordSection, subvertex, &soff);CHKERRQ(ierr); 3184e6ccafaeSMatthew G Knepley if (dof != sdof) SETERRQ4(comm, PETSC_ERR_PLIB, "Coordinate dimension %d on subvertex %d, vertex %d should be %d", sdof, subvertex, vertex, dof); 3185efa14ee0SMatthew G Knepley for (d = 0; d < dof; ++d) subCoords[soff+d] = coords[off+d]; 3186e6ccafaeSMatthew G Knepley } 3187e6ccafaeSMatthew G Knepley ierr = VecRestoreArray(coordinates, &coords);CHKERRQ(ierr); 3188e6ccafaeSMatthew G Knepley ierr = VecRestoreArray(subCoordinates, &subCoords);CHKERRQ(ierr); 3189e6ccafaeSMatthew G Knepley ierr = DMSetCoordinatesLocal(subdm, subCoordinates);CHKERRQ(ierr); 3190e6ccafaeSMatthew G Knepley ierr = VecDestroy(&subCoordinates);CHKERRQ(ierr); 3191e6ccafaeSMatthew G Knepley } 31923982b651SMatthew G. Knepley /* Build SF: We need this complexity because subpoints might not be selected on the owning process */ 31933982b651SMatthew G. Knepley { 31943982b651SMatthew G. Knepley PetscSF sfPoint, sfPointSub; 31953982b651SMatthew G. Knepley IS subpIS; 31963982b651SMatthew G. Knepley const PetscSFNode *remotePoints; 31973982b651SMatthew G. Knepley PetscSFNode *sremotePoints, *newLocalPoints, *newOwners; 31983982b651SMatthew G. Knepley const PetscInt *localPoints, *subpoints; 31993982b651SMatthew G. Knepley PetscInt *slocalPoints; 32003982b651SMatthew G. Knepley PetscInt numRoots, numLeaves, numSubpoints = 0, numSubroots, numSubleaves = 0, l, sl, ll, pStart, pEnd, p; 32013982b651SMatthew G. Knepley PetscMPIInt rank; 32023982b651SMatthew G. Knepley 32033982b651SMatthew G. Knepley ierr = MPI_Comm_rank(PetscObjectComm((PetscObject) dm), &rank);CHKERRQ(ierr); 32043982b651SMatthew G. Knepley ierr = DMGetPointSF(dm, &sfPoint);CHKERRQ(ierr); 32053982b651SMatthew G. Knepley ierr = DMGetPointSF(subdm, &sfPointSub);CHKERRQ(ierr); 32063982b651SMatthew G. Knepley ierr = DMPlexGetChart(dm, &pStart, &pEnd);CHKERRQ(ierr); 32073982b651SMatthew G. Knepley ierr = DMPlexGetChart(subdm, NULL, &numSubroots);CHKERRQ(ierr); 32083982b651SMatthew G. Knepley ierr = DMPlexCreateSubpointIS(subdm, &subpIS);CHKERRQ(ierr); 32093982b651SMatthew G. Knepley if (subpIS) { 32103982b651SMatthew G. Knepley ierr = ISGetIndices(subpIS, &subpoints);CHKERRQ(ierr); 32113982b651SMatthew G. Knepley ierr = ISGetLocalSize(subpIS, &numSubpoints);CHKERRQ(ierr); 32123982b651SMatthew G. Knepley } 32133982b651SMatthew G. Knepley ierr = PetscSFGetGraph(sfPoint, &numRoots, &numLeaves, &localPoints, &remotePoints);CHKERRQ(ierr); 32143982b651SMatthew G. Knepley if (numRoots >= 0) { 32153982b651SMatthew G. Knepley ierr = PetscMalloc2(pEnd-pStart,&newLocalPoints,numRoots,&newOwners);CHKERRQ(ierr); 32163982b651SMatthew G. Knepley for (p = 0; p < pEnd-pStart; ++p) { 32173982b651SMatthew G. Knepley newLocalPoints[p].rank = -2; 32183982b651SMatthew G. Knepley newLocalPoints[p].index = -2; 32193982b651SMatthew G. Knepley } 32203982b651SMatthew G. Knepley /* Set subleaves */ 32213982b651SMatthew G. Knepley for (l = 0; l < numLeaves; ++l) { 32223982b651SMatthew G. Knepley const PetscInt point = localPoints[l]; 32233982b651SMatthew G. Knepley const PetscInt subpoint = DMPlexFilterPoint_Internal(point, 0, numSubpoints, subpoints); 32243982b651SMatthew G. Knepley 32253982b651SMatthew G. Knepley if (subpoint < 0) continue; 32263982b651SMatthew G. Knepley newLocalPoints[point-pStart].rank = rank; 32273982b651SMatthew G. Knepley newLocalPoints[point-pStart].index = subpoint; 32283982b651SMatthew G. Knepley ++numSubleaves; 32293982b651SMatthew G. Knepley } 32303982b651SMatthew G. Knepley /* Must put in owned subpoints */ 32313982b651SMatthew G. Knepley for (p = pStart; p < pEnd; ++p) { 32323982b651SMatthew G. Knepley const PetscInt subpoint = DMPlexFilterPoint_Internal(p, 0, numSubpoints, subpoints); 32333982b651SMatthew G. Knepley 32343982b651SMatthew G. Knepley if (subpoint < 0) { 32353982b651SMatthew G. Knepley newOwners[p-pStart].rank = -3; 32363982b651SMatthew G. Knepley newOwners[p-pStart].index = -3; 32373982b651SMatthew G. Knepley } else { 32383982b651SMatthew G. Knepley newOwners[p-pStart].rank = rank; 32393982b651SMatthew G. Knepley newOwners[p-pStart].index = subpoint; 32403982b651SMatthew G. Knepley } 32413982b651SMatthew G. Knepley } 32423982b651SMatthew G. Knepley ierr = PetscSFReduceBegin(sfPoint, MPIU_2INT, newLocalPoints, newOwners, MPI_MAXLOC);CHKERRQ(ierr); 32433982b651SMatthew G. Knepley ierr = PetscSFReduceEnd(sfPoint, MPIU_2INT, newLocalPoints, newOwners, MPI_MAXLOC);CHKERRQ(ierr); 32443982b651SMatthew G. Knepley ierr = PetscSFBcastBegin(sfPoint, MPIU_2INT, newOwners, newLocalPoints);CHKERRQ(ierr); 32453982b651SMatthew G. Knepley ierr = PetscSFBcastEnd(sfPoint, MPIU_2INT, newOwners, newLocalPoints);CHKERRQ(ierr); 32463982b651SMatthew G. Knepley ierr = PetscMalloc1(numSubleaves, &slocalPoints);CHKERRQ(ierr); 32473982b651SMatthew G. Knepley ierr = PetscMalloc1(numSubleaves, &sremotePoints);CHKERRQ(ierr); 32483982b651SMatthew G. Knepley for (l = 0, sl = 0, ll = 0; l < numLeaves; ++l) { 32493982b651SMatthew G. Knepley const PetscInt point = localPoints[l]; 32503982b651SMatthew G. Knepley const PetscInt subpoint = DMPlexFilterPoint_Internal(point, 0, numSubpoints, subpoints); 32513982b651SMatthew G. Knepley 32523982b651SMatthew G. Knepley if (subpoint < 0) continue; 32533982b651SMatthew G. Knepley if (newLocalPoints[point].rank == rank) {++ll; continue;} 32543982b651SMatthew G. Knepley slocalPoints[sl] = subpoint; 32553982b651SMatthew G. Knepley sremotePoints[sl].rank = newLocalPoints[point].rank; 32563982b651SMatthew G. Knepley sremotePoints[sl].index = newLocalPoints[point].index; 32573982b651SMatthew G. Knepley if (sremotePoints[sl].rank < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Invalid remote rank for local point %d", point); 32583982b651SMatthew G. Knepley if (sremotePoints[sl].index < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Invalid remote subpoint for local point %d", point); 32593982b651SMatthew G. Knepley ++sl; 32603982b651SMatthew G. Knepley } 32613982b651SMatthew G. Knepley if (sl + ll != numSubleaves) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Mismatch in number of subleaves %d + %d != %d", sl, ll, numSubleaves); 32623982b651SMatthew G. Knepley ierr = PetscFree2(newLocalPoints,newOwners);CHKERRQ(ierr); 32633982b651SMatthew G. Knepley ierr = PetscSFSetGraph(sfPointSub, numSubroots, sl, slocalPoints, PETSC_OWN_POINTER, sremotePoints, PETSC_OWN_POINTER);CHKERRQ(ierr); 32643982b651SMatthew G. Knepley } 32653982b651SMatthew G. Knepley if (subpIS) { 32663982b651SMatthew G. Knepley ierr = ISRestoreIndices(subpIS, &subpoints);CHKERRQ(ierr); 32673982b651SMatthew G. Knepley ierr = ISDestroy(&subpIS);CHKERRQ(ierr); 32683982b651SMatthew G. Knepley } 32693982b651SMatthew G. Knepley } 3270efa14ee0SMatthew G Knepley /* Cleanup */ 3271e6ccafaeSMatthew G Knepley for (d = 0; d <= dim; ++d) { 32720ae02aa4SMatthew G. Knepley if (subpointIS[d]) {ierr = ISRestoreIndices(subpointIS[d], &subpoints[d]);CHKERRQ(ierr);} 3273e6ccafaeSMatthew G Knepley ierr = ISDestroy(&subpointIS[d]);CHKERRQ(ierr); 3274e6ccafaeSMatthew G Knepley } 3275efa14ee0SMatthew G Knepley ierr = PetscFree4(numSubPoints,firstSubPoint,subpointIS,subpoints);CHKERRQ(ierr); 3276e6ccafaeSMatthew G Knepley PetscFunctionReturn(0); 3277e6ccafaeSMatthew G Knepley } 3278e6ccafaeSMatthew G Knepley 3279158acfadSMatthew G. Knepley static PetscErrorCode DMPlexCreateSubmesh_Interpolated(DM dm, DMLabel vertexLabel, PetscInt value, PetscBool markedFaces, DM subdm) 32803982b651SMatthew G. Knepley { 32813982b651SMatthew G. Knepley PetscErrorCode ierr; 32823982b651SMatthew G. Knepley 32833982b651SMatthew G. Knepley PetscFunctionBegin; 3284158acfadSMatthew G. Knepley ierr = DMPlexCreateSubmeshGeneric_Interpolated(dm, vertexLabel, value, markedFaces, PETSC_FALSE, 1, subdm);CHKERRQ(ierr); 32853982b651SMatthew G. Knepley PetscFunctionReturn(0); 32863982b651SMatthew G. Knepley } 32873982b651SMatthew G. Knepley 3288d0fa310fSMatthew G. Knepley /*@ 3289e6ccafaeSMatthew G Knepley DMPlexCreateSubmesh - Extract a hypersurface from the mesh using vertices defined by a label 3290e6ccafaeSMatthew G Knepley 3291e6ccafaeSMatthew G Knepley Input Parameters: 3292e6ccafaeSMatthew G Knepley + dm - The original mesh 3293158acfadSMatthew G. Knepley . vertexLabel - The DMLabel marking points contained in the surface 3294158acfadSMatthew G. Knepley . value - The label value to use 3295158acfadSMatthew G. Knepley - markedFaces - PETSC_TRUE if surface faces are marked in addition to vertices, PETSC_FALSE if only vertices are marked 3296e6ccafaeSMatthew G Knepley 3297e6ccafaeSMatthew G Knepley Output Parameter: 3298e6ccafaeSMatthew G Knepley . subdm - The surface mesh 3299e6ccafaeSMatthew G Knepley 3300e6ccafaeSMatthew G Knepley Note: This function produces a DMLabel mapping original points in the submesh to their depth. This can be obtained using DMPlexGetSubpointMap(). 3301e6ccafaeSMatthew G Knepley 3302e6ccafaeSMatthew G Knepley Level: developer 3303e6ccafaeSMatthew G Knepley 3304c58f1c22SToby Isaac .seealso: DMPlexGetSubpointMap(), DMGetLabel(), DMLabelSetValue() 3305830e53efSMatthew G. Knepley @*/ 3306158acfadSMatthew G. Knepley PetscErrorCode DMPlexCreateSubmesh(DM dm, DMLabel vertexLabel, PetscInt value, PetscBool markedFaces, DM *subdm) 3307e6ccafaeSMatthew G Knepley { 3308827c4036SVaclav Hapla DMPlexInterpolatedFlag interpolated; 3309827c4036SVaclav Hapla PetscInt dim, cdim; 3310e6ccafaeSMatthew G Knepley PetscErrorCode ierr; 3311e6ccafaeSMatthew G Knepley 3312e6ccafaeSMatthew G Knepley PetscFunctionBegin; 3313e6ccafaeSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3314766ab985SMatthew G. Knepley PetscValidPointer(subdm, 3); 3315c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 331682f516ccSBarry Smith ierr = DMCreate(PetscObjectComm((PetscObject)dm), subdm);CHKERRQ(ierr); 3317e6ccafaeSMatthew G Knepley ierr = DMSetType(*subdm, DMPLEX);CHKERRQ(ierr); 3318c73cfb54SMatthew G. Knepley ierr = DMSetDimension(*subdm, dim-1);CHKERRQ(ierr); 3319dd2763adSMatthew G. Knepley ierr = DMGetCoordinateDim(dm, &cdim);CHKERRQ(ierr); 3320dd2763adSMatthew G. Knepley ierr = DMSetCoordinateDim(*subdm, cdim);CHKERRQ(ierr); 3321827c4036SVaclav Hapla ierr = DMPlexIsInterpolated(dm, &interpolated);CHKERRQ(ierr); 3322827c4036SVaclav Hapla if (interpolated == DMPLEX_INTERPOLATED_PARTIAL) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Not for partially interpolated meshes"); 3323827c4036SVaclav Hapla if (interpolated) { 3324158acfadSMatthew G. Knepley ierr = DMPlexCreateSubmesh_Interpolated(dm, vertexLabel, value, markedFaces, *subdm);CHKERRQ(ierr); 3325e6ccafaeSMatthew G Knepley } else { 3326830e53efSMatthew G. Knepley ierr = DMPlexCreateSubmesh_Uninterpolated(dm, vertexLabel, value, *subdm);CHKERRQ(ierr); 3327e6ccafaeSMatthew G Knepley } 3328e6ccafaeSMatthew G Knepley PetscFunctionReturn(0); 3329e6ccafaeSMatthew G Knepley } 3330e6ccafaeSMatthew G Knepley 333127c04023SMatthew G. Knepley static PetscErrorCode DMPlexCreateCohesiveSubmesh_Uninterpolated(DM dm, PetscBool hasLagrange, const char label[], PetscInt value, DM subdm) 3332766ab985SMatthew G. Knepley { 3333766ab985SMatthew G. Knepley MPI_Comm comm; 3334766ab985SMatthew G. Knepley DMLabel subpointMap; 3335766ab985SMatthew G. Knepley IS subvertexIS; 3336766ab985SMatthew G. Knepley const PetscInt *subVertices; 3337fed694aaSMatthew G. Knepley PetscInt numSubVertices, firstSubVertex, numSubCells, *subCells = NULL; 3338766ab985SMatthew G. Knepley PetscInt *subface, maxConeSize, numSubFaces, firstSubFace, newFacePoint, nFV; 333987feddfdSMatthew G. Knepley PetscInt cMax, c, f; 3340766ab985SMatthew G. Knepley PetscErrorCode ierr; 3341766ab985SMatthew G. Knepley 3342766ab985SMatthew G. Knepley PetscFunctionBegin; 3343766ab985SMatthew G. Knepley ierr = PetscObjectGetComm((PetscObject)dm, &comm);CHKERRQ(ierr); 3344766ab985SMatthew G. Knepley /* Create subpointMap which marks the submesh */ 3345d67d17b1SMatthew G. Knepley ierr = DMLabelCreate(PETSC_COMM_SELF, "subpoint_map", &subpointMap);CHKERRQ(ierr); 3346766ab985SMatthew G. Knepley ierr = DMPlexSetSubpointMap(subdm, subpointMap);CHKERRQ(ierr); 3347766ab985SMatthew G. Knepley ierr = DMLabelDestroy(&subpointMap);CHKERRQ(ierr); 334827c04023SMatthew G. Knepley ierr = DMPlexMarkCohesiveSubmesh_Uninterpolated(dm, hasLagrange, label, value, subpointMap, &numSubFaces, &nFV, &subCells, subdm);CHKERRQ(ierr); 3349766ab985SMatthew G. Knepley /* Setup chart */ 3350766ab985SMatthew G. Knepley ierr = DMLabelGetStratumSize(subpointMap, 0, &numSubVertices);CHKERRQ(ierr); 3351766ab985SMatthew G. Knepley ierr = DMLabelGetStratumSize(subpointMap, 2, &numSubCells);CHKERRQ(ierr); 3352766ab985SMatthew G. Knepley ierr = DMPlexSetChart(subdm, 0, numSubCells+numSubFaces+numSubVertices);CHKERRQ(ierr); 3353766ab985SMatthew G. Knepley ierr = DMPlexSetVTKCellHeight(subdm, 1);CHKERRQ(ierr); 3354766ab985SMatthew G. Knepley /* Set cone sizes */ 3355766ab985SMatthew G. Knepley firstSubVertex = numSubCells; 3356766ab985SMatthew G. Knepley firstSubFace = numSubCells+numSubVertices; 3357766ab985SMatthew G. Knepley newFacePoint = firstSubFace; 3358766ab985SMatthew G. Knepley ierr = DMLabelGetStratumIS(subpointMap, 0, &subvertexIS);CHKERRQ(ierr); 3359766ab985SMatthew G. Knepley if (subvertexIS) {ierr = ISGetIndices(subvertexIS, &subVertices);CHKERRQ(ierr);} 3360766ab985SMatthew G. Knepley for (c = 0; c < numSubCells; ++c) { 3361766ab985SMatthew G. Knepley ierr = DMPlexSetConeSize(subdm, c, 1);CHKERRQ(ierr); 3362766ab985SMatthew G. Knepley } 3363766ab985SMatthew G. Knepley for (f = firstSubFace; f < firstSubFace+numSubFaces; ++f) { 3364766ab985SMatthew G. Knepley ierr = DMPlexSetConeSize(subdm, f, nFV);CHKERRQ(ierr); 3365766ab985SMatthew G. Knepley } 3366766ab985SMatthew G. Knepley ierr = DMSetUp(subdm);CHKERRQ(ierr); 3367766ab985SMatthew G. Knepley /* Create face cones */ 3368766ab985SMatthew G. Knepley ierr = DMPlexGetMaxSizes(dm, &maxConeSize, NULL);CHKERRQ(ierr); 336987feddfdSMatthew G. Knepley ierr = DMPlexGetHybridBounds(dm, &cMax, NULL, NULL, NULL);CHKERRQ(ierr); 337069291d52SBarry Smith ierr = DMGetWorkArray(subdm, maxConeSize, MPIU_INT, (void**) &subface);CHKERRQ(ierr); 3371766ab985SMatthew G. Knepley for (c = 0; c < numSubCells; ++c) { 3372766ab985SMatthew G. Knepley const PetscInt cell = subCells[c]; 3373766ab985SMatthew G. Knepley const PetscInt subcell = c; 337487feddfdSMatthew G. Knepley const PetscInt *cone, *cells; 337587feddfdSMatthew G. Knepley PetscInt numCells, subVertex, p, v; 3376766ab985SMatthew G. Knepley 337787feddfdSMatthew G. Knepley if (cell < cMax) continue; 337887feddfdSMatthew G. Knepley ierr = DMPlexGetCone(dm, cell, &cone);CHKERRQ(ierr); 337987feddfdSMatthew G. Knepley for (v = 0; v < nFV; ++v) { 338087feddfdSMatthew G. Knepley ierr = PetscFindInt(cone[v], numSubVertices, subVertices, &subVertex);CHKERRQ(ierr); 338187feddfdSMatthew G. Knepley subface[v] = firstSubVertex+subVertex; 338287feddfdSMatthew G. Knepley } 338387feddfdSMatthew G. Knepley ierr = DMPlexSetCone(subdm, newFacePoint, subface);CHKERRQ(ierr); 338487feddfdSMatthew G. Knepley ierr = DMPlexSetCone(subdm, subcell, &newFacePoint);CHKERRQ(ierr); 338587feddfdSMatthew G. Knepley ierr = DMPlexGetJoin(dm, nFV, cone, &numCells, &cells);CHKERRQ(ierr); 338627234c99SMatthew G. Knepley /* Not true in parallel 338727234c99SMatthew G. Knepley if (numCells != 2) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Cohesive cells should separate two cells"); */ 338887feddfdSMatthew G. Knepley for (p = 0; p < numCells; ++p) { 338987feddfdSMatthew G. Knepley PetscInt negsubcell; 3390766ab985SMatthew G. Knepley 339187feddfdSMatthew G. Knepley if (cells[p] >= cMax) continue; 339287feddfdSMatthew G. Knepley /* I know this is a crap search */ 339387feddfdSMatthew G. Knepley for (negsubcell = 0; negsubcell < numSubCells; ++negsubcell) { 339487feddfdSMatthew G. Knepley if (subCells[negsubcell] == cells[p]) break; 3395766ab985SMatthew G. Knepley } 339687feddfdSMatthew G. Knepley if (negsubcell == numSubCells) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Could not find negative face neighbor for cohesive cell %d", cell); 339787feddfdSMatthew G. Knepley ierr = DMPlexSetCone(subdm, negsubcell, &newFacePoint);CHKERRQ(ierr); 3398766ab985SMatthew G. Knepley } 339987feddfdSMatthew G. Knepley ierr = DMPlexRestoreJoin(dm, nFV, cone, &numCells, &cells);CHKERRQ(ierr); 340087feddfdSMatthew G. Knepley ++newFacePoint; 3401766ab985SMatthew G. Knepley } 340269291d52SBarry Smith ierr = DMRestoreWorkArray(subdm, maxConeSize, MPIU_INT, (void**) &subface);CHKERRQ(ierr); 3403766ab985SMatthew G. Knepley ierr = DMPlexSymmetrize(subdm);CHKERRQ(ierr); 3404766ab985SMatthew G. Knepley ierr = DMPlexStratify(subdm);CHKERRQ(ierr); 3405766ab985SMatthew G. Knepley /* Build coordinates */ 3406766ab985SMatthew G. Knepley { 3407766ab985SMatthew G. Knepley PetscSection coordSection, subCoordSection; 3408766ab985SMatthew G. Knepley Vec coordinates, subCoordinates; 3409766ab985SMatthew G. Knepley PetscScalar *coords, *subCoords; 3410c0e8cf5fSMatthew G. Knepley PetscInt cdim, numComp, coordSize, v; 341124640c55SToby Isaac const char *name; 3412766ab985SMatthew G. Knepley 3413c0e8cf5fSMatthew G. Knepley ierr = DMGetCoordinateDim(dm, &cdim);CHKERRQ(ierr); 341469d8a9ceSMatthew G. Knepley ierr = DMGetCoordinateSection(dm, &coordSection);CHKERRQ(ierr); 3415766ab985SMatthew G. Knepley ierr = DMGetCoordinatesLocal(dm, &coordinates);CHKERRQ(ierr); 341669d8a9ceSMatthew G. Knepley ierr = DMGetCoordinateSection(subdm, &subCoordSection);CHKERRQ(ierr); 3417285d324eSMatthew G. Knepley ierr = PetscSectionSetNumFields(subCoordSection, 1);CHKERRQ(ierr); 3418285d324eSMatthew G. Knepley ierr = PetscSectionGetFieldComponents(coordSection, 0, &numComp);CHKERRQ(ierr); 3419285d324eSMatthew G. Knepley ierr = PetscSectionSetFieldComponents(subCoordSection, 0, numComp);CHKERRQ(ierr); 3420766ab985SMatthew G. Knepley ierr = PetscSectionSetChart(subCoordSection, firstSubVertex, firstSubVertex+numSubVertices);CHKERRQ(ierr); 3421766ab985SMatthew G. Knepley for (v = 0; v < numSubVertices; ++v) { 3422766ab985SMatthew G. Knepley const PetscInt vertex = subVertices[v]; 3423766ab985SMatthew G. Knepley const PetscInt subvertex = firstSubVertex+v; 3424766ab985SMatthew G. Knepley PetscInt dof; 3425766ab985SMatthew G. Knepley 3426766ab985SMatthew G. Knepley ierr = PetscSectionGetDof(coordSection, vertex, &dof);CHKERRQ(ierr); 3427766ab985SMatthew G. Knepley ierr = PetscSectionSetDof(subCoordSection, subvertex, dof);CHKERRQ(ierr); 3428285d324eSMatthew G. Knepley ierr = PetscSectionSetFieldDof(subCoordSection, subvertex, 0, dof);CHKERRQ(ierr); 3429766ab985SMatthew G. Knepley } 3430766ab985SMatthew G. Knepley ierr = PetscSectionSetUp(subCoordSection);CHKERRQ(ierr); 3431766ab985SMatthew G. Knepley ierr = PetscSectionGetStorageSize(subCoordSection, &coordSize);CHKERRQ(ierr); 34328b9ced59SLisandro Dalcin ierr = VecCreate(PETSC_COMM_SELF, &subCoordinates);CHKERRQ(ierr); 343324640c55SToby Isaac ierr = PetscObjectGetName((PetscObject)coordinates,&name);CHKERRQ(ierr); 343424640c55SToby Isaac ierr = PetscObjectSetName((PetscObject)subCoordinates,name);CHKERRQ(ierr); 3435766ab985SMatthew G. Knepley ierr = VecSetSizes(subCoordinates, coordSize, PETSC_DETERMINE);CHKERRQ(ierr); 3436c0e8cf5fSMatthew G. Knepley ierr = VecSetBlockSize(subCoordinates, cdim);CHKERRQ(ierr); 34372eb5907fSJed Brown ierr = VecSetType(subCoordinates,VECSTANDARD);CHKERRQ(ierr); 3438766ab985SMatthew G. Knepley ierr = VecGetArray(coordinates, &coords);CHKERRQ(ierr); 3439766ab985SMatthew G. Knepley ierr = VecGetArray(subCoordinates, &subCoords);CHKERRQ(ierr); 3440766ab985SMatthew G. Knepley for (v = 0; v < numSubVertices; ++v) { 3441766ab985SMatthew G. Knepley const PetscInt vertex = subVertices[v]; 3442766ab985SMatthew G. Knepley const PetscInt subvertex = firstSubVertex+v; 3443766ab985SMatthew G. Knepley PetscInt dof, off, sdof, soff, d; 3444766ab985SMatthew G. Knepley 3445766ab985SMatthew G. Knepley ierr = PetscSectionGetDof(coordSection, vertex, &dof);CHKERRQ(ierr); 3446766ab985SMatthew G. Knepley ierr = PetscSectionGetOffset(coordSection, vertex, &off);CHKERRQ(ierr); 3447766ab985SMatthew G. Knepley ierr = PetscSectionGetDof(subCoordSection, subvertex, &sdof);CHKERRQ(ierr); 3448766ab985SMatthew G. Knepley ierr = PetscSectionGetOffset(subCoordSection, subvertex, &soff);CHKERRQ(ierr); 3449766ab985SMatthew G. Knepley if (dof != sdof) SETERRQ4(comm, PETSC_ERR_PLIB, "Coordinate dimension %d on subvertex %d, vertex %d should be %d", sdof, subvertex, vertex, dof); 3450766ab985SMatthew G. Knepley for (d = 0; d < dof; ++d) subCoords[soff+d] = coords[off+d]; 3451766ab985SMatthew G. Knepley } 3452766ab985SMatthew G. Knepley ierr = VecRestoreArray(coordinates, &coords);CHKERRQ(ierr); 3453766ab985SMatthew G. Knepley ierr = VecRestoreArray(subCoordinates, &subCoords);CHKERRQ(ierr); 3454766ab985SMatthew G. Knepley ierr = DMSetCoordinatesLocal(subdm, subCoordinates);CHKERRQ(ierr); 3455766ab985SMatthew G. Knepley ierr = VecDestroy(&subCoordinates);CHKERRQ(ierr); 3456766ab985SMatthew G. Knepley } 3457aca35d17SMatthew G. Knepley /* Build SF */ 3458aca35d17SMatthew G. Knepley CHKMEMQ; 3459aca35d17SMatthew G. Knepley { 3460aca35d17SMatthew G. Knepley PetscSF sfPoint, sfPointSub; 3461aca35d17SMatthew G. Knepley const PetscSFNode *remotePoints; 3462bdcf2095SMatthew G. Knepley PetscSFNode *sremotePoints, *newLocalPoints, *newOwners; 3463aca35d17SMatthew G. Knepley const PetscInt *localPoints; 3464bdcf2095SMatthew G. Knepley PetscInt *slocalPoints; 346549c26ae4SMatthew G. Knepley PetscInt numRoots, numLeaves, numSubRoots = numSubCells+numSubFaces+numSubVertices, numSubLeaves = 0, l, sl, ll, pStart, pEnd, p, vStart, vEnd; 3466bdcf2095SMatthew G. Knepley PetscMPIInt rank; 3467aca35d17SMatthew G. Knepley 3468bdcf2095SMatthew G. Knepley ierr = MPI_Comm_rank(PetscObjectComm((PetscObject) dm), &rank);CHKERRQ(ierr); 3469aca35d17SMatthew G. Knepley ierr = DMGetPointSF(dm, &sfPoint);CHKERRQ(ierr); 3470aca35d17SMatthew G. Knepley ierr = DMGetPointSF(subdm, &sfPointSub);CHKERRQ(ierr); 3471aca35d17SMatthew G. Knepley ierr = DMPlexGetChart(dm, &pStart, &pEnd);CHKERRQ(ierr); 3472aca35d17SMatthew G. Knepley ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr); 3473aca35d17SMatthew G. Knepley ierr = PetscSFGetGraph(sfPoint, &numRoots, &numLeaves, &localPoints, &remotePoints);CHKERRQ(ierr); 3474aca35d17SMatthew G. Knepley if (numRoots >= 0) { 3475aca35d17SMatthew G. Knepley /* Only vertices should be shared */ 3476dcca6d9dSJed Brown ierr = PetscMalloc2(pEnd-pStart,&newLocalPoints,numRoots,&newOwners);CHKERRQ(ierr); 3477bdcf2095SMatthew G. Knepley for (p = 0; p < pEnd-pStart; ++p) { 3478bdcf2095SMatthew G. Knepley newLocalPoints[p].rank = -2; 3479bdcf2095SMatthew G. Knepley newLocalPoints[p].index = -2; 3480bdcf2095SMatthew G. Knepley } 34819e0823b2SMatthew G. Knepley /* Set subleaves */ 3482aca35d17SMatthew G. Knepley for (l = 0; l < numLeaves; ++l) { 3483aca35d17SMatthew G. Knepley const PetscInt point = localPoints[l]; 3484bdcf2095SMatthew G. Knepley const PetscInt subPoint = DMPlexFilterPoint_Internal(point, firstSubVertex, numSubVertices, subVertices); 3485aca35d17SMatthew G. Knepley 3486aca35d17SMatthew G. Knepley if ((point < vStart) && (point >= vEnd)) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Should not be mapping anything but vertices, %d", point); 3487bdcf2095SMatthew G. Knepley if (subPoint < 0) continue; 3488bdcf2095SMatthew G. Knepley newLocalPoints[point-pStart].rank = rank; 3489bdcf2095SMatthew G. Knepley newLocalPoints[point-pStart].index = subPoint; 3490bdcf2095SMatthew G. Knepley ++numSubLeaves; 3491aca35d17SMatthew G. Knepley } 34929e0823b2SMatthew G. Knepley /* Must put in owned subpoints */ 34939e0823b2SMatthew G. Knepley for (p = pStart; p < pEnd; ++p) { 34949e0823b2SMatthew G. Knepley const PetscInt subPoint = DMPlexFilterPoint_Internal(p, firstSubVertex, numSubVertices, subVertices); 34959e0823b2SMatthew G. Knepley 34969e0823b2SMatthew G. Knepley if (subPoint < 0) { 34979e0823b2SMatthew G. Knepley newOwners[p-pStart].rank = -3; 34989e0823b2SMatthew G. Knepley newOwners[p-pStart].index = -3; 34999e0823b2SMatthew G. Knepley } else { 35009e0823b2SMatthew G. Knepley newOwners[p-pStart].rank = rank; 35019e0823b2SMatthew G. Knepley newOwners[p-pStart].index = subPoint; 35029e0823b2SMatthew G. Knepley } 3503bdcf2095SMatthew G. Knepley } 3504bdcf2095SMatthew G. Knepley ierr = PetscSFReduceBegin(sfPoint, MPIU_2INT, newLocalPoints, newOwners, MPI_MAXLOC);CHKERRQ(ierr); 3505bdcf2095SMatthew G. Knepley ierr = PetscSFReduceEnd(sfPoint, MPIU_2INT, newLocalPoints, newOwners, MPI_MAXLOC);CHKERRQ(ierr); 3506bdcf2095SMatthew G. Knepley ierr = PetscSFBcastBegin(sfPoint, MPIU_2INT, newOwners, newLocalPoints);CHKERRQ(ierr); 3507bdcf2095SMatthew G. Knepley ierr = PetscSFBcastEnd(sfPoint, MPIU_2INT, newOwners, newLocalPoints);CHKERRQ(ierr); 3508785e854fSJed Brown ierr = PetscMalloc1(numSubLeaves, &slocalPoints);CHKERRQ(ierr); 3509785e854fSJed Brown ierr = PetscMalloc1(numSubLeaves, &sremotePoints);CHKERRQ(ierr); 351049c26ae4SMatthew G. Knepley for (l = 0, sl = 0, ll = 0; l < numLeaves; ++l) { 3511bdcf2095SMatthew G. Knepley const PetscInt point = localPoints[l]; 3512bdcf2095SMatthew G. Knepley const PetscInt subPoint = DMPlexFilterPoint_Internal(point, firstSubVertex, numSubVertices, subVertices); 3513aca35d17SMatthew G. Knepley 3514aca35d17SMatthew G. Knepley if (subPoint < 0) continue; 351549c26ae4SMatthew G. Knepley if (newLocalPoints[point].rank == rank) {++ll; continue;} 3516aca35d17SMatthew G. Knepley slocalPoints[sl] = subPoint; 3517bdcf2095SMatthew G. Knepley sremotePoints[sl].rank = newLocalPoints[point].rank; 3518bdcf2095SMatthew G. Knepley sremotePoints[sl].index = newLocalPoints[point].index; 3519bdcf2095SMatthew G. Knepley if (sremotePoints[sl].rank < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Invalid remote rank for local point %d", point); 3520bdcf2095SMatthew G. Knepley if (sremotePoints[sl].index < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Invalid remote subpoint for local point %d", point); 3521aca35d17SMatthew G. Knepley ++sl; 3522aca35d17SMatthew G. Knepley } 3523bdcf2095SMatthew G. Knepley ierr = PetscFree2(newLocalPoints,newOwners);CHKERRQ(ierr); 352449c26ae4SMatthew G. Knepley if (sl + ll != numSubLeaves) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Mismatch in number of subleaves %d + %d != %d", sl, ll, numSubLeaves); 352549c26ae4SMatthew G. Knepley ierr = PetscSFSetGraph(sfPointSub, numSubRoots, sl, slocalPoints, PETSC_OWN_POINTER, sremotePoints, PETSC_OWN_POINTER);CHKERRQ(ierr); 3526aca35d17SMatthew G. Knepley } 3527aca35d17SMatthew G. Knepley } 3528aca35d17SMatthew G. Knepley CHKMEMQ; 3529766ab985SMatthew G. Knepley /* Cleanup */ 3530766ab985SMatthew G. Knepley if (subvertexIS) {ierr = ISRestoreIndices(subvertexIS, &subVertices);CHKERRQ(ierr);} 3531766ab985SMatthew G. Knepley ierr = ISDestroy(&subvertexIS);CHKERRQ(ierr); 3532766ab985SMatthew G. Knepley ierr = PetscFree(subCells);CHKERRQ(ierr); 3533766ab985SMatthew G. Knepley PetscFunctionReturn(0); 3534766ab985SMatthew G. Knepley } 3535766ab985SMatthew G. Knepley 35363982b651SMatthew G. Knepley static PetscErrorCode DMPlexCreateCohesiveSubmesh_Interpolated(DM dm, const char labelname[], PetscInt value, DM subdm) 3537766ab985SMatthew G. Knepley { 35383982b651SMatthew G. Knepley DMLabel label = NULL; 3539766ab985SMatthew G. Knepley PetscErrorCode ierr; 3540766ab985SMatthew G. Knepley 3541766ab985SMatthew G. Knepley PetscFunctionBegin; 3542c58f1c22SToby Isaac if (labelname) {ierr = DMGetLabel(dm, labelname, &label);CHKERRQ(ierr);} 3543158acfadSMatthew G. Knepley ierr = DMPlexCreateSubmeshGeneric_Interpolated(dm, label, value, PETSC_FALSE, PETSC_TRUE, 1, subdm);CHKERRQ(ierr); 3544766ab985SMatthew G. Knepley PetscFunctionReturn(0); 3545766ab985SMatthew G. Knepley } 3546766ab985SMatthew G. Knepley 3547c08575a3SMatthew G. Knepley /*@C 354827c04023SMatthew G. Knepley DMPlexCreateCohesiveSubmesh - Extract from a mesh with cohesive cells the hypersurface defined by one face of the cells. Optionally, a Label an be given to restrict the cells. 3549766ab985SMatthew G. Knepley 3550766ab985SMatthew G. Knepley Input Parameters: 3551766ab985SMatthew G. Knepley + dm - The original mesh 355227c04023SMatthew G. Knepley . hasLagrange - The mesh has Lagrange unknowns in the cohesive cells 35537afc1a8bSJed Brown . label - A label name, or NULL 355427c04023SMatthew G. Knepley - value - A label value 3555766ab985SMatthew G. Knepley 3556766ab985SMatthew G. Knepley Output Parameter: 3557766ab985SMatthew G. Knepley . subdm - The surface mesh 3558766ab985SMatthew G. Knepley 3559766ab985SMatthew G. Knepley Note: This function produces a DMLabel mapping original points in the submesh to their depth. This can be obtained using DMPlexGetSubpointMap(). 3560766ab985SMatthew G. Knepley 3561766ab985SMatthew G. Knepley Level: developer 3562766ab985SMatthew G. Knepley 3563766ab985SMatthew G. Knepley .seealso: DMPlexGetSubpointMap(), DMPlexCreateSubmesh() 3564c08575a3SMatthew G. Knepley @*/ 356527c04023SMatthew G. Knepley PetscErrorCode DMPlexCreateCohesiveSubmesh(DM dm, PetscBool hasLagrange, const char label[], PetscInt value, DM *subdm) 3566766ab985SMatthew G. Knepley { 3567c0e8cf5fSMatthew G. Knepley PetscInt dim, cdim, depth; 3568766ab985SMatthew G. Knepley PetscErrorCode ierr; 3569766ab985SMatthew G. Knepley 3570766ab985SMatthew G. Knepley PetscFunctionBegin; 3571766ab985SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 357227c04023SMatthew G. Knepley PetscValidPointer(subdm, 5); 3573c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 3574766ab985SMatthew G. Knepley ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 3575766ab985SMatthew G. Knepley ierr = DMCreate(PetscObjectComm((PetscObject)dm), subdm);CHKERRQ(ierr); 3576766ab985SMatthew G. Knepley ierr = DMSetType(*subdm, DMPLEX);CHKERRQ(ierr); 3577c73cfb54SMatthew G. Knepley ierr = DMSetDimension(*subdm, dim-1);CHKERRQ(ierr); 3578c0e8cf5fSMatthew G. Knepley ierr = DMGetCoordinateDim(dm, &cdim);CHKERRQ(ierr); 3579c0e8cf5fSMatthew G. Knepley ierr = DMSetCoordinateDim(*subdm, cdim);CHKERRQ(ierr); 3580766ab985SMatthew G. Knepley if (depth == dim) { 3581b3154360SMatthew G. Knepley ierr = DMPlexCreateCohesiveSubmesh_Interpolated(dm, label, value, *subdm);CHKERRQ(ierr); 3582766ab985SMatthew G. Knepley } else { 358327c04023SMatthew G. Knepley ierr = DMPlexCreateCohesiveSubmesh_Uninterpolated(dm, hasLagrange, label, value, *subdm);CHKERRQ(ierr); 3584e6ccafaeSMatthew G Knepley } 3585e6ccafaeSMatthew G Knepley PetscFunctionReturn(0); 3586e6ccafaeSMatthew G Knepley } 3587e6ccafaeSMatthew G Knepley 3588bec263e5SMatthew G. Knepley /*@ 3589bec263e5SMatthew G. Knepley DMPlexFilter - Extract a subset of mesh cells defined by a label as a separate mesh 3590bec263e5SMatthew G. Knepley 3591bec263e5SMatthew G. Knepley Input Parameters: 3592bec263e5SMatthew G. Knepley + dm - The original mesh 3593bec263e5SMatthew G. Knepley . cellLabel - The DMLabel marking cells contained in the new mesh 3594bec263e5SMatthew G. Knepley - value - The label value to use 3595bec263e5SMatthew G. Knepley 3596bec263e5SMatthew G. Knepley Output Parameter: 3597bec263e5SMatthew G. Knepley . subdm - The new mesh 3598bec263e5SMatthew G. Knepley 3599bec263e5SMatthew G. Knepley Note: This function produces a DMLabel mapping original points in the submesh to their depth. This can be obtained using DMPlexGetSubpointMap(). 3600bec263e5SMatthew G. Knepley 3601bec263e5SMatthew G. Knepley Level: developer 3602bec263e5SMatthew G. Knepley 3603c58f1c22SToby Isaac .seealso: DMPlexGetSubpointMap(), DMGetLabel(), DMLabelSetValue() 3604bec263e5SMatthew G. Knepley @*/ 3605bec263e5SMatthew G. Knepley PetscErrorCode DMPlexFilter(DM dm, DMLabel cellLabel, PetscInt value, DM *subdm) 3606bec263e5SMatthew G. Knepley { 3607bec263e5SMatthew G. Knepley PetscInt dim; 3608bec263e5SMatthew G. Knepley PetscErrorCode ierr; 3609bec263e5SMatthew G. Knepley 3610bec263e5SMatthew G. Knepley PetscFunctionBegin; 3611bec263e5SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3612bec263e5SMatthew G. Knepley PetscValidPointer(subdm, 3); 3613bec263e5SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 3614bec263e5SMatthew G. Knepley ierr = DMCreate(PetscObjectComm((PetscObject) dm), subdm);CHKERRQ(ierr); 3615bec263e5SMatthew G. Knepley ierr = DMSetType(*subdm, DMPLEX);CHKERRQ(ierr); 3616bec263e5SMatthew G. Knepley ierr = DMSetDimension(*subdm, dim);CHKERRQ(ierr); 3617bec263e5SMatthew G. Knepley /* Extract submesh in place, could be empty on some procs, could have inconsistency if procs do not both extract a shared cell */ 3618158acfadSMatthew G. Knepley ierr = DMPlexCreateSubmeshGeneric_Interpolated(dm, cellLabel, value, PETSC_FALSE, PETSC_FALSE, 0, *subdm);CHKERRQ(ierr); 3619bec263e5SMatthew G. Knepley PetscFunctionReturn(0); 3620bec263e5SMatthew G. Knepley } 3621bec263e5SMatthew G. Knepley 362264beef6dSMatthew G. Knepley /*@ 362364beef6dSMatthew G. Knepley DMPlexGetSubpointMap - Returns a DMLabel with point dimension as values 362464beef6dSMatthew G. Knepley 362564beef6dSMatthew G. Knepley Input Parameter: 362664beef6dSMatthew G. Knepley . dm - The submesh DM 362764beef6dSMatthew G. Knepley 362864beef6dSMatthew G. Knepley Output Parameter: 362964beef6dSMatthew G. Knepley . subpointMap - The DMLabel of all the points from the original mesh in this submesh, or NULL if this is not a submesh 363064beef6dSMatthew G. Knepley 363164beef6dSMatthew G. Knepley Level: developer 363264beef6dSMatthew G. Knepley 363364beef6dSMatthew G. Knepley .seealso: DMPlexCreateSubmesh(), DMPlexCreateSubpointIS() 363464beef6dSMatthew G. Knepley @*/ 3635e6ccafaeSMatthew G Knepley PetscErrorCode DMPlexGetSubpointMap(DM dm, DMLabel *subpointMap) 3636e6ccafaeSMatthew G Knepley { 3637e6ccafaeSMatthew G Knepley PetscFunctionBegin; 3638e6ccafaeSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3639e6ccafaeSMatthew G Knepley PetscValidPointer(subpointMap, 2); 364065663942SMatthew G. Knepley *subpointMap = ((DM_Plex*) dm->data)->subpointMap; 3641e6ccafaeSMatthew G Knepley PetscFunctionReturn(0); 3642e6ccafaeSMatthew G Knepley } 3643e6ccafaeSMatthew G Knepley 3644c08575a3SMatthew G. Knepley /*@ 3645c08575a3SMatthew G. Knepley DMPlexSetSubpointMap - Sets the DMLabel with point dimension as values 3646c08575a3SMatthew G. Knepley 3647c08575a3SMatthew G. Knepley Input Parameters: 3648c08575a3SMatthew G. Knepley + dm - The submesh DM 3649c08575a3SMatthew G. Knepley - subpointMap - The DMLabel of all the points from the original mesh in this submesh 3650c08575a3SMatthew G. Knepley 3651c08575a3SMatthew G. Knepley Note: Should normally not be called by the user, since it is set in DMPlexCreateSubmesh() 3652c08575a3SMatthew G. Knepley 3653c08575a3SMatthew G. Knepley Level: developer 3654c08575a3SMatthew G. Knepley 3655c08575a3SMatthew G. Knepley .seealso: DMPlexCreateSubmesh(), DMPlexCreateSubpointIS() 3656c08575a3SMatthew G. Knepley @*/ 3657e6ccafaeSMatthew G Knepley PetscErrorCode DMPlexSetSubpointMap(DM dm, DMLabel subpointMap) 3658e6ccafaeSMatthew G Knepley { 3659e6ccafaeSMatthew G Knepley DM_Plex *mesh = (DM_Plex *) dm->data; 3660285d324eSMatthew G. Knepley DMLabel tmp; 3661e6ccafaeSMatthew G Knepley PetscErrorCode ierr; 3662e6ccafaeSMatthew G Knepley 3663e6ccafaeSMatthew G Knepley PetscFunctionBegin; 3664e6ccafaeSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3665285d324eSMatthew G. Knepley tmp = mesh->subpointMap; 3666e6ccafaeSMatthew G Knepley mesh->subpointMap = subpointMap; 3667d67d17b1SMatthew G. Knepley ierr = PetscObjectReference((PetscObject) mesh->subpointMap);CHKERRQ(ierr); 3668285d324eSMatthew G. Knepley ierr = DMLabelDestroy(&tmp);CHKERRQ(ierr); 3669e6ccafaeSMatthew G Knepley PetscFunctionReturn(0); 3670e6ccafaeSMatthew G Knepley } 3671e6ccafaeSMatthew G Knepley 367264beef6dSMatthew G. Knepley /*@ 3673e6ccafaeSMatthew G Knepley DMPlexCreateSubpointIS - Creates an IS covering the entire subdm chart with the original points as data 3674e6ccafaeSMatthew G Knepley 3675e6ccafaeSMatthew G Knepley Input Parameter: 3676e6ccafaeSMatthew G Knepley . dm - The submesh DM 3677e6ccafaeSMatthew G Knepley 3678e6ccafaeSMatthew G Knepley Output Parameter: 36790298fd71SBarry Smith . subpointIS - The IS of all the points from the original mesh in this submesh, or NULL if this is not a submesh 3680e6ccafaeSMatthew G Knepley 36813982b651SMatthew G. Knepley Note: This IS is guaranteed to be sorted by the construction of the submesh 368264beef6dSMatthew G. Knepley 368364beef6dSMatthew G. Knepley Level: developer 368464beef6dSMatthew G. Knepley 368564beef6dSMatthew G. Knepley .seealso: DMPlexCreateSubmesh(), DMPlexGetSubpointMap() 368664beef6dSMatthew G. Knepley @*/ 3687e6ccafaeSMatthew G Knepley PetscErrorCode DMPlexCreateSubpointIS(DM dm, IS *subpointIS) 3688e6ccafaeSMatthew G Knepley { 368982f516ccSBarry Smith MPI_Comm comm; 3690e6ccafaeSMatthew G Knepley DMLabel subpointMap; 3691e6ccafaeSMatthew G Knepley IS is; 3692e6ccafaeSMatthew G Knepley const PetscInt *opoints; 3693e6ccafaeSMatthew G Knepley PetscInt *points, *depths; 3694e6ccafaeSMatthew G Knepley PetscInt depth, depStart, depEnd, d, pStart, pEnd, p, n, off; 3695e6ccafaeSMatthew G Knepley PetscErrorCode ierr; 3696e6ccafaeSMatthew G Knepley 3697e6ccafaeSMatthew G Knepley PetscFunctionBegin; 3698e6ccafaeSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3699e6ccafaeSMatthew G Knepley PetscValidPointer(subpointIS, 2); 370082f516ccSBarry Smith ierr = PetscObjectGetComm((PetscObject)dm,&comm);CHKERRQ(ierr); 37010298fd71SBarry Smith *subpointIS = NULL; 3702e6ccafaeSMatthew G Knepley ierr = DMPlexGetSubpointMap(dm, &subpointMap);CHKERRQ(ierr); 3703e6ccafaeSMatthew G Knepley ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 3704fed694aaSMatthew G. Knepley if (subpointMap && depth >= 0) { 3705e6ccafaeSMatthew G Knepley ierr = DMPlexGetChart(dm, &pStart, &pEnd);CHKERRQ(ierr); 3706e6ccafaeSMatthew G Knepley if (pStart) SETERRQ1(comm, PETSC_ERR_ARG_WRONG, "Submeshes must start the point numbering at 0, not %d", pStart); 370769291d52SBarry Smith ierr = DMGetWorkArray(dm, depth+1, MPIU_INT, &depths);CHKERRQ(ierr); 3708e6ccafaeSMatthew G Knepley depths[0] = depth; 3709e6ccafaeSMatthew G Knepley depths[1] = 0; 3710e6ccafaeSMatthew G Knepley for(d = 2; d <= depth; ++d) {depths[d] = depth+1 - d;} 3711785e854fSJed Brown ierr = PetscMalloc1(pEnd, &points);CHKERRQ(ierr); 3712e6ccafaeSMatthew G Knepley for(d = 0, off = 0; d <= depth; ++d) { 3713e6ccafaeSMatthew G Knepley const PetscInt dep = depths[d]; 3714e6ccafaeSMatthew G Knepley 3715e6ccafaeSMatthew G Knepley ierr = DMPlexGetDepthStratum(dm, dep, &depStart, &depEnd);CHKERRQ(ierr); 3716e6ccafaeSMatthew G Knepley ierr = DMLabelGetStratumSize(subpointMap, dep, &n);CHKERRQ(ierr); 37171e21b6fdSMatthew G Knepley if (((d < 2) && (depth > 1)) || (d == 1)) { /* Only check vertices and cells for now since the map is broken for others */ 3718e6ccafaeSMatthew G Knepley if (n != depEnd-depStart) SETERRQ3(comm, PETSC_ERR_ARG_WRONG, "The number of mapped submesh points %d at depth %d should be %d", n, dep, depEnd-depStart); 3719e6ccafaeSMatthew G Knepley } else { 37201e21b6fdSMatthew G Knepley if (!n) { 37211e21b6fdSMatthew G Knepley if (d == 0) { 37221e21b6fdSMatthew G Knepley /* Missing cells */ 37231e21b6fdSMatthew G Knepley for(p = 0; p < depEnd-depStart; ++p, ++off) points[off] = -1; 37241e21b6fdSMatthew G Knepley } else { 37251e21b6fdSMatthew G Knepley /* Missing faces */ 37261e21b6fdSMatthew G Knepley for(p = 0; p < depEnd-depStart; ++p, ++off) points[off] = PETSC_MAX_INT; 37271e21b6fdSMatthew G Knepley } 37281e21b6fdSMatthew G Knepley } 3729e6ccafaeSMatthew G Knepley } 3730e6ccafaeSMatthew G Knepley if (n) { 3731e6ccafaeSMatthew G Knepley ierr = DMLabelGetStratumIS(subpointMap, dep, &is);CHKERRQ(ierr); 3732e6ccafaeSMatthew G Knepley ierr = ISGetIndices(is, &opoints);CHKERRQ(ierr); 3733e6ccafaeSMatthew G Knepley for(p = 0; p < n; ++p, ++off) points[off] = opoints[p]; 3734e6ccafaeSMatthew G Knepley ierr = ISRestoreIndices(is, &opoints);CHKERRQ(ierr); 3735e6ccafaeSMatthew G Knepley ierr = ISDestroy(&is);CHKERRQ(ierr); 3736e6ccafaeSMatthew G Knepley } 3737e6ccafaeSMatthew G Knepley } 373869291d52SBarry Smith ierr = DMRestoreWorkArray(dm, depth+1, MPIU_INT, &depths);CHKERRQ(ierr); 3739e6ccafaeSMatthew G Knepley if (off != pEnd) SETERRQ2(comm, PETSC_ERR_ARG_WRONG, "The number of mapped submesh points %d should be %d", off, pEnd); 3740fed694aaSMatthew G. Knepley ierr = ISCreateGeneral(PETSC_COMM_SELF, pEnd, points, PETSC_OWN_POINTER, subpointIS);CHKERRQ(ierr); 3741e6ccafaeSMatthew G Knepley } 3742e6ccafaeSMatthew G Knepley PetscFunctionReturn(0); 3743e6ccafaeSMatthew G Knepley } 3744559a1558SMatthew G. Knepley 3745559a1558SMatthew G. Knepley /*@ 3746a6e0b375SMatthew G. Knepley DMGetEnclosureRelation - Get the relationship between dmA and dmB 3747559a1558SMatthew G. Knepley 3748559a1558SMatthew G. Knepley Input Parameters: 3749a6e0b375SMatthew G. Knepley + dmA - The first DM 3750a6e0b375SMatthew G. Knepley - dmB - The second DM 3751559a1558SMatthew G. Knepley 3752559a1558SMatthew G. Knepley Output Parameter: 3753a6e0b375SMatthew G. Knepley . rel - The relation of dmA to dmB 3754559a1558SMatthew G. Knepley 3755a6e0b375SMatthew G. Knepley Level: intermediate 3756559a1558SMatthew G. Knepley 3757a6e0b375SMatthew G. Knepley .seealso: DMPlexGetEnclosurePoint() 3758559a1558SMatthew G. Knepley @*/ 3759a6e0b375SMatthew G. Knepley PetscErrorCode DMGetEnclosureRelation(DM dmA, DM dmB, DMEnclosureType *rel) 3760559a1558SMatthew G. Knepley { 3761a6e0b375SMatthew G. Knepley DM plexA, plexB, sdm; 3762559a1558SMatthew G. Knepley DMLabel spmap; 3763a6e0b375SMatthew G. Knepley PetscInt pStartA, pEndA, pStartB, pEndB, NpA, NpB; 3764559a1558SMatthew G. Knepley PetscErrorCode ierr; 3765559a1558SMatthew G. Knepley 376644171101SMatthew G. Knepley PetscFunctionBegin; 3767a6e0b375SMatthew G. Knepley PetscValidPointer(rel, 3); 3768a6e0b375SMatthew G. Knepley *rel = DM_ENC_NONE; 3769a6e0b375SMatthew G. Knepley if (!dmA || !dmB) PetscFunctionReturn(0); 3770a6e0b375SMatthew G. Knepley PetscValidHeaderSpecific(dmA, DM_CLASSID, 1); 3771a6e0b375SMatthew G. Knepley PetscValidHeaderSpecific(dmB, DM_CLASSID, 1); 3772a6e0b375SMatthew G. Knepley if (dmA == dmB) {*rel = DM_ENC_EQUALITY; PetscFunctionReturn(0);} 3773a6e0b375SMatthew G. Knepley ierr = DMConvert(dmA, DMPLEX, &plexA);CHKERRQ(ierr); 3774a6e0b375SMatthew G. Knepley ierr = DMConvert(dmB, DMPLEX, &plexB);CHKERRQ(ierr); 3775a6e0b375SMatthew G. Knepley ierr = DMPlexGetChart(plexA, &pStartA, &pEndA);CHKERRQ(ierr); 3776a6e0b375SMatthew G. Knepley ierr = DMPlexGetChart(plexB, &pStartB, &pEndB);CHKERRQ(ierr); 3777a6e0b375SMatthew G. Knepley /* Assumption 1: subDMs have smaller charts than the DMs that they originate from 3778a6e0b375SMatthew G. Knepley - The degenerate case of a subdomain which includes all of the domain on some process can be treated as equality */ 3779a6e0b375SMatthew G. Knepley if ((pStartA == pStartB) && (pEndA == pEndB)) { 3780a6e0b375SMatthew G. Knepley *rel = DM_ENC_EQUALITY; 3781a6e0b375SMatthew G. Knepley goto end; 3782559a1558SMatthew G. Knepley } 3783a6e0b375SMatthew G. Knepley NpA = pEndA - pStartA; 3784a6e0b375SMatthew G. Knepley NpB = pEndB - pStartB; 3785a6e0b375SMatthew G. Knepley if (NpA == NpB) goto end; 3786a6e0b375SMatthew G. Knepley sdm = NpA > NpB ? plexB : plexA; /* The other is the original, enclosing dm */ 3787a6e0b375SMatthew G. Knepley ierr = DMPlexGetSubpointMap(sdm, &spmap);CHKERRQ(ierr); 3788a6e0b375SMatthew G. Knepley if (!spmap) goto end; 3789a6e0b375SMatthew G. Knepley /* TODO Check the space mapped to by subpointMap is same size as dm */ 3790a6e0b375SMatthew G. Knepley if (NpA > NpB) { 3791a6e0b375SMatthew G. Knepley *rel = DM_ENC_SUPERMESH; 3792a6e0b375SMatthew G. Knepley } else { 3793a6e0b375SMatthew G. Knepley *rel = DM_ENC_SUBMESH; 3794a6e0b375SMatthew G. Knepley } 3795a6e0b375SMatthew G. Knepley end: 3796a6e0b375SMatthew G. Knepley ierr = DMDestroy(&plexA);CHKERRQ(ierr); 3797a6e0b375SMatthew G. Knepley ierr = DMDestroy(&plexB);CHKERRQ(ierr); 3798559a1558SMatthew G. Knepley PetscFunctionReturn(0); 3799559a1558SMatthew G. Knepley } 380044171101SMatthew G. Knepley 380144171101SMatthew G. Knepley /*@ 3802a6e0b375SMatthew G. Knepley DMGetEnclosurePoint - Get the point pA in dmA which corresponds to the point pB in dmB 380344171101SMatthew G. Knepley 380444171101SMatthew G. Knepley Input Parameters: 3805a6e0b375SMatthew G. Knepley + dmA - The first DM 3806a6e0b375SMatthew G. Knepley . dmB - The second DM 3807a6e0b375SMatthew G. Knepley . etype - The type of enclosure relation that dmA has to dmB 3808a6e0b375SMatthew G. Knepley - pB - A point of dmB 380944171101SMatthew G. Knepley 381044171101SMatthew G. Knepley Output Parameter: 3811a6e0b375SMatthew G. Knepley . pA - The corresponding point of dmA 381244171101SMatthew G. Knepley 3813a6e0b375SMatthew G. Knepley Level: intermediate 381444171101SMatthew G. Knepley 3815a6e0b375SMatthew G. Knepley .seealso: DMGetEnclosureRelation() 381644171101SMatthew G. Knepley @*/ 3817a6e0b375SMatthew G. Knepley PetscErrorCode DMGetEnclosurePoint(DM dmA, DM dmB, DMEnclosureType etype, PetscInt pB, PetscInt *pA) 381844171101SMatthew G. Knepley { 3819a6e0b375SMatthew G. Knepley DM sdm; 382044171101SMatthew G. Knepley DMLabel spmap; 3821a6e0b375SMatthew G. Knepley IS subpointIS; 3822a6e0b375SMatthew G. Knepley const PetscInt *subpoints; 3823a6e0b375SMatthew G. Knepley PetscInt numSubpoints; 382444171101SMatthew G. Knepley PetscErrorCode ierr; 382544171101SMatthew G. Knepley 382644171101SMatthew G. Knepley PetscFunctionBegin; 3827a6e0b375SMatthew G. Knepley /* TODO Cache the IS, making it look like an index */ 3828a6e0b375SMatthew G. Knepley switch (etype) { 3829a6e0b375SMatthew G. Knepley case DM_ENC_SUPERMESH: 3830a6e0b375SMatthew G. Knepley sdm = dmB; 3831a6e0b375SMatthew G. Knepley ierr = DMPlexGetSubpointMap(sdm, &spmap);CHKERRQ(ierr); 3832a6e0b375SMatthew G. Knepley ierr = DMPlexCreateSubpointIS(sdm, &subpointIS);CHKERRQ(ierr); 3833a6e0b375SMatthew G. Knepley ierr = ISGetIndices(subpointIS, &subpoints);CHKERRQ(ierr); 3834a6e0b375SMatthew G. Knepley *pA = subpoints[pB]; 3835a6e0b375SMatthew G. Knepley ierr = ISRestoreIndices(subpointIS, &subpoints);CHKERRQ(ierr); 3836a6e0b375SMatthew G. Knepley ierr = ISDestroy(&subpointIS);CHKERRQ(ierr); 3837a6e0b375SMatthew G. Knepley break; 3838a6e0b375SMatthew G. Knepley case DM_ENC_SUBMESH: 3839a6e0b375SMatthew G. Knepley sdm = dmA; 3840a6e0b375SMatthew G. Knepley ierr = DMPlexGetSubpointMap(sdm, &spmap);CHKERRQ(ierr); 3841a6e0b375SMatthew G. Knepley ierr = DMPlexCreateSubpointIS(sdm, &subpointIS);CHKERRQ(ierr); 3842a6e0b375SMatthew G. Knepley ierr = ISGetLocalSize(subpointIS, &numSubpoints);CHKERRQ(ierr); 3843a6e0b375SMatthew G. Knepley ierr = ISGetIndices(subpointIS, &subpoints);CHKERRQ(ierr); 3844a6e0b375SMatthew G. Knepley ierr = PetscFindInt(pB, numSubpoints, subpoints, pA);CHKERRQ(ierr); 3845a6e0b375SMatthew G. Knepley if (*pA < 0) { 3846a6e0b375SMatthew G. Knepley ierr = DMViewFromOptions(dmA, NULL, "-dm_enc_A_view");CHKERRQ(ierr); 3847a6e0b375SMatthew G. Knepley ierr = DMViewFromOptions(dmB, NULL, "-dm_enc_B_view");CHKERRQ(ierr); 3848a6e0b375SMatthew G. Knepley SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Point %d not found in submesh", pB); 3849a6e0b375SMatthew G. Knepley } 3850a6e0b375SMatthew G. Knepley ierr = ISRestoreIndices(subpointIS, &subpoints);CHKERRQ(ierr); 3851a6e0b375SMatthew G. Knepley ierr = ISDestroy(&subpointIS);CHKERRQ(ierr); 3852a6e0b375SMatthew G. Knepley break; 3853a6e0b375SMatthew G. Knepley case DM_ENC_EQUALITY: 3854a6e0b375SMatthew G. Knepley case DM_ENC_NONE: 3855a6e0b375SMatthew G. Knepley *pA = pB;break; 3856a6e0b375SMatthew G. Knepley case DM_ENC_UNKNOWN: 3857a6e0b375SMatthew G. Knepley { 3858a6e0b375SMatthew G. Knepley DMEnclosureType enc; 385944171101SMatthew G. Knepley 3860a6e0b375SMatthew G. Knepley ierr = DMGetEnclosureRelation(dmA, dmB, &enc);CHKERRQ(ierr); 3861a6e0b375SMatthew G. Knepley ierr = DMGetEnclosurePoint(dmA, dmB, enc, pB, pA);CHKERRQ(ierr); 3862a6e0b375SMatthew G. Knepley } 3863a6e0b375SMatthew G. Knepley break; 3864a6e0b375SMatthew G. Knepley default: SETERRQ1(PetscObjectComm((PetscObject) dmA), PETSC_ERR_ARG_OUTOFRANGE, "Invalid enclosure type %d", (int) etype); 386544171101SMatthew G. Knepley } 386644171101SMatthew G. Knepley PetscFunctionReturn(0); 386744171101SMatthew G. Knepley } 3868