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:   new(&s->s) ALE::Obj<ALE::Mesh::real_section_type>(ALE::Mesh::real_section_type(comm));
273:   new(&s->b) ALE::Obj<ALE::Mesh>(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<ALE::Mesh::real_section_type> oldSection;
326:   ALE::Obj<ALE::Mesh>               m;

330:   SectionRealGetSection(serialSection, oldSection);
331:   MeshGetMesh(parallelMesh, m);
332:   SectionRealCreate(oldSection->comm(), parallelSection);
333:   ALE::Obj<ALE::Mesh::real_section_type> newSection = ALE::Distribution<ALE::Mesh>::distributeSection(oldSection, m, m->getDistSendOverlap(), m->getDistRecvOverlap());
334:   SectionRealSetSection(*parallelSection, newSection);
335:   return(0);
336: }

340: /*@C
341:   SectionRealRestrict - Restricts the SectionReal to a subset of the topology, returning an array of values.

343:   Not collective

345:   Input Parameters:
346: + section - the section object
347: - point - the Sieve point

349:   Output Parameter:
350: . values - The values associated with the submesh

352:   Level: advanced

354: .seealso SectionUpdate(), SectionCreate(), SectionView()
355: @*/
356: PetscErrorCode  SectionRealRestrict(SectionReal section, PetscInt point, PetscScalar *values[])
357: {
361:   *values = (PetscScalar *) section->b->restrict(section->s, point);
362:   return(0);
363: }

367: /*@C
368:   SectionRealUpdate - Updates the array of values associated to a subset of the topology in this Section.

370:   Not collective

372:   Input Parameters:
373: + section - the section object
374: . point - the Sieve point
375: - values - The values associated with the submesh

377:   Level: advanced

379: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
380: @*/
381: PetscErrorCode  SectionRealUpdate(SectionReal section, PetscInt point, const PetscScalar values[])
382: {
386:   section->b->update(section->s, point, values);
387:   return(0);
388: }

392: /*@C
393:   SectionRealUpdateAdd - Updates the array of values associated to a subset of the topology in this Section.

395:   Not collective

397:   Input Parameters:
398: + section - the section object
399: . point - the Sieve point
400: - values - The values associated with the submesh

402:   Level: advanced

404: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
405: @*/
406: PetscErrorCode  SectionRealUpdateAdd(SectionReal section, PetscInt point, const PetscScalar values[])
407: {
411:   section->b->updateAdd(section->s, point, values);
412:   return(0);
413: }

417: /*@C
418:   SectionRealComplete - Exchanges data across the mesh overlap.

420:   Not collective

422:   Input Parameter:
423: . section - the section object

425:   Level: advanced

427: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
428: @*/
429: PetscErrorCode SectionRealComplete(SectionReal section)
430: {
431:   Obj<ALE::Mesh::real_section_type> s;
432:   Obj<ALE::Mesh>                    b;

436:   SectionRealGetSection(section, s);
437:   SectionRealGetBundle(section, b);
438:   ALE::Distribution<ALE::Mesh>::completeSection(b, s);
439:   return(0);
440: }

444: /*@C
445:   SectionRealZero - Zero out the entries

447:   Not collective

449:   Input Parameter:
450: . section - the section object

452:   Level: advanced

454: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
455: @*/
456: PetscErrorCode SectionRealZero(SectionReal section)
457: {
458:   Obj<ALE::Mesh::real_section_type> s;

462:   SectionRealGetSection(section, s);
463:   s->zero();
464:   return(0);
465: }

469: /*@C
470:   SectionRealSetFiberDimension - Set the size of the vector space attached to the point

472:   Not collective

474:   Input Parameters:
475: + section - the section object
476: . point - the Sieve point
477: - size - The fiber dimension

479:   Level: advanced

481: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
482: @*/
483: PetscErrorCode  SectionRealSetFiberDimension(SectionReal section, PetscInt point, const PetscInt size)
484: {
487:   section->s->setFiberDimension(point, size);
488:   return(0);
489: }

