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: /*@C
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: SETERRQ(PETSC_ERR_SUP, "I am being lazy, bug me.");
335: #else
336: ALE::Obj<PETSC_MESH_TYPE::real_section_type> newSection = ALE::Distribution<PETSC_MESH_TYPE>::distributeSection(oldSection, m, m->getDistSendOverlap(), m->getDistRecvOverlap());
337: SectionRealSetSection(*parallelSection, newSection);
338: #endif
339: return(0);
340: }
344: /*@C
345: SectionRealRestrict - Restricts the SectionReal to a subset of the topology, returning an array of values.
347: Not collective
349: Input Parameters:
350: + section - the section object
351: - point - the Sieve point
353: Output Parameter:
354: . values - The values associated with the submesh
356: Level: advanced
358: .seealso SectionUpdate(), SectionCreate(), SectionView()
359: @*/
360: PetscErrorCode SectionRealRestrict(SectionReal section, PetscInt point, PetscScalar *values[])
361: {
365: *values = (PetscScalar *) section->b->restrictClosure(section->s, point);
366: return(0);
367: }
371: /*@C
372: SectionRealUpdate - Updates the array of values associated to a subset of the topology in this Section.
374: Not collective
376: Input Parameters:
377: + section - the section object
378: . point - the Sieve point
379: - values - The values associated with the submesh
381: Level: advanced
383: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
384: @*/
385: PetscErrorCode SectionRealUpdate(SectionReal section, PetscInt point, const PetscScalar values[])
386: {
390: section->b->update(section->s, point, values);
391: return(0);
392: }
396: /*@C
397: SectionRealUpdateAdd - Updates the array of values associated to a subset of the topology in this Section.
399: Not collective
401: Input Parameters:
402: + section - the section object
403: . point - the Sieve point
404: - values - The values associated with the submesh
406: Level: advanced
408: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
409: @*/
410: PetscErrorCode SectionRealUpdateAdd(SectionReal section, PetscInt point, const PetscScalar values[])
411: {
415: section->b->updateAdd(section->s, point, values);
416: return(0);
417: }
421: /*@C
422: SectionRealComplete - Exchanges data across the mesh overlap.
424: Not collective
426: Input Parameter:
427: . section - the section object
429: Level: advanced
431: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
432: @*/
433: PetscErrorCode SectionRealComplete(SectionReal section)
434: {
435: Obj<PETSC_MESH_TYPE::real_section_type> s;
436: Obj<PETSC_MESH_TYPE> b;
440: SectionRealGetSection(section, s);
441: SectionRealGetBundle(section, b);
442: ALE::Distribution<PETSC_MESH_TYPE>::completeSection(b, s);
443: return(0);
444: }
448: /*@C
449: SectionRealZero - Zero out the entries
451: Not collective
453: Input Parameter:
454: . section - the section object
456: Level: advanced
458: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
459: @*/
460: PetscErrorCode SectionRealZero(SectionReal section)
461: {
462: Obj<PETSC_MESH_TYPE::real_section_type> s;
466: SectionRealGetSection(section, s);
467: s->zero();
468: return(0);
469: }
473: /*@C
474: SectionRealSetFiberDimension - Set the size of the vector space attached to the point
476: Not collective
478: Input Parameters:
479: + section - the section object
480: . point - the Sieve point
481: - size - The fiber dimension
483: Level: advanced
485: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
486: @*/
487: PetscErrorCode SectionRealSetFiberDimension(SectionReal section, PetscInt point, const PetscInt size)
488: {
491: section->s->setFiberDimension(point, size);
492: return(0);
493: }
497: /*@C
498: SectionRealAllocate - Allocate storage for this section
500: Not collective
502: Input Parameter:
503: . section - the section object
505: Level: advanced
507: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
508: @*/
509: PetscErrorCode SectionRealAllocate(SectionReal section)
510: {
513: section->b->allocate(section->s);
514: return(0);
515: }
519: /*@C
520: SectionRealCreateLocalVector - Creates a vector with the local piece of the Section
522: Collective on Mesh
524: Input Parameter:
525: . section - the Section
527: Output Parameter:
528: . localVec - the local vector
530: Level: advanced
532: .seealso MeshDestroy(), MeshCreate()
533: @*/
534: PetscErrorCode SectionRealCreateLocalVector(SectionReal section, Vec *localVec)
535: {
536: ALE::Obj<PETSC_MESH_TYPE::real_section_type> s;
540: SectionRealGetSection(section, s);
541: VecCreateSeqWithArray(PETSC_COMM_SELF, s->getStorageSize(), s->restrictSpace(), localVec);
542: return(0);
543: }
547: /*@C
548: SectionRealToVec - Maps the given section to a Vec
550: Collective on Section
552: Input Parameters:
553: + section - the real Section
554: - mesh - The Mesh
556: Output Parameter:
557: . vec - the Vec
559: Level: intermediate
561: .seealso VecCreate(), SectionRealCreate()
562: @*/
563: PetscErrorCode SectionRealToVec(SectionReal section, Mesh mesh, ScatterMode mode, Vec vec)
564: {
565: Vec localVec;
566: VecScatter scatter;
571: SectionRealCreateLocalVector(section, &localVec);
572: MeshGetGlobalScatter(mesh, &scatter);
573: if (mode == SCATTER_FORWARD) {
574: VecScatterBegin(scatter, localVec, vec, INSERT_VALUES, mode);
575: VecScatterEnd(scatter, localVec, vec, INSERT_VALUES, mode);
576: } else {
577: VecScatterBegin(scatter, vec, localVec, INSERT_VALUES, mode);
578: VecScatterEnd(scatter, vec, localVec, INSERT_VALUES, mode);
579: }
580: VecDestroy(localVec);
581: return(0);
582: }
586: /*@
587: SectionRealToVec - Map between unassembled local Section storage and a globally assembled Vec
589: Collective on VecScatter
591: Input Parameters:
592: + section - the Section
593: . scatter - the scatter from the Section to the Vec
594: . mode - the mode, SCATTER_FORWARD (Section to Vec) or SCATTER_REVERSE (Vec to Section)
595: - vec - the Vec
597: Level: advanced
599: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
600: @*/
601: PetscErrorCode SectionRealToVec(SectionReal section, VecScatter scatter, ScatterMode mode, Vec vec)
602: {
603: Vec localVec;
608: SectionRealCreateLocalVector(section, &localVec);
609: if (mode == SCATTER_FORWARD) {
610: VecScatterBegin(scatter, localVec, vec, INSERT_VALUES, mode);
611: VecScatterEnd(scatter, localVec, vec, INSERT_VALUES, mode);
612: } else {
613: VecScatterBegin(scatter, vec, localVec, INSERT_VALUES, mode);
614: VecScatterEnd(scatter, vec, localVec, INSERT_VALUES, mode);
615: }
616: VecDestroy(localVec);
617: return(0);
618: }
622: /*@C
623: SectionRealClear - Dellocate storage for this section
625: Not collective
627: Input Parameter:
628: . section - the section object
630: Level: advanced
632: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
633: @*/
634: PetscErrorCode SectionRealClear(SectionReal section)
635: {
638: section->s->clear();
639: return(0);
640: }
644: /*@
645: SectionRealSet - Sets all the values to the given value
647: Not collective
649: Input Parameters:
650: + section - the real Section
651: - val - the value
653: Level: intermediate
655: .seealso VecNorm(), SectionRealCreate()
656: @*/
657: PetscErrorCode SectionRealSet(SectionReal section, PetscReal val)
658: {
659: Obj<PETSC_MESH_TYPE::real_section_type> s;
663: SectionRealGetSection(section, s);
664: s->set(val);
665: return(0);
666: }
670: /*@C
671: SectionRealNorm - Computes the vector norm.
673: Collective on Section
675: Input Parameters:
676: + section - the real Section
677: - type - one of NORM_1, NORM_2, NORM_INFINITY. Also available
678: NORM_1_AND_2, which computes both norms and stores them
679: in a two element array.
681: Output Parameter:
682: . val - the norm
684: Notes:
685: $ NORM_1 denotes sum_i |x_i|
686: $ NORM_2 denotes sqrt(sum_i (x_i)^2)
687: $ NORM_INFINITY denotes max_i |x_i|
689: Level: intermediate
691: .seealso VecNorm(), SectionRealCreate()
692: @*/
693: PetscErrorCode SectionRealNorm(SectionReal section, Mesh mesh, NormType type, PetscReal *val)
694: {
695: Obj<PETSC_MESH_TYPE> m;
696: Obj<PETSC_MESH_TYPE::real_section_type> s;
697: Vec v;
702: MeshGetMesh(mesh, m);
703: SectionRealGetSection(section, s);
704: const ALE::Obj<PETSC_MESH_TYPE::order_type>& order = m->getFactory()->getGlobalOrder(m, s->getName(), s);
705: VecCreate(m->comm(), &v);
706: VecSetSizes(v, order->getLocalSize(), order->getGlobalSize());
707: VecSetFromOptions(v);
708: SectionRealToVec(section, mesh, SCATTER_FORWARD, v);
709: VecNorm(v, type, val);
710: VecDestroy(v);
711: return(0);
712: }
716: /*@C
717: SectionRealAXPY -
719: Collective on Section
721: Input Parameters:
722: + section - the real Section
723: . alpha - a scalar
724: - X - the other real Section
726: Output Parameter:
727: . section - the difference
729: Level: intermediate
731: .seealso VecNorm(), SectionRealCreate()
732: @*/
733: PetscErrorCode SectionRealAXPY(SectionReal section, Mesh mesh, PetscScalar alpha, SectionReal X)
734: {
735: Obj<PETSC_MESH_TYPE> m;
736: Obj<PETSC_MESH_TYPE::real_section_type> s;
737: Obj<PETSC_MESH_TYPE::real_section_type> sX;
738: Vec v, x;
743: MeshGetMesh(mesh, m);
744: SectionRealGetSection(section, s);
745: SectionRealGetSection(X, sX);
746: const ALE::Obj<PETSC_MESH_TYPE::order_type>& order = m->getFactory()->getGlobalOrder(m, s->getName(), s);
747: VecCreate(m->comm(), &v);
748: VecSetSizes(v, order->getLocalSize(), order->getGlobalSize());
749: VecSetFromOptions(v);
750: VecDuplicate(v, &x);
751: SectionRealToVec(section, mesh, SCATTER_FORWARD, v);
752: SectionRealToVec(X, mesh, SCATTER_FORWARD, x);
753: VecAXPY(v, alpha, x);
754: SectionRealToVec(section, mesh, SCATTER_REVERSE, v);
755: VecDestroy(v);
756: VecDestroy(x);
757: return(0);
758: }
762: /*@C
763: MeshGetVertexSectionReal - Create a Section over the vertices with the specified fiber dimension
765: Collective on Mesh
767: Input Parameters:
768: + mesh - The Mesh object
769: - fiberDim - The number of degrees of freedom per vertex
771: Output Parameter:
772: . section - The section
774: Level: intermediate
776: .keywords: mesh, section, vertex
777: .seealso: MeshCreate(), SectionRealCreate()
778: @*/
779: PetscErrorCode MeshGetVertexSectionReal(Mesh mesh, PetscInt fiberDim, SectionReal *section)
780: {
781: ALE::Obj<PETSC_MESH_TYPE> m;
782: ALE::Obj<PETSC_MESH_TYPE::real_section_type> s;
783: PetscErrorCode ierr;
786: MeshGetMesh(mesh, m);
787: SectionRealCreate(m->comm(), section);
788: SectionRealSetBundle(*section, m);
789: SectionRealGetSection(*section, s);
790: #ifdef PETSC_OPT_SIEVE
791: s->setChart(m->getSieve()->getChart());
792: #endif
793: s->setFiberDimension(m->depthStratum(0), fiberDim);
794: m->allocate(s);
795: return(0);
796: }
800: /*@C
801: MeshGetCellSectionReal - Create a Section over the cells with the specified fiber dimension
803: Collective on Mesh
805: Input Parameters:
806: + mesh - The Mesh object
807: - fiberDim - The section name
809: Output Parameter:
810: . section - The section
812: Level: intermediate
814: .keywords: mesh, section, cell
815: .seealso: MeshCreate(), SectionRealCreate()
816: @*/
817: PetscErrorCode MeshGetCellSectionReal(Mesh mesh, PetscInt fiberDim, SectionReal *section)
818: {
819: ALE::Obj<PETSC_MESH_TYPE> m;
820: ALE::Obj<PETSC_MESH_TYPE::real_section_type> s;
821: PetscErrorCode ierr;
824: MeshGetMesh(mesh, m);
825: SectionRealCreate(m->comm(), section);
826: SectionRealSetBundle(*section, m);
827: SectionRealGetSection(*section, s);
828: s->setFiberDimension(m->heightStratum(0), fiberDim);
829: m->allocate(s);
830: return(0);
831: }
835: /*@C
836: MeshCreateGlobalRealVector - Creates a vector of the correct size to be gathered into
837: by the mesh.
839: Collective on Mesh
841: Input Parameters:
842: + mesh - the mesh object
843: - section - The SectionReal
845: Output Parameters:
846: . gvec - the global vector
848: Level: advanced
850: .seealso MeshDestroy(), MeshCreate(), MeshCreateGlobalVector()
852: @*/
853: PetscErrorCode MeshCreateGlobalRealVector(Mesh mesh, SectionReal section, Vec *gvec)
854: {
855: ALE::Obj<PETSC_MESH_TYPE> m;
856: ALE::Obj<PETSC_MESH_TYPE::real_section_type> s;
857: const char *name;
861: MeshGetMesh(mesh, m);
862: SectionRealGetSection(section, s);
863: PetscObjectGetName((PetscObject) section, &name);
864: const ALE::Obj<PETSC_MESH_TYPE::order_type>& order = m->getFactory()->getGlobalOrder(m, name, s);
866: VecCreate(m->comm(), gvec);
867: VecSetSizes(*gvec, order->getLocalSize(), order->getGlobalSize());
868: VecSetFromOptions(*gvec);
869: return(0);
870: }
874: PetscErrorCode SectionIntView_Sieve(SectionInt section, PetscViewer viewer)
875: {
876: PetscTruth iascii, isbinary, isdraw;
880: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_ASCII, &iascii);
881: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &isbinary);
882: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_DRAW, &isdraw);
884: if (iascii){
885: ALE::Obj<PETSC_MESH_TYPE::int_section_type> s;
886: ALE::Obj<PETSC_MESH_TYPE> b;
887: const char *name;
889: SectionIntGetSection(section, s);
890: SectionIntGetBundle(section, b);
891: PetscObjectGetName((PetscObject) section, &name);
892: SectionView_Sieve_Ascii(b, s, name, viewer);
893: } else if (isbinary) {
894: SETERRQ(PETSC_ERR_SUP, "Binary viewer not implemented for Section");
895: } else if (isdraw){
896: SETERRQ(PETSC_ERR_SUP, "Draw viewer not implemented for Section");
897: } else {
898: SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported by this section object", ((PetscObject)viewer)->type_name);
899: }
900: return(0);
901: }
905: /*@C
906: SectionIntView - Views a Section object.
908: Collective on Section
910: Input Parameters:
911: + section - the Section
912: - viewer - an optional visualization context
914: Notes:
915: The available visualization contexts include
916: + PETSC_VIEWER_STDOUT_SELF - standard output (default)
917: - PETSC_VIEWER_STDOUT_WORLD - synchronized standard
918: output where only the first processor opens
919: the file. All other processors send their
920: data to the first processor to print.
922: You can change the format the section is printed using the
923: option PetscViewerSetFormat().
925: The user can open alternative visualization contexts with
926: + PetscViewerASCIIOpen() - Outputs section to a specified file
927: . PetscViewerBinaryOpen() - Outputs section in binary to a
928: specified file; corresponding input uses SectionLoad()
929: . PetscViewerDrawOpen() - Outputs section to an X window display
931: The user can call PetscViewerSetFormat() to specify the output
932: format of ASCII printed objects (when using PETSC_VIEWER_STDOUT_SELF,
933: PETSC_VIEWER_STDOUT_WORLD and PetscViewerASCIIOpen). Available formats include
934: + PETSC_VIEWER_DEFAULT - default, prints section information
935: - PETSC_VIEWER_ASCII_VTK - outputs a VTK file describing the section
937: Level: beginner
939: Concepts: section^printing
940: Concepts: section^saving to disk
942: .seealso: VecView(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerBinaryOpen(), PetscViewerCreate()
943: @*/
944: PetscErrorCode SectionIntView(SectionInt section, PetscViewer viewer)
945: {
951: if (!viewer) {
952: PetscViewerASCIIGetStdout(((PetscObject)section)->comm,&viewer);
953: }
957: PetscLogEventBegin(SectionInt_View,0,0,0,0);
958: (*section->ops->view)(section, viewer);
959: PetscLogEventEnd(SectionInt_View,0,0,0,0);
960: return(0);
961: }
965: /*@C
966: SectionIntGetSection - Gets the internal section object
968: Not collective
970: Input Parameter:
971: . section - the section object
973: Output Parameter:
974: . s - the internal section object
975:
976: Level: advanced
978: .seealso SectionIntCreate(), SectionIntSetSection()
979: @*/
980: PetscErrorCode SectionIntGetSection(SectionInt section, ALE::Obj<PETSC_MESH_TYPE::int_section_type>& s)
981: {
984: s = section->s;
985: return(0);
986: }
990: /*@C
991: SectionIntSetSection - Sets the internal section object
993: Not collective
995: Input Parameters:
996: + section - the section object
997: - s - the internal section object
998:
999: Level: advanced
1001: .seealso SectionIntCreate(), SectionIntGetSection()
1002: @*/
1003: PetscErrorCode SectionIntSetSection(SectionInt section, const ALE::Obj<PETSC_MESH_TYPE::int_section_type>& s)
1004: {
1009: if (!s.isNull()) {PetscObjectSetName((PetscObject) section, s->getName().c_str());}
1010: section->s = s;
1011: return(0);
1012: }
1016: /*@C
1017: SectionIntGetBundle - Gets the section bundle
1019: Not collective
1021: Input Parameter:
1022: . section - the section object
1024: Output Parameter:
1025: . b - the section bundle
1026:
1027: Level: advanced
1029: .seealso SectionIntCreate(), SectionIntGetSection(), SectionIntSetSection()
1030: @*/
1031: PetscErrorCode SectionIntGetBundle(SectionInt section, ALE::Obj<PETSC_MESH_TYPE>& b)
1032: {
1035: b = section->b;
1036: return(0);
1037: }
1041: /*@C
1042: SectionIntSetBundle - Sets the section bundle
1044: Not collective
1046: Input Parameters:
1047: + section - the section object
1048: - b - the section bundle
1049:
1050: Level: advanced
1052: .seealso SectionIntCreate(), SectionIntGetSection(), SectionIntSetSection()
1053: @*/
1054: PetscErrorCode SectionIntSetBundle(SectionInt section, const ALE::Obj<PETSC_MESH_TYPE>& b)
1055: {
1058: section->b = b;
1059: return(0);
1060: }
1064: /*@C
1065: SectionIntCreate - Creates a Section object, used to manage data for an unstructured problem
1066: described by a Sieve.
1068: Collective on MPI_Comm
1070: Input Parameter:
1071: . comm - the processors that will share the global section
1073: Output Parameters:
1074: . section - the section object
1076: Level: advanced
1078: .seealso SectionIntDestroy(), SectionIntView()
1079: @*/
1080: PetscErrorCode SectionIntCreate(MPI_Comm comm, SectionInt *section)
1081: {
1083: SectionInt s;
1087: *section = PETSC_NULL;
1089: PetscHeaderCreate(s,_p_SectionInt,struct _SectionIntOps,SECTIONINT_COOKIE,0,"SectionInt",comm,SectionIntDestroy,0);
1090: s->ops->view = SectionIntView_Sieve;
1091: s->ops->restrictClosure = SectionIntRestrict;
1092: s->ops->update = SectionIntUpdate;
1094: PetscObjectChangeTypeName((PetscObject) s, "sieve");
1096: new(&s->s) ALE::Obj<PETSC_MESH_TYPE::int_section_type>(PETSC_MESH_TYPE::int_section_type(comm));
1097: new(&s->b) ALE::Obj<PETSC_MESH_TYPE>(PETSC_NULL);
1098: *section = s;
1099: return(0);
1100: }
1104: /*@C
1105: SectionIntDestroy - Destroys a section.
1107: Collective on Section
1109: Input Parameter:
1110: . section - the section object
1112: Level: advanced
1114: .seealso SectionIntCreate(), SectionIntView()
1115: @*/
1116: PetscErrorCode SectionIntDestroy(SectionInt section)
1117: {
1122: if (--((PetscObject)section)->refct > 0) return(0);
1123: section->s = PETSC_NULL;
1124: PetscHeaderDestroy(section);
1125: return(0);
1126: }
1130: /*@C
1131: SectionIntDistribute - Distributes the sections.
1133: Not Collective
1135: Input Parameters:
1136: + serialSection - The original Section object
1137: - parallelMesh - The parallel Mesh
1139: Output Parameter:
1140: . parallelSection - The distributed Section object
1142: Level: intermediate
1144: .keywords: mesh, section, distribute
1145: .seealso: MeshCreate()
1146: @*/
1147: PetscErrorCode SectionIntDistribute(SectionInt serialSection, Mesh parallelMesh, SectionInt *parallelSection)
1148: {
1149: ALE::Obj<PETSC_MESH_TYPE::int_section_type> oldSection;
1150: ALE::Obj<PETSC_MESH_TYPE> m;
1151: PetscErrorCode ierr;
1154: SectionIntGetSection(serialSection, oldSection);
1155: MeshGetMesh(parallelMesh, m);
1156: SectionIntCreate(oldSection->comm(), parallelSection);
1157: #ifdef PETSC_OPT_SIEVE
1158: SETERRQ(PETSC_ERR_SUP, "I am being lazy, bug me.");
1159: #else
1160: ALE::Obj<PETSC_MESH_TYPE::int_section_type> newSection = ALE::Distribution<PETSC_MESH_TYPE>::distributeSection(oldSection, m, m->getDistSendOverlap(), m->getDistRecvOverlap());
1161: SectionIntSetSection(*parallelSection, newSection);
1162: #endif
1163: return(0);
1164: }
1168: /*@C
1169: SectionIntRestrict - Restricts the SectionInt to a subset of the topology, returning an array of values.
1171: Not collective
1173: Input Parameters:
1174: + section - the section object
1175: - point - the Sieve point
1177: Output Parameter:
1178: . values - The values associated with the submesh
1180: Level: advanced
1182: .seealso SectionIntUpdate(), SectionIntCreate(), SectionIntView()
1183: @*/
1184: PetscErrorCode SectionIntRestrict(SectionInt section, PetscInt point, PetscInt *values[])
1185: {
1189: *values = (PetscInt *) section->b->restrictClosure(section->s, point);
1190: return(0);
1191: }
1195: /*@C
1196: SectionIntUpdate - Updates the array of values associated to a subset of the topology in this Section.
1198: Not collective
1200: Input Parameters:
1201: + section - the section object
1202: . point - the Sieve point
1203: - values - The values associated with the submesh
1205: Level: advanced
1207: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1208: @*/
1209: PetscErrorCode SectionIntUpdate(SectionInt section, PetscInt point, const PetscInt values[])
1210: {
1214: section->b->update(section->s, point, values);
1215: return(0);
1216: }
1220: /*@C
1221: SectionIntUpdateAdd - Updates the array of values associated to a subset of the topology in this Section.
1223: Not collective
1225: Input Parameters:
1226: + section - the section object
1227: . point - the Sieve point
1228: - values - The values associated with the submesh
1230: Level: advanced
1232: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1233: @*/
1234: PetscErrorCode SectionIntUpdateAdd(SectionInt section, PetscInt point, const PetscInt values[])
1235: {
1239: section->b->updateAdd(section->s, point, values);
1240: return(0);
1241: }
1245: /*@C
1246: SectionIntComplete - Exchanges data across the mesh overlap.
1248: Not collective
1250: Input Parameter:
1251: . section - the section object
1253: Level: advanced
1255: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1256: @*/
1257: PetscErrorCode SectionIntComplete(SectionInt section)
1258: {
1259: Obj<PETSC_MESH_TYPE::int_section_type> s;
1260: Obj<PETSC_MESH_TYPE> b;
1264: SectionIntGetSection(section, s);
1265: SectionIntGetBundle(section, b);
1266: ALE::Distribution<PETSC_MESH_TYPE>::completeSection(b, s);
1267: return(0);
1268: }
1272: /*@C
1273: SectionIntSetFiberDimension - Set the size of the vector space attached to the point
1275: Not collective
1277: Input Parameters:
1278: + section - the section object
1279: . point - the Sieve point
1280: - size - The fiber dimension
1282: Level: advanced
1284: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1285: @*/
1286: PetscErrorCode SectionIntSetFiberDimension(SectionInt section, PetscInt point, const PetscInt size)
1287: {
1290: section->s->setFiberDimension(point, size);
1291: return(0);
1292: }
1296: /*@C
1297: SectionIntAllocate - Allocate storage for this section
1299: Not collective
1301: Input Parameter:
1302: . section - the section object
1304: Level: advanced
1306: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1307: @*/
1308: PetscErrorCode SectionIntAllocate(SectionInt section)
1309: {
1312: section->b->allocate(section->s);
1313: return(0);
1314: }
1318: /*@C
1319: SectionIntClear - Dellocate storage for this section
1321: Not collective
1323: Input Parameter:
1324: . section - the section object
1326: Level: advanced
1328: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1329: @*/
1330: PetscErrorCode SectionIntClear(SectionInt section)
1331: {
1334: section->s->clear();
1335: return(0);
1336: }
1340: /*@C
1341: MeshGetVertexSectionInt - Create a Section over the vertices with the specified fiber dimension
1343: Collective on Mesh
1345: Input Parameters:
1346: + mesh - The Mesh object
1347: - fiberDim - The section name
1349: Output Parameter:
1350: . section - The section
1352: Level: intermediate
1354: .keywords: mesh, section, vertex
1355: .seealso: MeshCreate(), SectionIntCreate()
1356: @*/
1357: PetscErrorCode MeshGetVertexSectionInt(Mesh mesh, PetscInt fiberDim, SectionInt *section)
1358: {
1359: ALE::Obj<PETSC_MESH_TYPE> m;
1360: ALE::Obj<PETSC_MESH_TYPE::int_section_type> s;
1361: PetscErrorCode ierr;
1364: MeshGetMesh(mesh, m);
1365: SectionIntCreate(m->comm(), section);
1366: SectionIntSetBundle(*section, m);
1367: SectionIntGetSection(*section, s);
1368: s->setFiberDimension(m->depthStratum(0), fiberDim);
1369: m->allocate(s);
1370: return(0);
1371: }
1375: /*@C
1376: MeshGetCellSectionInt - Create a Section over the cells with the specified fiber dimension
1378: Collective on Mesh
1380: Input Parameters:
1381: + mesh - The Mesh object
1382: - fiberDim - The section name
1384: Output Parameter:
1385: . section - The section
1387: Level: intermediate
1389: .keywords: mesh, section, cell
1390: .seealso: MeshCreate(), SectionIntCreate()
1391: @*/
1392: PetscErrorCode MeshGetCellSectionInt(Mesh mesh, PetscInt fiberDim, SectionInt *section)
1393: {
1394: ALE::Obj<PETSC_MESH_TYPE> m;
1395: ALE::Obj<PETSC_MESH_TYPE::int_section_type> s;
1396: PetscErrorCode ierr;
1399: MeshGetMesh(mesh, m);
1400: SectionIntCreate(m->comm(), section);
1401: SectionIntSetBundle(*section, m);
1402: SectionIntGetSection(*section, s);
1403: s->setFiberDimension(m->heightStratum(0), fiberDim);
1404: m->allocate(s);
1405: return(0);
1406: }