dune-grid  2.3beta2
common/entity.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_GRID_ENTITY_HH
4 #define DUNE_GRID_ENTITY_HH
5 
6 #include <dune/common/typetraits.hh>
7 #include "grid.hh"
8 #include "entitypointer.hh"
9 
10 namespace Dune
11 {
12 
55  template<int cd, int dim, class GridImp, template<int,int,class> class EntityImp>
56  class Entity
57  {
58 #if DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS
59  public:
60 #else
61  protected:
62  // give the GridDefaultImplementation class access to the realImp
63  friend class GridDefaultImplementation<
64  GridImp::dimension, GridImp::dimensionworld,
65  typename GridImp::ctype,
66  typename GridImp::GridFamily> ;
67 
68  // Default*GridView classes need access to intersection iterators
69  template< class, PartitionIteratorType > friend class DefaultLevelGridView;
70  template< class, PartitionIteratorType > friend class DefaultLeafGridView;
71 #endif
72  // type of underlying implementation, for internal use only
73  typedef EntityImp< cd, dim, GridImp > Implementation;
74 
76  Implementation &impl () { return realEntity; }
78  const Implementation &impl () const { return realEntity; }
79 
80  protected:
82 
83  public:
84 
85  //===========================================================
89  //===========================================================
90 
92  typedef typename GridImp::template Codim<cd>::Geometry Geometry;
93 
95  typedef typename GridImp::template Codim<cd>::EntitySeed EntitySeed;
96 
97  enum {
100  };
101  enum {
104  };
105  enum {
107  mydimension=dim-cd
108  };
110  static const int DUNE_DEPRECATED_MSG("Use Geometry::coorddimension instead!") dimensionworld=GridImp::dimensionworld;
111 
113  typedef typename GridImp::ctype ctype DUNE_DEPRECATED_MSG("Use Geometry::ctype instead!");
115 
116 
117 
118  //===========================================================
122  //===========================================================
123 
125  int level () const { return realEntity.level(); }
126 
128  PartitionType partitionType () const { return realEntity.partitionType(); }
129 
142  Geometry geometry () const { return realEntity.geometry(); }
143 
147  GeometryType type () const { return realEntity.type(); }
148 
152  EntitySeed seed () const { return realEntity.seed(); }
154 
155  //===========================================================
159  //===========================================================
160 
162  explicit Entity(const EntityImp<cd,dim,GridImp> & e) : realEntity(e) {}
163 
165 
166  protected:
167 
168  // need to make copy constructor of EntityPointer work for any iterator
169  template< class, class > friend class Dune::EntityPointer;
170 
172  Entity(const Entity& rhs) : realEntity(rhs.realEntity) {}
174  Entity & operator = (const Entity& rhs) {
175  realEntity = rhs.realEntity;
176  return *this;
177  }
178 
179  };
180 
195  template<int dim, class GridImp, template<int,int,class> class EntityImp>
196  class Entity <0,dim,GridImp,EntityImp>
197  {
198 #if DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS
199  public:
200 #else
201  protected:
202  // give the GridDefaultImplementation class access to the realImp
203  friend class GridDefaultImplementation<
204  GridImp::dimension, GridImp::dimensionworld,
205  typename GridImp::ctype,
206  typename GridImp::GridFamily> ;
207 
208  // Default*GridView classes need access to intersection iterators
209  template< class, PartitionIteratorType > friend class DefaultLevelGridView;
210  template< class, PartitionIteratorType > friend class DefaultLeafGridView;
211 #endif
212  // type of underlying implementation, for internal use only
213  typedef EntityImp< 0, dim, GridImp > Implementation;
214 
218  const Implementation &impl () const { return realEntity; }
219 
220  protected:
222 
223  public:
224 
225  //===========================================================
229  //===========================================================
230 
232  typedef typename GridImp::template Codim<0>::Geometry Geometry;
233 
235  typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed;
236 
244  typedef typename GridImp::template Codim<0>::LocalGeometry LocalGeometry;
245 
247  template <int cd>
248  struct Codim
249  {
250  typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
251  };
252 
254  typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
255 
259  typedef typename GridImp::LeafIntersectionIterator LeafIntersectionIterator;
260 
264  typedef typename GridImp::LevelIntersectionIterator LevelIntersectionIterator;
265 
267  typedef typename GridImp::HierarchicIterator HierarchicIterator;
268 
269  enum {
272  };
273  enum {
276  };
277  enum {
280  };
282  static const int DUNE_DEPRECATED_MSG("Use Geometry::coorddimension instead!") dimensionworld=GridImp::dimensionworld;
283 
285  typedef typename GridImp::ctype ctype DUNE_DEPRECATED_MSG("Use Geometry::ctype instead!");
287 
288 
289  //===========================================================
293  //===========================================================
294 
296  int level () const { return realEntity.level(); }
297 
299  PartitionType partitionType () const { return realEntity.partitionType(); }
300 
302  Geometry geometry () const { return realEntity.geometry(); }
303 
307  GeometryType type () const { return realEntity.type(); }
308 
312  EntitySeed seed () const { return realEntity.seed(); }
314 
315  //===========================================================
319  //===========================================================
320 
326  template<int cc> int count () const { return realEntity.template count<cc>(); }
327 
338  template< int codim >
339  typename Codim< codim >::EntityPointer subEntity ( int i ) const
340  {
341  return realEntity.template subEntity< codim >( i );
342  }
343 
357  LeafIntersectionIterator ileafbegin () const
358  DUNE_DEPRECATED_MSG("Use LeafGridView.ibegin(Entity) instead.")
359  {
360  return realEntity.ileafbegin();
361  }
362 
372  LeafIntersectionIterator ileafend () const
373  DUNE_DEPRECATED_MSG("Use LeafGridView.iend(Entity) instead.")
374  {
375  return realEntity.ileafend();
376  }
377 
391  LevelIntersectionIterator ilevelbegin () const
392  DUNE_DEPRECATED_MSG("Use LevelGridView.ibegin(Entity) instead.")
393  {
394  return realEntity.ilevelbegin();
395  }
396 
406  LevelIntersectionIterator ilevelend () const
407  DUNE_DEPRECATED_MSG("Use LevelGridView.iend(Entity) instead.")
408  {
409  return realEntity.ilevelend();
410  }
411 
421  EntityPointer father () const
422  {
423  return realEntity.father();
424  }
425 
429  bool hasFather () const
430  {
431  return realEntity.hasFather();
432  }
433 
435  bool isLeaf () const
436  {
437  return realEntity.isLeaf();
438  }
439 
443  bool isRegular() const { return realEntity.isRegular(); }
444 
470  LocalGeometry geometryInFather () const { return realEntity.geometryInFather(); }
471 
483  HierarchicIterator hbegin (int maxlevel) const
484  {
485  return realEntity.hbegin(maxlevel);
486  }
487 
495  HierarchicIterator hend (int maxlevel) const
496  {
497  return realEntity.hend(maxlevel);
498  }
499 
502  bool isNew () const { return realEntity.isNew(); }
503 
508  bool mightVanish () const { return realEntity.mightVanish(); }
509 
510  //===========================================================
514  //===========================================================
517  bool hasBoundaryIntersections () const { return realEntity.hasBoundaryIntersections(); }
518 
520  explicit Entity(const EntityImp<0,dim,GridImp> & e) : realEntity(e) {}
521 
523 
524 
525  protected:
526  // needed to make copy constructor from EntityPointer work for any iterator
527  template< class, class > friend class Dune::EntityPointer;
528 
530  Entity(const Entity& rhs) : realEntity(rhs.realEntity) {}
532  Entity & operator = (const Entity& rhs) {
533  realEntity = rhs.realEntity;
534  return *this;
535  }
536 
537  };
538 
539 
540  //********************************************************************
551  template<int cd, int dim, class GridImp, template<int,int,class> class EntityImp>
553  {
554  public:
556  enum { codimension=cd };
557 
559  enum { dimension=dim };
560 
562  enum { mydimension=dim-cd };
563 
565  static const int DUNE_DEPRECATED_MSG("Use Geometry::coorddimension instead!") dimensionworld=GridImp::dimensionworld;
566 
568  typedef typename GridImp::ctype ctype DUNE_DEPRECATED_MSG("Use Geometry::ctype instead!");
569 
571  typedef typename GridImp::template Codim<cd>::EntitySeed EntitySeed;
572 
574  typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
575 
579  GeometryType type () const { return asImp().geometry().type(); }
580 
581  private:
583  EntityImp<cd,dim,GridImp>& asImp ()
584  {
585  return static_cast<EntityImp<cd,dim,GridImp>&>(*this);
586  }
587  const EntityImp<cd,dim,GridImp>& asImp () const
588  {
589  return static_cast<const EntityImp<cd,dim,GridImp>&>(*this);
590  }
591  }; // end EntityDefaultImplementation
592 
593  //********************************************************************
604  template<int dim, class GridImp, template<int,int,class> class EntityImp>
605  class EntityDefaultImplementation <0,dim,GridImp,EntityImp>
606  {
607  public:
609  enum { codimension=0 };
610 
612  enum { dimension=dim };
613 
615  enum { mydimension=dim };
616 
618  static const int DUNE_DEPRECATED_MSG("Use Geometry::coorddimension instead!") dimensionworld=GridImp::dimensionworld;
619 
621  typedef typename GridImp::ctype ctype DUNE_DEPRECATED_MSG("Use Geometry::ctype instead!");
622 
624  typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed;
625 
627  typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
628 
632  bool isRegular() const { return true; }
633 
637  GeometryType type () const { return asImp().geometry().type(); }
638 
641  bool isNew () const { return false; }
642 
645  bool mightVanish () const { return false; }
646 
651  bool hasBoundaryIntersections () const
652  {
653  {
654  typedef typename GridImp::LevelIntersectionIterator IntersectionIterator;
655  IntersectionIterator end = asImp().ilevelend();
656  for(IntersectionIterator it = asImp().ilevelbegin(); it != end; ++it)
657  {
658  if( it->boundary() ) return true;
659  }
660  }
661 
662  {
663  typedef typename GridImp::LeafIntersectionIterator IntersectionIterator;
664  IntersectionIterator end = asImp().ileafend();
665  for(IntersectionIterator it = asImp().ileafbegin(); it != end; ++it)
666  {
667  if( it->boundary() ) return true;
668  }
669  }
670 
671  return false;
672  }
673 
674  private:
675  // Barton-Nackman trick
676  EntityImp<0,dim,GridImp>& asImp () { return static_cast<EntityImp<0,dim,GridImp>&>(*this); }
677  const EntityImp<0,dim,GridImp>& asImp () const { return static_cast<const EntityImp<0,dim,GridImp>&>(*this); }
678  };
679 
680 }
681 
682 #endif // DUNE_GRID_ENTITY_HH