493: /*@C
494:   SectionRealAllocate - Allocate storage for this section

496:   Not collective

498:   Input Parameter:
499: . section - the section object

501:   Level: advanced

503: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
504: @*/
505: PetscErrorCode  SectionRealAllocate(SectionReal section)
506: {
509:   section->b->allocate(section->s);
510:   return(0);
511: }

515: /*@C
516:   SectionRealCreateLocalVector - Creates a vector with the local piece of the Section

518:   Collective on Mesh

520:   Input Parameter:
521: . section - the Section  

523:   Output Parameter:
524: . localVec - the local vector

526:   Level: advanced

528: .seealso MeshDestroy(), MeshCreate()
529: @*/
530: PetscErrorCode  SectionRealCreateLocalVector(SectionReal section, Vec *localVec)
531: {
532:   ALE::Obj<ALE::Mesh::real_section_type> s;

536:   SectionRealGetSection(section, s);
537:   VecCreateSeqWithArray(PETSC_COMM_SELF, s->getStorageSize(), s->restrict(), localVec);
538:   return(0);
539: }

543: /*@C
544:   SectionRealToVec - Maps the given section to a Vec

546:   Collective on Section

548:   Input Parameters:
549: + section - the real Section
550: - mesh - The Mesh

552:   Output Parameter:
553: . vec - the Vec 

555:   Level: intermediate

557: .seealso VecCreate(), SectionRealCreate()
558: @*/
559: PetscErrorCode  SectionRealToVec(SectionReal section, Mesh mesh, ScatterMode mode, Vec vec)
560: {
561:   Vec            localVec;
562:   VecScatter     scatter;

567:   SectionRealCreateLocalVector(section, &localVec);
568:   MeshGetGlobalScatter(mesh, &scatter);
569:   if (mode == SCATTER_FORWARD) {
570:     VecScatterBegin(scatter, localVec, vec, INSERT_VALUES, mode);
571:     VecScatterEnd(scatter, localVec, vec, INSERT_VALUES, mode);
572:   } else {
573:     VecScatterBegin(scatter, vec, localVec, INSERT_VALUES, mode);
574:     VecScatterEnd(scatter, vec, localVec, INSERT_VALUES, mode);
575:   }
576:   VecDestroy(localVec);
577:   return(0);
578: }

580: PetscErrorCode  SectionRealToVec(SectionReal section, Mesh mesh, VecScatter scatter, ScatterMode mode, Vec vec)
581: {
582:   Vec            localVec;

587:   SectionRealCreateLocalVector(section, &localVec);
588:   if (mode == SCATTER_FORWARD) {
589:     VecScatterBegin(scatter, localVec, vec, INSERT_VALUES, mode);
590:     VecScatterEnd(scatter, localVec, vec, INSERT_VALUES, mode);
591:   } else {
592:     VecScatterBegin(scatter, vec, localVec, INSERT_VALUES, mode);
593:     VecScatterEnd(scatter, vec, localVec, INSERT_VALUES, mode);
594:   }
595:   VecDestroy(localVec);
596:   return(0);
597: }

601: /*@C
602:   SectionRealClear - Dellocate storage for this section

604:   Not collective

606:   Input Parameter:
607: . section - the section object

609:   Level: advanced

611: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
612: @*/
613: PetscErrorCode  SectionRealClear(SectionReal section)
614: {
617:   section->s->clear();
618:   return(0);
619: }

