xref: /petsc/src/dm/impls/plex/plexproject.c (revision 11d189da875c12f17506fb730448f6d8eb371d0d)
147923291SMatthew G. Knepley #include <petsc/private/dmpleximpl.h>   /*I      "petscdmplex.h"   I*/
247923291SMatthew G. Knepley 
38c6c5593SMatthew G. Knepley #include <petsc/private/petscfeimpl.h>
48c6c5593SMatthew G. Knepley 
547923291SMatthew G. Knepley #undef __FUNCT__
68c6c5593SMatthew G. Knepley #define __FUNCT__ "DMProjectPoint_Func_Private"
78c6c5593SMatthew G. Knepley static PetscErrorCode DMProjectPoint_Func_Private(DM dm, PetscReal time, PetscFECellGeom *fegeom, PetscFVCellGeom *fvgeom, PetscBool isFE[], PetscDualSpace sp[], PetscInt Nc[],
88c6c5593SMatthew G. Knepley                                                   PetscErrorCode (**funcs)(PetscInt, PetscReal, const PetscReal [], PetscInt, PetscScalar *, void *), void **ctxs,
98c6c5593SMatthew G. Knepley                                                   PetscScalar values[])
1047923291SMatthew G. Knepley {
118c6c5593SMatthew G. Knepley   PetscDS        prob;
128c6c5593SMatthew G. Knepley   PetscInt       Nf, f, spDim, d, c, v;
138c6c5593SMatthew G. Knepley   PetscErrorCode ierr;
148c6c5593SMatthew G. Knepley 
158c6c5593SMatthew G. Knepley   PetscFunctionBeginHot;
168c6c5593SMatthew G. Knepley   ierr = DMGetDS(dm, &prob);CHKERRQ(ierr);
178c6c5593SMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
188c6c5593SMatthew G. Knepley   /* Get values for closure */
198c6c5593SMatthew G. Knepley   for (f = 0, v = 0; f < Nf; ++f) {
208c6c5593SMatthew G. Knepley     void * const ctx = ctxs ? ctxs[f] : NULL;
218c6c5593SMatthew G. Knepley 
228c6c5593SMatthew G. Knepley     if (!sp[f]) continue;
238c6c5593SMatthew G. Knepley     ierr = PetscDualSpaceGetDimension(sp[f], &spDim);CHKERRQ(ierr);
248c6c5593SMatthew G. Knepley     for (d = 0; d < spDim; ++d) {
258c6c5593SMatthew G. Knepley       if (funcs[f]) {
268c6c5593SMatthew G. Knepley         if (isFE[f]) {ierr = PetscDualSpaceApply(sp[f], d, time, fegeom, Nc[f], funcs[f], ctx, &values[v]);CHKERRQ(ierr);}
278c6c5593SMatthew G. Knepley         else         {ierr = PetscDualSpaceApplyFVM(sp[f], d, time, fvgeom, Nc[f], funcs[f], ctx, &values[v]);CHKERRQ(ierr);}
288c6c5593SMatthew G. Knepley       } else {
298c6c5593SMatthew G. Knepley         for (c = 0; c < Nc[f]; ++c) values[v+c] = 0.0;
308c6c5593SMatthew G. Knepley       }
318c6c5593SMatthew G. Knepley       v += Nc[f];
328c6c5593SMatthew G. Knepley     }
338c6c5593SMatthew G. Knepley   }
348c6c5593SMatthew G. Knepley   PetscFunctionReturn(0);
358c6c5593SMatthew G. Knepley }
368c6c5593SMatthew G. Knepley 
378c6c5593SMatthew G. Knepley #undef __FUNCT__
388c6c5593SMatthew G. Knepley #define __FUNCT__ "DMProjectPoint_Field_Private"
398c6c5593SMatthew G. Knepley static PetscErrorCode DMProjectPoint_Field_Private(DM dm, DM dmAux, PetscReal time, Vec localU, Vec localA, PetscFECellGeom *fegeom, PetscDualSpace sp[], PetscInt Nc[], PetscInt p,
408c6c5593SMatthew G. Knepley                                                    void (**funcs)(PetscInt, PetscInt, PetscInt,
418c6c5593SMatthew G. Knepley                                                                   const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
428c6c5593SMatthew G. Knepley                                                                   const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
438c6c5593SMatthew G. Knepley                                                                   PetscReal, const PetscReal[], PetscScalar[]), void **ctxs,
448c6c5593SMatthew G. Knepley                                                    PetscScalar values[])
458c6c5593SMatthew G. Knepley {
468c6c5593SMatthew G. Knepley   PetscDS        prob, probAux = NULL;
478c6c5593SMatthew G. Knepley   PetscSection   section, sectionAux = NULL;
48*11d189daSMatthew G. Knepley   PetscScalar   *u, *u_t = NULL, *u_x, *a = NULL, *a_t = NULL, *a_x = NULL;
498c6c5593SMatthew G. Knepley   PetscScalar   *coefficients   = NULL, *coefficientsAux   = NULL;
508c6c5593SMatthew G. Knepley   PetscScalar   *coefficients_t = NULL, *coefficientsAux_t = NULL;
518c6c5593SMatthew G. Knepley   PetscReal     *x;
528c6c5593SMatthew G. Knepley   PetscInt      *uOff, *uOff_x, *aOff = NULL, *aOff_x = NULL;
538c6c5593SMatthew G. Knepley   PetscInt       dim, Nf, NfAux = 0, f, spDim, d, c, v;
548c6c5593SMatthew G. Knepley   PetscErrorCode ierr;
558c6c5593SMatthew G. Knepley 
568c6c5593SMatthew G. Knepley   PetscFunctionBeginHot;
578c6c5593SMatthew G. Knepley   ierr = DMGetDS(dm, &prob);CHKERRQ(ierr);
588c6c5593SMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
598c6c5593SMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
608c6c5593SMatthew G. Knepley   ierr = PetscDSGetComponentOffsets(prob, &uOff);CHKERRQ(ierr);
618c6c5593SMatthew G. Knepley   ierr = PetscDSGetComponentDerivativeOffsets(prob, &uOff_x);CHKERRQ(ierr);
62*11d189daSMatthew G. Knepley   ierr = PetscDSGetEvaluationArrays(prob, &u, NULL /*&u_t*/, &u_x);CHKERRQ(ierr);
638c6c5593SMatthew G. Knepley   ierr = PetscDSGetRefCoordArrays(prob, &x, NULL);CHKERRQ(ierr);
648c6c5593SMatthew G. Knepley   ierr = DMGetDefaultSection(dm, &section);CHKERRQ(ierr);
658c6c5593SMatthew G. Knepley   ierr = DMPlexVecGetClosure(dm, section, localU, c, NULL, &coefficients);CHKERRQ(ierr);
668c6c5593SMatthew G. Knepley   if (dmAux) {
678c6c5593SMatthew G. Knepley     ierr = DMGetDS(dmAux, &probAux);CHKERRQ(ierr);
688c6c5593SMatthew G. Knepley     ierr = PetscDSGetNumFields(probAux, &NfAux);CHKERRQ(ierr);
698c6c5593SMatthew G. Knepley     ierr = DMGetDefaultSection(dmAux, &sectionAux);CHKERRQ(ierr);
708c6c5593SMatthew G. Knepley     ierr = PetscDSGetComponentOffsets(probAux, &aOff);CHKERRQ(ierr);
718c6c5593SMatthew G. Knepley     ierr = PetscDSGetComponentDerivativeOffsets(probAux, &aOff_x);CHKERRQ(ierr);
72*11d189daSMatthew G. Knepley     ierr = PetscDSGetEvaluationArrays(probAux, &a, NULL /*&a_t*/, &a_x);CHKERRQ(ierr);
738c6c5593SMatthew G. Knepley     ierr = DMPlexVecGetClosure(dmAux, sectionAux, localA, c, NULL, &coefficientsAux);CHKERRQ(ierr);
748c6c5593SMatthew G. Knepley   }
758c6c5593SMatthew G. Knepley   /* Get values for closure */
768c6c5593SMatthew G. Knepley   for (f = 0, v = 0; f < Nf; ++f) {
778c6c5593SMatthew G. Knepley     void * const ctx = ctxs ? ctxs[f] : NULL;
788c6c5593SMatthew G. Knepley 
798c6c5593SMatthew G. Knepley     if (!sp[f]) continue;
808c6c5593SMatthew G. Knepley     ierr = PetscDualSpaceGetDimension(sp[f], &spDim);CHKERRQ(ierr);
818c6c5593SMatthew G. Knepley     for (d = 0; d < spDim; ++d) {
828c6c5593SMatthew G. Knepley       if (funcs[f]) {
838c6c5593SMatthew G. Knepley         PetscQuadrature  quad;
848c6c5593SMatthew G. Knepley         const PetscReal *points, *weights;
858c6c5593SMatthew G. Knepley         PetscInt         numPoints, q;
868c6c5593SMatthew G. Knepley 
878c6c5593SMatthew G. Knepley         ierr = PetscDualSpaceGetFunctional(sp[f], d, &quad);CHKERRQ(ierr);
888c6c5593SMatthew G. Knepley         ierr = PetscQuadratureGetData(quad, NULL, &numPoints, &points, &weights);CHKERRQ(ierr);
898c6c5593SMatthew G. Knepley         for (q = 0; q < numPoints; ++q) {
908c6c5593SMatthew G. Knepley           CoordinatesRefToReal(dim, dim, fegeom->v0, fegeom->J, &points[q*dim], x);
918c6c5593SMatthew G. Knepley           ierr = EvaluateFieldJets(prob,    PETSC_FALSE, q, fegeom->invJ, coefficients,    coefficients_t,    u, u_x, u_t);CHKERRQ(ierr);
928c6c5593SMatthew G. Knepley           ierr = EvaluateFieldJets(probAux, PETSC_FALSE, q, fegeom->invJ, coefficientsAux, coefficientsAux_t, a, a_x, a_t);CHKERRQ(ierr);
938c6c5593SMatthew G. Knepley           (*funcs[f])(dim, Nf, NfAux, uOff, uOff_x, u, u_t, u_x, aOff, aOff_x, a, a_t, a_x, time, x, &values[v]);
948c6c5593SMatthew G. Knepley         }
958c6c5593SMatthew G. Knepley       } else {
968c6c5593SMatthew G. Knepley         for (c = 0; c < Nc[f]; ++c) values[v+c] = 0.0;
978c6c5593SMatthew G. Knepley       }
988c6c5593SMatthew G. Knepley       v += Nc[f];
998c6c5593SMatthew G. Knepley     }
1008c6c5593SMatthew G. Knepley   }
1018c6c5593SMatthew G. Knepley   ierr = DMPlexVecRestoreClosure(dm, section, localU, p, NULL, &coefficients);CHKERRQ(ierr);
1028c6c5593SMatthew G. Knepley   if (dmAux) {ierr = DMPlexVecRestoreClosure(dmAux, sectionAux, localA, p, NULL, &coefficientsAux);CHKERRQ(ierr);}
1038c6c5593SMatthew G. Knepley   PetscFunctionReturn(0);
1048c6c5593SMatthew G. Knepley }
1058c6c5593SMatthew G. Knepley 
1068c6c5593SMatthew G. Knepley #undef __FUNCT__
1078c6c5593SMatthew G. Knepley #define __FUNCT__ "DMProjectPoint_Private"
1088c6c5593SMatthew G. Knepley static PetscErrorCode DMProjectPoint_Private(DM dm, DM dmAux, PetscInt h, PetscReal time, Vec localU, Vec localA, PetscBool hasFE, PetscBool hasFV, PetscBool isFE[], PetscDualSpace sp[], PetscInt Nc[], PetscInt p,
1098c6c5593SMatthew G. Knepley                                              DMBoundaryConditionType type, void (**funcs)(void), void **ctxs, PetscBool fieldActive[], PetscScalar values[])
1108c6c5593SMatthew G. Knepley {
1118c6c5593SMatthew G. Knepley   PetscFECellGeom fegeom;
1128c6c5593SMatthew G. Knepley   PetscFVCellGeom fvgeom;
1138c6c5593SMatthew G. Knepley   PetscInt        dim, dimEmbed;
1148c6c5593SMatthew G. Knepley   PetscErrorCode  ierr;
1158c6c5593SMatthew G. Knepley 
1168c6c5593SMatthew G. Knepley   PetscFunctionBeginHot;
1178c6c5593SMatthew G. Knepley   ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr);
1188c6c5593SMatthew G. Knepley   ierr = DMGetCoordinateDim(dm, &dimEmbed);CHKERRQ(ierr);
1198c6c5593SMatthew G. Knepley   if (hasFE) {
1208c6c5593SMatthew G. Knepley     ierr = DMPlexComputeCellGeometryFEM(dm, p, NULL, fegeom.v0, fegeom.J, NULL, &fegeom.detJ);CHKERRQ(ierr);
1218c6c5593SMatthew G. Knepley     fegeom.dim      = dim - h;
1228c6c5593SMatthew G. Knepley     fegeom.dimEmbed = dimEmbed;
1238c6c5593SMatthew G. Knepley   }
1248c6c5593SMatthew G. Knepley   if (hasFV) {ierr = DMPlexComputeCellGeometryFVM(dm, p, &fvgeom.volume, fvgeom.centroid, NULL);CHKERRQ(ierr);}
1258c6c5593SMatthew G. Knepley   switch (type) {
1268c6c5593SMatthew G. Knepley   case DM_BC_ESSENTIAL:
1278c6c5593SMatthew G. Knepley   case DM_BC_NATURAL:
1288c6c5593SMatthew G. Knepley     ierr = DMProjectPoint_Func_Private(dm, time, &fegeom, &fvgeom, isFE, sp, Nc, (PetscErrorCode (**)(PetscInt, PetscReal, const PetscReal [], PetscInt, PetscScalar *, void *)) funcs, ctxs, values);CHKERRQ(ierr);break;
1298c6c5593SMatthew G. Knepley   case DM_BC_ESSENTIAL_FIELD:
1308c6c5593SMatthew G. Knepley   case DM_BC_NATURAL_FIELD:
1318c6c5593SMatthew G. Knepley     ierr = DMProjectPoint_Field_Private(dm, dmAux, time, localU, localA, &fegeom, sp, Nc, p, (void (**)(PetscInt, PetscInt, PetscInt, const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[], const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[], PetscReal, const PetscReal[], PetscScalar[])) funcs, ctxs, values);CHKERRQ(ierr);break;
1328c6c5593SMatthew G. Knepley   default: SETERRQ1(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "Unknown boundary condition type: %d", (int) type);
1338c6c5593SMatthew G. Knepley   }
1348c6c5593SMatthew G. Knepley   PetscFunctionReturn(0);
1358c6c5593SMatthew G. Knepley }
1368c6c5593SMatthew G. Knepley 
1378c6c5593SMatthew G. Knepley #undef __FUNCT__
1388c6c5593SMatthew G. Knepley #define __FUNCT__ "DMProjectLocal_Generic_Plex"
1398c6c5593SMatthew G. Knepley PetscErrorCode DMProjectLocal_Generic_Plex(DM dm, PetscReal time, Vec localU,
1408c6c5593SMatthew G. Knepley                                            DMLabel label, PetscInt numIds, const PetscInt ids[],
1418c6c5593SMatthew G. Knepley                                            DMBoundaryConditionType type, void (**funcs)(void), void **ctxs,
1428c6c5593SMatthew G. Knepley                                            InsertMode mode, Vec localX)
1438c6c5593SMatthew G. Knepley {
1448c6c5593SMatthew G. Knepley   DM              dmAux  = NULL;
1458c6c5593SMatthew G. Knepley   Vec             localA = NULL;
14647923291SMatthew G. Knepley   PetscSection    section;
1478c6c5593SMatthew G. Knepley   PetscDualSpace *sp, *cellsp;
1488c6c5593SMatthew G. Knepley   PetscInt       *Nc;
1498c6c5593SMatthew G. Knepley   PetscInt        dim, dimEmbed, maxHeight, h, Nf, f;
15047923291SMatthew G. Knepley   PetscBool      *isFE, hasFE = PETSC_FALSE, hasFV = PETSC_FALSE;
15147923291SMatthew G. Knepley   PetscErrorCode  ierr;
15247923291SMatthew G. Knepley 
15347923291SMatthew G. Knepley   PetscFunctionBegin;
1548c6c5593SMatthew G. Knepley   ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr);
1558c6c5593SMatthew G. Knepley   ierr = DMPlexGetMaxProjectionHeight(dm, &maxHeight);CHKERRQ(ierr);
1568c6c5593SMatthew G. Knepley   if (maxHeight < 0 || maxHeight > dim) {SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Maximum projection height %d not in [0, %d)\n", maxHeight, dim);}
1578c6c5593SMatthew G. Knepley   ierr = DMGetCoordinateDim(dm, &dimEmbed);CHKERRQ(ierr);
15847923291SMatthew G. Knepley   ierr = DMGetDefaultSection(dm, &section);CHKERRQ(ierr);
15947923291SMatthew G. Knepley   ierr = PetscSectionGetNumFields(section, &Nf);CHKERRQ(ierr);
1608c6c5593SMatthew G. Knepley   ierr = PetscObjectQuery((PetscObject) dm, "dmAux", (PetscObject *) &dmAux);CHKERRQ(ierr);
1618c6c5593SMatthew G. Knepley   ierr = PetscObjectQuery((PetscObject) dm, "A", (PetscObject *) &localA);CHKERRQ(ierr);
1628c6c5593SMatthew G. Knepley   ierr = PetscMalloc3(Nf, &isFE, Nf, &sp, Nf, &Nc);CHKERRQ(ierr);
1638c6c5593SMatthew G. Knepley   if (maxHeight > 0) {ierr = PetscMalloc1(Nf, &cellsp);CHKERRQ(ierr);}
1648c6c5593SMatthew G. Knepley   else               {cellsp = sp;}
1658c6c5593SMatthew G. Knepley   if (localU && localU != localX) {ierr = DMPlexInsertBoundaryValues(dm, PETSC_TRUE, localU, time, NULL, NULL, NULL);CHKERRQ(ierr);}
1668c6c5593SMatthew G. Knepley   /* Get cell dual spaces */
16747923291SMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
16847923291SMatthew G. Knepley     PetscObject  obj;
16947923291SMatthew G. Knepley     PetscClassId id;
17047923291SMatthew G. Knepley 
17147923291SMatthew G. Knepley     ierr = DMGetField(dm, f, &obj);CHKERRQ(ierr);
17247923291SMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
17347923291SMatthew G. Knepley     if (id == PETSCFE_CLASSID) {
17447923291SMatthew G. Knepley       PetscFE fe = (PetscFE) obj;
17547923291SMatthew G. Knepley 
17647923291SMatthew G. Knepley       hasFE   = PETSC_TRUE;
17747923291SMatthew G. Knepley       isFE[f] = PETSC_TRUE;
1788c6c5593SMatthew G. Knepley       ierr = PetscFEGetNumComponents(fe, &Nc[f]);CHKERRQ(ierr);
17947923291SMatthew G. Knepley       ierr  = PetscFEGetDualSpace(fe, &cellsp[f]);CHKERRQ(ierr);
18047923291SMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
18147923291SMatthew G. Knepley       PetscFV fv = (PetscFV) obj;
18247923291SMatthew G. Knepley 
18347923291SMatthew G. Knepley       hasFV   = PETSC_TRUE;
18447923291SMatthew G. Knepley       isFE[f] = PETSC_FALSE;
1858c6c5593SMatthew G. Knepley       ierr = PetscFVGetNumComponents(fv, &Nc[f]);CHKERRQ(ierr);
18647923291SMatthew G. Knepley       ierr = PetscFVGetDualSpace(fv, &cellsp[f]);CHKERRQ(ierr);
18747923291SMatthew G. Knepley     } else SETERRQ1(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f);
18847923291SMatthew G. Knepley   }
18947923291SMatthew G. Knepley   /* Note: We make no attempt to optimize for height. Higher height things just overwrite the lower height results. */
19047923291SMatthew G. Knepley   for (h = 0; h <= maxHeight; h++) {
1918c6c5593SMatthew G. Knepley     PetscScalar *values;
1928c6c5593SMatthew G. Knepley     PetscBool   *fieldActive;
1938c6c5593SMatthew G. Knepley     PetscInt     pStart, pEnd, p, spDim, totDim, d, numValues, v;
1948c6c5593SMatthew G. Knepley 
19547923291SMatthew G. Knepley     ierr = DMPlexGetHeightStratum(dm, h, &pStart, &pEnd);CHKERRQ(ierr);
1968c6c5593SMatthew G. Knepley     if (!h) {
1978c6c5593SMatthew G. Knepley       PetscInt cEndInterior;
1988c6c5593SMatthew G. Knepley 
1998c6c5593SMatthew G. Knepley       ierr = DMPlexGetHybridBounds(dm, &cEndInterior, NULL, NULL, NULL);CHKERRQ(ierr);
2008c6c5593SMatthew G. Knepley       pEnd = cEndInterior < 0 ? pEnd : cEndInterior;
2018c6c5593SMatthew G. Knepley     }
20247923291SMatthew G. Knepley     if (pEnd <= pStart) continue;
20347923291SMatthew G. Knepley     /* Compute totDim, the number of dofs in the closure of a point at this height */
20447923291SMatthew G. Knepley     totDim = 0;
20547923291SMatthew G. Knepley     for (f = 0; f < Nf; ++f) {
20647923291SMatthew G. Knepley       if (!h) {
20747923291SMatthew G. Knepley         sp[f] = cellsp[f];
20847923291SMatthew G. Knepley       } else {
20947923291SMatthew G. Knepley         ierr = PetscDualSpaceGetHeightSubspace(cellsp[f], h, &sp[f]);CHKERRQ(ierr);
21047923291SMatthew G. Knepley         if (!sp[f]) continue;
21147923291SMatthew G. Knepley       }
21247923291SMatthew G. Knepley       ierr = PetscDualSpaceGetDimension(sp[f], &spDim);CHKERRQ(ierr);
2138c6c5593SMatthew G. Knepley       totDim += spDim*Nc[f];
21447923291SMatthew G. Knepley     }
21547923291SMatthew G. Knepley     ierr = DMPlexVecGetClosure(dm, section, localX, pStart, &numValues, NULL);CHKERRQ(ierr);
2168c6c5593SMatthew G. Knepley     if (numValues != totDim) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "The section point closure size %d != dual space dimension %d", numValues, totDim);
21747923291SMatthew G. Knepley     if (!totDim) continue;
21847923291SMatthew G. Knepley     /* Loop over points at this height */
21947923291SMatthew G. Knepley     ierr = DMGetWorkArray(dm, numValues, PETSC_SCALAR, &values);CHKERRQ(ierr);
2208c6c5593SMatthew G. Knepley     ierr = DMGetWorkArray(dm, Nf, PETSC_BOOL, &fieldActive);CHKERRQ(ierr);
2218c6c5593SMatthew G. Knepley     for (f = 0; f < Nf; ++f) fieldActive[f] = (funcs[f] && sp[f]) ? PETSC_TRUE : PETSC_FALSE;
2228c6c5593SMatthew G. Knepley     if (label) {
2238c6c5593SMatthew G. Knepley       PetscInt i;
22447923291SMatthew G. Knepley 
22547923291SMatthew G. Knepley       for (i = 0; i < numIds; ++i) {
22647923291SMatthew G. Knepley         IS              pointIS;
22747923291SMatthew G. Knepley         const PetscInt *points;
2288c6c5593SMatthew G. Knepley         PetscInt        n;
22947923291SMatthew G. Knepley 
23047923291SMatthew G. Knepley         ierr = DMLabelGetStratumIS(label, ids[i], &pointIS);CHKERRQ(ierr);
23147923291SMatthew G. Knepley         if (!pointIS) continue; /* No points with that id on this process */
23247923291SMatthew G. Knepley         ierr = ISGetLocalSize(pointIS, &n);CHKERRQ(ierr);
23347923291SMatthew G. Knepley         ierr = ISGetIndices(pointIS, &points);CHKERRQ(ierr);
23447923291SMatthew G. Knepley         for (p = 0; p < n; ++p) {
23547923291SMatthew G. Knepley           const PetscInt  point = points[p];
23647923291SMatthew G. Knepley 
23747923291SMatthew G. Knepley           if ((point < pStart) || (point >= pEnd)) continue;
2388c6c5593SMatthew G. Knepley           ierr = DMProjectPoint_Private(dm, dmAux, h, time, localU, localA, hasFE, hasFV, isFE, sp, Nc, point, type, funcs, ctxs, fieldActive, values);
23947923291SMatthew G. Knepley           if (ierr) {
24047923291SMatthew G. Knepley             PetscErrorCode ierr2;
24147923291SMatthew G. Knepley             ierr2 = DMRestoreWorkArray(dm, numValues, PETSC_SCALAR, &values);CHKERRQ(ierr2);
2428c6c5593SMatthew G. Knepley             ierr2 = DMRestoreWorkArray(dm, Nf, PETSC_BOOL, &fieldActive);CHKERRQ(ierr2);
24347923291SMatthew G. Knepley             CHKERRQ(ierr);
24447923291SMatthew G. Knepley           }
24547923291SMatthew G. Knepley           ierr = DMPlexVecSetFieldClosure_Internal(dm, section, localX, fieldActive, point, values, mode);CHKERRQ(ierr);
24647923291SMatthew G. Knepley         }
24747923291SMatthew G. Knepley         ierr = ISRestoreIndices(pointIS, &points);CHKERRQ(ierr);
24847923291SMatthew G. Knepley         ierr = ISDestroy(&pointIS);CHKERRQ(ierr);
24947923291SMatthew G. Knepley       }
2508c6c5593SMatthew G. Knepley     } else {
2518c6c5593SMatthew G. Knepley       for (p = pStart; p < pEnd; ++p) {
2528c6c5593SMatthew G. Knepley         ierr = DMProjectPoint_Private(dm, dmAux, h, time, localU, localA, hasFE, hasFV, isFE, sp, Nc, p, type, funcs, ctxs, fieldActive, values);
2538c6c5593SMatthew G. Knepley         if (ierr) {
2548c6c5593SMatthew G. Knepley           PetscErrorCode ierr2;
2558c6c5593SMatthew G. Knepley           ierr2 = DMRestoreWorkArray(dm, numValues, PETSC_SCALAR, &values);CHKERRQ(ierr2);
2568c6c5593SMatthew G. Knepley           ierr2 = DMRestoreWorkArray(dm, Nf, PETSC_BOOL, &fieldActive);CHKERRQ(ierr2);
2578c6c5593SMatthew G. Knepley           CHKERRQ(ierr);
2588c6c5593SMatthew G. Knepley         }
2598c6c5593SMatthew G. Knepley         ierr = DMPlexVecSetFieldClosure_Internal(dm, section, localX, fieldActive, p, values, mode);CHKERRQ(ierr);
2608c6c5593SMatthew G. Knepley       }
2618c6c5593SMatthew G. Knepley     }
26247923291SMatthew G. Knepley     ierr = DMRestoreWorkArray(dm, numValues, PETSC_SCALAR, &values);CHKERRQ(ierr);
2638c6c5593SMatthew G. Knepley     ierr = DMRestoreWorkArray(dm, Nf, PETSC_BOOL, &fieldActive);CHKERRQ(ierr);
26447923291SMatthew G. Knepley   }
2658c6c5593SMatthew G. Knepley   /* Cleanup */
2668c6c5593SMatthew G. Knepley   ierr = PetscFree3(isFE, sp, Nc);CHKERRQ(ierr);
2678c6c5593SMatthew G. Knepley   if (maxHeight > 0) {ierr = PetscFree(cellsp);CHKERRQ(ierr);}
2688c6c5593SMatthew G. Knepley   PetscFunctionReturn(0);
26947923291SMatthew G. Knepley }
2708c6c5593SMatthew G. Knepley 
2718c6c5593SMatthew G. Knepley #undef __FUNCT__
2728c6c5593SMatthew G. Knepley #define __FUNCT__ "DMProjectFunctionLocal_Plex"
2738c6c5593SMatthew G. Knepley PetscErrorCode DMProjectFunctionLocal_Plex(DM dm, PetscReal time, PetscErrorCode (**funcs)(PetscInt, PetscReal, const PetscReal [], PetscInt, PetscScalar *, void *), void **ctxs, InsertMode mode, Vec localX)
2748c6c5593SMatthew G. Knepley {
2758c6c5593SMatthew G. Knepley   PetscErrorCode ierr;
2768c6c5593SMatthew G. Knepley 
2778c6c5593SMatthew G. Knepley   PetscFunctionBegin;
2788c6c5593SMatthew G. Knepley   ierr = DMProjectLocal_Generic_Plex(dm, time, localX, NULL, 0, NULL, DM_BC_ESSENTIAL, (void (**)(void)) funcs, ctxs, mode, localX);CHKERRQ(ierr);
2798c6c5593SMatthew G. Knepley   PetscFunctionReturn(0);
2808c6c5593SMatthew G. Knepley }
2818c6c5593SMatthew G. Knepley 
2828c6c5593SMatthew G. Knepley #undef __FUNCT__
2838c6c5593SMatthew G. Knepley #define __FUNCT__ "DMProjectFunctionLabelLocal_Plex"
2848c6c5593SMatthew G. Knepley PetscErrorCode DMProjectFunctionLabelLocal_Plex(DM dm, PetscReal time, DMLabel label, PetscInt numIds, const PetscInt ids[], PetscErrorCode (**funcs)(PetscInt, PetscReal, const PetscReal [], PetscInt, PetscScalar *, void *), void **ctxs, InsertMode mode, Vec localX)
2858c6c5593SMatthew G. Knepley {
2868c6c5593SMatthew G. Knepley   PetscErrorCode ierr;
2878c6c5593SMatthew G. Knepley 
2888c6c5593SMatthew G. Knepley   PetscFunctionBegin;
2898c6c5593SMatthew G. Knepley   ierr = DMProjectLocal_Generic_Plex(dm, time, localX, label, numIds, ids, DM_BC_ESSENTIAL, (void (**)(void)) funcs, ctxs, mode, localX);CHKERRQ(ierr);
29047923291SMatthew G. Knepley   PetscFunctionReturn(0);
29147923291SMatthew G. Knepley }
29247923291SMatthew G. Knepley 
29347923291SMatthew G. Knepley #undef __FUNCT__
29447923291SMatthew G. Knepley #define __FUNCT__ "DMProjectFieldLocal_Plex"
2958c6c5593SMatthew G. Knepley PetscErrorCode DMProjectFieldLocal_Plex(DM dm, PetscReal time, Vec localU,
29647923291SMatthew G. Knepley                                         void (**funcs)(PetscInt, PetscInt, PetscInt,
29747923291SMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
29847923291SMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
29947923291SMatthew G. Knepley                                                        PetscReal, const PetscReal[], PetscScalar[]),
30047923291SMatthew G. Knepley                                         InsertMode mode, Vec localX)
30147923291SMatthew G. Knepley {
30247923291SMatthew G. Knepley   PetscErrorCode ierr;
30347923291SMatthew G. Knepley 
30447923291SMatthew G. Knepley   PetscFunctionBegin;
3058c6c5593SMatthew G. Knepley   ierr = DMProjectLocal_Generic_Plex(dm, time, localU, NULL, 0, NULL, DM_BC_ESSENTIAL_FIELD, (void (**)(void)) funcs, NULL, mode, localX);CHKERRQ(ierr);
3068c6c5593SMatthew G. Knepley   PetscFunctionReturn(0);
30747923291SMatthew G. Knepley }
30847923291SMatthew G. Knepley 
3098c6c5593SMatthew G. Knepley #undef __FUNCT__
3108c6c5593SMatthew G. Knepley #define __FUNCT__ "DMProjectFieldLabelLocal_Plex"
3118c6c5593SMatthew G. Knepley PetscErrorCode DMProjectFieldLabelLocal_Plex(DM dm, PetscReal time, DMLabel label, PetscInt numIds, const PetscInt ids[], Vec localU,
3128c6c5593SMatthew G. Knepley                                              void (**funcs)(PetscInt, PetscInt, PetscInt,
3138c6c5593SMatthew G. Knepley                                                             const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
3148c6c5593SMatthew G. Knepley                                                             const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
3158c6c5593SMatthew G. Knepley                                                             PetscReal, const PetscReal[], PetscScalar[]),
3168c6c5593SMatthew G. Knepley                                              InsertMode mode, Vec localX)
3178c6c5593SMatthew G. Knepley {
3188c6c5593SMatthew G. Knepley   PetscErrorCode ierr;
31947923291SMatthew G. Knepley 
3208c6c5593SMatthew G. Knepley   PetscFunctionBegin;
3218c6c5593SMatthew G. Knepley   ierr = DMProjectLocal_Generic_Plex(dm, time, localU, label, numIds, ids, DM_BC_ESSENTIAL_FIELD, (void (**)(void)) funcs, NULL, mode, localX);CHKERRQ(ierr);
32247923291SMatthew G. Knepley   PetscFunctionReturn(0);
32347923291SMatthew G. Knepley }
324