1ea844a1aSMatthew Knepley /* 2ea844a1aSMatthew Knepley This file contains routines for basic section object implementation. 3ea844a1aSMatthew Knepley */ 4ea844a1aSMatthew Knepley 5ea844a1aSMatthew Knepley #include <petsc/private/sectionimpl.h> /*I "petscsection.h" I*/ 6ea844a1aSMatthew Knepley #include <petscsf.h> 7ea844a1aSMatthew Knepley 8ea844a1aSMatthew Knepley PetscClassId PETSC_SECTION_CLASSID; 9ea844a1aSMatthew Knepley 10ea844a1aSMatthew Knepley /*@ 1120662ed9SBarry Smith PetscSectionCreate - Allocates a `PetscSection` and sets the map contents to the default. 12ea844a1aSMatthew Knepley 13ea844a1aSMatthew Knepley Collective 14ea844a1aSMatthew Knepley 15ea844a1aSMatthew Knepley Input Parameters: 16ea844a1aSMatthew Knepley + comm - the MPI communicator 17ea844a1aSMatthew Knepley - s - pointer to the section 18ea844a1aSMatthew Knepley 19ea844a1aSMatthew Knepley Level: beginner 20ea844a1aSMatthew Knepley 21ea844a1aSMatthew Knepley Notes: 22ea844a1aSMatthew Knepley Typical calling sequence 23cab54364SBarry Smith .vb 24cab54364SBarry Smith PetscSectionCreate(MPI_Comm,PetscSection *);! 25cab54364SBarry Smith PetscSectionSetNumFields(PetscSection, numFields); 26cab54364SBarry Smith PetscSectionSetChart(PetscSection,low,high); 27cab54364SBarry Smith PetscSectionSetDof(PetscSection,point,numdof); 28cab54364SBarry Smith PetscSectionSetUp(PetscSection); 29cab54364SBarry Smith PetscSectionGetOffset(PetscSection,point,PetscInt *); 30cab54364SBarry Smith PetscSectionDestroy(PetscSection); 31cab54364SBarry Smith .ve 32ea844a1aSMatthew Knepley 3335cb6cd3SPierre Jolivet The `PetscSection` object and methods are intended to be used in the PETSc `Vec` and `Mat` implementations. The indices returned by the `PetscSection` are appropriate for the kind of `Vec` it is associated with. For example, if the vector being indexed is a local vector, we call the section a local section. If the section indexes a global vector, we call it a global section. For parallel vectors, like global vectors, we use negative indices to indicate dofs owned by other processes. 34ea844a1aSMatthew Knepley 35583308b6SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetChart()`, `PetscSectionDestroy()`, `PetscSectionCreateGlobalSection()` 36ea844a1aSMatthew Knepley @*/ 37d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreate(MPI_Comm comm, PetscSection *s) 38d71ae5a4SJacob Faibussowitsch { 39ea844a1aSMatthew Knepley PetscFunctionBegin; 404f572ea9SToby Isaac PetscAssertPointer(s, 2); 419566063dSJacob Faibussowitsch PetscCall(ISInitializePackage()); 42ea844a1aSMatthew Knepley 439566063dSJacob Faibussowitsch PetscCall(PetscHeaderCreate(*s, PETSC_SECTION_CLASSID, "PetscSection", "Section", "IS", comm, PetscSectionDestroy, PetscSectionView)); 44ea844a1aSMatthew Knepley 45ea844a1aSMatthew Knepley (*s)->pStart = -1; 46ea844a1aSMatthew Knepley (*s)->pEnd = -1; 47ea844a1aSMatthew Knepley (*s)->perm = NULL; 48ea844a1aSMatthew Knepley (*s)->pointMajor = PETSC_TRUE; 4987e637c6Sksagiyam (*s)->includesConstraints = PETSC_TRUE; 50ea844a1aSMatthew Knepley (*s)->atlasDof = NULL; 51ea844a1aSMatthew Knepley (*s)->atlasOff = NULL; 52ea844a1aSMatthew Knepley (*s)->bc = NULL; 53ea844a1aSMatthew Knepley (*s)->bcIndices = NULL; 54ea844a1aSMatthew Knepley (*s)->setup = PETSC_FALSE; 55ea844a1aSMatthew Knepley (*s)->numFields = 0; 56ea844a1aSMatthew Knepley (*s)->fieldNames = NULL; 57ea844a1aSMatthew Knepley (*s)->field = NULL; 58ea844a1aSMatthew Knepley (*s)->useFieldOff = PETSC_FALSE; 59b778fa18SValeria Barra (*s)->compNames = NULL; 60ea844a1aSMatthew Knepley (*s)->clObj = NULL; 61c459fbc1SJed Brown (*s)->clHash = NULL; 62ea844a1aSMatthew Knepley (*s)->clSection = NULL; 63ea844a1aSMatthew Knepley (*s)->clPoints = NULL; 6469c11d05SVaclav Hapla PetscCall(PetscSectionInvalidateMaxDof_Internal(*s)); 653ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 66ea844a1aSMatthew Knepley } 67ea844a1aSMatthew Knepley 68ea844a1aSMatthew Knepley /*@ 69cab54364SBarry Smith PetscSectionCopy - Creates a shallow (if possible) copy of the `PetscSection` 70ea844a1aSMatthew Knepley 71ea844a1aSMatthew Knepley Collective 72ea844a1aSMatthew Knepley 73ea844a1aSMatthew Knepley Input Parameter: 74cab54364SBarry Smith . section - the `PetscSection` 75ea844a1aSMatthew Knepley 76ea844a1aSMatthew Knepley Output Parameter: 77ea844a1aSMatthew Knepley . newSection - the copy 78ea844a1aSMatthew Knepley 79ea844a1aSMatthew Knepley Level: intermediate 80ea844a1aSMatthew Knepley 8138b5cf2dSJacob Faibussowitsch Developer Notes: 82cab54364SBarry Smith What exactly does shallow mean in this context? 83cab54364SBarry Smith 84cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionDestroy()` 85ea844a1aSMatthew Knepley @*/ 86d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCopy(PetscSection section, PetscSection newSection) 87d71ae5a4SJacob Faibussowitsch { 88ea844a1aSMatthew Knepley PetscSectionSym sym; 89ea844a1aSMatthew Knepley IS perm; 90b778fa18SValeria Barra PetscInt numFields, f, c, pStart, pEnd, p; 91ea844a1aSMatthew Knepley 92ea844a1aSMatthew Knepley PetscFunctionBegin; 93ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 94ea844a1aSMatthew Knepley PetscValidHeaderSpecific(newSection, PETSC_SECTION_CLASSID, 2); 959566063dSJacob Faibussowitsch PetscCall(PetscSectionReset(newSection)); 969566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(section, &numFields)); 979566063dSJacob Faibussowitsch if (numFields) PetscCall(PetscSectionSetNumFields(newSection, numFields)); 98ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 99b778fa18SValeria Barra const char *fieldName = NULL, *compName = NULL; 100ea844a1aSMatthew Knepley PetscInt numComp = 0; 101ea844a1aSMatthew Knepley 1029566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldName(section, f, &fieldName)); 1039566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldName(newSection, f, fieldName)); 1049566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(section, f, &numComp)); 1059566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(newSection, f, numComp)); 106b778fa18SValeria Barra for (c = 0; c < numComp; ++c) { 1079566063dSJacob Faibussowitsch PetscCall(PetscSectionGetComponentName(section, f, c, &compName)); 1089566063dSJacob Faibussowitsch PetscCall(PetscSectionSetComponentName(newSection, f, c, compName)); 109b778fa18SValeria Barra } 1109566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldSym(section, f, &sym)); 1119566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldSym(newSection, f, sym)); 112ea844a1aSMatthew Knepley } 1139566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(section, &pStart, &pEnd)); 1149566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(newSection, pStart, pEnd)); 1159566063dSJacob Faibussowitsch PetscCall(PetscSectionGetPermutation(section, &perm)); 1169566063dSJacob Faibussowitsch PetscCall(PetscSectionSetPermutation(newSection, perm)); 1179566063dSJacob Faibussowitsch PetscCall(PetscSectionGetSym(section, &sym)); 1189566063dSJacob Faibussowitsch PetscCall(PetscSectionSetSym(newSection, sym)); 119ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 120ea844a1aSMatthew Knepley PetscInt dof, cdof, fcdof = 0; 121ea844a1aSMatthew Knepley 1229566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(section, p, &dof)); 1239566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(newSection, p, dof)); 1249566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(section, p, &cdof)); 1259566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetConstraintDof(newSection, p, cdof)); 126ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 1279566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(section, p, f, &dof)); 1289566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldDof(newSection, p, f, dof)); 129ea844a1aSMatthew Knepley if (cdof) { 1309566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(section, p, f, &fcdof)); 1319566063dSJacob Faibussowitsch if (fcdof) PetscCall(PetscSectionSetFieldConstraintDof(newSection, p, f, fcdof)); 132ea844a1aSMatthew Knepley } 133ea844a1aSMatthew Knepley } 134ea844a1aSMatthew Knepley } 1359566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(newSection)); 136ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 137ea844a1aSMatthew Knepley PetscInt off, cdof, fcdof = 0; 138ea844a1aSMatthew Knepley const PetscInt *cInd; 139ea844a1aSMatthew Knepley 140ea844a1aSMatthew Knepley /* Must set offsets in case they do not agree with the prefix sums */ 1419566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(section, p, &off)); 1429566063dSJacob Faibussowitsch PetscCall(PetscSectionSetOffset(newSection, p, off)); 1439566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(section, p, &cdof)); 144ea844a1aSMatthew Knepley if (cdof) { 1459566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(section, p, &cInd)); 1469566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(newSection, p, cInd)); 147ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 1489566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(section, p, f, &fcdof)); 149ea844a1aSMatthew Knepley if (fcdof) { 1509566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(section, p, f, &cInd)); 1519566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldConstraintIndices(newSection, p, f, cInd)); 152ea844a1aSMatthew Knepley } 153ea844a1aSMatthew Knepley } 154ea844a1aSMatthew Knepley } 155ea844a1aSMatthew Knepley } 1563ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 157ea844a1aSMatthew Knepley } 158ea844a1aSMatthew Knepley 159ea844a1aSMatthew Knepley /*@ 160cab54364SBarry Smith PetscSectionClone - Creates a shallow (if possible) copy of the `PetscSection` 161ea844a1aSMatthew Knepley 162ea844a1aSMatthew Knepley Collective 163ea844a1aSMatthew Knepley 164ea844a1aSMatthew Knepley Input Parameter: 165cab54364SBarry Smith . section - the `PetscSection` 166ea844a1aSMatthew Knepley 167ea844a1aSMatthew Knepley Output Parameter: 168ea844a1aSMatthew Knepley . newSection - the copy 169ea844a1aSMatthew Knepley 170ea844a1aSMatthew Knepley Level: beginner 171ea844a1aSMatthew Knepley 17238b5cf2dSJacob Faibussowitsch Developer Notes: 173cab54364SBarry Smith With standard PETSc terminology this should be called `PetscSectionDuplicate()` 174cab54364SBarry Smith 175cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionDestroy()`, `PetscSectionCopy()` 176ea844a1aSMatthew Knepley @*/ 177d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionClone(PetscSection section, PetscSection *newSection) 178d71ae5a4SJacob Faibussowitsch { 179ea844a1aSMatthew Knepley PetscFunctionBegin; 180ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 1814f572ea9SToby Isaac PetscAssertPointer(newSection, 2); 1829566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)section), newSection)); 1839566063dSJacob Faibussowitsch PetscCall(PetscSectionCopy(section, *newSection)); 1843ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 185ea844a1aSMatthew Knepley } 186ea844a1aSMatthew Knepley 187ea844a1aSMatthew Knepley /*@ 188cab54364SBarry Smith PetscSectionSetFromOptions - sets parameters in a `PetscSection` from the options database 189ea844a1aSMatthew Knepley 19040750d41SVaclav Hapla Collective 191ea844a1aSMatthew Knepley 192ea844a1aSMatthew Knepley Input Parameter: 19338b5cf2dSJacob Faibussowitsch . s - the `PetscSection` 194ea844a1aSMatthew Knepley 19520662ed9SBarry Smith Options Database Key: 196cab54364SBarry Smith . -petscsection_point_major - `PETSC_TRUE` for point-major order 197ea844a1aSMatthew Knepley 198ea844a1aSMatthew Knepley Level: intermediate 199ea844a1aSMatthew Knepley 200cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionDestroy()` 201ea844a1aSMatthew Knepley @*/ 202d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFromOptions(PetscSection s) 203d71ae5a4SJacob Faibussowitsch { 204ea844a1aSMatthew Knepley PetscFunctionBegin; 205ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 206d0609cedSBarry Smith PetscObjectOptionsBegin((PetscObject)s); 2079566063dSJacob Faibussowitsch PetscCall(PetscOptionsBool("-petscsection_point_major", "The for ordering, either point major or field major", "PetscSectionSetPointMajor", s->pointMajor, &s->pointMajor, NULL)); 208ea844a1aSMatthew Knepley /* process any options handlers added with PetscObjectAddOptionsHandler() */ 209dbbe0bcdSBarry Smith PetscCall(PetscObjectProcessOptionsHandlers((PetscObject)s, PetscOptionsObject)); 210d0609cedSBarry Smith PetscOptionsEnd(); 2119566063dSJacob Faibussowitsch PetscCall(PetscObjectViewFromOptions((PetscObject)s, NULL, "-petscsection_view")); 2123ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 213ea844a1aSMatthew Knepley } 214ea844a1aSMatthew Knepley 215ea844a1aSMatthew Knepley /*@ 216ea844a1aSMatthew Knepley PetscSectionCompare - Compares two sections 217ea844a1aSMatthew Knepley 21840750d41SVaclav Hapla Collective 219ea844a1aSMatthew Knepley 2207a7aea1fSJed Brown Input Parameters: 221cab54364SBarry Smith + s1 - the first `PetscSection` 222cab54364SBarry Smith - s2 - the second `PetscSection` 223ea844a1aSMatthew Knepley 224ea844a1aSMatthew Knepley Output Parameter: 225cab54364SBarry Smith . congruent - `PETSC_TRUE` if the two sections are congruent, `PETSC_FALSE` otherwise 226ea844a1aSMatthew Knepley 227ea844a1aSMatthew Knepley Level: intermediate 228ea844a1aSMatthew Knepley 229cab54364SBarry Smith Note: 230ea844a1aSMatthew Knepley Field names are disregarded. 231ea844a1aSMatthew Knepley 232cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionCopy()`, `PetscSectionClone()` 233ea844a1aSMatthew Knepley @*/ 234d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCompare(PetscSection s1, PetscSection s2, PetscBool *congruent) 235d71ae5a4SJacob Faibussowitsch { 236ea844a1aSMatthew Knepley PetscInt pStart, pEnd, nfields, ncdof, nfcdof, p, f, n1, n2; 237ea844a1aSMatthew Knepley const PetscInt *idx1, *idx2; 238ea844a1aSMatthew Knepley IS perm1, perm2; 239ea844a1aSMatthew Knepley PetscBool flg; 240ea844a1aSMatthew Knepley PetscMPIInt mflg; 241ea844a1aSMatthew Knepley 242ea844a1aSMatthew Knepley PetscFunctionBegin; 243ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s1, PETSC_SECTION_CLASSID, 1); 244ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s2, PETSC_SECTION_CLASSID, 2); 2454f572ea9SToby Isaac PetscAssertPointer(congruent, 3); 246ea844a1aSMatthew Knepley flg = PETSC_FALSE; 247ea844a1aSMatthew Knepley 2489566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_compare(PetscObjectComm((PetscObject)s1), PetscObjectComm((PetscObject)s2), &mflg)); 249ea844a1aSMatthew Knepley if (mflg != MPI_CONGRUENT && mflg != MPI_IDENT) { 250ea844a1aSMatthew Knepley *congruent = PETSC_FALSE; 2513ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 252ea844a1aSMatthew Knepley } 253ea844a1aSMatthew Knepley 2549566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s1, &pStart, &pEnd)); 2559566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s2, &n1, &n2)); 256ea844a1aSMatthew Knepley if (pStart != n1 || pEnd != n2) goto not_congruent; 257ea844a1aSMatthew Knepley 2589566063dSJacob Faibussowitsch PetscCall(PetscSectionGetPermutation(s1, &perm1)); 2599566063dSJacob Faibussowitsch PetscCall(PetscSectionGetPermutation(s2, &perm2)); 260ea844a1aSMatthew Knepley if (perm1 && perm2) { 2619566063dSJacob Faibussowitsch PetscCall(ISEqual(perm1, perm2, congruent)); 262ea844a1aSMatthew Knepley if (!(*congruent)) goto not_congruent; 263ea844a1aSMatthew Knepley } else if (perm1 != perm2) goto not_congruent; 264ea844a1aSMatthew Knepley 265ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2669566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s1, p, &n1)); 2679566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s2, p, &n2)); 268ea844a1aSMatthew Knepley if (n1 != n2) goto not_congruent; 269ea844a1aSMatthew Knepley 2709566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s1, p, &n1)); 2719566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s2, p, &n2)); 272ea844a1aSMatthew Knepley if (n1 != n2) goto not_congruent; 273ea844a1aSMatthew Knepley 2749566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s1, p, &ncdof)); 2759566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s2, p, &n2)); 276ea844a1aSMatthew Knepley if (ncdof != n2) goto not_congruent; 277ea844a1aSMatthew Knepley 2789566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s1, p, &idx1)); 2799566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s2, p, &idx2)); 2809566063dSJacob Faibussowitsch PetscCall(PetscArraycmp(idx1, idx2, ncdof, congruent)); 281ea844a1aSMatthew Knepley if (!(*congruent)) goto not_congruent; 282ea844a1aSMatthew Knepley } 283ea844a1aSMatthew Knepley 2849566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s1, &nfields)); 2859566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s2, &n2)); 286ea844a1aSMatthew Knepley if (nfields != n2) goto not_congruent; 287ea844a1aSMatthew Knepley 288ea844a1aSMatthew Knepley for (f = 0; f < nfields; ++f) { 2899566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s1, f, &n1)); 2909566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s2, f, &n2)); 291ea844a1aSMatthew Knepley if (n1 != n2) goto not_congruent; 292ea844a1aSMatthew Knepley 293ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2949566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldOffset(s1, p, f, &n1)); 2959566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldOffset(s2, p, f, &n2)); 296ea844a1aSMatthew Knepley if (n1 != n2) goto not_congruent; 297ea844a1aSMatthew Knepley 2989566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s1, p, f, &n1)); 2999566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s2, p, f, &n2)); 300ea844a1aSMatthew Knepley if (n1 != n2) goto not_congruent; 301ea844a1aSMatthew Knepley 3029566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s1, p, f, &nfcdof)); 3039566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s2, p, f, &n2)); 304ea844a1aSMatthew Knepley if (nfcdof != n2) goto not_congruent; 305ea844a1aSMatthew Knepley 3069566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(s1, p, f, &idx1)); 3079566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(s2, p, f, &idx2)); 3089566063dSJacob Faibussowitsch PetscCall(PetscArraycmp(idx1, idx2, nfcdof, congruent)); 309ea844a1aSMatthew Knepley if (!(*congruent)) goto not_congruent; 310ea844a1aSMatthew Knepley } 311ea844a1aSMatthew Knepley } 312ea844a1aSMatthew Knepley 313ea844a1aSMatthew Knepley flg = PETSC_TRUE; 314ea844a1aSMatthew Knepley not_congruent: 3151c2dc1cbSBarry Smith PetscCall(MPIU_Allreduce(&flg, congruent, 1, MPIU_BOOL, MPI_LAND, PetscObjectComm((PetscObject)s1))); 3163ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 317ea844a1aSMatthew Knepley } 318ea844a1aSMatthew Knepley 319ea844a1aSMatthew Knepley /*@ 320cab54364SBarry Smith PetscSectionGetNumFields - Returns the number of fields in a `PetscSection`, or 0 if no fields were defined. 321ea844a1aSMatthew Knepley 32240750d41SVaclav Hapla Not Collective 323ea844a1aSMatthew Knepley 324ea844a1aSMatthew Knepley Input Parameter: 325cab54364SBarry Smith . s - the `PetscSection` 326ea844a1aSMatthew Knepley 327ea844a1aSMatthew Knepley Output Parameter: 328ea844a1aSMatthew Knepley . numFields - the number of fields defined, or 0 if none were defined 329ea844a1aSMatthew Knepley 330ea844a1aSMatthew Knepley Level: intermediate 331ea844a1aSMatthew Knepley 332cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetNumFields()` 333ea844a1aSMatthew Knepley @*/ 334d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetNumFields(PetscSection s, PetscInt *numFields) 335d71ae5a4SJacob Faibussowitsch { 336ea844a1aSMatthew Knepley PetscFunctionBegin; 337ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 3384f572ea9SToby Isaac PetscAssertPointer(numFields, 2); 339ea844a1aSMatthew Knepley *numFields = s->numFields; 3403ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 341ea844a1aSMatthew Knepley } 342ea844a1aSMatthew Knepley 343ea844a1aSMatthew Knepley /*@ 344cab54364SBarry Smith PetscSectionSetNumFields - Sets the number of fields in a `PetscSection` 345ea844a1aSMatthew Knepley 34640750d41SVaclav Hapla Not Collective 347ea844a1aSMatthew Knepley 348ea844a1aSMatthew Knepley Input Parameters: 34920662ed9SBarry Smith + s - the `PetscSection` 350ea844a1aSMatthew Knepley - numFields - the number of fields 351ea844a1aSMatthew Knepley 352ea844a1aSMatthew Knepley Level: intermediate 353ea844a1aSMatthew Knepley 354583308b6SBarry Smith Notes: 355583308b6SBarry Smith Calling this destroys all the information in the `PetscSection` including the chart. 356583308b6SBarry Smith 357583308b6SBarry Smith You must call `PetscSectionSetChart()` after calling this. 358583308b6SBarry Smith 359583308b6SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetNumFields()`, `PetscSectionSetChart()`, `PetscSectionReset()` 360ea844a1aSMatthew Knepley @*/ 361d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetNumFields(PetscSection s, PetscInt numFields) 362d71ae5a4SJacob Faibussowitsch { 363ea844a1aSMatthew Knepley PetscInt f; 364ea844a1aSMatthew Knepley 365ea844a1aSMatthew Knepley PetscFunctionBegin; 366ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 36708401ef6SPierre Jolivet PetscCheck(numFields > 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "The number of fields %" PetscInt_FMT " must be positive", numFields); 3689566063dSJacob Faibussowitsch PetscCall(PetscSectionReset(s)); 369ea844a1aSMatthew Knepley 370ea844a1aSMatthew Knepley s->numFields = numFields; 3719566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(s->numFields, &s->numFieldComponents)); 3729566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(s->numFields, &s->fieldNames)); 3739566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(s->numFields, &s->compNames)); 3749566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(s->numFields, &s->field)); 375ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) { 376ea844a1aSMatthew Knepley char name[64]; 377ea844a1aSMatthew Knepley 378ea844a1aSMatthew Knepley s->numFieldComponents[f] = 1; 379ea844a1aSMatthew Knepley 3809566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), &s->field[f])); 3819566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(name, 64, "Field_%" PetscInt_FMT, f)); 3829566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, (char **)&s->fieldNames[f])); 3839566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(name, 64, "Component_0")); 3849566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(s->numFieldComponents[f], &s->compNames[f])); 3859566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, (char **)&s->compNames[f][0])); 386ea844a1aSMatthew Knepley } 3873ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 388ea844a1aSMatthew Knepley } 389ea844a1aSMatthew Knepley 390ea844a1aSMatthew Knepley /*@C 391cab54364SBarry Smith PetscSectionGetFieldName - Returns the name of a field in the `PetscSection` 392ea844a1aSMatthew Knepley 393ea844a1aSMatthew Knepley Not Collective 394ea844a1aSMatthew Knepley 395ea844a1aSMatthew Knepley Input Parameters: 396cab54364SBarry Smith + s - the `PetscSection` 397ea844a1aSMatthew Knepley - field - the field number 398ea844a1aSMatthew Knepley 399ea844a1aSMatthew Knepley Output Parameter: 400ea844a1aSMatthew Knepley . fieldName - the field name 401ea844a1aSMatthew Knepley 402ea844a1aSMatthew Knepley Level: intermediate 403ea844a1aSMatthew Knepley 404cab54364SBarry Smith Note: 405cab54364SBarry Smith Will error if the field number is out of range 406cab54364SBarry Smith 407cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetFieldName()`, `PetscSectionSetNumFields()`, `PetscSectionGetNumFields()` 408ea844a1aSMatthew Knepley @*/ 409d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldName(PetscSection s, PetscInt field, const char *fieldName[]) 410d71ae5a4SJacob Faibussowitsch { 411ea844a1aSMatthew Knepley PetscFunctionBegin; 412ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 4134f572ea9SToby Isaac PetscAssertPointer(fieldName, 3); 4142abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 415ea844a1aSMatthew Knepley *fieldName = s->fieldNames[field]; 4163ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 417ea844a1aSMatthew Knepley } 418ea844a1aSMatthew Knepley 419ea844a1aSMatthew Knepley /*@C 420cab54364SBarry Smith PetscSectionSetFieldName - Sets the name of a field in the `PetscSection` 421ea844a1aSMatthew Knepley 422ea844a1aSMatthew Knepley Not Collective 423ea844a1aSMatthew Knepley 424ea844a1aSMatthew Knepley Input Parameters: 425cab54364SBarry Smith + s - the `PetscSection` 426ea844a1aSMatthew Knepley . field - the field number 427ea844a1aSMatthew Knepley - fieldName - the field name 428ea844a1aSMatthew Knepley 429ea844a1aSMatthew Knepley Level: intermediate 430ea844a1aSMatthew Knepley 431cab54364SBarry Smith Note: 432cab54364SBarry Smith Will error if the field number is out of range 433cab54364SBarry Smith 434cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionGetFieldName()`, `PetscSectionSetNumFields()`, `PetscSectionGetNumFields()` 435ea844a1aSMatthew Knepley @*/ 436d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldName(PetscSection s, PetscInt field, const char fieldName[]) 437d71ae5a4SJacob Faibussowitsch { 438ea844a1aSMatthew Knepley PetscFunctionBegin; 439ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 4404f572ea9SToby Isaac if (fieldName) PetscAssertPointer(fieldName, 3); 4412abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 4429566063dSJacob Faibussowitsch PetscCall(PetscFree(s->fieldNames[field])); 4439566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(fieldName, (char **)&s->fieldNames[field])); 4443ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 445ea844a1aSMatthew Knepley } 446ea844a1aSMatthew Knepley 447b778fa18SValeria Barra /*@C 448cab54364SBarry Smith PetscSectionGetComponentName - Gets the name of a field component in the `PetscSection` 449b778fa18SValeria Barra 450b778fa18SValeria Barra Not Collective 451b778fa18SValeria Barra 452b778fa18SValeria Barra Input Parameters: 453cab54364SBarry Smith + s - the `PetscSection` 454b778fa18SValeria Barra . field - the field number 455cab54364SBarry Smith - comp - the component number 456cab54364SBarry Smith 457d5b43468SJose E. Roman Output Parameter: 458cab54364SBarry Smith . compName - the component name 459b778fa18SValeria Barra 460b778fa18SValeria Barra Level: intermediate 461b778fa18SValeria Barra 462cab54364SBarry Smith Note: 463cab54364SBarry Smith Will error if the field or component number do not exist 464cab54364SBarry Smith 46538b5cf2dSJacob Faibussowitsch Developer Notes: 466583308b6SBarry Smith The function name should have Field in it since they are field components. 467583308b6SBarry Smith 468cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetFieldName()`, `PetscSectionSetNumFields()`, `PetscSectionGetNumFields()`, 469cab54364SBarry Smith `PetscSectionSetComponentName()`, `PetscSectionSetFieldName()`, `PetscSectionGetFieldComponents()`, `PetscSectionSetFieldComponents()` 470b778fa18SValeria Barra @*/ 471d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetComponentName(PetscSection s, PetscInt field, PetscInt comp, const char *compName[]) 472d71ae5a4SJacob Faibussowitsch { 473b778fa18SValeria Barra PetscFunctionBegin; 474b778fa18SValeria Barra PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 4754f572ea9SToby Isaac PetscAssertPointer(compName, 4); 4762abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 4772abc8c78SJacob Faibussowitsch PetscSectionCheckValidFieldComponent(comp, s->numFieldComponents[field]); 478b778fa18SValeria Barra *compName = s->compNames[field][comp]; 4793ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 480b778fa18SValeria Barra } 481b778fa18SValeria Barra 482b778fa18SValeria Barra /*@C 483cab54364SBarry Smith PetscSectionSetComponentName - Sets the name of a field component in the `PetscSection` 484b778fa18SValeria Barra 485b778fa18SValeria Barra Not Collective 486b778fa18SValeria Barra 487b778fa18SValeria Barra Input Parameters: 48820662ed9SBarry Smith + s - the `PetscSection` 489b778fa18SValeria Barra . field - the field number 490b778fa18SValeria Barra . comp - the component number 491b778fa18SValeria Barra - compName - the component name 492b778fa18SValeria Barra 493583308b6SBarry Smith Level: advanced 494b778fa18SValeria Barra 495cab54364SBarry Smith Note: 496cab54364SBarry Smith Will error if the field or component number do not exist 497cab54364SBarry Smith 49838b5cf2dSJacob Faibussowitsch Developer Notes: 499583308b6SBarry Smith The function name should have Field in it since they are field components. 500583308b6SBarry Smith 501cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetComponentName()`, `PetscSectionSetNumFields()`, `PetscSectionGetNumFields()`, 50242747ad1SJacob Faibussowitsch `PetscSectionSetFieldName()`, `PetscSectionGetFieldComponents()`, `PetscSectionSetFieldComponents()` 503b778fa18SValeria Barra @*/ 504d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetComponentName(PetscSection s, PetscInt field, PetscInt comp, const char compName[]) 505d71ae5a4SJacob Faibussowitsch { 506b778fa18SValeria Barra PetscFunctionBegin; 507b778fa18SValeria Barra PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 5084f572ea9SToby Isaac if (compName) PetscAssertPointer(compName, 4); 5092abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 5102abc8c78SJacob Faibussowitsch PetscSectionCheckValidFieldComponent(comp, s->numFieldComponents[field]); 5119566063dSJacob Faibussowitsch PetscCall(PetscFree(s->compNames[field][comp])); 5129566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(compName, (char **)&s->compNames[field][comp])); 5133ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 514b778fa18SValeria Barra } 515b778fa18SValeria Barra 516ea844a1aSMatthew Knepley /*@ 517ea844a1aSMatthew Knepley PetscSectionGetFieldComponents - Returns the number of field components for the given field. 518ea844a1aSMatthew Knepley 51940750d41SVaclav Hapla Not Collective 520ea844a1aSMatthew Knepley 521ea844a1aSMatthew Knepley Input Parameters: 522cab54364SBarry Smith + s - the `PetscSection` 523ea844a1aSMatthew Knepley - field - the field number 524ea844a1aSMatthew Knepley 525ea844a1aSMatthew Knepley Output Parameter: 526ea844a1aSMatthew Knepley . numComp - the number of field components 527ea844a1aSMatthew Knepley 528583308b6SBarry Smith Level: advanced 529ea844a1aSMatthew Knepley 53038b5cf2dSJacob Faibussowitsch Developer Notes: 531cab54364SBarry Smith This function is misnamed. There is a Num in `PetscSectionGetNumFields()` but not in this name 532cab54364SBarry Smith 533583308b6SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetFieldComponents()`, `PetscSectionGetNumFields()`, 534583308b6SBarry Smith `PetscSectionSetComponentName()`, `PetscSectionGetComponentName()` 535ea844a1aSMatthew Knepley @*/ 536d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldComponents(PetscSection s, PetscInt field, PetscInt *numComp) 537d71ae5a4SJacob Faibussowitsch { 538ea844a1aSMatthew Knepley PetscFunctionBegin; 539ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 5404f572ea9SToby Isaac PetscAssertPointer(numComp, 3); 5412abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 542ea844a1aSMatthew Knepley *numComp = s->numFieldComponents[field]; 5433ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 544ea844a1aSMatthew Knepley } 545ea844a1aSMatthew Knepley 546ea844a1aSMatthew Knepley /*@ 547ea844a1aSMatthew Knepley PetscSectionSetFieldComponents - Sets the number of field components for the given field. 548ea844a1aSMatthew Knepley 54940750d41SVaclav Hapla Not Collective 550ea844a1aSMatthew Knepley 551ea844a1aSMatthew Knepley Input Parameters: 55220662ed9SBarry Smith + s - the `PetscSection` 553ea844a1aSMatthew Knepley . field - the field number 554ea844a1aSMatthew Knepley - numComp - the number of field components 555ea844a1aSMatthew Knepley 556583308b6SBarry Smith Level: advanced 557ea844a1aSMatthew Knepley 558583308b6SBarry Smith Note: 559583308b6SBarry Smith This number can be different than the values set with `PetscSectionSetFieldDof()`. It can be used to indicate the number of 560583308b6SBarry Smith components in the field of the underlying physical model which may be different than the number of degrees of freedom needed 561583308b6SBarry Smith at a point in a discretization. For example, if in three dimensions the field is velocity, it will have 3 components, u, v, and w but 562583308b6SBarry Smith an face based model for velocity (where the velocity normal to the face is stored) there is only 1 dof for each face point. 563583308b6SBarry Smith 564583308b6SBarry Smith The value set with this function are not needed or used in `PetscSectionSetUp()`. 565583308b6SBarry Smith 56638b5cf2dSJacob Faibussowitsch Developer Notes: 567583308b6SBarry Smith This function is misnamed. There is a Num in `PetscSectionSetNumFields()` but not in this name 568583308b6SBarry Smith 569583308b6SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetFieldComponents()`, `PetscSectionSetComponentName()`, 570583308b6SBarry Smith `PetscSectionGetComponentName()`, `PetscSectionGetNumFields()` 571ea844a1aSMatthew Knepley @*/ 572d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldComponents(PetscSection s, PetscInt field, PetscInt numComp) 573d71ae5a4SJacob Faibussowitsch { 574b778fa18SValeria Barra PetscInt c; 575b778fa18SValeria Barra 576ea844a1aSMatthew Knepley PetscFunctionBegin; 577ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 5782abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 579b778fa18SValeria Barra if (s->compNames) { 58048a46eb9SPierre Jolivet for (c = 0; c < s->numFieldComponents[field]; ++c) PetscCall(PetscFree(s->compNames[field][c])); 5819566063dSJacob Faibussowitsch PetscCall(PetscFree(s->compNames[field])); 582b778fa18SValeria Barra } 583b778fa18SValeria Barra 584ea844a1aSMatthew Knepley s->numFieldComponents[field] = numComp; 585b778fa18SValeria Barra if (numComp) { 5869566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(numComp, (char ***)&s->compNames[field])); 587b778fa18SValeria Barra for (c = 0; c < numComp; ++c) { 5882abc8c78SJacob Faibussowitsch char name[64]; 5892abc8c78SJacob Faibussowitsch 5909566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(name, 64, "%" PetscInt_FMT, c)); 5919566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, (char **)&s->compNames[field][c])); 592b778fa18SValeria Barra } 593b778fa18SValeria Barra } 5943ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 595ea844a1aSMatthew Knepley } 596ea844a1aSMatthew Knepley 597ea844a1aSMatthew Knepley /*@ 598583308b6SBarry Smith PetscSectionGetChart - Returns the range [`pStart`, `pEnd`) in which points (indices) lie for this `PetscSection` on this MPI process 599ea844a1aSMatthew Knepley 60040750d41SVaclav Hapla Not Collective 601ea844a1aSMatthew Knepley 602ea844a1aSMatthew Knepley Input Parameter: 603cab54364SBarry Smith . s - the `PetscSection` 604ea844a1aSMatthew Knepley 605ea844a1aSMatthew Knepley Output Parameters: 606ea844a1aSMatthew Knepley + pStart - the first point 607ea844a1aSMatthew Knepley - pEnd - one past the last point 608ea844a1aSMatthew Knepley 609ea844a1aSMatthew Knepley Level: intermediate 610ea844a1aSMatthew Knepley 611cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetChart()`, `PetscSectionCreate()` 612ea844a1aSMatthew Knepley @*/ 613d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetChart(PetscSection s, PetscInt *pStart, PetscInt *pEnd) 614d71ae5a4SJacob Faibussowitsch { 615ea844a1aSMatthew Knepley PetscFunctionBegin; 616ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 617ea844a1aSMatthew Knepley if (pStart) *pStart = s->pStart; 618ea844a1aSMatthew Knepley if (pEnd) *pEnd = s->pEnd; 6193ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 620ea844a1aSMatthew Knepley } 621ea844a1aSMatthew Knepley 622ea844a1aSMatthew Knepley /*@ 623583308b6SBarry Smith PetscSectionSetChart - Sets the range [`pStart`, `pEnd`) in which points (indices) lie for this `PetscSection` on this MPI process 624ea844a1aSMatthew Knepley 62540750d41SVaclav Hapla Not Collective 626ea844a1aSMatthew Knepley 627ea844a1aSMatthew Knepley Input Parameters: 62820662ed9SBarry Smith + s - the `PetscSection` 629ea844a1aSMatthew Knepley . pStart - the first point 630ea844a1aSMatthew Knepley - pEnd - one past the last point 631ea844a1aSMatthew Knepley 632ea844a1aSMatthew Knepley Level: intermediate 633ea844a1aSMatthew Knepley 634583308b6SBarry Smith Notes: 635583308b6SBarry Smith The charts on different MPI processes may (and often do) overlap 636583308b6SBarry Smith 637583308b6SBarry Smith If you intend to use `PetscSectionSetNumFields()` it must be called before this call. 638583308b6SBarry Smith 639583308b6SBarry Smith The chart for all fields created with `PetscSectionSetNumFields()` is the same as this chart. 640583308b6SBarry Smith 641583308b6SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetChart()`, `PetscSectionCreate()`, `PetscSectionSetNumFields()` 642ea844a1aSMatthew Knepley @*/ 643d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetChart(PetscSection s, PetscInt pStart, PetscInt pEnd) 644d71ae5a4SJacob Faibussowitsch { 645ea844a1aSMatthew Knepley PetscInt f; 646ea844a1aSMatthew Knepley 647ea844a1aSMatthew Knepley PetscFunctionBegin; 648ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 6493ba16761SJacob Faibussowitsch if (pStart == s->pStart && pEnd == s->pEnd) PetscFunctionReturn(PETSC_SUCCESS); 650ea844a1aSMatthew Knepley /* Cannot Reset() because it destroys field information */ 651ea844a1aSMatthew Knepley s->setup = PETSC_FALSE; 6529566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->bc)); 6539566063dSJacob Faibussowitsch PetscCall(PetscFree(s->bcIndices)); 6549566063dSJacob Faibussowitsch PetscCall(PetscFree2(s->atlasDof, s->atlasOff)); 655ea844a1aSMatthew Knepley 656ea844a1aSMatthew Knepley s->pStart = pStart; 657ea844a1aSMatthew Knepley s->pEnd = pEnd; 6589566063dSJacob Faibussowitsch PetscCall(PetscMalloc2((pEnd - pStart), &s->atlasDof, (pEnd - pStart), &s->atlasOff)); 6599566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(s->atlasDof, pEnd - pStart)); 66048a46eb9SPierre Jolivet for (f = 0; f < s->numFields; ++f) PetscCall(PetscSectionSetChart(s->field[f], pStart, pEnd)); 6613ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 662ea844a1aSMatthew Knepley } 663ea844a1aSMatthew Knepley 664ea844a1aSMatthew Knepley /*@ 66520662ed9SBarry Smith PetscSectionGetPermutation - Returns the permutation of [0, `pEnd` - `pStart`) or `NULL` that was set with `PetscSectionSetPermutation()` 666ea844a1aSMatthew Knepley 66740750d41SVaclav Hapla Not Collective 668ea844a1aSMatthew Knepley 669ea844a1aSMatthew Knepley Input Parameter: 670cab54364SBarry Smith . s - the `PetscSection` 671ea844a1aSMatthew Knepley 6722fe279fdSBarry Smith Output Parameter: 673cab54364SBarry Smith . perm - The permutation as an `IS` 674ea844a1aSMatthew Knepley 675ea844a1aSMatthew Knepley Level: intermediate 676ea844a1aSMatthew Knepley 677cab54364SBarry Smith .seealso: [](sec_scatter), `IS`, `PetscSection`, `PetscSectionSetPermutation()`, `PetscSectionCreate()` 678ea844a1aSMatthew Knepley @*/ 679d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetPermutation(PetscSection s, IS *perm) 680d71ae5a4SJacob Faibussowitsch { 681ea844a1aSMatthew Knepley PetscFunctionBegin; 682ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 6839371c9d4SSatish Balay if (perm) { 6844f572ea9SToby Isaac PetscAssertPointer(perm, 2); 6859371c9d4SSatish Balay *perm = s->perm; 6869371c9d4SSatish Balay } 6873ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 688ea844a1aSMatthew Knepley } 689ea844a1aSMatthew Knepley 690ea844a1aSMatthew Knepley /*@ 691583308b6SBarry Smith PetscSectionSetPermutation - Sets a permutation of the chart for this section, [0, `pEnd` - `pStart`), which determines the order to store the `PetscSection` information 692ea844a1aSMatthew Knepley 69340750d41SVaclav Hapla Not Collective 694ea844a1aSMatthew Knepley 695ea844a1aSMatthew Knepley Input Parameters: 69620662ed9SBarry Smith + s - the `PetscSection` 697ea844a1aSMatthew Knepley - perm - the permutation of points 698ea844a1aSMatthew Knepley 699ea844a1aSMatthew Knepley Level: intermediate 700ea844a1aSMatthew Knepley 701583308b6SBarry Smith Notes: 702583308b6SBarry Smith The permutation must be provided before `PetscSectionSetUp()`. 703cab54364SBarry Smith 704583308b6SBarry Smith The data in the `PetscSection` are permuted but the access via `PetscSectionGetFieldOffset()` and `PetscSectionGetOffset()` is not changed 705583308b6SBarry Smith 706583308b6SBarry Smith Compart to `PetscSectionPermute()` 707583308b6SBarry Smith 708583308b6SBarry Smith .seealso: [](sec_scatter), `IS`, `PetscSection`, `PetscSectionSetUp()`, `PetscSectionGetPermutation()`, `PetscSectionPermute()`, `PetscSectionCreate()` 709ea844a1aSMatthew Knepley @*/ 710d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetPermutation(PetscSection s, IS perm) 711d71ae5a4SJacob Faibussowitsch { 712ea844a1aSMatthew Knepley PetscFunctionBegin; 713ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 714ea844a1aSMatthew Knepley if (perm) PetscValidHeaderSpecific(perm, IS_CLASSID, 2); 71528b400f6SJacob Faibussowitsch PetscCheck(!s->setup, PetscObjectComm((PetscObject)s), PETSC_ERR_ARG_WRONGSTATE, "Cannot set a permutation after the section is setup"); 716ea844a1aSMatthew Knepley if (s->perm != perm) { 7179566063dSJacob Faibussowitsch PetscCall(ISDestroy(&s->perm)); 718ea844a1aSMatthew Knepley if (perm) { 719ea844a1aSMatthew Knepley s->perm = perm; 7209566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)s->perm)); 721ea844a1aSMatthew Knepley } 722ea844a1aSMatthew Knepley } 7233ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 724ea844a1aSMatthew Knepley } 725ea844a1aSMatthew Knepley 726ea844a1aSMatthew Knepley /*@ 727cab54364SBarry Smith PetscSectionGetPointMajor - Returns the flag for dof ordering, `PETSC_TRUE` if it is point major, `PETSC_FALSE` if it is field major 728ea844a1aSMatthew Knepley 72940750d41SVaclav Hapla Not Collective 730ea844a1aSMatthew Knepley 731ea844a1aSMatthew Knepley Input Parameter: 732cab54364SBarry Smith . s - the `PetscSection` 733ea844a1aSMatthew Knepley 734ea844a1aSMatthew Knepley Output Parameter: 735ea844a1aSMatthew Knepley . pm - the flag for point major ordering 736ea844a1aSMatthew Knepley 737ea844a1aSMatthew Knepley Level: intermediate 738ea844a1aSMatthew Knepley 73938b5cf2dSJacob Faibussowitsch .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetPointMajor()` 740ea844a1aSMatthew Knepley @*/ 741d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetPointMajor(PetscSection s, PetscBool *pm) 742d71ae5a4SJacob Faibussowitsch { 743ea844a1aSMatthew Knepley PetscFunctionBegin; 744ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 7454f572ea9SToby Isaac PetscAssertPointer(pm, 2); 746ea844a1aSMatthew Knepley *pm = s->pointMajor; 7473ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 748ea844a1aSMatthew Knepley } 749ea844a1aSMatthew Knepley 750ea844a1aSMatthew Knepley /*@ 751cab54364SBarry Smith PetscSectionSetPointMajor - Sets the flag for dof ordering, `PETSC_TRUE` for point major, otherwise it will be field major 752ea844a1aSMatthew Knepley 75340750d41SVaclav Hapla Not Collective 754ea844a1aSMatthew Knepley 755ea844a1aSMatthew Knepley Input Parameters: 756cab54364SBarry Smith + s - the `PetscSection` 757ea844a1aSMatthew Knepley - pm - the flag for point major ordering 758ea844a1aSMatthew Knepley 759ea844a1aSMatthew Knepley Level: intermediate 760ea844a1aSMatthew Knepley 761583308b6SBarry Smith Note: 762583308b6SBarry Smith Field-major order is not recommended unless you are managing the entire problem yourself, since many higher-level functions in PETSc depend on point-major order. 763583308b6SBarry Smith 764583308b6SBarry Smith Point major order means the degrees of freedom are stored as follows 765583308b6SBarry Smith .vb 766583308b6SBarry Smith all the degrees of freedom for each point are stored contiquously, one point after another (respecting a permutation set with `PetscSectionSetPermutation()`) 767583308b6SBarry Smith for each point 768583308b6SBarry Smith the degrees of freedom for each field (starting with the unnamed default field) are listed in order by field 769583308b6SBarry Smith .ve 770583308b6SBarry Smith 771583308b6SBarry Smith Field major order means the degrees of freedom are stored as follows 772583308b6SBarry Smith .vb 773583308b6SBarry Smith all degrees of freedom for each field (including the unnamed default field) are stored contiquously, one field after another 774583308b6SBarry Smith for each field (started with unnamed default field) 775583308b6SBarry Smith the degrees of freedom for each point are listed in order by point (respecting a permutation set with `PetscSectionSetPermutation()`) 776583308b6SBarry Smith .ve 777583308b6SBarry Smith 778583308b6SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetPointMajor()`, `PetscSectionSetPermutation()` 779ea844a1aSMatthew Knepley @*/ 780d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetPointMajor(PetscSection s, PetscBool pm) 781d71ae5a4SJacob Faibussowitsch { 782ea844a1aSMatthew Knepley PetscFunctionBegin; 783ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 78428b400f6SJacob Faibussowitsch PetscCheck(!s->setup, PetscObjectComm((PetscObject)s), PETSC_ERR_ARG_WRONGSTATE, "Cannot set the dof ordering after the section is setup"); 785ea844a1aSMatthew Knepley s->pointMajor = pm; 7863ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 787ea844a1aSMatthew Knepley } 788ea844a1aSMatthew Knepley 789ea844a1aSMatthew Knepley /*@ 790cab54364SBarry Smith PetscSectionGetIncludesConstraints - Returns the flag indicating if constrained dofs were included when computing offsets in the `PetscSection`. 791cab54364SBarry Smith The value is set with `PetscSectionSetIncludesConstraints()` 79287e637c6Sksagiyam 79340750d41SVaclav Hapla Not Collective 79487e637c6Sksagiyam 79587e637c6Sksagiyam Input Parameter: 796cab54364SBarry Smith . s - the `PetscSection` 79787e637c6Sksagiyam 79887e637c6Sksagiyam Output Parameter: 79987e637c6Sksagiyam . includesConstraints - the flag indicating if constrained dofs were included when computing offsets 80087e637c6Sksagiyam 80187e637c6Sksagiyam Level: intermediate 80287e637c6Sksagiyam 803cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetIncludesConstraints()` 80487e637c6Sksagiyam @*/ 805d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetIncludesConstraints(PetscSection s, PetscBool *includesConstraints) 806d71ae5a4SJacob Faibussowitsch { 80787e637c6Sksagiyam PetscFunctionBegin; 80887e637c6Sksagiyam PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 8094f572ea9SToby Isaac PetscAssertPointer(includesConstraints, 2); 81087e637c6Sksagiyam *includesConstraints = s->includesConstraints; 8113ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 81287e637c6Sksagiyam } 81387e637c6Sksagiyam 81487e637c6Sksagiyam /*@ 81587e637c6Sksagiyam PetscSectionSetIncludesConstraints - Sets the flag indicating if constrained dofs are to be included when computing offsets 81687e637c6Sksagiyam 81740750d41SVaclav Hapla Not Collective 81887e637c6Sksagiyam 81987e637c6Sksagiyam Input Parameters: 82020662ed9SBarry Smith + s - the `PetscSection` 82187e637c6Sksagiyam - includesConstraints - the flag indicating if constrained dofs are to be included when computing offsets 82287e637c6Sksagiyam 82387e637c6Sksagiyam Level: intermediate 82487e637c6Sksagiyam 825cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetIncludesConstraints()` 82687e637c6Sksagiyam @*/ 827d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetIncludesConstraints(PetscSection s, PetscBool includesConstraints) 828d71ae5a4SJacob Faibussowitsch { 82987e637c6Sksagiyam PetscFunctionBegin; 83087e637c6Sksagiyam PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 83128b400f6SJacob Faibussowitsch PetscCheck(!s->setup, PetscObjectComm((PetscObject)s), PETSC_ERR_ARG_WRONGSTATE, "Cannot set includesConstraints after the section is set up"); 83287e637c6Sksagiyam s->includesConstraints = includesConstraints; 8333ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 83487e637c6Sksagiyam } 83587e637c6Sksagiyam 83687e637c6Sksagiyam /*@ 837583308b6SBarry Smith PetscSectionGetDof - Return the total number of degrees of freedom associated with a given point. 838ea844a1aSMatthew Knepley 83940750d41SVaclav Hapla Not Collective 840ea844a1aSMatthew Knepley 841ea844a1aSMatthew Knepley Input Parameters: 842cab54364SBarry Smith + s - the `PetscSection` 843ea844a1aSMatthew Knepley - point - the point 844ea844a1aSMatthew Knepley 845ea844a1aSMatthew Knepley Output Parameter: 846ea844a1aSMatthew Knepley . numDof - the number of dof 847ea844a1aSMatthew Knepley 848583308b6SBarry Smith Level: intermediate 849583308b6SBarry Smith 850583308b6SBarry Smith Notes: 851db527f05SMatthew G. Knepley In a global section, this size will be negative for points not owned by this process. 852db527f05SMatthew G. Knepley 853583308b6SBarry Smith This number is for the unnamed default field at the given point plus all degrees of freedom associated with all fields at that point 854ea844a1aSMatthew Knepley 855cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetDof()`, `PetscSectionCreate()` 856ea844a1aSMatthew Knepley @*/ 857d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetDof(PetscSection s, PetscInt point, PetscInt *numDof) 858d71ae5a4SJacob Faibussowitsch { 85976bd3646SJed Brown PetscFunctionBeginHot; 860ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 8614f572ea9SToby Isaac PetscAssertPointer(numDof, 3); 862db485b19SStefano Zampini if (PetscDefined(USE_DEBUG)) PetscCheck(point >= s->pStart && point < s->pEnd, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section point %" PetscInt_FMT " should be in [%" PetscInt_FMT ", %" PetscInt_FMT ")", point, s->pStart, s->pEnd); 863ea844a1aSMatthew Knepley *numDof = s->atlasDof[point - s->pStart]; 8643ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 865ea844a1aSMatthew Knepley } 866ea844a1aSMatthew Knepley 867ea844a1aSMatthew Knepley /*@ 868583308b6SBarry Smith PetscSectionSetDof - Sets the total number of degrees of freedom associated with a given point. 869ea844a1aSMatthew Knepley 87040750d41SVaclav Hapla Not Collective 871ea844a1aSMatthew Knepley 872ea844a1aSMatthew Knepley Input Parameters: 873cab54364SBarry Smith + s - the `PetscSection` 874ea844a1aSMatthew Knepley . point - the point 875ea844a1aSMatthew Knepley - numDof - the number of dof 876ea844a1aSMatthew Knepley 877ea844a1aSMatthew Knepley Level: intermediate 878ea844a1aSMatthew Knepley 879583308b6SBarry Smith Note: 880583308b6SBarry Smith This number is for the unnamed default field at the given point plus all degrees of freedom associated with all fields at that point 881583308b6SBarry Smith 882cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetDof()`, `PetscSectionAddDof()`, `PetscSectionCreate()` 883ea844a1aSMatthew Knepley @*/ 884d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetDof(PetscSection s, PetscInt point, PetscInt numDof) 885d71ae5a4SJacob Faibussowitsch { 886ea844a1aSMatthew Knepley PetscFunctionBegin; 887ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 888c8bf3acbSVaclav Hapla PetscAssert(point >= s->pStart && point < s->pEnd, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section point %" PetscInt_FMT " should be in [%" PetscInt_FMT ", %" PetscInt_FMT ")", point, s->pStart, s->pEnd); 889ea844a1aSMatthew Knepley s->atlasDof[point - s->pStart] = numDof; 89069c11d05SVaclav Hapla PetscCall(PetscSectionInvalidateMaxDof_Internal(s)); 8913ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 892ea844a1aSMatthew Knepley } 893ea844a1aSMatthew Knepley 894ea844a1aSMatthew Knepley /*@ 895583308b6SBarry Smith PetscSectionAddDof - Adds to the total number of degrees of freedom associated with a given point. 896ea844a1aSMatthew Knepley 89740750d41SVaclav Hapla Not Collective 898ea844a1aSMatthew Knepley 899ea844a1aSMatthew Knepley Input Parameters: 900cab54364SBarry Smith + s - the `PetscSection` 901ea844a1aSMatthew Knepley . point - the point 902ea844a1aSMatthew Knepley - numDof - the number of additional dof 903ea844a1aSMatthew Knepley 904ea844a1aSMatthew Knepley Level: intermediate 905ea844a1aSMatthew Knepley 906583308b6SBarry Smith Note: 907583308b6SBarry Smith This number is for the unnamed default field at the given point plus all degrees of freedom associated with all fields at that point 908583308b6SBarry Smith 909cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetDof()`, `PetscSectionSetDof()`, `PetscSectionCreate()` 910ea844a1aSMatthew Knepley @*/ 911d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionAddDof(PetscSection s, PetscInt point, PetscInt numDof) 912d71ae5a4SJacob Faibussowitsch { 91376bd3646SJed Brown PetscFunctionBeginHot; 914ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 915db485b19SStefano Zampini if (PetscDefined(USE_DEBUG)) PetscCheck(point >= s->pStart && point < s->pEnd, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section point %" PetscInt_FMT " should be in [%" PetscInt_FMT ", %" PetscInt_FMT ")", point, s->pStart, s->pEnd); 916ea844a1aSMatthew Knepley s->atlasDof[point - s->pStart] += numDof; 91769c11d05SVaclav Hapla PetscCall(PetscSectionInvalidateMaxDof_Internal(s)); 9183ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 919ea844a1aSMatthew Knepley } 920ea844a1aSMatthew Knepley 921ea844a1aSMatthew Knepley /*@ 922ea844a1aSMatthew Knepley PetscSectionGetFieldDof - Return the number of degrees of freedom associated with a field on a given point. 923ea844a1aSMatthew Knepley 92440750d41SVaclav Hapla Not Collective 925ea844a1aSMatthew Knepley 926ea844a1aSMatthew Knepley Input Parameters: 927cab54364SBarry Smith + s - the `PetscSection` 928ea844a1aSMatthew Knepley . point - the point 929ea844a1aSMatthew Knepley - field - the field 930ea844a1aSMatthew Knepley 931ea844a1aSMatthew Knepley Output Parameter: 932ea844a1aSMatthew Knepley . numDof - the number of dof 933ea844a1aSMatthew Knepley 934ea844a1aSMatthew Knepley Level: intermediate 935ea844a1aSMatthew Knepley 936cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetFieldDof()`, `PetscSectionCreate()` 937ea844a1aSMatthew Knepley @*/ 938d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldDof(PetscSection s, PetscInt point, PetscInt field, PetscInt *numDof) 939d71ae5a4SJacob Faibussowitsch { 940ea844a1aSMatthew Knepley PetscFunctionBegin; 941ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 9424f572ea9SToby Isaac PetscAssertPointer(numDof, 4); 9432abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 9449566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s->field[field], point, numDof)); 9453ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 946ea844a1aSMatthew Knepley } 947ea844a1aSMatthew Knepley 948ea844a1aSMatthew Knepley /*@ 949ea844a1aSMatthew Knepley PetscSectionSetFieldDof - Sets the number of degrees of freedom associated with a field on a given point. 950ea844a1aSMatthew Knepley 95140750d41SVaclav Hapla Not Collective 952ea844a1aSMatthew Knepley 953ea844a1aSMatthew Knepley Input Parameters: 954cab54364SBarry Smith + s - the `PetscSection` 955ea844a1aSMatthew Knepley . point - the point 956ea844a1aSMatthew Knepley . field - the field 957ea844a1aSMatthew Knepley - numDof - the number of dof 958ea844a1aSMatthew Knepley 959ea844a1aSMatthew Knepley Level: intermediate 960ea844a1aSMatthew Knepley 961583308b6SBarry Smith Note: 962583308b6SBarry Smith When setting the number of dof for a field at a point one must also ensure the count of the total number of dof at the point (summed over 963583308b6SBarry Smith the fields and the unnamed default field) is correct by also calling `PetscSectionAddDof()` or `PetscSectionSetDof()` 964583308b6SBarry Smith 965583308b6SBarry Smith This is equivalent to 966583308b6SBarry Smith .vb 967583308b6SBarry Smith PetscSection fs; 968583308b6SBarry Smith PetscSectionGetField(s,field,&fs) 969583308b6SBarry Smith PetscSectionSetDof(fs,numDof) 970583308b6SBarry Smith .ve 971583308b6SBarry Smith 972583308b6SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetFieldDof()`, `PetscSectionCreate()`, `PetscSectionAddDof()`, `PetscSectionSetDof()` 973ea844a1aSMatthew Knepley @*/ 974d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof) 975d71ae5a4SJacob Faibussowitsch { 976ea844a1aSMatthew Knepley PetscFunctionBegin; 977ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 9782abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 9799566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(s->field[field], point, numDof)); 9803ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 981ea844a1aSMatthew Knepley } 982ea844a1aSMatthew Knepley 983ea844a1aSMatthew Knepley /*@ 984ea844a1aSMatthew Knepley PetscSectionAddFieldDof - Adds a number of degrees of freedom associated with a field on a given point. 985ea844a1aSMatthew Knepley 98640750d41SVaclav Hapla Not Collective 987ea844a1aSMatthew Knepley 988ea844a1aSMatthew Knepley Input Parameters: 989cab54364SBarry Smith + s - the `PetscSection` 990ea844a1aSMatthew Knepley . point - the point 991ea844a1aSMatthew Knepley . field - the field 992ea844a1aSMatthew Knepley - numDof - the number of dof 993ea844a1aSMatthew Knepley 994ea844a1aSMatthew Knepley Level: intermediate 995ea844a1aSMatthew Knepley 996583308b6SBarry Smith Notes: 997583308b6SBarry Smith When adding to the number of dof for a field at a point one must also ensure the count of the total number of dof at the point (summed over 998583308b6SBarry Smith the fields and the unnamed default field) is correct by also calling `PetscSectionAddDof()` or `PetscSectionSetDof()` 999583308b6SBarry Smith 1000583308b6SBarry Smith This is equivalent to 1001583308b6SBarry Smith .vb 1002583308b6SBarry Smith PetscSection fs; 1003583308b6SBarry Smith PetscSectionGetField(s,field,&fs) 1004583308b6SBarry Smith PetscSectionAddDof(fs,numDof) 1005583308b6SBarry Smith .ve 1006583308b6SBarry Smith 1007cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetFieldDof()`, `PetscSectionGetFieldDof()`, `PetscSectionCreate()` 1008ea844a1aSMatthew Knepley @*/ 1009d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionAddFieldDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof) 1010d71ae5a4SJacob Faibussowitsch { 1011ea844a1aSMatthew Knepley PetscFunctionBegin; 1012ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 10132abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 10149566063dSJacob Faibussowitsch PetscCall(PetscSectionAddDof(s->field[field], point, numDof)); 10153ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1016ea844a1aSMatthew Knepley } 1017ea844a1aSMatthew Knepley 1018ea844a1aSMatthew Knepley /*@ 1019ea844a1aSMatthew Knepley PetscSectionGetConstraintDof - Return the number of constrained degrees of freedom associated with a given point. 1020ea844a1aSMatthew Knepley 102140750d41SVaclav Hapla Not Collective 1022ea844a1aSMatthew Knepley 1023ea844a1aSMatthew Knepley Input Parameters: 1024cab54364SBarry Smith + s - the `PetscSection` 1025ea844a1aSMatthew Knepley - point - the point 1026ea844a1aSMatthew Knepley 1027ea844a1aSMatthew Knepley Output Parameter: 1028ea844a1aSMatthew Knepley . numDof - the number of dof which are fixed by constraints 1029ea844a1aSMatthew Knepley 1030ea844a1aSMatthew Knepley Level: intermediate 1031ea844a1aSMatthew Knepley 1032cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetDof()`, `PetscSectionSetConstraintDof()`, `PetscSectionCreate()` 1033ea844a1aSMatthew Knepley @*/ 1034d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetConstraintDof(PetscSection s, PetscInt point, PetscInt *numDof) 1035d71ae5a4SJacob Faibussowitsch { 1036ea844a1aSMatthew Knepley PetscFunctionBegin; 1037ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 10384f572ea9SToby Isaac PetscAssertPointer(numDof, 3); 1039ea844a1aSMatthew Knepley if (s->bc) { 10409566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s->bc, point, numDof)); 1041ea844a1aSMatthew Knepley } else *numDof = 0; 10423ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1043ea844a1aSMatthew Knepley } 1044ea844a1aSMatthew Knepley 1045ea844a1aSMatthew Knepley /*@ 1046ea844a1aSMatthew Knepley PetscSectionSetConstraintDof - Set the number of constrained degrees of freedom associated with a given point. 1047ea844a1aSMatthew Knepley 104840750d41SVaclav Hapla Not Collective 1049ea844a1aSMatthew Knepley 1050ea844a1aSMatthew Knepley Input Parameters: 1051cab54364SBarry Smith + s - the `PetscSection` 1052ea844a1aSMatthew Knepley . point - the point 1053ea844a1aSMatthew Knepley - numDof - the number of dof which are fixed by constraints 1054ea844a1aSMatthew Knepley 1055ea844a1aSMatthew Knepley Level: intermediate 1056ea844a1aSMatthew Knepley 1057cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetDof()`, `PetscSectionGetConstraintDof()`, `PetscSectionCreate()` 1058ea844a1aSMatthew Knepley @*/ 1059d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetConstraintDof(PetscSection s, PetscInt point, PetscInt numDof) 1060d71ae5a4SJacob Faibussowitsch { 1061ea844a1aSMatthew Knepley PetscFunctionBegin; 1062ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1063ea844a1aSMatthew Knepley if (numDof) { 10647c0883d5SVaclav Hapla PetscCall(PetscSectionCheckConstraints_Private(s)); 10659566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(s->bc, point, numDof)); 1066ea844a1aSMatthew Knepley } 10673ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1068ea844a1aSMatthew Knepley } 1069ea844a1aSMatthew Knepley 1070ea844a1aSMatthew Knepley /*@ 1071ea844a1aSMatthew Knepley PetscSectionAddConstraintDof - Increment the number of constrained degrees of freedom associated with a given point. 1072ea844a1aSMatthew Knepley 107340750d41SVaclav Hapla Not Collective 1074ea844a1aSMatthew Knepley 1075ea844a1aSMatthew Knepley Input Parameters: 1076cab54364SBarry Smith + s - the `PetscSection` 1077ea844a1aSMatthew Knepley . point - the point 1078ea844a1aSMatthew Knepley - numDof - the number of additional dof which are fixed by constraints 1079ea844a1aSMatthew Knepley 1080ea844a1aSMatthew Knepley Level: intermediate 1081ea844a1aSMatthew Knepley 1082cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionAddDof()`, `PetscSectionGetConstraintDof()`, `PetscSectionCreate()` 1083ea844a1aSMatthew Knepley @*/ 1084d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionAddConstraintDof(PetscSection s, PetscInt point, PetscInt numDof) 1085d71ae5a4SJacob Faibussowitsch { 1086ea844a1aSMatthew Knepley PetscFunctionBegin; 1087ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1088ea844a1aSMatthew Knepley if (numDof) { 10897c0883d5SVaclav Hapla PetscCall(PetscSectionCheckConstraints_Private(s)); 10909566063dSJacob Faibussowitsch PetscCall(PetscSectionAddDof(s->bc, point, numDof)); 1091ea844a1aSMatthew Knepley } 10923ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1093ea844a1aSMatthew Knepley } 1094ea844a1aSMatthew Knepley 1095ea844a1aSMatthew Knepley /*@ 1096ea844a1aSMatthew Knepley PetscSectionGetFieldConstraintDof - Return the number of constrained degrees of freedom associated with a given field on a point. 1097ea844a1aSMatthew Knepley 109840750d41SVaclav Hapla Not Collective 1099ea844a1aSMatthew Knepley 1100ea844a1aSMatthew Knepley Input Parameters: 1101cab54364SBarry Smith + s - the `PetscSection` 1102ea844a1aSMatthew Knepley . point - the point 1103ea844a1aSMatthew Knepley - field - the field 1104ea844a1aSMatthew Knepley 1105ea844a1aSMatthew Knepley Output Parameter: 1106ea844a1aSMatthew Knepley . numDof - the number of dof which are fixed by constraints 1107ea844a1aSMatthew Knepley 1108ea844a1aSMatthew Knepley Level: intermediate 1109ea844a1aSMatthew Knepley 1110cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetDof()`, `PetscSectionSetFieldConstraintDof()`, `PetscSectionCreate()` 1111ea844a1aSMatthew Knepley @*/ 1112d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldConstraintDof(PetscSection s, PetscInt point, PetscInt field, PetscInt *numDof) 1113d71ae5a4SJacob Faibussowitsch { 1114ea844a1aSMatthew Knepley PetscFunctionBegin; 1115ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 11164f572ea9SToby Isaac PetscAssertPointer(numDof, 4); 11172abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 11189566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s->field[field], point, numDof)); 11193ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1120ea844a1aSMatthew Knepley } 1121ea844a1aSMatthew Knepley 1122ea844a1aSMatthew Knepley /*@ 1123ea844a1aSMatthew Knepley PetscSectionSetFieldConstraintDof - Set the number of constrained degrees of freedom associated with a given field on a point. 1124ea844a1aSMatthew Knepley 112540750d41SVaclav Hapla Not Collective 1126ea844a1aSMatthew Knepley 1127ea844a1aSMatthew Knepley Input Parameters: 1128cab54364SBarry Smith + s - the `PetscSection` 1129ea844a1aSMatthew Knepley . point - the point 1130ea844a1aSMatthew Knepley . field - the field 1131ea844a1aSMatthew Knepley - numDof - the number of dof which are fixed by constraints 1132ea844a1aSMatthew Knepley 1133ea844a1aSMatthew Knepley Level: intermediate 1134ea844a1aSMatthew Knepley 1135cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetDof()`, `PetscSectionGetFieldConstraintDof()`, `PetscSectionCreate()` 1136ea844a1aSMatthew Knepley @*/ 1137d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldConstraintDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof) 1138d71ae5a4SJacob Faibussowitsch { 1139ea844a1aSMatthew Knepley PetscFunctionBegin; 1140ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 11412abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 11429566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintDof(s->field[field], point, numDof)); 11433ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1144ea844a1aSMatthew Knepley } 1145ea844a1aSMatthew Knepley 1146ea844a1aSMatthew Knepley /*@ 1147ea844a1aSMatthew Knepley PetscSectionAddFieldConstraintDof - Increment the number of constrained degrees of freedom associated with a given field on a point. 1148ea844a1aSMatthew Knepley 114940750d41SVaclav Hapla Not Collective 1150ea844a1aSMatthew Knepley 1151ea844a1aSMatthew Knepley Input Parameters: 1152cab54364SBarry Smith + s - the `PetscSection` 1153ea844a1aSMatthew Knepley . point - the point 1154ea844a1aSMatthew Knepley . field - the field 1155ea844a1aSMatthew Knepley - numDof - the number of additional dof which are fixed by constraints 1156ea844a1aSMatthew Knepley 1157ea844a1aSMatthew Knepley Level: intermediate 1158ea844a1aSMatthew Knepley 1159cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionAddDof()`, `PetscSectionGetFieldConstraintDof()`, `PetscSectionCreate()` 1160ea844a1aSMatthew Knepley @*/ 1161d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionAddFieldConstraintDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof) 1162d71ae5a4SJacob Faibussowitsch { 1163ea844a1aSMatthew Knepley PetscFunctionBegin; 1164ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 11652abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 11669566063dSJacob Faibussowitsch PetscCall(PetscSectionAddConstraintDof(s->field[field], point, numDof)); 11673ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1168ea844a1aSMatthew Knepley } 1169ea844a1aSMatthew Knepley 1170ea844a1aSMatthew Knepley /*@ 1171ea844a1aSMatthew Knepley PetscSectionSetUpBC - Setup the subsections describing boundary conditions. 1172ea844a1aSMatthew Knepley 117340750d41SVaclav Hapla Not Collective 1174ea844a1aSMatthew Knepley 1175ea844a1aSMatthew Knepley Input Parameter: 1176cab54364SBarry Smith . s - the `PetscSection` 1177ea844a1aSMatthew Knepley 1178ea844a1aSMatthew Knepley Level: advanced 1179ea844a1aSMatthew Knepley 1180cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetUp()`, `PetscSectionCreate()` 1181ea844a1aSMatthew Knepley @*/ 1182d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetUpBC(PetscSection s) 1183d71ae5a4SJacob Faibussowitsch { 1184ea844a1aSMatthew Knepley PetscFunctionBegin; 1185ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1186ea844a1aSMatthew Knepley if (s->bc) { 1187ea844a1aSMatthew Knepley const PetscInt last = (s->bc->pEnd - s->bc->pStart) - 1; 1188ea844a1aSMatthew Knepley 11899566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(s->bc)); 11908da24d32SBarry Smith PetscCall(PetscMalloc1((last >= 0 ? s->bc->atlasOff[last] + s->bc->atlasDof[last] : 0), &s->bcIndices)); 1191ea844a1aSMatthew Knepley } 11923ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1193ea844a1aSMatthew Knepley } 1194ea844a1aSMatthew Knepley 1195ea844a1aSMatthew Knepley /*@ 1196583308b6SBarry Smith PetscSectionSetUp - Calculate offsets based upon the number of degrees of freedom for each point in preparation for use of the `PetscSection` 1197ea844a1aSMatthew Knepley 119840750d41SVaclav Hapla Not Collective 1199ea844a1aSMatthew Knepley 1200ea844a1aSMatthew Knepley Input Parameter: 1201cab54364SBarry Smith . s - the `PetscSection` 1202ea844a1aSMatthew Knepley 1203ea844a1aSMatthew Knepley Level: intermediate 1204ea844a1aSMatthew Knepley 1205583308b6SBarry Smith Notes: 1206583308b6SBarry Smith If used, `PetscSectionSetPermutation()` must be called before this routine. 1207583308b6SBarry Smith 1208583308b6SBarry Smith `PetscSectionSetPointMajor()`, cannot be called after this routine. 1209583308b6SBarry Smith 1210583308b6SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionSetPermutation()` 1211ea844a1aSMatthew Knepley @*/ 1212d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetUp(PetscSection s) 1213d71ae5a4SJacob Faibussowitsch { 1214ea844a1aSMatthew Knepley const PetscInt *pind = NULL; 1215ea844a1aSMatthew Knepley PetscInt offset = 0, foff, p, f; 1216ea844a1aSMatthew Knepley 1217ea844a1aSMatthew Knepley PetscFunctionBegin; 1218ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 12193ba16761SJacob Faibussowitsch if (s->setup) PetscFunctionReturn(PETSC_SUCCESS); 1220ea844a1aSMatthew Knepley s->setup = PETSC_TRUE; 1221ea844a1aSMatthew Knepley /* Set offsets and field offsets for all points */ 1222ea844a1aSMatthew Knepley /* Assume that all fields have the same chart */ 122328b400f6SJacob Faibussowitsch PetscCheck(s->includesConstraints, PETSC_COMM_SELF, PETSC_ERR_SUP, "PetscSectionSetUp is currently unsupported for includesConstraints = PETSC_TRUE"); 12249566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISGetIndices(s->perm, &pind)); 1225ea844a1aSMatthew Knepley if (s->pointMajor) { 1226ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) { 1227ea844a1aSMatthew Knepley const PetscInt q = pind ? pind[p] : p; 1228ea844a1aSMatthew Knepley 1229ea844a1aSMatthew Knepley /* Set point offset */ 1230ea844a1aSMatthew Knepley s->atlasOff[q] = offset; 1231ea844a1aSMatthew Knepley offset += s->atlasDof[q]; 1232ea844a1aSMatthew Knepley /* Set field offset */ 1233ea844a1aSMatthew Knepley for (f = 0, foff = s->atlasOff[q]; f < s->numFields; ++f) { 1234ea844a1aSMatthew Knepley PetscSection sf = s->field[f]; 1235ea844a1aSMatthew Knepley 1236ea844a1aSMatthew Knepley sf->atlasOff[q] = foff; 1237ea844a1aSMatthew Knepley foff += sf->atlasDof[q]; 1238ea844a1aSMatthew Knepley } 1239ea844a1aSMatthew Knepley } 1240ea844a1aSMatthew Knepley } else { 1241ea844a1aSMatthew Knepley /* Set field offsets for all points */ 1242ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) { 1243ea844a1aSMatthew Knepley PetscSection sf = s->field[f]; 1244ea844a1aSMatthew Knepley 1245ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) { 1246ea844a1aSMatthew Knepley const PetscInt q = pind ? pind[p] : p; 1247ea844a1aSMatthew Knepley 1248ea844a1aSMatthew Knepley sf->atlasOff[q] = offset; 1249ea844a1aSMatthew Knepley offset += sf->atlasDof[q]; 1250ea844a1aSMatthew Knepley } 1251ea844a1aSMatthew Knepley } 1252ea844a1aSMatthew Knepley /* Disable point offsets since these are unused */ 1253ad540459SPierre Jolivet for (p = 0; p < s->pEnd - s->pStart; ++p) s->atlasOff[p] = -1; 1254ea844a1aSMatthew Knepley } 12559566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISRestoreIndices(s->perm, &pind)); 1256ea844a1aSMatthew Knepley /* Setup BC sections */ 12579566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUpBC(s)); 12589566063dSJacob Faibussowitsch for (f = 0; f < s->numFields; ++f) PetscCall(PetscSectionSetUpBC(s->field[f])); 12593ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1260ea844a1aSMatthew Knepley } 1261ea844a1aSMatthew Knepley 1262ea844a1aSMatthew Knepley /*@ 126320662ed9SBarry Smith PetscSectionGetMaxDof - Return the maximum number of degrees of freedom on any point in the `PetscSection` 1264ea844a1aSMatthew Knepley 126540750d41SVaclav Hapla Not Collective 1266ea844a1aSMatthew Knepley 12672fe279fdSBarry Smith Input Parameter: 1268cab54364SBarry Smith . s - the `PetscSection` 1269ea844a1aSMatthew Knepley 1270ea844a1aSMatthew Knepley Output Parameter: 1271ea844a1aSMatthew Knepley . maxDof - the maximum dof 1272ea844a1aSMatthew Knepley 1273ea844a1aSMatthew Knepley Level: intermediate 1274ea844a1aSMatthew Knepley 1275583308b6SBarry Smith Notes: 1276cab54364SBarry Smith The returned number is up-to-date without need for `PetscSectionSetUp()`. 127769c11d05SVaclav Hapla 1278583308b6SBarry Smith This is the maximum over all points of the sum of the number of dof in the unnamed default field plus all named fields. This is equivalent to 1279583308b6SBarry Smith the maximum over all points of the value returned by `PetscSectionGetDof()` on this MPI process 1280583308b6SBarry Smith 1281583308b6SBarry Smith Developer Notes: 128269c11d05SVaclav Hapla The returned number is calculated lazily and stashed. 1283cab54364SBarry Smith 1284cab54364SBarry Smith A call to `PetscSectionInvalidateMaxDof_Internal()` invalidates the stashed value. 1285cab54364SBarry Smith 1286cab54364SBarry Smith `PetscSectionInvalidateMaxDof_Internal()` is called in `PetscSectionSetDof()`, `PetscSectionAddDof()` and `PetscSectionReset()` 1287cab54364SBarry Smith 128820662ed9SBarry Smith It should also be called every time `atlasDof` is modified directly. 128969c11d05SVaclav Hapla 1290cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetDof()`, `PetscSectionSetDof()`, `PetscSectionAddDof()`, `PetscSectionCreate()` 1291ea844a1aSMatthew Knepley @*/ 1292d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetMaxDof(PetscSection s, PetscInt *maxDof) 1293d71ae5a4SJacob Faibussowitsch { 129469c11d05SVaclav Hapla PetscInt p; 129569c11d05SVaclav Hapla 1296ea844a1aSMatthew Knepley PetscFunctionBegin; 1297ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 12984f572ea9SToby Isaac PetscAssertPointer(maxDof, 2); 129969c11d05SVaclav Hapla if (s->maxDof == PETSC_MIN_INT) { 130069c11d05SVaclav Hapla s->maxDof = 0; 1301ad540459SPierre Jolivet for (p = 0; p < s->pEnd - s->pStart; ++p) s->maxDof = PetscMax(s->maxDof, s->atlasDof[p]); 130269c11d05SVaclav Hapla } 1303ea844a1aSMatthew Knepley *maxDof = s->maxDof; 13043ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1305ea844a1aSMatthew Knepley } 1306ea844a1aSMatthew Knepley 1307ea844a1aSMatthew Knepley /*@ 130820662ed9SBarry Smith PetscSectionGetStorageSize - Return the size of an array or local `Vec` capable of holding all the degrees of freedom defined in a `PetscSection` 1309ea844a1aSMatthew Knepley 131040750d41SVaclav Hapla Not Collective 1311ea844a1aSMatthew Knepley 1312ea844a1aSMatthew Knepley Input Parameter: 1313cab54364SBarry Smith . s - the `PetscSection` 1314ea844a1aSMatthew Knepley 1315ea844a1aSMatthew Knepley Output Parameter: 1316ea844a1aSMatthew Knepley . size - the size of an array which can hold all the dofs 1317ea844a1aSMatthew Knepley 1318ea844a1aSMatthew Knepley Level: intermediate 1319ea844a1aSMatthew Knepley 1320cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetOffset()`, `PetscSectionGetConstrainedStorageSize()`, `PetscSectionCreate()` 1321ea844a1aSMatthew Knepley @*/ 1322d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetStorageSize(PetscSection s, PetscInt *size) 1323d71ae5a4SJacob Faibussowitsch { 1324ea844a1aSMatthew Knepley PetscInt p, n = 0; 1325ea844a1aSMatthew Knepley 1326ea844a1aSMatthew Knepley PetscFunctionBegin; 1327ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 13284f572ea9SToby Isaac PetscAssertPointer(size, 2); 1329ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) n += s->atlasDof[p] > 0 ? s->atlasDof[p] : 0; 1330ea844a1aSMatthew Knepley *size = n; 13313ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1332ea844a1aSMatthew Knepley } 1333ea844a1aSMatthew Knepley 1334ea844a1aSMatthew Knepley /*@ 133520662ed9SBarry Smith PetscSectionGetConstrainedStorageSize - Return the size of an array or local `Vec` capable of holding all unconstrained degrees of freedom in a `PetscSection` 1336ea844a1aSMatthew Knepley 133740750d41SVaclav Hapla Not Collective 1338ea844a1aSMatthew Knepley 1339064ec1f3Sprj- Input Parameter: 1340cab54364SBarry Smith . s - the `PetscSection` 1341ea844a1aSMatthew Knepley 1342ea844a1aSMatthew Knepley Output Parameter: 1343ea844a1aSMatthew Knepley . size - the size of an array which can hold all unconstrained dofs 1344ea844a1aSMatthew Knepley 1345ea844a1aSMatthew Knepley Level: intermediate 1346ea844a1aSMatthew Knepley 1347cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetStorageSize()`, `PetscSectionGetOffset()`, `PetscSectionCreate()` 1348ea844a1aSMatthew Knepley @*/ 1349d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetConstrainedStorageSize(PetscSection s, PetscInt *size) 1350d71ae5a4SJacob Faibussowitsch { 1351ea844a1aSMatthew Knepley PetscInt p, n = 0; 1352ea844a1aSMatthew Knepley 1353ea844a1aSMatthew Knepley PetscFunctionBegin; 1354ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 13554f572ea9SToby Isaac PetscAssertPointer(size, 2); 1356ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) { 1357ea844a1aSMatthew Knepley const PetscInt cdof = s->bc ? s->bc->atlasDof[p] : 0; 1358ea844a1aSMatthew Knepley n += s->atlasDof[p] > 0 ? s->atlasDof[p] - cdof : 0; 1359ea844a1aSMatthew Knepley } 1360ea844a1aSMatthew Knepley *size = n; 13613ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1362ea844a1aSMatthew Knepley } 1363ea844a1aSMatthew Knepley 1364ea844a1aSMatthew Knepley /*@ 1365583308b6SBarry Smith PetscSectionCreateGlobalSection - Create a parallel section describing the global layout using 1366583308b6SBarry Smith a local (sequential) `PetscSection` on each MPI process and a `PetscSF` describing the section point overlap. 1367ea844a1aSMatthew Knepley 1368ea844a1aSMatthew Knepley Input Parameters: 1369cab54364SBarry Smith + s - The `PetscSection` for the local field layout 1370cab54364SBarry Smith . sf - The `PetscSF` describing parallel layout of the section points (leaves are unowned local points) 1371cab54364SBarry Smith . includeConstraints - By default this is `PETSC_FALSE`, meaning that the global field vector will not possess constrained dofs 1372cab54364SBarry Smith - localOffsets - If `PETSC_TRUE`, use local rather than global offsets for the points 1373ea844a1aSMatthew Knepley 1374ea844a1aSMatthew Knepley Output Parameter: 1375cab54364SBarry Smith . gsection - The `PetscSection` for the global field layout 1376ea844a1aSMatthew Knepley 1377ea844a1aSMatthew Knepley Level: intermediate 1378ea844a1aSMatthew Knepley 1379db527f05SMatthew G. Knepley Notes: 1380583308b6SBarry Smith On each MPI process `gsection` inherits the chart of the `s` on that process. 1381db527f05SMatthew G. Knepley 1382583308b6SBarry Smith This sets negative sizes and offsets to points not owned by this process as defined by `sf` but that are within the local value of the chart of `gsection`. 1383583308b6SBarry Smith In those locations the value of size is -(size+1) and the value of the offset on the remote process is -(off+1). 1384cab54364SBarry Smith 138520662ed9SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionCreateGlobalSectionCensored()` 1386ea844a1aSMatthew Knepley @*/ 1387d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateGlobalSection(PetscSection s, PetscSF sf, PetscBool includeConstraints, PetscBool localOffsets, PetscSection *gsection) 1388d71ae5a4SJacob Faibussowitsch { 1389ea844a1aSMatthew Knepley PetscSection gs; 1390ea844a1aSMatthew Knepley const PetscInt *pind = NULL; 1391ea844a1aSMatthew Knepley PetscInt *recv = NULL, *neg = NULL; 1392046d2115Sksagiyam PetscInt pStart, pEnd, p, dof, cdof, off, foff, globalOff = 0, nroots, nlocal, maxleaf; 1393046d2115Sksagiyam PetscInt numFields, f, numComponents; 1394ea844a1aSMatthew Knepley 1395ea844a1aSMatthew Knepley PetscFunctionBegin; 1396ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1397ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sf, PETSCSF_CLASSID, 2); 1398ea844a1aSMatthew Knepley PetscValidLogicalCollectiveBool(s, includeConstraints, 3); 1399ea844a1aSMatthew Knepley PetscValidLogicalCollectiveBool(s, localOffsets, 4); 14004f572ea9SToby Isaac PetscAssertPointer(gsection, 5); 140128b400f6SJacob Faibussowitsch PetscCheck(s->pointMajor, PETSC_COMM_SELF, PETSC_ERR_SUP, "No support for field major ordering"); 14029566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), &gs)); 14039566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s, &numFields)); 14049566063dSJacob Faibussowitsch if (numFields > 0) PetscCall(PetscSectionSetNumFields(gs, numFields)); 14059566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 14069566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(gs, pStart, pEnd)); 140787e637c6Sksagiyam gs->includesConstraints = includeConstraints; 14089566063dSJacob Faibussowitsch PetscCall(PetscSFGetGraph(sf, &nroots, NULL, NULL, NULL)); 1409ea844a1aSMatthew Knepley nlocal = nroots; /* The local/leaf space matches global/root space */ 1410ea844a1aSMatthew Knepley /* Must allocate for all points visible to SF, which may be more than this section */ 1411ea844a1aSMatthew Knepley if (nroots >= 0) { /* nroots < 0 means that the graph has not been set, only happens in serial */ 14129566063dSJacob Faibussowitsch PetscCall(PetscSFGetLeafRange(sf, NULL, &maxleaf)); 141308401ef6SPierre Jolivet PetscCheck(nroots >= pEnd, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "SF roots %" PetscInt_FMT " < pEnd %" PetscInt_FMT, nroots, pEnd); 141408401ef6SPierre Jolivet PetscCheck(maxleaf < nroots, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Max local leaf %" PetscInt_FMT " >= nroots %" PetscInt_FMT, maxleaf, nroots); 14159566063dSJacob Faibussowitsch PetscCall(PetscMalloc2(nroots, &neg, nlocal, &recv)); 14169566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(neg, nroots)); 1417ea844a1aSMatthew Knepley } 1418ea844a1aSMatthew Knepley /* Mark all local points with negative dof */ 1419ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 14209566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 14219566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(gs, p, dof)); 14229566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof)); 14239566063dSJacob Faibussowitsch if (!includeConstraints && cdof > 0) PetscCall(PetscSectionSetConstraintDof(gs, p, cdof)); 1424ea844a1aSMatthew Knepley if (neg) neg[p] = -(dof + 1); 1425ea844a1aSMatthew Knepley } 14269566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUpBC(gs)); 14279566063dSJacob Faibussowitsch if (gs->bcIndices) PetscCall(PetscArraycpy(gs->bcIndices, s->bcIndices, gs->bc->atlasOff[gs->bc->pEnd - gs->bc->pStart - 1] + gs->bc->atlasDof[gs->bc->pEnd - gs->bc->pStart - 1])); 1428ea844a1aSMatthew Knepley if (nroots >= 0) { 14299566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(recv, nlocal)); 14309566063dSJacob Faibussowitsch PetscCall(PetscSFBcastBegin(sf, MPIU_INT, neg, recv, MPI_REPLACE)); 14319566063dSJacob Faibussowitsch PetscCall(PetscSFBcastEnd(sf, MPIU_INT, neg, recv, MPI_REPLACE)); 1432ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1433ea844a1aSMatthew Knepley if (recv[p] < 0) { 1434ea844a1aSMatthew Knepley gs->atlasDof[p - pStart] = recv[p]; 14359566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 143608401ef6SPierre Jolivet PetscCheck(-(recv[p] + 1) == dof, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Global dof %" PetscInt_FMT " for point %" PetscInt_FMT " is not the unconstrained %" PetscInt_FMT, -(recv[p] + 1), p, dof); 1437ea844a1aSMatthew Knepley } 1438ea844a1aSMatthew Knepley } 1439ea844a1aSMatthew Knepley } 1440ea844a1aSMatthew Knepley /* Calculate new sizes, get process offset, and calculate point offsets */ 14419566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISGetIndices(s->perm, &pind)); 1442ea844a1aSMatthew Knepley for (p = 0, off = 0; p < pEnd - pStart; ++p) { 1443ea844a1aSMatthew Knepley const PetscInt q = pind ? pind[p] : p; 1444ea844a1aSMatthew Knepley 1445ea844a1aSMatthew Knepley cdof = (!includeConstraints && s->bc) ? s->bc->atlasDof[q] : 0; 1446ea844a1aSMatthew Knepley gs->atlasOff[q] = off; 1447ea844a1aSMatthew Knepley off += gs->atlasDof[q] > 0 ? gs->atlasDof[q] - cdof : 0; 1448ea844a1aSMatthew Knepley } 1449ea844a1aSMatthew Knepley if (!localOffsets) { 14509566063dSJacob Faibussowitsch PetscCallMPI(MPI_Scan(&off, &globalOff, 1, MPIU_INT, MPI_SUM, PetscObjectComm((PetscObject)s))); 1451ea844a1aSMatthew Knepley globalOff -= off; 1452ea844a1aSMatthew Knepley } 1453ea844a1aSMatthew Knepley for (p = pStart, off = 0; p < pEnd; ++p) { 1454ea844a1aSMatthew Knepley gs->atlasOff[p - pStart] += globalOff; 1455ea844a1aSMatthew Knepley if (neg) neg[p] = -(gs->atlasOff[p - pStart] + 1); 1456ea844a1aSMatthew Knepley } 14579566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISRestoreIndices(s->perm, &pind)); 1458ea844a1aSMatthew Knepley /* Put in negative offsets for ghost points */ 1459ea844a1aSMatthew Knepley if (nroots >= 0) { 14609566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(recv, nlocal)); 14619566063dSJacob Faibussowitsch PetscCall(PetscSFBcastBegin(sf, MPIU_INT, neg, recv, MPI_REPLACE)); 14629566063dSJacob Faibussowitsch PetscCall(PetscSFBcastEnd(sf, MPIU_INT, neg, recv, MPI_REPLACE)); 1463ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1464ea844a1aSMatthew Knepley if (recv[p] < 0) gs->atlasOff[p - pStart] = recv[p]; 1465ea844a1aSMatthew Knepley } 1466ea844a1aSMatthew Knepley } 14679566063dSJacob Faibussowitsch PetscCall(PetscFree2(neg, recv)); 1468046d2115Sksagiyam /* Set field dofs/offsets/constraints */ 1469046d2115Sksagiyam for (f = 0; f < numFields; ++f) { 1470046d2115Sksagiyam gs->field[f]->includesConstraints = includeConstraints; 14719566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s, f, &numComponents)); 14729566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(gs, f, numComponents)); 1473046d2115Sksagiyam } 1474046d2115Sksagiyam for (p = pStart; p < pEnd; ++p) { 14759566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(gs, p, &off)); 1476046d2115Sksagiyam for (f = 0, foff = off; f < numFields; ++f) { 14779566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, f, &cdof)); 14789566063dSJacob Faibussowitsch if (!includeConstraints && cdof > 0) PetscCall(PetscSectionSetFieldConstraintDof(gs, p, f, cdof)); 14799566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, f, &dof)); 14809566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldDof(gs, p, f, off < 0 ? -(dof + 1) : dof)); 14819566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldOffset(gs, p, f, foff)); 14829566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(gs, p, f, &cdof)); 1483046d2115Sksagiyam foff = off < 0 ? foff - (dof - cdof) : foff + (dof - cdof); 1484046d2115Sksagiyam } 1485046d2115Sksagiyam } 1486046d2115Sksagiyam for (f = 0; f < numFields; ++f) { 1487046d2115Sksagiyam PetscSection gfs = gs->field[f]; 1488046d2115Sksagiyam 14899566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUpBC(gfs)); 14909566063dSJacob Faibussowitsch if (gfs->bcIndices) PetscCall(PetscArraycpy(gfs->bcIndices, s->field[f]->bcIndices, gfs->bc->atlasOff[gfs->bc->pEnd - gfs->bc->pStart - 1] + gfs->bc->atlasDof[gfs->bc->pEnd - gfs->bc->pStart - 1])); 1491046d2115Sksagiyam } 1492046d2115Sksagiyam gs->setup = PETSC_TRUE; 14939566063dSJacob Faibussowitsch PetscCall(PetscSectionViewFromOptions(gs, NULL, "-global_section_view")); 1494ea844a1aSMatthew Knepley *gsection = gs; 14953ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1496ea844a1aSMatthew Knepley } 1497ea844a1aSMatthew Knepley 1498ea844a1aSMatthew Knepley /*@ 1499583308b6SBarry Smith PetscSectionCreateGlobalSectionCensored - Create a `PetscSection` describing the globallayout using 1500583308b6SBarry Smith a local (sequential) `PetscSection` on each MPI process and an `PetscSF` describing the section point overlap. 1501ea844a1aSMatthew Knepley 1502ea844a1aSMatthew Knepley Input Parameters: 1503cab54364SBarry Smith + s - The `PetscSection` for the local field layout 1504cab54364SBarry Smith . sf - The `PetscSF` describing parallel layout of the section points 1505583308b6SBarry Smith . includeConstraints - By default this is `PETSC_FALSE`, meaning that the global vector will not possess constrained dofs 1506583308b6SBarry Smith . numExcludes - The number of exclusion ranges, this must have the same value on all MPI processes 1507583308b6SBarry Smith - excludes - An array [start_0, end_0, start_1, end_1, ...] where there are `numExcludes` pairs and must have the same values on all MPI processes 1508ea844a1aSMatthew Knepley 1509ea844a1aSMatthew Knepley Output Parameter: 1510cab54364SBarry Smith . gsection - The `PetscSection` for the global field layout 1511ea844a1aSMatthew Knepley 1512ea844a1aSMatthew Knepley Level: advanced 1513ea844a1aSMatthew Knepley 1514583308b6SBarry Smith Notes: 1515583308b6SBarry Smith On each MPI process `gsection` inherits the chart of the `s` on that process. 151620662ed9SBarry Smith 1517583308b6SBarry Smith This sets negative sizes and offsets to points not owned by this process as defined by `sf` but that are within the local value of the chart of `gsection`. 1518583308b6SBarry Smith In those locations the value of size is -(size+1) and the value of the offset on the remote process is -(off+1). 1519583308b6SBarry Smith 1520583308b6SBarry Smith This routine augments `PetscSectionCreateGlobalSection()` by allowing one to exclude certain ranges in the chart of the `PetscSection` 1521cab54364SBarry Smith 152238b5cf2dSJacob Faibussowitsch Developer Notes: 152320662ed9SBarry Smith This is a terrible function name 152420662ed9SBarry Smith 152542747ad1SJacob Faibussowitsch .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()` 1526ea844a1aSMatthew Knepley @*/ 1527d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateGlobalSectionCensored(PetscSection s, PetscSF sf, PetscBool includeConstraints, PetscInt numExcludes, const PetscInt excludes[], PetscSection *gsection) 1528d71ae5a4SJacob Faibussowitsch { 1529ea844a1aSMatthew Knepley const PetscInt *pind = NULL; 1530ea844a1aSMatthew Knepley PetscInt *neg = NULL, *tmpOff = NULL; 1531ea844a1aSMatthew Knepley PetscInt pStart, pEnd, p, e, dof, cdof, off, globalOff = 0, nroots; 1532ea844a1aSMatthew Knepley 1533ea844a1aSMatthew Knepley PetscFunctionBegin; 1534ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1535ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sf, PETSCSF_CLASSID, 2); 15364f572ea9SToby Isaac PetscAssertPointer(gsection, 6); 15379566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), gsection)); 15389566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 15399566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(*gsection, pStart, pEnd)); 15409566063dSJacob Faibussowitsch PetscCall(PetscSFGetGraph(sf, &nroots, NULL, NULL, NULL)); 1541ea844a1aSMatthew Knepley if (nroots >= 0) { 154208401ef6SPierre Jolivet PetscCheck(nroots >= pEnd - pStart, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "PetscSF nroots %" PetscInt_FMT " < %" PetscInt_FMT " section size", nroots, pEnd - pStart); 15439566063dSJacob Faibussowitsch PetscCall(PetscCalloc1(nroots, &neg)); 1544ea844a1aSMatthew Knepley if (nroots > pEnd - pStart) { 15459566063dSJacob Faibussowitsch PetscCall(PetscCalloc1(nroots, &tmpOff)); 1546ea844a1aSMatthew Knepley } else { 1547ea844a1aSMatthew Knepley tmpOff = &(*gsection)->atlasDof[-pStart]; 1548ea844a1aSMatthew Knepley } 1549ea844a1aSMatthew Knepley } 1550ea844a1aSMatthew Knepley /* Mark ghost points with negative dof */ 1551ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1552ea844a1aSMatthew Knepley for (e = 0; e < numExcludes; ++e) { 1553ea844a1aSMatthew Knepley if ((p >= excludes[e * 2 + 0]) && (p < excludes[e * 2 + 1])) { 15549566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(*gsection, p, 0)); 1555ea844a1aSMatthew Knepley break; 1556ea844a1aSMatthew Knepley } 1557ea844a1aSMatthew Knepley } 1558ea844a1aSMatthew Knepley if (e < numExcludes) continue; 15599566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 15609566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(*gsection, p, dof)); 15619566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof)); 15629566063dSJacob Faibussowitsch if (!includeConstraints && cdof > 0) PetscCall(PetscSectionSetConstraintDof(*gsection, p, cdof)); 1563ea844a1aSMatthew Knepley if (neg) neg[p] = -(dof + 1); 1564ea844a1aSMatthew Knepley } 15659566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUpBC(*gsection)); 1566ea844a1aSMatthew Knepley if (nroots >= 0) { 15679566063dSJacob Faibussowitsch PetscCall(PetscSFBcastBegin(sf, MPIU_INT, neg, tmpOff, MPI_REPLACE)); 15689566063dSJacob Faibussowitsch PetscCall(PetscSFBcastEnd(sf, MPIU_INT, neg, tmpOff, MPI_REPLACE)); 1569ea844a1aSMatthew Knepley if (nroots > pEnd - pStart) { 15709371c9d4SSatish Balay for (p = pStart; p < pEnd; ++p) { 15719371c9d4SSatish Balay if (tmpOff[p] < 0) (*gsection)->atlasDof[p - pStart] = tmpOff[p]; 15729371c9d4SSatish Balay } 1573ea844a1aSMatthew Knepley } 1574ea844a1aSMatthew Knepley } 157535cb6cd3SPierre Jolivet /* Calculate new sizes, get process offset, and calculate point offsets */ 15769566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISGetIndices(s->perm, &pind)); 1577ea844a1aSMatthew Knepley for (p = 0, off = 0; p < pEnd - pStart; ++p) { 1578ea844a1aSMatthew Knepley const PetscInt q = pind ? pind[p] : p; 1579ea844a1aSMatthew Knepley 1580ea844a1aSMatthew Knepley cdof = (!includeConstraints && s->bc) ? s->bc->atlasDof[q] : 0; 1581ea844a1aSMatthew Knepley (*gsection)->atlasOff[q] = off; 1582ea844a1aSMatthew Knepley off += (*gsection)->atlasDof[q] > 0 ? (*gsection)->atlasDof[q] - cdof : 0; 1583ea844a1aSMatthew Knepley } 15849566063dSJacob Faibussowitsch PetscCallMPI(MPI_Scan(&off, &globalOff, 1, MPIU_INT, MPI_SUM, PetscObjectComm((PetscObject)s))); 1585ea844a1aSMatthew Knepley globalOff -= off; 1586ea844a1aSMatthew Knepley for (p = 0, off = 0; p < pEnd - pStart; ++p) { 1587ea844a1aSMatthew Knepley (*gsection)->atlasOff[p] += globalOff; 1588ea844a1aSMatthew Knepley if (neg) neg[p + pStart] = -((*gsection)->atlasOff[p] + 1); 1589ea844a1aSMatthew Knepley } 15909566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISRestoreIndices(s->perm, &pind)); 1591ea844a1aSMatthew Knepley /* Put in negative offsets for ghost points */ 1592ea844a1aSMatthew Knepley if (nroots >= 0) { 1593ea844a1aSMatthew Knepley if (nroots == pEnd - pStart) tmpOff = &(*gsection)->atlasOff[-pStart]; 15949566063dSJacob Faibussowitsch PetscCall(PetscSFBcastBegin(sf, MPIU_INT, neg, tmpOff, MPI_REPLACE)); 15959566063dSJacob Faibussowitsch PetscCall(PetscSFBcastEnd(sf, MPIU_INT, neg, tmpOff, MPI_REPLACE)); 1596ea844a1aSMatthew Knepley if (nroots > pEnd - pStart) { 15979371c9d4SSatish Balay for (p = pStart; p < pEnd; ++p) { 15989371c9d4SSatish Balay if (tmpOff[p] < 0) (*gsection)->atlasOff[p - pStart] = tmpOff[p]; 15999371c9d4SSatish Balay } 1600ea844a1aSMatthew Knepley } 1601ea844a1aSMatthew Knepley } 16029566063dSJacob Faibussowitsch if (nroots >= 0 && nroots > pEnd - pStart) PetscCall(PetscFree(tmpOff)); 16039566063dSJacob Faibussowitsch PetscCall(PetscFree(neg)); 16043ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1605ea844a1aSMatthew Knepley } 1606ea844a1aSMatthew Knepley 1607ea844a1aSMatthew Knepley /*@ 1608583308b6SBarry Smith PetscSectionGetPointLayout - Get a `PetscLayout` for the points with nonzero dof counts of the unnamed default field within this `PetscSection`s local chart 1609ea844a1aSMatthew Knepley 1610cab54364SBarry Smith Collective 1611ea844a1aSMatthew Knepley 1612ea844a1aSMatthew Knepley Input Parameters: 1613cab54364SBarry Smith + comm - The `MPI_Comm` 1614cab54364SBarry Smith - s - The `PetscSection` 1615ea844a1aSMatthew Knepley 1616ea844a1aSMatthew Knepley Output Parameter: 161720662ed9SBarry Smith . layout - The point layout for the data that defines the section 1618ea844a1aSMatthew Knepley 1619ea844a1aSMatthew Knepley Level: advanced 1620ea844a1aSMatthew Knepley 162120662ed9SBarry Smith Notes: 1622583308b6SBarry Smith `PetscSectionGetValueLayout()` provides similar information but counting the total number of degrees of freedom on the MPI process (excluding constrained 1623583308b6SBarry Smith degrees of freedom). 162420662ed9SBarry Smith 1625583308b6SBarry Smith This count includes constrained degrees of freedom 1626583308b6SBarry Smith 1627583308b6SBarry Smith This is usually called on the default global section. 1628583308b6SBarry Smith 1629583308b6SBarry Smith Example: 1630583308b6SBarry Smith .vb 1631583308b6SBarry Smith The chart is [2,5), point 2 has 2 dof, point 3 has 0 dof, point 4 has 1 dof 1632583308b6SBarry Smith The local size of the `PetscLayout` is 2 since 2 points have a non-zero number of dof 1633583308b6SBarry Smith .ve 1634583308b6SBarry Smith 163538b5cf2dSJacob Faibussowitsch Developer Notes: 1636583308b6SBarry Smith I find the names of these two functions extremely non-informative 1637cab54364SBarry Smith 1638cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetValueLayout()`, `PetscSectionCreate()` 1639ea844a1aSMatthew Knepley @*/ 1640d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetPointLayout(MPI_Comm comm, PetscSection s, PetscLayout *layout) 1641d71ae5a4SJacob Faibussowitsch { 1642ea844a1aSMatthew Knepley PetscInt pStart, pEnd, p, localSize = 0; 1643ea844a1aSMatthew Knepley 1644ea844a1aSMatthew Knepley PetscFunctionBegin; 16459566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 1646ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1647ea844a1aSMatthew Knepley PetscInt dof; 1648ea844a1aSMatthew Knepley 16499566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 16509120ba30SVaclav Hapla if (dof >= 0) ++localSize; 1651ea844a1aSMatthew Knepley } 16529566063dSJacob Faibussowitsch PetscCall(PetscLayoutCreate(comm, layout)); 16539566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetLocalSize(*layout, localSize)); 16549566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetBlockSize(*layout, 1)); 16559566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetUp(*layout)); 16563ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1657ea844a1aSMatthew Knepley } 1658ea844a1aSMatthew Knepley 1659ea844a1aSMatthew Knepley /*@ 166020662ed9SBarry Smith PetscSectionGetValueLayout - Get the `PetscLayout` associated with the section dofs of a `PetscSection` 1661ea844a1aSMatthew Knepley 1662cab54364SBarry Smith Collective 1663ea844a1aSMatthew Knepley 1664ea844a1aSMatthew Knepley Input Parameters: 1665cab54364SBarry Smith + comm - The `MPI_Comm` 1666cab54364SBarry Smith - s - The `PetscSection` 1667ea844a1aSMatthew Knepley 1668ea844a1aSMatthew Knepley Output Parameter: 1669ea844a1aSMatthew Knepley . layout - The dof layout for the section 1670ea844a1aSMatthew Knepley 1671ea844a1aSMatthew Knepley Level: advanced 1672ea844a1aSMatthew Knepley 167320662ed9SBarry Smith Notes: 1674583308b6SBarry Smith `PetscSectionGetPointLayout()` provides similar information but only counting the number of points with nonzero degrees of freedom and 1675583308b6SBarry Smith including the constrained degrees of freedom 167620662ed9SBarry Smith 1677cab54364SBarry Smith This is usually called for the default global section. 1678cab54364SBarry Smith 1679583308b6SBarry Smith Example: 1680583308b6SBarry Smith .vb 1681583308b6SBarry Smith The chart is [2,5), point 2 has 4 dof (2 constrained), point 3 has 0 dof, point 4 has 1 dof (not constrained) 1682583308b6SBarry Smith The local size of the `PetscLayout` is 3 since there are 3 unconstrained degrees of freedom on this MPI process 1683583308b6SBarry Smith .ve 1684583308b6SBarry Smith 1685cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetPointLayout()`, `PetscSectionCreate()` 1686ea844a1aSMatthew Knepley @*/ 1687d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetValueLayout(MPI_Comm comm, PetscSection s, PetscLayout *layout) 1688d71ae5a4SJacob Faibussowitsch { 1689ea844a1aSMatthew Knepley PetscInt pStart, pEnd, p, localSize = 0; 1690ea844a1aSMatthew Knepley 1691ea844a1aSMatthew Knepley PetscFunctionBegin; 1692ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 2); 16934f572ea9SToby Isaac PetscAssertPointer(layout, 3); 16949566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 1695ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1696ea844a1aSMatthew Knepley PetscInt dof, cdof; 1697ea844a1aSMatthew Knepley 16989566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 16999566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof)); 1700ea844a1aSMatthew Knepley if (dof - cdof > 0) localSize += dof - cdof; 1701ea844a1aSMatthew Knepley } 17029566063dSJacob Faibussowitsch PetscCall(PetscLayoutCreate(comm, layout)); 17039566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetLocalSize(*layout, localSize)); 17049566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetBlockSize(*layout, 1)); 17059566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetUp(*layout)); 17063ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1707ea844a1aSMatthew Knepley } 1708ea844a1aSMatthew Knepley 1709ea844a1aSMatthew Knepley /*@ 1710db527f05SMatthew G. Knepley PetscSectionGetOffset - Return the offset into an array or `Vec` for the dof associated with the given point. 1711ea844a1aSMatthew Knepley 171240750d41SVaclav Hapla Not Collective 1713ea844a1aSMatthew Knepley 1714ea844a1aSMatthew Knepley Input Parameters: 1715cab54364SBarry Smith + s - the `PetscSection` 1716ea844a1aSMatthew Knepley - point - the point 1717ea844a1aSMatthew Knepley 1718ea844a1aSMatthew Knepley Output Parameter: 1719ea844a1aSMatthew Knepley . offset - the offset 1720ea844a1aSMatthew Knepley 1721ea844a1aSMatthew Knepley Level: intermediate 1722ea844a1aSMatthew Knepley 1723583308b6SBarry Smith Notes: 1724583308b6SBarry Smith In a global section, this offset will be negative for points not owned by this process. 1725583308b6SBarry Smith 1726583308b6SBarry Smith This is for the unnamed default field in the `PetscSection` not the named fields 1727583308b6SBarry Smith 1728583308b6SBarry Smith The `offset` values are different depending on a value set with `PetscSectionSetPointMajor()` 1729583308b6SBarry Smith 1730583308b6SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetFieldOffset()`, `PetscSectionCreate()`, `PetscSectionSetPointMajor()` 1731ea844a1aSMatthew Knepley @*/ 1732d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetOffset(PetscSection s, PetscInt point, PetscInt *offset) 1733d71ae5a4SJacob Faibussowitsch { 1734ea844a1aSMatthew Knepley PetscFunctionBegin; 1735ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 17364f572ea9SToby Isaac PetscAssertPointer(offset, 3); 1737ad540459SPierre Jolivet if (PetscDefined(USE_DEBUG)) PetscCheck(!(point < s->pStart) && !(point >= s->pEnd), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section point %" PetscInt_FMT " should be in [%" PetscInt_FMT ", %" PetscInt_FMT ")", point, s->pStart, s->pEnd); 1738ea844a1aSMatthew Knepley *offset = s->atlasOff[point - s->pStart]; 17393ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1740ea844a1aSMatthew Knepley } 1741ea844a1aSMatthew Knepley 1742ea844a1aSMatthew Knepley /*@ 1743db527f05SMatthew G. Knepley PetscSectionSetOffset - Set the offset into an array or `Vec` for the dof associated with the given point. 1744ea844a1aSMatthew Knepley 174540750d41SVaclav Hapla Not Collective 1746ea844a1aSMatthew Knepley 1747ea844a1aSMatthew Knepley Input Parameters: 1748cab54364SBarry Smith + s - the `PetscSection` 1749ea844a1aSMatthew Knepley . point - the point 1750ea844a1aSMatthew Knepley - offset - the offset 1751ea844a1aSMatthew Knepley 1752583308b6SBarry Smith Level: developer 1753ea844a1aSMatthew Knepley 1754cab54364SBarry Smith Note: 1755cab54364SBarry Smith The user usually does not call this function, but uses `PetscSectionSetUp()` 1756cab54364SBarry Smith 1757cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetFieldOffset()`, `PetscSectionCreate()`, `PetscSectionSetUp()` 1758ea844a1aSMatthew Knepley @*/ 1759d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetOffset(PetscSection s, PetscInt point, PetscInt offset) 1760d71ae5a4SJacob Faibussowitsch { 1761ea844a1aSMatthew Knepley PetscFunctionBegin; 1762ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 176308401ef6SPierre Jolivet PetscCheck(!(point < s->pStart) && !(point >= s->pEnd), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section point %" PetscInt_FMT " should be in [%" PetscInt_FMT ", %" PetscInt_FMT ")", point, s->pStart, s->pEnd); 1764ea844a1aSMatthew Knepley s->atlasOff[point - s->pStart] = offset; 17653ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1766ea844a1aSMatthew Knepley } 1767ea844a1aSMatthew Knepley 1768ea844a1aSMatthew Knepley /*@ 1769db527f05SMatthew G. Knepley PetscSectionGetFieldOffset - Return the offset into an array or `Vec` for the field dof associated with the given point. 1770ea844a1aSMatthew Knepley 177140750d41SVaclav Hapla Not Collective 1772ea844a1aSMatthew Knepley 1773ea844a1aSMatthew Knepley Input Parameters: 1774cab54364SBarry Smith + s - the `PetscSection` 1775ea844a1aSMatthew Knepley . point - the point 1776ea844a1aSMatthew Knepley - field - the field 1777ea844a1aSMatthew Knepley 1778ea844a1aSMatthew Knepley Output Parameter: 1779ea844a1aSMatthew Knepley . offset - the offset 1780ea844a1aSMatthew Knepley 1781ea844a1aSMatthew Knepley Level: intermediate 1782ea844a1aSMatthew Knepley 1783583308b6SBarry Smith Notes: 1784583308b6SBarry Smith In a global section, this offset will be negative for points not owned by this process. 1785583308b6SBarry Smith 1786583308b6SBarry Smith The `offset` values are different depending on a value set with `PetscSectionSetPointMajor()` 1787583308b6SBarry Smith 1788583308b6SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetOffset()`, `PetscSectionCreate()`, `PetscSectionGetFieldPointOffset()` 1789ea844a1aSMatthew Knepley @*/ 1790d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldOffset(PetscSection s, PetscInt point, PetscInt field, PetscInt *offset) 1791d71ae5a4SJacob Faibussowitsch { 1792ea844a1aSMatthew Knepley PetscFunctionBegin; 1793ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 17944f572ea9SToby Isaac PetscAssertPointer(offset, 4); 17952abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 17969566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s->field[field], point, offset)); 17973ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1798ea844a1aSMatthew Knepley } 1799ea844a1aSMatthew Knepley 1800ea844a1aSMatthew Knepley /*@ 1801db527f05SMatthew G. Knepley PetscSectionSetFieldOffset - Set the offset into an array or `Vec` for the dof associated with the given field at a point. 1802ea844a1aSMatthew Knepley 180340750d41SVaclav Hapla Not Collective 1804ea844a1aSMatthew Knepley 1805ea844a1aSMatthew Knepley Input Parameters: 180620662ed9SBarry Smith + s - the `PetscSection` 1807ea844a1aSMatthew Knepley . point - the point 1808ea844a1aSMatthew Knepley . field - the field 1809ea844a1aSMatthew Knepley - offset - the offset 1810ea844a1aSMatthew Knepley 1811cab54364SBarry Smith Level: developer 1812ea844a1aSMatthew Knepley 1813cab54364SBarry Smith Note: 1814cab54364SBarry Smith The user usually does not call this function, but uses `PetscSectionSetUp()` 1815ea844a1aSMatthew Knepley 1816cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetFieldOffset()`, `PetscSectionSetOffset()`, `PetscSectionCreate()`, `PetscSectionSetUp()` 1817ea844a1aSMatthew Knepley @*/ 1818d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldOffset(PetscSection s, PetscInt point, PetscInt field, PetscInt offset) 1819d71ae5a4SJacob Faibussowitsch { 1820ea844a1aSMatthew Knepley PetscFunctionBegin; 1821ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 18222abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 18239566063dSJacob Faibussowitsch PetscCall(PetscSectionSetOffset(s->field[field], point, offset)); 18243ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1825ea844a1aSMatthew Knepley } 1826ea844a1aSMatthew Knepley 1827ea844a1aSMatthew Knepley /*@ 1828583308b6SBarry Smith PetscSectionGetFieldPointOffset - Return the offset for the first field dof associated with the given point relative to the offset for that point for the 1829583308b6SBarry Smith unnamed default field's first dof 1830ea844a1aSMatthew Knepley 183140750d41SVaclav Hapla Not Collective 1832ea844a1aSMatthew Knepley 1833ea844a1aSMatthew Knepley Input Parameters: 1834cab54364SBarry Smith + s - the `PetscSection` 1835ea844a1aSMatthew Knepley . point - the point 1836ea844a1aSMatthew Knepley - field - the field 1837ea844a1aSMatthew Knepley 1838ea844a1aSMatthew Knepley Output Parameter: 1839ea844a1aSMatthew Knepley . offset - the offset 1840ea844a1aSMatthew Knepley 1841ea844a1aSMatthew Knepley Level: advanced 1842ea844a1aSMatthew Knepley 1843cab54364SBarry Smith Note: 1844583308b6SBarry Smith This ignores constraints 1845cab54364SBarry Smith 1846583308b6SBarry Smith Example: 1847583308b6SBarry Smith .vb 1848583308b6SBarry Smith if PetscSectionSetPointMajor(s,PETSC_TRUE) 1849583308b6SBarry Smith The unnamed default field has 3 dof at `point` 1850583308b6SBarry Smith Field 0 has 2 dof at `point` 1851583308b6SBarry Smith Then PetscSectionGetFieldPointOffset(s,point,1,&offset) returns and offset of 5 1852583308b6SBarry Smith .ve 1853583308b6SBarry Smith 1854583308b6SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetOffset()`, `PetscSectionCreate()`, `PetscSectionGetFieldOffset()` 1855ea844a1aSMatthew Knepley @*/ 1856d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldPointOffset(PetscSection s, PetscInt point, PetscInt field, PetscInt *offset) 1857d71ae5a4SJacob Faibussowitsch { 1858ea844a1aSMatthew Knepley PetscInt off, foff; 1859ea844a1aSMatthew Knepley 1860ea844a1aSMatthew Knepley PetscFunctionBegin; 1861ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 18624f572ea9SToby Isaac PetscAssertPointer(offset, 4); 18632abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 18649566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s, point, &off)); 18659566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s->field[field], point, &foff)); 1866ea844a1aSMatthew Knepley *offset = foff - off; 18673ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1868ea844a1aSMatthew Knepley } 1869ea844a1aSMatthew Knepley 1870ea844a1aSMatthew Knepley /*@ 187120662ed9SBarry Smith PetscSectionGetOffsetRange - Return the full range of offsets [`start`, `end`) for a `PetscSection` 1872ea844a1aSMatthew Knepley 187340750d41SVaclav Hapla Not Collective 1874ea844a1aSMatthew Knepley 1875ea844a1aSMatthew Knepley Input Parameter: 1876cab54364SBarry Smith . s - the `PetscSection` 1877ea844a1aSMatthew Knepley 1878ea844a1aSMatthew Knepley Output Parameters: 1879ea844a1aSMatthew Knepley + start - the minimum offset 1880ea844a1aSMatthew Knepley - end - one more than the maximum offset 1881ea844a1aSMatthew Knepley 1882ea844a1aSMatthew Knepley Level: intermediate 1883ea844a1aSMatthew Knepley 1884cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetOffset()`, `PetscSectionCreate()` 1885ea844a1aSMatthew Knepley @*/ 1886d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetOffsetRange(PetscSection s, PetscInt *start, PetscInt *end) 1887d71ae5a4SJacob Faibussowitsch { 1888ea844a1aSMatthew Knepley PetscInt os = 0, oe = 0, pStart, pEnd, p; 1889ea844a1aSMatthew Knepley 1890ea844a1aSMatthew Knepley PetscFunctionBegin; 1891ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 18929371c9d4SSatish Balay if (s->atlasOff) { 18939371c9d4SSatish Balay os = s->atlasOff[0]; 18949371c9d4SSatish Balay oe = s->atlasOff[0]; 18959371c9d4SSatish Balay } 18969566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 1897ea844a1aSMatthew Knepley for (p = 0; p < pEnd - pStart; ++p) { 1898ea844a1aSMatthew Knepley PetscInt dof = s->atlasDof[p], off = s->atlasOff[p]; 1899ea844a1aSMatthew Knepley 1900ea844a1aSMatthew Knepley if (off >= 0) { 1901ea844a1aSMatthew Knepley os = PetscMin(os, off); 1902ea844a1aSMatthew Knepley oe = PetscMax(oe, off + dof); 1903ea844a1aSMatthew Knepley } 1904ea844a1aSMatthew Knepley } 1905ea844a1aSMatthew Knepley if (start) *start = os; 1906ea844a1aSMatthew Knepley if (end) *end = oe; 19073ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1908ea844a1aSMatthew Knepley } 1909ea844a1aSMatthew Knepley 1910ea844a1aSMatthew Knepley /*@ 1911583308b6SBarry Smith PetscSectionCreateSubsection - Create a new, smaller `PetscSection` composed of only selected fields 1912ea844a1aSMatthew Knepley 191340750d41SVaclav Hapla Collective 1914ea844a1aSMatthew Knepley 1915d8d19677SJose E. Roman Input Parameters: 1916cab54364SBarry Smith + s - the `PetscSection` 1917ea844a1aSMatthew Knepley . len - the number of subfields 1918ea844a1aSMatthew Knepley - fields - the subfield numbers 1919ea844a1aSMatthew Knepley 1920ea844a1aSMatthew Knepley Output Parameter: 1921ea844a1aSMatthew Knepley . subs - the subsection 1922ea844a1aSMatthew Knepley 1923ea844a1aSMatthew Knepley Level: advanced 1924ea844a1aSMatthew Knepley 1925cab54364SBarry Smith Notes: 1926583308b6SBarry Smith The chart of `subs` is the same as the chart of `s` 1927cab54364SBarry Smith 1928cab54364SBarry Smith This will error if a fieldnumber is out of range 1929cab54364SBarry Smith 1930cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreateSupersection()`, `PetscSectionCreate()` 1931ea844a1aSMatthew Knepley @*/ 1932d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateSubsection(PetscSection s, PetscInt len, const PetscInt fields[], PetscSection *subs) 1933d71ae5a4SJacob Faibussowitsch { 1934b778fa18SValeria Barra PetscInt nF, f, c, pStart, pEnd, p, maxCdof = 0; 1935ea844a1aSMatthew Knepley 1936ea844a1aSMatthew Knepley PetscFunctionBegin; 19373ba16761SJacob Faibussowitsch if (!len) PetscFunctionReturn(PETSC_SUCCESS); 1938ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 19394f572ea9SToby Isaac PetscAssertPointer(fields, 3); 19404f572ea9SToby Isaac PetscAssertPointer(subs, 4); 19419566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s, &nF)); 194208401ef6SPierre Jolivet PetscCheck(len <= nF, PetscObjectComm((PetscObject)s), PETSC_ERR_ARG_WRONG, "Number of requested fields %" PetscInt_FMT " greater than number of fields %" PetscInt_FMT, len, nF); 19439566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), subs)); 19449566063dSJacob Faibussowitsch PetscCall(PetscSectionSetNumFields(*subs, len)); 1945ea844a1aSMatthew Knepley for (f = 0; f < len; ++f) { 1946ea844a1aSMatthew Knepley const char *name = NULL; 1947ea844a1aSMatthew Knepley PetscInt numComp = 0; 194842a52479SJed Brown PetscSectionSym sym; 1949ea844a1aSMatthew Knepley 19509566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldName(s, fields[f], &name)); 19519566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldName(*subs, f, name)); 19529566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s, fields[f], &numComp)); 19539566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(*subs, f, numComp)); 1954b778fa18SValeria Barra for (c = 0; c < s->numFieldComponents[fields[f]]; ++c) { 19559566063dSJacob Faibussowitsch PetscCall(PetscSectionGetComponentName(s, fields[f], c, &name)); 19569566063dSJacob Faibussowitsch PetscCall(PetscSectionSetComponentName(*subs, f, c, name)); 1957b778fa18SValeria Barra } 195842a52479SJed Brown PetscCall(PetscSectionGetFieldSym(s, fields[f], &sym)); 195942a52479SJed Brown PetscCall(PetscSectionSetFieldSym(*subs, f, sym)); 1960ea844a1aSMatthew Knepley } 19619566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 19629566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(*subs, pStart, pEnd)); 1963ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1964ea844a1aSMatthew Knepley PetscInt dof = 0, cdof = 0, fdof = 0, cfdof = 0; 1965ea844a1aSMatthew Knepley 1966ea844a1aSMatthew Knepley for (f = 0; f < len; ++f) { 19679566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, fields[f], &fdof)); 19689566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldDof(*subs, p, f, fdof)); 19699566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, fields[f], &cfdof)); 19709566063dSJacob Faibussowitsch if (cfdof) PetscCall(PetscSectionSetFieldConstraintDof(*subs, p, f, cfdof)); 1971ea844a1aSMatthew Knepley dof += fdof; 1972ea844a1aSMatthew Knepley cdof += cfdof; 1973ea844a1aSMatthew Knepley } 19749566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(*subs, p, dof)); 19759566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetConstraintDof(*subs, p, cdof)); 1976ea844a1aSMatthew Knepley maxCdof = PetscMax(cdof, maxCdof); 1977ea844a1aSMatthew Knepley } 19789566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(*subs)); 1979ea844a1aSMatthew Knepley if (maxCdof) { 1980ea844a1aSMatthew Knepley PetscInt *indices; 1981ea844a1aSMatthew Knepley 19829566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(maxCdof, &indices)); 1983ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1984ea844a1aSMatthew Knepley PetscInt cdof; 1985ea844a1aSMatthew Knepley 19869566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(*subs, p, &cdof)); 1987ea844a1aSMatthew Knepley if (cdof) { 1988ea844a1aSMatthew Knepley const PetscInt *oldIndices = NULL; 1989ea844a1aSMatthew Knepley PetscInt fdof = 0, cfdof = 0, fc, numConst = 0, fOff = 0; 1990ea844a1aSMatthew Knepley 1991ea844a1aSMatthew Knepley for (f = 0; f < len; ++f) { 19929566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, fields[f], &fdof)); 19939566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, fields[f], &cfdof)); 19949566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(s, p, fields[f], &oldIndices)); 19959566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldConstraintIndices(*subs, p, f, oldIndices)); 19969574d0f0SMatthew G. Knepley for (fc = 0; fc < cfdof; ++fc) indices[numConst + fc] = oldIndices[fc] + fOff; 1997ea844a1aSMatthew Knepley numConst += cfdof; 1998ea844a1aSMatthew Knepley fOff += fdof; 1999ea844a1aSMatthew Knepley } 20009566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(*subs, p, indices)); 2001ea844a1aSMatthew Knepley } 2002ea844a1aSMatthew Knepley } 20039566063dSJacob Faibussowitsch PetscCall(PetscFree(indices)); 2004ea844a1aSMatthew Knepley } 20053ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2006ea844a1aSMatthew Knepley } 2007ea844a1aSMatthew Knepley 2008ea844a1aSMatthew Knepley /*@ 2009583308b6SBarry Smith PetscSectionCreateSupersection - Create a new, larger section composed of multiple `PetscSection`s 2010ea844a1aSMatthew Knepley 201140750d41SVaclav Hapla Collective 2012ea844a1aSMatthew Knepley 2013ea844a1aSMatthew Knepley Input Parameters: 2014ea844a1aSMatthew Knepley + s - the input sections 2015ea844a1aSMatthew Knepley - len - the number of input sections 2016ea844a1aSMatthew Knepley 2017ea844a1aSMatthew Knepley Output Parameter: 2018ea844a1aSMatthew Knepley . supers - the supersection 2019ea844a1aSMatthew Knepley 2020ea844a1aSMatthew Knepley Level: advanced 2021ea844a1aSMatthew Knepley 2022583308b6SBarry Smith Notes: 2023cab54364SBarry Smith The section offsets now refer to a new, larger vector. 2024cab54364SBarry Smith 202538b5cf2dSJacob Faibussowitsch Developer Notes: 2026cab54364SBarry Smith Needs to explain how the sections are composed 2027cab54364SBarry Smith 2028cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreateSubsection()`, `PetscSectionCreate()` 2029ea844a1aSMatthew Knepley @*/ 2030d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateSupersection(PetscSection s[], PetscInt len, PetscSection *supers) 2031d71ae5a4SJacob Faibussowitsch { 2032ea844a1aSMatthew Knepley PetscInt Nf = 0, f, pStart = PETSC_MAX_INT, pEnd = 0, p, maxCdof = 0, i; 2033ea844a1aSMatthew Knepley 2034ea844a1aSMatthew Knepley PetscFunctionBegin; 20353ba16761SJacob Faibussowitsch if (!len) PetscFunctionReturn(PETSC_SUCCESS); 2036ea844a1aSMatthew Knepley for (i = 0; i < len; ++i) { 2037ea844a1aSMatthew Knepley PetscInt nf, pStarti, pEndi; 2038ea844a1aSMatthew Knepley 20399566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s[i], &nf)); 20409566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s[i], &pStarti, &pEndi)); 2041ea844a1aSMatthew Knepley pStart = PetscMin(pStart, pStarti); 2042ea844a1aSMatthew Knepley pEnd = PetscMax(pEnd, pEndi); 2043ea844a1aSMatthew Knepley Nf += nf; 2044ea844a1aSMatthew Knepley } 20459566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s[0]), supers)); 20469566063dSJacob Faibussowitsch PetscCall(PetscSectionSetNumFields(*supers, Nf)); 2047ea844a1aSMatthew Knepley for (i = 0, f = 0; i < len; ++i) { 2048b778fa18SValeria Barra PetscInt nf, fi, ci; 2049ea844a1aSMatthew Knepley 20509566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s[i], &nf)); 2051ea844a1aSMatthew Knepley for (fi = 0; fi < nf; ++fi, ++f) { 2052ea844a1aSMatthew Knepley const char *name = NULL; 2053ea844a1aSMatthew Knepley PetscInt numComp = 0; 2054ea844a1aSMatthew Knepley 20559566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldName(s[i], fi, &name)); 20569566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldName(*supers, f, name)); 20579566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s[i], fi, &numComp)); 20589566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(*supers, f, numComp)); 2059b778fa18SValeria Barra for (ci = 0; ci < s[i]->numFieldComponents[fi]; ++ci) { 20609566063dSJacob Faibussowitsch PetscCall(PetscSectionGetComponentName(s[i], fi, ci, &name)); 20619566063dSJacob Faibussowitsch PetscCall(PetscSectionSetComponentName(*supers, f, ci, name)); 2062b778fa18SValeria Barra } 2063ea844a1aSMatthew Knepley } 2064ea844a1aSMatthew Knepley } 20659566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(*supers, pStart, pEnd)); 2066ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2067ea844a1aSMatthew Knepley PetscInt dof = 0, cdof = 0; 2068ea844a1aSMatthew Knepley 2069ea844a1aSMatthew Knepley for (i = 0, f = 0; i < len; ++i) { 2070ea844a1aSMatthew Knepley PetscInt nf, fi, pStarti, pEndi; 2071ea844a1aSMatthew Knepley PetscInt fdof = 0, cfdof = 0; 2072ea844a1aSMatthew Knepley 20739566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s[i], &nf)); 20749566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s[i], &pStarti, &pEndi)); 2075ea844a1aSMatthew Knepley if ((p < pStarti) || (p >= pEndi)) continue; 2076ea844a1aSMatthew Knepley for (fi = 0; fi < nf; ++fi, ++f) { 20779566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s[i], p, fi, &fdof)); 20789566063dSJacob Faibussowitsch PetscCall(PetscSectionAddFieldDof(*supers, p, f, fdof)); 20799566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s[i], p, fi, &cfdof)); 20809566063dSJacob Faibussowitsch if (cfdof) PetscCall(PetscSectionAddFieldConstraintDof(*supers, p, f, cfdof)); 2081ea844a1aSMatthew Knepley dof += fdof; 2082ea844a1aSMatthew Knepley cdof += cfdof; 2083ea844a1aSMatthew Knepley } 2084ea844a1aSMatthew Knepley } 20859566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(*supers, p, dof)); 20869566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetConstraintDof(*supers, p, cdof)); 2087ea844a1aSMatthew Knepley maxCdof = PetscMax(cdof, maxCdof); 2088ea844a1aSMatthew Knepley } 20899566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(*supers)); 2090ea844a1aSMatthew Knepley if (maxCdof) { 2091ea844a1aSMatthew Knepley PetscInt *indices; 2092ea844a1aSMatthew Knepley 20939566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(maxCdof, &indices)); 2094ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2095ea844a1aSMatthew Knepley PetscInt cdof; 2096ea844a1aSMatthew Knepley 20979566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(*supers, p, &cdof)); 2098ea844a1aSMatthew Knepley if (cdof) { 2099ea844a1aSMatthew Knepley PetscInt dof, numConst = 0, fOff = 0; 2100ea844a1aSMatthew Knepley 2101ea844a1aSMatthew Knepley for (i = 0, f = 0; i < len; ++i) { 2102ea844a1aSMatthew Knepley const PetscInt *oldIndices = NULL; 2103ea844a1aSMatthew Knepley PetscInt nf, fi, pStarti, pEndi, fdof, cfdof, fc; 2104ea844a1aSMatthew Knepley 21059566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s[i], &nf)); 21069566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s[i], &pStarti, &pEndi)); 2107ea844a1aSMatthew Knepley if ((p < pStarti) || (p >= pEndi)) continue; 2108ea844a1aSMatthew Knepley for (fi = 0; fi < nf; ++fi, ++f) { 21099566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s[i], p, fi, &fdof)); 21109566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s[i], p, fi, &cfdof)); 21119566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(s[i], p, fi, &oldIndices)); 2112fcd2503dSMatthew G. Knepley for (fc = 0; fc < cfdof; ++fc) indices[numConst + fc] = oldIndices[fc]; 21139566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldConstraintIndices(*supers, p, f, &indices[numConst])); 2114fcd2503dSMatthew G. Knepley for (fc = 0; fc < cfdof; ++fc) indices[numConst + fc] += fOff; 2115ea844a1aSMatthew Knepley numConst += cfdof; 2116ea844a1aSMatthew Knepley } 21179566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s[i], p, &dof)); 2118ea844a1aSMatthew Knepley fOff += dof; 2119ea844a1aSMatthew Knepley } 21209566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(*supers, p, indices)); 2121ea844a1aSMatthew Knepley } 2122ea844a1aSMatthew Knepley } 21239566063dSJacob Faibussowitsch PetscCall(PetscFree(indices)); 2124ea844a1aSMatthew Knepley } 21253ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2126ea844a1aSMatthew Knepley } 2127ea844a1aSMatthew Knepley 2128da8c939bSJacob Faibussowitsch static PetscErrorCode PetscSectionCreateSubplexSection_Private(PetscSection s, IS subpointMap, PetscBool renumberPoints, PetscSection *subs) 2129d71ae5a4SJacob Faibussowitsch { 2130ea844a1aSMatthew Knepley const PetscInt *points = NULL, *indices = NULL; 213141f23ed0SMatthew G. Knepley PetscInt numFields, f, c, numSubpoints = 0, pStart, pEnd, p, spStart, spEnd, subp; 2132ea844a1aSMatthew Knepley 2133ea844a1aSMatthew Knepley PetscFunctionBegin; 2134ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2135ea844a1aSMatthew Knepley PetscValidHeaderSpecific(subpointMap, IS_CLASSID, 2); 21364f572ea9SToby Isaac PetscAssertPointer(subs, 4); 21379566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s, &numFields)); 21389566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), subs)); 21399566063dSJacob Faibussowitsch if (numFields) PetscCall(PetscSectionSetNumFields(*subs, numFields)); 2140ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 2141ea844a1aSMatthew Knepley const char *name = NULL; 2142ea844a1aSMatthew Knepley PetscInt numComp = 0; 2143ea844a1aSMatthew Knepley 21449566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldName(s, f, &name)); 21459566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldName(*subs, f, name)); 21469566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s, f, &numComp)); 21479566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(*subs, f, numComp)); 2148b778fa18SValeria Barra for (c = 0; c < s->numFieldComponents[f]; ++c) { 21499566063dSJacob Faibussowitsch PetscCall(PetscSectionGetComponentName(s, f, c, &name)); 21509566063dSJacob Faibussowitsch PetscCall(PetscSectionSetComponentName(*subs, f, c, name)); 2151b778fa18SValeria Barra } 2152ea844a1aSMatthew Knepley } 2153ea844a1aSMatthew Knepley /* For right now, we do not try to squeeze the subchart */ 2154ea844a1aSMatthew Knepley if (subpointMap) { 21559566063dSJacob Faibussowitsch PetscCall(ISGetSize(subpointMap, &numSubpoints)); 21569566063dSJacob Faibussowitsch PetscCall(ISGetIndices(subpointMap, &points)); 2157ea844a1aSMatthew Knepley } 21589566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 215941f23ed0SMatthew G. Knepley if (renumberPoints) { 216041f23ed0SMatthew G. Knepley spStart = 0; 216141f23ed0SMatthew G. Knepley spEnd = numSubpoints; 216241f23ed0SMatthew G. Knepley } else { 216341f23ed0SMatthew G. Knepley PetscCall(ISGetMinMax(subpointMap, &spStart, &spEnd)); 216441f23ed0SMatthew G. Knepley ++spEnd; 216541f23ed0SMatthew G. Knepley } 216641f23ed0SMatthew G. Knepley PetscCall(PetscSectionSetChart(*subs, spStart, spEnd)); 2167ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2168ea844a1aSMatthew Knepley PetscInt dof, cdof, fdof = 0, cfdof = 0; 2169ea844a1aSMatthew Knepley 21709566063dSJacob Faibussowitsch PetscCall(PetscFindInt(p, numSubpoints, points, &subp)); 2171ea844a1aSMatthew Knepley if (subp < 0) continue; 217241f23ed0SMatthew G. Knepley if (!renumberPoints) subp = p; 2173ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 21749566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, f, &fdof)); 21759566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldDof(*subs, subp, f, fdof)); 21769566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, f, &cfdof)); 21779566063dSJacob Faibussowitsch if (cfdof) PetscCall(PetscSectionSetFieldConstraintDof(*subs, subp, f, cfdof)); 2178ea844a1aSMatthew Knepley } 21799566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 21809566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(*subs, subp, dof)); 21819566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof)); 21829566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetConstraintDof(*subs, subp, cdof)); 2183ea844a1aSMatthew Knepley } 21849566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(*subs)); 2185ea844a1aSMatthew Knepley /* Change offsets to original offsets */ 2186ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2187ea844a1aSMatthew Knepley PetscInt off, foff = 0; 2188ea844a1aSMatthew Knepley 21899566063dSJacob Faibussowitsch PetscCall(PetscFindInt(p, numSubpoints, points, &subp)); 2190ea844a1aSMatthew Knepley if (subp < 0) continue; 219141f23ed0SMatthew G. Knepley if (!renumberPoints) subp = p; 2192ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 21939566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldOffset(s, p, f, &foff)); 21949566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldOffset(*subs, subp, f, foff)); 2195ea844a1aSMatthew Knepley } 21969566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s, p, &off)); 21979566063dSJacob Faibussowitsch PetscCall(PetscSectionSetOffset(*subs, subp, off)); 2198ea844a1aSMatthew Knepley } 2199ea844a1aSMatthew Knepley /* Copy constraint indices */ 220041f23ed0SMatthew G. Knepley for (subp = spStart; subp < spEnd; ++subp) { 2201ea844a1aSMatthew Knepley PetscInt cdof; 2202ea844a1aSMatthew Knepley 22039566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(*subs, subp, &cdof)); 2204ea844a1aSMatthew Knepley if (cdof) { 2205ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 220641f23ed0SMatthew G. Knepley PetscCall(PetscSectionGetFieldConstraintIndices(s, points[subp - spStart], f, &indices)); 22079566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldConstraintIndices(*subs, subp, f, indices)); 2208ea844a1aSMatthew Knepley } 220941f23ed0SMatthew G. Knepley PetscCall(PetscSectionGetConstraintIndices(s, points[subp - spStart], &indices)); 22109566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(*subs, subp, indices)); 2211ea844a1aSMatthew Knepley } 2212ea844a1aSMatthew Knepley } 22139566063dSJacob Faibussowitsch if (subpointMap) PetscCall(ISRestoreIndices(subpointMap, &points)); 22143ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2215ea844a1aSMatthew Knepley } 2216ea844a1aSMatthew Knepley 221741f23ed0SMatthew G. Knepley /*@ 221841f23ed0SMatthew G. Knepley PetscSectionCreateSubmeshSection - Create a new, smaller section with support on the submesh 221941f23ed0SMatthew G. Knepley 2220c3339decSBarry Smith Collective 222141f23ed0SMatthew G. Knepley 222241f23ed0SMatthew G. Knepley Input Parameters: 2223cab54364SBarry Smith + s - the `PetscSection` 222441f23ed0SMatthew G. Knepley - subpointMap - a sorted list of points in the original mesh which are in the submesh 222541f23ed0SMatthew G. Knepley 222641f23ed0SMatthew G. Knepley Output Parameter: 222741f23ed0SMatthew G. Knepley . subs - the subsection 222841f23ed0SMatthew G. Knepley 2229cab54364SBarry Smith Level: advanced 2230cab54364SBarry Smith 2231583308b6SBarry Smith Notes: 2232583308b6SBarry Smith The points are renumbered from 0, and the section offsets now refer to a new, smaller vector. That is the chart of `subs` is `[0,sizeof(subpointmap))` 2233583308b6SBarry Smith 223420662ed9SBarry Smith Compare this with `PetscSectionCreateSubdomainSection()` that does not map the points numbers to start at zero but leaves them as before 223541f23ed0SMatthew G. Knepley 223638b5cf2dSJacob Faibussowitsch Developer Notes: 223720662ed9SBarry Smith The use of the term Submesh is confusing and needs clarification, it is not specific to meshes. It appears to be just a subset of the chart of the original `PetscSection` 223841f23ed0SMatthew G. Knepley 2239cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreateSubdomainSection()`, `PetscSectionCreateSubsection()`, `DMPlexGetSubpointMap()`, `PetscSectionCreate()` 224041f23ed0SMatthew G. Knepley @*/ 2241d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateSubmeshSection(PetscSection s, IS subpointMap, PetscSection *subs) 2242d71ae5a4SJacob Faibussowitsch { 224341f23ed0SMatthew G. Knepley PetscFunctionBegin; 2244da8c939bSJacob Faibussowitsch PetscCall(PetscSectionCreateSubplexSection_Private(s, subpointMap, PETSC_TRUE, subs)); 22453ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 224641f23ed0SMatthew G. Knepley } 224741f23ed0SMatthew G. Knepley 224841f23ed0SMatthew G. Knepley /*@ 224941f23ed0SMatthew G. Knepley PetscSectionCreateSubdomainSection - Create a new, smaller section with support on a subdomain of the mesh 225041f23ed0SMatthew G. Knepley 2251c3339decSBarry Smith Collective 225241f23ed0SMatthew G. Knepley 225341f23ed0SMatthew G. Knepley Input Parameters: 2254cab54364SBarry Smith + s - the `PetscSection` 225541f23ed0SMatthew G. Knepley - subpointMap - a sorted list of points in the original mesh which are in the subdomain 225641f23ed0SMatthew G. Knepley 225741f23ed0SMatthew G. Knepley Output Parameter: 225841f23ed0SMatthew G. Knepley . subs - the subsection 225941f23ed0SMatthew G. Knepley 2260cab54364SBarry Smith Level: advanced 2261cab54364SBarry Smith 2262583308b6SBarry Smith Notes: 2263583308b6SBarry Smith The point numbers remain the same as in the larger `PetscSection`, but the section offsets now refer to a new, smaller vector. The chart of `subs` 2264583308b6SBarry Smith is `[min(subpointMap),max(subpointMap)+1)` 2265583308b6SBarry Smith 226620662ed9SBarry Smith Compare this with `PetscSectionCreateSubmeshSection()` that maps the point numbers to start at zero 226741f23ed0SMatthew G. Knepley 2268cab54364SBarry Smith Developer Notes: 226920662ed9SBarry Smith The use of the term Subdomain is unneeded and needs clarification, it is not specific to meshes. It appears to be just a subset of the chart of the original `PetscSection` 2270cab54364SBarry Smith 2271cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreateSubmeshSection()`, `PetscSectionCreateSubsection()`, `DMPlexGetSubpointMap()`, `PetscSectionCreate()` 227241f23ed0SMatthew G. Knepley @*/ 2273d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateSubdomainSection(PetscSection s, IS subpointMap, PetscSection *subs) 2274d71ae5a4SJacob Faibussowitsch { 227541f23ed0SMatthew G. Knepley PetscFunctionBegin; 2276da8c939bSJacob Faibussowitsch PetscCall(PetscSectionCreateSubplexSection_Private(s, subpointMap, PETSC_FALSE, subs)); 22773ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 227841f23ed0SMatthew G. Knepley } 227941f23ed0SMatthew G. Knepley 2280d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscSectionView_ASCII(PetscSection s, PetscViewer viewer) 2281d71ae5a4SJacob Faibussowitsch { 2282ea844a1aSMatthew Knepley PetscInt p; 2283ea844a1aSMatthew Knepley PetscMPIInt rank; 2284ea844a1aSMatthew Knepley 2285ea844a1aSMatthew Knepley PetscFunctionBegin; 22869566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_rank(PetscObjectComm((PetscObject)viewer), &rank)); 22879566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushSynchronized(viewer)); 22889566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "Process %d:\n", rank)); 2289ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) { 2290ea844a1aSMatthew Knepley if ((s->bc) && (s->bc->atlasDof[p] > 0)) { 2291ea844a1aSMatthew Knepley PetscInt b; 2292ea844a1aSMatthew Knepley 22939566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " (%4" PetscInt_FMT ") dim %2" PetscInt_FMT " offset %3" PetscInt_FMT " constrained", p + s->pStart, s->atlasDof[p], s->atlasOff[p])); 2294083401c6SMatthew G. Knepley if (s->bcIndices) { 229548a46eb9SPierre Jolivet for (b = 0; b < s->bc->atlasDof[p]; ++b) PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " %" PetscInt_FMT, s->bcIndices[s->bc->atlasOff[p] + b])); 2296083401c6SMatthew G. Knepley } 22979566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "\n")); 2298ea844a1aSMatthew Knepley } else { 22999566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " (%4" PetscInt_FMT ") dim %2" PetscInt_FMT " offset %3" PetscInt_FMT "\n", p + s->pStart, s->atlasDof[p], s->atlasOff[p])); 2300ea844a1aSMatthew Knepley } 2301ea844a1aSMatthew Knepley } 23029566063dSJacob Faibussowitsch PetscCall(PetscViewerFlush(viewer)); 23039566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPopSynchronized(viewer)); 2304ea844a1aSMatthew Knepley if (s->sym) { 23059566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushTab(viewer)); 23069566063dSJacob Faibussowitsch PetscCall(PetscSectionSymView(s->sym, viewer)); 23079566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPopTab(viewer)); 2308ea844a1aSMatthew Knepley } 23093ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2310ea844a1aSMatthew Knepley } 2311ea844a1aSMatthew Knepley 2312ea844a1aSMatthew Knepley /*@C 2313cab54364SBarry Smith PetscSectionViewFromOptions - View the `PetscSection` based on values in the options database 2314fe2efc57SMark 231540750d41SVaclav Hapla Collective 2316fe2efc57SMark 2317fe2efc57SMark Input Parameters: 231820662ed9SBarry Smith + A - the `PetscSection` object to view 2319cab54364SBarry Smith . obj - Optional object that provides the options prefix used for the options 2320736c3998SJose E. Roman - name - command line option 2321fe2efc57SMark 2322fe2efc57SMark Level: intermediate 2323cab54364SBarry Smith 232420662ed9SBarry Smith Note: 232520662ed9SBarry Smith See `PetscObjectViewFromOptions()` for available values of `PetscViewer` and `PetscViewerFormat` 232620662ed9SBarry Smith 2327cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionView`, `PetscObjectViewFromOptions()`, `PetscSectionCreate()`, `PetscSectionView()` 2328fe2efc57SMark @*/ 2329d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionViewFromOptions(PetscSection A, PetscObject obj, const char name[]) 2330d71ae5a4SJacob Faibussowitsch { 2331fe2efc57SMark PetscFunctionBegin; 2332fe2efc57SMark PetscValidHeaderSpecific(A, PETSC_SECTION_CLASSID, 1); 23339566063dSJacob Faibussowitsch PetscCall(PetscObjectViewFromOptions((PetscObject)A, obj, name)); 23343ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2335fe2efc57SMark } 2336fe2efc57SMark 2337fe2efc57SMark /*@C 2338cab54364SBarry Smith PetscSectionView - Views a `PetscSection` 2339ea844a1aSMatthew Knepley 234040750d41SVaclav Hapla Collective 2341ea844a1aSMatthew Knepley 2342ea844a1aSMatthew Knepley Input Parameters: 2343cab54364SBarry Smith + s - the `PetscSection` object to view 234438b5cf2dSJacob Faibussowitsch - viewer - the viewer 2345ea844a1aSMatthew Knepley 2346cab54364SBarry Smith Level: beginner 2347cab54364SBarry Smith 23481ddd528eSksagiyam Note: 2349cab54364SBarry Smith `PetscSectionView()`, when viewer is of type `PETSCVIEWERHDF5`, only saves 23501ddd528eSksagiyam distribution independent data, such as dofs, offsets, constraint dofs, 23511ddd528eSksagiyam and constraint indices. Points that have negative dofs, for instance, 23521ddd528eSksagiyam are not saved as they represent points owned by other processes. 23531ddd528eSksagiyam Point numbering and rank assignment is currently not stored. 2354cab54364SBarry Smith The saved section can be loaded with `PetscSectionLoad()`. 23551ddd528eSksagiyam 2356cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionDestroy()`, `PetscSectionLoad()`, `PetscViewer` 2357ea844a1aSMatthew Knepley @*/ 2358d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionView(PetscSection s, PetscViewer viewer) 2359d71ae5a4SJacob Faibussowitsch { 23601ddd528eSksagiyam PetscBool isascii, ishdf5; 2361ea844a1aSMatthew Knepley PetscInt f; 2362ea844a1aSMatthew Knepley 2363ea844a1aSMatthew Knepley PetscFunctionBegin; 2364ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 23659566063dSJacob Faibussowitsch if (!viewer) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)s), &viewer)); 2366ea844a1aSMatthew Knepley PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2); 23679566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii)); 23689566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERHDF5, &ishdf5)); 2369ea844a1aSMatthew Knepley if (isascii) { 23709566063dSJacob Faibussowitsch PetscCall(PetscObjectPrintClassNamePrefixType((PetscObject)s, viewer)); 2371ea844a1aSMatthew Knepley if (s->numFields) { 23729566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT " fields\n", s->numFields)); 2373ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) { 23749566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, " field %" PetscInt_FMT " with %" PetscInt_FMT " components\n", f, s->numFieldComponents[f])); 23759566063dSJacob Faibussowitsch PetscCall(PetscSectionView_ASCII(s->field[f], viewer)); 2376ea844a1aSMatthew Knepley } 2377ea844a1aSMatthew Knepley } else { 23789566063dSJacob Faibussowitsch PetscCall(PetscSectionView_ASCII(s, viewer)); 2379ea844a1aSMatthew Knepley } 23801ddd528eSksagiyam } else if (ishdf5) { 23811ddd528eSksagiyam #if PetscDefined(HAVE_HDF5) 23829566063dSJacob Faibussowitsch PetscCall(PetscSectionView_HDF5_Internal(s, viewer)); 23831ddd528eSksagiyam #else 23841ddd528eSksagiyam SETERRQ(PetscObjectComm((PetscObject)s), PETSC_ERR_SUP, "HDF5 not supported in this build.\nPlease reconfigure using --download-hdf5"); 23851ddd528eSksagiyam #endif 2386ea844a1aSMatthew Knepley } 23873ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2388ea844a1aSMatthew Knepley } 2389ea844a1aSMatthew Knepley 2390fde5e3acSksagiyam /*@C 2391cab54364SBarry Smith PetscSectionLoad - Loads a `PetscSection` 2392fde5e3acSksagiyam 239340750d41SVaclav Hapla Collective 2394fde5e3acSksagiyam 2395fde5e3acSksagiyam Input Parameters: 2396cab54364SBarry Smith + s - the `PetscSection` object to load 239738b5cf2dSJacob Faibussowitsch - viewer - the viewer 2398fde5e3acSksagiyam 2399cab54364SBarry Smith Level: beginner 2400cab54364SBarry Smith 2401fde5e3acSksagiyam Note: 2402cab54364SBarry Smith `PetscSectionLoad()`, when viewer is of type `PETSCVIEWERHDF5`, loads 2403cab54364SBarry Smith a section saved with `PetscSectionView()`. The number of processes 2404fde5e3acSksagiyam used here (N) does not need to be the same as that used when saving. 2405fde5e3acSksagiyam After calling this function, the chart of s on rank i will be set 2406fde5e3acSksagiyam to [0, E_i), where \sum_{i=0}^{N-1}E_i equals to the total number of 2407fde5e3acSksagiyam saved section points. 2408fde5e3acSksagiyam 2409cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionDestroy()`, `PetscSectionView()` 2410fde5e3acSksagiyam @*/ 2411d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionLoad(PetscSection s, PetscViewer viewer) 2412d71ae5a4SJacob Faibussowitsch { 2413fde5e3acSksagiyam PetscBool ishdf5; 2414fde5e3acSksagiyam 2415fde5e3acSksagiyam PetscFunctionBegin; 2416fde5e3acSksagiyam PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2417fde5e3acSksagiyam PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2); 24189566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERHDF5, &ishdf5)); 2419fde5e3acSksagiyam if (ishdf5) { 2420fde5e3acSksagiyam #if PetscDefined(HAVE_HDF5) 24219566063dSJacob Faibussowitsch PetscCall(PetscSectionLoad_HDF5_Internal(s, viewer)); 24223ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2423fde5e3acSksagiyam #else 2424fde5e3acSksagiyam SETERRQ(PetscObjectComm((PetscObject)s), PETSC_ERR_SUP, "HDF5 not supported in this build.\nPlease reconfigure using --download-hdf5"); 2425fde5e3acSksagiyam #endif 242698921bdaSJacob Faibussowitsch } else SETERRQ(PetscObjectComm((PetscObject)s), PETSC_ERR_SUP, "Viewer type %s not yet supported for PetscSection loading", ((PetscObject)viewer)->type_name); 2427fde5e3acSksagiyam } 2428fde5e3acSksagiyam 2429d4a1ad33SMatthew G. Knepley /*@ 2430d4a1ad33SMatthew G. Knepley PetscSectionResetClosurePermutation - Remove any existing closure permutation 2431d4a1ad33SMatthew G. Knepley 2432d4a1ad33SMatthew G. Knepley Input Parameter: 2433*e8e188d2SZach Atkins . section - The `PetscSection` 2434d4a1ad33SMatthew G. Knepley 2435d4a1ad33SMatthew G. Knepley Level: intermediate 2436d4a1ad33SMatthew G. Knepley 2437*e8e188d2SZach Atkins .seealso: `PetscSectionSetClosurePermutation()`, `PetscSectionSetClosureIndex()`, `PetscSectionReset()` 2438d4a1ad33SMatthew G. Knepley @*/ 2439d4a1ad33SMatthew G. Knepley PetscErrorCode PetscSectionResetClosurePermutation(PetscSection section) 2440d71ae5a4SJacob Faibussowitsch { 2441c459fbc1SJed Brown PetscSectionClosurePermVal clVal; 2442c459fbc1SJed Brown 2443c459fbc1SJed Brown PetscFunctionBegin; 24443ba16761SJacob Faibussowitsch if (!section->clHash) PetscFunctionReturn(PETSC_SUCCESS); 2445c459fbc1SJed Brown kh_foreach_value(section->clHash, clVal, { 24469566063dSJacob Faibussowitsch PetscCall(PetscFree(clVal.perm)); 24479566063dSJacob Faibussowitsch PetscCall(PetscFree(clVal.invPerm)); 2448c459fbc1SJed Brown }); 2449c459fbc1SJed Brown kh_destroy(ClPerm, section->clHash); 2450c459fbc1SJed Brown section->clHash = NULL; 24513ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2452c459fbc1SJed Brown } 2453c459fbc1SJed Brown 2454ea844a1aSMatthew Knepley /*@ 2455583308b6SBarry Smith PetscSectionReset - Frees all section data, the section is then as if `PetscSectionCreate()` had just been called. 2456ea844a1aSMatthew Knepley 245740750d41SVaclav Hapla Not Collective 2458ea844a1aSMatthew Knepley 24592fe279fdSBarry Smith Input Parameter: 2460cab54364SBarry Smith . s - the `PetscSection` 2461ea844a1aSMatthew Knepley 2462ea844a1aSMatthew Knepley Level: beginner 2463ea844a1aSMatthew Knepley 2464cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()` 2465ea844a1aSMatthew Knepley @*/ 2466d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionReset(PetscSection s) 2467d71ae5a4SJacob Faibussowitsch { 2468b778fa18SValeria Barra PetscInt f, c; 2469ea844a1aSMatthew Knepley 2470ea844a1aSMatthew Knepley PetscFunctionBegin; 2471ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2472ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) { 24739566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->field[f])); 24749566063dSJacob Faibussowitsch PetscCall(PetscFree(s->fieldNames[f])); 247548a46eb9SPierre Jolivet for (c = 0; c < s->numFieldComponents[f]; ++c) PetscCall(PetscFree(s->compNames[f][c])); 24769566063dSJacob Faibussowitsch PetscCall(PetscFree(s->compNames[f])); 2477ea844a1aSMatthew Knepley } 24789566063dSJacob Faibussowitsch PetscCall(PetscFree(s->numFieldComponents)); 24799566063dSJacob Faibussowitsch PetscCall(PetscFree(s->fieldNames)); 24809566063dSJacob Faibussowitsch PetscCall(PetscFree(s->compNames)); 24819566063dSJacob Faibussowitsch PetscCall(PetscFree(s->field)); 24829566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->bc)); 24839566063dSJacob Faibussowitsch PetscCall(PetscFree(s->bcIndices)); 24849566063dSJacob Faibussowitsch PetscCall(PetscFree2(s->atlasDof, s->atlasOff)); 24859566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->clSection)); 24869566063dSJacob Faibussowitsch PetscCall(ISDestroy(&s->clPoints)); 24879566063dSJacob Faibussowitsch PetscCall(ISDestroy(&s->perm)); 2488d4a1ad33SMatthew G. Knepley PetscCall(PetscSectionResetClosurePermutation(s)); 24899566063dSJacob Faibussowitsch PetscCall(PetscSectionSymDestroy(&s->sym)); 24909566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->clSection)); 24919566063dSJacob Faibussowitsch PetscCall(ISDestroy(&s->clPoints)); 249269c11d05SVaclav Hapla PetscCall(PetscSectionInvalidateMaxDof_Internal(s)); 2493ea844a1aSMatthew Knepley s->pStart = -1; 2494ea844a1aSMatthew Knepley s->pEnd = -1; 2495ea844a1aSMatthew Knepley s->maxDof = 0; 2496ea844a1aSMatthew Knepley s->setup = PETSC_FALSE; 2497ea844a1aSMatthew Knepley s->numFields = 0; 2498ea844a1aSMatthew Knepley s->clObj = NULL; 24993ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2500ea844a1aSMatthew Knepley } 2501ea844a1aSMatthew Knepley 2502ea844a1aSMatthew Knepley /*@ 2503583308b6SBarry Smith PetscSectionDestroy - Frees a `PetscSection` 2504ea844a1aSMatthew Knepley 250540750d41SVaclav Hapla Not Collective 2506ea844a1aSMatthew Knepley 25072fe279fdSBarry Smith Input Parameter: 2508cab54364SBarry Smith . s - the `PetscSection` 2509ea844a1aSMatthew Knepley 2510ea844a1aSMatthew Knepley Level: beginner 2511ea844a1aSMatthew Knepley 2512cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionReset()` 2513ea844a1aSMatthew Knepley @*/ 2514d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionDestroy(PetscSection *s) 2515d71ae5a4SJacob Faibussowitsch { 2516ea844a1aSMatthew Knepley PetscFunctionBegin; 25173ba16761SJacob Faibussowitsch if (!*s) PetscFunctionReturn(PETSC_SUCCESS); 251862f17a49SStefano Zampini PetscValidHeaderSpecific(*s, PETSC_SECTION_CLASSID, 1); 2519ea844a1aSMatthew Knepley if (--((PetscObject)(*s))->refct > 0) { 2520ea844a1aSMatthew Knepley *s = NULL; 25213ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2522ea844a1aSMatthew Knepley } 25239566063dSJacob Faibussowitsch PetscCall(PetscSectionReset(*s)); 25249566063dSJacob Faibussowitsch PetscCall(PetscHeaderDestroy(s)); 25253ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2526ea844a1aSMatthew Knepley } 2527ea844a1aSMatthew Knepley 2528da8c939bSJacob Faibussowitsch static PetscErrorCode VecIntGetValuesSection_Private(const PetscInt *baseArray, PetscSection s, PetscInt point, const PetscInt **values) 2529d71ae5a4SJacob Faibussowitsch { 2530ea844a1aSMatthew Knepley const PetscInt p = point - s->pStart; 2531ea844a1aSMatthew Knepley 2532ea844a1aSMatthew Knepley PetscFunctionBegin; 2533ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 2); 2534ea844a1aSMatthew Knepley *values = &baseArray[s->atlasOff[p]]; 25353ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2536ea844a1aSMatthew Knepley } 2537ea844a1aSMatthew Knepley 2538da8c939bSJacob Faibussowitsch static PetscErrorCode VecIntSetValuesSection_Private(PetscInt *baseArray, PetscSection s, PetscInt point, const PetscInt values[], InsertMode mode) 2539d71ae5a4SJacob Faibussowitsch { 2540ea844a1aSMatthew Knepley PetscInt *array; 2541ea844a1aSMatthew Knepley const PetscInt p = point - s->pStart; 2542ea844a1aSMatthew Knepley const PetscInt orientation = 0; /* Needs to be included for use in closure operations */ 2543ea844a1aSMatthew Knepley PetscInt cDim = 0; 2544ea844a1aSMatthew Knepley 2545ea844a1aSMatthew Knepley PetscFunctionBegin; 2546ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 2); 25479566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cDim)); 2548ea844a1aSMatthew Knepley array = &baseArray[s->atlasOff[p]]; 2549ea844a1aSMatthew Knepley if (!cDim) { 2550ea844a1aSMatthew Knepley if (orientation >= 0) { 2551ea844a1aSMatthew Knepley const PetscInt dim = s->atlasDof[p]; 2552ea844a1aSMatthew Knepley PetscInt i; 2553ea844a1aSMatthew Knepley 2554ea844a1aSMatthew Knepley if (mode == INSERT_VALUES) { 2555ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) array[i] = values[i]; 2556ea844a1aSMatthew Knepley } else { 2557ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) array[i] += values[i]; 2558ea844a1aSMatthew Knepley } 2559ea844a1aSMatthew Knepley } else { 2560ea844a1aSMatthew Knepley PetscInt offset = 0; 2561ea844a1aSMatthew Knepley PetscInt j = -1, field, i; 2562ea844a1aSMatthew Knepley 2563ea844a1aSMatthew Knepley for (field = 0; field < s->numFields; ++field) { 2564ea844a1aSMatthew Knepley const PetscInt dim = s->field[field]->atlasDof[p]; 2565ea844a1aSMatthew Knepley 2566ea844a1aSMatthew Knepley for (i = dim - 1; i >= 0; --i) array[++j] = values[i + offset]; 2567ea844a1aSMatthew Knepley offset += dim; 2568ea844a1aSMatthew Knepley } 2569ea844a1aSMatthew Knepley } 2570ea844a1aSMatthew Knepley } else { 2571ea844a1aSMatthew Knepley if (orientation >= 0) { 2572ea844a1aSMatthew Knepley const PetscInt dim = s->atlasDof[p]; 2573ea844a1aSMatthew Knepley PetscInt cInd = 0, i; 2574ea844a1aSMatthew Knepley const PetscInt *cDof; 2575ea844a1aSMatthew Knepley 25769566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s, point, &cDof)); 2577ea844a1aSMatthew Knepley if (mode == INSERT_VALUES) { 2578ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) { 25799371c9d4SSatish Balay if ((cInd < cDim) && (i == cDof[cInd])) { 25809371c9d4SSatish Balay ++cInd; 25819371c9d4SSatish Balay continue; 25829371c9d4SSatish Balay } 2583ea844a1aSMatthew Knepley array[i] = values[i]; 2584ea844a1aSMatthew Knepley } 2585ea844a1aSMatthew Knepley } else { 2586ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) { 25879371c9d4SSatish Balay if ((cInd < cDim) && (i == cDof[cInd])) { 25889371c9d4SSatish Balay ++cInd; 25899371c9d4SSatish Balay continue; 25909371c9d4SSatish Balay } 2591ea844a1aSMatthew Knepley array[i] += values[i]; 2592ea844a1aSMatthew Knepley } 2593ea844a1aSMatthew Knepley } 2594ea844a1aSMatthew Knepley } else { 2595ea844a1aSMatthew Knepley const PetscInt *cDof; 2596ea844a1aSMatthew Knepley PetscInt offset = 0; 2597ea844a1aSMatthew Knepley PetscInt cOffset = 0; 2598ea844a1aSMatthew Knepley PetscInt j = 0, field; 2599ea844a1aSMatthew Knepley 26009566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s, point, &cDof)); 2601ea844a1aSMatthew Knepley for (field = 0; field < s->numFields; ++field) { 2602ea844a1aSMatthew Knepley const PetscInt dim = s->field[field]->atlasDof[p]; /* PetscSectionGetFieldDof() */ 2603ea844a1aSMatthew Knepley const PetscInt tDim = s->field[field]->bc->atlasDof[p]; /* PetscSectionGetFieldConstraintDof() */ 2604ea844a1aSMatthew Knepley const PetscInt sDim = dim - tDim; 2605ea844a1aSMatthew Knepley PetscInt cInd = 0, i, k; 2606ea844a1aSMatthew Knepley 2607ea844a1aSMatthew Knepley for (i = 0, k = dim + offset - 1; i < dim; ++i, ++j, --k) { 26089371c9d4SSatish Balay if ((cInd < sDim) && (j == cDof[cInd + cOffset])) { 26099371c9d4SSatish Balay ++cInd; 26109371c9d4SSatish Balay continue; 26119371c9d4SSatish Balay } 2612ea844a1aSMatthew Knepley array[j] = values[k]; 2613ea844a1aSMatthew Knepley } 2614ea844a1aSMatthew Knepley offset += dim; 2615ea844a1aSMatthew Knepley cOffset += dim - tDim; 2616ea844a1aSMatthew Knepley } 2617ea844a1aSMatthew Knepley } 2618ea844a1aSMatthew Knepley } 26193ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2620ea844a1aSMatthew Knepley } 2621ea844a1aSMatthew Knepley 2622ea844a1aSMatthew Knepley /*@C 262320662ed9SBarry Smith PetscSectionHasConstraints - Determine whether a `PetscSection` has constrained dofs 2624ea844a1aSMatthew Knepley 262540750d41SVaclav Hapla Not Collective 2626ea844a1aSMatthew Knepley 2627ea844a1aSMatthew Knepley Input Parameter: 2628cab54364SBarry Smith . s - The `PetscSection` 2629ea844a1aSMatthew Knepley 2630ea844a1aSMatthew Knepley Output Parameter: 2631ea844a1aSMatthew Knepley . hasConstraints - flag indicating that the section has constrained dofs 2632ea844a1aSMatthew Knepley 2633ea844a1aSMatthew Knepley Level: intermediate 2634ea844a1aSMatthew Knepley 2635cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSetConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection` 2636ea844a1aSMatthew Knepley @*/ 2637d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionHasConstraints(PetscSection s, PetscBool *hasConstraints) 2638d71ae5a4SJacob Faibussowitsch { 2639ea844a1aSMatthew Knepley PetscFunctionBegin; 2640ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 26414f572ea9SToby Isaac PetscAssertPointer(hasConstraints, 2); 2642ea844a1aSMatthew Knepley *hasConstraints = s->bc ? PETSC_TRUE : PETSC_FALSE; 26433ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2644ea844a1aSMatthew Knepley } 2645ea844a1aSMatthew Knepley 2646ea844a1aSMatthew Knepley /*@C 264720662ed9SBarry Smith PetscSectionGetConstraintIndices - Get the point dof numbers, in [0, dof), which are constrained for a given point 2648ea844a1aSMatthew Knepley 264940750d41SVaclav Hapla Not Collective 2650ea844a1aSMatthew Knepley 2651ea844a1aSMatthew Knepley Input Parameters: 2652cab54364SBarry Smith + s - The `PetscSection` 2653ea844a1aSMatthew Knepley - point - The point 2654ea844a1aSMatthew Knepley 2655ea844a1aSMatthew Knepley Output Parameter: 2656ea844a1aSMatthew Knepley . indices - The constrained dofs 2657ea844a1aSMatthew Knepley 2658ea844a1aSMatthew Knepley Level: intermediate 2659ea844a1aSMatthew Knepley 266038b5cf2dSJacob Faibussowitsch Fortran Notes: 266120662ed9SBarry Smith Use `PetscSectionGetConstraintIndicesF90()` and `PetscSectionRestoreConstraintIndicesF90()` 2662cab54364SBarry Smith 2663cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSetConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection` 2664ea844a1aSMatthew Knepley @*/ 2665d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetConstraintIndices(PetscSection s, PetscInt point, const PetscInt **indices) 2666d71ae5a4SJacob Faibussowitsch { 2667ea844a1aSMatthew Knepley PetscFunctionBegin; 2668ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2669ea844a1aSMatthew Knepley if (s->bc) { 2670da8c939bSJacob Faibussowitsch PetscCall(VecIntGetValuesSection_Private(s->bcIndices, s->bc, point, indices)); 2671ea844a1aSMatthew Knepley } else *indices = NULL; 26723ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2673ea844a1aSMatthew Knepley } 2674ea844a1aSMatthew Knepley 2675ea844a1aSMatthew Knepley /*@C 2676ea844a1aSMatthew Knepley PetscSectionSetConstraintIndices - Set the point dof numbers, in [0, dof), which are constrained 2677ea844a1aSMatthew Knepley 267840750d41SVaclav Hapla Not Collective 2679ea844a1aSMatthew Knepley 2680ea844a1aSMatthew Knepley Input Parameters: 2681cab54364SBarry Smith + s - The `PetscSection` 2682ea844a1aSMatthew Knepley . point - The point 2683ea844a1aSMatthew Knepley - indices - The constrained dofs 2684ea844a1aSMatthew Knepley 2685ea844a1aSMatthew Knepley Level: intermediate 2686ea844a1aSMatthew Knepley 268738b5cf2dSJacob Faibussowitsch Fortran Notes: 2688cab54364SBarry Smith Use `PetscSectionSetConstraintIndicesF90()` 2689cab54364SBarry Smith 2690cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionGetConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection` 2691ea844a1aSMatthew Knepley @*/ 2692d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetConstraintIndices(PetscSection s, PetscInt point, const PetscInt indices[]) 2693d71ae5a4SJacob Faibussowitsch { 2694ea844a1aSMatthew Knepley PetscFunctionBegin; 2695ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2696ea844a1aSMatthew Knepley if (s->bc) { 2697d57bb9dbSMatthew G. Knepley const PetscInt dof = s->atlasDof[point]; 2698d57bb9dbSMatthew G. Knepley const PetscInt cdof = s->bc->atlasDof[point]; 2699d57bb9dbSMatthew G. Knepley PetscInt d; 2700d57bb9dbSMatthew G. Knepley 2701ad540459SPierre Jolivet for (d = 0; d < cdof; ++d) PetscCheck(indices[d] < dof, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Point %" PetscInt_FMT " dof %" PetscInt_FMT ", invalid constraint index[%" PetscInt_FMT "]: %" PetscInt_FMT, point, dof, d, indices[d]); 2702da8c939bSJacob Faibussowitsch PetscCall(VecIntSetValuesSection_Private(s->bcIndices, s->bc, point, indices, INSERT_VALUES)); 2703ea844a1aSMatthew Knepley } 27043ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2705ea844a1aSMatthew Knepley } 2706ea844a1aSMatthew Knepley 2707ea844a1aSMatthew Knepley /*@C 2708ea844a1aSMatthew Knepley PetscSectionGetFieldConstraintIndices - Get the field dof numbers, in [0, fdof), which are constrained 2709ea844a1aSMatthew Knepley 271040750d41SVaclav Hapla Not Collective 2711ea844a1aSMatthew Knepley 2712ea844a1aSMatthew Knepley Input Parameters: 2713cab54364SBarry Smith + s - The `PetscSection` 2714ea844a1aSMatthew Knepley . field - The field number 2715ea844a1aSMatthew Knepley - point - The point 2716ea844a1aSMatthew Knepley 2717ea844a1aSMatthew Knepley Output Parameter: 27189759eb26SJed Brown . indices - The constrained dofs sorted in ascending order 2719ea844a1aSMatthew Knepley 2720ea844a1aSMatthew Knepley Level: intermediate 2721ea844a1aSMatthew Knepley 2722cab54364SBarry Smith Note: 2723cab54364SBarry Smith The indices array, which is provided by the caller, must have capacity to hold the number of constrained dofs, e.g., as returned by `PetscSectionGetConstraintDof()`. 2724cab54364SBarry Smith 272538b5cf2dSJacob Faibussowitsch Fortran Notes: 272620662ed9SBarry Smith Use `PetscSectionGetFieldConstraintIndicesF90()` and `PetscSectionRestoreFieldConstraintIndicesF90()` 2727cab54364SBarry Smith 2728cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSetFieldConstraintIndices()`, `PetscSectionGetConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection` 2729ea844a1aSMatthew Knepley @*/ 2730d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldConstraintIndices(PetscSection s, PetscInt point, PetscInt field, const PetscInt **indices) 2731d71ae5a4SJacob Faibussowitsch { 2732ea844a1aSMatthew Knepley PetscFunctionBegin; 2733ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 27344f572ea9SToby Isaac PetscAssertPointer(indices, 4); 27352abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 27369566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s->field[field], point, indices)); 27373ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2738ea844a1aSMatthew Knepley } 2739ea844a1aSMatthew Knepley 2740ea844a1aSMatthew Knepley /*@C 2741ea844a1aSMatthew Knepley PetscSectionSetFieldConstraintIndices - Set the field dof numbers, in [0, fdof), which are constrained 2742ea844a1aSMatthew Knepley 274340750d41SVaclav Hapla Not Collective 2744ea844a1aSMatthew Knepley 2745ea844a1aSMatthew Knepley Input Parameters: 2746cab54364SBarry Smith + s - The `PetscSection` 2747ea844a1aSMatthew Knepley . point - The point 2748ea844a1aSMatthew Knepley . field - The field number 2749ea844a1aSMatthew Knepley - indices - The constrained dofs 2750ea844a1aSMatthew Knepley 2751ea844a1aSMatthew Knepley Level: intermediate 2752ea844a1aSMatthew Knepley 275338b5cf2dSJacob Faibussowitsch Fortran Notes: 2754cab54364SBarry Smith Use `PetscSectionSetFieldConstraintIndicesF90()` 2755cab54364SBarry Smith 2756cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSetConstraintIndices()`, `PetscSectionGetFieldConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection` 2757ea844a1aSMatthew Knepley @*/ 2758d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldConstraintIndices(PetscSection s, PetscInt point, PetscInt field, const PetscInt indices[]) 2759d71ae5a4SJacob Faibussowitsch { 2760ea844a1aSMatthew Knepley PetscFunctionBegin; 2761ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 27622abc8c78SJacob Faibussowitsch if (PetscDefined(USE_DEBUG)) { 2763e2bfaee7SMatthew G. Knepley PetscInt nfdof; 27642abc8c78SJacob Faibussowitsch 27659566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, point, field, &nfdof)); 27664f572ea9SToby Isaac if (nfdof) PetscAssertPointer(indices, 4); 27672abc8c78SJacob Faibussowitsch } 27682abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 27699566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(s->field[field], point, indices)); 27703ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2771ea844a1aSMatthew Knepley } 2772ea844a1aSMatthew Knepley 2773ea844a1aSMatthew Knepley /*@ 2774ea844a1aSMatthew Knepley PetscSectionPermute - Reorder the section according to the input point permutation 2775ea844a1aSMatthew Knepley 277640750d41SVaclav Hapla Collective 2777ea844a1aSMatthew Knepley 2778d8d19677SJose E. Roman Input Parameters: 2779cab54364SBarry Smith + section - The `PetscSection` object 278038b5cf2dSJacob Faibussowitsch - permutation - The point permutation, old point p becomes new point perm[p] 2781ea844a1aSMatthew Knepley 2782ea844a1aSMatthew Knepley Output Parameter: 2783cab54364SBarry Smith . sectionNew - The permuted `PetscSection` 2784ea844a1aSMatthew Knepley 2785ea844a1aSMatthew Knepley Level: intermediate 2786ea844a1aSMatthew Knepley 2787583308b6SBarry Smith Note: 2788583308b6SBarry Smith The data and the access to the data via `PetscSectionGetFieldOffset()` and `PetscSectionGetOffset()` are both changed in `sectionNew` 2789583308b6SBarry Smith 2790583308b6SBarry Smith Compare to `PetscSectionSetPermutation()` 2791583308b6SBarry Smith 2792583308b6SBarry Smith .seealso: [PetscSection](sec_petscsection), `IS`, `PetscSection`, `MatPermute()`, `PetscSectionSetPermutation()` 2793ea844a1aSMatthew Knepley @*/ 2794d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionPermute(PetscSection section, IS permutation, PetscSection *sectionNew) 2795d71ae5a4SJacob Faibussowitsch { 2796ea844a1aSMatthew Knepley PetscSection s = section, sNew; 2797ea844a1aSMatthew Knepley const PetscInt *perm; 2798b778fa18SValeria Barra PetscInt numFields, f, c, numPoints, pStart, pEnd, p; 2799ea844a1aSMatthew Knepley 2800ea844a1aSMatthew Knepley PetscFunctionBegin; 2801ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 2802ea844a1aSMatthew Knepley PetscValidHeaderSpecific(permutation, IS_CLASSID, 2); 28034f572ea9SToby Isaac PetscAssertPointer(sectionNew, 3); 28049566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), &sNew)); 28059566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s, &numFields)); 28069566063dSJacob Faibussowitsch if (numFields) PetscCall(PetscSectionSetNumFields(sNew, numFields)); 2807ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 2808ea844a1aSMatthew Knepley const char *name; 2809ea844a1aSMatthew Knepley PetscInt numComp; 2810ea844a1aSMatthew Knepley 28119566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldName(s, f, &name)); 28129566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldName(sNew, f, name)); 28139566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s, f, &numComp)); 28149566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(sNew, f, numComp)); 2815b778fa18SValeria Barra for (c = 0; c < s->numFieldComponents[f]; ++c) { 28169566063dSJacob Faibussowitsch PetscCall(PetscSectionGetComponentName(s, f, c, &name)); 28179566063dSJacob Faibussowitsch PetscCall(PetscSectionSetComponentName(sNew, f, c, name)); 2818b778fa18SValeria Barra } 2819ea844a1aSMatthew Knepley } 28209566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(permutation, &numPoints)); 28219566063dSJacob Faibussowitsch PetscCall(ISGetIndices(permutation, &perm)); 28229566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 28239566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(sNew, pStart, pEnd)); 282408401ef6SPierre Jolivet PetscCheck(numPoints >= pEnd, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Permutation size %" PetscInt_FMT " is less than largest Section point %" PetscInt_FMT, numPoints, pEnd); 2825ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2826ea844a1aSMatthew Knepley PetscInt dof, cdof; 2827ea844a1aSMatthew Knepley 28289566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 28299566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(sNew, perm[p], dof)); 28309566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof)); 28319566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetConstraintDof(sNew, perm[p], cdof)); 2832ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 28339566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, f, &dof)); 28349566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldDof(sNew, perm[p], f, dof)); 28359566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, f, &cdof)); 28369566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetFieldConstraintDof(sNew, perm[p], f, cdof)); 2837ea844a1aSMatthew Knepley } 2838ea844a1aSMatthew Knepley } 28399566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(sNew)); 2840ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2841ea844a1aSMatthew Knepley const PetscInt *cind; 2842ea844a1aSMatthew Knepley PetscInt cdof; 2843ea844a1aSMatthew Knepley 28449566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof)); 2845ea844a1aSMatthew Knepley if (cdof) { 28469566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s, p, &cind)); 28479566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(sNew, perm[p], cind)); 2848ea844a1aSMatthew Knepley } 2849ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 28509566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, f, &cdof)); 2851ea844a1aSMatthew Knepley if (cdof) { 28529566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(s, p, f, &cind)); 28539566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldConstraintIndices(sNew, perm[p], f, cind)); 2854ea844a1aSMatthew Knepley } 2855ea844a1aSMatthew Knepley } 2856ea844a1aSMatthew Knepley } 28579566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(permutation, &perm)); 2858ea844a1aSMatthew Knepley *sectionNew = sNew; 28593ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2860ea844a1aSMatthew Knepley } 2861ea844a1aSMatthew Knepley 2862ea844a1aSMatthew Knepley /*@ 286320662ed9SBarry Smith PetscSectionSetClosureIndex - Create an internal data structure to speed up closure queries. 2864ea844a1aSMatthew Knepley 286540750d41SVaclav Hapla Collective 2866ea844a1aSMatthew Knepley 2867ea844a1aSMatthew Knepley Input Parameters: 2868cab54364SBarry Smith + section - The `PetscSection` 2869cab54364SBarry Smith . obj - A `PetscObject` which serves as the key for this index 2870cab54364SBarry Smith . clSection - `PetscSection` giving the size of the closure of each point 2871cab54364SBarry Smith - clPoints - `IS` giving the points in each closure 2872ea844a1aSMatthew Knepley 2873ea844a1aSMatthew Knepley Level: advanced 2874ea844a1aSMatthew Knepley 2875cab54364SBarry Smith Note: 287620662ed9SBarry Smith This function creates an internal map from each point to its closure. We compress out closure points with no dofs in this section. 287720662ed9SBarry Smith 287838b5cf2dSJacob Faibussowitsch Developer Notes: 287920662ed9SBarry Smith The information provided here is completely opaque 2880cab54364SBarry Smith 2881cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetClosureIndex()`, `DMPlexCreateClosureIndex()` 2882ea844a1aSMatthew Knepley @*/ 2883d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetClosureIndex(PetscSection section, PetscObject obj, PetscSection clSection, IS clPoints) 2884d71ae5a4SJacob Faibussowitsch { 2885ea844a1aSMatthew Knepley PetscFunctionBegin; 28863e03ebd8SStefano Zampini PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 28873e03ebd8SStefano Zampini PetscValidHeaderSpecific(clSection, PETSC_SECTION_CLASSID, 3); 28883e03ebd8SStefano Zampini PetscValidHeaderSpecific(clPoints, IS_CLASSID, 4); 2889d4a1ad33SMatthew G. Knepley if (section->clObj != obj) PetscCall(PetscSectionResetClosurePermutation(section)); 2890ea844a1aSMatthew Knepley section->clObj = obj; 28919566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)clSection)); 28929566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)clPoints)); 28939566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(§ion->clSection)); 28949566063dSJacob Faibussowitsch PetscCall(ISDestroy(§ion->clPoints)); 2895ea844a1aSMatthew Knepley section->clSection = clSection; 2896ea844a1aSMatthew Knepley section->clPoints = clPoints; 28973ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2898ea844a1aSMatthew Knepley } 2899ea844a1aSMatthew Knepley 2900ea844a1aSMatthew Knepley /*@ 2901cab54364SBarry Smith PetscSectionGetClosureIndex - Get the cache of points in the closure of each point in the section set with `PetscSectionSetClosureIndex()` 2902ea844a1aSMatthew Knepley 290340750d41SVaclav Hapla Collective 2904ea844a1aSMatthew Knepley 2905ea844a1aSMatthew Knepley Input Parameters: 2906cab54364SBarry Smith + section - The `PetscSection` 2907cab54364SBarry Smith - obj - A `PetscObject` which serves as the key for this index 2908ea844a1aSMatthew Knepley 2909ea844a1aSMatthew Knepley Output Parameters: 2910cab54364SBarry Smith + clSection - `PetscSection` giving the size of the closure of each point 2911cab54364SBarry Smith - clPoints - `IS` giving the points in each closure 2912ea844a1aSMatthew Knepley 2913ea844a1aSMatthew Knepley Level: advanced 2914ea844a1aSMatthew Knepley 2915cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSetClosureIndex()`, `DMPlexCreateClosureIndex()` 2916ea844a1aSMatthew Knepley @*/ 2917d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosureIndex(PetscSection section, PetscObject obj, PetscSection *clSection, IS *clPoints) 2918d71ae5a4SJacob Faibussowitsch { 2919ea844a1aSMatthew Knepley PetscFunctionBegin; 2920ea844a1aSMatthew Knepley if (section->clObj == obj) { 2921ea844a1aSMatthew Knepley if (clSection) *clSection = section->clSection; 2922ea844a1aSMatthew Knepley if (clPoints) *clPoints = section->clPoints; 2923ea844a1aSMatthew Knepley } else { 2924ea844a1aSMatthew Knepley if (clSection) *clSection = NULL; 2925ea844a1aSMatthew Knepley if (clPoints) *clPoints = NULL; 2926ea844a1aSMatthew Knepley } 29273ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2928ea844a1aSMatthew Knepley } 2929ea844a1aSMatthew Knepley 2930d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetClosurePermutation_Internal(PetscSection section, PetscObject obj, PetscInt depth, PetscInt clSize, PetscCopyMode mode, PetscInt *clPerm) 2931d71ae5a4SJacob Faibussowitsch { 2932ea844a1aSMatthew Knepley PetscInt i; 2933c459fbc1SJed Brown khiter_t iter; 2934c459fbc1SJed Brown int new_entry; 2935c459fbc1SJed Brown PetscSectionClosurePermKey key = {depth, clSize}; 2936c459fbc1SJed Brown PetscSectionClosurePermVal *val; 2937ea844a1aSMatthew Knepley 2938ea844a1aSMatthew Knepley PetscFunctionBegin; 2939ea844a1aSMatthew Knepley if (section->clObj != obj) { 29409566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(§ion->clSection)); 29419566063dSJacob Faibussowitsch PetscCall(ISDestroy(§ion->clPoints)); 2942ea844a1aSMatthew Knepley } 2943ea844a1aSMatthew Knepley section->clObj = obj; 29449566063dSJacob Faibussowitsch if (!section->clHash) PetscCall(PetscClPermCreate(§ion->clHash)); 2945c459fbc1SJed Brown iter = kh_put(ClPerm, section->clHash, key, &new_entry); 2946c459fbc1SJed Brown val = &kh_val(section->clHash, iter); 2947c459fbc1SJed Brown if (!new_entry) { 29489566063dSJacob Faibussowitsch PetscCall(PetscFree(val->perm)); 29499566063dSJacob Faibussowitsch PetscCall(PetscFree(val->invPerm)); 2950c459fbc1SJed Brown } 2951ea844a1aSMatthew Knepley if (mode == PETSC_COPY_VALUES) { 29529566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(clSize, &val->perm)); 29539566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(val->perm, clPerm, clSize)); 2954ea844a1aSMatthew Knepley } else if (mode == PETSC_OWN_POINTER) { 2955c459fbc1SJed Brown val->perm = clPerm; 2956ea844a1aSMatthew Knepley } else SETERRQ(PetscObjectComm(obj), PETSC_ERR_SUP, "Do not support borrowed arrays"); 29579566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(clSize, &val->invPerm)); 2958c459fbc1SJed Brown for (i = 0; i < clSize; ++i) val->invPerm[clPerm[i]] = i; 29593ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2960ea844a1aSMatthew Knepley } 2961ea844a1aSMatthew Knepley 2962ea844a1aSMatthew Knepley /*@ 2963c459fbc1SJed Brown PetscSectionSetClosurePermutation - Set the dof permutation for the closure of each cell in the section, meaning clPerm[newIndex] = oldIndex. 2964ea844a1aSMatthew Knepley 2965ea844a1aSMatthew Knepley Not Collective 2966ea844a1aSMatthew Knepley 2967ea844a1aSMatthew Knepley Input Parameters: 2968cab54364SBarry Smith + section - The `PetscSection` 2969cab54364SBarry Smith . obj - A `PetscObject` which serves as the key for this index (usually a `DM`) 2970c459fbc1SJed Brown . depth - Depth of points on which to apply the given permutation 2971ea844a1aSMatthew Knepley - perm - Permutation of the cell dof closure 2972ea844a1aSMatthew Knepley 2973cab54364SBarry Smith Level: intermediate 2974cab54364SBarry Smith 2975cab54364SBarry Smith Notes: 2976c459fbc1SJed Brown The specified permutation will only be applied to points at depth whose closure size matches the length of perm. In a 2977c459fbc1SJed Brown mixed-topology or variable-degree finite element space, this function can be called multiple times at each depth for 2978c459fbc1SJed Brown each topology and degree. 2979c459fbc1SJed Brown 2980c459fbc1SJed Brown This approach assumes that (depth, len(perm)) uniquely identifies the desired permutation; this might not be true for 2981c459fbc1SJed Brown exotic/enriched spaces on mixed topology meshes. 2982ea844a1aSMatthew Knepley 2983cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `IS`, `PetscSectionGetClosurePermutation()`, `PetscSectionGetClosureIndex()`, `DMPlexCreateClosureIndex()`, `PetscCopyMode` 2984ea844a1aSMatthew Knepley @*/ 2985d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetClosurePermutation(PetscSection section, PetscObject obj, PetscInt depth, IS perm) 2986d71ae5a4SJacob Faibussowitsch { 2987ea844a1aSMatthew Knepley const PetscInt *clPerm = NULL; 2988ea844a1aSMatthew Knepley PetscInt clSize = 0; 2989ea844a1aSMatthew Knepley 2990ea844a1aSMatthew Knepley PetscFunctionBegin; 2991ea844a1aSMatthew Knepley if (perm) { 29929566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(perm, &clSize)); 29939566063dSJacob Faibussowitsch PetscCall(ISGetIndices(perm, &clPerm)); 2994ea844a1aSMatthew Knepley } 29959566063dSJacob Faibussowitsch PetscCall(PetscSectionSetClosurePermutation_Internal(section, obj, depth, clSize, PETSC_COPY_VALUES, (PetscInt *)clPerm)); 29969566063dSJacob Faibussowitsch if (perm) PetscCall(ISRestoreIndices(perm, &clPerm)); 29973ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2998ea844a1aSMatthew Knepley } 2999ea844a1aSMatthew Knepley 3000da8c939bSJacob Faibussowitsch static PetscErrorCode PetscSectionGetClosurePermutation_Private(PetscSection section, PetscObject obj, PetscInt depth, PetscInt size, const PetscInt *perm[]) 3001d71ae5a4SJacob Faibussowitsch { 3002ea844a1aSMatthew Knepley PetscFunctionBegin; 3003ea844a1aSMatthew Knepley if (section->clObj == obj) { 3004c459fbc1SJed Brown PetscSectionClosurePermKey k = {depth, size}; 3005c459fbc1SJed Brown PetscSectionClosurePermVal v; 3006da8c939bSJacob Faibussowitsch 30079566063dSJacob Faibussowitsch PetscCall(PetscClPermGet(section->clHash, k, &v)); 3008c459fbc1SJed Brown if (perm) *perm = v.perm; 3009ea844a1aSMatthew Knepley } else { 3010ea844a1aSMatthew Knepley if (perm) *perm = NULL; 3011ea844a1aSMatthew Knepley } 30123ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3013ea844a1aSMatthew Knepley } 3014ea844a1aSMatthew Knepley 3015ea844a1aSMatthew Knepley /*@ 3016ea844a1aSMatthew Knepley PetscSectionGetClosurePermutation - Get the dof permutation for the closure of each cell in the section, meaning clPerm[newIndex] = oldIndex. 3017ea844a1aSMatthew Knepley 301840750d41SVaclav Hapla Not Collective 3019ea844a1aSMatthew Knepley 3020ea844a1aSMatthew Knepley Input Parameters: 3021cab54364SBarry Smith + section - The `PetscSection` 3022cab54364SBarry Smith . obj - A `PetscObject` which serves as the key for this index (usually a DM) 3023c459fbc1SJed Brown . depth - Depth stratum on which to obtain closure permutation 3024c459fbc1SJed Brown - clSize - Closure size to be permuted (e.g., may vary with element topology and degree) 3025ea844a1aSMatthew Knepley 3026ea844a1aSMatthew Knepley Output Parameter: 3027ea844a1aSMatthew Knepley . perm - The dof closure permutation 3028ea844a1aSMatthew Knepley 3029ea844a1aSMatthew Knepley Level: intermediate 3030ea844a1aSMatthew Knepley 3031cab54364SBarry Smith Note: 3032cab54364SBarry Smith The user must destroy the `IS` that is returned. 3033cab54364SBarry Smith 3034cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `IS`, `PetscSectionSetClosurePermutation()`, `PetscSectionGetClosureInversePermutation()`, `PetscSectionGetClosureIndex()`, `PetscSectionSetClosureIndex()`, `DMPlexCreateClosureIndex()` 3035ea844a1aSMatthew Knepley @*/ 3036d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosurePermutation(PetscSection section, PetscObject obj, PetscInt depth, PetscInt clSize, IS *perm) 3037d71ae5a4SJacob Faibussowitsch { 3038da8c939bSJacob Faibussowitsch const PetscInt *clPerm = NULL; 3039ea844a1aSMatthew Knepley 3040ea844a1aSMatthew Knepley PetscFunctionBegin; 3041da8c939bSJacob Faibussowitsch PetscCall(PetscSectionGetClosurePermutation_Private(section, obj, depth, clSize, &clPerm)); 30429566063dSJacob Faibussowitsch PetscCall(ISCreateGeneral(PETSC_COMM_SELF, clSize, clPerm, PETSC_USE_POINTER, perm)); 30433ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3044ea844a1aSMatthew Knepley } 3045ea844a1aSMatthew Knepley 3046d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosureInversePermutation_Internal(PetscSection section, PetscObject obj, PetscInt depth, PetscInt size, const PetscInt *perm[]) 3047d71ae5a4SJacob Faibussowitsch { 3048ea844a1aSMatthew Knepley PetscFunctionBegin; 3049c459fbc1SJed Brown if (section->clObj == obj && section->clHash) { 3050c459fbc1SJed Brown PetscSectionClosurePermKey k = {depth, size}; 3051c459fbc1SJed Brown PetscSectionClosurePermVal v; 30529566063dSJacob Faibussowitsch PetscCall(PetscClPermGet(section->clHash, k, &v)); 3053c459fbc1SJed Brown if (perm) *perm = v.invPerm; 3054ea844a1aSMatthew Knepley } else { 3055ea844a1aSMatthew Knepley if (perm) *perm = NULL; 3056ea844a1aSMatthew Knepley } 30573ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3058ea844a1aSMatthew Knepley } 3059ea844a1aSMatthew Knepley 3060ea844a1aSMatthew Knepley /*@ 3061ea844a1aSMatthew Knepley PetscSectionGetClosureInversePermutation - Get the inverse dof permutation for the closure of each cell in the section, meaning clPerm[oldIndex] = newIndex. 3062ea844a1aSMatthew Knepley 306340750d41SVaclav Hapla Not Collective 3064ea844a1aSMatthew Knepley 3065ea844a1aSMatthew Knepley Input Parameters: 3066cab54364SBarry Smith + section - The `PetscSection` 3067cab54364SBarry Smith . obj - A `PetscObject` which serves as the key for this index (usually a `DM`) 3068c459fbc1SJed Brown . depth - Depth stratum on which to obtain closure permutation 3069c459fbc1SJed Brown - clSize - Closure size to be permuted (e.g., may vary with element topology and degree) 3070ea844a1aSMatthew Knepley 30712fe279fdSBarry Smith Output Parameter: 3072c459fbc1SJed Brown . perm - The dof closure permutation 3073ea844a1aSMatthew Knepley 3074ea844a1aSMatthew Knepley Level: intermediate 3075ea844a1aSMatthew Knepley 3076cab54364SBarry Smith Note: 3077cab54364SBarry Smith The user must destroy the `IS` that is returned. 3078cab54364SBarry Smith 3079cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `IS`, `PetscSectionSetClosurePermutation()`, `PetscSectionGetClosureIndex()`, `PetscSectionSetClosureIndex()`, `DMPlexCreateClosureIndex()` 3080ea844a1aSMatthew Knepley @*/ 3081d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosureInversePermutation(PetscSection section, PetscObject obj, PetscInt depth, PetscInt clSize, IS *perm) 3082d71ae5a4SJacob Faibussowitsch { 3083da8c939bSJacob Faibussowitsch const PetscInt *clPerm = NULL; 3084ea844a1aSMatthew Knepley 3085ea844a1aSMatthew Knepley PetscFunctionBegin; 30869566063dSJacob Faibussowitsch PetscCall(PetscSectionGetClosureInversePermutation_Internal(section, obj, depth, clSize, &clPerm)); 30879566063dSJacob Faibussowitsch PetscCall(ISCreateGeneral(PETSC_COMM_SELF, clSize, clPerm, PETSC_USE_POINTER, perm)); 30883ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3089ea844a1aSMatthew Knepley } 3090ea844a1aSMatthew Knepley 3091ea844a1aSMatthew Knepley /*@ 3092583308b6SBarry Smith PetscSectionGetField - Get the `PetscSection` associated with a single field 3093ea844a1aSMatthew Knepley 3094ea844a1aSMatthew Knepley Input Parameters: 3095cab54364SBarry Smith + s - The `PetscSection` 3096ea844a1aSMatthew Knepley - field - The field number 3097ea844a1aSMatthew Knepley 3098ea844a1aSMatthew Knepley Output Parameter: 3099583308b6SBarry Smith . subs - The `PetscSection` for the given field, note the chart of `subs` is not set 3100ea844a1aSMatthew Knepley 3101ea844a1aSMatthew Knepley Level: intermediate 3102ea844a1aSMatthew Knepley 3103cab54364SBarry Smith Note: 3104cab54364SBarry Smith Does not increase the reference count of the selected sub-section. There is no matching `PetscSectionRestoreField()` 3105cab54364SBarry Smith 3106cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `IS`, `PetscSectionSetNumFields()` 3107ea844a1aSMatthew Knepley @*/ 3108d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetField(PetscSection s, PetscInt field, PetscSection *subs) 3109d71ae5a4SJacob Faibussowitsch { 3110ea844a1aSMatthew Knepley PetscFunctionBegin; 3111ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 31124f572ea9SToby Isaac PetscAssertPointer(subs, 3); 31132abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 3114ea844a1aSMatthew Knepley *subs = s->field[field]; 31153ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3116ea844a1aSMatthew Knepley } 3117ea844a1aSMatthew Knepley 3118ea844a1aSMatthew Knepley PetscClassId PETSC_SECTION_SYM_CLASSID; 3119ea844a1aSMatthew Knepley PetscFunctionList PetscSectionSymList = NULL; 3120ea844a1aSMatthew Knepley 3121ea844a1aSMatthew Knepley /*@ 3122cab54364SBarry Smith PetscSectionSymCreate - Creates an empty `PetscSectionSym` object. 3123ea844a1aSMatthew Knepley 3124ea844a1aSMatthew Knepley Collective 3125ea844a1aSMatthew Knepley 3126ea844a1aSMatthew Knepley Input Parameter: 3127ea844a1aSMatthew Knepley . comm - the MPI communicator 3128ea844a1aSMatthew Knepley 3129ea844a1aSMatthew Knepley Output Parameter: 3130ea844a1aSMatthew Knepley . sym - pointer to the new set of symmetries 3131ea844a1aSMatthew Knepley 3132ea844a1aSMatthew Knepley Level: developer 3133ea844a1aSMatthew Knepley 3134cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSym`, `PetscSectionSymDestroy()` 3135ea844a1aSMatthew Knepley @*/ 3136d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymCreate(MPI_Comm comm, PetscSectionSym *sym) 3137d71ae5a4SJacob Faibussowitsch { 3138ea844a1aSMatthew Knepley PetscFunctionBegin; 31394f572ea9SToby Isaac PetscAssertPointer(sym, 2); 31409566063dSJacob Faibussowitsch PetscCall(ISInitializePackage()); 31419566063dSJacob Faibussowitsch PetscCall(PetscHeaderCreate(*sym, PETSC_SECTION_SYM_CLASSID, "PetscSectionSym", "Section Symmetry", "IS", comm, PetscSectionSymDestroy, PetscSectionSymView)); 31423ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3143ea844a1aSMatthew Knepley } 3144ea844a1aSMatthew Knepley 3145ea844a1aSMatthew Knepley /*@C 3146cab54364SBarry Smith PetscSectionSymSetType - Builds a `PetscSectionSym`, for a particular implementation. 3147ea844a1aSMatthew Knepley 314840750d41SVaclav Hapla Collective 3149ea844a1aSMatthew Knepley 3150ea844a1aSMatthew Knepley Input Parameters: 3151ea844a1aSMatthew Knepley + sym - The section symmetry object 3152ea844a1aSMatthew Knepley - method - The name of the section symmetry type 3153ea844a1aSMatthew Knepley 3154ea844a1aSMatthew Knepley Level: developer 3155ea844a1aSMatthew Knepley 3156cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSymType`, `PetscSectionSymGetType()`, `PetscSectionSymCreate()` 3157ea844a1aSMatthew Knepley @*/ 3158d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymSetType(PetscSectionSym sym, PetscSectionSymType method) 3159d71ae5a4SJacob Faibussowitsch { 3160ea844a1aSMatthew Knepley PetscErrorCode (*r)(PetscSectionSym); 3161ea844a1aSMatthew Knepley PetscBool match; 3162ea844a1aSMatthew Knepley 3163ea844a1aSMatthew Knepley PetscFunctionBegin; 3164ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 31659566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)sym, method, &match)); 31663ba16761SJacob Faibussowitsch if (match) PetscFunctionReturn(PETSC_SUCCESS); 3167ea844a1aSMatthew Knepley 31689566063dSJacob Faibussowitsch PetscCall(PetscFunctionListFind(PetscSectionSymList, method, &r)); 31696adde796SStefano Zampini PetscCheck(r, PetscObjectComm((PetscObject)sym), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscSectionSym type: %s", method); 3170dbbe0bcdSBarry Smith PetscTryTypeMethod(sym, destroy); 3171ea844a1aSMatthew Knepley sym->ops->destroy = NULL; 3172dbbe0bcdSBarry Smith 31739566063dSJacob Faibussowitsch PetscCall((*r)(sym)); 31749566063dSJacob Faibussowitsch PetscCall(PetscObjectChangeTypeName((PetscObject)sym, method)); 31753ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3176ea844a1aSMatthew Knepley } 3177ea844a1aSMatthew Knepley 3178ea844a1aSMatthew Knepley /*@C 3179cab54364SBarry Smith PetscSectionSymGetType - Gets the section symmetry type name (as a string) from the `PetscSectionSym`. 3180ea844a1aSMatthew Knepley 3181ea844a1aSMatthew Knepley Not Collective 3182ea844a1aSMatthew Knepley 3183ea844a1aSMatthew Knepley Input Parameter: 3184ea844a1aSMatthew Knepley . sym - The section symmetry 3185ea844a1aSMatthew Knepley 3186ea844a1aSMatthew Knepley Output Parameter: 3187ea844a1aSMatthew Knepley . type - The index set type name 3188ea844a1aSMatthew Knepley 3189ea844a1aSMatthew Knepley Level: developer 3190ea844a1aSMatthew Knepley 3191cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSymType`, `PetscSectionSymSetType()`, `PetscSectionSymCreate()` 3192ea844a1aSMatthew Knepley @*/ 3193d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymGetType(PetscSectionSym sym, PetscSectionSymType *type) 3194d71ae5a4SJacob Faibussowitsch { 3195ea844a1aSMatthew Knepley PetscFunctionBegin; 3196ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 31974f572ea9SToby Isaac PetscAssertPointer(type, 2); 3198ea844a1aSMatthew Knepley *type = ((PetscObject)sym)->type_name; 31993ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3200ea844a1aSMatthew Knepley } 3201ea844a1aSMatthew Knepley 3202ea844a1aSMatthew Knepley /*@C 3203cab54364SBarry Smith PetscSectionSymRegister - Registers a new section symmetry implementation 3204ea844a1aSMatthew Knepley 3205ea844a1aSMatthew Knepley Not Collective 3206ea844a1aSMatthew Knepley 3207ea844a1aSMatthew Knepley Input Parameters: 32082fe279fdSBarry Smith + sname - The name of a new user-defined creation routine 32092fe279fdSBarry Smith - function - The creation routine itself 3210ea844a1aSMatthew Knepley 3211ea844a1aSMatthew Knepley Level: developer 3212ea844a1aSMatthew Knepley 3213cab54364SBarry Smith Notes: 3214cab54364SBarry Smith `PetscSectionSymRegister()` may be called multiple times to add several user-defined vectors 3215cab54364SBarry Smith 3216cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSymType`, `PetscSectionSymCreate()`, `PetscSectionSymSetType()` 3217ea844a1aSMatthew Knepley @*/ 3218d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymRegister(const char sname[], PetscErrorCode (*function)(PetscSectionSym)) 3219d71ae5a4SJacob Faibussowitsch { 3220ea844a1aSMatthew Knepley PetscFunctionBegin; 32219566063dSJacob Faibussowitsch PetscCall(ISInitializePackage()); 32229566063dSJacob Faibussowitsch PetscCall(PetscFunctionListAdd(&PetscSectionSymList, sname, function)); 32233ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3224ea844a1aSMatthew Knepley } 3225ea844a1aSMatthew Knepley 3226ea844a1aSMatthew Knepley /*@ 3227ea844a1aSMatthew Knepley PetscSectionSymDestroy - Destroys a section symmetry. 3228ea844a1aSMatthew Knepley 322940750d41SVaclav Hapla Collective 3230ea844a1aSMatthew Knepley 32312fe279fdSBarry Smith Input Parameter: 3232ea844a1aSMatthew Knepley . sym - the section symmetry 3233ea844a1aSMatthew Knepley 3234ea844a1aSMatthew Knepley Level: developer 3235ea844a1aSMatthew Knepley 323642747ad1SJacob Faibussowitsch .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSymCreate()` 3237ea844a1aSMatthew Knepley @*/ 3238d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymDestroy(PetscSectionSym *sym) 3239d71ae5a4SJacob Faibussowitsch { 3240ea844a1aSMatthew Knepley SymWorkLink link, next; 3241ea844a1aSMatthew Knepley 3242ea844a1aSMatthew Knepley PetscFunctionBegin; 32433ba16761SJacob Faibussowitsch if (!*sym) PetscFunctionReturn(PETSC_SUCCESS); 3244ea844a1aSMatthew Knepley PetscValidHeaderSpecific((*sym), PETSC_SECTION_SYM_CLASSID, 1); 32459371c9d4SSatish Balay if (--((PetscObject)(*sym))->refct > 0) { 32469371c9d4SSatish Balay *sym = NULL; 32473ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3248ea844a1aSMatthew Knepley } 324948a46eb9SPierre Jolivet if ((*sym)->ops->destroy) PetscCall((*(*sym)->ops->destroy)(*sym)); 3250c9cc58a2SBarry Smith PetscCheck(!(*sym)->workout, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Work array still checked out"); 3251ea844a1aSMatthew Knepley for (link = (*sym)->workin; link; link = next) { 32520c99d500SBarry Smith PetscInt **perms = (PetscInt **)link->perms; 32530c99d500SBarry Smith PetscScalar **rots = (PetscScalar **)link->rots; 32540c99d500SBarry Smith PetscCall(PetscFree2(perms, rots)); 3255ea844a1aSMatthew Knepley next = link->next; 32569566063dSJacob Faibussowitsch PetscCall(PetscFree(link)); 3257ea844a1aSMatthew Knepley } 3258ea844a1aSMatthew Knepley (*sym)->workin = NULL; 32599566063dSJacob Faibussowitsch PetscCall(PetscHeaderDestroy(sym)); 32603ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3261ea844a1aSMatthew Knepley } 3262ea844a1aSMatthew Knepley 3263ea844a1aSMatthew Knepley /*@C 3264ea844a1aSMatthew Knepley PetscSectionSymView - Displays a section symmetry 3265ea844a1aSMatthew Knepley 326640750d41SVaclav Hapla Collective 3267ea844a1aSMatthew Knepley 3268ea844a1aSMatthew Knepley Input Parameters: 3269ea844a1aSMatthew Knepley + sym - the index set 3270cab54364SBarry Smith - viewer - viewer used to display the set, for example `PETSC_VIEWER_STDOUT_SELF`. 3271ea844a1aSMatthew Knepley 3272ea844a1aSMatthew Knepley Level: developer 3273ea844a1aSMatthew Knepley 3274cab54364SBarry Smith .seealso: `PetscSectionSym`, `PetscViewer`, `PetscViewerASCIIOpen()` 3275ea844a1aSMatthew Knepley @*/ 3276d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymView(PetscSectionSym sym, PetscViewer viewer) 3277d71ae5a4SJacob Faibussowitsch { 3278ea844a1aSMatthew Knepley PetscFunctionBegin; 3279ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 328048a46eb9SPierre Jolivet if (!viewer) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)sym), &viewer)); 3281ea844a1aSMatthew Knepley PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2); 3282ea844a1aSMatthew Knepley PetscCheckSameComm(sym, 1, viewer, 2); 32839566063dSJacob Faibussowitsch PetscCall(PetscObjectPrintClassNamePrefixType((PetscObject)sym, viewer)); 3284dbbe0bcdSBarry Smith PetscTryTypeMethod(sym, view, viewer); 32853ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3286ea844a1aSMatthew Knepley } 3287ea844a1aSMatthew Knepley 3288ea844a1aSMatthew Knepley /*@ 3289ea844a1aSMatthew Knepley PetscSectionSetSym - Set the symmetries for the data referred to by the section 3290ea844a1aSMatthew Knepley 329140750d41SVaclav Hapla Collective 3292ea844a1aSMatthew Knepley 3293ea844a1aSMatthew Knepley Input Parameters: 3294ea844a1aSMatthew Knepley + section - the section describing data layout 3295ea844a1aSMatthew Knepley - sym - the symmetry describing the affect of orientation on the access of the data 3296ea844a1aSMatthew Knepley 3297ea844a1aSMatthew Knepley Level: developer 3298ea844a1aSMatthew Knepley 3299cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionGetSym()`, `PetscSectionSymCreate()` 3300ea844a1aSMatthew Knepley @*/ 3301d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetSym(PetscSection section, PetscSectionSym sym) 3302d71ae5a4SJacob Faibussowitsch { 3303ea844a1aSMatthew Knepley PetscFunctionBegin; 3304ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 33059566063dSJacob Faibussowitsch PetscCall(PetscSectionSymDestroy(&(section->sym))); 3306ea844a1aSMatthew Knepley if (sym) { 3307ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 2); 3308ea844a1aSMatthew Knepley PetscCheckSameComm(section, 1, sym, 2); 33099566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)sym)); 3310ea844a1aSMatthew Knepley } 3311ea844a1aSMatthew Knepley section->sym = sym; 33123ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3313ea844a1aSMatthew Knepley } 3314ea844a1aSMatthew Knepley 3315ea844a1aSMatthew Knepley /*@ 3316ea844a1aSMatthew Knepley PetscSectionGetSym - Get the symmetries for the data referred to by the section 3317ea844a1aSMatthew Knepley 331840750d41SVaclav Hapla Not Collective 3319ea844a1aSMatthew Knepley 33202fe279fdSBarry Smith Input Parameter: 3321ea844a1aSMatthew Knepley . section - the section describing data layout 3322ea844a1aSMatthew Knepley 33232fe279fdSBarry Smith Output Parameter: 332420662ed9SBarry Smith . sym - the symmetry describing the affect of orientation on the access of the data, provided previously by `PetscSectionSetSym()` 3325ea844a1aSMatthew Knepley 3326ea844a1aSMatthew Knepley Level: developer 3327ea844a1aSMatthew Knepley 3328cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSetSym()`, `PetscSectionSymCreate()` 3329ea844a1aSMatthew Knepley @*/ 3330d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetSym(PetscSection section, PetscSectionSym *sym) 3331d71ae5a4SJacob Faibussowitsch { 3332ea844a1aSMatthew Knepley PetscFunctionBegin; 3333ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 3334ea844a1aSMatthew Knepley *sym = section->sym; 33353ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3336ea844a1aSMatthew Knepley } 3337ea844a1aSMatthew Knepley 3338ea844a1aSMatthew Knepley /*@ 3339ea844a1aSMatthew Knepley PetscSectionSetFieldSym - Set the symmetries for the data referred to by a field of the section 3340ea844a1aSMatthew Knepley 334140750d41SVaclav Hapla Collective 3342ea844a1aSMatthew Knepley 3343ea844a1aSMatthew Knepley Input Parameters: 3344ea844a1aSMatthew Knepley + section - the section describing data layout 3345ea844a1aSMatthew Knepley . field - the field number 3346ea844a1aSMatthew Knepley - sym - the symmetry describing the affect of orientation on the access of the data 3347ea844a1aSMatthew Knepley 3348ea844a1aSMatthew Knepley Level: developer 3349ea844a1aSMatthew Knepley 3350cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionGetFieldSym()`, `PetscSectionSymCreate()` 3351ea844a1aSMatthew Knepley @*/ 3352d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldSym(PetscSection section, PetscInt field, PetscSectionSym sym) 3353d71ae5a4SJacob Faibussowitsch { 3354ea844a1aSMatthew Knepley PetscFunctionBegin; 3355ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 33562abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, section->numFields); 33579566063dSJacob Faibussowitsch PetscCall(PetscSectionSetSym(section->field[field], sym)); 33583ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3359ea844a1aSMatthew Knepley } 3360ea844a1aSMatthew Knepley 3361ea844a1aSMatthew Knepley /*@ 3362ea844a1aSMatthew Knepley PetscSectionGetFieldSym - Get the symmetries for the data referred to by a field of the section 3363ea844a1aSMatthew Knepley 336440750d41SVaclav Hapla Collective 3365ea844a1aSMatthew Knepley 3366ea844a1aSMatthew Knepley Input Parameters: 3367ea844a1aSMatthew Knepley + section - the section describing data layout 3368ea844a1aSMatthew Knepley - field - the field number 3369ea844a1aSMatthew Knepley 33702fe279fdSBarry Smith Output Parameter: 3371ea844a1aSMatthew Knepley . sym - the symmetry describing the affect of orientation on the access of the data 3372ea844a1aSMatthew Knepley 3373ea844a1aSMatthew Knepley Level: developer 3374ea844a1aSMatthew Knepley 3375cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSetFieldSym()`, `PetscSectionSymCreate()` 3376ea844a1aSMatthew Knepley @*/ 3377d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldSym(PetscSection section, PetscInt field, PetscSectionSym *sym) 3378d71ae5a4SJacob Faibussowitsch { 3379ea844a1aSMatthew Knepley PetscFunctionBegin; 3380ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 33812abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, section->numFields); 3382ea844a1aSMatthew Knepley *sym = section->field[field]->sym; 33833ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3384ea844a1aSMatthew Knepley } 3385ea844a1aSMatthew Knepley 3386ea844a1aSMatthew Knepley /*@C 3387cab54364SBarry Smith PetscSectionGetPointSyms - Get the symmetries for a set of points in a `PetscSection` under specific orientations. 3388ea844a1aSMatthew Knepley 338940750d41SVaclav Hapla Not Collective 3390ea844a1aSMatthew Knepley 3391ea844a1aSMatthew Knepley Input Parameters: 3392ea844a1aSMatthew Knepley + section - the section 3393ea844a1aSMatthew Knepley . numPoints - the number of points 339420662ed9SBarry Smith - points - an array of size 2 * `numPoints`, containing a list of (point, orientation) pairs. (An orientation is an 339520662ed9SBarry Smith arbitrary integer: its interpretation is up to sym. Orientations are used by `DM`: for their interpretation in that 339620662ed9SBarry Smith context, see `DMPlexGetConeOrientation()`). 3397ea844a1aSMatthew Knepley 3398d8d19677SJose E. Roman Output Parameters: 339920662ed9SBarry Smith + perms - The permutations for the given orientations (or `NULL` if there is no symmetry or the permutation is the identity). 340020662ed9SBarry Smith - rots - The field rotations symmetries for the given orientations (or `NULL` if there is no symmetry or the rotations are all 3401ea844a1aSMatthew Knepley identity). 3402ea844a1aSMatthew Knepley 3403ea844a1aSMatthew Knepley Example of usage, gathering dofs into a local array (lArray) from a section array (sArray): 3404ea844a1aSMatthew Knepley .vb 3405ea844a1aSMatthew Knepley const PetscInt **perms; 3406ea844a1aSMatthew Knepley const PetscScalar **rots; 3407ea844a1aSMatthew Knepley PetscInt lOffset; 3408ea844a1aSMatthew Knepley 3409ea844a1aSMatthew Knepley PetscSectionGetPointSyms(section,numPoints,points,&perms,&rots); 3410ea844a1aSMatthew Knepley for (i = 0, lOffset = 0; i < numPoints; i++) { 3411ea844a1aSMatthew Knepley PetscInt point = points[2*i], dof, sOffset; 3412ea844a1aSMatthew Knepley const PetscInt *perm = perms ? perms[i] : NULL; 3413ea844a1aSMatthew Knepley const PetscScalar *rot = rots ? rots[i] : NULL; 3414ea844a1aSMatthew Knepley 3415ea844a1aSMatthew Knepley PetscSectionGetDof(section,point,&dof); 3416ea844a1aSMatthew Knepley PetscSectionGetOffset(section,point,&sOffset); 3417ea844a1aSMatthew Knepley 3418ea844a1aSMatthew Knepley if (perm) {for (j = 0; j < dof; j++) {lArray[lOffset + perm[j]] = sArray[sOffset + j];}} 3419ea844a1aSMatthew Knepley else {for (j = 0; j < dof; j++) {lArray[lOffset + j ] = sArray[sOffset + j];}} 3420ea844a1aSMatthew Knepley if (rot) {for (j = 0; j < dof; j++) {lArray[lOffset + j ] *= rot[j]; }} 3421ea844a1aSMatthew Knepley lOffset += dof; 3422ea844a1aSMatthew Knepley } 3423ea844a1aSMatthew Knepley PetscSectionRestorePointSyms(section,numPoints,points,&perms,&rots); 3424ea844a1aSMatthew Knepley .ve 3425ea844a1aSMatthew Knepley 3426ea844a1aSMatthew Knepley Example of usage, adding dofs into a section array (sArray) from a local array (lArray): 3427ea844a1aSMatthew Knepley .vb 3428ea844a1aSMatthew Knepley const PetscInt **perms; 3429ea844a1aSMatthew Knepley const PetscScalar **rots; 3430ea844a1aSMatthew Knepley PetscInt lOffset; 3431ea844a1aSMatthew Knepley 3432ea844a1aSMatthew Knepley PetscSectionGetPointSyms(section,numPoints,points,&perms,&rots); 3433ea844a1aSMatthew Knepley for (i = 0, lOffset = 0; i < numPoints; i++) { 3434ea844a1aSMatthew Knepley PetscInt point = points[2*i], dof, sOffset; 3435ea844a1aSMatthew Knepley const PetscInt *perm = perms ? perms[i] : NULL; 3436ea844a1aSMatthew Knepley const PetscScalar *rot = rots ? rots[i] : NULL; 3437ea844a1aSMatthew Knepley 3438ea844a1aSMatthew Knepley PetscSectionGetDof(section,point,&dof); 3439ea844a1aSMatthew Knepley PetscSectionGetOffset(section,point,&sOff); 3440ea844a1aSMatthew Knepley 3441ea844a1aSMatthew Knepley if (perm) {for (j = 0; j < dof; j++) {sArray[sOffset + j] += lArray[lOffset + perm[j]] * (rot ? PetscConj(rot[perm[j]]) : 1.);}} 3442ea844a1aSMatthew Knepley else {for (j = 0; j < dof; j++) {sArray[sOffset + j] += lArray[lOffset + j ] * (rot ? PetscConj(rot[ j ]) : 1.);}} 3443ea844a1aSMatthew Knepley offset += dof; 3444ea844a1aSMatthew Knepley } 3445ea844a1aSMatthew Knepley PetscSectionRestorePointSyms(section,numPoints,points,&perms,&rots); 3446ea844a1aSMatthew Knepley .ve 3447ea844a1aSMatthew Knepley 3448ea844a1aSMatthew Knepley Level: developer 3449ea844a1aSMatthew Knepley 3450583308b6SBarry Smith Notes: 345120662ed9SBarry Smith `PetscSectionSetSym()` must have been previously called to provide the symmetries to the `PetscSection` 345220662ed9SBarry Smith 345320662ed9SBarry Smith Use `PetscSectionRestorePointSyms()` when finished with the data 345420662ed9SBarry Smith 3455cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionRestorePointSyms()`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()` 3456ea844a1aSMatthew Knepley @*/ 3457d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetPointSyms(PetscSection section, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots) 3458d71ae5a4SJacob Faibussowitsch { 3459ea844a1aSMatthew Knepley PetscSectionSym sym; 3460ea844a1aSMatthew Knepley 3461ea844a1aSMatthew Knepley PetscFunctionBegin; 3462ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 34634f572ea9SToby Isaac if (numPoints) PetscAssertPointer(points, 3); 3464ea844a1aSMatthew Knepley if (perms) *perms = NULL; 3465ea844a1aSMatthew Knepley if (rots) *rots = NULL; 3466ea844a1aSMatthew Knepley sym = section->sym; 3467ea844a1aSMatthew Knepley if (sym && (perms || rots)) { 3468ea844a1aSMatthew Knepley SymWorkLink link; 3469ea844a1aSMatthew Knepley 3470ea844a1aSMatthew Knepley if (sym->workin) { 3471ea844a1aSMatthew Knepley link = sym->workin; 3472ea844a1aSMatthew Knepley sym->workin = sym->workin->next; 3473ea844a1aSMatthew Knepley } else { 34744dfa11a4SJacob Faibussowitsch PetscCall(PetscNew(&link)); 3475ea844a1aSMatthew Knepley } 3476ea844a1aSMatthew Knepley if (numPoints > link->numPoints) { 34770c99d500SBarry Smith PetscInt **perms = (PetscInt **)link->perms; 34780c99d500SBarry Smith PetscScalar **rots = (PetscScalar **)link->rots; 34790c99d500SBarry Smith PetscCall(PetscFree2(perms, rots)); 34800c99d500SBarry Smith PetscCall(PetscMalloc2(numPoints, (PetscInt ***)&link->perms, numPoints, (PetscScalar ***)&link->rots)); 3481ea844a1aSMatthew Knepley link->numPoints = numPoints; 3482ea844a1aSMatthew Knepley } 3483ea844a1aSMatthew Knepley link->next = sym->workout; 3484ea844a1aSMatthew Knepley sym->workout = link; 34859566063dSJacob Faibussowitsch PetscCall(PetscArrayzero((PetscInt **)link->perms, numPoints)); 34869566063dSJacob Faibussowitsch PetscCall(PetscArrayzero((PetscInt **)link->rots, numPoints)); 34879566063dSJacob Faibussowitsch PetscCall((*sym->ops->getpoints)(sym, section, numPoints, points, link->perms, link->rots)); 3488ea844a1aSMatthew Knepley if (perms) *perms = link->perms; 3489ea844a1aSMatthew Knepley if (rots) *rots = link->rots; 3490ea844a1aSMatthew Knepley } 34913ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3492ea844a1aSMatthew Knepley } 3493ea844a1aSMatthew Knepley 3494ea844a1aSMatthew Knepley /*@C 3495cab54364SBarry Smith PetscSectionRestorePointSyms - Restore the symmetries returned by `PetscSectionGetPointSyms()` 3496ea844a1aSMatthew Knepley 349740750d41SVaclav Hapla Not Collective 3498ea844a1aSMatthew Knepley 3499ea844a1aSMatthew Knepley Input Parameters: 3500ea844a1aSMatthew Knepley + section - the section 3501ea844a1aSMatthew Knepley . numPoints - the number of points 350238b5cf2dSJacob Faibussowitsch . points - an array of size 2 * `numPoints`, containing a list of (point, orientation) pairs. (An orientation is an 3503cab54364SBarry Smith arbitrary integer: its interpretation is up to sym. Orientations are used by `DM`: for their interpretation in that 3504cab54364SBarry Smith context, see `DMPlexGetConeOrientation()`). 350520662ed9SBarry Smith . perms - The permutations for the given orientations: set to `NULL` at conclusion 350620662ed9SBarry Smith - rots - The field rotations symmetries for the given orientations: set to `NULL` at conclusion 3507ea844a1aSMatthew Knepley 3508ea844a1aSMatthew Knepley Level: developer 3509ea844a1aSMatthew Knepley 3510cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionGetPointSyms()`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()` 3511ea844a1aSMatthew Knepley @*/ 3512d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionRestorePointSyms(PetscSection section, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots) 3513d71ae5a4SJacob Faibussowitsch { 3514ea844a1aSMatthew Knepley PetscSectionSym sym; 3515ea844a1aSMatthew Knepley 3516ea844a1aSMatthew Knepley PetscFunctionBegin; 3517ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 3518ea844a1aSMatthew Knepley sym = section->sym; 3519ea844a1aSMatthew Knepley if (sym && (perms || rots)) { 3520ea844a1aSMatthew Knepley SymWorkLink *p, link; 3521ea844a1aSMatthew Knepley 3522ea844a1aSMatthew Knepley for (p = &sym->workout; (link = *p); p = &link->next) { 3523ea844a1aSMatthew Knepley if ((perms && link->perms == *perms) || (rots && link->rots == *rots)) { 3524ea844a1aSMatthew Knepley *p = link->next; 3525ea844a1aSMatthew Knepley link->next = sym->workin; 3526ea844a1aSMatthew Knepley sym->workin = link; 3527ea844a1aSMatthew Knepley if (perms) *perms = NULL; 3528ea844a1aSMatthew Knepley if (rots) *rots = NULL; 35293ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3530ea844a1aSMatthew Knepley } 3531ea844a1aSMatthew Knepley } 3532ea844a1aSMatthew Knepley SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Array was not checked out"); 3533ea844a1aSMatthew Knepley } 35343ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3535ea844a1aSMatthew Knepley } 3536ea844a1aSMatthew Knepley 3537ea844a1aSMatthew Knepley /*@C 3538cab54364SBarry Smith PetscSectionGetFieldPointSyms - Get the symmetries for a set of points in a field of a `PetscSection` under specific orientations. 3539ea844a1aSMatthew Knepley 354040750d41SVaclav Hapla Not Collective 3541ea844a1aSMatthew Knepley 3542ea844a1aSMatthew Knepley Input Parameters: 3543ea844a1aSMatthew Knepley + section - the section 3544ea844a1aSMatthew Knepley . field - the field of the section 3545ea844a1aSMatthew Knepley . numPoints - the number of points 354620662ed9SBarry Smith - points - an array of size 2 * `numPoints`, containing a list of (point, orientation) pairs. (An orientation is an 3547cab54364SBarry Smith arbitrary integer: its interpretation is up to sym. Orientations are used by `DM`: for their interpretation in that 3548cab54364SBarry Smith context, see `DMPlexGetConeOrientation()`). 3549ea844a1aSMatthew Knepley 3550d8d19677SJose E. Roman Output Parameters: 355120662ed9SBarry Smith + perms - The permutations for the given orientations (or `NULL` if there is no symmetry or the permutation is the identity). 355220662ed9SBarry Smith - rots - The field rotations symmetries for the given orientations (or `NULL` if there is no symmetry or the rotations are all 3553ea844a1aSMatthew Knepley identity). 3554ea844a1aSMatthew Knepley 3555ea844a1aSMatthew Knepley Level: developer 3556ea844a1aSMatthew Knepley 355720662ed9SBarry Smith Notes: 355820662ed9SBarry Smith `PetscSectionSetFieldSym()` must have been previously called to provide the symmetries to the `PetscSection` 355920662ed9SBarry Smith 356020662ed9SBarry Smith Use `PetscSectionRestoreFieldPointSyms()` when finished with the data 356120662ed9SBarry Smith 3562cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionGetPointSyms()`, `PetscSectionRestoreFieldPointSyms()` 3563ea844a1aSMatthew Knepley @*/ 3564d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldPointSyms(PetscSection section, PetscInt field, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots) 3565d71ae5a4SJacob Faibussowitsch { 3566ea844a1aSMatthew Knepley PetscFunctionBegin; 3567ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 356808401ef6SPierre Jolivet PetscCheck(field <= section->numFields, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "field %" PetscInt_FMT " greater than number of fields (%" PetscInt_FMT ") in section", field, section->numFields); 35699566063dSJacob Faibussowitsch PetscCall(PetscSectionGetPointSyms(section->field[field], numPoints, points, perms, rots)); 35703ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3571ea844a1aSMatthew Knepley } 3572ea844a1aSMatthew Knepley 3573ea844a1aSMatthew Knepley /*@C 3574cab54364SBarry Smith PetscSectionRestoreFieldPointSyms - Restore the symmetries returned by `PetscSectionGetFieldPointSyms()` 3575ea844a1aSMatthew Knepley 357640750d41SVaclav Hapla Not Collective 3577ea844a1aSMatthew Knepley 3578ea844a1aSMatthew Knepley Input Parameters: 3579ea844a1aSMatthew Knepley + section - the section 3580ea844a1aSMatthew Knepley . field - the field number 3581ea844a1aSMatthew Knepley . numPoints - the number of points 358238b5cf2dSJacob Faibussowitsch . points - an array of size 2 * `numPoints`, containing a list of (point, orientation) pairs. (An orientation is an 3583cab54364SBarry Smith arbitrary integer: its interpretation is up to sym. Orientations are used by `DM`: for their interpretation in that 3584cab54364SBarry Smith context, see `DMPlexGetConeOrientation()`). 358520662ed9SBarry Smith . perms - The permutations for the given orientations: set to NULL at conclusion 3586ea844a1aSMatthew Knepley - rots - The field rotations symmetries for the given orientations: set to NULL at conclusion 3587ea844a1aSMatthew Knepley 3588ea844a1aSMatthew Knepley Level: developer 3589ea844a1aSMatthew Knepley 3590cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionRestorePointSyms()`, `petscSectionGetFieldPointSyms()`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()` 3591ea844a1aSMatthew Knepley @*/ 3592d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionRestoreFieldPointSyms(PetscSection section, PetscInt field, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots) 3593d71ae5a4SJacob Faibussowitsch { 3594ea844a1aSMatthew Knepley PetscFunctionBegin; 3595ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 359608401ef6SPierre Jolivet PetscCheck(field <= section->numFields, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "field %" PetscInt_FMT " greater than number of fields (%" PetscInt_FMT ") in section", field, section->numFields); 35979566063dSJacob Faibussowitsch PetscCall(PetscSectionRestorePointSyms(section->field[field], numPoints, points, perms, rots)); 35983ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3599ea844a1aSMatthew Knepley } 3600ea844a1aSMatthew Knepley 3601ea844a1aSMatthew Knepley /*@ 3602b004864fSMatthew G. Knepley PetscSectionSymCopy - Copy the symmetries, assuming that the point structure is compatible 3603b004864fSMatthew G. Knepley 360440750d41SVaclav Hapla Not Collective 3605b004864fSMatthew G. Knepley 3606b004864fSMatthew G. Knepley Input Parameter: 3607cab54364SBarry Smith . sym - the `PetscSectionSym` 3608b004864fSMatthew G. Knepley 3609b004864fSMatthew G. Knepley Output Parameter: 3610b004864fSMatthew G. Knepley . nsym - the equivalent symmetries 3611b004864fSMatthew G. Knepley 3612b004864fSMatthew G. Knepley Level: developer 3613b004864fSMatthew G. Knepley 3614cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()`, `PetscSectionSymLabelSetStratum()`, `PetscSectionGetPointSyms()` 3615b004864fSMatthew G. Knepley @*/ 3616d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymCopy(PetscSectionSym sym, PetscSectionSym nsym) 3617d71ae5a4SJacob Faibussowitsch { 3618b004864fSMatthew G. Knepley PetscFunctionBegin; 3619b004864fSMatthew G. Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 3620b004864fSMatthew G. Knepley PetscValidHeaderSpecific(nsym, PETSC_SECTION_SYM_CLASSID, 2); 3621dbbe0bcdSBarry Smith PetscTryTypeMethod(sym, copy, nsym); 36223ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3623b004864fSMatthew G. Knepley } 3624b004864fSMatthew G. Knepley 3625b004864fSMatthew G. Knepley /*@ 3626cab54364SBarry Smith PetscSectionSymDistribute - Distribute the symmetries in accordance with the input `PetscSF` 3627b004864fSMatthew G. Knepley 3628b004864fSMatthew G. Knepley Collective 3629b004864fSMatthew G. Knepley 3630b004864fSMatthew G. Knepley Input Parameters: 3631cab54364SBarry Smith + sym - the `PetscSectionSym` 3632b004864fSMatthew G. Knepley - migrationSF - the distribution map from roots to leaves 3633b004864fSMatthew G. Knepley 36342fe279fdSBarry Smith Output Parameter: 3635b004864fSMatthew G. Knepley . dsym - the redistributed symmetries 3636b004864fSMatthew G. Knepley 3637b004864fSMatthew G. Knepley Level: developer 3638b004864fSMatthew G. Knepley 3639cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()`, `PetscSectionSymLabelSetStratum()`, `PetscSectionGetPointSyms()` 3640b004864fSMatthew G. Knepley @*/ 3641d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymDistribute(PetscSectionSym sym, PetscSF migrationSF, PetscSectionSym *dsym) 3642d71ae5a4SJacob Faibussowitsch { 3643b004864fSMatthew G. Knepley PetscFunctionBegin; 3644b004864fSMatthew G. Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 3645b004864fSMatthew G. Knepley PetscValidHeaderSpecific(migrationSF, PETSCSF_CLASSID, 2); 36464f572ea9SToby Isaac PetscAssertPointer(dsym, 3); 3647dbbe0bcdSBarry Smith PetscTryTypeMethod(sym, distribute, migrationSF, dsym); 36483ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3649b004864fSMatthew G. Knepley } 3650b004864fSMatthew G. Knepley 3651b004864fSMatthew G. Knepley /*@ 365220662ed9SBarry Smith PetscSectionGetUseFieldOffsets - Get the flag indicating if field offsets are used directly in a global section, rather than just the point offset 3653ea844a1aSMatthew Knepley 365440750d41SVaclav Hapla Not Collective 3655ea844a1aSMatthew Knepley 3656ea844a1aSMatthew Knepley Input Parameter: 3657cab54364SBarry Smith . s - the global `PetscSection` 3658ea844a1aSMatthew Knepley 36592fe279fdSBarry Smith Output Parameter: 3660ea844a1aSMatthew Knepley . flg - the flag 3661ea844a1aSMatthew Knepley 3662ea844a1aSMatthew Knepley Level: developer 3663ea844a1aSMatthew Knepley 3664cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSetChart()`, `PetscSectionCreate()` 3665ea844a1aSMatthew Knepley @*/ 3666d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetUseFieldOffsets(PetscSection s, PetscBool *flg) 3667d71ae5a4SJacob Faibussowitsch { 3668ea844a1aSMatthew Knepley PetscFunctionBegin; 3669ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 3670ea844a1aSMatthew Knepley *flg = s->useFieldOff; 36713ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3672ea844a1aSMatthew Knepley } 3673ea844a1aSMatthew Knepley 3674ea844a1aSMatthew Knepley /*@ 3675ea844a1aSMatthew Knepley PetscSectionSetUseFieldOffsets - Set the flag to use field offsets directly in a global section, rather than just the point offset 3676ea844a1aSMatthew Knepley 367740750d41SVaclav Hapla Not Collective 3678ea844a1aSMatthew Knepley 3679ea844a1aSMatthew Knepley Input Parameters: 3680cab54364SBarry Smith + s - the global `PetscSection` 3681ea844a1aSMatthew Knepley - flg - the flag 3682ea844a1aSMatthew Knepley 3683ea844a1aSMatthew Knepley Level: developer 3684ea844a1aSMatthew Knepley 3685cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionGetUseFieldOffsets()`, `PetscSectionSetChart()`, `PetscSectionCreate()` 3686ea844a1aSMatthew Knepley @*/ 3687d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetUseFieldOffsets(PetscSection s, PetscBool flg) 3688d71ae5a4SJacob Faibussowitsch { 3689ea844a1aSMatthew Knepley PetscFunctionBegin; 3690ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 3691ea844a1aSMatthew Knepley s->useFieldOff = flg; 36923ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3693ea844a1aSMatthew Knepley } 3694ea844a1aSMatthew Knepley 3695ea844a1aSMatthew Knepley #define PetscSectionExpandPoints_Loop(TYPE) \ 3696a8f51744SPierre Jolivet do { \ 3697ea844a1aSMatthew Knepley PetscInt i, n, o0, o1, size; \ 3698ea844a1aSMatthew Knepley TYPE *a0 = (TYPE *)origArray, *a1; \ 36999566063dSJacob Faibussowitsch PetscCall(PetscSectionGetStorageSize(s, &size)); \ 37009566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(size, &a1)); \ 3701ea844a1aSMatthew Knepley for (i = 0; i < npoints; i++) { \ 37029566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(origSection, points_[i], &o0)); \ 37039566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s, i, &o1)); \ 37049566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, i, &n)); \ 37059566063dSJacob Faibussowitsch PetscCall(PetscMemcpy(&a1[o1], &a0[o0], n *unitsize)); \ 3706ea844a1aSMatthew Knepley } \ 3707ea844a1aSMatthew Knepley *newArray = (void *)a1; \ 3708a8f51744SPierre Jolivet } while (0) 3709ea844a1aSMatthew Knepley 3710ea844a1aSMatthew Knepley /*@ 3711ea844a1aSMatthew Knepley PetscSectionExtractDofsFromArray - Extracts elements of an array corresponding to DOFs of specified points. 3712ea844a1aSMatthew Knepley 371340750d41SVaclav Hapla Not Collective 3714ea844a1aSMatthew Knepley 3715ea844a1aSMatthew Knepley Input Parameters: 3716cab54364SBarry Smith + origSection - the `PetscSection` describing the layout of the array 3717cab54364SBarry Smith . dataType - `MPI_Datatype` describing the data type of the array (currently only `MPIU_INT`, `MPIU_SCALAR`, `MPIU_REAL`) 371820662ed9SBarry Smith . origArray - the array; its size must be equal to the storage size of `origSection` 371920662ed9SBarry Smith - points - `IS` with points to extract; its indices must lie in the chart of `origSection` 3720ea844a1aSMatthew Knepley 3721ea844a1aSMatthew Knepley Output Parameters: 3722da81f932SPierre Jolivet + newSection - the new `PetscSection` describing the layout of the new array (with points renumbered 0,1,... but preserving numbers of DOFs) 372320662ed9SBarry Smith - newArray - the array of the extracted DOFs; its size is the storage size of `newSection` 3724ea844a1aSMatthew Knepley 3725ea844a1aSMatthew Knepley Level: developer 3726ea844a1aSMatthew Knepley 3727cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionGetChart()`, `PetscSectionGetDof()`, `PetscSectionGetStorageSize()`, `PetscSectionCreate()` 3728ea844a1aSMatthew Knepley @*/ 3729d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionExtractDofsFromArray(PetscSection origSection, MPI_Datatype dataType, const void *origArray, IS points, PetscSection *newSection, void *newArray[]) 3730d71ae5a4SJacob Faibussowitsch { 3731ea844a1aSMatthew Knepley PetscSection s; 3732ea844a1aSMatthew Knepley const PetscInt *points_; 3733ea844a1aSMatthew Knepley PetscInt i, n, npoints, pStart, pEnd; 3734ea844a1aSMatthew Knepley PetscMPIInt unitsize; 3735ea844a1aSMatthew Knepley 3736ea844a1aSMatthew Knepley PetscFunctionBegin; 3737ea844a1aSMatthew Knepley PetscValidHeaderSpecific(origSection, PETSC_SECTION_CLASSID, 1); 37384f572ea9SToby Isaac PetscAssertPointer(origArray, 3); 3739ea844a1aSMatthew Knepley PetscValidHeaderSpecific(points, IS_CLASSID, 4); 37404f572ea9SToby Isaac if (newSection) PetscAssertPointer(newSection, 5); 37414f572ea9SToby Isaac if (newArray) PetscAssertPointer(newArray, 6); 37429566063dSJacob Faibussowitsch PetscCallMPI(MPI_Type_size(dataType, &unitsize)); 37439566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(points, &npoints)); 37449566063dSJacob Faibussowitsch PetscCall(ISGetIndices(points, &points_)); 37459566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(origSection, &pStart, &pEnd)); 37469566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PETSC_COMM_SELF, &s)); 37479566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(s, 0, npoints)); 3748ea844a1aSMatthew Knepley for (i = 0; i < npoints; i++) { 3749c9cc58a2SBarry Smith PetscCheck(points_[i] >= pStart && points_[i] < pEnd, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "point %" PetscInt_FMT " (index %" PetscInt_FMT ") in input IS out of input section's chart", points_[i], i); 37509566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(origSection, points_[i], &n)); 37519566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(s, i, n)); 3752ea844a1aSMatthew Knepley } 37539566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(s)); 3754ea844a1aSMatthew Knepley if (newArray) { 37559371c9d4SSatish Balay if (dataType == MPIU_INT) { 37569371c9d4SSatish Balay PetscSectionExpandPoints_Loop(PetscInt); 37579371c9d4SSatish Balay } else if (dataType == MPIU_SCALAR) { 37589371c9d4SSatish Balay PetscSectionExpandPoints_Loop(PetscScalar); 37599371c9d4SSatish Balay } else if (dataType == MPIU_REAL) { 37609371c9d4SSatish Balay PetscSectionExpandPoints_Loop(PetscReal); 37619371c9d4SSatish Balay } else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "not implemented for this MPI_Datatype"); 3762ea844a1aSMatthew Knepley } 3763ea844a1aSMatthew Knepley if (newSection) { 3764ea844a1aSMatthew Knepley *newSection = s; 3765ea844a1aSMatthew Knepley } else { 37669566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s)); 3767ea844a1aSMatthew Knepley } 37689566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(points, &points_)); 37693ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3770ea844a1aSMatthew Knepley } 3771