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 /*@ 11cab54364SBarry Smith PetscSectionCreate - Allocates `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 33*35cb6cd3SPierre 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 35db527f05SMatthew G. Knepley .seealso: [PetscSection](sec_petscsection), `PetscSection`, `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)); 65ea844a1aSMatthew Knepley PetscFunctionReturn(0); 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 } 156ea844a1aSMatthew Knepley PetscFunctionReturn(0); 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)); 184ea844a1aSMatthew Knepley PetscFunctionReturn(0); 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 195ea844a1aSMatthew Knepley Options Database: 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")); 212ea844a1aSMatthew Knepley PetscFunctionReturn(0); 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; 251ea844a1aSMatthew Knepley PetscFunctionReturn(0); 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))); 316ea844a1aSMatthew Knepley PetscFunctionReturn(0); 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; 340ea844a1aSMatthew Knepley PetscFunctionReturn(0); 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: 349ea844a1aSMatthew Knepley + s - the PetscSection 350ea844a1aSMatthew Knepley - numFields - the number of fields 351ea844a1aSMatthew Knepley 352ea844a1aSMatthew Knepley Level: intermediate 353ea844a1aSMatthew Knepley 354cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection()`, `PetscSectionGetNumFields()` 355ea844a1aSMatthew Knepley @*/ 356d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetNumFields(PetscSection s, PetscInt numFields) 357d71ae5a4SJacob Faibussowitsch { 358ea844a1aSMatthew Knepley PetscInt f; 359ea844a1aSMatthew Knepley 360ea844a1aSMatthew Knepley PetscFunctionBegin; 361ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 36208401ef6SPierre Jolivet PetscCheck(numFields > 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "The number of fields %" PetscInt_FMT " must be positive", numFields); 3639566063dSJacob Faibussowitsch PetscCall(PetscSectionReset(s)); 364ea844a1aSMatthew Knepley 365ea844a1aSMatthew Knepley s->numFields = numFields; 3669566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(s->numFields, &s->numFieldComponents)); 3679566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(s->numFields, &s->fieldNames)); 3689566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(s->numFields, &s->compNames)); 3699566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(s->numFields, &s->field)); 370ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) { 371ea844a1aSMatthew Knepley char name[64]; 372ea844a1aSMatthew Knepley 373ea844a1aSMatthew Knepley s->numFieldComponents[f] = 1; 374ea844a1aSMatthew Knepley 3759566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), &s->field[f])); 3769566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(name, 64, "Field_%" PetscInt_FMT, f)); 3779566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, (char **)&s->fieldNames[f])); 3789566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(name, 64, "Component_0")); 3799566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(s->numFieldComponents[f], &s->compNames[f])); 3809566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, (char **)&s->compNames[f][0])); 381ea844a1aSMatthew Knepley } 382ea844a1aSMatthew Knepley PetscFunctionReturn(0); 383ea844a1aSMatthew Knepley } 384ea844a1aSMatthew Knepley 385ea844a1aSMatthew Knepley /*@C 386cab54364SBarry Smith PetscSectionGetFieldName - Returns the name of a field in the `PetscSection` 387ea844a1aSMatthew Knepley 388ea844a1aSMatthew Knepley Not Collective 389ea844a1aSMatthew Knepley 390ea844a1aSMatthew Knepley Input Parameters: 391cab54364SBarry Smith + s - the `PetscSection` 392ea844a1aSMatthew Knepley - field - the field number 393ea844a1aSMatthew Knepley 394ea844a1aSMatthew Knepley Output Parameter: 395ea844a1aSMatthew Knepley . fieldName - the field name 396ea844a1aSMatthew Knepley 397ea844a1aSMatthew Knepley Level: intermediate 398ea844a1aSMatthew Knepley 399cab54364SBarry Smith Note: 400cab54364SBarry Smith Will error if the field number is out of range 401cab54364SBarry Smith 402cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetFieldName()`, `PetscSectionSetNumFields()`, `PetscSectionGetNumFields()` 403ea844a1aSMatthew Knepley @*/ 404d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldName(PetscSection s, PetscInt field, const char *fieldName[]) 405d71ae5a4SJacob Faibussowitsch { 406ea844a1aSMatthew Knepley PetscFunctionBegin; 407ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 408ea844a1aSMatthew Knepley PetscValidPointer(fieldName, 3); 4092abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 410ea844a1aSMatthew Knepley *fieldName = s->fieldNames[field]; 411ea844a1aSMatthew Knepley PetscFunctionReturn(0); 412ea844a1aSMatthew Knepley } 413ea844a1aSMatthew Knepley 414ea844a1aSMatthew Knepley /*@C 415cab54364SBarry Smith PetscSectionSetFieldName - Sets the name of a field in the `PetscSection` 416ea844a1aSMatthew Knepley 417ea844a1aSMatthew Knepley Not Collective 418ea844a1aSMatthew Knepley 419ea844a1aSMatthew Knepley Input Parameters: 420cab54364SBarry Smith + s - the `PetscSection` 421ea844a1aSMatthew Knepley . field - the field number 422ea844a1aSMatthew Knepley - fieldName - the field name 423ea844a1aSMatthew Knepley 424ea844a1aSMatthew Knepley Level: intermediate 425ea844a1aSMatthew Knepley 426cab54364SBarry Smith Note: 427cab54364SBarry Smith Will error if the field number is out of range 428cab54364SBarry Smith 429cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionGetFieldName()`, `PetscSectionSetNumFields()`, `PetscSectionGetNumFields()` 430ea844a1aSMatthew Knepley @*/ 431d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldName(PetscSection s, PetscInt field, const char fieldName[]) 432d71ae5a4SJacob Faibussowitsch { 433ea844a1aSMatthew Knepley PetscFunctionBegin; 434ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 435ea844a1aSMatthew Knepley if (fieldName) PetscValidCharPointer(fieldName, 3); 4362abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 4379566063dSJacob Faibussowitsch PetscCall(PetscFree(s->fieldNames[field])); 4389566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(fieldName, (char **)&s->fieldNames[field])); 439ea844a1aSMatthew Knepley PetscFunctionReturn(0); 440ea844a1aSMatthew Knepley } 441ea844a1aSMatthew Knepley 442b778fa18SValeria Barra /*@C 443cab54364SBarry Smith PetscSectionGetComponentName - Gets the name of a field component in the `PetscSection` 444b778fa18SValeria Barra 445b778fa18SValeria Barra Not Collective 446b778fa18SValeria Barra 447b778fa18SValeria Barra Input Parameters: 448cab54364SBarry Smith + s - the `PetscSection` 449b778fa18SValeria Barra . field - the field number 450cab54364SBarry Smith - comp - the component number 451cab54364SBarry Smith 452d5b43468SJose E. Roman Output Parameter: 453cab54364SBarry Smith . compName - the component name 454b778fa18SValeria Barra 455b778fa18SValeria Barra Level: intermediate 456b778fa18SValeria Barra 457cab54364SBarry Smith Note: 458cab54364SBarry Smith Will error if the field or component number do not exist 459cab54364SBarry Smith 460cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetFieldName()`, `PetscSectionSetNumFields()`, `PetscSectionGetNumFields()`, 461cab54364SBarry Smith `PetscSectionSetComponentName()`, `PetscSectionSetFieldName()`, `PetscSectionGetFieldComponents()`, `PetscSectionSetFieldComponents()` 462b778fa18SValeria Barra @*/ 463d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetComponentName(PetscSection s, PetscInt field, PetscInt comp, const char *compName[]) 464d71ae5a4SJacob Faibussowitsch { 465b778fa18SValeria Barra PetscFunctionBegin; 466b778fa18SValeria Barra PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 467064a246eSJacob Faibussowitsch PetscValidPointer(compName, 4); 4682abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 4692abc8c78SJacob Faibussowitsch PetscSectionCheckValidFieldComponent(comp, s->numFieldComponents[field]); 470b778fa18SValeria Barra *compName = s->compNames[field][comp]; 471b778fa18SValeria Barra PetscFunctionReturn(0); 472b778fa18SValeria Barra } 473b778fa18SValeria Barra 474b778fa18SValeria Barra /*@C 475cab54364SBarry Smith PetscSectionSetComponentName - Sets the name of a field component in the `PetscSection` 476b778fa18SValeria Barra 477b778fa18SValeria Barra Not Collective 478b778fa18SValeria Barra 479b778fa18SValeria Barra Input Parameters: 480b778fa18SValeria Barra + s - the PetscSection 481b778fa18SValeria Barra . field - the field number 482b778fa18SValeria Barra . comp - the component number 483b778fa18SValeria Barra - compName - the component name 484b778fa18SValeria Barra 485b778fa18SValeria Barra Level: intermediate 486b778fa18SValeria Barra 487cab54364SBarry Smith Note: 488cab54364SBarry Smith Will error if the field or component number do not exist 489cab54364SBarry Smith 490cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetComponentName()`, `PetscSectionSetNumFields()`, `PetscSectionGetNumFields()`, 491cab54364SBarry Smith `PetscSectionSetComponentName()`, `PetscSectionSetFieldName()`, `PetscSectionGetFieldComponents()`, `PetscSectionSetFieldComponents()` 492b778fa18SValeria Barra @*/ 493d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetComponentName(PetscSection s, PetscInt field, PetscInt comp, const char compName[]) 494d71ae5a4SJacob Faibussowitsch { 495b778fa18SValeria Barra PetscFunctionBegin; 496b778fa18SValeria Barra PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 497064a246eSJacob Faibussowitsch if (compName) PetscValidCharPointer(compName, 4); 4982abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 4992abc8c78SJacob Faibussowitsch PetscSectionCheckValidFieldComponent(comp, s->numFieldComponents[field]); 5009566063dSJacob Faibussowitsch PetscCall(PetscFree(s->compNames[field][comp])); 5019566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(compName, (char **)&s->compNames[field][comp])); 502b778fa18SValeria Barra PetscFunctionReturn(0); 503b778fa18SValeria Barra } 504b778fa18SValeria Barra 505ea844a1aSMatthew Knepley /*@ 506ea844a1aSMatthew Knepley PetscSectionGetFieldComponents - Returns the number of field components for the given field. 507ea844a1aSMatthew Knepley 50840750d41SVaclav Hapla Not Collective 509ea844a1aSMatthew Knepley 510ea844a1aSMatthew Knepley Input Parameters: 511cab54364SBarry Smith + s - the `PetscSection` 512ea844a1aSMatthew Knepley - field - the field number 513ea844a1aSMatthew Knepley 514ea844a1aSMatthew Knepley Output Parameter: 515ea844a1aSMatthew Knepley . numComp - the number of field components 516ea844a1aSMatthew Knepley 517ea844a1aSMatthew Knepley Level: intermediate 518ea844a1aSMatthew Knepley 519cab54364SBarry Smith Developer Note: 520cab54364SBarry Smith This function is misnamed. There is a Num in `PetscSectionGetNumFields()` but not in this name 521cab54364SBarry Smith 522cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetFieldComponents()`, `PetscSectionGetNumFields()` 523ea844a1aSMatthew Knepley @*/ 524d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldComponents(PetscSection s, PetscInt field, PetscInt *numComp) 525d71ae5a4SJacob Faibussowitsch { 526ea844a1aSMatthew Knepley PetscFunctionBegin; 527ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 5282abc8c78SJacob Faibussowitsch PetscValidIntPointer(numComp, 3); 5292abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 530ea844a1aSMatthew Knepley *numComp = s->numFieldComponents[field]; 531ea844a1aSMatthew Knepley PetscFunctionReturn(0); 532ea844a1aSMatthew Knepley } 533ea844a1aSMatthew Knepley 534ea844a1aSMatthew Knepley /*@ 535ea844a1aSMatthew Knepley PetscSectionSetFieldComponents - Sets the number of field components for the given field. 536ea844a1aSMatthew Knepley 53740750d41SVaclav Hapla Not Collective 538ea844a1aSMatthew Knepley 539ea844a1aSMatthew Knepley Input Parameters: 540ea844a1aSMatthew Knepley + s - the PetscSection 541ea844a1aSMatthew Knepley . field - the field number 542ea844a1aSMatthew Knepley - numComp - the number of field components 543ea844a1aSMatthew Knepley 544ea844a1aSMatthew Knepley Level: intermediate 545ea844a1aSMatthew Knepley 546cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetFieldComponents()`, `PetscSectionGetNumFields()` 547ea844a1aSMatthew Knepley @*/ 548d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldComponents(PetscSection s, PetscInt field, PetscInt numComp) 549d71ae5a4SJacob Faibussowitsch { 550b778fa18SValeria Barra PetscInt c; 551b778fa18SValeria Barra 552ea844a1aSMatthew Knepley PetscFunctionBegin; 553ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 5542abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 555b778fa18SValeria Barra if (s->compNames) { 55648a46eb9SPierre Jolivet for (c = 0; c < s->numFieldComponents[field]; ++c) PetscCall(PetscFree(s->compNames[field][c])); 5579566063dSJacob Faibussowitsch PetscCall(PetscFree(s->compNames[field])); 558b778fa18SValeria Barra } 559b778fa18SValeria Barra 560ea844a1aSMatthew Knepley s->numFieldComponents[field] = numComp; 561b778fa18SValeria Barra if (numComp) { 5629566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(numComp, (char ***)&s->compNames[field])); 563b778fa18SValeria Barra for (c = 0; c < numComp; ++c) { 5642abc8c78SJacob Faibussowitsch char name[64]; 5652abc8c78SJacob Faibussowitsch 5669566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(name, 64, "%" PetscInt_FMT, c)); 5679566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, (char **)&s->compNames[field][c])); 568b778fa18SValeria Barra } 569b778fa18SValeria Barra } 570ea844a1aSMatthew Knepley PetscFunctionReturn(0); 571ea844a1aSMatthew Knepley } 572ea844a1aSMatthew Knepley 573ea844a1aSMatthew Knepley /*@ 574cab54364SBarry Smith PetscSectionGetChart - Returns the range [pStart, pEnd) in which points (indices) lie for this `PetscSection` 575ea844a1aSMatthew Knepley 57640750d41SVaclav Hapla Not Collective 577ea844a1aSMatthew Knepley 578ea844a1aSMatthew Knepley Input Parameter: 579cab54364SBarry Smith . s - the `PetscSection` 580ea844a1aSMatthew Knepley 581ea844a1aSMatthew Knepley Output Parameters: 582ea844a1aSMatthew Knepley + pStart - the first point 583ea844a1aSMatthew Knepley - pEnd - one past the last point 584ea844a1aSMatthew Knepley 585ea844a1aSMatthew Knepley Level: intermediate 586ea844a1aSMatthew Knepley 587cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetChart()`, `PetscSectionCreate()` 588ea844a1aSMatthew Knepley @*/ 589d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetChart(PetscSection s, PetscInt *pStart, PetscInt *pEnd) 590d71ae5a4SJacob Faibussowitsch { 591ea844a1aSMatthew Knepley PetscFunctionBegin; 592ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 593ea844a1aSMatthew Knepley if (pStart) *pStart = s->pStart; 594ea844a1aSMatthew Knepley if (pEnd) *pEnd = s->pEnd; 595ea844a1aSMatthew Knepley PetscFunctionReturn(0); 596ea844a1aSMatthew Knepley } 597ea844a1aSMatthew Knepley 598ea844a1aSMatthew Knepley /*@ 599cab54364SBarry Smith PetscSectionSetChart - Sets the range [pStart, pEnd) in which points (indices) lie for this `PetscSection` 600ea844a1aSMatthew Knepley 60140750d41SVaclav Hapla Not Collective 602ea844a1aSMatthew Knepley 603ea844a1aSMatthew Knepley Input Parameters: 604ea844a1aSMatthew Knepley + s - the PetscSection 605ea844a1aSMatthew Knepley . pStart - the first point 606ea844a1aSMatthew Knepley - pEnd - one past the last point 607ea844a1aSMatthew Knepley 608ea844a1aSMatthew Knepley Level: intermediate 609ea844a1aSMatthew Knepley 610cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetChart()`, `PetscSectionCreate()` 611ea844a1aSMatthew Knepley @*/ 612d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetChart(PetscSection s, PetscInt pStart, PetscInt pEnd) 613d71ae5a4SJacob Faibussowitsch { 614ea844a1aSMatthew Knepley PetscInt f; 615ea844a1aSMatthew Knepley 616ea844a1aSMatthew Knepley PetscFunctionBegin; 617ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 6189318fe57SMatthew G. Knepley if (pStart == s->pStart && pEnd == s->pEnd) PetscFunctionReturn(0); 619ea844a1aSMatthew Knepley /* Cannot Reset() because it destroys field information */ 620ea844a1aSMatthew Knepley s->setup = PETSC_FALSE; 6219566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->bc)); 6229566063dSJacob Faibussowitsch PetscCall(PetscFree(s->bcIndices)); 6239566063dSJacob Faibussowitsch PetscCall(PetscFree2(s->atlasDof, s->atlasOff)); 624ea844a1aSMatthew Knepley 625ea844a1aSMatthew Knepley s->pStart = pStart; 626ea844a1aSMatthew Knepley s->pEnd = pEnd; 6279566063dSJacob Faibussowitsch PetscCall(PetscMalloc2((pEnd - pStart), &s->atlasDof, (pEnd - pStart), &s->atlasOff)); 6289566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(s->atlasDof, pEnd - pStart)); 62948a46eb9SPierre Jolivet for (f = 0; f < s->numFields; ++f) PetscCall(PetscSectionSetChart(s->field[f], pStart, pEnd)); 630ea844a1aSMatthew Knepley PetscFunctionReturn(0); 631ea844a1aSMatthew Knepley } 632ea844a1aSMatthew Knepley 633ea844a1aSMatthew Knepley /*@ 634cab54364SBarry Smith PetscSectionGetPermutation - Returns the permutation of [0, pEnd-pStart) or NULL that was set with `PetscSectionSetPermutation()` 635ea844a1aSMatthew Knepley 63640750d41SVaclav Hapla Not Collective 637ea844a1aSMatthew Knepley 638ea844a1aSMatthew Knepley Input Parameter: 639cab54364SBarry Smith . s - the `PetscSection` 640ea844a1aSMatthew Knepley 641ea844a1aSMatthew Knepley Output Parameters: 642cab54364SBarry Smith . perm - The permutation as an `IS` 643ea844a1aSMatthew Knepley 644ea844a1aSMatthew Knepley Level: intermediate 645ea844a1aSMatthew Knepley 646cab54364SBarry Smith .seealso: [](sec_scatter), `IS`, `PetscSection`, `PetscSectionSetPermutation()`, `PetscSectionCreate()` 647ea844a1aSMatthew Knepley @*/ 648d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetPermutation(PetscSection s, IS *perm) 649d71ae5a4SJacob Faibussowitsch { 650ea844a1aSMatthew Knepley PetscFunctionBegin; 651ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 6529371c9d4SSatish Balay if (perm) { 6539371c9d4SSatish Balay PetscValidPointer(perm, 2); 6549371c9d4SSatish Balay *perm = s->perm; 6559371c9d4SSatish Balay } 656ea844a1aSMatthew Knepley PetscFunctionReturn(0); 657ea844a1aSMatthew Knepley } 658ea844a1aSMatthew Knepley 659ea844a1aSMatthew Knepley /*@ 660ea844a1aSMatthew Knepley PetscSectionSetPermutation - Sets the permutation for [0, pEnd-pStart) 661ea844a1aSMatthew Knepley 66240750d41SVaclav Hapla Not Collective 663ea844a1aSMatthew Knepley 664ea844a1aSMatthew Knepley Input Parameters: 665ea844a1aSMatthew Knepley + s - the PetscSection 666ea844a1aSMatthew Knepley - perm - the permutation of points 667ea844a1aSMatthew Knepley 668ea844a1aSMatthew Knepley Level: intermediate 669ea844a1aSMatthew Knepley 670cab54364SBarry Smith Developer Note: 671cab54364SBarry Smith What purpose does this permutation serve? 672cab54364SBarry Smith 673cab54364SBarry Smith .seealso: [](sec_scatter), `IS`, `PetscSection`, `PetscSectionGetPermutation()`, `PetscSectionCreate()` 674ea844a1aSMatthew Knepley @*/ 675d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetPermutation(PetscSection s, IS perm) 676d71ae5a4SJacob Faibussowitsch { 677ea844a1aSMatthew Knepley PetscFunctionBegin; 678ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 679ea844a1aSMatthew Knepley if (perm) PetscValidHeaderSpecific(perm, IS_CLASSID, 2); 68028b400f6SJacob Faibussowitsch PetscCheck(!s->setup, PetscObjectComm((PetscObject)s), PETSC_ERR_ARG_WRONGSTATE, "Cannot set a permutation after the section is setup"); 681ea844a1aSMatthew Knepley if (s->perm != perm) { 6829566063dSJacob Faibussowitsch PetscCall(ISDestroy(&s->perm)); 683ea844a1aSMatthew Knepley if (perm) { 684ea844a1aSMatthew Knepley s->perm = perm; 6859566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)s->perm)); 686ea844a1aSMatthew Knepley } 687ea844a1aSMatthew Knepley } 688ea844a1aSMatthew Knepley PetscFunctionReturn(0); 689ea844a1aSMatthew Knepley } 690ea844a1aSMatthew Knepley 691ea844a1aSMatthew Knepley /*@ 692cab54364SBarry Smith PetscSectionGetPointMajor - Returns the flag for dof ordering, `PETSC_TRUE` if it is point major, `PETSC_FALSE` if it is field major 693ea844a1aSMatthew Knepley 69440750d41SVaclav Hapla Not Collective 695ea844a1aSMatthew Knepley 696ea844a1aSMatthew Knepley Input Parameter: 697cab54364SBarry Smith . s - the `PetscSection` 698ea844a1aSMatthew Knepley 699ea844a1aSMatthew Knepley Output Parameter: 700ea844a1aSMatthew Knepley . pm - the flag for point major ordering 701ea844a1aSMatthew Knepley 702ea844a1aSMatthew Knepley Level: intermediate 703ea844a1aSMatthew Knepley 704cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, PetscSectionSetPointMajor()` 705ea844a1aSMatthew Knepley @*/ 706d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetPointMajor(PetscSection s, PetscBool *pm) 707d71ae5a4SJacob Faibussowitsch { 708ea844a1aSMatthew Knepley PetscFunctionBegin; 709ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 710dadcf809SJacob Faibussowitsch PetscValidBoolPointer(pm, 2); 711ea844a1aSMatthew Knepley *pm = s->pointMajor; 712ea844a1aSMatthew Knepley PetscFunctionReturn(0); 713ea844a1aSMatthew Knepley } 714ea844a1aSMatthew Knepley 715ea844a1aSMatthew Knepley /*@ 716cab54364SBarry Smith PetscSectionSetPointMajor - Sets the flag for dof ordering, `PETSC_TRUE` for point major, otherwise it will be field major 717ea844a1aSMatthew Knepley 71840750d41SVaclav Hapla Not Collective 719ea844a1aSMatthew Knepley 720ea844a1aSMatthew Knepley Input Parameters: 721cab54364SBarry Smith + s - the `PetscSection` 722ea844a1aSMatthew Knepley - pm - the flag for point major ordering 723ea844a1aSMatthew Knepley 724ea844a1aSMatthew Knepley Level: intermediate 725ea844a1aSMatthew Knepley 726cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetPointMajor()` 727ea844a1aSMatthew Knepley @*/ 728d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetPointMajor(PetscSection s, PetscBool pm) 729d71ae5a4SJacob Faibussowitsch { 730ea844a1aSMatthew Knepley PetscFunctionBegin; 731ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 73228b400f6SJacob Faibussowitsch PetscCheck(!s->setup, PetscObjectComm((PetscObject)s), PETSC_ERR_ARG_WRONGSTATE, "Cannot set the dof ordering after the section is setup"); 733ea844a1aSMatthew Knepley s->pointMajor = pm; 734ea844a1aSMatthew Knepley PetscFunctionReturn(0); 735ea844a1aSMatthew Knepley } 736ea844a1aSMatthew Knepley 737ea844a1aSMatthew Knepley /*@ 738cab54364SBarry Smith PetscSectionGetIncludesConstraints - Returns the flag indicating if constrained dofs were included when computing offsets in the `PetscSection`. 739cab54364SBarry Smith The value is set with `PetscSectionSetIncludesConstraints()` 74087e637c6Sksagiyam 74140750d41SVaclav Hapla Not Collective 74287e637c6Sksagiyam 74387e637c6Sksagiyam Input Parameter: 744cab54364SBarry Smith . s - the `PetscSection` 74587e637c6Sksagiyam 74687e637c6Sksagiyam Output Parameter: 74787e637c6Sksagiyam . includesConstraints - the flag indicating if constrained dofs were included when computing offsets 74887e637c6Sksagiyam 74987e637c6Sksagiyam Level: intermediate 75087e637c6Sksagiyam 751cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetIncludesConstraints()` 75287e637c6Sksagiyam @*/ 753d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetIncludesConstraints(PetscSection s, PetscBool *includesConstraints) 754d71ae5a4SJacob Faibussowitsch { 75587e637c6Sksagiyam PetscFunctionBegin; 75687e637c6Sksagiyam PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 75787e637c6Sksagiyam PetscValidBoolPointer(includesConstraints, 2); 75887e637c6Sksagiyam *includesConstraints = s->includesConstraints; 75987e637c6Sksagiyam PetscFunctionReturn(0); 76087e637c6Sksagiyam } 76187e637c6Sksagiyam 76287e637c6Sksagiyam /*@ 76387e637c6Sksagiyam PetscSectionSetIncludesConstraints - Sets the flag indicating if constrained dofs are to be included when computing offsets 76487e637c6Sksagiyam 76540750d41SVaclav Hapla Not Collective 76687e637c6Sksagiyam 76787e637c6Sksagiyam Input Parameters: 76887e637c6Sksagiyam + s - the PetscSection 76987e637c6Sksagiyam - includesConstraints - the flag indicating if constrained dofs are to be included when computing offsets 77087e637c6Sksagiyam 77187e637c6Sksagiyam Level: intermediate 77287e637c6Sksagiyam 773cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetIncludesConstraints()` 77487e637c6Sksagiyam @*/ 775d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetIncludesConstraints(PetscSection s, PetscBool includesConstraints) 776d71ae5a4SJacob Faibussowitsch { 77787e637c6Sksagiyam PetscFunctionBegin; 77887e637c6Sksagiyam PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 77928b400f6SJacob Faibussowitsch PetscCheck(!s->setup, PetscObjectComm((PetscObject)s), PETSC_ERR_ARG_WRONGSTATE, "Cannot set includesConstraints after the section is set up"); 78087e637c6Sksagiyam s->includesConstraints = includesConstraints; 78187e637c6Sksagiyam PetscFunctionReturn(0); 78287e637c6Sksagiyam } 78387e637c6Sksagiyam 78487e637c6Sksagiyam /*@ 785ea844a1aSMatthew Knepley PetscSectionGetDof - Return the number of degrees of freedom associated with a given point. 786ea844a1aSMatthew Knepley 78740750d41SVaclav Hapla Not Collective 788ea844a1aSMatthew Knepley 789ea844a1aSMatthew Knepley Input Parameters: 790cab54364SBarry Smith + s - the `PetscSection` 791ea844a1aSMatthew Knepley - point - the point 792ea844a1aSMatthew Knepley 793ea844a1aSMatthew Knepley Output Parameter: 794ea844a1aSMatthew Knepley . numDof - the number of dof 795ea844a1aSMatthew Knepley 796db527f05SMatthew G. Knepley Note: 797db527f05SMatthew G. Knepley In a global section, this size will be negative for points not owned by this process. 798db527f05SMatthew G. Knepley 799ea844a1aSMatthew Knepley Level: intermediate 800ea844a1aSMatthew Knepley 801cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetDof()`, `PetscSectionCreate()` 802ea844a1aSMatthew Knepley @*/ 803d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetDof(PetscSection s, PetscInt point, PetscInt *numDof) 804d71ae5a4SJacob Faibussowitsch { 80576bd3646SJed Brown PetscFunctionBeginHot; 806ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 807dadcf809SJacob Faibussowitsch PetscValidIntPointer(numDof, 3); 808c8bf3acbSVaclav 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); 809ea844a1aSMatthew Knepley *numDof = s->atlasDof[point - s->pStart]; 810ea844a1aSMatthew Knepley PetscFunctionReturn(0); 811ea844a1aSMatthew Knepley } 812ea844a1aSMatthew Knepley 813ea844a1aSMatthew Knepley /*@ 814ea844a1aSMatthew Knepley PetscSectionSetDof - Sets the number of degrees of freedom associated with a given point. 815ea844a1aSMatthew Knepley 81640750d41SVaclav Hapla Not Collective 817ea844a1aSMatthew Knepley 818ea844a1aSMatthew Knepley Input Parameters: 819cab54364SBarry Smith + s - the `PetscSection` 820ea844a1aSMatthew Knepley . point - the point 821ea844a1aSMatthew Knepley - numDof - the number of dof 822ea844a1aSMatthew Knepley 823ea844a1aSMatthew Knepley Level: intermediate 824ea844a1aSMatthew Knepley 825cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetDof()`, `PetscSectionAddDof()`, `PetscSectionCreate()` 826ea844a1aSMatthew Knepley @*/ 827d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetDof(PetscSection s, PetscInt point, PetscInt numDof) 828d71ae5a4SJacob Faibussowitsch { 829ea844a1aSMatthew Knepley PetscFunctionBegin; 830ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 831c8bf3acbSVaclav 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); 832ea844a1aSMatthew Knepley s->atlasDof[point - s->pStart] = numDof; 83369c11d05SVaclav Hapla PetscCall(PetscSectionInvalidateMaxDof_Internal(s)); 834ea844a1aSMatthew Knepley PetscFunctionReturn(0); 835ea844a1aSMatthew Knepley } 836ea844a1aSMatthew Knepley 837ea844a1aSMatthew Knepley /*@ 838ea844a1aSMatthew Knepley PetscSectionAddDof - Adds to the number of degrees of freedom associated with a given point. 839ea844a1aSMatthew Knepley 84040750d41SVaclav Hapla Not Collective 841ea844a1aSMatthew Knepley 842ea844a1aSMatthew Knepley Input Parameters: 843cab54364SBarry Smith + s - the `PetscSection` 844ea844a1aSMatthew Knepley . point - the point 845ea844a1aSMatthew Knepley - numDof - the number of additional dof 846ea844a1aSMatthew Knepley 847ea844a1aSMatthew Knepley Level: intermediate 848ea844a1aSMatthew Knepley 849cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetDof()`, `PetscSectionSetDof()`, `PetscSectionCreate()` 850ea844a1aSMatthew Knepley @*/ 851d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionAddDof(PetscSection s, PetscInt point, PetscInt numDof) 852d71ae5a4SJacob Faibussowitsch { 85376bd3646SJed Brown PetscFunctionBeginHot; 854ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 855c8bf3acbSVaclav 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); 856ea844a1aSMatthew Knepley s->atlasDof[point - s->pStart] += numDof; 85769c11d05SVaclav Hapla PetscCall(PetscSectionInvalidateMaxDof_Internal(s)); 858ea844a1aSMatthew Knepley PetscFunctionReturn(0); 859ea844a1aSMatthew Knepley } 860ea844a1aSMatthew Knepley 861ea844a1aSMatthew Knepley /*@ 862ea844a1aSMatthew Knepley PetscSectionGetFieldDof - Return the number of degrees of freedom associated with a field on a given point. 863ea844a1aSMatthew Knepley 86440750d41SVaclav Hapla Not Collective 865ea844a1aSMatthew Knepley 866ea844a1aSMatthew Knepley Input Parameters: 867cab54364SBarry Smith + s - the `PetscSection` 868ea844a1aSMatthew Knepley . point - the point 869ea844a1aSMatthew Knepley - field - the field 870ea844a1aSMatthew Knepley 871ea844a1aSMatthew Knepley Output Parameter: 872ea844a1aSMatthew Knepley . numDof - the number of dof 873ea844a1aSMatthew Knepley 874ea844a1aSMatthew Knepley Level: intermediate 875ea844a1aSMatthew Knepley 876cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetFieldDof()`, `PetscSectionCreate()` 877ea844a1aSMatthew Knepley @*/ 878d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldDof(PetscSection s, PetscInt point, PetscInt field, PetscInt *numDof) 879d71ae5a4SJacob Faibussowitsch { 880ea844a1aSMatthew Knepley PetscFunctionBegin; 881ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 8822abc8c78SJacob Faibussowitsch PetscValidIntPointer(numDof, 4); 8832abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 8849566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s->field[field], point, numDof)); 885ea844a1aSMatthew Knepley PetscFunctionReturn(0); 886ea844a1aSMatthew Knepley } 887ea844a1aSMatthew Knepley 888ea844a1aSMatthew Knepley /*@ 889ea844a1aSMatthew Knepley PetscSectionSetFieldDof - Sets the number of degrees of freedom associated with a field on a given point. 890ea844a1aSMatthew Knepley 89140750d41SVaclav Hapla Not Collective 892ea844a1aSMatthew Knepley 893ea844a1aSMatthew Knepley Input Parameters: 894cab54364SBarry Smith + s - the `PetscSection` 895ea844a1aSMatthew Knepley . point - the point 896ea844a1aSMatthew Knepley . field - the field 897ea844a1aSMatthew Knepley - numDof - the number of dof 898ea844a1aSMatthew Knepley 899ea844a1aSMatthew Knepley Level: intermediate 900ea844a1aSMatthew Knepley 901cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetFieldDof()`, `PetscSectionCreate()` 902ea844a1aSMatthew Knepley @*/ 903d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof) 904d71ae5a4SJacob Faibussowitsch { 905ea844a1aSMatthew Knepley PetscFunctionBegin; 906ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 9072abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 9089566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(s->field[field], point, numDof)); 909ea844a1aSMatthew Knepley PetscFunctionReturn(0); 910ea844a1aSMatthew Knepley } 911ea844a1aSMatthew Knepley 912ea844a1aSMatthew Knepley /*@ 913ea844a1aSMatthew Knepley PetscSectionAddFieldDof - Adds a number of degrees of freedom associated with a field on a given point. 914ea844a1aSMatthew Knepley 91540750d41SVaclav Hapla Not Collective 916ea844a1aSMatthew Knepley 917ea844a1aSMatthew Knepley Input Parameters: 918cab54364SBarry Smith + s - the `PetscSection` 919ea844a1aSMatthew Knepley . point - the point 920ea844a1aSMatthew Knepley . field - the field 921ea844a1aSMatthew Knepley - numDof - the number of dof 922ea844a1aSMatthew Knepley 923ea844a1aSMatthew Knepley Level: intermediate 924ea844a1aSMatthew Knepley 925cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetFieldDof()`, `PetscSectionGetFieldDof()`, `PetscSectionCreate()` 926ea844a1aSMatthew Knepley @*/ 927d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionAddFieldDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof) 928d71ae5a4SJacob Faibussowitsch { 929ea844a1aSMatthew Knepley PetscFunctionBegin; 930ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 9312abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 9329566063dSJacob Faibussowitsch PetscCall(PetscSectionAddDof(s->field[field], point, numDof)); 933ea844a1aSMatthew Knepley PetscFunctionReturn(0); 934ea844a1aSMatthew Knepley } 935ea844a1aSMatthew Knepley 936ea844a1aSMatthew Knepley /*@ 937ea844a1aSMatthew Knepley PetscSectionGetConstraintDof - Return the number of constrained degrees of freedom associated with a given point. 938ea844a1aSMatthew Knepley 93940750d41SVaclav Hapla Not Collective 940ea844a1aSMatthew Knepley 941ea844a1aSMatthew Knepley Input Parameters: 942cab54364SBarry Smith + s - the `PetscSection` 943ea844a1aSMatthew Knepley - point - the point 944ea844a1aSMatthew Knepley 945ea844a1aSMatthew Knepley Output Parameter: 946ea844a1aSMatthew Knepley . numDof - the number of dof which are fixed by constraints 947ea844a1aSMatthew Knepley 948ea844a1aSMatthew Knepley Level: intermediate 949ea844a1aSMatthew Knepley 950cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetDof()`, `PetscSectionSetConstraintDof()`, `PetscSectionCreate()` 951ea844a1aSMatthew Knepley @*/ 952d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetConstraintDof(PetscSection s, PetscInt point, PetscInt *numDof) 953d71ae5a4SJacob Faibussowitsch { 954ea844a1aSMatthew Knepley PetscFunctionBegin; 955ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 956dadcf809SJacob Faibussowitsch PetscValidIntPointer(numDof, 3); 957ea844a1aSMatthew Knepley if (s->bc) { 9589566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s->bc, point, numDof)); 959ea844a1aSMatthew Knepley } else *numDof = 0; 960ea844a1aSMatthew Knepley PetscFunctionReturn(0); 961ea844a1aSMatthew Knepley } 962ea844a1aSMatthew Knepley 963ea844a1aSMatthew Knepley /*@ 964ea844a1aSMatthew Knepley PetscSectionSetConstraintDof - Set the number of constrained degrees of freedom associated with a given point. 965ea844a1aSMatthew Knepley 96640750d41SVaclav Hapla Not Collective 967ea844a1aSMatthew Knepley 968ea844a1aSMatthew Knepley Input Parameters: 969cab54364SBarry Smith + s - the `PetscSection` 970ea844a1aSMatthew Knepley . point - the point 971ea844a1aSMatthew Knepley - numDof - the number of dof which are fixed by constraints 972ea844a1aSMatthew Knepley 973ea844a1aSMatthew Knepley Level: intermediate 974ea844a1aSMatthew Knepley 975cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetDof()`, `PetscSectionGetConstraintDof()`, `PetscSectionCreate()` 976ea844a1aSMatthew Knepley @*/ 977d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetConstraintDof(PetscSection s, PetscInt point, PetscInt numDof) 978d71ae5a4SJacob Faibussowitsch { 979ea844a1aSMatthew Knepley PetscFunctionBegin; 980ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 981ea844a1aSMatthew Knepley if (numDof) { 9827c0883d5SVaclav Hapla PetscCall(PetscSectionCheckConstraints_Private(s)); 9839566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(s->bc, point, numDof)); 984ea844a1aSMatthew Knepley } 985ea844a1aSMatthew Knepley PetscFunctionReturn(0); 986ea844a1aSMatthew Knepley } 987ea844a1aSMatthew Knepley 988ea844a1aSMatthew Knepley /*@ 989ea844a1aSMatthew Knepley PetscSectionAddConstraintDof - Increment the number of constrained degrees of freedom associated with a given point. 990ea844a1aSMatthew Knepley 99140750d41SVaclav Hapla Not Collective 992ea844a1aSMatthew Knepley 993ea844a1aSMatthew Knepley Input Parameters: 994cab54364SBarry Smith + s - the `PetscSection` 995ea844a1aSMatthew Knepley . point - the point 996ea844a1aSMatthew Knepley - numDof - the number of additional dof which are fixed by constraints 997ea844a1aSMatthew Knepley 998ea844a1aSMatthew Knepley Level: intermediate 999ea844a1aSMatthew Knepley 1000cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionAddDof()`, `PetscSectionGetConstraintDof()`, `PetscSectionCreate()` 1001ea844a1aSMatthew Knepley @*/ 1002d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionAddConstraintDof(PetscSection s, PetscInt point, PetscInt numDof) 1003d71ae5a4SJacob Faibussowitsch { 1004ea844a1aSMatthew Knepley PetscFunctionBegin; 1005ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1006ea844a1aSMatthew Knepley if (numDof) { 10077c0883d5SVaclav Hapla PetscCall(PetscSectionCheckConstraints_Private(s)); 10089566063dSJacob Faibussowitsch PetscCall(PetscSectionAddDof(s->bc, point, numDof)); 1009ea844a1aSMatthew Knepley } 1010ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1011ea844a1aSMatthew Knepley } 1012ea844a1aSMatthew Knepley 1013ea844a1aSMatthew Knepley /*@ 1014ea844a1aSMatthew Knepley PetscSectionGetFieldConstraintDof - Return the number of constrained degrees of freedom associated with a given field on a point. 1015ea844a1aSMatthew Knepley 101640750d41SVaclav Hapla Not Collective 1017ea844a1aSMatthew Knepley 1018ea844a1aSMatthew Knepley Input Parameters: 1019cab54364SBarry Smith + s - the `PetscSection` 1020ea844a1aSMatthew Knepley . point - the point 1021ea844a1aSMatthew Knepley - field - the field 1022ea844a1aSMatthew Knepley 1023ea844a1aSMatthew Knepley Output Parameter: 1024ea844a1aSMatthew Knepley . numDof - the number of dof which are fixed by constraints 1025ea844a1aSMatthew Knepley 1026ea844a1aSMatthew Knepley Level: intermediate 1027ea844a1aSMatthew Knepley 1028cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetDof()`, `PetscSectionSetFieldConstraintDof()`, `PetscSectionCreate()` 1029ea844a1aSMatthew Knepley @*/ 1030d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldConstraintDof(PetscSection s, PetscInt point, PetscInt field, PetscInt *numDof) 1031d71ae5a4SJacob Faibussowitsch { 1032ea844a1aSMatthew Knepley PetscFunctionBegin; 1033ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 10342abc8c78SJacob Faibussowitsch PetscValidIntPointer(numDof, 4); 10352abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 10369566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s->field[field], point, numDof)); 1037ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1038ea844a1aSMatthew Knepley } 1039ea844a1aSMatthew Knepley 1040ea844a1aSMatthew Knepley /*@ 1041ea844a1aSMatthew Knepley PetscSectionSetFieldConstraintDof - Set the number of constrained degrees of freedom associated with a given field on a point. 1042ea844a1aSMatthew Knepley 104340750d41SVaclav Hapla Not Collective 1044ea844a1aSMatthew Knepley 1045ea844a1aSMatthew Knepley Input Parameters: 1046cab54364SBarry Smith + s - the `PetscSection` 1047ea844a1aSMatthew Knepley . point - the point 1048ea844a1aSMatthew Knepley . field - the field 1049ea844a1aSMatthew Knepley - numDof - the number of dof which are fixed by constraints 1050ea844a1aSMatthew Knepley 1051ea844a1aSMatthew Knepley Level: intermediate 1052ea844a1aSMatthew Knepley 1053cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetDof()`, `PetscSectionGetFieldConstraintDof()`, `PetscSectionCreate()` 1054ea844a1aSMatthew Knepley @*/ 1055d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldConstraintDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof) 1056d71ae5a4SJacob Faibussowitsch { 1057ea844a1aSMatthew Knepley PetscFunctionBegin; 1058ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 10592abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 10609566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintDof(s->field[field], point, numDof)); 1061ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1062ea844a1aSMatthew Knepley } 1063ea844a1aSMatthew Knepley 1064ea844a1aSMatthew Knepley /*@ 1065ea844a1aSMatthew Knepley PetscSectionAddFieldConstraintDof - Increment the number of constrained degrees of freedom associated with a given field on a point. 1066ea844a1aSMatthew Knepley 106740750d41SVaclav Hapla Not Collective 1068ea844a1aSMatthew Knepley 1069ea844a1aSMatthew Knepley Input Parameters: 1070cab54364SBarry Smith + s - the `PetscSection` 1071ea844a1aSMatthew Knepley . point - the point 1072ea844a1aSMatthew Knepley . field - the field 1073ea844a1aSMatthew Knepley - numDof - the number of additional dof which are fixed by constraints 1074ea844a1aSMatthew Knepley 1075ea844a1aSMatthew Knepley Level: intermediate 1076ea844a1aSMatthew Knepley 1077cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionAddDof()`, `PetscSectionGetFieldConstraintDof()`, `PetscSectionCreate()` 1078ea844a1aSMatthew Knepley @*/ 1079d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionAddFieldConstraintDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof) 1080d71ae5a4SJacob Faibussowitsch { 1081ea844a1aSMatthew Knepley PetscFunctionBegin; 1082ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 10832abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 10849566063dSJacob Faibussowitsch PetscCall(PetscSectionAddConstraintDof(s->field[field], point, numDof)); 1085ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1086ea844a1aSMatthew Knepley } 1087ea844a1aSMatthew Knepley 1088ea844a1aSMatthew Knepley /*@ 1089ea844a1aSMatthew Knepley PetscSectionSetUpBC - Setup the subsections describing boundary conditions. 1090ea844a1aSMatthew Knepley 109140750d41SVaclav Hapla Not Collective 1092ea844a1aSMatthew Knepley 1093ea844a1aSMatthew Knepley Input Parameter: 1094cab54364SBarry Smith . s - the `PetscSection` 1095ea844a1aSMatthew Knepley 1096ea844a1aSMatthew Knepley Level: advanced 1097ea844a1aSMatthew Knepley 1098cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSetUp()`, `PetscSectionCreate()` 1099ea844a1aSMatthew Knepley @*/ 1100d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetUpBC(PetscSection s) 1101d71ae5a4SJacob Faibussowitsch { 1102ea844a1aSMatthew Knepley PetscFunctionBegin; 1103ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1104ea844a1aSMatthew Knepley if (s->bc) { 1105ea844a1aSMatthew Knepley const PetscInt last = (s->bc->pEnd - s->bc->pStart) - 1; 1106ea844a1aSMatthew Knepley 11079566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(s->bc)); 11088da24d32SBarry Smith PetscCall(PetscMalloc1((last >= 0 ? s->bc->atlasOff[last] + s->bc->atlasDof[last] : 0), &s->bcIndices)); 1109ea844a1aSMatthew Knepley } 1110ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1111ea844a1aSMatthew Knepley } 1112ea844a1aSMatthew Knepley 1113ea844a1aSMatthew Knepley /*@ 1114ea844a1aSMatthew Knepley PetscSectionSetUp - Calculate offsets based upon the number of degrees of freedom for each point. 1115ea844a1aSMatthew Knepley 111640750d41SVaclav Hapla Not Collective 1117ea844a1aSMatthew Knepley 1118ea844a1aSMatthew Knepley Input Parameter: 1119cab54364SBarry Smith . s - the `PetscSection` 1120ea844a1aSMatthew Knepley 1121ea844a1aSMatthew Knepley Level: intermediate 1122ea844a1aSMatthew Knepley 1123cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()` 1124ea844a1aSMatthew Knepley @*/ 1125d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetUp(PetscSection s) 1126d71ae5a4SJacob Faibussowitsch { 1127ea844a1aSMatthew Knepley const PetscInt *pind = NULL; 1128ea844a1aSMatthew Knepley PetscInt offset = 0, foff, p, f; 1129ea844a1aSMatthew Knepley 1130ea844a1aSMatthew Knepley PetscFunctionBegin; 1131ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1132ea844a1aSMatthew Knepley if (s->setup) PetscFunctionReturn(0); 1133ea844a1aSMatthew Knepley s->setup = PETSC_TRUE; 1134ea844a1aSMatthew Knepley /* Set offsets and field offsets for all points */ 1135ea844a1aSMatthew Knepley /* Assume that all fields have the same chart */ 113628b400f6SJacob Faibussowitsch PetscCheck(s->includesConstraints, PETSC_COMM_SELF, PETSC_ERR_SUP, "PetscSectionSetUp is currently unsupported for includesConstraints = PETSC_TRUE"); 11379566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISGetIndices(s->perm, &pind)); 1138ea844a1aSMatthew Knepley if (s->pointMajor) { 1139ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) { 1140ea844a1aSMatthew Knepley const PetscInt q = pind ? pind[p] : p; 1141ea844a1aSMatthew Knepley 1142ea844a1aSMatthew Knepley /* Set point offset */ 1143ea844a1aSMatthew Knepley s->atlasOff[q] = offset; 1144ea844a1aSMatthew Knepley offset += s->atlasDof[q]; 1145ea844a1aSMatthew Knepley /* Set field offset */ 1146ea844a1aSMatthew Knepley for (f = 0, foff = s->atlasOff[q]; f < s->numFields; ++f) { 1147ea844a1aSMatthew Knepley PetscSection sf = s->field[f]; 1148ea844a1aSMatthew Knepley 1149ea844a1aSMatthew Knepley sf->atlasOff[q] = foff; 1150ea844a1aSMatthew Knepley foff += sf->atlasDof[q]; 1151ea844a1aSMatthew Knepley } 1152ea844a1aSMatthew Knepley } 1153ea844a1aSMatthew Knepley } else { 1154ea844a1aSMatthew Knepley /* Set field offsets for all points */ 1155ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) { 1156ea844a1aSMatthew Knepley PetscSection sf = s->field[f]; 1157ea844a1aSMatthew Knepley 1158ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) { 1159ea844a1aSMatthew Knepley const PetscInt q = pind ? pind[p] : p; 1160ea844a1aSMatthew Knepley 1161ea844a1aSMatthew Knepley sf->atlasOff[q] = offset; 1162ea844a1aSMatthew Knepley offset += sf->atlasDof[q]; 1163ea844a1aSMatthew Knepley } 1164ea844a1aSMatthew Knepley } 1165ea844a1aSMatthew Knepley /* Disable point offsets since these are unused */ 1166ad540459SPierre Jolivet for (p = 0; p < s->pEnd - s->pStart; ++p) s->atlasOff[p] = -1; 1167ea844a1aSMatthew Knepley } 11689566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISRestoreIndices(s->perm, &pind)); 1169ea844a1aSMatthew Knepley /* Setup BC sections */ 11709566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUpBC(s)); 11719566063dSJacob Faibussowitsch for (f = 0; f < s->numFields; ++f) PetscCall(PetscSectionSetUpBC(s->field[f])); 1172ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1173ea844a1aSMatthew Knepley } 1174ea844a1aSMatthew Knepley 1175ea844a1aSMatthew Knepley /*@ 1176ea844a1aSMatthew Knepley PetscSectionGetMaxDof - Return the maximum number of degrees of freedom on any point in the chart 1177ea844a1aSMatthew Knepley 117840750d41SVaclav Hapla Not Collective 1179ea844a1aSMatthew Knepley 1180ea844a1aSMatthew Knepley Input Parameters: 1181cab54364SBarry Smith . s - the `PetscSection` 1182ea844a1aSMatthew Knepley 1183ea844a1aSMatthew Knepley Output Parameter: 1184ea844a1aSMatthew Knepley . maxDof - the maximum dof 1185ea844a1aSMatthew Knepley 1186ea844a1aSMatthew Knepley Level: intermediate 1187ea844a1aSMatthew Knepley 1188cab54364SBarry Smith Note: 1189cab54364SBarry Smith The returned number is up-to-date without need for `PetscSectionSetUp()`. 119069c11d05SVaclav Hapla 1191cab54364SBarry Smith Developer Note: 119269c11d05SVaclav Hapla The returned number is calculated lazily and stashed. 1193cab54364SBarry Smith 1194cab54364SBarry Smith A call to `PetscSectionInvalidateMaxDof_Internal()` invalidates the stashed value. 1195cab54364SBarry Smith 1196cab54364SBarry Smith `PetscSectionInvalidateMaxDof_Internal()` is called in `PetscSectionSetDof()`, `PetscSectionAddDof()` and `PetscSectionReset()` 1197cab54364SBarry Smith 119869c11d05SVaclav Hapla It should also be called every time atlasDof is modified directly. 119969c11d05SVaclav Hapla 1200cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetDof()`, `PetscSectionSetDof()`, `PetscSectionAddDof()`, `PetscSectionCreate()` 1201ea844a1aSMatthew Knepley @*/ 1202d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetMaxDof(PetscSection s, PetscInt *maxDof) 1203d71ae5a4SJacob Faibussowitsch { 120469c11d05SVaclav Hapla PetscInt p; 120569c11d05SVaclav Hapla 1206ea844a1aSMatthew Knepley PetscFunctionBegin; 1207ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1208dadcf809SJacob Faibussowitsch PetscValidIntPointer(maxDof, 2); 120969c11d05SVaclav Hapla if (s->maxDof == PETSC_MIN_INT) { 121069c11d05SVaclav Hapla s->maxDof = 0; 1211ad540459SPierre Jolivet for (p = 0; p < s->pEnd - s->pStart; ++p) s->maxDof = PetscMax(s->maxDof, s->atlasDof[p]); 121269c11d05SVaclav Hapla } 1213ea844a1aSMatthew Knepley *maxDof = s->maxDof; 1214ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1215ea844a1aSMatthew Knepley } 1216ea844a1aSMatthew Knepley 1217ea844a1aSMatthew Knepley /*@ 1218ea844a1aSMatthew Knepley PetscSectionGetStorageSize - Return the size of an array or local Vec capable of holding all the degrees of freedom. 1219ea844a1aSMatthew Knepley 122040750d41SVaclav Hapla Not Collective 1221ea844a1aSMatthew Knepley 1222ea844a1aSMatthew Knepley Input Parameter: 1223cab54364SBarry Smith . s - the `PetscSection` 1224ea844a1aSMatthew Knepley 1225ea844a1aSMatthew Knepley Output Parameter: 1226ea844a1aSMatthew Knepley . size - the size of an array which can hold all the dofs 1227ea844a1aSMatthew Knepley 1228ea844a1aSMatthew Knepley Level: intermediate 1229ea844a1aSMatthew Knepley 1230cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetOffset()`, `PetscSectionGetConstrainedStorageSize()`, `PetscSectionCreate()` 1231ea844a1aSMatthew Knepley @*/ 1232d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetStorageSize(PetscSection s, PetscInt *size) 1233d71ae5a4SJacob Faibussowitsch { 1234ea844a1aSMatthew Knepley PetscInt p, n = 0; 1235ea844a1aSMatthew Knepley 1236ea844a1aSMatthew Knepley PetscFunctionBegin; 1237ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1238dadcf809SJacob Faibussowitsch PetscValidIntPointer(size, 2); 1239ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) n += s->atlasDof[p] > 0 ? s->atlasDof[p] : 0; 1240ea844a1aSMatthew Knepley *size = n; 1241ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1242ea844a1aSMatthew Knepley } 1243ea844a1aSMatthew Knepley 1244ea844a1aSMatthew Knepley /*@ 1245cab54364SBarry Smith PetscSectionGetConstrainedStorageSize - Return the size of an array or local `Vec` capable of holding all unconstrained degrees of freedom. 1246ea844a1aSMatthew Knepley 124740750d41SVaclav Hapla Not Collective 1248ea844a1aSMatthew Knepley 1249064ec1f3Sprj- Input Parameter: 1250cab54364SBarry Smith . s - the `PetscSection` 1251ea844a1aSMatthew Knepley 1252ea844a1aSMatthew Knepley Output Parameter: 1253ea844a1aSMatthew Knepley . size - the size of an array which can hold all unconstrained dofs 1254ea844a1aSMatthew Knepley 1255ea844a1aSMatthew Knepley Level: intermediate 1256ea844a1aSMatthew Knepley 1257cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetStorageSize()`, `PetscSectionGetOffset()`, `PetscSectionCreate()` 1258ea844a1aSMatthew Knepley @*/ 1259d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetConstrainedStorageSize(PetscSection s, PetscInt *size) 1260d71ae5a4SJacob Faibussowitsch { 1261ea844a1aSMatthew Knepley PetscInt p, n = 0; 1262ea844a1aSMatthew Knepley 1263ea844a1aSMatthew Knepley PetscFunctionBegin; 1264ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1265dadcf809SJacob Faibussowitsch PetscValidIntPointer(size, 2); 1266ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) { 1267ea844a1aSMatthew Knepley const PetscInt cdof = s->bc ? s->bc->atlasDof[p] : 0; 1268ea844a1aSMatthew Knepley n += s->atlasDof[p] > 0 ? s->atlasDof[p] - cdof : 0; 1269ea844a1aSMatthew Knepley } 1270ea844a1aSMatthew Knepley *size = n; 1271ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1272ea844a1aSMatthew Knepley } 1273ea844a1aSMatthew Knepley 1274ea844a1aSMatthew Knepley /*@ 1275ea844a1aSMatthew Knepley PetscSectionCreateGlobalSection - Create a section describing the global field layout using 1276cab54364SBarry Smith the local section and a `PetscSF` describing the section point overlap. 1277ea844a1aSMatthew Knepley 1278ea844a1aSMatthew Knepley Input Parameters: 1279cab54364SBarry Smith + s - The `PetscSection` for the local field layout 1280cab54364SBarry Smith . sf - The `PetscSF` describing parallel layout of the section points (leaves are unowned local points) 1281cab54364SBarry Smith . includeConstraints - By default this is `PETSC_FALSE`, meaning that the global field vector will not possess constrained dofs 1282cab54364SBarry Smith - localOffsets - If `PETSC_TRUE`, use local rather than global offsets for the points 1283ea844a1aSMatthew Knepley 1284ea844a1aSMatthew Knepley Output Parameter: 1285cab54364SBarry Smith . gsection - The `PetscSection` for the global field layout 1286ea844a1aSMatthew Knepley 1287ea844a1aSMatthew Knepley Level: intermediate 1288ea844a1aSMatthew Knepley 1289db527f05SMatthew G. Knepley Notes: 1290db527f05SMatthew G. Knepley If we have a set of local sections defining the layout of a set of local vectors, and also a `PetscSF` to determine which section points are shared and the ownership, we can calculate a global section defining the parallel data layout, and the associated global vector. 1291db527f05SMatthew G. Knepley 1292cab54364SBarry Smith This gives negative sizes and offsets to points not owned by this process 1293cab54364SBarry Smith 1294cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()` 1295ea844a1aSMatthew Knepley @*/ 1296d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateGlobalSection(PetscSection s, PetscSF sf, PetscBool includeConstraints, PetscBool localOffsets, PetscSection *gsection) 1297d71ae5a4SJacob Faibussowitsch { 1298ea844a1aSMatthew Knepley PetscSection gs; 1299ea844a1aSMatthew Knepley const PetscInt *pind = NULL; 1300ea844a1aSMatthew Knepley PetscInt *recv = NULL, *neg = NULL; 1301046d2115Sksagiyam PetscInt pStart, pEnd, p, dof, cdof, off, foff, globalOff = 0, nroots, nlocal, maxleaf; 1302046d2115Sksagiyam PetscInt numFields, f, numComponents; 1303ea844a1aSMatthew Knepley 1304ea844a1aSMatthew Knepley PetscFunctionBegin; 1305ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1306ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sf, PETSCSF_CLASSID, 2); 1307ea844a1aSMatthew Knepley PetscValidLogicalCollectiveBool(s, includeConstraints, 3); 1308ea844a1aSMatthew Knepley PetscValidLogicalCollectiveBool(s, localOffsets, 4); 1309ea844a1aSMatthew Knepley PetscValidPointer(gsection, 5); 131028b400f6SJacob Faibussowitsch PetscCheck(s->pointMajor, PETSC_COMM_SELF, PETSC_ERR_SUP, "No support for field major ordering"); 13119566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), &gs)); 13129566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s, &numFields)); 13139566063dSJacob Faibussowitsch if (numFields > 0) PetscCall(PetscSectionSetNumFields(gs, numFields)); 13149566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 13159566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(gs, pStart, pEnd)); 131687e637c6Sksagiyam gs->includesConstraints = includeConstraints; 13179566063dSJacob Faibussowitsch PetscCall(PetscSFGetGraph(sf, &nroots, NULL, NULL, NULL)); 1318ea844a1aSMatthew Knepley nlocal = nroots; /* The local/leaf space matches global/root space */ 1319ea844a1aSMatthew Knepley /* Must allocate for all points visible to SF, which may be more than this section */ 1320ea844a1aSMatthew Knepley if (nroots >= 0) { /* nroots < 0 means that the graph has not been set, only happens in serial */ 13219566063dSJacob Faibussowitsch PetscCall(PetscSFGetLeafRange(sf, NULL, &maxleaf)); 132208401ef6SPierre Jolivet PetscCheck(nroots >= pEnd, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "SF roots %" PetscInt_FMT " < pEnd %" PetscInt_FMT, nroots, pEnd); 132308401ef6SPierre Jolivet PetscCheck(maxleaf < nroots, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Max local leaf %" PetscInt_FMT " >= nroots %" PetscInt_FMT, maxleaf, nroots); 13249566063dSJacob Faibussowitsch PetscCall(PetscMalloc2(nroots, &neg, nlocal, &recv)); 13259566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(neg, nroots)); 1326ea844a1aSMatthew Knepley } 1327ea844a1aSMatthew Knepley /* Mark all local points with negative dof */ 1328ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 13299566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 13309566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(gs, p, dof)); 13319566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof)); 13329566063dSJacob Faibussowitsch if (!includeConstraints && cdof > 0) PetscCall(PetscSectionSetConstraintDof(gs, p, cdof)); 1333ea844a1aSMatthew Knepley if (neg) neg[p] = -(dof + 1); 1334ea844a1aSMatthew Knepley } 13359566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUpBC(gs)); 13369566063dSJacob 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])); 1337ea844a1aSMatthew Knepley if (nroots >= 0) { 13389566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(recv, nlocal)); 13399566063dSJacob Faibussowitsch PetscCall(PetscSFBcastBegin(sf, MPIU_INT, neg, recv, MPI_REPLACE)); 13409566063dSJacob Faibussowitsch PetscCall(PetscSFBcastEnd(sf, MPIU_INT, neg, recv, MPI_REPLACE)); 1341ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1342ea844a1aSMatthew Knepley if (recv[p] < 0) { 1343ea844a1aSMatthew Knepley gs->atlasDof[p - pStart] = recv[p]; 13449566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 134508401ef6SPierre 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); 1346ea844a1aSMatthew Knepley } 1347ea844a1aSMatthew Knepley } 1348ea844a1aSMatthew Knepley } 1349ea844a1aSMatthew Knepley /* Calculate new sizes, get process offset, and calculate point offsets */ 13509566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISGetIndices(s->perm, &pind)); 1351ea844a1aSMatthew Knepley for (p = 0, off = 0; p < pEnd - pStart; ++p) { 1352ea844a1aSMatthew Knepley const PetscInt q = pind ? pind[p] : p; 1353ea844a1aSMatthew Knepley 1354ea844a1aSMatthew Knepley cdof = (!includeConstraints && s->bc) ? s->bc->atlasDof[q] : 0; 1355ea844a1aSMatthew Knepley gs->atlasOff[q] = off; 1356ea844a1aSMatthew Knepley off += gs->atlasDof[q] > 0 ? gs->atlasDof[q] - cdof : 0; 1357ea844a1aSMatthew Knepley } 1358ea844a1aSMatthew Knepley if (!localOffsets) { 13599566063dSJacob Faibussowitsch PetscCallMPI(MPI_Scan(&off, &globalOff, 1, MPIU_INT, MPI_SUM, PetscObjectComm((PetscObject)s))); 1360ea844a1aSMatthew Knepley globalOff -= off; 1361ea844a1aSMatthew Knepley } 1362ea844a1aSMatthew Knepley for (p = pStart, off = 0; p < pEnd; ++p) { 1363ea844a1aSMatthew Knepley gs->atlasOff[p - pStart] += globalOff; 1364ea844a1aSMatthew Knepley if (neg) neg[p] = -(gs->atlasOff[p - pStart] + 1); 1365ea844a1aSMatthew Knepley } 13669566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISRestoreIndices(s->perm, &pind)); 1367ea844a1aSMatthew Knepley /* Put in negative offsets for ghost points */ 1368ea844a1aSMatthew Knepley if (nroots >= 0) { 13699566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(recv, nlocal)); 13709566063dSJacob Faibussowitsch PetscCall(PetscSFBcastBegin(sf, MPIU_INT, neg, recv, MPI_REPLACE)); 13719566063dSJacob Faibussowitsch PetscCall(PetscSFBcastEnd(sf, MPIU_INT, neg, recv, MPI_REPLACE)); 1372ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1373ea844a1aSMatthew Knepley if (recv[p] < 0) gs->atlasOff[p - pStart] = recv[p]; 1374ea844a1aSMatthew Knepley } 1375ea844a1aSMatthew Knepley } 13769566063dSJacob Faibussowitsch PetscCall(PetscFree2(neg, recv)); 1377046d2115Sksagiyam /* Set field dofs/offsets/constraints */ 1378046d2115Sksagiyam for (f = 0; f < numFields; ++f) { 1379046d2115Sksagiyam gs->field[f]->includesConstraints = includeConstraints; 13809566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s, f, &numComponents)); 13819566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(gs, f, numComponents)); 1382046d2115Sksagiyam } 1383046d2115Sksagiyam for (p = pStart; p < pEnd; ++p) { 13849566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(gs, p, &off)); 1385046d2115Sksagiyam for (f = 0, foff = off; f < numFields; ++f) { 13869566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, f, &cdof)); 13879566063dSJacob Faibussowitsch if (!includeConstraints && cdof > 0) PetscCall(PetscSectionSetFieldConstraintDof(gs, p, f, cdof)); 13889566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, f, &dof)); 13899566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldDof(gs, p, f, off < 0 ? -(dof + 1) : dof)); 13909566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldOffset(gs, p, f, foff)); 13919566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(gs, p, f, &cdof)); 1392046d2115Sksagiyam foff = off < 0 ? foff - (dof - cdof) : foff + (dof - cdof); 1393046d2115Sksagiyam } 1394046d2115Sksagiyam } 1395046d2115Sksagiyam for (f = 0; f < numFields; ++f) { 1396046d2115Sksagiyam PetscSection gfs = gs->field[f]; 1397046d2115Sksagiyam 13989566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUpBC(gfs)); 13999566063dSJacob 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])); 1400046d2115Sksagiyam } 1401046d2115Sksagiyam gs->setup = PETSC_TRUE; 14029566063dSJacob Faibussowitsch PetscCall(PetscSectionViewFromOptions(gs, NULL, "-global_section_view")); 1403ea844a1aSMatthew Knepley *gsection = gs; 1404ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1405ea844a1aSMatthew Knepley } 1406ea844a1aSMatthew Knepley 1407ea844a1aSMatthew Knepley /*@ 1408cab54364SBarry Smith PetscSectionCreateGlobalSectionCensored - Create a `PetscSection` describing the global field layout using 1409cab54364SBarry Smith the local section and an `PetscSF` describing the section point overlap. 1410ea844a1aSMatthew Knepley 1411ea844a1aSMatthew Knepley Input Parameters: 1412cab54364SBarry Smith + s - The `PetscSection` for the local field layout 1413cab54364SBarry Smith . sf - The `PetscSF` describing parallel layout of the section points 1414cab54364SBarry Smith . includeConstraints - By default this is `PETSC_FALSE`, meaning that the global field vector will not possess constrained dofs 1415ea844a1aSMatthew Knepley . numExcludes - The number of exclusion ranges 1416ea844a1aSMatthew Knepley - excludes - An array [start_0, end_0, start_1, end_1, ...] where there are numExcludes pairs 1417ea844a1aSMatthew Knepley 1418ea844a1aSMatthew Knepley Output Parameter: 1419cab54364SBarry Smith . gsection - The `PetscSection` for the global field layout 1420ea844a1aSMatthew Knepley 1421ea844a1aSMatthew Knepley Level: advanced 1422ea844a1aSMatthew Knepley 1423cab54364SBarry Smith Note: 1424cab54364SBarry Smith This gives negative sizes and offsets to points not owned by this process 1425cab54364SBarry Smith 1426cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()` 1427ea844a1aSMatthew Knepley @*/ 1428d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateGlobalSectionCensored(PetscSection s, PetscSF sf, PetscBool includeConstraints, PetscInt numExcludes, const PetscInt excludes[], PetscSection *gsection) 1429d71ae5a4SJacob Faibussowitsch { 1430ea844a1aSMatthew Knepley const PetscInt *pind = NULL; 1431ea844a1aSMatthew Knepley PetscInt *neg = NULL, *tmpOff = NULL; 1432ea844a1aSMatthew Knepley PetscInt pStart, pEnd, p, e, dof, cdof, off, globalOff = 0, nroots; 1433ea844a1aSMatthew Knepley 1434ea844a1aSMatthew Knepley PetscFunctionBegin; 1435ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1436ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sf, PETSCSF_CLASSID, 2); 1437ea844a1aSMatthew Knepley PetscValidPointer(gsection, 6); 14389566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), gsection)); 14399566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 14409566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(*gsection, pStart, pEnd)); 14419566063dSJacob Faibussowitsch PetscCall(PetscSFGetGraph(sf, &nroots, NULL, NULL, NULL)); 1442ea844a1aSMatthew Knepley if (nroots >= 0) { 144308401ef6SPierre Jolivet PetscCheck(nroots >= pEnd - pStart, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "PetscSF nroots %" PetscInt_FMT " < %" PetscInt_FMT " section size", nroots, pEnd - pStart); 14449566063dSJacob Faibussowitsch PetscCall(PetscCalloc1(nroots, &neg)); 1445ea844a1aSMatthew Knepley if (nroots > pEnd - pStart) { 14469566063dSJacob Faibussowitsch PetscCall(PetscCalloc1(nroots, &tmpOff)); 1447ea844a1aSMatthew Knepley } else { 1448ea844a1aSMatthew Knepley tmpOff = &(*gsection)->atlasDof[-pStart]; 1449ea844a1aSMatthew Knepley } 1450ea844a1aSMatthew Knepley } 1451ea844a1aSMatthew Knepley /* Mark ghost points with negative dof */ 1452ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1453ea844a1aSMatthew Knepley for (e = 0; e < numExcludes; ++e) { 1454ea844a1aSMatthew Knepley if ((p >= excludes[e * 2 + 0]) && (p < excludes[e * 2 + 1])) { 14559566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(*gsection, p, 0)); 1456ea844a1aSMatthew Knepley break; 1457ea844a1aSMatthew Knepley } 1458ea844a1aSMatthew Knepley } 1459ea844a1aSMatthew Knepley if (e < numExcludes) continue; 14609566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 14619566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(*gsection, p, dof)); 14629566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof)); 14639566063dSJacob Faibussowitsch if (!includeConstraints && cdof > 0) PetscCall(PetscSectionSetConstraintDof(*gsection, p, cdof)); 1464ea844a1aSMatthew Knepley if (neg) neg[p] = -(dof + 1); 1465ea844a1aSMatthew Knepley } 14669566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUpBC(*gsection)); 1467ea844a1aSMatthew Knepley if (nroots >= 0) { 14689566063dSJacob Faibussowitsch PetscCall(PetscSFBcastBegin(sf, MPIU_INT, neg, tmpOff, MPI_REPLACE)); 14699566063dSJacob Faibussowitsch PetscCall(PetscSFBcastEnd(sf, MPIU_INT, neg, tmpOff, MPI_REPLACE)); 1470ea844a1aSMatthew Knepley if (nroots > pEnd - pStart) { 14719371c9d4SSatish Balay for (p = pStart; p < pEnd; ++p) { 14729371c9d4SSatish Balay if (tmpOff[p] < 0) (*gsection)->atlasDof[p - pStart] = tmpOff[p]; 14739371c9d4SSatish Balay } 1474ea844a1aSMatthew Knepley } 1475ea844a1aSMatthew Knepley } 1476*35cb6cd3SPierre Jolivet /* Calculate new sizes, get process offset, and calculate point offsets */ 14779566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISGetIndices(s->perm, &pind)); 1478ea844a1aSMatthew Knepley for (p = 0, off = 0; p < pEnd - pStart; ++p) { 1479ea844a1aSMatthew Knepley const PetscInt q = pind ? pind[p] : p; 1480ea844a1aSMatthew Knepley 1481ea844a1aSMatthew Knepley cdof = (!includeConstraints && s->bc) ? s->bc->atlasDof[q] : 0; 1482ea844a1aSMatthew Knepley (*gsection)->atlasOff[q] = off; 1483ea844a1aSMatthew Knepley off += (*gsection)->atlasDof[q] > 0 ? (*gsection)->atlasDof[q] - cdof : 0; 1484ea844a1aSMatthew Knepley } 14859566063dSJacob Faibussowitsch PetscCallMPI(MPI_Scan(&off, &globalOff, 1, MPIU_INT, MPI_SUM, PetscObjectComm((PetscObject)s))); 1486ea844a1aSMatthew Knepley globalOff -= off; 1487ea844a1aSMatthew Knepley for (p = 0, off = 0; p < pEnd - pStart; ++p) { 1488ea844a1aSMatthew Knepley (*gsection)->atlasOff[p] += globalOff; 1489ea844a1aSMatthew Knepley if (neg) neg[p + pStart] = -((*gsection)->atlasOff[p] + 1); 1490ea844a1aSMatthew Knepley } 14919566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISRestoreIndices(s->perm, &pind)); 1492ea844a1aSMatthew Knepley /* Put in negative offsets for ghost points */ 1493ea844a1aSMatthew Knepley if (nroots >= 0) { 1494ea844a1aSMatthew Knepley if (nroots == pEnd - pStart) tmpOff = &(*gsection)->atlasOff[-pStart]; 14959566063dSJacob Faibussowitsch PetscCall(PetscSFBcastBegin(sf, MPIU_INT, neg, tmpOff, MPI_REPLACE)); 14969566063dSJacob Faibussowitsch PetscCall(PetscSFBcastEnd(sf, MPIU_INT, neg, tmpOff, MPI_REPLACE)); 1497ea844a1aSMatthew Knepley if (nroots > pEnd - pStart) { 14989371c9d4SSatish Balay for (p = pStart; p < pEnd; ++p) { 14999371c9d4SSatish Balay if (tmpOff[p] < 0) (*gsection)->atlasOff[p - pStart] = tmpOff[p]; 15009371c9d4SSatish Balay } 1501ea844a1aSMatthew Knepley } 1502ea844a1aSMatthew Knepley } 15039566063dSJacob Faibussowitsch if (nroots >= 0 && nroots > pEnd - pStart) PetscCall(PetscFree(tmpOff)); 15049566063dSJacob Faibussowitsch PetscCall(PetscFree(neg)); 1505ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1506ea844a1aSMatthew Knepley } 1507ea844a1aSMatthew Knepley 1508ea844a1aSMatthew Knepley /*@ 1509cab54364SBarry Smith PetscSectionGetPointLayout - Get the `PetscLayout` associated with the section points 1510ea844a1aSMatthew Knepley 1511cab54364SBarry Smith Collective 1512ea844a1aSMatthew Knepley 1513ea844a1aSMatthew Knepley Input Parameters: 1514cab54364SBarry Smith + comm - The `MPI_Comm` 1515cab54364SBarry Smith - s - The `PetscSection` 1516ea844a1aSMatthew Knepley 1517ea844a1aSMatthew Knepley Output Parameter: 1518ea844a1aSMatthew Knepley . layout - The point layout for the section 1519ea844a1aSMatthew Knepley 1520ea844a1aSMatthew Knepley Level: advanced 1521ea844a1aSMatthew Knepley 1522cab54364SBarry Smith Note: 1523cab54364SBarry Smith This is usually called for the default global section. 1524cab54364SBarry Smith 1525cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetValueLayout()`, `PetscSectionCreate()` 1526ea844a1aSMatthew Knepley @*/ 1527d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetPointLayout(MPI_Comm comm, PetscSection s, PetscLayout *layout) 1528d71ae5a4SJacob Faibussowitsch { 1529ea844a1aSMatthew Knepley PetscInt pStart, pEnd, p, localSize = 0; 1530ea844a1aSMatthew Knepley 1531ea844a1aSMatthew Knepley PetscFunctionBegin; 15329566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 1533ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1534ea844a1aSMatthew Knepley PetscInt dof; 1535ea844a1aSMatthew Knepley 15369566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 15379120ba30SVaclav Hapla if (dof >= 0) ++localSize; 1538ea844a1aSMatthew Knepley } 15399566063dSJacob Faibussowitsch PetscCall(PetscLayoutCreate(comm, layout)); 15409566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetLocalSize(*layout, localSize)); 15419566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetBlockSize(*layout, 1)); 15429566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetUp(*layout)); 1543ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1544ea844a1aSMatthew Knepley } 1545ea844a1aSMatthew Knepley 1546ea844a1aSMatthew Knepley /*@ 1547cab54364SBarry Smith PetscSectionGetValueLayout - Get the `PetscLayout` associated with the section dofs. 1548ea844a1aSMatthew Knepley 1549cab54364SBarry Smith Collective 1550ea844a1aSMatthew Knepley 1551ea844a1aSMatthew Knepley Input Parameters: 1552cab54364SBarry Smith + comm - The `MPI_Comm` 1553cab54364SBarry Smith - s - The `PetscSection` 1554ea844a1aSMatthew Knepley 1555ea844a1aSMatthew Knepley Output Parameter: 1556ea844a1aSMatthew Knepley . layout - The dof layout for the section 1557ea844a1aSMatthew Knepley 1558ea844a1aSMatthew Knepley Level: advanced 1559ea844a1aSMatthew Knepley 1560cab54364SBarry Smith Note: 1561cab54364SBarry Smith This is usually called for the default global section. 1562cab54364SBarry Smith 1563cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetPointLayout()`, `PetscSectionCreate()` 1564ea844a1aSMatthew Knepley @*/ 1565d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetValueLayout(MPI_Comm comm, PetscSection s, PetscLayout *layout) 1566d71ae5a4SJacob Faibussowitsch { 1567ea844a1aSMatthew Knepley PetscInt pStart, pEnd, p, localSize = 0; 1568ea844a1aSMatthew Knepley 1569ea844a1aSMatthew Knepley PetscFunctionBegin; 1570ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 2); 1571ea844a1aSMatthew Knepley PetscValidPointer(layout, 3); 15729566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 1573ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1574ea844a1aSMatthew Knepley PetscInt dof, cdof; 1575ea844a1aSMatthew Knepley 15769566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 15779566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof)); 1578ea844a1aSMatthew Knepley if (dof - cdof > 0) localSize += dof - cdof; 1579ea844a1aSMatthew Knepley } 15809566063dSJacob Faibussowitsch PetscCall(PetscLayoutCreate(comm, layout)); 15819566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetLocalSize(*layout, localSize)); 15829566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetBlockSize(*layout, 1)); 15839566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetUp(*layout)); 1584ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1585ea844a1aSMatthew Knepley } 1586ea844a1aSMatthew Knepley 1587ea844a1aSMatthew Knepley /*@ 1588db527f05SMatthew G. Knepley PetscSectionGetOffset - Return the offset into an array or `Vec` for the dof associated with the given point. 1589ea844a1aSMatthew Knepley 159040750d41SVaclav Hapla Not Collective 1591ea844a1aSMatthew Knepley 1592ea844a1aSMatthew Knepley Input Parameters: 1593cab54364SBarry Smith + s - the `PetscSection` 1594ea844a1aSMatthew Knepley - point - the point 1595ea844a1aSMatthew Knepley 1596ea844a1aSMatthew Knepley Output Parameter: 1597ea844a1aSMatthew Knepley . offset - the offset 1598ea844a1aSMatthew Knepley 1599db527f05SMatthew G. Knepley Note: 1600db527f05SMatthew G. Knepley In a global section, this offset will be negative for points not owned by this process. 1601db527f05SMatthew G. Knepley 1602ea844a1aSMatthew Knepley Level: intermediate 1603ea844a1aSMatthew Knepley 1604cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetFieldOffset()`, `PetscSectionCreate()` 1605ea844a1aSMatthew Knepley @*/ 1606d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetOffset(PetscSection s, PetscInt point, PetscInt *offset) 1607d71ae5a4SJacob Faibussowitsch { 1608ea844a1aSMatthew Knepley PetscFunctionBegin; 1609ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1610dadcf809SJacob Faibussowitsch PetscValidIntPointer(offset, 3); 1611ad540459SPierre 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); 1612ea844a1aSMatthew Knepley *offset = s->atlasOff[point - s->pStart]; 1613ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1614ea844a1aSMatthew Knepley } 1615ea844a1aSMatthew Knepley 1616ea844a1aSMatthew Knepley /*@ 1617db527f05SMatthew G. Knepley PetscSectionSetOffset - Set the offset into an array or `Vec` for the dof associated with the given point. 1618ea844a1aSMatthew Knepley 161940750d41SVaclav Hapla Not Collective 1620ea844a1aSMatthew Knepley 1621ea844a1aSMatthew Knepley Input Parameters: 1622cab54364SBarry Smith + s - the `PetscSection` 1623ea844a1aSMatthew Knepley . point - the point 1624ea844a1aSMatthew Knepley - offset - the offset 1625ea844a1aSMatthew Knepley 1626ea844a1aSMatthew Knepley Level: intermediate 1627ea844a1aSMatthew Knepley 1628cab54364SBarry Smith Note: 1629cab54364SBarry Smith The user usually does not call this function, but uses `PetscSectionSetUp()` 1630cab54364SBarry Smith 1631cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetFieldOffset()`, `PetscSectionCreate()`, `PetscSectionSetUp()` 1632ea844a1aSMatthew Knepley @*/ 1633d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetOffset(PetscSection s, PetscInt point, PetscInt offset) 1634d71ae5a4SJacob Faibussowitsch { 1635ea844a1aSMatthew Knepley PetscFunctionBegin; 1636ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 163708401ef6SPierre 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); 1638ea844a1aSMatthew Knepley s->atlasOff[point - s->pStart] = offset; 1639ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1640ea844a1aSMatthew Knepley } 1641ea844a1aSMatthew Knepley 1642ea844a1aSMatthew Knepley /*@ 1643db527f05SMatthew G. Knepley PetscSectionGetFieldOffset - Return the offset into an array or `Vec` for the field dof associated with the given point. 1644ea844a1aSMatthew Knepley 164540750d41SVaclav Hapla Not Collective 1646ea844a1aSMatthew Knepley 1647ea844a1aSMatthew Knepley Input Parameters: 1648cab54364SBarry Smith + s - the `PetscSection` 1649ea844a1aSMatthew Knepley . point - the point 1650ea844a1aSMatthew Knepley - field - the field 1651ea844a1aSMatthew Knepley 1652ea844a1aSMatthew Knepley Output Parameter: 1653ea844a1aSMatthew Knepley . offset - the offset 1654ea844a1aSMatthew Knepley 1655db527f05SMatthew G. Knepley Note: 1656db527f05SMatthew G. Knepley In a global section, this offset will be negative for points not owned by this process. 1657db527f05SMatthew G. Knepley 1658ea844a1aSMatthew Knepley Level: intermediate 1659ea844a1aSMatthew Knepley 1660cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetOffset()`, `PetscSectionCreate()` 1661ea844a1aSMatthew Knepley @*/ 1662d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldOffset(PetscSection s, PetscInt point, PetscInt field, PetscInt *offset) 1663d71ae5a4SJacob Faibussowitsch { 1664ea844a1aSMatthew Knepley PetscFunctionBegin; 1665ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 16662abc8c78SJacob Faibussowitsch PetscValidIntPointer(offset, 4); 16672abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 16689566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s->field[field], point, offset)); 1669ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1670ea844a1aSMatthew Knepley } 1671ea844a1aSMatthew Knepley 1672ea844a1aSMatthew Knepley /*@ 1673db527f05SMatthew G. Knepley PetscSectionSetFieldOffset - Set the offset into an array or `Vec` for the dof associated with the given field at a point. 1674ea844a1aSMatthew Knepley 167540750d41SVaclav Hapla Not Collective 1676ea844a1aSMatthew Knepley 1677ea844a1aSMatthew Knepley Input Parameters: 1678ea844a1aSMatthew Knepley + s - the PetscSection 1679ea844a1aSMatthew Knepley . point - the point 1680ea844a1aSMatthew Knepley . field - the field 1681ea844a1aSMatthew Knepley - offset - the offset 1682ea844a1aSMatthew Knepley 1683cab54364SBarry Smith Level: developer 1684ea844a1aSMatthew Knepley 1685cab54364SBarry Smith Note: 1686cab54364SBarry Smith The user usually does not call this function, but uses `PetscSectionSetUp()` 1687ea844a1aSMatthew Knepley 1688cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetFieldOffset()`, `PetscSectionSetOffset()`, `PetscSectionCreate()`, `PetscSectionSetUp()` 1689ea844a1aSMatthew Knepley @*/ 1690d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldOffset(PetscSection s, PetscInt point, PetscInt field, PetscInt offset) 1691d71ae5a4SJacob Faibussowitsch { 1692ea844a1aSMatthew Knepley PetscFunctionBegin; 1693ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 16942abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 16959566063dSJacob Faibussowitsch PetscCall(PetscSectionSetOffset(s->field[field], point, offset)); 1696ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1697ea844a1aSMatthew Knepley } 1698ea844a1aSMatthew Knepley 1699ea844a1aSMatthew Knepley /*@ 1700ea844a1aSMatthew Knepley PetscSectionGetFieldPointOffset - Return the offset on the given point for the dof associated with the given point. 1701ea844a1aSMatthew Knepley 170240750d41SVaclav Hapla Not Collective 1703ea844a1aSMatthew Knepley 1704ea844a1aSMatthew Knepley Input Parameters: 1705cab54364SBarry Smith + s - the `PetscSection` 1706ea844a1aSMatthew Knepley . point - the point 1707ea844a1aSMatthew Knepley - field - the field 1708ea844a1aSMatthew Knepley 1709ea844a1aSMatthew Knepley Output Parameter: 1710ea844a1aSMatthew Knepley . offset - the offset 1711ea844a1aSMatthew Knepley 1712ea844a1aSMatthew Knepley Level: advanced 1713ea844a1aSMatthew Knepley 1714cab54364SBarry Smith Note: 1715cab54364SBarry Smith This gives the offset on a point of the field, ignoring constraints, meaning starting at the first dof for 1716cab54364SBarry Smith this point, what number is the first dof with this field. 1717cab54364SBarry Smith 1718cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetOffset()`, `PetscSectionCreate()` 1719ea844a1aSMatthew Knepley @*/ 1720d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldPointOffset(PetscSection s, PetscInt point, PetscInt field, PetscInt *offset) 1721d71ae5a4SJacob Faibussowitsch { 1722ea844a1aSMatthew Knepley PetscInt off, foff; 1723ea844a1aSMatthew Knepley 1724ea844a1aSMatthew Knepley PetscFunctionBegin; 1725ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 17262abc8c78SJacob Faibussowitsch PetscValidIntPointer(offset, 4); 17272abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 17289566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s, point, &off)); 17299566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s->field[field], point, &foff)); 1730ea844a1aSMatthew Knepley *offset = foff - off; 1731ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1732ea844a1aSMatthew Knepley } 1733ea844a1aSMatthew Knepley 1734ea844a1aSMatthew Knepley /*@ 1735ea844a1aSMatthew Knepley PetscSectionGetOffsetRange - Return the full range of offsets [start, end) 1736ea844a1aSMatthew Knepley 173740750d41SVaclav Hapla Not Collective 1738ea844a1aSMatthew Knepley 1739ea844a1aSMatthew Knepley Input Parameter: 1740cab54364SBarry Smith . s - the `PetscSection` 1741ea844a1aSMatthew Knepley 1742ea844a1aSMatthew Knepley Output Parameters: 1743ea844a1aSMatthew Knepley + start - the minimum offset 1744ea844a1aSMatthew Knepley - end - one more than the maximum offset 1745ea844a1aSMatthew Knepley 1746ea844a1aSMatthew Knepley Level: intermediate 1747ea844a1aSMatthew Knepley 1748cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetOffset()`, `PetscSectionCreate()` 1749ea844a1aSMatthew Knepley @*/ 1750d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetOffsetRange(PetscSection s, PetscInt *start, PetscInt *end) 1751d71ae5a4SJacob Faibussowitsch { 1752ea844a1aSMatthew Knepley PetscInt os = 0, oe = 0, pStart, pEnd, p; 1753ea844a1aSMatthew Knepley 1754ea844a1aSMatthew Knepley PetscFunctionBegin; 1755ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 17569371c9d4SSatish Balay if (s->atlasOff) { 17579371c9d4SSatish Balay os = s->atlasOff[0]; 17589371c9d4SSatish Balay oe = s->atlasOff[0]; 17599371c9d4SSatish Balay } 17609566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 1761ea844a1aSMatthew Knepley for (p = 0; p < pEnd - pStart; ++p) { 1762ea844a1aSMatthew Knepley PetscInt dof = s->atlasDof[p], off = s->atlasOff[p]; 1763ea844a1aSMatthew Knepley 1764ea844a1aSMatthew Knepley if (off >= 0) { 1765ea844a1aSMatthew Knepley os = PetscMin(os, off); 1766ea844a1aSMatthew Knepley oe = PetscMax(oe, off + dof); 1767ea844a1aSMatthew Knepley } 1768ea844a1aSMatthew Knepley } 1769ea844a1aSMatthew Knepley if (start) *start = os; 1770ea844a1aSMatthew Knepley if (end) *end = oe; 1771ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1772ea844a1aSMatthew Knepley } 1773ea844a1aSMatthew Knepley 1774ea844a1aSMatthew Knepley /*@ 1775ea844a1aSMatthew Knepley PetscSectionCreateSubsection - Create a new, smaller section composed of only the selected fields 1776ea844a1aSMatthew Knepley 177740750d41SVaclav Hapla Collective 1778ea844a1aSMatthew Knepley 1779d8d19677SJose E. Roman Input Parameters: 1780cab54364SBarry Smith + s - the `PetscSection` 1781ea844a1aSMatthew Knepley . len - the number of subfields 1782ea844a1aSMatthew Knepley - fields - the subfield numbers 1783ea844a1aSMatthew Knepley 1784ea844a1aSMatthew Knepley Output Parameter: 1785ea844a1aSMatthew Knepley . subs - the subsection 1786ea844a1aSMatthew Knepley 1787ea844a1aSMatthew Knepley Level: advanced 1788ea844a1aSMatthew Knepley 1789cab54364SBarry Smith Notes: 1790cab54364SBarry Smith The section offsets now refer to a new, smaller vector. 1791cab54364SBarry Smith 1792cab54364SBarry Smith This will error if a fieldnumber is out of range 1793cab54364SBarry Smith 1794cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreateSupersection()`, `PetscSectionCreate()` 1795ea844a1aSMatthew Knepley @*/ 1796d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateSubsection(PetscSection s, PetscInt len, const PetscInt fields[], PetscSection *subs) 1797d71ae5a4SJacob Faibussowitsch { 1798b778fa18SValeria Barra PetscInt nF, f, c, pStart, pEnd, p, maxCdof = 0; 1799ea844a1aSMatthew Knepley 1800ea844a1aSMatthew Knepley PetscFunctionBegin; 1801ea844a1aSMatthew Knepley if (!len) PetscFunctionReturn(0); 1802ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1803dadcf809SJacob Faibussowitsch PetscValidIntPointer(fields, 3); 1804ea844a1aSMatthew Knepley PetscValidPointer(subs, 4); 18059566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s, &nF)); 180608401ef6SPierre 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); 18079566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), subs)); 18089566063dSJacob Faibussowitsch PetscCall(PetscSectionSetNumFields(*subs, len)); 1809ea844a1aSMatthew Knepley for (f = 0; f < len; ++f) { 1810ea844a1aSMatthew Knepley const char *name = NULL; 1811ea844a1aSMatthew Knepley PetscInt numComp = 0; 1812ea844a1aSMatthew Knepley 18139566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldName(s, fields[f], &name)); 18149566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldName(*subs, f, name)); 18159566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s, fields[f], &numComp)); 18169566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(*subs, f, numComp)); 1817b778fa18SValeria Barra for (c = 0; c < s->numFieldComponents[fields[f]]; ++c) { 18189566063dSJacob Faibussowitsch PetscCall(PetscSectionGetComponentName(s, fields[f], c, &name)); 18199566063dSJacob Faibussowitsch PetscCall(PetscSectionSetComponentName(*subs, f, c, name)); 1820b778fa18SValeria Barra } 1821ea844a1aSMatthew Knepley } 18229566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 18239566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(*subs, pStart, pEnd)); 1824ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1825ea844a1aSMatthew Knepley PetscInt dof = 0, cdof = 0, fdof = 0, cfdof = 0; 1826ea844a1aSMatthew Knepley 1827ea844a1aSMatthew Knepley for (f = 0; f < len; ++f) { 18289566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, fields[f], &fdof)); 18299566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldDof(*subs, p, f, fdof)); 18309566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, fields[f], &cfdof)); 18319566063dSJacob Faibussowitsch if (cfdof) PetscCall(PetscSectionSetFieldConstraintDof(*subs, p, f, cfdof)); 1832ea844a1aSMatthew Knepley dof += fdof; 1833ea844a1aSMatthew Knepley cdof += cfdof; 1834ea844a1aSMatthew Knepley } 18359566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(*subs, p, dof)); 18369566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetConstraintDof(*subs, p, cdof)); 1837ea844a1aSMatthew Knepley maxCdof = PetscMax(cdof, maxCdof); 1838ea844a1aSMatthew Knepley } 18399566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(*subs)); 1840ea844a1aSMatthew Knepley if (maxCdof) { 1841ea844a1aSMatthew Knepley PetscInt *indices; 1842ea844a1aSMatthew Knepley 18439566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(maxCdof, &indices)); 1844ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1845ea844a1aSMatthew Knepley PetscInt cdof; 1846ea844a1aSMatthew Knepley 18479566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(*subs, p, &cdof)); 1848ea844a1aSMatthew Knepley if (cdof) { 1849ea844a1aSMatthew Knepley const PetscInt *oldIndices = NULL; 1850ea844a1aSMatthew Knepley PetscInt fdof = 0, cfdof = 0, fc, numConst = 0, fOff = 0; 1851ea844a1aSMatthew Knepley 1852ea844a1aSMatthew Knepley for (f = 0; f < len; ++f) { 18539566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, fields[f], &fdof)); 18549566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, fields[f], &cfdof)); 18559566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(s, p, fields[f], &oldIndices)); 18569566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldConstraintIndices(*subs, p, f, oldIndices)); 18579574d0f0SMatthew G. Knepley for (fc = 0; fc < cfdof; ++fc) indices[numConst + fc] = oldIndices[fc] + fOff; 1858ea844a1aSMatthew Knepley numConst += cfdof; 1859ea844a1aSMatthew Knepley fOff += fdof; 1860ea844a1aSMatthew Knepley } 18619566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(*subs, p, indices)); 1862ea844a1aSMatthew Knepley } 1863ea844a1aSMatthew Knepley } 18649566063dSJacob Faibussowitsch PetscCall(PetscFree(indices)); 1865ea844a1aSMatthew Knepley } 1866ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1867ea844a1aSMatthew Knepley } 1868ea844a1aSMatthew Knepley 1869ea844a1aSMatthew Knepley /*@ 1870ea844a1aSMatthew Knepley PetscSectionCreateSupersection - Create a new, larger section composed of the input sections 1871ea844a1aSMatthew Knepley 187240750d41SVaclav Hapla Collective 1873ea844a1aSMatthew Knepley 1874ea844a1aSMatthew Knepley Input Parameters: 1875ea844a1aSMatthew Knepley + s - the input sections 1876ea844a1aSMatthew Knepley - len - the number of input sections 1877ea844a1aSMatthew Knepley 1878ea844a1aSMatthew Knepley Output Parameter: 1879ea844a1aSMatthew Knepley . supers - the supersection 1880ea844a1aSMatthew Knepley 1881ea844a1aSMatthew Knepley Level: advanced 1882ea844a1aSMatthew Knepley 1883cab54364SBarry Smith Note: 1884cab54364SBarry Smith The section offsets now refer to a new, larger vector. 1885cab54364SBarry Smith 1886cab54364SBarry Smith Developer Note: 1887cab54364SBarry Smith Needs to explain how the sections are composed 1888cab54364SBarry Smith 1889cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreateSubsection()`, `PetscSectionCreate()` 1890ea844a1aSMatthew Knepley @*/ 1891d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateSupersection(PetscSection s[], PetscInt len, PetscSection *supers) 1892d71ae5a4SJacob Faibussowitsch { 1893ea844a1aSMatthew Knepley PetscInt Nf = 0, f, pStart = PETSC_MAX_INT, pEnd = 0, p, maxCdof = 0, i; 1894ea844a1aSMatthew Knepley 1895ea844a1aSMatthew Knepley PetscFunctionBegin; 1896ea844a1aSMatthew Knepley if (!len) PetscFunctionReturn(0); 1897ea844a1aSMatthew Knepley for (i = 0; i < len; ++i) { 1898ea844a1aSMatthew Knepley PetscInt nf, pStarti, pEndi; 1899ea844a1aSMatthew Knepley 19009566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s[i], &nf)); 19019566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s[i], &pStarti, &pEndi)); 1902ea844a1aSMatthew Knepley pStart = PetscMin(pStart, pStarti); 1903ea844a1aSMatthew Knepley pEnd = PetscMax(pEnd, pEndi); 1904ea844a1aSMatthew Knepley Nf += nf; 1905ea844a1aSMatthew Knepley } 19069566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s[0]), supers)); 19079566063dSJacob Faibussowitsch PetscCall(PetscSectionSetNumFields(*supers, Nf)); 1908ea844a1aSMatthew Knepley for (i = 0, f = 0; i < len; ++i) { 1909b778fa18SValeria Barra PetscInt nf, fi, ci; 1910ea844a1aSMatthew Knepley 19119566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s[i], &nf)); 1912ea844a1aSMatthew Knepley for (fi = 0; fi < nf; ++fi, ++f) { 1913ea844a1aSMatthew Knepley const char *name = NULL; 1914ea844a1aSMatthew Knepley PetscInt numComp = 0; 1915ea844a1aSMatthew Knepley 19169566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldName(s[i], fi, &name)); 19179566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldName(*supers, f, name)); 19189566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s[i], fi, &numComp)); 19199566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(*supers, f, numComp)); 1920b778fa18SValeria Barra for (ci = 0; ci < s[i]->numFieldComponents[fi]; ++ci) { 19219566063dSJacob Faibussowitsch PetscCall(PetscSectionGetComponentName(s[i], fi, ci, &name)); 19229566063dSJacob Faibussowitsch PetscCall(PetscSectionSetComponentName(*supers, f, ci, name)); 1923b778fa18SValeria Barra } 1924ea844a1aSMatthew Knepley } 1925ea844a1aSMatthew Knepley } 19269566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(*supers, pStart, pEnd)); 1927ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1928ea844a1aSMatthew Knepley PetscInt dof = 0, cdof = 0; 1929ea844a1aSMatthew Knepley 1930ea844a1aSMatthew Knepley for (i = 0, f = 0; i < len; ++i) { 1931ea844a1aSMatthew Knepley PetscInt nf, fi, pStarti, pEndi; 1932ea844a1aSMatthew Knepley PetscInt fdof = 0, cfdof = 0; 1933ea844a1aSMatthew Knepley 19349566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s[i], &nf)); 19359566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s[i], &pStarti, &pEndi)); 1936ea844a1aSMatthew Knepley if ((p < pStarti) || (p >= pEndi)) continue; 1937ea844a1aSMatthew Knepley for (fi = 0; fi < nf; ++fi, ++f) { 19389566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s[i], p, fi, &fdof)); 19399566063dSJacob Faibussowitsch PetscCall(PetscSectionAddFieldDof(*supers, p, f, fdof)); 19409566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s[i], p, fi, &cfdof)); 19419566063dSJacob Faibussowitsch if (cfdof) PetscCall(PetscSectionAddFieldConstraintDof(*supers, p, f, cfdof)); 1942ea844a1aSMatthew Knepley dof += fdof; 1943ea844a1aSMatthew Knepley cdof += cfdof; 1944ea844a1aSMatthew Knepley } 1945ea844a1aSMatthew Knepley } 19469566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(*supers, p, dof)); 19479566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetConstraintDof(*supers, p, cdof)); 1948ea844a1aSMatthew Knepley maxCdof = PetscMax(cdof, maxCdof); 1949ea844a1aSMatthew Knepley } 19509566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(*supers)); 1951ea844a1aSMatthew Knepley if (maxCdof) { 1952ea844a1aSMatthew Knepley PetscInt *indices; 1953ea844a1aSMatthew Knepley 19549566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(maxCdof, &indices)); 1955ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1956ea844a1aSMatthew Knepley PetscInt cdof; 1957ea844a1aSMatthew Knepley 19589566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(*supers, p, &cdof)); 1959ea844a1aSMatthew Knepley if (cdof) { 1960ea844a1aSMatthew Knepley PetscInt dof, numConst = 0, fOff = 0; 1961ea844a1aSMatthew Knepley 1962ea844a1aSMatthew Knepley for (i = 0, f = 0; i < len; ++i) { 1963ea844a1aSMatthew Knepley const PetscInt *oldIndices = NULL; 1964ea844a1aSMatthew Knepley PetscInt nf, fi, pStarti, pEndi, fdof, cfdof, fc; 1965ea844a1aSMatthew Knepley 19669566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s[i], &nf)); 19679566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s[i], &pStarti, &pEndi)); 1968ea844a1aSMatthew Knepley if ((p < pStarti) || (p >= pEndi)) continue; 1969ea844a1aSMatthew Knepley for (fi = 0; fi < nf; ++fi, ++f) { 19709566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s[i], p, fi, &fdof)); 19719566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s[i], p, fi, &cfdof)); 19729566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(s[i], p, fi, &oldIndices)); 1973fcd2503dSMatthew G. Knepley for (fc = 0; fc < cfdof; ++fc) indices[numConst + fc] = oldIndices[fc]; 19749566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldConstraintIndices(*supers, p, f, &indices[numConst])); 1975fcd2503dSMatthew G. Knepley for (fc = 0; fc < cfdof; ++fc) indices[numConst + fc] += fOff; 1976ea844a1aSMatthew Knepley numConst += cfdof; 1977ea844a1aSMatthew Knepley } 19789566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s[i], p, &dof)); 1979ea844a1aSMatthew Knepley fOff += dof; 1980ea844a1aSMatthew Knepley } 19819566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(*supers, p, indices)); 1982ea844a1aSMatthew Knepley } 1983ea844a1aSMatthew Knepley } 19849566063dSJacob Faibussowitsch PetscCall(PetscFree(indices)); 1985ea844a1aSMatthew Knepley } 1986ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1987ea844a1aSMatthew Knepley } 1988ea844a1aSMatthew Knepley 1989d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateSubplexSection_Internal(PetscSection s, IS subpointMap, PetscBool renumberPoints, PetscSection *subs) 1990d71ae5a4SJacob Faibussowitsch { 1991ea844a1aSMatthew Knepley const PetscInt *points = NULL, *indices = NULL; 199241f23ed0SMatthew G. Knepley PetscInt numFields, f, c, numSubpoints = 0, pStart, pEnd, p, spStart, spEnd, subp; 1993ea844a1aSMatthew Knepley 1994ea844a1aSMatthew Knepley PetscFunctionBegin; 1995ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1996ea844a1aSMatthew Knepley PetscValidHeaderSpecific(subpointMap, IS_CLASSID, 2); 199741f23ed0SMatthew G. Knepley PetscValidPointer(subs, 4); 19989566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s, &numFields)); 19999566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), subs)); 20009566063dSJacob Faibussowitsch if (numFields) PetscCall(PetscSectionSetNumFields(*subs, numFields)); 2001ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 2002ea844a1aSMatthew Knepley const char *name = NULL; 2003ea844a1aSMatthew Knepley PetscInt numComp = 0; 2004ea844a1aSMatthew Knepley 20059566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldName(s, f, &name)); 20069566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldName(*subs, f, name)); 20079566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s, f, &numComp)); 20089566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(*subs, f, numComp)); 2009b778fa18SValeria Barra for (c = 0; c < s->numFieldComponents[f]; ++c) { 20109566063dSJacob Faibussowitsch PetscCall(PetscSectionGetComponentName(s, f, c, &name)); 20119566063dSJacob Faibussowitsch PetscCall(PetscSectionSetComponentName(*subs, f, c, name)); 2012b778fa18SValeria Barra } 2013ea844a1aSMatthew Knepley } 2014ea844a1aSMatthew Knepley /* For right now, we do not try to squeeze the subchart */ 2015ea844a1aSMatthew Knepley if (subpointMap) { 20169566063dSJacob Faibussowitsch PetscCall(ISGetSize(subpointMap, &numSubpoints)); 20179566063dSJacob Faibussowitsch PetscCall(ISGetIndices(subpointMap, &points)); 2018ea844a1aSMatthew Knepley } 20199566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 202041f23ed0SMatthew G. Knepley if (renumberPoints) { 202141f23ed0SMatthew G. Knepley spStart = 0; 202241f23ed0SMatthew G. Knepley spEnd = numSubpoints; 202341f23ed0SMatthew G. Knepley } else { 202441f23ed0SMatthew G. Knepley PetscCall(ISGetMinMax(subpointMap, &spStart, &spEnd)); 202541f23ed0SMatthew G. Knepley ++spEnd; 202641f23ed0SMatthew G. Knepley } 202741f23ed0SMatthew G. Knepley PetscCall(PetscSectionSetChart(*subs, spStart, spEnd)); 2028ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2029ea844a1aSMatthew Knepley PetscInt dof, cdof, fdof = 0, cfdof = 0; 2030ea844a1aSMatthew Knepley 20319566063dSJacob Faibussowitsch PetscCall(PetscFindInt(p, numSubpoints, points, &subp)); 2032ea844a1aSMatthew Knepley if (subp < 0) continue; 203341f23ed0SMatthew G. Knepley if (!renumberPoints) subp = p; 2034ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 20359566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, f, &fdof)); 20369566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldDof(*subs, subp, f, fdof)); 20379566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, f, &cfdof)); 20389566063dSJacob Faibussowitsch if (cfdof) PetscCall(PetscSectionSetFieldConstraintDof(*subs, subp, f, cfdof)); 2039ea844a1aSMatthew Knepley } 20409566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 20419566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(*subs, subp, dof)); 20429566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof)); 20439566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetConstraintDof(*subs, subp, cdof)); 2044ea844a1aSMatthew Knepley } 20459566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(*subs)); 2046ea844a1aSMatthew Knepley /* Change offsets to original offsets */ 2047ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2048ea844a1aSMatthew Knepley PetscInt off, foff = 0; 2049ea844a1aSMatthew Knepley 20509566063dSJacob Faibussowitsch PetscCall(PetscFindInt(p, numSubpoints, points, &subp)); 2051ea844a1aSMatthew Knepley if (subp < 0) continue; 205241f23ed0SMatthew G. Knepley if (!renumberPoints) subp = p; 2053ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 20549566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldOffset(s, p, f, &foff)); 20559566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldOffset(*subs, subp, f, foff)); 2056ea844a1aSMatthew Knepley } 20579566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s, p, &off)); 20589566063dSJacob Faibussowitsch PetscCall(PetscSectionSetOffset(*subs, subp, off)); 2059ea844a1aSMatthew Knepley } 2060ea844a1aSMatthew Knepley /* Copy constraint indices */ 206141f23ed0SMatthew G. Knepley for (subp = spStart; subp < spEnd; ++subp) { 2062ea844a1aSMatthew Knepley PetscInt cdof; 2063ea844a1aSMatthew Knepley 20649566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(*subs, subp, &cdof)); 2065ea844a1aSMatthew Knepley if (cdof) { 2066ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 206741f23ed0SMatthew G. Knepley PetscCall(PetscSectionGetFieldConstraintIndices(s, points[subp - spStart], f, &indices)); 20689566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldConstraintIndices(*subs, subp, f, indices)); 2069ea844a1aSMatthew Knepley } 207041f23ed0SMatthew G. Knepley PetscCall(PetscSectionGetConstraintIndices(s, points[subp - spStart], &indices)); 20719566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(*subs, subp, indices)); 2072ea844a1aSMatthew Knepley } 2073ea844a1aSMatthew Knepley } 20749566063dSJacob Faibussowitsch if (subpointMap) PetscCall(ISRestoreIndices(subpointMap, &points)); 2075ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2076ea844a1aSMatthew Knepley } 2077ea844a1aSMatthew Knepley 207841f23ed0SMatthew G. Knepley /*@ 207941f23ed0SMatthew G. Knepley PetscSectionCreateSubmeshSection - Create a new, smaller section with support on the submesh 208041f23ed0SMatthew G. Knepley 2081c3339decSBarry Smith Collective 208241f23ed0SMatthew G. Knepley 208341f23ed0SMatthew G. Knepley Input Parameters: 2084cab54364SBarry Smith + s - the `PetscSection` 208541f23ed0SMatthew G. Knepley - subpointMap - a sorted list of points in the original mesh which are in the submesh 208641f23ed0SMatthew G. Knepley 208741f23ed0SMatthew G. Knepley Output Parameter: 208841f23ed0SMatthew G. Knepley . subs - the subsection 208941f23ed0SMatthew G. Knepley 2090cab54364SBarry Smith Level: advanced 2091cab54364SBarry Smith 209241f23ed0SMatthew G. Knepley Note: 209341f23ed0SMatthew G. Knepley The points are renumbered from 0, and the section offsets now refer to a new, smaller vector. 209441f23ed0SMatthew G. Knepley 2095cab54364SBarry Smith Developer Note: 2096cab54364SBarry Smith The use of the term Submesh is confusing and unneeded 209741f23ed0SMatthew G. Knepley 2098cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreateSubdomainSection()`, `PetscSectionCreateSubsection()`, `DMPlexGetSubpointMap()`, `PetscSectionCreate()` 209941f23ed0SMatthew G. Knepley @*/ 2100d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateSubmeshSection(PetscSection s, IS subpointMap, PetscSection *subs) 2101d71ae5a4SJacob Faibussowitsch { 210241f23ed0SMatthew G. Knepley PetscFunctionBegin; 210341f23ed0SMatthew G. Knepley PetscCall(PetscSectionCreateSubplexSection_Internal(s, subpointMap, PETSC_TRUE, subs)); 210441f23ed0SMatthew G. Knepley PetscFunctionReturn(0); 210541f23ed0SMatthew G. Knepley } 210641f23ed0SMatthew G. Knepley 210741f23ed0SMatthew G. Knepley /*@ 210841f23ed0SMatthew G. Knepley PetscSectionCreateSubdomainSection - Create a new, smaller section with support on a subdomain of the mesh 210941f23ed0SMatthew G. Knepley 2110c3339decSBarry Smith Collective 211141f23ed0SMatthew G. Knepley 211241f23ed0SMatthew G. Knepley Input Parameters: 2113cab54364SBarry Smith + s - the `PetscSection` 211441f23ed0SMatthew G. Knepley - subpointMap - a sorted list of points in the original mesh which are in the subdomain 211541f23ed0SMatthew G. Knepley 211641f23ed0SMatthew G. Knepley Output Parameter: 211741f23ed0SMatthew G. Knepley . subs - the subsection 211841f23ed0SMatthew G. Knepley 2119cab54364SBarry Smith Level: advanced 2120cab54364SBarry Smith 212141f23ed0SMatthew G. Knepley Note: 212241f23ed0SMatthew G. Knepley The point numbers remain the same, but the section offsets now refer to a new, smaller vector. 212341f23ed0SMatthew G. Knepley 2124cab54364SBarry Smith Developer Notes: 2125cab54364SBarry Smith It is unclear what the difference with `PetscSectionCreateSubmeshSection()` is. 212641f23ed0SMatthew G. Knepley 2127cab54364SBarry Smith The use of the term Subdomain is unneeded and confusing 2128cab54364SBarry Smith 2129cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreateSubmeshSection()`, `PetscSectionCreateSubsection()`, `DMPlexGetSubpointMap()`, `PetscSectionCreate()` 213041f23ed0SMatthew G. Knepley @*/ 2131d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateSubdomainSection(PetscSection s, IS subpointMap, PetscSection *subs) 2132d71ae5a4SJacob Faibussowitsch { 213341f23ed0SMatthew G. Knepley PetscFunctionBegin; 213441f23ed0SMatthew G. Knepley PetscCall(PetscSectionCreateSubplexSection_Internal(s, subpointMap, PETSC_FALSE, subs)); 213541f23ed0SMatthew G. Knepley PetscFunctionReturn(0); 213641f23ed0SMatthew G. Knepley } 213741f23ed0SMatthew G. Knepley 2138d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscSectionView_ASCII(PetscSection s, PetscViewer viewer) 2139d71ae5a4SJacob Faibussowitsch { 2140ea844a1aSMatthew Knepley PetscInt p; 2141ea844a1aSMatthew Knepley PetscMPIInt rank; 2142ea844a1aSMatthew Knepley 2143ea844a1aSMatthew Knepley PetscFunctionBegin; 21449566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_rank(PetscObjectComm((PetscObject)viewer), &rank)); 21459566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushSynchronized(viewer)); 21469566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "Process %d:\n", rank)); 2147ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) { 2148ea844a1aSMatthew Knepley if ((s->bc) && (s->bc->atlasDof[p] > 0)) { 2149ea844a1aSMatthew Knepley PetscInt b; 2150ea844a1aSMatthew Knepley 21519566063dSJacob 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])); 2152083401c6SMatthew G. Knepley if (s->bcIndices) { 215348a46eb9SPierre Jolivet for (b = 0; b < s->bc->atlasDof[p]; ++b) PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " %" PetscInt_FMT, s->bcIndices[s->bc->atlasOff[p] + b])); 2154083401c6SMatthew G. Knepley } 21559566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "\n")); 2156ea844a1aSMatthew Knepley } else { 21579566063dSJacob 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])); 2158ea844a1aSMatthew Knepley } 2159ea844a1aSMatthew Knepley } 21609566063dSJacob Faibussowitsch PetscCall(PetscViewerFlush(viewer)); 21619566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPopSynchronized(viewer)); 2162ea844a1aSMatthew Knepley if (s->sym) { 21639566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushTab(viewer)); 21649566063dSJacob Faibussowitsch PetscCall(PetscSectionSymView(s->sym, viewer)); 21659566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPopTab(viewer)); 2166ea844a1aSMatthew Knepley } 2167ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2168ea844a1aSMatthew Knepley } 2169ea844a1aSMatthew Knepley 2170ea844a1aSMatthew Knepley /*@C 2171cab54364SBarry Smith PetscSectionViewFromOptions - View the `PetscSection` based on values in the options database 2172fe2efc57SMark 217340750d41SVaclav Hapla Collective 2174fe2efc57SMark 2175fe2efc57SMark Input Parameters: 2176fe2efc57SMark + A - the PetscSection object to view 2177cab54364SBarry Smith . obj - Optional object that provides the options prefix used for the options 2178736c3998SJose E. Roman - name - command line option 2179fe2efc57SMark 2180fe2efc57SMark Level: intermediate 2181cab54364SBarry Smith 2182cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionView`, `PetscObjectViewFromOptions()`, `PetscSectionCreate()`, `PetscSectionView()` 2183fe2efc57SMark @*/ 2184d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionViewFromOptions(PetscSection A, PetscObject obj, const char name[]) 2185d71ae5a4SJacob Faibussowitsch { 2186fe2efc57SMark PetscFunctionBegin; 2187fe2efc57SMark PetscValidHeaderSpecific(A, PETSC_SECTION_CLASSID, 1); 21889566063dSJacob Faibussowitsch PetscCall(PetscObjectViewFromOptions((PetscObject)A, obj, name)); 2189fe2efc57SMark PetscFunctionReturn(0); 2190fe2efc57SMark } 2191fe2efc57SMark 2192fe2efc57SMark /*@C 2193cab54364SBarry Smith PetscSectionView - Views a `PetscSection` 2194ea844a1aSMatthew Knepley 219540750d41SVaclav Hapla Collective 2196ea844a1aSMatthew Knepley 2197ea844a1aSMatthew Knepley Input Parameters: 2198cab54364SBarry Smith + s - the `PetscSection` object to view 2199ea844a1aSMatthew Knepley - v - the viewer 2200ea844a1aSMatthew Knepley 2201cab54364SBarry Smith Level: beginner 2202cab54364SBarry Smith 22031ddd528eSksagiyam Note: 2204cab54364SBarry Smith `PetscSectionView()`, when viewer is of type `PETSCVIEWERHDF5`, only saves 22051ddd528eSksagiyam distribution independent data, such as dofs, offsets, constraint dofs, 22061ddd528eSksagiyam and constraint indices. Points that have negative dofs, for instance, 22071ddd528eSksagiyam are not saved as they represent points owned by other processes. 22081ddd528eSksagiyam Point numbering and rank assignment is currently not stored. 2209cab54364SBarry Smith The saved section can be loaded with `PetscSectionLoad()`. 22101ddd528eSksagiyam 2211cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionDestroy()`, `PetscSectionLoad()`, `PetscViewer` 2212ea844a1aSMatthew Knepley @*/ 2213d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionView(PetscSection s, PetscViewer viewer) 2214d71ae5a4SJacob Faibussowitsch { 22151ddd528eSksagiyam PetscBool isascii, ishdf5; 2216ea844a1aSMatthew Knepley PetscInt f; 2217ea844a1aSMatthew Knepley 2218ea844a1aSMatthew Knepley PetscFunctionBegin; 2219ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 22209566063dSJacob Faibussowitsch if (!viewer) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)s), &viewer)); 2221ea844a1aSMatthew Knepley PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2); 22229566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii)); 22239566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERHDF5, &ishdf5)); 2224ea844a1aSMatthew Knepley if (isascii) { 22259566063dSJacob Faibussowitsch PetscCall(PetscObjectPrintClassNamePrefixType((PetscObject)s, viewer)); 2226ea844a1aSMatthew Knepley if (s->numFields) { 22279566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT " fields\n", s->numFields)); 2228ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) { 22299566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, " field %" PetscInt_FMT " with %" PetscInt_FMT " components\n", f, s->numFieldComponents[f])); 22309566063dSJacob Faibussowitsch PetscCall(PetscSectionView_ASCII(s->field[f], viewer)); 2231ea844a1aSMatthew Knepley } 2232ea844a1aSMatthew Knepley } else { 22339566063dSJacob Faibussowitsch PetscCall(PetscSectionView_ASCII(s, viewer)); 2234ea844a1aSMatthew Knepley } 22351ddd528eSksagiyam } else if (ishdf5) { 22361ddd528eSksagiyam #if PetscDefined(HAVE_HDF5) 22379566063dSJacob Faibussowitsch PetscCall(PetscSectionView_HDF5_Internal(s, viewer)); 22381ddd528eSksagiyam #else 22391ddd528eSksagiyam SETERRQ(PetscObjectComm((PetscObject)s), PETSC_ERR_SUP, "HDF5 not supported in this build.\nPlease reconfigure using --download-hdf5"); 22401ddd528eSksagiyam #endif 2241ea844a1aSMatthew Knepley } 2242ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2243ea844a1aSMatthew Knepley } 2244ea844a1aSMatthew Knepley 2245fde5e3acSksagiyam /*@C 2246cab54364SBarry Smith PetscSectionLoad - Loads a `PetscSection` 2247fde5e3acSksagiyam 224840750d41SVaclav Hapla Collective 2249fde5e3acSksagiyam 2250fde5e3acSksagiyam Input Parameters: 2251cab54364SBarry Smith + s - the `PetscSection` object to load 2252fde5e3acSksagiyam - v - the viewer 2253fde5e3acSksagiyam 2254cab54364SBarry Smith Level: beginner 2255cab54364SBarry Smith 2256fde5e3acSksagiyam Note: 2257cab54364SBarry Smith `PetscSectionLoad()`, when viewer is of type `PETSCVIEWERHDF5`, loads 2258cab54364SBarry Smith a section saved with `PetscSectionView()`. The number of processes 2259fde5e3acSksagiyam used here (N) does not need to be the same as that used when saving. 2260fde5e3acSksagiyam After calling this function, the chart of s on rank i will be set 2261fde5e3acSksagiyam to [0, E_i), where \sum_{i=0}^{N-1}E_i equals to the total number of 2262fde5e3acSksagiyam saved section points. 2263fde5e3acSksagiyam 2264cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionDestroy()`, `PetscSectionView()` 2265fde5e3acSksagiyam @*/ 2266d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionLoad(PetscSection s, PetscViewer viewer) 2267d71ae5a4SJacob Faibussowitsch { 2268fde5e3acSksagiyam PetscBool ishdf5; 2269fde5e3acSksagiyam 2270fde5e3acSksagiyam PetscFunctionBegin; 2271fde5e3acSksagiyam PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2272fde5e3acSksagiyam PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2); 22739566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERHDF5, &ishdf5)); 2274fde5e3acSksagiyam if (ishdf5) { 2275fde5e3acSksagiyam #if PetscDefined(HAVE_HDF5) 22769566063dSJacob Faibussowitsch PetscCall(PetscSectionLoad_HDF5_Internal(s, viewer)); 2277fde5e3acSksagiyam PetscFunctionReturn(0); 2278fde5e3acSksagiyam #else 2279fde5e3acSksagiyam SETERRQ(PetscObjectComm((PetscObject)s), PETSC_ERR_SUP, "HDF5 not supported in this build.\nPlease reconfigure using --download-hdf5"); 2280fde5e3acSksagiyam #endif 228198921bdaSJacob Faibussowitsch } else SETERRQ(PetscObjectComm((PetscObject)s), PETSC_ERR_SUP, "Viewer type %s not yet supported for PetscSection loading", ((PetscObject)viewer)->type_name); 2282fde5e3acSksagiyam } 2283fde5e3acSksagiyam 2284d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscSectionResetClosurePermutation(PetscSection section) 2285d71ae5a4SJacob Faibussowitsch { 2286c459fbc1SJed Brown PetscSectionClosurePermVal clVal; 2287c459fbc1SJed Brown 2288c459fbc1SJed Brown PetscFunctionBegin; 2289c459fbc1SJed Brown if (!section->clHash) PetscFunctionReturn(0); 2290c459fbc1SJed Brown kh_foreach_value(section->clHash, clVal, { 22919566063dSJacob Faibussowitsch PetscCall(PetscFree(clVal.perm)); 22929566063dSJacob Faibussowitsch PetscCall(PetscFree(clVal.invPerm)); 2293c459fbc1SJed Brown }); 2294c459fbc1SJed Brown kh_destroy(ClPerm, section->clHash); 2295c459fbc1SJed Brown section->clHash = NULL; 2296c459fbc1SJed Brown PetscFunctionReturn(0); 2297c459fbc1SJed Brown } 2298c459fbc1SJed Brown 2299ea844a1aSMatthew Knepley /*@ 2300ea844a1aSMatthew Knepley PetscSectionReset - Frees all section data. 2301ea844a1aSMatthew Knepley 230240750d41SVaclav Hapla Not Collective 2303ea844a1aSMatthew Knepley 2304ea844a1aSMatthew Knepley Input Parameters: 2305cab54364SBarry Smith . s - the `PetscSection` 2306ea844a1aSMatthew Knepley 2307ea844a1aSMatthew Knepley Level: beginner 2308ea844a1aSMatthew Knepley 2309cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()` 2310ea844a1aSMatthew Knepley @*/ 2311d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionReset(PetscSection s) 2312d71ae5a4SJacob Faibussowitsch { 2313b778fa18SValeria Barra PetscInt f, c; 2314ea844a1aSMatthew Knepley 2315ea844a1aSMatthew Knepley PetscFunctionBegin; 2316ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2317ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) { 23189566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->field[f])); 23199566063dSJacob Faibussowitsch PetscCall(PetscFree(s->fieldNames[f])); 232048a46eb9SPierre Jolivet for (c = 0; c < s->numFieldComponents[f]; ++c) PetscCall(PetscFree(s->compNames[f][c])); 23219566063dSJacob Faibussowitsch PetscCall(PetscFree(s->compNames[f])); 2322ea844a1aSMatthew Knepley } 23239566063dSJacob Faibussowitsch PetscCall(PetscFree(s->numFieldComponents)); 23249566063dSJacob Faibussowitsch PetscCall(PetscFree(s->fieldNames)); 23259566063dSJacob Faibussowitsch PetscCall(PetscFree(s->compNames)); 23269566063dSJacob Faibussowitsch PetscCall(PetscFree(s->field)); 23279566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->bc)); 23289566063dSJacob Faibussowitsch PetscCall(PetscFree(s->bcIndices)); 23299566063dSJacob Faibussowitsch PetscCall(PetscFree2(s->atlasDof, s->atlasOff)); 23309566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->clSection)); 23319566063dSJacob Faibussowitsch PetscCall(ISDestroy(&s->clPoints)); 23329566063dSJacob Faibussowitsch PetscCall(ISDestroy(&s->perm)); 23339566063dSJacob Faibussowitsch PetscCall(PetscSectionResetClosurePermutation(s)); 23349566063dSJacob Faibussowitsch PetscCall(PetscSectionSymDestroy(&s->sym)); 23359566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->clSection)); 23369566063dSJacob Faibussowitsch PetscCall(ISDestroy(&s->clPoints)); 233769c11d05SVaclav Hapla PetscCall(PetscSectionInvalidateMaxDof_Internal(s)); 2338ea844a1aSMatthew Knepley s->pStart = -1; 2339ea844a1aSMatthew Knepley s->pEnd = -1; 2340ea844a1aSMatthew Knepley s->maxDof = 0; 2341ea844a1aSMatthew Knepley s->setup = PETSC_FALSE; 2342ea844a1aSMatthew Knepley s->numFields = 0; 2343ea844a1aSMatthew Knepley s->clObj = NULL; 2344ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2345ea844a1aSMatthew Knepley } 2346ea844a1aSMatthew Knepley 2347ea844a1aSMatthew Knepley /*@ 2348ea844a1aSMatthew Knepley PetscSectionDestroy - Frees a section object and frees its range if that exists. 2349ea844a1aSMatthew Knepley 235040750d41SVaclav Hapla Not Collective 2351ea844a1aSMatthew Knepley 2352ea844a1aSMatthew Knepley Input Parameters: 2353cab54364SBarry Smith . s - the `PetscSection` 2354ea844a1aSMatthew Knepley 2355ea844a1aSMatthew Knepley Level: beginner 2356ea844a1aSMatthew Knepley 2357cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionReset()` 2358ea844a1aSMatthew Knepley @*/ 2359d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionDestroy(PetscSection *s) 2360d71ae5a4SJacob Faibussowitsch { 2361ea844a1aSMatthew Knepley PetscFunctionBegin; 2362ea844a1aSMatthew Knepley if (!*s) PetscFunctionReturn(0); 236362f17a49SStefano Zampini PetscValidHeaderSpecific(*s, PETSC_SECTION_CLASSID, 1); 2364ea844a1aSMatthew Knepley if (--((PetscObject)(*s))->refct > 0) { 2365ea844a1aSMatthew Knepley *s = NULL; 2366ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2367ea844a1aSMatthew Knepley } 23689566063dSJacob Faibussowitsch PetscCall(PetscSectionReset(*s)); 23699566063dSJacob Faibussowitsch PetscCall(PetscHeaderDestroy(s)); 2370ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2371ea844a1aSMatthew Knepley } 2372ea844a1aSMatthew Knepley 2373d71ae5a4SJacob Faibussowitsch PetscErrorCode VecIntGetValuesSection(PetscInt *baseArray, PetscSection s, PetscInt point, const PetscInt **values) 2374d71ae5a4SJacob Faibussowitsch { 2375ea844a1aSMatthew Knepley const PetscInt p = point - s->pStart; 2376ea844a1aSMatthew Knepley 2377ea844a1aSMatthew Knepley PetscFunctionBegin; 2378ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 2); 2379ea844a1aSMatthew Knepley *values = &baseArray[s->atlasOff[p]]; 2380ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2381ea844a1aSMatthew Knepley } 2382ea844a1aSMatthew Knepley 2383d71ae5a4SJacob Faibussowitsch PetscErrorCode VecIntSetValuesSection(PetscInt *baseArray, PetscSection s, PetscInt point, const PetscInt values[], InsertMode mode) 2384d71ae5a4SJacob Faibussowitsch { 2385ea844a1aSMatthew Knepley PetscInt *array; 2386ea844a1aSMatthew Knepley const PetscInt p = point - s->pStart; 2387ea844a1aSMatthew Knepley const PetscInt orientation = 0; /* Needs to be included for use in closure operations */ 2388ea844a1aSMatthew Knepley PetscInt cDim = 0; 2389ea844a1aSMatthew Knepley 2390ea844a1aSMatthew Knepley PetscFunctionBegin; 2391ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 2); 23929566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cDim)); 2393ea844a1aSMatthew Knepley array = &baseArray[s->atlasOff[p]]; 2394ea844a1aSMatthew Knepley if (!cDim) { 2395ea844a1aSMatthew Knepley if (orientation >= 0) { 2396ea844a1aSMatthew Knepley const PetscInt dim = s->atlasDof[p]; 2397ea844a1aSMatthew Knepley PetscInt i; 2398ea844a1aSMatthew Knepley 2399ea844a1aSMatthew Knepley if (mode == INSERT_VALUES) { 2400ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) array[i] = values[i]; 2401ea844a1aSMatthew Knepley } else { 2402ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) array[i] += values[i]; 2403ea844a1aSMatthew Knepley } 2404ea844a1aSMatthew Knepley } else { 2405ea844a1aSMatthew Knepley PetscInt offset = 0; 2406ea844a1aSMatthew Knepley PetscInt j = -1, field, i; 2407ea844a1aSMatthew Knepley 2408ea844a1aSMatthew Knepley for (field = 0; field < s->numFields; ++field) { 2409ea844a1aSMatthew Knepley const PetscInt dim = s->field[field]->atlasDof[p]; 2410ea844a1aSMatthew Knepley 2411ea844a1aSMatthew Knepley for (i = dim - 1; i >= 0; --i) array[++j] = values[i + offset]; 2412ea844a1aSMatthew Knepley offset += dim; 2413ea844a1aSMatthew Knepley } 2414ea844a1aSMatthew Knepley } 2415ea844a1aSMatthew Knepley } else { 2416ea844a1aSMatthew Knepley if (orientation >= 0) { 2417ea844a1aSMatthew Knepley const PetscInt dim = s->atlasDof[p]; 2418ea844a1aSMatthew Knepley PetscInt cInd = 0, i; 2419ea844a1aSMatthew Knepley const PetscInt *cDof; 2420ea844a1aSMatthew Knepley 24219566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s, point, &cDof)); 2422ea844a1aSMatthew Knepley if (mode == INSERT_VALUES) { 2423ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) { 24249371c9d4SSatish Balay if ((cInd < cDim) && (i == cDof[cInd])) { 24259371c9d4SSatish Balay ++cInd; 24269371c9d4SSatish Balay continue; 24279371c9d4SSatish Balay } 2428ea844a1aSMatthew Knepley array[i] = values[i]; 2429ea844a1aSMatthew Knepley } 2430ea844a1aSMatthew Knepley } else { 2431ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) { 24329371c9d4SSatish Balay if ((cInd < cDim) && (i == cDof[cInd])) { 24339371c9d4SSatish Balay ++cInd; 24349371c9d4SSatish Balay continue; 24359371c9d4SSatish Balay } 2436ea844a1aSMatthew Knepley array[i] += values[i]; 2437ea844a1aSMatthew Knepley } 2438ea844a1aSMatthew Knepley } 2439ea844a1aSMatthew Knepley } else { 2440ea844a1aSMatthew Knepley const PetscInt *cDof; 2441ea844a1aSMatthew Knepley PetscInt offset = 0; 2442ea844a1aSMatthew Knepley PetscInt cOffset = 0; 2443ea844a1aSMatthew Knepley PetscInt j = 0, field; 2444ea844a1aSMatthew Knepley 24459566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s, point, &cDof)); 2446ea844a1aSMatthew Knepley for (field = 0; field < s->numFields; ++field) { 2447ea844a1aSMatthew Knepley const PetscInt dim = s->field[field]->atlasDof[p]; /* PetscSectionGetFieldDof() */ 2448ea844a1aSMatthew Knepley const PetscInt tDim = s->field[field]->bc->atlasDof[p]; /* PetscSectionGetFieldConstraintDof() */ 2449ea844a1aSMatthew Knepley const PetscInt sDim = dim - tDim; 2450ea844a1aSMatthew Knepley PetscInt cInd = 0, i, k; 2451ea844a1aSMatthew Knepley 2452ea844a1aSMatthew Knepley for (i = 0, k = dim + offset - 1; i < dim; ++i, ++j, --k) { 24539371c9d4SSatish Balay if ((cInd < sDim) && (j == cDof[cInd + cOffset])) { 24549371c9d4SSatish Balay ++cInd; 24559371c9d4SSatish Balay continue; 24569371c9d4SSatish Balay } 2457ea844a1aSMatthew Knepley array[j] = values[k]; 2458ea844a1aSMatthew Knepley } 2459ea844a1aSMatthew Knepley offset += dim; 2460ea844a1aSMatthew Knepley cOffset += dim - tDim; 2461ea844a1aSMatthew Knepley } 2462ea844a1aSMatthew Knepley } 2463ea844a1aSMatthew Knepley } 2464ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2465ea844a1aSMatthew Knepley } 2466ea844a1aSMatthew Knepley 2467ea844a1aSMatthew Knepley /*@C 2468ea844a1aSMatthew Knepley PetscSectionHasConstraints - Determine whether a section has constrained dofs 2469ea844a1aSMatthew Knepley 247040750d41SVaclav Hapla Not Collective 2471ea844a1aSMatthew Knepley 2472ea844a1aSMatthew Knepley Input Parameter: 2473cab54364SBarry Smith . s - The `PetscSection` 2474ea844a1aSMatthew Knepley 2475ea844a1aSMatthew Knepley Output Parameter: 2476ea844a1aSMatthew Knepley . hasConstraints - flag indicating that the section has constrained dofs 2477ea844a1aSMatthew Knepley 2478ea844a1aSMatthew Knepley Level: intermediate 2479ea844a1aSMatthew Knepley 2480cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSetConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection` 2481ea844a1aSMatthew Knepley @*/ 2482d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionHasConstraints(PetscSection s, PetscBool *hasConstraints) 2483d71ae5a4SJacob Faibussowitsch { 2484ea844a1aSMatthew Knepley PetscFunctionBegin; 2485ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2486dadcf809SJacob Faibussowitsch PetscValidBoolPointer(hasConstraints, 2); 2487ea844a1aSMatthew Knepley *hasConstraints = s->bc ? PETSC_TRUE : PETSC_FALSE; 2488ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2489ea844a1aSMatthew Knepley } 2490ea844a1aSMatthew Knepley 2491ea844a1aSMatthew Knepley /*@C 2492ea844a1aSMatthew Knepley PetscSectionGetConstraintIndices - Get the point dof numbers, in [0, dof), which are constrained 2493ea844a1aSMatthew Knepley 249440750d41SVaclav Hapla Not Collective 2495ea844a1aSMatthew Knepley 2496ea844a1aSMatthew Knepley Input Parameters: 2497cab54364SBarry Smith + s - The `PetscSection` 2498ea844a1aSMatthew Knepley - point - The point 2499ea844a1aSMatthew Knepley 2500ea844a1aSMatthew Knepley Output Parameter: 2501ea844a1aSMatthew Knepley . indices - The constrained dofs 2502ea844a1aSMatthew Knepley 2503ea844a1aSMatthew Knepley Level: intermediate 2504ea844a1aSMatthew Knepley 2505cab54364SBarry Smith Fortran Note: 2506cab54364SBarry Smith Call `PetscSectionGetConstraintIndicesF90()` and `PetscSectionRestoreConstraintIndicesF90()` 2507cab54364SBarry Smith 2508cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSetConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection` 2509ea844a1aSMatthew Knepley @*/ 2510d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetConstraintIndices(PetscSection s, PetscInt point, const PetscInt **indices) 2511d71ae5a4SJacob Faibussowitsch { 2512ea844a1aSMatthew Knepley PetscFunctionBegin; 2513ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2514ea844a1aSMatthew Knepley if (s->bc) { 25159566063dSJacob Faibussowitsch PetscCall(VecIntGetValuesSection(s->bcIndices, s->bc, point, indices)); 2516ea844a1aSMatthew Knepley } else *indices = NULL; 2517ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2518ea844a1aSMatthew Knepley } 2519ea844a1aSMatthew Knepley 2520ea844a1aSMatthew Knepley /*@C 2521ea844a1aSMatthew Knepley PetscSectionSetConstraintIndices - Set the point dof numbers, in [0, dof), which are constrained 2522ea844a1aSMatthew Knepley 252340750d41SVaclav Hapla Not Collective 2524ea844a1aSMatthew Knepley 2525ea844a1aSMatthew Knepley Input Parameters: 2526cab54364SBarry Smith + s - The `PetscSection` 2527ea844a1aSMatthew Knepley . point - The point 2528ea844a1aSMatthew Knepley - indices - The constrained dofs 2529ea844a1aSMatthew Knepley 2530ea844a1aSMatthew Knepley Level: intermediate 2531ea844a1aSMatthew Knepley 2532cab54364SBarry Smith Fortran Note: 2533cab54364SBarry Smith Use `PetscSectionSetConstraintIndicesF90()` 2534cab54364SBarry Smith 2535cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionGetConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection` 2536ea844a1aSMatthew Knepley @*/ 2537d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetConstraintIndices(PetscSection s, PetscInt point, const PetscInt indices[]) 2538d71ae5a4SJacob Faibussowitsch { 2539ea844a1aSMatthew Knepley PetscFunctionBegin; 2540ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2541ea844a1aSMatthew Knepley if (s->bc) { 2542d57bb9dbSMatthew G. Knepley const PetscInt dof = s->atlasDof[point]; 2543d57bb9dbSMatthew G. Knepley const PetscInt cdof = s->bc->atlasDof[point]; 2544d57bb9dbSMatthew G. Knepley PetscInt d; 2545d57bb9dbSMatthew G. Knepley 2546ad540459SPierre 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]); 25479566063dSJacob Faibussowitsch PetscCall(VecIntSetValuesSection(s->bcIndices, s->bc, point, indices, INSERT_VALUES)); 2548ea844a1aSMatthew Knepley } 2549ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2550ea844a1aSMatthew Knepley } 2551ea844a1aSMatthew Knepley 2552ea844a1aSMatthew Knepley /*@C 2553ea844a1aSMatthew Knepley PetscSectionGetFieldConstraintIndices - Get the field dof numbers, in [0, fdof), which are constrained 2554ea844a1aSMatthew Knepley 255540750d41SVaclav Hapla Not Collective 2556ea844a1aSMatthew Knepley 2557ea844a1aSMatthew Knepley Input Parameters: 2558cab54364SBarry Smith + s - The `PetscSection` 2559ea844a1aSMatthew Knepley . field - The field number 2560ea844a1aSMatthew Knepley - point - The point 2561ea844a1aSMatthew Knepley 2562ea844a1aSMatthew Knepley Output Parameter: 25639759eb26SJed Brown . indices - The constrained dofs sorted in ascending order 2564ea844a1aSMatthew Knepley 2565ea844a1aSMatthew Knepley Level: intermediate 2566ea844a1aSMatthew Knepley 2567cab54364SBarry Smith Note: 2568cab54364SBarry 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()`. 2569cab54364SBarry Smith 2570cab54364SBarry Smith Fortran Note: 2571cab54364SBarry Smith Call `PetscSectionGetFieldConstraintIndicesF90()` and `PetscSectionRestoreFieldConstraintIndicesF90()` 2572cab54364SBarry Smith 2573cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSetFieldConstraintIndices()`, `PetscSectionGetConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection` 2574ea844a1aSMatthew Knepley @*/ 2575d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldConstraintIndices(PetscSection s, PetscInt point, PetscInt field, const PetscInt **indices) 2576d71ae5a4SJacob Faibussowitsch { 2577ea844a1aSMatthew Knepley PetscFunctionBegin; 2578ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2579dadcf809SJacob Faibussowitsch PetscValidPointer(indices, 4); 25802abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 25819566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s->field[field], point, indices)); 2582ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2583ea844a1aSMatthew Knepley } 2584ea844a1aSMatthew Knepley 2585ea844a1aSMatthew Knepley /*@C 2586ea844a1aSMatthew Knepley PetscSectionSetFieldConstraintIndices - Set the field dof numbers, in [0, fdof), which are constrained 2587ea844a1aSMatthew Knepley 258840750d41SVaclav Hapla Not Collective 2589ea844a1aSMatthew Knepley 2590ea844a1aSMatthew Knepley Input Parameters: 2591cab54364SBarry Smith + s - The `PetscSection` 2592ea844a1aSMatthew Knepley . point - The point 2593ea844a1aSMatthew Knepley . field - The field number 2594ea844a1aSMatthew Knepley - indices - The constrained dofs 2595ea844a1aSMatthew Knepley 2596ea844a1aSMatthew Knepley Level: intermediate 2597ea844a1aSMatthew Knepley 2598cab54364SBarry Smith Fortran Note: 2599cab54364SBarry Smith Use `PetscSectionSetFieldConstraintIndicesF90()` 2600cab54364SBarry Smith 2601cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSetConstraintIndices()`, `PetscSectionGetFieldConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection` 2602ea844a1aSMatthew Knepley @*/ 2603d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldConstraintIndices(PetscSection s, PetscInt point, PetscInt field, const PetscInt indices[]) 2604d71ae5a4SJacob Faibussowitsch { 2605ea844a1aSMatthew Knepley PetscFunctionBegin; 2606ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 26072abc8c78SJacob Faibussowitsch if (PetscDefined(USE_DEBUG)) { 2608e2bfaee7SMatthew G. Knepley PetscInt nfdof; 26092abc8c78SJacob Faibussowitsch 26109566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, point, field, &nfdof)); 2611e2bfaee7SMatthew G. Knepley if (nfdof) PetscValidIntPointer(indices, 4); 26122abc8c78SJacob Faibussowitsch } 26132abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 26149566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(s->field[field], point, indices)); 2615ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2616ea844a1aSMatthew Knepley } 2617ea844a1aSMatthew Knepley 2618ea844a1aSMatthew Knepley /*@ 2619ea844a1aSMatthew Knepley PetscSectionPermute - Reorder the section according to the input point permutation 2620ea844a1aSMatthew Knepley 262140750d41SVaclav Hapla Collective 2622ea844a1aSMatthew Knepley 2623d8d19677SJose E. Roman Input Parameters: 2624cab54364SBarry Smith + section - The `PetscSection` object 2625ea844a1aSMatthew Knepley - perm - The point permutation, old point p becomes new point perm[p] 2626ea844a1aSMatthew Knepley 2627ea844a1aSMatthew Knepley Output Parameter: 2628cab54364SBarry Smith . sectionNew - The permuted `PetscSection` 2629ea844a1aSMatthew Knepley 2630ea844a1aSMatthew Knepley Level: intermediate 2631ea844a1aSMatthew Knepley 2632cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `IS`, `PetscSection`, `MatPermute()` 2633ea844a1aSMatthew Knepley @*/ 2634d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionPermute(PetscSection section, IS permutation, PetscSection *sectionNew) 2635d71ae5a4SJacob Faibussowitsch { 2636ea844a1aSMatthew Knepley PetscSection s = section, sNew; 2637ea844a1aSMatthew Knepley const PetscInt *perm; 2638b778fa18SValeria Barra PetscInt numFields, f, c, numPoints, pStart, pEnd, p; 2639ea844a1aSMatthew Knepley 2640ea844a1aSMatthew Knepley PetscFunctionBegin; 2641ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 2642ea844a1aSMatthew Knepley PetscValidHeaderSpecific(permutation, IS_CLASSID, 2); 2643ea844a1aSMatthew Knepley PetscValidPointer(sectionNew, 3); 26449566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), &sNew)); 26459566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s, &numFields)); 26469566063dSJacob Faibussowitsch if (numFields) PetscCall(PetscSectionSetNumFields(sNew, numFields)); 2647ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 2648ea844a1aSMatthew Knepley const char *name; 2649ea844a1aSMatthew Knepley PetscInt numComp; 2650ea844a1aSMatthew Knepley 26519566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldName(s, f, &name)); 26529566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldName(sNew, f, name)); 26539566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s, f, &numComp)); 26549566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(sNew, f, numComp)); 2655b778fa18SValeria Barra for (c = 0; c < s->numFieldComponents[f]; ++c) { 26569566063dSJacob Faibussowitsch PetscCall(PetscSectionGetComponentName(s, f, c, &name)); 26579566063dSJacob Faibussowitsch PetscCall(PetscSectionSetComponentName(sNew, f, c, name)); 2658b778fa18SValeria Barra } 2659ea844a1aSMatthew Knepley } 26609566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(permutation, &numPoints)); 26619566063dSJacob Faibussowitsch PetscCall(ISGetIndices(permutation, &perm)); 26629566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 26639566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(sNew, pStart, pEnd)); 266408401ef6SPierre 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); 2665ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2666ea844a1aSMatthew Knepley PetscInt dof, cdof; 2667ea844a1aSMatthew Knepley 26689566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 26699566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(sNew, perm[p], dof)); 26709566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof)); 26719566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetConstraintDof(sNew, perm[p], cdof)); 2672ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 26739566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, f, &dof)); 26749566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldDof(sNew, perm[p], f, dof)); 26759566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, f, &cdof)); 26769566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetFieldConstraintDof(sNew, perm[p], f, cdof)); 2677ea844a1aSMatthew Knepley } 2678ea844a1aSMatthew Knepley } 26799566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(sNew)); 2680ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2681ea844a1aSMatthew Knepley const PetscInt *cind; 2682ea844a1aSMatthew Knepley PetscInt cdof; 2683ea844a1aSMatthew Knepley 26849566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof)); 2685ea844a1aSMatthew Knepley if (cdof) { 26869566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s, p, &cind)); 26879566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(sNew, perm[p], cind)); 2688ea844a1aSMatthew Knepley } 2689ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 26909566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, f, &cdof)); 2691ea844a1aSMatthew Knepley if (cdof) { 26929566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(s, p, f, &cind)); 26939566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldConstraintIndices(sNew, perm[p], f, cind)); 2694ea844a1aSMatthew Knepley } 2695ea844a1aSMatthew Knepley } 2696ea844a1aSMatthew Knepley } 26979566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(permutation, &perm)); 2698ea844a1aSMatthew Knepley *sectionNew = sNew; 2699ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2700ea844a1aSMatthew Knepley } 2701ea844a1aSMatthew Knepley 2702ea844a1aSMatthew Knepley /*@ 2703ea844a1aSMatthew Knepley PetscSectionSetClosureIndex - Set a cache of points in the closure of each point in the section 2704ea844a1aSMatthew Knepley 270540750d41SVaclav Hapla Collective 2706ea844a1aSMatthew Knepley 2707ea844a1aSMatthew Knepley Input Parameters: 2708cab54364SBarry Smith + section - The `PetscSection` 2709cab54364SBarry Smith . obj - A `PetscObject` which serves as the key for this index 2710cab54364SBarry Smith . clSection - `PetscSection` giving the size of the closure of each point 2711cab54364SBarry Smith - clPoints - `IS` giving the points in each closure 2712ea844a1aSMatthew Knepley 2713ea844a1aSMatthew Knepley Level: advanced 2714ea844a1aSMatthew Knepley 2715cab54364SBarry Smith Note: 2716cab54364SBarry Smith We compress out closure points with no dofs in this section 2717cab54364SBarry Smith 2718cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionGetClosureIndex()`, `DMPlexCreateClosureIndex()` 2719ea844a1aSMatthew Knepley @*/ 2720d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetClosureIndex(PetscSection section, PetscObject obj, PetscSection clSection, IS clPoints) 2721d71ae5a4SJacob Faibussowitsch { 2722ea844a1aSMatthew Knepley PetscFunctionBegin; 27233e03ebd8SStefano Zampini PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 27243e03ebd8SStefano Zampini PetscValidHeaderSpecific(clSection, PETSC_SECTION_CLASSID, 3); 27253e03ebd8SStefano Zampini PetscValidHeaderSpecific(clPoints, IS_CLASSID, 4); 27269566063dSJacob Faibussowitsch if (section->clObj != obj) PetscCall(PetscSectionResetClosurePermutation(section)); 2727ea844a1aSMatthew Knepley section->clObj = obj; 27289566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)clSection)); 27299566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)clPoints)); 27309566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(§ion->clSection)); 27319566063dSJacob Faibussowitsch PetscCall(ISDestroy(§ion->clPoints)); 2732ea844a1aSMatthew Knepley section->clSection = clSection; 2733ea844a1aSMatthew Knepley section->clPoints = clPoints; 2734ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2735ea844a1aSMatthew Knepley } 2736ea844a1aSMatthew Knepley 2737ea844a1aSMatthew Knepley /*@ 2738cab54364SBarry Smith PetscSectionGetClosureIndex - Get the cache of points in the closure of each point in the section set with `PetscSectionSetClosureIndex()` 2739ea844a1aSMatthew Knepley 274040750d41SVaclav Hapla Collective 2741ea844a1aSMatthew Knepley 2742ea844a1aSMatthew Knepley Input Parameters: 2743cab54364SBarry Smith + section - The `PetscSection` 2744cab54364SBarry Smith - obj - A `PetscObject` which serves as the key for this index 2745ea844a1aSMatthew Knepley 2746ea844a1aSMatthew Knepley Output Parameters: 2747cab54364SBarry Smith + clSection - `PetscSection` giving the size of the closure of each point 2748cab54364SBarry Smith - clPoints - `IS` giving the points in each closure 2749ea844a1aSMatthew Knepley 2750ea844a1aSMatthew Knepley Level: advanced 2751ea844a1aSMatthew Knepley 2752cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSetClosureIndex()`, `DMPlexCreateClosureIndex()` 2753ea844a1aSMatthew Knepley @*/ 2754d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosureIndex(PetscSection section, PetscObject obj, PetscSection *clSection, IS *clPoints) 2755d71ae5a4SJacob Faibussowitsch { 2756ea844a1aSMatthew Knepley PetscFunctionBegin; 2757ea844a1aSMatthew Knepley if (section->clObj == obj) { 2758ea844a1aSMatthew Knepley if (clSection) *clSection = section->clSection; 2759ea844a1aSMatthew Knepley if (clPoints) *clPoints = section->clPoints; 2760ea844a1aSMatthew Knepley } else { 2761ea844a1aSMatthew Knepley if (clSection) *clSection = NULL; 2762ea844a1aSMatthew Knepley if (clPoints) *clPoints = NULL; 2763ea844a1aSMatthew Knepley } 2764ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2765ea844a1aSMatthew Knepley } 2766ea844a1aSMatthew Knepley 2767d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetClosurePermutation_Internal(PetscSection section, PetscObject obj, PetscInt depth, PetscInt clSize, PetscCopyMode mode, PetscInt *clPerm) 2768d71ae5a4SJacob Faibussowitsch { 2769ea844a1aSMatthew Knepley PetscInt i; 2770c459fbc1SJed Brown khiter_t iter; 2771c459fbc1SJed Brown int new_entry; 2772c459fbc1SJed Brown PetscSectionClosurePermKey key = {depth, clSize}; 2773c459fbc1SJed Brown PetscSectionClosurePermVal *val; 2774ea844a1aSMatthew Knepley 2775ea844a1aSMatthew Knepley PetscFunctionBegin; 2776ea844a1aSMatthew Knepley if (section->clObj != obj) { 27779566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(§ion->clSection)); 27789566063dSJacob Faibussowitsch PetscCall(ISDestroy(§ion->clPoints)); 2779ea844a1aSMatthew Knepley } 2780ea844a1aSMatthew Knepley section->clObj = obj; 27819566063dSJacob Faibussowitsch if (!section->clHash) PetscCall(PetscClPermCreate(§ion->clHash)); 2782c459fbc1SJed Brown iter = kh_put(ClPerm, section->clHash, key, &new_entry); 2783c459fbc1SJed Brown val = &kh_val(section->clHash, iter); 2784c459fbc1SJed Brown if (!new_entry) { 27859566063dSJacob Faibussowitsch PetscCall(PetscFree(val->perm)); 27869566063dSJacob Faibussowitsch PetscCall(PetscFree(val->invPerm)); 2787c459fbc1SJed Brown } 2788ea844a1aSMatthew Knepley if (mode == PETSC_COPY_VALUES) { 27899566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(clSize, &val->perm)); 27909566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(val->perm, clPerm, clSize)); 2791ea844a1aSMatthew Knepley } else if (mode == PETSC_OWN_POINTER) { 2792c459fbc1SJed Brown val->perm = clPerm; 2793ea844a1aSMatthew Knepley } else SETERRQ(PetscObjectComm(obj), PETSC_ERR_SUP, "Do not support borrowed arrays"); 27949566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(clSize, &val->invPerm)); 2795c459fbc1SJed Brown for (i = 0; i < clSize; ++i) val->invPerm[clPerm[i]] = i; 2796ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2797ea844a1aSMatthew Knepley } 2798ea844a1aSMatthew Knepley 2799ea844a1aSMatthew Knepley /*@ 2800c459fbc1SJed Brown PetscSectionSetClosurePermutation - Set the dof permutation for the closure of each cell in the section, meaning clPerm[newIndex] = oldIndex. 2801ea844a1aSMatthew Knepley 2802ea844a1aSMatthew Knepley Not Collective 2803ea844a1aSMatthew Knepley 2804ea844a1aSMatthew Knepley Input Parameters: 2805cab54364SBarry Smith + section - The `PetscSection` 2806cab54364SBarry Smith . obj - A `PetscObject` which serves as the key for this index (usually a `DM`) 2807c459fbc1SJed Brown . depth - Depth of points on which to apply the given permutation 2808ea844a1aSMatthew Knepley - perm - Permutation of the cell dof closure 2809ea844a1aSMatthew Knepley 2810cab54364SBarry Smith Level: intermediate 2811cab54364SBarry Smith 2812cab54364SBarry Smith Notes: 2813c459fbc1SJed Brown The specified permutation will only be applied to points at depth whose closure size matches the length of perm. In a 2814c459fbc1SJed Brown mixed-topology or variable-degree finite element space, this function can be called multiple times at each depth for 2815c459fbc1SJed Brown each topology and degree. 2816c459fbc1SJed Brown 2817c459fbc1SJed Brown This approach assumes that (depth, len(perm)) uniquely identifies the desired permutation; this might not be true for 2818c459fbc1SJed Brown exotic/enriched spaces on mixed topology meshes. 2819ea844a1aSMatthew Knepley 2820cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `IS`, `PetscSectionGetClosurePermutation()`, `PetscSectionGetClosureIndex()`, `DMPlexCreateClosureIndex()`, `PetscCopyMode` 2821ea844a1aSMatthew Knepley @*/ 2822d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetClosurePermutation(PetscSection section, PetscObject obj, PetscInt depth, IS perm) 2823d71ae5a4SJacob Faibussowitsch { 2824ea844a1aSMatthew Knepley const PetscInt *clPerm = NULL; 2825ea844a1aSMatthew Knepley PetscInt clSize = 0; 2826ea844a1aSMatthew Knepley 2827ea844a1aSMatthew Knepley PetscFunctionBegin; 2828ea844a1aSMatthew Knepley if (perm) { 28299566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(perm, &clSize)); 28309566063dSJacob Faibussowitsch PetscCall(ISGetIndices(perm, &clPerm)); 2831ea844a1aSMatthew Knepley } 28329566063dSJacob Faibussowitsch PetscCall(PetscSectionSetClosurePermutation_Internal(section, obj, depth, clSize, PETSC_COPY_VALUES, (PetscInt *)clPerm)); 28339566063dSJacob Faibussowitsch if (perm) PetscCall(ISRestoreIndices(perm, &clPerm)); 2834ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2835ea844a1aSMatthew Knepley } 2836ea844a1aSMatthew Knepley 2837d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosurePermutation_Internal(PetscSection section, PetscObject obj, PetscInt depth, PetscInt size, const PetscInt *perm[]) 2838d71ae5a4SJacob Faibussowitsch { 2839ea844a1aSMatthew Knepley PetscFunctionBegin; 2840ea844a1aSMatthew Knepley if (section->clObj == obj) { 2841c459fbc1SJed Brown PetscSectionClosurePermKey k = {depth, size}; 2842c459fbc1SJed Brown PetscSectionClosurePermVal v; 28439566063dSJacob Faibussowitsch PetscCall(PetscClPermGet(section->clHash, k, &v)); 2844c459fbc1SJed Brown if (perm) *perm = v.perm; 2845ea844a1aSMatthew Knepley } else { 2846ea844a1aSMatthew Knepley if (perm) *perm = NULL; 2847ea844a1aSMatthew Knepley } 2848ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2849ea844a1aSMatthew Knepley } 2850ea844a1aSMatthew Knepley 2851ea844a1aSMatthew Knepley /*@ 2852ea844a1aSMatthew Knepley PetscSectionGetClosurePermutation - Get the dof permutation for the closure of each cell in the section, meaning clPerm[newIndex] = oldIndex. 2853ea844a1aSMatthew Knepley 285440750d41SVaclav Hapla Not Collective 2855ea844a1aSMatthew Knepley 2856ea844a1aSMatthew Knepley Input Parameters: 2857cab54364SBarry Smith + section - The `PetscSection` 2858cab54364SBarry Smith . obj - A `PetscObject` which serves as the key for this index (usually a DM) 2859c459fbc1SJed Brown . depth - Depth stratum on which to obtain closure permutation 2860c459fbc1SJed Brown - clSize - Closure size to be permuted (e.g., may vary with element topology and degree) 2861ea844a1aSMatthew Knepley 2862ea844a1aSMatthew Knepley Output Parameter: 2863ea844a1aSMatthew Knepley . perm - The dof closure permutation 2864ea844a1aSMatthew Knepley 2865ea844a1aSMatthew Knepley Level: intermediate 2866ea844a1aSMatthew Knepley 2867cab54364SBarry Smith Note: 2868cab54364SBarry Smith The user must destroy the `IS` that is returned. 2869cab54364SBarry Smith 2870cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `IS`, `PetscSectionSetClosurePermutation()`, `PetscSectionGetClosureInversePermutation()`, `PetscSectionGetClosureIndex()`, `PetscSectionSetClosureIndex()`, `DMPlexCreateClosureIndex()` 2871ea844a1aSMatthew Knepley @*/ 2872d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosurePermutation(PetscSection section, PetscObject obj, PetscInt depth, PetscInt clSize, IS *perm) 2873d71ae5a4SJacob Faibussowitsch { 2874ea844a1aSMatthew Knepley const PetscInt *clPerm; 2875ea844a1aSMatthew Knepley 2876ea844a1aSMatthew Knepley PetscFunctionBegin; 28779566063dSJacob Faibussowitsch PetscCall(PetscSectionGetClosurePermutation_Internal(section, obj, depth, clSize, &clPerm)); 28789566063dSJacob Faibussowitsch PetscCall(ISCreateGeneral(PETSC_COMM_SELF, clSize, clPerm, PETSC_USE_POINTER, perm)); 2879ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2880ea844a1aSMatthew Knepley } 2881ea844a1aSMatthew Knepley 2882d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosureInversePermutation_Internal(PetscSection section, PetscObject obj, PetscInt depth, PetscInt size, const PetscInt *perm[]) 2883d71ae5a4SJacob Faibussowitsch { 2884ea844a1aSMatthew Knepley PetscFunctionBegin; 2885c459fbc1SJed Brown if (section->clObj == obj && section->clHash) { 2886c459fbc1SJed Brown PetscSectionClosurePermKey k = {depth, size}; 2887c459fbc1SJed Brown PetscSectionClosurePermVal v; 28889566063dSJacob Faibussowitsch PetscCall(PetscClPermGet(section->clHash, k, &v)); 2889c459fbc1SJed Brown if (perm) *perm = v.invPerm; 2890ea844a1aSMatthew Knepley } else { 2891ea844a1aSMatthew Knepley if (perm) *perm = NULL; 2892ea844a1aSMatthew Knepley } 2893ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2894ea844a1aSMatthew Knepley } 2895ea844a1aSMatthew Knepley 2896ea844a1aSMatthew Knepley /*@ 2897ea844a1aSMatthew Knepley PetscSectionGetClosureInversePermutation - Get the inverse dof permutation for the closure of each cell in the section, meaning clPerm[oldIndex] = newIndex. 2898ea844a1aSMatthew Knepley 289940750d41SVaclav Hapla Not Collective 2900ea844a1aSMatthew Knepley 2901ea844a1aSMatthew Knepley Input Parameters: 2902cab54364SBarry Smith + section - The `PetscSection` 2903cab54364SBarry Smith . obj - A `PetscObject` which serves as the key for this index (usually a `DM`) 2904c459fbc1SJed Brown . depth - Depth stratum on which to obtain closure permutation 2905c459fbc1SJed Brown - clSize - Closure size to be permuted (e.g., may vary with element topology and degree) 2906ea844a1aSMatthew Knepley 2907ea844a1aSMatthew Knepley Output Parameters: 2908c459fbc1SJed Brown . perm - The dof closure permutation 2909ea844a1aSMatthew Knepley 2910ea844a1aSMatthew Knepley Level: intermediate 2911ea844a1aSMatthew Knepley 2912cab54364SBarry Smith Note: 2913cab54364SBarry Smith The user must destroy the `IS` that is returned. 2914cab54364SBarry Smith 2915cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `IS`, `PetscSectionSetClosurePermutation()`, `PetscSectionGetClosureIndex()`, `PetscSectionSetClosureIndex()`, `DMPlexCreateClosureIndex()` 2916ea844a1aSMatthew Knepley @*/ 2917d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosureInversePermutation(PetscSection section, PetscObject obj, PetscInt depth, PetscInt clSize, IS *perm) 2918d71ae5a4SJacob Faibussowitsch { 2919ea844a1aSMatthew Knepley const PetscInt *clPerm; 2920ea844a1aSMatthew Knepley 2921ea844a1aSMatthew Knepley PetscFunctionBegin; 29229566063dSJacob Faibussowitsch PetscCall(PetscSectionGetClosureInversePermutation_Internal(section, obj, depth, clSize, &clPerm)); 29239566063dSJacob Faibussowitsch PetscCall(ISCreateGeneral(PETSC_COMM_SELF, clSize, clPerm, PETSC_USE_POINTER, perm)); 2924ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2925ea844a1aSMatthew Knepley } 2926ea844a1aSMatthew Knepley 2927ea844a1aSMatthew Knepley /*@ 2928ea844a1aSMatthew Knepley PetscSectionGetField - Get the subsection associated with a single field 2929ea844a1aSMatthew Knepley 2930ea844a1aSMatthew Knepley Input Parameters: 2931cab54364SBarry Smith + s - The `PetscSection` 2932ea844a1aSMatthew Knepley - field - The field number 2933ea844a1aSMatthew Knepley 2934ea844a1aSMatthew Knepley Output Parameter: 2935ea844a1aSMatthew Knepley . subs - The subsection for the given field 2936ea844a1aSMatthew Knepley 2937ea844a1aSMatthew Knepley Level: intermediate 2938ea844a1aSMatthew Knepley 2939cab54364SBarry Smith Note: 2940cab54364SBarry Smith Does not increase the reference count of the selected sub-section. There is no matching `PetscSectionRestoreField()` 2941cab54364SBarry Smith 2942cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `IS`, `PetscSectionSetNumFields()` 2943ea844a1aSMatthew Knepley @*/ 2944d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetField(PetscSection s, PetscInt field, PetscSection *subs) 2945d71ae5a4SJacob Faibussowitsch { 2946ea844a1aSMatthew Knepley PetscFunctionBegin; 2947ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2948ea844a1aSMatthew Knepley PetscValidPointer(subs, 3); 29492abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 2950ea844a1aSMatthew Knepley *subs = s->field[field]; 2951ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2952ea844a1aSMatthew Knepley } 2953ea844a1aSMatthew Knepley 2954ea844a1aSMatthew Knepley PetscClassId PETSC_SECTION_SYM_CLASSID; 2955ea844a1aSMatthew Knepley PetscFunctionList PetscSectionSymList = NULL; 2956ea844a1aSMatthew Knepley 2957ea844a1aSMatthew Knepley /*@ 2958cab54364SBarry Smith PetscSectionSymCreate - Creates an empty `PetscSectionSym` object. 2959ea844a1aSMatthew Knepley 2960ea844a1aSMatthew Knepley Collective 2961ea844a1aSMatthew Knepley 2962ea844a1aSMatthew Knepley Input Parameter: 2963ea844a1aSMatthew Knepley . comm - the MPI communicator 2964ea844a1aSMatthew Knepley 2965ea844a1aSMatthew Knepley Output Parameter: 2966ea844a1aSMatthew Knepley . sym - pointer to the new set of symmetries 2967ea844a1aSMatthew Knepley 2968ea844a1aSMatthew Knepley Level: developer 2969ea844a1aSMatthew Knepley 2970cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSection`, `PetscSectionSym`, `PetscSectionSymDestroy()` 2971ea844a1aSMatthew Knepley @*/ 2972d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymCreate(MPI_Comm comm, PetscSectionSym *sym) 2973d71ae5a4SJacob Faibussowitsch { 2974ea844a1aSMatthew Knepley PetscFunctionBegin; 2975ea844a1aSMatthew Knepley PetscValidPointer(sym, 2); 29769566063dSJacob Faibussowitsch PetscCall(ISInitializePackage()); 29779566063dSJacob Faibussowitsch PetscCall(PetscHeaderCreate(*sym, PETSC_SECTION_SYM_CLASSID, "PetscSectionSym", "Section Symmetry", "IS", comm, PetscSectionSymDestroy, PetscSectionSymView)); 2978ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2979ea844a1aSMatthew Knepley } 2980ea844a1aSMatthew Knepley 2981ea844a1aSMatthew Knepley /*@C 2982cab54364SBarry Smith PetscSectionSymSetType - Builds a `PetscSectionSym`, for a particular implementation. 2983ea844a1aSMatthew Knepley 298440750d41SVaclav Hapla Collective 2985ea844a1aSMatthew Knepley 2986ea844a1aSMatthew Knepley Input Parameters: 2987ea844a1aSMatthew Knepley + sym - The section symmetry object 2988ea844a1aSMatthew Knepley - method - The name of the section symmetry type 2989ea844a1aSMatthew Knepley 2990ea844a1aSMatthew Knepley Level: developer 2991ea844a1aSMatthew Knepley 2992cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSymType`, `PetscSectionSymGetType()`, `PetscSectionSymCreate()` 2993ea844a1aSMatthew Knepley @*/ 2994d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymSetType(PetscSectionSym sym, PetscSectionSymType method) 2995d71ae5a4SJacob Faibussowitsch { 2996ea844a1aSMatthew Knepley PetscErrorCode (*r)(PetscSectionSym); 2997ea844a1aSMatthew Knepley PetscBool match; 2998ea844a1aSMatthew Knepley 2999ea844a1aSMatthew Knepley PetscFunctionBegin; 3000ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 30019566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)sym, method, &match)); 3002ea844a1aSMatthew Knepley if (match) PetscFunctionReturn(0); 3003ea844a1aSMatthew Knepley 30049566063dSJacob Faibussowitsch PetscCall(PetscFunctionListFind(PetscSectionSymList, method, &r)); 300528b400f6SJacob Faibussowitsch PetscCheck(r, PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscSectionSym type: %s", method); 3006dbbe0bcdSBarry Smith PetscTryTypeMethod(sym, destroy); 3007ea844a1aSMatthew Knepley sym->ops->destroy = NULL; 3008dbbe0bcdSBarry Smith 30099566063dSJacob Faibussowitsch PetscCall((*r)(sym)); 30109566063dSJacob Faibussowitsch PetscCall(PetscObjectChangeTypeName((PetscObject)sym, method)); 3011ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3012ea844a1aSMatthew Knepley } 3013ea844a1aSMatthew Knepley 3014ea844a1aSMatthew Knepley /*@C 3015cab54364SBarry Smith PetscSectionSymGetType - Gets the section symmetry type name (as a string) from the `PetscSectionSym`. 3016ea844a1aSMatthew Knepley 3017ea844a1aSMatthew Knepley Not Collective 3018ea844a1aSMatthew Knepley 3019ea844a1aSMatthew Knepley Input Parameter: 3020ea844a1aSMatthew Knepley . sym - The section symmetry 3021ea844a1aSMatthew Knepley 3022ea844a1aSMatthew Knepley Output Parameter: 3023ea844a1aSMatthew Knepley . type - The index set type name 3024ea844a1aSMatthew Knepley 3025ea844a1aSMatthew Knepley Level: developer 3026ea844a1aSMatthew Knepley 3027cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSymType`, `PetscSectionSymSetType()`, `PetscSectionSymCreate()` 3028ea844a1aSMatthew Knepley @*/ 3029d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymGetType(PetscSectionSym sym, PetscSectionSymType *type) 3030d71ae5a4SJacob Faibussowitsch { 3031ea844a1aSMatthew Knepley PetscFunctionBegin; 3032ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 3033dadcf809SJacob Faibussowitsch PetscValidPointer(type, 2); 3034ea844a1aSMatthew Knepley *type = ((PetscObject)sym)->type_name; 3035ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3036ea844a1aSMatthew Knepley } 3037ea844a1aSMatthew Knepley 3038ea844a1aSMatthew Knepley /*@C 3039cab54364SBarry Smith PetscSectionSymRegister - Registers a new section symmetry implementation 3040ea844a1aSMatthew Knepley 3041ea844a1aSMatthew Knepley Not Collective 3042ea844a1aSMatthew Knepley 3043ea844a1aSMatthew Knepley Input Parameters: 3044ea844a1aSMatthew Knepley + name - The name of a new user-defined creation routine 3045ea844a1aSMatthew Knepley - create_func - The creation routine itself 3046ea844a1aSMatthew Knepley 3047ea844a1aSMatthew Knepley Level: developer 3048ea844a1aSMatthew Knepley 3049cab54364SBarry Smith Notes: 3050cab54364SBarry Smith `PetscSectionSymRegister()` may be called multiple times to add several user-defined vectors 3051cab54364SBarry Smith 3052cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSymType`, `PetscSectionSymCreate()`, `PetscSectionSymSetType()` 3053ea844a1aSMatthew Knepley @*/ 3054d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymRegister(const char sname[], PetscErrorCode (*function)(PetscSectionSym)) 3055d71ae5a4SJacob Faibussowitsch { 3056ea844a1aSMatthew Knepley PetscFunctionBegin; 30579566063dSJacob Faibussowitsch PetscCall(ISInitializePackage()); 30589566063dSJacob Faibussowitsch PetscCall(PetscFunctionListAdd(&PetscSectionSymList, sname, function)); 3059ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3060ea844a1aSMatthew Knepley } 3061ea844a1aSMatthew Knepley 3062ea844a1aSMatthew Knepley /*@ 3063ea844a1aSMatthew Knepley PetscSectionSymDestroy - Destroys a section symmetry. 3064ea844a1aSMatthew Knepley 306540750d41SVaclav Hapla Collective 3066ea844a1aSMatthew Knepley 3067ea844a1aSMatthew Knepley Input Parameters: 3068ea844a1aSMatthew Knepley . sym - the section symmetry 3069ea844a1aSMatthew Knepley 3070ea844a1aSMatthew Knepley Level: developer 3071ea844a1aSMatthew Knepley 3072cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSymCreate()`, `PetscSectionSymDestroy()` 3073ea844a1aSMatthew Knepley @*/ 3074d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymDestroy(PetscSectionSym *sym) 3075d71ae5a4SJacob Faibussowitsch { 3076ea844a1aSMatthew Knepley SymWorkLink link, next; 3077ea844a1aSMatthew Knepley 3078ea844a1aSMatthew Knepley PetscFunctionBegin; 3079ea844a1aSMatthew Knepley if (!*sym) PetscFunctionReturn(0); 3080ea844a1aSMatthew Knepley PetscValidHeaderSpecific((*sym), PETSC_SECTION_SYM_CLASSID, 1); 30819371c9d4SSatish Balay if (--((PetscObject)(*sym))->refct > 0) { 30829371c9d4SSatish Balay *sym = NULL; 30839371c9d4SSatish Balay PetscFunctionReturn(0); 3084ea844a1aSMatthew Knepley } 308548a46eb9SPierre Jolivet if ((*sym)->ops->destroy) PetscCall((*(*sym)->ops->destroy)(*sym)); 3086c9cc58a2SBarry Smith PetscCheck(!(*sym)->workout, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Work array still checked out"); 3087ea844a1aSMatthew Knepley for (link = (*sym)->workin; link; link = next) { 30880c99d500SBarry Smith PetscInt **perms = (PetscInt **)link->perms; 30890c99d500SBarry Smith PetscScalar **rots = (PetscScalar **)link->rots; 30900c99d500SBarry Smith PetscCall(PetscFree2(perms, rots)); 3091ea844a1aSMatthew Knepley next = link->next; 30929566063dSJacob Faibussowitsch PetscCall(PetscFree(link)); 3093ea844a1aSMatthew Knepley } 3094ea844a1aSMatthew Knepley (*sym)->workin = NULL; 30959566063dSJacob Faibussowitsch PetscCall(PetscHeaderDestroy(sym)); 3096ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3097ea844a1aSMatthew Knepley } 3098ea844a1aSMatthew Knepley 3099ea844a1aSMatthew Knepley /*@C 3100ea844a1aSMatthew Knepley PetscSectionSymView - Displays a section symmetry 3101ea844a1aSMatthew Knepley 310240750d41SVaclav Hapla Collective 3103ea844a1aSMatthew Knepley 3104ea844a1aSMatthew Knepley Input Parameters: 3105ea844a1aSMatthew Knepley + sym - the index set 3106cab54364SBarry Smith - viewer - viewer used to display the set, for example `PETSC_VIEWER_STDOUT_SELF`. 3107ea844a1aSMatthew Knepley 3108ea844a1aSMatthew Knepley Level: developer 3109ea844a1aSMatthew Knepley 3110cab54364SBarry Smith .seealso: `PetscSectionSym`, `PetscViewer`, `PetscViewerASCIIOpen()` 3111ea844a1aSMatthew Knepley @*/ 3112d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymView(PetscSectionSym sym, PetscViewer viewer) 3113d71ae5a4SJacob Faibussowitsch { 3114ea844a1aSMatthew Knepley PetscFunctionBegin; 3115ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 311648a46eb9SPierre Jolivet if (!viewer) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)sym), &viewer)); 3117ea844a1aSMatthew Knepley PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2); 3118ea844a1aSMatthew Knepley PetscCheckSameComm(sym, 1, viewer, 2); 31199566063dSJacob Faibussowitsch PetscCall(PetscObjectPrintClassNamePrefixType((PetscObject)sym, viewer)); 3120dbbe0bcdSBarry Smith PetscTryTypeMethod(sym, view, viewer); 3121ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3122ea844a1aSMatthew Knepley } 3123ea844a1aSMatthew Knepley 3124ea844a1aSMatthew Knepley /*@ 3125ea844a1aSMatthew Knepley PetscSectionSetSym - Set the symmetries for the data referred to by the section 3126ea844a1aSMatthew Knepley 312740750d41SVaclav Hapla Collective 3128ea844a1aSMatthew Knepley 3129ea844a1aSMatthew Knepley Input Parameters: 3130ea844a1aSMatthew Knepley + section - the section describing data layout 3131ea844a1aSMatthew Knepley - sym - the symmetry describing the affect of orientation on the access of the data 3132ea844a1aSMatthew Knepley 3133ea844a1aSMatthew Knepley Level: developer 3134ea844a1aSMatthew Knepley 3135cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionGetSym()`, `PetscSectionSymCreate()` 3136ea844a1aSMatthew Knepley @*/ 3137d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetSym(PetscSection section, PetscSectionSym sym) 3138d71ae5a4SJacob Faibussowitsch { 3139ea844a1aSMatthew Knepley PetscFunctionBegin; 3140ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 31419566063dSJacob Faibussowitsch PetscCall(PetscSectionSymDestroy(&(section->sym))); 3142ea844a1aSMatthew Knepley if (sym) { 3143ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 2); 3144ea844a1aSMatthew Knepley PetscCheckSameComm(section, 1, sym, 2); 31459566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)sym)); 3146ea844a1aSMatthew Knepley } 3147ea844a1aSMatthew Knepley section->sym = sym; 3148ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3149ea844a1aSMatthew Knepley } 3150ea844a1aSMatthew Knepley 3151ea844a1aSMatthew Knepley /*@ 3152ea844a1aSMatthew Knepley PetscSectionGetSym - Get the symmetries for the data referred to by the section 3153ea844a1aSMatthew Knepley 315440750d41SVaclav Hapla Not Collective 3155ea844a1aSMatthew Knepley 3156ea844a1aSMatthew Knepley Input Parameters: 3157ea844a1aSMatthew Knepley . section - the section describing data layout 3158ea844a1aSMatthew Knepley 3159ea844a1aSMatthew Knepley Output Parameters: 3160ea844a1aSMatthew Knepley . sym - the symmetry describing the affect of orientation on the access of the data 3161ea844a1aSMatthew Knepley 3162ea844a1aSMatthew Knepley Level: developer 3163ea844a1aSMatthew Knepley 3164cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSetSym()`, `PetscSectionSymCreate()` 3165ea844a1aSMatthew Knepley @*/ 3166d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetSym(PetscSection section, PetscSectionSym *sym) 3167d71ae5a4SJacob Faibussowitsch { 3168ea844a1aSMatthew Knepley PetscFunctionBegin; 3169ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 3170ea844a1aSMatthew Knepley *sym = section->sym; 3171ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3172ea844a1aSMatthew Knepley } 3173ea844a1aSMatthew Knepley 3174ea844a1aSMatthew Knepley /*@ 3175ea844a1aSMatthew Knepley PetscSectionSetFieldSym - Set the symmetries for the data referred to by a field of the section 3176ea844a1aSMatthew Knepley 317740750d41SVaclav Hapla Collective 3178ea844a1aSMatthew Knepley 3179ea844a1aSMatthew Knepley Input Parameters: 3180ea844a1aSMatthew Knepley + section - the section describing data layout 3181ea844a1aSMatthew Knepley . field - the field number 3182ea844a1aSMatthew Knepley - sym - the symmetry describing the affect of orientation on the access of the data 3183ea844a1aSMatthew Knepley 3184ea844a1aSMatthew Knepley Level: developer 3185ea844a1aSMatthew Knepley 3186cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionGetFieldSym()`, `PetscSectionSymCreate()` 3187ea844a1aSMatthew Knepley @*/ 3188d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldSym(PetscSection section, PetscInt field, PetscSectionSym sym) 3189d71ae5a4SJacob Faibussowitsch { 3190ea844a1aSMatthew Knepley PetscFunctionBegin; 3191ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 31922abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, section->numFields); 31939566063dSJacob Faibussowitsch PetscCall(PetscSectionSetSym(section->field[field], sym)); 3194ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3195ea844a1aSMatthew Knepley } 3196ea844a1aSMatthew Knepley 3197ea844a1aSMatthew Knepley /*@ 3198ea844a1aSMatthew Knepley PetscSectionGetFieldSym - Get the symmetries for the data referred to by a field of the section 3199ea844a1aSMatthew Knepley 320040750d41SVaclav Hapla Collective 3201ea844a1aSMatthew Knepley 3202ea844a1aSMatthew Knepley Input Parameters: 3203ea844a1aSMatthew Knepley + section - the section describing data layout 3204ea844a1aSMatthew Knepley - field - the field number 3205ea844a1aSMatthew Knepley 3206ea844a1aSMatthew Knepley Output Parameters: 3207ea844a1aSMatthew Knepley . sym - the symmetry describing the affect of orientation on the access of the data 3208ea844a1aSMatthew Knepley 3209ea844a1aSMatthew Knepley Level: developer 3210ea844a1aSMatthew Knepley 3211cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSetFieldSym()`, `PetscSectionSymCreate()` 3212ea844a1aSMatthew Knepley @*/ 3213d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldSym(PetscSection section, PetscInt field, PetscSectionSym *sym) 3214d71ae5a4SJacob Faibussowitsch { 3215ea844a1aSMatthew Knepley PetscFunctionBegin; 3216ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 32172abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, section->numFields); 3218ea844a1aSMatthew Knepley *sym = section->field[field]->sym; 3219ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3220ea844a1aSMatthew Knepley } 3221ea844a1aSMatthew Knepley 3222ea844a1aSMatthew Knepley /*@C 3223cab54364SBarry Smith PetscSectionGetPointSyms - Get the symmetries for a set of points in a `PetscSection` under specific orientations. 3224ea844a1aSMatthew Knepley 322540750d41SVaclav Hapla Not Collective 3226ea844a1aSMatthew Knepley 3227ea844a1aSMatthew Knepley Input Parameters: 3228ea844a1aSMatthew Knepley + section - the section 3229ea844a1aSMatthew Knepley . numPoints - the number of points 3230ea844a1aSMatthew Knepley - points - an array of size 2 * numPoints, containing a list of (point, orientation) pairs. (An orientation is an 3231ea844a1aSMatthew Knepley arbitrary integer: its interpretation is up to sym. Orientations are used by DM: for their interpretation in that 3232ea844a1aSMatthew Knepley context, see DMPlexGetConeOrientation()). 3233ea844a1aSMatthew Knepley 3234d8d19677SJose E. Roman Output Parameters: 3235ea844a1aSMatthew Knepley + perms - The permutations for the given orientations (or NULL if there is no symmetry or the permutation is the identity). 3236ea844a1aSMatthew Knepley - rots - The field rotations symmetries for the given orientations (or NULL if there is no symmetry or the rotations are all 3237ea844a1aSMatthew Knepley identity). 3238ea844a1aSMatthew Knepley 3239ea844a1aSMatthew Knepley Example of usage, gathering dofs into a local array (lArray) from a section array (sArray): 3240ea844a1aSMatthew Knepley .vb 3241ea844a1aSMatthew Knepley const PetscInt **perms; 3242ea844a1aSMatthew Knepley const PetscScalar **rots; 3243ea844a1aSMatthew Knepley PetscInt lOffset; 3244ea844a1aSMatthew Knepley 3245ea844a1aSMatthew Knepley PetscSectionGetPointSyms(section,numPoints,points,&perms,&rots); 3246ea844a1aSMatthew Knepley for (i = 0, lOffset = 0; i < numPoints; i++) { 3247ea844a1aSMatthew Knepley PetscInt point = points[2*i], dof, sOffset; 3248ea844a1aSMatthew Knepley const PetscInt *perm = perms ? perms[i] : NULL; 3249ea844a1aSMatthew Knepley const PetscScalar *rot = rots ? rots[i] : NULL; 3250ea844a1aSMatthew Knepley 3251ea844a1aSMatthew Knepley PetscSectionGetDof(section,point,&dof); 3252ea844a1aSMatthew Knepley PetscSectionGetOffset(section,point,&sOffset); 3253ea844a1aSMatthew Knepley 3254ea844a1aSMatthew Knepley if (perm) {for (j = 0; j < dof; j++) {lArray[lOffset + perm[j]] = sArray[sOffset + j];}} 3255ea844a1aSMatthew Knepley else {for (j = 0; j < dof; j++) {lArray[lOffset + j ] = sArray[sOffset + j];}} 3256ea844a1aSMatthew Knepley if (rot) {for (j = 0; j < dof; j++) {lArray[lOffset + j ] *= rot[j]; }} 3257ea844a1aSMatthew Knepley lOffset += dof; 3258ea844a1aSMatthew Knepley } 3259ea844a1aSMatthew Knepley PetscSectionRestorePointSyms(section,numPoints,points,&perms,&rots); 3260ea844a1aSMatthew Knepley .ve 3261ea844a1aSMatthew Knepley 3262ea844a1aSMatthew Knepley Example of usage, adding dofs into a section array (sArray) from a local array (lArray): 3263ea844a1aSMatthew Knepley .vb 3264ea844a1aSMatthew Knepley const PetscInt **perms; 3265ea844a1aSMatthew Knepley const PetscScalar **rots; 3266ea844a1aSMatthew Knepley PetscInt lOffset; 3267ea844a1aSMatthew Knepley 3268ea844a1aSMatthew Knepley PetscSectionGetPointSyms(section,numPoints,points,&perms,&rots); 3269ea844a1aSMatthew Knepley for (i = 0, lOffset = 0; i < numPoints; i++) { 3270ea844a1aSMatthew Knepley PetscInt point = points[2*i], dof, sOffset; 3271ea844a1aSMatthew Knepley const PetscInt *perm = perms ? perms[i] : NULL; 3272ea844a1aSMatthew Knepley const PetscScalar *rot = rots ? rots[i] : NULL; 3273ea844a1aSMatthew Knepley 3274ea844a1aSMatthew Knepley PetscSectionGetDof(section,point,&dof); 3275ea844a1aSMatthew Knepley PetscSectionGetOffset(section,point,&sOff); 3276ea844a1aSMatthew Knepley 3277ea844a1aSMatthew Knepley if (perm) {for (j = 0; j < dof; j++) {sArray[sOffset + j] += lArray[lOffset + perm[j]] * (rot ? PetscConj(rot[perm[j]]) : 1.);}} 3278ea844a1aSMatthew Knepley else {for (j = 0; j < dof; j++) {sArray[sOffset + j] += lArray[lOffset + j ] * (rot ? PetscConj(rot[ j ]) : 1.);}} 3279ea844a1aSMatthew Knepley offset += dof; 3280ea844a1aSMatthew Knepley } 3281ea844a1aSMatthew Knepley PetscSectionRestorePointSyms(section,numPoints,points,&perms,&rots); 3282ea844a1aSMatthew Knepley .ve 3283ea844a1aSMatthew Knepley 3284ea844a1aSMatthew Knepley Level: developer 3285ea844a1aSMatthew Knepley 3286cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionRestorePointSyms()`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()` 3287ea844a1aSMatthew Knepley @*/ 3288d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetPointSyms(PetscSection section, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots) 3289d71ae5a4SJacob Faibussowitsch { 3290ea844a1aSMatthew Knepley PetscSectionSym sym; 3291ea844a1aSMatthew Knepley 3292ea844a1aSMatthew Knepley PetscFunctionBegin; 3293ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 3294ea844a1aSMatthew Knepley if (numPoints) PetscValidIntPointer(points, 3); 3295ea844a1aSMatthew Knepley if (perms) *perms = NULL; 3296ea844a1aSMatthew Knepley if (rots) *rots = NULL; 3297ea844a1aSMatthew Knepley sym = section->sym; 3298ea844a1aSMatthew Knepley if (sym && (perms || rots)) { 3299ea844a1aSMatthew Knepley SymWorkLink link; 3300ea844a1aSMatthew Knepley 3301ea844a1aSMatthew Knepley if (sym->workin) { 3302ea844a1aSMatthew Knepley link = sym->workin; 3303ea844a1aSMatthew Knepley sym->workin = sym->workin->next; 3304ea844a1aSMatthew Knepley } else { 33054dfa11a4SJacob Faibussowitsch PetscCall(PetscNew(&link)); 3306ea844a1aSMatthew Knepley } 3307ea844a1aSMatthew Knepley if (numPoints > link->numPoints) { 33080c99d500SBarry Smith PetscInt **perms = (PetscInt **)link->perms; 33090c99d500SBarry Smith PetscScalar **rots = (PetscScalar **)link->rots; 33100c99d500SBarry Smith PetscCall(PetscFree2(perms, rots)); 33110c99d500SBarry Smith PetscCall(PetscMalloc2(numPoints, (PetscInt ***)&link->perms, numPoints, (PetscScalar ***)&link->rots)); 3312ea844a1aSMatthew Knepley link->numPoints = numPoints; 3313ea844a1aSMatthew Knepley } 3314ea844a1aSMatthew Knepley link->next = sym->workout; 3315ea844a1aSMatthew Knepley sym->workout = link; 33169566063dSJacob Faibussowitsch PetscCall(PetscArrayzero((PetscInt **)link->perms, numPoints)); 33179566063dSJacob Faibussowitsch PetscCall(PetscArrayzero((PetscInt **)link->rots, numPoints)); 33189566063dSJacob Faibussowitsch PetscCall((*sym->ops->getpoints)(sym, section, numPoints, points, link->perms, link->rots)); 3319ea844a1aSMatthew Knepley if (perms) *perms = link->perms; 3320ea844a1aSMatthew Knepley if (rots) *rots = link->rots; 3321ea844a1aSMatthew Knepley } 3322ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3323ea844a1aSMatthew Knepley } 3324ea844a1aSMatthew Knepley 3325ea844a1aSMatthew Knepley /*@C 3326cab54364SBarry Smith PetscSectionRestorePointSyms - Restore the symmetries returned by `PetscSectionGetPointSyms()` 3327ea844a1aSMatthew Knepley 332840750d41SVaclav Hapla Not Collective 3329ea844a1aSMatthew Knepley 3330ea844a1aSMatthew Knepley Input Parameters: 3331ea844a1aSMatthew Knepley + section - the section 3332ea844a1aSMatthew Knepley . numPoints - the number of points 3333ea844a1aSMatthew Knepley - points - an array of size 2 * numPoints, containing a list of (point, orientation) pairs. (An orientation is an 3334cab54364SBarry Smith arbitrary integer: its interpretation is up to sym. Orientations are used by `DM`: for their interpretation in that 3335cab54364SBarry Smith context, see `DMPlexGetConeOrientation()`). 3336ea844a1aSMatthew Knepley 3337d8d19677SJose E. Roman Output Parameters: 3338ea844a1aSMatthew Knepley + perms - The permutations for the given orientations: set to NULL at conclusion 3339ea844a1aSMatthew Knepley - rots - The field rotations symmetries for the given orientations: set to NULL at conclusion 3340ea844a1aSMatthew Knepley 3341ea844a1aSMatthew Knepley Level: developer 3342ea844a1aSMatthew Knepley 3343cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionGetPointSyms()`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()` 3344ea844a1aSMatthew Knepley @*/ 3345d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionRestorePointSyms(PetscSection section, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots) 3346d71ae5a4SJacob Faibussowitsch { 3347ea844a1aSMatthew Knepley PetscSectionSym sym; 3348ea844a1aSMatthew Knepley 3349ea844a1aSMatthew Knepley PetscFunctionBegin; 3350ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 3351ea844a1aSMatthew Knepley sym = section->sym; 3352ea844a1aSMatthew Knepley if (sym && (perms || rots)) { 3353ea844a1aSMatthew Knepley SymWorkLink *p, link; 3354ea844a1aSMatthew Knepley 3355ea844a1aSMatthew Knepley for (p = &sym->workout; (link = *p); p = &link->next) { 3356ea844a1aSMatthew Knepley if ((perms && link->perms == *perms) || (rots && link->rots == *rots)) { 3357ea844a1aSMatthew Knepley *p = link->next; 3358ea844a1aSMatthew Knepley link->next = sym->workin; 3359ea844a1aSMatthew Knepley sym->workin = link; 3360ea844a1aSMatthew Knepley if (perms) *perms = NULL; 3361ea844a1aSMatthew Knepley if (rots) *rots = NULL; 3362ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3363ea844a1aSMatthew Knepley } 3364ea844a1aSMatthew Knepley } 3365ea844a1aSMatthew Knepley SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Array was not checked out"); 3366ea844a1aSMatthew Knepley } 3367ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3368ea844a1aSMatthew Knepley } 3369ea844a1aSMatthew Knepley 3370ea844a1aSMatthew Knepley /*@C 3371cab54364SBarry Smith PetscSectionGetFieldPointSyms - Get the symmetries for a set of points in a field of a `PetscSection` under specific orientations. 3372ea844a1aSMatthew Knepley 337340750d41SVaclav Hapla Not Collective 3374ea844a1aSMatthew Knepley 3375ea844a1aSMatthew Knepley Input Parameters: 3376ea844a1aSMatthew Knepley + section - the section 3377ea844a1aSMatthew Knepley . field - the field of the section 3378ea844a1aSMatthew Knepley . numPoints - the number of points 3379ea844a1aSMatthew Knepley - points - an array of size 2 * numPoints, containing a list of (point, orientation) pairs. (An orientation is an 3380cab54364SBarry Smith arbitrary integer: its interpretation is up to sym. Orientations are used by `DM`: for their interpretation in that 3381cab54364SBarry Smith context, see `DMPlexGetConeOrientation()`). 3382ea844a1aSMatthew Knepley 3383d8d19677SJose E. Roman Output Parameters: 3384ea844a1aSMatthew Knepley + perms - The permutations for the given orientations (or NULL if there is no symmetry or the permutation is the identity). 3385ea844a1aSMatthew Knepley - rots - The field rotations symmetries for the given orientations (or NULL if there is no symmetry or the rotations are all 3386ea844a1aSMatthew Knepley identity). 3387ea844a1aSMatthew Knepley 3388ea844a1aSMatthew Knepley Level: developer 3389ea844a1aSMatthew Knepley 3390cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionGetPointSyms()`, `PetscSectionRestoreFieldPointSyms()` 3391ea844a1aSMatthew Knepley @*/ 3392d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldPointSyms(PetscSection section, PetscInt field, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots) 3393d71ae5a4SJacob Faibussowitsch { 3394ea844a1aSMatthew Knepley PetscFunctionBegin; 3395ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 339608401ef6SPierre 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); 33979566063dSJacob Faibussowitsch PetscCall(PetscSectionGetPointSyms(section->field[field], numPoints, points, perms, rots)); 3398ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3399ea844a1aSMatthew Knepley } 3400ea844a1aSMatthew Knepley 3401ea844a1aSMatthew Knepley /*@C 3402cab54364SBarry Smith PetscSectionRestoreFieldPointSyms - Restore the symmetries returned by `PetscSectionGetFieldPointSyms()` 3403ea844a1aSMatthew Knepley 340440750d41SVaclav Hapla Not Collective 3405ea844a1aSMatthew Knepley 3406ea844a1aSMatthew Knepley Input Parameters: 3407ea844a1aSMatthew Knepley + section - the section 3408ea844a1aSMatthew Knepley . field - the field number 3409ea844a1aSMatthew Knepley . numPoints - the number of points 3410ea844a1aSMatthew Knepley - points - an array of size 2 * numPoints, containing a list of (point, orientation) pairs. (An orientation is an 3411cab54364SBarry Smith arbitrary integer: its interpretation is up to sym. Orientations are used by `DM`: for their interpretation in that 3412cab54364SBarry Smith context, see `DMPlexGetConeOrientation()`). 3413ea844a1aSMatthew Knepley 3414d8d19677SJose E. Roman Output Parameters: 3415ea844a1aSMatthew Knepley + perms - The permutations for the given orientations: set to NULL at conclusion 3416ea844a1aSMatthew Knepley - rots - The field rotations symmetries for the given orientations: set to NULL at conclusion 3417ea844a1aSMatthew Knepley 3418ea844a1aSMatthew Knepley Level: developer 3419ea844a1aSMatthew Knepley 3420cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionRestorePointSyms()`, `petscSectionGetFieldPointSyms()`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()` 3421ea844a1aSMatthew Knepley @*/ 3422d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionRestoreFieldPointSyms(PetscSection section, PetscInt field, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots) 3423d71ae5a4SJacob Faibussowitsch { 3424ea844a1aSMatthew Knepley PetscFunctionBegin; 3425ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 342608401ef6SPierre 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); 34279566063dSJacob Faibussowitsch PetscCall(PetscSectionRestorePointSyms(section->field[field], numPoints, points, perms, rots)); 3428ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3429ea844a1aSMatthew Knepley } 3430ea844a1aSMatthew Knepley 3431ea844a1aSMatthew Knepley /*@ 3432b004864fSMatthew G. Knepley PetscSectionSymCopy - Copy the symmetries, assuming that the point structure is compatible 3433b004864fSMatthew G. Knepley 343440750d41SVaclav Hapla Not Collective 3435b004864fSMatthew G. Knepley 3436b004864fSMatthew G. Knepley Input Parameter: 3437cab54364SBarry Smith . sym - the `PetscSectionSym` 3438b004864fSMatthew G. Knepley 3439b004864fSMatthew G. Knepley Output Parameter: 3440b004864fSMatthew G. Knepley . nsym - the equivalent symmetries 3441b004864fSMatthew G. Knepley 3442b004864fSMatthew G. Knepley Level: developer 3443b004864fSMatthew G. Knepley 3444cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()`, `PetscSectionSymLabelSetStratum()`, `PetscSectionGetPointSyms()` 3445b004864fSMatthew G. Knepley @*/ 3446d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymCopy(PetscSectionSym sym, PetscSectionSym nsym) 3447d71ae5a4SJacob Faibussowitsch { 3448b004864fSMatthew G. Knepley PetscFunctionBegin; 3449b004864fSMatthew G. Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 3450b004864fSMatthew G. Knepley PetscValidHeaderSpecific(nsym, PETSC_SECTION_SYM_CLASSID, 2); 3451dbbe0bcdSBarry Smith PetscTryTypeMethod(sym, copy, nsym); 3452b004864fSMatthew G. Knepley PetscFunctionReturn(0); 3453b004864fSMatthew G. Knepley } 3454b004864fSMatthew G. Knepley 3455b004864fSMatthew G. Knepley /*@ 3456cab54364SBarry Smith PetscSectionSymDistribute - Distribute the symmetries in accordance with the input `PetscSF` 3457b004864fSMatthew G. Knepley 3458b004864fSMatthew G. Knepley Collective 3459b004864fSMatthew G. Knepley 3460b004864fSMatthew G. Knepley Input Parameters: 3461cab54364SBarry Smith + sym - the `PetscSectionSym` 3462b004864fSMatthew G. Knepley - migrationSF - the distribution map from roots to leaves 3463b004864fSMatthew G. Knepley 3464b004864fSMatthew G. Knepley Output Parameters: 3465b004864fSMatthew G. Knepley . dsym - the redistributed symmetries 3466b004864fSMatthew G. Knepley 3467b004864fSMatthew G. Knepley Level: developer 3468b004864fSMatthew G. Knepley 3469cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()`, `PetscSectionSymLabelSetStratum()`, `PetscSectionGetPointSyms()` 3470b004864fSMatthew G. Knepley @*/ 3471d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymDistribute(PetscSectionSym sym, PetscSF migrationSF, PetscSectionSym *dsym) 3472d71ae5a4SJacob Faibussowitsch { 3473b004864fSMatthew G. Knepley PetscFunctionBegin; 3474b004864fSMatthew G. Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 3475b004864fSMatthew G. Knepley PetscValidHeaderSpecific(migrationSF, PETSCSF_CLASSID, 2); 3476b004864fSMatthew G. Knepley PetscValidPointer(dsym, 3); 3477dbbe0bcdSBarry Smith PetscTryTypeMethod(sym, distribute, migrationSF, dsym); 3478b004864fSMatthew G. Knepley PetscFunctionReturn(0); 3479b004864fSMatthew G. Knepley } 3480b004864fSMatthew G. Knepley 3481b004864fSMatthew G. Knepley /*@ 3482ea844a1aSMatthew Knepley PetscSectionGetUseFieldOffsets - Get the flag to use field offsets directly in a global section, rather than just the point offset 3483ea844a1aSMatthew Knepley 348440750d41SVaclav Hapla Not Collective 3485ea844a1aSMatthew Knepley 3486ea844a1aSMatthew Knepley Input Parameter: 3487cab54364SBarry Smith . s - the global `PetscSection` 3488ea844a1aSMatthew Knepley 3489ea844a1aSMatthew Knepley Output Parameters: 3490ea844a1aSMatthew Knepley . flg - the flag 3491ea844a1aSMatthew Knepley 3492ea844a1aSMatthew Knepley Level: developer 3493ea844a1aSMatthew Knepley 3494cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionSetChart()`, `PetscSectionCreate()` 3495ea844a1aSMatthew Knepley @*/ 3496d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetUseFieldOffsets(PetscSection s, PetscBool *flg) 3497d71ae5a4SJacob Faibussowitsch { 3498ea844a1aSMatthew Knepley PetscFunctionBegin; 3499ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 3500ea844a1aSMatthew Knepley *flg = s->useFieldOff; 3501ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3502ea844a1aSMatthew Knepley } 3503ea844a1aSMatthew Knepley 3504ea844a1aSMatthew Knepley /*@ 3505ea844a1aSMatthew Knepley PetscSectionSetUseFieldOffsets - Set the flag to use field offsets directly in a global section, rather than just the point offset 3506ea844a1aSMatthew Knepley 350740750d41SVaclav Hapla Not Collective 3508ea844a1aSMatthew Knepley 3509ea844a1aSMatthew Knepley Input Parameters: 3510cab54364SBarry Smith + s - the global `PetscSection` 3511ea844a1aSMatthew Knepley - flg - the flag 3512ea844a1aSMatthew Knepley 3513ea844a1aSMatthew Knepley Level: developer 3514ea844a1aSMatthew Knepley 3515cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionGetUseFieldOffsets()`, `PetscSectionSetChart()`, `PetscSectionCreate()` 3516ea844a1aSMatthew Knepley @*/ 3517d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetUseFieldOffsets(PetscSection s, PetscBool flg) 3518d71ae5a4SJacob Faibussowitsch { 3519ea844a1aSMatthew Knepley PetscFunctionBegin; 3520ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 3521ea844a1aSMatthew Knepley s->useFieldOff = flg; 3522ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3523ea844a1aSMatthew Knepley } 3524ea844a1aSMatthew Knepley 3525ea844a1aSMatthew Knepley #define PetscSectionExpandPoints_Loop(TYPE) \ 3526ea844a1aSMatthew Knepley { \ 3527ea844a1aSMatthew Knepley PetscInt i, n, o0, o1, size; \ 3528ea844a1aSMatthew Knepley TYPE *a0 = (TYPE *)origArray, *a1; \ 35299566063dSJacob Faibussowitsch PetscCall(PetscSectionGetStorageSize(s, &size)); \ 35309566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(size, &a1)); \ 3531ea844a1aSMatthew Knepley for (i = 0; i < npoints; i++) { \ 35329566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(origSection, points_[i], &o0)); \ 35339566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s, i, &o1)); \ 35349566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, i, &n)); \ 35359566063dSJacob Faibussowitsch PetscCall(PetscMemcpy(&a1[o1], &a0[o0], n *unitsize)); \ 3536ea844a1aSMatthew Knepley } \ 3537ea844a1aSMatthew Knepley *newArray = (void *)a1; \ 3538ea844a1aSMatthew Knepley } 3539ea844a1aSMatthew Knepley 3540ea844a1aSMatthew Knepley /*@ 3541ea844a1aSMatthew Knepley PetscSectionExtractDofsFromArray - Extracts elements of an array corresponding to DOFs of specified points. 3542ea844a1aSMatthew Knepley 354340750d41SVaclav Hapla Not Collective 3544ea844a1aSMatthew Knepley 3545ea844a1aSMatthew Knepley Input Parameters: 3546cab54364SBarry Smith + origSection - the `PetscSection` describing the layout of the array 3547cab54364SBarry Smith . dataType - `MPI_Datatype` describing the data type of the array (currently only `MPIU_INT`, `MPIU_SCALAR`, `MPIU_REAL`) 3548ea844a1aSMatthew Knepley . origArray - the array; its size must be equal to the storage size of origSection 3549cab54364SBarry Smith - points - `IS` with points to extract; its indices must lie in the chart of origSection 3550ea844a1aSMatthew Knepley 3551ea844a1aSMatthew Knepley Output Parameters: 3552cab54364SBarry Smith + newSection - the new `PetscSection` desribing the layout of the new array (with points renumbered 0,1,... but preserving numbers of DOFs) 3553ea844a1aSMatthew Knepley - newArray - the array of the extracted DOFs; its size is the storage size of newSection 3554ea844a1aSMatthew Knepley 3555ea844a1aSMatthew Knepley Level: developer 3556ea844a1aSMatthew Knepley 3557cab54364SBarry Smith .seealso: [PetscSection](sec_petscsection), `PetscSectionSym`, `PetscSectionGetChart()`, `PetscSectionGetDof()`, `PetscSectionGetStorageSize()`, `PetscSectionCreate()` 3558ea844a1aSMatthew Knepley @*/ 3559d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionExtractDofsFromArray(PetscSection origSection, MPI_Datatype dataType, const void *origArray, IS points, PetscSection *newSection, void *newArray[]) 3560d71ae5a4SJacob Faibussowitsch { 3561ea844a1aSMatthew Knepley PetscSection s; 3562ea844a1aSMatthew Knepley const PetscInt *points_; 3563ea844a1aSMatthew Knepley PetscInt i, n, npoints, pStart, pEnd; 3564ea844a1aSMatthew Knepley PetscMPIInt unitsize; 3565ea844a1aSMatthew Knepley 3566ea844a1aSMatthew Knepley PetscFunctionBegin; 3567ea844a1aSMatthew Knepley PetscValidHeaderSpecific(origSection, PETSC_SECTION_CLASSID, 1); 3568ea844a1aSMatthew Knepley PetscValidPointer(origArray, 3); 3569ea844a1aSMatthew Knepley PetscValidHeaderSpecific(points, IS_CLASSID, 4); 3570ea844a1aSMatthew Knepley if (newSection) PetscValidPointer(newSection, 5); 3571ea844a1aSMatthew Knepley if (newArray) PetscValidPointer(newArray, 6); 35729566063dSJacob Faibussowitsch PetscCallMPI(MPI_Type_size(dataType, &unitsize)); 35739566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(points, &npoints)); 35749566063dSJacob Faibussowitsch PetscCall(ISGetIndices(points, &points_)); 35759566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(origSection, &pStart, &pEnd)); 35769566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PETSC_COMM_SELF, &s)); 35779566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(s, 0, npoints)); 3578ea844a1aSMatthew Knepley for (i = 0; i < npoints; i++) { 3579c9cc58a2SBarry 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); 35809566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(origSection, points_[i], &n)); 35819566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(s, i, n)); 3582ea844a1aSMatthew Knepley } 35839566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(s)); 3584ea844a1aSMatthew Knepley if (newArray) { 35859371c9d4SSatish Balay if (dataType == MPIU_INT) { 35869371c9d4SSatish Balay PetscSectionExpandPoints_Loop(PetscInt); 35879371c9d4SSatish Balay } else if (dataType == MPIU_SCALAR) { 35889371c9d4SSatish Balay PetscSectionExpandPoints_Loop(PetscScalar); 35899371c9d4SSatish Balay } else if (dataType == MPIU_REAL) { 35909371c9d4SSatish Balay PetscSectionExpandPoints_Loop(PetscReal); 35919371c9d4SSatish Balay } else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "not implemented for this MPI_Datatype"); 3592ea844a1aSMatthew Knepley } 3593ea844a1aSMatthew Knepley if (newSection) { 3594ea844a1aSMatthew Knepley *newSection = s; 3595ea844a1aSMatthew Knepley } else { 35969566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s)); 3597ea844a1aSMatthew Knepley } 35989566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(points, &points_)); 3599ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3600ea844a1aSMatthew Knepley } 3601