Actual source code: section.c

  1: 
 2:  #include src/dm/mesh/meshimpl.h
 3:  #include src/dm/mesh/meshvtk.h

  5: /* Logging support */
  6: PetscCookie  SECTIONREAL_COOKIE = 0;
  7: PetscEvent  SectionReal_View = 0;
  8: PetscCookie  SECTIONINT_COOKIE = 0;
  9: PetscEvent  SectionInt_View = 0;
 10: PetscCookie  SECTIONPAIR_COOKIE = 0;
 11: PetscEvent  SectionPair_View = 0;

 15: template<typename Section>
 16: PetscErrorCode SectionView_Sieve_Ascii(const Obj<Section>& s, const char name[], PetscViewer viewer)
 17: {
 18:   // state 0: No header has been output
 19:   // state 1: Only POINT_DATA has been output
 20:   // state 2: Only CELL_DATA has been output
 21:   // state 3: Output both, POINT_DATA last
 22:   // state 4: Output both, CELL_DATA last
 23:   const ALE::Obj<ALE::Mesh::topology_type>& topology = s->getTopology();
 24:   PetscViewerFormat format;
 25:   PetscErrorCode    ierr;

 28:   PetscViewerGetFormat(viewer, &format);
 29:   if (format == PETSC_VIEWER_ASCII_VTK || format == PETSC_VIEWER_ASCII_VTK_CELL) {
 30:     static PetscInt   stateId     = -1;
 31:     PetscInt          doOutput    = 0;
 32:     PetscInt          outputState = 0;
 33:     PetscTruth        hasState;

 35:     if (stateId < 0) {
 36:       PetscObjectComposedDataRegister(&stateId);
 37:       PetscObjectComposedDataSetInt((PetscObject) viewer, stateId, 0);
 38:     }
 39:     PetscObjectComposedDataGetInt((PetscObject) viewer, stateId, outputState, hasState);
 40:     if (format == PETSC_VIEWER_ASCII_VTK) {
 41:       if (outputState == 0) {
 42:         outputState = 1;
 43:         doOutput = 1;
 44:       } else if (outputState == 1) {
 45:         doOutput = 0;
 46:       } else if (outputState == 2) {
 47:         outputState = 3;
 48:         doOutput = 1;
 49:       } else if (outputState == 3) {
 50:         doOutput = 0;
 51:       } else if (outputState == 4) {
 52:         SETERRQ(PETSC_ERR_ARG_WRONGSTATE, "Tried to output POINT_DATA again after intervening CELL_DATA");
 53:       }
 54:       const typename Section::patch_type         patch     = topology->getPatches().begin()->first;
 55:       const ALE::Obj<ALE::Mesh::numbering_type>& numbering = ALE::Mesh::NumberingFactory::singleton(s->debug())->getNumbering(topology, patch, 0);
 56:       PetscInt fiberDim = std::abs(s->getFiberDimension(patch, *topology->depthStratum(patch, 0)->begin()));

 58:       if (doOutput) {
 59:         PetscViewerASCIIPrintf(viewer, "POINT_DATA %d\n", numbering->getGlobalSize());
 60:       }
 61:       VTKViewer::writeField(s, std::string(name), fiberDim, numbering, viewer);
 62:     } else {
 63:       if (outputState == 0) {
 64:         outputState = 2;
 65:         doOutput = 1;
 66:       } else if (outputState == 1) {
 67:         outputState = 4;
 68:         doOutput = 1;
 69:       } else if (outputState == 2) {
 70:         doOutput = 0;
 71:       } else if (outputState == 3) {
 72:         SETERRQ(PETSC_ERR_ARG_WRONGSTATE, "Tried to output CELL_DATA again after intervening POINT_DATA");
 73:       } else if (outputState == 4) {
 74:         doOutput = 0;
 75:       }
 76:       const typename Section::patch_type         patch     = topology->getPatches().begin()->first;
 77:       const ALE::Obj<ALE::Mesh::numbering_type>& numbering = ALE::Mesh::NumberingFactory::singleton(s->debug())->getNumbering(topology, patch, topology->depth());
 78:       PetscInt fiberDim = s->getFiberDimension(patch, *topology->heightStratum(patch, 0)->begin());

 80:       if (doOutput) {
 81:         PetscViewerASCIIPrintf(viewer, "CELL_DATA %d\n", numbering->getGlobalSize());
 82:       }
 83:       VTKViewer::writeField(s, std::string(name), fiberDim, numbering, viewer);
 84:     }
 85:     PetscObjectComposedDataSetInt((PetscObject) viewer, stateId, outputState);
 86:   } else {
 87:     s->view(name);
 88:   }
 89:   return(0);
 90: }

 94: PetscErrorCode SectionRealView_Sieve(SectionReal section, PetscViewer viewer)
 95: {
 96:   PetscTruth     iascii, isbinary, isdraw;

100:   PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_ASCII, &iascii);
101:   PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &isbinary);
102:   PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_DRAW, &isdraw);

