151a454edSToby Isaac #include <petsc/private/dmfieldimpl.h> /*I "petscdmfield.h" I*/ 20145028aSToby Isaac #include <petsc/private/petscfeimpl.h> /*I "petscdmfield.h" I*/ 351a454edSToby Isaac #include <petscfe.h> 451a454edSToby Isaac #include <petscdmplex.h> 551a454edSToby Isaac #include <petscds.h> 651a454edSToby Isaac 79371c9d4SSatish Balay typedef struct _n_DMField_DS { 851a454edSToby Isaac PetscBool multifieldVec; 96858538eSMatthew G. Knepley PetscInt height; /* Point height at which we want values and number of discretizations */ 106858538eSMatthew G. Knepley PetscInt fieldNum; /* Number in DS of field which we evaluate */ 116858538eSMatthew G. Knepley PetscObject *disc; /* Discretizations of this field at each height */ 126858538eSMatthew G. Knepley Vec vec; /* Field values */ 136858538eSMatthew G. Knepley DM dmDG; /* DM for the DG values */ 146858538eSMatthew G. Knepley PetscObject *discDG; /* DG Discretizations of this field at each height */ 156858538eSMatthew G. Knepley Vec vecDG; /* DG Field values */ 166858538eSMatthew G. Knepley } DMField_DS; 1751a454edSToby Isaac 18d71ae5a4SJacob Faibussowitsch static PetscErrorCode DMFieldDestroy_DS(DMField field) 19d71ae5a4SJacob Faibussowitsch { 206858538eSMatthew G. Knepley DMField_DS *dsfield = (DMField_DS *)field->data; 2151a454edSToby Isaac PetscInt i; 2251a454edSToby Isaac 2351a454edSToby Isaac PetscFunctionBegin; 249566063dSJacob Faibussowitsch PetscCall(VecDestroy(&dsfield->vec)); 256858538eSMatthew G. Knepley for (i = 0; i < dsfield->height; i++) PetscCall(PetscObjectDereference(dsfield->disc[i])); 269566063dSJacob Faibussowitsch PetscCall(PetscFree(dsfield->disc)); 276858538eSMatthew G. Knepley PetscCall(VecDestroy(&dsfield->vecDG)); 289371c9d4SSatish Balay if (dsfield->discDG) 299371c9d4SSatish Balay for (i = 0; i < dsfield->height; i++) PetscCall(PetscObjectDereference(dsfield->discDG[i])); 306858538eSMatthew G. Knepley PetscCall(PetscFree(dsfield->discDG)); 319566063dSJacob Faibussowitsch PetscCall(PetscFree(dsfield)); 323ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3351a454edSToby Isaac } 3451a454edSToby Isaac 35d71ae5a4SJacob Faibussowitsch static PetscErrorCode DMFieldView_DS(DMField field, PetscViewer viewer) 36d71ae5a4SJacob Faibussowitsch { 3751a454edSToby Isaac DMField_DS *dsfield = (DMField_DS *)field->data; 3851a454edSToby Isaac PetscObject disc; 399f196a02SMartin Diehl PetscBool isascii; 4051a454edSToby Isaac 4151a454edSToby Isaac PetscFunctionBegin; 429f196a02SMartin Diehl PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii)); 4351a454edSToby Isaac disc = dsfield->disc[0]; 449f196a02SMartin Diehl if (isascii) { 4563a3b9bcSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "PetscDS field %" PetscInt_FMT "\n", dsfield->fieldNum)); 469566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushTab(viewer)); 479566063dSJacob Faibussowitsch PetscCall(PetscObjectView(disc, viewer)); 489566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPopTab(viewer)); 4951a454edSToby Isaac } 509566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushTab(viewer)); 5128b400f6SJacob Faibussowitsch PetscCheck(!dsfield->multifieldVec, PetscObjectComm((PetscObject)field), PETSC_ERR_SUP, "View of subfield not implemented yet"); 529566063dSJacob Faibussowitsch PetscCall(VecView(dsfield->vec, viewer)); 539566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPopTab(viewer)); 543ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 5551a454edSToby Isaac } 5651a454edSToby Isaac 57d71ae5a4SJacob Faibussowitsch static PetscErrorCode DMFieldDSGetHeightDisc(DMField field, PetscInt height, PetscObject discList[], PetscObject *disc) 58d71ae5a4SJacob Faibussowitsch { 5951a454edSToby Isaac PetscFunctionBegin; 60313f16f2SMatthew G. Knepley PetscCheck(height >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Height %" PetscInt_FMT " must be non-negative", height); 616858538eSMatthew G. Knepley if (!discList[height]) { 6251a454edSToby Isaac PetscClassId id; 6351a454edSToby Isaac 646858538eSMatthew G. Knepley PetscCall(PetscObjectGetClassId(discList[0], &id)); 656858538eSMatthew G. Knepley if (id == PETSCFE_CLASSID) PetscCall(PetscFECreateHeightTrace((PetscFE)discList[0], height, (PetscFE *)&discList[height])); 6651a454edSToby Isaac } 676858538eSMatthew G. Knepley *disc = discList[height]; 683ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 6951a454edSToby Isaac } 7051a454edSToby Isaac 7162bd480fSMatthew G. Knepley /* y[m,c] = A[m,n,c] . b[n] */ 7251a454edSToby Isaac #define DMFieldDSdot(y, A, b, m, n, c, cast) \ 7351a454edSToby Isaac do { \ 7451a454edSToby Isaac PetscInt _i, _j, _k; \ 7551a454edSToby Isaac for (_i = 0; _i < (m); _i++) { \ 76ad540459SPierre Jolivet for (_k = 0; _k < (c); _k++) (y)[_i * (c) + _k] = 0.; \ 7751a454edSToby Isaac for (_j = 0; _j < (n); _j++) { \ 78ad540459SPierre Jolivet for (_k = 0; _k < (c); _k++) (y)[_i * (c) + _k] += (A)[(_i * (n) + _j) * (c) + _k] * cast((b)[_j]); \ 7951a454edSToby Isaac } \ 8051a454edSToby Isaac } \ 8151a454edSToby Isaac } while (0) 8251a454edSToby Isaac 836858538eSMatthew G. Knepley /* 846858538eSMatthew G. Knepley Since this is used for coordinates, we need to allow for the possibility that values come from multiple sections/Vecs, so that we can have DG version of the coordinates for periodicity. This reproduces DMPlexGetCellCoordinates_Internal(). 856858538eSMatthew G. Knepley */ 8666976f2fSJacob Faibussowitsch static PetscErrorCode DMFieldGetClosure_Internal(DMField field, PetscInt cell, PetscBool *isDG, PetscInt *Nc, const PetscScalar *array[], PetscScalar *values[]) 87d71ae5a4SJacob Faibussowitsch { 886858538eSMatthew G. Knepley DMField_DS *dsfield = (DMField_DS *)field->data; 896858538eSMatthew G. Knepley DM fdm = dsfield->dmDG; 906858538eSMatthew G. Knepley PetscSection s = NULL; 916858538eSMatthew G. Knepley const PetscScalar *cvalues; 926858538eSMatthew G. Knepley PetscInt pStart, pEnd; 936858538eSMatthew G. Knepley 946858538eSMatthew G. Knepley PetscFunctionBeginHot; 956858538eSMatthew G. Knepley *isDG = PETSC_FALSE; 966858538eSMatthew G. Knepley *Nc = 0; 976858538eSMatthew G. Knepley *array = NULL; 986858538eSMatthew G. Knepley *values = NULL; 996858538eSMatthew G. Knepley /* Check for cellwise section */ 1006858538eSMatthew G. Knepley if (fdm) PetscCall(DMGetLocalSection(fdm, &s)); 1016858538eSMatthew G. Knepley if (!s) goto cg; 1026858538eSMatthew G. Knepley /* Check that the cell exists in the cellwise section */ 1036858538eSMatthew G. Knepley PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 1046858538eSMatthew G. Knepley if (cell < pStart || cell >= pEnd) goto cg; 1056858538eSMatthew G. Knepley /* Check for cellwise coordinates for this cell */ 1066858538eSMatthew G. Knepley PetscCall(PetscSectionGetDof(s, cell, Nc)); 1076858538eSMatthew G. Knepley if (!*Nc) goto cg; 1086858538eSMatthew G. Knepley /* Check for cellwise coordinates */ 1096858538eSMatthew G. Knepley if (!dsfield->vecDG) goto cg; 1106858538eSMatthew G. Knepley /* Get cellwise coordinates */ 1116858538eSMatthew G. Knepley PetscCall(VecGetArrayRead(dsfield->vecDG, array)); 1126858538eSMatthew G. Knepley PetscCall(DMPlexPointLocalRead(fdm, cell, *array, &cvalues)); 1136858538eSMatthew G. Knepley PetscCall(DMGetWorkArray(fdm, *Nc, MPIU_SCALAR, values)); 1146858538eSMatthew G. Knepley PetscCall(PetscArraycpy(*values, cvalues, *Nc)); 1156858538eSMatthew G. Knepley PetscCall(VecRestoreArrayRead(dsfield->vecDG, array)); 1166858538eSMatthew G. Knepley *isDG = PETSC_TRUE; 1173ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1186858538eSMatthew G. Knepley cg: 1196858538eSMatthew G. Knepley /* Use continuous values */ 1206858538eSMatthew G. Knepley PetscCall(DMFieldGetDM(field, &fdm)); 1216858538eSMatthew G. Knepley PetscCall(DMGetLocalSection(fdm, &s)); 1226267c18cSMatthew G. Knepley PetscCall(PetscSectionGetField(s, dsfield->fieldNum, &s)); 1236858538eSMatthew G. Knepley PetscCall(DMPlexVecGetClosure(fdm, s, dsfield->vec, cell, Nc, values)); 1243ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1256858538eSMatthew G. Knepley } 1266858538eSMatthew G. Knepley 12766976f2fSJacob Faibussowitsch static PetscErrorCode DMFieldRestoreClosure_Internal(DMField field, PetscInt cell, PetscBool *isDG, PetscInt *Nc, const PetscScalar *array[], PetscScalar *values[]) 128d71ae5a4SJacob Faibussowitsch { 1296858538eSMatthew G. Knepley DMField_DS *dsfield = (DMField_DS *)field->data; 1306858538eSMatthew G. Knepley DM fdm; 1316858538eSMatthew G. Knepley PetscSection s; 1326858538eSMatthew G. Knepley 1336858538eSMatthew G. Knepley PetscFunctionBeginHot; 1346858538eSMatthew G. Knepley if (*isDG) { 1356858538eSMatthew G. Knepley PetscCall(DMRestoreWorkArray(dsfield->dmDG, *Nc, MPIU_SCALAR, values)); 1366858538eSMatthew G. Knepley } else { 1376858538eSMatthew G. Knepley PetscCall(DMFieldGetDM(field, &fdm)); 1386858538eSMatthew G. Knepley PetscCall(DMGetLocalSection(fdm, &s)); 139835f2295SStefano Zampini PetscCall(DMPlexVecRestoreClosure(fdm, s, dsfield->vec, cell, Nc, values)); 1406858538eSMatthew G. Knepley } 1413ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1426858538eSMatthew G. Knepley } 1436858538eSMatthew G. Knepley 144ef0bb6c7SMatthew G. Knepley /* TODO: Reorganize interface so that I can reuse a tabulation rather than mallocing each time */ 145d71ae5a4SJacob Faibussowitsch static PetscErrorCode DMFieldEvaluateFE_DS(DMField field, IS pointIS, PetscQuadrature quad, PetscDataType type, void *B, void *D, void *H) 146d71ae5a4SJacob Faibussowitsch { 14751a454edSToby Isaac DMField_DS *dsfield = (DMField_DS *)field->data; 14851a454edSToby Isaac DM dm; 14951a454edSToby Isaac PetscObject disc; 15051a454edSToby Isaac PetscClassId classid; 151966bd95aSPierre Jolivet PetscInt nq, nc, dim, meshDim, numCells, feDim, i, K = H ? 2 : (D ? 1 : (B ? 0 : -1)); 15251a454edSToby Isaac PetscSection section; 15351a454edSToby Isaac const PetscReal *qpoints; 15451a454edSToby Isaac PetscBool isStride; 15551a454edSToby Isaac const PetscInt *points = NULL; 15651a454edSToby Isaac PetscInt sfirst = -1, stride = -1; 157966bd95aSPierre Jolivet PetscFE fe; 158966bd95aSPierre Jolivet PetscTabulation T; 15951a454edSToby Isaac 16051a454edSToby Isaac PetscFunctionBeginHot; 16151a454edSToby Isaac dm = field->dm; 16251a454edSToby Isaac nc = field->numComponents; 1639566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetData(quad, &dim, NULL, &nq, &qpoints, NULL)); 1646858538eSMatthew G. Knepley PetscCall(DMFieldDSGetHeightDisc(field, dsfield->height - 1 - dim, dsfield->disc, &disc)); 1659566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &meshDim)); 1669566063dSJacob Faibussowitsch PetscCall(DMGetLocalSection(dm, §ion)); 1679566063dSJacob Faibussowitsch PetscCall(PetscSectionGetField(section, dsfield->fieldNum, §ion)); 1689566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(disc, &classid)); 16951a454edSToby Isaac /* TODO: batch */ 1709566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)pointIS, ISSTRIDE, &isStride)); 1719566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(pointIS, &numCells)); 1721baa6e33SBarry Smith if (isStride) PetscCall(ISStrideGetInfo(pointIS, &sfirst, &stride)); 1731baa6e33SBarry Smith else PetscCall(ISGetIndices(pointIS, &points)); 174966bd95aSPierre Jolivet PetscCheck(classid == PETSCFE_CLASSID, PetscObjectComm((PetscObject)field), PETSC_ERR_SUP, "Not implemented"); 175966bd95aSPierre Jolivet fe = (PetscFE)disc; 1769566063dSJacob Faibussowitsch PetscCall(PetscFEGetDimension(fe, &feDim)); 1779566063dSJacob Faibussowitsch PetscCall(PetscFECreateTabulation(fe, 1, nq, qpoints, K, &T)); 17851a454edSToby Isaac for (i = 0; i < numCells; i++) { 17951a454edSToby Isaac PetscInt c = isStride ? (sfirst + i * stride) : points[i]; 1802710589cSToby Isaac PetscInt closureSize; 1816858538eSMatthew G. Knepley const PetscScalar *array; 1822710589cSToby Isaac PetscScalar *elem = NULL; 1836858538eSMatthew G. Knepley PetscBool isDG; 18451a454edSToby Isaac 1856858538eSMatthew G. Knepley PetscCall(DMFieldGetClosure_Internal(field, c, &isDG, &closureSize, &array, &elem)); 18651a454edSToby Isaac if (B) { 18762bd480fSMatthew G. Knepley /* field[c] = T[q,b,c] . coef[b], so v[c] = T[q,b,c] . coords[b] */ 18851a454edSToby Isaac if (type == PETSC_SCALAR) { 18951a454edSToby Isaac PetscScalar *cB = &((PetscScalar *)B)[nc * nq * i]; 19051a454edSToby Isaac 191ef0bb6c7SMatthew G. Knepley DMFieldDSdot(cB, T->T[0], elem, nq, feDim, nc, (PetscScalar)); 19251a454edSToby Isaac } else { 19351a454edSToby Isaac PetscReal *cB = &((PetscReal *)B)[nc * nq * i]; 19451a454edSToby Isaac 195ef0bb6c7SMatthew G. Knepley DMFieldDSdot(cB, T->T[0], elem, nq, feDim, nc, PetscRealPart); 19651a454edSToby Isaac } 19751a454edSToby Isaac } 19851a454edSToby Isaac if (D) { 19951a454edSToby Isaac if (type == PETSC_SCALAR) { 20051a454edSToby Isaac PetscScalar *cD = &((PetscScalar *)D)[nc * nq * dim * i]; 20151a454edSToby Isaac 202ef0bb6c7SMatthew G. Knepley DMFieldDSdot(cD, T->T[1], elem, nq, feDim, (nc * dim), (PetscScalar)); 20351a454edSToby Isaac } else { 20451a454edSToby Isaac PetscReal *cD = &((PetscReal *)D)[nc * nq * dim * i]; 20551a454edSToby Isaac 206ef0bb6c7SMatthew G. Knepley DMFieldDSdot(cD, T->T[1], elem, nq, feDim, (nc * dim), PetscRealPart); 20751a454edSToby Isaac } 20851a454edSToby Isaac } 20951a454edSToby Isaac if (H) { 21051a454edSToby Isaac if (type == PETSC_SCALAR) { 21151a454edSToby Isaac PetscScalar *cH = &((PetscScalar *)H)[nc * nq * dim * dim * i]; 21251a454edSToby Isaac 213ef0bb6c7SMatthew G. Knepley DMFieldDSdot(cH, T->T[2], elem, nq, feDim, (nc * dim * dim), (PetscScalar)); 21451a454edSToby Isaac } else { 21551a454edSToby Isaac PetscReal *cH = &((PetscReal *)H)[nc * nq * dim * dim * i]; 21651a454edSToby Isaac 217ef0bb6c7SMatthew G. Knepley DMFieldDSdot(cH, T->T[2], elem, nq, feDim, (nc * dim * dim), PetscRealPart); 21851a454edSToby Isaac } 21951a454edSToby Isaac } 2206858538eSMatthew G. Knepley PetscCall(DMFieldRestoreClosure_Internal(field, c, &isDG, &closureSize, &array, &elem)); 22151a454edSToby Isaac } 2229566063dSJacob Faibussowitsch PetscCall(PetscTabulationDestroy(&T)); 22348a46eb9SPierre Jolivet if (!isStride) PetscCall(ISRestoreIndices(pointIS, &points)); 2243ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 22551a454edSToby Isaac } 22651a454edSToby Isaac 227d71ae5a4SJacob Faibussowitsch static PetscErrorCode DMFieldEvaluate_DS(DMField field, Vec points, PetscDataType datatype, void *B, void *D, void *H) 228d71ae5a4SJacob Faibussowitsch { 229a6216909SToby Isaac DMField_DS *dsfield = (DMField_DS *)field->data; 230a6216909SToby Isaac PetscSF cellSF = NULL; 231a6216909SToby Isaac const PetscSFNode *cells; 232a6216909SToby Isaac PetscInt c, nFound, numCells, feDim, nc; 233a6216909SToby Isaac const PetscInt *cellDegrees; 234a6216909SToby Isaac const PetscScalar *pointsArray; 235a6216909SToby Isaac PetscScalar *cellPoints; 236a6216909SToby Isaac PetscInt gatherSize, gatherMax; 237a6216909SToby Isaac PetscInt dim, dimR, offset; 238a6216909SToby Isaac MPI_Datatype pointType; 239a6216909SToby Isaac PetscObject cellDisc; 240a6216909SToby Isaac PetscFE cellFE; 241a6216909SToby Isaac PetscClassId discID; 242a6216909SToby Isaac PetscReal *coordsReal, *coordsRef; 243a6216909SToby Isaac PetscSection section; 244a6216909SToby Isaac PetscScalar *cellBs = NULL, *cellDs = NULL, *cellHs = NULL; 245a6216909SToby Isaac PetscReal *cellBr = NULL, *cellDr = NULL, *cellHr = NULL; 2464cbe5319SToby Isaac PetscReal *v, *J, *invJ, *detJ; 247835f2295SStefano Zampini PetscMPIInt idim; 248a6216909SToby Isaac 249a6216909SToby Isaac PetscFunctionBegin; 250a6216909SToby Isaac nc = field->numComponents; 2519566063dSJacob Faibussowitsch PetscCall(DMGetLocalSection(field->dm, §ion)); 2526858538eSMatthew G. Knepley PetscCall(DMFieldDSGetHeightDisc(field, 0, dsfield->disc, &cellDisc)); 2539566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(cellDisc, &discID)); 25408401ef6SPierre Jolivet PetscCheck(discID == PETSCFE_CLASSID, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Discretization type not supported"); 255a6216909SToby Isaac cellFE = (PetscFE)cellDisc; 2569566063dSJacob Faibussowitsch PetscCall(PetscFEGetDimension(cellFE, &feDim)); 2579566063dSJacob Faibussowitsch PetscCall(DMGetCoordinateDim(field->dm, &dim)); 2589566063dSJacob Faibussowitsch PetscCall(DMGetDimension(field->dm, &dimR)); 2599566063dSJacob Faibussowitsch PetscCall(DMLocatePoints(field->dm, points, DM_POINTLOCATION_NONE, &cellSF)); 2609566063dSJacob Faibussowitsch PetscCall(PetscSFGetGraph(cellSF, &numCells, &nFound, NULL, &cells)); 261ad540459SPierre Jolivet for (c = 0; c < nFound; c++) PetscCheck(cells[c].index >= 0, PetscObjectComm((PetscObject)points), PETSC_ERR_ARG_WRONG, "Point %" PetscInt_FMT " could not be located", c); 2629566063dSJacob Faibussowitsch PetscCall(PetscSFComputeDegreeBegin(cellSF, &cellDegrees)); 2639566063dSJacob Faibussowitsch PetscCall(PetscSFComputeDegreeEnd(cellSF, &cellDegrees)); 264a6216909SToby Isaac for (c = 0, gatherSize = 0, gatherMax = 0; c < numCells; c++) { 265a6216909SToby Isaac gatherMax = PetscMax(gatherMax, cellDegrees[c]); 266a6216909SToby Isaac gatherSize += cellDegrees[c]; 267a6216909SToby Isaac } 2689566063dSJacob Faibussowitsch PetscCall(PetscMalloc3(gatherSize * dim, &cellPoints, gatherMax * dim, &coordsReal, gatherMax * dimR, &coordsRef)); 2699566063dSJacob Faibussowitsch PetscCall(PetscMalloc4(gatherMax * dimR, &v, gatherMax * dimR * dimR, &J, gatherMax * dimR * dimR, &invJ, gatherMax, &detJ)); 27032603206SJames Wright if (datatype == PETSC_SCALAR) PetscCall(PetscMalloc3((B ? (size_t)nc * gatherSize : 0), &cellBs, (D ? (size_t)nc * dim * gatherSize : 0), &cellDs, (H ? (size_t)nc * dim * dim * gatherSize : 0), &cellHs)); 27132603206SJames Wright else PetscCall(PetscMalloc3((B ? (size_t)nc * gatherSize : 0), &cellBr, (D ? (size_t)nc * dim * gatherSize : 0), &cellDr, (H ? (size_t)nc * dim * dim * gatherSize : 0), &cellHr)); 272a6216909SToby Isaac 273835f2295SStefano Zampini PetscCall(PetscMPIIntCast(dim, &idim)); 274835f2295SStefano Zampini PetscCallMPI(MPI_Type_contiguous(idim, MPIU_SCALAR, &pointType)); 2759566063dSJacob Faibussowitsch PetscCallMPI(MPI_Type_commit(&pointType)); 2769566063dSJacob Faibussowitsch PetscCall(VecGetArrayRead(points, &pointsArray)); 2779566063dSJacob Faibussowitsch PetscCall(PetscSFGatherBegin(cellSF, pointType, pointsArray, cellPoints)); 2789566063dSJacob Faibussowitsch PetscCall(PetscSFGatherEnd(cellSF, pointType, pointsArray, cellPoints)); 2799566063dSJacob Faibussowitsch PetscCall(VecRestoreArrayRead(points, &pointsArray)); 280a6216909SToby Isaac for (c = 0, offset = 0; c < numCells; c++) { 281a6216909SToby Isaac PetscInt nq = cellDegrees[c], p; 282a6216909SToby Isaac 283a6216909SToby Isaac if (nq) { 284ef0bb6c7SMatthew G. Knepley PetscInt K = H ? 2 : (D ? 1 : (B ? 0 : -1)); 285ef0bb6c7SMatthew G. Knepley PetscTabulation T; 2866858538eSMatthew G. Knepley PetscQuadrature quad; 2876858538eSMatthew G. Knepley const PetscScalar *array; 288a6216909SToby Isaac PetscScalar *elem = NULL; 2894cbe5319SToby Isaac PetscReal *quadPoints; 2906858538eSMatthew G. Knepley PetscBool isDG; 2916858538eSMatthew G. Knepley PetscInt closureSize, d, e, f, g; 292a6216909SToby Isaac 2934d1a973fSToby Isaac for (p = 0; p < dim * nq; p++) coordsReal[p] = PetscRealPart(cellPoints[dim * offset + p]); 2949566063dSJacob Faibussowitsch PetscCall(DMPlexCoordinatesToReference(field->dm, c, nq, coordsReal, coordsRef)); 2959566063dSJacob Faibussowitsch PetscCall(PetscFECreateTabulation(cellFE, 1, nq, coordsRef, K, &T)); 2969566063dSJacob Faibussowitsch PetscCall(PetscQuadratureCreate(PETSC_COMM_SELF, &quad)); 2979566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(dimR * nq, &quadPoints)); 2984cbe5319SToby Isaac for (p = 0; p < dimR * nq; p++) quadPoints[p] = coordsRef[p]; 2999566063dSJacob Faibussowitsch PetscCall(PetscQuadratureSetData(quad, dimR, 0, nq, quadPoints, NULL)); 3009566063dSJacob Faibussowitsch PetscCall(DMPlexComputeCellGeometryFEM(field->dm, c, quad, v, J, invJ, detJ)); 3019566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&quad)); 3026858538eSMatthew G. Knepley PetscCall(DMFieldGetClosure_Internal(field, c, &isDG, &closureSize, &array, &elem)); 303a6216909SToby Isaac if (B) { 304a6216909SToby Isaac if (datatype == PETSC_SCALAR) { 305a6216909SToby Isaac PetscScalar *cB = &cellBs[nc * offset]; 306a6216909SToby Isaac 307ef0bb6c7SMatthew G. Knepley DMFieldDSdot(cB, T->T[0], elem, nq, feDim, nc, (PetscScalar)); 308a6216909SToby Isaac } else { 309a6216909SToby Isaac PetscReal *cB = &cellBr[nc * offset]; 310a6216909SToby Isaac 311ef0bb6c7SMatthew G. Knepley DMFieldDSdot(cB, T->T[0], elem, nq, feDim, nc, PetscRealPart); 312a6216909SToby Isaac } 313a6216909SToby Isaac } 314a6216909SToby Isaac if (D) { 315a6216909SToby Isaac if (datatype == PETSC_SCALAR) { 316a6216909SToby Isaac PetscScalar *cD = &cellDs[nc * dim * offset]; 317a6216909SToby Isaac 318ef0bb6c7SMatthew G. Knepley DMFieldDSdot(cD, T->T[1], elem, nq, feDim, (nc * dim), (PetscScalar)); 3194cbe5319SToby Isaac for (p = 0; p < nq; p++) { 3204cbe5319SToby Isaac for (g = 0; g < nc; g++) { 3214d1a973fSToby Isaac PetscScalar vs[3]; 3224d1a973fSToby Isaac 3234cbe5319SToby Isaac for (d = 0; d < dimR; d++) { 3244d1a973fSToby Isaac vs[d] = 0.; 325ad540459SPierre Jolivet for (e = 0; e < dimR; e++) vs[d] += invJ[dimR * dimR * p + e * dimR + d] * cD[(nc * p + g) * dimR + e]; 3264cbe5319SToby Isaac } 327ad540459SPierre Jolivet for (d = 0; d < dimR; d++) cD[(nc * p + g) * dimR + d] = vs[d]; 3284cbe5319SToby Isaac } 3294cbe5319SToby Isaac } 330a6216909SToby Isaac } else { 331a6216909SToby Isaac PetscReal *cD = &cellDr[nc * dim * offset]; 332a6216909SToby Isaac 333ef0bb6c7SMatthew G. Knepley DMFieldDSdot(cD, T->T[1], elem, nq, feDim, (nc * dim), PetscRealPart); 3344cbe5319SToby Isaac for (p = 0; p < nq; p++) { 3354cbe5319SToby Isaac for (g = 0; g < nc; g++) { 3364cbe5319SToby Isaac for (d = 0; d < dimR; d++) { 3374cbe5319SToby Isaac v[d] = 0.; 338ad540459SPierre Jolivet for (e = 0; e < dimR; e++) v[d] += invJ[dimR * dimR * p + e * dimR + d] * cD[(nc * p + g) * dimR + e]; 3394cbe5319SToby Isaac } 340ad540459SPierre Jolivet for (d = 0; d < dimR; d++) cD[(nc * p + g) * dimR + d] = v[d]; 3414cbe5319SToby Isaac } 3424cbe5319SToby Isaac } 343a6216909SToby Isaac } 344a6216909SToby Isaac } 345a6216909SToby Isaac if (H) { 346a6216909SToby Isaac if (datatype == PETSC_SCALAR) { 347a6216909SToby Isaac PetscScalar *cH = &cellHs[nc * dim * dim * offset]; 348a6216909SToby Isaac 349ef0bb6c7SMatthew G. Knepley DMFieldDSdot(cH, T->T[2], elem, nq, feDim, (nc * dim * dim), (PetscScalar)); 3504cbe5319SToby Isaac for (p = 0; p < nq; p++) { 3514cbe5319SToby Isaac for (g = 0; g < nc * dimR; g++) { 3524d1a973fSToby Isaac PetscScalar vs[3]; 3534d1a973fSToby Isaac 3544cbe5319SToby Isaac for (d = 0; d < dimR; d++) { 3554d1a973fSToby Isaac vs[d] = 0.; 356ad540459SPierre Jolivet for (e = 0; e < dimR; e++) vs[d] += invJ[dimR * dimR * p + e * dimR + d] * cH[(nc * dimR * p + g) * dimR + e]; 3574cbe5319SToby Isaac } 358ad540459SPierre Jolivet for (d = 0; d < dimR; d++) cH[(nc * dimR * p + g) * dimR + d] = vs[d]; 3594cbe5319SToby Isaac } 3604cbe5319SToby Isaac for (g = 0; g < nc; g++) { 3614cbe5319SToby Isaac for (f = 0; f < dimR; f++) { 3624d1a973fSToby Isaac PetscScalar vs[3]; 3634d1a973fSToby Isaac 3644cbe5319SToby Isaac for (d = 0; d < dimR; d++) { 3654d1a973fSToby Isaac vs[d] = 0.; 366ad540459SPierre Jolivet for (e = 0; e < dimR; e++) vs[d] += invJ[dimR * dimR * p + e * dimR + d] * cH[((nc * p + g) * dimR + e) * dimR + f]; 3674cbe5319SToby Isaac } 368ad540459SPierre Jolivet for (d = 0; d < dimR; d++) cH[((nc * p + g) * dimR + d) * dimR + f] = vs[d]; 3694cbe5319SToby Isaac } 3704cbe5319SToby Isaac } 3714cbe5319SToby Isaac } 372a6216909SToby Isaac } else { 373a6216909SToby Isaac PetscReal *cH = &cellHr[nc * dim * dim * offset]; 374a6216909SToby Isaac 375ef0bb6c7SMatthew G. Knepley DMFieldDSdot(cH, T->T[2], elem, nq, feDim, (nc * dim * dim), PetscRealPart); 3764cbe5319SToby Isaac for (p = 0; p < nq; p++) { 3774cbe5319SToby Isaac for (g = 0; g < nc * dimR; g++) { 3784cbe5319SToby Isaac for (d = 0; d < dimR; d++) { 3794cbe5319SToby Isaac v[d] = 0.; 380ad540459SPierre Jolivet for (e = 0; e < dimR; e++) v[d] += invJ[dimR * dimR * p + e * dimR + d] * cH[(nc * dimR * p + g) * dimR + e]; 3814cbe5319SToby Isaac } 382ad540459SPierre Jolivet for (d = 0; d < dimR; d++) cH[(nc * dimR * p + g) * dimR + d] = v[d]; 3834cbe5319SToby Isaac } 3844cbe5319SToby Isaac for (g = 0; g < nc; g++) { 3854cbe5319SToby Isaac for (f = 0; f < dimR; f++) { 3864cbe5319SToby Isaac for (d = 0; d < dimR; d++) { 3874cbe5319SToby Isaac v[d] = 0.; 388ad540459SPierre Jolivet for (e = 0; e < dimR; e++) v[d] += invJ[dimR * dimR * p + e * dimR + d] * cH[((nc * p + g) * dimR + e) * dimR + f]; 3894cbe5319SToby Isaac } 390ad540459SPierre Jolivet for (d = 0; d < dimR; d++) cH[((nc * p + g) * dimR + d) * dimR + f] = v[d]; 3914cbe5319SToby Isaac } 3924cbe5319SToby Isaac } 3934cbe5319SToby Isaac } 394a6216909SToby Isaac } 395a6216909SToby Isaac } 3966858538eSMatthew G. Knepley PetscCall(DMFieldRestoreClosure_Internal(field, c, &isDG, &closureSize, &array, &elem)); 3979566063dSJacob Faibussowitsch PetscCall(PetscTabulationDestroy(&T)); 398a6216909SToby Isaac } 399a6216909SToby Isaac offset += nq; 400a6216909SToby Isaac } 401a6216909SToby Isaac { 402a6216909SToby Isaac MPI_Datatype origtype; 4034cbe5319SToby Isaac 404a6216909SToby Isaac if (datatype == PETSC_SCALAR) { 405a6216909SToby Isaac origtype = MPIU_SCALAR; 406a6216909SToby Isaac } else { 407a6216909SToby Isaac origtype = MPIU_REAL; 408a6216909SToby Isaac } 409a6216909SToby Isaac if (B) { 410a6216909SToby Isaac MPI_Datatype Btype; 411a6216909SToby Isaac 412835f2295SStefano Zampini PetscCall(PetscMPIIntCast(nc, &idim)); 413835f2295SStefano Zampini PetscCallMPI(MPI_Type_contiguous(idim, origtype, &Btype)); 4149566063dSJacob Faibussowitsch PetscCallMPI(MPI_Type_commit(&Btype)); 4159566063dSJacob Faibussowitsch PetscCall(PetscSFScatterBegin(cellSF, Btype, (datatype == PETSC_SCALAR) ? (void *)cellBs : (void *)cellBr, B)); 4169566063dSJacob Faibussowitsch PetscCall(PetscSFScatterEnd(cellSF, Btype, (datatype == PETSC_SCALAR) ? (void *)cellBs : (void *)cellBr, B)); 4179566063dSJacob Faibussowitsch PetscCallMPI(MPI_Type_free(&Btype)); 418a6216909SToby Isaac } 419a6216909SToby Isaac if (D) { 420a6216909SToby Isaac MPI_Datatype Dtype; 421a6216909SToby Isaac 422835f2295SStefano Zampini PetscCall(PetscMPIIntCast(nc * dim, &idim)); 423835f2295SStefano Zampini PetscCallMPI(MPI_Type_contiguous(idim, origtype, &Dtype)); 4249566063dSJacob Faibussowitsch PetscCallMPI(MPI_Type_commit(&Dtype)); 4259566063dSJacob Faibussowitsch PetscCall(PetscSFScatterBegin(cellSF, Dtype, (datatype == PETSC_SCALAR) ? (void *)cellDs : (void *)cellDr, D)); 4269566063dSJacob Faibussowitsch PetscCall(PetscSFScatterEnd(cellSF, Dtype, (datatype == PETSC_SCALAR) ? (void *)cellDs : (void *)cellDr, D)); 4279566063dSJacob Faibussowitsch PetscCallMPI(MPI_Type_free(&Dtype)); 428a6216909SToby Isaac } 429a6216909SToby Isaac if (H) { 430a6216909SToby Isaac MPI_Datatype Htype; 431a6216909SToby Isaac 432835f2295SStefano Zampini PetscCall(PetscMPIIntCast(nc * dim * dim, &idim)); 433835f2295SStefano Zampini PetscCallMPI(MPI_Type_contiguous(idim, origtype, &Htype)); 4349566063dSJacob Faibussowitsch PetscCallMPI(MPI_Type_commit(&Htype)); 4359566063dSJacob Faibussowitsch PetscCall(PetscSFScatterBegin(cellSF, Htype, (datatype == PETSC_SCALAR) ? (void *)cellHs : (void *)cellHr, H)); 4369566063dSJacob Faibussowitsch PetscCall(PetscSFScatterEnd(cellSF, Htype, (datatype == PETSC_SCALAR) ? (void *)cellHs : (void *)cellHr, H)); 4379566063dSJacob Faibussowitsch PetscCallMPI(MPI_Type_free(&Htype)); 438a6216909SToby Isaac } 439a6216909SToby Isaac } 4409566063dSJacob Faibussowitsch PetscCall(PetscFree4(v, J, invJ, detJ)); 4419566063dSJacob Faibussowitsch PetscCall(PetscFree3(cellBr, cellDr, cellHr)); 4429566063dSJacob Faibussowitsch PetscCall(PetscFree3(cellBs, cellDs, cellHs)); 4439566063dSJacob Faibussowitsch PetscCall(PetscFree3(cellPoints, coordsReal, coordsRef)); 4449566063dSJacob Faibussowitsch PetscCallMPI(MPI_Type_free(&pointType)); 4459566063dSJacob Faibussowitsch PetscCall(PetscSFDestroy(&cellSF)); 4463ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 447a6216909SToby Isaac } 448a6216909SToby Isaac 449d71ae5a4SJacob Faibussowitsch static PetscErrorCode DMFieldEvaluateFV_DS(DMField field, IS pointIS, PetscDataType type, void *B, void *D, void *H) 450d71ae5a4SJacob Faibussowitsch { 451805e7170SToby Isaac DMField_DS *dsfield = (DMField_DS *)field->data; 452805e7170SToby Isaac PetscInt h, imin; 453805e7170SToby Isaac PetscInt dim; 454805e7170SToby Isaac PetscClassId id; 455805e7170SToby Isaac PetscQuadrature quad = NULL; 456b7260050SToby Isaac PetscInt maxDegree; 457805e7170SToby Isaac PetscFEGeom *geom; 458805e7170SToby Isaac PetscInt Nq, Nc, dimC, qNc, N; 459805e7170SToby Isaac PetscInt numPoints; 460805e7170SToby Isaac void *qB = NULL, *qD = NULL, *qH = NULL; 461805e7170SToby Isaac const PetscReal *weights; 462805e7170SToby Isaac MPI_Datatype mpitype = type == PETSC_SCALAR ? MPIU_SCALAR : MPIU_REAL; 463805e7170SToby Isaac PetscObject disc; 464805e7170SToby Isaac DMField coordField; 465805e7170SToby Isaac 466805e7170SToby Isaac PetscFunctionBegin; 467805e7170SToby Isaac Nc = field->numComponents; 4689566063dSJacob Faibussowitsch PetscCall(DMGetCoordinateDim(field->dm, &dimC)); 4699566063dSJacob Faibussowitsch PetscCall(DMGetDimension(field->dm, &dim)); 4709566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(pointIS, &numPoints)); 4719566063dSJacob Faibussowitsch PetscCall(ISGetMinMax(pointIS, &imin, NULL)); 472805e7170SToby Isaac for (h = 0; h < dsfield->height; h++) { 473805e7170SToby Isaac PetscInt hEnd; 474805e7170SToby Isaac 4759566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(field->dm, h, NULL, &hEnd)); 476805e7170SToby Isaac if (imin < hEnd) break; 477805e7170SToby Isaac } 478805e7170SToby Isaac dim -= h; 4796858538eSMatthew G. Knepley PetscCall(DMFieldDSGetHeightDisc(field, h, dsfield->disc, &disc)); 4809566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(disc, &id)); 48108401ef6SPierre Jolivet PetscCheck(id == PETSCFE_CLASSID, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Discretization not supported"); 4829566063dSJacob Faibussowitsch PetscCall(DMGetCoordinateField(field->dm, &coordField)); 4839566063dSJacob Faibussowitsch PetscCall(DMFieldGetDegree(coordField, pointIS, NULL, &maxDegree)); 48448a46eb9SPierre Jolivet if (maxDegree <= 1) PetscCall(DMFieldCreateDefaultQuadrature(coordField, pointIS, &quad)); 4859566063dSJacob Faibussowitsch if (!quad) PetscCall(DMFieldCreateDefaultQuadrature(field, pointIS, &quad)); 48628b400f6SJacob Faibussowitsch PetscCheck(quad, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Could not determine quadrature for cell averages"); 487ac9d17c7SMatthew G. Knepley PetscCall(DMFieldCreateFEGeom(coordField, pointIS, quad, PETSC_FEGEOM_BASIC, &geom)); 4889566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetData(quad, NULL, &qNc, &Nq, NULL, &weights)); 48908401ef6SPierre Jolivet PetscCheck(qNc == 1, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Expected scalar quadrature components"); 490805e7170SToby Isaac N = numPoints * Nq * Nc; 4919566063dSJacob Faibussowitsch if (B) PetscCall(DMGetWorkArray(field->dm, N, mpitype, &qB)); 4929566063dSJacob Faibussowitsch if (D) PetscCall(DMGetWorkArray(field->dm, N * dimC, mpitype, &qD)); 4939566063dSJacob Faibussowitsch if (H) PetscCall(DMGetWorkArray(field->dm, N * dimC * dimC, mpitype, &qH)); 4949566063dSJacob Faibussowitsch PetscCall(DMFieldEvaluateFE(field, pointIS, quad, type, qB, qD, qH)); 495805e7170SToby Isaac if (B) { 496805e7170SToby Isaac PetscInt i, j, k; 497805e7170SToby Isaac 498805e7170SToby Isaac if (type == PETSC_SCALAR) { 499805e7170SToby Isaac PetscScalar *sB = (PetscScalar *)B; 500805e7170SToby Isaac PetscScalar *sqB = (PetscScalar *)qB; 501805e7170SToby Isaac 502805e7170SToby Isaac for (i = 0; i < numPoints; i++) { 503805e7170SToby Isaac PetscReal vol = 0.; 504805e7170SToby Isaac 505ad540459SPierre Jolivet for (j = 0; j < Nc; j++) sB[i * Nc + j] = 0.; 506805e7170SToby Isaac for (k = 0; k < Nq; k++) { 507805e7170SToby Isaac vol += geom->detJ[i * Nq + k] * weights[k]; 508ad540459SPierre Jolivet for (j = 0; j < Nc; j++) sB[i * Nc + j] += geom->detJ[i * Nq + k] * weights[k] * sqB[(i * Nq + k) * Nc + j]; 509805e7170SToby Isaac } 51062bd480fSMatthew G. Knepley for (k = 0; k < Nc; k++) sB[i * Nc + k] /= vol; 511805e7170SToby Isaac } 512805e7170SToby Isaac } else { 513805e7170SToby Isaac PetscReal *rB = (PetscReal *)B; 514805e7170SToby Isaac PetscReal *rqB = (PetscReal *)qB; 515805e7170SToby Isaac 516805e7170SToby Isaac for (i = 0; i < numPoints; i++) { 517805e7170SToby Isaac PetscReal vol = 0.; 518805e7170SToby Isaac 519ad540459SPierre Jolivet for (j = 0; j < Nc; j++) rB[i * Nc + j] = 0.; 520805e7170SToby Isaac for (k = 0; k < Nq; k++) { 521805e7170SToby Isaac vol += geom->detJ[i * Nq + k] * weights[k]; 522ad540459SPierre Jolivet for (j = 0; j < Nc; j++) rB[i * Nc + j] += weights[k] * rqB[(i * Nq + k) * Nc + j]; 523805e7170SToby Isaac } 524805e7170SToby Isaac for (k = 0; k < Nc; k++) rB[i * Nc + k] /= vol; 525805e7170SToby Isaac } 526805e7170SToby Isaac } 527805e7170SToby Isaac } 528805e7170SToby Isaac if (D) { 529805e7170SToby Isaac PetscInt i, j, k, l, m; 530805e7170SToby Isaac 531805e7170SToby Isaac if (type == PETSC_SCALAR) { 532805e7170SToby Isaac PetscScalar *sD = (PetscScalar *)D; 533805e7170SToby Isaac PetscScalar *sqD = (PetscScalar *)qD; 534805e7170SToby Isaac 535805e7170SToby Isaac for (i = 0; i < numPoints; i++) { 536805e7170SToby Isaac PetscReal vol = 0.; 537805e7170SToby Isaac 538ad540459SPierre Jolivet for (j = 0; j < Nc * dimC; j++) sD[i * Nc * dimC + j] = 0.; 539805e7170SToby Isaac for (k = 0; k < Nq; k++) { 540805e7170SToby Isaac vol += geom->detJ[i * Nq + k] * weights[k]; 541805e7170SToby Isaac for (j = 0; j < Nc; j++) { 542805e7170SToby Isaac PetscScalar pD[3] = {0., 0., 0.}; 543805e7170SToby Isaac 544805e7170SToby Isaac for (l = 0; l < dimC; l++) { 545ad540459SPierre Jolivet for (m = 0; m < dim; m++) pD[l] += geom->invJ[((i * Nq + k) * dimC + m) * dimC + l] * sqD[((i * Nq + k) * Nc + j) * dim + m]; 546805e7170SToby Isaac } 547ad540459SPierre Jolivet for (l = 0; l < dimC; l++) sD[(i * Nc + j) * dimC + l] += geom->detJ[i * Nq + k] * weights[k] * pD[l]; 548805e7170SToby Isaac } 549805e7170SToby Isaac } 550805e7170SToby Isaac for (k = 0; k < Nc * dimC; k++) sD[i * Nc * dimC + k] /= vol; 551805e7170SToby Isaac } 552805e7170SToby Isaac } else { 553805e7170SToby Isaac PetscReal *rD = (PetscReal *)D; 554805e7170SToby Isaac PetscReal *rqD = (PetscReal *)qD; 555805e7170SToby Isaac 556805e7170SToby Isaac for (i = 0; i < numPoints; i++) { 557805e7170SToby Isaac PetscReal vol = 0.; 558805e7170SToby Isaac 559ad540459SPierre Jolivet for (j = 0; j < Nc * dimC; j++) rD[i * Nc * dimC + j] = 0.; 560805e7170SToby Isaac for (k = 0; k < Nq; k++) { 561805e7170SToby Isaac vol += geom->detJ[i * Nq + k] * weights[k]; 562805e7170SToby Isaac for (j = 0; j < Nc; j++) { 563805e7170SToby Isaac PetscReal pD[3] = {0., 0., 0.}; 564805e7170SToby Isaac 565805e7170SToby Isaac for (l = 0; l < dimC; l++) { 566ad540459SPierre Jolivet for (m = 0; m < dim; m++) pD[l] += geom->invJ[((i * Nq + k) * dimC + m) * dimC + l] * rqD[((i * Nq + k) * Nc + j) * dim + m]; 567805e7170SToby Isaac } 568ad540459SPierre Jolivet for (l = 0; l < dimC; l++) rD[(i * Nc + j) * dimC + l] += geom->detJ[i * Nq + k] * weights[k] * pD[l]; 569805e7170SToby Isaac } 570805e7170SToby Isaac } 571805e7170SToby Isaac for (k = 0; k < Nc * dimC; k++) rD[i * Nc * dimC + k] /= vol; 572805e7170SToby Isaac } 573805e7170SToby Isaac } 574805e7170SToby Isaac } 575805e7170SToby Isaac if (H) { 576805e7170SToby Isaac PetscInt i, j, k, l, m, q, r; 577805e7170SToby Isaac 578805e7170SToby Isaac if (type == PETSC_SCALAR) { 579805e7170SToby Isaac PetscScalar *sH = (PetscScalar *)H; 580805e7170SToby Isaac PetscScalar *sqH = (PetscScalar *)qH; 581805e7170SToby Isaac 582805e7170SToby Isaac for (i = 0; i < numPoints; i++) { 583805e7170SToby Isaac PetscReal vol = 0.; 584805e7170SToby Isaac 585ad540459SPierre Jolivet for (j = 0; j < Nc * dimC * dimC; j++) sH[i * Nc * dimC * dimC + j] = 0.; 586805e7170SToby Isaac for (k = 0; k < Nq; k++) { 5874d1a973fSToby Isaac const PetscReal *invJ = &geom->invJ[(i * Nq + k) * dimC * dimC]; 588805e7170SToby Isaac 589805e7170SToby Isaac vol += geom->detJ[i * Nq + k] * weights[k]; 590805e7170SToby Isaac for (j = 0; j < Nc; j++) { 5919371c9d4SSatish Balay PetscScalar pH[3][3] = { 5929371c9d4SSatish Balay {0., 0., 0.}, 5939371c9d4SSatish Balay {0., 0., 0.}, 5949371c9d4SSatish Balay {0., 0., 0.} 5959371c9d4SSatish Balay }; 596805e7170SToby Isaac const PetscScalar *spH = &sqH[((i * Nq + k) * Nc + j) * dimC * dimC]; 597805e7170SToby Isaac 598805e7170SToby Isaac for (l = 0; l < dimC; l++) { 599805e7170SToby Isaac for (m = 0; m < dimC; m++) { 600805e7170SToby Isaac for (q = 0; q < dim; q++) { 601ad540459SPierre Jolivet for (r = 0; r < dim; r++) pH[l][m] += invJ[q * dimC + l] * invJ[r * dimC + m] * spH[q * dim + r]; 602805e7170SToby Isaac } 603805e7170SToby Isaac } 604805e7170SToby Isaac } 605805e7170SToby Isaac for (l = 0; l < dimC; l++) { 606ad540459SPierre Jolivet for (m = 0; m < dimC; m++) sH[(i * Nc + j) * dimC * dimC + l * dimC + m] += geom->detJ[i * Nq + k] * weights[k] * pH[l][m]; 607805e7170SToby Isaac } 608805e7170SToby Isaac } 609805e7170SToby Isaac } 610805e7170SToby Isaac for (k = 0; k < Nc * dimC * dimC; k++) sH[i * Nc * dimC * dimC + k] /= vol; 611805e7170SToby Isaac } 612805e7170SToby Isaac } else { 613805e7170SToby Isaac PetscReal *rH = (PetscReal *)H; 614805e7170SToby Isaac PetscReal *rqH = (PetscReal *)qH; 615805e7170SToby Isaac 616805e7170SToby Isaac for (i = 0; i < numPoints; i++) { 617805e7170SToby Isaac PetscReal vol = 0.; 618805e7170SToby Isaac 619ad540459SPierre Jolivet for (j = 0; j < Nc * dimC * dimC; j++) rH[i * Nc * dimC * dimC + j] = 0.; 620805e7170SToby Isaac for (k = 0; k < Nq; k++) { 621805e7170SToby Isaac const PetscReal *invJ = &geom->invJ[(i * Nq + k) * dimC * dimC]; 622805e7170SToby Isaac 623805e7170SToby Isaac vol += geom->detJ[i * Nq + k] * weights[k]; 624805e7170SToby Isaac for (j = 0; j < Nc; j++) { 6259371c9d4SSatish Balay PetscReal pH[3][3] = { 6269371c9d4SSatish Balay {0., 0., 0.}, 6279371c9d4SSatish Balay {0., 0., 0.}, 6289371c9d4SSatish Balay {0., 0., 0.} 6299371c9d4SSatish Balay }; 630805e7170SToby Isaac const PetscReal *rpH = &rqH[((i * Nq + k) * Nc + j) * dimC * dimC]; 631805e7170SToby Isaac 632805e7170SToby Isaac for (l = 0; l < dimC; l++) { 633805e7170SToby Isaac for (m = 0; m < dimC; m++) { 634805e7170SToby Isaac for (q = 0; q < dim; q++) { 635ad540459SPierre Jolivet for (r = 0; r < dim; r++) pH[l][m] += invJ[q * dimC + l] * invJ[r * dimC + m] * rpH[q * dim + r]; 636805e7170SToby Isaac } 637805e7170SToby Isaac } 638805e7170SToby Isaac } 639805e7170SToby Isaac for (l = 0; l < dimC; l++) { 640ad540459SPierre Jolivet for (m = 0; m < dimC; m++) rH[(i * Nc + j) * dimC * dimC + l * dimC + m] += geom->detJ[i * Nq + k] * weights[k] * pH[l][m]; 641805e7170SToby Isaac } 642805e7170SToby Isaac } 643805e7170SToby Isaac } 644805e7170SToby Isaac for (k = 0; k < Nc * dimC * dimC; k++) rH[i * Nc * dimC * dimC + k] /= vol; 645805e7170SToby Isaac } 646805e7170SToby Isaac } 647805e7170SToby Isaac } 6489566063dSJacob Faibussowitsch if (B) PetscCall(DMRestoreWorkArray(field->dm, N, mpitype, &qB)); 6499566063dSJacob Faibussowitsch if (D) PetscCall(DMRestoreWorkArray(field->dm, N * dimC, mpitype, &qD)); 6509566063dSJacob Faibussowitsch if (H) PetscCall(DMRestoreWorkArray(field->dm, N * dimC * dimC, mpitype, &qH)); 6519566063dSJacob Faibussowitsch PetscCall(PetscFEGeomDestroy(&geom)); 6529566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&quad)); 6533ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 654805e7170SToby Isaac } 655805e7170SToby Isaac 656d71ae5a4SJacob Faibussowitsch static PetscErrorCode DMFieldGetDegree_DS(DMField field, IS pointIS, PetscInt *minDegree, PetscInt *maxDegree) 657d71ae5a4SJacob Faibussowitsch { 65851a454edSToby Isaac DMField_DS *dsfield; 65951a454edSToby Isaac PetscObject disc; 660741db25dSToby Isaac PetscInt h, imin, imax; 66151a454edSToby Isaac PetscClassId id; 66251a454edSToby Isaac 66351a454edSToby Isaac PetscFunctionBegin; 66451a454edSToby Isaac dsfield = (DMField_DS *)field->data; 6659566063dSJacob Faibussowitsch PetscCall(ISGetMinMax(pointIS, &imin, &imax)); 666741db25dSToby Isaac if (imin >= imax) { 66751aa0bf7SToby Isaac h = 0; 66851aa0bf7SToby Isaac } else { 669f99c8401SToby Isaac for (h = 0; h < dsfield->height; h++) { 67051a454edSToby Isaac PetscInt hEnd; 67151a454edSToby Isaac 6729566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(field->dm, h, NULL, &hEnd)); 67351a454edSToby Isaac if (imin < hEnd) break; 67451a454edSToby Isaac } 67551aa0bf7SToby Isaac } 6766858538eSMatthew G. Knepley PetscCall(DMFieldDSGetHeightDisc(field, h, dsfield->disc, &disc)); 6779566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(disc, &id)); 67851a454edSToby Isaac if (id == PETSCFE_CLASSID) { 67951a454edSToby Isaac PetscFE fe = (PetscFE)disc; 68051a454edSToby Isaac PetscSpace sp; 68151a454edSToby Isaac 6829566063dSJacob Faibussowitsch PetscCall(PetscFEGetBasisSpace(fe, &sp)); 6839566063dSJacob Faibussowitsch PetscCall(PetscSpaceGetDegree(sp, minDegree, maxDegree)); 68451a454edSToby Isaac } 6853ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 68651a454edSToby Isaac } 68751a454edSToby Isaac 688d71ae5a4SJacob Faibussowitsch PetscErrorCode DMFieldGetFVQuadrature_Internal(DMField field, IS pointIS, PetscQuadrature *quad) 689d71ae5a4SJacob Faibussowitsch { 690a2aba86cSMatthew G. Knepley DM dm = field->dm; 691a2aba86cSMatthew G. Knepley const PetscInt *points; 692a2aba86cSMatthew G. Knepley DMPolytopeType ct; 693a2aba86cSMatthew G. Knepley PetscInt dim, n; 694a2aba86cSMatthew G. Knepley PetscBool isplex; 695a2aba86cSMatthew G. Knepley 696a2aba86cSMatthew G. Knepley PetscFunctionBegin; 6979566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)dm, DMPLEX, &isplex)); 6989566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(pointIS, &n)); 699a2aba86cSMatthew G. Knepley if (isplex && n) { 7009566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim)); 7019566063dSJacob Faibussowitsch PetscCall(ISGetIndices(pointIS, &points)); 7029566063dSJacob Faibussowitsch PetscCall(DMPlexGetCellType(dm, points[0], &ct)); 703a2aba86cSMatthew G. Knepley switch (ct) { 704a2aba86cSMatthew G. Knepley case DM_POLYTOPE_TRIANGLE: 705d71ae5a4SJacob Faibussowitsch case DM_POLYTOPE_TETRAHEDRON: 706d71ae5a4SJacob Faibussowitsch PetscCall(PetscDTStroudConicalQuadrature(dim, 1, 1, -1.0, 1.0, quad)); 707d71ae5a4SJacob Faibussowitsch break; 708d71ae5a4SJacob Faibussowitsch default: 709d71ae5a4SJacob Faibussowitsch PetscCall(PetscDTGaussTensorQuadrature(dim, 1, 1, -1.0, 1.0, quad)); 710a2aba86cSMatthew G. Knepley } 7119566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(pointIS, &points)); 7121baa6e33SBarry Smith } else PetscCall(DMFieldCreateDefaultQuadrature(field, pointIS, quad)); 7133ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 714a2aba86cSMatthew G. Knepley } 715a2aba86cSMatthew G. Knepley 716d71ae5a4SJacob Faibussowitsch static PetscErrorCode DMFieldCreateDefaultQuadrature_DS(DMField field, IS pointIS, PetscQuadrature *quad) 717d71ae5a4SJacob Faibussowitsch { 7181fdf1f07SMatthew G. Knepley PetscInt h, dim, imax, imin, cellHeight; 71951a454edSToby Isaac DM dm; 72051a454edSToby Isaac DMField_DS *dsfield; 72151a454edSToby Isaac PetscObject disc; 72251a454edSToby Isaac PetscFE fe; 72351a454edSToby Isaac PetscClassId id; 72451a454edSToby Isaac 72551a454edSToby Isaac PetscFunctionBegin; 72651a454edSToby Isaac dm = field->dm; 72751a454edSToby Isaac dsfield = (DMField_DS *)field->data; 7289566063dSJacob Faibussowitsch PetscCall(ISGetMinMax(pointIS, &imin, &imax)); 7299566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim)); 73051a454edSToby Isaac for (h = 0; h <= dim; h++) { 73151a454edSToby Isaac PetscInt hStart, hEnd; 73251a454edSToby Isaac 7339566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(dm, h, &hStart, &hEnd)); 7346c041b70SSatish Balay if (imax >= hStart && imin < hEnd) break; 73551a454edSToby Isaac } 7369566063dSJacob Faibussowitsch PetscCall(DMPlexGetVTKCellHeight(dm, &cellHeight)); 7371fdf1f07SMatthew G. Knepley h -= cellHeight; 73851a454edSToby Isaac *quad = NULL; 739f99c8401SToby Isaac if (h < dsfield->height) { 7406858538eSMatthew G. Knepley PetscCall(DMFieldDSGetHeightDisc(field, h, dsfield->disc, &disc)); 7419566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(disc, &id)); 7423ba16761SJacob Faibussowitsch if (id != PETSCFE_CLASSID) PetscFunctionReturn(PETSC_SUCCESS); 74351a454edSToby Isaac fe = (PetscFE)disc; 7449566063dSJacob Faibussowitsch PetscCall(PetscFEGetQuadrature(fe, quad)); 7459566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)*quad)); 74651a454edSToby Isaac } 7473ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 74851a454edSToby Isaac } 74951a454edSToby Isaac 750989fa639SBrad Aagaard static PetscErrorCode DMFieldCreateDefaultFaceQuadrature_DS(DMField field, IS pointIS, PetscQuadrature *quad) 751989fa639SBrad Aagaard { 752989fa639SBrad Aagaard PetscInt h, dim, imax, imin, cellHeight; 753989fa639SBrad Aagaard DM dm; 754989fa639SBrad Aagaard DMField_DS *dsfield; 755989fa639SBrad Aagaard PetscObject disc; 756989fa639SBrad Aagaard PetscFE fe; 757989fa639SBrad Aagaard PetscClassId id; 758989fa639SBrad Aagaard 759989fa639SBrad Aagaard PetscFunctionBegin; 760989fa639SBrad Aagaard dm = field->dm; 761989fa639SBrad Aagaard dsfield = (DMField_DS *)field->data; 762989fa639SBrad Aagaard PetscCall(ISGetMinMax(pointIS, &imin, &imax)); 763989fa639SBrad Aagaard PetscCall(DMGetDimension(dm, &dim)); 764989fa639SBrad Aagaard for (h = 0; h <= dim; h++) { 765989fa639SBrad Aagaard PetscInt hStart, hEnd; 766989fa639SBrad Aagaard 767989fa639SBrad Aagaard PetscCall(DMPlexGetHeightStratum(dm, h, &hStart, &hEnd)); 768989fa639SBrad Aagaard if (imax >= hStart && imin < hEnd) break; 769989fa639SBrad Aagaard } 770989fa639SBrad Aagaard PetscCall(DMPlexGetVTKCellHeight(dm, &cellHeight)); 771989fa639SBrad Aagaard h -= cellHeight; 772989fa639SBrad Aagaard *quad = NULL; 773989fa639SBrad Aagaard if (h < dsfield->height) { 774989fa639SBrad Aagaard PetscQuadrature fq; 775989fa639SBrad Aagaard 776989fa639SBrad Aagaard PetscCall(DMFieldDSGetHeightDisc(field, h, dsfield->disc, &disc)); 777989fa639SBrad Aagaard PetscCall(PetscObjectGetClassId(disc, &id)); 778989fa639SBrad Aagaard if (id != PETSCFE_CLASSID) PetscFunctionReturn(PETSC_SUCCESS); 779989fa639SBrad Aagaard fe = (PetscFE)disc; 780989fa639SBrad Aagaard PetscCall(PetscFEGetFaceQuadrature(fe, &fq)); 781989fa639SBrad Aagaard PetscCall(PetscFEExpandFaceQuadrature(fe, fq, quad)); 782989fa639SBrad Aagaard } 783989fa639SBrad Aagaard PetscFunctionReturn(PETSC_SUCCESS); 784989fa639SBrad Aagaard } 785989fa639SBrad Aagaard 786d71ae5a4SJacob Faibussowitsch static PetscErrorCode DMFieldComputeFaceData_DS(DMField field, IS pointIS, PetscQuadrature quad, PetscFEGeom *geom) 787d71ae5a4SJacob Faibussowitsch { 7880145028aSToby Isaac const PetscInt *points; 7890145028aSToby Isaac PetscInt p, dim, dE, numFaces, Nq; 790b7260050SToby Isaac PetscInt maxDegree; 7910145028aSToby Isaac DMLabel depthLabel; 7920145028aSToby Isaac IS cellIS; 7930145028aSToby Isaac DM dm = field->dm; 7940145028aSToby Isaac 7950145028aSToby Isaac PetscFunctionBegin; 7960145028aSToby Isaac dim = geom->dim; 7970145028aSToby Isaac dE = geom->dimEmbed; 7989566063dSJacob Faibussowitsch PetscCall(DMPlexGetDepthLabel(dm, &depthLabel)); 7999566063dSJacob Faibussowitsch PetscCall(DMLabelGetStratumIS(depthLabel, dim + 1, &cellIS)); 8009566063dSJacob Faibussowitsch PetscCall(DMFieldGetDegree(field, cellIS, NULL, &maxDegree)); 8019566063dSJacob Faibussowitsch PetscCall(ISGetIndices(pointIS, &points)); 8020145028aSToby Isaac numFaces = geom->numCells; 8030145028aSToby Isaac Nq = geom->numPoints; 804f15274beSMatthew Knepley /* First, set local faces and flip normals so that they are outward for the first supporting cell */ 805f15274beSMatthew Knepley for (p = 0; p < numFaces; p++) { 806f15274beSMatthew Knepley PetscInt point = points[p]; 807f15274beSMatthew Knepley PetscInt suppSize, s, coneSize, c, numChildren; 8080e18dc48SMatthew G. Knepley const PetscInt *supp; 809f15274beSMatthew Knepley 8109566063dSJacob Faibussowitsch PetscCall(DMPlexGetTreeChildren(dm, point, &numChildren, NULL)); 81128b400f6SJacob Faibussowitsch PetscCheck(!numChildren, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Face data not valid for facets with children"); 8129566063dSJacob Faibussowitsch PetscCall(DMPlexGetSupportSize(dm, point, &suppSize)); 81363a3b9bcSJacob Faibussowitsch PetscCheck(suppSize <= 2, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Point %" PetscInt_FMT " has %" PetscInt_FMT " support, expected at most 2", point, suppSize); 814f15274beSMatthew Knepley if (!suppSize) continue; 8159566063dSJacob Faibussowitsch PetscCall(DMPlexGetSupport(dm, point, &supp)); 816f15274beSMatthew Knepley for (s = 0; s < suppSize; ++s) { 8170e18dc48SMatthew G. Knepley const PetscInt *cone, *ornt; 8180e18dc48SMatthew G. Knepley 8199566063dSJacob Faibussowitsch PetscCall(DMPlexGetConeSize(dm, supp[s], &coneSize)); 8200e18dc48SMatthew G. Knepley PetscCall(DMPlexGetOrientedCone(dm, supp[s], &cone, &ornt)); 8219371c9d4SSatish Balay for (c = 0; c < coneSize; ++c) 8229371c9d4SSatish Balay if (cone[c] == point) break; 8230e18dc48SMatthew G. Knepley geom->face[p][s * 2 + 0] = c; 8240e18dc48SMatthew G. Knepley geom->face[p][s * 2 + 1] = ornt[c]; 82584cbd072SMatthew G. Knepley PetscCall(DMPlexRestoreOrientedCone(dm, supp[s], &cone, &ornt)); 82684cbd072SMatthew G. Knepley PetscCheck(c != coneSize, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Invalid connectivity: point %" PetscInt_FMT " not found in cone of support point %" PetscInt_FMT, point, supp[s]); 827f15274beSMatthew Knepley } 8280e18dc48SMatthew G. Knepley if (geom->face[p][1] < 0) { 829f15274beSMatthew Knepley PetscInt Np = geom->numPoints, q, dE = geom->dimEmbed, d; 830f15274beSMatthew Knepley 8319371c9d4SSatish Balay for (q = 0; q < Np; ++q) 8329371c9d4SSatish Balay for (d = 0; d < dE; ++d) geom->n[(p * Np + q) * dE + d] = -geom->n[(p * Np + q) * dE + d]; 833f15274beSMatthew Knepley } 834f15274beSMatthew Knepley } 835b7260050SToby Isaac if (maxDegree <= 1) { 836313f16f2SMatthew G. Knepley PetscQuadrature cellQuad = NULL; 8370145028aSToby Isaac PetscInt numCells, offset, *cells; 8380145028aSToby Isaac PetscFEGeom *cellGeom; 8390145028aSToby Isaac IS suppIS; 8400145028aSToby Isaac 841313f16f2SMatthew G. Knepley if (quad) { 842313f16f2SMatthew G. Knepley DM dm; 843313f16f2SMatthew G. Knepley PetscReal *points, *weights; 844313f16f2SMatthew G. Knepley PetscInt tdim, Nc, Np; 845313f16f2SMatthew G. Knepley 846313f16f2SMatthew G. Knepley PetscCall(DMFieldGetDM(field, &dm)); 847313f16f2SMatthew G. Knepley PetscCall(DMGetDimension(dm, &tdim)); 848313f16f2SMatthew G. Knepley if (tdim > dim) { 849313f16f2SMatthew G. Knepley // Make a compatible cell quadrature (points don't matter since its affine) 850313f16f2SMatthew G. Knepley PetscCall(PetscQuadratureCreate(PETSC_COMM_SELF, &cellQuad)); 851313f16f2SMatthew G. Knepley PetscCall(PetscQuadratureGetData(quad, NULL, &Nc, &Np, NULL, NULL)); 852313f16f2SMatthew G. Knepley PetscCall(PetscCalloc1((dim + 1) * Np, &points)); 853313f16f2SMatthew G. Knepley PetscCall(PetscCalloc1(Nc * Np, &weights)); 854313f16f2SMatthew G. Knepley PetscCall(PetscQuadratureSetData(cellQuad, dim + 1, Nc, Np, points, weights)); 855313f16f2SMatthew G. Knepley } else { 856313f16f2SMatthew G. Knepley // TODO J will be wrong here, but other things need to be fixed 857313f16f2SMatthew G. Knepley // This path comes from calling DMProjectBdFieldLabelLocal() in Plex ex5 858313f16f2SMatthew G. Knepley PetscCall(PetscObjectReference((PetscObject)quad)); 859313f16f2SMatthew G. Knepley cellQuad = quad; 860313f16f2SMatthew G. Knepley } 861313f16f2SMatthew G. Knepley } 8620145028aSToby Isaac for (p = 0, numCells = 0; p < numFaces; p++) { 8630145028aSToby Isaac PetscInt point = points[p]; 8640145028aSToby Isaac PetscInt numSupp, numChildren; 8650145028aSToby Isaac 8669566063dSJacob Faibussowitsch PetscCall(DMPlexGetTreeChildren(dm, point, &numChildren, NULL)); 86728b400f6SJacob Faibussowitsch PetscCheck(!numChildren, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Face data not valid for facets with children"); 8689566063dSJacob Faibussowitsch PetscCall(DMPlexGetSupportSize(dm, point, &numSupp)); 86963a3b9bcSJacob Faibussowitsch PetscCheck(numSupp <= 2, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Point %" PetscInt_FMT " has %" PetscInt_FMT " support, expected at most 2", point, numSupp); 8700145028aSToby Isaac numCells += numSupp; 8710145028aSToby Isaac } 8729566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(numCells, &cells)); 8730145028aSToby Isaac for (p = 0, offset = 0; p < numFaces; p++) { 8740145028aSToby Isaac PetscInt point = points[p]; 8750145028aSToby Isaac PetscInt numSupp, s; 8760145028aSToby Isaac const PetscInt *supp; 8770145028aSToby Isaac 8789566063dSJacob Faibussowitsch PetscCall(DMPlexGetSupportSize(dm, point, &numSupp)); 8799566063dSJacob Faibussowitsch PetscCall(DMPlexGetSupport(dm, point, &supp)); 880ad540459SPierre Jolivet for (s = 0; s < numSupp; s++, offset++) cells[offset] = supp[s]; 8810145028aSToby Isaac } 8829566063dSJacob Faibussowitsch PetscCall(ISCreateGeneral(PETSC_COMM_SELF, numCells, cells, PETSC_USE_POINTER, &suppIS)); 883ac9d17c7SMatthew G. Knepley PetscCall(DMFieldCreateFEGeom(field, suppIS, cellQuad, PETSC_FEGEOM_BASIC, &cellGeom)); 8840145028aSToby Isaac for (p = 0, offset = 0; p < numFaces; p++) { 8850145028aSToby Isaac PetscInt point = points[p]; 8860145028aSToby Isaac PetscInt numSupp, s, q; 8870145028aSToby Isaac const PetscInt *supp; 8880145028aSToby Isaac 8899566063dSJacob Faibussowitsch PetscCall(DMPlexGetSupportSize(dm, point, &numSupp)); 8909566063dSJacob Faibussowitsch PetscCall(DMPlexGetSupport(dm, point, &supp)); 8910145028aSToby Isaac for (s = 0; s < numSupp; s++, offset++) { 8920145028aSToby Isaac for (q = 0; q < Nq * dE * dE; q++) { 89341418987SMatthew G. Knepley geom->suppJ[s][p * Nq * dE * dE + q] = cellGeom->J[offset * Nq * dE * dE + q]; 8940145028aSToby Isaac geom->suppInvJ[s][p * Nq * dE * dE + q] = cellGeom->invJ[offset * Nq * dE * dE + q]; 8950145028aSToby Isaac } 89641418987SMatthew G. Knepley for (q = 0; q < Nq; q++) geom->suppDetJ[s][p * Nq + q] = cellGeom->detJ[offset * Nq + q]; 8970145028aSToby Isaac } 8980145028aSToby Isaac } 8999566063dSJacob Faibussowitsch PetscCall(PetscFEGeomDestroy(&cellGeom)); 900313f16f2SMatthew G. Knepley PetscCall(PetscQuadratureDestroy(&cellQuad)); 9019566063dSJacob Faibussowitsch PetscCall(ISDestroy(&suppIS)); 9029566063dSJacob Faibussowitsch PetscCall(PetscFree(cells)); 9030145028aSToby Isaac } else { 9046858538eSMatthew G. Knepley DMField_DS *dsfield = (DMField_DS *)field->data; 9050145028aSToby Isaac PetscObject faceDisc, cellDisc; 9060145028aSToby Isaac PetscClassId faceId, cellId; 9070145028aSToby Isaac PetscDualSpace dsp; 9080145028aSToby Isaac DM K; 909ba2698f1SMatthew G. Knepley DMPolytopeType ct; 9100145028aSToby Isaac PetscInt (*co)[2][3]; 9110145028aSToby Isaac PetscInt coneSize; 9120145028aSToby Isaac PetscInt **counts; 9130145028aSToby Isaac PetscInt f, i, o, q, s; 914e59eb9b3SMatthew G. Knepley PetscBool found = PETSC_FALSE; 9150145028aSToby Isaac const PetscInt *coneK; 916ba2698f1SMatthew G. Knepley PetscInt eStart, minOrient, maxOrient, numOrient; 9170145028aSToby Isaac PetscInt *orients; 9180145028aSToby Isaac PetscReal **orientPoints; 9190145028aSToby Isaac PetscReal *cellPoints; 920*2a8381b2SBarry Smith PetscReal *unusedWeights; 9210145028aSToby Isaac PetscQuadrature cellQuad = NULL; 9220145028aSToby Isaac 9236858538eSMatthew G. Knepley PetscCall(DMFieldDSGetHeightDisc(field, 1, dsfield->disc, &faceDisc)); 9246858538eSMatthew G. Knepley PetscCall(DMFieldDSGetHeightDisc(field, 0, dsfield->disc, &cellDisc)); 9259566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(faceDisc, &faceId)); 9269566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(cellDisc, &cellId)); 9271dca8a05SBarry Smith PetscCheck(faceId == PETSCFE_CLASSID && cellId == PETSCFE_CLASSID, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Not supported"); 9289566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace((PetscFE)cellDisc, &dsp)); 9299566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDM(dsp, &K)); 9309566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(K, 1, &eStart, NULL)); 9319566063dSJacob Faibussowitsch PetscCall(DMPlexGetCellType(K, eStart, &ct)); 9329566063dSJacob Faibussowitsch PetscCall(DMPlexGetConeSize(K, 0, &coneSize)); 9339566063dSJacob Faibussowitsch PetscCall(DMPlexGetCone(K, 0, &coneK)); 9349566063dSJacob Faibussowitsch PetscCall(PetscMalloc2(numFaces, &co, coneSize, &counts)); 9359566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(dE * Nq, &cellPoints)); 936*2a8381b2SBarry Smith PetscCall(PetscMalloc1(Nq, &unusedWeights)); 9379566063dSJacob Faibussowitsch PetscCall(PetscQuadratureCreate(PETSC_COMM_SELF, &cellQuad)); 938*2a8381b2SBarry Smith PetscCall(PetscQuadratureSetData(cellQuad, dE, 1, Nq, cellPoints, unusedWeights)); 9391690c2aeSBarry Smith minOrient = PETSC_INT_MAX; 9401690c2aeSBarry Smith maxOrient = PETSC_INT_MIN; 9410145028aSToby Isaac for (p = 0; p < numFaces; p++) { /* record the orientation of the facet wrt the support cells */ 9420145028aSToby Isaac PetscInt point = points[p]; 9430145028aSToby Isaac PetscInt numSupp, numChildren; 9440145028aSToby Isaac const PetscInt *supp; 9450145028aSToby Isaac 9469566063dSJacob Faibussowitsch PetscCall(DMPlexGetTreeChildren(dm, point, &numChildren, NULL)); 94728b400f6SJacob Faibussowitsch PetscCheck(!numChildren, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Face data not valid for facets with children"); 9489566063dSJacob Faibussowitsch PetscCall(DMPlexGetSupportSize(dm, point, &numSupp)); 94963a3b9bcSJacob Faibussowitsch PetscCheck(numSupp <= 2, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Point %" PetscInt_FMT " has %" PetscInt_FMT " support, expected at most 2", point, numSupp); 9509566063dSJacob Faibussowitsch PetscCall(DMPlexGetSupport(dm, point, &supp)); 9510145028aSToby Isaac for (s = 0; s < numSupp; s++) { 9520145028aSToby Isaac PetscInt cell = supp[s]; 9530145028aSToby Isaac PetscInt numCone; 9540145028aSToby Isaac const PetscInt *cone, *orient; 9550145028aSToby Isaac 9569566063dSJacob Faibussowitsch PetscCall(DMPlexGetConeSize(dm, cell, &numCone)); 957e59eb9b3SMatthew G. Knepley // When we extract submeshes, we hang cells from the side that are not fully realized. We ignore these 958e59eb9b3SMatthew G. Knepley if (numCone == 1) { 959e59eb9b3SMatthew G. Knepley co[p][s][0] = -1; 960e59eb9b3SMatthew G. Knepley co[p][s][1] = -1; 961e59eb9b3SMatthew G. Knepley co[p][s][2] = -1; 962e59eb9b3SMatthew G. Knepley continue; 963e59eb9b3SMatthew G. Knepley } 96408401ef6SPierre Jolivet PetscCheck(numCone == coneSize, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Support point does not match reference element"); 9659566063dSJacob Faibussowitsch PetscCall(DMPlexGetCone(dm, cell, &cone)); 9669566063dSJacob Faibussowitsch PetscCall(DMPlexGetConeOrientation(dm, cell, &orient)); 9670145028aSToby Isaac for (f = 0; f < coneSize; f++) { 9680145028aSToby Isaac if (cone[f] == point) break; 9690145028aSToby Isaac } 9700145028aSToby Isaac co[p][s][0] = f; 9710145028aSToby Isaac co[p][s][1] = orient[f]; 9720145028aSToby Isaac co[p][s][2] = cell; 9730145028aSToby Isaac minOrient = PetscMin(minOrient, orient[f]); 974cd93b0e1SMatthew G. Knepley maxOrient = PetscMax(maxOrient, orient[f]); 975e59eb9b3SMatthew G. Knepley found = PETSC_TRUE; 9760145028aSToby Isaac } 9770145028aSToby Isaac for (; s < 2; s++) { 9780145028aSToby Isaac co[p][s][0] = -1; 9790145028aSToby Isaac co[p][s][1] = -1; 9800145028aSToby Isaac co[p][s][2] = -1; 9810145028aSToby Isaac } 9820145028aSToby Isaac } 983e59eb9b3SMatthew G. Knepley numOrient = found ? maxOrient + 1 - minOrient : 0; 9849566063dSJacob Faibussowitsch PetscCall(DMPlexGetCone(K, 0, &coneK)); 9850145028aSToby Isaac /* count all (face,orientation) doubles that appear */ 9869566063dSJacob Faibussowitsch PetscCall(PetscCalloc2(numOrient, &orients, numOrient, &orientPoints)); 9879566063dSJacob Faibussowitsch for (f = 0; f < coneSize; f++) PetscCall(PetscCalloc1(numOrient + 1, &counts[f])); 9880145028aSToby Isaac for (p = 0; p < numFaces; p++) { 9890145028aSToby Isaac for (s = 0; s < 2; s++) { 9900145028aSToby Isaac if (co[p][s][0] >= 0) { 9910145028aSToby Isaac counts[co[p][s][0]][co[p][s][1] - minOrient]++; 9920145028aSToby Isaac orients[co[p][s][1] - minOrient]++; 9930145028aSToby Isaac } 9940145028aSToby Isaac } 9950145028aSToby Isaac } 9960145028aSToby Isaac for (o = 0; o < numOrient; o++) { 9970145028aSToby Isaac if (orients[o]) { 9980145028aSToby Isaac PetscInt orient = o + minOrient; 9990145028aSToby Isaac PetscInt q; 10000145028aSToby Isaac 10019566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nq * dim, &orientPoints[o])); 10020145028aSToby Isaac /* rotate the quadrature points appropriately */ 1003ba2698f1SMatthew G. Knepley switch (ct) { 1004d71ae5a4SJacob Faibussowitsch case DM_POLYTOPE_POINT: 1005d71ae5a4SJacob Faibussowitsch break; 1006ba2698f1SMatthew G. Knepley case DM_POLYTOPE_SEGMENT: 10070145028aSToby Isaac if (orient == -2 || orient == 1) { 1008ad540459SPierre Jolivet for (q = 0; q < Nq; q++) orientPoints[o][q] = -geom->xi[q]; 10090145028aSToby Isaac } else { 1010ad540459SPierre Jolivet for (q = 0; q < Nq; q++) orientPoints[o][q] = geom->xi[q]; 10110145028aSToby Isaac } 10120145028aSToby Isaac break; 1013ba2698f1SMatthew G. Knepley case DM_POLYTOPE_TRIANGLE: 10140145028aSToby Isaac for (q = 0; q < Nq; q++) { 10150145028aSToby Isaac PetscReal lambda[3]; 10160145028aSToby Isaac PetscReal lambdao[3]; 10170145028aSToby Isaac 10180145028aSToby Isaac /* convert to barycentric */ 10190145028aSToby Isaac lambda[0] = -(geom->xi[2 * q] + geom->xi[2 * q + 1]) / 2.; 10200145028aSToby Isaac lambda[1] = (geom->xi[2 * q] + 1.) / 2.; 10210145028aSToby Isaac lambda[2] = (geom->xi[2 * q + 1] + 1.) / 2.; 10220145028aSToby Isaac if (orient >= 0) { 1023ad540459SPierre Jolivet for (i = 0; i < 3; i++) lambdao[i] = lambda[(orient + i) % 3]; 10240145028aSToby Isaac } else { 1025ad540459SPierre Jolivet for (i = 0; i < 3; i++) lambdao[i] = lambda[(-(orient + i) + 3) % 3]; 10260145028aSToby Isaac } 10270145028aSToby Isaac /* convert to coordinates */ 10280145028aSToby Isaac orientPoints[o][2 * q + 0] = -(lambdao[0] + lambdao[2]) + lambdao[1]; 10290145028aSToby Isaac orientPoints[o][2 * q + 1] = -(lambdao[0] + lambdao[1]) + lambdao[2]; 10300145028aSToby Isaac } 10310145028aSToby Isaac break; 1032ba2698f1SMatthew G. Knepley case DM_POLYTOPE_QUADRILATERAL: 10330145028aSToby Isaac for (q = 0; q < Nq; q++) { 10340145028aSToby Isaac PetscReal xi[2], xio[2]; 10350145028aSToby Isaac PetscInt oabs = (orient >= 0) ? orient : -(orient + 1); 10360145028aSToby Isaac 10370145028aSToby Isaac xi[0] = geom->xi[2 * q]; 10380145028aSToby Isaac xi[1] = geom->xi[2 * q + 1]; 10390145028aSToby Isaac switch (oabs) { 10400145028aSToby Isaac case 1: 10410145028aSToby Isaac xio[0] = xi[1]; 10420145028aSToby Isaac xio[1] = -xi[0]; 10430145028aSToby Isaac break; 1044f4d061e9SPierre Jolivet case 2: 1045f4d061e9SPierre Jolivet xio[0] = -xi[0]; 1046f4d061e9SPierre Jolivet xio[1] = -xi[1]; 1047f4d061e9SPierre Jolivet break; 1048f4d061e9SPierre Jolivet case 3: 1049f4d061e9SPierre Jolivet xio[0] = -xi[1]; 1050f4d061e9SPierre Jolivet xio[1] = xi[0]; 1051f4d061e9SPierre Jolivet break; 1052aa1371cbSToby Isaac case 0: 1053aa1371cbSToby Isaac default: 1054aa1371cbSToby Isaac xio[0] = xi[0]; 1055aa1371cbSToby Isaac xio[1] = xi[1]; 1056aa1371cbSToby Isaac break; 10570145028aSToby Isaac } 1058ad540459SPierre Jolivet if (orient < 0) xio[0] = -xio[0]; 10590145028aSToby Isaac orientPoints[o][2 * q + 0] = xio[0]; 10600145028aSToby Isaac orientPoints[o][2 * q + 1] = xio[1]; 10610145028aSToby Isaac } 10620145028aSToby Isaac break; 1063d71ae5a4SJacob Faibussowitsch default: 1064d71ae5a4SJacob Faibussowitsch SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Cell type %s not yet supported", DMPolytopeTypes[ct]); 10650145028aSToby Isaac } 10660145028aSToby Isaac } 10670145028aSToby Isaac } 10680145028aSToby Isaac for (f = 0; f < coneSize; f++) { 10690145028aSToby Isaac PetscInt face = coneK[f]; 10704d1a973fSToby Isaac PetscReal v0[3]; 10712d89661fSMatthew G. Knepley PetscReal J[9], detJ; 10720145028aSToby Isaac PetscInt numCells, offset; 10730145028aSToby Isaac PetscInt *cells; 10740145028aSToby Isaac IS suppIS; 10750145028aSToby Isaac 10769566063dSJacob Faibussowitsch PetscCall(DMPlexComputeCellGeometryFEM(K, face, NULL, v0, J, NULL, &detJ)); 10770145028aSToby Isaac for (o = 0; o <= numOrient; o++) { 10780145028aSToby Isaac PetscFEGeom *cellGeom; 10790145028aSToby Isaac 10800145028aSToby Isaac if (!counts[f][o]) continue; 10810145028aSToby Isaac /* If this (face,orientation) double appears, 10820145028aSToby Isaac * convert the face quadrature points into volume quadrature points */ 10830145028aSToby Isaac for (q = 0; q < Nq; q++) { 10840145028aSToby Isaac PetscReal xi0[3] = {-1., -1., -1.}; 10850145028aSToby Isaac 10860145028aSToby Isaac CoordinatesRefToReal(dE, dim, xi0, v0, J, &orientPoints[o][dim * q + 0], &cellPoints[dE * q + 0]); 10870145028aSToby Isaac } 10880145028aSToby Isaac for (p = 0, numCells = 0; p < numFaces; p++) { 10890145028aSToby Isaac for (s = 0; s < 2; s++) { 10900145028aSToby Isaac if (co[p][s][0] == f && co[p][s][1] == o + minOrient) numCells++; 10910145028aSToby Isaac } 10920145028aSToby Isaac } 10939566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(numCells, &cells)); 10940145028aSToby Isaac for (p = 0, offset = 0; p < numFaces; p++) { 10950145028aSToby Isaac for (s = 0; s < 2; s++) { 1096ad540459SPierre Jolivet if (co[p][s][0] == f && co[p][s][1] == o + minOrient) cells[offset++] = co[p][s][2]; 10970145028aSToby Isaac } 10980145028aSToby Isaac } 10999566063dSJacob Faibussowitsch PetscCall(ISCreateGeneral(PETSC_COMM_SELF, numCells, cells, PETSC_USE_POINTER, &suppIS)); 1100ac9d17c7SMatthew G. Knepley PetscCall(DMFieldCreateFEGeom(field, suppIS, cellQuad, PETSC_FEGEOM_BASIC, &cellGeom)); 11010145028aSToby Isaac for (p = 0, offset = 0; p < numFaces; p++) { 11020145028aSToby Isaac for (s = 0; s < 2; s++) { 11030145028aSToby Isaac if (co[p][s][0] == f && co[p][s][1] == o + minOrient) { 11040145028aSToby Isaac for (q = 0; q < Nq * dE * dE; q++) { 110541418987SMatthew G. Knepley geom->suppJ[s][p * Nq * dE * dE + q] = cellGeom->J[offset * Nq * dE * dE + q]; 11060145028aSToby Isaac geom->suppInvJ[s][p * Nq * dE * dE + q] = cellGeom->invJ[offset * Nq * dE * dE + q]; 11070145028aSToby Isaac } 110841418987SMatthew G. Knepley for (q = 0; q < Nq; q++) geom->suppDetJ[s][p * Nq + q] = cellGeom->detJ[offset * Nq + q]; 11090145028aSToby Isaac offset++; 11100145028aSToby Isaac } 11110145028aSToby Isaac } 11120145028aSToby Isaac } 11139566063dSJacob Faibussowitsch PetscCall(PetscFEGeomDestroy(&cellGeom)); 11149566063dSJacob Faibussowitsch PetscCall(ISDestroy(&suppIS)); 11159566063dSJacob Faibussowitsch PetscCall(PetscFree(cells)); 11160145028aSToby Isaac } 11170145028aSToby Isaac } 11180145028aSToby Isaac for (o = 0; o < numOrient; o++) { 111948a46eb9SPierre Jolivet if (orients[o]) PetscCall(PetscFree(orientPoints[o])); 11200145028aSToby Isaac } 11219566063dSJacob Faibussowitsch PetscCall(PetscFree2(orients, orientPoints)); 11229566063dSJacob Faibussowitsch PetscCall(PetscQuadratureDestroy(&cellQuad)); 11239566063dSJacob Faibussowitsch for (f = 0; f < coneSize; f++) PetscCall(PetscFree(counts[f])); 11249566063dSJacob Faibussowitsch PetscCall(PetscFree2(co, counts)); 11250145028aSToby Isaac } 11269566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(pointIS, &points)); 11279566063dSJacob Faibussowitsch PetscCall(ISDestroy(&cellIS)); 11283ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 11290145028aSToby Isaac } 11300145028aSToby Isaac 1131d71ae5a4SJacob Faibussowitsch static PetscErrorCode DMFieldInitialize_DS(DMField field) 1132d71ae5a4SJacob Faibussowitsch { 113351a454edSToby Isaac PetscFunctionBegin; 113451a454edSToby Isaac field->ops->destroy = DMFieldDestroy_DS; 113551a454edSToby Isaac field->ops->evaluate = DMFieldEvaluate_DS; 113651a454edSToby Isaac field->ops->evaluateFE = DMFieldEvaluateFE_DS; 1137805e7170SToby Isaac field->ops->evaluateFV = DMFieldEvaluateFV_DS; 1138b7260050SToby Isaac field->ops->getDegree = DMFieldGetDegree_DS; 113951a454edSToby Isaac field->ops->createDefaultQuadrature = DMFieldCreateDefaultQuadrature_DS; 1140989fa639SBrad Aagaard field->ops->createDefaultFaceQuadrature = DMFieldCreateDefaultFaceQuadrature_DS; 114151a454edSToby Isaac field->ops->view = DMFieldView_DS; 11420145028aSToby Isaac field->ops->computeFaceData = DMFieldComputeFaceData_DS; 11433ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 114451a454edSToby Isaac } 114551a454edSToby Isaac 1146d71ae5a4SJacob Faibussowitsch PETSC_INTERN PetscErrorCode DMFieldCreate_DS(DMField field) 1147d71ae5a4SJacob Faibussowitsch { 114851a454edSToby Isaac DMField_DS *dsfield; 114951a454edSToby Isaac 115051a454edSToby Isaac PetscFunctionBegin; 11514dfa11a4SJacob Faibussowitsch PetscCall(PetscNew(&dsfield)); 115251a454edSToby Isaac field->data = dsfield; 11539566063dSJacob Faibussowitsch PetscCall(DMFieldInitialize_DS(field)); 11543ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 115551a454edSToby Isaac } 115651a454edSToby Isaac 1157d71ae5a4SJacob Faibussowitsch PetscErrorCode DMFieldCreateDSWithDG(DM dm, DM dmDG, PetscInt fieldNum, Vec vec, Vec vecDG, DMField *field) 1158d71ae5a4SJacob Faibussowitsch { 115951a454edSToby Isaac DMField b; 116051a454edSToby Isaac DMField_DS *dsfield; 11616858538eSMatthew G. Knepley PetscObject disc = NULL, discDG = NULL; 11626858538eSMatthew G. Knepley PetscSection section; 116351a454edSToby Isaac PetscBool isContainer = PETSC_FALSE; 116451a454edSToby Isaac PetscClassId id = -1; 116551a454edSToby Isaac PetscInt numComponents = -1, dsNumFields; 116651a454edSToby Isaac 116751a454edSToby Isaac PetscFunctionBegin; 11689566063dSJacob Faibussowitsch PetscCall(DMGetLocalSection(dm, §ion)); 11699566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(section, fieldNum, &numComponents)); 11709566063dSJacob Faibussowitsch PetscCall(DMGetNumFields(dm, &dsNumFields)); 11719566063dSJacob Faibussowitsch if (dsNumFields) PetscCall(DMGetField(dm, fieldNum, NULL, &disc)); 11726858538eSMatthew G. Knepley if (dsNumFields && dmDG) { 11736858538eSMatthew G. Knepley PetscCall(DMGetField(dmDG, fieldNum, NULL, &discDG)); 11746858538eSMatthew G. Knepley PetscCall(PetscObjectReference(discDG)); 11756858538eSMatthew G. Knepley } 117651a454edSToby Isaac if (disc) { 11779566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(disc, &id)); 117851a454edSToby Isaac isContainer = (id == PETSC_CONTAINER_CLASSID) ? PETSC_TRUE : PETSC_FALSE; 117951a454edSToby Isaac } 118051a454edSToby Isaac if (!disc || isContainer) { 118151a454edSToby Isaac MPI_Comm comm = PetscObjectComm((PetscObject)dm); 118251a454edSToby Isaac PetscFE fe; 11832df84da0SMatthew G. Knepley DMPolytopeType ct, locct = DM_POLYTOPE_UNKNOWN; 11842df84da0SMatthew G. Knepley PetscInt dim, cStart, cEnd, cellHeight; 118551a454edSToby Isaac 11869566063dSJacob Faibussowitsch PetscCall(DMPlexGetVTKCellHeight(dm, &cellHeight)); 11879566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim)); 11889566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(dm, cellHeight, &cStart, &cEnd)); 11899566063dSJacob Faibussowitsch if (cEnd > cStart) PetscCall(DMPlexGetCellType(dm, cStart, &locct)); 11906a210b70SBarry Smith PetscCallMPI(MPIU_Allreduce(&locct, &ct, 1, MPI_INT, MPI_MIN, comm)); 11919566063dSJacob Faibussowitsch PetscCall(PetscFECreateLagrangeByCell(PETSC_COMM_SELF, dim, numComponents, ct, 1, PETSC_DETERMINE, &fe)); 11929566063dSJacob Faibussowitsch PetscCall(PetscFEViewFromOptions(fe, NULL, "-field_fe_view")); 119351a454edSToby Isaac disc = (PetscObject)fe; 11941baa6e33SBarry Smith } else PetscCall(PetscObjectReference(disc)); 11959566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(disc, &id)); 1196966bd95aSPierre Jolivet PetscCheck(id == PETSCFE_CLASSID, PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Cannot determine number of discretization components"); 1197966bd95aSPierre Jolivet PetscCall(PetscFEGetNumComponents((PetscFE)disc, &numComponents)); 11989566063dSJacob Faibussowitsch PetscCall(DMFieldCreate(dm, numComponents, DMFIELD_VERTEX, &b)); 11999566063dSJacob Faibussowitsch PetscCall(DMFieldSetType(b, DMFIELDDS)); 120051a454edSToby Isaac dsfield = (DMField_DS *)b->data; 120151a454edSToby Isaac dsfield->fieldNum = fieldNum; 12029566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dsfield->height)); 1203f99c8401SToby Isaac dsfield->height++; 12049566063dSJacob Faibussowitsch PetscCall(PetscCalloc1(dsfield->height, &dsfield->disc)); 120551a454edSToby Isaac dsfield->disc[0] = disc; 12069566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)vec)); 120751a454edSToby Isaac dsfield->vec = vec; 12086858538eSMatthew G. Knepley if (dmDG) { 12096858538eSMatthew G. Knepley dsfield->dmDG = dmDG; 12106858538eSMatthew G. Knepley PetscCall(PetscCalloc1(dsfield->height, &dsfield->discDG)); 12116858538eSMatthew G. Knepley dsfield->discDG[0] = discDG; 12126858538eSMatthew G. Knepley PetscCall(PetscObjectReference((PetscObject)vecDG)); 12136858538eSMatthew G. Knepley dsfield->vecDG = vecDG; 12146858538eSMatthew G. Knepley } 121551a454edSToby Isaac *field = b; 12163ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 12176858538eSMatthew G. Knepley } 121851a454edSToby Isaac 1219d71ae5a4SJacob Faibussowitsch PetscErrorCode DMFieldCreateDS(DM dm, PetscInt fieldNum, Vec vec, DMField *field) 1220d71ae5a4SJacob Faibussowitsch { 12216858538eSMatthew G. Knepley PetscFunctionBegin; 12226858538eSMatthew G. Knepley PetscCall(DMFieldCreateDSWithDG(dm, NULL, fieldNum, vec, NULL, field)); 12233ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 122451a454edSToby Isaac } 1225