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 /*@ 11ea844a1aSMatthew Knepley PetscSectionCreate - Allocates PetscSection space 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 23ea844a1aSMatthew Knepley $ PetscSectionCreate(MPI_Comm,PetscSection *); 24ea844a1aSMatthew Knepley $ PetscSectionSetNumFields(PetscSection, numFields); 25ea844a1aSMatthew Knepley $ PetscSectionSetChart(PetscSection,low,high); 26ea844a1aSMatthew Knepley $ PetscSectionSetDof(PetscSection,point,numdof); 27ea844a1aSMatthew Knepley $ PetscSectionSetUp(PetscSection); 28ea844a1aSMatthew Knepley $ PetscSectionGetOffset(PetscSection,point,PetscInt *); 29ea844a1aSMatthew Knepley $ PetscSectionDestroy(PetscSection); 30ea844a1aSMatthew Knepley 316aad120cSJose E. Roman The PetscSection object and methods are intended to be used in the PETSc Vec and Mat implementations; it is 32ea844a1aSMatthew Knepley recommended they not be used in user codes unless you really gain something in their use. 33ea844a1aSMatthew Knepley 34db781477SPatrick Sanan .seealso: `PetscSection`, `PetscSectionDestroy()` 35ea844a1aSMatthew Knepley @*/ 36*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreate(MPI_Comm comm, PetscSection *s) 37*d71ae5a4SJacob Faibussowitsch { 38ea844a1aSMatthew Knepley PetscFunctionBegin; 39ea844a1aSMatthew Knepley PetscValidPointer(s, 2); 409566063dSJacob Faibussowitsch PetscCall(ISInitializePackage()); 41ea844a1aSMatthew Knepley 429566063dSJacob Faibussowitsch PetscCall(PetscHeaderCreate(*s, PETSC_SECTION_CLASSID, "PetscSection", "Section", "IS", comm, PetscSectionDestroy, PetscSectionView)); 43ea844a1aSMatthew Knepley 44ea844a1aSMatthew Knepley (*s)->pStart = -1; 45ea844a1aSMatthew Knepley (*s)->pEnd = -1; 46ea844a1aSMatthew Knepley (*s)->perm = NULL; 47ea844a1aSMatthew Knepley (*s)->pointMajor = PETSC_TRUE; 4887e637c6Sksagiyam (*s)->includesConstraints = PETSC_TRUE; 49ea844a1aSMatthew Knepley (*s)->atlasDof = NULL; 50ea844a1aSMatthew Knepley (*s)->atlasOff = NULL; 51ea844a1aSMatthew Knepley (*s)->bc = NULL; 52ea844a1aSMatthew Knepley (*s)->bcIndices = NULL; 53ea844a1aSMatthew Knepley (*s)->setup = PETSC_FALSE; 54ea844a1aSMatthew Knepley (*s)->numFields = 0; 55ea844a1aSMatthew Knepley (*s)->fieldNames = NULL; 56ea844a1aSMatthew Knepley (*s)->field = NULL; 57ea844a1aSMatthew Knepley (*s)->useFieldOff = PETSC_FALSE; 58b778fa18SValeria Barra (*s)->compNames = NULL; 59ea844a1aSMatthew Knepley (*s)->clObj = NULL; 60c459fbc1SJed Brown (*s)->clHash = NULL; 61ea844a1aSMatthew Knepley (*s)->clSection = NULL; 62ea844a1aSMatthew Knepley (*s)->clPoints = NULL; 6369c11d05SVaclav Hapla PetscCall(PetscSectionInvalidateMaxDof_Internal(*s)); 64ea844a1aSMatthew Knepley PetscFunctionReturn(0); 65ea844a1aSMatthew Knepley } 66ea844a1aSMatthew Knepley 67ea844a1aSMatthew Knepley /*@ 68ea844a1aSMatthew Knepley PetscSectionCopy - Creates a shallow (if possible) copy of the PetscSection 69ea844a1aSMatthew Knepley 70ea844a1aSMatthew Knepley Collective 71ea844a1aSMatthew Knepley 72ea844a1aSMatthew Knepley Input Parameter: 73ea844a1aSMatthew Knepley . section - the PetscSection 74ea844a1aSMatthew Knepley 75ea844a1aSMatthew Knepley Output Parameter: 76ea844a1aSMatthew Knepley . newSection - the copy 77ea844a1aSMatthew Knepley 78ea844a1aSMatthew Knepley Level: intermediate 79ea844a1aSMatthew Knepley 80db781477SPatrick Sanan .seealso: `PetscSection`, `PetscSectionCreate()`, `PetscSectionDestroy()` 81ea844a1aSMatthew Knepley @*/ 82*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCopy(PetscSection section, PetscSection newSection) 83*d71ae5a4SJacob Faibussowitsch { 84ea844a1aSMatthew Knepley PetscSectionSym sym; 85ea844a1aSMatthew Knepley IS perm; 86b778fa18SValeria Barra PetscInt numFields, f, c, pStart, pEnd, p; 87ea844a1aSMatthew Knepley 88ea844a1aSMatthew Knepley PetscFunctionBegin; 89ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 90ea844a1aSMatthew Knepley PetscValidHeaderSpecific(newSection, PETSC_SECTION_CLASSID, 2); 919566063dSJacob Faibussowitsch PetscCall(PetscSectionReset(newSection)); 929566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(section, &numFields)); 939566063dSJacob Faibussowitsch if (numFields) PetscCall(PetscSectionSetNumFields(newSection, numFields)); 94ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 95b778fa18SValeria Barra const char *fieldName = NULL, *compName = NULL; 96ea844a1aSMatthew Knepley PetscInt numComp = 0; 97ea844a1aSMatthew Knepley 989566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldName(section, f, &fieldName)); 999566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldName(newSection, f, fieldName)); 1009566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(section, f, &numComp)); 1019566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(newSection, f, numComp)); 102b778fa18SValeria Barra for (c = 0; c < numComp; ++c) { 1039566063dSJacob Faibussowitsch PetscCall(PetscSectionGetComponentName(section, f, c, &compName)); 1049566063dSJacob Faibussowitsch PetscCall(PetscSectionSetComponentName(newSection, f, c, compName)); 105b778fa18SValeria Barra } 1069566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldSym(section, f, &sym)); 1079566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldSym(newSection, f, sym)); 108ea844a1aSMatthew Knepley } 1099566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(section, &pStart, &pEnd)); 1109566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(newSection, pStart, pEnd)); 1119566063dSJacob Faibussowitsch PetscCall(PetscSectionGetPermutation(section, &perm)); 1129566063dSJacob Faibussowitsch PetscCall(PetscSectionSetPermutation(newSection, perm)); 1139566063dSJacob Faibussowitsch PetscCall(PetscSectionGetSym(section, &sym)); 1149566063dSJacob Faibussowitsch PetscCall(PetscSectionSetSym(newSection, sym)); 115ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 116ea844a1aSMatthew Knepley PetscInt dof, cdof, fcdof = 0; 117ea844a1aSMatthew Knepley 1189566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(section, p, &dof)); 1199566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(newSection, p, dof)); 1209566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(section, p, &cdof)); 1219566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetConstraintDof(newSection, p, cdof)); 122ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 1239566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(section, p, f, &dof)); 1249566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldDof(newSection, p, f, dof)); 125ea844a1aSMatthew Knepley if (cdof) { 1269566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(section, p, f, &fcdof)); 1279566063dSJacob Faibussowitsch if (fcdof) PetscCall(PetscSectionSetFieldConstraintDof(newSection, p, f, fcdof)); 128ea844a1aSMatthew Knepley } 129ea844a1aSMatthew Knepley } 130ea844a1aSMatthew Knepley } 1319566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(newSection)); 132ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 133ea844a1aSMatthew Knepley PetscInt off, cdof, fcdof = 0; 134ea844a1aSMatthew Knepley const PetscInt *cInd; 135ea844a1aSMatthew Knepley 136ea844a1aSMatthew Knepley /* Must set offsets in case they do not agree with the prefix sums */ 1379566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(section, p, &off)); 1389566063dSJacob Faibussowitsch PetscCall(PetscSectionSetOffset(newSection, p, off)); 1399566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(section, p, &cdof)); 140ea844a1aSMatthew Knepley if (cdof) { 1419566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(section, p, &cInd)); 1429566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(newSection, p, cInd)); 143ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 1449566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(section, p, f, &fcdof)); 145ea844a1aSMatthew Knepley if (fcdof) { 1469566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(section, p, f, &cInd)); 1479566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldConstraintIndices(newSection, p, f, cInd)); 148ea844a1aSMatthew Knepley } 149ea844a1aSMatthew Knepley } 150ea844a1aSMatthew Knepley } 151ea844a1aSMatthew Knepley } 152ea844a1aSMatthew Knepley PetscFunctionReturn(0); 153ea844a1aSMatthew Knepley } 154ea844a1aSMatthew Knepley 155ea844a1aSMatthew Knepley /*@ 156ea844a1aSMatthew Knepley PetscSectionClone - Creates a shallow (if possible) copy of the PetscSection 157ea844a1aSMatthew Knepley 158ea844a1aSMatthew Knepley Collective 159ea844a1aSMatthew Knepley 160ea844a1aSMatthew Knepley Input Parameter: 161ea844a1aSMatthew Knepley . section - the PetscSection 162ea844a1aSMatthew Knepley 163ea844a1aSMatthew Knepley Output Parameter: 164ea844a1aSMatthew Knepley . newSection - the copy 165ea844a1aSMatthew Knepley 166ea844a1aSMatthew Knepley Level: beginner 167ea844a1aSMatthew Knepley 168db781477SPatrick Sanan .seealso: `PetscSection`, `PetscSectionCreate()`, `PetscSectionDestroy()` 169ea844a1aSMatthew Knepley @*/ 170*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionClone(PetscSection section, PetscSection *newSection) 171*d71ae5a4SJacob Faibussowitsch { 172ea844a1aSMatthew Knepley PetscFunctionBegin; 173ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 174ea844a1aSMatthew Knepley PetscValidPointer(newSection, 2); 1759566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)section), newSection)); 1769566063dSJacob Faibussowitsch PetscCall(PetscSectionCopy(section, *newSection)); 177ea844a1aSMatthew Knepley PetscFunctionReturn(0); 178ea844a1aSMatthew Knepley } 179ea844a1aSMatthew Knepley 180ea844a1aSMatthew Knepley /*@ 181ea844a1aSMatthew Knepley PetscSectionSetFromOptions - sets parameters in a PetscSection from the options database 182ea844a1aSMatthew Knepley 18340750d41SVaclav Hapla Collective 184ea844a1aSMatthew Knepley 185ea844a1aSMatthew Knepley Input Parameter: 186ea844a1aSMatthew Knepley . section - the PetscSection 187ea844a1aSMatthew Knepley 188ea844a1aSMatthew Knepley Options Database: 189147403d9SBarry Smith . -petscsection_point_major - PETSC_TRUE for point-major order 190ea844a1aSMatthew Knepley 191ea844a1aSMatthew Knepley Level: intermediate 192ea844a1aSMatthew Knepley 193db781477SPatrick Sanan .seealso: `PetscSection`, `PetscSectionCreate()`, `PetscSectionDestroy()` 194ea844a1aSMatthew Knepley @*/ 195*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFromOptions(PetscSection s) 196*d71ae5a4SJacob Faibussowitsch { 197ea844a1aSMatthew Knepley PetscFunctionBegin; 198ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 199d0609cedSBarry Smith PetscObjectOptionsBegin((PetscObject)s); 2009566063dSJacob Faibussowitsch PetscCall(PetscOptionsBool("-petscsection_point_major", "The for ordering, either point major or field major", "PetscSectionSetPointMajor", s->pointMajor, &s->pointMajor, NULL)); 201ea844a1aSMatthew Knepley /* process any options handlers added with PetscObjectAddOptionsHandler() */ 202dbbe0bcdSBarry Smith PetscCall(PetscObjectProcessOptionsHandlers((PetscObject)s, PetscOptionsObject)); 203d0609cedSBarry Smith PetscOptionsEnd(); 2049566063dSJacob Faibussowitsch PetscCall(PetscObjectViewFromOptions((PetscObject)s, NULL, "-petscsection_view")); 205ea844a1aSMatthew Knepley PetscFunctionReturn(0); 206ea844a1aSMatthew Knepley } 207ea844a1aSMatthew Knepley 208ea844a1aSMatthew Knepley /*@ 209ea844a1aSMatthew Knepley PetscSectionCompare - Compares two sections 210ea844a1aSMatthew Knepley 21140750d41SVaclav Hapla Collective 212ea844a1aSMatthew Knepley 2137a7aea1fSJed Brown Input Parameters: 214ea844a1aSMatthew Knepley + s1 - the first PetscSection 215ea844a1aSMatthew Knepley - s2 - the second PetscSection 216ea844a1aSMatthew Knepley 217ea844a1aSMatthew Knepley Output Parameter: 218ea844a1aSMatthew Knepley . congruent - PETSC_TRUE if the two sections are congruent, PETSC_FALSE otherwise 219ea844a1aSMatthew Knepley 220ea844a1aSMatthew Knepley Level: intermediate 221ea844a1aSMatthew Knepley 222ea844a1aSMatthew Knepley Notes: 223ea844a1aSMatthew Knepley Field names are disregarded. 224ea844a1aSMatthew Knepley 225db781477SPatrick Sanan .seealso: `PetscSection`, `PetscSectionCreate()`, `PetscSectionCopy()`, `PetscSectionClone()` 226ea844a1aSMatthew Knepley @*/ 227*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCompare(PetscSection s1, PetscSection s2, PetscBool *congruent) 228*d71ae5a4SJacob Faibussowitsch { 229ea844a1aSMatthew Knepley PetscInt pStart, pEnd, nfields, ncdof, nfcdof, p, f, n1, n2; 230ea844a1aSMatthew Knepley const PetscInt *idx1, *idx2; 231ea844a1aSMatthew Knepley IS perm1, perm2; 232ea844a1aSMatthew Knepley PetscBool flg; 233ea844a1aSMatthew Knepley PetscMPIInt mflg; 234ea844a1aSMatthew Knepley 235ea844a1aSMatthew Knepley PetscFunctionBegin; 236ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s1, PETSC_SECTION_CLASSID, 1); 237ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s2, PETSC_SECTION_CLASSID, 2); 238064a246eSJacob Faibussowitsch PetscValidBoolPointer(congruent, 3); 239ea844a1aSMatthew Knepley flg = PETSC_FALSE; 240ea844a1aSMatthew Knepley 2419566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_compare(PetscObjectComm((PetscObject)s1), PetscObjectComm((PetscObject)s2), &mflg)); 242ea844a1aSMatthew Knepley if (mflg != MPI_CONGRUENT && mflg != MPI_IDENT) { 243ea844a1aSMatthew Knepley *congruent = PETSC_FALSE; 244ea844a1aSMatthew Knepley PetscFunctionReturn(0); 245ea844a1aSMatthew Knepley } 246ea844a1aSMatthew Knepley 2479566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s1, &pStart, &pEnd)); 2489566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s2, &n1, &n2)); 249ea844a1aSMatthew Knepley if (pStart != n1 || pEnd != n2) goto not_congruent; 250ea844a1aSMatthew Knepley 2519566063dSJacob Faibussowitsch PetscCall(PetscSectionGetPermutation(s1, &perm1)); 2529566063dSJacob Faibussowitsch PetscCall(PetscSectionGetPermutation(s2, &perm2)); 253ea844a1aSMatthew Knepley if (perm1 && perm2) { 2549566063dSJacob Faibussowitsch PetscCall(ISEqual(perm1, perm2, congruent)); 255ea844a1aSMatthew Knepley if (!(*congruent)) goto not_congruent; 256ea844a1aSMatthew Knepley } else if (perm1 != perm2) goto not_congruent; 257ea844a1aSMatthew Knepley 258ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2599566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s1, p, &n1)); 2609566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s2, p, &n2)); 261ea844a1aSMatthew Knepley if (n1 != n2) goto not_congruent; 262ea844a1aSMatthew Knepley 2639566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s1, p, &n1)); 2649566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s2, p, &n2)); 265ea844a1aSMatthew Knepley if (n1 != n2) goto not_congruent; 266ea844a1aSMatthew Knepley 2679566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s1, p, &ncdof)); 2689566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s2, p, &n2)); 269ea844a1aSMatthew Knepley if (ncdof != n2) goto not_congruent; 270ea844a1aSMatthew Knepley 2719566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s1, p, &idx1)); 2729566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s2, p, &idx2)); 2739566063dSJacob Faibussowitsch PetscCall(PetscArraycmp(idx1, idx2, ncdof, congruent)); 274ea844a1aSMatthew Knepley if (!(*congruent)) goto not_congruent; 275ea844a1aSMatthew Knepley } 276ea844a1aSMatthew Knepley 2779566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s1, &nfields)); 2789566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s2, &n2)); 279ea844a1aSMatthew Knepley if (nfields != n2) goto not_congruent; 280ea844a1aSMatthew Knepley 281ea844a1aSMatthew Knepley for (f = 0; f < nfields; ++f) { 2829566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s1, f, &n1)); 2839566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s2, f, &n2)); 284ea844a1aSMatthew Knepley if (n1 != n2) goto not_congruent; 285ea844a1aSMatthew Knepley 286ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2879566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldOffset(s1, p, f, &n1)); 2889566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldOffset(s2, p, f, &n2)); 289ea844a1aSMatthew Knepley if (n1 != n2) goto not_congruent; 290ea844a1aSMatthew Knepley 2919566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s1, p, f, &n1)); 2929566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s2, p, f, &n2)); 293ea844a1aSMatthew Knepley if (n1 != n2) goto not_congruent; 294ea844a1aSMatthew Knepley 2959566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s1, p, f, &nfcdof)); 2969566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s2, p, f, &n2)); 297ea844a1aSMatthew Knepley if (nfcdof != n2) goto not_congruent; 298ea844a1aSMatthew Knepley 2999566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(s1, p, f, &idx1)); 3009566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(s2, p, f, &idx2)); 3019566063dSJacob Faibussowitsch PetscCall(PetscArraycmp(idx1, idx2, nfcdof, congruent)); 302ea844a1aSMatthew Knepley if (!(*congruent)) goto not_congruent; 303ea844a1aSMatthew Knepley } 304ea844a1aSMatthew Knepley } 305ea844a1aSMatthew Knepley 306ea844a1aSMatthew Knepley flg = PETSC_TRUE; 307ea844a1aSMatthew Knepley not_congruent: 3081c2dc1cbSBarry Smith PetscCall(MPIU_Allreduce(&flg, congruent, 1, MPIU_BOOL, MPI_LAND, PetscObjectComm((PetscObject)s1))); 309ea844a1aSMatthew Knepley PetscFunctionReturn(0); 310ea844a1aSMatthew Knepley } 311ea844a1aSMatthew Knepley 312ea844a1aSMatthew Knepley /*@ 313ea844a1aSMatthew Knepley PetscSectionGetNumFields - Returns the number of fields, or 0 if no fields were defined. 314ea844a1aSMatthew Knepley 31540750d41SVaclav Hapla Not Collective 316ea844a1aSMatthew Knepley 317ea844a1aSMatthew Knepley Input Parameter: 318ea844a1aSMatthew Knepley . s - the PetscSection 319ea844a1aSMatthew Knepley 320ea844a1aSMatthew Knepley Output Parameter: 321ea844a1aSMatthew Knepley . numFields - the number of fields defined, or 0 if none were defined 322ea844a1aSMatthew Knepley 323ea844a1aSMatthew Knepley Level: intermediate 324ea844a1aSMatthew Knepley 325db781477SPatrick Sanan .seealso: `PetscSectionSetNumFields()` 326ea844a1aSMatthew Knepley @*/ 327*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetNumFields(PetscSection s, PetscInt *numFields) 328*d71ae5a4SJacob Faibussowitsch { 329ea844a1aSMatthew Knepley PetscFunctionBegin; 330ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 331dadcf809SJacob Faibussowitsch PetscValidIntPointer(numFields, 2); 332ea844a1aSMatthew Knepley *numFields = s->numFields; 333ea844a1aSMatthew Knepley PetscFunctionReturn(0); 334ea844a1aSMatthew Knepley } 335ea844a1aSMatthew Knepley 336ea844a1aSMatthew Knepley /*@ 337ea844a1aSMatthew Knepley PetscSectionSetNumFields - Sets the number of fields. 338ea844a1aSMatthew Knepley 33940750d41SVaclav Hapla Not Collective 340ea844a1aSMatthew Knepley 341ea844a1aSMatthew Knepley Input Parameters: 342ea844a1aSMatthew Knepley + s - the PetscSection 343ea844a1aSMatthew Knepley - numFields - the number of fields 344ea844a1aSMatthew Knepley 345ea844a1aSMatthew Knepley Level: intermediate 346ea844a1aSMatthew Knepley 347db781477SPatrick Sanan .seealso: `PetscSectionGetNumFields()` 348ea844a1aSMatthew Knepley @*/ 349*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetNumFields(PetscSection s, PetscInt numFields) 350*d71ae5a4SJacob Faibussowitsch { 351ea844a1aSMatthew Knepley PetscInt f; 352ea844a1aSMatthew Knepley 353ea844a1aSMatthew Knepley PetscFunctionBegin; 354ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 35508401ef6SPierre Jolivet PetscCheck(numFields > 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "The number of fields %" PetscInt_FMT " must be positive", numFields); 3569566063dSJacob Faibussowitsch PetscCall(PetscSectionReset(s)); 357ea844a1aSMatthew Knepley 358ea844a1aSMatthew Knepley s->numFields = numFields; 3599566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(s->numFields, &s->numFieldComponents)); 3609566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(s->numFields, &s->fieldNames)); 3619566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(s->numFields, &s->compNames)); 3629566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(s->numFields, &s->field)); 363ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) { 364ea844a1aSMatthew Knepley char name[64]; 365ea844a1aSMatthew Knepley 366ea844a1aSMatthew Knepley s->numFieldComponents[f] = 1; 367ea844a1aSMatthew Knepley 3689566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), &s->field[f])); 3699566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(name, 64, "Field_%" PetscInt_FMT, f)); 3709566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, (char **)&s->fieldNames[f])); 3719566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(name, 64, "Component_0")); 3729566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(s->numFieldComponents[f], &s->compNames[f])); 3739566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, (char **)&s->compNames[f][0])); 374ea844a1aSMatthew Knepley } 375ea844a1aSMatthew Knepley PetscFunctionReturn(0); 376ea844a1aSMatthew Knepley } 377ea844a1aSMatthew Knepley 378ea844a1aSMatthew Knepley /*@C 379ea844a1aSMatthew Knepley PetscSectionGetFieldName - Returns the name of a field in the PetscSection 380ea844a1aSMatthew Knepley 381ea844a1aSMatthew Knepley Not Collective 382ea844a1aSMatthew Knepley 383ea844a1aSMatthew Knepley Input Parameters: 384ea844a1aSMatthew Knepley + s - the PetscSection 385ea844a1aSMatthew Knepley - field - the field number 386ea844a1aSMatthew Knepley 387ea844a1aSMatthew Knepley Output Parameter: 388ea844a1aSMatthew Knepley . fieldName - the field name 389ea844a1aSMatthew Knepley 390ea844a1aSMatthew Knepley Level: intermediate 391ea844a1aSMatthew Knepley 392db781477SPatrick Sanan .seealso: `PetscSectionSetFieldName()` 393ea844a1aSMatthew Knepley @*/ 394*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldName(PetscSection s, PetscInt field, const char *fieldName[]) 395*d71ae5a4SJacob Faibussowitsch { 396ea844a1aSMatthew Knepley PetscFunctionBegin; 397ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 398ea844a1aSMatthew Knepley PetscValidPointer(fieldName, 3); 3992abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 400ea844a1aSMatthew Knepley *fieldName = s->fieldNames[field]; 401ea844a1aSMatthew Knepley PetscFunctionReturn(0); 402ea844a1aSMatthew Knepley } 403ea844a1aSMatthew Knepley 404ea844a1aSMatthew Knepley /*@C 405ea844a1aSMatthew Knepley PetscSectionSetFieldName - Sets the name of a field in the PetscSection 406ea844a1aSMatthew Knepley 407ea844a1aSMatthew Knepley Not Collective 408ea844a1aSMatthew Knepley 409ea844a1aSMatthew Knepley Input Parameters: 410ea844a1aSMatthew Knepley + s - the PetscSection 411ea844a1aSMatthew Knepley . field - the field number 412ea844a1aSMatthew Knepley - fieldName - the field name 413ea844a1aSMatthew Knepley 414ea844a1aSMatthew Knepley Level: intermediate 415ea844a1aSMatthew Knepley 416db781477SPatrick Sanan .seealso: `PetscSectionGetFieldName()` 417ea844a1aSMatthew Knepley @*/ 418*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldName(PetscSection s, PetscInt field, const char fieldName[]) 419*d71ae5a4SJacob Faibussowitsch { 420ea844a1aSMatthew Knepley PetscFunctionBegin; 421ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 422ea844a1aSMatthew Knepley if (fieldName) PetscValidCharPointer(fieldName, 3); 4232abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 4249566063dSJacob Faibussowitsch PetscCall(PetscFree(s->fieldNames[field])); 4259566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(fieldName, (char **)&s->fieldNames[field])); 426ea844a1aSMatthew Knepley PetscFunctionReturn(0); 427ea844a1aSMatthew Knepley } 428ea844a1aSMatthew Knepley 429b778fa18SValeria Barra /*@C 430b778fa18SValeria Barra PetscSectionGetComponentName - Gets the name of a field component in the PetscSection 431b778fa18SValeria Barra 432b778fa18SValeria Barra Not Collective 433b778fa18SValeria Barra 434b778fa18SValeria Barra Input Parameters: 435b778fa18SValeria Barra + s - the PetscSection 436b778fa18SValeria Barra . field - the field number 437b778fa18SValeria Barra . comp - the component number 438b778fa18SValeria Barra - compName - the component name 439b778fa18SValeria Barra 440b778fa18SValeria Barra Level: intermediate 441b778fa18SValeria Barra 442db781477SPatrick Sanan .seealso: `PetscSectionSetComponentName()` 443b778fa18SValeria Barra @*/ 444*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetComponentName(PetscSection s, PetscInt field, PetscInt comp, const char *compName[]) 445*d71ae5a4SJacob Faibussowitsch { 446b778fa18SValeria Barra PetscFunctionBegin; 447b778fa18SValeria Barra PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 448064a246eSJacob Faibussowitsch PetscValidPointer(compName, 4); 4492abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 4502abc8c78SJacob Faibussowitsch PetscSectionCheckValidFieldComponent(comp, s->numFieldComponents[field]); 451b778fa18SValeria Barra *compName = s->compNames[field][comp]; 452b778fa18SValeria Barra PetscFunctionReturn(0); 453b778fa18SValeria Barra } 454b778fa18SValeria Barra 455b778fa18SValeria Barra /*@C 456b778fa18SValeria Barra PetscSectionSetComponentName - Sets the name of a field component in the PetscSection 457b778fa18SValeria Barra 458b778fa18SValeria Barra Not Collective 459b778fa18SValeria Barra 460b778fa18SValeria Barra Input Parameters: 461b778fa18SValeria Barra + s - the PetscSection 462b778fa18SValeria Barra . field - the field number 463b778fa18SValeria Barra . comp - the component number 464b778fa18SValeria Barra - compName - the component name 465b778fa18SValeria Barra 466b778fa18SValeria Barra Level: intermediate 467b778fa18SValeria Barra 468db781477SPatrick Sanan .seealso: `PetscSectionGetComponentName()` 469b778fa18SValeria Barra @*/ 470*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetComponentName(PetscSection s, PetscInt field, PetscInt comp, const char compName[]) 471*d71ae5a4SJacob Faibussowitsch { 472b778fa18SValeria Barra PetscFunctionBegin; 473b778fa18SValeria Barra PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 474064a246eSJacob Faibussowitsch if (compName) PetscValidCharPointer(compName, 4); 4752abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 4762abc8c78SJacob Faibussowitsch PetscSectionCheckValidFieldComponent(comp, s->numFieldComponents[field]); 4779566063dSJacob Faibussowitsch PetscCall(PetscFree(s->compNames[field][comp])); 4789566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(compName, (char **)&s->compNames[field][comp])); 479b778fa18SValeria Barra PetscFunctionReturn(0); 480b778fa18SValeria Barra } 481b778fa18SValeria Barra 482ea844a1aSMatthew Knepley /*@ 483ea844a1aSMatthew Knepley PetscSectionGetFieldComponents - Returns the number of field components for the given field. 484ea844a1aSMatthew Knepley 48540750d41SVaclav Hapla Not Collective 486ea844a1aSMatthew Knepley 487ea844a1aSMatthew Knepley Input Parameters: 488ea844a1aSMatthew Knepley + s - the PetscSection 489ea844a1aSMatthew Knepley - field - the field number 490ea844a1aSMatthew Knepley 491ea844a1aSMatthew Knepley Output Parameter: 492ea844a1aSMatthew Knepley . numComp - the number of field components 493ea844a1aSMatthew Knepley 494ea844a1aSMatthew Knepley Level: intermediate 495ea844a1aSMatthew Knepley 496db781477SPatrick Sanan .seealso: `PetscSectionSetFieldComponents()`, `PetscSectionGetNumFields()` 497ea844a1aSMatthew Knepley @*/ 498*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldComponents(PetscSection s, PetscInt field, PetscInt *numComp) 499*d71ae5a4SJacob Faibussowitsch { 500ea844a1aSMatthew Knepley PetscFunctionBegin; 501ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 5022abc8c78SJacob Faibussowitsch PetscValidIntPointer(numComp, 3); 5032abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 504ea844a1aSMatthew Knepley *numComp = s->numFieldComponents[field]; 505ea844a1aSMatthew Knepley PetscFunctionReturn(0); 506ea844a1aSMatthew Knepley } 507ea844a1aSMatthew Knepley 508ea844a1aSMatthew Knepley /*@ 509ea844a1aSMatthew Knepley PetscSectionSetFieldComponents - Sets the number of field components for the given field. 510ea844a1aSMatthew Knepley 51140750d41SVaclav Hapla Not Collective 512ea844a1aSMatthew Knepley 513ea844a1aSMatthew Knepley Input Parameters: 514ea844a1aSMatthew Knepley + s - the PetscSection 515ea844a1aSMatthew Knepley . field - the field number 516ea844a1aSMatthew Knepley - numComp - the number of field components 517ea844a1aSMatthew Knepley 518ea844a1aSMatthew Knepley Level: intermediate 519ea844a1aSMatthew Knepley 520db781477SPatrick Sanan .seealso: `PetscSectionGetFieldComponents()`, `PetscSectionGetNumFields()` 521ea844a1aSMatthew Knepley @*/ 522*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldComponents(PetscSection s, PetscInt field, PetscInt numComp) 523*d71ae5a4SJacob Faibussowitsch { 524b778fa18SValeria Barra PetscInt c; 525b778fa18SValeria Barra 526ea844a1aSMatthew Knepley PetscFunctionBegin; 527ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 5282abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 529b778fa18SValeria Barra if (s->compNames) { 53048a46eb9SPierre Jolivet for (c = 0; c < s->numFieldComponents[field]; ++c) PetscCall(PetscFree(s->compNames[field][c])); 5319566063dSJacob Faibussowitsch PetscCall(PetscFree(s->compNames[field])); 532b778fa18SValeria Barra } 533b778fa18SValeria Barra 534ea844a1aSMatthew Knepley s->numFieldComponents[field] = numComp; 535b778fa18SValeria Barra if (numComp) { 5369566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(numComp, (char ***)&s->compNames[field])); 537b778fa18SValeria Barra for (c = 0; c < numComp; ++c) { 5382abc8c78SJacob Faibussowitsch char name[64]; 5392abc8c78SJacob Faibussowitsch 5409566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(name, 64, "%" PetscInt_FMT, c)); 5419566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, (char **)&s->compNames[field][c])); 542b778fa18SValeria Barra } 543b778fa18SValeria Barra } 544ea844a1aSMatthew Knepley PetscFunctionReturn(0); 545ea844a1aSMatthew Knepley } 546ea844a1aSMatthew Knepley 547ea844a1aSMatthew Knepley /*@ 548ea844a1aSMatthew Knepley PetscSectionGetChart - Returns the range [pStart, pEnd) in which points lie. 549ea844a1aSMatthew Knepley 55040750d41SVaclav Hapla Not Collective 551ea844a1aSMatthew Knepley 552ea844a1aSMatthew Knepley Input Parameter: 553ea844a1aSMatthew Knepley . s - the PetscSection 554ea844a1aSMatthew Knepley 555ea844a1aSMatthew Knepley Output Parameters: 556ea844a1aSMatthew Knepley + pStart - the first point 557ea844a1aSMatthew Knepley - pEnd - one past the last point 558ea844a1aSMatthew Knepley 559ea844a1aSMatthew Knepley Level: intermediate 560ea844a1aSMatthew Knepley 561db781477SPatrick Sanan .seealso: `PetscSectionSetChart()`, `PetscSectionCreate()` 562ea844a1aSMatthew Knepley @*/ 563*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetChart(PetscSection s, PetscInt *pStart, PetscInt *pEnd) 564*d71ae5a4SJacob Faibussowitsch { 565ea844a1aSMatthew Knepley PetscFunctionBegin; 566ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 567ea844a1aSMatthew Knepley if (pStart) *pStart = s->pStart; 568ea844a1aSMatthew Knepley if (pEnd) *pEnd = s->pEnd; 569ea844a1aSMatthew Knepley PetscFunctionReturn(0); 570ea844a1aSMatthew Knepley } 571ea844a1aSMatthew Knepley 572ea844a1aSMatthew Knepley /*@ 573ea844a1aSMatthew Knepley PetscSectionSetChart - Sets the range [pStart, pEnd) in which points lie. 574ea844a1aSMatthew Knepley 57540750d41SVaclav Hapla Not Collective 576ea844a1aSMatthew Knepley 577ea844a1aSMatthew Knepley Input Parameters: 578ea844a1aSMatthew Knepley + s - the PetscSection 579ea844a1aSMatthew Knepley . pStart - the first point 580ea844a1aSMatthew Knepley - pEnd - one past the last point 581ea844a1aSMatthew Knepley 582ea844a1aSMatthew Knepley Level: intermediate 583ea844a1aSMatthew Knepley 584db781477SPatrick Sanan .seealso: `PetscSectionGetChart()`, `PetscSectionCreate()` 585ea844a1aSMatthew Knepley @*/ 586*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetChart(PetscSection s, PetscInt pStart, PetscInt pEnd) 587*d71ae5a4SJacob Faibussowitsch { 588ea844a1aSMatthew Knepley PetscInt f; 589ea844a1aSMatthew Knepley 590ea844a1aSMatthew Knepley PetscFunctionBegin; 591ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 5929318fe57SMatthew G. Knepley if (pStart == s->pStart && pEnd == s->pEnd) PetscFunctionReturn(0); 593ea844a1aSMatthew Knepley /* Cannot Reset() because it destroys field information */ 594ea844a1aSMatthew Knepley s->setup = PETSC_FALSE; 5959566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->bc)); 5969566063dSJacob Faibussowitsch PetscCall(PetscFree(s->bcIndices)); 5979566063dSJacob Faibussowitsch PetscCall(PetscFree2(s->atlasDof, s->atlasOff)); 598ea844a1aSMatthew Knepley 599ea844a1aSMatthew Knepley s->pStart = pStart; 600ea844a1aSMatthew Knepley s->pEnd = pEnd; 6019566063dSJacob Faibussowitsch PetscCall(PetscMalloc2((pEnd - pStart), &s->atlasDof, (pEnd - pStart), &s->atlasOff)); 6029566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(s->atlasDof, pEnd - pStart)); 60348a46eb9SPierre Jolivet for (f = 0; f < s->numFields; ++f) PetscCall(PetscSectionSetChart(s->field[f], pStart, pEnd)); 604ea844a1aSMatthew Knepley PetscFunctionReturn(0); 605ea844a1aSMatthew Knepley } 606ea844a1aSMatthew Knepley 607ea844a1aSMatthew Knepley /*@ 608ea844a1aSMatthew Knepley PetscSectionGetPermutation - Returns the permutation of [0, pEnd-pStart) or NULL 609ea844a1aSMatthew Knepley 61040750d41SVaclav Hapla Not Collective 611ea844a1aSMatthew Knepley 612ea844a1aSMatthew Knepley Input Parameter: 613ea844a1aSMatthew Knepley . s - the PetscSection 614ea844a1aSMatthew Knepley 615ea844a1aSMatthew Knepley Output Parameters: 616ea844a1aSMatthew Knepley . perm - The permutation as an IS 617ea844a1aSMatthew Knepley 618ea844a1aSMatthew Knepley Level: intermediate 619ea844a1aSMatthew Knepley 620db781477SPatrick Sanan .seealso: `PetscSectionSetPermutation()`, `PetscSectionCreate()` 621ea844a1aSMatthew Knepley @*/ 622*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetPermutation(PetscSection s, IS *perm) 623*d71ae5a4SJacob Faibussowitsch { 624ea844a1aSMatthew Knepley PetscFunctionBegin; 625ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 6269371c9d4SSatish Balay if (perm) { 6279371c9d4SSatish Balay PetscValidPointer(perm, 2); 6289371c9d4SSatish Balay *perm = s->perm; 6299371c9d4SSatish Balay } 630ea844a1aSMatthew Knepley PetscFunctionReturn(0); 631ea844a1aSMatthew Knepley } 632ea844a1aSMatthew Knepley 633ea844a1aSMatthew Knepley /*@ 634ea844a1aSMatthew Knepley PetscSectionSetPermutation - Sets the permutation for [0, pEnd-pStart) 635ea844a1aSMatthew Knepley 63640750d41SVaclav Hapla Not Collective 637ea844a1aSMatthew Knepley 638ea844a1aSMatthew Knepley Input Parameters: 639ea844a1aSMatthew Knepley + s - the PetscSection 640ea844a1aSMatthew Knepley - perm - the permutation of points 641ea844a1aSMatthew Knepley 642ea844a1aSMatthew Knepley Level: intermediate 643ea844a1aSMatthew Knepley 644db781477SPatrick Sanan .seealso: `PetscSectionGetPermutation()`, `PetscSectionCreate()` 645ea844a1aSMatthew Knepley @*/ 646*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetPermutation(PetscSection s, IS perm) 647*d71ae5a4SJacob Faibussowitsch { 648ea844a1aSMatthew Knepley PetscFunctionBegin; 649ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 650ea844a1aSMatthew Knepley if (perm) PetscValidHeaderSpecific(perm, IS_CLASSID, 2); 65128b400f6SJacob Faibussowitsch PetscCheck(!s->setup, PetscObjectComm((PetscObject)s), PETSC_ERR_ARG_WRONGSTATE, "Cannot set a permutation after the section is setup"); 652ea844a1aSMatthew Knepley if (s->perm != perm) { 6539566063dSJacob Faibussowitsch PetscCall(ISDestroy(&s->perm)); 654ea844a1aSMatthew Knepley if (perm) { 655ea844a1aSMatthew Knepley s->perm = perm; 6569566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)s->perm)); 657ea844a1aSMatthew Knepley } 658ea844a1aSMatthew Knepley } 659ea844a1aSMatthew Knepley PetscFunctionReturn(0); 660ea844a1aSMatthew Knepley } 661ea844a1aSMatthew Knepley 662ea844a1aSMatthew Knepley /*@ 663ea844a1aSMatthew Knepley PetscSectionGetPointMajor - Returns the flag for dof ordering, true if it is point major, otherwise field major 664ea844a1aSMatthew Knepley 66540750d41SVaclav Hapla Not Collective 666ea844a1aSMatthew Knepley 667ea844a1aSMatthew Knepley Input Parameter: 668ea844a1aSMatthew Knepley . s - the PetscSection 669ea844a1aSMatthew Knepley 670ea844a1aSMatthew Knepley Output Parameter: 671ea844a1aSMatthew Knepley . pm - the flag for point major ordering 672ea844a1aSMatthew Knepley 673ea844a1aSMatthew Knepley Level: intermediate 674ea844a1aSMatthew Knepley 675db781477SPatrick Sanan .seealso: `PetscSectionSetPointMajor()` 676ea844a1aSMatthew Knepley @*/ 677*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetPointMajor(PetscSection s, PetscBool *pm) 678*d71ae5a4SJacob Faibussowitsch { 679ea844a1aSMatthew Knepley PetscFunctionBegin; 680ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 681dadcf809SJacob Faibussowitsch PetscValidBoolPointer(pm, 2); 682ea844a1aSMatthew Knepley *pm = s->pointMajor; 683ea844a1aSMatthew Knepley PetscFunctionReturn(0); 684ea844a1aSMatthew Knepley } 685ea844a1aSMatthew Knepley 686ea844a1aSMatthew Knepley /*@ 687ea844a1aSMatthew Knepley PetscSectionSetPointMajor - Sets the flag for dof ordering, true if it is point major, otherwise field major 688ea844a1aSMatthew Knepley 68940750d41SVaclav Hapla Not Collective 690ea844a1aSMatthew Knepley 691ea844a1aSMatthew Knepley Input Parameters: 692ea844a1aSMatthew Knepley + s - the PetscSection 693ea844a1aSMatthew Knepley - pm - the flag for point major ordering 694ea844a1aSMatthew Knepley 695ea844a1aSMatthew Knepley Level: intermediate 696ea844a1aSMatthew Knepley 697db781477SPatrick Sanan .seealso: `PetscSectionGetPointMajor()` 698ea844a1aSMatthew Knepley @*/ 699*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetPointMajor(PetscSection s, PetscBool pm) 700*d71ae5a4SJacob Faibussowitsch { 701ea844a1aSMatthew Knepley PetscFunctionBegin; 702ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 70328b400f6SJacob Faibussowitsch PetscCheck(!s->setup, PetscObjectComm((PetscObject)s), PETSC_ERR_ARG_WRONGSTATE, "Cannot set the dof ordering after the section is setup"); 704ea844a1aSMatthew Knepley s->pointMajor = pm; 705ea844a1aSMatthew Knepley PetscFunctionReturn(0); 706ea844a1aSMatthew Knepley } 707ea844a1aSMatthew Knepley 708ea844a1aSMatthew Knepley /*@ 70987e637c6Sksagiyam PetscSectionGetIncludesConstraints - Returns the flag indicating if constrained dofs were included when computing offsets 71087e637c6Sksagiyam 71140750d41SVaclav Hapla Not Collective 71287e637c6Sksagiyam 71387e637c6Sksagiyam Input Parameter: 71487e637c6Sksagiyam . s - the PetscSection 71587e637c6Sksagiyam 71687e637c6Sksagiyam Output Parameter: 71787e637c6Sksagiyam . includesConstraints - the flag indicating if constrained dofs were included when computing offsets 71887e637c6Sksagiyam 71987e637c6Sksagiyam Level: intermediate 72087e637c6Sksagiyam 721db781477SPatrick Sanan .seealso: `PetscSectionSetIncludesConstraints()` 72287e637c6Sksagiyam @*/ 723*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetIncludesConstraints(PetscSection s, PetscBool *includesConstraints) 724*d71ae5a4SJacob Faibussowitsch { 72587e637c6Sksagiyam PetscFunctionBegin; 72687e637c6Sksagiyam PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 72787e637c6Sksagiyam PetscValidBoolPointer(includesConstraints, 2); 72887e637c6Sksagiyam *includesConstraints = s->includesConstraints; 72987e637c6Sksagiyam PetscFunctionReturn(0); 73087e637c6Sksagiyam } 73187e637c6Sksagiyam 73287e637c6Sksagiyam /*@ 73387e637c6Sksagiyam PetscSectionSetIncludesConstraints - Sets the flag indicating if constrained dofs are to be included when computing offsets 73487e637c6Sksagiyam 73540750d41SVaclav Hapla Not Collective 73687e637c6Sksagiyam 73787e637c6Sksagiyam Input Parameters: 73887e637c6Sksagiyam + s - the PetscSection 73987e637c6Sksagiyam - includesConstraints - the flag indicating if constrained dofs are to be included when computing offsets 74087e637c6Sksagiyam 74187e637c6Sksagiyam Level: intermediate 74287e637c6Sksagiyam 743db781477SPatrick Sanan .seealso: `PetscSectionGetIncludesConstraints()` 74487e637c6Sksagiyam @*/ 745*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetIncludesConstraints(PetscSection s, PetscBool includesConstraints) 746*d71ae5a4SJacob Faibussowitsch { 74787e637c6Sksagiyam PetscFunctionBegin; 74887e637c6Sksagiyam PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 74928b400f6SJacob Faibussowitsch PetscCheck(!s->setup, PetscObjectComm((PetscObject)s), PETSC_ERR_ARG_WRONGSTATE, "Cannot set includesConstraints after the section is set up"); 75087e637c6Sksagiyam s->includesConstraints = includesConstraints; 75187e637c6Sksagiyam PetscFunctionReturn(0); 75287e637c6Sksagiyam } 75387e637c6Sksagiyam 75487e637c6Sksagiyam /*@ 755ea844a1aSMatthew Knepley PetscSectionGetDof - Return the number of degrees of freedom associated with a given point. 756ea844a1aSMatthew Knepley 75740750d41SVaclav Hapla Not Collective 758ea844a1aSMatthew Knepley 759ea844a1aSMatthew Knepley Input Parameters: 760ea844a1aSMatthew Knepley + s - the PetscSection 761ea844a1aSMatthew Knepley - point - the point 762ea844a1aSMatthew Knepley 763ea844a1aSMatthew Knepley Output Parameter: 764ea844a1aSMatthew Knepley . numDof - the number of dof 765ea844a1aSMatthew Knepley 766ea844a1aSMatthew Knepley Level: intermediate 767ea844a1aSMatthew Knepley 768db781477SPatrick Sanan .seealso: `PetscSectionSetDof()`, `PetscSectionCreate()` 769ea844a1aSMatthew Knepley @*/ 770*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetDof(PetscSection s, PetscInt point, PetscInt *numDof) 771*d71ae5a4SJacob Faibussowitsch { 77276bd3646SJed Brown PetscFunctionBeginHot; 773ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 774dadcf809SJacob Faibussowitsch PetscValidIntPointer(numDof, 3); 775c8bf3acbSVaclav 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); 776ea844a1aSMatthew Knepley *numDof = s->atlasDof[point - s->pStart]; 777ea844a1aSMatthew Knepley PetscFunctionReturn(0); 778ea844a1aSMatthew Knepley } 779ea844a1aSMatthew Knepley 780ea844a1aSMatthew Knepley /*@ 781ea844a1aSMatthew Knepley PetscSectionSetDof - Sets the number of degrees of freedom associated with a given point. 782ea844a1aSMatthew Knepley 78340750d41SVaclav Hapla Not Collective 784ea844a1aSMatthew Knepley 785ea844a1aSMatthew Knepley Input Parameters: 786ea844a1aSMatthew Knepley + s - the PetscSection 787ea844a1aSMatthew Knepley . point - the point 788ea844a1aSMatthew Knepley - numDof - the number of dof 789ea844a1aSMatthew Knepley 790ea844a1aSMatthew Knepley Level: intermediate 791ea844a1aSMatthew Knepley 792db781477SPatrick Sanan .seealso: `PetscSectionGetDof()`, `PetscSectionAddDof()`, `PetscSectionCreate()` 793ea844a1aSMatthew Knepley @*/ 794*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetDof(PetscSection s, PetscInt point, PetscInt numDof) 795*d71ae5a4SJacob Faibussowitsch { 796ea844a1aSMatthew Knepley PetscFunctionBegin; 797ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 798c8bf3acbSVaclav 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); 799ea844a1aSMatthew Knepley s->atlasDof[point - s->pStart] = numDof; 80069c11d05SVaclav Hapla PetscCall(PetscSectionInvalidateMaxDof_Internal(s)); 801ea844a1aSMatthew Knepley PetscFunctionReturn(0); 802ea844a1aSMatthew Knepley } 803ea844a1aSMatthew Knepley 804ea844a1aSMatthew Knepley /*@ 805ea844a1aSMatthew Knepley PetscSectionAddDof - Adds to the number of degrees of freedom associated with a given point. 806ea844a1aSMatthew Knepley 80740750d41SVaclav Hapla Not Collective 808ea844a1aSMatthew Knepley 809ea844a1aSMatthew Knepley Input Parameters: 810ea844a1aSMatthew Knepley + s - the PetscSection 811ea844a1aSMatthew Knepley . point - the point 812ea844a1aSMatthew Knepley - numDof - the number of additional dof 813ea844a1aSMatthew Knepley 814ea844a1aSMatthew Knepley Level: intermediate 815ea844a1aSMatthew Knepley 816db781477SPatrick Sanan .seealso: `PetscSectionGetDof()`, `PetscSectionSetDof()`, `PetscSectionCreate()` 817ea844a1aSMatthew Knepley @*/ 818*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionAddDof(PetscSection s, PetscInt point, PetscInt numDof) 819*d71ae5a4SJacob Faibussowitsch { 82076bd3646SJed Brown PetscFunctionBeginHot; 821ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 822c8bf3acbSVaclav 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); 823ea844a1aSMatthew Knepley s->atlasDof[point - s->pStart] += numDof; 82469c11d05SVaclav Hapla PetscCall(PetscSectionInvalidateMaxDof_Internal(s)); 825ea844a1aSMatthew Knepley PetscFunctionReturn(0); 826ea844a1aSMatthew Knepley } 827ea844a1aSMatthew Knepley 828ea844a1aSMatthew Knepley /*@ 829ea844a1aSMatthew Knepley PetscSectionGetFieldDof - Return the number of degrees of freedom associated with a field on a given point. 830ea844a1aSMatthew Knepley 83140750d41SVaclav Hapla Not Collective 832ea844a1aSMatthew Knepley 833ea844a1aSMatthew Knepley Input Parameters: 834ea844a1aSMatthew Knepley + s - the PetscSection 835ea844a1aSMatthew Knepley . point - the point 836ea844a1aSMatthew Knepley - field - the field 837ea844a1aSMatthew Knepley 838ea844a1aSMatthew Knepley Output Parameter: 839ea844a1aSMatthew Knepley . numDof - the number of dof 840ea844a1aSMatthew Knepley 841ea844a1aSMatthew Knepley Level: intermediate 842ea844a1aSMatthew Knepley 843db781477SPatrick Sanan .seealso: `PetscSectionSetFieldDof()`, `PetscSectionCreate()` 844ea844a1aSMatthew Knepley @*/ 845*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldDof(PetscSection s, PetscInt point, PetscInt field, PetscInt *numDof) 846*d71ae5a4SJacob Faibussowitsch { 847ea844a1aSMatthew Knepley PetscFunctionBegin; 848ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 8492abc8c78SJacob Faibussowitsch PetscValidIntPointer(numDof, 4); 8502abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 8519566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s->field[field], point, numDof)); 852ea844a1aSMatthew Knepley PetscFunctionReturn(0); 853ea844a1aSMatthew Knepley } 854ea844a1aSMatthew Knepley 855ea844a1aSMatthew Knepley /*@ 856ea844a1aSMatthew Knepley PetscSectionSetFieldDof - Sets the number of degrees of freedom associated with a field on a given point. 857ea844a1aSMatthew Knepley 85840750d41SVaclav Hapla Not Collective 859ea844a1aSMatthew Knepley 860ea844a1aSMatthew Knepley Input Parameters: 861ea844a1aSMatthew Knepley + s - the PetscSection 862ea844a1aSMatthew Knepley . point - the point 863ea844a1aSMatthew Knepley . field - the field 864ea844a1aSMatthew Knepley - numDof - the number of dof 865ea844a1aSMatthew Knepley 866ea844a1aSMatthew Knepley Level: intermediate 867ea844a1aSMatthew Knepley 868db781477SPatrick Sanan .seealso: `PetscSectionGetFieldDof()`, `PetscSectionCreate()` 869ea844a1aSMatthew Knepley @*/ 870*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof) 871*d71ae5a4SJacob Faibussowitsch { 872ea844a1aSMatthew Knepley PetscFunctionBegin; 873ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 8742abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 8759566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(s->field[field], point, numDof)); 876ea844a1aSMatthew Knepley PetscFunctionReturn(0); 877ea844a1aSMatthew Knepley } 878ea844a1aSMatthew Knepley 879ea844a1aSMatthew Knepley /*@ 880ea844a1aSMatthew Knepley PetscSectionAddFieldDof - Adds a number of degrees of freedom associated with a field on a given point. 881ea844a1aSMatthew Knepley 88240750d41SVaclav Hapla Not Collective 883ea844a1aSMatthew Knepley 884ea844a1aSMatthew Knepley Input Parameters: 885ea844a1aSMatthew Knepley + s - the PetscSection 886ea844a1aSMatthew Knepley . point - the point 887ea844a1aSMatthew Knepley . field - the field 888ea844a1aSMatthew Knepley - numDof - the number of dof 889ea844a1aSMatthew Knepley 890ea844a1aSMatthew Knepley Level: intermediate 891ea844a1aSMatthew Knepley 892db781477SPatrick Sanan .seealso: `PetscSectionSetFieldDof()`, `PetscSectionGetFieldDof()`, `PetscSectionCreate()` 893ea844a1aSMatthew Knepley @*/ 894*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionAddFieldDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof) 895*d71ae5a4SJacob Faibussowitsch { 896ea844a1aSMatthew Knepley PetscFunctionBegin; 897ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 8982abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 8999566063dSJacob Faibussowitsch PetscCall(PetscSectionAddDof(s->field[field], point, numDof)); 900ea844a1aSMatthew Knepley PetscFunctionReturn(0); 901ea844a1aSMatthew Knepley } 902ea844a1aSMatthew Knepley 903ea844a1aSMatthew Knepley /*@ 904ea844a1aSMatthew Knepley PetscSectionGetConstraintDof - Return the number of constrained degrees of freedom associated with a given point. 905ea844a1aSMatthew Knepley 90640750d41SVaclav Hapla Not Collective 907ea844a1aSMatthew Knepley 908ea844a1aSMatthew Knepley Input Parameters: 909ea844a1aSMatthew Knepley + s - the PetscSection 910ea844a1aSMatthew Knepley - point - the point 911ea844a1aSMatthew Knepley 912ea844a1aSMatthew Knepley Output Parameter: 913ea844a1aSMatthew Knepley . numDof - the number of dof which are fixed by constraints 914ea844a1aSMatthew Knepley 915ea844a1aSMatthew Knepley Level: intermediate 916ea844a1aSMatthew Knepley 917db781477SPatrick Sanan .seealso: `PetscSectionGetDof()`, `PetscSectionSetConstraintDof()`, `PetscSectionCreate()` 918ea844a1aSMatthew Knepley @*/ 919*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetConstraintDof(PetscSection s, PetscInt point, PetscInt *numDof) 920*d71ae5a4SJacob Faibussowitsch { 921ea844a1aSMatthew Knepley PetscFunctionBegin; 922ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 923dadcf809SJacob Faibussowitsch PetscValidIntPointer(numDof, 3); 924ea844a1aSMatthew Knepley if (s->bc) { 9259566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s->bc, point, numDof)); 926ea844a1aSMatthew Knepley } else *numDof = 0; 927ea844a1aSMatthew Knepley PetscFunctionReturn(0); 928ea844a1aSMatthew Knepley } 929ea844a1aSMatthew Knepley 930ea844a1aSMatthew Knepley /*@ 931ea844a1aSMatthew Knepley PetscSectionSetConstraintDof - Set the number of constrained degrees of freedom associated with a given point. 932ea844a1aSMatthew Knepley 93340750d41SVaclav Hapla Not Collective 934ea844a1aSMatthew Knepley 935ea844a1aSMatthew Knepley Input Parameters: 936ea844a1aSMatthew Knepley + s - the PetscSection 937ea844a1aSMatthew Knepley . point - the point 938ea844a1aSMatthew Knepley - numDof - the number of dof which are fixed by constraints 939ea844a1aSMatthew Knepley 940ea844a1aSMatthew Knepley Level: intermediate 941ea844a1aSMatthew Knepley 942db781477SPatrick Sanan .seealso: `PetscSectionSetDof()`, `PetscSectionGetConstraintDof()`, `PetscSectionCreate()` 943ea844a1aSMatthew Knepley @*/ 944*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetConstraintDof(PetscSection s, PetscInt point, PetscInt numDof) 945*d71ae5a4SJacob Faibussowitsch { 946ea844a1aSMatthew Knepley PetscFunctionBegin; 947ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 948ea844a1aSMatthew Knepley if (numDof) { 9497c0883d5SVaclav Hapla PetscCall(PetscSectionCheckConstraints_Private(s)); 9509566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(s->bc, point, numDof)); 951ea844a1aSMatthew Knepley } 952ea844a1aSMatthew Knepley PetscFunctionReturn(0); 953ea844a1aSMatthew Knepley } 954ea844a1aSMatthew Knepley 955ea844a1aSMatthew Knepley /*@ 956ea844a1aSMatthew Knepley PetscSectionAddConstraintDof - Increment the number of constrained degrees of freedom associated with a given point. 957ea844a1aSMatthew Knepley 95840750d41SVaclav Hapla Not Collective 959ea844a1aSMatthew Knepley 960ea844a1aSMatthew Knepley Input Parameters: 961ea844a1aSMatthew Knepley + s - the PetscSection 962ea844a1aSMatthew Knepley . point - the point 963ea844a1aSMatthew Knepley - numDof - the number of additional dof which are fixed by constraints 964ea844a1aSMatthew Knepley 965ea844a1aSMatthew Knepley Level: intermediate 966ea844a1aSMatthew Knepley 967db781477SPatrick Sanan .seealso: `PetscSectionAddDof()`, `PetscSectionGetConstraintDof()`, `PetscSectionCreate()` 968ea844a1aSMatthew Knepley @*/ 969*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionAddConstraintDof(PetscSection s, PetscInt point, PetscInt numDof) 970*d71ae5a4SJacob Faibussowitsch { 971ea844a1aSMatthew Knepley PetscFunctionBegin; 972ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 973ea844a1aSMatthew Knepley if (numDof) { 9747c0883d5SVaclav Hapla PetscCall(PetscSectionCheckConstraints_Private(s)); 9759566063dSJacob Faibussowitsch PetscCall(PetscSectionAddDof(s->bc, point, numDof)); 976ea844a1aSMatthew Knepley } 977ea844a1aSMatthew Knepley PetscFunctionReturn(0); 978ea844a1aSMatthew Knepley } 979ea844a1aSMatthew Knepley 980ea844a1aSMatthew Knepley /*@ 981ea844a1aSMatthew Knepley PetscSectionGetFieldConstraintDof - Return the number of constrained degrees of freedom associated with a given field on a point. 982ea844a1aSMatthew Knepley 98340750d41SVaclav Hapla Not Collective 984ea844a1aSMatthew Knepley 985ea844a1aSMatthew Knepley Input Parameters: 986ea844a1aSMatthew Knepley + s - the PetscSection 987ea844a1aSMatthew Knepley . point - the point 988ea844a1aSMatthew Knepley - field - the field 989ea844a1aSMatthew Knepley 990ea844a1aSMatthew Knepley Output Parameter: 991ea844a1aSMatthew Knepley . numDof - the number of dof which are fixed by constraints 992ea844a1aSMatthew Knepley 993ea844a1aSMatthew Knepley Level: intermediate 994ea844a1aSMatthew Knepley 995db781477SPatrick Sanan .seealso: `PetscSectionGetDof()`, `PetscSectionSetFieldConstraintDof()`, `PetscSectionCreate()` 996ea844a1aSMatthew Knepley @*/ 997*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldConstraintDof(PetscSection s, PetscInt point, PetscInt field, PetscInt *numDof) 998*d71ae5a4SJacob Faibussowitsch { 999ea844a1aSMatthew Knepley PetscFunctionBegin; 1000ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 10012abc8c78SJacob Faibussowitsch PetscValidIntPointer(numDof, 4); 10022abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 10039566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s->field[field], point, numDof)); 1004ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1005ea844a1aSMatthew Knepley } 1006ea844a1aSMatthew Knepley 1007ea844a1aSMatthew Knepley /*@ 1008ea844a1aSMatthew Knepley PetscSectionSetFieldConstraintDof - Set the number of constrained degrees of freedom associated with a given field on a point. 1009ea844a1aSMatthew Knepley 101040750d41SVaclav Hapla Not Collective 1011ea844a1aSMatthew Knepley 1012ea844a1aSMatthew Knepley Input Parameters: 1013ea844a1aSMatthew Knepley + s - the PetscSection 1014ea844a1aSMatthew Knepley . point - the point 1015ea844a1aSMatthew Knepley . field - the field 1016ea844a1aSMatthew Knepley - numDof - the number of dof which are fixed by constraints 1017ea844a1aSMatthew Knepley 1018ea844a1aSMatthew Knepley Level: intermediate 1019ea844a1aSMatthew Knepley 1020db781477SPatrick Sanan .seealso: `PetscSectionSetDof()`, `PetscSectionGetFieldConstraintDof()`, `PetscSectionCreate()` 1021ea844a1aSMatthew Knepley @*/ 1022*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldConstraintDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof) 1023*d71ae5a4SJacob Faibussowitsch { 1024ea844a1aSMatthew Knepley PetscFunctionBegin; 1025ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 10262abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 10279566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintDof(s->field[field], point, numDof)); 1028ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1029ea844a1aSMatthew Knepley } 1030ea844a1aSMatthew Knepley 1031ea844a1aSMatthew Knepley /*@ 1032ea844a1aSMatthew Knepley PetscSectionAddFieldConstraintDof - Increment the number of constrained degrees of freedom associated with a given field on a point. 1033ea844a1aSMatthew Knepley 103440750d41SVaclav Hapla Not Collective 1035ea844a1aSMatthew Knepley 1036ea844a1aSMatthew Knepley Input Parameters: 1037ea844a1aSMatthew Knepley + s - the PetscSection 1038ea844a1aSMatthew Knepley . point - the point 1039ea844a1aSMatthew Knepley . field - the field 1040ea844a1aSMatthew Knepley - numDof - the number of additional dof which are fixed by constraints 1041ea844a1aSMatthew Knepley 1042ea844a1aSMatthew Knepley Level: intermediate 1043ea844a1aSMatthew Knepley 1044db781477SPatrick Sanan .seealso: `PetscSectionAddDof()`, `PetscSectionGetFieldConstraintDof()`, `PetscSectionCreate()` 1045ea844a1aSMatthew Knepley @*/ 1046*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionAddFieldConstraintDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof) 1047*d71ae5a4SJacob Faibussowitsch { 1048ea844a1aSMatthew Knepley PetscFunctionBegin; 1049ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 10502abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 10519566063dSJacob Faibussowitsch PetscCall(PetscSectionAddConstraintDof(s->field[field], point, numDof)); 1052ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1053ea844a1aSMatthew Knepley } 1054ea844a1aSMatthew Knepley 1055ea844a1aSMatthew Knepley /*@ 1056ea844a1aSMatthew Knepley PetscSectionSetUpBC - Setup the subsections describing boundary conditions. 1057ea844a1aSMatthew Knepley 105840750d41SVaclav Hapla Not Collective 1059ea844a1aSMatthew Knepley 1060ea844a1aSMatthew Knepley Input Parameter: 1061ea844a1aSMatthew Knepley . s - the PetscSection 1062ea844a1aSMatthew Knepley 1063ea844a1aSMatthew Knepley Level: advanced 1064ea844a1aSMatthew Knepley 1065db781477SPatrick Sanan .seealso: `PetscSectionSetUp()`, `PetscSectionCreate()` 1066ea844a1aSMatthew Knepley @*/ 1067*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetUpBC(PetscSection s) 1068*d71ae5a4SJacob Faibussowitsch { 1069ea844a1aSMatthew Knepley PetscFunctionBegin; 1070ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1071ea844a1aSMatthew Knepley if (s->bc) { 1072ea844a1aSMatthew Knepley const PetscInt last = (s->bc->pEnd - s->bc->pStart) - 1; 1073ea844a1aSMatthew Knepley 10749566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(s->bc)); 10758da24d32SBarry Smith PetscCall(PetscMalloc1((last >= 0 ? s->bc->atlasOff[last] + s->bc->atlasDof[last] : 0), &s->bcIndices)); 1076ea844a1aSMatthew Knepley } 1077ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1078ea844a1aSMatthew Knepley } 1079ea844a1aSMatthew Knepley 1080ea844a1aSMatthew Knepley /*@ 1081ea844a1aSMatthew Knepley PetscSectionSetUp - Calculate offsets based upon the number of degrees of freedom for each point. 1082ea844a1aSMatthew Knepley 108340750d41SVaclav Hapla Not Collective 1084ea844a1aSMatthew Knepley 1085ea844a1aSMatthew Knepley Input Parameter: 1086ea844a1aSMatthew Knepley . s - the PetscSection 1087ea844a1aSMatthew Knepley 1088ea844a1aSMatthew Knepley Level: intermediate 1089ea844a1aSMatthew Knepley 1090db781477SPatrick Sanan .seealso: `PetscSectionCreate()` 1091ea844a1aSMatthew Knepley @*/ 1092*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetUp(PetscSection s) 1093*d71ae5a4SJacob Faibussowitsch { 1094ea844a1aSMatthew Knepley const PetscInt *pind = NULL; 1095ea844a1aSMatthew Knepley PetscInt offset = 0, foff, p, f; 1096ea844a1aSMatthew Knepley 1097ea844a1aSMatthew Knepley PetscFunctionBegin; 1098ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1099ea844a1aSMatthew Knepley if (s->setup) PetscFunctionReturn(0); 1100ea844a1aSMatthew Knepley s->setup = PETSC_TRUE; 1101ea844a1aSMatthew Knepley /* Set offsets and field offsets for all points */ 1102ea844a1aSMatthew Knepley /* Assume that all fields have the same chart */ 110328b400f6SJacob Faibussowitsch PetscCheck(s->includesConstraints, PETSC_COMM_SELF, PETSC_ERR_SUP, "PetscSectionSetUp is currently unsupported for includesConstraints = PETSC_TRUE"); 11049566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISGetIndices(s->perm, &pind)); 1105ea844a1aSMatthew Knepley if (s->pointMajor) { 1106ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) { 1107ea844a1aSMatthew Knepley const PetscInt q = pind ? pind[p] : p; 1108ea844a1aSMatthew Knepley 1109ea844a1aSMatthew Knepley /* Set point offset */ 1110ea844a1aSMatthew Knepley s->atlasOff[q] = offset; 1111ea844a1aSMatthew Knepley offset += s->atlasDof[q]; 1112ea844a1aSMatthew Knepley /* Set field offset */ 1113ea844a1aSMatthew Knepley for (f = 0, foff = s->atlasOff[q]; f < s->numFields; ++f) { 1114ea844a1aSMatthew Knepley PetscSection sf = s->field[f]; 1115ea844a1aSMatthew Knepley 1116ea844a1aSMatthew Knepley sf->atlasOff[q] = foff; 1117ea844a1aSMatthew Knepley foff += sf->atlasDof[q]; 1118ea844a1aSMatthew Knepley } 1119ea844a1aSMatthew Knepley } 1120ea844a1aSMatthew Knepley } else { 1121ea844a1aSMatthew Knepley /* Set field offsets for all points */ 1122ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) { 1123ea844a1aSMatthew Knepley PetscSection sf = s->field[f]; 1124ea844a1aSMatthew Knepley 1125ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) { 1126ea844a1aSMatthew Knepley const PetscInt q = pind ? pind[p] : p; 1127ea844a1aSMatthew Knepley 1128ea844a1aSMatthew Knepley sf->atlasOff[q] = offset; 1129ea844a1aSMatthew Knepley offset += sf->atlasDof[q]; 1130ea844a1aSMatthew Knepley } 1131ea844a1aSMatthew Knepley } 1132ea844a1aSMatthew Knepley /* Disable point offsets since these are unused */ 1133ad540459SPierre Jolivet for (p = 0; p < s->pEnd - s->pStart; ++p) s->atlasOff[p] = -1; 1134ea844a1aSMatthew Knepley } 11359566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISRestoreIndices(s->perm, &pind)); 1136ea844a1aSMatthew Knepley /* Setup BC sections */ 11379566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUpBC(s)); 11389566063dSJacob Faibussowitsch for (f = 0; f < s->numFields; ++f) PetscCall(PetscSectionSetUpBC(s->field[f])); 1139ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1140ea844a1aSMatthew Knepley } 1141ea844a1aSMatthew Knepley 1142ea844a1aSMatthew Knepley /*@ 1143ea844a1aSMatthew Knepley PetscSectionGetMaxDof - Return the maximum number of degrees of freedom on any point in the chart 1144ea844a1aSMatthew Knepley 114540750d41SVaclav Hapla Not Collective 1146ea844a1aSMatthew Knepley 1147ea844a1aSMatthew Knepley Input Parameters: 1148ea844a1aSMatthew Knepley . s - the PetscSection 1149ea844a1aSMatthew Knepley 1150ea844a1aSMatthew Knepley Output Parameter: 1151ea844a1aSMatthew Knepley . maxDof - the maximum dof 1152ea844a1aSMatthew Knepley 1153ea844a1aSMatthew Knepley Level: intermediate 1154ea844a1aSMatthew Knepley 115569c11d05SVaclav Hapla Notes: 115669c11d05SVaclav Hapla The returned number is up-to-date without need for PetscSectionSetUp(). 115769c11d05SVaclav Hapla 115869c11d05SVaclav Hapla Developer Notes: 115969c11d05SVaclav Hapla The returned number is calculated lazily and stashed. 116069c11d05SVaclav Hapla A call to PetscSectionInvalidateMaxDof_Internal() invalidates the stashed value. 116169c11d05SVaclav Hapla PetscSectionInvalidateMaxDof_Internal() is called in PetscSectionSetDof(), PetscSectionAddDof() and PetscSectionReset(). 116269c11d05SVaclav Hapla It should also be called every time atlasDof is modified directly. 116369c11d05SVaclav Hapla 1164db781477SPatrick Sanan .seealso: `PetscSectionGetDof()`, `PetscSectionSetDof()`, `PetscSectionAddDof()`, `PetscSectionCreate()` 1165ea844a1aSMatthew Knepley @*/ 1166*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetMaxDof(PetscSection s, PetscInt *maxDof) 1167*d71ae5a4SJacob Faibussowitsch { 116869c11d05SVaclav Hapla PetscInt p; 116969c11d05SVaclav Hapla 1170ea844a1aSMatthew Knepley PetscFunctionBegin; 1171ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1172dadcf809SJacob Faibussowitsch PetscValidIntPointer(maxDof, 2); 117369c11d05SVaclav Hapla if (s->maxDof == PETSC_MIN_INT) { 117469c11d05SVaclav Hapla s->maxDof = 0; 1175ad540459SPierre Jolivet for (p = 0; p < s->pEnd - s->pStart; ++p) s->maxDof = PetscMax(s->maxDof, s->atlasDof[p]); 117669c11d05SVaclav Hapla } 1177ea844a1aSMatthew Knepley *maxDof = s->maxDof; 1178ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1179ea844a1aSMatthew Knepley } 1180ea844a1aSMatthew Knepley 1181ea844a1aSMatthew Knepley /*@ 1182ea844a1aSMatthew Knepley PetscSectionGetStorageSize - Return the size of an array or local Vec capable of holding all the degrees of freedom. 1183ea844a1aSMatthew Knepley 118440750d41SVaclav Hapla Not Collective 1185ea844a1aSMatthew Knepley 1186ea844a1aSMatthew Knepley Input Parameter: 1187ea844a1aSMatthew Knepley . s - the PetscSection 1188ea844a1aSMatthew Knepley 1189ea844a1aSMatthew Knepley Output Parameter: 1190ea844a1aSMatthew Knepley . size - the size of an array which can hold all the dofs 1191ea844a1aSMatthew Knepley 1192ea844a1aSMatthew Knepley Level: intermediate 1193ea844a1aSMatthew Knepley 1194db781477SPatrick Sanan .seealso: `PetscSectionGetOffset()`, `PetscSectionGetConstrainedStorageSize()`, `PetscSectionCreate()` 1195ea844a1aSMatthew Knepley @*/ 1196*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetStorageSize(PetscSection s, PetscInt *size) 1197*d71ae5a4SJacob Faibussowitsch { 1198ea844a1aSMatthew Knepley PetscInt p, n = 0; 1199ea844a1aSMatthew Knepley 1200ea844a1aSMatthew Knepley PetscFunctionBegin; 1201ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1202dadcf809SJacob Faibussowitsch PetscValidIntPointer(size, 2); 1203ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) n += s->atlasDof[p] > 0 ? s->atlasDof[p] : 0; 1204ea844a1aSMatthew Knepley *size = n; 1205ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1206ea844a1aSMatthew Knepley } 1207ea844a1aSMatthew Knepley 1208ea844a1aSMatthew Knepley /*@ 1209ea844a1aSMatthew Knepley PetscSectionGetConstrainedStorageSize - Return the size of an array or local Vec capable of holding all unconstrained degrees of freedom. 1210ea844a1aSMatthew Knepley 121140750d41SVaclav Hapla Not Collective 1212ea844a1aSMatthew Knepley 1213064ec1f3Sprj- Input Parameter: 1214064ec1f3Sprj- . s - the PetscSection 1215ea844a1aSMatthew Knepley 1216ea844a1aSMatthew Knepley Output Parameter: 1217ea844a1aSMatthew Knepley . size - the size of an array which can hold all unconstrained dofs 1218ea844a1aSMatthew Knepley 1219ea844a1aSMatthew Knepley Level: intermediate 1220ea844a1aSMatthew Knepley 1221db781477SPatrick Sanan .seealso: `PetscSectionGetStorageSize()`, `PetscSectionGetOffset()`, `PetscSectionCreate()` 1222ea844a1aSMatthew Knepley @*/ 1223*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetConstrainedStorageSize(PetscSection s, PetscInt *size) 1224*d71ae5a4SJacob Faibussowitsch { 1225ea844a1aSMatthew Knepley PetscInt p, n = 0; 1226ea844a1aSMatthew Knepley 1227ea844a1aSMatthew Knepley PetscFunctionBegin; 1228ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1229dadcf809SJacob Faibussowitsch PetscValidIntPointer(size, 2); 1230ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) { 1231ea844a1aSMatthew Knepley const PetscInt cdof = s->bc ? s->bc->atlasDof[p] : 0; 1232ea844a1aSMatthew Knepley n += s->atlasDof[p] > 0 ? s->atlasDof[p] - cdof : 0; 1233ea844a1aSMatthew Knepley } 1234ea844a1aSMatthew Knepley *size = n; 1235ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1236ea844a1aSMatthew Knepley } 1237ea844a1aSMatthew Knepley 1238ea844a1aSMatthew Knepley /*@ 1239ea844a1aSMatthew Knepley PetscSectionCreateGlobalSection - Create a section describing the global field layout using 1240ea844a1aSMatthew Knepley the local section and an SF describing the section point overlap. 1241ea844a1aSMatthew Knepley 1242ea844a1aSMatthew Knepley Input Parameters: 1243ea844a1aSMatthew Knepley + s - The PetscSection for the local field layout 1244ea844a1aSMatthew Knepley . sf - The SF describing parallel layout of the section points (leaves are unowned local points) 1245ea844a1aSMatthew Knepley . includeConstraints - By default this is PETSC_FALSE, meaning that the global field vector will not possess constrained dofs 1246ea844a1aSMatthew Knepley - localOffsets - If PETSC_TRUE, use local rather than global offsets for the points 1247ea844a1aSMatthew Knepley 1248ea844a1aSMatthew Knepley Output Parameter: 1249ea844a1aSMatthew Knepley . gsection - The PetscSection for the global field layout 1250ea844a1aSMatthew Knepley 1251ea844a1aSMatthew Knepley Note: This gives negative sizes and offsets to points not owned by this process 1252ea844a1aSMatthew Knepley 1253ea844a1aSMatthew Knepley Level: intermediate 1254ea844a1aSMatthew Knepley 1255db781477SPatrick Sanan .seealso: `PetscSectionCreate()` 1256ea844a1aSMatthew Knepley @*/ 1257*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateGlobalSection(PetscSection s, PetscSF sf, PetscBool includeConstraints, PetscBool localOffsets, PetscSection *gsection) 1258*d71ae5a4SJacob Faibussowitsch { 1259ea844a1aSMatthew Knepley PetscSection gs; 1260ea844a1aSMatthew Knepley const PetscInt *pind = NULL; 1261ea844a1aSMatthew Knepley PetscInt *recv = NULL, *neg = NULL; 1262046d2115Sksagiyam PetscInt pStart, pEnd, p, dof, cdof, off, foff, globalOff = 0, nroots, nlocal, maxleaf; 1263046d2115Sksagiyam PetscInt numFields, f, numComponents; 1264ea844a1aSMatthew Knepley 1265ea844a1aSMatthew Knepley PetscFunctionBegin; 1266ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1267ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sf, PETSCSF_CLASSID, 2); 1268ea844a1aSMatthew Knepley PetscValidLogicalCollectiveBool(s, includeConstraints, 3); 1269ea844a1aSMatthew Knepley PetscValidLogicalCollectiveBool(s, localOffsets, 4); 1270ea844a1aSMatthew Knepley PetscValidPointer(gsection, 5); 127128b400f6SJacob Faibussowitsch PetscCheck(s->pointMajor, PETSC_COMM_SELF, PETSC_ERR_SUP, "No support for field major ordering"); 12729566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), &gs)); 12739566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s, &numFields)); 12749566063dSJacob Faibussowitsch if (numFields > 0) PetscCall(PetscSectionSetNumFields(gs, numFields)); 12759566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 12769566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(gs, pStart, pEnd)); 127787e637c6Sksagiyam gs->includesConstraints = includeConstraints; 12789566063dSJacob Faibussowitsch PetscCall(PetscSFGetGraph(sf, &nroots, NULL, NULL, NULL)); 1279ea844a1aSMatthew Knepley nlocal = nroots; /* The local/leaf space matches global/root space */ 1280ea844a1aSMatthew Knepley /* Must allocate for all points visible to SF, which may be more than this section */ 1281ea844a1aSMatthew Knepley if (nroots >= 0) { /* nroots < 0 means that the graph has not been set, only happens in serial */ 12829566063dSJacob Faibussowitsch PetscCall(PetscSFGetLeafRange(sf, NULL, &maxleaf)); 128308401ef6SPierre Jolivet PetscCheck(nroots >= pEnd, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "SF roots %" PetscInt_FMT " < pEnd %" PetscInt_FMT, nroots, pEnd); 128408401ef6SPierre Jolivet PetscCheck(maxleaf < nroots, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Max local leaf %" PetscInt_FMT " >= nroots %" PetscInt_FMT, maxleaf, nroots); 12859566063dSJacob Faibussowitsch PetscCall(PetscMalloc2(nroots, &neg, nlocal, &recv)); 12869566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(neg, nroots)); 1287ea844a1aSMatthew Knepley } 1288ea844a1aSMatthew Knepley /* Mark all local points with negative dof */ 1289ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 12909566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 12919566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(gs, p, dof)); 12929566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof)); 12939566063dSJacob Faibussowitsch if (!includeConstraints && cdof > 0) PetscCall(PetscSectionSetConstraintDof(gs, p, cdof)); 1294ea844a1aSMatthew Knepley if (neg) neg[p] = -(dof + 1); 1295ea844a1aSMatthew Knepley } 12969566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUpBC(gs)); 12979566063dSJacob 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])); 1298ea844a1aSMatthew Knepley if (nroots >= 0) { 12999566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(recv, nlocal)); 13009566063dSJacob Faibussowitsch PetscCall(PetscSFBcastBegin(sf, MPIU_INT, neg, recv, MPI_REPLACE)); 13019566063dSJacob Faibussowitsch PetscCall(PetscSFBcastEnd(sf, MPIU_INT, neg, recv, MPI_REPLACE)); 1302ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1303ea844a1aSMatthew Knepley if (recv[p] < 0) { 1304ea844a1aSMatthew Knepley gs->atlasDof[p - pStart] = recv[p]; 13059566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 130608401ef6SPierre 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); 1307ea844a1aSMatthew Knepley } 1308ea844a1aSMatthew Knepley } 1309ea844a1aSMatthew Knepley } 1310ea844a1aSMatthew Knepley /* Calculate new sizes, get process offset, and calculate point offsets */ 13119566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISGetIndices(s->perm, &pind)); 1312ea844a1aSMatthew Knepley for (p = 0, off = 0; p < pEnd - pStart; ++p) { 1313ea844a1aSMatthew Knepley const PetscInt q = pind ? pind[p] : p; 1314ea844a1aSMatthew Knepley 1315ea844a1aSMatthew Knepley cdof = (!includeConstraints && s->bc) ? s->bc->atlasDof[q] : 0; 1316ea844a1aSMatthew Knepley gs->atlasOff[q] = off; 1317ea844a1aSMatthew Knepley off += gs->atlasDof[q] > 0 ? gs->atlasDof[q] - cdof : 0; 1318ea844a1aSMatthew Knepley } 1319ea844a1aSMatthew Knepley if (!localOffsets) { 13209566063dSJacob Faibussowitsch PetscCallMPI(MPI_Scan(&off, &globalOff, 1, MPIU_INT, MPI_SUM, PetscObjectComm((PetscObject)s))); 1321ea844a1aSMatthew Knepley globalOff -= off; 1322ea844a1aSMatthew Knepley } 1323ea844a1aSMatthew Knepley for (p = pStart, off = 0; p < pEnd; ++p) { 1324ea844a1aSMatthew Knepley gs->atlasOff[p - pStart] += globalOff; 1325ea844a1aSMatthew Knepley if (neg) neg[p] = -(gs->atlasOff[p - pStart] + 1); 1326ea844a1aSMatthew Knepley } 13279566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISRestoreIndices(s->perm, &pind)); 1328ea844a1aSMatthew Knepley /* Put in negative offsets for ghost points */ 1329ea844a1aSMatthew Knepley if (nroots >= 0) { 13309566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(recv, nlocal)); 13319566063dSJacob Faibussowitsch PetscCall(PetscSFBcastBegin(sf, MPIU_INT, neg, recv, MPI_REPLACE)); 13329566063dSJacob Faibussowitsch PetscCall(PetscSFBcastEnd(sf, MPIU_INT, neg, recv, MPI_REPLACE)); 1333ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1334ea844a1aSMatthew Knepley if (recv[p] < 0) gs->atlasOff[p - pStart] = recv[p]; 1335ea844a1aSMatthew Knepley } 1336ea844a1aSMatthew Knepley } 13379566063dSJacob Faibussowitsch PetscCall(PetscFree2(neg, recv)); 1338046d2115Sksagiyam /* Set field dofs/offsets/constraints */ 1339046d2115Sksagiyam for (f = 0; f < numFields; ++f) { 1340046d2115Sksagiyam gs->field[f]->includesConstraints = includeConstraints; 13419566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s, f, &numComponents)); 13429566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(gs, f, numComponents)); 1343046d2115Sksagiyam } 1344046d2115Sksagiyam for (p = pStart; p < pEnd; ++p) { 13459566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(gs, p, &off)); 1346046d2115Sksagiyam for (f = 0, foff = off; f < numFields; ++f) { 13479566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, f, &cdof)); 13489566063dSJacob Faibussowitsch if (!includeConstraints && cdof > 0) PetscCall(PetscSectionSetFieldConstraintDof(gs, p, f, cdof)); 13499566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, f, &dof)); 13509566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldDof(gs, p, f, off < 0 ? -(dof + 1) : dof)); 13519566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldOffset(gs, p, f, foff)); 13529566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(gs, p, f, &cdof)); 1353046d2115Sksagiyam foff = off < 0 ? foff - (dof - cdof) : foff + (dof - cdof); 1354046d2115Sksagiyam } 1355046d2115Sksagiyam } 1356046d2115Sksagiyam for (f = 0; f < numFields; ++f) { 1357046d2115Sksagiyam PetscSection gfs = gs->field[f]; 1358046d2115Sksagiyam 13599566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUpBC(gfs)); 13609566063dSJacob 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])); 1361046d2115Sksagiyam } 1362046d2115Sksagiyam gs->setup = PETSC_TRUE; 13639566063dSJacob Faibussowitsch PetscCall(PetscSectionViewFromOptions(gs, NULL, "-global_section_view")); 1364ea844a1aSMatthew Knepley *gsection = gs; 1365ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1366ea844a1aSMatthew Knepley } 1367ea844a1aSMatthew Knepley 1368ea844a1aSMatthew Knepley /*@ 1369ea844a1aSMatthew Knepley PetscSectionCreateGlobalSectionCensored - Create a section describing the global field layout using 1370ea844a1aSMatthew Knepley the local section and an SF describing the section point overlap. 1371ea844a1aSMatthew Knepley 1372ea844a1aSMatthew Knepley Input Parameters: 1373ea844a1aSMatthew Knepley + s - The PetscSection for the local field layout 1374ea844a1aSMatthew Knepley . sf - The SF describing parallel layout of the section points 1375ea844a1aSMatthew Knepley . includeConstraints - By default this is PETSC_FALSE, meaning that the global field vector will not possess constrained dofs 1376ea844a1aSMatthew Knepley . numExcludes - The number of exclusion ranges 1377ea844a1aSMatthew Knepley - excludes - An array [start_0, end_0, start_1, end_1, ...] where there are numExcludes pairs 1378ea844a1aSMatthew Knepley 1379ea844a1aSMatthew Knepley Output Parameter: 1380ea844a1aSMatthew Knepley . gsection - The PetscSection for the global field layout 1381ea844a1aSMatthew Knepley 1382ea844a1aSMatthew Knepley Note: This gives negative sizes and offsets to points not owned by this process 1383ea844a1aSMatthew Knepley 1384ea844a1aSMatthew Knepley Level: advanced 1385ea844a1aSMatthew Knepley 1386db781477SPatrick Sanan .seealso: `PetscSectionCreate()` 1387ea844a1aSMatthew Knepley @*/ 1388*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateGlobalSectionCensored(PetscSection s, PetscSF sf, PetscBool includeConstraints, PetscInt numExcludes, const PetscInt excludes[], PetscSection *gsection) 1389*d71ae5a4SJacob Faibussowitsch { 1390ea844a1aSMatthew Knepley const PetscInt *pind = NULL; 1391ea844a1aSMatthew Knepley PetscInt *neg = NULL, *tmpOff = NULL; 1392ea844a1aSMatthew Knepley PetscInt pStart, pEnd, p, e, dof, cdof, off, globalOff = 0, nroots; 1393ea844a1aSMatthew Knepley 1394ea844a1aSMatthew Knepley PetscFunctionBegin; 1395ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1396ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sf, PETSCSF_CLASSID, 2); 1397ea844a1aSMatthew Knepley PetscValidPointer(gsection, 6); 13989566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), gsection)); 13999566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 14009566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(*gsection, pStart, pEnd)); 14019566063dSJacob Faibussowitsch PetscCall(PetscSFGetGraph(sf, &nroots, NULL, NULL, NULL)); 1402ea844a1aSMatthew Knepley if (nroots >= 0) { 140308401ef6SPierre Jolivet PetscCheck(nroots >= pEnd - pStart, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "PetscSF nroots %" PetscInt_FMT " < %" PetscInt_FMT " section size", nroots, pEnd - pStart); 14049566063dSJacob Faibussowitsch PetscCall(PetscCalloc1(nroots, &neg)); 1405ea844a1aSMatthew Knepley if (nroots > pEnd - pStart) { 14069566063dSJacob Faibussowitsch PetscCall(PetscCalloc1(nroots, &tmpOff)); 1407ea844a1aSMatthew Knepley } else { 1408ea844a1aSMatthew Knepley tmpOff = &(*gsection)->atlasDof[-pStart]; 1409ea844a1aSMatthew Knepley } 1410ea844a1aSMatthew Knepley } 1411ea844a1aSMatthew Knepley /* Mark ghost points with negative dof */ 1412ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1413ea844a1aSMatthew Knepley for (e = 0; e < numExcludes; ++e) { 1414ea844a1aSMatthew Knepley if ((p >= excludes[e * 2 + 0]) && (p < excludes[e * 2 + 1])) { 14159566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(*gsection, p, 0)); 1416ea844a1aSMatthew Knepley break; 1417ea844a1aSMatthew Knepley } 1418ea844a1aSMatthew Knepley } 1419ea844a1aSMatthew Knepley if (e < numExcludes) continue; 14209566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 14219566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(*gsection, p, dof)); 14229566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof)); 14239566063dSJacob Faibussowitsch if (!includeConstraints && cdof > 0) PetscCall(PetscSectionSetConstraintDof(*gsection, p, cdof)); 1424ea844a1aSMatthew Knepley if (neg) neg[p] = -(dof + 1); 1425ea844a1aSMatthew Knepley } 14269566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUpBC(*gsection)); 1427ea844a1aSMatthew Knepley if (nroots >= 0) { 14289566063dSJacob Faibussowitsch PetscCall(PetscSFBcastBegin(sf, MPIU_INT, neg, tmpOff, MPI_REPLACE)); 14299566063dSJacob Faibussowitsch PetscCall(PetscSFBcastEnd(sf, MPIU_INT, neg, tmpOff, MPI_REPLACE)); 1430ea844a1aSMatthew Knepley if (nroots > pEnd - pStart) { 14319371c9d4SSatish Balay for (p = pStart; p < pEnd; ++p) { 14329371c9d4SSatish Balay if (tmpOff[p] < 0) (*gsection)->atlasDof[p - pStart] = tmpOff[p]; 14339371c9d4SSatish Balay } 1434ea844a1aSMatthew Knepley } 1435ea844a1aSMatthew Knepley } 1436ea844a1aSMatthew Knepley /* Calculate new sizes, get proccess offset, and calculate point offsets */ 14379566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISGetIndices(s->perm, &pind)); 1438ea844a1aSMatthew Knepley for (p = 0, off = 0; p < pEnd - pStart; ++p) { 1439ea844a1aSMatthew Knepley const PetscInt q = pind ? pind[p] : p; 1440ea844a1aSMatthew Knepley 1441ea844a1aSMatthew Knepley cdof = (!includeConstraints && s->bc) ? s->bc->atlasDof[q] : 0; 1442ea844a1aSMatthew Knepley (*gsection)->atlasOff[q] = off; 1443ea844a1aSMatthew Knepley off += (*gsection)->atlasDof[q] > 0 ? (*gsection)->atlasDof[q] - cdof : 0; 1444ea844a1aSMatthew Knepley } 14459566063dSJacob Faibussowitsch PetscCallMPI(MPI_Scan(&off, &globalOff, 1, MPIU_INT, MPI_SUM, PetscObjectComm((PetscObject)s))); 1446ea844a1aSMatthew Knepley globalOff -= off; 1447ea844a1aSMatthew Knepley for (p = 0, off = 0; p < pEnd - pStart; ++p) { 1448ea844a1aSMatthew Knepley (*gsection)->atlasOff[p] += globalOff; 1449ea844a1aSMatthew Knepley if (neg) neg[p + pStart] = -((*gsection)->atlasOff[p] + 1); 1450ea844a1aSMatthew Knepley } 14519566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISRestoreIndices(s->perm, &pind)); 1452ea844a1aSMatthew Knepley /* Put in negative offsets for ghost points */ 1453ea844a1aSMatthew Knepley if (nroots >= 0) { 1454ea844a1aSMatthew Knepley if (nroots == pEnd - pStart) tmpOff = &(*gsection)->atlasOff[-pStart]; 14559566063dSJacob Faibussowitsch PetscCall(PetscSFBcastBegin(sf, MPIU_INT, neg, tmpOff, MPI_REPLACE)); 14569566063dSJacob Faibussowitsch PetscCall(PetscSFBcastEnd(sf, MPIU_INT, neg, tmpOff, MPI_REPLACE)); 1457ea844a1aSMatthew Knepley if (nroots > pEnd - pStart) { 14589371c9d4SSatish Balay for (p = pStart; p < pEnd; ++p) { 14599371c9d4SSatish Balay if (tmpOff[p] < 0) (*gsection)->atlasOff[p - pStart] = tmpOff[p]; 14609371c9d4SSatish Balay } 1461ea844a1aSMatthew Knepley } 1462ea844a1aSMatthew Knepley } 14639566063dSJacob Faibussowitsch if (nroots >= 0 && nroots > pEnd - pStart) PetscCall(PetscFree(tmpOff)); 14649566063dSJacob Faibussowitsch PetscCall(PetscFree(neg)); 1465ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1466ea844a1aSMatthew Knepley } 1467ea844a1aSMatthew Knepley 1468ea844a1aSMatthew Knepley /*@ 1469ea844a1aSMatthew Knepley PetscSectionGetPointLayout - Get the PetscLayout associated with the section points 1470ea844a1aSMatthew Knepley 1471ea844a1aSMatthew Knepley Collective on comm 1472ea844a1aSMatthew Knepley 1473ea844a1aSMatthew Knepley Input Parameters: 1474ea844a1aSMatthew Knepley + comm - The MPI_Comm 1475ea844a1aSMatthew Knepley - s - The PetscSection 1476ea844a1aSMatthew Knepley 1477ea844a1aSMatthew Knepley Output Parameter: 1478ea844a1aSMatthew Knepley . layout - The point layout for the section 1479ea844a1aSMatthew Knepley 14801681d8a4SMatthew Knepley Note: This is usually called for the default global section. 1481ea844a1aSMatthew Knepley 1482ea844a1aSMatthew Knepley Level: advanced 1483ea844a1aSMatthew Knepley 1484db781477SPatrick Sanan .seealso: `PetscSectionGetValueLayout()`, `PetscSectionCreate()` 1485ea844a1aSMatthew Knepley @*/ 1486*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetPointLayout(MPI_Comm comm, PetscSection s, PetscLayout *layout) 1487*d71ae5a4SJacob Faibussowitsch { 1488ea844a1aSMatthew Knepley PetscInt pStart, pEnd, p, localSize = 0; 1489ea844a1aSMatthew Knepley 1490ea844a1aSMatthew Knepley PetscFunctionBegin; 14919566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 1492ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1493ea844a1aSMatthew Knepley PetscInt dof; 1494ea844a1aSMatthew Knepley 14959566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 14969120ba30SVaclav Hapla if (dof >= 0) ++localSize; 1497ea844a1aSMatthew Knepley } 14989566063dSJacob Faibussowitsch PetscCall(PetscLayoutCreate(comm, layout)); 14999566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetLocalSize(*layout, localSize)); 15009566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetBlockSize(*layout, 1)); 15019566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetUp(*layout)); 1502ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1503ea844a1aSMatthew Knepley } 1504ea844a1aSMatthew Knepley 1505ea844a1aSMatthew Knepley /*@ 1506ea844a1aSMatthew Knepley PetscSectionGetValueLayout - Get the PetscLayout associated with the section dofs. 1507ea844a1aSMatthew Knepley 1508ea844a1aSMatthew Knepley Collective on comm 1509ea844a1aSMatthew Knepley 1510ea844a1aSMatthew Knepley Input Parameters: 1511ea844a1aSMatthew Knepley + comm - The MPI_Comm 1512ea844a1aSMatthew Knepley - s - The PetscSection 1513ea844a1aSMatthew Knepley 1514ea844a1aSMatthew Knepley Output Parameter: 1515ea844a1aSMatthew Knepley . layout - The dof layout for the section 1516ea844a1aSMatthew Knepley 1517ea844a1aSMatthew Knepley Note: This is usually called for the default global section. 1518ea844a1aSMatthew Knepley 1519ea844a1aSMatthew Knepley Level: advanced 1520ea844a1aSMatthew Knepley 1521db781477SPatrick Sanan .seealso: `PetscSectionGetPointLayout()`, `PetscSectionCreate()` 1522ea844a1aSMatthew Knepley @*/ 1523*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetValueLayout(MPI_Comm comm, PetscSection s, PetscLayout *layout) 1524*d71ae5a4SJacob Faibussowitsch { 1525ea844a1aSMatthew Knepley PetscInt pStart, pEnd, p, localSize = 0; 1526ea844a1aSMatthew Knepley 1527ea844a1aSMatthew Knepley PetscFunctionBegin; 1528ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 2); 1529ea844a1aSMatthew Knepley PetscValidPointer(layout, 3); 15309566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 1531ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1532ea844a1aSMatthew Knepley PetscInt dof, cdof; 1533ea844a1aSMatthew Knepley 15349566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 15359566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof)); 1536ea844a1aSMatthew Knepley if (dof - cdof > 0) localSize += dof - cdof; 1537ea844a1aSMatthew Knepley } 15389566063dSJacob Faibussowitsch PetscCall(PetscLayoutCreate(comm, layout)); 15399566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetLocalSize(*layout, localSize)); 15409566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetBlockSize(*layout, 1)); 15419566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetUp(*layout)); 1542ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1543ea844a1aSMatthew Knepley } 1544ea844a1aSMatthew Knepley 1545ea844a1aSMatthew Knepley /*@ 1546ea844a1aSMatthew Knepley PetscSectionGetOffset - Return the offset into an array or local Vec for the dof associated with the given point. 1547ea844a1aSMatthew Knepley 154840750d41SVaclav Hapla Not Collective 1549ea844a1aSMatthew Knepley 1550ea844a1aSMatthew Knepley Input Parameters: 1551ea844a1aSMatthew Knepley + s - the PetscSection 1552ea844a1aSMatthew Knepley - point - the point 1553ea844a1aSMatthew Knepley 1554ea844a1aSMatthew Knepley Output Parameter: 1555ea844a1aSMatthew Knepley . offset - the offset 1556ea844a1aSMatthew Knepley 1557ea844a1aSMatthew Knepley Level: intermediate 1558ea844a1aSMatthew Knepley 1559db781477SPatrick Sanan .seealso: `PetscSectionGetFieldOffset()`, `PetscSectionCreate()` 1560ea844a1aSMatthew Knepley @*/ 1561*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetOffset(PetscSection s, PetscInt point, PetscInt *offset) 1562*d71ae5a4SJacob Faibussowitsch { 1563ea844a1aSMatthew Knepley PetscFunctionBegin; 1564ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1565dadcf809SJacob Faibussowitsch PetscValidIntPointer(offset, 3); 1566ad540459SPierre 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); 1567ea844a1aSMatthew Knepley *offset = s->atlasOff[point - s->pStart]; 1568ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1569ea844a1aSMatthew Knepley } 1570ea844a1aSMatthew Knepley 1571ea844a1aSMatthew Knepley /*@ 1572ea844a1aSMatthew Knepley PetscSectionSetOffset - Set the offset into an array or local Vec for the dof associated with the given point. 1573ea844a1aSMatthew Knepley 157440750d41SVaclav Hapla Not Collective 1575ea844a1aSMatthew Knepley 1576ea844a1aSMatthew Knepley Input Parameters: 1577ea844a1aSMatthew Knepley + s - the PetscSection 1578ea844a1aSMatthew Knepley . point - the point 1579ea844a1aSMatthew Knepley - offset - the offset 1580ea844a1aSMatthew Knepley 1581ea844a1aSMatthew Knepley Note: The user usually does not call this function, but uses PetscSectionSetUp() 1582ea844a1aSMatthew Knepley 1583ea844a1aSMatthew Knepley Level: intermediate 1584ea844a1aSMatthew Knepley 1585db781477SPatrick Sanan .seealso: `PetscSectionGetFieldOffset()`, `PetscSectionCreate()`, `PetscSectionSetUp()` 1586ea844a1aSMatthew Knepley @*/ 1587*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetOffset(PetscSection s, PetscInt point, PetscInt offset) 1588*d71ae5a4SJacob Faibussowitsch { 1589ea844a1aSMatthew Knepley PetscFunctionBegin; 1590ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 159108401ef6SPierre 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); 1592ea844a1aSMatthew Knepley s->atlasOff[point - s->pStart] = offset; 1593ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1594ea844a1aSMatthew Knepley } 1595ea844a1aSMatthew Knepley 1596ea844a1aSMatthew Knepley /*@ 1597ea844a1aSMatthew Knepley PetscSectionGetFieldOffset - Return the offset into an array or local Vec for the dof associated with the given point. 1598ea844a1aSMatthew Knepley 159940750d41SVaclav Hapla Not Collective 1600ea844a1aSMatthew Knepley 1601ea844a1aSMatthew Knepley Input Parameters: 1602ea844a1aSMatthew Knepley + s - the PetscSection 1603ea844a1aSMatthew Knepley . point - the point 1604ea844a1aSMatthew Knepley - field - the field 1605ea844a1aSMatthew Knepley 1606ea844a1aSMatthew Knepley Output Parameter: 1607ea844a1aSMatthew Knepley . offset - the offset 1608ea844a1aSMatthew Knepley 1609ea844a1aSMatthew Knepley Level: intermediate 1610ea844a1aSMatthew Knepley 1611db781477SPatrick Sanan .seealso: `PetscSectionGetOffset()`, `PetscSectionCreate()` 1612ea844a1aSMatthew Knepley @*/ 1613*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldOffset(PetscSection s, PetscInt point, PetscInt field, PetscInt *offset) 1614*d71ae5a4SJacob Faibussowitsch { 1615ea844a1aSMatthew Knepley PetscFunctionBegin; 1616ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 16172abc8c78SJacob Faibussowitsch PetscValidIntPointer(offset, 4); 16182abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 16199566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s->field[field], point, offset)); 1620ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1621ea844a1aSMatthew Knepley } 1622ea844a1aSMatthew Knepley 1623ea844a1aSMatthew Knepley /*@ 16241681d8a4SMatthew Knepley PetscSectionSetFieldOffset - Set the offset into an array or local Vec for the dof associated with the given field at a point. 1625ea844a1aSMatthew Knepley 162640750d41SVaclav Hapla Not Collective 1627ea844a1aSMatthew Knepley 1628ea844a1aSMatthew Knepley Input Parameters: 1629ea844a1aSMatthew Knepley + s - the PetscSection 1630ea844a1aSMatthew Knepley . point - the point 1631ea844a1aSMatthew Knepley . field - the field 1632ea844a1aSMatthew Knepley - offset - the offset 1633ea844a1aSMatthew Knepley 1634ea844a1aSMatthew Knepley Note: The user usually does not call this function, but uses PetscSectionSetUp() 1635ea844a1aSMatthew Knepley 1636ea844a1aSMatthew Knepley Level: intermediate 1637ea844a1aSMatthew Knepley 1638db781477SPatrick Sanan .seealso: `PetscSectionGetFieldOffset()`, `PetscSectionSetOffset()`, `PetscSectionCreate()`, `PetscSectionSetUp()` 1639ea844a1aSMatthew Knepley @*/ 1640*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldOffset(PetscSection s, PetscInt point, PetscInt field, PetscInt offset) 1641*d71ae5a4SJacob Faibussowitsch { 1642ea844a1aSMatthew Knepley PetscFunctionBegin; 1643ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 16442abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 16459566063dSJacob Faibussowitsch PetscCall(PetscSectionSetOffset(s->field[field], point, offset)); 1646ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1647ea844a1aSMatthew Knepley } 1648ea844a1aSMatthew Knepley 1649ea844a1aSMatthew Knepley /*@ 1650ea844a1aSMatthew Knepley PetscSectionGetFieldPointOffset - Return the offset on the given point for the dof associated with the given point. 1651ea844a1aSMatthew Knepley 165240750d41SVaclav Hapla Not Collective 1653ea844a1aSMatthew Knepley 1654ea844a1aSMatthew Knepley Input Parameters: 1655ea844a1aSMatthew Knepley + s - the PetscSection 1656ea844a1aSMatthew Knepley . point - the point 1657ea844a1aSMatthew Knepley - field - the field 1658ea844a1aSMatthew Knepley 1659ea844a1aSMatthew Knepley Output Parameter: 1660ea844a1aSMatthew Knepley . offset - the offset 1661ea844a1aSMatthew Knepley 1662ea844a1aSMatthew Knepley Note: This gives the offset on a point of the field, ignoring constraints, meaning starting at the first dof for 1663ea844a1aSMatthew Knepley this point, what number is the first dof with this field. 1664ea844a1aSMatthew Knepley 1665ea844a1aSMatthew Knepley Level: advanced 1666ea844a1aSMatthew Knepley 1667db781477SPatrick Sanan .seealso: `PetscSectionGetOffset()`, `PetscSectionCreate()` 1668ea844a1aSMatthew Knepley @*/ 1669*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldPointOffset(PetscSection s, PetscInt point, PetscInt field, PetscInt *offset) 1670*d71ae5a4SJacob Faibussowitsch { 1671ea844a1aSMatthew Knepley PetscInt off, foff; 1672ea844a1aSMatthew Knepley 1673ea844a1aSMatthew Knepley PetscFunctionBegin; 1674ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 16752abc8c78SJacob Faibussowitsch PetscValidIntPointer(offset, 4); 16762abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 16779566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s, point, &off)); 16789566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s->field[field], point, &foff)); 1679ea844a1aSMatthew Knepley *offset = foff - off; 1680ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1681ea844a1aSMatthew Knepley } 1682ea844a1aSMatthew Knepley 1683ea844a1aSMatthew Knepley /*@ 1684ea844a1aSMatthew Knepley PetscSectionGetOffsetRange - Return the full range of offsets [start, end) 1685ea844a1aSMatthew Knepley 168640750d41SVaclav Hapla Not Collective 1687ea844a1aSMatthew Knepley 1688ea844a1aSMatthew Knepley Input Parameter: 1689ea844a1aSMatthew Knepley . s - the PetscSection 1690ea844a1aSMatthew Knepley 1691ea844a1aSMatthew Knepley Output Parameters: 1692ea844a1aSMatthew Knepley + start - the minimum offset 1693ea844a1aSMatthew Knepley - end - one more than the maximum offset 1694ea844a1aSMatthew Knepley 1695ea844a1aSMatthew Knepley Level: intermediate 1696ea844a1aSMatthew Knepley 1697db781477SPatrick Sanan .seealso: `PetscSectionGetOffset()`, `PetscSectionCreate()` 1698ea844a1aSMatthew Knepley @*/ 1699*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetOffsetRange(PetscSection s, PetscInt *start, PetscInt *end) 1700*d71ae5a4SJacob Faibussowitsch { 1701ea844a1aSMatthew Knepley PetscInt os = 0, oe = 0, pStart, pEnd, p; 1702ea844a1aSMatthew Knepley 1703ea844a1aSMatthew Knepley PetscFunctionBegin; 1704ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 17059371c9d4SSatish Balay if (s->atlasOff) { 17069371c9d4SSatish Balay os = s->atlasOff[0]; 17079371c9d4SSatish Balay oe = s->atlasOff[0]; 17089371c9d4SSatish Balay } 17099566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 1710ea844a1aSMatthew Knepley for (p = 0; p < pEnd - pStart; ++p) { 1711ea844a1aSMatthew Knepley PetscInt dof = s->atlasDof[p], off = s->atlasOff[p]; 1712ea844a1aSMatthew Knepley 1713ea844a1aSMatthew Knepley if (off >= 0) { 1714ea844a1aSMatthew Knepley os = PetscMin(os, off); 1715ea844a1aSMatthew Knepley oe = PetscMax(oe, off + dof); 1716ea844a1aSMatthew Knepley } 1717ea844a1aSMatthew Knepley } 1718ea844a1aSMatthew Knepley if (start) *start = os; 1719ea844a1aSMatthew Knepley if (end) *end = oe; 1720ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1721ea844a1aSMatthew Knepley } 1722ea844a1aSMatthew Knepley 1723ea844a1aSMatthew Knepley /*@ 1724ea844a1aSMatthew Knepley PetscSectionCreateSubsection - Create a new, smaller section composed of only the selected fields 1725ea844a1aSMatthew Knepley 172640750d41SVaclav Hapla Collective 1727ea844a1aSMatthew Knepley 1728d8d19677SJose E. Roman Input Parameters: 1729ea844a1aSMatthew Knepley + s - the PetscSection 1730ea844a1aSMatthew Knepley . len - the number of subfields 1731ea844a1aSMatthew Knepley - fields - the subfield numbers 1732ea844a1aSMatthew Knepley 1733ea844a1aSMatthew Knepley Output Parameter: 1734ea844a1aSMatthew Knepley . subs - the subsection 1735ea844a1aSMatthew Knepley 1736ea844a1aSMatthew Knepley Note: The section offsets now refer to a new, smaller vector. 1737ea844a1aSMatthew Knepley 1738ea844a1aSMatthew Knepley Level: advanced 1739ea844a1aSMatthew Knepley 1740db781477SPatrick Sanan .seealso: `PetscSectionCreateSupersection()`, `PetscSectionCreate()` 1741ea844a1aSMatthew Knepley @*/ 1742*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateSubsection(PetscSection s, PetscInt len, const PetscInt fields[], PetscSection *subs) 1743*d71ae5a4SJacob Faibussowitsch { 1744b778fa18SValeria Barra PetscInt nF, f, c, pStart, pEnd, p, maxCdof = 0; 1745ea844a1aSMatthew Knepley 1746ea844a1aSMatthew Knepley PetscFunctionBegin; 1747ea844a1aSMatthew Knepley if (!len) PetscFunctionReturn(0); 1748ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1749dadcf809SJacob Faibussowitsch PetscValidIntPointer(fields, 3); 1750ea844a1aSMatthew Knepley PetscValidPointer(subs, 4); 17519566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s, &nF)); 175208401ef6SPierre 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); 17539566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), subs)); 17549566063dSJacob Faibussowitsch PetscCall(PetscSectionSetNumFields(*subs, len)); 1755ea844a1aSMatthew Knepley for (f = 0; f < len; ++f) { 1756ea844a1aSMatthew Knepley const char *name = NULL; 1757ea844a1aSMatthew Knepley PetscInt numComp = 0; 1758ea844a1aSMatthew Knepley 17599566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldName(s, fields[f], &name)); 17609566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldName(*subs, f, name)); 17619566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s, fields[f], &numComp)); 17629566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(*subs, f, numComp)); 1763b778fa18SValeria Barra for (c = 0; c < s->numFieldComponents[fields[f]]; ++c) { 17649566063dSJacob Faibussowitsch PetscCall(PetscSectionGetComponentName(s, fields[f], c, &name)); 17659566063dSJacob Faibussowitsch PetscCall(PetscSectionSetComponentName(*subs, f, c, name)); 1766b778fa18SValeria Barra } 1767ea844a1aSMatthew Knepley } 17689566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 17699566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(*subs, pStart, pEnd)); 1770ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1771ea844a1aSMatthew Knepley PetscInt dof = 0, cdof = 0, fdof = 0, cfdof = 0; 1772ea844a1aSMatthew Knepley 1773ea844a1aSMatthew Knepley for (f = 0; f < len; ++f) { 17749566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, fields[f], &fdof)); 17759566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldDof(*subs, p, f, fdof)); 17769566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, fields[f], &cfdof)); 17779566063dSJacob Faibussowitsch if (cfdof) PetscCall(PetscSectionSetFieldConstraintDof(*subs, p, f, cfdof)); 1778ea844a1aSMatthew Knepley dof += fdof; 1779ea844a1aSMatthew Knepley cdof += cfdof; 1780ea844a1aSMatthew Knepley } 17819566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(*subs, p, dof)); 17829566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetConstraintDof(*subs, p, cdof)); 1783ea844a1aSMatthew Knepley maxCdof = PetscMax(cdof, maxCdof); 1784ea844a1aSMatthew Knepley } 17859566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(*subs)); 1786ea844a1aSMatthew Knepley if (maxCdof) { 1787ea844a1aSMatthew Knepley PetscInt *indices; 1788ea844a1aSMatthew Knepley 17899566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(maxCdof, &indices)); 1790ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1791ea844a1aSMatthew Knepley PetscInt cdof; 1792ea844a1aSMatthew Knepley 17939566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(*subs, p, &cdof)); 1794ea844a1aSMatthew Knepley if (cdof) { 1795ea844a1aSMatthew Knepley const PetscInt *oldIndices = NULL; 1796ea844a1aSMatthew Knepley PetscInt fdof = 0, cfdof = 0, fc, numConst = 0, fOff = 0; 1797ea844a1aSMatthew Knepley 1798ea844a1aSMatthew Knepley for (f = 0; f < len; ++f) { 17999566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, fields[f], &fdof)); 18009566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, fields[f], &cfdof)); 18019566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(s, p, fields[f], &oldIndices)); 18029566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldConstraintIndices(*subs, p, f, oldIndices)); 18039574d0f0SMatthew G. Knepley for (fc = 0; fc < cfdof; ++fc) indices[numConst + fc] = oldIndices[fc] + fOff; 1804ea844a1aSMatthew Knepley numConst += cfdof; 1805ea844a1aSMatthew Knepley fOff += fdof; 1806ea844a1aSMatthew Knepley } 18079566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(*subs, p, indices)); 1808ea844a1aSMatthew Knepley } 1809ea844a1aSMatthew Knepley } 18109566063dSJacob Faibussowitsch PetscCall(PetscFree(indices)); 1811ea844a1aSMatthew Knepley } 1812ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1813ea844a1aSMatthew Knepley } 1814ea844a1aSMatthew Knepley 1815ea844a1aSMatthew Knepley /*@ 1816ea844a1aSMatthew Knepley PetscSectionCreateSupersection - Create a new, larger section composed of the input sections 1817ea844a1aSMatthew Knepley 181840750d41SVaclav Hapla Collective 1819ea844a1aSMatthew Knepley 1820ea844a1aSMatthew Knepley Input Parameters: 1821ea844a1aSMatthew Knepley + s - the input sections 1822ea844a1aSMatthew Knepley - len - the number of input sections 1823ea844a1aSMatthew Knepley 1824ea844a1aSMatthew Knepley Output Parameter: 1825ea844a1aSMatthew Knepley . supers - the supersection 1826ea844a1aSMatthew Knepley 1827ea844a1aSMatthew Knepley Note: The section offsets now refer to a new, larger vector. 1828ea844a1aSMatthew Knepley 1829ea844a1aSMatthew Knepley Level: advanced 1830ea844a1aSMatthew Knepley 1831db781477SPatrick Sanan .seealso: `PetscSectionCreateSubsection()`, `PetscSectionCreate()` 1832ea844a1aSMatthew Knepley @*/ 1833*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateSupersection(PetscSection s[], PetscInt len, PetscSection *supers) 1834*d71ae5a4SJacob Faibussowitsch { 1835ea844a1aSMatthew Knepley PetscInt Nf = 0, f, pStart = PETSC_MAX_INT, pEnd = 0, p, maxCdof = 0, i; 1836ea844a1aSMatthew Knepley 1837ea844a1aSMatthew Knepley PetscFunctionBegin; 1838ea844a1aSMatthew Knepley if (!len) PetscFunctionReturn(0); 1839ea844a1aSMatthew Knepley for (i = 0; i < len; ++i) { 1840ea844a1aSMatthew Knepley PetscInt nf, pStarti, pEndi; 1841ea844a1aSMatthew Knepley 18429566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s[i], &nf)); 18439566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s[i], &pStarti, &pEndi)); 1844ea844a1aSMatthew Knepley pStart = PetscMin(pStart, pStarti); 1845ea844a1aSMatthew Knepley pEnd = PetscMax(pEnd, pEndi); 1846ea844a1aSMatthew Knepley Nf += nf; 1847ea844a1aSMatthew Knepley } 18489566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s[0]), supers)); 18499566063dSJacob Faibussowitsch PetscCall(PetscSectionSetNumFields(*supers, Nf)); 1850ea844a1aSMatthew Knepley for (i = 0, f = 0; i < len; ++i) { 1851b778fa18SValeria Barra PetscInt nf, fi, ci; 1852ea844a1aSMatthew Knepley 18539566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s[i], &nf)); 1854ea844a1aSMatthew Knepley for (fi = 0; fi < nf; ++fi, ++f) { 1855ea844a1aSMatthew Knepley const char *name = NULL; 1856ea844a1aSMatthew Knepley PetscInt numComp = 0; 1857ea844a1aSMatthew Knepley 18589566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldName(s[i], fi, &name)); 18599566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldName(*supers, f, name)); 18609566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s[i], fi, &numComp)); 18619566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(*supers, f, numComp)); 1862b778fa18SValeria Barra for (ci = 0; ci < s[i]->numFieldComponents[fi]; ++ci) { 18639566063dSJacob Faibussowitsch PetscCall(PetscSectionGetComponentName(s[i], fi, ci, &name)); 18649566063dSJacob Faibussowitsch PetscCall(PetscSectionSetComponentName(*supers, f, ci, name)); 1865b778fa18SValeria Barra } 1866ea844a1aSMatthew Knepley } 1867ea844a1aSMatthew Knepley } 18689566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(*supers, pStart, pEnd)); 1869ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1870ea844a1aSMatthew Knepley PetscInt dof = 0, cdof = 0; 1871ea844a1aSMatthew Knepley 1872ea844a1aSMatthew Knepley for (i = 0, f = 0; i < len; ++i) { 1873ea844a1aSMatthew Knepley PetscInt nf, fi, pStarti, pEndi; 1874ea844a1aSMatthew Knepley PetscInt fdof = 0, cfdof = 0; 1875ea844a1aSMatthew Knepley 18769566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s[i], &nf)); 18779566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s[i], &pStarti, &pEndi)); 1878ea844a1aSMatthew Knepley if ((p < pStarti) || (p >= pEndi)) continue; 1879ea844a1aSMatthew Knepley for (fi = 0; fi < nf; ++fi, ++f) { 18809566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s[i], p, fi, &fdof)); 18819566063dSJacob Faibussowitsch PetscCall(PetscSectionAddFieldDof(*supers, p, f, fdof)); 18829566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s[i], p, fi, &cfdof)); 18839566063dSJacob Faibussowitsch if (cfdof) PetscCall(PetscSectionAddFieldConstraintDof(*supers, p, f, cfdof)); 1884ea844a1aSMatthew Knepley dof += fdof; 1885ea844a1aSMatthew Knepley cdof += cfdof; 1886ea844a1aSMatthew Knepley } 1887ea844a1aSMatthew Knepley } 18889566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(*supers, p, dof)); 18899566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetConstraintDof(*supers, p, cdof)); 1890ea844a1aSMatthew Knepley maxCdof = PetscMax(cdof, maxCdof); 1891ea844a1aSMatthew Knepley } 18929566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(*supers)); 1893ea844a1aSMatthew Knepley if (maxCdof) { 1894ea844a1aSMatthew Knepley PetscInt *indices; 1895ea844a1aSMatthew Knepley 18969566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(maxCdof, &indices)); 1897ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1898ea844a1aSMatthew Knepley PetscInt cdof; 1899ea844a1aSMatthew Knepley 19009566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(*supers, p, &cdof)); 1901ea844a1aSMatthew Knepley if (cdof) { 1902ea844a1aSMatthew Knepley PetscInt dof, numConst = 0, fOff = 0; 1903ea844a1aSMatthew Knepley 1904ea844a1aSMatthew Knepley for (i = 0, f = 0; i < len; ++i) { 1905ea844a1aSMatthew Knepley const PetscInt *oldIndices = NULL; 1906ea844a1aSMatthew Knepley PetscInt nf, fi, pStarti, pEndi, fdof, cfdof, fc; 1907ea844a1aSMatthew Knepley 19089566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s[i], &nf)); 19099566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s[i], &pStarti, &pEndi)); 1910ea844a1aSMatthew Knepley if ((p < pStarti) || (p >= pEndi)) continue; 1911ea844a1aSMatthew Knepley for (fi = 0; fi < nf; ++fi, ++f) { 19129566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s[i], p, fi, &fdof)); 19139566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s[i], p, fi, &cfdof)); 19149566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(s[i], p, fi, &oldIndices)); 1915fcd2503dSMatthew G. Knepley for (fc = 0; fc < cfdof; ++fc) indices[numConst + fc] = oldIndices[fc]; 19169566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldConstraintIndices(*supers, p, f, &indices[numConst])); 1917fcd2503dSMatthew G. Knepley for (fc = 0; fc < cfdof; ++fc) indices[numConst + fc] += fOff; 1918ea844a1aSMatthew Knepley numConst += cfdof; 1919ea844a1aSMatthew Knepley } 19209566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s[i], p, &dof)); 1921ea844a1aSMatthew Knepley fOff += dof; 1922ea844a1aSMatthew Knepley } 19239566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(*supers, p, indices)); 1924ea844a1aSMatthew Knepley } 1925ea844a1aSMatthew Knepley } 19269566063dSJacob Faibussowitsch PetscCall(PetscFree(indices)); 1927ea844a1aSMatthew Knepley } 1928ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1929ea844a1aSMatthew Knepley } 1930ea844a1aSMatthew Knepley 1931*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateSubplexSection_Internal(PetscSection s, IS subpointMap, PetscBool renumberPoints, PetscSection *subs) 1932*d71ae5a4SJacob Faibussowitsch { 1933ea844a1aSMatthew Knepley const PetscInt *points = NULL, *indices = NULL; 193441f23ed0SMatthew G. Knepley PetscInt numFields, f, c, numSubpoints = 0, pStart, pEnd, p, spStart, spEnd, subp; 1935ea844a1aSMatthew Knepley 1936ea844a1aSMatthew Knepley PetscFunctionBegin; 1937ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1938ea844a1aSMatthew Knepley PetscValidHeaderSpecific(subpointMap, IS_CLASSID, 2); 193941f23ed0SMatthew G. Knepley PetscValidPointer(subs, 4); 19409566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s, &numFields)); 19419566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), subs)); 19429566063dSJacob Faibussowitsch if (numFields) PetscCall(PetscSectionSetNumFields(*subs, numFields)); 1943ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 1944ea844a1aSMatthew Knepley const char *name = NULL; 1945ea844a1aSMatthew Knepley PetscInt numComp = 0; 1946ea844a1aSMatthew Knepley 19479566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldName(s, f, &name)); 19489566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldName(*subs, f, name)); 19499566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s, f, &numComp)); 19509566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(*subs, f, numComp)); 1951b778fa18SValeria Barra for (c = 0; c < s->numFieldComponents[f]; ++c) { 19529566063dSJacob Faibussowitsch PetscCall(PetscSectionGetComponentName(s, f, c, &name)); 19539566063dSJacob Faibussowitsch PetscCall(PetscSectionSetComponentName(*subs, f, c, name)); 1954b778fa18SValeria Barra } 1955ea844a1aSMatthew Knepley } 1956ea844a1aSMatthew Knepley /* For right now, we do not try to squeeze the subchart */ 1957ea844a1aSMatthew Knepley if (subpointMap) { 19589566063dSJacob Faibussowitsch PetscCall(ISGetSize(subpointMap, &numSubpoints)); 19599566063dSJacob Faibussowitsch PetscCall(ISGetIndices(subpointMap, &points)); 1960ea844a1aSMatthew Knepley } 19619566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 196241f23ed0SMatthew G. Knepley if (renumberPoints) { 196341f23ed0SMatthew G. Knepley spStart = 0; 196441f23ed0SMatthew G. Knepley spEnd = numSubpoints; 196541f23ed0SMatthew G. Knepley } else { 196641f23ed0SMatthew G. Knepley PetscCall(ISGetMinMax(subpointMap, &spStart, &spEnd)); 196741f23ed0SMatthew G. Knepley ++spEnd; 196841f23ed0SMatthew G. Knepley } 196941f23ed0SMatthew G. Knepley PetscCall(PetscSectionSetChart(*subs, spStart, spEnd)); 1970ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1971ea844a1aSMatthew Knepley PetscInt dof, cdof, fdof = 0, cfdof = 0; 1972ea844a1aSMatthew Knepley 19739566063dSJacob Faibussowitsch PetscCall(PetscFindInt(p, numSubpoints, points, &subp)); 1974ea844a1aSMatthew Knepley if (subp < 0) continue; 197541f23ed0SMatthew G. Knepley if (!renumberPoints) subp = p; 1976ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 19779566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, f, &fdof)); 19789566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldDof(*subs, subp, f, fdof)); 19799566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, f, &cfdof)); 19809566063dSJacob Faibussowitsch if (cfdof) PetscCall(PetscSectionSetFieldConstraintDof(*subs, subp, f, cfdof)); 1981ea844a1aSMatthew Knepley } 19829566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 19839566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(*subs, subp, dof)); 19849566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof)); 19859566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetConstraintDof(*subs, subp, cdof)); 1986ea844a1aSMatthew Knepley } 19879566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(*subs)); 1988ea844a1aSMatthew Knepley /* Change offsets to original offsets */ 1989ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1990ea844a1aSMatthew Knepley PetscInt off, foff = 0; 1991ea844a1aSMatthew Knepley 19929566063dSJacob Faibussowitsch PetscCall(PetscFindInt(p, numSubpoints, points, &subp)); 1993ea844a1aSMatthew Knepley if (subp < 0) continue; 199441f23ed0SMatthew G. Knepley if (!renumberPoints) subp = p; 1995ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 19969566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldOffset(s, p, f, &foff)); 19979566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldOffset(*subs, subp, f, foff)); 1998ea844a1aSMatthew Knepley } 19999566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s, p, &off)); 20009566063dSJacob Faibussowitsch PetscCall(PetscSectionSetOffset(*subs, subp, off)); 2001ea844a1aSMatthew Knepley } 2002ea844a1aSMatthew Knepley /* Copy constraint indices */ 200341f23ed0SMatthew G. Knepley for (subp = spStart; subp < spEnd; ++subp) { 2004ea844a1aSMatthew Knepley PetscInt cdof; 2005ea844a1aSMatthew Knepley 20069566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(*subs, subp, &cdof)); 2007ea844a1aSMatthew Knepley if (cdof) { 2008ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 200941f23ed0SMatthew G. Knepley PetscCall(PetscSectionGetFieldConstraintIndices(s, points[subp - spStart], f, &indices)); 20109566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldConstraintIndices(*subs, subp, f, indices)); 2011ea844a1aSMatthew Knepley } 201241f23ed0SMatthew G. Knepley PetscCall(PetscSectionGetConstraintIndices(s, points[subp - spStart], &indices)); 20139566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(*subs, subp, indices)); 2014ea844a1aSMatthew Knepley } 2015ea844a1aSMatthew Knepley } 20169566063dSJacob Faibussowitsch if (subpointMap) PetscCall(ISRestoreIndices(subpointMap, &points)); 2017ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2018ea844a1aSMatthew Knepley } 2019ea844a1aSMatthew Knepley 202041f23ed0SMatthew G. Knepley /*@ 202141f23ed0SMatthew G. Knepley PetscSectionCreateSubmeshSection - Create a new, smaller section with support on the submesh 202241f23ed0SMatthew G. Knepley 202341f23ed0SMatthew G. Knepley Collective on s 202441f23ed0SMatthew G. Knepley 202541f23ed0SMatthew G. Knepley Input Parameters: 202641f23ed0SMatthew G. Knepley + s - the PetscSection 202741f23ed0SMatthew G. Knepley - subpointMap - a sorted list of points in the original mesh which are in the submesh 202841f23ed0SMatthew G. Knepley 202941f23ed0SMatthew G. Knepley Output Parameter: 203041f23ed0SMatthew G. Knepley . subs - the subsection 203141f23ed0SMatthew G. Knepley 203241f23ed0SMatthew G. Knepley Note: 203341f23ed0SMatthew G. Knepley The points are renumbered from 0, and the section offsets now refer to a new, smaller vector. 203441f23ed0SMatthew G. Knepley 203541f23ed0SMatthew G. Knepley Level: advanced 203641f23ed0SMatthew G. Knepley 2037db781477SPatrick Sanan .seealso: `PetscSectionCreateSubdomainSection()`, `PetscSectionCreateSubsection()`, `DMPlexGetSubpointMap()`, `PetscSectionCreate()` 203841f23ed0SMatthew G. Knepley @*/ 2039*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateSubmeshSection(PetscSection s, IS subpointMap, PetscSection *subs) 2040*d71ae5a4SJacob Faibussowitsch { 204141f23ed0SMatthew G. Knepley PetscFunctionBegin; 204241f23ed0SMatthew G. Knepley PetscCall(PetscSectionCreateSubplexSection_Internal(s, subpointMap, PETSC_TRUE, subs)); 204341f23ed0SMatthew G. Knepley PetscFunctionReturn(0); 204441f23ed0SMatthew G. Knepley } 204541f23ed0SMatthew G. Knepley 204641f23ed0SMatthew G. Knepley /*@ 204741f23ed0SMatthew G. Knepley PetscSectionCreateSubdomainSection - Create a new, smaller section with support on a subdomain of the mesh 204841f23ed0SMatthew G. Knepley 204941f23ed0SMatthew G. Knepley Collective on s 205041f23ed0SMatthew G. Knepley 205141f23ed0SMatthew G. Knepley Input Parameters: 205241f23ed0SMatthew G. Knepley + s - the PetscSection 205341f23ed0SMatthew G. Knepley - subpointMap - a sorted list of points in the original mesh which are in the subdomain 205441f23ed0SMatthew G. Knepley 205541f23ed0SMatthew G. Knepley Output Parameter: 205641f23ed0SMatthew G. Knepley . subs - the subsection 205741f23ed0SMatthew G. Knepley 205841f23ed0SMatthew G. Knepley Note: 205941f23ed0SMatthew G. Knepley The point numbers remain the same, but the section offsets now refer to a new, smaller vector. 206041f23ed0SMatthew G. Knepley 206141f23ed0SMatthew G. Knepley Level: advanced 206241f23ed0SMatthew G. Knepley 2063db781477SPatrick Sanan .seealso: `PetscSectionCreateSubmeshSection()`, `PetscSectionCreateSubsection()`, `DMPlexGetSubpointMap()`, `PetscSectionCreate()` 206441f23ed0SMatthew G. Knepley @*/ 2065*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateSubdomainSection(PetscSection s, IS subpointMap, PetscSection *subs) 2066*d71ae5a4SJacob Faibussowitsch { 206741f23ed0SMatthew G. Knepley PetscFunctionBegin; 206841f23ed0SMatthew G. Knepley PetscCall(PetscSectionCreateSubplexSection_Internal(s, subpointMap, PETSC_FALSE, subs)); 206941f23ed0SMatthew G. Knepley PetscFunctionReturn(0); 207041f23ed0SMatthew G. Knepley } 207141f23ed0SMatthew G. Knepley 2072*d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscSectionView_ASCII(PetscSection s, PetscViewer viewer) 2073*d71ae5a4SJacob Faibussowitsch { 2074ea844a1aSMatthew Knepley PetscInt p; 2075ea844a1aSMatthew Knepley PetscMPIInt rank; 2076ea844a1aSMatthew Knepley 2077ea844a1aSMatthew Knepley PetscFunctionBegin; 20789566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_rank(PetscObjectComm((PetscObject)viewer), &rank)); 20799566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushSynchronized(viewer)); 20809566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "Process %d:\n", rank)); 2081ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) { 2082ea844a1aSMatthew Knepley if ((s->bc) && (s->bc->atlasDof[p] > 0)) { 2083ea844a1aSMatthew Knepley PetscInt b; 2084ea844a1aSMatthew Knepley 20859566063dSJacob 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])); 2086083401c6SMatthew G. Knepley if (s->bcIndices) { 208748a46eb9SPierre Jolivet for (b = 0; b < s->bc->atlasDof[p]; ++b) PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " %" PetscInt_FMT, s->bcIndices[s->bc->atlasOff[p] + b])); 2088083401c6SMatthew G. Knepley } 20899566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "\n")); 2090ea844a1aSMatthew Knepley } else { 20919566063dSJacob 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])); 2092ea844a1aSMatthew Knepley } 2093ea844a1aSMatthew Knepley } 20949566063dSJacob Faibussowitsch PetscCall(PetscViewerFlush(viewer)); 20959566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPopSynchronized(viewer)); 2096ea844a1aSMatthew Knepley if (s->sym) { 20979566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushTab(viewer)); 20989566063dSJacob Faibussowitsch PetscCall(PetscSectionSymView(s->sym, viewer)); 20999566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPopTab(viewer)); 2100ea844a1aSMatthew Knepley } 2101ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2102ea844a1aSMatthew Knepley } 2103ea844a1aSMatthew Knepley 2104ea844a1aSMatthew Knepley /*@C 2105fe2efc57SMark PetscSectionViewFromOptions - View from Options 2106fe2efc57SMark 210740750d41SVaclav Hapla Collective 2108fe2efc57SMark 2109fe2efc57SMark Input Parameters: 2110fe2efc57SMark + A - the PetscSection object to view 2111736c3998SJose E. Roman . obj - Optional object 2112736c3998SJose E. Roman - name - command line option 2113fe2efc57SMark 2114fe2efc57SMark Level: intermediate 2115db781477SPatrick Sanan .seealso: `PetscSection`, `PetscSectionView`, `PetscObjectViewFromOptions()`, `PetscSectionCreate()` 2116fe2efc57SMark @*/ 2117*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionViewFromOptions(PetscSection A, PetscObject obj, const char name[]) 2118*d71ae5a4SJacob Faibussowitsch { 2119fe2efc57SMark PetscFunctionBegin; 2120fe2efc57SMark PetscValidHeaderSpecific(A, PETSC_SECTION_CLASSID, 1); 21219566063dSJacob Faibussowitsch PetscCall(PetscObjectViewFromOptions((PetscObject)A, obj, name)); 2122fe2efc57SMark PetscFunctionReturn(0); 2123fe2efc57SMark } 2124fe2efc57SMark 2125fe2efc57SMark /*@C 2126ea844a1aSMatthew Knepley PetscSectionView - Views a PetscSection 2127ea844a1aSMatthew Knepley 212840750d41SVaclav Hapla Collective 2129ea844a1aSMatthew Knepley 2130ea844a1aSMatthew Knepley Input Parameters: 2131ea844a1aSMatthew Knepley + s - the PetscSection object to view 2132ea844a1aSMatthew Knepley - v - the viewer 2133ea844a1aSMatthew Knepley 21341ddd528eSksagiyam Note: 21351ddd528eSksagiyam PetscSectionView(), when viewer is of type PETSCVIEWERHDF5, only saves 21361ddd528eSksagiyam distribution independent data, such as dofs, offsets, constraint dofs, 21371ddd528eSksagiyam and constraint indices. Points that have negative dofs, for instance, 21381ddd528eSksagiyam are not saved as they represent points owned by other processes. 21391ddd528eSksagiyam Point numbering and rank assignment is currently not stored. 21401ddd528eSksagiyam The saved section can be loaded with PetscSectionLoad(). 21411ddd528eSksagiyam 2142ea844a1aSMatthew Knepley Level: beginner 2143ea844a1aSMatthew Knepley 2144db781477SPatrick Sanan .seealso `PetscSectionCreate()`, `PetscSectionDestroy()`, `PetscSectionLoad()` 2145ea844a1aSMatthew Knepley @*/ 2146*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionView(PetscSection s, PetscViewer viewer) 2147*d71ae5a4SJacob Faibussowitsch { 21481ddd528eSksagiyam PetscBool isascii, ishdf5; 2149ea844a1aSMatthew Knepley PetscInt f; 2150ea844a1aSMatthew Knepley 2151ea844a1aSMatthew Knepley PetscFunctionBegin; 2152ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 21539566063dSJacob Faibussowitsch if (!viewer) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)s), &viewer)); 2154ea844a1aSMatthew Knepley PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2); 21559566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii)); 21569566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERHDF5, &ishdf5)); 2157ea844a1aSMatthew Knepley if (isascii) { 21589566063dSJacob Faibussowitsch PetscCall(PetscObjectPrintClassNamePrefixType((PetscObject)s, viewer)); 2159ea844a1aSMatthew Knepley if (s->numFields) { 21609566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT " fields\n", s->numFields)); 2161ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) { 21629566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, " field %" PetscInt_FMT " with %" PetscInt_FMT " components\n", f, s->numFieldComponents[f])); 21639566063dSJacob Faibussowitsch PetscCall(PetscSectionView_ASCII(s->field[f], viewer)); 2164ea844a1aSMatthew Knepley } 2165ea844a1aSMatthew Knepley } else { 21669566063dSJacob Faibussowitsch PetscCall(PetscSectionView_ASCII(s, viewer)); 2167ea844a1aSMatthew Knepley } 21681ddd528eSksagiyam } else if (ishdf5) { 21691ddd528eSksagiyam #if PetscDefined(HAVE_HDF5) 21709566063dSJacob Faibussowitsch PetscCall(PetscSectionView_HDF5_Internal(s, viewer)); 21711ddd528eSksagiyam #else 21721ddd528eSksagiyam SETERRQ(PetscObjectComm((PetscObject)s), PETSC_ERR_SUP, "HDF5 not supported in this build.\nPlease reconfigure using --download-hdf5"); 21731ddd528eSksagiyam #endif 2174ea844a1aSMatthew Knepley } 2175ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2176ea844a1aSMatthew Knepley } 2177ea844a1aSMatthew Knepley 2178fde5e3acSksagiyam /*@C 2179fde5e3acSksagiyam PetscSectionLoad - Loads a PetscSection 2180fde5e3acSksagiyam 218140750d41SVaclav Hapla Collective 2182fde5e3acSksagiyam 2183fde5e3acSksagiyam Input Parameters: 2184fde5e3acSksagiyam + s - the PetscSection object to load 2185fde5e3acSksagiyam - v - the viewer 2186fde5e3acSksagiyam 2187fde5e3acSksagiyam Note: 2188fde5e3acSksagiyam PetscSectionLoad(), when viewer is of type PETSCVIEWERHDF5, loads 2189fde5e3acSksagiyam a section saved with PetscSectionView(). The number of processes 2190fde5e3acSksagiyam used here (N) does not need to be the same as that used when saving. 2191fde5e3acSksagiyam After calling this function, the chart of s on rank i will be set 2192fde5e3acSksagiyam to [0, E_i), where \sum_{i=0}^{N-1}E_i equals to the total number of 2193fde5e3acSksagiyam saved section points. 2194fde5e3acSksagiyam 2195fde5e3acSksagiyam Level: beginner 2196fde5e3acSksagiyam 2197db781477SPatrick Sanan .seealso `PetscSectionCreate()`, `PetscSectionDestroy()`, `PetscSectionView()` 2198fde5e3acSksagiyam @*/ 2199*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionLoad(PetscSection s, PetscViewer viewer) 2200*d71ae5a4SJacob Faibussowitsch { 2201fde5e3acSksagiyam PetscBool ishdf5; 2202fde5e3acSksagiyam 2203fde5e3acSksagiyam PetscFunctionBegin; 2204fde5e3acSksagiyam PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2205fde5e3acSksagiyam PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2); 22069566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERHDF5, &ishdf5)); 2207fde5e3acSksagiyam if (ishdf5) { 2208fde5e3acSksagiyam #if PetscDefined(HAVE_HDF5) 22099566063dSJacob Faibussowitsch PetscCall(PetscSectionLoad_HDF5_Internal(s, viewer)); 2210fde5e3acSksagiyam PetscFunctionReturn(0); 2211fde5e3acSksagiyam #else 2212fde5e3acSksagiyam SETERRQ(PetscObjectComm((PetscObject)s), PETSC_ERR_SUP, "HDF5 not supported in this build.\nPlease reconfigure using --download-hdf5"); 2213fde5e3acSksagiyam #endif 221498921bdaSJacob Faibussowitsch } else SETERRQ(PetscObjectComm((PetscObject)s), PETSC_ERR_SUP, "Viewer type %s not yet supported for PetscSection loading", ((PetscObject)viewer)->type_name); 2215fde5e3acSksagiyam } 2216fde5e3acSksagiyam 2217*d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscSectionResetClosurePermutation(PetscSection section) 2218*d71ae5a4SJacob Faibussowitsch { 2219c459fbc1SJed Brown PetscSectionClosurePermVal clVal; 2220c459fbc1SJed Brown 2221c459fbc1SJed Brown PetscFunctionBegin; 2222c459fbc1SJed Brown if (!section->clHash) PetscFunctionReturn(0); 2223c459fbc1SJed Brown kh_foreach_value(section->clHash, clVal, { 22249566063dSJacob Faibussowitsch PetscCall(PetscFree(clVal.perm)); 22259566063dSJacob Faibussowitsch PetscCall(PetscFree(clVal.invPerm)); 2226c459fbc1SJed Brown }); 2227c459fbc1SJed Brown kh_destroy(ClPerm, section->clHash); 2228c459fbc1SJed Brown section->clHash = NULL; 2229c459fbc1SJed Brown PetscFunctionReturn(0); 2230c459fbc1SJed Brown } 2231c459fbc1SJed Brown 2232ea844a1aSMatthew Knepley /*@ 2233ea844a1aSMatthew Knepley PetscSectionReset - Frees all section data. 2234ea844a1aSMatthew Knepley 223540750d41SVaclav Hapla Not Collective 2236ea844a1aSMatthew Knepley 2237ea844a1aSMatthew Knepley Input Parameters: 2238ea844a1aSMatthew Knepley . s - the PetscSection 2239ea844a1aSMatthew Knepley 2240ea844a1aSMatthew Knepley Level: beginner 2241ea844a1aSMatthew Knepley 2242db781477SPatrick Sanan .seealso: `PetscSection`, `PetscSectionCreate()` 2243ea844a1aSMatthew Knepley @*/ 2244*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionReset(PetscSection s) 2245*d71ae5a4SJacob Faibussowitsch { 2246b778fa18SValeria Barra PetscInt f, c; 2247ea844a1aSMatthew Knepley 2248ea844a1aSMatthew Knepley PetscFunctionBegin; 2249ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2250ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) { 22519566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->field[f])); 22529566063dSJacob Faibussowitsch PetscCall(PetscFree(s->fieldNames[f])); 225348a46eb9SPierre Jolivet for (c = 0; c < s->numFieldComponents[f]; ++c) PetscCall(PetscFree(s->compNames[f][c])); 22549566063dSJacob Faibussowitsch PetscCall(PetscFree(s->compNames[f])); 2255ea844a1aSMatthew Knepley } 22569566063dSJacob Faibussowitsch PetscCall(PetscFree(s->numFieldComponents)); 22579566063dSJacob Faibussowitsch PetscCall(PetscFree(s->fieldNames)); 22589566063dSJacob Faibussowitsch PetscCall(PetscFree(s->compNames)); 22599566063dSJacob Faibussowitsch PetscCall(PetscFree(s->field)); 22609566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->bc)); 22619566063dSJacob Faibussowitsch PetscCall(PetscFree(s->bcIndices)); 22629566063dSJacob Faibussowitsch PetscCall(PetscFree2(s->atlasDof, s->atlasOff)); 22639566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->clSection)); 22649566063dSJacob Faibussowitsch PetscCall(ISDestroy(&s->clPoints)); 22659566063dSJacob Faibussowitsch PetscCall(ISDestroy(&s->perm)); 22669566063dSJacob Faibussowitsch PetscCall(PetscSectionResetClosurePermutation(s)); 22679566063dSJacob Faibussowitsch PetscCall(PetscSectionSymDestroy(&s->sym)); 22689566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->clSection)); 22699566063dSJacob Faibussowitsch PetscCall(ISDestroy(&s->clPoints)); 227069c11d05SVaclav Hapla PetscCall(PetscSectionInvalidateMaxDof_Internal(s)); 2271ea844a1aSMatthew Knepley s->pStart = -1; 2272ea844a1aSMatthew Knepley s->pEnd = -1; 2273ea844a1aSMatthew Knepley s->maxDof = 0; 2274ea844a1aSMatthew Knepley s->setup = PETSC_FALSE; 2275ea844a1aSMatthew Knepley s->numFields = 0; 2276ea844a1aSMatthew Knepley s->clObj = NULL; 2277ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2278ea844a1aSMatthew Knepley } 2279ea844a1aSMatthew Knepley 2280ea844a1aSMatthew Knepley /*@ 2281ea844a1aSMatthew Knepley PetscSectionDestroy - Frees a section object and frees its range if that exists. 2282ea844a1aSMatthew Knepley 228340750d41SVaclav Hapla Not Collective 2284ea844a1aSMatthew Knepley 2285ea844a1aSMatthew Knepley Input Parameters: 2286ea844a1aSMatthew Knepley . s - the PetscSection 2287ea844a1aSMatthew Knepley 2288ea844a1aSMatthew Knepley Level: beginner 2289ea844a1aSMatthew Knepley 2290db781477SPatrick Sanan .seealso: `PetscSection`, `PetscSectionCreate()` 2291ea844a1aSMatthew Knepley @*/ 2292*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionDestroy(PetscSection *s) 2293*d71ae5a4SJacob Faibussowitsch { 2294ea844a1aSMatthew Knepley PetscFunctionBegin; 2295ea844a1aSMatthew Knepley if (!*s) PetscFunctionReturn(0); 229662f17a49SStefano Zampini PetscValidHeaderSpecific(*s, PETSC_SECTION_CLASSID, 1); 2297ea844a1aSMatthew Knepley if (--((PetscObject)(*s))->refct > 0) { 2298ea844a1aSMatthew Knepley *s = NULL; 2299ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2300ea844a1aSMatthew Knepley } 23019566063dSJacob Faibussowitsch PetscCall(PetscSectionReset(*s)); 23029566063dSJacob Faibussowitsch PetscCall(PetscHeaderDestroy(s)); 2303ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2304ea844a1aSMatthew Knepley } 2305ea844a1aSMatthew Knepley 2306*d71ae5a4SJacob Faibussowitsch PetscErrorCode VecIntGetValuesSection(PetscInt *baseArray, PetscSection s, PetscInt point, const PetscInt **values) 2307*d71ae5a4SJacob Faibussowitsch { 2308ea844a1aSMatthew Knepley const PetscInt p = point - s->pStart; 2309ea844a1aSMatthew Knepley 2310ea844a1aSMatthew Knepley PetscFunctionBegin; 2311ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 2); 2312ea844a1aSMatthew Knepley *values = &baseArray[s->atlasOff[p]]; 2313ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2314ea844a1aSMatthew Knepley } 2315ea844a1aSMatthew Knepley 2316*d71ae5a4SJacob Faibussowitsch PetscErrorCode VecIntSetValuesSection(PetscInt *baseArray, PetscSection s, PetscInt point, const PetscInt values[], InsertMode mode) 2317*d71ae5a4SJacob Faibussowitsch { 2318ea844a1aSMatthew Knepley PetscInt *array; 2319ea844a1aSMatthew Knepley const PetscInt p = point - s->pStart; 2320ea844a1aSMatthew Knepley const PetscInt orientation = 0; /* Needs to be included for use in closure operations */ 2321ea844a1aSMatthew Knepley PetscInt cDim = 0; 2322ea844a1aSMatthew Knepley 2323ea844a1aSMatthew Knepley PetscFunctionBegin; 2324ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 2); 23259566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cDim)); 2326ea844a1aSMatthew Knepley array = &baseArray[s->atlasOff[p]]; 2327ea844a1aSMatthew Knepley if (!cDim) { 2328ea844a1aSMatthew Knepley if (orientation >= 0) { 2329ea844a1aSMatthew Knepley const PetscInt dim = s->atlasDof[p]; 2330ea844a1aSMatthew Knepley PetscInt i; 2331ea844a1aSMatthew Knepley 2332ea844a1aSMatthew Knepley if (mode == INSERT_VALUES) { 2333ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) array[i] = values[i]; 2334ea844a1aSMatthew Knepley } else { 2335ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) array[i] += values[i]; 2336ea844a1aSMatthew Knepley } 2337ea844a1aSMatthew Knepley } else { 2338ea844a1aSMatthew Knepley PetscInt offset = 0; 2339ea844a1aSMatthew Knepley PetscInt j = -1, field, i; 2340ea844a1aSMatthew Knepley 2341ea844a1aSMatthew Knepley for (field = 0; field < s->numFields; ++field) { 2342ea844a1aSMatthew Knepley const PetscInt dim = s->field[field]->atlasDof[p]; 2343ea844a1aSMatthew Knepley 2344ea844a1aSMatthew Knepley for (i = dim - 1; i >= 0; --i) array[++j] = values[i + offset]; 2345ea844a1aSMatthew Knepley offset += dim; 2346ea844a1aSMatthew Knepley } 2347ea844a1aSMatthew Knepley } 2348ea844a1aSMatthew Knepley } else { 2349ea844a1aSMatthew Knepley if (orientation >= 0) { 2350ea844a1aSMatthew Knepley const PetscInt dim = s->atlasDof[p]; 2351ea844a1aSMatthew Knepley PetscInt cInd = 0, i; 2352ea844a1aSMatthew Knepley const PetscInt *cDof; 2353ea844a1aSMatthew Knepley 23549566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s, point, &cDof)); 2355ea844a1aSMatthew Knepley if (mode == INSERT_VALUES) { 2356ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) { 23579371c9d4SSatish Balay if ((cInd < cDim) && (i == cDof[cInd])) { 23589371c9d4SSatish Balay ++cInd; 23599371c9d4SSatish Balay continue; 23609371c9d4SSatish Balay } 2361ea844a1aSMatthew Knepley array[i] = values[i]; 2362ea844a1aSMatthew Knepley } 2363ea844a1aSMatthew Knepley } else { 2364ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) { 23659371c9d4SSatish Balay if ((cInd < cDim) && (i == cDof[cInd])) { 23669371c9d4SSatish Balay ++cInd; 23679371c9d4SSatish Balay continue; 23689371c9d4SSatish Balay } 2369ea844a1aSMatthew Knepley array[i] += values[i]; 2370ea844a1aSMatthew Knepley } 2371ea844a1aSMatthew Knepley } 2372ea844a1aSMatthew Knepley } else { 2373ea844a1aSMatthew Knepley const PetscInt *cDof; 2374ea844a1aSMatthew Knepley PetscInt offset = 0; 2375ea844a1aSMatthew Knepley PetscInt cOffset = 0; 2376ea844a1aSMatthew Knepley PetscInt j = 0, field; 2377ea844a1aSMatthew Knepley 23789566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s, point, &cDof)); 2379ea844a1aSMatthew Knepley for (field = 0; field < s->numFields; ++field) { 2380ea844a1aSMatthew Knepley const PetscInt dim = s->field[field]->atlasDof[p]; /* PetscSectionGetFieldDof() */ 2381ea844a1aSMatthew Knepley const PetscInt tDim = s->field[field]->bc->atlasDof[p]; /* PetscSectionGetFieldConstraintDof() */ 2382ea844a1aSMatthew Knepley const PetscInt sDim = dim - tDim; 2383ea844a1aSMatthew Knepley PetscInt cInd = 0, i, k; 2384ea844a1aSMatthew Knepley 2385ea844a1aSMatthew Knepley for (i = 0, k = dim + offset - 1; i < dim; ++i, ++j, --k) { 23869371c9d4SSatish Balay if ((cInd < sDim) && (j == cDof[cInd + cOffset])) { 23879371c9d4SSatish Balay ++cInd; 23889371c9d4SSatish Balay continue; 23899371c9d4SSatish Balay } 2390ea844a1aSMatthew Knepley array[j] = values[k]; 2391ea844a1aSMatthew Knepley } 2392ea844a1aSMatthew Knepley offset += dim; 2393ea844a1aSMatthew Knepley cOffset += dim - tDim; 2394ea844a1aSMatthew Knepley } 2395ea844a1aSMatthew Knepley } 2396ea844a1aSMatthew Knepley } 2397ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2398ea844a1aSMatthew Knepley } 2399ea844a1aSMatthew Knepley 2400ea844a1aSMatthew Knepley /*@C 2401ea844a1aSMatthew Knepley PetscSectionHasConstraints - Determine whether a section has constrained dofs 2402ea844a1aSMatthew Knepley 240340750d41SVaclav Hapla Not Collective 2404ea844a1aSMatthew Knepley 2405ea844a1aSMatthew Knepley Input Parameter: 2406ea844a1aSMatthew Knepley . s - The PetscSection 2407ea844a1aSMatthew Knepley 2408ea844a1aSMatthew Knepley Output Parameter: 2409ea844a1aSMatthew Knepley . hasConstraints - flag indicating that the section has constrained dofs 2410ea844a1aSMatthew Knepley 2411ea844a1aSMatthew Knepley Level: intermediate 2412ea844a1aSMatthew Knepley 2413db781477SPatrick Sanan .seealso: `PetscSectionSetConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection` 2414ea844a1aSMatthew Knepley @*/ 2415*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionHasConstraints(PetscSection s, PetscBool *hasConstraints) 2416*d71ae5a4SJacob Faibussowitsch { 2417ea844a1aSMatthew Knepley PetscFunctionBegin; 2418ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2419dadcf809SJacob Faibussowitsch PetscValidBoolPointer(hasConstraints, 2); 2420ea844a1aSMatthew Knepley *hasConstraints = s->bc ? PETSC_TRUE : PETSC_FALSE; 2421ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2422ea844a1aSMatthew Knepley } 2423ea844a1aSMatthew Knepley 2424ea844a1aSMatthew Knepley /*@C 2425ea844a1aSMatthew Knepley PetscSectionGetConstraintIndices - Get the point dof numbers, in [0, dof), which are constrained 2426ea844a1aSMatthew Knepley 242740750d41SVaclav Hapla Not Collective 2428ea844a1aSMatthew Knepley 2429ea844a1aSMatthew Knepley Input Parameters: 2430ea844a1aSMatthew Knepley + s - The PetscSection 2431ea844a1aSMatthew Knepley - point - The point 2432ea844a1aSMatthew Knepley 2433ea844a1aSMatthew Knepley Output Parameter: 2434ea844a1aSMatthew Knepley . indices - The constrained dofs 2435ea844a1aSMatthew Knepley 2436ea844a1aSMatthew Knepley Note: In Fortran, you call PetscSectionGetConstraintIndicesF90() and PetscSectionRestoreConstraintIndicesF90() 2437ea844a1aSMatthew Knepley 2438ea844a1aSMatthew Knepley Level: intermediate 2439ea844a1aSMatthew Knepley 2440db781477SPatrick Sanan .seealso: `PetscSectionSetConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection` 2441ea844a1aSMatthew Knepley @*/ 2442*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetConstraintIndices(PetscSection s, PetscInt point, const PetscInt **indices) 2443*d71ae5a4SJacob Faibussowitsch { 2444ea844a1aSMatthew Knepley PetscFunctionBegin; 2445ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2446ea844a1aSMatthew Knepley if (s->bc) { 24479566063dSJacob Faibussowitsch PetscCall(VecIntGetValuesSection(s->bcIndices, s->bc, point, indices)); 2448ea844a1aSMatthew Knepley } else *indices = NULL; 2449ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2450ea844a1aSMatthew Knepley } 2451ea844a1aSMatthew Knepley 2452ea844a1aSMatthew Knepley /*@C 2453ea844a1aSMatthew Knepley PetscSectionSetConstraintIndices - Set the point dof numbers, in [0, dof), which are constrained 2454ea844a1aSMatthew Knepley 245540750d41SVaclav Hapla Not Collective 2456ea844a1aSMatthew Knepley 2457ea844a1aSMatthew Knepley Input Parameters: 2458ea844a1aSMatthew Knepley + s - The PetscSection 2459ea844a1aSMatthew Knepley . point - The point 2460ea844a1aSMatthew Knepley - indices - The constrained dofs 2461ea844a1aSMatthew Knepley 2462ea844a1aSMatthew Knepley Note: The Fortran is PetscSectionSetConstraintIndicesF90() 2463ea844a1aSMatthew Knepley 2464ea844a1aSMatthew Knepley Level: intermediate 2465ea844a1aSMatthew Knepley 2466db781477SPatrick Sanan .seealso: `PetscSectionGetConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection` 2467ea844a1aSMatthew Knepley @*/ 2468*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetConstraintIndices(PetscSection s, PetscInt point, const PetscInt indices[]) 2469*d71ae5a4SJacob Faibussowitsch { 2470ea844a1aSMatthew Knepley PetscFunctionBegin; 2471ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2472ea844a1aSMatthew Knepley if (s->bc) { 2473d57bb9dbSMatthew G. Knepley const PetscInt dof = s->atlasDof[point]; 2474d57bb9dbSMatthew G. Knepley const PetscInt cdof = s->bc->atlasDof[point]; 2475d57bb9dbSMatthew G. Knepley PetscInt d; 2476d57bb9dbSMatthew G. Knepley 2477ad540459SPierre 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]); 24789566063dSJacob Faibussowitsch PetscCall(VecIntSetValuesSection(s->bcIndices, s->bc, point, indices, INSERT_VALUES)); 2479ea844a1aSMatthew Knepley } 2480ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2481ea844a1aSMatthew Knepley } 2482ea844a1aSMatthew Knepley 2483ea844a1aSMatthew Knepley /*@C 2484ea844a1aSMatthew Knepley PetscSectionGetFieldConstraintIndices - Get the field dof numbers, in [0, fdof), which are constrained 2485ea844a1aSMatthew Knepley 248640750d41SVaclav Hapla Not Collective 2487ea844a1aSMatthew Knepley 2488ea844a1aSMatthew Knepley Input Parameters: 2489ea844a1aSMatthew Knepley + s - The PetscSection 2490ea844a1aSMatthew Knepley . field - The field number 2491ea844a1aSMatthew Knepley - point - The point 2492ea844a1aSMatthew Knepley 2493ea844a1aSMatthew Knepley Output Parameter: 24949759eb26SJed Brown . indices - The constrained dofs sorted in ascending order 2495ea844a1aSMatthew Knepley 24969759eb26SJed Brown Notes: 24979759eb26SJed Brown 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(). 24989759eb26SJed Brown 24999759eb26SJed Brown Fortran Note: 25009759eb26SJed Brown In Fortran, you call PetscSectionGetFieldConstraintIndicesF90() and PetscSectionRestoreFieldConstraintIndicesF90() 2501ea844a1aSMatthew Knepley 2502ea844a1aSMatthew Knepley Level: intermediate 2503ea844a1aSMatthew Knepley 2504db781477SPatrick Sanan .seealso: `PetscSectionSetFieldConstraintIndices()`, `PetscSectionGetConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection` 2505ea844a1aSMatthew Knepley @*/ 2506*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldConstraintIndices(PetscSection s, PetscInt point, PetscInt field, const PetscInt **indices) 2507*d71ae5a4SJacob Faibussowitsch { 2508ea844a1aSMatthew Knepley PetscFunctionBegin; 2509ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2510dadcf809SJacob Faibussowitsch PetscValidPointer(indices, 4); 25112abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 25129566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s->field[field], point, indices)); 2513ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2514ea844a1aSMatthew Knepley } 2515ea844a1aSMatthew Knepley 2516ea844a1aSMatthew Knepley /*@C 2517ea844a1aSMatthew Knepley PetscSectionSetFieldConstraintIndices - Set the field dof numbers, in [0, fdof), which are constrained 2518ea844a1aSMatthew Knepley 251940750d41SVaclav Hapla Not Collective 2520ea844a1aSMatthew Knepley 2521ea844a1aSMatthew Knepley Input Parameters: 2522ea844a1aSMatthew Knepley + s - The PetscSection 2523ea844a1aSMatthew Knepley . point - The point 2524ea844a1aSMatthew Knepley . field - The field number 2525ea844a1aSMatthew Knepley - indices - The constrained dofs 2526ea844a1aSMatthew Knepley 2527ea844a1aSMatthew Knepley Note: The Fortran is PetscSectionSetFieldConstraintIndicesF90() 2528ea844a1aSMatthew Knepley 2529ea844a1aSMatthew Knepley Level: intermediate 2530ea844a1aSMatthew Knepley 2531db781477SPatrick Sanan .seealso: `PetscSectionSetConstraintIndices()`, `PetscSectionGetFieldConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection` 2532ea844a1aSMatthew Knepley @*/ 2533*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldConstraintIndices(PetscSection s, PetscInt point, PetscInt field, const PetscInt indices[]) 2534*d71ae5a4SJacob Faibussowitsch { 2535ea844a1aSMatthew Knepley PetscFunctionBegin; 2536ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 25372abc8c78SJacob Faibussowitsch if (PetscDefined(USE_DEBUG)) { 2538e2bfaee7SMatthew G. Knepley PetscInt nfdof; 25392abc8c78SJacob Faibussowitsch 25409566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, point, field, &nfdof)); 2541e2bfaee7SMatthew G. Knepley if (nfdof) PetscValidIntPointer(indices, 4); 25422abc8c78SJacob Faibussowitsch } 25432abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 25449566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(s->field[field], point, indices)); 2545ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2546ea844a1aSMatthew Knepley } 2547ea844a1aSMatthew Knepley 2548ea844a1aSMatthew Knepley /*@ 2549ea844a1aSMatthew Knepley PetscSectionPermute - Reorder the section according to the input point permutation 2550ea844a1aSMatthew Knepley 255140750d41SVaclav Hapla Collective 2552ea844a1aSMatthew Knepley 2553d8d19677SJose E. Roman Input Parameters: 2554ea844a1aSMatthew Knepley + section - The PetscSection object 2555ea844a1aSMatthew Knepley - perm - The point permutation, old point p becomes new point perm[p] 2556ea844a1aSMatthew Knepley 2557ea844a1aSMatthew Knepley Output Parameter: 2558ea844a1aSMatthew Knepley . sectionNew - The permuted PetscSection 2559ea844a1aSMatthew Knepley 2560ea844a1aSMatthew Knepley Level: intermediate 2561ea844a1aSMatthew Knepley 2562db781477SPatrick Sanan .seealso: `MatPermute()` 2563ea844a1aSMatthew Knepley @*/ 2564*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionPermute(PetscSection section, IS permutation, PetscSection *sectionNew) 2565*d71ae5a4SJacob Faibussowitsch { 2566ea844a1aSMatthew Knepley PetscSection s = section, sNew; 2567ea844a1aSMatthew Knepley const PetscInt *perm; 2568b778fa18SValeria Barra PetscInt numFields, f, c, numPoints, pStart, pEnd, p; 2569ea844a1aSMatthew Knepley 2570ea844a1aSMatthew Knepley PetscFunctionBegin; 2571ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 2572ea844a1aSMatthew Knepley PetscValidHeaderSpecific(permutation, IS_CLASSID, 2); 2573ea844a1aSMatthew Knepley PetscValidPointer(sectionNew, 3); 25749566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), &sNew)); 25759566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s, &numFields)); 25769566063dSJacob Faibussowitsch if (numFields) PetscCall(PetscSectionSetNumFields(sNew, numFields)); 2577ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 2578ea844a1aSMatthew Knepley const char *name; 2579ea844a1aSMatthew Knepley PetscInt numComp; 2580ea844a1aSMatthew Knepley 25819566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldName(s, f, &name)); 25829566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldName(sNew, f, name)); 25839566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s, f, &numComp)); 25849566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(sNew, f, numComp)); 2585b778fa18SValeria Barra for (c = 0; c < s->numFieldComponents[f]; ++c) { 25869566063dSJacob Faibussowitsch PetscCall(PetscSectionGetComponentName(s, f, c, &name)); 25879566063dSJacob Faibussowitsch PetscCall(PetscSectionSetComponentName(sNew, f, c, name)); 2588b778fa18SValeria Barra } 2589ea844a1aSMatthew Knepley } 25909566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(permutation, &numPoints)); 25919566063dSJacob Faibussowitsch PetscCall(ISGetIndices(permutation, &perm)); 25929566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd)); 25939566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(sNew, pStart, pEnd)); 259408401ef6SPierre 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); 2595ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2596ea844a1aSMatthew Knepley PetscInt dof, cdof; 2597ea844a1aSMatthew Knepley 25989566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof)); 25999566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(sNew, perm[p], dof)); 26009566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof)); 26019566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetConstraintDof(sNew, perm[p], cdof)); 2602ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 26039566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, f, &dof)); 26049566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldDof(sNew, perm[p], f, dof)); 26059566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, f, &cdof)); 26069566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetFieldConstraintDof(sNew, perm[p], f, cdof)); 2607ea844a1aSMatthew Knepley } 2608ea844a1aSMatthew Knepley } 26099566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(sNew)); 2610ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2611ea844a1aSMatthew Knepley const PetscInt *cind; 2612ea844a1aSMatthew Knepley PetscInt cdof; 2613ea844a1aSMatthew Knepley 26149566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof)); 2615ea844a1aSMatthew Knepley if (cdof) { 26169566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s, p, &cind)); 26179566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(sNew, perm[p], cind)); 2618ea844a1aSMatthew Knepley } 2619ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 26209566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, f, &cdof)); 2621ea844a1aSMatthew Knepley if (cdof) { 26229566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(s, p, f, &cind)); 26239566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldConstraintIndices(sNew, perm[p], f, cind)); 2624ea844a1aSMatthew Knepley } 2625ea844a1aSMatthew Knepley } 2626ea844a1aSMatthew Knepley } 26279566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(permutation, &perm)); 2628ea844a1aSMatthew Knepley *sectionNew = sNew; 2629ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2630ea844a1aSMatthew Knepley } 2631ea844a1aSMatthew Knepley 2632ea844a1aSMatthew Knepley /*@ 2633ea844a1aSMatthew Knepley PetscSectionSetClosureIndex - Set a cache of points in the closure of each point in the section 2634ea844a1aSMatthew Knepley 263540750d41SVaclav Hapla Collective 2636ea844a1aSMatthew Knepley 2637ea844a1aSMatthew Knepley Input Parameters: 2638ea844a1aSMatthew Knepley + section - The PetscSection 2639ea844a1aSMatthew Knepley . obj - A PetscObject which serves as the key for this index 2640ea844a1aSMatthew Knepley . clSection - Section giving the size of the closure of each point 2641ea844a1aSMatthew Knepley - clPoints - IS giving the points in each closure 2642ea844a1aSMatthew Knepley 2643ea844a1aSMatthew Knepley Note: We compress out closure points with no dofs in this section 2644ea844a1aSMatthew Knepley 2645ea844a1aSMatthew Knepley Level: advanced 2646ea844a1aSMatthew Knepley 2647db781477SPatrick Sanan .seealso: `PetscSectionGetClosureIndex()`, `DMPlexCreateClosureIndex()` 2648ea844a1aSMatthew Knepley @*/ 2649*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetClosureIndex(PetscSection section, PetscObject obj, PetscSection clSection, IS clPoints) 2650*d71ae5a4SJacob Faibussowitsch { 2651ea844a1aSMatthew Knepley PetscFunctionBegin; 26523e03ebd8SStefano Zampini PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 26533e03ebd8SStefano Zampini PetscValidHeaderSpecific(clSection, PETSC_SECTION_CLASSID, 3); 26543e03ebd8SStefano Zampini PetscValidHeaderSpecific(clPoints, IS_CLASSID, 4); 26559566063dSJacob Faibussowitsch if (section->clObj != obj) PetscCall(PetscSectionResetClosurePermutation(section)); 2656ea844a1aSMatthew Knepley section->clObj = obj; 26579566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)clSection)); 26589566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)clPoints)); 26599566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(§ion->clSection)); 26609566063dSJacob Faibussowitsch PetscCall(ISDestroy(§ion->clPoints)); 2661ea844a1aSMatthew Knepley section->clSection = clSection; 2662ea844a1aSMatthew Knepley section->clPoints = clPoints; 2663ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2664ea844a1aSMatthew Knepley } 2665ea844a1aSMatthew Knepley 2666ea844a1aSMatthew Knepley /*@ 2667ea844a1aSMatthew Knepley PetscSectionGetClosureIndex - Get the cache of points in the closure of each point in the section 2668ea844a1aSMatthew Knepley 266940750d41SVaclav Hapla Collective 2670ea844a1aSMatthew Knepley 2671ea844a1aSMatthew Knepley Input Parameters: 2672ea844a1aSMatthew Knepley + section - The PetscSection 2673ea844a1aSMatthew Knepley - obj - A PetscObject which serves as the key for this index 2674ea844a1aSMatthew Knepley 2675ea844a1aSMatthew Knepley Output Parameters: 2676ea844a1aSMatthew Knepley + clSection - Section giving the size of the closure of each point 2677ea844a1aSMatthew Knepley - clPoints - IS giving the points in each closure 2678ea844a1aSMatthew Knepley 2679ea844a1aSMatthew Knepley Note: We compress out closure points with no dofs in this section 2680ea844a1aSMatthew Knepley 2681ea844a1aSMatthew Knepley Level: advanced 2682ea844a1aSMatthew Knepley 2683db781477SPatrick Sanan .seealso: `PetscSectionSetClosureIndex()`, `DMPlexCreateClosureIndex()` 2684ea844a1aSMatthew Knepley @*/ 2685*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosureIndex(PetscSection section, PetscObject obj, PetscSection *clSection, IS *clPoints) 2686*d71ae5a4SJacob Faibussowitsch { 2687ea844a1aSMatthew Knepley PetscFunctionBegin; 2688ea844a1aSMatthew Knepley if (section->clObj == obj) { 2689ea844a1aSMatthew Knepley if (clSection) *clSection = section->clSection; 2690ea844a1aSMatthew Knepley if (clPoints) *clPoints = section->clPoints; 2691ea844a1aSMatthew Knepley } else { 2692ea844a1aSMatthew Knepley if (clSection) *clSection = NULL; 2693ea844a1aSMatthew Knepley if (clPoints) *clPoints = NULL; 2694ea844a1aSMatthew Knepley } 2695ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2696ea844a1aSMatthew Knepley } 2697ea844a1aSMatthew Knepley 2698*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetClosurePermutation_Internal(PetscSection section, PetscObject obj, PetscInt depth, PetscInt clSize, PetscCopyMode mode, PetscInt *clPerm) 2699*d71ae5a4SJacob Faibussowitsch { 2700ea844a1aSMatthew Knepley PetscInt i; 2701c459fbc1SJed Brown khiter_t iter; 2702c459fbc1SJed Brown int new_entry; 2703c459fbc1SJed Brown PetscSectionClosurePermKey key = {depth, clSize}; 2704c459fbc1SJed Brown PetscSectionClosurePermVal *val; 2705ea844a1aSMatthew Knepley 2706ea844a1aSMatthew Knepley PetscFunctionBegin; 2707ea844a1aSMatthew Knepley if (section->clObj != obj) { 27089566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(§ion->clSection)); 27099566063dSJacob Faibussowitsch PetscCall(ISDestroy(§ion->clPoints)); 2710ea844a1aSMatthew Knepley } 2711ea844a1aSMatthew Knepley section->clObj = obj; 27129566063dSJacob Faibussowitsch if (!section->clHash) PetscCall(PetscClPermCreate(§ion->clHash)); 2713c459fbc1SJed Brown iter = kh_put(ClPerm, section->clHash, key, &new_entry); 2714c459fbc1SJed Brown val = &kh_val(section->clHash, iter); 2715c459fbc1SJed Brown if (!new_entry) { 27169566063dSJacob Faibussowitsch PetscCall(PetscFree(val->perm)); 27179566063dSJacob Faibussowitsch PetscCall(PetscFree(val->invPerm)); 2718c459fbc1SJed Brown } 2719ea844a1aSMatthew Knepley if (mode == PETSC_COPY_VALUES) { 27209566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(clSize, &val->perm)); 27219566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(val->perm, clPerm, clSize)); 2722ea844a1aSMatthew Knepley } else if (mode == PETSC_OWN_POINTER) { 2723c459fbc1SJed Brown val->perm = clPerm; 2724ea844a1aSMatthew Knepley } else SETERRQ(PetscObjectComm(obj), PETSC_ERR_SUP, "Do not support borrowed arrays"); 27259566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(clSize, &val->invPerm)); 2726c459fbc1SJed Brown for (i = 0; i < clSize; ++i) val->invPerm[clPerm[i]] = i; 2727ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2728ea844a1aSMatthew Knepley } 2729ea844a1aSMatthew Knepley 2730ea844a1aSMatthew Knepley /*@ 2731c459fbc1SJed Brown PetscSectionSetClosurePermutation - Set the dof permutation for the closure of each cell in the section, meaning clPerm[newIndex] = oldIndex. 2732ea844a1aSMatthew Knepley 2733ea844a1aSMatthew Knepley Not Collective 2734ea844a1aSMatthew Knepley 2735ea844a1aSMatthew Knepley Input Parameters: 2736ea844a1aSMatthew Knepley + section - The PetscSection 2737c459fbc1SJed Brown . obj - A PetscObject which serves as the key for this index (usually a DM) 2738c459fbc1SJed Brown . depth - Depth of points on which to apply the given permutation 2739ea844a1aSMatthew Knepley - perm - Permutation of the cell dof closure 2740ea844a1aSMatthew Knepley 2741c459fbc1SJed Brown Note: 2742c459fbc1SJed Brown The specified permutation will only be applied to points at depth whose closure size matches the length of perm. In a 2743c459fbc1SJed Brown mixed-topology or variable-degree finite element space, this function can be called multiple times at each depth for 2744c459fbc1SJed Brown each topology and degree. 2745c459fbc1SJed Brown 2746c459fbc1SJed Brown This approach assumes that (depth, len(perm)) uniquely identifies the desired permutation; this might not be true for 2747c459fbc1SJed Brown exotic/enriched spaces on mixed topology meshes. 2748ea844a1aSMatthew Knepley 2749ea844a1aSMatthew Knepley Level: intermediate 2750ea844a1aSMatthew Knepley 2751db781477SPatrick Sanan .seealso: `PetscSectionGetClosurePermutation()`, `PetscSectionGetClosureIndex()`, `DMPlexCreateClosureIndex()`, `PetscCopyMode` 2752ea844a1aSMatthew Knepley @*/ 2753*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetClosurePermutation(PetscSection section, PetscObject obj, PetscInt depth, IS perm) 2754*d71ae5a4SJacob Faibussowitsch { 2755ea844a1aSMatthew Knepley const PetscInt *clPerm = NULL; 2756ea844a1aSMatthew Knepley PetscInt clSize = 0; 2757ea844a1aSMatthew Knepley 2758ea844a1aSMatthew Knepley PetscFunctionBegin; 2759ea844a1aSMatthew Knepley if (perm) { 27609566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(perm, &clSize)); 27619566063dSJacob Faibussowitsch PetscCall(ISGetIndices(perm, &clPerm)); 2762ea844a1aSMatthew Knepley } 27639566063dSJacob Faibussowitsch PetscCall(PetscSectionSetClosurePermutation_Internal(section, obj, depth, clSize, PETSC_COPY_VALUES, (PetscInt *)clPerm)); 27649566063dSJacob Faibussowitsch if (perm) PetscCall(ISRestoreIndices(perm, &clPerm)); 2765ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2766ea844a1aSMatthew Knepley } 2767ea844a1aSMatthew Knepley 2768*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosurePermutation_Internal(PetscSection section, PetscObject obj, PetscInt depth, PetscInt size, const PetscInt *perm[]) 2769*d71ae5a4SJacob Faibussowitsch { 2770ea844a1aSMatthew Knepley PetscFunctionBegin; 2771ea844a1aSMatthew Knepley if (section->clObj == obj) { 2772c459fbc1SJed Brown PetscSectionClosurePermKey k = {depth, size}; 2773c459fbc1SJed Brown PetscSectionClosurePermVal v; 27749566063dSJacob Faibussowitsch PetscCall(PetscClPermGet(section->clHash, k, &v)); 2775c459fbc1SJed Brown if (perm) *perm = v.perm; 2776ea844a1aSMatthew Knepley } else { 2777ea844a1aSMatthew Knepley if (perm) *perm = NULL; 2778ea844a1aSMatthew Knepley } 2779ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2780ea844a1aSMatthew Knepley } 2781ea844a1aSMatthew Knepley 2782ea844a1aSMatthew Knepley /*@ 2783ea844a1aSMatthew Knepley PetscSectionGetClosurePermutation - Get the dof permutation for the closure of each cell in the section, meaning clPerm[newIndex] = oldIndex. 2784ea844a1aSMatthew Knepley 278540750d41SVaclav Hapla Not Collective 2786ea844a1aSMatthew Knepley 2787ea844a1aSMatthew Knepley Input Parameters: 2788ea844a1aSMatthew Knepley + section - The PetscSection 2789c459fbc1SJed Brown . obj - A PetscObject which serves as the key for this index (usually a DM) 2790c459fbc1SJed Brown . depth - Depth stratum on which to obtain closure permutation 2791c459fbc1SJed Brown - clSize - Closure size to be permuted (e.g., may vary with element topology and degree) 2792ea844a1aSMatthew Knepley 2793ea844a1aSMatthew Knepley Output Parameter: 2794ea844a1aSMatthew Knepley . perm - The dof closure permutation 2795ea844a1aSMatthew Knepley 2796c459fbc1SJed Brown Note: 2797ea844a1aSMatthew Knepley The user must destroy the IS that is returned. 2798ea844a1aSMatthew Knepley 2799ea844a1aSMatthew Knepley Level: intermediate 2800ea844a1aSMatthew Knepley 2801db781477SPatrick Sanan .seealso: `PetscSectionSetClosurePermutation()`, `PetscSectionGetClosureInversePermutation()`, `PetscSectionGetClosureIndex()`, `PetscSectionSetClosureIndex()`, `DMPlexCreateClosureIndex()` 2802ea844a1aSMatthew Knepley @*/ 2803*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosurePermutation(PetscSection section, PetscObject obj, PetscInt depth, PetscInt clSize, IS *perm) 2804*d71ae5a4SJacob Faibussowitsch { 2805ea844a1aSMatthew Knepley const PetscInt *clPerm; 2806ea844a1aSMatthew Knepley 2807ea844a1aSMatthew Knepley PetscFunctionBegin; 28089566063dSJacob Faibussowitsch PetscCall(PetscSectionGetClosurePermutation_Internal(section, obj, depth, clSize, &clPerm)); 28099566063dSJacob Faibussowitsch PetscCall(ISCreateGeneral(PETSC_COMM_SELF, clSize, clPerm, PETSC_USE_POINTER, perm)); 2810ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2811ea844a1aSMatthew Knepley } 2812ea844a1aSMatthew Knepley 2813*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosureInversePermutation_Internal(PetscSection section, PetscObject obj, PetscInt depth, PetscInt size, const PetscInt *perm[]) 2814*d71ae5a4SJacob Faibussowitsch { 2815ea844a1aSMatthew Knepley PetscFunctionBegin; 2816c459fbc1SJed Brown if (section->clObj == obj && section->clHash) { 2817c459fbc1SJed Brown PetscSectionClosurePermKey k = {depth, size}; 2818c459fbc1SJed Brown PetscSectionClosurePermVal v; 28199566063dSJacob Faibussowitsch PetscCall(PetscClPermGet(section->clHash, k, &v)); 2820c459fbc1SJed Brown if (perm) *perm = v.invPerm; 2821ea844a1aSMatthew Knepley } else { 2822ea844a1aSMatthew Knepley if (perm) *perm = NULL; 2823ea844a1aSMatthew Knepley } 2824ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2825ea844a1aSMatthew Knepley } 2826ea844a1aSMatthew Knepley 2827ea844a1aSMatthew Knepley /*@ 2828ea844a1aSMatthew Knepley PetscSectionGetClosureInversePermutation - Get the inverse dof permutation for the closure of each cell in the section, meaning clPerm[oldIndex] = newIndex. 2829ea844a1aSMatthew Knepley 283040750d41SVaclav Hapla Not Collective 2831ea844a1aSMatthew Knepley 2832ea844a1aSMatthew Knepley Input Parameters: 2833ea844a1aSMatthew Knepley + section - The PetscSection 2834c459fbc1SJed Brown . obj - A PetscObject which serves as the key for this index (usually a DM) 2835c459fbc1SJed Brown . depth - Depth stratum on which to obtain closure permutation 2836c459fbc1SJed Brown - clSize - Closure size to be permuted (e.g., may vary with element topology and degree) 2837ea844a1aSMatthew Knepley 2838ea844a1aSMatthew Knepley Output Parameters: 2839c459fbc1SJed Brown . perm - The dof closure permutation 2840ea844a1aSMatthew Knepley 2841c459fbc1SJed Brown Note: 2842ea844a1aSMatthew Knepley The user must destroy the IS that is returned. 2843ea844a1aSMatthew Knepley 2844ea844a1aSMatthew Knepley Level: intermediate 2845ea844a1aSMatthew Knepley 2846db781477SPatrick Sanan .seealso: `PetscSectionSetClosurePermutation()`, `PetscSectionGetClosureIndex()`, `PetscSectionSetClosureIndex()`, `DMPlexCreateClosureIndex()` 2847ea844a1aSMatthew Knepley @*/ 2848*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosureInversePermutation(PetscSection section, PetscObject obj, PetscInt depth, PetscInt clSize, IS *perm) 2849*d71ae5a4SJacob Faibussowitsch { 2850ea844a1aSMatthew Knepley const PetscInt *clPerm; 2851ea844a1aSMatthew Knepley 2852ea844a1aSMatthew Knepley PetscFunctionBegin; 28539566063dSJacob Faibussowitsch PetscCall(PetscSectionGetClosureInversePermutation_Internal(section, obj, depth, clSize, &clPerm)); 28549566063dSJacob Faibussowitsch PetscCall(ISCreateGeneral(PETSC_COMM_SELF, clSize, clPerm, PETSC_USE_POINTER, perm)); 2855ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2856ea844a1aSMatthew Knepley } 2857ea844a1aSMatthew Knepley 2858ea844a1aSMatthew Knepley /*@ 2859ea844a1aSMatthew Knepley PetscSectionGetField - Get the subsection associated with a single field 2860ea844a1aSMatthew Knepley 2861ea844a1aSMatthew Knepley Input Parameters: 2862ea844a1aSMatthew Knepley + s - The PetscSection 2863ea844a1aSMatthew Knepley - field - The field number 2864ea844a1aSMatthew Knepley 2865ea844a1aSMatthew Knepley Output Parameter: 2866ea844a1aSMatthew Knepley . subs - The subsection for the given field 2867ea844a1aSMatthew Knepley 2868ea844a1aSMatthew Knepley Level: intermediate 2869ea844a1aSMatthew Knepley 2870db781477SPatrick Sanan .seealso: `PetscSectionSetNumFields()` 2871ea844a1aSMatthew Knepley @*/ 2872*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetField(PetscSection s, PetscInt field, PetscSection *subs) 2873*d71ae5a4SJacob Faibussowitsch { 2874ea844a1aSMatthew Knepley PetscFunctionBegin; 2875ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2876ea844a1aSMatthew Knepley PetscValidPointer(subs, 3); 28772abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields); 2878ea844a1aSMatthew Knepley *subs = s->field[field]; 2879ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2880ea844a1aSMatthew Knepley } 2881ea844a1aSMatthew Knepley 2882ea844a1aSMatthew Knepley PetscClassId PETSC_SECTION_SYM_CLASSID; 2883ea844a1aSMatthew Knepley PetscFunctionList PetscSectionSymList = NULL; 2884ea844a1aSMatthew Knepley 2885ea844a1aSMatthew Knepley /*@ 2886ea844a1aSMatthew Knepley PetscSectionSymCreate - Creates an empty PetscSectionSym object. 2887ea844a1aSMatthew Knepley 2888ea844a1aSMatthew Knepley Collective 2889ea844a1aSMatthew Knepley 2890ea844a1aSMatthew Knepley Input Parameter: 2891ea844a1aSMatthew Knepley . comm - the MPI communicator 2892ea844a1aSMatthew Knepley 2893ea844a1aSMatthew Knepley Output Parameter: 2894ea844a1aSMatthew Knepley . sym - pointer to the new set of symmetries 2895ea844a1aSMatthew Knepley 2896ea844a1aSMatthew Knepley Level: developer 2897ea844a1aSMatthew Knepley 2898db781477SPatrick Sanan .seealso: `PetscSectionSym`, `PetscSectionSymDestroy()` 2899ea844a1aSMatthew Knepley @*/ 2900*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymCreate(MPI_Comm comm, PetscSectionSym *sym) 2901*d71ae5a4SJacob Faibussowitsch { 2902ea844a1aSMatthew Knepley PetscFunctionBegin; 2903ea844a1aSMatthew Knepley PetscValidPointer(sym, 2); 29049566063dSJacob Faibussowitsch PetscCall(ISInitializePackage()); 29059566063dSJacob Faibussowitsch PetscCall(PetscHeaderCreate(*sym, PETSC_SECTION_SYM_CLASSID, "PetscSectionSym", "Section Symmetry", "IS", comm, PetscSectionSymDestroy, PetscSectionSymView)); 2906ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2907ea844a1aSMatthew Knepley } 2908ea844a1aSMatthew Knepley 2909ea844a1aSMatthew Knepley /*@C 2910ea844a1aSMatthew Knepley PetscSectionSymSetType - Builds a PetscSection symmetry, for a particular implementation. 2911ea844a1aSMatthew Knepley 291240750d41SVaclav Hapla Collective 2913ea844a1aSMatthew Knepley 2914ea844a1aSMatthew Knepley Input Parameters: 2915ea844a1aSMatthew Knepley + sym - The section symmetry object 2916ea844a1aSMatthew Knepley - method - The name of the section symmetry type 2917ea844a1aSMatthew Knepley 2918ea844a1aSMatthew Knepley Level: developer 2919ea844a1aSMatthew Knepley 2920db781477SPatrick Sanan .seealso: `PetscSectionSymGetType()`, `PetscSectionSymCreate()` 2921ea844a1aSMatthew Knepley @*/ 2922*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymSetType(PetscSectionSym sym, PetscSectionSymType method) 2923*d71ae5a4SJacob Faibussowitsch { 2924ea844a1aSMatthew Knepley PetscErrorCode (*r)(PetscSectionSym); 2925ea844a1aSMatthew Knepley PetscBool match; 2926ea844a1aSMatthew Knepley 2927ea844a1aSMatthew Knepley PetscFunctionBegin; 2928ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 29299566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)sym, method, &match)); 2930ea844a1aSMatthew Knepley if (match) PetscFunctionReturn(0); 2931ea844a1aSMatthew Knepley 29329566063dSJacob Faibussowitsch PetscCall(PetscFunctionListFind(PetscSectionSymList, method, &r)); 293328b400f6SJacob Faibussowitsch PetscCheck(r, PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscSectionSym type: %s", method); 2934dbbe0bcdSBarry Smith PetscTryTypeMethod(sym, destroy); 2935ea844a1aSMatthew Knepley sym->ops->destroy = NULL; 2936dbbe0bcdSBarry Smith 29379566063dSJacob Faibussowitsch PetscCall((*r)(sym)); 29389566063dSJacob Faibussowitsch PetscCall(PetscObjectChangeTypeName((PetscObject)sym, method)); 2939ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2940ea844a1aSMatthew Knepley } 2941ea844a1aSMatthew Knepley 2942ea844a1aSMatthew Knepley /*@C 2943ea844a1aSMatthew Knepley PetscSectionSymGetType - Gets the section symmetry type name (as a string) from the PetscSectionSym. 2944ea844a1aSMatthew Knepley 2945ea844a1aSMatthew Knepley Not Collective 2946ea844a1aSMatthew Knepley 2947ea844a1aSMatthew Knepley Input Parameter: 2948ea844a1aSMatthew Knepley . sym - The section symmetry 2949ea844a1aSMatthew Knepley 2950ea844a1aSMatthew Knepley Output Parameter: 2951ea844a1aSMatthew Knepley . type - The index set type name 2952ea844a1aSMatthew Knepley 2953ea844a1aSMatthew Knepley Level: developer 2954ea844a1aSMatthew Knepley 2955db781477SPatrick Sanan .seealso: `PetscSectionSymSetType()`, `PetscSectionSymCreate()` 2956ea844a1aSMatthew Knepley @*/ 2957*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymGetType(PetscSectionSym sym, PetscSectionSymType *type) 2958*d71ae5a4SJacob Faibussowitsch { 2959ea844a1aSMatthew Knepley PetscFunctionBegin; 2960ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 2961dadcf809SJacob Faibussowitsch PetscValidPointer(type, 2); 2962ea844a1aSMatthew Knepley *type = ((PetscObject)sym)->type_name; 2963ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2964ea844a1aSMatthew Knepley } 2965ea844a1aSMatthew Knepley 2966ea844a1aSMatthew Knepley /*@C 2967ea844a1aSMatthew Knepley PetscSectionSymRegister - Adds a new section symmetry implementation 2968ea844a1aSMatthew Knepley 2969ea844a1aSMatthew Knepley Not Collective 2970ea844a1aSMatthew Knepley 2971ea844a1aSMatthew Knepley Input Parameters: 2972ea844a1aSMatthew Knepley + name - The name of a new user-defined creation routine 2973ea844a1aSMatthew Knepley - create_func - The creation routine itself 2974ea844a1aSMatthew Knepley 2975ea844a1aSMatthew Knepley Notes: 2976ea844a1aSMatthew Knepley PetscSectionSymRegister() may be called multiple times to add several user-defined vectors 2977ea844a1aSMatthew Knepley 2978ea844a1aSMatthew Knepley Level: developer 2979ea844a1aSMatthew Knepley 2980db781477SPatrick Sanan .seealso: `PetscSectionSymCreate()`, `PetscSectionSymSetType()` 2981ea844a1aSMatthew Knepley @*/ 2982*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymRegister(const char sname[], PetscErrorCode (*function)(PetscSectionSym)) 2983*d71ae5a4SJacob Faibussowitsch { 2984ea844a1aSMatthew Knepley PetscFunctionBegin; 29859566063dSJacob Faibussowitsch PetscCall(ISInitializePackage()); 29869566063dSJacob Faibussowitsch PetscCall(PetscFunctionListAdd(&PetscSectionSymList, sname, function)); 2987ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2988ea844a1aSMatthew Knepley } 2989ea844a1aSMatthew Knepley 2990ea844a1aSMatthew Knepley /*@ 2991ea844a1aSMatthew Knepley PetscSectionSymDestroy - Destroys a section symmetry. 2992ea844a1aSMatthew Knepley 299340750d41SVaclav Hapla Collective 2994ea844a1aSMatthew Knepley 2995ea844a1aSMatthew Knepley Input Parameters: 2996ea844a1aSMatthew Knepley . sym - the section symmetry 2997ea844a1aSMatthew Knepley 2998ea844a1aSMatthew Knepley Level: developer 2999ea844a1aSMatthew Knepley 3000db781477SPatrick Sanan .seealso: `PetscSectionSymCreate()`, `PetscSectionSymDestroy()` 3001ea844a1aSMatthew Knepley @*/ 3002*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymDestroy(PetscSectionSym *sym) 3003*d71ae5a4SJacob Faibussowitsch { 3004ea844a1aSMatthew Knepley SymWorkLink link, next; 3005ea844a1aSMatthew Knepley 3006ea844a1aSMatthew Knepley PetscFunctionBegin; 3007ea844a1aSMatthew Knepley if (!*sym) PetscFunctionReturn(0); 3008ea844a1aSMatthew Knepley PetscValidHeaderSpecific((*sym), PETSC_SECTION_SYM_CLASSID, 1); 30099371c9d4SSatish Balay if (--((PetscObject)(*sym))->refct > 0) { 30109371c9d4SSatish Balay *sym = NULL; 30119371c9d4SSatish Balay PetscFunctionReturn(0); 3012ea844a1aSMatthew Knepley } 301348a46eb9SPierre Jolivet if ((*sym)->ops->destroy) PetscCall((*(*sym)->ops->destroy)(*sym)); 3014c9cc58a2SBarry Smith PetscCheck(!(*sym)->workout, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Work array still checked out"); 3015ea844a1aSMatthew Knepley for (link = (*sym)->workin; link; link = next) { 30160c99d500SBarry Smith PetscInt **perms = (PetscInt **)link->perms; 30170c99d500SBarry Smith PetscScalar **rots = (PetscScalar **)link->rots; 30180c99d500SBarry Smith PetscCall(PetscFree2(perms, rots)); 3019ea844a1aSMatthew Knepley next = link->next; 30209566063dSJacob Faibussowitsch PetscCall(PetscFree(link)); 3021ea844a1aSMatthew Knepley } 3022ea844a1aSMatthew Knepley (*sym)->workin = NULL; 30239566063dSJacob Faibussowitsch PetscCall(PetscHeaderDestroy(sym)); 3024ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3025ea844a1aSMatthew Knepley } 3026ea844a1aSMatthew Knepley 3027ea844a1aSMatthew Knepley /*@C 3028ea844a1aSMatthew Knepley PetscSectionSymView - Displays a section symmetry 3029ea844a1aSMatthew Knepley 303040750d41SVaclav Hapla Collective 3031ea844a1aSMatthew Knepley 3032ea844a1aSMatthew Knepley Input Parameters: 3033ea844a1aSMatthew Knepley + sym - the index set 3034ea844a1aSMatthew Knepley - viewer - viewer used to display the set, for example PETSC_VIEWER_STDOUT_SELF. 3035ea844a1aSMatthew Knepley 3036ea844a1aSMatthew Knepley Level: developer 3037ea844a1aSMatthew Knepley 3038db781477SPatrick Sanan .seealso: `PetscViewerASCIIOpen()` 3039ea844a1aSMatthew Knepley @*/ 3040*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymView(PetscSectionSym sym, PetscViewer viewer) 3041*d71ae5a4SJacob Faibussowitsch { 3042ea844a1aSMatthew Knepley PetscFunctionBegin; 3043ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 304448a46eb9SPierre Jolivet if (!viewer) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)sym), &viewer)); 3045ea844a1aSMatthew Knepley PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2); 3046ea844a1aSMatthew Knepley PetscCheckSameComm(sym, 1, viewer, 2); 30479566063dSJacob Faibussowitsch PetscCall(PetscObjectPrintClassNamePrefixType((PetscObject)sym, viewer)); 3048dbbe0bcdSBarry Smith PetscTryTypeMethod(sym, view, viewer); 3049ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3050ea844a1aSMatthew Knepley } 3051ea844a1aSMatthew Knepley 3052ea844a1aSMatthew Knepley /*@ 3053ea844a1aSMatthew Knepley PetscSectionSetSym - Set the symmetries for the data referred to by the section 3054ea844a1aSMatthew Knepley 305540750d41SVaclav Hapla Collective 3056ea844a1aSMatthew Knepley 3057ea844a1aSMatthew Knepley Input Parameters: 3058ea844a1aSMatthew Knepley + section - the section describing data layout 3059ea844a1aSMatthew Knepley - sym - the symmetry describing the affect of orientation on the access of the data 3060ea844a1aSMatthew Knepley 3061ea844a1aSMatthew Knepley Level: developer 3062ea844a1aSMatthew Knepley 3063db781477SPatrick Sanan .seealso: `PetscSectionGetSym()`, `PetscSectionSymCreate()` 3064ea844a1aSMatthew Knepley @*/ 3065*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetSym(PetscSection section, PetscSectionSym sym) 3066*d71ae5a4SJacob Faibussowitsch { 3067ea844a1aSMatthew Knepley PetscFunctionBegin; 3068ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 30699566063dSJacob Faibussowitsch PetscCall(PetscSectionSymDestroy(&(section->sym))); 3070ea844a1aSMatthew Knepley if (sym) { 3071ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 2); 3072ea844a1aSMatthew Knepley PetscCheckSameComm(section, 1, sym, 2); 30739566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)sym)); 3074ea844a1aSMatthew Knepley } 3075ea844a1aSMatthew Knepley section->sym = sym; 3076ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3077ea844a1aSMatthew Knepley } 3078ea844a1aSMatthew Knepley 3079ea844a1aSMatthew Knepley /*@ 3080ea844a1aSMatthew Knepley PetscSectionGetSym - Get the symmetries for the data referred to by the section 3081ea844a1aSMatthew Knepley 308240750d41SVaclav Hapla Not Collective 3083ea844a1aSMatthew Knepley 3084ea844a1aSMatthew Knepley Input Parameters: 3085ea844a1aSMatthew Knepley . section - the section describing data layout 3086ea844a1aSMatthew Knepley 3087ea844a1aSMatthew Knepley Output Parameters: 3088ea844a1aSMatthew Knepley . sym - the symmetry describing the affect of orientation on the access of the data 3089ea844a1aSMatthew Knepley 3090ea844a1aSMatthew Knepley Level: developer 3091ea844a1aSMatthew Knepley 3092db781477SPatrick Sanan .seealso: `PetscSectionSetSym()`, `PetscSectionSymCreate()` 3093ea844a1aSMatthew Knepley @*/ 3094*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetSym(PetscSection section, PetscSectionSym *sym) 3095*d71ae5a4SJacob Faibussowitsch { 3096ea844a1aSMatthew Knepley PetscFunctionBegin; 3097ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 3098ea844a1aSMatthew Knepley *sym = section->sym; 3099ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3100ea844a1aSMatthew Knepley } 3101ea844a1aSMatthew Knepley 3102ea844a1aSMatthew Knepley /*@ 3103ea844a1aSMatthew Knepley PetscSectionSetFieldSym - Set the symmetries for the data referred to by a field of the section 3104ea844a1aSMatthew Knepley 310540750d41SVaclav Hapla Collective 3106ea844a1aSMatthew Knepley 3107ea844a1aSMatthew Knepley Input Parameters: 3108ea844a1aSMatthew Knepley + section - the section describing data layout 3109ea844a1aSMatthew Knepley . field - the field number 3110ea844a1aSMatthew Knepley - sym - the symmetry describing the affect of orientation on the access of the data 3111ea844a1aSMatthew Knepley 3112ea844a1aSMatthew Knepley Level: developer 3113ea844a1aSMatthew Knepley 3114db781477SPatrick Sanan .seealso: `PetscSectionGetFieldSym()`, `PetscSectionSymCreate()` 3115ea844a1aSMatthew Knepley @*/ 3116*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldSym(PetscSection section, PetscInt field, PetscSectionSym sym) 3117*d71ae5a4SJacob Faibussowitsch { 3118ea844a1aSMatthew Knepley PetscFunctionBegin; 3119ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 31202abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, section->numFields); 31219566063dSJacob Faibussowitsch PetscCall(PetscSectionSetSym(section->field[field], sym)); 3122ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3123ea844a1aSMatthew Knepley } 3124ea844a1aSMatthew Knepley 3125ea844a1aSMatthew Knepley /*@ 3126ea844a1aSMatthew Knepley PetscSectionGetFieldSym - Get the symmetries for the data referred to by a field of the section 3127ea844a1aSMatthew Knepley 312840750d41SVaclav Hapla Collective 3129ea844a1aSMatthew Knepley 3130ea844a1aSMatthew Knepley Input Parameters: 3131ea844a1aSMatthew Knepley + section - the section describing data layout 3132ea844a1aSMatthew Knepley - field - the field number 3133ea844a1aSMatthew Knepley 3134ea844a1aSMatthew Knepley Output Parameters: 3135ea844a1aSMatthew Knepley . sym - the symmetry describing the affect of orientation on the access of the data 3136ea844a1aSMatthew Knepley 3137ea844a1aSMatthew Knepley Level: developer 3138ea844a1aSMatthew Knepley 3139db781477SPatrick Sanan .seealso: `PetscSectionSetFieldSym()`, `PetscSectionSymCreate()` 3140ea844a1aSMatthew Knepley @*/ 3141*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldSym(PetscSection section, PetscInt field, PetscSectionSym *sym) 3142*d71ae5a4SJacob Faibussowitsch { 3143ea844a1aSMatthew Knepley PetscFunctionBegin; 3144ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 31452abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, section->numFields); 3146ea844a1aSMatthew Knepley *sym = section->field[field]->sym; 3147ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3148ea844a1aSMatthew Knepley } 3149ea844a1aSMatthew Knepley 3150ea844a1aSMatthew Knepley /*@C 3151ea844a1aSMatthew Knepley PetscSectionGetPointSyms - Get the symmetries for a set of points in a PetscSection under specific orientations. 3152ea844a1aSMatthew Knepley 315340750d41SVaclav Hapla Not Collective 3154ea844a1aSMatthew Knepley 3155ea844a1aSMatthew Knepley Input Parameters: 3156ea844a1aSMatthew Knepley + section - the section 3157ea844a1aSMatthew Knepley . numPoints - the number of points 3158ea844a1aSMatthew Knepley - points - an array of size 2 * numPoints, containing a list of (point, orientation) pairs. (An orientation is an 3159ea844a1aSMatthew Knepley arbitrary integer: its interpretation is up to sym. Orientations are used by DM: for their interpretation in that 3160ea844a1aSMatthew Knepley context, see DMPlexGetConeOrientation()). 3161ea844a1aSMatthew Knepley 3162d8d19677SJose E. Roman Output Parameters: 3163ea844a1aSMatthew Knepley + perms - The permutations for the given orientations (or NULL if there is no symmetry or the permutation is the identity). 3164ea844a1aSMatthew Knepley - rots - The field rotations symmetries for the given orientations (or NULL if there is no symmetry or the rotations are all 3165ea844a1aSMatthew Knepley identity). 3166ea844a1aSMatthew Knepley 3167ea844a1aSMatthew Knepley Example of usage, gathering dofs into a local array (lArray) from a section array (sArray): 3168ea844a1aSMatthew Knepley .vb 3169ea844a1aSMatthew Knepley const PetscInt **perms; 3170ea844a1aSMatthew Knepley const PetscScalar **rots; 3171ea844a1aSMatthew Knepley PetscInt lOffset; 3172ea844a1aSMatthew Knepley 3173ea844a1aSMatthew Knepley PetscSectionGetPointSyms(section,numPoints,points,&perms,&rots); 3174ea844a1aSMatthew Knepley for (i = 0, lOffset = 0; i < numPoints; i++) { 3175ea844a1aSMatthew Knepley PetscInt point = points[2*i], dof, sOffset; 3176ea844a1aSMatthew Knepley const PetscInt *perm = perms ? perms[i] : NULL; 3177ea844a1aSMatthew Knepley const PetscScalar *rot = rots ? rots[i] : NULL; 3178ea844a1aSMatthew Knepley 3179ea844a1aSMatthew Knepley PetscSectionGetDof(section,point,&dof); 3180ea844a1aSMatthew Knepley PetscSectionGetOffset(section,point,&sOffset); 3181ea844a1aSMatthew Knepley 3182ea844a1aSMatthew Knepley if (perm) {for (j = 0; j < dof; j++) {lArray[lOffset + perm[j]] = sArray[sOffset + j];}} 3183ea844a1aSMatthew Knepley else {for (j = 0; j < dof; j++) {lArray[lOffset + j ] = sArray[sOffset + j];}} 3184ea844a1aSMatthew Knepley if (rot) {for (j = 0; j < dof; j++) {lArray[lOffset + j ] *= rot[j]; }} 3185ea844a1aSMatthew Knepley lOffset += dof; 3186ea844a1aSMatthew Knepley } 3187ea844a1aSMatthew Knepley PetscSectionRestorePointSyms(section,numPoints,points,&perms,&rots); 3188ea844a1aSMatthew Knepley .ve 3189ea844a1aSMatthew Knepley 3190ea844a1aSMatthew Knepley Example of usage, adding dofs into a section array (sArray) from a local array (lArray): 3191ea844a1aSMatthew Knepley .vb 3192ea844a1aSMatthew Knepley const PetscInt **perms; 3193ea844a1aSMatthew Knepley const PetscScalar **rots; 3194ea844a1aSMatthew Knepley PetscInt lOffset; 3195ea844a1aSMatthew Knepley 3196ea844a1aSMatthew Knepley PetscSectionGetPointSyms(section,numPoints,points,&perms,&rots); 3197ea844a1aSMatthew Knepley for (i = 0, lOffset = 0; i < numPoints; i++) { 3198ea844a1aSMatthew Knepley PetscInt point = points[2*i], dof, sOffset; 3199ea844a1aSMatthew Knepley const PetscInt *perm = perms ? perms[i] : NULL; 3200ea844a1aSMatthew Knepley const PetscScalar *rot = rots ? rots[i] : NULL; 3201ea844a1aSMatthew Knepley 3202ea844a1aSMatthew Knepley PetscSectionGetDof(section,point,&dof); 3203ea844a1aSMatthew Knepley PetscSectionGetOffset(section,point,&sOff); 3204ea844a1aSMatthew Knepley 3205ea844a1aSMatthew Knepley if (perm) {for (j = 0; j < dof; j++) {sArray[sOffset + j] += lArray[lOffset + perm[j]] * (rot ? PetscConj(rot[perm[j]]) : 1.);}} 3206ea844a1aSMatthew Knepley else {for (j = 0; j < dof; j++) {sArray[sOffset + j] += lArray[lOffset + j ] * (rot ? PetscConj(rot[ j ]) : 1.);}} 3207ea844a1aSMatthew Knepley offset += dof; 3208ea844a1aSMatthew Knepley } 3209ea844a1aSMatthew Knepley PetscSectionRestorePointSyms(section,numPoints,points,&perms,&rots); 3210ea844a1aSMatthew Knepley .ve 3211ea844a1aSMatthew Knepley 3212ea844a1aSMatthew Knepley Level: developer 3213ea844a1aSMatthew Knepley 3214db781477SPatrick Sanan .seealso: `PetscSectionRestorePointSyms()`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()` 3215ea844a1aSMatthew Knepley @*/ 3216*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetPointSyms(PetscSection section, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots) 3217*d71ae5a4SJacob Faibussowitsch { 3218ea844a1aSMatthew Knepley PetscSectionSym sym; 3219ea844a1aSMatthew Knepley 3220ea844a1aSMatthew Knepley PetscFunctionBegin; 3221ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 3222ea844a1aSMatthew Knepley if (numPoints) PetscValidIntPointer(points, 3); 3223ea844a1aSMatthew Knepley if (perms) *perms = NULL; 3224ea844a1aSMatthew Knepley if (rots) *rots = NULL; 3225ea844a1aSMatthew Knepley sym = section->sym; 3226ea844a1aSMatthew Knepley if (sym && (perms || rots)) { 3227ea844a1aSMatthew Knepley SymWorkLink link; 3228ea844a1aSMatthew Knepley 3229ea844a1aSMatthew Knepley if (sym->workin) { 3230ea844a1aSMatthew Knepley link = sym->workin; 3231ea844a1aSMatthew Knepley sym->workin = sym->workin->next; 3232ea844a1aSMatthew Knepley } else { 32334dfa11a4SJacob Faibussowitsch PetscCall(PetscNew(&link)); 3234ea844a1aSMatthew Knepley } 3235ea844a1aSMatthew Knepley if (numPoints > link->numPoints) { 32360c99d500SBarry Smith PetscInt **perms = (PetscInt **)link->perms; 32370c99d500SBarry Smith PetscScalar **rots = (PetscScalar **)link->rots; 32380c99d500SBarry Smith PetscCall(PetscFree2(perms, rots)); 32390c99d500SBarry Smith PetscCall(PetscMalloc2(numPoints, (PetscInt ***)&link->perms, numPoints, (PetscScalar ***)&link->rots)); 3240ea844a1aSMatthew Knepley link->numPoints = numPoints; 3241ea844a1aSMatthew Knepley } 3242ea844a1aSMatthew Knepley link->next = sym->workout; 3243ea844a1aSMatthew Knepley sym->workout = link; 32449566063dSJacob Faibussowitsch PetscCall(PetscArrayzero((PetscInt **)link->perms, numPoints)); 32459566063dSJacob Faibussowitsch PetscCall(PetscArrayzero((PetscInt **)link->rots, numPoints)); 32469566063dSJacob Faibussowitsch PetscCall((*sym->ops->getpoints)(sym, section, numPoints, points, link->perms, link->rots)); 3247ea844a1aSMatthew Knepley if (perms) *perms = link->perms; 3248ea844a1aSMatthew Knepley if (rots) *rots = link->rots; 3249ea844a1aSMatthew Knepley } 3250ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3251ea844a1aSMatthew Knepley } 3252ea844a1aSMatthew Knepley 3253ea844a1aSMatthew Knepley /*@C 3254ea844a1aSMatthew Knepley PetscSectionRestorePointSyms - Restore the symmetries returned by PetscSectionGetPointSyms() 3255ea844a1aSMatthew Knepley 325640750d41SVaclav Hapla Not Collective 3257ea844a1aSMatthew Knepley 3258ea844a1aSMatthew Knepley Input Parameters: 3259ea844a1aSMatthew Knepley + section - the section 3260ea844a1aSMatthew Knepley . numPoints - the number of points 3261ea844a1aSMatthew Knepley - points - an array of size 2 * numPoints, containing a list of (point, orientation) pairs. (An orientation is an 3262ea844a1aSMatthew Knepley arbitrary integer: its interpretation is up to sym. Orientations are used by DM: for their interpretation in that 3263ea844a1aSMatthew Knepley context, see DMPlexGetConeOrientation()). 3264ea844a1aSMatthew Knepley 3265d8d19677SJose E. Roman Output Parameters: 3266ea844a1aSMatthew Knepley + perms - The permutations for the given orientations: set to NULL at conclusion 3267ea844a1aSMatthew Knepley - rots - The field rotations symmetries for the given orientations: set to NULL at conclusion 3268ea844a1aSMatthew Knepley 3269ea844a1aSMatthew Knepley Level: developer 3270ea844a1aSMatthew Knepley 3271db781477SPatrick Sanan .seealso: `PetscSectionGetPointSyms()`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()` 3272ea844a1aSMatthew Knepley @*/ 3273*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionRestorePointSyms(PetscSection section, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots) 3274*d71ae5a4SJacob Faibussowitsch { 3275ea844a1aSMatthew Knepley PetscSectionSym sym; 3276ea844a1aSMatthew Knepley 3277ea844a1aSMatthew Knepley PetscFunctionBegin; 3278ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 3279ea844a1aSMatthew Knepley sym = section->sym; 3280ea844a1aSMatthew Knepley if (sym && (perms || rots)) { 3281ea844a1aSMatthew Knepley SymWorkLink *p, link; 3282ea844a1aSMatthew Knepley 3283ea844a1aSMatthew Knepley for (p = &sym->workout; (link = *p); p = &link->next) { 3284ea844a1aSMatthew Knepley if ((perms && link->perms == *perms) || (rots && link->rots == *rots)) { 3285ea844a1aSMatthew Knepley *p = link->next; 3286ea844a1aSMatthew Knepley link->next = sym->workin; 3287ea844a1aSMatthew Knepley sym->workin = link; 3288ea844a1aSMatthew Knepley if (perms) *perms = NULL; 3289ea844a1aSMatthew Knepley if (rots) *rots = NULL; 3290ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3291ea844a1aSMatthew Knepley } 3292ea844a1aSMatthew Knepley } 3293ea844a1aSMatthew Knepley SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Array was not checked out"); 3294ea844a1aSMatthew Knepley } 3295ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3296ea844a1aSMatthew Knepley } 3297ea844a1aSMatthew Knepley 3298ea844a1aSMatthew Knepley /*@C 3299ea844a1aSMatthew Knepley PetscSectionGetFieldPointSyms - Get the symmetries for a set of points in a field of a PetscSection under specific orientations. 3300ea844a1aSMatthew Knepley 330140750d41SVaclav Hapla Not Collective 3302ea844a1aSMatthew Knepley 3303ea844a1aSMatthew Knepley Input Parameters: 3304ea844a1aSMatthew Knepley + section - the section 3305ea844a1aSMatthew Knepley . field - the field of the section 3306ea844a1aSMatthew Knepley . numPoints - the number of points 3307ea844a1aSMatthew Knepley - points - an array of size 2 * numPoints, containing a list of (point, orientation) pairs. (An orientation is an 3308ea844a1aSMatthew Knepley arbitrary integer: its interpretation is up to sym. Orientations are used by DM: for their interpretation in that 3309ea844a1aSMatthew Knepley context, see DMPlexGetConeOrientation()). 3310ea844a1aSMatthew Knepley 3311d8d19677SJose E. Roman Output Parameters: 3312ea844a1aSMatthew Knepley + perms - The permutations for the given orientations (or NULL if there is no symmetry or the permutation is the identity). 3313ea844a1aSMatthew Knepley - rots - The field rotations symmetries for the given orientations (or NULL if there is no symmetry or the rotations are all 3314ea844a1aSMatthew Knepley identity). 3315ea844a1aSMatthew Knepley 3316ea844a1aSMatthew Knepley Level: developer 3317ea844a1aSMatthew Knepley 3318db781477SPatrick Sanan .seealso: `PetscSectionGetPointSyms()`, `PetscSectionRestoreFieldPointSyms()` 3319ea844a1aSMatthew Knepley @*/ 3320*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldPointSyms(PetscSection section, PetscInt field, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots) 3321*d71ae5a4SJacob Faibussowitsch { 3322ea844a1aSMatthew Knepley PetscFunctionBegin; 3323ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 332408401ef6SPierre 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); 33259566063dSJacob Faibussowitsch PetscCall(PetscSectionGetPointSyms(section->field[field], numPoints, points, perms, rots)); 3326ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3327ea844a1aSMatthew Knepley } 3328ea844a1aSMatthew Knepley 3329ea844a1aSMatthew Knepley /*@C 3330ea844a1aSMatthew Knepley PetscSectionRestoreFieldPointSyms - Restore the symmetries returned by PetscSectionGetFieldPointSyms() 3331ea844a1aSMatthew Knepley 333240750d41SVaclav Hapla Not Collective 3333ea844a1aSMatthew Knepley 3334ea844a1aSMatthew Knepley Input Parameters: 3335ea844a1aSMatthew Knepley + section - the section 3336ea844a1aSMatthew Knepley . field - the field number 3337ea844a1aSMatthew Knepley . numPoints - the number of points 3338ea844a1aSMatthew Knepley - points - an array of size 2 * numPoints, containing a list of (point, orientation) pairs. (An orientation is an 3339ea844a1aSMatthew Knepley arbitrary integer: its interpretation is up to sym. Orientations are used by DM: for their interpretation in that 3340ea844a1aSMatthew Knepley context, see DMPlexGetConeOrientation()). 3341ea844a1aSMatthew Knepley 3342d8d19677SJose E. Roman Output Parameters: 3343ea844a1aSMatthew Knepley + perms - The permutations for the given orientations: set to NULL at conclusion 3344ea844a1aSMatthew Knepley - rots - The field rotations symmetries for the given orientations: set to NULL at conclusion 3345ea844a1aSMatthew Knepley 3346ea844a1aSMatthew Knepley Level: developer 3347ea844a1aSMatthew Knepley 3348db781477SPatrick Sanan .seealso: `PetscSectionRestorePointSyms()`, `petscSectionGetFieldPointSyms()`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()` 3349ea844a1aSMatthew Knepley @*/ 3350*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionRestoreFieldPointSyms(PetscSection section, PetscInt field, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots) 3351*d71ae5a4SJacob Faibussowitsch { 3352ea844a1aSMatthew Knepley PetscFunctionBegin; 3353ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 335408401ef6SPierre 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); 33559566063dSJacob Faibussowitsch PetscCall(PetscSectionRestorePointSyms(section->field[field], numPoints, points, perms, rots)); 3356ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3357ea844a1aSMatthew Knepley } 3358ea844a1aSMatthew Knepley 3359ea844a1aSMatthew Knepley /*@ 3360b004864fSMatthew G. Knepley PetscSectionSymCopy - Copy the symmetries, assuming that the point structure is compatible 3361b004864fSMatthew G. Knepley 336240750d41SVaclav Hapla Not Collective 3363b004864fSMatthew G. Knepley 3364b004864fSMatthew G. Knepley Input Parameter: 3365b004864fSMatthew G. Knepley . sym - the PetscSectionSym 3366b004864fSMatthew G. Knepley 3367b004864fSMatthew G. Knepley Output Parameter: 3368b004864fSMatthew G. Knepley . nsym - the equivalent symmetries 3369b004864fSMatthew G. Knepley 3370b004864fSMatthew G. Knepley Level: developer 3371b004864fSMatthew G. Knepley 3372db781477SPatrick Sanan .seealso: `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()`, `PetscSectionSymLabelSetStratum()`, `PetscSectionGetPointSyms()` 3373b004864fSMatthew G. Knepley @*/ 3374*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymCopy(PetscSectionSym sym, PetscSectionSym nsym) 3375*d71ae5a4SJacob Faibussowitsch { 3376b004864fSMatthew G. Knepley PetscFunctionBegin; 3377b004864fSMatthew G. Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 3378b004864fSMatthew G. Knepley PetscValidHeaderSpecific(nsym, PETSC_SECTION_SYM_CLASSID, 2); 3379dbbe0bcdSBarry Smith PetscTryTypeMethod(sym, copy, nsym); 3380b004864fSMatthew G. Knepley PetscFunctionReturn(0); 3381b004864fSMatthew G. Knepley } 3382b004864fSMatthew G. Knepley 3383b004864fSMatthew G. Knepley /*@ 3384b004864fSMatthew G. Knepley PetscSectionSymDistribute - Distribute the symmetries in accordance with the input SF 3385b004864fSMatthew G. Knepley 3386b004864fSMatthew G. Knepley Collective 3387b004864fSMatthew G. Knepley 3388b004864fSMatthew G. Knepley Input Parameters: 3389b004864fSMatthew G. Knepley + sym - the PetscSectionSym 3390b004864fSMatthew G. Knepley - migrationSF - the distribution map from roots to leaves 3391b004864fSMatthew G. Knepley 3392b004864fSMatthew G. Knepley Output Parameters: 3393b004864fSMatthew G. Knepley . dsym - the redistributed symmetries 3394b004864fSMatthew G. Knepley 3395b004864fSMatthew G. Knepley Level: developer 3396b004864fSMatthew G. Knepley 3397db781477SPatrick Sanan .seealso: `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()`, `PetscSectionSymLabelSetStratum()`, `PetscSectionGetPointSyms()` 3398b004864fSMatthew G. Knepley @*/ 3399*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymDistribute(PetscSectionSym sym, PetscSF migrationSF, PetscSectionSym *dsym) 3400*d71ae5a4SJacob Faibussowitsch { 3401b004864fSMatthew G. Knepley PetscFunctionBegin; 3402b004864fSMatthew G. Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 3403b004864fSMatthew G. Knepley PetscValidHeaderSpecific(migrationSF, PETSCSF_CLASSID, 2); 3404b004864fSMatthew G. Knepley PetscValidPointer(dsym, 3); 3405dbbe0bcdSBarry Smith PetscTryTypeMethod(sym, distribute, migrationSF, dsym); 3406b004864fSMatthew G. Knepley PetscFunctionReturn(0); 3407b004864fSMatthew G. Knepley } 3408b004864fSMatthew G. Knepley 3409b004864fSMatthew G. Knepley /*@ 3410ea844a1aSMatthew Knepley PetscSectionGetUseFieldOffsets - Get the flag to use field offsets directly in a global section, rather than just the point offset 3411ea844a1aSMatthew Knepley 341240750d41SVaclav Hapla Not Collective 3413ea844a1aSMatthew Knepley 3414ea844a1aSMatthew Knepley Input Parameter: 3415ea844a1aSMatthew Knepley . s - the global PetscSection 3416ea844a1aSMatthew Knepley 3417ea844a1aSMatthew Knepley Output Parameters: 3418ea844a1aSMatthew Knepley . flg - the flag 3419ea844a1aSMatthew Knepley 3420ea844a1aSMatthew Knepley Level: developer 3421ea844a1aSMatthew Knepley 3422db781477SPatrick Sanan .seealso: `PetscSectionSetChart()`, `PetscSectionCreate()` 3423ea844a1aSMatthew Knepley @*/ 3424*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetUseFieldOffsets(PetscSection s, PetscBool *flg) 3425*d71ae5a4SJacob Faibussowitsch { 3426ea844a1aSMatthew Knepley PetscFunctionBegin; 3427ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 3428ea844a1aSMatthew Knepley *flg = s->useFieldOff; 3429ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3430ea844a1aSMatthew Knepley } 3431ea844a1aSMatthew Knepley 3432ea844a1aSMatthew Knepley /*@ 3433ea844a1aSMatthew Knepley PetscSectionSetUseFieldOffsets - Set the flag to use field offsets directly in a global section, rather than just the point offset 3434ea844a1aSMatthew Knepley 343540750d41SVaclav Hapla Not Collective 3436ea844a1aSMatthew Knepley 3437ea844a1aSMatthew Knepley Input Parameters: 3438ea844a1aSMatthew Knepley + s - the global PetscSection 3439ea844a1aSMatthew Knepley - flg - the flag 3440ea844a1aSMatthew Knepley 3441ea844a1aSMatthew Knepley Level: developer 3442ea844a1aSMatthew Knepley 3443db781477SPatrick Sanan .seealso: `PetscSectionGetUseFieldOffsets()`, `PetscSectionSetChart()`, `PetscSectionCreate()` 3444ea844a1aSMatthew Knepley @*/ 3445*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetUseFieldOffsets(PetscSection s, PetscBool flg) 3446*d71ae5a4SJacob Faibussowitsch { 3447ea844a1aSMatthew Knepley PetscFunctionBegin; 3448ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 3449ea844a1aSMatthew Knepley s->useFieldOff = flg; 3450ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3451ea844a1aSMatthew Knepley } 3452ea844a1aSMatthew Knepley 3453ea844a1aSMatthew Knepley #define PetscSectionExpandPoints_Loop(TYPE) \ 3454ea844a1aSMatthew Knepley { \ 3455ea844a1aSMatthew Knepley PetscInt i, n, o0, o1, size; \ 3456ea844a1aSMatthew Knepley TYPE *a0 = (TYPE *)origArray, *a1; \ 34579566063dSJacob Faibussowitsch PetscCall(PetscSectionGetStorageSize(s, &size)); \ 34589566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(size, &a1)); \ 3459ea844a1aSMatthew Knepley for (i = 0; i < npoints; i++) { \ 34609566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(origSection, points_[i], &o0)); \ 34619566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s, i, &o1)); \ 34629566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, i, &n)); \ 34639566063dSJacob Faibussowitsch PetscCall(PetscMemcpy(&a1[o1], &a0[o0], n *unitsize)); \ 3464ea844a1aSMatthew Knepley } \ 3465ea844a1aSMatthew Knepley *newArray = (void *)a1; \ 3466ea844a1aSMatthew Knepley } 3467ea844a1aSMatthew Knepley 3468ea844a1aSMatthew Knepley /*@ 3469ea844a1aSMatthew Knepley PetscSectionExtractDofsFromArray - Extracts elements of an array corresponding to DOFs of specified points. 3470ea844a1aSMatthew Knepley 347140750d41SVaclav Hapla Not Collective 3472ea844a1aSMatthew Knepley 3473ea844a1aSMatthew Knepley Input Parameters: 3474ea844a1aSMatthew Knepley + origSection - the PetscSection describing the layout of the array 3475ea844a1aSMatthew Knepley . dataType - MPI_Datatype describing the data type of the array (currently only MPIU_INT, MPIU_SCALAR, MPIU_REAL) 3476ea844a1aSMatthew Knepley . origArray - the array; its size must be equal to the storage size of origSection 3477ea844a1aSMatthew Knepley - points - IS with points to extract; its indices must lie in the chart of origSection 3478ea844a1aSMatthew Knepley 3479ea844a1aSMatthew Knepley Output Parameters: 3480ea844a1aSMatthew Knepley + newSection - the new PetscSection desribing the layout of the new array (with points renumbered 0,1,... but preserving numbers of DOFs) 3481ea844a1aSMatthew Knepley - newArray - the array of the extracted DOFs; its size is the storage size of newSection 3482ea844a1aSMatthew Knepley 3483ea844a1aSMatthew Knepley Level: developer 3484ea844a1aSMatthew Knepley 3485db781477SPatrick Sanan .seealso: `PetscSectionGetChart()`, `PetscSectionGetDof()`, `PetscSectionGetStorageSize()`, `PetscSectionCreate()` 3486ea844a1aSMatthew Knepley @*/ 3487*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionExtractDofsFromArray(PetscSection origSection, MPI_Datatype dataType, const void *origArray, IS points, PetscSection *newSection, void *newArray[]) 3488*d71ae5a4SJacob Faibussowitsch { 3489ea844a1aSMatthew Knepley PetscSection s; 3490ea844a1aSMatthew Knepley const PetscInt *points_; 3491ea844a1aSMatthew Knepley PetscInt i, n, npoints, pStart, pEnd; 3492ea844a1aSMatthew Knepley PetscMPIInt unitsize; 3493ea844a1aSMatthew Knepley 3494ea844a1aSMatthew Knepley PetscFunctionBegin; 3495ea844a1aSMatthew Knepley PetscValidHeaderSpecific(origSection, PETSC_SECTION_CLASSID, 1); 3496ea844a1aSMatthew Knepley PetscValidPointer(origArray, 3); 3497ea844a1aSMatthew Knepley PetscValidHeaderSpecific(points, IS_CLASSID, 4); 3498ea844a1aSMatthew Knepley if (newSection) PetscValidPointer(newSection, 5); 3499ea844a1aSMatthew Knepley if (newArray) PetscValidPointer(newArray, 6); 35009566063dSJacob Faibussowitsch PetscCallMPI(MPI_Type_size(dataType, &unitsize)); 35019566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(points, &npoints)); 35029566063dSJacob Faibussowitsch PetscCall(ISGetIndices(points, &points_)); 35039566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(origSection, &pStart, &pEnd)); 35049566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PETSC_COMM_SELF, &s)); 35059566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(s, 0, npoints)); 3506ea844a1aSMatthew Knepley for (i = 0; i < npoints; i++) { 3507c9cc58a2SBarry 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); 35089566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(origSection, points_[i], &n)); 35099566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(s, i, n)); 3510ea844a1aSMatthew Knepley } 35119566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(s)); 3512ea844a1aSMatthew Knepley if (newArray) { 35139371c9d4SSatish Balay if (dataType == MPIU_INT) { 35149371c9d4SSatish Balay PetscSectionExpandPoints_Loop(PetscInt); 35159371c9d4SSatish Balay } else if (dataType == MPIU_SCALAR) { 35169371c9d4SSatish Balay PetscSectionExpandPoints_Loop(PetscScalar); 35179371c9d4SSatish Balay } else if (dataType == MPIU_REAL) { 35189371c9d4SSatish Balay PetscSectionExpandPoints_Loop(PetscReal); 35199371c9d4SSatish Balay } else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "not implemented for this MPI_Datatype"); 3520ea844a1aSMatthew Knepley } 3521ea844a1aSMatthew Knepley if (newSection) { 3522ea844a1aSMatthew Knepley *newSection = s; 3523ea844a1aSMatthew Knepley } else { 35249566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s)); 3525ea844a1aSMatthew Knepley } 35269566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(points, &points_)); 3527ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3528ea844a1aSMatthew Knepley } 3529