104:   if (iascii){
105:     ALE::Obj<ALE::Mesh::real_section_type> s;
106:     const char                            *name;

108:     SectionRealGetSection(section, s);
109:     PetscObjectGetName((PetscObject) section, &name);
110:     SectionView_Sieve_Ascii(s, name, viewer);
111:   } else if (isbinary) {
112:     SETERRQ(PETSC_ERR_SUP, "Binary viewer not implemented for Section");
113:   } else if (isdraw){
114:     SETERRQ(PETSC_ERR_SUP, "Draw viewer not implemented for Section");
115:   } else {
116:     SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported by this section object", ((PetscObject)viewer)->type_name);
117:   }
118:   return(0);
119: }

123: /*@C
124:    SectionRealView - Views a Section object. 

126:    Collective on Section

128:    Input Parameters:
129: +  section - the Section
130: -  viewer - an optional visualization context

132:    Notes:
133:    The available visualization contexts include
134: +     PETSC_VIEWER_STDOUT_SELF - standard output (default)
135: -     PETSC_VIEWER_STDOUT_WORLD - synchronized standard
136:          output where only the first processor opens
137:          the file.  All other processors send their 
138:          data to the first processor to print. 

140:    You can change the format the section is printed using the 
141:    option PetscViewerSetFormat().

143:    The user can open alternative visualization contexts with
144: +    PetscViewerASCIIOpen() - Outputs section to a specified file
145: .    PetscViewerBinaryOpen() - Outputs section in binary to a
146:          specified file; corresponding input uses SectionLoad()
147: .    PetscViewerDrawOpen() - Outputs section to an X window display

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

155:    Level: beginner

157:    Concepts: section^printing
158:    Concepts: section^saving to disk

160: .seealso: VecView(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerBinaryOpen(), PetscViewerCreate()
161: @*/
162: PetscErrorCode SectionRealView(SectionReal section, PetscViewer viewer)
163: {

169:   if (!viewer) {
170:     PetscViewerASCIIGetStdout(section->comm,&viewer);
171:   }

176:   (*section->ops->view)(section, viewer);
178:   return(0);
179: }

183: /*@C
184:   SectionRealDuplicate - Create an equivalent Section object

186:   Not collective

188:   Input Parameter:
189: . section - the section object

191:   Output Parameter:
192: . newSection - the duplicate
193:  
194:   Level: advanced

196: .seealso SectionRealCreate(), SectionRealSetSection()
197: @*/
198: PetscErrorCode  SectionRealDuplicate(SectionReal section, SectionReal *newSection)
199: {

205:   const ALE::Obj<ALE::Mesh::real_section_type>& s = section->s;
206:   ALE::Obj<ALE::Mesh::real_section_type>        t = new ALE::Mesh::real_section_type(s->getTopology());

208:   t->setAtlas(s->getAtlas());
209:   t->allocateStorage();
210:   t->copyBC(s);
211:   SectionRealCreate(s->comm(), newSection);
212:   SectionRealSetSection(*newSection, t);
213:   return(0);
214: }

218: /*@C
219:   SectionRealGetSection - Gets the internal section object

221:   Not collective

223:   Input Parameter:
224: . section - the section object

226:   Output Parameter:
227: . s - the internal section object
228:  
229:   Level: advanced

231: .seealso SectionRealCreate(), SectionRealSetSection()
232: @*/
233: PetscErrorCode  SectionRealGetSection(SectionReal section, ALE::Obj<ALE::Mesh::real_section_type>& s)
234: {
237:   s = section->s;
238:   return(0);
239: }

243: /*@C
244:   SectionRealSetSection - Sets the internal section object

246:   Not collective

248:   Input Parameters:
249: + section - the section object
250: - s - the internal section object
251:  
252:   Level: advanced

254: .seealso SectionRealCreate(), SectionRealGetSection()
255: @*/
256: PetscErrorCode  SectionRealSetSection(SectionReal section, const ALE::Obj<ALE::Mesh::real_section_type>& s)
257: {
260:   section->s = s;
261:   return(0);
262: }

266: /*@C
267:   SectionRealGetTopology - Gets the internal section topology

269:   Not collective

271:   Input Parameter:
272: . section - the section object

274:   Output Parameter:
275: . t - the internal section topology
276:  
277:   Level: advanced

279: .seealso SectionRealCreate(), SectionRealGetSection(), SectionRealSetSection()
280: @*/
281: PetscErrorCode  SectionRealGetTopology(SectionReal section, ALE::Obj<ALE::Mesh::topology_type>& t)
282: {
285:   t = section->s->getTopology();
286:   return(0);
287: }

