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 = 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: 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<ALE::Mesh::real_section_type> s;
26: ALE::Obj<ALE::Mesh> 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_ASCII_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: }
98: (*section->ops->view)(section, viewer);
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<ALE::Mesh::real_section_type>& s = section->s;
128: ALE::Obj<ALE::Mesh::real_section_type> t = new ALE::Mesh::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<ALE::Mesh::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<ALE::Mesh::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<ALE::Mesh>& 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<ALE::Mesh>& 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->restrict = SectionRealRestrict;
268: s->ops->update = SectionRealUpdate;
270: PetscObjectChangeTypeName((PetscObject) s, "sieve");
272: s->s = new ALE::Mesh::real_section_type(comm);
273: *section = s;
274: return(0);
275: }
279: /*@C
280: SectionRealDestroy - Destroys a section.
282: Collective on Section
284: Input Parameter:
285: . section - the section object
287: Level: advanced
289: .seealso SectionRealCreate(), SectionRealView()
290: @*/
291: PetscErrorCode SectionRealDestroy(SectionReal section)
292: {
297: if (--((PetscObject)section)->refct > 0) return(0);
298: section->s = PETSC_NULL;
299: PetscHeaderDestroy(section);
300: return(0);
301: }
305: /*@C
306: SectionRealDistribute - Distributes the sections.
308: Not Collective
310: Input Parameters:
311: + serialSection - The original Section object
312: - parallelMesh - The parallel Mesh
314: Output Parameter:
315: . parallelSection - The distributed Section object
317: Level: intermediate
319: .keywords: mesh, section, distribute
320: .seealso: MeshCreate()
321: @*/
322: PetscErrorCode SectionRealDistribute(SectionReal serialSection, Mesh parallelMesh, SectionReal *parallelSection)
323: {
324: ALE::Obj<ALE::Mesh::real_section_type> oldSection;
325: ALE::Obj<ALE::Mesh> m;
329: SectionRealGetSection(serialSection, oldSection);
330: MeshGetMesh(parallelMesh, m);
331: SectionRealCreate(oldSection->comm(), parallelSection);
332: ALE::Obj<ALE::Mesh::real_section_type> newSection = ALE::Distribution<ALE::Mesh>::distributeSection(oldSection, m, m->getDistSendOverlap(), m->getDistRecvOverlap());
333: SectionRealSetSection(*parallelSection, newSection);
334: return(0);
335: }
339: /*@C
340: SectionRealRestrict - Restricts the SectionReal to a subset of the topology, returning an array of values.
342: Not collective
344: Input Parameters:
345: + section - the section object
346: - point - the Sieve point
348: Output Parameter:
349: . values - The values associated with the submesh
351: Level: advanced
353: .seealso SectionUpdate(), SectionCreate(), SectionView()
354: @*/
355: PetscErrorCode SectionRealRestrict(SectionReal section, PetscInt point, PetscScalar *values[])
356: {
360: *values = (PetscScalar *) section->b->restrict(section->s, point);
361: return(0);
362: }
366: /*@C
367: SectionRealUpdate - Updates the array of values associated to a subset of the topology in this Section.
369: Not collective
371: Input Parameters:
372: + section - the section object
373: . point - the Sieve point
374: - values - The values associated with the submesh
376: Level: advanced
378: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
379: @*/
380: PetscErrorCode SectionRealUpdate(SectionReal section, PetscInt point, const PetscScalar values[])
381: {
385: section->b->update(section->s, point, values);
386: return(0);
387: }
391: /*@C
392: SectionRealUpdateAdd - Updates the array of values associated to a subset of the topology in this Section.
394: Not collective
396: Input Parameters:
397: + section - the section object
398: . point - the Sieve point
399: - values - The values associated with the submesh
401: Level: advanced
403: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
404: @*/
405: PetscErrorCode SectionRealUpdateAdd(SectionReal section, PetscInt point, const PetscScalar values[])
406: {
410: section->b->updateAdd(section->s, point, values);
411: return(0);
412: }
416: /*@C
417: SectionRealComplete - Exchanges data across the mesh overlap.
419: Not collective
421: Input Parameter:
422: . section - the section object
424: Level: advanced
426: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
427: @*/
428: PetscErrorCode SectionRealComplete(SectionReal section)
429: {
430: Obj<ALE::Mesh::real_section_type> s;
431: Obj<ALE::Mesh> b;
435: SectionRealGetSection(section, s);
436: SectionRealGetBundle(section, b);
437: ALE::Distribution<ALE::Mesh>::completeSection(b, s);
438: return(0);
439: }
443: /*@C
444: SectionRealZero - Zero out the entries
446: Not collective
448: Input Parameter:
449: . section - the section object
451: Level: advanced
453: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
454: @*/
455: PetscErrorCode SectionRealZero(SectionReal section)
456: {
457: Obj<ALE::Mesh::real_section_type> s;
461: SectionRealGetSection(section, s);
462: s->zero();
463: return(0);
464: }
468: /*@C
469: SectionRealSetFiberDimension - Set the size of the vector space attached to the point
471: Not collective
473: Input Parameters:
474: + section - the section object
475: . point - the Sieve point
476: - size - The fiber dimension
478: Level: advanced
480: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
481: @*/
482: PetscErrorCode SectionRealSetFiberDimension(SectionReal section, PetscInt point, const PetscInt size)
483: {
486: section->s->setFiberDimension(point, size);
487: return(0);
488: }
492: /*@C
493: SectionRealAllocate - Allocate storage for this section
495: Not collective
497: Input Parameter:
498: . section - the section object
500: Level: advanced
502: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
503: @*/
504: PetscErrorCode SectionRealAllocate(SectionReal section)
505: {
508: section->b->allocate(section->s);
509: return(0);
510: }
514: /*@C
515: SectionRealCreateLocalVector - Creates a vector with the local piece of the Section
517: Collective on Mesh
519: Input Parameter:
520: . section - the Section
522: Output Parameter:
523: . localVec - the local vector
525: Level: advanced
527: .seealso MeshDestroy(), MeshCreate()
528: @*/
529: PetscErrorCode SectionRealCreateLocalVector(SectionReal section, Vec *localVec)
530: {
531: ALE::Obj<ALE::Mesh::real_section_type> s;
535: SectionRealGetSection(section, s);
536: VecCreateSeqWithArray(PETSC_COMM_SELF, s->getStorageSize(), s->restrict(), localVec);
537: return(0);
538: }
542: /*@C
543: SectionRealToVec - Maps the given section to a Vec
545: Collective on Section
547: Input Parameters:
548: + section - the real Section
549: - mesh - The Mesh
551: Output Parameter:
552: . vec - the Vec
554: Level: intermediate
556: .seealso VecCreate(), SectionRealCreate()
557: @*/
558: PetscErrorCode SectionRealToVec(SectionReal section, Mesh mesh, ScatterMode mode, Vec vec)
559: {
560: Vec localVec;
561: VecScatter scatter;
566: SectionRealCreateLocalVector(section, &localVec);
567: MeshGetGlobalScatter(mesh, &scatter);
568: if (mode == SCATTER_FORWARD) {
569: VecScatterBegin(scatter, localVec, vec, INSERT_VALUES, mode);
570: VecScatterEnd(scatter, localVec, vec, INSERT_VALUES, mode);
571: } else {
572: VecScatterBegin(scatter, vec, localVec, INSERT_VALUES, mode);
573: VecScatterEnd(scatter, vec, localVec, INSERT_VALUES, mode);
574: }
575: VecDestroy(localVec);
576: return(0);
577: }
579: PetscErrorCode SectionRealToVec(SectionReal section, Mesh mesh, VecScatter scatter, ScatterMode mode, Vec vec)
580: {
581: Vec localVec;
586: SectionRealCreateLocalVector(section, &localVec);
587: if (mode == SCATTER_FORWARD) {
588: VecScatterBegin(scatter, localVec, vec, INSERT_VALUES, mode);
589: VecScatterEnd(scatter, localVec, vec, INSERT_VALUES, mode);
590: } else {
591: VecScatterBegin(scatter, vec, localVec, INSERT_VALUES, mode);
592: VecScatterEnd(scatter, vec, localVec, INSERT_VALUES, mode);
593: }
594: VecDestroy(localVec);
595: return(0);
596: }
600: /*@C
601: SectionRealClear - Dellocate storage for this section
603: Not collective
605: Input Parameter:
606: . section - the section object
608: Level: advanced
610: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
611: @*/
612: PetscErrorCode SectionRealClear(SectionReal section)
613: {
616: section->s->clear();
617: return(0);
618: }
622: /*@C
623: SectionRealNorm - Computes the vector norm.
625: Collective on Section
627: Input Parameters:
628: + section - the real Section
629: - type - one of NORM_1, NORM_2, NORM_INFINITY. Also available
630: NORM_1_AND_2, which computes both norms and stores them
631: in a two element array.
633: Output Parameter:
634: . val - the norm
636: Notes:
637: $ NORM_1 denotes sum_i |x_i|
638: $ NORM_2 denotes sqrt(sum_i (x_i)^2)
639: $ NORM_INFINITY denotes max_i |x_i|
641: Level: intermediate
643: .seealso VecNorm(), SectionRealCreate()
644: @*/
645: PetscErrorCode SectionRealNorm(SectionReal section, Mesh mesh, NormType type, PetscReal *val)
646: {
647: Obj<ALE::Mesh> m;
648: Obj<ALE::Mesh::real_section_type> s;
649: Vec v;
654: MeshGetMesh(mesh, m);
655: SectionRealGetSection(section, s);
656: const ALE::Obj<ALE::Mesh::order_type>& order = m->getFactory()->getGlobalOrder(m, s->getName(), s);
657: VecCreate(m->comm(), &v);
658: VecSetSizes(v, order->getLocalSize(), order->getGlobalSize());
659: VecSetFromOptions(v);
660: SectionRealToVec(section, mesh, SCATTER_FORWARD, v);
661: VecNorm(v, type, val);
662: VecDestroy(v);
663: return(0);
664: }
668: /*@C
669: SectionRealAXPY -
671: Collective on Section
673: Input Parameters:
674: + section - the real Section
675: . alpha - a scalar
676: - X - the other real Section
678: Output Parameter:
679: . section - the difference
681: Level: intermediate
683: .seealso VecNorm(), SectionRealCreate()
684: @*/
685: PetscErrorCode SectionRealAXPY(SectionReal section, Mesh mesh, PetscScalar alpha, SectionReal X)
686: {
687: Obj<ALE::Mesh> m;
688: Obj<ALE::Mesh::real_section_type> s;
689: Obj<ALE::Mesh::real_section_type> sX;
690: Vec v, x;
695: MeshGetMesh(mesh, m);
696: SectionRealGetSection(section, s);
697: SectionRealGetSection(X, sX);
698: const ALE::Obj<ALE::Mesh::order_type>& order = m->getFactory()->getGlobalOrder(m, s->getName(), s);
699: VecCreate(m->comm(), &v);
700: VecSetSizes(v, order->getLocalSize(), order->getGlobalSize());
701: VecSetFromOptions(v);
702: VecDuplicate(v, &x);
703: SectionRealToVec(section, mesh, SCATTER_FORWARD, v);
704: SectionRealToVec(X, mesh, SCATTER_FORWARD, x);
705: VecAXPY(v, alpha, x);
706: SectionRealToVec(section, mesh, SCATTER_REVERSE, v);
707: VecDestroy(v);
708: VecDestroy(x);
709: return(0);
710: }
714: /*@C
715: MeshGetVertexSectionReal - Create a Section over the vertices with the specified fiber dimension
717: Collective on Mesh
719: Input Parameters:
720: + mesh - The Mesh object
721: - fiberDim - The section name
723: Output Parameter:
724: . section - The section
726: Level: intermediate
728: .keywords: mesh, section, vertex
729: .seealso: MeshCreate(), SectionRealCreate()
730: @*/
731: PetscErrorCode MeshGetVertexSectionReal(Mesh mesh, PetscInt fiberDim, SectionReal *section)
732: {
733: ALE::Obj<ALE::Mesh> m;
734: ALE::Obj<ALE::Mesh::real_section_type> s;
735: PetscErrorCode ierr;
738: MeshGetMesh(mesh, m);
739: SectionRealCreate(m->comm(), section);
740: SectionRealSetBundle(*section, m);
741: SectionRealGetSection(*section, s);
742: s->setFiberDimension(m->depthStratum(0), fiberDim);
743: m->allocate(s);
744: return(0);
745: }
749: /*@C
750: MeshGetCellSectionReal - Create a Section over the cells with the specified fiber dimension
752: Collective on Mesh
754: Input Parameters:
755: + mesh - The Mesh object
756: - fiberDim - The section name
758: Output Parameter:
759: . section - The section
761: Level: intermediate
763: .keywords: mesh, section, cell
764: .seealso: MeshCreate(), SectionRealCreate()
765: @*/
766: PetscErrorCode MeshGetCellSectionReal(Mesh mesh, PetscInt fiberDim, SectionReal *section)
767: {
768: ALE::Obj<ALE::Mesh> m;
769: ALE::Obj<ALE::Mesh::real_section_type> s;
770: PetscErrorCode ierr;
773: MeshGetMesh(mesh, m);
774: SectionRealCreate(m->comm(), section);
775: SectionRealSetBundle(*section, m);
776: SectionRealGetSection(*section, s);
777: s->setFiberDimension(m->heightStratum(0), fiberDim);
778: m->allocate(s);
779: return(0);
780: }
784: /*@C
785: MeshCreateGlobalRealVector - Creates a vector of the correct size to be gathered into
786: by the mesh.
788: Collective on Mesh
790: Input Parameters:
791: + mesh - the mesh object
792: - section - The SectionReal
794: Output Parameters:
795: . gvec - the global vector
797: Level: advanced
799: .seealso MeshDestroy(), MeshCreate(), MeshCreateGlobalVector()
801: @*/
802: PetscErrorCode MeshCreateGlobalRealVector(Mesh mesh, SectionReal section, Vec *gvec)
803: {
804: ALE::Obj<ALE::Mesh> m;
805: ALE::Obj<ALE::Mesh::real_section_type> s;
806: const char *name;
810: MeshGetMesh(mesh, m);
811: SectionRealGetSection(section, s);
812: PetscObjectGetName((PetscObject) section, &name);
813: const ALE::Obj<ALE::Mesh::order_type>& order = m->getFactory()->getGlobalOrder(m, name, s);
815: VecCreate(m->comm(), gvec);
816: VecSetSizes(*gvec, order->getLocalSize(), order->getGlobalSize());
817: VecSetFromOptions(*gvec);
818: return(0);
819: }
823: PetscErrorCode SectionIntView_Sieve(SectionInt section, PetscViewer viewer)
824: {
825: PetscTruth iascii, isbinary, isdraw;
829: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_ASCII, &iascii);
830: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &isbinary);
831: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_DRAW, &isdraw);
833: if (iascii){
834: ALE::Obj<ALE::Mesh::int_section_type> s;
835: ALE::Obj<ALE::Mesh> b;
836: const char *name;
838: SectionIntGetSection(section, s);
839: SectionIntGetBundle(section, b);
840: PetscObjectGetName((PetscObject) section, &name);
841: SectionView_Sieve_Ascii(b, s, name, viewer);
842: } else if (isbinary) {
843: SETERRQ(PETSC_ERR_SUP, "Binary viewer not implemented for Section");
844: } else if (isdraw){
845: SETERRQ(PETSC_ERR_SUP, "Draw viewer not implemented for Section");
846: } else {
847: SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported by this section object", ((PetscObject)viewer)->type_name);
848: }
849: return(0);
850: }
854: /*@C
855: SectionIntView - Views a Section object.
857: Collective on Section
859: Input Parameters:
860: + section - the Section
861: - viewer - an optional visualization context
863: Notes:
864: The available visualization contexts include
865: + PETSC_VIEWER_STDOUT_SELF - standard output (default)
866: - PETSC_VIEWER_STDOUT_WORLD - synchronized standard
867: output where only the first processor opens
868: the file. All other processors send their
869: data to the first processor to print.
871: You can change the format the section is printed using the
872: option PetscViewerSetFormat().
874: The user can open alternative visualization contexts with
875: + PetscViewerASCIIOpen() - Outputs section to a specified file
876: . PetscViewerBinaryOpen() - Outputs section in binary to a
877: specified file; corresponding input uses SectionLoad()
878: . PetscViewerDrawOpen() - Outputs section to an X window display
880: The user can call PetscViewerSetFormat() to specify the output
881: format of ASCII printed objects (when using PETSC_VIEWER_STDOUT_SELF,
882: PETSC_VIEWER_STDOUT_WORLD and PetscViewerASCIIOpen). Available formats include
883: + PETSC_VIEWER_ASCII_DEFAULT - default, prints section information
884: - PETSC_VIEWER_ASCII_VTK - outputs a VTK file describing the section
886: Level: beginner
888: Concepts: section^printing
889: Concepts: section^saving to disk
891: .seealso: VecView(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerBinaryOpen(), PetscViewerCreate()
892: @*/
893: PetscErrorCode SectionIntView(SectionInt section, PetscViewer viewer)
894: {
900: if (!viewer) {
901: PetscViewerASCIIGetStdout(((PetscObject)section)->comm,&viewer);
902: }
907: (*section->ops->view)(section, viewer);
909: return(0);
910: }
914: /*@C
915: SectionIntGetSection - Gets the internal section object
917: Not collective
919: Input Parameter:
920: . section - the section object
922: Output Parameter:
923: . s - the internal section object
924:
925: Level: advanced
927: .seealso SectionIntCreate(), SectionIntSetSection()
928: @*/
929: PetscErrorCode SectionIntGetSection(SectionInt section, ALE::Obj<ALE::Mesh::int_section_type>& s)
930: {
933: s = section->s;
934: return(0);
935: }
939: /*@C
940: SectionIntSetSection - Sets the internal section object
942: Not collective
944: Input Parameters:
945: + section - the section object
946: - s - the internal section object
947:
948: Level: advanced
950: .seealso SectionIntCreate(), SectionIntGetSection()
951: @*/
952: PetscErrorCode SectionIntSetSection(SectionInt section, const ALE::Obj<ALE::Mesh::int_section_type>& s)
953: {
958: if (!s.isNull()) {PetscObjectSetName((PetscObject) section, s->getName().c_str());}
959: section->s = s;
960: return(0);
961: }
965: /*@C
966: SectionIntGetBundle - Gets the section bundle
968: Not collective
970: Input Parameter:
971: . section - the section object
973: Output Parameter:
974: . b - the section bundle
975:
976: Level: advanced
978: .seealso SectionIntCreate(), SectionIntGetSection(), SectionIntSetSection()
979: @*/
980: PetscErrorCode SectionIntGetBundle(SectionInt section, ALE::Obj<ALE::Mesh>& b)
981: {
984: b = section->b;
985: return(0);
986: }
990: /*@C
991: SectionIntSetBundle - Sets the section bundle
993: Not collective
995: Input Parameters:
996: + section - the section object
997: - b - the section bundle
998:
999: Level: advanced
1001: .seealso SectionIntCreate(), SectionIntGetSection(), SectionIntSetSection()
1002: @*/
1003: PetscErrorCode SectionIntSetBundle(SectionInt section, const ALE::Obj<ALE::Mesh>& b)
1004: {
1007: section->b = b;
1008: return(0);
1009: }
1013: /*@C
1014: SectionIntCreate - Creates a Section object, used to manage data for an unstructured problem
1015: described by a Sieve.
1017: Collective on MPI_Comm
1019: Input Parameter:
1020: . comm - the processors that will share the global section
1022: Output Parameters:
1023: . section - the section object
1025: Level: advanced
1027: .seealso SectionIntDestroy(), SectionIntView()
1028: @*/
1029: PetscErrorCode SectionIntCreate(MPI_Comm comm, SectionInt *section)
1030: {
1032: SectionInt s;
1036: *section = PETSC_NULL;
1038: PetscHeaderCreate(s,_p_SectionInt,struct _SectionIntOps,SECTIONINT_COOKIE,0,"SectionInt",comm,SectionIntDestroy,0);
1039: s->ops->view = SectionIntView_Sieve;
1040: s->ops->restrict = SectionIntRestrict;
1041: s->ops->update = SectionIntUpdate;
1043: PetscObjectChangeTypeName((PetscObject) s, "sieve");
1045: s->s = new ALE::Mesh::int_section_type(comm);
1046: *section = s;
1047: return(0);
1048: }
1052: /*@C
1053: SectionIntDestroy - Destroys a section.
1055: Collective on Section
1057: Input Parameter:
1058: . section - the section object
1060: Level: advanced
1062: .seealso SectionIntCreate(), SectionIntView()
1063: @*/
1064: PetscErrorCode SectionIntDestroy(SectionInt section)
1065: {
1070: if (--((PetscObject)section)->refct > 0) return(0);
1071: section->s = PETSC_NULL;
1072: PetscHeaderDestroy(section);
1073: return(0);
1074: }
1078: /*@C
1079: SectionIntDistribute - Distributes the sections.
1081: Not Collective
1083: Input Parameters:
1084: + serialSection - The original Section object
1085: - parallelMesh - The parallel Mesh
1087: Output Parameter:
1088: . parallelSection - The distributed Section object
1090: Level: intermediate
1092: .keywords: mesh, section, distribute
1093: .seealso: MeshCreate()
1094: @*/
1095: PetscErrorCode SectionIntDistribute(SectionInt serialSection, Mesh parallelMesh, SectionInt *parallelSection)
1096: {
1097: ALE::Obj<ALE::Mesh::int_section_type> oldSection;
1098: ALE::Obj<ALE::Mesh> m;
1099: PetscErrorCode ierr;
1102: SectionIntGetSection(serialSection, oldSection);
1103: MeshGetMesh(parallelMesh, m);
1104: SectionIntCreate(oldSection->comm(), parallelSection);
1105: ALE::Obj<ALE::Mesh::int_section_type> newSection = ALE::Distribution<ALE::Mesh>::distributeSection(oldSection, m, m->getDistSendOverlap(), m->getDistRecvOverlap());
1106: SectionIntSetSection(*parallelSection, newSection);
1107: return(0);
1108: }
1112: /*@C
1113: SectionIntRestrict - Restricts the SectionInt to a subset of the topology, returning an array of values.
1115: Not collective
1117: Input Parameters:
1118: + section - the section object
1119: - point - the Sieve point
1121: Output Parameter:
1122: . values - The values associated with the submesh
1124: Level: advanced
1126: .seealso SectionIntUpdate(), SectionIntCreate(), SectionIntView()
1127: @*/
1128: PetscErrorCode SectionIntRestrict(SectionInt section, PetscInt point, PetscInt *values[])
1129: {
1133: *values = (PetscInt *) section->b->restrict(section->s, point);
1134: return(0);
1135: }
1139: /*@C
1140: SectionIntUpdate - Updates the array of values associated to a subset of the topology in this Section.
1142: Not collective
1144: Input Parameters:
1145: + section - the section object
1146: . point - the Sieve point
1147: - values - The values associated with the submesh
1149: Level: advanced
1151: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1152: @*/
1153: PetscErrorCode SectionIntUpdate(SectionInt section, PetscInt point, const PetscInt values[])
1154: {
1158: section->b->update(section->s, point, values);
1159: return(0);
1160: }
1164: /*@C
1165: SectionIntUpdateAdd - Updates the array of values associated to a subset of the topology in this Section.
1167: Not collective
1169: Input Parameters:
1170: + section - the section object
1171: . point - the Sieve point
1172: - values - The values associated with the submesh
1174: Level: advanced
1176: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1177: @*/
1178: PetscErrorCode SectionIntUpdateAdd(SectionInt section, PetscInt point, const PetscInt values[])
1179: {
1183: section->b->updateAdd(section->s, point, values);
1184: return(0);
1185: }
1189: /*@C
1190: SectionIntComplete - Exchanges data across the mesh overlap.
1192: Not collective
1194: Input Parameter:
1195: . section - the section object
1197: Level: advanced
1199: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1200: @*/
1201: PetscErrorCode SectionIntComplete(SectionInt section)
1202: {
1203: Obj<ALE::Mesh::int_section_type> s;
1204: Obj<ALE::Mesh> b;
1208: SectionIntGetSection(section, s);
1209: SectionIntGetBundle(section, b);
1210: ALE::Distribution<ALE::Mesh>::completeSection(b, s);
1211: return(0);
1212: }
1216: /*@C
1217: SectionIntSetFiberDimension - Set the size of the vector space attached to the point
1219: Not collective
1221: Input Parameters:
1222: + section - the section object
1223: . point - the Sieve point
1224: - size - The fiber dimension
1226: Level: advanced
1228: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1229: @*/
1230: PetscErrorCode SectionIntSetFiberDimension(SectionInt section, PetscInt point, const PetscInt size)
1231: {
1234: section->s->setFiberDimension(point, size);
1235: return(0);
1236: }
1240: /*@C
1241: SectionIntAllocate - Allocate storage for this section
1243: Not collective
1245: Input Parameter:
1246: . section - the section object
1248: Level: advanced
1250: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1251: @*/
1252: PetscErrorCode SectionIntAllocate(SectionInt section)
1253: {
1256: section->b->allocate(section->s);
1257: return(0);
1258: }
1262: /*@C
1263: SectionIntClear - Dellocate storage for this section
1265: Not collective
1267: Input Parameter:
1268: . section - the section object
1270: Level: advanced
1272: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1273: @*/
1274: PetscErrorCode SectionIntClear(SectionInt section)
1275: {
1278: section->s->clear();
1279: return(0);
1280: }
1284: /*@C
1285: MeshGetVertexSectionInt - Create a Section over the vertices with the specified fiber dimension
1287: Collective on Mesh
1289: Input Parameters:
1290: + mesh - The Mesh object
1291: - fiberDim - The section name
1293: Output Parameter:
1294: . section - The section
1296: Level: intermediate
1298: .keywords: mesh, section, vertex
1299: .seealso: MeshCreate(), SectionIntCreate()
1300: @*/
1301: PetscErrorCode MeshGetVertexSectionInt(Mesh mesh, PetscInt fiberDim, SectionInt *section)
1302: {
1303: ALE::Obj<ALE::Mesh> m;
1304: ALE::Obj<ALE::Mesh::int_section_type> s;
1305: PetscErrorCode ierr;
1308: MeshGetMesh(mesh, m);
1309: SectionIntCreate(m->comm(), section);
1310: SectionIntSetBundle(*section, m);
1311: SectionIntGetSection(*section, s);
1312: s->setFiberDimension(m->depthStratum(0), fiberDim);
1313: m->allocate(s);
1314: return(0);
1315: }
1319: /*@C
1320: MeshGetCellSectionInt - Create a Section over the cells with the specified fiber dimension
1322: Collective on Mesh
1324: Input Parameters:
1325: + mesh - The Mesh object
1326: - fiberDim - The section name
1328: Output Parameter:
1329: . section - The section
1331: Level: intermediate
1333: .keywords: mesh, section, cell
1334: .seealso: MeshCreate(), SectionIntCreate()
1335: @*/
1336: PetscErrorCode MeshGetCellSectionInt(Mesh mesh, PetscInt fiberDim, SectionInt *section)
1337: {
1338: ALE::Obj<ALE::Mesh> m;
1339: ALE::Obj<ALE::Mesh::int_section_type> s;
1340: PetscErrorCode ierr;
1343: MeshGetMesh(mesh, m);
1344: SectionIntCreate(m->comm(), section);
1345: SectionIntSetBundle(*section, m);
1346: SectionIntGetSection(*section, s);
1347: s->setFiberDimension(m->heightStratum(0), fiberDim);
1348: m->allocate(s);
1349: return(0);
1350: }