623: /*@C
624:   SectionRealNorm - Computes the vector norm.

626:   Collective on Section

628:   Input Parameters:
629: +  section - the real Section
630: -  type - one of NORM_1, NORM_2, NORM_INFINITY.  Also available
631:           NORM_1_AND_2, which computes both norms and stores them
632:           in a two element array.

634:   Output Parameter:
635: . val - the norm 

637:   Notes:
638: $     NORM_1 denotes sum_i |x_i|
639: $     NORM_2 denotes sqrt(sum_i (x_i)^2)
640: $     NORM_INFINITY denotes max_i |x_i|

642:   Level: intermediate

644: .seealso VecNorm(), SectionRealCreate()
645: @*/
646: PetscErrorCode  SectionRealNorm(SectionReal section, Mesh mesh, NormType type, PetscReal *val)
647: {
648:   Obj<ALE::Mesh> m;
649:   Obj<ALE::Mesh::real_section_type> s;
650:   Vec            v;

655:   MeshGetMesh(mesh, m);
656:   SectionRealGetSection(section, s);
657:   const ALE::Obj<ALE::Mesh::order_type>& order = m->getFactory()->getGlobalOrder(m, s->getName(), s);
658:   VecCreate(m->comm(), &v);
659:   VecSetSizes(v, order->getLocalSize(), order->getGlobalSize());
660:   VecSetFromOptions(v);
661:   SectionRealToVec(section, mesh, SCATTER_FORWARD, v);
662:   VecNorm(v, type, val);
663:   VecDestroy(v);
664:   return(0);
665: }

669: /*@C
670:   SectionRealAXPY - 

672:   Collective on Section

674:   Input Parameters:
675: +  section - the real Section
676: .  alpha - a scalar
677: -  X - the other real Section

679:   Output Parameter:
680: . section - the difference 

682:   Level: intermediate

684: .seealso VecNorm(), SectionRealCreate()
685: @*/
686: PetscErrorCode  SectionRealAXPY(SectionReal section, Mesh mesh, PetscScalar alpha, SectionReal X)
687: {
688:   Obj<ALE::Mesh> m;
689:   Obj<ALE::Mesh::real_section_type> s;
690:   Obj<ALE::Mesh::real_section_type> sX;
691:   Vec            v, x;

696:   MeshGetMesh(mesh, m);
697:   SectionRealGetSection(section, s);
698:   SectionRealGetSection(X, sX);
699:   const ALE::Obj<ALE::Mesh::order_type>& order = m->getFactory()->getGlobalOrder(m, s->getName(), s);
700:   VecCreate(m->comm(), &v);
701:   VecSetSizes(v, order->getLocalSize(), order->getGlobalSize());
702:   VecSetFromOptions(v);
703:   VecDuplicate(v, &x);
704:   SectionRealToVec(section, mesh, SCATTER_FORWARD, v);
705:   SectionRealToVec(X,       mesh, SCATTER_FORWARD, x);
706:   VecAXPY(v, alpha, x);
707:   SectionRealToVec(section, mesh, SCATTER_REVERSE, v);
708:   VecDestroy(v);
709:   VecDestroy(x);
710:   return(0);
711: }

715: /*@C
716:   MeshGetVertexSectionReal - Create a Section over the vertices with the specified fiber dimension

718:   Collective on Mesh

720:   Input Parameters:
721: + mesh - The Mesh object
722: - fiberDim - The section name

724:   Output Parameter:
725: . section - The section

727:   Level: intermediate

729: .keywords: mesh, section, vertex
730: .seealso: MeshCreate(), SectionRealCreate()
731: @*/
732: PetscErrorCode MeshGetVertexSectionReal(Mesh mesh, PetscInt fiberDim, SectionReal *section)
733: {
734:   ALE::Obj<ALE::Mesh> m;
735:   ALE::Obj<ALE::Mesh::real_section_type> s;
736:   PetscErrorCode      ierr;

739:   MeshGetMesh(mesh, m);
740:   SectionRealCreate(m->comm(), section);
741:   SectionRealSetBundle(*section, m);
742:   SectionRealGetSection(*section, s);
743:   s->setFiberDimension(m->depthStratum(0), fiberDim);
744:   m->allocate(s);
745:   return(0);
746: }