291: /*@C
292:   SectionRealSetTopology - Sets the internal section topology

294:   Not collective

296:   Input Parameters:
297: + section - the section object
298: - t - the internal section topology
299:  
300:   Level: advanced

302: .seealso SectionRealCreate(), SectionRealGetSection(), SectionRealSetSection()
303: @*/
304: PetscErrorCode  SectionRealSetTopology(SectionReal section, const ALE::Obj<ALE::Mesh::topology_type>& t)
305: {
308:   section->s->setTopology(t);
309:   return(0);
310: }

314: /*@C
315:   SectionRealCreate - Creates a Section object, used to manage data for an unstructured problem
316:   described by a Sieve.

318:   Collective on MPI_Comm

320:   Input Parameter:
321: . comm - the processors that will share the global section

323:   Output Parameters:
324: . section - the section object

326:   Level: advanced

328: .seealso SectionRealDestroy(), SectionRealView()
329: @*/
330: PetscErrorCode  SectionRealCreate(MPI_Comm comm, SectionReal *section)
331: {
333:   SectionReal    s;

337:   *section = PETSC_NULL;

339:   PetscHeaderCreate(s,_p_SectionReal,struct _SectionRealOps,SECTIONREAL_COOKIE,0,"SectionReal",comm,SectionRealDestroy,0);
340:   s->ops->view     = SectionRealView_Sieve;
341:   s->ops->restrict = SectionRealRestrict;
342:   s->ops->update   = SectionRealUpdate;

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

346:   s->s             = new ALE::Mesh::real_section_type(comm);
347:   *section = s;
348:   return(0);
349: }

353: /*@C
354:   SectionRealDestroy - Destroys a section.

356:   Collective on Section

358:   Input Parameter:
359: . section - the section object

361:   Level: advanced

363: .seealso SectionRealCreate(), SectionRealView()
364: @*/
365: PetscErrorCode  SectionRealDestroy(SectionReal section)
366: {

371:   if (--section->refct > 0) return(0);
372:   section->s = PETSC_NULL;
373:   PetscHeaderDestroy(section);
374:   return(0);
375: }

379: /*@C
380:   SectionRealDistribute - Distributes the sections.

382:   Not Collective

384:   Input Parameters:
385: + serialSection - The original Section object
386: - parallelMesh - The parallel Mesh

388:   Output Parameter:
389: . parallelSection - The distributed Section object

391:   Level: intermediate

393: .keywords: mesh, section, distribute
394: .seealso: MeshCreate()
395: @*/
396: PetscErrorCode SectionRealDistribute(SectionReal serialSection, Mesh parallelMesh, SectionReal *parallelSection)
397: {
398:   ALE::Obj<ALE::Mesh::real_section_type> oldSection;
399:   ALE::Obj<ALE::Mesh>               m;

403:   SectionRealGetSection(serialSection, oldSection);
404:   MeshGetMesh(parallelMesh, m);
405:   SectionRealCreate(oldSection->comm(), parallelSection);
406:   ALE::Obj<ALE::Mesh::real_section_type> newSection = ALE::New::Distribution<ALE::Mesh::topology_type>::distributeSection(oldSection, m->getTopology(), m->getTopology()->getDistSendOverlap(), m->getTopology()->getDistRecvOverlap());
407:   SectionRealSetSection(*parallelSection, newSection);
408:   return(0);
409: }

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

416:   Not collective

418:   Input Parameters:
419: + section - the section object
420: - point - the Sieve point

422:   Output Parameter:
423: . values - The values associated with the submesh

425:   Level: advanced

427: .seealso SectionUpdate(), SectionCreate(), SectionView()
428: @*/
429: PetscErrorCode  SectionRealRestrict(SectionReal section, PetscInt point, PetscScalar *values[])
430: {
434:   *values = (PetscScalar *) section->s->restrict(0, point);
435:   return(0);
436: }

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

443:   Not collective

445:   Input Parameters:
446: + section - the section object
447: . point - the Sieve point
448: - values - The values associated with the submesh

450:   Level: advanced

452: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
453: @*/
454: PetscErrorCode  SectionRealUpdate(SectionReal section, PetscInt point, const PetscScalar values[])
455: {
459:   section->s->update(0, point, values);
460:   return(0);
461: }

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

468:   Not collective

470:   Input Parameters:
471: + section - the section object
472: . point - the Sieve point
473: - values - The values associated with the submesh

475:   Level: advanced

477: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
478: @*/
479: PetscErrorCode  SectionRealUpdateAdd(SectionReal section, PetscInt point, const PetscScalar values[])
480: {
484:   section->s->updateAdd(0, point, values);
485:   return(0);
486: }

