Overture  Version 25
UnstructuredMapping.h
Go to the documentation of this file.
1 #ifndef UNSTRUCTURED_MAPPING_H
2 #define UNSTRUCTURED_MAPPING_H
3 
4 #include "OvertureDefine.h"
5 
6 #ifndef OV_USE_OLD_STL_HEADERS
7 #include <map>
8 #include <list>
9 #include <string>
10 #include <vector>
11 #else
12 #include <map.h>
13 #include <list.h>
14 #include <string>
15 #include <vector.h>
16 #endif
17 
18 #include "Mapping.h"
19 #include "EntityTag.h"
20 #include "ArraySimple.h"
21 // #include "CompositeGrid.h"
22 
24 class CompositeSurface;
25 class GeometricADT3dInt;
26 class CompositeGrid;
29 
30 
31 
32 //-------------------------------------------------------------
33 // Define a Mapping for unstructured surfaces and volumes
34 //-------------------------------------------------------------
36 {
37 
38 public:
39 
41  {
42  Invalid=-1,
43  Vertex=0,
47  Mesh, // kkc put this here to enable "Mesh" tagging...
49  };
50 
53 
55  {
66  };
67 
70 
71  class IDTuple
72  {
73  public:
75 
76  inline IDTuple(EntityTypeEnum et_=Invalid, int e_=-1) : et(et_), e(e_) { }
77  inline IDTuple( const IDTuple &id ) : et(id.et), e(id.e) { }
78  inline ~IDTuple() {}
79 
80  inline bool operator< ( const IDTuple & id ) const
81  { return et<id.et ? true : ( et==id.et ? e<id.e : false) ; }
82 
83  inline bool operator< ( const IDTuple & id )
84  { return et<id.et ? true : ( et==id.et ? e<id.e : false) ; }
85 
86  inline bool operator== ( const IDTuple & id ) const
87  { return (et==id.et && e==id.e); }
88 
89  inline bool operator== ( const IDTuple & id )
90  { return (et==id.et && e==id.e); }
91 
92  inline bool operator!= ( const IDTuple & id ) const
93  { return !(*this==id); }
94 
95  inline bool operator!= ( const IDTuple & id )
96  { return !(*this==id); }
97 
98  };
99 
100  struct TagError { }; // for exception handling
101 
103 
104  UnstructuredMapping(int domainDimension_ /* =3 */,
105  int rangeDimension_ /* =3 */,
106  mappingSpace domainSpace_ /* =parameterSpace */,
107  mappingSpace rangeSpace_ /* =cartesianSpace */ );
108 
109  // Copy constructor is deep by default
110  UnstructuredMapping( const UnstructuredMapping &, const CopyType copyType=DEEP );
111 
113 
115 
116  void addGhostElements( bool trueOrFalse=true );
117  //
118  // overload of this method, it doesn't really make sense for UnstructuredMappings (?)
119  // watch out, the base class method Mapping::getGrid actually calls Mapping::map, which
120  // is private in UnstructuredMapping since it makes little sense.
121  //
123  bool includeGhost=false) { return node; }
124 
125  int getNumberOfNodes() const;
126 
127  int getNumberOfElements() const;
128 
129  int getNumberOfFaces() const;
130 
131  int getNumberOfEdges() const;
132 
133  int getMaxNumberOfNodesPerElement() const;
134 
135  int getMaxNumberOfFacesPerElement() const;
136 
137  int getMaxNumberOfNodesPerFace() const;
138 
139  int getNumberOfBoundaryFaces() const;
140 
141  inline int size( EntityTypeEnum t ) const { return t<Mesh ? entitySize[int(t)] : 1; }
142  inline int capacity( EntityTypeEnum t ) const { return t<Mesh ? entityCapacity[int(t)] : 1; }
143  int reserve( EntityTypeEnum, int);
144 
145  void setPreferTriangles( bool trueOrFalse=true ){ preferTriangles=trueOrFalse;}
147 
148  const realArray & getNodes() const;
149  const intArray & getElements() const;
150  const intArray & getFaces();
151  const intArray & getFaceElements();
152  const intArray & getEdges();
153  const intArray & getTags();
154  const intArray & getElementFaces();
155  const intArray & getBoundaryFace();
156  const intArray & getBoundaryFaceTags();
157 
158  const intArray & getEntities(EntityTypeEnum);
159  const intArray & getEntityAdjacencyIndices(EntityTypeEnum from, EntityTypeEnum to, intArray &offsets);
160 
161  const intArray & getGhostElements() const;
162  const intArray & getMask(EntityTypeEnum entityType) const;
163 
164  // dynamically created connectivities
165  void createNodeElementList(intArray &nodeElementList);
166 
167  // iteration helpers
168  inline int getNumberOfNodesThisElement(int element) const;
169  inline int getNumberOfNodesThisFace(int face_) const;
170  inline int getBoundaryFace(int bdyface_) const;
171  inline int getBoundaryFaceTag(int bdyface_) const;
172  inline int elementGlobalVertex(int element, int vertex) const;
173  inline int faceGlobalVertex(int face, int vertex) const;
174  inline int getNumberOfFacesThisElement(int element_) const;
175 
176  inline UnstructuredMappingIterator begin(EntityTypeEnum entityType_, bool skipGhostEntities=false) const;
177  inline UnstructuredMappingIterator end(EntityTypeEnum entityType_, bool skipGhostEntities=false) const;
178 
180  bool skipGhostEntities=false) const;
181 
183  bool skipGhostEntities=false) const;
184 
186  bool skipGhostEntities=false) const;
188  bool skipGhostEntities=false) const;
189 
191  bool skipGhostEntities=false) const;
193  bool skipGhostEntities=false) const;
194 
196  bool skipGhostEntities=false) const;
198  bool skipGhostEntities=false) const;
199 
200 
201 
202  int setNodesAndConnectivity( const realArray & nodes,
203  const intArray & elements,
204  int domainDimension =-1,
205  bool buildConnectivity =true);
206 
207  int setNodesAndConnectivity( const realArray & nodes,
208  const intArray & elements,
209  const intArray & faces,
210  const intArray & faceElements,
211  const intArray & elementFaces,
212  int numberOfFaces=-1,
213  int numberOfBoundaryFaces=-1,
214  int domainDimension =-1,
215  bool constantNumberOfNodesPerElement=false );
216 
217 
218  int setNodesElementsAndNeighbours(const realArray & nodes,
219  const intArray & elements,
220  const intArray & neighbours,
221  int numberOfFaces=-1,
222  int numberOfBoundaryFaces=-1,
223  int domainDimension =-1 );
224 
225  void setTags(const intArray &new_tags);
226 
227  int splitElement( int e, int relativeEdge, real *x ); // add a new node that splits an edge.
228 
229 
230  // determine if points are inside or outside a (closed) triangulation using ray tracing
231  int insideOrOutside( realArray & x, IntegerArray & inside );
232 
233  virtual int intersects(Mapping & map2,
234  const int & side1=-1,
235  const int & axis1=-1,
236  const int & side2=-1,
237  const int & axis2=-1,
238  const real & tol=0. ) const;
239 
240  // project points onto the surface
241  int project( realArray & x, MappingProjectionParameters & mpParameters );
242 
244 
245  int printConnectivity( FILE *file =stdout );
246  int printStatistics(FILE *file =stdout );
247 
248  int checkConnectivity( bool printResults=true, IntegerArray *pBadElements=NULL );
249 
250  void getNormal( int e, real *normalVector ); // determine the normal to an element
251 
252  //IntegerArray buildFromAMapping( Mapping & map, int elementType=-1 );
253  intArray buildFromAMapping( Mapping & map, intArray &maskin = Overture::nullIntegerDistributedArray() );
254 
255  // an optimized build for domainDimension==2:
256  int buildFromARegularMapping( Mapping & map, ElementType elementTypePreferred=triangle );
257  int buildUnstructuredGrid( Mapping & map, int numberOfGridPoints[2]);
258 
261 
262  int findBoundaryCurves(int & numberOfBoundaryCurves, Mapping **& boundaryCurves );
263 
264  virtual int get( const GenericDataBase & dir, const aString & name); // get from a database file
265  virtual int put( GenericDataBase & dir, const aString & name) const; // put to a database file
266 
267  // read an unstructured grid from an ascii file.
268  virtual int get( const aString & fileName );
269 
270  // save the unstructured grid to an ascii file.
271  virtual int put(const aString & fileName = nullString ) const;
272 
273  Mapping *make( const aString & mappingClassName );
274 
275  int update( MappingInformation & mapInfo ) ;
276 
277  inline ElementType getElementType(int e) const;
278 
279  virtual aString getClassName() const { return UnstructuredMapping::className; }
280 
281  // put this utility routine here so it can be used by other codes. It does not need to be
282  // a member function. ** this could probably be done in a better way with a namespace **
283  static bool projectOnTriangle( real *x0, real *x1, real *x2,
284  real *xa, real *xb,
285  real *xt,
286  int & intersectionFace, int & intersectionFace2,
287  real & r0, real & s0,
288  real *normal=NULL );
289 // set & get colour
290  aString getColour( ) const;
291  int setColour( const aString & colour);
292 
293 // AP display lists...
295 
296  int
297  getDisplayList(DisplayListProperty d){if (d<numberOfDLProperties) return dList[d]; else return 0;};
298 
299  void
300  setDisplayList(DisplayListProperty d, int l){if (d<numberOfDLProperties && l>0) dList[d]=l;};
301 
302  void
304 
305  // kkc tagging support added 0802
306  inline bool dumpTags() const { return dumpTagsToHDF; }
307  inline bool dumpTags( bool dt ) { dumpTagsToHDF = dt; return dumpTagsToHDF; }
308 
309  EntityTag & addTag( const EntityTypeEnum entityType, const int entityIndex, const std::string tagName,
310  const void *tagData, const bool copyTag=false, const int tagSize=0 );
311  int deleteTag( const EntityTypeEnum entityType, const int entityIndex, const EntityTag &tagToDelete );
312  int deleteTag( const EntityTypeEnum entityType, const int entityIndex, const std::string tagToDelete );
313 
314  bool hasTag( const EntityTypeEnum entityType, const int entityIndex, const std::string tag );
315  EntityTag & getTag( const EntityTypeEnum entityType, const int entityIndex, const std::string tagName);
316  void * getTagData( const EntityTypeEnum entityType, const int entityIndex, const std::string tag );
317 
318  int setTag( const EntityTypeEnum entityType, const int entityIndex, const EntityTag & newTag );
319  int setTagData( const EntityTypeEnum entityType, const int entityIndex, const std::string tagName,
320  const void *data, const bool copyData=false, const int tagSize=0 );
321 
322  void maintainTagToEntityMap( bool v );
323  bool maintainsTagToEntityMap() const;
324 
326  typedef std::list<EntityTag*>::iterator entity_tag_iterator;
327  typedef std::list<EntityTag*>::const_iterator const_entity_tag_iterator;
328 
330  typedef std::list<IDTuple>::iterator tag_entity_iterator;
331  typedef std::list<IDTuple>::const_iterator const_tag_entity_iterator;
332 
335  { return entityTags[IDTuple(et,index)].begin(); }
337  { return entityTags[IDTuple(et,index)].begin(); }
338 
341  { return entityTags[IDTuple(et,index)].end(); }
343  { return entityTags[IDTuple(et,index)].end(); }
344 
346  inline tag_entity_iterator tag_entity_begin(std::string tagName)
347  {
348  // hey, you asked for it!
349  maintainTagToEntityMap( true );
350  return tagEntities[tagName].begin();
351  }
352 
354  inline tag_entity_iterator tag_entity_end(std::string tagName)
355  {
356  // hey, you asked for it!
357  maintainTagToEntityMap( true );
358  return tagEntities[tagName].end();
359  }
360 
361 
362  // =====================================================================================================
363  // *kkc* new connectivity interface data structures
364  //
365  public:
371  };
372 
373  protected:
375  intArray *entities[int(NumberOfEntityTypes)-1]; // -1 because we don't include the "Mesh" entity
377  intArray *entityMasks[int(NumberOfEntityTypes)-1];
380 
385 
388 
393 
394 public:
395  // *kkc* new connectivity interface utility methods
396  //
398  inline int maxVerticesInEntity(EntityTypeEnum type);
399 
400  inline ElementType computeElementType(EntityTypeEnum type, int e);
401 
403  inline int numberOfVertices(EntityTypeEnum, int);
404 
406  bool entitiesAreEquivalent(EntityTypeEnum type, int entity, ArraySimple<int> &verticies);
407 
409  std::string tagPrefix( EntityTypeEnum type, EntityInfoMask info );
410 
412  void setAsGhost(EntityTypeEnum type, int entity);
413 
415  inline bool isGhost(EntityTypeEnum type, int entity) const
416  {
417  return entityMasks[type] ? (*entityMasks[type])(entity) & GhostEntity : false;
418  }
419 
421  void setBC(EntityTypeEnum type, int entity, int bc);
422 
424  inline bool hasBC(EntityTypeEnum type, int entity)
425  { return entityMasks[type] ? (*entityMasks[type])(entity) & BCEntity : false; }
426 
428  inline long getBC(EntityTypeEnum type, int entity)
429  { return hasBC(type,entity) ? long(getTagData(type,entity,tagPrefix(type,BCEntity))) : -1; }
430 
432  bool specifyVertices(const realArray &verts);
433 
435  bool buildEntity(EntityTypeEnum type, bool rebuild=false, bool keepDownward=true, bool keepUpward=true);
436 
438  bool specifyEntity(const EntityTypeEnum type, const intArray &entity);
439 
441  int addVertex(real x, real y, real z=0.);
442 
444  int addEntity(EntityTypeEnum type, ArraySimple<int> &newEntVerts);
445 
447  /*** buildConnectivity will allocate the space for and build the upward or downward connectivities requested.
448  * If rebuild=true, it will destroy any previously created connectivity and regenerate it.
449  */
450  bool buildConnectivity(EntityTypeEnum from, EntityTypeEnum to, bool rebuild=false);
452  /*** specifyConnectivity tells the mapping to use the given connectivity information rather than building it.
453  * it returns false only if the given connectivity makes no sense.
454  */
455  bool specifyConnectivity(const EntityTypeEnum from, const EntityTypeEnum to, const intArray &index, const char *orientation,
456  const intArray &offset=Overture::nullIntegerDistributedArray());
457 
459  inline bool connectivityExists(EntityTypeEnum from, EntityTypeEnum to) const
460  {
461  return to==Vertex ? entities[from]!=0 : indexLists[from][to]!=0;
462  }
463 
468 
470  void deleteConnectivity();
471 
473  void expandGhostBoundary( int bc=-1 );
474 
475  // =====================================================================================================
476 
477 protected:
478 
479  int dList[numberOfDLProperties]; // display list numbers for different properties
480 
483  bool numberOfNodesPerElementIsConstant; // *wdh* 020517
484 
487  bool preferTriangles; // prefer building triangles or tets.
488  real elementDensityTolerance; // for choosing the number of elements on a Mapping.
489  real stitchingTolerance; // relative tol for stitching surfaces together.
490  real absoluteStitchingTolerance; // absolute tol for stitching surfaces together.
491  int debugs; // debug for stitching
492 
493  GeometricADT3dInt *search; // used to search for triangles nearby a point (Alternating Digital Tree)
494 
495 
498  intArray bdyFaceTags;
499  intArray *elementFaces; // optionally holds elementFaces.
500 
502  intArray *elementMask, *faceMask, *edgeMask, *nodeMask; // optional info when ghost elements are included.
503  intArray *ghostElements; // optional info about ghost elements
504 
506  {
515  };
517 
519  void initMapping();
520 
521  // FEZ means Finite Element Zoo
522  // connectivity templates for a finite element zoo
523  // the connectivity should be abstracted away in some nice way...
524  // for now, keep it simple, allocate some extra arrays and just do the bookkeeping...
525 
526  // parameters
528 
529  // zone based templates
534 
535  // auxillary connectivity arrays
536  intArray elementType;
537  intArray faceZ1Offset;
538 
539  // element tag array ( for denoting regions, etc.)
540  intArray tags;
541 
542  // auxillary connectivity methods (used when building the connectivity)
543  // most of the following methods abstract out the ugliness of the FEZ connectivity
545  inline IntegerArray getElementFaceNodes(int element_, int faceOffset) const;
546 
547  int FEZInitializeConnectivity(); // initialize the Finite Element Zoo Connectivity
548 
549  int addNodeToInterface( int s1, int & i1, int & j1, int & e1m, int & e1p, IntegerArray & connectionInfo1,
550  int s2, int & i2, int & j2, int & e2m, int & e2p, IntegerArray & connectionInfo2,
551  const intArray & elementface2,
552  intArray * bNodep, IntegerArray & faceOffset, IntegerArray & elementOffset,
553  int maxNumberOfElements, int maxNumberOfFaces );
554 
555  int buildSearchTree();
556 
557  int computeConnection(int s, int s2,
558  intArray *bNodep,
559  IntegerArray & numberOfBoundaryNodes,
560  UnstructuredMapping *boundaryp,
561  real epsx,
562  IntegerArray & connectionInfo );
563 
564  bool isDuplicateNode(int i, int n, int e, int s, int s2, real & r0, real & r1,
565  realArray & x,
566  real epsDup,
567  intArray & bNode,
568  intArray & nodeInfo,
569  int & localEdge,
570  real & dist0, real & dist1, real & dist2, int debugFlag);
571 
572  void replaceNode( int n, int n0, intArray & nodeInfo, intArray & ef );
573 
574  bool validStitch( int n, realArray & x0, realArray & x, intArray & nodeInfo, real tol, int debug);
575 
578 
579  // kkc General tagging support added 0802
580  // the user should *never* see these levely template types. we only use them internally
582  mutable std::map<IDTuple, std::list<EntityTag*> > entityTags; // always built when tags are used
583  mutable std::map<std::string, std::list<IDTuple>, std::less<std::string> > tagEntities; // optionally built if requested.
584 
586 
587  private:
588 
589  aString className, gridColour;
590 
591  // the map function should not be called
592  void map( const realArray & r, realArray & x, realArray & xr = Overture::nullRealDistributedArray(),
594 
595  //
596  // Virtual member functions used only through class ReferenceCounting:
597  //
599  { return operator=((UnstructuredMapping &)x); }
600  virtual void reference( const ReferenceCounting& x)
601  { reference((UnstructuredMapping &)x); } // *** Conversion to this class for the virtual = ****
602  virtual ReferenceCounting* virtualConstructor( const CopyType ct = DEEP ) const
603  { return ::new UnstructuredMapping(*this, ct); }
604 
605 };
606 
607 // This class is used to iterate over the valid entities (excluding ghost entities)
609 {
610 public:
613  int position, bool skipGhostEntites_ = false );
615 
616  inline bool setLocation( int l )
617  {
618  if ( l<numberOfEntities)
619  {
620  e = l;
621  return true;
622  }
623  return false;
624  }
625 
626  void operator++(int){
627  e++;
628  while ( e<numberOfEntities && (entityMask[e]&skipMask) ) e++;
629  // if ( includeGhostElements )
630  // { e++; while ( e<numberOfEntities && (entityMask[entityArray[offset+e*stride]] & UnstructuredMapping::HoleInEntityData) ) e++; }
631  // else
632  // { e++; while( e<numberOfEntities && entityMask[entityArray[offset + e*stride]] ) e++; }
633 
634  // if( !includeGhostElements)
635  // { e++; }
636  //else
637  // { e++; while( entityMask[e]<=0 && e<numberOfEntities ){ e++; } }
638  }
639 
640  int operator *() const {return e;} //
641 
642  bool operator==(const UnstructuredMappingIterator & iter) const { return iter.e==e; } //
643  bool operator!=(const UnstructuredMappingIterator & iter) const { return iter.e!=e; } //
644 
645  void operator=(const UnstructuredMappingIterator & iter);
647  inline UnstructuredMapping::EntityTypeEnum getType() const { return entityType; }
648 
649  bool isGhost() const { return entityMask[**this]&UnstructuredMapping::GhostEntity; }
650  bool isBC() const { return entityMask[**this]&UnstructuredMapping::BCEntity; }
651 
653  friend class UnstructuredMapping;
654 private:
656  int numberOfEntities;
657  int *entityMask;
658  //bool includeGhostElements;
659  bool skipGhostEntities;
660  int skipMask;
661  int e;
662 };
663 
665 {
667 public:
671  int position, bool skipGhostEntities_ = false );
673 
674  inline void operator++(int)
675  {
676  e++;
677  while ( e<numberOfEntities && (entityMask[entityArray[offset + e*stride]]&skipMask) ) e++; // if ( !skipGhostEntities )
678  // { e++; while ( e<numberOfEntities && (entityMask[entityArray[offset+e*stride]] & UnstructuredMapping::HoleInEntityData) ) e++; }
679  // else
680  // { e++; while( e<numberOfEntities && entityMask[entityArray[offset + e*stride]] ) e++; }
681  }
682 
683  inline int operator*() const { return e<numberOfEntities ? abs(entityArray[offset + e*stride]) : -1; }
684 
686  { return entityArray ? ( (i.adjEntityType==adjEntityType) && ( (**this)==(*i) ) ) : entityArray==i.entityArray; }
687  //{ return entityArray ? (i.e==e) && i.adjEntityType==adjEntityType && offset==i.offset: entityArray==i.entityArray; }
688 /* { return (entityArray && i.entityArray) ? */
689 /* ( (i.adjEntityType==adjEntityType) && abs(entityArray[offset + e*stride])==abs(i.entityArray[i.offset + i.e*i.stride]) ) : */
690 /* !(entityArray || i.entityArray); } */
691 
692  //{ return entityArray ? (i.e==e) && i.adjEntityType==adjEntityType : entityArray==i.entityArray; }
693 
694  inline bool operator==(const UnstructuredMappingIterator &i) const
695  { return entityArray ? (i.e==abs(entityArray[offset + e*stride])) && i.entityType==adjEntityType : false; }
696 
698  { return ! (*this==i);}
699  // { return entityArray ? (i.adjEntityType==adjEntityType ? i.e!=e || offset!=i.offset : true) : entityArray!=i.entityArray; }
700  //{ return entityArray ? (i.adjEntityType==adjEntityType ? i.e!=e : true) : entityArray!=i.entityArray; }
701 
702  inline bool operator!=(const UnstructuredMappingIterator &i) const
703  { return !(*this==i); }//entityArray ? (i.entityType==adjEntityType ? i.e!=abs(entityArray[offset + e*stride]) : true) : true; }
704 
706 
707  inline int orientation() const { return orientationArray ? (orientationArray[offset + e*stride] ? 1 : -1) : 1; }
708 
709  inline UnstructuredMapping::EntityTypeEnum getType() const { return adjEntityType; }
710  bool isGhost() const { return entityMask[**this]&UnstructuredMapping::GhostEntity; }
711  bool isBC() const { return entityMask[**this]&UnstructuredMapping::BCEntity; }
712 
713  inline int nAdjacent() const { return numberOfEntities; }
714 
715  friend class UnstructuredMapping;
716 
717 private:
720 
721  int *entityArray;
722  char *orientationArray;
723  int numberOfEntities, stride, offset;
724  int e;
725  int *entityMask;
726  bool skipGhostEntities;
727  int skipMask;
728 };
729 
730 
731 
732 // most of the following inlined methods abstract out the ugliness of the FEZ connectivity
733 //\begin{>UnstructuredMappingInclude.tex}{\subsection{getElementFaceNodes}}
735 getElementFaceNodes(int element_, int faceOffset) const
736 //===========================================================================
737 // /Description: get a list of the nodes on a particular face of an element
738 // /element\_ (input): the element in question
739 // /faceOffset (input): the face in the element whose nodes we want
740 // /Returns : IntegerArray of global node indices
741 // /Throws : nothing
742 //\end{UnstructuredMappingInclude.tex}
743 //===========================================================================
744 {
745  assert(element_>-1 && element_<numberOfElements);
746  int etype = elementType(element_);
747 
748  IntegerArray emslice;
749  Index Iface(0,numberOfNodesThisElementFaceType(etype, faceOffset));
750  IntegerArray retArray;
751 
752 #if 0
753  // this works but I am not sure it is any faster...
754  emslice = elementMasterTemplate(etype, faceOffset, Iface);
755  emslice.reshape(Iface);
756  IntegerArray ia(Iface);
757  ia = element_;
758  retArray = element(ia, emslice);
759  retArray.reshape(Iface);
760 #else
761  retArray.resize(Iface);
762  for (int i=0; i<Iface.getLength(); i++)
763  retArray(i) = element(element_, elementMasterTemplate(etype, faceOffset, i));
764 #endif
765 
766  return retArray;
767 }
768 
769 //\begin{>>UnstructuredMappingInclude.tex}{\subsection{getNumberOfFacesThisElement}}
770 inline int UnstructuredMapping::
771 getNumberOfFacesThisElement(int element_) const
772 //===========================================================================
773 // /Description: get the number of faces in a particular element
774 // /element\_ (input): the element in question
775 // /Returns : int containing the number of faces in element\_
776 // /Throws : nothing
777 //\end{UnstructuredMappingInclude.tex}
778 //===========================================================================
779 {
780  assert(element_>-1);
783  else
784  return numberOfFacesThisElementType(elementType(element_));
785 }
786 
787 //\begin{>>UnstructuredMappingInclude.tex}{\subsection{getNumberOfNodesThisElement}}
788 inline int UnstructuredMapping::
789 getNumberOfNodesThisElement(int element_) const
790 //===========================================================================
791 // /Description: get the number of nodes in a particular element
792 // /element\_ (input): the element in question
793 // /Returns : int containing the number of nodes in element\_
794 // /Throws : nothing
795 //\end{UnstructuredMappingInclude.tex}
796 //===========================================================================
797 {
798  assert(element_>-1);
801  else
802  return numberOfNodesThisElementType(elementType(element_));
803 }
804 
805 //\begin{>>UnstructuredMappingInclude.tex}{\subsection{getNumberOfNodesThisFace}}
806 inline int UnstructuredMapping::
807 getNumberOfNodesThisFace(int face_) const
808 //===========================================================================
809 // /Description: get the number of nodes in a particular face
810 // /face\_ (input): the face in question
811 // /Returns : int containing the number of nodes in face\_
812 // /Throws : nothing
813 //\end{UnstructuredMappingInclude.tex}
814 //===========================================================================
815 {
816  assert(face_>-1);
818  return 2;
819  else
821 }
822 
823 //\begin{>>UnstructuredMappingInclude.tex}{\subsection{getElementType}}
825 getElementType(int e) const
826 //===========================================================================
827 // /Description: get the type of a particular element
828 // /element\_ (input): the element in question
829 // /Returns : UnstructuredMapping::ElementType
830 // /Throws : nothing
831 //\end{UnstructuredMappingInclude.tex}
832 //===========================================================================
833 {
835  return triangle;
836  else
837  return ElementType(elementType(e));
838 }
839 
840 //\begin{>>UnstructuredMappingInclude.tex}{\subsection{elementGlobalVertex}}
841 inline int UnstructuredMapping::
842 elementGlobalVertex(int elem, int vertex) const
843 //===========================================================================
844 // /Description: get the global vertex index for a node in an element
845 // /elem (input): the element in question
846 // /vertex (input): the node in the element whose global index is required
847 // /Returns : int, the global index of node vertex in element elem
848 // /Throws : nothing
849 //\end{UnstructuredMappingInclude.tex}
850 //===========================================================================
851 {
852  return element(elem, vertex);
853 }
854 
855 //\begin{>>UnstructuredMappingInclude.tex}{\subsection{faceGlobalVertex}}
856 inline int UnstructuredMapping::
857 faceGlobalVertex(int f, int v) const
858 //===========================================================================
859 // /Description: get the global vertex index for a node in a face
860 // /f (input): the face in question
861 // /v (input): the node in the face whose global index is required
862 // /Returns : int, the global index of node v in face f
863 // /Throws : nothing
864 //\end{UnstructuredMappingInclude.tex}
865 //===========================================================================
866 {
867  return element(face(f,0), elementMasterTemplate(elementType(face(f,0)), faceZ1Offset(f), v));
868 }
869 
870 inline int UnstructuredMapping::
871 getBoundaryFace(int bdyface_) const
872 {
873  return bdyFace(bdyface_);
874 }
875 
876 inline int UnstructuredMapping::
877 getBoundaryFaceTag(int bdyface_) const
878 {
879  return bdyFaceTags(bdyface_);
880 }
881 
883 begin(EntityTypeEnum entityType, bool skipGhostEntities /* =false */ ) const
884 {
885  if ( !entities[entityType] ) ((UnstructuredMapping *)this)->buildEntity(entityType);
886  return UnstructuredMappingIterator(*this,entityType,0,skipGhostEntities);
887 }
888 
890 end(EntityTypeEnum entityType, bool skipGhostEntities /* =false */) const
891 {
892  if ( !entities[entityType] ) ((UnstructuredMapping *)this)->buildEntity(entityType);
893  return UnstructuredMappingIterator(*this,entityType,1,skipGhostEntities);
894 }
895 
898 adjacency_begin(EntityTypeEnum fromT, int fromE, EntityTypeEnum to, bool skipGhostEntities) const
899 {
900  if ( !connectivityExists(fromT,to) ) ((UnstructuredMapping *)this)->buildConnectivity(fromT,to);
901  return UnstructuredMappingAdjacencyIterator(*this, fromT, fromE, to, 0, skipGhostEntities);
902 }
903 
906 adjacency_end(EntityTypeEnum fromT, int fromE, EntityTypeEnum to, bool skipGhostEntities) const
907 {
908  if ( !connectivityExists(fromT,to) ) ((UnstructuredMapping *)this)->buildConnectivity(fromT,to);
909  return UnstructuredMappingAdjacencyIterator(*this, fromT, fromE, to, 1, skipGhostEntities);
910 }
911 
914 adjacency_begin(UnstructuredMappingIterator from, EntityTypeEnum to, bool skipGhostEntities) const
915 {
916  if ( !connectivityExists(from.entityType,to) ) ((UnstructuredMapping *)this)->buildConnectivity(from.entityType,to);
917  return UnstructuredMappingAdjacencyIterator(*this, from.entityType, *from, to, 0, skipGhostEntities);
918 }
919 
922 adjacency_end(UnstructuredMappingIterator from, EntityTypeEnum to, bool skipGhostEntities) const
923 {
924  if ( !connectivityExists(from.entityType,to) ) ((UnstructuredMapping *)this)->buildConnectivity(from.entityType,to);
925  return UnstructuredMappingAdjacencyIterator(*this, from.entityType, *from, to, 1, skipGhostEntities);
926 }
927 
931 {
932  if ( !connectivityExists(from.adjEntityType,to) ) ((UnstructuredMapping *)this)->buildConnectivity(from.adjEntityType,to);
933  return UnstructuredMappingAdjacencyIterator(*this, from.adjEntityType, *from, to, 0, skipGhostEntities);
934 }
935 
939 {
940  if ( !connectivityExists(from.adjEntityType,to) ) ((UnstructuredMapping *)this)->buildConnectivity(from.adjEntityType,to);
941  return UnstructuredMappingAdjacencyIterator(*this, from.adjEntityType, *from, to, 1, skipGhostEntities);
942 }
943 
946 adjacency_begin(IDTuple from, EntityTypeEnum to, bool skipGhostEntities) const
947 {
948  if ( !connectivityExists(from.et,to) ) ((UnstructuredMapping *)this)->buildConnectivity(from.et,to);
949  return UnstructuredMappingAdjacencyIterator(*this, from.et, from.e, to, 0, skipGhostEntities);
950 }
951 
954 adjacency_end(IDTuple from, EntityTypeEnum to, bool skipGhostEntities) const
955 {
956  if ( !connectivityExists(from.et,to) ) ((UnstructuredMapping *)this)->buildConnectivity(from.et,to);
957  return UnstructuredMappingAdjacencyIterator(*this, from.et, from.e, to, 1, skipGhostEntities);
958 }
959 
961 inline int
964 {
965  switch(type) {
966  case Region:
967  return 8;
968  case Face:
969  return 4;
970  case Edge:
971  return 2;
972  case Vertex:
973  return 1;
974  default:
975  return 0;
976  }
977 }
978 
980 inline int
983 {
984  const intArray & earray = getEntities(type);
985  switch(type) {
986  case Region:
987  {
988  for ( int i=7; i>=3; i-- )
989  if ( earray(entity,i)!=-1 )
990  return i+1;
991 
992  break;
993  }
994  case Face:
995  {
996  for ( int i=3; i>1; i-- )
997  if ( earray(entity,i)!=-1 )
998  return i+1;
999 
1000  break;
1001  }
1002  case Edge:
1003  return 2;
1004  case Vertex:
1005  return 1;
1006  default:
1007  return 0;
1008  }
1009  return 0;
1010 }
1011 
1015 {
1016  int nv = numberOfVertices(type,e);
1017  if ( type==Face )
1018  return nv==3 ? triangle : ( nv==4 ? quadrilateral : other );
1019  else
1020  return nv==8 ? hexahedron : ( nv==7 ? septahedron : ( nv==6 ? triPrism : ( nv==5 ? pyramid : ( nv==4 ? tetrahedron : other))));
1021 }
1022 
1023 
1024 #endif
1025 
1026 
1027