1ea844a1aSMatthew Knepley /*
2ea844a1aSMatthew Knepley This file contains routines for basic section object implementation.
3ea844a1aSMatthew Knepley */
4ea844a1aSMatthew Knepley
5ea844a1aSMatthew Knepley #include <petsc/private/sectionimpl.h> /*I "petscsection.h" I*/
6ea844a1aSMatthew Knepley #include <petscsf.h>
7ea844a1aSMatthew Knepley
8ea844a1aSMatthew Knepley PetscClassId PETSC_SECTION_CLASSID;
9ea844a1aSMatthew Knepley
10ea844a1aSMatthew Knepley /*@
1120662ed9SBarry Smith PetscSectionCreate - Allocates a `PetscSection` and sets the map contents to the default.
12ea844a1aSMatthew Knepley
13ea844a1aSMatthew Knepley Collective
14ea844a1aSMatthew Knepley
15ea844a1aSMatthew Knepley Input Parameters:
16ea844a1aSMatthew Knepley + comm - the MPI communicator
17ea844a1aSMatthew Knepley - s - pointer to the section
18ea844a1aSMatthew Knepley
19ea844a1aSMatthew Knepley Level: beginner
20ea844a1aSMatthew Knepley
21ea844a1aSMatthew Knepley Notes:
22ea844a1aSMatthew Knepley Typical calling sequence
23cab54364SBarry Smith .vb
24cab54364SBarry Smith PetscSectionCreate(MPI_Comm,PetscSection *);!
25cab54364SBarry Smith PetscSectionSetNumFields(PetscSection, numFields);
26cab54364SBarry Smith PetscSectionSetChart(PetscSection,low,high);
27cab54364SBarry Smith PetscSectionSetDof(PetscSection,point,numdof);
28cab54364SBarry Smith PetscSectionSetUp(PetscSection);
29cab54364SBarry Smith PetscSectionGetOffset(PetscSection,point,PetscInt *);
30cab54364SBarry Smith PetscSectionDestroy(PetscSection);
31cab54364SBarry Smith .ve
32ea844a1aSMatthew Knepley
3335cb6cd3SPierre Jolivet The `PetscSection` object and methods are intended to be used in the PETSc `Vec` and `Mat` implementations. The indices returned by the `PetscSection` are appropriate for the kind of `Vec` it is associated with. For example, if the vector being indexed is a local vector, we call the section a local section. If the section indexes a global vector, we call it a global section. For parallel vectors, like global vectors, we use negative indices to indicate dofs owned by other processes.
34ea844a1aSMatthew Knepley
35b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionSetChart()`, `PetscSectionDestroy()`, `PetscSectionCreateGlobalSection()`
36ea844a1aSMatthew Knepley @*/
PetscSectionCreate(MPI_Comm comm,PetscSection * s)37d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreate(MPI_Comm comm, PetscSection *s)
38d71ae5a4SJacob Faibussowitsch {
39ea844a1aSMatthew Knepley PetscFunctionBegin;
404f572ea9SToby Isaac PetscAssertPointer(s, 2);
419566063dSJacob Faibussowitsch PetscCall(ISInitializePackage());
42ea844a1aSMatthew Knepley
439566063dSJacob Faibussowitsch PetscCall(PetscHeaderCreate(*s, PETSC_SECTION_CLASSID, "PetscSection", "Section", "IS", comm, PetscSectionDestroy, PetscSectionView));
44ea844a1aSMatthew Knepley (*s)->pStart = -1;
45ea844a1aSMatthew Knepley (*s)->pEnd = -1;
46ea844a1aSMatthew Knepley (*s)->perm = NULL;
47ea844a1aSMatthew Knepley (*s)->pointMajor = PETSC_TRUE;
4887e637c6Sksagiyam (*s)->includesConstraints = PETSC_TRUE;
49ea844a1aSMatthew Knepley (*s)->atlasDof = NULL;
50ea844a1aSMatthew Knepley (*s)->atlasOff = NULL;
51ea844a1aSMatthew Knepley (*s)->bc = NULL;
52ea844a1aSMatthew Knepley (*s)->bcIndices = NULL;
53ea844a1aSMatthew Knepley (*s)->setup = PETSC_FALSE;
54ea844a1aSMatthew Knepley (*s)->numFields = 0;
55ea844a1aSMatthew Knepley (*s)->fieldNames = NULL;
56ea844a1aSMatthew Knepley (*s)->field = NULL;
57ea844a1aSMatthew Knepley (*s)->useFieldOff = PETSC_FALSE;
58b778fa18SValeria Barra (*s)->compNames = NULL;
59ea844a1aSMatthew Knepley (*s)->clObj = NULL;
60c459fbc1SJed Brown (*s)->clHash = NULL;
61ea844a1aSMatthew Knepley (*s)->clSection = NULL;
62ea844a1aSMatthew Knepley (*s)->clPoints = NULL;
6369c11d05SVaclav Hapla PetscCall(PetscSectionInvalidateMaxDof_Internal(*s));
643ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
65ea844a1aSMatthew Knepley }
66ea844a1aSMatthew Knepley
67ea844a1aSMatthew Knepley /*@
68cab54364SBarry Smith PetscSectionCopy - Creates a shallow (if possible) copy of the `PetscSection`
69ea844a1aSMatthew Knepley
70ea844a1aSMatthew Knepley Collective
71ea844a1aSMatthew Knepley
72ea844a1aSMatthew Knepley Input Parameter:
73cab54364SBarry Smith . section - the `PetscSection`
74ea844a1aSMatthew Knepley
75ea844a1aSMatthew Knepley Output Parameter:
76ea844a1aSMatthew Knepley . newSection - the copy
77ea844a1aSMatthew Knepley
78ea844a1aSMatthew Knepley Level: intermediate
79ea844a1aSMatthew Knepley
8038b5cf2dSJacob Faibussowitsch Developer Notes:
81cab54364SBarry Smith What exactly does shallow mean in this context?
82cab54364SBarry Smith
83b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionDestroy()`
84ea844a1aSMatthew Knepley @*/
PetscSectionCopy(PetscSection section,PetscSection newSection)85d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCopy(PetscSection section, PetscSection newSection)
86d71ae5a4SJacob Faibussowitsch {
873857f682SStefano Zampini PetscFunctionBegin;
883857f682SStefano Zampini PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1);
893857f682SStefano Zampini PetscValidHeaderSpecific(newSection, PETSC_SECTION_CLASSID, 2);
903857f682SStefano Zampini PetscCall(PetscSectionCopy_Internal(section, newSection, NULL));
913857f682SStefano Zampini PetscFunctionReturn(PETSC_SUCCESS);
923857f682SStefano Zampini }
933857f682SStefano Zampini
PetscSectionCopy_Internal(PetscSection section,PetscSection newSection,PetscBT constrained_dofs)943857f682SStefano Zampini PetscErrorCode PetscSectionCopy_Internal(PetscSection section, PetscSection newSection, PetscBT constrained_dofs)
953857f682SStefano Zampini {
96ea844a1aSMatthew Knepley PetscSectionSym sym;
97ea844a1aSMatthew Knepley IS perm;
98b778fa18SValeria Barra PetscInt numFields, f, c, pStart, pEnd, p;
99ea844a1aSMatthew Knepley
100ea844a1aSMatthew Knepley PetscFunctionBegin;
101ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1);
102ea844a1aSMatthew Knepley PetscValidHeaderSpecific(newSection, PETSC_SECTION_CLASSID, 2);
1039566063dSJacob Faibussowitsch PetscCall(PetscSectionReset(newSection));
1049566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(section, &numFields));
1059566063dSJacob Faibussowitsch if (numFields) PetscCall(PetscSectionSetNumFields(newSection, numFields));
106ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) {
107b778fa18SValeria Barra const char *fieldName = NULL, *compName = NULL;
108ea844a1aSMatthew Knepley PetscInt numComp = 0;
109ea844a1aSMatthew Knepley
1109566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldName(section, f, &fieldName));
1119566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldName(newSection, f, fieldName));
1129566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(section, f, &numComp));
1139566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(newSection, f, numComp));
114b778fa18SValeria Barra for (c = 0; c < numComp; ++c) {
1159566063dSJacob Faibussowitsch PetscCall(PetscSectionGetComponentName(section, f, c, &compName));
1169566063dSJacob Faibussowitsch PetscCall(PetscSectionSetComponentName(newSection, f, c, compName));
117b778fa18SValeria Barra }
1189566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldSym(section, f, &sym));
1199566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldSym(newSection, f, sym));
120ea844a1aSMatthew Knepley }
1219566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(section, &pStart, &pEnd));
1229566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(newSection, pStart, pEnd));
1239566063dSJacob Faibussowitsch PetscCall(PetscSectionGetPermutation(section, &perm));
1249566063dSJacob Faibussowitsch PetscCall(PetscSectionSetPermutation(newSection, perm));
1259566063dSJacob Faibussowitsch PetscCall(PetscSectionGetSym(section, &sym));
1269566063dSJacob Faibussowitsch PetscCall(PetscSectionSetSym(newSection, sym));
127ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) {
128ea844a1aSMatthew Knepley PetscInt dof, cdof, fcdof = 0;
1293857f682SStefano Zampini PetscBool force_constrained = (PetscBool)(constrained_dofs && PetscBTLookup(constrained_dofs, p - pStart));
130ea844a1aSMatthew Knepley
1319566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(section, p, &dof));
1329566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(newSection, p, dof));
1333857f682SStefano Zampini if (force_constrained) cdof = dof;
1343857f682SStefano Zampini else PetscCall(PetscSectionGetConstraintDof(section, p, &cdof));
1359566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetConstraintDof(newSection, p, cdof));
136ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) {
1379566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(section, p, f, &dof));
1389566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldDof(newSection, p, f, dof));
139ea844a1aSMatthew Knepley if (cdof) {
1403857f682SStefano Zampini if (force_constrained) fcdof = dof;
1413857f682SStefano Zampini else PetscCall(PetscSectionGetFieldConstraintDof(section, p, f, &fcdof));
1429566063dSJacob Faibussowitsch if (fcdof) PetscCall(PetscSectionSetFieldConstraintDof(newSection, p, f, fcdof));
143ea844a1aSMatthew Knepley }
144ea844a1aSMatthew Knepley }
145ea844a1aSMatthew Knepley }
1469566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(newSection));
147ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) {
148ea844a1aSMatthew Knepley PetscInt off, cdof, fcdof = 0;
149ea844a1aSMatthew Knepley const PetscInt *cInd;
1503857f682SStefano Zampini PetscBool force_constrained = (PetscBool)(constrained_dofs && PetscBTLookup(constrained_dofs, p - pStart));
151ea844a1aSMatthew Knepley
152ea844a1aSMatthew Knepley /* Must set offsets in case they do not agree with the prefix sums */
1539566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(section, p, &off));
1549566063dSJacob Faibussowitsch PetscCall(PetscSectionSetOffset(newSection, p, off));
1553857f682SStefano Zampini PetscCall(PetscSectionGetConstraintDof(newSection, p, &cdof));
156ea844a1aSMatthew Knepley if (cdof) {
1573857f682SStefano Zampini if (force_constrained) cInd = NULL;
1583857f682SStefano Zampini else PetscCall(PetscSectionGetConstraintIndices(section, p, &cInd));
1599566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(newSection, p, cInd));
160ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) {
1613857f682SStefano Zampini PetscCall(PetscSectionGetFieldOffset(section, p, f, &off));
1623857f682SStefano Zampini PetscCall(PetscSectionSetFieldOffset(newSection, p, f, off));
1633857f682SStefano Zampini PetscCall(PetscSectionGetFieldConstraintDof(newSection, p, f, &fcdof));
164ea844a1aSMatthew Knepley if (fcdof) {
1653857f682SStefano Zampini if (force_constrained) cInd = NULL;
1663857f682SStefano Zampini else PetscCall(PetscSectionGetFieldConstraintIndices(section, p, f, &cInd));
1679566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldConstraintIndices(newSection, p, f, cInd));
168ea844a1aSMatthew Knepley }
169ea844a1aSMatthew Knepley }
170ea844a1aSMatthew Knepley }
171ea844a1aSMatthew Knepley }
1723ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
173ea844a1aSMatthew Knepley }
174ea844a1aSMatthew Knepley
175ea844a1aSMatthew Knepley /*@
176cab54364SBarry Smith PetscSectionClone - Creates a shallow (if possible) copy of the `PetscSection`
177ea844a1aSMatthew Knepley
178ea844a1aSMatthew Knepley Collective
179ea844a1aSMatthew Knepley
180ea844a1aSMatthew Knepley Input Parameter:
181cab54364SBarry Smith . section - the `PetscSection`
182ea844a1aSMatthew Knepley
183ea844a1aSMatthew Knepley Output Parameter:
184ea844a1aSMatthew Knepley . newSection - the copy
185ea844a1aSMatthew Knepley
186ea844a1aSMatthew Knepley Level: beginner
187ea844a1aSMatthew Knepley
18838b5cf2dSJacob Faibussowitsch Developer Notes:
189cab54364SBarry Smith With standard PETSc terminology this should be called `PetscSectionDuplicate()`
190cab54364SBarry Smith
191b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionDestroy()`, `PetscSectionCopy()`
192ea844a1aSMatthew Knepley @*/
PetscSectionClone(PetscSection section,PetscSection * newSection)193d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionClone(PetscSection section, PetscSection *newSection)
194d71ae5a4SJacob Faibussowitsch {
195ea844a1aSMatthew Knepley PetscFunctionBegin;
196ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1);
1974f572ea9SToby Isaac PetscAssertPointer(newSection, 2);
1989566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)section), newSection));
1999566063dSJacob Faibussowitsch PetscCall(PetscSectionCopy(section, *newSection));
2003ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
201ea844a1aSMatthew Knepley }
202ea844a1aSMatthew Knepley
203ea844a1aSMatthew Knepley /*@
204cab54364SBarry Smith PetscSectionSetFromOptions - sets parameters in a `PetscSection` from the options database
205ea844a1aSMatthew Knepley
20640750d41SVaclav Hapla Collective
207ea844a1aSMatthew Knepley
208ea844a1aSMatthew Knepley Input Parameter:
20938b5cf2dSJacob Faibussowitsch . s - the `PetscSection`
210ea844a1aSMatthew Knepley
21120662ed9SBarry Smith Options Database Key:
212cab54364SBarry Smith . -petscsection_point_major - `PETSC_TRUE` for point-major order
213ea844a1aSMatthew Knepley
214ea844a1aSMatthew Knepley Level: intermediate
215ea844a1aSMatthew Knepley
216b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionDestroy()`
217ea844a1aSMatthew Knepley @*/
PetscSectionSetFromOptions(PetscSection s)218d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFromOptions(PetscSection s)
219d71ae5a4SJacob Faibussowitsch {
220ea844a1aSMatthew Knepley PetscFunctionBegin;
221ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
222d0609cedSBarry Smith PetscObjectOptionsBegin((PetscObject)s);
2239566063dSJacob Faibussowitsch PetscCall(PetscOptionsBool("-petscsection_point_major", "The for ordering, either point major or field major", "PetscSectionSetPointMajor", s->pointMajor, &s->pointMajor, NULL));
224ea844a1aSMatthew Knepley /* process any options handlers added with PetscObjectAddOptionsHandler() */
225dbbe0bcdSBarry Smith PetscCall(PetscObjectProcessOptionsHandlers((PetscObject)s, PetscOptionsObject));
226d0609cedSBarry Smith PetscOptionsEnd();
2279566063dSJacob Faibussowitsch PetscCall(PetscObjectViewFromOptions((PetscObject)s, NULL, "-petscsection_view"));
2283ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
229ea844a1aSMatthew Knepley }
230ea844a1aSMatthew Knepley
231ea844a1aSMatthew Knepley /*@
232ea844a1aSMatthew Knepley PetscSectionCompare - Compares two sections
233ea844a1aSMatthew Knepley
23440750d41SVaclav Hapla Collective
235ea844a1aSMatthew Knepley
2367a7aea1fSJed Brown Input Parameters:
237cab54364SBarry Smith + s1 - the first `PetscSection`
238cab54364SBarry Smith - s2 - the second `PetscSection`
239ea844a1aSMatthew Knepley
240ea844a1aSMatthew Knepley Output Parameter:
241cab54364SBarry Smith . congruent - `PETSC_TRUE` if the two sections are congruent, `PETSC_FALSE` otherwise
242ea844a1aSMatthew Knepley
243ea844a1aSMatthew Knepley Level: intermediate
244ea844a1aSMatthew Knepley
245cab54364SBarry Smith Note:
246ea844a1aSMatthew Knepley Field names are disregarded.
247ea844a1aSMatthew Knepley
248b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionCopy()`, `PetscSectionClone()`
249ea844a1aSMatthew Knepley @*/
PetscSectionCompare(PetscSection s1,PetscSection s2,PetscBool * congruent)250d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCompare(PetscSection s1, PetscSection s2, PetscBool *congruent)
251d71ae5a4SJacob Faibussowitsch {
252ea844a1aSMatthew Knepley PetscInt pStart, pEnd, nfields, ncdof, nfcdof, p, f, n1, n2;
253ea844a1aSMatthew Knepley const PetscInt *idx1, *idx2;
254ea844a1aSMatthew Knepley IS perm1, perm2;
255ea844a1aSMatthew Knepley PetscBool flg;
256ea844a1aSMatthew Knepley PetscMPIInt mflg;
257ea844a1aSMatthew Knepley
258ea844a1aSMatthew Knepley PetscFunctionBegin;
259ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s1, PETSC_SECTION_CLASSID, 1);
260ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s2, PETSC_SECTION_CLASSID, 2);
2614f572ea9SToby Isaac PetscAssertPointer(congruent, 3);
262ea844a1aSMatthew Knepley flg = PETSC_FALSE;
263ea844a1aSMatthew Knepley
2649566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_compare(PetscObjectComm((PetscObject)s1), PetscObjectComm((PetscObject)s2), &mflg));
265ea844a1aSMatthew Knepley if (mflg != MPI_CONGRUENT && mflg != MPI_IDENT) {
266ea844a1aSMatthew Knepley *congruent = PETSC_FALSE;
2673ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
268ea844a1aSMatthew Knepley }
269ea844a1aSMatthew Knepley
2709566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s1, &pStart, &pEnd));
2719566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s2, &n1, &n2));
272ea844a1aSMatthew Knepley if (pStart != n1 || pEnd != n2) goto not_congruent;
273ea844a1aSMatthew Knepley
2749566063dSJacob Faibussowitsch PetscCall(PetscSectionGetPermutation(s1, &perm1));
2759566063dSJacob Faibussowitsch PetscCall(PetscSectionGetPermutation(s2, &perm2));
276ea844a1aSMatthew Knepley if (perm1 && perm2) {
2779566063dSJacob Faibussowitsch PetscCall(ISEqual(perm1, perm2, congruent));
2784ad8454bSPierre Jolivet if (!*congruent) goto not_congruent;
279ea844a1aSMatthew Knepley } else if (perm1 != perm2) goto not_congruent;
280ea844a1aSMatthew Knepley
281ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) {
2829566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s1, p, &n1));
2839566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s2, p, &n2));
284ea844a1aSMatthew Knepley if (n1 != n2) goto not_congruent;
285ea844a1aSMatthew Knepley
2869566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s1, p, &n1));
2879566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s2, p, &n2));
288ea844a1aSMatthew Knepley if (n1 != n2) goto not_congruent;
289ea844a1aSMatthew Knepley
2909566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s1, p, &ncdof));
2919566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s2, p, &n2));
292ea844a1aSMatthew Knepley if (ncdof != n2) goto not_congruent;
293ea844a1aSMatthew Knepley
2949566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s1, p, &idx1));
2959566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s2, p, &idx2));
2969566063dSJacob Faibussowitsch PetscCall(PetscArraycmp(idx1, idx2, ncdof, congruent));
2974ad8454bSPierre Jolivet if (!*congruent) goto not_congruent;
298ea844a1aSMatthew Knepley }
299ea844a1aSMatthew Knepley
3009566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s1, &nfields));
3019566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s2, &n2));
302ea844a1aSMatthew Knepley if (nfields != n2) goto not_congruent;
303ea844a1aSMatthew Knepley
304ea844a1aSMatthew Knepley for (f = 0; f < nfields; ++f) {
3059566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s1, f, &n1));
3069566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s2, f, &n2));
307ea844a1aSMatthew Knepley if (n1 != n2) goto not_congruent;
308ea844a1aSMatthew Knepley
309ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) {
3109566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldOffset(s1, p, f, &n1));
3119566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldOffset(s2, p, f, &n2));
312ea844a1aSMatthew Knepley if (n1 != n2) goto not_congruent;
313ea844a1aSMatthew Knepley
3149566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s1, p, f, &n1));
3159566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s2, p, f, &n2));
316ea844a1aSMatthew Knepley if (n1 != n2) goto not_congruent;
317ea844a1aSMatthew Knepley
3189566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s1, p, f, &nfcdof));
3199566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s2, p, f, &n2));
320ea844a1aSMatthew Knepley if (nfcdof != n2) goto not_congruent;
321ea844a1aSMatthew Knepley
3229566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(s1, p, f, &idx1));
3239566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(s2, p, f, &idx2));
3249566063dSJacob Faibussowitsch PetscCall(PetscArraycmp(idx1, idx2, nfcdof, congruent));
3254ad8454bSPierre Jolivet if (!*congruent) goto not_congruent;
326ea844a1aSMatthew Knepley }
327ea844a1aSMatthew Knepley }
328ea844a1aSMatthew Knepley
329ea844a1aSMatthew Knepley flg = PETSC_TRUE;
330ea844a1aSMatthew Knepley not_congruent:
3315440e5dcSBarry Smith PetscCallMPI(MPIU_Allreduce(&flg, congruent, 1, MPI_C_BOOL, MPI_LAND, PetscObjectComm((PetscObject)s1)));
3323ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
333ea844a1aSMatthew Knepley }
334ea844a1aSMatthew Knepley
335ea844a1aSMatthew Knepley /*@
336cab54364SBarry Smith PetscSectionGetNumFields - Returns the number of fields in a `PetscSection`, or 0 if no fields were defined.
337ea844a1aSMatthew Knepley
33840750d41SVaclav Hapla Not Collective
339ea844a1aSMatthew Knepley
340ea844a1aSMatthew Knepley Input Parameter:
341cab54364SBarry Smith . s - the `PetscSection`
342ea844a1aSMatthew Knepley
343ea844a1aSMatthew Knepley Output Parameter:
344ea844a1aSMatthew Knepley . numFields - the number of fields defined, or 0 if none were defined
345ea844a1aSMatthew Knepley
346ea844a1aSMatthew Knepley Level: intermediate
347ea844a1aSMatthew Knepley
348b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionSetNumFields()`
349ea844a1aSMatthew Knepley @*/
PetscSectionGetNumFields(PetscSection s,PetscInt * numFields)350d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetNumFields(PetscSection s, PetscInt *numFields)
351d71ae5a4SJacob Faibussowitsch {
352ea844a1aSMatthew Knepley PetscFunctionBegin;
353ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
3544f572ea9SToby Isaac PetscAssertPointer(numFields, 2);
355ea844a1aSMatthew Knepley *numFields = s->numFields;
3563ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
357ea844a1aSMatthew Knepley }
358ea844a1aSMatthew Knepley
359ea844a1aSMatthew Knepley /*@
360cab54364SBarry Smith PetscSectionSetNumFields - Sets the number of fields in a `PetscSection`
361ea844a1aSMatthew Knepley
36240750d41SVaclav Hapla Not Collective
363ea844a1aSMatthew Knepley
364ea844a1aSMatthew Knepley Input Parameters:
36520662ed9SBarry Smith + s - the `PetscSection`
366ea844a1aSMatthew Knepley - numFields - the number of fields
367ea844a1aSMatthew Knepley
368ea844a1aSMatthew Knepley Level: intermediate
369ea844a1aSMatthew Knepley
370583308b6SBarry Smith Notes:
371583308b6SBarry Smith Calling this destroys all the information in the `PetscSection` including the chart.
372583308b6SBarry Smith
373583308b6SBarry Smith You must call `PetscSectionSetChart()` after calling this.
374583308b6SBarry Smith
375b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetNumFields()`, `PetscSectionSetChart()`, `PetscSectionReset()`
376ea844a1aSMatthew Knepley @*/
PetscSectionSetNumFields(PetscSection s,PetscInt numFields)377d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetNumFields(PetscSection s, PetscInt numFields)
378d71ae5a4SJacob Faibussowitsch {
379ea844a1aSMatthew Knepley PetscInt f;
380ea844a1aSMatthew Knepley
381ea844a1aSMatthew Knepley PetscFunctionBegin;
382ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
38308401ef6SPierre Jolivet PetscCheck(numFields > 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "The number of fields %" PetscInt_FMT " must be positive", numFields);
3849566063dSJacob Faibussowitsch PetscCall(PetscSectionReset(s));
385ea844a1aSMatthew Knepley
386ea844a1aSMatthew Knepley s->numFields = numFields;
3879566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(s->numFields, &s->numFieldComponents));
3889566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(s->numFields, &s->fieldNames));
3899566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(s->numFields, &s->compNames));
3909566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(s->numFields, &s->field));
391ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) {
392ea844a1aSMatthew Knepley char name[64];
393ea844a1aSMatthew Knepley
394ea844a1aSMatthew Knepley s->numFieldComponents[f] = 1;
395ea844a1aSMatthew Knepley
3969566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), &s->field[f]));
3979566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(name, 64, "Field_%" PetscInt_FMT, f));
398835f2295SStefano Zampini PetscCall(PetscStrallocpy(name, &s->fieldNames[f]));
3999566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(name, 64, "Component_0"));
4009566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(s->numFieldComponents[f], &s->compNames[f]));
401835f2295SStefano Zampini PetscCall(PetscStrallocpy(name, &s->compNames[f][0]));
402ea844a1aSMatthew Knepley }
4033ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
404ea844a1aSMatthew Knepley }
405ea844a1aSMatthew Knepley
406cc4c1da9SBarry Smith /*@
407cab54364SBarry Smith PetscSectionGetFieldName - Returns the name of a field in the `PetscSection`
408ea844a1aSMatthew Knepley
409ea844a1aSMatthew Knepley Not Collective
410ea844a1aSMatthew Knepley
411ea844a1aSMatthew Knepley Input Parameters:
412cab54364SBarry Smith + s - the `PetscSection`
413ea844a1aSMatthew Knepley - field - the field number
414ea844a1aSMatthew Knepley
415ea844a1aSMatthew Knepley Output Parameter:
416ea844a1aSMatthew Knepley . fieldName - the field name
417ea844a1aSMatthew Knepley
418ea844a1aSMatthew Knepley Level: intermediate
419ea844a1aSMatthew Knepley
420cab54364SBarry Smith Note:
421cab54364SBarry Smith Will error if the field number is out of range
422cab54364SBarry Smith
423b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionSetFieldName()`, `PetscSectionSetNumFields()`, `PetscSectionGetNumFields()`
424ea844a1aSMatthew Knepley @*/
PetscSectionGetFieldName(PetscSection s,PetscInt field,const char * fieldName[])425d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldName(PetscSection s, PetscInt field, const char *fieldName[])
426d71ae5a4SJacob Faibussowitsch {
427ea844a1aSMatthew Knepley PetscFunctionBegin;
428ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
4294f572ea9SToby Isaac PetscAssertPointer(fieldName, 3);
4302abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields);
431ea844a1aSMatthew Knepley *fieldName = s->fieldNames[field];
4323ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
433ea844a1aSMatthew Knepley }
434ea844a1aSMatthew Knepley
435cc4c1da9SBarry Smith /*@
436cab54364SBarry Smith PetscSectionSetFieldName - Sets the name of a field in the `PetscSection`
437ea844a1aSMatthew Knepley
438ea844a1aSMatthew Knepley Not Collective
439ea844a1aSMatthew Knepley
440ea844a1aSMatthew Knepley Input Parameters:
441cab54364SBarry Smith + s - the `PetscSection`
442ea844a1aSMatthew Knepley . field - the field number
443ea844a1aSMatthew Knepley - fieldName - the field name
444ea844a1aSMatthew Knepley
445ea844a1aSMatthew Knepley Level: intermediate
446ea844a1aSMatthew Knepley
447cab54364SBarry Smith Note:
448cab54364SBarry Smith Will error if the field number is out of range
449cab54364SBarry Smith
450b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionGetFieldName()`, `PetscSectionSetNumFields()`, `PetscSectionGetNumFields()`
451ea844a1aSMatthew Knepley @*/
PetscSectionSetFieldName(PetscSection s,PetscInt field,const char fieldName[])452d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldName(PetscSection s, PetscInt field, const char fieldName[])
453d71ae5a4SJacob Faibussowitsch {
454ea844a1aSMatthew Knepley PetscFunctionBegin;
455ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
4564f572ea9SToby Isaac if (fieldName) PetscAssertPointer(fieldName, 3);
4572abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields);
4589566063dSJacob Faibussowitsch PetscCall(PetscFree(s->fieldNames[field]));
459835f2295SStefano Zampini PetscCall(PetscStrallocpy(fieldName, &s->fieldNames[field]));
4603ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
461ea844a1aSMatthew Knepley }
462ea844a1aSMatthew Knepley
463cc4c1da9SBarry Smith /*@
464cab54364SBarry Smith PetscSectionGetComponentName - Gets the name of a field component in the `PetscSection`
465b778fa18SValeria Barra
466b778fa18SValeria Barra Not Collective
467b778fa18SValeria Barra
468b778fa18SValeria Barra Input Parameters:
469cab54364SBarry Smith + s - the `PetscSection`
470b778fa18SValeria Barra . field - the field number
471cab54364SBarry Smith - comp - the component number
472cab54364SBarry Smith
473d5b43468SJose E. Roman Output Parameter:
474cab54364SBarry Smith . compName - the component name
475b778fa18SValeria Barra
476b778fa18SValeria Barra Level: intermediate
477b778fa18SValeria Barra
478cab54364SBarry Smith Note:
479cab54364SBarry Smith Will error if the field or component number do not exist
480cab54364SBarry Smith
48138b5cf2dSJacob Faibussowitsch Developer Notes:
482583308b6SBarry Smith The function name should have Field in it since they are field components.
483583308b6SBarry Smith
484b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetFieldName()`, `PetscSectionSetNumFields()`, `PetscSectionGetNumFields()`,
485cab54364SBarry Smith `PetscSectionSetComponentName()`, `PetscSectionSetFieldName()`, `PetscSectionGetFieldComponents()`, `PetscSectionSetFieldComponents()`
486b778fa18SValeria Barra @*/
PetscSectionGetComponentName(PetscSection s,PetscInt field,PetscInt comp,const char * compName[])487d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetComponentName(PetscSection s, PetscInt field, PetscInt comp, const char *compName[])
488d71ae5a4SJacob Faibussowitsch {
489b778fa18SValeria Barra PetscFunctionBegin;
490b778fa18SValeria Barra PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
4914f572ea9SToby Isaac PetscAssertPointer(compName, 4);
4922abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields);
4932abc8c78SJacob Faibussowitsch PetscSectionCheckValidFieldComponent(comp, s->numFieldComponents[field]);
494b778fa18SValeria Barra *compName = s->compNames[field][comp];
4953ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
496b778fa18SValeria Barra }
497b778fa18SValeria Barra
498cc4c1da9SBarry Smith /*@
499cab54364SBarry Smith PetscSectionSetComponentName - Sets the name of a field component in the `PetscSection`
500b778fa18SValeria Barra
501b778fa18SValeria Barra Not Collective
502b778fa18SValeria Barra
503b778fa18SValeria Barra Input Parameters:
50420662ed9SBarry Smith + s - the `PetscSection`
505b778fa18SValeria Barra . field - the field number
506b778fa18SValeria Barra . comp - the component number
507b778fa18SValeria Barra - compName - the component name
508b778fa18SValeria Barra
509583308b6SBarry Smith Level: advanced
510b778fa18SValeria Barra
511cab54364SBarry Smith Note:
512cab54364SBarry Smith Will error if the field or component number do not exist
513cab54364SBarry Smith
51438b5cf2dSJacob Faibussowitsch Developer Notes:
515583308b6SBarry Smith The function name should have Field in it since they are field components.
516583308b6SBarry Smith
517b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetComponentName()`, `PetscSectionSetNumFields()`, `PetscSectionGetNumFields()`,
51842747ad1SJacob Faibussowitsch `PetscSectionSetFieldName()`, `PetscSectionGetFieldComponents()`, `PetscSectionSetFieldComponents()`
519b778fa18SValeria Barra @*/
PetscSectionSetComponentName(PetscSection s,PetscInt field,PetscInt comp,const char compName[])520d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetComponentName(PetscSection s, PetscInt field, PetscInt comp, const char compName[])
521d71ae5a4SJacob Faibussowitsch {
522b778fa18SValeria Barra PetscFunctionBegin;
523b778fa18SValeria Barra PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
5244f572ea9SToby Isaac if (compName) PetscAssertPointer(compName, 4);
5252abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields);
5262abc8c78SJacob Faibussowitsch PetscSectionCheckValidFieldComponent(comp, s->numFieldComponents[field]);
5279566063dSJacob Faibussowitsch PetscCall(PetscFree(s->compNames[field][comp]));
528835f2295SStefano Zampini PetscCall(PetscStrallocpy(compName, &s->compNames[field][comp]));
5293ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
530b778fa18SValeria Barra }
531b778fa18SValeria Barra
532ea844a1aSMatthew Knepley /*@
533ea844a1aSMatthew Knepley PetscSectionGetFieldComponents - Returns the number of field components for the given field.
534ea844a1aSMatthew Knepley
53540750d41SVaclav Hapla Not Collective
536ea844a1aSMatthew Knepley
537ea844a1aSMatthew Knepley Input Parameters:
538cab54364SBarry Smith + s - the `PetscSection`
539ea844a1aSMatthew Knepley - field - the field number
540ea844a1aSMatthew Knepley
541ea844a1aSMatthew Knepley Output Parameter:
542ea844a1aSMatthew Knepley . numComp - the number of field components
543ea844a1aSMatthew Knepley
544583308b6SBarry Smith Level: advanced
545ea844a1aSMatthew Knepley
54638b5cf2dSJacob Faibussowitsch Developer Notes:
547cab54364SBarry Smith This function is misnamed. There is a Num in `PetscSectionGetNumFields()` but not in this name
548cab54364SBarry Smith
549b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionSetFieldComponents()`, `PetscSectionGetNumFields()`,
550583308b6SBarry Smith `PetscSectionSetComponentName()`, `PetscSectionGetComponentName()`
551ea844a1aSMatthew Knepley @*/
PetscSectionGetFieldComponents(PetscSection s,PetscInt field,PetscInt * numComp)552d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldComponents(PetscSection s, PetscInt field, PetscInt *numComp)
553d71ae5a4SJacob Faibussowitsch {
554ea844a1aSMatthew Knepley PetscFunctionBegin;
555ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
5564f572ea9SToby Isaac PetscAssertPointer(numComp, 3);
5572abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields);
558ea844a1aSMatthew Knepley *numComp = s->numFieldComponents[field];
5593ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
560ea844a1aSMatthew Knepley }
561ea844a1aSMatthew Knepley
562ea844a1aSMatthew Knepley /*@
563ea844a1aSMatthew Knepley PetscSectionSetFieldComponents - Sets the number of field components for the given field.
564ea844a1aSMatthew Knepley
56540750d41SVaclav Hapla Not Collective
566ea844a1aSMatthew Knepley
567ea844a1aSMatthew Knepley Input Parameters:
56820662ed9SBarry Smith + s - the `PetscSection`
569ea844a1aSMatthew Knepley . field - the field number
570ea844a1aSMatthew Knepley - numComp - the number of field components
571ea844a1aSMatthew Knepley
572583308b6SBarry Smith Level: advanced
573ea844a1aSMatthew Knepley
574583308b6SBarry Smith Note:
575583308b6SBarry Smith This number can be different than the values set with `PetscSectionSetFieldDof()`. It can be used to indicate the number of
576583308b6SBarry Smith components in the field of the underlying physical model which may be different than the number of degrees of freedom needed
577583308b6SBarry Smith at a point in a discretization. For example, if in three dimensions the field is velocity, it will have 3 components, u, v, and w but
578583308b6SBarry Smith an face based model for velocity (where the velocity normal to the face is stored) there is only 1 dof for each face point.
579583308b6SBarry Smith
580583308b6SBarry Smith The value set with this function are not needed or used in `PetscSectionSetUp()`.
581583308b6SBarry Smith
58238b5cf2dSJacob Faibussowitsch Developer Notes:
583583308b6SBarry Smith This function is misnamed. There is a Num in `PetscSectionSetNumFields()` but not in this name
584583308b6SBarry Smith
585b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetFieldComponents()`, `PetscSectionSetComponentName()`,
586583308b6SBarry Smith `PetscSectionGetComponentName()`, `PetscSectionGetNumFields()`
587ea844a1aSMatthew Knepley @*/
PetscSectionSetFieldComponents(PetscSection s,PetscInt field,PetscInt numComp)588d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldComponents(PetscSection s, PetscInt field, PetscInt numComp)
589d71ae5a4SJacob Faibussowitsch {
590b778fa18SValeria Barra PetscInt c;
591b778fa18SValeria Barra
592ea844a1aSMatthew Knepley PetscFunctionBegin;
593ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
5942abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields);
595b778fa18SValeria Barra if (s->compNames) {
59648a46eb9SPierre Jolivet for (c = 0; c < s->numFieldComponents[field]; ++c) PetscCall(PetscFree(s->compNames[field][c]));
5979566063dSJacob Faibussowitsch PetscCall(PetscFree(s->compNames[field]));
598b778fa18SValeria Barra }
599b778fa18SValeria Barra
600ea844a1aSMatthew Knepley s->numFieldComponents[field] = numComp;
601b778fa18SValeria Barra if (numComp) {
602835f2295SStefano Zampini PetscCall(PetscMalloc1(numComp, &s->compNames[field]));
603b778fa18SValeria Barra for (c = 0; c < numComp; ++c) {
6042abc8c78SJacob Faibussowitsch char name[64];
6052abc8c78SJacob Faibussowitsch
6069566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(name, 64, "%" PetscInt_FMT, c));
607835f2295SStefano Zampini PetscCall(PetscStrallocpy(name, &s->compNames[field][c]));
608b778fa18SValeria Barra }
609b778fa18SValeria Barra }
6103ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
611ea844a1aSMatthew Knepley }
612ea844a1aSMatthew Knepley
613ea844a1aSMatthew Knepley /*@
614583308b6SBarry Smith PetscSectionGetChart - Returns the range [`pStart`, `pEnd`) in which points (indices) lie for this `PetscSection` on this MPI process
615ea844a1aSMatthew Knepley
61640750d41SVaclav Hapla Not Collective
617ea844a1aSMatthew Knepley
618ea844a1aSMatthew Knepley Input Parameter:
619cab54364SBarry Smith . s - the `PetscSection`
620ea844a1aSMatthew Knepley
621ea844a1aSMatthew Knepley Output Parameters:
622ea844a1aSMatthew Knepley + pStart - the first point
623ea844a1aSMatthew Knepley - pEnd - one past the last point
624ea844a1aSMatthew Knepley
625ea844a1aSMatthew Knepley Level: intermediate
626ea844a1aSMatthew Knepley
627*dac9a9d1SBarry Smith Note:
628*dac9a9d1SBarry Smith The chart may be thought of as the bounds on the points (indices) one may use to index into numerical data that is associated with
629*dac9a9d1SBarry Smith the `PetscSection` data layout.
630*dac9a9d1SBarry Smith
631b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionSetChart()`, `PetscSectionCreate()`
632ea844a1aSMatthew Knepley @*/
PetscSectionGetChart(PetscSection s,PetscInt * pStart,PetscInt * pEnd)633d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetChart(PetscSection s, PetscInt *pStart, PetscInt *pEnd)
634d71ae5a4SJacob Faibussowitsch {
635ea844a1aSMatthew Knepley PetscFunctionBegin;
636ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
637ea844a1aSMatthew Knepley if (pStart) *pStart = s->pStart;
638ea844a1aSMatthew Knepley if (pEnd) *pEnd = s->pEnd;
6393ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
640ea844a1aSMatthew Knepley }
641ea844a1aSMatthew Knepley
642ea844a1aSMatthew Knepley /*@
643583308b6SBarry Smith PetscSectionSetChart - Sets the range [`pStart`, `pEnd`) in which points (indices) lie for this `PetscSection` on this MPI process
644ea844a1aSMatthew Knepley
64540750d41SVaclav Hapla Not Collective
646ea844a1aSMatthew Knepley
647ea844a1aSMatthew Knepley Input Parameters:
64820662ed9SBarry Smith + s - the `PetscSection`
649*dac9a9d1SBarry Smith . pStart - the first `point`
650376335faSBarry Smith - pEnd - one past the last point, `pStart` $ \le $ `pEnd`
651ea844a1aSMatthew Knepley
652ea844a1aSMatthew Knepley Level: intermediate
653ea844a1aSMatthew Knepley
654583308b6SBarry Smith Notes:
655*dac9a9d1SBarry Smith The chart may be thought of as the bounds on the points (indices) one may use to index into numerical data that is associated with
656*dac9a9d1SBarry Smith the `PetscSection` data layout.
657*dac9a9d1SBarry Smith
658583308b6SBarry Smith The charts on different MPI processes may (and often do) overlap
659583308b6SBarry Smith
660583308b6SBarry Smith If you intend to use `PetscSectionSetNumFields()` it must be called before this call.
661583308b6SBarry Smith
662583308b6SBarry Smith The chart for all fields created with `PetscSectionSetNumFields()` is the same as this chart.
663583308b6SBarry Smith
664b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetChart()`, `PetscSectionCreate()`, `PetscSectionSetNumFields()`
665ea844a1aSMatthew Knepley @*/
PetscSectionSetChart(PetscSection s,PetscInt pStart,PetscInt pEnd)666d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetChart(PetscSection s, PetscInt pStart, PetscInt pEnd)
667d71ae5a4SJacob Faibussowitsch {
668ea844a1aSMatthew Knepley PetscInt f;
669ea844a1aSMatthew Knepley
670ea844a1aSMatthew Knepley PetscFunctionBegin;
671ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
67240196513SBarry Smith PetscCheck(pEnd >= pStart, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Chart pEnd %" PetscInt_FMT " cannot be smaller than chart pStart %" PetscInt_FMT, pEnd, pStart);
6733ba16761SJacob Faibussowitsch if (pStart == s->pStart && pEnd == s->pEnd) PetscFunctionReturn(PETSC_SUCCESS);
674ea844a1aSMatthew Knepley /* Cannot Reset() because it destroys field information */
675ea844a1aSMatthew Knepley s->setup = PETSC_FALSE;
6769566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->bc));
6779566063dSJacob Faibussowitsch PetscCall(PetscFree(s->bcIndices));
6789566063dSJacob Faibussowitsch PetscCall(PetscFree2(s->atlasDof, s->atlasOff));
679ea844a1aSMatthew Knepley
680ea844a1aSMatthew Knepley s->pStart = pStart;
681ea844a1aSMatthew Knepley s->pEnd = pEnd;
68257508eceSPierre Jolivet PetscCall(PetscMalloc2(pEnd - pStart, &s->atlasDof, pEnd - pStart, &s->atlasOff));
6839566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(s->atlasDof, pEnd - pStart));
68448a46eb9SPierre Jolivet for (f = 0; f < s->numFields; ++f) PetscCall(PetscSectionSetChart(s->field[f], pStart, pEnd));
6853ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
686ea844a1aSMatthew Knepley }
687ea844a1aSMatthew Knepley
688ea844a1aSMatthew Knepley /*@
68920662ed9SBarry Smith PetscSectionGetPermutation - Returns the permutation of [0, `pEnd` - `pStart`) or `NULL` that was set with `PetscSectionSetPermutation()`
690ea844a1aSMatthew Knepley
69140750d41SVaclav Hapla Not Collective
692ea844a1aSMatthew Knepley
693ea844a1aSMatthew Knepley Input Parameter:
694cab54364SBarry Smith . s - the `PetscSection`
695ea844a1aSMatthew Knepley
6962fe279fdSBarry Smith Output Parameter:
697cab54364SBarry Smith . perm - The permutation as an `IS`
698ea844a1aSMatthew Knepley
699ea844a1aSMatthew Knepley Level: intermediate
700ea844a1aSMatthew Knepley
701cab54364SBarry Smith .seealso: [](sec_scatter), `IS`, `PetscSection`, `PetscSectionSetPermutation()`, `PetscSectionCreate()`
702ea844a1aSMatthew Knepley @*/
PetscSectionGetPermutation(PetscSection s,IS * perm)703d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetPermutation(PetscSection s, IS *perm)
704d71ae5a4SJacob Faibussowitsch {
705ea844a1aSMatthew Knepley PetscFunctionBegin;
706ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
7079371c9d4SSatish Balay if (perm) {
7084f572ea9SToby Isaac PetscAssertPointer(perm, 2);
7099371c9d4SSatish Balay *perm = s->perm;
7109371c9d4SSatish Balay }
7113ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
712ea844a1aSMatthew Knepley }
713ea844a1aSMatthew Knepley
714ea844a1aSMatthew Knepley /*@
715583308b6SBarry Smith PetscSectionSetPermutation - Sets a permutation of the chart for this section, [0, `pEnd` - `pStart`), which determines the order to store the `PetscSection` information
716ea844a1aSMatthew Knepley
71740750d41SVaclav Hapla Not Collective
718ea844a1aSMatthew Knepley
719ea844a1aSMatthew Knepley Input Parameters:
72020662ed9SBarry Smith + s - the `PetscSection`
721ea844a1aSMatthew Knepley - perm - the permutation of points
722ea844a1aSMatthew Knepley
723ea844a1aSMatthew Knepley Level: intermediate
724ea844a1aSMatthew Knepley
725583308b6SBarry Smith Notes:
726583308b6SBarry Smith The permutation must be provided before `PetscSectionSetUp()`.
727cab54364SBarry Smith
728583308b6SBarry Smith The data in the `PetscSection` are permuted but the access via `PetscSectionGetFieldOffset()` and `PetscSectionGetOffset()` is not changed
729583308b6SBarry Smith
7303ec46b7bSMatthew G. Knepley Compare to `PetscSectionPermute()`
731583308b6SBarry Smith
732583308b6SBarry Smith .seealso: [](sec_scatter), `IS`, `PetscSection`, `PetscSectionSetUp()`, `PetscSectionGetPermutation()`, `PetscSectionPermute()`, `PetscSectionCreate()`
733ea844a1aSMatthew Knepley @*/
PetscSectionSetPermutation(PetscSection s,IS perm)734d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetPermutation(PetscSection s, IS perm)
735d71ae5a4SJacob Faibussowitsch {
736ea844a1aSMatthew Knepley PetscFunctionBegin;
737ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
738ea844a1aSMatthew Knepley if (perm) PetscValidHeaderSpecific(perm, IS_CLASSID, 2);
73928b400f6SJacob Faibussowitsch PetscCheck(!s->setup, PetscObjectComm((PetscObject)s), PETSC_ERR_ARG_WRONGSTATE, "Cannot set a permutation after the section is setup");
740ea844a1aSMatthew Knepley if (s->perm != perm) {
7419566063dSJacob Faibussowitsch PetscCall(ISDestroy(&s->perm));
742ea844a1aSMatthew Knepley if (perm) {
743ea844a1aSMatthew Knepley s->perm = perm;
7449566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)s->perm));
745ea844a1aSMatthew Knepley }
746ea844a1aSMatthew Knepley }
7473ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
748ea844a1aSMatthew Knepley }
749ea844a1aSMatthew Knepley
7503ec46b7bSMatthew G. Knepley /*@C
7513ec46b7bSMatthew G. Knepley PetscSectionGetBlockStarts - Returns a table indicating which points start new blocks
7523ec46b7bSMatthew G. Knepley
753cc4c1da9SBarry Smith Not Collective, No Fortran Support
7543ec46b7bSMatthew G. Knepley
7553ec46b7bSMatthew G. Knepley Input Parameter:
7563ec46b7bSMatthew G. Knepley . s - the `PetscSection`
7573ec46b7bSMatthew G. Knepley
7583ec46b7bSMatthew G. Knepley Output Parameter:
7593ec46b7bSMatthew G. Knepley . blockStarts - The `PetscBT` with a 1 for each point that begins a block
7603ec46b7bSMatthew G. Knepley
7613ec46b7bSMatthew G. Knepley Notes:
7623ec46b7bSMatthew G. Knepley The table is on [0, `pEnd` - `pStart`).
7633ec46b7bSMatthew G. Knepley
7643ec46b7bSMatthew G. Knepley This information is used by `DMCreateMatrix()` to create a variable block size description which is set using `MatSetVariableBlockSizes()`.
7653ec46b7bSMatthew G. Knepley
7663ec46b7bSMatthew G. Knepley Level: intermediate
7673ec46b7bSMatthew G. Knepley
7683ec46b7bSMatthew G. Knepley .seealso: [](sec_scatter), `IS`, `PetscSection`, `PetscSectionSetBlockStarts()`, `PetscSectionCreate()`, `DMCreateMatrix()`, `MatSetVariableBlockSizes()`
7693ec46b7bSMatthew G. Knepley @*/
PetscSectionGetBlockStarts(PetscSection s,PetscBT * blockStarts)7703ec46b7bSMatthew G. Knepley PetscErrorCode PetscSectionGetBlockStarts(PetscSection s, PetscBT *blockStarts)
7713ec46b7bSMatthew G. Knepley {
7723ec46b7bSMatthew G. Knepley PetscFunctionBegin;
7733ec46b7bSMatthew G. Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
7743ec46b7bSMatthew G. Knepley if (blockStarts) {
7753ec46b7bSMatthew G. Knepley PetscAssertPointer(blockStarts, 2);
7763ec46b7bSMatthew G. Knepley *blockStarts = s->blockStarts;
7773ec46b7bSMatthew G. Knepley }
7783ec46b7bSMatthew G. Knepley PetscFunctionReturn(PETSC_SUCCESS);
7793ec46b7bSMatthew G. Knepley }
7803ec46b7bSMatthew G. Knepley
7813ec46b7bSMatthew G. Knepley /*@C
7823ec46b7bSMatthew G. Knepley PetscSectionSetBlockStarts - Sets a table indicating which points start new blocks
7833ec46b7bSMatthew G. Knepley
784cc4c1da9SBarry Smith Not Collective, No Fortran Support
7853ec46b7bSMatthew G. Knepley
7863ec46b7bSMatthew G. Knepley Input Parameters:
7873ec46b7bSMatthew G. Knepley + s - the `PetscSection`
7883ec46b7bSMatthew G. Knepley - blockStarts - The `PetscBT` with a 1 for each point that begins a block
7893ec46b7bSMatthew G. Knepley
7903ec46b7bSMatthew G. Knepley Level: intermediate
7913ec46b7bSMatthew G. Knepley
7923ec46b7bSMatthew G. Knepley Notes:
7933ec46b7bSMatthew G. Knepley The table is on [0, `pEnd` - `pStart`). PETSc takes ownership of the `PetscBT` when it is passed in and will destroy it. The user should not destroy it.
7943ec46b7bSMatthew G. Knepley
7953ec46b7bSMatthew G. Knepley This information is used by `DMCreateMatrix()` to create a variable block size description which is set using `MatSetVariableBlockSizes()`.
7963ec46b7bSMatthew G. Knepley
7973ec46b7bSMatthew G. Knepley .seealso: [](sec_scatter), `IS`, `PetscSection`, `PetscSectionGetBlockStarts()`, `PetscSectionCreate()`, `DMCreateMatrix()`, `MatSetVariableBlockSizes()`
7983ec46b7bSMatthew G. Knepley @*/
PetscSectionSetBlockStarts(PetscSection s,PetscBT blockStarts)7993ec46b7bSMatthew G. Knepley PetscErrorCode PetscSectionSetBlockStarts(PetscSection s, PetscBT blockStarts)
8003ec46b7bSMatthew G. Knepley {
8013ec46b7bSMatthew G. Knepley PetscFunctionBegin;
8023ec46b7bSMatthew G. Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
8033ec46b7bSMatthew G. Knepley if (s->blockStarts != blockStarts) {
8043ec46b7bSMatthew G. Knepley PetscCall(PetscBTDestroy(&s->blockStarts));
8053ec46b7bSMatthew G. Knepley s->blockStarts = blockStarts;
8063ec46b7bSMatthew G. Knepley }
8073ec46b7bSMatthew G. Knepley PetscFunctionReturn(PETSC_SUCCESS);
8083ec46b7bSMatthew G. Knepley }
8093ec46b7bSMatthew G. Knepley
810ea844a1aSMatthew Knepley /*@
811cab54364SBarry Smith PetscSectionGetPointMajor - Returns the flag for dof ordering, `PETSC_TRUE` if it is point major, `PETSC_FALSE` if it is field major
812ea844a1aSMatthew Knepley
81340750d41SVaclav Hapla Not Collective
814ea844a1aSMatthew Knepley
815ea844a1aSMatthew Knepley Input Parameter:
816cab54364SBarry Smith . s - the `PetscSection`
817ea844a1aSMatthew Knepley
818ea844a1aSMatthew Knepley Output Parameter:
819ea844a1aSMatthew Knepley . pm - the flag for point major ordering
820ea844a1aSMatthew Knepley
821ea844a1aSMatthew Knepley Level: intermediate
822ea844a1aSMatthew Knepley
823b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionSetPointMajor()`
824ea844a1aSMatthew Knepley @*/
PetscSectionGetPointMajor(PetscSection s,PetscBool * pm)825d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetPointMajor(PetscSection s, PetscBool *pm)
826d71ae5a4SJacob Faibussowitsch {
827ea844a1aSMatthew Knepley PetscFunctionBegin;
828ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
8294f572ea9SToby Isaac PetscAssertPointer(pm, 2);
830ea844a1aSMatthew Knepley *pm = s->pointMajor;
8313ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
832ea844a1aSMatthew Knepley }
833ea844a1aSMatthew Knepley
834ea844a1aSMatthew Knepley /*@
835cab54364SBarry Smith PetscSectionSetPointMajor - Sets the flag for dof ordering, `PETSC_TRUE` for point major, otherwise it will be field major
836ea844a1aSMatthew Knepley
83740750d41SVaclav Hapla Not Collective
838ea844a1aSMatthew Knepley
839ea844a1aSMatthew Knepley Input Parameters:
840cab54364SBarry Smith + s - the `PetscSection`
841ea844a1aSMatthew Knepley - pm - the flag for point major ordering
842ea844a1aSMatthew Knepley
843ea844a1aSMatthew Knepley Level: intermediate
844ea844a1aSMatthew Knepley
845583308b6SBarry Smith Note:
846583308b6SBarry Smith Field-major order is not recommended unless you are managing the entire problem yourself, since many higher-level functions in PETSc depend on point-major order.
847583308b6SBarry Smith
848583308b6SBarry Smith Point major order means the degrees of freedom are stored as follows
849583308b6SBarry Smith .vb
85011e840c0SPierre Jolivet all the degrees of freedom for each point are stored contiguously, one point after another (respecting a permutation set with `PetscSectionSetPermutation()`)
851583308b6SBarry Smith for each point
852583308b6SBarry Smith the degrees of freedom for each field (starting with the unnamed default field) are listed in order by field
853583308b6SBarry Smith .ve
854583308b6SBarry Smith
855583308b6SBarry Smith Field major order means the degrees of freedom are stored as follows
856583308b6SBarry Smith .vb
85711e840c0SPierre Jolivet all degrees of freedom for each field (including the unnamed default field) are stored contiguously, one field after another
858583308b6SBarry Smith for each field (started with unnamed default field)
859583308b6SBarry Smith the degrees of freedom for each point are listed in order by point (respecting a permutation set with `PetscSectionSetPermutation()`)
860583308b6SBarry Smith .ve
861583308b6SBarry Smith
862b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetPointMajor()`, `PetscSectionSetPermutation()`
863ea844a1aSMatthew Knepley @*/
PetscSectionSetPointMajor(PetscSection s,PetscBool pm)864d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetPointMajor(PetscSection s, PetscBool pm)
865d71ae5a4SJacob Faibussowitsch {
866ea844a1aSMatthew Knepley PetscFunctionBegin;
867ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
86828b400f6SJacob Faibussowitsch PetscCheck(!s->setup, PetscObjectComm((PetscObject)s), PETSC_ERR_ARG_WRONGSTATE, "Cannot set the dof ordering after the section is setup");
869ea844a1aSMatthew Knepley s->pointMajor = pm;
8703ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
871ea844a1aSMatthew Knepley }
872ea844a1aSMatthew Knepley
873ea844a1aSMatthew Knepley /*@
874cab54364SBarry Smith PetscSectionGetIncludesConstraints - Returns the flag indicating if constrained dofs were included when computing offsets in the `PetscSection`.
875cab54364SBarry Smith The value is set with `PetscSectionSetIncludesConstraints()`
87687e637c6Sksagiyam
87740750d41SVaclav Hapla Not Collective
87887e637c6Sksagiyam
87987e637c6Sksagiyam Input Parameter:
880cab54364SBarry Smith . s - the `PetscSection`
88187e637c6Sksagiyam
88287e637c6Sksagiyam Output Parameter:
88387e637c6Sksagiyam . includesConstraints - the flag indicating if constrained dofs were included when computing offsets
88487e637c6Sksagiyam
88587e637c6Sksagiyam Level: intermediate
88687e637c6Sksagiyam
887b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionSetIncludesConstraints()`
88887e637c6Sksagiyam @*/
PetscSectionGetIncludesConstraints(PetscSection s,PetscBool * includesConstraints)889d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetIncludesConstraints(PetscSection s, PetscBool *includesConstraints)
890d71ae5a4SJacob Faibussowitsch {
89187e637c6Sksagiyam PetscFunctionBegin;
89287e637c6Sksagiyam PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
8934f572ea9SToby Isaac PetscAssertPointer(includesConstraints, 2);
89487e637c6Sksagiyam *includesConstraints = s->includesConstraints;
8953ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
89687e637c6Sksagiyam }
89787e637c6Sksagiyam
89887e637c6Sksagiyam /*@
89987e637c6Sksagiyam PetscSectionSetIncludesConstraints - Sets the flag indicating if constrained dofs are to be included when computing offsets
90087e637c6Sksagiyam
90140750d41SVaclav Hapla Not Collective
90287e637c6Sksagiyam
90387e637c6Sksagiyam Input Parameters:
90420662ed9SBarry Smith + s - the `PetscSection`
90587e637c6Sksagiyam - includesConstraints - the flag indicating if constrained dofs are to be included when computing offsets
90687e637c6Sksagiyam
90787e637c6Sksagiyam Level: intermediate
90887e637c6Sksagiyam
909b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetIncludesConstraints()`
91087e637c6Sksagiyam @*/
PetscSectionSetIncludesConstraints(PetscSection s,PetscBool includesConstraints)911d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetIncludesConstraints(PetscSection s, PetscBool includesConstraints)
912d71ae5a4SJacob Faibussowitsch {
91387e637c6Sksagiyam PetscFunctionBegin;
91487e637c6Sksagiyam PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
91528b400f6SJacob Faibussowitsch PetscCheck(!s->setup, PetscObjectComm((PetscObject)s), PETSC_ERR_ARG_WRONGSTATE, "Cannot set includesConstraints after the section is set up");
91687e637c6Sksagiyam s->includesConstraints = includesConstraints;
9173ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
91887e637c6Sksagiyam }
91987e637c6Sksagiyam
92087e637c6Sksagiyam /*@
921583308b6SBarry Smith PetscSectionGetDof - Return the total number of degrees of freedom associated with a given point.
922ea844a1aSMatthew Knepley
92340750d41SVaclav Hapla Not Collective
924ea844a1aSMatthew Knepley
925ea844a1aSMatthew Knepley Input Parameters:
926cab54364SBarry Smith + s - the `PetscSection`
927ea844a1aSMatthew Knepley - point - the point
928ea844a1aSMatthew Knepley
929ea844a1aSMatthew Knepley Output Parameter:
930ea844a1aSMatthew Knepley . numDof - the number of dof
931ea844a1aSMatthew Knepley
932583308b6SBarry Smith Level: intermediate
933583308b6SBarry Smith
934583308b6SBarry Smith Notes:
935db527f05SMatthew G. Knepley In a global section, this size will be negative for points not owned by this process.
936db527f05SMatthew G. Knepley
937583308b6SBarry Smith This number is for the unnamed default field at the given point plus all degrees of freedom associated with all fields at that point
938ea844a1aSMatthew Knepley
939b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionSetDof()`, `PetscSectionCreate()`
940ea844a1aSMatthew Knepley @*/
PetscSectionGetDof(PetscSection s,PetscInt point,PetscInt * numDof)941d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetDof(PetscSection s, PetscInt point, PetscInt *numDof)
942d71ae5a4SJacob Faibussowitsch {
94376bd3646SJed Brown PetscFunctionBeginHot;
944ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
9454f572ea9SToby Isaac PetscAssertPointer(numDof, 3);
946b498ca8aSPierre Jolivet PetscAssert(point >= s->pStart && point < s->pEnd, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section point %" PetscInt_FMT " should be in [%" PetscInt_FMT ", %" PetscInt_FMT ")", point, s->pStart, s->pEnd);
947ea844a1aSMatthew Knepley *numDof = s->atlasDof[point - s->pStart];
9483ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
949ea844a1aSMatthew Knepley }
950ea844a1aSMatthew Knepley
951ea844a1aSMatthew Knepley /*@
952583308b6SBarry Smith PetscSectionSetDof - Sets the total number of degrees of freedom associated with a given point.
953ea844a1aSMatthew Knepley
95440750d41SVaclav Hapla Not Collective
955ea844a1aSMatthew Knepley
956ea844a1aSMatthew Knepley Input Parameters:
957cab54364SBarry Smith + s - the `PetscSection`
958ea844a1aSMatthew Knepley . point - the point
959376335faSBarry Smith - numDof - the number of dof, these values may be negative -(dof+1) to indicate they are off process
960ea844a1aSMatthew Knepley
961ea844a1aSMatthew Knepley Level: intermediate
962ea844a1aSMatthew Knepley
963583308b6SBarry Smith Note:
964583308b6SBarry Smith This number is for the unnamed default field at the given point plus all degrees of freedom associated with all fields at that point
965583308b6SBarry Smith
966b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetDof()`, `PetscSectionAddDof()`, `PetscSectionCreate()`
967ea844a1aSMatthew Knepley @*/
PetscSectionSetDof(PetscSection s,PetscInt point,PetscInt numDof)968d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetDof(PetscSection s, PetscInt point, PetscInt numDof)
969d71ae5a4SJacob Faibussowitsch {
970ea844a1aSMatthew Knepley PetscFunctionBegin;
971ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
972c8bf3acbSVaclav Hapla PetscAssert(point >= s->pStart && point < s->pEnd, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section point %" PetscInt_FMT " should be in [%" PetscInt_FMT ", %" PetscInt_FMT ")", point, s->pStart, s->pEnd);
973ea844a1aSMatthew Knepley s->atlasDof[point - s->pStart] = numDof;
97469c11d05SVaclav Hapla PetscCall(PetscSectionInvalidateMaxDof_Internal(s));
9753ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
976ea844a1aSMatthew Knepley }
977ea844a1aSMatthew Knepley
978ea844a1aSMatthew Knepley /*@
979583308b6SBarry Smith PetscSectionAddDof - Adds to the total number of degrees of freedom associated with a given point.
980ea844a1aSMatthew Knepley
98140750d41SVaclav Hapla Not Collective
982ea844a1aSMatthew Knepley
983ea844a1aSMatthew Knepley Input Parameters:
984cab54364SBarry Smith + s - the `PetscSection`
985ea844a1aSMatthew Knepley . point - the point
986ea844a1aSMatthew Knepley - numDof - the number of additional dof
987ea844a1aSMatthew Knepley
988ea844a1aSMatthew Knepley Level: intermediate
989ea844a1aSMatthew Knepley
990583308b6SBarry Smith Note:
991583308b6SBarry Smith This number is for the unnamed default field at the given point plus all degrees of freedom associated with all fields at that point
992583308b6SBarry Smith
993b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetDof()`, `PetscSectionSetDof()`, `PetscSectionCreate()`
994ea844a1aSMatthew Knepley @*/
PetscSectionAddDof(PetscSection s,PetscInt point,PetscInt numDof)995d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionAddDof(PetscSection s, PetscInt point, PetscInt numDof)
996d71ae5a4SJacob Faibussowitsch {
99776bd3646SJed Brown PetscFunctionBeginHot;
998ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
999b498ca8aSPierre Jolivet PetscAssert(point >= s->pStart && point < s->pEnd, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section point %" PetscInt_FMT " should be in [%" PetscInt_FMT ", %" PetscInt_FMT ")", point, s->pStart, s->pEnd);
100040196513SBarry Smith PetscCheck(numDof >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "numDof %" PetscInt_FMT " should not be negative", numDof);
1001ea844a1aSMatthew Knepley s->atlasDof[point - s->pStart] += numDof;
100269c11d05SVaclav Hapla PetscCall(PetscSectionInvalidateMaxDof_Internal(s));
10033ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1004ea844a1aSMatthew Knepley }
1005ea844a1aSMatthew Knepley
1006ea844a1aSMatthew Knepley /*@
1007ea844a1aSMatthew Knepley PetscSectionGetFieldDof - Return the number of degrees of freedom associated with a field on a given point.
1008ea844a1aSMatthew Knepley
100940750d41SVaclav Hapla Not Collective
1010ea844a1aSMatthew Knepley
1011ea844a1aSMatthew Knepley Input Parameters:
1012cab54364SBarry Smith + s - the `PetscSection`
1013ea844a1aSMatthew Knepley . point - the point
1014ea844a1aSMatthew Knepley - field - the field
1015ea844a1aSMatthew Knepley
1016ea844a1aSMatthew Knepley Output Parameter:
1017ea844a1aSMatthew Knepley . numDof - the number of dof
1018ea844a1aSMatthew Knepley
1019ea844a1aSMatthew Knepley Level: intermediate
1020ea844a1aSMatthew Knepley
1021b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionSetFieldDof()`, `PetscSectionCreate()`
1022ea844a1aSMatthew Knepley @*/
PetscSectionGetFieldDof(PetscSection s,PetscInt point,PetscInt field,PetscInt * numDof)1023d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldDof(PetscSection s, PetscInt point, PetscInt field, PetscInt *numDof)
1024d71ae5a4SJacob Faibussowitsch {
1025ea844a1aSMatthew Knepley PetscFunctionBegin;
1026ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
10274f572ea9SToby Isaac PetscAssertPointer(numDof, 4);
10282abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields);
10299566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s->field[field], point, numDof));
10303ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1031ea844a1aSMatthew Knepley }
1032ea844a1aSMatthew Knepley
1033ea844a1aSMatthew Knepley /*@
1034ea844a1aSMatthew Knepley PetscSectionSetFieldDof - Sets the number of degrees of freedom associated with a field on a given point.
1035ea844a1aSMatthew Knepley
103640750d41SVaclav Hapla Not Collective
1037ea844a1aSMatthew Knepley
1038ea844a1aSMatthew Knepley Input Parameters:
1039cab54364SBarry Smith + s - the `PetscSection`
1040ea844a1aSMatthew Knepley . point - the point
1041ea844a1aSMatthew Knepley . field - the field
1042376335faSBarry Smith - numDof - the number of dof, these values may be negative -(dof+1) to indicate they are off process
1043ea844a1aSMatthew Knepley
1044ea844a1aSMatthew Knepley Level: intermediate
1045ea844a1aSMatthew Knepley
1046583308b6SBarry Smith Note:
1047583308b6SBarry Smith When setting the number of dof for a field at a point one must also ensure the count of the total number of dof at the point (summed over
1048583308b6SBarry Smith the fields and the unnamed default field) is correct by also calling `PetscSectionAddDof()` or `PetscSectionSetDof()`
1049583308b6SBarry Smith
1050583308b6SBarry Smith This is equivalent to
1051583308b6SBarry Smith .vb
1052583308b6SBarry Smith PetscSection fs;
1053583308b6SBarry Smith PetscSectionGetField(s,field,&fs)
1054583308b6SBarry Smith PetscSectionSetDof(fs,numDof)
1055583308b6SBarry Smith .ve
1056583308b6SBarry Smith
1057b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetFieldDof()`, `PetscSectionCreate()`, `PetscSectionAddDof()`, `PetscSectionSetDof()`
1058ea844a1aSMatthew Knepley @*/
PetscSectionSetFieldDof(PetscSection s,PetscInt point,PetscInt field,PetscInt numDof)1059d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof)
1060d71ae5a4SJacob Faibussowitsch {
1061ea844a1aSMatthew Knepley PetscFunctionBegin;
1062ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
10632abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields);
10649566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(s->field[field], point, numDof));
10653ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1066ea844a1aSMatthew Knepley }
1067ea844a1aSMatthew Knepley
1068ea844a1aSMatthew Knepley /*@
1069ea844a1aSMatthew Knepley PetscSectionAddFieldDof - Adds a number of degrees of freedom associated with a field on a given point.
1070ea844a1aSMatthew Knepley
107140750d41SVaclav Hapla Not Collective
1072ea844a1aSMatthew Knepley
1073ea844a1aSMatthew Knepley Input Parameters:
1074cab54364SBarry Smith + s - the `PetscSection`
1075ea844a1aSMatthew Knepley . point - the point
1076ea844a1aSMatthew Knepley . field - the field
1077ea844a1aSMatthew Knepley - numDof - the number of dof
1078ea844a1aSMatthew Knepley
1079ea844a1aSMatthew Knepley Level: intermediate
1080ea844a1aSMatthew Knepley
1081583308b6SBarry Smith Notes:
1082583308b6SBarry Smith When adding to the number of dof for a field at a point one must also ensure the count of the total number of dof at the point (summed over
1083583308b6SBarry Smith the fields and the unnamed default field) is correct by also calling `PetscSectionAddDof()` or `PetscSectionSetDof()`
1084583308b6SBarry Smith
1085583308b6SBarry Smith This is equivalent to
1086583308b6SBarry Smith .vb
1087583308b6SBarry Smith PetscSection fs;
1088583308b6SBarry Smith PetscSectionGetField(s,field,&fs)
1089583308b6SBarry Smith PetscSectionAddDof(fs,numDof)
1090583308b6SBarry Smith .ve
1091583308b6SBarry Smith
1092b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionSetFieldDof()`, `PetscSectionGetFieldDof()`, `PetscSectionCreate()`
1093ea844a1aSMatthew Knepley @*/
PetscSectionAddFieldDof(PetscSection s,PetscInt point,PetscInt field,PetscInt numDof)1094d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionAddFieldDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof)
1095d71ae5a4SJacob Faibussowitsch {
1096ea844a1aSMatthew Knepley PetscFunctionBegin;
1097ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
10982abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields);
10999566063dSJacob Faibussowitsch PetscCall(PetscSectionAddDof(s->field[field], point, numDof));
11003ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1101ea844a1aSMatthew Knepley }
1102ea844a1aSMatthew Knepley
1103ea844a1aSMatthew Knepley /*@
1104ea844a1aSMatthew Knepley PetscSectionGetConstraintDof - Return the number of constrained degrees of freedom associated with a given point.
1105ea844a1aSMatthew Knepley
110640750d41SVaclav Hapla Not Collective
1107ea844a1aSMatthew Knepley
1108ea844a1aSMatthew Knepley Input Parameters:
1109cab54364SBarry Smith + s - the `PetscSection`
1110ea844a1aSMatthew Knepley - point - the point
1111ea844a1aSMatthew Knepley
1112ea844a1aSMatthew Knepley Output Parameter:
1113ea844a1aSMatthew Knepley . numDof - the number of dof which are fixed by constraints
1114ea844a1aSMatthew Knepley
1115ea844a1aSMatthew Knepley Level: intermediate
1116ea844a1aSMatthew Knepley
1117b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetDof()`, `PetscSectionSetConstraintDof()`, `PetscSectionCreate()`
1118ea844a1aSMatthew Knepley @*/
PetscSectionGetConstraintDof(PetscSection s,PetscInt point,PetscInt * numDof)1119d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetConstraintDof(PetscSection s, PetscInt point, PetscInt *numDof)
1120d71ae5a4SJacob Faibussowitsch {
1121ea844a1aSMatthew Knepley PetscFunctionBegin;
1122ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
11234f572ea9SToby Isaac PetscAssertPointer(numDof, 3);
1124ac530a7eSPierre Jolivet if (s->bc) PetscCall(PetscSectionGetDof(s->bc, point, numDof));
1125ac530a7eSPierre Jolivet else *numDof = 0;
11263ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1127ea844a1aSMatthew Knepley }
1128ea844a1aSMatthew Knepley
1129ea844a1aSMatthew Knepley /*@
1130ea844a1aSMatthew Knepley PetscSectionSetConstraintDof - Set the number of constrained degrees of freedom associated with a given point.
1131ea844a1aSMatthew Knepley
113240750d41SVaclav Hapla Not Collective
1133ea844a1aSMatthew Knepley
1134ea844a1aSMatthew Knepley Input Parameters:
1135cab54364SBarry Smith + s - the `PetscSection`
1136ea844a1aSMatthew Knepley . point - the point
1137ea844a1aSMatthew Knepley - numDof - the number of dof which are fixed by constraints
1138ea844a1aSMatthew Knepley
1139ea844a1aSMatthew Knepley Level: intermediate
1140ea844a1aSMatthew Knepley
1141b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionSetDof()`, `PetscSectionGetConstraintDof()`, `PetscSectionCreate()`
1142ea844a1aSMatthew Knepley @*/
PetscSectionSetConstraintDof(PetscSection s,PetscInt point,PetscInt numDof)1143d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetConstraintDof(PetscSection s, PetscInt point, PetscInt numDof)
1144d71ae5a4SJacob Faibussowitsch {
1145ea844a1aSMatthew Knepley PetscFunctionBegin;
1146ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
1147ea844a1aSMatthew Knepley if (numDof) {
11487c0883d5SVaclav Hapla PetscCall(PetscSectionCheckConstraints_Private(s));
11499566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(s->bc, point, numDof));
1150ea844a1aSMatthew Knepley }
11513ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1152ea844a1aSMatthew Knepley }
1153ea844a1aSMatthew Knepley
1154ea844a1aSMatthew Knepley /*@
1155ea844a1aSMatthew Knepley PetscSectionAddConstraintDof - Increment the number of constrained degrees of freedom associated with a given point.
1156ea844a1aSMatthew Knepley
115740750d41SVaclav Hapla Not Collective
1158ea844a1aSMatthew Knepley
1159ea844a1aSMatthew Knepley Input Parameters:
1160cab54364SBarry Smith + s - the `PetscSection`
1161ea844a1aSMatthew Knepley . point - the point
1162ea844a1aSMatthew Knepley - numDof - the number of additional dof which are fixed by constraints
1163ea844a1aSMatthew Knepley
1164ea844a1aSMatthew Knepley Level: intermediate
1165ea844a1aSMatthew Knepley
1166b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionAddDof()`, `PetscSectionGetConstraintDof()`, `PetscSectionCreate()`
1167ea844a1aSMatthew Knepley @*/
PetscSectionAddConstraintDof(PetscSection s,PetscInt point,PetscInt numDof)1168d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionAddConstraintDof(PetscSection s, PetscInt point, PetscInt numDof)
1169d71ae5a4SJacob Faibussowitsch {
1170ea844a1aSMatthew Knepley PetscFunctionBegin;
1171ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
1172ea844a1aSMatthew Knepley if (numDof) {
11737c0883d5SVaclav Hapla PetscCall(PetscSectionCheckConstraints_Private(s));
11749566063dSJacob Faibussowitsch PetscCall(PetscSectionAddDof(s->bc, point, numDof));
1175ea844a1aSMatthew Knepley }
11763ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1177ea844a1aSMatthew Knepley }
1178ea844a1aSMatthew Knepley
1179ea844a1aSMatthew Knepley /*@
1180ea844a1aSMatthew Knepley PetscSectionGetFieldConstraintDof - Return the number of constrained degrees of freedom associated with a given field on a point.
1181ea844a1aSMatthew Knepley
118240750d41SVaclav Hapla Not Collective
1183ea844a1aSMatthew Knepley
1184ea844a1aSMatthew Knepley Input Parameters:
1185cab54364SBarry Smith + s - the `PetscSection`
1186ea844a1aSMatthew Knepley . point - the point
1187ea844a1aSMatthew Knepley - field - the field
1188ea844a1aSMatthew Knepley
1189ea844a1aSMatthew Knepley Output Parameter:
1190ea844a1aSMatthew Knepley . numDof - the number of dof which are fixed by constraints
1191ea844a1aSMatthew Knepley
1192ea844a1aSMatthew Knepley Level: intermediate
1193ea844a1aSMatthew Knepley
1194b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetDof()`, `PetscSectionSetFieldConstraintDof()`, `PetscSectionCreate()`
1195ea844a1aSMatthew Knepley @*/
PetscSectionGetFieldConstraintDof(PetscSection s,PetscInt point,PetscInt field,PetscInt * numDof)1196d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldConstraintDof(PetscSection s, PetscInt point, PetscInt field, PetscInt *numDof)
1197d71ae5a4SJacob Faibussowitsch {
1198ea844a1aSMatthew Knepley PetscFunctionBegin;
1199ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
12004f572ea9SToby Isaac PetscAssertPointer(numDof, 4);
12012abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields);
12029566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s->field[field], point, numDof));
12033ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1204ea844a1aSMatthew Knepley }
1205ea844a1aSMatthew Knepley
1206ea844a1aSMatthew Knepley /*@
1207ea844a1aSMatthew Knepley PetscSectionSetFieldConstraintDof - Set the number of constrained degrees of freedom associated with a given field on a point.
1208ea844a1aSMatthew Knepley
120940750d41SVaclav Hapla Not Collective
1210ea844a1aSMatthew Knepley
1211ea844a1aSMatthew Knepley Input Parameters:
1212cab54364SBarry Smith + s - the `PetscSection`
1213ea844a1aSMatthew Knepley . point - the point
1214ea844a1aSMatthew Knepley . field - the field
1215ea844a1aSMatthew Knepley - numDof - the number of dof which are fixed by constraints
1216ea844a1aSMatthew Knepley
1217ea844a1aSMatthew Knepley Level: intermediate
1218ea844a1aSMatthew Knepley
1219b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionSetDof()`, `PetscSectionGetFieldConstraintDof()`, `PetscSectionCreate()`
1220ea844a1aSMatthew Knepley @*/
PetscSectionSetFieldConstraintDof(PetscSection s,PetscInt point,PetscInt field,PetscInt numDof)1221d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldConstraintDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof)
1222d71ae5a4SJacob Faibussowitsch {
1223ea844a1aSMatthew Knepley PetscFunctionBegin;
1224ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
12252abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields);
12269566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintDof(s->field[field], point, numDof));
12273ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1228ea844a1aSMatthew Knepley }
1229ea844a1aSMatthew Knepley
1230ea844a1aSMatthew Knepley /*@
1231ea844a1aSMatthew Knepley PetscSectionAddFieldConstraintDof - Increment the number of constrained degrees of freedom associated with a given field on a point.
1232ea844a1aSMatthew Knepley
123340750d41SVaclav Hapla Not Collective
1234ea844a1aSMatthew Knepley
1235ea844a1aSMatthew Knepley Input Parameters:
1236cab54364SBarry Smith + s - the `PetscSection`
1237ea844a1aSMatthew Knepley . point - the point
1238ea844a1aSMatthew Knepley . field - the field
1239ea844a1aSMatthew Knepley - numDof - the number of additional dof which are fixed by constraints
1240ea844a1aSMatthew Knepley
1241ea844a1aSMatthew Knepley Level: intermediate
1242ea844a1aSMatthew Knepley
1243b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionAddDof()`, `PetscSectionGetFieldConstraintDof()`, `PetscSectionCreate()`
1244ea844a1aSMatthew Knepley @*/
PetscSectionAddFieldConstraintDof(PetscSection s,PetscInt point,PetscInt field,PetscInt numDof)1245d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionAddFieldConstraintDof(PetscSection s, PetscInt point, PetscInt field, PetscInt numDof)
1246d71ae5a4SJacob Faibussowitsch {
1247ea844a1aSMatthew Knepley PetscFunctionBegin;
1248ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
12492abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields);
12509566063dSJacob Faibussowitsch PetscCall(PetscSectionAddConstraintDof(s->field[field], point, numDof));
12513ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1252ea844a1aSMatthew Knepley }
1253ea844a1aSMatthew Knepley
1254ea844a1aSMatthew Knepley /*@
1255ea844a1aSMatthew Knepley PetscSectionSetUpBC - Setup the subsections describing boundary conditions.
1256ea844a1aSMatthew Knepley
125740750d41SVaclav Hapla Not Collective
1258ea844a1aSMatthew Knepley
1259ea844a1aSMatthew Knepley Input Parameter:
1260cab54364SBarry Smith . s - the `PetscSection`
1261ea844a1aSMatthew Knepley
1262ea844a1aSMatthew Knepley Level: advanced
1263ea844a1aSMatthew Knepley
1264b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionSetUp()`, `PetscSectionCreate()`
1265ea844a1aSMatthew Knepley @*/
PetscSectionSetUpBC(PetscSection s)1266d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetUpBC(PetscSection s)
1267d71ae5a4SJacob Faibussowitsch {
1268ea844a1aSMatthew Knepley PetscFunctionBegin;
1269ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
1270ea844a1aSMatthew Knepley if (s->bc) {
1271ea844a1aSMatthew Knepley const PetscInt last = (s->bc->pEnd - s->bc->pStart) - 1;
1272ea844a1aSMatthew Knepley
12739566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(s->bc));
1274ea17275aSJose E. Roman if (last >= 0) PetscCall(PetscMalloc1(s->bc->atlasOff[last] + s->bc->atlasDof[last], &s->bcIndices));
1275ea17275aSJose E. Roman else s->bcIndices = NULL;
1276ea844a1aSMatthew Knepley }
12773ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1278ea844a1aSMatthew Knepley }
1279ea844a1aSMatthew Knepley
1280ea844a1aSMatthew Knepley /*@
1281583308b6SBarry Smith PetscSectionSetUp - Calculate offsets based upon the number of degrees of freedom for each point in preparation for use of the `PetscSection`
1282ea844a1aSMatthew Knepley
128340750d41SVaclav Hapla Not Collective
1284ea844a1aSMatthew Knepley
1285ea844a1aSMatthew Knepley Input Parameter:
1286cab54364SBarry Smith . s - the `PetscSection`
1287ea844a1aSMatthew Knepley
1288ea844a1aSMatthew Knepley Level: intermediate
1289ea844a1aSMatthew Knepley
1290583308b6SBarry Smith Notes:
1291583308b6SBarry Smith If used, `PetscSectionSetPermutation()` must be called before this routine.
1292583308b6SBarry Smith
1293583308b6SBarry Smith `PetscSectionSetPointMajor()`, cannot be called after this routine.
1294583308b6SBarry Smith
1295b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionSetPermutation()`
1296ea844a1aSMatthew Knepley @*/
PetscSectionSetUp(PetscSection s)1297d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetUp(PetscSection s)
1298d71ae5a4SJacob Faibussowitsch {
1299357d8704SBarry Smith PetscInt f;
1300ea844a1aSMatthew Knepley const PetscInt *pind = NULL;
13016497c311SBarry Smith PetscCount offset = 0;
1302ea844a1aSMatthew Knepley
1303ea844a1aSMatthew Knepley PetscFunctionBegin;
1304ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
13053ba16761SJacob Faibussowitsch if (s->setup) PetscFunctionReturn(PETSC_SUCCESS);
1306ea844a1aSMatthew Knepley s->setup = PETSC_TRUE;
1307ea844a1aSMatthew Knepley /* Set offsets and field offsets for all points */
1308ea844a1aSMatthew Knepley /* Assume that all fields have the same chart */
130928b400f6SJacob Faibussowitsch PetscCheck(s->includesConstraints, PETSC_COMM_SELF, PETSC_ERR_SUP, "PetscSectionSetUp is currently unsupported for includesConstraints = PETSC_TRUE");
13109566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISGetIndices(s->perm, &pind));
1311ea844a1aSMatthew Knepley if (s->pointMajor) {
13126497c311SBarry Smith PetscCount foff;
1313357d8704SBarry Smith for (PetscInt p = 0; p < s->pEnd - s->pStart; ++p) {
1314ea844a1aSMatthew Knepley const PetscInt q = pind ? pind[p] : p;
1315ea844a1aSMatthew Knepley
1316ea844a1aSMatthew Knepley /* Set point offset */
1317357d8704SBarry Smith PetscCall(PetscIntCast(offset, &s->atlasOff[q]));
1318ea844a1aSMatthew Knepley offset += s->atlasDof[q];
1319ea844a1aSMatthew Knepley /* Set field offset */
1320ea844a1aSMatthew Knepley for (f = 0, foff = s->atlasOff[q]; f < s->numFields; ++f) {
1321ea844a1aSMatthew Knepley PetscSection sf = s->field[f];
1322ea844a1aSMatthew Knepley
1323357d8704SBarry Smith PetscCall(PetscIntCast(foff, &sf->atlasOff[q]));
1324ea844a1aSMatthew Knepley foff += sf->atlasDof[q];
1325ea844a1aSMatthew Knepley }
1326ea844a1aSMatthew Knepley }
1327ea844a1aSMatthew Knepley } else {
1328ea844a1aSMatthew Knepley /* Set field offsets for all points */
1329ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) {
1330ea844a1aSMatthew Knepley PetscSection sf = s->field[f];
1331ea844a1aSMatthew Knepley
1332357d8704SBarry Smith for (PetscInt p = 0; p < s->pEnd - s->pStart; ++p) {
1333ea844a1aSMatthew Knepley const PetscInt q = pind ? pind[p] : p;
1334ea844a1aSMatthew Knepley
1335357d8704SBarry Smith PetscCall(PetscIntCast(offset, &sf->atlasOff[q]));
1336ea844a1aSMatthew Knepley offset += sf->atlasDof[q];
1337ea844a1aSMatthew Knepley }
1338ea844a1aSMatthew Knepley }
1339ea844a1aSMatthew Knepley /* Disable point offsets since these are unused */
1340357d8704SBarry Smith for (PetscInt p = 0; p < s->pEnd - s->pStart; ++p) s->atlasOff[p] = -1;
1341ea844a1aSMatthew Knepley }
13429566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISRestoreIndices(s->perm, &pind));
1343ea844a1aSMatthew Knepley /* Setup BC sections */
13449566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUpBC(s));
13459566063dSJacob Faibussowitsch for (f = 0; f < s->numFields; ++f) PetscCall(PetscSectionSetUpBC(s->field[f]));
13463ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1347ea844a1aSMatthew Knepley }
1348ea844a1aSMatthew Knepley
1349ea844a1aSMatthew Knepley /*@
135020662ed9SBarry Smith PetscSectionGetMaxDof - Return the maximum number of degrees of freedom on any point in the `PetscSection`
1351ea844a1aSMatthew Knepley
135240750d41SVaclav Hapla Not Collective
1353ea844a1aSMatthew Knepley
13542fe279fdSBarry Smith Input Parameter:
1355cab54364SBarry Smith . s - the `PetscSection`
1356ea844a1aSMatthew Knepley
1357ea844a1aSMatthew Knepley Output Parameter:
1358ea844a1aSMatthew Knepley . maxDof - the maximum dof
1359ea844a1aSMatthew Knepley
1360ea844a1aSMatthew Knepley Level: intermediate
1361ea844a1aSMatthew Knepley
1362583308b6SBarry Smith Notes:
1363cab54364SBarry Smith The returned number is up-to-date without need for `PetscSectionSetUp()`.
136469c11d05SVaclav Hapla
1365583308b6SBarry Smith This is the maximum over all points of the sum of the number of dof in the unnamed default field plus all named fields. This is equivalent to
1366583308b6SBarry Smith the maximum over all points of the value returned by `PetscSectionGetDof()` on this MPI process
1367583308b6SBarry Smith
1368583308b6SBarry Smith Developer Notes:
136969c11d05SVaclav Hapla The returned number is calculated lazily and stashed.
1370cab54364SBarry Smith
1371cab54364SBarry Smith A call to `PetscSectionInvalidateMaxDof_Internal()` invalidates the stashed value.
1372cab54364SBarry Smith
1373cab54364SBarry Smith `PetscSectionInvalidateMaxDof_Internal()` is called in `PetscSectionSetDof()`, `PetscSectionAddDof()` and `PetscSectionReset()`
1374cab54364SBarry Smith
137520662ed9SBarry Smith It should also be called every time `atlasDof` is modified directly.
137669c11d05SVaclav Hapla
1377b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetDof()`, `PetscSectionSetDof()`, `PetscSectionAddDof()`, `PetscSectionCreate()`
1378ea844a1aSMatthew Knepley @*/
PetscSectionGetMaxDof(PetscSection s,PetscInt * maxDof)1379d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetMaxDof(PetscSection s, PetscInt *maxDof)
1380d71ae5a4SJacob Faibussowitsch {
138169c11d05SVaclav Hapla PetscInt p;
138269c11d05SVaclav Hapla
1383ea844a1aSMatthew Knepley PetscFunctionBegin;
1384ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
13854f572ea9SToby Isaac PetscAssertPointer(maxDof, 2);
13861690c2aeSBarry Smith if (s->maxDof == PETSC_INT_MIN) {
138769c11d05SVaclav Hapla s->maxDof = 0;
1388ad540459SPierre Jolivet for (p = 0; p < s->pEnd - s->pStart; ++p) s->maxDof = PetscMax(s->maxDof, s->atlasDof[p]);
138969c11d05SVaclav Hapla }
1390ea844a1aSMatthew Knepley *maxDof = s->maxDof;
13913ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1392ea844a1aSMatthew Knepley }
1393ea844a1aSMatthew Knepley
1394ea844a1aSMatthew Knepley /*@
139520662ed9SBarry Smith PetscSectionGetStorageSize - Return the size of an array or local `Vec` capable of holding all the degrees of freedom defined in a `PetscSection`
1396ea844a1aSMatthew Knepley
139740750d41SVaclav Hapla Not Collective
1398ea844a1aSMatthew Knepley
1399ea844a1aSMatthew Knepley Input Parameter:
1400cab54364SBarry Smith . s - the `PetscSection`
1401ea844a1aSMatthew Knepley
1402ea844a1aSMatthew Knepley Output Parameter:
1403ea844a1aSMatthew Knepley . size - the size of an array which can hold all the dofs
1404ea844a1aSMatthew Knepley
1405ea844a1aSMatthew Knepley Level: intermediate
1406ea844a1aSMatthew Knepley
1407b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetOffset()`, `PetscSectionGetConstrainedStorageSize()`, `PetscSectionCreate()`
1408ea844a1aSMatthew Knepley @*/
PetscSectionGetStorageSize(PetscSection s,PetscInt * size)1409d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetStorageSize(PetscSection s, PetscInt *size)
1410d71ae5a4SJacob Faibussowitsch {
1411357d8704SBarry Smith PetscInt64 n = 0;
1412ea844a1aSMatthew Knepley
1413ea844a1aSMatthew Knepley PetscFunctionBegin;
1414ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
14154f572ea9SToby Isaac PetscAssertPointer(size, 2);
1416357d8704SBarry Smith for (PetscInt p = 0; p < s->pEnd - s->pStart; ++p) n += s->atlasDof[p] > 0 ? s->atlasDof[p] : 0;
1417357d8704SBarry Smith PetscCall(PetscIntCast(n, size));
14183ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1419ea844a1aSMatthew Knepley }
1420ea844a1aSMatthew Knepley
1421ea844a1aSMatthew Knepley /*@
142220662ed9SBarry Smith PetscSectionGetConstrainedStorageSize - Return the size of an array or local `Vec` capable of holding all unconstrained degrees of freedom in a `PetscSection`
1423ea844a1aSMatthew Knepley
142440750d41SVaclav Hapla Not Collective
1425ea844a1aSMatthew Knepley
1426064ec1f3Sprj- Input Parameter:
1427cab54364SBarry Smith . s - the `PetscSection`
1428ea844a1aSMatthew Knepley
1429ea844a1aSMatthew Knepley Output Parameter:
1430ea844a1aSMatthew Knepley . size - the size of an array which can hold all unconstrained dofs
1431ea844a1aSMatthew Knepley
1432ea844a1aSMatthew Knepley Level: intermediate
1433ea844a1aSMatthew Knepley
1434b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetStorageSize()`, `PetscSectionGetOffset()`, `PetscSectionCreate()`
1435ea844a1aSMatthew Knepley @*/
PetscSectionGetConstrainedStorageSize(PetscSection s,PetscInt * size)1436d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetConstrainedStorageSize(PetscSection s, PetscInt *size)
1437d71ae5a4SJacob Faibussowitsch {
1438357d8704SBarry Smith PetscInt64 n = 0;
1439ea844a1aSMatthew Knepley
1440ea844a1aSMatthew Knepley PetscFunctionBegin;
1441ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
14424f572ea9SToby Isaac PetscAssertPointer(size, 2);
1443357d8704SBarry Smith for (PetscInt p = 0; p < s->pEnd - s->pStart; ++p) {
1444ea844a1aSMatthew Knepley const PetscInt cdof = s->bc ? s->bc->atlasDof[p] : 0;
1445ea844a1aSMatthew Knepley n += s->atlasDof[p] > 0 ? s->atlasDof[p] - cdof : 0;
1446ea844a1aSMatthew Knepley }
1447357d8704SBarry Smith PetscCall(PetscIntCast(n, size));
14483ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1449ea844a1aSMatthew Knepley }
1450ea844a1aSMatthew Knepley
1451ea844a1aSMatthew Knepley /*@
1452583308b6SBarry Smith PetscSectionCreateGlobalSection - Create a parallel section describing the global layout using
1453583308b6SBarry Smith a local (sequential) `PetscSection` on each MPI process and a `PetscSF` describing the section point overlap.
1454ea844a1aSMatthew Knepley
1455ea844a1aSMatthew Knepley Input Parameters:
1456cab54364SBarry Smith + s - The `PetscSection` for the local field layout
1457cab54364SBarry Smith . sf - The `PetscSF` describing parallel layout of the section points (leaves are unowned local points)
1458eb9d3e4dSMatthew G. Knepley . usePermutation - By default this is `PETSC_TRUE`, meaning any permutation of the local section is transferred to the global section
1459cab54364SBarry Smith . includeConstraints - By default this is `PETSC_FALSE`, meaning that the global field vector will not possess constrained dofs
1460cab54364SBarry Smith - localOffsets - If `PETSC_TRUE`, use local rather than global offsets for the points
1461ea844a1aSMatthew Knepley
1462ea844a1aSMatthew Knepley Output Parameter:
1463cab54364SBarry Smith . gsection - The `PetscSection` for the global field layout
1464ea844a1aSMatthew Knepley
1465ea844a1aSMatthew Knepley Level: intermediate
1466ea844a1aSMatthew Knepley
1467db527f05SMatthew G. Knepley Notes:
1468583308b6SBarry Smith On each MPI process `gsection` inherits the chart of the `s` on that process.
1469db527f05SMatthew G. Knepley
1470583308b6SBarry Smith This sets negative sizes and offsets to points not owned by this process as defined by `sf` but that are within the local value of the chart of `gsection`.
1471583308b6SBarry Smith In those locations the value of size is -(size+1) and the value of the offset on the remote process is -(off+1).
1472cab54364SBarry Smith
1473b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionCreateGlobalSectionCensored()`
1474ea844a1aSMatthew Knepley @*/
PetscSectionCreateGlobalSection(PetscSection s,PetscSF sf,PetscBool usePermutation,PetscBool includeConstraints,PetscBool localOffsets,PetscSection * gsection)1475eb9d3e4dSMatthew G. Knepley PetscErrorCode PetscSectionCreateGlobalSection(PetscSection s, PetscSF sf, PetscBool usePermutation, PetscBool includeConstraints, PetscBool localOffsets, PetscSection *gsection)
1476d71ae5a4SJacob Faibussowitsch {
1477ea844a1aSMatthew Knepley PetscSection gs;
1478ea844a1aSMatthew Knepley const PetscInt *pind = NULL;
1479ea844a1aSMatthew Knepley PetscInt *recv = NULL, *neg = NULL;
1480357d8704SBarry Smith PetscInt pStart, pEnd, p, dof, cdof, off, globalOff = 0, nroots, nlocal, maxleaf;
1481046d2115Sksagiyam PetscInt numFields, f, numComponents;
1482835f2295SStefano Zampini PetscInt foff;
1483ea844a1aSMatthew Knepley
1484ea844a1aSMatthew Knepley PetscFunctionBegin;
1485ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
1486ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sf, PETSCSF_CLASSID, 2);
1487eb9d3e4dSMatthew G. Knepley PetscValidLogicalCollectiveBool(s, usePermutation, 3);
1488eb9d3e4dSMatthew G. Knepley PetscValidLogicalCollectiveBool(s, includeConstraints, 4);
1489eb9d3e4dSMatthew G. Knepley PetscValidLogicalCollectiveBool(s, localOffsets, 5);
1490eb9d3e4dSMatthew G. Knepley PetscAssertPointer(gsection, 6);
149128b400f6SJacob Faibussowitsch PetscCheck(s->pointMajor, PETSC_COMM_SELF, PETSC_ERR_SUP, "No support for field major ordering");
14929566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), &gs));
14939566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s, &numFields));
14949566063dSJacob Faibussowitsch if (numFields > 0) PetscCall(PetscSectionSetNumFields(gs, numFields));
14959566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd));
14969566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(gs, pStart, pEnd));
149787e637c6Sksagiyam gs->includesConstraints = includeConstraints;
14989566063dSJacob Faibussowitsch PetscCall(PetscSFGetGraph(sf, &nroots, NULL, NULL, NULL));
1499ea844a1aSMatthew Knepley nlocal = nroots; /* The local/leaf space matches global/root space */
1500ea844a1aSMatthew Knepley /* Must allocate for all points visible to SF, which may be more than this section */
1501ea844a1aSMatthew Knepley if (nroots >= 0) { /* nroots < 0 means that the graph has not been set, only happens in serial */
15029566063dSJacob Faibussowitsch PetscCall(PetscSFGetLeafRange(sf, NULL, &maxleaf));
150308401ef6SPierre Jolivet PetscCheck(nroots >= pEnd, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "SF roots %" PetscInt_FMT " < pEnd %" PetscInt_FMT, nroots, pEnd);
150408401ef6SPierre Jolivet PetscCheck(maxleaf < nroots, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Max local leaf %" PetscInt_FMT " >= nroots %" PetscInt_FMT, maxleaf, nroots);
15059566063dSJacob Faibussowitsch PetscCall(PetscMalloc2(nroots, &neg, nlocal, &recv));
15069566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(neg, nroots));
1507ea844a1aSMatthew Knepley }
1508ea844a1aSMatthew Knepley /* Mark all local points with negative dof */
1509ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) {
15109566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof));
15119566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(gs, p, dof));
15129566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof));
15139566063dSJacob Faibussowitsch if (!includeConstraints && cdof > 0) PetscCall(PetscSectionSetConstraintDof(gs, p, cdof));
1514ea844a1aSMatthew Knepley if (neg) neg[p] = -(dof + 1);
1515ea844a1aSMatthew Knepley }
15169566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUpBC(gs));
15179566063dSJacob Faibussowitsch if (gs->bcIndices) PetscCall(PetscArraycpy(gs->bcIndices, s->bcIndices, gs->bc->atlasOff[gs->bc->pEnd - gs->bc->pStart - 1] + gs->bc->atlasDof[gs->bc->pEnd - gs->bc->pStart - 1]));
1518ea844a1aSMatthew Knepley if (nroots >= 0) {
15199566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(recv, nlocal));
15209566063dSJacob Faibussowitsch PetscCall(PetscSFBcastBegin(sf, MPIU_INT, neg, recv, MPI_REPLACE));
15219566063dSJacob Faibussowitsch PetscCall(PetscSFBcastEnd(sf, MPIU_INT, neg, recv, MPI_REPLACE));
1522ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) {
1523ea844a1aSMatthew Knepley if (recv[p] < 0) {
1524ea844a1aSMatthew Knepley gs->atlasDof[p - pStart] = recv[p];
15259566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof));
152608401ef6SPierre Jolivet PetscCheck(-(recv[p] + 1) == dof, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Global dof %" PetscInt_FMT " for point %" PetscInt_FMT " is not the unconstrained %" PetscInt_FMT, -(recv[p] + 1), p, dof);
1527ea844a1aSMatthew Knepley }
1528ea844a1aSMatthew Knepley }
1529ea844a1aSMatthew Knepley }
1530ea844a1aSMatthew Knepley /* Calculate new sizes, get process offset, and calculate point offsets */
1531eb9d3e4dSMatthew G. Knepley if (usePermutation && s->perm) PetscCall(ISGetIndices(s->perm, &pind));
1532ea844a1aSMatthew Knepley for (p = 0, off = 0; p < pEnd - pStart; ++p) {
1533ea844a1aSMatthew Knepley const PetscInt q = pind ? pind[p] : p;
1534ea844a1aSMatthew Knepley
1535ea844a1aSMatthew Knepley cdof = (!includeConstraints && s->bc) ? s->bc->atlasDof[q] : 0;
1536ea844a1aSMatthew Knepley gs->atlasOff[q] = off;
1537ea844a1aSMatthew Knepley off += gs->atlasDof[q] > 0 ? gs->atlasDof[q] - cdof : 0;
1538ea844a1aSMatthew Knepley }
1539ea844a1aSMatthew Knepley if (!localOffsets) {
1540eac151a8SMatthew G. Knepley PetscCallMPI(MPI_Scan(&off, &globalOff, 1, MPIU_INT, MPI_SUM, PetscObjectComm((PetscObject)sf)));
1541ea844a1aSMatthew Knepley globalOff -= off;
1542ea844a1aSMatthew Knepley }
1543ea844a1aSMatthew Knepley for (p = pStart, off = 0; p < pEnd; ++p) {
1544ea844a1aSMatthew Knepley gs->atlasOff[p - pStart] += globalOff;
1545ea844a1aSMatthew Knepley if (neg) neg[p] = -(gs->atlasOff[p - pStart] + 1);
1546ea844a1aSMatthew Knepley }
1547eb9d3e4dSMatthew G. Knepley if (usePermutation && s->perm) PetscCall(ISRestoreIndices(s->perm, &pind));
1548ea844a1aSMatthew Knepley /* Put in negative offsets for ghost points */
1549ea844a1aSMatthew Knepley if (nroots >= 0) {
15509566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(recv, nlocal));
15519566063dSJacob Faibussowitsch PetscCall(PetscSFBcastBegin(sf, MPIU_INT, neg, recv, MPI_REPLACE));
15529566063dSJacob Faibussowitsch PetscCall(PetscSFBcastEnd(sf, MPIU_INT, neg, recv, MPI_REPLACE));
1553ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) {
1554ea844a1aSMatthew Knepley if (recv[p] < 0) gs->atlasOff[p - pStart] = recv[p];
1555ea844a1aSMatthew Knepley }
1556ea844a1aSMatthew Knepley }
15579566063dSJacob Faibussowitsch PetscCall(PetscFree2(neg, recv));
1558046d2115Sksagiyam /* Set field dofs/offsets/constraints */
1559046d2115Sksagiyam for (f = 0; f < numFields; ++f) {
15604cd8913cSStefano Zampini const char *name;
15614cd8913cSStefano Zampini
1562046d2115Sksagiyam gs->field[f]->includesConstraints = includeConstraints;
15639566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s, f, &numComponents));
15649566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(gs, f, numComponents));
15654cd8913cSStefano Zampini PetscCall(PetscSectionGetFieldName(s, f, &name));
15664cd8913cSStefano Zampini PetscCall(PetscSectionSetFieldName(gs, f, name));
1567046d2115Sksagiyam }
1568046d2115Sksagiyam for (p = pStart; p < pEnd; ++p) {
15699566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(gs, p, &off));
1570046d2115Sksagiyam for (f = 0, foff = off; f < numFields; ++f) {
15719566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, f, &cdof));
15729566063dSJacob Faibussowitsch if (!includeConstraints && cdof > 0) PetscCall(PetscSectionSetFieldConstraintDof(gs, p, f, cdof));
15739566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, f, &dof));
15749566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldDof(gs, p, f, off < 0 ? -(dof + 1) : dof));
1575835f2295SStefano Zampini PetscCall(PetscSectionSetFieldOffset(gs, p, f, foff));
15769566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(gs, p, f, &cdof));
1577046d2115Sksagiyam foff = off < 0 ? foff - (dof - cdof) : foff + (dof - cdof);
1578046d2115Sksagiyam }
1579046d2115Sksagiyam }
1580046d2115Sksagiyam for (f = 0; f < numFields; ++f) {
1581046d2115Sksagiyam PetscSection gfs = gs->field[f];
1582046d2115Sksagiyam
15839566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUpBC(gfs));
15849566063dSJacob Faibussowitsch if (gfs->bcIndices) PetscCall(PetscArraycpy(gfs->bcIndices, s->field[f]->bcIndices, gfs->bc->atlasOff[gfs->bc->pEnd - gfs->bc->pStart - 1] + gfs->bc->atlasDof[gfs->bc->pEnd - gfs->bc->pStart - 1]));
1585046d2115Sksagiyam }
1586046d2115Sksagiyam gs->setup = PETSC_TRUE;
15879566063dSJacob Faibussowitsch PetscCall(PetscSectionViewFromOptions(gs, NULL, "-global_section_view"));
1588ea844a1aSMatthew Knepley *gsection = gs;
15893ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1590ea844a1aSMatthew Knepley }
1591ea844a1aSMatthew Knepley
1592ea844a1aSMatthew Knepley /*@
1593583308b6SBarry Smith PetscSectionCreateGlobalSectionCensored - Create a `PetscSection` describing the globallayout using
1594583308b6SBarry Smith a local (sequential) `PetscSection` on each MPI process and an `PetscSF` describing the section point overlap.
1595ea844a1aSMatthew Knepley
1596ea844a1aSMatthew Knepley Input Parameters:
1597cab54364SBarry Smith + s - The `PetscSection` for the local field layout
1598cab54364SBarry Smith . sf - The `PetscSF` describing parallel layout of the section points
1599583308b6SBarry Smith . includeConstraints - By default this is `PETSC_FALSE`, meaning that the global vector will not possess constrained dofs
1600583308b6SBarry Smith . numExcludes - The number of exclusion ranges, this must have the same value on all MPI processes
1601583308b6SBarry Smith - excludes - An array [start_0, end_0, start_1, end_1, ...] where there are `numExcludes` pairs and must have the same values on all MPI processes
1602ea844a1aSMatthew Knepley
1603ea844a1aSMatthew Knepley Output Parameter:
1604cab54364SBarry Smith . gsection - The `PetscSection` for the global field layout
1605ea844a1aSMatthew Knepley
1606ea844a1aSMatthew Knepley Level: advanced
1607ea844a1aSMatthew Knepley
1608583308b6SBarry Smith Notes:
1609583308b6SBarry Smith On each MPI process `gsection` inherits the chart of the `s` on that process.
161020662ed9SBarry Smith
1611583308b6SBarry Smith This sets negative sizes and offsets to points not owned by this process as defined by `sf` but that are within the local value of the chart of `gsection`.
1612583308b6SBarry Smith In those locations the value of size is -(size+1) and the value of the offset on the remote process is -(off+1).
1613583308b6SBarry Smith
1614583308b6SBarry Smith This routine augments `PetscSectionCreateGlobalSection()` by allowing one to exclude certain ranges in the chart of the `PetscSection`
1615cab54364SBarry Smith
161638b5cf2dSJacob Faibussowitsch Developer Notes:
161720662ed9SBarry Smith This is a terrible function name
161820662ed9SBarry Smith
1619b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionCreate()`
1620ea844a1aSMatthew Knepley @*/
PetscSectionCreateGlobalSectionCensored(PetscSection s,PetscSF sf,PetscBool includeConstraints,PetscInt numExcludes,const PetscInt excludes[],PetscSection * gsection)1621d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateGlobalSectionCensored(PetscSection s, PetscSF sf, PetscBool includeConstraints, PetscInt numExcludes, const PetscInt excludes[], PetscSection *gsection)
1622d71ae5a4SJacob Faibussowitsch {
1623ea844a1aSMatthew Knepley const PetscInt *pind = NULL;
1624ea844a1aSMatthew Knepley PetscInt *neg = NULL, *tmpOff = NULL;
1625357d8704SBarry Smith PetscInt pStart, pEnd, p, e, dof, cdof, globalOff = 0, nroots;
1626835f2295SStefano Zampini PetscInt off;
1627ea844a1aSMatthew Knepley
1628ea844a1aSMatthew Knepley PetscFunctionBegin;
1629ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
1630ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sf, PETSCSF_CLASSID, 2);
16314f572ea9SToby Isaac PetscAssertPointer(gsection, 6);
16329566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), gsection));
16339566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd));
16349566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(*gsection, pStart, pEnd));
16359566063dSJacob Faibussowitsch PetscCall(PetscSFGetGraph(sf, &nroots, NULL, NULL, NULL));
1636ea844a1aSMatthew Knepley if (nroots >= 0) {
163708401ef6SPierre Jolivet PetscCheck(nroots >= pEnd - pStart, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "PetscSF nroots %" PetscInt_FMT " < %" PetscInt_FMT " section size", nroots, pEnd - pStart);
16389566063dSJacob Faibussowitsch PetscCall(PetscCalloc1(nroots, &neg));
1639ea844a1aSMatthew Knepley if (nroots > pEnd - pStart) {
16409566063dSJacob Faibussowitsch PetscCall(PetscCalloc1(nroots, &tmpOff));
1641ea844a1aSMatthew Knepley } else {
1642ea844a1aSMatthew Knepley tmpOff = &(*gsection)->atlasDof[-pStart];
1643ea844a1aSMatthew Knepley }
1644ea844a1aSMatthew Knepley }
1645ea844a1aSMatthew Knepley /* Mark ghost points with negative dof */
1646ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) {
1647ea844a1aSMatthew Knepley for (e = 0; e < numExcludes; ++e) {
1648ea844a1aSMatthew Knepley if ((p >= excludes[e * 2 + 0]) && (p < excludes[e * 2 + 1])) {
16499566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(*gsection, p, 0));
1650ea844a1aSMatthew Knepley break;
1651ea844a1aSMatthew Knepley }
1652ea844a1aSMatthew Knepley }
1653ea844a1aSMatthew Knepley if (e < numExcludes) continue;
16549566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof));
16559566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(*gsection, p, dof));
16569566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof));
16579566063dSJacob Faibussowitsch if (!includeConstraints && cdof > 0) PetscCall(PetscSectionSetConstraintDof(*gsection, p, cdof));
1658ea844a1aSMatthew Knepley if (neg) neg[p] = -(dof + 1);
1659ea844a1aSMatthew Knepley }
16609566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUpBC(*gsection));
1661ea844a1aSMatthew Knepley if (nroots >= 0) {
16629566063dSJacob Faibussowitsch PetscCall(PetscSFBcastBegin(sf, MPIU_INT, neg, tmpOff, MPI_REPLACE));
16639566063dSJacob Faibussowitsch PetscCall(PetscSFBcastEnd(sf, MPIU_INT, neg, tmpOff, MPI_REPLACE));
1664ea844a1aSMatthew Knepley if (nroots > pEnd - pStart) {
16659371c9d4SSatish Balay for (p = pStart; p < pEnd; ++p) {
16669371c9d4SSatish Balay if (tmpOff[p] < 0) (*gsection)->atlasDof[p - pStart] = tmpOff[p];
16679371c9d4SSatish Balay }
1668ea844a1aSMatthew Knepley }
1669ea844a1aSMatthew Knepley }
167035cb6cd3SPierre Jolivet /* Calculate new sizes, get process offset, and calculate point offsets */
16719566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISGetIndices(s->perm, &pind));
1672ea844a1aSMatthew Knepley for (p = 0, off = 0; p < pEnd - pStart; ++p) {
1673ea844a1aSMatthew Knepley const PetscInt q = pind ? pind[p] : p;
1674ea844a1aSMatthew Knepley
1675ea844a1aSMatthew Knepley cdof = (!includeConstraints && s->bc) ? s->bc->atlasDof[q] : 0;
1676835f2295SStefano Zampini (*gsection)->atlasOff[q] = off;
1677ea844a1aSMatthew Knepley off += (*gsection)->atlasDof[q] > 0 ? (*gsection)->atlasDof[q] - cdof : 0;
16786497c311SBarry Smith }
16799566063dSJacob Faibussowitsch PetscCallMPI(MPI_Scan(&off, &globalOff, 1, MPIU_INT, MPI_SUM, PetscObjectComm((PetscObject)s)));
1680ea844a1aSMatthew Knepley globalOff -= off;
1681ea844a1aSMatthew Knepley for (p = 0, off = 0; p < pEnd - pStart; ++p) {
1682ea844a1aSMatthew Knepley (*gsection)->atlasOff[p] += globalOff;
1683ea844a1aSMatthew Knepley if (neg) neg[p + pStart] = -((*gsection)->atlasOff[p] + 1);
1684ea844a1aSMatthew Knepley }
16859566063dSJacob Faibussowitsch if (s->perm) PetscCall(ISRestoreIndices(s->perm, &pind));
1686ea844a1aSMatthew Knepley /* Put in negative offsets for ghost points */
1687ea844a1aSMatthew Knepley if (nroots >= 0) {
1688ea844a1aSMatthew Knepley if (nroots == pEnd - pStart) tmpOff = &(*gsection)->atlasOff[-pStart];
16899566063dSJacob Faibussowitsch PetscCall(PetscSFBcastBegin(sf, MPIU_INT, neg, tmpOff, MPI_REPLACE));
16909566063dSJacob Faibussowitsch PetscCall(PetscSFBcastEnd(sf, MPIU_INT, neg, tmpOff, MPI_REPLACE));
1691ea844a1aSMatthew Knepley if (nroots > pEnd - pStart) {
16929371c9d4SSatish Balay for (p = pStart; p < pEnd; ++p) {
16939371c9d4SSatish Balay if (tmpOff[p] < 0) (*gsection)->atlasOff[p - pStart] = tmpOff[p];
16949371c9d4SSatish Balay }
1695ea844a1aSMatthew Knepley }
1696ea844a1aSMatthew Knepley }
16979566063dSJacob Faibussowitsch if (nroots >= 0 && nroots > pEnd - pStart) PetscCall(PetscFree(tmpOff));
16989566063dSJacob Faibussowitsch PetscCall(PetscFree(neg));
16993ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1700ea844a1aSMatthew Knepley }
1701ea844a1aSMatthew Knepley
1702ea844a1aSMatthew Knepley /*@
1703583308b6SBarry Smith PetscSectionGetPointLayout - Get a `PetscLayout` for the points with nonzero dof counts of the unnamed default field within this `PetscSection`s local chart
1704ea844a1aSMatthew Knepley
1705cab54364SBarry Smith Collective
1706ea844a1aSMatthew Knepley
1707ea844a1aSMatthew Knepley Input Parameters:
1708cab54364SBarry Smith + comm - The `MPI_Comm`
1709cab54364SBarry Smith - s - The `PetscSection`
1710ea844a1aSMatthew Knepley
1711ea844a1aSMatthew Knepley Output Parameter:
171220662ed9SBarry Smith . layout - The point layout for the data that defines the section
1713ea844a1aSMatthew Knepley
1714ea844a1aSMatthew Knepley Level: advanced
1715ea844a1aSMatthew Knepley
171620662ed9SBarry Smith Notes:
1717583308b6SBarry Smith `PetscSectionGetValueLayout()` provides similar information but counting the total number of degrees of freedom on the MPI process (excluding constrained
1718583308b6SBarry Smith degrees of freedom).
171920662ed9SBarry Smith
1720583308b6SBarry Smith This count includes constrained degrees of freedom
1721583308b6SBarry Smith
1722583308b6SBarry Smith This is usually called on the default global section.
1723583308b6SBarry Smith
1724583308b6SBarry Smith Example:
1725583308b6SBarry Smith .vb
1726583308b6SBarry Smith The chart is [2,5), point 2 has 2 dof, point 3 has 0 dof, point 4 has 1 dof
1727583308b6SBarry Smith The local size of the `PetscLayout` is 2 since 2 points have a non-zero number of dof
1728583308b6SBarry Smith .ve
1729583308b6SBarry Smith
173038b5cf2dSJacob Faibussowitsch Developer Notes:
1731583308b6SBarry Smith I find the names of these two functions extremely non-informative
1732cab54364SBarry Smith
1733b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetValueLayout()`, `PetscSectionCreate()`
1734ea844a1aSMatthew Knepley @*/
PetscSectionGetPointLayout(MPI_Comm comm,PetscSection s,PetscLayout * layout)1735d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetPointLayout(MPI_Comm comm, PetscSection s, PetscLayout *layout)
1736d71ae5a4SJacob Faibussowitsch {
1737ea844a1aSMatthew Knepley PetscInt pStart, pEnd, p, localSize = 0;
1738ea844a1aSMatthew Knepley
1739ea844a1aSMatthew Knepley PetscFunctionBegin;
17409566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd));
1741ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) {
1742ea844a1aSMatthew Knepley PetscInt dof;
1743ea844a1aSMatthew Knepley
17449566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof));
17459120ba30SVaclav Hapla if (dof >= 0) ++localSize;
1746ea844a1aSMatthew Knepley }
17479566063dSJacob Faibussowitsch PetscCall(PetscLayoutCreate(comm, layout));
17489566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetLocalSize(*layout, localSize));
17499566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetBlockSize(*layout, 1));
17509566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetUp(*layout));
17513ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1752ea844a1aSMatthew Knepley }
1753ea844a1aSMatthew Knepley
1754ea844a1aSMatthew Knepley /*@
175520662ed9SBarry Smith PetscSectionGetValueLayout - Get the `PetscLayout` associated with the section dofs of a `PetscSection`
1756ea844a1aSMatthew Knepley
1757cab54364SBarry Smith Collective
1758ea844a1aSMatthew Knepley
1759ea844a1aSMatthew Knepley Input Parameters:
1760cab54364SBarry Smith + comm - The `MPI_Comm`
1761cab54364SBarry Smith - s - The `PetscSection`
1762ea844a1aSMatthew Knepley
1763ea844a1aSMatthew Knepley Output Parameter:
1764ea844a1aSMatthew Knepley . layout - The dof layout for the section
1765ea844a1aSMatthew Knepley
1766ea844a1aSMatthew Knepley Level: advanced
1767ea844a1aSMatthew Knepley
176820662ed9SBarry Smith Notes:
1769583308b6SBarry Smith `PetscSectionGetPointLayout()` provides similar information but only counting the number of points with nonzero degrees of freedom and
1770583308b6SBarry Smith including the constrained degrees of freedom
177120662ed9SBarry Smith
1772cab54364SBarry Smith This is usually called for the default global section.
1773cab54364SBarry Smith
1774583308b6SBarry Smith Example:
1775583308b6SBarry Smith .vb
1776583308b6SBarry Smith The chart is [2,5), point 2 has 4 dof (2 constrained), point 3 has 0 dof, point 4 has 1 dof (not constrained)
1777583308b6SBarry Smith The local size of the `PetscLayout` is 3 since there are 3 unconstrained degrees of freedom on this MPI process
1778583308b6SBarry Smith .ve
1779583308b6SBarry Smith
1780b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetPointLayout()`, `PetscSectionCreate()`
1781ea844a1aSMatthew Knepley @*/
PetscSectionGetValueLayout(MPI_Comm comm,PetscSection s,PetscLayout * layout)1782d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetValueLayout(MPI_Comm comm, PetscSection s, PetscLayout *layout)
1783d71ae5a4SJacob Faibussowitsch {
1784ea844a1aSMatthew Knepley PetscInt pStart, pEnd, p, localSize = 0;
1785ea844a1aSMatthew Knepley
1786ea844a1aSMatthew Knepley PetscFunctionBegin;
1787ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 2);
17884f572ea9SToby Isaac PetscAssertPointer(layout, 3);
17899566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd));
1790ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) {
1791ea844a1aSMatthew Knepley PetscInt dof, cdof;
1792ea844a1aSMatthew Knepley
17939566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof));
17949566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof));
1795ea844a1aSMatthew Knepley if (dof - cdof > 0) localSize += dof - cdof;
1796ea844a1aSMatthew Knepley }
17979566063dSJacob Faibussowitsch PetscCall(PetscLayoutCreate(comm, layout));
17989566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetLocalSize(*layout, localSize));
17999566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetBlockSize(*layout, 1));
18009566063dSJacob Faibussowitsch PetscCall(PetscLayoutSetUp(*layout));
18013ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1802ea844a1aSMatthew Knepley }
1803ea844a1aSMatthew Knepley
1804ea844a1aSMatthew Knepley /*@
1805db527f05SMatthew G. Knepley PetscSectionGetOffset - Return the offset into an array or `Vec` for the dof associated with the given point.
1806ea844a1aSMatthew Knepley
180740750d41SVaclav Hapla Not Collective
1808ea844a1aSMatthew Knepley
1809ea844a1aSMatthew Knepley Input Parameters:
1810cab54364SBarry Smith + s - the `PetscSection`
1811ea844a1aSMatthew Knepley - point - the point
1812ea844a1aSMatthew Knepley
1813ea844a1aSMatthew Knepley Output Parameter:
1814ea844a1aSMatthew Knepley . offset - the offset
1815ea844a1aSMatthew Knepley
1816ea844a1aSMatthew Knepley Level: intermediate
1817ea844a1aSMatthew Knepley
1818583308b6SBarry Smith Notes:
1819376335faSBarry Smith In a global section, `offset` will be negative for points not owned by this process.
1820583308b6SBarry Smith
1821583308b6SBarry Smith This is for the unnamed default field in the `PetscSection` not the named fields
1822583308b6SBarry Smith
1823583308b6SBarry Smith The `offset` values are different depending on a value set with `PetscSectionSetPointMajor()`
1824583308b6SBarry Smith
1825b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetFieldOffset()`, `PetscSectionCreate()`, `PetscSectionSetPointMajor()`
1826ea844a1aSMatthew Knepley @*/
PetscSectionGetOffset(PetscSection s,PetscInt point,PetscInt * offset)1827d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetOffset(PetscSection s, PetscInt point, PetscInt *offset)
1828d71ae5a4SJacob Faibussowitsch {
1829ea844a1aSMatthew Knepley PetscFunctionBegin;
1830ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
18314f572ea9SToby Isaac PetscAssertPointer(offset, 3);
1832b498ca8aSPierre Jolivet PetscAssert(!(point < s->pStart) && !(point >= s->pEnd), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section point %" PetscInt_FMT " should be in [%" PetscInt_FMT ", %" PetscInt_FMT ")", point, s->pStart, s->pEnd);
1833ea844a1aSMatthew Knepley *offset = s->atlasOff[point - s->pStart];
18343ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1835ea844a1aSMatthew Knepley }
1836ea844a1aSMatthew Knepley
1837ea844a1aSMatthew Knepley /*@
1838db527f05SMatthew G. Knepley PetscSectionSetOffset - Set the offset into an array or `Vec` for the dof associated with the given point.
1839ea844a1aSMatthew Knepley
184040750d41SVaclav Hapla Not Collective
1841ea844a1aSMatthew Knepley
1842ea844a1aSMatthew Knepley Input Parameters:
1843cab54364SBarry Smith + s - the `PetscSection`
1844ea844a1aSMatthew Knepley . point - the point
1845376335faSBarry Smith - offset - the offset, these values may be negative indicating the values are off process
1846ea844a1aSMatthew Knepley
1847583308b6SBarry Smith Level: developer
1848ea844a1aSMatthew Knepley
1849cab54364SBarry Smith Note:
1850cab54364SBarry Smith The user usually does not call this function, but uses `PetscSectionSetUp()`
1851cab54364SBarry Smith
1852b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetFieldOffset()`, `PetscSectionCreate()`, `PetscSectionSetUp()`
1853ea844a1aSMatthew Knepley @*/
PetscSectionSetOffset(PetscSection s,PetscInt point,PetscInt offset)1854d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetOffset(PetscSection s, PetscInt point, PetscInt offset)
1855d71ae5a4SJacob Faibussowitsch {
1856ea844a1aSMatthew Knepley PetscFunctionBegin;
1857ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
185808401ef6SPierre Jolivet PetscCheck(!(point < s->pStart) && !(point >= s->pEnd), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Section point %" PetscInt_FMT " should be in [%" PetscInt_FMT ", %" PetscInt_FMT ")", point, s->pStart, s->pEnd);
1859ea844a1aSMatthew Knepley s->atlasOff[point - s->pStart] = offset;
18603ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1861ea844a1aSMatthew Knepley }
1862ea844a1aSMatthew Knepley
1863ea844a1aSMatthew Knepley /*@
1864db527f05SMatthew G. Knepley PetscSectionGetFieldOffset - Return the offset into an array or `Vec` for the field dof associated with the given point.
1865ea844a1aSMatthew Knepley
186640750d41SVaclav Hapla Not Collective
1867ea844a1aSMatthew Knepley
1868ea844a1aSMatthew Knepley Input Parameters:
1869cab54364SBarry Smith + s - the `PetscSection`
1870ea844a1aSMatthew Knepley . point - the point
1871ea844a1aSMatthew Knepley - field - the field
1872ea844a1aSMatthew Knepley
1873ea844a1aSMatthew Knepley Output Parameter:
1874ea844a1aSMatthew Knepley . offset - the offset
1875ea844a1aSMatthew Knepley
1876ea844a1aSMatthew Knepley Level: intermediate
1877ea844a1aSMatthew Knepley
1878583308b6SBarry Smith Notes:
1879376335faSBarry Smith In a global section, `offset` will be negative for points not owned by this process.
1880583308b6SBarry Smith
1881583308b6SBarry Smith The `offset` values are different depending on a value set with `PetscSectionSetPointMajor()`
1882583308b6SBarry Smith
1883b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetOffset()`, `PetscSectionCreate()`, `PetscSectionGetFieldPointOffset()`
1884ea844a1aSMatthew Knepley @*/
PetscSectionGetFieldOffset(PetscSection s,PetscInt point,PetscInt field,PetscInt * offset)1885d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldOffset(PetscSection s, PetscInt point, PetscInt field, PetscInt *offset)
1886d71ae5a4SJacob Faibussowitsch {
1887ea844a1aSMatthew Knepley PetscFunctionBegin;
1888ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
18894f572ea9SToby Isaac PetscAssertPointer(offset, 4);
18902abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields);
18919566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s->field[field], point, offset));
18923ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1893ea844a1aSMatthew Knepley }
1894ea844a1aSMatthew Knepley
1895ea844a1aSMatthew Knepley /*@
1896db527f05SMatthew G. Knepley PetscSectionSetFieldOffset - Set the offset into an array or `Vec` for the dof associated with the given field at a point.
1897ea844a1aSMatthew Knepley
189840750d41SVaclav Hapla Not Collective
1899ea844a1aSMatthew Knepley
1900ea844a1aSMatthew Knepley Input Parameters:
190120662ed9SBarry Smith + s - the `PetscSection`
1902ea844a1aSMatthew Knepley . point - the point
1903ea844a1aSMatthew Knepley . field - the field
1904376335faSBarry Smith - offset - the offset, these values may be negative indicating the values are off process
1905ea844a1aSMatthew Knepley
1906cab54364SBarry Smith Level: developer
1907ea844a1aSMatthew Knepley
1908cab54364SBarry Smith Note:
1909cab54364SBarry Smith The user usually does not call this function, but uses `PetscSectionSetUp()`
1910ea844a1aSMatthew Knepley
1911b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetFieldOffset()`, `PetscSectionSetOffset()`, `PetscSectionCreate()`, `PetscSectionSetUp()`
1912ea844a1aSMatthew Knepley @*/
PetscSectionSetFieldOffset(PetscSection s,PetscInt point,PetscInt field,PetscInt offset)1913d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldOffset(PetscSection s, PetscInt point, PetscInt field, PetscInt offset)
1914d71ae5a4SJacob Faibussowitsch {
1915ea844a1aSMatthew Knepley PetscFunctionBegin;
1916ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
19172abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields);
19189566063dSJacob Faibussowitsch PetscCall(PetscSectionSetOffset(s->field[field], point, offset));
19193ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1920ea844a1aSMatthew Knepley }
1921ea844a1aSMatthew Knepley
1922ea844a1aSMatthew Knepley /*@
1923583308b6SBarry Smith PetscSectionGetFieldPointOffset - Return the offset for the first field dof associated with the given point relative to the offset for that point for the
1924583308b6SBarry Smith unnamed default field's first dof
1925ea844a1aSMatthew Knepley
192640750d41SVaclav Hapla Not Collective
1927ea844a1aSMatthew Knepley
1928ea844a1aSMatthew Knepley Input Parameters:
1929cab54364SBarry Smith + s - the `PetscSection`
1930ea844a1aSMatthew Knepley . point - the point
1931ea844a1aSMatthew Knepley - field - the field
1932ea844a1aSMatthew Knepley
1933ea844a1aSMatthew Knepley Output Parameter:
1934ea844a1aSMatthew Knepley . offset - the offset
1935ea844a1aSMatthew Knepley
1936ea844a1aSMatthew Knepley Level: advanced
1937ea844a1aSMatthew Knepley
1938cab54364SBarry Smith Note:
1939583308b6SBarry Smith This ignores constraints
1940cab54364SBarry Smith
1941583308b6SBarry Smith Example:
1942583308b6SBarry Smith .vb
1943583308b6SBarry Smith if PetscSectionSetPointMajor(s,PETSC_TRUE)
1944583308b6SBarry Smith The unnamed default field has 3 dof at `point`
1945583308b6SBarry Smith Field 0 has 2 dof at `point`
1946583308b6SBarry Smith Then PetscSectionGetFieldPointOffset(s,point,1,&offset) returns and offset of 5
1947583308b6SBarry Smith .ve
1948583308b6SBarry Smith
1949b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetOffset()`, `PetscSectionCreate()`, `PetscSectionGetFieldOffset()`
1950ea844a1aSMatthew Knepley @*/
PetscSectionGetFieldPointOffset(PetscSection s,PetscInt point,PetscInt field,PetscInt * offset)1951d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldPointOffset(PetscSection s, PetscInt point, PetscInt field, PetscInt *offset)
1952d71ae5a4SJacob Faibussowitsch {
1953ea844a1aSMatthew Knepley PetscInt off, foff;
1954ea844a1aSMatthew Knepley
1955ea844a1aSMatthew Knepley PetscFunctionBegin;
1956ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
19574f572ea9SToby Isaac PetscAssertPointer(offset, 4);
19582abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields);
19599566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s, point, &off));
19609566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s->field[field], point, &foff));
1961ea844a1aSMatthew Knepley *offset = foff - off;
19623ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
1963ea844a1aSMatthew Knepley }
1964ea844a1aSMatthew Knepley
1965ea844a1aSMatthew Knepley /*@
196620662ed9SBarry Smith PetscSectionGetOffsetRange - Return the full range of offsets [`start`, `end`) for a `PetscSection`
1967ea844a1aSMatthew Knepley
196840750d41SVaclav Hapla Not Collective
1969ea844a1aSMatthew Knepley
1970ea844a1aSMatthew Knepley Input Parameter:
1971cab54364SBarry Smith . s - the `PetscSection`
1972ea844a1aSMatthew Knepley
1973ea844a1aSMatthew Knepley Output Parameters:
1974ea844a1aSMatthew Knepley + start - the minimum offset
1975ea844a1aSMatthew Knepley - end - one more than the maximum offset
1976ea844a1aSMatthew Knepley
1977ea844a1aSMatthew Knepley Level: intermediate
1978ea844a1aSMatthew Knepley
1979b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetOffset()`, `PetscSectionCreate()`
1980ea844a1aSMatthew Knepley @*/
PetscSectionGetOffsetRange(PetscSection s,PetscInt * start,PetscInt * end)1981d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetOffsetRange(PetscSection s, PetscInt *start, PetscInt *end)
1982d71ae5a4SJacob Faibussowitsch {
1983ea844a1aSMatthew Knepley PetscInt os = 0, oe = 0, pStart, pEnd, p;
1984ea844a1aSMatthew Knepley
1985ea844a1aSMatthew Knepley PetscFunctionBegin;
1986ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
19879371c9d4SSatish Balay if (s->atlasOff) {
19889371c9d4SSatish Balay os = s->atlasOff[0];
19899371c9d4SSatish Balay oe = s->atlasOff[0];
19909371c9d4SSatish Balay }
19919566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd));
1992ea844a1aSMatthew Knepley for (p = 0; p < pEnd - pStart; ++p) {
1993ea844a1aSMatthew Knepley PetscInt dof = s->atlasDof[p], off = s->atlasOff[p];
1994ea844a1aSMatthew Knepley
1995ea844a1aSMatthew Knepley if (off >= 0) {
1996ea844a1aSMatthew Knepley os = PetscMin(os, off);
1997ea844a1aSMatthew Knepley oe = PetscMax(oe, off + dof);
1998ea844a1aSMatthew Knepley }
1999ea844a1aSMatthew Knepley }
2000ea844a1aSMatthew Knepley if (start) *start = os;
2001ea844a1aSMatthew Knepley if (end) *end = oe;
20023ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2003ea844a1aSMatthew Knepley }
2004ea844a1aSMatthew Knepley
2005ea844a1aSMatthew Knepley /*@
2006583308b6SBarry Smith PetscSectionCreateSubsection - Create a new, smaller `PetscSection` composed of only selected fields
2007ea844a1aSMatthew Knepley
200840750d41SVaclav Hapla Collective
2009ea844a1aSMatthew Knepley
2010d8d19677SJose E. Roman Input Parameters:
2011cab54364SBarry Smith + s - the `PetscSection`
2012ea844a1aSMatthew Knepley . len - the number of subfields
2013ea844a1aSMatthew Knepley - fields - the subfield numbers
2014ea844a1aSMatthew Knepley
2015ea844a1aSMatthew Knepley Output Parameter:
2016ea844a1aSMatthew Knepley . subs - the subsection
2017ea844a1aSMatthew Knepley
2018ea844a1aSMatthew Knepley Level: advanced
2019ea844a1aSMatthew Knepley
2020cab54364SBarry Smith Notes:
2021583308b6SBarry Smith The chart of `subs` is the same as the chart of `s`
2022cab54364SBarry Smith
2023cab54364SBarry Smith This will error if a fieldnumber is out of range
2024cab54364SBarry Smith
2025b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionCreateSupersection()`, `PetscSectionCreate()`
2026ea844a1aSMatthew Knepley @*/
PetscSectionCreateSubsection(PetscSection s,PetscInt len,const PetscInt fields[],PetscSection * subs)2027d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateSubsection(PetscSection s, PetscInt len, const PetscInt fields[], PetscSection *subs)
2028d71ae5a4SJacob Faibussowitsch {
2029b778fa18SValeria Barra PetscInt nF, f, c, pStart, pEnd, p, maxCdof = 0;
2030ea844a1aSMatthew Knepley
2031ea844a1aSMatthew Knepley PetscFunctionBegin;
20323ba16761SJacob Faibussowitsch if (!len) PetscFunctionReturn(PETSC_SUCCESS);
2033ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
20344f572ea9SToby Isaac PetscAssertPointer(fields, 3);
20354f572ea9SToby Isaac PetscAssertPointer(subs, 4);
20369566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s, &nF));
203708401ef6SPierre Jolivet PetscCheck(len <= nF, PetscObjectComm((PetscObject)s), PETSC_ERR_ARG_WRONG, "Number of requested fields %" PetscInt_FMT " greater than number of fields %" PetscInt_FMT, len, nF);
20389566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), subs));
20399566063dSJacob Faibussowitsch PetscCall(PetscSectionSetNumFields(*subs, len));
2040ea844a1aSMatthew Knepley for (f = 0; f < len; ++f) {
2041ea844a1aSMatthew Knepley const char *name = NULL;
2042ea844a1aSMatthew Knepley PetscInt numComp = 0;
204342a52479SJed Brown PetscSectionSym sym;
2044ea844a1aSMatthew Knepley
20459566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldName(s, fields[f], &name));
20469566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldName(*subs, f, name));
20479566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s, fields[f], &numComp));
20489566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(*subs, f, numComp));
2049b778fa18SValeria Barra for (c = 0; c < s->numFieldComponents[fields[f]]; ++c) {
20509566063dSJacob Faibussowitsch PetscCall(PetscSectionGetComponentName(s, fields[f], c, &name));
20519566063dSJacob Faibussowitsch PetscCall(PetscSectionSetComponentName(*subs, f, c, name));
2052b778fa18SValeria Barra }
205342a52479SJed Brown PetscCall(PetscSectionGetFieldSym(s, fields[f], &sym));
205442a52479SJed Brown PetscCall(PetscSectionSetFieldSym(*subs, f, sym));
2055ea844a1aSMatthew Knepley }
20569566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd));
20579566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(*subs, pStart, pEnd));
2058ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) {
2059ea844a1aSMatthew Knepley PetscInt dof = 0, cdof = 0, fdof = 0, cfdof = 0;
2060ea844a1aSMatthew Knepley
2061ea844a1aSMatthew Knepley for (f = 0; f < len; ++f) {
20629566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, fields[f], &fdof));
20639566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldDof(*subs, p, f, fdof));
20649566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, fields[f], &cfdof));
20659566063dSJacob Faibussowitsch if (cfdof) PetscCall(PetscSectionSetFieldConstraintDof(*subs, p, f, cfdof));
2066ea844a1aSMatthew Knepley dof += fdof;
2067ea844a1aSMatthew Knepley cdof += cfdof;
2068ea844a1aSMatthew Knepley }
20699566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(*subs, p, dof));
20709566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetConstraintDof(*subs, p, cdof));
2071ea844a1aSMatthew Knepley maxCdof = PetscMax(cdof, maxCdof);
2072ea844a1aSMatthew Knepley }
20736e3bbc6dSMatthew G. Knepley PetscBT bst, subbst;
20746e3bbc6dSMatthew G. Knepley
20756e3bbc6dSMatthew G. Knepley PetscCall(PetscSectionGetBlockStarts(s, &bst));
20766e3bbc6dSMatthew G. Knepley if (bst) {
20776e3bbc6dSMatthew G. Knepley PetscCall(PetscBTCreate(pEnd - pStart, &subbst));
20786e3bbc6dSMatthew G. Knepley PetscCall(PetscBTCopy(subbst, pEnd - pStart, bst));
20796e3bbc6dSMatthew G. Knepley PetscCall(PetscSectionSetBlockStarts(*subs, subbst));
20806e3bbc6dSMatthew G. Knepley }
20819566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(*subs));
2082ea844a1aSMatthew Knepley if (maxCdof) {
2083ea844a1aSMatthew Knepley PetscInt *indices;
2084ea844a1aSMatthew Knepley
20859566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(maxCdof, &indices));
2086ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) {
2087ea844a1aSMatthew Knepley PetscInt cdof;
2088ea844a1aSMatthew Knepley
20899566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(*subs, p, &cdof));
2090ea844a1aSMatthew Knepley if (cdof) {
2091ea844a1aSMatthew Knepley const PetscInt *oldIndices = NULL;
2092ea844a1aSMatthew Knepley PetscInt fdof = 0, cfdof = 0, fc, numConst = 0, fOff = 0;
2093ea844a1aSMatthew Knepley
2094ea844a1aSMatthew Knepley for (f = 0; f < len; ++f) {
20959566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, fields[f], &fdof));
20969566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, fields[f], &cfdof));
20979566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(s, p, fields[f], &oldIndices));
20989566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldConstraintIndices(*subs, p, f, oldIndices));
20999574d0f0SMatthew G. Knepley for (fc = 0; fc < cfdof; ++fc) indices[numConst + fc] = oldIndices[fc] + fOff;
2100ea844a1aSMatthew Knepley numConst += cfdof;
2101ea844a1aSMatthew Knepley fOff += fdof;
2102ea844a1aSMatthew Knepley }
21039566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(*subs, p, indices));
2104ea844a1aSMatthew Knepley }
2105ea844a1aSMatthew Knepley }
21069566063dSJacob Faibussowitsch PetscCall(PetscFree(indices));
2107ea844a1aSMatthew Knepley }
21083ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2109ea844a1aSMatthew Knepley }
2110ea844a1aSMatthew Knepley
2111ea844a1aSMatthew Knepley /*@
21125becf6f4SMatthew G. Knepley PetscSectionCreateComponentSubsection - Create a new, smaller `PetscSection` composed of only selected components
21135becf6f4SMatthew G. Knepley
21145becf6f4SMatthew G. Knepley Collective
21155becf6f4SMatthew G. Knepley
21165becf6f4SMatthew G. Knepley Input Parameters:
21175becf6f4SMatthew G. Knepley + s - the `PetscSection`
21185becf6f4SMatthew G. Knepley . len - the number of components
21195becf6f4SMatthew G. Knepley - comps - the component numbers
21205becf6f4SMatthew G. Knepley
21215becf6f4SMatthew G. Knepley Output Parameter:
21225becf6f4SMatthew G. Knepley . subs - the subsection
21235becf6f4SMatthew G. Knepley
21245becf6f4SMatthew G. Knepley Level: advanced
21255becf6f4SMatthew G. Knepley
21265becf6f4SMatthew G. Knepley Notes:
21275becf6f4SMatthew G. Knepley The chart of `subs` is the same as the chart of `s`
21285becf6f4SMatthew G. Knepley
21295becf6f4SMatthew G. Knepley This will error if the section has more than one field, or if a component number is out of range
21305becf6f4SMatthew G. Knepley
2131b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionCreateSupersection()`, `PetscSectionCreate()`
21325becf6f4SMatthew G. Knepley @*/
PetscSectionCreateComponentSubsection(PetscSection s,PetscInt len,const PetscInt comps[],PetscSection * subs)21335becf6f4SMatthew G. Knepley PetscErrorCode PetscSectionCreateComponentSubsection(PetscSection s, PetscInt len, const PetscInt comps[], PetscSection *subs)
21345becf6f4SMatthew G. Knepley {
21355becf6f4SMatthew G. Knepley PetscSectionSym sym;
21365becf6f4SMatthew G. Knepley const char *name = NULL;
21375becf6f4SMatthew G. Knepley PetscInt Nf, pStart, pEnd;
21385becf6f4SMatthew G. Knepley
21395becf6f4SMatthew G. Knepley PetscFunctionBegin;
21405becf6f4SMatthew G. Knepley if (!len) PetscFunctionReturn(PETSC_SUCCESS);
21415becf6f4SMatthew G. Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
21425becf6f4SMatthew G. Knepley PetscAssertPointer(comps, 3);
21435becf6f4SMatthew G. Knepley PetscAssertPointer(subs, 4);
21445becf6f4SMatthew G. Knepley PetscCall(PetscSectionGetNumFields(s, &Nf));
21455becf6f4SMatthew G. Knepley PetscCheck(Nf == 1, PetscObjectComm((PetscObject)s), PETSC_ERR_ARG_WRONG, "This method can only handle one field, not %" PetscInt_FMT, Nf);
21465becf6f4SMatthew G. Knepley PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), subs));
21475becf6f4SMatthew G. Knepley PetscCall(PetscSectionSetNumFields(*subs, 1));
21485becf6f4SMatthew G. Knepley PetscCall(PetscSectionGetFieldName(s, 0, &name));
21495becf6f4SMatthew G. Knepley PetscCall(PetscSectionSetFieldName(*subs, 0, name));
21505becf6f4SMatthew G. Knepley PetscCall(PetscSectionSetFieldComponents(*subs, 0, len));
21515becf6f4SMatthew G. Knepley PetscCall(PetscSectionGetFieldSym(s, 0, &sym));
21525becf6f4SMatthew G. Knepley PetscCall(PetscSectionSetFieldSym(*subs, 0, sym));
21535becf6f4SMatthew G. Knepley for (PetscInt c = 0; c < len; ++c) {
21545becf6f4SMatthew G. Knepley PetscCall(PetscSectionGetComponentName(s, 0, comps[c], &name));
21555becf6f4SMatthew G. Knepley PetscCall(PetscSectionSetComponentName(*subs, 0, c, name));
21565becf6f4SMatthew G. Knepley }
21575becf6f4SMatthew G. Knepley PetscCall(PetscSectionGetChart(s, &pStart, &pEnd));
21585becf6f4SMatthew G. Knepley PetscCall(PetscSectionSetChart(*subs, pStart, pEnd));
21595becf6f4SMatthew G. Knepley for (PetscInt p = pStart; p < pEnd; ++p) {
21605becf6f4SMatthew G. Knepley PetscInt dof, cdof, cfdof;
21615becf6f4SMatthew G. Knepley
21625becf6f4SMatthew G. Knepley PetscCall(PetscSectionGetDof(s, p, &dof));
21635becf6f4SMatthew G. Knepley if (!dof) continue;
21645becf6f4SMatthew G. Knepley PetscCall(PetscSectionGetFieldConstraintDof(s, p, 0, &cfdof));
21655becf6f4SMatthew G. Knepley PetscCall(PetscSectionGetConstraintDof(s, p, &cdof));
21665becf6f4SMatthew G. Knepley PetscCheck(!cdof && !cfdof, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Component selection does not work with constraints");
21675becf6f4SMatthew G. Knepley PetscCall(PetscSectionSetFieldDof(*subs, p, 0, len));
21685becf6f4SMatthew G. Knepley PetscCall(PetscSectionSetDof(*subs, p, len));
21695becf6f4SMatthew G. Knepley }
21705becf6f4SMatthew G. Knepley PetscCall(PetscSectionSetUp(*subs));
21715becf6f4SMatthew G. Knepley PetscFunctionReturn(PETSC_SUCCESS);
21725becf6f4SMatthew G. Knepley }
21735becf6f4SMatthew G. Knepley
21745becf6f4SMatthew G. Knepley /*@
2175583308b6SBarry Smith PetscSectionCreateSupersection - Create a new, larger section composed of multiple `PetscSection`s
2176ea844a1aSMatthew Knepley
217740750d41SVaclav Hapla Collective
2178ea844a1aSMatthew Knepley
2179ea844a1aSMatthew Knepley Input Parameters:
2180ea844a1aSMatthew Knepley + s - the input sections
2181ea844a1aSMatthew Knepley - len - the number of input sections
2182ea844a1aSMatthew Knepley
2183ea844a1aSMatthew Knepley Output Parameter:
2184ea844a1aSMatthew Knepley . supers - the supersection
2185ea844a1aSMatthew Knepley
2186ea844a1aSMatthew Knepley Level: advanced
2187ea844a1aSMatthew Knepley
2188583308b6SBarry Smith Notes:
2189cab54364SBarry Smith The section offsets now refer to a new, larger vector.
2190cab54364SBarry Smith
219138b5cf2dSJacob Faibussowitsch Developer Notes:
2192cab54364SBarry Smith Needs to explain how the sections are composed
2193cab54364SBarry Smith
2194b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionCreateSubsection()`, `PetscSectionCreate()`
2195ea844a1aSMatthew Knepley @*/
PetscSectionCreateSupersection(PetscSection s[],PetscInt len,PetscSection * supers)2196d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateSupersection(PetscSection s[], PetscInt len, PetscSection *supers)
2197d71ae5a4SJacob Faibussowitsch {
21981690c2aeSBarry Smith PetscInt Nf = 0, f, pStart = PETSC_INT_MAX, pEnd = 0, p, maxCdof = 0, i;
2199ea844a1aSMatthew Knepley
2200ea844a1aSMatthew Knepley PetscFunctionBegin;
22013ba16761SJacob Faibussowitsch if (!len) PetscFunctionReturn(PETSC_SUCCESS);
2202ea844a1aSMatthew Knepley for (i = 0; i < len; ++i) {
2203ea844a1aSMatthew Knepley PetscInt nf, pStarti, pEndi;
2204ea844a1aSMatthew Knepley
22059566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s[i], &nf));
22069566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s[i], &pStarti, &pEndi));
2207ea844a1aSMatthew Knepley pStart = PetscMin(pStart, pStarti);
2208ea844a1aSMatthew Knepley pEnd = PetscMax(pEnd, pEndi);
2209ea844a1aSMatthew Knepley Nf += nf;
2210ea844a1aSMatthew Knepley }
22119566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s[0]), supers));
22129566063dSJacob Faibussowitsch PetscCall(PetscSectionSetNumFields(*supers, Nf));
2213ea844a1aSMatthew Knepley for (i = 0, f = 0; i < len; ++i) {
2214b778fa18SValeria Barra PetscInt nf, fi, ci;
2215ea844a1aSMatthew Knepley
22169566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s[i], &nf));
2217ea844a1aSMatthew Knepley for (fi = 0; fi < nf; ++fi, ++f) {
2218ea844a1aSMatthew Knepley const char *name = NULL;
2219ea844a1aSMatthew Knepley PetscInt numComp = 0;
2220ea844a1aSMatthew Knepley
22219566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldName(s[i], fi, &name));
22229566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldName(*supers, f, name));
22239566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s[i], fi, &numComp));
22249566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(*supers, f, numComp));
2225b778fa18SValeria Barra for (ci = 0; ci < s[i]->numFieldComponents[fi]; ++ci) {
22269566063dSJacob Faibussowitsch PetscCall(PetscSectionGetComponentName(s[i], fi, ci, &name));
22279566063dSJacob Faibussowitsch PetscCall(PetscSectionSetComponentName(*supers, f, ci, name));
2228b778fa18SValeria Barra }
2229ea844a1aSMatthew Knepley }
2230ea844a1aSMatthew Knepley }
22319566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(*supers, pStart, pEnd));
2232ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) {
2233ea844a1aSMatthew Knepley PetscInt dof = 0, cdof = 0;
2234ea844a1aSMatthew Knepley
2235ea844a1aSMatthew Knepley for (i = 0, f = 0; i < len; ++i) {
2236ea844a1aSMatthew Knepley PetscInt nf, fi, pStarti, pEndi;
2237ea844a1aSMatthew Knepley PetscInt fdof = 0, cfdof = 0;
2238ea844a1aSMatthew Knepley
22399566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s[i], &nf));
22409566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s[i], &pStarti, &pEndi));
2241ea844a1aSMatthew Knepley if ((p < pStarti) || (p >= pEndi)) continue;
2242ea844a1aSMatthew Knepley for (fi = 0; fi < nf; ++fi, ++f) {
22439566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s[i], p, fi, &fdof));
22449566063dSJacob Faibussowitsch PetscCall(PetscSectionAddFieldDof(*supers, p, f, fdof));
22459566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s[i], p, fi, &cfdof));
22469566063dSJacob Faibussowitsch if (cfdof) PetscCall(PetscSectionAddFieldConstraintDof(*supers, p, f, cfdof));
2247ea844a1aSMatthew Knepley dof += fdof;
2248ea844a1aSMatthew Knepley cdof += cfdof;
2249ea844a1aSMatthew Knepley }
2250ea844a1aSMatthew Knepley }
22519566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(*supers, p, dof));
22529566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetConstraintDof(*supers, p, cdof));
2253ea844a1aSMatthew Knepley maxCdof = PetscMax(cdof, maxCdof);
2254ea844a1aSMatthew Knepley }
22559566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(*supers));
2256ea844a1aSMatthew Knepley if (maxCdof) {
2257ea844a1aSMatthew Knepley PetscInt *indices;
2258ea844a1aSMatthew Knepley
22599566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(maxCdof, &indices));
2260ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) {
2261ea844a1aSMatthew Knepley PetscInt cdof;
2262ea844a1aSMatthew Knepley
22639566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(*supers, p, &cdof));
2264ea844a1aSMatthew Knepley if (cdof) {
2265ea844a1aSMatthew Knepley PetscInt dof, numConst = 0, fOff = 0;
2266ea844a1aSMatthew Knepley
2267ea844a1aSMatthew Knepley for (i = 0, f = 0; i < len; ++i) {
2268ea844a1aSMatthew Knepley const PetscInt *oldIndices = NULL;
2269ea844a1aSMatthew Knepley PetscInt nf, fi, pStarti, pEndi, fdof, cfdof, fc;
2270ea844a1aSMatthew Knepley
22719566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s[i], &nf));
22729566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s[i], &pStarti, &pEndi));
2273ea844a1aSMatthew Knepley if ((p < pStarti) || (p >= pEndi)) continue;
2274ea844a1aSMatthew Knepley for (fi = 0; fi < nf; ++fi, ++f) {
22759566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s[i], p, fi, &fdof));
22769566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s[i], p, fi, &cfdof));
22779566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(s[i], p, fi, &oldIndices));
2278fcd2503dSMatthew G. Knepley for (fc = 0; fc < cfdof; ++fc) indices[numConst + fc] = oldIndices[fc];
22799566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldConstraintIndices(*supers, p, f, &indices[numConst]));
2280fcd2503dSMatthew G. Knepley for (fc = 0; fc < cfdof; ++fc) indices[numConst + fc] += fOff;
2281ea844a1aSMatthew Knepley numConst += cfdof;
2282ea844a1aSMatthew Knepley }
22839566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s[i], p, &dof));
2284ea844a1aSMatthew Knepley fOff += dof;
2285ea844a1aSMatthew Knepley }
22869566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(*supers, p, indices));
2287ea844a1aSMatthew Knepley }
2288ea844a1aSMatthew Knepley }
22899566063dSJacob Faibussowitsch PetscCall(PetscFree(indices));
2290ea844a1aSMatthew Knepley }
22913ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2292ea844a1aSMatthew Knepley }
2293ea844a1aSMatthew Knepley
PetscSectionCreateSubplexSection_Private(PetscSection s,IS subpointIS,PetscBool renumberPoints,PetscSection * subs)229429d2e75bSMatthew G. Knepley static PetscErrorCode PetscSectionCreateSubplexSection_Private(PetscSection s, IS subpointIS, PetscBool renumberPoints, PetscSection *subs)
2295d71ae5a4SJacob Faibussowitsch {
2296ea844a1aSMatthew Knepley const PetscInt *points = NULL, *indices = NULL;
229729d2e75bSMatthew G. Knepley PetscInt *spoints = NULL, *order = NULL;
229841f23ed0SMatthew G. Knepley PetscInt numFields, f, c, numSubpoints = 0, pStart, pEnd, p, spStart, spEnd, subp;
2299ea844a1aSMatthew Knepley
2300ea844a1aSMatthew Knepley PetscFunctionBegin;
2301ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
230229d2e75bSMatthew G. Knepley PetscValidHeaderSpecific(subpointIS, IS_CLASSID, 2);
23034f572ea9SToby Isaac PetscAssertPointer(subs, 4);
23049566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s, &numFields));
23059566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), subs));
23069566063dSJacob Faibussowitsch if (numFields) PetscCall(PetscSectionSetNumFields(*subs, numFields));
2307ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) {
2308ea844a1aSMatthew Knepley const char *name = NULL;
2309ea844a1aSMatthew Knepley PetscInt numComp = 0;
2310ea844a1aSMatthew Knepley
23119566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldName(s, f, &name));
23129566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldName(*subs, f, name));
23139566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s, f, &numComp));
23149566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(*subs, f, numComp));
2315b778fa18SValeria Barra for (c = 0; c < s->numFieldComponents[f]; ++c) {
23169566063dSJacob Faibussowitsch PetscCall(PetscSectionGetComponentName(s, f, c, &name));
23179566063dSJacob Faibussowitsch PetscCall(PetscSectionSetComponentName(*subs, f, c, name));
2318b778fa18SValeria Barra }
2319ea844a1aSMatthew Knepley }
2320ea844a1aSMatthew Knepley /* For right now, we do not try to squeeze the subchart */
232129d2e75bSMatthew G. Knepley if (subpointIS) {
232229d2e75bSMatthew G. Knepley PetscCall(ISGetLocalSize(subpointIS, &numSubpoints));
232329d2e75bSMatthew G. Knepley PetscCall(ISGetIndices(subpointIS, &points));
2324ea844a1aSMatthew Knepley }
23259566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd));
232641f23ed0SMatthew G. Knepley if (renumberPoints) {
232729d2e75bSMatthew G. Knepley PetscBool sorted;
232829d2e75bSMatthew G. Knepley
232941f23ed0SMatthew G. Knepley spStart = 0;
233041f23ed0SMatthew G. Knepley spEnd = numSubpoints;
233129d2e75bSMatthew G. Knepley PetscCall(ISSorted(subpointIS, &sorted));
233229d2e75bSMatthew G. Knepley if (!sorted) {
233329d2e75bSMatthew G. Knepley PetscCall(PetscMalloc2(numSubpoints, &spoints, numSubpoints, &order));
233429d2e75bSMatthew G. Knepley PetscCall(PetscArraycpy(spoints, points, numSubpoints));
233529d2e75bSMatthew G. Knepley for (PetscInt i = 0; i < numSubpoints; ++i) order[i] = i;
233629d2e75bSMatthew G. Knepley PetscCall(PetscSortIntWithArray(numSubpoints, spoints, order));
233729d2e75bSMatthew G. Knepley }
233841f23ed0SMatthew G. Knepley } else {
233929d2e75bSMatthew G. Knepley PetscCall(ISGetMinMax(subpointIS, &spStart, &spEnd));
234041f23ed0SMatthew G. Knepley ++spEnd;
234141f23ed0SMatthew G. Knepley }
234241f23ed0SMatthew G. Knepley PetscCall(PetscSectionSetChart(*subs, spStart, spEnd));
2343ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) {
2344ea844a1aSMatthew Knepley PetscInt dof, cdof, fdof = 0, cfdof = 0;
2345ea844a1aSMatthew Knepley
234629d2e75bSMatthew G. Knepley PetscCall(PetscFindInt(p, numSubpoints, spoints ? spoints : points, &subp));
2347ea844a1aSMatthew Knepley if (subp < 0) continue;
234841f23ed0SMatthew G. Knepley if (!renumberPoints) subp = p;
234929d2e75bSMatthew G. Knepley else subp = order ? order[subp] : subp;
2350ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) {
23519566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, f, &fdof));
23529566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldDof(*subs, subp, f, fdof));
23539566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, f, &cfdof));
23549566063dSJacob Faibussowitsch if (cfdof) PetscCall(PetscSectionSetFieldConstraintDof(*subs, subp, f, cfdof));
2355ea844a1aSMatthew Knepley }
23569566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof));
23579566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(*subs, subp, dof));
23589566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof));
23599566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetConstraintDof(*subs, subp, cdof));
2360ea844a1aSMatthew Knepley }
23619566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(*subs));
2362ea844a1aSMatthew Knepley /* Change offsets to original offsets */
2363ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) {
2364ea844a1aSMatthew Knepley PetscInt off, foff = 0;
2365ea844a1aSMatthew Knepley
236629d2e75bSMatthew G. Knepley PetscCall(PetscFindInt(p, numSubpoints, spoints ? spoints : points, &subp));
2367ea844a1aSMatthew Knepley if (subp < 0) continue;
236841f23ed0SMatthew G. Knepley if (!renumberPoints) subp = p;
236929d2e75bSMatthew G. Knepley else subp = order ? order[subp] : subp;
2370ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) {
23719566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldOffset(s, p, f, &foff));
23729566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldOffset(*subs, subp, f, foff));
2373ea844a1aSMatthew Knepley }
23749566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s, p, &off));
23759566063dSJacob Faibussowitsch PetscCall(PetscSectionSetOffset(*subs, subp, off));
2376ea844a1aSMatthew Knepley }
2377ea844a1aSMatthew Knepley /* Copy constraint indices */
237841f23ed0SMatthew G. Knepley for (subp = spStart; subp < spEnd; ++subp) {
2379ea844a1aSMatthew Knepley PetscInt cdof;
2380ea844a1aSMatthew Knepley
23819566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(*subs, subp, &cdof));
2382ea844a1aSMatthew Knepley if (cdof) {
2383ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) {
238441f23ed0SMatthew G. Knepley PetscCall(PetscSectionGetFieldConstraintIndices(s, points[subp - spStart], f, &indices));
23859566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldConstraintIndices(*subs, subp, f, indices));
2386ea844a1aSMatthew Knepley }
238741f23ed0SMatthew G. Knepley PetscCall(PetscSectionGetConstraintIndices(s, points[subp - spStart], &indices));
23889566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(*subs, subp, indices));
2389ea844a1aSMatthew Knepley }
2390ea844a1aSMatthew Knepley }
239129d2e75bSMatthew G. Knepley if (subpointIS) PetscCall(ISRestoreIndices(subpointIS, &points));
239229d2e75bSMatthew G. Knepley PetscCall(PetscFree2(spoints, order));
23933ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2394ea844a1aSMatthew Knepley }
2395ea844a1aSMatthew Knepley
239641f23ed0SMatthew G. Knepley /*@
239741f23ed0SMatthew G. Knepley PetscSectionCreateSubmeshSection - Create a new, smaller section with support on the submesh
239841f23ed0SMatthew G. Knepley
2399c3339decSBarry Smith Collective
240041f23ed0SMatthew G. Knepley
240141f23ed0SMatthew G. Knepley Input Parameters:
2402cab54364SBarry Smith + s - the `PetscSection`
240329d2e75bSMatthew G. Knepley - subpointIS - a sorted list of points in the original mesh which are in the submesh
240441f23ed0SMatthew G. Knepley
240541f23ed0SMatthew G. Knepley Output Parameter:
240641f23ed0SMatthew G. Knepley . subs - the subsection
240741f23ed0SMatthew G. Knepley
2408cab54364SBarry Smith Level: advanced
2409cab54364SBarry Smith
2410583308b6SBarry Smith Notes:
2411583308b6SBarry Smith The points are renumbered from 0, and the section offsets now refer to a new, smaller vector. That is the chart of `subs` is `[0,sizeof(subpointmap))`
2412583308b6SBarry Smith
241320662ed9SBarry Smith Compare this with `PetscSectionCreateSubdomainSection()` that does not map the points numbers to start at zero but leaves them as before
241441f23ed0SMatthew G. Knepley
241538b5cf2dSJacob Faibussowitsch Developer Notes:
241620662ed9SBarry Smith The use of the term Submesh is confusing and needs clarification, it is not specific to meshes. It appears to be just a subset of the chart of the original `PetscSection`
241741f23ed0SMatthew G. Knepley
2418b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionCreateSubdomainSection()`, `PetscSectionCreateSubsection()`, `DMPlexGetSubpointMap()`, `PetscSectionCreate()`
241941f23ed0SMatthew G. Knepley @*/
PetscSectionCreateSubmeshSection(PetscSection s,IS subpointIS,PetscSection * subs)242029d2e75bSMatthew G. Knepley PetscErrorCode PetscSectionCreateSubmeshSection(PetscSection s, IS subpointIS, PetscSection *subs)
2421d71ae5a4SJacob Faibussowitsch {
242241f23ed0SMatthew G. Knepley PetscFunctionBegin;
242329d2e75bSMatthew G. Knepley PetscCall(PetscSectionCreateSubplexSection_Private(s, subpointIS, PETSC_TRUE, subs));
24243ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
242541f23ed0SMatthew G. Knepley }
242641f23ed0SMatthew G. Knepley
242741f23ed0SMatthew G. Knepley /*@
242841f23ed0SMatthew G. Knepley PetscSectionCreateSubdomainSection - Create a new, smaller section with support on a subdomain of the mesh
242941f23ed0SMatthew G. Knepley
2430c3339decSBarry Smith Collective
243141f23ed0SMatthew G. Knepley
243241f23ed0SMatthew G. Knepley Input Parameters:
2433cab54364SBarry Smith + s - the `PetscSection`
243441f23ed0SMatthew G. Knepley - subpointMap - a sorted list of points in the original mesh which are in the subdomain
243541f23ed0SMatthew G. Knepley
243641f23ed0SMatthew G. Knepley Output Parameter:
243741f23ed0SMatthew G. Knepley . subs - the subsection
243841f23ed0SMatthew G. Knepley
2439cab54364SBarry Smith Level: advanced
2440cab54364SBarry Smith
2441583308b6SBarry Smith Notes:
2442583308b6SBarry Smith The point numbers remain the same as in the larger `PetscSection`, but the section offsets now refer to a new, smaller vector. The chart of `subs`
2443583308b6SBarry Smith is `[min(subpointMap),max(subpointMap)+1)`
2444583308b6SBarry Smith
244520662ed9SBarry Smith Compare this with `PetscSectionCreateSubmeshSection()` that maps the point numbers to start at zero
244641f23ed0SMatthew G. Knepley
2447cab54364SBarry Smith Developer Notes:
244820662ed9SBarry Smith The use of the term Subdomain is unneeded and needs clarification, it is not specific to meshes. It appears to be just a subset of the chart of the original `PetscSection`
2449cab54364SBarry Smith
2450b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionCreateSubmeshSection()`, `PetscSectionCreateSubsection()`, `DMPlexGetSubpointMap()`, `PetscSectionCreate()`
245141f23ed0SMatthew G. Knepley @*/
PetscSectionCreateSubdomainSection(PetscSection s,IS subpointMap,PetscSection * subs)2452d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionCreateSubdomainSection(PetscSection s, IS subpointMap, PetscSection *subs)
2453d71ae5a4SJacob Faibussowitsch {
245441f23ed0SMatthew G. Knepley PetscFunctionBegin;
2455da8c939bSJacob Faibussowitsch PetscCall(PetscSectionCreateSubplexSection_Private(s, subpointMap, PETSC_FALSE, subs));
24563ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
245741f23ed0SMatthew G. Knepley }
245841f23ed0SMatthew G. Knepley
PetscSectionView_ASCII(PetscSection s,PetscViewer viewer)2459d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscSectionView_ASCII(PetscSection s, PetscViewer viewer)
2460d71ae5a4SJacob Faibussowitsch {
2461ea844a1aSMatthew Knepley PetscInt p;
2462ea844a1aSMatthew Knepley PetscMPIInt rank;
2463ea844a1aSMatthew Knepley
2464ea844a1aSMatthew Knepley PetscFunctionBegin;
24659566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_rank(PetscObjectComm((PetscObject)viewer), &rank));
24669566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushSynchronized(viewer));
24679566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "Process %d:\n", rank));
2468ea844a1aSMatthew Knepley for (p = 0; p < s->pEnd - s->pStart; ++p) {
24693857f682SStefano Zampini if (s->bc && s->bc->atlasDof[p] > 0) {
2470ea844a1aSMatthew Knepley PetscInt b;
24716497c311SBarry Smith PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " (%4" PetscInt_FMT ") dof %2" PetscInt_FMT " offset %3" PetscInt_FMT " constrained", p + s->pStart, s->atlasDof[p], s->atlasOff[p]));
2472083401c6SMatthew G. Knepley if (s->bcIndices) {
247348a46eb9SPierre Jolivet for (b = 0; b < s->bc->atlasDof[p]; ++b) PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " %" PetscInt_FMT, s->bcIndices[s->bc->atlasOff[p] + b]));
2474083401c6SMatthew G. Knepley }
24759566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "\n"));
2476ea844a1aSMatthew Knepley } else {
24776497c311SBarry Smith PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " (%4" PetscInt_FMT ") dof %2" PetscInt_FMT " offset %3" PetscInt_FMT "\n", p + s->pStart, s->atlasDof[p], s->atlasOff[p]));
2478ea844a1aSMatthew Knepley }
2479ea844a1aSMatthew Knepley }
24809566063dSJacob Faibussowitsch PetscCall(PetscViewerFlush(viewer));
24819566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPopSynchronized(viewer));
2482ea844a1aSMatthew Knepley if (s->sym) {
24839566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushTab(viewer));
24849566063dSJacob Faibussowitsch PetscCall(PetscSectionSymView(s->sym, viewer));
24859566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPopTab(viewer));
2486ea844a1aSMatthew Knepley }
24873ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2488ea844a1aSMatthew Knepley }
2489ea844a1aSMatthew Knepley
2490ffeef943SBarry Smith /*@
2491cab54364SBarry Smith PetscSectionViewFromOptions - View the `PetscSection` based on values in the options database
2492fe2efc57SMark
249340750d41SVaclav Hapla Collective
2494fe2efc57SMark
2495fe2efc57SMark Input Parameters:
249620662ed9SBarry Smith + A - the `PetscSection` object to view
2497cab54364SBarry Smith . obj - Optional object that provides the options prefix used for the options
2498736c3998SJose E. Roman - name - command line option
2499fe2efc57SMark
2500fe2efc57SMark Level: intermediate
2501cab54364SBarry Smith
250220662ed9SBarry Smith Note:
250320662ed9SBarry Smith See `PetscObjectViewFromOptions()` for available values of `PetscViewer` and `PetscViewerFormat`
250420662ed9SBarry Smith
2505b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionView`, `PetscObjectViewFromOptions()`, `PetscSectionCreate()`, `PetscSectionView()`
2506fe2efc57SMark @*/
PetscSectionViewFromOptions(PetscSection A,PetscObject obj,const char name[])2507d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionViewFromOptions(PetscSection A, PetscObject obj, const char name[])
2508d71ae5a4SJacob Faibussowitsch {
2509fe2efc57SMark PetscFunctionBegin;
2510fe2efc57SMark PetscValidHeaderSpecific(A, PETSC_SECTION_CLASSID, 1);
25119566063dSJacob Faibussowitsch PetscCall(PetscObjectViewFromOptions((PetscObject)A, obj, name));
25123ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2513fe2efc57SMark }
2514fe2efc57SMark
2515ffeef943SBarry Smith /*@
2516cab54364SBarry Smith PetscSectionView - Views a `PetscSection`
2517ea844a1aSMatthew Knepley
251840750d41SVaclav Hapla Collective
2519ea844a1aSMatthew Knepley
2520ea844a1aSMatthew Knepley Input Parameters:
2521cab54364SBarry Smith + s - the `PetscSection` object to view
252238b5cf2dSJacob Faibussowitsch - viewer - the viewer
2523ea844a1aSMatthew Knepley
2524cab54364SBarry Smith Level: beginner
2525cab54364SBarry Smith
25261ddd528eSksagiyam Note:
2527cab54364SBarry Smith `PetscSectionView()`, when viewer is of type `PETSCVIEWERHDF5`, only saves
25281ddd528eSksagiyam distribution independent data, such as dofs, offsets, constraint dofs,
25291ddd528eSksagiyam and constraint indices. Points that have negative dofs, for instance,
25301ddd528eSksagiyam are not saved as they represent points owned by other processes.
25311ddd528eSksagiyam Point numbering and rank assignment is currently not stored.
2532cab54364SBarry Smith The saved section can be loaded with `PetscSectionLoad()`.
25331ddd528eSksagiyam
2534b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionDestroy()`, `PetscSectionLoad()`, `PetscViewer`
2535ea844a1aSMatthew Knepley @*/
PetscSectionView(PetscSection s,PetscViewer viewer)2536d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionView(PetscSection s, PetscViewer viewer)
2537d71ae5a4SJacob Faibussowitsch {
25381ddd528eSksagiyam PetscBool isascii, ishdf5;
2539ea844a1aSMatthew Knepley PetscInt f;
2540ea844a1aSMatthew Knepley
2541ea844a1aSMatthew Knepley PetscFunctionBegin;
2542ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
25439566063dSJacob Faibussowitsch if (!viewer) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)s), &viewer));
2544ea844a1aSMatthew Knepley PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2);
25459566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii));
25469566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERHDF5, &ishdf5));
2547ea844a1aSMatthew Knepley if (isascii) {
25489566063dSJacob Faibussowitsch PetscCall(PetscObjectPrintClassNamePrefixType((PetscObject)s, viewer));
2549ea844a1aSMatthew Knepley if (s->numFields) {
25509566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT " fields\n", s->numFields));
2551ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) {
25524cd8913cSStefano Zampini PetscCall(PetscViewerASCIIPrintf(viewer, " field %" PetscInt_FMT " \"%s\" with %" PetscInt_FMT " components\n", f, s->fieldNames[f], s->numFieldComponents[f]));
25539566063dSJacob Faibussowitsch PetscCall(PetscSectionView_ASCII(s->field[f], viewer));
2554ea844a1aSMatthew Knepley }
2555ea844a1aSMatthew Knepley } else {
25569566063dSJacob Faibussowitsch PetscCall(PetscSectionView_ASCII(s, viewer));
2557ea844a1aSMatthew Knepley }
25581ddd528eSksagiyam } else if (ishdf5) {
25591ddd528eSksagiyam #if PetscDefined(HAVE_HDF5)
25609566063dSJacob Faibussowitsch PetscCall(PetscSectionView_HDF5_Internal(s, viewer));
25611ddd528eSksagiyam #else
25621ddd528eSksagiyam SETERRQ(PetscObjectComm((PetscObject)s), PETSC_ERR_SUP, "HDF5 not supported in this build.\nPlease reconfigure using --download-hdf5");
25631ddd528eSksagiyam #endif
2564ea844a1aSMatthew Knepley }
25653ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2566ea844a1aSMatthew Knepley }
2567ea844a1aSMatthew Knepley
2568ffeef943SBarry Smith /*@
2569cab54364SBarry Smith PetscSectionLoad - Loads a `PetscSection`
2570fde5e3acSksagiyam
257140750d41SVaclav Hapla Collective
2572fde5e3acSksagiyam
2573fde5e3acSksagiyam Input Parameters:
2574cab54364SBarry Smith + s - the `PetscSection` object to load
257538b5cf2dSJacob Faibussowitsch - viewer - the viewer
2576fde5e3acSksagiyam
2577cab54364SBarry Smith Level: beginner
2578cab54364SBarry Smith
2579fde5e3acSksagiyam Note:
2580cab54364SBarry Smith `PetscSectionLoad()`, when viewer is of type `PETSCVIEWERHDF5`, loads
2581cab54364SBarry Smith a section saved with `PetscSectionView()`. The number of processes
2582fde5e3acSksagiyam used here (N) does not need to be the same as that used when saving.
2583fde5e3acSksagiyam After calling this function, the chart of s on rank i will be set
2584fde5e3acSksagiyam to [0, E_i), where \sum_{i=0}^{N-1}E_i equals to the total number of
2585fde5e3acSksagiyam saved section points.
2586fde5e3acSksagiyam
2587b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionDestroy()`, `PetscSectionView()`
2588fde5e3acSksagiyam @*/
PetscSectionLoad(PetscSection s,PetscViewer viewer)2589d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionLoad(PetscSection s, PetscViewer viewer)
2590d71ae5a4SJacob Faibussowitsch {
2591fde5e3acSksagiyam PetscBool ishdf5;
2592fde5e3acSksagiyam
2593fde5e3acSksagiyam PetscFunctionBegin;
2594fde5e3acSksagiyam PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
2595fde5e3acSksagiyam PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2);
25969566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERHDF5, &ishdf5));
2597966bd95aSPierre Jolivet PetscCheck(ishdf5, PetscObjectComm((PetscObject)s), PETSC_ERR_SUP, "Viewer type %s not yet supported for PetscSection loading", ((PetscObject)viewer)->type_name);
2598fde5e3acSksagiyam #if PetscDefined(HAVE_HDF5)
25999566063dSJacob Faibussowitsch PetscCall(PetscSectionLoad_HDF5_Internal(s, viewer));
26003ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2601fde5e3acSksagiyam #else
2602fde5e3acSksagiyam SETERRQ(PetscObjectComm((PetscObject)s), PETSC_ERR_SUP, "HDF5 not supported in this build.\nPlease reconfigure using --download-hdf5");
2603fde5e3acSksagiyam #endif
2604fde5e3acSksagiyam }
2605fde5e3acSksagiyam
PrintArrayElement(void * array,PetscDataType data_type,PetscCount index,PetscViewer viewer)260613e2dd01SJames Wright static inline PetscErrorCode PrintArrayElement(void *array, PetscDataType data_type, PetscCount index, PetscViewer viewer)
260737fd50d0SJames Wright {
260837fd50d0SJames Wright PetscFunctionBeginUser;
260937fd50d0SJames Wright switch (data_type) {
261037fd50d0SJames Wright case PETSC_INT: {
261137fd50d0SJames Wright PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " %2" PetscInt_FMT, ((PetscInt *)array)[index]));
261237fd50d0SJames Wright break;
261337fd50d0SJames Wright }
261437fd50d0SJames Wright case PETSC_INT32: {
261537fd50d0SJames Wright PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " %2" PetscInt32_FMT, ((PetscInt32 *)array)[index]));
261637fd50d0SJames Wright break;
261737fd50d0SJames Wright }
261837fd50d0SJames Wright case PETSC_INT64: {
261937fd50d0SJames Wright PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " %2" PetscInt64_FMT, ((PetscInt64 *)array)[index]));
262037fd50d0SJames Wright break;
262137fd50d0SJames Wright }
262237fd50d0SJames Wright case PETSC_COUNT: {
262337fd50d0SJames Wright PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " %2" PetscCount_FMT, ((PetscCount *)array)[index]));
262437fd50d0SJames Wright break;
262537fd50d0SJames Wright }
262637fd50d0SJames Wright // PETSC_SCALAR is set to the appropriate type
262737fd50d0SJames Wright case PETSC_DOUBLE: {
262837fd50d0SJames Wright PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " %g", ((double *)array)[index]));
262937fd50d0SJames Wright break;
263037fd50d0SJames Wright }
263137fd50d0SJames Wright case PETSC_FLOAT: {
263237fd50d0SJames Wright PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " %g", (double)((float *)array)[index]));
263337fd50d0SJames Wright break;
263437fd50d0SJames Wright }
263537fd50d0SJames Wright #if defined(PETSC_USE_REAL___FLOAT128)
263637fd50d0SJames Wright case PETSC___FLOAT128: {
263713e2dd01SJames Wright PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " %g", (double)((PetscReal *)array)[index]));
263837fd50d0SJames Wright break;
263937fd50d0SJames Wright }
264037fd50d0SJames Wright #endif
264137fd50d0SJames Wright #if defined(PETSC_USE_REAL___FP16)
264237fd50d0SJames Wright case PETSC___FP16: {
264313e2dd01SJames Wright PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " %g", (double)((PetscReal *)array)[index]));
264437fd50d0SJames Wright break;
264537fd50d0SJames Wright }
264637fd50d0SJames Wright #endif
264737fd50d0SJames Wright #if defined(PETSC_HAVE_COMPLEX)
264837fd50d0SJames Wright case PETSC_COMPLEX: {
264937fd50d0SJames Wright PetscComplex v = ((PetscComplex *)array)[index];
265037fd50d0SJames Wright if (PetscImaginaryPartComplex(v) > 0.0) {
265137fd50d0SJames Wright PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " %g + %g i", (double)PetscRealPartComplex(v), (double)PetscImaginaryPartComplex(v)));
265237fd50d0SJames Wright } else if (PetscImaginaryPartComplex(v) < 0.0) {
265337fd50d0SJames Wright PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " %g - %g i", (double)PetscRealPartComplex(v), (double)(-PetscImaginaryPartComplex(v))));
265437fd50d0SJames Wright } else {
265537fd50d0SJames Wright PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " %g", (double)PetscRealPartComplex(v)));
265637fd50d0SJames Wright }
265737fd50d0SJames Wright break;
265837fd50d0SJames Wright }
265937fd50d0SJames Wright #endif
266037fd50d0SJames Wright default:
266137fd50d0SJames Wright SETERRQ(PetscObjectComm((PetscObject)viewer), PETSC_ERR_SUP, "PetscDataType %d (%s) not supported", data_type, PetscDataTypes[data_type]);
266237fd50d0SJames Wright }
266337fd50d0SJames Wright PetscFunctionReturn(PETSC_SUCCESS);
266437fd50d0SJames Wright }
266537fd50d0SJames Wright
PetscSectionArrayView_ASCII_Internal(PetscSection s,void * array,PetscDataType data_type,PetscViewer viewer)266637fd50d0SJames Wright PetscErrorCode PetscSectionArrayView_ASCII_Internal(PetscSection s, void *array, PetscDataType data_type, PetscViewer viewer)
266737fd50d0SJames Wright {
266837fd50d0SJames Wright PetscInt p, i;
266937fd50d0SJames Wright PetscMPIInt rank;
267037fd50d0SJames Wright
267137fd50d0SJames Wright PetscFunctionBegin;
267237fd50d0SJames Wright PetscCallMPI(MPI_Comm_rank(PetscObjectComm((PetscObject)viewer), &rank));
267337fd50d0SJames Wright PetscCall(PetscViewerASCIIPushSynchronized(viewer));
267437fd50d0SJames Wright PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "Process %d:\n", rank));
267537fd50d0SJames Wright for (p = 0; p < s->pEnd - s->pStart; ++p) {
267637fd50d0SJames Wright if (s->bc && (s->bc->atlasDof[p] > 0)) {
267737fd50d0SJames Wright PetscInt b;
267837fd50d0SJames Wright
267937fd50d0SJames Wright PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " (%4" PetscInt_FMT ") dof %2" PetscInt_FMT " offset %3" PetscInt_FMT, p + s->pStart, s->atlasDof[p], s->atlasOff[p]));
268013e2dd01SJames Wright for (i = s->atlasOff[p]; i < s->atlasOff[p] + s->atlasDof[p]; ++i) PetscCall(PrintArrayElement(array, data_type, i, viewer));
268137fd50d0SJames Wright PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " constrained"));
268237fd50d0SJames Wright for (b = 0; b < s->bc->atlasDof[p]; ++b) PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " %" PetscInt_FMT, s->bcIndices[s->bc->atlasOff[p] + b]));
268337fd50d0SJames Wright PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "\n"));
268437fd50d0SJames Wright } else {
268537fd50d0SJames Wright PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " (%4" PetscInt_FMT ") dof %2" PetscInt_FMT " offset %3" PetscInt_FMT, p + s->pStart, s->atlasDof[p], s->atlasOff[p]));
268613e2dd01SJames Wright for (i = s->atlasOff[p]; i < s->atlasOff[p] + s->atlasDof[p]; ++i) PetscCall(PrintArrayElement(array, data_type, i, viewer));
268737fd50d0SJames Wright PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "\n"));
268837fd50d0SJames Wright }
268937fd50d0SJames Wright }
269037fd50d0SJames Wright PetscCall(PetscViewerFlush(viewer));
269137fd50d0SJames Wright PetscCall(PetscViewerASCIIPopSynchronized(viewer));
269237fd50d0SJames Wright PetscFunctionReturn(PETSC_SUCCESS);
269337fd50d0SJames Wright }
269437fd50d0SJames Wright
269537fd50d0SJames Wright /*@
269637fd50d0SJames Wright PetscSectionArrayView - View an array, using the section to structure the values
269737fd50d0SJames Wright
269837fd50d0SJames Wright Collective
269937fd50d0SJames Wright
270037fd50d0SJames Wright Input Parameters:
270137fd50d0SJames Wright + s - the organizing `PetscSection`
270237fd50d0SJames Wright . array - the array of values
270337fd50d0SJames Wright . data_type - the `PetscDataType` of the array
270437fd50d0SJames Wright - viewer - the `PetscViewer`
270537fd50d0SJames Wright
270637fd50d0SJames Wright Level: developer
270737fd50d0SJames Wright
270837fd50d0SJames Wright .seealso: `PetscSection`, `PetscViewer`, `PetscSectionCreate()`, `VecSetValuesSection()`, `PetscSectionVecView()`
270937fd50d0SJames Wright @*/
PetscSectionArrayView(PetscSection s,void * array,PetscDataType data_type,PetscViewer viewer)271037fd50d0SJames Wright PetscErrorCode PetscSectionArrayView(PetscSection s, void *array, PetscDataType data_type, PetscViewer viewer)
271137fd50d0SJames Wright {
271237fd50d0SJames Wright PetscBool isascii;
271337fd50d0SJames Wright PetscInt f;
271437fd50d0SJames Wright
271537fd50d0SJames Wright PetscFunctionBegin;
271637fd50d0SJames Wright PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
271782ecdcb1SJames Wright if (!array) {
271882ecdcb1SJames Wright PetscInt size;
271982ecdcb1SJames Wright PetscCall(PetscSectionGetStorageSize(s, &size));
272082ecdcb1SJames Wright PetscCheck(size == 0, PetscObjectComm((PetscObject)s), PETSC_ERR_ARG_SIZ, "NULL array passed, but section's storage size is non-zero");
272182ecdcb1SJames Wright } else PetscAssertPointer(array, 2);
272237fd50d0SJames Wright if (!viewer) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)s), &viewer));
272337fd50d0SJames Wright PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 4);
272437fd50d0SJames Wright PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii));
272537fd50d0SJames Wright if (isascii) {
272637fd50d0SJames Wright if (s->numFields) {
272737fd50d0SJames Wright PetscCall(PetscViewerASCIIPrintf(viewer, "Array with %" PetscInt_FMT " fields\n", s->numFields));
272837fd50d0SJames Wright for (f = 0; f < s->numFields; ++f) {
272937fd50d0SJames Wright PetscCall(PetscViewerASCIIPrintf(viewer, " field %" PetscInt_FMT " with %" PetscInt_FMT " components\n", f, s->numFieldComponents[f]));
273037fd50d0SJames Wright PetscCall(PetscSectionArrayView_ASCII_Internal(s->field[f], array, data_type, viewer));
273137fd50d0SJames Wright }
273237fd50d0SJames Wright } else {
273337fd50d0SJames Wright PetscCall(PetscSectionArrayView_ASCII_Internal(s, array, data_type, viewer));
273437fd50d0SJames Wright }
273537fd50d0SJames Wright }
273637fd50d0SJames Wright PetscFunctionReturn(PETSC_SUCCESS);
273737fd50d0SJames Wright }
273837fd50d0SJames Wright
2739d4a1ad33SMatthew G. Knepley /*@
2740d4a1ad33SMatthew G. Knepley PetscSectionResetClosurePermutation - Remove any existing closure permutation
2741d4a1ad33SMatthew G. Knepley
2742d4a1ad33SMatthew G. Knepley Input Parameter:
2743e8e188d2SZach Atkins . section - The `PetscSection`
2744d4a1ad33SMatthew G. Knepley
2745d4a1ad33SMatthew G. Knepley Level: intermediate
2746d4a1ad33SMatthew G. Knepley
2747e8e188d2SZach Atkins .seealso: `PetscSectionSetClosurePermutation()`, `PetscSectionSetClosureIndex()`, `PetscSectionReset()`
2748d4a1ad33SMatthew G. Knepley @*/
PetscSectionResetClosurePermutation(PetscSection section)2749d4a1ad33SMatthew G. Knepley PetscErrorCode PetscSectionResetClosurePermutation(PetscSection section)
2750d71ae5a4SJacob Faibussowitsch {
2751c459fbc1SJed Brown PetscSectionClosurePermVal clVal;
2752c459fbc1SJed Brown
2753c459fbc1SJed Brown PetscFunctionBegin;
27543ba16761SJacob Faibussowitsch if (!section->clHash) PetscFunctionReturn(PETSC_SUCCESS);
2755c459fbc1SJed Brown kh_foreach_value(section->clHash, clVal, {
27569566063dSJacob Faibussowitsch PetscCall(PetscFree(clVal.perm));
27579566063dSJacob Faibussowitsch PetscCall(PetscFree(clVal.invPerm));
2758c459fbc1SJed Brown });
2759c459fbc1SJed Brown kh_destroy(ClPerm, section->clHash);
2760c459fbc1SJed Brown section->clHash = NULL;
27613ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2762c459fbc1SJed Brown }
2763c459fbc1SJed Brown
2764ea844a1aSMatthew Knepley /*@
2765583308b6SBarry Smith PetscSectionReset - Frees all section data, the section is then as if `PetscSectionCreate()` had just been called.
2766ea844a1aSMatthew Knepley
276740750d41SVaclav Hapla Not Collective
2768ea844a1aSMatthew Knepley
27692fe279fdSBarry Smith Input Parameter:
2770cab54364SBarry Smith . s - the `PetscSection`
2771ea844a1aSMatthew Knepley
2772ea844a1aSMatthew Knepley Level: beginner
2773ea844a1aSMatthew Knepley
2774b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionCreate()`
2775ea844a1aSMatthew Knepley @*/
PetscSectionReset(PetscSection s)2776d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionReset(PetscSection s)
2777d71ae5a4SJacob Faibussowitsch {
2778b778fa18SValeria Barra PetscInt f, c;
2779ea844a1aSMatthew Knepley
2780ea844a1aSMatthew Knepley PetscFunctionBegin;
2781ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
2782ea844a1aSMatthew Knepley for (f = 0; f < s->numFields; ++f) {
27839566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->field[f]));
27849566063dSJacob Faibussowitsch PetscCall(PetscFree(s->fieldNames[f]));
278548a46eb9SPierre Jolivet for (c = 0; c < s->numFieldComponents[f]; ++c) PetscCall(PetscFree(s->compNames[f][c]));
27869566063dSJacob Faibussowitsch PetscCall(PetscFree(s->compNames[f]));
2787ea844a1aSMatthew Knepley }
27889566063dSJacob Faibussowitsch PetscCall(PetscFree(s->numFieldComponents));
27899566063dSJacob Faibussowitsch PetscCall(PetscFree(s->fieldNames));
27909566063dSJacob Faibussowitsch PetscCall(PetscFree(s->compNames));
27919566063dSJacob Faibussowitsch PetscCall(PetscFree(s->field));
27929566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->bc));
27939566063dSJacob Faibussowitsch PetscCall(PetscFree(s->bcIndices));
27949566063dSJacob Faibussowitsch PetscCall(PetscFree2(s->atlasDof, s->atlasOff));
27959566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->clSection));
27969566063dSJacob Faibussowitsch PetscCall(ISDestroy(&s->clPoints));
27979566063dSJacob Faibussowitsch PetscCall(ISDestroy(&s->perm));
27983ec46b7bSMatthew G. Knepley PetscCall(PetscBTDestroy(&s->blockStarts));
2799d4a1ad33SMatthew G. Knepley PetscCall(PetscSectionResetClosurePermutation(s));
28009566063dSJacob Faibussowitsch PetscCall(PetscSectionSymDestroy(&s->sym));
28019566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s->clSection));
28029566063dSJacob Faibussowitsch PetscCall(ISDestroy(&s->clPoints));
280369c11d05SVaclav Hapla PetscCall(PetscSectionInvalidateMaxDof_Internal(s));
2804ea844a1aSMatthew Knepley s->pStart = -1;
2805ea844a1aSMatthew Knepley s->pEnd = -1;
2806ea844a1aSMatthew Knepley s->maxDof = 0;
2807ea844a1aSMatthew Knepley s->setup = PETSC_FALSE;
2808ea844a1aSMatthew Knepley s->numFields = 0;
2809ea844a1aSMatthew Knepley s->clObj = NULL;
28103ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2811ea844a1aSMatthew Knepley }
2812ea844a1aSMatthew Knepley
2813ea844a1aSMatthew Knepley /*@
2814583308b6SBarry Smith PetscSectionDestroy - Frees a `PetscSection`
2815ea844a1aSMatthew Knepley
281640750d41SVaclav Hapla Not Collective
2817ea844a1aSMatthew Knepley
28182fe279fdSBarry Smith Input Parameter:
2819cab54364SBarry Smith . s - the `PetscSection`
2820ea844a1aSMatthew Knepley
2821ea844a1aSMatthew Knepley Level: beginner
2822ea844a1aSMatthew Knepley
2823b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionCreate()`, `PetscSectionReset()`
2824ea844a1aSMatthew Knepley @*/
PetscSectionDestroy(PetscSection * s)2825d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionDestroy(PetscSection *s)
2826d71ae5a4SJacob Faibussowitsch {
2827ea844a1aSMatthew Knepley PetscFunctionBegin;
28283ba16761SJacob Faibussowitsch if (!*s) PetscFunctionReturn(PETSC_SUCCESS);
282962f17a49SStefano Zampini PetscValidHeaderSpecific(*s, PETSC_SECTION_CLASSID, 1);
2830f4f49eeaSPierre Jolivet if (--((PetscObject)*s)->refct > 0) {
2831ea844a1aSMatthew Knepley *s = NULL;
28323ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2833ea844a1aSMatthew Knepley }
28349566063dSJacob Faibussowitsch PetscCall(PetscSectionReset(*s));
28359566063dSJacob Faibussowitsch PetscCall(PetscHeaderDestroy(s));
28363ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2837ea844a1aSMatthew Knepley }
2838ea844a1aSMatthew Knepley
VecIntGetValuesSection_Private(const PetscInt * baseArray,PetscSection s,PetscInt point,const PetscInt ** values)2839da8c939bSJacob Faibussowitsch static PetscErrorCode VecIntGetValuesSection_Private(const PetscInt *baseArray, PetscSection s, PetscInt point, const PetscInt **values)
2840d71ae5a4SJacob Faibussowitsch {
2841ea844a1aSMatthew Knepley const PetscInt p = point - s->pStart;
2842ea844a1aSMatthew Knepley
2843ea844a1aSMatthew Knepley PetscFunctionBegin;
2844ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 2);
2845ea844a1aSMatthew Knepley *values = &baseArray[s->atlasOff[p]];
28463ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2847ea844a1aSMatthew Knepley }
2848ea844a1aSMatthew Knepley
VecIntSetValuesSection_Private(PetscInt * baseArray,PetscSection s,PetscInt point,const PetscInt values[],InsertMode mode)2849da8c939bSJacob Faibussowitsch static PetscErrorCode VecIntSetValuesSection_Private(PetscInt *baseArray, PetscSection s, PetscInt point, const PetscInt values[], InsertMode mode)
2850d71ae5a4SJacob Faibussowitsch {
2851ea844a1aSMatthew Knepley PetscInt *array;
2852ea844a1aSMatthew Knepley const PetscInt p = point - s->pStart;
2853ea844a1aSMatthew Knepley const PetscInt orientation = 0; /* Needs to be included for use in closure operations */
2854ea844a1aSMatthew Knepley PetscInt cDim = 0;
2855ea844a1aSMatthew Knepley
2856ea844a1aSMatthew Knepley PetscFunctionBegin;
2857ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 2);
28589566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cDim));
2859ea844a1aSMatthew Knepley array = &baseArray[s->atlasOff[p]];
2860ea844a1aSMatthew Knepley if (!cDim) {
2861ea844a1aSMatthew Knepley if (orientation >= 0) {
2862ea844a1aSMatthew Knepley const PetscInt dim = s->atlasDof[p];
2863ea844a1aSMatthew Knepley PetscInt i;
2864ea844a1aSMatthew Knepley
2865ea844a1aSMatthew Knepley if (mode == INSERT_VALUES) {
2866ad716f99SStefano Zampini for (i = 0; i < dim; ++i) array[i] = values ? values[i] : i;
2867ea844a1aSMatthew Knepley } else {
2868ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) array[i] += values[i];
2869ea844a1aSMatthew Knepley }
2870ea844a1aSMatthew Knepley } else {
2871ea844a1aSMatthew Knepley PetscInt offset = 0;
2872ea844a1aSMatthew Knepley PetscInt j = -1, field, i;
2873ea844a1aSMatthew Knepley
2874ea844a1aSMatthew Knepley for (field = 0; field < s->numFields; ++field) {
2875ea844a1aSMatthew Knepley const PetscInt dim = s->field[field]->atlasDof[p];
2876ea844a1aSMatthew Knepley
2877ad716f99SStefano Zampini for (i = dim - 1; i >= 0; --i) array[++j] = values ? values[i + offset] : i + offset;
2878ea844a1aSMatthew Knepley offset += dim;
2879ea844a1aSMatthew Knepley }
2880ea844a1aSMatthew Knepley }
2881ea844a1aSMatthew Knepley } else {
2882ea844a1aSMatthew Knepley if (orientation >= 0) {
2883ea844a1aSMatthew Knepley const PetscInt dim = s->atlasDof[p];
2884ea844a1aSMatthew Knepley PetscInt cInd = 0, i;
2885ea844a1aSMatthew Knepley const PetscInt *cDof;
2886ea844a1aSMatthew Knepley
28879566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s, point, &cDof));
2888ea844a1aSMatthew Knepley if (mode == INSERT_VALUES) {
2889ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) {
28909371c9d4SSatish Balay if ((cInd < cDim) && (i == cDof[cInd])) {
28919371c9d4SSatish Balay ++cInd;
28929371c9d4SSatish Balay continue;
28939371c9d4SSatish Balay }
2894ad716f99SStefano Zampini array[i] = values ? values[i] : i;
2895ea844a1aSMatthew Knepley }
2896ea844a1aSMatthew Knepley } else {
2897ea844a1aSMatthew Knepley for (i = 0; i < dim; ++i) {
28989371c9d4SSatish Balay if ((cInd < cDim) && (i == cDof[cInd])) {
28999371c9d4SSatish Balay ++cInd;
29009371c9d4SSatish Balay continue;
29019371c9d4SSatish Balay }
2902ea844a1aSMatthew Knepley array[i] += values[i];
2903ea844a1aSMatthew Knepley }
2904ea844a1aSMatthew Knepley }
2905ea844a1aSMatthew Knepley } else {
2906ea844a1aSMatthew Knepley const PetscInt *cDof;
2907ea844a1aSMatthew Knepley PetscInt offset = 0;
2908ea844a1aSMatthew Knepley PetscInt cOffset = 0;
2909ea844a1aSMatthew Knepley PetscInt j = 0, field;
2910ea844a1aSMatthew Knepley
29119566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s, point, &cDof));
2912ea844a1aSMatthew Knepley for (field = 0; field < s->numFields; ++field) {
2913ea844a1aSMatthew Knepley const PetscInt dim = s->field[field]->atlasDof[p]; /* PetscSectionGetFieldDof() */
2914ea844a1aSMatthew Knepley const PetscInt tDim = s->field[field]->bc->atlasDof[p]; /* PetscSectionGetFieldConstraintDof() */
2915ea844a1aSMatthew Knepley const PetscInt sDim = dim - tDim;
2916ea844a1aSMatthew Knepley PetscInt cInd = 0, i, k;
2917ea844a1aSMatthew Knepley
2918ea844a1aSMatthew Knepley for (i = 0, k = dim + offset - 1; i < dim; ++i, ++j, --k) {
29199371c9d4SSatish Balay if ((cInd < sDim) && (j == cDof[cInd + cOffset])) {
29209371c9d4SSatish Balay ++cInd;
29219371c9d4SSatish Balay continue;
29229371c9d4SSatish Balay }
2923ad716f99SStefano Zampini array[j] = values ? values[k] : k;
2924ea844a1aSMatthew Knepley }
2925ea844a1aSMatthew Knepley offset += dim;
2926ea844a1aSMatthew Knepley cOffset += dim - tDim;
2927ea844a1aSMatthew Knepley }
2928ea844a1aSMatthew Knepley }
2929ea844a1aSMatthew Knepley }
29303ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2931ea844a1aSMatthew Knepley }
2932ea844a1aSMatthew Knepley
2933cc4c1da9SBarry Smith /*@
293420662ed9SBarry Smith PetscSectionHasConstraints - Determine whether a `PetscSection` has constrained dofs
2935ea844a1aSMatthew Knepley
293640750d41SVaclav Hapla Not Collective
2937ea844a1aSMatthew Knepley
2938ea844a1aSMatthew Knepley Input Parameter:
2939cab54364SBarry Smith . s - The `PetscSection`
2940ea844a1aSMatthew Knepley
2941ea844a1aSMatthew Knepley Output Parameter:
2942ea844a1aSMatthew Knepley . hasConstraints - flag indicating that the section has constrained dofs
2943ea844a1aSMatthew Knepley
2944ea844a1aSMatthew Knepley Level: intermediate
2945ea844a1aSMatthew Knepley
2946b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSetConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection`
2947ea844a1aSMatthew Knepley @*/
PetscSectionHasConstraints(PetscSection s,PetscBool * hasConstraints)2948d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionHasConstraints(PetscSection s, PetscBool *hasConstraints)
2949d71ae5a4SJacob Faibussowitsch {
2950ea844a1aSMatthew Knepley PetscFunctionBegin;
2951ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
29524f572ea9SToby Isaac PetscAssertPointer(hasConstraints, 2);
2953ea844a1aSMatthew Knepley *hasConstraints = s->bc ? PETSC_TRUE : PETSC_FALSE;
29543ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2955ea844a1aSMatthew Knepley }
2956ea844a1aSMatthew Knepley
2957ea844a1aSMatthew Knepley /*@C
295820662ed9SBarry Smith PetscSectionGetConstraintIndices - Get the point dof numbers, in [0, dof), which are constrained for a given point
2959ea844a1aSMatthew Knepley
296040750d41SVaclav Hapla Not Collective
2961ea844a1aSMatthew Knepley
2962ea844a1aSMatthew Knepley Input Parameters:
2963cab54364SBarry Smith + s - The `PetscSection`
2964ea844a1aSMatthew Knepley - point - The point
2965ea844a1aSMatthew Knepley
2966ea844a1aSMatthew Knepley Output Parameter:
2967ea844a1aSMatthew Knepley . indices - The constrained dofs
2968ea844a1aSMatthew Knepley
2969ea844a1aSMatthew Knepley Level: intermediate
2970ea844a1aSMatthew Knepley
297138b5cf2dSJacob Faibussowitsch Fortran Notes:
2972ce78bad3SBarry Smith Use `PetscSectionRestoreConstraintIndices()` when the indices are no longer needed
2973cab54364SBarry Smith
2974b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSetConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection`
2975ea844a1aSMatthew Knepley @*/
PetscSectionGetConstraintIndices(PetscSection s,PetscInt point,const PetscInt * indices[])2976cc4c1da9SBarry Smith PetscErrorCode PetscSectionGetConstraintIndices(PetscSection s, PetscInt point, const PetscInt *indices[])
2977d71ae5a4SJacob Faibussowitsch {
2978ea844a1aSMatthew Knepley PetscFunctionBegin;
2979ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
2980ac530a7eSPierre Jolivet if (s->bc) PetscCall(VecIntGetValuesSection_Private(s->bcIndices, s->bc, point, indices));
2981ac530a7eSPierre Jolivet else *indices = NULL;
29823ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
2983ea844a1aSMatthew Knepley }
2984ea844a1aSMatthew Knepley
2985cc4c1da9SBarry Smith /*@
2986ea844a1aSMatthew Knepley PetscSectionSetConstraintIndices - Set the point dof numbers, in [0, dof), which are constrained
2987ea844a1aSMatthew Knepley
298840750d41SVaclav Hapla Not Collective
2989ea844a1aSMatthew Knepley
2990ea844a1aSMatthew Knepley Input Parameters:
2991cab54364SBarry Smith + s - The `PetscSection`
2992ea844a1aSMatthew Knepley . point - The point
2993ea844a1aSMatthew Knepley - indices - The constrained dofs
2994ea844a1aSMatthew Knepley
2995ea844a1aSMatthew Knepley Level: intermediate
2996ea844a1aSMatthew Knepley
2997b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionGetConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection`
2998ea844a1aSMatthew Knepley @*/
PetscSectionSetConstraintIndices(PetscSection s,PetscInt point,const PetscInt indices[])2999d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetConstraintIndices(PetscSection s, PetscInt point, const PetscInt indices[])
3000d71ae5a4SJacob Faibussowitsch {
3001ea844a1aSMatthew Knepley PetscFunctionBegin;
3002ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
3003ea844a1aSMatthew Knepley if (s->bc) {
3004d57bb9dbSMatthew G. Knepley const PetscInt dof = s->atlasDof[point];
3005d57bb9dbSMatthew G. Knepley const PetscInt cdof = s->bc->atlasDof[point];
3006d57bb9dbSMatthew G. Knepley PetscInt d;
3007d57bb9dbSMatthew G. Knepley
3008ad716f99SStefano Zampini if (indices)
3009ad540459SPierre Jolivet for (d = 0; d < cdof; ++d) PetscCheck(indices[d] < dof, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Point %" PetscInt_FMT " dof %" PetscInt_FMT ", invalid constraint index[%" PetscInt_FMT "]: %" PetscInt_FMT, point, dof, d, indices[d]);
3010da8c939bSJacob Faibussowitsch PetscCall(VecIntSetValuesSection_Private(s->bcIndices, s->bc, point, indices, INSERT_VALUES));
3011ea844a1aSMatthew Knepley }
30123ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3013ea844a1aSMatthew Knepley }
3014ea844a1aSMatthew Knepley
3015ea844a1aSMatthew Knepley /*@C
3016ea844a1aSMatthew Knepley PetscSectionGetFieldConstraintIndices - Get the field dof numbers, in [0, fdof), which are constrained
3017ea844a1aSMatthew Knepley
301840750d41SVaclav Hapla Not Collective
3019ea844a1aSMatthew Knepley
3020ea844a1aSMatthew Knepley Input Parameters:
3021cab54364SBarry Smith + s - The `PetscSection`
3022ea844a1aSMatthew Knepley . field - The field number
3023ea844a1aSMatthew Knepley - point - The point
3024ea844a1aSMatthew Knepley
3025ea844a1aSMatthew Knepley Output Parameter:
3026ce78bad3SBarry Smith . indices - The constrained dofs sorted in ascending order, the length is returned by `PetscSectionGetConstraintDof()`.
3027ea844a1aSMatthew Knepley
3028ea844a1aSMatthew Knepley Level: intermediate
3029ea844a1aSMatthew Knepley
303038b5cf2dSJacob Faibussowitsch Fortran Notes:
3031ce78bad3SBarry Smith Use `PetscSectionRestoreFieldConstraintIndices()` to restore the indices when no longer needed
3032cab54364SBarry Smith
3033b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSetFieldConstraintIndices()`, `PetscSectionGetConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection`
3034ea844a1aSMatthew Knepley @*/
PetscSectionGetFieldConstraintIndices(PetscSection s,PetscInt point,PetscInt field,const PetscInt * indices[])3035ce78bad3SBarry Smith PetscErrorCode PetscSectionGetFieldConstraintIndices(PetscSection s, PetscInt point, PetscInt field, const PetscInt *indices[])
3036d71ae5a4SJacob Faibussowitsch {
3037ea844a1aSMatthew Knepley PetscFunctionBegin;
3038ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
30394f572ea9SToby Isaac PetscAssertPointer(indices, 4);
30402abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields);
30419566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s->field[field], point, indices));
30423ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3043ea844a1aSMatthew Knepley }
3044ea844a1aSMatthew Knepley
3045ce78bad3SBarry Smith /*@
3046ea844a1aSMatthew Knepley PetscSectionSetFieldConstraintIndices - Set the field dof numbers, in [0, fdof), which are constrained
3047ea844a1aSMatthew Knepley
304840750d41SVaclav Hapla Not Collective
3049ea844a1aSMatthew Knepley
3050ea844a1aSMatthew Knepley Input Parameters:
3051cab54364SBarry Smith + s - The `PetscSection`
3052ea844a1aSMatthew Knepley . point - The point
3053ea844a1aSMatthew Knepley . field - The field number
3054ea844a1aSMatthew Knepley - indices - The constrained dofs
3055ea844a1aSMatthew Knepley
3056ea844a1aSMatthew Knepley Level: intermediate
3057ea844a1aSMatthew Knepley
3058b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSetConstraintIndices()`, `PetscSectionGetFieldConstraintIndices()`, `PetscSectionGetConstraintDof()`, `PetscSection`
3059ea844a1aSMatthew Knepley @*/
PetscSectionSetFieldConstraintIndices(PetscSection s,PetscInt point,PetscInt field,const PetscInt indices[])3060d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldConstraintIndices(PetscSection s, PetscInt point, PetscInt field, const PetscInt indices[])
3061d71ae5a4SJacob Faibussowitsch {
3062ea844a1aSMatthew Knepley PetscFunctionBegin;
3063ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
30642abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields);
30659566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(s->field[field], point, indices));
30663ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3067ea844a1aSMatthew Knepley }
3068ea844a1aSMatthew Knepley
3069ea844a1aSMatthew Knepley /*@
3070ea844a1aSMatthew Knepley PetscSectionPermute - Reorder the section according to the input point permutation
3071ea844a1aSMatthew Knepley
307240750d41SVaclav Hapla Collective
3073ea844a1aSMatthew Knepley
3074d8d19677SJose E. Roman Input Parameters:
3075cab54364SBarry Smith + section - The `PetscSection` object
307638b5cf2dSJacob Faibussowitsch - permutation - The point permutation, old point p becomes new point perm[p]
3077ea844a1aSMatthew Knepley
3078ea844a1aSMatthew Knepley Output Parameter:
3079cab54364SBarry Smith . sectionNew - The permuted `PetscSection`
3080ea844a1aSMatthew Knepley
3081ea844a1aSMatthew Knepley Level: intermediate
3082ea844a1aSMatthew Knepley
3083583308b6SBarry Smith Note:
3084583308b6SBarry Smith The data and the access to the data via `PetscSectionGetFieldOffset()` and `PetscSectionGetOffset()` are both changed in `sectionNew`
3085583308b6SBarry Smith
3086583308b6SBarry Smith Compare to `PetscSectionSetPermutation()`
3087583308b6SBarry Smith
3088b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `IS`, `PetscSection`, `MatPermute()`, `PetscSectionSetPermutation()`
3089ea844a1aSMatthew Knepley @*/
PetscSectionPermute(PetscSection section,IS permutation,PetscSection * sectionNew)3090d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionPermute(PetscSection section, IS permutation, PetscSection *sectionNew)
3091d71ae5a4SJacob Faibussowitsch {
3092ea844a1aSMatthew Knepley PetscSection s = section, sNew;
3093ea844a1aSMatthew Knepley const PetscInt *perm;
3094b778fa18SValeria Barra PetscInt numFields, f, c, numPoints, pStart, pEnd, p;
3095ea844a1aSMatthew Knepley
3096ea844a1aSMatthew Knepley PetscFunctionBegin;
3097ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1);
3098ea844a1aSMatthew Knepley PetscValidHeaderSpecific(permutation, IS_CLASSID, 2);
30994f572ea9SToby Isaac PetscAssertPointer(sectionNew, 3);
31009566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject)s), &sNew));
31019566063dSJacob Faibussowitsch PetscCall(PetscSectionGetNumFields(s, &numFields));
31029566063dSJacob Faibussowitsch if (numFields) PetscCall(PetscSectionSetNumFields(sNew, numFields));
3103ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) {
3104ea844a1aSMatthew Knepley const char *name;
3105ea844a1aSMatthew Knepley PetscInt numComp;
3106ea844a1aSMatthew Knepley
31079566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldName(s, f, &name));
31089566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldName(sNew, f, name));
31099566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldComponents(s, f, &numComp));
31109566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldComponents(sNew, f, numComp));
3111b778fa18SValeria Barra for (c = 0; c < s->numFieldComponents[f]; ++c) {
31129566063dSJacob Faibussowitsch PetscCall(PetscSectionGetComponentName(s, f, c, &name));
31139566063dSJacob Faibussowitsch PetscCall(PetscSectionSetComponentName(sNew, f, c, name));
3114b778fa18SValeria Barra }
3115ea844a1aSMatthew Knepley }
31169566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(permutation, &numPoints));
31179566063dSJacob Faibussowitsch PetscCall(ISGetIndices(permutation, &perm));
31189566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(s, &pStart, &pEnd));
31199566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(sNew, pStart, pEnd));
312008401ef6SPierre Jolivet PetscCheck(numPoints >= pEnd, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Permutation size %" PetscInt_FMT " is less than largest Section point %" PetscInt_FMT, numPoints, pEnd);
3121ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) {
3122ea844a1aSMatthew Knepley PetscInt dof, cdof;
3123ea844a1aSMatthew Knepley
31249566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, p, &dof));
31259566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(sNew, perm[p], dof));
31269566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof));
31279566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetConstraintDof(sNew, perm[p], cdof));
3128ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) {
31299566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldDof(s, p, f, &dof));
31309566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldDof(sNew, perm[p], f, dof));
31319566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, f, &cdof));
31329566063dSJacob Faibussowitsch if (cdof) PetscCall(PetscSectionSetFieldConstraintDof(sNew, perm[p], f, cdof));
3133ea844a1aSMatthew Knepley }
3134ea844a1aSMatthew Knepley }
31359566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(sNew));
3136ea844a1aSMatthew Knepley for (p = pStart; p < pEnd; ++p) {
3137ea844a1aSMatthew Knepley const PetscInt *cind;
3138ea844a1aSMatthew Knepley PetscInt cdof;
3139ea844a1aSMatthew Knepley
31409566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintDof(s, p, &cdof));
3141ea844a1aSMatthew Knepley if (cdof) {
31429566063dSJacob Faibussowitsch PetscCall(PetscSectionGetConstraintIndices(s, p, &cind));
31439566063dSJacob Faibussowitsch PetscCall(PetscSectionSetConstraintIndices(sNew, perm[p], cind));
3144ea844a1aSMatthew Knepley }
3145ea844a1aSMatthew Knepley for (f = 0; f < numFields; ++f) {
31469566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintDof(s, p, f, &cdof));
3147ea844a1aSMatthew Knepley if (cdof) {
31489566063dSJacob Faibussowitsch PetscCall(PetscSectionGetFieldConstraintIndices(s, p, f, &cind));
31499566063dSJacob Faibussowitsch PetscCall(PetscSectionSetFieldConstraintIndices(sNew, perm[p], f, cind));
3150ea844a1aSMatthew Knepley }
3151ea844a1aSMatthew Knepley }
3152ea844a1aSMatthew Knepley }
31539566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(permutation, &perm));
3154ea844a1aSMatthew Knepley *sectionNew = sNew;
31553ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3156ea844a1aSMatthew Knepley }
3157ea844a1aSMatthew Knepley
3158ea844a1aSMatthew Knepley /*@
315920662ed9SBarry Smith PetscSectionSetClosureIndex - Create an internal data structure to speed up closure queries.
3160ea844a1aSMatthew Knepley
316140750d41SVaclav Hapla Collective
3162ea844a1aSMatthew Knepley
3163ea844a1aSMatthew Knepley Input Parameters:
3164cab54364SBarry Smith + section - The `PetscSection`
3165cab54364SBarry Smith . obj - A `PetscObject` which serves as the key for this index
3166cab54364SBarry Smith . clSection - `PetscSection` giving the size of the closure of each point
3167cab54364SBarry Smith - clPoints - `IS` giving the points in each closure
3168ea844a1aSMatthew Knepley
3169ea844a1aSMatthew Knepley Level: advanced
3170ea844a1aSMatthew Knepley
3171cab54364SBarry Smith Note:
317220662ed9SBarry Smith This function creates an internal map from each point to its closure. We compress out closure points with no dofs in this section.
317320662ed9SBarry Smith
317438b5cf2dSJacob Faibussowitsch Developer Notes:
317520662ed9SBarry Smith The information provided here is completely opaque
3176cab54364SBarry Smith
3177b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionGetClosureIndex()`, `DMPlexCreateClosureIndex()`
3178ea844a1aSMatthew Knepley @*/
PetscSectionSetClosureIndex(PetscSection section,PetscObject obj,PetscSection clSection,IS clPoints)3179d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetClosureIndex(PetscSection section, PetscObject obj, PetscSection clSection, IS clPoints)
3180d71ae5a4SJacob Faibussowitsch {
3181ea844a1aSMatthew Knepley PetscFunctionBegin;
31823e03ebd8SStefano Zampini PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1);
31833e03ebd8SStefano Zampini PetscValidHeaderSpecific(clSection, PETSC_SECTION_CLASSID, 3);
31843e03ebd8SStefano Zampini PetscValidHeaderSpecific(clPoints, IS_CLASSID, 4);
3185d4a1ad33SMatthew G. Knepley if (section->clObj != obj) PetscCall(PetscSectionResetClosurePermutation(section));
3186ea844a1aSMatthew Knepley section->clObj = obj;
31879566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)clSection));
31889566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)clPoints));
31899566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(§ion->clSection));
31909566063dSJacob Faibussowitsch PetscCall(ISDestroy(§ion->clPoints));
3191ea844a1aSMatthew Knepley section->clSection = clSection;
3192ea844a1aSMatthew Knepley section->clPoints = clPoints;
31933ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3194ea844a1aSMatthew Knepley }
3195ea844a1aSMatthew Knepley
3196ea844a1aSMatthew Knepley /*@
3197cab54364SBarry Smith PetscSectionGetClosureIndex - Get the cache of points in the closure of each point in the section set with `PetscSectionSetClosureIndex()`
3198ea844a1aSMatthew Knepley
319940750d41SVaclav Hapla Collective
3200ea844a1aSMatthew Knepley
3201ea844a1aSMatthew Knepley Input Parameters:
3202cab54364SBarry Smith + section - The `PetscSection`
3203cab54364SBarry Smith - obj - A `PetscObject` which serves as the key for this index
3204ea844a1aSMatthew Knepley
3205ea844a1aSMatthew Knepley Output Parameters:
3206cab54364SBarry Smith + clSection - `PetscSection` giving the size of the closure of each point
3207cab54364SBarry Smith - clPoints - `IS` giving the points in each closure
3208ea844a1aSMatthew Knepley
3209ea844a1aSMatthew Knepley Level: advanced
3210ea844a1aSMatthew Knepley
3211b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSetClosureIndex()`, `DMPlexCreateClosureIndex()`
3212ea844a1aSMatthew Knepley @*/
PetscSectionGetClosureIndex(PetscSection section,PetscObject obj,PetscSection * clSection,IS * clPoints)3213d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosureIndex(PetscSection section, PetscObject obj, PetscSection *clSection, IS *clPoints)
3214d71ae5a4SJacob Faibussowitsch {
3215ea844a1aSMatthew Knepley PetscFunctionBegin;
3216ea844a1aSMatthew Knepley if (section->clObj == obj) {
3217ea844a1aSMatthew Knepley if (clSection) *clSection = section->clSection;
3218ea844a1aSMatthew Knepley if (clPoints) *clPoints = section->clPoints;
3219ea844a1aSMatthew Knepley } else {
3220ea844a1aSMatthew Knepley if (clSection) *clSection = NULL;
3221ea844a1aSMatthew Knepley if (clPoints) *clPoints = NULL;
3222ea844a1aSMatthew Knepley }
32233ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3224ea844a1aSMatthew Knepley }
3225ea844a1aSMatthew Knepley
PetscSectionSetClosurePermutation_Internal(PetscSection section,PetscObject obj,PetscInt depth,PetscInt clSize,PetscCopyMode mode,PetscInt * clPerm)3226d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetClosurePermutation_Internal(PetscSection section, PetscObject obj, PetscInt depth, PetscInt clSize, PetscCopyMode mode, PetscInt *clPerm)
3227d71ae5a4SJacob Faibussowitsch {
3228ea844a1aSMatthew Knepley PetscInt i;
3229c459fbc1SJed Brown khiter_t iter;
3230c459fbc1SJed Brown int new_entry;
3231c459fbc1SJed Brown PetscSectionClosurePermKey key = {depth, clSize};
3232c459fbc1SJed Brown PetscSectionClosurePermVal *val;
3233ea844a1aSMatthew Knepley
3234ea844a1aSMatthew Knepley PetscFunctionBegin;
3235ea844a1aSMatthew Knepley if (section->clObj != obj) {
32369566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(§ion->clSection));
32379566063dSJacob Faibussowitsch PetscCall(ISDestroy(§ion->clPoints));
3238ea844a1aSMatthew Knepley }
3239ea844a1aSMatthew Knepley section->clObj = obj;
32409566063dSJacob Faibussowitsch if (!section->clHash) PetscCall(PetscClPermCreate(§ion->clHash));
3241c459fbc1SJed Brown iter = kh_put(ClPerm, section->clHash, key, &new_entry);
3242c459fbc1SJed Brown val = &kh_val(section->clHash, iter);
3243c459fbc1SJed Brown if (!new_entry) {
32449566063dSJacob Faibussowitsch PetscCall(PetscFree(val->perm));
32459566063dSJacob Faibussowitsch PetscCall(PetscFree(val->invPerm));
3246c459fbc1SJed Brown }
3247ea844a1aSMatthew Knepley if (mode == PETSC_COPY_VALUES) {
32489566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(clSize, &val->perm));
32499566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(val->perm, clPerm, clSize));
3250ea844a1aSMatthew Knepley } else if (mode == PETSC_OWN_POINTER) {
3251c459fbc1SJed Brown val->perm = clPerm;
3252ea844a1aSMatthew Knepley } else SETERRQ(PetscObjectComm(obj), PETSC_ERR_SUP, "Do not support borrowed arrays");
32539566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(clSize, &val->invPerm));
3254c459fbc1SJed Brown for (i = 0; i < clSize; ++i) val->invPerm[clPerm[i]] = i;
32553ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3256ea844a1aSMatthew Knepley }
3257ea844a1aSMatthew Knepley
3258ea844a1aSMatthew Knepley /*@
3259c459fbc1SJed Brown PetscSectionSetClosurePermutation - Set the dof permutation for the closure of each cell in the section, meaning clPerm[newIndex] = oldIndex.
3260ea844a1aSMatthew Knepley
3261ea844a1aSMatthew Knepley Not Collective
3262ea844a1aSMatthew Knepley
3263ea844a1aSMatthew Knepley Input Parameters:
3264cab54364SBarry Smith + section - The `PetscSection`
3265cab54364SBarry Smith . obj - A `PetscObject` which serves as the key for this index (usually a `DM`)
3266c459fbc1SJed Brown . depth - Depth of points on which to apply the given permutation
3267ea844a1aSMatthew Knepley - perm - Permutation of the cell dof closure
3268ea844a1aSMatthew Knepley
3269cab54364SBarry Smith Level: intermediate
3270cab54364SBarry Smith
3271cab54364SBarry Smith Notes:
3272c459fbc1SJed Brown The specified permutation will only be applied to points at depth whose closure size matches the length of perm. In a
3273c459fbc1SJed Brown mixed-topology or variable-degree finite element space, this function can be called multiple times at each depth for
3274c459fbc1SJed Brown each topology and degree.
3275c459fbc1SJed Brown
3276c459fbc1SJed Brown This approach assumes that (depth, len(perm)) uniquely identifies the desired permutation; this might not be true for
3277c459fbc1SJed Brown exotic/enriched spaces on mixed topology meshes.
3278ea844a1aSMatthew Knepley
3279b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `IS`, `PetscSectionGetClosurePermutation()`, `PetscSectionGetClosureIndex()`, `DMPlexCreateClosureIndex()`, `PetscCopyMode`
3280ea844a1aSMatthew Knepley @*/
PetscSectionSetClosurePermutation(PetscSection section,PetscObject obj,PetscInt depth,IS perm)3281d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetClosurePermutation(PetscSection section, PetscObject obj, PetscInt depth, IS perm)
3282d71ae5a4SJacob Faibussowitsch {
3283ea844a1aSMatthew Knepley const PetscInt *clPerm = NULL;
3284ea844a1aSMatthew Knepley PetscInt clSize = 0;
3285ea844a1aSMatthew Knepley
3286ea844a1aSMatthew Knepley PetscFunctionBegin;
3287ea844a1aSMatthew Knepley if (perm) {
32889566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(perm, &clSize));
32899566063dSJacob Faibussowitsch PetscCall(ISGetIndices(perm, &clPerm));
3290ea844a1aSMatthew Knepley }
32919566063dSJacob Faibussowitsch PetscCall(PetscSectionSetClosurePermutation_Internal(section, obj, depth, clSize, PETSC_COPY_VALUES, (PetscInt *)clPerm));
32929566063dSJacob Faibussowitsch if (perm) PetscCall(ISRestoreIndices(perm, &clPerm));
32933ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3294ea844a1aSMatthew Knepley }
3295ea844a1aSMatthew Knepley
PetscSectionGetClosurePermutation_Private(PetscSection section,PetscObject obj,PetscInt depth,PetscInt size,const PetscInt * perm[])3296da8c939bSJacob Faibussowitsch static PetscErrorCode PetscSectionGetClosurePermutation_Private(PetscSection section, PetscObject obj, PetscInt depth, PetscInt size, const PetscInt *perm[])
3297d71ae5a4SJacob Faibussowitsch {
3298ea844a1aSMatthew Knepley PetscFunctionBegin;
3299ea844a1aSMatthew Knepley if (section->clObj == obj) {
3300c459fbc1SJed Brown PetscSectionClosurePermKey k = {depth, size};
3301c459fbc1SJed Brown PetscSectionClosurePermVal v;
3302da8c939bSJacob Faibussowitsch
33039566063dSJacob Faibussowitsch PetscCall(PetscClPermGet(section->clHash, k, &v));
3304c459fbc1SJed Brown if (perm) *perm = v.perm;
3305ea844a1aSMatthew Knepley } else {
3306ea844a1aSMatthew Knepley if (perm) *perm = NULL;
3307ea844a1aSMatthew Knepley }
33083ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3309ea844a1aSMatthew Knepley }
3310ea844a1aSMatthew Knepley
3311ea844a1aSMatthew Knepley /*@
3312ea844a1aSMatthew Knepley PetscSectionGetClosurePermutation - Get the dof permutation for the closure of each cell in the section, meaning clPerm[newIndex] = oldIndex.
3313ea844a1aSMatthew Knepley
331440750d41SVaclav Hapla Not Collective
3315ea844a1aSMatthew Knepley
3316ea844a1aSMatthew Knepley Input Parameters:
3317cab54364SBarry Smith + section - The `PetscSection`
3318cab54364SBarry Smith . obj - A `PetscObject` which serves as the key for this index (usually a DM)
3319c459fbc1SJed Brown . depth - Depth stratum on which to obtain closure permutation
3320c459fbc1SJed Brown - clSize - Closure size to be permuted (e.g., may vary with element topology and degree)
3321ea844a1aSMatthew Knepley
3322ea844a1aSMatthew Knepley Output Parameter:
3323ea844a1aSMatthew Knepley . perm - The dof closure permutation
3324ea844a1aSMatthew Knepley
3325ea844a1aSMatthew Knepley Level: intermediate
3326ea844a1aSMatthew Knepley
3327cab54364SBarry Smith Note:
3328cab54364SBarry Smith The user must destroy the `IS` that is returned.
3329cab54364SBarry Smith
3330b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `IS`, `PetscSectionSetClosurePermutation()`, `PetscSectionGetClosureInversePermutation()`, `PetscSectionGetClosureIndex()`, `PetscSectionSetClosureIndex()`, `DMPlexCreateClosureIndex()`
3331ea844a1aSMatthew Knepley @*/
PetscSectionGetClosurePermutation(PetscSection section,PetscObject obj,PetscInt depth,PetscInt clSize,IS * perm)3332d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosurePermutation(PetscSection section, PetscObject obj, PetscInt depth, PetscInt clSize, IS *perm)
3333d71ae5a4SJacob Faibussowitsch {
3334da8c939bSJacob Faibussowitsch const PetscInt *clPerm = NULL;
3335ea844a1aSMatthew Knepley
3336ea844a1aSMatthew Knepley PetscFunctionBegin;
3337da8c939bSJacob Faibussowitsch PetscCall(PetscSectionGetClosurePermutation_Private(section, obj, depth, clSize, &clPerm));
3338835f2295SStefano Zampini PetscCheck(clPerm, PetscObjectComm(obj), PETSC_ERR_ARG_WRONG, "There is no closure permutation associated with this object for depth %" PetscInt_FMT " of size %" PetscInt_FMT, depth, clSize);
33399566063dSJacob Faibussowitsch PetscCall(ISCreateGeneral(PETSC_COMM_SELF, clSize, clPerm, PETSC_USE_POINTER, perm));
33403ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3341ea844a1aSMatthew Knepley }
3342ea844a1aSMatthew Knepley
PetscSectionGetClosureInversePermutation_Internal(PetscSection section,PetscObject obj,PetscInt depth,PetscInt size,const PetscInt * perm[])3343d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosureInversePermutation_Internal(PetscSection section, PetscObject obj, PetscInt depth, PetscInt size, const PetscInt *perm[])
3344d71ae5a4SJacob Faibussowitsch {
3345ea844a1aSMatthew Knepley PetscFunctionBegin;
3346c459fbc1SJed Brown if (section->clObj == obj && section->clHash) {
3347c459fbc1SJed Brown PetscSectionClosurePermKey k = {depth, size};
3348c459fbc1SJed Brown PetscSectionClosurePermVal v;
33499566063dSJacob Faibussowitsch PetscCall(PetscClPermGet(section->clHash, k, &v));
3350c459fbc1SJed Brown if (perm) *perm = v.invPerm;
3351ea844a1aSMatthew Knepley } else {
3352ea844a1aSMatthew Knepley if (perm) *perm = NULL;
3353ea844a1aSMatthew Knepley }
33543ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3355ea844a1aSMatthew Knepley }
3356ea844a1aSMatthew Knepley
3357ea844a1aSMatthew Knepley /*@
3358ea844a1aSMatthew Knepley PetscSectionGetClosureInversePermutation - Get the inverse dof permutation for the closure of each cell in the section, meaning clPerm[oldIndex] = newIndex.
3359ea844a1aSMatthew Knepley
336040750d41SVaclav Hapla Not Collective
3361ea844a1aSMatthew Knepley
3362ea844a1aSMatthew Knepley Input Parameters:
3363cab54364SBarry Smith + section - The `PetscSection`
3364cab54364SBarry Smith . obj - A `PetscObject` which serves as the key for this index (usually a `DM`)
3365c459fbc1SJed Brown . depth - Depth stratum on which to obtain closure permutation
3366c459fbc1SJed Brown - clSize - Closure size to be permuted (e.g., may vary with element topology and degree)
3367ea844a1aSMatthew Knepley
33682fe279fdSBarry Smith Output Parameter:
3369c459fbc1SJed Brown . perm - The dof closure permutation
3370ea844a1aSMatthew Knepley
3371ea844a1aSMatthew Knepley Level: intermediate
3372ea844a1aSMatthew Knepley
3373cab54364SBarry Smith Note:
3374cab54364SBarry Smith The user must destroy the `IS` that is returned.
3375cab54364SBarry Smith
3376b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `IS`, `PetscSectionSetClosurePermutation()`, `PetscSectionGetClosureIndex()`, `PetscSectionSetClosureIndex()`, `DMPlexCreateClosureIndex()`
3377ea844a1aSMatthew Knepley @*/
PetscSectionGetClosureInversePermutation(PetscSection section,PetscObject obj,PetscInt depth,PetscInt clSize,IS * perm)3378d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetClosureInversePermutation(PetscSection section, PetscObject obj, PetscInt depth, PetscInt clSize, IS *perm)
3379d71ae5a4SJacob Faibussowitsch {
3380da8c939bSJacob Faibussowitsch const PetscInt *clPerm = NULL;
3381ea844a1aSMatthew Knepley
3382ea844a1aSMatthew Knepley PetscFunctionBegin;
33839566063dSJacob Faibussowitsch PetscCall(PetscSectionGetClosureInversePermutation_Internal(section, obj, depth, clSize, &clPerm));
33849566063dSJacob Faibussowitsch PetscCall(ISCreateGeneral(PETSC_COMM_SELF, clSize, clPerm, PETSC_USE_POINTER, perm));
33853ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3386ea844a1aSMatthew Knepley }
3387ea844a1aSMatthew Knepley
3388ea844a1aSMatthew Knepley /*@
3389583308b6SBarry Smith PetscSectionGetField - Get the `PetscSection` associated with a single field
3390ea844a1aSMatthew Knepley
3391ea844a1aSMatthew Knepley Input Parameters:
3392cab54364SBarry Smith + s - The `PetscSection`
3393ea844a1aSMatthew Knepley - field - The field number
3394ea844a1aSMatthew Knepley
3395ea844a1aSMatthew Knepley Output Parameter:
3396583308b6SBarry Smith . subs - The `PetscSection` for the given field, note the chart of `subs` is not set
3397ea844a1aSMatthew Knepley
3398ea844a1aSMatthew Knepley Level: intermediate
3399ea844a1aSMatthew Knepley
3400cab54364SBarry Smith Note:
3401cab54364SBarry Smith Does not increase the reference count of the selected sub-section. There is no matching `PetscSectionRestoreField()`
3402cab54364SBarry Smith
3403b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `IS`, `PetscSectionSetNumFields()`
3404ea844a1aSMatthew Knepley @*/
PetscSectionGetField(PetscSection s,PetscInt field,PetscSection * subs)3405d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetField(PetscSection s, PetscInt field, PetscSection *subs)
3406d71ae5a4SJacob Faibussowitsch {
3407ea844a1aSMatthew Knepley PetscFunctionBegin;
3408ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
34094f572ea9SToby Isaac PetscAssertPointer(subs, 3);
34102abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, s->numFields);
3411ea844a1aSMatthew Knepley *subs = s->field[field];
34123ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3413ea844a1aSMatthew Knepley }
3414ea844a1aSMatthew Knepley
3415ea844a1aSMatthew Knepley PetscClassId PETSC_SECTION_SYM_CLASSID;
3416ea844a1aSMatthew Knepley PetscFunctionList PetscSectionSymList = NULL;
3417ea844a1aSMatthew Knepley
3418ea844a1aSMatthew Knepley /*@
3419cab54364SBarry Smith PetscSectionSymCreate - Creates an empty `PetscSectionSym` object.
3420ea844a1aSMatthew Knepley
3421ea844a1aSMatthew Knepley Collective
3422ea844a1aSMatthew Knepley
3423ea844a1aSMatthew Knepley Input Parameter:
3424ea844a1aSMatthew Knepley . comm - the MPI communicator
3425ea844a1aSMatthew Knepley
3426ea844a1aSMatthew Knepley Output Parameter:
3427ea844a1aSMatthew Knepley . sym - pointer to the new set of symmetries
3428ea844a1aSMatthew Knepley
3429ea844a1aSMatthew Knepley Level: developer
3430ea844a1aSMatthew Knepley
3431b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSectionSym`, `PetscSectionSymDestroy()`
3432ea844a1aSMatthew Knepley @*/
PetscSectionSymCreate(MPI_Comm comm,PetscSectionSym * sym)3433d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymCreate(MPI_Comm comm, PetscSectionSym *sym)
3434d71ae5a4SJacob Faibussowitsch {
3435ea844a1aSMatthew Knepley PetscFunctionBegin;
34364f572ea9SToby Isaac PetscAssertPointer(sym, 2);
34379566063dSJacob Faibussowitsch PetscCall(ISInitializePackage());
3438377f809aSBarry Smith
34399566063dSJacob Faibussowitsch PetscCall(PetscHeaderCreate(*sym, PETSC_SECTION_SYM_CLASSID, "PetscSectionSym", "Section Symmetry", "IS", comm, PetscSectionSymDestroy, PetscSectionSymView));
34403ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3441ea844a1aSMatthew Knepley }
3442ea844a1aSMatthew Knepley
3443cc4c1da9SBarry Smith /*@
3444cab54364SBarry Smith PetscSectionSymSetType - Builds a `PetscSectionSym`, for a particular implementation.
3445ea844a1aSMatthew Knepley
344640750d41SVaclav Hapla Collective
3447ea844a1aSMatthew Knepley
3448ea844a1aSMatthew Knepley Input Parameters:
3449ea844a1aSMatthew Knepley + sym - The section symmetry object
3450ea844a1aSMatthew Knepley - method - The name of the section symmetry type
3451ea844a1aSMatthew Knepley
3452ea844a1aSMatthew Knepley Level: developer
3453ea844a1aSMatthew Knepley
3454b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSym`, `PetscSectionSymType`, `PetscSectionSymGetType()`, `PetscSectionSymCreate()`
3455ea844a1aSMatthew Knepley @*/
PetscSectionSymSetType(PetscSectionSym sym,PetscSectionSymType method)3456d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymSetType(PetscSectionSym sym, PetscSectionSymType method)
3457d71ae5a4SJacob Faibussowitsch {
3458ea844a1aSMatthew Knepley PetscErrorCode (*r)(PetscSectionSym);
3459ea844a1aSMatthew Knepley PetscBool match;
3460ea844a1aSMatthew Knepley
3461ea844a1aSMatthew Knepley PetscFunctionBegin;
3462ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1);
34639566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)sym, method, &match));
34643ba16761SJacob Faibussowitsch if (match) PetscFunctionReturn(PETSC_SUCCESS);
3465ea844a1aSMatthew Knepley
34669566063dSJacob Faibussowitsch PetscCall(PetscFunctionListFind(PetscSectionSymList, method, &r));
34676adde796SStefano Zampini PetscCheck(r, PetscObjectComm((PetscObject)sym), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscSectionSym type: %s", method);
3468dbbe0bcdSBarry Smith PetscTryTypeMethod(sym, destroy);
3469ea844a1aSMatthew Knepley sym->ops->destroy = NULL;
3470dbbe0bcdSBarry Smith
34719566063dSJacob Faibussowitsch PetscCall((*r)(sym));
34729566063dSJacob Faibussowitsch PetscCall(PetscObjectChangeTypeName((PetscObject)sym, method));
34733ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3474ea844a1aSMatthew Knepley }
3475ea844a1aSMatthew Knepley
3476cc4c1da9SBarry Smith /*@
3477cab54364SBarry Smith PetscSectionSymGetType - Gets the section symmetry type name (as a string) from the `PetscSectionSym`.
3478ea844a1aSMatthew Knepley
3479ea844a1aSMatthew Knepley Not Collective
3480ea844a1aSMatthew Knepley
3481ea844a1aSMatthew Knepley Input Parameter:
3482ea844a1aSMatthew Knepley . sym - The section symmetry
3483ea844a1aSMatthew Knepley
3484ea844a1aSMatthew Knepley Output Parameter:
3485ea844a1aSMatthew Knepley . type - The index set type name
3486ea844a1aSMatthew Knepley
3487ea844a1aSMatthew Knepley Level: developer
3488ea844a1aSMatthew Knepley
3489b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSym`, `PetscSectionSymType`, `PetscSectionSymSetType()`, `PetscSectionSymCreate()`
3490ea844a1aSMatthew Knepley @*/
PetscSectionSymGetType(PetscSectionSym sym,PetscSectionSymType * type)3491d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymGetType(PetscSectionSym sym, PetscSectionSymType *type)
3492d71ae5a4SJacob Faibussowitsch {
3493ea844a1aSMatthew Knepley PetscFunctionBegin;
3494ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1);
34954f572ea9SToby Isaac PetscAssertPointer(type, 2);
3496ea844a1aSMatthew Knepley *type = ((PetscObject)sym)->type_name;
34973ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3498ea844a1aSMatthew Knepley }
3499ea844a1aSMatthew Knepley
3500ea844a1aSMatthew Knepley /*@C
3501cab54364SBarry Smith PetscSectionSymRegister - Registers a new section symmetry implementation
3502ea844a1aSMatthew Knepley
3503cc4c1da9SBarry Smith Not Collective, No Fortran Support
3504ea844a1aSMatthew Knepley
3505ea844a1aSMatthew Knepley Input Parameters:
35062fe279fdSBarry Smith + sname - The name of a new user-defined creation routine
35072fe279fdSBarry Smith - function - The creation routine itself
3508ea844a1aSMatthew Knepley
3509ea844a1aSMatthew Knepley Level: developer
3510ea844a1aSMatthew Knepley
3511cab54364SBarry Smith Notes:
3512cab54364SBarry Smith `PetscSectionSymRegister()` may be called multiple times to add several user-defined vectors
3513cab54364SBarry Smith
3514b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSym`, `PetscSectionSymType`, `PetscSectionSymCreate()`, `PetscSectionSymSetType()`
3515ea844a1aSMatthew Knepley @*/
PetscSectionSymRegister(const char sname[],PetscErrorCode (* function)(PetscSectionSym))3516d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymRegister(const char sname[], PetscErrorCode (*function)(PetscSectionSym))
3517d71ae5a4SJacob Faibussowitsch {
3518ea844a1aSMatthew Knepley PetscFunctionBegin;
35199566063dSJacob Faibussowitsch PetscCall(ISInitializePackage());
35209566063dSJacob Faibussowitsch PetscCall(PetscFunctionListAdd(&PetscSectionSymList, sname, function));
35213ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3522ea844a1aSMatthew Knepley }
3523ea844a1aSMatthew Knepley
3524ea844a1aSMatthew Knepley /*@
3525ea844a1aSMatthew Knepley PetscSectionSymDestroy - Destroys a section symmetry.
3526ea844a1aSMatthew Knepley
352740750d41SVaclav Hapla Collective
3528ea844a1aSMatthew Knepley
35292fe279fdSBarry Smith Input Parameter:
3530ea844a1aSMatthew Knepley . sym - the section symmetry
3531ea844a1aSMatthew Knepley
3532ea844a1aSMatthew Knepley Level: developer
3533ea844a1aSMatthew Knepley
3534b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSym`, `PetscSectionSymCreate()`
3535ea844a1aSMatthew Knepley @*/
PetscSectionSymDestroy(PetscSectionSym * sym)3536d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymDestroy(PetscSectionSym *sym)
3537d71ae5a4SJacob Faibussowitsch {
3538ea844a1aSMatthew Knepley SymWorkLink link, next;
3539ea844a1aSMatthew Knepley
3540ea844a1aSMatthew Knepley PetscFunctionBegin;
35413ba16761SJacob Faibussowitsch if (!*sym) PetscFunctionReturn(PETSC_SUCCESS);
3542f4f49eeaSPierre Jolivet PetscValidHeaderSpecific(*sym, PETSC_SECTION_SYM_CLASSID, 1);
3543f4f49eeaSPierre Jolivet if (--((PetscObject)*sym)->refct > 0) {
35449371c9d4SSatish Balay *sym = NULL;
35453ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3546ea844a1aSMatthew Knepley }
3547213acdd3SPierre Jolivet PetscTryTypeMethod(*sym, destroy);
3548c9cc58a2SBarry Smith PetscCheck(!(*sym)->workout, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Work array still checked out");
3549ea844a1aSMatthew Knepley for (link = (*sym)->workin; link; link = next) {
35500c99d500SBarry Smith PetscInt **perms = (PetscInt **)link->perms;
35510c99d500SBarry Smith PetscScalar **rots = (PetscScalar **)link->rots;
35520c99d500SBarry Smith PetscCall(PetscFree2(perms, rots));
3553ea844a1aSMatthew Knepley next = link->next;
35549566063dSJacob Faibussowitsch PetscCall(PetscFree(link));
3555ea844a1aSMatthew Knepley }
3556ea844a1aSMatthew Knepley (*sym)->workin = NULL;
35579566063dSJacob Faibussowitsch PetscCall(PetscHeaderDestroy(sym));
35583ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3559ea844a1aSMatthew Knepley }
3560ea844a1aSMatthew Knepley
3561ffeef943SBarry Smith /*@
3562ea844a1aSMatthew Knepley PetscSectionSymView - Displays a section symmetry
3563ea844a1aSMatthew Knepley
356440750d41SVaclav Hapla Collective
3565ea844a1aSMatthew Knepley
3566ea844a1aSMatthew Knepley Input Parameters:
3567ea844a1aSMatthew Knepley + sym - the index set
3568cab54364SBarry Smith - viewer - viewer used to display the set, for example `PETSC_VIEWER_STDOUT_SELF`.
3569ea844a1aSMatthew Knepley
3570ea844a1aSMatthew Knepley Level: developer
3571ea844a1aSMatthew Knepley
3572cab54364SBarry Smith .seealso: `PetscSectionSym`, `PetscViewer`, `PetscViewerASCIIOpen()`
3573ea844a1aSMatthew Knepley @*/
PetscSectionSymView(PetscSectionSym sym,PetscViewer viewer)3574d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymView(PetscSectionSym sym, PetscViewer viewer)
3575d71ae5a4SJacob Faibussowitsch {
3576ea844a1aSMatthew Knepley PetscFunctionBegin;
3577ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1);
357848a46eb9SPierre Jolivet if (!viewer) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)sym), &viewer));
3579ea844a1aSMatthew Knepley PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2);
3580ea844a1aSMatthew Knepley PetscCheckSameComm(sym, 1, viewer, 2);
35819566063dSJacob Faibussowitsch PetscCall(PetscObjectPrintClassNamePrefixType((PetscObject)sym, viewer));
3582dbbe0bcdSBarry Smith PetscTryTypeMethod(sym, view, viewer);
35833ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3584ea844a1aSMatthew Knepley }
3585ea844a1aSMatthew Knepley
3586ea844a1aSMatthew Knepley /*@
3587ea844a1aSMatthew Knepley PetscSectionSetSym - Set the symmetries for the data referred to by the section
3588ea844a1aSMatthew Knepley
358940750d41SVaclav Hapla Collective
3590ea844a1aSMatthew Knepley
3591ea844a1aSMatthew Knepley Input Parameters:
3592ea844a1aSMatthew Knepley + section - the section describing data layout
3593ea844a1aSMatthew Knepley - sym - the symmetry describing the affect of orientation on the access of the data
3594ea844a1aSMatthew Knepley
3595ea844a1aSMatthew Knepley Level: developer
3596ea844a1aSMatthew Knepley
3597b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSym`, `PetscSectionGetSym()`, `PetscSectionSymCreate()`
3598ea844a1aSMatthew Knepley @*/
PetscSectionSetSym(PetscSection section,PetscSectionSym sym)3599d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetSym(PetscSection section, PetscSectionSym sym)
3600d71ae5a4SJacob Faibussowitsch {
3601ea844a1aSMatthew Knepley PetscFunctionBegin;
3602ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1);
3603f4f49eeaSPierre Jolivet PetscCall(PetscSectionSymDestroy(§ion->sym));
3604ea844a1aSMatthew Knepley if (sym) {
3605ea844a1aSMatthew Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 2);
3606ea844a1aSMatthew Knepley PetscCheckSameComm(section, 1, sym, 2);
36079566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)sym));
3608ea844a1aSMatthew Knepley }
3609ea844a1aSMatthew Knepley section->sym = sym;
36103ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3611ea844a1aSMatthew Knepley }
3612ea844a1aSMatthew Knepley
3613ea844a1aSMatthew Knepley /*@
3614ea844a1aSMatthew Knepley PetscSectionGetSym - Get the symmetries for the data referred to by the section
3615ea844a1aSMatthew Knepley
361640750d41SVaclav Hapla Not Collective
3617ea844a1aSMatthew Knepley
36182fe279fdSBarry Smith Input Parameter:
3619ea844a1aSMatthew Knepley . section - the section describing data layout
3620ea844a1aSMatthew Knepley
36212fe279fdSBarry Smith Output Parameter:
362220662ed9SBarry Smith . sym - the symmetry describing the affect of orientation on the access of the data, provided previously by `PetscSectionSetSym()`
3623ea844a1aSMatthew Knepley
3624ea844a1aSMatthew Knepley Level: developer
3625ea844a1aSMatthew Knepley
3626b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSym`, `PetscSectionSetSym()`, `PetscSectionSymCreate()`
3627ea844a1aSMatthew Knepley @*/
PetscSectionGetSym(PetscSection section,PetscSectionSym * sym)3628d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetSym(PetscSection section, PetscSectionSym *sym)
3629d71ae5a4SJacob Faibussowitsch {
3630ea844a1aSMatthew Knepley PetscFunctionBegin;
3631ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1);
3632ea844a1aSMatthew Knepley *sym = section->sym;
36333ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3634ea844a1aSMatthew Knepley }
3635ea844a1aSMatthew Knepley
3636ea844a1aSMatthew Knepley /*@
3637ea844a1aSMatthew Knepley PetscSectionSetFieldSym - Set the symmetries for the data referred to by a field of the section
3638ea844a1aSMatthew Knepley
363940750d41SVaclav Hapla Collective
3640ea844a1aSMatthew Knepley
3641ea844a1aSMatthew Knepley Input Parameters:
3642ea844a1aSMatthew Knepley + section - the section describing data layout
3643ea844a1aSMatthew Knepley . field - the field number
3644ea844a1aSMatthew Knepley - sym - the symmetry describing the affect of orientation on the access of the data
3645ea844a1aSMatthew Knepley
3646ea844a1aSMatthew Knepley Level: developer
3647ea844a1aSMatthew Knepley
3648b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSym`, `PetscSectionGetFieldSym()`, `PetscSectionSymCreate()`
3649ea844a1aSMatthew Knepley @*/
PetscSectionSetFieldSym(PetscSection section,PetscInt field,PetscSectionSym sym)3650d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetFieldSym(PetscSection section, PetscInt field, PetscSectionSym sym)
3651d71ae5a4SJacob Faibussowitsch {
3652ea844a1aSMatthew Knepley PetscFunctionBegin;
3653ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1);
36542abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, section->numFields);
36559566063dSJacob Faibussowitsch PetscCall(PetscSectionSetSym(section->field[field], sym));
36563ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3657ea844a1aSMatthew Knepley }
3658ea844a1aSMatthew Knepley
3659ea844a1aSMatthew Knepley /*@
3660ea844a1aSMatthew Knepley PetscSectionGetFieldSym - Get the symmetries for the data referred to by a field of the section
3661ea844a1aSMatthew Knepley
366240750d41SVaclav Hapla Collective
3663ea844a1aSMatthew Knepley
3664ea844a1aSMatthew Knepley Input Parameters:
3665ea844a1aSMatthew Knepley + section - the section describing data layout
3666ea844a1aSMatthew Knepley - field - the field number
3667ea844a1aSMatthew Knepley
36682fe279fdSBarry Smith Output Parameter:
3669ea844a1aSMatthew Knepley . sym - the symmetry describing the affect of orientation on the access of the data
3670ea844a1aSMatthew Knepley
3671ea844a1aSMatthew Knepley Level: developer
3672ea844a1aSMatthew Knepley
3673b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSym`, `PetscSectionSetFieldSym()`, `PetscSectionSymCreate()`
3674ea844a1aSMatthew Knepley @*/
PetscSectionGetFieldSym(PetscSection section,PetscInt field,PetscSectionSym * sym)3675d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldSym(PetscSection section, PetscInt field, PetscSectionSym *sym)
3676d71ae5a4SJacob Faibussowitsch {
3677ea844a1aSMatthew Knepley PetscFunctionBegin;
3678ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1);
36792abc8c78SJacob Faibussowitsch PetscSectionCheckValidField(field, section->numFields);
3680ea844a1aSMatthew Knepley *sym = section->field[field]->sym;
36813ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3682ea844a1aSMatthew Knepley }
3683ea844a1aSMatthew Knepley
3684ea844a1aSMatthew Knepley /*@C
3685cab54364SBarry Smith PetscSectionGetPointSyms - Get the symmetries for a set of points in a `PetscSection` under specific orientations.
3686ea844a1aSMatthew Knepley
368740750d41SVaclav Hapla Not Collective
3688ea844a1aSMatthew Knepley
3689ea844a1aSMatthew Knepley Input Parameters:
3690ea844a1aSMatthew Knepley + section - the section
3691ea844a1aSMatthew Knepley . numPoints - the number of points
369220662ed9SBarry Smith - points - an array of size 2 * `numPoints`, containing a list of (point, orientation) pairs. (An orientation is an
369320662ed9SBarry Smith arbitrary integer: its interpretation is up to sym. Orientations are used by `DM`: for their interpretation in that
369420662ed9SBarry Smith context, see `DMPlexGetConeOrientation()`).
3695ea844a1aSMatthew Knepley
3696d8d19677SJose E. Roman Output Parameters:
369720662ed9SBarry Smith + perms - The permutations for the given orientations (or `NULL` if there is no symmetry or the permutation is the identity).
369820662ed9SBarry Smith - rots - The field rotations symmetries for the given orientations (or `NULL` if there is no symmetry or the rotations are all
3699ea844a1aSMatthew Knepley identity).
3700ea844a1aSMatthew Knepley
3701ea844a1aSMatthew Knepley Example of usage, gathering dofs into a local array (lArray) from a section array (sArray):
3702ea844a1aSMatthew Knepley .vb
3703ea844a1aSMatthew Knepley const PetscInt **perms;
3704ea844a1aSMatthew Knepley const PetscScalar **rots;
3705ea844a1aSMatthew Knepley PetscInt lOffset;
3706ea844a1aSMatthew Knepley
3707ea844a1aSMatthew Knepley PetscSectionGetPointSyms(section,numPoints,points,&perms,&rots);
3708ea844a1aSMatthew Knepley for (i = 0, lOffset = 0; i < numPoints; i++) {
3709ea844a1aSMatthew Knepley PetscInt point = points[2*i], dof, sOffset;
3710ea844a1aSMatthew Knepley const PetscInt *perm = perms ? perms[i] : NULL;
3711ea844a1aSMatthew Knepley const PetscScalar *rot = rots ? rots[i] : NULL;
3712ea844a1aSMatthew Knepley
3713ea844a1aSMatthew Knepley PetscSectionGetDof(section,point,&dof);
3714ea844a1aSMatthew Knepley PetscSectionGetOffset(section,point,&sOffset);
3715ea844a1aSMatthew Knepley
3716ac530a7eSPierre Jolivet if (perm) { for (j = 0; j < dof; j++) lArray[lOffset + perm[j]] = sArray[sOffset + j]; }
3717ac530a7eSPierre Jolivet else { for (j = 0; j < dof; j++) lArray[lOffset + j ] = sArray[sOffset + j]; }
3718ac530a7eSPierre Jolivet if (rot) { for (j = 0; j < dof; j++) lArray[lOffset + j ] *= rot[j]; }
3719ea844a1aSMatthew Knepley lOffset += dof;
3720ea844a1aSMatthew Knepley }
3721ea844a1aSMatthew Knepley PetscSectionRestorePointSyms(section,numPoints,points,&perms,&rots);
3722ea844a1aSMatthew Knepley .ve
3723ea844a1aSMatthew Knepley
3724ea844a1aSMatthew Knepley Example of usage, adding dofs into a section array (sArray) from a local array (lArray):
3725ea844a1aSMatthew Knepley .vb
3726ea844a1aSMatthew Knepley const PetscInt **perms;
3727ea844a1aSMatthew Knepley const PetscScalar **rots;
3728ea844a1aSMatthew Knepley PetscInt lOffset;
3729ea844a1aSMatthew Knepley
3730ea844a1aSMatthew Knepley PetscSectionGetPointSyms(section,numPoints,points,&perms,&rots);
3731ea844a1aSMatthew Knepley for (i = 0, lOffset = 0; i < numPoints; i++) {
3732ea844a1aSMatthew Knepley PetscInt point = points[2*i], dof, sOffset;
3733ea844a1aSMatthew Knepley const PetscInt *perm = perms ? perms[i] : NULL;
3734ea844a1aSMatthew Knepley const PetscScalar *rot = rots ? rots[i] : NULL;
3735ea844a1aSMatthew Knepley
3736ea844a1aSMatthew Knepley PetscSectionGetDof(section,point,&dof);
3737ea844a1aSMatthew Knepley PetscSectionGetOffset(section,point,&sOff);
3738ea844a1aSMatthew Knepley
3739ac530a7eSPierre Jolivet if (perm) { for (j = 0; j < dof; j++) sArray[sOffset + j] += lArray[lOffset + perm[j]] * (rot ? PetscConj(rot[perm[j]]) : 1.); }
3740ac530a7eSPierre Jolivet else { for (j = 0; j < dof; j++) sArray[sOffset + j] += lArray[lOffset + j ] * (rot ? PetscConj(rot[ j ]) : 1.); }
3741ea844a1aSMatthew Knepley offset += dof;
3742ea844a1aSMatthew Knepley }
3743ea844a1aSMatthew Knepley PetscSectionRestorePointSyms(section,numPoints,points,&perms,&rots);
3744ea844a1aSMatthew Knepley .ve
3745ea844a1aSMatthew Knepley
3746ea844a1aSMatthew Knepley Level: developer
3747ea844a1aSMatthew Knepley
3748583308b6SBarry Smith Notes:
374920662ed9SBarry Smith `PetscSectionSetSym()` must have been previously called to provide the symmetries to the `PetscSection`
375020662ed9SBarry Smith
375120662ed9SBarry Smith Use `PetscSectionRestorePointSyms()` when finished with the data
375220662ed9SBarry Smith
3753b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSym`, `PetscSectionRestorePointSyms()`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()`
3754ea844a1aSMatthew Knepley @*/
PetscSectionGetPointSyms(PetscSection section,PetscInt numPoints,const PetscInt * points,const PetscInt *** perms,const PetscScalar *** rots)3755d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetPointSyms(PetscSection section, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots)
3756d71ae5a4SJacob Faibussowitsch {
3757ea844a1aSMatthew Knepley PetscSectionSym sym;
3758ea844a1aSMatthew Knepley
3759ea844a1aSMatthew Knepley PetscFunctionBegin;
3760ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1);
37614f572ea9SToby Isaac if (numPoints) PetscAssertPointer(points, 3);
3762ea844a1aSMatthew Knepley if (perms) *perms = NULL;
3763ea844a1aSMatthew Knepley if (rots) *rots = NULL;
3764ea844a1aSMatthew Knepley sym = section->sym;
3765ea844a1aSMatthew Knepley if (sym && (perms || rots)) {
3766ea844a1aSMatthew Knepley SymWorkLink link;
3767ea844a1aSMatthew Knepley
3768ea844a1aSMatthew Knepley if (sym->workin) {
3769ea844a1aSMatthew Knepley link = sym->workin;
3770ea844a1aSMatthew Knepley sym->workin = sym->workin->next;
3771ea844a1aSMatthew Knepley } else {
37724dfa11a4SJacob Faibussowitsch PetscCall(PetscNew(&link));
3773ea844a1aSMatthew Knepley }
3774ea844a1aSMatthew Knepley if (numPoints > link->numPoints) {
37750c99d500SBarry Smith PetscInt **perms = (PetscInt **)link->perms;
37760c99d500SBarry Smith PetscScalar **rots = (PetscScalar **)link->rots;
37770c99d500SBarry Smith PetscCall(PetscFree2(perms, rots));
37780c99d500SBarry Smith PetscCall(PetscMalloc2(numPoints, (PetscInt ***)&link->perms, numPoints, (PetscScalar ***)&link->rots));
3779ea844a1aSMatthew Knepley link->numPoints = numPoints;
3780ea844a1aSMatthew Knepley }
3781ea844a1aSMatthew Knepley link->next = sym->workout;
3782ea844a1aSMatthew Knepley sym->workout = link;
37839566063dSJacob Faibussowitsch PetscCall(PetscArrayzero((PetscInt **)link->perms, numPoints));
37849566063dSJacob Faibussowitsch PetscCall(PetscArrayzero((PetscInt **)link->rots, numPoints));
37859927e4dfSBarry Smith PetscUseTypeMethod(sym, getpoints, section, numPoints, points, link->perms, link->rots);
3786ea844a1aSMatthew Knepley if (perms) *perms = link->perms;
3787ea844a1aSMatthew Knepley if (rots) *rots = link->rots;
3788ea844a1aSMatthew Knepley }
37893ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3790ea844a1aSMatthew Knepley }
3791ea844a1aSMatthew Knepley
3792ea844a1aSMatthew Knepley /*@C
3793cab54364SBarry Smith PetscSectionRestorePointSyms - Restore the symmetries returned by `PetscSectionGetPointSyms()`
3794ea844a1aSMatthew Knepley
379540750d41SVaclav Hapla Not Collective
3796ea844a1aSMatthew Knepley
3797ea844a1aSMatthew Knepley Input Parameters:
3798ea844a1aSMatthew Knepley + section - the section
3799ea844a1aSMatthew Knepley . numPoints - the number of points
380038b5cf2dSJacob Faibussowitsch . points - an array of size 2 * `numPoints`, containing a list of (point, orientation) pairs. (An orientation is an
3801cab54364SBarry Smith arbitrary integer: its interpretation is up to sym. Orientations are used by `DM`: for their interpretation in that
3802cab54364SBarry Smith context, see `DMPlexGetConeOrientation()`).
380320662ed9SBarry Smith . perms - The permutations for the given orientations: set to `NULL` at conclusion
380420662ed9SBarry Smith - rots - The field rotations symmetries for the given orientations: set to `NULL` at conclusion
3805ea844a1aSMatthew Knepley
3806ea844a1aSMatthew Knepley Level: developer
3807ea844a1aSMatthew Knepley
3808b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSym`, `PetscSectionGetPointSyms()`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()`
3809ea844a1aSMatthew Knepley @*/
PetscSectionRestorePointSyms(PetscSection section,PetscInt numPoints,const PetscInt * points,const PetscInt *** perms,const PetscScalar *** rots)3810d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionRestorePointSyms(PetscSection section, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots)
3811d71ae5a4SJacob Faibussowitsch {
3812ea844a1aSMatthew Knepley PetscSectionSym sym;
3813ea844a1aSMatthew Knepley
3814ea844a1aSMatthew Knepley PetscFunctionBegin;
3815ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1);
3816ea844a1aSMatthew Knepley sym = section->sym;
3817ea844a1aSMatthew Knepley if (sym && (perms || rots)) {
3818ea844a1aSMatthew Knepley SymWorkLink *p, link;
3819ea844a1aSMatthew Knepley
3820ea844a1aSMatthew Knepley for (p = &sym->workout; (link = *p); p = &link->next) {
3821ea844a1aSMatthew Knepley if ((perms && link->perms == *perms) || (rots && link->rots == *rots)) {
3822ea844a1aSMatthew Knepley *p = link->next;
3823ea844a1aSMatthew Knepley link->next = sym->workin;
3824ea844a1aSMatthew Knepley sym->workin = link;
3825ea844a1aSMatthew Knepley if (perms) *perms = NULL;
3826ea844a1aSMatthew Knepley if (rots) *rots = NULL;
38273ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3828ea844a1aSMatthew Knepley }
3829ea844a1aSMatthew Knepley }
3830ea844a1aSMatthew Knepley SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Array was not checked out");
3831ea844a1aSMatthew Knepley }
38323ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3833ea844a1aSMatthew Knepley }
3834ea844a1aSMatthew Knepley
3835ea844a1aSMatthew Knepley /*@C
3836cab54364SBarry Smith PetscSectionGetFieldPointSyms - Get the symmetries for a set of points in a field of a `PetscSection` under specific orientations.
3837ea844a1aSMatthew Knepley
383840750d41SVaclav Hapla Not Collective
3839ea844a1aSMatthew Knepley
3840ea844a1aSMatthew Knepley Input Parameters:
3841ea844a1aSMatthew Knepley + section - the section
3842ea844a1aSMatthew Knepley . field - the field of the section
3843ea844a1aSMatthew Knepley . numPoints - the number of points
384420662ed9SBarry Smith - points - an array of size 2 * `numPoints`, containing a list of (point, orientation) pairs. (An orientation is an
3845cab54364SBarry Smith arbitrary integer: its interpretation is up to sym. Orientations are used by `DM`: for their interpretation in that
3846cab54364SBarry Smith context, see `DMPlexGetConeOrientation()`).
3847ea844a1aSMatthew Knepley
3848d8d19677SJose E. Roman Output Parameters:
384920662ed9SBarry Smith + perms - The permutations for the given orientations (or `NULL` if there is no symmetry or the permutation is the identity).
385020662ed9SBarry Smith - rots - The field rotations symmetries for the given orientations (or `NULL` if there is no symmetry or the rotations are all
3851ea844a1aSMatthew Knepley identity).
3852ea844a1aSMatthew Knepley
3853ea844a1aSMatthew Knepley Level: developer
3854ea844a1aSMatthew Knepley
385520662ed9SBarry Smith Notes:
385620662ed9SBarry Smith `PetscSectionSetFieldSym()` must have been previously called to provide the symmetries to the `PetscSection`
385720662ed9SBarry Smith
385820662ed9SBarry Smith Use `PetscSectionRestoreFieldPointSyms()` when finished with the data
385920662ed9SBarry Smith
3860b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSym`, `PetscSectionGetPointSyms()`, `PetscSectionRestoreFieldPointSyms()`
3861ea844a1aSMatthew Knepley @*/
PetscSectionGetFieldPointSyms(PetscSection section,PetscInt field,PetscInt numPoints,const PetscInt * points,const PetscInt *** perms,const PetscScalar *** rots)3862d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetFieldPointSyms(PetscSection section, PetscInt field, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots)
3863d71ae5a4SJacob Faibussowitsch {
3864ea844a1aSMatthew Knepley PetscFunctionBegin;
3865ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1);
386608401ef6SPierre Jolivet PetscCheck(field <= section->numFields, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "field %" PetscInt_FMT " greater than number of fields (%" PetscInt_FMT ") in section", field, section->numFields);
38679566063dSJacob Faibussowitsch PetscCall(PetscSectionGetPointSyms(section->field[field], numPoints, points, perms, rots));
38683ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3869ea844a1aSMatthew Knepley }
3870ea844a1aSMatthew Knepley
3871ea844a1aSMatthew Knepley /*@C
3872cab54364SBarry Smith PetscSectionRestoreFieldPointSyms - Restore the symmetries returned by `PetscSectionGetFieldPointSyms()`
3873ea844a1aSMatthew Knepley
387440750d41SVaclav Hapla Not Collective
3875ea844a1aSMatthew Knepley
3876ea844a1aSMatthew Knepley Input Parameters:
3877ea844a1aSMatthew Knepley + section - the section
3878ea844a1aSMatthew Knepley . field - the field number
3879ea844a1aSMatthew Knepley . numPoints - the number of points
388038b5cf2dSJacob Faibussowitsch . points - an array of size 2 * `numPoints`, containing a list of (point, orientation) pairs. (An orientation is an
3881cab54364SBarry Smith arbitrary integer: its interpretation is up to sym. Orientations are used by `DM`: for their interpretation in that
3882cab54364SBarry Smith context, see `DMPlexGetConeOrientation()`).
388320662ed9SBarry Smith . perms - The permutations for the given orientations: set to NULL at conclusion
3884ea844a1aSMatthew Knepley - rots - The field rotations symmetries for the given orientations: set to NULL at conclusion
3885ea844a1aSMatthew Knepley
3886ea844a1aSMatthew Knepley Level: developer
3887ea844a1aSMatthew Knepley
3888b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSym`, `PetscSectionRestorePointSyms()`, `petscSectionGetFieldPointSyms()`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()`
3889ea844a1aSMatthew Knepley @*/
PetscSectionRestoreFieldPointSyms(PetscSection section,PetscInt field,PetscInt numPoints,const PetscInt * points,const PetscInt *** perms,const PetscScalar *** rots)3890d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionRestoreFieldPointSyms(PetscSection section, PetscInt field, PetscInt numPoints, const PetscInt *points, const PetscInt ***perms, const PetscScalar ***rots)
3891d71ae5a4SJacob Faibussowitsch {
3892ea844a1aSMatthew Knepley PetscFunctionBegin;
3893ea844a1aSMatthew Knepley PetscValidHeaderSpecific(section, PETSC_SECTION_CLASSID, 1);
389408401ef6SPierre Jolivet PetscCheck(field <= section->numFields, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "field %" PetscInt_FMT " greater than number of fields (%" PetscInt_FMT ") in section", field, section->numFields);
38959566063dSJacob Faibussowitsch PetscCall(PetscSectionRestorePointSyms(section->field[field], numPoints, points, perms, rots));
38963ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3897ea844a1aSMatthew Knepley }
3898ea844a1aSMatthew Knepley
3899ea844a1aSMatthew Knepley /*@
3900b004864fSMatthew G. Knepley PetscSectionSymCopy - Copy the symmetries, assuming that the point structure is compatible
3901b004864fSMatthew G. Knepley
390240750d41SVaclav Hapla Not Collective
3903b004864fSMatthew G. Knepley
3904b004864fSMatthew G. Knepley Input Parameter:
3905cab54364SBarry Smith . sym - the `PetscSectionSym`
3906b004864fSMatthew G. Knepley
3907b004864fSMatthew G. Knepley Output Parameter:
3908b004864fSMatthew G. Knepley . nsym - the equivalent symmetries
3909b004864fSMatthew G. Knepley
3910b004864fSMatthew G. Knepley Level: developer
3911b004864fSMatthew G. Knepley
3912b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSym`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()`, `PetscSectionSymLabelSetStratum()`, `PetscSectionGetPointSyms()`
3913b004864fSMatthew G. Knepley @*/
PetscSectionSymCopy(PetscSectionSym sym,PetscSectionSym nsym)3914d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymCopy(PetscSectionSym sym, PetscSectionSym nsym)
3915d71ae5a4SJacob Faibussowitsch {
3916b004864fSMatthew G. Knepley PetscFunctionBegin;
3917b004864fSMatthew G. Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1);
3918b004864fSMatthew G. Knepley PetscValidHeaderSpecific(nsym, PETSC_SECTION_SYM_CLASSID, 2);
3919dbbe0bcdSBarry Smith PetscTryTypeMethod(sym, copy, nsym);
39203ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3921b004864fSMatthew G. Knepley }
3922b004864fSMatthew G. Knepley
3923b004864fSMatthew G. Knepley /*@
3924cab54364SBarry Smith PetscSectionSymDistribute - Distribute the symmetries in accordance with the input `PetscSF`
3925b004864fSMatthew G. Knepley
3926b004864fSMatthew G. Knepley Collective
3927b004864fSMatthew G. Knepley
3928b004864fSMatthew G. Knepley Input Parameters:
3929cab54364SBarry Smith + sym - the `PetscSectionSym`
3930b004864fSMatthew G. Knepley - migrationSF - the distribution map from roots to leaves
3931b004864fSMatthew G. Knepley
39322fe279fdSBarry Smith Output Parameter:
3933b004864fSMatthew G. Knepley . dsym - the redistributed symmetries
3934b004864fSMatthew G. Knepley
3935b004864fSMatthew G. Knepley Level: developer
3936b004864fSMatthew G. Knepley
3937b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSym`, `PetscSectionSymCreate()`, `PetscSectionSetSym()`, `PetscSectionGetSym()`, `PetscSectionSymLabelSetStratum()`, `PetscSectionGetPointSyms()`
3938b004864fSMatthew G. Knepley @*/
PetscSectionSymDistribute(PetscSectionSym sym,PetscSF migrationSF,PetscSectionSym * dsym)3939d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSymDistribute(PetscSectionSym sym, PetscSF migrationSF, PetscSectionSym *dsym)
3940d71ae5a4SJacob Faibussowitsch {
3941b004864fSMatthew G. Knepley PetscFunctionBegin;
3942b004864fSMatthew G. Knepley PetscValidHeaderSpecific(sym, PETSC_SECTION_SYM_CLASSID, 1);
3943b004864fSMatthew G. Knepley PetscValidHeaderSpecific(migrationSF, PETSCSF_CLASSID, 2);
39444f572ea9SToby Isaac PetscAssertPointer(dsym, 3);
3945dbbe0bcdSBarry Smith PetscTryTypeMethod(sym, distribute, migrationSF, dsym);
39463ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3947b004864fSMatthew G. Knepley }
3948b004864fSMatthew G. Knepley
3949b004864fSMatthew G. Knepley /*@
395020662ed9SBarry Smith PetscSectionGetUseFieldOffsets - Get the flag indicating if field offsets are used directly in a global section, rather than just the point offset
3951ea844a1aSMatthew Knepley
395240750d41SVaclav Hapla Not Collective
3953ea844a1aSMatthew Knepley
3954ea844a1aSMatthew Knepley Input Parameter:
3955cab54364SBarry Smith . s - the global `PetscSection`
3956ea844a1aSMatthew Knepley
39572fe279fdSBarry Smith Output Parameter:
3958ea844a1aSMatthew Knepley . flg - the flag
3959ea844a1aSMatthew Knepley
3960ea844a1aSMatthew Knepley Level: developer
3961ea844a1aSMatthew Knepley
3962b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSym`, `PetscSectionSetChart()`, `PetscSectionCreate()`
3963ea844a1aSMatthew Knepley @*/
PetscSectionGetUseFieldOffsets(PetscSection s,PetscBool * flg)3964d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionGetUseFieldOffsets(PetscSection s, PetscBool *flg)
3965d71ae5a4SJacob Faibussowitsch {
3966ea844a1aSMatthew Knepley PetscFunctionBegin;
3967ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
3968ea844a1aSMatthew Knepley *flg = s->useFieldOff;
39693ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3970ea844a1aSMatthew Knepley }
3971ea844a1aSMatthew Knepley
3972ea844a1aSMatthew Knepley /*@
3973ea844a1aSMatthew Knepley PetscSectionSetUseFieldOffsets - Set the flag to use field offsets directly in a global section, rather than just the point offset
3974ea844a1aSMatthew Knepley
397540750d41SVaclav Hapla Not Collective
3976ea844a1aSMatthew Knepley
3977ea844a1aSMatthew Knepley Input Parameters:
3978cab54364SBarry Smith + s - the global `PetscSection`
3979ea844a1aSMatthew Knepley - flg - the flag
3980ea844a1aSMatthew Knepley
3981ea844a1aSMatthew Knepley Level: developer
3982ea844a1aSMatthew Knepley
3983b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSym`, `PetscSectionGetUseFieldOffsets()`, `PetscSectionSetChart()`, `PetscSectionCreate()`
3984ea844a1aSMatthew Knepley @*/
PetscSectionSetUseFieldOffsets(PetscSection s,PetscBool flg)3985d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionSetUseFieldOffsets(PetscSection s, PetscBool flg)
3986d71ae5a4SJacob Faibussowitsch {
3987ea844a1aSMatthew Knepley PetscFunctionBegin;
3988ea844a1aSMatthew Knepley PetscValidHeaderSpecific(s, PETSC_SECTION_CLASSID, 1);
3989ea844a1aSMatthew Knepley s->useFieldOff = flg;
39903ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
3991ea844a1aSMatthew Knepley }
3992ea844a1aSMatthew Knepley
3993ea844a1aSMatthew Knepley #define PetscSectionExpandPoints_Loop(TYPE) \
3994a8f51744SPierre Jolivet do { \
3995ea844a1aSMatthew Knepley PetscInt i, n, o0, o1, size; \
3996ea844a1aSMatthew Knepley TYPE *a0 = (TYPE *)origArray, *a1; \
39979566063dSJacob Faibussowitsch PetscCall(PetscSectionGetStorageSize(s, &size)); \
39989566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(size, &a1)); \
3999ea844a1aSMatthew Knepley for (i = 0; i < npoints; i++) { \
40009566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(origSection, points_[i], &o0)); \
40019566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(s, i, &o1)); \
40029566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(s, i, &n)); \
40039566063dSJacob Faibussowitsch PetscCall(PetscMemcpy(&a1[o1], &a0[o0], n * unitsize)); \
4004ea844a1aSMatthew Knepley } \
4005ea844a1aSMatthew Knepley *newArray = (void *)a1; \
4006a8f51744SPierre Jolivet } while (0)
4007ea844a1aSMatthew Knepley
4008ea844a1aSMatthew Knepley /*@
4009ea844a1aSMatthew Knepley PetscSectionExtractDofsFromArray - Extracts elements of an array corresponding to DOFs of specified points.
4010ea844a1aSMatthew Knepley
401140750d41SVaclav Hapla Not Collective
4012ea844a1aSMatthew Knepley
4013ea844a1aSMatthew Knepley Input Parameters:
4014cab54364SBarry Smith + origSection - the `PetscSection` describing the layout of the array
4015cab54364SBarry Smith . dataType - `MPI_Datatype` describing the data type of the array (currently only `MPIU_INT`, `MPIU_SCALAR`, `MPIU_REAL`)
401620662ed9SBarry Smith . origArray - the array; its size must be equal to the storage size of `origSection`
401720662ed9SBarry Smith - points - `IS` with points to extract; its indices must lie in the chart of `origSection`
4018ea844a1aSMatthew Knepley
4019ea844a1aSMatthew Knepley Output Parameters:
4020da81f932SPierre Jolivet + newSection - the new `PetscSection` describing the layout of the new array (with points renumbered 0,1,... but preserving numbers of DOFs)
402120662ed9SBarry Smith - newArray - the array of the extracted DOFs; its size is the storage size of `newSection`
4022ea844a1aSMatthew Knepley
4023ea844a1aSMatthew Knepley Level: developer
4024ea844a1aSMatthew Knepley
4025b0c76368SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSectionSym`, `PetscSectionGetChart()`, `PetscSectionGetDof()`, `PetscSectionGetStorageSize()`, `PetscSectionCreate()`
4026ea844a1aSMatthew Knepley @*/
PetscSectionExtractDofsFromArray(PetscSection origSection,MPI_Datatype dataType,const void * origArray,IS points,PetscSection * newSection,void * newArray[])4027d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSectionExtractDofsFromArray(PetscSection origSection, MPI_Datatype dataType, const void *origArray, IS points, PetscSection *newSection, void *newArray[])
4028d71ae5a4SJacob Faibussowitsch {
4029ea844a1aSMatthew Knepley PetscSection s;
4030ea844a1aSMatthew Knepley const PetscInt *points_;
4031ea844a1aSMatthew Knepley PetscInt i, n, npoints, pStart, pEnd;
4032ea844a1aSMatthew Knepley PetscMPIInt unitsize;
4033ea844a1aSMatthew Knepley
4034ea844a1aSMatthew Knepley PetscFunctionBegin;
4035ea844a1aSMatthew Knepley PetscValidHeaderSpecific(origSection, PETSC_SECTION_CLASSID, 1);
40364f572ea9SToby Isaac PetscAssertPointer(origArray, 3);
4037ea844a1aSMatthew Knepley PetscValidHeaderSpecific(points, IS_CLASSID, 4);
40384f572ea9SToby Isaac if (newSection) PetscAssertPointer(newSection, 5);
40394f572ea9SToby Isaac if (newArray) PetscAssertPointer(newArray, 6);
40409566063dSJacob Faibussowitsch PetscCallMPI(MPI_Type_size(dataType, &unitsize));
40419566063dSJacob Faibussowitsch PetscCall(ISGetLocalSize(points, &npoints));
40429566063dSJacob Faibussowitsch PetscCall(ISGetIndices(points, &points_));
40439566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(origSection, &pStart, &pEnd));
40449566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PETSC_COMM_SELF, &s));
40459566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(s, 0, npoints));
4046ea844a1aSMatthew Knepley for (i = 0; i < npoints; i++) {
4047c9cc58a2SBarry Smith PetscCheck(points_[i] >= pStart && points_[i] < pEnd, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "point %" PetscInt_FMT " (index %" PetscInt_FMT ") in input IS out of input section's chart", points_[i], i);
40489566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(origSection, points_[i], &n));
40499566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(s, i, n));
4050ea844a1aSMatthew Knepley }
40519566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(s));
4052ea844a1aSMatthew Knepley if (newArray) {
40539371c9d4SSatish Balay if (dataType == MPIU_INT) {
40549371c9d4SSatish Balay PetscSectionExpandPoints_Loop(PetscInt);
40559371c9d4SSatish Balay } else if (dataType == MPIU_SCALAR) {
40569371c9d4SSatish Balay PetscSectionExpandPoints_Loop(PetscScalar);
40579371c9d4SSatish Balay } else if (dataType == MPIU_REAL) {
40589371c9d4SSatish Balay PetscSectionExpandPoints_Loop(PetscReal);
40599371c9d4SSatish Balay } else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "not implemented for this MPI_Datatype");
4060ea844a1aSMatthew Knepley }
4061ea844a1aSMatthew Knepley if (newSection) {
4062ea844a1aSMatthew Knepley *newSection = s;
4063ea844a1aSMatthew Knepley } else {
40649566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&s));
4065ea844a1aSMatthew Knepley }
40669566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(points, &points_));
40673ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
4068ea844a1aSMatthew Knepley }
40696964b6c7SJames Wright
40706964b6c7SJames Wright /*@
40716964b6c7SJames Wright PetscSectionMigrateData - Migrate data described by a `PetscSection` using a `PetscSF` that defines a original-to-new (root-to-leaf) point mapping
40726964b6c7SJames Wright
40736964b6c7SJames Wright Collective
40746964b6c7SJames Wright
40756964b6c7SJames Wright Input Parameters:
40766964b6c7SJames Wright + migratePointSF - defines the mapping (communication) of the root points to the leaf points
40776964b6c7SJames Wright . datatype - the type of data
40786964b6c7SJames Wright . rootSection - the `PetscSection` that describes the data layout on the root points (how many dof and what fields are associated with each root point)
40796964b6c7SJames Wright - rootData - the existing data array described by `rootSection`, may be `NULL` is storage size of `rootSection` is zero
40806964b6c7SJames Wright
40816964b6c7SJames Wright Output Parameters:
40826964b6c7SJames Wright + leafSection - the new `PetscSection` that describes the data layout on the leaf points
40836964b6c7SJames Wright . leafData - the redistributed data array that is associated with the leaf points
40846964b6c7SJames Wright - migrateDataSF - defines the mapping (communication) of the `rootData` array to the `leafData` array, may be `NULL` if not needed
40856964b6c7SJames Wright
40866964b6c7SJames Wright Level: advanced
40876964b6c7SJames Wright
40886964b6c7SJames Wright Notes:
40896964b6c7SJames Wright This function can best be thought of as applying `PetscSFBcastBegin()` to an array described by a `PetscSection`.
40906964b6c7SJames Wright While `PetscSFBcastBegin()` is limited to broadcasting data that is of the same size for every index, this function allows the data to be a different size for each index.
40916964b6c7SJames Wright The size and layout of that irregularly sized data before and after `PetscSFBcastBegin()` is described by the `rootSection` and `leafSection`, respectively.
40926964b6c7SJames Wright
40936964b6c7SJames Wright This function combines `PetscSFDistributeSection()`, `PetscSFCreateSectionSF()`, and `PetscSFBcastBegin()`/`PetscSFBcastEnd()` into a single call.
40946964b6c7SJames Wright `migrateDataSF` can be used to repeat the `PetscSFBcastBegin()`/`PetscSFBcastEnd()` on a different data array described by the same `rootSection`.
40956964b6c7SJames Wright
40966964b6c7SJames Wright This should not be used for global-to-local type communciation patterns.
40976964b6c7SJames Wright For this use case, see `PetscSectionCreateGlobalSection()` and `PetscSFSetGraphSection()`.
40986964b6c7SJames Wright
40996964b6c7SJames Wright .seealso: [PetscSection](ch_petscsection), `PetscSection`, `PetscSFDistributeSection()`, `PetscSFCreateSectionSF()`, `DMPlexDistributeData()`
41006964b6c7SJames Wright @*/
PetscSectionMigrateData(PetscSF migratePointSF,MPI_Datatype datatype,PetscSection rootSection,const void * rootData,PetscSection leafSection,void * leafData[],PetscSF * migrateDataSF)41016964b6c7SJames Wright PetscErrorCode PetscSectionMigrateData(PetscSF migratePointSF, MPI_Datatype datatype, PetscSection rootSection, const void *rootData, PetscSection leafSection, void *leafData[], PetscSF *migrateDataSF)
41026964b6c7SJames Wright {
41036964b6c7SJames Wright PetscSF fieldSF;
41046964b6c7SJames Wright PetscInt *remoteOffsets, fieldSize;
41056964b6c7SJames Wright PetscMPIInt dataSize;
41066964b6c7SJames Wright
41076964b6c7SJames Wright PetscFunctionBegin;
41086964b6c7SJames Wright PetscValidHeaderSpecific(migratePointSF, PETSCSF_CLASSID, 1);
41096964b6c7SJames Wright PetscValidHeaderSpecific(rootSection, PETSC_SECTION_CLASSID, 3);
41106964b6c7SJames Wright if (rootData) PetscAssertPointer(rootData, 4);
41116964b6c7SJames Wright else {
41126964b6c7SJames Wright PetscInt size;
41136964b6c7SJames Wright PetscCall(PetscSectionGetStorageSize(rootSection, &size));
41146964b6c7SJames Wright PetscCheck(size == 0, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "originalData may be NULL iff the storage size of originalSection is zero, but is %" PetscInt_FMT, size);
41156964b6c7SJames Wright }
41166964b6c7SJames Wright PetscValidHeaderSpecific(leafSection, PETSC_SECTION_CLASSID, 5);
41176964b6c7SJames Wright PetscAssertPointer(leafData, 6);
41186964b6c7SJames Wright if (migrateDataSF) PetscAssertPointer(migrateDataSF, 7);
41196964b6c7SJames Wright
41206964b6c7SJames Wright PetscCall(PetscSFDistributeSection(migratePointSF, rootSection, &remoteOffsets, leafSection));
41216964b6c7SJames Wright PetscCall(PetscSFCreateSectionSF(migratePointSF, rootSection, remoteOffsets, leafSection, &fieldSF));
41226964b6c7SJames Wright PetscCall(PetscFree(remoteOffsets));
41236964b6c7SJames Wright
41246964b6c7SJames Wright PetscCall(PetscSectionGetStorageSize(leafSection, &fieldSize));
41256964b6c7SJames Wright PetscCallMPI(MPI_Type_size(datatype, &dataSize));
41266964b6c7SJames Wright PetscCall(PetscMalloc(fieldSize * dataSize, leafData));
41276964b6c7SJames Wright PetscCall(PetscSFBcastBegin(fieldSF, datatype, rootData, *leafData, MPI_REPLACE));
41286964b6c7SJames Wright PetscCall(PetscSFBcastEnd(fieldSF, datatype, rootData, *leafData, MPI_REPLACE));
41296964b6c7SJames Wright
41306964b6c7SJames Wright if (migrateDataSF) *migrateDataSF = fieldSF;
41316964b6c7SJames Wright else PetscCall(PetscSFDestroy(&fieldSF));
41326964b6c7SJames Wright PetscFunctionReturn(PETSC_SUCCESS);
41336964b6c7SJames Wright }
4134