490: /*@C
491:   SectionRealComplete - Exchanges data across the mesh overlap.

493:   Not collective

495:   Input Parameter:
496: . section - the section object

498:   Level: advanced

500: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
501: @*/
502: PetscErrorCode SectionRealComplete(SectionReal section)
503: {
504:   Obj<ALE::Mesh::real_section_type> s;

508:   SectionRealGetSection(section, s);
509:   ALE::New::Distribution<ALE::Mesh::topology_type>::completeSection(s);
510:   return(0);
511: }

515: /*@C
516:   SectionRealGetLocalVector - Retrieves the local section storage as a Vec

518:   Not collective

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

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

526:   Level: advanced

528: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
529: @*/
530: PetscErrorCode SectionRealGetLocalVector(SectionReal section, Vec *lv)
531: {
532:   const ALE::Mesh::real_section_type::patch_type patch = 0;
533:   Obj<ALE::Mesh::real_section_type> s;

537:   SectionRealGetSection(section, s);
538:   VecCreateSeqWithArray(PETSC_COMM_SELF, s->size(patch), s->restrict(patch), lv);
539:   return(0);
540: }

544: /*@C
545:   SectionRealZero - Zero out the entries

547:   Not collective

549:   Input Parameter:
550: . section - the section object

552:   Level: advanced

554: .seealso SectionRealRestrict(), SectionRealCreate(), SectionRealView()
555: @*/
556: PetscErrorCode SectionRealZero(SectionReal section)
557: {
558:   const ALE::Mesh::real_section_type::patch_type patch = 0;
559:   Obj<ALE::Mesh::real_section_type> s;

563:   SectionRealGetSection(section, s);
564:   s->zero(patch);
565:   return(0);
566: }

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

573:   Collective on Mesh

575:   Input Parameters:
576: + mesh - The Mesh object
577: - fiberDim - The section name

579:   Output Parameter:
580: . section - The section

582:   Level: intermediate

584: .keywords: mesh, section, vertex
585: .seealso: MeshCreate(), SectionRealCreate()
586: @*/
587: PetscErrorCode MeshGetVertexSectionReal(Mesh mesh, PetscInt fiberDim, SectionReal *section)
588: {
589:   ALE::Obj<ALE::Mesh> m;
590:   ALE::Obj<ALE::Mesh::real_section_type> s;
591:   PetscErrorCode      ierr;

594:   MeshGetMesh(mesh, m);
595:   SectionRealCreate(m->comm(), section);
596:   SectionRealSetTopology(*section, m->getTopology());
597:   SectionRealGetSection(*section, s);
598:   s->setFiberDimensionByDepth(0, 0, fiberDim);
599:   s->allocate();
600:   return(0);
601: }

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

608:   Collective on Mesh

610:   Input Parameters:
611: + mesh - The Mesh object
612: - fiberDim - The section name

614:   Output Parameter:
615: . section - The section

617:   Level: intermediate

619: .keywords: mesh, section, cell
620: .seealso: MeshCreate(), SectionRealCreate()
621: @*/
622: PetscErrorCode MeshGetCellSectionReal(Mesh mesh, PetscInt fiberDim, SectionReal *section)
623: {
624:   ALE::Obj<ALE::Mesh> m;
625:   ALE::Obj<ALE::Mesh::real_section_type> s;
626:   PetscErrorCode      ierr;

629:   MeshGetMesh(mesh, m);
630:   SectionRealCreate(m->comm(), section);
631:   SectionRealSetTopology(*section, m->getTopology());
632:   SectionRealGetSection(*section, s);
633:   s->setFiberDimensionByHeight(0, 0, fiberDim);
634:   s->allocate();
635:   return(0);
636: }

640: PetscErrorCode SectionIntView_Sieve(SectionInt section, PetscViewer viewer)
641: {
642:   PetscTruth     iascii, isbinary, isdraw;

646:   PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_ASCII, &iascii);
647:   PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &isbinary);
648:   PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_DRAW, &isdraw);

650:   if (iascii){
651:     ALE::Obj<ALE::Mesh::int_section_type> s;
652:     const char                           *name;

654:     SectionIntGetSection(section, s);
655:     PetscObjectGetName((PetscObject) section, &name);
656:     SectionView_Sieve_Ascii(s, name, viewer);
657:   } else if (isbinary) {
658:     SETERRQ(PETSC_ERR_SUP, "Binary viewer not implemented for Section");
659:   } else if (isdraw){
660:     SETERRQ(PETSC_ERR_SUP, "Draw viewer not implemented for Section");
661:   } else {
662:     SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported by this section object", ((PetscObject)viewer)->type_name);
663:   }
664:   return(0);
665: }

