Actual source code: section.c
1: #include "private/meshimpl.h" /*I "petscmesh.h" I*/
2: #include <petscmesh_viewers.hh>
4: /* Logging support */
5: PetscCookie SECTIONREAL_COOKIE;
6: PetscLogEvent SectionReal_View;
7: PetscCookie SECTIONINT_COOKIE;
8: PetscLogEvent SectionInt_View;
9: PetscCookie SECTIONPAIR_COOKIE;
10: PetscLogEvent SectionPair_View;
14: PetscErrorCode SectionRealView_Sieve(SectionReal section, PetscViewer viewer)
15: {
16: PetscTruth iascii, isbinary, isdraw;
20: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_ASCII, &iascii);
21: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &isbinary);
22: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_DRAW, &isdraw);
24: if (iascii){
25: ALE::Obj<PETSC_MESH_TYPE::real_section_type> s;
26: ALE::Obj<PETSC_MESH_TYPE> b;
27: const char *name;
29: SectionRealGetSection(section, s);
30: SectionRealGetBundle(section, b);
31: PetscObjectGetName((PetscObject) section, &name);
32: SectionView_Sieve_Ascii(b, s, name, viewer);
33: } else if (isbinary) {
34: SETERRQ(PETSC_ERR_SUP, "Binary viewer not implemented for Section");
35: } else if (isdraw){
36: SETERRQ(PETSC_ERR_SUP, "Draw viewer not implemented for Section");
37: } else {
38: SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported by this section object", ((PetscObject)viewer)->type_name);
39: }
40: return(0);
41: }
45: /*@C
46: SectionRealView - Views a Section object.
48: Collective on Section
50: Input Parameters:
51: + section - the Section
52: - viewer - an optional visualization context
54: Notes:
55: The available visualization contexts include
56: + PETSC_VIEWER_STDOUT_SELF - standard output (default)
57: - PETSC_VIEWER_STDOUT_WORLD - synchronized standard
58: output where only the first processor opens
59: the file. All other processors send their
60: data to the first processor to print.
62: You can change the format the section is printed using the
63: option PetscViewerSetFormat().
65: The user can open alternative visualization contexts with
66: + PetscViewerASCIIOpen() - Outputs section to a specified file
67: . PetscViewerBinaryOpen() - Outputs section in binary to a
68: specified file; corresponding input uses SectionLoad()
69: . PetscViewerDrawOpen() - Outputs section to an X window display
71: The user can call PetscViewerSetFormat() to specify the output
72: format of ASCII printed objects (when using PETSC_VIEWER_STDOUT_SELF,
73: PETSC_VIEWER_STDOUT_WORLD and PetscViewerASCIIOpen). Available formats include
74: + PETSC_VIEWER_DEFAULT - default, prints section information
75: - PETSC_VIEWER_ASCII_VTK - outputs a VTK file describing the section
77: Level: beginner
79: Concepts: section^printing
80: Concepts: section^saving to disk
82: .seealso: VecView(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerBinaryOpen(), PetscViewerCreate()
83: @*/
84: PetscErrorCode SectionRealView(SectionReal section, PetscViewer viewer)
85: {
91: if (!viewer) {
92: PetscViewerASCIIGetStdout(((PetscObject)section)->comm,&viewer);
93: }
97: PetscLogEventBegin(SectionReal_View,0,0,0,0);
98: (*section->ops->view)(section, viewer);
99: PetscLogEventEnd(SectionReal_View,0,0,0,0);
100: return(0);
101: }
105: /*@C
106: SectionRealDuplicate - Create an equivalent Section object
108: Not collective
110: Input Parameter:
111: . section - the section object
113: Output Parameter:
114: . newSection - the duplicate
115:
116: Level: advanced
118: .seealso SectionRealCreate(), SectionRealSetSection()
119: @*/
120: PetscErrorCode SectionRealDuplicate(SectionReal section, SectionReal *newSection)
121: {
127: const ALE::Obj<PETSC_MESH_TYPE::real_section_type>& s = section->s;
128: ALE::Obj<PETSC_MESH_TYPE::real_section_type> t = new PETSC_MESH_TYPE::real_section_type(s->comm(), s->debug());
130: t->setAtlas(s->getAtlas());
131: t->allocateStorage();
132: t->copyBC(s);
133: SectionRealCreate(s->comm(), newSection);
134: SectionRealSetSection(*newSection, t);
135: SectionRealSetBundle(*newSection, section->b);
136: return(0);
137: }
141: /*@C
142: SectionRealGetSection - Gets the internal section object
144: Not collective
146: Input Parameter:
147: . section - the section object
149: Output Parameter:
150: . s - the internal section object
151:
152: Level: advanced
154: .seealso SectionRealCreate(), SectionRealSetSection()
155: @*/
156: PetscErrorCode SectionRealGetSection(SectionReal section, ALE::Obj<PETSC_MESH_TYPE::real_section_type>& s)
157: {
160: s = section->s;
161: return(0);
162: }
166: /*@C
167: SectionRealSetSection - Sets the internal section object
169: Not collective
171: Input Parameters:
172: + section - the section object
173: - s - the internal section object
174:
175: Level: advanced
177: .seealso SectionRealCreate(), SectionRealGetSection()
178: @*/
179: PetscErrorCode SectionRealSetSection(SectionReal section, const ALE::Obj<PETSC_MESH_TYPE::real_section_type>& s)
180: {
185: if (!s.isNull()) {PetscObjectSetName((PetscObject) section, s->getName().c_str());}
186: section->s = s;
187: return(0);
188: }
192: /*@C
193: SectionRealGetBundle - Gets the section bundle
195: Not collective
197: Input Parameter:
198: . section - the section object
200: Output Parameter:
201: . b - the section bundle
202:
203: Level: advanced
205: .seealso SectionRealCreate(), SectionRealGetSection(), SectionRealSetSection()
206: @*/
207: PetscErrorCode SectionRealGetBundle(SectionReal section, ALE::Obj<PETSC_MESH_TYPE>& b)
208: {
211: b = section->b;
212: return(0);
213: }
217: /*@C
218: SectionRealSetBundle - Sets the section bundle
220: Not collective
222: Input Parameters:
223: + section - the section object
224: - b - the section bundle
225:
226: Level: advanced
228: .seealso SectionRealCreate(), SectionRealGetSection(), SectionRealSetSection()
229: @*/
230: PetscErrorCode SectionRealSetBundle(SectionReal section, const ALE::Obj<PETSC_MESH_TYPE>& b)
231: {
234: section->b = b;
235: return(0);
236: }
240: /*@C
241: SectionRealCreate - Creates a Section object, used to manage data for an unstructured problem
242: described by a Sieve.
244: Collective on MPI_Comm
246: Input Parameter:
247: . comm - the processors that will share the global section
249: Output Parameters:
250: . section - the section object
252: Level: advanced
254: .seealso SectionRealDestroy(), SectionRealView()
255: @*/
256: PetscErrorCode SectionRealCreate(MPI_Comm comm, SectionReal *section)
257: {
259: SectionReal s;
263: *section = PETSC_NULL;
265: PetscHeaderCreate(s,_p_SectionReal,struct _SectionRealOps,SECTIONREAL_COOKIE,0,"SectionReal",comm,SectionRealDestroy,0);
266: s->ops->view = SectionRealView_Sieve;
267: s->ops->restrictClosure = SectionRealRestrict;
268: s->ops->update = SectionRealUpdate;
270: PetscObjectChangeTypeName((PetscObject) s, "sieve");
272: new(&s->s) ALE::Obj<PETSC_MESH_TYPE::real_section_type>(PETSC_MESH_TYPE::real_section_type(comm));
273: new(&s->b) ALE::Obj<PETSC_MESH_TYPE>(PETSC_NULL);
274: *section = s;
275: return(0);
276: }
280: /*@
281: SectionRealDestroy - Destroys a section.
283: Collective on Section
285: Input Parameter:
286: . section - the section object
288: Level: advanced
290: .seealso SectionRealCreate(), SectionRealView()
291: @*/
292: PetscErrorCode SectionRealDestroy(SectionReal section)
293: {
298: if (--((PetscObject)section)->refct > 0) return(0);
299: section->s = PETSC_NULL;
300: PetscHeaderDestroy(section);
301: return(0);
302: }
306: /*@C
307: SectionRealDistribute - Distributes the sections.
309: Not Collective
311: Input Parameters:
312: + serialSection - The original Section object
313: - parallelMesh - The parallel Mesh
315: Output Parameter:
316: . parallelSection - The distributed Section object
318: Level: intermediate
320: .keywords: mesh, section, distribute
321: .seealso: MeshCreate()
322: @*/
323: PetscErrorCode SectionRealDistribute(SectionReal serialSection, Mesh parallelMesh, SectionReal *parallelSection)
324: {
325: ALE::Obj<PETSC_MESH_TYPE::real_section_type> oldSection;
326: ALE::Obj<PETSC_MESH_TYPE> m;
330: SectionRealGetSection(serialSection, oldSection);
331: MeshGetMesh(parallelMesh, m);
332: SectionRealCreate(oldSection->comm(), parallelSection);
333: #ifdef PETSC_OPT_SIEVE
334: ALE::Obj<PETSC_MESH_TYPE::real_section_type> newSection;
336: // We assume all integer sections are complete sections
337: newSection->setName(oldSection->getName());
338: newSection->setChart(m->getSieve()->getChart());
339: //distributeSection(oldSection, partition, m->getRenumbering(), m->getDistSendOverlap(), m->getDistRecvOverlap(), newSection);
340: SectionRealSetSection(*parallelSection, newSection);
341: SETERRQ(PETSC_ERR_SUP, "Not working because the partition is unavailable");
342: #else
343: ALE::Obj<PETSC_MESH_TYPE::real_section_type> newSection = ALE::Distribution<PETSC_MESH_TYPE>::distributeSection(oldSection, m, m->getDistSendOverlap(), m->getDistRecvOverlap());
344: SectionRealSetSection(*parallelSection, newSection);
345: #endif
346: return(0);
347: }
351: /*@C
352: SectionRealRestrict - Restricts the SectionReal to a subset of the topology, returning an array of values.
354: Not collective
356: Input Parameters:
357: + section - the section object
358: - point - the Sieve point
360: Output Parameter:
361: . values - The values associated with the submesh
363: Level: advanced
365: .seealso SectionUpdate(), SectionCreate(), SectionView()
366: @*/
367: PetscErrorCode SectionRealRestrict(SectionReal section, PetscInt point, PetscScalar *values[])
368: {
372: *values = (PetscScalar *) section->s->restrictPoint(point);
373: return(0);
374: }
378: /*@C
379: SectionRealUpdate - Updates the array of values associated to a subset of the topology in this Section.
381: Not collective
383: Input Parameters:
384: + section - the section object
385: . point - the Sieve point
386: . values - The values associated with the submesh
387: - mode - The insertion mode
389: Level: advanced
391: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
392: @*/
393: PetscErrorCode SectionRealUpdate(SectionReal section, PetscInt point, const PetscScalar values[], InsertMode mode)
394: {
398: #ifdef PETSC_USE_COMPLEX
399: SETERRQ(PETSC_ERR_SUP, "SectionReal does not support complex updates");
400: #else
401: if (mode == INSERT_VALUES) {
402: section->b->update(section->s, point, values);
403: } else if (mode == ADD_VALUES) {
404: section->b->updateAdd(section->s, point, values);
405: } else {
406: SETERRQ1(PETSC_ERR_ARG_WRONG, "Invalid insertion mode: %d", mode);
407: }
408: #endif
409: return(0);
410: }
414: /*@C
415: SectionRealRestrictClosure - Returns an array with the values in a given closure
417: Not Collective
419: Input Parameters:
420: + section - The section
421: . mesh - The Mesh object
422: . point - The sieve point
423: . n - The array size
424: - array - The array to fill up
426: Output Parameter:
427: . array - The array full of values in the closure
429: Level: intermediate
431: .keywords: mesh, elements
432: .seealso: MeshCreate()
433: @*/
434: PetscErrorCode SectionRealRestrictClosure(SectionReal section, Mesh mesh, PetscInt point, PetscInt n, PetscScalar values[])
435: {
436: ALE::Obj<PETSC_MESH_TYPE> m;
437: ALE::Obj<PETSC_MESH_TYPE::real_section_type> s;
438: PetscErrorCode ierr;
441: MeshGetMesh(mesh, m);
442: SectionRealGetSection(section, s);
443: #ifdef PETSC_USE_COMPLEX
444: SETERRQ(PETSC_ERR_SUP, "SectionReal does not support complex restriction");
445: #else
446: m->restrictClosure(s, point, values, n);
447: #endif
448: return(0);
449: }
453: /*@C
454: SectionRealUpdateClosure - Updates the values in a given closure from the array
456: Not Collective
458: Input Parameters:
459: + section - The section
460: . mesh - The Mesh object
461: . point - The sieve point
462: . array - The array to fill up
463: - mode - The insertion mode
465: Output Parameter:
466: . array - The array full of values in the closure
468: Level: intermediate
470: .keywords: mesh, elements
471: .seealso: MeshCreate()
472: @*/
473: PetscErrorCode SectionRealUpdateClosure(SectionReal section, Mesh mesh, PetscInt point, PetscScalar values[], InsertMode mode)
474: {
475: ALE::Obj<PETSC_MESH_TYPE> m;
476: ALE::Obj<PETSC_MESH_TYPE::real_section_type> s;
477: PetscErrorCode ierr;
480: MeshGetMesh(mesh, m);
481: SectionRealGetSection(section, s);
482: #ifdef PETSC_USE_COMPLEX
483: SETERRQ(PETSC_ERR_SUP, "SectionReal does not support complex update");
484: #else
485: if (mode == INSERT_VALUES) {
486: m->update(s, point, values);
487: } else if (mode == ADD_VALUES) {
488: m->updateAdd(s, point, values);
489: } else {
490: SETERRQ1(PETSC_ERR_ARG_WRONG, "Invalid insertion mode: %d", mode);
491: }
492: #endif
493: return(0);
494: }
498: /*@
499: SectionRealComplete - Exchanges data across the mesh overlap.
501: Not collective
503: Input Parameter:
504: . section - the section object
506: Level: advanced
508: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
509: @*/
510: PetscErrorCode SectionRealComplete(SectionReal section)
511: {
512: Obj<PETSC_MESH_TYPE::real_section_type> s;
513: Obj<PETSC_MESH_TYPE> b;
517: SectionRealGetSection(section, s);
518: SectionRealGetBundle(section, b);
519: #if 0
520: ALE::Distribution<PETSC_MESH_TYPE>::completeSection(b, s);
521: #else
522: ALE::Completion::completeSectionAdd(b->getSendOverlap(), b->getRecvOverlap(), s, s);
523: #endif
524: return(0);
525: }
529: /*@
530: SectionRealZero - Zero out the entries
532: Not collective
534: Input Parameter:
535: . section - the section object
537: Level: advanced
539: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
540: @*/
541: PetscErrorCode SectionRealZero(SectionReal section)
542: {
543: Obj<PETSC_MESH_TYPE::real_section_type> s;
547: SectionRealGetSection(section, s);
548: s->zero();
549: return(0);
550: }
554: /*@
555: SectionRealGetFiberDimension - Get the size of the vector space attached to the point
557: Not collective
559: Input Parameters:
560: + section - the section object
561: - point - the Sieve point
563: Output Parameters:
564: . size - The fiber dimension
566: Level: advanced
568: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
569: @*/
570: PetscErrorCode SectionRealGetFiberDimension(SectionReal section, PetscInt point, PetscInt *size)
571: {
574: *size = section->s->getFiberDimension(point);
575: return(0);
576: }
580: /*@
581: SectionRealSetFiberDimension - Set the size of the vector space attached to the point
583: Not collective
585: Input Parameters:
586: + section - the section object
587: . point - the Sieve point
588: - size - The fiber dimension
590: Level: advanced
592: .seealso SectionRealSetFiberDimensionField(), SectionRealRestrict(), SectionRealCreate(), SectionRealView()
593: @*/
594: PetscErrorCode SectionRealSetFiberDimension(SectionReal section, PetscInt point, const PetscInt size)
595: {
598: section->s->setFiberDimension(point, size);
599: return(0);
600: }
604: /*@
605: SectionRealSetFiberDimensionField - Set the size of the vector space attached to the point for a given field
607: Not collective
609: Input Parameters:
610: + section - the section object
611: . point - the Sieve point
612: . size - The fiber dimension
613: - field - The field number
615: Level: advanced
617: .seealso SectionRealSetFiberDimension(), SectionRealRestrict(), SectionRealCreate(), SectionRealView()
618: @*/
619: PetscErrorCode SectionRealSetFiberDimensionField(SectionReal section, PetscInt point, const PetscInt size, const PetscInt field)
620: {
623: section->s->setFiberDimension(point, size, field);
624: return(0);
625: }
629: /*@
630: SectionRealGetSize - Gets the number of local dofs in this Section
632: Not collective
634: Input Parameter:
635: . section - the section object
637: Output Parameter:
638: . size - the section size
640: Level: advanced
642: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
643: @*/
644: PetscErrorCode SectionRealGetSize(SectionReal section, PetscInt *size)
645: {
646: Obj<PETSC_MESH_TYPE::real_section_type> s;
651: SectionRealGetSection(section, s);
652: *size = s->size();
653: return(0);
654: }
658: /*@
659: SectionRealAllocate - Allocate storage for this section
661: Not collective
663: Input Parameter:
664: . section - the section object
666: Level: advanced
668: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
669: @*/
670: PetscErrorCode SectionRealAllocate(SectionReal section)
671: {
674: section->b->allocate(section->s);
675: return(0);
676: }
680: /*@
681: SectionRealCreateLocalVector - Creates a vector with the local piece of the Section
683: Collective on Mesh
685: Input Parameter:
686: . section - the Section
688: Output Parameter:
689: . localVec - the local vector
691: Level: advanced
693: Notes: The vector can safely be destroyed using VecDestroy().
694: .seealso MeshDestroy(), MeshCreate()
695: @*/
696: PetscErrorCode SectionRealCreateLocalVector(SectionReal section, Vec *localVec)
697: {
698: ALE::Obj<PETSC_MESH_TYPE::real_section_type> s;
702: #ifdef PETSC_USE_COMPLEX
703: SETERRQ(PETSC_ERR_SUP, "SectionReal does not support complex Vec");
704: #else
705: SectionRealGetSection(section, s);
706: VecCreateSeqWithArray(PETSC_COMM_SELF, s->getStorageSize(), s->restrictSpace(), localVec);
707: #endif
708: return(0);
709: }
713: /*@
714: SectionRealAddSpace - Add another field to this section
716: Collective on Mesh
718: Input Parameter:
719: . section - the Section
721: Level: advanced
723: .seealso SectionRealCreate(), SectionRealGetFibration()
724: @*/
725: PetscErrorCode SectionRealAddSpace(SectionReal section)
726: {
727: ALE::Obj<PETSC_MESH_TYPE::real_section_type> s;
731: SectionRealGetSection(section, s);
732: s->addSpace();
733: return(0);
734: }
738: /*@C
739: SectionRealGetFibration - Creates a section for only the data associated with the given field
741: Collective on Mesh
743: Input Parameter:
744: + section - the Section
745: - field- The field number
747: Output Parameter:
748: . subsection - the section of the given field
750: Level: advanced
752: .seealso SectionRealCreate()
753: @*/
754: PetscErrorCode SectionRealGetFibration(SectionReal section, const PetscInt field, SectionReal *subsection)
755: {
756: ALE::Obj<PETSC_MESH_TYPE> b;
757: ALE::Obj<PETSC_MESH_TYPE::real_section_type> s;
758: ALE::Obj<PETSC_MESH_TYPE::real_section_type> t;
759: MPI_Comm comm;
763: PetscObjectGetComm((PetscObject) section, &comm);
764: SectionRealGetBundle(section, b);
765: SectionRealGetSection(section, s);
766: SectionRealCreate(comm, subsection);
767: SectionRealSetBundle(*subsection, b);
768: t = s->getFibration(field);
769: SectionRealSetSection(*subsection, t);
770: return(0);
771: }
775: /*@C
776: SectionRealToVec - Maps the given section to a Vec
778: Collective on Section
780: Input Parameters:
781: + section - the real Section
782: - mesh - The Mesh
784: Output Parameter:
785: . vec - the Vec
787: Level: intermediate
789: .seealso VecCreate(), SectionRealCreate()
790: @*/
791: PetscErrorCode SectionRealToVec(SectionReal section, Mesh mesh, ScatterMode mode, Vec vec)
792: {
793: Vec localVec;
794: VecScatter scatter;
799: SectionRealCreateLocalVector(section, &localVec);
800: MeshGetGlobalScatter(mesh, &scatter);
801: if (mode == SCATTER_FORWARD) {
802: VecScatterBegin(scatter, localVec, vec, INSERT_VALUES, mode);
803: VecScatterEnd(scatter, localVec, vec, INSERT_VALUES, mode);
804: } else {
805: VecScatterBegin(scatter, vec, localVec, INSERT_VALUES, mode);
806: VecScatterEnd(scatter, vec, localVec, INSERT_VALUES, mode);
807: }
808: VecDestroy(localVec);
809: return(0);
810: }
814: /*@
815: SectionRealToVec - Map between unassembled local Section storage and a globally assembled Vec
817: Collective on VecScatter
819: Input Parameters:
820: + section - the Section
821: . scatter - the scatter from the Section to the Vec
822: . mode - the mode, SCATTER_FORWARD (Section to Vec) or SCATTER_REVERSE (Vec to Section)
823: - vec - the Vec
825: Level: advanced
827: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
828: @*/
829: PetscErrorCode SectionRealToVec(SectionReal section, VecScatter scatter, ScatterMode mode, Vec vec)
830: {
831: Vec localVec;
836: SectionRealCreateLocalVector(section, &localVec);
837: if (mode == SCATTER_FORWARD) {
838: VecScatterBegin(scatter, localVec, vec, INSERT_VALUES, mode);
839: VecScatterEnd(scatter, localVec, vec, INSERT_VALUES, mode);
840: } else {
841: VecScatterBegin(scatter, vec, localVec, INSERT_VALUES, mode);
842: VecScatterEnd(scatter, vec, localVec, INSERT_VALUES, mode);
843: }
844: VecDestroy(localVec);
845: return(0);
846: }
850: /*@
851: SectionRealClear - Dellocate storage for this section
853: Not collective
855: Input Parameter:
856: . section - the section object
858: Level: advanced
860: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
861: @*/
862: PetscErrorCode SectionRealClear(SectionReal section)
863: {
866: section->s->clear();
867: return(0);
868: }
872: /*@
873: SectionRealSet - Sets all the values to the given value
875: Not collective
877: Input Parameters:
878: + section - the real Section
879: - val - the value
881: Level: intermediate
883: .seealso VecNorm(), SectionRealCreate()
884: @*/
885: PetscErrorCode SectionRealSet(SectionReal section, PetscReal val)
886: {
887: Obj<PETSC_MESH_TYPE::real_section_type> s;
891: SectionRealGetSection(section, s);
892: s->set(val);
893: return(0);
894: }
898: /*@C
899: SectionRealNorm - Computes the vector norm.
901: Collective on Section
903: Input Parameters:
904: + section - the real Section
905: - type - one of NORM_1, NORM_2, NORM_INFINITY. Also available
906: NORM_1_AND_2, which computes both norms and stores them
907: in a two element array.
909: Output Parameter:
910: . val - the norm
912: Notes:
913: $ NORM_1 denotes sum_i |x_i|
914: $ NORM_2 denotes sqrt(sum_i (x_i)^2)
915: $ NORM_INFINITY denotes max_i |x_i|
917: Level: intermediate
919: .seealso VecNorm(), SectionRealCreate()
920: @*/
921: PetscErrorCode SectionRealNorm(SectionReal section, Mesh mesh, NormType type, PetscReal *val)
922: {
923: Obj<PETSC_MESH_TYPE> m;
924: Obj<PETSC_MESH_TYPE::real_section_type> s;
925: Vec v;
930: MeshGetMesh(mesh, m);
931: SectionRealGetSection(section, s);
932: const ALE::Obj<PETSC_MESH_TYPE::order_type>& order = m->getFactory()->getGlobalOrder(m, s->getName(), s);
933: VecCreate(m->comm(), &v);
934: VecSetSizes(v, order->getLocalSize(), order->getGlobalSize());
935: VecSetFromOptions(v);
936: SectionRealToVec(section, mesh, SCATTER_FORWARD, v);
937: VecNorm(v, type, val);
938: VecDestroy(v);
939: return(0);
940: }
944: /*@
945: SectionRealAXPY -
947: Collective on Section
949: Input Parameters:
950: + section - the real Section
951: . alpha - a scalar
952: - X - the other real Section
954: Output Parameter:
955: . section - the difference
957: Level: intermediate
959: .seealso VecNorm(), SectionRealCreate()
960: @*/
961: PetscErrorCode SectionRealAXPY(SectionReal section, Mesh mesh, PetscScalar alpha, SectionReal X)
962: {
963: Obj<PETSC_MESH_TYPE> m;
964: Obj<PETSC_MESH_TYPE::real_section_type> s;
965: Obj<PETSC_MESH_TYPE::real_section_type> sX;
966: Vec v, x;
971: MeshGetMesh(mesh, m);
972: SectionRealGetSection(section, s);
973: SectionRealGetSection(X, sX);
974: const ALE::Obj<PETSC_MESH_TYPE::order_type>& order = m->getFactory()->getGlobalOrder(m, s->getName(), s);
975: VecCreate(m->comm(), &v);
976: VecSetSizes(v, order->getLocalSize(), order->getGlobalSize());
977: VecSetFromOptions(v);
978: VecDuplicate(v, &x);
979: SectionRealToVec(section, mesh, SCATTER_FORWARD, v);
980: SectionRealToVec(X, mesh, SCATTER_FORWARD, x);
981: VecAXPY(v, alpha, x);
982: SectionRealToVec(section, mesh, SCATTER_REVERSE, v);
983: VecDestroy(v);
984: VecDestroy(x);
985: return(0);
986: }
990: /*@C
991: MeshGetVertexSectionReal - Create a Section over the vertices with the specified fiber dimension
993: Collective on Mesh
995: Input Parameters:
996: + mesh - The Mesh object
997: - fiberDim - The number of degrees of freedom per vertex
999: Output Parameter:
1000: . section - The section
1002: Level: intermediate
1004: .keywords: mesh, section, vertex
1005: .seealso: MeshCreate(), SectionRealCreate()
1006: @*/
1007: PetscErrorCode MeshGetVertexSectionReal(Mesh mesh, const char name[], PetscInt fiberDim, SectionReal *section)
1008: {
1009: ALE::Obj<PETSC_MESH_TYPE> m;
1010: ALE::Obj<PETSC_MESH_TYPE::real_section_type> s;
1011: PetscErrorCode ierr;
1014: MeshGetMesh(mesh, m);
1015: SectionRealCreate(m->comm(), section);
1016: PetscObjectSetName((PetscObject) *section, name);
1017: SectionRealSetBundle(*section, m);
1018: SectionRealGetSection(*section, s);
1019: #ifdef PETSC_OPT_SIEVE
1020: s->setChart(m->getSieve()->getChart());
1021: #endif
1022: s->setName(name);
1023: s->setFiberDimension(m->depthStratum(0), fiberDim);
1024: m->allocate(s);
1025: return(0);
1026: }
1030: /*@C
1031: MeshGetCellSectionReal - Create a Section over the cells with the specified fiber dimension
1033: Collective on Mesh
1035: Input Parameters:
1036: + mesh - The Mesh object
1037: - fiberDim - The section name
1039: Output Parameter:
1040: . section - The section
1042: Level: intermediate
1044: .keywords: mesh, section, cell
1045: .seealso: MeshCreate(), SectionRealCreate()
1046: @*/
1047: PetscErrorCode MeshGetCellSectionReal(Mesh mesh, const char name[], PetscInt fiberDim, SectionReal *section)
1048: {
1049: ALE::Obj<PETSC_MESH_TYPE> m;
1050: ALE::Obj<PETSC_MESH_TYPE::real_section_type> s;
1051: PetscErrorCode ierr;
1054: MeshGetMesh(mesh, m);
1055: SectionRealCreate(m->comm(), section);
1056: PetscObjectSetName((PetscObject) *section, name);
1057: SectionRealSetBundle(*section, m);
1058: SectionRealGetSection(*section, s);
1059: #ifdef PETSC_OPT_SIEVE
1060: s->setChart(m->getSieve()->getChart());
1061: #endif
1062: s->setName(name);
1063: s->setFiberDimension(m->heightStratum(0), fiberDim);
1064: m->allocate(s);
1065: return(0);
1066: }
1070: /*@C
1071: MeshCreateGlobalRealVector - Creates a vector of the correct size to be gathered into
1072: by the mesh.
1074: Collective on Mesh
1076: Input Parameters:
1077: + mesh - the mesh object
1078: - section - The SectionReal
1080: Output Parameters:
1081: . gvec - the global vector
1083: Level: advanced
1085: .seealso MeshDestroy(), MeshCreate(), MeshCreateGlobalVector()
1087: @*/
1088: PetscErrorCode MeshCreateGlobalRealVector(Mesh mesh, SectionReal section, Vec *gvec)
1089: {
1090: ALE::Obj<PETSC_MESH_TYPE> m;
1091: ALE::Obj<PETSC_MESH_TYPE::real_section_type> s;
1092: const char *name;
1096: MeshGetMesh(mesh, m);
1097: SectionRealGetSection(section, s);
1098: PetscObjectGetName((PetscObject) section, &name);
1099: const ALE::Obj<PETSC_MESH_TYPE::order_type>& order = m->getFactory()->getGlobalOrder(m, name, s);
1101: VecCreate(m->comm(), gvec);
1102: VecSetSizes(*gvec, order->getLocalSize(), order->getGlobalSize());
1103: VecSetFromOptions(*gvec);
1104: return(0);
1105: }
1109: PetscErrorCode SectionIntView_Sieve(SectionInt section, PetscViewer viewer)
1110: {
1111: PetscTruth iascii, isbinary, isdraw;
1115: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_ASCII, &iascii);
1116: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &isbinary);
1117: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_DRAW, &isdraw);
1119: if (iascii){
1120: ALE::Obj<PETSC_MESH_TYPE::int_section_type> s;
1121: ALE::Obj<PETSC_MESH_TYPE> b;
1122: const char *name;
1124: SectionIntGetSection(section, s);
1125: SectionIntGetBundle(section, b);
1126: PetscObjectGetName((PetscObject) section, &name);
1127: SectionView_Sieve_Ascii(b, s, name, viewer);
1128: } else if (isbinary) {
1129: SETERRQ(PETSC_ERR_SUP, "Binary viewer not implemented for Section");
1130: } else if (isdraw){
1131: SETERRQ(PETSC_ERR_SUP, "Draw viewer not implemented for Section");
1132: } else {
1133: SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported by this section object", ((PetscObject)viewer)->type_name);
1134: }
1135: return(0);
1136: }
1140: /*@C
1141: SectionIntView - Views a Section object.
1143: Collective on Section
1145: Input Parameters:
1146: + section - the Section
1147: - viewer - an optional visualization context
1149: Notes:
1150: The available visualization contexts include
1151: + PETSC_VIEWER_STDOUT_SELF - standard output (default)
1152: - PETSC_VIEWER_STDOUT_WORLD - synchronized standard
1153: output where only the first processor opens
1154: the file. All other processors send their
1155: data to the first processor to print.
1157: You can change the format the section is printed using the
1158: option PetscViewerSetFormat().
1160: The user can open alternative visualization contexts with
1161: + PetscViewerASCIIOpen() - Outputs section to a specified file
1162: . PetscViewerBinaryOpen() - Outputs section in binary to a
1163: specified file; corresponding input uses SectionLoad()
1164: . PetscViewerDrawOpen() - Outputs section to an X window display
1166: The user can call PetscViewerSetFormat() to specify the output
1167: format of ASCII printed objects (when using PETSC_VIEWER_STDOUT_SELF,
1168: PETSC_VIEWER_STDOUT_WORLD and PetscViewerASCIIOpen). Available formats include
1169: + PETSC_VIEWER_DEFAULT - default, prints section information
1170: - PETSC_VIEWER_ASCII_VTK - outputs a VTK file describing the section
1172: Level: beginner
1174: Concepts: section^printing
1175: Concepts: section^saving to disk
1177: .seealso: VecView(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerBinaryOpen(), PetscViewerCreate()
1178: @*/
1179: PetscErrorCode SectionIntView(SectionInt section, PetscViewer viewer)
1180: {
1186: if (!viewer) {
1187: PetscViewerASCIIGetStdout(((PetscObject)section)->comm,&viewer);
1188: }
1192: PetscLogEventBegin(SectionInt_View,0,0,0,0);
1193: (*section->ops->view)(section, viewer);
1194: PetscLogEventEnd(SectionInt_View,0,0,0,0);
1195: return(0);
1196: }
1200: /*@C
1201: SectionIntGetSection - Gets the internal section object
1203: Not collective
1205: Input Parameter:
1206: . section - the section object
1208: Output Parameter:
1209: . s - the internal section object
1210:
1211: Level: advanced
1213: .seealso SectionIntCreate(), SectionIntSetSection()
1214: @*/
1215: PetscErrorCode SectionIntGetSection(SectionInt section, ALE::Obj<PETSC_MESH_TYPE::int_section_type>& s)
1216: {
1219: s = section->s;
1220: return(0);
1221: }
1225: /*@C
1226: SectionIntSetSection - Sets the internal section object
1228: Not collective
1230: Input Parameters:
1231: + section - the section object
1232: - s - the internal section object
1233:
1234: Level: advanced
1236: .seealso SectionIntCreate(), SectionIntGetSection()
1237: @*/
1238: PetscErrorCode SectionIntSetSection(SectionInt section, const ALE::Obj<PETSC_MESH_TYPE::int_section_type>& s)
1239: {
1244: if (!s.isNull()) {PetscObjectSetName((PetscObject) section, s->getName().c_str());}
1245: section->s = s;
1246: return(0);
1247: }
1251: /*@C
1252: SectionIntGetBundle - Gets the section bundle
1254: Not collective
1256: Input Parameter:
1257: . section - the section object
1259: Output Parameter:
1260: . b - the section bundle
1261:
1262: Level: advanced
1264: .seealso SectionIntCreate(), SectionIntGetSection(), SectionIntSetSection()
1265: @*/
1266: PetscErrorCode SectionIntGetBundle(SectionInt section, ALE::Obj<PETSC_MESH_TYPE>& b)
1267: {
1270: b = section->b;
1271: return(0);
1272: }
1276: /*@C
1277: SectionIntSetBundle - Sets the section bundle
1279: Not collective
1281: Input Parameters:
1282: + section - the section object
1283: - b - the section bundle
1284:
1285: Level: advanced
1287: .seealso SectionIntCreate(), SectionIntGetSection(), SectionIntSetSection()
1288: @*/
1289: PetscErrorCode SectionIntSetBundle(SectionInt section, const ALE::Obj<PETSC_MESH_TYPE>& b)
1290: {
1293: section->b = b;
1294: return(0);
1295: }
1299: /*@C
1300: SectionIntCreate - Creates a Section object, used to manage data for an unstructured problem
1301: described by a Sieve.
1303: Collective on MPI_Comm
1305: Input Parameter:
1306: . comm - the processors that will share the global section
1308: Output Parameters:
1309: . section - the section object
1311: Level: advanced
1313: .seealso SectionIntDestroy(), SectionIntView()
1314: @*/
1315: PetscErrorCode SectionIntCreate(MPI_Comm comm, SectionInt *section)
1316: {
1318: SectionInt s;
1322: *section = PETSC_NULL;
1324: PetscHeaderCreate(s,_p_SectionInt,struct _SectionIntOps,SECTIONINT_COOKIE,0,"SectionInt",comm,SectionIntDestroy,0);
1325: s->ops->view = SectionIntView_Sieve;
1326: s->ops->restrictClosure = SectionIntRestrict;
1327: s->ops->update = SectionIntUpdate;
1329: PetscObjectChangeTypeName((PetscObject) s, "sieve");
1331: new(&s->s) ALE::Obj<PETSC_MESH_TYPE::int_section_type>(PETSC_MESH_TYPE::int_section_type(comm));
1332: new(&s->b) ALE::Obj<PETSC_MESH_TYPE>(PETSC_NULL);
1333: *section = s;
1334: return(0);
1335: }
1339: /*@
1340: SectionIntDestroy - Destroys a section.
1342: Collective on Section
1344: Input Parameter:
1345: . section - the section object
1347: Level: advanced
1349: .seealso SectionIntCreate(), SectionIntView()
1350: @*/
1351: PetscErrorCode SectionIntDestroy(SectionInt section)
1352: {
1357: if (--((PetscObject)section)->refct > 0) return(0);
1358: section->s = PETSC_NULL;
1359: PetscHeaderDestroy(section);
1360: return(0);
1361: }
1365: /*@C
1366: SectionIntDistribute - Distributes the sections.
1368: Not Collective
1370: Input Parameters:
1371: + serialSection - The original Section object
1372: - parallelMesh - The parallel Mesh
1374: Output Parameter:
1375: . parallelSection - The distributed Section object
1377: Level: intermediate
1379: .keywords: mesh, section, distribute
1380: .seealso: MeshCreate()
1381: @*/
1382: PetscErrorCode SectionIntDistribute(SectionInt serialSection, Mesh parallelMesh, SectionInt *parallelSection)
1383: {
1384: ALE::Obj<PETSC_MESH_TYPE::int_section_type> oldSection;
1385: ALE::Obj<PETSC_MESH_TYPE> m;
1386: PetscErrorCode ierr;
1389: SectionIntGetSection(serialSection, oldSection);
1390: MeshGetMesh(parallelMesh, m);
1391: SectionIntCreate(oldSection->comm(), parallelSection);
1392: #ifdef PETSC_OPT_SIEVE
1393: ALE::Obj<PETSC_MESH_TYPE::int_section_type> newSection;
1395: // We assume all integer sections are complete sections
1396: newSection->setName(oldSection->getName());
1397: newSection->setChart(m->getSieve()->getChart());
1398: //distributeSection(oldSection, partition, m->getRenumbering(), m->getDistSendOverlap(), m->getDistRecvOverlap(), newSection);
1399: SectionIntSetSection(*parallelSection, newSection);
1400: SETERRQ(PETSC_ERR_SUP, "Not working because the partition is unavailable");
1401: #else
1402: ALE::Obj<PETSC_MESH_TYPE::int_section_type> newSection = ALE::Distribution<PETSC_MESH_TYPE>::distributeSection(oldSection, m, m->getDistSendOverlap(), m->getDistRecvOverlap());
1403: SectionIntSetSection(*parallelSection, newSection);
1404: #endif
1405: return(0);
1406: }
1410: /*@C
1411: SectionIntRestrict - Restricts the SectionInt to a subset of the topology, returning an array of values.
1413: Not collective
1415: Input Parameters:
1416: + section - the section object
1417: - point - the Sieve point
1419: Output Parameter:
1420: . values - The values associated with the submesh
1422: Level: advanced
1424: .seealso SectionIntUpdate(), SectionIntCreate(), SectionIntView()
1425: @*/
1426: PetscErrorCode SectionIntRestrict(SectionInt section, PetscInt point, PetscInt *values[])
1427: {
1431: *values = (PetscInt *) section->b->restrictClosure(section->s, point);
1432: return(0);
1433: }
1437: /*@C
1438: SectionIntUpdate - Updates the array of values associated to a subset of the topology in this Section.
1440: Not collective
1442: Input Parameters:
1443: + section - the section object
1444: . point - the Sieve point
1445: . values - The values associated with the submesh
1446: - mode - The insertion mode
1448: Level: advanced
1450: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1451: @*/
1452: PetscErrorCode SectionIntUpdate(SectionInt section, PetscInt point, const PetscInt values[], InsertMode mode)
1453: {
1457: if (mode == INSERT_VALUES) {
1458: section->b->update(section->s, point, values);
1459: } else if (mode == ADD_VALUES) {
1460: section->b->updateAdd(section->s, point, values);
1461: } else {
1462: SETERRQ1(PETSC_ERR_ARG_WRONG, "Invalid insertion mode: %d", mode);
1463: }
1464: return(0);
1465: }
1469: /*@C
1470: SectionIntRestrictClosure - Returns an array with the values in a given closure
1472: Not Collective
1474: Input Parameters:
1475: + section - The section
1476: . mesh - The Mesh object
1477: . point - The sieve point
1478: . n - The array size
1479: - array - The array to fill up
1481: Output Parameter:
1482: . array - The array full of values in the closure
1484: Level: intermediate
1486: .keywords: mesh, elements
1487: .seealso: MeshCreate()
1488: @*/
1489: PetscErrorCode SectionIntRestrictClosure(SectionInt section, Mesh mesh, PetscInt point, PetscInt n, PetscInt values[])
1490: {
1491: ALE::Obj<PETSC_MESH_TYPE> m;
1492: ALE::Obj<PETSC_MESH_TYPE::int_section_type> s;
1493: PetscErrorCode ierr;
1496: MeshGetMesh(mesh, m);
1497: SectionIntGetSection(section, s);
1498: m->restrictClosure(s, point, values, n);
1499: return(0);
1500: }
1504: /*@C
1505: SectionIntUpdateClosure - Updates the values in a given closure from the array
1507: Not Collective
1509: Input Parameters:
1510: + section - The section
1511: . mesh - The Mesh object
1512: . point - The sieve point
1513: . array - The array to fill up
1514: - mode - The insertion mode
1516: Output Parameter:
1517: . array - The array full of values in the closure
1519: Level: intermediate
1521: .keywords: mesh, elements
1522: .seealso: MeshCreate()
1523: @*/
1524: PetscErrorCode SectionIntUpdateClosure(SectionInt section, Mesh mesh, PetscInt point, PetscInt values[], InsertMode mode)
1525: {
1526: ALE::Obj<PETSC_MESH_TYPE> m;
1527: ALE::Obj<PETSC_MESH_TYPE::int_section_type> s;
1528: PetscErrorCode ierr;
1531: MeshGetMesh(mesh, m);
1532: SectionIntGetSection(section, s);
1533: if (mode == INSERT_VALUES) {
1534: m->update(s, point, values);
1535: } else if (mode == ADD_VALUES) {
1536: m->updateAdd(s, point, values);
1537: } else {
1538: SETERRQ1(PETSC_ERR_ARG_WRONG, "Invalid insertion mode: %d", mode);
1539: }
1540: return(0);
1541: }
1545: /*@
1546: SectionIntComplete - Exchanges data across the mesh overlap.
1548: Not collective
1550: Input Parameter:
1551: . section - the section object
1553: Level: advanced
1555: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1556: @*/
1557: PetscErrorCode SectionIntComplete(SectionInt section)
1558: {
1559: Obj<PETSC_MESH_TYPE::int_section_type> s;
1560: Obj<PETSC_MESH_TYPE> b;
1564: SectionIntGetSection(section, s);
1565: SectionIntGetBundle(section, b);
1566: #if 0
1567: ALE::Distribution<PETSC_MESH_TYPE>::completeSection(b, s);
1568: #else
1569: ALE::Completion::completeSectionAdd(b->getSendOverlap(), b->getRecvOverlap(), s, s);
1570: #endif
1571: return(0);
1572: }
1576: /*@
1577: SectionIntZero - Zero out the entries
1579: Not collective
1581: Input Parameter:
1582: . section - the section object
1584: Level: advanced
1586: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1587: @*/
1588: PetscErrorCode SectionIntZero(SectionInt section)
1589: {
1590: Obj<PETSC_MESH_TYPE::int_section_type> s;
1594: SectionIntGetSection(section, s);
1595: s->zero();
1596: return(0);
1597: }
1601: /*@
1602: SectionIntGetFiberDimension - Get the size of the vector space attached to the point
1604: Not collective
1606: Input Parameters:
1607: + section - the section object
1608: - point - the Sieve point
1610: Output Parameters:
1611: . size - The fiber dimension
1613: Level: advanced
1615: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
1616: @*/
1617: PetscErrorCode SectionIntGetFiberDimension(SectionInt section, PetscInt point, PetscInt *size)
1618: {
1621: *size = section->s->getFiberDimension(point);
1622: return(0);
1623: }
1627: /*@
1628: SectionIntSetFiberDimension - Set the size of the vector space attached to the point
1630: Not collective
1632: Input Parameters:
1633: + section - the section object
1634: . point - the Sieve point
1635: - size - The fiber dimension
1637: Level: advanced
1639: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1640: @*/
1641: PetscErrorCode SectionIntSetFiberDimension(SectionInt section, PetscInt point, const PetscInt size)
1642: {
1645: section->s->setFiberDimension(point, size);
1646: return(0);
1647: }
1651: /*@
1652: SectionIntSetFiberDimensionField - Set the size of the vector space attached to the point for a given field
1654: Not collective
1656: Input Parameters:
1657: + section - the section object
1658: . point - the Sieve point
1659: . size - The fiber dimension
1660: - field - The field number
1662: Level: advanced
1664: .seealso SectionIntSetFiberDimension(), SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1665: @*/
1666: PetscErrorCode SectionIntSetFiberDimensionField(SectionInt section, PetscInt point, const PetscInt size, const PetscInt field)
1667: {
1670: section->s->setFiberDimension(point, size, field);
1671: return(0);
1672: }
1676: /*@
1677: SectionIntGetSize - Gets the number of local dofs in this Section
1679: Not collective
1681: Input Parameter:
1682: . section - the section object
1684: Output Parameter:
1685: . size - the section size
1687: Level: advanced
1689: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1690: @*/
1691: PetscErrorCode SectionIntGetSize(SectionInt section, PetscInt *size)
1692: {
1693: Obj<PETSC_MESH_TYPE::int_section_type> s;
1698: SectionIntGetSection(section, s);
1699: *size = s->size();
1700: return(0);
1701: }
1705: /*@
1706: SectionIntAllocate - Allocate storage for this section
1708: Not collective
1710: Input Parameter:
1711: . section - the section object
1713: Level: advanced
1715: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1716: @*/
1717: PetscErrorCode SectionIntAllocate(SectionInt section)
1718: {
1721: section->b->allocate(section->s);
1722: return(0);
1723: }
1727: /*@C
1728: SectionIntClear - Dellocate storage for this section
1730: Not collective
1732: Input Parameter:
1733: . section - the section object
1735: Level: advanced
1737: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1738: @*/
1739: PetscErrorCode SectionIntClear(SectionInt section)
1740: {
1743: section->s->clear();
1744: return(0);
1745: }
1749: /*@
1750: SectionIntSet - Sets all the values to the given value
1752: Not collective
1754: Input Parameters:
1755: + section - the real Section
1756: - val - the value
1758: Level: intermediate
1760: .seealso VecNorm(), SectionIntCreate()
1761: @*/
1762: PetscErrorCode SectionIntSet(SectionInt section, PetscInt val)
1763: {
1764: Obj<PETSC_MESH_TYPE::int_section_type> s;
1768: SectionIntGetSection(section, s);
1769: s->set(val);
1770: return(0);
1771: }
1775: /*@
1776: SectionIntAddSpace - Add another field to this section
1778: Collective on Mesh
1780: Input Parameter:
1781: . section - the Section
1783: Level: advanced
1785: .seealso SectionIntCreate(), SectionIntGetFibration()
1786: @*/
1787: PetscErrorCode SectionIntAddSpace(SectionInt section)
1788: {
1789: ALE::Obj<PETSC_MESH_TYPE::int_section_type> s;
1793: SectionIntGetSection(section, s);
1794: s->addSpace();
1795: return(0);
1796: }
1800: /*@C
1801: SectionIntGetFibration - Creates a section for only the data associated with the given field
1803: Collective on Mesh
1805: Input Parameter:
1806: + section - the Section
1807: - field- The field number
1809: Output Parameter:
1810: . subsection - the section of the given field
1812: Level: advanced
1814: .seealso SectionIntCreate(), SectionIntAddSpace()
1815: @*/
1816: PetscErrorCode SectionIntGetFibration(SectionInt section, const PetscInt field, SectionInt *subsection)
1817: {
1818: ALE::Obj<PETSC_MESH_TYPE> b;
1819: ALE::Obj<PETSC_MESH_TYPE::int_section_type> s;
1820: ALE::Obj<PETSC_MESH_TYPE::int_section_type> t;
1821: MPI_Comm comm;
1825: PetscObjectGetComm((PetscObject) section, &comm);
1826: SectionIntGetBundle(section, b);
1827: SectionIntGetSection(section, s);
1828: SectionIntCreate(comm, subsection);
1829: SectionIntSetBundle(*subsection, b);
1830: t = s->getFibration(field);
1831: SectionIntSetSection(*subsection, t);
1832: return(0);
1833: }
1837: /*@C
1838: MeshGetVertexSectionInt - Create a Section over the vertices with the specified fiber dimension
1840: Collective on Mesh
1842: Input Parameters:
1843: + mesh - The Mesh object
1844: - fiberDim - The section name
1846: Output Parameter:
1847: . section - The section
1849: Level: intermediate
1851: .keywords: mesh, section, vertex
1852: .seealso: MeshCreate(), SectionIntCreate()
1853: @*/
1854: PetscErrorCode MeshGetVertexSectionInt(Mesh mesh, const char name[], PetscInt fiberDim, SectionInt *section)
1855: {
1856: ALE::Obj<PETSC_MESH_TYPE> m;
1857: ALE::Obj<PETSC_MESH_TYPE::int_section_type> s;
1858: PetscErrorCode ierr;
1861: MeshGetMesh(mesh, m);
1862: SectionIntCreate(m->comm(), section);
1863: PetscObjectSetName((PetscObject) *section, name);
1864: SectionIntSetBundle(*section, m);
1865: SectionIntGetSection(*section, s);
1866: #ifdef PETSC_OPT_SIEVE
1867: s->setChart(m->getSieve()->getChart());
1868: #endif
1869: s->setName(name);
1870: s->setFiberDimension(m->depthStratum(0), fiberDim);
1871: m->allocate(s);
1872: return(0);
1873: }
1877: /*@C
1878: MeshGetCellSectionInt - Create a Section over the cells with the specified fiber dimension
1880: Collective on Mesh
1882: Input Parameters:
1883: + mesh - The Mesh object
1884: - fiberDim - The section name
1886: Output Parameter:
1887: . section - The section
1889: Level: intermediate
1891: .keywords: mesh, section, cell
1892: .seealso: MeshCreate(), SectionIntCreate()
1893: @*/
1894: PetscErrorCode MeshGetCellSectionInt(Mesh mesh, const char name[], PetscInt fiberDim, SectionInt *section)
1895: {
1896: ALE::Obj<PETSC_MESH_TYPE> m;
1897: ALE::Obj<PETSC_MESH_TYPE::int_section_type> s;
1898: PetscErrorCode ierr;
1901: MeshGetMesh(mesh, m);
1902: SectionIntCreate(m->comm(), section);
1903: PetscObjectSetName((PetscObject) *section, name);
1904: SectionIntSetBundle(*section, m);
1905: SectionIntGetSection(*section, s);
1906: #ifdef PETSC_OPT_SIEVE
1907: s->setChart(m->getSieve()->getChart());
1908: #endif
1909: s->setName(name);
1910: s->setFiberDimension(m->heightStratum(0), fiberDim);
1911: m->allocate(s);
1912: return(0);
1913: }