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 31ea844a1aSMatthew Knepley The PetscSection object and methods are intended to be used in the PETSc Vec and Mat implementions; it is 32ea844a1aSMatthew Knepley recommended they not be used in user codes unless you really gain something in their use. 33ea844a1aSMatthew Knepley 34ea844a1aSMatthew Knepley .seealso: PetscSection, PetscSectionDestroy() 35ea844a1aSMatthew Knepley @*/ 36ea844a1aSMatthew Knepley PetscErrorCode PetscSectionCreate(MPI_Comm comm, PetscSection *s) 37ea844a1aSMatthew Knepley { 38ea844a1aSMatthew Knepley PetscErrorCode ierr; 39ea844a1aSMatthew Knepley 40ea844a1aSMatthew Knepley PetscFunctionBegin; 41ea844a1aSMatthew Knepley PetscValidPointer(s,2); 42ea844a1aSMatthew Knepley ierr = ISInitializePackage();CHKERRQ(ierr); 43ea844a1aSMatthew Knepley 44ea844a1aSMatthew Knepley ierr = PetscHeaderCreate(*s,PETSC_SECTION_CLASSID,"PetscSection","Section","IS",comm,PetscSectionDestroy,PetscSectionView);CHKERRQ(ierr); 45ea844a1aSMatthew Knepley 46ea844a1aSMatthew Knepley (*s)->pStart = -1; 47ea844a1aSMatthew Knepley (*s)->pEnd = -1; 48ea844a1aSMatthew Knepley (*s)->perm = NULL; 49ea844a1aSMatthew Knepley (*s)->pointMajor = PETSC_TRUE; 5087e637c6Sksagiyam (*s)->includesConstraints = PETSC_TRUE; 51ea844a1aSMatthew Knepley (*s)->maxDof = 0; 52ea844a1aSMatthew Knepley (*s)->atlasDof = NULL; 53ea844a1aSMatthew Knepley (*s)->atlasOff = NULL; 54ea844a1aSMatthew Knepley (*s)->bc = NULL; 55ea844a1aSMatthew Knepley (*s)->bcIndices = NULL; 56ea844a1aSMatthew Knepley (*s)->setup = PETSC_FALSE; 57ea844a1aSMatthew Knepley (*s)->numFields = 0; 58ea844a1aSMatthew Knepley (*s)->fieldNames = NULL; 59ea844a1aSMatthew Knepley (*s)->field = NULL; 60ea844a1aSMatthew Knepley (*s)->useFieldOff = PETSC_FALSE; 61b778fa18SValeria Barra (*s)->compNames = NULL; 62ea844a1aSMatthew Knepley (*s)->clObj = NULL; 63c459fbc1SJed Brown (*s)->clHash = NULL; 64ea844a1aSMatthew Knepley (*s)->clSection = NULL; 65ea844a1aSMatthew Knepley (*s)->clPoints = NULL; 66ea844a1aSMatthew Knepley PetscFunctionReturn(0); 67ea844a1aSMatthew Knepley } 68ea844a1aSMatthew Knepley 69ea844a1aSMatthew Knepley /*@ 70ea844a1aSMatthew Knepley PetscSectionCopy - Creates a shallow (if possible) copy of the PetscSection 71ea844a1aSMatthew Knepley 72ea844a1aSMatthew Knepley Collective 73ea844a1aSMatthew Knepley 74ea844a1aSMatthew Knepley Input Parameter: 75ea844a1aSMatthew Knepley . section - the PetscSection 76ea844a1aSMatthew Knepley 77ea844a1aSMatthew Knepley Output Parameter: 78ea844a1aSMatthew Knepley . newSection - the copy 79ea844a1aSMatthew Knepley 80ea844a1aSMatthew Knepley Level: intermediate 81ea844a1aSMatthew Knepley 82ea844a1aSMatthew Knepley .seealso: PetscSection, PetscSectionCreate(), PetscSectionDestroy() 83ea844a1aSMatthew Knepley @*/ 84ea844a1aSMatthew Knepley PetscErrorCode PetscSectionCopy(PetscSection section, PetscSection newSection) 85ea844a1aSMatthew Knepley { 86ea844a1aSMatthew Knepley PetscSectionSym sym; 87ea844a1aSMatthew Knepley IS perm; 88b778fa18SValeria Barra PetscInt numFields, f, c, pStart, pEnd, p; 89ea844a1aSMatthew Knepley PetscErrorCode ierr; 90ea844a1aSMatthew Knepley 91ea844a1aSMatthew Knepley PetscFunctionBegin; 92ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 93ea844a1aSMatthew Knepley PetscValidHeaderSpecific(newSection, PETSC_SECTION_CLASSID, 2); 94124bfe34SStefano Zampini ierr = PetscSectionReset(newSection);CHKERRQ(ierr); 95ea844a1aSMatthew Knepley ierr = PetscSectionGetNumFields(section, &numFields);CHKERRQ(ierr); 96ea844a1aSMatthew Knepley if (numFields) {ierr = PetscSectionSetNumFields(newSection, numFields);CHKERRQ(ierr);} 97ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 98b778fa18SValeria Barra const char *fieldName = NULL, *compName = NULL; 99ea844a1aSMatthew Knepley PetscInt numComp = 0; 100ea844a1aSMatthew Knepley 101b778fa18SValeria Barra ierr = PetscSectionGetFieldName(section, f, &fieldName);CHKERRQ(ierr); 102b778fa18SValeria Barra ierr = PetscSectionSetFieldName(newSection, f, fieldName);CHKERRQ(ierr); 103ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldComponents(section, f, &numComp);CHKERRQ(ierr); 104ea844a1aSMatthew Knepley ierr = PetscSectionSetFieldComponents(newSection, f, numComp);CHKERRQ(ierr); 105b778fa18SValeria Barra for (c = 0; c < numComp; ++c) { 106b778fa18SValeria Barra ierr = PetscSectionGetComponentName(section, f, c, &compName);CHKERRQ(ierr); 107b778fa18SValeria Barra ierr = PetscSectionSetComponentName(newSection, f, c, compName);CHKERRQ(ierr); 108b778fa18SValeria Barra } 109ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldSym(section, f, &sym);CHKERRQ(ierr); 110ea844a1aSMatthew Knepley ierr = PetscSectionSetFieldSym(newSection, f, sym);CHKERRQ(ierr); 111ea844a1aSMatthew Knepley } 112ea844a1aSMatthew Knepley ierr = PetscSectionGetChart(section, &pStart, &pEnd);CHKERRQ(ierr); 113ea844a1aSMatthew Knepley ierr = PetscSectionSetChart(newSection, pStart, pEnd);CHKERRQ(ierr); 114ea844a1aSMatthew Knepley ierr = PetscSectionGetPermutation(section, &perm);CHKERRQ(ierr); 115ea844a1aSMatthew Knepley ierr = PetscSectionSetPermutation(newSection, perm);CHKERRQ(ierr); 116ea844a1aSMatthew Knepley ierr = PetscSectionGetSym(section, &sym);CHKERRQ(ierr); 117ea844a1aSMatthew Knepley ierr = PetscSectionSetSym(newSection, sym);CHKERRQ(ierr); 118ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 119ea844a1aSMatthew Knepley PetscInt dof, cdof, fcdof = 0; 120ea844a1aSMatthew Knepley 121ea844a1aSMatthew Knepley ierr = PetscSectionGetDof(section, p, &dof);CHKERRQ(ierr); 122ea844a1aSMatthew Knepley ierr = PetscSectionSetDof(newSection, p, dof);CHKERRQ(ierr); 123ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintDof(section, p, &cdof);CHKERRQ(ierr); 124ea844a1aSMatthew Knepley if (cdof) {ierr = PetscSectionSetConstraintDof(newSection, p, cdof);CHKERRQ(ierr);} 125ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 126ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldDof(section, p, f, &dof);CHKERRQ(ierr); 127ea844a1aSMatthew Knepley ierr = PetscSectionSetFieldDof(newSection, p, f, dof);CHKERRQ(ierr); 128ea844a1aSMatthew Knepley if (cdof) { 129ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, f, &fcdof);CHKERRQ(ierr); 130ea844a1aSMatthew Knepley if (fcdof) {ierr = PetscSectionSetFieldConstraintDof(newSection, p, f, fcdof);CHKERRQ(ierr);} 131ea844a1aSMatthew Knepley } 132ea844a1aSMatthew Knepley } 133ea844a1aSMatthew Knepley } 134ea844a1aSMatthew Knepley ierr = PetscSectionSetUp(newSection);CHKERRQ(ierr); 135ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 136ea844a1aSMatthew Knepley PetscInt off, cdof, fcdof = 0; 137ea844a1aSMatthew Knepley const PetscInt *cInd; 138ea844a1aSMatthew Knepley 139ea844a1aSMatthew Knepley /* Must set offsets in case they do not agree with the prefix sums */ 140ea844a1aSMatthew Knepley ierr = PetscSectionGetOffset(section, p, &off);CHKERRQ(ierr); 141ea844a1aSMatthew Knepley ierr = PetscSectionSetOffset(newSection, p, off);CHKERRQ(ierr); 142ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintDof(section, p, &cdof);CHKERRQ(ierr); 143ea844a1aSMatthew Knepley if (cdof) { 144ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintIndices(section, p, &cInd);CHKERRQ(ierr); 145ea844a1aSMatthew Knepley ierr = PetscSectionSetConstraintIndices(newSection, p, cInd);CHKERRQ(ierr); 146ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 147ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, f, &fcdof);CHKERRQ(ierr); 148ea844a1aSMatthew Knepley if (fcdof) { 149ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldConstraintIndices(section, p, f, &cInd);CHKERRQ(ierr); 150ea844a1aSMatthew Knepley ierr = PetscSectionSetFieldConstraintIndices(newSection, p, f, cInd);CHKERRQ(ierr); 151ea844a1aSMatthew Knepley } 152ea844a1aSMatthew Knepley } 153ea844a1aSMatthew Knepley } 154ea844a1aSMatthew Knepley } 155ea844a1aSMatthew Knepley PetscFunctionReturn(0); 156ea844a1aSMatthew Knepley } 157ea844a1aSMatthew Knepley 158ea844a1aSMatthew Knepley /*@ 159ea844a1aSMatthew Knepley PetscSectionClone - Creates a shallow (if possible) copy of the PetscSection 160ea844a1aSMatthew Knepley 161ea844a1aSMatthew Knepley Collective 162ea844a1aSMatthew Knepley 163ea844a1aSMatthew Knepley Input Parameter: 164ea844a1aSMatthew Knepley . section - the PetscSection 165ea844a1aSMatthew Knepley 166ea844a1aSMatthew Knepley Output Parameter: 167ea844a1aSMatthew Knepley . newSection - the copy 168ea844a1aSMatthew Knepley 169ea844a1aSMatthew Knepley Level: beginner 170ea844a1aSMatthew Knepley 171ea844a1aSMatthew Knepley .seealso: PetscSection, PetscSectionCreate(), PetscSectionDestroy() 172ea844a1aSMatthew Knepley @*/ 173ea844a1aSMatthew Knepley PetscErrorCode PetscSectionClone(PetscSection section, PetscSection *newSection) 174ea844a1aSMatthew Knepley { 175ea844a1aSMatthew Knepley PetscErrorCode ierr; 176ea844a1aSMatthew Knepley 177ea844a1aSMatthew Knepley PetscFunctionBegin; 178ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 179ea844a1aSMatthew Knepley PetscValidPointer(newSection, 2); 180ea844a1aSMatthew Knepley ierr = PetscSectionCreate(PetscObjectComm((PetscObject) section), newSection);CHKERRQ(ierr); 181ea844a1aSMatthew Knepley ierr = PetscSectionCopy(section, *newSection);CHKERRQ(ierr); 182ea844a1aSMatthew Knepley PetscFunctionReturn(0); 183ea844a1aSMatthew Knepley } 184ea844a1aSMatthew Knepley 185ea844a1aSMatthew Knepley /*@ 186ea844a1aSMatthew Knepley PetscSectionSetFromOptions - sets parameters in a PetscSection from the options database 187ea844a1aSMatthew Knepley 188ea844a1aSMatthew Knepley Collective on PetscSection 189ea844a1aSMatthew Knepley 190ea844a1aSMatthew Knepley Input Parameter: 191ea844a1aSMatthew Knepley . section - the PetscSection 192ea844a1aSMatthew Knepley 193ea844a1aSMatthew Knepley Options Database: 194*147403d9SBarry Smith . -petscsection_point_major - PETSC_TRUE for point-major order 195ea844a1aSMatthew Knepley 196ea844a1aSMatthew Knepley Level: intermediate 197ea844a1aSMatthew Knepley 198ea844a1aSMatthew Knepley .seealso: PetscSection, PetscSectionCreate(), PetscSectionDestroy() 199ea844a1aSMatthew Knepley @*/ 200ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetFromOptions(PetscSection s) 201ea844a1aSMatthew Knepley { 202ea844a1aSMatthew Knepley PetscErrorCode ierr; 203ea844a1aSMatthew Knepley 204ea844a1aSMatthew Knepley PetscFunctionBegin; 205ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 206ea844a1aSMatthew Knepley ierr = PetscObjectOptionsBegin((PetscObject) s);CHKERRQ(ierr); 207ea844a1aSMatthew Knepley ierr = PetscOptionsBool("-petscsection_point_major", "The for ordering, either point major or field major", "PetscSectionSetPointMajor", s->pointMajor, &s->pointMajor, NULL);CHKERRQ(ierr); 208ea844a1aSMatthew Knepley /* process any options handlers added with PetscObjectAddOptionsHandler() */ 209ea844a1aSMatthew Knepley ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) s);CHKERRQ(ierr); 210ea844a1aSMatthew Knepley ierr = PetscOptionsEnd();CHKERRQ(ierr); 211ea844a1aSMatthew Knepley ierr = PetscObjectViewFromOptions((PetscObject) s, NULL, "-petscsection_view");CHKERRQ(ierr); 212ea844a1aSMatthew Knepley PetscFunctionReturn(0); 213ea844a1aSMatthew Knepley } 214ea844a1aSMatthew Knepley 215ea844a1aSMatthew Knepley /*@ 216ea844a1aSMatthew Knepley PetscSectionCompare - Compares two sections 217ea844a1aSMatthew Knepley 218ea844a1aSMatthew Knepley Collective on PetscSection 219ea844a1aSMatthew Knepley 2207a7aea1fSJed Brown Input Parameters: 221ea844a1aSMatthew Knepley + s1 - the first PetscSection 222ea844a1aSMatthew Knepley - s2 - the second PetscSection 223ea844a1aSMatthew Knepley 224ea844a1aSMatthew Knepley Output Parameter: 225ea844a1aSMatthew Knepley . congruent - PETSC_TRUE if the two sections are congruent, PETSC_FALSE otherwise 226ea844a1aSMatthew Knepley 227ea844a1aSMatthew Knepley Level: intermediate 228ea844a1aSMatthew Knepley 229ea844a1aSMatthew Knepley Notes: 230ea844a1aSMatthew Knepley Field names are disregarded. 231ea844a1aSMatthew Knepley 232ea844a1aSMatthew Knepley .seealso: PetscSection, PetscSectionCreate(), PetscSectionCopy(), PetscSectionClone() 233ea844a1aSMatthew Knepley @*/ 234ea844a1aSMatthew Knepley PetscErrorCode PetscSectionCompare(PetscSection s1, PetscSection s2, PetscBool *congruent) 235ea844a1aSMatthew Knepley { 236ea844a1aSMatthew Knepley PetscInt pStart, pEnd, nfields, ncdof, nfcdof, p, f, n1, n2; 237ea844a1aSMatthew Knepley const PetscInt *idx1, *idx2; 238ea844a1aSMatthew Knepley IS perm1, perm2; 239ea844a1aSMatthew Knepley PetscBool flg; 240ea844a1aSMatthew Knepley PetscMPIInt mflg; 241ea844a1aSMatthew Knepley PetscErrorCode ierr; 242ea844a1aSMatthew Knepley 243ea844a1aSMatthew Knepley PetscFunctionBegin; 244ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s1, PETSC_SECTION_CLASSID, 1); 245ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s2, PETSC_SECTION_CLASSID, 2); 246064a246eSJacob Faibussowitsch PetscValidBoolPointer(congruent,3); 247ea844a1aSMatthew Knepley flg = PETSC_FALSE; 248ea844a1aSMatthew Knepley 249ffc4695bSBarry Smith ierr = MPI_Comm_compare(PetscObjectComm((PetscObject)s1),PetscObjectComm((PetscObject)s2),&mflg);CHKERRMPI(ierr); 250ea844a1aSMatthew Knepley if (mflg != MPI_CONGRUENT && mflg != MPI_IDENT) { 251ea844a1aSMatthew Knepley *congruent = PETSC_FALSE; 252ea844a1aSMatthew Knepley PetscFunctionReturn(0); 253ea844a1aSMatthew Knepley } 254ea844a1aSMatthew Knepley 255ea844a1aSMatthew Knepley ierr = PetscSectionGetChart(s1, &pStart, &pEnd);CHKERRQ(ierr); 256ea844a1aSMatthew Knepley ierr = PetscSectionGetChart(s2, &n1, &n2);CHKERRQ(ierr); 257ea844a1aSMatthew Knepley if (pStart != n1 || pEnd != n2) goto not_congruent; 258ea844a1aSMatthew Knepley 259ea844a1aSMatthew Knepley ierr = PetscSectionGetPermutation(s1, &perm1);CHKERRQ(ierr); 260ea844a1aSMatthew Knepley ierr = PetscSectionGetPermutation(s2, &perm2);CHKERRQ(ierr); 261ea844a1aSMatthew Knepley if (perm1 && perm2) { 262ea844a1aSMatthew Knepley ierr = ISEqual(perm1, perm2, congruent);CHKERRQ(ierr); 263ea844a1aSMatthew Knepley if (!(*congruent)) goto not_congruent; 264ea844a1aSMatthew Knepley } else if (perm1 != perm2) goto not_congruent; 265ea844a1aSMatthew Knepley 266ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 267ea844a1aSMatthew Knepley ierr = PetscSectionGetOffset(s1, p, &n1);CHKERRQ(ierr); 268ea844a1aSMatthew Knepley ierr = PetscSectionGetOffset(s2, p, &n2);CHKERRQ(ierr); 269ea844a1aSMatthew Knepley if (n1 != n2) goto not_congruent; 270ea844a1aSMatthew Knepley 271ea844a1aSMatthew Knepley ierr = PetscSectionGetDof(s1, p, &n1);CHKERRQ(ierr); 272ea844a1aSMatthew Knepley ierr = PetscSectionGetDof(s2, p, &n2);CHKERRQ(ierr); 273ea844a1aSMatthew Knepley if (n1 != n2) goto not_congruent; 274ea844a1aSMatthew Knepley 275ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintDof(s1, p, &ncdof);CHKERRQ(ierr); 276ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintDof(s2, p, &n2);CHKERRQ(ierr); 277ea844a1aSMatthew Knepley if (ncdof != n2) goto not_congruent; 278ea844a1aSMatthew Knepley 279ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintIndices(s1, p, &idx1);CHKERRQ(ierr); 280ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintIndices(s2, p, &idx2);CHKERRQ(ierr); 281ea844a1aSMatthew Knepley ierr = PetscArraycmp(idx1, idx2, ncdof, congruent);CHKERRQ(ierr); 282ea844a1aSMatthew Knepley if (!(*congruent)) goto not_congruent; 283ea844a1aSMatthew Knepley } 284ea844a1aSMatthew Knepley 285ea844a1aSMatthew Knepley ierr = PetscSectionGetNumFields(s1, &nfields);CHKERRQ(ierr); 286ea844a1aSMatthew Knepley ierr = PetscSectionGetNumFields(s2, &n2);CHKERRQ(ierr); 287ea844a1aSMatthew Knepley if (nfields != n2) goto not_congruent; 288ea844a1aSMatthew Knepley 289ea844a1aSMatthew Knepley for (f = 0; f < nfields; ++f) { 290ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldComponents(s1, f, &n1);CHKERRQ(ierr); 291ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldComponents(s2, f, &n2);CHKERRQ(ierr); 292ea844a1aSMatthew Knepley if (n1 != n2) goto not_congruent; 293ea844a1aSMatthew Knepley 294ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 295ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldOffset(s1, p, f, &n1);CHKERRQ(ierr); 296ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldOffset(s2, p, f, &n2);CHKERRQ(ierr); 297ea844a1aSMatthew Knepley if (n1 != n2) goto not_congruent; 298ea844a1aSMatthew Knepley 299ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldDof(s1, p, f, &n1);CHKERRQ(ierr); 300ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldDof(s2, p, f, &n2);CHKERRQ(ierr); 301ea844a1aSMatthew Knepley if (n1 != n2) goto not_congruent; 302ea844a1aSMatthew Knepley 303ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldConstraintDof(s1, p, f, &nfcdof);CHKERRQ(ierr); 304ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldConstraintDof(s2, p, f, &n2);CHKERRQ(ierr); 305ea844a1aSMatthew Knepley if (nfcdof != n2) goto not_congruent; 306ea844a1aSMatthew Knepley 307ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldConstraintIndices(s1, p, f, &idx1);CHKERRQ(ierr); 308ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldConstraintIndices(s2, p, f, &idx2);CHKERRQ(ierr); 309ea844a1aSMatthew Knepley ierr = PetscArraycmp(idx1, idx2, nfcdof, congruent);CHKERRQ(ierr); 310ea844a1aSMatthew Knepley if (!(*congruent)) goto not_congruent; 311ea844a1aSMatthew Knepley } 312ea844a1aSMatthew Knepley } 313ea844a1aSMatthew Knepley 314ea844a1aSMatthew Knepley flg = PETSC_TRUE; 315ea844a1aSMatthew Knepley not_congruent: 316820f2d46SBarry Smith ierr = MPIU_Allreduce(&flg,congruent,1,MPIU_BOOL,MPI_LAND,PetscObjectComm((PetscObject)s1));CHKERRMPI(ierr); 317ea844a1aSMatthew Knepley PetscFunctionReturn(0); 318ea844a1aSMatthew Knepley } 319ea844a1aSMatthew Knepley 320ea844a1aSMatthew Knepley /*@ 321ea844a1aSMatthew Knepley PetscSectionGetNumFields - Returns the number of fields, or 0 if no fields were defined. 322ea844a1aSMatthew Knepley 323ea844a1aSMatthew Knepley Not collective 324ea844a1aSMatthew Knepley 325ea844a1aSMatthew Knepley Input Parameter: 326ea844a1aSMatthew Knepley . s - the PetscSection 327ea844a1aSMatthew Knepley 328ea844a1aSMatthew Knepley Output Parameter: 329ea844a1aSMatthew Knepley . numFields - the number of fields defined, or 0 if none were defined 330ea844a1aSMatthew Knepley 331ea844a1aSMatthew Knepley Level: intermediate 332ea844a1aSMatthew Knepley 333ea844a1aSMatthew Knepley .seealso: PetscSectionSetNumFields() 334ea844a1aSMatthew Knepley @*/ 335ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetNumFields(PetscSection s, PetscInt *numFields) 336ea844a1aSMatthew Knepley { 337ea844a1aSMatthew Knepley PetscFunctionBegin; 338ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 339ea844a1aSMatthew Knepley PetscValidPointer(numFields,2); 340ea844a1aSMatthew Knepley *numFields = s->numFields; 341ea844a1aSMatthew Knepley PetscFunctionReturn(0); 342ea844a1aSMatthew Knepley } 343ea844a1aSMatthew Knepley 344ea844a1aSMatthew Knepley /*@ 345ea844a1aSMatthew Knepley PetscSectionSetNumFields - Sets the number of fields. 346ea844a1aSMatthew Knepley 347ea844a1aSMatthew Knepley Not collective 348ea844a1aSMatthew Knepley 349ea844a1aSMatthew Knepley Input Parameters: 350ea844a1aSMatthew Knepley + s - the PetscSection 351ea844a1aSMatthew Knepley - numFields - the number of fields 352ea844a1aSMatthew Knepley 353ea844a1aSMatthew Knepley Level: intermediate 354ea844a1aSMatthew Knepley 355ea844a1aSMatthew Knepley .seealso: PetscSectionGetNumFields() 356ea844a1aSMatthew Knepley @*/ 357ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetNumFields(PetscSection s, PetscInt numFields) 358ea844a1aSMatthew Knepley { 359ea844a1aSMatthew Knepley PetscInt f; 360ea844a1aSMatthew Knepley PetscErrorCode ierr; 361ea844a1aSMatthew Knepley 362ea844a1aSMatthew Knepley PetscFunctionBegin; 363ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 3642c71b3e2SJacob Faibussowitsch PetscCheckFalse(numFields <= 0,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "The number of fields %" PetscInt_FMT " must be positive", numFields); 365ea844a1aSMatthew Knepley ierr = PetscSectionReset(s);CHKERRQ(ierr); 366ea844a1aSMatthew Knepley 367ea844a1aSMatthew Knepley s->numFields = numFields; 368ea844a1aSMatthew Knepley ierr = PetscMalloc1(s->numFields, &s->numFieldComponents);CHKERRQ(ierr); 369ea844a1aSMatthew Knepley ierr = PetscMalloc1(s->numFields, &s->fieldNames);CHKERRQ(ierr); 370b778fa18SValeria Barra ierr = PetscMalloc1(s->numFields, &s->compNames);CHKERRQ(ierr); 371ea844a1aSMatthew Knepley ierr = PetscMalloc1(s->numFields, &s->field);CHKERRQ(ierr); 372ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) { 373ea844a1aSMatthew Knepley char name[64]; 374ea844a1aSMatthew Knepley 375ea844a1aSMatthew Knepley s->numFieldComponents[f] = 1; 376ea844a1aSMatthew Knepley 377ea844a1aSMatthew Knepley ierr = PetscSectionCreate(PetscObjectComm((PetscObject) s), &s->field[f]);CHKERRQ(ierr); 3782cfd1bebSJacob Faibussowitsch ierr = PetscSNPrintf(name, 64, "Field_%" PetscInt_FMT, f);CHKERRQ(ierr); 379ea844a1aSMatthew Knepley ierr = PetscStrallocpy(name, (char **) &s->fieldNames[f]);CHKERRQ(ierr); 380b778fa18SValeria Barra ierr = PetscSNPrintf(name, 64, "Component_0");CHKERRQ(ierr); 381b778fa18SValeria Barra ierr = PetscMalloc1(s->numFieldComponents[f], &s->compNames[f]);CHKERRQ(ierr); 382b778fa18SValeria Barra ierr = PetscStrallocpy(name, (char **) &s->compNames[f][0]);CHKERRQ(ierr); 383ea844a1aSMatthew Knepley } 384ea844a1aSMatthew Knepley PetscFunctionReturn(0); 385ea844a1aSMatthew Knepley } 386ea844a1aSMatthew Knepley 387ea844a1aSMatthew Knepley /*@C 388ea844a1aSMatthew Knepley PetscSectionGetFieldName - Returns the name of a field in the PetscSection 389ea844a1aSMatthew Knepley 390ea844a1aSMatthew Knepley Not Collective 391ea844a1aSMatthew Knepley 392ea844a1aSMatthew Knepley Input Parameters: 393ea844a1aSMatthew Knepley + s - the PetscSection 394ea844a1aSMatthew Knepley - field - the field number 395ea844a1aSMatthew Knepley 396ea844a1aSMatthew Knepley Output Parameter: 397ea844a1aSMatthew Knepley . fieldName - the field name 398ea844a1aSMatthew Knepley 399ea844a1aSMatthew Knepley Level: intermediate 400ea844a1aSMatthew Knepley 401ea844a1aSMatthew Knepley .seealso: PetscSectionSetFieldName() 402ea844a1aSMatthew Knepley @*/ 403ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetFieldName(PetscSection s, PetscInt field, const char *fieldName[]) 404ea844a1aSMatthew Knepley { 405ea844a1aSMatthew Knepley PetscFunctionBegin; 406ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 407ea844a1aSMatthew Knepley PetscValidPointer(fieldName, 3); 4082abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field,s->numFields); 409ea844a1aSMatthew Knepley *fieldName = s->fieldNames[field]; 410ea844a1aSMatthew Knepley PetscFunctionReturn(0); 411ea844a1aSMatthew Knepley } 412ea844a1aSMatthew Knepley 413ea844a1aSMatthew Knepley /*@C 414ea844a1aSMatthew Knepley PetscSectionSetFieldName - Sets the name of a field in the PetscSection 415ea844a1aSMatthew Knepley 416ea844a1aSMatthew Knepley Not Collective 417ea844a1aSMatthew Knepley 418ea844a1aSMatthew Knepley Input Parameters: 419ea844a1aSMatthew Knepley + s - the PetscSection 420ea844a1aSMatthew Knepley . field - the field number 421ea844a1aSMatthew Knepley - fieldName - the field name 422ea844a1aSMatthew Knepley 423ea844a1aSMatthew Knepley Level: intermediate 424ea844a1aSMatthew Knepley 425ea844a1aSMatthew Knepley .seealso: PetscSectionGetFieldName() 426ea844a1aSMatthew Knepley @*/ 427ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetFieldName(PetscSection s, PetscInt field, const char fieldName[]) 428ea844a1aSMatthew Knepley { 429ea844a1aSMatthew Knepley PetscErrorCode ierr; 430ea844a1aSMatthew Knepley 431ea844a1aSMatthew Knepley PetscFunctionBegin; 432ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 433ea844a1aSMatthew Knepley if (fieldName) PetscValidCharPointer(fieldName, 3); 4342abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field,s->numFields); 435ea844a1aSMatthew Knepley ierr = PetscFree(s->fieldNames[field]);CHKERRQ(ierr); 436ea844a1aSMatthew Knepley ierr = PetscStrallocpy(fieldName, (char**) &s->fieldNames[field]);CHKERRQ(ierr); 437ea844a1aSMatthew Knepley PetscFunctionReturn(0); 438ea844a1aSMatthew Knepley } 439ea844a1aSMatthew Knepley 440b778fa18SValeria Barra /*@C 441b778fa18SValeria Barra PetscSectionGetComponentName - Gets the name of a field component in the PetscSection 442b778fa18SValeria Barra 443b778fa18SValeria Barra Not Collective 444b778fa18SValeria Barra 445b778fa18SValeria Barra Input Parameters: 446b778fa18SValeria Barra + s - the PetscSection 447b778fa18SValeria Barra . field - the field number 448b778fa18SValeria Barra . comp - the component number 449b778fa18SValeria Barra - compName - the component name 450b778fa18SValeria Barra 451b778fa18SValeria Barra Level: intermediate 452b778fa18SValeria Barra 453b778fa18SValeria Barra .seealso: PetscSectionSetComponentName() 454b778fa18SValeria Barra @*/ 455b778fa18SValeria Barra PetscErrorCode PetscSectionGetComponentName(PetscSection s, PetscInt field, PetscInt comp, const char *compName[]) 456b778fa18SValeria Barra { 457b778fa18SValeria Barra PetscFunctionBegin; 458b778fa18SValeria Barra PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 459064a246eSJacob Faibussowitsch PetscValidPointer(compName, 4); 4602abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field,s->numFields); 4612abc8c78SJacob Faibussowitsch PetscSectionCheckValidFieldComponent(comp,s->numFieldComponents[field]); 462b778fa18SValeria Barra *compName = s->compNames[field][comp]; 463b778fa18SValeria Barra PetscFunctionReturn(0); 464b778fa18SValeria Barra } 465b778fa18SValeria Barra 466b778fa18SValeria Barra /*@C 467b778fa18SValeria Barra PetscSectionSetComponentName - Sets the name of a field component in the PetscSection 468b778fa18SValeria Barra 469b778fa18SValeria Barra Not Collective 470b778fa18SValeria Barra 471b778fa18SValeria Barra Input Parameters: 472b778fa18SValeria Barra + s - the PetscSection 473b778fa18SValeria Barra . field - the field number 474b778fa18SValeria Barra . comp - the component number 475b778fa18SValeria Barra - compName - the component name 476b778fa18SValeria Barra 477b778fa18SValeria Barra Level: intermediate 478b778fa18SValeria Barra 479b778fa18SValeria Barra .seealso: PetscSectionGetComponentName() 480b778fa18SValeria Barra @*/ 481b778fa18SValeria Barra PetscErrorCode PetscSectionSetComponentName(PetscSection s, PetscInt field, PetscInt comp, const char compName[]) 482b778fa18SValeria Barra { 483b778fa18SValeria Barra PetscErrorCode ierr; 484b778fa18SValeria Barra 485b778fa18SValeria Barra PetscFunctionBegin; 486b778fa18SValeria Barra PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 487064a246eSJacob Faibussowitsch if (compName) PetscValidCharPointer(compName, 4); 4882abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field,s->numFields); 4892abc8c78SJacob Faibussowitsch PetscSectionCheckValidFieldComponent(comp,s->numFieldComponents[field]); 490b778fa18SValeria Barra ierr = PetscFree(s->compNames[field][comp]);CHKERRQ(ierr); 491b778fa18SValeria Barra ierr = PetscStrallocpy(compName, (char**) &s->compNames[field][comp]);CHKERRQ(ierr); 492b778fa18SValeria Barra PetscFunctionReturn(0); 493b778fa18SValeria Barra } 494b778fa18SValeria Barra 495ea844a1aSMatthew Knepley /*@ 496ea844a1aSMatthew Knepley PetscSectionGetFieldComponents - Returns the number of field components for the given field. 497ea844a1aSMatthew Knepley 498ea844a1aSMatthew Knepley Not collective 499ea844a1aSMatthew Knepley 500ea844a1aSMatthew Knepley Input Parameters: 501ea844a1aSMatthew Knepley + s - the PetscSection 502ea844a1aSMatthew Knepley - field - the field number 503ea844a1aSMatthew Knepley 504ea844a1aSMatthew Knepley Output Parameter: 505ea844a1aSMatthew Knepley . numComp - the number of field components 506ea844a1aSMatthew Knepley 507ea844a1aSMatthew Knepley Level: intermediate 508ea844a1aSMatthew Knepley 509ea844a1aSMatthew Knepley .seealso: PetscSectionSetFieldComponents(), PetscSectionGetNumFields() 510ea844a1aSMatthew Knepley @*/ 511ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetFieldComponents(PetscSection s, PetscInt field, PetscInt *numComp) 512ea844a1aSMatthew Knepley { 513ea844a1aSMatthew Knepley PetscFunctionBegin; 514ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 5152abc8c78SJacob Faibussowitsch PetscValidIntPointer(numComp, 3); 5162abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field,s->numFields); 517ea844a1aSMatthew Knepley *numComp = s->numFieldComponents[field]; 518ea844a1aSMatthew Knepley PetscFunctionReturn(0); 519ea844a1aSMatthew Knepley } 520ea844a1aSMatthew Knepley 521ea844a1aSMatthew Knepley /*@ 522ea844a1aSMatthew Knepley PetscSectionSetFieldComponents - Sets the number of field components for the given field. 523ea844a1aSMatthew Knepley 524ea844a1aSMatthew Knepley Not collective 525ea844a1aSMatthew Knepley 526ea844a1aSMatthew Knepley Input Parameters: 527ea844a1aSMatthew Knepley + s - the PetscSection 528ea844a1aSMatthew Knepley . field - the field number 529ea844a1aSMatthew Knepley - numComp - the number of field components 530ea844a1aSMatthew Knepley 531ea844a1aSMatthew Knepley Level: intermediate 532ea844a1aSMatthew Knepley 533245d9833Sprj- .seealso: PetscSectionGetFieldComponents(), PetscSectionGetNumFields() 534ea844a1aSMatthew Knepley @*/ 535ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetFieldComponents(PetscSection s, PetscInt field, PetscInt numComp) 536ea844a1aSMatthew Knepley { 537b778fa18SValeria Barra PetscErrorCode ierr; 538b778fa18SValeria Barra PetscInt c; 539b778fa18SValeria Barra 540ea844a1aSMatthew Knepley PetscFunctionBegin; 541ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 5422abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field,s->numFields); 543b778fa18SValeria Barra if (s->compNames) { 544b778fa18SValeria Barra for (c = 0; c < s->numFieldComponents[field]; ++c) { 545b778fa18SValeria Barra ierr = PetscFree(s->compNames[field][c]);CHKERRQ(ierr); 546b778fa18SValeria Barra } 547b778fa18SValeria Barra ierr = PetscFree(s->compNames[field]);CHKERRQ(ierr); 548b778fa18SValeria Barra } 549b778fa18SValeria Barra 550ea844a1aSMatthew Knepley s->numFieldComponents[field] = numComp; 551b778fa18SValeria Barra if (numComp) { 552b778fa18SValeria Barra ierr = PetscMalloc1(numComp, (char ***) &s->compNames[field]);CHKERRQ(ierr); 553b778fa18SValeria Barra for (c = 0; c < numComp; ++c) { 5542abc8c78SJacob Faibussowitsch char name[64]; 5552abc8c78SJacob Faibussowitsch 5562abc8c78SJacob Faibussowitsch ierr = PetscSNPrintf(name, 64, "%" PetscInt_FMT, c);CHKERRQ(ierr); 557b778fa18SValeria Barra ierr = PetscStrallocpy(name, (char **) &s->compNames[field][c]);CHKERRQ(ierr); 558b778fa18SValeria Barra } 559b778fa18SValeria Barra } 560ea844a1aSMatthew Knepley PetscFunctionReturn(0); 561ea844a1aSMatthew Knepley } 562ea844a1aSMatthew Knepley 563ea844a1aSMatthew Knepley static PetscErrorCode PetscSectionCheckConstraints_Static(PetscSection s) 564ea844a1aSMatthew Knepley { 565ea844a1aSMatthew Knepley PetscErrorCode ierr; 566ea844a1aSMatthew Knepley 567ea844a1aSMatthew Knepley PetscFunctionBegin; 568ea844a1aSMatthew Knepley if (!s->bc) { 569ea844a1aSMatthew Knepley ierr = PetscSectionCreate(PETSC_COMM_SELF, &s->bc);CHKERRQ(ierr); 570ea844a1aSMatthew Knepley ierr = PetscSectionSetChart(s->bc, s->pStart, s->pEnd);CHKERRQ(ierr); 571ea844a1aSMatthew Knepley } 572ea844a1aSMatthew Knepley PetscFunctionReturn(0); 573ea844a1aSMatthew Knepley } 574ea844a1aSMatthew Knepley 575ea844a1aSMatthew Knepley /*@ 576ea844a1aSMatthew Knepley PetscSectionGetChart - Returns the range [pStart, pEnd) in which points lie. 577ea844a1aSMatthew Knepley 578ea844a1aSMatthew Knepley Not collective 579ea844a1aSMatthew Knepley 580ea844a1aSMatthew Knepley Input Parameter: 581ea844a1aSMatthew Knepley . s - the PetscSection 582ea844a1aSMatthew Knepley 583ea844a1aSMatthew Knepley Output Parameters: 584ea844a1aSMatthew Knepley + pStart - the first point 585ea844a1aSMatthew Knepley - pEnd - one past the last point 586ea844a1aSMatthew Knepley 587ea844a1aSMatthew Knepley Level: intermediate 588ea844a1aSMatthew Knepley 589ea844a1aSMatthew Knepley .seealso: PetscSectionSetChart(), PetscSectionCreate() 590ea844a1aSMatthew Knepley @*/ 591ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetChart(PetscSection s, PetscInt *pStart, PetscInt *pEnd) 592ea844a1aSMatthew Knepley { 593ea844a1aSMatthew Knepley PetscFunctionBegin; 594ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 595ea844a1aSMatthew Knepley if (pStart) *pStart = s->pStart; 596ea844a1aSMatthew Knepley if (pEnd) *pEnd = s->pEnd; 597ea844a1aSMatthew Knepley PetscFunctionReturn(0); 598ea844a1aSMatthew Knepley } 599ea844a1aSMatthew Knepley 600ea844a1aSMatthew Knepley /*@ 601ea844a1aSMatthew Knepley PetscSectionSetChart - Sets the range [pStart, pEnd) in which points lie. 602ea844a1aSMatthew Knepley 603ea844a1aSMatthew Knepley Not collective 604ea844a1aSMatthew Knepley 605ea844a1aSMatthew Knepley Input Parameters: 606ea844a1aSMatthew Knepley + s - the PetscSection 607ea844a1aSMatthew Knepley . pStart - the first point 608ea844a1aSMatthew Knepley - pEnd - one past the last point 609ea844a1aSMatthew Knepley 610ea844a1aSMatthew Knepley Level: intermediate 611ea844a1aSMatthew Knepley 612ea844a1aSMatthew Knepley .seealso: PetscSectionGetChart(), PetscSectionCreate() 613ea844a1aSMatthew Knepley @*/ 614ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetChart(PetscSection s, PetscInt pStart, PetscInt pEnd) 615ea844a1aSMatthew Knepley { 616ea844a1aSMatthew Knepley PetscInt f; 617ea844a1aSMatthew Knepley PetscErrorCode ierr; 618ea844a1aSMatthew Knepley 619ea844a1aSMatthew Knepley PetscFunctionBegin; 620ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 6219318fe57SMatthew G. Knepley if (pStart == s->pStart && pEnd == s->pEnd) PetscFunctionReturn(0); 622ea844a1aSMatthew Knepley /* Cannot Reset() because it destroys field information */ 623ea844a1aSMatthew Knepley s->setup = PETSC_FALSE; 624ea844a1aSMatthew Knepley ierr = PetscSectionDestroy(&s->bc);CHKERRQ(ierr); 625ea844a1aSMatthew Knepley ierr = PetscFree(s->bcIndices);CHKERRQ(ierr); 626ea844a1aSMatthew Knepley ierr = PetscFree2(s->atlasDof, s->atlasOff);CHKERRQ(ierr); 627ea844a1aSMatthew Knepley 628ea844a1aSMatthew Knepley s->pStart = pStart; 629ea844a1aSMatthew Knepley s->pEnd = pEnd; 630ea844a1aSMatthew Knepley ierr = PetscMalloc2((pEnd - pStart), &s->atlasDof, (pEnd - pStart), &s->atlasOff);CHKERRQ(ierr); 631ea844a1aSMatthew Knepley ierr = PetscArrayzero(s->atlasDof, pEnd - pStart);CHKERRQ(ierr); 632ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) { 633ea844a1aSMatthew Knepley ierr = PetscSectionSetChart(s->field[f], pStart, pEnd);CHKERRQ(ierr); 634ea844a1aSMatthew Knepley } 635ea844a1aSMatthew Knepley PetscFunctionReturn(0); 636ea844a1aSMatthew Knepley } 637ea844a1aSMatthew Knepley 638ea844a1aSMatthew Knepley /*@ 639ea844a1aSMatthew Knepley PetscSectionGetPermutation - Returns the permutation of [0, pEnd-pStart) or NULL 640ea844a1aSMatthew Knepley 641ea844a1aSMatthew Knepley Not collective 642ea844a1aSMatthew Knepley 643ea844a1aSMatthew Knepley Input Parameter: 644ea844a1aSMatthew Knepley . s - the PetscSection 645ea844a1aSMatthew Knepley 646ea844a1aSMatthew Knepley Output Parameters: 647ea844a1aSMatthew Knepley . perm - The permutation as an IS 648ea844a1aSMatthew Knepley 649ea844a1aSMatthew Knepley Level: intermediate 650ea844a1aSMatthew Knepley 651ea844a1aSMatthew Knepley .seealso: PetscSectionSetPermutation(), PetscSectionCreate() 652ea844a1aSMatthew Knepley @*/ 653ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetPermutation(PetscSection s, IS *perm) 654ea844a1aSMatthew Knepley { 655ea844a1aSMatthew Knepley PetscFunctionBegin; 656ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 657ea844a1aSMatthew Knepley if (perm) {PetscValidPointer(perm, 2); *perm = s->perm;} 658ea844a1aSMatthew Knepley PetscFunctionReturn(0); 659ea844a1aSMatthew Knepley } 660ea844a1aSMatthew Knepley 661ea844a1aSMatthew Knepley /*@ 662ea844a1aSMatthew Knepley PetscSectionSetPermutation - Sets the permutation for [0, pEnd-pStart) 663ea844a1aSMatthew Knepley 664ea844a1aSMatthew Knepley Not collective 665ea844a1aSMatthew Knepley 666ea844a1aSMatthew Knepley Input Parameters: 667ea844a1aSMatthew Knepley + s - the PetscSection 668ea844a1aSMatthew Knepley - perm - the permutation of points 669ea844a1aSMatthew Knepley 670ea844a1aSMatthew Knepley Level: intermediate 671ea844a1aSMatthew Knepley 672ea844a1aSMatthew Knepley .seealso: PetscSectionGetPermutation(), PetscSectionCreate() 673ea844a1aSMatthew Knepley @*/ 674ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetPermutation(PetscSection s, IS perm) 675ea844a1aSMatthew Knepley { 676ea844a1aSMatthew Knepley PetscErrorCode ierr; 677ea844a1aSMatthew Knepley 678ea844a1aSMatthew Knepley PetscFunctionBegin; 679ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 680ea844a1aSMatthew Knepley if (perm) PetscValidHeaderSpecific(perm, IS_CLASSID, 2); 6812c71b3e2SJacob Faibussowitsch PetscCheckFalse(s->setup,PetscObjectComm((PetscObject) s), PETSC_ERR_ARG_WRONGSTATE, "Cannot set a permutation after the section is setup"); 682ea844a1aSMatthew Knepley if (s->perm != perm) { 683ea844a1aSMatthew Knepley ierr = ISDestroy(&s->perm);CHKERRQ(ierr); 684ea844a1aSMatthew Knepley if (perm) { 685ea844a1aSMatthew Knepley s->perm = perm; 686ea844a1aSMatthew Knepley ierr = PetscObjectReference((PetscObject) s->perm);CHKERRQ(ierr); 687ea844a1aSMatthew Knepley } 688ea844a1aSMatthew Knepley } 689ea844a1aSMatthew Knepley PetscFunctionReturn(0); 690ea844a1aSMatthew Knepley } 691ea844a1aSMatthew Knepley 692ea844a1aSMatthew Knepley /*@ 693ea844a1aSMatthew Knepley PetscSectionGetPointMajor - Returns the flag for dof ordering, true if it is point major, otherwise field major 694ea844a1aSMatthew Knepley 695ea844a1aSMatthew Knepley Not collective 696ea844a1aSMatthew Knepley 697ea844a1aSMatthew Knepley Input Parameter: 698ea844a1aSMatthew Knepley . s - the PetscSection 699ea844a1aSMatthew Knepley 700ea844a1aSMatthew Knepley Output Parameter: 701ea844a1aSMatthew Knepley . pm - the flag for point major ordering 702ea844a1aSMatthew Knepley 703ea844a1aSMatthew Knepley Level: intermediate 704ea844a1aSMatthew Knepley 705ea844a1aSMatthew Knepley .seealso: PetscSectionSetPointMajor() 706ea844a1aSMatthew Knepley @*/ 707ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetPointMajor(PetscSection s, PetscBool *pm) 708ea844a1aSMatthew Knepley { 709ea844a1aSMatthew Knepley PetscFunctionBegin; 710ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 711ea844a1aSMatthew Knepley PetscValidPointer(pm,2); 712ea844a1aSMatthew Knepley *pm = s->pointMajor; 713ea844a1aSMatthew Knepley PetscFunctionReturn(0); 714ea844a1aSMatthew Knepley } 715ea844a1aSMatthew Knepley 716ea844a1aSMatthew Knepley /*@ 717ea844a1aSMatthew Knepley PetscSectionSetPointMajor - Sets the flag for dof ordering, true if it is point major, otherwise field major 718ea844a1aSMatthew Knepley 719ea844a1aSMatthew Knepley Not collective 720ea844a1aSMatthew Knepley 721ea844a1aSMatthew Knepley Input Parameters: 722ea844a1aSMatthew Knepley + s - the PetscSection 723ea844a1aSMatthew Knepley - pm - the flag for point major ordering 724ea844a1aSMatthew Knepley 725ea844a1aSMatthew Knepley Not collective 726ea844a1aSMatthew Knepley 727ea844a1aSMatthew Knepley Level: intermediate 728ea844a1aSMatthew Knepley 729ea844a1aSMatthew Knepley .seealso: PetscSectionGetPointMajor() 730ea844a1aSMatthew Knepley @*/ 731ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetPointMajor(PetscSection s, PetscBool pm) 732ea844a1aSMatthew Knepley { 733ea844a1aSMatthew Knepley PetscFunctionBegin; 734ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 7352c71b3e2SJacob Faibussowitsch PetscCheckFalse(s->setup,PetscObjectComm((PetscObject) s), PETSC_ERR_ARG_WRONGSTATE, "Cannot set the dof ordering after the section is setup"); 736ea844a1aSMatthew Knepley s->pointMajor = pm; 737ea844a1aSMatthew Knepley PetscFunctionReturn(0); 738ea844a1aSMatthew Knepley } 739ea844a1aSMatthew Knepley 740ea844a1aSMatthew Knepley /*@ 74187e637c6Sksagiyam PetscSectionGetIncludesConstraints - Returns the flag indicating if constrained dofs were included when computing offsets 74287e637c6Sksagiyam 74387e637c6Sksagiyam Not collective 74487e637c6Sksagiyam 74587e637c6Sksagiyam Input Parameter: 74687e637c6Sksagiyam . s - the PetscSection 74787e637c6Sksagiyam 74887e637c6Sksagiyam Output Parameter: 74987e637c6Sksagiyam . includesConstraints - the flag indicating if constrained dofs were included when computing offsets 75087e637c6Sksagiyam 75187e637c6Sksagiyam Level: intermediate 75287e637c6Sksagiyam 75387e637c6Sksagiyam .seealso: PetscSectionSetIncludesConstraints() 75487e637c6Sksagiyam @*/ 75587e637c6Sksagiyam PetscErrorCode PetscSectionGetIncludesConstraints(PetscSection s, PetscBool *includesConstraints) 75687e637c6Sksagiyam { 75787e637c6Sksagiyam PetscFunctionBegin; 75887e637c6Sksagiyam PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 75987e637c6Sksagiyam PetscValidBoolPointer(includesConstraints,2); 76087e637c6Sksagiyam *includesConstraints = s->includesConstraints; 76187e637c6Sksagiyam PetscFunctionReturn(0); 76287e637c6Sksagiyam } 76387e637c6Sksagiyam 76487e637c6Sksagiyam /*@ 76587e637c6Sksagiyam PetscSectionSetIncludesConstraints - Sets the flag indicating if constrained dofs are to be included when computing offsets 76687e637c6Sksagiyam 76787e637c6Sksagiyam Not collective 76887e637c6Sksagiyam 76987e637c6Sksagiyam Input Parameters: 77087e637c6Sksagiyam + s - the PetscSection 77187e637c6Sksagiyam - includesConstraints - the flag indicating if constrained dofs are to be included when computing offsets 77287e637c6Sksagiyam 77387e637c6Sksagiyam Not collective 77487e637c6Sksagiyam 77587e637c6Sksagiyam Level: intermediate 77687e637c6Sksagiyam 77787e637c6Sksagiyam .seealso: PetscSectionGetIncludesConstraints() 77887e637c6Sksagiyam @*/ 77987e637c6Sksagiyam PetscErrorCode PetscSectionSetIncludesConstraints(PetscSection s, PetscBool includesConstraints) 78087e637c6Sksagiyam { 78187e637c6Sksagiyam PetscFunctionBegin; 78287e637c6Sksagiyam PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 7832c71b3e2SJacob Faibussowitsch PetscCheckFalse(s->setup,PetscObjectComm((PetscObject) s), PETSC_ERR_ARG_WRONGSTATE, "Cannot set includesConstraints after the section is set up"); 78487e637c6Sksagiyam s->includesConstraints = includesConstraints; 78587e637c6Sksagiyam PetscFunctionReturn(0); 78687e637c6Sksagiyam } 78787e637c6Sksagiyam 78887e637c6Sksagiyam /*@ 789ea844a1aSMatthew Knepley PetscSectionGetDof - Return the number of degrees of freedom associated with a given point. 790ea844a1aSMatthew Knepley 791ea844a1aSMatthew Knepley Not collective 792ea844a1aSMatthew Knepley 793ea844a1aSMatthew Knepley Input Parameters: 794ea844a1aSMatthew Knepley + s - the PetscSection 795ea844a1aSMatthew Knepley - point - the point 796ea844a1aSMatthew Knepley 797ea844a1aSMatthew Knepley Output Parameter: 798ea844a1aSMatthew Knepley . numDof - the number of dof 799ea844a1aSMatthew Knepley 800ea844a1aSMatthew Knepley Level: intermediate 801ea844a1aSMatthew Knepley 802ea844a1aSMatthew Knepley .seealso: PetscSectionSetDof(), PetscSectionCreate() 803ea844a1aSMatthew Knepley @*/ 804ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetDof(PetscSection s, PetscInt point, PetscInt *numDof) 805ea844a1aSMatthew Knepley { 80676bd3646SJed Brown PetscFunctionBeginHot; 807ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 808ea844a1aSMatthew Knepley PetscValidPointer(numDof, 3); 80976bd3646SJed Brown if (PetscDefined(USE_DEBUG)) { 8102c71b3e2SJacob Faibussowitsch PetscCheckFalse((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); 81176bd3646SJed Brown } 812ea844a1aSMatthew Knepley *numDof = s->atlasDof[point - s->pStart]; 813ea844a1aSMatthew Knepley PetscFunctionReturn(0); 814ea844a1aSMatthew Knepley } 815ea844a1aSMatthew Knepley 816ea844a1aSMatthew Knepley /*@ 817ea844a1aSMatthew Knepley PetscSectionSetDof - Sets the number of degrees of freedom associated with a given point. 818ea844a1aSMatthew Knepley 819ea844a1aSMatthew Knepley Not collective 820ea844a1aSMatthew Knepley 821ea844a1aSMatthew Knepley Input Parameters: 822ea844a1aSMatthew Knepley + s - the PetscSection 823ea844a1aSMatthew Knepley . point - the point 824ea844a1aSMatthew Knepley - numDof - the number of dof 825ea844a1aSMatthew Knepley 826ea844a1aSMatthew Knepley Level: intermediate 827ea844a1aSMatthew Knepley 828ea844a1aSMatthew Knepley .seealso: PetscSectionGetDof(), PetscSectionAddDof(), PetscSectionCreate() 829ea844a1aSMatthew Knepley @*/ 830ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetDof(PetscSection s, PetscInt point, PetscInt numDof) 831ea844a1aSMatthew Knepley { 832ea844a1aSMatthew Knepley PetscFunctionBegin; 833ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 8342c71b3e2SJacob Faibussowitsch PetscCheckFalse((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); 835ea844a1aSMatthew Knepley s->atlasDof[point - s->pStart] = numDof; 836ea844a1aSMatthew Knepley PetscFunctionReturn(0); 837ea844a1aSMatthew Knepley } 838ea844a1aSMatthew Knepley 839ea844a1aSMatthew Knepley /*@ 840ea844a1aSMatthew Knepley PetscSectionAddDof - Adds to the number of degrees of freedom associated with a given point. 841ea844a1aSMatthew Knepley 842ea844a1aSMatthew Knepley Not collective 843ea844a1aSMatthew Knepley 844ea844a1aSMatthew Knepley Input Parameters: 845ea844a1aSMatthew Knepley + s - the PetscSection 846ea844a1aSMatthew Knepley . point - the point 847ea844a1aSMatthew Knepley - numDof - the number of additional dof 848ea844a1aSMatthew Knepley 849ea844a1aSMatthew Knepley Level: intermediate 850ea844a1aSMatthew Knepley 851ea844a1aSMatthew Knepley .seealso: PetscSectionGetDof(), PetscSectionSetDof(), PetscSectionCreate() 852ea844a1aSMatthew Knepley @*/ 853ea844a1aSMatthew Knepley PetscErrorCode PetscSectionAddDof(PetscSection s, PetscInt point, PetscInt numDof) 854ea844a1aSMatthew Knepley { 85576bd3646SJed Brown PetscFunctionBeginHot; 856ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 85776bd3646SJed Brown if (PetscDefined(USE_DEBUG)) { 8582c71b3e2SJacob Faibussowitsch PetscCheckFalse((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); 85976bd3646SJed Brown } 860ea844a1aSMatthew Knepley s->atlasDof[point - s->pStart] += numDof; 861ea844a1aSMatthew Knepley PetscFunctionReturn(0); 862ea844a1aSMatthew Knepley } 863ea844a1aSMatthew Knepley 864ea844a1aSMatthew Knepley /*@ 865ea844a1aSMatthew Knepley PetscSectionGetFieldDof - Return the number of degrees of freedom associated with a field on a given point. 866ea844a1aSMatthew Knepley 867ea844a1aSMatthew Knepley Not collective 868ea844a1aSMatthew Knepley 869ea844a1aSMatthew Knepley Input Parameters: 870ea844a1aSMatthew Knepley + s - the PetscSection 871ea844a1aSMatthew Knepley . point - the point 872ea844a1aSMatthew Knepley - field - the field 873ea844a1aSMatthew Knepley 874ea844a1aSMatthew Knepley Output Parameter: 875ea844a1aSMatthew Knepley . numDof - the number of dof 876ea844a1aSMatthew Knepley 877ea844a1aSMatthew Knepley Level: intermediate 878ea844a1aSMatthew Knepley 879ea844a1aSMatthew Knepley .seealso: PetscSectionSetFieldDof(), PetscSectionCreate() 880ea844a1aSMatthew Knepley @*/ 881ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetFieldDof(PetscSection s, PetscInt point, PetscInt field, PetscInt *numDof) 882ea844a1aSMatthew Knepley { 883ea844a1aSMatthew Knepley PetscErrorCode ierr; 884ea844a1aSMatthew Knepley 885ea844a1aSMatthew Knepley PetscFunctionBegin; 886ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 8872abc8c78SJacob Faibussowitsch PetscValidIntPointer(numDof,4); 8882abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field,s->numFields); 889ea844a1aSMatthew Knepley ierr = PetscSectionGetDof(s->field[field], point, numDof);CHKERRQ(ierr); 890ea844a1aSMatthew Knepley PetscFunctionReturn(0); 891ea844a1aSMatthew Knepley } 892ea844a1aSMatthew Knepley 893ea844a1aSMatthew Knepley /*@ 894ea844a1aSMatthew Knepley PetscSectionSetFieldDof - Sets the number of degrees of freedom associated with a field on a given point. 895ea844a1aSMatthew Knepley 896ea844a1aSMatthew Knepley Not collective 897ea844a1aSMatthew Knepley 898ea844a1aSMatthew Knepley Input Parameters: 899ea844a1aSMatthew Knepley + s - the PetscSection 900ea844a1aSMatthew Knepley . point - the point 901ea844a1aSMatthew Knepley . field - the field 902ea844a1aSMatthew Knepley - numDof - the number of dof 903ea844a1aSMatthew Knepley 904ea844a1aSMatthew Knepley Level: intermediate 905ea844a1aSMatthew Knepley 906ea844a1aSMatthew Knepley .seealso: PetscSectionGetFieldDof(), PetscSectionCreate() 907ea844a1aSMatthew Knepley @*/ 908ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetFieldDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof) 909ea844a1aSMatthew Knepley { 910ea844a1aSMatthew Knepley PetscErrorCode ierr; 911ea844a1aSMatthew Knepley 912ea844a1aSMatthew Knepley PetscFunctionBegin; 913ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 9142abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field,s->numFields); 915ea844a1aSMatthew Knepley ierr = PetscSectionSetDof(s->field[field], point, numDof);CHKERRQ(ierr); 916ea844a1aSMatthew Knepley PetscFunctionReturn(0); 917ea844a1aSMatthew Knepley } 918ea844a1aSMatthew Knepley 919ea844a1aSMatthew Knepley /*@ 920ea844a1aSMatthew Knepley PetscSectionAddFieldDof - Adds a number of degrees of freedom associated with a field on a given point. 921ea844a1aSMatthew Knepley 922ea844a1aSMatthew Knepley Not collective 923ea844a1aSMatthew Knepley 924ea844a1aSMatthew Knepley Input Parameters: 925ea844a1aSMatthew Knepley + s - the PetscSection 926ea844a1aSMatthew Knepley . point - the point 927ea844a1aSMatthew Knepley . field - the field 928ea844a1aSMatthew Knepley - numDof - the number of dof 929ea844a1aSMatthew Knepley 930ea844a1aSMatthew Knepley Level: intermediate 931ea844a1aSMatthew Knepley 932ea844a1aSMatthew Knepley .seealso: PetscSectionSetFieldDof(), PetscSectionGetFieldDof(), PetscSectionCreate() 933ea844a1aSMatthew Knepley @*/ 934ea844a1aSMatthew Knepley PetscErrorCode PetscSectionAddFieldDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof) 935ea844a1aSMatthew Knepley { 936ea844a1aSMatthew Knepley PetscErrorCode ierr; 937ea844a1aSMatthew Knepley 938ea844a1aSMatthew Knepley PetscFunctionBegin; 939ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 9402abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field,s->numFields); 941ea844a1aSMatthew Knepley ierr = PetscSectionAddDof(s->field[field], point, numDof);CHKERRQ(ierr); 942ea844a1aSMatthew Knepley PetscFunctionReturn(0); 943ea844a1aSMatthew Knepley } 944ea844a1aSMatthew Knepley 945ea844a1aSMatthew Knepley /*@ 946ea844a1aSMatthew Knepley PetscSectionGetConstraintDof - Return the number of constrained degrees of freedom associated with a given point. 947ea844a1aSMatthew Knepley 948ea844a1aSMatthew Knepley Not collective 949ea844a1aSMatthew Knepley 950ea844a1aSMatthew Knepley Input Parameters: 951ea844a1aSMatthew Knepley + s - the PetscSection 952ea844a1aSMatthew Knepley - point - the point 953ea844a1aSMatthew Knepley 954ea844a1aSMatthew Knepley Output Parameter: 955ea844a1aSMatthew Knepley . numDof - the number of dof which are fixed by constraints 956ea844a1aSMatthew Knepley 957ea844a1aSMatthew Knepley Level: intermediate 958ea844a1aSMatthew Knepley 959ea844a1aSMatthew Knepley .seealso: PetscSectionGetDof(), PetscSectionSetConstraintDof(), PetscSectionCreate() 960ea844a1aSMatthew Knepley @*/ 961ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetConstraintDof(PetscSection s, PetscInt point, PetscInt *numDof) 962ea844a1aSMatthew Knepley { 963ea844a1aSMatthew Knepley PetscErrorCode ierr; 964ea844a1aSMatthew Knepley 965ea844a1aSMatthew Knepley PetscFunctionBegin; 966ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 967ea844a1aSMatthew Knepley PetscValidPointer(numDof, 3); 968ea844a1aSMatthew Knepley if (s->bc) { 969ea844a1aSMatthew Knepley ierr = PetscSectionGetDof(s->bc, point, numDof);CHKERRQ(ierr); 970ea844a1aSMatthew Knepley } else *numDof = 0; 971ea844a1aSMatthew Knepley PetscFunctionReturn(0); 972ea844a1aSMatthew Knepley } 973ea844a1aSMatthew Knepley 974ea844a1aSMatthew Knepley /*@ 975ea844a1aSMatthew Knepley PetscSectionSetConstraintDof - Set the number of constrained degrees of freedom associated with a given point. 976ea844a1aSMatthew Knepley 977ea844a1aSMatthew Knepley Not collective 978ea844a1aSMatthew Knepley 979ea844a1aSMatthew Knepley Input Parameters: 980ea844a1aSMatthew Knepley + s - the PetscSection 981ea844a1aSMatthew Knepley . point - the point 982ea844a1aSMatthew Knepley - numDof - the number of dof which are fixed by constraints 983ea844a1aSMatthew Knepley 984ea844a1aSMatthew Knepley Level: intermediate 985ea844a1aSMatthew Knepley 986ea844a1aSMatthew Knepley .seealso: PetscSectionSetDof(), PetscSectionGetConstraintDof(), PetscSectionCreate() 987ea844a1aSMatthew Knepley @*/ 988ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetConstraintDof(PetscSection s, PetscInt point, PetscInt numDof) 989ea844a1aSMatthew Knepley { 990ea844a1aSMatthew Knepley PetscErrorCode ierr; 991ea844a1aSMatthew Knepley 992ea844a1aSMatthew Knepley PetscFunctionBegin; 993ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 994ea844a1aSMatthew Knepley if (numDof) { 995ea844a1aSMatthew Knepley ierr = PetscSectionCheckConstraints_Static(s);CHKERRQ(ierr); 996ea844a1aSMatthew Knepley ierr = PetscSectionSetDof(s->bc, point, numDof);CHKERRQ(ierr); 997ea844a1aSMatthew Knepley } 998ea844a1aSMatthew Knepley PetscFunctionReturn(0); 999ea844a1aSMatthew Knepley } 1000ea844a1aSMatthew Knepley 1001ea844a1aSMatthew Knepley /*@ 1002ea844a1aSMatthew Knepley PetscSectionAddConstraintDof - Increment the number of constrained degrees of freedom associated with a given point. 1003ea844a1aSMatthew Knepley 1004ea844a1aSMatthew Knepley Not collective 1005ea844a1aSMatthew Knepley 1006ea844a1aSMatthew Knepley Input Parameters: 1007ea844a1aSMatthew Knepley + s - the PetscSection 1008ea844a1aSMatthew Knepley . point - the point 1009ea844a1aSMatthew Knepley - numDof - the number of additional dof which are fixed by constraints 1010ea844a1aSMatthew Knepley 1011ea844a1aSMatthew Knepley Level: intermediate 1012ea844a1aSMatthew Knepley 1013ea844a1aSMatthew Knepley .seealso: PetscSectionAddDof(), PetscSectionGetConstraintDof(), PetscSectionCreate() 1014ea844a1aSMatthew Knepley @*/ 1015ea844a1aSMatthew Knepley PetscErrorCode PetscSectionAddConstraintDof(PetscSection s, PetscInt point, PetscInt numDof) 1016ea844a1aSMatthew Knepley { 1017ea844a1aSMatthew Knepley PetscErrorCode ierr; 1018ea844a1aSMatthew Knepley 1019ea844a1aSMatthew Knepley PetscFunctionBegin; 1020ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1021ea844a1aSMatthew Knepley if (numDof) { 1022ea844a1aSMatthew Knepley ierr = PetscSectionCheckConstraints_Static(s);CHKERRQ(ierr); 1023ea844a1aSMatthew Knepley ierr = PetscSectionAddDof(s->bc, point, numDof);CHKERRQ(ierr); 1024ea844a1aSMatthew Knepley } 1025ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1026ea844a1aSMatthew Knepley } 1027ea844a1aSMatthew Knepley 1028ea844a1aSMatthew Knepley /*@ 1029ea844a1aSMatthew Knepley PetscSectionGetFieldConstraintDof - Return the number of constrained degrees of freedom associated with a given field on a point. 1030ea844a1aSMatthew Knepley 1031ea844a1aSMatthew Knepley Not collective 1032ea844a1aSMatthew Knepley 1033ea844a1aSMatthew Knepley Input Parameters: 1034ea844a1aSMatthew Knepley + s - the PetscSection 1035ea844a1aSMatthew Knepley . point - the point 1036ea844a1aSMatthew Knepley - field - the field 1037ea844a1aSMatthew Knepley 1038ea844a1aSMatthew Knepley Output Parameter: 1039ea844a1aSMatthew Knepley . numDof - the number of dof which are fixed by constraints 1040ea844a1aSMatthew Knepley 1041ea844a1aSMatthew Knepley Level: intermediate 1042ea844a1aSMatthew Knepley 1043ea844a1aSMatthew Knepley .seealso: PetscSectionGetDof(), PetscSectionSetFieldConstraintDof(), PetscSectionCreate() 1044ea844a1aSMatthew Knepley @*/ 1045ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetFieldConstraintDof(PetscSection s, PetscInt point, PetscInt field, PetscInt *numDof) 1046ea844a1aSMatthew Knepley { 1047ea844a1aSMatthew Knepley PetscErrorCode ierr; 1048ea844a1aSMatthew Knepley 1049ea844a1aSMatthew Knepley PetscFunctionBegin; 1050ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 10512abc8c78SJacob Faibussowitsch PetscValidIntPointer(numDof, 4); 10522abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field,s->numFields); 1053ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintDof(s->field[field], point, numDof);CHKERRQ(ierr); 1054ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1055ea844a1aSMatthew Knepley } 1056ea844a1aSMatthew Knepley 1057ea844a1aSMatthew Knepley /*@ 1058ea844a1aSMatthew Knepley PetscSectionSetFieldConstraintDof - Set the number of constrained degrees of freedom associated with a given field on a point. 1059ea844a1aSMatthew Knepley 1060ea844a1aSMatthew Knepley Not collective 1061ea844a1aSMatthew Knepley 1062ea844a1aSMatthew Knepley Input Parameters: 1063ea844a1aSMatthew Knepley + s - the PetscSection 1064ea844a1aSMatthew Knepley . point - the point 1065ea844a1aSMatthew Knepley . field - the field 1066ea844a1aSMatthew Knepley - numDof - the number of dof which are fixed by constraints 1067ea844a1aSMatthew Knepley 1068ea844a1aSMatthew Knepley Level: intermediate 1069ea844a1aSMatthew Knepley 1070ea844a1aSMatthew Knepley .seealso: PetscSectionSetDof(), PetscSectionGetFieldConstraintDof(), PetscSectionCreate() 1071ea844a1aSMatthew Knepley @*/ 1072ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetFieldConstraintDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof) 1073ea844a1aSMatthew Knepley { 1074ea844a1aSMatthew Knepley PetscErrorCode ierr; 1075ea844a1aSMatthew Knepley 1076ea844a1aSMatthew Knepley PetscFunctionBegin; 1077ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 10782abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field,s->numFields); 1079ea844a1aSMatthew Knepley ierr = PetscSectionSetConstraintDof(s->field[field], point, numDof);CHKERRQ(ierr); 1080ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1081ea844a1aSMatthew Knepley } 1082ea844a1aSMatthew Knepley 1083ea844a1aSMatthew Knepley /*@ 1084ea844a1aSMatthew Knepley PetscSectionAddFieldConstraintDof - Increment the number of constrained degrees of freedom associated with a given field on a point. 1085ea844a1aSMatthew Knepley 1086ea844a1aSMatthew Knepley Not collective 1087ea844a1aSMatthew Knepley 1088ea844a1aSMatthew Knepley Input Parameters: 1089ea844a1aSMatthew Knepley + s - the PetscSection 1090ea844a1aSMatthew Knepley . point - the point 1091ea844a1aSMatthew Knepley . field - the field 1092ea844a1aSMatthew Knepley - numDof - the number of additional dof which are fixed by constraints 1093ea844a1aSMatthew Knepley 1094ea844a1aSMatthew Knepley Level: intermediate 1095ea844a1aSMatthew Knepley 1096ea844a1aSMatthew Knepley .seealso: PetscSectionAddDof(), PetscSectionGetFieldConstraintDof(), PetscSectionCreate() 1097ea844a1aSMatthew Knepley @*/ 1098ea844a1aSMatthew Knepley PetscErrorCode PetscSectionAddFieldConstraintDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof) 1099ea844a1aSMatthew Knepley { 1100ea844a1aSMatthew Knepley PetscErrorCode ierr; 1101ea844a1aSMatthew Knepley 1102ea844a1aSMatthew Knepley PetscFunctionBegin; 1103ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 11042abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field,s->numFields); 1105ea844a1aSMatthew Knepley ierr = PetscSectionAddConstraintDof(s->field[field], point, numDof);CHKERRQ(ierr); 1106ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1107ea844a1aSMatthew Knepley } 1108ea844a1aSMatthew Knepley 1109ea844a1aSMatthew Knepley /*@ 1110ea844a1aSMatthew Knepley PetscSectionSetUpBC - Setup the subsections describing boundary conditions. 1111ea844a1aSMatthew Knepley 1112ea844a1aSMatthew Knepley Not collective 1113ea844a1aSMatthew Knepley 1114ea844a1aSMatthew Knepley Input Parameter: 1115ea844a1aSMatthew Knepley . s - the PetscSection 1116ea844a1aSMatthew Knepley 1117ea844a1aSMatthew Knepley Level: advanced 1118ea844a1aSMatthew Knepley 1119ea844a1aSMatthew Knepley .seealso: PetscSectionSetUp(), PetscSectionCreate() 1120ea844a1aSMatthew Knepley @*/ 1121ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetUpBC(PetscSection s) 1122ea844a1aSMatthew Knepley { 1123ea844a1aSMatthew Knepley PetscErrorCode ierr; 1124ea844a1aSMatthew Knepley 1125ea844a1aSMatthew Knepley PetscFunctionBegin; 1126ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1127ea844a1aSMatthew Knepley if (s->bc) { 1128ea844a1aSMatthew Knepley const PetscInt last = (s->bc->pEnd-s->bc->pStart) - 1; 1129ea844a1aSMatthew Knepley 1130ea844a1aSMatthew Knepley ierr = PetscSectionSetUp(s->bc);CHKERRQ(ierr); 113128d58a37SPierre Jolivet ierr = PetscMalloc1(last >= 0 ? s->bc->atlasOff[last] + s->bc->atlasDof[last] : 0, &s->bcIndices);CHKERRQ(ierr); 1132ea844a1aSMatthew Knepley } 1133ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1134ea844a1aSMatthew Knepley } 1135ea844a1aSMatthew Knepley 1136ea844a1aSMatthew Knepley /*@ 1137ea844a1aSMatthew Knepley PetscSectionSetUp - Calculate offsets based upon the number of degrees of freedom for each point. 1138ea844a1aSMatthew Knepley 1139ea844a1aSMatthew Knepley Not collective 1140ea844a1aSMatthew Knepley 1141ea844a1aSMatthew Knepley Input Parameter: 1142ea844a1aSMatthew Knepley . s - the PetscSection 1143ea844a1aSMatthew Knepley 1144ea844a1aSMatthew Knepley Level: intermediate 1145ea844a1aSMatthew Knepley 1146ea844a1aSMatthew Knepley .seealso: PetscSectionCreate() 1147ea844a1aSMatthew Knepley @*/ 1148ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetUp(PetscSection s) 1149ea844a1aSMatthew Knepley { 1150ea844a1aSMatthew Knepley const PetscInt *pind = NULL; 1151ea844a1aSMatthew Knepley PetscInt offset = 0, foff, p, f; 1152ea844a1aSMatthew Knepley PetscErrorCode ierr; 1153ea844a1aSMatthew Knepley 1154ea844a1aSMatthew Knepley PetscFunctionBegin; 1155ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1156ea844a1aSMatthew Knepley if (s->setup) PetscFunctionReturn(0); 1157ea844a1aSMatthew Knepley s->setup = PETSC_TRUE; 1158ea844a1aSMatthew Knepley /* Set offsets and field offsets for all points */ 1159ea844a1aSMatthew Knepley /* Assume that all fields have the same chart */ 11602c71b3e2SJacob Faibussowitsch PetscCheckFalse(!s->includesConstraints,PETSC_COMM_SELF,PETSC_ERR_SUP,"PetscSectionSetUp is currently unsupported for includesConstraints = PETSC_TRUE"); 1161ea844a1aSMatthew Knepley if (s->perm) {ierr = ISGetIndices(s->perm, &pind);CHKERRQ(ierr);} 1162ea844a1aSMatthew Knepley if (s->pointMajor) { 1163ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) { 1164ea844a1aSMatthew Knepley const PetscInt q = pind ? pind[p] : p; 1165ea844a1aSMatthew Knepley 1166ea844a1aSMatthew Knepley /* Set point offset */ 1167ea844a1aSMatthew Knepley s->atlasOff[q] = offset; 1168ea844a1aSMatthew Knepley offset += s->atlasDof[q]; 1169ea844a1aSMatthew Knepley s->maxDof = PetscMax(s->maxDof, s->atlasDof[q]); 1170ea844a1aSMatthew Knepley /* Set field offset */ 1171ea844a1aSMatthew Knepley for (f = 0, foff = s->atlasOff[q]; f < s->numFields; ++f) { 1172ea844a1aSMatthew Knepley PetscSection sf = s->field[f]; 1173ea844a1aSMatthew Knepley 1174ea844a1aSMatthew Knepley sf->atlasOff[q] = foff; 1175ea844a1aSMatthew Knepley foff += sf->atlasDof[q]; 1176ea844a1aSMatthew Knepley } 1177ea844a1aSMatthew Knepley } 1178ea844a1aSMatthew Knepley } else { 1179ea844a1aSMatthew Knepley /* Set field offsets for all points */ 1180ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) { 1181ea844a1aSMatthew Knepley PetscSection sf = s->field[f]; 1182ea844a1aSMatthew Knepley 1183ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) { 1184ea844a1aSMatthew Knepley const PetscInt q = pind ? pind[p] : p; 1185ea844a1aSMatthew Knepley 1186ea844a1aSMatthew Knepley sf->atlasOff[q] = offset; 1187ea844a1aSMatthew Knepley offset += sf->atlasDof[q]; 1188ea844a1aSMatthew Knepley } 1189ea844a1aSMatthew Knepley } 1190ea844a1aSMatthew Knepley /* Disable point offsets since these are unused */ 1191ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) { 1192ea844a1aSMatthew Knepley s->atlasOff[p] = -1; 1193ea844a1aSMatthew Knepley s->maxDof = PetscMax(s->maxDof, s->atlasDof[p]); 1194ea844a1aSMatthew Knepley } 1195ea844a1aSMatthew Knepley } 1196ea844a1aSMatthew Knepley if (s->perm) {ierr = ISRestoreIndices(s->perm, &pind);CHKERRQ(ierr);} 1197ea844a1aSMatthew Knepley /* Setup BC sections */ 1198ea844a1aSMatthew Knepley ierr = PetscSectionSetUpBC(s);CHKERRQ(ierr); 1199ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) {ierr = PetscSectionSetUpBC(s->field[f]);CHKERRQ(ierr);} 1200ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1201ea844a1aSMatthew Knepley } 1202ea844a1aSMatthew Knepley 1203ea844a1aSMatthew Knepley /*@ 1204ea844a1aSMatthew Knepley PetscSectionGetMaxDof - Return the maximum number of degrees of freedom on any point in the chart 1205ea844a1aSMatthew Knepley 1206ea844a1aSMatthew Knepley Not collective 1207ea844a1aSMatthew Knepley 1208ea844a1aSMatthew Knepley Input Parameters: 1209ea844a1aSMatthew Knepley . s - the PetscSection 1210ea844a1aSMatthew Knepley 1211ea844a1aSMatthew Knepley Output Parameter: 1212ea844a1aSMatthew Knepley . maxDof - the maximum dof 1213ea844a1aSMatthew Knepley 1214ea844a1aSMatthew Knepley Level: intermediate 1215ea844a1aSMatthew Knepley 1216ea844a1aSMatthew Knepley .seealso: PetscSectionGetDof(), PetscSectionSetDof(), PetscSectionCreate() 1217ea844a1aSMatthew Knepley @*/ 1218ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetMaxDof(PetscSection s, PetscInt *maxDof) 1219ea844a1aSMatthew Knepley { 1220ea844a1aSMatthew Knepley PetscFunctionBegin; 1221ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1222ea844a1aSMatthew Knepley PetscValidPointer(maxDof, 2); 1223ea844a1aSMatthew Knepley *maxDof = s->maxDof; 1224ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1225ea844a1aSMatthew Knepley } 1226ea844a1aSMatthew Knepley 1227ea844a1aSMatthew Knepley /*@ 1228ea844a1aSMatthew Knepley PetscSectionGetStorageSize - Return the size of an array or local Vec capable of holding all the degrees of freedom. 1229ea844a1aSMatthew Knepley 1230ea844a1aSMatthew Knepley Not collective 1231ea844a1aSMatthew Knepley 1232ea844a1aSMatthew Knepley Input Parameter: 1233ea844a1aSMatthew Knepley . s - the PetscSection 1234ea844a1aSMatthew Knepley 1235ea844a1aSMatthew Knepley Output Parameter: 1236ea844a1aSMatthew Knepley . size - the size of an array which can hold all the dofs 1237ea844a1aSMatthew Knepley 1238ea844a1aSMatthew Knepley Level: intermediate 1239ea844a1aSMatthew Knepley 1240ea844a1aSMatthew Knepley .seealso: PetscSectionGetOffset(), PetscSectionGetConstrainedStorageSize(), PetscSectionCreate() 1241ea844a1aSMatthew Knepley @*/ 1242ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetStorageSize(PetscSection s, PetscInt *size) 1243ea844a1aSMatthew Knepley { 1244ea844a1aSMatthew Knepley PetscInt p, n = 0; 1245ea844a1aSMatthew Knepley 1246ea844a1aSMatthew Knepley PetscFunctionBegin; 1247ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1248ea844a1aSMatthew Knepley PetscValidPointer(size, 2); 1249ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) n += s->atlasDof[p] > 0 ? s->atlasDof[p] : 0; 1250ea844a1aSMatthew Knepley *size = n; 1251ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1252ea844a1aSMatthew Knepley } 1253ea844a1aSMatthew Knepley 1254ea844a1aSMatthew Knepley /*@ 1255ea844a1aSMatthew Knepley PetscSectionGetConstrainedStorageSize - Return the size of an array or local Vec capable of holding all unconstrained degrees of freedom. 1256ea844a1aSMatthew Knepley 1257ea844a1aSMatthew Knepley Not collective 1258ea844a1aSMatthew Knepley 1259064ec1f3Sprj- Input Parameter: 1260064ec1f3Sprj- . s - the PetscSection 1261ea844a1aSMatthew Knepley 1262ea844a1aSMatthew Knepley Output Parameter: 1263ea844a1aSMatthew Knepley . size - the size of an array which can hold all unconstrained dofs 1264ea844a1aSMatthew Knepley 1265ea844a1aSMatthew Knepley Level: intermediate 1266ea844a1aSMatthew Knepley 1267ea844a1aSMatthew Knepley .seealso: PetscSectionGetStorageSize(), PetscSectionGetOffset(), PetscSectionCreate() 1268ea844a1aSMatthew Knepley @*/ 1269ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetConstrainedStorageSize(PetscSection s, PetscInt *size) 1270ea844a1aSMatthew Knepley { 1271ea844a1aSMatthew Knepley PetscInt p, n = 0; 1272ea844a1aSMatthew Knepley 1273ea844a1aSMatthew Knepley PetscFunctionBegin; 1274ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1275ea844a1aSMatthew Knepley PetscValidPointer(size, 2); 1276ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) { 1277ea844a1aSMatthew Knepley const PetscInt cdof = s->bc ? s->bc->atlasDof[p] : 0; 1278ea844a1aSMatthew Knepley n += s->atlasDof[p] > 0 ? s->atlasDof[p] - cdof : 0; 1279ea844a1aSMatthew Knepley } 1280ea844a1aSMatthew Knepley *size = n; 1281ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1282ea844a1aSMatthew Knepley } 1283ea844a1aSMatthew Knepley 1284ea844a1aSMatthew Knepley /*@ 1285ea844a1aSMatthew Knepley PetscSectionCreateGlobalSection - Create a section describing the global field layout using 1286ea844a1aSMatthew Knepley the local section and an SF describing the section point overlap. 1287ea844a1aSMatthew Knepley 1288ea844a1aSMatthew Knepley Input Parameters: 1289ea844a1aSMatthew Knepley + s - The PetscSection for the local field layout 1290ea844a1aSMatthew Knepley . sf - The SF describing parallel layout of the section points (leaves are unowned local points) 1291ea844a1aSMatthew Knepley . includeConstraints - By default this is PETSC_FALSE, meaning that the global field vector will not possess constrained dofs 1292ea844a1aSMatthew Knepley - localOffsets - If PETSC_TRUE, use local rather than global offsets for the points 1293ea844a1aSMatthew Knepley 1294ea844a1aSMatthew Knepley Output Parameter: 1295ea844a1aSMatthew Knepley . gsection - The PetscSection for the global field layout 1296ea844a1aSMatthew Knepley 1297ea844a1aSMatthew Knepley Note: This gives negative sizes and offsets to points not owned by this process 1298ea844a1aSMatthew Knepley 1299ea844a1aSMatthew Knepley Level: intermediate 1300ea844a1aSMatthew Knepley 1301ea844a1aSMatthew Knepley .seealso: PetscSectionCreate() 1302ea844a1aSMatthew Knepley @*/ 1303ea844a1aSMatthew Knepley PetscErrorCode PetscSectionCreateGlobalSection(PetscSection s, PetscSF sf, PetscBool includeConstraints, PetscBool localOffsets, PetscSection *gsection) 1304ea844a1aSMatthew Knepley { 1305ea844a1aSMatthew Knepley PetscSection gs; 1306ea844a1aSMatthew Knepley const PetscInt *pind = NULL; 1307ea844a1aSMatthew Knepley PetscInt *recv = NULL, *neg = NULL; 1308046d2115Sksagiyam PetscInt pStart, pEnd, p, dof, cdof, off, foff, globalOff = 0, nroots, nlocal, maxleaf; 1309046d2115Sksagiyam PetscInt numFields, f, numComponents; 1310ea844a1aSMatthew Knepley PetscErrorCode ierr; 1311ea844a1aSMatthew Knepley 1312ea844a1aSMatthew Knepley PetscFunctionBegin; 1313ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1314ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sf, PETSCSF_CLASSID, 2); 1315ea844a1aSMatthew Knepley PetscValidLogicalCollectiveBool(s, includeConstraints, 3); 1316ea844a1aSMatthew Knepley PetscValidLogicalCollectiveBool(s, localOffsets, 4); 1317ea844a1aSMatthew Knepley PetscValidPointer(gsection, 5); 13182c71b3e2SJacob Faibussowitsch PetscCheckFalse(!s->pointMajor,PETSC_COMM_SELF,PETSC_ERR_SUP, "No support for field major ordering"); 1319ea844a1aSMatthew Knepley ierr = PetscSectionCreate(PetscObjectComm((PetscObject) s), &gs);CHKERRQ(ierr); 1320046d2115Sksagiyam ierr = PetscSectionGetNumFields(s, &numFields);CHKERRQ(ierr); 1321046d2115Sksagiyam if (numFields > 0) {ierr = PetscSectionSetNumFields(gs, numFields);CHKERRQ(ierr);} 1322ea844a1aSMatthew Knepley ierr = PetscSectionGetChart(s, &pStart, &pEnd);CHKERRQ(ierr); 1323ea844a1aSMatthew Knepley ierr = PetscSectionSetChart(gs, pStart, pEnd);CHKERRQ(ierr); 132487e637c6Sksagiyam gs->includesConstraints = includeConstraints; 1325ea844a1aSMatthew Knepley ierr = PetscSFGetGraph(sf, &nroots, NULL, NULL, NULL);CHKERRQ(ierr); 1326ea844a1aSMatthew Knepley nlocal = nroots; /* The local/leaf space matches global/root space */ 1327ea844a1aSMatthew Knepley /* Must allocate for all points visible to SF, which may be more than this section */ 1328ea844a1aSMatthew Knepley if (nroots >= 0) { /* nroots < 0 means that the graph has not been set, only happens in serial */ 1329ea844a1aSMatthew Knepley ierr = PetscSFGetLeafRange(sf, NULL, &maxleaf);CHKERRQ(ierr); 13302c71b3e2SJacob Faibussowitsch PetscCheckFalse(nroots < pEnd,PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "SF roots %" PetscInt_FMT " < pEnd %" PetscInt_FMT, nroots, pEnd); 13312c71b3e2SJacob Faibussowitsch PetscCheckFalse(maxleaf >= nroots,PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Max local leaf %" PetscInt_FMT " >= nroots %" PetscInt_FMT, maxleaf, nroots); 1332ea844a1aSMatthew Knepley ierr = PetscMalloc2(nroots,&neg,nlocal,&recv);CHKERRQ(ierr); 1333ea844a1aSMatthew Knepley ierr = PetscArrayzero(neg,nroots);CHKERRQ(ierr); 1334ea844a1aSMatthew Knepley } 1335ea844a1aSMatthew Knepley /* Mark all local points with negative dof */ 1336ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1337ea844a1aSMatthew Knepley ierr = PetscSectionGetDof(s, p, &dof);CHKERRQ(ierr); 1338ea844a1aSMatthew Knepley ierr = PetscSectionSetDof(gs, p, dof);CHKERRQ(ierr); 1339ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintDof(s, p, &cdof);CHKERRQ(ierr); 1340ea844a1aSMatthew Knepley if (!includeConstraints && cdof > 0) {ierr = PetscSectionSetConstraintDof(gs, p, cdof);CHKERRQ(ierr);} 1341ea844a1aSMatthew Knepley if (neg) neg[p] = -(dof+1); 1342ea844a1aSMatthew Knepley } 1343ea844a1aSMatthew Knepley ierr = PetscSectionSetUpBC(gs);CHKERRQ(ierr); 1344ea844a1aSMatthew Knepley if (gs->bcIndices) {ierr = 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]);CHKERRQ(ierr);} 1345ea844a1aSMatthew Knepley if (nroots >= 0) { 1346ea844a1aSMatthew Knepley ierr = PetscArrayzero(recv,nlocal);CHKERRQ(ierr); 1347ad227feaSJunchao Zhang ierr = PetscSFBcastBegin(sf, MPIU_INT, neg, recv,MPI_REPLACE);CHKERRQ(ierr); 1348ad227feaSJunchao Zhang ierr = PetscSFBcastEnd(sf, MPIU_INT, neg, recv,MPI_REPLACE);CHKERRQ(ierr); 1349ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1350ea844a1aSMatthew Knepley if (recv[p] < 0) { 1351ea844a1aSMatthew Knepley gs->atlasDof[p-pStart] = recv[p]; 1352ea844a1aSMatthew Knepley ierr = PetscSectionGetDof(s, p, &dof);CHKERRQ(ierr); 13532c71b3e2SJacob Faibussowitsch PetscCheckFalse(-(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); 1354ea844a1aSMatthew Knepley } 1355ea844a1aSMatthew Knepley } 1356ea844a1aSMatthew Knepley } 1357ea844a1aSMatthew Knepley /* Calculate new sizes, get process offset, and calculate point offsets */ 1358ea844a1aSMatthew Knepley if (s->perm) {ierr = ISGetIndices(s->perm, &pind);CHKERRQ(ierr);} 1359ea844a1aSMatthew Knepley for (p = 0, off = 0; p < pEnd-pStart; ++p) { 1360ea844a1aSMatthew Knepley const PetscInt q = pind ? pind[p] : p; 1361ea844a1aSMatthew Knepley 1362ea844a1aSMatthew Knepley cdof = (!includeConstraints && s->bc) ? s->bc->atlasDof[q] : 0; 1363ea844a1aSMatthew Knepley gs->atlasOff[q] = off; 1364ea844a1aSMatthew Knepley off += gs->atlasDof[q] > 0 ? gs->atlasDof[q]-cdof : 0; 1365ea844a1aSMatthew Knepley } 1366ea844a1aSMatthew Knepley if (!localOffsets) { 1367ffc4695bSBarry Smith ierr = MPI_Scan(&off, &globalOff, 1, MPIU_INT, MPI_SUM, PetscObjectComm((PetscObject) s));CHKERRMPI(ierr); 1368ea844a1aSMatthew Knepley globalOff -= off; 1369ea844a1aSMatthew Knepley } 1370ea844a1aSMatthew Knepley for (p = pStart, off = 0; p < pEnd; ++p) { 1371ea844a1aSMatthew Knepley gs->atlasOff[p-pStart] += globalOff; 1372ea844a1aSMatthew Knepley if (neg) neg[p] = -(gs->atlasOff[p-pStart]+1); 1373ea844a1aSMatthew Knepley } 1374ea844a1aSMatthew Knepley if (s->perm) {ierr = ISRestoreIndices(s->perm, &pind);CHKERRQ(ierr);} 1375ea844a1aSMatthew Knepley /* Put in negative offsets for ghost points */ 1376ea844a1aSMatthew Knepley if (nroots >= 0) { 1377ea844a1aSMatthew Knepley ierr = PetscArrayzero(recv,nlocal);CHKERRQ(ierr); 1378ad227feaSJunchao Zhang ierr = PetscSFBcastBegin(sf, MPIU_INT, neg, recv,MPI_REPLACE);CHKERRQ(ierr); 1379ad227feaSJunchao Zhang ierr = PetscSFBcastEnd(sf, MPIU_INT, neg, recv,MPI_REPLACE);CHKERRQ(ierr); 1380ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1381ea844a1aSMatthew Knepley if (recv[p] < 0) gs->atlasOff[p-pStart] = recv[p]; 1382ea844a1aSMatthew Knepley } 1383ea844a1aSMatthew Knepley } 1384ea844a1aSMatthew Knepley ierr = PetscFree2(neg,recv);CHKERRQ(ierr); 1385046d2115Sksagiyam /* Set field dofs/offsets/constraints */ 1386046d2115Sksagiyam for (f = 0; f < numFields; ++f) { 1387046d2115Sksagiyam gs->field[f]->includesConstraints = includeConstraints; 1388046d2115Sksagiyam ierr = PetscSectionGetFieldComponents(s, f, &numComponents);CHKERRQ(ierr); 1389046d2115Sksagiyam ierr = PetscSectionSetFieldComponents(gs, f, numComponents);CHKERRQ(ierr); 1390046d2115Sksagiyam } 1391046d2115Sksagiyam for (p = pStart; p < pEnd; ++p) { 1392046d2115Sksagiyam ierr = PetscSectionGetOffset(gs, p, &off);CHKERRQ(ierr); 1393046d2115Sksagiyam for (f = 0, foff = off; f < numFields; ++f) { 1394046d2115Sksagiyam ierr = PetscSectionGetFieldConstraintDof(s, p, f, &cdof);CHKERRQ(ierr); 1395046d2115Sksagiyam if (!includeConstraints && cdof > 0) {ierr = PetscSectionSetFieldConstraintDof(gs, p, f, cdof);CHKERRQ(ierr);} 1396046d2115Sksagiyam ierr = PetscSectionGetFieldDof(s, p, f, &dof);CHKERRQ(ierr); 1397046d2115Sksagiyam ierr = PetscSectionSetFieldDof(gs, p, f, off < 0 ? -(dof + 1) : dof);CHKERRQ(ierr); 1398046d2115Sksagiyam ierr = PetscSectionSetFieldOffset(gs, p, f, foff);CHKERRQ(ierr); 1399046d2115Sksagiyam ierr = PetscSectionGetFieldConstraintDof(gs, p, f, &cdof);CHKERRQ(ierr); 1400046d2115Sksagiyam foff = off < 0 ? foff - (dof - cdof) : foff + (dof - cdof); 1401046d2115Sksagiyam } 1402046d2115Sksagiyam } 1403046d2115Sksagiyam for (f = 0; f < numFields; ++f) { 1404046d2115Sksagiyam PetscSection gfs = gs->field[f]; 1405046d2115Sksagiyam 1406046d2115Sksagiyam ierr = PetscSectionSetUpBC(gfs);CHKERRQ(ierr); 1407046d2115Sksagiyam if (gfs->bcIndices) {ierr = 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]);CHKERRQ(ierr);} 1408046d2115Sksagiyam } 1409046d2115Sksagiyam gs->setup = PETSC_TRUE; 1410ea844a1aSMatthew Knepley ierr = PetscSectionViewFromOptions(gs, NULL, "-global_section_view");CHKERRQ(ierr); 1411ea844a1aSMatthew Knepley *gsection = gs; 1412ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1413ea844a1aSMatthew Knepley } 1414ea844a1aSMatthew Knepley 1415ea844a1aSMatthew Knepley /*@ 1416ea844a1aSMatthew Knepley PetscSectionCreateGlobalSectionCensored - Create a section describing the global field layout using 1417ea844a1aSMatthew Knepley the local section and an SF describing the section point overlap. 1418ea844a1aSMatthew Knepley 1419ea844a1aSMatthew Knepley Input Parameters: 1420ea844a1aSMatthew Knepley + s - The PetscSection for the local field layout 1421ea844a1aSMatthew Knepley . sf - The SF describing parallel layout of the section points 1422ea844a1aSMatthew Knepley . includeConstraints - By default this is PETSC_FALSE, meaning that the global field vector will not possess constrained dofs 1423ea844a1aSMatthew Knepley . numExcludes - The number of exclusion ranges 1424ea844a1aSMatthew Knepley - excludes - An array [start_0, end_0, start_1, end_1, ...] where there are numExcludes pairs 1425ea844a1aSMatthew Knepley 1426ea844a1aSMatthew Knepley Output Parameter: 1427ea844a1aSMatthew Knepley . gsection - The PetscSection for the global field layout 1428ea844a1aSMatthew Knepley 1429ea844a1aSMatthew Knepley Note: This gives negative sizes and offsets to points not owned by this process 1430ea844a1aSMatthew Knepley 1431ea844a1aSMatthew Knepley Level: advanced 1432ea844a1aSMatthew Knepley 1433ea844a1aSMatthew Knepley .seealso: PetscSectionCreate() 1434ea844a1aSMatthew Knepley @*/ 1435ea844a1aSMatthew Knepley PetscErrorCode PetscSectionCreateGlobalSectionCensored(PetscSection s, PetscSF sf, PetscBool includeConstraints, PetscInt numExcludes, const PetscInt excludes[], PetscSection *gsection) 1436ea844a1aSMatthew Knepley { 1437ea844a1aSMatthew Knepley const PetscInt *pind = NULL; 1438ea844a1aSMatthew Knepley PetscInt *neg = NULL, *tmpOff = NULL; 1439ea844a1aSMatthew Knepley PetscInt pStart, pEnd, p, e, dof, cdof, off, globalOff = 0, nroots; 1440ea844a1aSMatthew Knepley PetscErrorCode ierr; 1441ea844a1aSMatthew Knepley 1442ea844a1aSMatthew Knepley PetscFunctionBegin; 1443ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1444ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sf, PETSCSF_CLASSID, 2); 1445ea844a1aSMatthew Knepley PetscValidPointer(gsection, 6); 1446ea844a1aSMatthew Knepley ierr = PetscSectionCreate(PetscObjectComm((PetscObject) s), gsection);CHKERRQ(ierr); 1447ea844a1aSMatthew Knepley ierr = PetscSectionGetChart(s, &pStart, &pEnd);CHKERRQ(ierr); 1448ea844a1aSMatthew Knepley ierr = PetscSectionSetChart(*gsection, pStart, pEnd);CHKERRQ(ierr); 1449ea844a1aSMatthew Knepley ierr = PetscSFGetGraph(sf, &nroots, NULL, NULL, NULL);CHKERRQ(ierr); 1450ea844a1aSMatthew Knepley if (nroots >= 0) { 14512c71b3e2SJacob Faibussowitsch PetscCheckFalse(nroots < pEnd-pStart,PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "PetscSF nroots %" PetscInt_FMT " < %" PetscInt_FMT " section size", nroots, pEnd-pStart); 1452ea844a1aSMatthew Knepley ierr = PetscCalloc1(nroots, &neg);CHKERRQ(ierr); 1453ea844a1aSMatthew Knepley if (nroots > pEnd-pStart) { 1454ea844a1aSMatthew Knepley ierr = PetscCalloc1(nroots, &tmpOff);CHKERRQ(ierr); 1455ea844a1aSMatthew Knepley } else { 1456ea844a1aSMatthew Knepley tmpOff = &(*gsection)->atlasDof[-pStart]; 1457ea844a1aSMatthew Knepley } 1458ea844a1aSMatthew Knepley } 1459ea844a1aSMatthew Knepley /* Mark ghost points with negative dof */ 1460ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1461ea844a1aSMatthew Knepley for (e = 0; e < numExcludes; ++e) { 1462ea844a1aSMatthew Knepley if ((p >= excludes[e*2+0]) && (p < excludes[e*2+1])) { 1463ea844a1aSMatthew Knepley ierr = PetscSectionSetDof(*gsection, p, 0);CHKERRQ(ierr); 1464ea844a1aSMatthew Knepley break; 1465ea844a1aSMatthew Knepley } 1466ea844a1aSMatthew Knepley } 1467ea844a1aSMatthew Knepley if (e < numExcludes) continue; 1468ea844a1aSMatthew Knepley ierr = PetscSectionGetDof(s, p, &dof);CHKERRQ(ierr); 1469ea844a1aSMatthew Knepley ierr = PetscSectionSetDof(*gsection, p, dof);CHKERRQ(ierr); 1470ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintDof(s, p, &cdof);CHKERRQ(ierr); 1471ea844a1aSMatthew Knepley if (!includeConstraints && cdof > 0) {ierr = PetscSectionSetConstraintDof(*gsection, p, cdof);CHKERRQ(ierr);} 1472ea844a1aSMatthew Knepley if (neg) neg[p] = -(dof+1); 1473ea844a1aSMatthew Knepley } 1474ea844a1aSMatthew Knepley ierr = PetscSectionSetUpBC(*gsection);CHKERRQ(ierr); 1475ea844a1aSMatthew Knepley if (nroots >= 0) { 1476ad227feaSJunchao Zhang ierr = PetscSFBcastBegin(sf, MPIU_INT, neg, tmpOff,MPI_REPLACE);CHKERRQ(ierr); 1477ad227feaSJunchao Zhang ierr = PetscSFBcastEnd(sf, MPIU_INT, neg, tmpOff,MPI_REPLACE);CHKERRQ(ierr); 1478ea844a1aSMatthew Knepley if (nroots > pEnd - pStart) { 1479ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) {if (tmpOff[p] < 0) (*gsection)->atlasDof[p-pStart] = tmpOff[p];} 1480ea844a1aSMatthew Knepley } 1481ea844a1aSMatthew Knepley } 1482ea844a1aSMatthew Knepley /* Calculate new sizes, get proccess offset, and calculate point offsets */ 1483ea844a1aSMatthew Knepley if (s->perm) {ierr = ISGetIndices(s->perm, &pind);CHKERRQ(ierr);} 1484ea844a1aSMatthew Knepley for (p = 0, off = 0; p < pEnd-pStart; ++p) { 1485ea844a1aSMatthew Knepley const PetscInt q = pind ? pind[p] : p; 1486ea844a1aSMatthew Knepley 1487ea844a1aSMatthew Knepley cdof = (!includeConstraints && s->bc) ? s->bc->atlasDof[q] : 0; 1488ea844a1aSMatthew Knepley (*gsection)->atlasOff[q] = off; 1489ea844a1aSMatthew Knepley off += (*gsection)->atlasDof[q] > 0 ? (*gsection)->atlasDof[q]-cdof : 0; 1490ea844a1aSMatthew Knepley } 1491ffc4695bSBarry Smith ierr = MPI_Scan(&off, &globalOff, 1, MPIU_INT, MPI_SUM, PetscObjectComm((PetscObject) s));CHKERRMPI(ierr); 1492ea844a1aSMatthew Knepley globalOff -= off; 1493ea844a1aSMatthew Knepley for (p = 0, off = 0; p < pEnd-pStart; ++p) { 1494ea844a1aSMatthew Knepley (*gsection)->atlasOff[p] += globalOff; 1495ea844a1aSMatthew Knepley if (neg) neg[p+pStart] = -((*gsection)->atlasOff[p]+1); 1496ea844a1aSMatthew Knepley } 1497ea844a1aSMatthew Knepley if (s->perm) {ierr = ISRestoreIndices(s->perm, &pind);CHKERRQ(ierr);} 1498ea844a1aSMatthew Knepley /* Put in negative offsets for ghost points */ 1499ea844a1aSMatthew Knepley if (nroots >= 0) { 1500ea844a1aSMatthew Knepley if (nroots == pEnd-pStart) tmpOff = &(*gsection)->atlasOff[-pStart]; 1501ad227feaSJunchao Zhang ierr = PetscSFBcastBegin(sf, MPIU_INT, neg, tmpOff,MPI_REPLACE);CHKERRQ(ierr); 1502ad227feaSJunchao Zhang ierr = PetscSFBcastEnd(sf, MPIU_INT, neg, tmpOff,MPI_REPLACE);CHKERRQ(ierr); 1503ea844a1aSMatthew Knepley if (nroots > pEnd - pStart) { 1504ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) {if (tmpOff[p] < 0) (*gsection)->atlasOff[p-pStart] = tmpOff[p];} 1505ea844a1aSMatthew Knepley } 1506ea844a1aSMatthew Knepley } 1507ea844a1aSMatthew Knepley if (nroots >= 0 && nroots > pEnd-pStart) {ierr = PetscFree(tmpOff);CHKERRQ(ierr);} 1508ea844a1aSMatthew Knepley ierr = PetscFree(neg);CHKERRQ(ierr); 1509ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1510ea844a1aSMatthew Knepley } 1511ea844a1aSMatthew Knepley 1512ea844a1aSMatthew Knepley /*@ 1513ea844a1aSMatthew Knepley PetscSectionGetPointLayout - Get the PetscLayout associated with the section points 1514ea844a1aSMatthew Knepley 1515ea844a1aSMatthew Knepley Collective on comm 1516ea844a1aSMatthew Knepley 1517ea844a1aSMatthew Knepley Input Parameters: 1518ea844a1aSMatthew Knepley + comm - The MPI_Comm 1519ea844a1aSMatthew Knepley - s - The PetscSection 1520ea844a1aSMatthew Knepley 1521ea844a1aSMatthew Knepley Output Parameter: 1522ea844a1aSMatthew Knepley . layout - The point layout for the section 1523ea844a1aSMatthew Knepley 15241681d8a4SMatthew Knepley Note: This is usually called for the default global section. 1525ea844a1aSMatthew Knepley 1526ea844a1aSMatthew Knepley Level: advanced 1527ea844a1aSMatthew Knepley 1528ea844a1aSMatthew Knepley .seealso: PetscSectionGetValueLayout(), PetscSectionCreate() 1529ea844a1aSMatthew Knepley @*/ 1530ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetPointLayout(MPI_Comm comm, PetscSection s, PetscLayout *layout) 1531ea844a1aSMatthew Knepley { 1532ea844a1aSMatthew Knepley PetscInt pStart, pEnd, p, localSize = 0; 1533ea844a1aSMatthew Knepley PetscErrorCode ierr; 1534ea844a1aSMatthew Knepley 1535ea844a1aSMatthew Knepley PetscFunctionBegin; 1536ea844a1aSMatthew Knepley ierr = PetscSectionGetChart(s, &pStart, &pEnd);CHKERRQ(ierr); 1537ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1538ea844a1aSMatthew Knepley PetscInt dof; 1539ea844a1aSMatthew Knepley 1540ea844a1aSMatthew Knepley ierr = PetscSectionGetDof(s, p, &dof);CHKERRQ(ierr); 1541ea844a1aSMatthew Knepley if (dof > 0) ++localSize; 1542ea844a1aSMatthew Knepley } 1543ea844a1aSMatthew Knepley ierr = PetscLayoutCreate(comm, layout);CHKERRQ(ierr); 1544ea844a1aSMatthew Knepley ierr = PetscLayoutSetLocalSize(*layout, localSize);CHKERRQ(ierr); 1545ea844a1aSMatthew Knepley ierr = PetscLayoutSetBlockSize(*layout, 1);CHKERRQ(ierr); 1546ea844a1aSMatthew Knepley ierr = PetscLayoutSetUp(*layout);CHKERRQ(ierr); 1547ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1548ea844a1aSMatthew Knepley } 1549ea844a1aSMatthew Knepley 1550ea844a1aSMatthew Knepley /*@ 1551ea844a1aSMatthew Knepley PetscSectionGetValueLayout - Get the PetscLayout associated with the section dofs. 1552ea844a1aSMatthew Knepley 1553ea844a1aSMatthew Knepley Collective on comm 1554ea844a1aSMatthew Knepley 1555ea844a1aSMatthew Knepley Input Parameters: 1556ea844a1aSMatthew Knepley + comm - The MPI_Comm 1557ea844a1aSMatthew Knepley - s - The PetscSection 1558ea844a1aSMatthew Knepley 1559ea844a1aSMatthew Knepley Output Parameter: 1560ea844a1aSMatthew Knepley . layout - The dof layout for the section 1561ea844a1aSMatthew Knepley 1562ea844a1aSMatthew Knepley Note: This is usually called for the default global section. 1563ea844a1aSMatthew Knepley 1564ea844a1aSMatthew Knepley Level: advanced 1565ea844a1aSMatthew Knepley 1566ea844a1aSMatthew Knepley .seealso: PetscSectionGetPointLayout(), PetscSectionCreate() 1567ea844a1aSMatthew Knepley @*/ 1568ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetValueLayout(MPI_Comm comm, PetscSection s, PetscLayout *layout) 1569ea844a1aSMatthew Knepley { 1570ea844a1aSMatthew Knepley PetscInt pStart, pEnd, p, localSize = 0; 1571ea844a1aSMatthew Knepley PetscErrorCode ierr; 1572ea844a1aSMatthew Knepley 1573ea844a1aSMatthew Knepley PetscFunctionBegin; 1574ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 2); 1575ea844a1aSMatthew Knepley PetscValidPointer(layout, 3); 1576ea844a1aSMatthew Knepley ierr = PetscSectionGetChart(s, &pStart, &pEnd);CHKERRQ(ierr); 1577ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1578ea844a1aSMatthew Knepley PetscInt dof,cdof; 1579ea844a1aSMatthew Knepley 1580ea844a1aSMatthew Knepley ierr = PetscSectionGetDof(s, p, &dof);CHKERRQ(ierr); 1581ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintDof(s, p, &cdof);CHKERRQ(ierr); 1582ea844a1aSMatthew Knepley if (dof-cdof > 0) localSize += dof-cdof; 1583ea844a1aSMatthew Knepley } 1584ea844a1aSMatthew Knepley ierr = PetscLayoutCreate(comm, layout);CHKERRQ(ierr); 1585ea844a1aSMatthew Knepley ierr = PetscLayoutSetLocalSize(*layout, localSize);CHKERRQ(ierr); 1586ea844a1aSMatthew Knepley ierr = PetscLayoutSetBlockSize(*layout, 1);CHKERRQ(ierr); 1587ea844a1aSMatthew Knepley ierr = PetscLayoutSetUp(*layout);CHKERRQ(ierr); 1588ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1589ea844a1aSMatthew Knepley } 1590ea844a1aSMatthew Knepley 1591ea844a1aSMatthew Knepley /*@ 1592ea844a1aSMatthew Knepley PetscSectionGetOffset - Return the offset into an array or local Vec for the dof associated with the given point. 1593ea844a1aSMatthew Knepley 1594ea844a1aSMatthew Knepley Not collective 1595ea844a1aSMatthew Knepley 1596ea844a1aSMatthew Knepley Input Parameters: 1597ea844a1aSMatthew Knepley + s - the PetscSection 1598ea844a1aSMatthew Knepley - point - the point 1599ea844a1aSMatthew Knepley 1600ea844a1aSMatthew Knepley Output Parameter: 1601ea844a1aSMatthew Knepley . offset - the offset 1602ea844a1aSMatthew Knepley 1603ea844a1aSMatthew Knepley Level: intermediate 1604ea844a1aSMatthew Knepley 1605ea844a1aSMatthew Knepley .seealso: PetscSectionGetFieldOffset(), PetscSectionCreate() 1606ea844a1aSMatthew Knepley @*/ 1607ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetOffset(PetscSection s, PetscInt point, PetscInt *offset) 1608ea844a1aSMatthew Knepley { 1609ea844a1aSMatthew Knepley PetscFunctionBegin; 1610ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1611ea844a1aSMatthew Knepley PetscValidPointer(offset, 3); 161276bd3646SJed Brown if (PetscDefined(USE_DEBUG)) { 16132c71b3e2SJacob Faibussowitsch PetscCheckFalse((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); 161476bd3646SJed Brown } 1615ea844a1aSMatthew Knepley *offset = s->atlasOff[point - s->pStart]; 1616ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1617ea844a1aSMatthew Knepley } 1618ea844a1aSMatthew Knepley 1619ea844a1aSMatthew Knepley /*@ 1620ea844a1aSMatthew Knepley PetscSectionSetOffset - Set the offset into an array or local Vec for the dof associated with the given point. 1621ea844a1aSMatthew Knepley 1622ea844a1aSMatthew Knepley Not collective 1623ea844a1aSMatthew Knepley 1624ea844a1aSMatthew Knepley Input Parameters: 1625ea844a1aSMatthew Knepley + s - the PetscSection 1626ea844a1aSMatthew Knepley . point - the point 1627ea844a1aSMatthew Knepley - offset - the offset 1628ea844a1aSMatthew Knepley 1629ea844a1aSMatthew Knepley Note: The user usually does not call this function, but uses PetscSectionSetUp() 1630ea844a1aSMatthew Knepley 1631ea844a1aSMatthew Knepley Level: intermediate 1632ea844a1aSMatthew Knepley 1633ea844a1aSMatthew Knepley .seealso: PetscSectionGetFieldOffset(), PetscSectionCreate(), PetscSectionSetUp() 1634ea844a1aSMatthew Knepley @*/ 1635ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetOffset(PetscSection s, PetscInt point, PetscInt offset) 1636ea844a1aSMatthew Knepley { 1637ea844a1aSMatthew Knepley PetscFunctionBegin; 1638ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 16392c71b3e2SJacob Faibussowitsch PetscCheckFalse((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); 1640ea844a1aSMatthew Knepley s->atlasOff[point - s->pStart] = offset; 1641ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1642ea844a1aSMatthew Knepley } 1643ea844a1aSMatthew Knepley 1644ea844a1aSMatthew Knepley /*@ 1645ea844a1aSMatthew Knepley PetscSectionGetFieldOffset - Return the offset into an array or local Vec for the dof associated with the given point. 1646ea844a1aSMatthew Knepley 1647ea844a1aSMatthew Knepley Not collective 1648ea844a1aSMatthew Knepley 1649ea844a1aSMatthew Knepley Input Parameters: 1650ea844a1aSMatthew Knepley + s - the PetscSection 1651ea844a1aSMatthew Knepley . point - the point 1652ea844a1aSMatthew Knepley - field - the field 1653ea844a1aSMatthew Knepley 1654ea844a1aSMatthew Knepley Output Parameter: 1655ea844a1aSMatthew Knepley . offset - the offset 1656ea844a1aSMatthew Knepley 1657ea844a1aSMatthew Knepley Level: intermediate 1658ea844a1aSMatthew Knepley 1659ea844a1aSMatthew Knepley .seealso: PetscSectionGetOffset(), PetscSectionCreate() 1660ea844a1aSMatthew Knepley @*/ 1661ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetFieldOffset(PetscSection s, PetscInt point, PetscInt field, PetscInt *offset) 1662ea844a1aSMatthew Knepley { 1663ea844a1aSMatthew Knepley PetscErrorCode ierr; 1664ea844a1aSMatthew Knepley 1665ea844a1aSMatthew Knepley PetscFunctionBegin; 1666ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 16672abc8c78SJacob Faibussowitsch PetscValidIntPointer(offset, 4); 16682abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field,s->numFields); 1669ea844a1aSMatthew Knepley ierr = PetscSectionGetOffset(s->field[field], point, offset);CHKERRQ(ierr); 1670ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1671ea844a1aSMatthew Knepley } 1672ea844a1aSMatthew Knepley 1673ea844a1aSMatthew Knepley /*@ 16741681d8a4SMatthew Knepley PetscSectionSetFieldOffset - Set the offset into an array or local Vec for the dof associated with the given field at a point. 1675ea844a1aSMatthew Knepley 1676ea844a1aSMatthew Knepley Not collective 1677ea844a1aSMatthew Knepley 1678ea844a1aSMatthew Knepley Input Parameters: 1679ea844a1aSMatthew Knepley + s - the PetscSection 1680ea844a1aSMatthew Knepley . point - the point 1681ea844a1aSMatthew Knepley . field - the field 1682ea844a1aSMatthew Knepley - offset - the offset 1683ea844a1aSMatthew Knepley 1684ea844a1aSMatthew Knepley Note: The user usually does not call this function, but uses PetscSectionSetUp() 1685ea844a1aSMatthew Knepley 1686ea844a1aSMatthew Knepley Level: intermediate 1687ea844a1aSMatthew Knepley 16881681d8a4SMatthew Knepley .seealso: PetscSectionGetFieldOffset(), PetscSectionSetOffset(), PetscSectionCreate(), PetscSectionSetUp() 1689ea844a1aSMatthew Knepley @*/ 1690ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetFieldOffset(PetscSection s, PetscInt point, PetscInt field, PetscInt offset) 1691ea844a1aSMatthew Knepley { 1692ea844a1aSMatthew Knepley PetscErrorCode ierr; 1693ea844a1aSMatthew Knepley 1694ea844a1aSMatthew Knepley PetscFunctionBegin; 1695ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 16962abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field,s->numFields); 1697ea844a1aSMatthew Knepley ierr = PetscSectionSetOffset(s->field[field], point, offset);CHKERRQ(ierr); 1698ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1699ea844a1aSMatthew Knepley } 1700ea844a1aSMatthew Knepley 1701ea844a1aSMatthew Knepley /*@ 1702ea844a1aSMatthew Knepley PetscSectionGetFieldPointOffset - Return the offset on the given point for the dof associated with the given point. 1703ea844a1aSMatthew Knepley 1704ea844a1aSMatthew Knepley Not collective 1705ea844a1aSMatthew Knepley 1706ea844a1aSMatthew Knepley Input Parameters: 1707ea844a1aSMatthew Knepley + s - the PetscSection 1708ea844a1aSMatthew Knepley . point - the point 1709ea844a1aSMatthew Knepley - field - the field 1710ea844a1aSMatthew Knepley 1711ea844a1aSMatthew Knepley Output Parameter: 1712ea844a1aSMatthew Knepley . offset - the offset 1713ea844a1aSMatthew Knepley 1714ea844a1aSMatthew Knepley Note: This gives the offset on a point of the field, ignoring constraints, meaning starting at the first dof for 1715ea844a1aSMatthew Knepley this point, what number is the first dof with this field. 1716ea844a1aSMatthew Knepley 1717ea844a1aSMatthew Knepley Level: advanced 1718ea844a1aSMatthew Knepley 1719ea844a1aSMatthew Knepley .seealso: PetscSectionGetOffset(), PetscSectionCreate() 1720ea844a1aSMatthew Knepley @*/ 1721ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetFieldPointOffset(PetscSection s, PetscInt point, PetscInt field, PetscInt *offset) 1722ea844a1aSMatthew Knepley { 1723ea844a1aSMatthew Knepley PetscInt off, foff; 1724ea844a1aSMatthew Knepley PetscErrorCode ierr; 1725ea844a1aSMatthew Knepley 1726ea844a1aSMatthew Knepley PetscFunctionBegin; 1727ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 17282abc8c78SJacob Faibussowitsch PetscValidIntPointer(offset, 4); 17292abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field,s->numFields); 1730ea844a1aSMatthew Knepley ierr = PetscSectionGetOffset(s, point, &off);CHKERRQ(ierr); 1731ea844a1aSMatthew Knepley ierr = PetscSectionGetOffset(s->field[field], point, &foff);CHKERRQ(ierr); 1732ea844a1aSMatthew Knepley *offset = foff - off; 1733ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1734ea844a1aSMatthew Knepley } 1735ea844a1aSMatthew Knepley 1736ea844a1aSMatthew Knepley /*@ 1737ea844a1aSMatthew Knepley PetscSectionGetOffsetRange - Return the full range of offsets [start, end) 1738ea844a1aSMatthew Knepley 1739ea844a1aSMatthew Knepley Not collective 1740ea844a1aSMatthew Knepley 1741ea844a1aSMatthew Knepley Input Parameter: 1742ea844a1aSMatthew Knepley . s - the PetscSection 1743ea844a1aSMatthew Knepley 1744ea844a1aSMatthew Knepley Output Parameters: 1745ea844a1aSMatthew Knepley + start - the minimum offset 1746ea844a1aSMatthew Knepley - end - one more than the maximum offset 1747ea844a1aSMatthew Knepley 1748ea844a1aSMatthew Knepley Level: intermediate 1749ea844a1aSMatthew Knepley 1750ea844a1aSMatthew Knepley .seealso: PetscSectionGetOffset(), PetscSectionCreate() 1751ea844a1aSMatthew Knepley @*/ 1752ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetOffsetRange(PetscSection s, PetscInt *start, PetscInt *end) 1753ea844a1aSMatthew Knepley { 1754ea844a1aSMatthew Knepley PetscInt os = 0, oe = 0, pStart, pEnd, p; 1755ea844a1aSMatthew Knepley PetscErrorCode ierr; 1756ea844a1aSMatthew Knepley 1757ea844a1aSMatthew Knepley PetscFunctionBegin; 1758ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1759ea844a1aSMatthew Knepley if (s->atlasOff) {os = s->atlasOff[0]; oe = s->atlasOff[0];} 1760ea844a1aSMatthew Knepley ierr = PetscSectionGetChart(s, &pStart, &pEnd);CHKERRQ(ierr); 1761ea844a1aSMatthew Knepley for (p = 0; p < pEnd-pStart; ++p) { 1762ea844a1aSMatthew Knepley PetscInt dof = s->atlasDof[p], off = s->atlasOff[p]; 1763ea844a1aSMatthew Knepley 1764ea844a1aSMatthew Knepley if (off >= 0) { 1765ea844a1aSMatthew Knepley os = PetscMin(os, off); 1766ea844a1aSMatthew Knepley oe = PetscMax(oe, off+dof); 1767ea844a1aSMatthew Knepley } 1768ea844a1aSMatthew Knepley } 1769ea844a1aSMatthew Knepley if (start) *start = os; 1770ea844a1aSMatthew Knepley if (end) *end = oe; 1771ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1772ea844a1aSMatthew Knepley } 1773ea844a1aSMatthew Knepley 1774ea844a1aSMatthew Knepley /*@ 1775ea844a1aSMatthew Knepley PetscSectionCreateSubsection - Create a new, smaller section composed of only the selected fields 1776ea844a1aSMatthew Knepley 1777ea844a1aSMatthew Knepley Collective on s 1778ea844a1aSMatthew Knepley 1779d8d19677SJose E. Roman Input Parameters: 1780ea844a1aSMatthew Knepley + s - the PetscSection 1781ea844a1aSMatthew Knepley . len - the number of subfields 1782ea844a1aSMatthew Knepley - fields - the subfield numbers 1783ea844a1aSMatthew Knepley 1784ea844a1aSMatthew Knepley Output Parameter: 1785ea844a1aSMatthew Knepley . subs - the subsection 1786ea844a1aSMatthew Knepley 1787ea844a1aSMatthew Knepley Note: The section offsets now refer to a new, smaller vector. 1788ea844a1aSMatthew Knepley 1789ea844a1aSMatthew Knepley Level: advanced 1790ea844a1aSMatthew Knepley 1791ea844a1aSMatthew Knepley .seealso: PetscSectionCreateSupersection(), PetscSectionCreate() 1792ea844a1aSMatthew Knepley @*/ 1793ea844a1aSMatthew Knepley PetscErrorCode PetscSectionCreateSubsection(PetscSection s, PetscInt len, const PetscInt fields[], PetscSection *subs) 1794ea844a1aSMatthew Knepley { 1795b778fa18SValeria Barra PetscInt nF, f, c, pStart, pEnd, p, maxCdof = 0; 1796ea844a1aSMatthew Knepley PetscErrorCode ierr; 1797ea844a1aSMatthew Knepley 1798ea844a1aSMatthew Knepley PetscFunctionBegin; 1799ea844a1aSMatthew Knepley if (!len) PetscFunctionReturn(0); 1800ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 1801ea844a1aSMatthew Knepley PetscValidPointer(fields, 3); 1802ea844a1aSMatthew Knepley PetscValidPointer(subs, 4); 1803ea844a1aSMatthew Knepley ierr = PetscSectionGetNumFields(s, &nF);CHKERRQ(ierr); 18042c71b3e2SJacob Faibussowitsch PetscCheckFalse(len > nF,PetscObjectComm((PetscObject) s), PETSC_ERR_ARG_WRONG, "Number of requested fields %" PetscInt_FMT " greater than number of fields %" PetscInt_FMT, len, nF); 1805ea844a1aSMatthew Knepley ierr = PetscSectionCreate(PetscObjectComm((PetscObject) s), subs);CHKERRQ(ierr); 1806ea844a1aSMatthew Knepley ierr = PetscSectionSetNumFields(*subs, len);CHKERRQ(ierr); 1807ea844a1aSMatthew Knepley for (f = 0; f < len; ++f) { 1808ea844a1aSMatthew Knepley const char *name = NULL; 1809ea844a1aSMatthew Knepley PetscInt numComp = 0; 1810ea844a1aSMatthew Knepley 1811ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldName(s, fields[f], &name);CHKERRQ(ierr); 1812ea844a1aSMatthew Knepley ierr = PetscSectionSetFieldName(*subs, f, name);CHKERRQ(ierr); 1813ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldComponents(s, fields[f], &numComp);CHKERRQ(ierr); 1814ea844a1aSMatthew Knepley ierr = PetscSectionSetFieldComponents(*subs, f, numComp);CHKERRQ(ierr); 1815b778fa18SValeria Barra for (c = 0; c < s->numFieldComponents[fields[f]]; ++c) { 1816b778fa18SValeria Barra ierr = PetscSectionGetComponentName(s, fields[f], c, &name);CHKERRQ(ierr); 1817b778fa18SValeria Barra ierr = PetscSectionSetComponentName(*subs, f, c, name);CHKERRQ(ierr); 1818b778fa18SValeria Barra } 1819ea844a1aSMatthew Knepley } 1820ea844a1aSMatthew Knepley ierr = PetscSectionGetChart(s, &pStart, &pEnd);CHKERRQ(ierr); 1821ea844a1aSMatthew Knepley ierr = PetscSectionSetChart(*subs, pStart, pEnd);CHKERRQ(ierr); 1822ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1823ea844a1aSMatthew Knepley PetscInt dof = 0, cdof = 0, fdof = 0, cfdof = 0; 1824ea844a1aSMatthew Knepley 1825ea844a1aSMatthew Knepley for (f = 0; f < len; ++f) { 1826ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldDof(s, p, fields[f], &fdof);CHKERRQ(ierr); 1827ea844a1aSMatthew Knepley ierr = PetscSectionSetFieldDof(*subs, p, f, fdof);CHKERRQ(ierr); 1828ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldConstraintDof(s, p, fields[f], &cfdof);CHKERRQ(ierr); 1829ea844a1aSMatthew Knepley if (cfdof) {ierr = PetscSectionSetFieldConstraintDof(*subs, p, f, cfdof);CHKERRQ(ierr);} 1830ea844a1aSMatthew Knepley dof += fdof; 1831ea844a1aSMatthew Knepley cdof += cfdof; 1832ea844a1aSMatthew Knepley } 1833ea844a1aSMatthew Knepley ierr = PetscSectionSetDof(*subs, p, dof);CHKERRQ(ierr); 1834ea844a1aSMatthew Knepley if (cdof) {ierr = PetscSectionSetConstraintDof(*subs, p, cdof);CHKERRQ(ierr);} 1835ea844a1aSMatthew Knepley maxCdof = PetscMax(cdof, maxCdof); 1836ea844a1aSMatthew Knepley } 1837ea844a1aSMatthew Knepley ierr = PetscSectionSetUp(*subs);CHKERRQ(ierr); 1838ea844a1aSMatthew Knepley if (maxCdof) { 1839ea844a1aSMatthew Knepley PetscInt *indices; 1840ea844a1aSMatthew Knepley 1841ea844a1aSMatthew Knepley ierr = PetscMalloc1(maxCdof, &indices);CHKERRQ(ierr); 1842ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1843ea844a1aSMatthew Knepley PetscInt cdof; 1844ea844a1aSMatthew Knepley 1845ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintDof(*subs, p, &cdof);CHKERRQ(ierr); 1846ea844a1aSMatthew Knepley if (cdof) { 1847ea844a1aSMatthew Knepley const PetscInt *oldIndices = NULL; 1848ea844a1aSMatthew Knepley PetscInt fdof = 0, cfdof = 0, fc, numConst = 0, fOff = 0; 1849ea844a1aSMatthew Knepley 1850ea844a1aSMatthew Knepley for (f = 0; f < len; ++f) { 1851ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldDof(s, p, fields[f], &fdof);CHKERRQ(ierr); 1852ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldConstraintDof(s, p, fields[f], &cfdof);CHKERRQ(ierr); 1853ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldConstraintIndices(s, p, fields[f], &oldIndices);CHKERRQ(ierr); 18549574d0f0SMatthew G. Knepley ierr = PetscSectionSetFieldConstraintIndices(*subs, p, f, oldIndices);CHKERRQ(ierr); 18559574d0f0SMatthew G. Knepley for (fc = 0; fc < cfdof; ++fc) indices[numConst+fc] = oldIndices[fc] + fOff; 1856ea844a1aSMatthew Knepley numConst += cfdof; 1857ea844a1aSMatthew Knepley fOff += fdof; 1858ea844a1aSMatthew Knepley } 1859ea844a1aSMatthew Knepley ierr = PetscSectionSetConstraintIndices(*subs, p, indices);CHKERRQ(ierr); 1860ea844a1aSMatthew Knepley } 1861ea844a1aSMatthew Knepley } 1862ea844a1aSMatthew Knepley ierr = PetscFree(indices);CHKERRQ(ierr); 1863ea844a1aSMatthew Knepley } 1864ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1865ea844a1aSMatthew Knepley } 1866ea844a1aSMatthew Knepley 1867ea844a1aSMatthew Knepley /*@ 1868ea844a1aSMatthew Knepley PetscSectionCreateSupersection - Create a new, larger section composed of the input sections 1869ea844a1aSMatthew Knepley 1870ea844a1aSMatthew Knepley Collective on s 1871ea844a1aSMatthew Knepley 1872ea844a1aSMatthew Knepley Input Parameters: 1873ea844a1aSMatthew Knepley + s - the input sections 1874ea844a1aSMatthew Knepley - len - the number of input sections 1875ea844a1aSMatthew Knepley 1876ea844a1aSMatthew Knepley Output Parameter: 1877ea844a1aSMatthew Knepley . supers - the supersection 1878ea844a1aSMatthew Knepley 1879ea844a1aSMatthew Knepley Note: The section offsets now refer to a new, larger vector. 1880ea844a1aSMatthew Knepley 1881ea844a1aSMatthew Knepley Level: advanced 1882ea844a1aSMatthew Knepley 1883ea844a1aSMatthew Knepley .seealso: PetscSectionCreateSubsection(), PetscSectionCreate() 1884ea844a1aSMatthew Knepley @*/ 1885ea844a1aSMatthew Knepley PetscErrorCode PetscSectionCreateSupersection(PetscSection s[], PetscInt len, PetscSection *supers) 1886ea844a1aSMatthew Knepley { 1887ea844a1aSMatthew Knepley PetscInt Nf = 0, f, pStart = PETSC_MAX_INT, pEnd = 0, p, maxCdof = 0, i; 1888ea844a1aSMatthew Knepley PetscErrorCode ierr; 1889ea844a1aSMatthew Knepley 1890ea844a1aSMatthew Knepley PetscFunctionBegin; 1891ea844a1aSMatthew Knepley if (!len) PetscFunctionReturn(0); 1892ea844a1aSMatthew Knepley for (i = 0; i < len; ++i) { 1893ea844a1aSMatthew Knepley PetscInt nf, pStarti, pEndi; 1894ea844a1aSMatthew Knepley 1895ea844a1aSMatthew Knepley ierr = PetscSectionGetNumFields(s[i], &nf);CHKERRQ(ierr); 1896ea844a1aSMatthew Knepley ierr = PetscSectionGetChart(s[i], &pStarti, &pEndi);CHKERRQ(ierr); 1897ea844a1aSMatthew Knepley pStart = PetscMin(pStart, pStarti); 1898ea844a1aSMatthew Knepley pEnd = PetscMax(pEnd, pEndi); 1899ea844a1aSMatthew Knepley Nf += nf; 1900ea844a1aSMatthew Knepley } 1901ea844a1aSMatthew Knepley ierr = PetscSectionCreate(PetscObjectComm((PetscObject) s[0]), supers);CHKERRQ(ierr); 1902ea844a1aSMatthew Knepley ierr = PetscSectionSetNumFields(*supers, Nf);CHKERRQ(ierr); 1903ea844a1aSMatthew Knepley for (i = 0, f = 0; i < len; ++i) { 1904b778fa18SValeria Barra PetscInt nf, fi, ci; 1905ea844a1aSMatthew Knepley 1906ea844a1aSMatthew Knepley ierr = PetscSectionGetNumFields(s[i], &nf);CHKERRQ(ierr); 1907ea844a1aSMatthew Knepley for (fi = 0; fi < nf; ++fi, ++f) { 1908ea844a1aSMatthew Knepley const char *name = NULL; 1909ea844a1aSMatthew Knepley PetscInt numComp = 0; 1910ea844a1aSMatthew Knepley 1911ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldName(s[i], fi, &name);CHKERRQ(ierr); 1912ea844a1aSMatthew Knepley ierr = PetscSectionSetFieldName(*supers, f, name);CHKERRQ(ierr); 1913ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldComponents(s[i], fi, &numComp);CHKERRQ(ierr); 1914ea844a1aSMatthew Knepley ierr = PetscSectionSetFieldComponents(*supers, f, numComp);CHKERRQ(ierr); 1915b778fa18SValeria Barra for (ci = 0; ci < s[i]->numFieldComponents[fi]; ++ci) { 1916b778fa18SValeria Barra ierr = PetscSectionGetComponentName(s[i], fi, ci, &name);CHKERRQ(ierr); 1917b778fa18SValeria Barra ierr = PetscSectionSetComponentName(*supers, f, ci, name);CHKERRQ(ierr); 1918b778fa18SValeria Barra } 1919ea844a1aSMatthew Knepley } 1920ea844a1aSMatthew Knepley } 1921ea844a1aSMatthew Knepley ierr = PetscSectionSetChart(*supers, pStart, pEnd);CHKERRQ(ierr); 1922ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1923ea844a1aSMatthew Knepley PetscInt dof = 0, cdof = 0; 1924ea844a1aSMatthew Knepley 1925ea844a1aSMatthew Knepley for (i = 0, f = 0; i < len; ++i) { 1926ea844a1aSMatthew Knepley PetscInt nf, fi, pStarti, pEndi; 1927ea844a1aSMatthew Knepley PetscInt fdof = 0, cfdof = 0; 1928ea844a1aSMatthew Knepley 1929ea844a1aSMatthew Knepley ierr = PetscSectionGetNumFields(s[i], &nf);CHKERRQ(ierr); 1930ea844a1aSMatthew Knepley ierr = PetscSectionGetChart(s[i], &pStarti, &pEndi);CHKERRQ(ierr); 1931ea844a1aSMatthew Knepley if ((p < pStarti) || (p >= pEndi)) continue; 1932ea844a1aSMatthew Knepley for (fi = 0; fi < nf; ++fi, ++f) { 1933ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldDof(s[i], p, fi, &fdof);CHKERRQ(ierr); 1934ea844a1aSMatthew Knepley ierr = PetscSectionAddFieldDof(*supers, p, f, fdof);CHKERRQ(ierr); 1935ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldConstraintDof(s[i], p, fi, &cfdof);CHKERRQ(ierr); 1936ea844a1aSMatthew Knepley if (cfdof) {ierr = PetscSectionAddFieldConstraintDof(*supers, p, f, cfdof);CHKERRQ(ierr);} 1937ea844a1aSMatthew Knepley dof += fdof; 1938ea844a1aSMatthew Knepley cdof += cfdof; 1939ea844a1aSMatthew Knepley } 1940ea844a1aSMatthew Knepley } 1941ea844a1aSMatthew Knepley ierr = PetscSectionSetDof(*supers, p, dof);CHKERRQ(ierr); 1942ea844a1aSMatthew Knepley if (cdof) {ierr = PetscSectionSetConstraintDof(*supers, p, cdof);CHKERRQ(ierr);} 1943ea844a1aSMatthew Knepley maxCdof = PetscMax(cdof, maxCdof); 1944ea844a1aSMatthew Knepley } 1945ea844a1aSMatthew Knepley ierr = PetscSectionSetUp(*supers);CHKERRQ(ierr); 1946ea844a1aSMatthew Knepley if (maxCdof) { 1947ea844a1aSMatthew Knepley PetscInt *indices; 1948ea844a1aSMatthew Knepley 1949ea844a1aSMatthew Knepley ierr = PetscMalloc1(maxCdof, &indices);CHKERRQ(ierr); 1950ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 1951ea844a1aSMatthew Knepley PetscInt cdof; 1952ea844a1aSMatthew Knepley 1953ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintDof(*supers, p, &cdof);CHKERRQ(ierr); 1954ea844a1aSMatthew Knepley if (cdof) { 1955ea844a1aSMatthew Knepley PetscInt dof, numConst = 0, fOff = 0; 1956ea844a1aSMatthew Knepley 1957ea844a1aSMatthew Knepley for (i = 0, f = 0; i < len; ++i) { 1958ea844a1aSMatthew Knepley const PetscInt *oldIndices = NULL; 1959ea844a1aSMatthew Knepley PetscInt nf, fi, pStarti, pEndi, fdof, cfdof, fc; 1960ea844a1aSMatthew Knepley 1961ea844a1aSMatthew Knepley ierr = PetscSectionGetNumFields(s[i], &nf);CHKERRQ(ierr); 1962ea844a1aSMatthew Knepley ierr = PetscSectionGetChart(s[i], &pStarti, &pEndi);CHKERRQ(ierr); 1963ea844a1aSMatthew Knepley if ((p < pStarti) || (p >= pEndi)) continue; 1964ea844a1aSMatthew Knepley for (fi = 0; fi < nf; ++fi, ++f) { 1965ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldDof(s[i], p, fi, &fdof);CHKERRQ(ierr); 1966ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldConstraintDof(s[i], p, fi, &cfdof);CHKERRQ(ierr); 1967ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldConstraintIndices(s[i], p, fi, &oldIndices);CHKERRQ(ierr); 1968fcd2503dSMatthew G. Knepley for (fc = 0; fc < cfdof; ++fc) indices[numConst+fc] = oldIndices[fc]; 1969ea844a1aSMatthew Knepley ierr = PetscSectionSetFieldConstraintIndices(*supers, p, f, &indices[numConst]);CHKERRQ(ierr); 1970fcd2503dSMatthew G. Knepley for (fc = 0; fc < cfdof; ++fc) indices[numConst+fc] += fOff; 1971ea844a1aSMatthew Knepley numConst += cfdof; 1972ea844a1aSMatthew Knepley } 1973ea844a1aSMatthew Knepley ierr = PetscSectionGetDof(s[i], p, &dof);CHKERRQ(ierr); 1974ea844a1aSMatthew Knepley fOff += dof; 1975ea844a1aSMatthew Knepley } 1976ea844a1aSMatthew Knepley ierr = PetscSectionSetConstraintIndices(*supers, p, indices);CHKERRQ(ierr); 1977ea844a1aSMatthew Knepley } 1978ea844a1aSMatthew Knepley } 1979ea844a1aSMatthew Knepley ierr = PetscFree(indices);CHKERRQ(ierr); 1980ea844a1aSMatthew Knepley } 1981ea844a1aSMatthew Knepley PetscFunctionReturn(0); 1982ea844a1aSMatthew Knepley } 1983ea844a1aSMatthew Knepley 1984ea844a1aSMatthew Knepley /*@ 1985ea844a1aSMatthew Knepley PetscSectionCreateSubmeshSection - Create a new, smaller section with support on the submesh 1986ea844a1aSMatthew Knepley 1987ea844a1aSMatthew Knepley Collective on s 1988ea844a1aSMatthew Knepley 1989ea844a1aSMatthew Knepley Input Parameters: 1990ea844a1aSMatthew Knepley + s - the PetscSection 1991ea844a1aSMatthew Knepley - subpointMap - a sorted list of points in the original mesh which are in the submesh 1992ea844a1aSMatthew Knepley 1993ea844a1aSMatthew Knepley Output Parameter: 1994ea844a1aSMatthew Knepley . subs - the subsection 1995ea844a1aSMatthew Knepley 1996ea844a1aSMatthew Knepley Note: The section offsets now refer to a new, smaller vector. 1997ea844a1aSMatthew Knepley 1998ea844a1aSMatthew Knepley Level: advanced 1999ea844a1aSMatthew Knepley 2000ea844a1aSMatthew Knepley .seealso: PetscSectionCreateSubsection(), DMPlexGetSubpointMap(), PetscSectionCreate() 2001ea844a1aSMatthew Knepley @*/ 2002ea844a1aSMatthew Knepley PetscErrorCode PetscSectionCreateSubmeshSection(PetscSection s, IS subpointMap, PetscSection *subs) 2003ea844a1aSMatthew Knepley { 2004ea844a1aSMatthew Knepley const PetscInt *points = NULL, *indices = NULL; 2005b778fa18SValeria Barra PetscInt numFields, f, c, numSubpoints = 0, pStart, pEnd, p, subp; 2006ea844a1aSMatthew Knepley PetscErrorCode ierr; 2007ea844a1aSMatthew Knepley 2008ea844a1aSMatthew Knepley PetscFunctionBegin; 2009ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2010ea844a1aSMatthew Knepley PetscValidHeaderSpecific(subpointMap, IS_CLASSID, 2); 2011ea844a1aSMatthew Knepley PetscValidPointer(subs, 3); 2012ea844a1aSMatthew Knepley ierr = PetscSectionGetNumFields(s, &numFields);CHKERRQ(ierr); 2013ea844a1aSMatthew Knepley ierr = PetscSectionCreate(PetscObjectComm((PetscObject) s), subs);CHKERRQ(ierr); 2014ea844a1aSMatthew Knepley if (numFields) {ierr = PetscSectionSetNumFields(*subs, numFields);CHKERRQ(ierr);} 2015ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 2016ea844a1aSMatthew Knepley const char *name = NULL; 2017ea844a1aSMatthew Knepley PetscInt numComp = 0; 2018ea844a1aSMatthew Knepley 2019ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldName(s, f, &name);CHKERRQ(ierr); 2020ea844a1aSMatthew Knepley ierr = PetscSectionSetFieldName(*subs, f, name);CHKERRQ(ierr); 2021ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldComponents(s, f, &numComp);CHKERRQ(ierr); 2022ea844a1aSMatthew Knepley ierr = PetscSectionSetFieldComponents(*subs, f, numComp);CHKERRQ(ierr); 2023b778fa18SValeria Barra for (c = 0; c < s->numFieldComponents[f]; ++c) { 2024b778fa18SValeria Barra ierr = PetscSectionGetComponentName(s, f, c, &name);CHKERRQ(ierr); 2025b778fa18SValeria Barra ierr = PetscSectionSetComponentName(*subs, f, c, name);CHKERRQ(ierr); 2026b778fa18SValeria Barra } 2027ea844a1aSMatthew Knepley } 2028ea844a1aSMatthew Knepley /* For right now, we do not try to squeeze the subchart */ 2029ea844a1aSMatthew Knepley if (subpointMap) { 2030ea844a1aSMatthew Knepley ierr = ISGetSize(subpointMap, &numSubpoints);CHKERRQ(ierr); 2031ea844a1aSMatthew Knepley ierr = ISGetIndices(subpointMap, &points);CHKERRQ(ierr); 2032ea844a1aSMatthew Knepley } 2033ea844a1aSMatthew Knepley ierr = PetscSectionGetChart(s, &pStart, &pEnd);CHKERRQ(ierr); 2034ea844a1aSMatthew Knepley ierr = PetscSectionSetChart(*subs, 0, numSubpoints);CHKERRQ(ierr); 2035ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2036ea844a1aSMatthew Knepley PetscInt dof, cdof, fdof = 0, cfdof = 0; 2037ea844a1aSMatthew Knepley 2038ea844a1aSMatthew Knepley ierr = PetscFindInt(p, numSubpoints, points, &subp);CHKERRQ(ierr); 2039ea844a1aSMatthew Knepley if (subp < 0) continue; 2040ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 2041ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldDof(s, p, f, &fdof);CHKERRQ(ierr); 2042ea844a1aSMatthew Knepley ierr = PetscSectionSetFieldDof(*subs, subp, f, fdof);CHKERRQ(ierr); 2043ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldConstraintDof(s, p, f, &cfdof);CHKERRQ(ierr); 2044ea844a1aSMatthew Knepley if (cfdof) {ierr = PetscSectionSetFieldConstraintDof(*subs, subp, f, cfdof);CHKERRQ(ierr);} 2045ea844a1aSMatthew Knepley } 2046ea844a1aSMatthew Knepley ierr = PetscSectionGetDof(s, p, &dof);CHKERRQ(ierr); 2047ea844a1aSMatthew Knepley ierr = PetscSectionSetDof(*subs, subp, dof);CHKERRQ(ierr); 2048ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintDof(s, p, &cdof);CHKERRQ(ierr); 2049ea844a1aSMatthew Knepley if (cdof) {ierr = PetscSectionSetConstraintDof(*subs, subp, cdof);CHKERRQ(ierr);} 2050ea844a1aSMatthew Knepley } 2051ea844a1aSMatthew Knepley ierr = PetscSectionSetUp(*subs);CHKERRQ(ierr); 2052ea844a1aSMatthew Knepley /* Change offsets to original offsets */ 2053ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2054ea844a1aSMatthew Knepley PetscInt off, foff = 0; 2055ea844a1aSMatthew Knepley 2056ea844a1aSMatthew Knepley ierr = PetscFindInt(p, numSubpoints, points, &subp);CHKERRQ(ierr); 2057ea844a1aSMatthew Knepley if (subp < 0) continue; 2058ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 2059ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldOffset(s, p, f, &foff);CHKERRQ(ierr); 2060ea844a1aSMatthew Knepley ierr = PetscSectionSetFieldOffset(*subs, subp, f, foff);CHKERRQ(ierr); 2061ea844a1aSMatthew Knepley } 2062ea844a1aSMatthew Knepley ierr = PetscSectionGetOffset(s, p, &off);CHKERRQ(ierr); 2063ea844a1aSMatthew Knepley ierr = PetscSectionSetOffset(*subs, subp, off);CHKERRQ(ierr); 2064ea844a1aSMatthew Knepley } 2065ea844a1aSMatthew Knepley /* Copy constraint indices */ 2066ea844a1aSMatthew Knepley for (subp = 0; subp < numSubpoints; ++subp) { 2067ea844a1aSMatthew Knepley PetscInt cdof; 2068ea844a1aSMatthew Knepley 2069ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintDof(*subs, subp, &cdof);CHKERRQ(ierr); 2070ea844a1aSMatthew Knepley if (cdof) { 2071ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 2072ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldConstraintIndices(s, points[subp], f, &indices);CHKERRQ(ierr); 2073ea844a1aSMatthew Knepley ierr = PetscSectionSetFieldConstraintIndices(*subs, subp, f, indices);CHKERRQ(ierr); 2074ea844a1aSMatthew Knepley } 2075ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintIndices(s, points[subp], &indices);CHKERRQ(ierr); 2076ea844a1aSMatthew Knepley ierr = PetscSectionSetConstraintIndices(*subs, subp, indices);CHKERRQ(ierr); 2077ea844a1aSMatthew Knepley } 2078ea844a1aSMatthew Knepley } 2079ea844a1aSMatthew Knepley if (subpointMap) {ierr = ISRestoreIndices(subpointMap, &points);CHKERRQ(ierr);} 2080ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2081ea844a1aSMatthew Knepley } 2082ea844a1aSMatthew Knepley 2083ea844a1aSMatthew Knepley static PetscErrorCode PetscSectionView_ASCII(PetscSection s, PetscViewer viewer) 2084ea844a1aSMatthew Knepley { 2085ea844a1aSMatthew Knepley PetscInt p; 2086ea844a1aSMatthew Knepley PetscMPIInt rank; 2087ea844a1aSMatthew Knepley PetscErrorCode ierr; 2088ea844a1aSMatthew Knepley 2089ea844a1aSMatthew Knepley PetscFunctionBegin; 2090ffc4695bSBarry Smith ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)viewer), &rank);CHKERRMPI(ierr); 2091ea844a1aSMatthew Knepley ierr = PetscViewerASCIIPushSynchronized(viewer);CHKERRQ(ierr); 2092ea844a1aSMatthew Knepley ierr = PetscViewerASCIISynchronizedPrintf(viewer, "Process %d:\n", rank);CHKERRQ(ierr); 2093ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) { 2094ea844a1aSMatthew Knepley if ((s->bc) && (s->bc->atlasDof[p] > 0)) { 2095ea844a1aSMatthew Knepley PetscInt b; 2096ea844a1aSMatthew Knepley 20972abc8c78SJacob Faibussowitsch ierr = PetscViewerASCIISynchronizedPrintf(viewer, " (%4" PetscInt_FMT ") dim %2" PetscInt_FMT " offset %3" PetscInt_FMT " constrained", p+s->pStart, s->atlasDof[p], s->atlasOff[p]);CHKERRQ(ierr); 2098083401c6SMatthew G. Knepley if (s->bcIndices) { 2099ea844a1aSMatthew Knepley for (b = 0; b < s->bc->atlasDof[p]; ++b) { 21002cfd1bebSJacob Faibussowitsch ierr = PetscViewerASCIISynchronizedPrintf(viewer, " %" PetscInt_FMT, s->bcIndices[s->bc->atlasOff[p]+b]);CHKERRQ(ierr); 2101ea844a1aSMatthew Knepley } 2102083401c6SMatthew G. Knepley } 2103ea844a1aSMatthew Knepley ierr = PetscViewerASCIISynchronizedPrintf(viewer, "\n");CHKERRQ(ierr); 2104ea844a1aSMatthew Knepley } else { 21052abc8c78SJacob Faibussowitsch ierr = PetscViewerASCIISynchronizedPrintf(viewer, " (%4" PetscInt_FMT ") dim %2" PetscInt_FMT " offset %3" PetscInt_FMT "\n", p+s->pStart, s->atlasDof[p], s->atlasOff[p]);CHKERRQ(ierr); 2106ea844a1aSMatthew Knepley } 2107ea844a1aSMatthew Knepley } 2108ea844a1aSMatthew Knepley ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); 2109ea844a1aSMatthew Knepley ierr = PetscViewerASCIIPopSynchronized(viewer);CHKERRQ(ierr); 2110ea844a1aSMatthew Knepley if (s->sym) { 2111ea844a1aSMatthew Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 2112ea844a1aSMatthew Knepley ierr = PetscSectionSymView(s->sym,viewer);CHKERRQ(ierr); 2113ea844a1aSMatthew Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 2114ea844a1aSMatthew Knepley } 2115ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2116ea844a1aSMatthew Knepley } 2117ea844a1aSMatthew Knepley 2118ea844a1aSMatthew Knepley /*@C 2119fe2efc57SMark PetscSectionViewFromOptions - View from Options 2120fe2efc57SMark 2121fe2efc57SMark Collective on PetscSection 2122fe2efc57SMark 2123fe2efc57SMark Input Parameters: 2124fe2efc57SMark + A - the PetscSection object to view 2125736c3998SJose E. Roman . obj - Optional object 2126736c3998SJose E. Roman - name - command line option 2127fe2efc57SMark 2128fe2efc57SMark Level: intermediate 2129fe2efc57SMark .seealso: PetscSection, PetscSectionView, PetscObjectViewFromOptions(), PetscSectionCreate() 2130fe2efc57SMark @*/ 2131fe2efc57SMark PetscErrorCode PetscSectionViewFromOptions(PetscSection A,PetscObject obj,const char name[]) 2132fe2efc57SMark { 2133fe2efc57SMark PetscErrorCode ierr; 2134fe2efc57SMark 2135fe2efc57SMark PetscFunctionBegin; 2136fe2efc57SMark PetscValidHeaderSpecific(A,PETSC_SECTION_CLASSID,1); 2137fe2efc57SMark ierr = PetscObjectViewFromOptions((PetscObject)A,obj,name);CHKERRQ(ierr); 2138fe2efc57SMark PetscFunctionReturn(0); 2139fe2efc57SMark } 2140fe2efc57SMark 2141fe2efc57SMark /*@C 2142ea844a1aSMatthew Knepley PetscSectionView - Views a PetscSection 2143ea844a1aSMatthew Knepley 2144ea844a1aSMatthew Knepley Collective on PetscSection 2145ea844a1aSMatthew Knepley 2146ea844a1aSMatthew Knepley Input Parameters: 2147ea844a1aSMatthew Knepley + s - the PetscSection object to view 2148ea844a1aSMatthew Knepley - v - the viewer 2149ea844a1aSMatthew Knepley 21501ddd528eSksagiyam Note: 21511ddd528eSksagiyam PetscSectionView(), when viewer is of type PETSCVIEWERHDF5, only saves 21521ddd528eSksagiyam distribution independent data, such as dofs, offsets, constraint dofs, 21531ddd528eSksagiyam and constraint indices. Points that have negative dofs, for instance, 21541ddd528eSksagiyam are not saved as they represent points owned by other processes. 21551ddd528eSksagiyam Point numbering and rank assignment is currently not stored. 21561ddd528eSksagiyam The saved section can be loaded with PetscSectionLoad(). 21571ddd528eSksagiyam 2158ea844a1aSMatthew Knepley Level: beginner 2159ea844a1aSMatthew Knepley 2160fde5e3acSksagiyam .seealso PetscSectionCreate(), PetscSectionDestroy(), PetscSectionLoad() 2161ea844a1aSMatthew Knepley @*/ 2162ea844a1aSMatthew Knepley PetscErrorCode PetscSectionView(PetscSection s, PetscViewer viewer) 2163ea844a1aSMatthew Knepley { 21641ddd528eSksagiyam PetscBool isascii, ishdf5; 2165ea844a1aSMatthew Knepley PetscInt f; 2166ea844a1aSMatthew Knepley PetscErrorCode ierr; 2167ea844a1aSMatthew Knepley 2168ea844a1aSMatthew Knepley PetscFunctionBegin; 2169ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2170ea844a1aSMatthew Knepley if (!viewer) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)s), &viewer);CHKERRQ(ierr);} 2171ea844a1aSMatthew Knepley PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2); 2172ea844a1aSMatthew Knepley ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERASCII, &isascii);CHKERRQ(ierr); 21731ddd528eSksagiyam ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERHDF5, &ishdf5);CHKERRQ(ierr); 2174ea844a1aSMatthew Knepley if (isascii) { 2175ea844a1aSMatthew Knepley ierr = PetscObjectPrintClassNamePrefixType((PetscObject)s,viewer);CHKERRQ(ierr); 2176ea844a1aSMatthew Knepley if (s->numFields) { 21772abc8c78SJacob Faibussowitsch ierr = PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT " fields\n", s->numFields);CHKERRQ(ierr); 2178ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) { 21792abc8c78SJacob Faibussowitsch ierr = PetscViewerASCIIPrintf(viewer, " field %" PetscInt_FMT " with %" PetscInt_FMT " components\n", f, s->numFieldComponents[f]);CHKERRQ(ierr); 2180ea844a1aSMatthew Knepley ierr = PetscSectionView_ASCII(s->field[f], viewer);CHKERRQ(ierr); 2181ea844a1aSMatthew Knepley } 2182ea844a1aSMatthew Knepley } else { 2183ea844a1aSMatthew Knepley ierr = PetscSectionView_ASCII(s, viewer);CHKERRQ(ierr); 2184ea844a1aSMatthew Knepley } 21851ddd528eSksagiyam } else if (ishdf5) { 21861ddd528eSksagiyam #if PetscDefined(HAVE_HDF5) 21871ddd528eSksagiyam ierr = PetscSectionView_HDF5_Internal(s, viewer);CHKERRQ(ierr); 21881ddd528eSksagiyam #else 21891ddd528eSksagiyam SETERRQ(PetscObjectComm((PetscObject) s), PETSC_ERR_SUP, "HDF5 not supported in this build.\nPlease reconfigure using --download-hdf5"); 21901ddd528eSksagiyam #endif 2191ea844a1aSMatthew Knepley } 2192ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2193ea844a1aSMatthew Knepley } 2194ea844a1aSMatthew Knepley 2195fde5e3acSksagiyam /*@C 2196fde5e3acSksagiyam PetscSectionLoad - Loads a PetscSection 2197fde5e3acSksagiyam 2198fde5e3acSksagiyam Collective on PetscSection 2199fde5e3acSksagiyam 2200fde5e3acSksagiyam Input Parameters: 2201fde5e3acSksagiyam + s - the PetscSection object to load 2202fde5e3acSksagiyam - v - the viewer 2203fde5e3acSksagiyam 2204fde5e3acSksagiyam Note: 2205fde5e3acSksagiyam PetscSectionLoad(), when viewer is of type PETSCVIEWERHDF5, loads 2206fde5e3acSksagiyam a section saved with PetscSectionView(). The number of processes 2207fde5e3acSksagiyam used here (N) does not need to be the same as that used when saving. 2208fde5e3acSksagiyam After calling this function, the chart of s on rank i will be set 2209fde5e3acSksagiyam to [0, E_i), where \sum_{i=0}^{N-1}E_i equals to the total number of 2210fde5e3acSksagiyam saved section points. 2211fde5e3acSksagiyam 2212fde5e3acSksagiyam Level: beginner 2213fde5e3acSksagiyam 2214fde5e3acSksagiyam .seealso PetscSectionCreate(), PetscSectionDestroy(), PetscSectionView() 2215fde5e3acSksagiyam @*/ 2216fde5e3acSksagiyam PetscErrorCode PetscSectionLoad(PetscSection s, PetscViewer viewer) 2217fde5e3acSksagiyam { 2218fde5e3acSksagiyam PetscBool ishdf5; 2219fde5e3acSksagiyam PetscErrorCode ierr; 2220fde5e3acSksagiyam 2221fde5e3acSksagiyam PetscFunctionBegin; 2222fde5e3acSksagiyam PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2223fde5e3acSksagiyam PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2); 2224fde5e3acSksagiyam ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERHDF5, &ishdf5);CHKERRQ(ierr); 2225fde5e3acSksagiyam if (ishdf5) { 2226fde5e3acSksagiyam #if PetscDefined(HAVE_HDF5) 2227fde5e3acSksagiyam ierr = PetscSectionLoad_HDF5_Internal(s, viewer);CHKERRQ(ierr); 2228fde5e3acSksagiyam PetscFunctionReturn(0); 2229fde5e3acSksagiyam #else 2230fde5e3acSksagiyam SETERRQ(PetscObjectComm((PetscObject) s), PETSC_ERR_SUP, "HDF5 not supported in this build.\nPlease reconfigure using --download-hdf5"); 2231fde5e3acSksagiyam #endif 223298921bdaSJacob Faibussowitsch } else SETERRQ(PetscObjectComm((PetscObject) s), PETSC_ERR_SUP, "Viewer type %s not yet supported for PetscSection loading", ((PetscObject)viewer)->type_name); 2233fde5e3acSksagiyam } 2234fde5e3acSksagiyam 2235c459fbc1SJed Brown static PetscErrorCode PetscSectionResetClosurePermutation(PetscSection section) 2236c459fbc1SJed Brown { 2237c459fbc1SJed Brown PetscErrorCode ierr; 2238c459fbc1SJed Brown PetscSectionClosurePermVal clVal; 2239c459fbc1SJed Brown 2240c459fbc1SJed Brown PetscFunctionBegin; 2241c459fbc1SJed Brown if (!section->clHash) PetscFunctionReturn(0); 2242c459fbc1SJed Brown kh_foreach_value(section->clHash, clVal, { 2243c459fbc1SJed Brown ierr = PetscFree(clVal.perm);CHKERRQ(ierr); 2244c459fbc1SJed Brown ierr = PetscFree(clVal.invPerm);CHKERRQ(ierr); 2245c459fbc1SJed Brown }); 2246c459fbc1SJed Brown kh_destroy(ClPerm, section->clHash); 2247c459fbc1SJed Brown section->clHash = NULL; 2248c459fbc1SJed Brown PetscFunctionReturn(0); 2249c459fbc1SJed Brown } 2250c459fbc1SJed Brown 2251ea844a1aSMatthew Knepley /*@ 2252ea844a1aSMatthew Knepley PetscSectionReset - Frees all section data. 2253ea844a1aSMatthew Knepley 2254ea844a1aSMatthew Knepley Not collective 2255ea844a1aSMatthew Knepley 2256ea844a1aSMatthew Knepley Input Parameters: 2257ea844a1aSMatthew Knepley . s - the PetscSection 2258ea844a1aSMatthew Knepley 2259ea844a1aSMatthew Knepley Level: beginner 2260ea844a1aSMatthew Knepley 2261ea844a1aSMatthew Knepley .seealso: PetscSection, PetscSectionCreate() 2262ea844a1aSMatthew Knepley @*/ 2263ea844a1aSMatthew Knepley PetscErrorCode PetscSectionReset(PetscSection s) 2264ea844a1aSMatthew Knepley { 2265b778fa18SValeria Barra PetscInt f, c; 2266ea844a1aSMatthew Knepley PetscErrorCode ierr; 2267ea844a1aSMatthew Knepley 2268ea844a1aSMatthew Knepley PetscFunctionBegin; 2269ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2270ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) { 2271ea844a1aSMatthew Knepley ierr = PetscSectionDestroy(&s->field[f]);CHKERRQ(ierr); 2272ea844a1aSMatthew Knepley ierr = PetscFree(s->fieldNames[f]);CHKERRQ(ierr); 2273b146d1acSSatish Balay for (c = 0; c < s->numFieldComponents[f]; ++c) { 2274b778fa18SValeria Barra ierr = PetscFree(s->compNames[f][c]);CHKERRQ(ierr); 2275b146d1acSSatish Balay } 2276b778fa18SValeria Barra ierr = PetscFree(s->compNames[f]);CHKERRQ(ierr); 2277ea844a1aSMatthew Knepley } 2278b778fa18SValeria Barra ierr = PetscFree(s->numFieldComponents);CHKERRQ(ierr); 2279ea844a1aSMatthew Knepley ierr = PetscFree(s->fieldNames);CHKERRQ(ierr); 2280b778fa18SValeria Barra ierr = PetscFree(s->compNames);CHKERRQ(ierr); 2281ea844a1aSMatthew Knepley ierr = PetscFree(s->field);CHKERRQ(ierr); 2282ea844a1aSMatthew Knepley ierr = PetscSectionDestroy(&s->bc);CHKERRQ(ierr); 2283ea844a1aSMatthew Knepley ierr = PetscFree(s->bcIndices);CHKERRQ(ierr); 2284ea844a1aSMatthew Knepley ierr = PetscFree2(s->atlasDof, s->atlasOff);CHKERRQ(ierr); 2285ea844a1aSMatthew Knepley ierr = PetscSectionDestroy(&s->clSection);CHKERRQ(ierr); 2286ea844a1aSMatthew Knepley ierr = ISDestroy(&s->clPoints);CHKERRQ(ierr); 2287ea844a1aSMatthew Knepley ierr = ISDestroy(&s->perm);CHKERRQ(ierr); 2288c459fbc1SJed Brown ierr = PetscSectionResetClosurePermutation(s);CHKERRQ(ierr); 2289ea844a1aSMatthew Knepley ierr = PetscSectionSymDestroy(&s->sym);CHKERRQ(ierr); 22903e03ebd8SStefano Zampini ierr = PetscSectionDestroy(&s->clSection);CHKERRQ(ierr); 22913e03ebd8SStefano Zampini ierr = ISDestroy(&s->clPoints);CHKERRQ(ierr); 2292ea844a1aSMatthew Knepley 2293ea844a1aSMatthew Knepley s->pStart = -1; 2294ea844a1aSMatthew Knepley s->pEnd = -1; 2295ea844a1aSMatthew Knepley s->maxDof = 0; 2296ea844a1aSMatthew Knepley s->setup = PETSC_FALSE; 2297ea844a1aSMatthew Knepley s->numFields = 0; 2298ea844a1aSMatthew Knepley s->clObj = NULL; 2299ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2300ea844a1aSMatthew Knepley } 2301ea844a1aSMatthew Knepley 2302ea844a1aSMatthew Knepley /*@ 2303ea844a1aSMatthew Knepley PetscSectionDestroy - Frees a section object and frees its range if that exists. 2304ea844a1aSMatthew Knepley 2305ea844a1aSMatthew Knepley Not collective 2306ea844a1aSMatthew Knepley 2307ea844a1aSMatthew Knepley Input Parameters: 2308ea844a1aSMatthew Knepley . s - the PetscSection 2309ea844a1aSMatthew Knepley 2310ea844a1aSMatthew Knepley Level: beginner 2311ea844a1aSMatthew Knepley 2312ea844a1aSMatthew Knepley .seealso: PetscSection, PetscSectionCreate() 2313ea844a1aSMatthew Knepley @*/ 2314ea844a1aSMatthew Knepley PetscErrorCode PetscSectionDestroy(PetscSection *s) 2315ea844a1aSMatthew Knepley { 2316ea844a1aSMatthew Knepley PetscErrorCode ierr; 2317ea844a1aSMatthew Knepley 2318ea844a1aSMatthew Knepley PetscFunctionBegin; 2319ea844a1aSMatthew Knepley if (!*s) PetscFunctionReturn(0); 232062f17a49SStefano Zampini PetscValidHeaderSpecific(*s,PETSC_SECTION_CLASSID,1); 2321ea844a1aSMatthew Knepley if (--((PetscObject)(*s))->refct > 0) { 2322ea844a1aSMatthew Knepley *s = NULL; 2323ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2324ea844a1aSMatthew Knepley } 2325ea844a1aSMatthew Knepley ierr = PetscSectionReset(*s);CHKERRQ(ierr); 2326ea844a1aSMatthew Knepley ierr = PetscHeaderDestroy(s);CHKERRQ(ierr); 2327ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2328ea844a1aSMatthew Knepley } 2329ea844a1aSMatthew Knepley 2330ea844a1aSMatthew Knepley PetscErrorCode VecIntGetValuesSection(PetscInt *baseArray, PetscSection s, PetscInt point, const PetscInt **values) 2331ea844a1aSMatthew Knepley { 2332ea844a1aSMatthew Knepley const PetscInt p = point - s->pStart; 2333ea844a1aSMatthew Knepley 2334ea844a1aSMatthew Knepley PetscFunctionBegin; 2335ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 2); 2336ea844a1aSMatthew Knepley *values = &baseArray[s->atlasOff[p]]; 2337ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2338ea844a1aSMatthew Knepley } 2339ea844a1aSMatthew Knepley 2340ea844a1aSMatthew Knepley PetscErrorCode VecIntSetValuesSection(PetscInt *baseArray, PetscSection s, PetscInt point, const PetscInt values[], InsertMode mode) 2341ea844a1aSMatthew Knepley { 2342ea844a1aSMatthew Knepley PetscInt *array; 2343ea844a1aSMatthew Knepley const PetscInt p = point - s->pStart; 2344ea844a1aSMatthew Knepley const PetscInt orientation = 0; /* Needs to be included for use in closure operations */ 2345ea844a1aSMatthew Knepley PetscInt cDim = 0; 2346ea844a1aSMatthew Knepley PetscErrorCode ierr; 2347ea844a1aSMatthew Knepley 2348ea844a1aSMatthew Knepley PetscFunctionBegin; 2349ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 2); 2350ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintDof(s, p, &cDim);CHKERRQ(ierr); 2351ea844a1aSMatthew Knepley array = &baseArray[s->atlasOff[p]]; 2352ea844a1aSMatthew Knepley if (!cDim) { 2353ea844a1aSMatthew Knepley if (orientation >= 0) { 2354ea844a1aSMatthew Knepley const PetscInt dim = s->atlasDof[p]; 2355ea844a1aSMatthew Knepley PetscInt i; 2356ea844a1aSMatthew Knepley 2357ea844a1aSMatthew Knepley if (mode == INSERT_VALUES) { 2358ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) array[i] = values[i]; 2359ea844a1aSMatthew Knepley } else { 2360ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) array[i] += values[i]; 2361ea844a1aSMatthew Knepley } 2362ea844a1aSMatthew Knepley } else { 2363ea844a1aSMatthew Knepley PetscInt offset = 0; 2364ea844a1aSMatthew Knepley PetscInt j = -1, field, i; 2365ea844a1aSMatthew Knepley 2366ea844a1aSMatthew Knepley for (field = 0; field < s->numFields; ++field) { 2367ea844a1aSMatthew Knepley const PetscInt dim = s->field[field]->atlasDof[p]; 2368ea844a1aSMatthew Knepley 2369ea844a1aSMatthew Knepley for (i = dim-1; i >= 0; --i) array[++j] = values[i+offset]; 2370ea844a1aSMatthew Knepley offset += dim; 2371ea844a1aSMatthew Knepley } 2372ea844a1aSMatthew Knepley } 2373ea844a1aSMatthew Knepley } else { 2374ea844a1aSMatthew Knepley if (orientation >= 0) { 2375ea844a1aSMatthew Knepley const PetscInt dim = s->atlasDof[p]; 2376ea844a1aSMatthew Knepley PetscInt cInd = 0, i; 2377ea844a1aSMatthew Knepley const PetscInt *cDof; 2378ea844a1aSMatthew Knepley 2379ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintIndices(s, point, &cDof);CHKERRQ(ierr); 2380ea844a1aSMatthew Knepley if (mode == INSERT_VALUES) { 2381ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) { 2382ea844a1aSMatthew Knepley if ((cInd < cDim) && (i == cDof[cInd])) {++cInd; continue;} 2383ea844a1aSMatthew Knepley array[i] = values[i]; 2384ea844a1aSMatthew Knepley } 2385ea844a1aSMatthew Knepley } else { 2386ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) { 2387ea844a1aSMatthew Knepley if ((cInd < cDim) && (i == cDof[cInd])) {++cInd; continue;} 2388ea844a1aSMatthew Knepley array[i] += values[i]; 2389ea844a1aSMatthew Knepley } 2390ea844a1aSMatthew Knepley } 2391ea844a1aSMatthew Knepley } else { 2392ea844a1aSMatthew Knepley const PetscInt *cDof; 2393ea844a1aSMatthew Knepley PetscInt offset = 0; 2394ea844a1aSMatthew Knepley PetscInt cOffset = 0; 2395ea844a1aSMatthew Knepley PetscInt j = 0, field; 2396ea844a1aSMatthew Knepley 2397ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintIndices(s, point, &cDof);CHKERRQ(ierr); 2398ea844a1aSMatthew Knepley for (field = 0; field < s->numFields; ++field) { 2399ea844a1aSMatthew Knepley const PetscInt dim = s->field[field]->atlasDof[p]; /* PetscSectionGetFieldDof() */ 2400ea844a1aSMatthew Knepley const PetscInt tDim = s->field[field]->bc->atlasDof[p]; /* PetscSectionGetFieldConstraintDof() */ 2401ea844a1aSMatthew Knepley const PetscInt sDim = dim - tDim; 2402ea844a1aSMatthew Knepley PetscInt cInd = 0, i,k; 2403ea844a1aSMatthew Knepley 2404ea844a1aSMatthew Knepley for (i = 0, k = dim+offset-1; i < dim; ++i, ++j, --k) { 2405ea844a1aSMatthew Knepley if ((cInd < sDim) && (j == cDof[cInd+cOffset])) {++cInd; continue;} 2406ea844a1aSMatthew Knepley array[j] = values[k]; 2407ea844a1aSMatthew Knepley } 2408ea844a1aSMatthew Knepley offset += dim; 2409ea844a1aSMatthew Knepley cOffset += dim - tDim; 2410ea844a1aSMatthew Knepley } 2411ea844a1aSMatthew Knepley } 2412ea844a1aSMatthew Knepley } 2413ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2414ea844a1aSMatthew Knepley } 2415ea844a1aSMatthew Knepley 2416ea844a1aSMatthew Knepley /*@C 2417ea844a1aSMatthew Knepley PetscSectionHasConstraints - Determine whether a section has constrained dofs 2418ea844a1aSMatthew Knepley 2419ea844a1aSMatthew Knepley Not collective 2420ea844a1aSMatthew Knepley 2421ea844a1aSMatthew Knepley Input Parameter: 2422ea844a1aSMatthew Knepley . s - The PetscSection 2423ea844a1aSMatthew Knepley 2424ea844a1aSMatthew Knepley Output Parameter: 2425ea844a1aSMatthew Knepley . hasConstraints - flag indicating that the section has constrained dofs 2426ea844a1aSMatthew Knepley 2427ea844a1aSMatthew Knepley Level: intermediate 2428ea844a1aSMatthew Knepley 2429ea844a1aSMatthew Knepley .seealso: PetscSectionSetConstraintIndices(), PetscSectionGetConstraintDof(), PetscSection 2430ea844a1aSMatthew Knepley @*/ 2431ea844a1aSMatthew Knepley PetscErrorCode PetscSectionHasConstraints(PetscSection s, PetscBool *hasConstraints) 2432ea844a1aSMatthew Knepley { 2433ea844a1aSMatthew Knepley PetscFunctionBegin; 2434ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2435ea844a1aSMatthew Knepley PetscValidPointer(hasConstraints, 2); 2436ea844a1aSMatthew Knepley *hasConstraints = s->bc ? PETSC_TRUE : PETSC_FALSE; 2437ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2438ea844a1aSMatthew Knepley } 2439ea844a1aSMatthew Knepley 2440ea844a1aSMatthew Knepley /*@C 2441ea844a1aSMatthew Knepley PetscSectionGetConstraintIndices - Get the point dof numbers, in [0, dof), which are constrained 2442ea844a1aSMatthew Knepley 2443ea844a1aSMatthew Knepley Not collective 2444ea844a1aSMatthew Knepley 2445ea844a1aSMatthew Knepley Input Parameters: 2446ea844a1aSMatthew Knepley + s - The PetscSection 2447ea844a1aSMatthew Knepley - point - The point 2448ea844a1aSMatthew Knepley 2449ea844a1aSMatthew Knepley Output Parameter: 2450ea844a1aSMatthew Knepley . indices - The constrained dofs 2451ea844a1aSMatthew Knepley 2452ea844a1aSMatthew Knepley Note: In Fortran, you call PetscSectionGetConstraintIndicesF90() and PetscSectionRestoreConstraintIndicesF90() 2453ea844a1aSMatthew Knepley 2454ea844a1aSMatthew Knepley Level: intermediate 2455ea844a1aSMatthew Knepley 2456ea844a1aSMatthew Knepley .seealso: PetscSectionSetConstraintIndices(), PetscSectionGetConstraintDof(), PetscSection 2457ea844a1aSMatthew Knepley @*/ 2458ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetConstraintIndices(PetscSection s, PetscInt point, const PetscInt **indices) 2459ea844a1aSMatthew Knepley { 2460ea844a1aSMatthew Knepley PetscErrorCode ierr; 2461ea844a1aSMatthew Knepley 2462ea844a1aSMatthew Knepley PetscFunctionBegin; 2463ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2464ea844a1aSMatthew Knepley if (s->bc) { 2465ea844a1aSMatthew Knepley ierr = VecIntGetValuesSection(s->bcIndices, s->bc, point, indices);CHKERRQ(ierr); 2466ea844a1aSMatthew Knepley } else *indices = NULL; 2467ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2468ea844a1aSMatthew Knepley } 2469ea844a1aSMatthew Knepley 2470ea844a1aSMatthew Knepley /*@C 2471ea844a1aSMatthew Knepley PetscSectionSetConstraintIndices - Set the point dof numbers, in [0, dof), which are constrained 2472ea844a1aSMatthew Knepley 2473ea844a1aSMatthew Knepley Not collective 2474ea844a1aSMatthew Knepley 2475ea844a1aSMatthew Knepley Input Parameters: 2476ea844a1aSMatthew Knepley + s - The PetscSection 2477ea844a1aSMatthew Knepley . point - The point 2478ea844a1aSMatthew Knepley - indices - The constrained dofs 2479ea844a1aSMatthew Knepley 2480ea844a1aSMatthew Knepley Note: The Fortran is PetscSectionSetConstraintIndicesF90() 2481ea844a1aSMatthew Knepley 2482ea844a1aSMatthew Knepley Level: intermediate 2483ea844a1aSMatthew Knepley 2484ea844a1aSMatthew Knepley .seealso: PetscSectionGetConstraintIndices(), PetscSectionGetConstraintDof(), PetscSection 2485ea844a1aSMatthew Knepley @*/ 2486ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetConstraintIndices(PetscSection s, PetscInt point, const PetscInt indices[]) 2487ea844a1aSMatthew Knepley { 2488ea844a1aSMatthew Knepley PetscErrorCode ierr; 2489ea844a1aSMatthew Knepley 2490ea844a1aSMatthew Knepley PetscFunctionBegin; 2491ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 2492ea844a1aSMatthew Knepley if (s->bc) { 2493d57bb9dbSMatthew G. Knepley const PetscInt dof = s->atlasDof[point]; 2494d57bb9dbSMatthew G. Knepley const PetscInt cdof = s->bc->atlasDof[point]; 2495d57bb9dbSMatthew G. Knepley PetscInt d; 2496d57bb9dbSMatthew G. Knepley 2497d57bb9dbSMatthew G. Knepley for (d = 0; d < cdof; ++d) { 2498e2bfaee7SMatthew G. Knepley 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]); 2499d57bb9dbSMatthew G. Knepley } 2500ea844a1aSMatthew Knepley ierr = VecIntSetValuesSection(s->bcIndices, s->bc, point, indices, INSERT_VALUES);CHKERRQ(ierr); 2501ea844a1aSMatthew Knepley } 2502ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2503ea844a1aSMatthew Knepley } 2504ea844a1aSMatthew Knepley 2505ea844a1aSMatthew Knepley /*@C 2506ea844a1aSMatthew Knepley PetscSectionGetFieldConstraintIndices - Get the field dof numbers, in [0, fdof), which are constrained 2507ea844a1aSMatthew Knepley 2508ea844a1aSMatthew Knepley Not collective 2509ea844a1aSMatthew Knepley 2510ea844a1aSMatthew Knepley Input Parameters: 2511ea844a1aSMatthew Knepley + s - The PetscSection 2512ea844a1aSMatthew Knepley . field - The field number 2513ea844a1aSMatthew Knepley - point - The point 2514ea844a1aSMatthew Knepley 2515ea844a1aSMatthew Knepley Output Parameter: 25169759eb26SJed Brown . indices - The constrained dofs sorted in ascending order 2517ea844a1aSMatthew Knepley 25189759eb26SJed Brown Notes: 25199759eb26SJed 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(). 25209759eb26SJed Brown 25219759eb26SJed Brown Fortran Note: 25229759eb26SJed Brown In Fortran, you call PetscSectionGetFieldConstraintIndicesF90() and PetscSectionRestoreFieldConstraintIndicesF90() 2523ea844a1aSMatthew Knepley 2524ea844a1aSMatthew Knepley Level: intermediate 2525ea844a1aSMatthew Knepley 2526ea844a1aSMatthew Knepley .seealso: PetscSectionSetFieldConstraintIndices(), PetscSectionGetConstraintIndices(), PetscSectionGetConstraintDof(), PetscSection 2527ea844a1aSMatthew Knepley @*/ 2528ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetFieldConstraintIndices(PetscSection s, PetscInt point, PetscInt field, const PetscInt **indices) 2529ea844a1aSMatthew Knepley { 2530ea844a1aSMatthew Knepley PetscErrorCode ierr; 2531ea844a1aSMatthew Knepley 2532ea844a1aSMatthew Knepley PetscFunctionBegin; 2533ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 25342abc8c78SJacob Faibussowitsch PetscValidIntPointer(indices,4); 25352abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field,s->numFields); 2536ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintIndices(s->field[field], point, indices);CHKERRQ(ierr); 2537ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2538ea844a1aSMatthew Knepley } 2539ea844a1aSMatthew Knepley 2540ea844a1aSMatthew Knepley /*@C 2541ea844a1aSMatthew Knepley PetscSectionSetFieldConstraintIndices - Set the field dof numbers, in [0, fdof), which are constrained 2542ea844a1aSMatthew Knepley 2543ea844a1aSMatthew Knepley Not collective 2544ea844a1aSMatthew Knepley 2545ea844a1aSMatthew Knepley Input Parameters: 2546ea844a1aSMatthew Knepley + s - The PetscSection 2547ea844a1aSMatthew Knepley . point - The point 2548ea844a1aSMatthew Knepley . field - The field number 2549ea844a1aSMatthew Knepley - indices - The constrained dofs 2550ea844a1aSMatthew Knepley 2551ea844a1aSMatthew Knepley Note: The Fortran is PetscSectionSetFieldConstraintIndicesF90() 2552ea844a1aSMatthew Knepley 2553ea844a1aSMatthew Knepley Level: intermediate 2554ea844a1aSMatthew Knepley 2555ea844a1aSMatthew Knepley .seealso: PetscSectionSetConstraintIndices(), PetscSectionGetFieldConstraintIndices(), PetscSectionGetConstraintDof(), PetscSection 2556ea844a1aSMatthew Knepley @*/ 2557ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetFieldConstraintIndices(PetscSection s, PetscInt point, PetscInt field, const PetscInt indices[]) 2558ea844a1aSMatthew Knepley { 2559ea844a1aSMatthew Knepley PetscErrorCode ierr; 2560ea844a1aSMatthew Knepley 2561ea844a1aSMatthew Knepley PetscFunctionBegin; 2562ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 25632abc8c78SJacob Faibussowitsch if (PetscDefined(USE_DEBUG)) { 2564e2bfaee7SMatthew G. Knepley PetscInt nfdof; 25652abc8c78SJacob Faibussowitsch 2566e2bfaee7SMatthew G. Knepley ierr = PetscSectionGetFieldConstraintDof(s, point, field, &nfdof);CHKERRQ(ierr); 2567e2bfaee7SMatthew G. Knepley if (nfdof) PetscValidIntPointer(indices, 4); 25682abc8c78SJacob Faibussowitsch } 25692abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field,s->numFields); 2570ea844a1aSMatthew Knepley ierr = PetscSectionSetConstraintIndices(s->field[field], point, indices);CHKERRQ(ierr); 2571ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2572ea844a1aSMatthew Knepley } 2573ea844a1aSMatthew Knepley 2574ea844a1aSMatthew Knepley /*@ 2575ea844a1aSMatthew Knepley PetscSectionPermute - Reorder the section according to the input point permutation 2576ea844a1aSMatthew Knepley 2577ea844a1aSMatthew Knepley Collective on PetscSection 2578ea844a1aSMatthew Knepley 2579d8d19677SJose E. Roman Input Parameters: 2580ea844a1aSMatthew Knepley + section - The PetscSection object 2581ea844a1aSMatthew Knepley - perm - The point permutation, old point p becomes new point perm[p] 2582ea844a1aSMatthew Knepley 2583ea844a1aSMatthew Knepley Output Parameter: 2584ea844a1aSMatthew Knepley . sectionNew - The permuted PetscSection 2585ea844a1aSMatthew Knepley 2586ea844a1aSMatthew Knepley Level: intermediate 2587ea844a1aSMatthew Knepley 2588ea844a1aSMatthew Knepley .seealso: MatPermute() 2589ea844a1aSMatthew Knepley @*/ 2590ea844a1aSMatthew Knepley PetscErrorCode PetscSectionPermute(PetscSection section, IS permutation, PetscSection *sectionNew) 2591ea844a1aSMatthew Knepley { 2592ea844a1aSMatthew Knepley PetscSection s = section, sNew; 2593ea844a1aSMatthew Knepley const PetscInt *perm; 2594b778fa18SValeria Barra PetscInt numFields, f, c, numPoints, pStart, pEnd, p; 2595ea844a1aSMatthew Knepley PetscErrorCode ierr; 2596ea844a1aSMatthew Knepley 2597ea844a1aSMatthew Knepley PetscFunctionBegin; 2598ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1); 2599ea844a1aSMatthew Knepley PetscValidHeaderSpecific(permutation, IS_CLASSID, 2); 2600ea844a1aSMatthew Knepley PetscValidPointer(sectionNew, 3); 2601ea844a1aSMatthew Knepley ierr = PetscSectionCreate(PetscObjectComm((PetscObject) s), &sNew);CHKERRQ(ierr); 2602ea844a1aSMatthew Knepley ierr = PetscSectionGetNumFields(s, &numFields);CHKERRQ(ierr); 2603ea844a1aSMatthew Knepley if (numFields) {ierr = PetscSectionSetNumFields(sNew, numFields);CHKERRQ(ierr);} 2604ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 2605ea844a1aSMatthew Knepley const char *name; 2606ea844a1aSMatthew Knepley PetscInt numComp; 2607ea844a1aSMatthew Knepley 2608ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldName(s, f, &name);CHKERRQ(ierr); 2609ea844a1aSMatthew Knepley ierr = PetscSectionSetFieldName(sNew, f, name);CHKERRQ(ierr); 2610ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldComponents(s, f, &numComp);CHKERRQ(ierr); 2611ea844a1aSMatthew Knepley ierr = PetscSectionSetFieldComponents(sNew, f, numComp);CHKERRQ(ierr); 2612b778fa18SValeria Barra for (c = 0; c < s->numFieldComponents[f]; ++c) { 2613b778fa18SValeria Barra ierr = PetscSectionGetComponentName(s, f, c, &name);CHKERRQ(ierr); 2614b778fa18SValeria Barra ierr = PetscSectionSetComponentName(sNew, f, c, name);CHKERRQ(ierr); 2615b778fa18SValeria Barra } 2616ea844a1aSMatthew Knepley } 2617ea844a1aSMatthew Knepley ierr = ISGetLocalSize(permutation, &numPoints);CHKERRQ(ierr); 2618ea844a1aSMatthew Knepley ierr = ISGetIndices(permutation, &perm);CHKERRQ(ierr); 2619ea844a1aSMatthew Knepley ierr = PetscSectionGetChart(s, &pStart, &pEnd);CHKERRQ(ierr); 2620ea844a1aSMatthew Knepley ierr = PetscSectionSetChart(sNew, pStart, pEnd);CHKERRQ(ierr); 26212c71b3e2SJacob Faibussowitsch PetscCheckFalse(numPoints < pEnd,PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Permutation size %" PetscInt_FMT " is less than largest Section point %" PetscInt_FMT, numPoints, pEnd); 2622ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2623ea844a1aSMatthew Knepley PetscInt dof, cdof; 2624ea844a1aSMatthew Knepley 2625ea844a1aSMatthew Knepley ierr = PetscSectionGetDof(s, p, &dof);CHKERRQ(ierr); 2626ea844a1aSMatthew Knepley ierr = PetscSectionSetDof(sNew, perm[p], dof);CHKERRQ(ierr); 2627ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintDof(s, p, &cdof);CHKERRQ(ierr); 2628ea844a1aSMatthew Knepley if (cdof) {ierr = PetscSectionSetConstraintDof(sNew, perm[p], cdof);CHKERRQ(ierr);} 2629ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 2630ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldDof(s, p, f, &dof);CHKERRQ(ierr); 2631ea844a1aSMatthew Knepley ierr = PetscSectionSetFieldDof(sNew, perm[p], f, dof);CHKERRQ(ierr); 2632ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldConstraintDof(s, p, f, &cdof);CHKERRQ(ierr); 2633ea844a1aSMatthew Knepley if (cdof) {ierr = PetscSectionSetFieldConstraintDof(sNew, perm[p], f, cdof);CHKERRQ(ierr);} 2634ea844a1aSMatthew Knepley } 2635ea844a1aSMatthew Knepley } 2636ea844a1aSMatthew Knepley ierr = PetscSectionSetUp(sNew);CHKERRQ(ierr); 2637ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) { 2638ea844a1aSMatthew Knepley const PetscInt *cind; 2639ea844a1aSMatthew Knepley PetscInt cdof; 2640ea844a1aSMatthew Knepley 2641ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintDof(s, p, &cdof);CHKERRQ(ierr); 2642ea844a1aSMatthew Knepley if (cdof) { 2643ea844a1aSMatthew Knepley ierr = PetscSectionGetConstraintIndices(s, p, &cind);CHKERRQ(ierr); 2644ea844a1aSMatthew Knepley ierr = PetscSectionSetConstraintIndices(sNew, perm[p], cind);CHKERRQ(ierr); 2645ea844a1aSMatthew Knepley } 2646ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) { 2647ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldConstraintDof(s, p, f, &cdof);CHKERRQ(ierr); 2648ea844a1aSMatthew Knepley if (cdof) { 2649ea844a1aSMatthew Knepley ierr = PetscSectionGetFieldConstraintIndices(s, p, f, &cind);CHKERRQ(ierr); 2650ea844a1aSMatthew Knepley ierr = PetscSectionSetFieldConstraintIndices(sNew, perm[p], f, cind);CHKERRQ(ierr); 2651ea844a1aSMatthew Knepley } 2652ea844a1aSMatthew Knepley } 2653ea844a1aSMatthew Knepley } 2654ea844a1aSMatthew Knepley ierr = ISRestoreIndices(permutation, &perm);CHKERRQ(ierr); 2655ea844a1aSMatthew Knepley *sectionNew = sNew; 2656ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2657ea844a1aSMatthew Knepley } 2658ea844a1aSMatthew Knepley 2659ea844a1aSMatthew Knepley /*@ 2660ea844a1aSMatthew Knepley PetscSectionSetClosureIndex - Set a cache of points in the closure of each point in the section 2661ea844a1aSMatthew Knepley 2662ea844a1aSMatthew Knepley Collective on section 2663ea844a1aSMatthew Knepley 2664ea844a1aSMatthew Knepley Input Parameters: 2665ea844a1aSMatthew Knepley + section - The PetscSection 2666ea844a1aSMatthew Knepley . obj - A PetscObject which serves as the key for this index 2667ea844a1aSMatthew Knepley . clSection - Section giving the size of the closure of each point 2668ea844a1aSMatthew Knepley - clPoints - IS giving the points in each closure 2669ea844a1aSMatthew Knepley 2670ea844a1aSMatthew Knepley Note: We compress out closure points with no dofs in this section 2671ea844a1aSMatthew Knepley 2672ea844a1aSMatthew Knepley Level: advanced 2673ea844a1aSMatthew Knepley 2674ea844a1aSMatthew Knepley .seealso: PetscSectionGetClosureIndex(), DMPlexCreateClosureIndex() 2675ea844a1aSMatthew Knepley @*/ 2676ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetClosureIndex(PetscSection section, PetscObject obj, PetscSection clSection, IS clPoints) 2677ea844a1aSMatthew Knepley { 2678ea844a1aSMatthew Knepley PetscErrorCode ierr; 2679ea844a1aSMatthew Knepley 2680ea844a1aSMatthew Knepley PetscFunctionBegin; 26813e03ebd8SStefano Zampini PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,1); 26823e03ebd8SStefano Zampini PetscValidHeaderSpecific(clSection,PETSC_SECTION_CLASSID,3); 26833e03ebd8SStefano Zampini PetscValidHeaderSpecific(clPoints,IS_CLASSID,4); 2684c459fbc1SJed Brown if (section->clObj != obj) {ierr = PetscSectionResetClosurePermutation(section);CHKERRQ(ierr);} 2685ea844a1aSMatthew Knepley section->clObj = obj; 26863e03ebd8SStefano Zampini ierr = PetscObjectReference((PetscObject)clSection);CHKERRQ(ierr); 26873e03ebd8SStefano Zampini ierr = PetscObjectReference((PetscObject)clPoints);CHKERRQ(ierr); 2688ea844a1aSMatthew Knepley ierr = PetscSectionDestroy(§ion->clSection);CHKERRQ(ierr); 2689ea844a1aSMatthew Knepley ierr = ISDestroy(§ion->clPoints);CHKERRQ(ierr); 2690ea844a1aSMatthew Knepley section->clSection = clSection; 2691ea844a1aSMatthew Knepley section->clPoints = clPoints; 2692ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2693ea844a1aSMatthew Knepley } 2694ea844a1aSMatthew Knepley 2695ea844a1aSMatthew Knepley /*@ 2696ea844a1aSMatthew Knepley PetscSectionGetClosureIndex - Get the cache of points in the closure of each point in the section 2697ea844a1aSMatthew Knepley 2698ea844a1aSMatthew Knepley Collective on section 2699ea844a1aSMatthew Knepley 2700ea844a1aSMatthew Knepley Input Parameters: 2701ea844a1aSMatthew Knepley + section - The PetscSection 2702ea844a1aSMatthew Knepley - obj - A PetscObject which serves as the key for this index 2703ea844a1aSMatthew Knepley 2704ea844a1aSMatthew Knepley Output Parameters: 2705ea844a1aSMatthew Knepley + clSection - Section giving the size of the closure of each point 2706ea844a1aSMatthew Knepley - clPoints - IS giving the points in each closure 2707ea844a1aSMatthew Knepley 2708ea844a1aSMatthew Knepley Note: We compress out closure points with no dofs in this section 2709ea844a1aSMatthew Knepley 2710ea844a1aSMatthew Knepley Level: advanced 2711ea844a1aSMatthew Knepley 2712ea844a1aSMatthew Knepley .seealso: PetscSectionSetClosureIndex(), DMPlexCreateClosureIndex() 2713ea844a1aSMatthew Knepley @*/ 2714ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetClosureIndex(PetscSection section, PetscObject obj, PetscSection *clSection, IS *clPoints) 2715ea844a1aSMatthew Knepley { 2716ea844a1aSMatthew Knepley PetscFunctionBegin; 2717ea844a1aSMatthew Knepley if (section->clObj == obj) { 2718ea844a1aSMatthew Knepley if (clSection) *clSection = section->clSection; 2719ea844a1aSMatthew Knepley if (clPoints) *clPoints = section->clPoints; 2720ea844a1aSMatthew Knepley } else { 2721ea844a1aSMatthew Knepley if (clSection) *clSection = NULL; 2722ea844a1aSMatthew Knepley if (clPoints) *clPoints = NULL; 2723ea844a1aSMatthew Knepley } 2724ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2725ea844a1aSMatthew Knepley } 2726ea844a1aSMatthew Knepley 2727c459fbc1SJed Brown PetscErrorCode PetscSectionSetClosurePermutation_Internal(PetscSection section, PetscObject obj, PetscInt depth, PetscInt clSize, PetscCopyMode mode, PetscInt *clPerm) 2728ea844a1aSMatthew Knepley { 2729ea844a1aSMatthew Knepley PetscInt i; 2730c459fbc1SJed Brown khiter_t iter; 2731c459fbc1SJed Brown int new_entry; 2732c459fbc1SJed Brown PetscSectionClosurePermKey key = {depth, clSize}; 2733c459fbc1SJed Brown PetscSectionClosurePermVal *val; 2734ea844a1aSMatthew Knepley PetscErrorCode ierr; 2735ea844a1aSMatthew Knepley 2736ea844a1aSMatthew Knepley PetscFunctionBegin; 2737ea844a1aSMatthew Knepley if (section->clObj != obj) { 2738ea844a1aSMatthew Knepley ierr = PetscSectionDestroy(§ion->clSection);CHKERRQ(ierr); 2739ea844a1aSMatthew Knepley ierr = ISDestroy(§ion->clPoints);CHKERRQ(ierr); 2740ea844a1aSMatthew Knepley } 2741ea844a1aSMatthew Knepley section->clObj = obj; 2742c459fbc1SJed Brown if (!section->clHash) {ierr = PetscClPermCreate(§ion->clHash);CHKERRQ(ierr);} 2743c459fbc1SJed Brown iter = kh_put(ClPerm, section->clHash, key, &new_entry); 2744c459fbc1SJed Brown val = &kh_val(section->clHash, iter); 2745c459fbc1SJed Brown if (!new_entry) { 2746c459fbc1SJed Brown ierr = PetscFree(val->perm);CHKERRQ(ierr); 2747c459fbc1SJed Brown ierr = PetscFree(val->invPerm);CHKERRQ(ierr); 2748c459fbc1SJed Brown } 2749ea844a1aSMatthew Knepley if (mode == PETSC_COPY_VALUES) { 2750c459fbc1SJed Brown ierr = PetscMalloc1(clSize, &val->perm);CHKERRQ(ierr); 2751ea844a1aSMatthew Knepley ierr = PetscLogObjectMemory((PetscObject) obj, clSize*sizeof(PetscInt));CHKERRQ(ierr); 2752c459fbc1SJed Brown ierr = PetscArraycpy(val->perm, clPerm, clSize);CHKERRQ(ierr); 2753ea844a1aSMatthew Knepley } else if (mode == PETSC_OWN_POINTER) { 2754c459fbc1SJed Brown val->perm = clPerm; 2755ea844a1aSMatthew Knepley } else SETERRQ(PetscObjectComm(obj), PETSC_ERR_SUP, "Do not support borrowed arrays"); 2756c459fbc1SJed Brown ierr = PetscMalloc1(clSize, &val->invPerm);CHKERRQ(ierr); 2757c459fbc1SJed Brown for (i = 0; i < clSize; ++i) val->invPerm[clPerm[i]] = i; 2758ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2759ea844a1aSMatthew Knepley } 2760ea844a1aSMatthew Knepley 2761ea844a1aSMatthew Knepley /*@ 2762c459fbc1SJed Brown PetscSectionSetClosurePermutation - Set the dof permutation for the closure of each cell in the section, meaning clPerm[newIndex] = oldIndex. 2763ea844a1aSMatthew Knepley 2764ea844a1aSMatthew Knepley Not Collective 2765ea844a1aSMatthew Knepley 2766ea844a1aSMatthew Knepley Input Parameters: 2767ea844a1aSMatthew Knepley + section - The PetscSection 2768c459fbc1SJed Brown . obj - A PetscObject which serves as the key for this index (usually a DM) 2769c459fbc1SJed Brown . depth - Depth of points on which to apply the given permutation 2770ea844a1aSMatthew Knepley - perm - Permutation of the cell dof closure 2771ea844a1aSMatthew Knepley 2772c459fbc1SJed Brown Note: 2773c459fbc1SJed Brown The specified permutation will only be applied to points at depth whose closure size matches the length of perm. In a 2774c459fbc1SJed Brown mixed-topology or variable-degree finite element space, this function can be called multiple times at each depth for 2775c459fbc1SJed Brown each topology and degree. 2776c459fbc1SJed Brown 2777c459fbc1SJed Brown This approach assumes that (depth, len(perm)) uniquely identifies the desired permutation; this might not be true for 2778c459fbc1SJed Brown exotic/enriched spaces on mixed topology meshes. 2779ea844a1aSMatthew Knepley 2780ea844a1aSMatthew Knepley Level: intermediate 2781ea844a1aSMatthew Knepley 2782ea844a1aSMatthew Knepley .seealso: PetscSectionGetClosurePermutation(), PetscSectionGetClosureIndex(), DMPlexCreateClosureIndex(), PetscCopyMode 2783ea844a1aSMatthew Knepley @*/ 2784c459fbc1SJed Brown PetscErrorCode PetscSectionSetClosurePermutation(PetscSection section, PetscObject obj, PetscInt depth, IS perm) 2785ea844a1aSMatthew Knepley { 2786ea844a1aSMatthew Knepley const PetscInt *clPerm = NULL; 2787ea844a1aSMatthew Knepley PetscInt clSize = 0; 2788ea844a1aSMatthew Knepley PetscErrorCode ierr; 2789ea844a1aSMatthew Knepley 2790ea844a1aSMatthew Knepley PetscFunctionBegin; 2791ea844a1aSMatthew Knepley if (perm) { 2792ea844a1aSMatthew Knepley ierr = ISGetLocalSize(perm, &clSize);CHKERRQ(ierr); 2793ea844a1aSMatthew Knepley ierr = ISGetIndices(perm, &clPerm);CHKERRQ(ierr); 2794ea844a1aSMatthew Knepley } 2795c459fbc1SJed Brown ierr = PetscSectionSetClosurePermutation_Internal(section, obj, depth, clSize, PETSC_COPY_VALUES, (PetscInt *) clPerm);CHKERRQ(ierr); 2796ea844a1aSMatthew Knepley if (perm) {ierr = ISRestoreIndices(perm, &clPerm);CHKERRQ(ierr);} 2797ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2798ea844a1aSMatthew Knepley } 2799ea844a1aSMatthew Knepley 2800c459fbc1SJed Brown PetscErrorCode PetscSectionGetClosurePermutation_Internal(PetscSection section, PetscObject obj, PetscInt depth, PetscInt size, const PetscInt *perm[]) 2801ea844a1aSMatthew Knepley { 2802c459fbc1SJed Brown PetscErrorCode ierr; 2803c459fbc1SJed Brown 2804ea844a1aSMatthew Knepley PetscFunctionBegin; 2805ea844a1aSMatthew Knepley if (section->clObj == obj) { 2806c459fbc1SJed Brown PetscSectionClosurePermKey k = {depth, size}; 2807c459fbc1SJed Brown PetscSectionClosurePermVal v; 2808c459fbc1SJed Brown ierr = PetscClPermGet(section->clHash, k, &v);CHKERRQ(ierr); 2809c459fbc1SJed Brown if (perm) *perm = v.perm; 2810ea844a1aSMatthew Knepley } else { 2811ea844a1aSMatthew Knepley if (perm) *perm = NULL; 2812ea844a1aSMatthew Knepley } 2813ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2814ea844a1aSMatthew Knepley } 2815ea844a1aSMatthew Knepley 2816ea844a1aSMatthew Knepley /*@ 2817ea844a1aSMatthew Knepley PetscSectionGetClosurePermutation - Get the dof permutation for the closure of each cell in the section, meaning clPerm[newIndex] = oldIndex. 2818ea844a1aSMatthew Knepley 2819ea844a1aSMatthew Knepley Not collective 2820ea844a1aSMatthew Knepley 2821ea844a1aSMatthew Knepley Input Parameters: 2822ea844a1aSMatthew Knepley + section - The PetscSection 2823c459fbc1SJed Brown . obj - A PetscObject which serves as the key for this index (usually a DM) 2824c459fbc1SJed Brown . depth - Depth stratum on which to obtain closure permutation 2825c459fbc1SJed Brown - clSize - Closure size to be permuted (e.g., may vary with element topology and degree) 2826ea844a1aSMatthew Knepley 2827ea844a1aSMatthew Knepley Output Parameter: 2828ea844a1aSMatthew Knepley . perm - The dof closure permutation 2829ea844a1aSMatthew Knepley 2830c459fbc1SJed Brown Note: 2831ea844a1aSMatthew Knepley The user must destroy the IS that is returned. 2832ea844a1aSMatthew Knepley 2833ea844a1aSMatthew Knepley Level: intermediate 2834ea844a1aSMatthew Knepley 2835ea844a1aSMatthew Knepley .seealso: PetscSectionSetClosurePermutation(), PetscSectionGetClosureInversePermutation(), PetscSectionGetClosureIndex(), PetscSectionSetClosureIndex(), DMPlexCreateClosureIndex() 2836ea844a1aSMatthew Knepley @*/ 2837c459fbc1SJed Brown PetscErrorCode PetscSectionGetClosurePermutation(PetscSection section, PetscObject obj, PetscInt depth, PetscInt clSize, IS *perm) 2838ea844a1aSMatthew Knepley { 2839ea844a1aSMatthew Knepley const PetscInt *clPerm; 2840ea844a1aSMatthew Knepley PetscErrorCode ierr; 2841ea844a1aSMatthew Knepley 2842ea844a1aSMatthew Knepley PetscFunctionBegin; 2843c459fbc1SJed Brown ierr = PetscSectionGetClosurePermutation_Internal(section, obj, depth, clSize, &clPerm);CHKERRQ(ierr); 2844ea844a1aSMatthew Knepley ierr = ISCreateGeneral(PETSC_COMM_SELF, clSize, clPerm, PETSC_USE_POINTER, perm);CHKERRQ(ierr); 2845ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2846ea844a1aSMatthew Knepley } 2847ea844a1aSMatthew Knepley 2848c459fbc1SJed Brown PetscErrorCode PetscSectionGetClosureInversePermutation_Internal(PetscSection section, PetscObject obj, PetscInt depth, PetscInt size, const PetscInt *perm[]) 2849ea844a1aSMatthew Knepley { 2850c459fbc1SJed Brown PetscErrorCode ierr; 2851c459fbc1SJed Brown 2852ea844a1aSMatthew Knepley PetscFunctionBegin; 2853c459fbc1SJed Brown if (section->clObj == obj && section->clHash) { 2854c459fbc1SJed Brown PetscSectionClosurePermKey k = {depth, size}; 2855c459fbc1SJed Brown PetscSectionClosurePermVal v; 2856c459fbc1SJed Brown ierr = PetscClPermGet(section->clHash, k, &v);CHKERRQ(ierr); 2857c459fbc1SJed Brown if (perm) *perm = v.invPerm; 2858ea844a1aSMatthew Knepley } else { 2859ea844a1aSMatthew Knepley if (perm) *perm = NULL; 2860ea844a1aSMatthew Knepley } 2861ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2862ea844a1aSMatthew Knepley } 2863ea844a1aSMatthew Knepley 2864ea844a1aSMatthew Knepley /*@ 2865ea844a1aSMatthew Knepley PetscSectionGetClosureInversePermutation - Get the inverse dof permutation for the closure of each cell in the section, meaning clPerm[oldIndex] = newIndex. 2866ea844a1aSMatthew Knepley 2867ea844a1aSMatthew Knepley Not collective 2868ea844a1aSMatthew Knepley 2869ea844a1aSMatthew Knepley Input Parameters: 2870ea844a1aSMatthew Knepley + section - The PetscSection 2871c459fbc1SJed Brown . obj - A PetscObject which serves as the key for this index (usually a DM) 2872c459fbc1SJed Brown . depth - Depth stratum on which to obtain closure permutation 2873c459fbc1SJed Brown - clSize - Closure size to be permuted (e.g., may vary with element topology and degree) 2874ea844a1aSMatthew Knepley 2875ea844a1aSMatthew Knepley Output Parameters: 2876c459fbc1SJed Brown . perm - The dof closure permutation 2877ea844a1aSMatthew Knepley 2878c459fbc1SJed Brown Note: 2879ea844a1aSMatthew Knepley The user must destroy the IS that is returned. 2880ea844a1aSMatthew Knepley 2881ea844a1aSMatthew Knepley Level: intermediate 2882ea844a1aSMatthew Knepley 2883ea844a1aSMatthew Knepley .seealso: PetscSectionSetClosurePermutation(), PetscSectionGetClosureIndex(), PetscSectionSetClosureIndex(), DMPlexCreateClosureIndex() 2884ea844a1aSMatthew Knepley @*/ 2885c459fbc1SJed Brown PetscErrorCode PetscSectionGetClosureInversePermutation(PetscSection section, PetscObject obj, PetscInt depth, PetscInt clSize, IS *perm) 2886ea844a1aSMatthew Knepley { 2887ea844a1aSMatthew Knepley const PetscInt *clPerm; 2888ea844a1aSMatthew Knepley PetscErrorCode ierr; 2889ea844a1aSMatthew Knepley 2890ea844a1aSMatthew Knepley PetscFunctionBegin; 2891c459fbc1SJed Brown ierr = PetscSectionGetClosureInversePermutation_Internal(section, obj, depth, clSize, &clPerm);CHKERRQ(ierr); 2892ea844a1aSMatthew Knepley ierr = ISCreateGeneral(PETSC_COMM_SELF, clSize, clPerm, PETSC_USE_POINTER, perm);CHKERRQ(ierr); 2893ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2894ea844a1aSMatthew Knepley } 2895ea844a1aSMatthew Knepley 2896ea844a1aSMatthew Knepley /*@ 2897ea844a1aSMatthew Knepley PetscSectionGetField - Get the subsection associated with a single field 2898ea844a1aSMatthew Knepley 2899ea844a1aSMatthew Knepley Input Parameters: 2900ea844a1aSMatthew Knepley + s - The PetscSection 2901ea844a1aSMatthew Knepley - field - The field number 2902ea844a1aSMatthew Knepley 2903ea844a1aSMatthew Knepley Output Parameter: 2904ea844a1aSMatthew Knepley . subs - The subsection for the given field 2905ea844a1aSMatthew Knepley 2906ea844a1aSMatthew Knepley Level: intermediate 2907ea844a1aSMatthew Knepley 2908ea844a1aSMatthew Knepley .seealso: PetscSectionSetNumFields() 2909ea844a1aSMatthew Knepley @*/ 2910ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetField(PetscSection s, PetscInt field, PetscSection *subs) 2911ea844a1aSMatthew Knepley { 2912ea844a1aSMatthew Knepley PetscFunctionBegin; 2913ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s,PETSC_SECTION_CLASSID,1); 2914ea844a1aSMatthew Knepley PetscValidPointer(subs,3); 29152abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field,s->numFields); 2916ea844a1aSMatthew Knepley *subs = s->field[field]; 2917ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2918ea844a1aSMatthew Knepley } 2919ea844a1aSMatthew Knepley 2920ea844a1aSMatthew Knepley PetscClassId PETSC_SECTION_SYM_CLASSID; 2921ea844a1aSMatthew Knepley PetscFunctionList PetscSectionSymList = NULL; 2922ea844a1aSMatthew Knepley 2923ea844a1aSMatthew Knepley /*@ 2924ea844a1aSMatthew Knepley PetscSectionSymCreate - Creates an empty PetscSectionSym object. 2925ea844a1aSMatthew Knepley 2926ea844a1aSMatthew Knepley Collective 2927ea844a1aSMatthew Knepley 2928ea844a1aSMatthew Knepley Input Parameter: 2929ea844a1aSMatthew Knepley . comm - the MPI communicator 2930ea844a1aSMatthew Knepley 2931ea844a1aSMatthew Knepley Output Parameter: 2932ea844a1aSMatthew Knepley . sym - pointer to the new set of symmetries 2933ea844a1aSMatthew Knepley 2934ea844a1aSMatthew Knepley Level: developer 2935ea844a1aSMatthew Knepley 2936ea844a1aSMatthew Knepley .seealso: PetscSectionSym, PetscSectionSymDestroy() 2937ea844a1aSMatthew Knepley @*/ 2938ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSymCreate(MPI_Comm comm, PetscSectionSym *sym) 2939ea844a1aSMatthew Knepley { 2940ea844a1aSMatthew Knepley PetscErrorCode ierr; 2941ea844a1aSMatthew Knepley 2942ea844a1aSMatthew Knepley PetscFunctionBegin; 2943ea844a1aSMatthew Knepley PetscValidPointer(sym,2); 2944ea844a1aSMatthew Knepley ierr = ISInitializePackage();CHKERRQ(ierr); 2945ea844a1aSMatthew Knepley ierr = PetscHeaderCreate(*sym,PETSC_SECTION_SYM_CLASSID,"PetscSectionSym","Section Symmetry","IS",comm,PetscSectionSymDestroy,PetscSectionSymView);CHKERRQ(ierr); 2946ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2947ea844a1aSMatthew Knepley } 2948ea844a1aSMatthew Knepley 2949ea844a1aSMatthew Knepley /*@C 2950ea844a1aSMatthew Knepley PetscSectionSymSetType - Builds a PetscSection symmetry, for a particular implementation. 2951ea844a1aSMatthew Knepley 2952ea844a1aSMatthew Knepley Collective on PetscSectionSym 2953ea844a1aSMatthew Knepley 2954ea844a1aSMatthew Knepley Input Parameters: 2955ea844a1aSMatthew Knepley + sym - The section symmetry object 2956ea844a1aSMatthew Knepley - method - The name of the section symmetry type 2957ea844a1aSMatthew Knepley 2958ea844a1aSMatthew Knepley Level: developer 2959ea844a1aSMatthew Knepley 2960ea844a1aSMatthew Knepley .seealso: PetscSectionSymGetType(), PetscSectionSymCreate() 2961ea844a1aSMatthew Knepley @*/ 2962ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSymSetType(PetscSectionSym sym, PetscSectionSymType method) 2963ea844a1aSMatthew Knepley { 2964ea844a1aSMatthew Knepley PetscErrorCode (*r)(PetscSectionSym); 2965ea844a1aSMatthew Knepley PetscBool match; 2966ea844a1aSMatthew Knepley PetscErrorCode ierr; 2967ea844a1aSMatthew Knepley 2968ea844a1aSMatthew Knepley PetscFunctionBegin; 2969ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID,1); 2970ea844a1aSMatthew Knepley ierr = PetscObjectTypeCompare((PetscObject) sym, method, &match);CHKERRQ(ierr); 2971ea844a1aSMatthew Knepley if (match) PetscFunctionReturn(0); 2972ea844a1aSMatthew Knepley 2973ea844a1aSMatthew Knepley ierr = PetscFunctionListFind(PetscSectionSymList,method,&r);CHKERRQ(ierr); 29742c71b3e2SJacob Faibussowitsch PetscCheckFalse(!r,PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscSectionSym type: %s", method); 2975ea844a1aSMatthew Knepley if (sym->ops->destroy) { 2976ea844a1aSMatthew Knepley ierr = (*sym->ops->destroy)(sym);CHKERRQ(ierr); 2977ea844a1aSMatthew Knepley sym->ops->destroy = NULL; 2978ea844a1aSMatthew Knepley } 2979ea844a1aSMatthew Knepley ierr = (*r)(sym);CHKERRQ(ierr); 2980ea844a1aSMatthew Knepley ierr = PetscObjectChangeTypeName((PetscObject)sym,method);CHKERRQ(ierr); 2981ea844a1aSMatthew Knepley PetscFunctionReturn(0); 2982ea844a1aSMatthew Knepley } 2983ea844a1aSMatthew Knepley 2984ea844a1aSMatthew Knepley /*@C 2985ea844a1aSMatthew Knepley PetscSectionSymGetType - Gets the section symmetry type name (as a string) from the PetscSectionSym. 2986ea844a1aSMatthew Knepley 2987ea844a1aSMatthew Knepley Not Collective 2988ea844a1aSMatthew Knepley 2989ea844a1aSMatthew Knepley Input Parameter: 2990ea844a1aSMatthew Knepley . sym - The section symmetry 2991ea844a1aSMatthew Knepley 2992ea844a1aSMatthew Knepley Output Parameter: 2993ea844a1aSMatthew Knepley . type - The index set type name 2994ea844a1aSMatthew Knepley 2995ea844a1aSMatthew Knepley Level: developer 2996ea844a1aSMatthew Knepley 2997ea844a1aSMatthew Knepley .seealso: PetscSectionSymSetType(), PetscSectionSymCreate() 2998ea844a1aSMatthew Knepley @*/ 2999ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSymGetType(PetscSectionSym sym, PetscSectionSymType *type) 3000ea844a1aSMatthew Knepley { 3001ea844a1aSMatthew Knepley PetscFunctionBegin; 3002ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID,1); 3003ea844a1aSMatthew Knepley PetscValidCharPointer(type,2); 3004ea844a1aSMatthew Knepley *type = ((PetscObject)sym)->type_name; 3005ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3006ea844a1aSMatthew Knepley } 3007ea844a1aSMatthew Knepley 3008ea844a1aSMatthew Knepley /*@C 3009ea844a1aSMatthew Knepley PetscSectionSymRegister - Adds a new section symmetry implementation 3010ea844a1aSMatthew Knepley 3011ea844a1aSMatthew Knepley Not Collective 3012ea844a1aSMatthew Knepley 3013ea844a1aSMatthew Knepley Input Parameters: 3014ea844a1aSMatthew Knepley + name - The name of a new user-defined creation routine 3015ea844a1aSMatthew Knepley - create_func - The creation routine itself 3016ea844a1aSMatthew Knepley 3017ea844a1aSMatthew Knepley Notes: 3018ea844a1aSMatthew Knepley PetscSectionSymRegister() may be called multiple times to add several user-defined vectors 3019ea844a1aSMatthew Knepley 3020ea844a1aSMatthew Knepley Level: developer 3021ea844a1aSMatthew Knepley 3022ea844a1aSMatthew Knepley .seealso: PetscSectionSymCreate(), PetscSectionSymSetType() 3023ea844a1aSMatthew Knepley @*/ 3024ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSymRegister(const char sname[], PetscErrorCode (*function)(PetscSectionSym)) 3025ea844a1aSMatthew Knepley { 3026ea844a1aSMatthew Knepley PetscErrorCode ierr; 3027ea844a1aSMatthew Knepley 3028ea844a1aSMatthew Knepley PetscFunctionBegin; 3029ea844a1aSMatthew Knepley ierr = ISInitializePackage();CHKERRQ(ierr); 3030ea844a1aSMatthew Knepley ierr = PetscFunctionListAdd(&PetscSectionSymList,sname,function);CHKERRQ(ierr); 3031ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3032ea844a1aSMatthew Knepley } 3033ea844a1aSMatthew Knepley 3034ea844a1aSMatthew Knepley /*@ 3035ea844a1aSMatthew Knepley PetscSectionSymDestroy - Destroys a section symmetry. 3036ea844a1aSMatthew Knepley 3037ea844a1aSMatthew Knepley Collective on PetscSectionSym 3038ea844a1aSMatthew Knepley 3039ea844a1aSMatthew Knepley Input Parameters: 3040ea844a1aSMatthew Knepley . sym - the section symmetry 3041ea844a1aSMatthew Knepley 3042ea844a1aSMatthew Knepley Level: developer 3043ea844a1aSMatthew Knepley 3044ea844a1aSMatthew Knepley .seealso: PetscSectionSymCreate(), PetscSectionSymDestroy() 3045ea844a1aSMatthew Knepley @*/ 3046ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSymDestroy(PetscSectionSym *sym) 3047ea844a1aSMatthew Knepley { 3048ea844a1aSMatthew Knepley SymWorkLink link,next; 3049ea844a1aSMatthew Knepley PetscErrorCode ierr; 3050ea844a1aSMatthew Knepley 3051ea844a1aSMatthew Knepley PetscFunctionBegin; 3052ea844a1aSMatthew Knepley if (!*sym) PetscFunctionReturn(0); 3053ea844a1aSMatthew Knepley PetscValidHeaderSpecific((*sym),PETSC_SECTION_SYM_CLASSID,1); 30544c8fdceaSLisandro Dalcin if (--((PetscObject)(*sym))->refct > 0) {*sym = NULL; PetscFunctionReturn(0);} 3055ea844a1aSMatthew Knepley if ((*sym)->ops->destroy) { 3056ea844a1aSMatthew Knepley ierr = (*(*sym)->ops->destroy)(*sym);CHKERRQ(ierr); 3057ea844a1aSMatthew Knepley } 30582c71b3e2SJacob Faibussowitsch PetscCheckFalse((*sym)->workout,PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Work array still checked out"); 3059ea844a1aSMatthew Knepley for (link=(*sym)->workin; link; link=next) { 3060ea844a1aSMatthew Knepley next = link->next; 3061a4ab841cSLisandro Dalcin ierr = PetscFree2(link->perms,link->rots);CHKERRQ(ierr); 3062ea844a1aSMatthew Knepley ierr = PetscFree(link);CHKERRQ(ierr); 3063ea844a1aSMatthew Knepley } 3064ea844a1aSMatthew Knepley (*sym)->workin = NULL; 3065ea844a1aSMatthew Knepley ierr = PetscHeaderDestroy(sym);CHKERRQ(ierr); 3066ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3067ea844a1aSMatthew Knepley } 3068ea844a1aSMatthew Knepley 3069ea844a1aSMatthew Knepley /*@C 3070ea844a1aSMatthew Knepley PetscSectionSymView - Displays a section symmetry 3071ea844a1aSMatthew Knepley 3072ea844a1aSMatthew Knepley Collective on PetscSectionSym 3073ea844a1aSMatthew Knepley 3074ea844a1aSMatthew Knepley Input Parameters: 3075ea844a1aSMatthew Knepley + sym - the index set 3076ea844a1aSMatthew Knepley - viewer - viewer used to display the set, for example PETSC_VIEWER_STDOUT_SELF. 3077ea844a1aSMatthew Knepley 3078ea844a1aSMatthew Knepley Level: developer 3079ea844a1aSMatthew Knepley 3080ea844a1aSMatthew Knepley .seealso: PetscViewerASCIIOpen() 3081ea844a1aSMatthew Knepley @*/ 3082ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSymView(PetscSectionSym sym,PetscViewer viewer) 3083ea844a1aSMatthew Knepley { 3084ea844a1aSMatthew Knepley PetscErrorCode ierr; 3085ea844a1aSMatthew Knepley 3086ea844a1aSMatthew Knepley PetscFunctionBegin; 3087ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym,PETSC_SECTION_SYM_CLASSID,1); 3088ea844a1aSMatthew Knepley if (!viewer) { 3089ea844a1aSMatthew Knepley ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)sym),&viewer);CHKERRQ(ierr); 3090ea844a1aSMatthew Knepley } 3091ea844a1aSMatthew Knepley PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 3092ea844a1aSMatthew Knepley PetscCheckSameComm(sym,1,viewer,2); 3093ea844a1aSMatthew Knepley ierr = PetscObjectPrintClassNamePrefixType((PetscObject)sym,viewer);CHKERRQ(ierr); 3094ea844a1aSMatthew Knepley if (sym->ops->view) { 3095ea844a1aSMatthew Knepley ierr = (*sym->ops->view)(sym,viewer);CHKERRQ(ierr); 3096ea844a1aSMatthew Knepley } 3097ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3098ea844a1aSMatthew Knepley } 3099ea844a1aSMatthew Knepley 3100ea844a1aSMatthew Knepley /*@ 3101ea844a1aSMatthew Knepley PetscSectionSetSym - Set the symmetries for the data referred to by the section 3102ea844a1aSMatthew Knepley 3103ea844a1aSMatthew Knepley Collective on PetscSection 3104ea844a1aSMatthew Knepley 3105ea844a1aSMatthew Knepley Input Parameters: 3106ea844a1aSMatthew Knepley + section - the section describing data layout 3107ea844a1aSMatthew Knepley - sym - the symmetry describing the affect of orientation on the access of the data 3108ea844a1aSMatthew Knepley 3109ea844a1aSMatthew Knepley Level: developer 3110ea844a1aSMatthew Knepley 3111ea844a1aSMatthew Knepley .seealso: PetscSectionGetSym(), PetscSectionSymCreate() 3112ea844a1aSMatthew Knepley @*/ 3113ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetSym(PetscSection section, PetscSectionSym sym) 3114ea844a1aSMatthew Knepley { 3115ea844a1aSMatthew Knepley PetscErrorCode ierr; 3116ea844a1aSMatthew Knepley 3117ea844a1aSMatthew Knepley PetscFunctionBegin; 3118ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,1); 3119ea844a1aSMatthew Knepley ierr = PetscSectionSymDestroy(&(section->sym));CHKERRQ(ierr); 3120ea844a1aSMatthew Knepley if (sym) { 3121ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym,PETSC_SECTION_SYM_CLASSID,2); 3122ea844a1aSMatthew Knepley PetscCheckSameComm(section,1,sym,2); 3123ea844a1aSMatthew Knepley ierr = PetscObjectReference((PetscObject) sym);CHKERRQ(ierr); 3124ea844a1aSMatthew Knepley } 3125ea844a1aSMatthew Knepley section->sym = sym; 3126ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3127ea844a1aSMatthew Knepley } 3128ea844a1aSMatthew Knepley 3129ea844a1aSMatthew Knepley /*@ 3130ea844a1aSMatthew Knepley PetscSectionGetSym - Get the symmetries for the data referred to by the section 3131ea844a1aSMatthew Knepley 3132ea844a1aSMatthew Knepley Not collective 3133ea844a1aSMatthew Knepley 3134ea844a1aSMatthew Knepley Input Parameters: 3135ea844a1aSMatthew Knepley . section - the section describing data layout 3136ea844a1aSMatthew Knepley 3137ea844a1aSMatthew Knepley Output Parameters: 3138ea844a1aSMatthew Knepley . sym - the symmetry describing the affect of orientation on the access of the data 3139ea844a1aSMatthew Knepley 3140ea844a1aSMatthew Knepley Level: developer 3141ea844a1aSMatthew Knepley 3142ea844a1aSMatthew Knepley .seealso: PetscSectionSetSym(), PetscSectionSymCreate() 3143ea844a1aSMatthew Knepley @*/ 3144ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetSym(PetscSection section, PetscSectionSym *sym) 3145ea844a1aSMatthew Knepley { 3146ea844a1aSMatthew Knepley PetscFunctionBegin; 3147ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,1); 3148ea844a1aSMatthew Knepley *sym = section->sym; 3149ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3150ea844a1aSMatthew Knepley } 3151ea844a1aSMatthew Knepley 3152ea844a1aSMatthew Knepley /*@ 3153ea844a1aSMatthew Knepley PetscSectionSetFieldSym - Set the symmetries for the data referred to by a field of the section 3154ea844a1aSMatthew Knepley 3155ea844a1aSMatthew Knepley Collective on PetscSection 3156ea844a1aSMatthew Knepley 3157ea844a1aSMatthew Knepley Input Parameters: 3158ea844a1aSMatthew Knepley + section - the section describing data layout 3159ea844a1aSMatthew Knepley . field - the field number 3160ea844a1aSMatthew Knepley - sym - the symmetry describing the affect of orientation on the access of the data 3161ea844a1aSMatthew Knepley 3162ea844a1aSMatthew Knepley Level: developer 3163ea844a1aSMatthew Knepley 3164ea844a1aSMatthew Knepley .seealso: PetscSectionGetFieldSym(), PetscSectionSymCreate() 3165ea844a1aSMatthew Knepley @*/ 3166ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetFieldSym(PetscSection section, PetscInt field, PetscSectionSym sym) 3167ea844a1aSMatthew Knepley { 3168ea844a1aSMatthew Knepley PetscErrorCode ierr; 3169ea844a1aSMatthew Knepley 3170ea844a1aSMatthew Knepley PetscFunctionBegin; 3171ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,1); 31722abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field,section->numFields); 3173ea844a1aSMatthew Knepley ierr = PetscSectionSetSym(section->field[field],sym);CHKERRQ(ierr); 3174ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3175ea844a1aSMatthew Knepley } 3176ea844a1aSMatthew Knepley 3177ea844a1aSMatthew Knepley /*@ 3178ea844a1aSMatthew Knepley PetscSectionGetFieldSym - Get the symmetries for the data referred to by a field of the section 3179ea844a1aSMatthew Knepley 3180ea844a1aSMatthew Knepley Collective on PetscSection 3181ea844a1aSMatthew Knepley 3182ea844a1aSMatthew Knepley Input Parameters: 3183ea844a1aSMatthew Knepley + section - the section describing data layout 3184ea844a1aSMatthew Knepley - field - the field number 3185ea844a1aSMatthew Knepley 3186ea844a1aSMatthew Knepley Output Parameters: 3187ea844a1aSMatthew Knepley . sym - the symmetry describing the affect of orientation on the access of the data 3188ea844a1aSMatthew Knepley 3189ea844a1aSMatthew Knepley Level: developer 3190ea844a1aSMatthew Knepley 3191ea844a1aSMatthew Knepley .seealso: PetscSectionSetFieldSym(), PetscSectionSymCreate() 3192ea844a1aSMatthew Knepley @*/ 3193ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetFieldSym(PetscSection section, PetscInt field, PetscSectionSym *sym) 3194ea844a1aSMatthew Knepley { 3195ea844a1aSMatthew Knepley PetscFunctionBegin; 3196ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,1); 31972abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field,section->numFields); 3198ea844a1aSMatthew Knepley *sym = section->field[field]->sym; 3199ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3200ea844a1aSMatthew Knepley } 3201ea844a1aSMatthew Knepley 3202ea844a1aSMatthew Knepley /*@C 3203ea844a1aSMatthew Knepley PetscSectionGetPointSyms - Get the symmetries for a set of points in a PetscSection under specific orientations. 3204ea844a1aSMatthew Knepley 3205ea844a1aSMatthew Knepley Not collective 3206ea844a1aSMatthew Knepley 3207ea844a1aSMatthew Knepley Input Parameters: 3208ea844a1aSMatthew Knepley + section - the section 3209ea844a1aSMatthew Knepley . numPoints - the number of points 3210ea844a1aSMatthew Knepley - points - an array of size 2 * numPoints, containing a list of (point, orientation) pairs. (An orientation is an 3211ea844a1aSMatthew Knepley arbitrary integer: its interpretation is up to sym. Orientations are used by DM: for their interpretation in that 3212ea844a1aSMatthew Knepley context, see DMPlexGetConeOrientation()). 3213ea844a1aSMatthew Knepley 3214d8d19677SJose E. Roman Output Parameters: 3215ea844a1aSMatthew Knepley + perms - The permutations for the given orientations (or NULL if there is no symmetry or the permutation is the identity). 3216ea844a1aSMatthew Knepley - rots - The field rotations symmetries for the given orientations (or NULL if there is no symmetry or the rotations are all 3217ea844a1aSMatthew Knepley identity). 3218ea844a1aSMatthew Knepley 3219ea844a1aSMatthew Knepley Example of usage, gathering dofs into a local array (lArray) from a section array (sArray): 3220ea844a1aSMatthew Knepley .vb 3221ea844a1aSMatthew Knepley const PetscInt **perms; 3222ea844a1aSMatthew Knepley const PetscScalar **rots; 3223ea844a1aSMatthew Knepley PetscInt lOffset; 3224ea844a1aSMatthew Knepley 3225ea844a1aSMatthew Knepley PetscSectionGetPointSyms(section,numPoints,points,&perms,&rots); 3226ea844a1aSMatthew Knepley for (i = 0, lOffset = 0; i < numPoints; i++) { 3227ea844a1aSMatthew Knepley PetscInt point = points[2*i], dof, sOffset; 3228ea844a1aSMatthew Knepley const PetscInt *perm = perms ? perms[i] : NULL; 3229ea844a1aSMatthew Knepley const PetscScalar *rot = rots ? rots[i] : NULL; 3230ea844a1aSMatthew Knepley 3231ea844a1aSMatthew Knepley PetscSectionGetDof(section,point,&dof); 3232ea844a1aSMatthew Knepley PetscSectionGetOffset(section,point,&sOffset); 3233ea844a1aSMatthew Knepley 3234ea844a1aSMatthew Knepley if (perm) {for (j = 0; j < dof; j++) {lArray[lOffset + perm[j]] = sArray[sOffset + j];}} 3235ea844a1aSMatthew Knepley else {for (j = 0; j < dof; j++) {lArray[lOffset + j ] = sArray[sOffset + j];}} 3236ea844a1aSMatthew Knepley if (rot) {for (j = 0; j < dof; j++) {lArray[lOffset + j ] *= rot[j]; }} 3237ea844a1aSMatthew Knepley lOffset += dof; 3238ea844a1aSMatthew Knepley } 3239ea844a1aSMatthew Knepley PetscSectionRestorePointSyms(section,numPoints,points,&perms,&rots); 3240ea844a1aSMatthew Knepley .ve 3241ea844a1aSMatthew Knepley 3242ea844a1aSMatthew Knepley Example of usage, adding dofs into a section array (sArray) from a local array (lArray): 3243ea844a1aSMatthew Knepley .vb 3244ea844a1aSMatthew Knepley const PetscInt **perms; 3245ea844a1aSMatthew Knepley const PetscScalar **rots; 3246ea844a1aSMatthew Knepley PetscInt lOffset; 3247ea844a1aSMatthew Knepley 3248ea844a1aSMatthew Knepley PetscSectionGetPointSyms(section,numPoints,points,&perms,&rots); 3249ea844a1aSMatthew Knepley for (i = 0, lOffset = 0; i < numPoints; i++) { 3250ea844a1aSMatthew Knepley PetscInt point = points[2*i], dof, sOffset; 3251ea844a1aSMatthew Knepley const PetscInt *perm = perms ? perms[i] : NULL; 3252ea844a1aSMatthew Knepley const PetscScalar *rot = rots ? rots[i] : NULL; 3253ea844a1aSMatthew Knepley 3254ea844a1aSMatthew Knepley PetscSectionGetDof(section,point,&dof); 3255ea844a1aSMatthew Knepley PetscSectionGetOffset(section,point,&sOff); 3256ea844a1aSMatthew Knepley 3257ea844a1aSMatthew Knepley if (perm) {for (j = 0; j < dof; j++) {sArray[sOffset + j] += lArray[lOffset + perm[j]] * (rot ? PetscConj(rot[perm[j]]) : 1.);}} 3258ea844a1aSMatthew Knepley else {for (j = 0; j < dof; j++) {sArray[sOffset + j] += lArray[lOffset + j ] * (rot ? PetscConj(rot[ j ]) : 1.);}} 3259ea844a1aSMatthew Knepley offset += dof; 3260ea844a1aSMatthew Knepley } 3261ea844a1aSMatthew Knepley PetscSectionRestorePointSyms(section,numPoints,points,&perms,&rots); 3262ea844a1aSMatthew Knepley .ve 3263ea844a1aSMatthew Knepley 3264ea844a1aSMatthew Knepley Level: developer 3265ea844a1aSMatthew Knepley 3266ea844a1aSMatthew Knepley .seealso: PetscSectionRestorePointSyms(), PetscSectionSymCreate(), PetscSectionSetSym(), PetscSectionGetSym() 3267ea844a1aSMatthew Knepley @*/ 3268ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetPointSyms(PetscSection section, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots) 3269ea844a1aSMatthew Knepley { 3270ea844a1aSMatthew Knepley PetscSectionSym sym; 3271ea844a1aSMatthew Knepley PetscErrorCode ierr; 3272ea844a1aSMatthew Knepley 3273ea844a1aSMatthew Knepley PetscFunctionBegin; 3274ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,1); 3275ea844a1aSMatthew Knepley if (numPoints) PetscValidIntPointer(points,3); 3276ea844a1aSMatthew Knepley if (perms) *perms = NULL; 3277ea844a1aSMatthew Knepley if (rots) *rots = NULL; 3278ea844a1aSMatthew Knepley sym = section->sym; 3279ea844a1aSMatthew Knepley if (sym && (perms || rots)) { 3280ea844a1aSMatthew Knepley SymWorkLink link; 3281ea844a1aSMatthew Knepley 3282ea844a1aSMatthew Knepley if (sym->workin) { 3283ea844a1aSMatthew Knepley link = sym->workin; 3284ea844a1aSMatthew Knepley sym->workin = sym->workin->next; 3285ea844a1aSMatthew Knepley } else { 3286ea844a1aSMatthew Knepley ierr = PetscNewLog(sym,&link);CHKERRQ(ierr); 3287ea844a1aSMatthew Knepley } 3288ea844a1aSMatthew Knepley if (numPoints > link->numPoints) { 3289a4ab841cSLisandro Dalcin ierr = PetscFree2(link->perms,link->rots);CHKERRQ(ierr); 3290a4ab841cSLisandro Dalcin ierr = PetscMalloc2(numPoints,&link->perms,numPoints,&link->rots);CHKERRQ(ierr); 3291ea844a1aSMatthew Knepley link->numPoints = numPoints; 3292ea844a1aSMatthew Knepley } 3293ea844a1aSMatthew Knepley link->next = sym->workout; 3294ea844a1aSMatthew Knepley sym->workout = link; 3295ea844a1aSMatthew Knepley ierr = PetscArrayzero((PetscInt**)link->perms,numPoints);CHKERRQ(ierr); 3296ea844a1aSMatthew Knepley ierr = PetscArrayzero((PetscInt**)link->rots,numPoints);CHKERRQ(ierr); 3297ea844a1aSMatthew Knepley ierr = (*sym->ops->getpoints) (sym, section, numPoints, points, link->perms, link->rots);CHKERRQ(ierr); 3298ea844a1aSMatthew Knepley if (perms) *perms = link->perms; 3299ea844a1aSMatthew Knepley if (rots) *rots = link->rots; 3300ea844a1aSMatthew Knepley } 3301ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3302ea844a1aSMatthew Knepley } 3303ea844a1aSMatthew Knepley 3304ea844a1aSMatthew Knepley /*@C 3305ea844a1aSMatthew Knepley PetscSectionRestorePointSyms - Restore the symmetries returned by PetscSectionGetPointSyms() 3306ea844a1aSMatthew Knepley 3307ea844a1aSMatthew Knepley Not collective 3308ea844a1aSMatthew Knepley 3309ea844a1aSMatthew Knepley Input Parameters: 3310ea844a1aSMatthew Knepley + section - the section 3311ea844a1aSMatthew Knepley . numPoints - the number of points 3312ea844a1aSMatthew Knepley - points - an array of size 2 * numPoints, containing a list of (point, orientation) pairs. (An orientation is an 3313ea844a1aSMatthew Knepley arbitrary integer: its interpretation is up to sym. Orientations are used by DM: for their interpretation in that 3314ea844a1aSMatthew Knepley context, see DMPlexGetConeOrientation()). 3315ea844a1aSMatthew Knepley 3316d8d19677SJose E. Roman Output Parameters: 3317ea844a1aSMatthew Knepley + perms - The permutations for the given orientations: set to NULL at conclusion 3318ea844a1aSMatthew Knepley - rots - The field rotations symmetries for the given orientations: set to NULL at conclusion 3319ea844a1aSMatthew Knepley 3320ea844a1aSMatthew Knepley Level: developer 3321ea844a1aSMatthew Knepley 3322ea844a1aSMatthew Knepley .seealso: PetscSectionGetPointSyms(), PetscSectionSymCreate(), PetscSectionSetSym(), PetscSectionGetSym() 3323ea844a1aSMatthew Knepley @*/ 3324ea844a1aSMatthew Knepley PetscErrorCode PetscSectionRestorePointSyms(PetscSection section, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots) 3325ea844a1aSMatthew Knepley { 3326ea844a1aSMatthew Knepley PetscSectionSym sym; 3327ea844a1aSMatthew Knepley 3328ea844a1aSMatthew Knepley PetscFunctionBegin; 3329ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,1); 3330ea844a1aSMatthew Knepley sym = section->sym; 3331ea844a1aSMatthew Knepley if (sym && (perms || rots)) { 3332ea844a1aSMatthew Knepley SymWorkLink *p,link; 3333ea844a1aSMatthew Knepley 3334ea844a1aSMatthew Knepley for (p=&sym->workout; (link=*p); p=&link->next) { 3335ea844a1aSMatthew Knepley if ((perms && link->perms == *perms) || (rots && link->rots == *rots)) { 3336ea844a1aSMatthew Knepley *p = link->next; 3337ea844a1aSMatthew Knepley link->next = sym->workin; 3338ea844a1aSMatthew Knepley sym->workin = link; 3339ea844a1aSMatthew Knepley if (perms) *perms = NULL; 3340ea844a1aSMatthew Knepley if (rots) *rots = NULL; 3341ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3342ea844a1aSMatthew Knepley } 3343ea844a1aSMatthew Knepley } 3344ea844a1aSMatthew Knepley SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Array was not checked out"); 3345ea844a1aSMatthew Knepley } 3346ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3347ea844a1aSMatthew Knepley } 3348ea844a1aSMatthew Knepley 3349ea844a1aSMatthew Knepley /*@C 3350ea844a1aSMatthew Knepley PetscSectionGetFieldPointSyms - Get the symmetries for a set of points in a field of a PetscSection under specific orientations. 3351ea844a1aSMatthew Knepley 3352ea844a1aSMatthew Knepley Not collective 3353ea844a1aSMatthew Knepley 3354ea844a1aSMatthew Knepley Input Parameters: 3355ea844a1aSMatthew Knepley + section - the section 3356ea844a1aSMatthew Knepley . field - the field of the section 3357ea844a1aSMatthew Knepley . numPoints - the number of points 3358ea844a1aSMatthew Knepley - points - an array of size 2 * numPoints, containing a list of (point, orientation) pairs. (An orientation is an 3359ea844a1aSMatthew Knepley arbitrary integer: its interpretation is up to sym. Orientations are used by DM: for their interpretation in that 3360ea844a1aSMatthew Knepley context, see DMPlexGetConeOrientation()). 3361ea844a1aSMatthew Knepley 3362d8d19677SJose E. Roman Output Parameters: 3363ea844a1aSMatthew Knepley + perms - The permutations for the given orientations (or NULL if there is no symmetry or the permutation is the identity). 3364ea844a1aSMatthew Knepley - rots - The field rotations symmetries for the given orientations (or NULL if there is no symmetry or the rotations are all 3365ea844a1aSMatthew Knepley identity). 3366ea844a1aSMatthew Knepley 3367ea844a1aSMatthew Knepley Level: developer 3368ea844a1aSMatthew Knepley 3369ea844a1aSMatthew Knepley .seealso: PetscSectionGetPointSyms(), PetscSectionRestoreFieldPointSyms() 3370ea844a1aSMatthew Knepley @*/ 3371ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetFieldPointSyms(PetscSection section, PetscInt field, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots) 3372ea844a1aSMatthew Knepley { 3373ea844a1aSMatthew Knepley PetscErrorCode ierr; 3374ea844a1aSMatthew Knepley 3375ea844a1aSMatthew Knepley PetscFunctionBegin; 3376ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,1); 33772c71b3e2SJacob Faibussowitsch PetscCheckFalse(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); 3378ea844a1aSMatthew Knepley ierr = PetscSectionGetPointSyms(section->field[field],numPoints,points,perms,rots);CHKERRQ(ierr); 3379ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3380ea844a1aSMatthew Knepley } 3381ea844a1aSMatthew Knepley 3382ea844a1aSMatthew Knepley /*@C 3383ea844a1aSMatthew Knepley PetscSectionRestoreFieldPointSyms - Restore the symmetries returned by PetscSectionGetFieldPointSyms() 3384ea844a1aSMatthew Knepley 3385ea844a1aSMatthew Knepley Not collective 3386ea844a1aSMatthew Knepley 3387ea844a1aSMatthew Knepley Input Parameters: 3388ea844a1aSMatthew Knepley + section - the section 3389ea844a1aSMatthew Knepley . field - the field number 3390ea844a1aSMatthew Knepley . numPoints - the number of points 3391ea844a1aSMatthew Knepley - points - an array of size 2 * numPoints, containing a list of (point, orientation) pairs. (An orientation is an 3392ea844a1aSMatthew Knepley arbitrary integer: its interpretation is up to sym. Orientations are used by DM: for their interpretation in that 3393ea844a1aSMatthew Knepley context, see DMPlexGetConeOrientation()). 3394ea844a1aSMatthew Knepley 3395d8d19677SJose E. Roman Output Parameters: 3396ea844a1aSMatthew Knepley + perms - The permutations for the given orientations: set to NULL at conclusion 3397ea844a1aSMatthew Knepley - rots - The field rotations symmetries for the given orientations: set to NULL at conclusion 3398ea844a1aSMatthew Knepley 3399ea844a1aSMatthew Knepley Level: developer 3400ea844a1aSMatthew Knepley 3401ea844a1aSMatthew Knepley .seealso: PetscSectionRestorePointSyms(), petscSectionGetFieldPointSyms(), PetscSectionSymCreate(), PetscSectionSetSym(), PetscSectionGetSym() 3402ea844a1aSMatthew Knepley @*/ 3403ea844a1aSMatthew Knepley PetscErrorCode PetscSectionRestoreFieldPointSyms(PetscSection section, PetscInt field, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots) 3404ea844a1aSMatthew Knepley { 3405ea844a1aSMatthew Knepley PetscErrorCode ierr; 3406ea844a1aSMatthew Knepley 3407ea844a1aSMatthew Knepley PetscFunctionBegin; 3408ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,1); 34092c71b3e2SJacob Faibussowitsch PetscCheckFalse(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); 3410ea844a1aSMatthew Knepley ierr = PetscSectionRestorePointSyms(section->field[field],numPoints,points,perms,rots);CHKERRQ(ierr); 3411ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3412ea844a1aSMatthew Knepley } 3413ea844a1aSMatthew Knepley 3414ea844a1aSMatthew Knepley /*@ 3415b004864fSMatthew G. Knepley PetscSectionSymCopy - Copy the symmetries, assuming that the point structure is compatible 3416b004864fSMatthew G. Knepley 3417b004864fSMatthew G. Knepley Not collective 3418b004864fSMatthew G. Knepley 3419b004864fSMatthew G. Knepley Input Parameter: 3420b004864fSMatthew G. Knepley . sym - the PetscSectionSym 3421b004864fSMatthew G. Knepley 3422b004864fSMatthew G. Knepley Output Parameter: 3423b004864fSMatthew G. Knepley . nsym - the equivalent symmetries 3424b004864fSMatthew G. Knepley 3425b004864fSMatthew G. Knepley Level: developer 3426b004864fSMatthew G. Knepley 3427b004864fSMatthew G. Knepley .seealso: PetscSectionSymCreate(), PetscSectionSetSym(), PetscSectionGetSym(), PetscSectionSymLabelSetStratum(), PetscSectionGetPointSyms() 3428b004864fSMatthew G. Knepley @*/ 3429b004864fSMatthew G. Knepley PetscErrorCode PetscSectionSymCopy(PetscSectionSym sym, PetscSectionSym nsym) 3430b004864fSMatthew G. Knepley { 3431b004864fSMatthew G. Knepley PetscErrorCode ierr; 3432b004864fSMatthew G. Knepley 3433b004864fSMatthew G. Knepley PetscFunctionBegin; 3434b004864fSMatthew G. Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 3435b004864fSMatthew G. Knepley PetscValidHeaderSpecific(nsym, PETSC_SECTION_SYM_CLASSID, 2); 3436b004864fSMatthew G. Knepley if (sym->ops->copy) {ierr = (*sym->ops->copy)(sym, nsym);CHKERRQ(ierr);} 3437b004864fSMatthew G. Knepley PetscFunctionReturn(0); 3438b004864fSMatthew G. Knepley } 3439b004864fSMatthew G. Knepley 3440b004864fSMatthew G. Knepley /*@ 3441b004864fSMatthew G. Knepley PetscSectionSymDistribute - Distribute the symmetries in accordance with the input SF 3442b004864fSMatthew G. Knepley 3443b004864fSMatthew G. Knepley Collective 3444b004864fSMatthew G. Knepley 3445b004864fSMatthew G. Knepley Input Parameters: 3446b004864fSMatthew G. Knepley + sym - the PetscSectionSym 3447b004864fSMatthew G. Knepley - migrationSF - the distribution map from roots to leaves 3448b004864fSMatthew G. Knepley 3449b004864fSMatthew G. Knepley Output Parameters: 3450b004864fSMatthew G. Knepley . dsym - the redistributed symmetries 3451b004864fSMatthew G. Knepley 3452b004864fSMatthew G. Knepley Level: developer 3453b004864fSMatthew G. Knepley 3454b004864fSMatthew G. Knepley .seealso: PetscSectionSymCreate(), PetscSectionSetSym(), PetscSectionGetSym(), PetscSectionSymLabelSetStratum(), PetscSectionGetPointSyms() 3455b004864fSMatthew G. Knepley @*/ 3456b004864fSMatthew G. Knepley PetscErrorCode PetscSectionSymDistribute(PetscSectionSym sym, PetscSF migrationSF, PetscSectionSym *dsym) 3457b004864fSMatthew G. Knepley { 3458b004864fSMatthew G. Knepley PetscErrorCode ierr; 3459b004864fSMatthew G. Knepley 3460b004864fSMatthew G. Knepley PetscFunctionBegin; 3461b004864fSMatthew G. Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1); 3462b004864fSMatthew G. Knepley PetscValidHeaderSpecific(migrationSF, PETSCSF_CLASSID, 2); 3463b004864fSMatthew G. Knepley PetscValidPointer(dsym, 3); 3464b004864fSMatthew G. Knepley if (sym->ops->distribute) {ierr = (*sym->ops->distribute)(sym, migrationSF, dsym);CHKERRQ(ierr);} 3465b004864fSMatthew G. Knepley PetscFunctionReturn(0); 3466b004864fSMatthew G. Knepley } 3467b004864fSMatthew G. Knepley 3468b004864fSMatthew G. Knepley /*@ 3469ea844a1aSMatthew Knepley PetscSectionGetUseFieldOffsets - Get the flag to use field offsets directly in a global section, rather than just the point offset 3470ea844a1aSMatthew Knepley 3471ea844a1aSMatthew Knepley Not collective 3472ea844a1aSMatthew Knepley 3473ea844a1aSMatthew Knepley Input Parameter: 3474ea844a1aSMatthew Knepley . s - the global PetscSection 3475ea844a1aSMatthew Knepley 3476ea844a1aSMatthew Knepley Output Parameters: 3477ea844a1aSMatthew Knepley . flg - the flag 3478ea844a1aSMatthew Knepley 3479ea844a1aSMatthew Knepley Level: developer 3480ea844a1aSMatthew Knepley 3481ea844a1aSMatthew Knepley .seealso: PetscSectionSetChart(), PetscSectionCreate() 3482ea844a1aSMatthew Knepley @*/ 3483ea844a1aSMatthew Knepley PetscErrorCode PetscSectionGetUseFieldOffsets(PetscSection s, PetscBool *flg) 3484ea844a1aSMatthew Knepley { 3485ea844a1aSMatthew Knepley PetscFunctionBegin; 3486ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 3487ea844a1aSMatthew Knepley *flg = s->useFieldOff; 3488ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3489ea844a1aSMatthew Knepley } 3490ea844a1aSMatthew Knepley 3491ea844a1aSMatthew Knepley /*@ 3492ea844a1aSMatthew Knepley PetscSectionSetUseFieldOffsets - Set the flag to use field offsets directly in a global section, rather than just the point offset 3493ea844a1aSMatthew Knepley 3494ea844a1aSMatthew Knepley Not collective 3495ea844a1aSMatthew Knepley 3496ea844a1aSMatthew Knepley Input Parameters: 3497ea844a1aSMatthew Knepley + s - the global PetscSection 3498ea844a1aSMatthew Knepley - flg - the flag 3499ea844a1aSMatthew Knepley 3500ea844a1aSMatthew Knepley Level: developer 3501ea844a1aSMatthew Knepley 3502ea844a1aSMatthew Knepley .seealso: PetscSectionGetUseFieldOffsets(), PetscSectionSetChart(), PetscSectionCreate() 3503ea844a1aSMatthew Knepley @*/ 3504ea844a1aSMatthew Knepley PetscErrorCode PetscSectionSetUseFieldOffsets(PetscSection s, PetscBool flg) 3505ea844a1aSMatthew Knepley { 3506ea844a1aSMatthew Knepley PetscFunctionBegin; 3507ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1); 3508ea844a1aSMatthew Knepley s->useFieldOff = flg; 3509ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3510ea844a1aSMatthew Knepley } 3511ea844a1aSMatthew Knepley 3512ea844a1aSMatthew Knepley #define PetscSectionExpandPoints_Loop(TYPE) \ 3513ea844a1aSMatthew Knepley { \ 3514ea844a1aSMatthew Knepley PetscInt i, n, o0, o1, size; \ 3515ea844a1aSMatthew Knepley TYPE *a0 = (TYPE*)origArray, *a1; \ 3516ea844a1aSMatthew Knepley ierr = PetscSectionGetStorageSize(s, &size);CHKERRQ(ierr); \ 3517ea844a1aSMatthew Knepley ierr = PetscMalloc1(size, &a1);CHKERRQ(ierr); \ 3518ea844a1aSMatthew Knepley for (i=0; i<npoints; i++) { \ 3519ea844a1aSMatthew Knepley ierr = PetscSectionGetOffset(origSection, points_[i], &o0);CHKERRQ(ierr); \ 3520ea844a1aSMatthew Knepley ierr = PetscSectionGetOffset(s, i, &o1);CHKERRQ(ierr); \ 3521ea844a1aSMatthew Knepley ierr = PetscSectionGetDof(s, i, &n);CHKERRQ(ierr); \ 3522ea844a1aSMatthew Knepley ierr = PetscMemcpy(&a1[o1], &a0[o0], n*unitsize);CHKERRQ(ierr); \ 3523ea844a1aSMatthew Knepley } \ 3524ea844a1aSMatthew Knepley *newArray = (void*)a1; \ 3525ea844a1aSMatthew Knepley } 3526ea844a1aSMatthew Knepley 3527ea844a1aSMatthew Knepley /*@ 3528ea844a1aSMatthew Knepley PetscSectionExtractDofsFromArray - Extracts elements of an array corresponding to DOFs of specified points. 3529ea844a1aSMatthew Knepley 3530ea844a1aSMatthew Knepley Not collective 3531ea844a1aSMatthew Knepley 3532ea844a1aSMatthew Knepley Input Parameters: 3533ea844a1aSMatthew Knepley + origSection - the PetscSection describing the layout of the array 3534ea844a1aSMatthew Knepley . dataType - MPI_Datatype describing the data type of the array (currently only MPIU_INT, MPIU_SCALAR, MPIU_REAL) 3535ea844a1aSMatthew Knepley . origArray - the array; its size must be equal to the storage size of origSection 3536ea844a1aSMatthew Knepley - points - IS with points to extract; its indices must lie in the chart of origSection 3537ea844a1aSMatthew Knepley 3538ea844a1aSMatthew Knepley Output Parameters: 3539ea844a1aSMatthew Knepley + newSection - the new PetscSection desribing the layout of the new array (with points renumbered 0,1,... but preserving numbers of DOFs) 3540ea844a1aSMatthew Knepley - newArray - the array of the extracted DOFs; its size is the storage size of newSection 3541ea844a1aSMatthew Knepley 3542ea844a1aSMatthew Knepley Level: developer 3543ea844a1aSMatthew Knepley 3544ea844a1aSMatthew Knepley .seealso: PetscSectionGetChart(), PetscSectionGetDof(), PetscSectionGetStorageSize(), PetscSectionCreate() 3545ea844a1aSMatthew Knepley @*/ 3546ea844a1aSMatthew Knepley PetscErrorCode PetscSectionExtractDofsFromArray(PetscSection origSection, MPI_Datatype dataType, const void *origArray, IS points, PetscSection *newSection, void *newArray[]) 3547ea844a1aSMatthew Knepley { 3548ea844a1aSMatthew Knepley PetscSection s; 3549ea844a1aSMatthew Knepley const PetscInt *points_; 3550ea844a1aSMatthew Knepley PetscInt i, n, npoints, pStart, pEnd; 3551ea844a1aSMatthew Knepley PetscMPIInt unitsize; 3552ea844a1aSMatthew Knepley PetscErrorCode ierr; 3553ea844a1aSMatthew Knepley 3554ea844a1aSMatthew Knepley PetscFunctionBegin; 3555ea844a1aSMatthew Knepley PetscValidHeaderSpecific(origSection, PETSC_SECTION_CLASSID, 1); 3556ea844a1aSMatthew Knepley PetscValidPointer(origArray, 3); 3557ea844a1aSMatthew Knepley PetscValidHeaderSpecific(points, IS_CLASSID, 4); 3558ea844a1aSMatthew Knepley if (newSection) PetscValidPointer(newSection, 5); 3559ea844a1aSMatthew Knepley if (newArray) PetscValidPointer(newArray, 6); 3560ffc4695bSBarry Smith ierr = MPI_Type_size(dataType, &unitsize);CHKERRMPI(ierr); 3561ea844a1aSMatthew Knepley ierr = ISGetLocalSize(points, &npoints);CHKERRQ(ierr); 3562ea844a1aSMatthew Knepley ierr = ISGetIndices(points, &points_);CHKERRQ(ierr); 3563ea844a1aSMatthew Knepley ierr = PetscSectionGetChart(origSection, &pStart, &pEnd);CHKERRQ(ierr); 3564ea844a1aSMatthew Knepley ierr = PetscSectionCreate(PETSC_COMM_SELF, &s);CHKERRQ(ierr); 3565ea844a1aSMatthew Knepley ierr = PetscSectionSetChart(s, 0, npoints);CHKERRQ(ierr); 3566ea844a1aSMatthew Knepley for (i=0; i<npoints; i++) { 35672c71b3e2SJacob Faibussowitsch PetscCheckFalse(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); 3568ea844a1aSMatthew Knepley ierr = PetscSectionGetDof(origSection, points_[i], &n);CHKERRQ(ierr); 3569ea844a1aSMatthew Knepley ierr = PetscSectionSetDof(s, i, n);CHKERRQ(ierr); 3570ea844a1aSMatthew Knepley } 3571ea844a1aSMatthew Knepley ierr = PetscSectionSetUp(s);CHKERRQ(ierr); 3572ea844a1aSMatthew Knepley if (newArray) { 3573ea844a1aSMatthew Knepley if (dataType == MPIU_INT) {PetscSectionExpandPoints_Loop(PetscInt);} 3574ea844a1aSMatthew Knepley else if (dataType == MPIU_SCALAR) {PetscSectionExpandPoints_Loop(PetscScalar);} 3575ea844a1aSMatthew Knepley else if (dataType == MPIU_REAL) {PetscSectionExpandPoints_Loop(PetscReal);} 3576ea844a1aSMatthew Knepley else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "not implemented for this MPI_Datatype"); 3577ea844a1aSMatthew Knepley } 3578ea844a1aSMatthew Knepley if (newSection) { 3579ea844a1aSMatthew Knepley *newSection = s; 3580ea844a1aSMatthew Knepley } else { 3581ea844a1aSMatthew Knepley ierr = PetscSectionDestroy(&s);CHKERRQ(ierr); 3582ea844a1aSMatthew Knepley } 35838609f9c4SVaclav Hapla ierr = ISRestoreIndices(points, &points_);CHKERRQ(ierr); 3584ea844a1aSMatthew Knepley PetscFunctionReturn(0); 3585ea844a1aSMatthew Knepley } 3586