669: /*@C
670:    SectionIntView - Views a Section object. 

672:    Collective on Section

674:    Input Parameters:
675: +  section - the Section
676: -  viewer - an optional visualization context

678:    Notes:
679:    The available visualization contexts include
680: +     PETSC_VIEWER_STDOUT_SELF - standard output (default)
681: -     PETSC_VIEWER_STDOUT_WORLD - synchronized standard
682:          output where only the first processor opens
683:          the file.  All other processors send their 
684:          data to the first processor to print. 

686:    You can change the format the section is printed using the 
687:    option PetscViewerSetFormat().

689:    The user can open alternative visualization contexts with
690: +    PetscViewerASCIIOpen() - Outputs section to a specified file
691: .    PetscViewerBinaryOpen() - Outputs section in binary to a
692:          specified file; corresponding input uses SectionLoad()
693: .    PetscViewerDrawOpen() - Outputs section to an X window display

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

701:    Level: beginner

703:    Concepts: section^printing
704:    Concepts: section^saving to disk

706: .seealso: VecView(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerBinaryOpen(), PetscViewerCreate()
707: @*/
708: PetscErrorCode SectionIntView(SectionInt section, PetscViewer viewer)
709: {

715:   if (!viewer) {
716:     PetscViewerASCIIGetStdout(section->comm,&viewer);
717:   }

722:   (*section->ops->view)(section, viewer);
724:   return(0);
725: }

729: /*@C
730:   SectionIntGetSection - Gets the internal section object

732:   Not collective

734:   Input Parameter:
735: . section - the section object

737:   Output Parameter:
738: . s - the internal section object
739:  
740:   Level: advanced

742: .seealso SectionIntCreate(), SectionIntSetSection()
743: @*/
744: PetscErrorCode  SectionIntGetSection(SectionInt section, ALE::Obj<ALE::Mesh::int_section_type>& s)
745: {
748:   s = section->s;
749:   return(0);
750: }

754: /*@C
755:   SectionIntSetSection - Sets the internal section object

757:   Not collective

759:   Input Parameters:
760: + section - the section object
761: - s - the internal section object
762:  
763:   Level: advanced

765: .seealso SectionIntCreate(), SectionIntGetSection()
766: @*/
767: PetscErrorCode  SectionIntSetSection(SectionInt section, const ALE::Obj<ALE::Mesh::int_section_type>& s)
768: {
771:   section->s = s;
772:   return(0);
773: }

777: /*@C
778:   SectionIntGetTopology - Gets the internal section topology

780:   Not collective

782:   Input Parameter:
783: . section - the section object

785:   Output Parameter:
786: . t - the internal section topology
787:  
788:   Level: advanced

790: .seealso SectionIntCreate(), SectionIntGetSection(), SectionIntSetSection()
791: @*/
792: PetscErrorCode  SectionIntGetTopology(SectionInt section, ALE::Obj<ALE::Mesh::topology_type>& t)
793: {
796:   t = section->s->getTopology();
797:   return(0);
798: }

802: /*@C
803:   SectionIntSetTopology - Sets the internal section topology

805:   Not collective

807:   Input Parameters:
808: + section - the section object
809: - t - the internal section topology
810:  
811:   Level: advanced

813: .seealso SectionIntCreate(), SectionIntGetSection(), SectionIntSetSection()
814: @*/
815: PetscErrorCode  SectionIntSetTopology(SectionInt section, const ALE::Obj<ALE::Mesh::topology_type>& t)
816: {
819:   section->s->setTopology(t);
820:   return(0);
821: }

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

829:   Collective on MPI_Comm

831:   Input Parameter:
832: . comm - the processors that will share the global section

834:   Output Parameters:
835: . section - the section object

837:   Level: advanced

839: .seealso SectionIntDestroy(), SectionIntView()
840: @*/
841: PetscErrorCode  SectionIntCreate(MPI_Comm comm, SectionInt *section)
842: {
844:   SectionInt    s;

848:   *section = PETSC_NULL;

850:   PetscHeaderCreate(s,_p_SectionInt,struct _SectionIntOps,SECTIONINT_COOKIE,0,"SectionInt",comm,SectionIntDestroy,0);
851:   s->ops->view     = SectionIntView_Sieve;
852:   s->ops->restrict = SectionIntRestrict;
853:   s->ops->update   = SectionIntUpdate;

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

857:   s->s             = new ALE::Mesh::int_section_type(comm);
858:   *section = s;
859:   return(0);
860: }

864: /*@C
865:   SectionIntDestroy - Destroys a section.

867:   Collective on Section

869:   Input Parameter:
870: . section - the section object

872:   Level: advanced

874: .seealso SectionIntCreate(), SectionIntView()
875: @*/
876: PetscErrorCode  SectionIntDestroy(SectionInt section)
877: {

882:   if (--section->refct > 0) return(0);
883:   section->s = PETSC_NULL;
884:   PetscHeaderDestroy(section);
885:   return(0);
886: }

