xref: /petsc/src/dm/impls/plex/plexrefine.c (revision 3fe31fa29bf1bd75ee57c8d4c344699ef3f6a635)
1af0996ceSBarry Smith #include <petsc/private/dmpleximpl.h>   /*I      "petscdmplex.h"   I*/
275d3a19aSMatthew G. Knepley #include <petscsf.h>
375d3a19aSMatthew G. Knepley 
475d3a19aSMatthew G. Knepley #undef __FUNCT__
575d3a19aSMatthew G. Knepley #define __FUNCT__ "GetDepthStart_Private"
675d3a19aSMatthew G. Knepley PETSC_STATIC_INLINE PetscErrorCode GetDepthStart_Private(PetscInt depth, PetscInt depthSize[], PetscInt *cStart, PetscInt *fStart, PetscInt *eStart, PetscInt *vStart)
775d3a19aSMatthew G. Knepley {
875d3a19aSMatthew G. Knepley   PetscFunctionBegin;
975d3a19aSMatthew G. Knepley   if (cStart) *cStart = 0;
1015fa1f8eSMatthew G. Knepley   if (vStart) *vStart = depth < 0 ? 0 : depthSize[depth];
1115fa1f8eSMatthew G. Knepley   if (fStart) *fStart = depth < 0 ? 0 : depthSize[depth] + depthSize[0];
1215fa1f8eSMatthew G. Knepley   if (eStart) *eStart = depth < 0 ? 0 : depthSize[depth] + depthSize[0] + depthSize[depth-1];
1375d3a19aSMatthew G. Knepley   PetscFunctionReturn(0);
1475d3a19aSMatthew G. Knepley }
1575d3a19aSMatthew G. Knepley 
1675d3a19aSMatthew G. Knepley #undef __FUNCT__
1775d3a19aSMatthew G. Knepley #define __FUNCT__ "GetDepthEnd_Private"
1875d3a19aSMatthew G. Knepley PETSC_STATIC_INLINE PetscErrorCode GetDepthEnd_Private(PetscInt depth, PetscInt depthSize[], PetscInt *cEnd, PetscInt *fEnd, PetscInt *eEnd, PetscInt *vEnd)
1975d3a19aSMatthew G. Knepley {
2075d3a19aSMatthew G. Knepley   PetscFunctionBegin;
2115fa1f8eSMatthew G. Knepley   if (cEnd) *cEnd = depth < 0 ? 0 : depthSize[depth];
2215fa1f8eSMatthew G. Knepley   if (vEnd) *vEnd = depth < 0 ? 0 : depthSize[depth] + depthSize[0];
2315fa1f8eSMatthew G. Knepley   if (fEnd) *fEnd = depth < 0 ? 0 : depthSize[depth] + depthSize[0] + depthSize[depth-1];
2415fa1f8eSMatthew G. Knepley   if (eEnd) *eEnd = depth < 0 ? 0 : depthSize[depth] + depthSize[0] + depthSize[depth-1] + depthSize[1];
2575d3a19aSMatthew G. Knepley   PetscFunctionReturn(0);
2675d3a19aSMatthew G. Knepley }
2775d3a19aSMatthew G. Knepley 
2875d3a19aSMatthew G. Knepley #undef __FUNCT__
29bed052eaSMatthew G. Knepley #define __FUNCT__ "CellRefinerGetAffineTransforms_Internal"
30bed052eaSMatthew G. Knepley /* Gets the affine map from the original cell to each subcell */
31bed052eaSMatthew G. Knepley PetscErrorCode CellRefinerGetAffineTransforms_Internal(CellRefiner refiner, PetscInt *numSubcells, PetscReal *v0[], PetscReal *jac[], PetscReal *invjac[])
32bed052eaSMatthew G. Knepley {
33bed052eaSMatthew G. Knepley   PetscReal     *v = NULL, *j = NULL, *invj = NULL, detJ;
34bed052eaSMatthew G. Knepley   PetscInt       dim, s;
35bed052eaSMatthew G. Knepley   PetscErrorCode ierr;
36bed052eaSMatthew G. Knepley 
37bed052eaSMatthew G. Knepley   PetscFunctionBegin;
38bed052eaSMatthew G. Knepley   switch (refiner) {
399b1a0e7fSLawrence Mitchell   case REFINER_NOOP: break;
409b1a0e7fSLawrence Mitchell   case REFINER_SIMPLEX_2D:
41260b6d3fSMatthew G. Knepley     /*
42260b6d3fSMatthew G. Knepley      2
43260b6d3fSMatthew G. Knepley      |\
44260b6d3fSMatthew G. Knepley      | \
45260b6d3fSMatthew G. Knepley      |  \
46260b6d3fSMatthew G. Knepley      |   \
47260b6d3fSMatthew G. Knepley      | C  \
48260b6d3fSMatthew G. Knepley      |     \
49260b6d3fSMatthew G. Knepley      |      \
50260b6d3fSMatthew G. Knepley      2---1---1
51260b6d3fSMatthew G. Knepley      |\  D  / \
52260b6d3fSMatthew G. Knepley      | 2   0   \
53260b6d3fSMatthew G. Knepley      |A \ /  B  \
54260b6d3fSMatthew G. Knepley      0---0-------1
55260b6d3fSMatthew G. Knepley      */
56bed052eaSMatthew G. Knepley     dim = 2;
57bed052eaSMatthew G. Knepley     if (numSubcells) *numSubcells = 4;
58bed052eaSMatthew G. Knepley     if (v0) {
59bed052eaSMatthew G. Knepley       ierr = PetscMalloc3(4*dim,&v,4*dim*dim,&j,4*dim*dim,&invj);CHKERRQ(ierr);
60bed052eaSMatthew G. Knepley       /* A */
61bed052eaSMatthew G. Knepley       v[0+0] = -1.0; v[0+1] = -1.0;
62bed052eaSMatthew G. Knepley       j[0+0] =  0.5; j[0+1] =  0.0;
63bed052eaSMatthew G. Knepley       j[0+2] =  0.0; j[0+3] =  0.5;
64bed052eaSMatthew G. Knepley       /* B */
65bed052eaSMatthew G. Knepley       v[2+0] =  0.0; v[2+1] = -1.0;
66bed052eaSMatthew G. Knepley       j[4+0] =  0.5; j[4+1] =  0.0;
67bed052eaSMatthew G. Knepley       j[4+2] =  0.0; j[4+3] =  0.5;
68bed052eaSMatthew G. Knepley       /* C */
69bed052eaSMatthew G. Knepley       v[4+0] = -1.0; v[4+1] =  0.0;
70bed052eaSMatthew G. Knepley       j[8+0] =  0.5; j[8+1] =  0.0;
71bed052eaSMatthew G. Knepley       j[8+2] =  0.0; j[8+3] =  0.5;
72bed052eaSMatthew G. Knepley       /* D */
73bed052eaSMatthew G. Knepley       v[6+0]  =  0.0; v[6+1]  = -1.0;
74bed052eaSMatthew G. Knepley       j[12+0] =  0.0; j[12+1] = -0.5;
75bed052eaSMatthew G. Knepley       j[12+2] =  0.5; j[12+3] =  0.5;
76bed052eaSMatthew G. Knepley       for (s = 0; s < 4; ++s) {
77bed052eaSMatthew G. Knepley         DMPlex_Det2D_Internal(&detJ, &j[s*dim*dim]);
78bed052eaSMatthew G. Knepley         DMPlex_Invert2D_Internal(&invj[s*dim*dim], &j[s*dim*dim], detJ);
79bed052eaSMatthew G. Knepley       }
80bed052eaSMatthew G. Knepley     }
81bed052eaSMatthew G. Knepley     break;
829b1a0e7fSLawrence Mitchell   case REFINER_HEX_2D:
83260b6d3fSMatthew G. Knepley     /*
84260b6d3fSMatthew G. Knepley      3---------2---------2
85260b6d3fSMatthew G. Knepley      |         |         |
86260b6d3fSMatthew G. Knepley      |    D    2    C    |
87260b6d3fSMatthew G. Knepley      |         |         |
88260b6d3fSMatthew G. Knepley      3----3----0----1----1
89260b6d3fSMatthew G. Knepley      |         |         |
90260b6d3fSMatthew G. Knepley      |    A    0    B    |
91260b6d3fSMatthew G. Knepley      |         |         |
92260b6d3fSMatthew G. Knepley      0---------0---------1
93260b6d3fSMatthew G. Knepley      */
94260b6d3fSMatthew G. Knepley     dim = 2;
95260b6d3fSMatthew G. Knepley     if (numSubcells) *numSubcells = 4;
96260b6d3fSMatthew G. Knepley     if (v0) {
97260b6d3fSMatthew G. Knepley       ierr = PetscMalloc3(4*dim,&v,4*dim*dim,&j,4*dim*dim,&invj);CHKERRQ(ierr);
98260b6d3fSMatthew G. Knepley       /* A */
99260b6d3fSMatthew G. Knepley       v[0+0] = -1.0; v[0+1] = -1.0;
100260b6d3fSMatthew G. Knepley       j[0+0] =  0.5; j[0+1] =  0.0;
101260b6d3fSMatthew G. Knepley       j[0+2] =  0.0; j[0+3] =  0.5;
102260b6d3fSMatthew G. Knepley       /* B */
103260b6d3fSMatthew G. Knepley       v[2+0] =  0.0; v[2+1] = -1.0;
104260b6d3fSMatthew G. Knepley       j[4+0] =  0.5; j[4+1] =  0.0;
105260b6d3fSMatthew G. Knepley       j[4+2] =  0.0; j[4+3] =  0.5;
106260b6d3fSMatthew G. Knepley       /* C */
107260b6d3fSMatthew G. Knepley       v[4+0] =  0.0; v[4+1] =  0.0;
108260b6d3fSMatthew G. Knepley       j[8+0] =  0.5; j[8+1] =  0.0;
109260b6d3fSMatthew G. Knepley       j[8+2] =  0.0; j[8+3] =  0.5;
110260b6d3fSMatthew G. Knepley       /* D */
111260b6d3fSMatthew G. Knepley       v[6+0]  = -1.0; v[6+1]  =  0.0;
112260b6d3fSMatthew G. Knepley       j[12+0] =  0.5; j[12+1] =  0.0;
113260b6d3fSMatthew G. Knepley       j[12+2] =  0.0; j[12+3] =  0.5;
114260b6d3fSMatthew G. Knepley       for (s = 0; s < 4; ++s) {
115260b6d3fSMatthew G. Knepley         DMPlex_Det2D_Internal(&detJ, &j[s*dim*dim]);
116260b6d3fSMatthew G. Knepley         DMPlex_Invert2D_Internal(&invj[s*dim*dim], &j[s*dim*dim], detJ);
117260b6d3fSMatthew G. Knepley       }
118260b6d3fSMatthew G. Knepley     }
119260b6d3fSMatthew G. Knepley     break;
120bed052eaSMatthew G. Knepley   default:
121bed052eaSMatthew G. Knepley     SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Unknown cell refiner %d", refiner);
122bed052eaSMatthew G. Knepley   }
123bed052eaSMatthew G. Knepley   if (v0) {*v0 = v; *jac = j; *invjac = invj;}
124bed052eaSMatthew G. Knepley   PetscFunctionReturn(0);
125bed052eaSMatthew G. Knepley }
126bed052eaSMatthew G. Knepley 
127bed052eaSMatthew G. Knepley #undef __FUNCT__
128bed052eaSMatthew G. Knepley #define __FUNCT__ "CellRefinerRestoreAffineTransforms_Internal"
129bed052eaSMatthew G. Knepley PetscErrorCode CellRefinerRestoreAffineTransforms_Internal(CellRefiner refiner, PetscInt *numSubcells, PetscReal *v0[], PetscReal *jac[], PetscReal *invjac[])
130bed052eaSMatthew G. Knepley {
131bed052eaSMatthew G. Knepley   PetscErrorCode ierr;
132bed052eaSMatthew G. Knepley 
133bed052eaSMatthew G. Knepley   PetscFunctionBegin;
134bed052eaSMatthew G. Knepley   ierr = PetscFree3(*v0,*jac,*invjac);CHKERRQ(ierr);
135bed052eaSMatthew G. Knepley   PetscFunctionReturn(0);
136bed052eaSMatthew G. Knepley }
137bed052eaSMatthew G. Knepley 
138bed052eaSMatthew G. Knepley #undef __FUNCT__
13980389061SMatthew G. Knepley #define __FUNCT__ "CellRefinerInCellTest_Internal"
14080389061SMatthew G. Knepley /* Should this be here or in the DualSpace somehow? */
14180389061SMatthew G. Knepley PetscErrorCode CellRefinerInCellTest_Internal(CellRefiner refiner, const PetscReal point[], PetscBool *inside)
14280389061SMatthew G. Knepley {
14380389061SMatthew G. Knepley   PetscReal sum = 0.0;
14480389061SMatthew G. Knepley   PetscInt  d;
14580389061SMatthew G. Knepley 
14680389061SMatthew G. Knepley   PetscFunctionBegin;
14780389061SMatthew G. Knepley   *inside = PETSC_TRUE;
14880389061SMatthew G. Knepley   switch (refiner) {
1499b1a0e7fSLawrence Mitchell   case REFINER_NOOP: break;
1506c0c04f5SMatthew G. Knepley   case REFINER_SIMPLEX_2D:
15180389061SMatthew G. Knepley     for (d = 0; d < 2; ++d) {
15280389061SMatthew G. Knepley       if (point[d] < -1.0) {*inside = PETSC_FALSE; break;}
15380389061SMatthew G. Knepley       sum += point[d];
15480389061SMatthew G. Knepley     }
15580389061SMatthew G. Knepley     if (sum > 0.0) {*inside = PETSC_FALSE; break;}
15680389061SMatthew G. Knepley     break;
1576c0c04f5SMatthew G. Knepley   case REFINER_HEX_2D:
15880389061SMatthew G. Knepley     for (d = 0; d < 2; ++d) if ((point[d] < -1.0) || (point[d] > 1.0)) {*inside = PETSC_FALSE; break;}
15980389061SMatthew G. Knepley     break;
16080389061SMatthew G. Knepley   default:
16180389061SMatthew G. Knepley     SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Unknown cell refiner %d", refiner);
16280389061SMatthew G. Knepley   }
16380389061SMatthew G. Knepley   PetscFunctionReturn(0);
16480389061SMatthew G. Knepley }
16580389061SMatthew G. Knepley 
16680389061SMatthew G. Knepley #undef __FUNCT__
16775d3a19aSMatthew G. Knepley #define __FUNCT__ "CellRefinerGetSizes"
16886150812SJed Brown static PetscErrorCode CellRefinerGetSizes(CellRefiner refiner, DM dm, PetscInt depthSize[])
16975d3a19aSMatthew G. Knepley {
1706ce3c06aSMatthew G. Knepley   PetscInt       cStart, cEnd, cMax, vStart, vEnd, vMax, fStart, fEnd, fMax, eStart, eEnd, eMax;
17175d3a19aSMatthew G. Knepley   PetscErrorCode ierr;
17275d3a19aSMatthew G. Knepley 
17375d3a19aSMatthew G. Knepley   PetscFunctionBegin;
17475d3a19aSMatthew G. Knepley   ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr);
17575d3a19aSMatthew G. Knepley   ierr = DMPlexGetDepthStratum(dm, 1, &eStart, &eEnd);CHKERRQ(ierr);
17675d3a19aSMatthew G. Knepley   ierr = DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd);CHKERRQ(ierr);
17775d3a19aSMatthew G. Knepley   ierr = DMPlexGetHeightStratum(dm, 1, &fStart, &fEnd);CHKERRQ(ierr);
17875d3a19aSMatthew G. Knepley   ierr = DMPlexGetHybridBounds(dm, &cMax, &fMax, &eMax, &vMax);CHKERRQ(ierr);
17975d3a19aSMatthew G. Knepley   switch (refiner) {
1809b1a0e7fSLawrence Mitchell   case REFINER_NOOP:
1813478d7aaSMatthew G. Knepley     break;
1820314a74cSLawrence Mitchell   case REFINER_SIMPLEX_1D:
1830314a74cSLawrence Mitchell     depthSize[0] = vEnd - vStart + cEnd - cStart;         /* Add a vertex on every cell. */
1840314a74cSLawrence Mitchell     depthSize[1] = 2*(cEnd - cStart);                     /* Split every cell in 2. */
1850314a74cSLawrence Mitchell     break;
1869b1a0e7fSLawrence Mitchell   case REFINER_SIMPLEX_2D:
18775d3a19aSMatthew G. Knepley     depthSize[0] = vEnd - vStart + fEnd - fStart;         /* Add a vertex on every face */
18875d3a19aSMatthew G. Knepley     depthSize[1] = 2*(fEnd - fStart) + 3*(cEnd - cStart); /* Every face is split into 2 faces and 3 faces are added for each cell */
18975d3a19aSMatthew G. Knepley     depthSize[2] = 4*(cEnd - cStart);                     /* Every cell split into 4 cells */
19075d3a19aSMatthew G. Knepley     break;
1919b1a0e7fSLawrence Mitchell   case REFINER_HYBRID_SIMPLEX_2D:
19275d3a19aSMatthew G. Knepley     if (cMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No cell maximum specified in hybrid mesh");
19375d3a19aSMatthew G. Knepley     if (fMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No face maximum specified in hybrid mesh");
19475d3a19aSMatthew G. Knepley     depthSize[0] = vEnd - vStart + fMax - fStart;                                         /* Add a vertex on every face, but not hybrid faces */
19575d3a19aSMatthew G. Knepley     depthSize[1] = 2*(fMax - fStart) + 3*(cMax - cStart) + (fEnd - fMax) + (cEnd - cMax); /* Every interior face is split into 2 faces, 3 faces are added for each interior cell, and one in each hybrid cell */
19675d3a19aSMatthew G. Knepley     depthSize[2] = 4*(cMax - cStart) + 2*(cEnd - cMax);                                   /* Interior cells split into 4 cells, Hybrid cells split into 2 cells */
19775d3a19aSMatthew G. Knepley     break;
1989b1a0e7fSLawrence Mitchell   case REFINER_HEX_2D:
199149f48fdSMatthew G. Knepley     depthSize[0] = vEnd - vStart + fEnd - fStart + cEnd - cStart; /* Add a vertex on every face and cell */
20075d3a19aSMatthew G. Knepley     depthSize[1] = 2*(fEnd - fStart) + 4*(cEnd - cStart);         /* Every face is split into 2 faces and 4 faces are added for each cell */
20175d3a19aSMatthew G. Knepley     depthSize[2] = 4*(cEnd - cStart);                             /* Every cell split into 4 cells */
20275d3a19aSMatthew G. Knepley     break;
2039b1a0e7fSLawrence Mitchell   case REFINER_HYBRID_HEX_2D:
204a97b51b8SMatthew G. Knepley     if (cMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No cell maximum specified in hybrid mesh");
205a97b51b8SMatthew G. Knepley     if (fMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No face maximum specified in hybrid mesh");
206a97b51b8SMatthew G. Knepley     /* Quadrilateral */
207a97b51b8SMatthew G. Knepley     depthSize[0] = vEnd - vStart + fMax - fStart + cMax - cStart;                 /* Add a vertex on every face and cell */
208a97b51b8SMatthew G. Knepley     depthSize[1] = 2*(fMax - fStart) + 4*(cMax - cStart);                         /* Every face is split into 2 faces, and 4 faces are added for each cell */
209a97b51b8SMatthew G. Knepley     depthSize[2] = 4*(cMax - cStart);                                             /* Every cell split into 4 cells */
210a97b51b8SMatthew G. Knepley     /* Segment Prisms */
211a97b51b8SMatthew G. Knepley     depthSize[0] += 0;                                                            /* No hybrid vertices */
212a97b51b8SMatthew G. Knepley     depthSize[1] +=   (fEnd - fMax)  +   (cEnd - cMax);                           /* Every hybrid face remains and 1 faces is added for each hybrid cell */
213a97b51b8SMatthew G. Knepley     depthSize[2] += 2*(cEnd - cMax);                                              /* Every hybrid cell split into 2 cells */
214a97b51b8SMatthew G. Knepley     break;
2159b1a0e7fSLawrence Mitchell   case REFINER_SIMPLEX_3D:
216b5da9499SMatthew G. Knepley     depthSize[0] =    vEnd - vStart  +    eEnd - eStart;                    /* Add a vertex on every edge */
217b5da9499SMatthew G. Knepley     depthSize[1] = 2*(eEnd - eStart) + 3*(fEnd - fStart) + (cEnd - cStart); /* Every edge is split into 2 edges, 3 edges are added for each face, and 1 edge for each cell */
218b5da9499SMatthew G. Knepley     depthSize[2] = 4*(fEnd - fStart) + 8*(cEnd - cStart);                   /* Every face split into 4 faces and 8 faces are added for each cell */
219b5da9499SMatthew G. Knepley     depthSize[3] = 8*(cEnd - cStart);                                       /* Every cell split into 8 cells */
220b5da9499SMatthew G. Knepley     break;
2219b1a0e7fSLawrence Mitchell   case REFINER_HYBRID_SIMPLEX_3D:
222b5da9499SMatthew G. Knepley     if (cMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No cell maximum specified in hybrid mesh");
2236ce3c06aSMatthew G. Knepley     if (fMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No face maximum specified in hybrid mesh");
224b5da9499SMatthew G. Knepley     if (eMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No edge maximum specified in hybrid mesh");
225dae4404aSMatthew G. Knepley     /* Tetrahedra */
226dae4404aSMatthew G. Knepley     depthSize[0]  =    vEnd - vStart  +    eMax - eStart;                    /* Add a vertex on every interior edge */
227dae4404aSMatthew G. Knepley     depthSize[1]  = 2*(eMax - eStart) + 3*(fMax - fStart) + (cMax - cStart); /* Every interior edge split into 2 edges, 3 edges added for each interior face, 1 edge for each interior cell */
228dae4404aSMatthew G. Knepley     depthSize[2]  = 4*(fMax - fStart) + 8*(cMax - cStart);                   /* Every interior face split into 4 faces, 8 faces added for each interior cell */
229dae4404aSMatthew G. Knepley     depthSize[3]  = 8*(cMax - cStart);                                       /* Every interior cell split into 8 cells */
230dae4404aSMatthew G. Knepley     /* Triangular Prisms */
231dae4404aSMatthew G. Knepley     depthSize[0] += 0;                                                       /* No hybrid vertices */
232dae4404aSMatthew G. Knepley     depthSize[1] +=   (eEnd - eMax)   +   (fEnd - fMax);                     /* Every hybrid edge remains, 1 edge for every hybrid face */
2336ce3c06aSMatthew G. Knepley     depthSize[2] += 2*(fEnd - fMax)   + 3*(cEnd - cMax);                     /* Every hybrid face split into 2 faces and 3 faces are added for each hybrid cell */
234dae4404aSMatthew G. Knepley     depthSize[3] += 4*(cEnd - cMax);                                         /* Every hybrid cell split into 4 cells */
235b5da9499SMatthew G. Knepley     break;
2369b1a0e7fSLawrence Mitchell   case REFINER_HEX_3D:
2376ce3c06aSMatthew G. Knepley     depthSize[0] = vEnd - vStart + eEnd - eStart + fEnd - fStart + cEnd - cStart; /* Add a vertex on every edge, face and cell */
2386ce3c06aSMatthew G. Knepley     depthSize[1] = 2*(eEnd - eStart) +  4*(fEnd - fStart) + 6*(cEnd - cStart);    /* Every edge is split into 2 edge, 4 edges are added for each face, and 6 edges for each cell */
2396ce3c06aSMatthew G. Knepley     depthSize[2] = 4*(fEnd - fStart) + 12*(cEnd - cStart);                        /* Every face is split into 4 faces, and 12 faces are added for each cell */
2406ce3c06aSMatthew G. Knepley     depthSize[3] = 8*(cEnd - cStart);                                             /* Every cell split into 8 cells */
2416ce3c06aSMatthew G. Knepley     break;
2429b1a0e7fSLawrence Mitchell   case REFINER_HYBRID_HEX_3D:
24327fcede3SMatthew G. Knepley     if (cMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No cell maximum specified in hybrid mesh");
24427fcede3SMatthew G. Knepley     if (fMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No face maximum specified in hybrid mesh");
24527fcede3SMatthew G. Knepley     if (eMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No edge maximum specified in hybrid mesh");
24627fcede3SMatthew G. Knepley     /* Hexahedra */
24727fcede3SMatthew G. Knepley     depthSize[0] = vEnd - vStart + eMax - eStart + fMax - fStart + cMax - cStart; /* Add a vertex on every edge, face and cell */
24827fcede3SMatthew G. Knepley     depthSize[1] = 2*(eMax - eStart) +  4*(fMax - fStart) + 6*(cMax - cStart);    /* Every edge is split into 2 edge, 4 edges are added for each face, and 6 edges for each cell */
24927fcede3SMatthew G. Knepley     depthSize[2] = 4*(fMax - fStart) + 12*(cMax - cStart);                        /* Every face is split into 4 faces, and 12 faces are added for each cell */
25027fcede3SMatthew G. Knepley     depthSize[3] = 8*(cMax - cStart);                                             /* Every cell split into 8 cells */
25127fcede3SMatthew G. Knepley     /* Quadrilateral Prisms */
25227fcede3SMatthew G. Knepley     depthSize[0] += 0;                                                            /* No hybrid vertices */
25327fcede3SMatthew G. Knepley     depthSize[1] +=   (eEnd - eMax)   +   (fEnd - fMax)   +   (cEnd - cMax);      /* Every hybrid edge remains, 1 edge for every hybrid face and hybrid cell */
25427fcede3SMatthew G. Knepley     depthSize[2] += 2*(fEnd - fMax)   + 4*(cEnd - cMax);                          /* Every hybrid face split into 2 faces and 4 faces are added for each hybrid cell */
25527fcede3SMatthew G. Knepley     depthSize[3] += 4*(cEnd - cMax);                                              /* Every hybrid cell split into 4 cells */
25627fcede3SMatthew G. Knepley     break;
25775d3a19aSMatthew G. Knepley   default:
25875d3a19aSMatthew G. Knepley     SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Unknown cell refiner %d", refiner);
25975d3a19aSMatthew G. Knepley   }
26075d3a19aSMatthew G. Knepley   PetscFunctionReturn(0);
26175d3a19aSMatthew G. Knepley }
26275d3a19aSMatthew G. Knepley 
26342525629SMatthew G. Knepley /* Return triangle edge for orientation o, if it is r for o == 0 */
26442525629SMatthew G. Knepley PETSC_STATIC_INLINE PetscInt GetTriEdge_Static(PetscInt o, PetscInt r) {
265518a8359SMatthew G. Knepley   return (o < 0 ? 2-(o+r) : o+r)%3;
266518a8359SMatthew G. Knepley }
267de65f515SMatthew G. Knepley PETSC_STATIC_INLINE PetscInt GetTriEdgeInverse_Static(PetscInt o, PetscInt s) {
268de65f515SMatthew G. Knepley   return (o < 0 ? 2-(o+s) : 3+s-o)%3;
269de65f515SMatthew G. Knepley }
270518a8359SMatthew G. Knepley 
271518a8359SMatthew G. Knepley /* Return triangle subface for orientation o, if it is r for o == 0 */
272518a8359SMatthew G. Knepley PETSC_STATIC_INLINE PetscInt GetTriSubface_Static(PetscInt o, PetscInt r) {
2734bae88c7SMatthew G. Knepley   return (o < 0 ? 3-(o+r) : o+r)%3;
27442525629SMatthew G. Knepley }
275de65f515SMatthew G. Knepley PETSC_STATIC_INLINE PetscInt GetTriSubfaceInverse_Static(PetscInt o, PetscInt s) {
276de65f515SMatthew G. Knepley   return (o < 0 ? 3-(o+s) : 3+s-o)%3;
277de65f515SMatthew G. Knepley }
27842525629SMatthew G. Knepley 
279431647a4SMatthew G. Knepley /* I HAVE NO IDEA: Return ??? for orientation o, if it is r for o == 0 */
280431647a4SMatthew G. Knepley PETSC_STATIC_INLINE PetscInt GetTetSomething_Static(PetscInt o, PetscInt r) {
281431647a4SMatthew G. Knepley   return (o < 0 ? 1-(o+r) : o+r)%3;
282431647a4SMatthew G. Knepley }
283431647a4SMatthew G. Knepley PETSC_STATIC_INLINE PetscInt GetTetSomethingInverse_Static(PetscInt o, PetscInt s) {
284431647a4SMatthew G. Knepley   return (o < 0 ? 1-(o+s) : 3+s-o)%3;
285431647a4SMatthew G. Knepley }
286431647a4SMatthew G. Knepley 
28742525629SMatthew G. Knepley 
288e3f8b1d6SMatthew G. Knepley /* Return quad edge for orientation o, if it is r for o == 0 */
289e3f8b1d6SMatthew G. Knepley PETSC_STATIC_INLINE PetscInt GetQuadEdge_Static(PetscInt o, PetscInt r) {
290e3f8b1d6SMatthew G. Knepley   return (o < 0 ? 3-(o+r) : o+r)%4;
291e3f8b1d6SMatthew G. Knepley }
292d6d937efSMatthew G. Knepley PETSC_STATIC_INLINE PetscInt GetQuadEdgeInverse_Static(PetscInt o, PetscInt s) {
293d6d937efSMatthew G. Knepley   return (o < 0 ? 3-(o+s) : 4+s-o)%4;
294d6d937efSMatthew G. Knepley }
295e3f8b1d6SMatthew G. Knepley 
296e3f8b1d6SMatthew G. Knepley /* Return quad subface for orientation o, if it is r for o == 0 */
297e3f8b1d6SMatthew G. Knepley PETSC_STATIC_INLINE PetscInt GetQuadSubface_Static(PetscInt o, PetscInt r) {
2984bae88c7SMatthew G. Knepley   return (o < 0 ? 4-(o+r) : o+r)%4;
29942525629SMatthew G. Knepley }
300d6d937efSMatthew G. Knepley PETSC_STATIC_INLINE PetscInt GetQuadSubfaceInverse_Static(PetscInt o, PetscInt s) {
301d6d937efSMatthew G. Knepley   return (o < 0 ? 4-(o+s) : 4+s-o)%4;
302d6d937efSMatthew G. Knepley }
30342525629SMatthew G. Knepley 
30475d3a19aSMatthew G. Knepley #undef __FUNCT__
30575d3a19aSMatthew G. Knepley #define __FUNCT__ "CellRefinerSetConeSizes"
30686150812SJed Brown static PetscErrorCode CellRefinerSetConeSizes(CellRefiner refiner, DM dm, PetscInt depthSize[], DM rdm)
30775d3a19aSMatthew G. Knepley {
308b5da9499SMatthew G. Knepley   PetscInt       depth, cStart, cStartNew, cEnd, cMax, c, vStart, vStartNew, vEnd, vMax, v, fStart, fStartNew, fEnd, fMax, f, eStart, eStartNew, eEnd, eMax, e, r;
30975d3a19aSMatthew G. Knepley   PetscErrorCode ierr;
31075d3a19aSMatthew G. Knepley 
31175d3a19aSMatthew G. Knepley   PetscFunctionBegin;
3122a5d0125SJed Brown   if (!refiner) PetscFunctionReturn(0);
31375d3a19aSMatthew G. Knepley   ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr);
31475d3a19aSMatthew G. Knepley   ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr);
31575d3a19aSMatthew G. Knepley   ierr = DMPlexGetDepthStratum(dm, 1, &eStart, &eEnd);CHKERRQ(ierr);
31675d3a19aSMatthew G. Knepley   ierr = DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd);CHKERRQ(ierr);
31775d3a19aSMatthew G. Knepley   ierr = DMPlexGetHeightStratum(dm, 1, &fStart, &fEnd);CHKERRQ(ierr);
31875d3a19aSMatthew G. Knepley   ierr = DMPlexGetHybridBounds(dm, &cMax, &fMax, &eMax, &vMax);CHKERRQ(ierr);
3192a5d0125SJed Brown   ierr = GetDepthStart_Private(depth, depthSize, &cStartNew, &fStartNew, &eStartNew, &vStartNew);CHKERRQ(ierr);
32075d3a19aSMatthew G. Knepley   switch (refiner) {
3210314a74cSLawrence Mitchell   case REFINER_SIMPLEX_1D:
3220314a74cSLawrence Mitchell     /* All cells have 2 vertices */
3230314a74cSLawrence Mitchell     for (c = cStart; c < cEnd; ++c) {
3240314a74cSLawrence Mitchell       for (r = 0; r < 2; ++r) {
3250314a74cSLawrence Mitchell         const PetscInt newp = cStartNew + (c - cStart)*2 + r;
3260314a74cSLawrence Mitchell 
3270314a74cSLawrence Mitchell         ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
3280314a74cSLawrence Mitchell       }
3290314a74cSLawrence Mitchell     }
3300314a74cSLawrence Mitchell     /* Old vertices have identical supports */
3310314a74cSLawrence Mitchell     for (v = vStart; v < vEnd; ++v) {
3320314a74cSLawrence Mitchell       const PetscInt newp = vStartNew + (v - vStart);
3330314a74cSLawrence Mitchell       PetscInt       size;
3340314a74cSLawrence Mitchell 
3350314a74cSLawrence Mitchell       ierr = DMPlexGetSupportSize(dm, v, &size);CHKERRQ(ierr);
3360314a74cSLawrence Mitchell       ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
3370314a74cSLawrence Mitchell     }
3380314a74cSLawrence Mitchell     /* Cell vertices have support 2 */
3390314a74cSLawrence Mitchell     for (c = cStart; c < cEnd; ++c) {
3400314a74cSLawrence Mitchell       const PetscInt newp = vStartNew + (vEnd - vStart) + (c - cStart);
3410314a74cSLawrence Mitchell 
3420314a74cSLawrence Mitchell       ierr = DMPlexSetSupportSize(rdm, newp, 2);CHKERRQ(ierr);
3430314a74cSLawrence Mitchell     }
3440314a74cSLawrence Mitchell     break;
3459b1a0e7fSLawrence Mitchell   case REFINER_SIMPLEX_2D:
34675d3a19aSMatthew G. Knepley     /* All cells have 3 faces */
34775d3a19aSMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
34875d3a19aSMatthew G. Knepley       for (r = 0; r < 4; ++r) {
34975d3a19aSMatthew G. Knepley         const PetscInt newp = (c - cStart)*4 + r;
35075d3a19aSMatthew G. Knepley 
35175d3a19aSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 3);CHKERRQ(ierr);
35275d3a19aSMatthew G. Knepley       }
35375d3a19aSMatthew G. Knepley     }
35475d3a19aSMatthew G. Knepley     /* Split faces have 2 vertices and the same cells as the parent */
35575d3a19aSMatthew G. Knepley     for (f = fStart; f < fEnd; ++f) {
35675d3a19aSMatthew G. Knepley       for (r = 0; r < 2; ++r) {
35775d3a19aSMatthew G. Knepley         const PetscInt newp = fStartNew + (f - fStart)*2 + r;
35875d3a19aSMatthew G. Knepley         PetscInt       size;
35975d3a19aSMatthew G. Knepley 
36075d3a19aSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
36175d3a19aSMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
36275d3a19aSMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
36375d3a19aSMatthew G. Knepley       }
36475d3a19aSMatthew G. Knepley     }
36575d3a19aSMatthew G. Knepley     /* Interior faces have 2 vertices and 2 cells */
36675d3a19aSMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
36775d3a19aSMatthew G. Knepley       for (r = 0; r < 3; ++r) {
36875d3a19aSMatthew G. Knepley         const PetscInt newp = fStartNew + (fEnd - fStart)*2 + (c - cStart)*3 + r;
36975d3a19aSMatthew G. Knepley 
37075d3a19aSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
37175d3a19aSMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, 2);CHKERRQ(ierr);
37275d3a19aSMatthew G. Knepley       }
37375d3a19aSMatthew G. Knepley     }
37475d3a19aSMatthew G. Knepley     /* Old vertices have identical supports */
37575d3a19aSMatthew G. Knepley     for (v = vStart; v < vEnd; ++v) {
37675d3a19aSMatthew G. Knepley       const PetscInt newp = vStartNew + (v - vStart);
37775d3a19aSMatthew G. Knepley       PetscInt       size;
37875d3a19aSMatthew G. Knepley 
37975d3a19aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, v, &size);CHKERRQ(ierr);
38075d3a19aSMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
38175d3a19aSMatthew G. Knepley     }
38275d3a19aSMatthew G. Knepley     /* Face vertices have 2 + cells*2 supports */
38375d3a19aSMatthew G. Knepley     for (f = fStart; f < fEnd; ++f) {
38475d3a19aSMatthew G. Knepley       const PetscInt newp = vStartNew + (vEnd - vStart) + (f - fStart);
38575d3a19aSMatthew G. Knepley       PetscInt       size;
38675d3a19aSMatthew G. Knepley 
38775d3a19aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
38875d3a19aSMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, 2 + size*2);CHKERRQ(ierr);
38975d3a19aSMatthew G. Knepley     }
39075d3a19aSMatthew G. Knepley     break;
3919b1a0e7fSLawrence Mitchell   case REFINER_HEX_2D:
39275d3a19aSMatthew G. Knepley     /* All cells have 4 faces */
39375d3a19aSMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
39475d3a19aSMatthew G. Knepley       for (r = 0; r < 4; ++r) {
395149f48fdSMatthew G. Knepley         const PetscInt newp = cStartNew + (c - cStart)*4 + r;
39675d3a19aSMatthew G. Knepley 
39775d3a19aSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 4);CHKERRQ(ierr);
39875d3a19aSMatthew G. Knepley       }
39975d3a19aSMatthew G. Knepley     }
40075d3a19aSMatthew G. Knepley     /* Split faces have 2 vertices and the same cells as the parent */
40175d3a19aSMatthew G. Knepley     for (f = fStart; f < fEnd; ++f) {
40275d3a19aSMatthew G. Knepley       for (r = 0; r < 2; ++r) {
40375d3a19aSMatthew G. Knepley         const PetscInt newp = fStartNew + (f - fStart)*2 + r;
40475d3a19aSMatthew G. Knepley         PetscInt       size;
40575d3a19aSMatthew G. Knepley 
40675d3a19aSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
40775d3a19aSMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
40875d3a19aSMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
40975d3a19aSMatthew G. Knepley       }
41075d3a19aSMatthew G. Knepley     }
41175d3a19aSMatthew G. Knepley     /* Interior faces have 2 vertices and 2 cells */
41275d3a19aSMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
41375d3a19aSMatthew G. Knepley       for (r = 0; r < 4; ++r) {
41475d3a19aSMatthew G. Knepley         const PetscInt newp = fStartNew + (fEnd - fStart)*2 + (c - cStart)*4 + r;
41575d3a19aSMatthew G. Knepley 
41675d3a19aSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
41775d3a19aSMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, 2);CHKERRQ(ierr);
41875d3a19aSMatthew G. Knepley       }
41975d3a19aSMatthew G. Knepley     }
42075d3a19aSMatthew G. Knepley     /* Old vertices have identical supports */
42175d3a19aSMatthew G. Knepley     for (v = vStart; v < vEnd; ++v) {
42275d3a19aSMatthew G. Knepley       const PetscInt newp = vStartNew + (v - vStart);
42375d3a19aSMatthew G. Knepley       PetscInt       size;
42475d3a19aSMatthew G. Knepley 
42575d3a19aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, v, &size);CHKERRQ(ierr);
42675d3a19aSMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
42775d3a19aSMatthew G. Knepley     }
42875d3a19aSMatthew G. Knepley     /* Face vertices have 2 + cells supports */
42975d3a19aSMatthew G. Knepley     for (f = fStart; f < fEnd; ++f) {
43075d3a19aSMatthew G. Knepley       const PetscInt newp = vStartNew + (vEnd - vStart) + (f - fStart);
43175d3a19aSMatthew G. Knepley       PetscInt       size;
43275d3a19aSMatthew G. Knepley 
43375d3a19aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
43475d3a19aSMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, 2 + size);CHKERRQ(ierr);
43575d3a19aSMatthew G. Knepley     }
43675d3a19aSMatthew G. Knepley     /* Cell vertices have 4 supports */
43775d3a19aSMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
43875d3a19aSMatthew G. Knepley       const PetscInt newp = vStartNew + (vEnd - vStart) + (fEnd - fStart) + (c - cStart);
43975d3a19aSMatthew G. Knepley 
44075d3a19aSMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, 4);CHKERRQ(ierr);
44175d3a19aSMatthew G. Knepley     }
44275d3a19aSMatthew G. Knepley     break;
4439b1a0e7fSLawrence Mitchell   case REFINER_HYBRID_SIMPLEX_2D:
44475d3a19aSMatthew G. Knepley     if (cMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No cell maximum specified in hybrid mesh");
44575d3a19aSMatthew G. Knepley     cMax = PetscMin(cEnd, cMax);
44675d3a19aSMatthew G. Knepley     if (fMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No face maximum specified in hybrid mesh");
44775d3a19aSMatthew G. Knepley     fMax = PetscMin(fEnd, fMax);
44875d3a19aSMatthew G. Knepley     ierr = DMPlexSetHybridBounds(rdm, cStartNew + (cMax - cStart)*4, fStartNew + (fMax - fStart)*2 + (cMax - cStart)*3, PETSC_DETERMINE, PETSC_DETERMINE);CHKERRQ(ierr);
44975d3a19aSMatthew G. Knepley     /* Interior cells have 3 faces */
45075d3a19aSMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
45175d3a19aSMatthew G. Knepley       for (r = 0; r < 4; ++r) {
45275d3a19aSMatthew G. Knepley         const PetscInt newp = cStartNew + (c - cStart)*4 + r;
45375d3a19aSMatthew G. Knepley 
45475d3a19aSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 3);CHKERRQ(ierr);
45575d3a19aSMatthew G. Knepley       }
45675d3a19aSMatthew G. Knepley     }
45775d3a19aSMatthew G. Knepley     /* Hybrid cells have 4 faces */
45875d3a19aSMatthew G. Knepley     for (c = cMax; c < cEnd; ++c) {
45975d3a19aSMatthew G. Knepley       for (r = 0; r < 2; ++r) {
46075d3a19aSMatthew G. Knepley         const PetscInt newp = cStartNew + (cMax - cStart)*4 + (c - cMax)*2 + r;
46175d3a19aSMatthew G. Knepley 
46275d3a19aSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 4);CHKERRQ(ierr);
46375d3a19aSMatthew G. Knepley       }
46475d3a19aSMatthew G. Knepley     }
46575d3a19aSMatthew G. Knepley     /* Interior split faces have 2 vertices and the same cells as the parent */
46675d3a19aSMatthew G. Knepley     for (f = fStart; f < fMax; ++f) {
46775d3a19aSMatthew G. Knepley       for (r = 0; r < 2; ++r) {
46875d3a19aSMatthew G. Knepley         const PetscInt newp = fStartNew + (f - fStart)*2 + r;
46975d3a19aSMatthew G. Knepley         PetscInt       size;
47075d3a19aSMatthew G. Knepley 
47175d3a19aSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
47275d3a19aSMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
47375d3a19aSMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
47475d3a19aSMatthew G. Knepley       }
47575d3a19aSMatthew G. Knepley     }
47675d3a19aSMatthew G. Knepley     /* Interior cell faces have 2 vertices and 2 cells */
47775d3a19aSMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
47875d3a19aSMatthew G. Knepley       for (r = 0; r < 3; ++r) {
47975d3a19aSMatthew G. Knepley         const PetscInt newp = fStartNew + (fMax - fStart)*2 + (c - cStart)*3 + r;
48075d3a19aSMatthew G. Knepley 
48175d3a19aSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
48275d3a19aSMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, 2);CHKERRQ(ierr);
48375d3a19aSMatthew G. Knepley       }
48475d3a19aSMatthew G. Knepley     }
48575d3a19aSMatthew G. Knepley     /* Hybrid faces have 2 vertices and the same cells */
48675d3a19aSMatthew G. Knepley     for (f = fMax; f < fEnd; ++f) {
48775d3a19aSMatthew G. Knepley       const PetscInt newp = fStartNew + (fMax - fStart)*2 + (cMax - cStart)*3 + (f - fMax);
48875d3a19aSMatthew G. Knepley       PetscInt       size;
48975d3a19aSMatthew G. Knepley 
49075d3a19aSMatthew G. Knepley       ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
49175d3a19aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
49275d3a19aSMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
49375d3a19aSMatthew G. Knepley     }
49475d3a19aSMatthew G. Knepley     /* Hybrid cell faces have 2 vertices and 2 cells */
49575d3a19aSMatthew G. Knepley     for (c = cMax; c < cEnd; ++c) {
49675d3a19aSMatthew G. Knepley       const PetscInt newp = fStartNew + (fMax - fStart)*2 + (cMax - cStart)*3 + (fEnd - fMax) + (c - cMax);
49775d3a19aSMatthew G. Knepley 
49875d3a19aSMatthew G. Knepley       ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
49975d3a19aSMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, 2);CHKERRQ(ierr);
50075d3a19aSMatthew G. Knepley     }
50175d3a19aSMatthew G. Knepley     /* Old vertices have identical supports */
50275d3a19aSMatthew G. Knepley     for (v = vStart; v < vEnd; ++v) {
50375d3a19aSMatthew G. Knepley       const PetscInt newp = vStartNew + (v - vStart);
50475d3a19aSMatthew G. Knepley       PetscInt       size;
50575d3a19aSMatthew G. Knepley 
50675d3a19aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, v, &size);CHKERRQ(ierr);
50775d3a19aSMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
50875d3a19aSMatthew G. Knepley     }
50975d3a19aSMatthew G. Knepley     /* Face vertices have 2 + (2 interior, 1 hybrid) supports */
51075d3a19aSMatthew G. Knepley     for (f = fStart; f < fMax; ++f) {
51175d3a19aSMatthew G. Knepley       const PetscInt newp = vStartNew + (vEnd - vStart) + (f - fStart);
51275d3a19aSMatthew G. Knepley       const PetscInt *support;
51375d3a19aSMatthew G. Knepley       PetscInt       size, newSize = 2, s;
51475d3a19aSMatthew G. Knepley 
51575d3a19aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
51675d3a19aSMatthew G. Knepley       ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
51775d3a19aSMatthew G. Knepley       for (s = 0; s < size; ++s) {
51875d3a19aSMatthew G. Knepley         if (support[s] >= cMax) newSize += 1;
51975d3a19aSMatthew G. Knepley         else newSize += 2;
52075d3a19aSMatthew G. Knepley       }
52175d3a19aSMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, newSize);CHKERRQ(ierr);
52275d3a19aSMatthew G. Knepley     }
52375d3a19aSMatthew G. Knepley     break;
5249b1a0e7fSLawrence Mitchell   case REFINER_HYBRID_HEX_2D:
525a97b51b8SMatthew G. Knepley     if (cMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No cell maximum specified in hybrid mesh");
526a97b51b8SMatthew G. Knepley     cMax = PetscMin(cEnd, cMax);
527a97b51b8SMatthew G. Knepley     if (fMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No face maximum specified in hybrid mesh");
528a97b51b8SMatthew G. Knepley     fMax = PetscMin(fEnd, fMax);
529a97b51b8SMatthew G. Knepley     ierr = DMPlexSetHybridBounds(rdm, cStartNew + (cMax - cStart)*4, fStartNew + (fMax - fStart)*2 + (cMax - cStart)*4, PETSC_DETERMINE, PETSC_DETERMINE);CHKERRQ(ierr);
530a97b51b8SMatthew G. Knepley     /* Interior cells have 4 faces */
531a97b51b8SMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
532a97b51b8SMatthew G. Knepley       for (r = 0; r < 4; ++r) {
533a97b51b8SMatthew G. Knepley         const PetscInt newp = cStartNew + (c - cStart)*4 + r;
534a97b51b8SMatthew G. Knepley 
535a97b51b8SMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 4);CHKERRQ(ierr);
536a97b51b8SMatthew G. Knepley       }
537a97b51b8SMatthew G. Knepley     }
538a97b51b8SMatthew G. Knepley     /* Hybrid cells have 4 faces */
539a97b51b8SMatthew G. Knepley     for (c = cMax; c < cEnd; ++c) {
540a97b51b8SMatthew G. Knepley       for (r = 0; r < 2; ++r) {
541a97b51b8SMatthew G. Knepley         const PetscInt newp = cStartNew + (cMax - cStart)*4 + (c - cMax)*2 + r;
542a97b51b8SMatthew G. Knepley 
543a97b51b8SMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 4);CHKERRQ(ierr);
544a97b51b8SMatthew G. Knepley       }
545a97b51b8SMatthew G. Knepley     }
546a97b51b8SMatthew G. Knepley     /* Interior split faces have 2 vertices and the same cells as the parent */
547a97b51b8SMatthew G. Knepley     for (f = fStart; f < fMax; ++f) {
548a97b51b8SMatthew G. Knepley       for (r = 0; r < 2; ++r) {
549a97b51b8SMatthew G. Knepley         const PetscInt newp = fStartNew + (f - fStart)*2 + r;
550a97b51b8SMatthew G. Knepley         PetscInt       size;
551a97b51b8SMatthew G. Knepley 
552a97b51b8SMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
553a97b51b8SMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
554a97b51b8SMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
555a97b51b8SMatthew G. Knepley       }
556a97b51b8SMatthew G. Knepley     }
557a97b51b8SMatthew G. Knepley     /* Interior cell faces have 2 vertices and 2 cells */
558a97b51b8SMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
559a97b51b8SMatthew G. Knepley       for (r = 0; r < 4; ++r) {
560a97b51b8SMatthew G. Knepley         const PetscInt newp = fStartNew + (fMax - fStart)*2 + (c - cStart)*4 + r;
561a97b51b8SMatthew G. Knepley 
562a97b51b8SMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
563a97b51b8SMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, 2);CHKERRQ(ierr);
564a97b51b8SMatthew G. Knepley       }
565a97b51b8SMatthew G. Knepley     }
566a97b51b8SMatthew G. Knepley     /* Hybrid faces have 2 vertices and the same cells */
567a97b51b8SMatthew G. Knepley     for (f = fMax; f < fEnd; ++f) {
568a97b51b8SMatthew G. Knepley       const PetscInt newp = fStartNew + (fMax - fStart)*2 + (cMax - cStart)*4 + (f - fMax);
569a97b51b8SMatthew G. Knepley       PetscInt       size;
570a97b51b8SMatthew G. Knepley 
571a97b51b8SMatthew G. Knepley       ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
572a97b51b8SMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
573a97b51b8SMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
574a97b51b8SMatthew G. Knepley     }
575a97b51b8SMatthew G. Knepley     /* Hybrid cell faces have 2 vertices and 2 cells */
576a97b51b8SMatthew G. Knepley     for (c = cMax; c < cEnd; ++c) {
577a97b51b8SMatthew G. Knepley       const PetscInt newp = fStartNew + (fMax - fStart)*2 + (cMax - cStart)*4 + (fEnd - fMax) + (c - cMax);
578a97b51b8SMatthew G. Knepley 
579a97b51b8SMatthew G. Knepley       ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
580a97b51b8SMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, 2);CHKERRQ(ierr);
581a97b51b8SMatthew G. Knepley     }
582a97b51b8SMatthew G. Knepley     /* Old vertices have identical supports */
583a97b51b8SMatthew G. Knepley     for (v = vStart; v < vEnd; ++v) {
584a97b51b8SMatthew G. Knepley       const PetscInt newp = vStartNew + (v - vStart);
585a97b51b8SMatthew G. Knepley       PetscInt       size;
586a97b51b8SMatthew G. Knepley 
587a97b51b8SMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, v, &size);CHKERRQ(ierr);
588a97b51b8SMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
589a97b51b8SMatthew G. Knepley     }
590a97b51b8SMatthew G. Knepley     /* Face vertices have 2 + cells supports */
591a97b51b8SMatthew G. Knepley     for (f = fStart; f < fMax; ++f) {
592a97b51b8SMatthew G. Knepley       const PetscInt newp = vStartNew + (vEnd - vStart) + (f - fStart);
593a97b51b8SMatthew G. Knepley       PetscInt       size;
594a97b51b8SMatthew G. Knepley 
595a97b51b8SMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
596a97b51b8SMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, 2 + size);CHKERRQ(ierr);
597a97b51b8SMatthew G. Knepley     }
598a97b51b8SMatthew G. Knepley     /* Cell vertices have 4 supports */
599a97b51b8SMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
600a97b51b8SMatthew G. Knepley       const PetscInt newp = vStartNew + (vEnd - vStart) + (fMax - fStart) + (c - cStart);
601a97b51b8SMatthew G. Knepley 
602a97b51b8SMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, 4);CHKERRQ(ierr);
603a97b51b8SMatthew G. Knepley     }
604a97b51b8SMatthew G. Knepley     break;
6059b1a0e7fSLawrence Mitchell   case REFINER_SIMPLEX_3D:
606b5da9499SMatthew G. Knepley     /* All cells have 4 faces */
607b5da9499SMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
608b5da9499SMatthew G. Knepley       for (r = 0; r < 8; ++r) {
609dae4404aSMatthew G. Knepley         const PetscInt newp = cStartNew + (c - cStart)*8 + r;
610b5da9499SMatthew G. Knepley 
611b5da9499SMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 4);CHKERRQ(ierr);
612b5da9499SMatthew G. Knepley       }
613b5da9499SMatthew G. Knepley     }
614b5da9499SMatthew G. Knepley     /* Split faces have 3 edges and the same cells as the parent */
615b5da9499SMatthew G. Knepley     for (f = fStart; f < fEnd; ++f) {
616b5da9499SMatthew G. Knepley       for (r = 0; r < 4; ++r) {
617b5da9499SMatthew G. Knepley         const PetscInt newp = fStartNew + (f - fStart)*4 + r;
618b5da9499SMatthew G. Knepley         PetscInt       size;
619b5da9499SMatthew G. Knepley 
620b5da9499SMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 3);CHKERRQ(ierr);
621b5da9499SMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
622b5da9499SMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
623b5da9499SMatthew G. Knepley       }
624b5da9499SMatthew G. Knepley     }
6259ddff745SMatthew G. Knepley     /* Interior cell faces have 3 edges and 2 cells */
626b5da9499SMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
627b5da9499SMatthew G. Knepley       for (r = 0; r < 8; ++r) {
628b5da9499SMatthew G. Knepley         const PetscInt newp = fStartNew + (fEnd - fStart)*4 + (c - cStart)*8 + r;
629b5da9499SMatthew G. Knepley 
630b5da9499SMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 3);CHKERRQ(ierr);
631b5da9499SMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, 2);CHKERRQ(ierr);
632b5da9499SMatthew G. Knepley       }
633b5da9499SMatthew G. Knepley     }
634b5da9499SMatthew G. Knepley     /* Split edges have 2 vertices and the same faces */
635b5da9499SMatthew G. Knepley     for (e = eStart; e < eEnd; ++e) {
636b5da9499SMatthew G. Knepley       for (r = 0; r < 2; ++r) {
637b5da9499SMatthew G. Knepley         const PetscInt newp = eStartNew + (e - eStart)*2 + r;
638b5da9499SMatthew G. Knepley         PetscInt       size;
639b5da9499SMatthew G. Knepley 
640b5da9499SMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
641b5da9499SMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, e, &size);CHKERRQ(ierr);
642b5da9499SMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
643b5da9499SMatthew G. Knepley       }
644b5da9499SMatthew G. Knepley     }
645b5da9499SMatthew G. Knepley     /* Face edges have 2 vertices and 2+cells*(1/2) faces */
646b5da9499SMatthew G. Knepley     for (f = fStart; f < fEnd; ++f) {
647b5da9499SMatthew G. Knepley       for (r = 0; r < 3; ++r) {
648b5da9499SMatthew G. Knepley         const PetscInt  newp = eStartNew + (eEnd - eStart)*2 + (f - fStart)*3 + r;
649b5da9499SMatthew G. Knepley         const PetscInt *cone, *ornt, *support, eint[4] = {1, 0, 2, 0};
650b5da9499SMatthew G. Knepley         PetscInt        coneSize, c, supportSize, s, er, intFaces = 0;
651b5da9499SMatthew G. Knepley 
652b5da9499SMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
653b5da9499SMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &supportSize);CHKERRQ(ierr);
654b5da9499SMatthew G. Knepley         ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
655b5da9499SMatthew G. Knepley         for (s = 0; s < supportSize; ++s) {
656b5da9499SMatthew G. Knepley           ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr);
657b5da9499SMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
658b5da9499SMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, support[s], &ornt);CHKERRQ(ierr);
659b5da9499SMatthew G. Knepley           for (c = 0; c < coneSize; ++c) {if (cone[c] == f) break;}
66086f0afeeSMatthew G. Knepley           /* Here we want to determine whether edge newp contains a vertex which is part of the cross-tet edge */
6619ddff745SMatthew G. Knepley           er = GetTetSomethingInverse_Static(ornt[c], r);
662b5da9499SMatthew G. Knepley           if (er == eint[c]) {
663b5da9499SMatthew G. Knepley             intFaces += 1;
664b5da9499SMatthew G. Knepley           } else {
665b5da9499SMatthew G. Knepley             intFaces += 2;
666b5da9499SMatthew G. Knepley           }
667b5da9499SMatthew G. Knepley         }
668b5da9499SMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, 2+intFaces);CHKERRQ(ierr);
669b5da9499SMatthew G. Knepley       }
670b5da9499SMatthew G. Knepley     }
6719ddff745SMatthew G. Knepley     /* Interior cell edges have 2 vertices and 4 faces */
672b5da9499SMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
673b5da9499SMatthew G. Knepley       const PetscInt newp = eStartNew + (eEnd - eStart)*2 + (fEnd - fStart)*3 + (c - cStart);
674b5da9499SMatthew G. Knepley 
675b5da9499SMatthew G. Knepley       ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
676b5da9499SMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, 4);CHKERRQ(ierr);
677b5da9499SMatthew G. Knepley     }
678b5da9499SMatthew G. Knepley     /* Old vertices have identical supports */
679b5da9499SMatthew G. Knepley     for (v = vStart; v < vEnd; ++v) {
680b5da9499SMatthew G. Knepley       const PetscInt newp = vStartNew + (v - vStart);
681b5da9499SMatthew G. Knepley       PetscInt       size;
682b5da9499SMatthew G. Knepley 
683b5da9499SMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, v, &size);CHKERRQ(ierr);
684b5da9499SMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
685b5da9499SMatthew G. Knepley     }
686b5da9499SMatthew G. Knepley     /* Edge vertices have 2 + faces*2 + cells*0/1 supports */
687b5da9499SMatthew G. Knepley     for (e = eStart; e < eEnd; ++e) {
688b5da9499SMatthew G. Knepley       const PetscInt newp = vStartNew + (vEnd - vStart) + (e - eStart);
689b5da9499SMatthew G. Knepley       PetscInt       size, *star = NULL, starSize, s, cellSize = 0;
690b5da9499SMatthew G. Knepley 
691b5da9499SMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, e, &size);CHKERRQ(ierr);
692b5da9499SMatthew G. Knepley       ierr = DMPlexGetTransitiveClosure(dm, e, PETSC_FALSE, &starSize, &star);CHKERRQ(ierr);
693b5da9499SMatthew G. Knepley       for (s = 0; s < starSize*2; s += 2) {
694b5da9499SMatthew G. Knepley         const PetscInt *cone, *ornt;
695b5da9499SMatthew G. Knepley         PetscInt        e01, e23;
696b5da9499SMatthew G. Knepley 
697b5da9499SMatthew G. Knepley         if ((star[s] >= cStart) && (star[s] < cEnd)) {
698b5da9499SMatthew G. Knepley           /* Check edge 0-1 */
699b5da9499SMatthew G. Knepley           ierr = DMPlexGetCone(dm, star[s], &cone);CHKERRQ(ierr);
700b5da9499SMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, star[s], &ornt);CHKERRQ(ierr);
701b5da9499SMatthew G. Knepley           ierr = DMPlexGetCone(dm, cone[0], &cone);CHKERRQ(ierr);
70242525629SMatthew G. Knepley           e01  = cone[GetTriEdge_Static(ornt[0], 0)];
703b5da9499SMatthew G. Knepley           /* Check edge 2-3 */
704b5da9499SMatthew G. Knepley           ierr = DMPlexGetCone(dm, star[s], &cone);CHKERRQ(ierr);
705b5da9499SMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, star[s], &ornt);CHKERRQ(ierr);
70642525629SMatthew G. Knepley           ierr = DMPlexGetCone(dm, cone[2], &cone);CHKERRQ(ierr);
70742525629SMatthew G. Knepley           e23  = cone[GetTriEdge_Static(ornt[2], 1)];
708b5da9499SMatthew G. Knepley           if ((e01 == e) || (e23 == e)) ++cellSize;
709b5da9499SMatthew G. Knepley         }
710b5da9499SMatthew G. Knepley       }
711b5da9499SMatthew G. Knepley       ierr = DMPlexRestoreTransitiveClosure(dm, e, PETSC_FALSE, &starSize, &star);CHKERRQ(ierr);
712b5da9499SMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, 2 + size*2 + cellSize);CHKERRQ(ierr);
713b5da9499SMatthew G. Knepley     }
714b5da9499SMatthew G. Knepley     break;
7159b1a0e7fSLawrence Mitchell   case REFINER_HYBRID_SIMPLEX_3D:
7166ce3c06aSMatthew G. Knepley     ierr = DMPlexSetHybridBounds(rdm, cStartNew + 8*(cMax-cStart), fStartNew + 4*(fMax - fStart) + 8*(cMax - cStart),
7176ce3c06aSMatthew G. Knepley                                  eStartNew + 2*(eMax - eStart) + 3*(fMax - fStart) + (cMax - cStart), PETSC_DETERMINE);CHKERRQ(ierr);
718dae4404aSMatthew G. Knepley     /* Interior cells have 4 faces */
719dae4404aSMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
720dae4404aSMatthew G. Knepley       for (r = 0; r < 8; ++r) {
721dae4404aSMatthew G. Knepley         const PetscInt newp = cStartNew + (c - cStart)*8 + r;
722dae4404aSMatthew G. Knepley 
723dae4404aSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 4);CHKERRQ(ierr);
724dae4404aSMatthew G. Knepley       }
725dae4404aSMatthew G. Knepley     }
726dae4404aSMatthew G. Knepley     /* Hybrid cells have 5 faces */
727dae4404aSMatthew G. Knepley     for (c = cMax; c < cEnd; ++c) {
728dae4404aSMatthew G. Knepley       for (r = 0; r < 4; ++r) {
729dae4404aSMatthew G. Knepley         const PetscInt newp = cStartNew + (cMax - cStart)*8 + (c - cMax)*4 + r;
730dae4404aSMatthew G. Knepley 
731dae4404aSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 5);CHKERRQ(ierr);
732dae4404aSMatthew G. Knepley       }
733dae4404aSMatthew G. Knepley     }
7346ce3c06aSMatthew G. Knepley     /* Interior split faces have 3 edges and the same cells as the parent */
735dae4404aSMatthew G. Knepley     for (f = fStart; f < fMax; ++f) {
736dae4404aSMatthew G. Knepley       for (r = 0; r < 4; ++r) {
737dae4404aSMatthew G. Knepley         const PetscInt newp = fStartNew + (f - fStart)*4 + r;
738dae4404aSMatthew G. Knepley         PetscInt       size;
739dae4404aSMatthew G. Knepley 
740dae4404aSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 3);CHKERRQ(ierr);
741dae4404aSMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
742dae4404aSMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
743dae4404aSMatthew G. Knepley       }
744dae4404aSMatthew G. Knepley     }
745dae4404aSMatthew G. Knepley     /* Interior cell faces have 3 edges and 2 cells */
746dae4404aSMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
747dae4404aSMatthew G. Knepley       for (r = 0; r < 8; ++r) {
748dae4404aSMatthew G. Knepley         const PetscInt newp = fStartNew + (fMax - fStart)*4 + (c - cStart)*8 + r;
749dae4404aSMatthew G. Knepley 
750dae4404aSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 3);CHKERRQ(ierr);
751dae4404aSMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, 2);CHKERRQ(ierr);
752dae4404aSMatthew G. Knepley       }
753dae4404aSMatthew G. Knepley     }
7546ce3c06aSMatthew G. Knepley     /* Hybrid split faces have 4 edges and the same cells as the parent */
7556ce3c06aSMatthew G. Knepley     for (f = fMax; f < fEnd; ++f) {
7566ce3c06aSMatthew G. Knepley       for (r = 0; r < 2; ++r) {
7576ce3c06aSMatthew G. Knepley         const PetscInt newp = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*8 + (f - fMax)*2 + r;
7586ce3c06aSMatthew G. Knepley         PetscInt       size;
7596ce3c06aSMatthew G. Knepley 
7606ce3c06aSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 4);CHKERRQ(ierr);
7616ce3c06aSMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
7626ce3c06aSMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
7636ce3c06aSMatthew G. Knepley       }
7646ce3c06aSMatthew G. Knepley     }
7656ce3c06aSMatthew G. Knepley     /* Hybrid cells faces have 4 edges and 2 cells */
7666ce3c06aSMatthew G. Knepley     for (c = cMax; c < cEnd; ++c) {
7676ce3c06aSMatthew G. Knepley       for (r = 0; r < 3; ++r) {
7686ce3c06aSMatthew G. Knepley         const PetscInt newp = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*8 + (fEnd - fMax)*2 + (c - cMax)*3 + r;
7696ce3c06aSMatthew G. Knepley 
7706ce3c06aSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 4);CHKERRQ(ierr);
7716ce3c06aSMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, 2);CHKERRQ(ierr);
7726ce3c06aSMatthew G. Knepley       }
7736ce3c06aSMatthew G. Knepley     }
7746ce3c06aSMatthew G. Knepley     /* Interior split edges have 2 vertices and the same faces */
775dae4404aSMatthew G. Knepley     for (e = eStart; e < eMax; ++e) {
776dae4404aSMatthew G. Knepley       for (r = 0; r < 2; ++r) {
777dae4404aSMatthew G. Knepley         const PetscInt newp = eStartNew + (e - eStart)*2 + r;
778dae4404aSMatthew G. Knepley         PetscInt       size;
779dae4404aSMatthew G. Knepley 
780dae4404aSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
781dae4404aSMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, e, &size);CHKERRQ(ierr);
782dae4404aSMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
783dae4404aSMatthew G. Knepley       }
784dae4404aSMatthew G. Knepley     }
7856ce3c06aSMatthew G. Knepley     /* Interior face edges have 2 vertices and 2+cells*(1/2) faces */
786dae4404aSMatthew G. Knepley     for (f = fStart; f < fMax; ++f) {
787dae4404aSMatthew G. Knepley       for (r = 0; r < 3; ++r) {
788dae4404aSMatthew G. Knepley         const PetscInt  newp = eStartNew + (eMax - eStart)*2 + (f - fStart)*3 + r;
789dae4404aSMatthew G. Knepley         const PetscInt *cone, *ornt, *support, eint[4] = {1, 0, 2, 0};
790dae4404aSMatthew G. Knepley         PetscInt        coneSize, c, supportSize, s, er, intFaces = 0;
791dae4404aSMatthew G. Knepley 
792dae4404aSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
793dae4404aSMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &supportSize);CHKERRQ(ierr);
794dae4404aSMatthew G. Knepley         ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
795dae4404aSMatthew G. Knepley         for (s = 0; s < supportSize; ++s) {
796dae4404aSMatthew G. Knepley           ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr);
797dae4404aSMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
798dae4404aSMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, support[s], &ornt);CHKERRQ(ierr);
799dae4404aSMatthew G. Knepley           for (c = 0; c < coneSize; ++c) {if (cone[c] == f) break;}
8006ce3c06aSMatthew G. Knepley           if (support[s] < cMax) {
801dae4404aSMatthew G. Knepley             /* Here we want to determine whether edge newp contains a vertex which is part of the cross-tet edge */
8029ddff745SMatthew G. Knepley             er = GetTetSomethingInverse_Static(ornt[c], r);
803dae4404aSMatthew G. Knepley             if (er == eint[c]) {
804dae4404aSMatthew G. Knepley               intFaces += 1;
805dae4404aSMatthew G. Knepley             } else {
806dae4404aSMatthew G. Knepley               intFaces += 2;
807dae4404aSMatthew G. Knepley             }
8086ce3c06aSMatthew G. Knepley           } else {
8096ce3c06aSMatthew G. Knepley             intFaces += 1;
8106ce3c06aSMatthew G. Knepley           }
811dae4404aSMatthew G. Knepley         }
812dae4404aSMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, 2+intFaces);CHKERRQ(ierr);
813dae4404aSMatthew G. Knepley       }
814dae4404aSMatthew G. Knepley     }
8156ce3c06aSMatthew G. Knepley     /* Interior cell edges have 2 vertices and 4 faces */
816dae4404aSMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
817dae4404aSMatthew G. Knepley       const PetscInt newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*3 + (c - cStart);
818dae4404aSMatthew G. Knepley 
819dae4404aSMatthew G. Knepley       ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
820dae4404aSMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, 4);CHKERRQ(ierr);
821dae4404aSMatthew G. Knepley     }
8226ce3c06aSMatthew G. Knepley     /* Hybrid edges have 2 vertices and the same faces */
823dae4404aSMatthew G. Knepley     for (e = eMax; e < eEnd; ++e) {
8246ce3c06aSMatthew G. Knepley       const PetscInt newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*3 + (cMax - cStart) + (e - eMax);
8256ce3c06aSMatthew G. Knepley       PetscInt       size;
8266ce3c06aSMatthew G. Knepley 
8276ce3c06aSMatthew G. Knepley       ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
8286ce3c06aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, e, &size);CHKERRQ(ierr);
8296ce3c06aSMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
8306ce3c06aSMatthew G. Knepley     }
8316ce3c06aSMatthew G. Knepley     /* Hybrid face edges have 2 vertices and 2+2*cells faces */
8326ce3c06aSMatthew G. Knepley     for (f = fMax; f < fEnd; ++f) {
8336ce3c06aSMatthew G. Knepley       const PetscInt newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*3 + (cMax - cStart) + (eEnd - eMax) + (f - fMax);
834dae4404aSMatthew G. Knepley       PetscInt       size;
835dae4404aSMatthew G. Knepley 
836dae4404aSMatthew G. Knepley       ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
837dae4404aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
8386ce3c06aSMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, 2+2*size);CHKERRQ(ierr);
839dae4404aSMatthew G. Knepley     }
8406ce3c06aSMatthew G. Knepley     /* Interior vertices have identical supports */
841dae4404aSMatthew G. Knepley     for (v = vStart; v < vEnd; ++v) {
842dae4404aSMatthew G. Knepley       const PetscInt newp = vStartNew + (v - vStart);
843dae4404aSMatthew G. Knepley       PetscInt       size;
844dae4404aSMatthew G. Knepley 
845dae4404aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, v, &size);CHKERRQ(ierr);
846dae4404aSMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
847dae4404aSMatthew G. Knepley     }
8486ce3c06aSMatthew G. Knepley     /* Interior edge vertices have 2 + interior face*2 + hybrid face + cells*0/1 supports */
8496ce3c06aSMatthew G. Knepley     for (e = eStart; e < eMax; ++e) {
8506ce3c06aSMatthew G. Knepley       const PetscInt  newp = vStartNew + (vEnd - vStart) + (e - eStart);
851dae4404aSMatthew G. Knepley       const PetscInt *support;
8526ce3c06aSMatthew G. Knepley       PetscInt        size, *star = NULL, starSize, s, faceSize = 0, cellSize = 0;
853dae4404aSMatthew G. Knepley 
8546ce3c06aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, e, &size);CHKERRQ(ierr);
8556ce3c06aSMatthew G. Knepley       ierr = DMPlexGetSupport(dm, e, &support);CHKERRQ(ierr);
856dae4404aSMatthew G. Knepley       for (s = 0; s < size; ++s) {
8576ce3c06aSMatthew G. Knepley         if (support[s] < fMax) faceSize += 2;
8586ce3c06aSMatthew G. Knepley         else                   faceSize += 1;
859dae4404aSMatthew G. Knepley       }
8606ce3c06aSMatthew G. Knepley       ierr = DMPlexGetTransitiveClosure(dm, e, PETSC_FALSE, &starSize, &star);CHKERRQ(ierr);
8616ce3c06aSMatthew G. Knepley       for (s = 0; s < starSize*2; s += 2) {
8626ce3c06aSMatthew G. Knepley         const PetscInt *cone, *ornt;
8636ce3c06aSMatthew G. Knepley         PetscInt        e01, e23;
8646ce3c06aSMatthew G. Knepley 
8656ce3c06aSMatthew G. Knepley         if ((star[s] >= cStart) && (star[s] < cMax)) {
8666ce3c06aSMatthew G. Knepley           /* Check edge 0-1 */
8676ce3c06aSMatthew G. Knepley           ierr = DMPlexGetCone(dm, star[s], &cone);CHKERRQ(ierr);
8686ce3c06aSMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, star[s], &ornt);CHKERRQ(ierr);
8696ce3c06aSMatthew G. Knepley           ierr = DMPlexGetCone(dm, cone[0], &cone);CHKERRQ(ierr);
8706ce3c06aSMatthew G. Knepley           e01  = cone[GetTriEdge_Static(ornt[0], 0)];
8716ce3c06aSMatthew G. Knepley           /* Check edge 2-3 */
8726ce3c06aSMatthew G. Knepley           ierr = DMPlexGetCone(dm, star[s], &cone);CHKERRQ(ierr);
8736ce3c06aSMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, star[s], &ornt);CHKERRQ(ierr);
8746ce3c06aSMatthew G. Knepley           ierr = DMPlexGetCone(dm, cone[2], &cone);CHKERRQ(ierr);
8756ce3c06aSMatthew G. Knepley           e23  = cone[GetTriEdge_Static(ornt[2], 1)];
8766ce3c06aSMatthew G. Knepley           if ((e01 == e) || (e23 == e)) ++cellSize;
8776ce3c06aSMatthew G. Knepley         }
8786ce3c06aSMatthew G. Knepley       }
8796ce3c06aSMatthew G. Knepley       ierr = DMPlexRestoreTransitiveClosure(dm, e, PETSC_FALSE, &starSize, &star);CHKERRQ(ierr);
8806ce3c06aSMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, 2 + faceSize + cellSize);CHKERRQ(ierr);
881dae4404aSMatthew G. Knepley     }
882dae4404aSMatthew G. Knepley     break;
8839b1a0e7fSLawrence Mitchell   case REFINER_HEX_3D:
8842eabf88fSMatthew G. Knepley     /* All cells have 6 faces */
8852eabf88fSMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
8862eabf88fSMatthew G. Knepley       for (r = 0; r < 8; ++r) {
8872eabf88fSMatthew G. Knepley         const PetscInt newp = (c - cStart)*8 + r;
8882eabf88fSMatthew G. Knepley 
8892eabf88fSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 6);CHKERRQ(ierr);
8902eabf88fSMatthew G. Knepley       }
8912eabf88fSMatthew G. Knepley     }
8922eabf88fSMatthew G. Knepley     /* Split faces have 4 edges and the same cells as the parent */
8932eabf88fSMatthew G. Knepley     for (f = fStart; f < fEnd; ++f) {
8942eabf88fSMatthew G. Knepley       for (r = 0; r < 4; ++r) {
8952eabf88fSMatthew G. Knepley         const PetscInt newp = fStartNew + (f - fStart)*4 + r;
8962eabf88fSMatthew G. Knepley         PetscInt       size;
8972eabf88fSMatthew G. Knepley 
8982eabf88fSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 4);CHKERRQ(ierr);
8992eabf88fSMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
9002eabf88fSMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
9012eabf88fSMatthew G. Knepley       }
9022eabf88fSMatthew G. Knepley     }
9032eabf88fSMatthew G. Knepley     /* Interior faces have 4 edges and 2 cells */
9042eabf88fSMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
9052eabf88fSMatthew G. Knepley       for (r = 0; r < 12; ++r) {
9062eabf88fSMatthew G. Knepley         const PetscInt newp = fStartNew + (fEnd - fStart)*4 + (c - cStart)*12 + r;
9072eabf88fSMatthew G. Knepley 
9082eabf88fSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 4);CHKERRQ(ierr);
9092eabf88fSMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, 2);CHKERRQ(ierr);
9102eabf88fSMatthew G. Knepley       }
9112eabf88fSMatthew G. Knepley     }
9122eabf88fSMatthew G. Knepley     /* Split edges have 2 vertices and the same faces as the parent */
9132eabf88fSMatthew G. Knepley     for (e = eStart; e < eEnd; ++e) {
9142eabf88fSMatthew G. Knepley       for (r = 0; r < 2; ++r) {
9152eabf88fSMatthew G. Knepley         const PetscInt newp = eStartNew + (e - eStart)*2 + r;
9162eabf88fSMatthew G. Knepley         PetscInt       size;
9172eabf88fSMatthew G. Knepley 
9182eabf88fSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
9192eabf88fSMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, e, &size);CHKERRQ(ierr);
9202eabf88fSMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
9212eabf88fSMatthew G. Knepley       }
9222eabf88fSMatthew G. Knepley     }
9232eabf88fSMatthew G. Knepley     /* Face edges have 2 vertices and 2+cells faces */
9242eabf88fSMatthew G. Knepley     for (f = fStart; f < fEnd; ++f) {
9252eabf88fSMatthew G. Knepley       for (r = 0; r < 4; ++r) {
9262eabf88fSMatthew G. Knepley         const PetscInt newp = eStartNew + (eEnd - eStart)*2 + (f - fStart)*4 + r;
9272eabf88fSMatthew G. Knepley         PetscInt       size;
9282eabf88fSMatthew G. Knepley 
9292eabf88fSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
9302eabf88fSMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
9312eabf88fSMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, 2+size);CHKERRQ(ierr);
9322eabf88fSMatthew G. Knepley       }
9332eabf88fSMatthew G. Knepley     }
9342eabf88fSMatthew G. Knepley     /* Cell edges have 2 vertices and 4 faces */
9352eabf88fSMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
9362eabf88fSMatthew G. Knepley       for (r = 0; r < 6; ++r) {
9372eabf88fSMatthew G. Knepley         const PetscInt newp = eStartNew + (eEnd - eStart)*2 + (fEnd - fStart)*4 + (c - cStart)*6 + r;
9382eabf88fSMatthew G. Knepley 
9392eabf88fSMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
9402eabf88fSMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, 4);CHKERRQ(ierr);
9412eabf88fSMatthew G. Knepley       }
9422eabf88fSMatthew G. Knepley     }
9432eabf88fSMatthew G. Knepley     /* Old vertices have identical supports */
9442eabf88fSMatthew G. Knepley     for (v = vStart; v < vEnd; ++v) {
9452eabf88fSMatthew G. Knepley       const PetscInt newp = vStartNew + (v - vStart);
9462eabf88fSMatthew G. Knepley       PetscInt       size;
9472eabf88fSMatthew G. Knepley 
9482eabf88fSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, v, &size);CHKERRQ(ierr);
9492eabf88fSMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
9502eabf88fSMatthew G. Knepley     }
9512eabf88fSMatthew G. Knepley     /* Edge vertices have 2 + faces supports */
9522eabf88fSMatthew G. Knepley     for (e = eStart; e < eEnd; ++e) {
9532eabf88fSMatthew G. Knepley       const PetscInt newp = vStartNew + (vEnd - vStart) + (e - eStart);
9542eabf88fSMatthew G. Knepley       PetscInt       size;
9552eabf88fSMatthew G. Knepley 
9562eabf88fSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, e, &size);CHKERRQ(ierr);
9572eabf88fSMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, 2 + size);CHKERRQ(ierr);
9582eabf88fSMatthew G. Knepley     }
9592eabf88fSMatthew G. Knepley     /* Face vertices have 4 + cells supports */
9602eabf88fSMatthew G. Knepley     for (f = fStart; f < fEnd; ++f) {
9612eabf88fSMatthew G. Knepley       const PetscInt newp = vStartNew + (vEnd - vStart) + (eEnd - eStart) + (f - fStart);
9622eabf88fSMatthew G. Knepley       PetscInt       size;
9632eabf88fSMatthew G. Knepley 
9642eabf88fSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
9652eabf88fSMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, 4 + size);CHKERRQ(ierr);
9662eabf88fSMatthew G. Knepley     }
9672eabf88fSMatthew G. Knepley     /* Cell vertices have 6 supports */
9682eabf88fSMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
9692eabf88fSMatthew G. Knepley       const PetscInt newp = vStartNew + (vEnd - vStart) + (eEnd - eStart) + (fEnd - fStart) + (c - cStart);
9702eabf88fSMatthew G. Knepley 
9712eabf88fSMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, 6);CHKERRQ(ierr);
9722eabf88fSMatthew G. Knepley     }
9732eabf88fSMatthew G. Knepley     break;
9749b1a0e7fSLawrence Mitchell   case REFINER_HYBRID_HEX_3D:
97527fcede3SMatthew G. Knepley     ierr = DMPlexSetHybridBounds(rdm, cStartNew + 8*(cMax-cStart), fStartNew + 4*(fMax - fStart) + 12*(cMax - cStart),
97627fcede3SMatthew G. Knepley                                  eStartNew + 2*(eMax - eStart) + 4*(fMax - fStart) + 6*(cMax - cStart), PETSC_DETERMINE);CHKERRQ(ierr);
97727fcede3SMatthew G. Knepley     /* Interior cells have 6 faces */
97827fcede3SMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
97927fcede3SMatthew G. Knepley       for (r = 0; r < 8; ++r) {
98027fcede3SMatthew G. Knepley         const PetscInt newp = cStartNew + (c - cStart)*8 + r;
98127fcede3SMatthew G. Knepley 
98227fcede3SMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 6);CHKERRQ(ierr);
98327fcede3SMatthew G. Knepley       }
98427fcede3SMatthew G. Knepley     }
98527fcede3SMatthew G. Knepley     /* Hybrid cells have 6 faces */
98627fcede3SMatthew G. Knepley     for (c = cMax; c < cEnd; ++c) {
98727fcede3SMatthew G. Knepley       for (r = 0; r < 4; ++r) {
98827fcede3SMatthew G. Knepley         const PetscInt newp = cStartNew + (cMax - cStart)*8 + (c - cMax)*4 + r;
98927fcede3SMatthew G. Knepley 
99027fcede3SMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 6);CHKERRQ(ierr);
99127fcede3SMatthew G. Knepley       }
99227fcede3SMatthew G. Knepley     }
99327fcede3SMatthew G. Knepley     /* Interior split faces have 4 edges and the same cells as the parent */
99427fcede3SMatthew G. Knepley     for (f = fStart; f < fMax; ++f) {
99527fcede3SMatthew G. Knepley       for (r = 0; r < 4; ++r) {
99627fcede3SMatthew G. Knepley         const PetscInt newp = fStartNew + (f - fStart)*4 + r;
99727fcede3SMatthew G. Knepley         PetscInt       size;
99827fcede3SMatthew G. Knepley 
99927fcede3SMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 4);CHKERRQ(ierr);
100027fcede3SMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
100127fcede3SMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
100227fcede3SMatthew G. Knepley       }
100327fcede3SMatthew G. Knepley     }
100427fcede3SMatthew G. Knepley     /* Interior cell faces have 4 edges and 2 cells */
100527fcede3SMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
100627fcede3SMatthew G. Knepley       for (r = 0; r < 12; ++r) {
100727fcede3SMatthew G. Knepley         const PetscInt newp = fStartNew + (fMax - fStart)*4 + (c - cStart)*12 + r;
100827fcede3SMatthew G. Knepley 
100927fcede3SMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 4);CHKERRQ(ierr);
101027fcede3SMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, 2);CHKERRQ(ierr);
101127fcede3SMatthew G. Knepley       }
101227fcede3SMatthew G. Knepley     }
101327fcede3SMatthew G. Knepley     /* Hybrid split faces have 4 edges and the same cells as the parent */
101427fcede3SMatthew G. Knepley     for (f = fMax; f < fEnd; ++f) {
101527fcede3SMatthew G. Knepley       for (r = 0; r < 2; ++r) {
101627fcede3SMatthew G. Knepley         const PetscInt newp = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*12 + (f - fMax)*2 + r;
101727fcede3SMatthew G. Knepley         PetscInt       size;
101827fcede3SMatthew G. Knepley 
101927fcede3SMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 4);CHKERRQ(ierr);
102027fcede3SMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
102127fcede3SMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
102227fcede3SMatthew G. Knepley       }
102327fcede3SMatthew G. Knepley     }
102427fcede3SMatthew G. Knepley     /* Hybrid cells faces have 4 edges and 2 cells */
102527fcede3SMatthew G. Knepley     for (c = cMax; c < cEnd; ++c) {
102627fcede3SMatthew G. Knepley       for (r = 0; r < 4; ++r) {
102727fcede3SMatthew G. Knepley         const PetscInt newp = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*12 + (fEnd - fMax)*2 + (c - cMax)*4 + r;
102827fcede3SMatthew G. Knepley 
102927fcede3SMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 4);CHKERRQ(ierr);
103027fcede3SMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, 2);CHKERRQ(ierr);
103127fcede3SMatthew G. Knepley       }
103227fcede3SMatthew G. Knepley     }
103327fcede3SMatthew G. Knepley     /* Interior split edges have 2 vertices and the same faces as the parent */
103427fcede3SMatthew G. Knepley     for (e = eStart; e < eMax; ++e) {
103527fcede3SMatthew G. Knepley       for (r = 0; r < 2; ++r) {
103627fcede3SMatthew G. Knepley         const PetscInt newp = eStartNew + (e - eStart)*2 + r;
103727fcede3SMatthew G. Knepley         PetscInt       size;
103827fcede3SMatthew G. Knepley 
103927fcede3SMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
104027fcede3SMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, e, &size);CHKERRQ(ierr);
104127fcede3SMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
104227fcede3SMatthew G. Knepley       }
104327fcede3SMatthew G. Knepley     }
104427fcede3SMatthew G. Knepley     /* Interior face edges have 2 vertices and 2+cells faces */
104527fcede3SMatthew G. Knepley     for (f = fStart; f < fMax; ++f) {
104627fcede3SMatthew G. Knepley       for (r = 0; r < 4; ++r) {
104727fcede3SMatthew G. Knepley         const PetscInt newp = eStartNew + (eMax - eStart)*2 + (f - fStart)*4 + r;
104827fcede3SMatthew G. Knepley         PetscInt       size;
104927fcede3SMatthew G. Knepley 
105027fcede3SMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
105127fcede3SMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
105227fcede3SMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, 2+size);CHKERRQ(ierr);
105327fcede3SMatthew G. Knepley       }
105427fcede3SMatthew G. Knepley     }
105527fcede3SMatthew G. Knepley     /* Interior cell edges have 2 vertices and 4 faces */
105627fcede3SMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
105727fcede3SMatthew G. Knepley       for (r = 0; r < 6; ++r) {
105827fcede3SMatthew G. Knepley         const PetscInt newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (c - cStart)*6 + r;
105927fcede3SMatthew G. Knepley 
106027fcede3SMatthew G. Knepley         ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
106127fcede3SMatthew G. Knepley         ierr = DMPlexSetSupportSize(rdm, newp, 4);CHKERRQ(ierr);
106227fcede3SMatthew G. Knepley       }
106327fcede3SMatthew G. Knepley     }
106427fcede3SMatthew G. Knepley     /* Hybrid edges have 2 vertices and the same faces */
106527fcede3SMatthew G. Knepley     for (e = eMax; e < eEnd; ++e) {
106627fcede3SMatthew G. Knepley       const PetscInt newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (cMax - cStart)*6 + (e - eMax);
106727fcede3SMatthew G. Knepley       PetscInt       size;
106827fcede3SMatthew G. Knepley 
106927fcede3SMatthew G. Knepley       ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
107027fcede3SMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, e, &size);CHKERRQ(ierr);
107127fcede3SMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
107227fcede3SMatthew G. Knepley     }
107327fcede3SMatthew G. Knepley     /* Hybrid face edges have 2 vertices and 2+cells faces */
107427fcede3SMatthew G. Knepley     for (f = fMax; f < fEnd; ++f) {
107527fcede3SMatthew G. Knepley       const PetscInt newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (cMax - cStart)*6 + (eEnd - eMax) + (f - fMax);
107627fcede3SMatthew G. Knepley       PetscInt       size;
107727fcede3SMatthew G. Knepley 
107827fcede3SMatthew G. Knepley       ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
107927fcede3SMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
108027fcede3SMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, 2+size);CHKERRQ(ierr);
108127fcede3SMatthew G. Knepley     }
108227fcede3SMatthew G. Knepley     /* Hybrid cell edges have 2 vertices and 4 faces */
108327fcede3SMatthew G. Knepley     for (c = cMax; c < cEnd; ++c) {
108427fcede3SMatthew G. Knepley       const PetscInt newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (cMax - cStart)*6 + (eEnd - eMax) + (fEnd - fMax) + (c - cMax);
108527fcede3SMatthew G. Knepley 
108627fcede3SMatthew G. Knepley       ierr = DMPlexSetConeSize(rdm, newp, 2);CHKERRQ(ierr);
108727fcede3SMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, 4);CHKERRQ(ierr);
108827fcede3SMatthew G. Knepley     }
108927fcede3SMatthew G. Knepley     /* Interior vertices have identical supports */
109027fcede3SMatthew G. Knepley     for (v = vStart; v < vEnd; ++v) {
109127fcede3SMatthew G. Knepley       const PetscInt newp = vStartNew + (v - vStart);
109227fcede3SMatthew G. Knepley       PetscInt       size;
109327fcede3SMatthew G. Knepley 
109427fcede3SMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, v, &size);CHKERRQ(ierr);
109527fcede3SMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, size);CHKERRQ(ierr);
109627fcede3SMatthew G. Knepley     }
109727fcede3SMatthew G. Knepley     /* Interior edge vertices have 2 + faces supports */
109827fcede3SMatthew G. Knepley     for (e = eStart; e < eMax; ++e) {
109927fcede3SMatthew G. Knepley       const PetscInt newp = vStartNew + (vEnd - vStart) + (e - eStart);
110027fcede3SMatthew G. Knepley       PetscInt       size;
110127fcede3SMatthew G. Knepley 
110227fcede3SMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, e, &size);CHKERRQ(ierr);
110327fcede3SMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, 2 + size);CHKERRQ(ierr);
110427fcede3SMatthew G. Knepley     }
110527fcede3SMatthew G. Knepley     /* Interior face vertices have 4 + cells supports */
110627fcede3SMatthew G. Knepley     for (f = fStart; f < fMax; ++f) {
110727fcede3SMatthew G. Knepley       const PetscInt newp = vStartNew + (vEnd - vStart) + (eMax - eStart) + (f - fStart);
110827fcede3SMatthew G. Knepley       PetscInt       size;
110927fcede3SMatthew G. Knepley 
111027fcede3SMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
111127fcede3SMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, 4 + size);CHKERRQ(ierr);
111227fcede3SMatthew G. Knepley     }
111327fcede3SMatthew G. Knepley     /* Interior cell vertices have 6 supports */
111427fcede3SMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
111527fcede3SMatthew G. Knepley       const PetscInt newp = vStartNew + (vEnd - vStart) + (eMax - eStart) + (fMax - fStart) + (c - cStart);
111627fcede3SMatthew G. Knepley 
111727fcede3SMatthew G. Knepley       ierr = DMPlexSetSupportSize(rdm, newp, 6);CHKERRQ(ierr);
111827fcede3SMatthew G. Knepley     }
111927fcede3SMatthew G. Knepley     break;
112075d3a19aSMatthew G. Knepley   default:
112175d3a19aSMatthew G. Knepley     SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Unknown cell refiner %d", refiner);
112275d3a19aSMatthew G. Knepley   }
112375d3a19aSMatthew G. Knepley   PetscFunctionReturn(0);
112475d3a19aSMatthew G. Knepley }
112575d3a19aSMatthew G. Knepley 
112675d3a19aSMatthew G. Knepley #undef __FUNCT__
112775d3a19aSMatthew G. Knepley #define __FUNCT__ "CellRefinerSetCones"
112886150812SJed Brown static PetscErrorCode CellRefinerSetCones(CellRefiner refiner, DM dm, PetscInt depthSize[], DM rdm)
112975d3a19aSMatthew G. Knepley {
1130b5da9499SMatthew G. Knepley   const PetscInt *faces, cellInd[4] = {0, 1, 2, 3};
11316ce3c06aSMatthew G. Knepley   PetscInt        cStart,    cEnd,    cMax,    vStart,    vEnd, vMax, fStart,    fEnd,    fMax,    eStart,    eEnd,    eMax;
11326ce3c06aSMatthew G. Knepley   PetscInt        cStartNew, cEndNew, cMaxNew, vStartNew, vEndNew,    fStartNew, fEndNew, fMaxNew, eStartNew, eEndNew, eMaxNew;
11336ce3c06aSMatthew G. Knepley   PetscInt        depth, maxSupportSize, *supportRef, c, f, e, v, r, p;
113475d3a19aSMatthew G. Knepley   PetscErrorCode  ierr;
113575d3a19aSMatthew G. Knepley 
113675d3a19aSMatthew G. Knepley   PetscFunctionBegin;
11372a5d0125SJed Brown   if (!refiner) PetscFunctionReturn(0);
113875d3a19aSMatthew G. Knepley   ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr);
113975d3a19aSMatthew G. Knepley   ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr);
114075d3a19aSMatthew G. Knepley   ierr = DMPlexGetDepthStratum(dm, 1, &eStart, &eEnd);CHKERRQ(ierr);
114175d3a19aSMatthew G. Knepley   ierr = DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd);CHKERRQ(ierr);
114275d3a19aSMatthew G. Knepley   ierr = DMPlexGetHeightStratum(dm, 1, &fStart, &fEnd);CHKERRQ(ierr);
114375d3a19aSMatthew G. Knepley   ierr = DMPlexGetHybridBounds(dm, &cMax, &fMax, &eMax, &vMax);CHKERRQ(ierr);
114475d3a19aSMatthew G. Knepley   ierr = GetDepthStart_Private(depth, depthSize, &cStartNew, &fStartNew, &eStartNew, &vStartNew);CHKERRQ(ierr);
114575d3a19aSMatthew G. Knepley   ierr = GetDepthEnd_Private(depth, depthSize, &cEndNew, &fEndNew, &eEndNew, &vEndNew);CHKERRQ(ierr);
114675d3a19aSMatthew G. Knepley   switch (refiner) {
11470314a74cSLawrence Mitchell   case REFINER_SIMPLEX_1D:
11480314a74cSLawrence Mitchell     /* Max support size of refined mesh is 2 */
11490314a74cSLawrence Mitchell     ierr = PetscMalloc1(2, &supportRef);CHKERRQ(ierr);
11500314a74cSLawrence Mitchell     /* All cells have 2 vertices */
11510314a74cSLawrence Mitchell     for (c = cStart; c < cEnd; ++c) {
11520314a74cSLawrence Mitchell       const PetscInt  newv = vStartNew + (vEnd - vStart) + (c - cStart);
11530314a74cSLawrence Mitchell 
11540314a74cSLawrence Mitchell       for (r = 0; r < 2; ++r) {
11550314a74cSLawrence Mitchell         const PetscInt newp = cStartNew + (c - cStart)*2 + r;
11560314a74cSLawrence Mitchell         const PetscInt *cone;
11570314a74cSLawrence Mitchell         PetscInt        coneNew[2];
11580314a74cSLawrence Mitchell 
11590314a74cSLawrence Mitchell         ierr             = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
11600314a74cSLawrence Mitchell         coneNew[0]       = vStartNew + (cone[0] - vStart);
11610314a74cSLawrence Mitchell         coneNew[1]       = vStartNew + (cone[1] - vStart);
11620314a74cSLawrence Mitchell         coneNew[(r+1)%2] = newv;
11630314a74cSLawrence Mitchell         ierr             = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
11640314a74cSLawrence Mitchell #if 1
11650314a74cSLawrence Mitchell         if ((newp < cStartNew) || (newp >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp, cStartNew, cEndNew);
11660314a74cSLawrence Mitchell         for (p = 0; p < 2; ++p) {
11670314a74cSLawrence Mitchell           if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
11680314a74cSLawrence Mitchell         }
11690314a74cSLawrence Mitchell #endif
11700314a74cSLawrence Mitchell       }
11710314a74cSLawrence Mitchell     }
11720314a74cSLawrence Mitchell     /* Old vertices have identical supports */
11730314a74cSLawrence Mitchell     for (v = vStart; v < vEnd; ++v) {
11740314a74cSLawrence Mitchell       const PetscInt  newp = vStartNew + (v - vStart);
11750314a74cSLawrence Mitchell       const PetscInt *support, *cone;
11760314a74cSLawrence Mitchell       PetscInt        size, s;
11770314a74cSLawrence Mitchell 
11780314a74cSLawrence Mitchell       ierr = DMPlexGetSupportSize(dm, v, &size);CHKERRQ(ierr);
11790314a74cSLawrence Mitchell       ierr = DMPlexGetSupport(dm, v, &support);CHKERRQ(ierr);
11800314a74cSLawrence Mitchell       for (s = 0; s < size; ++s) {
11810314a74cSLawrence Mitchell         PetscInt r = 0;
11820314a74cSLawrence Mitchell 
11830314a74cSLawrence Mitchell         ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
11840314a74cSLawrence Mitchell         if (cone[1] == v) r = 1;
11850314a74cSLawrence Mitchell         supportRef[s] = cStartNew + (support[s] - cStart)*2 + r;
11860314a74cSLawrence Mitchell       }
11870314a74cSLawrence Mitchell       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
11880314a74cSLawrence Mitchell #if 1
11890314a74cSLawrence Mitchell       if ((newp < vStartNew) || (newp >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", newp, vStartNew, vEndNew);
11900314a74cSLawrence Mitchell       for (p = 0; p < size; ++p) {
11910314a74cSLawrence Mitchell         if ((supportRef[p] < cStartNew) || (supportRef[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportRef[p], cStartNew, cEndNew);
11920314a74cSLawrence Mitchell       }
11930314a74cSLawrence Mitchell #endif
11940314a74cSLawrence Mitchell     }
11950314a74cSLawrence Mitchell     /* Cell vertices have support of 2 cells */
11960314a74cSLawrence Mitchell     for (c = cStart; c < cEnd; ++c) {
11970314a74cSLawrence Mitchell       const PetscInt  newp = vStartNew + (vEnd - vStart) + (c - cStart);
11980314a74cSLawrence Mitchell 
11990314a74cSLawrence Mitchell       supportRef[0] = cStartNew + (c - cStart)*2 + 0;
12000314a74cSLawrence Mitchell       supportRef[1] = cStartNew + (c - cStart)*2 + 1;
12010314a74cSLawrence Mitchell       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
12020314a74cSLawrence Mitchell #if 1
12030314a74cSLawrence Mitchell       if ((newp < vStartNew) || (newp >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", newp, vStartNew, vEndNew);
12040314a74cSLawrence Mitchell       for (p = 0; p < 2; ++p) {
12050314a74cSLawrence Mitchell         if ((supportRef[p] < cStartNew) || (supportRef[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportRef[p], cStartNew, cEndNew);
12060314a74cSLawrence Mitchell       }
12070314a74cSLawrence Mitchell #endif
12080314a74cSLawrence Mitchell     }
12090314a74cSLawrence Mitchell     ierr = PetscFree(supportRef);CHKERRQ(ierr);
12100314a74cSLawrence Mitchell     break;
12119b1a0e7fSLawrence Mitchell   case REFINER_SIMPLEX_2D:
121275d3a19aSMatthew G. Knepley     /*
121375d3a19aSMatthew G. Knepley      2
121475d3a19aSMatthew G. Knepley      |\
121575d3a19aSMatthew G. Knepley      | \
121675d3a19aSMatthew G. Knepley      |  \
121775d3a19aSMatthew G. Knepley      |   \
121875d3a19aSMatthew G. Knepley      | C  \
121975d3a19aSMatthew G. Knepley      |     \
122075d3a19aSMatthew G. Knepley      |      \
122175d3a19aSMatthew G. Knepley      2---1---1
122275d3a19aSMatthew G. Knepley      |\  D  / \
122375d3a19aSMatthew G. Knepley      | 2   0   \
122475d3a19aSMatthew G. Knepley      |A \ /  B  \
122575d3a19aSMatthew G. Knepley      0---0-------1
122675d3a19aSMatthew G. Knepley      */
122775d3a19aSMatthew G. Knepley     /* All cells have 3 faces */
122875d3a19aSMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
122975d3a19aSMatthew G. Knepley       const PetscInt  newp = cStartNew + (c - cStart)*4;
123075d3a19aSMatthew G. Knepley       const PetscInt *cone, *ornt;
123175d3a19aSMatthew G. Knepley       PetscInt        coneNew[3], orntNew[3];
123275d3a19aSMatthew G. Knepley 
123375d3a19aSMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
123475d3a19aSMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr);
123575d3a19aSMatthew G. Knepley       /* A triangle */
123675d3a19aSMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*2 + (ornt[0] < 0 ? 1 : 0);
123775d3a19aSMatthew G. Knepley       orntNew[0] = ornt[0];
123875d3a19aSMatthew G. Knepley       coneNew[1] = fStartNew + (fEnd    - fStart)*2 + (c - cStart)*3 + 2;
123975d3a19aSMatthew G. Knepley       orntNew[1] = -2;
124075d3a19aSMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*2 + (ornt[2] < 0 ? 0 : 1);
124175d3a19aSMatthew G. Knepley       orntNew[2] = ornt[2];
124275d3a19aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+0, coneNew);CHKERRQ(ierr);
124375d3a19aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+0, orntNew);CHKERRQ(ierr);
124475d3a19aSMatthew G. Knepley #if 1
124575d3a19aSMatthew G. Knepley       if ((newp+0 < cStartNew) || (newp+0 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+0, cStartNew, cEndNew);
124675d3a19aSMatthew G. Knepley       for (p = 0; p < 3; ++p) {
124775d3a19aSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
124875d3a19aSMatthew G. Knepley       }
124975d3a19aSMatthew G. Knepley #endif
125075d3a19aSMatthew G. Knepley       /* B triangle */
125175d3a19aSMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*2 + (ornt[0] < 0 ? 0 : 1);
125275d3a19aSMatthew G. Knepley       orntNew[0] = ornt[0];
125375d3a19aSMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*2 + (ornt[1] < 0 ? 1 : 0);
125475d3a19aSMatthew G. Knepley       orntNew[1] = ornt[1];
125575d3a19aSMatthew G. Knepley       coneNew[2] = fStartNew + (fEnd    - fStart)*2 + (c - cStart)*3 + 0;
125675d3a19aSMatthew G. Knepley       orntNew[2] = -2;
125775d3a19aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+1, coneNew);CHKERRQ(ierr);
125875d3a19aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+1, orntNew);CHKERRQ(ierr);
125975d3a19aSMatthew G. Knepley #if 1
126075d3a19aSMatthew G. Knepley       if ((newp+1 < cStartNew) || (newp+1 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+1, cStartNew, cEndNew);
126175d3a19aSMatthew G. Knepley       for (p = 0; p < 3; ++p) {
126275d3a19aSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
126375d3a19aSMatthew G. Knepley       }
126475d3a19aSMatthew G. Knepley #endif
126575d3a19aSMatthew G. Knepley       /* C triangle */
126675d3a19aSMatthew G. Knepley       coneNew[0] = fStartNew + (fEnd    - fStart)*2 + (c - cStart)*3 + 1;
126775d3a19aSMatthew G. Knepley       orntNew[0] = -2;
126875d3a19aSMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*2 + (ornt[1] < 0 ? 0 : 1);
126975d3a19aSMatthew G. Knepley       orntNew[1] = ornt[1];
127075d3a19aSMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*2 + (ornt[2] < 0 ? 1 : 0);
127175d3a19aSMatthew G. Knepley       orntNew[2] = ornt[2];
127275d3a19aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+2, coneNew);CHKERRQ(ierr);
127375d3a19aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+2, orntNew);CHKERRQ(ierr);
127475d3a19aSMatthew G. Knepley #if 1
127575d3a19aSMatthew G. Knepley       if ((newp+2 < cStartNew) || (newp+2 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+2, cStartNew, cEndNew);
127675d3a19aSMatthew G. Knepley       for (p = 0; p < 3; ++p) {
127775d3a19aSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
127875d3a19aSMatthew G. Knepley       }
127975d3a19aSMatthew G. Knepley #endif
128075d3a19aSMatthew G. Knepley       /* D triangle */
128175d3a19aSMatthew G. Knepley       coneNew[0] = fStartNew + (fEnd    - fStart)*2 + (c - cStart)*3 + 0;
128275d3a19aSMatthew G. Knepley       orntNew[0] = 0;
128375d3a19aSMatthew G. Knepley       coneNew[1] = fStartNew + (fEnd    - fStart)*2 + (c - cStart)*3 + 1;
128475d3a19aSMatthew G. Knepley       orntNew[1] = 0;
128575d3a19aSMatthew G. Knepley       coneNew[2] = fStartNew + (fEnd    - fStart)*2 + (c - cStart)*3 + 2;
128675d3a19aSMatthew G. Knepley       orntNew[2] = 0;
128775d3a19aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+3, coneNew);CHKERRQ(ierr);
128875d3a19aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+3, orntNew);CHKERRQ(ierr);
128975d3a19aSMatthew G. Knepley #if 1
129075d3a19aSMatthew G. Knepley       if ((newp+3 < cStartNew) || (newp+3 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+3, cStartNew, cEndNew);
129175d3a19aSMatthew G. Knepley       for (p = 0; p < 3; ++p) {
129275d3a19aSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
129375d3a19aSMatthew G. Knepley       }
129475d3a19aSMatthew G. Knepley #endif
129575d3a19aSMatthew G. Knepley     }
129675d3a19aSMatthew G. Knepley     /* Split faces have 2 vertices and the same cells as the parent */
129775d3a19aSMatthew G. Knepley     ierr = DMPlexGetMaxSizes(dm, NULL, &maxSupportSize);CHKERRQ(ierr);
1298854ce69bSBarry Smith     ierr = PetscMalloc1(2 + maxSupportSize*2, &supportRef);CHKERRQ(ierr);
129975d3a19aSMatthew G. Knepley     for (f = fStart; f < fEnd; ++f) {
130075d3a19aSMatthew G. Knepley       const PetscInt newv = vStartNew + (vEnd - vStart) + (f - fStart);
130175d3a19aSMatthew G. Knepley 
130275d3a19aSMatthew G. Knepley       for (r = 0; r < 2; ++r) {
130375d3a19aSMatthew G. Knepley         const PetscInt  newp = fStartNew + (f - fStart)*2 + r;
1304297d2bf4SMatthew G. Knepley         const PetscInt *cone, *ornt, *support;
130575d3a19aSMatthew G. Knepley         PetscInt        coneNew[2], coneSize, c, supportSize, s;
130675d3a19aSMatthew G. Knepley 
130775d3a19aSMatthew G. Knepley         ierr             = DMPlexGetCone(dm, f, &cone);CHKERRQ(ierr);
130875d3a19aSMatthew G. Knepley         coneNew[0]       = vStartNew + (cone[0] - vStart);
130975d3a19aSMatthew G. Knepley         coneNew[1]       = vStartNew + (cone[1] - vStart);
131075d3a19aSMatthew G. Knepley         coneNew[(r+1)%2] = newv;
131175d3a19aSMatthew G. Knepley         ierr             = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
131275d3a19aSMatthew G. Knepley #if 1
131375d3a19aSMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
131475d3a19aSMatthew G. Knepley         for (p = 0; p < 2; ++p) {
131575d3a19aSMatthew G. Knepley           if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
131675d3a19aSMatthew G. Knepley         }
131775d3a19aSMatthew G. Knepley #endif
131875d3a19aSMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &supportSize);CHKERRQ(ierr);
131975d3a19aSMatthew G. Knepley         ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
132075d3a19aSMatthew G. Knepley         for (s = 0; s < supportSize; ++s) {
132175d3a19aSMatthew G. Knepley           ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr);
132275d3a19aSMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
1323297d2bf4SMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, support[s], &ornt);CHKERRQ(ierr);
132475d3a19aSMatthew G. Knepley           for (c = 0; c < coneSize; ++c) {
132575d3a19aSMatthew G. Knepley             if (cone[c] == f) break;
132675d3a19aSMatthew G. Knepley           }
1327297d2bf4SMatthew G. Knepley           supportRef[s] = cStartNew + (support[s] - cStart)*4 + (ornt[c] < 0 ? (c+1-r)%3 : (c+r)%3);
132875d3a19aSMatthew G. Knepley         }
132975d3a19aSMatthew G. Knepley         ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
133075d3a19aSMatthew G. Knepley #if 1
133175d3a19aSMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
133275d3a19aSMatthew G. Knepley         for (p = 0; p < supportSize; ++p) {
133375d3a19aSMatthew G. Knepley           if ((supportRef[p] < cStartNew) || (supportRef[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportRef[p], cStartNew, cEndNew);
133475d3a19aSMatthew G. Knepley         }
133575d3a19aSMatthew G. Knepley #endif
133675d3a19aSMatthew G. Knepley       }
133775d3a19aSMatthew G. Knepley     }
133875d3a19aSMatthew G. Knepley     /* Interior faces have 2 vertices and 2 cells */
133975d3a19aSMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
134075d3a19aSMatthew G. Knepley       const PetscInt *cone;
134175d3a19aSMatthew G. Knepley 
134275d3a19aSMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
134375d3a19aSMatthew G. Knepley       for (r = 0; r < 3; ++r) {
134475d3a19aSMatthew G. Knepley         const PetscInt newp = fStartNew + (fEnd - fStart)*2 + (c - cStart)*3 + r;
134575d3a19aSMatthew G. Knepley         PetscInt       coneNew[2];
134675d3a19aSMatthew G. Knepley         PetscInt       supportNew[2];
134775d3a19aSMatthew G. Knepley 
134875d3a19aSMatthew G. Knepley         coneNew[0] = vStartNew + (vEnd - vStart) + (cone[r]       - fStart);
134975d3a19aSMatthew G. Knepley         coneNew[1] = vStartNew + (vEnd - vStart) + (cone[(r+1)%3] - fStart);
135075d3a19aSMatthew G. Knepley         ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
135175d3a19aSMatthew G. Knepley #if 1
135275d3a19aSMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
135375d3a19aSMatthew G. Knepley         for (p = 0; p < 2; ++p) {
135475d3a19aSMatthew G. Knepley           if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
135575d3a19aSMatthew G. Knepley         }
135675d3a19aSMatthew G. Knepley #endif
135775d3a19aSMatthew G. Knepley         supportNew[0] = (c - cStart)*4 + (r+1)%3;
135875d3a19aSMatthew G. Knepley         supportNew[1] = (c - cStart)*4 + 3;
135975d3a19aSMatthew G. Knepley         ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
136075d3a19aSMatthew G. Knepley #if 1
136175d3a19aSMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
136275d3a19aSMatthew G. Knepley         for (p = 0; p < 2; ++p) {
136375d3a19aSMatthew G. Knepley           if ((supportNew[p] < cStartNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cEndNew);
136475d3a19aSMatthew G. Knepley         }
136575d3a19aSMatthew G. Knepley #endif
136675d3a19aSMatthew G. Knepley       }
136775d3a19aSMatthew G. Knepley     }
136875d3a19aSMatthew G. Knepley     /* Old vertices have identical supports */
136975d3a19aSMatthew G. Knepley     for (v = vStart; v < vEnd; ++v) {
137075d3a19aSMatthew G. Knepley       const PetscInt  newp = vStartNew + (v - vStart);
137175d3a19aSMatthew G. Knepley       const PetscInt *support, *cone;
137275d3a19aSMatthew G. Knepley       PetscInt        size, s;
137375d3a19aSMatthew G. Knepley 
137475d3a19aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, v, &size);CHKERRQ(ierr);
137575d3a19aSMatthew G. Knepley       ierr = DMPlexGetSupport(dm, v, &support);CHKERRQ(ierr);
137675d3a19aSMatthew G. Knepley       for (s = 0; s < size; ++s) {
137775d3a19aSMatthew G. Knepley         PetscInt r = 0;
137875d3a19aSMatthew G. Knepley 
137975d3a19aSMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
138075d3a19aSMatthew G. Knepley         if (cone[1] == v) r = 1;
138175d3a19aSMatthew G. Knepley         supportRef[s] = fStartNew + (support[s] - fStart)*2 + r;
138275d3a19aSMatthew G. Knepley       }
138375d3a19aSMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
138475d3a19aSMatthew G. Knepley #if 1
138575d3a19aSMatthew G. Knepley       if ((newp < vStartNew) || (newp >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", newp, vStartNew, vEndNew);
138675d3a19aSMatthew G. Knepley       for (p = 0; p < size; ++p) {
138775d3a19aSMatthew G. Knepley         if ((supportRef[p] < fStartNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", supportRef[p], fStartNew, fEndNew);
138875d3a19aSMatthew G. Knepley       }
138975d3a19aSMatthew G. Knepley #endif
139075d3a19aSMatthew G. Knepley     }
139175d3a19aSMatthew G. Knepley     /* Face vertices have 2 + cells*2 supports */
139275d3a19aSMatthew G. Knepley     for (f = fStart; f < fEnd; ++f) {
139375d3a19aSMatthew G. Knepley       const PetscInt  newp = vStartNew + (vEnd - vStart) + (f - fStart);
139475d3a19aSMatthew G. Knepley       const PetscInt *cone, *support;
139575d3a19aSMatthew G. Knepley       PetscInt        size, s;
139675d3a19aSMatthew G. Knepley 
139775d3a19aSMatthew G. Knepley       ierr          = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
139875d3a19aSMatthew G. Knepley       ierr          = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
139975d3a19aSMatthew G. Knepley       supportRef[0] = fStartNew + (f - fStart)*2 + 0;
140075d3a19aSMatthew G. Knepley       supportRef[1] = fStartNew + (f - fStart)*2 + 1;
140175d3a19aSMatthew G. Knepley       for (s = 0; s < size; ++s) {
140275d3a19aSMatthew G. Knepley         PetscInt r = 0;
140375d3a19aSMatthew G. Knepley 
140475d3a19aSMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
140575d3a19aSMatthew G. Knepley         if      (cone[1] == f) r = 1;
140675d3a19aSMatthew G. Knepley         else if (cone[2] == f) r = 2;
140775d3a19aSMatthew G. Knepley         supportRef[2+s*2+0] = fStartNew + (fEnd - fStart)*2 + (support[s] - cStart)*3 + (r+2)%3;
140875d3a19aSMatthew G. Knepley         supportRef[2+s*2+1] = fStartNew + (fEnd - fStart)*2 + (support[s] - cStart)*3 + r;
140975d3a19aSMatthew G. Knepley       }
141075d3a19aSMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
141175d3a19aSMatthew G. Knepley #if 1
141275d3a19aSMatthew G. Knepley       if ((newp < vStartNew) || (newp >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", newp, vStartNew, vEndNew);
141375d3a19aSMatthew G. Knepley       for (p = 0; p < 2+size*2; ++p) {
141475d3a19aSMatthew G. Knepley         if ((supportRef[p] < fStartNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", supportRef[p], fStartNew, fEndNew);
141575d3a19aSMatthew G. Knepley       }
141675d3a19aSMatthew G. Knepley #endif
141775d3a19aSMatthew G. Knepley     }
141875d3a19aSMatthew G. Knepley     ierr = PetscFree(supportRef);CHKERRQ(ierr);
141975d3a19aSMatthew G. Knepley     break;
14209b1a0e7fSLawrence Mitchell   case REFINER_HEX_2D:
142175d3a19aSMatthew G. Knepley     /*
142275d3a19aSMatthew G. Knepley      3---------2---------2
142375d3a19aSMatthew G. Knepley      |         |         |
142475d3a19aSMatthew G. Knepley      |    D    2    C    |
142575d3a19aSMatthew G. Knepley      |         |         |
142675d3a19aSMatthew G. Knepley      3----3----0----1----1
142775d3a19aSMatthew G. Knepley      |         |         |
142875d3a19aSMatthew G. Knepley      |    A    0    B    |
142975d3a19aSMatthew G. Knepley      |         |         |
143075d3a19aSMatthew G. Knepley      0---------0---------1
143175d3a19aSMatthew G. Knepley      */
143275d3a19aSMatthew G. Knepley     /* All cells have 4 faces */
143375d3a19aSMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
143475d3a19aSMatthew G. Knepley       const PetscInt  newp = (c - cStart)*4;
143575d3a19aSMatthew G. Knepley       const PetscInt *cone, *ornt;
143675d3a19aSMatthew G. Knepley       PetscInt        coneNew[4], orntNew[4];
143775d3a19aSMatthew G. Knepley 
143875d3a19aSMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
143975d3a19aSMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr);
144075d3a19aSMatthew G. Knepley       /* A quad */
144175d3a19aSMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*2 + (ornt[0] < 0 ? 1 : 0);
144275d3a19aSMatthew G. Knepley       orntNew[0] = ornt[0];
144375d3a19aSMatthew G. Knepley       coneNew[1] = fStartNew + (fEnd    - fStart)*2 + (c - cStart)*4 + 0;
144475d3a19aSMatthew G. Knepley       orntNew[1] = 0;
144575d3a19aSMatthew G. Knepley       coneNew[2] = fStartNew + (fEnd    - fStart)*2 + (c - cStart)*4 + 3;
144675d3a19aSMatthew G. Knepley       orntNew[2] = -2;
144775d3a19aSMatthew G. Knepley       coneNew[3] = fStartNew + (cone[3] - fStart)*2 + (ornt[3] < 0 ? 0 : 1);
144875d3a19aSMatthew G. Knepley       orntNew[3] = ornt[3];
144975d3a19aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+0, coneNew);CHKERRQ(ierr);
145075d3a19aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+0, orntNew);CHKERRQ(ierr);
145175d3a19aSMatthew G. Knepley #if 1
145275d3a19aSMatthew G. Knepley       if ((newp+0 < cStartNew) || (newp+0 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+0, cStartNew, cEndNew);
145375d3a19aSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
145475d3a19aSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
145575d3a19aSMatthew G. Knepley       }
145675d3a19aSMatthew G. Knepley #endif
145775d3a19aSMatthew G. Knepley       /* B quad */
145875d3a19aSMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*2 + (ornt[0] < 0 ? 0 : 1);
145975d3a19aSMatthew G. Knepley       orntNew[0] = ornt[0];
146075d3a19aSMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*2 + (ornt[1] < 0 ? 1 : 0);
146175d3a19aSMatthew G. Knepley       orntNew[1] = ornt[1];
146275d3a19aSMatthew G. Knepley       coneNew[2] = fStartNew + (fEnd    - fStart)*2 + (c - cStart)*4 + 1;
146375d3a19aSMatthew G. Knepley       orntNew[2] = 0;
146475d3a19aSMatthew G. Knepley       coneNew[3] = fStartNew + (fEnd    - fStart)*2 + (c - cStart)*4 + 0;
146575d3a19aSMatthew G. Knepley       orntNew[3] = -2;
146675d3a19aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+1, coneNew);CHKERRQ(ierr);
146775d3a19aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+1, orntNew);CHKERRQ(ierr);
146875d3a19aSMatthew G. Knepley #if 1
146975d3a19aSMatthew G. Knepley       if ((newp+1 < cStartNew) || (newp+1 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+1, cStartNew, cEndNew);
147075d3a19aSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
147175d3a19aSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
147275d3a19aSMatthew G. Knepley       }
147375d3a19aSMatthew G. Knepley #endif
147475d3a19aSMatthew G. Knepley       /* C quad */
147575d3a19aSMatthew G. Knepley       coneNew[0] = fStartNew + (fEnd    - fStart)*2 + (c - cStart)*4 + 1;
147675d3a19aSMatthew G. Knepley       orntNew[0] = -2;
147775d3a19aSMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*2 + (ornt[1] < 0 ? 0 : 1);
147875d3a19aSMatthew G. Knepley       orntNew[1] = ornt[1];
147975d3a19aSMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*2 + (ornt[2] < 0 ? 1 : 0);
148075d3a19aSMatthew G. Knepley       orntNew[2] = ornt[2];
148175d3a19aSMatthew G. Knepley       coneNew[3] = fStartNew + (fEnd    - fStart)*2 + (c - cStart)*4 + 2;
148275d3a19aSMatthew G. Knepley       orntNew[3] = 0;
148375d3a19aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+2, coneNew);CHKERRQ(ierr);
148475d3a19aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+2, orntNew);CHKERRQ(ierr);
148575d3a19aSMatthew G. Knepley #if 1
148675d3a19aSMatthew G. Knepley       if ((newp+2 < cStartNew) || (newp+2 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+2, cStartNew, cEndNew);
148775d3a19aSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
148875d3a19aSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
148975d3a19aSMatthew G. Knepley       }
149075d3a19aSMatthew G. Knepley #endif
149175d3a19aSMatthew G. Knepley       /* D quad */
149275d3a19aSMatthew G. Knepley       coneNew[0] = fStartNew + (fEnd    - fStart)*2 + (c - cStart)*4 + 3;
149375d3a19aSMatthew G. Knepley       orntNew[0] = 0;
149475d3a19aSMatthew G. Knepley       coneNew[1] = fStartNew + (fEnd    - fStart)*2 + (c - cStart)*4 + 2;
149575d3a19aSMatthew G. Knepley       orntNew[1] = -2;
149675d3a19aSMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*2 + (ornt[2] < 0 ? 0 : 1);
149775d3a19aSMatthew G. Knepley       orntNew[2] = ornt[2];
149875d3a19aSMatthew G. Knepley       coneNew[3] = fStartNew + (cone[3] - fStart)*2 + (ornt[3] < 0 ? 1 : 0);
149975d3a19aSMatthew G. Knepley       orntNew[3] = ornt[3];
150075d3a19aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+3, coneNew);CHKERRQ(ierr);
150175d3a19aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+3, orntNew);CHKERRQ(ierr);
150275d3a19aSMatthew G. Knepley #if 1
150375d3a19aSMatthew G. Knepley       if ((newp+3 < cStartNew) || (newp+3 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+3, cStartNew, cEndNew);
150475d3a19aSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
150575d3a19aSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
150675d3a19aSMatthew G. Knepley       }
150775d3a19aSMatthew G. Knepley #endif
150875d3a19aSMatthew G. Knepley     }
150975d3a19aSMatthew G. Knepley     /* Split faces have 2 vertices and the same cells as the parent */
151075d3a19aSMatthew G. Knepley     ierr = DMPlexGetMaxSizes(dm, NULL, &maxSupportSize);CHKERRQ(ierr);
1511854ce69bSBarry Smith     ierr = PetscMalloc1(2 + maxSupportSize*2, &supportRef);CHKERRQ(ierr);
151275d3a19aSMatthew G. Knepley     for (f = fStart; f < fEnd; ++f) {
151375d3a19aSMatthew G. Knepley       const PetscInt newv = vStartNew + (vEnd - vStart) + (f - fStart);
151475d3a19aSMatthew G. Knepley 
151575d3a19aSMatthew G. Knepley       for (r = 0; r < 2; ++r) {
151675d3a19aSMatthew G. Knepley         const PetscInt  newp = fStartNew + (f - fStart)*2 + r;
1517455d6cd4SMatthew G. Knepley         const PetscInt *cone, *ornt, *support;
151875d3a19aSMatthew G. Knepley         PetscInt        coneNew[2], coneSize, c, supportSize, s;
151975d3a19aSMatthew G. Knepley 
152075d3a19aSMatthew G. Knepley         ierr             = DMPlexGetCone(dm, f, &cone);CHKERRQ(ierr);
152175d3a19aSMatthew G. Knepley         coneNew[0]       = vStartNew + (cone[0] - vStart);
152275d3a19aSMatthew G. Knepley         coneNew[1]       = vStartNew + (cone[1] - vStart);
152375d3a19aSMatthew G. Knepley         coneNew[(r+1)%2] = newv;
152475d3a19aSMatthew G. Knepley         ierr             = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
152575d3a19aSMatthew G. Knepley #if 1
152675d3a19aSMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
152775d3a19aSMatthew G. Knepley         for (p = 0; p < 2; ++p) {
152875d3a19aSMatthew G. Knepley           if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
152975d3a19aSMatthew G. Knepley         }
153075d3a19aSMatthew G. Knepley #endif
153175d3a19aSMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &supportSize);CHKERRQ(ierr);
153275d3a19aSMatthew G. Knepley         ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
153375d3a19aSMatthew G. Knepley         for (s = 0; s < supportSize; ++s) {
153475d3a19aSMatthew G. Knepley           ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr);
153575d3a19aSMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
1536455d6cd4SMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, support[s], &ornt);CHKERRQ(ierr);
153775d3a19aSMatthew G. Knepley           for (c = 0; c < coneSize; ++c) {
153875d3a19aSMatthew G. Knepley             if (cone[c] == f) break;
153975d3a19aSMatthew G. Knepley           }
1540455d6cd4SMatthew G. Knepley           supportRef[s] = cStartNew + (support[s] - cStart)*4 + (ornt[c] < 0 ? (c+1-r)%4 : (c+r)%4);
154175d3a19aSMatthew G. Knepley         }
154275d3a19aSMatthew G. Knepley         ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
154375d3a19aSMatthew G. Knepley #if 1
154475d3a19aSMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
154575d3a19aSMatthew G. Knepley         for (p = 0; p < supportSize; ++p) {
154675d3a19aSMatthew G. Knepley           if ((supportRef[p] < cStartNew) || (supportRef[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportRef[p], cStartNew, cEndNew);
154775d3a19aSMatthew G. Knepley         }
154875d3a19aSMatthew G. Knepley #endif
154975d3a19aSMatthew G. Knepley       }
155075d3a19aSMatthew G. Knepley     }
155175d3a19aSMatthew G. Knepley     /* Interior faces have 2 vertices and 2 cells */
155275d3a19aSMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
155375d3a19aSMatthew G. Knepley       const PetscInt *cone;
155475d3a19aSMatthew G. Knepley       PetscInt        coneNew[2], supportNew[2];
155575d3a19aSMatthew G. Knepley 
155675d3a19aSMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
155775d3a19aSMatthew G. Knepley       for (r = 0; r < 4; ++r) {
155875d3a19aSMatthew G. Knepley         const PetscInt newp = fStartNew + (fEnd - fStart)*2 + (c - cStart)*4 + r;
155975d3a19aSMatthew G. Knepley 
156075d3a19aSMatthew G. Knepley         coneNew[0] = vStartNew + (vEnd - vStart) + (cone[r] - fStart);
156175d3a19aSMatthew G. Knepley         coneNew[1] = vStartNew + (vEnd - vStart) + (fEnd    - fStart) + (c - cStart);
156275d3a19aSMatthew G. Knepley         ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
156375d3a19aSMatthew G. Knepley #if 1
156475d3a19aSMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
156575d3a19aSMatthew G. Knepley         for (p = 0; p < 2; ++p) {
156675d3a19aSMatthew G. Knepley           if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
156775d3a19aSMatthew G. Knepley         }
156875d3a19aSMatthew G. Knepley #endif
156975d3a19aSMatthew G. Knepley         supportNew[0] = (c - cStart)*4 + r;
157075d3a19aSMatthew G. Knepley         supportNew[1] = (c - cStart)*4 + (r+1)%4;
157175d3a19aSMatthew G. Knepley         ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
157275d3a19aSMatthew G. Knepley #if 1
157375d3a19aSMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
157475d3a19aSMatthew G. Knepley         for (p = 0; p < 2; ++p) {
157575d3a19aSMatthew G. Knepley           if ((supportNew[p] < cStartNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cEndNew);
157675d3a19aSMatthew G. Knepley         }
157775d3a19aSMatthew G. Knepley #endif
157875d3a19aSMatthew G. Knepley       }
157975d3a19aSMatthew G. Knepley     }
158075d3a19aSMatthew G. Knepley     /* Old vertices have identical supports */
158175d3a19aSMatthew G. Knepley     for (v = vStart; v < vEnd; ++v) {
158275d3a19aSMatthew G. Knepley       const PetscInt  newp = vStartNew + (v - vStart);
158375d3a19aSMatthew G. Knepley       const PetscInt *support, *cone;
158475d3a19aSMatthew G. Knepley       PetscInt        size, s;
158575d3a19aSMatthew G. Knepley 
158675d3a19aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, v, &size);CHKERRQ(ierr);
158775d3a19aSMatthew G. Knepley       ierr = DMPlexGetSupport(dm, v, &support);CHKERRQ(ierr);
158875d3a19aSMatthew G. Knepley       for (s = 0; s < size; ++s) {
158975d3a19aSMatthew G. Knepley         PetscInt r = 0;
159075d3a19aSMatthew G. Knepley 
159175d3a19aSMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
159275d3a19aSMatthew G. Knepley         if (cone[1] == v) r = 1;
159375d3a19aSMatthew G. Knepley         supportRef[s] = fStartNew + (support[s] - fStart)*2 + r;
159475d3a19aSMatthew G. Knepley       }
159575d3a19aSMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
159675d3a19aSMatthew G. Knepley #if 1
159775d3a19aSMatthew G. Knepley       if ((newp < vStartNew) || (newp >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", newp, vStartNew, vEndNew);
159875d3a19aSMatthew G. Knepley       for (p = 0; p < size; ++p) {
159975d3a19aSMatthew G. Knepley         if ((supportRef[p] < fStartNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", supportRef[p], fStartNew, fEndNew);
160075d3a19aSMatthew G. Knepley       }
160175d3a19aSMatthew G. Knepley #endif
160275d3a19aSMatthew G. Knepley     }
160375d3a19aSMatthew G. Knepley     /* Face vertices have 2 + cells supports */
160475d3a19aSMatthew G. Knepley     for (f = fStart; f < fEnd; ++f) {
160575d3a19aSMatthew G. Knepley       const PetscInt  newp = vStartNew + (vEnd - vStart) + (f - fStart);
160675d3a19aSMatthew G. Knepley       const PetscInt *cone, *support;
160775d3a19aSMatthew G. Knepley       PetscInt        size, s;
160875d3a19aSMatthew G. Knepley 
160975d3a19aSMatthew G. Knepley       ierr          = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
161075d3a19aSMatthew G. Knepley       ierr          = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
161175d3a19aSMatthew G. Knepley       supportRef[0] = fStartNew + (f - fStart)*2 + 0;
161275d3a19aSMatthew G. Knepley       supportRef[1] = fStartNew + (f - fStart)*2 + 1;
161375d3a19aSMatthew G. Knepley       for (s = 0; s < size; ++s) {
161475d3a19aSMatthew G. Knepley         PetscInt r = 0;
161575d3a19aSMatthew G. Knepley 
161675d3a19aSMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
161775d3a19aSMatthew G. Knepley         if      (cone[1] == f) r = 1;
161875d3a19aSMatthew G. Knepley         else if (cone[2] == f) r = 2;
161975d3a19aSMatthew G. Knepley         else if (cone[3] == f) r = 3;
162075d3a19aSMatthew G. Knepley         supportRef[2+s] = fStartNew + (fEnd - fStart)*2 + (support[s] - cStart)*4 + r;
162175d3a19aSMatthew G. Knepley       }
162275d3a19aSMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
162375d3a19aSMatthew G. Knepley #if 1
162475d3a19aSMatthew G. Knepley       if ((newp < vStartNew) || (newp >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", newp, vStartNew, vEndNew);
162575d3a19aSMatthew G. Knepley       for (p = 0; p < 2+size; ++p) {
162675d3a19aSMatthew G. Knepley         if ((supportRef[p] < fStartNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", supportRef[p], fStartNew, fEndNew);
162775d3a19aSMatthew G. Knepley       }
162875d3a19aSMatthew G. Knepley #endif
162975d3a19aSMatthew G. Knepley     }
163075d3a19aSMatthew G. Knepley     /* Cell vertices have 4 supports */
163175d3a19aSMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
163275d3a19aSMatthew G. Knepley       const PetscInt newp = vStartNew + (vEnd - vStart) + (fEnd - fStart) + (c - cStart);
163375d3a19aSMatthew G. Knepley       PetscInt       supportNew[4];
163475d3a19aSMatthew G. Knepley 
163575d3a19aSMatthew G. Knepley       for (r = 0; r < 4; ++r) {
163675d3a19aSMatthew G. Knepley         supportNew[r] = fStartNew + (fEnd - fStart)*2 + (c - cStart)*4 + r;
163775d3a19aSMatthew G. Knepley       }
163875d3a19aSMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
163975d3a19aSMatthew G. Knepley     }
1640da00770fSMatthew G. Knepley     ierr = PetscFree(supportRef);CHKERRQ(ierr);
164175d3a19aSMatthew G. Knepley     break;
16429b1a0e7fSLawrence Mitchell   case REFINER_HYBRID_SIMPLEX_2D:
164375d3a19aSMatthew G. Knepley     if (cMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No cell maximum specified in hybrid mesh");
164475d3a19aSMatthew G. Knepley     cMax = PetscMin(cEnd, cMax);
164575d3a19aSMatthew G. Knepley     if (fMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No face maximum specified in hybrid mesh");
164675d3a19aSMatthew G. Knepley     fMax = PetscMin(fEnd, fMax);
1647149f48fdSMatthew G. Knepley     ierr = DMPlexGetHybridBounds(rdm, &cMaxNew, &fMaxNew, NULL, NULL);CHKERRQ(ierr);
164875d3a19aSMatthew G. Knepley     /* Interior cells have 3 faces */
164975d3a19aSMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
165075d3a19aSMatthew G. Knepley       const PetscInt  newp = cStartNew + (c - cStart)*4;
165175d3a19aSMatthew G. Knepley       const PetscInt *cone, *ornt;
165275d3a19aSMatthew G. Knepley       PetscInt        coneNew[3], orntNew[3];
165375d3a19aSMatthew G. Knepley 
165475d3a19aSMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
165575d3a19aSMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr);
165675d3a19aSMatthew G. Knepley       /* A triangle */
165775d3a19aSMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*2 + (ornt[0] < 0 ? 1 : 0);
165875d3a19aSMatthew G. Knepley       orntNew[0] = ornt[0];
165975d3a19aSMatthew G. Knepley       coneNew[1] = fStartNew + (fMax    - fStart)*2 + (c - cStart)*3 + 2;
166075d3a19aSMatthew G. Knepley       orntNew[1] = -2;
166175d3a19aSMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*2 + (ornt[2] < 0 ? 0 : 1);
166275d3a19aSMatthew G. Knepley       orntNew[2] = ornt[2];
166375d3a19aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+0, coneNew);CHKERRQ(ierr);
166475d3a19aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+0, orntNew);CHKERRQ(ierr);
166575d3a19aSMatthew G. Knepley #if 1
1666149f48fdSMatthew G. Knepley       if ((newp+0 < cStartNew) || (newp+0 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior cell [%d, %d)", newp+0, cStartNew, cMaxNew);
166775d3a19aSMatthew G. Knepley       for (p = 0; p < 3; ++p) {
1668149f48fdSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
166975d3a19aSMatthew G. Knepley       }
167075d3a19aSMatthew G. Knepley #endif
167175d3a19aSMatthew G. Knepley       /* B triangle */
167275d3a19aSMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*2 + (ornt[0] < 0 ? 0 : 1);
167375d3a19aSMatthew G. Knepley       orntNew[0] = ornt[0];
167475d3a19aSMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*2 + (ornt[1] < 0 ? 1 : 0);
167575d3a19aSMatthew G. Knepley       orntNew[1] = ornt[1];
167675d3a19aSMatthew G. Knepley       coneNew[2] = fStartNew + (fMax    - fStart)*2 + (c - cStart)*3 + 0;
167775d3a19aSMatthew G. Knepley       orntNew[2] = -2;
167875d3a19aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+1, coneNew);CHKERRQ(ierr);
167975d3a19aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+1, orntNew);CHKERRQ(ierr);
168075d3a19aSMatthew G. Knepley #if 1
1681a97b51b8SMatthew G. Knepley       if ((newp+1 < cStartNew) || (newp+1 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior cell [%d, %d)", newp+1, cStartNew, cMaxNew);
168275d3a19aSMatthew G. Knepley       for (p = 0; p < 3; ++p) {
1683a97b51b8SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
168475d3a19aSMatthew G. Knepley       }
168575d3a19aSMatthew G. Knepley #endif
168675d3a19aSMatthew G. Knepley       /* C triangle */
168775d3a19aSMatthew G. Knepley       coneNew[0] = fStartNew + (fMax    - fStart)*2 + (c - cStart)*3 + 1;
168875d3a19aSMatthew G. Knepley       orntNew[0] = -2;
168975d3a19aSMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*2 + (ornt[1] < 0 ? 0 : 1);
169075d3a19aSMatthew G. Knepley       orntNew[1] = ornt[1];
169175d3a19aSMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*2 + (ornt[2] < 0 ? 1 : 0);
169275d3a19aSMatthew G. Knepley       orntNew[2] = ornt[2];
169375d3a19aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+2, coneNew);CHKERRQ(ierr);
169475d3a19aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+2, orntNew);CHKERRQ(ierr);
169575d3a19aSMatthew G. Knepley #if 1
1696a97b51b8SMatthew G. Knepley       if ((newp+2 < cStartNew) || (newp+2 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior cell [%d, %d)", newp+2, cStartNew, cMaxNew);
169775d3a19aSMatthew G. Knepley       for (p = 0; p < 3; ++p) {
1698a97b51b8SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
169975d3a19aSMatthew G. Knepley       }
170075d3a19aSMatthew G. Knepley #endif
170175d3a19aSMatthew G. Knepley       /* D triangle */
170275d3a19aSMatthew G. Knepley       coneNew[0] = fStartNew + (fMax    - fStart)*2 + (c - cStart)*3 + 0;
170375d3a19aSMatthew G. Knepley       orntNew[0] = 0;
170475d3a19aSMatthew G. Knepley       coneNew[1] = fStartNew + (fMax    - fStart)*2 + (c - cStart)*3 + 1;
170575d3a19aSMatthew G. Knepley       orntNew[1] = 0;
170675d3a19aSMatthew G. Knepley       coneNew[2] = fStartNew + (fMax    - fStart)*2 + (c - cStart)*3 + 2;
170775d3a19aSMatthew G. Knepley       orntNew[2] = 0;
170875d3a19aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+3, coneNew);CHKERRQ(ierr);
170975d3a19aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+3, orntNew);CHKERRQ(ierr);
171075d3a19aSMatthew G. Knepley #if 1
1711a97b51b8SMatthew G. Knepley       if ((newp+3 < cStartNew) || (newp+3 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior cell [%d, %d)", newp+3, cStartNew, cMaxNew);
171275d3a19aSMatthew G. Knepley       for (p = 0; p < 3; ++p) {
1713a97b51b8SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
171475d3a19aSMatthew G. Knepley       }
171575d3a19aSMatthew G. Knepley #endif
171675d3a19aSMatthew G. Knepley     }
171775d3a19aSMatthew G. Knepley     /*
171875d3a19aSMatthew G. Knepley      2----3----3
171975d3a19aSMatthew G. Knepley      |         |
172075d3a19aSMatthew G. Knepley      |    B    |
172175d3a19aSMatthew G. Knepley      |         |
172275d3a19aSMatthew G. Knepley      0----4--- 1
172375d3a19aSMatthew G. Knepley      |         |
172475d3a19aSMatthew G. Knepley      |    A    |
172575d3a19aSMatthew G. Knepley      |         |
172675d3a19aSMatthew G. Knepley      0----2----1
172775d3a19aSMatthew G. Knepley      */
172875d3a19aSMatthew G. Knepley     /* Hybrid cells have 4 faces */
172975d3a19aSMatthew G. Knepley     for (c = cMax; c < cEnd; ++c) {
173075d3a19aSMatthew G. Knepley       const PetscInt  newp = cStartNew + (cMax - cStart)*4 + (c - cMax)*2;
173175d3a19aSMatthew G. Knepley       const PetscInt *cone, *ornt;
1732ea00e70eSMatthew G. Knepley       PetscInt        coneNew[4], orntNew[4], r;
173375d3a19aSMatthew G. Knepley 
173475d3a19aSMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
173575d3a19aSMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr);
1736ea00e70eSMatthew G. Knepley       r    = (ornt[0] < 0 ? 1 : 0);
173775d3a19aSMatthew G. Knepley       /* A quad */
1738ea00e70eSMatthew G. Knepley       coneNew[0]   = fStartNew + (cone[0] - fStart)*2 + r;
173975d3a19aSMatthew G. Knepley       orntNew[0]   = ornt[0];
1740ea00e70eSMatthew G. Knepley       coneNew[1]   = fStartNew + (cone[1] - fStart)*2 + r;
174175d3a19aSMatthew G. Knepley       orntNew[1]   = ornt[1];
1742ea00e70eSMatthew G. Knepley       coneNew[2+r] = fStartNew + (fMax    - fStart)*2 + (cMax - cStart)*3 + (cone[2+r] - fMax);
1743ea00e70eSMatthew G. Knepley       orntNew[2+r] = 0;
1744ea00e70eSMatthew G. Knepley       coneNew[3-r] = fStartNew + (fMax    - fStart)*2 + (cMax - cStart)*3 + (fEnd    - fMax) + (c - cMax);
1745ea00e70eSMatthew G. Knepley       orntNew[3-r] = 0;
174675d3a19aSMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp+0, coneNew);CHKERRQ(ierr);
174775d3a19aSMatthew G. Knepley       ierr = DMPlexSetConeOrientation(rdm, newp+0, orntNew);CHKERRQ(ierr);
174875d3a19aSMatthew G. Knepley #if 1
174975d3a19aSMatthew G. Knepley       if ((newp+0 < cStartNew) || (newp+0 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+0, cStartNew, cEndNew);
175075d3a19aSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
175175d3a19aSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
175275d3a19aSMatthew G. Knepley       }
175375d3a19aSMatthew G. Knepley #endif
175475d3a19aSMatthew G. Knepley       /* B quad */
1755ea00e70eSMatthew G. Knepley       coneNew[0]   = fStartNew + (cone[0] - fStart)*2 + 1-r;
175675d3a19aSMatthew G. Knepley       orntNew[0]   = ornt[0];
1757ea00e70eSMatthew G. Knepley       coneNew[1]   = fStartNew + (cone[1] - fStart)*2 + 1-r;
175875d3a19aSMatthew G. Knepley       orntNew[1]   = ornt[1];
1759ea00e70eSMatthew G. Knepley       coneNew[2+r] = fStartNew + (fMax    - fStart)*2 + (cMax - cStart)*3 + (fEnd    - fMax) + (c - cMax);
1760ea00e70eSMatthew G. Knepley       orntNew[2+r] = 0;
1761ea00e70eSMatthew G. Knepley       coneNew[3-r] = fStartNew + (fMax    - fStart)*2 + (cMax - cStart)*3 + (cone[3-r] - fMax);
1762ea00e70eSMatthew G. Knepley       orntNew[3-r] = 0;
176375d3a19aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+1, coneNew);CHKERRQ(ierr);
176475d3a19aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+1, orntNew);CHKERRQ(ierr);
176575d3a19aSMatthew G. Knepley #if 1
176675d3a19aSMatthew G. Knepley       if ((newp+1 < cStartNew) || (newp+1 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+1, cStartNew, cEndNew);
176775d3a19aSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
176875d3a19aSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
176975d3a19aSMatthew G. Knepley       }
177075d3a19aSMatthew G. Knepley #endif
177175d3a19aSMatthew G. Knepley     }
177275d3a19aSMatthew G. Knepley     /* Interior split faces have 2 vertices and the same cells as the parent */
177375d3a19aSMatthew G. Knepley     ierr = DMPlexGetMaxSizes(dm, NULL, &maxSupportSize);CHKERRQ(ierr);
1774854ce69bSBarry Smith     ierr = PetscMalloc1(2 + maxSupportSize*2, &supportRef);CHKERRQ(ierr);
177575d3a19aSMatthew G. Knepley     for (f = fStart; f < fMax; ++f) {
177675d3a19aSMatthew G. Knepley       const PetscInt newv = vStartNew + (vEnd - vStart) + (f - fStart);
177775d3a19aSMatthew G. Knepley 
177875d3a19aSMatthew G. Knepley       for (r = 0; r < 2; ++r) {
177975d3a19aSMatthew G. Knepley         const PetscInt  newp = fStartNew + (f - fStart)*2 + r;
1780297d2bf4SMatthew G. Knepley         const PetscInt *cone, *ornt, *support;
178175d3a19aSMatthew G. Knepley         PetscInt        coneNew[2], coneSize, c, supportSize, s;
178275d3a19aSMatthew G. Knepley 
178375d3a19aSMatthew G. Knepley         ierr             = DMPlexGetCone(dm, f, &cone);CHKERRQ(ierr);
178475d3a19aSMatthew G. Knepley         coneNew[0]       = vStartNew + (cone[0] - vStart);
178575d3a19aSMatthew G. Knepley         coneNew[1]       = vStartNew + (cone[1] - vStart);
178675d3a19aSMatthew G. Knepley         coneNew[(r+1)%2] = newv;
178775d3a19aSMatthew G. Knepley         ierr             = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
178875d3a19aSMatthew G. Knepley #if 1
178975d3a19aSMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
179075d3a19aSMatthew G. Knepley         for (p = 0; p < 2; ++p) {
179175d3a19aSMatthew G. Knepley           if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
179275d3a19aSMatthew G. Knepley         }
179375d3a19aSMatthew G. Knepley #endif
179475d3a19aSMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &supportSize);CHKERRQ(ierr);
179575d3a19aSMatthew G. Knepley         ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
179675d3a19aSMatthew G. Knepley         for (s = 0; s < supportSize; ++s) {
179775d3a19aSMatthew G. Knepley           ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr);
179875d3a19aSMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
1799297d2bf4SMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, support[s], &ornt);CHKERRQ(ierr);
1800ea00e70eSMatthew G. Knepley           for (c = 0; c < coneSize; ++c) if (cone[c] == f) break;
1801ea00e70eSMatthew G. Knepley           if (support[s] >= cMax) {
1802ea00e70eSMatthew G. Knepley             supportRef[s] = cStartNew + (cMax - cStart)*4 + (support[s] - cMax)*2 + (ornt[c] < 0 ? 1-r : r);
1803ea00e70eSMatthew G. Knepley           } else {
1804297d2bf4SMatthew G. Knepley             supportRef[s] = cStartNew + (support[s] - cStart)*4 + (ornt[c] < 0 ? (c+1-r)%3 : (c+r)%3);
180575d3a19aSMatthew G. Knepley           }
180675d3a19aSMatthew G. Knepley         }
180775d3a19aSMatthew G. Knepley         ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
180875d3a19aSMatthew G. Knepley #if 1
180975d3a19aSMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
181075d3a19aSMatthew G. Knepley         for (p = 0; p < supportSize; ++p) {
181175d3a19aSMatthew G. Knepley           if ((supportRef[p] < cStartNew) || (supportRef[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportRef[p], cStartNew, cEndNew);
181275d3a19aSMatthew G. Knepley         }
181375d3a19aSMatthew G. Knepley #endif
181475d3a19aSMatthew G. Knepley       }
181575d3a19aSMatthew G. Knepley     }
181675d3a19aSMatthew G. Knepley     /* Interior cell faces have 2 vertices and 2 cells */
181775d3a19aSMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
181875d3a19aSMatthew G. Knepley       const PetscInt *cone;
181975d3a19aSMatthew G. Knepley 
182075d3a19aSMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
182175d3a19aSMatthew G. Knepley       for (r = 0; r < 3; ++r) {
182275d3a19aSMatthew G. Knepley         const PetscInt newp = fStartNew + (fMax - fStart)*2 + (c - cStart)*3 + r;
182375d3a19aSMatthew G. Knepley         PetscInt       coneNew[2];
182475d3a19aSMatthew G. Knepley         PetscInt       supportNew[2];
182575d3a19aSMatthew G. Knepley 
182675d3a19aSMatthew G. Knepley         coneNew[0] = vStartNew + (vEnd - vStart) + (cone[r]       - fStart);
182775d3a19aSMatthew G. Knepley         coneNew[1] = vStartNew + (vEnd - vStart) + (cone[(r+1)%3] - fStart);
182875d3a19aSMatthew G. Knepley         ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
182975d3a19aSMatthew G. Knepley #if 1
183075d3a19aSMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
183175d3a19aSMatthew G. Knepley         for (p = 0; p < 2; ++p) {
183275d3a19aSMatthew G. Knepley           if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
183375d3a19aSMatthew G. Knepley         }
183475d3a19aSMatthew G. Knepley #endif
183575d3a19aSMatthew G. Knepley         supportNew[0] = (c - cStart)*4 + (r+1)%3;
183675d3a19aSMatthew G. Knepley         supportNew[1] = (c - cStart)*4 + 3;
183775d3a19aSMatthew G. Knepley         ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
183875d3a19aSMatthew G. Knepley #if 1
183975d3a19aSMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
184075d3a19aSMatthew G. Knepley         for (p = 0; p < 2; ++p) {
184175d3a19aSMatthew G. Knepley           if ((supportNew[p] < cStartNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cEndNew);
184275d3a19aSMatthew G. Knepley         }
184375d3a19aSMatthew G. Knepley #endif
184475d3a19aSMatthew G. Knepley       }
184575d3a19aSMatthew G. Knepley     }
184675d3a19aSMatthew G. Knepley     /* Interior hybrid faces have 2 vertices and the same cells */
184775d3a19aSMatthew G. Knepley     for (f = fMax; f < fEnd; ++f) {
184875d3a19aSMatthew G. Knepley       const PetscInt  newp = fStartNew + (fMax - fStart)*2 + (cMax - cStart)*3 + (f - fMax);
1849ea00e70eSMatthew G. Knepley       const PetscInt *cone, *ornt;
185075d3a19aSMatthew G. Knepley       const PetscInt *support;
185175d3a19aSMatthew G. Knepley       PetscInt        coneNew[2];
185275d3a19aSMatthew G. Knepley       PetscInt        supportNew[2];
185375d3a19aSMatthew G. Knepley       PetscInt        size, s, r;
185475d3a19aSMatthew G. Knepley 
185575d3a19aSMatthew G. Knepley       ierr       = DMPlexGetCone(dm, f, &cone);CHKERRQ(ierr);
185675d3a19aSMatthew G. Knepley       coneNew[0] = vStartNew + (cone[0] - vStart);
185775d3a19aSMatthew G. Knepley       coneNew[1] = vStartNew + (cone[1] - vStart);
185875d3a19aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
185975d3a19aSMatthew G. Knepley #if 1
186075d3a19aSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
186175d3a19aSMatthew G. Knepley       for (p = 0; p < 2; ++p) {
186275d3a19aSMatthew G. Knepley         if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
186375d3a19aSMatthew G. Knepley       }
186475d3a19aSMatthew G. Knepley #endif
186575d3a19aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
186675d3a19aSMatthew G. Knepley       ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
186775d3a19aSMatthew G. Knepley       for (s = 0; s < size; ++s) {
186875d3a19aSMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
1869ea00e70eSMatthew G. Knepley         ierr = DMPlexGetConeOrientation(dm, support[s], &ornt);CHKERRQ(ierr);
187075d3a19aSMatthew G. Knepley         for (r = 0; r < 2; ++r) {
187175d3a19aSMatthew G. Knepley           if (cone[r+2] == f) break;
187275d3a19aSMatthew G. Knepley         }
1873ea00e70eSMatthew G. Knepley         supportNew[s] = (cMax - cStart)*4 + (support[s] - cMax)*2 + (ornt[0] < 0 ? 1-r : r);
187475d3a19aSMatthew G. Knepley       }
187575d3a19aSMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
187675d3a19aSMatthew G. Knepley #if 1
187775d3a19aSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
187875d3a19aSMatthew G. Knepley       for (p = 0; p < size; ++p) {
187975d3a19aSMatthew G. Knepley         if ((supportNew[p] < cStartNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cEndNew);
188075d3a19aSMatthew G. Knepley       }
188175d3a19aSMatthew G. Knepley #endif
188275d3a19aSMatthew G. Knepley     }
188375d3a19aSMatthew G. Knepley     /* Cell hybrid faces have 2 vertices and 2 cells */
188475d3a19aSMatthew G. Knepley     for (c = cMax; c < cEnd; ++c) {
188575d3a19aSMatthew G. Knepley       const PetscInt  newp = fStartNew + (fMax - fStart)*2 + (cMax - cStart)*3 + (fEnd - fMax) + (c - cMax);
188675d3a19aSMatthew G. Knepley       const PetscInt *cone;
188775d3a19aSMatthew G. Knepley       PetscInt        coneNew[2];
188875d3a19aSMatthew G. Knepley       PetscInt        supportNew[2];
188975d3a19aSMatthew G. Knepley 
189075d3a19aSMatthew G. Knepley       ierr       = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
189175d3a19aSMatthew G. Knepley       coneNew[0] = vStartNew + (vEnd - vStart) + (cone[0] - fStart);
189275d3a19aSMatthew G. Knepley       coneNew[1] = vStartNew + (vEnd - vStart) + (cone[1] - fStart);
189375d3a19aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
189475d3a19aSMatthew G. Knepley #if 1
189575d3a19aSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
189675d3a19aSMatthew G. Knepley       for (p = 0; p < 2; ++p) {
189775d3a19aSMatthew G. Knepley         if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
189875d3a19aSMatthew G. Knepley       }
189975d3a19aSMatthew G. Knepley #endif
190075d3a19aSMatthew G. Knepley       supportNew[0] = (cMax - cStart)*4 + (c - cMax)*2 + 0;
190175d3a19aSMatthew G. Knepley       supportNew[1] = (cMax - cStart)*4 + (c - cMax)*2 + 1;
190275d3a19aSMatthew G. Knepley       ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
190375d3a19aSMatthew G. Knepley #if 1
190475d3a19aSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
190575d3a19aSMatthew G. Knepley       for (p = 0; p < 2; ++p) {
190675d3a19aSMatthew G. Knepley         if ((supportNew[p] < cStartNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cEndNew);
190775d3a19aSMatthew G. Knepley       }
190875d3a19aSMatthew G. Knepley #endif
190975d3a19aSMatthew G. Knepley     }
191075d3a19aSMatthew G. Knepley     /* Old vertices have identical supports */
191175d3a19aSMatthew G. Knepley     for (v = vStart; v < vEnd; ++v) {
191275d3a19aSMatthew G. Knepley       const PetscInt  newp = vStartNew + (v - vStart);
191375d3a19aSMatthew G. Knepley       const PetscInt *support, *cone;
191475d3a19aSMatthew G. Knepley       PetscInt        size, s;
191575d3a19aSMatthew G. Knepley 
191675d3a19aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, v, &size);CHKERRQ(ierr);
191775d3a19aSMatthew G. Knepley       ierr = DMPlexGetSupport(dm, v, &support);CHKERRQ(ierr);
191875d3a19aSMatthew G. Knepley       for (s = 0; s < size; ++s) {
191975d3a19aSMatthew G. Knepley         if (support[s] >= fMax) {
192075d3a19aSMatthew G. Knepley           supportRef[s] = fStartNew + (fMax - fStart)*2 + (cMax - cStart)*3 + (support[s] - fMax);
192175d3a19aSMatthew G. Knepley         } else {
192275d3a19aSMatthew G. Knepley           PetscInt r = 0;
192375d3a19aSMatthew G. Knepley 
192475d3a19aSMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
192575d3a19aSMatthew G. Knepley           if (cone[1] == v) r = 1;
192675d3a19aSMatthew G. Knepley           supportRef[s] = fStartNew + (support[s] - fStart)*2 + r;
192775d3a19aSMatthew G. Knepley         }
192875d3a19aSMatthew G. Knepley       }
192975d3a19aSMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
193075d3a19aSMatthew G. Knepley #if 1
193175d3a19aSMatthew G. Knepley       if ((newp < vStartNew) || (newp >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", newp, vStartNew, vEndNew);
193275d3a19aSMatthew G. Knepley       for (p = 0; p < size; ++p) {
193375d3a19aSMatthew G. Knepley         if ((supportRef[p] < fStartNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", supportRef[p], fStartNew, fEndNew);
193475d3a19aSMatthew G. Knepley       }
193575d3a19aSMatthew G. Knepley #endif
193675d3a19aSMatthew G. Knepley     }
193775d3a19aSMatthew G. Knepley     /* Face vertices have 2 + (2 interior, 1 hybrid) supports */
193875d3a19aSMatthew G. Knepley     for (f = fStart; f < fMax; ++f) {
193975d3a19aSMatthew G. Knepley       const PetscInt  newp = vStartNew + (vEnd - vStart) + (f - fStart);
194075d3a19aSMatthew G. Knepley       const PetscInt *cone, *support;
194175d3a19aSMatthew G. Knepley       PetscInt        size, newSize = 2, s;
194275d3a19aSMatthew G. Knepley 
194375d3a19aSMatthew G. Knepley       ierr          = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
194475d3a19aSMatthew G. Knepley       ierr          = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
194575d3a19aSMatthew G. Knepley       supportRef[0] = fStartNew + (f - fStart)*2 + 0;
194675d3a19aSMatthew G. Knepley       supportRef[1] = fStartNew + (f - fStart)*2 + 1;
194775d3a19aSMatthew G. Knepley       for (s = 0; s < size; ++s) {
194875d3a19aSMatthew G. Knepley         PetscInt r = 0;
194975d3a19aSMatthew G. Knepley 
195075d3a19aSMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
195175d3a19aSMatthew G. Knepley         if (support[s] >= cMax) {
195275d3a19aSMatthew G. Knepley           supportRef[newSize+0] = fStartNew + (fMax - fStart)*2 + (cMax - cStart)*3 + (fEnd - fMax) + (support[s] - cMax);
195375d3a19aSMatthew G. Knepley 
195475d3a19aSMatthew G. Knepley           newSize += 1;
195575d3a19aSMatthew G. Knepley         } else {
195675d3a19aSMatthew G. Knepley           if      (cone[1] == f) r = 1;
195775d3a19aSMatthew G. Knepley           else if (cone[2] == f) r = 2;
195875d3a19aSMatthew G. Knepley           supportRef[newSize+0] = fStartNew + (fMax - fStart)*2 + (support[s] - cStart)*3 + (r+2)%3;
195975d3a19aSMatthew G. Knepley           supportRef[newSize+1] = fStartNew + (fMax - fStart)*2 + (support[s] - cStart)*3 + r;
196075d3a19aSMatthew G. Knepley 
196175d3a19aSMatthew G. Knepley           newSize += 2;
196275d3a19aSMatthew G. Knepley         }
196375d3a19aSMatthew G. Knepley       }
196475d3a19aSMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
196575d3a19aSMatthew G. Knepley #if 1
196675d3a19aSMatthew G. Knepley       if ((newp < vStartNew) || (newp >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", newp, vStartNew, vEndNew);
196775d3a19aSMatthew G. Knepley       for (p = 0; p < newSize; ++p) {
196875d3a19aSMatthew G. Knepley         if ((supportRef[p] < fStartNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", supportRef[p], fStartNew, fEndNew);
196975d3a19aSMatthew G. Knepley       }
197075d3a19aSMatthew G. Knepley #endif
197175d3a19aSMatthew G. Knepley     }
197275d3a19aSMatthew G. Knepley     ierr = PetscFree(supportRef);CHKERRQ(ierr);
197375d3a19aSMatthew G. Knepley     break;
19749b1a0e7fSLawrence Mitchell   case REFINER_HYBRID_HEX_2D:
1975a97b51b8SMatthew G. Knepley     /* Hybrid Hex 2D */
1976a97b51b8SMatthew G. Knepley     if (cMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No cell maximum specified in hybrid mesh");
1977a97b51b8SMatthew G. Knepley     cMax = PetscMin(cEnd, cMax);
1978a97b51b8SMatthew G. Knepley     if (fMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No face maximum specified in hybrid mesh");
1979a97b51b8SMatthew G. Knepley     fMax = PetscMin(fEnd, fMax);
1980a97b51b8SMatthew G. Knepley     ierr = DMPlexGetHybridBounds(rdm, &cMaxNew, &fMaxNew, NULL, NULL);CHKERRQ(ierr);
1981a97b51b8SMatthew G. Knepley     /* Interior cells have 4 faces */
1982a97b51b8SMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
1983a97b51b8SMatthew G. Knepley       const PetscInt  newp = cStartNew + (c - cStart)*4;
1984a97b51b8SMatthew G. Knepley       const PetscInt *cone, *ornt;
1985a97b51b8SMatthew G. Knepley       PetscInt        coneNew[4], orntNew[4];
1986a97b51b8SMatthew G. Knepley 
1987a97b51b8SMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
1988a97b51b8SMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr);
1989a97b51b8SMatthew G. Knepley       /* A quad */
1990a97b51b8SMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*2 + (ornt[0] < 0 ? 1 : 0);
1991a97b51b8SMatthew G. Knepley       orntNew[0] = ornt[0];
1992a97b51b8SMatthew G. Knepley       coneNew[1] = fStartNew + (fMax    - fStart)*2 + (c - cStart)*4 + 0;
1993a97b51b8SMatthew G. Knepley       orntNew[1] = 0;
1994a97b51b8SMatthew G. Knepley       coneNew[2] = fStartNew + (fMax    - fStart)*2 + (c - cStart)*4 + 3;
1995a97b51b8SMatthew G. Knepley       orntNew[2] = -2;
1996a97b51b8SMatthew G. Knepley       coneNew[3] = fStartNew + (cone[3] - fStart)*2 + (ornt[3] < 0 ? 0 : 1);
1997a97b51b8SMatthew G. Knepley       orntNew[3] = ornt[3];
1998a97b51b8SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+0, coneNew);CHKERRQ(ierr);
1999a97b51b8SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+0, orntNew);CHKERRQ(ierr);
2000a97b51b8SMatthew G. Knepley #if 1
2001a97b51b8SMatthew G. Knepley       if ((newp+0 < cStartNew) || (newp+0 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior cell [%d, %d)", newp+0, cStartNew, cMaxNew);
2002a97b51b8SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
2003a97b51b8SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
2004a97b51b8SMatthew G. Knepley       }
2005a97b51b8SMatthew G. Knepley #endif
2006a97b51b8SMatthew G. Knepley       /* B quad */
2007a97b51b8SMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*2 + (ornt[0] < 0 ? 0 : 1);
2008a97b51b8SMatthew G. Knepley       orntNew[0] = ornt[0];
2009a97b51b8SMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*2 + (ornt[1] < 0 ? 1 : 0);
2010a97b51b8SMatthew G. Knepley       orntNew[1] = ornt[1];
2011a97b51b8SMatthew G. Knepley       coneNew[2] = fStartNew + (fMax    - fStart)*2 + (c - cStart)*4 + 1;
2012a97b51b8SMatthew G. Knepley       orntNew[2] = 0;
2013a97b51b8SMatthew G. Knepley       coneNew[3] = fStartNew + (fMax    - fStart)*2 + (c - cStart)*4 + 0;
2014a97b51b8SMatthew G. Knepley       orntNew[3] = -2;
2015a97b51b8SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+1, coneNew);CHKERRQ(ierr);
2016a97b51b8SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+1, orntNew);CHKERRQ(ierr);
2017a97b51b8SMatthew G. Knepley #if 1
2018a97b51b8SMatthew G. Knepley       if ((newp+1 < cStartNew) || (newp+1 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior cell [%d, %d)", newp+1, cStartNew, cMaxNew);
2019a97b51b8SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
2020a97b51b8SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
2021a97b51b8SMatthew G. Knepley       }
2022a97b51b8SMatthew G. Knepley #endif
2023a97b51b8SMatthew G. Knepley       /* C quad */
2024a97b51b8SMatthew G. Knepley       coneNew[0] = fStartNew + (fMax    - fStart)*2 + (c - cStart)*4 + 1;
2025a97b51b8SMatthew G. Knepley       orntNew[0] = -2;
2026a97b51b8SMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*2 + (ornt[1] < 0 ? 0 : 1);
2027a97b51b8SMatthew G. Knepley       orntNew[1] = ornt[1];
2028a97b51b8SMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*2 + (ornt[2] < 0 ? 1 : 0);
2029a97b51b8SMatthew G. Knepley       orntNew[2] = ornt[2];
2030a97b51b8SMatthew G. Knepley       coneNew[3] = fStartNew + (fMax    - fStart)*2 + (c - cStart)*4 + 2;
2031a97b51b8SMatthew G. Knepley       orntNew[3] = 0;
2032a97b51b8SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+2, coneNew);CHKERRQ(ierr);
2033a97b51b8SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+2, orntNew);CHKERRQ(ierr);
2034a97b51b8SMatthew G. Knepley #if 1
2035a97b51b8SMatthew G. Knepley       if ((newp+2 < cStartNew) || (newp+2 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior cell [%d, %d)", newp+2, cStartNew, cMaxNew);
2036a97b51b8SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
2037a97b51b8SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
2038a97b51b8SMatthew G. Knepley       }
2039a97b51b8SMatthew G. Knepley #endif
2040a97b51b8SMatthew G. Knepley       /* D quad */
2041a97b51b8SMatthew G. Knepley       coneNew[0] = fStartNew + (fMax    - fStart)*2 + (c - cStart)*4 + 3;
2042a97b51b8SMatthew G. Knepley       orntNew[0] = 0;
2043a97b51b8SMatthew G. Knepley       coneNew[1] = fStartNew + (fMax    - fStart)*2 + (c - cStart)*4 + 2;
2044a97b51b8SMatthew G. Knepley       orntNew[1] = -2;
2045a97b51b8SMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*2 + (ornt[2] < 0 ? 0 : 1);
2046a97b51b8SMatthew G. Knepley       orntNew[2] = ornt[2];
2047a97b51b8SMatthew G. Knepley       coneNew[3] = fStartNew + (cone[3] - fStart)*2 + (ornt[3] < 0 ? 1 : 0);
2048a97b51b8SMatthew G. Knepley       orntNew[3] = ornt[3];
2049a97b51b8SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+3, coneNew);CHKERRQ(ierr);
2050a97b51b8SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+3, orntNew);CHKERRQ(ierr);
2051a97b51b8SMatthew G. Knepley #if 1
2052a97b51b8SMatthew G. Knepley       if ((newp+3 < cStartNew) || (newp+3 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior cell [%d, %d)", newp+3, cStartNew, cMaxNew);
2053a97b51b8SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
2054a97b51b8SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
2055a97b51b8SMatthew G. Knepley       }
2056a97b51b8SMatthew G. Knepley #endif
2057a97b51b8SMatthew G. Knepley     }
2058a97b51b8SMatthew G. Knepley     /*
2059a97b51b8SMatthew G. Knepley      2----3----3
2060a97b51b8SMatthew G. Knepley      |         |
2061a97b51b8SMatthew G. Knepley      |    B    |
2062a97b51b8SMatthew G. Knepley      |         |
2063a97b51b8SMatthew G. Knepley      0----4--- 1
2064a97b51b8SMatthew G. Knepley      |         |
2065a97b51b8SMatthew G. Knepley      |    A    |
2066a97b51b8SMatthew G. Knepley      |         |
2067a97b51b8SMatthew G. Knepley      0----2----1
2068a97b51b8SMatthew G. Knepley      */
2069a97b51b8SMatthew G. Knepley     /* Hybrid cells have 4 faces */
2070a97b51b8SMatthew G. Knepley     for (c = cMax; c < cEnd; ++c) {
2071a97b51b8SMatthew G. Knepley       const PetscInt  newp = cStartNew + (cMax - cStart)*4 + (c - cMax)*2;
2072a97b51b8SMatthew G. Knepley       const PetscInt *cone, *ornt;
2073a97b51b8SMatthew G. Knepley       PetscInt        coneNew[4], orntNew[4];
2074a97b51b8SMatthew G. Knepley 
2075a97b51b8SMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
2076a97b51b8SMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr);
2077a97b51b8SMatthew G. Knepley       /* A quad */
2078a97b51b8SMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*2 + (ornt[0] < 0 ? 1 : 0);
2079a97b51b8SMatthew G. Knepley       orntNew[0] = ornt[0];
2080a97b51b8SMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*2 + (ornt[1] < 0 ? 1 : 0);
2081a97b51b8SMatthew G. Knepley       orntNew[1] = ornt[1];
2082a97b51b8SMatthew G. Knepley       coneNew[2] = fStartNew + (fMax    - fStart)*2 + (cMax - cStart)*4 + (cone[2] - fMax);
2083a97b51b8SMatthew G. Knepley       orntNew[2] = 0;
2084a97b51b8SMatthew G. Knepley       coneNew[3] = fStartNew + (fMax    - fStart)*2 + (cMax - cStart)*4 + (fEnd    - fMax) + (c - cMax);
2085a97b51b8SMatthew G. Knepley       orntNew[3] = 0;
2086a97b51b8SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+0, coneNew);CHKERRQ(ierr);
2087a97b51b8SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+0, orntNew);CHKERRQ(ierr);
2088a97b51b8SMatthew G. Knepley #if 1
2089a97b51b8SMatthew G. Knepley       if ((newp+0 < cStartNew) || (newp+0 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+0, cStartNew, cEndNew);
2090a97b51b8SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
2091a97b51b8SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
2092a97b51b8SMatthew G. Knepley       }
2093a97b51b8SMatthew G. Knepley #endif
2094a97b51b8SMatthew G. Knepley       /* B quad */
2095a97b51b8SMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*2 + (ornt[0] < 0 ? 0 : 1);
2096a97b51b8SMatthew G. Knepley       orntNew[0] = ornt[0];
2097a97b51b8SMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*2 + (ornt[1] < 0 ? 0 : 1);
2098a97b51b8SMatthew G. Knepley       orntNew[1] = ornt[1];
2099a97b51b8SMatthew G. Knepley       coneNew[2] = fStartNew + (fMax    - fStart)*2 + (cMax - cStart)*4 + (fEnd    - fMax) + (c - cMax);
2100a97b51b8SMatthew G. Knepley       orntNew[2] = 0;
2101a97b51b8SMatthew G. Knepley       coneNew[3] = fStartNew + (fMax    - fStart)*2 + (cMax - cStart)*4 + (cone[3] - fMax);
2102a97b51b8SMatthew G. Knepley       orntNew[3] = 0;
2103a97b51b8SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+1, coneNew);CHKERRQ(ierr);
2104a97b51b8SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+1, orntNew);CHKERRQ(ierr);
2105a97b51b8SMatthew G. Knepley #if 1
2106a97b51b8SMatthew G. Knepley       if ((newp+1 < cStartNew) || (newp+1 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+1, cStartNew, cEndNew);
2107a97b51b8SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
2108a97b51b8SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
2109a97b51b8SMatthew G. Knepley       }
2110a97b51b8SMatthew G. Knepley #endif
2111a97b51b8SMatthew G. Knepley     }
2112a97b51b8SMatthew G. Knepley     /* Interior split faces have 2 vertices and the same cells as the parent */
2113a97b51b8SMatthew G. Knepley     ierr = DMPlexGetMaxSizes(dm, NULL, &maxSupportSize);CHKERRQ(ierr);
2114854ce69bSBarry Smith     ierr = PetscMalloc1(2 + maxSupportSize*2, &supportRef);CHKERRQ(ierr);
2115a97b51b8SMatthew G. Knepley     for (f = fStart; f < fMax; ++f) {
2116a97b51b8SMatthew G. Knepley       const PetscInt newv = vStartNew + (vEnd - vStart) + (f - fStart);
2117a97b51b8SMatthew G. Knepley 
2118a97b51b8SMatthew G. Knepley       for (r = 0; r < 2; ++r) {
2119a97b51b8SMatthew G. Knepley         const PetscInt  newp = fStartNew + (f - fStart)*2 + r;
2120a97b51b8SMatthew G. Knepley         const PetscInt *cone, *ornt, *support;
2121a97b51b8SMatthew G. Knepley         PetscInt        coneNew[2], coneSize, c, supportSize, s;
2122a97b51b8SMatthew G. Knepley 
2123a97b51b8SMatthew G. Knepley         ierr             = DMPlexGetCone(dm, f, &cone);CHKERRQ(ierr);
2124a97b51b8SMatthew G. Knepley         coneNew[0]       = vStartNew + (cone[0] - vStart);
2125a97b51b8SMatthew G. Knepley         coneNew[1]       = vStartNew + (cone[1] - vStart);
2126a97b51b8SMatthew G. Knepley         coneNew[(r+1)%2] = newv;
2127a97b51b8SMatthew G. Knepley         ierr             = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
2128a97b51b8SMatthew G. Knepley #if 1
2129a97b51b8SMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2130a97b51b8SMatthew G. Knepley         for (p = 0; p < 2; ++p) {
2131a97b51b8SMatthew G. Knepley           if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
2132a97b51b8SMatthew G. Knepley         }
2133a97b51b8SMatthew G. Knepley #endif
2134a97b51b8SMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &supportSize);CHKERRQ(ierr);
2135a97b51b8SMatthew G. Knepley         ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
2136a97b51b8SMatthew G. Knepley         for (s = 0; s < supportSize; ++s) {
2137a97b51b8SMatthew G. Knepley           if (support[s] >= cMax) {
2138a97b51b8SMatthew G. Knepley             supportRef[s] = cStartNew + (cMax - cStart)*4 + (support[s] - cMax)*2 + r;
2139a97b51b8SMatthew G. Knepley           } else {
2140a97b51b8SMatthew G. Knepley             ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr);
2141a97b51b8SMatthew G. Knepley             ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
2142a97b51b8SMatthew G. Knepley             ierr = DMPlexGetConeOrientation(dm, support[s], &ornt);CHKERRQ(ierr);
2143a97b51b8SMatthew G. Knepley             for (c = 0; c < coneSize; ++c) {
2144a97b51b8SMatthew G. Knepley               if (cone[c] == f) break;
2145a97b51b8SMatthew G. Knepley             }
2146a97b51b8SMatthew G. Knepley             supportRef[s] = cStartNew + (support[s] - cStart)*4 + (ornt[c] < 0 ? (c+1-r)%4 : (c+r)%4);
2147a97b51b8SMatthew G. Knepley           }
2148a97b51b8SMatthew G. Knepley         }
2149a97b51b8SMatthew G. Knepley         ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
2150a97b51b8SMatthew G. Knepley #if 1
2151a97b51b8SMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2152a97b51b8SMatthew G. Knepley         for (p = 0; p < supportSize; ++p) {
2153a97b51b8SMatthew G. Knepley           if ((supportRef[p] < cStartNew) || (supportRef[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportRef[p], cStartNew, cEndNew);
2154a97b51b8SMatthew G. Knepley         }
2155a97b51b8SMatthew G. Knepley #endif
2156a97b51b8SMatthew G. Knepley       }
2157a97b51b8SMatthew G. Knepley     }
2158a97b51b8SMatthew G. Knepley     /* Interior cell faces have 2 vertices and 2 cells */
2159a97b51b8SMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
2160a97b51b8SMatthew G. Knepley       const PetscInt *cone;
2161a97b51b8SMatthew G. Knepley 
2162a97b51b8SMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
2163a97b51b8SMatthew G. Knepley       for (r = 0; r < 4; ++r) {
2164a97b51b8SMatthew G. Knepley         const PetscInt newp = fStartNew + (fMax - fStart)*2 + (c - cStart)*4 + r;
2165a97b51b8SMatthew G. Knepley         PetscInt       coneNew[2], supportNew[2];
2166a97b51b8SMatthew G. Knepley 
2167a97b51b8SMatthew G. Knepley         coneNew[0] = vStartNew + (vEnd - vStart) + (cone[r] - fStart);
2168a97b51b8SMatthew G. Knepley         coneNew[1] = vStartNew + (vEnd - vStart) + (fMax    - fStart) + (c - cStart);
2169a97b51b8SMatthew G. Knepley         ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
2170a97b51b8SMatthew G. Knepley #if 1
2171a97b51b8SMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2172a97b51b8SMatthew G. Knepley         for (p = 0; p < 2; ++p) {
2173a97b51b8SMatthew G. Knepley           if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
2174a97b51b8SMatthew G. Knepley         }
2175a97b51b8SMatthew G. Knepley #endif
2176a97b51b8SMatthew G. Knepley         supportNew[0] = (c - cStart)*4 + r;
2177a97b51b8SMatthew G. Knepley         supportNew[1] = (c - cStart)*4 + (r+1)%4;
2178a97b51b8SMatthew G. Knepley         ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
2179a97b51b8SMatthew G. Knepley #if 1
2180a97b51b8SMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2181a97b51b8SMatthew G. Knepley         for (p = 0; p < 2; ++p) {
2182a97b51b8SMatthew G. Knepley           if ((supportNew[p] < cStartNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cEndNew);
2183a97b51b8SMatthew G. Knepley         }
2184a97b51b8SMatthew G. Knepley #endif
2185a97b51b8SMatthew G. Knepley       }
2186a97b51b8SMatthew G. Knepley     }
2187a97b51b8SMatthew G. Knepley     /* Hybrid faces have 2 vertices and the same cells */
2188a97b51b8SMatthew G. Knepley     for (f = fMax; f < fEnd; ++f) {
2189a97b51b8SMatthew G. Knepley       const PetscInt  newp = fStartNew + (fMax - fStart)*2 + (cMax - cStart)*4 + (f - fMax);
2190a97b51b8SMatthew G. Knepley       const PetscInt *cone, *support;
2191a97b51b8SMatthew G. Knepley       PetscInt        coneNew[2], supportNew[2];
2192a97b51b8SMatthew G. Knepley       PetscInt        size, s, r;
2193a97b51b8SMatthew G. Knepley 
2194a97b51b8SMatthew G. Knepley       ierr       = DMPlexGetCone(dm, f, &cone);CHKERRQ(ierr);
2195a97b51b8SMatthew G. Knepley       coneNew[0] = vStartNew + (cone[0] - vStart);
2196a97b51b8SMatthew G. Knepley       coneNew[1] = vStartNew + (cone[1] - vStart);
2197a97b51b8SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
2198a97b51b8SMatthew G. Knepley #if 1
2199a97b51b8SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2200a97b51b8SMatthew G. Knepley       for (p = 0; p < 2; ++p) {
2201a97b51b8SMatthew G. Knepley         if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
2202a97b51b8SMatthew G. Knepley       }
2203a97b51b8SMatthew G. Knepley #endif
2204a97b51b8SMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
2205a97b51b8SMatthew G. Knepley       ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
2206a97b51b8SMatthew G. Knepley       for (s = 0; s < size; ++s) {
2207a97b51b8SMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
2208a97b51b8SMatthew G. Knepley         for (r = 0; r < 2; ++r) {
2209a97b51b8SMatthew G. Knepley           if (cone[r+2] == f) break;
2210a97b51b8SMatthew G. Knepley         }
2211a97b51b8SMatthew G. Knepley         supportNew[s] = (cMax - cStart)*4 + (support[s] - cMax)*2 + r;
2212a97b51b8SMatthew G. Knepley       }
2213a97b51b8SMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
2214a97b51b8SMatthew G. Knepley #if 1
2215a97b51b8SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2216a97b51b8SMatthew G. Knepley       for (p = 0; p < size; ++p) {
2217a97b51b8SMatthew G. Knepley         if ((supportNew[p] < cStartNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cEndNew);
2218a97b51b8SMatthew G. Knepley       }
2219a97b51b8SMatthew G. Knepley #endif
2220a97b51b8SMatthew G. Knepley     }
2221a97b51b8SMatthew G. Knepley     /* Cell hybrid faces have 2 vertices and 2 cells */
2222a97b51b8SMatthew G. Knepley     for (c = cMax; c < cEnd; ++c) {
2223a97b51b8SMatthew G. Knepley       const PetscInt  newp = fStartNew + (fMax - fStart)*2 + (cMax - cStart)*4 + (fEnd - fMax) + (c - cMax);
2224a97b51b8SMatthew G. Knepley       const PetscInt *cone;
2225a97b51b8SMatthew G. Knepley       PetscInt        coneNew[2], supportNew[2];
2226a97b51b8SMatthew G. Knepley 
2227a97b51b8SMatthew G. Knepley       ierr       = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
2228a97b51b8SMatthew G. Knepley       coneNew[0] = vStartNew + (vEnd - vStart) + (cone[0] - fStart);
2229a97b51b8SMatthew G. Knepley       coneNew[1] = vStartNew + (vEnd - vStart) + (cone[1] - fStart);
2230a97b51b8SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
2231a97b51b8SMatthew G. Knepley #if 1
2232a97b51b8SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2233a97b51b8SMatthew G. Knepley       for (p = 0; p < 2; ++p) {
2234a97b51b8SMatthew G. Knepley         if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
2235a97b51b8SMatthew G. Knepley       }
2236a97b51b8SMatthew G. Knepley #endif
2237a97b51b8SMatthew G. Knepley       supportNew[0] = (cMax - cStart)*4 + (c - cMax)*2 + 0;
2238a97b51b8SMatthew G. Knepley       supportNew[1] = (cMax - cStart)*4 + (c - cMax)*2 + 1;
2239a97b51b8SMatthew G. Knepley       ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
2240a97b51b8SMatthew G. Knepley #if 1
2241a97b51b8SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2242a97b51b8SMatthew G. Knepley       for (p = 0; p < 2; ++p) {
2243a97b51b8SMatthew G. Knepley         if ((supportNew[p] < cStartNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cEndNew);
2244a97b51b8SMatthew G. Knepley       }
2245a97b51b8SMatthew G. Knepley #endif
2246a97b51b8SMatthew G. Knepley     }
2247a97b51b8SMatthew G. Knepley     /* Old vertices have identical supports */
2248a97b51b8SMatthew G. Knepley     for (v = vStart; v < vEnd; ++v) {
2249a97b51b8SMatthew G. Knepley       const PetscInt  newp = vStartNew + (v - vStart);
2250a97b51b8SMatthew G. Knepley       const PetscInt *support, *cone;
2251a97b51b8SMatthew G. Knepley       PetscInt        size, s;
2252a97b51b8SMatthew G. Knepley 
2253a97b51b8SMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, v, &size);CHKERRQ(ierr);
2254a97b51b8SMatthew G. Knepley       ierr = DMPlexGetSupport(dm, v, &support);CHKERRQ(ierr);
2255a97b51b8SMatthew G. Knepley       for (s = 0; s < size; ++s) {
2256a97b51b8SMatthew G. Knepley         if (support[s] >= fMax) {
2257a97b51b8SMatthew G. Knepley           supportRef[s] = fStartNew + (fMax - fStart)*2 + (cMax - cStart)*4 + (support[s] - fMax);
2258a97b51b8SMatthew G. Knepley         } else {
2259a97b51b8SMatthew G. Knepley           PetscInt r = 0;
2260a97b51b8SMatthew G. Knepley 
2261a97b51b8SMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
2262a97b51b8SMatthew G. Knepley           if (cone[1] == v) r = 1;
2263a97b51b8SMatthew G. Knepley           supportRef[s] = fStartNew + (support[s] - fStart)*2 + r;
2264a97b51b8SMatthew G. Knepley         }
2265a97b51b8SMatthew G. Knepley       }
2266a97b51b8SMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
2267a97b51b8SMatthew G. Knepley #if 1
2268a97b51b8SMatthew G. Knepley       if ((newp < vStartNew) || (newp >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", newp, vStartNew, vEndNew);
2269a97b51b8SMatthew G. Knepley       for (p = 0; p < size; ++p) {
2270a97b51b8SMatthew G. Knepley         if ((supportRef[p] < fStartNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", supportRef[p], fStartNew, fEndNew);
2271a97b51b8SMatthew G. Knepley       }
2272a97b51b8SMatthew G. Knepley #endif
2273a97b51b8SMatthew G. Knepley     }
2274a97b51b8SMatthew G. Knepley     /* Face vertices have 2 + cells supports */
2275a97b51b8SMatthew G. Knepley     for (f = fStart; f < fMax; ++f) {
2276a97b51b8SMatthew G. Knepley       const PetscInt  newp = vStartNew + (vEnd - vStart) + (f - fStart);
2277a97b51b8SMatthew G. Knepley       const PetscInt *cone, *support;
2278a97b51b8SMatthew G. Knepley       PetscInt        size, s;
2279a97b51b8SMatthew G. Knepley 
2280a97b51b8SMatthew G. Knepley       ierr          = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
2281a97b51b8SMatthew G. Knepley       ierr          = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
2282a97b51b8SMatthew G. Knepley       supportRef[0] = fStartNew + (f - fStart)*2 + 0;
2283a97b51b8SMatthew G. Knepley       supportRef[1] = fStartNew + (f - fStart)*2 + 1;
2284a97b51b8SMatthew G. Knepley       for (s = 0; s < size; ++s) {
2285a97b51b8SMatthew G. Knepley         PetscInt r = 0;
2286a97b51b8SMatthew G. Knepley 
2287a97b51b8SMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
2288a97b51b8SMatthew G. Knepley         if (support[s] >= cMax) {
2289a97b51b8SMatthew G. Knepley           supportRef[2+s] = fStartNew + (fMax - fStart)*2 + (cMax - cStart)*4 + (fEnd - fMax) + (support[s] - cMax);
2290a97b51b8SMatthew G. Knepley         } else {
2291a97b51b8SMatthew G. Knepley           if      (cone[1] == f) r = 1;
2292a97b51b8SMatthew G. Knepley           else if (cone[2] == f) r = 2;
2293a97b51b8SMatthew G. Knepley           else if (cone[3] == f) r = 3;
2294a97b51b8SMatthew G. Knepley           supportRef[2+s] = fStartNew + (fMax - fStart)*2 + (support[s] - cStart)*4 + r;
2295a97b51b8SMatthew G. Knepley         }
2296a97b51b8SMatthew G. Knepley       }
2297a97b51b8SMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
2298a97b51b8SMatthew G. Knepley #if 1
2299a97b51b8SMatthew G. Knepley       if ((newp < vStartNew) || (newp >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", newp, vStartNew, vEndNew);
2300a97b51b8SMatthew G. Knepley       for (p = 0; p < 2+size; ++p) {
2301a97b51b8SMatthew G. Knepley         if ((supportRef[p] < fStartNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", supportRef[p], fStartNew, fEndNew);
2302a97b51b8SMatthew G. Knepley       }
2303a97b51b8SMatthew G. Knepley #endif
2304a97b51b8SMatthew G. Knepley     }
2305a97b51b8SMatthew G. Knepley     /* Cell vertices have 4 supports */
2306a97b51b8SMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
2307a97b51b8SMatthew G. Knepley       const PetscInt newp = vStartNew + (vEnd - vStart) + (fMax - fStart) + (c - cStart);
2308a97b51b8SMatthew G. Knepley       PetscInt       supportNew[4];
2309a97b51b8SMatthew G. Knepley 
2310a97b51b8SMatthew G. Knepley       for (r = 0; r < 4; ++r) {
2311a97b51b8SMatthew G. Knepley         supportNew[r] = fStartNew + (fMax - fStart)*2 + (c - cStart)*4 + r;
2312a97b51b8SMatthew G. Knepley       }
2313a97b51b8SMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
2314a97b51b8SMatthew G. Knepley     }
2315a97b51b8SMatthew G. Knepley     ierr = PetscFree(supportRef);CHKERRQ(ierr);
2316a97b51b8SMatthew G. Knepley     break;
23179b1a0e7fSLawrence Mitchell   case REFINER_SIMPLEX_3D:
2318b5da9499SMatthew G. Knepley     /* All cells have 4 faces: Tet face order is prescribed in DMPlexGetFaces_Internal() */
2319b5da9499SMatthew G. Knepley     ierr = DMPlexGetRawFaces_Internal(dm, 3, 4, cellInd, NULL, NULL, &faces);CHKERRQ(ierr);
2320b5da9499SMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
2321b5da9499SMatthew G. Knepley       const PetscInt  newp = cStartNew + (c - cStart)*8;
2322b5da9499SMatthew G. Knepley       const PetscInt *cone, *ornt;
2323b5da9499SMatthew G. Knepley       PetscInt        coneNew[4], orntNew[4];
2324b5da9499SMatthew G. Knepley 
2325b5da9499SMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
2326b5da9499SMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr);
2327b5da9499SMatthew G. Knepley       /* A tetrahedron: {0, a, c, d} */
2328518a8359SMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*4 + GetTriSubface_Static(ornt[0], 0); /* A */
2329b5da9499SMatthew G. Knepley       orntNew[0] = ornt[0];
2330518a8359SMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*4 + GetTriSubface_Static(ornt[1], 0); /* A */
2331b5da9499SMatthew G. Knepley       orntNew[1] = ornt[1];
2332518a8359SMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*4 + GetTriSubface_Static(ornt[2], 0); /* A */
2333b5da9499SMatthew G. Knepley       orntNew[2] = ornt[2];
2334b5da9499SMatthew G. Knepley       coneNew[3] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 0;
2335b5da9499SMatthew G. Knepley       orntNew[3] = 0;
2336b5da9499SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+0, coneNew);CHKERRQ(ierr);
2337b5da9499SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+0, orntNew);CHKERRQ(ierr);
2338b5da9499SMatthew G. Knepley #if 1
2339b5da9499SMatthew G. Knepley       if ((newp+0 < cStartNew) || (newp+0 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+0, cStartNew, cEndNew);
2340b5da9499SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
2341b5da9499SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
2342b5da9499SMatthew G. Knepley       }
2343b5da9499SMatthew G. Knepley #endif
2344b5da9499SMatthew G. Knepley       /* B tetrahedron: {a, 1, b, e} */
2345518a8359SMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*4 + GetTriSubface_Static(ornt[0], 1); /* B */
2346b5da9499SMatthew G. Knepley       orntNew[0] = ornt[0];
2347518a8359SMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*4 + GetTriSubface_Static(ornt[1], 2); /* C */
2348b5da9499SMatthew G. Knepley       orntNew[1] = ornt[1];
2349b5da9499SMatthew G. Knepley       coneNew[2] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 1;
2350b5da9499SMatthew G. Knepley       orntNew[2] = 0;
2351518a8359SMatthew G. Knepley       coneNew[3] = fStartNew + (cone[3] - fStart)*4 + GetTriSubface_Static(ornt[3], 1); /* B */
2352b5da9499SMatthew G. Knepley       orntNew[3] = ornt[3];
2353b5da9499SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+1, coneNew);CHKERRQ(ierr);
2354b5da9499SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+1, orntNew);CHKERRQ(ierr);
2355b5da9499SMatthew G. Knepley #if 1
2356b5da9499SMatthew G. Knepley       if ((newp+1 < cStartNew) || (newp+1 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+1, cStartNew, cEndNew);
2357b5da9499SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
2358b5da9499SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
2359b5da9499SMatthew G. Knepley       }
2360b5da9499SMatthew G. Knepley #endif
2361b5da9499SMatthew G. Knepley       /* C tetrahedron: {c, b, 2, f} */
2362518a8359SMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*4 + GetTriSubface_Static(ornt[0], 2); /* C */
2363b5da9499SMatthew G. Knepley       orntNew[0] = ornt[0];
2364b5da9499SMatthew G. Knepley       coneNew[1] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 2;
2365b5da9499SMatthew G. Knepley       orntNew[1] = 0;
2366518a8359SMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*4 + GetTriSubface_Static(ornt[2], 1); /* B */
2367b5da9499SMatthew G. Knepley       orntNew[2] = ornt[2];
2368518a8359SMatthew G. Knepley       coneNew[3] = fStartNew + (cone[3] - fStart)*4 + GetTriSubface_Static(ornt[3], 0); /* A */
2369b5da9499SMatthew G. Knepley       orntNew[3] = ornt[3];
2370b5da9499SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+2, coneNew);CHKERRQ(ierr);
2371b5da9499SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+2, orntNew);CHKERRQ(ierr);
2372b5da9499SMatthew G. Knepley #if 1
2373b5da9499SMatthew G. Knepley       if ((newp+2 < cStartNew) || (newp+2 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+2, cStartNew, cEndNew);
2374b5da9499SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
2375b5da9499SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
2376b5da9499SMatthew G. Knepley       }
2377b5da9499SMatthew G. Knepley #endif
2378b5da9499SMatthew G. Knepley       /* D tetrahedron: {d, e, f, 3} */
2379b5da9499SMatthew G. Knepley       coneNew[0] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 3;
2380b5da9499SMatthew G. Knepley       orntNew[0] = 0;
2381518a8359SMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*4 + GetTriSubface_Static(ornt[1], 1); /* B */
2382b5da9499SMatthew G. Knepley       orntNew[1] = ornt[1];
2383518a8359SMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*4 + GetTriSubface_Static(ornt[2], 2); /* C */
2384b5da9499SMatthew G. Knepley       orntNew[2] = ornt[2];
2385518a8359SMatthew G. Knepley       coneNew[3] = fStartNew + (cone[3] - fStart)*4 + GetTriSubface_Static(ornt[3], 2); /* C */
2386b5da9499SMatthew G. Knepley       orntNew[3] = ornt[3];
2387b5da9499SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+3, coneNew);CHKERRQ(ierr);
2388b5da9499SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+3, orntNew);CHKERRQ(ierr);
2389b5da9499SMatthew G. Knepley #if 1
2390b5da9499SMatthew G. Knepley       if ((newp+3 < cStartNew) || (newp+3 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+3, cStartNew, cEndNew);
2391b5da9499SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
2392b5da9499SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
2393b5da9499SMatthew G. Knepley       }
2394b5da9499SMatthew G. Knepley #endif
2395*3fe31fa2SToby Isaac       /* A' tetrahedron: {c, d, a, f} */
2396b5da9499SMatthew G. Knepley       coneNew[0] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 0;
2397b5da9499SMatthew G. Knepley       orntNew[0] = -3;
2398fac4ab25SMatthew G. Knepley       coneNew[1] = fStartNew + (cone[2] - fStart)*4 + 3;
2399db2c6090SMatthew G. Knepley       orntNew[1] = ornt[2] < 0 ? -(GetTetSomething_Static(ornt[2], 0)+1) : GetTetSomething_Static(ornt[2], 0);
2400fac4ab25SMatthew G. Knepley       coneNew[2] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 5;
2401fac4ab25SMatthew G. Knepley       orntNew[2] = 0;
2402fac4ab25SMatthew G. Knepley       coneNew[3] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 4;
2403fac4ab25SMatthew G. Knepley       orntNew[3] = 2;
2404b5da9499SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+4, coneNew);CHKERRQ(ierr);
2405b5da9499SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+4, orntNew);CHKERRQ(ierr);
2406b5da9499SMatthew G. Knepley #if 1
2407b5da9499SMatthew G. Knepley       if ((newp+4 < cStartNew) || (newp+4 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+4, cStartNew, cEndNew);
2408b5da9499SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
2409b5da9499SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
2410b5da9499SMatthew G. Knepley       }
2411b5da9499SMatthew G. Knepley #endif
2412*3fe31fa2SToby Isaac #if 0
2413*3fe31fa2SToby Isaac       /* B' tetrahedron: {a, e, b, f} */
2414b5da9499SMatthew G. Knepley       coneNew[0] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 1;
2415b5da9499SMatthew G. Knepley       orntNew[0] = -3;
2416fac4ab25SMatthew G. Knepley       coneNew[1] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 6;
2417fac4ab25SMatthew G. Knepley       orntNew[1] = 1;
2418fac4ab25SMatthew G. Knepley       coneNew[2] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 7;
2419b5da9499SMatthew G. Knepley       orntNew[2] = 0;
2420fac4ab25SMatthew G. Knepley       coneNew[3] = fStartNew + (cone[3] - fStart)*4 + 3;
2421db2c6090SMatthew G. Knepley       orntNew[3] = ornt[3] < 0 ? -(GetTetSomething_Static(ornt[3], 0)+1) : GetTetSomething_Static(ornt[3], 0);
2422*3fe31fa2SToby Isaac #else
2423*3fe31fa2SToby Isaac       /* B' tetrahedron: {e, b, a, f} */
2424*3fe31fa2SToby Isaac       coneNew[0] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 1;
2425*3fe31fa2SToby Isaac       orntNew[0] = -2;
2426*3fe31fa2SToby Isaac       coneNew[1] = fStartNew + (cone[3] - fStart)*4 + 3;
2427*3fe31fa2SToby Isaac       orntNew[1] = ornt[3] < 0 ? -(GetTetSomething_Static(ornt[3], 1)+1) : GetTetSomething_Static(ornt[3], 1);
2428*3fe31fa2SToby Isaac       coneNew[2] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 6;
2429*3fe31fa2SToby Isaac       orntNew[2] = 0;
2430*3fe31fa2SToby Isaac       coneNew[3] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 7;
2431*3fe31fa2SToby Isaac       orntNew[3] = 0;
2432*3fe31fa2SToby Isaac #endif
2433b5da9499SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+5, coneNew);CHKERRQ(ierr);
2434b5da9499SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+5, orntNew);CHKERRQ(ierr);
2435b5da9499SMatthew G. Knepley #if 1
2436b5da9499SMatthew G. Knepley       if ((newp+5 < cStartNew) || (newp+5 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+5, cStartNew, cEndNew);
2437b5da9499SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
2438b5da9499SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
2439b5da9499SMatthew G. Knepley       }
2440b5da9499SMatthew G. Knepley #endif
2441*3fe31fa2SToby Isaac #if 0
2442*3fe31fa2SToby Isaac       /* C' tetrahedron: {c, b, f, a} */
2443b5da9499SMatthew G. Knepley       coneNew[0] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 2;
2444b5da9499SMatthew G. Knepley       orntNew[0] = -3;
2445fac4ab25SMatthew G. Knepley       coneNew[1] = fStartNew + (cone[0] - fStart)*4 + 3;
2446db2c6090SMatthew G. Knepley       orntNew[1] = ornt[0] < 0 ? -(GetTetSomething_Static(ornt[0], 2)+1) : GetTetSomething_Static(ornt[0], 2);
2447fac4ab25SMatthew G. Knepley       coneNew[2] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 5;
2448fac4ab25SMatthew G. Knepley       orntNew[2] = -3;
2449fac4ab25SMatthew G. Knepley       coneNew[3] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 7;
2450fac4ab25SMatthew G. Knepley       orntNew[3] = -2;
2451*3fe31fa2SToby Isaac #else
2452*3fe31fa2SToby Isaac       /* C' tetrahedron: {f, a, c, b} */
2453*3fe31fa2SToby Isaac       coneNew[0] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 5;
2454*3fe31fa2SToby Isaac       orntNew[0] = -2;
2455*3fe31fa2SToby Isaac       coneNew[1] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 7;
2456*3fe31fa2SToby Isaac       orntNew[1] = -2;
2457*3fe31fa2SToby Isaac       coneNew[2] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 2;
2458*3fe31fa2SToby Isaac       orntNew[2] = -1;
2459*3fe31fa2SToby Isaac       coneNew[3] = fStartNew + (cone[0] - fStart)*4 + 3;
2460*3fe31fa2SToby Isaac       orntNew[3] = ornt[0] < 0 ? -(GetTetSomething_Static(ornt[0], 2)+1) : GetTetSomething_Static(ornt[0], 2);
2461*3fe31fa2SToby Isaac #endif
2462b5da9499SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+6, coneNew);CHKERRQ(ierr);
2463b5da9499SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+6, orntNew);CHKERRQ(ierr);
2464b5da9499SMatthew G. Knepley #if 1
2465b5da9499SMatthew G. Knepley       if ((newp+6 < cStartNew) || (newp+6 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+6, cStartNew, cEndNew);
2466b5da9499SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
2467b5da9499SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
2468b5da9499SMatthew G. Knepley       }
2469b5da9499SMatthew G. Knepley #endif
2470*3fe31fa2SToby Isaac #if 0
2471*3fe31fa2SToby Isaac       /* D' tetrahedron: {d, f, e, a} */
2472b5da9499SMatthew G. Knepley       coneNew[0] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 3;
2473b5da9499SMatthew G. Knepley       orntNew[0] = -3;
2474fac4ab25SMatthew G. Knepley       coneNew[1] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 4;
2475b5da9499SMatthew G. Knepley       orntNew[1] = -3;
2476fac4ab25SMatthew G. Knepley       coneNew[2] = fStartNew + (cone[1] - fStart)*4 + 3;
2477db2c6090SMatthew G. Knepley       orntNew[2] = ornt[1] < 0 ? -(GetTetSomething_Static(ornt[1], 0)+1) : GetTetSomething_Static(ornt[1], 0);
2478fac4ab25SMatthew G. Knepley       coneNew[3] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 6;
2479fac4ab25SMatthew G. Knepley       orntNew[3] = -3;
2480*3fe31fa2SToby Isaac #else
2481*3fe31fa2SToby Isaac       /* D' tetrahedron: {f, a, e, d} */
2482*3fe31fa2SToby Isaac       coneNew[0] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 6;
2483*3fe31fa2SToby Isaac       orntNew[0] = -2;
2484*3fe31fa2SToby Isaac       coneNew[1] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 4;
2485*3fe31fa2SToby Isaac       orntNew[1] = -1;
2486*3fe31fa2SToby Isaac       coneNew[2] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*8 + 3;
2487*3fe31fa2SToby Isaac       orntNew[2] = -2;
2488*3fe31fa2SToby Isaac       coneNew[3] = fStartNew + (cone[1] - fStart)*4 + 3;
2489*3fe31fa2SToby Isaac       orntNew[3] = ornt[1] < 0 ? -(GetTetSomething_Static(ornt[1], 1)+1) : GetTetSomething_Static(ornt[1], 1);
2490*3fe31fa2SToby Isaac #endif
2491b5da9499SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+7, coneNew);CHKERRQ(ierr);
2492b5da9499SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+7, orntNew);CHKERRQ(ierr);
2493b5da9499SMatthew G. Knepley #if 1
2494b5da9499SMatthew G. Knepley       if ((newp+7 < cStartNew) || (newp+7 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+7, cStartNew, cEndNew);
2495b5da9499SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
2496b5da9499SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
2497b5da9499SMatthew G. Knepley       }
2498b5da9499SMatthew G. Knepley #endif
2499b5da9499SMatthew G. Knepley     }
2500b5da9499SMatthew G. Knepley     /* Split faces have 3 edges and the same cells as the parent */
2501b5da9499SMatthew G. Knepley     ierr = DMPlexGetMaxSizes(dm, NULL, &maxSupportSize);CHKERRQ(ierr);
2502854ce69bSBarry Smith     ierr = PetscMalloc1(2 + maxSupportSize*2, &supportRef);CHKERRQ(ierr);
2503b5da9499SMatthew G. Knepley     for (f = fStart; f < fEnd; ++f) {
2504b5da9499SMatthew G. Knepley       const PetscInt  newp = fStartNew + (f - fStart)*4;
2505b5da9499SMatthew G. Knepley       const PetscInt *cone, *ornt, *support;
2506b5da9499SMatthew G. Knepley       PetscInt        coneNew[3], orntNew[3], coneSize, supportSize, s;
2507b5da9499SMatthew G. Knepley 
2508b5da9499SMatthew G. Knepley       ierr = DMPlexGetCone(dm, f, &cone);CHKERRQ(ierr);
2509b5da9499SMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, f, &ornt);CHKERRQ(ierr);
2510b5da9499SMatthew G. Knepley       /* A triangle */
2511b5da9499SMatthew G. Knepley       coneNew[0] = eStartNew + (cone[0] - eStart)*2 + (ornt[0] < 0 ? 1 : 0);
2512b5da9499SMatthew G. Knepley       orntNew[0] = ornt[0];
2513b5da9499SMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd    - eStart)*2 + (f - fStart)*3 + 2;
2514b5da9499SMatthew G. Knepley       orntNew[1] = -2;
2515b5da9499SMatthew G. Knepley       coneNew[2] = eStartNew + (cone[2] - eStart)*2 + (ornt[2] < 0 ? 0 : 1);
2516b5da9499SMatthew G. Knepley       orntNew[2] = ornt[2];
2517b5da9499SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+0, coneNew);CHKERRQ(ierr);
2518b5da9499SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+0, orntNew);CHKERRQ(ierr);
2519b5da9499SMatthew G. Knepley #if 1
2520b5da9499SMatthew G. Knepley       if ((newp+0 < fStartNew) || (newp+0 >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp+0, fStartNew, fEndNew);
2521b5da9499SMatthew G. Knepley       for (p = 0; p < 3; ++p) {
2522b5da9499SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
2523b5da9499SMatthew G. Knepley       }
2524b5da9499SMatthew G. Knepley #endif
2525b5da9499SMatthew G. Knepley       /* B triangle */
2526b5da9499SMatthew G. Knepley       coneNew[0] = eStartNew + (cone[0] - eStart)*2 + (ornt[0] < 0 ? 0 : 1);
2527b5da9499SMatthew G. Knepley       orntNew[0] = ornt[0];
2528b5da9499SMatthew G. Knepley       coneNew[1] = eStartNew + (cone[1] - eStart)*2 + (ornt[1] < 0 ? 1 : 0);
2529b5da9499SMatthew G. Knepley       orntNew[1] = ornt[1];
2530b5da9499SMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd    - eStart)*2 + (f - fStart)*3 + 0;
2531b5da9499SMatthew G. Knepley       orntNew[2] = -2;
2532b5da9499SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+1, coneNew);CHKERRQ(ierr);
2533b5da9499SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+1, orntNew);CHKERRQ(ierr);
2534b5da9499SMatthew G. Knepley #if 1
2535b5da9499SMatthew G. Knepley       if ((newp+1 < fStartNew) || (newp+1 >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp+1, fStartNew, fEndNew);
2536b5da9499SMatthew G. Knepley       for (p = 0; p < 3; ++p) {
2537b5da9499SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
2538b5da9499SMatthew G. Knepley       }
2539b5da9499SMatthew G. Knepley #endif
2540b5da9499SMatthew G. Knepley       /* C triangle */
2541b5da9499SMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd    - eStart)*2 + (f - fStart)*3 + 1;
2542b5da9499SMatthew G. Knepley       orntNew[0] = -2;
2543b5da9499SMatthew G. Knepley       coneNew[1] = eStartNew + (cone[1] - eStart)*2 + (ornt[1] < 0 ? 0 : 1);
2544b5da9499SMatthew G. Knepley       orntNew[1] = ornt[1];
2545b5da9499SMatthew G. Knepley       coneNew[2] = eStartNew + (cone[2] - eStart)*2 + (ornt[2] < 0 ? 1 : 0);
2546b5da9499SMatthew G. Knepley       orntNew[2] = ornt[2];
2547b5da9499SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+2, coneNew);CHKERRQ(ierr);
2548b5da9499SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+2, orntNew);CHKERRQ(ierr);
2549b5da9499SMatthew G. Knepley #if 1
2550b5da9499SMatthew G. Knepley       if ((newp+2 < fStartNew) || (newp+2 >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp+2, fStartNew, fEndNew);
2551b5da9499SMatthew G. Knepley       for (p = 0; p < 3; ++p) {
2552b5da9499SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
2553b5da9499SMatthew G. Knepley       }
2554b5da9499SMatthew G. Knepley #endif
2555b5da9499SMatthew G. Knepley       /* D triangle */
2556b5da9499SMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd    - eStart)*2 + (f - fStart)*3 + 0;
2557b5da9499SMatthew G. Knepley       orntNew[0] = 0;
2558b5da9499SMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd    - eStart)*2 + (f - fStart)*3 + 1;
2559b5da9499SMatthew G. Knepley       orntNew[1] = 0;
2560b5da9499SMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd    - eStart)*2 + (f - fStart)*3 + 2;
2561b5da9499SMatthew G. Knepley       orntNew[2] = 0;
2562b5da9499SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+3, coneNew);CHKERRQ(ierr);
2563b5da9499SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+3, orntNew);CHKERRQ(ierr);
2564b5da9499SMatthew G. Knepley #if 1
2565b5da9499SMatthew G. Knepley       if ((newp+3 < fStartNew) || (newp+3 >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp+3, fStartNew, fEndNew);
2566b5da9499SMatthew G. Knepley       for (p = 0; p < 3; ++p) {
2567b5da9499SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
2568b5da9499SMatthew G. Knepley       }
2569b5da9499SMatthew G. Knepley #endif
2570b5da9499SMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, f, &supportSize);CHKERRQ(ierr);
2571b5da9499SMatthew G. Knepley       ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
2572b5da9499SMatthew G. Knepley       for (r = 0; r < 4; ++r) {
2573b5da9499SMatthew G. Knepley         for (s = 0; s < supportSize; ++s) {
2574219f7b90SMatthew G. Knepley           PetscInt subf;
2575b5da9499SMatthew G. Knepley           ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr);
2576b5da9499SMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
2577b5da9499SMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, support[s], &ornt);CHKERRQ(ierr);
2578b5da9499SMatthew G. Knepley           for (c = 0; c < coneSize; ++c) {
2579b5da9499SMatthew G. Knepley             if (cone[c] == f) break;
2580b5da9499SMatthew G. Knepley           }
2581219f7b90SMatthew G. Knepley           subf = GetTriSubfaceInverse_Static(ornt[c], r);
2582219f7b90SMatthew G. Knepley           supportRef[s] = cStartNew + (support[s] - cStart)*8 + (r==3 ? (c+2)%4 + 4 : faces[c*3+subf]);
2583b5da9499SMatthew G. Knepley         }
2584b5da9499SMatthew G. Knepley         ierr = DMPlexSetSupport(rdm, newp+r, supportRef);CHKERRQ(ierr);
2585b5da9499SMatthew G. Knepley #if 1
25869ddff745SMatthew G. Knepley         if ((newp+r < fStartNew) || (newp+r >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp+r, fStartNew, fEndNew);
2587b5da9499SMatthew G. Knepley         for (p = 0; p < supportSize; ++p) {
2588b5da9499SMatthew G. Knepley           if ((supportRef[p] < cStartNew) || (supportRef[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportRef[p], cStartNew, cEndNew);
2589b5da9499SMatthew G. Knepley         }
2590b5da9499SMatthew G. Knepley #endif
2591b5da9499SMatthew G. Knepley       }
2592b5da9499SMatthew G. Knepley     }
2593b5da9499SMatthew G. Knepley     /* Interior faces have 3 edges and 2 cells */
2594b5da9499SMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
2595b5da9499SMatthew G. Knepley       PetscInt        newp = fStartNew + (fEnd - fStart)*4 + (c - cStart)*8;
2596b5da9499SMatthew G. Knepley       const PetscInt *cone, *ornt;
2597b5da9499SMatthew G. Knepley       PetscInt        coneNew[3], orntNew[3];
2598b5da9499SMatthew G. Knepley       PetscInt        supportNew[2];
2599b5da9499SMatthew G. Knepley 
2600b5da9499SMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
2601b5da9499SMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr);
2602b5da9499SMatthew G. Knepley       /* Face A: {c, a, d} */
26034bb260e2SMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd - eStart)*2 + (cone[0] - fStart)*3 + GetTetSomething_Static(ornt[0], 2);
2604b5da9499SMatthew G. Knepley       orntNew[0] = ornt[0] < 0 ? -2 : 0;
26054bb260e2SMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd - eStart)*2 + (cone[1] - fStart)*3 + GetTetSomething_Static(ornt[1], 2);
2606b5da9499SMatthew G. Knepley       orntNew[1] = ornt[1] < 0 ? -2 : 0;
26074bb260e2SMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd - eStart)*2 + (cone[2] - fStart)*3 + GetTetSomething_Static(ornt[2], 2);
2608b5da9499SMatthew G. Knepley       orntNew[2] = ornt[2] < 0 ? -2 : 0;
2609b5da9499SMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
2610b5da9499SMatthew G. Knepley       ierr = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
2611b5da9499SMatthew G. Knepley #if 1
2612b5da9499SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2613b5da9499SMatthew G. Knepley       for (p = 0; p < 3; ++p) {
2614b5da9499SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
2615b5da9499SMatthew G. Knepley       }
2616b5da9499SMatthew G. Knepley #endif
2617b5da9499SMatthew G. Knepley       supportNew[0] = (c - cStart)*8 + 0;
2618b5da9499SMatthew G. Knepley       supportNew[1] = (c - cStart)*8 + 0+4;
2619b5da9499SMatthew G. Knepley       ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
2620b5da9499SMatthew G. Knepley #if 1
2621b5da9499SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2622b5da9499SMatthew G. Knepley       for (p = 0; p < 2; ++p) {
2623b5da9499SMatthew G. Knepley         if ((supportNew[p] < cStartNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cEndNew);
2624b5da9499SMatthew G. Knepley       }
2625b5da9499SMatthew G. Knepley #endif
2626b5da9499SMatthew G. Knepley       ++newp;
2627b5da9499SMatthew G. Knepley       /* Face B: {a, b, e} */
26284bb260e2SMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd - eStart)*2 + (cone[0] - fStart)*3 + GetTetSomething_Static(ornt[0], 0);
2629b5da9499SMatthew G. Knepley       orntNew[0] = ornt[0] < 0 ? -2 : 0;
26304bb260e2SMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd - eStart)*2 + (cone[3] - fStart)*3 + GetTetSomething_Static(ornt[3], 0);
2631b5da9499SMatthew G. Knepley       orntNew[1] = ornt[3] < 0 ? -2 : 0;
26324bb260e2SMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd - eStart)*2 + (cone[1] - fStart)*3 + GetTetSomething_Static(ornt[1], 1);
2633b5da9499SMatthew G. Knepley       orntNew[2] = ornt[1] < 0 ? -2 : 0;
2634b5da9499SMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
2635b5da9499SMatthew G. Knepley       ierr = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
2636b5da9499SMatthew G. Knepley #if 1
26374bb260e2SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2638b5da9499SMatthew G. Knepley       for (p = 0; p < 3; ++p) {
2639b5da9499SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
2640b5da9499SMatthew G. Knepley       }
2641b5da9499SMatthew G. Knepley #endif
2642b5da9499SMatthew G. Knepley       supportNew[0] = (c - cStart)*8 + 1;
2643b5da9499SMatthew G. Knepley       supportNew[1] = (c - cStart)*8 + 1+4;
2644b5da9499SMatthew G. Knepley       ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
2645b5da9499SMatthew G. Knepley #if 1
2646b5da9499SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2647b5da9499SMatthew G. Knepley       for (p = 0; p < 2; ++p) {
2648b5da9499SMatthew G. Knepley         if ((supportNew[p] < cStartNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cEndNew);
2649b5da9499SMatthew G. Knepley       }
2650b5da9499SMatthew G. Knepley #endif
2651b5da9499SMatthew G. Knepley       ++newp;
2652b5da9499SMatthew G. Knepley       /* Face C: {c, f, b} */
26534bb260e2SMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd - eStart)*2 + (cone[2] - fStart)*3 + GetTetSomething_Static(ornt[2], 0);
2654b5da9499SMatthew G. Knepley       orntNew[0] = ornt[2] < 0 ? -2 : 0;
26554bb260e2SMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd - eStart)*2 + (cone[3] - fStart)*3 + GetTetSomething_Static(ornt[3], 2);
2656b5da9499SMatthew G. Knepley       orntNew[1] = ornt[3] < 0 ? -2 : 0;
26574bb260e2SMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd - eStart)*2 + (cone[0] - fStart)*3 + GetTetSomething_Static(ornt[0], 1);
2658b5da9499SMatthew G. Knepley       orntNew[2] = ornt[0] < 0 ? -2 : 0;
2659b5da9499SMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
2660b5da9499SMatthew G. Knepley       ierr = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
2661b5da9499SMatthew G. Knepley #if 1
2662b5da9499SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2663b5da9499SMatthew G. Knepley       for (p = 0; p < 3; ++p) {
2664b5da9499SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
2665b5da9499SMatthew G. Knepley       }
2666b5da9499SMatthew G. Knepley #endif
2667b5da9499SMatthew G. Knepley       supportNew[0] = (c - cStart)*8 + 2;
2668b5da9499SMatthew G. Knepley       supportNew[1] = (c - cStart)*8 + 2+4;
2669b5da9499SMatthew G. Knepley       ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
2670b5da9499SMatthew G. Knepley #if 1
2671b5da9499SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2672b5da9499SMatthew G. Knepley       for (p = 0; p < 2; ++p) {
2673b5da9499SMatthew G. Knepley         if ((supportNew[p] < cStartNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cEndNew);
2674b5da9499SMatthew G. Knepley       }
2675b5da9499SMatthew G. Knepley #endif
2676b5da9499SMatthew G. Knepley       ++newp;
2677b5da9499SMatthew G. Knepley       /* Face D: {d, e, f} */
26784bb260e2SMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd - eStart)*2 + (cone[1] - fStart)*3 + GetTetSomething_Static(ornt[1], 0);
2679b5da9499SMatthew G. Knepley       orntNew[0] = ornt[1] < 0 ? -2 : 0;
26804bb260e2SMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd - eStart)*2 + (cone[3] - fStart)*3 + GetTetSomething_Static(ornt[3], 1);
2681b5da9499SMatthew G. Knepley       orntNew[1] = ornt[3] < 0 ? -2 : 0;
26824bb260e2SMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd - eStart)*2 + (cone[2] - fStart)*3 + GetTetSomething_Static(ornt[2], 1);
2683b5da9499SMatthew G. Knepley       orntNew[2] = ornt[2] < 0 ? -2 : 0;
2684b5da9499SMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
2685b5da9499SMatthew G. Knepley       ierr = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
2686b5da9499SMatthew G. Knepley #if 1
2687b5da9499SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2688b5da9499SMatthew G. Knepley       for (p = 0; p < 3; ++p) {
2689b5da9499SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
2690b5da9499SMatthew G. Knepley       }
2691b5da9499SMatthew G. Knepley #endif
2692b5da9499SMatthew G. Knepley       supportNew[0] = (c - cStart)*8 + 3;
2693b5da9499SMatthew G. Knepley       supportNew[1] = (c - cStart)*8 + 3+4;
2694b5da9499SMatthew G. Knepley       ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
2695b5da9499SMatthew G. Knepley #if 1
2696b5da9499SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2697b5da9499SMatthew G. Knepley       for (p = 0; p < 2; ++p) {
2698b5da9499SMatthew G. Knepley         if ((supportNew[p] < cStartNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cEndNew);
2699b5da9499SMatthew G. Knepley       }
2700b5da9499SMatthew G. Knepley #endif
2701b5da9499SMatthew G. Knepley       ++newp;
2702b5da9499SMatthew G. Knepley       /* Face E: {d, f, a} */
27034bb260e2SMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd - eStart)*2 + (cone[2] - fStart)*3 + GetTetSomething_Static(ornt[2], 1);
2704b5da9499SMatthew G. Knepley       orntNew[0] = ornt[2] < 0 ? 0 : -2;
2705b5da9499SMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd - eStart)*2 + (fEnd - fStart)*3 + (c - cStart);
27064bb260e2SMatthew G. Knepley       orntNew[1] = -2;
27074bb260e2SMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd - eStart)*2 + (cone[1] - fStart)*3 + GetTetSomething_Static(ornt[1], 2);
2708b5da9499SMatthew G. Knepley       orntNew[2] = ornt[1] < 0 ? -2 : 0;
2709b5da9499SMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
2710b5da9499SMatthew G. Knepley       ierr = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
2711b5da9499SMatthew G. Knepley #if 1
2712b5da9499SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2713b5da9499SMatthew G. Knepley       for (p = 0; p < 3; ++p) {
2714b5da9499SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
2715b5da9499SMatthew G. Knepley       }
2716b5da9499SMatthew G. Knepley #endif
2717b5da9499SMatthew G. Knepley       supportNew[0] = (c - cStart)*8 + 0+4;
2718b5da9499SMatthew G. Knepley       supportNew[1] = (c - cStart)*8 + 3+4;
2719b5da9499SMatthew G. Knepley       ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
2720b5da9499SMatthew G. Knepley #if 1
2721b5da9499SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2722b5da9499SMatthew G. Knepley       for (p = 0; p < 2; ++p) {
2723b5da9499SMatthew G. Knepley         if ((supportNew[p] < cStartNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cEndNew);
2724b5da9499SMatthew G. Knepley       }
2725b5da9499SMatthew G. Knepley #endif
2726b5da9499SMatthew G. Knepley       ++newp;
2727b5da9499SMatthew G. Knepley       /* Face F: {c, a, f} */
27284bb260e2SMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd - eStart)*2 + (cone[0] - fStart)*3 + GetTetSomething_Static(ornt[0], 2);
2729b5da9499SMatthew G. Knepley       orntNew[0] = ornt[0] < 0 ? -2 : 0;
2730b5da9499SMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd - eStart)*2 + (fEnd - fStart)*3 + (c - cStart);
27314bb260e2SMatthew G. Knepley       orntNew[1] = 0;
27324bb260e2SMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd - eStart)*2 + (cone[2] - fStart)*3 + GetTetSomething_Static(ornt[2], 0);
27332baf2947SMatthew G. Knepley       orntNew[2] = ornt[2] < 0 ? 0 : -2;
2734b5da9499SMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
2735b5da9499SMatthew G. Knepley       ierr = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
2736b5da9499SMatthew G. Knepley #if 1
2737b5da9499SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2738b5da9499SMatthew G. Knepley       for (p = 0; p < 3; ++p) {
2739b5da9499SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
2740b5da9499SMatthew G. Knepley       }
2741b5da9499SMatthew G. Knepley #endif
2742b5da9499SMatthew G. Knepley       supportNew[0] = (c - cStart)*8 + 0+4;
2743b5da9499SMatthew G. Knepley       supportNew[1] = (c - cStart)*8 + 2+4;
2744b5da9499SMatthew G. Knepley       ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
2745b5da9499SMatthew G. Knepley #if 1
2746b5da9499SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2747b5da9499SMatthew G. Knepley       for (p = 0; p < 2; ++p) {
2748b5da9499SMatthew G. Knepley         if ((supportNew[p] < cStartNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cEndNew);
2749b5da9499SMatthew G. Knepley       }
2750b5da9499SMatthew G. Knepley #endif
2751b5da9499SMatthew G. Knepley       ++newp;
2752b5da9499SMatthew G. Knepley       /* Face G: {e, a, f} */
27534bb260e2SMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd - eStart)*2 + (cone[1] - fStart)*3 + GetTetSomething_Static(ornt[1], 1);
2754b5da9499SMatthew G. Knepley       orntNew[0] = ornt[1] < 0 ? -2 : 0;
2755b5da9499SMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd - eStart)*2 + (fEnd - fStart)*3 + (c - cStart);
2756fac4ab25SMatthew G. Knepley       orntNew[1] = 0;
27574bb260e2SMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd - eStart)*2 + (cone[3] - fStart)*3 + GetTetSomething_Static(ornt[3], 1);
2758b5da9499SMatthew G. Knepley       orntNew[2] = ornt[3] < 0 ? 0 : -2;
2759b5da9499SMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
2760b5da9499SMatthew G. Knepley       ierr = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
2761b5da9499SMatthew G. Knepley #if 1
2762b5da9499SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2763b5da9499SMatthew G. Knepley       for (p = 0; p < 3; ++p) {
2764b5da9499SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
2765b5da9499SMatthew G. Knepley       }
2766b5da9499SMatthew G. Knepley #endif
2767b5da9499SMatthew G. Knepley       supportNew[0] = (c - cStart)*8 + 1+4;
2768b5da9499SMatthew G. Knepley       supportNew[1] = (c - cStart)*8 + 3+4;
2769b5da9499SMatthew G. Knepley       ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
2770b5da9499SMatthew G. Knepley #if 1
2771b5da9499SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2772b5da9499SMatthew G. Knepley       for (p = 0; p < 2; ++p) {
2773b5da9499SMatthew G. Knepley         if ((supportNew[p] < cStartNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cEndNew);
2774b5da9499SMatthew G. Knepley       }
2775b5da9499SMatthew G. Knepley #endif
2776b5da9499SMatthew G. Knepley       ++newp;
2777b5da9499SMatthew G. Knepley       /* Face H: {a, b, f} */
27784bb260e2SMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd - eStart)*2 + (cone[0] - fStart)*3 + GetTetSomething_Static(ornt[0], 0);
2779b5da9499SMatthew G. Knepley       orntNew[0] = ornt[0] < 0 ? -2 : 0;
27804bb260e2SMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd - eStart)*2 + (cone[3] - fStart)*3 + GetTetSomething_Static(ornt[3], 2);
2781b5da9499SMatthew G. Knepley       orntNew[1] = ornt[3] < 0 ? 0 : -2;
2782b5da9499SMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd - eStart)*2 + (fEnd - fStart)*3 + (c - cStart);
27834bb260e2SMatthew G. Knepley       orntNew[2] = -2;
2784b5da9499SMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
2785b5da9499SMatthew G. Knepley       ierr = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
2786b5da9499SMatthew G. Knepley #if 1
2787b5da9499SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2788b5da9499SMatthew G. Knepley       for (p = 0; p < 3; ++p) {
2789b5da9499SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
2790b5da9499SMatthew G. Knepley       }
2791b5da9499SMatthew G. Knepley #endif
2792b5da9499SMatthew G. Knepley       supportNew[0] = (c - cStart)*8 + 1+4;
2793b5da9499SMatthew G. Knepley       supportNew[1] = (c - cStart)*8 + 2+4;
2794b5da9499SMatthew G. Knepley       ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
2795b5da9499SMatthew G. Knepley #if 1
2796b5da9499SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
2797b5da9499SMatthew G. Knepley       for (p = 0; p < 2; ++p) {
2798b5da9499SMatthew G. Knepley         if ((supportNew[p] < cStartNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cEndNew);
2799b5da9499SMatthew G. Knepley       }
2800b5da9499SMatthew G. Knepley #endif
2801b5da9499SMatthew G. Knepley       ++newp;
2802b5da9499SMatthew G. Knepley     }
2803b5da9499SMatthew G. Knepley     /* Split Edges have 2 vertices and the same faces as the parent */
2804b5da9499SMatthew G. Knepley     for (e = eStart; e < eEnd; ++e) {
2805b5da9499SMatthew G. Knepley       const PetscInt newv = vStartNew + (vEnd - vStart) + (e - eStart);
2806b5da9499SMatthew G. Knepley 
2807b5da9499SMatthew G. Knepley       for (r = 0; r < 2; ++r) {
2808b5da9499SMatthew G. Knepley         const PetscInt  newp = eStartNew + (e - eStart)*2 + r;
2809b5da9499SMatthew G. Knepley         const PetscInt *cone, *ornt, *support;
2810b5da9499SMatthew G. Knepley         PetscInt        coneNew[2], coneSize, c, supportSize, s;
2811b5da9499SMatthew G. Knepley 
2812b5da9499SMatthew G. Knepley         ierr             = DMPlexGetCone(dm, e, &cone);CHKERRQ(ierr);
2813b5da9499SMatthew G. Knepley         coneNew[0]       = vStartNew + (cone[0] - vStart);
2814b5da9499SMatthew G. Knepley         coneNew[1]       = vStartNew + (cone[1] - vStart);
2815b5da9499SMatthew G. Knepley         coneNew[(r+1)%2] = newv;
2816b5da9499SMatthew G. Knepley         ierr             = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
2817b5da9499SMatthew G. Knepley #if 1
2818b5da9499SMatthew G. Knepley         if ((newp < eStartNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eEndNew);
2819b5da9499SMatthew G. Knepley         for (p = 0; p < 2; ++p) {
2820b5da9499SMatthew G. Knepley           if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
2821b5da9499SMatthew G. Knepley         }
2822b5da9499SMatthew G. Knepley #endif
2823b5da9499SMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, e, &supportSize);CHKERRQ(ierr);
2824b5da9499SMatthew G. Knepley         ierr = DMPlexGetSupport(dm, e, &support);CHKERRQ(ierr);
2825b5da9499SMatthew G. Knepley         for (s = 0; s < supportSize; ++s) {
2826b5da9499SMatthew G. Knepley           ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr);
2827b5da9499SMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
2828b5da9499SMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, support[s], &ornt);CHKERRQ(ierr);
2829b5da9499SMatthew G. Knepley           for (c = 0; c < coneSize; ++c) {
2830b5da9499SMatthew G. Knepley             if (cone[c] == e) break;
2831b5da9499SMatthew G. Knepley           }
2832b5da9499SMatthew G. Knepley           supportRef[s] = fStartNew + (support[s] - fStart)*4 + (c + (ornt[c] < 0 ? 1-r : r))%3;
2833b5da9499SMatthew G. Knepley         }
2834b5da9499SMatthew G. Knepley         ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
2835b5da9499SMatthew G. Knepley #if 1
2836b5da9499SMatthew G. Knepley         if ((newp < eStartNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eEndNew);
2837b5da9499SMatthew G. Knepley         for (p = 0; p < supportSize; ++p) {
2838b5da9499SMatthew G. Knepley           if ((supportRef[p] < fStartNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", supportRef[p], fStartNew, fEndNew);
2839b5da9499SMatthew G. Knepley         }
2840b5da9499SMatthew G. Knepley #endif
2841b5da9499SMatthew G. Knepley       }
2842b5da9499SMatthew G. Knepley     }
284386f0afeeSMatthew G. Knepley     /* Face edges have 2 vertices and 2+cells*(1/2) faces */
2844b5da9499SMatthew G. Knepley     for (f = fStart; f < fEnd; ++f) {
2845b5da9499SMatthew G. Knepley       const PetscInt *cone, *ornt, *support;
2846b5da9499SMatthew G. Knepley       PetscInt        coneSize, supportSize, s;
2847b5da9499SMatthew G. Knepley 
2848b5da9499SMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, f, &supportSize);CHKERRQ(ierr);
2849b5da9499SMatthew G. Knepley       ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
2850b5da9499SMatthew G. Knepley       for (r = 0; r < 3; ++r) {
2851b5da9499SMatthew G. Knepley         const PetscInt  newp = eStartNew + (eEnd - eStart)*2 + (f - fStart)*3 + r;
2852b5da9499SMatthew G. Knepley         PetscInt        coneNew[2], intFaces = 0, er, eint[4] = {1, 0, 2, 0};
2853b5da9499SMatthew G. Knepley         PetscInt        fint[24] = { 1,  7, -1, -1,  0,  5,
2854b5da9499SMatthew G. Knepley                                     -1, -1,  1,  6,  0,  4,
2855b5da9499SMatthew G. Knepley                                      2,  5,  3,  4, -1, -1,
2856b5da9499SMatthew G. Knepley                                     -1, -1,  3,  6,  2,  7};
2857b5da9499SMatthew G. Knepley 
2858b5da9499SMatthew G. Knepley         ierr = DMPlexGetCone(dm, f, &cone);CHKERRQ(ierr);
2859b5da9499SMatthew G. Knepley         coneNew[0] = vStartNew + (vEnd - vStart) + (cone[(r+0)%3] - eStart);
2860b5da9499SMatthew G. Knepley         coneNew[1] = vStartNew + (vEnd - vStart) + (cone[(r+1)%3] - eStart);
2861b5da9499SMatthew G. Knepley         ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
2862b5da9499SMatthew G. Knepley #if 1
2863b5da9499SMatthew G. Knepley         if ((newp < eStartNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eEndNew);
2864b5da9499SMatthew G. Knepley         for (p = 0; p < 2; ++p) {
2865b5da9499SMatthew G. Knepley           if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
2866b5da9499SMatthew G. Knepley         }
2867b5da9499SMatthew G. Knepley #endif
2868b5da9499SMatthew G. Knepley         supportRef[0] = fStartNew + (f - fStart)*4 + (r+1)%3;
2869b5da9499SMatthew G. Knepley         supportRef[1] = fStartNew + (f - fStart)*4 + 3;
2870b5da9499SMatthew G. Knepley         for (s = 0; s < supportSize; ++s) {
2871b5da9499SMatthew G. Knepley           ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr);
2872b5da9499SMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
2873b5da9499SMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, support[s], &ornt);CHKERRQ(ierr);
2874b5da9499SMatthew G. Knepley           for (c = 0; c < coneSize; ++c) {if (cone[c] == f) break;}
287586f0afeeSMatthew G. Knepley           /* Here we want to determine whether edge newp contains a vertex which is part of the cross-tet edge */
28769ddff745SMatthew G. Knepley           er = GetTetSomethingInverse_Static(ornt[c], r);
2877b5da9499SMatthew G. Knepley           if (er == eint[c]) {
2878b5da9499SMatthew G. Knepley             supportRef[2+intFaces++] = fStartNew + (fEnd - fStart)*4 + (support[s] - cStart)*8 + (c + 2)%4;
2879b5da9499SMatthew G. Knepley           } else {
2880b5da9499SMatthew G. Knepley             supportRef[2+intFaces++] = fStartNew + (fEnd - fStart)*4 + (support[s] - cStart)*8 + fint[(c*3 + er)*2 + 0];
2881b5da9499SMatthew G. Knepley             supportRef[2+intFaces++] = fStartNew + (fEnd - fStart)*4 + (support[s] - cStart)*8 + fint[(c*3 + er)*2 + 1];
2882b5da9499SMatthew G. Knepley           }
2883b5da9499SMatthew G. Knepley         }
2884b5da9499SMatthew G. Knepley         ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
2885b5da9499SMatthew G. Knepley #if 1
2886b5da9499SMatthew G. Knepley         if ((newp < eStartNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eEndNew);
2887b5da9499SMatthew G. Knepley         for (p = 0; p < intFaces; ++p) {
2888b5da9499SMatthew G. Knepley           if ((supportRef[p] < fStartNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", supportRef[p], fStartNew, fEndNew);
2889b5da9499SMatthew G. Knepley         }
2890b5da9499SMatthew G. Knepley #endif
2891b5da9499SMatthew G. Knepley       }
2892b5da9499SMatthew G. Knepley     }
2893b5da9499SMatthew G. Knepley     /* Interior edges have 2 vertices and 4 faces */
2894b5da9499SMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
2895b5da9499SMatthew G. Knepley       const PetscInt  newp = eStartNew + (eEnd - eStart)*2 + (fEnd - fStart)*3 + (c - cStart);
2896b5da9499SMatthew G. Knepley       const PetscInt *cone, *ornt, *fcone;
28974a40f731SMatthew G. Knepley       PetscInt        coneNew[2], supportNew[4], find;
2898b5da9499SMatthew G. Knepley 
2899b5da9499SMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
2900b5da9499SMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr);
2901b5da9499SMatthew G. Knepley       ierr = DMPlexGetCone(dm, cone[0], &fcone);CHKERRQ(ierr);
290242525629SMatthew G. Knepley       find = GetTriEdge_Static(ornt[0], 0);
2903b5da9499SMatthew G. Knepley       coneNew[0] = vStartNew + (vEnd - vStart) + (fcone[find] - eStart);
2904b5da9499SMatthew G. Knepley       ierr = DMPlexGetCone(dm, cone[2], &fcone);CHKERRQ(ierr);
290542525629SMatthew G. Knepley       find = GetTriEdge_Static(ornt[2], 1);
2906b5da9499SMatthew G. Knepley       coneNew[1] = vStartNew + (vEnd - vStart) + (fcone[find] - eStart);
2907b5da9499SMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
2908b5da9499SMatthew G. Knepley #if 1
2909b5da9499SMatthew G. Knepley       if ((newp < eStartNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eEndNew);
2910b5da9499SMatthew G. Knepley       for (p = 0; p < 2; ++p) {
2911b5da9499SMatthew G. Knepley         if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
2912b5da9499SMatthew G. Knepley       }
2913b5da9499SMatthew G. Knepley #endif
2914b5da9499SMatthew G. Knepley       supportNew[0] = fStartNew + (fEnd - fStart)*4 + (c - cStart)*8 + 4;
2915b5da9499SMatthew G. Knepley       supportNew[1] = fStartNew + (fEnd - fStart)*4 + (c - cStart)*8 + 5;
2916b5da9499SMatthew G. Knepley       supportNew[2] = fStartNew + (fEnd - fStart)*4 + (c - cStart)*8 + 6;
2917b5da9499SMatthew G. Knepley       supportNew[3] = fStartNew + (fEnd - fStart)*4 + (c - cStart)*8 + 7;
2918b5da9499SMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
2919b5da9499SMatthew G. Knepley #if 1
2920b5da9499SMatthew G. Knepley       if ((newp < eStartNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eEndNew);
2921b5da9499SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
2922b5da9499SMatthew G. Knepley         if ((supportNew[p] < fStartNew) || (supportNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", supportNew[p], fStartNew, fEndNew);
2923b5da9499SMatthew G. Knepley       }
2924b5da9499SMatthew G. Knepley #endif
2925b5da9499SMatthew G. Knepley     }
2926b5da9499SMatthew G. Knepley     /* Old vertices have identical supports */
2927b5da9499SMatthew G. Knepley     for (v = vStart; v < vEnd; ++v) {
2928b5da9499SMatthew G. Knepley       const PetscInt  newp = vStartNew + (v - vStart);
2929b5da9499SMatthew G. Knepley       const PetscInt *support, *cone;
2930b5da9499SMatthew G. Knepley       PetscInt        size, s;
2931b5da9499SMatthew G. Knepley 
2932b5da9499SMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, v, &size);CHKERRQ(ierr);
2933b5da9499SMatthew G. Knepley       ierr = DMPlexGetSupport(dm, v, &support);CHKERRQ(ierr);
2934b5da9499SMatthew G. Knepley       for (s = 0; s < size; ++s) {
2935b5da9499SMatthew G. Knepley         PetscInt r = 0;
2936b5da9499SMatthew G. Knepley 
2937b5da9499SMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
2938b5da9499SMatthew G. Knepley         if (cone[1] == v) r = 1;
2939b5da9499SMatthew G. Knepley         supportRef[s] = eStartNew + (support[s] - eStart)*2 + r;
2940b5da9499SMatthew G. Knepley       }
2941b5da9499SMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
2942b5da9499SMatthew G. Knepley #if 1
2943b5da9499SMatthew G. Knepley       if ((newp < vStartNew) || (newp >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", newp, vStartNew, vEndNew);
2944b5da9499SMatthew G. Knepley       for (p = 0; p < size; ++p) {
2945b5da9499SMatthew G. Knepley         if ((supportRef[p] < eStartNew) || (supportRef[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", supportRef[p], eStartNew, eEndNew);
2946b5da9499SMatthew G. Knepley       }
2947b5da9499SMatthew G. Knepley #endif
2948b5da9499SMatthew G. Knepley     }
2949b5da9499SMatthew G. Knepley     /* Edge vertices have 2 + face*2 + 0/1 supports */
2950b5da9499SMatthew G. Knepley     for (e = eStart; e < eEnd; ++e) {
2951b5da9499SMatthew G. Knepley       const PetscInt  newp = vStartNew + (vEnd - vStart) + (e - eStart);
2952b5da9499SMatthew G. Knepley       const PetscInt *cone, *support;
2953b5da9499SMatthew G. Knepley       PetscInt       *star = NULL, starSize, cellSize = 0, coneSize, size, s;
2954b5da9499SMatthew G. Knepley 
2955b5da9499SMatthew G. Knepley       ierr          = DMPlexGetSupportSize(dm, e, &size);CHKERRQ(ierr);
2956b5da9499SMatthew G. Knepley       ierr          = DMPlexGetSupport(dm, e, &support);CHKERRQ(ierr);
2957b5da9499SMatthew G. Knepley       supportRef[0] = eStartNew + (e - eStart)*2 + 0;
2958b5da9499SMatthew G. Knepley       supportRef[1] = eStartNew + (e - eStart)*2 + 1;
2959b5da9499SMatthew G. Knepley       for (s = 0; s < size; ++s) {
2960b5da9499SMatthew G. Knepley         PetscInt r = 0;
2961b5da9499SMatthew G. Knepley 
2962b5da9499SMatthew G. Knepley         ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr);
2963b5da9499SMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
2964b5da9499SMatthew G. Knepley         for (r = 0; r < coneSize; ++r) {if (cone[r] == e) break;}
2965b5da9499SMatthew G. Knepley         supportRef[2+s*2+0] = eStartNew + (eEnd - eStart)*2 + (support[s] - fStart)*3 + (r+0)%3;
2966b5da9499SMatthew G. Knepley         supportRef[2+s*2+1] = eStartNew + (eEnd - eStart)*2 + (support[s] - fStart)*3 + (r+2)%3;
2967b5da9499SMatthew G. Knepley       }
2968b5da9499SMatthew G. Knepley       ierr = DMPlexGetTransitiveClosure(dm, e, PETSC_FALSE, &starSize, &star);CHKERRQ(ierr);
2969b5da9499SMatthew G. Knepley       for (s = 0; s < starSize*2; s += 2) {
2970b5da9499SMatthew G. Knepley         const PetscInt *cone, *ornt;
2971b5da9499SMatthew G. Knepley         PetscInt        e01, e23;
2972b5da9499SMatthew G. Knepley 
2973b5da9499SMatthew G. Knepley         if ((star[s] >= cStart) && (star[s] < cEnd)) {
2974b5da9499SMatthew G. Knepley           /* Check edge 0-1 */
2975b5da9499SMatthew G. Knepley           ierr = DMPlexGetCone(dm, star[s], &cone);CHKERRQ(ierr);
2976b5da9499SMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, star[s], &ornt);CHKERRQ(ierr);
2977b5da9499SMatthew G. Knepley           ierr = DMPlexGetCone(dm, cone[0], &cone);CHKERRQ(ierr);
297842525629SMatthew G. Knepley           e01  = cone[GetTriEdge_Static(ornt[0], 0)];
2979b5da9499SMatthew G. Knepley           /* Check edge 2-3 */
2980b5da9499SMatthew G. Knepley           ierr = DMPlexGetCone(dm, star[s], &cone);CHKERRQ(ierr);
2981b5da9499SMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, star[s], &ornt);CHKERRQ(ierr);
298242525629SMatthew G. Knepley           ierr = DMPlexGetCone(dm, cone[2], &cone);CHKERRQ(ierr);
298342525629SMatthew G. Knepley           e23  = cone[GetTriEdge_Static(ornt[2], 1)];
2984b5da9499SMatthew G. Knepley           if ((e01 == e) || (e23 == e)) {supportRef[2+size*2+cellSize++] = eStartNew + (eEnd - eStart)*2 + (fEnd - fStart)*3 + (star[s] - cStart);}
2985b5da9499SMatthew G. Knepley         }
2986b5da9499SMatthew G. Knepley       }
2987b5da9499SMatthew G. Knepley       ierr = DMPlexRestoreTransitiveClosure(dm, e, PETSC_FALSE, &starSize, &star);CHKERRQ(ierr);
2988b5da9499SMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
2989b5da9499SMatthew G. Knepley #if 1
2990b5da9499SMatthew G. Knepley       if ((newp < vStartNew) || (newp >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", newp, vStartNew, vEndNew);
2991b5da9499SMatthew G. Knepley       for (p = 0; p < 2+size*2+cellSize; ++p) {
2992b5da9499SMatthew G. Knepley         if ((supportRef[p] < eStartNew) || (supportRef[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", supportRef[p], eStartNew, eEndNew);
2993b5da9499SMatthew G. Knepley       }
2994b5da9499SMatthew G. Knepley #endif
2995b5da9499SMatthew G. Knepley     }
2996b5da9499SMatthew G. Knepley     ierr = PetscFree(supportRef);CHKERRQ(ierr);
2997b5da9499SMatthew G. Knepley     ierr = DMPlexRestoreFaces_Internal(dm, 3, cStart, NULL, NULL, &faces);CHKERRQ(ierr);
2998b5da9499SMatthew G. Knepley     break;
29999b1a0e7fSLawrence Mitchell   case REFINER_HYBRID_SIMPLEX_3D:
30006ce3c06aSMatthew G. Knepley     ierr = DMPlexGetHybridBounds(rdm, &cMaxNew, &fMaxNew, &eMaxNew, NULL);CHKERRQ(ierr);
30016ce3c06aSMatthew G. Knepley     /* Interior cells have 4 faces: Tet face order is prescribed in DMPlexGetFaces_Internal() */
30026ce3c06aSMatthew G. Knepley     ierr = DMPlexGetRawFaces_Internal(dm, 3, 4, cellInd, NULL, NULL, &faces);CHKERRQ(ierr);
30036ce3c06aSMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
30046ce3c06aSMatthew G. Knepley       const PetscInt  newp = cStartNew + (c - cStart)*8;
30056ce3c06aSMatthew G. Knepley       const PetscInt *cone, *ornt;
30066ce3c06aSMatthew G. Knepley       PetscInt        coneNew[4], orntNew[4];
30076ce3c06aSMatthew G. Knepley 
30086ce3c06aSMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
30096ce3c06aSMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr);
30106ce3c06aSMatthew G. Knepley       /* A tetrahedron: {0, a, c, d} */
30116ce3c06aSMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*4 + GetTriSubface_Static(ornt[0], 0); /* A */
30126ce3c06aSMatthew G. Knepley       orntNew[0] = ornt[0];
30136ce3c06aSMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*4 + GetTriSubface_Static(ornt[1], 0); /* A */
30146ce3c06aSMatthew G. Knepley       orntNew[1] = ornt[1];
30156ce3c06aSMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*4 + GetTriSubface_Static(ornt[2], 0); /* A */
30166ce3c06aSMatthew G. Knepley       orntNew[2] = ornt[2];
30176ce3c06aSMatthew G. Knepley       coneNew[3] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*8 + 0;
30186ce3c06aSMatthew G. Knepley       orntNew[3] = 0;
30196ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+0, coneNew);CHKERRQ(ierr);
30206ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+0, orntNew);CHKERRQ(ierr);
30216ce3c06aSMatthew G. Knepley #if 1
30226ce3c06aSMatthew G. Knepley       if ((newp+0 < cStartNew) || (newp+0 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+0, cStartNew, cMaxNew);
30236ce3c06aSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
30246ce3c06aSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
30256ce3c06aSMatthew G. Knepley       }
30266ce3c06aSMatthew G. Knepley #endif
30276ce3c06aSMatthew G. Knepley       /* B tetrahedron: {a, 1, b, e} */
30286ce3c06aSMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*4 + GetTriSubface_Static(ornt[0], 1); /* B */
30296ce3c06aSMatthew G. Knepley       orntNew[0] = ornt[0];
30306ce3c06aSMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*4 + GetTriSubface_Static(ornt[1], 2); /* C */
30316ce3c06aSMatthew G. Knepley       orntNew[1] = ornt[1];
30326ce3c06aSMatthew G. Knepley       coneNew[2] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*8 + 1;
30336ce3c06aSMatthew G. Knepley       orntNew[2] = 0;
30346ce3c06aSMatthew G. Knepley       coneNew[3] = fStartNew + (cone[3] - fStart)*4 + GetTriSubface_Static(ornt[3], 1); /* B */
30356ce3c06aSMatthew G. Knepley       orntNew[3] = ornt[3];
30366ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+1, coneNew);CHKERRQ(ierr);
30376ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+1, orntNew);CHKERRQ(ierr);
30386ce3c06aSMatthew G. Knepley #if 1
30396ce3c06aSMatthew G. Knepley       if ((newp+1 < cStartNew) || (newp+1 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+1, cStartNew, cMaxNew);
30406ce3c06aSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
30416ce3c06aSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
30426ce3c06aSMatthew G. Knepley       }
30436ce3c06aSMatthew G. Knepley #endif
30446ce3c06aSMatthew G. Knepley       /* C tetrahedron: {c, b, 2, f} */
30456ce3c06aSMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*4 + GetTriSubface_Static(ornt[0], 2); /* C */
30466ce3c06aSMatthew G. Knepley       orntNew[0] = ornt[0];
30476ce3c06aSMatthew G. Knepley       coneNew[1] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*8 + 2;
30486ce3c06aSMatthew G. Knepley       orntNew[1] = 0;
30496ce3c06aSMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*4 + GetTriSubface_Static(ornt[2], 1); /* B */
30506ce3c06aSMatthew G. Knepley       orntNew[2] = ornt[2];
30516ce3c06aSMatthew G. Knepley       coneNew[3] = fStartNew + (cone[3] - fStart)*4 + GetTriSubface_Static(ornt[3], 0); /* A */
30526ce3c06aSMatthew G. Knepley       orntNew[3] = ornt[3];
30536ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+2, coneNew);CHKERRQ(ierr);
30546ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+2, orntNew);CHKERRQ(ierr);
30556ce3c06aSMatthew G. Knepley #if 1
30566ce3c06aSMatthew G. Knepley       if ((newp+2 < cStartNew) || (newp+2 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+2, cStartNew, cMaxNew);
30576ce3c06aSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
30586ce3c06aSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
30596ce3c06aSMatthew G. Knepley       }
30606ce3c06aSMatthew G. Knepley #endif
30616ce3c06aSMatthew G. Knepley       /* D tetrahedron: {d, e, f, 3} */
30626ce3c06aSMatthew G. Knepley       coneNew[0] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*8 + 3;
30636ce3c06aSMatthew G. Knepley       orntNew[0] = 0;
30646ce3c06aSMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*4 + GetTriSubface_Static(ornt[1], 1); /* B */
30656ce3c06aSMatthew G. Knepley       orntNew[1] = ornt[1];
30666ce3c06aSMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*4 + GetTriSubface_Static(ornt[2], 2); /* C */
30676ce3c06aSMatthew G. Knepley       orntNew[2] = ornt[2];
30686ce3c06aSMatthew G. Knepley       coneNew[3] = fStartNew + (cone[3] - fStart)*4 + GetTriSubface_Static(ornt[3], 2); /* C */
30696ce3c06aSMatthew G. Knepley       orntNew[3] = ornt[3];
30706ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+3, coneNew);CHKERRQ(ierr);
30716ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+3, orntNew);CHKERRQ(ierr);
30726ce3c06aSMatthew G. Knepley #if 1
30736ce3c06aSMatthew G. Knepley       if ((newp+3 < cStartNew) || (newp+3 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+3, cStartNew, cMaxNew);
30746ce3c06aSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
30756ce3c06aSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
30766ce3c06aSMatthew G. Knepley       }
30776ce3c06aSMatthew G. Knepley #endif
30786ce3c06aSMatthew G. Knepley       /* A' tetrahedron: {d, a, c, f} */
30796ce3c06aSMatthew G. Knepley       coneNew[0] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*8 + 0;
30806ce3c06aSMatthew G. Knepley       orntNew[0] = -3;
30819ddff745SMatthew G. Knepley       coneNew[1] = fStartNew + (cone[2] - fStart)*4 + 3;
30829ddff745SMatthew G. Knepley       orntNew[1] = ornt[2] < 0 ? -(GetTetSomething_Static(ornt[2], 0)+1) : GetTetSomething_Static(ornt[2], 0);
30839ddff745SMatthew G. Knepley       coneNew[2] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*8 + 5;
30849ddff745SMatthew G. Knepley       orntNew[2] = 0;
30859ddff745SMatthew G. Knepley       coneNew[3] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*8 + 4;
30869ddff745SMatthew G. Knepley       orntNew[3] = 2;
30876ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+4, coneNew);CHKERRQ(ierr);
30886ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+4, orntNew);CHKERRQ(ierr);
30896ce3c06aSMatthew G. Knepley #if 1
30906ce3c06aSMatthew G. Knepley       if ((newp+4 < cStartNew) || (newp+4 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+4, cStartNew, cMaxNew);
30916ce3c06aSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
30926ce3c06aSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
30936ce3c06aSMatthew G. Knepley       }
30946ce3c06aSMatthew G. Knepley #endif
30956ce3c06aSMatthew G. Knepley       /* B' tetrahedron: {e, b, a, f} */
30966ce3c06aSMatthew G. Knepley       coneNew[0] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*8 + 1;
30976ce3c06aSMatthew G. Knepley       orntNew[0] = -3;
30989ddff745SMatthew G. Knepley       coneNew[1] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*8 + 6;
30999ddff745SMatthew G. Knepley       orntNew[1] = 1;
31009ddff745SMatthew G. Knepley       coneNew[2] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*8 + 7;
31016ce3c06aSMatthew G. Knepley       orntNew[2] = 0;
31029ddff745SMatthew G. Knepley       coneNew[3] = fStartNew + (cone[3] - fStart)*4 + 3;
31039ddff745SMatthew G. Knepley       orntNew[3] = ornt[3] < 0 ? -(GetTetSomething_Static(ornt[3], 0)+1) : GetTetSomething_Static(ornt[3], 0);
31046ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+5, coneNew);CHKERRQ(ierr);
31056ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+5, orntNew);CHKERRQ(ierr);
31066ce3c06aSMatthew G. Knepley #if 1
31076ce3c06aSMatthew G. Knepley       if ((newp+5 < cStartNew) || (newp+5 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+5, cStartNew, cMaxNew);
31086ce3c06aSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
31096ce3c06aSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
31106ce3c06aSMatthew G. Knepley       }
31116ce3c06aSMatthew G. Knepley #endif
31126ce3c06aSMatthew G. Knepley       /* C' tetrahedron: {b, f, c, a} */
31136ce3c06aSMatthew G. Knepley       coneNew[0] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*8 + 2;
31146ce3c06aSMatthew G. Knepley       orntNew[0] = -3;
31159ddff745SMatthew G. Knepley       coneNew[1] = fStartNew + (cone[0] - fStart)*4 + 3;
31169ddff745SMatthew G. Knepley       orntNew[1] = ornt[0] < 0 ? -(GetTetSomething_Static(ornt[0], 2)+1) : GetTetSomething_Static(ornt[0], 2);
31179ddff745SMatthew G. Knepley       coneNew[2] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*8 + 5;
31189ddff745SMatthew G. Knepley       orntNew[2] = -3;
31199ddff745SMatthew G. Knepley       coneNew[3] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*8 + 7;
31209ddff745SMatthew G. Knepley       orntNew[3] = -2;
31216ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+6, coneNew);CHKERRQ(ierr);
31226ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+6, orntNew);CHKERRQ(ierr);
31236ce3c06aSMatthew G. Knepley #if 1
31246ce3c06aSMatthew G. Knepley       if ((newp+6 < cStartNew) || (newp+6 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+6, cStartNew, cMaxNew);
31256ce3c06aSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
31266ce3c06aSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
31276ce3c06aSMatthew G. Knepley       }
31286ce3c06aSMatthew G. Knepley #endif
31296ce3c06aSMatthew G. Knepley       /* D' tetrahedron: {f, e, d, a} */
31306ce3c06aSMatthew G. Knepley       coneNew[0] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*8 + 3;
31316ce3c06aSMatthew G. Knepley       orntNew[0] = -3;
31329ddff745SMatthew G. Knepley       coneNew[1] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*8 + 4;
31336ce3c06aSMatthew G. Knepley       orntNew[1] = -3;
31349ddff745SMatthew G. Knepley       coneNew[2] = fStartNew + (cone[1] - fStart)*4 + 3;
31359ddff745SMatthew G. Knepley       orntNew[2] = ornt[1] < 0 ? -(GetTetSomething_Static(ornt[1], 0)+1) : GetTetSomething_Static(ornt[1], 0);
31369ddff745SMatthew G. Knepley       coneNew[3] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*8 + 6;
31379ddff745SMatthew G. Knepley       orntNew[3] = -3;
31386ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+7, coneNew);CHKERRQ(ierr);
31396ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+7, orntNew);CHKERRQ(ierr);
31406ce3c06aSMatthew G. Knepley #if 1
31416ce3c06aSMatthew G. Knepley       if ((newp+7 < cStartNew) || (newp+7 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+7, cStartNew, cMaxNew);
31426ce3c06aSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
31436ce3c06aSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
31446ce3c06aSMatthew G. Knepley       }
31456ce3c06aSMatthew G. Knepley #endif
31466ce3c06aSMatthew G. Knepley     }
31476ce3c06aSMatthew G. Knepley     /* Hybrid cells have 5 faces */
31486ce3c06aSMatthew G. Knepley     for (c = cMax; c < cEnd; ++c) {
31496ce3c06aSMatthew G. Knepley       const PetscInt  newp = cStartNew + (cMax - cStart)*8 + (c - cMax)*4;
3150d3a1cc75SMatthew G. Knepley       const PetscInt *cone, *ornt, *fornt;
31513b61eb6dSMatthew G. Knepley       PetscInt        coneNew[5], orntNew[5], o, of, i;
31526ce3c06aSMatthew G. Knepley 
31536ce3c06aSMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
31546ce3c06aSMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr);
3155d3a1cc75SMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, cone[0], &fornt);CHKERRQ(ierr);
3156084f9c62SMatthew G. Knepley       o = ornt[0] < 0 ? -1 : 1;
31576ce3c06aSMatthew G. Knepley       for (r = 0; r < 3; ++r) {
31586ce3c06aSMatthew G. Knepley         coneNew[0] = fStartNew + (cone[0] - fStart)*4 + GetTriSubface_Static(ornt[0], r);
31596ce3c06aSMatthew G. Knepley         orntNew[0] = ornt[0];
31606ce3c06aSMatthew G. Knepley         coneNew[1] = fStartNew + (cone[1] - fStart)*4 + GetTriSubface_Static(ornt[1], r);
31616ce3c06aSMatthew G. Knepley         orntNew[1] = ornt[1];
3162084f9c62SMatthew G. Knepley         of = fornt[GetTriEdge_Static(ornt[0], r)]       < 0 ? -1 : 1;
31633b61eb6dSMatthew G. Knepley         i  = GetTriEdgeInverse_Static(ornt[0], r)       + 2;
31643b61eb6dSMatthew G. Knepley         coneNew[i] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*8 + (cone[2+GetTriEdge_Static(ornt[0], r)]       - fMax)*2 + (o*of < 0 ? 1 : 0);
31653b61eb6dSMatthew G. Knepley         orntNew[i] = 0;
31663b61eb6dSMatthew G. Knepley         i  = GetTriEdgeInverse_Static(ornt[0], (r+1)%3) + 2;
31673b61eb6dSMatthew G. Knepley         coneNew[i] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*8 + (fEnd - fMax)*2 + (c - cMax)*3 + GetTriSubface_Static(ornt[0], r);
31683b61eb6dSMatthew G. Knepley         orntNew[i] = 0;
31693b61eb6dSMatthew G. Knepley         of = fornt[GetTriEdge_Static(ornt[0], (r+2)%3)] < 0 ? -1 : 1;
31703b61eb6dSMatthew G. Knepley         i  = GetTriEdgeInverse_Static(ornt[0], (r+2)%3) + 2;
31713b61eb6dSMatthew G. Knepley         coneNew[i] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*8 + (cone[2+GetTriEdge_Static(ornt[0], (r+2)%3)] - fMax)*2 + (o*of < 0 ? 0 : 1);
31723b61eb6dSMatthew G. Knepley         orntNew[i] = 0;
31736ce3c06aSMatthew G. Knepley         ierr = DMPlexSetCone(rdm, newp+r, coneNew);CHKERRQ(ierr);
31746ce3c06aSMatthew G. Knepley         ierr = DMPlexSetConeOrientation(rdm, newp+r, orntNew);CHKERRQ(ierr);
31756ce3c06aSMatthew G. Knepley #if 1
31766ce3c06aSMatthew G. Knepley         if ((newp+r < cMaxNew) || (newp+r >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid cell [%d, %d)", newp+r, cMaxNew, cEndNew);
31776ce3c06aSMatthew G. Knepley         for (p = 0; p < 2; ++p) {
31786ce3c06aSMatthew G. Knepley           if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
31796ce3c06aSMatthew G. Knepley         }
31806ce3c06aSMatthew G. Knepley         for (p = 2; p < 5; ++p) {
31816ce3c06aSMatthew G. Knepley           if ((coneNew[p] < fMaxNew)   || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid face [%d, %d)", coneNew[p], fMaxNew, fEndNew);
31826ce3c06aSMatthew G. Knepley         }
31836ce3c06aSMatthew G. Knepley #endif
31846ce3c06aSMatthew G. Knepley       }
31856ce3c06aSMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*4 + 3;
31866ce3c06aSMatthew G. Knepley       orntNew[0] = 0;
31876ce3c06aSMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*4 + 3;
31886ce3c06aSMatthew G. Knepley       orntNew[1] = 0;
31893b61eb6dSMatthew G. Knepley       coneNew[2] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*8 + (fEnd - fMax)*2 + (c - cMax)*3 + 1;
31906ce3c06aSMatthew G. Knepley       orntNew[2] = 0;
31913b61eb6dSMatthew G. Knepley       coneNew[3] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*8 + (fEnd - fMax)*2 + (c - cMax)*3 + 2;
31926ce3c06aSMatthew G. Knepley       orntNew[3] = 0;
31933b61eb6dSMatthew G. Knepley       coneNew[4] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*8 + (fEnd - fMax)*2 + (c - cMax)*3 + 0;
31946ce3c06aSMatthew G. Knepley       orntNew[4] = 0;
31956ce3c06aSMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp+3, coneNew);CHKERRQ(ierr);
31966ce3c06aSMatthew G. Knepley       ierr = DMPlexSetConeOrientation(rdm, newp+3, orntNew);CHKERRQ(ierr);
31976ce3c06aSMatthew G. Knepley #if 1
31986ce3c06aSMatthew G. Knepley       if ((newp+3 < cMaxNew) || (newp+3 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid cell [%d, %d)", newp+3, cMaxNew, cEndNew);
31996ce3c06aSMatthew G. Knepley       for (p = 0; p < 2; ++p) {
32006ce3c06aSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
32016ce3c06aSMatthew G. Knepley       }
32026ce3c06aSMatthew G. Knepley       for (p = 2; p < 5; ++p) {
32036ce3c06aSMatthew G. Knepley         if ((coneNew[p] < fMaxNew)   || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid face [%d, %d)", coneNew[p], fMaxNew, fEndNew);
32046ce3c06aSMatthew G. Knepley       }
32056ce3c06aSMatthew G. Knepley #endif
32066ce3c06aSMatthew G. Knepley     }
32076ce3c06aSMatthew G. Knepley     /* Split faces have 3 edges and the same cells as the parent */
32086ce3c06aSMatthew G. Knepley     ierr = DMPlexGetMaxSizes(dm, NULL, &maxSupportSize);CHKERRQ(ierr);
3209854ce69bSBarry Smith     ierr = PetscMalloc1(2 + maxSupportSize*2, &supportRef);CHKERRQ(ierr);
32106ce3c06aSMatthew G. Knepley     for (f = fStart; f < fMax; ++f) {
32116ce3c06aSMatthew G. Knepley       const PetscInt  newp = fStartNew + (f - fStart)*4;
32126ce3c06aSMatthew G. Knepley       const PetscInt *cone, *ornt, *support;
32136ce3c06aSMatthew G. Knepley       PetscInt        coneNew[3], orntNew[3], coneSize, supportSize, s;
32146ce3c06aSMatthew G. Knepley 
32156ce3c06aSMatthew G. Knepley       ierr = DMPlexGetCone(dm, f, &cone);CHKERRQ(ierr);
32166ce3c06aSMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, f, &ornt);CHKERRQ(ierr);
32176ce3c06aSMatthew G. Knepley       /* A triangle */
32186ce3c06aSMatthew G. Knepley       coneNew[0] = eStartNew + (cone[0] - eStart)*2 + (ornt[0] < 0 ? 1 : 0);
32196ce3c06aSMatthew G. Knepley       orntNew[0] = ornt[0];
32206ce3c06aSMatthew G. Knepley       coneNew[1] = eStartNew + (eMax    - eStart)*2 + (f - fStart)*3 + 2;
32216ce3c06aSMatthew G. Knepley       orntNew[1] = -2;
32226ce3c06aSMatthew G. Knepley       coneNew[2] = eStartNew + (cone[2] - eStart)*2 + (ornt[2] < 0 ? 0 : 1);
32236ce3c06aSMatthew G. Knepley       orntNew[2] = ornt[2];
32246ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+0, coneNew);CHKERRQ(ierr);
32256ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+0, orntNew);CHKERRQ(ierr);
32266ce3c06aSMatthew G. Knepley #if 1
32276ce3c06aSMatthew G. Knepley       if ((newp+0 < fStartNew) || (newp+0 >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp+0, fStartNew, fMaxNew);
32286ce3c06aSMatthew G. Knepley       for (p = 0; p < 3; ++p) {
32296ce3c06aSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
32306ce3c06aSMatthew G. Knepley       }
32316ce3c06aSMatthew G. Knepley #endif
32326ce3c06aSMatthew G. Knepley       /* B triangle */
32336ce3c06aSMatthew G. Knepley       coneNew[0] = eStartNew + (cone[0] - eStart)*2 + (ornt[0] < 0 ? 0 : 1);
32346ce3c06aSMatthew G. Knepley       orntNew[0] = ornt[0];
32356ce3c06aSMatthew G. Knepley       coneNew[1] = eStartNew + (cone[1] - eStart)*2 + (ornt[1] < 0 ? 1 : 0);
32366ce3c06aSMatthew G. Knepley       orntNew[1] = ornt[1];
32376ce3c06aSMatthew G. Knepley       coneNew[2] = eStartNew + (eMax    - eStart)*2 + (f - fStart)*3 + 0;
32386ce3c06aSMatthew G. Knepley       orntNew[2] = -2;
32396ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+1, coneNew);CHKERRQ(ierr);
32406ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+1, orntNew);CHKERRQ(ierr);
32416ce3c06aSMatthew G. Knepley #if 1
32426ce3c06aSMatthew G. Knepley       if ((newp+1 < fStartNew) || (newp+1 >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp+1, fStartNew, fMaxNew);
32436ce3c06aSMatthew G. Knepley       for (p = 0; p < 3; ++p) {
32446ce3c06aSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
32456ce3c06aSMatthew G. Knepley       }
32466ce3c06aSMatthew G. Knepley #endif
32476ce3c06aSMatthew G. Knepley       /* C triangle */
32486ce3c06aSMatthew G. Knepley       coneNew[0] = eStartNew + (eMax    - eStart)*2 + (f - fStart)*3 + 1;
32496ce3c06aSMatthew G. Knepley       orntNew[0] = -2;
32506ce3c06aSMatthew G. Knepley       coneNew[1] = eStartNew + (cone[1] - eStart)*2 + (ornt[1] < 0 ? 0 : 1);
32516ce3c06aSMatthew G. Knepley       orntNew[1] = ornt[1];
32526ce3c06aSMatthew G. Knepley       coneNew[2] = eStartNew + (cone[2] - eStart)*2 + (ornt[2] < 0 ? 1 : 0);
32536ce3c06aSMatthew G. Knepley       orntNew[2] = ornt[2];
32546ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+2, coneNew);CHKERRQ(ierr);
32556ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+2, orntNew);CHKERRQ(ierr);
32566ce3c06aSMatthew G. Knepley #if 1
32576ce3c06aSMatthew G. Knepley       if ((newp+2 < fStartNew) || (newp+2 >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp+2, fStartNew, fMaxNew);
32586ce3c06aSMatthew G. Knepley       for (p = 0; p < 3; ++p) {
32596ce3c06aSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
32606ce3c06aSMatthew G. Knepley       }
32616ce3c06aSMatthew G. Knepley #endif
32626ce3c06aSMatthew G. Knepley       /* D triangle */
32636ce3c06aSMatthew G. Knepley       coneNew[0] = eStartNew + (eMax    - eStart)*2 + (f - fStart)*3 + 0;
32646ce3c06aSMatthew G. Knepley       orntNew[0] = 0;
32656ce3c06aSMatthew G. Knepley       coneNew[1] = eStartNew + (eMax    - eStart)*2 + (f - fStart)*3 + 1;
32666ce3c06aSMatthew G. Knepley       orntNew[1] = 0;
32676ce3c06aSMatthew G. Knepley       coneNew[2] = eStartNew + (eMax    - eStart)*2 + (f - fStart)*3 + 2;
32686ce3c06aSMatthew G. Knepley       orntNew[2] = 0;
32696ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+3, coneNew);CHKERRQ(ierr);
32706ce3c06aSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+3, orntNew);CHKERRQ(ierr);
32716ce3c06aSMatthew G. Knepley #if 1
32726ce3c06aSMatthew G. Knepley       if ((newp+3 < fStartNew) || (newp+3 >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp+3, fStartNew, fMaxNew);
32736ce3c06aSMatthew G. Knepley       for (p = 0; p < 3; ++p) {
32746ce3c06aSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
32756ce3c06aSMatthew G. Knepley       }
32766ce3c06aSMatthew G. Knepley #endif
32776ce3c06aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, f, &supportSize);CHKERRQ(ierr);
32786ce3c06aSMatthew G. Knepley       ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
32796ce3c06aSMatthew G. Knepley       for (r = 0; r < 4; ++r) {
32806ce3c06aSMatthew G. Knepley         for (s = 0; s < supportSize; ++s) {
32819ddff745SMatthew G. Knepley           PetscInt subf;
32826ce3c06aSMatthew G. Knepley           ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr);
32836ce3c06aSMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
32846ce3c06aSMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, support[s], &ornt);CHKERRQ(ierr);
32856ce3c06aSMatthew G. Knepley           for (c = 0; c < coneSize; ++c) {
32866ce3c06aSMatthew G. Knepley             if (cone[c] == f) break;
32876ce3c06aSMatthew G. Knepley           }
32889ddff745SMatthew G. Knepley           subf = GetTriSubfaceInverse_Static(ornt[c], r);
32896ce3c06aSMatthew G. Knepley           if (support[s] < cMax) {
32909ddff745SMatthew G. Knepley             supportRef[s] = cStartNew + (support[s] - cStart)*8 + (r==3 ? (c+2)%4 + 4 : faces[c*3+subf]);
32916ce3c06aSMatthew G. Knepley           } else {
32929ddff745SMatthew G. Knepley             supportRef[s] = cStartNew + (cMax - cStart)*8 + (support[s] - cMax)*4 + (r==3 ? r : subf);
32936ce3c06aSMatthew G. Knepley           }
32946ce3c06aSMatthew G. Knepley         }
32956ce3c06aSMatthew G. Knepley         ierr = DMPlexSetSupport(rdm, newp+r, supportRef);CHKERRQ(ierr);
32966ce3c06aSMatthew G. Knepley #if 1
32979ddff745SMatthew G. Knepley         if ((newp+r < fStartNew) || (newp+r >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp+r, fStartNew, fMaxNew);
32986ce3c06aSMatthew G. Knepley         for (p = 0; p < supportSize; ++p) {
32996ce3c06aSMatthew G. Knepley           if ((supportRef[p] < cStartNew) || (supportRef[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior or hybrid cell [%d, %d)", supportRef[p], cStartNew, cEndNew);
33006ce3c06aSMatthew G. Knepley         }
33016ce3c06aSMatthew G. Knepley #endif
33026ce3c06aSMatthew G. Knepley       }
33036ce3c06aSMatthew G. Knepley     }
33046ce3c06aSMatthew G. Knepley     /* Interior cell faces have 3 edges and 2 cells */
33056ce3c06aSMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
33066ce3c06aSMatthew G. Knepley       PetscInt        newp = fStartNew + (fMax - fStart)*4 + (c - cStart)*8;
33076ce3c06aSMatthew G. Knepley       const PetscInt *cone, *ornt;
33086ce3c06aSMatthew G. Knepley       PetscInt        coneNew[3], orntNew[3];
33096ce3c06aSMatthew G. Knepley       PetscInt        supportNew[2];
33106ce3c06aSMatthew G. Knepley 
33116ce3c06aSMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
33126ce3c06aSMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr);
33136ce3c06aSMatthew G. Knepley       /* Face A: {c, a, d} */
33149ddff745SMatthew G. Knepley       coneNew[0] = eStartNew + (eMax - eStart)*2 + (cone[0] - fStart)*3 + GetTetSomething_Static(ornt[0], 2);
33156ce3c06aSMatthew G. Knepley       orntNew[0] = ornt[0] < 0 ? -2 : 0;
33169ddff745SMatthew G. Knepley       coneNew[1] = eStartNew + (eMax - eStart)*2 + (cone[1] - fStart)*3 + GetTetSomething_Static(ornt[1], 2);
33176ce3c06aSMatthew G. Knepley       orntNew[1] = ornt[1] < 0 ? -2 : 0;
33189ddff745SMatthew G. Knepley       coneNew[2] = eStartNew + (eMax - eStart)*2 + (cone[2] - fStart)*3 + GetTetSomething_Static(ornt[2], 2);
33196ce3c06aSMatthew G. Knepley       orntNew[2] = ornt[2] < 0 ? -2 : 0;
33206ce3c06aSMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
33216ce3c06aSMatthew G. Knepley       ierr = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
33226ce3c06aSMatthew G. Knepley #if 1
33236ce3c06aSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
33246ce3c06aSMatthew G. Knepley       for (p = 0; p < 3; ++p) {
33256ce3c06aSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
33266ce3c06aSMatthew G. Knepley       }
33276ce3c06aSMatthew G. Knepley #endif
33286ce3c06aSMatthew G. Knepley       supportNew[0] = (c - cStart)*8 + 0;
33296ce3c06aSMatthew G. Knepley       supportNew[1] = (c - cStart)*8 + 0+4;
33306ce3c06aSMatthew G. Knepley       ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
33316ce3c06aSMatthew G. Knepley #if 1
33326ce3c06aSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
33336ce3c06aSMatthew G. Knepley       for (p = 0; p < 2; ++p) {
33346ce3c06aSMatthew G. Knepley         if ((supportNew[p] < cStartNew) || (supportNew[p] >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cMaxNew);
33356ce3c06aSMatthew G. Knepley       }
33366ce3c06aSMatthew G. Knepley #endif
33376ce3c06aSMatthew G. Knepley       ++newp;
33386ce3c06aSMatthew G. Knepley       /* Face B: {a, b, e} */
33399ddff745SMatthew G. Knepley       coneNew[0] = eStartNew + (eMax - eStart)*2 + (cone[0] - fStart)*3 + GetTetSomething_Static(ornt[0], 0);
33406ce3c06aSMatthew G. Knepley       orntNew[0] = ornt[0] < 0 ? -2 : 0;
33419ddff745SMatthew G. Knepley       coneNew[1] = eStartNew + (eMax - eStart)*2 + (cone[3] - fStart)*3 + GetTetSomething_Static(ornt[3], 0);
33426ce3c06aSMatthew G. Knepley       orntNew[1] = ornt[3] < 0 ? -2 : 0;
33439ddff745SMatthew G. Knepley       coneNew[2] = eStartNew + (eMax - eStart)*2 + (cone[1] - fStart)*3 + GetTetSomething_Static(ornt[1], 1);
33446ce3c06aSMatthew G. Knepley       orntNew[2] = ornt[1] < 0 ? -2 : 0;
33456ce3c06aSMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
33466ce3c06aSMatthew G. Knepley       ierr = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
33476ce3c06aSMatthew G. Knepley #if 1
33486ce3c06aSMatthew G. Knepley       if ((newp+1 < fStartNew) || (newp+1 >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp+1, fStartNew, fMaxNew);
33496ce3c06aSMatthew G. Knepley       for (p = 0; p < 3; ++p) {
33506ce3c06aSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
33516ce3c06aSMatthew G. Knepley       }
33526ce3c06aSMatthew G. Knepley #endif
33536ce3c06aSMatthew G. Knepley       supportNew[0] = (c - cStart)*8 + 1;
33546ce3c06aSMatthew G. Knepley       supportNew[1] = (c - cStart)*8 + 1+4;
33556ce3c06aSMatthew G. Knepley       ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
33566ce3c06aSMatthew G. Knepley #if 1
33576ce3c06aSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
33586ce3c06aSMatthew G. Knepley       for (p = 0; p < 2; ++p) {
33596ce3c06aSMatthew G. Knepley         if ((supportNew[p] < cStartNew) || (supportNew[p] >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cMaxNew);
33606ce3c06aSMatthew G. Knepley       }
33616ce3c06aSMatthew G. Knepley #endif
33626ce3c06aSMatthew G. Knepley       ++newp;
33636ce3c06aSMatthew G. Knepley       /* Face C: {c, f, b} */
33649ddff745SMatthew G. Knepley       coneNew[0] = eStartNew + (eMax - eStart)*2 + (cone[2] - fStart)*3 + GetTetSomething_Static(ornt[2], 0);
33656ce3c06aSMatthew G. Knepley       orntNew[0] = ornt[2] < 0 ? -2 : 0;
33669ddff745SMatthew G. Knepley       coneNew[1] = eStartNew + (eMax - eStart)*2 + (cone[3] - fStart)*3 + GetTetSomething_Static(ornt[3], 2);
33676ce3c06aSMatthew G. Knepley       orntNew[1] = ornt[3] < 0 ? -2 : 0;
33689ddff745SMatthew G. Knepley       coneNew[2] = eStartNew + (eMax - eStart)*2 + (cone[0] - fStart)*3 + GetTetSomething_Static(ornt[0], 1);
33696ce3c06aSMatthew G. Knepley       orntNew[2] = ornt[0] < 0 ? -2 : 0;
33706ce3c06aSMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
33716ce3c06aSMatthew G. Knepley       ierr = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
33726ce3c06aSMatthew G. Knepley #if 1
33736ce3c06aSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
33746ce3c06aSMatthew G. Knepley       for (p = 0; p < 3; ++p) {
33756ce3c06aSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
33766ce3c06aSMatthew G. Knepley       }
33776ce3c06aSMatthew G. Knepley #endif
33786ce3c06aSMatthew G. Knepley       supportNew[0] = (c - cStart)*8 + 2;
33796ce3c06aSMatthew G. Knepley       supportNew[1] = (c - cStart)*8 + 2+4;
33806ce3c06aSMatthew G. Knepley       ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
33816ce3c06aSMatthew G. Knepley #if 1
33826ce3c06aSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
33836ce3c06aSMatthew G. Knepley       for (p = 0; p < 2; ++p) {
33846ce3c06aSMatthew G. Knepley         if ((supportNew[p] < cStartNew) || (supportNew[p] >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cMaxNew);
33856ce3c06aSMatthew G. Knepley       }
33866ce3c06aSMatthew G. Knepley #endif
33876ce3c06aSMatthew G. Knepley       ++newp;
33886ce3c06aSMatthew G. Knepley       /* Face D: {d, e, f} */
33899ddff745SMatthew G. Knepley       coneNew[0] = eStartNew + (eMax - eStart)*2 + (cone[1] - fStart)*3 + GetTetSomething_Static(ornt[1], 0);
33906ce3c06aSMatthew G. Knepley       orntNew[0] = ornt[1] < 0 ? -2 : 0;
33919ddff745SMatthew G. Knepley       coneNew[1] = eStartNew + (eMax - eStart)*2 + (cone[3] - fStart)*3 + GetTetSomething_Static(ornt[3], 1);
33926ce3c06aSMatthew G. Knepley       orntNew[1] = ornt[3] < 0 ? -2 : 0;
33939ddff745SMatthew G. Knepley       coneNew[2] = eStartNew + (eMax - eStart)*2 + (cone[2] - fStart)*3 + GetTetSomething_Static(ornt[2], 1);
33946ce3c06aSMatthew G. Knepley       orntNew[2] = ornt[2] < 0 ? -2 : 0;
33956ce3c06aSMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
33966ce3c06aSMatthew G. Knepley       ierr = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
33976ce3c06aSMatthew G. Knepley #if 1
33986ce3c06aSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
33996ce3c06aSMatthew G. Knepley       for (p = 0; p < 3; ++p) {
34006ce3c06aSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
34016ce3c06aSMatthew G. Knepley       }
34026ce3c06aSMatthew G. Knepley #endif
34036ce3c06aSMatthew G. Knepley       supportNew[0] = (c - cStart)*8 + 3;
34046ce3c06aSMatthew G. Knepley       supportNew[1] = (c - cStart)*8 + 3+4;
34056ce3c06aSMatthew G. Knepley       ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
34066ce3c06aSMatthew G. Knepley #if 1
34076ce3c06aSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
34086ce3c06aSMatthew G. Knepley       for (p = 0; p < 2; ++p) {
34096ce3c06aSMatthew G. Knepley         if ((supportNew[p] < cStartNew) || (supportNew[p] >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cMaxNew);
34106ce3c06aSMatthew G. Knepley       }
34116ce3c06aSMatthew G. Knepley #endif
34126ce3c06aSMatthew G. Knepley       ++newp;
34136ce3c06aSMatthew G. Knepley       /* Face E: {d, f, a} */
34149ddff745SMatthew G. Knepley       coneNew[0] = eStartNew + (eMax - eStart)*2 + (cone[2] - fStart)*3 + GetTetSomething_Static(ornt[2], 1);
34156ce3c06aSMatthew G. Knepley       orntNew[0] = ornt[2] < 0 ? 0 : -2;
34166ce3c06aSMatthew G. Knepley       coneNew[1] = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*3 + (c - cStart);
34179ddff745SMatthew G. Knepley       orntNew[1] = -2;
34189ddff745SMatthew G. Knepley       coneNew[2] = eStartNew + (eMax - eStart)*2 + (cone[1] - fStart)*3 + GetTetSomething_Static(ornt[1], 2);
34196ce3c06aSMatthew G. Knepley       orntNew[2] = ornt[1] < 0 ? -2 : 0;
34206ce3c06aSMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
34216ce3c06aSMatthew G. Knepley       ierr = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
34226ce3c06aSMatthew G. Knepley #if 1
34236ce3c06aSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
34246ce3c06aSMatthew G. Knepley       for (p = 0; p < 3; ++p) {
34256ce3c06aSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
34266ce3c06aSMatthew G. Knepley       }
34276ce3c06aSMatthew G. Knepley #endif
34286ce3c06aSMatthew G. Knepley       supportNew[0] = (c - cStart)*8 + 0+4;
34296ce3c06aSMatthew G. Knepley       supportNew[1] = (c - cStart)*8 + 3+4;
34306ce3c06aSMatthew G. Knepley       ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
34316ce3c06aSMatthew G. Knepley #if 1
34326ce3c06aSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
34336ce3c06aSMatthew G. Knepley       for (p = 0; p < 2; ++p) {
34346ce3c06aSMatthew G. Knepley         if ((supportNew[p] < cStartNew) || (supportNew[p] >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cMaxNew);
34356ce3c06aSMatthew G. Knepley       }
34366ce3c06aSMatthew G. Knepley #endif
34376ce3c06aSMatthew G. Knepley       ++newp;
34386ce3c06aSMatthew G. Knepley       /* Face F: {c, a, f} */
34399ddff745SMatthew G. Knepley       coneNew[0] = eStartNew + (eMax - eStart)*2 + (cone[0] - fStart)*3 + GetTetSomething_Static(ornt[0], 2);
34406ce3c06aSMatthew G. Knepley       orntNew[0] = ornt[0] < 0 ? -2 : 0;
34416ce3c06aSMatthew G. Knepley       coneNew[1] = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*3 + (c - cStart);
34429ddff745SMatthew G. Knepley       orntNew[1] = 0;
34439ddff745SMatthew G. Knepley       coneNew[2] = eStartNew + (eMax - eStart)*2 + (cone[2] - fStart)*3 + GetTetSomething_Static(ornt[2], 0);
34449ddff745SMatthew G. Knepley       orntNew[2] = ornt[2] < 0 ? 0 : -2;
34456ce3c06aSMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
34466ce3c06aSMatthew G. Knepley       ierr = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
34476ce3c06aSMatthew G. Knepley #if 1
34486ce3c06aSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
34496ce3c06aSMatthew G. Knepley       for (p = 0; p < 3; ++p) {
34506ce3c06aSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
34516ce3c06aSMatthew G. Knepley       }
34526ce3c06aSMatthew G. Knepley #endif
34536ce3c06aSMatthew G. Knepley       supportNew[0] = (c - cStart)*8 + 0+4;
34546ce3c06aSMatthew G. Knepley       supportNew[1] = (c - cStart)*8 + 2+4;
34556ce3c06aSMatthew G. Knepley       ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
34566ce3c06aSMatthew G. Knepley #if 1
34576ce3c06aSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
34586ce3c06aSMatthew G. Knepley       for (p = 0; p < 2; ++p) {
34596ce3c06aSMatthew G. Knepley         if ((supportNew[p] < cStartNew) || (supportNew[p] >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cMaxNew);
34606ce3c06aSMatthew G. Knepley       }
34616ce3c06aSMatthew G. Knepley #endif
34626ce3c06aSMatthew G. Knepley       ++newp;
34636ce3c06aSMatthew G. Knepley       /* Face G: {e, a, f} */
34649ddff745SMatthew G. Knepley       coneNew[0] = eStartNew + (eMax - eStart)*2 + (cone[1] - fStart)*3 + GetTetSomething_Static(ornt[1], 1);
34656ce3c06aSMatthew G. Knepley       orntNew[0] = ornt[1] < 0 ? -2 : 0;
34666ce3c06aSMatthew G. Knepley       coneNew[1] = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*3 + (c - cStart);
34679ddff745SMatthew G. Knepley       orntNew[1] = 0;
34689ddff745SMatthew G. Knepley       coneNew[2] = eStartNew + (eMax - eStart)*2 + (cone[3] - fStart)*3 + GetTetSomething_Static(ornt[3], 1);
34696ce3c06aSMatthew G. Knepley       orntNew[2] = ornt[3] < 0 ? 0 : -2;
34706ce3c06aSMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
34716ce3c06aSMatthew G. Knepley       ierr = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
34726ce3c06aSMatthew G. Knepley #if 1
34736ce3c06aSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
34746ce3c06aSMatthew G. Knepley       for (p = 0; p < 3; ++p) {
34756ce3c06aSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
34766ce3c06aSMatthew G. Knepley       }
34776ce3c06aSMatthew G. Knepley #endif
34786ce3c06aSMatthew G. Knepley       supportNew[0] = (c - cStart)*8 + 1+4;
34796ce3c06aSMatthew G. Knepley       supportNew[1] = (c - cStart)*8 + 3+4;
34806ce3c06aSMatthew G. Knepley       ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
34816ce3c06aSMatthew G. Knepley #if 1
34826ce3c06aSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
34836ce3c06aSMatthew G. Knepley       for (p = 0; p < 2; ++p) {
34846ce3c06aSMatthew G. Knepley         if ((supportNew[p] < cStartNew) || (supportNew[p] >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cMaxNew);
34856ce3c06aSMatthew G. Knepley       }
34866ce3c06aSMatthew G. Knepley #endif
34876ce3c06aSMatthew G. Knepley       ++newp;
34886ce3c06aSMatthew G. Knepley       /* Face H: {a, b, f} */
34899ddff745SMatthew G. Knepley       coneNew[0] = eStartNew + (eMax - eStart)*2 + (cone[0] - fStart)*3 + GetTetSomething_Static(ornt[0], 0);
34906ce3c06aSMatthew G. Knepley       orntNew[0] = ornt[0] < 0 ? -2 : 0;
34919ddff745SMatthew G. Knepley       coneNew[1] = eStartNew + (eMax - eStart)*2 + (cone[3] - fStart)*3 + GetTetSomething_Static(ornt[3], 2);
34926ce3c06aSMatthew G. Knepley       orntNew[1] = ornt[3] < 0 ? 0 : -2;
34936ce3c06aSMatthew G. Knepley       coneNew[2] = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*3 + (c - cStart);
34949ddff745SMatthew G. Knepley       orntNew[2] = -2;
34956ce3c06aSMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
34966ce3c06aSMatthew G. Knepley       ierr = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
34976ce3c06aSMatthew G. Knepley #if 1
34986ce3c06aSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
34996ce3c06aSMatthew G. Knepley       for (p = 0; p < 3; ++p) {
35006ce3c06aSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
35016ce3c06aSMatthew G. Knepley       }
35026ce3c06aSMatthew G. Knepley #endif
35036ce3c06aSMatthew G. Knepley       supportNew[0] = (c - cStart)*8 + 1+4;
35046ce3c06aSMatthew G. Knepley       supportNew[1] = (c - cStart)*8 + 2+4;
35056ce3c06aSMatthew G. Knepley       ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
35066ce3c06aSMatthew G. Knepley #if 1
35076ce3c06aSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
35086ce3c06aSMatthew G. Knepley       for (p = 0; p < 2; ++p) {
35096ce3c06aSMatthew G. Knepley         if ((supportNew[p] < cStartNew) || (supportNew[p] >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cMaxNew);
35106ce3c06aSMatthew G. Knepley       }
35116ce3c06aSMatthew G. Knepley #endif
35126ce3c06aSMatthew G. Knepley       ++newp;
35136ce3c06aSMatthew G. Knepley     }
35146ce3c06aSMatthew G. Knepley     /* Hybrid split faces have 4 edges and same cells */
35156ce3c06aSMatthew G. Knepley     for (f = fMax; f < fEnd; ++f) {
35166ce3c06aSMatthew G. Knepley       const PetscInt *cone, *ornt, *support;
35176ce3c06aSMatthew G. Knepley       PetscInt        coneNew[4], orntNew[4];
35186ce3c06aSMatthew G. Knepley       PetscInt        supportNew[2], size, s, c;
35196ce3c06aSMatthew G. Knepley 
35206ce3c06aSMatthew G. Knepley       ierr = DMPlexGetCone(dm, f, &cone);CHKERRQ(ierr);
35216ce3c06aSMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, f, &ornt);CHKERRQ(ierr);
35226ce3c06aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
35236ce3c06aSMatthew G. Knepley       ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
35246ce3c06aSMatthew G. Knepley       for (r = 0; r < 2; ++r) {
35256ce3c06aSMatthew G. Knepley         const PetscInt newp = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*8 + (f - fMax)*2 + r;
35266ce3c06aSMatthew G. Knepley 
35276ce3c06aSMatthew G. Knepley         coneNew[0]   = eStartNew + (cone[0] - eStart)*2 + (ornt[0] < 0 ? 1-r : r);
35286ce3c06aSMatthew G. Knepley         orntNew[0]   = ornt[0];
35296ce3c06aSMatthew G. Knepley         coneNew[1]   = eStartNew + (cone[1] - eStart)*2 + (ornt[1] < 0 ? 1-r : r);
35306ce3c06aSMatthew G. Knepley         orntNew[1]   = ornt[1];
35316ce3c06aSMatthew G. Knepley         coneNew[2+r] = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*3 + (cMax - cStart) + (cone[2+r] - eMax);
35326ce3c06aSMatthew G. Knepley         orntNew[2+r] = 0;
35336ce3c06aSMatthew G. Knepley         coneNew[3-r] = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*3 + (cMax - cStart) + (eEnd      - eMax) + (f - fMax);
35346ce3c06aSMatthew G. Knepley         orntNew[3-r] = 0;
35356ce3c06aSMatthew G. Knepley         ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
35366ce3c06aSMatthew G. Knepley         ierr = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
35376ce3c06aSMatthew G. Knepley #if 1
35386ce3c06aSMatthew G. Knepley         if ((newp < fMaxNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid face [%d, %d)", newp, fMaxNew, fEndNew);
35396ce3c06aSMatthew G. Knepley         for (p = 0; p < 2; ++p) {
35406ce3c06aSMatthew G. Knepley           if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
35416ce3c06aSMatthew G. Knepley         }
35426ce3c06aSMatthew G. Knepley         for (p = 2; p < 4; ++p) {
35436ce3c06aSMatthew G. Knepley           if ((coneNew[p] < eMaxNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid edge [%d, %d)", coneNew[p], eMaxNew, eEndNew);
35446ce3c06aSMatthew G. Knepley         }
35456ce3c06aSMatthew G. Knepley #endif
35466ce3c06aSMatthew G. Knepley         for (s = 0; s < size; ++s) {
3547d3a1cc75SMatthew G. Knepley           const PetscInt *coneCell, *orntCell, *fornt;
3548084f9c62SMatthew G. Knepley           PetscInt        o, of;
35496ce3c06aSMatthew G. Knepley 
35506ce3c06aSMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &coneCell);CHKERRQ(ierr);
35516ce3c06aSMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, support[s], &orntCell);CHKERRQ(ierr);
3552084f9c62SMatthew G. Knepley           o = orntCell[0] < 0 ? -1 : 1;
35536ce3c06aSMatthew G. Knepley           for (c = 2; c < 5; ++c) if (coneCell[c] == f) break;
35546ce3c06aSMatthew G. Knepley           if (c >= 5) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Could not find face %d in cone of cell %d", f, support[s]);
3555d3a1cc75SMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, coneCell[0], &fornt);CHKERRQ(ierr);
3556084f9c62SMatthew G. Knepley           of = fornt[c-2] < 0 ? -1 : 1;
3557084f9c62SMatthew G. Knepley           supportNew[s] = cStartNew + (cMax - cStart)*8 + (support[s] - cMax)*4 + (GetTriEdgeInverse_Static(orntCell[0], c-2) + (o*of < 0 ? 1-r : r))%3;
35586ce3c06aSMatthew G. Knepley         }
35596ce3c06aSMatthew G. Knepley         ierr = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
35606ce3c06aSMatthew G. Knepley #if 1
35616ce3c06aSMatthew G. Knepley         if ((newp < fMaxNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid face [%d, %d)", newp, fMaxNew, fEndNew);
35626ce3c06aSMatthew G. Knepley         for (p = 0; p < size; ++p) {
35636ce3c06aSMatthew G. Knepley           if ((supportNew[p] < cMaxNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid cell [%d, %d)", supportNew[p], cMaxNew, cEndNew);
35646ce3c06aSMatthew G. Knepley         }
35656ce3c06aSMatthew G. Knepley #endif
35666ce3c06aSMatthew G. Knepley       }
35676ce3c06aSMatthew G. Knepley     }
35686ce3c06aSMatthew G. Knepley     /* Hybrid cell faces have 4 edges and 2 cells */
35696ce3c06aSMatthew G. Knepley     for (c = cMax; c < cEnd; ++c) {
35706ce3c06aSMatthew G. Knepley       PetscInt        newp = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*8 + (fEnd - fMax)*2 + (c - cMax)*3;
35716ce3c06aSMatthew G. Knepley       const PetscInt *cone, *ornt;
35726ce3c06aSMatthew G. Knepley       PetscInt        coneNew[4], orntNew[4];
35736ce3c06aSMatthew G. Knepley       PetscInt        supportNew[2];
35746ce3c06aSMatthew G. Knepley 
35756ce3c06aSMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
35766ce3c06aSMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr);
35776ce3c06aSMatthew G. Knepley       for (r = 0; r < 3; ++r) {
3578b598a9d5SMatthew G. Knepley         coneNew[0] = eStartNew + (eMax - eStart)*2 + (cone[0] - fStart)*3 + (r+2)%3;
35796ce3c06aSMatthew G. Knepley         orntNew[0] = 0;
3580b598a9d5SMatthew G. Knepley         coneNew[1] = eStartNew + (eMax - eStart)*2 + (cone[1] - fStart)*3 + (r+2)%3;
35816ce3c06aSMatthew G. Knepley         orntNew[1] = 0;
3582b598a9d5SMatthew G. Knepley         coneNew[2] = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*3 + (cMax - cStart) + (eEnd - eMax) + (cone[2+(r+2)%3] - fMax);
35836ce3c06aSMatthew G. Knepley         orntNew[2] = 0;
3584b598a9d5SMatthew G. Knepley         coneNew[3] = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*3 + (cMax - cStart) + (eEnd - eMax) + (cone[2+r]       - fMax);
35856ce3c06aSMatthew G. Knepley         orntNew[3] = 0;
35866ce3c06aSMatthew G. Knepley         ierr = DMPlexSetCone(rdm, newp+r, coneNew);CHKERRQ(ierr);
35876ce3c06aSMatthew G. Knepley         ierr = DMPlexSetConeOrientation(rdm, newp+r, orntNew);CHKERRQ(ierr);
35886ce3c06aSMatthew G. Knepley #if 1
35896ce3c06aSMatthew G. Knepley         if ((newp+r < fMaxNew) || (newp+r >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid face [%d, %d)", newp+r, fMaxNew, fEndNew);
35906ce3c06aSMatthew G. Knepley         for (p = 0; p < 2; ++p) {
35916ce3c06aSMatthew G. Knepley           if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
35926ce3c06aSMatthew G. Knepley         }
35936ce3c06aSMatthew G. Knepley         for (p = 2; p < 4; ++p) {
35946ce3c06aSMatthew G. Knepley           if ((coneNew[p] < eMaxNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid edge [%d, %d)", coneNew[p], eMaxNew, eEndNew);
35956ce3c06aSMatthew G. Knepley         }
35966ce3c06aSMatthew G. Knepley #endif
35976ce3c06aSMatthew G. Knepley         supportNew[0] = cStartNew + (cMax - cStart)*8 + (c - cMax)*4 + GetTriSubface_Static(ornt[0], r);
35986ce3c06aSMatthew G. Knepley         supportNew[1] = cStartNew + (cMax - cStart)*8 + (c - cMax)*4 + 3;
35996ce3c06aSMatthew G. Knepley         ierr          = DMPlexSetSupport(rdm, newp+r, supportNew);CHKERRQ(ierr);
36006ce3c06aSMatthew G. Knepley #if 1
36016ce3c06aSMatthew G. Knepley         if ((newp+r < fMaxNew) || (newp+r >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid face [%d, %d)", newp+r, fMaxNew, fEndNew);
36026ce3c06aSMatthew G. Knepley         for (p = 0; p < 2; ++p) {
36036ce3c06aSMatthew G. Knepley           if ((supportNew[p] < cMaxNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid cell [%d, %d)", supportNew[p], cMaxNew, cEndNew);
36046ce3c06aSMatthew G. Knepley         }
36056ce3c06aSMatthew G. Knepley #endif
36066ce3c06aSMatthew G. Knepley       }
36076ce3c06aSMatthew G. Knepley     }
36086ce3c06aSMatthew G. Knepley     /* Interior split edges have 2 vertices and the same faces as the parent */
36096ce3c06aSMatthew G. Knepley     for (e = eStart; e < eMax; ++e) {
36106ce3c06aSMatthew G. Knepley       const PetscInt newv = vStartNew + (vEnd - vStart) + (e - eStart);
36116ce3c06aSMatthew G. Knepley 
36126ce3c06aSMatthew G. Knepley       for (r = 0; r < 2; ++r) {
36136ce3c06aSMatthew G. Knepley         const PetscInt  newp = eStartNew + (e - eStart)*2 + r;
36146ce3c06aSMatthew G. Knepley         const PetscInt *cone, *ornt, *support;
36156ce3c06aSMatthew G. Knepley         PetscInt        coneNew[2], coneSize, c, supportSize, s;
36166ce3c06aSMatthew G. Knepley 
36176ce3c06aSMatthew G. Knepley         ierr             = DMPlexGetCone(dm, e, &cone);CHKERRQ(ierr);
36186ce3c06aSMatthew G. Knepley         coneNew[0]       = vStartNew + (cone[0] - vStart);
36196ce3c06aSMatthew G. Knepley         coneNew[1]       = vStartNew + (cone[1] - vStart);
36206ce3c06aSMatthew G. Knepley         coneNew[(r+1)%2] = newv;
36216ce3c06aSMatthew G. Knepley         ierr             = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
36226ce3c06aSMatthew G. Knepley #if 1
36236ce3c06aSMatthew G. Knepley         if ((newp < eStartNew) || (newp >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eMaxNew);
36246ce3c06aSMatthew G. Knepley         for (p = 0; p < 2; ++p) {
36256ce3c06aSMatthew G. Knepley           if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
36266ce3c06aSMatthew G. Knepley         }
36276ce3c06aSMatthew G. Knepley #endif
36286ce3c06aSMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, e, &supportSize);CHKERRQ(ierr);
36296ce3c06aSMatthew G. Knepley         ierr = DMPlexGetSupport(dm, e, &support);CHKERRQ(ierr);
36306ce3c06aSMatthew G. Knepley         for (s = 0; s < supportSize; ++s) {
36316ce3c06aSMatthew G. Knepley           ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr);
36326ce3c06aSMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
36336ce3c06aSMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, support[s], &ornt);CHKERRQ(ierr);
36346ce3c06aSMatthew G. Knepley           for (c = 0; c < coneSize; ++c) if (cone[c] == e) break;
36356ce3c06aSMatthew G. Knepley           if (support[s] < fMax) {
36366ce3c06aSMatthew G. Knepley             supportRef[s] = fStartNew + (support[s] - fStart)*4 + (c + (ornt[c] < 0 ? 1-r : r))%3;
36376ce3c06aSMatthew G. Knepley           } else {
36386ce3c06aSMatthew G. Knepley             supportRef[s] = fStartNew + (fMax       - fStart)*4 + (cMax - cStart)*8 + (support[s] - fMax)*2 + (ornt[c] < 0 ? 1-r : r);
36396ce3c06aSMatthew G. Knepley           }
36406ce3c06aSMatthew G. Knepley         }
36416ce3c06aSMatthew G. Knepley         ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
36426ce3c06aSMatthew G. Knepley #if 1
36436ce3c06aSMatthew G. Knepley         if ((newp < eStartNew) || (newp >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eMaxNew);
36446ce3c06aSMatthew G. Knepley         for (p = 0; p < supportSize; ++p) {
36456ce3c06aSMatthew G. Knepley           if ((supportRef[p] < fStartNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior or hybrid face [%d, %d)", supportRef[p], fStartNew, fEndNew);
36466ce3c06aSMatthew G. Knepley         }
36476ce3c06aSMatthew G. Knepley #endif
36486ce3c06aSMatthew G. Knepley       }
36496ce3c06aSMatthew G. Knepley     }
36506ce3c06aSMatthew G. Knepley     /* Interior face edges have 2 vertices and 2+cells*(1/2) faces */
36516ce3c06aSMatthew G. Knepley     for (f = fStart; f < fMax; ++f) {
36526ce3c06aSMatthew G. Knepley       const PetscInt *cone, *ornt, *support;
36536ce3c06aSMatthew G. Knepley       PetscInt        coneSize, supportSize, s;
36546ce3c06aSMatthew G. Knepley 
36556ce3c06aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, f, &supportSize);CHKERRQ(ierr);
36566ce3c06aSMatthew G. Knepley       ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
36576ce3c06aSMatthew G. Knepley       for (r = 0; r < 3; ++r) {
36586ce3c06aSMatthew G. Knepley         const PetscInt  newp = eStartNew + (eMax - eStart)*2 + (f - fStart)*3 + r;
36596ce3c06aSMatthew G. Knepley         PetscInt        coneNew[2], intFaces = 0, er, eint[4] = {1, 0, 2, 0};
36606ce3c06aSMatthew G. Knepley         PetscInt        fint[24] = { 1,  7, -1, -1,  0,  5,
36616ce3c06aSMatthew G. Knepley                                     -1, -1,  1,  6,  0,  4,
36626ce3c06aSMatthew G. Knepley                                      2,  5,  3,  4, -1, -1,
36636ce3c06aSMatthew G. Knepley                                     -1, -1,  3,  6,  2,  7};
36646ce3c06aSMatthew G. Knepley 
36656ce3c06aSMatthew G. Knepley         ierr = DMPlexGetCone(dm, f, &cone);CHKERRQ(ierr);
36666ce3c06aSMatthew G. Knepley         coneNew[0] = vStartNew + (vEnd - vStart) + (cone[(r+0)%3] - eStart);
36676ce3c06aSMatthew G. Knepley         coneNew[1] = vStartNew + (vEnd - vStart) + (cone[(r+1)%3] - eStart);
36686ce3c06aSMatthew G. Knepley         ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
36696ce3c06aSMatthew G. Knepley #if 1
36706ce3c06aSMatthew G. Knepley         if ((newp < eStartNew) || (newp >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eMaxNew);
36716ce3c06aSMatthew G. Knepley         for (p = 0; p < 2; ++p) {
36726ce3c06aSMatthew G. Knepley           if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
36736ce3c06aSMatthew G. Knepley         }
36746ce3c06aSMatthew G. Knepley #endif
36756ce3c06aSMatthew G. Knepley         supportRef[0] = fStartNew + (f - fStart)*4 + (r+1)%3;
36766ce3c06aSMatthew G. Knepley         supportRef[1] = fStartNew + (f - fStart)*4 + 3;
36776ce3c06aSMatthew G. Knepley         for (s = 0; s < supportSize; ++s) {
36786ce3c06aSMatthew G. Knepley           ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr);
36796ce3c06aSMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
36806ce3c06aSMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, support[s], &ornt);CHKERRQ(ierr);
36816ce3c06aSMatthew G. Knepley           for (c = 0; c < coneSize; ++c) {if (cone[c] == f) break;}
36826ce3c06aSMatthew G. Knepley           if (support[s] < cMax) {
36836ce3c06aSMatthew G. Knepley             /* Here we want to determine whether edge newp contains a vertex which is part of the cross-tet edge */
36849ddff745SMatthew G. Knepley             er = GetTetSomethingInverse_Static(ornt[c], r);
36856ce3c06aSMatthew G. Knepley             if (er == eint[c]) {
36866ce3c06aSMatthew G. Knepley               supportRef[2+intFaces++] = fStartNew + (fMax - fStart)*4 + (support[s] - cStart)*8 + (c + 2)%4;
36876ce3c06aSMatthew G. Knepley             } else {
36886ce3c06aSMatthew G. Knepley               supportRef[2+intFaces++] = fStartNew + (fMax - fStart)*4 + (support[s] - cStart)*8 + fint[(c*3 + er)*2 + 0];
36896ce3c06aSMatthew G. Knepley               supportRef[2+intFaces++] = fStartNew + (fMax - fStart)*4 + (support[s] - cStart)*8 + fint[(c*3 + er)*2 + 1];
36906ce3c06aSMatthew G. Knepley             }
36916ce3c06aSMatthew G. Knepley           } else {
3692b598a9d5SMatthew G. Knepley             supportRef[2+intFaces++] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*8 + (fEnd - fMax)*2 + (support[s] - cMax)*3 + (r + 1)%3;
36936ce3c06aSMatthew G. Knepley           }
36946ce3c06aSMatthew G. Knepley         }
36956ce3c06aSMatthew G. Knepley         ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
36966ce3c06aSMatthew G. Knepley #if 1
36976ce3c06aSMatthew G. Knepley         if ((newp < eStartNew) || (newp >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eMaxNew);
36986ce3c06aSMatthew G. Knepley         for (p = 0; p < intFaces; ++p) {
36996ce3c06aSMatthew G. Knepley           if ((supportRef[p] < fStartNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior or hybrid face [%d, %d)", supportRef[p], fStartNew, fEndNew);
37006ce3c06aSMatthew G. Knepley         }
37016ce3c06aSMatthew G. Knepley #endif
37026ce3c06aSMatthew G. Knepley       }
37036ce3c06aSMatthew G. Knepley     }
37046ce3c06aSMatthew G. Knepley     /* Interior cell edges have 2 vertices and 4 faces */
37056ce3c06aSMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
37066ce3c06aSMatthew G. Knepley       const PetscInt  newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*3 + (c - cStart);
37076ce3c06aSMatthew G. Knepley       const PetscInt *cone, *ornt, *fcone;
37086ce3c06aSMatthew G. Knepley       PetscInt        coneNew[2], supportNew[4], find;
37096ce3c06aSMatthew G. Knepley 
37106ce3c06aSMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
37116ce3c06aSMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr);
37126ce3c06aSMatthew G. Knepley       ierr = DMPlexGetCone(dm, cone[0], &fcone);CHKERRQ(ierr);
37136ce3c06aSMatthew G. Knepley       find = GetTriEdge_Static(ornt[0], 0);
37146ce3c06aSMatthew G. Knepley       coneNew[0] = vStartNew + (vEnd - vStart) + (fcone[find] - eStart);
37156ce3c06aSMatthew G. Knepley       ierr = DMPlexGetCone(dm, cone[2], &fcone);CHKERRQ(ierr);
37166ce3c06aSMatthew G. Knepley       find = GetTriEdge_Static(ornt[2], 1);
37176ce3c06aSMatthew G. Knepley       coneNew[1] = vStartNew + (vEnd - vStart) + (fcone[find] - eStart);
37186ce3c06aSMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
37196ce3c06aSMatthew G. Knepley #if 1
37206ce3c06aSMatthew G. Knepley       if ((newp < eStartNew) || (newp >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eMaxNew);
37216ce3c06aSMatthew G. Knepley       for (p = 0; p < 2; ++p) {
37226ce3c06aSMatthew G. Knepley         if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
37236ce3c06aSMatthew G. Knepley       }
37246ce3c06aSMatthew G. Knepley #endif
37256ce3c06aSMatthew G. Knepley       supportNew[0] = fStartNew + (fMax - fStart)*4 + (c - cStart)*8 + 4;
37266ce3c06aSMatthew G. Knepley       supportNew[1] = fStartNew + (fMax - fStart)*4 + (c - cStart)*8 + 5;
37276ce3c06aSMatthew G. Knepley       supportNew[2] = fStartNew + (fMax - fStart)*4 + (c - cStart)*8 + 6;
37286ce3c06aSMatthew G. Knepley       supportNew[3] = fStartNew + (fMax - fStart)*4 + (c - cStart)*8 + 7;
37296ce3c06aSMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
37306ce3c06aSMatthew G. Knepley #if 1
37316ce3c06aSMatthew G. Knepley       if ((newp < eStartNew) || (newp >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eMaxNew);
37326ce3c06aSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
37336ce3c06aSMatthew G. Knepley         if ((supportNew[p] < fStartNew) || (supportNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", supportNew[p], fStartNew, fMaxNew);
37346ce3c06aSMatthew G. Knepley       }
37356ce3c06aSMatthew G. Knepley #endif
37366ce3c06aSMatthew G. Knepley     }
37376ce3c06aSMatthew G. Knepley     /* Hybrid edges have two vertices and the same faces */
37386ce3c06aSMatthew G. Knepley     for (e = eMax; e < eEnd; ++e) {
37396ce3c06aSMatthew G. Knepley       const PetscInt  newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*3 + (cMax - cStart) + (e - eMax);
37406ce3c06aSMatthew G. Knepley       const PetscInt *cone, *support, *fcone;
37416ce3c06aSMatthew G. Knepley       PetscInt        coneNew[2], size, fsize, s;
37426ce3c06aSMatthew G. Knepley 
37436ce3c06aSMatthew G. Knepley       ierr = DMPlexGetCone(dm, e, &cone);CHKERRQ(ierr);
37446ce3c06aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, e, &size);CHKERRQ(ierr);
37456ce3c06aSMatthew G. Knepley       ierr = DMPlexGetSupport(dm, e, &support);CHKERRQ(ierr);
37466ce3c06aSMatthew G. Knepley       coneNew[0] = vStartNew + (cone[0] - vStart);
37476ce3c06aSMatthew G. Knepley       coneNew[1] = vStartNew + (cone[1] - vStart);
37486ce3c06aSMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
37496ce3c06aSMatthew G. Knepley #if 1
37506ce3c06aSMatthew G. Knepley       if ((newp < eMaxNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid edge [%d, %d)", newp, eMaxNew, eEndNew);
37516ce3c06aSMatthew G. Knepley       for (p = 0; p < 2; ++p) {
37526ce3c06aSMatthew G. Knepley         if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
37536ce3c06aSMatthew G. Knepley       }
37546ce3c06aSMatthew G. Knepley #endif
37556ce3c06aSMatthew G. Knepley       for (s = 0; s < size; ++s) {
37566ce3c06aSMatthew G. Knepley         ierr = DMPlexGetConeSize(dm, support[s], &fsize);CHKERRQ(ierr);
37576ce3c06aSMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &fcone);CHKERRQ(ierr);
37586ce3c06aSMatthew G. Knepley         for (c = 0; c < fsize; ++c) if (fcone[c] == e) break;
37596ce3c06aSMatthew G. Knepley         if ((c < 2) || (c > 3)) SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Edge %d not found in cone of face %d", e, support[s]);
37606ce3c06aSMatthew G. Knepley         supportRef[s] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*8 + (support[s] - fMax)*2 + c-2;
37616ce3c06aSMatthew G. Knepley       }
37626ce3c06aSMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
37636ce3c06aSMatthew G. Knepley #if 1
37646ce3c06aSMatthew G. Knepley       if ((newp < eMaxNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid edge [%d, %d)", newp, eMaxNew, eEndNew);
37656ce3c06aSMatthew G. Knepley       for (p = 0; p < size; ++p) {
37666ce3c06aSMatthew G. Knepley         if ((supportRef[p] < fMaxNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid face [%d, %d)", supportRef[p], fMaxNew, fEndNew);
37676ce3c06aSMatthew G. Knepley       }
37686ce3c06aSMatthew G. Knepley #endif
37696ce3c06aSMatthew G. Knepley     }
37706ce3c06aSMatthew G. Knepley     /* Hybrid face edges have 2 vertices and 2+2*cells faces */
37716ce3c06aSMatthew G. Knepley     for (f = fMax; f < fEnd; ++f) {
37726ce3c06aSMatthew G. Knepley       const PetscInt  newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*3 + (cMax - cStart) + (eEnd - eMax) + (f - fMax);
3773623f4348SMatthew G. Knepley       const PetscInt *cone, *support, *ccone, *cornt;
37746ce3c06aSMatthew G. Knepley       PetscInt        coneNew[2], size, csize, s;
37756ce3c06aSMatthew G. Knepley 
37766ce3c06aSMatthew G. Knepley       ierr = DMPlexGetCone(dm, f, &cone);CHKERRQ(ierr);
37776ce3c06aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
37786ce3c06aSMatthew G. Knepley       ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
37796ce3c06aSMatthew G. Knepley       coneNew[0] = vStartNew + (vEnd - vStart) + (cone[0] - eStart);
37806ce3c06aSMatthew G. Knepley       coneNew[1] = vStartNew + (vEnd - vStart) + (cone[1] - eStart);
37816ce3c06aSMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
37826ce3c06aSMatthew G. Knepley #if 1
37836ce3c06aSMatthew G. Knepley       if ((newp < eMaxNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid edge [%d, %d)", newp, eMaxNew, eEndNew);
37846ce3c06aSMatthew G. Knepley       for (p = 0; p < 2; ++p) {
37856ce3c06aSMatthew G. Knepley         if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
37866ce3c06aSMatthew G. Knepley       }
37876ce3c06aSMatthew G. Knepley #endif
37886ce3c06aSMatthew G. Knepley       supportRef[0] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*8 + (f - fMax)*2 + 0;
37896ce3c06aSMatthew G. Knepley       supportRef[1] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*8 + (f - fMax)*2 + 1;
37906ce3c06aSMatthew G. Knepley       for (s = 0; s < size; ++s) {
37916ce3c06aSMatthew G. Knepley         ierr = DMPlexGetConeSize(dm, support[s], &csize);CHKERRQ(ierr);
37926ce3c06aSMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &ccone);CHKERRQ(ierr);
3793623f4348SMatthew G. Knepley         ierr = DMPlexGetConeOrientation(dm, support[s], &cornt);CHKERRQ(ierr);
37946ce3c06aSMatthew G. Knepley         for (c = 0; c < csize; ++c) if (ccone[c] == f) break;
37956ce3c06aSMatthew G. Knepley         if ((c < 2) || (c >= csize)) SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Hybrid face %d is not in cone of hybrid cell %d", f, support[s]);
3796b598a9d5SMatthew G. Knepley         supportRef[2+s*2+0] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*8 + (fEnd - fMax)*2 + (support[s] - cMax)*3 + c-2;
3797b598a9d5SMatthew G. Knepley         supportRef[2+s*2+1] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*8 + (fEnd - fMax)*2 + (support[s] - cMax)*3 + (c-1)%3;
37986ce3c06aSMatthew G. Knepley       }
37996ce3c06aSMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
38006ce3c06aSMatthew G. Knepley #if 1
38016ce3c06aSMatthew G. Knepley       if ((newp < eMaxNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid edge [%d, %d)", newp, eMaxNew, eEndNew);
38026ce3c06aSMatthew G. Knepley       for (p = 0; p < 2+size*2; ++p) {
38036ce3c06aSMatthew G. Knepley         if ((supportRef[p] < fMaxNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid face [%d, %d)", supportRef[p], fMaxNew, fEndNew);
38046ce3c06aSMatthew G. Knepley       }
38056ce3c06aSMatthew G. Knepley #endif
38066ce3c06aSMatthew G. Knepley     }
38076ce3c06aSMatthew G. Knepley     /* Interior vertices have identical supports */
38086ce3c06aSMatthew G. Knepley     for (v = vStart; v < vEnd; ++v) {
38096ce3c06aSMatthew G. Knepley       const PetscInt  newp = vStartNew + (v - vStart);
38106ce3c06aSMatthew G. Knepley       const PetscInt *support, *cone;
38116ce3c06aSMatthew G. Knepley       PetscInt        size, s;
38126ce3c06aSMatthew G. Knepley 
38136ce3c06aSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, v, &size);CHKERRQ(ierr);
38146ce3c06aSMatthew G. Knepley       ierr = DMPlexGetSupport(dm, v, &support);CHKERRQ(ierr);
38156ce3c06aSMatthew G. Knepley       for (s = 0; s < size; ++s) {
38166ce3c06aSMatthew G. Knepley         PetscInt r = 0;
38176ce3c06aSMatthew G. Knepley 
38186ce3c06aSMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
38196ce3c06aSMatthew G. Knepley         if (cone[1] == v) r = 1;
38206ce3c06aSMatthew G. Knepley         if (support[s] < eMax) supportRef[s] = eStartNew + (support[s] - eStart)*2 + r;
38216ce3c06aSMatthew G. Knepley         else                   supportRef[s] = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*3 + (cMax - cStart) + (support[s] - eMax);
38226ce3c06aSMatthew G. Knepley       }
38236ce3c06aSMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
38246ce3c06aSMatthew G. Knepley #if 1
38256ce3c06aSMatthew G. Knepley       if ((newp < vStartNew) || (newp >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", newp, vStartNew, vEndNew);
38266ce3c06aSMatthew G. Knepley       for (p = 0; p < size; ++p) {
38276ce3c06aSMatthew G. Knepley         if ((supportRef[p] < eStartNew) || (supportRef[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior or hybrid edge [%d, %d)", supportRef[p], eStartNew, eEndNew);
38286ce3c06aSMatthew G. Knepley       }
38296ce3c06aSMatthew G. Knepley #endif
38306ce3c06aSMatthew G. Knepley     }
38316ce3c06aSMatthew G. Knepley     /* Interior edge vertices have 2 + interior face*2 + hybrid face + cells*0/1 supports */
38326ce3c06aSMatthew G. Knepley     for (e = eStart; e < eMax; ++e) {
38336ce3c06aSMatthew G. Knepley       const PetscInt  newp = vStartNew + (vEnd - vStart) + (e - eStart);
38346ce3c06aSMatthew G. Knepley       const PetscInt *cone, *support;
38356ce3c06aSMatthew G. Knepley       PetscInt       *star = NULL, starSize, faceSize = 0, cellSize = 0, coneSize, size, s;
38366ce3c06aSMatthew G. Knepley 
38376ce3c06aSMatthew G. Knepley       ierr          = DMPlexGetSupportSize(dm, e, &size);CHKERRQ(ierr);
38386ce3c06aSMatthew G. Knepley       ierr          = DMPlexGetSupport(dm, e, &support);CHKERRQ(ierr);
38396ce3c06aSMatthew G. Knepley       supportRef[0] = eStartNew + (e - eStart)*2 + 0;
38406ce3c06aSMatthew G. Knepley       supportRef[1] = eStartNew + (e - eStart)*2 + 1;
38416ce3c06aSMatthew G. Knepley       for (s = 0; s < size; ++s) {
38426ce3c06aSMatthew G. Knepley         PetscInt r = 0;
38436ce3c06aSMatthew G. Knepley 
38446ce3c06aSMatthew G. Knepley         if (support[s] < fMax) {
38456ce3c06aSMatthew G. Knepley           ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr);
38466ce3c06aSMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
38476ce3c06aSMatthew G. Knepley           for (r = 0; r < coneSize; ++r) {if (cone[r] == e) break;}
38486ce3c06aSMatthew G. Knepley           supportRef[2+faceSize+0] = eStartNew + (eMax - eStart)*2 + (support[s] - fStart)*3 + (r+0)%3;
38496ce3c06aSMatthew G. Knepley           supportRef[2+faceSize+1] = eStartNew + (eMax - eStart)*2 + (support[s] - fStart)*3 + (r+2)%3;
38506ce3c06aSMatthew G. Knepley           faceSize += 2;
38516ce3c06aSMatthew G. Knepley         } else {
38526ce3c06aSMatthew G. Knepley           supportRef[2+faceSize+0] = eStartNew + (eMax - eStart)*2 + (fMax       - fStart)*3 + (cMax - cStart) + (eEnd - eMax) + (support[s] - fMax);
38536ce3c06aSMatthew G. Knepley           ++faceSize;
38546ce3c06aSMatthew G. Knepley         }
38556ce3c06aSMatthew G. Knepley       }
38566ce3c06aSMatthew G. Knepley       ierr = DMPlexGetTransitiveClosure(dm, e, PETSC_FALSE, &starSize, &star);CHKERRQ(ierr);
38576ce3c06aSMatthew G. Knepley       for (s = 0; s < starSize*2; s += 2) {
38586ce3c06aSMatthew G. Knepley         const PetscInt *cone, *ornt;
38596ce3c06aSMatthew G. Knepley         PetscInt        e01, e23;
38606ce3c06aSMatthew G. Knepley 
38616ce3c06aSMatthew G. Knepley         if ((star[s] >= cStart) && (star[s] < cMax)) {
38626ce3c06aSMatthew G. Knepley           /* Check edge 0-1 */
38636ce3c06aSMatthew G. Knepley           ierr = DMPlexGetCone(dm, star[s], &cone);CHKERRQ(ierr);
38646ce3c06aSMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, star[s], &ornt);CHKERRQ(ierr);
38656ce3c06aSMatthew G. Knepley           ierr = DMPlexGetCone(dm, cone[0], &cone);CHKERRQ(ierr);
38666ce3c06aSMatthew G. Knepley           e01  = cone[GetTriEdge_Static(ornt[0], 0)];
38676ce3c06aSMatthew G. Knepley           /* Check edge 2-3 */
38686ce3c06aSMatthew G. Knepley           ierr = DMPlexGetCone(dm, star[s], &cone);CHKERRQ(ierr);
38696ce3c06aSMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, star[s], &ornt);CHKERRQ(ierr);
38706ce3c06aSMatthew G. Knepley           ierr = DMPlexGetCone(dm, cone[2], &cone);CHKERRQ(ierr);
38716ce3c06aSMatthew G. Knepley           e23  = cone[GetTriEdge_Static(ornt[2], 1)];
38726ce3c06aSMatthew G. Knepley           if ((e01 == e) || (e23 == e)) {supportRef[2+faceSize+cellSize++] = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*3 + (star[s] - cStart);}
38736ce3c06aSMatthew G. Knepley         }
38746ce3c06aSMatthew G. Knepley       }
38756ce3c06aSMatthew G. Knepley       ierr = DMPlexRestoreTransitiveClosure(dm, e, PETSC_FALSE, &starSize, &star);CHKERRQ(ierr);
38766ce3c06aSMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
38776ce3c06aSMatthew G. Knepley #if 1
38786ce3c06aSMatthew G. Knepley       if ((newp < vStartNew) || (newp >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", newp, vStartNew, vEndNew);
38796ce3c06aSMatthew G. Knepley       for (p = 0; p < 2+faceSize+cellSize; ++p) {
38806ce3c06aSMatthew G. Knepley         if ((supportRef[p] < eStartNew) || (supportRef[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an interior or hybrid edge [%d, %d)", supportRef[p], eStartNew, eEndNew);
38816ce3c06aSMatthew G. Knepley       }
38826ce3c06aSMatthew G. Knepley #endif
38836ce3c06aSMatthew G. Knepley     }
38846ce3c06aSMatthew G. Knepley     ierr = PetscFree(supportRef);CHKERRQ(ierr);
38856ce3c06aSMatthew G. Knepley     ierr = DMPlexRestoreFaces_Internal(dm, 3, cStart, NULL, NULL, &faces);CHKERRQ(ierr);
38866ce3c06aSMatthew G. Knepley     break;
38879b1a0e7fSLawrence Mitchell   case REFINER_HEX_3D:
38882eabf88fSMatthew G. Knepley     /*
38892eabf88fSMatthew G. Knepley      Bottom (viewed from top)    Top
38902eabf88fSMatthew G. Knepley      1---------2---------2       7---------2---------6
38912eabf88fSMatthew G. Knepley      |         |         |       |         |         |
38922eabf88fSMatthew G. Knepley      |    B    2    C    |       |    H    2    G    |
38932eabf88fSMatthew G. Knepley      |         |         |       |         |         |
38942eabf88fSMatthew G. Knepley      3----3----0----1----1       3----3----0----1----1
38952eabf88fSMatthew G. Knepley      |         |         |       |         |         |
38962eabf88fSMatthew G. Knepley      |    A    0    D    |       |    E    0    F    |
38972eabf88fSMatthew G. Knepley      |         |         |       |         |         |
38982eabf88fSMatthew G. Knepley      0---------0---------3       4---------0---------5
38992eabf88fSMatthew G. Knepley      */
39002eabf88fSMatthew G. Knepley     /* All cells have 6 faces: Bottom, Top, Front, Back, Right, Left */
39012eabf88fSMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
39022eabf88fSMatthew G. Knepley       const PetscInt  newp = (c - cStart)*8;
39032eabf88fSMatthew G. Knepley       const PetscInt *cone, *ornt;
39042eabf88fSMatthew G. Knepley       PetscInt        coneNew[6], orntNew[6];
39052eabf88fSMatthew G. Knepley 
39062eabf88fSMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
39072eabf88fSMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr);
39082eabf88fSMatthew G. Knepley       /* A hex */
3909e3f8b1d6SMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*4 + GetQuadSubface_Static(ornt[0], 0);
39102eabf88fSMatthew G. Knepley       orntNew[0] = ornt[0];
39112eabf88fSMatthew G. Knepley       coneNew[1] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 +  8; /* AE */
39122eabf88fSMatthew G. Knepley       orntNew[1] = 0;
3913e3f8b1d6SMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*4 + GetQuadSubface_Static(ornt[2], 0);
39142eabf88fSMatthew G. Knepley       orntNew[2] = ornt[2];
39152eabf88fSMatthew G. Knepley       coneNew[3] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 +  3; /* AB */
39162eabf88fSMatthew G. Knepley       orntNew[3] = 0;
39172eabf88fSMatthew G. Knepley       coneNew[4] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 +  0; /* AD */
39182eabf88fSMatthew G. Knepley       orntNew[4] = 0;
3919e3f8b1d6SMatthew G. Knepley       coneNew[5] = fStartNew + (cone[5] - fStart)*4 + GetQuadSubface_Static(ornt[5], 0);
39202eabf88fSMatthew G. Knepley       orntNew[5] = ornt[5];
39212eabf88fSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+0, coneNew);CHKERRQ(ierr);
39222eabf88fSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+0, orntNew);CHKERRQ(ierr);
39232eabf88fSMatthew G. Knepley #if 1
39242eabf88fSMatthew G. Knepley       if ((newp+0 < cStartNew) || (newp+0 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+0, cStartNew, cEndNew);
39252eabf88fSMatthew G. Knepley       for (p = 0; p < 6; ++p) {
39262eabf88fSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
39272eabf88fSMatthew G. Knepley       }
39282eabf88fSMatthew G. Knepley #endif
39292eabf88fSMatthew G. Knepley       /* B hex */
3930e3f8b1d6SMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*4 + GetQuadSubface_Static(ornt[0], 1);
39312eabf88fSMatthew G. Knepley       orntNew[0] = ornt[0];
39322eabf88fSMatthew G. Knepley       coneNew[1] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 + 11; /* BH */
39332eabf88fSMatthew G. Knepley       orntNew[1] = 0;
39342eabf88fSMatthew G. Knepley       coneNew[2] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 +  3; /* AB */
3935a3cddbf8SMatthew G. Knepley       orntNew[2] = -1;
3936e3f8b1d6SMatthew G. Knepley       coneNew[3] = fStartNew + (cone[3] - fStart)*4 + GetQuadSubface_Static(ornt[3], 1);
39372eabf88fSMatthew G. Knepley       orntNew[3] = ornt[3];
39382eabf88fSMatthew G. Knepley       coneNew[4] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 +  2; /* BC */
39392eabf88fSMatthew G. Knepley       orntNew[4] = 0;
3940e3f8b1d6SMatthew G. Knepley       coneNew[5] = fStartNew + (cone[5] - fStart)*4 + GetQuadSubface_Static(ornt[5], 3);
39412eabf88fSMatthew G. Knepley       orntNew[5] = ornt[5];
39422eabf88fSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+1, coneNew);CHKERRQ(ierr);
39432eabf88fSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+1, orntNew);CHKERRQ(ierr);
39442eabf88fSMatthew G. Knepley #if 1
39452eabf88fSMatthew G. Knepley       if ((newp+1 < cStartNew) || (newp+1 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+1, cStartNew, cEndNew);
39462eabf88fSMatthew G. Knepley       for (p = 0; p < 6; ++p) {
39472eabf88fSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
39482eabf88fSMatthew G. Knepley       }
39492eabf88fSMatthew G. Knepley #endif
39502eabf88fSMatthew G. Knepley       /* C hex */
3951e3f8b1d6SMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*4 + GetQuadSubface_Static(ornt[0], 2);
39522eabf88fSMatthew G. Knepley       orntNew[0] = ornt[0];
39532eabf88fSMatthew G. Knepley       coneNew[1] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 + 10; /* CG */
39542eabf88fSMatthew G. Knepley       orntNew[1] = 0;
39552eabf88fSMatthew G. Knepley       coneNew[2] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 +  1; /* CD */
3956a3cddbf8SMatthew G. Knepley       orntNew[2] = -1;
3957e3f8b1d6SMatthew G. Knepley       coneNew[3] = fStartNew + (cone[3] - fStart)*4 + GetQuadSubface_Static(ornt[3], 0);
39582eabf88fSMatthew G. Knepley       orntNew[3] = ornt[3];
3959e3f8b1d6SMatthew G. Knepley       coneNew[4] = fStartNew + (cone[4] - fStart)*4 + GetQuadSubface_Static(ornt[4], 1);
39602eabf88fSMatthew G. Knepley       orntNew[4] = ornt[4];
39612eabf88fSMatthew G. Knepley       coneNew[5] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 +  2; /* BC */
3962a3cddbf8SMatthew G. Knepley       orntNew[5] = -4;
39632eabf88fSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+2, coneNew);CHKERRQ(ierr);
39642eabf88fSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+2, orntNew);CHKERRQ(ierr);
39652eabf88fSMatthew G. Knepley #if 1
39662eabf88fSMatthew G. Knepley       if ((newp+2 < cStartNew) || (newp+2 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+2, cStartNew, cEndNew);
39672eabf88fSMatthew G. Knepley       for (p = 0; p < 6; ++p) {
39682eabf88fSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
39692eabf88fSMatthew G. Knepley       }
39702eabf88fSMatthew G. Knepley #endif
39712eabf88fSMatthew G. Knepley       /* D hex */
3972e3f8b1d6SMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*4 + GetQuadSubface_Static(ornt[0], 3);
39732eabf88fSMatthew G. Knepley       orntNew[0] = ornt[0];
39742eabf88fSMatthew G. Knepley       coneNew[1] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 +  9; /* DF */
39752eabf88fSMatthew G. Knepley       orntNew[1] = 0;
3976e3f8b1d6SMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*4 + GetQuadSubface_Static(ornt[2], 1);
39772eabf88fSMatthew G. Knepley       orntNew[2] = ornt[2];
39782eabf88fSMatthew G. Knepley       coneNew[3] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 +  1; /* CD */
3979a3cddbf8SMatthew G. Knepley       orntNew[3] = 0;
3980e3f8b1d6SMatthew G. Knepley       coneNew[4] = fStartNew + (cone[4] - fStart)*4 + GetQuadSubface_Static(ornt[4], 0);
39812eabf88fSMatthew G. Knepley       orntNew[4] = ornt[4];
39822eabf88fSMatthew G. Knepley       coneNew[5] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 +  0; /* AD */
3983a3cddbf8SMatthew G. Knepley       orntNew[5] = -4;
39842eabf88fSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+3, coneNew);CHKERRQ(ierr);
39852eabf88fSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+3, orntNew);CHKERRQ(ierr);
39862eabf88fSMatthew G. Knepley #if 1
39872eabf88fSMatthew G. Knepley       if ((newp+3 < cStartNew) || (newp+3 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+3, cStartNew, cEndNew);
39882eabf88fSMatthew G. Knepley       for (p = 0; p < 6; ++p) {
39892eabf88fSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
39902eabf88fSMatthew G. Knepley       }
39912eabf88fSMatthew G. Knepley #endif
39922eabf88fSMatthew G. Knepley       /* E hex */
39932eabf88fSMatthew G. Knepley       coneNew[0] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 +  8; /* AE */
3994a3cddbf8SMatthew G. Knepley       orntNew[0] = -4;
3995e3f8b1d6SMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*4 + GetQuadSubface_Static(ornt[1], 0);
39962eabf88fSMatthew G. Knepley       orntNew[1] = ornt[1];
3997e3f8b1d6SMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*4 + GetQuadSubface_Static(ornt[2], 3);
39982eabf88fSMatthew G. Knepley       orntNew[2] = ornt[2];
39992eabf88fSMatthew G. Knepley       coneNew[3] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 +  7; /* EH */
40002eabf88fSMatthew G. Knepley       orntNew[3] = 0;
40012eabf88fSMatthew G. Knepley       coneNew[4] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 +  4; /* EF */
4002a3cddbf8SMatthew G. Knepley       orntNew[4] = -1;
4003e3f8b1d6SMatthew G. Knepley       coneNew[5] = fStartNew + (cone[5] - fStart)*4 + GetQuadSubface_Static(ornt[5], 1);
40042eabf88fSMatthew G. Knepley       orntNew[5] = ornt[5];
4005b164cbf2SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+4, coneNew);CHKERRQ(ierr);
4006b164cbf2SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+4, orntNew);CHKERRQ(ierr);
40072eabf88fSMatthew G. Knepley #if 1
4008b164cbf2SMatthew G. Knepley       if ((newp+4 < cStartNew) || (newp+4 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+4, cStartNew, cEndNew);
40092eabf88fSMatthew G. Knepley       for (p = 0; p < 6; ++p) {
40102eabf88fSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
40112eabf88fSMatthew G. Knepley       }
40122eabf88fSMatthew G. Knepley #endif
40132eabf88fSMatthew G. Knepley       /* F hex */
40142eabf88fSMatthew G. Knepley       coneNew[0] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 +  9; /* DF */
4015a3cddbf8SMatthew G. Knepley       orntNew[0] = -4;
4016e3f8b1d6SMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*4 + GetQuadSubface_Static(ornt[1], 1);
40172eabf88fSMatthew G. Knepley       orntNew[1] = ornt[1];
4018e3f8b1d6SMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*4 + GetQuadSubface_Static(ornt[2], 2);
40192eabf88fSMatthew G. Knepley       orntNew[2] = ornt[2];
40202eabf88fSMatthew G. Knepley       coneNew[3] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 +  5; /* FG */
4021a3cddbf8SMatthew G. Knepley       orntNew[3] = -1;
4022e3f8b1d6SMatthew G. Knepley       coneNew[4] = fStartNew + (cone[4] - fStart)*4 + GetQuadSubface_Static(ornt[4], 3);
40232eabf88fSMatthew G. Knepley       orntNew[4] = ornt[4];
40242eabf88fSMatthew G. Knepley       coneNew[5] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 +  4; /* EF */
4025a3cddbf8SMatthew G. Knepley       orntNew[5] = 1;
4026b164cbf2SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+5, coneNew);CHKERRQ(ierr);
4027b164cbf2SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+5, orntNew);CHKERRQ(ierr);
40282eabf88fSMatthew G. Knepley #if 1
4029b164cbf2SMatthew G. Knepley       if ((newp+5 < cStartNew) || (newp+5 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+5, cStartNew, cEndNew);
40302eabf88fSMatthew G. Knepley       for (p = 0; p < 6; ++p) {
40312eabf88fSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
40322eabf88fSMatthew G. Knepley       }
40332eabf88fSMatthew G. Knepley #endif
40342eabf88fSMatthew G. Knepley       /* G hex */
40352eabf88fSMatthew G. Knepley       coneNew[0] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 + 10; /* CG */
4036a3cddbf8SMatthew G. Knepley       orntNew[0] = -4;
4037e3f8b1d6SMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*4 + GetQuadSubface_Static(ornt[1], 2);
40382eabf88fSMatthew G. Knepley       orntNew[1] = ornt[1];
40392eabf88fSMatthew G. Knepley       coneNew[2] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 +  5; /* FG */
4040a3cddbf8SMatthew G. Knepley       orntNew[2] = 0;
4041e3f8b1d6SMatthew G. Knepley       coneNew[3] = fStartNew + (cone[3] - fStart)*4 + GetQuadSubface_Static(ornt[3], 3);
40422eabf88fSMatthew G. Knepley       orntNew[3] = ornt[3];
4043e3f8b1d6SMatthew G. Knepley       coneNew[4] = fStartNew + (cone[4] - fStart)*4 + GetQuadSubface_Static(ornt[4], 2);
40442eabf88fSMatthew G. Knepley       orntNew[4] = ornt[4];
40452eabf88fSMatthew G. Knepley       coneNew[5] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 +  6; /* GH */
4046a3cddbf8SMatthew G. Knepley       orntNew[5] = -3;
4047b164cbf2SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+6, coneNew);CHKERRQ(ierr);
4048b164cbf2SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+6, orntNew);CHKERRQ(ierr);
40492eabf88fSMatthew G. Knepley #if 1
4050b164cbf2SMatthew G. Knepley       if ((newp+6 < cStartNew) || (newp+6 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+6, cStartNew, cEndNew);
40512eabf88fSMatthew G. Knepley       for (p = 0; p < 6; ++p) {
40522eabf88fSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
40532eabf88fSMatthew G. Knepley       }
40542eabf88fSMatthew G. Knepley #endif
40552eabf88fSMatthew G. Knepley       /* H hex */
40562eabf88fSMatthew G. Knepley       coneNew[0] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 + 11; /* BH */
4057a3cddbf8SMatthew G. Knepley       orntNew[0] = -4;
4058e3f8b1d6SMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*4 + GetQuadSubface_Static(ornt[1], 3);
40592eabf88fSMatthew G. Knepley       orntNew[1] = ornt[1];
40602eabf88fSMatthew G. Knepley       coneNew[2] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 +  7; /* EH */
4061a3cddbf8SMatthew G. Knepley       orntNew[2] = -1;
4062e3f8b1d6SMatthew G. Knepley       coneNew[3] = fStartNew + (cone[3] - fStart)*4 + GetQuadSubface_Static(ornt[3], 2);
40632eabf88fSMatthew G. Knepley       orntNew[3] = ornt[3];
40642eabf88fSMatthew G. Knepley       coneNew[4] = fStartNew + (fEnd    - fStart)*4 + (c - cStart)*12 +  6; /* GH */
4065a3cddbf8SMatthew G. Knepley       orntNew[4] = 3;
4066e3f8b1d6SMatthew G. Knepley       coneNew[5] = fStartNew + (cone[5] - fStart)*4 + GetQuadSubface_Static(ornt[5], 2);
40672eabf88fSMatthew G. Knepley       orntNew[5] = ornt[5];
4068b164cbf2SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+7, coneNew);CHKERRQ(ierr);
4069b164cbf2SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+7, orntNew);CHKERRQ(ierr);
40702eabf88fSMatthew G. Knepley #if 1
4071b164cbf2SMatthew G. Knepley       if ((newp+7 < cStartNew) || (newp+7 >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+7, cStartNew, cEndNew);
40722eabf88fSMatthew G. Knepley       for (p = 0; p < 6; ++p) {
40732eabf88fSMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fEndNew);
40742eabf88fSMatthew G. Knepley       }
40752eabf88fSMatthew G. Knepley #endif
40762eabf88fSMatthew G. Knepley     }
40772eabf88fSMatthew G. Knepley     /* Split faces have 4 edges and the same cells as the parent */
40782eabf88fSMatthew G. Knepley     ierr = DMPlexGetMaxSizes(dm, NULL, &maxSupportSize);CHKERRQ(ierr);
4079854ce69bSBarry Smith     ierr = PetscMalloc1(4 + maxSupportSize*2, &supportRef);CHKERRQ(ierr);
40802eabf88fSMatthew G. Knepley     for (f = fStart; f < fEnd; ++f) {
40812eabf88fSMatthew G. Knepley       for (r = 0; r < 4; ++r) {
4082aaebbb9dSMatthew G. Knepley         /* TODO: This can come from GetFaces_Internal() */
40832eabf88fSMatthew G. Knepley         const PetscInt  newCells[24] = {0, 1, 2, 3,  4, 5, 6, 7,  0, 3, 5, 4,  2, 1, 7, 6,  3, 2, 6, 5,  0, 4, 7, 1};
40842eabf88fSMatthew G. Knepley         const PetscInt  newp = fStartNew + (f - fStart)*4 + r;
40852eabf88fSMatthew G. Knepley         const PetscInt *cone, *ornt, *support;
4086aaebbb9dSMatthew G. Knepley         PetscInt        coneNew[4], orntNew[4], coneSize, c, supportSize, s;
40872eabf88fSMatthew G. Knepley 
40882eabf88fSMatthew G. Knepley         ierr = DMPlexGetCone(dm, f, &cone);CHKERRQ(ierr);
4089aaebbb9dSMatthew G. Knepley         ierr = DMPlexGetConeOrientation(dm, f, &ornt);CHKERRQ(ierr);
4090a3cddbf8SMatthew G. Knepley         coneNew[(r+3)%4] = eStartNew + (cone[(r+3)%4] - eStart)*2 + (ornt[(r+3)%4] < 0 ? 0 : 1);
4091a3cddbf8SMatthew G. Knepley         orntNew[(r+3)%4] = ornt[(r+3)%4];
4092a3cddbf8SMatthew G. Knepley         coneNew[(r+0)%4] = eStartNew + (cone[r]       - eStart)*2 + (ornt[r] < 0 ? 1 : 0);
4093a3cddbf8SMatthew G. Knepley         orntNew[(r+0)%4] = ornt[r];
4094a3cddbf8SMatthew G. Knepley         coneNew[(r+1)%4] = eStartNew + (eEnd - eStart)*2 + (f - fStart)*4 + r;
4095a3cddbf8SMatthew G. Knepley         orntNew[(r+1)%4] = 0;
4096a3cddbf8SMatthew G. Knepley         coneNew[(r+2)%4] = eStartNew + (eEnd - eStart)*2 + (f - fStart)*4 + (r+3)%4;
4097a3cddbf8SMatthew G. Knepley         orntNew[(r+2)%4] = -2;
40982eabf88fSMatthew G. Knepley         ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
4099aaebbb9dSMatthew G. Knepley         ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
41002eabf88fSMatthew G. Knepley #if 1
41012eabf88fSMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
41022eabf88fSMatthew G. Knepley         for (p = 0; p < 4; ++p) {
41032eabf88fSMatthew G. Knepley           if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
41042eabf88fSMatthew G. Knepley         }
41052eabf88fSMatthew G. Knepley #endif
41062eabf88fSMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &supportSize);CHKERRQ(ierr);
41072eabf88fSMatthew G. Knepley         ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
41082eabf88fSMatthew G. Knepley         for (s = 0; s < supportSize; ++s) {
41092eabf88fSMatthew G. Knepley           ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr);
41102eabf88fSMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
41112eabf88fSMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, support[s], &ornt);CHKERRQ(ierr);
41122eabf88fSMatthew G. Knepley           for (c = 0; c < coneSize; ++c) {
41132eabf88fSMatthew G. Knepley             if (cone[c] == f) break;
41142eabf88fSMatthew G. Knepley           }
4115a3cddbf8SMatthew G. Knepley           supportRef[s] = cStartNew + (support[s] - cStart)*8 + newCells[c*4+GetQuadSubfaceInverse_Static(ornt[c], r)];
41162eabf88fSMatthew G. Knepley         }
41172eabf88fSMatthew G. Knepley         ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
41182eabf88fSMatthew G. Knepley #if 1
41192eabf88fSMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
41202eabf88fSMatthew G. Knepley         for (p = 0; p < supportSize; ++p) {
41212eabf88fSMatthew G. Knepley           if ((supportRef[p] < cStartNew) || (supportRef[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportRef[p], cStartNew, cEndNew);
41222eabf88fSMatthew G. Knepley         }
41232eabf88fSMatthew G. Knepley #endif
41242eabf88fSMatthew G. Knepley       }
41252eabf88fSMatthew G. Knepley     }
41262eabf88fSMatthew G. Knepley     /* Interior faces have 4 edges and 2 cells */
41272eabf88fSMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
41282eabf88fSMatthew G. Knepley       const PetscInt  newCells[24] = {0, 3,  2, 3,  1, 2,  0, 1,  4, 5,  5, 6,  6, 7,  4, 7,  0, 4,  3, 5,  2, 6,  1, 7};
4129afb2665bSMatthew G. Knepley       const PetscInt *cone, *ornt;
4130afb2665bSMatthew G. Knepley       PetscInt        newp, coneNew[4], orntNew[4], supportNew[2];
41312eabf88fSMatthew G. Knepley 
41322eabf88fSMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
4133afb2665bSMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr);
4134afb2665bSMatthew G. Knepley       /* A-D face */
4135afb2665bSMatthew G. Knepley       newp = fStartNew + (fEnd - fStart)*4 + (c - cStart)*12 + 0;
4136a3cddbf8SMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd - eStart)*2 + (cone[0] - fStart)*4 + GetQuadEdge_Static(ornt[0], 3);
4137a3cddbf8SMatthew G. Knepley       orntNew[0] = 0;
4138a3cddbf8SMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 0;
4139afb2665bSMatthew G. Knepley       orntNew[1] = 0;
4140a3cddbf8SMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 2;
4141a3cddbf8SMatthew G. Knepley       orntNew[2] = -2;
4142a3cddbf8SMatthew G. Knepley       coneNew[3] = eStartNew + (eEnd - eStart)*2 + (cone[2] - fStart)*4 + GetQuadEdge_Static(ornt[2], 0);
4143afb2665bSMatthew G. Knepley       orntNew[3] = -2;
41442eabf88fSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
4145afb2665bSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
41462eabf88fSMatthew G. Knepley #if 1
41472eabf88fSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
41482eabf88fSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
41492eabf88fSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
41502eabf88fSMatthew G. Knepley       }
41512eabf88fSMatthew G. Knepley #endif
4152afb2665bSMatthew G. Knepley       /* C-D face */
4153afb2665bSMatthew G. Knepley       newp = fStartNew + (fEnd - fStart)*4 + (c - cStart)*12 + 1;
4154a3cddbf8SMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd - eStart)*2 + (cone[0] - fStart)*4 + GetQuadEdge_Static(ornt[0], 2);
4155a3cddbf8SMatthew G. Knepley       orntNew[0] = 0;
4156a3cddbf8SMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 0;
4157afb2665bSMatthew G. Knepley       orntNew[1] = 0;
4158a3cddbf8SMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 4;
4159a3cddbf8SMatthew G. Knepley       orntNew[2] = -2;
4160a3cddbf8SMatthew G. Knepley       coneNew[3] = eStartNew + (eEnd - eStart)*2 + (cone[4] - fStart)*4 + GetQuadEdge_Static(ornt[4], 0);
4161afb2665bSMatthew G. Knepley       orntNew[3] = -2;
4162afb2665bSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
4163afb2665bSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
4164afb2665bSMatthew G. Knepley #if 1
4165afb2665bSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
4166afb2665bSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
4167afb2665bSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
4168afb2665bSMatthew G. Knepley       }
4169afb2665bSMatthew G. Knepley #endif
4170afb2665bSMatthew G. Knepley       /* B-C face */
4171afb2665bSMatthew G. Knepley       newp = fStartNew + (fEnd - fStart)*4 + (c - cStart)*12 + 2;
4172afb2665bSMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd - eStart)*2 + (cone[0] - fStart)*4 + GetQuadEdge_Static(ornt[0], 1);
4173afb2665bSMatthew G. Knepley       orntNew[0] = -2;
4174afb2665bSMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd - eStart)*2 + (cone[3] - fStart)*4 + GetQuadEdge_Static(ornt[3], 0);
4175afb2665bSMatthew G. Knepley       orntNew[1] = 0;
4176afb2665bSMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 3;
4177afb2665bSMatthew G. Knepley       orntNew[2] = 0;
4178afb2665bSMatthew G. Knepley       coneNew[3] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 0;
4179afb2665bSMatthew G. Knepley       orntNew[3] = -2;
4180afb2665bSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
4181afb2665bSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
4182afb2665bSMatthew G. Knepley #if 1
4183afb2665bSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
4184afb2665bSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
4185afb2665bSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
4186afb2665bSMatthew G. Knepley       }
4187afb2665bSMatthew G. Knepley #endif
4188afb2665bSMatthew G. Knepley       /* A-B face */
4189afb2665bSMatthew G. Knepley       newp = fStartNew + (fEnd - fStart)*4 + (c - cStart)*12 + 3;
4190afb2665bSMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd - eStart)*2 + (cone[0] - fStart)*4 + GetQuadEdge_Static(ornt[0], 0);
4191afb2665bSMatthew G. Knepley       orntNew[0] = -2;
4192afb2665bSMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd - eStart)*2 + (cone[5] - fStart)*4 + GetQuadEdge_Static(ornt[5], 3);
4193afb2665bSMatthew G. Knepley       orntNew[1] = 0;
4194afb2665bSMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 5;
4195afb2665bSMatthew G. Knepley       orntNew[2] = 0;
4196afb2665bSMatthew G. Knepley       coneNew[3] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 0;
4197afb2665bSMatthew G. Knepley       orntNew[3] = -2;
4198afb2665bSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
4199afb2665bSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
4200afb2665bSMatthew G. Knepley #if 1
4201afb2665bSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
4202afb2665bSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
4203afb2665bSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
4204afb2665bSMatthew G. Knepley       }
4205afb2665bSMatthew G. Knepley #endif
4206afb2665bSMatthew G. Knepley       /* E-F face */
4207afb2665bSMatthew G. Knepley       newp = fStartNew + (fEnd - fStart)*4 + (c - cStart)*12 + 4;
4208a3cddbf8SMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 2;
4209afb2665bSMatthew G. Knepley       orntNew[0] = -2;
4210a3cddbf8SMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd - eStart)*2 + (cone[2] - fStart)*4 + GetQuadEdge_Static(ornt[2], 2);
4211a3cddbf8SMatthew G. Knepley       orntNew[1] = -2;
4212a3cddbf8SMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd - eStart)*2 + (cone[1] - fStart)*4 + GetQuadEdge_Static(ornt[1], 0);
4213afb2665bSMatthew G. Knepley       orntNew[2] = 0;
4214a3cddbf8SMatthew G. Knepley       coneNew[3] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 1;
4215a3cddbf8SMatthew G. Knepley       orntNew[3] = 0;
4216afb2665bSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
4217afb2665bSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
4218afb2665bSMatthew G. Knepley #if 1
4219afb2665bSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
4220afb2665bSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
4221afb2665bSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
4222afb2665bSMatthew G. Knepley       }
4223afb2665bSMatthew G. Knepley #endif
4224afb2665bSMatthew G. Knepley       /* F-G face */
4225afb2665bSMatthew G. Knepley       newp = fStartNew + (fEnd - fStart)*4 + (c - cStart)*12 + 5;
4226a3cddbf8SMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 4;
4227afb2665bSMatthew G. Knepley       orntNew[0] = -2;
4228a3cddbf8SMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd - eStart)*2 + (cone[4] - fStart)*4 + GetQuadEdge_Static(ornt[4], 2);
4229a3cddbf8SMatthew G. Knepley       orntNew[1] = -2;
4230a3cddbf8SMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd - eStart)*2 + (cone[1] - fStart)*4 + GetQuadEdge_Static(ornt[1], 1);
4231afb2665bSMatthew G. Knepley       orntNew[2] = 0;
4232a3cddbf8SMatthew G. Knepley       coneNew[3] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 1;
4233a3cddbf8SMatthew G. Knepley       orntNew[3] = 0;
4234afb2665bSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
4235afb2665bSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
4236afb2665bSMatthew G. Knepley #if 1
4237afb2665bSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
4238afb2665bSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
4239afb2665bSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
4240afb2665bSMatthew G. Knepley       }
4241afb2665bSMatthew G. Knepley #endif
4242afb2665bSMatthew G. Knepley       /* G-H face */
4243afb2665bSMatthew G. Knepley       newp = fStartNew + (fEnd - fStart)*4 + (c - cStart)*12 + 6;
4244afb2665bSMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd - eStart)*2 + (cone[3] - fStart)*4 + GetQuadEdge_Static(ornt[3], 2);
4245afb2665bSMatthew G. Knepley       orntNew[0] = -2;
4246afb2665bSMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd - eStart)*2 + (cone[1] - fStart)*4 + GetQuadEdge_Static(ornt[1], 2);
4247afb2665bSMatthew G. Knepley       orntNew[1] = 0;
4248afb2665bSMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 1;
4249afb2665bSMatthew G. Knepley       orntNew[2] = 0;
4250afb2665bSMatthew G. Knepley       coneNew[3] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 3;
4251afb2665bSMatthew G. Knepley       orntNew[3] = -2;
4252afb2665bSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
4253afb2665bSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
4254afb2665bSMatthew G. Knepley #if 1
4255afb2665bSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
4256afb2665bSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
4257afb2665bSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
4258afb2665bSMatthew G. Knepley       }
4259afb2665bSMatthew G. Knepley #endif
4260afb2665bSMatthew G. Knepley       /* E-H face */
4261afb2665bSMatthew G. Knepley       newp = fStartNew + (fEnd - fStart)*4 + (c - cStart)*12 + 7;
4262a3cddbf8SMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 5;
4263afb2665bSMatthew G. Knepley       orntNew[0] = -2;
4264a3cddbf8SMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd - eStart)*2 + (cone[5] - fStart)*4 + GetQuadEdge_Static(ornt[5], 1);
4265a3cddbf8SMatthew G. Knepley       orntNew[1] = -2;
4266a3cddbf8SMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd - eStart)*2 + (cone[1] - fStart)*4 + GetQuadEdge_Static(ornt[1], 3);
4267afb2665bSMatthew G. Knepley       orntNew[2] = 0;
4268a3cddbf8SMatthew G. Knepley       coneNew[3] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 1;
4269a3cddbf8SMatthew G. Knepley       orntNew[3] = 0;
4270afb2665bSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
4271afb2665bSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
4272afb2665bSMatthew G. Knepley #if 1
4273afb2665bSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
4274afb2665bSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
4275afb2665bSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
4276afb2665bSMatthew G. Knepley       }
4277afb2665bSMatthew G. Knepley #endif
4278afb2665bSMatthew G. Knepley       /* A-E face */
4279afb2665bSMatthew G. Knepley       newp = fStartNew + (fEnd - fStart)*4 + (c - cStart)*12 + 8;
4280a3cddbf8SMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd - eStart)*2 + (cone[2] - fStart)*4 + GetQuadEdge_Static(ornt[2], 3);
4281a3cddbf8SMatthew G. Knepley       orntNew[0] = 0;
4282a3cddbf8SMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 2;
4283afb2665bSMatthew G. Knepley       orntNew[1] = 0;
4284a3cddbf8SMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 5;
4285a3cddbf8SMatthew G. Knepley       orntNew[2] = -2;
4286a3cddbf8SMatthew G. Knepley       coneNew[3] = eStartNew + (eEnd - eStart)*2 + (cone[5] - fStart)*4 + GetQuadEdge_Static(ornt[5], 0);
4287afb2665bSMatthew G. Knepley       orntNew[3] = -2;
4288afb2665bSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
4289afb2665bSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
4290afb2665bSMatthew G. Knepley #if 1
4291afb2665bSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
4292afb2665bSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
4293afb2665bSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
4294afb2665bSMatthew G. Knepley       }
4295afb2665bSMatthew G. Knepley #endif
4296afb2665bSMatthew G. Knepley       /* D-F face */
4297afb2665bSMatthew G. Knepley       newp = fStartNew + (fEnd - fStart)*4 + (c - cStart)*12 + 9;
4298afb2665bSMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd - eStart)*2 + (cone[2] - fStart)*4 + GetQuadEdge_Static(ornt[2], 1);
4299afb2665bSMatthew G. Knepley       orntNew[0] = -2;
4300afb2665bSMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd - eStart)*2 + (cone[4] - fStart)*4 + GetQuadEdge_Static(ornt[4], 3);
4301afb2665bSMatthew G. Knepley       orntNew[1] = 0;
4302afb2665bSMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 4;
4303afb2665bSMatthew G. Knepley       orntNew[2] = 0;
4304afb2665bSMatthew G. Knepley       coneNew[3] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 2;
4305afb2665bSMatthew G. Knepley       orntNew[3] = -2;
4306afb2665bSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
4307afb2665bSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
4308afb2665bSMatthew G. Knepley #if 1
4309afb2665bSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
4310afb2665bSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
4311afb2665bSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
4312afb2665bSMatthew G. Knepley       }
4313afb2665bSMatthew G. Knepley #endif
4314afb2665bSMatthew G. Knepley       /* C-G face */
4315afb2665bSMatthew G. Knepley       newp = fStartNew + (fEnd - fStart)*4 + (c - cStart)*12 + 10;
4316a3cddbf8SMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 4;
4317afb2665bSMatthew G. Knepley       orntNew[0] = -2;
4318a3cddbf8SMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd - eStart)*2 + (cone[4] - fStart)*4 + GetQuadEdge_Static(ornt[4], 1);
4319a3cddbf8SMatthew G. Knepley       orntNew[1] = -2;
4320a3cddbf8SMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd - eStart)*2 + (cone[3] - fStart)*4 + GetQuadEdge_Static(ornt[3], 3);
4321afb2665bSMatthew G. Knepley       orntNew[2] = 0;
4322a3cddbf8SMatthew G. Knepley       coneNew[3] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 3;
4323a3cddbf8SMatthew G. Knepley       orntNew[3] = 0;
4324afb2665bSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
4325afb2665bSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
4326afb2665bSMatthew G. Knepley #if 1
4327afb2665bSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
4328afb2665bSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
4329afb2665bSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
4330afb2665bSMatthew G. Knepley       }
4331afb2665bSMatthew G. Knepley #endif
4332afb2665bSMatthew G. Knepley       /* B-H face */
4333afb2665bSMatthew G. Knepley       newp = fStartNew + (fEnd - fStart)*4 + (c - cStart)*12 + 11;
4334a3cddbf8SMatthew G. Knepley       coneNew[0] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 5;
4335a3cddbf8SMatthew G. Knepley       orntNew[0] = 0;
4336a3cddbf8SMatthew G. Knepley       coneNew[1] = eStartNew + (eEnd - eStart)*2 + (fEnd    - fStart)*4 + (c - cStart)*6 + 3;
4337a3cddbf8SMatthew G. Knepley       orntNew[1] = -2;
4338a3cddbf8SMatthew G. Knepley       coneNew[2] = eStartNew + (eEnd - eStart)*2 + (cone[3] - fStart)*4 + GetQuadEdge_Static(ornt[3], 1);
4339a3cddbf8SMatthew G. Knepley       orntNew[2] = -2;
4340a3cddbf8SMatthew G. Knepley       coneNew[3] = eStartNew + (eEnd - eStart)*2 + (cone[5] - fStart)*4 + GetQuadEdge_Static(ornt[5], 2);
4341a3cddbf8SMatthew G. Knepley       orntNew[3] = 0;
4342afb2665bSMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
4343afb2665bSMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
4344afb2665bSMatthew G. Knepley #if 1
4345afb2665bSMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
4346afb2665bSMatthew G. Knepley       for (p = 0; p < 4; ++p) {
4347afb2665bSMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eEndNew);
4348afb2665bSMatthew G. Knepley       }
4349afb2665bSMatthew G. Knepley #endif
4350afb2665bSMatthew G. Knepley       for (r = 0; r < 12; ++r) {
4351afb2665bSMatthew G. Knepley         newp = fStartNew + (fEnd - fStart)*4 + (c - cStart)*12 + r;
43522eabf88fSMatthew G. Knepley         supportNew[0] = cStartNew + (c - cStart)*8 + newCells[r*2+0];
43532eabf88fSMatthew G. Knepley         supportNew[1] = cStartNew + (c - cStart)*8 + newCells[r*2+1];
43542eabf88fSMatthew G. Knepley         ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
43552eabf88fSMatthew G. Knepley #if 1
43562eabf88fSMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fEndNew);
43572eabf88fSMatthew G. Knepley         for (p = 0; p < 2; ++p) {
43582eabf88fSMatthew G. Knepley           if ((supportNew[p] < cStartNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cEndNew);
43592eabf88fSMatthew G. Knepley         }
43602eabf88fSMatthew G. Knepley #endif
43612eabf88fSMatthew G. Knepley       }
43622eabf88fSMatthew G. Knepley     }
43632eabf88fSMatthew G. Knepley     /* Split edges have 2 vertices and the same faces as the parent */
43642eabf88fSMatthew G. Knepley     ierr = DMPlexGetMaxSizes(dm, NULL, &maxSupportSize);CHKERRQ(ierr);
43652eabf88fSMatthew G. Knepley     for (e = eStart; e < eEnd; ++e) {
43662eabf88fSMatthew G. Knepley       const PetscInt newv = vStartNew + (vEnd - vStart) + (e - eStart);
43672eabf88fSMatthew G. Knepley 
43682eabf88fSMatthew G. Knepley       for (r = 0; r < 2; ++r) {
43692eabf88fSMatthew G. Knepley         const PetscInt  newp = eStartNew + (e - eStart)*2 + r;
43702eabf88fSMatthew G. Knepley         const PetscInt *cone, *ornt, *support;
43712eabf88fSMatthew G. Knepley         PetscInt        coneNew[2], coneSize, c, supportSize, s;
43722eabf88fSMatthew G. Knepley 
43732eabf88fSMatthew G. Knepley         ierr             = DMPlexGetCone(dm, e, &cone);CHKERRQ(ierr);
43742eabf88fSMatthew G. Knepley         coneNew[0]       = vStartNew + (cone[0] - vStart);
43752eabf88fSMatthew G. Knepley         coneNew[1]       = vStartNew + (cone[1] - vStart);
43762eabf88fSMatthew G. Knepley         coneNew[(r+1)%2] = newv;
43772eabf88fSMatthew G. Knepley         ierr             = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
43782eabf88fSMatthew G. Knepley #if 1
43792eabf88fSMatthew G. Knepley         if ((newp < eStartNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eEndNew);
43802eabf88fSMatthew G. Knepley         for (p = 0; p < 2; ++p) {
43812eabf88fSMatthew G. Knepley           if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
43822eabf88fSMatthew G. Knepley         }
43832eabf88fSMatthew G. Knepley #endif
43842eabf88fSMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, e, &supportSize);CHKERRQ(ierr);
43852eabf88fSMatthew G. Knepley         ierr = DMPlexGetSupport(dm, e, &support);CHKERRQ(ierr);
43862eabf88fSMatthew G. Knepley         for (s = 0; s < supportSize; ++s) {
43872eabf88fSMatthew G. Knepley           ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr);
43882eabf88fSMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
43892eabf88fSMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, support[s], &ornt);CHKERRQ(ierr);
43902eabf88fSMatthew G. Knepley           for (c = 0; c < coneSize; ++c) {
43912eabf88fSMatthew G. Knepley             if (cone[c] == e) break;
43922eabf88fSMatthew G. Knepley           }
43932eabf88fSMatthew G. Knepley           supportRef[s] = fStartNew + (support[s] - fStart)*4 + (ornt[c] < 0 ? (c+1-r)%4 : (c+r)%4);
43942eabf88fSMatthew G. Knepley         }
43952eabf88fSMatthew G. Knepley         ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
43962eabf88fSMatthew G. Knepley #if 1
43972eabf88fSMatthew G. Knepley         if ((newp < eStartNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eEndNew);
43982eabf88fSMatthew G. Knepley         for (p = 0; p < supportSize; ++p) {
43992eabf88fSMatthew G. Knepley           if ((supportRef[p] < fStartNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", supportRef[p], fStartNew, fEndNew);
44002eabf88fSMatthew G. Knepley         }
44012eabf88fSMatthew G. Knepley #endif
44022eabf88fSMatthew G. Knepley       }
44032eabf88fSMatthew G. Knepley     }
44042eabf88fSMatthew G. Knepley     /* Face edges have 2 vertices and 2+cells faces */
44052eabf88fSMatthew G. Knepley     for (f = fStart; f < fEnd; ++f) {
44066b852384SMatthew G. Knepley       const PetscInt  newFaces[24] = {3, 2, 1, 0,  4, 5, 6, 7,  0, 9, 4, 8,  2, 11, 6, 10,  1, 10, 5, 9,  8, 7, 11, 3};
44072eabf88fSMatthew G. Knepley       const PetscInt  newv = vStartNew + (vEnd - vStart) + (eEnd - eStart) + (f - fStart);
44086b852384SMatthew G. Knepley       const PetscInt *cone, *coneCell, *orntCell, *support;
44092eabf88fSMatthew G. Knepley       PetscInt        coneNew[2], coneSize, c, supportSize, s;
44102eabf88fSMatthew G. Knepley 
44112eabf88fSMatthew G. Knepley       ierr = DMPlexGetCone(dm, f, &cone);CHKERRQ(ierr);
44122eabf88fSMatthew G. Knepley       for (r = 0; r < 4; ++r) {
44132eabf88fSMatthew G. Knepley         const PetscInt newp = eStartNew + (eEnd - eStart)*2 + (f - fStart)*4 + r;
44142eabf88fSMatthew G. Knepley 
44152eabf88fSMatthew G. Knepley         coneNew[0] = vStartNew + (vEnd - vStart) + (cone[r] - eStart);
44162eabf88fSMatthew G. Knepley         coneNew[1] = newv;
44172eabf88fSMatthew G. Knepley         ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
44182eabf88fSMatthew G. Knepley #if 1
44192eabf88fSMatthew G. Knepley         if ((newp < eStartNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eEndNew);
44202eabf88fSMatthew G. Knepley         for (p = 0; p < 2; ++p) {
44212eabf88fSMatthew G. Knepley           if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
44222eabf88fSMatthew G. Knepley         }
44232eabf88fSMatthew G. Knepley #endif
44242eabf88fSMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &supportSize);CHKERRQ(ierr);
44252eabf88fSMatthew G. Knepley         ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
44262eabf88fSMatthew G. Knepley         supportRef[0] = fStartNew + (f - fStart)*4 + r;
44272eabf88fSMatthew G. Knepley         supportRef[1] = fStartNew + (f - fStart)*4 + (r+1)%4;
44282eabf88fSMatthew G. Knepley         for (s = 0; s < supportSize; ++s) {
44296b852384SMatthew G. Knepley           ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr);
44306b852384SMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &coneCell);CHKERRQ(ierr);
44316b852384SMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, support[s], &orntCell);CHKERRQ(ierr);
44322eabf88fSMatthew G. Knepley           for (c = 0; c < coneSize; ++c) if (coneCell[c] == f) break;
4433a3cddbf8SMatthew G. Knepley           supportRef[2+s] = fStartNew + (fEnd - fStart)*4 + (support[s] - cStart)*12 + newFaces[c*4 + GetQuadEdgeInverse_Static(orntCell[c], r)];
44342eabf88fSMatthew G. Knepley         }
44352eabf88fSMatthew G. Knepley         ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
44362eabf88fSMatthew G. Knepley #if 1
44372eabf88fSMatthew G. Knepley         if ((newp < eStartNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eEndNew);
44382eabf88fSMatthew G. Knepley         for (p = 0; p < 2+supportSize; ++p) {
44392eabf88fSMatthew G. Knepley           if ((supportRef[p] < fStartNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", supportRef[p], fStartNew, fEndNew);
44402eabf88fSMatthew G. Knepley         }
44412eabf88fSMatthew G. Knepley #endif
44422eabf88fSMatthew G. Knepley       }
44432eabf88fSMatthew G. Knepley     }
44442eabf88fSMatthew G. Knepley     /* Cell edges have 2 vertices and 4 faces */
44452eabf88fSMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
44462eabf88fSMatthew G. Knepley       const PetscInt  newFaces[24] = {0, 1, 2, 3,  4, 5, 6, 7,  0, 9, 4, 8,  2, 11, 6, 10,  1, 10, 5, 9,  3, 8, 7, 11};
44472eabf88fSMatthew G. Knepley       const PetscInt  newv = vStartNew + (vEnd - vStart) + (eEnd - eStart) + (fEnd - fStart) + (c - cStart);
44482eabf88fSMatthew G. Knepley       const PetscInt *cone;
44492eabf88fSMatthew G. Knepley       PetscInt        coneNew[2], supportNew[4];
44502eabf88fSMatthew G. Knepley 
44512eabf88fSMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
44522eabf88fSMatthew G. Knepley       for (r = 0; r < 6; ++r) {
44532eabf88fSMatthew G. Knepley         const PetscInt newp = eStartNew + (eEnd - eStart)*2 + (fEnd - fStart)*4 + (c - cStart)*6 + r;
44542eabf88fSMatthew G. Knepley 
44552eabf88fSMatthew G. Knepley         coneNew[0] = vStartNew + (vEnd - vStart) + (eEnd - eStart) + (cone[r] - fStart);
44562eabf88fSMatthew G. Knepley         coneNew[1] = newv;
44572eabf88fSMatthew G. Knepley         ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
44582eabf88fSMatthew G. Knepley #if 1
44592eabf88fSMatthew G. Knepley         if ((newp < eStartNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eEndNew);
44602eabf88fSMatthew G. Knepley         for (p = 0; p < 2; ++p) {
44612eabf88fSMatthew G. Knepley           if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
44622eabf88fSMatthew G. Knepley         }
44632eabf88fSMatthew G. Knepley #endif
44642eabf88fSMatthew G. Knepley         for (f = 0; f < 4; ++f) supportNew[f] = fStartNew + (fEnd - fStart)*4 + (c - cStart)*12 + newFaces[r*4+f];
44652eabf88fSMatthew G. Knepley         ierr = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
44662eabf88fSMatthew G. Knepley #if 1
44672eabf88fSMatthew G. Knepley         if ((newp < eStartNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eEndNew);
44682eabf88fSMatthew G. Knepley         for (p = 0; p < 4; ++p) {
44692eabf88fSMatthew G. Knepley           if ((supportNew[p] < fStartNew) || (supportNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", supportNew[p], fStartNew, fEndNew);
44702eabf88fSMatthew G. Knepley         }
44712eabf88fSMatthew G. Knepley #endif
44722eabf88fSMatthew G. Knepley       }
44732eabf88fSMatthew G. Knepley     }
44742eabf88fSMatthew G. Knepley     /* Old vertices have identical supports */
44752eabf88fSMatthew G. Knepley     for (v = vStart; v < vEnd; ++v) {
44762eabf88fSMatthew G. Knepley       const PetscInt  newp = vStartNew + (v - vStart);
44772eabf88fSMatthew G. Knepley       const PetscInt *support, *cone;
44782eabf88fSMatthew G. Knepley       PetscInt        size, s;
44792eabf88fSMatthew G. Knepley 
44802eabf88fSMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, v, &size);CHKERRQ(ierr);
44812eabf88fSMatthew G. Knepley       ierr = DMPlexGetSupport(dm, v, &support);CHKERRQ(ierr);
44822eabf88fSMatthew G. Knepley       for (s = 0; s < size; ++s) {
44832eabf88fSMatthew G. Knepley         PetscInt r = 0;
44842eabf88fSMatthew G. Knepley 
44852eabf88fSMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
44862eabf88fSMatthew G. Knepley         if (cone[1] == v) r = 1;
44872eabf88fSMatthew G. Knepley         supportRef[s] = eStartNew + (support[s] - eStart)*2 + r;
44882eabf88fSMatthew G. Knepley       }
44892eabf88fSMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
44902eabf88fSMatthew G. Knepley #if 1
44912eabf88fSMatthew G. Knepley       if ((newp < vStartNew) || (newp >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", newp, vStartNew, vEndNew);
44922eabf88fSMatthew G. Knepley       for (p = 0; p < size; ++p) {
44932eabf88fSMatthew G. Knepley         if ((supportRef[p] < eStartNew) || (supportRef[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", supportRef[p], eStartNew, eEndNew);
44942eabf88fSMatthew G. Knepley       }
44952eabf88fSMatthew G. Knepley #endif
44962eabf88fSMatthew G. Knepley     }
44972eabf88fSMatthew G. Knepley     /* Edge vertices have 2 + faces supports */
44982eabf88fSMatthew G. Knepley     for (e = eStart; e < eEnd; ++e) {
44992eabf88fSMatthew G. Knepley       const PetscInt  newp = vStartNew + (vEnd - vStart) + (e - eStart);
45002eabf88fSMatthew G. Knepley       const PetscInt *cone, *support;
45012eabf88fSMatthew G. Knepley       PetscInt        size, s;
45022eabf88fSMatthew G. Knepley 
45032eabf88fSMatthew G. Knepley       ierr          = DMPlexGetSupportSize(dm, e, &size);CHKERRQ(ierr);
45042eabf88fSMatthew G. Knepley       ierr          = DMPlexGetSupport(dm, e, &support);CHKERRQ(ierr);
45052eabf88fSMatthew G. Knepley       supportRef[0] = eStartNew + (e - eStart)*2 + 0;
45062eabf88fSMatthew G. Knepley       supportRef[1] = eStartNew + (e - eStart)*2 + 1;
45072eabf88fSMatthew G. Knepley       for (s = 0; s < size; ++s) {
45082eabf88fSMatthew G. Knepley         PetscInt r;
45092eabf88fSMatthew G. Knepley 
45102eabf88fSMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
4511a660e16cSMatthew G. Knepley         for (r = 0; r < 4; ++r) if (cone[r] == e) break;
45122eabf88fSMatthew G. Knepley         supportRef[2+s] = eStartNew + (eEnd - eStart)*2 + (support[s] - fStart)*4 + r;
45132eabf88fSMatthew G. Knepley       }
45142eabf88fSMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
45152eabf88fSMatthew G. Knepley #if 1
45162eabf88fSMatthew G. Knepley       if ((newp < vStartNew) || (newp >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", newp, vStartNew, vEndNew);
45172eabf88fSMatthew G. Knepley       for (p = 0; p < 2+size; ++p) {
45182eabf88fSMatthew G. Knepley         if ((supportRef[p] < eStartNew) || (supportRef[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", supportRef[p], eStartNew, eEndNew);
45192eabf88fSMatthew G. Knepley       }
45202eabf88fSMatthew G. Knepley #endif
45212eabf88fSMatthew G. Knepley     }
45222eabf88fSMatthew G. Knepley     /* Face vertices have 4 + cells supports */
45232eabf88fSMatthew G. Knepley     for (f = fStart; f < fEnd; ++f) {
45242eabf88fSMatthew G. Knepley       const PetscInt  newp = vStartNew + (vEnd - vStart) + (eEnd - eStart) + (f - fStart);
45252eabf88fSMatthew G. Knepley       const PetscInt *cone, *support;
45262eabf88fSMatthew G. Knepley       PetscInt        size, s;
45272eabf88fSMatthew G. Knepley 
45282eabf88fSMatthew G. Knepley       ierr          = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
45292eabf88fSMatthew G. Knepley       ierr          = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
45300793999aSMatthew G. Knepley       for (r = 0; r < 4; ++r) supportRef[r] = eStartNew + (eEnd - eStart)*2 +  (f - fStart)*4 + r;
45312eabf88fSMatthew G. Knepley       for (s = 0; s < size; ++s) {
45322eabf88fSMatthew G. Knepley         PetscInt r;
45332eabf88fSMatthew G. Knepley 
45342eabf88fSMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
45352eabf88fSMatthew G. Knepley         for (r = 0; r < 6; ++r) if (cone[r] == f) break;
45362eabf88fSMatthew G. Knepley         supportRef[4+s] = eStartNew + (eEnd - eStart)*2 + (fEnd - fStart)*4 + (support[s] - cStart)*6 + r;
45372eabf88fSMatthew G. Knepley       }
45382eabf88fSMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
45392eabf88fSMatthew G. Knepley #if 1
45402eabf88fSMatthew G. Knepley       if ((newp < vStartNew) || (newp >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", newp, vStartNew, vEndNew);
45412eabf88fSMatthew G. Knepley       for (p = 0; p < 4+size; ++p) {
45422eabf88fSMatthew G. Knepley         if ((supportRef[p] < eStartNew) || (supportRef[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", supportRef[p], eStartNew, eEndNew);
45432eabf88fSMatthew G. Knepley       }
45442eabf88fSMatthew G. Knepley #endif
45452eabf88fSMatthew G. Knepley     }
45462eabf88fSMatthew G. Knepley     /* Cell vertices have 6 supports */
45472eabf88fSMatthew G. Knepley     for (c = cStart; c < cEnd; ++c) {
45482eabf88fSMatthew G. Knepley       const PetscInt newp = vStartNew + (vEnd - vStart) + (eEnd - eStart) + (fEnd - fStart) + (c - cStart);
45492eabf88fSMatthew G. Knepley       PetscInt       supportNew[6];
45502eabf88fSMatthew G. Knepley 
45512eabf88fSMatthew G. Knepley       for (r = 0; r < 6; ++r) {
45522eabf88fSMatthew G. Knepley         supportNew[r] = eStartNew + (eEnd - eStart)*2 + (fEnd - fStart)*4 + (c - cStart)*6 + r;
45532eabf88fSMatthew G. Knepley       }
45542eabf88fSMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
45552eabf88fSMatthew G. Knepley     }
4556da00770fSMatthew G. Knepley     ierr = PetscFree(supportRef);CHKERRQ(ierr);
45572eabf88fSMatthew G. Knepley     break;
45589b1a0e7fSLawrence Mitchell   case REFINER_HYBRID_HEX_3D:
455927fcede3SMatthew G. Knepley     ierr = DMPlexGetHybridBounds(rdm, &cMaxNew, &fMaxNew, &eMaxNew, NULL);CHKERRQ(ierr);
456027fcede3SMatthew G. Knepley     /*
456127fcede3SMatthew G. Knepley      Bottom (viewed from top)    Top
456227fcede3SMatthew G. Knepley      1---------2---------2       7---------2---------6
456327fcede3SMatthew G. Knepley      |         |         |       |         |         |
456427fcede3SMatthew G. Knepley      |    B    2    C    |       |    H    2    G    |
456527fcede3SMatthew G. Knepley      |         |         |       |         |         |
456627fcede3SMatthew G. Knepley      3----3----0----1----1       3----3----0----1----1
456727fcede3SMatthew G. Knepley      |         |         |       |         |         |
456827fcede3SMatthew G. Knepley      |    A    0    D    |       |    E    0    F    |
456927fcede3SMatthew G. Knepley      |         |         |       |         |         |
457027fcede3SMatthew G. Knepley      0---------0---------3       4---------0---------5
457127fcede3SMatthew G. Knepley      */
457227fcede3SMatthew G. Knepley     /* Interior cells have 6 faces: Bottom, Top, Front, Back, Right, Left */
457327fcede3SMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
457427fcede3SMatthew G. Knepley       const PetscInt  newp = (c - cStart)*8;
457527fcede3SMatthew G. Knepley       const PetscInt *cone, *ornt;
457627fcede3SMatthew G. Knepley       PetscInt        coneNew[6], orntNew[6];
457727fcede3SMatthew G. Knepley 
457827fcede3SMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
457927fcede3SMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr);
458027fcede3SMatthew G. Knepley       /* A hex */
458127fcede3SMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*4 + GetQuadSubface_Static(ornt[0], 0);
458227fcede3SMatthew G. Knepley       orntNew[0] = ornt[0];
458327fcede3SMatthew G. Knepley       coneNew[1] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 +  8; /* AE */
458427fcede3SMatthew G. Knepley       orntNew[1] = 0;
458527fcede3SMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*4 + GetQuadSubface_Static(ornt[2], 0);
458627fcede3SMatthew G. Knepley       orntNew[2] = ornt[2];
458727fcede3SMatthew G. Knepley       coneNew[3] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 +  3; /* AB */
458827fcede3SMatthew G. Knepley       orntNew[3] = 0;
458927fcede3SMatthew G. Knepley       coneNew[4] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 +  0; /* AD */
459027fcede3SMatthew G. Knepley       orntNew[4] = 0;
459127fcede3SMatthew G. Knepley       coneNew[5] = fStartNew + (cone[5] - fStart)*4 + GetQuadSubface_Static(ornt[5], 0);
459227fcede3SMatthew G. Knepley       orntNew[5] = ornt[5];
459327fcede3SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+0, coneNew);CHKERRQ(ierr);
459427fcede3SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+0, orntNew);CHKERRQ(ierr);
459527fcede3SMatthew G. Knepley #if 1
459627fcede3SMatthew G. Knepley       if ((newp+0 < cStartNew) || (newp+0 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+0, cStartNew, cMaxNew);
459727fcede3SMatthew G. Knepley       for (p = 0; p < 6; ++p) {
459827fcede3SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
459927fcede3SMatthew G. Knepley       }
460027fcede3SMatthew G. Knepley #endif
460127fcede3SMatthew G. Knepley       /* B hex */
460227fcede3SMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*4 + GetQuadSubface_Static(ornt[0], 1);
460327fcede3SMatthew G. Knepley       orntNew[0] = ornt[0];
460427fcede3SMatthew G. Knepley       coneNew[1] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 + 11; /* BH */
460527fcede3SMatthew G. Knepley       orntNew[1] = 0;
460627fcede3SMatthew G. Knepley       coneNew[2] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 +  3; /* AB */
460727fcede3SMatthew G. Knepley       orntNew[2] = -1;
460827fcede3SMatthew G. Knepley       coneNew[3] = fStartNew + (cone[3] - fStart)*4 + GetQuadSubface_Static(ornt[3], 1);
460927fcede3SMatthew G. Knepley       orntNew[3] = ornt[3];
461027fcede3SMatthew G. Knepley       coneNew[4] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 +  2; /* BC */
461127fcede3SMatthew G. Knepley       orntNew[4] = 0;
461227fcede3SMatthew G. Knepley       coneNew[5] = fStartNew + (cone[5] - fStart)*4 + GetQuadSubface_Static(ornt[5], 3);
461327fcede3SMatthew G. Knepley       orntNew[5] = ornt[5];
461427fcede3SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+1, coneNew);CHKERRQ(ierr);
461527fcede3SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+1, orntNew);CHKERRQ(ierr);
461627fcede3SMatthew G. Knepley #if 1
461727fcede3SMatthew G. Knepley       if ((newp+1 < cStartNew) || (newp+1 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+1, cStartNew, cMaxNew);
461827fcede3SMatthew G. Knepley       for (p = 0; p < 6; ++p) {
461927fcede3SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
462027fcede3SMatthew G. Knepley       }
462127fcede3SMatthew G. Knepley #endif
462227fcede3SMatthew G. Knepley       /* C hex */
462327fcede3SMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*4 + GetQuadSubface_Static(ornt[0], 2);
462427fcede3SMatthew G. Knepley       orntNew[0] = ornt[0];
462527fcede3SMatthew G. Knepley       coneNew[1] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 + 10; /* CG */
462627fcede3SMatthew G. Knepley       orntNew[1] = 0;
462727fcede3SMatthew G. Knepley       coneNew[2] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 +  1; /* CD */
462827fcede3SMatthew G. Knepley       orntNew[2] = -1;
462927fcede3SMatthew G. Knepley       coneNew[3] = fStartNew + (cone[3] - fStart)*4 + GetQuadSubface_Static(ornt[3], 0);
463027fcede3SMatthew G. Knepley       orntNew[3] = ornt[3];
463127fcede3SMatthew G. Knepley       coneNew[4] = fStartNew + (cone[4] - fStart)*4 + GetQuadSubface_Static(ornt[4], 1);
463227fcede3SMatthew G. Knepley       orntNew[4] = ornt[4];
463327fcede3SMatthew G. Knepley       coneNew[5] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 +  2; /* BC */
463427fcede3SMatthew G. Knepley       orntNew[5] = -4;
463527fcede3SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+2, coneNew);CHKERRQ(ierr);
463627fcede3SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+2, orntNew);CHKERRQ(ierr);
463727fcede3SMatthew G. Knepley #if 1
463827fcede3SMatthew G. Knepley       if ((newp+2 < cStartNew) || (newp+2 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+2, cStartNew, cMaxNew);
463927fcede3SMatthew G. Knepley       for (p = 0; p < 6; ++p) {
464027fcede3SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
464127fcede3SMatthew G. Knepley       }
464227fcede3SMatthew G. Knepley #endif
464327fcede3SMatthew G. Knepley       /* D hex */
464427fcede3SMatthew G. Knepley       coneNew[0] = fStartNew + (cone[0] - fStart)*4 + GetQuadSubface_Static(ornt[0], 3);
464527fcede3SMatthew G. Knepley       orntNew[0] = ornt[0];
464627fcede3SMatthew G. Knepley       coneNew[1] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 +  9; /* DF */
464727fcede3SMatthew G. Knepley       orntNew[1] = 0;
464827fcede3SMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*4 + GetQuadSubface_Static(ornt[2], 1);
464927fcede3SMatthew G. Knepley       orntNew[2] = ornt[2];
465027fcede3SMatthew G. Knepley       coneNew[3] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 +  1; /* CD */
465127fcede3SMatthew G. Knepley       orntNew[3] = 0;
465227fcede3SMatthew G. Knepley       coneNew[4] = fStartNew + (cone[4] - fStart)*4 + GetQuadSubface_Static(ornt[4], 0);
465327fcede3SMatthew G. Knepley       orntNew[4] = ornt[4];
465427fcede3SMatthew G. Knepley       coneNew[5] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 +  0; /* AD */
465527fcede3SMatthew G. Knepley       orntNew[5] = -4;
465627fcede3SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+3, coneNew);CHKERRQ(ierr);
465727fcede3SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+3, orntNew);CHKERRQ(ierr);
465827fcede3SMatthew G. Knepley #if 1
465927fcede3SMatthew G. Knepley       if ((newp+3 < cStartNew) || (newp+3 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+3, cStartNew, cMaxNew);
466027fcede3SMatthew G. Knepley       for (p = 0; p < 6; ++p) {
466127fcede3SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
466227fcede3SMatthew G. Knepley       }
466327fcede3SMatthew G. Knepley #endif
466427fcede3SMatthew G. Knepley       /* E hex */
466527fcede3SMatthew G. Knepley       coneNew[0] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 +  8; /* AE */
466627fcede3SMatthew G. Knepley       orntNew[0] = -4;
466727fcede3SMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*4 + GetQuadSubface_Static(ornt[1], 0);
466827fcede3SMatthew G. Knepley       orntNew[1] = ornt[1];
466927fcede3SMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*4 + GetQuadSubface_Static(ornt[2], 3);
467027fcede3SMatthew G. Knepley       orntNew[2] = ornt[2];
467127fcede3SMatthew G. Knepley       coneNew[3] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 +  7; /* EH */
467227fcede3SMatthew G. Knepley       orntNew[3] = 0;
467327fcede3SMatthew G. Knepley       coneNew[4] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 +  4; /* EF */
467427fcede3SMatthew G. Knepley       orntNew[4] = -1;
467527fcede3SMatthew G. Knepley       coneNew[5] = fStartNew + (cone[5] - fStart)*4 + GetQuadSubface_Static(ornt[5], 1);
467627fcede3SMatthew G. Knepley       orntNew[5] = ornt[5];
467727fcede3SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+4, coneNew);CHKERRQ(ierr);
467827fcede3SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+4, orntNew);CHKERRQ(ierr);
467927fcede3SMatthew G. Knepley #if 1
468027fcede3SMatthew G. Knepley       if ((newp+4 < cStartNew) || (newp+4 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+4, cStartNew, cMaxNew);
468127fcede3SMatthew G. Knepley       for (p = 0; p < 6; ++p) {
468227fcede3SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
468327fcede3SMatthew G. Knepley       }
468427fcede3SMatthew G. Knepley #endif
468527fcede3SMatthew G. Knepley       /* F hex */
468627fcede3SMatthew G. Knepley       coneNew[0] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 +  9; /* DF */
468727fcede3SMatthew G. Knepley       orntNew[0] = -4;
468827fcede3SMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*4 + GetQuadSubface_Static(ornt[1], 1);
468927fcede3SMatthew G. Knepley       orntNew[1] = ornt[1];
469027fcede3SMatthew G. Knepley       coneNew[2] = fStartNew + (cone[2] - fStart)*4 + GetQuadSubface_Static(ornt[2], 2);
469127fcede3SMatthew G. Knepley       orntNew[2] = ornt[2];
469227fcede3SMatthew G. Knepley       coneNew[3] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 +  5; /* FG */
469327fcede3SMatthew G. Knepley       orntNew[3] = -1;
469427fcede3SMatthew G. Knepley       coneNew[4] = fStartNew + (cone[4] - fStart)*4 + GetQuadSubface_Static(ornt[4], 3);
469527fcede3SMatthew G. Knepley       orntNew[4] = ornt[4];
469627fcede3SMatthew G. Knepley       coneNew[5] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 +  4; /* EF */
469727fcede3SMatthew G. Knepley       orntNew[5] = 1;
469827fcede3SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+5, coneNew);CHKERRQ(ierr);
469927fcede3SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+5, orntNew);CHKERRQ(ierr);
470027fcede3SMatthew G. Knepley #if 1
470127fcede3SMatthew G. Knepley       if ((newp+5 < cStartNew) || (newp+5 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+5, cStartNew, cMaxNew);
470227fcede3SMatthew G. Knepley       for (p = 0; p < 6; ++p) {
470327fcede3SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
470427fcede3SMatthew G. Knepley       }
470527fcede3SMatthew G. Knepley #endif
470627fcede3SMatthew G. Knepley       /* G hex */
470727fcede3SMatthew G. Knepley       coneNew[0] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 + 10; /* CG */
470827fcede3SMatthew G. Knepley       orntNew[0] = -4;
470927fcede3SMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*4 + GetQuadSubface_Static(ornt[1], 2);
471027fcede3SMatthew G. Knepley       orntNew[1] = ornt[1];
471127fcede3SMatthew G. Knepley       coneNew[2] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 +  5; /* FG */
471227fcede3SMatthew G. Knepley       orntNew[2] = 0;
471327fcede3SMatthew G. Knepley       coneNew[3] = fStartNew + (cone[3] - fStart)*4 + GetQuadSubface_Static(ornt[3], 3);
471427fcede3SMatthew G. Knepley       orntNew[3] = ornt[3];
471527fcede3SMatthew G. Knepley       coneNew[4] = fStartNew + (cone[4] - fStart)*4 + GetQuadSubface_Static(ornt[4], 2);
471627fcede3SMatthew G. Knepley       orntNew[4] = ornt[4];
471727fcede3SMatthew G. Knepley       coneNew[5] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 +  6; /* GH */
471827fcede3SMatthew G. Knepley       orntNew[5] = -3;
471927fcede3SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+6, coneNew);CHKERRQ(ierr);
472027fcede3SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+6, orntNew);CHKERRQ(ierr);
472127fcede3SMatthew G. Knepley #if 1
472227fcede3SMatthew G. Knepley       if ((newp+6 < cStartNew) || (newp+6 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+6, cStartNew, cMaxNew);
472327fcede3SMatthew G. Knepley       for (p = 0; p < 6; ++p) {
472427fcede3SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
472527fcede3SMatthew G. Knepley       }
472627fcede3SMatthew G. Knepley #endif
472727fcede3SMatthew G. Knepley       /* H hex */
472827fcede3SMatthew G. Knepley       coneNew[0] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 + 11; /* BH */
472927fcede3SMatthew G. Knepley       orntNew[0] = -4;
473027fcede3SMatthew G. Knepley       coneNew[1] = fStartNew + (cone[1] - fStart)*4 + GetQuadSubface_Static(ornt[1], 3);
473127fcede3SMatthew G. Knepley       orntNew[1] = ornt[1];
473227fcede3SMatthew G. Knepley       coneNew[2] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 +  7; /* EH */
473327fcede3SMatthew G. Knepley       orntNew[2] = -1;
473427fcede3SMatthew G. Knepley       coneNew[3] = fStartNew + (cone[3] - fStart)*4 + GetQuadSubface_Static(ornt[3], 2);
473527fcede3SMatthew G. Knepley       orntNew[3] = ornt[3];
473627fcede3SMatthew G. Knepley       coneNew[4] = fStartNew + (fMax    - fStart)*4 + (c - cStart)*12 +  6; /* GH */
473727fcede3SMatthew G. Knepley       orntNew[4] = 3;
473827fcede3SMatthew G. Knepley       coneNew[5] = fStartNew + (cone[5] - fStart)*4 + GetQuadSubface_Static(ornt[5], 2);
473927fcede3SMatthew G. Knepley       orntNew[5] = ornt[5];
474027fcede3SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp+7, coneNew);CHKERRQ(ierr);
474127fcede3SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp+7, orntNew);CHKERRQ(ierr);
474227fcede3SMatthew G. Knepley #if 1
474327fcede3SMatthew G. Knepley       if ((newp+7 < cStartNew) || (newp+7 >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", newp+7, cStartNew, cMaxNew);
474427fcede3SMatthew G. Knepley       for (p = 0; p < 6; ++p) {
474527fcede3SMatthew G. Knepley         if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
474627fcede3SMatthew G. Knepley       }
474727fcede3SMatthew G. Knepley #endif
474827fcede3SMatthew G. Knepley     }
474927fcede3SMatthew G. Knepley     /* Hybrid cells have 6 faces: Front, Back, Sides */
475027fcede3SMatthew G. Knepley     /*
475127fcede3SMatthew G. Knepley      3---------2---------2
475227fcede3SMatthew G. Knepley      |         |         |
475327fcede3SMatthew G. Knepley      |    D    2    C    |
475427fcede3SMatthew G. Knepley      |         |         |
475527fcede3SMatthew G. Knepley      3----3----0----1----1
475627fcede3SMatthew G. Knepley      |         |         |
475727fcede3SMatthew G. Knepley      |    A    0    B    |
475827fcede3SMatthew G. Knepley      |         |         |
475927fcede3SMatthew G. Knepley      0---------0---------1
476027fcede3SMatthew G. Knepley      */
476127fcede3SMatthew G. Knepley     for (c = cMax; c < cEnd; ++c) {
476227fcede3SMatthew G. Knepley       const PetscInt  newp = (cMax - cStart)*8 + (c - cMax)*4;
476327fcede3SMatthew G. Knepley       const PetscInt *cone, *ornt, *fornt;
4764d273725eSMatthew G. Knepley       PetscInt        coneNew[6], orntNew[6], o, of, i;
476527fcede3SMatthew G. Knepley 
476627fcede3SMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
476727fcede3SMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr);
476827fcede3SMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, cone[0], &fornt);CHKERRQ(ierr);
4769d273725eSMatthew G. Knepley       o = ornt[0] < 0 ? -1 : 1;
477027fcede3SMatthew G. Knepley       for (r = 0; r < 4; ++r) {
477127fcede3SMatthew G. Knepley         PetscInt subfA = GetQuadSubface_Static(ornt[0], r);
477227fcede3SMatthew G. Knepley         PetscInt edgeA = GetQuadEdge_Static(ornt[0], r);
4773d273725eSMatthew G. Knepley         PetscInt edgeB = GetQuadEdge_Static(ornt[0], (r+3)%4);
477427fcede3SMatthew G. Knepley         if (ornt[0] != ornt[1]) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Inconsistent ordering for matching ends of hybrid cell %d: %d != %d", c, ornt[0], ornt[1]);
477527fcede3SMatthew G. Knepley         coneNew[0]         = fStartNew + (cone[0] - fStart)*4 + subfA;
477627fcede3SMatthew G. Knepley         orntNew[0]         = ornt[0];
477727fcede3SMatthew G. Knepley         coneNew[1]         = fStartNew + (cone[1] - fStart)*4 + subfA;
477827fcede3SMatthew G. Knepley         orntNew[1]         = ornt[0];
4779d273725eSMatthew G. Knepley         of = fornt[edgeA] < 0 ? -1 : 1;
4780d273725eSMatthew G. Knepley         i  = GetQuadEdgeInverse_Static(ornt[0], r) + 2;
4781d273725eSMatthew G. Knepley         coneNew[i] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*12 + (cone[2+edgeA] - fMax)*2 + (o*of < 0 ? 1 : 0);
4782d273725eSMatthew G. Knepley         orntNew[i] = ornt[edgeA];
4783d273725eSMatthew G. Knepley         i  = GetQuadEdgeInverse_Static(ornt[0], (r+1)%4) + 2;
4784d273725eSMatthew G. Knepley         coneNew[i] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*12 + (fEnd          - fMax)*2 + (c - cMax)*4 + edgeA;
4785d273725eSMatthew G. Knepley         orntNew[i] = 0;
4786d273725eSMatthew G. Knepley         i  = GetQuadEdgeInverse_Static(ornt[0], (r+2)%4) + 2;
4787d273725eSMatthew G. Knepley         coneNew[i] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*12 + (fEnd          - fMax)*2 + (c - cMax)*4 + edgeB;
4788d273725eSMatthew G. Knepley         orntNew[i] = -2;
4789d273725eSMatthew G. Knepley         of = fornt[edgeB] < 0 ? -1 : 1;
4790d273725eSMatthew G. Knepley         i  = GetQuadEdgeInverse_Static(ornt[0], (r+3)%4) + 2;
4791d273725eSMatthew G. Knepley         coneNew[i] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*12 + (cone[2+edgeB] - fMax)*2 + (o*of < 0 ? 0 : 1);
4792d273725eSMatthew G. Knepley         orntNew[i] = ornt[edgeB];
479327fcede3SMatthew G. Knepley         ierr       = DMPlexSetCone(rdm, newp+r, coneNew);CHKERRQ(ierr);
479427fcede3SMatthew G. Knepley         ierr       = DMPlexSetConeOrientation(rdm, newp+r, orntNew);CHKERRQ(ierr);
479527fcede3SMatthew G. Knepley #if 1
479627fcede3SMatthew G. Knepley         if ((newp+r < cMaxNew) || (newp+r >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid cell [%d, %d)", newp+r, cMaxNew, cEndNew);
479727fcede3SMatthew G. Knepley         for (p = 0; p < 2; ++p) {
479827fcede3SMatthew G. Knepley           if ((coneNew[p] < fStartNew) || (coneNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", coneNew[p], fStartNew, fMaxNew);
479927fcede3SMatthew G. Knepley         }
480027fcede3SMatthew G. Knepley         for (p = 2; p < 6; ++p) {
480127fcede3SMatthew G. Knepley           if ((coneNew[p] < fMaxNew) || (coneNew[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid face [%d, %d)", coneNew[p], fMaxNew, fEndNew);
480227fcede3SMatthew G. Knepley         }
480327fcede3SMatthew G. Knepley #endif
480427fcede3SMatthew G. Knepley       }
480527fcede3SMatthew G. Knepley     }
480627fcede3SMatthew G. Knepley     /* Interior split faces have 4 edges and the same cells as the parent */
480727fcede3SMatthew G. Knepley     ierr = DMPlexGetMaxSizes(dm, NULL, &maxSupportSize);CHKERRQ(ierr);
4808854ce69bSBarry Smith     ierr = PetscMalloc1(4 + maxSupportSize*2, &supportRef);CHKERRQ(ierr);
480927fcede3SMatthew G. Knepley     for (f = fStart; f < fMax; ++f) {
481027fcede3SMatthew G. Knepley       for (r = 0; r < 4; ++r) {
481127fcede3SMatthew G. Knepley         /* TODO: This can come from GetFaces_Internal() */
481227fcede3SMatthew G. Knepley         const PetscInt  newCells[24] = {0, 1, 2, 3,  4, 5, 6, 7,  0, 3, 5, 4,  2, 1, 7, 6,  3, 2, 6, 5,  0, 4, 7, 1};
481327fcede3SMatthew G. Knepley         const PetscInt  newp = fStartNew + (f - fStart)*4 + r;
481427fcede3SMatthew G. Knepley         const PetscInt *cone, *ornt, *support;
481527fcede3SMatthew G. Knepley         PetscInt        coneNew[4], orntNew[4], coneSize, c, supportSize, s;
481627fcede3SMatthew G. Knepley 
481727fcede3SMatthew G. Knepley         ierr = DMPlexGetCone(dm, f, &cone);CHKERRQ(ierr);
481827fcede3SMatthew G. Knepley         ierr = DMPlexGetConeOrientation(dm, f, &ornt);CHKERRQ(ierr);
481927fcede3SMatthew G. Knepley         coneNew[(r+3)%4] = eStartNew + (cone[(r+3)%4] - eStart)*2 + (ornt[(r+3)%4] < 0 ? 0 : 1);
482027fcede3SMatthew G. Knepley         orntNew[(r+3)%4] = ornt[(r+3)%4];
482127fcede3SMatthew G. Knepley         coneNew[(r+0)%4] = eStartNew + (cone[r]       - eStart)*2 + (ornt[r] < 0 ? 1 : 0);
482227fcede3SMatthew G. Knepley         orntNew[(r+0)%4] = ornt[r];
482327fcede3SMatthew G. Knepley         coneNew[(r+1)%4] = eStartNew + (eMax - eStart)*2 + (f - fStart)*4 + r;
482427fcede3SMatthew G. Knepley         orntNew[(r+1)%4] = 0;
482527fcede3SMatthew G. Knepley         coneNew[(r+2)%4] = eStartNew + (eMax - eStart)*2 + (f - fStart)*4 + (r+3)%4;
482627fcede3SMatthew G. Knepley         orntNew[(r+2)%4] = -2;
482727fcede3SMatthew G. Knepley         ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
482827fcede3SMatthew G. Knepley         ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
482927fcede3SMatthew G. Knepley #if 1
483027fcede3SMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
483127fcede3SMatthew G. Knepley         for (p = 0; p < 4; ++p) {
483227fcede3SMatthew G. Knepley           if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
483327fcede3SMatthew G. Knepley         }
483427fcede3SMatthew G. Knepley #endif
483527fcede3SMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &supportSize);CHKERRQ(ierr);
483627fcede3SMatthew G. Knepley         ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
483727fcede3SMatthew G. Knepley         for (s = 0; s < supportSize; ++s) {
483827fcede3SMatthew G. Knepley           PetscInt subf;
483927fcede3SMatthew G. Knepley           ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr);
484027fcede3SMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
484127fcede3SMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, support[s], &ornt);CHKERRQ(ierr);
484227fcede3SMatthew G. Knepley           for (c = 0; c < coneSize; ++c) {
484327fcede3SMatthew G. Knepley             if (cone[c] == f) break;
484427fcede3SMatthew G. Knepley           }
484527fcede3SMatthew G. Knepley           subf = GetQuadSubfaceInverse_Static(ornt[c], r);
484627fcede3SMatthew G. Knepley           if (support[s] < cMax) {
484727fcede3SMatthew G. Knepley             supportRef[s] = cStartNew + (support[s] - cStart)*8 + newCells[c*4+subf];
484827fcede3SMatthew G. Knepley           } else {
484927fcede3SMatthew G. Knepley             supportRef[s] = cStartNew + (cMax       - cStart)*8 + (support[s] - cMax)*4 + subf;
485027fcede3SMatthew G. Knepley           }
485127fcede3SMatthew G. Knepley         }
485227fcede3SMatthew G. Knepley         ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
485327fcede3SMatthew G. Knepley #if 1
485427fcede3SMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
485527fcede3SMatthew G. Knepley         for (p = 0; p < supportSize; ++p) {
485627fcede3SMatthew G. Knepley           if ((supportRef[p] < cStartNew) || (supportRef[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportRef[p], cStartNew, cEndNew);
485727fcede3SMatthew G. Knepley         }
485827fcede3SMatthew G. Knepley #endif
485927fcede3SMatthew G. Knepley       }
486027fcede3SMatthew G. Knepley     }
4861d273725eSMatthew G. Knepley     /* Interior cell faces have 4 edges and 2 cells */
486227fcede3SMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
486327fcede3SMatthew G. Knepley       const PetscInt  newCells[24] = {0, 3,  2, 3,  1, 2,  0, 1,  4, 5,  5, 6,  6, 7,  4, 7,  0, 4,  3, 5,  2, 6,  1, 7};
486427fcede3SMatthew G. Knepley       const PetscInt *cone, *ornt;
486527fcede3SMatthew G. Knepley       PetscInt        newp, coneNew[4], orntNew[4], supportNew[2];
486627fcede3SMatthew G. Knepley 
486727fcede3SMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
486827fcede3SMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr);
486927fcede3SMatthew G. Knepley       /* A-D face */
487027fcede3SMatthew G. Knepley       newp = fStartNew + (fMax - fStart)*4 + (c - cStart)*12 + 0;
487127fcede3SMatthew G. Knepley       coneNew[0] = eStartNew + (eMax - eStart)*2 + (cone[0] - fStart)*4 + GetQuadEdge_Static(ornt[0], 3);
487227fcede3SMatthew G. Knepley       orntNew[0] = 0;
487327fcede3SMatthew G. Knepley       coneNew[1] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 0;
487427fcede3SMatthew G. Knepley       orntNew[1] = 0;
487527fcede3SMatthew G. Knepley       coneNew[2] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 2;
487627fcede3SMatthew G. Knepley       orntNew[2] = -2;
487727fcede3SMatthew G. Knepley       coneNew[3] = eStartNew + (eMax - eStart)*2 + (cone[2] - fStart)*4 + GetQuadEdge_Static(ornt[2], 0);
487827fcede3SMatthew G. Knepley       orntNew[3] = -2;
487927fcede3SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
488027fcede3SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
488127fcede3SMatthew G. Knepley #if 1
488227fcede3SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
488327fcede3SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
488427fcede3SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
488527fcede3SMatthew G. Knepley       }
488627fcede3SMatthew G. Knepley #endif
488727fcede3SMatthew G. Knepley       /* C-D face */
488827fcede3SMatthew G. Knepley       newp = fStartNew + (fMax - fStart)*4 + (c - cStart)*12 + 1;
488927fcede3SMatthew G. Knepley       coneNew[0] = eStartNew + (eMax - eStart)*2 + (cone[0] - fStart)*4 + GetQuadEdge_Static(ornt[0], 2);
489027fcede3SMatthew G. Knepley       orntNew[0] = 0;
489127fcede3SMatthew G. Knepley       coneNew[1] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 0;
489227fcede3SMatthew G. Knepley       orntNew[1] = 0;
489327fcede3SMatthew G. Knepley       coneNew[2] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 4;
489427fcede3SMatthew G. Knepley       orntNew[2] = -2;
489527fcede3SMatthew G. Knepley       coneNew[3] = eStartNew + (eMax - eStart)*2 + (cone[4] - fStart)*4 + GetQuadEdge_Static(ornt[4], 0);
489627fcede3SMatthew G. Knepley       orntNew[3] = -2;
489727fcede3SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
489827fcede3SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
489927fcede3SMatthew G. Knepley #if 1
490027fcede3SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
490127fcede3SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
490227fcede3SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
490327fcede3SMatthew G. Knepley       }
490427fcede3SMatthew G. Knepley #endif
490527fcede3SMatthew G. Knepley       /* B-C face */
490627fcede3SMatthew G. Knepley       newp = fStartNew + (fMax - fStart)*4 + (c - cStart)*12 + 2;
490727fcede3SMatthew G. Knepley       coneNew[0] = eStartNew + (eMax - eStart)*2 + (cone[0] - fStart)*4 + GetQuadEdge_Static(ornt[0], 1);
490827fcede3SMatthew G. Knepley       orntNew[0] = -2;
490927fcede3SMatthew G. Knepley       coneNew[1] = eStartNew + (eMax - eStart)*2 + (cone[3] - fStart)*4 + GetQuadEdge_Static(ornt[3], 0);
491027fcede3SMatthew G. Knepley       orntNew[1] = 0;
491127fcede3SMatthew G. Knepley       coneNew[2] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 3;
491227fcede3SMatthew G. Knepley       orntNew[2] = 0;
491327fcede3SMatthew G. Knepley       coneNew[3] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 0;
491427fcede3SMatthew G. Knepley       orntNew[3] = -2;
491527fcede3SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
491627fcede3SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
491727fcede3SMatthew G. Knepley #if 1
491827fcede3SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
491927fcede3SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
492027fcede3SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
492127fcede3SMatthew G. Knepley       }
492227fcede3SMatthew G. Knepley #endif
492327fcede3SMatthew G. Knepley       /* A-B face */
492427fcede3SMatthew G. Knepley       newp = fStartNew + (fMax - fStart)*4 + (c - cStart)*12 + 3;
492527fcede3SMatthew G. Knepley       coneNew[0] = eStartNew + (eMax - eStart)*2 + (cone[0] - fStart)*4 + GetQuadEdge_Static(ornt[0], 0);
492627fcede3SMatthew G. Knepley       orntNew[0] = -2;
492727fcede3SMatthew G. Knepley       coneNew[1] = eStartNew + (eMax - eStart)*2 + (cone[5] - fStart)*4 + GetQuadEdge_Static(ornt[5], 3);
492827fcede3SMatthew G. Knepley       orntNew[1] = 0;
492927fcede3SMatthew G. Knepley       coneNew[2] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 5;
493027fcede3SMatthew G. Knepley       orntNew[2] = 0;
493127fcede3SMatthew G. Knepley       coneNew[3] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 0;
493227fcede3SMatthew G. Knepley       orntNew[3] = -2;
493327fcede3SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
493427fcede3SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
493527fcede3SMatthew G. Knepley #if 1
493627fcede3SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
493727fcede3SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
493827fcede3SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
493927fcede3SMatthew G. Knepley       }
494027fcede3SMatthew G. Knepley #endif
494127fcede3SMatthew G. Knepley       /* E-F face */
494227fcede3SMatthew G. Knepley       newp = fStartNew + (fMax - fStart)*4 + (c - cStart)*12 + 4;
494327fcede3SMatthew G. Knepley       coneNew[0] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 2;
494427fcede3SMatthew G. Knepley       orntNew[0] = -2;
494527fcede3SMatthew G. Knepley       coneNew[1] = eStartNew + (eMax - eStart)*2 + (cone[2] - fStart)*4 + GetQuadEdge_Static(ornt[2], 2);
494627fcede3SMatthew G. Knepley       orntNew[1] = -2;
494727fcede3SMatthew G. Knepley       coneNew[2] = eStartNew + (eMax - eStart)*2 + (cone[1] - fStart)*4 + GetQuadEdge_Static(ornt[1], 0);
494827fcede3SMatthew G. Knepley       orntNew[2] = 0;
494927fcede3SMatthew G. Knepley       coneNew[3] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 1;
495027fcede3SMatthew G. Knepley       orntNew[3] = 0;
495127fcede3SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
495227fcede3SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
495327fcede3SMatthew G. Knepley #if 1
495427fcede3SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
495527fcede3SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
495627fcede3SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
495727fcede3SMatthew G. Knepley       }
495827fcede3SMatthew G. Knepley #endif
495927fcede3SMatthew G. Knepley       /* F-G face */
496027fcede3SMatthew G. Knepley       newp = fStartNew + (fMax - fStart)*4 + (c - cStart)*12 + 5;
496127fcede3SMatthew G. Knepley       coneNew[0] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 4;
496227fcede3SMatthew G. Knepley       orntNew[0] = -2;
496327fcede3SMatthew G. Knepley       coneNew[1] = eStartNew + (eMax - eStart)*2 + (cone[4] - fStart)*4 + GetQuadEdge_Static(ornt[4], 2);
496427fcede3SMatthew G. Knepley       orntNew[1] = -2;
496527fcede3SMatthew G. Knepley       coneNew[2] = eStartNew + (eMax - eStart)*2 + (cone[1] - fStart)*4 + GetQuadEdge_Static(ornt[1], 1);
496627fcede3SMatthew G. Knepley       orntNew[2] = 0;
496727fcede3SMatthew G. Knepley       coneNew[3] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 1;
496827fcede3SMatthew G. Knepley       orntNew[3] = 0;
496927fcede3SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
497027fcede3SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
497127fcede3SMatthew G. Knepley #if 1
497227fcede3SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
497327fcede3SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
497427fcede3SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
497527fcede3SMatthew G. Knepley       }
497627fcede3SMatthew G. Knepley #endif
497727fcede3SMatthew G. Knepley       /* G-H face */
497827fcede3SMatthew G. Knepley       newp = fStartNew + (fMax - fStart)*4 + (c - cStart)*12 + 6;
497927fcede3SMatthew G. Knepley       coneNew[0] = eStartNew + (eMax - eStart)*2 + (cone[3] - fStart)*4 + GetQuadEdge_Static(ornt[3], 2);
498027fcede3SMatthew G. Knepley       orntNew[0] = -2;
498127fcede3SMatthew G. Knepley       coneNew[1] = eStartNew + (eMax - eStart)*2 + (cone[1] - fStart)*4 + GetQuadEdge_Static(ornt[1], 2);
498227fcede3SMatthew G. Knepley       orntNew[1] = 0;
498327fcede3SMatthew G. Knepley       coneNew[2] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 1;
498427fcede3SMatthew G. Knepley       orntNew[2] = 0;
498527fcede3SMatthew G. Knepley       coneNew[3] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 3;
498627fcede3SMatthew G. Knepley       orntNew[3] = -2;
498727fcede3SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
498827fcede3SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
498927fcede3SMatthew G. Knepley #if 1
499027fcede3SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
499127fcede3SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
499227fcede3SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
499327fcede3SMatthew G. Knepley       }
499427fcede3SMatthew G. Knepley #endif
499527fcede3SMatthew G. Knepley       /* E-H face */
499627fcede3SMatthew G. Knepley       newp = fStartNew + (fMax - fStart)*4 + (c - cStart)*12 + 7;
499727fcede3SMatthew G. Knepley       coneNew[0] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 5;
499827fcede3SMatthew G. Knepley       orntNew[0] = -2;
499927fcede3SMatthew G. Knepley       coneNew[1] = eStartNew + (eMax - eStart)*2 + (cone[5] - fStart)*4 + GetQuadEdge_Static(ornt[5], 1);
500027fcede3SMatthew G. Knepley       orntNew[1] = -2;
500127fcede3SMatthew G. Knepley       coneNew[2] = eStartNew + (eMax - eStart)*2 + (cone[1] - fStart)*4 + GetQuadEdge_Static(ornt[1], 3);
500227fcede3SMatthew G. Knepley       orntNew[2] = 0;
500327fcede3SMatthew G. Knepley       coneNew[3] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 1;
500427fcede3SMatthew G. Knepley       orntNew[3] = 0;
500527fcede3SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
500627fcede3SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
500727fcede3SMatthew G. Knepley #if 1
500827fcede3SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
500927fcede3SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
501027fcede3SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
501127fcede3SMatthew G. Knepley       }
501227fcede3SMatthew G. Knepley #endif
501327fcede3SMatthew G. Knepley       /* A-E face */
501427fcede3SMatthew G. Knepley       newp = fStartNew + (fMax - fStart)*4 + (c - cStart)*12 + 8;
501527fcede3SMatthew G. Knepley       coneNew[0] = eStartNew + (eMax - eStart)*2 + (cone[2] - fStart)*4 + GetQuadEdge_Static(ornt[2], 3);
501627fcede3SMatthew G. Knepley       orntNew[0] = 0;
501727fcede3SMatthew G. Knepley       coneNew[1] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 2;
501827fcede3SMatthew G. Knepley       orntNew[1] = 0;
501927fcede3SMatthew G. Knepley       coneNew[2] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 5;
502027fcede3SMatthew G. Knepley       orntNew[2] = -2;
502127fcede3SMatthew G. Knepley       coneNew[3] = eStartNew + (eMax - eStart)*2 + (cone[5] - fStart)*4 + GetQuadEdge_Static(ornt[5], 0);
502227fcede3SMatthew G. Knepley       orntNew[3] = -2;
502327fcede3SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
502427fcede3SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
502527fcede3SMatthew G. Knepley #if 1
502627fcede3SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
502727fcede3SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
502827fcede3SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
502927fcede3SMatthew G. Knepley       }
503027fcede3SMatthew G. Knepley #endif
503127fcede3SMatthew G. Knepley       /* D-F face */
503227fcede3SMatthew G. Knepley       newp = fStartNew + (fMax - fStart)*4 + (c - cStart)*12 + 9;
503327fcede3SMatthew G. Knepley       coneNew[0] = eStartNew + (eMax - eStart)*2 + (cone[2] - fStart)*4 + GetQuadEdge_Static(ornt[2], 1);
503427fcede3SMatthew G. Knepley       orntNew[0] = -2;
503527fcede3SMatthew G. Knepley       coneNew[1] = eStartNew + (eMax - eStart)*2 + (cone[4] - fStart)*4 + GetQuadEdge_Static(ornt[4], 3);
503627fcede3SMatthew G. Knepley       orntNew[1] = 0;
503727fcede3SMatthew G. Knepley       coneNew[2] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 4;
503827fcede3SMatthew G. Knepley       orntNew[2] = 0;
503927fcede3SMatthew G. Knepley       coneNew[3] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 2;
504027fcede3SMatthew G. Knepley       orntNew[3] = -2;
504127fcede3SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
504227fcede3SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
504327fcede3SMatthew G. Knepley #if 1
504427fcede3SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
504527fcede3SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
504627fcede3SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
504727fcede3SMatthew G. Knepley       }
504827fcede3SMatthew G. Knepley #endif
504927fcede3SMatthew G. Knepley       /* C-G face */
505027fcede3SMatthew G. Knepley       newp = fStartNew + (fMax - fStart)*4 + (c - cStart)*12 + 10;
505127fcede3SMatthew G. Knepley       coneNew[0] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 4;
505227fcede3SMatthew G. Knepley       orntNew[0] = -2;
505327fcede3SMatthew G. Knepley       coneNew[1] = eStartNew + (eMax - eStart)*2 + (cone[4] - fStart)*4 + GetQuadEdge_Static(ornt[4], 1);
505427fcede3SMatthew G. Knepley       orntNew[1] = -2;
505527fcede3SMatthew G. Knepley       coneNew[2] = eStartNew + (eMax - eStart)*2 + (cone[3] - fStart)*4 + GetQuadEdge_Static(ornt[3], 3);
505627fcede3SMatthew G. Knepley       orntNew[2] = 0;
505727fcede3SMatthew G. Knepley       coneNew[3] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 3;
505827fcede3SMatthew G. Knepley       orntNew[3] = 0;
505927fcede3SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
506027fcede3SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
506127fcede3SMatthew G. Knepley #if 1
506227fcede3SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
506327fcede3SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
506427fcede3SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
506527fcede3SMatthew G. Knepley       }
506627fcede3SMatthew G. Knepley #endif
506727fcede3SMatthew G. Knepley       /* B-H face */
506827fcede3SMatthew G. Knepley       newp = fStartNew + (fMax - fStart)*4 + (c - cStart)*12 + 11;
506927fcede3SMatthew G. Knepley       coneNew[0] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 5;
507027fcede3SMatthew G. Knepley       orntNew[0] = 0;
507127fcede3SMatthew G. Knepley       coneNew[1] = eStartNew + (eMax - eStart)*2 + (fMax    - fStart)*4 + (c - cStart)*6 + 3;
507227fcede3SMatthew G. Knepley       orntNew[1] = -2;
507327fcede3SMatthew G. Knepley       coneNew[2] = eStartNew + (eMax - eStart)*2 + (cone[3] - fStart)*4 + GetQuadEdge_Static(ornt[3], 1);
507427fcede3SMatthew G. Knepley       orntNew[2] = -2;
507527fcede3SMatthew G. Knepley       coneNew[3] = eStartNew + (eMax - eStart)*2 + (cone[5] - fStart)*4 + GetQuadEdge_Static(ornt[5], 2);
507627fcede3SMatthew G. Knepley       orntNew[3] = 0;
507727fcede3SMatthew G. Knepley       ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
507827fcede3SMatthew G. Knepley       ierr       = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
507927fcede3SMatthew G. Knepley #if 1
508027fcede3SMatthew G. Knepley       if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
508127fcede3SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
508227fcede3SMatthew G. Knepley         if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
508327fcede3SMatthew G. Knepley       }
508427fcede3SMatthew G. Knepley #endif
508527fcede3SMatthew G. Knepley       for (r = 0; r < 12; ++r) {
508627fcede3SMatthew G. Knepley         newp = fStartNew + (fMax - fStart)*4 + (c - cStart)*12 + r;
508727fcede3SMatthew G. Knepley         supportNew[0] = cStartNew + (c - cStart)*8 + newCells[r*2+0];
508827fcede3SMatthew G. Knepley         supportNew[1] = cStartNew + (c - cStart)*8 + newCells[r*2+1];
508927fcede3SMatthew G. Knepley         ierr          = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
509027fcede3SMatthew G. Knepley #if 1
509127fcede3SMatthew G. Knepley         if ((newp < fStartNew) || (newp >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", newp, fStartNew, fMaxNew);
509227fcede3SMatthew G. Knepley         for (p = 0; p < 2; ++p) {
509327fcede3SMatthew G. Knepley           if ((supportNew[p] < cStartNew) || (supportNew[p] >= cMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a cell [%d, %d)", supportNew[p], cStartNew, cMaxNew);
509427fcede3SMatthew G. Knepley         }
509527fcede3SMatthew G. Knepley #endif
509627fcede3SMatthew G. Knepley       }
509727fcede3SMatthew G. Knepley     }
509827fcede3SMatthew G. Knepley     /* Hybrid split faces have 4 edges and same cells */
509927fcede3SMatthew G. Knepley     for (f = fMax; f < fEnd; ++f) {
510027fcede3SMatthew G. Knepley       const PetscInt *cone, *ornt, *support;
510127fcede3SMatthew G. Knepley       PetscInt        coneNew[4], orntNew[4];
510227fcede3SMatthew G. Knepley       PetscInt        supportNew[2], size, s, c;
510327fcede3SMatthew G. Knepley 
510427fcede3SMatthew G. Knepley       ierr = DMPlexGetCone(dm, f, &cone);CHKERRQ(ierr);
510527fcede3SMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, f, &ornt);CHKERRQ(ierr);
510627fcede3SMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
510727fcede3SMatthew G. Knepley       ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
510827fcede3SMatthew G. Knepley       for (r = 0; r < 2; ++r) {
510927fcede3SMatthew G. Knepley         const PetscInt newp = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*12 + (f - fMax)*2 + r;
511027fcede3SMatthew G. Knepley 
511127fcede3SMatthew G. Knepley         coneNew[0]   = eStartNew + (cone[0] - eStart)*2 + (ornt[0] < 0 ? 1-r : r);
511227fcede3SMatthew G. Knepley         orntNew[0]   = ornt[0];
511327fcede3SMatthew G. Knepley         coneNew[1]   = eStartNew + (cone[1] - eStart)*2 + (ornt[1] < 0 ? 1-r : r);
511427fcede3SMatthew G. Knepley         orntNew[1]   = ornt[1];
511527fcede3SMatthew G. Knepley         coneNew[2+r] = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (cMax - cStart)*6 + (cone[2+r] - eMax);
511627fcede3SMatthew G. Knepley         orntNew[2+r] = 0;
511727fcede3SMatthew G. Knepley         coneNew[3-r] = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (cMax - cStart)*6 + (eEnd      - eMax) + (f - fMax);
511827fcede3SMatthew G. Knepley         orntNew[3-r] = 0;
511927fcede3SMatthew G. Knepley         ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
512027fcede3SMatthew G. Knepley         ierr = DMPlexSetConeOrientation(rdm, newp, orntNew);CHKERRQ(ierr);
512127fcede3SMatthew G. Knepley #if 1
512227fcede3SMatthew G. Knepley         if ((newp < fMaxNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid face [%d, %d)", newp, fMaxNew, fEndNew);
512327fcede3SMatthew G. Knepley         for (p = 0; p < 2; ++p) {
512427fcede3SMatthew G. Knepley           if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
512527fcede3SMatthew G. Knepley         }
512627fcede3SMatthew G. Knepley         for (p = 2; p < 4; ++p) {
512727fcede3SMatthew G. Knepley           if ((coneNew[p] < eMaxNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid edge [%d, %d)", coneNew[p], eMaxNew, eEndNew);
512827fcede3SMatthew G. Knepley         }
512927fcede3SMatthew G. Knepley #endif
513027fcede3SMatthew G. Knepley         for (s = 0; s < size; ++s) {
513127fcede3SMatthew G. Knepley           const PetscInt *coneCell, *orntCell, *fornt;
5132d273725eSMatthew G. Knepley           PetscInt        o, of;
513327fcede3SMatthew G. Knepley 
513427fcede3SMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &coneCell);CHKERRQ(ierr);
513527fcede3SMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, support[s], &orntCell);CHKERRQ(ierr);
5136d273725eSMatthew G. Knepley           o = orntCell[0] < 0 ? -1 : 1;
513727fcede3SMatthew G. Knepley           for (c = 2; c < 6; ++c) if (coneCell[c] == f) break;
513827fcede3SMatthew G. Knepley           if (c >= 6) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Could not find face %d in cone of cell %d", f, support[s]);
513927fcede3SMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, coneCell[0], &fornt);CHKERRQ(ierr);
5140d273725eSMatthew G. Knepley           of = fornt[c-2] < 0 ? -1 : 1;
5141d273725eSMatthew G. Knepley           supportNew[s] = cStartNew + (cMax - cStart)*8 + (support[s] - cMax)*4 + (GetQuadEdgeInverse_Static(orntCell[0], c-2) + (o*of < 0 ? 1-r : r))%4;
514227fcede3SMatthew G. Knepley         }
514327fcede3SMatthew G. Knepley         ierr = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
514427fcede3SMatthew G. Knepley #if 1
514527fcede3SMatthew G. Knepley         if ((newp < fMaxNew) || (newp >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid face [%d, %d)", newp, fMaxNew, fEndNew);
514627fcede3SMatthew G. Knepley         for (p = 0; p < size; ++p) {
514727fcede3SMatthew G. Knepley           if ((supportNew[p] < cMaxNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid cell [%d, %d)", supportNew[p], cMaxNew, cEndNew);
514827fcede3SMatthew G. Knepley         }
514927fcede3SMatthew G. Knepley #endif
515027fcede3SMatthew G. Knepley       }
515127fcede3SMatthew G. Knepley     }
515227fcede3SMatthew G. Knepley     /* Hybrid cell faces have 4 edges and 2 cells */
515327fcede3SMatthew G. Knepley     for (c = cMax; c < cEnd; ++c) {
515427fcede3SMatthew G. Knepley       PetscInt        newp = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*12 + (fEnd - fMax)*2 + (c - cMax)*4;
515527fcede3SMatthew G. Knepley       const PetscInt *cone, *ornt;
515627fcede3SMatthew G. Knepley       PetscInt        coneNew[4], orntNew[4];
515727fcede3SMatthew G. Knepley       PetscInt        supportNew[2];
515827fcede3SMatthew G. Knepley 
515927fcede3SMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
516027fcede3SMatthew G. Knepley       ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr);
516127fcede3SMatthew G. Knepley       for (r = 0; r < 4; ++r) {
5162d273725eSMatthew G. Knepley #if 0
516327fcede3SMatthew G. Knepley         coneNew[0] = eStartNew + (eMax - eStart)*2 + (cone[0] - fStart)*4 + GetQuadSubface_Static(ornt[0], r);
516427fcede3SMatthew G. Knepley         orntNew[0] = 0;
516527fcede3SMatthew G. Knepley         coneNew[1] = eStartNew + (eMax - eStart)*2 + (cone[1] - fStart)*4 + GetQuadSubface_Static(ornt[1], r);
516627fcede3SMatthew G. Knepley         orntNew[1] = 0;
516727fcede3SMatthew G. Knepley         coneNew[2] = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (cMax - cStart)*6 + (eEnd - eMax) + (cone[2+GetQuadEdge_Static(ornt[0], r)] - fMax);
516827fcede3SMatthew G. Knepley         orntNew[2] = 0;
516927fcede3SMatthew G. Knepley         coneNew[3] = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (cMax - cStart)*6 + (eEnd - eMax) + (fEnd                                   - fMax) + (c - cMax);
517027fcede3SMatthew G. Knepley         orntNew[3] = 0;
5171d273725eSMatthew G. Knepley #else
5172d273725eSMatthew G. Knepley         coneNew[0] = eStartNew + (eMax - eStart)*2 + (cone[0] - fStart)*4 + r;
5173d273725eSMatthew G. Knepley         orntNew[0] = 0;
5174d273725eSMatthew G. Knepley         coneNew[1] = eStartNew + (eMax - eStart)*2 + (cone[1] - fStart)*4 + r;
5175d273725eSMatthew G. Knepley         orntNew[1] = 0;
5176d273725eSMatthew G. Knepley         coneNew[2] = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (cMax - cStart)*6 + (eEnd - eMax) + (cone[2+r] - fMax);
5177d273725eSMatthew G. Knepley         orntNew[2] = 0;
5178d273725eSMatthew G. Knepley         coneNew[3] = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (cMax - cStart)*6 + (eEnd - eMax) + (fEnd      - fMax) + (c - cMax);
5179d273725eSMatthew G. Knepley         orntNew[3] = 0;
5180d273725eSMatthew G. Knepley #endif
518127fcede3SMatthew G. Knepley         ierr = DMPlexSetCone(rdm, newp+r, coneNew);CHKERRQ(ierr);
518227fcede3SMatthew G. Knepley         ierr = DMPlexSetConeOrientation(rdm, newp+r, orntNew);CHKERRQ(ierr);
518327fcede3SMatthew G. Knepley #if 1
518427fcede3SMatthew G. Knepley         if ((newp+r < fMaxNew) || (newp+r >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid face [%d, %d)", newp+r, fMaxNew, fEndNew);
518527fcede3SMatthew G. Knepley         for (p = 0; p < 2; ++p) {
518627fcede3SMatthew G. Knepley           if ((coneNew[p] < eStartNew) || (coneNew[p] >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", coneNew[p], eStartNew, eMaxNew);
518727fcede3SMatthew G. Knepley         }
518827fcede3SMatthew G. Knepley         for (p = 2; p < 4; ++p) {
518927fcede3SMatthew G. Knepley           if ((coneNew[p] < eMaxNew) || (coneNew[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid edge [%d, %d)", coneNew[p], eMaxNew, eEndNew);
519027fcede3SMatthew G. Knepley         }
519127fcede3SMatthew G. Knepley #endif
519227fcede3SMatthew G. Knepley         supportNew[0] = cStartNew + (cMax - cStart)*8 + (c - cMax)*4 + GetQuadSubface_Static(ornt[0], r);
519327fcede3SMatthew G. Knepley         supportNew[1] = cStartNew + (cMax - cStart)*8 + (c - cMax)*4 + GetQuadSubface_Static(ornt[0], (r+1)%4);
519427fcede3SMatthew G. Knepley         ierr          = DMPlexSetSupport(rdm, newp+r, supportNew);CHKERRQ(ierr);
519527fcede3SMatthew G. Knepley #if 1
519627fcede3SMatthew G. Knepley         if ((newp+r < fMaxNew) || (newp+r >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid face [%d, %d)", newp+r, fMaxNew, fEndNew);
519727fcede3SMatthew G. Knepley         for (p = 0; p < 2; ++p) {
519827fcede3SMatthew G. Knepley           if ((supportNew[p] < cMaxNew) || (supportNew[p] >= cEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid cell [%d, %d)", supportNew[p], cMaxNew, cEndNew);
519927fcede3SMatthew G. Knepley         }
520027fcede3SMatthew G. Knepley #endif
520127fcede3SMatthew G. Knepley       }
520227fcede3SMatthew G. Knepley     }
520327fcede3SMatthew G. Knepley     /* Interior split edges have 2 vertices and the same faces as the parent */
520427fcede3SMatthew G. Knepley     ierr = DMPlexGetMaxSizes(dm, NULL, &maxSupportSize);CHKERRQ(ierr);
520527fcede3SMatthew G. Knepley     for (e = eStart; e < eMax; ++e) {
520627fcede3SMatthew G. Knepley       const PetscInt newv = vStartNew + (vEnd - vStart) + (e - eStart);
520727fcede3SMatthew G. Knepley 
520827fcede3SMatthew G. Knepley       for (r = 0; r < 2; ++r) {
520927fcede3SMatthew G. Knepley         const PetscInt  newp = eStartNew + (e - eStart)*2 + r;
521027fcede3SMatthew G. Knepley         const PetscInt *cone, *ornt, *support;
521127fcede3SMatthew G. Knepley         PetscInt        coneNew[2], coneSize, c, supportSize, s;
521227fcede3SMatthew G. Knepley 
521327fcede3SMatthew G. Knepley         ierr             = DMPlexGetCone(dm, e, &cone);CHKERRQ(ierr);
521427fcede3SMatthew G. Knepley         coneNew[0]       = vStartNew + (cone[0] - vStart);
521527fcede3SMatthew G. Knepley         coneNew[1]       = vStartNew + (cone[1] - vStart);
521627fcede3SMatthew G. Knepley         coneNew[(r+1)%2] = newv;
521727fcede3SMatthew G. Knepley         ierr             = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
521827fcede3SMatthew G. Knepley #if 1
521927fcede3SMatthew G. Knepley         if ((newp < eStartNew) || (newp >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eMaxNew);
522027fcede3SMatthew G. Knepley         for (p = 0; p < 2; ++p) {
522127fcede3SMatthew G. Knepley           if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
522227fcede3SMatthew G. Knepley         }
522327fcede3SMatthew G. Knepley #endif
522427fcede3SMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, e, &supportSize);CHKERRQ(ierr);
522527fcede3SMatthew G. Knepley         ierr = DMPlexGetSupport(dm, e, &support);CHKERRQ(ierr);
522627fcede3SMatthew G. Knepley         for (s = 0; s < supportSize; ++s) {
522727fcede3SMatthew G. Knepley           ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr);
522827fcede3SMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
522927fcede3SMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, support[s], &ornt);CHKERRQ(ierr);
523027fcede3SMatthew G. Knepley           for (c = 0; c < coneSize; ++c) {
523127fcede3SMatthew G. Knepley             if (cone[c] == e) break;
523227fcede3SMatthew G. Knepley           }
523327fcede3SMatthew G. Knepley           if (support[s] < fMax) {
523427fcede3SMatthew G. Knepley             supportRef[s] = fStartNew + (support[s] - fStart)*4 + (c + (ornt[c] < 0 ? 1-r : r))%4;
523527fcede3SMatthew G. Knepley           } else {
523627fcede3SMatthew G. Knepley             supportRef[s] = fStartNew + (fMax       - fStart)*4 + (cMax - cStart)*12 + (support[s] - fMax)*2 + (ornt[c] < 0 ? 1-r : r);
523727fcede3SMatthew G. Knepley           }
523827fcede3SMatthew G. Knepley         }
523927fcede3SMatthew G. Knepley         ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
524027fcede3SMatthew G. Knepley #if 1
524127fcede3SMatthew G. Knepley         if ((newp < eStartNew) || (newp >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eMaxNew);
524227fcede3SMatthew G. Knepley         for (p = 0; p < supportSize; ++p) {
524327fcede3SMatthew G. Knepley           if ((supportRef[p] < fStartNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", supportRef[p], fStartNew, fEndNew);
524427fcede3SMatthew G. Knepley         }
524527fcede3SMatthew G. Knepley #endif
524627fcede3SMatthew G. Knepley       }
524727fcede3SMatthew G. Knepley     }
524827fcede3SMatthew G. Knepley     /* Interior face edges have 2 vertices and 2+cells faces */
524927fcede3SMatthew G. Knepley     for (f = fStart; f < fMax; ++f) {
525027fcede3SMatthew G. Knepley       const PetscInt  newFaces[24] = {3, 2, 1, 0,  4, 5, 6, 7,  0, 9, 4, 8,  2, 11, 6, 10,  1, 10, 5, 9,  8, 7, 11, 3};
525127fcede3SMatthew G. Knepley       const PetscInt  newv = vStartNew + (vEnd - vStart) + (eMax - eStart) + (f - fStart);
525227fcede3SMatthew G. Knepley       const PetscInt *cone, *coneCell, *orntCell, *support;
525327fcede3SMatthew G. Knepley       PetscInt        coneNew[2], coneSize, c, supportSize, s;
525427fcede3SMatthew G. Knepley 
525527fcede3SMatthew G. Knepley       ierr = DMPlexGetCone(dm, f, &cone);CHKERRQ(ierr);
525627fcede3SMatthew G. Knepley       for (r = 0; r < 4; ++r) {
525727fcede3SMatthew G. Knepley         const PetscInt newp = eStartNew + (eMax - eStart)*2 + (f - fStart)*4 + r;
525827fcede3SMatthew G. Knepley 
525927fcede3SMatthew G. Knepley         coneNew[0] = vStartNew + (vEnd - vStart) + (cone[r] - eStart);
526027fcede3SMatthew G. Knepley         coneNew[1] = newv;
526127fcede3SMatthew G. Knepley         ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
526227fcede3SMatthew G. Knepley #if 1
526327fcede3SMatthew G. Knepley         if ((newp < eStartNew) || (newp >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eMaxNew);
526427fcede3SMatthew G. Knepley         for (p = 0; p < 2; ++p) {
526527fcede3SMatthew G. Knepley           if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
526627fcede3SMatthew G. Knepley         }
526727fcede3SMatthew G. Knepley #endif
526827fcede3SMatthew G. Knepley         ierr = DMPlexGetSupportSize(dm, f, &supportSize);CHKERRQ(ierr);
526927fcede3SMatthew G. Knepley         ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
527027fcede3SMatthew G. Knepley         supportRef[0] = fStartNew + (f - fStart)*4 + r;
527127fcede3SMatthew G. Knepley         supportRef[1] = fStartNew + (f - fStart)*4 + (r+1)%4;
527227fcede3SMatthew G. Knepley         for (s = 0; s < supportSize; ++s) {
527327fcede3SMatthew G. Knepley           ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr);
527427fcede3SMatthew G. Knepley           ierr = DMPlexGetCone(dm, support[s], &coneCell);CHKERRQ(ierr);
527527fcede3SMatthew G. Knepley           ierr = DMPlexGetConeOrientation(dm, support[s], &orntCell);CHKERRQ(ierr);
527627fcede3SMatthew G. Knepley           for (c = 0; c < coneSize; ++c) if (coneCell[c] == f) break;
527727fcede3SMatthew G. Knepley           if (support[s] < cMax) {
527827fcede3SMatthew G. Knepley             supportRef[2+s] = fStartNew + (fMax - fStart)*4 + (support[s] - cStart)*12 + newFaces[c*4 + GetQuadEdgeInverse_Static(orntCell[c], r)];
527927fcede3SMatthew G. Knepley           } else {
5280d273725eSMatthew G. Knepley             supportRef[2+s] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*12 + (fEnd - fMax)*2 + (support[s] - cMax)*4 + r;
528127fcede3SMatthew G. Knepley           }
528227fcede3SMatthew G. Knepley         }
528327fcede3SMatthew G. Knepley         ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
528427fcede3SMatthew G. Knepley #if 1
528527fcede3SMatthew G. Knepley         if ((newp < eStartNew) || (newp >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eMaxNew);
528627fcede3SMatthew G. Knepley         for (p = 0; p < 2+supportSize; ++p) {
528727fcede3SMatthew G. Knepley           if ((supportRef[p] < fStartNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", supportRef[p], fStartNew, fEndNew);
528827fcede3SMatthew G. Knepley         }
528927fcede3SMatthew G. Knepley #endif
529027fcede3SMatthew G. Knepley       }
529127fcede3SMatthew G. Knepley     }
529227fcede3SMatthew G. Knepley     /* Interior cell edges have 2 vertices and 4 faces */
529327fcede3SMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
529427fcede3SMatthew G. Knepley       const PetscInt  newFaces[24] = {0, 1, 2, 3,  4, 5, 6, 7,  0, 9, 4, 8,  2, 11, 6, 10,  1, 10, 5, 9,  3, 8, 7, 11};
529527fcede3SMatthew G. Knepley       const PetscInt  newv = vStartNew + (vEnd - vStart) + (eMax - eStart) + (fMax - fStart) + (c - cStart);
529627fcede3SMatthew G. Knepley       const PetscInt *cone;
529727fcede3SMatthew G. Knepley       PetscInt        coneNew[2], supportNew[4];
529827fcede3SMatthew G. Knepley 
529927fcede3SMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
530027fcede3SMatthew G. Knepley       for (r = 0; r < 6; ++r) {
530127fcede3SMatthew G. Knepley         const PetscInt newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (c - cStart)*6 + r;
530227fcede3SMatthew G. Knepley 
530327fcede3SMatthew G. Knepley         coneNew[0] = vStartNew + (vEnd - vStart) + (eMax - eStart) + (cone[r] - fStart);
530427fcede3SMatthew G. Knepley         coneNew[1] = newv;
530527fcede3SMatthew G. Knepley         ierr       = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
530627fcede3SMatthew G. Knepley #if 1
530727fcede3SMatthew G. Knepley         if ((newp < eStartNew) || (newp >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eMaxNew);
530827fcede3SMatthew G. Knepley         for (p = 0; p < 2; ++p) {
530927fcede3SMatthew G. Knepley           if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
531027fcede3SMatthew G. Knepley         }
531127fcede3SMatthew G. Knepley #endif
531227fcede3SMatthew G. Knepley         for (f = 0; f < 4; ++f) supportNew[f] = fStartNew + (fMax - fStart)*4 + (c - cStart)*12 + newFaces[r*4+f];
531327fcede3SMatthew G. Knepley         ierr = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
531427fcede3SMatthew G. Knepley #if 1
531527fcede3SMatthew G. Knepley         if ((newp < eStartNew) || (newp >= eMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", newp, eStartNew, eMaxNew);
531627fcede3SMatthew G. Knepley         for (p = 0; p < 4; ++p) {
531727fcede3SMatthew G. Knepley           if ((supportNew[p] < fStartNew) || (supportNew[p] >= fMaxNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a face [%d, %d)", supportNew[p], fStartNew, fMaxNew);
531827fcede3SMatthew G. Knepley         }
531927fcede3SMatthew G. Knepley #endif
532027fcede3SMatthew G. Knepley       }
532127fcede3SMatthew G. Knepley     }
532227fcede3SMatthew G. Knepley     /* Hybrid edges have two vertices and the same faces */
532327fcede3SMatthew G. Knepley     for (e = eMax; e < eEnd; ++e) {
532427fcede3SMatthew G. Knepley       const PetscInt  newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (cMax - cStart)*6 + (e - eMax);
532527fcede3SMatthew G. Knepley       const PetscInt *cone, *support, *fcone;
532627fcede3SMatthew G. Knepley       PetscInt        coneNew[2], size, fsize, s;
532727fcede3SMatthew G. Knepley 
532827fcede3SMatthew G. Knepley       ierr = DMPlexGetCone(dm, e, &cone);CHKERRQ(ierr);
532927fcede3SMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, e, &size);CHKERRQ(ierr);
533027fcede3SMatthew G. Knepley       ierr = DMPlexGetSupport(dm, e, &support);CHKERRQ(ierr);
533127fcede3SMatthew G. Knepley       coneNew[0] = vStartNew + (cone[0] - vStart);
533227fcede3SMatthew G. Knepley       coneNew[1] = vStartNew + (cone[1] - vStart);
533327fcede3SMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
533427fcede3SMatthew G. Knepley #if 1
533527fcede3SMatthew G. Knepley       if ((newp < eMaxNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid edge [%d, %d)", newp, eMaxNew, eEndNew);
533627fcede3SMatthew G. Knepley       for (p = 0; p < 2; ++p) {
533727fcede3SMatthew G. Knepley         if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
533827fcede3SMatthew G. Knepley       }
533927fcede3SMatthew G. Knepley #endif
534027fcede3SMatthew G. Knepley       for (s = 0; s < size; ++s) {
534127fcede3SMatthew G. Knepley         ierr = DMPlexGetConeSize(dm, support[s], &fsize);CHKERRQ(ierr);
534227fcede3SMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &fcone);CHKERRQ(ierr);
534327fcede3SMatthew G. Knepley         for (c = 0; c < fsize; ++c) if (fcone[c] == e) break;
534427fcede3SMatthew G. Knepley         if ((c < 2) || (c > 3)) SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Edge %d not found in cone of face %d", e, support[s]);
534527fcede3SMatthew G. Knepley         supportRef[s] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*12 + (support[s] - fMax)*2 + c-2;
534627fcede3SMatthew G. Knepley       }
534727fcede3SMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
534827fcede3SMatthew G. Knepley #if 1
534927fcede3SMatthew G. Knepley       if ((newp < eMaxNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid edge [%d, %d)", newp, eMaxNew, eEndNew);
535027fcede3SMatthew G. Knepley       for (p = 0; p < size; ++p) {
535127fcede3SMatthew G. Knepley         if ((supportRef[p] < fMaxNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid face [%d, %d)", supportRef[p], fMaxNew, fEndNew);
535227fcede3SMatthew G. Knepley       }
535327fcede3SMatthew G. Knepley #endif
535427fcede3SMatthew G. Knepley     }
535527fcede3SMatthew G. Knepley     /* Hybrid face edges have 2 vertices and 2+cells faces */
535627fcede3SMatthew G. Knepley     for (f = fMax; f < fEnd; ++f) {
535727fcede3SMatthew G. Knepley       const PetscInt  newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (cMax - cStart)*6 + (eEnd - eMax) + (f - fMax);
535827fcede3SMatthew G. Knepley       const PetscInt *cone, *support, *ccone, *cornt;
535927fcede3SMatthew G. Knepley       PetscInt        coneNew[2], size, csize, s;
536027fcede3SMatthew G. Knepley 
536127fcede3SMatthew G. Knepley       ierr = DMPlexGetCone(dm, f, &cone);CHKERRQ(ierr);
536227fcede3SMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
536327fcede3SMatthew G. Knepley       ierr = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
536427fcede3SMatthew G. Knepley       coneNew[0] = vStartNew + (vEnd - vStart) + (cone[0] - eStart);
536527fcede3SMatthew G. Knepley       coneNew[1] = vStartNew + (vEnd - vStart) + (cone[1] - eStart);
536627fcede3SMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
536727fcede3SMatthew G. Knepley #if 1
536827fcede3SMatthew G. Knepley       if ((newp < eMaxNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid edge [%d, %d)", newp, eMaxNew, eEndNew);
536927fcede3SMatthew G. Knepley       for (p = 0; p < 2; ++p) {
537027fcede3SMatthew G. Knepley         if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
537127fcede3SMatthew G. Knepley       }
537227fcede3SMatthew G. Knepley #endif
537327fcede3SMatthew G. Knepley       supportRef[0] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*12 + (f - fMax)*2 + 0;
537427fcede3SMatthew G. Knepley       supportRef[1] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*12 + (f - fMax)*2 + 1;
537527fcede3SMatthew G. Knepley       for (s = 0; s < size; ++s) {
537627fcede3SMatthew G. Knepley         ierr = DMPlexGetConeSize(dm, support[s], &csize);CHKERRQ(ierr);
537727fcede3SMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &ccone);CHKERRQ(ierr);
537827fcede3SMatthew G. Knepley         ierr = DMPlexGetConeOrientation(dm, support[s], &cornt);CHKERRQ(ierr);
537927fcede3SMatthew G. Knepley         for (c = 0; c < csize; ++c) if (ccone[c] == f) break;
538027fcede3SMatthew G. Knepley         if ((c < 2) || (c >= csize)) SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Hybrid face %d is not in cone of hybrid cell %d", f, support[s]);
5381d273725eSMatthew G. Knepley         supportRef[2+s] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*12 + (fEnd - fMax)*2 + (support[s] - cMax)*4 + c-2;
538227fcede3SMatthew G. Knepley       }
538327fcede3SMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
538427fcede3SMatthew G. Knepley #if 1
538527fcede3SMatthew G. Knepley       if ((newp < eMaxNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid edge [%d, %d)", newp, eMaxNew, eEndNew);
538627fcede3SMatthew G. Knepley       for (p = 0; p < 2+size; ++p) {
538727fcede3SMatthew G. Knepley         if ((supportRef[p] < fMaxNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid face [%d, %d)", supportRef[p], fMaxNew, fEndNew);
538827fcede3SMatthew G. Knepley       }
538927fcede3SMatthew G. Knepley #endif
539027fcede3SMatthew G. Knepley     }
539127fcede3SMatthew G. Knepley     /* Hybrid cell edges have 2 vertices and 4 faces */
539227fcede3SMatthew G. Knepley     for (c = cMax; c < cEnd; ++c) {
539327fcede3SMatthew G. Knepley       const PetscInt  newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (cMax - cStart)*6 + (eEnd - eMax) + (fEnd - fMax) + (c - cMax);
539427fcede3SMatthew G. Knepley       const PetscInt *cone, *support;
539527fcede3SMatthew G. Knepley       PetscInt        coneNew[2], size;
539627fcede3SMatthew G. Knepley 
539727fcede3SMatthew G. Knepley       ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr);
539827fcede3SMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, c, &size);CHKERRQ(ierr);
539927fcede3SMatthew G. Knepley       ierr = DMPlexGetSupport(dm, c, &support);CHKERRQ(ierr);
540027fcede3SMatthew G. Knepley       coneNew[0] = vStartNew + (vEnd - vStart) + (eMax - eStart) + (cone[0] - fStart);
540127fcede3SMatthew G. Knepley       coneNew[1] = vStartNew + (vEnd - vStart) + (eMax - eStart) + (cone[1] - fStart);
540227fcede3SMatthew G. Knepley       ierr = DMPlexSetCone(rdm, newp, coneNew);CHKERRQ(ierr);
540327fcede3SMatthew G. Knepley #if 1
540427fcede3SMatthew G. Knepley       if ((newp < eMaxNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid edge [%d, %d)", newp, eMaxNew, eEndNew);
540527fcede3SMatthew G. Knepley       for (p = 0; p < 2; ++p) {
540627fcede3SMatthew G. Knepley         if ((coneNew[p] < vStartNew) || (coneNew[p] >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", coneNew[p], vStartNew, vEndNew);
540727fcede3SMatthew G. Knepley       }
540827fcede3SMatthew G. Knepley #endif
540927fcede3SMatthew G. Knepley       supportRef[0] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*12 + (fEnd - fMax)*2 + (c - cMax)*4 + 0;
541027fcede3SMatthew G. Knepley       supportRef[1] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*12 + (fEnd - fMax)*2 + (c - cMax)*4 + 1;
541127fcede3SMatthew G. Knepley       supportRef[2] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*12 + (fEnd - fMax)*2 + (c - cMax)*4 + 2;
541227fcede3SMatthew G. Knepley       supportRef[3] = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*12 + (fEnd - fMax)*2 + (c - cMax)*4 + 3;
541327fcede3SMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
541427fcede3SMatthew G. Knepley #if 1
541527fcede3SMatthew G. Knepley       if ((newp < eMaxNew) || (newp >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid edge [%d, %d)", newp, eMaxNew, eEndNew);
541627fcede3SMatthew G. Knepley       for (p = 0; p < 4; ++p) {
541727fcede3SMatthew G. Knepley         if ((supportRef[p] < fMaxNew) || (supportRef[p] >= fEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a hybrid face [%d, %d)", supportRef[p], fMaxNew, fEndNew);
541827fcede3SMatthew G. Knepley       }
541927fcede3SMatthew G. Knepley #endif
542027fcede3SMatthew G. Knepley     }
542127fcede3SMatthew G. Knepley     /* Interior vertices have identical supports */
542227fcede3SMatthew G. Knepley     for (v = vStart; v < vEnd; ++v) {
542327fcede3SMatthew G. Knepley       const PetscInt  newp = vStartNew + (v - vStart);
542427fcede3SMatthew G. Knepley       const PetscInt *support, *cone;
542527fcede3SMatthew G. Knepley       PetscInt        size, s;
542627fcede3SMatthew G. Knepley 
542727fcede3SMatthew G. Knepley       ierr = DMPlexGetSupportSize(dm, v, &size);CHKERRQ(ierr);
542827fcede3SMatthew G. Knepley       ierr = DMPlexGetSupport(dm, v, &support);CHKERRQ(ierr);
542927fcede3SMatthew G. Knepley       for (s = 0; s < size; ++s) {
543027fcede3SMatthew G. Knepley         PetscInt r = 0;
543127fcede3SMatthew G. Knepley 
543227fcede3SMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
543327fcede3SMatthew G. Knepley         if (cone[1] == v) r = 1;
543427fcede3SMatthew G. Knepley         if (support[s] < eMax) supportRef[s] = eStartNew + (support[s] - eStart)*2 + r;
543527fcede3SMatthew G. Knepley         else                   supportRef[s] = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (cMax - cStart)*6 + (support[s] - eMax);
543627fcede3SMatthew G. Knepley       }
543727fcede3SMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
543827fcede3SMatthew G. Knepley #if 1
543927fcede3SMatthew G. Knepley       if ((newp < vStartNew) || (newp >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", newp, vStartNew, vEndNew);
544027fcede3SMatthew G. Knepley       for (p = 0; p < size; ++p) {
544127fcede3SMatthew G. Knepley         if ((supportRef[p] < eStartNew) || (supportRef[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", supportRef[p], eStartNew, eEndNew);
544227fcede3SMatthew G. Knepley       }
544327fcede3SMatthew G. Knepley #endif
544427fcede3SMatthew G. Knepley     }
544527fcede3SMatthew G. Knepley     /* Interior edge vertices have 2 + faces supports */
544627fcede3SMatthew G. Knepley     for (e = eStart; e < eMax; ++e) {
544727fcede3SMatthew G. Knepley       const PetscInt  newp = vStartNew + (vEnd - vStart) + (e - eStart);
544827fcede3SMatthew G. Knepley       const PetscInt *cone, *support;
544927fcede3SMatthew G. Knepley       PetscInt        size, s;
545027fcede3SMatthew G. Knepley 
545127fcede3SMatthew G. Knepley       ierr          = DMPlexGetSupportSize(dm, e, &size);CHKERRQ(ierr);
545227fcede3SMatthew G. Knepley       ierr          = DMPlexGetSupport(dm, e, &support);CHKERRQ(ierr);
545327fcede3SMatthew G. Knepley       supportRef[0] = eStartNew + (e - eStart)*2 + 0;
545427fcede3SMatthew G. Knepley       supportRef[1] = eStartNew + (e - eStart)*2 + 1;
545527fcede3SMatthew G. Knepley       for (s = 0; s < size; ++s) {
545627fcede3SMatthew G. Knepley         PetscInt r;
545727fcede3SMatthew G. Knepley 
545827fcede3SMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
545927fcede3SMatthew G. Knepley         for (r = 0; r < 4; ++r) if (cone[r] == e) break;
546027fcede3SMatthew G. Knepley         if (support[s] < fMax) {
546127fcede3SMatthew G. Knepley           supportRef[2+s] = eStartNew + (eMax - eStart)*2 + (support[s] - fStart)*4 + r;
546227fcede3SMatthew G. Knepley         } else {
546327fcede3SMatthew G. Knepley           supportRef[2+s] = eStartNew + (eMax - eStart)*2 + (fMax       - fStart)*4 + (cMax - cStart)*6 + (eEnd - eMax) + (support[s] - fMax);
546427fcede3SMatthew G. Knepley         }
546527fcede3SMatthew G. Knepley       }
546627fcede3SMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
546727fcede3SMatthew G. Knepley #if 1
546827fcede3SMatthew G. Knepley       if ((newp < vStartNew) || (newp >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", newp, vStartNew, vEndNew);
546927fcede3SMatthew G. Knepley       for (p = 0; p < 2+size; ++p) {
547027fcede3SMatthew G. Knepley         if ((supportRef[p] < eStartNew) || (supportRef[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", supportRef[p], eStartNew, eEndNew);
547127fcede3SMatthew G. Knepley       }
547227fcede3SMatthew G. Knepley #endif
547327fcede3SMatthew G. Knepley     }
547427fcede3SMatthew G. Knepley     /* Interior face vertices have 4 + cells supports */
547527fcede3SMatthew G. Knepley     for (f = fStart; f < fMax; ++f) {
547627fcede3SMatthew G. Knepley       const PetscInt  newp = vStartNew + (vEnd - vStart) + (eMax - eStart) + (f - fStart);
547727fcede3SMatthew G. Knepley       const PetscInt *cone, *support;
547827fcede3SMatthew G. Knepley       PetscInt        size, s;
547927fcede3SMatthew G. Knepley 
548027fcede3SMatthew G. Knepley       ierr          = DMPlexGetSupportSize(dm, f, &size);CHKERRQ(ierr);
548127fcede3SMatthew G. Knepley       ierr          = DMPlexGetSupport(dm, f, &support);CHKERRQ(ierr);
548227fcede3SMatthew G. Knepley       for (r = 0; r < 4; ++r) supportRef[r] = eStartNew + (eMax - eStart)*2 +  (f - fStart)*4 + r;
548327fcede3SMatthew G. Knepley       for (s = 0; s < size; ++s) {
548427fcede3SMatthew G. Knepley         PetscInt r;
548527fcede3SMatthew G. Knepley 
548627fcede3SMatthew G. Knepley         ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr);
548727fcede3SMatthew G. Knepley         for (r = 0; r < 6; ++r) if (cone[r] == f) break;
548827fcede3SMatthew G. Knepley         if (support[s] < cMax) {
548927fcede3SMatthew G. Knepley           supportRef[4+s] = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (support[s] - cStart)*6 + r;
549027fcede3SMatthew G. Knepley         } else {
549127fcede3SMatthew G. Knepley           supportRef[4+s] = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (cMax       - cStart)*6 + (eEnd - eMax) + (fEnd - fMax) + (support[s] - cMax);
549227fcede3SMatthew G. Knepley         }
549327fcede3SMatthew G. Knepley       }
549427fcede3SMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportRef);CHKERRQ(ierr);
549527fcede3SMatthew G. Knepley #if 1
549627fcede3SMatthew G. Knepley       if ((newp < vStartNew) || (newp >= vEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not a vertex [%d, %d)", newp, vStartNew, vEndNew);
549727fcede3SMatthew G. Knepley       for (p = 0; p < 4+size; ++p) {
549827fcede3SMatthew G. Knepley         if ((supportRef[p] < eStartNew) || (supportRef[p] >= eEndNew)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Point %d is not an edge [%d, %d)", supportRef[p], eStartNew, eEndNew);
549927fcede3SMatthew G. Knepley       }
550027fcede3SMatthew G. Knepley #endif
550127fcede3SMatthew G. Knepley     }
550227fcede3SMatthew G. Knepley     /* Cell vertices have 6 supports */
550327fcede3SMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
550427fcede3SMatthew G. Knepley       const PetscInt newp = vStartNew + (vEnd - vStart) + (eMax - eStart) + (fMax - fStart) + (c - cStart);
550527fcede3SMatthew G. Knepley       PetscInt       supportNew[6];
550627fcede3SMatthew G. Knepley 
550727fcede3SMatthew G. Knepley       for (r = 0; r < 6; ++r) {
550827fcede3SMatthew G. Knepley         supportNew[r] = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (c - cStart)*6 + r;
550927fcede3SMatthew G. Knepley       }
551027fcede3SMatthew G. Knepley       ierr = DMPlexSetSupport(rdm, newp, supportNew);CHKERRQ(ierr);
551127fcede3SMatthew G. Knepley     }
551227fcede3SMatthew G. Knepley     ierr = PetscFree(supportRef);CHKERRQ(ierr);
551327fcede3SMatthew G. Knepley     break;
551475d3a19aSMatthew G. Knepley   default:
551575d3a19aSMatthew G. Knepley     SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Unknown cell refiner %d", refiner);
551675d3a19aSMatthew G. Knepley   }
551775d3a19aSMatthew G. Knepley   PetscFunctionReturn(0);
551875d3a19aSMatthew G. Knepley }
551975d3a19aSMatthew G. Knepley 
552075d3a19aSMatthew G. Knepley #undef __FUNCT__
552175d3a19aSMatthew G. Knepley #define __FUNCT__ "CellRefinerSetCoordinates"
552286150812SJed Brown static PetscErrorCode CellRefinerSetCoordinates(CellRefiner refiner, DM dm, PetscInt depthSize[], DM rdm)
552375d3a19aSMatthew G. Knepley {
552475d3a19aSMatthew G. Knepley   PetscSection   coordSection, coordSectionNew;
552575d3a19aSMatthew G. Knepley   Vec            coordinates, coordinatesNew;
552675d3a19aSMatthew G. Knepley   PetscScalar   *coords, *coordsNew;
55273478d7aaSMatthew G. Knepley   const PetscInt numVertices = depthSize ? depthSize[0] : 0;
5528a57030b0SMatthew G. Knepley   PetscInt       dim, spaceDim, depth, bs, coordSizeNew, cStart, cEnd, cMax, c, vStart, vStartNew, vEnd, v, eStart, eEnd, eMax, e, fStart, fEnd, fMax, f;
552975d3a19aSMatthew G. Knepley   PetscErrorCode ierr;
553075d3a19aSMatthew G. Knepley 
553175d3a19aSMatthew G. Knepley   PetscFunctionBegin;
5532a57030b0SMatthew G. Knepley   ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr);
553375d3a19aSMatthew G. Knepley   ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr);
553475d3a19aSMatthew G. Knepley   ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr);
5535b5da9499SMatthew G. Knepley   ierr = DMPlexGetDepthStratum(dm, 1, &eStart, &eEnd);CHKERRQ(ierr);
553675d3a19aSMatthew G. Knepley   ierr = DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd);CHKERRQ(ierr);
553775d3a19aSMatthew G. Knepley   ierr = DMPlexGetHeightStratum(dm, 1, &fStart, &fEnd);CHKERRQ(ierr);
553827fcede3SMatthew G. Knepley   ierr = DMPlexGetHybridBounds(dm, &cMax, &fMax, &eMax, NULL);CHKERRQ(ierr);
55393478d7aaSMatthew G. Knepley   if (refiner) {ierr = GetDepthStart_Private(depth, depthSize, NULL, NULL, NULL, &vStartNew);CHKERRQ(ierr);}
554075d3a19aSMatthew G. Knepley   ierr = GetDepthStart_Private(depth, depthSize, NULL, NULL, NULL, &vStartNew);CHKERRQ(ierr);
5541f719d809SMatthew G. Knepley   ierr = DMGetCoordinateSection(dm, &coordSection);CHKERRQ(ierr);
5542f1d7821bSLawrence Mitchell   ierr = PetscSectionGetFieldComponents(coordSection, 0, &spaceDim);CHKERRQ(ierr);
554375d3a19aSMatthew G. Knepley   ierr = PetscSectionCreate(PetscObjectComm((PetscObject)dm), &coordSectionNew);CHKERRQ(ierr);
554475d3a19aSMatthew G. Knepley   ierr = PetscSectionSetNumFields(coordSectionNew, 1);CHKERRQ(ierr);
5545f1d7821bSLawrence Mitchell   ierr = PetscSectionSetFieldComponents(coordSectionNew, 0, spaceDim);CHKERRQ(ierr);
55463478d7aaSMatthew G. Knepley   ierr = PetscSectionSetChart(coordSectionNew, vStartNew, vStartNew+numVertices);CHKERRQ(ierr);
554727fcede3SMatthew G. Knepley   if (cMax < 0) cMax = cEnd;
554875d3a19aSMatthew G. Knepley   if (fMax < 0) fMax = fEnd;
5549b5da9499SMatthew G. Knepley   if (eMax < 0) eMax = eEnd;
5550f1d7821bSLawrence Mitchell   /* All vertices have the spaceDim coordinates */
55513478d7aaSMatthew G. Knepley   for (v = vStartNew; v < vStartNew+numVertices; ++v) {
5552f1d7821bSLawrence Mitchell     ierr = PetscSectionSetDof(coordSectionNew, v, spaceDim);CHKERRQ(ierr);
5553f1d7821bSLawrence Mitchell     ierr = PetscSectionSetFieldDof(coordSectionNew, v, 0, spaceDim);CHKERRQ(ierr);
555475d3a19aSMatthew G. Knepley   }
555575d3a19aSMatthew G. Knepley   ierr = PetscSectionSetUp(coordSectionNew);CHKERRQ(ierr);
555646e270d4SMatthew G. Knepley   ierr = DMSetCoordinateSection(rdm, PETSC_DETERMINE, coordSectionNew);CHKERRQ(ierr);
555775d3a19aSMatthew G. Knepley   ierr = DMGetCoordinatesLocal(dm, &coordinates);CHKERRQ(ierr);
555875d3a19aSMatthew G. Knepley   ierr = PetscSectionGetStorageSize(coordSectionNew, &coordSizeNew);CHKERRQ(ierr);
555975d3a19aSMatthew G. Knepley   ierr = VecCreate(PetscObjectComm((PetscObject)dm), &coordinatesNew);CHKERRQ(ierr);
556075d3a19aSMatthew G. Knepley   ierr = PetscObjectSetName((PetscObject) coordinatesNew, "coordinates");CHKERRQ(ierr);
556175d3a19aSMatthew G. Knepley   ierr = VecSetSizes(coordinatesNew, coordSizeNew, PETSC_DETERMINE);CHKERRQ(ierr);
556260b9e8a1SMatthew G. Knepley   ierr = VecGetBlockSize(coordinates, &bs);CHKERRQ(ierr);
556360b9e8a1SMatthew G. Knepley   ierr = VecSetBlockSize(coordinatesNew, bs);CHKERRQ(ierr);
556475d3a19aSMatthew G. Knepley   ierr = VecSetFromOptions(coordinatesNew);CHKERRQ(ierr);
556575d3a19aSMatthew G. Knepley   ierr = VecGetArray(coordinates, &coords);CHKERRQ(ierr);
556675d3a19aSMatthew G. Knepley   ierr = VecGetArray(coordinatesNew, &coordsNew);CHKERRQ(ierr);
5567b5da9499SMatthew G. Knepley   switch (refiner) {
55689b1a0e7fSLawrence Mitchell   case REFINER_NOOP: break;
55699b1a0e7fSLawrence Mitchell   case REFINER_HEX_3D:
55709b1a0e7fSLawrence Mitchell   case REFINER_HYBRID_HEX_3D:
5571b5da9499SMatthew G. Knepley     /* Face vertices have the average of corner coordinates */
5572d856d60fSMatthew G. Knepley     for (f = fStart; f < fMax; ++f) {
557327fcede3SMatthew G. Knepley       const PetscInt newv = vStartNew + (vEnd - vStart) + (eMax - eStart) + (f - fStart);
5574b5da9499SMatthew G. Knepley       PetscInt      *cone = NULL;
5575b5da9499SMatthew G. Knepley       PetscInt       closureSize, coneSize = 0, off[8], offnew, p, d;
5576b5da9499SMatthew G. Knepley 
5577b5da9499SMatthew G. Knepley       ierr = DMPlexGetTransitiveClosure(dm, f, PETSC_TRUE, &closureSize, &cone);CHKERRQ(ierr);
5578b5da9499SMatthew G. Knepley       for (p = 0; p < closureSize*2; p += 2) {
5579b5da9499SMatthew G. Knepley         const PetscInt point = cone[p];
5580b5da9499SMatthew G. Knepley         if ((point >= vStart) && (point < vEnd)) cone[coneSize++] = point;
5581b5da9499SMatthew G. Knepley       }
5582b5da9499SMatthew G. Knepley       for (v = 0; v < coneSize; ++v) {
5583b5da9499SMatthew G. Knepley         ierr = PetscSectionGetOffset(coordSection, cone[v], &off[v]);CHKERRQ(ierr);
5584b5da9499SMatthew G. Knepley       }
5585b5da9499SMatthew G. Knepley       ierr = PetscSectionGetOffset(coordSectionNew, newv, &offnew);CHKERRQ(ierr);
5586f1d7821bSLawrence Mitchell       for (d = 0; d < spaceDim; ++d) coordsNew[offnew+d] = 0.0;
5587f1d7821bSLawrence Mitchell       for (v = 0; v < coneSize; ++v) {ierr = DMPlexLocalizeAddCoordinate_Internal(dm, spaceDim, &coords[off[0]], &coords[off[v]], &coordsNew[offnew]);CHKERRQ(ierr);}
5588f1d7821bSLawrence Mitchell       for (d = 0; d < spaceDim; ++d) coordsNew[offnew+d] /= coneSize;
5589b5da9499SMatthew G. Knepley       ierr = DMPlexRestoreTransitiveClosure(dm, f, PETSC_TRUE, &closureSize, &cone);CHKERRQ(ierr);
5590b5da9499SMatthew G. Knepley     }
55919b1a0e7fSLawrence Mitchell   case REFINER_HEX_2D:
55929b1a0e7fSLawrence Mitchell   case REFINER_HYBRID_HEX_2D:
5593383c10e6SMatthew G. Knepley   case REFINER_SIMPLEX_1D:
5594b5da9499SMatthew G. Knepley     /* Cell vertices have the average of corner coordinates */
559527fcede3SMatthew G. Knepley     for (c = cStart; c < cMax; ++c) {
55962ed5862eSMatthew G. Knepley       const PetscInt newv = vStartNew + (vEnd - vStart) + (dim > 1 ? (eMax - eStart) : 0) + (c - cStart) + (dim > 2 ? (fMax - fStart) : 0);
5597b5da9499SMatthew G. Knepley       PetscInt      *cone = NULL;
5598b5da9499SMatthew G. Knepley       PetscInt       closureSize, coneSize = 0, off[8], offnew, p, d;
5599b5da9499SMatthew G. Knepley 
5600b5da9499SMatthew G. Knepley       ierr = DMPlexGetTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &cone);CHKERRQ(ierr);
5601b5da9499SMatthew G. Knepley       for (p = 0; p < closureSize*2; p += 2) {
5602b5da9499SMatthew G. Knepley         const PetscInt point = cone[p];
5603b5da9499SMatthew G. Knepley         if ((point >= vStart) && (point < vEnd)) cone[coneSize++] = point;
5604b5da9499SMatthew G. Knepley       }
5605b5da9499SMatthew G. Knepley       for (v = 0; v < coneSize; ++v) {
5606b5da9499SMatthew G. Knepley         ierr = PetscSectionGetOffset(coordSection, cone[v], &off[v]);CHKERRQ(ierr);
5607b5da9499SMatthew G. Knepley       }
5608b5da9499SMatthew G. Knepley       ierr = PetscSectionGetOffset(coordSectionNew, newv, &offnew);CHKERRQ(ierr);
5609f1d7821bSLawrence Mitchell       for (d = 0; d < spaceDim; ++d) coordsNew[offnew+d] = 0.0;
5610f1d7821bSLawrence Mitchell       for (v = 0; v < coneSize; ++v) {ierr = DMPlexLocalizeAddCoordinate_Internal(dm, spaceDim, &coords[off[0]], &coords[off[v]], &coordsNew[offnew]);CHKERRQ(ierr);}
5611f1d7821bSLawrence Mitchell       for (d = 0; d < spaceDim; ++d) coordsNew[offnew+d] /= coneSize;
5612b5da9499SMatthew G. Knepley       ierr = DMPlexRestoreTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &cone);CHKERRQ(ierr);
5613b5da9499SMatthew G. Knepley     }
56149b1a0e7fSLawrence Mitchell   case REFINER_SIMPLEX_2D:
56159b1a0e7fSLawrence Mitchell   case REFINER_HYBRID_SIMPLEX_2D:
56169b1a0e7fSLawrence Mitchell   case REFINER_SIMPLEX_3D:
56179b1a0e7fSLawrence Mitchell   case REFINER_HYBRID_SIMPLEX_3D:
5618b5da9499SMatthew G. Knepley     /* Edge vertices have the average of endpoint coordinates */
5619b5da9499SMatthew G. Knepley     for (e = eStart; e < eMax; ++e) {
5620b5da9499SMatthew G. Knepley       const PetscInt  newv = vStartNew + (vEnd - vStart) + (e - eStart);
5621b5da9499SMatthew G. Knepley       const PetscInt *cone;
5622b5da9499SMatthew G. Knepley       PetscInt        coneSize, offA, offB, offnew, d;
5623b5da9499SMatthew G. Knepley 
5624b5da9499SMatthew G. Knepley       ierr = DMPlexGetConeSize(dm, e, &coneSize);CHKERRQ(ierr);
5625b5da9499SMatthew G. Knepley       if (coneSize != 2) SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "Edge %d cone should have two vertices, not %d", e, coneSize);
5626b5da9499SMatthew G. Knepley       ierr = DMPlexGetCone(dm, e, &cone);CHKERRQ(ierr);
5627b5da9499SMatthew G. Knepley       ierr = PetscSectionGetOffset(coordSection, cone[0], &offA);CHKERRQ(ierr);
5628b5da9499SMatthew G. Knepley       ierr = PetscSectionGetOffset(coordSection, cone[1], &offB);CHKERRQ(ierr);
5629b5da9499SMatthew G. Knepley       ierr = PetscSectionGetOffset(coordSectionNew, newv, &offnew);CHKERRQ(ierr);
5630f1d7821bSLawrence Mitchell       ierr = DMPlexLocalizeCoordinate_Internal(dm, spaceDim, &coords[offA], &coords[offB], &coordsNew[offnew]);CHKERRQ(ierr);
5631f1d7821bSLawrence Mitchell       for (d = 0; d < spaceDim; ++d) {
5632a96104c9SMatthew G. Knepley         coordsNew[offnew+d] = 0.5*(coords[offA+d] + coordsNew[offnew+d]);
5633b5da9499SMatthew G. Knepley       }
5634b5da9499SMatthew G. Knepley     }
563575d3a19aSMatthew G. Knepley     /* Old vertices have the same coordinates */
563675d3a19aSMatthew G. Knepley     for (v = vStart; v < vEnd; ++v) {
563775d3a19aSMatthew G. Knepley       const PetscInt newv = vStartNew + (v - vStart);
563875d3a19aSMatthew G. Knepley       PetscInt       off, offnew, d;
563975d3a19aSMatthew G. Knepley 
564075d3a19aSMatthew G. Knepley       ierr = PetscSectionGetOffset(coordSection, v, &off);CHKERRQ(ierr);
564175d3a19aSMatthew G. Knepley       ierr = PetscSectionGetOffset(coordSectionNew, newv, &offnew);CHKERRQ(ierr);
5642f1d7821bSLawrence Mitchell       for (d = 0; d < spaceDim; ++d) {
564375d3a19aSMatthew G. Knepley         coordsNew[offnew+d] = coords[off+d];
564475d3a19aSMatthew G. Knepley       }
564575d3a19aSMatthew G. Knepley     }
5646b5da9499SMatthew G. Knepley     break;
5647b5da9499SMatthew G. Knepley   default:
5648b5da9499SMatthew G. Knepley     SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Unknown cell refiner %d", refiner);
564975d3a19aSMatthew G. Knepley   }
565075d3a19aSMatthew G. Knepley   ierr = VecRestoreArray(coordinates, &coords);CHKERRQ(ierr);
565175d3a19aSMatthew G. Knepley   ierr = VecRestoreArray(coordinatesNew, &coordsNew);CHKERRQ(ierr);
565275d3a19aSMatthew G. Knepley   ierr = DMSetCoordinatesLocal(rdm, coordinatesNew);CHKERRQ(ierr);
565375d3a19aSMatthew G. Knepley   ierr = VecDestroy(&coordinatesNew);CHKERRQ(ierr);
565475d3a19aSMatthew G. Knepley   ierr = PetscSectionDestroy(&coordSectionNew);CHKERRQ(ierr);
5655a96104c9SMatthew G. Knepley   if (dm->maxCell) {
5656a96104c9SMatthew G. Knepley     const PetscReal *maxCell, *L;
56575dc8c3f7SMatthew G. Knepley     const DMBoundaryType *bd;
56585dc8c3f7SMatthew G. Knepley     ierr = DMGetPeriodicity(dm,  &maxCell, &L, &bd);CHKERRQ(ierr);
56595dc8c3f7SMatthew G. Knepley     ierr = DMSetPeriodicity(rdm,  maxCell,  L,  bd);CHKERRQ(ierr);
5660a96104c9SMatthew G. Knepley   }
566175d3a19aSMatthew G. Knepley   PetscFunctionReturn(0);
566275d3a19aSMatthew G. Knepley }
566375d3a19aSMatthew G. Knepley 
566475d3a19aSMatthew G. Knepley #undef __FUNCT__
566575d3a19aSMatthew G. Knepley #define __FUNCT__ "DMPlexCreateProcessSF"
5666963fc26aSMatthew G. Knepley /*@
5667963fc26aSMatthew G. Knepley   DMPlexCreateProcessSF - Create an SF which just has process connectivity
5668963fc26aSMatthew G. Knepley 
5669963fc26aSMatthew G. Knepley   Collective on DM
5670963fc26aSMatthew G. Knepley 
5671963fc26aSMatthew G. Knepley   Input Parameters:
5672963fc26aSMatthew G. Knepley + dm      - The DM
5673963fc26aSMatthew G. Knepley - sfPoint - The PetscSF which encodes point connectivity
5674963fc26aSMatthew G. Knepley 
5675963fc26aSMatthew G. Knepley   Output Parameters:
5676963fc26aSMatthew G. Knepley + processRanks - A list of process neighbors, or NULL
5677963fc26aSMatthew G. Knepley - sfProcess    - An SF encoding the process connectivity, or NULL
5678963fc26aSMatthew G. Knepley 
5679963fc26aSMatthew G. Knepley   Level: developer
5680963fc26aSMatthew G. Knepley 
5681963fc26aSMatthew G. Knepley .seealso: PetscSFCreate(), DMPlexCreateTwoSidedProcessSF()
5682963fc26aSMatthew G. Knepley @*/
5683963fc26aSMatthew G. Knepley PetscErrorCode DMPlexCreateProcessSF(DM dm, PetscSF sfPoint, IS *processRanks, PetscSF *sfProcess)
568475d3a19aSMatthew G. Knepley {
568575d3a19aSMatthew G. Knepley   PetscInt           numRoots, numLeaves, l;
568675d3a19aSMatthew G. Knepley   const PetscInt    *localPoints;
568775d3a19aSMatthew G. Knepley   const PetscSFNode *remotePoints;
568875d3a19aSMatthew G. Knepley   PetscInt          *localPointsNew;
568975d3a19aSMatthew G. Knepley   PetscSFNode       *remotePointsNew;
569075d3a19aSMatthew G. Knepley   PetscInt          *ranks, *ranksNew;
5691963fc26aSMatthew G. Knepley   PetscMPIInt        numProcs;
569275d3a19aSMatthew G. Knepley   PetscErrorCode     ierr;
569375d3a19aSMatthew G. Knepley 
569475d3a19aSMatthew G. Knepley   PetscFunctionBegin;
5695963fc26aSMatthew G. Knepley   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
5696963fc26aSMatthew G. Knepley   PetscValidHeaderSpecific(sfPoint, PETSCSF_CLASSID, 2);
5697963fc26aSMatthew G. Knepley   if (processRanks) {PetscValidPointer(processRanks, 3);}
5698963fc26aSMatthew G. Knepley   if (sfProcess)    {PetscValidPointer(sfProcess, 4);}
5699963fc26aSMatthew G. Knepley   ierr = MPI_Comm_size(PetscObjectComm((PetscObject) dm), &numProcs);CHKERRQ(ierr);
570075d3a19aSMatthew G. Knepley   ierr = PetscSFGetGraph(sfPoint, &numRoots, &numLeaves, &localPoints, &remotePoints);CHKERRQ(ierr);
5701785e854fSJed Brown   ierr = PetscMalloc1(numLeaves, &ranks);CHKERRQ(ierr);
570275d3a19aSMatthew G. Knepley   for (l = 0; l < numLeaves; ++l) {
570375d3a19aSMatthew G. Knepley     ranks[l] = remotePoints[l].rank;
570475d3a19aSMatthew G. Knepley   }
570575d3a19aSMatthew G. Knepley   ierr = PetscSortRemoveDupsInt(&numLeaves, ranks);CHKERRQ(ierr);
5706785e854fSJed Brown   ierr = PetscMalloc1(numLeaves, &ranksNew);CHKERRQ(ierr);
5707785e854fSJed Brown   ierr = PetscMalloc1(numLeaves, &localPointsNew);CHKERRQ(ierr);
5708785e854fSJed Brown   ierr = PetscMalloc1(numLeaves, &remotePointsNew);CHKERRQ(ierr);
570975d3a19aSMatthew G. Knepley   for (l = 0; l < numLeaves; ++l) {
571075d3a19aSMatthew G. Knepley     ranksNew[l]              = ranks[l];
571175d3a19aSMatthew G. Knepley     localPointsNew[l]        = l;
571275d3a19aSMatthew G. Knepley     remotePointsNew[l].index = 0;
571375d3a19aSMatthew G. Knepley     remotePointsNew[l].rank  = ranksNew[l];
571475d3a19aSMatthew G. Knepley   }
571575d3a19aSMatthew G. Knepley   ierr = PetscFree(ranks);CHKERRQ(ierr);
5716963fc26aSMatthew G. Knepley   if (processRanks) {ierr = ISCreateGeneral(PetscObjectComm((PetscObject)dm), numLeaves, ranksNew, PETSC_OWN_POINTER, processRanks);CHKERRQ(ierr);}
5717963fc26aSMatthew G. Knepley   else              {ierr = PetscFree(ranksNew);CHKERRQ(ierr);}
5718963fc26aSMatthew G. Knepley   if (sfProcess) {
571975d3a19aSMatthew G. Knepley     ierr = PetscSFCreate(PetscObjectComm((PetscObject)dm), sfProcess);CHKERRQ(ierr);
5720963fc26aSMatthew G. Knepley     ierr = PetscObjectSetName((PetscObject) *sfProcess, "Process SF");CHKERRQ(ierr);
572175d3a19aSMatthew G. Knepley     ierr = PetscSFSetFromOptions(*sfProcess);CHKERRQ(ierr);
5722963fc26aSMatthew G. Knepley     ierr = PetscSFSetGraph(*sfProcess, numProcs, numLeaves, localPointsNew, PETSC_OWN_POINTER, remotePointsNew, PETSC_OWN_POINTER);CHKERRQ(ierr);
5723963fc26aSMatthew G. Knepley   }
572475d3a19aSMatthew G. Knepley   PetscFunctionReturn(0);
572575d3a19aSMatthew G. Knepley }
572675d3a19aSMatthew G. Knepley 
572775d3a19aSMatthew G. Knepley #undef __FUNCT__
572875d3a19aSMatthew G. Knepley #define __FUNCT__ "CellRefinerCreateSF"
572986150812SJed Brown static PetscErrorCode CellRefinerCreateSF(CellRefiner refiner, DM dm, PetscInt depthSize[], DM rdm)
573075d3a19aSMatthew G. Knepley {
573175d3a19aSMatthew G. Knepley   PetscSF            sf, sfNew, sfProcess;
573275d3a19aSMatthew G. Knepley   IS                 processRanks;
573375d3a19aSMatthew G. Knepley   MPI_Datatype       depthType;
573475d3a19aSMatthew G. Knepley   PetscInt           numRoots, numLeaves, numLeavesNew = 0, l, m;
573575d3a19aSMatthew G. Knepley   const PetscInt    *localPoints, *neighbors;
573675d3a19aSMatthew G. Knepley   const PetscSFNode *remotePoints;
573775d3a19aSMatthew G. Knepley   PetscInt          *localPointsNew;
573875d3a19aSMatthew G. Knepley   PetscSFNode       *remotePointsNew;
573975d3a19aSMatthew G. Knepley   PetscInt          *depthSizeOld, *rdepthSize, *rdepthSizeOld, *rdepthMaxOld, *rvStart, *rvStartNew, *reStart, *reStartNew, *rfStart, *rfStartNew, *rcStart, *rcStartNew;
57407ba685a0SMatthew G. Knepley   PetscInt           depth, numNeighbors, pStartNew, pEndNew, cStart, cEnd, cMax, vStart, vEnd, vMax, fStart, fEnd, fMax, eStart, eEnd, eMax, r, n;
57417ba685a0SMatthew G. Knepley   PetscInt           cStartNew = 0, vStartNew = 0, fStartNew = 0, eStartNew = 0;
574275d3a19aSMatthew G. Knepley   PetscErrorCode     ierr;
574375d3a19aSMatthew G. Knepley 
574475d3a19aSMatthew G. Knepley   PetscFunctionBegin;
574575d3a19aSMatthew G. Knepley   ierr = DMPlexGetChart(rdm, &pStartNew, &pEndNew);CHKERRQ(ierr);
574675d3a19aSMatthew G. Knepley   ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr);
574775d3a19aSMatthew G. Knepley   ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr);
574875d3a19aSMatthew G. Knepley   ierr = DMPlexGetDepthStratum(dm, 1, &eStart, &eEnd);CHKERRQ(ierr);
574975d3a19aSMatthew G. Knepley   ierr = DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd);CHKERRQ(ierr);
575075d3a19aSMatthew G. Knepley   ierr = DMPlexGetHeightStratum(dm, 1, &fStart, &fEnd);CHKERRQ(ierr);
575175d3a19aSMatthew G. Knepley   ierr = DMPlexGetHybridBounds(dm, &cMax, &fMax, &eMax, &vMax);CHKERRQ(ierr);
5752add09238SMatthew G. Knepley   cMax = cMax < 0 ? cEnd : cMax;
5753add09238SMatthew G. Knepley   fMax = fMax < 0 ? fEnd : fMax;
5754add09238SMatthew G. Knepley   eMax = eMax < 0 ? eEnd : eMax;
57553478d7aaSMatthew G. Knepley   if (refiner) {ierr = GetDepthStart_Private(depth, depthSize, &cStartNew, &fStartNew, &eStartNew, &vStartNew);CHKERRQ(ierr);}
575675d3a19aSMatthew G. Knepley   ierr = DMGetPointSF(dm, &sf);CHKERRQ(ierr);
575775d3a19aSMatthew G. Knepley   ierr = DMGetPointSF(rdm, &sfNew);CHKERRQ(ierr);
5758add09238SMatthew G. Knepley   /* Calculate size of new SF */
575975d3a19aSMatthew G. Knepley   ierr = PetscSFGetGraph(sf, &numRoots, &numLeaves, &localPoints, &remotePoints);CHKERRQ(ierr);
576075d3a19aSMatthew G. Knepley   if (numRoots < 0) PetscFunctionReturn(0);
576175d3a19aSMatthew G. Knepley   for (l = 0; l < numLeaves; ++l) {
576275d3a19aSMatthew G. Knepley     const PetscInt p = localPoints[l];
576375d3a19aSMatthew G. Knepley 
576475d3a19aSMatthew G. Knepley     switch (refiner) {
57650314a74cSLawrence Mitchell     case REFINER_SIMPLEX_1D:
57660314a74cSLawrence Mitchell       if ((p >= vStart) && (p < vEnd)) {
57670314a74cSLawrence Mitchell         /* Interior vertices stay the same */
57680314a74cSLawrence Mitchell         ++numLeavesNew;
57690314a74cSLawrence Mitchell       } else if ((p >= cStart && p < cMax)) {
57700314a74cSLawrence Mitchell         /* Interior cells add new cells and interior vertices */
57710314a74cSLawrence Mitchell         numLeavesNew += 2 + 1;
57720314a74cSLawrence Mitchell       }
57730314a74cSLawrence Mitchell       break;
57749b1a0e7fSLawrence Mitchell     case REFINER_SIMPLEX_2D:
57759b1a0e7fSLawrence Mitchell     case REFINER_HYBRID_SIMPLEX_2D:
5776a97b51b8SMatthew G. Knepley       if ((p >= vStart) && (p < vEnd)) {
5777a97b51b8SMatthew G. Knepley         /* Interior vertices stay the same */
5778a97b51b8SMatthew G. Knepley         ++numLeavesNew;
5779a97b51b8SMatthew G. Knepley       } else if ((p >= fStart) && (p < fMax)) {
5780a97b51b8SMatthew G. Knepley         /* Interior faces add new faces and vertex */
5781a97b51b8SMatthew G. Knepley         numLeavesNew += 2 + 1;
5782a97b51b8SMatthew G. Knepley       } else if ((p >= fMax) && (p < fEnd)) {
5783a97b51b8SMatthew G. Knepley         /* Hybrid faces stay the same */
5784a97b51b8SMatthew G. Knepley         ++numLeavesNew;
5785a97b51b8SMatthew G. Knepley       } else if ((p >= cStart) && (p < cMax)) {
5786a97b51b8SMatthew G. Knepley         /* Interior cells add new cells and interior faces */
5787a97b51b8SMatthew G. Knepley         numLeavesNew += 4 + 3;
5788a97b51b8SMatthew G. Knepley       } else if ((p >= cMax) && (p < cEnd)) {
5789a97b51b8SMatthew G. Knepley         /* Hybrid cells add new cells and hybrid face */
5790a97b51b8SMatthew G. Knepley         numLeavesNew += 2 + 1;
5791a97b51b8SMatthew G. Knepley       }
5792a97b51b8SMatthew G. Knepley       break;
57939b1a0e7fSLawrence Mitchell     case REFINER_HEX_2D:
57949b1a0e7fSLawrence Mitchell     case REFINER_HYBRID_HEX_2D:
5795a97b51b8SMatthew G. Knepley       if ((p >= vStart) && (p < vEnd)) {
5796a97b51b8SMatthew G. Knepley         /* Interior vertices stay the same */
5797a97b51b8SMatthew G. Knepley         ++numLeavesNew;
5798a97b51b8SMatthew G. Knepley       } else if ((p >= fStart) && (p < fMax)) {
5799a97b51b8SMatthew G. Knepley         /* Interior faces add new faces and vertex */
5800a97b51b8SMatthew G. Knepley         numLeavesNew += 2 + 1;
5801a97b51b8SMatthew G. Knepley       } else if ((p >= fMax) && (p < fEnd)) {
5802a97b51b8SMatthew G. Knepley         /* Hybrid faces stay the same */
5803a97b51b8SMatthew G. Knepley         ++numLeavesNew;
5804a97b51b8SMatthew G. Knepley       } else if ((p >= cStart) && (p < cMax)) {
5805a97b51b8SMatthew G. Knepley         /* Interior cells add new cells, interior faces, and vertex */
5806a97b51b8SMatthew G. Knepley         numLeavesNew += 4 + 4 + 1;
5807a97b51b8SMatthew G. Knepley       } else if ((p >= cMax) && (p < cEnd)) {
5808a97b51b8SMatthew G. Knepley         /* Hybrid cells add new cells and hybrid face */
5809a97b51b8SMatthew G. Knepley         numLeavesNew += 2 + 1;
5810a97b51b8SMatthew G. Knepley       }
5811a97b51b8SMatthew G. Knepley       break;
58129b1a0e7fSLawrence Mitchell     case REFINER_SIMPLEX_3D:
58139b1a0e7fSLawrence Mitchell     case REFINER_HYBRID_SIMPLEX_3D:
58146ce3c06aSMatthew G. Knepley       if ((p >= vStart) && (p < vEnd)) {
58156ce3c06aSMatthew G. Knepley         /* Interior vertices stay the same */
58166ce3c06aSMatthew G. Knepley         ++numLeavesNew;
58176ce3c06aSMatthew G. Knepley       } else if ((p >= eStart) && (p < eMax)) {
58186ce3c06aSMatthew G. Knepley         /* Interior edges add new edges and vertex */
58196ce3c06aSMatthew G. Knepley         numLeavesNew += 2 + 1;
58206ce3c06aSMatthew G. Knepley       } else if ((p >= eMax) && (p < eEnd)) {
58216ce3c06aSMatthew G. Knepley         /* Hybrid edges stay the same */
58226ce3c06aSMatthew G. Knepley         ++numLeavesNew;
58236ce3c06aSMatthew G. Knepley       } else if ((p >= fStart) && (p < fMax)) {
58246ce3c06aSMatthew G. Knepley         /* Interior faces add new faces and edges */
58256ce3c06aSMatthew G. Knepley         numLeavesNew += 4 + 3;
58266ce3c06aSMatthew G. Knepley       } else if ((p >= fMax) && (p < fEnd)) {
58276ce3c06aSMatthew G. Knepley         /* Hybrid faces add new faces and edges */
58286ce3c06aSMatthew G. Knepley         numLeavesNew += 2 + 1;
58296ce3c06aSMatthew G. Knepley       } else if ((p >= cStart) && (p < cMax)) {
58306ce3c06aSMatthew G. Knepley         /* Interior cells add new cells, faces, and edges */
58316ce3c06aSMatthew G. Knepley         numLeavesNew += 8 + 8 + 1;
58326ce3c06aSMatthew G. Knepley       } else if ((p >= cMax) && (p < cEnd)) {
58336ce3c06aSMatthew G. Knepley         /* Hybrid cells add new cells and faces */
58346ce3c06aSMatthew G. Knepley         numLeavesNew += 4 + 3;
58356ce3c06aSMatthew G. Knepley       }
58366ce3c06aSMatthew G. Knepley       break;
58379b1a0e7fSLawrence Mitchell     case REFINER_HEX_3D:
58389b1a0e7fSLawrence Mitchell     case REFINER_HYBRID_HEX_3D:
583927fcede3SMatthew G. Knepley       if ((p >= vStart) && (p < vEnd)) {
584027fcede3SMatthew G. Knepley         /* Old vertices stay the same */
584127fcede3SMatthew G. Knepley         ++numLeavesNew;
584227fcede3SMatthew G. Knepley       } else if ((p >= eStart) && (p < eMax)) {
584327fcede3SMatthew G. Knepley         /* Interior edges add new edges, and vertex */
584427fcede3SMatthew G. Knepley         numLeavesNew += 2 + 1;
584527fcede3SMatthew G. Knepley       } else if ((p >= eMax) && (p < eEnd)) {
584627fcede3SMatthew G. Knepley         /* Hybrid edges stay the same */
584727fcede3SMatthew G. Knepley         ++numLeavesNew;
584827fcede3SMatthew G. Knepley       } else if ((p >= fStart) && (p < fMax)) {
584927fcede3SMatthew G. Knepley         /* Interior faces add new faces, edges, and vertex */
585027fcede3SMatthew G. Knepley         numLeavesNew += 4 + 4 + 1;
585127fcede3SMatthew G. Knepley       } else if ((p >= fMax) && (p < fEnd)) {
585227fcede3SMatthew G. Knepley         /* Hybrid faces add new faces and edges */
585327fcede3SMatthew G. Knepley         numLeavesNew += 2 + 1;
585427fcede3SMatthew G. Knepley       } else if ((p >= cStart) && (p < cMax)) {
585527fcede3SMatthew G. Knepley         /* Interior cells add new cells, faces, edges, and vertex */
585627fcede3SMatthew G. Knepley         numLeavesNew += 8 + 12 + 6 + 1;
585727fcede3SMatthew G. Knepley       } else if ((p >= cStart) && (p < cEnd)) {
585827fcede3SMatthew G. Knepley         /* Hybrid cells add new cells, faces, and edges */
585927fcede3SMatthew G. Knepley         numLeavesNew += 4 + 4 + 1;
586027fcede3SMatthew G. Knepley       }
586127fcede3SMatthew G. Knepley       break;
586275d3a19aSMatthew G. Knepley     default:
586375d3a19aSMatthew G. Knepley       SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Unknown cell refiner %d", refiner);
586475d3a19aSMatthew G. Knepley     }
586575d3a19aSMatthew G. Knepley   }
586675d3a19aSMatthew G. Knepley   /* Communicate depthSizes for each remote rank */
586775d3a19aSMatthew G. Knepley   ierr = DMPlexCreateProcessSF(dm, sf, &processRanks, &sfProcess);CHKERRQ(ierr);
586875d3a19aSMatthew G. Knepley   ierr = ISGetLocalSize(processRanks, &numNeighbors);CHKERRQ(ierr);
5869dcca6d9dSJed Brown   ierr = PetscMalloc5((depth+1)*numNeighbors,&rdepthSize,numNeighbors,&rvStartNew,numNeighbors,&reStartNew,numNeighbors,&rfStartNew,numNeighbors,&rcStartNew);CHKERRQ(ierr);
5870dcca6d9dSJed Brown   ierr = PetscMalloc7(depth+1,&depthSizeOld,(depth+1)*numNeighbors,&rdepthSizeOld,(depth+1)*numNeighbors,&rdepthMaxOld,numNeighbors,&rvStart,numNeighbors,&reStart,numNeighbors,&rfStart,numNeighbors,&rcStart);CHKERRQ(ierr);
587175d3a19aSMatthew G. Knepley   ierr = MPI_Type_contiguous(depth+1, MPIU_INT, &depthType);CHKERRQ(ierr);
587275d3a19aSMatthew G. Knepley   ierr = MPI_Type_commit(&depthType);CHKERRQ(ierr);
587375d3a19aSMatthew G. Knepley   ierr = PetscSFBcastBegin(sfProcess, depthType, depthSize, rdepthSize);CHKERRQ(ierr);
587475d3a19aSMatthew G. Knepley   ierr = PetscSFBcastEnd(sfProcess, depthType, depthSize, rdepthSize);CHKERRQ(ierr);
587575d3a19aSMatthew G. Knepley   for (n = 0; n < numNeighbors; ++n) {
587675d3a19aSMatthew G. Knepley     ierr = GetDepthStart_Private(depth, &rdepthSize[n*(depth+1)], &rcStartNew[n], &rfStartNew[n], &reStartNew[n], &rvStartNew[n]);CHKERRQ(ierr);
587775d3a19aSMatthew G. Knepley   }
587875d3a19aSMatthew G. Knepley   depthSizeOld[depth]   = cMax;
587975d3a19aSMatthew G. Knepley   depthSizeOld[0]       = vMax;
588075d3a19aSMatthew G. Knepley   depthSizeOld[depth-1] = fMax;
588175d3a19aSMatthew G. Knepley   depthSizeOld[1]       = eMax;
588275d3a19aSMatthew G. Knepley 
588375d3a19aSMatthew G. Knepley   ierr = PetscSFBcastBegin(sfProcess, depthType, depthSizeOld, rdepthMaxOld);CHKERRQ(ierr);
588475d3a19aSMatthew G. Knepley   ierr = PetscSFBcastEnd(sfProcess, depthType, depthSizeOld, rdepthMaxOld);CHKERRQ(ierr);
588575d3a19aSMatthew G. Knepley 
588675d3a19aSMatthew G. Knepley   depthSizeOld[depth]   = cEnd - cStart;
588775d3a19aSMatthew G. Knepley   depthSizeOld[0]       = vEnd - vStart;
588875d3a19aSMatthew G. Knepley   depthSizeOld[depth-1] = fEnd - fStart;
588975d3a19aSMatthew G. Knepley   depthSizeOld[1]       = eEnd - eStart;
589075d3a19aSMatthew G. Knepley 
589175d3a19aSMatthew G. Knepley   ierr = PetscSFBcastBegin(sfProcess, depthType, depthSizeOld, rdepthSizeOld);CHKERRQ(ierr);
589275d3a19aSMatthew G. Knepley   ierr = PetscSFBcastEnd(sfProcess, depthType, depthSizeOld, rdepthSizeOld);CHKERRQ(ierr);
589375d3a19aSMatthew G. Knepley   for (n = 0; n < numNeighbors; ++n) {
589475d3a19aSMatthew G. Knepley     ierr = GetDepthStart_Private(depth, &rdepthSizeOld[n*(depth+1)], &rcStart[n], &rfStart[n], &reStart[n], &rvStart[n]);CHKERRQ(ierr);
58950252e7f5SMatthew G. Knepley     rdepthMaxOld[n*(depth+1)+depth]   = rdepthMaxOld[n*(depth+1)+depth]   < 0 ? rdepthSizeOld[n*(depth+1)+depth]  +rcStart[n]: rdepthMaxOld[n*(depth+1)+depth];
58960252e7f5SMatthew G. Knepley     rdepthMaxOld[n*(depth+1)+depth-1] = rdepthMaxOld[n*(depth+1)+depth-1] < 0 ? rdepthSizeOld[n*(depth+1)+depth-1]+rfStart[n]: rdepthMaxOld[n*(depth+1)+depth-1];
58970252e7f5SMatthew G. Knepley     rdepthMaxOld[n*(depth+1)+1]       = rdepthMaxOld[n*(depth+1)+1]       < 0 ? rdepthSizeOld[n*(depth+1)+1]      +reStart[n]: rdepthMaxOld[n*(depth+1)+1];
589875d3a19aSMatthew G. Knepley   }
589975d3a19aSMatthew G. Knepley   ierr = MPI_Type_free(&depthType);CHKERRQ(ierr);
590075d3a19aSMatthew G. Knepley   ierr = PetscSFDestroy(&sfProcess);CHKERRQ(ierr);
590175d3a19aSMatthew G. Knepley   /* Calculate new point SF */
5902785e854fSJed Brown   ierr = PetscMalloc1(numLeavesNew, &localPointsNew);CHKERRQ(ierr);
5903785e854fSJed Brown   ierr = PetscMalloc1(numLeavesNew, &remotePointsNew);CHKERRQ(ierr);
590475d3a19aSMatthew G. Knepley   ierr = ISGetIndices(processRanks, &neighbors);CHKERRQ(ierr);
590575d3a19aSMatthew G. Knepley   for (l = 0, m = 0; l < numLeaves; ++l) {
590675d3a19aSMatthew G. Knepley     PetscInt    p     = localPoints[l];
590775d3a19aSMatthew G. Knepley     PetscInt    rp    = remotePoints[l].index, n;
590875d3a19aSMatthew G. Knepley     PetscMPIInt rrank = remotePoints[l].rank;
590975d3a19aSMatthew G. Knepley 
591075d3a19aSMatthew G. Knepley     ierr = PetscFindInt(rrank, numNeighbors, neighbors, &n);CHKERRQ(ierr);
591175d3a19aSMatthew G. Knepley     if (n < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Could not locate remote rank %d", rrank);
591275d3a19aSMatthew G. Knepley     switch (refiner) {
59130314a74cSLawrence Mitchell     case REFINER_SIMPLEX_1D:
59140314a74cSLawrence Mitchell       if ((p >= vStart) && (p < vEnd)) {
59150314a74cSLawrence Mitchell         /* Old vertices stay the same */
59160314a74cSLawrence Mitchell         localPointsNew[m]        = vStartNew     + (p  - vStart);
59170314a74cSLawrence Mitchell         remotePointsNew[m].index = rvStartNew[n] + (rp - rvStart[n]);
59180314a74cSLawrence Mitchell         remotePointsNew[m].rank  = rrank;
59190314a74cSLawrence Mitchell         ++m;
59200314a74cSLawrence Mitchell       } else if ((p >= cStart) && (p < cMax)) {
59210314a74cSLawrence Mitchell         /* Old interior cells add new cells and vertex */
59220314a74cSLawrence Mitchell         for (r = 0; r < 2; ++r, ++m) {
59230314a74cSLawrence Mitchell           localPointsNew[m]        = cStartNew     + (p  - cStart)*2     + r;
59240314a74cSLawrence Mitchell           remotePointsNew[m].index = rcStartNew[n] + (rp - rcStart[n])*2 + r;
59250314a74cSLawrence Mitchell           remotePointsNew[m].rank  = rrank;
59260314a74cSLawrence Mitchell         }
59270314a74cSLawrence Mitchell         localPointsNew[m]        = vStartNew     + (vEnd - vStart)              + (p  - cStart);
59280314a74cSLawrence Mitchell         remotePointsNew[m].index = rvStartNew[n] + rdepthSizeOld[n*(depth+1)+0] + (rp - rcStart[n]);
59290314a74cSLawrence Mitchell         remotePointsNew[m].rank  = rrank;
59300314a74cSLawrence Mitchell         ++m;
59310314a74cSLawrence Mitchell       }
59320314a74cSLawrence Mitchell       break;
59339b1a0e7fSLawrence Mitchell     case REFINER_SIMPLEX_2D:
59349b1a0e7fSLawrence Mitchell     case REFINER_HYBRID_SIMPLEX_2D:
593575d3a19aSMatthew G. Knepley       if ((p >= vStart) && (p < vEnd)) {
593675d3a19aSMatthew G. Knepley         /* Old vertices stay the same */
593775d3a19aSMatthew G. Knepley         localPointsNew[m]        = vStartNew     + (p  - vStart);
593875d3a19aSMatthew G. Knepley         remotePointsNew[m].index = rvStartNew[n] + (rp - rvStart[n]);
593975d3a19aSMatthew G. Knepley         remotePointsNew[m].rank  = rrank;
594075d3a19aSMatthew G. Knepley         ++m;
594175d3a19aSMatthew G. Knepley       } else if ((p >= fStart) && (p < fMax)) {
594275d3a19aSMatthew G. Knepley         /* Old interior faces add new faces and vertex */
594375d3a19aSMatthew G. Knepley         for (r = 0; r < 2; ++r, ++m) {
594475d3a19aSMatthew G. Knepley           localPointsNew[m]        = fStartNew     + (p  - fStart)*2     + r;
594575d3a19aSMatthew G. Knepley           remotePointsNew[m].index = rfStartNew[n] + (rp - rfStart[n])*2 + r;
594675d3a19aSMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
594775d3a19aSMatthew G. Knepley         }
5948add09238SMatthew G. Knepley         localPointsNew[m]        = vStartNew     + (vEnd - vStart)              + (p  - fStart);
5949add09238SMatthew G. Knepley         remotePointsNew[m].index = rvStartNew[n] + rdepthSizeOld[n*(depth+1)+0] + (rp - rfStart[n]);
5950add09238SMatthew G. Knepley         remotePointsNew[m].rank  = rrank;
5951add09238SMatthew G. Knepley         ++m;
595275d3a19aSMatthew G. Knepley       } else if ((p >= fMax) && (p < fEnd)) {
595375d3a19aSMatthew G. Knepley         /* Old hybrid faces stay the same */
595475d3a19aSMatthew G. Knepley         localPointsNew[m]        = fStartNew     + (fMax                              - fStart)*2     + (p  - fMax);
595575d3a19aSMatthew G. Knepley         remotePointsNew[m].index = rfStartNew[n] + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n])*2 + (rp - rdepthMaxOld[n*(depth+1)+depth-1]);
595675d3a19aSMatthew G. Knepley         remotePointsNew[m].rank  = rrank;
595775d3a19aSMatthew G. Knepley         ++m;
595875d3a19aSMatthew G. Knepley       } else if ((p >= cStart) && (p < cMax)) {
595975d3a19aSMatthew G. Knepley         /* Old interior cells add new cells and interior faces */
596075d3a19aSMatthew G. Knepley         for (r = 0; r < 4; ++r, ++m) {
596175d3a19aSMatthew G. Knepley           localPointsNew[m]        = cStartNew     + (p  - cStart)*4     + r;
596275d3a19aSMatthew G. Knepley           remotePointsNew[m].index = rcStartNew[n] + (rp - rcStart[n])*4 + r;
596375d3a19aSMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
596475d3a19aSMatthew G. Knepley         }
596575d3a19aSMatthew G. Knepley         for (r = 0; r < 3; ++r, ++m) {
596675d3a19aSMatthew G. Knepley           localPointsNew[m]        = fStartNew     + (fMax                              - fStart)*2     + (p  - cStart)*3     + r;
596775d3a19aSMatthew G. Knepley           remotePointsNew[m].index = rfStartNew[n] + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n])*2 + (rp - rcStart[n])*3 + r;
596875d3a19aSMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
596975d3a19aSMatthew G. Knepley         }
5970add09238SMatthew G. Knepley       } else if ((p >= cMax) && (p < cEnd)) {
597175d3a19aSMatthew G. Knepley         /* Old hybrid cells add new cells and hybrid face */
597275d3a19aSMatthew G. Knepley         for (r = 0; r < 2; ++r, ++m) {
597375d3a19aSMatthew G. Knepley           localPointsNew[m]        = cStartNew     + (p  - cStart)*4     + r;
597475d3a19aSMatthew G. Knepley           remotePointsNew[m].index = rcStartNew[n] + (rp - rcStart[n])*4 + r;
597575d3a19aSMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
597675d3a19aSMatthew G. Knepley         }
597775d3a19aSMatthew G. Knepley         localPointsNew[m]        = fStartNew     + (fMax                              - fStart)*2     + (cMax                            - cStart)*3     + (p  - cMax);
597875d3a19aSMatthew G. Knepley         remotePointsNew[m].index = rfStartNew[n] + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n])*2 + (rdepthMaxOld[n*(depth+1)+depth] - rcStart[n])*3 + (rp - rdepthMaxOld[n*(depth+1)+depth]);
597975d3a19aSMatthew G. Knepley         remotePointsNew[m].rank  = rrank;
598075d3a19aSMatthew G. Knepley         ++m;
598175d3a19aSMatthew G. Knepley       }
598275d3a19aSMatthew G. Knepley       break;
59839b1a0e7fSLawrence Mitchell     case REFINER_HEX_2D:
59849b1a0e7fSLawrence Mitchell     case REFINER_HYBRID_HEX_2D:
5985a97b51b8SMatthew G. Knepley       if ((p >= vStart) && (p < vEnd)) {
5986a97b51b8SMatthew G. Knepley         /* Old vertices stay the same */
5987a97b51b8SMatthew G. Knepley         localPointsNew[m]        = vStartNew     + (p  - vStart);
5988a97b51b8SMatthew G. Knepley         remotePointsNew[m].index = rvStartNew[n] + (rp - rvStart[n]);
5989a97b51b8SMatthew G. Knepley         remotePointsNew[m].rank  = rrank;
5990a97b51b8SMatthew G. Knepley         ++m;
5991a97b51b8SMatthew G. Knepley       } else if ((p >= fStart) && (p < fMax)) {
5992a97b51b8SMatthew G. Knepley         /* Old interior faces add new faces and vertex */
5993a97b51b8SMatthew G. Knepley         for (r = 0; r < 2; ++r, ++m) {
5994a97b51b8SMatthew G. Knepley           localPointsNew[m]        = fStartNew     + (p  - fStart)*2     + r;
5995a97b51b8SMatthew G. Knepley           remotePointsNew[m].index = rfStartNew[n] + (rp - rfStart[n])*2 + r;
5996a97b51b8SMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
5997a97b51b8SMatthew G. Knepley         }
5998add09238SMatthew G. Knepley         localPointsNew[m]        = vStartNew     + (vEnd - vStart)              + (p  - fStart);
5999add09238SMatthew G. Knepley         remotePointsNew[m].index = rvStartNew[n] + rdepthSizeOld[n*(depth+1)+0] + (rp - rfStart[n]);
6000add09238SMatthew G. Knepley         remotePointsNew[m].rank  = rrank;
6001add09238SMatthew G. Knepley         ++m;
6002a97b51b8SMatthew G. Knepley       } else if ((p >= fMax) && (p < fEnd)) {
6003a97b51b8SMatthew G. Knepley         /* Old hybrid faces stay the same */
6004a97b51b8SMatthew G. Knepley         localPointsNew[m]        = fStartNew     + (fMax                              - fStart)*2     + (p  - fMax);
6005a97b51b8SMatthew G. Knepley         remotePointsNew[m].index = rfStartNew[n] + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n])*2 + (rp - rdepthMaxOld[n*(depth+1)+depth-1]);
6006a97b51b8SMatthew G. Knepley         remotePointsNew[m].rank  = rrank;
6007a97b51b8SMatthew G. Knepley         ++m;
6008a97b51b8SMatthew G. Knepley       } else if ((p >= cStart) && (p < cMax)) {
6009a97b51b8SMatthew G. Knepley         /* Old interior cells add new cells, interior faces, and vertex */
6010a97b51b8SMatthew G. Knepley         for (r = 0; r < 4; ++r, ++m) {
6011a97b51b8SMatthew G. Knepley           localPointsNew[m]        = cStartNew     + (p  - cStart)*4     + r;
6012a97b51b8SMatthew G. Knepley           remotePointsNew[m].index = rcStartNew[n] + (rp - rcStart[n])*4 + r;
6013a97b51b8SMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
6014a97b51b8SMatthew G. Knepley         }
6015a97b51b8SMatthew G. Knepley         for (r = 0; r < 4; ++r, ++m) {
6016a97b51b8SMatthew G. Knepley           localPointsNew[m]        = fStartNew     + (fMax                              - fStart)*2     + (p  - cStart)*4     + r;
6017a97b51b8SMatthew G. Knepley           remotePointsNew[m].index = rfStartNew[n] + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n])*2 + (rp - rcStart[n])*4 + r;
6018a97b51b8SMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
6019a97b51b8SMatthew G. Knepley         }
6020add09238SMatthew G. Knepley         localPointsNew[m]        = vStartNew     + (vEnd - vStart)               + (fMax                              - fStart)     + (p  - cStart);
6021add09238SMatthew G. Knepley         remotePointsNew[m].index = rvStartNew[n] + rdepthSizeOld[n*(depth+1)+0]  + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n]) + (rp - rcStart[n]);
6022add09238SMatthew G. Knepley         remotePointsNew[m].rank  = rrank;
6023add09238SMatthew G. Knepley         ++m;
6024a97b51b8SMatthew G. Knepley       } else if ((p >= cStart) && (p < cMax)) {
6025a97b51b8SMatthew G. Knepley         /* Old hybrid cells add new cells and hybrid face */
6026a97b51b8SMatthew G. Knepley         for (r = 0; r < 2; ++r, ++m) {
6027a97b51b8SMatthew G. Knepley           localPointsNew[m]        = cStartNew     + (p  - cStart)*4     + r;
6028a97b51b8SMatthew G. Knepley           remotePointsNew[m].index = rcStartNew[n] + (rp - rcStart[n])*4 + r;
6029a97b51b8SMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
6030a97b51b8SMatthew G. Knepley         }
6031a97b51b8SMatthew G. Knepley         localPointsNew[m]        = fStartNew     + (fMax                              - fStart)*2     + (cMax                            - cStart)*4     + (p  - cMax);
6032a97b51b8SMatthew G. Knepley         remotePointsNew[m].index = rfStartNew[n] + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n])*2 + (rdepthMaxOld[n*(depth+1)+depth] - rcStart[n])*4 + (rp - rdepthMaxOld[n*(depth+1)+depth]);
6033a97b51b8SMatthew G. Knepley         remotePointsNew[m].rank  = rrank;
6034a97b51b8SMatthew G. Knepley         ++m;
6035a97b51b8SMatthew G. Knepley       }
6036a97b51b8SMatthew G. Knepley       break;
60379b1a0e7fSLawrence Mitchell     case REFINER_SIMPLEX_3D:
60389b1a0e7fSLawrence Mitchell     case REFINER_HYBRID_SIMPLEX_3D:
60396ce3c06aSMatthew G. Knepley       if ((p >= vStart) && (p < vEnd)) {
60406ce3c06aSMatthew G. Knepley         /* Interior vertices stay the same */
60416ce3c06aSMatthew G. Knepley         localPointsNew[m]        = vStartNew     + (p  - vStart);
60426ce3c06aSMatthew G. Knepley         remotePointsNew[m].index = rvStartNew[n] + (rp - rvStart[n]);
60436ce3c06aSMatthew G. Knepley         remotePointsNew[m].rank  = rrank;
60446ce3c06aSMatthew G. Knepley         ++m;
60456ce3c06aSMatthew G. Knepley       } else if ((p >= eStart) && (p < eMax)) {
60466ce3c06aSMatthew G. Knepley         /* Interior edges add new edges and vertex */
60476ce3c06aSMatthew G. Knepley         for (r = 0; r < 2; ++r, ++m) {
60486ce3c06aSMatthew G. Knepley           localPointsNew[m]        = eStartNew     + (p  - eStart)*2     + r;
60496ce3c06aSMatthew G. Knepley           remotePointsNew[m].index = reStartNew[n] + (rp - reStart[n])*2 + r;
60506ce3c06aSMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
60516ce3c06aSMatthew G. Knepley         }
60526ce3c06aSMatthew G. Knepley         localPointsNew[m]        = vStartNew     + (vEnd - vStart)              + (p  - eStart);
60536ce3c06aSMatthew G. Knepley         remotePointsNew[m].index = rvStartNew[n] + rdepthSizeOld[n*(depth+1)+0] + (rp - reStart[n]);
60546ce3c06aSMatthew G. Knepley         remotePointsNew[m].rank  = rrank;
60556ce3c06aSMatthew G. Knepley         ++m;
60566ce3c06aSMatthew G. Knepley       } else if ((p >= eMax) && (p < eEnd)) {
60576ce3c06aSMatthew G. Knepley         /* Hybrid edges stay the same */
60586ce3c06aSMatthew G. Knepley         localPointsNew[m]        = eStartNew     + (eMax                        - eStart)*2     + (fMax                              - fStart)*3     + (cMax                            - cStart)     + (p  - eMax);
60597d5cd7d5SMatthew G. Knepley         remotePointsNew[m].index = reStartNew[n] + (rdepthMaxOld[n*(depth+1)+1] - reStart[n])*2 + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n])*3 + (rdepthMaxOld[n*(depth+1)+depth] - rcStart[n]) + (rp - rdepthMaxOld[n*(depth+1)+1]);
60606ce3c06aSMatthew G. Knepley         remotePointsNew[m].rank  = rrank;
60616ce3c06aSMatthew G. Knepley         ++m;
60626ce3c06aSMatthew G. Knepley       } else if ((p >= fStart) && (p < fMax)) {
60636ce3c06aSMatthew G. Knepley         /* Interior faces add new faces and edges */
60646ce3c06aSMatthew G. Knepley         for (r = 0; r < 4; ++r, ++m) {
60656ce3c06aSMatthew G. Knepley           localPointsNew[m]        = fStartNew     + (p  - fStart)*4     + r;
60666ce3c06aSMatthew G. Knepley           remotePointsNew[m].index = rfStartNew[n] + (rp - rfStart[n])*4 + r;
60676ce3c06aSMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
60686ce3c06aSMatthew G. Knepley         }
60696ce3c06aSMatthew G. Knepley         for (r = 0; r < 3; ++r, ++m) {
60706ce3c06aSMatthew G. Knepley           localPointsNew[m]        = eStartNew     + (eMax                        - eStart)*2     + (p  - fStart)*3     + r;
60716ce3c06aSMatthew G. Knepley           remotePointsNew[m].index = reStartNew[n] + (rdepthMaxOld[n*(depth+1)+1] - reStart[n])*2 + (rp - rfStart[n])*3 + r;
60726ce3c06aSMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
60736ce3c06aSMatthew G. Knepley         }
60746ce3c06aSMatthew G. Knepley       } else if ((p >= fMax) && (p < fEnd)) {
60756ce3c06aSMatthew G. Knepley         /* Hybrid faces add new faces and edges */
60766ce3c06aSMatthew G. Knepley         for (r = 0; r < 2; ++r, ++m) {
6077899f98d0SMatthew G. Knepley           localPointsNew[m]        = fStartNew     + (fMax                              - fStart)*4     + (cMax                            - cStart)*8     + (p  - fMax)*2                              + r;
6078899f98d0SMatthew G. Knepley           remotePointsNew[m].index = rfStartNew[n] + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n])*4 + (rdepthMaxOld[n*(depth+1)+depth] - rcStart[n])*8 + (rp - rdepthMaxOld[n*(depth+1)+depth-1])*2 + r;
60796ce3c06aSMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
60806ce3c06aSMatthew G. Knepley         }
60817d5cd7d5SMatthew G. Knepley         localPointsNew[m]        = eStartNew     + (eMax                        - eStart)*2     + (fMax                              - fStart)*3     + (cMax                            - cStart)     + (eEnd                                    - eMax)                        + (p  - fMax);
60827d5cd7d5SMatthew G. Knepley         remotePointsNew[m].index = reStartNew[n] + (rdepthMaxOld[n*(depth+1)+1] - reStart[n])*2 + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n])*3 + (rdepthMaxOld[n*(depth+1)+depth] - rcStart[n]) + (rdepthSizeOld[n*(depth+1)+1]+reStart[n] - rdepthMaxOld[n*(depth+1)+1]) + (rp - rdepthMaxOld[n*(depth+1)+depth-1]);
60836ce3c06aSMatthew G. Knepley         remotePointsNew[m].rank  = rrank;
608409b1338fSMatthew G. Knepley         ++m;
60856ce3c06aSMatthew G. Knepley       } else if ((p >= cStart) && (p < cMax)) {
60866ce3c06aSMatthew G. Knepley         /* Interior cells add new cells, faces, and edges */
60876ce3c06aSMatthew G. Knepley         for (r = 0; r < 8; ++r, ++m) {
60886ce3c06aSMatthew G. Knepley           localPointsNew[m]        = cStartNew     + (p  - cStart)*8     + r;
60896ce3c06aSMatthew G. Knepley           remotePointsNew[m].index = rcStartNew[n] + (rp - rcStart[n])*8 + r;
60906ce3c06aSMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
60916ce3c06aSMatthew G. Knepley         }
60926ce3c06aSMatthew G. Knepley         for (r = 0; r < 8; ++r, ++m) {
60936ce3c06aSMatthew G. Knepley           localPointsNew[m]        = fStartNew     + (fMax                              - fStart)*4     + (p  - cStart)*8     + r;
60946ce3c06aSMatthew G. Knepley           remotePointsNew[m].index = rfStartNew[n] + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n])*4 + (rp - rcStart[n])*8 + r;
60956ce3c06aSMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
60966ce3c06aSMatthew G. Knepley         }
6097c7c54c77SMatthew G. Knepley         localPointsNew[m]        = eStartNew     + (eMax                        - eStart)*2     + (fMax                              - fStart)*3     + (p  - cStart)*1     + 0;
6098c7c54c77SMatthew G. Knepley         remotePointsNew[m].index = reStartNew[n] + (rdepthMaxOld[n*(depth+1)+1] - reStart[n])*2 + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n])*3 + (rp - rcStart[n])*1 + 0;
60996ce3c06aSMatthew G. Knepley         remotePointsNew[m].rank  = rrank;
610009b1338fSMatthew G. Knepley         ++m;
61016ce3c06aSMatthew G. Knepley       } else if ((p >= cMax) && (p < cEnd)) {
61026ce3c06aSMatthew G. Knepley         /* Hybrid cells add new cells and faces */
61036ce3c06aSMatthew G. Knepley         for (r = 0; r < 4; ++r, ++m) {
61046ce3c06aSMatthew G. Knepley           localPointsNew[m]        = cStartNew     + (cMax                            - cStart)*8     + (p  - cMax)*4                            + r;
61056ce3c06aSMatthew G. Knepley           remotePointsNew[m].index = rcStartNew[n] + (rdepthMaxOld[n*(depth+1)+depth] - rcStart[n])*8 + (rp - rdepthMaxOld[n*(depth+1)+depth])*4 + r;
61066ce3c06aSMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
61076ce3c06aSMatthew G. Knepley         }
61086ce3c06aSMatthew G. Knepley         for (r = 0; r < 3; ++r, ++m) {
6109899f98d0SMatthew G. Knepley           localPointsNew[m]        = fStartNew     + (fMax                              - fStart)*4     + (cMax                            - cStart)*8     + (fEnd                                          - fMax)*2                              + (p  - cMax)*3                            + r;
6110899f98d0SMatthew G. Knepley           remotePointsNew[m].index = rfStartNew[n] + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n])*4 + (rdepthMaxOld[n*(depth+1)+depth] - rcStart[n])*8 + (rdepthSizeOld[n*(depth+1)+depth-1]+rfStart[n] - rdepthMaxOld[n*(depth+1)+depth-1])*2 + (rp - rdepthMaxOld[n*(depth+1)+depth])*3 + r;
61116ce3c06aSMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
61126ce3c06aSMatthew G. Knepley         }
61136ce3c06aSMatthew G. Knepley       }
61146ce3c06aSMatthew G. Knepley       break;
61159b1a0e7fSLawrence Mitchell     case REFINER_HEX_3D:
61169b1a0e7fSLawrence Mitchell     case REFINER_HYBRID_HEX_3D:
611727fcede3SMatthew G. Knepley       if ((p >= vStart) && (p < vEnd)) {
611827fcede3SMatthew G. Knepley         /* Interior vertices stay the same */
611927fcede3SMatthew G. Knepley         localPointsNew[m]        = vStartNew     + (p  - vStart);
612027fcede3SMatthew G. Knepley         remotePointsNew[m].index = rvStartNew[n] + (rp - rvStart[n]);
612127fcede3SMatthew G. Knepley         remotePointsNew[m].rank  = rrank;
612227fcede3SMatthew G. Knepley         ++m;
612327fcede3SMatthew G. Knepley       } else if ((p >= eStart) && (p < eMax)) {
612427fcede3SMatthew G. Knepley         /* Interior edges add new edges and vertex */
612527fcede3SMatthew G. Knepley         for (r = 0; r < 2; ++r, ++m) {
612627fcede3SMatthew G. Knepley           localPointsNew[m]        = eStartNew     + (p  - eStart)*2     + r;
612727fcede3SMatthew G. Knepley           remotePointsNew[m].index = reStartNew[n] + (rp - reStart[n])*2 + r;
612827fcede3SMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
612927fcede3SMatthew G. Knepley         }
613027fcede3SMatthew G. Knepley         localPointsNew[m]        = vStartNew     + (vEnd - vStart)              + (p  - eStart);
613127fcede3SMatthew G. Knepley         remotePointsNew[m].index = rvStartNew[n] + rdepthSizeOld[n*(depth+1)+0] + (rp - reStart[n]);
613227fcede3SMatthew G. Knepley         remotePointsNew[m].rank  = rrank;
613327fcede3SMatthew G. Knepley         ++m;
613427fcede3SMatthew G. Knepley       } else if ((p >= eMax) && (p < eEnd)) {
613527fcede3SMatthew G. Knepley         /* Hybrid edges stay the same */
613627fcede3SMatthew G. Knepley         localPointsNew[m]        = eStartNew     + (eMax                        - eStart)*2     + (fMax                              - fStart)*4     + (cMax                            - cStart)*6     + (p  - eMax);
6137d2701f60SMatthew G. Knepley         remotePointsNew[m].index = reStartNew[n] + (rdepthMaxOld[n*(depth+1)+1] - reStart[n])*2 + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n])*4 + (rdepthMaxOld[n*(depth+1)+depth] - rcStart[n])*6 + (rp - rdepthMaxOld[n*(depth+1)+1]);
613827fcede3SMatthew G. Knepley         remotePointsNew[m].rank  = rrank;
613927fcede3SMatthew G. Knepley         ++m;
614027fcede3SMatthew G. Knepley       } else if ((p >= fStart) && (p < fMax)) {
614127fcede3SMatthew G. Knepley         /* Interior faces add new faces, edges, and vertex */
614227fcede3SMatthew G. Knepley         for (r = 0; r < 4; ++r, ++m) {
614327fcede3SMatthew G. Knepley           localPointsNew[m]        = fStartNew     + (p  - fStart)*4     + r;
614427fcede3SMatthew G. Knepley           remotePointsNew[m].index = rfStartNew[n] + (rp - rfStart[n])*4 + r;
614527fcede3SMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
614627fcede3SMatthew G. Knepley         }
614727fcede3SMatthew G. Knepley         for (r = 0; r < 4; ++r, ++m) {
614827fcede3SMatthew G. Knepley           localPointsNew[m]        = eStartNew     + (eMax                        - eStart)*2     + (p  - fStart)*4     + r;
614927fcede3SMatthew G. Knepley           remotePointsNew[m].index = reStartNew[n] + (rdepthMaxOld[n*(depth+1)+1] - reStart[n])*2 + (rp - rfStart[n])*4 + r;
615027fcede3SMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
615127fcede3SMatthew G. Knepley         }
615227fcede3SMatthew G. Knepley         localPointsNew[m]        = vStartNew     + (vEnd - vStart)              + (eMax                        - eStart)     + (p  - fStart);
615327fcede3SMatthew G. Knepley         remotePointsNew[m].index = rvStartNew[n] + rdepthSizeOld[n*(depth+1)+0] + (rdepthMaxOld[n*(depth+1)+1] - reStart[n]) + (rp - rfStart[n]);
615427fcede3SMatthew G. Knepley         remotePointsNew[m].rank  = rrank;
615527fcede3SMatthew G. Knepley         ++m;
615627fcede3SMatthew G. Knepley       } else if ((p >= fMax) && (p < fEnd)) {
615727fcede3SMatthew G. Knepley         /* Hybrid faces add new faces and edges */
615827fcede3SMatthew G. Knepley         for (r = 0; r < 2; ++r, ++m) {
6159d2701f60SMatthew G. Knepley           localPointsNew[m]        = fStartNew     + (fMax                              - fStart)*4     + (cMax                            - cStart)*12     + (p  - fMax)*2                              + r;
6160d2701f60SMatthew G. Knepley           remotePointsNew[m].index = rfStartNew[n] + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n])*4 + (rdepthMaxOld[n*(depth+1)+depth] - rcStart[n])*12 + (rp - rdepthMaxOld[n*(depth+1)+depth-1])*2 + r;
616127fcede3SMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
616227fcede3SMatthew G. Knepley         }
6163d2701f60SMatthew G. Knepley         localPointsNew[m]        = eStartNew     + (eMax                        - eStart)*2     + (fMax                              - fStart)*4     + (cMax                            - cStart)*6     + (eEnd                                    - eMax)                        + (p  - fMax);
6164d2701f60SMatthew G. Knepley         remotePointsNew[m].index = reStartNew[n] + (rdepthMaxOld[n*(depth+1)+1] - reStart[n])*2 + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n])*4 + (rdepthMaxOld[n*(depth+1)+depth] - rcStart[n])*6 + (rdepthSizeOld[n*(depth+1)+1]+reStart[n] - rdepthMaxOld[n*(depth+1)+1]) + (rp - rdepthMaxOld[n*(depth+1)+depth-1]);
616527fcede3SMatthew G. Knepley         remotePointsNew[m].rank  = rrank;
616627fcede3SMatthew G. Knepley         ++m;
616727fcede3SMatthew G. Knepley       } else if ((p >= cStart) && (p < cMax)) {
616827fcede3SMatthew G. Knepley         /* Interior cells add new cells, faces, edges, and vertex */
616927fcede3SMatthew G. Knepley         for (r = 0; r < 8; ++r, ++m) {
617027fcede3SMatthew G. Knepley           localPointsNew[m]        = cStartNew     + (p  - cStart)*8     + r;
617127fcede3SMatthew G. Knepley           remotePointsNew[m].index = rcStartNew[n] + (rp - rcStart[n])*8 + r;
617227fcede3SMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
617327fcede3SMatthew G. Knepley         }
617427fcede3SMatthew G. Knepley         for (r = 0; r < 12; ++r, ++m) {
617527fcede3SMatthew G. Knepley           localPointsNew[m]        = fStartNew     + (fMax                              - fStart)*4     + (p  - cStart)*12     + r;
617627fcede3SMatthew G. Knepley           remotePointsNew[m].index = rfStartNew[n] + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n])*4 + (rp - rcStart[n])*12 + r;
617727fcede3SMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
617827fcede3SMatthew G. Knepley         }
617927fcede3SMatthew G. Knepley         for (r = 0; r < 6; ++r, ++m) {
618027fcede3SMatthew G. Knepley           localPointsNew[m]        = eStartNew     + (eMax                        - eStart)*2     + (fMax                              - fStart)*4     + (p  - cStart)*6     + r;
618127fcede3SMatthew G. Knepley           remotePointsNew[m].index = reStartNew[n] + (rdepthMaxOld[n*(depth+1)+1] - reStart[n])*2 + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n])*4 + (rp - rcStart[n])*6 + r;
618227fcede3SMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
618327fcede3SMatthew G. Knepley         }
618427fcede3SMatthew G. Knepley         for (r = 0; r < 1; ++r, ++m) {
618527fcede3SMatthew G. Knepley           localPointsNew[m]        = vStartNew     + (eMax                        - eStart)     + (fMax                              - fStart)     + (p  - cStart)     + r;
618627fcede3SMatthew G. Knepley           remotePointsNew[m].index = rvStartNew[n] + (rdepthMaxOld[n*(depth+1)+1] - reStart[n]) + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n]) + (rp - rcStart[n]) + r;
618727fcede3SMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
618827fcede3SMatthew G. Knepley         }
618927fcede3SMatthew G. Knepley       } else if ((p >= cMax) && (p < cEnd)) {
619027fcede3SMatthew G. Knepley         /* Hybrid cells add new cells, faces, and edges */
619127fcede3SMatthew G. Knepley         for (r = 0; r < 4; ++r, ++m) {
619227fcede3SMatthew G. Knepley           localPointsNew[m]        = cStartNew     + (cMax                            - cStart)*8     + (p  - cMax)*4                            + r;
619327fcede3SMatthew G. Knepley           remotePointsNew[m].index = rcStartNew[n] + (rdepthMaxOld[n*(depth+1)+depth] - rcStart[n])*8 + (rp - rdepthMaxOld[n*(depth+1)+depth])*4 + r;
619427fcede3SMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
619527fcede3SMatthew G. Knepley         }
619627fcede3SMatthew G. Knepley         for (r = 0; r < 4; ++r, ++m) {
6197d2701f60SMatthew G. Knepley           localPointsNew[m]        = fStartNew     + (fMax                              - fStart)*4     + (cMax                            - cStart)*12     + (fEnd                                          - fMax)*2                              + (p  - cMax)*4                            + r;
6198d2701f60SMatthew G. Knepley           remotePointsNew[m].index = rfStartNew[n] + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n])*4 + (rdepthMaxOld[n*(depth+1)+depth] - rcStart[n])*12 + (rdepthSizeOld[n*(depth+1)+depth-1]+rfStart[n] - rdepthMaxOld[n*(depth+1)+depth-1])*2 + (rp - rdepthMaxOld[n*(depth+1)+depth])*4 + r;
619927fcede3SMatthew G. Knepley           remotePointsNew[m].rank  = rrank;
620027fcede3SMatthew G. Knepley         }
6201d2701f60SMatthew G. Knepley         localPointsNew[m]        = eStartNew     + (eMax                        - eStart)*2     + (fMax                              - fStart)*4     + (cMax                            - cStart)*6     + (eEnd                                    - eMax)                        + (fEnd                                          - fMax)                              + (p  - cMax);
6202d2701f60SMatthew G. Knepley         remotePointsNew[m].index = reStartNew[n] + (rdepthMaxOld[n*(depth+1)+1] - reStart[n])*2 + (rdepthMaxOld[n*(depth+1)+depth-1] - rfStart[n])*4 + (rdepthMaxOld[n*(depth+1)+depth] - rcStart[n])*6 + (rdepthSizeOld[n*(depth+1)+1]+reStart[n] - rdepthMaxOld[n*(depth+1)+1]) + (rdepthSizeOld[n*(depth+1)+depth-1]+rfStart[n] - rdepthMaxOld[n*(depth+1)+depth-1]) + (rp - rdepthMaxOld[n*(depth+1)+depth]);
620327fcede3SMatthew G. Knepley         remotePointsNew[m].rank  = rrank;
620427fcede3SMatthew G. Knepley         ++m;
620527fcede3SMatthew G. Knepley       }
620627fcede3SMatthew G. Knepley       break;
620775d3a19aSMatthew G. Knepley     default:
620875d3a19aSMatthew G. Knepley       SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Unknown cell refiner %d", refiner);
620975d3a19aSMatthew G. Knepley     }
621075d3a19aSMatthew G. Knepley   }
621109b1338fSMatthew G. Knepley   if (m != numLeavesNew) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Number of leaf point %d should be %d", m, numLeavesNew);
621275d3a19aSMatthew G. Knepley   ierr = ISRestoreIndices(processRanks, &neighbors);CHKERRQ(ierr);
621375d3a19aSMatthew G. Knepley   ierr = ISDestroy(&processRanks);CHKERRQ(ierr);
6214ba3c3d50SMatthew G. Knepley   {
6215ba3c3d50SMatthew G. Knepley     PetscSFNode *rp, *rtmp;
6216ba3c3d50SMatthew G. Knepley     PetscInt    *lp, *idx, *ltmp, i;
6217ba3c3d50SMatthew G. Knepley 
6218ba3c3d50SMatthew G. Knepley     /* SF needs sorted leaves to correct calculate Gather */
6219ba3c3d50SMatthew G. Knepley     ierr = PetscMalloc1(numLeavesNew,&idx);CHKERRQ(ierr);
6220ba3c3d50SMatthew G. Knepley     ierr = PetscMalloc1(numLeavesNew, &lp);CHKERRQ(ierr);
6221ba3c3d50SMatthew G. Knepley     ierr = PetscMalloc1(numLeavesNew, &rp);CHKERRQ(ierr);
6222c7c54c77SMatthew G. Knepley     for (i = 0; i < numLeavesNew; ++i) {
6223c7c54c77SMatthew G. Knepley       if ((localPointsNew[i] < pStartNew) || (localPointsNew[i] >= pEndNew)) SETERRQ4(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Local SF point %d (%d) not in [%d, %d)", localPointsNew[i], i, pStartNew, pEndNew);
6224c7c54c77SMatthew G. Knepley       idx[i] = i;
6225c7c54c77SMatthew G. Knepley     }
6226ba3c3d50SMatthew G. Knepley     ierr = PetscSortIntWithPermutation(numLeavesNew, localPointsNew, idx);CHKERRQ(ierr);
6227ba3c3d50SMatthew G. Knepley     for (i = 0; i < numLeavesNew; ++i) {
6228ba3c3d50SMatthew G. Knepley       lp[i] = localPointsNew[idx[i]];
6229ba3c3d50SMatthew G. Knepley       rp[i] = remotePointsNew[idx[i]];
6230ba3c3d50SMatthew G. Knepley     }
6231ba3c3d50SMatthew G. Knepley     ltmp            = localPointsNew;
6232ba3c3d50SMatthew G. Knepley     localPointsNew  = lp;
6233ba3c3d50SMatthew G. Knepley     rtmp            = remotePointsNew;
6234ba3c3d50SMatthew G. Knepley     remotePointsNew = rp;
6235ba3c3d50SMatthew G. Knepley     ierr = PetscFree(idx);CHKERRQ(ierr);
6236ba3c3d50SMatthew G. Knepley     ierr = PetscFree(ltmp);CHKERRQ(ierr);
6237ba3c3d50SMatthew G. Knepley     ierr = PetscFree(rtmp);CHKERRQ(ierr);
6238ba3c3d50SMatthew G. Knepley   }
623975d3a19aSMatthew G. Knepley   ierr = PetscSFSetGraph(sfNew, pEndNew-pStartNew, numLeavesNew, localPointsNew, PETSC_OWN_POINTER, remotePointsNew, PETSC_OWN_POINTER);CHKERRQ(ierr);
624075d3a19aSMatthew G. Knepley   ierr = PetscFree5(rdepthSize,rvStartNew,reStartNew,rfStartNew,rcStartNew);CHKERRQ(ierr);
624106a0ba2dSMatthew G. Knepley   ierr = PetscFree7(depthSizeOld,rdepthSizeOld,rdepthMaxOld,rvStart,reStart,rfStart,rcStart);CHKERRQ(ierr);
624275d3a19aSMatthew G. Knepley   PetscFunctionReturn(0);
624375d3a19aSMatthew G. Knepley }
624475d3a19aSMatthew G. Knepley 
624575d3a19aSMatthew G. Knepley #undef __FUNCT__
624675d3a19aSMatthew G. Knepley #define __FUNCT__ "CellRefinerCreateLabels"
624786150812SJed Brown static PetscErrorCode CellRefinerCreateLabels(CellRefiner refiner, DM dm, PetscInt depthSize[], DM rdm)
624875d3a19aSMatthew G. Knepley {
624975d3a19aSMatthew G. Knepley   PetscInt       numLabels, l;
62507ba685a0SMatthew G. Knepley   PetscInt       depth, newp, cStart, cEnd, cMax, vStart, vEnd, vMax, fStart, fEnd, fMax, eStart, eEnd, eMax, r;
62517ba685a0SMatthew G. Knepley   PetscInt       cStartNew = 0, vStartNew = 0, fStartNew = 0, eStartNew = 0;
625275d3a19aSMatthew G. Knepley   PetscErrorCode ierr;
625375d3a19aSMatthew G. Knepley 
625475d3a19aSMatthew G. Knepley   PetscFunctionBegin;
625575d3a19aSMatthew G. Knepley   ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr);
625675d3a19aSMatthew G. Knepley   ierr = DMPlexGetDepthStratum(dm, 1, &eStart, &eEnd);CHKERRQ(ierr);
625775d3a19aSMatthew G. Knepley   ierr = DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd);CHKERRQ(ierr);
625875d3a19aSMatthew G. Knepley   ierr = DMPlexGetHeightStratum(dm, 1, &fStart, &fEnd);CHKERRQ(ierr);
6259d963de37SMatthew G. Knepley   ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr);
62603478d7aaSMatthew G. Knepley   if (refiner) {ierr = GetDepthStart_Private(depth, depthSize, &cStartNew, &fStartNew, &eStartNew, &vStartNew);CHKERRQ(ierr);}
626175d3a19aSMatthew G. Knepley   ierr = DMPlexGetNumLabels(dm, &numLabels);CHKERRQ(ierr);
626275d3a19aSMatthew G. Knepley   ierr = DMPlexGetHybridBounds(dm, &cMax, &fMax, &eMax, &vMax);CHKERRQ(ierr);
626375d3a19aSMatthew G. Knepley   switch (refiner) {
62649b1a0e7fSLawrence Mitchell   case REFINER_NOOP:
62650314a74cSLawrence Mitchell   case REFINER_SIMPLEX_1D:
62669b1a0e7fSLawrence Mitchell   case REFINER_SIMPLEX_2D:
62679b1a0e7fSLawrence Mitchell   case REFINER_HEX_2D:
62689b1a0e7fSLawrence Mitchell   case REFINER_SIMPLEX_3D:
62699b1a0e7fSLawrence Mitchell   case REFINER_HEX_3D:
62709b1a0e7fSLawrence Mitchell     break;
62719b1a0e7fSLawrence Mitchell   case REFINER_HYBRID_SIMPLEX_3D:
62729b1a0e7fSLawrence Mitchell   case REFINER_HYBRID_HEX_3D:
627358b8852aSMatthew G. Knepley     if (eMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No edge maximum specified in hybrid mesh");
62749b1a0e7fSLawrence Mitchell   case REFINER_HYBRID_SIMPLEX_2D:
62759b1a0e7fSLawrence Mitchell   case REFINER_HYBRID_HEX_2D:
627675d3a19aSMatthew G. Knepley     if (cMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No cell maximum specified in hybrid mesh");
627775d3a19aSMatthew G. Knepley     if (fMax < 0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No face maximum specified in hybrid mesh");
62781e317b1dSMatthew G. Knepley     break;
62799b1a0e7fSLawrence Mitchell   default:
62809b1a0e7fSLawrence Mitchell     SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Unknown cell refiner %d", refiner);
628175d3a19aSMatthew G. Knepley   }
628275d3a19aSMatthew G. Knepley   for (l = 0; l < numLabels; ++l) {
628375d3a19aSMatthew G. Knepley     DMLabel         label, labelNew;
628475d3a19aSMatthew G. Knepley     const char     *lname;
628575d3a19aSMatthew G. Knepley     PetscBool       isDepth;
628675d3a19aSMatthew G. Knepley     IS              valueIS;
628775d3a19aSMatthew G. Knepley     const PetscInt *values;
628875d3a19aSMatthew G. Knepley     PetscInt        numValues, val;
628975d3a19aSMatthew G. Knepley 
629075d3a19aSMatthew G. Knepley     ierr = DMPlexGetLabelName(dm, l, &lname);CHKERRQ(ierr);
629175d3a19aSMatthew G. Knepley     ierr = PetscStrcmp(lname, "depth", &isDepth);CHKERRQ(ierr);
629275d3a19aSMatthew G. Knepley     if (isDepth) continue;
629375d3a19aSMatthew G. Knepley     ierr = DMPlexCreateLabel(rdm, lname);CHKERRQ(ierr);
629475d3a19aSMatthew G. Knepley     ierr = DMPlexGetLabel(dm, lname, &label);CHKERRQ(ierr);
629575d3a19aSMatthew G. Knepley     ierr = DMPlexGetLabel(rdm, lname, &labelNew);CHKERRQ(ierr);
629675d3a19aSMatthew G. Knepley     ierr = DMLabelGetValueIS(label, &valueIS);CHKERRQ(ierr);
629775d3a19aSMatthew G. Knepley     ierr = ISGetLocalSize(valueIS, &numValues);CHKERRQ(ierr);
629875d3a19aSMatthew G. Knepley     ierr = ISGetIndices(valueIS, &values);CHKERRQ(ierr);
629975d3a19aSMatthew G. Knepley     for (val = 0; val < numValues; ++val) {
630075d3a19aSMatthew G. Knepley       IS              pointIS;
630175d3a19aSMatthew G. Knepley       const PetscInt *points;
630275d3a19aSMatthew G. Knepley       PetscInt        numPoints, n;
630375d3a19aSMatthew G. Knepley 
630475d3a19aSMatthew G. Knepley       ierr = DMLabelGetStratumIS(label, values[val], &pointIS);CHKERRQ(ierr);
630575d3a19aSMatthew G. Knepley       ierr = ISGetLocalSize(pointIS, &numPoints);CHKERRQ(ierr);
630675d3a19aSMatthew G. Knepley       ierr = ISGetIndices(pointIS, &points);CHKERRQ(ierr);
63072bc5314cSMichael Lange       /* Ensure refined label is created with same number of strata as
63082bc5314cSMichael Lange        * original (even if no entries here). */
63092bc5314cSMichael Lange       if (!numPoints) {
63102bc5314cSMichael Lange         ierr = DMLabelSetValue(labelNew, 0, values[val]);CHKERRQ(ierr);
63112bc5314cSMichael Lange         ierr = DMLabelClearValue(labelNew, 0, values[val]);CHKERRQ(ierr);
63122bc5314cSMichael Lange       }
631375d3a19aSMatthew G. Knepley       for (n = 0; n < numPoints; ++n) {
631475d3a19aSMatthew G. Knepley         const PetscInt p = points[n];
631575d3a19aSMatthew G. Knepley         switch (refiner) {
63160314a74cSLawrence Mitchell         case REFINER_SIMPLEX_1D:
63170314a74cSLawrence Mitchell           if ((p >= vStart) && (p < vEnd)) {
63180314a74cSLawrence Mitchell             /* Old vertices stay the same */
63190314a74cSLawrence Mitchell             newp = vStartNew + (p - vStart);
63200314a74cSLawrence Mitchell             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
63210314a74cSLawrence Mitchell           } else if ((p >= cStart) && (p < cEnd)) {
63220314a74cSLawrence Mitchell             /* Old cells add new cells and vertex */
63230314a74cSLawrence Mitchell             newp = vStartNew + (vEnd - vStart) + (p - cStart);
63240314a74cSLawrence Mitchell             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
63250314a74cSLawrence Mitchell             for (r = 0; r < 2; ++r) {
63260314a74cSLawrence Mitchell               newp = cStartNew + (p - cStart)*2 + r;
63270314a74cSLawrence Mitchell               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
63280314a74cSLawrence Mitchell             }
63290314a74cSLawrence Mitchell           }
63300314a74cSLawrence Mitchell           break;
63319b1a0e7fSLawrence Mitchell         case REFINER_SIMPLEX_2D:
633275d3a19aSMatthew G. Knepley           if ((p >= vStart) && (p < vEnd)) {
633375d3a19aSMatthew G. Knepley             /* Old vertices stay the same */
633475d3a19aSMatthew G. Knepley             newp = vStartNew + (p - vStart);
633575d3a19aSMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
633675d3a19aSMatthew G. Knepley           } else if ((p >= fStart) && (p < fEnd)) {
633775d3a19aSMatthew G. Knepley             /* Old faces add new faces and vertex */
633875d3a19aSMatthew G. Knepley             newp = vStartNew + (vEnd - vStart) + (p - fStart);
633975d3a19aSMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
634075d3a19aSMatthew G. Knepley             for (r = 0; r < 2; ++r) {
634175d3a19aSMatthew G. Knepley               newp = fStartNew + (p - fStart)*2 + r;
634275d3a19aSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
634375d3a19aSMatthew G. Knepley             }
634475d3a19aSMatthew G. Knepley           } else if ((p >= cStart) && (p < cEnd)) {
634575d3a19aSMatthew G. Knepley             /* Old cells add new cells and interior faces */
634675d3a19aSMatthew G. Knepley             for (r = 0; r < 4; ++r) {
634775d3a19aSMatthew G. Knepley               newp = cStartNew + (p - cStart)*4 + r;
634875d3a19aSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
634975d3a19aSMatthew G. Knepley             }
635075d3a19aSMatthew G. Knepley             for (r = 0; r < 3; ++r) {
635175d3a19aSMatthew G. Knepley               newp = fStartNew + (fEnd - fStart)*2 + (p - cStart)*3 + r;
635275d3a19aSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
635375d3a19aSMatthew G. Knepley             }
635475d3a19aSMatthew G. Knepley           }
635575d3a19aSMatthew G. Knepley           break;
63569b1a0e7fSLawrence Mitchell         case REFINER_HEX_2D:
635775d3a19aSMatthew G. Knepley           if ((p >= vStart) && (p < vEnd)) {
635875d3a19aSMatthew G. Knepley             /* Old vertices stay the same */
635975d3a19aSMatthew G. Knepley             newp = vStartNew + (p - vStart);
636075d3a19aSMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
636175d3a19aSMatthew G. Knepley           } else if ((p >= fStart) && (p < fEnd)) {
636275d3a19aSMatthew G. Knepley             /* Old faces add new faces and vertex */
636375d3a19aSMatthew G. Knepley             newp = vStartNew + (vEnd - vStart) + (p - fStart);
636475d3a19aSMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
636575d3a19aSMatthew G. Knepley             for (r = 0; r < 2; ++r) {
636675d3a19aSMatthew G. Knepley               newp = fStartNew + (p - fStart)*2 + r;
636775d3a19aSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
636875d3a19aSMatthew G. Knepley             }
636975d3a19aSMatthew G. Knepley           } else if ((p >= cStart) && (p < cEnd)) {
637075d3a19aSMatthew G. Knepley             /* Old cells add new cells and interior faces and vertex */
637175d3a19aSMatthew G. Knepley             for (r = 0; r < 4; ++r) {
637275d3a19aSMatthew G. Knepley               newp = cStartNew + (p - cStart)*4 + r;
637375d3a19aSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
637475d3a19aSMatthew G. Knepley             }
637575d3a19aSMatthew G. Knepley             for (r = 0; r < 4; ++r) {
637675d3a19aSMatthew G. Knepley               newp = fStartNew + (fEnd - fStart)*2 + (p - cStart)*4 + r;
637775d3a19aSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
637875d3a19aSMatthew G. Knepley             }
637975d3a19aSMatthew G. Knepley             newp = vStartNew + (vEnd - vStart) + (fEnd - fStart) + (p - cStart);
638075d3a19aSMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
638175d3a19aSMatthew G. Knepley           }
638275d3a19aSMatthew G. Knepley           break;
63839b1a0e7fSLawrence Mitchell         case REFINER_HYBRID_SIMPLEX_2D:
638475d3a19aSMatthew G. Knepley           if ((p >= vStart) && (p < vEnd)) {
638575d3a19aSMatthew G. Knepley             /* Old vertices stay the same */
638675d3a19aSMatthew G. Knepley             newp = vStartNew + (p - vStart);
638775d3a19aSMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
638875d3a19aSMatthew G. Knepley           } else if ((p >= fStart) && (p < fMax)) {
638975d3a19aSMatthew G. Knepley             /* Old interior faces add new faces and vertex */
639075d3a19aSMatthew G. Knepley             newp = vStartNew + (vEnd - vStart) + (p - fStart);
639175d3a19aSMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
639275d3a19aSMatthew G. Knepley             for (r = 0; r < 2; ++r) {
639375d3a19aSMatthew G. Knepley               newp = fStartNew + (p - fStart)*2 + r;
639475d3a19aSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
639575d3a19aSMatthew G. Knepley             }
639675d3a19aSMatthew G. Knepley           } else if ((p >= fMax) && (p < fEnd)) {
639775d3a19aSMatthew G. Knepley             /* Old hybrid faces stay the same */
639875d3a19aSMatthew G. Knepley             newp = fStartNew + (fMax - fStart)*2 + (p - fMax);
639975d3a19aSMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
640075d3a19aSMatthew G. Knepley           } else if ((p >= cStart) && (p < cMax)) {
640175d3a19aSMatthew G. Knepley             /* Old interior cells add new cells and interior faces */
640275d3a19aSMatthew G. Knepley             for (r = 0; r < 4; ++r) {
640375d3a19aSMatthew G. Knepley               newp = cStartNew + (p - cStart)*4 + r;
640475d3a19aSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
640575d3a19aSMatthew G. Knepley             }
640675d3a19aSMatthew G. Knepley             for (r = 0; r < 3; ++r) {
640775d3a19aSMatthew G. Knepley               newp = fStartNew + (fEnd - fStart)*2 + (p - cStart)*3 + r;
640875d3a19aSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
640975d3a19aSMatthew G. Knepley             }
641075d3a19aSMatthew G. Knepley           } else if ((p >= cMax) && (p < cEnd)) {
641175d3a19aSMatthew G. Knepley             /* Old hybrid cells add new cells and hybrid face */
641275d3a19aSMatthew G. Knepley             for (r = 0; r < 2; ++r) {
641375d3a19aSMatthew G. Knepley               newp = cStartNew + (cMax - cStart)*4 + (p - cMax)*2 + r;
641475d3a19aSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
641575d3a19aSMatthew G. Knepley             }
641675d3a19aSMatthew G. Knepley             newp = fStartNew + (fMax - fStart)*2 + (cMax - cStart)*3 + (p - cMax);
641775d3a19aSMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
641875d3a19aSMatthew G. Knepley           }
641975d3a19aSMatthew G. Knepley           break;
64209b1a0e7fSLawrence Mitchell         case REFINER_HYBRID_HEX_2D:
6421a97b51b8SMatthew G. Knepley           if ((p >= vStart) && (p < vEnd)) {
6422a97b51b8SMatthew G. Knepley             /* Old vertices stay the same */
6423a97b51b8SMatthew G. Knepley             newp = vStartNew + (p - vStart);
6424a97b51b8SMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
6425a97b51b8SMatthew G. Knepley           } else if ((p >= fStart) && (p < fMax)) {
6426a97b51b8SMatthew G. Knepley             /* Old interior faces add new faces and vertex */
6427a97b51b8SMatthew G. Knepley             newp = vStartNew + (vEnd - vStart) + (p - fStart);
6428a97b51b8SMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
6429a97b51b8SMatthew G. Knepley             for (r = 0; r < 2; ++r) {
6430a97b51b8SMatthew G. Knepley               newp = fStartNew + (p - fStart)*2 + r;
6431a97b51b8SMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
6432a97b51b8SMatthew G. Knepley             }
6433a97b51b8SMatthew G. Knepley           } else if ((p >= fMax) && (p < fEnd)) {
6434a97b51b8SMatthew G. Knepley             /* Old hybrid faces stay the same */
6435a97b51b8SMatthew G. Knepley             newp = fStartNew + (fMax - fStart)*2 + (p - fMax);
6436a97b51b8SMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
6437a97b51b8SMatthew G. Knepley           } else if ((p >= cStart) && (p < cMax)) {
6438a97b51b8SMatthew G. Knepley             /* Old interior cells add new cells, interior faces, and vertex */
6439a97b51b8SMatthew G. Knepley             for (r = 0; r < 4; ++r) {
6440a97b51b8SMatthew G. Knepley               newp = cStartNew + (p - cStart)*4 + r;
6441a97b51b8SMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
6442a97b51b8SMatthew G. Knepley             }
6443a97b51b8SMatthew G. Knepley             for (r = 0; r < 4; ++r) {
6444a97b51b8SMatthew G. Knepley               newp = fStartNew + (fEnd - fStart)*2 + (p - cStart)*4 + r;
6445a97b51b8SMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
6446a97b51b8SMatthew G. Knepley             }
6447a97b51b8SMatthew G. Knepley             newp = vStartNew + (vEnd - vStart) + (fEnd - fStart) + (p - cStart);
6448a97b51b8SMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
6449a97b51b8SMatthew G. Knepley           } else if ((p >= cMax) && (p < cEnd)) {
6450a97b51b8SMatthew G. Knepley             /* Old hybrid cells add new cells and hybrid face */
6451a97b51b8SMatthew G. Knepley             for (r = 0; r < 2; ++r) {
6452a97b51b8SMatthew G. Knepley               newp = cStartNew + (cMax - cStart)*4 + (p - cMax)*2 + r;
6453a97b51b8SMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
6454a97b51b8SMatthew G. Knepley             }
6455a97b51b8SMatthew G. Knepley             newp = fStartNew + (fMax - fStart)*2 + (cMax - cStart)*4 + (p - cMax);
6456a97b51b8SMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
6457a97b51b8SMatthew G. Knepley           }
6458a97b51b8SMatthew G. Knepley           break;
64599b1a0e7fSLawrence Mitchell         case REFINER_SIMPLEX_3D:
6460b5da9499SMatthew G. Knepley           if ((p >= vStart) && (p < vEnd)) {
6461b5da9499SMatthew G. Knepley             /* Old vertices stay the same */
6462b5da9499SMatthew G. Knepley             newp = vStartNew + (p - vStart);
6463b5da9499SMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
6464b5da9499SMatthew G. Knepley           } else if ((p >= eStart) && (p < eEnd)) {
6465b5da9499SMatthew G. Knepley             /* Old edges add new edges and vertex */
6466b5da9499SMatthew G. Knepley             for (r = 0; r < 2; ++r) {
6467b5da9499SMatthew G. Knepley               newp = eStartNew + (p - eStart)*2 + r;
6468b5da9499SMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
6469b5da9499SMatthew G. Knepley             }
6470b5da9499SMatthew G. Knepley             newp = vStartNew + (vEnd - vStart) + (p - eStart);
6471b5da9499SMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
6472b5da9499SMatthew G. Knepley           } else if ((p >= fStart) && (p < fEnd)) {
6473b5da9499SMatthew G. Knepley             /* Old faces add new faces and edges */
6474b5da9499SMatthew G. Knepley             for (r = 0; r < 4; ++r) {
6475b5da9499SMatthew G. Knepley               newp = fStartNew + (p - fStart)*4 + r;
6476b5da9499SMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
6477b5da9499SMatthew G. Knepley             }
6478b5da9499SMatthew G. Knepley             for (r = 0; r < 3; ++r) {
6479b5da9499SMatthew G. Knepley               newp = eStartNew + (eEnd - eStart)*2 + (p - fStart)*3 + r;
6480b5da9499SMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
6481b5da9499SMatthew G. Knepley             }
6482b5da9499SMatthew G. Knepley           } else if ((p >= cStart) && (p < cEnd)) {
6483b5da9499SMatthew G. Knepley             /* Old cells add new cells and interior faces and edges */
6484b5da9499SMatthew G. Knepley             for (r = 0; r < 8; ++r) {
6485b5da9499SMatthew G. Knepley               newp = cStartNew + (p - cStart)*8 + r;
6486b5da9499SMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
6487b5da9499SMatthew G. Knepley             }
6488b5da9499SMatthew G. Knepley             for (r = 0; r < 8; ++r) {
6489b5da9499SMatthew G. Knepley               newp = fStartNew + (fEnd - fStart)*4 + (p - cStart)*8 + r;
6490b5da9499SMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
6491b5da9499SMatthew G. Knepley             }
6492b5da9499SMatthew G. Knepley             for (r = 0; r < 1; ++r) {
6493b5da9499SMatthew G. Knepley               newp = eStartNew + (eEnd - eStart)*2 + (fEnd - fStart)*3 + (p - cStart)*1 + r;
6494b5da9499SMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
6495b5da9499SMatthew G. Knepley             }
6496b5da9499SMatthew G. Knepley           }
6497b5da9499SMatthew G. Knepley           break;
64989b1a0e7fSLawrence Mitchell         case REFINER_HYBRID_SIMPLEX_3D:
64996ce3c06aSMatthew G. Knepley           if ((p >= vStart) && (p < vEnd)) {
65006ce3c06aSMatthew G. Knepley             /* Interior vertices stay the same */
65016ce3c06aSMatthew G. Knepley             newp = vStartNew + (p - vStart);
65026ce3c06aSMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65036ce3c06aSMatthew G. Knepley           } else if ((p >= eStart) && (p < eMax)) {
65046ce3c06aSMatthew G. Knepley             /* Interior edges add new edges and vertex */
65056ce3c06aSMatthew G. Knepley             for (r = 0; r < 2; ++r) {
65066ce3c06aSMatthew G. Knepley               newp = eStartNew + (p - eStart)*2 + r;
65076ce3c06aSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65086ce3c06aSMatthew G. Knepley             }
65096ce3c06aSMatthew G. Knepley             newp = vStartNew + (vEnd - vStart) + (p - eStart);
65106ce3c06aSMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65116ce3c06aSMatthew G. Knepley           } else if ((p >= eMax) && (p < eEnd)) {
65126ce3c06aSMatthew G. Knepley             /* Hybrid edges stay the same */
65136ce3c06aSMatthew G. Knepley             newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*3 + (cMax - cStart) + (p - eMax);
65146ce3c06aSMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65156ce3c06aSMatthew G. Knepley           } else if ((p >= fStart) && (p < fMax)) {
65166ce3c06aSMatthew G. Knepley             /* Interior faces add new faces and edges */
65176ce3c06aSMatthew G. Knepley             for (r = 0; r < 4; ++r) {
65186ce3c06aSMatthew G. Knepley               newp = fStartNew + (p - fStart)*4 + r;
65196ce3c06aSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65206ce3c06aSMatthew G. Knepley             }
65216ce3c06aSMatthew G. Knepley             for (r = 0; r < 3; ++r) {
65226ce3c06aSMatthew G. Knepley               newp = eStartNew + (eMax - eStart)*2 + (p - fStart)*3 + r;
65236ce3c06aSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65246ce3c06aSMatthew G. Knepley             }
65256ce3c06aSMatthew G. Knepley           } else if ((p >= fMax) && (p < fEnd)) {
65266ce3c06aSMatthew G. Knepley             /* Hybrid faces add new faces and edges */
65276ce3c06aSMatthew G. Knepley             for (r = 0; r < 2; ++r) {
65286ce3c06aSMatthew G. Knepley               newp = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*8 + (p - fMax)*2 + r;
65296ce3c06aSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65306ce3c06aSMatthew G. Knepley             }
65316ce3c06aSMatthew G. Knepley             newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*3 + (cMax - cStart) + (p - fMax);
65326ce3c06aSMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65336ce3c06aSMatthew G. Knepley           } else if ((p >= cStart) && (p < cMax)) {
65346ce3c06aSMatthew G. Knepley             /* Interior cells add new cells, faces, and edges */
65356ce3c06aSMatthew G. Knepley             for (r = 0; r < 8; ++r) {
65366ce3c06aSMatthew G. Knepley               newp = cStartNew + (p - cStart)*8 + r;
65376ce3c06aSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65386ce3c06aSMatthew G. Knepley             }
65396ce3c06aSMatthew G. Knepley             for (r = 0; r < 8; ++r) {
65406ce3c06aSMatthew G. Knepley               newp = fStartNew + (fMax - fStart)*4 + (p - cStart)*8 + r;
65416ce3c06aSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65426ce3c06aSMatthew G. Knepley             }
65436ce3c06aSMatthew G. Knepley             newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*3 + (p - cStart);
65446ce3c06aSMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
654558b8852aSMatthew G. Knepley           } else if ((p >= cMax) && (p < cEnd)) {
65466ce3c06aSMatthew G. Knepley             /* Hybrid cells add new cells and faces */
65476ce3c06aSMatthew G. Knepley             for (r = 0; r < 4; ++r) {
65486ce3c06aSMatthew G. Knepley               newp = cStartNew + (cMax - cStart)*8 + (p - cMax)*4 + r;
65496ce3c06aSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65506ce3c06aSMatthew G. Knepley             }
65516ce3c06aSMatthew G. Knepley             for (r = 0; r < 3; ++r) {
65526ce3c06aSMatthew G. Knepley               newp = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*8 + (fEnd - fMax)*2 + (p - cMax)*3 + r;
65536ce3c06aSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65546ce3c06aSMatthew G. Knepley             }
65556ce3c06aSMatthew G. Knepley           }
65566ce3c06aSMatthew G. Knepley           break;
65579b1a0e7fSLawrence Mitchell         case REFINER_HEX_3D:
65582eabf88fSMatthew G. Knepley           if ((p >= vStart) && (p < vEnd)) {
65592eabf88fSMatthew G. Knepley             /* Old vertices stay the same */
65602eabf88fSMatthew G. Knepley             newp = vStartNew + (p - vStart);
65612eabf88fSMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
656219d7d790SMatthew G. Knepley           } else if ((p >= eStart) && (p < eEnd)) {
65632eabf88fSMatthew G. Knepley             /* Old edges add new edges and vertex */
65642eabf88fSMatthew G. Knepley             for (r = 0; r < 2; ++r) {
65652eabf88fSMatthew G. Knepley               newp = eStartNew + (p - eStart)*2 + r;
65662eabf88fSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65672eabf88fSMatthew G. Knepley             }
65682eabf88fSMatthew G. Knepley             newp = vStartNew + (vEnd - vStart) + (p - eStart);
65692eabf88fSMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65702eabf88fSMatthew G. Knepley           } else if ((p >= fStart) && (p < fEnd)) {
65712eabf88fSMatthew G. Knepley             /* Old faces add new faces, edges, and vertex */
65722eabf88fSMatthew G. Knepley             for (r = 0; r < 4; ++r) {
65732eabf88fSMatthew G. Knepley               newp = fStartNew + (p - fStart)*4 + r;
65742eabf88fSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65752eabf88fSMatthew G. Knepley             }
65762eabf88fSMatthew G. Knepley             for (r = 0; r < 4; ++r) {
65772eabf88fSMatthew G. Knepley               newp = eStartNew + (eEnd - eStart)*2 + (p - fStart)*4 + r;
65782eabf88fSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65792eabf88fSMatthew G. Knepley             }
65802eabf88fSMatthew G. Knepley             newp = vStartNew + (vEnd - vStart) + (eEnd - eStart) + (p - fStart);
65812eabf88fSMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65822eabf88fSMatthew G. Knepley           } else if ((p >= cStart) && (p < cEnd)) {
65832eabf88fSMatthew G. Knepley             /* Old cells add new cells, faces, edges, and vertex */
65842eabf88fSMatthew G. Knepley             for (r = 0; r < 8; ++r) {
65852eabf88fSMatthew G. Knepley               newp = cStartNew + (p - cStart)*8 + r;
65862eabf88fSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65872eabf88fSMatthew G. Knepley             }
65882eabf88fSMatthew G. Knepley             for (r = 0; r < 12; ++r) {
65892eabf88fSMatthew G. Knepley               newp = fStartNew + (fEnd - fStart)*4 + (p - cStart)*12 + r;
65902eabf88fSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65912eabf88fSMatthew G. Knepley             }
65922eabf88fSMatthew G. Knepley             for (r = 0; r < 6; ++r) {
65932eabf88fSMatthew G. Knepley               newp = eStartNew + (eEnd - eStart)*2 + (fEnd - fStart)*4 + (p - cStart)*6 + r;
65942eabf88fSMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65952eabf88fSMatthew G. Knepley             }
65962eabf88fSMatthew G. Knepley             newp = vStartNew + (vEnd - vStart) + (eEnd - eStart) + (fEnd - fStart) + (p - cStart);
65972eabf88fSMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
65982eabf88fSMatthew G. Knepley           }
65992eabf88fSMatthew G. Knepley           break;
66009b1a0e7fSLawrence Mitchell         case REFINER_HYBRID_HEX_3D:
660127fcede3SMatthew G. Knepley           if ((p >= vStart) && (p < vEnd)) {
660227fcede3SMatthew G. Knepley             /* Interior vertices stay the same */
660327fcede3SMatthew G. Knepley             newp = vStartNew + (p - vStart);
660427fcede3SMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
660527fcede3SMatthew G. Knepley           } else if ((p >= eStart) && (p < eMax)) {
660627fcede3SMatthew G. Knepley             /* Interior edges add new edges and vertex */
660727fcede3SMatthew G. Knepley             for (r = 0; r < 2; ++r) {
660827fcede3SMatthew G. Knepley               newp = eStartNew + (p - eStart)*2 + r;
660927fcede3SMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
661027fcede3SMatthew G. Knepley             }
661127fcede3SMatthew G. Knepley             newp = vStartNew + (vEnd - vStart) + (p - eStart);
661227fcede3SMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
661327fcede3SMatthew G. Knepley           } else if ((p >= eMax) && (p < eEnd)) {
661427fcede3SMatthew G. Knepley             /* Hybrid edges stay the same */
661527fcede3SMatthew G. Knepley             newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (cMax - cStart)*6 + (p - eMax);
661627fcede3SMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
661727fcede3SMatthew G. Knepley           } else if ((p >= fStart) && (p < fMax)) {
661827fcede3SMatthew G. Knepley             /* Interior faces add new faces, edges, and vertex */
661927fcede3SMatthew G. Knepley             for (r = 0; r < 4; ++r) {
662027fcede3SMatthew G. Knepley               newp = fStartNew + (p - fStart)*4 + r;
662127fcede3SMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
662227fcede3SMatthew G. Knepley             }
662327fcede3SMatthew G. Knepley             for (r = 0; r < 4; ++r) {
662427fcede3SMatthew G. Knepley               newp = eStartNew + (eMax - eStart)*2 + (p - fStart)*4 + r;
662527fcede3SMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
662627fcede3SMatthew G. Knepley             }
662727fcede3SMatthew G. Knepley             newp = vStartNew + (vEnd - vStart) + (eMax - eStart) + (p - fStart);
662827fcede3SMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
662927fcede3SMatthew G. Knepley           } else if ((p >= fMax) && (p < fEnd)) {
663027fcede3SMatthew G. Knepley             /* Hybrid faces add new faces and edges */
663127fcede3SMatthew G. Knepley             for (r = 0; r < 2; ++r) {
663227fcede3SMatthew G. Knepley               newp = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*12 + (p - fMax)*2 + r;
663327fcede3SMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
663427fcede3SMatthew G. Knepley             }
663527fcede3SMatthew G. Knepley             newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (cMax - cStart)*6 + (p - fMax);
663627fcede3SMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
663727fcede3SMatthew G. Knepley           } else if ((p >= cStart) && (p < cMax)) {
663827fcede3SMatthew G. Knepley             /* Interior cells add new cells, faces, edges, and vertex */
663927fcede3SMatthew G. Knepley             for (r = 0; r < 8; ++r) {
664027fcede3SMatthew G. Knepley               newp = cStartNew + (p - cStart)*8 + r;
664127fcede3SMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
664227fcede3SMatthew G. Knepley             }
664327fcede3SMatthew G. Knepley             for (r = 0; r < 12; ++r) {
664427fcede3SMatthew G. Knepley               newp = fStartNew + (fMax - fStart)*4 + (p - cStart)*12 + r;
664527fcede3SMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
664627fcede3SMatthew G. Knepley             }
664727fcede3SMatthew G. Knepley             for (r = 0; r < 6; ++r) {
664827fcede3SMatthew G. Knepley               newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (p - cStart)*6 + r;
664927fcede3SMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
665027fcede3SMatthew G. Knepley             }
665127fcede3SMatthew G. Knepley             newp = vStartNew + (vEnd - vStart) + (eMax - eStart) + (fMax - fStart) + (p - cStart);
665227fcede3SMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
665327fcede3SMatthew G. Knepley           } else if ((p >= cMax) && (p < cEnd)) {
665427fcede3SMatthew G. Knepley             /* Hybrid cells add new cells, faces, and edges */
665527fcede3SMatthew G. Knepley             for (r = 0; r < 4; ++r) {
665627fcede3SMatthew G. Knepley               newp = cStartNew + (cMax - cStart)*8 + (p - cMax)*4 + r;
665727fcede3SMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
665827fcede3SMatthew G. Knepley             }
665927fcede3SMatthew G. Knepley             for (r = 0; r < 4; ++r) {
666027fcede3SMatthew G. Knepley               newp = fStartNew + (fMax - fStart)*4 + (cMax - cStart)*12 + (fEnd - fMax)*2 + (p - cMax)*4 + r;
666127fcede3SMatthew G. Knepley               ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
666227fcede3SMatthew G. Knepley             }
666327fcede3SMatthew G. Knepley             newp = eStartNew + (eMax - eStart)*2 + (fMax - fStart)*4 + (cMax - cStart)*6 + (fEnd - fMax) + (p - cMax);
666427fcede3SMatthew G. Knepley             ierr = DMLabelSetValue(labelNew, newp, values[val]);CHKERRQ(ierr);
666527fcede3SMatthew G. Knepley           }
666627fcede3SMatthew G. Knepley           break;
666775d3a19aSMatthew G. Knepley         default:
666875d3a19aSMatthew G. Knepley           SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Unknown cell refiner %d", refiner);
666975d3a19aSMatthew G. Knepley         }
667075d3a19aSMatthew G. Knepley       }
667175d3a19aSMatthew G. Knepley       ierr = ISRestoreIndices(pointIS, &points);CHKERRQ(ierr);
667275d3a19aSMatthew G. Knepley       ierr = ISDestroy(&pointIS);CHKERRQ(ierr);
667375d3a19aSMatthew G. Knepley     }
667475d3a19aSMatthew G. Knepley     ierr = ISRestoreIndices(valueIS, &values);CHKERRQ(ierr);
667575d3a19aSMatthew G. Knepley     ierr = ISDestroy(&valueIS);CHKERRQ(ierr);
667675d3a19aSMatthew G. Knepley     if (0) {
667775d3a19aSMatthew G. Knepley       ierr = PetscViewerASCIISynchronizedAllow(PETSC_VIEWER_STDOUT_WORLD, PETSC_TRUE);CHKERRQ(ierr);
667875d3a19aSMatthew G. Knepley       ierr = DMLabelView(labelNew, PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
667975d3a19aSMatthew G. Knepley       ierr = PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
668075d3a19aSMatthew G. Knepley     }
668175d3a19aSMatthew G. Knepley   }
668275d3a19aSMatthew G. Knepley   PetscFunctionReturn(0);
668375d3a19aSMatthew G. Knepley }
668475d3a19aSMatthew G. Knepley 
668575d3a19aSMatthew G. Knepley #undef __FUNCT__
6686509c9b89SMatthew G. Knepley #define __FUNCT__ "DMPlexRefineUniform_Internal"
668775d3a19aSMatthew G. Knepley /* This will only work for interpolated meshes */
6688509c9b89SMatthew G. Knepley PetscErrorCode DMPlexRefineUniform_Internal(DM dm, CellRefiner cellRefiner, DM *dmRefined)
668975d3a19aSMatthew G. Knepley {
669075d3a19aSMatthew G. Knepley   DM             rdm;
669175d3a19aSMatthew G. Knepley   PetscInt      *depthSize;
669275d3a19aSMatthew G. Knepley   PetscInt       dim, depth = 0, d, pStart = 0, pEnd = 0;
669375d3a19aSMatthew G. Knepley   PetscErrorCode ierr;
669475d3a19aSMatthew G. Knepley 
669575d3a19aSMatthew G. Knepley   PetscFunctionBegin;
669675d3a19aSMatthew G. Knepley   ierr = DMCreate(PetscObjectComm((PetscObject)dm), &rdm);CHKERRQ(ierr);
669775d3a19aSMatthew G. Knepley   ierr = DMSetType(rdm, DMPLEX);CHKERRQ(ierr);
6698c73cfb54SMatthew G. Knepley   ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr);
6699c73cfb54SMatthew G. Knepley   ierr = DMSetDimension(rdm, dim);CHKERRQ(ierr);
670075d3a19aSMatthew G. Knepley   /* Calculate number of new points of each depth */
670175d3a19aSMatthew G. Knepley   ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr);
67021e573d11SMatthew G. Knepley   if (depth >= 0 && dim != depth) SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "Mesh must be interpolated for regular refinement");
6703854ce69bSBarry Smith   ierr = PetscMalloc1(depth+1, &depthSize);CHKERRQ(ierr);
670475d3a19aSMatthew G. Knepley   ierr = PetscMemzero(depthSize, (depth+1) * sizeof(PetscInt));CHKERRQ(ierr);
670575d3a19aSMatthew G. Knepley   ierr = CellRefinerGetSizes(cellRefiner, dm, depthSize);CHKERRQ(ierr);
670675d3a19aSMatthew G. Knepley   /* Step 1: Set chart */
670775d3a19aSMatthew G. Knepley   for (d = 0; d <= depth; ++d) pEnd += depthSize[d];
670875d3a19aSMatthew G. Knepley   ierr = DMPlexSetChart(rdm, pStart, pEnd);CHKERRQ(ierr);
670975d3a19aSMatthew G. Knepley   /* Step 2: Set cone/support sizes */
671075d3a19aSMatthew G. Knepley   ierr = CellRefinerSetConeSizes(cellRefiner, dm, depthSize, rdm);CHKERRQ(ierr);
671175d3a19aSMatthew G. Knepley   /* Step 3: Setup refined DM */
671275d3a19aSMatthew G. Knepley   ierr = DMSetUp(rdm);CHKERRQ(ierr);
671375d3a19aSMatthew G. Knepley   /* Step 4: Set cones and supports */
671475d3a19aSMatthew G. Knepley   ierr = CellRefinerSetCones(cellRefiner, dm, depthSize, rdm);CHKERRQ(ierr);
671575d3a19aSMatthew G. Knepley   /* Step 5: Stratify */
671675d3a19aSMatthew G. Knepley   ierr = DMPlexStratify(rdm);CHKERRQ(ierr);
67170fadad52SMatthew G. Knepley   /* Step 6: Create pointSF */
671875d3a19aSMatthew G. Knepley   ierr = CellRefinerCreateSF(cellRefiner, dm, depthSize, rdm);CHKERRQ(ierr);
67190fadad52SMatthew G. Knepley   /* Step 7: Set coordinates for vertices */
67200fadad52SMatthew G. Knepley   ierr = CellRefinerSetCoordinates(cellRefiner, dm, depthSize, rdm);CHKERRQ(ierr);
672175d3a19aSMatthew G. Knepley   /* Step 8: Create labels */
672275d3a19aSMatthew G. Knepley   ierr = CellRefinerCreateLabels(cellRefiner, dm, depthSize, rdm);CHKERRQ(ierr);
672375d3a19aSMatthew G. Knepley   ierr = PetscFree(depthSize);CHKERRQ(ierr);
672475d3a19aSMatthew G. Knepley 
672575d3a19aSMatthew G. Knepley   *dmRefined = rdm;
672675d3a19aSMatthew G. Knepley   PetscFunctionReturn(0);
672775d3a19aSMatthew G. Knepley }
672875d3a19aSMatthew G. Knepley 
672975d3a19aSMatthew G. Knepley #undef __FUNCT__
67302389894bSMatthew G. Knepley #define __FUNCT__ "DMPlexCreateCoarsePointIS"
67312389894bSMatthew G. Knepley /*@
67322389894bSMatthew G. Knepley   DMPlexCreateCoarsePointIS - Creates an IS covering the coarse DM chart with the fine points as data
67332389894bSMatthew G. Knepley 
67342389894bSMatthew G. Knepley   Input Parameter:
67352389894bSMatthew G. Knepley . dm - The coarse DM
67362389894bSMatthew G. Knepley 
67372389894bSMatthew G. Knepley   Output Parameter:
67382389894bSMatthew G. Knepley . fpointIS - The IS of all the fine points which exist in the original coarse mesh
67392389894bSMatthew G. Knepley 
67402389894bSMatthew G. Knepley   Level: developer
67412389894bSMatthew G. Knepley 
67422389894bSMatthew G. Knepley .seealso: DMRefine(), DMPlexSetRefinementUniform(), DMPlexCreateSubpointIS()
67432389894bSMatthew G. Knepley @*/
67442389894bSMatthew G. Knepley PetscErrorCode DMPlexCreateCoarsePointIS(DM dm, IS *fpointIS)
67452389894bSMatthew G. Knepley {
67462389894bSMatthew G. Knepley   CellRefiner    cellRefiner;
67472389894bSMatthew G. Knepley   PetscInt      *depthSize, *fpoints;
67482389894bSMatthew G. Knepley   PetscInt       cStartNew = 0, vStartNew = 0, fStartNew = 0, eStartNew = 0;
67492389894bSMatthew G. Knepley   PetscInt       depth, pStart, pEnd, p, vStart, vEnd, v;
67502389894bSMatthew G. Knepley   PetscErrorCode ierr;
67512389894bSMatthew G. Knepley 
67522389894bSMatthew G. Knepley   PetscFunctionBegin;
67532389894bSMatthew G. Knepley   ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr);
67542389894bSMatthew G. Knepley   ierr = DMPlexGetChart(dm, &pStart, &pEnd);CHKERRQ(ierr);
67552389894bSMatthew G. Knepley   ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr);
67562389894bSMatthew G. Knepley   ierr = DMPlexGetCellRefiner_Internal(dm, &cellRefiner);CHKERRQ(ierr);
6757854ce69bSBarry Smith   ierr = PetscMalloc1(depth+1, &depthSize);CHKERRQ(ierr);
67582389894bSMatthew G. Knepley   ierr = CellRefinerGetSizes(cellRefiner, dm, depthSize);CHKERRQ(ierr);
67592389894bSMatthew G. Knepley   if (cellRefiner) {ierr = GetDepthStart_Private(depth, depthSize, &cStartNew, &fStartNew, &eStartNew, &vStartNew);CHKERRQ(ierr);}
67602389894bSMatthew G. Knepley   ierr = PetscMalloc1(pEnd-pStart,&fpoints);CHKERRQ(ierr);
67612389894bSMatthew G. Knepley   for (p = 0; p < pEnd-pStart; ++p) fpoints[p] = -1;
67622389894bSMatthew G. Knepley   switch (cellRefiner) {
67636c0c04f5SMatthew G. Knepley   case REFINER_SIMPLEX_1D:
67646c0c04f5SMatthew G. Knepley   case REFINER_SIMPLEX_2D:
67656c0c04f5SMatthew G. Knepley   case REFINER_HYBRID_SIMPLEX_2D:
67666c0c04f5SMatthew G. Knepley   case REFINER_HEX_2D:
67676c0c04f5SMatthew G. Knepley   case REFINER_HYBRID_HEX_2D:
67686c0c04f5SMatthew G. Knepley   case REFINER_SIMPLEX_3D:
67696c0c04f5SMatthew G. Knepley   case REFINER_HYBRID_SIMPLEX_3D:
67706c0c04f5SMatthew G. Knepley   case REFINER_HEX_3D:
67716c0c04f5SMatthew G. Knepley   case REFINER_HYBRID_HEX_3D:
67722389894bSMatthew G. Knepley     for (v = vStart; v < vEnd; ++v) fpoints[v-pStart] = vStartNew + (v - vStart);
67732389894bSMatthew G. Knepley     break;
67742389894bSMatthew G. Knepley   default:
67752389894bSMatthew G. Knepley     SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Unknown cell refiner %d", cellRefiner);
67762389894bSMatthew G. Knepley   }
67772389894bSMatthew G. Knepley   ierr = ISCreateGeneral(PETSC_COMM_SELF, pEnd-pStart, fpoints, PETSC_OWN_POINTER, fpointIS);CHKERRQ(ierr);
67782389894bSMatthew G. Knepley   ierr = PetscFree(depthSize);CHKERRQ(ierr);
67792389894bSMatthew G. Knepley   PetscFunctionReturn(0);
67802389894bSMatthew G. Knepley }
67812389894bSMatthew G. Knepley 
67822389894bSMatthew G. Knepley #undef __FUNCT__
678375d3a19aSMatthew G. Knepley #define __FUNCT__ "DMPlexSetRefinementUniform"
67840e2b6761SMatthew G. Knepley /*@
67850e2b6761SMatthew G. Knepley   DMPlexSetRefinementUniform - Set the flag for uniform refinement
67860e2b6761SMatthew G. Knepley 
67870e2b6761SMatthew G. Knepley   Input Parameters:
67880e2b6761SMatthew G. Knepley + dm - The DM
67890e2b6761SMatthew G. Knepley - refinementUniform - The flag for uniform refinement
67900e2b6761SMatthew G. Knepley 
67910e2b6761SMatthew G. Knepley   Level: developer
67920e2b6761SMatthew G. Knepley 
67930e2b6761SMatthew G. Knepley .seealso: DMRefine(), DMPlexGetRefinementUniform(), DMPlexGetRefinementLimit(), DMPlexSetRefinementLimit()
67940e2b6761SMatthew G. Knepley @*/
679575d3a19aSMatthew G. Knepley PetscErrorCode DMPlexSetRefinementUniform(DM dm, PetscBool refinementUniform)
679675d3a19aSMatthew G. Knepley {
679775d3a19aSMatthew G. Knepley   DM_Plex *mesh = (DM_Plex*) dm->data;
679875d3a19aSMatthew G. Knepley 
679975d3a19aSMatthew G. Knepley   PetscFunctionBegin;
680075d3a19aSMatthew G. Knepley   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
680175d3a19aSMatthew G. Knepley   mesh->refinementUniform = refinementUniform;
680275d3a19aSMatthew G. Knepley   PetscFunctionReturn(0);
680375d3a19aSMatthew G. Knepley }
680475d3a19aSMatthew G. Knepley 
680575d3a19aSMatthew G. Knepley #undef __FUNCT__
680675d3a19aSMatthew G. Knepley #define __FUNCT__ "DMPlexGetRefinementUniform"
68070e2b6761SMatthew G. Knepley /*@
68080e2b6761SMatthew G. Knepley   DMPlexGetRefinementUniform - Retrieve the flag for uniform refinement
68090e2b6761SMatthew G. Knepley 
68100e2b6761SMatthew G. Knepley   Input Parameter:
68110e2b6761SMatthew G. Knepley . dm - The DM
68120e2b6761SMatthew G. Knepley 
68130e2b6761SMatthew G. Knepley   Output Parameter:
68140e2b6761SMatthew G. Knepley . refinementUniform - The flag for uniform refinement
68150e2b6761SMatthew G. Knepley 
68160e2b6761SMatthew G. Knepley   Level: developer
68170e2b6761SMatthew G. Knepley 
68180e2b6761SMatthew G. Knepley .seealso: DMRefine(), DMPlexSetRefinementUniform(), DMPlexGetRefinementLimit(), DMPlexSetRefinementLimit()
68190e2b6761SMatthew G. Knepley @*/
682075d3a19aSMatthew G. Knepley PetscErrorCode DMPlexGetRefinementUniform(DM dm, PetscBool *refinementUniform)
682175d3a19aSMatthew G. Knepley {
682275d3a19aSMatthew G. Knepley   DM_Plex *mesh = (DM_Plex*) dm->data;
682375d3a19aSMatthew G. Knepley 
682475d3a19aSMatthew G. Knepley   PetscFunctionBegin;
682575d3a19aSMatthew G. Knepley   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
682675d3a19aSMatthew G. Knepley   PetscValidPointer(refinementUniform,  2);
682775d3a19aSMatthew G. Knepley   *refinementUniform = mesh->refinementUniform;
682875d3a19aSMatthew G. Knepley   PetscFunctionReturn(0);
682975d3a19aSMatthew G. Knepley }
683075d3a19aSMatthew G. Knepley 
683175d3a19aSMatthew G. Knepley #undef __FUNCT__
683275d3a19aSMatthew G. Knepley #define __FUNCT__ "DMPlexSetRefinementLimit"
68330e2b6761SMatthew G. Knepley /*@
68340e2b6761SMatthew G. Knepley   DMPlexSetRefinementLimit - Set the maximum cell volume for refinement
68350e2b6761SMatthew G. Knepley 
68360e2b6761SMatthew G. Knepley   Input Parameters:
68370e2b6761SMatthew G. Knepley + dm - The DM
68380e2b6761SMatthew G. Knepley - refinementLimit - The maximum cell volume in the refined mesh
68390e2b6761SMatthew G. Knepley 
68400e2b6761SMatthew G. Knepley   Level: developer
68410e2b6761SMatthew G. Knepley 
68420e2b6761SMatthew G. Knepley .seealso: DMRefine(), DMPlexGetRefinementLimit(), DMPlexGetRefinementUniform(), DMPlexSetRefinementUniform()
68430e2b6761SMatthew G. Knepley @*/
684475d3a19aSMatthew G. Knepley PetscErrorCode DMPlexSetRefinementLimit(DM dm, PetscReal refinementLimit)
684575d3a19aSMatthew G. Knepley {
684675d3a19aSMatthew G. Knepley   DM_Plex *mesh = (DM_Plex*) dm->data;
684775d3a19aSMatthew G. Knepley 
684875d3a19aSMatthew G. Knepley   PetscFunctionBegin;
684975d3a19aSMatthew G. Knepley   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
685075d3a19aSMatthew G. Knepley   mesh->refinementLimit = refinementLimit;
685175d3a19aSMatthew G. Knepley   PetscFunctionReturn(0);
685275d3a19aSMatthew G. Knepley }
685375d3a19aSMatthew G. Knepley 
685475d3a19aSMatthew G. Knepley #undef __FUNCT__
685575d3a19aSMatthew G. Knepley #define __FUNCT__ "DMPlexGetRefinementLimit"
68560e2b6761SMatthew G. Knepley /*@
68570e2b6761SMatthew G. Knepley   DMPlexGetRefinementLimit - Retrieve the maximum cell volume for refinement
68580e2b6761SMatthew G. Knepley 
68590e2b6761SMatthew G. Knepley   Input Parameter:
68600e2b6761SMatthew G. Knepley . dm - The DM
68610e2b6761SMatthew G. Knepley 
68620e2b6761SMatthew G. Knepley   Output Parameter:
68630e2b6761SMatthew G. Knepley . refinementLimit - The maximum cell volume in the refined mesh
68640e2b6761SMatthew G. Knepley 
68650e2b6761SMatthew G. Knepley   Level: developer
68660e2b6761SMatthew G. Knepley 
68670e2b6761SMatthew G. Knepley .seealso: DMRefine(), DMPlexSetRefinementLimit(), DMPlexGetRefinementUniform(), DMPlexSetRefinementUniform()
68680e2b6761SMatthew G. Knepley @*/
686975d3a19aSMatthew G. Knepley PetscErrorCode DMPlexGetRefinementLimit(DM dm, PetscReal *refinementLimit)
687075d3a19aSMatthew G. Knepley {
687175d3a19aSMatthew G. Knepley   DM_Plex *mesh = (DM_Plex*) dm->data;
687275d3a19aSMatthew G. Knepley 
687375d3a19aSMatthew G. Knepley   PetscFunctionBegin;
687475d3a19aSMatthew G. Knepley   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
687575d3a19aSMatthew G. Knepley   PetscValidPointer(refinementLimit,  2);
687675d3a19aSMatthew G. Knepley   /* if (mesh->refinementLimit < 0) = getMaxVolume()/2.0; */
687775d3a19aSMatthew G. Knepley   *refinementLimit = mesh->refinementLimit;
687875d3a19aSMatthew G. Knepley   PetscFunctionReturn(0);
687975d3a19aSMatthew G. Knepley }
688075d3a19aSMatthew G. Knepley 
688175d3a19aSMatthew G. Knepley #undef __FUNCT__
6882509c9b89SMatthew G. Knepley #define __FUNCT__ "DMPlexGetCellRefiner_Internal"
6883509c9b89SMatthew G. Knepley PetscErrorCode DMPlexGetCellRefiner_Internal(DM dm, CellRefiner *cellRefiner)
688475d3a19aSMatthew G. Knepley {
68850f9259d6SMatthew G. Knepley   PetscInt       dim, cStart, cEnd, coneSize, cMax, fMax;
688675d3a19aSMatthew G. Knepley   PetscErrorCode ierr;
688775d3a19aSMatthew G. Knepley 
688875d3a19aSMatthew G. Knepley   PetscFunctionBegin;
6889c73cfb54SMatthew G. Knepley   ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr);
68903478d7aaSMatthew G. Knepley   ierr = DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd);CHKERRQ(ierr);
68919b1a0e7fSLawrence Mitchell   if (cEnd <= cStart) {*cellRefiner = REFINER_NOOP; PetscFunctionReturn(0);}
689275d3a19aSMatthew G. Knepley   ierr = DMPlexGetConeSize(dm, cStart, &coneSize);CHKERRQ(ierr);
689389b38ed4SMatthew G. Knepley   ierr = DMPlexGetHybridBounds(dm, &cMax, &fMax, NULL, NULL);CHKERRQ(ierr);
689475d3a19aSMatthew G. Knepley   switch (dim) {
68950314a74cSLawrence Mitchell   case 1:
68960314a74cSLawrence Mitchell     switch (coneSize) {
68970314a74cSLawrence Mitchell     case 2:
68980314a74cSLawrence Mitchell       *cellRefiner = REFINER_SIMPLEX_1D;
68990314a74cSLawrence Mitchell       break;
69000314a74cSLawrence Mitchell     default:
69010314a74cSLawrence Mitchell       SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Unknown coneSize %d in dimension %d for cell refiner", coneSize, dim);
69020314a74cSLawrence Mitchell     }
69030314a74cSLawrence Mitchell     break;
690475d3a19aSMatthew G. Knepley   case 2:
690575d3a19aSMatthew G. Knepley     switch (coneSize) {
690675d3a19aSMatthew G. Knepley     case 3:
69079b1a0e7fSLawrence Mitchell       if (cMax >= 0) *cellRefiner = REFINER_HYBRID_SIMPLEX_2D;
69089b1a0e7fSLawrence Mitchell       else *cellRefiner = REFINER_SIMPLEX_2D;
690975d3a19aSMatthew G. Knepley       break;
691075d3a19aSMatthew G. Knepley     case 4:
691189b38ed4SMatthew G. Knepley       if (cMax >= 0 && fMax >= 0) *cellRefiner = REFINER_HYBRID_HEX_2D;
69129b1a0e7fSLawrence Mitchell       else *cellRefiner = REFINER_HEX_2D;
691375d3a19aSMatthew G. Knepley       break;
691475d3a19aSMatthew G. Knepley     default:
691575d3a19aSMatthew G. Knepley       SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Unknown coneSize %d in dimension %d for cell refiner", coneSize, dim);
691675d3a19aSMatthew G. Knepley     }
691775d3a19aSMatthew G. Knepley     break;
6918b5da9499SMatthew G. Knepley   case 3:
6919b5da9499SMatthew G. Knepley     switch (coneSize) {
6920b5da9499SMatthew G. Knepley     case 4:
69219b1a0e7fSLawrence Mitchell       if (cMax >= 0) *cellRefiner = REFINER_HYBRID_SIMPLEX_3D;
69229b1a0e7fSLawrence Mitchell       else *cellRefiner = REFINER_SIMPLEX_3D;
6923b5da9499SMatthew G. Knepley       break;
69242eabf88fSMatthew G. Knepley     case 6:
69259b1a0e7fSLawrence Mitchell       if (cMax >= 0) *cellRefiner = REFINER_HYBRID_HEX_3D;
69269b1a0e7fSLawrence Mitchell       else *cellRefiner = REFINER_HEX_3D;
69272eabf88fSMatthew G. Knepley       break;
6928b5da9499SMatthew G. Knepley     default:
6929b5da9499SMatthew G. Knepley       SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Unknown coneSize %d in dimension %d for cell refiner", coneSize, dim);
6930b5da9499SMatthew G. Knepley     }
6931b5da9499SMatthew G. Knepley     break;
693275d3a19aSMatthew G. Knepley   default:
693375d3a19aSMatthew G. Knepley     SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Unknown dimension %d for cell refiner", dim);
693475d3a19aSMatthew G. Knepley   }
693575d3a19aSMatthew G. Knepley   PetscFunctionReturn(0);
693675d3a19aSMatthew G. Knepley }
6937