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; 40ea844a1aSMatthew Knepley PetscValidPointer(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 81cab54364SBarry Smith Developer Note: 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 172cab54364SBarry Smith Developer Note: 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); 181ea844a1aSMatthew Knepley PetscValidPointer(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: 193cab54364SBarry Smith . section - 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); 245064a246eSJacob Faibussowitsch PetscValidBoolPointer(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); 338dadcf809SJacob Faibussowitsch PetscValidIntPointer(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); 413ea844a1aSMatthew Knepley PetscValidPointer(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); 440ea844a1aSMatthew Knepley if (fieldName) PetscValidCharPointer(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 465583308b6SBarry Smith Developer Note: 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); 475064a246eSJacob Faibussowitsch PetscValidPointer(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 498583308b6SBarry Smith Developer Note: 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()`, 502cab54364SBarry Smith `PetscSectionSetComponentName()`, `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); 508064a246eSJacob Faibussowitsch if (compName) PetscValidCharPointer(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 530cab54364SBarry Smith Developer Note: 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); 5402abc8c78SJacob Faibussowitsch PetscValidIntPointer(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 566583308b6SBarry Smith Developer Note: 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) { 6849371c9d4SSatish Balay PetscValidPointer(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 739cab54364SBarry Smith .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); 745dadcf809SJacob Faibussowitsch PetscValidBoolPointer(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); 80987e637c6Sksagiyam PetscValidBoolPointer(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); 861dadcf809SJacob Faibussowitsch PetscValidIntPointer(numDof, 3); 862c8bf3acbSVaclav 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); 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); 915c8bf3acbSVaclav 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); 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); 9422abc8c78SJacob Faibussowitsch PetscValidIntPointer(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); 1038dadcf809SJacob Faibussowitsch PetscValidIntPointer(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); 11162abc8c78SJacob Faibussowitsch PetscValidIntPointer(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); 1298dadcf809SJacob Faibussowitsch PetscValidIntPointer(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); 1328dadcf809SJacob Faibussowitsch PetscValidIntPointer(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); 1355dadcf809SJacob Faibussowitsch PetscValidIntPointer(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); 1400ea844a1aSMatthew Knepley PetscValidPointer(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 152220662ed9SBarry Smith Developer Note: 152320662ed9SBarry Smith This is a terrible function name 152420662ed9SBarry Smith 152520662ed9SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionCreateGlobalSectionCensored()` 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); 1536ea844a1aSMatthew Knepley PetscValidPointer(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 1635583308b6SBarry Smith Developer Note: 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); 1693ea844a1aSMatthew Knepley PetscValidPointer(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); 1736dadcf809SJacob Faibussowitsch PetscValidIntPointer(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); 17942abc8c78SJacob Faibussowitsch PetscValidIntPointer(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); 18622abc8c78SJacob Faibussowitsch PetscValidIntPointer(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); 1939dadcf809SJacob Faibussowitsch PetscValidIntPointer(fields, 3); 1940ea844a1aSMatthew Knepley PetscValidPointer(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 2025cab54364SBarry Smith Developer Note: 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 2128d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateSubplexSection_Internal(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); 213641f23ed0SMatthew G. Knepley PetscValidPointer(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 2236cab54364SBarry Smith Developer Note: 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; 224441f23ed0SMatthew G. Knepley PetscCall(PetscSectionCreateSubplexSection_Internal(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; 227641f23ed0SMatthew G. Knepley PetscCall(PetscSectionCreateSubplexSection_Internal(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 2344ea844a1aSMatthew Knepley - v - 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 2397fde5e3acSksagiyam - v - 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 2429d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscSectionResetClosurePermutation(PetscSection section) 2430d71ae5a4SJacob Faibussowitsch { 2431c459fbc1SJed Brown PetscSectionClosurePermVal clVal; 2432c459fbc1SJed Brown 2433c459fbc1SJed Brown PetscFunctionBegin; 24343ba16761SJacob Faibussowitsch if (!section->clHash) PetscFunctionReturn(PETSC_SUCCESS); 2435c459fbc1SJed Brown kh_foreach_value(section->clHash, clVal, { 24369566063dSJacob Faibussowitsch PetscCall(PetscFree(clVal.perm)); 24379566063dSJacob Faibussowitsch PetscCall(PetscFree(clVal.invPerm)); 2438c459fbc1SJed Brown }); 2439c459fbc1SJed Brown kh_destroy(ClPerm, section->clHash); 2440c459fbc1SJed Brown section->clHash = NULL; 24413ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2442c459fbc1SJed Brown } 2443c459fbc1SJed Brown 2444ea844a1aSMatthew Knepley /*@ 2445583308b6SBarry Smith PetscSectionReset - Frees all section data, the section is then as if `PetscSectionCreate()` had just been called. 2446ea844a1aSMatthew Knepley 244740750d41SVaclav Hapla Not Collective 2448ea844a1aSMatthew Knepley 24492fe279fdSBarry Smith Input Parameter: 2450cab54364SBarry Smith . s - the `PetscSection` 2451ea844a1aSMatthew Knepley 2452ea844a1aSMatthew Knepley Level: beginner 2453ea844a1aSMatthew Knepley 2454cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()` 2455ea844a1aSMatthew Knepley @*/ 2456d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionReset(PetscSection s) 2457d71ae5a4SJacob Faibussowitsch { 2458b778fa18SValeria Barra PetscInt f, c; 2459ea844a1aSMatthew Knepley 2460ea844a1aSMatthew Knepley PetscFunctionBegin; 2461ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2462ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) { 24639566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->field[f])); 24649566063dSJacob Faibussowitsch PetscCall(PetscFree(s->fieldNames[f])); 246548a46eb9SPierre Jolivet for (c = 0; c < s->numFieldComponents[f]; ++c) PetscCall(PetscFree(s->compNames[f][c])); 24669566063dSJacob Faibussowitsch PetscCall(PetscFree(s->compNames[f])); 2467ea844a1aSMatthew Knepley } 24689566063dSJacob Faibussowitsch PetscCall(PetscFree(s->numFieldComponents)); 24699566063dSJacob Faibussowitsch PetscCall(PetscFree(s->fieldNames)); 24709566063dSJacob Faibussowitsch PetscCall(PetscFree(s->compNames)); 24719566063dSJacob Faibussowitsch PetscCall(PetscFree(s->field)); 24729566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->bc)); 24739566063dSJacob Faibussowitsch PetscCall(PetscFree(s->bcIndices)); 24749566063dSJacob Faibussowitsch PetscCall(PetscFree2(s->atlasDof, s->atlasOff)); 24759566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->clSection)); 24769566063dSJacob Faibussowitsch PetscCall(ISDestroy(&s->clPoints)); 24779566063dSJacob Faibussowitsch PetscCall(ISDestroy(&s->perm)); 24789566063dSJacob Faibussowitsch PetscCall(PetscSectionResetClosurePermutation(s)); 24799566063dSJacob Faibussowitsch PetscCall(PetscSectionSymDestroy(&s->sym)); 24809566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->clSection)); 24819566063dSJacob Faibussowitsch PetscCall(ISDestroy(&s->clPoints)); 248269c11d05SVaclav Hapla PetscCall(PetscSectionInvalidateMaxDof_Internal(s)); 2483ea844a1aSMatthew Knepley s->pStart = -1; 2484ea844a1aSMatthew Knepley s->pEnd = -1; 2485ea844a1aSMatthew Knepley s->maxDof = 0; 2486ea844a1aSMatthew Knepley s->setup = PETSC_FALSE; 2487ea844a1aSMatthew Knepley s->numFields = 0; 2488ea844a1aSMatthew Knepley s->clObj = NULL; 24893ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2490ea844a1aSMatthew Knepley } 2491ea844a1aSMatthew Knepley 2492ea844a1aSMatthew Knepley /*@ 2493583308b6SBarry Smith PetscSectionDestroy - Frees a `PetscSection` 2494ea844a1aSMatthew Knepley 249540750d41SVaclav Hapla Not Collective 2496ea844a1aSMatthew Knepley 24972fe279fdSBarry Smith Input Parameter: 2498cab54364SBarry Smith . s - the `PetscSection` 2499ea844a1aSMatthew Knepley 2500ea844a1aSMatthew Knepley Level: beginner 2501ea844a1aSMatthew Knepley 2502cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionReset()` 2503ea844a1aSMatthew Knepley @*/ 2504d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionDestroy(PetscSection *s) 2505d71ae5a4SJacob Faibussowitsch { 2506ea844a1aSMatthew Knepley PetscFunctionBegin; 25073ba16761SJacob Faibussowitsch if (!*s) PetscFunctionReturn(PETSC_SUCCESS); 250862f17a49SStefano Zampini PetscValidHeaderSpecific(*s, PETSC_SECTION_CLASSID, 1); 2509ea844a1aSMatthew Knepley if (--((PetscObject)(*s))->refct > 0) { 2510ea844a1aSMatthew Knepley *s = NULL; 25113ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2512ea844a1aSMatthew Knepley } 25139566063dSJacob Faibussowitsch PetscCall(PetscSectionReset(*s)); 25149566063dSJacob Faibussowitsch PetscCall(PetscHeaderDestroy(s)); 25153ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2516ea844a1aSMatthew Knepley } 2517ea844a1aSMatthew Knepley 2518d71ae5a4SJacob Faibussowitsch PetscErrorCode VecIntGetValuesSection(PetscInt *baseArray, PetscSection s, PetscInt point, const PetscInt **values) 2519d71ae5a4SJacob Faibussowitsch { 2520ea844a1aSMatthew Knepley const PetscInt p = point - s->pStart; 2521ea844a1aSMatthew Knepley 2522ea844a1aSMatthew Knepley PetscFunctionBegin; 2523ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 2); 2524ea844a1aSMatthew Knepley *values = &baseArray[s->atlasOff[p]]; 25253ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2526ea844a1aSMatthew Knepley } 2527ea844a1aSMatthew Knepley 2528d71ae5a4SJacob Faibussowitsch PetscErrorCode VecIntSetValuesSection(PetscInt *baseArray, PetscSection s, PetscInt point, const PetscInt values[], InsertMode mode) 2529d71ae5a4SJacob Faibussowitsch { 2530ea844a1aSMatthew Knepley PetscInt *array; 2531ea844a1aSMatthew Knepley const PetscInt p = point - s->pStart; 2532ea844a1aSMatthew Knepley const PetscInt orientation = 0; /* Needs to be included for use in closure operations */ 2533ea844a1aSMatthew Knepley PetscInt cDim = 0; 2534ea844a1aSMatthew Knepley 2535ea844a1aSMatthew Knepley PetscFunctionBegin; 2536ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 2); 25379566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cDim)); 2538ea844a1aSMatthew Knepley array = &baseArray[s->atlasOff[p]]; 2539ea844a1aSMatthew Knepley if (!cDim) { 2540ea844a1aSMatthew Knepley if (orientation >= 0) { 2541ea844a1aSMatthew Knepley const PetscInt dim = s->atlasDof[p]; 2542ea844a1aSMatthew Knepley PetscInt i; 2543ea844a1aSMatthew Knepley 2544ea844a1aSMatthew Knepley if (mode == INSERT_VALUES) { 2545ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) array[i] = values[i]; 2546ea844a1aSMatthew Knepley } else { 2547ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) array[i] += values[i]; 2548ea844a1aSMatthew Knepley } 2549ea844a1aSMatthew Knepley } else { 2550ea844a1aSMatthew Knepley PetscInt offset = 0; 2551ea844a1aSMatthew Knepley PetscInt j = -1, field, i; 2552ea844a1aSMatthew Knepley 2553ea844a1aSMatthew Knepley for (field = 0; field < s->numFields; ++field) { 2554ea844a1aSMatthew Knepley const PetscInt dim = s->field[field]->atlasDof[p]; 2555ea844a1aSMatthew Knepley 2556ea844a1aSMatthew Knepley for (i = dim - 1; i >= 0; --i) array[++j] = values[i + offset]; 2557ea844a1aSMatthew Knepley offset += dim; 2558ea844a1aSMatthew Knepley } 2559ea844a1aSMatthew Knepley } 2560ea844a1aSMatthew Knepley } else { 2561ea844a1aSMatthew Knepley if (orientation >= 0) { 2562ea844a1aSMatthew Knepley const PetscInt dim = s->atlasDof[p]; 2563ea844a1aSMatthew Knepley PetscInt cInd = 0, i; 2564ea844a1aSMatthew Knepley const PetscInt *cDof; 2565ea844a1aSMatthew Knepley 25669566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s, point, &cDof)); 2567ea844a1aSMatthew Knepley if (mode == INSERT_VALUES) { 2568ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) { 25699371c9d4SSatish Balay if ((cInd < cDim) && (i == cDof[cInd])) { 25709371c9d4SSatish Balay ++cInd; 25719371c9d4SSatish Balay continue; 25729371c9d4SSatish Balay } 2573ea844a1aSMatthew Knepley array[i] = values[i]; 2574ea844a1aSMatthew Knepley } 2575ea844a1aSMatthew Knepley } else { 2576ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) { 25779371c9d4SSatish Balay if ((cInd < cDim) && (i == cDof[cInd])) { 25789371c9d4SSatish Balay ++cInd; 25799371c9d4SSatish Balay continue; 25809371c9d4SSatish Balay } 2581ea844a1aSMatthew Knepley array[i] += values[i]; 2582ea844a1aSMatthew Knepley } 2583ea844a1aSMatthew Knepley } 2584ea844a1aSMatthew Knepley } else { 2585ea844a1aSMatthew Knepley const PetscInt *cDof; 2586ea844a1aSMatthew Knepley PetscInt offset = 0; 2587ea844a1aSMatthew Knepley PetscInt cOffset = 0; 2588ea844a1aSMatthew Knepley PetscInt j = 0, field; 2589ea844a1aSMatthew Knepley 25909566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s, point, &cDof)); 2591ea844a1aSMatthew Knepley for (field = 0; field < s->numFields; ++field) { 2592ea844a1aSMatthew Knepley const PetscInt dim = s->field[field]->atlasDof[p]; /* PetscSectionGetFieldDof() */ 2593ea844a1aSMatthew Knepley const PetscInt tDim = s->field[field]->bc->atlasDof[p]; /* PetscSectionGetFieldConstraintDof() */ 2594ea844a1aSMatthew Knepley const PetscInt sDim = dim - tDim; 2595ea844a1aSMatthew Knepley PetscInt cInd = 0, i, k; 2596ea844a1aSMatthew Knepley 2597ea844a1aSMatthew Knepley for (i = 0, k = dim + offset - 1; i < dim; ++i, ++j, --k) { 25989371c9d4SSatish Balay if ((cInd < sDim) && (j == cDof[cInd + cOffset])) { 25999371c9d4SSatish Balay ++cInd; 26009371c9d4SSatish Balay continue; 26019371c9d4SSatish Balay } 2602ea844a1aSMatthew Knepley array[j] = values[k]; 2603ea844a1aSMatthew Knepley } 2604ea844a1aSMatthew Knepley offset += dim; 2605ea844a1aSMatthew Knepley cOffset += dim - tDim; 2606ea844a1aSMatthew Knepley } 2607ea844a1aSMatthew Knepley } 2608ea844a1aSMatthew Knepley } 26093ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2610ea844a1aSMatthew Knepley } 2611ea844a1aSMatthew Knepley 2612ea844a1aSMatthew Knepley /*@C 261320662ed9SBarry Smith PetscSectionHasConstraints - Determine whether a `PetscSection` has constrained dofs 2614ea844a1aSMatthew Knepley 261540750d41SVaclav Hapla Not Collective 2616ea844a1aSMatthew Knepley 2617ea844a1aSMatthew Knepley Input Parameter: 2618cab54364SBarry Smith . s - The `PetscSection` 2619ea844a1aSMatthew Knepley 2620ea844a1aSMatthew Knepley Output Parameter: 2621ea844a1aSMatthew Knepley . hasConstraints - flag indicating that the section has constrained dofs 2622ea844a1aSMatthew Knepley 2623ea844a1aSMatthew Knepley Level: intermediate 2624ea844a1aSMatthew Knepley 2625cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSetConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection` 2626ea844a1aSMatthew Knepley @*/ 2627d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionHasConstraints(PetscSection s, PetscBool *hasConstraints) 2628d71ae5a4SJacob Faibussowitsch { 2629ea844a1aSMatthew Knepley PetscFunctionBegin; 2630ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2631dadcf809SJacob Faibussowitsch PetscValidBoolPointer(hasConstraints, 2); 2632ea844a1aSMatthew Knepley *hasConstraints = s->bc ? PETSC_TRUE : PETSC_FALSE; 26333ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2634ea844a1aSMatthew Knepley } 2635ea844a1aSMatthew Knepley 2636ea844a1aSMatthew Knepley /*@C 263720662ed9SBarry Smith PetscSectionGetConstraintIndices - Get the point dof numbers, in [0, dof), which are constrained for a given point 2638ea844a1aSMatthew Knepley 263940750d41SVaclav Hapla Not Collective 2640ea844a1aSMatthew Knepley 2641ea844a1aSMatthew Knepley Input Parameters: 2642cab54364SBarry Smith + s - The `PetscSection` 2643ea844a1aSMatthew Knepley - point - The point 2644ea844a1aSMatthew Knepley 2645ea844a1aSMatthew Knepley Output Parameter: 2646ea844a1aSMatthew Knepley . indices - The constrained dofs 2647ea844a1aSMatthew Knepley 2648ea844a1aSMatthew Knepley Level: intermediate 2649ea844a1aSMatthew Knepley 2650cab54364SBarry Smith Fortran Note: 265120662ed9SBarry Smith Use `PetscSectionGetConstraintIndicesF90()` and `PetscSectionRestoreConstraintIndicesF90()` 2652cab54364SBarry Smith 2653cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSetConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection` 2654ea844a1aSMatthew Knepley @*/ 2655d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetConstraintIndices(PetscSection s, PetscInt point, const PetscInt **indices) 2656d71ae5a4SJacob Faibussowitsch { 2657ea844a1aSMatthew Knepley PetscFunctionBegin; 2658ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2659ea844a1aSMatthew Knepley if (s->bc) { 26609566063dSJacob Faibussowitsch PetscCall(VecIntGetValuesSection(s->bcIndices, s->bc, point, indices)); 2661ea844a1aSMatthew Knepley } else *indices = NULL; 26623ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2663ea844a1aSMatthew Knepley } 2664ea844a1aSMatthew Knepley 2665ea844a1aSMatthew Knepley /*@C 2666ea844a1aSMatthew Knepley PetscSectionSetConstraintIndices - Set the point dof numbers, in [0, dof), which are constrained 2667ea844a1aSMatthew Knepley 266840750d41SVaclav Hapla Not Collective 2669ea844a1aSMatthew Knepley 2670ea844a1aSMatthew Knepley Input Parameters: 2671cab54364SBarry Smith + s - The `PetscSection` 2672ea844a1aSMatthew Knepley . point - The point 2673ea844a1aSMatthew Knepley - indices - The constrained dofs 2674ea844a1aSMatthew Knepley 2675ea844a1aSMatthew Knepley Level: intermediate 2676ea844a1aSMatthew Knepley 2677cab54364SBarry Smith Fortran Note: 2678cab54364SBarry Smith Use `PetscSectionSetConstraintIndicesF90()` 2679cab54364SBarry Smith 2680cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionGetConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection` 2681ea844a1aSMatthew Knepley @*/ 2682d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetConstraintIndices(PetscSection s, PetscInt point, const PetscInt indices[]) 2683d71ae5a4SJacob Faibussowitsch { 2684ea844a1aSMatthew Knepley PetscFunctionBegin; 2685ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2686ea844a1aSMatthew Knepley if (s->bc) { 2687d57bb9dbSMatthew G. Knepley const PetscInt dof = s->atlasDof[point]; 2688d57bb9dbSMatthew G. Knepley const PetscInt cdof = s->bc->atlasDof[point]; 2689d57bb9dbSMatthew G. Knepley PetscInt d; 2690d57bb9dbSMatthew G. Knepley 2691ad540459SPierre 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]); 26929566063dSJacob Faibussowitsch PetscCall(VecIntSetValuesSection(s->bcIndices, s->bc, point, indices, INSERT_VALUES)); 2693ea844a1aSMatthew Knepley } 26943ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2695ea844a1aSMatthew Knepley } 2696ea844a1aSMatthew Knepley 2697ea844a1aSMatthew Knepley /*@C 2698ea844a1aSMatthew Knepley PetscSectionGetFieldConstraintIndices - Get the field dof numbers, in [0, fdof), which are constrained 2699ea844a1aSMatthew Knepley 270040750d41SVaclav Hapla Not Collective 2701ea844a1aSMatthew Knepley 2702ea844a1aSMatthew Knepley Input Parameters: 2703cab54364SBarry Smith + s - The `PetscSection` 2704ea844a1aSMatthew Knepley . field - The field number 2705ea844a1aSMatthew Knepley - point - The point 2706ea844a1aSMatthew Knepley 2707ea844a1aSMatthew Knepley Output Parameter: 27089759eb26SJed Brown . indices - The constrained dofs sorted in ascending order 2709ea844a1aSMatthew Knepley 2710ea844a1aSMatthew Knepley Level: intermediate 2711ea844a1aSMatthew Knepley 2712cab54364SBarry Smith Note: 2713cab54364SBarry 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()`. 2714cab54364SBarry Smith 2715cab54364SBarry Smith Fortran Note: 271620662ed9SBarry Smith Use `PetscSectionGetFieldConstraintIndicesF90()` and `PetscSectionRestoreFieldConstraintIndicesF90()` 2717cab54364SBarry Smith 2718cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSetFieldConstraintIndices()`, `PetscSectionGetConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection` 2719ea844a1aSMatthew Knepley @*/ 2720d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldConstraintIndices(PetscSection s, PetscInt point, PetscInt field, const PetscInt **indices) 2721d71ae5a4SJacob Faibussowitsch { 2722ea844a1aSMatthew Knepley PetscFunctionBegin; 2723ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2724dadcf809SJacob Faibussowitsch PetscValidPointer(indices, 4); 27252abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 27269566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s->field[field], point, indices)); 27273ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2728ea844a1aSMatthew Knepley } 2729ea844a1aSMatthew Knepley 2730ea844a1aSMatthew Knepley /*@C 2731ea844a1aSMatthew Knepley PetscSectionSetFieldConstraintIndices - Set the field dof numbers, in [0, fdof), which are constrained 2732ea844a1aSMatthew Knepley 273340750d41SVaclav Hapla Not Collective 2734ea844a1aSMatthew Knepley 2735ea844a1aSMatthew Knepley Input Parameters: 2736cab54364SBarry Smith + s - The `PetscSection` 2737ea844a1aSMatthew Knepley . point - The point 2738ea844a1aSMatthew Knepley . field - The field number 2739ea844a1aSMatthew Knepley - indices - The constrained dofs 2740ea844a1aSMatthew Knepley 2741ea844a1aSMatthew Knepley Level: intermediate 2742ea844a1aSMatthew Knepley 2743cab54364SBarry Smith Fortran Note: 2744cab54364SBarry Smith Use `PetscSectionSetFieldConstraintIndicesF90()` 2745cab54364SBarry Smith 2746cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSetConstraintIndices()`, `PetscSectionGetFieldConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection` 2747ea844a1aSMatthew Knepley @*/ 2748d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldConstraintIndices(PetscSection s, PetscInt point, PetscInt field, const PetscInt indices[]) 2749d71ae5a4SJacob Faibussowitsch { 2750ea844a1aSMatthew Knepley PetscFunctionBegin; 2751ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 27522abc8c78SJacob Faibussowitsch if (PetscDefined(USE_DEBUG)) { 2753e2bfaee7SMatthew G. Knepley PetscInt nfdof; 27542abc8c78SJacob Faibussowitsch 27559566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, point, field, &nfdof)); 2756e2bfaee7SMatthew G. Knepley if (nfdof) PetscValidIntPointer(indices, 4); 27572abc8c78SJacob Faibussowitsch } 27582abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 27599566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(s->field[field], point, indices)); 27603ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2761ea844a1aSMatthew Knepley } 2762ea844a1aSMatthew Knepley 2763ea844a1aSMatthew Knepley /*@ 2764ea844a1aSMatthew Knepley PetscSectionPermute - Reorder the section according to the input point permutation 2765ea844a1aSMatthew Knepley 276640750d41SVaclav Hapla Collective 2767ea844a1aSMatthew Knepley 2768d8d19677SJose E. Roman Input Parameters: 2769cab54364SBarry Smith + section - The `PetscSection` object 2770ea844a1aSMatthew Knepley - perm - The point permutation, old point p becomes new point perm[p] 2771ea844a1aSMatthew Knepley 2772ea844a1aSMatthew Knepley Output Parameter: 2773cab54364SBarry Smith . sectionNew - The permuted `PetscSection` 2774ea844a1aSMatthew Knepley 2775ea844a1aSMatthew Knepley Level: intermediate 2776ea844a1aSMatthew Knepley 2777583308b6SBarry Smith Note: 2778583308b6SBarry Smith The data and the access to the data via `PetscSectionGetFieldOffset()` and `PetscSectionGetOffset()` are both changed in `sectionNew` 2779583308b6SBarry Smith 2780583308b6SBarry Smith Compare to `PetscSectionSetPermutation()` 2781583308b6SBarry Smith 2782583308b6SBarry Smith .seealso: [PetscSection](sec_petscsection), `IS`, `PetscSection`, `MatPermute()`, `PetscSectionSetPermutation()` 2783ea844a1aSMatthew Knepley @*/ 2784d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionPermute(PetscSection section, IS permutation, PetscSection *sectionNew) 2785d71ae5a4SJacob Faibussowitsch { 2786ea844a1aSMatthew Knepley PetscSection s = section, sNew; 2787ea844a1aSMatthew Knepley const PetscInt *perm; 2788b778fa18SValeria Barra PetscInt numFields, f, c, numPoints, pStart, pEnd, p; 2789ea844a1aSMatthew Knepley 2790ea844a1aSMatthew Knepley PetscFunctionBegin; 2791ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 2792ea844a1aSMatthew Knepley PetscValidHeaderSpecific(permutation, IS_CLASSID, 2); 2793ea844a1aSMatthew Knepley PetscValidPointer(sectionNew, 3); 27949566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), &sNew)); 27959566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s, &numFields)); 27969566063dSJacob Faibussowitsch if (numFields) PetscCall(PetscSectionSetNumFields(sNew, numFields)); 2797ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 2798ea844a1aSMatthew Knepley const char *name; 2799ea844a1aSMatthew Knepley PetscInt numComp; 2800ea844a1aSMatthew Knepley 28019566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldName(s, f, &name)); 28029566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldName(sNew, f, name)); 28039566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s, f, &numComp)); 28049566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(sNew, f, numComp)); 2805b778fa18SValeria Barra for (c = 0; c < s->numFieldComponents[f]; ++c) { 28069566063dSJacob Faibussowitsch PetscCall(PetscSectionGetComponentName(s, f, c, &name)); 28079566063dSJacob Faibussowitsch PetscCall(PetscSectionSetComponentName(sNew, f, c, name)); 2808b778fa18SValeria Barra } 2809ea844a1aSMatthew Knepley } 28109566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(permutation, &numPoints)); 28119566063dSJacob Faibussowitsch PetscCall(ISGetIndices(permutation, &perm)); 28129566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 28139566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(sNew, pStart, pEnd)); 281408401ef6SPierre 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); 2815ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2816ea844a1aSMatthew Knepley PetscInt dof, cdof; 2817ea844a1aSMatthew Knepley 28189566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 28199566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(sNew, perm[p], dof)); 28209566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof)); 28219566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetConstraintDof(sNew, perm[p], cdof)); 2822ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 28239566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, f, &dof)); 28249566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldDof(sNew, perm[p], f, dof)); 28259566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, f, &cdof)); 28269566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetFieldConstraintDof(sNew, perm[p], f, cdof)); 2827ea844a1aSMatthew Knepley } 2828ea844a1aSMatthew Knepley } 28299566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(sNew)); 2830ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2831ea844a1aSMatthew Knepley const PetscInt *cind; 2832ea844a1aSMatthew Knepley PetscInt cdof; 2833ea844a1aSMatthew Knepley 28349566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof)); 2835ea844a1aSMatthew Knepley if (cdof) { 28369566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s, p, &cind)); 28379566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(sNew, perm[p], cind)); 2838ea844a1aSMatthew Knepley } 2839ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 28409566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, f, &cdof)); 2841ea844a1aSMatthew Knepley if (cdof) { 28429566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(s, p, f, &cind)); 28439566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldConstraintIndices(sNew, perm[p], f, cind)); 2844ea844a1aSMatthew Knepley } 2845ea844a1aSMatthew Knepley } 2846ea844a1aSMatthew Knepley } 28479566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(permutation, &perm)); 2848ea844a1aSMatthew Knepley *sectionNew = sNew; 28493ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2850ea844a1aSMatthew Knepley } 2851ea844a1aSMatthew Knepley 2852ea844a1aSMatthew Knepley /*@ 285320662ed9SBarry Smith PetscSectionSetClosureIndex - Create an internal data structure to speed up closure queries. 2854ea844a1aSMatthew Knepley 285540750d41SVaclav Hapla Collective 2856ea844a1aSMatthew Knepley 2857ea844a1aSMatthew Knepley Input Parameters: 2858cab54364SBarry Smith + section - The `PetscSection` 2859cab54364SBarry Smith . obj - A `PetscObject` which serves as the key for this index 2860cab54364SBarry Smith . clSection - `PetscSection` giving the size of the closure of each point 2861cab54364SBarry Smith - clPoints - `IS` giving the points in each closure 2862ea844a1aSMatthew Knepley 2863ea844a1aSMatthew Knepley Level: advanced 2864ea844a1aSMatthew Knepley 2865cab54364SBarry Smith Note: 286620662ed9SBarry Smith This function creates an internal map from each point to its closure. We compress out closure points with no dofs in this section. 286720662ed9SBarry Smith 286820662ed9SBarry Smith Developer Note: 286920662ed9SBarry Smith The information provided here is completely opaque 2870cab54364SBarry Smith 2871cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetClosureIndex()`, `DMPlexCreateClosureIndex()` 2872ea844a1aSMatthew Knepley @*/ 2873d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetClosureIndex(PetscSection section, PetscObject obj, PetscSection clSection, IS clPoints) 2874d71ae5a4SJacob Faibussowitsch { 2875ea844a1aSMatthew Knepley PetscFunctionBegin; 28763e03ebd8SStefano Zampini PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 28773e03ebd8SStefano Zampini PetscValidHeaderSpecific(clSection, PETSC_SECTION_CLASSID, 3); 28783e03ebd8SStefano Zampini PetscValidHeaderSpecific(clPoints, IS_CLASSID, 4); 28799566063dSJacob Faibussowitsch if (section->clObj != obj) PetscCall(PetscSectionResetClosurePermutation(section)); 2880ea844a1aSMatthew Knepley section->clObj = obj; 28819566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)clSection)); 28829566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)clPoints)); 28839566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(§ion->clSection)); 28849566063dSJacob Faibussowitsch PetscCall(ISDestroy(§ion->clPoints)); 2885ea844a1aSMatthew Knepley section->clSection = clSection; 2886ea844a1aSMatthew Knepley section->clPoints = clPoints; 28873ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2888ea844a1aSMatthew Knepley } 2889ea844a1aSMatthew Knepley 2890ea844a1aSMatthew Knepley /*@ 2891cab54364SBarry Smith PetscSectionGetClosureIndex - Get the cache of points in the closure of each point in the section set with `PetscSectionSetClosureIndex()` 2892ea844a1aSMatthew Knepley 289340750d41SVaclav Hapla Collective 2894ea844a1aSMatthew Knepley 2895ea844a1aSMatthew Knepley Input Parameters: 2896cab54364SBarry Smith + section - The `PetscSection` 2897cab54364SBarry Smith - obj - A `PetscObject` which serves as the key for this index 2898ea844a1aSMatthew Knepley 2899ea844a1aSMatthew Knepley Output Parameters: 2900cab54364SBarry Smith + clSection - `PetscSection` giving the size of the closure of each point 2901cab54364SBarry Smith - clPoints - `IS` giving the points in each closure 2902ea844a1aSMatthew Knepley 2903ea844a1aSMatthew Knepley Level: advanced 2904ea844a1aSMatthew Knepley 2905cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSetClosureIndex()`, `DMPlexCreateClosureIndex()` 2906ea844a1aSMatthew Knepley @*/ 2907d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosureIndex(PetscSection section, PetscObject obj, PetscSection *clSection, IS *clPoints) 2908d71ae5a4SJacob Faibussowitsch { 2909ea844a1aSMatthew Knepley PetscFunctionBegin; 2910ea844a1aSMatthew Knepley if (section->clObj == obj) { 2911ea844a1aSMatthew Knepley if (clSection) *clSection = section->clSection; 2912ea844a1aSMatthew Knepley if (clPoints) *clPoints = section->clPoints; 2913ea844a1aSMatthew Knepley } else { 2914ea844a1aSMatthew Knepley if (clSection) *clSection = NULL; 2915ea844a1aSMatthew Knepley if (clPoints) *clPoints = NULL; 2916ea844a1aSMatthew Knepley } 29173ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2918ea844a1aSMatthew Knepley } 2919ea844a1aSMatthew Knepley 2920d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetClosurePermutation_Internal(PetscSection section, PetscObject obj, PetscInt depth, PetscInt clSize, PetscCopyMode mode, PetscInt *clPerm) 2921d71ae5a4SJacob Faibussowitsch { 2922ea844a1aSMatthew Knepley PetscInt i; 2923c459fbc1SJed Brown khiter_t iter; 2924c459fbc1SJed Brown int new_entry; 2925c459fbc1SJed Brown PetscSectionClosurePermKey key = {depth, clSize}; 2926c459fbc1SJed Brown PetscSectionClosurePermVal *val; 2927ea844a1aSMatthew Knepley 2928ea844a1aSMatthew Knepley PetscFunctionBegin; 2929ea844a1aSMatthew Knepley if (section->clObj != obj) { 29309566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(§ion->clSection)); 29319566063dSJacob Faibussowitsch PetscCall(ISDestroy(§ion->clPoints)); 2932ea844a1aSMatthew Knepley } 2933ea844a1aSMatthew Knepley section->clObj = obj; 29349566063dSJacob Faibussowitsch if (!section->clHash) PetscCall(PetscClPermCreate(§ion->clHash)); 2935c459fbc1SJed Brown iter = kh_put(ClPerm, section->clHash, key, &new_entry); 2936c459fbc1SJed Brown val = &kh_val(section->clHash, iter); 2937c459fbc1SJed Brown if (!new_entry) { 29389566063dSJacob Faibussowitsch PetscCall(PetscFree(val->perm)); 29399566063dSJacob Faibussowitsch PetscCall(PetscFree(val->invPerm)); 2940c459fbc1SJed Brown } 2941ea844a1aSMatthew Knepley if (mode == PETSC_COPY_VALUES) { 29429566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(clSize, &val->perm)); 29439566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(val->perm, clPerm, clSize)); 2944ea844a1aSMatthew Knepley } else if (mode == PETSC_OWN_POINTER) { 2945c459fbc1SJed Brown val->perm = clPerm; 2946ea844a1aSMatthew Knepley } else SETERRQ(PetscObjectComm(obj), PETSC_ERR_SUP, "Do not support borrowed arrays"); 29479566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(clSize, &val->invPerm)); 2948c459fbc1SJed Brown for (i = 0; i < clSize; ++i) val->invPerm[clPerm[i]] = i; 29493ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2950ea844a1aSMatthew Knepley } 2951ea844a1aSMatthew Knepley 2952ea844a1aSMatthew Knepley /*@ 2953c459fbc1SJed Brown PetscSectionSetClosurePermutation - Set the dof permutation for the closure of each cell in the section, meaning clPerm[newIndex] = oldIndex. 2954ea844a1aSMatthew Knepley 2955ea844a1aSMatthew Knepley Not Collective 2956ea844a1aSMatthew Knepley 2957ea844a1aSMatthew Knepley Input Parameters: 2958cab54364SBarry Smith + section - The `PetscSection` 2959cab54364SBarry Smith . obj - A `PetscObject` which serves as the key for this index (usually a `DM`) 2960c459fbc1SJed Brown . depth - Depth of points on which to apply the given permutation 2961ea844a1aSMatthew Knepley - perm - Permutation of the cell dof closure 2962ea844a1aSMatthew Knepley 2963cab54364SBarry Smith Level: intermediate 2964cab54364SBarry Smith 2965cab54364SBarry Smith Notes: 2966c459fbc1SJed Brown The specified permutation will only be applied to points at depth whose closure size matches the length of perm. In a 2967c459fbc1SJed Brown mixed-topology or variable-degree finite element space, this function can be called multiple times at each depth for 2968c459fbc1SJed Brown each topology and degree. 2969c459fbc1SJed Brown 2970c459fbc1SJed Brown This approach assumes that (depth, len(perm)) uniquely identifies the desired permutation; this might not be true for 2971c459fbc1SJed Brown exotic/enriched spaces on mixed topology meshes. 2972ea844a1aSMatthew Knepley 2973cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `IS`, `PetscSectionGetClosurePermutation()`, `PetscSectionGetClosureIndex()`, `DMPlexCreateClosureIndex()`, `PetscCopyMode` 2974ea844a1aSMatthew Knepley @*/ 2975d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetClosurePermutation(PetscSection section, PetscObject obj, PetscInt depth, IS perm) 2976d71ae5a4SJacob Faibussowitsch { 2977ea844a1aSMatthew Knepley const PetscInt *clPerm = NULL; 2978ea844a1aSMatthew Knepley PetscInt clSize = 0; 2979ea844a1aSMatthew Knepley 2980ea844a1aSMatthew Knepley PetscFunctionBegin; 2981ea844a1aSMatthew Knepley if (perm) { 29829566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(perm, &clSize)); 29839566063dSJacob Faibussowitsch PetscCall(ISGetIndices(perm, &clPerm)); 2984ea844a1aSMatthew Knepley } 29859566063dSJacob Faibussowitsch PetscCall(PetscSectionSetClosurePermutation_Internal(section, obj, depth, clSize, PETSC_COPY_VALUES, (PetscInt *)clPerm)); 29869566063dSJacob Faibussowitsch if (perm) PetscCall(ISRestoreIndices(perm, &clPerm)); 29873ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2988ea844a1aSMatthew Knepley } 2989ea844a1aSMatthew Knepley 2990d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosurePermutation_Internal(PetscSection section, PetscObject obj, PetscInt depth, PetscInt size, const PetscInt *perm[]) 2991d71ae5a4SJacob Faibussowitsch { 2992ea844a1aSMatthew Knepley PetscFunctionBegin; 2993ea844a1aSMatthew Knepley if (section->clObj == obj) { 2994c459fbc1SJed Brown PetscSectionClosurePermKey k = {depth, size}; 2995c459fbc1SJed Brown PetscSectionClosurePermVal v; 29969566063dSJacob Faibussowitsch PetscCall(PetscClPermGet(section->clHash, k, &v)); 2997c459fbc1SJed Brown if (perm) *perm = v.perm; 2998ea844a1aSMatthew Knepley } else { 2999ea844a1aSMatthew Knepley if (perm) *perm = NULL; 3000ea844a1aSMatthew Knepley } 30013ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3002ea844a1aSMatthew Knepley } 3003ea844a1aSMatthew Knepley 3004ea844a1aSMatthew Knepley /*@ 3005ea844a1aSMatthew Knepley PetscSectionGetClosurePermutation - Get the dof permutation for the closure of each cell in the section, meaning clPerm[newIndex] = oldIndex. 3006ea844a1aSMatthew Knepley 300740750d41SVaclav Hapla Not Collective 3008ea844a1aSMatthew Knepley 3009ea844a1aSMatthew Knepley Input Parameters: 3010cab54364SBarry Smith + section - The `PetscSection` 3011cab54364SBarry Smith . obj - A `PetscObject` which serves as the key for this index (usually a DM) 3012c459fbc1SJed Brown . depth - Depth stratum on which to obtain closure permutation 3013c459fbc1SJed Brown - clSize - Closure size to be permuted (e.g., may vary with element topology and degree) 3014ea844a1aSMatthew Knepley 3015ea844a1aSMatthew Knepley Output Parameter: 3016ea844a1aSMatthew Knepley . perm - The dof closure permutation 3017ea844a1aSMatthew Knepley 3018ea844a1aSMatthew Knepley Level: intermediate 3019ea844a1aSMatthew Knepley 3020cab54364SBarry Smith Note: 3021cab54364SBarry Smith The user must destroy the `IS` that is returned. 3022cab54364SBarry Smith 3023cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `IS`, `PetscSectionSetClosurePermutation()`, `PetscSectionGetClosureInversePermutation()`, `PetscSectionGetClosureIndex()`, `PetscSectionSetClosureIndex()`, `DMPlexCreateClosureIndex()` 3024ea844a1aSMatthew Knepley @*/ 3025d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosurePermutation(PetscSection section, PetscObject obj, PetscInt depth, PetscInt clSize, IS *perm) 3026d71ae5a4SJacob Faibussowitsch { 3027ea844a1aSMatthew Knepley const PetscInt *clPerm; 3028ea844a1aSMatthew Knepley 3029ea844a1aSMatthew Knepley PetscFunctionBegin; 30309566063dSJacob Faibussowitsch PetscCall(PetscSectionGetClosurePermutation_Internal(section, obj, depth, clSize, &clPerm)); 30319566063dSJacob Faibussowitsch PetscCall(ISCreateGeneral(PETSC_COMM_SELF, clSize, clPerm, PETSC_USE_POINTER, perm)); 30323ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3033ea844a1aSMatthew Knepley } 3034ea844a1aSMatthew Knepley 3035d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosureInversePermutation_Internal(PetscSection section, PetscObject obj, PetscInt depth, PetscInt size, const PetscInt *perm[]) 3036d71ae5a4SJacob Faibussowitsch { 3037ea844a1aSMatthew Knepley PetscFunctionBegin; 3038c459fbc1SJed Brown if (section->clObj == obj && section->clHash) { 3039c459fbc1SJed Brown PetscSectionClosurePermKey k = {depth, size}; 3040c459fbc1SJed Brown PetscSectionClosurePermVal v; 30419566063dSJacob Faibussowitsch PetscCall(PetscClPermGet(section->clHash, k, &v)); 3042c459fbc1SJed Brown if (perm) *perm = v.invPerm; 3043ea844a1aSMatthew Knepley } else { 3044ea844a1aSMatthew Knepley if (perm) *perm = NULL; 3045ea844a1aSMatthew Knepley } 30463ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3047ea844a1aSMatthew Knepley } 3048ea844a1aSMatthew Knepley 3049ea844a1aSMatthew Knepley /*@ 3050ea844a1aSMatthew Knepley PetscSectionGetClosureInversePermutation - Get the inverse dof permutation for the closure of each cell in the section, meaning clPerm[oldIndex] = newIndex. 3051ea844a1aSMatthew Knepley 305240750d41SVaclav Hapla Not Collective 3053ea844a1aSMatthew Knepley 3054ea844a1aSMatthew Knepley Input Parameters: 3055cab54364SBarry Smith + section - The `PetscSection` 3056cab54364SBarry Smith . obj - A `PetscObject` which serves as the key for this index (usually a `DM`) 3057c459fbc1SJed Brown . depth - Depth stratum on which to obtain closure permutation 3058c459fbc1SJed Brown - clSize - Closure size to be permuted (e.g., may vary with element topology and degree) 3059ea844a1aSMatthew Knepley 30602fe279fdSBarry Smith Output Parameter: 3061c459fbc1SJed Brown . perm - The dof closure permutation 3062ea844a1aSMatthew Knepley 3063ea844a1aSMatthew Knepley Level: intermediate 3064ea844a1aSMatthew Knepley 3065cab54364SBarry Smith Note: 3066cab54364SBarry Smith The user must destroy the `IS` that is returned. 3067cab54364SBarry Smith 3068cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `IS`, `PetscSectionSetClosurePermutation()`, `PetscSectionGetClosureIndex()`, `PetscSectionSetClosureIndex()`, `DMPlexCreateClosureIndex()` 3069ea844a1aSMatthew Knepley @*/ 3070d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosureInversePermutation(PetscSection section, PetscObject obj, PetscInt depth, PetscInt clSize, IS *perm) 3071d71ae5a4SJacob Faibussowitsch { 3072ea844a1aSMatthew Knepley const PetscInt *clPerm; 3073ea844a1aSMatthew Knepley 3074ea844a1aSMatthew Knepley PetscFunctionBegin; 30759566063dSJacob Faibussowitsch PetscCall(PetscSectionGetClosureInversePermutation_Internal(section, obj, depth, clSize, &clPerm)); 30769566063dSJacob Faibussowitsch PetscCall(ISCreateGeneral(PETSC_COMM_SELF, clSize, clPerm, PETSC_USE_POINTER, perm)); 30773ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3078ea844a1aSMatthew Knepley } 3079ea844a1aSMatthew Knepley 3080ea844a1aSMatthew Knepley /*@ 3081583308b6SBarry Smith PetscSectionGetField - Get the `PetscSection` associated with a single field 3082ea844a1aSMatthew Knepley 3083ea844a1aSMatthew Knepley Input Parameters: 3084cab54364SBarry Smith + s - The `PetscSection` 3085ea844a1aSMatthew Knepley - field - The field number 3086ea844a1aSMatthew Knepley 3087ea844a1aSMatthew Knepley Output Parameter: 3088583308b6SBarry Smith . subs - The `PetscSection` for the given field, note the chart of `subs` is not set 3089ea844a1aSMatthew Knepley 3090ea844a1aSMatthew Knepley Level: intermediate 3091ea844a1aSMatthew Knepley 3092cab54364SBarry Smith Note: 3093cab54364SBarry Smith Does not increase the reference count of the selected sub-section. There is no matching `PetscSectionRestoreField()` 3094cab54364SBarry Smith 3095cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `IS`, `PetscSectionSetNumFields()` 3096ea844a1aSMatthew Knepley @*/ 3097d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetField(PetscSection s, PetscInt field, PetscSection *subs) 3098d71ae5a4SJacob Faibussowitsch { 3099ea844a1aSMatthew Knepley PetscFunctionBegin; 3100ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 3101ea844a1aSMatthew Knepley PetscValidPointer(subs, 3); 31022abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 3103ea844a1aSMatthew Knepley *subs = s->field[field]; 31043ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3105ea844a1aSMatthew Knepley } 3106ea844a1aSMatthew Knepley 3107ea844a1aSMatthew Knepley PetscClassId PETSC_SECTION_SYM_CLASSID; 3108ea844a1aSMatthew Knepley PetscFunctionList PetscSectionSymList = NULL; 3109ea844a1aSMatthew Knepley 3110ea844a1aSMatthew Knepley /*@ 3111cab54364SBarry Smith PetscSectionSymCreate - Creates an empty `PetscSectionSym` object. 3112ea844a1aSMatthew Knepley 3113ea844a1aSMatthew Knepley Collective 3114ea844a1aSMatthew Knepley 3115ea844a1aSMatthew Knepley Input Parameter: 3116ea844a1aSMatthew Knepley . comm - the MPI communicator 3117ea844a1aSMatthew Knepley 3118ea844a1aSMatthew Knepley Output Parameter: 3119ea844a1aSMatthew Knepley . sym - pointer to the new set of symmetries 3120ea844a1aSMatthew Knepley 3121ea844a1aSMatthew Knepley Level: developer 3122ea844a1aSMatthew Knepley 3123cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSym`, `PetscSectionSymDestroy()` 3124ea844a1aSMatthew Knepley @*/ 3125d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymCreate(MPI_Comm comm, PetscSectionSym *sym) 3126d71ae5a4SJacob Faibussowitsch { 3127ea844a1aSMatthew Knepley PetscFunctionBegin; 3128ea844a1aSMatthew Knepley PetscValidPointer(sym, 2); 31299566063dSJacob Faibussowitsch PetscCall(ISInitializePackage()); 31309566063dSJacob Faibussowitsch PetscCall(PetscHeaderCreate(*sym, PETSC_SECTION_SYM_CLASSID, "PetscSectionSym", "Section Symmetry", "IS", comm, PetscSectionSymDestroy, PetscSectionSymView)); 31313ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3132ea844a1aSMatthew Knepley } 3133ea844a1aSMatthew Knepley 3134ea844a1aSMatthew Knepley /*@C 3135cab54364SBarry Smith PetscSectionSymSetType - Builds a `PetscSectionSym`, for a particular implementation. 3136ea844a1aSMatthew Knepley 313740750d41SVaclav Hapla Collective 3138ea844a1aSMatthew Knepley 3139ea844a1aSMatthew Knepley Input Parameters: 3140ea844a1aSMatthew Knepley + sym - The section symmetry object 3141ea844a1aSMatthew Knepley - method - The name of the section symmetry type 3142ea844a1aSMatthew Knepley 3143ea844a1aSMatthew Knepley Level: developer 3144ea844a1aSMatthew Knepley 3145cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSymType`, `PetscSectionSymGetType()`, `PetscSectionSymCreate()` 3146ea844a1aSMatthew Knepley @*/ 3147d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymSetType(PetscSectionSym sym, PetscSectionSymType method) 3148d71ae5a4SJacob Faibussowitsch { 3149ea844a1aSMatthew Knepley PetscErrorCode (*r)(PetscSectionSym); 3150ea844a1aSMatthew Knepley PetscBool match; 3151ea844a1aSMatthew Knepley 3152ea844a1aSMatthew Knepley PetscFunctionBegin; 3153ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 31549566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)sym, method, &match)); 31553ba16761SJacob Faibussowitsch if (match) PetscFunctionReturn(PETSC_SUCCESS); 3156ea844a1aSMatthew Knepley 31579566063dSJacob Faibussowitsch PetscCall(PetscFunctionListFind(PetscSectionSymList, method, &r)); 3158*6adde796SStefano Zampini PetscCheck(r, PetscObjectComm((PetscObject)sym), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscSectionSym type: %s", method); 3159dbbe0bcdSBarry Smith PetscTryTypeMethod(sym, destroy); 3160ea844a1aSMatthew Knepley sym->ops->destroy = NULL; 3161dbbe0bcdSBarry Smith 31629566063dSJacob Faibussowitsch PetscCall((*r)(sym)); 31639566063dSJacob Faibussowitsch PetscCall(PetscObjectChangeTypeName((PetscObject)sym, method)); 31643ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3165ea844a1aSMatthew Knepley } 3166ea844a1aSMatthew Knepley 3167ea844a1aSMatthew Knepley /*@C 3168cab54364SBarry Smith PetscSectionSymGetType - Gets the section symmetry type name (as a string) from the `PetscSectionSym`. 3169ea844a1aSMatthew Knepley 3170ea844a1aSMatthew Knepley Not Collective 3171ea844a1aSMatthew Knepley 3172ea844a1aSMatthew Knepley Input Parameter: 3173ea844a1aSMatthew Knepley . sym - The section symmetry 3174ea844a1aSMatthew Knepley 3175ea844a1aSMatthew Knepley Output Parameter: 3176ea844a1aSMatthew Knepley . type - The index set type name 3177ea844a1aSMatthew Knepley 3178ea844a1aSMatthew Knepley Level: developer 3179ea844a1aSMatthew Knepley 3180cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSymType`, `PetscSectionSymSetType()`, `PetscSectionSymCreate()` 3181ea844a1aSMatthew Knepley @*/ 3182d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymGetType(PetscSectionSym sym, PetscSectionSymType *type) 3183d71ae5a4SJacob Faibussowitsch { 3184ea844a1aSMatthew Knepley PetscFunctionBegin; 3185ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 3186dadcf809SJacob Faibussowitsch PetscValidPointer(type, 2); 3187ea844a1aSMatthew Knepley *type = ((PetscObject)sym)->type_name; 31883ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3189ea844a1aSMatthew Knepley } 3190ea844a1aSMatthew Knepley 3191ea844a1aSMatthew Knepley /*@C 3192cab54364SBarry Smith PetscSectionSymRegister - Registers a new section symmetry implementation 3193ea844a1aSMatthew Knepley 3194ea844a1aSMatthew Knepley Not Collective 3195ea844a1aSMatthew Knepley 3196ea844a1aSMatthew Knepley Input Parameters: 31972fe279fdSBarry Smith + sname - The name of a new user-defined creation routine 31982fe279fdSBarry Smith - function - The creation routine itself 3199ea844a1aSMatthew Knepley 3200ea844a1aSMatthew Knepley Level: developer 3201ea844a1aSMatthew Knepley 3202cab54364SBarry Smith Notes: 3203cab54364SBarry Smith `PetscSectionSymRegister()` may be called multiple times to add several user-defined vectors 3204cab54364SBarry Smith 3205cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSymType`, `PetscSectionSymCreate()`, `PetscSectionSymSetType()` 3206ea844a1aSMatthew Knepley @*/ 3207d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymRegister(const char sname[], PetscErrorCode (*function)(PetscSectionSym)) 3208d71ae5a4SJacob Faibussowitsch { 3209ea844a1aSMatthew Knepley PetscFunctionBegin; 32109566063dSJacob Faibussowitsch PetscCall(ISInitializePackage()); 32119566063dSJacob Faibussowitsch PetscCall(PetscFunctionListAdd(&PetscSectionSymList, sname, function)); 32123ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3213ea844a1aSMatthew Knepley } 3214ea844a1aSMatthew Knepley 3215ea844a1aSMatthew Knepley /*@ 3216ea844a1aSMatthew Knepley PetscSectionSymDestroy - Destroys a section symmetry. 3217ea844a1aSMatthew Knepley 321840750d41SVaclav Hapla Collective 3219ea844a1aSMatthew Knepley 32202fe279fdSBarry Smith Input Parameter: 3221ea844a1aSMatthew Knepley . sym - the section symmetry 3222ea844a1aSMatthew Knepley 3223ea844a1aSMatthew Knepley Level: developer 3224ea844a1aSMatthew Knepley 3225cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSymCreate()`, `PetscSectionSymDestroy()` 3226ea844a1aSMatthew Knepley @*/ 3227d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymDestroy(PetscSectionSym *sym) 3228d71ae5a4SJacob Faibussowitsch { 3229ea844a1aSMatthew Knepley SymWorkLink link, next; 3230ea844a1aSMatthew Knepley 3231ea844a1aSMatthew Knepley PetscFunctionBegin; 32323ba16761SJacob Faibussowitsch if (!*sym) PetscFunctionReturn(PETSC_SUCCESS); 3233ea844a1aSMatthew Knepley PetscValidHeaderSpecific((*sym), PETSC_SECTION_SYM_CLASSID, 1); 32349371c9d4SSatish Balay if (--((PetscObject)(*sym))->refct > 0) { 32359371c9d4SSatish Balay *sym = NULL; 32363ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3237ea844a1aSMatthew Knepley } 323848a46eb9SPierre Jolivet if ((*sym)->ops->destroy) PetscCall((*(*sym)->ops->destroy)(*sym)); 3239c9cc58a2SBarry Smith PetscCheck(!(*sym)->workout, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Work array still checked out"); 3240ea844a1aSMatthew Knepley for (link = (*sym)->workin; link; link = next) { 32410c99d500SBarry Smith PetscInt **perms = (PetscInt **)link->perms; 32420c99d500SBarry Smith PetscScalar **rots = (PetscScalar **)link->rots; 32430c99d500SBarry Smith PetscCall(PetscFree2(perms, rots)); 3244ea844a1aSMatthew Knepley next = link->next; 32459566063dSJacob Faibussowitsch PetscCall(PetscFree(link)); 3246ea844a1aSMatthew Knepley } 3247ea844a1aSMatthew Knepley (*sym)->workin = NULL; 32489566063dSJacob Faibussowitsch PetscCall(PetscHeaderDestroy(sym)); 32493ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3250ea844a1aSMatthew Knepley } 3251ea844a1aSMatthew Knepley 3252ea844a1aSMatthew Knepley /*@C 3253ea844a1aSMatthew Knepley PetscSectionSymView - Displays a section symmetry 3254ea844a1aSMatthew Knepley 325540750d41SVaclav Hapla Collective 3256ea844a1aSMatthew Knepley 3257ea844a1aSMatthew Knepley Input Parameters: 3258ea844a1aSMatthew Knepley + sym - the index set 3259cab54364SBarry Smith - viewer - viewer used to display the set, for example `PETSC_VIEWER_STDOUT_SELF`. 3260ea844a1aSMatthew Knepley 3261ea844a1aSMatthew Knepley Level: developer 3262ea844a1aSMatthew Knepley 3263cab54364SBarry Smith .seealso: `PetscSectionSym`, `PetscViewer`, `PetscViewerASCIIOpen()` 3264ea844a1aSMatthew Knepley @*/ 3265d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymView(PetscSectionSym sym, PetscViewer viewer) 3266d71ae5a4SJacob Faibussowitsch { 3267ea844a1aSMatthew Knepley PetscFunctionBegin; 3268ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 326948a46eb9SPierre Jolivet if (!viewer) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)sym), &viewer)); 3270ea844a1aSMatthew Knepley PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2); 3271ea844a1aSMatthew Knepley PetscCheckSameComm(sym, 1, viewer, 2); 32729566063dSJacob Faibussowitsch PetscCall(PetscObjectPrintClassNamePrefixType((PetscObject)sym, viewer)); 3273dbbe0bcdSBarry Smith PetscTryTypeMethod(sym, view, viewer); 32743ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3275ea844a1aSMatthew Knepley } 3276ea844a1aSMatthew Knepley 3277ea844a1aSMatthew Knepley /*@ 3278ea844a1aSMatthew Knepley PetscSectionSetSym - Set the symmetries for the data referred to by the section 3279ea844a1aSMatthew Knepley 328040750d41SVaclav Hapla Collective 3281ea844a1aSMatthew Knepley 3282ea844a1aSMatthew Knepley Input Parameters: 3283ea844a1aSMatthew Knepley + section - the section describing data layout 3284ea844a1aSMatthew Knepley - sym - the symmetry describing the affect of orientation on the access of the data 3285ea844a1aSMatthew Knepley 3286ea844a1aSMatthew Knepley Level: developer 3287ea844a1aSMatthew Knepley 3288cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionGetSym()`, `PetscSectionSymCreate()` 3289ea844a1aSMatthew Knepley @*/ 3290d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetSym(PetscSection section, PetscSectionSym sym) 3291d71ae5a4SJacob Faibussowitsch { 3292ea844a1aSMatthew Knepley PetscFunctionBegin; 3293ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 32949566063dSJacob Faibussowitsch PetscCall(PetscSectionSymDestroy(&(section->sym))); 3295ea844a1aSMatthew Knepley if (sym) { 3296ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 2); 3297ea844a1aSMatthew Knepley PetscCheckSameComm(section, 1, sym, 2); 32989566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)sym)); 3299ea844a1aSMatthew Knepley } 3300ea844a1aSMatthew Knepley section->sym = sym; 33013ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3302ea844a1aSMatthew Knepley } 3303ea844a1aSMatthew Knepley 3304ea844a1aSMatthew Knepley /*@ 3305ea844a1aSMatthew Knepley PetscSectionGetSym - Get the symmetries for the data referred to by the section 3306ea844a1aSMatthew Knepley 330740750d41SVaclav Hapla Not Collective 3308ea844a1aSMatthew Knepley 33092fe279fdSBarry Smith Input Parameter: 3310ea844a1aSMatthew Knepley . section - the section describing data layout 3311ea844a1aSMatthew Knepley 33122fe279fdSBarry Smith Output Parameter: 331320662ed9SBarry Smith . sym - the symmetry describing the affect of orientation on the access of the data, provided previously by `PetscSectionSetSym()` 3314ea844a1aSMatthew Knepley 3315ea844a1aSMatthew Knepley Level: developer 3316ea844a1aSMatthew Knepley 3317cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSetSym()`, `PetscSectionSymCreate()` 3318ea844a1aSMatthew Knepley @*/ 3319d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetSym(PetscSection section, PetscSectionSym *sym) 3320d71ae5a4SJacob Faibussowitsch { 3321ea844a1aSMatthew Knepley PetscFunctionBegin; 3322ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 3323ea844a1aSMatthew Knepley *sym = section->sym; 33243ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3325ea844a1aSMatthew Knepley } 3326ea844a1aSMatthew Knepley 3327ea844a1aSMatthew Knepley /*@ 3328ea844a1aSMatthew Knepley PetscSectionSetFieldSym - Set the symmetries for the data referred to by a field of the section 3329ea844a1aSMatthew Knepley 333040750d41SVaclav Hapla Collective 3331ea844a1aSMatthew Knepley 3332ea844a1aSMatthew Knepley Input Parameters: 3333ea844a1aSMatthew Knepley + section - the section describing data layout 3334ea844a1aSMatthew Knepley . field - the field number 3335ea844a1aSMatthew Knepley - sym - the symmetry describing the affect of orientation on the access of the data 3336ea844a1aSMatthew Knepley 3337ea844a1aSMatthew Knepley Level: developer 3338ea844a1aSMatthew Knepley 3339cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionGetFieldSym()`, `PetscSectionSymCreate()` 3340ea844a1aSMatthew Knepley @*/ 3341d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldSym(PetscSection section, PetscInt field, PetscSectionSym sym) 3342d71ae5a4SJacob Faibussowitsch { 3343ea844a1aSMatthew Knepley PetscFunctionBegin; 3344ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 33452abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, section->numFields); 33469566063dSJacob Faibussowitsch PetscCall(PetscSectionSetSym(section->field[field], sym)); 33473ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3348ea844a1aSMatthew Knepley } 3349ea844a1aSMatthew Knepley 3350ea844a1aSMatthew Knepley /*@ 3351ea844a1aSMatthew Knepley PetscSectionGetFieldSym - Get the symmetries for the data referred to by a field of the section 3352ea844a1aSMatthew Knepley 335340750d41SVaclav Hapla Collective 3354ea844a1aSMatthew Knepley 3355ea844a1aSMatthew Knepley Input Parameters: 3356ea844a1aSMatthew Knepley + section - the section describing data layout 3357ea844a1aSMatthew Knepley - field - the field number 3358ea844a1aSMatthew Knepley 33592fe279fdSBarry Smith Output Parameter: 3360ea844a1aSMatthew Knepley . sym - the symmetry describing the affect of orientation on the access of the data 3361ea844a1aSMatthew Knepley 3362ea844a1aSMatthew Knepley Level: developer 3363ea844a1aSMatthew Knepley 3364cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSetFieldSym()`, `PetscSectionSymCreate()` 3365ea844a1aSMatthew Knepley @*/ 3366d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldSym(PetscSection section, PetscInt field, PetscSectionSym *sym) 3367d71ae5a4SJacob Faibussowitsch { 3368ea844a1aSMatthew Knepley PetscFunctionBegin; 3369ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 33702abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, section->numFields); 3371ea844a1aSMatthew Knepley *sym = section->field[field]->sym; 33723ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3373ea844a1aSMatthew Knepley } 3374ea844a1aSMatthew Knepley 3375ea844a1aSMatthew Knepley /*@C 3376cab54364SBarry Smith PetscSectionGetPointSyms - Get the symmetries for a set of points in a `PetscSection` under specific orientations. 3377ea844a1aSMatthew Knepley 337840750d41SVaclav Hapla Not Collective 3379ea844a1aSMatthew Knepley 3380ea844a1aSMatthew Knepley Input Parameters: 3381ea844a1aSMatthew Knepley + section - the section 3382ea844a1aSMatthew Knepley . numPoints - the number of points 338320662ed9SBarry Smith - points - an array of size 2 * `numPoints`, containing a list of (point, orientation) pairs. (An orientation is an 338420662ed9SBarry Smith arbitrary integer: its interpretation is up to sym. Orientations are used by `DM`: for their interpretation in that 338520662ed9SBarry Smith context, see `DMPlexGetConeOrientation()`). 3386ea844a1aSMatthew Knepley 3387d8d19677SJose E. Roman Output Parameters: 338820662ed9SBarry Smith + perms - The permutations for the given orientations (or `NULL` if there is no symmetry or the permutation is the identity). 338920662ed9SBarry Smith - rots - The field rotations symmetries for the given orientations (or `NULL` if there is no symmetry or the rotations are all 3390ea844a1aSMatthew Knepley identity). 3391ea844a1aSMatthew Knepley 3392ea844a1aSMatthew Knepley Example of usage, gathering dofs into a local array (lArray) from a section array (sArray): 3393ea844a1aSMatthew Knepley .vb 3394ea844a1aSMatthew Knepley const PetscInt **perms; 3395ea844a1aSMatthew Knepley const PetscScalar **rots; 3396ea844a1aSMatthew Knepley PetscInt lOffset; 3397ea844a1aSMatthew Knepley 3398ea844a1aSMatthew Knepley PetscSectionGetPointSyms(section,numPoints,points,&perms,&rots); 3399ea844a1aSMatthew Knepley for (i = 0, lOffset = 0; i < numPoints; i++) { 3400ea844a1aSMatthew Knepley PetscInt point = points[2*i], dof, sOffset; 3401ea844a1aSMatthew Knepley const PetscInt *perm = perms ? perms[i] : NULL; 3402ea844a1aSMatthew Knepley const PetscScalar *rot = rots ? rots[i] : NULL; 3403ea844a1aSMatthew Knepley 3404ea844a1aSMatthew Knepley PetscSectionGetDof(section,point,&dof); 3405ea844a1aSMatthew Knepley PetscSectionGetOffset(section,point,&sOffset); 3406ea844a1aSMatthew Knepley 3407ea844a1aSMatthew Knepley if (perm) {for (j = 0; j < dof; j++) {lArray[lOffset + perm[j]] = sArray[sOffset + j];}} 3408ea844a1aSMatthew Knepley else {for (j = 0; j < dof; j++) {lArray[lOffset + j ] = sArray[sOffset + j];}} 3409ea844a1aSMatthew Knepley if (rot) {for (j = 0; j < dof; j++) {lArray[lOffset + j ] *= rot[j]; }} 3410ea844a1aSMatthew Knepley lOffset += dof; 3411ea844a1aSMatthew Knepley } 3412ea844a1aSMatthew Knepley PetscSectionRestorePointSyms(section,numPoints,points,&perms,&rots); 3413ea844a1aSMatthew Knepley .ve 3414ea844a1aSMatthew Knepley 3415ea844a1aSMatthew Knepley Example of usage, adding dofs into a section array (sArray) from a local array (lArray): 3416ea844a1aSMatthew Knepley .vb 3417ea844a1aSMatthew Knepley const PetscInt **perms; 3418ea844a1aSMatthew Knepley const PetscScalar **rots; 3419ea844a1aSMatthew Knepley PetscInt lOffset; 3420ea844a1aSMatthew Knepley 3421ea844a1aSMatthew Knepley PetscSectionGetPointSyms(section,numPoints,points,&perms,&rots); 3422ea844a1aSMatthew Knepley for (i = 0, lOffset = 0; i < numPoints; i++) { 3423ea844a1aSMatthew Knepley PetscInt point = points[2*i], dof, sOffset; 3424ea844a1aSMatthew Knepley const PetscInt *perm = perms ? perms[i] : NULL; 3425ea844a1aSMatthew Knepley const PetscScalar *rot = rots ? rots[i] : NULL; 3426ea844a1aSMatthew Knepley 3427ea844a1aSMatthew Knepley PetscSectionGetDof(section,point,&dof); 3428ea844a1aSMatthew Knepley PetscSectionGetOffset(section,point,&sOff); 3429ea844a1aSMatthew Knepley 3430ea844a1aSMatthew Knepley if (perm) {for (j = 0; j < dof; j++) {sArray[sOffset + j] += lArray[lOffset + perm[j]] * (rot ? PetscConj(rot[perm[j]]) : 1.);}} 3431ea844a1aSMatthew Knepley else {for (j = 0; j < dof; j++) {sArray[sOffset + j] += lArray[lOffset + j ] * (rot ? PetscConj(rot[ j ]) : 1.);}} 3432ea844a1aSMatthew Knepley offset += dof; 3433ea844a1aSMatthew Knepley } 3434ea844a1aSMatthew Knepley PetscSectionRestorePointSyms(section,numPoints,points,&perms,&rots); 3435ea844a1aSMatthew Knepley .ve 3436ea844a1aSMatthew Knepley 3437ea844a1aSMatthew Knepley Level: developer 3438ea844a1aSMatthew Knepley 3439583308b6SBarry Smith Notes: 344020662ed9SBarry Smith `PetscSectionSetSym()` must have been previously called to provide the symmetries to the `PetscSection` 344120662ed9SBarry Smith 344220662ed9SBarry Smith Use `PetscSectionRestorePointSyms()` when finished with the data 344320662ed9SBarry Smith 3444cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionRestorePointSyms()`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()` 3445ea844a1aSMatthew Knepley @*/ 3446d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetPointSyms(PetscSection section, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots) 3447d71ae5a4SJacob Faibussowitsch { 3448ea844a1aSMatthew Knepley PetscSectionSym sym; 3449ea844a1aSMatthew Knepley 3450ea844a1aSMatthew Knepley PetscFunctionBegin; 3451ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 3452ea844a1aSMatthew Knepley if (numPoints) PetscValidIntPointer(points, 3); 3453ea844a1aSMatthew Knepley if (perms) *perms = NULL; 3454ea844a1aSMatthew Knepley if (rots) *rots = NULL; 3455ea844a1aSMatthew Knepley sym = section->sym; 3456ea844a1aSMatthew Knepley if (sym && (perms || rots)) { 3457ea844a1aSMatthew Knepley SymWorkLink link; 3458ea844a1aSMatthew Knepley 3459ea844a1aSMatthew Knepley if (sym->workin) { 3460ea844a1aSMatthew Knepley link = sym->workin; 3461ea844a1aSMatthew Knepley sym->workin = sym->workin->next; 3462ea844a1aSMatthew Knepley } else { 34634dfa11a4SJacob Faibussowitsch PetscCall(PetscNew(&link)); 3464ea844a1aSMatthew Knepley } 3465ea844a1aSMatthew Knepley if (numPoints > link->numPoints) { 34660c99d500SBarry Smith PetscInt **perms = (PetscInt **)link->perms; 34670c99d500SBarry Smith PetscScalar **rots = (PetscScalar **)link->rots; 34680c99d500SBarry Smith PetscCall(PetscFree2(perms, rots)); 34690c99d500SBarry Smith PetscCall(PetscMalloc2(numPoints, (PetscInt ***)&link->perms, numPoints, (PetscScalar ***)&link->rots)); 3470ea844a1aSMatthew Knepley link->numPoints = numPoints; 3471ea844a1aSMatthew Knepley } 3472ea844a1aSMatthew Knepley link->next = sym->workout; 3473ea844a1aSMatthew Knepley sym->workout = link; 34749566063dSJacob Faibussowitsch PetscCall(PetscArrayzero((PetscInt **)link->perms, numPoints)); 34759566063dSJacob Faibussowitsch PetscCall(PetscArrayzero((PetscInt **)link->rots, numPoints)); 34769566063dSJacob Faibussowitsch PetscCall((*sym->ops->getpoints)(sym, section, numPoints, points, link->perms, link->rots)); 3477ea844a1aSMatthew Knepley if (perms) *perms = link->perms; 3478ea844a1aSMatthew Knepley if (rots) *rots = link->rots; 3479ea844a1aSMatthew Knepley } 34803ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3481ea844a1aSMatthew Knepley } 3482ea844a1aSMatthew Knepley 3483ea844a1aSMatthew Knepley /*@C 3484cab54364SBarry Smith PetscSectionRestorePointSyms - Restore the symmetries returned by `PetscSectionGetPointSyms()` 3485ea844a1aSMatthew Knepley 348640750d41SVaclav Hapla Not Collective 3487ea844a1aSMatthew Knepley 3488ea844a1aSMatthew Knepley Input Parameters: 3489ea844a1aSMatthew Knepley + section - the section 3490ea844a1aSMatthew Knepley . numPoints - the number of points 349120662ed9SBarry Smith - points - an array of size 2 * `numPoints`, containing a list of (point, orientation) pairs. (An orientation is an 3492cab54364SBarry Smith arbitrary integer: its interpretation is up to sym. Orientations are used by `DM`: for their interpretation in that 3493cab54364SBarry Smith context, see `DMPlexGetConeOrientation()`). 349420662ed9SBarry Smith . perms - The permutations for the given orientations: set to `NULL` at conclusion 349520662ed9SBarry Smith - rots - The field rotations symmetries for the given orientations: set to `NULL` at conclusion 3496ea844a1aSMatthew Knepley 3497ea844a1aSMatthew Knepley Level: developer 3498ea844a1aSMatthew Knepley 3499cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionGetPointSyms()`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()` 3500ea844a1aSMatthew Knepley @*/ 3501d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionRestorePointSyms(PetscSection section, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots) 3502d71ae5a4SJacob Faibussowitsch { 3503ea844a1aSMatthew Knepley PetscSectionSym sym; 3504ea844a1aSMatthew Knepley 3505ea844a1aSMatthew Knepley PetscFunctionBegin; 3506ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 3507ea844a1aSMatthew Knepley sym = section->sym; 3508ea844a1aSMatthew Knepley if (sym && (perms || rots)) { 3509ea844a1aSMatthew Knepley SymWorkLink *p, link; 3510ea844a1aSMatthew Knepley 3511ea844a1aSMatthew Knepley for (p = &sym->workout; (link = *p); p = &link->next) { 3512ea844a1aSMatthew Knepley if ((perms && link->perms == *perms) || (rots && link->rots == *rots)) { 3513ea844a1aSMatthew Knepley *p = link->next; 3514ea844a1aSMatthew Knepley link->next = sym->workin; 3515ea844a1aSMatthew Knepley sym->workin = link; 3516ea844a1aSMatthew Knepley if (perms) *perms = NULL; 3517ea844a1aSMatthew Knepley if (rots) *rots = NULL; 35183ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3519ea844a1aSMatthew Knepley } 3520ea844a1aSMatthew Knepley } 3521ea844a1aSMatthew Knepley SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Array was not checked out"); 3522ea844a1aSMatthew Knepley } 35233ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3524ea844a1aSMatthew Knepley } 3525ea844a1aSMatthew Knepley 3526ea844a1aSMatthew Knepley /*@C 3527cab54364SBarry Smith PetscSectionGetFieldPointSyms - Get the symmetries for a set of points in a field of a `PetscSection` under specific orientations. 3528ea844a1aSMatthew Knepley 352940750d41SVaclav Hapla Not Collective 3530ea844a1aSMatthew Knepley 3531ea844a1aSMatthew Knepley Input Parameters: 3532ea844a1aSMatthew Knepley + section - the section 3533ea844a1aSMatthew Knepley . field - the field of the section 3534ea844a1aSMatthew Knepley . numPoints - the number of points 353520662ed9SBarry Smith - points - an array of size 2 * `numPoints`, containing a list of (point, orientation) pairs. (An orientation is an 3536cab54364SBarry Smith arbitrary integer: its interpretation is up to sym. Orientations are used by `DM`: for their interpretation in that 3537cab54364SBarry Smith context, see `DMPlexGetConeOrientation()`). 3538ea844a1aSMatthew Knepley 3539d8d19677SJose E. Roman Output Parameters: 354020662ed9SBarry Smith + perms - The permutations for the given orientations (or `NULL` if there is no symmetry or the permutation is the identity). 354120662ed9SBarry Smith - rots - The field rotations symmetries for the given orientations (or `NULL` if there is no symmetry or the rotations are all 3542ea844a1aSMatthew Knepley identity). 3543ea844a1aSMatthew Knepley 3544ea844a1aSMatthew Knepley Level: developer 3545ea844a1aSMatthew Knepley 354620662ed9SBarry Smith Notes: 354720662ed9SBarry Smith `PetscSectionSetFieldSym()` must have been previously called to provide the symmetries to the `PetscSection` 354820662ed9SBarry Smith 354920662ed9SBarry Smith Use `PetscSectionRestoreFieldPointSyms()` when finished with the data 355020662ed9SBarry Smith 3551cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionGetPointSyms()`, `PetscSectionRestoreFieldPointSyms()` 3552ea844a1aSMatthew Knepley @*/ 3553d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldPointSyms(PetscSection section, PetscInt field, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots) 3554d71ae5a4SJacob Faibussowitsch { 3555ea844a1aSMatthew Knepley PetscFunctionBegin; 3556ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 355708401ef6SPierre 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); 35589566063dSJacob Faibussowitsch PetscCall(PetscSectionGetPointSyms(section->field[field], numPoints, points, perms, rots)); 35593ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3560ea844a1aSMatthew Knepley } 3561ea844a1aSMatthew Knepley 3562ea844a1aSMatthew Knepley /*@C 3563cab54364SBarry Smith PetscSectionRestoreFieldPointSyms - Restore the symmetries returned by `PetscSectionGetFieldPointSyms()` 3564ea844a1aSMatthew Knepley 356540750d41SVaclav Hapla Not Collective 3566ea844a1aSMatthew Knepley 3567ea844a1aSMatthew Knepley Input Parameters: 3568ea844a1aSMatthew Knepley + section - the section 3569ea844a1aSMatthew Knepley . field - the field number 3570ea844a1aSMatthew Knepley . numPoints - the number of points 357120662ed9SBarry Smith - points - an array of size 2 * `numPoints`, containing a list of (point, orientation) pairs. (An orientation is an 3572cab54364SBarry Smith arbitrary integer: its interpretation is up to sym. Orientations are used by `DM`: for their interpretation in that 3573cab54364SBarry Smith context, see `DMPlexGetConeOrientation()`). 357420662ed9SBarry Smith . perms - The permutations for the given orientations: set to NULL at conclusion 3575ea844a1aSMatthew Knepley - rots - The field rotations symmetries for the given orientations: set to NULL at conclusion 3576ea844a1aSMatthew Knepley 3577ea844a1aSMatthew Knepley Level: developer 3578ea844a1aSMatthew Knepley 3579cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionRestorePointSyms()`, `petscSectionGetFieldPointSyms()`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()` 3580ea844a1aSMatthew Knepley @*/ 3581d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionRestoreFieldPointSyms(PetscSection section, PetscInt field, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots) 3582d71ae5a4SJacob Faibussowitsch { 3583ea844a1aSMatthew Knepley PetscFunctionBegin; 3584ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 358508401ef6SPierre 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); 35869566063dSJacob Faibussowitsch PetscCall(PetscSectionRestorePointSyms(section->field[field], numPoints, points, perms, rots)); 35873ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3588ea844a1aSMatthew Knepley } 3589ea844a1aSMatthew Knepley 3590ea844a1aSMatthew Knepley /*@ 3591b004864fSMatthew G. Knepley PetscSectionSymCopy - Copy the symmetries, assuming that the point structure is compatible 3592b004864fSMatthew G. Knepley 359340750d41SVaclav Hapla Not Collective 3594b004864fSMatthew G. Knepley 3595b004864fSMatthew G. Knepley Input Parameter: 3596cab54364SBarry Smith . sym - the `PetscSectionSym` 3597b004864fSMatthew G. Knepley 3598b004864fSMatthew G. Knepley Output Parameter: 3599b004864fSMatthew G. Knepley . nsym - the equivalent symmetries 3600b004864fSMatthew G. Knepley 3601b004864fSMatthew G. Knepley Level: developer 3602b004864fSMatthew G. Knepley 3603cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()`, `PetscSectionSymLabelSetStratum()`, `PetscSectionGetPointSyms()` 3604b004864fSMatthew G. Knepley @*/ 3605d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymCopy(PetscSectionSym sym, PetscSectionSym nsym) 3606d71ae5a4SJacob Faibussowitsch { 3607b004864fSMatthew G. Knepley PetscFunctionBegin; 3608b004864fSMatthew G. Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 3609b004864fSMatthew G. Knepley PetscValidHeaderSpecific(nsym, PETSC_SECTION_SYM_CLASSID, 2); 3610dbbe0bcdSBarry Smith PetscTryTypeMethod(sym, copy, nsym); 36113ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3612b004864fSMatthew G. Knepley } 3613b004864fSMatthew G. Knepley 3614b004864fSMatthew G. Knepley /*@ 3615cab54364SBarry Smith PetscSectionSymDistribute - Distribute the symmetries in accordance with the input `PetscSF` 3616b004864fSMatthew G. Knepley 3617b004864fSMatthew G. Knepley Collective 3618b004864fSMatthew G. Knepley 3619b004864fSMatthew G. Knepley Input Parameters: 3620cab54364SBarry Smith + sym - the `PetscSectionSym` 3621b004864fSMatthew G. Knepley - migrationSF - the distribution map from roots to leaves 3622b004864fSMatthew G. Knepley 36232fe279fdSBarry Smith Output Parameter: 3624b004864fSMatthew G. Knepley . dsym - the redistributed symmetries 3625b004864fSMatthew G. Knepley 3626b004864fSMatthew G. Knepley Level: developer 3627b004864fSMatthew G. Knepley 3628cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()`, `PetscSectionSymLabelSetStratum()`, `PetscSectionGetPointSyms()` 3629b004864fSMatthew G. Knepley @*/ 3630d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymDistribute(PetscSectionSym sym, PetscSF migrationSF, PetscSectionSym *dsym) 3631d71ae5a4SJacob Faibussowitsch { 3632b004864fSMatthew G. Knepley PetscFunctionBegin; 3633b004864fSMatthew G. Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 3634b004864fSMatthew G. Knepley PetscValidHeaderSpecific(migrationSF, PETSCSF_CLASSID, 2); 3635b004864fSMatthew G. Knepley PetscValidPointer(dsym, 3); 3636dbbe0bcdSBarry Smith PetscTryTypeMethod(sym, distribute, migrationSF, dsym); 36373ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3638b004864fSMatthew G. Knepley } 3639b004864fSMatthew G. Knepley 3640b004864fSMatthew G. Knepley /*@ 364120662ed9SBarry Smith PetscSectionGetUseFieldOffsets - Get the flag indicating if field offsets are used directly in a global section, rather than just the point offset 3642ea844a1aSMatthew Knepley 364340750d41SVaclav Hapla Not Collective 3644ea844a1aSMatthew Knepley 3645ea844a1aSMatthew Knepley Input Parameter: 3646cab54364SBarry Smith . s - the global `PetscSection` 3647ea844a1aSMatthew Knepley 36482fe279fdSBarry Smith Output Parameter: 3649ea844a1aSMatthew Knepley . flg - the flag 3650ea844a1aSMatthew Knepley 3651ea844a1aSMatthew Knepley Level: developer 3652ea844a1aSMatthew Knepley 3653cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSetChart()`, `PetscSectionCreate()` 3654ea844a1aSMatthew Knepley @*/ 3655d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetUseFieldOffsets(PetscSection s, PetscBool *flg) 3656d71ae5a4SJacob Faibussowitsch { 3657ea844a1aSMatthew Knepley PetscFunctionBegin; 3658ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 3659ea844a1aSMatthew Knepley *flg = s->useFieldOff; 36603ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3661ea844a1aSMatthew Knepley } 3662ea844a1aSMatthew Knepley 3663ea844a1aSMatthew Knepley /*@ 3664ea844a1aSMatthew Knepley PetscSectionSetUseFieldOffsets - Set the flag to use field offsets directly in a global section, rather than just the point offset 3665ea844a1aSMatthew Knepley 366640750d41SVaclav Hapla Not Collective 3667ea844a1aSMatthew Knepley 3668ea844a1aSMatthew Knepley Input Parameters: 3669cab54364SBarry Smith + s - the global `PetscSection` 3670ea844a1aSMatthew Knepley - flg - the flag 3671ea844a1aSMatthew Knepley 3672ea844a1aSMatthew Knepley Level: developer 3673ea844a1aSMatthew Knepley 3674cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionGetUseFieldOffsets()`, `PetscSectionSetChart()`, `PetscSectionCreate()` 3675ea844a1aSMatthew Knepley @*/ 3676d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetUseFieldOffsets(PetscSection s, PetscBool flg) 3677d71ae5a4SJacob Faibussowitsch { 3678ea844a1aSMatthew Knepley PetscFunctionBegin; 3679ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 3680ea844a1aSMatthew Knepley s->useFieldOff = flg; 36813ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3682ea844a1aSMatthew Knepley } 3683ea844a1aSMatthew Knepley 3684ea844a1aSMatthew Knepley #define PetscSectionExpandPoints_Loop(TYPE) \ 3685ea844a1aSMatthew Knepley { \ 3686ea844a1aSMatthew Knepley PetscInt i, n, o0, o1, size; \ 3687ea844a1aSMatthew Knepley TYPE *a0 = (TYPE *)origArray, *a1; \ 36889566063dSJacob Faibussowitsch PetscCall(PetscSectionGetStorageSize(s, &size)); \ 36899566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(size, &a1)); \ 3690ea844a1aSMatthew Knepley for (i = 0; i < npoints; i++) { \ 36919566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(origSection, points_[i], &o0)); \ 36929566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s, i, &o1)); \ 36939566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, i, &n)); \ 36949566063dSJacob Faibussowitsch PetscCall(PetscMemcpy(&a1[o1], &a0[o0], n *unitsize)); \ 3695ea844a1aSMatthew Knepley } \ 3696ea844a1aSMatthew Knepley *newArray = (void *)a1; \ 3697ea844a1aSMatthew Knepley } 3698ea844a1aSMatthew Knepley 3699ea844a1aSMatthew Knepley /*@ 3700ea844a1aSMatthew Knepley PetscSectionExtractDofsFromArray - Extracts elements of an array corresponding to DOFs of specified points. 3701ea844a1aSMatthew Knepley 370240750d41SVaclav Hapla Not Collective 3703ea844a1aSMatthew Knepley 3704ea844a1aSMatthew Knepley Input Parameters: 3705cab54364SBarry Smith + origSection - the `PetscSection` describing the layout of the array 3706cab54364SBarry Smith . dataType - `MPI_Datatype` describing the data type of the array (currently only `MPIU_INT`, `MPIU_SCALAR`, `MPIU_REAL`) 370720662ed9SBarry Smith . origArray - the array; its size must be equal to the storage size of `origSection` 370820662ed9SBarry Smith - points - `IS` with points to extract; its indices must lie in the chart of `origSection` 3709ea844a1aSMatthew Knepley 3710ea844a1aSMatthew Knepley Output Parameters: 3711da81f932SPierre Jolivet + newSection - the new `PetscSection` describing the layout of the new array (with points renumbered 0,1,... but preserving numbers of DOFs) 371220662ed9SBarry Smith - newArray - the array of the extracted DOFs; its size is the storage size of `newSection` 3713ea844a1aSMatthew Knepley 3714ea844a1aSMatthew Knepley Level: developer 3715ea844a1aSMatthew Knepley 3716cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionGetChart()`, `PetscSectionGetDof()`, `PetscSectionGetStorageSize()`, `PetscSectionCreate()` 3717ea844a1aSMatthew Knepley @*/ 3718d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionExtractDofsFromArray(PetscSection origSection, MPI_Datatype dataType, const void *origArray, IS points, PetscSection *newSection, void *newArray[]) 3719d71ae5a4SJacob Faibussowitsch { 3720ea844a1aSMatthew Knepley PetscSection s; 3721ea844a1aSMatthew Knepley const PetscInt *points_; 3722ea844a1aSMatthew Knepley PetscInt i, n, npoints, pStart, pEnd; 3723ea844a1aSMatthew Knepley PetscMPIInt unitsize; 3724ea844a1aSMatthew Knepley 3725ea844a1aSMatthew Knepley PetscFunctionBegin; 3726ea844a1aSMatthew Knepley PetscValidHeaderSpecific(origSection, PETSC_SECTION_CLASSID, 1); 3727ea844a1aSMatthew Knepley PetscValidPointer(origArray, 3); 3728ea844a1aSMatthew Knepley PetscValidHeaderSpecific(points, IS_CLASSID, 4); 3729ea844a1aSMatthew Knepley if (newSection) PetscValidPointer(newSection, 5); 3730ea844a1aSMatthew Knepley if (newArray) PetscValidPointer(newArray, 6); 37319566063dSJacob Faibussowitsch PetscCallMPI(MPI_Type_size(dataType, &unitsize)); 37329566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(points, &npoints)); 37339566063dSJacob Faibussowitsch PetscCall(ISGetIndices(points, &points_)); 37349566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(origSection, &pStart, &pEnd)); 37359566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PETSC_COMM_SELF, &s)); 37369566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(s, 0, npoints)); 3737ea844a1aSMatthew Knepley for (i = 0; i < npoints; i++) { 3738c9cc58a2SBarry 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); 37399566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(origSection, points_[i], &n)); 37409566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(s, i, n)); 3741ea844a1aSMatthew Knepley } 37429566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(s)); 3743ea844a1aSMatthew Knepley if (newArray) { 37449371c9d4SSatish Balay if (dataType == MPIU_INT) { 37459371c9d4SSatish Balay PetscSectionExpandPoints_Loop(PetscInt); 37469371c9d4SSatish Balay } else if (dataType == MPIU_SCALAR) { 37479371c9d4SSatish Balay PetscSectionExpandPoints_Loop(PetscScalar); 37489371c9d4SSatish Balay } else if (dataType == MPIU_REAL) { 37499371c9d4SSatish Balay PetscSectionExpandPoints_Loop(PetscReal); 37509371c9d4SSatish Balay } else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "not implemented for this MPI_Datatype"); 3751ea844a1aSMatthew Knepley } 3752ea844a1aSMatthew Knepley if (newSection) { 3753ea844a1aSMatthew Knepley *newSection = s; 3754ea844a1aSMatthew Knepley } else { 37559566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s)); 3756ea844a1aSMatthew Knepley } 37579566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(points, &points_)); 37583ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 3759ea844a1aSMatthew Knepley } 3760