890: /*@C
891:   SectionIntDistribute - Distributes the sections.

893:   Not Collective

895:   Input Parameters:
896: + serialSection - The original Section object
897: - parallelMesh - The parallel Mesh

899:   Output Parameter:
900: . parallelSection - The distributed Section object

902:   Level: intermediate

904: .keywords: mesh, section, distribute
905: .seealso: MeshCreate()
906: @*/
907: PetscErrorCode SectionIntDistribute(SectionInt serialSection, Mesh parallelMesh, SectionInt *parallelSection)
908: {
909:   ALE::Obj<ALE::Mesh::int_section_type> oldSection;
910:   ALE::Obj<ALE::Mesh> m;
911:   PetscErrorCode      ierr;

914:   SectionIntGetSection(serialSection, oldSection);
915:   MeshGetMesh(parallelMesh, m);
916:   SectionIntCreate(oldSection->comm(), parallelSection);
917:   ALE::Obj<ALE::Mesh::int_section_type> newSection = ALE::New::Distribution<ALE::Mesh::topology_type>::distributeSection(oldSection, m->getTopology(), m->getTopology()->getDistSendOverlap(), m->getTopology()->getDistRecvOverlap());
918:   SectionIntSetSection(*parallelSection, newSection);
919:   return(0);
920: }

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

927:   Not collective

929:   Input Parameters:
930: + section - the section object
931: - point - the Sieve point

933:   Output Parameter:
934: . values - The values associated with the submesh

936:   Level: advanced

938: .seealso SectionIntUpdate(), SectionIntCreate(), SectionIntView()
939: @*/
940: PetscErrorCode  SectionIntRestrict(SectionInt section, PetscInt point, PetscInt *values[])
941: {
945:   *values = (PetscInt *) section->s->restrict(0, point);
946:   return(0);
947: }

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

954:   Not collective

956:   Input Parameters:
957: + section - the section object
958: . point - the Sieve point
959: - values - The values associated with the submesh

961:   Level: advanced

963: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
964: @*/
965: PetscErrorCode  SectionIntUpdate(SectionInt section, PetscInt point, const PetscInt values[])
966: {
970:   section->s->update(0, point, values);
971:   return(0);
972: }

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

979:   Not collective

981:   Input Parameters:
982: + section - the section object
983: . point - the Sieve point
984: - values - The values associated with the submesh

986:   Level: advanced

988: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
989: @*/
990: PetscErrorCode  SectionIntUpdateAdd(SectionInt section, PetscInt point, const PetscInt values[])
991: {
995:   section->s->updateAdd(0, point, values);
996:   return(0);
997: }

1001: /*@C
1002:   SectionIntComplete - Exchanges data across the mesh overlap.

1004:   Not collective

1006:   Input Parameter:
1007: . section - the section object

1009:   Level: advanced

1011: .seealso SectionIntRestrict(), SectionIntCreate(), SectionIntView()
1012: @*/
1013: PetscErrorCode SectionIntComplete(SectionInt section)
1014: {
1015:   Obj<ALE::Mesh::int_section_type> s;

1019:   SectionIntGetSection(section, s);
1020:   ALE::New::Distribution<ALE::Mesh::topology_type>::completeSection(s);
1021:   return(0);
1022: }

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

1029:   Collective on Mesh

1031:   Input Parameters:
1032: + mesh - The Mesh object
1033: - fiberDim - The section name

1035:   Output Parameter:
1036: . section - The section

1038:   Level: intermediate

1040: .keywords: mesh, section, vertex
1041: .seealso: MeshCreate(), SectionIntCreate()
1042: @*/
1043: PetscErrorCode MeshGetVertexSectionInt(Mesh mesh, PetscInt fiberDim, SectionInt *section)
1044: {
1045:   ALE::Obj<ALE::Mesh> m;
1046:   ALE::Obj<ALE::Mesh::int_section_type> s;
1047:   PetscErrorCode      ierr;

1050:   MeshGetMesh(mesh, m);
1051:   SectionIntCreate(m->comm(), section);
1052:   SectionIntSetTopology(*section, m->getTopology());
1053:   SectionIntGetSection(*section, s);
1054:   s->setFiberDimensionByDepth(0, 0, fiberDim);
1055:   s->allocate();
1056:   return(0);
1057: }

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

1064:   Collective on Mesh

1066:   Input Parameters:
1067: + mesh - The Mesh object
1068: - fiberDim - The section name

1070:   Output Parameter:
1071: . section - The section

1073:   Level: intermediate

1075: .keywords: mesh, section, cell
1076: .seealso: MeshCreate(), SectionIntCreate()
1077: @*/
1078: PetscErrorCode MeshGetCellSectionInt(Mesh mesh, PetscInt fiberDim, SectionInt *section)
1079: {
1080:   ALE::Obj<ALE::Mesh> m;
1081:   ALE::Obj<ALE::Mesh::int_section_type> s;
1082:   PetscErrorCode      ierr;

1085:   MeshGetMesh(mesh, m);
1086:   SectionIntCreate(m->comm(), section);
1087:   SectionIntSetTopology(*section, m->getTopology());
1088:   SectionIntGetSection(*section, s);
1089:   s->setFiberDimensionByHeight(0, 0, fiberDim);
1090:   s->allocate();
1091:   return(0);
1092: }