750: /*@C
751:   MeshGetCellSectionReal - Create a Section over the cells with the specified fiber dimension

753:   Collective on Mesh

755:   Input Parameters:
756: + mesh - The Mesh object
757: - fiberDim - The section name

759:   Output Parameter:
760: . section - The section

762:   Level: intermediate

764: .keywords: mesh, section, cell
765: .seealso: MeshCreate(), SectionRealCreate()
766: @*/
767: PetscErrorCode MeshGetCellSectionReal(Mesh mesh, PetscInt fiberDim, SectionReal *section)
768: {
769:   ALE::Obj<ALE::Mesh> m;
770:   ALE::Obj<ALE::Mesh::real_section_type> s;
771:   PetscErrorCode      ierr;

774:   MeshGetMesh(mesh, m);
775:   SectionRealCreate(m->comm(), section);
776:   SectionRealSetBundle(*section, m);
777:   SectionRealGetSection(*section, s);
778:   s->setFiberDimension(m->heightStratum(0), fiberDim);
779:   m->allocate(s);
780:   return(0);
781: }

785: /*@C
786:     MeshCreateGlobalRealVector - Creates a vector of the correct size to be gathered into 
787:         by the mesh.

789:     Collective on Mesh

791:     Input Parameters:
792: +    mesh - the mesh object
793: -    section - The SectionReal

795:     Output Parameters:
796: .   gvec - the global vector

798:     Level: advanced

800: .seealso MeshDestroy(), MeshCreate(), MeshCreateGlobalVector()

802: @*/
803: PetscErrorCode  MeshCreateGlobalRealVector(Mesh mesh, SectionReal section, Vec *gvec)
804: {
805:   ALE::Obj<ALE::Mesh> m;
806:   ALE::Obj<ALE::Mesh::real_section_type> s;
807:   const char    *name;

811:   MeshGetMesh(mesh, m);
812:   SectionRealGetSection(section, s);
813:   PetscObjectGetName((PetscObject) section, &name);
814:   const ALE::Obj<ALE::Mesh::order_type>& order = m->getFactory()->getGlobalOrder(m, name, s);

816:   VecCreate(m->comm(), gvec);
817:   VecSetSizes(*gvec, order->getLocalSize(), order->getGlobalSize());
818:   VecSetFromOptions(*gvec);
819:   return(0);
820: }

824: PetscErrorCode SectionIntView_Sieve(SectionInt section, PetscViewer viewer)
825: {
826:   PetscTruth     iascii, isbinary, isdraw;

830:   PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_ASCII, &iascii);
831:   PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &isbinary);
832:   PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_DRAW, &isdraw);

834:   if (iascii){
835:     ALE::Obj<ALE::Mesh::int_section_type> s;
836:     ALE::Obj<ALE::Mesh>                   b;
837:     const char                                  *name;

839:     SectionIntGetSection(section, s);
840:     SectionIntGetBundle(section, b);
841:     PetscObjectGetName((PetscObject) section, &name);
842:     SectionView_Sieve_Ascii(b, s, name, viewer);
843:   } else if (isbinary) {
844:     SETERRQ(PETSC_ERR_SUP, "Binary viewer not implemented for Section");
845:   } else if (isdraw){
846:     SETERRQ(PETSC_ERR_SUP, "Draw viewer not implemented for Section");
847:   } else {
848:     SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported by this section object", ((PetscObject)viewer)->type_name);
849:   }
850:   return(0);
851: }

855: /*@C
856:    SectionIntView - Views a Section object. 

858:    Collective on Section

860:    Input Parameters:
861: +  section - the Section
862: -  viewer - an optional visualization context

864:    Notes:
865:    The available visualization contexts include
866: +     PETSC_VIEWER_STDOUT_SELF - standard output (default)
867: -     PETSC_VIEWER_STDOUT_WORLD - synchronized standard
868:          output where only the first processor opens
869:          the file.  All other processors send their 
870:          data to the first processor to print. 

872:    You can change the format the section is printed using the 
873:    option PetscViewerSetFormat().

875:    The user can open alternative visualization contexts with
876: +    PetscViewerASCIIOpen() - Outputs section to a specified file
877: .    PetscViewerBinaryOpen() - Outputs section in binary to a
878:          specified file; corresponding input uses SectionLoad()
879: .    PetscViewerDrawOpen() - Outputs section to an X window display

881:    The user can call PetscViewerSetFormat() to specify the output
882:    format of ASCII printed objects (when using PETSC_VIEWER_STDOUT_SELF,
883:    PETSC_VIEWER_STDOUT_WORLD and PetscViewerASCIIOpen).  Available formats include
884: +    PETSC_VIEWER_ASCII_DEFAULT - default, prints section information
885: -    PETSC_VIEWER_ASCII_VTK - outputs a VTK file describing the section

887:    Level: beginner

889:    Concepts: section^printing
890:    Concepts: section^saving to disk

892: .seealso: VecView(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerBinaryOpen(), PetscViewerCreate()
893: @*/
894: PetscErrorCode SectionIntView(SectionInt section, PetscViewer viewer)
895: {

901:   if (!viewer) {
902:     PetscViewerASCIIGetStdout(((PetscObject)section)->comm,&viewer);
903:   }

908:   (*section->ops->view)(section, viewer);
910:   return(0);
911: }

