1af0996ceSBarry Smith #include <petsc/private/dmpleximpl.h> /*I "petscdmplex.h" I*/ 2af0996ceSBarry Smith #include <petsc/private/isimpl.h> 3e5c6e791SKarl Rupp #include <petsc/private/vecimpl.h> 48135c375SStefano Zampini #include <petsc/private/glvisvecimpl.h> 50c312b8eSJed Brown #include <petscsf.h> 6e228b242SToby Isaac #include <petscds.h> 7e412dcbdSMatthew G. Knepley #include <petscdraw.h> 8f19dbd58SToby Isaac #include <petscdmfield.h> 9552f7358SJed Brown 10552f7358SJed Brown /* Logging support */ 1167eb269bSLisandro Dalcin PetscLogEvent DMPLEX_Interpolate, DMPLEX_Partition, DMPLEX_Distribute, DMPLEX_DistributeCones, DMPLEX_DistributeLabels, DMPLEX_DistributeSF, DMPLEX_DistributeOverlap, DMPLEX_DistributeField, DMPLEX_DistributeData, DMPLEX_Migrate, DMPLEX_InterpolateSF, DMPLEX_GlobalToNaturalBegin, DMPLEX_GlobalToNaturalEnd, DMPLEX_NaturalToGlobalBegin, DMPLEX_NaturalToGlobalEnd, DMPLEX_Stratify, DMPLEX_Preallocate, DMPLEX_ResidualFEM, DMPLEX_JacobianFEM, DMPLEX_InterpolatorFEM, DMPLEX_InjectorFEM, DMPLEX_IntegralFEM, DMPLEX_CreateGmsh; 12552f7358SJed Brown 135a576424SJed Brown PETSC_EXTERN PetscErrorCode VecView_MPI(Vec, PetscViewer); 14552f7358SJed Brown 15e5337592SStefano Zampini /*@ 16e5337592SStefano Zampini DMPlexRefineSimplexToTensor - Uniformly refines simplicial cells into tensor product cells. 17e5337592SStefano Zampini 3 quadrilaterals per triangle in 2D and 4 hexahedra per tetrahedron in 3D. 18e5337592SStefano Zampini 19e5337592SStefano Zampini Collective 20e5337592SStefano Zampini 21e5337592SStefano Zampini Input Parameters: 22e5337592SStefano Zampini . dm - The DMPlex object 23e5337592SStefano Zampini 24e5337592SStefano Zampini Output Parameters: 25e5337592SStefano Zampini . dmRefined - The refined DMPlex object 26e5337592SStefano Zampini 27e5337592SStefano Zampini Note: Returns NULL if the mesh is already a tensor product mesh. 28e5337592SStefano Zampini 29e5337592SStefano Zampini Level: intermediate 30e5337592SStefano Zampini 31e5337592SStefano Zampini .seealso: DMPlexCreate(), DMPlexSetRefinementUniform() 32e5337592SStefano Zampini @*/ 33e5337592SStefano Zampini PetscErrorCode DMPlexRefineSimplexToTensor(DM dm, DM *dmRefined) 34e5337592SStefano Zampini { 35e5337592SStefano Zampini PetscInt dim, cMax, fMax, cStart, cEnd, coneSize; 36e5337592SStefano Zampini CellRefiner cellRefiner; 37e5337592SStefano Zampini PetscBool lop, allnoop, localized; 38e5337592SStefano Zampini PetscErrorCode ierr; 39e5337592SStefano Zampini 40e5337592SStefano Zampini PetscFunctionBegin; 41e5337592SStefano Zampini PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 424330a3fcSStefano Zampini PetscValidPointer(dmRefined, 1); 43e5337592SStefano Zampini ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 44e5337592SStefano Zampini ierr = DMPlexGetHybridBounds(dm,&cMax,&fMax,NULL,NULL);CHKERRQ(ierr); 45e5337592SStefano Zampini ierr = DMPlexGetHeightStratum(dm,0,&cStart,&cEnd);CHKERRQ(ierr); 46e5337592SStefano Zampini if (!(cEnd - cStart)) cellRefiner = REFINER_NOOP; 47e5337592SStefano Zampini else { 48e5337592SStefano Zampini ierr = DMPlexGetConeSize(dm,cStart,&coneSize);CHKERRQ(ierr); 49e5337592SStefano Zampini switch (dim) { 50e5337592SStefano Zampini case 1: 51e5337592SStefano Zampini cellRefiner = REFINER_NOOP; 52e5337592SStefano Zampini break; 53e5337592SStefano Zampini case 2: 54e5337592SStefano Zampini switch (coneSize) { 55e5337592SStefano Zampini case 3: 564330a3fcSStefano Zampini if (cMax >= 0) cellRefiner = REFINER_HYBRID_SIMPLEX_TO_HEX_2D; 574330a3fcSStefano Zampini else cellRefiner = REFINER_SIMPLEX_TO_HEX_2D; 58e5337592SStefano Zampini break; 59e5337592SStefano Zampini case 4: 604330a3fcSStefano Zampini if (cMax >= 0) cellRefiner = REFINER_HYBRID_SIMPLEX_TO_HEX_2D; 614330a3fcSStefano Zampini else cellRefiner = REFINER_NOOP; 62e5337592SStefano Zampini break; 63e5337592SStefano Zampini default: SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot handle coneSize %D with dimension %D",coneSize,dim); 64e5337592SStefano Zampini } 65e5337592SStefano Zampini break; 66e5337592SStefano Zampini case 3: 67e5337592SStefano Zampini switch (coneSize) { 68e5337592SStefano Zampini case 4: 694330a3fcSStefano Zampini if (cMax >= 0) cellRefiner = REFINER_HYBRID_SIMPLEX_TO_HEX_3D; 704330a3fcSStefano Zampini else cellRefiner = REFINER_SIMPLEX_TO_HEX_3D; 714330a3fcSStefano Zampini break; 724330a3fcSStefano Zampini case 5: 734330a3fcSStefano Zampini if (cMax >= 0) cellRefiner = REFINER_HYBRID_SIMPLEX_TO_HEX_3D; 744330a3fcSStefano Zampini else cellRefiner = REFINER_NOOP; 75e5337592SStefano Zampini break; 76e5337592SStefano Zampini case 6: 774330a3fcSStefano Zampini if (cMax >= 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Simplex2Tensor in 3D with Hybrid mesh not yet done"); 78e5337592SStefano Zampini cellRefiner = REFINER_NOOP; 79e5337592SStefano Zampini break; 80e5337592SStefano Zampini default: SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot handle coneSize %D with dimension %D",coneSize,dim); 81e5337592SStefano Zampini } 82e5337592SStefano Zampini break; 83e5337592SStefano Zampini default: SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot handle dimension %D",dim); 84e5337592SStefano Zampini } 85e5337592SStefano Zampini } 86e5337592SStefano Zampini /* return if we don't need to refine */ 87e5337592SStefano Zampini lop = (cellRefiner == REFINER_NOOP) ? PETSC_TRUE : PETSC_FALSE; 88e5337592SStefano Zampini ierr = MPIU_Allreduce(&lop,&allnoop,1,MPIU_BOOL,MPI_LAND,PetscObjectComm((PetscObject)dm));CHKERRQ(ierr); 89e5337592SStefano Zampini if (allnoop) { 90e5337592SStefano Zampini *dmRefined = NULL; 91e5337592SStefano Zampini PetscFunctionReturn(0); 92e5337592SStefano Zampini } 93e5337592SStefano Zampini ierr = DMPlexRefineUniform_Internal(dm, cellRefiner, dmRefined);CHKERRQ(ierr); 94e5337592SStefano Zampini ierr = DMCopyBoundary(dm, *dmRefined);CHKERRQ(ierr); 95e5337592SStefano Zampini ierr = DMGetCoordinatesLocalized(dm, &localized);CHKERRQ(ierr); 96e5337592SStefano Zampini if (localized) { 97e5337592SStefano Zampini ierr = DMLocalizeCoordinates(*dmRefined);CHKERRQ(ierr); 98e5337592SStefano Zampini } 99e5337592SStefano Zampini PetscFunctionReturn(0); 100e5337592SStefano Zampini } 101e5337592SStefano Zampini 1027afe7537SMatthew G. Knepley PetscErrorCode DMPlexGetFieldType_Internal(DM dm, PetscSection section, PetscInt field, PetscInt *sStart, PetscInt *sEnd, PetscViewerVTKFieldType *ft) 1037e42fee7SMatthew G. Knepley { 104a99a26bcSAdrian Croucher PetscInt dim, pStart, pEnd, vStart, vEnd, cStart, cEnd, cEndInterior; 105a99a26bcSAdrian Croucher PetscInt vcdof[2] = {0,0}, globalvcdof[2]; 1067e42fee7SMatthew G. Knepley PetscErrorCode ierr; 1077e42fee7SMatthew G. Knepley 1087e42fee7SMatthew G. Knepley PetscFunctionBegin; 1097e42fee7SMatthew G. Knepley *ft = PETSC_VTK_POINT_FIELD; 110c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 1117e42fee7SMatthew G. Knepley ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr); 1127e42fee7SMatthew G. Knepley ierr = DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd);CHKERRQ(ierr); 11380d5bdc6SMatthew G. Knepley ierr = DMPlexGetHybridBounds(dm, &cEndInterior, NULL, NULL, NULL);CHKERRQ(ierr); 11480d5bdc6SMatthew G. Knepley cEnd = cEndInterior < 0 ? cEnd : cEndInterior; 1157e42fee7SMatthew G. Knepley ierr = PetscSectionGetChart(section, &pStart, &pEnd);CHKERRQ(ierr); 1167e42fee7SMatthew G. Knepley if (field >= 0) { 117a99a26bcSAdrian Croucher if ((vStart >= pStart) && (vStart < pEnd)) {ierr = PetscSectionGetFieldDof(section, vStart, field, &vcdof[0]);CHKERRQ(ierr);} 118a99a26bcSAdrian Croucher if ((cStart >= pStart) && (cStart < pEnd)) {ierr = PetscSectionGetFieldDof(section, cStart, field, &vcdof[1]);CHKERRQ(ierr);} 1197e42fee7SMatthew G. Knepley } else { 120a99a26bcSAdrian Croucher if ((vStart >= pStart) && (vStart < pEnd)) {ierr = PetscSectionGetDof(section, vStart, &vcdof[0]);CHKERRQ(ierr);} 121a99a26bcSAdrian Croucher if ((cStart >= pStart) && (cStart < pEnd)) {ierr = PetscSectionGetDof(section, cStart, &vcdof[1]);CHKERRQ(ierr);} 1227e42fee7SMatthew G. Knepley } 1235483465cSMatthew G. Knepley ierr = MPI_Allreduce(vcdof, globalvcdof, 2, MPIU_INT, MPI_MAX, PetscObjectComm((PetscObject)dm));CHKERRQ(ierr); 124a99a26bcSAdrian Croucher if (globalvcdof[0]) { 1257e42fee7SMatthew G. Knepley *sStart = vStart; 1267e42fee7SMatthew G. Knepley *sEnd = vEnd; 127a99a26bcSAdrian Croucher if (globalvcdof[0] == dim) *ft = PETSC_VTK_POINT_VECTOR_FIELD; 1287e42fee7SMatthew G. Knepley else *ft = PETSC_VTK_POINT_FIELD; 129a99a26bcSAdrian Croucher } else if (globalvcdof[1]) { 1307e42fee7SMatthew G. Knepley *sStart = cStart; 1317e42fee7SMatthew G. Knepley *sEnd = cEnd; 132a99a26bcSAdrian Croucher if (globalvcdof[1] == dim) *ft = PETSC_VTK_CELL_VECTOR_FIELD; 1337e42fee7SMatthew G. Knepley else *ft = PETSC_VTK_CELL_FIELD; 1347e42fee7SMatthew G. Knepley } else SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "Could not classify input Vec for VTK"); 1357e42fee7SMatthew G. Knepley PetscFunctionReturn(0); 1367e42fee7SMatthew G. Knepley } 1377e42fee7SMatthew G. Knepley 1387cd05799SMatthew G. Knepley static PetscErrorCode VecView_Plex_Local_Draw(Vec v, PetscViewer viewer) 139e412dcbdSMatthew G. Knepley { 140e412dcbdSMatthew G. Knepley DM dm; 141d1df6f1dSMatthew G. Knepley PetscSection s; 142e412dcbdSMatthew G. Knepley PetscDraw draw, popup; 143e412dcbdSMatthew G. Knepley DM cdm; 144e412dcbdSMatthew G. Knepley PetscSection coordSection; 145e412dcbdSMatthew G. Knepley Vec coordinates; 146e412dcbdSMatthew G. Knepley const PetscScalar *coords, *array; 147e412dcbdSMatthew G. Knepley PetscReal bound[4] = {PETSC_MAX_REAL, PETSC_MAX_REAL, PETSC_MIN_REAL, PETSC_MIN_REAL}; 148339e3443SMatthew G. Knepley PetscReal vbound[2], time; 149339e3443SMatthew G. Knepley PetscBool isnull, flg; 150d1df6f1dSMatthew G. Knepley PetscInt dim, Nf, f, Nc, comp, vStart, vEnd, cStart, cEnd, c, N, level, step, w = 0; 151e412dcbdSMatthew G. Knepley const char *name; 152339e3443SMatthew G. Knepley char title[PETSC_MAX_PATH_LEN]; 153e412dcbdSMatthew G. Knepley PetscErrorCode ierr; 154e412dcbdSMatthew G. Knepley 155e412dcbdSMatthew G. Knepley PetscFunctionBegin; 156d1df6f1dSMatthew G. Knepley ierr = PetscViewerDrawGetDraw(viewer, 0, &draw);CHKERRQ(ierr); 157d1df6f1dSMatthew G. Knepley ierr = PetscDrawIsNull(draw, &isnull);CHKERRQ(ierr); 158d1df6f1dSMatthew G. Knepley if (isnull) PetscFunctionReturn(0); 159d1df6f1dSMatthew G. Knepley 160e412dcbdSMatthew G. Knepley ierr = VecGetDM(v, &dm);CHKERRQ(ierr); 161e412dcbdSMatthew G. Knepley ierr = DMGetCoordinateDim(dm, &dim);CHKERRQ(ierr); 1628135c375SStefano Zampini if (dim != 2) SETERRQ1(PetscObjectComm((PetscObject) dm), PETSC_ERR_SUP, "Cannot draw meshes of dimension %D. Use PETSCVIEWERGLVIS", dim); 163e87a4003SBarry Smith ierr = DMGetSection(dm, &s);CHKERRQ(ierr); 164d1df6f1dSMatthew G. Knepley ierr = PetscSectionGetNumFields(s, &Nf);CHKERRQ(ierr); 165e412dcbdSMatthew G. Knepley ierr = DMGetCoarsenLevel(dm, &level);CHKERRQ(ierr); 166e412dcbdSMatthew G. Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 167e87a4003SBarry Smith ierr = DMGetSection(cdm, &coordSection);CHKERRQ(ierr); 168e412dcbdSMatthew G. Knepley ierr = DMGetCoordinatesLocal(dm, &coordinates);CHKERRQ(ierr); 169e412dcbdSMatthew G. Knepley ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr); 170e412dcbdSMatthew G. Knepley ierr = DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd);CHKERRQ(ierr); 171e412dcbdSMatthew G. Knepley 172e412dcbdSMatthew G. Knepley ierr = PetscObjectGetName((PetscObject) v, &name);CHKERRQ(ierr); 173339e3443SMatthew G. Knepley ierr = DMGetOutputSequenceNumber(dm, &step, &time);CHKERRQ(ierr); 174e412dcbdSMatthew G. Knepley 175e412dcbdSMatthew G. Knepley ierr = VecGetLocalSize(coordinates, &N);CHKERRQ(ierr); 176e412dcbdSMatthew G. Knepley ierr = VecGetArrayRead(coordinates, &coords);CHKERRQ(ierr); 177e412dcbdSMatthew G. Knepley for (c = 0; c < N; c += dim) { 1780c81f2a8SMatthew G. Knepley bound[0] = PetscMin(bound[0], PetscRealPart(coords[c])); bound[2] = PetscMax(bound[2], PetscRealPart(coords[c])); 1790c81f2a8SMatthew G. Knepley bound[1] = PetscMin(bound[1], PetscRealPart(coords[c+1])); bound[3] = PetscMax(bound[3], PetscRealPart(coords[c+1])); 180e412dcbdSMatthew G. Knepley } 181e412dcbdSMatthew G. Knepley ierr = VecRestoreArrayRead(coordinates, &coords);CHKERRQ(ierr); 182e412dcbdSMatthew G. Knepley ierr = PetscDrawClear(draw);CHKERRQ(ierr); 183e412dcbdSMatthew G. Knepley 184d1df6f1dSMatthew G. Knepley /* Could implement something like DMDASelectFields() */ 185d1df6f1dSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 186d1df6f1dSMatthew G. Knepley DM fdm = dm; 187d1df6f1dSMatthew G. Knepley Vec fv = v; 188d1df6f1dSMatthew G. Knepley IS fis; 189d1df6f1dSMatthew G. Knepley char prefix[PETSC_MAX_PATH_LEN]; 190d1df6f1dSMatthew G. Knepley const char *fname; 191d1df6f1dSMatthew G. Knepley 192d1df6f1dSMatthew G. Knepley ierr = PetscSectionGetFieldComponents(s, f, &Nc);CHKERRQ(ierr); 193d1df6f1dSMatthew G. Knepley ierr = PetscSectionGetFieldName(s, f, &fname);CHKERRQ(ierr); 194d1df6f1dSMatthew G. Knepley 195a126751eSBarry Smith if (v->hdr.prefix) {ierr = PetscStrncpy(prefix, v->hdr.prefix,sizeof(prefix));CHKERRQ(ierr);} 196d1df6f1dSMatthew G. Knepley else {prefix[0] = '\0';} 197d1df6f1dSMatthew G. Knepley if (Nf > 1) { 198d1df6f1dSMatthew G. Knepley ierr = DMCreateSubDM(dm, 1, &f, &fis, &fdm);CHKERRQ(ierr); 199d1df6f1dSMatthew G. Knepley ierr = VecGetSubVector(v, fis, &fv);CHKERRQ(ierr); 200a126751eSBarry Smith ierr = PetscStrlcat(prefix, fname,sizeof(prefix));CHKERRQ(ierr); 201a126751eSBarry Smith ierr = PetscStrlcat(prefix, "_",sizeof(prefix));CHKERRQ(ierr); 202d1df6f1dSMatthew G. Knepley } 203d1df6f1dSMatthew G. Knepley for (comp = 0; comp < Nc; ++comp, ++w) { 204d1df6f1dSMatthew G. Knepley PetscInt nmax = 2; 205d1df6f1dSMatthew G. Knepley 206d1df6f1dSMatthew G. Knepley ierr = PetscViewerDrawGetDraw(viewer, w, &draw);CHKERRQ(ierr); 207d1df6f1dSMatthew G. Knepley if (Nc > 1) {ierr = PetscSNPrintf(title, sizeof(title), "%s:%s_%D Step: %D Time: %.4g", name, fname, comp, step, time);CHKERRQ(ierr);} 208d1df6f1dSMatthew G. Knepley else {ierr = PetscSNPrintf(title, sizeof(title), "%s:%s Step: %D Time: %.4g", name, fname, step, time);CHKERRQ(ierr);} 209d1df6f1dSMatthew G. Knepley ierr = PetscDrawSetTitle(draw, title);CHKERRQ(ierr); 210d1df6f1dSMatthew G. Knepley 211d1df6f1dSMatthew G. Knepley /* TODO Get max and min only for this component */ 212d1df6f1dSMatthew G. Knepley ierr = PetscOptionsGetRealArray(NULL, prefix, "-vec_view_bounds", vbound, &nmax, &flg);CHKERRQ(ierr); 213339e3443SMatthew G. Knepley if (!flg) { 214d1df6f1dSMatthew G. Knepley ierr = VecMin(fv, NULL, &vbound[0]);CHKERRQ(ierr); 215d1df6f1dSMatthew G. Knepley ierr = VecMax(fv, NULL, &vbound[1]);CHKERRQ(ierr); 216d1df6f1dSMatthew G. Knepley if (vbound[1] <= vbound[0]) vbound[1] = vbound[0] + 1.0; 217339e3443SMatthew G. Knepley } 218e412dcbdSMatthew G. Knepley ierr = PetscDrawGetPopup(draw, &popup);CHKERRQ(ierr); 219339e3443SMatthew G. Knepley ierr = PetscDrawScalePopup(popup, vbound[0], vbound[1]);CHKERRQ(ierr); 220d1df6f1dSMatthew G. Knepley ierr = PetscDrawSetCoordinates(draw, bound[0], bound[1], bound[2], bound[3]);CHKERRQ(ierr); 221e412dcbdSMatthew G. Knepley 222d1df6f1dSMatthew G. Knepley ierr = VecGetArrayRead(fv, &array);CHKERRQ(ierr); 223e412dcbdSMatthew G. Knepley for (c = cStart; c < cEnd; ++c) { 22499a2f7bcSMatthew G. Knepley PetscScalar *coords = NULL, *a = NULL; 225e56f9228SJed Brown PetscInt numCoords, color[4] = {-1,-1,-1,-1}; 226e412dcbdSMatthew G. Knepley 227d1df6f1dSMatthew G. Knepley ierr = DMPlexPointLocalRead(fdm, c, array, &a);CHKERRQ(ierr); 228339e3443SMatthew G. Knepley if (a) { 229d1df6f1dSMatthew G. Knepley color[0] = PetscDrawRealToColor(PetscRealPart(a[comp]), vbound[0], vbound[1]); 230339e3443SMatthew G. Knepley color[1] = color[2] = color[3] = color[0]; 231339e3443SMatthew G. Knepley } else { 232339e3443SMatthew G. Knepley PetscScalar *vals = NULL; 233339e3443SMatthew G. Knepley PetscInt numVals, va; 234339e3443SMatthew G. Knepley 235d1df6f1dSMatthew G. Knepley ierr = DMPlexVecGetClosure(fdm, NULL, fv, c, &numVals, &vals);CHKERRQ(ierr); 236d1df6f1dSMatthew G. Knepley if (numVals % Nc) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "The number of components %D does not divide the number of values in the closure %D", Nc, numVals); 237d1df6f1dSMatthew G. Knepley switch (numVals/Nc) { 238d1df6f1dSMatthew G. Knepley case 3: /* P1 Triangle */ 239d1df6f1dSMatthew G. Knepley case 4: /* P1 Quadrangle */ 240d1df6f1dSMatthew G. Knepley for (va = 0; va < numVals/Nc; ++va) color[va] = PetscDrawRealToColor(PetscRealPart(vals[va*Nc+comp]), vbound[0], vbound[1]); 241339e3443SMatthew G. Knepley break; 242d1df6f1dSMatthew G. Knepley case 6: /* P2 Triangle */ 243d1df6f1dSMatthew G. Knepley case 8: /* P2 Quadrangle */ 244d1df6f1dSMatthew G. Knepley for (va = 0; va < numVals/(Nc*2); ++va) color[va] = PetscDrawRealToColor(PetscRealPart(vals[va*Nc+comp + numVals/(Nc*2)]), vbound[0], vbound[1]); 245d1df6f1dSMatthew G. Knepley break; 246d1df6f1dSMatthew G. Knepley default: SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Number of values for cell closure %D cannot be handled", numVals/Nc); 247339e3443SMatthew G. Knepley } 248d1df6f1dSMatthew G. Knepley ierr = DMPlexVecRestoreClosure(fdm, NULL, fv, c, &numVals, &vals);CHKERRQ(ierr); 249339e3443SMatthew G. Knepley } 250e412dcbdSMatthew G. Knepley ierr = DMPlexVecGetClosure(dm, coordSection, coordinates, c, &numCoords, &coords);CHKERRQ(ierr); 251e412dcbdSMatthew G. Knepley switch (numCoords) { 252e412dcbdSMatthew G. Knepley case 6: 253339e3443SMatthew G. Knepley ierr = PetscDrawTriangle(draw, PetscRealPart(coords[0]), PetscRealPart(coords[1]), PetscRealPart(coords[2]), PetscRealPart(coords[3]), PetscRealPart(coords[4]), PetscRealPart(coords[5]), color[0], color[1], color[2]);CHKERRQ(ierr); 254e412dcbdSMatthew G. Knepley break; 255e412dcbdSMatthew G. Knepley case 8: 256339e3443SMatthew G. Knepley ierr = PetscDrawTriangle(draw, PetscRealPart(coords[0]), PetscRealPart(coords[1]), PetscRealPart(coords[2]), PetscRealPart(coords[3]), PetscRealPart(coords[4]), PetscRealPart(coords[5]), color[0], color[1], color[2]);CHKERRQ(ierr); 257339e3443SMatthew G. Knepley ierr = PetscDrawTriangle(draw, PetscRealPart(coords[4]), PetscRealPart(coords[5]), PetscRealPart(coords[6]), PetscRealPart(coords[7]), PetscRealPart(coords[0]), PetscRealPart(coords[1]), color[2], color[3], color[0]);CHKERRQ(ierr); 258e412dcbdSMatthew G. Knepley break; 259e412dcbdSMatthew G. Knepley default: SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_SUP, "Cannot draw cells with %D coordinates", numCoords); 260e412dcbdSMatthew G. Knepley } 261e412dcbdSMatthew G. Knepley ierr = DMPlexVecRestoreClosure(dm, coordSection, coordinates, c, &numCoords, &coords);CHKERRQ(ierr); 262e412dcbdSMatthew G. Knepley } 263d1df6f1dSMatthew G. Knepley ierr = VecRestoreArrayRead(fv, &array);CHKERRQ(ierr); 264e412dcbdSMatthew G. Knepley ierr = PetscDrawFlush(draw);CHKERRQ(ierr); 265e412dcbdSMatthew G. Knepley ierr = PetscDrawPause(draw);CHKERRQ(ierr); 266e412dcbdSMatthew G. Knepley ierr = PetscDrawSave(draw);CHKERRQ(ierr); 267d1df6f1dSMatthew G. Knepley } 268d1df6f1dSMatthew G. Knepley if (Nf > 1) { 269d1df6f1dSMatthew G. Knepley ierr = VecRestoreSubVector(v, fis, &fv);CHKERRQ(ierr); 270d1df6f1dSMatthew G. Knepley ierr = ISDestroy(&fis);CHKERRQ(ierr); 271d1df6f1dSMatthew G. Knepley ierr = DMDestroy(&fdm);CHKERRQ(ierr); 272d1df6f1dSMatthew G. Knepley } 273d1df6f1dSMatthew G. Knepley } 274e412dcbdSMatthew G. Knepley PetscFunctionReturn(0); 275e412dcbdSMatthew G. Knepley } 276e412dcbdSMatthew G. Knepley 277684b87d9SLisandro Dalcin static PetscErrorCode VecView_Plex_Local_VTK(Vec v, PetscViewer viewer) 278684b87d9SLisandro Dalcin { 279684b87d9SLisandro Dalcin DM dm; 280684b87d9SLisandro Dalcin Vec locv; 281684b87d9SLisandro Dalcin const char *name; 282684b87d9SLisandro Dalcin PetscSection section; 283684b87d9SLisandro Dalcin PetscInt pStart, pEnd; 284684b87d9SLisandro Dalcin PetscViewerVTKFieldType ft; 285684b87d9SLisandro Dalcin PetscErrorCode ierr; 286684b87d9SLisandro Dalcin 287684b87d9SLisandro Dalcin PetscFunctionBegin; 288684b87d9SLisandro Dalcin ierr = VecGetDM(v, &dm);CHKERRQ(ierr); 289684b87d9SLisandro Dalcin ierr = DMCreateLocalVector(dm, &locv);CHKERRQ(ierr); /* VTK viewer requires exclusive ownership of the vector */ 290684b87d9SLisandro Dalcin ierr = PetscObjectGetName((PetscObject) v, &name);CHKERRQ(ierr); 291684b87d9SLisandro Dalcin ierr = PetscObjectSetName((PetscObject) locv, name);CHKERRQ(ierr); 292684b87d9SLisandro Dalcin ierr = VecCopy(v, locv);CHKERRQ(ierr); 293e87a4003SBarry Smith ierr = DMGetSection(dm, §ion);CHKERRQ(ierr); 294684b87d9SLisandro Dalcin ierr = DMPlexGetFieldType_Internal(dm, section, PETSC_DETERMINE, &pStart, &pEnd, &ft);CHKERRQ(ierr); 295a8f87f1dSPatrick Sanan ierr = PetscViewerVTKAddField(viewer, (PetscObject) dm, DMPlexVTKWriteAll, ft, PETSC_TRUE,(PetscObject) locv);CHKERRQ(ierr); 296684b87d9SLisandro Dalcin PetscFunctionReturn(0); 297684b87d9SLisandro Dalcin } 298684b87d9SLisandro Dalcin 299552f7358SJed Brown PetscErrorCode VecView_Plex_Local(Vec v, PetscViewer viewer) 300552f7358SJed Brown { 301552f7358SJed Brown DM dm; 302684b87d9SLisandro Dalcin PetscBool isvtk, ishdf5, isdraw, isglvis; 303552f7358SJed Brown PetscErrorCode ierr; 304552f7358SJed Brown 305552f7358SJed Brown PetscFunctionBegin; 306552f7358SJed Brown ierr = VecGetDM(v, &dm);CHKERRQ(ierr); 30782f516ccSBarry Smith if (!dm) SETERRQ(PetscObjectComm((PetscObject)v), PETSC_ERR_ARG_WRONG, "Vector not generated from a DM"); 308552f7358SJed Brown ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERVTK, &isvtk);CHKERRQ(ierr); 309b136c2c9SMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERHDF5, &ishdf5);CHKERRQ(ierr); 310f13a32a3SMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERDRAW, &isdraw);CHKERRQ(ierr); 3118135c375SStefano Zampini ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERGLVIS, &isglvis);CHKERRQ(ierr); 312684b87d9SLisandro Dalcin if (isvtk || ishdf5 || isdraw || isglvis) { 313684b87d9SLisandro Dalcin PetscInt i,numFields; 314684b87d9SLisandro Dalcin PetscObject fe; 315ef31f671SMatthew G. Knepley PetscBool fem = PETSC_FALSE; 316684b87d9SLisandro Dalcin Vec locv = v; 317684b87d9SLisandro Dalcin const char *name; 318684b87d9SLisandro Dalcin PetscInt step; 319684b87d9SLisandro Dalcin PetscReal time; 320ef31f671SMatthew G. Knepley 321ef31f671SMatthew G. Knepley ierr = DMGetNumFields(dm, &numFields);CHKERRQ(ierr); 322684b87d9SLisandro Dalcin for (i=0; i<numFields; i++) { 323684b87d9SLisandro Dalcin ierr = DMGetField(dm, i, &fe);CHKERRQ(ierr); 324684b87d9SLisandro Dalcin if (fe->classid == PETSCFE_CLASSID) { fem = PETSC_TRUE; break; } 325ef31f671SMatthew G. Knepley } 326684b87d9SLisandro Dalcin if (fem) { 327684b87d9SLisandro Dalcin ierr = DMGetLocalVector(dm, &locv);CHKERRQ(ierr); 328684b87d9SLisandro Dalcin ierr = PetscObjectGetName((PetscObject) v, &name);CHKERRQ(ierr); 329684b87d9SLisandro Dalcin ierr = PetscObjectSetName((PetscObject) locv, name);CHKERRQ(ierr); 330684b87d9SLisandro Dalcin ierr = VecCopy(v, locv);CHKERRQ(ierr); 331684b87d9SLisandro Dalcin ierr = DMGetOutputSequenceNumber(dm, NULL, &time);CHKERRQ(ierr); 332684b87d9SLisandro Dalcin ierr = DMPlexInsertBoundaryValues(dm, PETSC_TRUE, locv, time, NULL, NULL, NULL);CHKERRQ(ierr); 333ef31f671SMatthew G. Knepley } 334552f7358SJed Brown if (isvtk) { 335684b87d9SLisandro Dalcin ierr = VecView_Plex_Local_VTK(locv, viewer);CHKERRQ(ierr); 336b136c2c9SMatthew G. Knepley } else if (ishdf5) { 337b136c2c9SMatthew G. Knepley #if defined(PETSC_HAVE_HDF5) 338684b87d9SLisandro Dalcin ierr = VecView_Plex_Local_HDF5_Internal(locv, viewer);CHKERRQ(ierr); 339b136c2c9SMatthew G. Knepley #else 340b136c2c9SMatthew G. Knepley SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_SUP, "HDF5 not supported in this build.\nPlease reconfigure using --download-hdf5"); 341b136c2c9SMatthew G. Knepley #endif 342f13a32a3SMatthew G. Knepley } else if (isdraw) { 343684b87d9SLisandro Dalcin ierr = VecView_Plex_Local_Draw(locv, viewer);CHKERRQ(ierr); 344684b87d9SLisandro Dalcin } else if (isglvis) { 345684b87d9SLisandro Dalcin ierr = DMGetOutputSequenceNumber(dm, &step, NULL);CHKERRQ(ierr); 346684b87d9SLisandro Dalcin ierr = PetscViewerGLVisSetSnapId(viewer, step);CHKERRQ(ierr); 347684b87d9SLisandro Dalcin ierr = VecView_GLVis(locv, viewer);CHKERRQ(ierr); 348684b87d9SLisandro Dalcin } 349684b87d9SLisandro Dalcin if (fem) {ierr = DMRestoreLocalVector(dm, &locv);CHKERRQ(ierr);} 350552f7358SJed Brown } else { 351684b87d9SLisandro Dalcin PetscBool isseq; 352684b87d9SLisandro Dalcin 353684b87d9SLisandro Dalcin ierr = PetscObjectTypeCompare((PetscObject) v, VECSEQ, &isseq);CHKERRQ(ierr); 35455f2e967SMatthew G. Knepley if (isseq) {ierr = VecView_Seq(v, viewer);CHKERRQ(ierr);} 35555f2e967SMatthew G. Knepley else {ierr = VecView_MPI(v, viewer);CHKERRQ(ierr);} 356552f7358SJed Brown } 357552f7358SJed Brown PetscFunctionReturn(0); 358552f7358SJed Brown } 359552f7358SJed Brown 360552f7358SJed Brown PetscErrorCode VecView_Plex(Vec v, PetscViewer viewer) 361552f7358SJed Brown { 362552f7358SJed Brown DM dm; 363684b87d9SLisandro Dalcin PetscBool isvtk, ishdf5, isdraw, isglvis; 364552f7358SJed Brown PetscErrorCode ierr; 365552f7358SJed Brown 366552f7358SJed Brown PetscFunctionBegin; 367552f7358SJed Brown ierr = VecGetDM(v, &dm);CHKERRQ(ierr); 36882f516ccSBarry Smith if (!dm) SETERRQ(PetscObjectComm((PetscObject)v), PETSC_ERR_ARG_WRONG, "Vector not generated from a DM"); 369552f7358SJed Brown ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERVTK, &isvtk);CHKERRQ(ierr); 37033c3e6b4SMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERHDF5, &ishdf5);CHKERRQ(ierr); 371e412dcbdSMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERDRAW, &isdraw);CHKERRQ(ierr); 3728135c375SStefano Zampini ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERGLVIS, &isglvis);CHKERRQ(ierr); 373684b87d9SLisandro Dalcin if (isvtk || isdraw || isglvis) { 374552f7358SJed Brown Vec locv; 375552f7358SJed Brown const char *name; 376552f7358SJed Brown 377c8dd51e9SBarry Smith ierr = DMGetLocalVector(dm, &locv);CHKERRQ(ierr); 378552f7358SJed Brown ierr = PetscObjectGetName((PetscObject) v, &name);CHKERRQ(ierr); 379552f7358SJed Brown ierr = PetscObjectSetName((PetscObject) locv, name);CHKERRQ(ierr); 380552f7358SJed Brown ierr = DMGlobalToLocalBegin(dm, v, INSERT_VALUES, locv);CHKERRQ(ierr); 381552f7358SJed Brown ierr = DMGlobalToLocalEnd(dm, v, INSERT_VALUES, locv);CHKERRQ(ierr); 382552f7358SJed Brown ierr = VecView_Plex_Local(locv, viewer);CHKERRQ(ierr); 383c8dd51e9SBarry Smith ierr = DMRestoreLocalVector(dm, &locv);CHKERRQ(ierr); 384b136c2c9SMatthew G. Knepley } else if (ishdf5) { 385b136c2c9SMatthew G. Knepley #if defined(PETSC_HAVE_HDF5) 38639d25373SMatthew G. Knepley ierr = VecView_Plex_HDF5_Internal(v, viewer);CHKERRQ(ierr); 387b136c2c9SMatthew G. Knepley #else 388b136c2c9SMatthew G. Knepley SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_SUP, "HDF5 not supported in this build.\nPlease reconfigure using --download-hdf5"); 389b136c2c9SMatthew G. Knepley #endif 390552f7358SJed Brown } else { 391684b87d9SLisandro Dalcin PetscBool isseq; 392684b87d9SLisandro Dalcin 393684b87d9SLisandro Dalcin ierr = PetscObjectTypeCompare((PetscObject) v, VECSEQ, &isseq);CHKERRQ(ierr); 39455f2e967SMatthew G. Knepley if (isseq) {ierr = VecView_Seq(v, viewer);CHKERRQ(ierr);} 39555f2e967SMatthew G. Knepley else {ierr = VecView_MPI(v, viewer);CHKERRQ(ierr);} 396552f7358SJed Brown } 397552f7358SJed Brown PetscFunctionReturn(0); 398552f7358SJed Brown } 399552f7358SJed Brown 400d930f514SMatthew G. Knepley PetscErrorCode VecView_Plex_Native(Vec originalv, PetscViewer viewer) 401d930f514SMatthew G. Knepley { 402d930f514SMatthew G. Knepley DM dm; 403d930f514SMatthew G. Knepley MPI_Comm comm; 404d930f514SMatthew G. Knepley PetscViewerFormat format; 405d930f514SMatthew G. Knepley Vec v; 406d930f514SMatthew G. Knepley PetscBool isvtk, ishdf5; 407d930f514SMatthew G. Knepley PetscErrorCode ierr; 408d930f514SMatthew G. Knepley 409d930f514SMatthew G. Knepley PetscFunctionBegin; 410d930f514SMatthew G. Knepley ierr = VecGetDM(originalv, &dm);CHKERRQ(ierr); 411d930f514SMatthew G. Knepley ierr = PetscObjectGetComm((PetscObject) originalv, &comm);CHKERRQ(ierr); 4122c4c0c81SMatthew G. Knepley if (!dm) SETERRQ(comm, PETSC_ERR_ARG_WRONG, "Vector not generated from a DM"); 413d930f514SMatthew G. Knepley ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr); 414d930f514SMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERHDF5, &ishdf5);CHKERRQ(ierr); 415d930f514SMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERVTK, &isvtk);CHKERRQ(ierr); 416d930f514SMatthew G. Knepley if (format == PETSC_VIEWER_NATIVE) { 417d930f514SMatthew G. Knepley const char *vecname; 418d930f514SMatthew G. Knepley PetscInt n, nroots; 419d930f514SMatthew G. Knepley 420d930f514SMatthew G. Knepley if (dm->sfNatural) { 421ca43db0aSBarry Smith ierr = VecGetLocalSize(originalv, &n);CHKERRQ(ierr); 422d930f514SMatthew G. Knepley ierr = PetscSFGetGraph(dm->sfNatural, &nroots, NULL, NULL, NULL);CHKERRQ(ierr); 423d930f514SMatthew G. Knepley if (n == nroots) { 424d930f514SMatthew G. Knepley ierr = DMGetGlobalVector(dm, &v);CHKERRQ(ierr); 425d930f514SMatthew G. Knepley ierr = DMPlexGlobalToNaturalBegin(dm, originalv, v);CHKERRQ(ierr); 426d930f514SMatthew G. Knepley ierr = DMPlexGlobalToNaturalEnd(dm, originalv, v);CHKERRQ(ierr); 427d930f514SMatthew G. Knepley ierr = PetscObjectGetName((PetscObject) originalv, &vecname);CHKERRQ(ierr); 428d930f514SMatthew G. Knepley ierr = PetscObjectSetName((PetscObject) v, vecname);CHKERRQ(ierr); 429d930f514SMatthew G. Knepley } else SETERRQ(comm, PETSC_ERR_ARG_WRONG, "DM global to natural SF only handles global vectors"); 430d930f514SMatthew G. Knepley } else SETERRQ(comm, PETSC_ERR_ARG_WRONGSTATE, "DM global to natural SF was not created"); 431d930f514SMatthew G. Knepley } else { 432d930f514SMatthew G. Knepley /* we are viewing a natural DMPlex vec. */ 433d930f514SMatthew G. Knepley v = originalv; 434d930f514SMatthew G. Knepley } 435d930f514SMatthew G. Knepley if (ishdf5) { 436d930f514SMatthew G. Knepley #if defined(PETSC_HAVE_HDF5) 43739d25373SMatthew G. Knepley ierr = VecView_Plex_HDF5_Native_Internal(v, viewer);CHKERRQ(ierr); 438d930f514SMatthew G. Knepley #else 439d930f514SMatthew G. Knepley SETERRQ(comm, PETSC_ERR_SUP, "HDF5 not supported in this build.\nPlease reconfigure using --download-hdf5"); 440d930f514SMatthew G. Knepley #endif 441d930f514SMatthew G. Knepley } else if (isvtk) { 442d930f514SMatthew G. Knepley SETERRQ(comm, PETSC_ERR_SUP, "VTK format does not support viewing in natural order. Please switch to HDF5."); 443d930f514SMatthew G. Knepley } else { 444d930f514SMatthew G. Knepley PetscBool isseq; 445d930f514SMatthew G. Knepley 446d930f514SMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) v, VECSEQ, &isseq);CHKERRQ(ierr); 447d930f514SMatthew G. Knepley if (isseq) {ierr = VecView_Seq(v, viewer);CHKERRQ(ierr);} 448d930f514SMatthew G. Knepley else {ierr = VecView_MPI(v, viewer);CHKERRQ(ierr);} 449d930f514SMatthew G. Knepley } 450d930f514SMatthew G. Knepley if (format == PETSC_VIEWER_NATIVE) {ierr = DMRestoreGlobalVector(dm, &v);CHKERRQ(ierr);} 451d930f514SMatthew G. Knepley PetscFunctionReturn(0); 452d930f514SMatthew G. Knepley } 453d930f514SMatthew G. Knepley 4542c40f234SMatthew G. Knepley PetscErrorCode VecLoad_Plex_Local(Vec v, PetscViewer viewer) 4552c40f234SMatthew G. Knepley { 4562c40f234SMatthew G. Knepley DM dm; 4572c40f234SMatthew G. Knepley PetscBool ishdf5; 4582c40f234SMatthew G. Knepley PetscErrorCode ierr; 4592c40f234SMatthew G. Knepley 4602c40f234SMatthew G. Knepley PetscFunctionBegin; 4612c40f234SMatthew G. Knepley ierr = VecGetDM(v, &dm);CHKERRQ(ierr); 4622c40f234SMatthew G. Knepley if (!dm) SETERRQ(PetscObjectComm((PetscObject)v), PETSC_ERR_ARG_WRONG, "Vector not generated from a DM"); 4632c40f234SMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERHDF5, &ishdf5);CHKERRQ(ierr); 4642c40f234SMatthew G. Knepley if (ishdf5) { 4652c40f234SMatthew G. Knepley DM dmBC; 4662c40f234SMatthew G. Knepley Vec gv; 4672c40f234SMatthew G. Knepley const char *name; 4682c40f234SMatthew G. Knepley 4692c40f234SMatthew G. Knepley ierr = DMGetOutputDM(dm, &dmBC);CHKERRQ(ierr); 4702c40f234SMatthew G. Knepley ierr = DMGetGlobalVector(dmBC, &gv);CHKERRQ(ierr); 4712c40f234SMatthew G. Knepley ierr = PetscObjectGetName((PetscObject) v, &name);CHKERRQ(ierr); 4722c40f234SMatthew G. Knepley ierr = PetscObjectSetName((PetscObject) gv, name);CHKERRQ(ierr); 4732c40f234SMatthew G. Knepley ierr = VecLoad_Default(gv, viewer);CHKERRQ(ierr); 4742c40f234SMatthew G. Knepley ierr = DMGlobalToLocalBegin(dmBC, gv, INSERT_VALUES, v);CHKERRQ(ierr); 4752c40f234SMatthew G. Knepley ierr = DMGlobalToLocalEnd(dmBC, gv, INSERT_VALUES, v);CHKERRQ(ierr); 4762c40f234SMatthew G. Knepley ierr = DMRestoreGlobalVector(dmBC, &gv);CHKERRQ(ierr); 4772c40f234SMatthew G. Knepley } else { 4782c40f234SMatthew G. Knepley ierr = VecLoad_Default(v, viewer);CHKERRQ(ierr); 4792c40f234SMatthew G. Knepley } 4802c40f234SMatthew G. Knepley PetscFunctionReturn(0); 4812c40f234SMatthew G. Knepley } 4822c40f234SMatthew G. Knepley 4832c40f234SMatthew G. Knepley PetscErrorCode VecLoad_Plex(Vec v, PetscViewer viewer) 4842c40f234SMatthew G. Knepley { 4852c40f234SMatthew G. Knepley DM dm; 4862c40f234SMatthew G. Knepley PetscBool ishdf5; 4872c40f234SMatthew G. Knepley PetscErrorCode ierr; 4882c40f234SMatthew G. Knepley 4892c40f234SMatthew G. Knepley PetscFunctionBegin; 4902c40f234SMatthew G. Knepley ierr = VecGetDM(v, &dm);CHKERRQ(ierr); 4912c40f234SMatthew G. Knepley if (!dm) SETERRQ(PetscObjectComm((PetscObject)v), PETSC_ERR_ARG_WRONG, "Vector not generated from a DM"); 4922c40f234SMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERHDF5, &ishdf5);CHKERRQ(ierr); 4932c40f234SMatthew G. Knepley if (ishdf5) { 494878b459fSMatthew G. Knepley #if defined(PETSC_HAVE_HDF5) 49539d25373SMatthew G. Knepley ierr = VecLoad_Plex_HDF5_Internal(v, viewer);CHKERRQ(ierr); 496b136c2c9SMatthew G. Knepley #else 497b136c2c9SMatthew G. Knepley SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_SUP, "HDF5 not supported in this build.\nPlease reconfigure using --download-hdf5"); 498878b459fSMatthew G. Knepley #endif 4992c40f234SMatthew G. Knepley } else { 5002c40f234SMatthew G. Knepley ierr = VecLoad_Default(v, viewer);CHKERRQ(ierr); 501552f7358SJed Brown } 502552f7358SJed Brown PetscFunctionReturn(0); 503552f7358SJed Brown } 504552f7358SJed Brown 505d930f514SMatthew G. Knepley PetscErrorCode VecLoad_Plex_Native(Vec originalv, PetscViewer viewer) 506d930f514SMatthew G. Knepley { 507d930f514SMatthew G. Knepley DM dm; 508d930f514SMatthew G. Knepley PetscViewerFormat format; 509d930f514SMatthew G. Knepley PetscBool ishdf5; 510d930f514SMatthew G. Knepley PetscErrorCode ierr; 511d930f514SMatthew G. Knepley 512d930f514SMatthew G. Knepley PetscFunctionBegin; 513d930f514SMatthew G. Knepley ierr = VecGetDM(originalv, &dm);CHKERRQ(ierr); 514d930f514SMatthew G. Knepley if (!dm) SETERRQ(PetscObjectComm((PetscObject) originalv), PETSC_ERR_ARG_WRONG, "Vector not generated from a DM"); 515d930f514SMatthew G. Knepley ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr); 516d930f514SMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERHDF5, &ishdf5);CHKERRQ(ierr); 517d930f514SMatthew G. Knepley if (format == PETSC_VIEWER_NATIVE) { 518d930f514SMatthew G. Knepley if (dm->sfNatural) { 519d930f514SMatthew G. Knepley if (ishdf5) { 520d930f514SMatthew G. Knepley #if defined(PETSC_HAVE_HDF5) 521d930f514SMatthew G. Knepley Vec v; 522d930f514SMatthew G. Knepley const char *vecname; 523d930f514SMatthew G. Knepley 524d930f514SMatthew G. Knepley ierr = DMGetGlobalVector(dm, &v);CHKERRQ(ierr); 525d930f514SMatthew G. Knepley ierr = PetscObjectGetName((PetscObject) originalv, &vecname);CHKERRQ(ierr); 526d930f514SMatthew G. Knepley ierr = PetscObjectSetName((PetscObject) v, vecname);CHKERRQ(ierr); 52739d25373SMatthew G. Knepley ierr = VecLoad_Plex_HDF5_Native_Internal(v, viewer);CHKERRQ(ierr); 528d930f514SMatthew G. Knepley ierr = DMPlexNaturalToGlobalBegin(dm, v, originalv);CHKERRQ(ierr); 529d930f514SMatthew G. Knepley ierr = DMPlexNaturalToGlobalEnd(dm, v, originalv);CHKERRQ(ierr); 530d930f514SMatthew G. Knepley ierr = DMRestoreGlobalVector(dm, &v);CHKERRQ(ierr); 531d930f514SMatthew G. Knepley #else 532d930f514SMatthew G. Knepley SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_SUP, "HDF5 not supported in this build.\nPlease reconfigure using --download-hdf5"); 533d930f514SMatthew G. Knepley #endif 534d930f514SMatthew G. Knepley } else SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_SUP, "Reading in natural order is not supported for anything but HDF5."); 535d930f514SMatthew G. Knepley } 536d930f514SMatthew G. Knepley } 537d930f514SMatthew G. Knepley PetscFunctionReturn(0); 538d930f514SMatthew G. Knepley } 539d930f514SMatthew G. Knepley 5407cd05799SMatthew G. Knepley PETSC_UNUSED static PetscErrorCode DMPlexView_Ascii_Geometry(DM dm, PetscViewer viewer) 541731e8ddeSMatthew G. Knepley { 542731e8ddeSMatthew G. Knepley PetscSection coordSection; 543731e8ddeSMatthew G. Knepley Vec coordinates; 544731e8ddeSMatthew G. Knepley DMLabel depthLabel; 545731e8ddeSMatthew G. Knepley const char *name[4]; 546731e8ddeSMatthew G. Knepley const PetscScalar *a; 547731e8ddeSMatthew G. Knepley PetscInt dim, pStart, pEnd, cStart, cEnd, c; 548731e8ddeSMatthew G. Knepley PetscErrorCode ierr; 549731e8ddeSMatthew G. Knepley 550731e8ddeSMatthew G. Knepley PetscFunctionBegin; 551731e8ddeSMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 552731e8ddeSMatthew G. Knepley ierr = DMGetCoordinatesLocal(dm, &coordinates);CHKERRQ(ierr); 553731e8ddeSMatthew G. Knepley ierr = DMGetCoordinateSection(dm, &coordSection);CHKERRQ(ierr); 554731e8ddeSMatthew G. Knepley ierr = DMPlexGetDepthLabel(dm, &depthLabel);CHKERRQ(ierr); 555731e8ddeSMatthew G. Knepley ierr = DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd);CHKERRQ(ierr); 556731e8ddeSMatthew G. Knepley ierr = PetscSectionGetChart(coordSection, &pStart, &pEnd);CHKERRQ(ierr); 557731e8ddeSMatthew G. Knepley ierr = VecGetArrayRead(coordinates, &a);CHKERRQ(ierr); 558731e8ddeSMatthew G. Knepley name[0] = "vertex"; 559731e8ddeSMatthew G. Knepley name[1] = "edge"; 560731e8ddeSMatthew G. Knepley name[dim-1] = "face"; 561731e8ddeSMatthew G. Knepley name[dim] = "cell"; 562731e8ddeSMatthew G. Knepley for (c = cStart; c < cEnd; ++c) { 563731e8ddeSMatthew G. Knepley PetscInt *closure = NULL; 564731e8ddeSMatthew G. Knepley PetscInt closureSize, cl; 565731e8ddeSMatthew G. Knepley 566f347f43bSBarry Smith ierr = PetscViewerASCIIPrintf(viewer, "Geometry for cell %D:\n", c);CHKERRQ(ierr); 567731e8ddeSMatthew G. Knepley ierr = DMPlexGetTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 568731e8ddeSMatthew G. Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 569731e8ddeSMatthew G. Knepley for (cl = 0; cl < closureSize*2; cl += 2) { 570731e8ddeSMatthew G. Knepley PetscInt point = closure[cl], depth, dof, off, d, p; 571731e8ddeSMatthew G. Knepley 572731e8ddeSMatthew G. Knepley if ((point < pStart) || (point >= pEnd)) continue; 573731e8ddeSMatthew G. Knepley ierr = PetscSectionGetDof(coordSection, point, &dof);CHKERRQ(ierr); 574731e8ddeSMatthew G. Knepley if (!dof) continue; 575731e8ddeSMatthew G. Knepley ierr = DMLabelGetValue(depthLabel, point, &depth);CHKERRQ(ierr); 576731e8ddeSMatthew G. Knepley ierr = PetscSectionGetOffset(coordSection, point, &off);CHKERRQ(ierr); 577f347f43bSBarry Smith ierr = PetscViewerASCIIPrintf(viewer, "%s %D coords:", name[depth], point);CHKERRQ(ierr); 578731e8ddeSMatthew G. Knepley for (p = 0; p < dof/dim; ++p) { 579731e8ddeSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " (");CHKERRQ(ierr); 580731e8ddeSMatthew G. Knepley for (d = 0; d < dim; ++d) { 581731e8ddeSMatthew G. Knepley if (d > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);} 58241477eefSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "%g", PetscRealPart(a[off+p*dim+d]));CHKERRQ(ierr); 583731e8ddeSMatthew G. Knepley } 584731e8ddeSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, ")");CHKERRQ(ierr); 585731e8ddeSMatthew G. Knepley } 586731e8ddeSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr); 587731e8ddeSMatthew G. Knepley } 588731e8ddeSMatthew G. Knepley ierr = DMPlexRestoreTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 589731e8ddeSMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 590731e8ddeSMatthew G. Knepley } 591731e8ddeSMatthew G. Knepley ierr = VecRestoreArrayRead(coordinates, &a);CHKERRQ(ierr); 592731e8ddeSMatthew G. Knepley PetscFunctionReturn(0); 593731e8ddeSMatthew G. Knepley } 594731e8ddeSMatthew G. Knepley 5957cd05799SMatthew G. Knepley static PetscErrorCode DMPlexView_Ascii(DM dm, PetscViewer viewer) 596552f7358SJed Brown { 597552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 598552f7358SJed Brown DM cdm; 599552f7358SJed Brown DMLabel markers; 600552f7358SJed Brown PetscSection coordSection; 601552f7358SJed Brown Vec coordinates; 602552f7358SJed Brown PetscViewerFormat format; 603552f7358SJed Brown PetscErrorCode ierr; 604552f7358SJed Brown 605552f7358SJed Brown PetscFunctionBegin; 606552f7358SJed Brown ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 607e87a4003SBarry Smith ierr = DMGetSection(cdm, &coordSection);CHKERRQ(ierr); 608552f7358SJed Brown ierr = DMGetCoordinatesLocal(dm, &coordinates);CHKERRQ(ierr); 609552f7358SJed Brown ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr); 610552f7358SJed Brown if (format == PETSC_VIEWER_ASCII_INFO_DETAIL) { 611552f7358SJed Brown const char *name; 612f73eea6eSMatthew G. Knepley PetscInt dim, cellHeight, maxConeSize, maxSupportSize; 613552f7358SJed Brown PetscInt pStart, pEnd, p; 614552f7358SJed Brown PetscMPIInt rank, size; 615552f7358SJed Brown 61682f516ccSBarry Smith ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)dm), &rank);CHKERRQ(ierr); 61782f516ccSBarry Smith ierr = MPI_Comm_size(PetscObjectComm((PetscObject)dm), &size);CHKERRQ(ierr); 618552f7358SJed Brown ierr = PetscObjectGetName((PetscObject) dm, &name);CHKERRQ(ierr); 619552f7358SJed Brown ierr = DMPlexGetChart(dm, &pStart, &pEnd);CHKERRQ(ierr); 620552f7358SJed Brown ierr = DMPlexGetMaxSizes(dm, &maxConeSize, &maxSupportSize);CHKERRQ(ierr); 621f73eea6eSMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 622f73eea6eSMatthew G. Knepley ierr = DMPlexGetVTKCellHeight(dm, &cellHeight);CHKERRQ(ierr); 623f73eea6eSMatthew G. Knepley if (name) {ierr = PetscViewerASCIIPrintf(viewer, "%s in %D dimension%s:\n", name, dim, dim == 1 ? "" : "s");CHKERRQ(ierr);} 624f73eea6eSMatthew G. Knepley else {ierr = PetscViewerASCIIPrintf(viewer, "Mesh in %D dimension%s:\n", dim, dim == 1 ? "" : "s");CHKERRQ(ierr);} 625f73eea6eSMatthew G. Knepley if (cellHeight) {ierr = PetscViewerASCIIPrintf(viewer, " Cells are at height %D\n", cellHeight);CHKERRQ(ierr);} 626e9cb465cSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "Supports:\n", name);CHKERRQ(ierr); 6274d4c343aSBarry Smith ierr = PetscViewerASCIIPushSynchronized(viewer);CHKERRQ(ierr); 628e9cb465cSMatthew G. Knepley ierr = PetscViewerASCIISynchronizedPrintf(viewer, "[%d] Max support size: %D\n", rank, maxSupportSize);CHKERRQ(ierr); 629552f7358SJed Brown for (p = pStart; p < pEnd; ++p) { 630552f7358SJed Brown PetscInt dof, off, s; 631552f7358SJed Brown 632552f7358SJed Brown ierr = PetscSectionGetDof(mesh->supportSection, p, &dof);CHKERRQ(ierr); 633552f7358SJed Brown ierr = PetscSectionGetOffset(mesh->supportSection, p, &off);CHKERRQ(ierr); 634552f7358SJed Brown for (s = off; s < off+dof; ++s) { 635e4b003c7SBarry Smith ierr = PetscViewerASCIISynchronizedPrintf(viewer, "[%d]: %D ----> %D\n", rank, p, mesh->supports[s]);CHKERRQ(ierr); 636552f7358SJed Brown } 637552f7358SJed Brown } 638552f7358SJed Brown ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); 639e9cb465cSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "Cones:\n", name);CHKERRQ(ierr); 640e9cb465cSMatthew G. Knepley ierr = PetscViewerASCIISynchronizedPrintf(viewer, "[%d] Max cone size: %D\n", rank, maxConeSize);CHKERRQ(ierr); 641552f7358SJed Brown for (p = pStart; p < pEnd; ++p) { 642552f7358SJed Brown PetscInt dof, off, c; 643552f7358SJed Brown 644552f7358SJed Brown ierr = PetscSectionGetDof(mesh->coneSection, p, &dof);CHKERRQ(ierr); 645552f7358SJed Brown ierr = PetscSectionGetOffset(mesh->coneSection, p, &off);CHKERRQ(ierr); 646552f7358SJed Brown for (c = off; c < off+dof; ++c) { 647e4b003c7SBarry Smith ierr = PetscViewerASCIISynchronizedPrintf(viewer, "[%d]: %D <---- %D (%D)\n", rank, p, mesh->cones[c], mesh->coneOrientations[c]);CHKERRQ(ierr); 648552f7358SJed Brown } 649552f7358SJed Brown } 650552f7358SJed Brown ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); 6514d4c343aSBarry Smith ierr = PetscViewerASCIIPopSynchronized(viewer);CHKERRQ(ierr); 6520298fd71SBarry Smith ierr = PetscSectionGetChart(coordSection, &pStart, NULL);CHKERRQ(ierr); 653552f7358SJed Brown if (pStart >= 0) {ierr = PetscSectionVecView(coordSection, coordinates, viewer);CHKERRQ(ierr);} 654c58f1c22SToby Isaac ierr = DMGetLabel(dm, "marker", &markers);CHKERRQ(ierr); 655552f7358SJed Brown ierr = DMLabelView(markers,viewer);CHKERRQ(ierr); 656552f7358SJed Brown if (size > 1) { 657552f7358SJed Brown PetscSF sf; 658552f7358SJed Brown 659552f7358SJed Brown ierr = DMGetPointSF(dm, &sf);CHKERRQ(ierr); 660552f7358SJed Brown ierr = PetscSFView(sf, viewer);CHKERRQ(ierr); 661552f7358SJed Brown } 662552f7358SJed Brown ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); 663552f7358SJed Brown } else if (format == PETSC_VIEWER_ASCII_LATEX) { 6640588280cSMatthew G. Knepley const char *name, *color; 6650588280cSMatthew G. Knepley const char *defcolors[3] = {"gray", "orange", "green"}; 6660588280cSMatthew G. Knepley const char *deflcolors[4] = {"blue", "cyan", "red", "magenta"}; 667552f7358SJed Brown PetscReal scale = 2.0; 6680588280cSMatthew G. Knepley PetscBool useNumbers = PETSC_TRUE, useLabels, useColors; 6690588280cSMatthew G. Knepley double tcoords[3]; 670552f7358SJed Brown PetscScalar *coords; 6710588280cSMatthew G. Knepley PetscInt numLabels, l, numColors, numLColors, dim, depth, cStart, cEnd, c, vStart, vEnd, v, eStart = 0, eEnd = 0, e, p; 672552f7358SJed Brown PetscMPIInt rank, size; 6730588280cSMatthew G. Knepley char **names, **colors, **lcolors; 674202fd40aSStefano Zampini PetscBool plotEdges, flg; 675552f7358SJed Brown 6760588280cSMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 677552f7358SJed Brown ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 678c58f1c22SToby Isaac ierr = DMGetNumLabels(dm, &numLabels);CHKERRQ(ierr); 6790588280cSMatthew G. Knepley numLabels = PetscMax(numLabels, 10); 6800588280cSMatthew G. Knepley numColors = 10; 6810588280cSMatthew G. Knepley numLColors = 10; 6820588280cSMatthew G. Knepley ierr = PetscCalloc3(numLabels, &names, numColors, &colors, numLColors, &lcolors);CHKERRQ(ierr); 683c5929fdfSBarry Smith ierr = PetscOptionsGetReal(((PetscObject) viewer)->options,((PetscObject) viewer)->prefix, "-dm_plex_view_scale", &scale, NULL);CHKERRQ(ierr); 684c5929fdfSBarry Smith ierr = PetscOptionsGetBool(((PetscObject) viewer)->options,((PetscObject) viewer)->prefix, "-dm_plex_view_numbers", &useNumbers, NULL);CHKERRQ(ierr); 685c5929fdfSBarry Smith ierr = PetscOptionsGetStringArray(((PetscObject) viewer)->options,((PetscObject) viewer)->prefix, "-dm_plex_view_labels", names, &numLabels, &useLabels);CHKERRQ(ierr); 6860588280cSMatthew G. Knepley if (!useLabels) numLabels = 0; 687c5929fdfSBarry Smith ierr = PetscOptionsGetStringArray(((PetscObject) viewer)->options,((PetscObject) viewer)->prefix, "-dm_plex_view_colors", colors, &numColors, &useColors);CHKERRQ(ierr); 6880588280cSMatthew G. Knepley if (!useColors) { 6890588280cSMatthew G. Knepley numColors = 3; 6900588280cSMatthew G. Knepley for (c = 0; c < numColors; ++c) {ierr = PetscStrallocpy(defcolors[c], &colors[c]);CHKERRQ(ierr);} 6910588280cSMatthew G. Knepley } 692c5929fdfSBarry Smith ierr = PetscOptionsGetStringArray(((PetscObject) viewer)->options,((PetscObject) viewer)->prefix, "-dm_plex_view_lcolors", lcolors, &numLColors, &useColors);CHKERRQ(ierr); 6930588280cSMatthew G. Knepley if (!useColors) { 6940588280cSMatthew G. Knepley numLColors = 4; 6950588280cSMatthew G. Knepley for (c = 0; c < numLColors; ++c) {ierr = PetscStrallocpy(deflcolors[c], &lcolors[c]);CHKERRQ(ierr);} 6960588280cSMatthew G. Knepley } 697202fd40aSStefano Zampini plotEdges = (PetscBool)(depth > 1 && useNumbers && dim < 3); 698202fd40aSStefano Zampini ierr = PetscOptionsGetBool(((PetscObject) viewer)->options,((PetscObject) viewer)->prefix, "-dm_plex_view_edges", &plotEdges, &flg);CHKERRQ(ierr); 699202fd40aSStefano Zampini if (flg && plotEdges && depth < dim) SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_SUP, "Mesh must be interpolated"); 700202fd40aSStefano Zampini if (depth < dim) plotEdges = PETSC_FALSE; 70182f516ccSBarry Smith ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)dm), &rank);CHKERRQ(ierr); 70282f516ccSBarry Smith ierr = MPI_Comm_size(PetscObjectComm((PetscObject)dm), &size);CHKERRQ(ierr); 703552f7358SJed Brown ierr = PetscObjectGetName((PetscObject) dm, &name);CHKERRQ(ierr); 704770b213bSMatthew G Knepley ierr = PetscViewerASCIIPrintf(viewer, "\ 7050588280cSMatthew G. Knepley \\documentclass[tikz]{standalone}\n\n\ 706552f7358SJed Brown \\usepackage{pgflibraryshapes}\n\ 707552f7358SJed Brown \\usetikzlibrary{backgrounds}\n\ 708552f7358SJed Brown \\usetikzlibrary{arrows}\n\ 7090588280cSMatthew G. Knepley \\begin{document}\n");CHKERRQ(ierr); 7100588280cSMatthew G. Knepley if (size > 1) { 711f738dd31SMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "%s for process ", name);CHKERRQ(ierr); 712770b213bSMatthew G Knepley for (p = 0; p < size; ++p) { 713770b213bSMatthew G Knepley if (p > 0 && p == size-1) { 714770b213bSMatthew G Knepley ierr = PetscViewerASCIIPrintf(viewer, ", and ", colors[p%numColors], p);CHKERRQ(ierr); 715770b213bSMatthew G Knepley } else if (p > 0) { 716770b213bSMatthew G Knepley ierr = PetscViewerASCIIPrintf(viewer, ", ", colors[p%numColors], p);CHKERRQ(ierr); 717770b213bSMatthew G Knepley } 718770b213bSMatthew G Knepley ierr = PetscViewerASCIIPrintf(viewer, "{\\textcolor{%s}%D}", colors[p%numColors], p);CHKERRQ(ierr); 719770b213bSMatthew G Knepley } 7200588280cSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, ".\n\n\n");CHKERRQ(ierr); 7210588280cSMatthew G. Knepley } 7220588280cSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "\\begin{tikzpicture}[scale = %g,font=\\fontsize{8}{8}\\selectfont]\n", 1.0);CHKERRQ(ierr); 723552f7358SJed Brown /* Plot vertices */ 724552f7358SJed Brown ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr); 725552f7358SJed Brown ierr = VecGetArray(coordinates, &coords);CHKERRQ(ierr); 7264d4c343aSBarry Smith ierr = PetscViewerASCIIPushSynchronized(viewer);CHKERRQ(ierr); 727552f7358SJed Brown for (v = vStart; v < vEnd; ++v) { 728552f7358SJed Brown PetscInt off, dof, d; 7290588280cSMatthew G. Knepley PetscBool isLabeled = PETSC_FALSE; 730552f7358SJed Brown 731552f7358SJed Brown ierr = PetscSectionGetDof(coordSection, v, &dof);CHKERRQ(ierr); 732552f7358SJed Brown ierr = PetscSectionGetOffset(coordSection, v, &off);CHKERRQ(ierr); 7330588280cSMatthew G. Knepley ierr = PetscViewerASCIISynchronizedPrintf(viewer, "\\path (");CHKERRQ(ierr); 734f6dae198SJed Brown if (PetscUnlikely(dof > 3)) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_PLIB,"coordSection vertex %D has dof %D > 3",v,dof); 7350588280cSMatthew G. Knepley for (d = 0; d < dof; ++d) { 7360588280cSMatthew G. Knepley tcoords[d] = (double) (scale*PetscRealPart(coords[off+d])); 737c068d9bbSLisandro Dalcin tcoords[d] = PetscAbs(tcoords[d]) < 1e-10 ? 0.0 : tcoords[d]; 7380588280cSMatthew G. Knepley } 7390588280cSMatthew G. Knepley /* Rotate coordinates since PGF makes z point out of the page instead of up */ 7400588280cSMatthew G. Knepley if (dim == 3) {PetscReal tmp = tcoords[1]; tcoords[1] = tcoords[2]; tcoords[2] = -tmp;} 741552f7358SJed Brown for (d = 0; d < dof; ++d) { 742552f7358SJed Brown if (d > 0) {ierr = PetscViewerASCIISynchronizedPrintf(viewer, ",");CHKERRQ(ierr);} 7430588280cSMatthew G. Knepley ierr = PetscViewerASCIISynchronizedPrintf(viewer, "%g", tcoords[d]);CHKERRQ(ierr); 744552f7358SJed Brown } 7450588280cSMatthew G. Knepley color = colors[rank%numColors]; 7460588280cSMatthew G. Knepley for (l = 0; l < numLabels; ++l) { 7470588280cSMatthew G. Knepley PetscInt val; 748c58f1c22SToby Isaac ierr = DMGetLabelValue(dm, names[l], v, &val);CHKERRQ(ierr); 7490588280cSMatthew G. Knepley if (val >= 0) {color = lcolors[l%numLColors]; isLabeled = PETSC_TRUE; break;} 7500588280cSMatthew G. Knepley } 7510588280cSMatthew G. Knepley if (useNumbers) { 752e4b003c7SBarry Smith ierr = PetscViewerASCIISynchronizedPrintf(viewer, ") node(%D_%d) [draw,shape=circle,color=%s] {%D};\n", v, rank, color, v);CHKERRQ(ierr); 7530588280cSMatthew G. Knepley } else { 754e4b003c7SBarry Smith ierr = PetscViewerASCIISynchronizedPrintf(viewer, ") node(%D_%d) [fill,inner sep=%dpt,shape=circle,color=%s] {};\n", v, rank, !isLabeled ? 1 : 2, color);CHKERRQ(ierr); 7550588280cSMatthew G. Knepley } 756552f7358SJed Brown } 757552f7358SJed Brown ierr = VecRestoreArray(coordinates, &coords);CHKERRQ(ierr); 758552f7358SJed Brown ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); 759846a3e8bSMatthew G. Knepley /* Plot cells */ 760846a3e8bSMatthew G. Knepley ierr = DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd);CHKERRQ(ierr); 761846a3e8bSMatthew G. Knepley if (dim == 3 || !useNumbers) { 762846a3e8bSMatthew G. Knepley for (e = eStart; e < eEnd; ++e) { 763846a3e8bSMatthew G. Knepley const PetscInt *cone; 764846a3e8bSMatthew G. Knepley 765846a3e8bSMatthew G. Knepley color = colors[rank%numColors]; 766846a3e8bSMatthew G. Knepley for (l = 0; l < numLabels; ++l) { 767846a3e8bSMatthew G. Knepley PetscInt val; 768846a3e8bSMatthew G. Knepley ierr = DMGetLabelValue(dm, names[l], e, &val);CHKERRQ(ierr); 769846a3e8bSMatthew G. Knepley if (val >= 0) {color = lcolors[l%numLColors]; break;} 770846a3e8bSMatthew G. Knepley } 771846a3e8bSMatthew G. Knepley ierr = DMPlexGetCone(dm, e, &cone);CHKERRQ(ierr); 772846a3e8bSMatthew G. Knepley ierr = PetscViewerASCIISynchronizedPrintf(viewer, "\\draw[color=%s] (%D_%d) -- (%D_%d);\n", color, cone[0], rank, cone[1], rank);CHKERRQ(ierr); 773846a3e8bSMatthew G. Knepley } 774846a3e8bSMatthew G. Knepley } else { 775846a3e8bSMatthew G. Knepley for (c = cStart; c < cEnd; ++c) { 776846a3e8bSMatthew G. Knepley PetscInt *closure = NULL; 777846a3e8bSMatthew G. Knepley PetscInt closureSize, firstPoint = -1; 778846a3e8bSMatthew G. Knepley 779846a3e8bSMatthew G. Knepley ierr = DMPlexGetTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 780846a3e8bSMatthew G. Knepley ierr = PetscViewerASCIISynchronizedPrintf(viewer, "\\draw[color=%s] ", colors[rank%numColors]);CHKERRQ(ierr); 781846a3e8bSMatthew G. Knepley for (p = 0; p < closureSize*2; p += 2) { 782846a3e8bSMatthew G. Knepley const PetscInt point = closure[p]; 783846a3e8bSMatthew G. Knepley 784846a3e8bSMatthew G. Knepley if ((point < vStart) || (point >= vEnd)) continue; 785846a3e8bSMatthew G. Knepley if (firstPoint >= 0) {ierr = PetscViewerASCIISynchronizedPrintf(viewer, " -- ");CHKERRQ(ierr);} 786846a3e8bSMatthew G. Knepley ierr = PetscViewerASCIISynchronizedPrintf(viewer, "(%D_%d)", point, rank);CHKERRQ(ierr); 787846a3e8bSMatthew G. Knepley if (firstPoint < 0) firstPoint = point; 788846a3e8bSMatthew G. Knepley } 789846a3e8bSMatthew G. Knepley /* Why doesn't this work? ierr = PetscViewerASCIISynchronizedPrintf(viewer, " -- cycle;\n");CHKERRQ(ierr); */ 790846a3e8bSMatthew G. Knepley ierr = PetscViewerASCIISynchronizedPrintf(viewer, " -- (%D_%d);\n", firstPoint, rank);CHKERRQ(ierr); 791846a3e8bSMatthew G. Knepley ierr = DMPlexRestoreTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 792846a3e8bSMatthew G. Knepley } 793846a3e8bSMatthew G. Knepley } 794846a3e8bSMatthew G. Knepley ierr = VecGetArray(coordinates, &coords);CHKERRQ(ierr); 795846a3e8bSMatthew G. Knepley for (c = cStart; c < cEnd; ++c) { 796846a3e8bSMatthew G. Knepley double ccoords[3] = {0.0, 0.0, 0.0}; 797846a3e8bSMatthew G. Knepley PetscBool isLabeled = PETSC_FALSE; 798846a3e8bSMatthew G. Knepley PetscInt *closure = NULL; 799846a3e8bSMatthew G. Knepley PetscInt closureSize, dof, d, n = 0; 800846a3e8bSMatthew G. Knepley 801846a3e8bSMatthew G. Knepley ierr = DMPlexGetTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 802846a3e8bSMatthew G. Knepley ierr = PetscViewerASCIISynchronizedPrintf(viewer, "\\path (");CHKERRQ(ierr); 803846a3e8bSMatthew G. Knepley for (p = 0; p < closureSize*2; p += 2) { 804846a3e8bSMatthew G. Knepley const PetscInt point = closure[p]; 805846a3e8bSMatthew G. Knepley PetscInt off; 806846a3e8bSMatthew G. Knepley 807846a3e8bSMatthew G. Knepley if ((point < vStart) || (point >= vEnd)) continue; 808846a3e8bSMatthew G. Knepley ierr = PetscSectionGetDof(coordSection, point, &dof);CHKERRQ(ierr); 809846a3e8bSMatthew G. Knepley ierr = PetscSectionGetOffset(coordSection, point, &off);CHKERRQ(ierr); 810846a3e8bSMatthew G. Knepley for (d = 0; d < dof; ++d) { 811846a3e8bSMatthew G. Knepley tcoords[d] = (double) (scale*PetscRealPart(coords[off+d])); 812846a3e8bSMatthew G. Knepley tcoords[d] = PetscAbs(tcoords[d]) < 1e-10 ? 0.0 : tcoords[d]; 813846a3e8bSMatthew G. Knepley } 814846a3e8bSMatthew G. Knepley /* Rotate coordinates since PGF makes z point out of the page instead of up */ 815846a3e8bSMatthew G. Knepley if (dof == 3) {PetscReal tmp = tcoords[1]; tcoords[1] = tcoords[2]; tcoords[2] = -tmp;} 816846a3e8bSMatthew G. Knepley for (d = 0; d < dof; ++d) {ccoords[d] += tcoords[d];} 817846a3e8bSMatthew G. Knepley ++n; 818846a3e8bSMatthew G. Knepley } 819846a3e8bSMatthew G. Knepley for (d = 0; d < dof; ++d) {ccoords[d] /= n;} 820846a3e8bSMatthew G. Knepley ierr = DMPlexRestoreTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 821846a3e8bSMatthew G. Knepley for (d = 0; d < dof; ++d) { 822846a3e8bSMatthew G. Knepley if (d > 0) {ierr = PetscViewerASCIISynchronizedPrintf(viewer, ",");CHKERRQ(ierr);} 823846a3e8bSMatthew G. Knepley ierr = PetscViewerASCIISynchronizedPrintf(viewer, "%g", ccoords[d]);CHKERRQ(ierr); 824846a3e8bSMatthew G. Knepley } 825846a3e8bSMatthew G. Knepley color = colors[rank%numColors]; 826846a3e8bSMatthew G. Knepley for (l = 0; l < numLabels; ++l) { 827846a3e8bSMatthew G. Knepley PetscInt val; 828846a3e8bSMatthew G. Knepley ierr = DMGetLabelValue(dm, names[l], c, &val);CHKERRQ(ierr); 829846a3e8bSMatthew G. Knepley if (val >= 0) {color = lcolors[l%numLColors]; isLabeled = PETSC_TRUE; break;} 830846a3e8bSMatthew G. Knepley } 831846a3e8bSMatthew G. Knepley if (useNumbers) { 832846a3e8bSMatthew G. Knepley ierr = PetscViewerASCIISynchronizedPrintf(viewer, ") node(%D_%d) [draw,shape=circle,color=%s] {%D};\n", c, rank, color, c);CHKERRQ(ierr); 833846a3e8bSMatthew G. Knepley } else { 834846a3e8bSMatthew G. Knepley ierr = PetscViewerASCIISynchronizedPrintf(viewer, ") node(%D_%d) [fill,inner sep=%dpt,shape=circle,color=%s] {};\n", c, rank, !isLabeled ? 1 : 2, color);CHKERRQ(ierr); 835846a3e8bSMatthew G. Knepley } 836846a3e8bSMatthew G. Knepley } 837846a3e8bSMatthew G. Knepley ierr = VecRestoreArray(coordinates, &coords);CHKERRQ(ierr); 838552f7358SJed Brown /* Plot edges */ 839202fd40aSStefano Zampini if (depth > 1 || plotEdges) {ierr = DMPlexGetDepthStratum(dm, 1, &eStart, &eEnd);CHKERRQ(ierr);} 840202fd40aSStefano Zampini if (plotEdges) { 841552f7358SJed Brown ierr = VecGetArray(coordinates, &coords);CHKERRQ(ierr); 842552f7358SJed Brown ierr = PetscViewerASCIIPrintf(viewer, "\\path\n");CHKERRQ(ierr); 843552f7358SJed Brown for (e = eStart; e < eEnd; ++e) { 844552f7358SJed Brown const PetscInt *cone; 845552f7358SJed Brown PetscInt coneSize, offA, offB, dof, d; 846552f7358SJed Brown 847552f7358SJed Brown ierr = DMPlexGetConeSize(dm, e, &coneSize);CHKERRQ(ierr); 848f347f43bSBarry Smith if (coneSize != 2) SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "Edge %D cone should have two vertices, not %D", e, coneSize); 849552f7358SJed Brown ierr = DMPlexGetCone(dm, e, &cone);CHKERRQ(ierr); 850552f7358SJed Brown ierr = PetscSectionGetDof(coordSection, cone[0], &dof);CHKERRQ(ierr); 851552f7358SJed Brown ierr = PetscSectionGetOffset(coordSection, cone[0], &offA);CHKERRQ(ierr); 852552f7358SJed Brown ierr = PetscSectionGetOffset(coordSection, cone[1], &offB);CHKERRQ(ierr); 853552f7358SJed Brown ierr = PetscViewerASCIISynchronizedPrintf(viewer, "(");CHKERRQ(ierr); 854552f7358SJed Brown for (d = 0; d < dof; ++d) { 855202fd40aSStefano Zampini tcoords[d] = (double) (0.5*scale*PetscRealPart(coords[offA+d]+coords[offB+d])); 856c068d9bbSLisandro Dalcin tcoords[d] = PetscAbs(tcoords[d]) < 1e-10 ? 0.0 : tcoords[d]; 857552f7358SJed Brown } 8580588280cSMatthew G. Knepley /* Rotate coordinates since PGF makes z point out of the page instead of up */ 8590588280cSMatthew G. Knepley if (dim == 3) {PetscReal tmp = tcoords[1]; tcoords[1] = tcoords[2]; tcoords[2] = -tmp;} 8600588280cSMatthew G. Knepley for (d = 0; d < dof; ++d) { 8610588280cSMatthew G. Knepley if (d > 0) {ierr = PetscViewerASCIISynchronizedPrintf(viewer, ",");CHKERRQ(ierr);} 862f347f43bSBarry Smith ierr = PetscViewerASCIISynchronizedPrintf(viewer, "%g", (double)tcoords[d]);CHKERRQ(ierr); 8630588280cSMatthew G. Knepley } 8640588280cSMatthew G. Knepley color = colors[rank%numColors]; 8650588280cSMatthew G. Knepley for (l = 0; l < numLabels; ++l) { 8660588280cSMatthew G. Knepley PetscInt val; 867c58f1c22SToby Isaac ierr = DMGetLabelValue(dm, names[l], v, &val);CHKERRQ(ierr); 8680750fff4SMatthew G. Knepley if (val >= 0) {color = lcolors[l%numLColors]; break;} 8690588280cSMatthew G. Knepley } 870e4b003c7SBarry Smith ierr = PetscViewerASCIISynchronizedPrintf(viewer, ") node(%D_%d) [draw,shape=circle,color=%s] {%D} --\n", e, rank, color, e);CHKERRQ(ierr); 871552f7358SJed Brown } 872552f7358SJed Brown ierr = VecRestoreArray(coordinates, &coords);CHKERRQ(ierr); 873552f7358SJed Brown ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); 874552f7358SJed Brown ierr = PetscViewerASCIIPrintf(viewer, "(0,0);\n");CHKERRQ(ierr); 8750588280cSMatthew G. Knepley } 876552f7358SJed Brown ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); 8774d4c343aSBarry Smith ierr = PetscViewerASCIIPopSynchronized(viewer);CHKERRQ(ierr); 8780588280cSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "\\end{tikzpicture}\n");CHKERRQ(ierr); 879770b213bSMatthew G Knepley ierr = PetscViewerASCIIPrintf(viewer, "\\end{document}\n", name);CHKERRQ(ierr); 8800588280cSMatthew G. Knepley for (l = 0; l < numLabels; ++l) {ierr = PetscFree(names[l]);CHKERRQ(ierr);} 8810588280cSMatthew G. Knepley for (c = 0; c < numColors; ++c) {ierr = PetscFree(colors[c]);CHKERRQ(ierr);} 8820588280cSMatthew G. Knepley for (c = 0; c < numLColors; ++c) {ierr = PetscFree(lcolors[c]);CHKERRQ(ierr);} 8830588280cSMatthew G. Knepley ierr = PetscFree3(names, colors, lcolors);CHKERRQ(ierr); 884552f7358SJed Brown } else { 88582f516ccSBarry Smith MPI_Comm comm; 886834065abSMatthew G. Knepley PetscInt *sizes, *hybsizes; 887f73eea6eSMatthew G. Knepley PetscInt locDepth, depth, cellHeight, dim, d, pMax[4]; 888552f7358SJed Brown PetscInt pStart, pEnd, p; 889a57dd577SMatthew G Knepley PetscInt numLabels, l; 8901143a3c0SMatthew G. Knepley const char *name; 891552f7358SJed Brown PetscMPIInt size; 892552f7358SJed Brown 89382f516ccSBarry Smith ierr = PetscObjectGetComm((PetscObject)dm,&comm);CHKERRQ(ierr); 894552f7358SJed Brown ierr = MPI_Comm_size(comm, &size);CHKERRQ(ierr); 895c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 896f73eea6eSMatthew G. Knepley ierr = DMPlexGetVTKCellHeight(dm, &cellHeight);CHKERRQ(ierr); 8975f64d76eSMatthew G. Knepley ierr = PetscObjectGetName((PetscObject) dm, &name);CHKERRQ(ierr); 898f73eea6eSMatthew G. Knepley if (name) {ierr = PetscViewerASCIIPrintf(viewer, "%s in %D dimension%s:\n", name, dim, dim == 1 ? "" : "s");CHKERRQ(ierr);} 899f73eea6eSMatthew G. Knepley else {ierr = PetscViewerASCIIPrintf(viewer, "Mesh in %D dimension%s:\n", dim, dim == 1 ? "" : "s");CHKERRQ(ierr);} 900f73eea6eSMatthew G. Knepley if (cellHeight) {ierr = PetscViewerASCIIPrintf(viewer, " Cells are at height %D\n", cellHeight);CHKERRQ(ierr);} 901552f7358SJed Brown ierr = DMPlexGetDepth(dm, &locDepth);CHKERRQ(ierr); 902b2566f29SBarry Smith ierr = MPIU_Allreduce(&locDepth, &depth, 1, MPIU_INT, MPI_MAX, comm);CHKERRQ(ierr); 903a04427b4SStefano Zampini ierr = DMPlexGetHybridBounds(dm, &pMax[depth], depth > 0 ? &pMax[depth-1] : NULL, depth > 1 ? &pMax[depth - 2] : NULL, &pMax[0]);CHKERRQ(ierr); 904dcca6d9dSJed Brown ierr = PetscMalloc2(size,&sizes,size,&hybsizes);CHKERRQ(ierr); 905552f7358SJed Brown if (depth == 1) { 906552f7358SJed Brown ierr = DMPlexGetDepthStratum(dm, 0, &pStart, &pEnd);CHKERRQ(ierr); 907552f7358SJed Brown pEnd = pEnd - pStart; 908a04427b4SStefano Zampini pMax[0] -= pStart; 909552f7358SJed Brown ierr = MPI_Gather(&pEnd, 1, MPIU_INT, sizes, 1, MPIU_INT, 0, comm);CHKERRQ(ierr); 910a04427b4SStefano Zampini ierr = MPI_Gather(&pMax[0], 1, MPIU_INT, hybsizes, 1, MPIU_INT, 0, comm);CHKERRQ(ierr); 911f347f43bSBarry Smith ierr = PetscViewerASCIIPrintf(viewer, " %d-cells:", 0);CHKERRQ(ierr); 912a04427b4SStefano Zampini for (p = 0; p < size; ++p) { 913a04427b4SStefano Zampini if (hybsizes[p] >= 0) {ierr = PetscViewerASCIIPrintf(viewer, " %D (%D)", sizes[p], sizes[p] - hybsizes[p]);CHKERRQ(ierr);} 914a04427b4SStefano Zampini else {ierr = PetscViewerASCIIPrintf(viewer, " %D", sizes[p]);CHKERRQ(ierr);} 915a04427b4SStefano Zampini } 916552f7358SJed Brown ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr); 917552f7358SJed Brown ierr = DMPlexGetHeightStratum(dm, 0, &pStart, &pEnd);CHKERRQ(ierr); 918552f7358SJed Brown pEnd = pEnd - pStart; 919a04427b4SStefano Zampini pMax[depth] -= pStart; 920552f7358SJed Brown ierr = MPI_Gather(&pEnd, 1, MPIU_INT, sizes, 1, MPIU_INT, 0, comm);CHKERRQ(ierr); 921a04427b4SStefano Zampini ierr = MPI_Gather(&pMax[depth], 1, MPIU_INT, hybsizes, 1, MPIU_INT, 0, comm);CHKERRQ(ierr); 922552f7358SJed Brown ierr = PetscViewerASCIIPrintf(viewer, " %D-cells:", dim);CHKERRQ(ierr); 923a04427b4SStefano Zampini for (p = 0; p < size; ++p) { 924a04427b4SStefano Zampini if (hybsizes[p] >= 0) {ierr = PetscViewerASCIIPrintf(viewer, " %D (%D)", sizes[p], sizes[p] - hybsizes[p]);CHKERRQ(ierr);} 925a04427b4SStefano Zampini else {ierr = PetscViewerASCIIPrintf(viewer, " %D", sizes[p]);CHKERRQ(ierr);} 926a04427b4SStefano Zampini } 927552f7358SJed Brown ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr); 928552f7358SJed Brown } else { 929cbb7f117SMark Adams PetscMPIInt rank; 930cbb7f117SMark Adams ierr = MPI_Comm_rank(comm, &rank);CHKERRQ(ierr); 931552f7358SJed Brown for (d = 0; d <= dim; d++) { 932552f7358SJed Brown ierr = DMPlexGetDepthStratum(dm, d, &pStart, &pEnd);CHKERRQ(ierr); 933834065abSMatthew G. Knepley pEnd -= pStart; 934834065abSMatthew G. Knepley pMax[d] -= pStart; 935552f7358SJed Brown ierr = MPI_Gather(&pEnd, 1, MPIU_INT, sizes, 1, MPIU_INT, 0, comm);CHKERRQ(ierr); 936834065abSMatthew G. Knepley ierr = MPI_Gather(&pMax[d], 1, MPIU_INT, hybsizes, 1, MPIU_INT, 0, comm);CHKERRQ(ierr); 937552f7358SJed Brown ierr = PetscViewerASCIIPrintf(viewer, " %D-cells:", d);CHKERRQ(ierr); 938834065abSMatthew G. Knepley for (p = 0; p < size; ++p) { 939cbb7f117SMark Adams if (!rank) { 940834065abSMatthew G. Knepley if (hybsizes[p] >= 0) {ierr = PetscViewerASCIIPrintf(viewer, " %D (%D)", sizes[p], sizes[p] - hybsizes[p]);CHKERRQ(ierr);} 941834065abSMatthew G. Knepley else {ierr = PetscViewerASCIIPrintf(viewer, " %D", sizes[p]);CHKERRQ(ierr);} 942834065abSMatthew G. Knepley } 943cbb7f117SMark Adams } 944552f7358SJed Brown ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr); 945552f7358SJed Brown } 946552f7358SJed Brown } 947834065abSMatthew G. Knepley ierr = PetscFree2(sizes,hybsizes);CHKERRQ(ierr); 948c58f1c22SToby Isaac ierr = DMGetNumLabels(dm, &numLabels);CHKERRQ(ierr); 949a57dd577SMatthew G Knepley if (numLabels) {ierr = PetscViewerASCIIPrintf(viewer, "Labels:\n");CHKERRQ(ierr);} 950a57dd577SMatthew G Knepley for (l = 0; l < numLabels; ++l) { 951a57dd577SMatthew G Knepley DMLabel label; 952a57dd577SMatthew G Knepley const char *name; 953a57dd577SMatthew G Knepley IS valueIS; 954a57dd577SMatthew G Knepley const PetscInt *values; 955a57dd577SMatthew G Knepley PetscInt numValues, v; 956a57dd577SMatthew G Knepley 957c58f1c22SToby Isaac ierr = DMGetLabelName(dm, l, &name);CHKERRQ(ierr); 958c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 959a57dd577SMatthew G Knepley ierr = DMLabelGetNumValues(label, &numValues);CHKERRQ(ierr); 960d72f73ffSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " %s: %D strata with value/size (", name, numValues);CHKERRQ(ierr); 961a57dd577SMatthew G Knepley ierr = DMLabelGetValueIS(label, &valueIS);CHKERRQ(ierr); 962a57dd577SMatthew G Knepley ierr = ISGetIndices(valueIS, &values);CHKERRQ(ierr); 963120dea56SMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr); 964a57dd577SMatthew G Knepley for (v = 0; v < numValues; ++v) { 965a57dd577SMatthew G Knepley PetscInt size; 966a57dd577SMatthew G Knepley 967a57dd577SMatthew G Knepley ierr = DMLabelGetStratumSize(label, values[v], &size);CHKERRQ(ierr); 968a57dd577SMatthew G Knepley if (v > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);} 969d72f73ffSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "%D (%D)", values[v], size);CHKERRQ(ierr); 970a57dd577SMatthew G Knepley } 971a57dd577SMatthew G Knepley ierr = PetscViewerASCIIPrintf(viewer, ")\n");CHKERRQ(ierr); 972120dea56SMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr); 973a57dd577SMatthew G Knepley ierr = ISRestoreIndices(valueIS, &values);CHKERRQ(ierr); 9744d41221fSMatthew G Knepley ierr = ISDestroy(&valueIS);CHKERRQ(ierr); 975a57dd577SMatthew G Knepley } 976a8fb8f29SToby Isaac ierr = DMGetCoarseDM(dm, &cdm);CHKERRQ(ierr); 9778e7ff633SMatthew G. Knepley if (cdm) { 9788e7ff633SMatthew G. Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 9798e7ff633SMatthew G. Knepley ierr = DMPlexView_Ascii(cdm, viewer);CHKERRQ(ierr); 9808e7ff633SMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 9818e7ff633SMatthew G. Knepley } 982552f7358SJed Brown } 983552f7358SJed Brown PetscFunctionReturn(0); 984552f7358SJed Brown } 985552f7358SJed Brown 9867cd05799SMatthew G. Knepley static PetscErrorCode DMPlexView_Draw(DM dm, PetscViewer viewer) 987e412dcbdSMatthew G. Knepley { 988e412dcbdSMatthew G. Knepley PetscDraw draw; 989e412dcbdSMatthew G. Knepley DM cdm; 990e412dcbdSMatthew G. Knepley PetscSection coordSection; 991e412dcbdSMatthew G. Knepley Vec coordinates; 992e412dcbdSMatthew G. Knepley const PetscScalar *coords; 99329494db1SLisandro Dalcin PetscReal xyl[2],xyr[2],bound[4] = {PETSC_MAX_REAL, PETSC_MAX_REAL, PETSC_MIN_REAL, PETSC_MIN_REAL}; 994e412dcbdSMatthew G. Knepley PetscBool isnull; 995e412dcbdSMatthew G. Knepley PetscInt dim, vStart, vEnd, cStart, cEnd, c, N; 996*cf3064d3SMatthew G. Knepley PetscMPIInt rank; 997e412dcbdSMatthew G. Knepley PetscErrorCode ierr; 998e412dcbdSMatthew G. Knepley 999e412dcbdSMatthew G. Knepley PetscFunctionBegin; 1000e412dcbdSMatthew G. Knepley ierr = DMGetCoordinateDim(dm, &dim);CHKERRQ(ierr); 1001e412dcbdSMatthew G. Knepley if (dim != 2) SETERRQ1(PetscObjectComm((PetscObject) dm), PETSC_ERR_SUP, "Cannot draw meshes of dimension %D", dim); 1002e412dcbdSMatthew G. Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 1003e87a4003SBarry Smith ierr = DMGetSection(cdm, &coordSection);CHKERRQ(ierr); 1004e412dcbdSMatthew G. Knepley ierr = DMGetCoordinatesLocal(dm, &coordinates);CHKERRQ(ierr); 1005e412dcbdSMatthew G. Knepley ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr); 1006e412dcbdSMatthew G. Knepley ierr = DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd);CHKERRQ(ierr); 1007e412dcbdSMatthew G. Knepley 1008e412dcbdSMatthew G. Knepley ierr = PetscViewerDrawGetDraw(viewer, 0, &draw);CHKERRQ(ierr); 1009e412dcbdSMatthew G. Knepley ierr = PetscDrawIsNull(draw, &isnull);CHKERRQ(ierr); 1010e412dcbdSMatthew G. Knepley if (isnull) PetscFunctionReturn(0); 1011e412dcbdSMatthew G. Knepley ierr = PetscDrawSetTitle(draw, "Mesh");CHKERRQ(ierr); 1012e412dcbdSMatthew G. Knepley 1013e412dcbdSMatthew G. Knepley ierr = VecGetLocalSize(coordinates, &N);CHKERRQ(ierr); 1014e412dcbdSMatthew G. Knepley ierr = VecGetArrayRead(coordinates, &coords);CHKERRQ(ierr); 1015e412dcbdSMatthew G. Knepley for (c = 0; c < N; c += dim) { 10160c81f2a8SMatthew G. Knepley bound[0] = PetscMin(bound[0], PetscRealPart(coords[c])); bound[2] = PetscMax(bound[2], PetscRealPart(coords[c])); 10170c81f2a8SMatthew G. Knepley bound[1] = PetscMin(bound[1], PetscRealPart(coords[c+1])); bound[3] = PetscMax(bound[3], PetscRealPart(coords[c+1])); 1018e412dcbdSMatthew G. Knepley } 1019e412dcbdSMatthew G. Knepley ierr = VecRestoreArrayRead(coordinates, &coords);CHKERRQ(ierr); 102029494db1SLisandro Dalcin ierr = MPIU_Allreduce(&bound[0],xyl,2,MPIU_REAL,MPIU_MIN,PetscObjectComm((PetscObject)dm));CHKERRQ(ierr); 102129494db1SLisandro Dalcin ierr = MPIU_Allreduce(&bound[2],xyr,2,MPIU_REAL,MPIU_MAX,PetscObjectComm((PetscObject)dm));CHKERRQ(ierr); 102229494db1SLisandro Dalcin ierr = PetscDrawSetCoordinates(draw, xyl[0], xyl[1], xyr[0], xyr[1]);CHKERRQ(ierr); 1023e412dcbdSMatthew G. Knepley ierr = PetscDrawClear(draw);CHKERRQ(ierr); 1024e412dcbdSMatthew G. Knepley 1025*cf3064d3SMatthew G. Knepley ierr = MPI_Comm_rank(PetscObjectComm((PetscObject) dm), &rank);CHKERRQ(ierr); 1026*cf3064d3SMatthew G. Knepley for (c = cStart; c < cEnd; ++c) { 1027*cf3064d3SMatthew G. Knepley PetscScalar *coords = NULL; 1028*cf3064d3SMatthew G. Knepley PetscInt numCoords,coneSize; 1029*cf3064d3SMatthew G. Knepley 1030*cf3064d3SMatthew G. Knepley ierr = DMPlexGetConeSize(dm, c, &coneSize);CHKERRQ(ierr); 1031*cf3064d3SMatthew G. Knepley ierr = DMPlexVecGetClosure(dm, coordSection, coordinates, c, &numCoords, &coords);CHKERRQ(ierr); 1032*cf3064d3SMatthew G. Knepley switch (coneSize) { 1033*cf3064d3SMatthew G. Knepley case 3: 1034*cf3064d3SMatthew G. Knepley ierr = PetscDrawTriangle(draw, PetscRealPart(coords[0]), PetscRealPart(coords[1]), PetscRealPart(coords[2]), PetscRealPart(coords[3]), PetscRealPart(coords[4]), PetscRealPart(coords[5]), 1035*cf3064d3SMatthew G. Knepley PETSC_DRAW_WHITE + rank % (PETSC_DRAW_BASIC_COLORS-2) + 2, 1036*cf3064d3SMatthew G. Knepley PETSC_DRAW_WHITE + rank % (PETSC_DRAW_BASIC_COLORS-2) + 2, 1037*cf3064d3SMatthew G. Knepley PETSC_DRAW_WHITE + rank % (PETSC_DRAW_BASIC_COLORS-2) + 2);CHKERRQ(ierr); 1038*cf3064d3SMatthew G. Knepley break; 1039*cf3064d3SMatthew G. Knepley case 4: 1040*cf3064d3SMatthew G. Knepley ierr = PetscDrawRectangle(draw, PetscRealPart(coords[0]), PetscRealPart(coords[1]), PetscRealPart(coords[4]), PetscRealPart(coords[5]), 1041*cf3064d3SMatthew G. Knepley PETSC_DRAW_WHITE + rank % (PETSC_DRAW_BASIC_COLORS-2) + 2, 1042*cf3064d3SMatthew G. Knepley PETSC_DRAW_WHITE + rank % (PETSC_DRAW_BASIC_COLORS-2) + 2, 1043*cf3064d3SMatthew G. Knepley PETSC_DRAW_WHITE + rank % (PETSC_DRAW_BASIC_COLORS-2) + 2, 1044*cf3064d3SMatthew G. Knepley PETSC_DRAW_WHITE + rank % (PETSC_DRAW_BASIC_COLORS-2) + 2);CHKERRQ(ierr); 1045*cf3064d3SMatthew G. Knepley break; 1046*cf3064d3SMatthew G. Knepley default: SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_SUP, "Cannot draw cells with %D facets", coneSize); 1047*cf3064d3SMatthew G. Knepley } 1048*cf3064d3SMatthew G. Knepley ierr = DMPlexVecRestoreClosure(dm, coordSection, coordinates, c, &numCoords, &coords);CHKERRQ(ierr); 1049*cf3064d3SMatthew G. Knepley } 1050e412dcbdSMatthew G. Knepley for (c = cStart; c < cEnd; ++c) { 1051e412dcbdSMatthew G. Knepley PetscScalar *coords = NULL; 105229494db1SLisandro Dalcin PetscInt numCoords,coneSize; 1053e412dcbdSMatthew G. Knepley 105429494db1SLisandro Dalcin ierr = DMPlexGetConeSize(dm, c, &coneSize);CHKERRQ(ierr); 1055e412dcbdSMatthew G. Knepley ierr = DMPlexVecGetClosure(dm, coordSection, coordinates, c, &numCoords, &coords);CHKERRQ(ierr); 105629494db1SLisandro Dalcin switch (coneSize) { 105729494db1SLisandro Dalcin case 3: 10580c81f2a8SMatthew G. Knepley ierr = PetscDrawLine(draw, PetscRealPart(coords[0]), PetscRealPart(coords[1]), PetscRealPart(coords[2]), PetscRealPart(coords[3]), PETSC_DRAW_BLACK);CHKERRQ(ierr); 10590c81f2a8SMatthew G. Knepley ierr = PetscDrawLine(draw, PetscRealPart(coords[2]), PetscRealPart(coords[3]), PetscRealPart(coords[4]), PetscRealPart(coords[5]), PETSC_DRAW_BLACK);CHKERRQ(ierr); 10600c81f2a8SMatthew G. Knepley ierr = PetscDrawLine(draw, PetscRealPart(coords[4]), PetscRealPart(coords[5]), PetscRealPart(coords[0]), PetscRealPart(coords[1]), PETSC_DRAW_BLACK);CHKERRQ(ierr); 1061e412dcbdSMatthew G. Knepley break; 106229494db1SLisandro Dalcin case 4: 10630c81f2a8SMatthew G. Knepley ierr = PetscDrawLine(draw, PetscRealPart(coords[0]), PetscRealPart(coords[1]), PetscRealPart(coords[2]), PetscRealPart(coords[3]), PETSC_DRAW_BLACK);CHKERRQ(ierr); 10640c81f2a8SMatthew G. Knepley ierr = PetscDrawLine(draw, PetscRealPart(coords[2]), PetscRealPart(coords[3]), PetscRealPart(coords[4]), PetscRealPart(coords[5]), PETSC_DRAW_BLACK);CHKERRQ(ierr); 10650c81f2a8SMatthew G. Knepley ierr = PetscDrawLine(draw, PetscRealPart(coords[4]), PetscRealPart(coords[5]), PetscRealPart(coords[6]), PetscRealPart(coords[7]), PETSC_DRAW_BLACK);CHKERRQ(ierr); 10660c81f2a8SMatthew G. Knepley ierr = PetscDrawLine(draw, PetscRealPart(coords[6]), PetscRealPart(coords[7]), PetscRealPart(coords[0]), PetscRealPart(coords[1]), PETSC_DRAW_BLACK);CHKERRQ(ierr); 1067e412dcbdSMatthew G. Knepley break; 106829494db1SLisandro Dalcin default: SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_SUP, "Cannot draw cells with %D facets", coneSize); 1069e412dcbdSMatthew G. Knepley } 1070e412dcbdSMatthew G. Knepley ierr = DMPlexVecRestoreClosure(dm, coordSection, coordinates, c, &numCoords, &coords);CHKERRQ(ierr); 1071e412dcbdSMatthew G. Knepley } 1072e412dcbdSMatthew G. Knepley ierr = PetscDrawFlush(draw);CHKERRQ(ierr); 1073e412dcbdSMatthew G. Knepley ierr = PetscDrawPause(draw);CHKERRQ(ierr); 1074e412dcbdSMatthew G. Knepley ierr = PetscDrawSave(draw);CHKERRQ(ierr); 1075e412dcbdSMatthew G. Knepley PetscFunctionReturn(0); 1076e412dcbdSMatthew G. Knepley } 1077e412dcbdSMatthew G. Knepley 1078552f7358SJed Brown PetscErrorCode DMView_Plex(DM dm, PetscViewer viewer) 1079552f7358SJed Brown { 1080e655db49SSatish Balay PetscBool iascii, ishdf5, isvtk, isdraw, flg, isglvis; 1081552f7358SJed Brown PetscErrorCode ierr; 1082552f7358SJed Brown 1083552f7358SJed Brown PetscFunctionBegin; 1084552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1085552f7358SJed Brown PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2); 1086552f7358SJed Brown ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr); 1087fcf6c8fdSToby Isaac ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERVTK, &isvtk);CHKERRQ(ierr); 1088c6ccd67eSMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERHDF5, &ishdf5);CHKERRQ(ierr); 1089e412dcbdSMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERDRAW, &isdraw);CHKERRQ(ierr); 10908135c375SStefano Zampini ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERGLVIS, &isglvis);CHKERRQ(ierr); 1091552f7358SJed Brown if (iascii) { 10928135c375SStefano Zampini PetscViewerFormat format; 10938135c375SStefano Zampini ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr); 10948135c375SStefano Zampini if (format == PETSC_VIEWER_ASCII_GLVIS) { 10958135c375SStefano Zampini ierr = DMPlexView_GLVis(dm, viewer);CHKERRQ(ierr); 10968135c375SStefano Zampini } else { 1097552f7358SJed Brown ierr = DMPlexView_Ascii(dm, viewer);CHKERRQ(ierr); 10988135c375SStefano Zampini } 1099c6ccd67eSMatthew G. Knepley } else if (ishdf5) { 1100c6ccd67eSMatthew G. Knepley #if defined(PETSC_HAVE_HDF5) 110139d25373SMatthew G. Knepley ierr = DMPlexView_HDF5_Internal(dm, viewer);CHKERRQ(ierr); 1102c6ccd67eSMatthew G. Knepley #else 1103c6ccd67eSMatthew G. Knepley SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_SUP, "HDF5 not supported in this build.\nPlease reconfigure using --download-hdf5"); 1104552f7358SJed Brown #endif 1105e412dcbdSMatthew G. Knepley } else if (isvtk) { 1106fcf6c8fdSToby Isaac ierr = DMPlexVTKWriteAll((PetscObject) dm,viewer);CHKERRQ(ierr); 1107e412dcbdSMatthew G. Knepley } else if (isdraw) { 1108e412dcbdSMatthew G. Knepley ierr = DMPlexView_Draw(dm, viewer);CHKERRQ(ierr); 11098135c375SStefano Zampini } else if (isglvis) { 11108135c375SStefano Zampini ierr = DMPlexView_GLVis(dm, viewer);CHKERRQ(ierr); 111162201deeSVaclav Hapla } else { 1112a94aea51SVaclav Hapla SETERRQ1(PetscObjectComm((PetscObject) dm), PETSC_ERR_SUP, "Viewer type %s not yet supported for DMPlex writing", ((PetscObject)viewer)->type_name); 1113fcf6c8fdSToby Isaac } 1114cb3ba0daSMatthew G. Knepley /* Optionally view the partition */ 1115cb3ba0daSMatthew G. Knepley ierr = PetscOptionsHasName(((PetscObject) dm)->options, ((PetscObject) dm)->prefix, "-dm_partition_view", &flg);CHKERRQ(ierr); 1116cb3ba0daSMatthew G. Knepley if (flg) { 1117cb3ba0daSMatthew G. Knepley Vec ranks; 1118cb3ba0daSMatthew G. Knepley ierr = DMPlexCreateRankField(dm, &ranks);CHKERRQ(ierr); 1119cb3ba0daSMatthew G. Knepley ierr = VecView(ranks, viewer);CHKERRQ(ierr); 1120cb3ba0daSMatthew G. Knepley ierr = VecDestroy(&ranks);CHKERRQ(ierr); 1121cb3ba0daSMatthew G. Knepley } 1122552f7358SJed Brown PetscFunctionReturn(0); 1123552f7358SJed Brown } 1124552f7358SJed Brown 11252c40f234SMatthew G. Knepley PetscErrorCode DMLoad_Plex(DM dm, PetscViewer viewer) 11262c40f234SMatthew G. Knepley { 1127d4f5a9a0SVaclav Hapla PetscBool ishdf5; 11282c40f234SMatthew G. Knepley PetscErrorCode ierr; 11292c40f234SMatthew G. Knepley 11302c40f234SMatthew G. Knepley PetscFunctionBegin; 11312c40f234SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 11322c40f234SMatthew G. Knepley PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2); 11332c40f234SMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERHDF5, &ishdf5);CHKERRQ(ierr); 1134d4f5a9a0SVaclav Hapla if (ishdf5) { 11352c40f234SMatthew G. Knepley #if defined(PETSC_HAVE_HDF5) 11369c48423bSVaclav Hapla PetscViewerFormat format; 11379c48423bSVaclav Hapla ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr); 11389c48423bSVaclav Hapla if (format == PETSC_VIEWER_HDF5_XDMF || format == PETSC_VIEWER_HDF5_VIZ) { 11399c48423bSVaclav Hapla ierr = DMPlexLoad_HDF5_Xdmf_Internal(dm, viewer);CHKERRQ(ierr); 11409c48423bSVaclav Hapla } else { 114139d25373SMatthew G. Knepley ierr = DMPlexLoad_HDF5_Internal(dm, viewer);CHKERRQ(ierr); 11429c48423bSVaclav Hapla } 11432c40f234SMatthew G. Knepley #else 11442c40f234SMatthew G. Knepley SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_SUP, "HDF5 not supported in this build.\nPlease reconfigure using --download-hdf5"); 1145552f7358SJed Brown #endif 1146d4f5a9a0SVaclav Hapla } else { 1147d4f5a9a0SVaclav Hapla SETERRQ1(PetscObjectComm((PetscObject) dm), PETSC_ERR_SUP, "Viewer type %s not yet supported for DMPlex loading", ((PetscObject)viewer)->type_name); 1148552f7358SJed Brown } 1149552f7358SJed Brown PetscFunctionReturn(0); 1150552f7358SJed Brown } 1151552f7358SJed Brown 1152552f7358SJed Brown PetscErrorCode DMDestroy_Plex(DM dm) 1153552f7358SJed Brown { 1154552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 1155552f7358SJed Brown PetscErrorCode ierr; 1156552f7358SJed Brown 1157552f7358SJed Brown PetscFunctionBegin; 11588135c375SStefano Zampini ierr = PetscObjectComposeFunction((PetscObject)dm,"DMSetUpGLVisViewer_C",NULL);CHKERRQ(ierr); 11598135c375SStefano Zampini ierr = PetscObjectComposeFunction((PetscObject)dm,"DMPlexInsertBoundaryValues_C", NULL);CHKERRQ(ierr); 11600d644c17SKarl Rupp if (--mesh->refct > 0) PetscFunctionReturn(0); 1161552f7358SJed Brown ierr = PetscSectionDestroy(&mesh->coneSection);CHKERRQ(ierr); 1162552f7358SJed Brown ierr = PetscFree(mesh->cones);CHKERRQ(ierr); 1163552f7358SJed Brown ierr = PetscFree(mesh->coneOrientations);CHKERRQ(ierr); 1164552f7358SJed Brown ierr = PetscSectionDestroy(&mesh->supportSection);CHKERRQ(ierr); 1165be36d101SStefano Zampini ierr = PetscSectionDestroy(&mesh->subdomainSection);CHKERRQ(ierr); 1166552f7358SJed Brown ierr = PetscFree(mesh->supports);CHKERRQ(ierr); 1167552f7358SJed Brown ierr = PetscFree(mesh->facesTmp);CHKERRQ(ierr); 1168d9deefdfSMatthew G. Knepley ierr = PetscFree(mesh->tetgenOpts);CHKERRQ(ierr); 1169d9deefdfSMatthew G. Knepley ierr = PetscFree(mesh->triangleOpts);CHKERRQ(ierr); 117077623264SMatthew G. Knepley ierr = PetscPartitionerDestroy(&mesh->partitioner);CHKERRQ(ierr); 1171a89082eeSMatthew G Knepley ierr = DMLabelDestroy(&mesh->subpointMap);CHKERRQ(ierr); 1172552f7358SJed Brown ierr = ISDestroy(&mesh->globalVertexNumbers);CHKERRQ(ierr); 1173552f7358SJed Brown ierr = ISDestroy(&mesh->globalCellNumbers);CHKERRQ(ierr); 1174a68b90caSToby Isaac ierr = PetscSectionDestroy(&mesh->anchorSection);CHKERRQ(ierr); 1175a68b90caSToby Isaac ierr = ISDestroy(&mesh->anchorIS);CHKERRQ(ierr); 1176d961a43aSToby Isaac ierr = PetscSectionDestroy(&mesh->parentSection);CHKERRQ(ierr); 1177d961a43aSToby Isaac ierr = PetscFree(mesh->parents);CHKERRQ(ierr); 1178d961a43aSToby Isaac ierr = PetscFree(mesh->childIDs);CHKERRQ(ierr); 1179d961a43aSToby Isaac ierr = PetscSectionDestroy(&mesh->childSection);CHKERRQ(ierr); 1180d961a43aSToby Isaac ierr = PetscFree(mesh->children);CHKERRQ(ierr); 1181d6a7ad0dSToby Isaac ierr = DMDestroy(&mesh->referenceTree);CHKERRQ(ierr); 1182fec49543SMatthew G. Knepley ierr = PetscGridHashDestroy(&mesh->lbox);CHKERRQ(ierr); 1183552f7358SJed Brown /* This was originally freed in DMDestroy(), but that prevents reference counting of backend objects */ 1184552f7358SJed Brown ierr = PetscFree(mesh);CHKERRQ(ierr); 1185552f7358SJed Brown PetscFunctionReturn(0); 1186552f7358SJed Brown } 1187552f7358SJed Brown 1188b412c318SBarry Smith PetscErrorCode DMCreateMatrix_Plex(DM dm, Mat *J) 1189552f7358SJed Brown { 11908d1174e4SMatthew G. Knepley PetscSection sectionGlobal; 1191acd755d7SMatthew G. Knepley PetscInt bs = -1, mbs; 1192552f7358SJed Brown PetscInt localSize; 1193837628f4SStefano Zampini PetscBool isShell, isBlock, isSeqBlock, isMPIBlock, isSymBlock, isSymSeqBlock, isSymMPIBlock, isMatIS; 1194552f7358SJed Brown PetscErrorCode ierr; 1195b412c318SBarry Smith MatType mtype; 11961428887cSShri Abhyankar ISLocalToGlobalMapping ltog; 1197552f7358SJed Brown 1198552f7358SJed Brown PetscFunctionBegin; 1199607a6623SBarry Smith ierr = MatInitializePackage();CHKERRQ(ierr); 1200b412c318SBarry Smith mtype = dm->mattype; 1201e87a4003SBarry Smith ierr = DMGetGlobalSection(dm, §ionGlobal);CHKERRQ(ierr); 1202552f7358SJed Brown /* ierr = PetscSectionGetStorageSize(sectionGlobal, &localSize);CHKERRQ(ierr); */ 1203552f7358SJed Brown ierr = PetscSectionGetConstrainedStorageSize(sectionGlobal, &localSize);CHKERRQ(ierr); 120482f516ccSBarry Smith ierr = MatCreate(PetscObjectComm((PetscObject)dm), J);CHKERRQ(ierr); 1205552f7358SJed Brown ierr = MatSetSizes(*J, localSize, localSize, PETSC_DETERMINE, PETSC_DETERMINE);CHKERRQ(ierr); 1206552f7358SJed Brown ierr = MatSetType(*J, mtype);CHKERRQ(ierr); 1207552f7358SJed Brown ierr = MatSetFromOptions(*J);CHKERRQ(ierr); 1208acd755d7SMatthew G. Knepley ierr = MatGetBlockSize(*J, &mbs);CHKERRQ(ierr); 1209acd755d7SMatthew G. Knepley if (mbs > 1) bs = mbs; 1210552f7358SJed Brown ierr = PetscStrcmp(mtype, MATSHELL, &isShell);CHKERRQ(ierr); 1211552f7358SJed Brown ierr = PetscStrcmp(mtype, MATBAIJ, &isBlock);CHKERRQ(ierr); 1212552f7358SJed Brown ierr = PetscStrcmp(mtype, MATSEQBAIJ, &isSeqBlock);CHKERRQ(ierr); 1213552f7358SJed Brown ierr = PetscStrcmp(mtype, MATMPIBAIJ, &isMPIBlock);CHKERRQ(ierr); 1214552f7358SJed Brown ierr = PetscStrcmp(mtype, MATSBAIJ, &isSymBlock);CHKERRQ(ierr); 1215552f7358SJed Brown ierr = PetscStrcmp(mtype, MATSEQSBAIJ, &isSymSeqBlock);CHKERRQ(ierr); 1216552f7358SJed Brown ierr = PetscStrcmp(mtype, MATMPISBAIJ, &isSymMPIBlock);CHKERRQ(ierr); 1217837628f4SStefano Zampini ierr = PetscStrcmp(mtype, MATIS, &isMatIS);CHKERRQ(ierr); 1218552f7358SJed Brown if (!isShell) { 1219be36d101SStefano Zampini PetscSection subSection; 1220837628f4SStefano Zampini PetscBool fillMatrix = (PetscBool)(!dm->prealloc_only && !isMatIS); 12210be3e97aSMatthew G. Knepley PetscInt *dnz, *onz, *dnzu, *onzu, bsLocal[2], bsMinMax[2], *ltogidx, lsize; 1222fad22124SMatthew G Knepley PetscInt pStart, pEnd, p, dof, cdof; 1223552f7358SJed Brown 122400140cc3SStefano Zampini /* Set localtoglobalmapping on the matrix for MatSetValuesLocal() to work (it also creates the local matrices in case of MATIS) */ 1225be36d101SStefano Zampini if (isMatIS) { /* need a different l2g map than the one computed by DMGetLocalToGlobalMapping */ 1226be36d101SStefano Zampini PetscSection section; 1227be36d101SStefano Zampini PetscInt size; 1228be36d101SStefano Zampini 1229e87a4003SBarry Smith ierr = DMGetSection(dm, §ion);CHKERRQ(ierr); 1230be36d101SStefano Zampini ierr = PetscSectionGetStorageSize(section, &size);CHKERRQ(ierr); 1231be36d101SStefano Zampini ierr = PetscMalloc1(size,<ogidx);CHKERRQ(ierr); 1232be36d101SStefano Zampini ierr = DMPlexGetSubdomainSection(dm, &subSection);CHKERRQ(ierr); 1233be36d101SStefano Zampini } else { 123400140cc3SStefano Zampini ierr = DMGetLocalToGlobalMapping(dm,<og);CHKERRQ(ierr); 1235be36d101SStefano Zampini } 1236552f7358SJed Brown ierr = PetscSectionGetChart(sectionGlobal, &pStart, &pEnd);CHKERRQ(ierr); 1237be36d101SStefano Zampini for (p = pStart, lsize = 0; p < pEnd; ++p) { 1238a9d99c84SMatthew G. Knepley PetscInt bdof; 1239a9d99c84SMatthew G. Knepley 1240552f7358SJed Brown ierr = PetscSectionGetDof(sectionGlobal, p, &dof);CHKERRQ(ierr); 1241fad22124SMatthew G Knepley ierr = PetscSectionGetConstraintDof(sectionGlobal, p, &cdof);CHKERRQ(ierr); 12421d17a0a3SMatthew G. Knepley dof = dof < 0 ? -(dof+1) : dof; 12431d17a0a3SMatthew G. Knepley bdof = cdof && (dof-cdof) ? 1 : dof; 12441d17a0a3SMatthew G. Knepley if (dof) { 12451d17a0a3SMatthew G. Knepley if (bs < 0) {bs = bdof;} 1246be36d101SStefano Zampini else if (bs != bdof) {bs = 1; if (!isMatIS) break;} 1247be36d101SStefano Zampini } 1248be36d101SStefano Zampini if (isMatIS) { 1249be36d101SStefano Zampini PetscInt loff,c,off; 1250be36d101SStefano Zampini ierr = PetscSectionGetOffset(subSection, p, &loff);CHKERRQ(ierr); 1251be36d101SStefano Zampini ierr = PetscSectionGetOffset(sectionGlobal, p, &off);CHKERRQ(ierr); 1252be36d101SStefano Zampini for (c = 0; c < dof-cdof; ++c, ++lsize) ltogidx[loff+c] = off > -1 ? off+c : -(off+1)+c; 1253552f7358SJed Brown } 12542a28c762SMatthew G Knepley } 12552a28c762SMatthew G Knepley /* Must have same blocksize on all procs (some might have no points) */ 12560be3e97aSMatthew G. Knepley bsLocal[0] = bs < 0 ? PETSC_MAX_INT : bs; bsLocal[1] = bs; 12570be3e97aSMatthew G. Knepley ierr = PetscGlobalMinMaxInt(PetscObjectComm((PetscObject) dm), bsLocal, bsMinMax);CHKERRQ(ierr); 12580be3e97aSMatthew G. Knepley if (bsMinMax[0] != bsMinMax[1]) {bs = 1;} 12590be3e97aSMatthew G. Knepley else {bs = bsMinMax[0];} 12604fa26246SMatthew G. Knepley bs = bs < 0 ? 1 : bs; 1261be36d101SStefano Zampini if (isMatIS) { 12624fa26246SMatthew G. Knepley PetscInt l; 12634fa26246SMatthew G. Knepley /* Must reduce indices by blocksize */ 12644fa26246SMatthew G. Knepley if (bs > 1) for (l = 0; l < lsize; ++l) ltogidx[l] /= bs; 12654fa26246SMatthew G. Knepley ierr = ISLocalToGlobalMappingCreate(PetscObjectComm((PetscObject)dm), bs, lsize, ltogidx, PETSC_OWN_POINTER, <og);CHKERRQ(ierr); 1266be36d101SStefano Zampini } 1267be36d101SStefano Zampini ierr = MatSetLocalToGlobalMapping(*J,ltog,ltog);CHKERRQ(ierr); 1268be36d101SStefano Zampini if (isMatIS) { 1269be36d101SStefano Zampini ierr = ISLocalToGlobalMappingDestroy(<og);CHKERRQ(ierr); 1270be36d101SStefano Zampini } 12711795a4d1SJed Brown ierr = PetscCalloc4(localSize/bs, &dnz, localSize/bs, &onz, localSize/bs, &dnzu, localSize/bs, &onzu);CHKERRQ(ierr); 12728d1174e4SMatthew G. Knepley ierr = DMPlexPreallocateOperator(dm, bs, dnz, onz, dnzu, onzu, *J, fillMatrix);CHKERRQ(ierr); 1273552f7358SJed Brown ierr = PetscFree4(dnz, onz, dnzu, onzu);CHKERRQ(ierr); 1274552f7358SJed Brown } 1275b1f74addSMatthew G. Knepley ierr = MatSetDM(*J, dm);CHKERRQ(ierr); 1276552f7358SJed Brown PetscFunctionReturn(0); 1277552f7358SJed Brown } 1278552f7358SJed Brown 12797cd05799SMatthew G. Knepley /*@ 1280a8f00d21SMatthew G. Knepley DMPlexGetSubdomainSection - Returns the section associated with the subdomain 1281be36d101SStefano Zampini 1282be36d101SStefano Zampini Not collective 1283be36d101SStefano Zampini 1284be36d101SStefano Zampini Input Parameter: 1285be36d101SStefano Zampini . mesh - The DMPlex 1286be36d101SStefano Zampini 1287be36d101SStefano Zampini Output Parameters: 1288be36d101SStefano Zampini . subsection - The subdomain section 1289be36d101SStefano Zampini 1290be36d101SStefano Zampini Level: developer 1291be36d101SStefano Zampini 1292be36d101SStefano Zampini .seealso: 12937cd05799SMatthew G. Knepley @*/ 1294be36d101SStefano Zampini PetscErrorCode DMPlexGetSubdomainSection(DM dm, PetscSection *subsection) 1295be36d101SStefano Zampini { 1296be36d101SStefano Zampini DM_Plex *mesh = (DM_Plex*) dm->data; 1297be36d101SStefano Zampini PetscErrorCode ierr; 1298be36d101SStefano Zampini 1299be36d101SStefano Zampini PetscFunctionBegin; 1300be36d101SStefano Zampini PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1301be36d101SStefano Zampini if (!mesh->subdomainSection) { 1302be36d101SStefano Zampini PetscSection section; 1303be36d101SStefano Zampini PetscSF sf; 1304be36d101SStefano Zampini 1305be36d101SStefano Zampini ierr = PetscSFCreate(PETSC_COMM_SELF,&sf);CHKERRQ(ierr); 1306e87a4003SBarry Smith ierr = DMGetSection(dm,§ion);CHKERRQ(ierr); 1307be36d101SStefano Zampini ierr = PetscSectionCreateGlobalSection(section,sf,PETSC_FALSE,PETSC_TRUE,&mesh->subdomainSection);CHKERRQ(ierr); 1308be36d101SStefano Zampini ierr = PetscSFDestroy(&sf);CHKERRQ(ierr); 1309be36d101SStefano Zampini } 1310be36d101SStefano Zampini *subsection = mesh->subdomainSection; 1311be36d101SStefano Zampini PetscFunctionReturn(0); 1312be36d101SStefano Zampini } 1313be36d101SStefano Zampini 1314552f7358SJed Brown /*@ 1315552f7358SJed Brown DMPlexGetChart - Return the interval for all mesh points [pStart, pEnd) 1316552f7358SJed Brown 1317552f7358SJed Brown Not collective 1318552f7358SJed Brown 1319552f7358SJed Brown Input Parameter: 1320552f7358SJed Brown . mesh - The DMPlex 1321552f7358SJed Brown 1322552f7358SJed Brown Output Parameters: 1323552f7358SJed Brown + pStart - The first mesh point 1324552f7358SJed Brown - pEnd - The upper bound for mesh points 1325552f7358SJed Brown 1326552f7358SJed Brown Level: beginner 1327552f7358SJed Brown 1328552f7358SJed Brown .seealso: DMPlexCreate(), DMPlexSetChart() 1329552f7358SJed Brown @*/ 1330552f7358SJed Brown PetscErrorCode DMPlexGetChart(DM dm, PetscInt *pStart, PetscInt *pEnd) 1331552f7358SJed Brown { 1332552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 1333552f7358SJed Brown PetscErrorCode ierr; 1334552f7358SJed Brown 1335552f7358SJed Brown PetscFunctionBegin; 1336552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1337552f7358SJed Brown ierr = PetscSectionGetChart(mesh->coneSection, pStart, pEnd);CHKERRQ(ierr); 1338552f7358SJed Brown PetscFunctionReturn(0); 1339552f7358SJed Brown } 1340552f7358SJed Brown 1341552f7358SJed Brown /*@ 1342552f7358SJed Brown DMPlexSetChart - Set the interval for all mesh points [pStart, pEnd) 1343552f7358SJed Brown 1344552f7358SJed Brown Not collective 1345552f7358SJed Brown 1346552f7358SJed Brown Input Parameters: 1347552f7358SJed Brown + mesh - The DMPlex 1348552f7358SJed Brown . pStart - The first mesh point 1349552f7358SJed Brown - pEnd - The upper bound for mesh points 1350552f7358SJed Brown 1351552f7358SJed Brown Output Parameters: 1352552f7358SJed Brown 1353552f7358SJed Brown Level: beginner 1354552f7358SJed Brown 1355552f7358SJed Brown .seealso: DMPlexCreate(), DMPlexGetChart() 1356552f7358SJed Brown @*/ 1357552f7358SJed Brown PetscErrorCode DMPlexSetChart(DM dm, PetscInt pStart, PetscInt pEnd) 1358552f7358SJed Brown { 1359552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 1360552f7358SJed Brown PetscErrorCode ierr; 1361552f7358SJed Brown 1362552f7358SJed Brown PetscFunctionBegin; 1363552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1364552f7358SJed Brown ierr = PetscSectionSetChart(mesh->coneSection, pStart, pEnd);CHKERRQ(ierr); 1365552f7358SJed Brown ierr = PetscSectionSetChart(mesh->supportSection, pStart, pEnd);CHKERRQ(ierr); 1366552f7358SJed Brown PetscFunctionReturn(0); 1367552f7358SJed Brown } 1368552f7358SJed Brown 1369552f7358SJed Brown /*@ 1370eaf898f9SPatrick Sanan DMPlexGetConeSize - Return the number of in-edges for this point in the DAG 1371552f7358SJed Brown 1372552f7358SJed Brown Not collective 1373552f7358SJed Brown 1374552f7358SJed Brown Input Parameters: 1375552f7358SJed Brown + mesh - The DMPlex 1376eaf898f9SPatrick Sanan - p - The point, which must lie in the chart set with DMPlexSetChart() 1377552f7358SJed Brown 1378552f7358SJed Brown Output Parameter: 1379552f7358SJed Brown . size - The cone size for point p 1380552f7358SJed Brown 1381552f7358SJed Brown Level: beginner 1382552f7358SJed Brown 1383552f7358SJed Brown .seealso: DMPlexCreate(), DMPlexSetConeSize(), DMPlexSetChart() 1384552f7358SJed Brown @*/ 1385552f7358SJed Brown PetscErrorCode DMPlexGetConeSize(DM dm, PetscInt p, PetscInt *size) 1386552f7358SJed Brown { 1387552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 1388552f7358SJed Brown PetscErrorCode ierr; 1389552f7358SJed Brown 1390552f7358SJed Brown PetscFunctionBegin; 1391552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1392552f7358SJed Brown PetscValidPointer(size, 3); 1393552f7358SJed Brown ierr = PetscSectionGetDof(mesh->coneSection, p, size);CHKERRQ(ierr); 1394552f7358SJed Brown PetscFunctionReturn(0); 1395552f7358SJed Brown } 1396552f7358SJed Brown 1397552f7358SJed Brown /*@ 1398eaf898f9SPatrick Sanan DMPlexSetConeSize - Set the number of in-edges for this point in the DAG 1399552f7358SJed Brown 1400552f7358SJed Brown Not collective 1401552f7358SJed Brown 1402552f7358SJed Brown Input Parameters: 1403552f7358SJed Brown + mesh - The DMPlex 1404eaf898f9SPatrick Sanan . p - The point, which must lie in the chart set with DMPlexSetChart() 1405552f7358SJed Brown - size - The cone size for point p 1406552f7358SJed Brown 1407552f7358SJed Brown Output Parameter: 1408552f7358SJed Brown 1409552f7358SJed Brown Note: 1410552f7358SJed Brown This should be called after DMPlexSetChart(). 1411552f7358SJed Brown 1412552f7358SJed Brown Level: beginner 1413552f7358SJed Brown 1414552f7358SJed Brown .seealso: DMPlexCreate(), DMPlexGetConeSize(), DMPlexSetChart() 1415552f7358SJed Brown @*/ 1416552f7358SJed Brown PetscErrorCode DMPlexSetConeSize(DM dm, PetscInt p, PetscInt size) 1417552f7358SJed Brown { 1418552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 1419552f7358SJed Brown PetscErrorCode ierr; 1420552f7358SJed Brown 1421552f7358SJed Brown PetscFunctionBegin; 1422552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1423552f7358SJed Brown ierr = PetscSectionSetDof(mesh->coneSection, p, size);CHKERRQ(ierr); 14240d644c17SKarl Rupp 1425552f7358SJed Brown mesh->maxConeSize = PetscMax(mesh->maxConeSize, size); 1426552f7358SJed Brown PetscFunctionReturn(0); 1427552f7358SJed Brown } 1428552f7358SJed Brown 1429f5a469b9SMatthew G. Knepley /*@ 1430eaf898f9SPatrick Sanan DMPlexAddConeSize - Add the given number of in-edges to this point in the DAG 1431f5a469b9SMatthew G. Knepley 1432f5a469b9SMatthew G. Knepley Not collective 1433f5a469b9SMatthew G. Knepley 1434f5a469b9SMatthew G. Knepley Input Parameters: 1435f5a469b9SMatthew G. Knepley + mesh - The DMPlex 1436eaf898f9SPatrick Sanan . p - The point, which must lie in the chart set with DMPlexSetChart() 1437f5a469b9SMatthew G. Knepley - size - The additional cone size for point p 1438f5a469b9SMatthew G. Knepley 1439f5a469b9SMatthew G. Knepley Output Parameter: 1440f5a469b9SMatthew G. Knepley 1441f5a469b9SMatthew G. Knepley Note: 1442f5a469b9SMatthew G. Knepley This should be called after DMPlexSetChart(). 1443f5a469b9SMatthew G. Knepley 1444f5a469b9SMatthew G. Knepley Level: beginner 1445f5a469b9SMatthew G. Knepley 1446f5a469b9SMatthew G. Knepley .seealso: DMPlexCreate(), DMPlexSetConeSize(), DMPlexGetConeSize(), DMPlexSetChart() 1447f5a469b9SMatthew G. Knepley @*/ 1448f5a469b9SMatthew G. Knepley PetscErrorCode DMPlexAddConeSize(DM dm, PetscInt p, PetscInt size) 1449f5a469b9SMatthew G. Knepley { 1450f5a469b9SMatthew G. Knepley DM_Plex *mesh = (DM_Plex*) dm->data; 1451f5a469b9SMatthew G. Knepley PetscInt csize; 1452f5a469b9SMatthew G. Knepley PetscErrorCode ierr; 1453f5a469b9SMatthew G. Knepley 1454f5a469b9SMatthew G. Knepley PetscFunctionBegin; 1455f5a469b9SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1456f5a469b9SMatthew G. Knepley ierr = PetscSectionAddDof(mesh->coneSection, p, size);CHKERRQ(ierr); 1457f5a469b9SMatthew G. Knepley ierr = PetscSectionGetDof(mesh->coneSection, p, &csize);CHKERRQ(ierr); 1458f5a469b9SMatthew G. Knepley 1459f5a469b9SMatthew G. Knepley mesh->maxConeSize = PetscMax(mesh->maxConeSize, csize); 1460f5a469b9SMatthew G. Knepley PetscFunctionReturn(0); 1461f5a469b9SMatthew G. Knepley } 1462f5a469b9SMatthew G. Knepley 1463552f7358SJed Brown /*@C 1464eaf898f9SPatrick Sanan DMPlexGetCone - Return the points on the in-edges for this point in the DAG 1465552f7358SJed Brown 1466552f7358SJed Brown Not collective 1467552f7358SJed Brown 1468552f7358SJed Brown Input Parameters: 1469552f7358SJed Brown + mesh - The DMPlex 1470eaf898f9SPatrick Sanan - p - The point, which must lie in the chart set with DMPlexSetChart() 1471552f7358SJed Brown 1472552f7358SJed Brown Output Parameter: 1473552f7358SJed Brown . cone - An array of points which are on the in-edges for point p 1474552f7358SJed Brown 1475552f7358SJed Brown Level: beginner 1476552f7358SJed Brown 14773813dfbdSMatthew G Knepley Fortran Notes: 14783813dfbdSMatthew G Knepley Since it returns an array, this routine is only available in Fortran 90, and you must 14793813dfbdSMatthew G Knepley include petsc.h90 in your code. 14803813dfbdSMatthew G Knepley 14813813dfbdSMatthew G Knepley You must also call DMPlexRestoreCone() after you finish using the returned array. 1482552f7358SJed Brown 1483552f7358SJed Brown .seealso: DMPlexCreate(), DMPlexSetCone(), DMPlexSetChart() 1484552f7358SJed Brown @*/ 1485552f7358SJed Brown PetscErrorCode DMPlexGetCone(DM dm, PetscInt p, const PetscInt *cone[]) 1486552f7358SJed Brown { 1487552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 1488552f7358SJed Brown PetscInt off; 1489552f7358SJed Brown PetscErrorCode ierr; 1490552f7358SJed Brown 1491552f7358SJed Brown PetscFunctionBegin; 1492552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1493552f7358SJed Brown PetscValidPointer(cone, 3); 1494552f7358SJed Brown ierr = PetscSectionGetOffset(mesh->coneSection, p, &off);CHKERRQ(ierr); 1495552f7358SJed Brown *cone = &mesh->cones[off]; 1496552f7358SJed Brown PetscFunctionReturn(0); 1497552f7358SJed Brown } 1498552f7358SJed Brown 1499552f7358SJed Brown /*@ 150092371b87SBarry Smith DMPlexSetCone - Set the points on the in-edges for this point in the DAG; that is these are the points that cover the specific point 1501552f7358SJed Brown 1502552f7358SJed Brown Not collective 1503552f7358SJed Brown 1504552f7358SJed Brown Input Parameters: 1505552f7358SJed Brown + mesh - The DMPlex 1506eaf898f9SPatrick Sanan . p - The point, which must lie in the chart set with DMPlexSetChart() 1507552f7358SJed Brown - cone - An array of points which are on the in-edges for point p 1508552f7358SJed Brown 1509552f7358SJed Brown Output Parameter: 1510552f7358SJed Brown 1511552f7358SJed Brown Note: 1512552f7358SJed Brown This should be called after all calls to DMPlexSetConeSize() and DMSetUp(). 1513552f7358SJed Brown 151492371b87SBarry Smith Developer Note: Why not call this DMPlexSetCover() 151592371b87SBarry Smith 1516552f7358SJed Brown Level: beginner 1517552f7358SJed Brown 151892371b87SBarry Smith .seealso: DMPlexCreate(), DMPlexGetCone(), DMPlexSetChart(), DMPlexSetConeSize(), DMSetUp(), DMPlexSetSupport(), DMPlexSetSupportSize() 1519552f7358SJed Brown @*/ 1520552f7358SJed Brown PetscErrorCode DMPlexSetCone(DM dm, PetscInt p, const PetscInt cone[]) 1521552f7358SJed Brown { 1522552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 1523552f7358SJed Brown PetscInt pStart, pEnd; 1524552f7358SJed Brown PetscInt dof, off, c; 1525552f7358SJed Brown PetscErrorCode ierr; 1526552f7358SJed Brown 1527552f7358SJed Brown PetscFunctionBegin; 1528552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1529552f7358SJed Brown ierr = PetscSectionGetChart(mesh->coneSection, &pStart, &pEnd);CHKERRQ(ierr); 1530552f7358SJed Brown ierr = PetscSectionGetDof(mesh->coneSection, p, &dof);CHKERRQ(ierr); 1531552f7358SJed Brown if (dof) PetscValidPointer(cone, 3); 1532552f7358SJed Brown ierr = PetscSectionGetOffset(mesh->coneSection, p, &off);CHKERRQ(ierr); 153382f516ccSBarry Smith if ((p < pStart) || (p >= pEnd)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Mesh point %D is not in the valid range [%D, %D)", p, pStart, pEnd); 1534552f7358SJed Brown for (c = 0; c < dof; ++c) { 153582f516ccSBarry Smith if ((cone[c] < pStart) || (cone[c] >= pEnd)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Cone point %D is not in the valid range [%D, %D)", cone[c], pStart, pEnd); 1536552f7358SJed Brown mesh->cones[off+c] = cone[c]; 1537552f7358SJed Brown } 1538552f7358SJed Brown PetscFunctionReturn(0); 1539552f7358SJed Brown } 1540552f7358SJed Brown 1541552f7358SJed Brown /*@C 1542eaf898f9SPatrick Sanan DMPlexGetConeOrientation - Return the orientations on the in-edges for this point in the DAG 1543552f7358SJed Brown 1544552f7358SJed Brown Not collective 1545552f7358SJed Brown 1546552f7358SJed Brown Input Parameters: 1547552f7358SJed Brown + mesh - The DMPlex 1548eaf898f9SPatrick Sanan - p - The point, which must lie in the chart set with DMPlexSetChart() 1549552f7358SJed Brown 1550552f7358SJed Brown Output Parameter: 1551552f7358SJed Brown . coneOrientation - An array of orientations which are on the in-edges for point p. An orientation is an 1552552f7358SJed Brown integer giving the prescription for cone traversal. If it is negative, the cone is 1553552f7358SJed Brown traversed in the opposite direction. Its value 'o', or if negative '-(o+1)', gives 1554552f7358SJed Brown the index of the cone point on which to start. 1555552f7358SJed Brown 1556552f7358SJed Brown Level: beginner 1557552f7358SJed Brown 15583813dfbdSMatthew G Knepley Fortran Notes: 15593813dfbdSMatthew G Knepley Since it returns an array, this routine is only available in Fortran 90, and you must 15603813dfbdSMatthew G Knepley include petsc.h90 in your code. 15613813dfbdSMatthew G Knepley 15623813dfbdSMatthew G Knepley You must also call DMPlexRestoreConeOrientation() after you finish using the returned array. 1563552f7358SJed Brown 1564552f7358SJed Brown .seealso: DMPlexCreate(), DMPlexGetCone(), DMPlexSetCone(), DMPlexSetChart() 1565552f7358SJed Brown @*/ 1566552f7358SJed Brown PetscErrorCode DMPlexGetConeOrientation(DM dm, PetscInt p, const PetscInt *coneOrientation[]) 1567552f7358SJed Brown { 1568552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 1569552f7358SJed Brown PetscInt off; 1570552f7358SJed Brown PetscErrorCode ierr; 1571552f7358SJed Brown 1572552f7358SJed Brown PetscFunctionBegin; 1573552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1574552f7358SJed Brown #if defined(PETSC_USE_DEBUG) 1575552f7358SJed Brown { 1576552f7358SJed Brown PetscInt dof; 1577552f7358SJed Brown ierr = PetscSectionGetDof(mesh->coneSection, p, &dof);CHKERRQ(ierr); 1578552f7358SJed Brown if (dof) PetscValidPointer(coneOrientation, 3); 1579552f7358SJed Brown } 1580552f7358SJed Brown #endif 1581552f7358SJed Brown ierr = PetscSectionGetOffset(mesh->coneSection, p, &off);CHKERRQ(ierr); 15820d644c17SKarl Rupp 1583552f7358SJed Brown *coneOrientation = &mesh->coneOrientations[off]; 1584552f7358SJed Brown PetscFunctionReturn(0); 1585552f7358SJed Brown } 1586552f7358SJed Brown 1587552f7358SJed Brown /*@ 1588eaf898f9SPatrick Sanan DMPlexSetConeOrientation - Set the orientations on the in-edges for this point in the DAG 1589552f7358SJed Brown 1590552f7358SJed Brown Not collective 1591552f7358SJed Brown 1592552f7358SJed Brown Input Parameters: 1593552f7358SJed Brown + mesh - The DMPlex 1594eaf898f9SPatrick Sanan . p - The point, which must lie in the chart set with DMPlexSetChart() 1595552f7358SJed Brown - coneOrientation - An array of orientations which are on the in-edges for point p. An orientation is an 1596552f7358SJed Brown integer giving the prescription for cone traversal. If it is negative, the cone is 1597552f7358SJed Brown traversed in the opposite direction. Its value 'o', or if negative '-(o+1)', gives 1598552f7358SJed Brown the index of the cone point on which to start. 1599552f7358SJed Brown 1600552f7358SJed Brown Output Parameter: 1601552f7358SJed Brown 1602552f7358SJed Brown Note: 1603552f7358SJed Brown This should be called after all calls to DMPlexSetConeSize() and DMSetUp(). 1604552f7358SJed Brown 1605552f7358SJed Brown Level: beginner 1606552f7358SJed Brown 1607552f7358SJed Brown .seealso: DMPlexCreate(), DMPlexGetConeOrientation(), DMPlexSetCone(), DMPlexSetChart(), DMPlexSetConeSize(), DMSetUp() 1608552f7358SJed Brown @*/ 1609552f7358SJed Brown PetscErrorCode DMPlexSetConeOrientation(DM dm, PetscInt p, const PetscInt coneOrientation[]) 1610552f7358SJed Brown { 1611552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 1612552f7358SJed Brown PetscInt pStart, pEnd; 1613552f7358SJed Brown PetscInt dof, off, c; 1614552f7358SJed Brown PetscErrorCode ierr; 1615552f7358SJed Brown 1616552f7358SJed Brown PetscFunctionBegin; 1617552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1618552f7358SJed Brown ierr = PetscSectionGetChart(mesh->coneSection, &pStart, &pEnd);CHKERRQ(ierr); 1619552f7358SJed Brown ierr = PetscSectionGetDof(mesh->coneSection, p, &dof);CHKERRQ(ierr); 1620552f7358SJed Brown if (dof) PetscValidPointer(coneOrientation, 3); 1621552f7358SJed Brown ierr = PetscSectionGetOffset(mesh->coneSection, p, &off);CHKERRQ(ierr); 162282f516ccSBarry Smith if ((p < pStart) || (p >= pEnd)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Mesh point %D is not in the valid range [%D, %D)", p, pStart, pEnd); 1623552f7358SJed Brown for (c = 0; c < dof; ++c) { 1624552f7358SJed Brown PetscInt cdof, o = coneOrientation[c]; 1625552f7358SJed Brown 1626552f7358SJed Brown ierr = PetscSectionGetDof(mesh->coneSection, mesh->cones[off+c], &cdof);CHKERRQ(ierr); 162782f516ccSBarry Smith if (o && ((o < -(cdof+1)) || (o >= cdof))) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Cone orientation %D is not in the valid range [%D. %D)", o, -(cdof+1), cdof); 1628552f7358SJed Brown mesh->coneOrientations[off+c] = o; 1629552f7358SJed Brown } 1630552f7358SJed Brown PetscFunctionReturn(0); 1631552f7358SJed Brown } 1632552f7358SJed Brown 16337cd05799SMatthew G. Knepley /*@ 1634eaf898f9SPatrick Sanan DMPlexInsertCone - Insert a point into the in-edges for the point p in the DAG 16357cd05799SMatthew G. Knepley 16367cd05799SMatthew G. Knepley Not collective 16377cd05799SMatthew G. Knepley 16387cd05799SMatthew G. Knepley Input Parameters: 16397cd05799SMatthew G. Knepley + mesh - The DMPlex 1640eaf898f9SPatrick Sanan . p - The point, which must lie in the chart set with DMPlexSetChart() 16417cd05799SMatthew G. Knepley . conePos - The local index in the cone where the point should be put 16427cd05799SMatthew G. Knepley - conePoint - The mesh point to insert 16437cd05799SMatthew G. Knepley 16447cd05799SMatthew G. Knepley Level: beginner 16457cd05799SMatthew G. Knepley 16467cd05799SMatthew G. Knepley .seealso: DMPlexCreate(), DMPlexGetCone(), DMPlexSetChart(), DMPlexSetConeSize(), DMSetUp() 16477cd05799SMatthew G. Knepley @*/ 1648552f7358SJed Brown PetscErrorCode DMPlexInsertCone(DM dm, PetscInt p, PetscInt conePos, PetscInt conePoint) 1649552f7358SJed Brown { 1650552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 1651552f7358SJed Brown PetscInt pStart, pEnd; 1652552f7358SJed Brown PetscInt dof, off; 1653552f7358SJed Brown PetscErrorCode ierr; 1654552f7358SJed Brown 1655552f7358SJed Brown PetscFunctionBegin; 1656552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1657552f7358SJed Brown ierr = PetscSectionGetChart(mesh->coneSection, &pStart, &pEnd);CHKERRQ(ierr); 165882f516ccSBarry Smith if ((p < pStart) || (p >= pEnd)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Mesh point %D is not in the valid range [%D, %D)", p, pStart, pEnd); 165982f516ccSBarry Smith if ((conePoint < pStart) || (conePoint >= pEnd)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Cone point %D is not in the valid range [%D, %D)", conePoint, pStart, pEnd); 166077c88f5bSMatthew G Knepley ierr = PetscSectionGetDof(mesh->coneSection, p, &dof);CHKERRQ(ierr); 166177c88f5bSMatthew G Knepley ierr = PetscSectionGetOffset(mesh->coneSection, p, &off);CHKERRQ(ierr); 166277c88f5bSMatthew G Knepley if ((conePos < 0) || (conePos >= dof)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Cone position %D of point %D is not in the valid range [0, %D)", conePos, p, dof); 1663552f7358SJed Brown mesh->cones[off+conePos] = conePoint; 1664552f7358SJed Brown PetscFunctionReturn(0); 1665552f7358SJed Brown } 1666552f7358SJed Brown 16677cd05799SMatthew G. Knepley /*@ 1668eaf898f9SPatrick Sanan DMPlexInsertConeOrientation - Insert a point orientation for the in-edge for the point p in the DAG 16697cd05799SMatthew G. Knepley 16707cd05799SMatthew G. Knepley Not collective 16717cd05799SMatthew G. Knepley 16727cd05799SMatthew G. Knepley Input Parameters: 16737cd05799SMatthew G. Knepley + mesh - The DMPlex 1674eaf898f9SPatrick Sanan . p - The point, which must lie in the chart set with DMPlexSetChart() 16757cd05799SMatthew G. Knepley . conePos - The local index in the cone where the point should be put 16767cd05799SMatthew G. Knepley - coneOrientation - The point orientation to insert 16777cd05799SMatthew G. Knepley 16787cd05799SMatthew G. Knepley Level: beginner 16797cd05799SMatthew G. Knepley 16807cd05799SMatthew G. Knepley .seealso: DMPlexCreate(), DMPlexGetCone(), DMPlexSetChart(), DMPlexSetConeSize(), DMSetUp() 16817cd05799SMatthew G. Knepley @*/ 168277c88f5bSMatthew G Knepley PetscErrorCode DMPlexInsertConeOrientation(DM dm, PetscInt p, PetscInt conePos, PetscInt coneOrientation) 168377c88f5bSMatthew G Knepley { 168477c88f5bSMatthew G Knepley DM_Plex *mesh = (DM_Plex*) dm->data; 168577c88f5bSMatthew G Knepley PetscInt pStart, pEnd; 168677c88f5bSMatthew G Knepley PetscInt dof, off; 168777c88f5bSMatthew G Knepley PetscErrorCode ierr; 168877c88f5bSMatthew G Knepley 168977c88f5bSMatthew G Knepley PetscFunctionBegin; 169077c88f5bSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 169177c88f5bSMatthew G Knepley ierr = PetscSectionGetChart(mesh->coneSection, &pStart, &pEnd);CHKERRQ(ierr); 169277c88f5bSMatthew G Knepley if ((p < pStart) || (p >= pEnd)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Mesh point %D is not in the valid range [%D, %D)", p, pStart, pEnd); 169377c88f5bSMatthew G Knepley ierr = PetscSectionGetDof(mesh->coneSection, p, &dof);CHKERRQ(ierr); 169477c88f5bSMatthew G Knepley ierr = PetscSectionGetOffset(mesh->coneSection, p, &off);CHKERRQ(ierr); 169577c88f5bSMatthew G Knepley if ((conePos < 0) || (conePos >= dof)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Cone position %D of point %D is not in the valid range [0, %D)", conePos, p, dof); 169677c88f5bSMatthew G Knepley mesh->coneOrientations[off+conePos] = coneOrientation; 169777c88f5bSMatthew G Knepley PetscFunctionReturn(0); 169877c88f5bSMatthew G Knepley } 169977c88f5bSMatthew G Knepley 1700552f7358SJed Brown /*@ 1701eaf898f9SPatrick Sanan DMPlexGetSupportSize - Return the number of out-edges for this point in the DAG 1702552f7358SJed Brown 1703552f7358SJed Brown Not collective 1704552f7358SJed Brown 1705552f7358SJed Brown Input Parameters: 1706552f7358SJed Brown + mesh - The DMPlex 1707eaf898f9SPatrick Sanan - p - The point, which must lie in the chart set with DMPlexSetChart() 1708552f7358SJed Brown 1709552f7358SJed Brown Output Parameter: 1710552f7358SJed Brown . size - The support size for point p 1711552f7358SJed Brown 1712552f7358SJed Brown Level: beginner 1713552f7358SJed Brown 1714552f7358SJed Brown .seealso: DMPlexCreate(), DMPlexSetConeSize(), DMPlexSetChart(), DMPlexGetConeSize() 1715552f7358SJed Brown @*/ 1716552f7358SJed Brown PetscErrorCode DMPlexGetSupportSize(DM dm, PetscInt p, PetscInt *size) 1717552f7358SJed Brown { 1718552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 1719552f7358SJed Brown PetscErrorCode ierr; 1720552f7358SJed Brown 1721552f7358SJed Brown PetscFunctionBegin; 1722552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1723552f7358SJed Brown PetscValidPointer(size, 3); 1724552f7358SJed Brown ierr = PetscSectionGetDof(mesh->supportSection, p, size);CHKERRQ(ierr); 1725552f7358SJed Brown PetscFunctionReturn(0); 1726552f7358SJed Brown } 1727552f7358SJed Brown 1728552f7358SJed Brown /*@ 1729eaf898f9SPatrick Sanan DMPlexSetSupportSize - Set the number of out-edges for this point in the DAG 1730552f7358SJed Brown 1731552f7358SJed Brown Not collective 1732552f7358SJed Brown 1733552f7358SJed Brown Input Parameters: 1734552f7358SJed Brown + mesh - The DMPlex 1735eaf898f9SPatrick Sanan . p - The point, which must lie in the chart set with DMPlexSetChart() 1736552f7358SJed Brown - size - The support size for point p 1737552f7358SJed Brown 1738552f7358SJed Brown Output Parameter: 1739552f7358SJed Brown 1740552f7358SJed Brown Note: 1741552f7358SJed Brown This should be called after DMPlexSetChart(). 1742552f7358SJed Brown 1743552f7358SJed Brown Level: beginner 1744552f7358SJed Brown 1745552f7358SJed Brown .seealso: DMPlexCreate(), DMPlexGetSupportSize(), DMPlexSetChart() 1746552f7358SJed Brown @*/ 1747552f7358SJed Brown PetscErrorCode DMPlexSetSupportSize(DM dm, PetscInt p, PetscInt size) 1748552f7358SJed Brown { 1749552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 1750552f7358SJed Brown PetscErrorCode ierr; 1751552f7358SJed Brown 1752552f7358SJed Brown PetscFunctionBegin; 1753552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1754552f7358SJed Brown ierr = PetscSectionSetDof(mesh->supportSection, p, size);CHKERRQ(ierr); 17550d644c17SKarl Rupp 1756552f7358SJed Brown mesh->maxSupportSize = PetscMax(mesh->maxSupportSize, size); 1757552f7358SJed Brown PetscFunctionReturn(0); 1758552f7358SJed Brown } 1759552f7358SJed Brown 1760552f7358SJed Brown /*@C 1761eaf898f9SPatrick Sanan DMPlexGetSupport - Return the points on the out-edges for this point in the DAG 1762552f7358SJed Brown 1763552f7358SJed Brown Not collective 1764552f7358SJed Brown 1765552f7358SJed Brown Input Parameters: 1766552f7358SJed Brown + mesh - The DMPlex 1767eaf898f9SPatrick Sanan - p - The point, which must lie in the chart set with DMPlexSetChart() 1768552f7358SJed Brown 1769552f7358SJed Brown Output Parameter: 1770552f7358SJed Brown . support - An array of points which are on the out-edges for point p 1771552f7358SJed Brown 1772552f7358SJed Brown Level: beginner 1773552f7358SJed Brown 17743813dfbdSMatthew G Knepley Fortran Notes: 17753813dfbdSMatthew G Knepley Since it returns an array, this routine is only available in Fortran 90, and you must 17763813dfbdSMatthew G Knepley include petsc.h90 in your code. 17773813dfbdSMatthew G Knepley 17783813dfbdSMatthew G Knepley You must also call DMPlexRestoreSupport() after you finish using the returned array. 17793813dfbdSMatthew G Knepley 1780552f7358SJed Brown .seealso: DMPlexCreate(), DMPlexSetCone(), DMPlexSetChart(), DMPlexGetCone() 1781552f7358SJed Brown @*/ 1782552f7358SJed Brown PetscErrorCode DMPlexGetSupport(DM dm, PetscInt p, const PetscInt *support[]) 1783552f7358SJed Brown { 1784552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 1785552f7358SJed Brown PetscInt off; 1786552f7358SJed Brown PetscErrorCode ierr; 1787552f7358SJed Brown 1788552f7358SJed Brown PetscFunctionBegin; 1789552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1790552f7358SJed Brown PetscValidPointer(support, 3); 1791552f7358SJed Brown ierr = PetscSectionGetOffset(mesh->supportSection, p, &off);CHKERRQ(ierr); 1792552f7358SJed Brown *support = &mesh->supports[off]; 1793552f7358SJed Brown PetscFunctionReturn(0); 1794552f7358SJed Brown } 1795552f7358SJed Brown 1796552f7358SJed Brown /*@ 179792371b87SBarry Smith DMPlexSetSupport - Set the points on the out-edges for this point in the DAG, that is the list of points that this point covers 1798552f7358SJed Brown 1799552f7358SJed Brown Not collective 1800552f7358SJed Brown 1801552f7358SJed Brown Input Parameters: 1802552f7358SJed Brown + mesh - The DMPlex 1803eaf898f9SPatrick Sanan . p - The point, which must lie in the chart set with DMPlexSetChart() 180492371b87SBarry Smith - support - An array of points which are on the out-edges for point p 1805552f7358SJed Brown 1806552f7358SJed Brown Output Parameter: 1807552f7358SJed Brown 1808552f7358SJed Brown Note: 1809552f7358SJed Brown This should be called after all calls to DMPlexSetSupportSize() and DMSetUp(). 1810552f7358SJed Brown 1811552f7358SJed Brown Level: beginner 1812552f7358SJed Brown 181392371b87SBarry Smith .seealso: DMPlexSetCone(), DMPlexSetConeSize(), DMPlexCreate(), DMPlexGetSupport(), DMPlexSetChart(), DMPlexSetSupportSize(), DMSetUp() 1814552f7358SJed Brown @*/ 1815552f7358SJed Brown PetscErrorCode DMPlexSetSupport(DM dm, PetscInt p, const PetscInt support[]) 1816552f7358SJed Brown { 1817552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 1818552f7358SJed Brown PetscInt pStart, pEnd; 1819552f7358SJed Brown PetscInt dof, off, c; 1820552f7358SJed Brown PetscErrorCode ierr; 1821552f7358SJed Brown 1822552f7358SJed Brown PetscFunctionBegin; 1823552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1824552f7358SJed Brown ierr = PetscSectionGetChart(mesh->supportSection, &pStart, &pEnd);CHKERRQ(ierr); 1825552f7358SJed Brown ierr = PetscSectionGetDof(mesh->supportSection, p, &dof);CHKERRQ(ierr); 1826552f7358SJed Brown if (dof) PetscValidPointer(support, 3); 1827552f7358SJed Brown ierr = PetscSectionGetOffset(mesh->supportSection, p, &off);CHKERRQ(ierr); 182882f516ccSBarry Smith if ((p < pStart) || (p >= pEnd)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Mesh point %D is not in the valid range [%D, %D)", p, pStart, pEnd); 1829552f7358SJed Brown for (c = 0; c < dof; ++c) { 183082f516ccSBarry Smith if ((support[c] < pStart) || (support[c] >= pEnd)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Support point %D is not in the valid range [%D, %D)", support[c], pStart, pEnd); 1831552f7358SJed Brown mesh->supports[off+c] = support[c]; 1832552f7358SJed Brown } 1833552f7358SJed Brown PetscFunctionReturn(0); 1834552f7358SJed Brown } 1835552f7358SJed Brown 18367cd05799SMatthew G. Knepley /*@ 1837eaf898f9SPatrick Sanan DMPlexInsertSupport - Insert a point into the out-edges for the point p in the DAG 18387cd05799SMatthew G. Knepley 18397cd05799SMatthew G. Knepley Not collective 18407cd05799SMatthew G. Knepley 18417cd05799SMatthew G. Knepley Input Parameters: 18427cd05799SMatthew G. Knepley + mesh - The DMPlex 1843eaf898f9SPatrick Sanan . p - The point, which must lie in the chart set with DMPlexSetChart() 18447cd05799SMatthew G. Knepley . supportPos - The local index in the cone where the point should be put 18457cd05799SMatthew G. Knepley - supportPoint - The mesh point to insert 18467cd05799SMatthew G. Knepley 18477cd05799SMatthew G. Knepley Level: beginner 18487cd05799SMatthew G. Knepley 18497cd05799SMatthew G. Knepley .seealso: DMPlexCreate(), DMPlexGetCone(), DMPlexSetChart(), DMPlexSetConeSize(), DMSetUp() 18507cd05799SMatthew G. Knepley @*/ 1851552f7358SJed Brown PetscErrorCode DMPlexInsertSupport(DM dm, PetscInt p, PetscInt supportPos, PetscInt supportPoint) 1852552f7358SJed Brown { 1853552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 1854552f7358SJed Brown PetscInt pStart, pEnd; 1855552f7358SJed Brown PetscInt dof, off; 1856552f7358SJed Brown PetscErrorCode ierr; 1857552f7358SJed Brown 1858552f7358SJed Brown PetscFunctionBegin; 1859552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1860552f7358SJed Brown ierr = PetscSectionGetChart(mesh->supportSection, &pStart, &pEnd);CHKERRQ(ierr); 1861552f7358SJed Brown ierr = PetscSectionGetDof(mesh->supportSection, p, &dof);CHKERRQ(ierr); 1862552f7358SJed Brown ierr = PetscSectionGetOffset(mesh->supportSection, p, &off);CHKERRQ(ierr); 186382f516ccSBarry Smith if ((p < pStart) || (p >= pEnd)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Mesh point %D is not in the valid range [%D, %D)", p, pStart, pEnd); 186482f516ccSBarry Smith if ((supportPoint < pStart) || (supportPoint >= pEnd)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Support point %D is not in the valid range [%D, %D)", supportPoint, pStart, pEnd); 186582f516ccSBarry Smith if (supportPos >= dof) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Support position %D of point %D is not in the valid range [0, %D)", supportPos, p, dof); 1866552f7358SJed Brown mesh->supports[off+supportPos] = supportPoint; 1867552f7358SJed Brown PetscFunctionReturn(0); 1868552f7358SJed Brown } 1869552f7358SJed Brown 1870552f7358SJed Brown /*@C 1871eaf898f9SPatrick Sanan DMPlexGetTransitiveClosure - Return the points on the transitive closure of the in-edges or out-edges for this point in the DAG 1872552f7358SJed Brown 1873552f7358SJed Brown Not collective 1874552f7358SJed Brown 1875552f7358SJed Brown Input Parameters: 1876552f7358SJed Brown + mesh - The DMPlex 1877eaf898f9SPatrick Sanan . p - The point, which must lie in the chart set with DMPlexSetChart() 1878552f7358SJed Brown . useCone - PETSC_TRUE for in-edges, otherwise use out-edges 18790298fd71SBarry Smith - points - If points is NULL on input, internal storage will be returned, otherwise the provided array is used 1880552f7358SJed Brown 1881552f7358SJed Brown Output Parameters: 1882552f7358SJed Brown + numPoints - The number of points in the closure, so points[] is of size 2*numPoints 1883552f7358SJed Brown - points - The points and point orientations, interleaved as pairs [p0, o0, p1, o1, ...] 1884552f7358SJed Brown 1885552f7358SJed Brown Note: 18860298fd71SBarry Smith If using internal storage (points is NULL on input), each call overwrites the last output. 1887552f7358SJed Brown 18883813dfbdSMatthew G Knepley Fortran Notes: 18893813dfbdSMatthew G Knepley Since it returns an array, this routine is only available in Fortran 90, and you must 18903813dfbdSMatthew G Knepley include petsc.h90 in your code. 18913813dfbdSMatthew G Knepley 18923813dfbdSMatthew G Knepley The numPoints argument is not present in the Fortran 90 binding since it is internal to the array. 18933813dfbdSMatthew G Knepley 1894552f7358SJed Brown Level: beginner 1895552f7358SJed Brown 1896552f7358SJed Brown .seealso: DMPlexRestoreTransitiveClosure(), DMPlexCreate(), DMPlexSetCone(), DMPlexSetChart(), DMPlexGetCone() 1897552f7358SJed Brown @*/ 1898552f7358SJed Brown PetscErrorCode DMPlexGetTransitiveClosure(DM dm, PetscInt p, PetscBool useCone, PetscInt *numPoints, PetscInt *points[]) 1899552f7358SJed Brown { 1900552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 1901552f7358SJed Brown PetscInt *closure, *fifo; 19020298fd71SBarry Smith const PetscInt *tmp = NULL, *tmpO = NULL; 1903552f7358SJed Brown PetscInt tmpSize, t; 1904552f7358SJed Brown PetscInt depth = 0, maxSize; 1905552f7358SJed Brown PetscInt closureSize = 2, fifoSize = 0, fifoStart = 0; 1906552f7358SJed Brown PetscErrorCode ierr; 1907552f7358SJed Brown 1908552f7358SJed Brown PetscFunctionBegin; 1909552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 1910552f7358SJed Brown ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 1911552f7358SJed Brown /* This is only 1-level */ 1912552f7358SJed Brown if (useCone) { 1913552f7358SJed Brown ierr = DMPlexGetConeSize(dm, p, &tmpSize);CHKERRQ(ierr); 1914552f7358SJed Brown ierr = DMPlexGetCone(dm, p, &tmp);CHKERRQ(ierr); 1915552f7358SJed Brown ierr = DMPlexGetConeOrientation(dm, p, &tmpO);CHKERRQ(ierr); 1916552f7358SJed Brown } else { 1917552f7358SJed Brown ierr = DMPlexGetSupportSize(dm, p, &tmpSize);CHKERRQ(ierr); 1918552f7358SJed Brown ierr = DMPlexGetSupport(dm, p, &tmp);CHKERRQ(ierr); 1919552f7358SJed Brown } 1920bfbcdd7aSMatthew G. Knepley if (depth == 1) { 1921bfbcdd7aSMatthew G. Knepley if (*points) { 1922bfbcdd7aSMatthew G. Knepley closure = *points; 1923bfbcdd7aSMatthew G. Knepley } else { 1924bfbcdd7aSMatthew G. Knepley maxSize = 2*(PetscMax(mesh->maxConeSize, mesh->maxSupportSize)+1); 192569291d52SBarry Smith ierr = DMGetWorkArray(dm, maxSize, MPIU_INT, &closure);CHKERRQ(ierr); 1926bfbcdd7aSMatthew G. Knepley } 1927bfbcdd7aSMatthew G. Knepley closure[0] = p; closure[1] = 0; 1928bfbcdd7aSMatthew G. Knepley for (t = 0; t < tmpSize; ++t, closureSize += 2) { 1929bfbcdd7aSMatthew G. Knepley closure[closureSize] = tmp[t]; 1930bfbcdd7aSMatthew G. Knepley closure[closureSize+1] = tmpO ? tmpO[t] : 0; 1931bfbcdd7aSMatthew G. Knepley } 1932bfbcdd7aSMatthew G. Knepley if (numPoints) *numPoints = closureSize/2; 1933bfbcdd7aSMatthew G. Knepley if (points) *points = closure; 1934bfbcdd7aSMatthew G. Knepley PetscFunctionReturn(0); 1935bfbcdd7aSMatthew G. Knepley } 193624c766afSToby Isaac { 193724c766afSToby Isaac PetscInt c, coneSeries, s,supportSeries; 193824c766afSToby Isaac 193924c766afSToby Isaac c = mesh->maxConeSize; 194024c766afSToby Isaac coneSeries = (c > 1) ? ((PetscPowInt(c,depth+1)-1)/(c-1)) : depth+1; 194124c766afSToby Isaac s = mesh->maxSupportSize; 194224c766afSToby Isaac supportSeries = (s > 1) ? ((PetscPowInt(s,depth+1)-1)/(s-1)) : depth+1; 194324c766afSToby Isaac maxSize = 2*PetscMax(coneSeries,supportSeries); 194424c766afSToby Isaac } 194569291d52SBarry Smith ierr = DMGetWorkArray(dm, maxSize, MPIU_INT, &fifo);CHKERRQ(ierr); 1946bfbcdd7aSMatthew G. Knepley if (*points) { 1947bfbcdd7aSMatthew G. Knepley closure = *points; 1948bfbcdd7aSMatthew G. Knepley } else { 194969291d52SBarry Smith ierr = DMGetWorkArray(dm, maxSize, MPIU_INT, &closure);CHKERRQ(ierr); 1950bfbcdd7aSMatthew G. Knepley } 1951bfbcdd7aSMatthew G. Knepley closure[0] = p; closure[1] = 0; 1952552f7358SJed Brown for (t = 0; t < tmpSize; ++t, closureSize += 2, fifoSize += 2) { 1953552f7358SJed Brown const PetscInt cp = tmp[t]; 1954552f7358SJed Brown const PetscInt co = tmpO ? tmpO[t] : 0; 1955552f7358SJed Brown 1956552f7358SJed Brown closure[closureSize] = cp; 1957552f7358SJed Brown closure[closureSize+1] = co; 1958552f7358SJed Brown fifo[fifoSize] = cp; 1959552f7358SJed Brown fifo[fifoSize+1] = co; 1960552f7358SJed Brown } 1961bfbcdd7aSMatthew G. Knepley /* Should kick out early when depth is reached, rather than checking all vertices for empty cones */ 1962552f7358SJed Brown while (fifoSize - fifoStart) { 1963552f7358SJed Brown const PetscInt q = fifo[fifoStart]; 1964552f7358SJed Brown const PetscInt o = fifo[fifoStart+1]; 1965552f7358SJed Brown const PetscInt rev = o >= 0 ? 0 : 1; 1966552f7358SJed Brown const PetscInt off = rev ? -(o+1) : o; 1967552f7358SJed Brown 1968552f7358SJed Brown if (useCone) { 1969552f7358SJed Brown ierr = DMPlexGetConeSize(dm, q, &tmpSize);CHKERRQ(ierr); 1970552f7358SJed Brown ierr = DMPlexGetCone(dm, q, &tmp);CHKERRQ(ierr); 1971552f7358SJed Brown ierr = DMPlexGetConeOrientation(dm, q, &tmpO);CHKERRQ(ierr); 1972552f7358SJed Brown } else { 1973552f7358SJed Brown ierr = DMPlexGetSupportSize(dm, q, &tmpSize);CHKERRQ(ierr); 1974552f7358SJed Brown ierr = DMPlexGetSupport(dm, q, &tmp);CHKERRQ(ierr); 19750298fd71SBarry Smith tmpO = NULL; 1976552f7358SJed Brown } 1977552f7358SJed Brown for (t = 0; t < tmpSize; ++t) { 1978552f7358SJed Brown const PetscInt i = ((rev ? tmpSize-t : t) + off)%tmpSize; 1979552f7358SJed Brown const PetscInt cp = tmp[i]; 19802e1b13c2SMatthew G. Knepley /* Must propogate orientation: When we reverse orientation, we both reverse the direction of iteration and start at the other end of the chain. */ 19812e1b13c2SMatthew G. Knepley /* HACK: It is worse to get the size here, than to change the interpretation of -(*+1) 19822e1b13c2SMatthew G. Knepley const PetscInt co = tmpO ? (rev ? -(tmpO[i]+1) : tmpO[i]) : 0; */ 19832e1b13c2SMatthew G. Knepley PetscInt co = tmpO ? tmpO[i] : 0; 1984552f7358SJed Brown PetscInt c; 1985552f7358SJed Brown 19862e1b13c2SMatthew G. Knepley if (rev) { 19872e1b13c2SMatthew G. Knepley PetscInt childSize, coff; 19882e1b13c2SMatthew G. Knepley ierr = DMPlexGetConeSize(dm, cp, &childSize);CHKERRQ(ierr); 19892e1b13c2SMatthew G. Knepley coff = tmpO[i] < 0 ? -(tmpO[i]+1) : tmpO[i]; 19902e1b13c2SMatthew G. Knepley co = childSize ? -(((coff+childSize-1)%childSize)+1) : 0; 19912e1b13c2SMatthew G. Knepley } 1992552f7358SJed Brown /* Check for duplicate */ 1993552f7358SJed Brown for (c = 0; c < closureSize; c += 2) { 1994552f7358SJed Brown if (closure[c] == cp) break; 1995552f7358SJed Brown } 1996552f7358SJed Brown if (c == closureSize) { 1997552f7358SJed Brown closure[closureSize] = cp; 1998552f7358SJed Brown closure[closureSize+1] = co; 1999552f7358SJed Brown fifo[fifoSize] = cp; 2000552f7358SJed Brown fifo[fifoSize+1] = co; 2001552f7358SJed Brown closureSize += 2; 2002552f7358SJed Brown fifoSize += 2; 2003552f7358SJed Brown } 2004552f7358SJed Brown } 2005552f7358SJed Brown fifoStart += 2; 2006552f7358SJed Brown } 2007552f7358SJed Brown if (numPoints) *numPoints = closureSize/2; 2008552f7358SJed Brown if (points) *points = closure; 200969291d52SBarry Smith ierr = DMRestoreWorkArray(dm, maxSize, MPIU_INT, &fifo);CHKERRQ(ierr); 2010552f7358SJed Brown PetscFunctionReturn(0); 2011552f7358SJed Brown } 2012552f7358SJed Brown 20139bf0dad6SMatthew G. Knepley /*@C 2014eaf898f9SPatrick Sanan DMPlexGetTransitiveClosure_Internal - Return the points on the transitive closure of the in-edges or out-edges for this point in the DAG with a specified initial orientation 20159bf0dad6SMatthew G. Knepley 20169bf0dad6SMatthew G. Knepley Not collective 20179bf0dad6SMatthew G. Knepley 20189bf0dad6SMatthew G. Knepley Input Parameters: 20199bf0dad6SMatthew G. Knepley + mesh - The DMPlex 2020eaf898f9SPatrick Sanan . p - The point, which must lie in the chart set with DMPlexSetChart() 20219bf0dad6SMatthew G. Knepley . orientation - The orientation of the point 20229bf0dad6SMatthew G. Knepley . useCone - PETSC_TRUE for in-edges, otherwise use out-edges 20239bf0dad6SMatthew G. Knepley - points - If points is NULL on input, internal storage will be returned, otherwise the provided array is used 20249bf0dad6SMatthew G. Knepley 20259bf0dad6SMatthew G. Knepley Output Parameters: 20269bf0dad6SMatthew G. Knepley + numPoints - The number of points in the closure, so points[] is of size 2*numPoints 20279bf0dad6SMatthew G. Knepley - points - The points and point orientations, interleaved as pairs [p0, o0, p1, o1, ...] 20289bf0dad6SMatthew G. Knepley 20299bf0dad6SMatthew G. Knepley Note: 20309bf0dad6SMatthew G. Knepley If using internal storage (points is NULL on input), each call overwrites the last output. 20319bf0dad6SMatthew G. Knepley 20329bf0dad6SMatthew G. Knepley Fortran Notes: 20339bf0dad6SMatthew G. Knepley Since it returns an array, this routine is only available in Fortran 90, and you must 20349bf0dad6SMatthew G. Knepley include petsc.h90 in your code. 20359bf0dad6SMatthew G. Knepley 20369bf0dad6SMatthew G. Knepley The numPoints argument is not present in the Fortran 90 binding since it is internal to the array. 20379bf0dad6SMatthew G. Knepley 20389bf0dad6SMatthew G. Knepley Level: beginner 20399bf0dad6SMatthew G. Knepley 20409bf0dad6SMatthew G. Knepley .seealso: DMPlexRestoreTransitiveClosure(), DMPlexCreate(), DMPlexSetCone(), DMPlexSetChart(), DMPlexGetCone() 20419bf0dad6SMatthew G. Knepley @*/ 20429bf0dad6SMatthew G. Knepley PetscErrorCode DMPlexGetTransitiveClosure_Internal(DM dm, PetscInt p, PetscInt ornt, PetscBool useCone, PetscInt *numPoints, PetscInt *points[]) 20439bf0dad6SMatthew G. Knepley { 20449bf0dad6SMatthew G. Knepley DM_Plex *mesh = (DM_Plex*) dm->data; 20459bf0dad6SMatthew G. Knepley PetscInt *closure, *fifo; 20469bf0dad6SMatthew G. Knepley const PetscInt *tmp = NULL, *tmpO = NULL; 20479bf0dad6SMatthew G. Knepley PetscInt tmpSize, t; 20489bf0dad6SMatthew G. Knepley PetscInt depth = 0, maxSize; 20499bf0dad6SMatthew G. Knepley PetscInt closureSize = 2, fifoSize = 0, fifoStart = 0; 20509bf0dad6SMatthew G. Knepley PetscErrorCode ierr; 20519bf0dad6SMatthew G. Knepley 20529bf0dad6SMatthew G. Knepley PetscFunctionBegin; 20539bf0dad6SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 20549bf0dad6SMatthew G. Knepley ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 20559bf0dad6SMatthew G. Knepley /* This is only 1-level */ 20569bf0dad6SMatthew G. Knepley if (useCone) { 20579bf0dad6SMatthew G. Knepley ierr = DMPlexGetConeSize(dm, p, &tmpSize);CHKERRQ(ierr); 20589bf0dad6SMatthew G. Knepley ierr = DMPlexGetCone(dm, p, &tmp);CHKERRQ(ierr); 20599bf0dad6SMatthew G. Knepley ierr = DMPlexGetConeOrientation(dm, p, &tmpO);CHKERRQ(ierr); 20609bf0dad6SMatthew G. Knepley } else { 20619bf0dad6SMatthew G. Knepley ierr = DMPlexGetSupportSize(dm, p, &tmpSize);CHKERRQ(ierr); 20629bf0dad6SMatthew G. Knepley ierr = DMPlexGetSupport(dm, p, &tmp);CHKERRQ(ierr); 20639bf0dad6SMatthew G. Knepley } 20649bf0dad6SMatthew G. Knepley if (depth == 1) { 20659bf0dad6SMatthew G. Knepley if (*points) { 20669bf0dad6SMatthew G. Knepley closure = *points; 20679bf0dad6SMatthew G. Knepley } else { 20689bf0dad6SMatthew G. Knepley maxSize = 2*(PetscMax(mesh->maxConeSize, mesh->maxSupportSize)+1); 206969291d52SBarry Smith ierr = DMGetWorkArray(dm, maxSize, MPIU_INT, &closure);CHKERRQ(ierr); 20709bf0dad6SMatthew G. Knepley } 20719bf0dad6SMatthew G. Knepley closure[0] = p; closure[1] = ornt; 20729bf0dad6SMatthew G. Knepley for (t = 0; t < tmpSize; ++t, closureSize += 2) { 20739bf0dad6SMatthew G. Knepley const PetscInt i = ornt >= 0 ? (t+ornt)%tmpSize : (-(ornt+1) + tmpSize-t)%tmpSize; 20749bf0dad6SMatthew G. Knepley closure[closureSize] = tmp[i]; 20759bf0dad6SMatthew G. Knepley closure[closureSize+1] = tmpO ? tmpO[i] : 0; 20769bf0dad6SMatthew G. Knepley } 20779bf0dad6SMatthew G. Knepley if (numPoints) *numPoints = closureSize/2; 20789bf0dad6SMatthew G. Knepley if (points) *points = closure; 20799bf0dad6SMatthew G. Knepley PetscFunctionReturn(0); 20809bf0dad6SMatthew G. Knepley } 208124c766afSToby Isaac { 208224c766afSToby Isaac PetscInt c, coneSeries, s,supportSeries; 208324c766afSToby Isaac 208424c766afSToby Isaac c = mesh->maxConeSize; 208524c766afSToby Isaac coneSeries = (c > 1) ? ((PetscPowInt(c,depth+1)-1)/(c-1)) : depth+1; 208624c766afSToby Isaac s = mesh->maxSupportSize; 208724c766afSToby Isaac supportSeries = (s > 1) ? ((PetscPowInt(s,depth+1)-1)/(s-1)) : depth+1; 208824c766afSToby Isaac maxSize = 2*PetscMax(coneSeries,supportSeries); 208924c766afSToby Isaac } 209069291d52SBarry Smith ierr = DMGetWorkArray(dm, maxSize, MPIU_INT, &fifo);CHKERRQ(ierr); 20919bf0dad6SMatthew G. Knepley if (*points) { 20929bf0dad6SMatthew G. Knepley closure = *points; 20939bf0dad6SMatthew G. Knepley } else { 209469291d52SBarry Smith ierr = DMGetWorkArray(dm, maxSize, MPIU_INT, &closure);CHKERRQ(ierr); 20959bf0dad6SMatthew G. Knepley } 20969bf0dad6SMatthew G. Knepley closure[0] = p; closure[1] = ornt; 20979bf0dad6SMatthew G. Knepley for (t = 0; t < tmpSize; ++t, closureSize += 2, fifoSize += 2) { 20989bf0dad6SMatthew G. Knepley const PetscInt i = ornt >= 0 ? (t+ornt)%tmpSize : (-(ornt+1) + tmpSize-t)%tmpSize; 20999bf0dad6SMatthew G. Knepley const PetscInt cp = tmp[i]; 21009bf0dad6SMatthew G. Knepley PetscInt co = tmpO ? tmpO[i] : 0; 21019bf0dad6SMatthew G. Knepley 21029bf0dad6SMatthew G. Knepley if (ornt < 0) { 21039bf0dad6SMatthew G. Knepley PetscInt childSize, coff; 21049bf0dad6SMatthew G. Knepley ierr = DMPlexGetConeSize(dm, cp, &childSize);CHKERRQ(ierr); 210586b63641SMatthew G. Knepley coff = co < 0 ? -(tmpO[i]+1) : tmpO[i]; 21069bf0dad6SMatthew G. Knepley co = childSize ? -(((coff+childSize-1)%childSize)+1) : 0; 21079bf0dad6SMatthew G. Knepley } 21089bf0dad6SMatthew G. Knepley closure[closureSize] = cp; 21099bf0dad6SMatthew G. Knepley closure[closureSize+1] = co; 21109bf0dad6SMatthew G. Knepley fifo[fifoSize] = cp; 21119bf0dad6SMatthew G. Knepley fifo[fifoSize+1] = co; 21129bf0dad6SMatthew G. Knepley } 21139bf0dad6SMatthew G. Knepley /* Should kick out early when depth is reached, rather than checking all vertices for empty cones */ 21149bf0dad6SMatthew G. Knepley while (fifoSize - fifoStart) { 21159bf0dad6SMatthew G. Knepley const PetscInt q = fifo[fifoStart]; 21169bf0dad6SMatthew G. Knepley const PetscInt o = fifo[fifoStart+1]; 21179bf0dad6SMatthew G. Knepley const PetscInt rev = o >= 0 ? 0 : 1; 21189bf0dad6SMatthew G. Knepley const PetscInt off = rev ? -(o+1) : o; 21199bf0dad6SMatthew G. Knepley 21209bf0dad6SMatthew G. Knepley if (useCone) { 21219bf0dad6SMatthew G. Knepley ierr = DMPlexGetConeSize(dm, q, &tmpSize);CHKERRQ(ierr); 21229bf0dad6SMatthew G. Knepley ierr = DMPlexGetCone(dm, q, &tmp);CHKERRQ(ierr); 21239bf0dad6SMatthew G. Knepley ierr = DMPlexGetConeOrientation(dm, q, &tmpO);CHKERRQ(ierr); 21249bf0dad6SMatthew G. Knepley } else { 21259bf0dad6SMatthew G. Knepley ierr = DMPlexGetSupportSize(dm, q, &tmpSize);CHKERRQ(ierr); 21269bf0dad6SMatthew G. Knepley ierr = DMPlexGetSupport(dm, q, &tmp);CHKERRQ(ierr); 21279bf0dad6SMatthew G. Knepley tmpO = NULL; 21289bf0dad6SMatthew G. Knepley } 21299bf0dad6SMatthew G. Knepley for (t = 0; t < tmpSize; ++t) { 21309bf0dad6SMatthew G. Knepley const PetscInt i = ((rev ? tmpSize-t : t) + off)%tmpSize; 21319bf0dad6SMatthew G. Knepley const PetscInt cp = tmp[i]; 21329bf0dad6SMatthew G. Knepley /* Must propogate orientation: When we reverse orientation, we both reverse the direction of iteration and start at the other end of the chain. */ 21339bf0dad6SMatthew G. Knepley /* HACK: It is worse to get the size here, than to change the interpretation of -(*+1) 21349bf0dad6SMatthew G. Knepley const PetscInt co = tmpO ? (rev ? -(tmpO[i]+1) : tmpO[i]) : 0; */ 21359bf0dad6SMatthew G. Knepley PetscInt co = tmpO ? tmpO[i] : 0; 21369bf0dad6SMatthew G. Knepley PetscInt c; 21379bf0dad6SMatthew G. Knepley 21389bf0dad6SMatthew G. Knepley if (rev) { 21399bf0dad6SMatthew G. Knepley PetscInt childSize, coff; 21409bf0dad6SMatthew G. Knepley ierr = DMPlexGetConeSize(dm, cp, &childSize);CHKERRQ(ierr); 21419bf0dad6SMatthew G. Knepley coff = tmpO[i] < 0 ? -(tmpO[i]+1) : tmpO[i]; 21429bf0dad6SMatthew G. Knepley co = childSize ? -(((coff+childSize-1)%childSize)+1) : 0; 21439bf0dad6SMatthew G. Knepley } 21449bf0dad6SMatthew G. Knepley /* Check for duplicate */ 21459bf0dad6SMatthew G. Knepley for (c = 0; c < closureSize; c += 2) { 21469bf0dad6SMatthew G. Knepley if (closure[c] == cp) break; 21479bf0dad6SMatthew G. Knepley } 21489bf0dad6SMatthew G. Knepley if (c == closureSize) { 21499bf0dad6SMatthew G. Knepley closure[closureSize] = cp; 21509bf0dad6SMatthew G. Knepley closure[closureSize+1] = co; 21519bf0dad6SMatthew G. Knepley fifo[fifoSize] = cp; 21529bf0dad6SMatthew G. Knepley fifo[fifoSize+1] = co; 21539bf0dad6SMatthew G. Knepley closureSize += 2; 21549bf0dad6SMatthew G. Knepley fifoSize += 2; 21559bf0dad6SMatthew G. Knepley } 21569bf0dad6SMatthew G. Knepley } 21579bf0dad6SMatthew G. Knepley fifoStart += 2; 21589bf0dad6SMatthew G. Knepley } 21599bf0dad6SMatthew G. Knepley if (numPoints) *numPoints = closureSize/2; 21609bf0dad6SMatthew G. Knepley if (points) *points = closure; 216169291d52SBarry Smith ierr = DMRestoreWorkArray(dm, maxSize, MPIU_INT, &fifo);CHKERRQ(ierr); 21629bf0dad6SMatthew G. Knepley PetscFunctionReturn(0); 21639bf0dad6SMatthew G. Knepley } 21649bf0dad6SMatthew G. Knepley 2165552f7358SJed Brown /*@C 2166eaf898f9SPatrick Sanan DMPlexRestoreTransitiveClosure - Restore the array of points on the transitive closure of the in-edges or out-edges for this point in the DAG 2167552f7358SJed Brown 2168552f7358SJed Brown Not collective 2169552f7358SJed Brown 2170552f7358SJed Brown Input Parameters: 2171552f7358SJed Brown + mesh - The DMPlex 2172eaf898f9SPatrick Sanan . p - The point, which must lie in the chart set with DMPlexSetChart() 2173552f7358SJed Brown . useCone - PETSC_TRUE for in-edges, otherwise use out-edges 2174e5c84f05SJed Brown . numPoints - The number of points in the closure, so points[] is of size 2*numPoints, zeroed on exit 2175e5c84f05SJed Brown - points - The points and point orientations, interleaved as pairs [p0, o0, p1, o1, ...], zeroed on exit 2176552f7358SJed Brown 2177552f7358SJed Brown Note: 21780298fd71SBarry Smith If not using internal storage (points is not NULL on input), this call is unnecessary 2179552f7358SJed Brown 21803813dfbdSMatthew G Knepley Fortran Notes: 21813813dfbdSMatthew G Knepley Since it returns an array, this routine is only available in Fortran 90, and you must 21823813dfbdSMatthew G Knepley include petsc.h90 in your code. 21833813dfbdSMatthew G Knepley 21843813dfbdSMatthew G Knepley The numPoints argument is not present in the Fortran 90 binding since it is internal to the array. 21853813dfbdSMatthew G Knepley 2186552f7358SJed Brown Level: beginner 2187552f7358SJed Brown 2188552f7358SJed Brown .seealso: DMPlexGetTransitiveClosure(), DMPlexCreate(), DMPlexSetCone(), DMPlexSetChart(), DMPlexGetCone() 2189552f7358SJed Brown @*/ 2190552f7358SJed Brown PetscErrorCode DMPlexRestoreTransitiveClosure(DM dm, PetscInt p, PetscBool useCone, PetscInt *numPoints, PetscInt *points[]) 2191552f7358SJed Brown { 2192552f7358SJed Brown PetscErrorCode ierr; 2193552f7358SJed Brown 2194552f7358SJed Brown PetscFunctionBegin; 2195552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 2196e5c84f05SJed Brown if (numPoints) PetscValidIntPointer(numPoints,4); 2197e5c84f05SJed Brown if (points) PetscValidPointer(points,5); 219869291d52SBarry Smith ierr = DMRestoreWorkArray(dm, 0, MPIU_INT, points);CHKERRQ(ierr); 21994ff43b2cSJed Brown if (numPoints) *numPoints = 0; 2200552f7358SJed Brown PetscFunctionReturn(0); 2201552f7358SJed Brown } 2202552f7358SJed Brown 2203552f7358SJed Brown /*@ 2204eaf898f9SPatrick Sanan DMPlexGetMaxSizes - Return the maximum number of in-edges (cone) and out-edges (support) for any point in the DAG 2205552f7358SJed Brown 2206552f7358SJed Brown Not collective 2207552f7358SJed Brown 2208552f7358SJed Brown Input Parameter: 2209552f7358SJed Brown . mesh - The DMPlex 2210552f7358SJed Brown 2211552f7358SJed Brown Output Parameters: 2212552f7358SJed Brown + maxConeSize - The maximum number of in-edges 2213552f7358SJed Brown - maxSupportSize - The maximum number of out-edges 2214552f7358SJed Brown 2215552f7358SJed Brown Level: beginner 2216552f7358SJed Brown 2217552f7358SJed Brown .seealso: DMPlexCreate(), DMPlexSetConeSize(), DMPlexSetChart() 2218552f7358SJed Brown @*/ 2219552f7358SJed Brown PetscErrorCode DMPlexGetMaxSizes(DM dm, PetscInt *maxConeSize, PetscInt *maxSupportSize) 2220552f7358SJed Brown { 2221552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 2222552f7358SJed Brown 2223552f7358SJed Brown PetscFunctionBegin; 2224552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 2225552f7358SJed Brown if (maxConeSize) *maxConeSize = mesh->maxConeSize; 2226552f7358SJed Brown if (maxSupportSize) *maxSupportSize = mesh->maxSupportSize; 2227552f7358SJed Brown PetscFunctionReturn(0); 2228552f7358SJed Brown } 2229552f7358SJed Brown 2230552f7358SJed Brown PetscErrorCode DMSetUp_Plex(DM dm) 2231552f7358SJed Brown { 2232552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 2233552f7358SJed Brown PetscInt size; 2234552f7358SJed Brown PetscErrorCode ierr; 2235552f7358SJed Brown 2236552f7358SJed Brown PetscFunctionBegin; 2237552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 2238552f7358SJed Brown ierr = PetscSectionSetUp(mesh->coneSection);CHKERRQ(ierr); 2239552f7358SJed Brown ierr = PetscSectionGetStorageSize(mesh->coneSection, &size);CHKERRQ(ierr); 22401795a4d1SJed Brown ierr = PetscMalloc1(size, &mesh->cones);CHKERRQ(ierr); 22411795a4d1SJed Brown ierr = PetscCalloc1(size, &mesh->coneOrientations);CHKERRQ(ierr); 2242552f7358SJed Brown if (mesh->maxSupportSize) { 2243552f7358SJed Brown ierr = PetscSectionSetUp(mesh->supportSection);CHKERRQ(ierr); 2244552f7358SJed Brown ierr = PetscSectionGetStorageSize(mesh->supportSection, &size);CHKERRQ(ierr); 22451795a4d1SJed Brown ierr = PetscMalloc1(size, &mesh->supports);CHKERRQ(ierr); 2246552f7358SJed Brown } 2247552f7358SJed Brown PetscFunctionReturn(0); 2248552f7358SJed Brown } 2249552f7358SJed Brown 2250276c5506SMatthew G. Knepley PetscErrorCode DMCreateSubDM_Plex(DM dm, PetscInt numFields, const PetscInt fields[], IS *is, DM *subdm) 2251552f7358SJed Brown { 2252552f7358SJed Brown PetscErrorCode ierr; 2253552f7358SJed Brown 2254552f7358SJed Brown PetscFunctionBegin; 22554d9407bcSMatthew G. Knepley if (subdm) {ierr = DMClone(dm, subdm);CHKERRQ(ierr);} 22564d9407bcSMatthew G. Knepley ierr = DMCreateSubDM_Section_Private(dm, numFields, fields, is, subdm);CHKERRQ(ierr); 2257c2939958SSatish Balay if (subdm) {(*subdm)->useNatural = dm->useNatural;} 2258736995cdSBlaise Bourdin if (dm->useNatural && dm->sfMigration) { 2259f94b4a02SBlaise Bourdin PetscSF sfMigrationInv,sfNatural; 2260f94b4a02SBlaise Bourdin PetscSection section, sectionSeq; 2261f94b4a02SBlaise Bourdin 22623dcd263cSBlaise Bourdin (*subdm)->sfMigration = dm->sfMigration; 22633dcd263cSBlaise Bourdin ierr = PetscObjectReference((PetscObject) dm->sfMigration);CHKERRQ(ierr); 2264e87a4003SBarry Smith ierr = DMGetSection((*subdm), §ion);CHKERRQ(ierr);CHKERRQ(ierr); 2265f94b4a02SBlaise Bourdin ierr = PetscSFCreateInverseSF((*subdm)->sfMigration, &sfMigrationInv);CHKERRQ(ierr); 2266f94b4a02SBlaise Bourdin ierr = PetscSectionCreate(PetscObjectComm((PetscObject) (*subdm)), §ionSeq);CHKERRQ(ierr); 2267f94b4a02SBlaise Bourdin ierr = PetscSFDistributeSection(sfMigrationInv, section, NULL, sectionSeq);CHKERRQ(ierr); 2268f94b4a02SBlaise Bourdin 2269f94b4a02SBlaise Bourdin ierr = DMPlexCreateGlobalToNaturalSF(*subdm, sectionSeq, (*subdm)->sfMigration, &sfNatural);CHKERRQ(ierr); 2270c40e9495SBlaise Bourdin (*subdm)->sfNatural = sfNatural; 2271f94b4a02SBlaise Bourdin ierr = PetscSectionDestroy(§ionSeq);CHKERRQ(ierr); 2272f94b4a02SBlaise Bourdin ierr = PetscSFDestroy(&sfMigrationInv);CHKERRQ(ierr); 2273f94b4a02SBlaise Bourdin } 2274552f7358SJed Brown PetscFunctionReturn(0); 2275552f7358SJed Brown } 2276552f7358SJed Brown 22772adcc780SMatthew G. Knepley PetscErrorCode DMCreateSuperDM_Plex(DM dms[], PetscInt len, IS **is, DM *superdm) 22782adcc780SMatthew G. Knepley { 22792adcc780SMatthew G. Knepley PetscErrorCode ierr; 22803dcd263cSBlaise Bourdin PetscInt i = 0; 22812adcc780SMatthew G. Knepley 22822adcc780SMatthew G. Knepley PetscFunctionBegin; 22832adcc780SMatthew G. Knepley if (superdm) {ierr = DMClone(dms[0], superdm);CHKERRQ(ierr);} 22842adcc780SMatthew G. Knepley ierr = DMCreateSuperDM_Section_Private(dms, len, is, superdm);CHKERRQ(ierr); 2285c40e9495SBlaise Bourdin (*superdm)->useNatural = PETSC_FALSE; 22863dcd263cSBlaise Bourdin for (i = 0; i < len; i++){ 22873dcd263cSBlaise Bourdin if (dms[i]->useNatural && dms[i]->sfMigration) { 22883dcd263cSBlaise Bourdin PetscSF sfMigrationInv,sfNatural; 22893dcd263cSBlaise Bourdin PetscSection section, sectionSeq; 22903dcd263cSBlaise Bourdin 22913dcd263cSBlaise Bourdin (*superdm)->sfMigration = dms[i]->sfMigration; 22923dcd263cSBlaise Bourdin ierr = PetscObjectReference((PetscObject) dms[i]->sfMigration);CHKERRQ(ierr); 2293c40e9495SBlaise Bourdin (*superdm)->useNatural = PETSC_TRUE; 2294cf0b7c11SKarl Rupp ierr = DMGetSection((*superdm), §ion);CHKERRQ(ierr); 22953dcd263cSBlaise Bourdin ierr = PetscSFCreateInverseSF((*superdm)->sfMigration, &sfMigrationInv);CHKERRQ(ierr); 22963dcd263cSBlaise Bourdin ierr = PetscSectionCreate(PetscObjectComm((PetscObject) (*superdm)), §ionSeq);CHKERRQ(ierr); 22973dcd263cSBlaise Bourdin ierr = PetscSFDistributeSection(sfMigrationInv, section, NULL, sectionSeq);CHKERRQ(ierr); 22983dcd263cSBlaise Bourdin 22993dcd263cSBlaise Bourdin ierr = DMPlexCreateGlobalToNaturalSF(*superdm, sectionSeq, (*superdm)->sfMigration, &sfNatural);CHKERRQ(ierr); 2300c40e9495SBlaise Bourdin (*superdm)->sfNatural = sfNatural; 23013dcd263cSBlaise Bourdin ierr = PetscSectionDestroy(§ionSeq);CHKERRQ(ierr); 23023dcd263cSBlaise Bourdin ierr = PetscSFDestroy(&sfMigrationInv);CHKERRQ(ierr); 23033dcd263cSBlaise Bourdin break; 23043dcd263cSBlaise Bourdin } 23053dcd263cSBlaise Bourdin } 23062adcc780SMatthew G. Knepley PetscFunctionReturn(0); 23072adcc780SMatthew G. Knepley } 23082adcc780SMatthew G. Knepley 2309552f7358SJed Brown /*@ 2310eaf898f9SPatrick Sanan DMPlexSymmetrize - Create support (out-edge) information from cone (in-edge) information 2311552f7358SJed Brown 2312552f7358SJed Brown Not collective 2313552f7358SJed Brown 2314552f7358SJed Brown Input Parameter: 2315552f7358SJed Brown . mesh - The DMPlex 2316552f7358SJed Brown 2317552f7358SJed Brown Output Parameter: 2318552f7358SJed Brown 2319552f7358SJed Brown Note: 2320552f7358SJed Brown This should be called after all calls to DMPlexSetCone() 2321552f7358SJed Brown 2322552f7358SJed Brown Level: beginner 2323552f7358SJed Brown 2324552f7358SJed Brown .seealso: DMPlexCreate(), DMPlexSetChart(), DMPlexSetConeSize(), DMPlexSetCone() 2325552f7358SJed Brown @*/ 2326552f7358SJed Brown PetscErrorCode DMPlexSymmetrize(DM dm) 2327552f7358SJed Brown { 2328552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 2329552f7358SJed Brown PetscInt *offsets; 2330552f7358SJed Brown PetscInt supportSize; 2331552f7358SJed Brown PetscInt pStart, pEnd, p; 2332552f7358SJed Brown PetscErrorCode ierr; 2333552f7358SJed Brown 2334552f7358SJed Brown PetscFunctionBegin; 2335552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 233682f516ccSBarry Smith if (mesh->supports) SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONGSTATE, "Supports were already setup in this DMPlex"); 2337552f7358SJed Brown /* Calculate support sizes */ 2338552f7358SJed Brown ierr = DMPlexGetChart(dm, &pStart, &pEnd);CHKERRQ(ierr); 2339552f7358SJed Brown for (p = pStart; p < pEnd; ++p) { 2340552f7358SJed Brown PetscInt dof, off, c; 2341552f7358SJed Brown 2342552f7358SJed Brown ierr = PetscSectionGetDof(mesh->coneSection, p, &dof);CHKERRQ(ierr); 2343552f7358SJed Brown ierr = PetscSectionGetOffset(mesh->coneSection, p, &off);CHKERRQ(ierr); 2344552f7358SJed Brown for (c = off; c < off+dof; ++c) { 2345552f7358SJed Brown ierr = PetscSectionAddDof(mesh->supportSection, mesh->cones[c], 1);CHKERRQ(ierr); 2346552f7358SJed Brown } 2347552f7358SJed Brown } 2348552f7358SJed Brown for (p = pStart; p < pEnd; ++p) { 2349552f7358SJed Brown PetscInt dof; 2350552f7358SJed Brown 2351552f7358SJed Brown ierr = PetscSectionGetDof(mesh->supportSection, p, &dof);CHKERRQ(ierr); 23520d644c17SKarl Rupp 2353552f7358SJed Brown mesh->maxSupportSize = PetscMax(mesh->maxSupportSize, dof); 2354552f7358SJed Brown } 2355552f7358SJed Brown ierr = PetscSectionSetUp(mesh->supportSection);CHKERRQ(ierr); 2356552f7358SJed Brown /* Calculate supports */ 2357552f7358SJed Brown ierr = PetscSectionGetStorageSize(mesh->supportSection, &supportSize);CHKERRQ(ierr); 23581795a4d1SJed Brown ierr = PetscMalloc1(supportSize, &mesh->supports);CHKERRQ(ierr); 23591795a4d1SJed Brown ierr = PetscCalloc1(pEnd - pStart, &offsets);CHKERRQ(ierr); 2360552f7358SJed Brown for (p = pStart; p < pEnd; ++p) { 2361552f7358SJed Brown PetscInt dof, off, c; 2362552f7358SJed Brown 2363552f7358SJed Brown ierr = PetscSectionGetDof(mesh->coneSection, p, &dof);CHKERRQ(ierr); 2364552f7358SJed Brown ierr = PetscSectionGetOffset(mesh->coneSection, p, &off);CHKERRQ(ierr); 2365552f7358SJed Brown for (c = off; c < off+dof; ++c) { 2366552f7358SJed Brown const PetscInt q = mesh->cones[c]; 2367552f7358SJed Brown PetscInt offS; 2368552f7358SJed Brown 2369552f7358SJed Brown ierr = PetscSectionGetOffset(mesh->supportSection, q, &offS);CHKERRQ(ierr); 23700d644c17SKarl Rupp 2371552f7358SJed Brown mesh->supports[offS+offsets[q]] = p; 2372552f7358SJed Brown ++offsets[q]; 2373552f7358SJed Brown } 2374552f7358SJed Brown } 2375552f7358SJed Brown ierr = PetscFree(offsets);CHKERRQ(ierr); 2376552f7358SJed Brown PetscFunctionReturn(0); 2377552f7358SJed Brown } 2378552f7358SJed Brown 23797d5acc75SStefano Zampini static PetscErrorCode DMPlexCreateDimStratum(DM,DMLabel,DMLabel,PetscInt,PetscInt); 23807d5acc75SStefano Zampini 2381552f7358SJed Brown /*@ 2382eaf898f9SPatrick Sanan DMPlexStratify - The DAG for most topologies is a graded poset (http://en.wikipedia.org/wiki/Graded_poset), and 2383eaf898f9SPatrick Sanan can be illustrated by a Hasse Diagram (a http://en.wikipedia.org/wiki/Hasse_diagram). The strata group all points of the 2384552f7358SJed Brown same grade, and this function calculates the strata. This grade can be seen as the height (or depth) of the point in 2385552f7358SJed Brown the DAG. 2386552f7358SJed Brown 2387bf4602e4SToby Isaac Collective on dm 2388552f7358SJed Brown 2389552f7358SJed Brown Input Parameter: 2390552f7358SJed Brown . mesh - The DMPlex 2391552f7358SJed Brown 2392552f7358SJed Brown Output Parameter: 2393552f7358SJed Brown 2394552f7358SJed Brown Notes: 2395150b719bSJed Brown Concretely, DMPlexStratify() creates a new label named "depth" containing the dimension of each element: 0 for vertices, 2396150b719bSJed Brown 1 for edges, and so on. The depth label can be accessed through DMPlexGetDepthLabel() or DMPlexGetDepthStratum(), or 2397c58f1c22SToby Isaac manually via DMGetLabel(). The height is defined implicitly by height = maxDimension - depth, and can be accessed 2398150b719bSJed Brown via DMPlexGetHeightStratum(). For example, cells have height 0 and faces have height 1. 2399552f7358SJed Brown 2400150b719bSJed Brown DMPlexStratify() should be called after all calls to DMPlexSymmetrize() 2401552f7358SJed Brown 2402552f7358SJed Brown Level: beginner 2403552f7358SJed Brown 2404552f7358SJed Brown .seealso: DMPlexCreate(), DMPlexSymmetrize() 2405552f7358SJed Brown @*/ 2406552f7358SJed Brown PetscErrorCode DMPlexStratify(DM dm) 2407552f7358SJed Brown { 2408df0420ecSMatthew G. Knepley DM_Plex *mesh = (DM_Plex*) dm->data; 2409aa50250dSMatthew G. Knepley DMLabel label; 2410552f7358SJed Brown PetscInt pStart, pEnd, p; 2411552f7358SJed Brown PetscInt numRoots = 0, numLeaves = 0; 24127d5acc75SStefano Zampini PetscInt cMax, fMax, eMax, vMax; 2413552f7358SJed Brown PetscErrorCode ierr; 2414552f7358SJed Brown 2415552f7358SJed Brown PetscFunctionBegin; 2416552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 2417552f7358SJed Brown ierr = PetscLogEventBegin(DMPLEX_Stratify,dm,0,0,0);CHKERRQ(ierr); 2418552f7358SJed Brown /* Calculate depth */ 2419aa50250dSMatthew G. Knepley ierr = DMPlexGetChart(dm, &pStart, &pEnd);CHKERRQ(ierr); 2420c58f1c22SToby Isaac ierr = DMCreateLabel(dm, "depth");CHKERRQ(ierr); 2421aa50250dSMatthew G. Knepley ierr = DMPlexGetDepthLabel(dm, &label);CHKERRQ(ierr); 2422552f7358SJed Brown /* Initialize roots and count leaves */ 2423552f7358SJed Brown for (p = pStart; p < pEnd; ++p) { 2424552f7358SJed Brown PetscInt coneSize, supportSize; 2425552f7358SJed Brown 2426552f7358SJed Brown ierr = DMPlexGetConeSize(dm, p, &coneSize);CHKERRQ(ierr); 2427552f7358SJed Brown ierr = DMPlexGetSupportSize(dm, p, &supportSize);CHKERRQ(ierr); 2428552f7358SJed Brown if (!coneSize && supportSize) { 2429552f7358SJed Brown ++numRoots; 2430aa50250dSMatthew G. Knepley ierr = DMLabelSetValue(label, p, 0);CHKERRQ(ierr); 2431552f7358SJed Brown } else if (!supportSize && coneSize) { 2432552f7358SJed Brown ++numLeaves; 2433552f7358SJed Brown } else if (!supportSize && !coneSize) { 2434552f7358SJed Brown /* Isolated points */ 2435aa50250dSMatthew G. Knepley ierr = DMLabelSetValue(label, p, 0);CHKERRQ(ierr); 2436552f7358SJed Brown } 2437552f7358SJed Brown } 2438552f7358SJed Brown if (numRoots + numLeaves == (pEnd - pStart)) { 2439552f7358SJed Brown for (p = pStart; p < pEnd; ++p) { 2440552f7358SJed Brown PetscInt coneSize, supportSize; 2441552f7358SJed Brown 2442552f7358SJed Brown ierr = DMPlexGetConeSize(dm, p, &coneSize);CHKERRQ(ierr); 2443552f7358SJed Brown ierr = DMPlexGetSupportSize(dm, p, &supportSize);CHKERRQ(ierr); 2444552f7358SJed Brown if (!supportSize && coneSize) { 2445aa50250dSMatthew G. Knepley ierr = DMLabelSetValue(label, p, 1);CHKERRQ(ierr); 2446552f7358SJed Brown } 2447552f7358SJed Brown } 2448552f7358SJed Brown } else { 244974ef644bSMatthew G. Knepley IS pointIS; 245074ef644bSMatthew G. Knepley PetscInt numPoints = 0, level = 0; 2451552f7358SJed Brown 245274ef644bSMatthew G. Knepley ierr = DMLabelGetStratumIS(label, level, &pointIS);CHKERRQ(ierr); 245374ef644bSMatthew G. Knepley if (pointIS) {ierr = ISGetLocalSize(pointIS, &numPoints);CHKERRQ(ierr);} 245474ef644bSMatthew G. Knepley while (numPoints) { 245574ef644bSMatthew G. Knepley const PetscInt *points; 245674ef644bSMatthew G. Knepley const PetscInt newLevel = level+1; 245774ef644bSMatthew G. Knepley 245874ef644bSMatthew G. Knepley ierr = ISGetIndices(pointIS, &points);CHKERRQ(ierr); 245974ef644bSMatthew G. Knepley for (p = 0; p < numPoints; ++p) { 246074ef644bSMatthew G. Knepley const PetscInt point = points[p]; 246174ef644bSMatthew G. Knepley const PetscInt *support; 246274ef644bSMatthew G. Knepley PetscInt supportSize, s; 246374ef644bSMatthew G. Knepley 246474ef644bSMatthew G. Knepley ierr = DMPlexGetSupportSize(dm, point, &supportSize);CHKERRQ(ierr); 246574ef644bSMatthew G. Knepley ierr = DMPlexGetSupport(dm, point, &support);CHKERRQ(ierr); 246674ef644bSMatthew G. Knepley for (s = 0; s < supportSize; ++s) { 246774ef644bSMatthew G. Knepley ierr = DMLabelSetValue(label, support[s], newLevel);CHKERRQ(ierr); 2468552f7358SJed Brown } 2469552f7358SJed Brown } 24705edfc765SMatthew G. Knepley ierr = ISRestoreIndices(pointIS, &points);CHKERRQ(ierr); 247174ef644bSMatthew G. Knepley ++level; 247274ef644bSMatthew G. Knepley ierr = ISDestroy(&pointIS);CHKERRQ(ierr); 247374ef644bSMatthew G. Knepley ierr = DMLabelGetStratumIS(label, level, &pointIS);CHKERRQ(ierr); 247474ef644bSMatthew G. Knepley if (pointIS) {ierr = ISGetLocalSize(pointIS, &numPoints);CHKERRQ(ierr);} 247574ef644bSMatthew G. Knepley else {numPoints = 0;} 247674ef644bSMatthew G. Knepley } 247774ef644bSMatthew G. Knepley ierr = ISDestroy(&pointIS);CHKERRQ(ierr); 247874ef644bSMatthew G. Knepley } 2479bf4602e4SToby Isaac { /* just in case there is an empty process */ 2480bf4602e4SToby Isaac PetscInt numValues, maxValues = 0, v; 2481bf4602e4SToby Isaac 2482bf4602e4SToby Isaac ierr = DMLabelGetNumValues(label,&numValues);CHKERRQ(ierr); 24834de306b1SToby Isaac for (v = 0; v < numValues; v++) { 24844de306b1SToby Isaac IS pointIS; 24854de306b1SToby Isaac 24864de306b1SToby Isaac ierr = DMLabelGetStratumIS(label, v, &pointIS);CHKERRQ(ierr); 24874de306b1SToby Isaac if (pointIS) { 24884de306b1SToby Isaac PetscInt min, max, numPoints; 24894de306b1SToby Isaac PetscInt start; 24904de306b1SToby Isaac PetscBool contig; 24914de306b1SToby Isaac 24924de306b1SToby Isaac ierr = ISGetLocalSize(pointIS, &numPoints);CHKERRQ(ierr); 24934de306b1SToby Isaac ierr = ISGetMinMax(pointIS, &min, &max);CHKERRQ(ierr); 24944de306b1SToby Isaac ierr = ISContiguousLocal(pointIS,min,max+1,&start,&contig);CHKERRQ(ierr); 24954de306b1SToby Isaac if (start == 0 && contig) { 24964de306b1SToby Isaac ierr = ISDestroy(&pointIS);CHKERRQ(ierr); 24974de306b1SToby Isaac ierr = ISCreateStride(PETSC_COMM_SELF,numPoints,min,1,&pointIS);CHKERRQ(ierr); 24984de306b1SToby Isaac ierr = DMLabelSetStratumIS(label, v, pointIS);CHKERRQ(ierr); 24994de306b1SToby Isaac } 25004de306b1SToby Isaac } 25014de306b1SToby Isaac ierr = ISDestroy(&pointIS);CHKERRQ(ierr); 25024de306b1SToby Isaac } 25036d1e82d3SBarry Smith ierr = MPI_Allreduce(&numValues,&maxValues,1,MPIU_INT,MPI_MAX,PetscObjectComm((PetscObject)dm));CHKERRQ(ierr); 2504bf4602e4SToby Isaac for (v = numValues; v < maxValues; v++) { 2505bf4602e4SToby Isaac DMLabelAddStratum(label,v);CHKERRQ(ierr); 2506bf4602e4SToby Isaac } 2507bf4602e4SToby Isaac } 2508df0420ecSMatthew G. Knepley ierr = DMLabelGetState(label, &mesh->depthState);CHKERRQ(ierr); 25097d5acc75SStefano Zampini 25107d5acc75SStefano Zampini ierr = DMPlexGetHybridBounds(dm, &cMax, &fMax, &eMax, &vMax);CHKERRQ(ierr); 25117d5acc75SStefano Zampini if (cMax >= 0 || fMax >= 0 || eMax >= 0 || vMax >= 0) { 25127d5acc75SStefano Zampini DMLabel dimLabel; 25137d5acc75SStefano Zampini PetscInt dim; 25147d5acc75SStefano Zampini 25157d5acc75SStefano Zampini ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 25167d5acc75SStefano Zampini ierr = DMGetLabel(dm, "dim", &dimLabel);CHKERRQ(ierr); 25177d5acc75SStefano Zampini if (!dimLabel) { 25187d5acc75SStefano Zampini ierr = DMCreateLabel(dm, "dim");CHKERRQ(ierr); 25197d5acc75SStefano Zampini ierr = DMGetLabel(dm, "dim", &dimLabel);CHKERRQ(ierr); 25207d5acc75SStefano Zampini } 25217d5acc75SStefano Zampini if (cMax >= 0) {ierr = DMPlexCreateDimStratum(dm, label, dimLabel, dim, cMax);CHKERRQ(ierr);} 25227d5acc75SStefano Zampini if (fMax >= 0) {ierr = DMPlexCreateDimStratum(dm, label, dimLabel, dim - 1, fMax);CHKERRQ(ierr);} 25237d5acc75SStefano Zampini if (eMax >= 0) {ierr = DMPlexCreateDimStratum(dm, label, dimLabel, 1, eMax);CHKERRQ(ierr);} 25247d5acc75SStefano Zampini if (vMax >= 0) {ierr = DMPlexCreateDimStratum(dm, label, dimLabel, 0, vMax);CHKERRQ(ierr);} 25257d5acc75SStefano Zampini } 2526552f7358SJed Brown ierr = PetscLogEventEnd(DMPLEX_Stratify,dm,0,0,0);CHKERRQ(ierr); 2527552f7358SJed Brown PetscFunctionReturn(0); 2528552f7358SJed Brown } 2529552f7358SJed Brown 2530552f7358SJed Brown /*@C 2531552f7358SJed Brown DMPlexGetJoin - Get an array for the join of the set of points 2532552f7358SJed Brown 2533552f7358SJed Brown Not Collective 2534552f7358SJed Brown 2535552f7358SJed Brown Input Parameters: 2536552f7358SJed Brown + dm - The DMPlex object 2537552f7358SJed Brown . numPoints - The number of input points for the join 2538552f7358SJed Brown - points - The input points 2539552f7358SJed Brown 2540552f7358SJed Brown Output Parameters: 2541552f7358SJed Brown + numCoveredPoints - The number of points in the join 2542552f7358SJed Brown - coveredPoints - The points in the join 2543552f7358SJed Brown 2544552f7358SJed Brown Level: intermediate 2545552f7358SJed Brown 2546552f7358SJed Brown Note: Currently, this is restricted to a single level join 2547552f7358SJed Brown 25483813dfbdSMatthew G Knepley Fortran Notes: 25493813dfbdSMatthew G Knepley Since it returns an array, this routine is only available in Fortran 90, and you must 25503813dfbdSMatthew G Knepley include petsc.h90 in your code. 25513813dfbdSMatthew G Knepley 25523813dfbdSMatthew G Knepley The numCoveredPoints argument is not present in the Fortran 90 binding since it is internal to the array. 25533813dfbdSMatthew G Knepley 2554552f7358SJed Brown .keywords: mesh 2555552f7358SJed Brown .seealso: DMPlexRestoreJoin(), DMPlexGetMeet() 2556552f7358SJed Brown @*/ 2557552f7358SJed Brown PetscErrorCode DMPlexGetJoin(DM dm, PetscInt numPoints, const PetscInt points[], PetscInt *numCoveredPoints, const PetscInt **coveredPoints) 2558552f7358SJed Brown { 2559552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 2560552f7358SJed Brown PetscInt *join[2]; 2561552f7358SJed Brown PetscInt joinSize, i = 0; 2562552f7358SJed Brown PetscInt dof, off, p, c, m; 2563552f7358SJed Brown PetscErrorCode ierr; 2564552f7358SJed Brown 2565552f7358SJed Brown PetscFunctionBegin; 2566552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 2567552f7358SJed Brown PetscValidPointer(points, 2); 2568552f7358SJed Brown PetscValidPointer(numCoveredPoints, 3); 2569552f7358SJed Brown PetscValidPointer(coveredPoints, 4); 257069291d52SBarry Smith ierr = DMGetWorkArray(dm, mesh->maxSupportSize, MPIU_INT, &join[0]);CHKERRQ(ierr); 257169291d52SBarry Smith ierr = DMGetWorkArray(dm, mesh->maxSupportSize, MPIU_INT, &join[1]);CHKERRQ(ierr); 2572552f7358SJed Brown /* Copy in support of first point */ 2573552f7358SJed Brown ierr = PetscSectionGetDof(mesh->supportSection, points[0], &dof);CHKERRQ(ierr); 2574552f7358SJed Brown ierr = PetscSectionGetOffset(mesh->supportSection, points[0], &off);CHKERRQ(ierr); 2575552f7358SJed Brown for (joinSize = 0; joinSize < dof; ++joinSize) { 2576552f7358SJed Brown join[i][joinSize] = mesh->supports[off+joinSize]; 2577552f7358SJed Brown } 2578552f7358SJed Brown /* Check each successive support */ 2579552f7358SJed Brown for (p = 1; p < numPoints; ++p) { 2580552f7358SJed Brown PetscInt newJoinSize = 0; 2581552f7358SJed Brown 2582552f7358SJed Brown ierr = PetscSectionGetDof(mesh->supportSection, points[p], &dof);CHKERRQ(ierr); 2583552f7358SJed Brown ierr = PetscSectionGetOffset(mesh->supportSection, points[p], &off);CHKERRQ(ierr); 2584552f7358SJed Brown for (c = 0; c < dof; ++c) { 2585552f7358SJed Brown const PetscInt point = mesh->supports[off+c]; 2586552f7358SJed Brown 2587552f7358SJed Brown for (m = 0; m < joinSize; ++m) { 2588552f7358SJed Brown if (point == join[i][m]) { 2589552f7358SJed Brown join[1-i][newJoinSize++] = point; 2590552f7358SJed Brown break; 2591552f7358SJed Brown } 2592552f7358SJed Brown } 2593552f7358SJed Brown } 2594552f7358SJed Brown joinSize = newJoinSize; 2595552f7358SJed Brown i = 1-i; 2596552f7358SJed Brown } 2597552f7358SJed Brown *numCoveredPoints = joinSize; 2598552f7358SJed Brown *coveredPoints = join[i]; 259969291d52SBarry Smith ierr = DMRestoreWorkArray(dm, mesh->maxSupportSize, MPIU_INT, &join[1-i]);CHKERRQ(ierr); 2600552f7358SJed Brown PetscFunctionReturn(0); 2601552f7358SJed Brown } 2602552f7358SJed Brown 2603552f7358SJed Brown /*@C 2604552f7358SJed Brown DMPlexRestoreJoin - Restore an array for the join of the set of points 2605552f7358SJed Brown 2606552f7358SJed Brown Not Collective 2607552f7358SJed Brown 2608552f7358SJed Brown Input Parameters: 2609552f7358SJed Brown + dm - The DMPlex object 2610552f7358SJed Brown . numPoints - The number of input points for the join 2611552f7358SJed Brown - points - The input points 2612552f7358SJed Brown 2613552f7358SJed Brown Output Parameters: 2614552f7358SJed Brown + numCoveredPoints - The number of points in the join 2615552f7358SJed Brown - coveredPoints - The points in the join 2616552f7358SJed Brown 26173813dfbdSMatthew G Knepley Fortran Notes: 26183813dfbdSMatthew G Knepley Since it returns an array, this routine is only available in Fortran 90, and you must 26193813dfbdSMatthew G Knepley include petsc.h90 in your code. 26203813dfbdSMatthew G Knepley 26213813dfbdSMatthew G Knepley The numCoveredPoints argument is not present in the Fortran 90 binding since it is internal to the array. 26223813dfbdSMatthew G Knepley 2623552f7358SJed Brown Level: intermediate 2624552f7358SJed Brown 2625552f7358SJed Brown .keywords: mesh 2626552f7358SJed Brown .seealso: DMPlexGetJoin(), DMPlexGetFullJoin(), DMPlexGetMeet() 2627552f7358SJed Brown @*/ 2628552f7358SJed Brown PetscErrorCode DMPlexRestoreJoin(DM dm, PetscInt numPoints, const PetscInt points[], PetscInt *numCoveredPoints, const PetscInt **coveredPoints) 2629552f7358SJed Brown { 2630552f7358SJed Brown PetscErrorCode ierr; 2631552f7358SJed Brown 2632552f7358SJed Brown PetscFunctionBegin; 2633552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 2634d7902bd2SMatthew G. Knepley if (points) PetscValidIntPointer(points,3); 2635d7902bd2SMatthew G. Knepley if (numCoveredPoints) PetscValidIntPointer(numCoveredPoints,4); 2636d7902bd2SMatthew G. Knepley PetscValidPointer(coveredPoints, 5); 263769291d52SBarry Smith ierr = DMRestoreWorkArray(dm, 0, MPIU_INT, (void*) coveredPoints);CHKERRQ(ierr); 2638d7902bd2SMatthew G. Knepley if (numCoveredPoints) *numCoveredPoints = 0; 2639552f7358SJed Brown PetscFunctionReturn(0); 2640552f7358SJed Brown } 2641552f7358SJed Brown 2642552f7358SJed Brown /*@C 2643552f7358SJed Brown DMPlexGetFullJoin - Get an array for the join of the set of points 2644552f7358SJed Brown 2645552f7358SJed Brown Not Collective 2646552f7358SJed Brown 2647552f7358SJed Brown Input Parameters: 2648552f7358SJed Brown + dm - The DMPlex object 2649552f7358SJed Brown . numPoints - The number of input points for the join 2650552f7358SJed Brown - points - The input points 2651552f7358SJed Brown 2652552f7358SJed Brown Output Parameters: 2653552f7358SJed Brown + numCoveredPoints - The number of points in the join 2654552f7358SJed Brown - coveredPoints - The points in the join 2655552f7358SJed Brown 26563813dfbdSMatthew G Knepley Fortran Notes: 26573813dfbdSMatthew G Knepley Since it returns an array, this routine is only available in Fortran 90, and you must 26583813dfbdSMatthew G Knepley include petsc.h90 in your code. 26593813dfbdSMatthew G Knepley 26603813dfbdSMatthew G Knepley The numCoveredPoints argument is not present in the Fortran 90 binding since it is internal to the array. 26613813dfbdSMatthew G Knepley 2662552f7358SJed Brown Level: intermediate 2663552f7358SJed Brown 2664552f7358SJed Brown .keywords: mesh 2665552f7358SJed Brown .seealso: DMPlexGetJoin(), DMPlexRestoreJoin(), DMPlexGetMeet() 2666552f7358SJed Brown @*/ 2667552f7358SJed Brown PetscErrorCode DMPlexGetFullJoin(DM dm, PetscInt numPoints, const PetscInt points[], PetscInt *numCoveredPoints, const PetscInt **coveredPoints) 2668552f7358SJed Brown { 2669552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 2670552f7358SJed Brown PetscInt *offsets, **closures; 2671552f7358SJed Brown PetscInt *join[2]; 2672552f7358SJed Brown PetscInt depth = 0, maxSize, joinSize = 0, i = 0; 267324c766afSToby Isaac PetscInt p, d, c, m, ms; 2674552f7358SJed Brown PetscErrorCode ierr; 2675552f7358SJed Brown 2676552f7358SJed Brown PetscFunctionBegin; 2677552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 2678552f7358SJed Brown PetscValidPointer(points, 2); 2679552f7358SJed Brown PetscValidPointer(numCoveredPoints, 3); 2680552f7358SJed Brown PetscValidPointer(coveredPoints, 4); 2681552f7358SJed Brown 2682552f7358SJed Brown ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 26831795a4d1SJed Brown ierr = PetscCalloc1(numPoints, &closures);CHKERRQ(ierr); 268469291d52SBarry Smith ierr = DMGetWorkArray(dm, numPoints*(depth+2), MPIU_INT, &offsets);CHKERRQ(ierr); 268524c766afSToby Isaac ms = mesh->maxSupportSize; 268624c766afSToby Isaac maxSize = (ms > 1) ? ((PetscPowInt(ms,depth+1)-1)/(ms-1)) : depth + 1; 268769291d52SBarry Smith ierr = DMGetWorkArray(dm, maxSize, MPIU_INT, &join[0]);CHKERRQ(ierr); 268869291d52SBarry Smith ierr = DMGetWorkArray(dm, maxSize, MPIU_INT, &join[1]);CHKERRQ(ierr); 2689552f7358SJed Brown 2690552f7358SJed Brown for (p = 0; p < numPoints; ++p) { 2691552f7358SJed Brown PetscInt closureSize; 2692552f7358SJed Brown 2693552f7358SJed Brown ierr = DMPlexGetTransitiveClosure(dm, points[p], PETSC_FALSE, &closureSize, &closures[p]);CHKERRQ(ierr); 26940d644c17SKarl Rupp 2695552f7358SJed Brown offsets[p*(depth+2)+0] = 0; 2696552f7358SJed Brown for (d = 0; d < depth+1; ++d) { 2697552f7358SJed Brown PetscInt pStart, pEnd, i; 2698552f7358SJed Brown 2699552f7358SJed Brown ierr = DMPlexGetDepthStratum(dm, d, &pStart, &pEnd);CHKERRQ(ierr); 2700552f7358SJed Brown for (i = offsets[p*(depth+2)+d]; i < closureSize; ++i) { 2701552f7358SJed Brown if ((pStart > closures[p][i*2]) || (pEnd <= closures[p][i*2])) { 2702552f7358SJed Brown offsets[p*(depth+2)+d+1] = i; 2703552f7358SJed Brown break; 2704552f7358SJed Brown } 2705552f7358SJed Brown } 2706552f7358SJed Brown if (i == closureSize) offsets[p*(depth+2)+d+1] = i; 2707552f7358SJed Brown } 270882f516ccSBarry Smith if (offsets[p*(depth+2)+depth+1] != closureSize) SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Total size of closure %D should be %D", offsets[p*(depth+2)+depth+1], closureSize); 2709552f7358SJed Brown } 2710552f7358SJed Brown for (d = 0; d < depth+1; ++d) { 2711552f7358SJed Brown PetscInt dof; 2712552f7358SJed Brown 2713552f7358SJed Brown /* Copy in support of first point */ 2714552f7358SJed Brown dof = offsets[d+1] - offsets[d]; 2715552f7358SJed Brown for (joinSize = 0; joinSize < dof; ++joinSize) { 2716552f7358SJed Brown join[i][joinSize] = closures[0][(offsets[d]+joinSize)*2]; 2717552f7358SJed Brown } 2718552f7358SJed Brown /* Check each successive cone */ 2719552f7358SJed Brown for (p = 1; p < numPoints && joinSize; ++p) { 2720552f7358SJed Brown PetscInt newJoinSize = 0; 2721552f7358SJed Brown 2722552f7358SJed Brown dof = offsets[p*(depth+2)+d+1] - offsets[p*(depth+2)+d]; 2723552f7358SJed Brown for (c = 0; c < dof; ++c) { 2724552f7358SJed Brown const PetscInt point = closures[p][(offsets[p*(depth+2)+d]+c)*2]; 2725552f7358SJed Brown 2726552f7358SJed Brown for (m = 0; m < joinSize; ++m) { 2727552f7358SJed Brown if (point == join[i][m]) { 2728552f7358SJed Brown join[1-i][newJoinSize++] = point; 2729552f7358SJed Brown break; 2730552f7358SJed Brown } 2731552f7358SJed Brown } 2732552f7358SJed Brown } 2733552f7358SJed Brown joinSize = newJoinSize; 2734552f7358SJed Brown i = 1-i; 2735552f7358SJed Brown } 2736552f7358SJed Brown if (joinSize) break; 2737552f7358SJed Brown } 2738552f7358SJed Brown *numCoveredPoints = joinSize; 2739552f7358SJed Brown *coveredPoints = join[i]; 2740552f7358SJed Brown for (p = 0; p < numPoints; ++p) { 27410298fd71SBarry Smith ierr = DMPlexRestoreTransitiveClosure(dm, points[p], PETSC_FALSE, NULL, &closures[p]);CHKERRQ(ierr); 2742552f7358SJed Brown } 2743552f7358SJed Brown ierr = PetscFree(closures);CHKERRQ(ierr); 274469291d52SBarry Smith ierr = DMRestoreWorkArray(dm, numPoints*(depth+2), MPIU_INT, &offsets);CHKERRQ(ierr); 274569291d52SBarry Smith ierr = DMRestoreWorkArray(dm, mesh->maxSupportSize, MPIU_INT, &join[1-i]);CHKERRQ(ierr); 2746552f7358SJed Brown PetscFunctionReturn(0); 2747552f7358SJed Brown } 2748552f7358SJed Brown 2749552f7358SJed Brown /*@C 2750552f7358SJed Brown DMPlexGetMeet - Get an array for the meet of the set of points 2751552f7358SJed Brown 2752552f7358SJed Brown Not Collective 2753552f7358SJed Brown 2754552f7358SJed Brown Input Parameters: 2755552f7358SJed Brown + dm - The DMPlex object 2756552f7358SJed Brown . numPoints - The number of input points for the meet 2757552f7358SJed Brown - points - The input points 2758552f7358SJed Brown 2759552f7358SJed Brown Output Parameters: 2760552f7358SJed Brown + numCoveredPoints - The number of points in the meet 2761552f7358SJed Brown - coveredPoints - The points in the meet 2762552f7358SJed Brown 2763552f7358SJed Brown Level: intermediate 2764552f7358SJed Brown 2765552f7358SJed Brown Note: Currently, this is restricted to a single level meet 2766552f7358SJed Brown 27673813dfbdSMatthew G Knepley Fortran Notes: 27683813dfbdSMatthew G Knepley Since it returns an array, this routine is only available in Fortran 90, and you must 27693813dfbdSMatthew G Knepley include petsc.h90 in your code. 27703813dfbdSMatthew G Knepley 27713813dfbdSMatthew G Knepley The numCoveredPoints argument is not present in the Fortran 90 binding since it is internal to the array. 27723813dfbdSMatthew G Knepley 2773552f7358SJed Brown .keywords: mesh 2774552f7358SJed Brown .seealso: DMPlexRestoreMeet(), DMPlexGetJoin() 2775552f7358SJed Brown @*/ 2776552f7358SJed Brown PetscErrorCode DMPlexGetMeet(DM dm, PetscInt numPoints, const PetscInt points[], PetscInt *numCoveringPoints, const PetscInt **coveringPoints) 2777552f7358SJed Brown { 2778552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 2779552f7358SJed Brown PetscInt *meet[2]; 2780552f7358SJed Brown PetscInt meetSize, i = 0; 2781552f7358SJed Brown PetscInt dof, off, p, c, m; 2782552f7358SJed Brown PetscErrorCode ierr; 2783552f7358SJed Brown 2784552f7358SJed Brown PetscFunctionBegin; 2785552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 2786552f7358SJed Brown PetscValidPointer(points, 2); 2787552f7358SJed Brown PetscValidPointer(numCoveringPoints, 3); 2788552f7358SJed Brown PetscValidPointer(coveringPoints, 4); 278969291d52SBarry Smith ierr = DMGetWorkArray(dm, mesh->maxConeSize, MPIU_INT, &meet[0]);CHKERRQ(ierr); 279069291d52SBarry Smith ierr = DMGetWorkArray(dm, mesh->maxConeSize, MPIU_INT, &meet[1]);CHKERRQ(ierr); 2791552f7358SJed Brown /* Copy in cone of first point */ 2792552f7358SJed Brown ierr = PetscSectionGetDof(mesh->coneSection, points[0], &dof);CHKERRQ(ierr); 2793552f7358SJed Brown ierr = PetscSectionGetOffset(mesh->coneSection, points[0], &off);CHKERRQ(ierr); 2794552f7358SJed Brown for (meetSize = 0; meetSize < dof; ++meetSize) { 2795552f7358SJed Brown meet[i][meetSize] = mesh->cones[off+meetSize]; 2796552f7358SJed Brown } 2797552f7358SJed Brown /* Check each successive cone */ 2798552f7358SJed Brown for (p = 1; p < numPoints; ++p) { 2799552f7358SJed Brown PetscInt newMeetSize = 0; 2800552f7358SJed Brown 2801552f7358SJed Brown ierr = PetscSectionGetDof(mesh->coneSection, points[p], &dof);CHKERRQ(ierr); 2802552f7358SJed Brown ierr = PetscSectionGetOffset(mesh->coneSection, points[p], &off);CHKERRQ(ierr); 2803552f7358SJed Brown for (c = 0; c < dof; ++c) { 2804552f7358SJed Brown const PetscInt point = mesh->cones[off+c]; 2805552f7358SJed Brown 2806552f7358SJed Brown for (m = 0; m < meetSize; ++m) { 2807552f7358SJed Brown if (point == meet[i][m]) { 2808552f7358SJed Brown meet[1-i][newMeetSize++] = point; 2809552f7358SJed Brown break; 2810552f7358SJed Brown } 2811552f7358SJed Brown } 2812552f7358SJed Brown } 2813552f7358SJed Brown meetSize = newMeetSize; 2814552f7358SJed Brown i = 1-i; 2815552f7358SJed Brown } 2816552f7358SJed Brown *numCoveringPoints = meetSize; 2817552f7358SJed Brown *coveringPoints = meet[i]; 281869291d52SBarry Smith ierr = DMRestoreWorkArray(dm, mesh->maxConeSize, MPIU_INT, &meet[1-i]);CHKERRQ(ierr); 2819552f7358SJed Brown PetscFunctionReturn(0); 2820552f7358SJed Brown } 2821552f7358SJed Brown 2822552f7358SJed Brown /*@C 2823552f7358SJed Brown DMPlexRestoreMeet - Restore an array for the meet of the set of points 2824552f7358SJed Brown 2825552f7358SJed Brown Not Collective 2826552f7358SJed Brown 2827552f7358SJed Brown Input Parameters: 2828552f7358SJed Brown + dm - The DMPlex object 2829552f7358SJed Brown . numPoints - The number of input points for the meet 2830552f7358SJed Brown - points - The input points 2831552f7358SJed Brown 2832552f7358SJed Brown Output Parameters: 2833552f7358SJed Brown + numCoveredPoints - The number of points in the meet 2834552f7358SJed Brown - coveredPoints - The points in the meet 2835552f7358SJed Brown 2836552f7358SJed Brown Level: intermediate 2837552f7358SJed Brown 28383813dfbdSMatthew G Knepley Fortran Notes: 28393813dfbdSMatthew G Knepley Since it returns an array, this routine is only available in Fortran 90, and you must 28403813dfbdSMatthew G Knepley include petsc.h90 in your code. 28413813dfbdSMatthew G Knepley 28423813dfbdSMatthew G Knepley The numCoveredPoints argument is not present in the Fortran 90 binding since it is internal to the array. 28433813dfbdSMatthew G Knepley 2844552f7358SJed Brown .keywords: mesh 2845552f7358SJed Brown .seealso: DMPlexGetMeet(), DMPlexGetFullMeet(), DMPlexGetJoin() 2846552f7358SJed Brown @*/ 2847552f7358SJed Brown PetscErrorCode DMPlexRestoreMeet(DM dm, PetscInt numPoints, const PetscInt points[], PetscInt *numCoveredPoints, const PetscInt **coveredPoints) 2848552f7358SJed Brown { 2849552f7358SJed Brown PetscErrorCode ierr; 2850552f7358SJed Brown 2851552f7358SJed Brown PetscFunctionBegin; 2852552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 2853d7902bd2SMatthew G. Knepley if (points) PetscValidIntPointer(points,3); 2854d7902bd2SMatthew G. Knepley if (numCoveredPoints) PetscValidIntPointer(numCoveredPoints,4); 2855d7902bd2SMatthew G. Knepley PetscValidPointer(coveredPoints,5); 285669291d52SBarry Smith ierr = DMRestoreWorkArray(dm, 0, MPIU_INT, (void*) coveredPoints);CHKERRQ(ierr); 2857d7902bd2SMatthew G. Knepley if (numCoveredPoints) *numCoveredPoints = 0; 2858552f7358SJed Brown PetscFunctionReturn(0); 2859552f7358SJed Brown } 2860552f7358SJed Brown 2861552f7358SJed Brown /*@C 2862552f7358SJed Brown DMPlexGetFullMeet - Get an array for the meet of the set of points 2863552f7358SJed Brown 2864552f7358SJed Brown Not Collective 2865552f7358SJed Brown 2866552f7358SJed Brown Input Parameters: 2867552f7358SJed Brown + dm - The DMPlex object 2868552f7358SJed Brown . numPoints - The number of input points for the meet 2869552f7358SJed Brown - points - The input points 2870552f7358SJed Brown 2871552f7358SJed Brown Output Parameters: 2872552f7358SJed Brown + numCoveredPoints - The number of points in the meet 2873552f7358SJed Brown - coveredPoints - The points in the meet 2874552f7358SJed Brown 2875552f7358SJed Brown Level: intermediate 2876552f7358SJed Brown 28773813dfbdSMatthew G Knepley Fortran Notes: 28783813dfbdSMatthew G Knepley Since it returns an array, this routine is only available in Fortran 90, and you must 28793813dfbdSMatthew G Knepley include petsc.h90 in your code. 28803813dfbdSMatthew G Knepley 28813813dfbdSMatthew G Knepley The numCoveredPoints argument is not present in the Fortran 90 binding since it is internal to the array. 28823813dfbdSMatthew G Knepley 2883552f7358SJed Brown .keywords: mesh 2884552f7358SJed Brown .seealso: DMPlexGetMeet(), DMPlexRestoreMeet(), DMPlexGetJoin() 2885552f7358SJed Brown @*/ 2886552f7358SJed Brown PetscErrorCode DMPlexGetFullMeet(DM dm, PetscInt numPoints, const PetscInt points[], PetscInt *numCoveredPoints, const PetscInt **coveredPoints) 2887552f7358SJed Brown { 2888552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 2889552f7358SJed Brown PetscInt *offsets, **closures; 2890552f7358SJed Brown PetscInt *meet[2]; 2891552f7358SJed Brown PetscInt height = 0, maxSize, meetSize = 0, i = 0; 289224c766afSToby Isaac PetscInt p, h, c, m, mc; 2893552f7358SJed Brown PetscErrorCode ierr; 2894552f7358SJed Brown 2895552f7358SJed Brown PetscFunctionBegin; 2896552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 2897552f7358SJed Brown PetscValidPointer(points, 2); 2898552f7358SJed Brown PetscValidPointer(numCoveredPoints, 3); 2899552f7358SJed Brown PetscValidPointer(coveredPoints, 4); 2900552f7358SJed Brown 2901552f7358SJed Brown ierr = DMPlexGetDepth(dm, &height);CHKERRQ(ierr); 2902785e854fSJed Brown ierr = PetscMalloc1(numPoints, &closures);CHKERRQ(ierr); 290369291d52SBarry Smith ierr = DMGetWorkArray(dm, numPoints*(height+2), MPIU_INT, &offsets);CHKERRQ(ierr); 290424c766afSToby Isaac mc = mesh->maxConeSize; 290524c766afSToby Isaac maxSize = (mc > 1) ? ((PetscPowInt(mc,height+1)-1)/(mc-1)) : height + 1; 290669291d52SBarry Smith ierr = DMGetWorkArray(dm, maxSize, MPIU_INT, &meet[0]);CHKERRQ(ierr); 290769291d52SBarry Smith ierr = DMGetWorkArray(dm, maxSize, MPIU_INT, &meet[1]);CHKERRQ(ierr); 2908552f7358SJed Brown 2909552f7358SJed Brown for (p = 0; p < numPoints; ++p) { 2910552f7358SJed Brown PetscInt closureSize; 2911552f7358SJed Brown 2912552f7358SJed Brown ierr = DMPlexGetTransitiveClosure(dm, points[p], PETSC_TRUE, &closureSize, &closures[p]);CHKERRQ(ierr); 29130d644c17SKarl Rupp 2914552f7358SJed Brown offsets[p*(height+2)+0] = 0; 2915552f7358SJed Brown for (h = 0; h < height+1; ++h) { 2916552f7358SJed Brown PetscInt pStart, pEnd, i; 2917552f7358SJed Brown 2918552f7358SJed Brown ierr = DMPlexGetHeightStratum(dm, h, &pStart, &pEnd);CHKERRQ(ierr); 2919552f7358SJed Brown for (i = offsets[p*(height+2)+h]; i < closureSize; ++i) { 2920552f7358SJed Brown if ((pStart > closures[p][i*2]) || (pEnd <= closures[p][i*2])) { 2921552f7358SJed Brown offsets[p*(height+2)+h+1] = i; 2922552f7358SJed Brown break; 2923552f7358SJed Brown } 2924552f7358SJed Brown } 2925552f7358SJed Brown if (i == closureSize) offsets[p*(height+2)+h+1] = i; 2926552f7358SJed Brown } 292782f516ccSBarry Smith if (offsets[p*(height+2)+height+1] != closureSize) SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Total size of closure %D should be %D", offsets[p*(height+2)+height+1], closureSize); 2928552f7358SJed Brown } 2929552f7358SJed Brown for (h = 0; h < height+1; ++h) { 2930552f7358SJed Brown PetscInt dof; 2931552f7358SJed Brown 2932552f7358SJed Brown /* Copy in cone of first point */ 2933552f7358SJed Brown dof = offsets[h+1] - offsets[h]; 2934552f7358SJed Brown for (meetSize = 0; meetSize < dof; ++meetSize) { 2935552f7358SJed Brown meet[i][meetSize] = closures[0][(offsets[h]+meetSize)*2]; 2936552f7358SJed Brown } 2937552f7358SJed Brown /* Check each successive cone */ 2938552f7358SJed Brown for (p = 1; p < numPoints && meetSize; ++p) { 2939552f7358SJed Brown PetscInt newMeetSize = 0; 2940552f7358SJed Brown 2941552f7358SJed Brown dof = offsets[p*(height+2)+h+1] - offsets[p*(height+2)+h]; 2942552f7358SJed Brown for (c = 0; c < dof; ++c) { 2943552f7358SJed Brown const PetscInt point = closures[p][(offsets[p*(height+2)+h]+c)*2]; 2944552f7358SJed Brown 2945552f7358SJed Brown for (m = 0; m < meetSize; ++m) { 2946552f7358SJed Brown if (point == meet[i][m]) { 2947552f7358SJed Brown meet[1-i][newMeetSize++] = point; 2948552f7358SJed Brown break; 2949552f7358SJed Brown } 2950552f7358SJed Brown } 2951552f7358SJed Brown } 2952552f7358SJed Brown meetSize = newMeetSize; 2953552f7358SJed Brown i = 1-i; 2954552f7358SJed Brown } 2955552f7358SJed Brown if (meetSize) break; 2956552f7358SJed Brown } 2957552f7358SJed Brown *numCoveredPoints = meetSize; 2958552f7358SJed Brown *coveredPoints = meet[i]; 2959552f7358SJed Brown for (p = 0; p < numPoints; ++p) { 29600298fd71SBarry Smith ierr = DMPlexRestoreTransitiveClosure(dm, points[p], PETSC_TRUE, NULL, &closures[p]);CHKERRQ(ierr); 2961552f7358SJed Brown } 2962552f7358SJed Brown ierr = PetscFree(closures);CHKERRQ(ierr); 296369291d52SBarry Smith ierr = DMRestoreWorkArray(dm, numPoints*(height+2), MPIU_INT, &offsets);CHKERRQ(ierr); 296469291d52SBarry Smith ierr = DMRestoreWorkArray(dm, mesh->maxConeSize, MPIU_INT, &meet[1-i]);CHKERRQ(ierr); 2965552f7358SJed Brown PetscFunctionReturn(0); 2966552f7358SJed Brown } 2967552f7358SJed Brown 29684e3744c5SMatthew G. Knepley /*@C 29694e3744c5SMatthew G. Knepley DMPlexEqual - Determine if two DMs have the same topology 29704e3744c5SMatthew G. Knepley 29714e3744c5SMatthew G. Knepley Not Collective 29724e3744c5SMatthew G. Knepley 29734e3744c5SMatthew G. Knepley Input Parameters: 29744e3744c5SMatthew G. Knepley + dmA - A DMPlex object 29754e3744c5SMatthew G. Knepley - dmB - A DMPlex object 29764e3744c5SMatthew G. Knepley 29774e3744c5SMatthew G. Knepley Output Parameters: 29784e3744c5SMatthew G. Knepley . equal - PETSC_TRUE if the topologies are identical 29794e3744c5SMatthew G. Knepley 29804e3744c5SMatthew G. Knepley Level: intermediate 29814e3744c5SMatthew G. Knepley 29824e3744c5SMatthew G. Knepley Notes: 29834e3744c5SMatthew G. Knepley We are not solving graph isomorphism, so we do not permutation. 29844e3744c5SMatthew G. Knepley 29854e3744c5SMatthew G. Knepley .keywords: mesh 29864e3744c5SMatthew G. Knepley .seealso: DMPlexGetCone() 29874e3744c5SMatthew G. Knepley @*/ 29884e3744c5SMatthew G. Knepley PetscErrorCode DMPlexEqual(DM dmA, DM dmB, PetscBool *equal) 29894e3744c5SMatthew G. Knepley { 29904e3744c5SMatthew G. Knepley PetscInt depth, depthB, pStart, pEnd, pStartB, pEndB, p; 29914e3744c5SMatthew G. Knepley PetscErrorCode ierr; 29924e3744c5SMatthew G. Knepley 29934e3744c5SMatthew G. Knepley PetscFunctionBegin; 29944e3744c5SMatthew G. Knepley PetscValidHeaderSpecific(dmA, DM_CLASSID, 1); 29954e3744c5SMatthew G. Knepley PetscValidHeaderSpecific(dmB, DM_CLASSID, 2); 29964e3744c5SMatthew G. Knepley PetscValidPointer(equal, 3); 29974e3744c5SMatthew G. Knepley 29984e3744c5SMatthew G. Knepley *equal = PETSC_FALSE; 29994e3744c5SMatthew G. Knepley ierr = DMPlexGetDepth(dmA, &depth);CHKERRQ(ierr); 30004e3744c5SMatthew G. Knepley ierr = DMPlexGetDepth(dmB, &depthB);CHKERRQ(ierr); 30014e3744c5SMatthew G. Knepley if (depth != depthB) PetscFunctionReturn(0); 30024e3744c5SMatthew G. Knepley ierr = DMPlexGetChart(dmA, &pStart, &pEnd);CHKERRQ(ierr); 30034e3744c5SMatthew G. Knepley ierr = DMPlexGetChart(dmB, &pStartB, &pEndB);CHKERRQ(ierr); 30044e3744c5SMatthew G. Knepley if ((pStart != pStartB) || (pEnd != pEndB)) PetscFunctionReturn(0); 30054e3744c5SMatthew G. Knepley for (p = pStart; p < pEnd; ++p) { 30064e3744c5SMatthew G. Knepley const PetscInt *cone, *coneB, *ornt, *orntB, *support, *supportB; 30074e3744c5SMatthew G. Knepley PetscInt coneSize, coneSizeB, c, supportSize, supportSizeB, s; 30084e3744c5SMatthew G. Knepley 30094e3744c5SMatthew G. Knepley ierr = DMPlexGetConeSize(dmA, p, &coneSize);CHKERRQ(ierr); 30104e3744c5SMatthew G. Knepley ierr = DMPlexGetCone(dmA, p, &cone);CHKERRQ(ierr); 30114e3744c5SMatthew G. Knepley ierr = DMPlexGetConeOrientation(dmA, p, &ornt);CHKERRQ(ierr); 30124e3744c5SMatthew G. Knepley ierr = DMPlexGetConeSize(dmB, p, &coneSizeB);CHKERRQ(ierr); 30134e3744c5SMatthew G. Knepley ierr = DMPlexGetCone(dmB, p, &coneB);CHKERRQ(ierr); 30144e3744c5SMatthew G. Knepley ierr = DMPlexGetConeOrientation(dmB, p, &orntB);CHKERRQ(ierr); 30154e3744c5SMatthew G. Knepley if (coneSize != coneSizeB) PetscFunctionReturn(0); 30164e3744c5SMatthew G. Knepley for (c = 0; c < coneSize; ++c) { 30174e3744c5SMatthew G. Knepley if (cone[c] != coneB[c]) PetscFunctionReturn(0); 30184e3744c5SMatthew G. Knepley if (ornt[c] != orntB[c]) PetscFunctionReturn(0); 30194e3744c5SMatthew G. Knepley } 30204e3744c5SMatthew G. Knepley ierr = DMPlexGetSupportSize(dmA, p, &supportSize);CHKERRQ(ierr); 30214e3744c5SMatthew G. Knepley ierr = DMPlexGetSupport(dmA, p, &support);CHKERRQ(ierr); 30224e3744c5SMatthew G. Knepley ierr = DMPlexGetSupportSize(dmB, p, &supportSizeB);CHKERRQ(ierr); 30234e3744c5SMatthew G. Knepley ierr = DMPlexGetSupport(dmB, p, &supportB);CHKERRQ(ierr); 30244e3744c5SMatthew G. Knepley if (supportSize != supportSizeB) PetscFunctionReturn(0); 30254e3744c5SMatthew G. Knepley for (s = 0; s < supportSize; ++s) { 30264e3744c5SMatthew G. Knepley if (support[s] != supportB[s]) PetscFunctionReturn(0); 30274e3744c5SMatthew G. Knepley } 30284e3744c5SMatthew G. Knepley } 30294e3744c5SMatthew G. Knepley *equal = PETSC_TRUE; 30304e3744c5SMatthew G. Knepley PetscFunctionReturn(0); 30314e3744c5SMatthew G. Knepley } 30324e3744c5SMatthew G. Knepley 30337cd05799SMatthew G. Knepley /*@C 30347cd05799SMatthew G. Knepley DMPlexGetNumFaceVertices - Returns the number of vertices on a face 30357cd05799SMatthew G. Knepley 30367cd05799SMatthew G. Knepley Not Collective 30377cd05799SMatthew G. Knepley 30387cd05799SMatthew G. Knepley Input Parameters: 30397cd05799SMatthew G. Knepley + dm - The DMPlex 30407cd05799SMatthew G. Knepley . cellDim - The cell dimension 30417cd05799SMatthew G. Knepley - numCorners - The number of vertices on a cell 30427cd05799SMatthew G. Knepley 30437cd05799SMatthew G. Knepley Output Parameters: 30447cd05799SMatthew G. Knepley . numFaceVertices - The number of vertices on a face 30457cd05799SMatthew G. Knepley 30467cd05799SMatthew G. Knepley Level: developer 30477cd05799SMatthew G. Knepley 30487cd05799SMatthew G. Knepley Notes: 30497cd05799SMatthew G. Knepley Of course this can only work for a restricted set of symmetric shapes 30507cd05799SMatthew G. Knepley 30517cd05799SMatthew G. Knepley .seealso: DMPlexGetCone() 30527cd05799SMatthew G. Knepley @*/ 305318ad9376SMatthew G. Knepley PetscErrorCode DMPlexGetNumFaceVertices(DM dm, PetscInt cellDim, PetscInt numCorners, PetscInt *numFaceVertices) 3054a6dfd86eSKarl Rupp { 305582f516ccSBarry Smith MPI_Comm comm; 3056552f7358SJed Brown PetscErrorCode ierr; 3057552f7358SJed Brown 3058552f7358SJed Brown PetscFunctionBegin; 305982f516ccSBarry Smith ierr = PetscObjectGetComm((PetscObject)dm,&comm);CHKERRQ(ierr); 3060552f7358SJed Brown PetscValidPointer(numFaceVertices,3); 3061552f7358SJed Brown switch (cellDim) { 3062552f7358SJed Brown case 0: 3063552f7358SJed Brown *numFaceVertices = 0; 3064552f7358SJed Brown break; 3065552f7358SJed Brown case 1: 3066552f7358SJed Brown *numFaceVertices = 1; 3067552f7358SJed Brown break; 3068552f7358SJed Brown case 2: 3069552f7358SJed Brown switch (numCorners) { 307019436ca2SJed Brown case 3: /* triangle */ 307119436ca2SJed Brown *numFaceVertices = 2; /* Edge has 2 vertices */ 3072552f7358SJed Brown break; 307319436ca2SJed Brown case 4: /* quadrilateral */ 307419436ca2SJed Brown *numFaceVertices = 2; /* Edge has 2 vertices */ 3075552f7358SJed Brown break; 307619436ca2SJed Brown case 6: /* quadratic triangle, tri and quad cohesive Lagrange cells */ 307719436ca2SJed Brown *numFaceVertices = 3; /* Edge has 3 vertices */ 3078552f7358SJed Brown break; 307919436ca2SJed Brown case 9: /* quadratic quadrilateral, quadratic quad cohesive Lagrange cells */ 308019436ca2SJed Brown *numFaceVertices = 3; /* Edge has 3 vertices */ 3081552f7358SJed Brown break; 3082552f7358SJed Brown default: 3083f347f43bSBarry Smith SETERRQ2(comm, PETSC_ERR_ARG_OUTOFRANGE, "Invalid number of face corners %D for dimension %D", numCorners, cellDim); 3084552f7358SJed Brown } 3085552f7358SJed Brown break; 3086552f7358SJed Brown case 3: 3087552f7358SJed Brown switch (numCorners) { 308819436ca2SJed Brown case 4: /* tetradehdron */ 308919436ca2SJed Brown *numFaceVertices = 3; /* Face has 3 vertices */ 3090552f7358SJed Brown break; 309119436ca2SJed Brown case 6: /* tet cohesive cells */ 309219436ca2SJed Brown *numFaceVertices = 4; /* Face has 4 vertices */ 3093552f7358SJed Brown break; 309419436ca2SJed Brown case 8: /* hexahedron */ 309519436ca2SJed Brown *numFaceVertices = 4; /* Face has 4 vertices */ 3096552f7358SJed Brown break; 309719436ca2SJed Brown case 9: /* tet cohesive Lagrange cells */ 309819436ca2SJed Brown *numFaceVertices = 6; /* Face has 6 vertices */ 3099552f7358SJed Brown break; 310019436ca2SJed Brown case 10: /* quadratic tetrahedron */ 310119436ca2SJed Brown *numFaceVertices = 6; /* Face has 6 vertices */ 3102552f7358SJed Brown break; 310319436ca2SJed Brown case 12: /* hex cohesive Lagrange cells */ 310419436ca2SJed Brown *numFaceVertices = 6; /* Face has 6 vertices */ 3105552f7358SJed Brown break; 310619436ca2SJed Brown case 18: /* quadratic tet cohesive Lagrange cells */ 310719436ca2SJed Brown *numFaceVertices = 6; /* Face has 6 vertices */ 3108552f7358SJed Brown break; 310919436ca2SJed Brown case 27: /* quadratic hexahedron, quadratic hex cohesive Lagrange cells */ 311019436ca2SJed Brown *numFaceVertices = 9; /* Face has 9 vertices */ 3111552f7358SJed Brown break; 3112552f7358SJed Brown default: 3113f347f43bSBarry Smith SETERRQ2(comm, PETSC_ERR_ARG_OUTOFRANGE, "Invalid number of face corners %D for dimension %D", numCorners, cellDim); 3114552f7358SJed Brown } 3115552f7358SJed Brown break; 3116552f7358SJed Brown default: 3117f347f43bSBarry Smith SETERRQ1(comm, PETSC_ERR_ARG_OUTOFRANGE, "Invalid cell dimension %D", cellDim); 3118552f7358SJed Brown } 3119552f7358SJed Brown PetscFunctionReturn(0); 3120552f7358SJed Brown } 3121552f7358SJed Brown 3122552f7358SJed Brown /*@ 3123aa50250dSMatthew G. Knepley DMPlexGetDepthLabel - Get the DMLabel recording the depth of each point 3124552f7358SJed Brown 3125552f7358SJed Brown Not Collective 3126552f7358SJed Brown 3127aa50250dSMatthew G. Knepley Input Parameter: 3128552f7358SJed Brown . dm - The DMPlex object 3129552f7358SJed Brown 3130aa50250dSMatthew G. Knepley Output Parameter: 3131aa50250dSMatthew G. Knepley . depthLabel - The DMLabel recording point depth 3132552f7358SJed Brown 3133552f7358SJed Brown Level: developer 3134552f7358SJed Brown 3135aa50250dSMatthew G. Knepley .keywords: mesh, points 3136aa50250dSMatthew G. Knepley .seealso: DMPlexGetDepth(), DMPlexGetHeightStratum(), DMPlexGetDepthStratum() 3137aa50250dSMatthew G. Knepley @*/ 3138aa50250dSMatthew G. Knepley PetscErrorCode DMPlexGetDepthLabel(DM dm, DMLabel *depthLabel) 3139aa50250dSMatthew G. Knepley { 3140aa50250dSMatthew G. Knepley PetscErrorCode ierr; 3141aa50250dSMatthew G. Knepley 3142aa50250dSMatthew G. Knepley PetscFunctionBegin; 3143aa50250dSMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3144aa50250dSMatthew G. Knepley PetscValidPointer(depthLabel, 2); 3145c58f1c22SToby Isaac if (!dm->depthLabel) {ierr = DMGetLabel(dm, "depth", &dm->depthLabel);CHKERRQ(ierr);} 3146c58f1c22SToby Isaac *depthLabel = dm->depthLabel; 3147aa50250dSMatthew G. Knepley PetscFunctionReturn(0); 3148aa50250dSMatthew G. Knepley } 3149aa50250dSMatthew G. Knepley 3150aa50250dSMatthew G. Knepley /*@ 3151aa50250dSMatthew G. Knepley DMPlexGetDepth - Get the depth of the DAG representing this mesh 3152aa50250dSMatthew G. Knepley 3153aa50250dSMatthew G. Knepley Not Collective 3154aa50250dSMatthew G. Knepley 3155aa50250dSMatthew G. Knepley Input Parameter: 3156aa50250dSMatthew G. Knepley . dm - The DMPlex object 3157aa50250dSMatthew G. Knepley 3158aa50250dSMatthew G. Knepley Output Parameter: 3159aa50250dSMatthew G. Knepley . depth - The number of strata (breadth first levels) in the DAG 3160aa50250dSMatthew G. Knepley 3161aa50250dSMatthew G. Knepley Level: developer 3162552f7358SJed Brown 3163552f7358SJed Brown .keywords: mesh, points 3164aa50250dSMatthew G. Knepley .seealso: DMPlexGetDepthLabel(), DMPlexGetHeightStratum(), DMPlexGetDepthStratum() 3165552f7358SJed Brown @*/ 3166552f7358SJed Brown PetscErrorCode DMPlexGetDepth(DM dm, PetscInt *depth) 3167552f7358SJed Brown { 3168aa50250dSMatthew G. Knepley DMLabel label; 3169aa50250dSMatthew G. Knepley PetscInt d = 0; 3170552f7358SJed Brown PetscErrorCode ierr; 3171552f7358SJed Brown 3172552f7358SJed Brown PetscFunctionBegin; 3173552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3174552f7358SJed Brown PetscValidPointer(depth, 2); 3175aa50250dSMatthew G. Knepley ierr = DMPlexGetDepthLabel(dm, &label);CHKERRQ(ierr); 3176aa50250dSMatthew G. Knepley if (label) {ierr = DMLabelGetNumValues(label, &d);CHKERRQ(ierr);} 3177552f7358SJed Brown *depth = d-1; 3178552f7358SJed Brown PetscFunctionReturn(0); 3179552f7358SJed Brown } 3180552f7358SJed Brown 3181552f7358SJed Brown /*@ 3182552f7358SJed Brown DMPlexGetDepthStratum - Get the bounds [start, end) for all points at a certain depth. 3183552f7358SJed Brown 3184552f7358SJed Brown Not Collective 3185552f7358SJed Brown 3186552f7358SJed Brown Input Parameters: 3187552f7358SJed Brown + dm - The DMPlex object 3188552f7358SJed Brown - stratumValue - The requested depth 3189552f7358SJed Brown 3190552f7358SJed Brown Output Parameters: 3191552f7358SJed Brown + start - The first point at this depth 3192552f7358SJed Brown - end - One beyond the last point at this depth 3193552f7358SJed Brown 3194552f7358SJed Brown Level: developer 3195552f7358SJed Brown 3196552f7358SJed Brown .keywords: mesh, points 3197552f7358SJed Brown .seealso: DMPlexGetHeightStratum(), DMPlexGetDepth() 3198552f7358SJed Brown @*/ 31990adebc6cSBarry Smith PetscErrorCode DMPlexGetDepthStratum(DM dm, PetscInt stratumValue, PetscInt *start, PetscInt *end) 32000adebc6cSBarry Smith { 3201aa50250dSMatthew G. Knepley DMLabel label; 320263d1a920SMatthew G. Knepley PetscInt pStart, pEnd; 3203552f7358SJed Brown PetscErrorCode ierr; 3204552f7358SJed Brown 3205552f7358SJed Brown PetscFunctionBegin; 3206552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 320763d1a920SMatthew G. Knepley if (start) {PetscValidPointer(start, 3); *start = 0;} 320863d1a920SMatthew G. Knepley if (end) {PetscValidPointer(end, 4); *end = 0;} 3209552f7358SJed Brown ierr = DMPlexGetChart(dm, &pStart, &pEnd);CHKERRQ(ierr); 32100d644c17SKarl Rupp if (pStart == pEnd) PetscFunctionReturn(0); 321163d1a920SMatthew G. Knepley if (stratumValue < 0) { 321263d1a920SMatthew G. Knepley if (start) *start = pStart; 321363d1a920SMatthew G. Knepley if (end) *end = pEnd; 321463d1a920SMatthew G. Knepley PetscFunctionReturn(0); 3215552f7358SJed Brown } 3216aa50250dSMatthew G. Knepley ierr = DMPlexGetDepthLabel(dm, &label);CHKERRQ(ierr); 321763d1a920SMatthew G. Knepley if (!label) SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "No label named depth was found"); 321863d1a920SMatthew G. Knepley ierr = DMLabelGetStratumBounds(label, stratumValue, start, end);CHKERRQ(ierr); 3219552f7358SJed Brown PetscFunctionReturn(0); 3220552f7358SJed Brown } 3221552f7358SJed Brown 3222552f7358SJed Brown /*@ 3223552f7358SJed Brown DMPlexGetHeightStratum - Get the bounds [start, end) for all points at a certain height. 3224552f7358SJed Brown 3225552f7358SJed Brown Not Collective 3226552f7358SJed Brown 3227552f7358SJed Brown Input Parameters: 3228552f7358SJed Brown + dm - The DMPlex object 3229552f7358SJed Brown - stratumValue - The requested height 3230552f7358SJed Brown 3231552f7358SJed Brown Output Parameters: 3232552f7358SJed Brown + start - The first point at this height 3233552f7358SJed Brown - end - One beyond the last point at this height 3234552f7358SJed Brown 3235552f7358SJed Brown Level: developer 3236552f7358SJed Brown 3237552f7358SJed Brown .keywords: mesh, points 3238552f7358SJed Brown .seealso: DMPlexGetDepthStratum(), DMPlexGetDepth() 3239552f7358SJed Brown @*/ 32400adebc6cSBarry Smith PetscErrorCode DMPlexGetHeightStratum(DM dm, PetscInt stratumValue, PetscInt *start, PetscInt *end) 32410adebc6cSBarry Smith { 3242aa50250dSMatthew G. Knepley DMLabel label; 324363d1a920SMatthew G. Knepley PetscInt depth, pStart, pEnd; 3244552f7358SJed Brown PetscErrorCode ierr; 3245552f7358SJed Brown 3246552f7358SJed Brown PetscFunctionBegin; 3247552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 324863d1a920SMatthew G. Knepley if (start) {PetscValidPointer(start, 3); *start = 0;} 324963d1a920SMatthew G. Knepley if (end) {PetscValidPointer(end, 4); *end = 0;} 3250552f7358SJed Brown ierr = DMPlexGetChart(dm, &pStart, &pEnd);CHKERRQ(ierr); 32510d644c17SKarl Rupp if (pStart == pEnd) PetscFunctionReturn(0); 325263d1a920SMatthew G. Knepley if (stratumValue < 0) { 325363d1a920SMatthew G. Knepley if (start) *start = pStart; 325463d1a920SMatthew G. Knepley if (end) *end = pEnd; 325563d1a920SMatthew G. Knepley PetscFunctionReturn(0); 3256552f7358SJed Brown } 3257aa50250dSMatthew G. Knepley ierr = DMPlexGetDepthLabel(dm, &label);CHKERRQ(ierr); 325813903a91SSatish Balay if (!label) SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "No label named depth was found"); 325963d1a920SMatthew G. Knepley ierr = DMLabelGetNumValues(label, &depth);CHKERRQ(ierr); 326063d1a920SMatthew G. Knepley ierr = DMLabelGetStratumBounds(label, depth-1-stratumValue, start, end);CHKERRQ(ierr); 3261552f7358SJed Brown PetscFunctionReturn(0); 3262552f7358SJed Brown } 3263552f7358SJed Brown 3264552f7358SJed Brown /* Set the number of dof on each point and separate by fields */ 32657cd05799SMatthew G. Knepley static PetscErrorCode DMPlexCreateSectionInitial(DM dm, PetscInt dim, PetscInt numFields,const PetscInt numComp[],const PetscInt numDof[], PetscSection *section) 3266a6dfd86eSKarl Rupp { 3267ee55978aSMatthew G. Knepley PetscInt *pMax; 3268470f9322SMatthew G. Knepley PetscInt depth, cellHeight, pStart = 0, pEnd = 0; 3269ee55978aSMatthew G. Knepley PetscInt Nf, p, d, dep, f; 3270fa716be8SMatthew G. Knepley PetscBool *isFE; 3271552f7358SJed Brown PetscErrorCode ierr; 3272552f7358SJed Brown 3273552f7358SJed Brown PetscFunctionBegin; 3274fa716be8SMatthew G. Knepley ierr = PetscMalloc1(numFields, &isFE);CHKERRQ(ierr); 3275ee55978aSMatthew G. Knepley ierr = DMGetNumFields(dm, &Nf);CHKERRQ(ierr); 3276fa716be8SMatthew G. Knepley for (f = 0; f < numFields; ++f) { 3277fa716be8SMatthew G. Knepley PetscObject obj; 3278fa716be8SMatthew G. Knepley PetscClassId id; 3279fa716be8SMatthew G. Knepley 3280ee55978aSMatthew G. Knepley isFE[f] = PETSC_FALSE; 3281ee55978aSMatthew G. Knepley if (f >= Nf) continue; 3282fa716be8SMatthew G. Knepley ierr = DMGetField(dm, f, &obj);CHKERRQ(ierr); 3283fa716be8SMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 3284fa716be8SMatthew G. Knepley if (id == PETSCFE_CLASSID) {isFE[f] = PETSC_TRUE;} 3285fa716be8SMatthew G. Knepley else if (id == PETSCFV_CLASSID) {isFE[f] = PETSC_FALSE;} 3286552f7358SJed Brown } 328782f516ccSBarry Smith ierr = PetscSectionCreate(PetscObjectComm((PetscObject)dm), section);CHKERRQ(ierr); 3288552f7358SJed Brown if (numFields > 0) { 3289552f7358SJed Brown ierr = PetscSectionSetNumFields(*section, numFields);CHKERRQ(ierr); 3290552f7358SJed Brown if (numComp) { 3291552f7358SJed Brown for (f = 0; f < numFields; ++f) { 3292552f7358SJed Brown ierr = PetscSectionSetFieldComponents(*section, f, numComp[f]);CHKERRQ(ierr); 3293d484f18aSToby Isaac if (isFE[f]) { 3294d484f18aSToby Isaac PetscFE fe; 3295d484f18aSToby Isaac PetscDualSpace dspace; 3296d484f18aSToby Isaac const PetscInt ***perms; 3297d484f18aSToby Isaac const PetscScalar ***flips; 3298d484f18aSToby Isaac const PetscInt *numDof; 3299d484f18aSToby Isaac 3300d484f18aSToby Isaac ierr = DMGetField(dm,f,(PetscObject *) &fe);CHKERRQ(ierr); 3301d484f18aSToby Isaac ierr = PetscFEGetDualSpace(fe,&dspace);CHKERRQ(ierr); 3302d484f18aSToby Isaac ierr = PetscDualSpaceGetSymmetries(dspace,&perms,&flips);CHKERRQ(ierr); 3303d484f18aSToby Isaac ierr = PetscDualSpaceGetNumDof(dspace,&numDof);CHKERRQ(ierr); 3304d484f18aSToby Isaac if (perms || flips) { 3305d484f18aSToby Isaac DM K; 3306d484f18aSToby Isaac DMLabel depthLabel; 3307d484f18aSToby Isaac PetscInt depth, h; 3308d484f18aSToby Isaac PetscSectionSym sym; 3309d484f18aSToby Isaac 3310d484f18aSToby Isaac ierr = PetscDualSpaceGetDM(dspace,&K);CHKERRQ(ierr); 3311d484f18aSToby Isaac ierr = DMPlexGetDepthLabel(dm,&depthLabel);CHKERRQ(ierr); 3312d484f18aSToby Isaac ierr = DMPlexGetDepth(dm,&depth);CHKERRQ(ierr); 3313d484f18aSToby Isaac ierr = PetscSectionSymCreateLabel(PetscObjectComm((PetscObject)*section),depthLabel,&sym);CHKERRQ(ierr); 3314d484f18aSToby Isaac for (h = 0; h <= depth; h++) { 3315d484f18aSToby Isaac PetscDualSpace hspace; 3316d484f18aSToby Isaac PetscInt kStart, kEnd; 3317d484f18aSToby Isaac PetscInt kConeSize; 3318d484f18aSToby Isaac const PetscInt **perms0 = NULL; 3319d484f18aSToby Isaac const PetscScalar **flips0 = NULL; 3320d484f18aSToby Isaac 3321d484f18aSToby Isaac ierr = PetscDualSpaceGetHeightSubspace(dspace,h,&hspace);CHKERRQ(ierr); 3322d484f18aSToby Isaac ierr = DMPlexGetHeightStratum(K,h,&kStart,&kEnd);CHKERRQ(ierr); 3323d484f18aSToby Isaac if (!hspace) continue; 3324d484f18aSToby Isaac ierr = PetscDualSpaceGetSymmetries(hspace,&perms,&flips);CHKERRQ(ierr); 3325d484f18aSToby Isaac if (perms) perms0 = perms[0]; 3326d484f18aSToby Isaac if (flips) flips0 = flips[0]; 3327d484f18aSToby Isaac if (!(perms0 || flips0)) continue; 3328d484f18aSToby Isaac ierr = DMPlexGetConeSize(K,kStart,&kConeSize);CHKERRQ(ierr); 3329d484f18aSToby Isaac ierr = PetscSectionSymLabelSetStratum(sym,depth - h,numDof[depth - h],-kConeSize,kConeSize,PETSC_USE_POINTER,perms0 ? &perms0[-kConeSize] : NULL,flips0 ? &flips0[-kConeSize] : NULL);CHKERRQ(ierr); 3330d484f18aSToby Isaac } 3331d484f18aSToby Isaac ierr = PetscSectionSetFieldSym(*section,f,sym);CHKERRQ(ierr); 3332d484f18aSToby Isaac ierr = PetscSectionSymDestroy(&sym);CHKERRQ(ierr); 3333d484f18aSToby Isaac } 3334d484f18aSToby Isaac } 3335552f7358SJed Brown } 3336552f7358SJed Brown } 3337552f7358SJed Brown } 3338552f7358SJed Brown ierr = DMPlexGetChart(dm, &pStart, &pEnd);CHKERRQ(ierr); 3339552f7358SJed Brown ierr = PetscSectionSetChart(*section, pStart, pEnd);CHKERRQ(ierr); 3340916f0f19SMatthew G. Knepley ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 33419ac3fadcSMatthew G. Knepley ierr = PetscMalloc1(depth+1,&pMax);CHKERRQ(ierr); 33429ac3fadcSMatthew G. Knepley ierr = DMPlexGetHybridBounds(dm, depth >= 0 ? &pMax[depth] : NULL, depth>1 ? &pMax[depth-1] : NULL, depth>2 ? &pMax[1] : NULL, &pMax[0]);CHKERRQ(ierr); 3343470f9322SMatthew G. Knepley ierr = DMPlexGetVTKCellHeight(dm, &cellHeight);CHKERRQ(ierr); 3344470f9322SMatthew G. Knepley for (dep = 0; dep <= depth - cellHeight; ++dep) { 3345916f0f19SMatthew G. Knepley d = dim == depth ? dep : (!dep ? 0 : dim); 3346916f0f19SMatthew G. Knepley ierr = DMPlexGetDepthStratum(dm, dep, &pStart, &pEnd);CHKERRQ(ierr); 3347fa716be8SMatthew G. Knepley pMax[dep] = pMax[dep] < 0 ? pEnd : pMax[dep]; 3348552f7358SJed Brown for (p = pStart; p < pEnd; ++p) { 3349ee55978aSMatthew G. Knepley PetscInt tot = 0; 3350ee55978aSMatthew G. Knepley 3351552f7358SJed Brown for (f = 0; f < numFields; ++f) { 3352fa716be8SMatthew G. Knepley if (isFE[f] && p >= pMax[dep]) continue; 3353552f7358SJed Brown ierr = PetscSectionSetFieldDof(*section, p, f, numDof[f*(dim+1)+d]);CHKERRQ(ierr); 3354ee55978aSMatthew G. Knepley tot += numDof[f*(dim+1)+d]; 3355552f7358SJed Brown } 3356ee55978aSMatthew G. Knepley ierr = PetscSectionSetDof(*section, p, tot);CHKERRQ(ierr); 3357552f7358SJed Brown } 3358552f7358SJed Brown } 33599ac3fadcSMatthew G. Knepley ierr = PetscFree(pMax);CHKERRQ(ierr); 3360fa716be8SMatthew G. Knepley ierr = PetscFree(isFE);CHKERRQ(ierr); 3361552f7358SJed Brown PetscFunctionReturn(0); 3362552f7358SJed Brown } 3363552f7358SJed Brown 3364552f7358SJed Brown /* Set the number of dof on each point and separate by fields 3365ab1d0545SMatthew G. Knepley If bcComps is NULL or the IS is NULL, constrain every dof on the point 3366552f7358SJed Brown */ 33677cd05799SMatthew G. Knepley static PetscErrorCode DMPlexCreateSectionBCDof(DM dm, PetscInt numBC, const PetscInt bcField[], const IS bcComps[], const IS bcPoints[], PetscSection section) 3368a6dfd86eSKarl Rupp { 3369552f7358SJed Brown PetscInt numFields; 3370552f7358SJed Brown PetscInt bc; 3371a68b90caSToby Isaac PetscSection aSec; 3372552f7358SJed Brown PetscErrorCode ierr; 3373552f7358SJed Brown 3374552f7358SJed Brown PetscFunctionBegin; 3375552f7358SJed Brown ierr = PetscSectionGetNumFields(section, &numFields);CHKERRQ(ierr); 3376552f7358SJed Brown for (bc = 0; bc < numBC; ++bc) { 3377552f7358SJed Brown PetscInt field = 0; 3378ab1d0545SMatthew G. Knepley const PetscInt *comp; 3379552f7358SJed Brown const PetscInt *idx; 3380ab1d0545SMatthew G. Knepley PetscInt Nc = -1, n, i; 3381552f7358SJed Brown 33820d644c17SKarl Rupp if (numFields) field = bcField[bc]; 3383ab1d0545SMatthew G. Knepley if (bcComps && bcComps[bc]) {ierr = ISGetLocalSize(bcComps[bc], &Nc);CHKERRQ(ierr);} 3384ab1d0545SMatthew G. Knepley if (bcComps && bcComps[bc]) {ierr = ISGetIndices(bcComps[bc], &comp);CHKERRQ(ierr);} 3385552f7358SJed Brown ierr = ISGetLocalSize(bcPoints[bc], &n);CHKERRQ(ierr); 3386552f7358SJed Brown ierr = ISGetIndices(bcPoints[bc], &idx);CHKERRQ(ierr); 3387552f7358SJed Brown for (i = 0; i < n; ++i) { 3388552f7358SJed Brown const PetscInt p = idx[i]; 338906ff1081SMatthew G. Knepley PetscInt numConst; 3390552f7358SJed Brown 3391552f7358SJed Brown if (numFields) { 3392552f7358SJed Brown ierr = PetscSectionGetFieldDof(section, p, field, &numConst);CHKERRQ(ierr); 3393552f7358SJed Brown } else { 3394552f7358SJed Brown ierr = PetscSectionGetDof(section, p, &numConst);CHKERRQ(ierr); 3395552f7358SJed Brown } 339606ff1081SMatthew G. Knepley /* If Nc < 0, constrain every dof on the point */ 339706ff1081SMatthew G. Knepley if (Nc > 0) numConst = PetscMin(numConst, Nc); 339806ff1081SMatthew G. Knepley if (numFields) {ierr = PetscSectionAddFieldConstraintDof(section, p, field, numConst);CHKERRQ(ierr);} 3399552f7358SJed Brown ierr = PetscSectionAddConstraintDof(section, p, numConst);CHKERRQ(ierr); 3400552f7358SJed Brown } 3401552f7358SJed Brown ierr = ISRestoreIndices(bcPoints[bc], &idx);CHKERRQ(ierr); 340206ff1081SMatthew G. Knepley if (bcComps && bcComps[bc]) {ierr = ISRestoreIndices(bcComps[bc], &comp);CHKERRQ(ierr);} 3403552f7358SJed Brown } 3404a17985deSToby Isaac ierr = DMPlexGetAnchors(dm, &aSec, NULL);CHKERRQ(ierr); 3405a68b90caSToby Isaac if (aSec) { 3406a68b90caSToby Isaac PetscInt aStart, aEnd, a; 3407a68b90caSToby Isaac 3408a68b90caSToby Isaac ierr = PetscSectionGetChart(aSec, &aStart, &aEnd);CHKERRQ(ierr); 3409a68b90caSToby Isaac for (a = aStart; a < aEnd; a++) { 3410ab1d0545SMatthew G. Knepley PetscInt dof, f; 3411a68b90caSToby Isaac 3412a68b90caSToby Isaac ierr = PetscSectionGetDof(aSec, a, &dof);CHKERRQ(ierr); 3413a68b90caSToby Isaac if (dof) { 3414a68b90caSToby Isaac /* if there are point-to-point constraints, then all dofs are constrained */ 3415a68b90caSToby Isaac ierr = PetscSectionGetDof(section, a, &dof);CHKERRQ(ierr); 3416a68b90caSToby Isaac ierr = PetscSectionSetConstraintDof(section, a, dof);CHKERRQ(ierr); 3417a68b90caSToby Isaac for (f = 0; f < numFields; f++) { 3418a68b90caSToby Isaac ierr = PetscSectionGetFieldDof(section, a, f, &dof);CHKERRQ(ierr); 3419a68b90caSToby Isaac ierr = PetscSectionSetFieldConstraintDof(section, a, f, dof);CHKERRQ(ierr); 3420a68b90caSToby Isaac } 3421a68b90caSToby Isaac } 3422a68b90caSToby Isaac } 3423a68b90caSToby Isaac } 3424552f7358SJed Brown PetscFunctionReturn(0); 3425552f7358SJed Brown } 3426552f7358SJed Brown 3427ab1d0545SMatthew G. Knepley /* Set the constrained field indices on each point 3428ab1d0545SMatthew G. Knepley If bcComps is NULL or the IS is NULL, constrain every dof on the point 3429ab1d0545SMatthew G. Knepley */ 34307cd05799SMatthew G. Knepley static PetscErrorCode DMPlexCreateSectionBCIndicesField(DM dm, PetscInt numBC,const PetscInt bcField[], const IS bcComps[], const IS bcPoints[], PetscSection section) 34310adebc6cSBarry Smith { 3432ab1d0545SMatthew G. Knepley PetscSection aSec; 3433ab1d0545SMatthew G. Knepley PetscInt *indices; 3434503335f2SSander Arens PetscInt numFields, cdof, maxDof = 0, pStart, pEnd, p, bc, f, d; 3435552f7358SJed Brown PetscErrorCode ierr; 3436552f7358SJed Brown 3437552f7358SJed Brown PetscFunctionBegin; 3438552f7358SJed Brown ierr = PetscSectionGetNumFields(section, &numFields);CHKERRQ(ierr); 3439ab1d0545SMatthew G. Knepley if (!numFields) PetscFunctionReturn(0); 3440ab1d0545SMatthew G. Knepley /* Initialize all field indices to -1 */ 3441552f7358SJed Brown ierr = PetscSectionGetChart(section, &pStart, &pEnd);CHKERRQ(ierr); 3442503335f2SSander Arens for (p = pStart; p < pEnd; ++p) {ierr = PetscSectionGetConstraintDof(section, p, &cdof);CHKERRQ(ierr); maxDof = PetscMax(maxDof, cdof);} 3443ab1d0545SMatthew G. Knepley ierr = PetscMalloc1(maxDof, &indices);CHKERRQ(ierr); 3444ab1d0545SMatthew G. Knepley for (d = 0; d < maxDof; ++d) indices[d] = -1; 3445ab1d0545SMatthew G. Knepley for (p = pStart; p < pEnd; ++p) for (f = 0; f < numFields; ++f) {ierr = PetscSectionSetFieldConstraintIndices(section, p, f, indices);CHKERRQ(ierr);} 3446ab1d0545SMatthew G. Knepley /* Handle BC constraints */ 3447ab1d0545SMatthew G. Knepley for (bc = 0; bc < numBC; ++bc) { 3448ab1d0545SMatthew G. Knepley const PetscInt field = bcField[bc]; 3449ab1d0545SMatthew G. Knepley const PetscInt *comp, *idx; 3450ab1d0545SMatthew G. Knepley PetscInt Nc = -1, n, i; 3451552f7358SJed Brown 3452ab1d0545SMatthew G. Knepley if (bcComps && bcComps[bc]) {ierr = ISGetLocalSize(bcComps[bc], &Nc);CHKERRQ(ierr);} 3453ab1d0545SMatthew G. Knepley if (bcComps && bcComps[bc]) {ierr = ISGetIndices(bcComps[bc], &comp);CHKERRQ(ierr);} 3454ab1d0545SMatthew G. Knepley ierr = ISGetLocalSize(bcPoints[bc], &n);CHKERRQ(ierr); 3455ab1d0545SMatthew G. Knepley ierr = ISGetIndices(bcPoints[bc], &idx);CHKERRQ(ierr); 3456ab1d0545SMatthew G. Knepley for (i = 0; i < n; ++i) { 3457ab1d0545SMatthew G. Knepley const PetscInt p = idx[i]; 3458ab1d0545SMatthew G. Knepley const PetscInt *find; 3459503335f2SSander Arens PetscInt fdof, fcdof, c; 3460ab1d0545SMatthew G. Knepley 3461503335f2SSander Arens ierr = PetscSectionGetFieldDof(section, p, field, &fdof);CHKERRQ(ierr); 3462503335f2SSander Arens if (!fdof) continue; 3463ab1d0545SMatthew G. Knepley if (Nc < 0) { 3464503335f2SSander Arens for (d = 0; d < fdof; ++d) indices[d] = d; 3465503335f2SSander Arens fcdof = fdof; 3466552f7358SJed Brown } else { 3467503335f2SSander Arens ierr = PetscSectionGetFieldConstraintDof(section, p, field, &fcdof);CHKERRQ(ierr); 3468ab1d0545SMatthew G. Knepley ierr = PetscSectionGetFieldConstraintIndices(section, p, field, &find);CHKERRQ(ierr); 3469ab1d0545SMatthew G. Knepley for (d = 0; d < fcdof; ++d) {if (find[d] < 0) break; indices[d] = find[d];} 3470503335f2SSander Arens for (c = 0; c < Nc; ++c) indices[d++] = comp[c]; 3471503335f2SSander Arens ierr = PetscSortRemoveDupsInt(&d, indices);CHKERRQ(ierr); 3472503335f2SSander Arens for (c = d; c < fcdof; ++c) indices[c] = -1; 3473503335f2SSander Arens fcdof = d; 3474552f7358SJed Brown } 3475503335f2SSander Arens ierr = PetscSectionSetFieldConstraintDof(section, p, field, fcdof);CHKERRQ(ierr); 3476ab1d0545SMatthew G. Knepley ierr = PetscSectionSetFieldConstraintIndices(section, p, field, indices);CHKERRQ(ierr); 3477552f7358SJed Brown } 3478ab1d0545SMatthew G. Knepley if (bcComps && bcComps[bc]) {ierr = ISRestoreIndices(bcComps[bc], &comp);CHKERRQ(ierr);} 3479ab1d0545SMatthew G. Knepley ierr = ISRestoreIndices(bcPoints[bc], &idx);CHKERRQ(ierr); 3480552f7358SJed Brown } 3481ab1d0545SMatthew G. Knepley /* Handle anchors */ 3482ab1d0545SMatthew G. Knepley ierr = DMPlexGetAnchors(dm, &aSec, NULL);CHKERRQ(ierr); 3483ab1d0545SMatthew G. Knepley if (aSec) { 3484ab1d0545SMatthew G. Knepley PetscInt aStart, aEnd, a; 3485552f7358SJed Brown 3486ab1d0545SMatthew G. Knepley for (d = 0; d < maxDof; ++d) indices[d] = d; 3487ab1d0545SMatthew G. Knepley ierr = PetscSectionGetChart(aSec, &aStart, &aEnd);CHKERRQ(ierr); 3488ab1d0545SMatthew G. Knepley for (a = aStart; a < aEnd; a++) { 3489503335f2SSander Arens PetscInt dof, f; 3490ab1d0545SMatthew G. Knepley 3491ab1d0545SMatthew G. Knepley ierr = PetscSectionGetDof(aSec, a, &dof);CHKERRQ(ierr); 3492ab1d0545SMatthew G. Knepley if (dof) { 3493ab1d0545SMatthew G. Knepley /* if there are point-to-point constraints, then all dofs are constrained */ 3494ab1d0545SMatthew G. Knepley for (f = 0; f < numFields; f++) { 3495ab1d0545SMatthew G. Knepley ierr = PetscSectionSetFieldConstraintIndices(section, a, f, indices);CHKERRQ(ierr); 3496ab1d0545SMatthew G. Knepley } 3497ab1d0545SMatthew G. Knepley } 3498ab1d0545SMatthew G. Knepley } 3499ab1d0545SMatthew G. Knepley } 3500ab1d0545SMatthew G. Knepley ierr = PetscFree(indices);CHKERRQ(ierr); 3501ab1d0545SMatthew G. Knepley PetscFunctionReturn(0); 3502ab1d0545SMatthew G. Knepley } 3503ab1d0545SMatthew G. Knepley 3504ab1d0545SMatthew G. Knepley /* Set the constrained indices on each point */ 35057cd05799SMatthew G. Knepley static PetscErrorCode DMPlexCreateSectionBCIndices(DM dm, PetscSection section) 3506ab1d0545SMatthew G. Knepley { 3507ab1d0545SMatthew G. Knepley PetscInt *indices; 3508ab1d0545SMatthew G. Knepley PetscInt numFields, maxDof, pStart, pEnd, p, f, d; 3509ab1d0545SMatthew G. Knepley PetscErrorCode ierr; 3510ab1d0545SMatthew G. Knepley 3511ab1d0545SMatthew G. Knepley PetscFunctionBegin; 3512ab1d0545SMatthew G. Knepley ierr = PetscSectionGetNumFields(section, &numFields);CHKERRQ(ierr); 3513ab1d0545SMatthew G. Knepley ierr = PetscSectionGetMaxDof(section, &maxDof);CHKERRQ(ierr); 3514ab1d0545SMatthew G. Knepley ierr = PetscSectionGetChart(section, &pStart, &pEnd);CHKERRQ(ierr); 3515ab1d0545SMatthew G. Knepley ierr = PetscMalloc1(maxDof, &indices);CHKERRQ(ierr); 3516ab1d0545SMatthew G. Knepley for (d = 0; d < maxDof; ++d) indices[d] = -1; 3517552f7358SJed Brown for (p = pStart; p < pEnd; ++p) { 3518552f7358SJed Brown PetscInt cdof, d; 3519552f7358SJed Brown 3520552f7358SJed Brown ierr = PetscSectionGetConstraintDof(section, p, &cdof);CHKERRQ(ierr); 3521552f7358SJed Brown if (cdof) { 3522552f7358SJed Brown if (numFields) { 3523552f7358SJed Brown PetscInt numConst = 0, foff = 0; 3524552f7358SJed Brown 3525552f7358SJed Brown for (f = 0; f < numFields; ++f) { 3526ab1d0545SMatthew G. Knepley const PetscInt *find; 3527ab1d0545SMatthew G. Knepley PetscInt fcdof, fdof; 3528552f7358SJed Brown 3529552f7358SJed Brown ierr = PetscSectionGetFieldDof(section, p, f, &fdof);CHKERRQ(ierr); 3530ab1d0545SMatthew G. Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, f, &fcdof);CHKERRQ(ierr); 3531ab1d0545SMatthew G. Knepley /* Change constraint numbering from field component to local dof number */ 3532ab1d0545SMatthew G. Knepley ierr = PetscSectionGetFieldConstraintIndices(section, p, f, &find);CHKERRQ(ierr); 3533ab1d0545SMatthew G. Knepley for (d = 0; d < fcdof; ++d) indices[numConst+d] = find[d] + foff; 3534ab1d0545SMatthew G. Knepley numConst += fcdof; 3535552f7358SJed Brown foff += fdof; 3536552f7358SJed Brown } 3537503335f2SSander Arens if (cdof != numConst) {ierr = PetscSectionSetConstraintDof(section, p, numConst);CHKERRQ(ierr);} 3538552f7358SJed Brown } else { 35390d644c17SKarl Rupp for (d = 0; d < cdof; ++d) indices[d] = d; 3540552f7358SJed Brown } 3541552f7358SJed Brown ierr = PetscSectionSetConstraintIndices(section, p, indices);CHKERRQ(ierr); 3542552f7358SJed Brown } 3543552f7358SJed Brown } 3544552f7358SJed Brown ierr = PetscFree(indices);CHKERRQ(ierr); 3545552f7358SJed Brown PetscFunctionReturn(0); 3546552f7358SJed Brown } 3547552f7358SJed Brown 3548552f7358SJed Brown /*@C 3549552f7358SJed Brown DMPlexCreateSection - Create a PetscSection based upon the dof layout specification provided. 3550552f7358SJed Brown 3551552f7358SJed Brown Not Collective 3552552f7358SJed Brown 3553552f7358SJed Brown Input Parameters: 3554552f7358SJed Brown + dm - The DMPlex object 3555552f7358SJed Brown . dim - The spatial dimension of the problem 3556552f7358SJed Brown . numFields - The number of fields in the problem 3557552f7358SJed Brown . numComp - An array of size numFields that holds the number of components for each field 3558552f7358SJed Brown . numDof - An array of size numFields*(dim+1) which holds the number of dof for each field on a mesh piece of dimension d 3559552f7358SJed Brown . numBC - The number of boundary conditions 3560552f7358SJed Brown . bcField - An array of size numBC giving the field number for each boundry condition 3561ab1d0545SMatthew G. Knepley . bcComps - [Optional] An array of size numBC giving an IS holding the field components to which each boundary condition applies 3562ab1d0545SMatthew G. Knepley . bcPoints - An array of size numBC giving an IS holding the Plex points to which each boundary condition applies 3563f8f126e8SMatthew G. Knepley - perm - Optional permutation of the chart, or NULL 3564552f7358SJed Brown 3565552f7358SJed Brown Output Parameter: 3566552f7358SJed Brown . section - The PetscSection object 3567552f7358SJed Brown 356895452b02SPatrick Sanan Notes: 356995452b02SPatrick Sanan numDof[f*(dim+1)+d] gives the number of dof for field f on points of dimension d. For instance, numDof[1] is the 3570f8f126e8SMatthew G. Knepley number of dof for field 0 on each edge. 3571f8f126e8SMatthew G. Knepley 3572f8f126e8SMatthew G. Knepley The chart permutation is the same one set using PetscSectionSetPermutation() 3573552f7358SJed Brown 3574552f7358SJed Brown Level: developer 3575552f7358SJed Brown 35763813dfbdSMatthew G Knepley Fortran Notes: 35773813dfbdSMatthew G Knepley A Fortran 90 version is available as DMPlexCreateSectionF90() 35783813dfbdSMatthew G Knepley 3579552f7358SJed Brown .keywords: mesh, elements 3580f8f126e8SMatthew G. Knepley .seealso: DMPlexCreate(), PetscSectionCreate(), PetscSectionSetPermutation() 3581552f7358SJed Brown @*/ 3582ab1d0545SMatthew G. Knepley PetscErrorCode DMPlexCreateSection(DM dm, PetscInt dim, PetscInt numFields,const PetscInt numComp[],const PetscInt numDof[], PetscInt numBC,const PetscInt bcField[], const IS bcComps[], const IS bcPoints[], IS perm, PetscSection *section) 3583a6dfd86eSKarl Rupp { 3584a68b90caSToby Isaac PetscSection aSec; 3585552f7358SJed Brown PetscErrorCode ierr; 3586552f7358SJed Brown 3587552f7358SJed Brown PetscFunctionBegin; 3588552f7358SJed Brown ierr = DMPlexCreateSectionInitial(dm, dim, numFields, numComp, numDof, section);CHKERRQ(ierr); 3589ab1d0545SMatthew G. Knepley ierr = DMPlexCreateSectionBCDof(dm, numBC, bcField, bcComps, bcPoints, *section);CHKERRQ(ierr); 3590f8f126e8SMatthew G. Knepley if (perm) {ierr = PetscSectionSetPermutation(*section, perm);CHKERRQ(ierr);} 3591552f7358SJed Brown ierr = PetscSectionSetUp(*section);CHKERRQ(ierr); 3592a17985deSToby Isaac ierr = DMPlexGetAnchors(dm,&aSec,NULL);CHKERRQ(ierr); 3593ab1d0545SMatthew G. Knepley if (numBC || aSec) { 3594ab1d0545SMatthew G. Knepley ierr = DMPlexCreateSectionBCIndicesField(dm, numBC, bcField, bcComps, bcPoints, *section);CHKERRQ(ierr); 3595ab1d0545SMatthew G. Knepley ierr = DMPlexCreateSectionBCIndices(dm, *section);CHKERRQ(ierr); 3596ab1d0545SMatthew G. Knepley } 3597ce1779c8SBarry Smith ierr = PetscSectionViewFromOptions(*section,NULL,"-section_view");CHKERRQ(ierr); 3598552f7358SJed Brown PetscFunctionReturn(0); 3599552f7358SJed Brown } 3600552f7358SJed Brown 36010adebc6cSBarry Smith PetscErrorCode DMCreateCoordinateDM_Plex(DM dm, DM *cdm) 36020adebc6cSBarry Smith { 3603efe440bfSMatthew G. Knepley PetscSection section, s; 3604efe440bfSMatthew G. Knepley Mat m; 36053e922f36SToby Isaac PetscInt maxHeight; 3606552f7358SJed Brown PetscErrorCode ierr; 3607552f7358SJed Brown 3608552f7358SJed Brown PetscFunctionBegin; 360938221697SMatthew G. Knepley ierr = DMClone(dm, cdm);CHKERRQ(ierr); 36103e922f36SToby Isaac ierr = DMPlexGetMaxProjectionHeight(dm, &maxHeight);CHKERRQ(ierr); 36113e922f36SToby Isaac ierr = DMPlexSetMaxProjectionHeight(*cdm, maxHeight);CHKERRQ(ierr); 361282f516ccSBarry Smith ierr = PetscSectionCreate(PetscObjectComm((PetscObject)dm), §ion);CHKERRQ(ierr); 3613e87a4003SBarry Smith ierr = DMSetSection(*cdm, section);CHKERRQ(ierr); 36141d799100SJed Brown ierr = PetscSectionDestroy(§ion);CHKERRQ(ierr); 3615efe440bfSMatthew G. Knepley ierr = PetscSectionCreate(PETSC_COMM_SELF, &s);CHKERRQ(ierr); 3616efe440bfSMatthew G. Knepley ierr = MatCreate(PETSC_COMM_SELF, &m);CHKERRQ(ierr); 3617efe440bfSMatthew G. Knepley ierr = DMSetDefaultConstraints(*cdm, s, m);CHKERRQ(ierr); 3618efe440bfSMatthew G. Knepley ierr = PetscSectionDestroy(&s);CHKERRQ(ierr); 3619efe440bfSMatthew G. Knepley ierr = MatDestroy(&m);CHKERRQ(ierr); 3620552f7358SJed Brown PetscFunctionReturn(0); 3621552f7358SJed Brown } 3622552f7358SJed Brown 3623f19dbd58SToby Isaac PetscErrorCode DMCreateCoordinateField_Plex(DM dm, DMField *field) 3624f19dbd58SToby Isaac { 3625f19dbd58SToby Isaac Vec coordsLocal; 3626f19dbd58SToby Isaac DM coordsDM; 3627f19dbd58SToby Isaac PetscErrorCode ierr; 3628f19dbd58SToby Isaac 3629f19dbd58SToby Isaac PetscFunctionBegin; 3630f19dbd58SToby Isaac *field = NULL; 3631f19dbd58SToby Isaac ierr = DMGetCoordinatesLocal(dm,&coordsLocal);CHKERRQ(ierr); 3632f19dbd58SToby Isaac ierr = DMGetCoordinateDM(dm,&coordsDM);CHKERRQ(ierr); 3633f19dbd58SToby Isaac if (coordsLocal && coordsDM) { 3634f19dbd58SToby Isaac ierr = DMFieldCreateDS(coordsDM, 0, coordsLocal, field);CHKERRQ(ierr); 3635f19dbd58SToby Isaac } 3636f19dbd58SToby Isaac PetscFunctionReturn(0); 3637f19dbd58SToby Isaac } 3638f19dbd58SToby Isaac 36397cd05799SMatthew G. Knepley /*@C 36407cd05799SMatthew G. Knepley DMPlexGetConeSection - Return a section which describes the layout of cone data 36417cd05799SMatthew G. Knepley 36427cd05799SMatthew G. Knepley Not Collective 36437cd05799SMatthew G. Knepley 36447cd05799SMatthew G. Knepley Input Parameters: 36457cd05799SMatthew G. Knepley . dm - The DMPlex object 36467cd05799SMatthew G. Knepley 36477cd05799SMatthew G. Knepley Output Parameter: 36487cd05799SMatthew G. Knepley . section - The PetscSection object 36497cd05799SMatthew G. Knepley 36507cd05799SMatthew G. Knepley Level: developer 36517cd05799SMatthew G. Knepley 36527cd05799SMatthew G. Knepley .seealso: DMPlexGetSupportSection(), DMPlexGetCones(), DMPlexGetConeOrientations() 36537cd05799SMatthew G. Knepley @*/ 36540adebc6cSBarry Smith PetscErrorCode DMPlexGetConeSection(DM dm, PetscSection *section) 36550adebc6cSBarry Smith { 3656552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 3657552f7358SJed Brown 3658552f7358SJed Brown PetscFunctionBegin; 3659552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3660552f7358SJed Brown if (section) *section = mesh->coneSection; 3661552f7358SJed Brown PetscFunctionReturn(0); 3662552f7358SJed Brown } 3663552f7358SJed Brown 36647cd05799SMatthew G. Knepley /*@C 36657cd05799SMatthew G. Knepley DMPlexGetSupportSection - Return a section which describes the layout of support data 36667cd05799SMatthew G. Knepley 36677cd05799SMatthew G. Knepley Not Collective 36687cd05799SMatthew G. Knepley 36697cd05799SMatthew G. Knepley Input Parameters: 36707cd05799SMatthew G. Knepley . dm - The DMPlex object 36717cd05799SMatthew G. Knepley 36727cd05799SMatthew G. Knepley Output Parameter: 36737cd05799SMatthew G. Knepley . section - The PetscSection object 36747cd05799SMatthew G. Knepley 36757cd05799SMatthew G. Knepley Level: developer 36767cd05799SMatthew G. Knepley 36777cd05799SMatthew G. Knepley .seealso: DMPlexGetConeSection() 36787cd05799SMatthew G. Knepley @*/ 36798cb4d582SMatthew G. Knepley PetscErrorCode DMPlexGetSupportSection(DM dm, PetscSection *section) 36808cb4d582SMatthew G. Knepley { 36818cb4d582SMatthew G. Knepley DM_Plex *mesh = (DM_Plex*) dm->data; 36828cb4d582SMatthew G. Knepley 36838cb4d582SMatthew G. Knepley PetscFunctionBegin; 36848cb4d582SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 36858cb4d582SMatthew G. Knepley if (section) *section = mesh->supportSection; 36868cb4d582SMatthew G. Knepley PetscFunctionReturn(0); 36878cb4d582SMatthew G. Knepley } 36888cb4d582SMatthew G. Knepley 36897cd05799SMatthew G. Knepley /*@C 36907cd05799SMatthew G. Knepley DMPlexGetCones - Return cone data 36917cd05799SMatthew G. Knepley 36927cd05799SMatthew G. Knepley Not Collective 36937cd05799SMatthew G. Knepley 36947cd05799SMatthew G. Knepley Input Parameters: 36957cd05799SMatthew G. Knepley . dm - The DMPlex object 36967cd05799SMatthew G. Knepley 36977cd05799SMatthew G. Knepley Output Parameter: 36987cd05799SMatthew G. Knepley . cones - The cone for each point 36997cd05799SMatthew G. Knepley 37007cd05799SMatthew G. Knepley Level: developer 37017cd05799SMatthew G. Knepley 37027cd05799SMatthew G. Knepley .seealso: DMPlexGetConeSection() 37037cd05799SMatthew G. Knepley @*/ 3704a6dfd86eSKarl Rupp PetscErrorCode DMPlexGetCones(DM dm, PetscInt *cones[]) 3705a6dfd86eSKarl Rupp { 3706552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 3707552f7358SJed Brown 3708552f7358SJed Brown PetscFunctionBegin; 3709552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3710552f7358SJed Brown if (cones) *cones = mesh->cones; 3711552f7358SJed Brown PetscFunctionReturn(0); 3712552f7358SJed Brown } 3713552f7358SJed Brown 37147cd05799SMatthew G. Knepley /*@C 37157cd05799SMatthew G. Knepley DMPlexGetConeOrientations - Return cone orientation data 37167cd05799SMatthew G. Knepley 37177cd05799SMatthew G. Knepley Not Collective 37187cd05799SMatthew G. Knepley 37197cd05799SMatthew G. Knepley Input Parameters: 37207cd05799SMatthew G. Knepley . dm - The DMPlex object 37217cd05799SMatthew G. Knepley 37227cd05799SMatthew G. Knepley Output Parameter: 37237cd05799SMatthew G. Knepley . coneOrientations - The cone orientation for each point 37247cd05799SMatthew G. Knepley 37257cd05799SMatthew G. Knepley Level: developer 37267cd05799SMatthew G. Knepley 37277cd05799SMatthew G. Knepley .seealso: DMPlexGetConeSection() 37287cd05799SMatthew G. Knepley @*/ 3729a6dfd86eSKarl Rupp PetscErrorCode DMPlexGetConeOrientations(DM dm, PetscInt *coneOrientations[]) 3730a6dfd86eSKarl Rupp { 3731552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 3732552f7358SJed Brown 3733552f7358SJed Brown PetscFunctionBegin; 3734552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3735552f7358SJed Brown if (coneOrientations) *coneOrientations = mesh->coneOrientations; 3736552f7358SJed Brown PetscFunctionReturn(0); 3737552f7358SJed Brown } 3738552f7358SJed Brown 3739552f7358SJed Brown /******************************** FEM Support **********************************/ 3740552f7358SJed Brown 37417391a63aSMatthew G. Knepley PetscErrorCode DMPlexCreateSpectralClosurePermutation(DM dm, PetscInt point, PetscSection section) 37423194fc30SMatthew G. Knepley { 37437391a63aSMatthew G. Knepley DMLabel label; 37443194fc30SMatthew G. Knepley PetscInt *perm; 37457391a63aSMatthew G. Knepley PetscInt dim, depth, eStart, k, Nf, f, Nc, c, i, j, size = 0, offset = 0, foffset = 0; 37463194fc30SMatthew G. Knepley PetscErrorCode ierr; 37473194fc30SMatthew G. Knepley 37483194fc30SMatthew G. Knepley PetscFunctionBegin; 37497391a63aSMatthew G. Knepley if (point < 0) {ierr = DMPlexGetDepthStratum(dm, 1, &point, NULL);CHKERRQ(ierr);} 37503194fc30SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 37517391a63aSMatthew G. Knepley ierr = DMPlexGetDepthLabel(dm, &label);CHKERRQ(ierr); 37527391a63aSMatthew G. Knepley ierr = DMLabelGetValue(label, point, &depth);CHKERRQ(ierr); 37537391a63aSMatthew G. Knepley if (depth == 1) {eStart = point;} 37547391a63aSMatthew G. Knepley else if (depth == dim) { 37557391a63aSMatthew G. Knepley const PetscInt *cone; 37567391a63aSMatthew G. Knepley 37577391a63aSMatthew G. Knepley ierr = DMPlexGetCone(dm, point, &cone);CHKERRQ(ierr); 37587391a63aSMatthew G. Knepley eStart = cone[0]; 37597391a63aSMatthew G. Knepley } else SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Point %D of depth %D cannot be used to bootstrap spectral ordering", point, depth); 3760e87a4003SBarry Smith if (!section) {ierr = DMGetSection(dm, §ion);CHKERRQ(ierr);} 37613194fc30SMatthew G. Knepley ierr = PetscSectionGetNumFields(section, &Nf);CHKERRQ(ierr); 376289eabcffSMatthew G. Knepley if (dim <= 1) PetscFunctionReturn(0); 37633194fc30SMatthew G. Knepley for (f = 0; f < Nf; ++f) { 37643194fc30SMatthew G. Knepley /* An order k SEM disc has k-1 dofs on an edge */ 37653194fc30SMatthew G. Knepley ierr = PetscSectionGetFieldDof(section, eStart, f, &k);CHKERRQ(ierr); 37663194fc30SMatthew G. Knepley ierr = PetscSectionGetFieldComponents(section, f, &Nc);CHKERRQ(ierr); 37673194fc30SMatthew G. Knepley k = k/Nc + 1; 376889eabcffSMatthew G. Knepley size += PetscPowInt(k+1, dim)*Nc; 37693194fc30SMatthew G. Knepley } 37703194fc30SMatthew G. Knepley ierr = PetscMalloc1(size, &perm);CHKERRQ(ierr); 37713194fc30SMatthew G. Knepley for (f = 0; f < Nf; ++f) { 377289eabcffSMatthew G. Knepley switch (dim) { 377389eabcffSMatthew G. Knepley case 2: 37743194fc30SMatthew G. Knepley /* The original quad closure is oriented clockwise, {f, e_b, e_r, e_t, e_l, v_lb, v_rb, v_tr, v_tl} */ 37753194fc30SMatthew G. Knepley ierr = PetscSectionGetFieldDof(section, eStart, f, &k);CHKERRQ(ierr); 37763194fc30SMatthew G. Knepley ierr = PetscSectionGetFieldComponents(section, f, &Nc);CHKERRQ(ierr); 37773194fc30SMatthew G. Knepley k = k/Nc + 1; 37783194fc30SMatthew G. Knepley /* The SEM order is 37793194fc30SMatthew G. Knepley 37803194fc30SMatthew G. Knepley v_lb, {e_b}, v_rb, 378189eabcffSMatthew G. Knepley e^{(k-1)-i}_l, {f^{i*(k-1)}}, e^i_r, 37823194fc30SMatthew G. Knepley v_lt, reverse {e_t}, v_rt 37833194fc30SMatthew G. Knepley */ 37843194fc30SMatthew G. Knepley { 37853194fc30SMatthew G. Knepley const PetscInt of = 0; 37863194fc30SMatthew G. Knepley const PetscInt oeb = of + PetscSqr(k-1); 37873194fc30SMatthew G. Knepley const PetscInt oer = oeb + (k-1); 37883194fc30SMatthew G. Knepley const PetscInt oet = oer + (k-1); 37893194fc30SMatthew G. Knepley const PetscInt oel = oet + (k-1); 37903194fc30SMatthew G. Knepley const PetscInt ovlb = oel + (k-1); 37913194fc30SMatthew G. Knepley const PetscInt ovrb = ovlb + 1; 37923194fc30SMatthew G. Knepley const PetscInt ovrt = ovrb + 1; 37933194fc30SMatthew G. Knepley const PetscInt ovlt = ovrt + 1; 37943194fc30SMatthew G. Knepley PetscInt o; 37953194fc30SMatthew G. Knepley 37963194fc30SMatthew G. Knepley /* bottom */ 37973194fc30SMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = ovlb*Nc + c + foffset; 37983194fc30SMatthew G. Knepley for (o = oeb; o < oer; ++o) for (c = 0; c < Nc; ++c, ++offset) perm[offset] = o*Nc + c + foffset; 37993194fc30SMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = ovrb*Nc + c + foffset; 38003194fc30SMatthew G. Knepley /* middle */ 38013194fc30SMatthew G. Knepley for (i = 0; i < k-1; ++i) { 38023194fc30SMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = (oel+(k-2)-i)*Nc + c + foffset; 38033194fc30SMatthew G. Knepley for (o = of+(k-1)*i; o < of+(k-1)*(i+1); ++o) for (c = 0; c < Nc; ++c, ++offset) perm[offset] = o*Nc + c + foffset; 38043194fc30SMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = (oer+i)*Nc + c + foffset; 38053194fc30SMatthew G. Knepley } 38063194fc30SMatthew G. Knepley /* top */ 38073194fc30SMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = ovlt*Nc + c + foffset; 38083194fc30SMatthew G. Knepley for (o = oel-1; o >= oet; --o) for (c = 0; c < Nc; ++c, ++offset) perm[offset] = o*Nc + c + foffset; 38093194fc30SMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = ovrt*Nc + c + foffset; 38103194fc30SMatthew G. Knepley foffset = offset; 38113194fc30SMatthew G. Knepley } 381289eabcffSMatthew G. Knepley break; 381389eabcffSMatthew G. Knepley case 3: 381489eabcffSMatthew G. Knepley /* The original hex closure is 381589eabcffSMatthew G. Knepley 381689eabcffSMatthew G. Knepley {c, 381789eabcffSMatthew G. Knepley f_b, f_t, f_f, f_b, f_r, f_l, 381889eabcffSMatthew G. Knepley e_bl, e_bb, e_br, e_bf, e_tf, e_tr, e_tb, e_tl, e_rf, e_lf, e_lb, e_rb, 381989eabcffSMatthew G. Knepley v_blf, v_blb, v_brb, v_brf, v_tlf, v_trf, v_trb, v_tlb} 382089eabcffSMatthew G. Knepley */ 382189eabcffSMatthew G. Knepley ierr = PetscSectionGetFieldDof(section, eStart, f, &k);CHKERRQ(ierr); 382289eabcffSMatthew G. Knepley ierr = PetscSectionGetFieldComponents(section, f, &Nc);CHKERRQ(ierr); 382389eabcffSMatthew G. Knepley k = k/Nc + 1; 382489eabcffSMatthew G. Knepley /* The SEM order is 382589eabcffSMatthew G. Knepley Bottom Slice 382689eabcffSMatthew G. Knepley v_blf, {e^{(k-1)-n}_bf}, v_brf, 382789eabcffSMatthew G. Knepley e^{i}_bl, f^{n*(k-1)+(k-1)-i}_b, e^{(k-1)-i}_br, 382889eabcffSMatthew G. Knepley v_blb, {e_bb}, v_brb, 382989eabcffSMatthew G. Knepley 383089eabcffSMatthew G. Knepley Middle Slice (j) 383189eabcffSMatthew G. Knepley {e^{(k-1)-j}_lf}, {f^{j*(k-1)+n}_f}, e^j_rf, 383289eabcffSMatthew G. Knepley f^{i*(k-1)+j}_l, {c^{(j*(k-1) + i)*(k-1)+n}_t}, f^{j*(k-1)+i}_r, 383389eabcffSMatthew G. Knepley e^j_lb, {f^{j*(k-1)+(k-1)-n}_b}, e^{(k-1)-j}_rb, 383489eabcffSMatthew G. Knepley 383589eabcffSMatthew G. Knepley Top Slice 383689eabcffSMatthew G. Knepley v_tlf, {e_tf}, v_trf, 383789eabcffSMatthew G. Knepley e^{(k-1)-i}_tl, {f^{i*(k-1)}_t}, e^{i}_tr, 383889eabcffSMatthew G. Knepley v_tlb, {e^{(k-1)-n}_tb}, v_trb, 383989eabcffSMatthew G. Knepley */ 384089eabcffSMatthew G. Knepley { 384189eabcffSMatthew G. Knepley const PetscInt oc = 0; 384289eabcffSMatthew G. Knepley const PetscInt ofb = oc + PetscSqr(k-1)*(k-1); 384389eabcffSMatthew G. Knepley const PetscInt oft = ofb + PetscSqr(k-1); 384489eabcffSMatthew G. Knepley const PetscInt off = oft + PetscSqr(k-1); 384589eabcffSMatthew G. Knepley const PetscInt ofk = off + PetscSqr(k-1); 384689eabcffSMatthew G. Knepley const PetscInt ofr = ofk + PetscSqr(k-1); 384789eabcffSMatthew G. Knepley const PetscInt ofl = ofr + PetscSqr(k-1); 384889eabcffSMatthew G. Knepley const PetscInt oebl = ofl + PetscSqr(k-1); 384989eabcffSMatthew G. Knepley const PetscInt oebb = oebl + (k-1); 385089eabcffSMatthew G. Knepley const PetscInt oebr = oebb + (k-1); 385189eabcffSMatthew G. Knepley const PetscInt oebf = oebr + (k-1); 385289eabcffSMatthew G. Knepley const PetscInt oetf = oebf + (k-1); 385389eabcffSMatthew G. Knepley const PetscInt oetr = oetf + (k-1); 385489eabcffSMatthew G. Knepley const PetscInt oetb = oetr + (k-1); 385589eabcffSMatthew G. Knepley const PetscInt oetl = oetb + (k-1); 385689eabcffSMatthew G. Knepley const PetscInt oerf = oetl + (k-1); 385789eabcffSMatthew G. Knepley const PetscInt oelf = oerf + (k-1); 385889eabcffSMatthew G. Knepley const PetscInt oelb = oelf + (k-1); 385989eabcffSMatthew G. Knepley const PetscInt oerb = oelb + (k-1); 386089eabcffSMatthew G. Knepley const PetscInt ovblf = oerb + (k-1); 386189eabcffSMatthew G. Knepley const PetscInt ovblb = ovblf + 1; 386289eabcffSMatthew G. Knepley const PetscInt ovbrb = ovblb + 1; 386389eabcffSMatthew G. Knepley const PetscInt ovbrf = ovbrb + 1; 386489eabcffSMatthew G. Knepley const PetscInt ovtlf = ovbrf + 1; 386589eabcffSMatthew G. Knepley const PetscInt ovtrf = ovtlf + 1; 386689eabcffSMatthew G. Knepley const PetscInt ovtrb = ovtrf + 1; 386789eabcffSMatthew G. Knepley const PetscInt ovtlb = ovtrb + 1; 386889eabcffSMatthew G. Knepley PetscInt o, n; 386989eabcffSMatthew G. Knepley 387089eabcffSMatthew G. Knepley /* Bottom Slice */ 387189eabcffSMatthew G. Knepley /* bottom */ 387289eabcffSMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = ovblf*Nc + c + foffset; 387389eabcffSMatthew G. Knepley for (o = oetf-1; o >= oebf; --o) for (c = 0; c < Nc; ++c, ++offset) perm[offset] = o*Nc + c + foffset; 387489eabcffSMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = ovbrf*Nc + c + foffset; 387589eabcffSMatthew G. Knepley /* middle */ 387689eabcffSMatthew G. Knepley for (i = 0; i < k-1; ++i) { 387789eabcffSMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = (oebl+i)*Nc + c + foffset; 3878316b7f87SMax Rietmann for (n = 0; n < k-1; ++n) {o = ofb+n*(k-1)+i; for (c = 0; c < Nc; ++c, ++offset) perm[offset] = o*Nc + c + foffset;} 387989eabcffSMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = (oebr+(k-2)-i)*Nc + c + foffset; 38803194fc30SMatthew G. Knepley } 388189eabcffSMatthew G. Knepley /* top */ 388289eabcffSMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = ovblb*Nc + c + foffset; 388389eabcffSMatthew G. Knepley for (o = oebb; o < oebr; ++o) for (c = 0; c < Nc; ++c, ++offset) perm[offset] = o*Nc + c + foffset; 388489eabcffSMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = ovbrb*Nc + c + foffset; 388589eabcffSMatthew G. Knepley 388689eabcffSMatthew G. Knepley /* Middle Slice */ 388789eabcffSMatthew G. Knepley for (j = 0; j < k-1; ++j) { 388889eabcffSMatthew G. Knepley /* bottom */ 388989eabcffSMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = (oelf+(k-2)-j)*Nc + c + foffset; 389089eabcffSMatthew G. Knepley for (o = off+j*(k-1); o < off+(j+1)*(k-1); ++o) for (c = 0; c < Nc; ++c, ++offset) perm[offset] = o*Nc + c + foffset; 389189eabcffSMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = (oerf+j)*Nc + c + foffset; 389289eabcffSMatthew G. Knepley /* middle */ 389389eabcffSMatthew G. Knepley for (i = 0; i < k-1; ++i) { 389489eabcffSMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = (ofl+i*(k-1)+j)*Nc + c + foffset; 389589eabcffSMatthew G. Knepley for (n = 0; n < k-1; ++n) for (c = 0; c < Nc; ++c, ++offset) perm[offset] = (oc+(j*(k-1)+i)*(k-1)+n)*Nc + c + foffset; 389689eabcffSMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = (ofr+j*(k-1)+i)*Nc + c + foffset; 389789eabcffSMatthew G. Knepley } 389889eabcffSMatthew G. Knepley /* top */ 389989eabcffSMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = (oelb+j)*Nc + c + foffset; 390089eabcffSMatthew G. Knepley for (o = ofk+j*(k-1)+(k-2); o >= ofk+j*(k-1); --o) for (c = 0; c < Nc; ++c, ++offset) perm[offset] = o*Nc + c + foffset; 390189eabcffSMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = (oerb+(k-2)-j)*Nc + c + foffset; 390289eabcffSMatthew G. Knepley } 390389eabcffSMatthew G. Knepley 390489eabcffSMatthew G. Knepley /* Top Slice */ 390589eabcffSMatthew G. Knepley /* bottom */ 390689eabcffSMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = ovtlf*Nc + c + foffset; 390789eabcffSMatthew G. Knepley for (o = oetf; o < oetr; ++o) for (c = 0; c < Nc; ++c, ++offset) perm[offset] = o*Nc + c + foffset; 390889eabcffSMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = ovtrf*Nc + c + foffset; 390989eabcffSMatthew G. Knepley /* middle */ 391089eabcffSMatthew G. Knepley for (i = 0; i < k-1; ++i) { 391189eabcffSMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = (oetl+(k-2)-i)*Nc + c + foffset; 391289eabcffSMatthew G. Knepley for (n = 0; n < k-1; ++n) for (c = 0; c < Nc; ++c, ++offset) perm[offset] = (oft+i*(k-1)+n)*Nc + c + foffset; 391389eabcffSMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = (oetr+i)*Nc + c + foffset; 391489eabcffSMatthew G. Knepley } 391589eabcffSMatthew G. Knepley /* top */ 391689eabcffSMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = ovtlb*Nc + c + foffset; 391789eabcffSMatthew G. Knepley for (o = oetl-1; o >= oetb; --o) for (c = 0; c < Nc; ++c, ++offset) perm[offset] = o*Nc + c + foffset; 391889eabcffSMatthew G. Knepley for (c = 0; c < Nc; ++c, ++offset) perm[offset] = ovtrb*Nc + c + foffset; 391989eabcffSMatthew G. Knepley 392089eabcffSMatthew G. Knepley foffset = offset; 392189eabcffSMatthew G. Knepley } 392289eabcffSMatthew G. Knepley break; 392389eabcffSMatthew G. Knepley default: SETERRQ1(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_OUTOFRANGE, "No spectral ordering for dimension %D", dim); 392489eabcffSMatthew G. Knepley } 392589eabcffSMatthew G. Knepley } 392689eabcffSMatthew G. Knepley if (offset != size) SETERRQ2(PetscObjectComm((PetscObject) dm), PETSC_ERR_PLIB, "Number of permutation entries %D != %D", offset, size); 39273194fc30SMatthew G. Knepley /* Check permutation */ 39283194fc30SMatthew G. Knepley { 39293194fc30SMatthew G. Knepley PetscInt *check; 39303194fc30SMatthew G. Knepley 39313194fc30SMatthew G. Knepley ierr = PetscMalloc1(size, &check);CHKERRQ(ierr); 39323194fc30SMatthew G. Knepley for (i = 0; i < size; ++i) {check[i] = -1; if (perm[i] < 0 || perm[i] >= size) SETERRQ2(PetscObjectComm((PetscObject) dm), PETSC_ERR_PLIB, "Invalid permutation index p[%D] = %D", i, perm[i]);} 39333194fc30SMatthew G. Knepley for (i = 0; i < size; ++i) check[perm[i]] = i; 39343194fc30SMatthew G. Knepley for (i = 0; i < size; ++i) {if (check[i] < 0) SETERRQ1(PetscObjectComm((PetscObject) dm), PETSC_ERR_PLIB, "Missing permutation index %D", i);} 39353194fc30SMatthew G. Knepley ierr = PetscFree(check);CHKERRQ(ierr); 39363194fc30SMatthew G. Knepley } 39371fdd32a2SMatthew G. Knepley ierr = PetscSectionSetClosurePermutation_Internal(section, (PetscObject) dm, size, PETSC_OWN_POINTER, perm);CHKERRQ(ierr); 39383194fc30SMatthew G. Knepley PetscFunctionReturn(0); 39393194fc30SMatthew G. Knepley } 39403194fc30SMatthew G. Knepley 3941e071409bSToby Isaac PetscErrorCode DMPlexGetPointDualSpaceFEM(DM dm, PetscInt point, PetscInt field, PetscDualSpace *dspace) 3942e071409bSToby Isaac { 3943e071409bSToby Isaac PetscDS prob; 3944e071409bSToby Isaac PetscInt depth, Nf, h; 3945e071409bSToby Isaac DMLabel label; 3946e071409bSToby Isaac PetscErrorCode ierr; 3947e071409bSToby Isaac 3948e071409bSToby Isaac PetscFunctionBeginHot; 3949e071409bSToby Isaac prob = dm->prob; 3950e071409bSToby Isaac Nf = prob->Nf; 3951e071409bSToby Isaac label = dm->depthLabel; 3952e071409bSToby Isaac *dspace = NULL; 3953e071409bSToby Isaac if (field < Nf) { 3954e071409bSToby Isaac PetscObject disc = prob->disc[field]; 3955e071409bSToby Isaac 3956e071409bSToby Isaac if (disc->classid == PETSCFE_CLASSID) { 3957e071409bSToby Isaac PetscDualSpace dsp; 3958e071409bSToby Isaac 3959e071409bSToby Isaac ierr = PetscFEGetDualSpace((PetscFE)disc,&dsp);CHKERRQ(ierr); 3960e071409bSToby Isaac ierr = DMLabelGetNumValues(label,&depth);CHKERRQ(ierr); 3961e071409bSToby Isaac ierr = DMLabelGetValue(label,point,&h);CHKERRQ(ierr); 3962e071409bSToby Isaac h = depth - 1 - h; 3963e071409bSToby Isaac if (h) { 3964e071409bSToby Isaac ierr = PetscDualSpaceGetHeightSubspace(dsp,h,dspace);CHKERRQ(ierr); 3965e071409bSToby Isaac } else { 3966e071409bSToby Isaac *dspace = dsp; 3967e071409bSToby Isaac } 3968e071409bSToby Isaac } 3969e071409bSToby Isaac } 3970e071409bSToby Isaac PetscFunctionReturn(0); 3971e071409bSToby Isaac } 3972e071409bSToby Isaac 3973e071409bSToby Isaac 39741a271a75SMatthew G. Knepley PETSC_STATIC_INLINE PetscErrorCode DMPlexVecGetClosure_Depth1_Static(DM dm, PetscSection section, Vec v, PetscInt point, PetscInt *csize, PetscScalar *values[]) 3975a6dfd86eSKarl Rupp { 3976552f7358SJed Brown PetscScalar *array, *vArray; 3977d9917b9dSMatthew G. Knepley const PetscInt *cone, *coneO; 39781a271a75SMatthew G. Knepley PetscInt pStart, pEnd, p, numPoints, size = 0, offset = 0; 3979552f7358SJed Brown PetscErrorCode ierr; 3980552f7358SJed Brown 39811b406b76SMatthew G. Knepley PetscFunctionBeginHot; 39822a3aaacfSMatthew G. Knepley ierr = PetscSectionGetChart(section, &pStart, &pEnd);CHKERRQ(ierr); 39835a1bb5cfSMatthew G. Knepley ierr = DMPlexGetConeSize(dm, point, &numPoints);CHKERRQ(ierr); 39845a1bb5cfSMatthew G. Knepley ierr = DMPlexGetCone(dm, point, &cone);CHKERRQ(ierr); 39855a1bb5cfSMatthew G. Knepley ierr = DMPlexGetConeOrientation(dm, point, &coneO);CHKERRQ(ierr); 39863f7cbbe7SMatthew G. Knepley if (!values || !*values) { 39879df71ca4SMatthew G. Knepley if ((point >= pStart) && (point < pEnd)) { 39889df71ca4SMatthew G. Knepley PetscInt dof; 3989d9917b9dSMatthew G. Knepley 39909df71ca4SMatthew G. Knepley ierr = PetscSectionGetDof(section, point, &dof);CHKERRQ(ierr); 39919df71ca4SMatthew G. Knepley size += dof; 39929df71ca4SMatthew G. Knepley } 39939df71ca4SMatthew G. Knepley for (p = 0; p < numPoints; ++p) { 39949df71ca4SMatthew G. Knepley const PetscInt cp = cone[p]; 39952a3aaacfSMatthew G. Knepley PetscInt dof; 39965a1bb5cfSMatthew G. Knepley 39975a1bb5cfSMatthew G. Knepley if ((cp < pStart) || (cp >= pEnd)) continue; 39982a3aaacfSMatthew G. Knepley ierr = PetscSectionGetDof(section, cp, &dof);CHKERRQ(ierr); 39995a1bb5cfSMatthew G. Knepley size += dof; 40005a1bb5cfSMatthew G. Knepley } 40013f7cbbe7SMatthew G. Knepley if (!values) { 40023f7cbbe7SMatthew G. Knepley if (csize) *csize = size; 40033f7cbbe7SMatthew G. Knepley PetscFunctionReturn(0); 40043f7cbbe7SMatthew G. Knepley } 400569291d52SBarry Smith ierr = DMGetWorkArray(dm, size, MPIU_SCALAR, &array);CHKERRQ(ierr); 4006982e9ed1SMatthew G. Knepley } else { 4007982e9ed1SMatthew G. Knepley array = *values; 4008982e9ed1SMatthew G. Knepley } 40099df71ca4SMatthew G. Knepley size = 0; 40105a1bb5cfSMatthew G. Knepley ierr = VecGetArray(v, &vArray);CHKERRQ(ierr); 40119df71ca4SMatthew G. Knepley if ((point >= pStart) && (point < pEnd)) { 40129df71ca4SMatthew G. Knepley PetscInt dof, off, d; 40139df71ca4SMatthew G. Knepley PetscScalar *varr; 4014d9917b9dSMatthew G. Knepley 40159df71ca4SMatthew G. Knepley ierr = PetscSectionGetDof(section, point, &dof);CHKERRQ(ierr); 40169df71ca4SMatthew G. Knepley ierr = PetscSectionGetOffset(section, point, &off);CHKERRQ(ierr); 40179df71ca4SMatthew G. Knepley varr = &vArray[off]; 40181a271a75SMatthew G. Knepley for (d = 0; d < dof; ++d, ++offset) { 40191a271a75SMatthew G. Knepley array[offset] = varr[d]; 40209df71ca4SMatthew G. Knepley } 40219df71ca4SMatthew G. Knepley size += dof; 40229df71ca4SMatthew G. Knepley } 40239df71ca4SMatthew G. Knepley for (p = 0; p < numPoints; ++p) { 40249df71ca4SMatthew G. Knepley const PetscInt cp = cone[p]; 40259df71ca4SMatthew G. Knepley PetscInt o = coneO[p]; 40265a1bb5cfSMatthew G. Knepley PetscInt dof, off, d; 40275a1bb5cfSMatthew G. Knepley PetscScalar *varr; 40285a1bb5cfSMatthew G. Knepley 402952ed52e8SMatthew G. Knepley if ((cp < pStart) || (cp >= pEnd)) continue; 40305a1bb5cfSMatthew G. Knepley ierr = PetscSectionGetDof(section, cp, &dof);CHKERRQ(ierr); 40315a1bb5cfSMatthew G. Knepley ierr = PetscSectionGetOffset(section, cp, &off);CHKERRQ(ierr); 40325a1bb5cfSMatthew G. Knepley varr = &vArray[off]; 40335a1bb5cfSMatthew G. Knepley if (o >= 0) { 40341a271a75SMatthew G. Knepley for (d = 0; d < dof; ++d, ++offset) { 40351a271a75SMatthew G. Knepley array[offset] = varr[d]; 40365a1bb5cfSMatthew G. Knepley } 40375a1bb5cfSMatthew G. Knepley } else { 40381a271a75SMatthew G. Knepley for (d = dof-1; d >= 0; --d, ++offset) { 40391a271a75SMatthew G. Knepley array[offset] = varr[d]; 40405a1bb5cfSMatthew G. Knepley } 40415a1bb5cfSMatthew G. Knepley } 40429df71ca4SMatthew G. Knepley size += dof; 40435a1bb5cfSMatthew G. Knepley } 40445a1bb5cfSMatthew G. Knepley ierr = VecRestoreArray(v, &vArray);CHKERRQ(ierr); 40459df71ca4SMatthew G. Knepley if (!*values) { 40465a1bb5cfSMatthew G. Knepley if (csize) *csize = size; 40475a1bb5cfSMatthew G. Knepley *values = array; 40489df71ca4SMatthew G. Knepley } else { 40498ccfff9cSToby Isaac if (size > *csize) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Size of input array %D < actual size %D", *csize, size); 40508c312ff3SMatthew G. Knepley *csize = size; 40519df71ca4SMatthew G. Knepley } 40525a1bb5cfSMatthew G. Knepley PetscFunctionReturn(0); 40535a1bb5cfSMatthew G. Knepley } 4054d9917b9dSMatthew G. Knepley 4055923c78e0SToby Isaac static PetscErrorCode DMPlexGetCompressedClosure(DM dm, PetscSection section, PetscInt point, PetscInt *numPoints, PetscInt **points, PetscSection *clSec, IS *clPoints, const PetscInt **clp) 4056923c78e0SToby Isaac { 4057923c78e0SToby Isaac const PetscInt *cla; 4058923c78e0SToby Isaac PetscInt np, *pts = NULL; 4059923c78e0SToby Isaac PetscErrorCode ierr; 4060923c78e0SToby Isaac 4061923c78e0SToby Isaac PetscFunctionBeginHot; 4062923c78e0SToby Isaac ierr = PetscSectionGetClosureIndex(section, (PetscObject) dm, clSec, clPoints);CHKERRQ(ierr); 4063923c78e0SToby Isaac if (!*clPoints) { 4064923c78e0SToby Isaac PetscInt pStart, pEnd, p, q; 4065923c78e0SToby Isaac 4066923c78e0SToby Isaac ierr = PetscSectionGetChart(section, &pStart, &pEnd);CHKERRQ(ierr); 4067923c78e0SToby Isaac ierr = DMPlexGetTransitiveClosure(dm, point, PETSC_TRUE, &np, &pts);CHKERRQ(ierr); 4068923c78e0SToby Isaac /* Compress out points not in the section */ 4069923c78e0SToby Isaac for (p = 0, q = 0; p < np; p++) { 4070923c78e0SToby Isaac PetscInt r = pts[2*p]; 4071923c78e0SToby Isaac if ((r >= pStart) && (r < pEnd)) { 4072923c78e0SToby Isaac pts[q*2] = r; 4073923c78e0SToby Isaac pts[q*2+1] = pts[2*p+1]; 4074923c78e0SToby Isaac ++q; 4075923c78e0SToby Isaac } 4076923c78e0SToby Isaac } 4077923c78e0SToby Isaac np = q; 4078923c78e0SToby Isaac cla = NULL; 4079923c78e0SToby Isaac } else { 4080923c78e0SToby Isaac PetscInt dof, off; 4081923c78e0SToby Isaac 4082923c78e0SToby Isaac ierr = PetscSectionGetDof(*clSec, point, &dof);CHKERRQ(ierr); 4083923c78e0SToby Isaac ierr = PetscSectionGetOffset(*clSec, point, &off);CHKERRQ(ierr); 4084923c78e0SToby Isaac ierr = ISGetIndices(*clPoints, &cla);CHKERRQ(ierr); 4085923c78e0SToby Isaac np = dof/2; 4086923c78e0SToby Isaac pts = (PetscInt *) &cla[off]; 4087923c78e0SToby Isaac } 4088923c78e0SToby Isaac *numPoints = np; 4089923c78e0SToby Isaac *points = pts; 4090923c78e0SToby Isaac *clp = cla; 4091923c78e0SToby Isaac 4092923c78e0SToby Isaac PetscFunctionReturn(0); 4093923c78e0SToby Isaac } 4094923c78e0SToby Isaac 4095923c78e0SToby Isaac static PetscErrorCode DMPlexRestoreCompressedClosure(DM dm, PetscSection section, PetscInt point, PetscInt *numPoints, PetscInt **points, PetscSection *clSec, IS *clPoints, const PetscInt **clp) 4096923c78e0SToby Isaac { 4097923c78e0SToby Isaac PetscErrorCode ierr; 4098923c78e0SToby Isaac 4099923c78e0SToby Isaac PetscFunctionBeginHot; 4100923c78e0SToby Isaac if (!*clPoints) { 4101923c78e0SToby Isaac ierr = DMPlexRestoreTransitiveClosure(dm, point, PETSC_TRUE, numPoints, points);CHKERRQ(ierr); 4102923c78e0SToby Isaac } else { 4103923c78e0SToby Isaac ierr = ISRestoreIndices(*clPoints, clp);CHKERRQ(ierr); 4104923c78e0SToby Isaac } 4105923c78e0SToby Isaac *numPoints = 0; 4106923c78e0SToby Isaac *points = NULL; 4107923c78e0SToby Isaac *clSec = NULL; 4108923c78e0SToby Isaac *clPoints = NULL; 4109923c78e0SToby Isaac *clp = NULL; 4110923c78e0SToby Isaac PetscFunctionReturn(0); 4111923c78e0SToby Isaac } 4112923c78e0SToby Isaac 411397e99dd9SToby Isaac PETSC_STATIC_INLINE PetscErrorCode DMPlexVecGetClosure_Static(DM dm, PetscSection section, PetscInt numPoints, const PetscInt points[], const PetscInt clperm[], const PetscScalar vArray[], PetscInt *size, PetscScalar array[]) 41141a271a75SMatthew G. Knepley { 41151a271a75SMatthew G. Knepley PetscInt offset = 0, p; 411697e99dd9SToby Isaac const PetscInt **perms = NULL; 411797e99dd9SToby Isaac const PetscScalar **flips = NULL; 41181a271a75SMatthew G. Knepley PetscErrorCode ierr; 41191a271a75SMatthew G. Knepley 41201a271a75SMatthew G. Knepley PetscFunctionBeginHot; 4121fe02ba77SJed Brown *size = 0; 412297e99dd9SToby Isaac ierr = PetscSectionGetPointSyms(section,numPoints,points,&perms,&flips);CHKERRQ(ierr); 412397e99dd9SToby Isaac for (p = 0; p < numPoints; p++) { 412497e99dd9SToby Isaac const PetscInt point = points[2*p]; 412597e99dd9SToby Isaac const PetscInt *perm = perms ? perms[p] : NULL; 412697e99dd9SToby Isaac const PetscScalar *flip = flips ? flips[p] : NULL; 41271a271a75SMatthew G. Knepley PetscInt dof, off, d; 41281a271a75SMatthew G. Knepley const PetscScalar *varr; 41291a271a75SMatthew G. Knepley 41301a271a75SMatthew G. Knepley ierr = PetscSectionGetDof(section, point, &dof);CHKERRQ(ierr); 41311a271a75SMatthew G. Knepley ierr = PetscSectionGetOffset(section, point, &off);CHKERRQ(ierr); 41321a271a75SMatthew G. Knepley varr = &vArray[off]; 413397e99dd9SToby Isaac if (clperm) { 413497e99dd9SToby Isaac if (perm) { 413597e99dd9SToby Isaac for (d = 0; d < dof; d++) array[clperm[offset + perm[d]]] = varr[d]; 41361a271a75SMatthew G. Knepley } else { 413797e99dd9SToby Isaac for (d = 0; d < dof; d++) array[clperm[offset + d ]] = varr[d]; 413897e99dd9SToby Isaac } 413997e99dd9SToby Isaac if (flip) { 414097e99dd9SToby Isaac for (d = 0; d < dof; d++) array[clperm[offset + d ]] *= flip[d]; 414197e99dd9SToby Isaac } 414297e99dd9SToby Isaac } else { 414397e99dd9SToby Isaac if (perm) { 414497e99dd9SToby Isaac for (d = 0; d < dof; d++) array[offset + perm[d]] = varr[d]; 414597e99dd9SToby Isaac } else { 414697e99dd9SToby Isaac for (d = 0; d < dof; d++) array[offset + d ] = varr[d]; 414797e99dd9SToby Isaac } 414897e99dd9SToby Isaac if (flip) { 414997e99dd9SToby Isaac for (d = 0; d < dof; d++) array[offset + d ] *= flip[d]; 41501a271a75SMatthew G. Knepley } 41511a271a75SMatthew G. Knepley } 415297e99dd9SToby Isaac offset += dof; 415397e99dd9SToby Isaac } 415497e99dd9SToby Isaac ierr = PetscSectionRestorePointSyms(section,numPoints,points,&perms,&flips);CHKERRQ(ierr); 41551a271a75SMatthew G. Knepley *size = offset; 41561a271a75SMatthew G. Knepley PetscFunctionReturn(0); 41571a271a75SMatthew G. Knepley } 41581a271a75SMatthew G. Knepley 415997e99dd9SToby Isaac PETSC_STATIC_INLINE PetscErrorCode DMPlexVecGetClosure_Fields_Static(DM dm, PetscSection section, PetscInt numPoints, const PetscInt points[], PetscInt numFields, const PetscInt clperm[], const PetscScalar vArray[], PetscInt *size, PetscScalar array[]) 41601a271a75SMatthew G. Knepley { 41611a271a75SMatthew G. Knepley PetscInt offset = 0, f; 41621a271a75SMatthew G. Knepley PetscErrorCode ierr; 41631a271a75SMatthew G. Knepley 41641a271a75SMatthew G. Knepley PetscFunctionBeginHot; 4165fe02ba77SJed Brown *size = 0; 41661a271a75SMatthew G. Knepley for (f = 0; f < numFields; ++f) { 416797e99dd9SToby Isaac PetscInt p; 416897e99dd9SToby Isaac const PetscInt **perms = NULL; 416997e99dd9SToby Isaac const PetscScalar **flips = NULL; 41701a271a75SMatthew G. Knepley 417197e99dd9SToby Isaac ierr = PetscSectionGetFieldPointSyms(section,f,numPoints,points,&perms,&flips);CHKERRQ(ierr); 417297e99dd9SToby Isaac for (p = 0; p < numPoints; p++) { 417397e99dd9SToby Isaac const PetscInt point = points[2*p]; 417497e99dd9SToby Isaac PetscInt fdof, foff, b; 41751a271a75SMatthew G. Knepley const PetscScalar *varr; 417697e99dd9SToby Isaac const PetscInt *perm = perms ? perms[p] : NULL; 417797e99dd9SToby Isaac const PetscScalar *flip = flips ? flips[p] : NULL; 41781a271a75SMatthew G. Knepley 41791a271a75SMatthew G. Knepley ierr = PetscSectionGetFieldDof(section, point, f, &fdof);CHKERRQ(ierr); 41801a271a75SMatthew G. Knepley ierr = PetscSectionGetFieldOffset(section, point, f, &foff);CHKERRQ(ierr); 41811a271a75SMatthew G. Knepley varr = &vArray[foff]; 418297e99dd9SToby Isaac if (clperm) { 418397e99dd9SToby Isaac if (perm) {for (b = 0; b < fdof; b++) {array[clperm[offset + perm[b]]] = varr[b];}} 418497e99dd9SToby Isaac else {for (b = 0; b < fdof; b++) {array[clperm[offset + b ]] = varr[b];}} 418597e99dd9SToby Isaac if (flip) {for (b = 0; b < fdof; b++) {array[clperm[offset + b ]] *= flip[b];}} 41861a271a75SMatthew G. Knepley } else { 418797e99dd9SToby Isaac if (perm) {for (b = 0; b < fdof; b++) {array[offset + perm[b]] = varr[b];}} 418897e99dd9SToby Isaac else {for (b = 0; b < fdof; b++) {array[offset + b ] = varr[b];}} 418997e99dd9SToby Isaac if (flip) {for (b = 0; b < fdof; b++) {array[offset + b ] *= flip[b];}} 41901a271a75SMatthew G. Knepley } 419197e99dd9SToby Isaac offset += fdof; 41921a271a75SMatthew G. Knepley } 419397e99dd9SToby Isaac ierr = PetscSectionRestoreFieldPointSyms(section,f,numPoints,points,&perms,&flips);CHKERRQ(ierr); 41941a271a75SMatthew G. Knepley } 41951a271a75SMatthew G. Knepley *size = offset; 41961a271a75SMatthew G. Knepley PetscFunctionReturn(0); 41971a271a75SMatthew G. Knepley } 41981a271a75SMatthew G. Knepley 4199552f7358SJed Brown /*@C 4200552f7358SJed Brown DMPlexVecGetClosure - Get an array of the values on the closure of 'point' 4201552f7358SJed Brown 4202552f7358SJed Brown Not collective 4203552f7358SJed Brown 4204552f7358SJed Brown Input Parameters: 4205552f7358SJed Brown + dm - The DM 4206552f7358SJed Brown . section - The section describing the layout in v, or NULL to use the default section 4207552f7358SJed Brown . v - The local vector 420822c1ee49SMatthew G. Knepley . point - The point in the DM 420922c1ee49SMatthew G. Knepley . csize - The size of the input values array, or NULL 421022c1ee49SMatthew G. Knepley - values - An array to use for the values, or NULL to have it allocated automatically 4211552f7358SJed Brown 4212552f7358SJed Brown Output Parameters: 421322c1ee49SMatthew G. Knepley + csize - The number of values in the closure 421422c1ee49SMatthew G. Knepley - values - The array of values. If the user provided NULL, it is a borrowed array and should not be freed 421522c1ee49SMatthew G. Knepley 421622c1ee49SMatthew G. Knepley $ Note that DMPlexVecGetClosure/DMPlexVecRestoreClosure only allocates the values array if it set to NULL in the 421722c1ee49SMatthew G. Knepley $ calling function. This is because DMPlexVecGetClosure() is typically called in the inner loop of a Vec or Mat 421822c1ee49SMatthew G. Knepley $ assembly function, and a user may already have allocated storage for this operation. 421922c1ee49SMatthew G. Knepley $ 422022c1ee49SMatthew G. Knepley $ A typical use could be 422122c1ee49SMatthew G. Knepley $ 422222c1ee49SMatthew G. Knepley $ values = NULL; 422322c1ee49SMatthew G. Knepley $ ierr = DMPlexVecGetClosure(dm, NULL, v, p, &clSize, &values);CHKERRQ(ierr); 422422c1ee49SMatthew G. Knepley $ for (cl = 0; cl < clSize; ++cl) { 422522c1ee49SMatthew G. Knepley $ <Compute on closure> 422622c1ee49SMatthew G. Knepley $ } 422722c1ee49SMatthew G. Knepley $ ierr = DMPlexVecRestoreClosure(dm, NULL, v, p, &clSize, &values);CHKERRQ(ierr); 422822c1ee49SMatthew G. Knepley $ 422922c1ee49SMatthew G. Knepley $ or 423022c1ee49SMatthew G. Knepley $ 423122c1ee49SMatthew G. Knepley $ PetscMalloc1(clMaxSize, &values); 423222c1ee49SMatthew G. Knepley $ for (p = pStart; p < pEnd; ++p) { 423322c1ee49SMatthew G. Knepley $ clSize = clMaxSize; 423422c1ee49SMatthew G. Knepley $ ierr = DMPlexVecGetClosure(dm, NULL, v, p, &clSize, &values);CHKERRQ(ierr); 423522c1ee49SMatthew G. Knepley $ for (cl = 0; cl < clSize; ++cl) { 423622c1ee49SMatthew G. Knepley $ <Compute on closure> 423722c1ee49SMatthew G. Knepley $ } 423822c1ee49SMatthew G. Knepley $ } 423922c1ee49SMatthew G. Knepley $ PetscFree(values); 4240552f7358SJed Brown 4241552f7358SJed Brown Fortran Notes: 4242552f7358SJed Brown Since it returns an array, this routine is only available in Fortran 90, and you must 4243552f7358SJed Brown include petsc.h90 in your code. 4244552f7358SJed Brown 4245552f7358SJed Brown The csize argument is not present in the Fortran 90 binding since it is internal to the array. 4246552f7358SJed Brown 4247552f7358SJed Brown Level: intermediate 4248552f7358SJed Brown 4249552f7358SJed Brown .seealso DMPlexVecRestoreClosure(), DMPlexVecSetClosure(), DMPlexMatSetClosure() 4250552f7358SJed Brown @*/ 4251552f7358SJed Brown PetscErrorCode DMPlexVecGetClosure(DM dm, PetscSection section, Vec v, PetscInt point, PetscInt *csize, PetscScalar *values[]) 4252552f7358SJed Brown { 4253552f7358SJed Brown PetscSection clSection; 4254d9917b9dSMatthew G. Knepley IS clPoints; 42558a84db2dSMatthew G. Knepley PetscScalar *array; 42568a84db2dSMatthew G. Knepley const PetscScalar *vArray; 4257552f7358SJed Brown PetscInt *points = NULL; 42588f3be42fSMatthew G. Knepley const PetscInt *clp, *perm; 42591a271a75SMatthew G. Knepley PetscInt depth, numFields, numPoints, size; 4260552f7358SJed Brown PetscErrorCode ierr; 4261552f7358SJed Brown 4262d9917b9dSMatthew G. Knepley PetscFunctionBeginHot; 4263552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 4264e87a4003SBarry Smith if (!section) {ierr = DMGetSection(dm, §ion);CHKERRQ(ierr);} 42651a271a75SMatthew G. Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 2); 42661a271a75SMatthew G. Knepley PetscValidHeaderSpecific(v, VEC_CLASSID, 3); 4267552f7358SJed Brown ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 4268552f7358SJed Brown ierr = PetscSectionGetNumFields(section, &numFields);CHKERRQ(ierr); 4269552f7358SJed Brown if (depth == 1 && numFields < 2) { 42701a271a75SMatthew G. Knepley ierr = DMPlexVecGetClosure_Depth1_Static(dm, section, v, point, csize, values);CHKERRQ(ierr); 4271552f7358SJed Brown PetscFunctionReturn(0); 4272552f7358SJed Brown } 42731a271a75SMatthew G. Knepley /* Get points */ 4274923c78e0SToby Isaac ierr = DMPlexGetCompressedClosure(dm,section,point,&numPoints,&points,&clSection,&clPoints,&clp);CHKERRQ(ierr); 42751fdd32a2SMatthew G. Knepley ierr = PetscSectionGetClosureInversePermutation_Internal(section, (PetscObject) dm, NULL, &perm);CHKERRQ(ierr); 42761a271a75SMatthew G. Knepley /* Get array */ 4277bd6c0d32SMatthew G. Knepley if (!values || !*values) { 42781a271a75SMatthew G. Knepley PetscInt asize = 0, dof, p; 4279552f7358SJed Brown 42801a271a75SMatthew G. Knepley for (p = 0; p < numPoints*2; p += 2) { 4281552f7358SJed Brown ierr = PetscSectionGetDof(section, points[p], &dof);CHKERRQ(ierr); 42821a271a75SMatthew G. Knepley asize += dof; 4283552f7358SJed Brown } 4284bd6c0d32SMatthew G. Knepley if (!values) { 4285923c78e0SToby Isaac ierr = DMPlexRestoreCompressedClosure(dm,section,point,&numPoints,&points,&clSection,&clPoints,&clp);CHKERRQ(ierr); 42861a271a75SMatthew G. Knepley if (csize) *csize = asize; 4287bd6c0d32SMatthew G. Knepley PetscFunctionReturn(0); 4288bd6c0d32SMatthew G. Knepley } 428969291d52SBarry Smith ierr = DMGetWorkArray(dm, asize, MPIU_SCALAR, &array);CHKERRQ(ierr); 4290d0f6b257SMatthew G. Knepley } else { 4291d0f6b257SMatthew G. Knepley array = *values; 4292d0f6b257SMatthew G. Knepley } 42938a84db2dSMatthew G. Knepley ierr = VecGetArrayRead(v, &vArray);CHKERRQ(ierr); 42941a271a75SMatthew G. Knepley /* Get values */ 429597e99dd9SToby Isaac if (numFields > 0) {ierr = DMPlexVecGetClosure_Fields_Static(dm, section, numPoints, points, numFields, perm, vArray, &size, array);CHKERRQ(ierr);} 429697e99dd9SToby Isaac else {ierr = DMPlexVecGetClosure_Static(dm, section, numPoints, points, perm, vArray, &size, array);CHKERRQ(ierr);} 42971a271a75SMatthew G. Knepley /* Cleanup points */ 4298923c78e0SToby Isaac ierr = DMPlexRestoreCompressedClosure(dm,section,point,&numPoints,&points,&clSection,&clPoints,&clp);CHKERRQ(ierr); 42991a271a75SMatthew G. Knepley /* Cleanup array */ 43008a84db2dSMatthew G. Knepley ierr = VecRestoreArrayRead(v, &vArray);CHKERRQ(ierr); 4301d0f6b257SMatthew G. Knepley if (!*values) { 4302552f7358SJed Brown if (csize) *csize = size; 4303552f7358SJed Brown *values = array; 4304d0f6b257SMatthew G. Knepley } else { 4305f347f43bSBarry Smith if (size > *csize) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Size of input array %D < actual size %D", *csize, size); 4306d0f6b257SMatthew G. Knepley *csize = size; 4307d0f6b257SMatthew G. Knepley } 4308552f7358SJed Brown PetscFunctionReturn(0); 4309552f7358SJed Brown } 4310552f7358SJed Brown 4311552f7358SJed Brown /*@C 4312552f7358SJed Brown DMPlexVecRestoreClosure - Restore the array of the values on the closure of 'point' 4313552f7358SJed Brown 4314552f7358SJed Brown Not collective 4315552f7358SJed Brown 4316552f7358SJed Brown Input Parameters: 4317552f7358SJed Brown + dm - The DM 43180298fd71SBarry Smith . section - The section describing the layout in v, or NULL to use the default section 4319552f7358SJed Brown . v - The local vector 4320eaf898f9SPatrick Sanan . point - The point in the DM 43210298fd71SBarry Smith . csize - The number of values in the closure, or NULL 4322552f7358SJed Brown - values - The array of values, which is a borrowed array and should not be freed 4323552f7358SJed Brown 432422c1ee49SMatthew G. Knepley Note that the array values are discarded and not copied back into v. In order to copy values back to v, use DMPlexVecSetClosure() 432522c1ee49SMatthew G. Knepley 43263813dfbdSMatthew G Knepley Fortran Notes: 43273813dfbdSMatthew G Knepley Since it returns an array, this routine is only available in Fortran 90, and you must 43283813dfbdSMatthew G Knepley include petsc.h90 in your code. 43293813dfbdSMatthew G Knepley 43303813dfbdSMatthew G Knepley The csize argument is not present in the Fortran 90 binding since it is internal to the array. 43313813dfbdSMatthew G Knepley 4332552f7358SJed Brown Level: intermediate 4333552f7358SJed Brown 4334552f7358SJed Brown .seealso DMPlexVecGetClosure(), DMPlexVecSetClosure(), DMPlexMatSetClosure() 4335552f7358SJed Brown @*/ 43367c1f9639SMatthew G Knepley PetscErrorCode DMPlexVecRestoreClosure(DM dm, PetscSection section, Vec v, PetscInt point, PetscInt *csize, PetscScalar *values[]) 4337a6dfd86eSKarl Rupp { 4338552f7358SJed Brown PetscInt size = 0; 4339552f7358SJed Brown PetscErrorCode ierr; 4340552f7358SJed Brown 4341552f7358SJed Brown PetscFunctionBegin; 4342552f7358SJed Brown /* Should work without recalculating size */ 434369291d52SBarry Smith ierr = DMRestoreWorkArray(dm, size, MPIU_SCALAR, (void*) values);CHKERRQ(ierr); 4344c9fdaa05SMatthew G. Knepley *values = NULL; 4345552f7358SJed Brown PetscFunctionReturn(0); 4346552f7358SJed Brown } 4347552f7358SJed Brown 4348552f7358SJed Brown PETSC_STATIC_INLINE void add (PetscScalar *x, PetscScalar y) {*x += y;} 4349552f7358SJed Brown PETSC_STATIC_INLINE void insert(PetscScalar *x, PetscScalar y) {*x = y;} 4350552f7358SJed Brown 435197e99dd9SToby Isaac PETSC_STATIC_INLINE PetscErrorCode updatePoint_private(PetscSection section, PetscInt point, PetscInt dof, void (*fuse)(PetscScalar*, PetscScalar), PetscBool setBC, const PetscInt perm[], const PetscScalar flip[], const PetscInt clperm[], const PetscScalar values[], PetscInt offset, PetscScalar array[]) 4352552f7358SJed Brown { 4353552f7358SJed Brown PetscInt cdof; /* The number of constraints on this point */ 4354552f7358SJed Brown const PetscInt *cdofs; /* The indices of the constrained dofs on this point */ 4355552f7358SJed Brown PetscScalar *a; 4356552f7358SJed Brown PetscInt off, cind = 0, k; 4357552f7358SJed Brown PetscErrorCode ierr; 4358552f7358SJed Brown 4359552f7358SJed Brown PetscFunctionBegin; 4360552f7358SJed Brown ierr = PetscSectionGetConstraintDof(section, point, &cdof);CHKERRQ(ierr); 4361552f7358SJed Brown ierr = PetscSectionGetOffset(section, point, &off);CHKERRQ(ierr); 4362552f7358SJed Brown a = &array[off]; 4363552f7358SJed Brown if (!cdof || setBC) { 436497e99dd9SToby Isaac if (clperm) { 436597e99dd9SToby Isaac if (perm) {for (k = 0; k < dof; ++k) {fuse(&a[k], values[clperm[offset+perm[k]]] * (flip ? flip[perm[k]] : 1.));}} 436697e99dd9SToby Isaac else {for (k = 0; k < dof; ++k) {fuse(&a[k], values[clperm[offset+ k ]] * (flip ? flip[ k ] : 1.));}} 4367552f7358SJed Brown } else { 436897e99dd9SToby Isaac if (perm) {for (k = 0; k < dof; ++k) {fuse(&a[k], values[offset+perm[k]] * (flip ? flip[perm[k]] : 1.));}} 436997e99dd9SToby Isaac else {for (k = 0; k < dof; ++k) {fuse(&a[k], values[offset+ k ] * (flip ? flip[ k ] : 1.));}} 4370552f7358SJed Brown } 4371552f7358SJed Brown } else { 4372552f7358SJed Brown ierr = PetscSectionGetConstraintIndices(section, point, &cdofs);CHKERRQ(ierr); 437397e99dd9SToby Isaac if (clperm) { 437497e99dd9SToby Isaac if (perm) {for (k = 0; k < dof; ++k) { 4375552f7358SJed Brown if ((cind < cdof) && (k == cdofs[cind])) {++cind; continue;} 437697e99dd9SToby Isaac fuse(&a[k], values[clperm[offset+perm[k]]] * (flip ? flip[perm[k]] : 1.)); 4377552f7358SJed Brown } 4378552f7358SJed Brown } else { 4379552f7358SJed Brown for (k = 0; k < dof; ++k) { 4380552f7358SJed Brown if ((cind < cdof) && (k == cdofs[cind])) {++cind; continue;} 438197e99dd9SToby Isaac fuse(&a[k], values[clperm[offset+ k ]] * (flip ? flip[ k ] : 1.)); 438297e99dd9SToby Isaac } 438397e99dd9SToby Isaac } 438497e99dd9SToby Isaac } else { 438597e99dd9SToby Isaac if (perm) { 438697e99dd9SToby Isaac for (k = 0; k < dof; ++k) { 438797e99dd9SToby Isaac if ((cind < cdof) && (k == cdofs[cind])) {++cind; continue;} 438897e99dd9SToby Isaac fuse(&a[k], values[offset+perm[k]] * (flip ? flip[perm[k]] : 1.)); 438997e99dd9SToby Isaac } 439097e99dd9SToby Isaac } else { 439197e99dd9SToby Isaac for (k = 0; k < dof; ++k) { 439297e99dd9SToby Isaac if ((cind < cdof) && (k == cdofs[cind])) {++cind; continue;} 439397e99dd9SToby Isaac fuse(&a[k], values[offset+ k ] * (flip ? flip[ k ] : 1.)); 439497e99dd9SToby Isaac } 4395552f7358SJed Brown } 4396552f7358SJed Brown } 4397552f7358SJed Brown } 4398552f7358SJed Brown PetscFunctionReturn(0); 4399552f7358SJed Brown } 4400552f7358SJed Brown 440197e99dd9SToby Isaac PETSC_STATIC_INLINE PetscErrorCode updatePointBC_private(PetscSection section, PetscInt point, PetscInt dof, void (*fuse)(PetscScalar*, PetscScalar), const PetscInt perm[], const PetscScalar flip[], const PetscInt clperm[], const PetscScalar values[], PetscInt offset, PetscScalar array[]) 4402a5e93ea8SMatthew G. Knepley { 4403a5e93ea8SMatthew G. Knepley PetscInt cdof; /* The number of constraints on this point */ 4404a5e93ea8SMatthew G. Knepley const PetscInt *cdofs; /* The indices of the constrained dofs on this point */ 4405a5e93ea8SMatthew G. Knepley PetscScalar *a; 4406a5e93ea8SMatthew G. Knepley PetscInt off, cind = 0, k; 4407a5e93ea8SMatthew G. Knepley PetscErrorCode ierr; 4408a5e93ea8SMatthew G. Knepley 4409a5e93ea8SMatthew G. Knepley PetscFunctionBegin; 4410a5e93ea8SMatthew G. Knepley ierr = PetscSectionGetConstraintDof(section, point, &cdof);CHKERRQ(ierr); 4411a5e93ea8SMatthew G. Knepley ierr = PetscSectionGetOffset(section, point, &off);CHKERRQ(ierr); 4412a5e93ea8SMatthew G. Knepley a = &array[off]; 4413a5e93ea8SMatthew G. Knepley if (cdof) { 4414a5e93ea8SMatthew G. Knepley ierr = PetscSectionGetConstraintIndices(section, point, &cdofs);CHKERRQ(ierr); 441597e99dd9SToby Isaac if (clperm) { 441697e99dd9SToby Isaac if (perm) { 4417a5e93ea8SMatthew G. Knepley for (k = 0; k < dof; ++k) { 4418a5e93ea8SMatthew G. Knepley if ((cind < cdof) && (k == cdofs[cind])) { 441997e99dd9SToby Isaac fuse(&a[k], values[clperm[offset+perm[k]]] * (flip ? flip[perm[k]] : 1.)); 442097e99dd9SToby Isaac cind++; 4421a5e93ea8SMatthew G. Knepley } 4422a5e93ea8SMatthew G. Knepley } 4423a5e93ea8SMatthew G. Knepley } else { 4424a5e93ea8SMatthew G. Knepley for (k = 0; k < dof; ++k) { 4425a5e93ea8SMatthew G. Knepley if ((cind < cdof) && (k == cdofs[cind])) { 442697e99dd9SToby Isaac fuse(&a[k], values[clperm[offset+ k ]] * (flip ? flip[ k ] : 1.)); 442797e99dd9SToby Isaac cind++; 442897e99dd9SToby Isaac } 442997e99dd9SToby Isaac } 443097e99dd9SToby Isaac } 443197e99dd9SToby Isaac } else { 443297e99dd9SToby Isaac if (perm) { 443397e99dd9SToby Isaac for (k = 0; k < dof; ++k) { 443497e99dd9SToby Isaac if ((cind < cdof) && (k == cdofs[cind])) { 443597e99dd9SToby Isaac fuse(&a[k], values[offset+perm[k]] * (flip ? flip[perm[k]] : 1.)); 443697e99dd9SToby Isaac cind++; 443797e99dd9SToby Isaac } 443897e99dd9SToby Isaac } 443997e99dd9SToby Isaac } else { 444097e99dd9SToby Isaac for (k = 0; k < dof; ++k) { 444197e99dd9SToby Isaac if ((cind < cdof) && (k == cdofs[cind])) { 444297e99dd9SToby Isaac fuse(&a[k], values[offset+ k ] * (flip ? flip[ k ] : 1.)); 444397e99dd9SToby Isaac cind++; 444497e99dd9SToby Isaac } 4445a5e93ea8SMatthew G. Knepley } 4446a5e93ea8SMatthew G. Knepley } 4447a5e93ea8SMatthew G. Knepley } 4448a5e93ea8SMatthew G. Knepley } 4449a5e93ea8SMatthew G. Knepley PetscFunctionReturn(0); 4450a5e93ea8SMatthew G. Knepley } 4451a5e93ea8SMatthew G. Knepley 445297e99dd9SToby Isaac PETSC_STATIC_INLINE PetscErrorCode updatePointFields_private(PetscSection section, PetscInt point, const PetscInt *perm, const PetscScalar *flip, PetscInt f, void (*fuse)(PetscScalar*, PetscScalar), PetscBool setBC, const PetscInt clperm[], const PetscScalar values[], PetscInt *offset, PetscScalar array[]) 4453a6dfd86eSKarl Rupp { 4454552f7358SJed Brown PetscScalar *a; 44551a271a75SMatthew G. Knepley PetscInt fdof, foff, fcdof, foffset = *offset; 44561a271a75SMatthew G. Knepley const PetscInt *fcdofs; /* The indices of the constrained dofs for field f on this point */ 445797e99dd9SToby Isaac PetscInt cind = 0, b; 4458552f7358SJed Brown PetscErrorCode ierr; 4459552f7358SJed Brown 4460552f7358SJed Brown PetscFunctionBegin; 4461552f7358SJed Brown ierr = PetscSectionGetFieldDof(section, point, f, &fdof);CHKERRQ(ierr); 4462552f7358SJed Brown ierr = PetscSectionGetFieldConstraintDof(section, point, f, &fcdof);CHKERRQ(ierr); 44631a271a75SMatthew G. Knepley ierr = PetscSectionGetFieldOffset(section, point, f, &foff);CHKERRQ(ierr); 44641a271a75SMatthew G. Knepley a = &array[foff]; 4465552f7358SJed Brown if (!fcdof || setBC) { 446697e99dd9SToby Isaac if (clperm) { 446797e99dd9SToby Isaac if (perm) {for (b = 0; b < fdof; b++) {fuse(&a[b], values[clperm[foffset+perm[b]]] * (flip ? flip[perm[b]] : 1.));}} 446897e99dd9SToby Isaac else {for (b = 0; b < fdof; b++) {fuse(&a[b], values[clperm[foffset+ b ]] * (flip ? flip[ b ] : 1.));}} 4469552f7358SJed Brown } else { 447097e99dd9SToby Isaac if (perm) {for (b = 0; b < fdof; b++) {fuse(&a[b], values[foffset+perm[b]] * (flip ? flip[perm[b]] : 1.));}} 447197e99dd9SToby Isaac else {for (b = 0; b < fdof; b++) {fuse(&a[b], values[foffset+ b ] * (flip ? flip[ b ] : 1.));}} 4472552f7358SJed Brown } 4473552f7358SJed Brown } else { 4474552f7358SJed Brown ierr = PetscSectionGetFieldConstraintIndices(section, point, f, &fcdofs);CHKERRQ(ierr); 447597e99dd9SToby Isaac if (clperm) { 447697e99dd9SToby Isaac if (perm) { 447797e99dd9SToby Isaac for (b = 0; b < fdof; b++) { 447897e99dd9SToby Isaac if ((cind < fcdof) && (b == fcdofs[cind])) {++cind; continue;} 447997e99dd9SToby Isaac fuse(&a[b], values[clperm[foffset+perm[b]]] * (flip ? flip[perm[b]] : 1.)); 4480552f7358SJed Brown } 4481552f7358SJed Brown } else { 448297e99dd9SToby Isaac for (b = 0; b < fdof; b++) { 448397e99dd9SToby Isaac if ((cind < fcdof) && (b == fcdofs[cind])) {++cind; continue;} 448497e99dd9SToby Isaac fuse(&a[b], values[clperm[foffset+ b ]] * (flip ? flip[ b ] : 1.)); 448597e99dd9SToby Isaac } 448697e99dd9SToby Isaac } 448797e99dd9SToby Isaac } else { 448897e99dd9SToby Isaac if (perm) { 448997e99dd9SToby Isaac for (b = 0; b < fdof; b++) { 449097e99dd9SToby Isaac if ((cind < fcdof) && (b == fcdofs[cind])) {++cind; continue;} 449197e99dd9SToby Isaac fuse(&a[b], values[foffset+perm[b]] * (flip ? flip[perm[b]] : 1.)); 449297e99dd9SToby Isaac } 449397e99dd9SToby Isaac } else { 449497e99dd9SToby Isaac for (b = 0; b < fdof; b++) { 449597e99dd9SToby Isaac if ((cind < fcdof) && (b == fcdofs[cind])) {++cind; continue;} 449697e99dd9SToby Isaac fuse(&a[b], values[foffset+ b ] * (flip ? flip[ b ] : 1.)); 4497552f7358SJed Brown } 4498552f7358SJed Brown } 4499552f7358SJed Brown } 4500552f7358SJed Brown } 45011a271a75SMatthew G. Knepley *offset += fdof; 4502552f7358SJed Brown PetscFunctionReturn(0); 4503552f7358SJed Brown } 4504552f7358SJed Brown 4505ba322698SMatthew G. Knepley PETSC_STATIC_INLINE PetscErrorCode updatePointFieldsBC_private(PetscSection section, PetscInt point, const PetscInt perm[], const PetscScalar flip[], PetscInt f, PetscInt Ncc, const PetscInt comps[], void (*fuse)(PetscScalar*, PetscScalar), const PetscInt clperm[], const PetscScalar values[], PetscInt *offset, PetscScalar array[]) 4506a5e93ea8SMatthew G. Knepley { 4507a5e93ea8SMatthew G. Knepley PetscScalar *a; 45081a271a75SMatthew G. Knepley PetscInt fdof, foff, fcdof, foffset = *offset; 45091a271a75SMatthew G. Knepley const PetscInt *fcdofs; /* The indices of the constrained dofs for field f on this point */ 4510ba322698SMatthew G. Knepley PetscInt cind = 0, ncind = 0, b; 4511ba322698SMatthew G. Knepley PetscBool ncSet, fcSet; 4512a5e93ea8SMatthew G. Knepley PetscErrorCode ierr; 4513a5e93ea8SMatthew G. Knepley 4514a5e93ea8SMatthew G. Knepley PetscFunctionBegin; 4515a5e93ea8SMatthew G. Knepley ierr = PetscSectionGetFieldDof(section, point, f, &fdof);CHKERRQ(ierr); 4516a5e93ea8SMatthew G. Knepley ierr = PetscSectionGetFieldConstraintDof(section, point, f, &fcdof);CHKERRQ(ierr); 45171a271a75SMatthew G. Knepley ierr = PetscSectionGetFieldOffset(section, point, f, &foff);CHKERRQ(ierr); 45181a271a75SMatthew G. Knepley a = &array[foff]; 4519a5e93ea8SMatthew G. Knepley if (fcdof) { 4520ba322698SMatthew G. Knepley /* We just override fcdof and fcdofs with Ncc and comps */ 4521a5e93ea8SMatthew G. Knepley ierr = PetscSectionGetFieldConstraintIndices(section, point, f, &fcdofs);CHKERRQ(ierr); 452297e99dd9SToby Isaac if (clperm) { 452397e99dd9SToby Isaac if (perm) { 4524ba322698SMatthew G. Knepley if (comps) { 4525ba322698SMatthew G. Knepley for (b = 0; b < fdof; b++) { 4526ba322698SMatthew G. Knepley ncSet = fcSet = PETSC_FALSE; 4527ba322698SMatthew G. Knepley if ((ncind < Ncc) && (b == comps[ncind])) {++ncind; ncSet = PETSC_TRUE;} 4528ba322698SMatthew G. Knepley if ((cind < fcdof) && (b == fcdofs[cind])) {++cind; fcSet = PETSC_TRUE;} 4529ba322698SMatthew G. Knepley if (ncSet && fcSet) {fuse(&a[b], values[clperm[foffset+perm[b]]] * (flip ? flip[perm[b]] : 1.));} 4530ba322698SMatthew G. Knepley } 4531ba322698SMatthew G. Knepley } else { 453297e99dd9SToby Isaac for (b = 0; b < fdof; b++) { 453397e99dd9SToby Isaac if ((cind < fcdof) && (b == fcdofs[cind])) { 453497e99dd9SToby Isaac fuse(&a[b], values[clperm[foffset+perm[b]]] * (flip ? flip[perm[b]] : 1.)); 4535a5e93ea8SMatthew G. Knepley ++cind; 4536a5e93ea8SMatthew G. Knepley } 4537a5e93ea8SMatthew G. Knepley } 4538ba322698SMatthew G. Knepley } 4539ba322698SMatthew G. Knepley } else { 4540ba322698SMatthew G. Knepley if (comps) { 4541ba322698SMatthew G. Knepley for (b = 0; b < fdof; b++) { 4542ba322698SMatthew G. Knepley ncSet = fcSet = PETSC_FALSE; 4543ba322698SMatthew G. Knepley if ((ncind < Ncc) && (b == comps[ncind])) {++ncind; ncSet = PETSC_TRUE;} 4544ba322698SMatthew G. Knepley if ((cind < fcdof) && (b == fcdofs[cind])) {++cind; fcSet = PETSC_TRUE;} 4545ba322698SMatthew G. Knepley if (ncSet && fcSet) {fuse(&a[b], values[clperm[foffset+ b ]] * (flip ? flip[ b ] : 1.));} 4546ba322698SMatthew G. Knepley } 4547a5e93ea8SMatthew G. Knepley } else { 454897e99dd9SToby Isaac for (b = 0; b < fdof; b++) { 454997e99dd9SToby Isaac if ((cind < fcdof) && (b == fcdofs[cind])) { 455097e99dd9SToby Isaac fuse(&a[b], values[clperm[foffset+ b ]] * (flip ? flip[ b ] : 1.)); 455197e99dd9SToby Isaac ++cind; 455297e99dd9SToby Isaac } 455397e99dd9SToby Isaac } 455497e99dd9SToby Isaac } 4555ba322698SMatthew G. Knepley } 455697e99dd9SToby Isaac } else { 455797e99dd9SToby Isaac if (perm) { 4558ba322698SMatthew G. Knepley if (comps) { 4559ba322698SMatthew G. Knepley for (b = 0; b < fdof; b++) { 4560ba322698SMatthew G. Knepley ncSet = fcSet = PETSC_FALSE; 4561ba322698SMatthew G. Knepley if ((ncind < Ncc) && (b == comps[ncind])) {++ncind; ncSet = PETSC_TRUE;} 4562ba322698SMatthew G. Knepley if ((cind < fcdof) && (b == fcdofs[cind])) {++cind; fcSet = PETSC_TRUE;} 4563ba322698SMatthew G. Knepley if (ncSet && fcSet) {fuse(&a[b], values[foffset+perm[b]] * (flip ? flip[perm[b]] : 1.));} 4564ba322698SMatthew G. Knepley } 4565ba322698SMatthew G. Knepley } else { 456697e99dd9SToby Isaac for (b = 0; b < fdof; b++) { 456797e99dd9SToby Isaac if ((cind < fcdof) && (b == fcdofs[cind])) { 456897e99dd9SToby Isaac fuse(&a[b], values[foffset+perm[b]] * (flip ? flip[perm[b]] : 1.)); 456997e99dd9SToby Isaac ++cind; 457097e99dd9SToby Isaac } 457197e99dd9SToby Isaac } 4572ba322698SMatthew G. Knepley } 4573ba322698SMatthew G. Knepley } else { 4574ba322698SMatthew G. Knepley if (comps) { 4575ba322698SMatthew G. Knepley for (b = 0; b < fdof; b++) { 4576ba322698SMatthew G. Knepley ncSet = fcSet = PETSC_FALSE; 4577ba322698SMatthew G. Knepley if ((ncind < Ncc) && (b == comps[ncind])) {++ncind; ncSet = PETSC_TRUE;} 4578ba322698SMatthew G. Knepley if ((cind < fcdof) && (b == fcdofs[cind])) {++cind; fcSet = PETSC_TRUE;} 4579ba322698SMatthew G. Knepley if (ncSet && fcSet) {fuse(&a[b], values[foffset+ b ] * (flip ? flip[ b ] : 1.));} 4580ba322698SMatthew G. Knepley } 458197e99dd9SToby Isaac } else { 458297e99dd9SToby Isaac for (b = 0; b < fdof; b++) { 458397e99dd9SToby Isaac if ((cind < fcdof) && (b == fcdofs[cind])) { 458497e99dd9SToby Isaac fuse(&a[b], values[foffset+ b ] * (flip ? flip[ b ] : 1.)); 4585a5e93ea8SMatthew G. Knepley ++cind; 4586a5e93ea8SMatthew G. Knepley } 4587a5e93ea8SMatthew G. Knepley } 4588a5e93ea8SMatthew G. Knepley } 4589a5e93ea8SMatthew G. Knepley } 4590a5e93ea8SMatthew G. Knepley } 4591ba322698SMatthew G. Knepley } 45921a271a75SMatthew G. Knepley *offset += fdof; 4593a5e93ea8SMatthew G. Knepley PetscFunctionReturn(0); 4594a5e93ea8SMatthew G. Knepley } 4595a5e93ea8SMatthew G. Knepley 45968f3be42fSMatthew G. Knepley PETSC_STATIC_INLINE PetscErrorCode DMPlexVecSetClosure_Depth1_Static(DM dm, PetscSection section, Vec v, PetscInt point, const PetscScalar values[], InsertMode mode) 4597a6dfd86eSKarl Rupp { 4598552f7358SJed Brown PetscScalar *array; 45991b406b76SMatthew G. Knepley const PetscInt *cone, *coneO; 46001b406b76SMatthew G. Knepley PetscInt pStart, pEnd, p, numPoints, off, dof; 4601552f7358SJed Brown PetscErrorCode ierr; 4602552f7358SJed Brown 46031b406b76SMatthew G. Knepley PetscFunctionBeginHot; 4604b6ebb6e6SMatthew G. Knepley ierr = PetscSectionGetChart(section, &pStart, &pEnd);CHKERRQ(ierr); 4605b6ebb6e6SMatthew G. Knepley ierr = DMPlexGetConeSize(dm, point, &numPoints);CHKERRQ(ierr); 4606b6ebb6e6SMatthew G. Knepley ierr = DMPlexGetCone(dm, point, &cone);CHKERRQ(ierr); 4607b6ebb6e6SMatthew G. Knepley ierr = DMPlexGetConeOrientation(dm, point, &coneO);CHKERRQ(ierr); 4608b6ebb6e6SMatthew G. Knepley ierr = VecGetArray(v, &array);CHKERRQ(ierr); 4609b6ebb6e6SMatthew G. Knepley for (p = 0, off = 0; p <= numPoints; ++p, off += dof) { 4610b6ebb6e6SMatthew G. Knepley const PetscInt cp = !p ? point : cone[p-1]; 4611b6ebb6e6SMatthew G. Knepley const PetscInt o = !p ? 0 : coneO[p-1]; 4612b6ebb6e6SMatthew G. Knepley 4613b6ebb6e6SMatthew G. Knepley if ((cp < pStart) || (cp >= pEnd)) {dof = 0; continue;} 4614b6ebb6e6SMatthew G. Knepley ierr = PetscSectionGetDof(section, cp, &dof);CHKERRQ(ierr); 4615b6ebb6e6SMatthew G. Knepley /* ADD_VALUES */ 4616b6ebb6e6SMatthew G. Knepley { 4617b6ebb6e6SMatthew G. Knepley const PetscInt *cdofs; /* The indices of the constrained dofs on this point */ 4618b6ebb6e6SMatthew G. Knepley PetscScalar *a; 4619b6ebb6e6SMatthew G. Knepley PetscInt cdof, coff, cind = 0, k; 4620b6ebb6e6SMatthew G. Knepley 4621b6ebb6e6SMatthew G. Knepley ierr = PetscSectionGetConstraintDof(section, cp, &cdof);CHKERRQ(ierr); 4622b6ebb6e6SMatthew G. Knepley ierr = PetscSectionGetOffset(section, cp, &coff);CHKERRQ(ierr); 4623b6ebb6e6SMatthew G. Knepley a = &array[coff]; 4624b6ebb6e6SMatthew G. Knepley if (!cdof) { 4625b6ebb6e6SMatthew G. Knepley if (o >= 0) { 4626b6ebb6e6SMatthew G. Knepley for (k = 0; k < dof; ++k) { 4627b6ebb6e6SMatthew G. Knepley a[k] += values[off+k]; 4628b6ebb6e6SMatthew G. Knepley } 4629b6ebb6e6SMatthew G. Knepley } else { 4630b6ebb6e6SMatthew G. Knepley for (k = 0; k < dof; ++k) { 4631b6ebb6e6SMatthew G. Knepley a[k] += values[off+dof-k-1]; 4632b6ebb6e6SMatthew G. Knepley } 4633b6ebb6e6SMatthew G. Knepley } 4634b6ebb6e6SMatthew G. Knepley } else { 4635b6ebb6e6SMatthew G. Knepley ierr = PetscSectionGetConstraintIndices(section, cp, &cdofs);CHKERRQ(ierr); 4636b6ebb6e6SMatthew G. Knepley if (o >= 0) { 4637b6ebb6e6SMatthew G. Knepley for (k = 0; k < dof; ++k) { 4638b6ebb6e6SMatthew G. Knepley if ((cind < cdof) && (k == cdofs[cind])) {++cind; continue;} 4639b6ebb6e6SMatthew G. Knepley a[k] += values[off+k]; 4640b6ebb6e6SMatthew G. Knepley } 4641b6ebb6e6SMatthew G. Knepley } else { 4642b6ebb6e6SMatthew G. Knepley for (k = 0; k < dof; ++k) { 4643b6ebb6e6SMatthew G. Knepley if ((cind < cdof) && (k == cdofs[cind])) {++cind; continue;} 4644b6ebb6e6SMatthew G. Knepley a[k] += values[off+dof-k-1]; 4645b6ebb6e6SMatthew G. Knepley } 4646b6ebb6e6SMatthew G. Knepley } 4647b6ebb6e6SMatthew G. Knepley } 4648b6ebb6e6SMatthew G. Knepley } 4649b6ebb6e6SMatthew G. Knepley } 4650b6ebb6e6SMatthew G. Knepley ierr = VecRestoreArray(v, &array);CHKERRQ(ierr); 4651b6ebb6e6SMatthew G. Knepley PetscFunctionReturn(0); 4652b6ebb6e6SMatthew G. Knepley } 46531b406b76SMatthew G. Knepley 46541b406b76SMatthew G. Knepley /*@C 46551b406b76SMatthew G. Knepley DMPlexVecSetClosure - Set an array of the values on the closure of 'point' 46561b406b76SMatthew G. Knepley 46571b406b76SMatthew G. Knepley Not collective 46581b406b76SMatthew G. Knepley 46591b406b76SMatthew G. Knepley Input Parameters: 46601b406b76SMatthew G. Knepley + dm - The DM 46611b406b76SMatthew G. Knepley . section - The section describing the layout in v, or NULL to use the default section 46621b406b76SMatthew G. Knepley . v - The local vector 4663eaf898f9SPatrick Sanan . point - The point in the DM 46641b406b76SMatthew G. Knepley . values - The array of values 466522c1ee49SMatthew G. Knepley - mode - The insert mode. One of INSERT_ALL_VALUES, ADD_ALL_VALUES, INSERT_VALUES, ADD_VALUES, INSERT_BC_VALUES, and ADD_BC_VALUES, 466622c1ee49SMatthew G. Knepley where INSERT_ALL_VALUES and ADD_ALL_VALUES also overwrite boundary conditions. 46671b406b76SMatthew G. Knepley 46681b406b76SMatthew G. Knepley Fortran Notes: 46691b406b76SMatthew G. Knepley This routine is only available in Fortran 90, and you must include petsc.h90 in your code. 46701b406b76SMatthew G. Knepley 46711b406b76SMatthew G. Knepley Level: intermediate 46721b406b76SMatthew G. Knepley 46731b406b76SMatthew G. Knepley .seealso DMPlexVecGetClosure(), DMPlexMatSetClosure() 46741b406b76SMatthew G. Knepley @*/ 46751b406b76SMatthew G. Knepley PetscErrorCode DMPlexVecSetClosure(DM dm, PetscSection section, Vec v, PetscInt point, const PetscScalar values[], InsertMode mode) 46761b406b76SMatthew G. Knepley { 46771b406b76SMatthew G. Knepley PetscSection clSection; 46781b406b76SMatthew G. Knepley IS clPoints; 46791b406b76SMatthew G. Knepley PetscScalar *array; 46801b406b76SMatthew G. Knepley PetscInt *points = NULL; 468197e99dd9SToby Isaac const PetscInt *clp, *clperm; 46821a271a75SMatthew G. Knepley PetscInt depth, numFields, numPoints, p; 46831b406b76SMatthew G. Knepley PetscErrorCode ierr; 46841b406b76SMatthew G. Knepley 46851a271a75SMatthew G. Knepley PetscFunctionBeginHot; 46861b406b76SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 4687e87a4003SBarry Smith if (!section) {ierr = DMGetSection(dm, §ion);CHKERRQ(ierr);} 46881a271a75SMatthew G. Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 2); 46891a271a75SMatthew G. Knepley PetscValidHeaderSpecific(v, VEC_CLASSID, 3); 46901b406b76SMatthew G. Knepley ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 46911b406b76SMatthew G. Knepley ierr = PetscSectionGetNumFields(section, &numFields);CHKERRQ(ierr); 46921b406b76SMatthew G. Knepley if (depth == 1 && numFields < 2 && mode == ADD_VALUES) { 46938f3be42fSMatthew G. Knepley ierr = DMPlexVecSetClosure_Depth1_Static(dm, section, v, point, values, mode);CHKERRQ(ierr); 46941b406b76SMatthew G. Knepley PetscFunctionReturn(0); 46951b406b76SMatthew G. Knepley } 46961a271a75SMatthew G. Knepley /* Get points */ 469797e99dd9SToby Isaac ierr = PetscSectionGetClosureInversePermutation_Internal(section, (PetscObject) dm, NULL, &clperm);CHKERRQ(ierr); 4698923c78e0SToby Isaac ierr = DMPlexGetCompressedClosure(dm,section,point,&numPoints,&points,&clSection,&clPoints,&clp);CHKERRQ(ierr); 46991a271a75SMatthew G. Knepley /* Get array */ 4700552f7358SJed Brown ierr = VecGetArray(v, &array);CHKERRQ(ierr); 47011a271a75SMatthew G. Knepley /* Get values */ 4702ef90cfe2SMatthew G. Knepley if (numFields > 0) { 470397e99dd9SToby Isaac PetscInt offset = 0, f; 4704552f7358SJed Brown for (f = 0; f < numFields; ++f) { 470597e99dd9SToby Isaac const PetscInt **perms = NULL; 470697e99dd9SToby Isaac const PetscScalar **flips = NULL; 470797e99dd9SToby Isaac 470897e99dd9SToby Isaac ierr = PetscSectionGetFieldPointSyms(section,f,numPoints,points,&perms,&flips);CHKERRQ(ierr); 4709552f7358SJed Brown switch (mode) { 4710552f7358SJed Brown case INSERT_VALUES: 471197e99dd9SToby Isaac for (p = 0; p < numPoints; p++) { 471297e99dd9SToby Isaac const PetscInt point = points[2*p]; 471397e99dd9SToby Isaac const PetscInt *perm = perms ? perms[p] : NULL; 471497e99dd9SToby Isaac const PetscScalar *flip = flips ? flips[p] : NULL; 471597e99dd9SToby Isaac updatePointFields_private(section, point, perm, flip, f, insert, PETSC_FALSE, clperm, values, &offset, array); 4716552f7358SJed Brown } break; 4717552f7358SJed Brown case INSERT_ALL_VALUES: 471897e99dd9SToby Isaac for (p = 0; p < numPoints; p++) { 471997e99dd9SToby Isaac const PetscInt point = points[2*p]; 472097e99dd9SToby Isaac const PetscInt *perm = perms ? perms[p] : NULL; 472197e99dd9SToby Isaac const PetscScalar *flip = flips ? flips[p] : NULL; 472297e99dd9SToby Isaac updatePointFields_private(section, point, perm, flip, f, insert, PETSC_TRUE, clperm, values, &offset, array); 4723552f7358SJed Brown } break; 4724a5e93ea8SMatthew G. Knepley case INSERT_BC_VALUES: 472597e99dd9SToby Isaac for (p = 0; p < numPoints; p++) { 472697e99dd9SToby Isaac const PetscInt point = points[2*p]; 472797e99dd9SToby Isaac const PetscInt *perm = perms ? perms[p] : NULL; 472897e99dd9SToby Isaac const PetscScalar *flip = flips ? flips[p] : NULL; 4729ba322698SMatthew G. Knepley updatePointFieldsBC_private(section, point, perm, flip, f, -1, NULL, insert, clperm, values, &offset, array); 4730a5e93ea8SMatthew G. Knepley } break; 4731552f7358SJed Brown case ADD_VALUES: 473297e99dd9SToby Isaac for (p = 0; p < numPoints; p++) { 473397e99dd9SToby Isaac const PetscInt point = points[2*p]; 473497e99dd9SToby Isaac const PetscInt *perm = perms ? perms[p] : NULL; 473597e99dd9SToby Isaac const PetscScalar *flip = flips ? flips[p] : NULL; 473697e99dd9SToby Isaac updatePointFields_private(section, point, perm, flip, f, add, PETSC_FALSE, clperm, values, &offset, array); 4737552f7358SJed Brown } break; 4738552f7358SJed Brown case ADD_ALL_VALUES: 473997e99dd9SToby Isaac for (p = 0; p < numPoints; p++) { 474097e99dd9SToby Isaac const PetscInt point = points[2*p]; 474197e99dd9SToby Isaac const PetscInt *perm = perms ? perms[p] : NULL; 474297e99dd9SToby Isaac const PetscScalar *flip = flips ? flips[p] : NULL; 474397e99dd9SToby Isaac updatePointFields_private(section, point, perm, flip, f, add, PETSC_TRUE, clperm, values, &offset, array); 4744552f7358SJed Brown } break; 4745304ab55fSMatthew G. Knepley case ADD_BC_VALUES: 474697e99dd9SToby Isaac for (p = 0; p < numPoints; p++) { 474797e99dd9SToby Isaac const PetscInt point = points[2*p]; 474897e99dd9SToby Isaac const PetscInt *perm = perms ? perms[p] : NULL; 474997e99dd9SToby Isaac const PetscScalar *flip = flips ? flips[p] : NULL; 4750ba322698SMatthew G. Knepley updatePointFieldsBC_private(section, point, perm, flip, f, -1, NULL, add, clperm, values, &offset, array); 4751304ab55fSMatthew G. Knepley } break; 4752552f7358SJed Brown default: 4753f347f43bSBarry Smith SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insert mode %d", mode); 4754552f7358SJed Brown } 475597e99dd9SToby Isaac ierr = PetscSectionRestoreFieldPointSyms(section,f,numPoints,points,&perms,&flips);CHKERRQ(ierr); 47561a271a75SMatthew G. Knepley } 4757552f7358SJed Brown } else { 47581a271a75SMatthew G. Knepley PetscInt dof, off; 475997e99dd9SToby Isaac const PetscInt **perms = NULL; 476097e99dd9SToby Isaac const PetscScalar **flips = NULL; 47611a271a75SMatthew G. Knepley 476297e99dd9SToby Isaac ierr = PetscSectionGetPointSyms(section,numPoints,points,&perms,&flips);CHKERRQ(ierr); 4763552f7358SJed Brown switch (mode) { 4764552f7358SJed Brown case INSERT_VALUES: 476597e99dd9SToby Isaac for (p = 0, off = 0; p < numPoints; p++, off += dof) { 476697e99dd9SToby Isaac const PetscInt point = points[2*p]; 476797e99dd9SToby Isaac const PetscInt *perm = perms ? perms[p] : NULL; 476897e99dd9SToby Isaac const PetscScalar *flip = flips ? flips[p] : NULL; 476997e99dd9SToby Isaac ierr = PetscSectionGetDof(section, point, &dof);CHKERRQ(ierr); 477097e99dd9SToby Isaac updatePoint_private(section, point, dof, insert, PETSC_FALSE, perm, flip, clperm, values, off, array); 4771552f7358SJed Brown } break; 4772552f7358SJed Brown case INSERT_ALL_VALUES: 477397e99dd9SToby Isaac for (p = 0, off = 0; p < numPoints; p++, off += dof) { 477497e99dd9SToby Isaac const PetscInt point = points[2*p]; 477597e99dd9SToby Isaac const PetscInt *perm = perms ? perms[p] : NULL; 477697e99dd9SToby Isaac const PetscScalar *flip = flips ? flips[p] : NULL; 477797e99dd9SToby Isaac ierr = PetscSectionGetDof(section, point, &dof);CHKERRQ(ierr); 477897e99dd9SToby Isaac updatePoint_private(section, point, dof, insert, PETSC_TRUE, perm, flip, clperm, values, off, array); 4779552f7358SJed Brown } break; 4780a5e93ea8SMatthew G. Knepley case INSERT_BC_VALUES: 478197e99dd9SToby Isaac for (p = 0, off = 0; p < numPoints; p++, off += dof) { 478297e99dd9SToby Isaac const PetscInt point = points[2*p]; 478397e99dd9SToby Isaac const PetscInt *perm = perms ? perms[p] : NULL; 478497e99dd9SToby Isaac const PetscScalar *flip = flips ? flips[p] : NULL; 478597e99dd9SToby Isaac ierr = PetscSectionGetDof(section, point, &dof);CHKERRQ(ierr); 478697e99dd9SToby Isaac updatePointBC_private(section, point, dof, insert, perm, flip, clperm, values, off, array); 4787a5e93ea8SMatthew G. Knepley } break; 4788552f7358SJed Brown case ADD_VALUES: 478997e99dd9SToby Isaac for (p = 0, off = 0; p < numPoints; p++, off += dof) { 479097e99dd9SToby Isaac const PetscInt point = points[2*p]; 479197e99dd9SToby Isaac const PetscInt *perm = perms ? perms[p] : NULL; 479297e99dd9SToby Isaac const PetscScalar *flip = flips ? flips[p] : NULL; 479397e99dd9SToby Isaac ierr = PetscSectionGetDof(section, point, &dof);CHKERRQ(ierr); 479497e99dd9SToby Isaac updatePoint_private(section, point, dof, add, PETSC_FALSE, perm, flip, clperm, values, off, array); 4795552f7358SJed Brown } break; 4796552f7358SJed Brown case ADD_ALL_VALUES: 479797e99dd9SToby Isaac for (p = 0, off = 0; p < numPoints; p++, off += dof) { 479897e99dd9SToby Isaac const PetscInt point = points[2*p]; 479997e99dd9SToby Isaac const PetscInt *perm = perms ? perms[p] : NULL; 480097e99dd9SToby Isaac const PetscScalar *flip = flips ? flips[p] : NULL; 480197e99dd9SToby Isaac ierr = PetscSectionGetDof(section, point, &dof);CHKERRQ(ierr); 480297e99dd9SToby Isaac updatePoint_private(section, point, dof, add, PETSC_TRUE, perm, flip, clperm, values, off, array); 4803552f7358SJed Brown } break; 4804304ab55fSMatthew G. Knepley case ADD_BC_VALUES: 480597e99dd9SToby Isaac for (p = 0, off = 0; p < numPoints; p++, off += dof) { 480697e99dd9SToby Isaac const PetscInt point = points[2*p]; 480797e99dd9SToby Isaac const PetscInt *perm = perms ? perms[p] : NULL; 480897e99dd9SToby Isaac const PetscScalar *flip = flips ? flips[p] : NULL; 480997e99dd9SToby Isaac ierr = PetscSectionGetDof(section, point, &dof);CHKERRQ(ierr); 481097e99dd9SToby Isaac updatePointBC_private(section, point, dof, add, perm, flip, clperm, values, off, array); 4811304ab55fSMatthew G. Knepley } break; 4812552f7358SJed Brown default: 4813f347f43bSBarry Smith SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insert mode %d", mode); 4814552f7358SJed Brown } 481597e99dd9SToby Isaac ierr = PetscSectionRestorePointSyms(section,numPoints,points,&perms,&flips);CHKERRQ(ierr); 4816552f7358SJed Brown } 48171a271a75SMatthew G. Knepley /* Cleanup points */ 4818923c78e0SToby Isaac ierr = DMPlexRestoreCompressedClosure(dm,section,point,&numPoints,&points,&clSection,&clPoints,&clp);CHKERRQ(ierr); 48191a271a75SMatthew G. Knepley /* Cleanup array */ 4820552f7358SJed Brown ierr = VecRestoreArray(v, &array);CHKERRQ(ierr); 4821552f7358SJed Brown PetscFunctionReturn(0); 4822552f7358SJed Brown } 4823552f7358SJed Brown 4824ba322698SMatthew G. Knepley PetscErrorCode DMPlexVecSetFieldClosure_Internal(DM dm, PetscSection section, Vec v, PetscBool fieldActive[], PetscInt point, PetscInt Ncc, const PetscInt comps[], const PetscScalar values[], InsertMode mode) 4825e07394fbSMatthew G. Knepley { 4826e07394fbSMatthew G. Knepley PetscSection clSection; 4827e07394fbSMatthew G. Knepley IS clPoints; 4828e07394fbSMatthew G. Knepley PetscScalar *array; 4829e07394fbSMatthew G. Knepley PetscInt *points = NULL; 4830b04c866fSMatthew G. Knepley const PetscInt *clp, *clperm; 4831e07394fbSMatthew G. Knepley PetscInt numFields, numPoints, p; 483297e99dd9SToby Isaac PetscInt offset = 0, f; 4833e07394fbSMatthew G. Knepley PetscErrorCode ierr; 4834e07394fbSMatthew G. Knepley 4835e07394fbSMatthew G. Knepley PetscFunctionBeginHot; 4836e07394fbSMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 4837e87a4003SBarry Smith if (!section) {ierr = DMGetSection(dm, §ion);CHKERRQ(ierr);} 4838e07394fbSMatthew G. Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 2); 4839e07394fbSMatthew G. Knepley PetscValidHeaderSpecific(v, VEC_CLASSID, 3); 4840e07394fbSMatthew G. Knepley ierr = PetscSectionGetNumFields(section, &numFields);CHKERRQ(ierr); 4841e07394fbSMatthew G. Knepley /* Get points */ 4842b04c866fSMatthew G. Knepley ierr = PetscSectionGetClosureInversePermutation_Internal(section, (PetscObject) dm, NULL, &clperm);CHKERRQ(ierr); 4843923c78e0SToby Isaac ierr = DMPlexGetCompressedClosure(dm,section,point,&numPoints,&points,&clSection,&clPoints,&clp);CHKERRQ(ierr); 4844e07394fbSMatthew G. Knepley /* Get array */ 4845e07394fbSMatthew G. Knepley ierr = VecGetArray(v, &array);CHKERRQ(ierr); 4846e07394fbSMatthew G. Knepley /* Get values */ 4847e07394fbSMatthew G. Knepley for (f = 0; f < numFields; ++f) { 484897e99dd9SToby Isaac const PetscInt **perms = NULL; 484997e99dd9SToby Isaac const PetscScalar **flips = NULL; 485097e99dd9SToby Isaac 4851e07394fbSMatthew G. Knepley if (!fieldActive[f]) { 4852e07394fbSMatthew G. Knepley for (p = 0; p < numPoints*2; p += 2) { 4853e07394fbSMatthew G. Knepley PetscInt fdof; 4854e07394fbSMatthew G. Knepley ierr = PetscSectionGetFieldDof(section, points[p], f, &fdof);CHKERRQ(ierr); 4855e07394fbSMatthew G. Knepley offset += fdof; 4856e07394fbSMatthew G. Knepley } 4857e07394fbSMatthew G. Knepley continue; 4858e07394fbSMatthew G. Knepley } 485997e99dd9SToby Isaac ierr = PetscSectionGetFieldPointSyms(section,f,numPoints,points,&perms,&flips);CHKERRQ(ierr); 4860e07394fbSMatthew G. Knepley switch (mode) { 4861e07394fbSMatthew G. Knepley case INSERT_VALUES: 486297e99dd9SToby Isaac for (p = 0; p < numPoints; p++) { 486397e99dd9SToby Isaac const PetscInt point = points[2*p]; 486497e99dd9SToby Isaac const PetscInt *perm = perms ? perms[p] : NULL; 486597e99dd9SToby Isaac const PetscScalar *flip = flips ? flips[p] : NULL; 4866b04c866fSMatthew G. Knepley updatePointFields_private(section, point, perm, flip, f, insert, PETSC_FALSE, clperm, values, &offset, array); 4867e07394fbSMatthew G. Knepley } break; 4868e07394fbSMatthew G. Knepley case INSERT_ALL_VALUES: 486997e99dd9SToby Isaac for (p = 0; p < numPoints; p++) { 487097e99dd9SToby Isaac const PetscInt point = points[2*p]; 487197e99dd9SToby Isaac const PetscInt *perm = perms ? perms[p] : NULL; 487297e99dd9SToby Isaac const PetscScalar *flip = flips ? flips[p] : NULL; 4873b04c866fSMatthew G. Knepley updatePointFields_private(section, point, perm, flip, f, insert, PETSC_TRUE, clperm, values, &offset, array); 4874e07394fbSMatthew G. Knepley } break; 4875e07394fbSMatthew G. Knepley case INSERT_BC_VALUES: 487697e99dd9SToby Isaac for (p = 0; p < numPoints; p++) { 487797e99dd9SToby Isaac const PetscInt point = points[2*p]; 487897e99dd9SToby Isaac const PetscInt *perm = perms ? perms[p] : NULL; 487997e99dd9SToby Isaac const PetscScalar *flip = flips ? flips[p] : NULL; 4880ba322698SMatthew G. Knepley updatePointFieldsBC_private(section, point, perm, flip, f, Ncc, comps, insert, clperm, values, &offset, array); 4881e07394fbSMatthew G. Knepley } break; 4882e07394fbSMatthew G. Knepley case ADD_VALUES: 488397e99dd9SToby Isaac for (p = 0; p < numPoints; p++) { 488497e99dd9SToby Isaac const PetscInt point = points[2*p]; 488597e99dd9SToby Isaac const PetscInt *perm = perms ? perms[p] : NULL; 488697e99dd9SToby Isaac const PetscScalar *flip = flips ? flips[p] : NULL; 4887b04c866fSMatthew G. Knepley updatePointFields_private(section, point, perm, flip, f, add, PETSC_FALSE, clperm, values, &offset, array); 4888e07394fbSMatthew G. Knepley } break; 4889e07394fbSMatthew G. Knepley case ADD_ALL_VALUES: 489097e99dd9SToby Isaac for (p = 0; p < numPoints; p++) { 489197e99dd9SToby Isaac const PetscInt point = points[2*p]; 489297e99dd9SToby Isaac const PetscInt *perm = perms ? perms[p] : NULL; 489397e99dd9SToby Isaac const PetscScalar *flip = flips ? flips[p] : NULL; 4894b04c866fSMatthew G. Knepley updatePointFields_private(section, point, perm, flip, f, add, PETSC_TRUE, clperm, values, &offset, array); 4895e07394fbSMatthew G. Knepley } break; 4896e07394fbSMatthew G. Knepley default: 4897f347f43bSBarry Smith SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insert mode %d", mode); 4898e07394fbSMatthew G. Knepley } 489997e99dd9SToby Isaac ierr = PetscSectionRestoreFieldPointSyms(section,f,numPoints,points,&perms,&flips);CHKERRQ(ierr); 4900e07394fbSMatthew G. Knepley } 4901e07394fbSMatthew G. Knepley /* Cleanup points */ 4902923c78e0SToby Isaac ierr = DMPlexRestoreCompressedClosure(dm,section,point,&numPoints,&points,&clSection,&clPoints,&clp);CHKERRQ(ierr); 4903e07394fbSMatthew G. Knepley /* Cleanup array */ 4904e07394fbSMatthew G. Knepley ierr = VecRestoreArray(v, &array);CHKERRQ(ierr); 4905e07394fbSMatthew G. Knepley PetscFunctionReturn(0); 4906e07394fbSMatthew G. Knepley } 4907e07394fbSMatthew G. Knepley 49087cd05799SMatthew G. Knepley static PetscErrorCode DMPlexPrintMatSetValues(PetscViewer viewer, Mat A, PetscInt point, PetscInt numRIndices, const PetscInt rindices[], PetscInt numCIndices, const PetscInt cindices[], const PetscScalar values[]) 4909552f7358SJed Brown { 4910552f7358SJed Brown PetscMPIInt rank; 4911552f7358SJed Brown PetscInt i, j; 4912552f7358SJed Brown PetscErrorCode ierr; 4913552f7358SJed Brown 4914552f7358SJed Brown PetscFunctionBegin; 491582f516ccSBarry Smith ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)A), &rank);CHKERRQ(ierr); 4916eaf898f9SPatrick Sanan ierr = PetscViewerASCIIPrintf(viewer, "[%d]mat for point %D\n", rank, point);CHKERRQ(ierr); 4917e4b003c7SBarry Smith for (i = 0; i < numRIndices; i++) {ierr = PetscViewerASCIIPrintf(viewer, "[%d]mat row indices[%D] = %D\n", rank, i, rindices[i]);CHKERRQ(ierr);} 4918e4b003c7SBarry Smith for (i = 0; i < numCIndices; i++) {ierr = PetscViewerASCIIPrintf(viewer, "[%d]mat col indices[%D] = %D\n", rank, i, cindices[i]);CHKERRQ(ierr);} 4919b0ecff45SMatthew G. Knepley numCIndices = numCIndices ? numCIndices : numRIndices; 4920b0ecff45SMatthew G. Knepley for (i = 0; i < numRIndices; i++) { 4921e4b003c7SBarry Smith ierr = PetscViewerASCIIPrintf(viewer, "[%d]", rank);CHKERRQ(ierr); 4922b0ecff45SMatthew G. Knepley for (j = 0; j < numCIndices; j++) { 4923519f805aSKarl Rupp #if defined(PETSC_USE_COMPLEX) 49247eba1a17SMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " (%g,%g)", (double)PetscRealPart(values[i*numCIndices+j]), (double)PetscImaginaryPart(values[i*numCIndices+j]));CHKERRQ(ierr); 4925552f7358SJed Brown #else 4926b0ecff45SMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " %g", (double)values[i*numCIndices+j]);CHKERRQ(ierr); 4927552f7358SJed Brown #endif 4928552f7358SJed Brown } 492977a6746dSMatthew G Knepley ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr); 4930552f7358SJed Brown } 4931552f7358SJed Brown PetscFunctionReturn(0); 4932552f7358SJed Brown } 4933552f7358SJed Brown 4934552f7358SJed Brown /* . off - The global offset of this point */ 49354acb8e1eSToby Isaac PetscErrorCode DMPlexGetIndicesPoint_Internal(PetscSection section, PetscInt point, PetscInt off, PetscInt *loff, PetscBool setBC, const PetscInt perm[], PetscInt indices[]) 4936a6dfd86eSKarl Rupp { 4937e6ccafaeSMatthew G Knepley PetscInt dof; /* The number of unknowns on this point */ 4938552f7358SJed Brown PetscInt cdof; /* The number of constraints on this point */ 4939552f7358SJed Brown const PetscInt *cdofs; /* The indices of the constrained dofs on this point */ 4940552f7358SJed Brown PetscInt cind = 0, k; 4941552f7358SJed Brown PetscErrorCode ierr; 4942552f7358SJed Brown 4943552f7358SJed Brown PetscFunctionBegin; 4944552f7358SJed Brown ierr = PetscSectionGetDof(section, point, &dof);CHKERRQ(ierr); 4945552f7358SJed Brown ierr = PetscSectionGetConstraintDof(section, point, &cdof);CHKERRQ(ierr); 4946552f7358SJed Brown if (!cdof || setBC) { 49474acb8e1eSToby Isaac if (perm) { 49484acb8e1eSToby Isaac for (k = 0; k < dof; k++) indices[*loff+perm[k]] = off + k; 4949552f7358SJed Brown } else { 49504acb8e1eSToby Isaac for (k = 0; k < dof; k++) indices[*loff+k] = off + k; 4951552f7358SJed Brown } 4952552f7358SJed Brown } else { 4953552f7358SJed Brown ierr = PetscSectionGetConstraintIndices(section, point, &cdofs);CHKERRQ(ierr); 49544acb8e1eSToby Isaac if (perm) { 49554acb8e1eSToby Isaac for (k = 0; k < dof; ++k) { 49564acb8e1eSToby Isaac if ((cind < cdof) && (k == cdofs[cind])) { 49574acb8e1eSToby Isaac /* Insert check for returning constrained indices */ 49584acb8e1eSToby Isaac indices[*loff+perm[k]] = -(off+k+1); 49594acb8e1eSToby Isaac ++cind; 49604acb8e1eSToby Isaac } else { 49614acb8e1eSToby Isaac indices[*loff+perm[k]] = off+k-cind; 49624acb8e1eSToby Isaac } 49634acb8e1eSToby Isaac } 49644acb8e1eSToby Isaac } else { 4965552f7358SJed Brown for (k = 0; k < dof; ++k) { 4966552f7358SJed Brown if ((cind < cdof) && (k == cdofs[cind])) { 4967552f7358SJed Brown /* Insert check for returning constrained indices */ 4968e6ccafaeSMatthew G Knepley indices[*loff+k] = -(off+k+1); 4969552f7358SJed Brown ++cind; 4970552f7358SJed Brown } else { 4971e6ccafaeSMatthew G Knepley indices[*loff+k] = off+k-cind; 4972552f7358SJed Brown } 4973552f7358SJed Brown } 4974552f7358SJed Brown } 4975552f7358SJed Brown } 4976e6ccafaeSMatthew G Knepley *loff += dof; 4977552f7358SJed Brown PetscFunctionReturn(0); 4978552f7358SJed Brown } 4979552f7358SJed Brown 49807e29afd2SMatthew G. Knepley /* 49817e29afd2SMatthew G. Knepley This version only believes the point offset from the globalSection 49827e29afd2SMatthew G. Knepley 49837e29afd2SMatthew G. Knepley . off - The global offset of this point 49847e29afd2SMatthew G. Knepley */ 49854acb8e1eSToby Isaac PetscErrorCode DMPlexGetIndicesPointFields_Internal(PetscSection section, PetscInt point, PetscInt off, PetscInt foffs[], PetscBool setBC, const PetscInt ***perms, PetscInt permsoff, PetscInt indices[]) 4986a6dfd86eSKarl Rupp { 4987552f7358SJed Brown PetscInt numFields, foff, f; 4988552f7358SJed Brown PetscErrorCode ierr; 4989552f7358SJed Brown 4990552f7358SJed Brown PetscFunctionBegin; 4991552f7358SJed Brown ierr = PetscSectionGetNumFields(section, &numFields);CHKERRQ(ierr); 4992552f7358SJed Brown for (f = 0, foff = 0; f < numFields; ++f) { 49934acb8e1eSToby Isaac PetscInt fdof, cfdof; 4994552f7358SJed Brown const PetscInt *fcdofs; /* The indices of the constrained dofs for field f on this point */ 49954acb8e1eSToby Isaac PetscInt cind = 0, b; 49964acb8e1eSToby Isaac const PetscInt *perm = (perms && perms[f]) ? perms[f][permsoff] : NULL; 4997552f7358SJed Brown 4998552f7358SJed Brown ierr = PetscSectionGetFieldDof(section, point, f, &fdof);CHKERRQ(ierr); 4999552f7358SJed Brown ierr = PetscSectionGetFieldConstraintDof(section, point, f, &cfdof);CHKERRQ(ierr); 5000552f7358SJed Brown if (!cfdof || setBC) { 50014acb8e1eSToby Isaac if (perm) {for (b = 0; b < fdof; b++) {indices[foffs[f]+perm[b]] = off+foff+b;}} 50024acb8e1eSToby Isaac else {for (b = 0; b < fdof; b++) {indices[foffs[f]+ b ] = off+foff+b;}} 5003552f7358SJed Brown } else { 5004552f7358SJed Brown ierr = PetscSectionGetFieldConstraintIndices(section, point, f, &fcdofs);CHKERRQ(ierr); 50054acb8e1eSToby Isaac if (perm) { 50064acb8e1eSToby Isaac for (b = 0; b < fdof; b++) { 50074acb8e1eSToby Isaac if ((cind < cfdof) && (b == fcdofs[cind])) { 50084acb8e1eSToby Isaac indices[foffs[f]+perm[b]] = -(off+foff+b+1); 5009552f7358SJed Brown ++cind; 5010552f7358SJed Brown } else { 50114acb8e1eSToby Isaac indices[foffs[f]+perm[b]] = off+foff+b-cind; 5012552f7358SJed Brown } 5013552f7358SJed Brown } 5014552f7358SJed Brown } else { 50154acb8e1eSToby Isaac for (b = 0; b < fdof; b++) { 50164acb8e1eSToby Isaac if ((cind < cfdof) && (b == fcdofs[cind])) { 50174acb8e1eSToby Isaac indices[foffs[f]+b] = -(off+foff+b+1); 5018552f7358SJed Brown ++cind; 5019552f7358SJed Brown } else { 50204acb8e1eSToby Isaac indices[foffs[f]+b] = off+foff+b-cind; 5021552f7358SJed Brown } 5022552f7358SJed Brown } 5023552f7358SJed Brown } 5024552f7358SJed Brown } 5025a9096520SToby Isaac foff += (setBC ? fdof : (fdof - cfdof)); 5026552f7358SJed Brown foffs[f] += fdof; 5027552f7358SJed Brown } 5028552f7358SJed Brown PetscFunctionReturn(0); 5029552f7358SJed Brown } 5030552f7358SJed Brown 50317e29afd2SMatthew G. Knepley /* 50327e29afd2SMatthew G. Knepley This version believes the globalSection offsets for each field, rather than just the point offset 50337e29afd2SMatthew G. Knepley 50347e29afd2SMatthew G. Knepley . foffs - The offset into 'indices' for each field, since it is segregated by field 50357e29afd2SMatthew G. Knepley */ 50367e29afd2SMatthew G. Knepley PetscErrorCode DMPlexGetIndicesPointFieldsSplit_Internal(PetscSection section, PetscSection globalSection, PetscInt point, PetscInt foffs[], PetscBool setBC, const PetscInt ***perms, PetscInt permsoff, PetscInt indices[]) 50377e29afd2SMatthew G. Knepley { 50387e29afd2SMatthew G. Knepley PetscInt numFields, foff, f; 50397e29afd2SMatthew G. Knepley PetscErrorCode ierr; 50407e29afd2SMatthew G. Knepley 50417e29afd2SMatthew G. Knepley PetscFunctionBegin; 50427e29afd2SMatthew G. Knepley ierr = PetscSectionGetNumFields(section, &numFields);CHKERRQ(ierr); 50437e29afd2SMatthew G. Knepley for (f = 0; f < numFields; ++f) { 50447e29afd2SMatthew G. Knepley PetscInt fdof, cfdof; 50457e29afd2SMatthew G. Knepley const PetscInt *fcdofs; /* The indices of the constrained dofs for field f on this point */ 50467e29afd2SMatthew G. Knepley PetscInt cind = 0, b; 50477e29afd2SMatthew G. Knepley const PetscInt *perm = (perms && perms[f]) ? perms[f][permsoff] : NULL; 50487e29afd2SMatthew G. Knepley 50497e29afd2SMatthew G. Knepley ierr = PetscSectionGetFieldDof(section, point, f, &fdof);CHKERRQ(ierr); 50507e29afd2SMatthew G. Knepley ierr = PetscSectionGetFieldConstraintDof(section, point, f, &cfdof);CHKERRQ(ierr); 50517e29afd2SMatthew G. Knepley ierr = PetscSectionGetFieldOffset(globalSection, point, f, &foff);CHKERRQ(ierr); 50527e29afd2SMatthew G. Knepley if (!cfdof || setBC) { 50537e29afd2SMatthew G. Knepley if (perm) {for (b = 0; b < fdof; b++) {indices[foffs[f]+perm[b]] = foff+b;}} 50547e29afd2SMatthew G. Knepley else {for (b = 0; b < fdof; b++) {indices[foffs[f]+ b ] = foff+b;}} 50557e29afd2SMatthew G. Knepley } else { 50567e29afd2SMatthew G. Knepley ierr = PetscSectionGetFieldConstraintIndices(section, point, f, &fcdofs);CHKERRQ(ierr); 50577e29afd2SMatthew G. Knepley if (perm) { 50587e29afd2SMatthew G. Knepley for (b = 0; b < fdof; b++) { 50597e29afd2SMatthew G. Knepley if ((cind < cfdof) && (b == fcdofs[cind])) { 50607e29afd2SMatthew G. Knepley indices[foffs[f]+perm[b]] = -(foff+b+1); 50617e29afd2SMatthew G. Knepley ++cind; 50627e29afd2SMatthew G. Knepley } else { 50637e29afd2SMatthew G. Knepley indices[foffs[f]+perm[b]] = foff+b-cind; 50647e29afd2SMatthew G. Knepley } 50657e29afd2SMatthew G. Knepley } 50667e29afd2SMatthew G. Knepley } else { 50677e29afd2SMatthew G. Knepley for (b = 0; b < fdof; b++) { 50687e29afd2SMatthew G. Knepley if ((cind < cfdof) && (b == fcdofs[cind])) { 50697e29afd2SMatthew G. Knepley indices[foffs[f]+b] = -(foff+b+1); 50707e29afd2SMatthew G. Knepley ++cind; 50717e29afd2SMatthew G. Knepley } else { 50727e29afd2SMatthew G. Knepley indices[foffs[f]+b] = foff+b-cind; 50737e29afd2SMatthew G. Knepley } 50747e29afd2SMatthew G. Knepley } 50757e29afd2SMatthew G. Knepley } 50767e29afd2SMatthew G. Knepley } 50777e29afd2SMatthew G. Knepley foffs[f] += fdof; 50787e29afd2SMatthew G. Knepley } 50797e29afd2SMatthew G. Knepley PetscFunctionReturn(0); 50807e29afd2SMatthew G. Knepley } 50817e29afd2SMatthew G. Knepley 50824acb8e1eSToby Isaac PetscErrorCode DMPlexAnchorsModifyMat(DM dm, PetscSection section, PetscInt numPoints, PetscInt numIndices, const PetscInt points[], const PetscInt ***perms, const PetscScalar values[], PetscInt *outNumPoints, PetscInt *outNumIndices, PetscInt *outPoints[], PetscScalar *outValues[], PetscInt offsets[], PetscBool multiplyLeft) 5083d3d1a6afSToby Isaac { 5084d3d1a6afSToby Isaac Mat cMat; 5085d3d1a6afSToby Isaac PetscSection aSec, cSec; 5086d3d1a6afSToby Isaac IS aIS; 5087d3d1a6afSToby Isaac PetscInt aStart = -1, aEnd = -1; 5088d3d1a6afSToby Isaac const PetscInt *anchors; 5089e17c06e0SMatthew G. Knepley PetscInt numFields, f, p, q, newP = 0; 5090d3d1a6afSToby Isaac PetscInt newNumPoints = 0, newNumIndices = 0; 5091d3d1a6afSToby Isaac PetscInt *newPoints, *indices, *newIndices; 5092d3d1a6afSToby Isaac PetscInt maxAnchor, maxDof; 5093d3d1a6afSToby Isaac PetscInt newOffsets[32]; 5094d3d1a6afSToby Isaac PetscInt *pointMatOffsets[32]; 5095d3d1a6afSToby Isaac PetscInt *newPointOffsets[32]; 5096d3d1a6afSToby Isaac PetscScalar *pointMat[32]; 50976ecaa68aSToby Isaac PetscScalar *newValues=NULL,*tmpValues; 5098d3d1a6afSToby Isaac PetscBool anyConstrained = PETSC_FALSE; 5099d3d1a6afSToby Isaac PetscErrorCode ierr; 5100d3d1a6afSToby Isaac 5101d3d1a6afSToby Isaac PetscFunctionBegin; 5102d3d1a6afSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5103d3d1a6afSToby Isaac PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 2); 5104d3d1a6afSToby Isaac ierr = PetscSectionGetNumFields(section, &numFields);CHKERRQ(ierr); 5105d3d1a6afSToby Isaac 5106a17985deSToby Isaac ierr = DMPlexGetAnchors(dm,&aSec,&aIS);CHKERRQ(ierr); 5107d3d1a6afSToby Isaac /* if there are point-to-point constraints */ 5108d3d1a6afSToby Isaac if (aSec) { 5109d3d1a6afSToby Isaac ierr = PetscMemzero(newOffsets, 32 * sizeof(PetscInt));CHKERRQ(ierr); 5110d3d1a6afSToby Isaac ierr = ISGetIndices(aIS,&anchors);CHKERRQ(ierr); 5111d3d1a6afSToby Isaac ierr = PetscSectionGetChart(aSec,&aStart,&aEnd);CHKERRQ(ierr); 5112d3d1a6afSToby Isaac /* figure out how many points are going to be in the new element matrix 5113d3d1a6afSToby Isaac * (we allow double counting, because it's all just going to be summed 5114d3d1a6afSToby Isaac * into the global matrix anyway) */ 5115d3d1a6afSToby Isaac for (p = 0; p < 2*numPoints; p+=2) { 5116d3d1a6afSToby Isaac PetscInt b = points[p]; 51174b2f2278SToby Isaac PetscInt bDof = 0, bSecDof; 5118d3d1a6afSToby Isaac 51194b2f2278SToby Isaac ierr = PetscSectionGetDof(section,b,&bSecDof);CHKERRQ(ierr); 51204b2f2278SToby Isaac if (!bSecDof) { 51214b2f2278SToby Isaac continue; 51224b2f2278SToby Isaac } 5123d3d1a6afSToby Isaac if (b >= aStart && b < aEnd) { 5124d3d1a6afSToby Isaac ierr = PetscSectionGetDof(aSec,b,&bDof);CHKERRQ(ierr); 5125d3d1a6afSToby Isaac } 5126d3d1a6afSToby Isaac if (bDof) { 5127d3d1a6afSToby Isaac /* this point is constrained */ 5128d3d1a6afSToby Isaac /* it is going to be replaced by its anchors */ 5129d3d1a6afSToby Isaac PetscInt bOff, q; 5130d3d1a6afSToby Isaac 5131d3d1a6afSToby Isaac anyConstrained = PETSC_TRUE; 5132d3d1a6afSToby Isaac newNumPoints += bDof; 5133d3d1a6afSToby Isaac ierr = PetscSectionGetOffset(aSec,b,&bOff);CHKERRQ(ierr); 5134d3d1a6afSToby Isaac for (q = 0; q < bDof; q++) { 5135d3d1a6afSToby Isaac PetscInt a = anchors[bOff + q]; 5136d3d1a6afSToby Isaac PetscInt aDof; 5137d3d1a6afSToby Isaac 5138d3d1a6afSToby Isaac ierr = PetscSectionGetDof(section,a,&aDof);CHKERRQ(ierr); 5139d3d1a6afSToby Isaac newNumIndices += aDof; 5140d3d1a6afSToby Isaac for (f = 0; f < numFields; ++f) { 5141d3d1a6afSToby Isaac PetscInt fDof; 5142d3d1a6afSToby Isaac 5143d3d1a6afSToby Isaac ierr = PetscSectionGetFieldDof(section, a, f, &fDof);CHKERRQ(ierr); 5144d3d1a6afSToby Isaac newOffsets[f+1] += fDof; 5145d3d1a6afSToby Isaac } 5146d3d1a6afSToby Isaac } 5147d3d1a6afSToby Isaac } 5148d3d1a6afSToby Isaac else { 5149d3d1a6afSToby Isaac /* this point is not constrained */ 5150d3d1a6afSToby Isaac newNumPoints++; 51514b2f2278SToby Isaac newNumIndices += bSecDof; 5152d3d1a6afSToby Isaac for (f = 0; f < numFields; ++f) { 5153d3d1a6afSToby Isaac PetscInt fDof; 5154d3d1a6afSToby Isaac 5155d3d1a6afSToby Isaac ierr = PetscSectionGetFieldDof(section, b, f, &fDof);CHKERRQ(ierr); 5156d3d1a6afSToby Isaac newOffsets[f+1] += fDof; 5157d3d1a6afSToby Isaac } 5158d3d1a6afSToby Isaac } 5159d3d1a6afSToby Isaac } 5160d3d1a6afSToby Isaac } 5161d3d1a6afSToby Isaac if (!anyConstrained) { 516272b80496SMatthew G. Knepley if (outNumPoints) *outNumPoints = 0; 516372b80496SMatthew G. Knepley if (outNumIndices) *outNumIndices = 0; 516472b80496SMatthew G. Knepley if (outPoints) *outPoints = NULL; 516572b80496SMatthew G. Knepley if (outValues) *outValues = NULL; 516672b80496SMatthew G. Knepley if (aSec) {ierr = ISRestoreIndices(aIS,&anchors);CHKERRQ(ierr);} 5167d3d1a6afSToby Isaac PetscFunctionReturn(0); 5168d3d1a6afSToby Isaac } 5169d3d1a6afSToby Isaac 51706ecaa68aSToby Isaac if (outNumPoints) *outNumPoints = newNumPoints; 51716ecaa68aSToby Isaac if (outNumIndices) *outNumIndices = newNumIndices; 51726ecaa68aSToby Isaac 5173f13f9184SToby Isaac for (f = 0; f < numFields; ++f) newOffsets[f+1] += newOffsets[f]; 5174d3d1a6afSToby Isaac 51756ecaa68aSToby Isaac if (!outPoints && !outValues) { 51766ecaa68aSToby Isaac if (offsets) { 51776ecaa68aSToby Isaac for (f = 0; f <= numFields; f++) { 51786ecaa68aSToby Isaac offsets[f] = newOffsets[f]; 51796ecaa68aSToby Isaac } 51806ecaa68aSToby Isaac } 51816ecaa68aSToby Isaac if (aSec) {ierr = ISRestoreIndices(aIS,&anchors);CHKERRQ(ierr);} 51826ecaa68aSToby Isaac PetscFunctionReturn(0); 51836ecaa68aSToby Isaac } 51846ecaa68aSToby Isaac 5185f347f43bSBarry Smith if (numFields && newOffsets[numFields] != newNumIndices) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Invalid size for closure %D should be %D", newOffsets[numFields], newNumIndices); 5186d3d1a6afSToby Isaac 5187f7c74593SToby Isaac ierr = DMGetDefaultConstraints(dm, &cSec, &cMat);CHKERRQ(ierr); 5188d3d1a6afSToby Isaac 5189d3d1a6afSToby Isaac /* workspaces */ 5190d3d1a6afSToby Isaac if (numFields) { 5191d3d1a6afSToby Isaac for (f = 0; f < numFields; f++) { 519269291d52SBarry Smith ierr = DMGetWorkArray(dm,numPoints+1,MPIU_INT,&pointMatOffsets[f]);CHKERRQ(ierr); 519369291d52SBarry Smith ierr = DMGetWorkArray(dm,numPoints+1,MPIU_INT,&newPointOffsets[f]);CHKERRQ(ierr); 5194d3d1a6afSToby Isaac } 5195d3d1a6afSToby Isaac } 5196d3d1a6afSToby Isaac else { 519769291d52SBarry Smith ierr = DMGetWorkArray(dm,numPoints+1,MPIU_INT,&pointMatOffsets[0]);CHKERRQ(ierr); 519869291d52SBarry Smith ierr = DMGetWorkArray(dm,numPoints,MPIU_INT,&newPointOffsets[0]);CHKERRQ(ierr); 5199d3d1a6afSToby Isaac } 5200d3d1a6afSToby Isaac 5201d3d1a6afSToby Isaac /* get workspaces for the point-to-point matrices */ 5202d3d1a6afSToby Isaac if (numFields) { 52034b2f2278SToby Isaac PetscInt totalOffset, totalMatOffset; 52044b2f2278SToby Isaac 5205d3d1a6afSToby Isaac for (p = 0; p < numPoints; p++) { 5206d3d1a6afSToby Isaac PetscInt b = points[2*p]; 52074b2f2278SToby Isaac PetscInt bDof = 0, bSecDof; 5208d3d1a6afSToby Isaac 52094b2f2278SToby Isaac ierr = PetscSectionGetDof(section,b,&bSecDof);CHKERRQ(ierr); 52104b2f2278SToby Isaac if (!bSecDof) { 52114b2f2278SToby Isaac for (f = 0; f < numFields; f++) { 52124b2f2278SToby Isaac newPointOffsets[f][p + 1] = 0; 52134b2f2278SToby Isaac pointMatOffsets[f][p + 1] = 0; 52144b2f2278SToby Isaac } 52154b2f2278SToby Isaac continue; 52164b2f2278SToby Isaac } 5217d3d1a6afSToby Isaac if (b >= aStart && b < aEnd) { 5218d3d1a6afSToby Isaac ierr = PetscSectionGetDof(aSec, b, &bDof);CHKERRQ(ierr); 5219d3d1a6afSToby Isaac } 5220d3d1a6afSToby Isaac if (bDof) { 5221d3d1a6afSToby Isaac for (f = 0; f < numFields; f++) { 5222d3d1a6afSToby Isaac PetscInt fDof, q, bOff, allFDof = 0; 5223d3d1a6afSToby Isaac 5224d3d1a6afSToby Isaac ierr = PetscSectionGetFieldDof(section, b, f, &fDof);CHKERRQ(ierr); 5225d3d1a6afSToby Isaac ierr = PetscSectionGetOffset(aSec, b, &bOff);CHKERRQ(ierr); 5226d3d1a6afSToby Isaac for (q = 0; q < bDof; q++) { 5227d3d1a6afSToby Isaac PetscInt a = anchors[bOff + q]; 5228d3d1a6afSToby Isaac PetscInt aFDof; 5229d3d1a6afSToby Isaac 5230d3d1a6afSToby Isaac ierr = PetscSectionGetFieldDof(section, a, f, &aFDof);CHKERRQ(ierr); 5231d3d1a6afSToby Isaac allFDof += aFDof; 5232d3d1a6afSToby Isaac } 5233d3d1a6afSToby Isaac newPointOffsets[f][p+1] = allFDof; 5234d3d1a6afSToby Isaac pointMatOffsets[f][p+1] = fDof * allFDof; 5235d3d1a6afSToby Isaac } 5236d3d1a6afSToby Isaac } 5237d3d1a6afSToby Isaac else { 5238d3d1a6afSToby Isaac for (f = 0; f < numFields; f++) { 5239d3d1a6afSToby Isaac PetscInt fDof; 5240d3d1a6afSToby Isaac 5241d3d1a6afSToby Isaac ierr = PetscSectionGetFieldDof(section, b, f, &fDof);CHKERRQ(ierr); 5242d3d1a6afSToby Isaac newPointOffsets[f][p+1] = fDof; 5243d3d1a6afSToby Isaac pointMatOffsets[f][p+1] = 0; 5244d3d1a6afSToby Isaac } 5245d3d1a6afSToby Isaac } 5246d3d1a6afSToby Isaac } 52474b2f2278SToby Isaac for (f = 0, totalOffset = 0, totalMatOffset = 0; f < numFields; f++) { 52484b2f2278SToby Isaac newPointOffsets[f][0] = totalOffset; 52494b2f2278SToby Isaac pointMatOffsets[f][0] = totalMatOffset; 5250d3d1a6afSToby Isaac for (p = 0; p < numPoints; p++) { 5251d3d1a6afSToby Isaac newPointOffsets[f][p+1] += newPointOffsets[f][p]; 5252d3d1a6afSToby Isaac pointMatOffsets[f][p+1] += pointMatOffsets[f][p]; 5253d3d1a6afSToby Isaac } 525419f70fd5SToby Isaac totalOffset = newPointOffsets[f][numPoints]; 525519f70fd5SToby Isaac totalMatOffset = pointMatOffsets[f][numPoints]; 525669291d52SBarry Smith ierr = DMGetWorkArray(dm,pointMatOffsets[f][numPoints],MPIU_SCALAR,&pointMat[f]);CHKERRQ(ierr); 5257d3d1a6afSToby Isaac } 5258d3d1a6afSToby Isaac } 5259d3d1a6afSToby Isaac else { 5260d3d1a6afSToby Isaac for (p = 0; p < numPoints; p++) { 5261d3d1a6afSToby Isaac PetscInt b = points[2*p]; 52624b2f2278SToby Isaac PetscInt bDof = 0, bSecDof; 5263d3d1a6afSToby Isaac 52644b2f2278SToby Isaac ierr = PetscSectionGetDof(section,b,&bSecDof);CHKERRQ(ierr); 52654b2f2278SToby Isaac if (!bSecDof) { 52664b2f2278SToby Isaac newPointOffsets[0][p + 1] = 0; 52674b2f2278SToby Isaac pointMatOffsets[0][p + 1] = 0; 52684b2f2278SToby Isaac continue; 52694b2f2278SToby Isaac } 5270d3d1a6afSToby Isaac if (b >= aStart && b < aEnd) { 5271d3d1a6afSToby Isaac ierr = PetscSectionGetDof(aSec, b, &bDof);CHKERRQ(ierr); 5272d3d1a6afSToby Isaac } 5273d3d1a6afSToby Isaac if (bDof) { 52744b2f2278SToby Isaac PetscInt bOff, q, allDof = 0; 5275d3d1a6afSToby Isaac 5276d3d1a6afSToby Isaac ierr = PetscSectionGetOffset(aSec, b, &bOff);CHKERRQ(ierr); 5277d3d1a6afSToby Isaac for (q = 0; q < bDof; q++) { 5278d3d1a6afSToby Isaac PetscInt a = anchors[bOff + q], aDof; 5279d3d1a6afSToby Isaac 5280d3d1a6afSToby Isaac ierr = PetscSectionGetDof(section, a, &aDof);CHKERRQ(ierr); 5281d3d1a6afSToby Isaac allDof += aDof; 5282d3d1a6afSToby Isaac } 5283d3d1a6afSToby Isaac newPointOffsets[0][p+1] = allDof; 52844b2f2278SToby Isaac pointMatOffsets[0][p+1] = bSecDof * allDof; 5285d3d1a6afSToby Isaac } 5286d3d1a6afSToby Isaac else { 52874b2f2278SToby Isaac newPointOffsets[0][p+1] = bSecDof; 5288d3d1a6afSToby Isaac pointMatOffsets[0][p+1] = 0; 5289d3d1a6afSToby Isaac } 5290d3d1a6afSToby Isaac } 5291d3d1a6afSToby Isaac newPointOffsets[0][0] = 0; 5292d3d1a6afSToby Isaac pointMatOffsets[0][0] = 0; 5293d3d1a6afSToby Isaac for (p = 0; p < numPoints; p++) { 5294d3d1a6afSToby Isaac newPointOffsets[0][p+1] += newPointOffsets[0][p]; 5295d3d1a6afSToby Isaac pointMatOffsets[0][p+1] += pointMatOffsets[0][p]; 5296d3d1a6afSToby Isaac } 529769291d52SBarry Smith ierr = DMGetWorkArray(dm,pointMatOffsets[0][numPoints],MPIU_SCALAR,&pointMat[0]);CHKERRQ(ierr); 5298d3d1a6afSToby Isaac } 5299d3d1a6afSToby Isaac 53006ecaa68aSToby Isaac /* output arrays */ 530169291d52SBarry Smith ierr = DMGetWorkArray(dm,2*newNumPoints,MPIU_INT,&newPoints);CHKERRQ(ierr); 53026ecaa68aSToby Isaac 5303d3d1a6afSToby Isaac /* get the point-to-point matrices; construct newPoints */ 5304d3d1a6afSToby Isaac ierr = PetscSectionGetMaxDof(aSec, &maxAnchor);CHKERRQ(ierr); 5305d3d1a6afSToby Isaac ierr = PetscSectionGetMaxDof(section, &maxDof);CHKERRQ(ierr); 530669291d52SBarry Smith ierr = DMGetWorkArray(dm,maxDof,MPIU_INT,&indices);CHKERRQ(ierr); 530769291d52SBarry Smith ierr = DMGetWorkArray(dm,maxAnchor*maxDof,MPIU_INT,&newIndices);CHKERRQ(ierr); 5308d3d1a6afSToby Isaac if (numFields) { 5309d3d1a6afSToby Isaac for (p = 0, newP = 0; p < numPoints; p++) { 5310d3d1a6afSToby Isaac PetscInt b = points[2*p]; 5311d3d1a6afSToby Isaac PetscInt o = points[2*p+1]; 53124b2f2278SToby Isaac PetscInt bDof = 0, bSecDof; 5313d3d1a6afSToby Isaac 53144b2f2278SToby Isaac ierr = PetscSectionGetDof(section, b, &bSecDof);CHKERRQ(ierr); 53154b2f2278SToby Isaac if (!bSecDof) { 53164b2f2278SToby Isaac continue; 53174b2f2278SToby Isaac } 5318d3d1a6afSToby Isaac if (b >= aStart && b < aEnd) { 5319d3d1a6afSToby Isaac ierr = PetscSectionGetDof(aSec, b, &bDof);CHKERRQ(ierr); 5320d3d1a6afSToby Isaac } 5321d3d1a6afSToby Isaac if (bDof) { 5322d3d1a6afSToby Isaac PetscInt fStart[32], fEnd[32], fAnchorStart[32], fAnchorEnd[32], bOff, q; 5323d3d1a6afSToby Isaac 5324d3d1a6afSToby Isaac fStart[0] = 0; 5325d3d1a6afSToby Isaac fEnd[0] = 0; 5326d3d1a6afSToby Isaac for (f = 0; f < numFields; f++) { 5327d3d1a6afSToby Isaac PetscInt fDof; 5328d3d1a6afSToby Isaac 5329d3d1a6afSToby Isaac ierr = PetscSectionGetFieldDof(cSec, b, f, &fDof);CHKERRQ(ierr); 5330d3d1a6afSToby Isaac fStart[f+1] = fStart[f] + fDof; 5331d3d1a6afSToby Isaac fEnd[f+1] = fStart[f+1]; 5332d3d1a6afSToby Isaac } 5333d3d1a6afSToby Isaac ierr = PetscSectionGetOffset(cSec, b, &bOff);CHKERRQ(ierr); 53344acb8e1eSToby Isaac ierr = DMPlexGetIndicesPointFields_Internal(cSec, b, bOff, fEnd, PETSC_TRUE, perms, p, indices);CHKERRQ(ierr); 5335d3d1a6afSToby Isaac 5336d3d1a6afSToby Isaac fAnchorStart[0] = 0; 5337d3d1a6afSToby Isaac fAnchorEnd[0] = 0; 5338d3d1a6afSToby Isaac for (f = 0; f < numFields; f++) { 5339d3d1a6afSToby Isaac PetscInt fDof = newPointOffsets[f][p + 1] - newPointOffsets[f][p]; 5340d3d1a6afSToby Isaac 5341d3d1a6afSToby Isaac fAnchorStart[f+1] = fAnchorStart[f] + fDof; 5342d3d1a6afSToby Isaac fAnchorEnd[f+1] = fAnchorStart[f + 1]; 5343d3d1a6afSToby Isaac } 5344d3d1a6afSToby Isaac ierr = PetscSectionGetOffset(aSec, b, &bOff);CHKERRQ(ierr); 5345d3d1a6afSToby Isaac for (q = 0; q < bDof; q++) { 5346d3d1a6afSToby Isaac PetscInt a = anchors[bOff + q], aOff; 5347d3d1a6afSToby Isaac 5348d3d1a6afSToby Isaac /* we take the orientation of ap into account in the order that we constructed the indices above: the newly added points have no orientation */ 5349d3d1a6afSToby Isaac newPoints[2*(newP + q)] = a; 5350d3d1a6afSToby Isaac newPoints[2*(newP + q) + 1] = 0; 5351302440fdSBarry Smith ierr = PetscSectionGetOffset(section, a, &aOff);CHKERRQ(ierr); 53524acb8e1eSToby Isaac ierr = DMPlexGetIndicesPointFields_Internal(section, a, aOff, fAnchorEnd, PETSC_TRUE, NULL, -1, newIndices);CHKERRQ(ierr); 5353d3d1a6afSToby Isaac } 5354d3d1a6afSToby Isaac newP += bDof; 5355d3d1a6afSToby Isaac 53566ecaa68aSToby Isaac if (outValues) { 5357d3d1a6afSToby Isaac /* get the point-to-point submatrix */ 5358d3d1a6afSToby Isaac for (f = 0; f < numFields; f++) { 5359d3d1a6afSToby Isaac ierr = MatGetValues(cMat,fEnd[f]-fStart[f],indices + fStart[f],fAnchorEnd[f] - fAnchorStart[f],newIndices + fAnchorStart[f],pointMat[f] + pointMatOffsets[f][p]);CHKERRQ(ierr); 5360d3d1a6afSToby Isaac } 5361d3d1a6afSToby Isaac } 53626ecaa68aSToby Isaac } 5363d3d1a6afSToby Isaac else { 5364d3d1a6afSToby Isaac newPoints[2 * newP] = b; 5365d3d1a6afSToby Isaac newPoints[2 * newP + 1] = o; 5366d3d1a6afSToby Isaac newP++; 5367d3d1a6afSToby Isaac } 5368d3d1a6afSToby Isaac } 5369d3d1a6afSToby Isaac } else { 5370d3d1a6afSToby Isaac for (p = 0; p < numPoints; p++) { 5371d3d1a6afSToby Isaac PetscInt b = points[2*p]; 5372d3d1a6afSToby Isaac PetscInt o = points[2*p+1]; 53734b2f2278SToby Isaac PetscInt bDof = 0, bSecDof; 5374d3d1a6afSToby Isaac 53754b2f2278SToby Isaac ierr = PetscSectionGetDof(section, b, &bSecDof);CHKERRQ(ierr); 53764b2f2278SToby Isaac if (!bSecDof) { 53774b2f2278SToby Isaac continue; 53784b2f2278SToby Isaac } 5379d3d1a6afSToby Isaac if (b >= aStart && b < aEnd) { 5380d3d1a6afSToby Isaac ierr = PetscSectionGetDof(aSec, b, &bDof);CHKERRQ(ierr); 5381d3d1a6afSToby Isaac } 5382d3d1a6afSToby Isaac if (bDof) { 5383d3d1a6afSToby Isaac PetscInt bEnd = 0, bAnchorEnd = 0, bOff; 5384d3d1a6afSToby Isaac 5385d3d1a6afSToby Isaac ierr = PetscSectionGetOffset(cSec, b, &bOff);CHKERRQ(ierr); 53864acb8e1eSToby Isaac ierr = DMPlexGetIndicesPoint_Internal(cSec, b, bOff, &bEnd, PETSC_TRUE, (perms && perms[0]) ? perms[0][p] : NULL, indices);CHKERRQ(ierr); 5387d3d1a6afSToby Isaac 5388d3d1a6afSToby Isaac ierr = PetscSectionGetOffset (aSec, b, &bOff);CHKERRQ(ierr); 5389d3d1a6afSToby Isaac for (q = 0; q < bDof; q++) { 5390d3d1a6afSToby Isaac PetscInt a = anchors[bOff + q], aOff; 5391d3d1a6afSToby Isaac 5392d3d1a6afSToby Isaac /* we take the orientation of ap into account in the order that we constructed the indices above: the newly added points have no orientation */ 5393d3d1a6afSToby Isaac 5394d3d1a6afSToby Isaac newPoints[2*(newP + q)] = a; 5395d3d1a6afSToby Isaac newPoints[2*(newP + q) + 1] = 0; 5396302440fdSBarry Smith ierr = PetscSectionGetOffset(section, a, &aOff);CHKERRQ(ierr); 53974acb8e1eSToby Isaac ierr = DMPlexGetIndicesPoint_Internal(section, a, aOff, &bAnchorEnd, PETSC_TRUE, NULL, newIndices);CHKERRQ(ierr); 5398d3d1a6afSToby Isaac } 5399d3d1a6afSToby Isaac newP += bDof; 5400d3d1a6afSToby Isaac 5401d3d1a6afSToby Isaac /* get the point-to-point submatrix */ 54026ecaa68aSToby Isaac if (outValues) { 5403d3d1a6afSToby Isaac ierr = MatGetValues(cMat,bEnd,indices,bAnchorEnd,newIndices,pointMat[0] + pointMatOffsets[0][p]);CHKERRQ(ierr); 5404d3d1a6afSToby Isaac } 54056ecaa68aSToby Isaac } 5406d3d1a6afSToby Isaac else { 5407d3d1a6afSToby Isaac newPoints[2 * newP] = b; 5408d3d1a6afSToby Isaac newPoints[2 * newP + 1] = o; 5409d3d1a6afSToby Isaac newP++; 5410d3d1a6afSToby Isaac } 5411d3d1a6afSToby Isaac } 5412d3d1a6afSToby Isaac } 5413d3d1a6afSToby Isaac 54146ecaa68aSToby Isaac if (outValues) { 541569291d52SBarry Smith ierr = DMGetWorkArray(dm,newNumIndices*numIndices,MPIU_SCALAR,&tmpValues);CHKERRQ(ierr); 5416d3d1a6afSToby Isaac ierr = PetscMemzero(tmpValues,newNumIndices*numIndices*sizeof(*tmpValues));CHKERRQ(ierr); 5417d3d1a6afSToby Isaac /* multiply constraints on the right */ 5418d3d1a6afSToby Isaac if (numFields) { 5419d3d1a6afSToby Isaac for (f = 0; f < numFields; f++) { 5420d3d1a6afSToby Isaac PetscInt oldOff = offsets[f]; 5421d3d1a6afSToby Isaac 5422d3d1a6afSToby Isaac for (p = 0; p < numPoints; p++) { 5423d3d1a6afSToby Isaac PetscInt cStart = newPointOffsets[f][p]; 5424d3d1a6afSToby Isaac PetscInt b = points[2 * p]; 5425d3d1a6afSToby Isaac PetscInt c, r, k; 5426d3d1a6afSToby Isaac PetscInt dof; 5427d3d1a6afSToby Isaac 5428d3d1a6afSToby Isaac ierr = PetscSectionGetFieldDof(section,b,f,&dof);CHKERRQ(ierr); 54294b2f2278SToby Isaac if (!dof) { 54304b2f2278SToby Isaac continue; 54314b2f2278SToby Isaac } 5432d3d1a6afSToby Isaac if (pointMatOffsets[f][p] < pointMatOffsets[f][p + 1]) { 5433d3d1a6afSToby Isaac PetscInt nCols = newPointOffsets[f][p+1]-cStart; 5434d3d1a6afSToby Isaac const PetscScalar *mat = pointMat[f] + pointMatOffsets[f][p]; 5435d3d1a6afSToby Isaac 5436d3d1a6afSToby Isaac for (r = 0; r < numIndices; r++) { 5437d3d1a6afSToby Isaac for (c = 0; c < nCols; c++) { 5438d3d1a6afSToby Isaac for (k = 0; k < dof; k++) { 54394acb8e1eSToby Isaac tmpValues[r * newNumIndices + cStart + c] += values[r * numIndices + oldOff + k] * mat[k * nCols + c]; 5440d3d1a6afSToby Isaac } 5441d3d1a6afSToby Isaac } 5442d3d1a6afSToby Isaac } 5443d3d1a6afSToby Isaac } 5444d3d1a6afSToby Isaac else { 5445d3d1a6afSToby Isaac /* copy this column as is */ 5446d3d1a6afSToby Isaac for (r = 0; r < numIndices; r++) { 5447d3d1a6afSToby Isaac for (c = 0; c < dof; c++) { 5448d3d1a6afSToby Isaac tmpValues[r * newNumIndices + cStart + c] = values[r * numIndices + oldOff + c]; 5449d3d1a6afSToby Isaac } 5450d3d1a6afSToby Isaac } 5451d3d1a6afSToby Isaac } 5452d3d1a6afSToby Isaac oldOff += dof; 5453d3d1a6afSToby Isaac } 5454d3d1a6afSToby Isaac } 5455d3d1a6afSToby Isaac } 5456d3d1a6afSToby Isaac else { 5457d3d1a6afSToby Isaac PetscInt oldOff = 0; 5458d3d1a6afSToby Isaac for (p = 0; p < numPoints; p++) { 5459d3d1a6afSToby Isaac PetscInt cStart = newPointOffsets[0][p]; 5460d3d1a6afSToby Isaac PetscInt b = points[2 * p]; 5461d3d1a6afSToby Isaac PetscInt c, r, k; 5462d3d1a6afSToby Isaac PetscInt dof; 5463d3d1a6afSToby Isaac 5464d3d1a6afSToby Isaac ierr = PetscSectionGetDof(section,b,&dof);CHKERRQ(ierr); 54654b2f2278SToby Isaac if (!dof) { 54664b2f2278SToby Isaac continue; 54674b2f2278SToby Isaac } 5468d3d1a6afSToby Isaac if (pointMatOffsets[0][p] < pointMatOffsets[0][p + 1]) { 5469d3d1a6afSToby Isaac PetscInt nCols = newPointOffsets[0][p+1]-cStart; 5470d3d1a6afSToby Isaac const PetscScalar *mat = pointMat[0] + pointMatOffsets[0][p]; 5471d3d1a6afSToby Isaac 5472d3d1a6afSToby Isaac for (r = 0; r < numIndices; r++) { 5473d3d1a6afSToby Isaac for (c = 0; c < nCols; c++) { 5474d3d1a6afSToby Isaac for (k = 0; k < dof; k++) { 5475d3d1a6afSToby Isaac tmpValues[r * newNumIndices + cStart + c] += mat[k * nCols + c] * values[r * numIndices + oldOff + k]; 5476d3d1a6afSToby Isaac } 5477d3d1a6afSToby Isaac } 5478d3d1a6afSToby Isaac } 5479d3d1a6afSToby Isaac } 5480d3d1a6afSToby Isaac else { 5481d3d1a6afSToby Isaac /* copy this column as is */ 5482d3d1a6afSToby Isaac for (r = 0; r < numIndices; r++) { 5483d3d1a6afSToby Isaac for (c = 0; c < dof; c++) { 5484d3d1a6afSToby Isaac tmpValues[r * newNumIndices + cStart + c] = values[r * numIndices + oldOff + c]; 5485d3d1a6afSToby Isaac } 5486d3d1a6afSToby Isaac } 5487d3d1a6afSToby Isaac } 5488d3d1a6afSToby Isaac oldOff += dof; 5489d3d1a6afSToby Isaac } 5490d3d1a6afSToby Isaac } 5491d3d1a6afSToby Isaac 54926ecaa68aSToby Isaac if (multiplyLeft) { 549369291d52SBarry Smith ierr = DMGetWorkArray(dm,newNumIndices*newNumIndices,MPIU_SCALAR,&newValues);CHKERRQ(ierr); 5494d3d1a6afSToby Isaac ierr = PetscMemzero(newValues,newNumIndices*newNumIndices*sizeof(*newValues));CHKERRQ(ierr); 5495d3d1a6afSToby Isaac /* multiply constraints transpose on the left */ 5496d3d1a6afSToby Isaac if (numFields) { 5497d3d1a6afSToby Isaac for (f = 0; f < numFields; f++) { 5498d3d1a6afSToby Isaac PetscInt oldOff = offsets[f]; 5499d3d1a6afSToby Isaac 5500d3d1a6afSToby Isaac for (p = 0; p < numPoints; p++) { 5501d3d1a6afSToby Isaac PetscInt rStart = newPointOffsets[f][p]; 5502d3d1a6afSToby Isaac PetscInt b = points[2 * p]; 5503d3d1a6afSToby Isaac PetscInt c, r, k; 5504d3d1a6afSToby Isaac PetscInt dof; 5505d3d1a6afSToby Isaac 5506d3d1a6afSToby Isaac ierr = PetscSectionGetFieldDof(section,b,f,&dof);CHKERRQ(ierr); 5507d3d1a6afSToby Isaac if (pointMatOffsets[f][p] < pointMatOffsets[f][p + 1]) { 5508d3d1a6afSToby Isaac PetscInt nRows = newPointOffsets[f][p+1]-rStart; 5509d3d1a6afSToby Isaac const PetscScalar *PETSC_RESTRICT mat = pointMat[f] + pointMatOffsets[f][p]; 5510d3d1a6afSToby Isaac 5511d3d1a6afSToby Isaac for (r = 0; r < nRows; r++) { 5512d3d1a6afSToby Isaac for (c = 0; c < newNumIndices; c++) { 5513d3d1a6afSToby Isaac for (k = 0; k < dof; k++) { 5514d3d1a6afSToby Isaac newValues[(rStart + r) * newNumIndices + c] += mat[k * nRows + r] * tmpValues[(oldOff + k) * newNumIndices + c]; 5515d3d1a6afSToby Isaac } 5516d3d1a6afSToby Isaac } 5517d3d1a6afSToby Isaac } 5518d3d1a6afSToby Isaac } 5519d3d1a6afSToby Isaac else { 5520d3d1a6afSToby Isaac /* copy this row as is */ 5521d3d1a6afSToby Isaac for (r = 0; r < dof; r++) { 5522d3d1a6afSToby Isaac for (c = 0; c < newNumIndices; c++) { 5523d3d1a6afSToby Isaac newValues[(rStart + r) * newNumIndices + c] = tmpValues[(oldOff + r) * newNumIndices + c]; 5524d3d1a6afSToby Isaac } 5525d3d1a6afSToby Isaac } 5526d3d1a6afSToby Isaac } 5527d3d1a6afSToby Isaac oldOff += dof; 5528d3d1a6afSToby Isaac } 5529d3d1a6afSToby Isaac } 5530d3d1a6afSToby Isaac } 5531d3d1a6afSToby Isaac else { 5532d3d1a6afSToby Isaac PetscInt oldOff = 0; 5533d3d1a6afSToby Isaac 5534d3d1a6afSToby Isaac for (p = 0; p < numPoints; p++) { 5535d3d1a6afSToby Isaac PetscInt rStart = newPointOffsets[0][p]; 5536d3d1a6afSToby Isaac PetscInt b = points[2 * p]; 5537d3d1a6afSToby Isaac PetscInt c, r, k; 5538d3d1a6afSToby Isaac PetscInt dof; 5539d3d1a6afSToby Isaac 5540d3d1a6afSToby Isaac ierr = PetscSectionGetDof(section,b,&dof);CHKERRQ(ierr); 5541d3d1a6afSToby Isaac if (pointMatOffsets[0][p] < pointMatOffsets[0][p + 1]) { 5542d3d1a6afSToby Isaac PetscInt nRows = newPointOffsets[0][p+1]-rStart; 5543d3d1a6afSToby Isaac const PetscScalar *PETSC_RESTRICT mat = pointMat[0] + pointMatOffsets[0][p]; 5544d3d1a6afSToby Isaac 5545d3d1a6afSToby Isaac for (r = 0; r < nRows; r++) { 5546d3d1a6afSToby Isaac for (c = 0; c < newNumIndices; c++) { 5547d3d1a6afSToby Isaac for (k = 0; k < dof; k++) { 5548d3d1a6afSToby Isaac newValues[(rStart + r) * newNumIndices + c] += mat[k * nRows + r] * tmpValues[(oldOff + k) * newNumIndices + c]; 5549d3d1a6afSToby Isaac } 5550d3d1a6afSToby Isaac } 5551d3d1a6afSToby Isaac } 5552d3d1a6afSToby Isaac } 5553d3d1a6afSToby Isaac else { 5554d3d1a6afSToby Isaac /* copy this row as is */ 55559fc93327SToby Isaac for (r = 0; r < dof; r++) { 5556d3d1a6afSToby Isaac for (c = 0; c < newNumIndices; c++) { 5557d3d1a6afSToby Isaac newValues[(rStart + r) * newNumIndices + c] = tmpValues[(oldOff + r) * newNumIndices + c]; 5558d3d1a6afSToby Isaac } 5559d3d1a6afSToby Isaac } 5560d3d1a6afSToby Isaac } 5561d3d1a6afSToby Isaac oldOff += dof; 5562d3d1a6afSToby Isaac } 5563d3d1a6afSToby Isaac } 5564d3d1a6afSToby Isaac 556569291d52SBarry Smith ierr = DMRestoreWorkArray(dm,newNumIndices*numIndices,MPIU_SCALAR,&tmpValues);CHKERRQ(ierr); 55666ecaa68aSToby Isaac } 55676ecaa68aSToby Isaac else { 55686ecaa68aSToby Isaac newValues = tmpValues; 55696ecaa68aSToby Isaac } 55706ecaa68aSToby Isaac } 55716ecaa68aSToby Isaac 5572d3d1a6afSToby Isaac /* clean up */ 557369291d52SBarry Smith ierr = DMRestoreWorkArray(dm,maxDof,MPIU_INT,&indices);CHKERRQ(ierr); 557469291d52SBarry Smith ierr = DMRestoreWorkArray(dm,maxAnchor*maxDof,MPIU_INT,&newIndices);CHKERRQ(ierr); 55756ecaa68aSToby Isaac 5576d3d1a6afSToby Isaac if (numFields) { 5577d3d1a6afSToby Isaac for (f = 0; f < numFields; f++) { 557869291d52SBarry Smith ierr = DMRestoreWorkArray(dm,pointMatOffsets[f][numPoints],MPIU_SCALAR,&pointMat[f]);CHKERRQ(ierr); 557969291d52SBarry Smith ierr = DMRestoreWorkArray(dm,numPoints+1,MPIU_INT,&pointMatOffsets[f]);CHKERRQ(ierr); 558069291d52SBarry Smith ierr = DMRestoreWorkArray(dm,numPoints+1,MPIU_INT,&newPointOffsets[f]);CHKERRQ(ierr); 5581d3d1a6afSToby Isaac } 5582d3d1a6afSToby Isaac } 5583d3d1a6afSToby Isaac else { 558469291d52SBarry Smith ierr = DMRestoreWorkArray(dm,pointMatOffsets[0][numPoints],MPIU_SCALAR,&pointMat[0]);CHKERRQ(ierr); 558569291d52SBarry Smith ierr = DMRestoreWorkArray(dm,numPoints+1,MPIU_INT,&pointMatOffsets[0]);CHKERRQ(ierr); 558669291d52SBarry Smith ierr = DMRestoreWorkArray(dm,numPoints+1,MPIU_INT,&newPointOffsets[0]);CHKERRQ(ierr); 5587d3d1a6afSToby Isaac } 5588d3d1a6afSToby Isaac ierr = ISRestoreIndices(aIS,&anchors);CHKERRQ(ierr); 5589d3d1a6afSToby Isaac 5590d3d1a6afSToby Isaac /* output */ 55916ecaa68aSToby Isaac if (outPoints) { 5592d3d1a6afSToby Isaac *outPoints = newPoints; 55936ecaa68aSToby Isaac } 55946ecaa68aSToby Isaac else { 559569291d52SBarry Smith ierr = DMRestoreWorkArray(dm,2*newNumPoints,MPIU_INT,&newPoints);CHKERRQ(ierr); 55966ecaa68aSToby Isaac } 559731620726SToby Isaac if (outValues) { 5598d3d1a6afSToby Isaac *outValues = newValues; 55996ecaa68aSToby Isaac } 56006ecaa68aSToby Isaac for (f = 0; f <= numFields; f++) { 5601d3d1a6afSToby Isaac offsets[f] = newOffsets[f]; 5602d3d1a6afSToby Isaac } 5603d3d1a6afSToby Isaac PetscFunctionReturn(0); 5604d3d1a6afSToby Isaac } 5605d3d1a6afSToby Isaac 56067cd05799SMatthew G. Knepley /*@C 5607a87adde4SMatthew G. Knepley DMPlexGetClosureIndices - Get the global indices in a vector v for all points in the closure of the given point 56087cd05799SMatthew G. Knepley 56097cd05799SMatthew G. Knepley Not collective 56107cd05799SMatthew G. Knepley 56117cd05799SMatthew G. Knepley Input Parameters: 56127cd05799SMatthew G. Knepley + dm - The DM 56137cd05799SMatthew G. Knepley . section - The section describing the layout in v, or NULL to use the default section 56147cd05799SMatthew G. Knepley . globalSection - The section describing the parallel layout in v, or NULL to use the default section 56157cd05799SMatthew G. Knepley - point - The mesh point 56167cd05799SMatthew G. Knepley 56177cd05799SMatthew G. Knepley Output parameters: 56187cd05799SMatthew G. Knepley + numIndices - The number of indices 56197cd05799SMatthew G. Knepley . indices - The indices 56207cd05799SMatthew G. Knepley - outOffsets - Field offset if not NULL 56217cd05799SMatthew G. Knepley 56227cd05799SMatthew G. Knepley Note: Must call DMPlexRestoreClosureIndices() to free allocated memory 56237cd05799SMatthew G. Knepley 56247cd05799SMatthew G. Knepley Level: advanced 56257cd05799SMatthew G. Knepley 56267cd05799SMatthew G. Knepley .seealso DMPlexRestoreClosureIndices(), DMPlexVecGetClosure(), DMPlexMatSetClosure() 56277cd05799SMatthew G. Knepley @*/ 56286ecaa68aSToby Isaac PetscErrorCode DMPlexGetClosureIndices(DM dm, PetscSection section, PetscSection globalSection, PetscInt point, PetscInt *numIndices, PetscInt **indices, PetscInt *outOffsets) 56297773e69fSMatthew G. Knepley { 56307773e69fSMatthew G. Knepley PetscSection clSection; 56317773e69fSMatthew G. Knepley IS clPoints; 56327773e69fSMatthew G. Knepley const PetscInt *clp; 56334acb8e1eSToby Isaac const PetscInt **perms[32] = {NULL}; 56347773e69fSMatthew G. Knepley PetscInt *points = NULL, *pointsNew; 56357773e69fSMatthew G. Knepley PetscInt numPoints, numPointsNew; 56367773e69fSMatthew G. Knepley PetscInt offsets[32]; 56377773e69fSMatthew G. Knepley PetscInt Nf, Nind, NindNew, off, globalOff, f, p; 56387773e69fSMatthew G. Knepley PetscErrorCode ierr; 56397773e69fSMatthew G. Knepley 56407773e69fSMatthew G. Knepley PetscFunctionBegin; 56417773e69fSMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 56427773e69fSMatthew G. Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 2); 56437773e69fSMatthew G. Knepley PetscValidHeaderSpecific(globalSection, PETSC_SECTION_CLASSID, 3); 56447773e69fSMatthew G. Knepley if (numIndices) PetscValidPointer(numIndices, 4); 56457773e69fSMatthew G. Knepley PetscValidPointer(indices, 5); 56467773e69fSMatthew G. Knepley ierr = PetscSectionGetNumFields(section, &Nf);CHKERRQ(ierr); 56477773e69fSMatthew G. Knepley if (Nf > 31) SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Number of fields %D limited to 31", Nf); 56487773e69fSMatthew G. Knepley ierr = PetscMemzero(offsets, 32 * sizeof(PetscInt));CHKERRQ(ierr); 56497773e69fSMatthew G. Knepley /* Get points in closure */ 5650923c78e0SToby Isaac ierr = DMPlexGetCompressedClosure(dm,section,point,&numPoints,&points,&clSection,&clPoints,&clp);CHKERRQ(ierr); 56517773e69fSMatthew G. Knepley /* Get number of indices and indices per field */ 56527773e69fSMatthew G. Knepley for (p = 0, Nind = 0; p < numPoints*2; p += 2) { 56537773e69fSMatthew G. Knepley PetscInt dof, fdof; 56547773e69fSMatthew G. Knepley 56557773e69fSMatthew G. Knepley ierr = PetscSectionGetDof(section, points[p], &dof);CHKERRQ(ierr); 56567773e69fSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 56577773e69fSMatthew G. Knepley ierr = PetscSectionGetFieldDof(section, points[p], f, &fdof);CHKERRQ(ierr); 56587773e69fSMatthew G. Knepley offsets[f+1] += fdof; 56597773e69fSMatthew G. Knepley } 56607773e69fSMatthew G. Knepley Nind += dof; 56617773e69fSMatthew G. Knepley } 56627773e69fSMatthew G. Knepley for (f = 1; f < Nf; ++f) offsets[f+1] += offsets[f]; 56638ccfff9cSToby Isaac if (Nf && offsets[Nf] != Nind) SETERRQ2(PetscObjectComm((PetscObject) dm), PETSC_ERR_PLIB, "Invalid size for closure %D should be %D", offsets[Nf], Nind); 56644acb8e1eSToby Isaac if (!Nf) offsets[1] = Nind; 56654acb8e1eSToby Isaac /* Get dual space symmetries */ 56664acb8e1eSToby Isaac for (f = 0; f < PetscMax(1,Nf); f++) { 56674acb8e1eSToby Isaac if (Nf) {ierr = PetscSectionGetFieldPointSyms(section,f,numPoints,points,&perms[f],NULL);CHKERRQ(ierr);} 56684acb8e1eSToby Isaac else {ierr = PetscSectionGetPointSyms(section,numPoints,points,&perms[f],NULL);CHKERRQ(ierr);} 56694acb8e1eSToby Isaac } 56707773e69fSMatthew G. Knepley /* Correct for hanging node constraints */ 56717773e69fSMatthew G. Knepley { 56724acb8e1eSToby Isaac ierr = DMPlexAnchorsModifyMat(dm, section, numPoints, Nind, points, perms, NULL, &numPointsNew, &NindNew, &pointsNew, NULL, offsets, PETSC_TRUE);CHKERRQ(ierr); 56737773e69fSMatthew G. Knepley if (numPointsNew) { 56744acb8e1eSToby Isaac for (f = 0; f < PetscMax(1,Nf); f++) { 56754acb8e1eSToby Isaac if (Nf) {ierr = PetscSectionRestoreFieldPointSyms(section,f,numPoints,points,&perms[f],NULL);CHKERRQ(ierr);} 56764acb8e1eSToby Isaac else {ierr = PetscSectionRestorePointSyms(section,numPoints,points,&perms[f],NULL);CHKERRQ(ierr);} 56774acb8e1eSToby Isaac } 56784acb8e1eSToby Isaac for (f = 0; f < PetscMax(1,Nf); f++) { 56794acb8e1eSToby Isaac if (Nf) {ierr = PetscSectionGetFieldPointSyms(section,f,numPointsNew,pointsNew,&perms[f],NULL);CHKERRQ(ierr);} 56804acb8e1eSToby Isaac else {ierr = PetscSectionGetPointSyms(section,numPointsNew,pointsNew,&perms[f],NULL);CHKERRQ(ierr);} 56814acb8e1eSToby Isaac } 5682923c78e0SToby Isaac ierr = DMPlexRestoreCompressedClosure(dm,section,point,&numPoints,&points,&clSection,&clPoints,&clp);CHKERRQ(ierr); 56837773e69fSMatthew G. Knepley numPoints = numPointsNew; 56847773e69fSMatthew G. Knepley Nind = NindNew; 56857773e69fSMatthew G. Knepley points = pointsNew; 56867773e69fSMatthew G. Knepley } 56877773e69fSMatthew G. Knepley } 56887773e69fSMatthew G. Knepley /* Calculate indices */ 568969291d52SBarry Smith ierr = DMGetWorkArray(dm, Nind, MPIU_INT, indices);CHKERRQ(ierr); 56907773e69fSMatthew G. Knepley if (Nf) { 56916ecaa68aSToby Isaac if (outOffsets) { 56926ecaa68aSToby Isaac PetscInt f; 56936ecaa68aSToby Isaac 569446bdb399SToby Isaac for (f = 0; f <= Nf; f++) { 56956ecaa68aSToby Isaac outOffsets[f] = offsets[f]; 56966ecaa68aSToby Isaac } 56976ecaa68aSToby Isaac } 56984acb8e1eSToby Isaac for (p = 0; p < numPoints; p++) { 56994acb8e1eSToby Isaac ierr = PetscSectionGetOffset(globalSection, points[2*p], &globalOff);CHKERRQ(ierr); 57004acb8e1eSToby Isaac DMPlexGetIndicesPointFields_Internal(section, points[2*p], globalOff < 0 ? -(globalOff+1) : globalOff, offsets, PETSC_FALSE, perms, p, *indices); 57017773e69fSMatthew G. Knepley } 57027773e69fSMatthew G. Knepley } else { 57034acb8e1eSToby Isaac for (p = 0, off = 0; p < numPoints; p++) { 57044acb8e1eSToby Isaac const PetscInt *perm = perms[0] ? perms[0][p] : NULL; 57054acb8e1eSToby Isaac 57064acb8e1eSToby Isaac ierr = PetscSectionGetOffset(globalSection, points[2*p], &globalOff);CHKERRQ(ierr); 57074acb8e1eSToby Isaac DMPlexGetIndicesPoint_Internal(section, points[2*p], globalOff < 0 ? -(globalOff+1) : globalOff, &off, PETSC_FALSE, perm, *indices); 57087773e69fSMatthew G. Knepley } 57097773e69fSMatthew G. Knepley } 57107773e69fSMatthew G. Knepley /* Cleanup points */ 57114acb8e1eSToby Isaac for (f = 0; f < PetscMax(1,Nf); f++) { 57124acb8e1eSToby Isaac if (Nf) {ierr = PetscSectionRestoreFieldPointSyms(section,f,numPoints,points,&perms[f],NULL);CHKERRQ(ierr);} 57134acb8e1eSToby Isaac else {ierr = PetscSectionRestorePointSyms(section,numPoints,points,&perms[f],NULL);CHKERRQ(ierr);} 57144acb8e1eSToby Isaac } 57157773e69fSMatthew G. Knepley if (numPointsNew) { 571669291d52SBarry Smith ierr = DMRestoreWorkArray(dm, 2*numPointsNew, MPIU_INT, &pointsNew);CHKERRQ(ierr); 57177773e69fSMatthew G. Knepley } else { 5718923c78e0SToby Isaac ierr = DMPlexRestoreCompressedClosure(dm,section,point,&numPoints,&points,&clSection,&clPoints,&clp);CHKERRQ(ierr); 57197773e69fSMatthew G. Knepley } 57207773e69fSMatthew G. Knepley if (numIndices) *numIndices = Nind; 57217773e69fSMatthew G. Knepley PetscFunctionReturn(0); 57227773e69fSMatthew G. Knepley } 57237773e69fSMatthew G. Knepley 57247cd05799SMatthew G. Knepley /*@C 57257cd05799SMatthew G. Knepley DMPlexRestoreClosureIndices - Restore the indices in a vector v for all points in the closure of the given point 57267cd05799SMatthew G. Knepley 57277cd05799SMatthew G. Knepley Not collective 57287cd05799SMatthew G. Knepley 57297cd05799SMatthew G. Knepley Input Parameters: 57307cd05799SMatthew G. Knepley + dm - The DM 57317cd05799SMatthew G. Knepley . section - The section describing the layout in v, or NULL to use the default section 57327cd05799SMatthew G. Knepley . globalSection - The section describing the parallel layout in v, or NULL to use the default section 57337cd05799SMatthew G. Knepley . point - The mesh point 57347cd05799SMatthew G. Knepley . numIndices - The number of indices 57357cd05799SMatthew G. Knepley . indices - The indices 57367cd05799SMatthew G. Knepley - outOffsets - Field offset if not NULL 57377cd05799SMatthew G. Knepley 57387cd05799SMatthew G. Knepley Level: advanced 57397cd05799SMatthew G. Knepley 57407cd05799SMatthew G. Knepley .seealso DMPlexGetClosureIndices(), DMPlexVecGetClosure(), DMPlexMatSetClosure() 57417cd05799SMatthew G. Knepley @*/ 574246bdb399SToby Isaac PetscErrorCode DMPlexRestoreClosureIndices(DM dm, PetscSection section, PetscSection globalSection, PetscInt point, PetscInt *numIndices, PetscInt **indices,PetscInt *outOffsets) 57437773e69fSMatthew G. Knepley { 57447773e69fSMatthew G. Knepley PetscErrorCode ierr; 57457773e69fSMatthew G. Knepley 57467773e69fSMatthew G. Knepley PetscFunctionBegin; 57477773e69fSMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 57487773e69fSMatthew G. Knepley PetscValidPointer(indices, 5); 574969291d52SBarry Smith ierr = DMRestoreWorkArray(dm, 0, MPIU_INT, indices);CHKERRQ(ierr); 57507773e69fSMatthew G. Knepley PetscFunctionReturn(0); 57517773e69fSMatthew G. Knepley } 57527773e69fSMatthew G. Knepley 57537f5d1fdeSMatthew G. Knepley /*@C 57547f5d1fdeSMatthew G. Knepley DMPlexMatSetClosure - Set an array of the values on the closure of 'point' 57557f5d1fdeSMatthew G. Knepley 57567f5d1fdeSMatthew G. Knepley Not collective 57577f5d1fdeSMatthew G. Knepley 57587f5d1fdeSMatthew G. Knepley Input Parameters: 57597f5d1fdeSMatthew G. Knepley + dm - The DM 5760ebd6d717SJed Brown . section - The section describing the layout in v, or NULL to use the default section 5761ebd6d717SJed Brown . globalSection - The section describing the layout in v, or NULL to use the default global section 57627f5d1fdeSMatthew G. Knepley . A - The matrix 5763eaf898f9SPatrick Sanan . point - The point in the DM 57647f5d1fdeSMatthew G. Knepley . values - The array of values 57657f5d1fdeSMatthew G. Knepley - mode - The insert mode, where INSERT_ALL_VALUES and ADD_ALL_VALUES also overwrite boundary conditions 57667f5d1fdeSMatthew G. Knepley 57677f5d1fdeSMatthew G. Knepley Fortran Notes: 57687f5d1fdeSMatthew G. Knepley This routine is only available in Fortran 90, and you must include petsc.h90 in your code. 57697f5d1fdeSMatthew G. Knepley 57707f5d1fdeSMatthew G. Knepley Level: intermediate 57717f5d1fdeSMatthew G. Knepley 57727f5d1fdeSMatthew G. Knepley .seealso DMPlexVecGetClosure(), DMPlexVecSetClosure() 57737f5d1fdeSMatthew G. Knepley @*/ 57747c1f9639SMatthew G Knepley PetscErrorCode DMPlexMatSetClosure(DM dm, PetscSection section, PetscSection globalSection, Mat A, PetscInt point, const PetscScalar values[], InsertMode mode) 5775552f7358SJed Brown { 5776552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 57771b406b76SMatthew G. Knepley PetscSection clSection; 57781b406b76SMatthew G. Knepley IS clPoints; 5779d3d1a6afSToby Isaac PetscInt *points = NULL, *newPoints; 57801b406b76SMatthew G. Knepley const PetscInt *clp; 5781552f7358SJed Brown PetscInt *indices; 5782552f7358SJed Brown PetscInt offsets[32]; 57834acb8e1eSToby Isaac const PetscInt **perms[32] = {NULL}; 57844acb8e1eSToby Isaac const PetscScalar **flips[32] = {NULL}; 5785923c78e0SToby Isaac PetscInt numFields, numPoints, newNumPoints, numIndices, newNumIndices, dof, off, globalOff, p, f; 57864acb8e1eSToby Isaac PetscScalar *valCopy = NULL; 5787d3d1a6afSToby Isaac PetscScalar *newValues; 5788552f7358SJed Brown PetscErrorCode ierr; 5789552f7358SJed Brown 5790552f7358SJed Brown PetscFunctionBegin; 5791552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5792e87a4003SBarry Smith if (!section) {ierr = DMGetSection(dm, §ion);CHKERRQ(ierr);} 57933dc93601SMatthew G. Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 2); 5794e87a4003SBarry Smith if (!globalSection) {ierr = DMGetGlobalSection(dm, &globalSection);CHKERRQ(ierr);} 57953dc93601SMatthew G. Knepley PetscValidHeaderSpecific(globalSection, PETSC_SECTION_CLASSID, 3); 57963dc93601SMatthew G. Knepley PetscValidHeaderSpecific(A, MAT_CLASSID, 4); 5797552f7358SJed Brown ierr = PetscSectionGetNumFields(section, &numFields);CHKERRQ(ierr); 579882f516ccSBarry Smith if (numFields > 31) SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Number of fields %D limited to 31", numFields); 5799552f7358SJed Brown ierr = PetscMemzero(offsets, 32 * sizeof(PetscInt));CHKERRQ(ierr); 5800923c78e0SToby Isaac ierr = DMPlexGetCompressedClosure(dm,section,point,&numPoints,&points,&clSection,&clPoints,&clp);CHKERRQ(ierr); 5801552f7358SJed Brown for (p = 0, numIndices = 0; p < numPoints*2; p += 2) { 5802552f7358SJed Brown PetscInt fdof; 5803552f7358SJed Brown 5804552f7358SJed Brown ierr = PetscSectionGetDof(section, points[p], &dof);CHKERRQ(ierr); 5805552f7358SJed Brown for (f = 0; f < numFields; ++f) { 5806552f7358SJed Brown ierr = PetscSectionGetFieldDof(section, points[p], f, &fdof);CHKERRQ(ierr); 5807552f7358SJed Brown offsets[f+1] += fdof; 5808552f7358SJed Brown } 5809552f7358SJed Brown numIndices += dof; 5810552f7358SJed Brown } 58110d644c17SKarl Rupp for (f = 1; f < numFields; ++f) offsets[f+1] += offsets[f]; 58120d644c17SKarl Rupp 58138ccfff9cSToby Isaac if (numFields && offsets[numFields] != numIndices) SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "Invalid size for closure %D should be %D", offsets[numFields], numIndices); 58144acb8e1eSToby Isaac /* Get symmetries */ 58154acb8e1eSToby Isaac for (f = 0; f < PetscMax(1,numFields); f++) { 58164acb8e1eSToby Isaac if (numFields) {ierr = PetscSectionGetFieldPointSyms(section,f,numPoints,points,&perms[f],&flips[f]);CHKERRQ(ierr);} 58174acb8e1eSToby Isaac else {ierr = PetscSectionGetPointSyms(section,numPoints,points,&perms[f],&flips[f]);CHKERRQ(ierr);} 58184acb8e1eSToby Isaac if (values && flips[f]) { /* may need to apply sign changes to the element matrix */ 58194acb8e1eSToby Isaac PetscInt foffset = offsets[f]; 58204acb8e1eSToby Isaac 58214acb8e1eSToby Isaac for (p = 0; p < numPoints; p++) { 58224acb8e1eSToby Isaac PetscInt point = points[2*p], fdof; 58234acb8e1eSToby Isaac const PetscScalar *flip = flips[f] ? flips[f][p] : NULL; 58244acb8e1eSToby Isaac 58254acb8e1eSToby Isaac if (!numFields) { 58264acb8e1eSToby Isaac ierr = PetscSectionGetDof(section,point,&fdof);CHKERRQ(ierr); 58274acb8e1eSToby Isaac } else { 58284acb8e1eSToby Isaac ierr = PetscSectionGetFieldDof(section,point,f,&fdof);CHKERRQ(ierr); 58294acb8e1eSToby Isaac } 58304acb8e1eSToby Isaac if (flip) { 58314acb8e1eSToby Isaac PetscInt i, j, k; 58324acb8e1eSToby Isaac 58334acb8e1eSToby Isaac if (!valCopy) { 583469291d52SBarry Smith ierr = DMGetWorkArray(dm,numIndices*numIndices,MPIU_SCALAR,&valCopy);CHKERRQ(ierr); 58354acb8e1eSToby Isaac for (j = 0; j < numIndices * numIndices; j++) valCopy[j] = values[j]; 58364acb8e1eSToby Isaac values = valCopy; 58374acb8e1eSToby Isaac } 58384acb8e1eSToby Isaac for (i = 0; i < fdof; i++) { 5839775f7be2SToby Isaac PetscScalar fval = flip[i]; 58404acb8e1eSToby Isaac 58414acb8e1eSToby Isaac for (k = 0; k < numIndices; k++) { 58424acb8e1eSToby Isaac valCopy[numIndices * (foffset + i) + k] *= fval; 58434acb8e1eSToby Isaac valCopy[numIndices * k + (foffset + i)] *= fval; 58444acb8e1eSToby Isaac } 58454acb8e1eSToby Isaac } 58464acb8e1eSToby Isaac } 58474acb8e1eSToby Isaac foffset += fdof; 58484acb8e1eSToby Isaac } 58494acb8e1eSToby Isaac } 58504acb8e1eSToby Isaac } 58514acb8e1eSToby Isaac ierr = DMPlexAnchorsModifyMat(dm,section,numPoints,numIndices,points,perms,values,&newNumPoints,&newNumIndices,&newPoints,&newValues,offsets,PETSC_TRUE);CHKERRQ(ierr); 5852d3d1a6afSToby Isaac if (newNumPoints) { 58534acb8e1eSToby Isaac if (valCopy) { 585469291d52SBarry Smith ierr = DMRestoreWorkArray(dm,numIndices*numIndices,MPIU_SCALAR,&valCopy);CHKERRQ(ierr); 58554acb8e1eSToby Isaac } 58564acb8e1eSToby Isaac for (f = 0; f < PetscMax(1,numFields); f++) { 58574acb8e1eSToby Isaac if (numFields) {ierr = PetscSectionRestoreFieldPointSyms(section,f,numPoints,points,&perms[f],&flips[f]);CHKERRQ(ierr);} 58584acb8e1eSToby Isaac else {ierr = PetscSectionRestorePointSyms(section,numPoints,points,&perms[f],&flips[f]);CHKERRQ(ierr);} 58594acb8e1eSToby Isaac } 58604acb8e1eSToby Isaac for (f = 0; f < PetscMax(1,numFields); f++) { 58614acb8e1eSToby Isaac if (numFields) {ierr = PetscSectionGetFieldPointSyms(section,f,newNumPoints,newPoints,&perms[f],&flips[f]);CHKERRQ(ierr);} 58624acb8e1eSToby Isaac else {ierr = PetscSectionGetPointSyms(section,newNumPoints,newPoints,&perms[f],&flips[f]);CHKERRQ(ierr);} 58634acb8e1eSToby Isaac } 5864923c78e0SToby Isaac ierr = DMPlexRestoreCompressedClosure(dm,section,point,&numPoints,&points,&clSection,&clPoints,&clp);CHKERRQ(ierr); 5865d3d1a6afSToby Isaac numPoints = newNumPoints; 5866d3d1a6afSToby Isaac numIndices = newNumIndices; 5867d3d1a6afSToby Isaac points = newPoints; 5868d3d1a6afSToby Isaac values = newValues; 5869d3d1a6afSToby Isaac } 587069291d52SBarry Smith ierr = DMGetWorkArray(dm, numIndices, MPIU_INT, &indices);CHKERRQ(ierr); 5871552f7358SJed Brown if (numFields) { 58727e29afd2SMatthew G. Knepley PetscBool useFieldOffsets; 58737e29afd2SMatthew G. Knepley 58747e29afd2SMatthew G. Knepley ierr = PetscSectionGetUseFieldOffsets(globalSection, &useFieldOffsets);CHKERRQ(ierr); 58757e29afd2SMatthew G. Knepley if (useFieldOffsets) { 58767e29afd2SMatthew G. Knepley for (p = 0; p < numPoints; p++) { 58777e29afd2SMatthew G. Knepley DMPlexGetIndicesPointFieldsSplit_Internal(section, globalSection, points[2*p], offsets, PETSC_FALSE, perms, p, indices); 58787e29afd2SMatthew G. Knepley } 58797e29afd2SMatthew G. Knepley } else { 58804acb8e1eSToby Isaac for (p = 0; p < numPoints; p++) { 58814acb8e1eSToby Isaac ierr = PetscSectionGetOffset(globalSection, points[2*p], &globalOff);CHKERRQ(ierr); 58824acb8e1eSToby Isaac DMPlexGetIndicesPointFields_Internal(section, points[2*p], globalOff < 0 ? -(globalOff+1) : globalOff, offsets, PETSC_FALSE, perms, p, indices); 5883552f7358SJed Brown } 58847e29afd2SMatthew G. Knepley } 5885552f7358SJed Brown } else { 58864acb8e1eSToby Isaac for (p = 0, off = 0; p < numPoints; p++) { 58874acb8e1eSToby Isaac const PetscInt *perm = perms[0] ? perms[0][p] : NULL; 58884acb8e1eSToby Isaac ierr = PetscSectionGetOffset(globalSection, points[2*p], &globalOff);CHKERRQ(ierr); 58894acb8e1eSToby Isaac DMPlexGetIndicesPoint_Internal(section, points[2*p], globalOff < 0 ? -(globalOff+1) : globalOff, &off, PETSC_FALSE, perm, indices); 5890552f7358SJed Brown } 5891552f7358SJed Brown } 5892b0ecff45SMatthew G. Knepley if (mesh->printSetValues) {ierr = DMPlexPrintMatSetValues(PETSC_VIEWER_STDOUT_SELF, A, point, numIndices, indices, 0, NULL, values);CHKERRQ(ierr);} 5893552f7358SJed Brown ierr = MatSetValues(A, numIndices, indices, numIndices, indices, values, mode); 5894ab1d0545SMatthew G. Knepley if (mesh->printFEM > 1) { 5895ab1d0545SMatthew G. Knepley PetscInt i; 5896ab1d0545SMatthew G. Knepley ierr = PetscPrintf(PETSC_COMM_SELF, " Indices:");CHKERRQ(ierr); 58978ccfff9cSToby Isaac for (i = 0; i < numIndices; ++i) {ierr = PetscPrintf(PETSC_COMM_SELF, " %D", indices[i]);CHKERRQ(ierr);} 5898ab1d0545SMatthew G. Knepley ierr = PetscPrintf(PETSC_COMM_SELF, "\n");CHKERRQ(ierr); 5899ab1d0545SMatthew G. Knepley } 5900552f7358SJed Brown if (ierr) { 5901552f7358SJed Brown PetscMPIInt rank; 5902552f7358SJed Brown PetscErrorCode ierr2; 5903552f7358SJed Brown 590482f516ccSBarry Smith ierr2 = MPI_Comm_rank(PetscObjectComm((PetscObject)A), &rank);CHKERRQ(ierr2); 5905e4b003c7SBarry Smith ierr2 = (*PetscErrorPrintf)("[%d]ERROR in DMPlexMatSetClosure\n", rank);CHKERRQ(ierr2); 5906b0ecff45SMatthew G. Knepley ierr2 = DMPlexPrintMatSetValues(PETSC_VIEWER_STDERR_SELF, A, point, numIndices, indices, 0, NULL, values);CHKERRQ(ierr2); 590769291d52SBarry Smith ierr2 = DMRestoreWorkArray(dm, numIndices, MPIU_INT, &indices);CHKERRQ(ierr2); 5908552f7358SJed Brown CHKERRQ(ierr); 5909552f7358SJed Brown } 59104acb8e1eSToby Isaac for (f = 0; f < PetscMax(1,numFields); f++) { 59114acb8e1eSToby Isaac if (numFields) {ierr = PetscSectionRestoreFieldPointSyms(section,f,numPoints,points,&perms[f],&flips[f]);CHKERRQ(ierr);} 59124acb8e1eSToby Isaac else {ierr = PetscSectionRestorePointSyms(section,numPoints,points,&perms[f],&flips[f]);CHKERRQ(ierr);} 59134acb8e1eSToby Isaac } 5914d3d1a6afSToby Isaac if (newNumPoints) { 591569291d52SBarry Smith ierr = DMRestoreWorkArray(dm,newNumIndices*newNumIndices,MPIU_SCALAR,&newValues);CHKERRQ(ierr); 591669291d52SBarry Smith ierr = DMRestoreWorkArray(dm,2*newNumPoints,MPIU_INT,&newPoints);CHKERRQ(ierr); 5917d3d1a6afSToby Isaac } 5918d3d1a6afSToby Isaac else { 59194acb8e1eSToby Isaac if (valCopy) { 592069291d52SBarry Smith ierr = DMRestoreWorkArray(dm,numIndices*numIndices,MPIU_SCALAR,&valCopy);CHKERRQ(ierr); 59214acb8e1eSToby Isaac } 5922923c78e0SToby Isaac ierr = DMPlexRestoreCompressedClosure(dm,section,point,&numPoints,&points,&clSection,&clPoints,&clp);CHKERRQ(ierr); 5923d3d1a6afSToby Isaac } 592469291d52SBarry Smith ierr = DMRestoreWorkArray(dm, numIndices, MPIU_INT, &indices);CHKERRQ(ierr); 5925552f7358SJed Brown PetscFunctionReturn(0); 5926552f7358SJed Brown } 5927552f7358SJed Brown 5928de41b84cSMatthew G. Knepley PetscErrorCode DMPlexMatSetClosureRefined(DM dmf, PetscSection fsection, PetscSection globalFSection, DM dmc, PetscSection csection, PetscSection globalCSection, Mat A, PetscInt point, const PetscScalar values[], InsertMode mode) 5929de41b84cSMatthew G. Knepley { 5930de41b84cSMatthew G. Knepley DM_Plex *mesh = (DM_Plex*) dmf->data; 5931de41b84cSMatthew G. Knepley PetscInt *fpoints = NULL, *ftotpoints = NULL; 5932de41b84cSMatthew G. Knepley PetscInt *cpoints = NULL; 5933de41b84cSMatthew G. Knepley PetscInt *findices, *cindices; 5934de41b84cSMatthew G. Knepley PetscInt foffsets[32], coffsets[32]; 5935de41b84cSMatthew G. Knepley CellRefiner cellRefiner; 59364ca5e9f5SMatthew G. Knepley PetscInt numFields, numSubcells, maxFPoints, numFPoints, numCPoints, numFIndices, numCIndices, dof, off, globalOff, pStart, pEnd, p, q, r, s, f; 5937de41b84cSMatthew G. Knepley PetscErrorCode ierr; 5938de41b84cSMatthew G. Knepley 5939de41b84cSMatthew G. Knepley PetscFunctionBegin; 5940de41b84cSMatthew G. Knepley PetscValidHeaderSpecific(dmf, DM_CLASSID, 1); 5941de41b84cSMatthew G. Knepley PetscValidHeaderSpecific(dmc, DM_CLASSID, 4); 5942e87a4003SBarry Smith if (!fsection) {ierr = DMGetSection(dmf, &fsection);CHKERRQ(ierr);} 5943de41b84cSMatthew G. Knepley PetscValidHeaderSpecific(fsection, PETSC_SECTION_CLASSID, 2); 5944e87a4003SBarry Smith if (!csection) {ierr = DMGetSection(dmc, &csection);CHKERRQ(ierr);} 5945de41b84cSMatthew G. Knepley PetscValidHeaderSpecific(csection, PETSC_SECTION_CLASSID, 5); 5946e87a4003SBarry Smith if (!globalFSection) {ierr = DMGetGlobalSection(dmf, &globalFSection);CHKERRQ(ierr);} 5947de41b84cSMatthew G. Knepley PetscValidHeaderSpecific(globalFSection, PETSC_SECTION_CLASSID, 3); 5948e87a4003SBarry Smith if (!globalCSection) {ierr = DMGetGlobalSection(dmc, &globalCSection);CHKERRQ(ierr);} 5949de41b84cSMatthew G. Knepley PetscValidHeaderSpecific(globalCSection, PETSC_SECTION_CLASSID, 6); 5950de41b84cSMatthew G. Knepley PetscValidHeaderSpecific(A, MAT_CLASSID, 7); 5951de41b84cSMatthew G. Knepley ierr = PetscSectionGetNumFields(fsection, &numFields);CHKERRQ(ierr); 5952de41b84cSMatthew G. Knepley if (numFields > 31) SETERRQ1(PetscObjectComm((PetscObject)dmf), PETSC_ERR_ARG_OUTOFRANGE, "Number of fields %D limited to 31", numFields); 5953de41b84cSMatthew G. Knepley ierr = PetscMemzero(foffsets, 32 * sizeof(PetscInt));CHKERRQ(ierr); 5954de41b84cSMatthew G. Knepley ierr = PetscMemzero(coffsets, 32 * sizeof(PetscInt));CHKERRQ(ierr); 5955de41b84cSMatthew G. Knepley /* Column indices */ 5956de41b84cSMatthew G. Knepley ierr = DMPlexGetTransitiveClosure(dmc, point, PETSC_TRUE, &numCPoints, &cpoints);CHKERRQ(ierr); 59574ca5e9f5SMatthew G. Knepley maxFPoints = numCPoints; 5958de41b84cSMatthew G. Knepley /* Compress out points not in the section */ 5959de41b84cSMatthew G. Knepley /* TODO: Squeeze out points with 0 dof as well */ 5960de41b84cSMatthew G. Knepley ierr = PetscSectionGetChart(csection, &pStart, &pEnd);CHKERRQ(ierr); 5961de41b84cSMatthew G. Knepley for (p = 0, q = 0; p < numCPoints*2; p += 2) { 5962de41b84cSMatthew G. Knepley if ((cpoints[p] >= pStart) && (cpoints[p] < pEnd)) { 5963de41b84cSMatthew G. Knepley cpoints[q*2] = cpoints[p]; 5964de41b84cSMatthew G. Knepley cpoints[q*2+1] = cpoints[p+1]; 5965de41b84cSMatthew G. Knepley ++q; 5966de41b84cSMatthew G. Knepley } 5967de41b84cSMatthew G. Knepley } 5968de41b84cSMatthew G. Knepley numCPoints = q; 5969de41b84cSMatthew G. Knepley for (p = 0, numCIndices = 0; p < numCPoints*2; p += 2) { 5970de41b84cSMatthew G. Knepley PetscInt fdof; 5971de41b84cSMatthew G. Knepley 5972de41b84cSMatthew G. Knepley ierr = PetscSectionGetDof(csection, cpoints[p], &dof);CHKERRQ(ierr); 59734ca5e9f5SMatthew G. Knepley if (!dof) continue; 5974de41b84cSMatthew G. Knepley for (f = 0; f < numFields; ++f) { 5975de41b84cSMatthew G. Knepley ierr = PetscSectionGetFieldDof(csection, cpoints[p], f, &fdof);CHKERRQ(ierr); 5976de41b84cSMatthew G. Knepley coffsets[f+1] += fdof; 5977de41b84cSMatthew G. Knepley } 5978de41b84cSMatthew G. Knepley numCIndices += dof; 5979de41b84cSMatthew G. Knepley } 5980de41b84cSMatthew G. Knepley for (f = 1; f < numFields; ++f) coffsets[f+1] += coffsets[f]; 5981de41b84cSMatthew G. Knepley /* Row indices */ 5982de41b84cSMatthew G. Knepley ierr = DMPlexGetCellRefiner_Internal(dmc, &cellRefiner);CHKERRQ(ierr); 5983de41b84cSMatthew G. Knepley ierr = CellRefinerGetAffineTransforms_Internal(cellRefiner, &numSubcells, NULL, NULL, NULL);CHKERRQ(ierr); 598469291d52SBarry Smith ierr = DMGetWorkArray(dmf, maxFPoints*2*numSubcells, MPIU_INT, &ftotpoints);CHKERRQ(ierr); 5985de41b84cSMatthew G. Knepley for (r = 0, q = 0; r < numSubcells; ++r) { 5986de41b84cSMatthew G. Knepley /* TODO Map from coarse to fine cells */ 5987de41b84cSMatthew G. Knepley ierr = DMPlexGetTransitiveClosure(dmf, point*numSubcells + r, PETSC_TRUE, &numFPoints, &fpoints);CHKERRQ(ierr); 5988de41b84cSMatthew G. Knepley /* Compress out points not in the section */ 5989de41b84cSMatthew G. Knepley ierr = PetscSectionGetChart(fsection, &pStart, &pEnd);CHKERRQ(ierr); 5990de41b84cSMatthew G. Knepley for (p = 0; p < numFPoints*2; p += 2) { 5991de41b84cSMatthew G. Knepley if ((fpoints[p] >= pStart) && (fpoints[p] < pEnd)) { 59924ca5e9f5SMatthew G. Knepley ierr = PetscSectionGetDof(fsection, fpoints[p], &dof);CHKERRQ(ierr); 59934ca5e9f5SMatthew G. Knepley if (!dof) continue; 59944ca5e9f5SMatthew G. Knepley for (s = 0; s < q; ++s) if (fpoints[p] == ftotpoints[s*2]) break; 59954ca5e9f5SMatthew G. Knepley if (s < q) continue; 5996de41b84cSMatthew G. Knepley ftotpoints[q*2] = fpoints[p]; 5997de41b84cSMatthew G. Knepley ftotpoints[q*2+1] = fpoints[p+1]; 5998de41b84cSMatthew G. Knepley ++q; 5999de41b84cSMatthew G. Knepley } 6000de41b84cSMatthew G. Knepley } 6001de41b84cSMatthew G. Knepley ierr = DMPlexRestoreTransitiveClosure(dmf, point, PETSC_TRUE, &numFPoints, &fpoints);CHKERRQ(ierr); 6002de41b84cSMatthew G. Knepley } 6003de41b84cSMatthew G. Knepley numFPoints = q; 6004de41b84cSMatthew G. Knepley for (p = 0, numFIndices = 0; p < numFPoints*2; p += 2) { 6005de41b84cSMatthew G. Knepley PetscInt fdof; 6006de41b84cSMatthew G. Knepley 6007de41b84cSMatthew G. Knepley ierr = PetscSectionGetDof(fsection, ftotpoints[p], &dof);CHKERRQ(ierr); 60084ca5e9f5SMatthew G. Knepley if (!dof) continue; 6009de41b84cSMatthew G. Knepley for (f = 0; f < numFields; ++f) { 6010de41b84cSMatthew G. Knepley ierr = PetscSectionGetFieldDof(fsection, ftotpoints[p], f, &fdof);CHKERRQ(ierr); 6011de41b84cSMatthew G. Knepley foffsets[f+1] += fdof; 6012de41b84cSMatthew G. Knepley } 6013de41b84cSMatthew G. Knepley numFIndices += dof; 6014de41b84cSMatthew G. Knepley } 6015de41b84cSMatthew G. Knepley for (f = 1; f < numFields; ++f) foffsets[f+1] += foffsets[f]; 6016de41b84cSMatthew G. Knepley 60178ccfff9cSToby Isaac if (numFields && foffsets[numFields] != numFIndices) SETERRQ2(PetscObjectComm((PetscObject)dmf), PETSC_ERR_PLIB, "Invalid size for closure %D should be %D", foffsets[numFields], numFIndices); 60188ccfff9cSToby Isaac if (numFields && coffsets[numFields] != numCIndices) SETERRQ2(PetscObjectComm((PetscObject)dmc), PETSC_ERR_PLIB, "Invalid size for closure %D should be %D", coffsets[numFields], numCIndices); 601969291d52SBarry Smith ierr = DMGetWorkArray(dmf, numFIndices, MPIU_INT, &findices);CHKERRQ(ierr); 602069291d52SBarry Smith ierr = DMGetWorkArray(dmc, numCIndices, MPIU_INT, &cindices);CHKERRQ(ierr); 6021de41b84cSMatthew G. Knepley if (numFields) { 60224acb8e1eSToby Isaac const PetscInt **permsF[32] = {NULL}; 60234acb8e1eSToby Isaac const PetscInt **permsC[32] = {NULL}; 60244acb8e1eSToby Isaac 60254acb8e1eSToby Isaac for (f = 0; f < numFields; f++) { 60264acb8e1eSToby Isaac ierr = PetscSectionGetFieldPointSyms(fsection,f,numFPoints,ftotpoints,&permsF[f],NULL);CHKERRQ(ierr); 60274acb8e1eSToby Isaac ierr = PetscSectionGetFieldPointSyms(csection,f,numCPoints,cpoints,&permsC[f],NULL);CHKERRQ(ierr); 6028de41b84cSMatthew G. Knepley } 60294acb8e1eSToby Isaac for (p = 0; p < numFPoints; p++) { 60304acb8e1eSToby Isaac ierr = PetscSectionGetOffset(globalFSection, ftotpoints[2*p], &globalOff);CHKERRQ(ierr); 60314acb8e1eSToby Isaac DMPlexGetIndicesPointFields_Internal(fsection, ftotpoints[2*p], globalOff < 0 ? -(globalOff+1) : globalOff, foffsets, PETSC_FALSE, permsF, p, findices); 60324acb8e1eSToby Isaac } 60334acb8e1eSToby Isaac for (p = 0; p < numCPoints; p++) { 60344acb8e1eSToby Isaac ierr = PetscSectionGetOffset(globalCSection, cpoints[2*p], &globalOff);CHKERRQ(ierr); 60354acb8e1eSToby Isaac DMPlexGetIndicesPointFields_Internal(csection, cpoints[2*p], globalOff < 0 ? -(globalOff+1) : globalOff, coffsets, PETSC_FALSE, permsC, p, cindices); 60364acb8e1eSToby Isaac } 60374acb8e1eSToby Isaac for (f = 0; f < numFields; f++) { 60384acb8e1eSToby Isaac ierr = PetscSectionRestoreFieldPointSyms(fsection,f,numFPoints,ftotpoints,&permsF[f],NULL);CHKERRQ(ierr); 60394acb8e1eSToby Isaac ierr = PetscSectionRestoreFieldPointSyms(csection,f,numCPoints,cpoints,&permsC[f],NULL);CHKERRQ(ierr); 6040de41b84cSMatthew G. Knepley } 6041de41b84cSMatthew G. Knepley } else { 60424acb8e1eSToby Isaac const PetscInt **permsF = NULL; 60434acb8e1eSToby Isaac const PetscInt **permsC = NULL; 60444acb8e1eSToby Isaac 60454acb8e1eSToby Isaac ierr = PetscSectionGetPointSyms(fsection,numFPoints,ftotpoints,&permsF,NULL);CHKERRQ(ierr); 60464acb8e1eSToby Isaac ierr = PetscSectionGetPointSyms(csection,numCPoints,cpoints,&permsC,NULL);CHKERRQ(ierr); 60474acb8e1eSToby Isaac for (p = 0, off = 0; p < numFPoints; p++) { 60484acb8e1eSToby Isaac const PetscInt *perm = permsF ? permsF[p] : NULL; 60494acb8e1eSToby Isaac 60504acb8e1eSToby Isaac ierr = PetscSectionGetOffset(globalFSection, ftotpoints[2*p], &globalOff);CHKERRQ(ierr); 60514acb8e1eSToby Isaac ierr = DMPlexGetIndicesPoint_Internal(fsection, ftotpoints[2*p], globalOff < 0 ? -(globalOff+1) : globalOff, &off, PETSC_FALSE, perm, findices);CHKERRQ(ierr); 6052de41b84cSMatthew G. Knepley } 60534acb8e1eSToby Isaac for (p = 0, off = 0; p < numCPoints; p++) { 60544acb8e1eSToby Isaac const PetscInt *perm = permsC ? permsC[p] : NULL; 60554acb8e1eSToby Isaac 60564acb8e1eSToby Isaac ierr = PetscSectionGetOffset(globalCSection, cpoints[2*p], &globalOff);CHKERRQ(ierr); 60574acb8e1eSToby Isaac ierr = DMPlexGetIndicesPoint_Internal(csection, cpoints[2*p], globalOff < 0 ? -(globalOff+1) : globalOff, &off, PETSC_FALSE, perm, cindices);CHKERRQ(ierr); 6058de41b84cSMatthew G. Knepley } 60594acb8e1eSToby Isaac ierr = PetscSectionRestorePointSyms(fsection,numFPoints,ftotpoints,&permsF,NULL);CHKERRQ(ierr); 60604acb8e1eSToby Isaac ierr = PetscSectionRestorePointSyms(csection,numCPoints,cpoints,&permsC,NULL);CHKERRQ(ierr); 6061de41b84cSMatthew G. Knepley } 6062de41b84cSMatthew G. Knepley if (mesh->printSetValues) {ierr = DMPlexPrintMatSetValues(PETSC_VIEWER_STDOUT_SELF, A, point, numFIndices, findices, numCIndices, cindices, values);CHKERRQ(ierr);} 60634acb8e1eSToby Isaac /* TODO: flips */ 6064de41b84cSMatthew G. Knepley ierr = MatSetValues(A, numFIndices, findices, numCIndices, cindices, values, mode); 6065de41b84cSMatthew G. Knepley if (ierr) { 6066de41b84cSMatthew G. Knepley PetscMPIInt rank; 6067de41b84cSMatthew G. Knepley PetscErrorCode ierr2; 6068de41b84cSMatthew G. Knepley 6069de41b84cSMatthew G. Knepley ierr2 = MPI_Comm_rank(PetscObjectComm((PetscObject)A), &rank);CHKERRQ(ierr2); 6070e4b003c7SBarry Smith ierr2 = (*PetscErrorPrintf)("[%d]ERROR in DMPlexMatSetClosure\n", rank);CHKERRQ(ierr2); 6071de41b84cSMatthew G. Knepley ierr2 = DMPlexPrintMatSetValues(PETSC_VIEWER_STDERR_SELF, A, point, numFIndices, findices, numCIndices, cindices, values);CHKERRQ(ierr2); 607269291d52SBarry Smith ierr2 = DMRestoreWorkArray(dmf, numFIndices, MPIU_INT, &findices);CHKERRQ(ierr2); 607369291d52SBarry Smith ierr2 = DMRestoreWorkArray(dmc, numCIndices, MPIU_INT, &cindices);CHKERRQ(ierr2); 6074de41b84cSMatthew G. Knepley CHKERRQ(ierr); 6075de41b84cSMatthew G. Knepley } 607669291d52SBarry Smith ierr = DMRestoreWorkArray(dmf, numCPoints*2*4, MPIU_INT, &ftotpoints);CHKERRQ(ierr); 6077de41b84cSMatthew G. Knepley ierr = DMPlexRestoreTransitiveClosure(dmc, point, PETSC_TRUE, &numCPoints, &cpoints);CHKERRQ(ierr); 607869291d52SBarry Smith ierr = DMRestoreWorkArray(dmf, numFIndices, MPIU_INT, &findices);CHKERRQ(ierr); 607969291d52SBarry Smith ierr = DMRestoreWorkArray(dmc, numCIndices, MPIU_INT, &cindices);CHKERRQ(ierr); 6080de41b84cSMatthew G. Knepley PetscFunctionReturn(0); 6081de41b84cSMatthew G. Knepley } 6082de41b84cSMatthew G. Knepley 60837c927364SMatthew G. Knepley PetscErrorCode DMPlexMatGetClosureIndicesRefined(DM dmf, PetscSection fsection, PetscSection globalFSection, DM dmc, PetscSection csection, PetscSection globalCSection, PetscInt point, PetscInt cindices[], PetscInt findices[]) 60847c927364SMatthew G. Knepley { 60857c927364SMatthew G. Knepley PetscInt *fpoints = NULL, *ftotpoints = NULL; 60867c927364SMatthew G. Knepley PetscInt *cpoints = NULL; 60877c927364SMatthew G. Knepley PetscInt foffsets[32], coffsets[32]; 60887c927364SMatthew G. Knepley CellRefiner cellRefiner; 60897c927364SMatthew G. Knepley PetscInt numFields, numSubcells, maxFPoints, numFPoints, numCPoints, numFIndices, numCIndices, dof, off, globalOff, pStart, pEnd, p, q, r, s, f; 60907c927364SMatthew G. Knepley PetscErrorCode ierr; 60917c927364SMatthew G. Knepley 60927c927364SMatthew G. Knepley PetscFunctionBegin; 60937c927364SMatthew G. Knepley PetscValidHeaderSpecific(dmf, DM_CLASSID, 1); 60947c927364SMatthew G. Knepley PetscValidHeaderSpecific(dmc, DM_CLASSID, 4); 6095e87a4003SBarry Smith if (!fsection) {ierr = DMGetSection(dmf, &fsection);CHKERRQ(ierr);} 60967c927364SMatthew G. Knepley PetscValidHeaderSpecific(fsection, PETSC_SECTION_CLASSID, 2); 6097e87a4003SBarry Smith if (!csection) {ierr = DMGetSection(dmc, &csection);CHKERRQ(ierr);} 60987c927364SMatthew G. Knepley PetscValidHeaderSpecific(csection, PETSC_SECTION_CLASSID, 5); 6099e87a4003SBarry Smith if (!globalFSection) {ierr = DMGetGlobalSection(dmf, &globalFSection);CHKERRQ(ierr);} 61007c927364SMatthew G. Knepley PetscValidHeaderSpecific(globalFSection, PETSC_SECTION_CLASSID, 3); 6101e87a4003SBarry Smith if (!globalCSection) {ierr = DMGetGlobalSection(dmc, &globalCSection);CHKERRQ(ierr);} 61027c927364SMatthew G. Knepley PetscValidHeaderSpecific(globalCSection, PETSC_SECTION_CLASSID, 6); 61037c927364SMatthew G. Knepley ierr = PetscSectionGetNumFields(fsection, &numFields);CHKERRQ(ierr); 61047c927364SMatthew G. Knepley if (numFields > 31) SETERRQ1(PetscObjectComm((PetscObject)dmf), PETSC_ERR_ARG_OUTOFRANGE, "Number of fields %D limited to 31", numFields); 61057c927364SMatthew G. Knepley ierr = PetscMemzero(foffsets, 32 * sizeof(PetscInt));CHKERRQ(ierr); 61067c927364SMatthew G. Knepley ierr = PetscMemzero(coffsets, 32 * sizeof(PetscInt));CHKERRQ(ierr); 61077c927364SMatthew G. Knepley /* Column indices */ 61087c927364SMatthew G. Knepley ierr = DMPlexGetTransitiveClosure(dmc, point, PETSC_TRUE, &numCPoints, &cpoints);CHKERRQ(ierr); 61097c927364SMatthew G. Knepley maxFPoints = numCPoints; 61107c927364SMatthew G. Knepley /* Compress out points not in the section */ 61117c927364SMatthew G. Knepley /* TODO: Squeeze out points with 0 dof as well */ 61127c927364SMatthew G. Knepley ierr = PetscSectionGetChart(csection, &pStart, &pEnd);CHKERRQ(ierr); 61137c927364SMatthew G. Knepley for (p = 0, q = 0; p < numCPoints*2; p += 2) { 61147c927364SMatthew G. Knepley if ((cpoints[p] >= pStart) && (cpoints[p] < pEnd)) { 61157c927364SMatthew G. Knepley cpoints[q*2] = cpoints[p]; 61167c927364SMatthew G. Knepley cpoints[q*2+1] = cpoints[p+1]; 61177c927364SMatthew G. Knepley ++q; 61187c927364SMatthew G. Knepley } 61197c927364SMatthew G. Knepley } 61207c927364SMatthew G. Knepley numCPoints = q; 61217c927364SMatthew G. Knepley for (p = 0, numCIndices = 0; p < numCPoints*2; p += 2) { 61227c927364SMatthew G. Knepley PetscInt fdof; 61237c927364SMatthew G. Knepley 61247c927364SMatthew G. Knepley ierr = PetscSectionGetDof(csection, cpoints[p], &dof);CHKERRQ(ierr); 61257c927364SMatthew G. Knepley if (!dof) continue; 61267c927364SMatthew G. Knepley for (f = 0; f < numFields; ++f) { 61277c927364SMatthew G. Knepley ierr = PetscSectionGetFieldDof(csection, cpoints[p], f, &fdof);CHKERRQ(ierr); 61287c927364SMatthew G. Knepley coffsets[f+1] += fdof; 61297c927364SMatthew G. Knepley } 61307c927364SMatthew G. Knepley numCIndices += dof; 61317c927364SMatthew G. Knepley } 61327c927364SMatthew G. Knepley for (f = 1; f < numFields; ++f) coffsets[f+1] += coffsets[f]; 61337c927364SMatthew G. Knepley /* Row indices */ 61347c927364SMatthew G. Knepley ierr = DMPlexGetCellRefiner_Internal(dmc, &cellRefiner);CHKERRQ(ierr); 61357c927364SMatthew G. Knepley ierr = CellRefinerGetAffineTransforms_Internal(cellRefiner, &numSubcells, NULL, NULL, NULL);CHKERRQ(ierr); 613669291d52SBarry Smith ierr = DMGetWorkArray(dmf, maxFPoints*2*numSubcells, MPIU_INT, &ftotpoints);CHKERRQ(ierr); 61377c927364SMatthew G. Knepley for (r = 0, q = 0; r < numSubcells; ++r) { 61387c927364SMatthew G. Knepley /* TODO Map from coarse to fine cells */ 61397c927364SMatthew G. Knepley ierr = DMPlexGetTransitiveClosure(dmf, point*numSubcells + r, PETSC_TRUE, &numFPoints, &fpoints);CHKERRQ(ierr); 61407c927364SMatthew G. Knepley /* Compress out points not in the section */ 61417c927364SMatthew G. Knepley ierr = PetscSectionGetChart(fsection, &pStart, &pEnd);CHKERRQ(ierr); 61427c927364SMatthew G. Knepley for (p = 0; p < numFPoints*2; p += 2) { 61437c927364SMatthew G. Knepley if ((fpoints[p] >= pStart) && (fpoints[p] < pEnd)) { 61447c927364SMatthew G. Knepley ierr = PetscSectionGetDof(fsection, fpoints[p], &dof);CHKERRQ(ierr); 61457c927364SMatthew G. Knepley if (!dof) continue; 61467c927364SMatthew G. Knepley for (s = 0; s < q; ++s) if (fpoints[p] == ftotpoints[s*2]) break; 61477c927364SMatthew G. Knepley if (s < q) continue; 61487c927364SMatthew G. Knepley ftotpoints[q*2] = fpoints[p]; 61497c927364SMatthew G. Knepley ftotpoints[q*2+1] = fpoints[p+1]; 61507c927364SMatthew G. Knepley ++q; 61517c927364SMatthew G. Knepley } 61527c927364SMatthew G. Knepley } 61537c927364SMatthew G. Knepley ierr = DMPlexRestoreTransitiveClosure(dmf, point, PETSC_TRUE, &numFPoints, &fpoints);CHKERRQ(ierr); 61547c927364SMatthew G. Knepley } 61557c927364SMatthew G. Knepley numFPoints = q; 61567c927364SMatthew G. Knepley for (p = 0, numFIndices = 0; p < numFPoints*2; p += 2) { 61577c927364SMatthew G. Knepley PetscInt fdof; 61587c927364SMatthew G. Knepley 61597c927364SMatthew G. Knepley ierr = PetscSectionGetDof(fsection, ftotpoints[p], &dof);CHKERRQ(ierr); 61607c927364SMatthew G. Knepley if (!dof) continue; 61617c927364SMatthew G. Knepley for (f = 0; f < numFields; ++f) { 61627c927364SMatthew G. Knepley ierr = PetscSectionGetFieldDof(fsection, ftotpoints[p], f, &fdof);CHKERRQ(ierr); 61637c927364SMatthew G. Knepley foffsets[f+1] += fdof; 61647c927364SMatthew G. Knepley } 61657c927364SMatthew G. Knepley numFIndices += dof; 61667c927364SMatthew G. Knepley } 61677c927364SMatthew G. Knepley for (f = 1; f < numFields; ++f) foffsets[f+1] += foffsets[f]; 61687c927364SMatthew G. Knepley 61698ccfff9cSToby Isaac if (numFields && foffsets[numFields] != numFIndices) SETERRQ2(PetscObjectComm((PetscObject)dmf), PETSC_ERR_PLIB, "Invalid size for closure %D should be %D", foffsets[numFields], numFIndices); 61708ccfff9cSToby Isaac if (numFields && coffsets[numFields] != numCIndices) SETERRQ2(PetscObjectComm((PetscObject)dmc), PETSC_ERR_PLIB, "Invalid size for closure %D should be %D", coffsets[numFields], numCIndices); 61717c927364SMatthew G. Knepley if (numFields) { 61724acb8e1eSToby Isaac const PetscInt **permsF[32] = {NULL}; 61734acb8e1eSToby Isaac const PetscInt **permsC[32] = {NULL}; 61744acb8e1eSToby Isaac 61754acb8e1eSToby Isaac for (f = 0; f < numFields; f++) { 61764acb8e1eSToby Isaac ierr = PetscSectionGetFieldPointSyms(fsection,f,numFPoints,ftotpoints,&permsF[f],NULL);CHKERRQ(ierr); 61774acb8e1eSToby Isaac ierr = PetscSectionGetFieldPointSyms(csection,f,numCPoints,cpoints,&permsC[f],NULL);CHKERRQ(ierr); 61787c927364SMatthew G. Knepley } 61794acb8e1eSToby Isaac for (p = 0; p < numFPoints; p++) { 61804acb8e1eSToby Isaac ierr = PetscSectionGetOffset(globalFSection, ftotpoints[2*p], &globalOff);CHKERRQ(ierr); 61814acb8e1eSToby Isaac DMPlexGetIndicesPointFields_Internal(fsection, ftotpoints[2*p], globalOff < 0 ? -(globalOff+1) : globalOff, foffsets, PETSC_FALSE, permsF, p, findices); 61824acb8e1eSToby Isaac } 61834acb8e1eSToby Isaac for (p = 0; p < numCPoints; p++) { 61844acb8e1eSToby Isaac ierr = PetscSectionGetOffset(globalCSection, cpoints[2*p], &globalOff);CHKERRQ(ierr); 61854acb8e1eSToby Isaac DMPlexGetIndicesPointFields_Internal(csection, cpoints[2*p], globalOff < 0 ? -(globalOff+1) : globalOff, coffsets, PETSC_FALSE, permsC, p, cindices); 61864acb8e1eSToby Isaac } 61874acb8e1eSToby Isaac for (f = 0; f < numFields; f++) { 61884acb8e1eSToby Isaac ierr = PetscSectionRestoreFieldPointSyms(fsection,f,numFPoints,ftotpoints,&permsF[f],NULL);CHKERRQ(ierr); 61894acb8e1eSToby Isaac ierr = PetscSectionRestoreFieldPointSyms(csection,f,numCPoints,cpoints,&permsC[f],NULL);CHKERRQ(ierr); 61907c927364SMatthew G. Knepley } 61917c927364SMatthew G. Knepley } else { 61924acb8e1eSToby Isaac const PetscInt **permsF = NULL; 61934acb8e1eSToby Isaac const PetscInt **permsC = NULL; 61944acb8e1eSToby Isaac 61954acb8e1eSToby Isaac ierr = PetscSectionGetPointSyms(fsection,numFPoints,ftotpoints,&permsF,NULL);CHKERRQ(ierr); 61964acb8e1eSToby Isaac ierr = PetscSectionGetPointSyms(csection,numCPoints,cpoints,&permsC,NULL);CHKERRQ(ierr); 61974acb8e1eSToby Isaac for (p = 0, off = 0; p < numFPoints; p++) { 61984acb8e1eSToby Isaac const PetscInt *perm = permsF ? permsF[p] : NULL; 61994acb8e1eSToby Isaac 62004acb8e1eSToby Isaac ierr = PetscSectionGetOffset(globalFSection, ftotpoints[2*p], &globalOff);CHKERRQ(ierr); 62014acb8e1eSToby Isaac DMPlexGetIndicesPoint_Internal(fsection, ftotpoints[2*p], globalOff < 0 ? -(globalOff+1) : globalOff, &off, PETSC_FALSE, perm, findices); 62027c927364SMatthew G. Knepley } 62034acb8e1eSToby Isaac for (p = 0, off = 0; p < numCPoints; p++) { 62044acb8e1eSToby Isaac const PetscInt *perm = permsC ? permsC[p] : NULL; 62054acb8e1eSToby Isaac 62064acb8e1eSToby Isaac ierr = PetscSectionGetOffset(globalCSection, cpoints[2*p], &globalOff);CHKERRQ(ierr); 62074acb8e1eSToby Isaac DMPlexGetIndicesPoint_Internal(csection, cpoints[2*p], globalOff < 0 ? -(globalOff+1) : globalOff, &off, PETSC_FALSE, perm, cindices); 62087c927364SMatthew G. Knepley } 62094acb8e1eSToby Isaac ierr = PetscSectionRestorePointSyms(fsection,numFPoints,ftotpoints,&permsF,NULL);CHKERRQ(ierr); 62104acb8e1eSToby Isaac ierr = PetscSectionRestorePointSyms(csection,numCPoints,cpoints,&permsC,NULL);CHKERRQ(ierr); 62117c927364SMatthew G. Knepley } 621269291d52SBarry Smith ierr = DMRestoreWorkArray(dmf, numCPoints*2*4, MPIU_INT, &ftotpoints);CHKERRQ(ierr); 62137c927364SMatthew G. Knepley ierr = DMPlexRestoreTransitiveClosure(dmc, point, PETSC_TRUE, &numCPoints, &cpoints);CHKERRQ(ierr); 62147c927364SMatthew G. Knepley PetscFunctionReturn(0); 62157c927364SMatthew G. Knepley } 62167c927364SMatthew G. Knepley 6217f96281f8SMatthew G. Knepley /*@ 6218f96281f8SMatthew G. Knepley DMPlexGetHybridBounds - Get the first mesh point of each dimension which is a hybrid 6219f96281f8SMatthew G. Knepley 6220f96281f8SMatthew G. Knepley Input Parameter: 6221f96281f8SMatthew G. Knepley . dm - The DMPlex object 6222f96281f8SMatthew G. Knepley 6223f96281f8SMatthew G. Knepley Output Parameters: 6224f96281f8SMatthew G. Knepley + cMax - The first hybrid cell 6225dc5a3409SMatthew G. Knepley . fMax - The first hybrid face 6226dc5a3409SMatthew G. Knepley . eMax - The first hybrid edge 6227dc5a3409SMatthew G. Knepley - vMax - The first hybrid vertex 6228f96281f8SMatthew G. Knepley 6229f96281f8SMatthew G. Knepley Level: developer 6230f96281f8SMatthew G. Knepley 6231dc5a3409SMatthew G. Knepley .seealso DMPlexCreateHybridMesh(), DMPlexSetHybridBounds() 6232f96281f8SMatthew G. Knepley @*/ 6233770b213bSMatthew G Knepley PetscErrorCode DMPlexGetHybridBounds(DM dm, PetscInt *cMax, PetscInt *fMax, PetscInt *eMax, PetscInt *vMax) 6234552f7358SJed Brown { 6235552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 6236770b213bSMatthew G Knepley PetscInt dim; 6237770b213bSMatthew G Knepley PetscErrorCode ierr; 6238552f7358SJed Brown 6239552f7358SJed Brown PetscFunctionBegin; 6240552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 6241c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 62427d5acc75SStefano Zampini if (dim < 0) SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONGSTATE, "DM dimension not yet set"); 6243770b213bSMatthew G Knepley if (cMax) *cMax = mesh->hybridPointMax[dim]; 62447d5acc75SStefano Zampini if (fMax) *fMax = mesh->hybridPointMax[PetscMax(dim-1,0)]; 6245770b213bSMatthew G Knepley if (eMax) *eMax = mesh->hybridPointMax[1]; 6246770b213bSMatthew G Knepley if (vMax) *vMax = mesh->hybridPointMax[0]; 6247552f7358SJed Brown PetscFunctionReturn(0); 6248552f7358SJed Brown } 6249552f7358SJed Brown 6250aeadca18SToby Isaac static PetscErrorCode DMPlexCreateDimStratum(DM dm, DMLabel depthLabel, DMLabel dimLabel, PetscInt d, PetscInt dMax) 62514a3e9fdbSToby Isaac { 62524a3e9fdbSToby Isaac IS is, his; 62537d5acc75SStefano Zampini PetscInt first = 0, stride; 62544a3e9fdbSToby Isaac PetscBool isStride; 62554a3e9fdbSToby Isaac PetscErrorCode ierr; 62564a3e9fdbSToby Isaac 62574a3e9fdbSToby Isaac PetscFunctionBegin; 62584a3e9fdbSToby Isaac ierr = DMLabelGetStratumIS(depthLabel, d, &is);CHKERRQ(ierr); 62594a3e9fdbSToby Isaac ierr = PetscObjectTypeCompare((PetscObject) is, ISSTRIDE, &isStride);CHKERRQ(ierr); 62604a3e9fdbSToby Isaac if (isStride) { 62614a3e9fdbSToby Isaac ierr = ISStrideGetInfo(is, &first, &stride);CHKERRQ(ierr); 62624a3e9fdbSToby Isaac } 62637d5acc75SStefano Zampini if (is && (!isStride || stride != 1)) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "DM is not stratified: depth %D IS is not contiguous", d); 62644a3e9fdbSToby Isaac ierr = ISCreateStride(PETSC_COMM_SELF, (dMax - first), first, 1, &his);CHKERRQ(ierr); 6265aeadca18SToby Isaac ierr = DMLabelSetStratumIS(dimLabel, d, his);CHKERRQ(ierr); 62664a3e9fdbSToby Isaac ierr = ISDestroy(&his);CHKERRQ(ierr); 62674a3e9fdbSToby Isaac ierr = ISDestroy(&is);CHKERRQ(ierr); 62684a3e9fdbSToby Isaac PetscFunctionReturn(0); 62694a3e9fdbSToby Isaac } 62704a3e9fdbSToby Isaac 6271dc5a3409SMatthew G. Knepley /*@ 6272dc5a3409SMatthew G. Knepley DMPlexSetHybridBounds - Set the first mesh point of each dimension which is a hybrid 6273dc5a3409SMatthew G. Knepley 6274dc5a3409SMatthew G. Knepley Input Parameters: 6275dc5a3409SMatthew G. Knepley . dm - The DMPlex object 6276dc5a3409SMatthew G. Knepley . cMax - The first hybrid cell 6277dc5a3409SMatthew G. Knepley . fMax - The first hybrid face 6278dc5a3409SMatthew G. Knepley . eMax - The first hybrid edge 6279dc5a3409SMatthew G. Knepley - vMax - The first hybrid vertex 6280dc5a3409SMatthew G. Knepley 6281dc5a3409SMatthew G. Knepley Level: developer 6282dc5a3409SMatthew G. Knepley 6283dc5a3409SMatthew G. Knepley .seealso DMPlexCreateHybridMesh(), DMPlexGetHybridBounds() 6284dc5a3409SMatthew G. Knepley @*/ 6285770b213bSMatthew G Knepley PetscErrorCode DMPlexSetHybridBounds(DM dm, PetscInt cMax, PetscInt fMax, PetscInt eMax, PetscInt vMax) 6286552f7358SJed Brown { 6287552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 6288770b213bSMatthew G Knepley PetscInt dim; 6289770b213bSMatthew G Knepley PetscErrorCode ierr; 6290552f7358SJed Brown 6291552f7358SJed Brown PetscFunctionBegin; 6292552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 6293c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 62947d5acc75SStefano Zampini if (dim < 0) SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONGSTATE, "DM dimension not yet set"); 6295770b213bSMatthew G Knepley if (cMax >= 0) mesh->hybridPointMax[dim] = cMax; 62967d5acc75SStefano Zampini if (fMax >= 0) mesh->hybridPointMax[PetscMax(dim-1,0)] = fMax; 6297770b213bSMatthew G Knepley if (eMax >= 0) mesh->hybridPointMax[1] = eMax; 6298770b213bSMatthew G Knepley if (vMax >= 0) mesh->hybridPointMax[0] = vMax; 6299552f7358SJed Brown PetscFunctionReturn(0); 6300552f7358SJed Brown } 6301552f7358SJed Brown 63027cd05799SMatthew G. Knepley /*@C 63037cd05799SMatthew G. Knepley DMPlexGetVTKCellHeight - Returns the height in the DAG used to determine which points are cells (normally 0) 63047cd05799SMatthew G. Knepley 63057cd05799SMatthew G. Knepley Input Parameter: 63067cd05799SMatthew G. Knepley . dm - The DMPlex object 63077cd05799SMatthew G. Knepley 63087cd05799SMatthew G. Knepley Output Parameter: 63097cd05799SMatthew G. Knepley . cellHeight - The height of a cell 63107cd05799SMatthew G. Knepley 63117cd05799SMatthew G. Knepley Level: developer 63127cd05799SMatthew G. Knepley 63137cd05799SMatthew G. Knepley .seealso DMPlexSetVTKCellHeight() 63147cd05799SMatthew G. Knepley @*/ 6315552f7358SJed Brown PetscErrorCode DMPlexGetVTKCellHeight(DM dm, PetscInt *cellHeight) 6316552f7358SJed Brown { 6317552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 6318552f7358SJed Brown 6319552f7358SJed Brown PetscFunctionBegin; 6320552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 6321552f7358SJed Brown PetscValidPointer(cellHeight, 2); 6322552f7358SJed Brown *cellHeight = mesh->vtkCellHeight; 6323552f7358SJed Brown PetscFunctionReturn(0); 6324552f7358SJed Brown } 6325552f7358SJed Brown 63267cd05799SMatthew G. Knepley /*@C 63277cd05799SMatthew G. Knepley DMPlexSetVTKCellHeight - Sets the height in the DAG used to determine which points are cells (normally 0) 63287cd05799SMatthew G. Knepley 63297cd05799SMatthew G. Knepley Input Parameters: 63307cd05799SMatthew G. Knepley + dm - The DMPlex object 63317cd05799SMatthew G. Knepley - cellHeight - The height of a cell 63327cd05799SMatthew G. Knepley 63337cd05799SMatthew G. Knepley Level: developer 63347cd05799SMatthew G. Knepley 63357cd05799SMatthew G. Knepley .seealso DMPlexGetVTKCellHeight() 63367cd05799SMatthew G. Knepley @*/ 6337552f7358SJed Brown PetscErrorCode DMPlexSetVTKCellHeight(DM dm, PetscInt cellHeight) 6338552f7358SJed Brown { 6339552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 6340552f7358SJed Brown 6341552f7358SJed Brown PetscFunctionBegin; 6342552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 6343552f7358SJed Brown mesh->vtkCellHeight = cellHeight; 6344552f7358SJed Brown PetscFunctionReturn(0); 6345552f7358SJed Brown } 6346552f7358SJed Brown 6347552f7358SJed Brown /* We can easily have a form that takes an IS instead */ 6348ef48cebcSMatthew G. Knepley static PetscErrorCode DMPlexCreateNumbering_Private(DM dm, PetscInt pStart, PetscInt pEnd, PetscInt shift, PetscInt *globalSize, PetscSF sf, IS *numbering) 6349552f7358SJed Brown { 6350552f7358SJed Brown PetscSection section, globalSection; 6351552f7358SJed Brown PetscInt *numbers, p; 6352552f7358SJed Brown PetscErrorCode ierr; 6353552f7358SJed Brown 6354552f7358SJed Brown PetscFunctionBegin; 635582f516ccSBarry Smith ierr = PetscSectionCreate(PetscObjectComm((PetscObject)dm), §ion);CHKERRQ(ierr); 6356552f7358SJed Brown ierr = PetscSectionSetChart(section, pStart, pEnd);CHKERRQ(ierr); 6357552f7358SJed Brown for (p = pStart; p < pEnd; ++p) { 6358552f7358SJed Brown ierr = PetscSectionSetDof(section, p, 1);CHKERRQ(ierr); 6359552f7358SJed Brown } 6360552f7358SJed Brown ierr = PetscSectionSetUp(section);CHKERRQ(ierr); 636115b58121SMatthew G. Knepley ierr = PetscSectionCreateGlobalSection(section, sf, PETSC_FALSE, PETSC_FALSE, &globalSection);CHKERRQ(ierr); 6362854ce69bSBarry Smith ierr = PetscMalloc1(pEnd - pStart, &numbers);CHKERRQ(ierr); 6363552f7358SJed Brown for (p = pStart; p < pEnd; ++p) { 6364552f7358SJed Brown ierr = PetscSectionGetOffset(globalSection, p, &numbers[p-pStart]);CHKERRQ(ierr); 6365ef48cebcSMatthew G. Knepley if (numbers[p-pStart] < 0) numbers[p-pStart] -= shift; 6366ef48cebcSMatthew G. Knepley else numbers[p-pStart] += shift; 6367552f7358SJed Brown } 636882f516ccSBarry Smith ierr = ISCreateGeneral(PetscObjectComm((PetscObject) dm), pEnd - pStart, numbers, PETSC_OWN_POINTER, numbering);CHKERRQ(ierr); 6369ef48cebcSMatthew G. Knepley if (globalSize) { 6370ef48cebcSMatthew G. Knepley PetscLayout layout; 6371ef48cebcSMatthew G. Knepley ierr = PetscSectionGetPointLayout(PetscObjectComm((PetscObject) dm), globalSection, &layout);CHKERRQ(ierr); 6372ef48cebcSMatthew G. Knepley ierr = PetscLayoutGetSize(layout, globalSize);CHKERRQ(ierr); 6373ef48cebcSMatthew G. Knepley ierr = PetscLayoutDestroy(&layout);CHKERRQ(ierr); 6374ef48cebcSMatthew G. Knepley } 6375552f7358SJed Brown ierr = PetscSectionDestroy(§ion);CHKERRQ(ierr); 6376552f7358SJed Brown ierr = PetscSectionDestroy(&globalSection);CHKERRQ(ierr); 6377552f7358SJed Brown PetscFunctionReturn(0); 6378552f7358SJed Brown } 6379552f7358SJed Brown 638081ed3555SMatthew G. Knepley PetscErrorCode DMPlexCreateCellNumbering_Internal(DM dm, PetscBool includeHybrid, IS *globalCellNumbers) 6381552f7358SJed Brown { 6382552f7358SJed Brown PetscInt cellHeight, cStart, cEnd, cMax; 6383552f7358SJed Brown PetscErrorCode ierr; 6384552f7358SJed Brown 6385552f7358SJed Brown PetscFunctionBegin; 6386552f7358SJed Brown ierr = DMPlexGetVTKCellHeight(dm, &cellHeight);CHKERRQ(ierr); 6387552f7358SJed Brown ierr = DMPlexGetHeightStratum(dm, cellHeight, &cStart, &cEnd);CHKERRQ(ierr); 63880298fd71SBarry Smith ierr = DMPlexGetHybridBounds(dm, &cMax, NULL, NULL, NULL);CHKERRQ(ierr); 638981ed3555SMatthew G. Knepley if (cMax >= 0 && !includeHybrid) cEnd = PetscMin(cEnd, cMax); 639081ed3555SMatthew G. Knepley ierr = DMPlexCreateNumbering_Private(dm, cStart, cEnd, 0, NULL, dm->sf, globalCellNumbers);CHKERRQ(ierr); 639181ed3555SMatthew G. Knepley PetscFunctionReturn(0); 6392552f7358SJed Brown } 639381ed3555SMatthew G. Knepley 63947cd05799SMatthew G. Knepley /*@C 63957cd05799SMatthew G. Knepley DMPlexGetCellNumbering - Get a global cell numbering for all cells on this process 63967cd05799SMatthew G. Knepley 63977cd05799SMatthew G. Knepley Input Parameter: 63987cd05799SMatthew G. Knepley . dm - The DMPlex object 63997cd05799SMatthew G. Knepley 64007cd05799SMatthew G. Knepley Output Parameter: 64017cd05799SMatthew G. Knepley . globalCellNumbers - Global cell numbers for all cells on this process 64027cd05799SMatthew G. Knepley 64037cd05799SMatthew G. Knepley Level: developer 64047cd05799SMatthew G. Knepley 64057cd05799SMatthew G. Knepley .seealso DMPlexGetVertexNumbering() 64067cd05799SMatthew G. Knepley @*/ 640781ed3555SMatthew G. Knepley PetscErrorCode DMPlexGetCellNumbering(DM dm, IS *globalCellNumbers) 640881ed3555SMatthew G. Knepley { 640981ed3555SMatthew G. Knepley DM_Plex *mesh = (DM_Plex*) dm->data; 641081ed3555SMatthew G. Knepley PetscErrorCode ierr; 641181ed3555SMatthew G. Knepley 641281ed3555SMatthew G. Knepley PetscFunctionBegin; 641381ed3555SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 641481ed3555SMatthew G. Knepley if (!mesh->globalCellNumbers) {ierr = DMPlexCreateCellNumbering_Internal(dm, PETSC_FALSE, &mesh->globalCellNumbers);CHKERRQ(ierr);} 6415552f7358SJed Brown *globalCellNumbers = mesh->globalCellNumbers; 6416552f7358SJed Brown PetscFunctionReturn(0); 6417552f7358SJed Brown } 6418552f7358SJed Brown 641981ed3555SMatthew G. Knepley PetscErrorCode DMPlexCreateVertexNumbering_Internal(DM dm, PetscBool includeHybrid, IS *globalVertexNumbers) 642081ed3555SMatthew G. Knepley { 642181ed3555SMatthew G. Knepley PetscInt vStart, vEnd, vMax; 642281ed3555SMatthew G. Knepley PetscErrorCode ierr; 642381ed3555SMatthew G. Knepley 642481ed3555SMatthew G. Knepley PetscFunctionBegin; 642581ed3555SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 642681ed3555SMatthew G. Knepley ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr); 642781ed3555SMatthew G. Knepley ierr = DMPlexGetHybridBounds(dm, NULL, NULL, NULL, &vMax);CHKERRQ(ierr); 642881ed3555SMatthew G. Knepley if (vMax >= 0 && !includeHybrid) vEnd = PetscMin(vEnd, vMax); 642981ed3555SMatthew G. Knepley ierr = DMPlexCreateNumbering_Private(dm, vStart, vEnd, 0, NULL, dm->sf, globalVertexNumbers);CHKERRQ(ierr); 643081ed3555SMatthew G. Knepley PetscFunctionReturn(0); 643181ed3555SMatthew G. Knepley } 643281ed3555SMatthew G. Knepley 64337cd05799SMatthew G. Knepley /*@C 64347cd05799SMatthew G. Knepley DMPlexGetVertexNumbering - Get a global certex numbering for all vertices on this process 64357cd05799SMatthew G. Knepley 64367cd05799SMatthew G. Knepley Input Parameter: 64377cd05799SMatthew G. Knepley . dm - The DMPlex object 64387cd05799SMatthew G. Knepley 64397cd05799SMatthew G. Knepley Output Parameter: 64407cd05799SMatthew G. Knepley . globalVertexNumbers - Global vertex numbers for all vertices on this process 64417cd05799SMatthew G. Knepley 64427cd05799SMatthew G. Knepley Level: developer 64437cd05799SMatthew G. Knepley 64447cd05799SMatthew G. Knepley .seealso DMPlexGetCellNumbering() 64457cd05799SMatthew G. Knepley @*/ 6446552f7358SJed Brown PetscErrorCode DMPlexGetVertexNumbering(DM dm, IS *globalVertexNumbers) 6447552f7358SJed Brown { 6448552f7358SJed Brown DM_Plex *mesh = (DM_Plex*) dm->data; 6449552f7358SJed Brown PetscErrorCode ierr; 6450552f7358SJed Brown 6451552f7358SJed Brown PetscFunctionBegin; 6452552f7358SJed Brown PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 645381ed3555SMatthew G. Knepley if (!mesh->globalVertexNumbers) {ierr = DMPlexCreateVertexNumbering_Internal(dm, PETSC_FALSE, &mesh->globalVertexNumbers);CHKERRQ(ierr);} 6454552f7358SJed Brown *globalVertexNumbers = mesh->globalVertexNumbers; 6455552f7358SJed Brown PetscFunctionReturn(0); 6456552f7358SJed Brown } 6457552f7358SJed Brown 64587cd05799SMatthew G. Knepley /*@C 64597cd05799SMatthew G. Knepley DMPlexCreatePointNumbering - Create a global numbering for all points on this process 64607cd05799SMatthew G. Knepley 64617cd05799SMatthew G. Knepley Input Parameter: 64627cd05799SMatthew G. Knepley . dm - The DMPlex object 64637cd05799SMatthew G. Knepley 64647cd05799SMatthew G. Knepley Output Parameter: 64657cd05799SMatthew G. Knepley . globalPointNumbers - Global numbers for all points on this process 64667cd05799SMatthew G. Knepley 64677cd05799SMatthew G. Knepley Level: developer 64687cd05799SMatthew G. Knepley 64697cd05799SMatthew G. Knepley .seealso DMPlexGetCellNumbering() 64707cd05799SMatthew G. Knepley @*/ 6471ef48cebcSMatthew G. Knepley PetscErrorCode DMPlexCreatePointNumbering(DM dm, IS *globalPointNumbers) 6472ef48cebcSMatthew G. Knepley { 6473ef48cebcSMatthew G. Knepley IS nums[4]; 6474ef48cebcSMatthew G. Knepley PetscInt depths[4]; 6475ef48cebcSMatthew G. Knepley PetscInt depth, d, shift = 0; 6476ef48cebcSMatthew G. Knepley PetscErrorCode ierr; 6477ef48cebcSMatthew G. Knepley 6478ef48cebcSMatthew G. Knepley PetscFunctionBegin; 6479ef48cebcSMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 6480ef48cebcSMatthew G. Knepley ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 64818abc87a0SMichael Lange /* For unstratified meshes use dim instead of depth */ 64828abc87a0SMichael Lange if (depth < 0) {ierr = DMGetDimension(dm, &depth);CHKERRQ(ierr);} 6483ef48cebcSMatthew G. Knepley depths[0] = depth; depths[1] = 0; 6484ef48cebcSMatthew G. Knepley for (d = 2; d <= depth; ++d) depths[d] = depth-d+1; 6485ef48cebcSMatthew G. Knepley for (d = 0; d <= depth; ++d) { 6486ef48cebcSMatthew G. Knepley PetscInt pStart, pEnd, gsize; 6487ef48cebcSMatthew G. Knepley 6488ef48cebcSMatthew G. Knepley ierr = DMPlexGetDepthStratum(dm, depths[d], &pStart, &pEnd);CHKERRQ(ierr); 6489ef48cebcSMatthew G. Knepley ierr = DMPlexCreateNumbering_Private(dm, pStart, pEnd, shift, &gsize, dm->sf, &nums[d]);CHKERRQ(ierr); 6490ef48cebcSMatthew G. Knepley shift += gsize; 6491ef48cebcSMatthew G. Knepley } 6492302440fdSBarry Smith ierr = ISConcatenate(PetscObjectComm((PetscObject) dm), depth+1, nums, globalPointNumbers);CHKERRQ(ierr); 6493ef48cebcSMatthew G. Knepley for (d = 0; d <= depth; ++d) {ierr = ISDestroy(&nums[d]);CHKERRQ(ierr);} 6494ef48cebcSMatthew G. Knepley PetscFunctionReturn(0); 6495ef48cebcSMatthew G. Knepley } 6496ef48cebcSMatthew G. Knepley 649708a22f4bSMatthew G. Knepley 649808a22f4bSMatthew G. Knepley /*@ 649908a22f4bSMatthew G. Knepley DMPlexCreateRankField - Create a cell field whose value is the rank of the owner 650008a22f4bSMatthew G. Knepley 650108a22f4bSMatthew G. Knepley Input Parameter: 650208a22f4bSMatthew G. Knepley . dm - The DMPlex object 650308a22f4bSMatthew G. Knepley 650408a22f4bSMatthew G. Knepley Output Parameter: 650508a22f4bSMatthew G. Knepley . ranks - The rank field 650608a22f4bSMatthew G. Knepley 650708a22f4bSMatthew G. Knepley Options Database Keys: 650808a22f4bSMatthew G. Knepley . -dm_partition_view - Adds the rank field into the DM output from -dm_view using the same viewer 650908a22f4bSMatthew G. Knepley 651008a22f4bSMatthew G. Knepley Level: intermediate 651108a22f4bSMatthew G. Knepley 651208a22f4bSMatthew G. Knepley .seealso: DMView() 651308a22f4bSMatthew G. Knepley @*/ 651408a22f4bSMatthew G. Knepley PetscErrorCode DMPlexCreateRankField(DM dm, Vec *ranks) 651508a22f4bSMatthew G. Knepley { 651608a22f4bSMatthew G. Knepley DM rdm; 651708a22f4bSMatthew G. Knepley PetscDS prob; 651808a22f4bSMatthew G. Knepley PetscFE fe; 651908a22f4bSMatthew G. Knepley PetscScalar *r; 652008a22f4bSMatthew G. Knepley PetscMPIInt rank; 652108a22f4bSMatthew G. Knepley PetscInt dim, cStart, cEnd, c; 652208a22f4bSMatthew G. Knepley PetscErrorCode ierr; 652308a22f4bSMatthew G. Knepley 652408a22f4bSMatthew G. Knepley PetscFunctionBeginUser; 652508a22f4bSMatthew G. Knepley ierr = MPI_Comm_rank(PetscObjectComm((PetscObject) dm), &rank);CHKERRQ(ierr); 652608a22f4bSMatthew G. Knepley ierr = DMClone(dm, &rdm);CHKERRQ(ierr); 652708a22f4bSMatthew G. Knepley ierr = DMGetDimension(rdm, &dim);CHKERRQ(ierr); 6528e8d98e54SMatthew G. Knepley ierr = PetscFECreateDefault(PetscObjectComm((PetscObject) rdm), dim, 1, PETSC_TRUE, NULL, -1, &fe);CHKERRQ(ierr); 652908a22f4bSMatthew G. Knepley ierr = PetscObjectSetName((PetscObject) fe, "rank");CHKERRQ(ierr); 653008a22f4bSMatthew G. Knepley ierr = DMGetDS(rdm, &prob);CHKERRQ(ierr); 653108a22f4bSMatthew G. Knepley ierr = PetscDSSetDiscretization(prob, 0, (PetscObject) fe);CHKERRQ(ierr); 653208a22f4bSMatthew G. Knepley ierr = PetscFEDestroy(&fe);CHKERRQ(ierr); 653308a22f4bSMatthew G. Knepley ierr = DMPlexGetHeightStratum(rdm, 0, &cStart, &cEnd);CHKERRQ(ierr); 653408a22f4bSMatthew G. Knepley ierr = DMCreateGlobalVector(rdm, ranks);CHKERRQ(ierr); 653508a22f4bSMatthew G. Knepley ierr = PetscObjectSetName((PetscObject) *ranks, "partition");CHKERRQ(ierr); 653608a22f4bSMatthew G. Knepley ierr = VecGetArray(*ranks, &r);CHKERRQ(ierr); 653708a22f4bSMatthew G. Knepley for (c = cStart; c < cEnd; ++c) { 653808a22f4bSMatthew G. Knepley PetscScalar *lr; 653908a22f4bSMatthew G. Knepley 654008a22f4bSMatthew G. Knepley ierr = DMPlexPointGlobalRef(rdm, c, r, &lr);CHKERRQ(ierr); 654108a22f4bSMatthew G. Knepley *lr = rank; 654208a22f4bSMatthew G. Knepley } 654308a22f4bSMatthew G. Knepley ierr = VecRestoreArray(*ranks, &r);CHKERRQ(ierr); 654408a22f4bSMatthew G. Knepley ierr = DMDestroy(&rdm);CHKERRQ(ierr); 654508a22f4bSMatthew G. Knepley PetscFunctionReturn(0); 654608a22f4bSMatthew G. Knepley } 654708a22f4bSMatthew G. Knepley 6548ca8062c8SMatthew G. Knepley /*@ 6549ca8062c8SMatthew G. Knepley DMPlexCheckSymmetry - Check that the adjacency information in the mesh is symmetric. 6550ca8062c8SMatthew G. Knepley 655169916449SMatthew G. Knepley Input Parameter: 655269916449SMatthew G. Knepley . dm - The DMPlex object 6553ca8062c8SMatthew G. Knepley 6554ca8062c8SMatthew G. Knepley Note: This is a useful diagnostic when creating meshes programmatically. 6555ca8062c8SMatthew G. Knepley 6556ca8062c8SMatthew G. Knepley Level: developer 6557ca8062c8SMatthew G. Knepley 65587d5acc75SStefano Zampini .seealso: DMCreate(), DMPlexCheckSkeleton(), DMPlexCheckFaces() 6559ca8062c8SMatthew G. Knepley @*/ 6560ca8062c8SMatthew G. Knepley PetscErrorCode DMPlexCheckSymmetry(DM dm) 6561ca8062c8SMatthew G. Knepley { 6562ca8062c8SMatthew G. Knepley PetscSection coneSection, supportSection; 6563ca8062c8SMatthew G. Knepley const PetscInt *cone, *support; 6564ca8062c8SMatthew G. Knepley PetscInt coneSize, c, supportSize, s; 6565ca8062c8SMatthew G. Knepley PetscInt pStart, pEnd, p, csize, ssize; 6566ca8062c8SMatthew G. Knepley PetscErrorCode ierr; 6567ca8062c8SMatthew G. Knepley 6568ca8062c8SMatthew G. Knepley PetscFunctionBegin; 6569ca8062c8SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 6570ca8062c8SMatthew G. Knepley ierr = DMPlexGetConeSection(dm, &coneSection);CHKERRQ(ierr); 6571ca8062c8SMatthew G. Knepley ierr = DMPlexGetSupportSection(dm, &supportSection);CHKERRQ(ierr); 6572ca8062c8SMatthew G. Knepley /* Check that point p is found in the support of its cone points, and vice versa */ 6573ca8062c8SMatthew G. Knepley ierr = DMPlexGetChart(dm, &pStart, &pEnd);CHKERRQ(ierr); 6574ca8062c8SMatthew G. Knepley for (p = pStart; p < pEnd; ++p) { 6575ca8062c8SMatthew G. Knepley ierr = DMPlexGetConeSize(dm, p, &coneSize);CHKERRQ(ierr); 6576ca8062c8SMatthew G. Knepley ierr = DMPlexGetCone(dm, p, &cone);CHKERRQ(ierr); 6577ca8062c8SMatthew G. Knepley for (c = 0; c < coneSize; ++c) { 657842e66dfaSMatthew G. Knepley PetscBool dup = PETSC_FALSE; 657942e66dfaSMatthew G. Knepley PetscInt d; 658042e66dfaSMatthew G. Knepley for (d = c-1; d >= 0; --d) { 658142e66dfaSMatthew G. Knepley if (cone[c] == cone[d]) {dup = PETSC_TRUE; break;} 658242e66dfaSMatthew G. Knepley } 6583ca8062c8SMatthew G. Knepley ierr = DMPlexGetSupportSize(dm, cone[c], &supportSize);CHKERRQ(ierr); 6584ca8062c8SMatthew G. Knepley ierr = DMPlexGetSupport(dm, cone[c], &support);CHKERRQ(ierr); 6585ca8062c8SMatthew G. Knepley for (s = 0; s < supportSize; ++s) { 6586ca8062c8SMatthew G. Knepley if (support[s] == p) break; 6587ca8062c8SMatthew G. Knepley } 658842e66dfaSMatthew G. Knepley if ((s >= supportSize) || (dup && (support[s+1] != p))) { 65898ccfff9cSToby Isaac ierr = PetscPrintf(PETSC_COMM_SELF, "p: %D cone: ", p);CHKERRQ(ierr); 6590ca8062c8SMatthew G. Knepley for (s = 0; s < coneSize; ++s) { 65918ccfff9cSToby Isaac ierr = PetscPrintf(PETSC_COMM_SELF, "%D, ", cone[s]);CHKERRQ(ierr); 6592ca8062c8SMatthew G. Knepley } 6593302440fdSBarry Smith ierr = PetscPrintf(PETSC_COMM_SELF, "\n");CHKERRQ(ierr); 65948ccfff9cSToby Isaac ierr = PetscPrintf(PETSC_COMM_SELF, "p: %D support: ", cone[c]);CHKERRQ(ierr); 6595ca8062c8SMatthew G. Knepley for (s = 0; s < supportSize; ++s) { 65968ccfff9cSToby Isaac ierr = PetscPrintf(PETSC_COMM_SELF, "%D, ", support[s]);CHKERRQ(ierr); 6597ca8062c8SMatthew G. Knepley } 6598302440fdSBarry Smith ierr = PetscPrintf(PETSC_COMM_SELF, "\n");CHKERRQ(ierr); 65998ccfff9cSToby Isaac if (dup) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Point %D not repeatedly found in support of repeated cone point %D", p, cone[c]); 66008ccfff9cSToby Isaac else SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Point %D not found in support of cone point %D", p, cone[c]); 6601ca8062c8SMatthew G. Knepley } 660242e66dfaSMatthew G. Knepley } 6603ca8062c8SMatthew G. Knepley ierr = DMPlexGetSupportSize(dm, p, &supportSize);CHKERRQ(ierr); 6604ca8062c8SMatthew G. Knepley ierr = DMPlexGetSupport(dm, p, &support);CHKERRQ(ierr); 6605ca8062c8SMatthew G. Knepley for (s = 0; s < supportSize; ++s) { 6606ca8062c8SMatthew G. Knepley ierr = DMPlexGetConeSize(dm, support[s], &coneSize);CHKERRQ(ierr); 6607ca8062c8SMatthew G. Knepley ierr = DMPlexGetCone(dm, support[s], &cone);CHKERRQ(ierr); 6608ca8062c8SMatthew G. Knepley for (c = 0; c < coneSize; ++c) { 6609ca8062c8SMatthew G. Knepley if (cone[c] == p) break; 6610ca8062c8SMatthew G. Knepley } 6611ca8062c8SMatthew G. Knepley if (c >= coneSize) { 66128ccfff9cSToby Isaac ierr = PetscPrintf(PETSC_COMM_SELF, "p: %D support: ", p);CHKERRQ(ierr); 6613ca8062c8SMatthew G. Knepley for (c = 0; c < supportSize; ++c) { 66148ccfff9cSToby Isaac ierr = PetscPrintf(PETSC_COMM_SELF, "%D, ", support[c]);CHKERRQ(ierr); 6615ca8062c8SMatthew G. Knepley } 6616302440fdSBarry Smith ierr = PetscPrintf(PETSC_COMM_SELF, "\n");CHKERRQ(ierr); 66178ccfff9cSToby Isaac ierr = PetscPrintf(PETSC_COMM_SELF, "p: %D cone: ", support[s]);CHKERRQ(ierr); 6618ca8062c8SMatthew G. Knepley for (c = 0; c < coneSize; ++c) { 66198ccfff9cSToby Isaac ierr = PetscPrintf(PETSC_COMM_SELF, "%D, ", cone[c]);CHKERRQ(ierr); 6620ca8062c8SMatthew G. Knepley } 6621302440fdSBarry Smith ierr = PetscPrintf(PETSC_COMM_SELF, "\n");CHKERRQ(ierr); 66228ccfff9cSToby Isaac SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Point %D not found in cone of support point %D", p, support[s]); 6623ca8062c8SMatthew G. Knepley } 6624ca8062c8SMatthew G. Knepley } 6625ca8062c8SMatthew G. Knepley } 6626ca8062c8SMatthew G. Knepley ierr = PetscSectionGetStorageSize(coneSection, &csize);CHKERRQ(ierr); 6627ca8062c8SMatthew G. Knepley ierr = PetscSectionGetStorageSize(supportSection, &ssize);CHKERRQ(ierr); 66288ccfff9cSToby Isaac if (csize != ssize) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Total cone size %D != Total support size %D", csize, ssize); 6629ca8062c8SMatthew G. Knepley PetscFunctionReturn(0); 6630ca8062c8SMatthew G. Knepley } 6631ca8062c8SMatthew G. Knepley 6632ca8062c8SMatthew G. Knepley /*@ 6633ca8062c8SMatthew G. Knepley DMPlexCheckSkeleton - Check that each cell has the correct number of vertices 6634ca8062c8SMatthew G. Knepley 6635ca8062c8SMatthew G. Knepley Input Parameters: 6636ca8062c8SMatthew G. Knepley + dm - The DMPlex object 663758723a97SMatthew G. Knepley . isSimplex - Are the cells simplices or tensor products 663858723a97SMatthew G. Knepley - cellHeight - Normally 0 6639ca8062c8SMatthew G. Knepley 6640ca8062c8SMatthew G. Knepley Note: This is a useful diagnostic when creating meshes programmatically. 6641ca8062c8SMatthew G. Knepley 6642ca8062c8SMatthew G. Knepley Level: developer 6643ca8062c8SMatthew G. Knepley 66447d5acc75SStefano Zampini .seealso: DMCreate(), DMPlexCheckSymmetry(), DMPlexCheckFaces() 6645ca8062c8SMatthew G. Knepley @*/ 664658723a97SMatthew G. Knepley PetscErrorCode DMPlexCheckSkeleton(DM dm, PetscBool isSimplex, PetscInt cellHeight) 6647ca8062c8SMatthew G. Knepley { 664842363296SMatthew G. Knepley PetscInt dim, numCorners, numHybridCorners, vStart, vEnd, cStart, cEnd, cMax, c; 6649ca8062c8SMatthew G. Knepley PetscErrorCode ierr; 6650ca8062c8SMatthew G. Knepley 6651ca8062c8SMatthew G. Knepley PetscFunctionBegin; 6652ca8062c8SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 6653c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 6654ca8062c8SMatthew G. Knepley switch (dim) { 665542363296SMatthew G. Knepley case 1: numCorners = isSimplex ? 2 : 2; numHybridCorners = isSimplex ? 2 : 2; break; 665642363296SMatthew G. Knepley case 2: numCorners = isSimplex ? 3 : 4; numHybridCorners = isSimplex ? 4 : 4; break; 665742363296SMatthew G. Knepley case 3: numCorners = isSimplex ? 4 : 8; numHybridCorners = isSimplex ? 6 : 8; break; 6658ca8062c8SMatthew G. Knepley default: 66598ccfff9cSToby Isaac SETERRQ1(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_OUTOFRANGE, "Cannot handle meshes of dimension %D", dim); 6660ca8062c8SMatthew G. Knepley } 666158723a97SMatthew G. Knepley ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr); 666258723a97SMatthew G. Knepley ierr = DMPlexGetHeightStratum(dm, cellHeight, &cStart, &cEnd);CHKERRQ(ierr); 6663ca8062c8SMatthew G. Knepley ierr = DMPlexGetHybridBounds(dm, &cMax, NULL, NULL, NULL);CHKERRQ(ierr); 6664ca8062c8SMatthew G. Knepley cMax = cMax >= 0 ? cMax : cEnd; 6665ca8062c8SMatthew G. Knepley for (c = cStart; c < cMax; ++c) { 666658723a97SMatthew G. Knepley PetscInt *closure = NULL, closureSize, cl, coneSize = 0; 666758723a97SMatthew G. Knepley 666858723a97SMatthew G. Knepley ierr = DMPlexGetTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 666958723a97SMatthew G. Knepley for (cl = 0; cl < closureSize*2; cl += 2) { 667058723a97SMatthew G. Knepley const PetscInt p = closure[cl]; 667158723a97SMatthew G. Knepley if ((p >= vStart) && (p < vEnd)) ++coneSize; 667258723a97SMatthew G. Knepley } 667358723a97SMatthew G. Knepley ierr = DMPlexRestoreTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 66748ccfff9cSToby Isaac if (coneSize != numCorners) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Cell %D has %D vertices != %D", c, coneSize, numCorners); 6675ca8062c8SMatthew G. Knepley } 667642363296SMatthew G. Knepley for (c = cMax; c < cEnd; ++c) { 667742363296SMatthew G. Knepley PetscInt *closure = NULL, closureSize, cl, coneSize = 0; 667842363296SMatthew G. Knepley 667942363296SMatthew G. Knepley ierr = DMPlexGetTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 668042363296SMatthew G. Knepley for (cl = 0; cl < closureSize*2; cl += 2) { 668142363296SMatthew G. Knepley const PetscInt p = closure[cl]; 668242363296SMatthew G. Knepley if ((p >= vStart) && (p < vEnd)) ++coneSize; 668342363296SMatthew G. Knepley } 668442363296SMatthew G. Knepley ierr = DMPlexRestoreTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 66858ccfff9cSToby Isaac if (coneSize > numHybridCorners) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Hybrid cell %D has %D vertices > %D", c, coneSize, numHybridCorners); 668642363296SMatthew G. Knepley } 6687ca8062c8SMatthew G. Knepley PetscFunctionReturn(0); 6688ca8062c8SMatthew G. Knepley } 66899bf0dad6SMatthew G. Knepley 66909bf0dad6SMatthew G. Knepley /*@ 66919bf0dad6SMatthew G. Knepley DMPlexCheckFaces - Check that the faces of each cell give a vertex order this is consistent with what we expect from the cell type 66929bf0dad6SMatthew G. Knepley 66939bf0dad6SMatthew G. Knepley Input Parameters: 66949bf0dad6SMatthew G. Knepley + dm - The DMPlex object 66959bf0dad6SMatthew G. Knepley . isSimplex - Are the cells simplices or tensor products 66969bf0dad6SMatthew G. Knepley - cellHeight - Normally 0 66979bf0dad6SMatthew G. Knepley 66989bf0dad6SMatthew G. Knepley Note: This is a useful diagnostic when creating meshes programmatically. 66999bf0dad6SMatthew G. Knepley 67009bf0dad6SMatthew G. Knepley Level: developer 67019bf0dad6SMatthew G. Knepley 67027d5acc75SStefano Zampini .seealso: DMCreate(), DMPlexCheckSymmetry(), DMPlexCheckSkeleton() 67039bf0dad6SMatthew G. Knepley @*/ 67049bf0dad6SMatthew G. Knepley PetscErrorCode DMPlexCheckFaces(DM dm, PetscBool isSimplex, PetscInt cellHeight) 67059bf0dad6SMatthew G. Knepley { 67063554e41dSMatthew G. Knepley PetscInt pMax[4]; 67073554e41dSMatthew G. Knepley PetscInt dim, vStart, vEnd, cStart, cEnd, c, h; 67089bf0dad6SMatthew G. Knepley PetscErrorCode ierr; 67099bf0dad6SMatthew G. Knepley 67109bf0dad6SMatthew G. Knepley PetscFunctionBegin; 67119bf0dad6SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 6712c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 67139bf0dad6SMatthew G. Knepley ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr); 671425abba81SMatthew G. Knepley ierr = DMPlexGetHybridBounds(dm, &pMax[dim], &pMax[dim-1], &pMax[1], &pMax[0]);CHKERRQ(ierr); 67153554e41dSMatthew G. Knepley for (h = cellHeight; h < dim; ++h) { 67163554e41dSMatthew G. Knepley ierr = DMPlexGetHeightStratum(dm, h, &cStart, &cEnd);CHKERRQ(ierr); 67173554e41dSMatthew G. Knepley for (c = cStart; c < cEnd; ++c) { 67189bf0dad6SMatthew G. Knepley const PetscInt *cone, *ornt, *faces; 67199bf0dad6SMatthew G. Knepley PetscInt numFaces, faceSize, coneSize,f; 67209bf0dad6SMatthew G. Knepley PetscInt *closure = NULL, closureSize, cl, numCorners = 0; 67219bf0dad6SMatthew G. Knepley 672225abba81SMatthew G. Knepley if (pMax[dim-h] >= 0 && c >= pMax[dim-h]) continue; 67239bf0dad6SMatthew G. Knepley ierr = DMPlexGetConeSize(dm, c, &coneSize);CHKERRQ(ierr); 67249bf0dad6SMatthew G. Knepley ierr = DMPlexGetCone(dm, c, &cone);CHKERRQ(ierr); 67259bf0dad6SMatthew G. Knepley ierr = DMPlexGetConeOrientation(dm, c, &ornt);CHKERRQ(ierr); 67269bf0dad6SMatthew G. Knepley ierr = DMPlexGetTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 67279bf0dad6SMatthew G. Knepley for (cl = 0; cl < closureSize*2; cl += 2) { 67289bf0dad6SMatthew G. Knepley const PetscInt p = closure[cl]; 67299bf0dad6SMatthew G. Knepley if ((p >= vStart) && (p < vEnd)) closure[numCorners++] = p; 67309bf0dad6SMatthew G. Knepley } 67313554e41dSMatthew G. Knepley ierr = DMPlexGetRawFaces_Internal(dm, dim-h, numCorners, closure, &numFaces, &faceSize, &faces);CHKERRQ(ierr); 67328ccfff9cSToby Isaac if (coneSize != numFaces) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Cell %D has %D faces but should have %D", c, coneSize, numFaces); 67339bf0dad6SMatthew G. Knepley for (f = 0; f < numFaces; ++f) { 67349bf0dad6SMatthew G. Knepley PetscInt *fclosure = NULL, fclosureSize, cl, fnumCorners = 0, v; 67359bf0dad6SMatthew G. Knepley 67369bf0dad6SMatthew G. Knepley ierr = DMPlexGetTransitiveClosure_Internal(dm, cone[f], ornt[f], PETSC_TRUE, &fclosureSize, &fclosure);CHKERRQ(ierr); 67379bf0dad6SMatthew G. Knepley for (cl = 0; cl < fclosureSize*2; cl += 2) { 67389bf0dad6SMatthew G. Knepley const PetscInt p = fclosure[cl]; 67399bf0dad6SMatthew G. Knepley if ((p >= vStart) && (p < vEnd)) fclosure[fnumCorners++] = p; 67409bf0dad6SMatthew G. Knepley } 67418ccfff9cSToby Isaac if (fnumCorners != faceSize) SETERRQ5(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Face %D (%D) of cell %D has %D vertices but should have %D", cone[f], f, c, fnumCorners, faceSize); 67429bf0dad6SMatthew G. Knepley for (v = 0; v < fnumCorners; ++v) { 67438ccfff9cSToby Isaac if (fclosure[v] != faces[f*faceSize+v]) SETERRQ6(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Face %D (%d) of cell %D vertex %D, %D != %D", cone[f], f, c, v, fclosure[v], faces[f*faceSize+v]); 67449bf0dad6SMatthew G. Knepley } 67459bf0dad6SMatthew G. Knepley ierr = DMPlexRestoreTransitiveClosure(dm, cone[f], PETSC_TRUE, &fclosureSize, &fclosure);CHKERRQ(ierr); 67469bf0dad6SMatthew G. Knepley } 67479bf0dad6SMatthew G. Knepley ierr = DMPlexRestoreFaces_Internal(dm, dim, c, &numFaces, &faceSize, &faces);CHKERRQ(ierr); 67489bf0dad6SMatthew G. Knepley ierr = DMPlexRestoreTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); 67499bf0dad6SMatthew G. Knepley } 67503554e41dSMatthew G. Knepley } 6751552f7358SJed Brown PetscFunctionReturn(0); 6752552f7358SJed Brown } 67533913d7c8SMatthew G. Knepley 6754bceba477SMatthew G. Knepley /* Pointwise interpolation 6755bceba477SMatthew G. Knepley Just code FEM for now 6756bceba477SMatthew G. Knepley u^f = I u^c 67574ca5e9f5SMatthew G. Knepley sum_k u^f_k phi^f_k = I sum_j u^c_j phi^c_j 67584ca5e9f5SMatthew G. Knepley u^f_i = sum_j psi^f_i I phi^c_j u^c_j 67594ca5e9f5SMatthew G. Knepley I_{ij} = psi^f_i phi^c_j 6760bceba477SMatthew G. Knepley */ 6761bceba477SMatthew G. Knepley PetscErrorCode DMCreateInterpolation_Plex(DM dmCoarse, DM dmFine, Mat *interpolation, Vec *scaling) 6762bceba477SMatthew G. Knepley { 6763bceba477SMatthew G. Knepley PetscSection gsc, gsf; 6764bceba477SMatthew G. Knepley PetscInt m, n; 6765a063dac3SMatthew G. Knepley void *ctx; 676668132eb9SMatthew G. Knepley DM cdm; 6767fd194bc8SStefano Zampini PetscBool regular, ismatis; 6768bceba477SMatthew G. Knepley PetscErrorCode ierr; 6769bceba477SMatthew G. Knepley 6770bceba477SMatthew G. Knepley PetscFunctionBegin; 6771e87a4003SBarry Smith ierr = DMGetGlobalSection(dmFine, &gsf);CHKERRQ(ierr); 6772bceba477SMatthew G. Knepley ierr = PetscSectionGetConstrainedStorageSize(gsf, &m);CHKERRQ(ierr); 6773e87a4003SBarry Smith ierr = DMGetGlobalSection(dmCoarse, &gsc);CHKERRQ(ierr); 6774bceba477SMatthew G. Knepley ierr = PetscSectionGetConstrainedStorageSize(gsc, &n);CHKERRQ(ierr); 677568132eb9SMatthew G. Knepley 6776fd194bc8SStefano Zampini ierr = PetscStrcmp(dmCoarse->mattype, MATIS, &ismatis);CHKERRQ(ierr); 6777bceba477SMatthew G. Knepley ierr = MatCreate(PetscObjectComm((PetscObject) dmCoarse), interpolation);CHKERRQ(ierr); 6778bceba477SMatthew G. Knepley ierr = MatSetSizes(*interpolation, m, n, PETSC_DETERMINE, PETSC_DETERMINE);CHKERRQ(ierr); 6779fd194bc8SStefano Zampini ierr = MatSetType(*interpolation, ismatis ? MATAIJ : dmCoarse->mattype);CHKERRQ(ierr); 6780a063dac3SMatthew G. Knepley ierr = DMGetApplicationContext(dmFine, &ctx);CHKERRQ(ierr); 678168132eb9SMatthew G. Knepley 6782a8fb8f29SToby Isaac ierr = DMGetCoarseDM(dmFine, &cdm);CHKERRQ(ierr); 678368132eb9SMatthew G. Knepley ierr = DMPlexGetRegularRefinement(dmFine, ®ular);CHKERRQ(ierr); 678468132eb9SMatthew G. Knepley if (regular && cdm == dmCoarse) {ierr = DMPlexComputeInterpolatorNested(dmCoarse, dmFine, *interpolation, ctx);CHKERRQ(ierr);} 678568132eb9SMatthew G. Knepley else {ierr = DMPlexComputeInterpolatorGeneral(dmCoarse, dmFine, *interpolation, ctx);CHKERRQ(ierr);} 678668132eb9SMatthew G. Knepley ierr = MatViewFromOptions(*interpolation, NULL, "-interp_mat_view");CHKERRQ(ierr); 67875d1c2e58SMatthew G. Knepley /* Use naive scaling */ 67885d1c2e58SMatthew G. Knepley ierr = DMCreateInterpolationScale(dmCoarse, dmFine, *interpolation, scaling);CHKERRQ(ierr); 6789a063dac3SMatthew G. Knepley PetscFunctionReturn(0); 6790a063dac3SMatthew G. Knepley } 6791bceba477SMatthew G. Knepley 67926dbf9973SLawrence Mitchell PetscErrorCode DMCreateInjection_Plex(DM dmCoarse, DM dmFine, Mat *mat) 6793a063dac3SMatthew G. Knepley { 679490748bafSMatthew G. Knepley PetscErrorCode ierr; 67956dbf9973SLawrence Mitchell VecScatter ctx; 679690748bafSMatthew G. Knepley 6797a063dac3SMatthew G. Knepley PetscFunctionBegin; 67986dbf9973SLawrence Mitchell ierr = DMPlexComputeInjectorFEM(dmCoarse, dmFine, &ctx, NULL);CHKERRQ(ierr); 67996dbf9973SLawrence Mitchell ierr = MatCreateScatter(PetscObjectComm((PetscObject)ctx), ctx, mat);CHKERRQ(ierr); 68006dbf9973SLawrence Mitchell ierr = VecScatterDestroy(&ctx);CHKERRQ(ierr); 6801bceba477SMatthew G. Knepley PetscFunctionReturn(0); 6802bceba477SMatthew G. Knepley } 6803bceba477SMatthew G. Knepley 6804bd041c0cSMatthew G. Knepley PetscErrorCode DMCreateMassMatrix_Plex(DM dmCoarse, DM dmFine, Mat *mass) 6805bd041c0cSMatthew G. Knepley { 6806bd041c0cSMatthew G. Knepley PetscSection gsc, gsf; 6807bd041c0cSMatthew G. Knepley PetscInt m, n; 6808bd041c0cSMatthew G. Knepley void *ctx; 6809bd041c0cSMatthew G. Knepley DM cdm; 6810bd041c0cSMatthew G. Knepley PetscBool regular; 6811bd041c0cSMatthew G. Knepley PetscErrorCode ierr; 6812bd041c0cSMatthew G. Knepley 6813bd041c0cSMatthew G. Knepley PetscFunctionBegin; 6814e87a4003SBarry Smith ierr = DMGetGlobalSection(dmFine, &gsf);CHKERRQ(ierr); 6815bd041c0cSMatthew G. Knepley ierr = PetscSectionGetConstrainedStorageSize(gsf, &m);CHKERRQ(ierr); 6816e87a4003SBarry Smith ierr = DMGetGlobalSection(dmCoarse, &gsc);CHKERRQ(ierr); 6817bd041c0cSMatthew G. Knepley ierr = PetscSectionGetConstrainedStorageSize(gsc, &n);CHKERRQ(ierr); 6818bd041c0cSMatthew G. Knepley 6819bd041c0cSMatthew G. Knepley ierr = MatCreate(PetscObjectComm((PetscObject) dmCoarse), mass);CHKERRQ(ierr); 6820bd041c0cSMatthew G. Knepley ierr = MatSetSizes(*mass, m, n, PETSC_DETERMINE, PETSC_DETERMINE);CHKERRQ(ierr); 6821bd041c0cSMatthew G. Knepley ierr = MatSetType(*mass, dmCoarse->mattype);CHKERRQ(ierr); 6822bd041c0cSMatthew G. Knepley ierr = DMGetApplicationContext(dmFine, &ctx);CHKERRQ(ierr); 6823bd041c0cSMatthew G. Knepley 6824bd041c0cSMatthew G. Knepley ierr = DMGetCoarseDM(dmFine, &cdm);CHKERRQ(ierr); 6825bd041c0cSMatthew G. Knepley ierr = DMPlexGetRegularRefinement(dmFine, ®ular);CHKERRQ(ierr); 6826bd041c0cSMatthew G. Knepley if (regular && cdm == dmCoarse) {ierr = DMPlexComputeMassMatrixNested(dmCoarse, dmFine, *mass, ctx);CHKERRQ(ierr);} 6827bd041c0cSMatthew G. Knepley else {ierr = DMPlexComputeMassMatrixGeneral(dmCoarse, dmFine, *mass, ctx);CHKERRQ(ierr);} 6828bd041c0cSMatthew G. Knepley ierr = MatViewFromOptions(*mass, NULL, "-mass_mat_view");CHKERRQ(ierr); 6829bd041c0cSMatthew G. Knepley PetscFunctionReturn(0); 6830bd041c0cSMatthew G. Knepley } 6831bd041c0cSMatthew G. Knepley 6832fd59a867SMatthew G. Knepley PetscErrorCode DMCreateDefaultSection_Plex(DM dm) 6833fd59a867SMatthew G. Knepley { 6834fd59a867SMatthew G. Knepley PetscSection section; 6835ab1d0545SMatthew G. Knepley IS *bcPoints, *bcComps; 6836ebb3236fSMatthew G. Knepley PetscBool *isFE; 6837286d8613SMatthew G. Knepley PetscInt *bcFields, *numComp, *numDof; 6838ebb3236fSMatthew G. Knepley PetscInt depth, dim, numBd, numBC = 0, numFields, bd, bc = 0, f; 6839ebb3236fSMatthew G. Knepley PetscInt cStart, cEnd, cEndInterior; 6840fd59a867SMatthew G. Knepley PetscErrorCode ierr; 6841fd59a867SMatthew G. Knepley 6842fd59a867SMatthew G. Knepley PetscFunctionBegin; 6843ebb3236fSMatthew G. Knepley ierr = DMGetNumFields(dm, &numFields);CHKERRQ(ierr); 6844ebb3236fSMatthew G. Knepley /* FE and FV boundary conditions are handled slightly differently */ 6845ebb3236fSMatthew G. Knepley ierr = PetscMalloc1(numFields, &isFE);CHKERRQ(ierr); 6846ebb3236fSMatthew G. Knepley for (f = 0; f < numFields; ++f) { 6847ebb3236fSMatthew G. Knepley PetscObject obj; 6848ebb3236fSMatthew G. Knepley PetscClassId id; 6849ebb3236fSMatthew G. Knepley 6850ebb3236fSMatthew G. Knepley ierr = DMGetField(dm, f, &obj);CHKERRQ(ierr); 6851ebb3236fSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 6852ebb3236fSMatthew G. Knepley if (id == PETSCFE_CLASSID) {isFE[f] = PETSC_TRUE;} 6853ebb3236fSMatthew G. Knepley else if (id == PETSCFV_CLASSID) {isFE[f] = PETSC_FALSE;} 68548ccfff9cSToby Isaac else SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %D", f); 6855ebb3236fSMatthew G. Knepley } 68562f900235SMatthew G. Knepley /* Allocate boundary point storage for FEM boundaries */ 6857286d8613SMatthew G. Knepley ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 6858c73cfb54SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 6859ebb3236fSMatthew G. Knepley ierr = DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd);CHKERRQ(ierr); 6860ebb3236fSMatthew G. Knepley ierr = DMPlexGetHybridBounds(dm, &cEndInterior, NULL, NULL, NULL);CHKERRQ(ierr); 6861dff059c6SToby Isaac ierr = PetscDSGetNumBoundary(dm->prob, &numBd);CHKERRQ(ierr); 6862fdafae62SVaclav Hapla if (!numFields && numBd) SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_PLIB, "number of fields is zero and number of boundary conditions is nonzero (this should never happen)"); 6863fd59a867SMatthew G. Knepley for (bd = 0; bd < numBd; ++bd) { 68642f900235SMatthew G. Knepley PetscInt field; 6865f971fd6bSMatthew G. Knepley DMBoundaryConditionType type; 6866385532a5SToby Isaac const char *labelName; 6867385532a5SToby Isaac DMLabel label; 68682f900235SMatthew G. Knepley 6869f971fd6bSMatthew G. Knepley ierr = PetscDSGetBoundary(dm->prob, bd, &type, NULL, &labelName, &field, NULL, NULL, NULL, NULL, NULL, NULL);CHKERRQ(ierr); 6870385532a5SToby Isaac ierr = DMGetLabel(dm,labelName,&label);CHKERRQ(ierr); 6871f971fd6bSMatthew G. Knepley if (label && isFE[field] && (type & DM_BC_ESSENTIAL)) ++numBC; 6872fd59a867SMatthew G. Knepley } 68732f900235SMatthew G. Knepley /* Add ghost cell boundaries for FVM */ 6874ebb3236fSMatthew G. Knepley for (f = 0; f < numFields; ++f) if (!isFE[f] && cEndInterior >= 0) ++numBC; 68756c8d74c4SMatthew G. Knepley ierr = PetscCalloc3(numBC,&bcFields,numBC,&bcPoints,numBC,&bcComps);CHKERRQ(ierr); 6876ebb3236fSMatthew G. Knepley /* Constrain ghost cells for FV */ 6877ebb3236fSMatthew G. Knepley for (f = 0; f < numFields; ++f) { 6878ebb3236fSMatthew G. Knepley PetscInt *newidx, c; 6879ebb3236fSMatthew G. Knepley 6880ebb3236fSMatthew G. Knepley if (isFE[f] || cEndInterior < 0) continue; 6881ebb3236fSMatthew G. Knepley ierr = PetscMalloc1(cEnd-cEndInterior,&newidx);CHKERRQ(ierr); 6882ebb3236fSMatthew G. Knepley for (c = cEndInterior; c < cEnd; ++c) newidx[c-cEndInterior] = c; 6883ebb3236fSMatthew G. Knepley bcFields[bc] = f; 6884ebb3236fSMatthew G. Knepley ierr = ISCreateGeneral(PetscObjectComm((PetscObject) dm), cEnd-cEndInterior, newidx, PETSC_OWN_POINTER, &bcPoints[bc++]);CHKERRQ(ierr); 6885ebb3236fSMatthew G. Knepley } 6886ebb3236fSMatthew G. Knepley /* Handle FEM Dirichlet boundaries */ 6887ebb3236fSMatthew G. Knepley for (bd = 0; bd < numBd; ++bd) { 6888fd59a867SMatthew G. Knepley const char *bdLabel; 6889fd59a867SMatthew G. Knepley DMLabel label; 68900e0f25f2SMatthew G. Knepley const PetscInt *comps; 6891fd59a867SMatthew G. Knepley const PetscInt *values; 68920e0f25f2SMatthew G. Knepley PetscInt bd2, field, numComps, numValues; 6893f971fd6bSMatthew G. Knepley DMBoundaryConditionType type; 6894f971fd6bSMatthew G. Knepley PetscBool duplicate = PETSC_FALSE; 6895fd59a867SMatthew G. Knepley 6896f971fd6bSMatthew G. Knepley ierr = PetscDSGetBoundary(dm->prob, bd, &type, NULL, &bdLabel, &field, &numComps, &comps, NULL, &numValues, &values, NULL);CHKERRQ(ierr); 6897c58f1c22SToby Isaac ierr = DMGetLabel(dm, bdLabel, &label);CHKERRQ(ierr); 6898385532a5SToby Isaac if (!isFE[field] || !label) continue; 6899ebb3236fSMatthew G. Knepley /* Only want to modify label once */ 69007391c1cbSMatthew G. Knepley for (bd2 = 0; bd2 < bd; ++bd2) { 69017391c1cbSMatthew G. Knepley const char *bdname; 6902dff059c6SToby Isaac ierr = PetscDSGetBoundary(dm->prob, bd2, NULL, NULL, &bdname, NULL, NULL, NULL, NULL, NULL, NULL, NULL);CHKERRQ(ierr); 69037391c1cbSMatthew G. Knepley ierr = PetscStrcmp(bdname, bdLabel, &duplicate);CHKERRQ(ierr); 69047391c1cbSMatthew G. Knepley if (duplicate) break; 69057391c1cbSMatthew G. Knepley } 6906ebb3236fSMatthew G. Knepley if (!duplicate && (isFE[field])) { 6907b0bf5782SToby Isaac /* don't complete cells, which are just present to give orientation to the boundary */ 6908092e5057SToby Isaac ierr = DMPlexLabelComplete(dm, label);CHKERRQ(ierr); 69097391c1cbSMatthew G. Knepley } 6910ebb3236fSMatthew G. Knepley /* Filter out cells, if you actually want to constrain cells you need to do things by hand right now */ 6911f971fd6bSMatthew G. Knepley if (type & DM_BC_ESSENTIAL) { 691293a5981aSMatthew G. Knepley PetscInt *newidx; 6913ebb3236fSMatthew G. Knepley PetscInt n, newn = 0, p, v; 691493a5981aSMatthew G. Knepley 6915fd59a867SMatthew G. Knepley bcFields[bc] = field; 69160e0f25f2SMatthew G. Knepley if (numComps) {ierr = ISCreateGeneral(PetscObjectComm((PetscObject) dm), numComps, comps, PETSC_COPY_VALUES, &bcComps[bc]);CHKERRQ(ierr);} 6917ebb3236fSMatthew G. Knepley for (v = 0; v < numValues; ++v) { 6918ebb3236fSMatthew G. Knepley IS tmp; 6919ebb3236fSMatthew G. Knepley const PetscInt *idx; 6920ebb3236fSMatthew G. Knepley 6921c58f1c22SToby Isaac ierr = DMGetStratumIS(dm, bdLabel, values[v], &tmp);CHKERRQ(ierr); 6922ebb3236fSMatthew G. Knepley if (!tmp) continue; 692393a5981aSMatthew G. Knepley ierr = ISGetLocalSize(tmp, &n);CHKERRQ(ierr); 692493a5981aSMatthew G. Knepley ierr = ISGetIndices(tmp, &idx);CHKERRQ(ierr); 6925ebb3236fSMatthew G. Knepley if (isFE[field]) { 692693a5981aSMatthew G. Knepley for (p = 0; p < n; ++p) if ((idx[p] < cStart) || (idx[p] >= cEnd)) ++newn; 6927ebb3236fSMatthew G. Knepley } else { 6928ebb3236fSMatthew G. Knepley for (p = 0; p < n; ++p) if ((idx[p] >= cStart) || (idx[p] < cEnd)) ++newn; 6929ebb3236fSMatthew G. Knepley } 693093a5981aSMatthew G. Knepley ierr = ISRestoreIndices(tmp, &idx);CHKERRQ(ierr); 693193a5981aSMatthew G. Knepley ierr = ISDestroy(&tmp);CHKERRQ(ierr); 6932fd59a867SMatthew G. Knepley } 6933ebb3236fSMatthew G. Knepley ierr = PetscMalloc1(newn,&newidx);CHKERRQ(ierr); 6934ebb3236fSMatthew G. Knepley newn = 0; 6935ebb3236fSMatthew G. Knepley for (v = 0; v < numValues; ++v) { 6936ebb3236fSMatthew G. Knepley IS tmp; 6937ebb3236fSMatthew G. Knepley const PetscInt *idx; 6938ebb3236fSMatthew G. Knepley 6939c58f1c22SToby Isaac ierr = DMGetStratumIS(dm, bdLabel, values[v], &tmp);CHKERRQ(ierr); 6940ebb3236fSMatthew G. Knepley if (!tmp) continue; 6941ebb3236fSMatthew G. Knepley ierr = ISGetLocalSize(tmp, &n);CHKERRQ(ierr); 6942ebb3236fSMatthew G. Knepley ierr = ISGetIndices(tmp, &idx);CHKERRQ(ierr); 6943ebb3236fSMatthew G. Knepley if (isFE[field]) { 6944ebb3236fSMatthew G. Knepley for (p = 0; p < n; ++p) if ((idx[p] < cStart) || (idx[p] >= cEnd)) newidx[newn++] = idx[p]; 6945ebb3236fSMatthew G. Knepley } else { 6946ebb3236fSMatthew G. Knepley for (p = 0; p < n; ++p) if ((idx[p] >= cStart) || (idx[p] < cEnd)) newidx[newn++] = idx[p]; 6947ebb3236fSMatthew G. Knepley } 6948ebb3236fSMatthew G. Knepley ierr = ISRestoreIndices(tmp, &idx);CHKERRQ(ierr); 6949ebb3236fSMatthew G. Knepley ierr = ISDestroy(&tmp);CHKERRQ(ierr); 6950ebb3236fSMatthew G. Knepley } 6951ebb3236fSMatthew G. Knepley ierr = ISCreateGeneral(PetscObjectComm((PetscObject) dm), newn, newidx, PETSC_OWN_POINTER, &bcPoints[bc++]);CHKERRQ(ierr); 6952ebb3236fSMatthew G. Knepley } 6953fd59a867SMatthew G. Knepley } 6954fd59a867SMatthew G. Knepley /* Handle discretization */ 6955ebb3236fSMatthew G. Knepley ierr = PetscCalloc2(numFields,&numComp,numFields*(dim+1),&numDof);CHKERRQ(ierr); 6956fd59a867SMatthew G. Knepley for (f = 0; f < numFields; ++f) { 69570bacfa0aSMatthew G. Knepley PetscObject obj; 69580bacfa0aSMatthew G. Knepley 69590bacfa0aSMatthew G. Knepley ierr = DMGetField(dm, f, &obj);CHKERRQ(ierr); 6960ebb3236fSMatthew G. Knepley if (isFE[f]) { 69610bacfa0aSMatthew G. Knepley PetscFE fe = (PetscFE) obj; 6962286d8613SMatthew G. Knepley const PetscInt *numFieldDof; 6963fd59a867SMatthew G. Knepley PetscInt d; 6964fd59a867SMatthew G. Knepley 6965fd59a867SMatthew G. Knepley ierr = PetscFEGetNumComponents(fe, &numComp[f]);CHKERRQ(ierr); 6966286d8613SMatthew G. Knepley ierr = PetscFEGetNumDof(fe, &numFieldDof);CHKERRQ(ierr); 6967286d8613SMatthew G. Knepley for (d = 0; d < dim+1; ++d) numDof[f*(dim+1)+d] = numFieldDof[d]; 6968ebb3236fSMatthew G. Knepley } else { 69690bacfa0aSMatthew G. Knepley PetscFV fv = (PetscFV) obj; 69700bacfa0aSMatthew G. Knepley 69710bacfa0aSMatthew G. Knepley ierr = PetscFVGetNumComponents(fv, &numComp[f]);CHKERRQ(ierr); 69720bacfa0aSMatthew G. Knepley numDof[f*(dim+1)+dim] = numComp[f]; 6973ebb3236fSMatthew G. Knepley } 6974fd59a867SMatthew G. Knepley } 6975286d8613SMatthew G. Knepley for (f = 0; f < numFields; ++f) { 6976286d8613SMatthew G. Knepley PetscInt d; 6977286d8613SMatthew G. Knepley for (d = 1; d < dim; ++d) { 6978286d8613SMatthew G. Knepley if ((numDof[f*(dim+1)+d] > 0) && (depth < dim)) SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "Mesh must be interpolated when unknowns are specified on edges or faces."); 6979286d8613SMatthew G. Knepley } 6980286d8613SMatthew G. Knepley } 6981ab1d0545SMatthew G. Knepley ierr = DMPlexCreateSection(dm, dim, numFields, numComp, numDof, numBC, bcFields, bcComps, bcPoints, NULL, §ion);CHKERRQ(ierr); 6982fd59a867SMatthew G. Knepley for (f = 0; f < numFields; ++f) { 6983fd59a867SMatthew G. Knepley PetscFE fe; 6984fd59a867SMatthew G. Knepley const char *name; 698518abd763SMatthew G. Knepley 698618abd763SMatthew G. Knepley ierr = DMGetField(dm, f, (PetscObject *) &fe);CHKERRQ(ierr); 6987fd59a867SMatthew G. Knepley ierr = PetscObjectGetName((PetscObject) fe, &name);CHKERRQ(ierr); 6988fd59a867SMatthew G. Knepley ierr = PetscSectionSetFieldName(section, f, name);CHKERRQ(ierr); 6989fd59a867SMatthew G. Knepley } 6990e87a4003SBarry Smith ierr = DMSetSection(dm, section);CHKERRQ(ierr); 6991fd59a867SMatthew G. Knepley ierr = PetscSectionDestroy(§ion);CHKERRQ(ierr); 69920e0f25f2SMatthew G. Knepley for (bc = 0; bc < numBC; ++bc) {ierr = ISDestroy(&bcPoints[bc]);CHKERRQ(ierr);ierr = ISDestroy(&bcComps[bc]);CHKERRQ(ierr);} 69930e0f25f2SMatthew G. Knepley ierr = PetscFree3(bcFields,bcPoints,bcComps);CHKERRQ(ierr); 6994286d8613SMatthew G. Knepley ierr = PetscFree2(numComp,numDof);CHKERRQ(ierr); 6995ebb3236fSMatthew G. Knepley ierr = PetscFree(isFE);CHKERRQ(ierr); 6996bceba477SMatthew G. Knepley PetscFunctionReturn(0); 6997bceba477SMatthew G. Knepley } 6998bceba477SMatthew G. Knepley 69990aef6b92SMatthew G. Knepley /*@ 70000aef6b92SMatthew G. Knepley DMPlexGetRegularRefinement - Get the flag indicating that this mesh was obtained by regular refinement from its coarse mesh 70010aef6b92SMatthew G. Knepley 70020aef6b92SMatthew G. Knepley Input Parameter: 70030aef6b92SMatthew G. Knepley . dm - The DMPlex object 70040aef6b92SMatthew G. Knepley 70050aef6b92SMatthew G. Knepley Output Parameter: 70060aef6b92SMatthew G. Knepley . regular - The flag 70070aef6b92SMatthew G. Knepley 70080aef6b92SMatthew G. Knepley Level: intermediate 70090aef6b92SMatthew G. Knepley 70100aef6b92SMatthew G. Knepley .seealso: DMPlexSetRegularRefinement() 70110aef6b92SMatthew G. Knepley @*/ 70120aef6b92SMatthew G. Knepley PetscErrorCode DMPlexGetRegularRefinement(DM dm, PetscBool *regular) 70130aef6b92SMatthew G. Knepley { 70140aef6b92SMatthew G. Knepley PetscFunctionBegin; 70150aef6b92SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 70160aef6b92SMatthew G. Knepley PetscValidPointer(regular, 2); 70170aef6b92SMatthew G. Knepley *regular = ((DM_Plex *) dm->data)->regularRefinement; 70180aef6b92SMatthew G. Knepley PetscFunctionReturn(0); 70190aef6b92SMatthew G. Knepley } 70200aef6b92SMatthew G. Knepley 70210aef6b92SMatthew G. Knepley /*@ 70220aef6b92SMatthew G. Knepley DMPlexSetRegularRefinement - Set the flag indicating that this mesh was obtained by regular refinement from its coarse mesh 70230aef6b92SMatthew G. Knepley 70240aef6b92SMatthew G. Knepley Input Parameters: 70250aef6b92SMatthew G. Knepley + dm - The DMPlex object 70260aef6b92SMatthew G. Knepley - regular - The flag 70270aef6b92SMatthew G. Knepley 70280aef6b92SMatthew G. Knepley Level: intermediate 70290aef6b92SMatthew G. Knepley 70300aef6b92SMatthew G. Knepley .seealso: DMPlexGetRegularRefinement() 70310aef6b92SMatthew G. Knepley @*/ 70320aef6b92SMatthew G. Knepley PetscErrorCode DMPlexSetRegularRefinement(DM dm, PetscBool regular) 70330aef6b92SMatthew G. Knepley { 70340aef6b92SMatthew G. Knepley PetscFunctionBegin; 70350aef6b92SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 70360aef6b92SMatthew G. Knepley ((DM_Plex *) dm->data)->regularRefinement = regular; 70370aef6b92SMatthew G. Knepley PetscFunctionReturn(0); 70380aef6b92SMatthew G. Knepley } 70390aef6b92SMatthew G. Knepley 7040f7c74593SToby Isaac /* anchors */ 7041a68b90caSToby Isaac /*@ 7042f7c74593SToby Isaac DMPlexGetAnchors - Get the layout of the anchor (point-to-point) constraints. Typically, the user will not have to 7043f7c74593SToby Isaac call DMPlexGetAnchors() directly: if there are anchors, then DMPlexGetAnchors() is called during DMGetConstraints(). 7044a68b90caSToby Isaac 7045e228b242SToby Isaac not collective 7046a68b90caSToby Isaac 7047a68b90caSToby Isaac Input Parameters: 7048a68b90caSToby Isaac . dm - The DMPlex object 7049a68b90caSToby Isaac 7050a68b90caSToby Isaac Output Parameters: 7051a68b90caSToby Isaac + anchorSection - If not NULL, set to the section describing which points anchor the constrained points. 7052a68b90caSToby Isaac - anchorIS - If not NULL, set to the list of anchors indexed by anchorSection 7053a68b90caSToby Isaac 7054a68b90caSToby Isaac 7055a68b90caSToby Isaac Level: intermediate 7056a68b90caSToby Isaac 7057f7c74593SToby Isaac .seealso: DMPlexSetAnchors(), DMGetConstraints(), DMSetConstraints() 7058a68b90caSToby Isaac @*/ 7059a17985deSToby Isaac PetscErrorCode DMPlexGetAnchors(DM dm, PetscSection *anchorSection, IS *anchorIS) 7060a68b90caSToby Isaac { 7061a68b90caSToby Isaac DM_Plex *plex = (DM_Plex *)dm->data; 706241e6d900SToby Isaac PetscErrorCode ierr; 7063a68b90caSToby Isaac 7064a68b90caSToby Isaac PetscFunctionBegin; 7065a68b90caSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 706641e6d900SToby Isaac if (!plex->anchorSection && !plex->anchorIS && plex->createanchors) {ierr = (*plex->createanchors)(dm);CHKERRQ(ierr);} 7067a68b90caSToby Isaac if (anchorSection) *anchorSection = plex->anchorSection; 7068a68b90caSToby Isaac if (anchorIS) *anchorIS = plex->anchorIS; 7069a68b90caSToby Isaac PetscFunctionReturn(0); 7070a68b90caSToby Isaac } 7071a68b90caSToby Isaac 7072a68b90caSToby Isaac /*@ 7073f7c74593SToby Isaac DMPlexSetAnchors - Set the layout of the local anchor (point-to-point) constraints. Unlike boundary conditions, 7074f7c74593SToby Isaac when a point's degrees of freedom in a section are constrained to an outside value, the anchor constraints set a 7075a68b90caSToby Isaac point's degrees of freedom to be a linear combination of other points' degrees of freedom. 7076a68b90caSToby Isaac 7077a17985deSToby Isaac After specifying the layout of constraints with DMPlexSetAnchors(), one specifies the constraints by calling 7078f7c74593SToby Isaac DMGetConstraints() and filling in the entries in the constraint matrix. 7079a68b90caSToby Isaac 7080e228b242SToby Isaac collective on dm 7081a68b90caSToby Isaac 7082a68b90caSToby Isaac Input Parameters: 7083a68b90caSToby Isaac + dm - The DMPlex object 7084e228b242SToby Isaac . anchorSection - The section that describes the mapping from constrained points to the anchor points listed in anchorIS. Must have a local communicator (PETSC_COMM_SELF or derivative). 7085e228b242SToby Isaac - anchorIS - The list of all anchor points. Must have a local communicator (PETSC_COMM_SELF or derivative). 7086a68b90caSToby Isaac 7087a68b90caSToby Isaac The reference counts of anchorSection and anchorIS are incremented. 7088a68b90caSToby Isaac 7089a68b90caSToby Isaac Level: intermediate 7090a68b90caSToby Isaac 7091f7c74593SToby Isaac .seealso: DMPlexGetAnchors(), DMGetConstraints(), DMSetConstraints() 7092a68b90caSToby Isaac @*/ 7093a17985deSToby Isaac PetscErrorCode DMPlexSetAnchors(DM dm, PetscSection anchorSection, IS anchorIS) 7094a68b90caSToby Isaac { 7095a68b90caSToby Isaac DM_Plex *plex = (DM_Plex *)dm->data; 7096e228b242SToby Isaac PetscMPIInt result; 7097a68b90caSToby Isaac PetscErrorCode ierr; 7098a68b90caSToby Isaac 7099a68b90caSToby Isaac PetscFunctionBegin; 7100a68b90caSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 7101e228b242SToby Isaac if (anchorSection) { 7102e228b242SToby Isaac PetscValidHeaderSpecific(anchorSection,PETSC_SECTION_CLASSID,2); 7103e228b242SToby Isaac ierr = MPI_Comm_compare(PETSC_COMM_SELF,PetscObjectComm((PetscObject)anchorSection),&result);CHKERRQ(ierr); 7104f6a3d38cSToby Isaac if (result != MPI_CONGRUENT && result != MPI_IDENT) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NOTSAMECOMM,"anchor section must have local communicator"); 7105e228b242SToby Isaac } 7106e228b242SToby Isaac if (anchorIS) { 7107e228b242SToby Isaac PetscValidHeaderSpecific(anchorIS,IS_CLASSID,3); 7108e228b242SToby Isaac ierr = MPI_Comm_compare(PETSC_COMM_SELF,PetscObjectComm((PetscObject)anchorIS),&result);CHKERRQ(ierr); 7109f6a3d38cSToby Isaac if (result != MPI_CONGRUENT && result != MPI_IDENT) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NOTSAMECOMM,"anchor IS must have local communicator"); 7110e228b242SToby Isaac } 7111a68b90caSToby Isaac 7112a68b90caSToby Isaac ierr = PetscObjectReference((PetscObject)anchorSection);CHKERRQ(ierr); 7113a68b90caSToby Isaac ierr = PetscSectionDestroy(&plex->anchorSection);CHKERRQ(ierr); 7114a68b90caSToby Isaac plex->anchorSection = anchorSection; 7115a68b90caSToby Isaac 7116a68b90caSToby Isaac ierr = PetscObjectReference((PetscObject)anchorIS);CHKERRQ(ierr); 7117a68b90caSToby Isaac ierr = ISDestroy(&plex->anchorIS);CHKERRQ(ierr); 7118a68b90caSToby Isaac plex->anchorIS = anchorIS; 7119a68b90caSToby Isaac 7120a68b90caSToby Isaac #if defined(PETSC_USE_DEBUG) 7121a68b90caSToby Isaac if (anchorIS && anchorSection) { 7122a68b90caSToby Isaac PetscInt size, a, pStart, pEnd; 7123a68b90caSToby Isaac const PetscInt *anchors; 7124a68b90caSToby Isaac 7125a68b90caSToby Isaac ierr = PetscSectionGetChart(anchorSection,&pStart,&pEnd);CHKERRQ(ierr); 7126a68b90caSToby Isaac ierr = ISGetLocalSize(anchorIS,&size);CHKERRQ(ierr); 7127a68b90caSToby Isaac ierr = ISGetIndices(anchorIS,&anchors);CHKERRQ(ierr); 7128a68b90caSToby Isaac for (a = 0; a < size; a++) { 7129a68b90caSToby Isaac PetscInt p; 7130a68b90caSToby Isaac 7131a68b90caSToby Isaac p = anchors[a]; 7132a68b90caSToby Isaac if (p >= pStart && p < pEnd) { 7133a68b90caSToby Isaac PetscInt dof; 7134a68b90caSToby Isaac 7135a68b90caSToby Isaac ierr = PetscSectionGetDof(anchorSection,p,&dof);CHKERRQ(ierr); 7136a68b90caSToby Isaac if (dof) { 7137a68b90caSToby Isaac PetscErrorCode ierr2; 7138a68b90caSToby Isaac 7139a68b90caSToby Isaac ierr2 = ISRestoreIndices(anchorIS,&anchors);CHKERRQ(ierr2); 71408ccfff9cSToby Isaac SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_INCOMP,"Point %D cannot be constrained and an anchor",p); 7141a68b90caSToby Isaac } 7142a68b90caSToby Isaac } 7143a68b90caSToby Isaac } 7144a68b90caSToby Isaac ierr = ISRestoreIndices(anchorIS,&anchors);CHKERRQ(ierr); 7145a68b90caSToby Isaac } 7146a68b90caSToby Isaac #endif 7147f7c74593SToby Isaac /* reset the generic constraints */ 7148f7c74593SToby Isaac ierr = DMSetDefaultConstraints(dm,NULL,NULL);CHKERRQ(ierr); 7149a68b90caSToby Isaac PetscFunctionReturn(0); 7150a68b90caSToby Isaac } 7151a68b90caSToby Isaac 7152f7c74593SToby Isaac static PetscErrorCode DMPlexCreateConstraintSection_Anchors(DM dm, PetscSection section, PetscSection *cSec) 7153a68b90caSToby Isaac { 7154f7c74593SToby Isaac PetscSection anchorSection; 71556995de1eSToby Isaac PetscInt pStart, pEnd, sStart, sEnd, p, dof, numFields, f; 7156a68b90caSToby Isaac PetscErrorCode ierr; 7157a68b90caSToby Isaac 7158a68b90caSToby Isaac PetscFunctionBegin; 7159a68b90caSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 7160a17985deSToby Isaac ierr = DMPlexGetAnchors(dm,&anchorSection,NULL);CHKERRQ(ierr); 7161e228b242SToby Isaac ierr = PetscSectionCreate(PETSC_COMM_SELF,cSec);CHKERRQ(ierr); 7162a68b90caSToby Isaac ierr = PetscSectionGetNumFields(section,&numFields);CHKERRQ(ierr); 71636995de1eSToby Isaac if (numFields) { 7164719ab38cSToby Isaac PetscInt f; 7165a68b90caSToby Isaac ierr = PetscSectionSetNumFields(*cSec,numFields);CHKERRQ(ierr); 7166719ab38cSToby Isaac 7167719ab38cSToby Isaac for (f = 0; f < numFields; f++) { 7168719ab38cSToby Isaac PetscInt numComp; 7169719ab38cSToby Isaac 7170719ab38cSToby Isaac ierr = PetscSectionGetFieldComponents(section,f,&numComp);CHKERRQ(ierr); 7171719ab38cSToby Isaac ierr = PetscSectionSetFieldComponents(*cSec,f,numComp);CHKERRQ(ierr); 7172719ab38cSToby Isaac } 71736995de1eSToby Isaac } 7174a68b90caSToby Isaac ierr = PetscSectionGetChart(anchorSection,&pStart,&pEnd);CHKERRQ(ierr); 71756995de1eSToby Isaac ierr = PetscSectionGetChart(section,&sStart,&sEnd);CHKERRQ(ierr); 71766995de1eSToby Isaac pStart = PetscMax(pStart,sStart); 71776995de1eSToby Isaac pEnd = PetscMin(pEnd,sEnd); 71786995de1eSToby Isaac pEnd = PetscMax(pStart,pEnd); 7179a68b90caSToby Isaac ierr = PetscSectionSetChart(*cSec,pStart,pEnd);CHKERRQ(ierr); 7180a68b90caSToby Isaac for (p = pStart; p < pEnd; p++) { 7181a68b90caSToby Isaac ierr = PetscSectionGetDof(anchorSection,p,&dof);CHKERRQ(ierr); 7182a68b90caSToby Isaac if (dof) { 7183a68b90caSToby Isaac ierr = PetscSectionGetDof(section,p,&dof);CHKERRQ(ierr); 7184a68b90caSToby Isaac ierr = PetscSectionSetDof(*cSec,p,dof);CHKERRQ(ierr); 7185a68b90caSToby Isaac for (f = 0; f < numFields; f++) { 7186a68b90caSToby Isaac ierr = PetscSectionGetFieldDof(section,p,f,&dof);CHKERRQ(ierr); 7187a68b90caSToby Isaac ierr = PetscSectionSetFieldDof(*cSec,p,f,dof);CHKERRQ(ierr); 7188a68b90caSToby Isaac } 7189a68b90caSToby Isaac } 7190a68b90caSToby Isaac } 7191a68b90caSToby Isaac ierr = PetscSectionSetUp(*cSec);CHKERRQ(ierr); 7192a68b90caSToby Isaac PetscFunctionReturn(0); 7193a68b90caSToby Isaac } 7194a68b90caSToby Isaac 7195f7c74593SToby Isaac static PetscErrorCode DMPlexCreateConstraintMatrix_Anchors(DM dm, PetscSection section, PetscSection cSec, Mat *cMat) 7196a68b90caSToby Isaac { 7197f7c74593SToby Isaac PetscSection aSec; 71980ac89760SToby Isaac PetscInt pStart, pEnd, p, dof, aDof, aOff, off, nnz, annz, m, n, q, a, offset, *i, *j; 71990ac89760SToby Isaac const PetscInt *anchors; 72000ac89760SToby Isaac PetscInt numFields, f; 720166ad2231SToby Isaac IS aIS; 72020ac89760SToby Isaac PetscErrorCode ierr; 72030ac89760SToby Isaac 72040ac89760SToby Isaac PetscFunctionBegin; 72050ac89760SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 72060ac89760SToby Isaac ierr = PetscSectionGetStorageSize(cSec, &m);CHKERRQ(ierr); 72070ac89760SToby Isaac ierr = PetscSectionGetStorageSize(section, &n);CHKERRQ(ierr); 72080ac89760SToby Isaac ierr = MatCreate(PETSC_COMM_SELF,cMat);CHKERRQ(ierr); 72090ac89760SToby Isaac ierr = MatSetSizes(*cMat,m,n,m,n);CHKERRQ(ierr); 7210302440fdSBarry Smith ierr = MatSetType(*cMat,MATSEQAIJ);CHKERRQ(ierr); 7211a17985deSToby Isaac ierr = DMPlexGetAnchors(dm,&aSec,&aIS);CHKERRQ(ierr); 721266ad2231SToby Isaac ierr = ISGetIndices(aIS,&anchors);CHKERRQ(ierr); 72136995de1eSToby Isaac /* cSec will be a subset of aSec and section */ 72146995de1eSToby Isaac ierr = PetscSectionGetChart(cSec,&pStart,&pEnd);CHKERRQ(ierr); 72150ac89760SToby Isaac ierr = PetscMalloc1(m+1,&i);CHKERRQ(ierr); 72160ac89760SToby Isaac i[0] = 0; 72170ac89760SToby Isaac ierr = PetscSectionGetNumFields(section,&numFields);CHKERRQ(ierr); 72180ac89760SToby Isaac for (p = pStart; p < pEnd; p++) { 7219f19733c5SToby Isaac PetscInt rDof, rOff, r; 7220f19733c5SToby Isaac 7221f19733c5SToby Isaac ierr = PetscSectionGetDof(aSec,p,&rDof);CHKERRQ(ierr); 7222f19733c5SToby Isaac if (!rDof) continue; 7223f19733c5SToby Isaac ierr = PetscSectionGetOffset(aSec,p,&rOff);CHKERRQ(ierr); 72240ac89760SToby Isaac if (numFields) { 72250ac89760SToby Isaac for (f = 0; f < numFields; f++) { 72260ac89760SToby Isaac annz = 0; 7227f19733c5SToby Isaac for (r = 0; r < rDof; r++) { 7228f19733c5SToby Isaac a = anchors[rOff + r]; 72290ac89760SToby Isaac ierr = PetscSectionGetFieldDof(section,a,f,&aDof);CHKERRQ(ierr); 72300ac89760SToby Isaac annz += aDof; 72310ac89760SToby Isaac } 72320ac89760SToby Isaac ierr = PetscSectionGetFieldDof(cSec,p,f,&dof);CHKERRQ(ierr); 72330ac89760SToby Isaac ierr = PetscSectionGetFieldOffset(cSec,p,f,&off);CHKERRQ(ierr); 72340ac89760SToby Isaac for (q = 0; q < dof; q++) { 72350ac89760SToby Isaac i[off + q + 1] = i[off + q] + annz; 72360ac89760SToby Isaac } 72370ac89760SToby Isaac } 72380ac89760SToby Isaac } 72390ac89760SToby Isaac else { 72400ac89760SToby Isaac annz = 0; 72410ac89760SToby Isaac for (q = 0; q < dof; q++) { 72420ac89760SToby Isaac a = anchors[off + q]; 72430ac89760SToby Isaac ierr = PetscSectionGetDof(section,a,&aDof);CHKERRQ(ierr); 72440ac89760SToby Isaac annz += aDof; 72450ac89760SToby Isaac } 72460ac89760SToby Isaac ierr = PetscSectionGetDof(cSec,p,&dof);CHKERRQ(ierr); 72470ac89760SToby Isaac ierr = PetscSectionGetOffset(cSec,p,&off);CHKERRQ(ierr); 72480ac89760SToby Isaac for (q = 0; q < dof; q++) { 72490ac89760SToby Isaac i[off + q + 1] = i[off + q] + annz; 72500ac89760SToby Isaac } 72510ac89760SToby Isaac } 72520ac89760SToby Isaac } 72530ac89760SToby Isaac nnz = i[m]; 72540ac89760SToby Isaac ierr = PetscMalloc1(nnz,&j);CHKERRQ(ierr); 72550ac89760SToby Isaac offset = 0; 72560ac89760SToby Isaac for (p = pStart; p < pEnd; p++) { 72570ac89760SToby Isaac if (numFields) { 72580ac89760SToby Isaac for (f = 0; f < numFields; f++) { 72590ac89760SToby Isaac ierr = PetscSectionGetFieldDof(cSec,p,f,&dof);CHKERRQ(ierr); 72600ac89760SToby Isaac for (q = 0; q < dof; q++) { 72610ac89760SToby Isaac PetscInt rDof, rOff, r; 72620ac89760SToby Isaac ierr = PetscSectionGetDof(aSec,p,&rDof);CHKERRQ(ierr); 72630ac89760SToby Isaac ierr = PetscSectionGetOffset(aSec,p,&rOff);CHKERRQ(ierr); 72640ac89760SToby Isaac for (r = 0; r < rDof; r++) { 72650ac89760SToby Isaac PetscInt s; 72660ac89760SToby Isaac 72670ac89760SToby Isaac a = anchors[rOff + r]; 72680ac89760SToby Isaac ierr = PetscSectionGetFieldDof(section,a,f,&aDof);CHKERRQ(ierr); 72690ac89760SToby Isaac ierr = PetscSectionGetFieldOffset(section,a,f,&aOff);CHKERRQ(ierr); 72700ac89760SToby Isaac for (s = 0; s < aDof; s++) { 72710ac89760SToby Isaac j[offset++] = aOff + s; 72720ac89760SToby Isaac } 72730ac89760SToby Isaac } 72740ac89760SToby Isaac } 72750ac89760SToby Isaac } 72760ac89760SToby Isaac } 72770ac89760SToby Isaac else { 72780ac89760SToby Isaac ierr = PetscSectionGetDof(cSec,p,&dof);CHKERRQ(ierr); 72790ac89760SToby Isaac for (q = 0; q < dof; q++) { 72800ac89760SToby Isaac PetscInt rDof, rOff, r; 72810ac89760SToby Isaac ierr = PetscSectionGetDof(aSec,p,&rDof);CHKERRQ(ierr); 72820ac89760SToby Isaac ierr = PetscSectionGetOffset(aSec,p,&rOff);CHKERRQ(ierr); 72830ac89760SToby Isaac for (r = 0; r < rDof; r++) { 72840ac89760SToby Isaac PetscInt s; 72850ac89760SToby Isaac 72860ac89760SToby Isaac a = anchors[rOff + r]; 72870ac89760SToby Isaac ierr = PetscSectionGetDof(section,a,&aDof);CHKERRQ(ierr); 72880ac89760SToby Isaac ierr = PetscSectionGetOffset(section,a,&aOff);CHKERRQ(ierr); 72890ac89760SToby Isaac for (s = 0; s < aDof; s++) { 72900ac89760SToby Isaac j[offset++] = aOff + s; 72910ac89760SToby Isaac } 72920ac89760SToby Isaac } 72930ac89760SToby Isaac } 72940ac89760SToby Isaac } 72950ac89760SToby Isaac } 72960ac89760SToby Isaac ierr = MatSeqAIJSetPreallocationCSR(*cMat,i,j,NULL);CHKERRQ(ierr); 729725570a81SToby Isaac ierr = PetscFree(i);CHKERRQ(ierr); 729825570a81SToby Isaac ierr = PetscFree(j);CHKERRQ(ierr); 729966ad2231SToby Isaac ierr = ISRestoreIndices(aIS,&anchors);CHKERRQ(ierr); 73000ac89760SToby Isaac PetscFunctionReturn(0); 73010ac89760SToby Isaac } 73020ac89760SToby Isaac 730366ad2231SToby Isaac PetscErrorCode DMCreateDefaultConstraints_Plex(DM dm) 730466ad2231SToby Isaac { 7305f7c74593SToby Isaac DM_Plex *plex = (DM_Plex *)dm->data; 7306f7c74593SToby Isaac PetscSection anchorSection, section, cSec; 730766ad2231SToby Isaac Mat cMat; 730866ad2231SToby Isaac PetscErrorCode ierr; 730966ad2231SToby Isaac 731066ad2231SToby Isaac PetscFunctionBegin; 731166ad2231SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 7312a17985deSToby Isaac ierr = DMPlexGetAnchors(dm,&anchorSection,NULL);CHKERRQ(ierr); 731366ad2231SToby Isaac if (anchorSection) { 7314e228b242SToby Isaac PetscDS ds; 7315e228b242SToby Isaac PetscInt nf; 7316e228b242SToby Isaac 7317e87a4003SBarry Smith ierr = DMGetSection(dm,§ion);CHKERRQ(ierr); 7318f7c74593SToby Isaac ierr = DMPlexCreateConstraintSection_Anchors(dm,section,&cSec);CHKERRQ(ierr); 7319f7c74593SToby Isaac ierr = DMPlexCreateConstraintMatrix_Anchors(dm,section,cSec,&cMat);CHKERRQ(ierr); 7320e228b242SToby Isaac ierr = DMGetDS(dm,&ds);CHKERRQ(ierr); 7321302440fdSBarry Smith ierr = PetscDSGetNumFields(ds,&nf);CHKERRQ(ierr); 7322e228b242SToby Isaac if (nf && plex->computeanchormatrix) {ierr = (*plex->computeanchormatrix)(dm,section,cSec,cMat);CHKERRQ(ierr);} 732366ad2231SToby Isaac ierr = DMSetDefaultConstraints(dm,cSec,cMat);CHKERRQ(ierr); 732466ad2231SToby Isaac ierr = PetscSectionDestroy(&cSec);CHKERRQ(ierr); 732566ad2231SToby Isaac ierr = MatDestroy(&cMat);CHKERRQ(ierr); 732666ad2231SToby Isaac } 732766ad2231SToby Isaac PetscFunctionReturn(0); 732866ad2231SToby Isaac } 7329a93c429eSMatthew G. Knepley 7330a93c429eSMatthew G. Knepley PetscErrorCode DMCreateSubDomainDM_Plex(DM dm, DMLabel label, PetscInt value, IS *is, DM *subdm) 7331a93c429eSMatthew G. Knepley { 7332a93c429eSMatthew G. Knepley PetscDS prob; 7333a93c429eSMatthew G. Knepley IS subis; 7334a93c429eSMatthew G. Knepley PetscSection section, subsection; 7335a93c429eSMatthew G. Knepley PetscErrorCode ierr; 7336a93c429eSMatthew G. Knepley 7337a93c429eSMatthew G. Knepley PetscFunctionBegin; 7338a93c429eSMatthew G. Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 7339a93c429eSMatthew G. Knepley if (!section) SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "Must set default section for DM before splitting subdomain"); 7340a93c429eSMatthew G. Knepley if (!subdm) SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "Must set output subDM for splitting subdomain"); 7341a93c429eSMatthew G. Knepley /* Create subdomain */ 7342a93c429eSMatthew G. Knepley ierr = DMPlexFilter(dm, label, value, subdm);CHKERRQ(ierr); 7343a93c429eSMatthew G. Knepley /* Create submodel */ 7344a93c429eSMatthew G. Knepley ierr = DMPlexCreateSubpointIS(*subdm, &subis);CHKERRQ(ierr); 7345a93c429eSMatthew G. Knepley ierr = PetscSectionCreateSubmeshSection(section, subis, &subsection);CHKERRQ(ierr); 7346a93c429eSMatthew G. Knepley ierr = ISDestroy(&subis);CHKERRQ(ierr); 7347a93c429eSMatthew G. Knepley ierr = DMSetDefaultSection(*subdm, subsection);CHKERRQ(ierr); 7348a93c429eSMatthew G. Knepley ierr = PetscSectionDestroy(&subsection);CHKERRQ(ierr); 7349a93c429eSMatthew G. Knepley ierr = DMGetDS(dm, &prob);CHKERRQ(ierr); 7350a93c429eSMatthew G. Knepley ierr = DMSetDS(*subdm, prob);CHKERRQ(ierr); 7351a93c429eSMatthew G. Knepley /* Create map from submodel to global model */ 7352a93c429eSMatthew G. Knepley if (is) { 7353a93c429eSMatthew G. Knepley PetscSection sectionGlobal, subsectionGlobal; 7354a93c429eSMatthew G. Knepley IS spIS; 7355a93c429eSMatthew G. Knepley const PetscInt *spmap; 7356a93c429eSMatthew G. Knepley PetscInt *subIndices; 7357a93c429eSMatthew G. Knepley PetscInt subSize = 0, subOff = 0, pStart, pEnd, p; 7358a93c429eSMatthew G. Knepley PetscInt Nf, f, bs = -1, bsLocal[2], bsMinMax[2]; 7359a93c429eSMatthew G. Knepley 7360a93c429eSMatthew G. Knepley ierr = DMPlexCreateSubpointIS(*subdm, &spIS);CHKERRQ(ierr); 7361a93c429eSMatthew G. Knepley ierr = ISGetIndices(spIS, &spmap);CHKERRQ(ierr); 7362a93c429eSMatthew G. Knepley ierr = PetscSectionGetNumFields(section, &Nf);CHKERRQ(ierr); 7363a93c429eSMatthew G. Knepley ierr = DMGetDefaultGlobalSection(dm, §ionGlobal);CHKERRQ(ierr); 7364a93c429eSMatthew G. Knepley ierr = DMGetDefaultGlobalSection(*subdm, &subsectionGlobal);CHKERRQ(ierr); 7365a93c429eSMatthew G. Knepley ierr = PetscSectionGetChart(subsection, &pStart, &pEnd);CHKERRQ(ierr); 7366a93c429eSMatthew G. Knepley for (p = pStart; p < pEnd; ++p) { 7367a93c429eSMatthew G. Knepley PetscInt gdof, pSubSize = 0; 7368a93c429eSMatthew G. Knepley 7369a93c429eSMatthew G. Knepley ierr = PetscSectionGetDof(sectionGlobal, p, &gdof);CHKERRQ(ierr); 7370a93c429eSMatthew G. Knepley if (gdof > 0) { 7371a93c429eSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 7372a93c429eSMatthew G. Knepley PetscInt fdof, fcdof; 7373a93c429eSMatthew G. Knepley 7374a93c429eSMatthew G. Knepley ierr = PetscSectionGetFieldDof(subsection, p, f, &fdof);CHKERRQ(ierr); 7375a93c429eSMatthew G. Knepley ierr = PetscSectionGetFieldConstraintDof(subsection, p, f, &fcdof);CHKERRQ(ierr); 7376a93c429eSMatthew G. Knepley pSubSize += fdof-fcdof; 7377a93c429eSMatthew G. Knepley } 7378a93c429eSMatthew G. Knepley subSize += pSubSize; 7379a93c429eSMatthew G. Knepley if (pSubSize) { 7380a93c429eSMatthew G. Knepley if (bs < 0) { 7381a93c429eSMatthew G. Knepley bs = pSubSize; 7382a93c429eSMatthew G. Knepley } else if (bs != pSubSize) { 7383a93c429eSMatthew G. Knepley /* Layout does not admit a pointwise block size */ 7384a93c429eSMatthew G. Knepley bs = 1; 7385a93c429eSMatthew G. Knepley } 7386a93c429eSMatthew G. Knepley } 7387a93c429eSMatthew G. Knepley } 7388a93c429eSMatthew G. Knepley } 7389a93c429eSMatthew G. Knepley /* Must have same blocksize on all procs (some might have no points) */ 7390a93c429eSMatthew G. Knepley bsLocal[0] = bs < 0 ? PETSC_MAX_INT : bs; bsLocal[1] = bs; 7391a93c429eSMatthew G. Knepley ierr = PetscGlobalMinMaxInt(PetscObjectComm((PetscObject) dm), bsLocal, bsMinMax);CHKERRQ(ierr); 7392a93c429eSMatthew G. Knepley if (bsMinMax[0] != bsMinMax[1]) {bs = 1;} 7393a93c429eSMatthew G. Knepley else {bs = bsMinMax[0];} 7394a93c429eSMatthew G. Knepley ierr = PetscMalloc1(subSize, &subIndices);CHKERRQ(ierr); 7395a93c429eSMatthew G. Knepley for (p = pStart; p < pEnd; ++p) { 7396a93c429eSMatthew G. Knepley PetscInt gdof, goff; 7397a93c429eSMatthew G. Knepley 7398a93c429eSMatthew G. Knepley ierr = PetscSectionGetDof(subsectionGlobal, p, &gdof);CHKERRQ(ierr); 7399a93c429eSMatthew G. Knepley if (gdof > 0) { 7400a93c429eSMatthew G. Knepley const PetscInt point = spmap[p]; 7401a93c429eSMatthew G. Knepley 7402a93c429eSMatthew G. Knepley ierr = PetscSectionGetOffset(sectionGlobal, point, &goff);CHKERRQ(ierr); 7403a93c429eSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 7404a93c429eSMatthew G. Knepley PetscInt fdof, fcdof, fc, f2, poff = 0; 7405a93c429eSMatthew G. Knepley 7406a93c429eSMatthew G. Knepley /* Can get rid of this loop by storing field information in the global section */ 7407a93c429eSMatthew G. Knepley for (f2 = 0; f2 < f; ++f2) { 7408a93c429eSMatthew G. Knepley ierr = PetscSectionGetFieldDof(section, p, f2, &fdof);CHKERRQ(ierr); 7409a93c429eSMatthew G. Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, f2, &fcdof);CHKERRQ(ierr); 7410a93c429eSMatthew G. Knepley poff += fdof-fcdof; 7411a93c429eSMatthew G. Knepley } 7412a93c429eSMatthew G. Knepley ierr = PetscSectionGetFieldDof(section, p, f, &fdof);CHKERRQ(ierr); 7413a93c429eSMatthew G. Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, f, &fcdof);CHKERRQ(ierr); 7414a93c429eSMatthew G. Knepley for (fc = 0; fc < fdof-fcdof; ++fc, ++subOff) { 7415a93c429eSMatthew G. Knepley subIndices[subOff] = goff+poff+fc; 7416a93c429eSMatthew G. Knepley } 7417a93c429eSMatthew G. Knepley } 7418a93c429eSMatthew G. Knepley } 7419a93c429eSMatthew G. Knepley } 7420a93c429eSMatthew G. Knepley ierr = ISRestoreIndices(spIS, &spmap);CHKERRQ(ierr); 7421a93c429eSMatthew G. Knepley ierr = ISDestroy(&spIS);CHKERRQ(ierr); 7422a93c429eSMatthew G. Knepley ierr = ISCreateGeneral(PetscObjectComm((PetscObject)dm), subSize, subIndices, PETSC_OWN_POINTER, is);CHKERRQ(ierr); 7423a93c429eSMatthew G. Knepley if (bs > 1) { 7424a93c429eSMatthew G. Knepley /* We need to check that the block size does not come from non-contiguous fields */ 7425a93c429eSMatthew G. Knepley PetscInt i, j, set = 1; 7426a93c429eSMatthew G. Knepley for (i = 0; i < subSize; i += bs) { 7427a93c429eSMatthew G. Knepley for (j = 0; j < bs; ++j) { 7428a93c429eSMatthew G. Knepley if (subIndices[i+j] != subIndices[i]+j) {set = 0; break;} 7429a93c429eSMatthew G. Knepley } 7430a93c429eSMatthew G. Knepley } 7431a93c429eSMatthew G. Knepley if (set) {ierr = ISSetBlockSize(*is, bs);CHKERRQ(ierr);} 7432a93c429eSMatthew G. Knepley } 7433a93c429eSMatthew G. Knepley /* Attach nullspace */ 7434a93c429eSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 7435a93c429eSMatthew G. Knepley (*subdm)->nullspaceConstructors[f] = dm->nullspaceConstructors[f]; 7436a93c429eSMatthew G. Knepley if ((*subdm)->nullspaceConstructors[f]) break; 7437a93c429eSMatthew G. Knepley } 7438a93c429eSMatthew G. Knepley if (f < Nf) { 7439a93c429eSMatthew G. Knepley MatNullSpace nullSpace; 7440a93c429eSMatthew G. Knepley 7441a93c429eSMatthew G. Knepley ierr = (*(*subdm)->nullspaceConstructors[f])(*subdm, f, &nullSpace);CHKERRQ(ierr); 7442a93c429eSMatthew G. Knepley ierr = PetscObjectCompose((PetscObject) *is, "nullspace", (PetscObject) nullSpace);CHKERRQ(ierr); 7443a93c429eSMatthew G. Knepley ierr = MatNullSpaceDestroy(&nullSpace);CHKERRQ(ierr); 7444a93c429eSMatthew G. Knepley } 7445a93c429eSMatthew G. Knepley } 7446a93c429eSMatthew G. Knepley PetscFunctionReturn(0); 7447a93c429eSMatthew G. Knepley } 7448