1096: PetscErrorCode SectionPairView_Sieve(SectionPair section, PetscViewer viewer)
1097: {
1098:   PetscTruth     iascii, isbinary, isdraw;

1102:   PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_ASCII, &iascii);
1103:   PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &isbinary);
1104:   PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_DRAW, &isdraw);

1106:   if (iascii){
1107:     ALE::Obj<ALE::Mesh::pair_section_type> s;
1108:     const char                            *name;

1110:     SectionPairGetSection(section, s);
1111:     PetscObjectGetName((PetscObject) section, &name);
1112:     //FIX SectionView_Sieve_Ascii(s, name, viewer);
1113:   } else if (isbinary) {
1114:     SETERRQ(PETSC_ERR_SUP, "Binary viewer not implemented for Section");
1115:   } else if (isdraw){
1116:     SETERRQ(PETSC_ERR_SUP, "Draw viewer not implemented for Section");
1117:   } else {
1118:     SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported by this section object", ((PetscObject)viewer)->type_name);
1119:   }
1120:   return(0);
1121: }

1125: /*@C
1126:    SectionPairView - Views a Section object. 

1128:    Collective on Section

1130:    Input Parameters:
1131: +  section - the Section
1132: -  viewer - an optional visualization context

1134:    Notes:
1135:    The available visualization contexts include
1136: +     PETSC_VIEWER_STDOUT_SELF - standard output (default)
1137: -     PETSC_VIEWER_STDOUT_WORLD - synchronized standard
1138:          output where only the first processor opens
1139:          the file.  All other processors send their 
1140:          data to the first processor to print. 

1142:    You can change the format the section is printed using the 
1143:    option PetscViewerSetFormat().

1145:    The user can open alternative visualization contexts with
1146: +    PetscViewerASCIIOpen() - Outputs section to a specified file
1147: .    PetscViewerBinaryOpen() - Outputs section in binary to a
1148:          specified file; corresponding input uses SectionLoad()
1149: .    PetscViewerDrawOpen() - Outputs section to an X window display

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

1157:    Level: beginner

1159:    Concepts: section^printing
1160:    Concepts: section^saving to disk

1162: .seealso: VecView(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), PetscViewerBinaryOpen(), PetscViewerCreate()
1163: @*/
1164: PetscErrorCode SectionPairView(SectionPair section, PetscViewer viewer)
1165: {

1171:   if (!viewer) {
1172:     PetscViewerASCIIGetStdout(section->comm,&viewer);
1173:   }

1178:   (*section->ops->view)(section, viewer);
1180:   return(0);
1181: }

1185: /*@C
1186:   SectionPairGetSection - Gets the internal section object

1188:   Not collective

1190:   Input Parameter:
1191: . section - the section object

1193:   Output Parameter:
1194: . s - the internal section object
1195:  
1196:   Level: advanced

1198: .seealso SectionPairCreate(), SectionPairSetSection()
1199: @*/
1200: PetscErrorCode  SectionPairGetSection(SectionPair section, ALE::Obj<ALE::Mesh::pair_section_type>& s)
1201: {
1204:   s = section->s;
1205:   return(0);
1206: }

1210: /*@C
1211:   SectionPairSetSection - Sets the internal section object

1213:   Not collective

1215:   Input Parameters:
1216: + section - the section object
1217: - s - the internal section object
1218:  
1219:   Level: advanced

1221: .seealso SectionPairCreate(), SectionPairGetSection()
1222: @*/
1223: PetscErrorCode  SectionPairSetSection(SectionPair section, const ALE::Obj<ALE::Mesh::pair_section_type>& s)
1224: {
1227:   section->s = s;
1228:   return(0);
1229: }

1233: /*@C
1234:   SectionPairGetTopology - Gets the internal section topology

1236:   Not collective

1238:   Input Parameter:
1239: . section - the section object

1241:   Output Parameter:
1242: . t - the internal section topology
1243:  
1244:   Level: advanced

1246: .seealso SectionPairCreate(), SectionPairGetSection(), SectionPairSetSection()
1247: @*/
1248: PetscErrorCode  SectionPairGetTopology(SectionPair section, ALE::Obj<ALE::Mesh::topology_type>& t)
1249: {
1252:   t = section->s->getTopology();
1253:   return(0);
1254: }