915: /*@C
916:   SectionIntGetSection - Gets the internal section object

918:   Not collective

920:   Input Parameter:
921: . section - the section object

923:   Output Parameter:
924: . s - the internal section object
925:  
926:   Level: advanced

928: .seealso SectionIntCreate(), SectionIntSetSection()
929: @*/
930: PetscErrorCode  SectionIntGetSection(SectionInt section, ALE::Obj<ALE::Mesh::int_section_type>& s)
931: {
934:   s = section->s;
935:   return(0);
936: }

940: /*@C
941:   SectionIntSetSection - Sets the internal section object

943:   Not collective

945:   Input Parameters:
946: + section - the section object
947: - s - the internal section object
948:  
949:   Level: advanced

951: .seealso SectionIntCreate(), SectionIntGetSection()
952: @*/
953: PetscErrorCode  SectionIntSetSection(SectionInt section, const ALE::Obj<ALE::Mesh::int_section_type>& s)
954: {

959:   if (!s.isNull()) {PetscObjectSetName((PetscObject) section, s->getName().c_str());}
960:   section->s = s;
961:   return(0);
962: }

966: /*@C
967:   SectionIntGetBundle - Gets the section bundle

969:   Not collective

971:   Input Parameter:
972: . section - the section object

974:   Output Parameter:
975: . b - the section bundle
976:  
977:   Level: advanced

979: .seealso SectionIntCreate(), SectionIntGetSection(), SectionIntSetSection()
980: @*/
981: PetscErrorCode  SectionIntGetBundle(SectionInt section, ALE::Obj<ALE::Mesh>& b)
982: {
985:   b = section->b;
986:   return(0);
987: }

991: /*@C
992:   SectionIntSetBundle - Sets the section bundle

994:   Not collective

996:   Input Parameters:
997: + section - the section object
998: - b - the section bundle
999:  
1000:   Level: advanced

1002: .seealso SectionIntCreate(), SectionIntGetSection(), SectionIntSetSection()
1003: @*/
1004: PetscErrorCode  SectionIntSetBundle(SectionInt section, const ALE::Obj<ALE::Mesh>& b)
1005: {
1008:   section->b = b;
1009:   return(0);
1010: }

1014: /*@C
1015:   SectionIntCreate - Creates a Section object, used to manage data for an unstructured problem
1016:   described by a Sieve.

1018:   Collective on MPI_Comm

1020:   Input Parameter:
1021: . comm - the processors that will share the global section

1023:   Output Parameters:
1024: . section - the section object

1026:   Level: advanced

1028: .seealso SectionIntDestroy(), SectionIntView()
1029: @*/
1030: PetscErrorCode  SectionIntCreate(MPI_Comm comm, SectionInt *section)
1031: {
1033:   SectionInt    s;

1037:   *section = PETSC_NULL;

1039:   PetscHeaderCreate(s,_p_SectionInt,struct _SectionIntOps,SECTIONINT_COOKIE,0,"SectionInt",comm,SectionIntDestroy,0);
1040:   s->ops->view     = SectionIntView_Sieve;
1041:   s->ops->restrict = SectionIntRestrict;
1042:   s->ops->update   = SectionIntUpdate;

1044:   PetscObjectChangeTypeName((PetscObject) s, "sieve");

1046:   new(&s->s) ALE::Obj<ALE::Mesh::int_section_type>(ALE::Mesh::int_section_type(comm));
1047:   new(&s->b) ALE::Obj<ALE::Mesh>(PETSC_NULL);
1048:   *section = s;
1049:   return(0);
1050: }

