dune-grid  2.2.1
common/entity.hh
Go to the documentation of this file.
1 #ifndef DUNE_GRID_ENTITY_HH
2 #define DUNE_GRID_ENTITY_HH
3 
4 #include <dune/common/typetraits.hh>
5 #include "grid.hh"
6 #include "entitypointer.hh"
7 
8 namespace Dune
9 {
10 
56 template<int cd, int dim, class GridImp, template<int,int,class> class EntityImp>
57 class Entity
58 {
59 #if DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS
60 public:
61 #else
62 protected:
63  // give the GridDefaultImplementation class access to the realImp
64  friend class GridDefaultImplementation<
65  GridImp::dimension, GridImp::dimensionworld,
66  typename GridImp::ctype,
67  typename GridImp::GridFamily> ;
68 #endif
69  // type of underlying implementation, for internal use only
70  typedef EntityImp< cd, dim, GridImp > Implementation;
71 
73  Implementation &impl () { return realEntity; }
75  const Implementation &impl () const { return realEntity; }
76 
77 protected:
79 
80 public:
81 
82  //===========================================================
86  //===========================================================
87 
89  typedef typename GridImp::template Codim<cd>::Geometry Geometry;
90 
92  typedef typename GridImp::template Codim<cd>::EntitySeed EntitySeed;
93 
94  enum {
97  };
98  enum {
101  };
102  enum {
104  mydimension=dim-cd
105  };
106  enum {
108  dimensionworld=GridImp::dimensionworld
109  };
110 
112  typedef typename GridImp::ctype ctype;
114 
115 
116 
117  //===========================================================
121  //===========================================================
122 
124  int level () const { return realEntity.level(); }
125 
127  PartitionType partitionType () const { return realEntity.partitionType(); }
128 
141  Geometry geometry () const { return realEntity.geometry(); }
143 
147  GeometryType type () const { return realEntity.type(); }
148 
152  EntitySeed seed () const { return realEntity.seed(); }
153 
154  //===========================================================
158  //===========================================================
159 
161  explicit Entity(const EntityImp<cd,dim,GridImp> & e) : realEntity(e) {}
162 
163  /* not part of the interface but maybe in later versions
164  \brief Id of the boundary which is associated with the entity,
165  returns 0 for inner entities, arbitrary int otherwise
166  */
167  //int boundaryId () const { return realEntity.boundaryId(); }
168 
170 
171 protected:
172  typedef typename remove_const<GridImp>::type mutableGridImp;
173 
174  //===========================================================
178  //===========================================================
179 
180  // need to make copy constructor of EntityPointer work for any iterator
181  //friend class Dune::EntityPointer<GridImp,
182  // typename GridImp::GridFamily::Traits::template Codim<cd>::EntityPointerImpl>;
183  template< class, class > friend class Dune::EntityPointer;
184 
185 protected:
187  Entity(const Entity& rhs) : realEntity(rhs.realEntity) {}
189  Entity & operator = (const Entity& rhs) {
190  realEntity = rhs.realEntity;
191  return *this;
192  }
194 };
195 
206 template<int dim, class GridImp, template<int,int,class> class EntityImp>
207 class Entity <0,dim,GridImp,EntityImp>
208 {
209 #if DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS
210 public:
211 #else
212 protected:
213  // give the GridDefaultImplementation class access to the realImp
214  friend class GridDefaultImplementation<
215  GridImp::dimension, GridImp::dimensionworld,
216  typename GridImp::ctype,
217  typename GridImp::GridFamily> ;
218 #endif
219  // type of underlying implementation, for internal use only
220  typedef EntityImp< 0, dim, GridImp > Implementation;
221 
225  const Implementation &impl () const { return realEntity; }
226 
227 protected:
229 
230  typedef typename remove_const<GridImp>::type mutableGridImp;
231 
232 public:
233 
234  //===========================================================
238  //===========================================================
239 
241  typedef typename GridImp::template Codim<0>::Geometry Geometry;
242 
244  typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed;
245 
253  typedef typename GridImp::template Codim<0>::LocalGeometry LocalGeometry;
254 
256  template <int cd>
257  struct Codim
258  {
259  typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
260  };
261 
263  typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
264 
266  typedef typename GridImp::LeafIntersectionIterator LeafIntersectionIterator;
267 
269  typedef typename GridImp::LevelIntersectionIterator LevelIntersectionIterator;
270 
272  typedef typename GridImp::HierarchicIterator HierarchicIterator;
273 
274  enum {
277  };
278  enum {
281  };
282  enum {
285  };
286  enum {
288  dimensionworld=GridImp::dimensionworld
289  };
291  typedef typename GridImp::ctype ctype;
293 
294 
295  //===========================================================
299  //===========================================================
300 
302  int level () const { return realEntity.level(); }
303 
305  PartitionType partitionType () const { return realEntity.partitionType(); }
306 
308  Geometry geometry () const { return realEntity.geometry(); }
310 
314  GeometryType type () const { return realEntity.type(); }
315 
319  EntitySeed seed () const { return realEntity.seed(); }
320 
321  //===========================================================
325  //===========================================================
326 
332  template<int cc> int count () const { return realEntity.template count<cc>(); }
333 
344  template< int codim >
345  typename Codim< codim >::EntityPointer subEntity ( int i ) const
346  {
347  return realEntity.template subEntity< codim >( i );
348  }
349 
360  LeafIntersectionIterator ileafbegin () const
361  {
362  return realEntity.ileafbegin();
363  }
364 
371  LeafIntersectionIterator ileafend () const
372  {
373  return realEntity.ileafend();
374  }
375 
386  LevelIntersectionIterator ilevelbegin () const
387  {
388  return realEntity.ilevelbegin();
389  }
390 
397  LevelIntersectionIterator ilevelend () const
398  {
399  return realEntity.ilevelend();
400  }
401 
411  EntityPointer father () const
412  {
413  return realEntity.father();
414  }
415 
419  bool hasFather () const
420  {
421  return realEntity.hasFather();
422  }
423 
425  bool isLeaf () const
426  {
427  return realEntity.isLeaf();
428  }
429 
433  bool isRegular() const { return realEntity.isRegular(); }
434 
460  LocalGeometry geometryInFather () const { return realEntity.geometryInFather(); }
461 
473  HierarchicIterator hbegin (int maxlevel) const
474  {
475  return realEntity.hbegin(maxlevel);
476  }
477 
485  HierarchicIterator hend (int maxlevel) const
486  {
487  return realEntity.hend(maxlevel);
488  }
489 
492  bool isNew () const { return realEntity.isNew(); }
493 
498  bool mightVanish () const { return realEntity.mightVanish(); }
499 
500  //===========================================================
504  //===========================================================
508  bool hasBoundaryIntersections () const { return realEntity.hasBoundaryIntersections(); }
509 
511  explicit Entity(const EntityImp<0,dim,GridImp> & e) : realEntity(e) {}
512 
513  // @copydoc Dune::Entity::boundaryId()
514  // maybe available in later versions
515  //int boundaryId () const { return realEntity.boundaryId(); }
516 
517  /* not part of the interface, mybe in later versions
518  \brief The boundaryId of the i-th subentity of codimension <tt>cc</tt>
519 
520  This does the same as <code>entity<cc>(i).boundaryId()</code>, but it is
521  usually a lot faster.
522  */
523  /*
524  template <int cc> int subBoundaryId ( int i ) const
525  {
526  return realEntity.subBoundaryId<cc>(i);
527  }
528  */
529 
531 
532 
533 protected:
534  //===========================================================
538  //===========================================================
539 
540  // need to make copy constructor of EntityPointer work for any iterator
541  //friend class Dune::EntityPointer<GridImp,
542  // typename GridImp::GridFamily::Traits::template Codim<0>::EntityPointerImpl>;
543  template< class, class > friend class Dune::EntityPointer;
544 
545 protected:
547  Entity(const Entity& rhs) : realEntity(rhs.realEntity) {}
549  Entity & operator = (const Entity& rhs) {
550  realEntity = rhs.realEntity;
551  return *this;
552  }
554 };
555 
556 
557 //********************************************************************
568 template<int cd, int dim, class GridImp, template<int,int,class> class EntityImp>
570 {
571 public:
573  enum { codimension=cd };
574 
576  enum { dimension=dim };
577 
579  enum { mydimension=dim-cd };
580 
582  enum { dimensionworld=GridImp::dimensionworld };
583 
585  typedef typename GridImp::ctype ctype;
586 
588  typedef typename GridImp::template Codim<cd>::EntitySeed EntitySeed;
589 
591  typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
592 
596  GeometryType type () const { return asImp().geometry().type(); }
597 
598 private:
600  EntityImp<cd,dim,GridImp>& asImp ()
601  {
602  return static_cast<EntityImp<cd,dim,GridImp>&>(*this);
603  }
604  const EntityImp<cd,dim,GridImp>& asImp () const
605  {
606  return static_cast<const EntityImp<cd,dim,GridImp>&>(*this);
607  }
608 }; // end EntityDefaultImplementation
609 
610 //********************************************************************
621 template<int dim, class GridImp, template<int,int,class> class EntityImp>
622 class EntityDefaultImplementation <0,dim,GridImp,EntityImp>
623 {
624 public:
626  enum { codimension=0 };
627 
629  enum { dimension=dim };
630 
632  enum { mydimension=dim };
633 
635  enum { dimensionworld=GridImp::dimensionworld };
636 
638  typedef typename GridImp::ctype ctype;
639 
641  typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed;
642 
644  typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
645 
649  bool isRegular() const { return true; }
650 
654  GeometryType type () const { return asImp().geometry().type(); }
655 
656  /* maybe in later versions
657  * \brief Default implementation for access to boundaryId of sub entities
658  *
659  * Default implementation for access to boundaryId via interface method
660  * entity<codim>.boundaryId(), default is very slow, but works, can be
661  * overloaded be the actual grid implementation.
662  */
663  /*
664  template <int cc> int subBoundaryId ( int i ) const
665  {
666  return (asImp().template entity<cc>(i))->boundaryId();
667  }
668  */
669 
672  bool isNew () const { return false; }
673 
676  bool mightVanish () const { return false; }
677 
682  bool hasBoundaryIntersections () const
683  {
684  {
685  typedef typename GridImp::LevelIntersectionIterator IntersectionIterator;
686  IntersectionIterator end = asImp().ilevelend();
687  for(IntersectionIterator it = asImp().ilevelbegin(); it != end; ++it)
688  {
689  if( it->boundary() ) return true;
690  }
691  }
692 
693  {
694  typedef typename GridImp::LeafIntersectionIterator IntersectionIterator;
695  IntersectionIterator end = asImp().ileafend();
696  for(IntersectionIterator it = asImp().ileafbegin(); it != end; ++it)
697  {
698  if( it->boundary() ) return true;
699  }
700  }
701 
702  return false;
703  }
704 
705 private:
706  // Barton-Nackman trick
707  EntityImp<0,dim,GridImp>& asImp () { return static_cast<EntityImp<0,dim,GridImp>&>(*this); }
708  const EntityImp<0,dim,GridImp>& asImp () const { return static_cast<const EntityImp<0,dim,GridImp>&>(*this); }
709 };
710 
711 }
712 
713 #endif // DUNE_GRID_ENTITY_HH