Actual source code: section.c
1: #include "private/meshimpl.h" /*I "petscmesh.h" I*/
2: #include src/dm/mesh/meshvtk.h
4: /* Logging support */
5: PetscCookie SECTIONREAL_COOKIE = 0;
6: PetscEvent SectionReal_View = 0;
7: PetscCookie SECTIONINT_COOKIE = 0;
8: PetscEvent SectionInt_View = 0;
9: PetscCookie SECTIONPAIR_COOKIE = 0;
10: PetscEvent SectionPair_View = 0;
14: template<typename Bundle, typename Section>
15: PetscErrorCode SectionView_Sieve_Ascii(const Obj<Bundle>& bundle, const Obj<Section>& s, const char name[], PetscViewer viewer)
16: {
17: // state 0: No header has been output
18: // state 1: Only POINT_DATA has been output
19: // state 2: Only CELL_DATA has been output
20: // state 3: Output both, POINT_DATA last
21: // state 4: Output both, CELL_DATA last
22: PetscViewerFormat format;
23: PetscErrorCode ierr;
26: PetscViewerGetFormat(viewer, &format);
27: if (format == PETSC_VIEWER_ASCII_VTK || format == PETSC_VIEWER_ASCII_VTK_CELL) {
28: static PetscInt stateId = -1;
29: PetscInt doOutput = 0;
30: PetscInt outputState = 0;
31: PetscTruth hasState;
33: if (stateId < 0) {
34: PetscObjectComposedDataRegister(&stateId);
35: PetscObjectComposedDataSetInt((PetscObject) viewer, stateId, 0);
36: }
37: PetscObjectComposedDataGetInt((PetscObject) viewer, stateId, outputState, hasState);
38: if (format == PETSC_VIEWER_ASCII_VTK) {
39: if (outputState == 0) {
40: outputState = 1;
41: doOutput = 1;
42: } else if (outputState == 1) {
43: doOutput = 0;
44: } else if (outputState == 2) {
45: outputState = 3;
46: doOutput = 1;
47: } else if (outputState == 3) {
48: doOutput = 0;
49: } else if (outputState == 4) {
50: SETERRQ(PETSC_ERR_ARG_WRONGSTATE, "Tried to output POINT_DATA again after intervening CELL_DATA");
51: }
52: const ALE::Obj<ALE::Mesh::numbering_type>& numbering = bundle->getFactory()->getNumbering(bundle, 0);
53: PetscInt fiberDim = std::abs(s->getFiberDimension(*bundle->depthStratum(0)->begin()));
55: if (doOutput) {
56: PetscViewerASCIIPrintf(viewer, "POINT_DATA %d\n", numbering->getGlobalSize());
57: }
58: VTKViewer::writeField(s, std::string(name), fiberDim, numbering, viewer);
59: } else {
60: if (outputState == 0) {
61: outputState = 2;
62: doOutput = 1;
63: } else if (outputState == 1) {
64: outputState = 4;
65: doOutput = 1;
66: } else if (outputState == 2) {
67: doOutput = 0;
68: } else if (outputState == 3) {
69: SETERRQ(PETSC_ERR_ARG_WRONGSTATE, "Tried to output CELL_DATA again after intervening POINT_DATA");
70: } else if (outputState == 4) {
71: doOutput = 0;
72: }
73: const ALE::Obj<ALE::Mesh::numbering_type>& numbering = bundle->getFactory()->getNumbering(bundle, bundle->depth());
74: PetscInt fiberDim = s->getFiberDimension(*bundle->heightStratum(0)->begin());
76: if (doOutput) {
77: PetscViewerASCIIPrintf(viewer, "CELL_DATA %d\n", numbering->getGlobalSize());
78: }
79: VTKViewer::writeField(s, std::string(name), fiberDim, numbering, viewer);
80: }
81: PetscObjectComposedDataSetInt((PetscObject) viewer, stateId, outputState);
82: } else {
83: s->view(name);
84: }
85: return(0);
86: }
90: PetscErrorCode SectionRealView_Sieve(SectionReal section, PetscViewer viewer)
91: {
92: PetscTruth iascii, isbinary, isdraw;
96: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_ASCII, &iascii);
97: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &isbinary);
98: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_DRAW, &isdraw);
100: if (iascii){
101: ALE::Obj<ALE::Mesh::real_section_type> s;
102: ALE::Obj<ALE::Mesh> b;
103: const char *name;
105: SectionRealGetSection(section, s);
106: SectionRealGetBundle(section, b);
107: PetscObjectGetName((PetscObject) section, &name);
108: SectionView_Sieve_Ascii(b, s, name, viewer);
109: } else if (isbinary) {
110: SETERRQ(PETSC_ERR_SUP, "Binary viewer not implemented for Section");
111: } else if (isdraw){
112: SETERRQ(PETSC_ERR_SUP, "Draw viewer not implemented for Section");
113: } else {
114: SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported by this section object", ((PetscObject)viewer)->type_name);
115: }
116: return(0);
117: }
121: /*@C
122: SectionRealView - Views a Section object.
124: Collective on Section
126: Input Parameters:
127: + section - the Section
128: - viewer - an optional visualization context
130: Notes:
131: The available visualization contexts include
132: + PETSC_VIEWER_STDOUT_SELF - standard output (default)
133: - PETSC_VIEWER_STDOUT_WORLD - synchronized standard
134: output where only the first processor opens
135: the file. All other processors send their
136: data to the first processor to print.
138: You can change the format the section is printed using the
139: option PetscViewerSetFormat().
141: The user can open alternative visualization contexts with
142: + PetscViewerASCIIOpen() - Outputs section to a specified file
143: . PetscViewerBinaryOpen() - Outputs section in binary to a
144: specified file; corresponding input uses SectionLoad()
145: . PetscViewerDrawOpen() - Outputs section to an X window display
147: The user can call PetscViewerSetFormat() to specify the output
148: format of ASCII printed objects (when using PETSC_VIEWER_STDOUT_SELF,
149: PETSC_VIEWER_STDOUT_WORLD and PetscViewerASCIIOpen). Available formats include
150: + PETSC_VIEWER_ASCII_DEFAULT - default, prints section information
151: - PETSC_VIEWER_ASCII_VTK - outputs a VTK file describing the section
153: Level: beginner
155: Concepts: section^printing
156: Concepts: section^saving to disk
158: .seealso: VecView(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerBinaryOpen(), PetscViewerCreate()
159: @*/
160: PetscErrorCode SectionRealView(SectionReal section, PetscViewer viewer)
161: {
167: if (!viewer) {
168: PetscViewerASCIIGetStdout(section->comm,&viewer);
169: }
174: (*section->ops->view)(section, viewer);
176: return(0);
177: }
181: /*@C
182: SectionRealDuplicate - Create an equivalent Section object
184: Not collective
186: Input Parameter:
187: . section - the section object
189: Output Parameter:
190: . newSection - the duplicate
191:
192: Level: advanced
194: .seealso SectionRealCreate(), SectionRealSetSection()
195: @*/
196: PetscErrorCode SectionRealDuplicate(SectionReal section, SectionReal *newSection)
197: {
203: const ALE::Obj<ALE::Mesh::real_section_type>& s = section->s;
204: ALE::Obj<ALE::Mesh::real_section_type> t = new ALE::Mesh::real_section_type(s->comm(), s->debug());
206: t->setAtlas(s->getAtlas());
207: t->allocateStorage();
208: t->copyBC(s);
209: SectionRealCreate(s->comm(), newSection);
210: SectionRealSetSection(*newSection, t);
211: SectionRealSetBundle(*newSection, section->b);
212: return(0);
213: }
217: /*@C
218: SectionRealGetSection - Gets the internal section object
220: Not collective
222: Input Parameter:
223: . section - the section object
225: Output Parameter:
226: . s - the internal section object
227:
228: Level: advanced
230: .seealso SectionRealCreate(), SectionRealSetSection()
231: @*/
232: PetscErrorCode SectionRealGetSection(SectionReal section, ALE::Obj<ALE::Mesh::real_section_type>& s)
233: {
236: s = section->s;
237: return(0);
238: }
242: /*@C
243: SectionRealSetSection - Sets the internal section object
245: Not collective
247: Input Parameters:
248: + section - the section object
249: - s - the internal section object
250:
251: Level: advanced
253: .seealso SectionRealCreate(), SectionRealGetSection()
254: @*/
255: PetscErrorCode SectionRealSetSection(SectionReal section, const ALE::Obj<ALE::Mesh::real_section_type>& s)
256: {
259: section->s = s;
260: return(0);
261: }
265: /*@C
266: SectionRealGetBundle - Gets the section bundle
268: Not collective
270: Input Parameter:
271: . section - the section object
273: Output Parameter:
274: . b - the section bundle
275:
276: Level: advanced
278: .seealso SectionRealCreate(), SectionRealGetSection(), SectionRealSetSection()
279: @*/
280: PetscErrorCode SectionRealGetBundle(SectionReal section, ALE::Obj<ALE::Mesh>& b)
281: {
284: b = section->b;
285: return(0);
286: }
290: /*@C
291: SectionRealSetBundle - Sets the section bundle
293: Not collective
295: Input Parameters:
296: + section - the section object
297: - b - the section bundle
298:
299: Level: advanced
301: .seealso SectionRealCreate(), SectionRealGetSection(), SectionRealSetSection()
302: @*/
303: PetscErrorCode SectionRealSetBundle(SectionReal section, const ALE::Obj<ALE::Mesh>& b)
304: {
307: section->b = b;
308: return(0);
309: }
313: /*@C
314: SectionRealCreate - Creates a Section object, used to manage data for an unstructured problem
315: described by a Sieve.
317: Collective on MPI_Comm
319: Input Parameter:
320: . comm - the processors that will share the global section
322: Output Parameters:
323: . section - the section object
325: Level: advanced
327: .seealso SectionRealDestroy(), SectionRealView()
328: @*/
329: PetscErrorCode SectionRealCreate(MPI_Comm comm, SectionReal *section)
330: {
332: SectionReal s;
336: *section = PETSC_NULL;
338: PetscHeaderCreate(s,_p_SectionReal,struct _SectionRealOps,SECTIONREAL_COOKIE,0,"SectionReal",comm,SectionRealDestroy,0);
339: s->ops->view = SectionRealView_Sieve;
340: s->ops->restrict = SectionRealRestrict;
341: s->ops->update = SectionRealUpdate;
343: PetscObjectChangeTypeName((PetscObject) s, "sieve");
345: s->s = new ALE::Mesh::real_section_type(comm);
346: *section = s;
347: return(0);
348: }
352: /*@C
353: SectionRealDestroy - Destroys a section.
355: Collective on Section
357: Input Parameter:
358: . section - the section object
360: Level: advanced
362: .seealso SectionRealCreate(), SectionRealView()
363: @*/
364: PetscErrorCode SectionRealDestroy(SectionReal section)
365: {
370: if (--section->refct > 0) return(0);
371: section->s = PETSC_NULL;
372: PetscHeaderDestroy(section);
373: return(0);
374: }
378: /*@C
379: SectionRealDistribute - Distributes the sections.
381: Not Collective
383: Input Parameters:
384: + serialSection - The original Section object
385: - parallelMesh - The parallel Mesh
387: Output Parameter:
388: . parallelSection - The distributed Section object
390: Level: intermediate
392: .keywords: mesh, section, distribute
393: .seealso: MeshCreate()
394: @*/
395: PetscErrorCode SectionRealDistribute(SectionReal serialSection, Mesh parallelMesh, SectionReal *parallelSection)
396: {
397: ALE::Obj<ALE::Mesh::real_section_type> oldSection;
398: ALE::Obj<ALE::Mesh> m;
402: SectionRealGetSection(serialSection, oldSection);
403: MeshGetMesh(parallelMesh, m);
404: SectionRealCreate(oldSection->comm(), parallelSection);
405: ALE::Obj<ALE::Mesh::real_section_type> newSection = ALE::Distribution<ALE::Mesh>::distributeSection(oldSection, m, m->getDistSendOverlap(), m->getDistRecvOverlap());
406: SectionRealSetSection(*parallelSection, newSection);
407: return(0);
408: }
412: /*@C
413: SectionRealRestrict - Restricts the SectionReal to a subset of the topology, returning an array of values.
415: Not collective
417: Input Parameters:
418: + section - the section object
419: - point - the Sieve point
421: Output Parameter:
422: . values - The values associated with the submesh
424: Level: advanced
426: .seealso SectionUpdate(), SectionCreate(), SectionView()
427: @*/
428: PetscErrorCode SectionRealRestrict(SectionReal section, PetscInt point, PetscScalar *values[])
429: {
433: *values = (PetscScalar *) section->b->restrict(section->s, point);
434: return(0);
435: }
439: /*@C
440: SectionRealUpdate - Updates the array of values associated to a subset of the topology in this Section.
442: Not collective
444: Input Parameters:
445: + section - the section object
446: . point - the Sieve point
447: - values - The values associated with the submesh
449: Level: advanced
451: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
452: @*/
453: PetscErrorCode SectionRealUpdate(SectionReal section, PetscInt point, const PetscScalar values[])
454: {
458: section->b->update(section->s, point, values);
459: return(0);
460: }
464: /*@C
465: SectionRealUpdateAdd - Updates the array of values associated to a subset of the topology in this Section.
467: Not collective
469: Input Parameters:
470: + section - the section object
471: . point - the Sieve point
472: - values - The values associated with the submesh
474: Level: advanced
476: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
477: @*/
478: PetscErrorCode SectionRealUpdateAdd(SectionReal section, PetscInt point, const PetscScalar values[])
479: {
483: section->b->updateAdd(section->s, point, values);
484: return(0);
485: }
489: /*@C
490: SectionRealComplete - Exchanges data across the mesh overlap.
492: Not collective
494: Input Parameter:
495: . section - the section object
497: Level: advanced
499: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
500: @*/
501: PetscErrorCode SectionRealComplete(SectionReal section)
502: {
503: Obj<ALE::Mesh::real_section_type> s;
504: Obj<ALE::Mesh> b;
508: SectionRealGetSection(section, s);
509: SectionRealGetBundle(section, b);
510: ALE::Distribution<ALE::Mesh>::completeSection(b, s);
511: return(0);
512: }
516: /*@C
517: SectionRealZero - Zero out the entries
519: Not collective
521: Input Parameter:
522: . section - the section object
524: Level: advanced
526: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
527: @*/
528: PetscErrorCode SectionRealZero(SectionReal section)
529: {
530: Obj<ALE::Mesh::real_section_type> s;
534: SectionRealGetSection(section, s);
535: s->zero();
536: return(0);
537: }
541: /*@C
542: SectionRealSetFiberDimension - Set the size of the vector space attached to the point
544: Not collective
546: Input Parameters:
547: + section - the section object
548: . point - the Sieve point
549: - size - The fiber dimension
551: Level: advanced
553: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
554: @*/
555: PetscErrorCode SectionRealSetFiberDimension(SectionReal section, PetscInt point, const PetscInt size)
556: {
559: section->s->setFiberDimension(point, size);
560: return(0);
561: }
565: /*@C
566: SectionRealAllocate - Allocate storage for this section
568: Not collective
570: Input Parameter:
571: . section - the section object
573: Level: advanced
575: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
576: @*/
577: PetscErrorCode SectionRealAllocate(SectionReal section)
578: {
581: section->b->allocate(section->s);
582: return(0);
583: }
587: /*@C
588: SectionRealCreateLocalVector - Creates a vector with the local piece of the Section
590: Collective on Mesh
592: Input Parameter:
593: . section - the Section
595: Output Parameter:
596: . localVec - the local vector
598: Level: advanced
600: .seealso MeshDestroy(), MeshCreate()
601: @*/
602: PetscErrorCode SectionRealCreateLocalVector(SectionReal section, Vec *localVec)
603: {
604: ALE::Obj<ALE::Mesh::real_section_type> s;
608: SectionRealGetSection(section, s);
609: VecCreateSeqWithArray(PETSC_COMM_SELF, s->sizeWithBC(), s->restrict(), localVec);
610: return(0);
611: }
615: /*@C
616: SectionRealToVec - Maps the given section to a Vec
618: Collective on Section
620: Input Parameters:
621: + section - the real Section
622: - mesh - The Mesh
624: Output Parameter:
625: . vec - the Vec
627: Level: intermediate
629: .seealso VecCreate(), SectionRealCreate()
630: @*/
631: PetscErrorCode SectionRealToVec(SectionReal section, Mesh mesh, ScatterMode mode, Vec vec)
632: {
633: Vec localVec;
634: VecScatter scatter;
639: SectionRealCreateLocalVector(section, &localVec);
640: MeshGetGlobalScatter(mesh, &scatter);
641: if (mode == SCATTER_FORWARD) {
642: VecScatterBegin(scatter, localVec, vec, INSERT_VALUES, mode);
643: VecScatterEnd(scatter, localVec, vec, INSERT_VALUES, mode);
644: } else {
645: VecScatterBegin(scatter, vec, localVec, INSERT_VALUES, mode);
646: VecScatterEnd(scatter, vec, localVec, INSERT_VALUES, mode);
647: }
648: VecDestroy(localVec);
649: return(0);
650: }
654: /*@C
655: SectionRealClear - Dellocate storage for this section
657: Not collective
659: Input Parameter:
660: . section - the section object
662: Level: advanced
664: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
665: @*/
666: PetscErrorCode SectionRealClear(SectionReal section)
667: {
670: section->s->clear();
671: return(0);
672: }
676: /*@C
677: SectionRealNorm - Computes the vector norm.
679: Collective on Section
681: Input Parameters:
682: + section - the real Section
683: - type - one of NORM_1, NORM_2, NORM_INFINITY. Also available
684: NORM_1_AND_2, which computes both norms and stores them
685: in a two element array.
687: Output Parameter:
688: . val - the norm
690: Notes:
691: $ NORM_1 denotes sum_i |x_i|
692: $ NORM_2 denotes sqrt(sum_i (x_i)^2)
693: $ NORM_INFINITY denotes max_i |x_i|
695: Level: intermediate
697: .seealso VecNorm(), SectionRealCreate()
698: @*/
699: PetscErrorCode SectionRealNorm(SectionReal section, Mesh mesh, NormType type, PetscReal *val)
700: {
701: Obj<ALE::Mesh> m;
702: Obj<ALE::Mesh::real_section_type> s;
703: Vec v;
708: MeshGetMesh(mesh, m);
709: SectionRealGetSection(section, s);
710: const ALE::Obj<ALE::Mesh::order_type>& order = m->getFactory()->getGlobalOrder(m, s->getName(), s);
711: VecCreate(m->comm(), &v);
712: VecSetSizes(v, order->getLocalSize(), order->getGlobalSize());
713: VecSetFromOptions(v);
714: SectionRealToVec(section, mesh, SCATTER_FORWARD, v);
715: VecNorm(v, type, val);
716: VecDestroy(v);
717: return(0);
718: }
722: /*@C
723: MeshGetVertexSectionReal - Create a Section over the vertices with the specified fiber dimension
725: Collective on Mesh
727: Input Parameters:
728: + mesh - The Mesh object
729: - fiberDim - The section name
731: Output Parameter:
732: . section - The section
734: Level: intermediate
736: .keywords: mesh, section, vertex
737: .seealso: MeshCreate(), SectionRealCreate()
738: @*/
739: PetscErrorCode MeshGetVertexSectionReal(Mesh mesh, PetscInt fiberDim, SectionReal *section)
740: {
741: ALE::Obj<ALE::Mesh> m;
742: ALE::Obj<ALE::Mesh::real_section_type> s;
743: PetscErrorCode ierr;
746: MeshGetMesh(mesh, m);
747: SectionRealCreate(m->comm(), section);
748: SectionRealSetBundle(*section, m);
749: SectionRealGetSection(*section, s);
750: s->setFiberDimension(m->depthStratum(0), fiberDim);
751: m->allocate(s);
752: return(0);
753: }
757: /*@C
758: MeshGetCellSectionReal - Create a Section over the cells with the specified fiber dimension
760: Collective on Mesh
762: Input Parameters:
763: + mesh - The Mesh object
764: - fiberDim - The section name
766: Output Parameter:
767: . section - The section
769: Level: intermediate
771: .keywords: mesh, section, cell
772: .seealso: MeshCreate(), SectionRealCreate()
773: @*/
774: PetscErrorCode MeshGetCellSectionReal(Mesh mesh, PetscInt fiberDim, SectionReal *section)
775: {
776: ALE::Obj<ALE::Mesh> m;
777: ALE::Obj<ALE::Mesh::real_section_type> s;
778: PetscErrorCode ierr;
781: MeshGetMesh(mesh, m);
782: SectionRealCreate(m->comm(), section);
783: SectionRealSetBundle(*section, m);
784: SectionRealGetSection(*section, s);
785: s->setFiberDimension(m->heightStratum(0), fiberDim);
786: m->allocate(s);
787: return(0);
788: }
792: PetscErrorCode SectionIntView_Sieve(SectionInt section, PetscViewer viewer)
793: {
794: PetscTruth iascii, isbinary, isdraw;
798: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_ASCII, &iascii);
799: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &isbinary);
800: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_DRAW, &isdraw);
802: if (iascii){
803: ALE::Obj<ALE::Mesh::int_section_type> s;
804: ALE::Obj<ALE::Mesh> b;
805: const char *name;
807: SectionIntGetSection(section, s);
808: SectionIntGetBundle(section, b);
809: PetscObjectGetName((PetscObject) section, &name);
810: SectionView_Sieve_Ascii(b, s, name, viewer);
811: } else if (isbinary) {
812: SETERRQ(PETSC_ERR_SUP, "Binary viewer not implemented for Section");
813: } else if (isdraw){
814: SETERRQ(PETSC_ERR_SUP, "Draw viewer not implemented for Section");
815: } else {
816: SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported by this section object", ((PetscObject)viewer)->type_name);
817: }
818: return(0);
819: }
823: /*@C
824: SectionIntView - Views a Section object.
826: Collective on Section
828: Input Parameters:
829: + section - the Section
830: - viewer - an optional visualization context
832: Notes:
833: The available visualization contexts include
834: + PETSC_VIEWER_STDOUT_SELF - standard output (default)
835: - PETSC_VIEWER_STDOUT_WORLD - synchronized standard
836: output where only the first processor opens
837: the file. All other processors send their
838: data to the first processor to print.
840: You can change the format the section is printed using the
841: option PetscViewerSetFormat().
843: The user can open alternative visualization contexts with
844: + PetscViewerASCIIOpen() - Outputs section to a specified file
845: . PetscViewerBinaryOpen() - Outputs section in binary to a
846: specified file; corresponding input uses SectionLoad()
847: . PetscViewerDrawOpen() - Outputs section to an X window display
849: The user can call PetscViewerSetFormat() to specify the output
850: format of ASCII printed objects (when using PETSC_VIEWER_STDOUT_SELF,
851: PETSC_VIEWER_STDOUT_WORLD and PetscViewerASCIIOpen). Available formats include
852: + PETSC_VIEWER_ASCII_DEFAULT - default, prints section information
853: - PETSC_VIEWER_ASCII_VTK - outputs a VTK file describing the section
855: Level: beginner
857: Concepts: section^printing
858: Concepts: section^saving to disk
860: .seealso: VecView(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerBinaryOpen(), PetscViewerCreate()
861: @*/
862: PetscErrorCode SectionIntView(SectionInt section, PetscViewer viewer)
863: {
869: if (!viewer) {
870: PetscViewerASCIIGetStdout(section->comm,&viewer);
871: }
876: (*section->ops->view)(section, viewer);
878: return(0);
879: }
883: /*@C
884: SectionIntGetSection - Gets the internal section object
886: Not collective
888: Input Parameter:
889: . section - the section object
891: Output Parameter:
892: . s - the internal section object
893:
894: Level: advanced
896: .seealso SectionIntCreate(), SectionIntSetSection()
897: @*/
898: PetscErrorCode SectionIntGetSection(SectionInt section, ALE::Obj<ALE::Mesh::int_section_type>& s)
899: {
902: s = section->s;
903: return(0);
904: }
908: /*@C
909: SectionIntSetSection - Sets the internal section object
911: Not collective
913: Input Parameters:
914: + section - the section object
915: - s - the internal section object
916:
917: Level: advanced
919: .seealso SectionIntCreate(), SectionIntGetSection()
920: @*/
921: PetscErrorCode SectionIntSetSection(SectionInt section, const ALE::Obj<ALE::Mesh::int_section_type>& s)
922: {
925: section->s = s;
926: return(0);
927: }
931: /*@C
932: SectionIntGetBundle - Gets the section bundle
934: Not collective
936: Input Parameter:
937: . section - the section object
939: Output Parameter:
940: . b - the section bundle
941:
942: Level: advanced
944: .seealso SectionIntCreate(), SectionIntGetSection(), SectionIntSetSection()
945: @*/
946: PetscErrorCode SectionIntGetBundle(SectionInt section, ALE::Obj<ALE::Mesh>& b)
947: {
950: b = section->b;
951: return(0);
952: }
956: /*@C
957: SectionIntSetBundle - Sets the section bundle
959: Not collective
961: Input Parameters:
962: + section - the section object
963: - b - the section bundle
964:
965: Level: advanced
967: .seealso SectionIntCreate(), SectionIntGetSection(), SectionIntSetSection()
968: @*/
969: PetscErrorCode SectionIntSetBundle(SectionInt section, const ALE::Obj<ALE::Mesh>& b)
970: {
973: section->b = b;
974: return(0);
975: }
979: /*@C
980: SectionIntCreate - Creates a Section object, used to manage data for an unstructured problem
981: described by a Sieve.
983: Collective on MPI_Comm
985: Input Parameter:
986: . comm - the processors that will share the global section
988: Output Parameters:
989: . section - the section object
991: Level: advanced
993: .seealso SectionIntDestroy(), SectionIntView()
994: @*/
995: PetscErrorCode SectionIntCreate(MPI_Comm comm, SectionInt *section)
996: {
998: SectionInt s;
1002: *section = PETSC_NULL;
1004: PetscHeaderCreate(s,_p_SectionInt,struct _SectionIntOps,SECTIONINT_COOKIE,0,"SectionInt",comm,SectionIntDestroy,0);
1005: s->ops->view = SectionIntView_Sieve;
1006: s->ops->restrict = SectionIntRestrict;
1007: s->ops->update = SectionIntUpdate;
1009: PetscObjectChangeTypeName((PetscObject) s, "sieve");
1011: s->s = new ALE::Mesh::int_section_type(comm);
1012: *section = s;
1013: return(0);
1014: }
1018: /*@C
1019: SectionIntDestroy - Destroys a section.
1021: Collective on Section
1023: Input Parameter:
1024: . section - the section object
1026: Level: advanced
1028: .seealso SectionIntCreate(), SectionIntView()
1029: @*/
1030: PetscErrorCode SectionIntDestroy(SectionInt section)
1031: {
1036: if (--section->refct > 0) return(0);
1037: section->s = PETSC_NULL;
1038: PetscHeaderDestroy(section);
1039: return(0);
1040: }
1044: /*@C
1045: SectionIntDistribute - Distributes the sections.
1047: Not Collective
1049: Input Parameters:
1050: + serialSection - The original Section object
1051: - parallelMesh - The parallel Mesh
1053: Output Parameter:
1054: . parallelSection - The distributed Section object
1056: Level: intermediate
1058: .keywords: mesh, section, distribute
1059: .seealso: MeshCreate()
1060: @*/
1061: PetscErrorCode SectionIntDistribute(SectionInt serialSection, Mesh parallelMesh, SectionInt *parallelSection)
1062: {
1063: ALE::Obj<ALE::Mesh::int_section_type> oldSection;
1064: ALE::Obj<ALE::Mesh> m;
1065: PetscErrorCode ierr;
1068: SectionIntGetSection(serialSection, oldSection);
1069: MeshGetMesh(parallelMesh, m);
1070: SectionIntCreate(oldSection->comm(), parallelSection);
1071: ALE::Obj<ALE::Mesh::int_section_type> newSection = ALE::Distribution<ALE::Mesh>::distributeSection(oldSection, m, m->getDistSendOverlap(), m->getDistRecvOverlap());
1072: SectionIntSetSection(*parallelSection, newSection);
1073: return(0);
1074: }
1078: /*@C
1079: SectionIntRestrict - Restricts the SectionInt to a subset of the topology, returning an array of values.
1081: Not collective
1083: Input Parameters:
1084: + section - the section object
1085: - point - the Sieve point
1087: Output Parameter:
1088: . values - The values associated with the submesh
1090: Level: advanced
1092: .seealso SectionIntUpdate(), SectionIntCreate(), SectionIntView()
1093: @*/
1094: PetscErrorCode SectionIntRestrict(SectionInt section, PetscInt point, PetscInt *values[])
1095: {
1099: *values = (PetscInt *) section->b->restrict(section->s, point);
1100: return(0);
1101: }
1105: /*@C
1106: SectionIntUpdate - Updates the array of values associated to a subset of the topology in this Section.
1108: Not collective
1110: Input Parameters:
1111: + section - the section object
1112: . point - the Sieve point
1113: - values - The values associated with the submesh
1115: Level: advanced
1117: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1118: @*/
1119: PetscErrorCode SectionIntUpdate(SectionInt section, PetscInt point, const PetscInt values[])
1120: {
1124: section->b->update(section->s, point, values);
1125: return(0);
1126: }
1130: /*@C
1131: SectionIntUpdateAdd - Updates the array of values associated to a subset of the topology in this Section.
1133: Not collective
1135: Input Parameters:
1136: + section - the section object
1137: . point - the Sieve point
1138: - values - The values associated with the submesh
1140: Level: advanced
1142: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1143: @*/
1144: PetscErrorCode SectionIntUpdateAdd(SectionInt section, PetscInt point, const PetscInt values[])
1145: {
1149: section->b->updateAdd(section->s, point, values);
1150: return(0);
1151: }
1155: /*@C
1156: SectionIntComplete - Exchanges data across the mesh overlap.
1158: Not collective
1160: Input Parameter:
1161: . section - the section object
1163: Level: advanced
1165: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1166: @*/
1167: PetscErrorCode SectionIntComplete(SectionInt section)
1168: {
1169: Obj<ALE::Mesh::int_section_type> s;
1170: Obj<ALE::Mesh> b;
1174: SectionIntGetSection(section, s);
1175: SectionIntGetBundle(section, b);
1176: ALE::Distribution<ALE::Mesh>::completeSection(b, s);
1177: return(0);
1178: }
1182: /*@C
1183: SectionIntSetFiberDimension - Set the size of the vector space attached to the point
1185: Not collective
1187: Input Parameters:
1188: + section - the section object
1189: . point - the Sieve point
1190: - size - The fiber dimension
1192: Level: advanced
1194: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1195: @*/
1196: PetscErrorCode SectionIntSetFiberDimension(SectionInt section, PetscInt point, const PetscInt size)
1197: {
1200: section->s->setFiberDimension(point, size);
1201: return(0);
1202: }
1206: /*@C
1207: SectionIntAllocate - Allocate storage for this section
1209: Not collective
1211: Input Parameter:
1212: . section - the section object
1214: Level: advanced
1216: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1217: @*/
1218: PetscErrorCode SectionIntAllocate(SectionInt section)
1219: {
1222: section->b->allocate(section->s);
1223: return(0);
1224: }
1228: /*@C
1229: SectionIntClear - Dellocate storage for this section
1231: Not collective
1233: Input Parameter:
1234: . section - the section object
1236: Level: advanced
1238: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1239: @*/
1240: PetscErrorCode SectionIntClear(SectionInt section)
1241: {
1244: section->s->clear();
1245: return(0);
1246: }
1250: /*@C
1251: MeshGetVertexSectionInt - Create a Section over the vertices with the specified fiber dimension
1253: Collective on Mesh
1255: Input Parameters:
1256: + mesh - The Mesh object
1257: - fiberDim - The section name
1259: Output Parameter:
1260: . section - The section
1262: Level: intermediate
1264: .keywords: mesh, section, vertex
1265: .seealso: MeshCreate(), SectionIntCreate()
1266: @*/
1267: PetscErrorCode MeshGetVertexSectionInt(Mesh mesh, PetscInt fiberDim, SectionInt *section)
1268: {
1269: ALE::Obj<ALE::Mesh> m;
1270: ALE::Obj<ALE::Mesh::int_section_type> s;
1271: PetscErrorCode ierr;
1274: MeshGetMesh(mesh, m);
1275: SectionIntCreate(m->comm(), section);
1276: SectionIntSetBundle(*section, m);
1277: SectionIntGetSection(*section, s);
1278: s->setFiberDimension(m->depthStratum(0), fiberDim);
1279: m->allocate(s);
1280: return(0);
1281: }
1285: /*@C
1286: MeshGetCellSectionInt - Create a Section over the cells with the specified fiber dimension
1288: Collective on Mesh
1290: Input Parameters:
1291: + mesh - The Mesh object
1292: - fiberDim - The section name
1294: Output Parameter:
1295: . section - The section
1297: Level: intermediate
1299: .keywords: mesh, section, cell
1300: .seealso: MeshCreate(), SectionIntCreate()
1301: @*/
1302: PetscErrorCode MeshGetCellSectionInt(Mesh mesh, PetscInt fiberDim, SectionInt *section)
1303: {
1304: ALE::Obj<ALE::Mesh> m;
1305: ALE::Obj<ALE::Mesh::int_section_type> s;
1306: PetscErrorCode ierr;
1309: MeshGetMesh(mesh, m);
1310: SectionIntCreate(m->comm(), section);
1311: SectionIntSetBundle(*section, m);
1312: SectionIntGetSection(*section, s);
1313: s->setFiberDimension(m->heightStratum(0), fiberDim);
1314: m->allocate(s);
1315: return(0);
1316: }