1054: /*@C
1055:   SectionIntDestroy - Destroys a section.

1057:   Collective on Section

1059:   Input Parameter:
1060: . section - the section object

1062:   Level: advanced

1064: .seealso SectionIntCreate(), SectionIntView()
1065: @*/
1066: PetscErrorCode  SectionIntDestroy(SectionInt section)
1067: {

1072:   if (--((PetscObject)section)->refct > 0) return(0);
1073:   section->s = PETSC_NULL;
1074:   PetscHeaderDestroy(section);
1075:   return(0);
1076: }

1080: /*@C
1081:   SectionIntDistribute - Distributes the sections.

1083:   Not Collective

1085:   Input Parameters:
1086: + serialSection - The original Section object
1087: - parallelMesh - The parallel Mesh

1089:   Output Parameter:
1090: . parallelSection - The distributed Section object

1092:   Level: intermediate

1094: .keywords: mesh, section, distribute
1095: .seealso: MeshCreate()
1096: @*/
1097: PetscErrorCode SectionIntDistribute(SectionInt serialSection, Mesh parallelMesh, SectionInt *parallelSection)
1098: {
1099:   ALE::Obj<ALE::Mesh::int_section_type> oldSection;
1100:   ALE::Obj<ALE::Mesh> m;
1101:   PetscErrorCode      ierr;

1104:   SectionIntGetSection(serialSection, oldSection);
1105:   MeshGetMesh(parallelMesh, m);
1106:   SectionIntCreate(oldSection->comm(), parallelSection);
1107:   ALE::Obj<ALE::Mesh::int_section_type> newSection = ALE::Distribution<ALE::Mesh>::distributeSection(oldSection, m, m->getDistSendOverlap(), m->getDistRecvOverlap());
1108:   SectionIntSetSection(*parallelSection, newSection);
1109:   return(0);
1110: }

1114: /*@C
1115:   SectionIntRestrict - Restricts the SectionInt to a subset of the topology, returning an array of values.

1117:   Not collective

1119:   Input Parameters:
1120: + section - the section object
1121: - point - the Sieve point

1123:   Output Parameter:
1124: . values - The values associated with the submesh

1126:   Level: advanced

1128: .seealso SectionIntUpdate(), SectionIntCreate(), SectionIntView()
1129: @*/
1130: PetscErrorCode  SectionIntRestrict(SectionInt section, PetscInt point, PetscInt *values[])
1131: {
1135:   *values = (PetscInt *) section->b->restrict(section->s, point);
1136:   return(0);
1137: }

1141: /*@C
1142:   SectionIntUpdate - Updates the array of values associated to a subset of the topology in this Section.

1144:   Not collective

1146:   Input Parameters:
1147: + section - the section object
1148: . point - the Sieve point
1149: - values - The values associated with the submesh

1151:   Level: advanced

1153: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1154: @*/
1155: PetscErrorCode  SectionIntUpdate(SectionInt section, PetscInt point, const PetscInt values[])
1156: {
1160:   section->b->update(section->s, point, values);
1161:   return(0);
1162: }

1166: /*@C
1167:   SectionIntUpdateAdd - Updates the array of values associated to a subset of the topology in this Section.

1169:   Not collective

1171:   Input Parameters:
1172: + section - the section object
1173: . point - the Sieve point
1174: - values - The values associated with the submesh

1176:   Level: advanced

1178: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1179: @*/
1180: PetscErrorCode  SectionIntUpdateAdd(SectionInt section, PetscInt point, const PetscInt values[])
1181: {
1185:   section->b->updateAdd(section->s, point, values);
1186:   return(0);
1187: }