1258: /*@C
1259:   SectionPairSetTopology - Sets the internal section topology

1261:   Not collective

1263:   Input Parameters:
1264: + section - the section object
1265: - t - the internal section topology
1266:  
1267:   Level: advanced

1269: .seealso SectionPairCreate(), SectionPairGetSection(), SectionPairSetSection()
1270: @*/
1271: PetscErrorCode  SectionPairSetTopology(SectionPair section, const ALE::Obj<ALE::Mesh::topology_type>& t)
1272: {
1275:   section->s->setTopology(t);
1276:   return(0);
1277: }

1281: /*@C
1282:   SectionPairCreate - Creates a Section object, used to manage data for an unstructured problem
1283:   described by a Sieve.

1285:   Collective on MPI_Comm

1287:   Input Parameter:
1288: . comm - the processors that will share the global section

1290:   Output Parameters:
1291: . section - the section object

1293:   Level: advanced

1295: .seealso SectionPairDestroy(), SectionPairView()
1296: @*/
1297: PetscErrorCode  SectionPairCreate(MPI_Comm comm, SectionPair *section)
1298: {
1300:   SectionPair    s;

1304:   *section = PETSC_NULL;

1306:   PetscHeaderCreate(s,_p_SectionPair,struct _SectionPairOps,SECTIONPAIR_COOKIE,0,"SectionPair",comm,SectionPairDestroy,0);
1307:   s->ops->view     = SectionPairView_Sieve;
1308:   s->ops->restrict = SectionPairRestrict;
1309:   s->ops->update   = SectionPairUpdate;

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

1313:   s->s             = new ALE::Mesh::pair_section_type(comm);
1314:   *section = s;
1315:   return(0);
1316: }

1320: /*@C
1321:   SectionPairDestroy - Destroys a section.

1323:   Collective on Section

1325:   Input Parameter:
1326: . section - the section object

1328:   Level: advanced

1330: .seealso SectionPairCreate(), SectionPairView()
1331: @*/
1332: PetscErrorCode  SectionPairDestroy(SectionPair section)
1333: {

1338:   if (--section->refct > 0) return(0);
1339:   section->s = PETSC_NULL;
1340:   PetscHeaderDestroy(section);
1341:   return(0);
1342: }

1346: /*@C
1347:   SectionPairDistribute - Distributes the sections.

1349:   Not Collective

1351:   Input Parameters:
1352: + serialSection - The original Section object
1353: - parallelMesh - The parallel Mesh

1355:   Output Parameter:
1356: . parallelSection - The distributed Section object

1358:   Level: intermediate

1360: .keywords: mesh, section, distribute
1361: .seealso: MeshCreate()
1362: @*/
1363: PetscErrorCode SectionPairDistribute(SectionPair serialSection, Mesh parallelMesh, SectionPair *parallelSection)
1364: {
1365:   ALE::Obj<ALE::Mesh::pair_section_type> oldSection;
1366:   ALE::Obj<ALE::Mesh> m;
1367:   PetscErrorCode      ierr;

1370:   SectionPairGetSection(serialSection, oldSection);
1371:   MeshGetMesh(parallelMesh, m);
1372:   SectionPairCreate(oldSection->comm(), parallelSection);
1373:   ALE::Obj<ALE::Mesh::pair_section_type> newSection = ALE::New::Distribution<ALE::Mesh::topology_type>::distributeSection(oldSection, m->getTopology(), m->getTopology()->getDistSendOverlap(), m->getTopology()->getDistRecvOverlap());
1374:   SectionPairSetSection(*parallelSection, newSection);
1375:   return(0);
1376: }

1380: /*@C
1381:   SectionPairRestrict - Restricts the SectionPair to a subset of the topology, returning an array of values.

1383:   Not collective

1385:   Input Parameters:
1386: + section - the section object
1387: - point - the Sieve point

1389:   Output Parameter:
1390: . values - The values associated with the submesh

1392:   Level: advanced

1394: .seealso SectionUpdate(), SectionCreate(), SectionView()
1395: @*/
1396: PetscErrorCode  SectionPairRestrict(SectionPair section, PetscInt point, PetscPair *values[])
1397: {
1401:   *values = (PetscPair *) section->s->restrict(0, point);
1402:   return(0);
1403: }

1407: /*@C
1408:   SectionPairUpdate - Updates the array of values associated to a subset of the topology in this Section.

1410:   Not collective

1412:   Input Parameters:
1413: + section - the section object
1414: . point - the Sieve point
1415: - values - The values associated with the submesh

1417:   Level: advanced

1419: .seealso SectionPairRestrict(), SectionPairCreate(), SectionPairView()
1420: @*/
1421: PetscErrorCode  SectionPairUpdate(SectionPair section, PetscInt point, const PetscPair values[])
1422: {
1426:   section->s->update(0, point, (ALE::pair<int, ALE::Mesh::split_value> *) values);
1427:   return(0);
1428: }