1191: /*@C
1192:   SectionIntComplete - Exchanges data across the mesh overlap.

1194:   Not collective

1196:   Input Parameter:
1197: . section - the section object

1199:   Level: advanced

1201: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1202: @*/
1203: PetscErrorCode SectionIntComplete(SectionInt section)
1204: {
1205:   Obj<ALE::Mesh::int_section_type> s;
1206:   Obj<ALE::Mesh>                   b;

1210:   SectionIntGetSection(section, s);
1211:   SectionIntGetBundle(section, b);
1212:   ALE::Distribution<ALE::Mesh>::completeSection(b, s);
1213:   return(0);
1214: }

1218: /*@C
1219:   SectionIntSetFiberDimension - Set the size of the vector space attached to the point

1221:   Not collective

1223:   Input Parameters:
1224: + section - the section object
1225: . point - the Sieve point
1226: - size - The fiber dimension

1228:   Level: advanced

1230: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1231: @*/
1232: PetscErrorCode  SectionIntSetFiberDimension(SectionInt section, PetscInt point, const PetscInt size)
1233: {
1236:   section->s->setFiberDimension(point, size);
1237:   return(0);
1238: }

1242: /*@C
1243:   SectionIntAllocate - Allocate storage for this section

1245:   Not collective

1247:   Input Parameter:
1248: . section - the section object

1250:   Level: advanced

1252: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1253: @*/
1254: PetscErrorCode  SectionIntAllocate(SectionInt section)
1255: {
1258:   section->b->allocate(section->s);
1259:   return(0);
1260: }

1264: /*@C
1265:   SectionIntClear - Dellocate storage for this section

1267:   Not collective

1269:   Input Parameter:
1270: . section - the section object

1272:   Level: advanced

1274: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1275: @*/
1276: PetscErrorCode  SectionIntClear(SectionInt section)
1277: {
1280:   section->s->clear();
1281:   return(0);
1282: }

1286: /*@C
1287:   MeshGetVertexSectionInt - Create a Section over the vertices with the specified fiber dimension

1289:   Collective on Mesh

1291:   Input Parameters:
1292: + mesh - The Mesh object
1293: - fiberDim - The section name

1295:   Output Parameter:
1296: . section - The section

1298:   Level: intermediate

1300: .keywords: mesh, section, vertex
1301: .seealso: MeshCreate(), SectionIntCreate()
1302: @*/
1303: PetscErrorCode MeshGetVertexSectionInt(Mesh mesh, PetscInt fiberDim, SectionInt *section)
1304: {
1305:   ALE::Obj<ALE::Mesh> m;
1306:   ALE::Obj<ALE::Mesh::int_section_type> s;
1307:   PetscErrorCode      ierr;

1310:   MeshGetMesh(mesh, m);
1311:   SectionIntCreate(m->comm(), section);
1312:   SectionIntSetBundle(*section, m);
1313:   SectionIntGetSection(*section, s);
1314:   s->setFiberDimension(m->depthStratum(0), fiberDim);
1315:   m->allocate(s);
1316:   return(0);
1317: }

1321: /*@C
1322:   MeshGetCellSectionInt - Create a Section over the cells with the specified fiber dimension

1324:   Collective on Mesh

1326:   Input Parameters:
1327: + mesh - The Mesh object
1328: - fiberDim - The section name

1330:   Output Parameter:
1331: . section - The section

1333:   Level: intermediate

1335: .keywords: mesh, section, cell
1336: .seealso: MeshCreate(), SectionIntCreate()
1337: @*/
1338: PetscErrorCode MeshGetCellSectionInt(Mesh mesh, PetscInt fiberDim, SectionInt *section)
1339: {
1340:   ALE::Obj<ALE::Mesh> m;
1341:   ALE::Obj<ALE::Mesh::int_section_type> s;
1342:   PetscErrorCode      ierr;

1345:   MeshGetMesh(mesh, m);
1346:   SectionIntCreate(m->comm(), section);
1347:   SectionIntSetBundle(*section, m);
1348:   SectionIntGetSection(*section, s);
1349:   s->setFiberDimension(m->heightStratum(0), fiberDim);
1350:   m->allocate(s);
1351:   return(0);
1352: }