dune-grid  2.4
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/iteratorrange.hh>
7 #include <dune/common/typetraits.hh>
8 
9 #include <dune/geometry/dimension.hh>
10 
11 #include "grid.hh"
12 #include "entitypointer.hh"
13 #include "rangegenerators.hh"
14 
15 namespace Dune
16 {
17 
60  template<int cd, int dim, class GridImp, template<int,int,class> class EntityImp>
61  class Entity
62  {
63 #if DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS
64  public:
65 #else
66  protected:
67  // give the GridDefaultImplementation class access to the realImp
68  friend class GridDefaultImplementation<
69  GridImp::dimension, GridImp::dimensionworld,
70  typename GridImp::ctype,
71  typename GridImp::GridFamily> ;
72 
73  // Default*GridView classes need access to intersection iterators
74  template< class, PartitionIteratorType > friend class DefaultLevelGridView;
75  template< class, PartitionIteratorType > friend class DefaultLeafGridView;
76 #endif
77  // type of underlying implementation, for internal use only
78  typedef EntityImp< cd, dim, GridImp > Implementation;
79 
81  Implementation &impl () { return realEntity; }
83  const Implementation &impl () const { return realEntity; }
84 
85  protected:
87 
88  public:
89 
90  //===========================================================
94  //===========================================================
95 
97  typedef typename GridImp::template Codim<cd>::Geometry Geometry;
98 
100  typedef typename GridImp::template Codim<cd>::EntitySeed EntitySeed;
101 
102  enum {
105  };
106  enum {
109  };
110  enum {
112  mydimension=dim-cd
113  };
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(); }
153 
155  bool operator==(const Entity& other) const
156  {
157  return realEntity.equals(other.realEntity);
158  }
159 
161  bool operator!=(const Entity& other) const
162  {
163  return !realEntity.equals(other.realEntity);
164  }
165 
171  template<typename ItImp>
172  DUNE_DEPRECATED_MSG("EntityPointer is deprecated and will be removed after the release of dune-grid-2.4. Instead, you can copy and store entities directly now.")
173  bool operator==(const Dune::EntityPointer<GridImp,ItImp>& other) const
174  {
175  return (*this) == (*other);
176  }
177 
183  template<typename ItImp>
184  DUNE_DEPRECATED_MSG("EntityPointer is deprecated and will be removed after the release of dune-grid-2.4. Instead, you can copy and store entities directly now.")
185  bool operator!=(const Dune::EntityPointer<GridImp,ItImp>& other) const
186  {
187  return (*this) != (*other);
188  }
189 
191  {}
192 
194  Entity(const Entity& other)
195  : realEntity(other.realEntity)
196  {}
197 
199  Entity(Entity&& other)
200  : realEntity(std::move(other.realEntity))
201  {}
202 
204  Entity& operator=(const Entity& other)
205  {
206  realEntity = other.realEntity;
207  return *this;
208  }
209 
212  {
213  realEntity = std::move(other.realEntity);
214  return *this;
215  }
216 
222  const Entity& operator*() const
223  DUNE_DEPRECATED_MSG("This is now an Entity instead of an EntityPointer. You do not have to dereference it anymore!")
224  {
225  return *this;
226  }
227 
233  const Entity* operator->() const
234  DUNE_DEPRECATED_MSG("This is now an Entity instead of an EntityPointer. You do not have to dereference it anymore!")
235  {
236  return this;
237  }
238 
240 
241  //===========================================================
245  //===========================================================
246 
248  Entity(const EntityImp<cd,dim,GridImp> & e) : realEntity(e) {}
249 
251  Entity(EntityImp<cd,dim,GridImp> && e) : realEntity(std::move(e)) {}
252 
254 
255  protected:
256 
257  // need to make copy constructor of EntityPointer work for any iterator
258  template< class, class > friend class Dune::EntityPointer;
259 
260  };
261 
276  template<int dim, class GridImp, template<int,int,class> class EntityImp>
277  class Entity <0,dim,GridImp,EntityImp>
278  {
279 #if DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS
280  public:
281 #else
282  protected:
283  // give the GridDefaultImplementation class access to the realImp
284  friend class GridDefaultImplementation<
285  GridImp::dimension, GridImp::dimensionworld,
286  typename GridImp::ctype,
287  typename GridImp::GridFamily> ;
288 
289  // Default*GridView classes need access to intersection iterators
290  template< class, PartitionIteratorType > friend class DefaultLevelGridView;
291  template< class, PartitionIteratorType > friend class DefaultLeafGridView;
292 #endif
293  // type of underlying implementation, for internal use only
294  typedef EntityImp< 0, dim, GridImp > Implementation;
295 
299  const Implementation &impl () const { return realEntity; }
300 
301  protected:
303 
304  public:
305 
306  //===========================================================
310  //===========================================================
311 
313  typedef typename GridImp::template Codim<0>::Geometry Geometry;
314 
316  typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed;
317 
325  typedef typename GridImp::template Codim<0>::LocalGeometry LocalGeometry;
326 
328  template <int cd>
329  struct Codim
330  {
331  typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
332  typedef typename GridImp::template Codim<cd>::Entity Entity;
333  };
334 
336  typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
337 
339  typedef typename GridImp::HierarchicIterator HierarchicIterator;
340 
341  enum {
344  };
345  enum {
348  };
349  enum {
352  };
354 
355 
356  //===========================================================
360  //===========================================================
361 
363  int level () const { return realEntity.level(); }
364 
366  PartitionType partitionType () const { return realEntity.partitionType(); }
367 
369  Geometry geometry () const { return realEntity.geometry(); }
370 
374  GeometryType type () const { return realEntity.type(); }
375 
379  EntitySeed seed () const { return realEntity.seed(); }
380 
382  bool operator==(const Entity& other) const
383  {
384  return realEntity.equals(other.realEntity);
385  }
386 
388  bool operator!=(const Entity& other) const
389  {
390  return !realEntity.equals(other.realEntity);
391  }
392 
398  template<typename ItImp>
399  DUNE_DEPRECATED_MSG("EntityPointer is deprecated and will be removed after the release of dune-grid-2.4. Instead, you can copy and store entities directly now.")
400  bool operator==(const Dune::EntityPointer<GridImp,ItImp>& other) const
401  {
402  return (*this) == (*other);
403  }
404 
410  template<typename ItImp>
411  DUNE_DEPRECATED_MSG("EntityPointer is deprecated and will be removed after the release of dune-grid-2.4. Instead, you can copy and store entities directly now.")
412  bool operator!=(const Dune::EntityPointer<GridImp,ItImp>& other) const
413  {
414  return (*this) != (*other);
415  }
416 
418  {}
419 
421  Entity(const Entity& other)
422  : realEntity(other.realEntity)
423  {}
424 
426  Entity(Entity&& other)
427  : realEntity(std::move(other.realEntity))
428  {}
429 
431  Entity& operator=(const Entity& other)
432  {
433  realEntity = other.realEntity;
434  return *this;
435  }
436 
439  {
440  realEntity = std::move(other.realEntity);
441  return *this;
442  }
443 
449  const Entity& operator*() const
450  DUNE_DEPRECATED_MSG("This is now an Entity instead of an EntityPointer. You do not have to dereference it anymore!")
451  {
452  return *this;
453  }
454 
460  const Entity* operator->() const
461  DUNE_DEPRECATED_MSG("This is now an Entity instead of an EntityPointer. You do not have to dereference it anymore!")
462  {
463  return this;
464  }
465 
467 
468  //===========================================================
472  //===========================================================
473 
482  template<int codim> int DUNE_DEPRECATED_MSG("Use subEntities(unsigned int) instead!") count () const { return realEntity.template count<codim>(); }
483 
489  unsigned int subEntities(unsigned int codim) const
490  {
491  return realEntity.subEntities(codim);
492  }
493 
494 #ifndef DOXYGEN
495 
496  // The following ugly helper struct is here to work around deficiencies in the decltype() implementation
497  // of GCC 4.4.
498  // If we try to merge the two typedefs in the struct and put them directly into the return value of
499  // subEntity(), GCC 4.4 dies with an internal compiler error complaining that mangling of template_id_name
500  // is not supported.
501  // So we put everything into this separate struct and just instantiate it in the signature of subEntity()
502  // which makes GCC 4.4 happy.
503  template <int codim_>
504  struct subentity_return_info
505  {
506 
507  // Step 1: Obtain return value of subentity from implementation class
508  //
509  // it would be more readable to use std::declval() here, but that's another thing that's missing
510  // GCC 4.4, so we do it the manual way with a static cast
511  typedef decltype(
512  static_cast<Implementation*>(nullptr)->template subEntity<codim_>(0)
513  ) implementation_return_type;
514 
515  // Step 2: Check whether the implementation returned a facade entity or not
516  // If yes -> declare Entity return type
517  // If no -> declare EntityPointer return type
518  typedef typename std::conditional<
519  std::is_same<
520  implementation_return_type,
521  typename Entity::template Codim<codim_>::Entity
522  >::value,
523  typename Entity::template Codim<codim_>::Entity,
524  typename Entity::template Codim<codim_>::EntityPointer
525  >::type type;
526  };
527 
528 #endif // DOXYGEN
529 
540  template< int codim >
541 #ifdef DOXYGEN
542  typename Codim< codim >::Entity
543 #else
544  typename subentity_return_info<codim>::type
545 #endif
546  subEntity ( int i ) const
547  {
548  warnOnDeprecatedEntityPointer<typename subentity_return_info<codim>::type>();
549  return realEntity.template subEntity< codim >( i );
550  }
551 
561 #ifdef DOXYGEN
562  Entity
563  father () const
564 #else
565  template<typename Foo = void>
566  typename std::conditional<
567  std::is_same<
568  decltype(realEntity.father()),
569  Entity
570  >::value,
571  Entity,
572  EntityPointer
573  >::type
574  father (typename std::enable_if<std::is_same<Foo,void>::value,void*>::type = nullptr) const
575 #endif
576  {
577  warnOnDeprecatedEntityPointer<decltype(realEntity.father())>();
578  return realEntity.father();
579  }
580 
584  bool hasFather () const
585  {
586  return realEntity.hasFather();
587  }
588 
590  bool isLeaf () const
591  {
592  return realEntity.isLeaf();
593  }
594 
598  bool isRegular() const { return realEntity.isRegular(); }
599 
625  LocalGeometry geometryInFather () const { return realEntity.geometryInFather(); }
626 
638  HierarchicIterator hbegin (int maxLevel) const
639  {
640  return realEntity.hbegin(maxLevel);
641  }
642 
650  HierarchicIterator hend (int maxLevel) const
651  {
652  return realEntity.hend(maxLevel);
653  }
654 
657  bool isNew () const { return realEntity.isNew(); }
658 
663  bool mightVanish () const { return realEntity.mightVanish(); }
664 
667  bool hasBoundaryIntersections () const { return realEntity.hasBoundaryIntersections(); }
668 
669 
670  //===========================================================
674  //===========================================================
675 
677  Entity(const EntityImp<0,dim,GridImp> & e) : realEntity(e) {}
678 
680  Entity(EntityImp<0,dim,GridImp> && e) : realEntity(std::move(e)) {}
681 
683 
684 #ifndef DOXYGEN
685 
686  // these two methods are just here for the 2.4 transition from EntityPointer to Entity
687  // they will generate a compile time warning if the grid implementation still returns
688  // an EntityPointer from certain interface methods.
689  // These methods are also required by the intersection facade, so I just made them public
690  // and hid them from Doxygen. As they don't do anything remotely useful, I don't think any
691  // user will try to call them manually... :-P
692 
693  // this non-warning version only matches if E is an entity that has been correctly wrapped
694  // in a facade class
695  template<typename E>
696  static typename std::enable_if<
697  std::is_same<
698  E,
699  typename Codim<E::codimension>::Entity
700  >::value
701  >::type
702  warnOnDeprecatedEntityPointer()
703  {}
704 
705  template<typename E>
706  DUNE_DEPRECATED_MSG("This grid still returns EntityPointers instead of Entities")
707  static typename std::enable_if<
708  not std::is_same<
709  E,
710  typename Codim<E::codimension>::Entity
711  >::value
712  >::type
713  warnOnDeprecatedEntityPointer()
714  {}
715 
716 #endif // DOXYGEN
717 
718  protected:
719  // needed to make copy constructor from EntityPointer work for any iterator
720  template< class, class > friend class Dune::EntityPointer;
721 
722  };
723 
724 
725 
726  //********************************************************************
737  template<int cd, int dim, class GridImp, template<int,int,class> class EntityImp>
739  {
740  public:
742  enum { codimension=cd };
743 
745  enum { dimension=dim };
746 
748  enum { mydimension=dim-cd };
749 
751  typedef typename GridImp::template Codim<cd>::EntitySeed EntitySeed;
752 
754  typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
755 
759  GeometryType type () const { return asImp().geometry().type(); }
760 
761  private:
763  EntityImp<cd,dim,GridImp>& asImp ()
764  {
765  return static_cast<EntityImp<cd,dim,GridImp>&>(*this);
766  }
767  const EntityImp<cd,dim,GridImp>& asImp () const
768  {
769  return static_cast<const EntityImp<cd,dim,GridImp>&>(*this);
770  }
771  }; // end EntityDefaultImplementation
772 
773  //********************************************************************
784  template<int dim, class GridImp, template<int,int,class> class EntityImp>
785  class EntityDefaultImplementation <0,dim,GridImp,EntityImp>
786  {
787  public:
789  enum { codimension=0 };
790 
792  enum { dimension=dim };
793 
795  enum { mydimension=dim };
796 
798  typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed;
799 
801  typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
802 
806  bool isRegular() const { return true; }
807 
811  GeometryType type () const { return asImp().geometry().type(); }
812 
815  bool isNew () const { return false; }
816 
819  bool mightVanish () const { return false; }
820 
826  {
827  {
828  typedef typename GridImp::LevelIntersectionIterator IntersectionIterator;
829  IntersectionIterator end = asImp().ilevelend();
830  for(IntersectionIterator it = asImp().ilevelbegin(); it != end; ++it)
831  {
832  if( it->boundary() ) return true;
833  }
834  }
835 
836  {
837  typedef typename GridImp::LeafIntersectionIterator IntersectionIterator;
838  IntersectionIterator end = asImp().ileafend();
839  for(IntersectionIterator it = asImp().ileafbegin(); it != end; ++it)
840  {
841  if( it->boundary() ) return true;
842  }
843  }
844 
845  return false;
846  }
847 
848  private:
849  // Barton-Nackman trick
850  EntityImp<0,dim,GridImp>& asImp () { return static_cast<EntityImp<0,dim,GridImp>&>(*this); }
851  const EntityImp<0,dim,GridImp>& asImp () const { return static_cast<const EntityImp<0,dim,GridImp>&>(*this); }
852  };
853 
854 }
855 
856 #endif // DUNE_GRID_ENTITY_HH
Entity & operator=(Entity &&other)
Move assignment operator from an existing entity.
Definition: common/entity.hh:438
bool isRegular() const
Returns true if element is of regular type in red/green type refinement. In bisection or hanging node...
Definition: common/entity.hh:598
GridImp::template Codim< 0 >::EntitySeed EntitySeed
The corresponding entity seed (for storage of entities)
Definition: common/entity.hh:316
Entity()
Definition: common/entity.hh:190
Entity & operator=(const Entity &other)
Copy assignment operator from an existing entity.
Definition: common/entity.hh:431
Know the grid dimension.
Definition: common/entity.hh:108
Wrapper class for pointers to entities.
Definition: common/entitypointer.hh:112
Definition: common/geometry.hh:24
GridImp::template Codim< 0 >::Geometry Geometry
The geometry type of this entity.
Definition: common/entity.hh:313
bool mightVanish() const
Returns true, if entity might disappear during the next call to adapt()
Definition: common/entity.hh:819
unsigned int subEntities(unsigned int codim) const
Number of subentities with codimension codim.
Definition: common/entity.hh:489
Know your own codimension.
Definition: common/entity.hh:104
GridImp::template Codim< cd >::EntityPointer EntityPointer
The corresponding entity seed (for storage of entities)
Definition: common/entity.hh:754
bool isRegular() const
Returns true if element is of regular type in red/green type refinement. In bisection or hanging node...
Definition: common/entity.hh:806
Entity & operator=(Entity &&other)
Move assignment operator from an existing entity.
Definition: common/entity.hh:211
Mesh entities of codimension 0 ("elements") allow to visit all intersections with "neighboring" eleme...
Definition: common/grid.hh:360
GridImp::template Codim< 0 >::EntityPointer EntityPointer
The codim==0 EntityPointer type.
Definition: common/entity.hh:336
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: common/entity.hh:152
GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: common/entity.hh:374
Default Implementations for EntityImp.
Definition: common/entity.hh:738
Dimensionality of the reference element of the entity.
Definition: common/entity.hh:112
const Entity * operator->() const
Dereference Entity to itself for backwards compatibility with EntityPointer.
Definition: common/entity.hh:233
Include standard header files.
Definition: agrid.hh:59
Implementation & impl()
Return reference to the real implementation.
Definition: common/entity.hh:81
int level() const
The level of this entity.
Definition: common/entity.hh:363
Entity(const EntityImp< cd, dim, GridImp > &e)
Copy constructor from EntityImp.
Definition: common/entity.hh:248
Entity(Entity &&other)
Move constructor from an existing entity.
Definition: common/entity.hh:426
GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: common/entity.hh:147
bool mightVanish() const
Returns true, if entity might disappear during the next call to adapt(). If the method returns false...
Definition: common/entity.hh:663
bool operator!=(const Entity &other) const
Compares two entities for inequality.
Definition: common/entity.hh:388
bool hasFather() const
Return true if entity has a father entity which can be accessed using the father() method...
Definition: common/entity.hh:584
static void(*)(*)(*)(*)(*)(*) move(const double *)
Definition: partitiondisplay.cc:122
const Implementation & impl() const
Return const reference to the real implementation.
Definition: common/entity.hh:299
EntityImp< cd, dim, Grid > Implementation
Definition: common/entity.hh:78
Geometry geometry() const
obtain geometric realization of the entity
Definition: common/entity.hh:142
GridImp::template Codim< 0 >::LocalGeometry LocalGeometry
The geometry type of this entity when the geometry is expressed embedded in the father element...
Definition: common/entity.hh:325
GridImp::template Codim< 0 >::EntitySeed EntitySeed
The corresponding entity seed (for storage of entities)
Definition: common/entity.hh:798
PartitionType partitionType() const
Partition type of this entity.
Definition: common/entity.hh:366
Entity(const Entity &other)
Copy constructor from an existing entity.
Definition: common/entity.hh:421
bool hasBoundaryIntersections() const
Returns true, if entity has intersections with boundary, this implementation uses the Level- and Leaf...
Definition: common/entity.hh:825
GridImp::template Codim< 0 >::EntityPointer EntityPointer
The corresponding entity seed (for storage of entities)
Definition: common/entity.hh:801
bool isNew() const
Returns true, if the entity has been created during the last call to adapt()
Definition: common/entity.hh:815
Different resources needed by all grid implementations.
Implementation realEntity
Definition: common/entity.hh:86
GridImp::template Codim< cd >::EntitySeed EntitySeed
The corresponding entity seed (for storage of entities)
Definition: common/entity.hh:751
Codim< codim >::Entity subEntity(int i) const
Obtain a pointer to a subentity.
Definition: common/entity.hh:546
Definition: defaultgridview.hh:16
Entity(const EntityImp< 0, dim, GridImp > &e)
Copy constructor from EntityImp.
Definition: common/entity.hh:677
HierarchicIterator hend(int maxLevel) const
Returns iterator to one past the last son element.
Definition: common/entity.hh:650
Wrapper and interface class for a static iterator (EntityPointer)
GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: common/entity.hh:759
Entity & operator=(const Entity &other)
Copy assignment operator from an existing entity.
Definition: common/entity.hh:204
Entity(Entity &&other)
Move constructor from an existing entity.
Definition: common/entity.hh:199
PartitionType partitionType() const
Partition type of this entity.
Definition: common/entity.hh:128
Entity father() const
Inter-level access to father entity on the next-coarser grid. The given entity resulted directly from...
Definition: common/entity.hh:563
bool operator==(const Entity &other) const
Compares two entities for equality.
Definition: common/entity.hh:382
Implementation realEntity
Definition: common/entity.hh:302
STL namespace.
bool isNew() const
Returns true, if the entity has been created during the last call to adapt()
Definition: common/entity.hh:657
bool isLeaf() const
Returns true if the entity is contained in the leaf grid.
Definition: common/entity.hh:590
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: common/entity.hh:379
GridImp::HierarchicIterator HierarchicIterator
The HierarchicIterator type.
Definition: common/entity.hh:339
const Entity * operator->() const
Dereference Entity to itself for backwards compatibility with EntityPointer.
Definition: common/entity.hh:460
bool hasBoundaryIntersections() const
Returns true, if entity has intersections with boundary.
Definition: common/entity.hh:667
HierarchicIterator hbegin(int maxLevel) const
Inter-level access to elements that resulted from (recursive) subdivision of this element...
Definition: common/entity.hh:638
Geometry geometry() const
obtain geometric realization of the entity
Definition: common/entity.hh:369
Entity(const Entity &other)
Copy constructor from an existing entity.
Definition: common/entity.hh:194
Entity()
Definition: common/entity.hh:417
int level() const
The level of this entity.
Definition: common/entity.hh:125
bool operator!=(const Entity &other) const
Compares two entities for inequality.
Definition: common/entity.hh:161
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:28
const Entity & operator*() const
Dereference Entity to itself for backwards compatibility with EntityPointer.
Definition: common/entity.hh:449
GridImp::template Codim< cd >::EntityPointer EntityPointer
Definition: common/entity.hh:331
const Implementation & impl() const
Return const reference to the real implementation.
Definition: common/entity.hh:83
Entity(EntityImp< 0, dim, GridImp > &&e)
Move constructor from EntityImp.
Definition: common/entity.hh:680
const Entity & operator*() const
Dereference Entity to itself for backwards compatibility with EntityPointer.
Definition: common/entity.hh:222
Definition: defaultgridview.hh:19
bool operator==(const Entity &other) const
Compares two entities for equality.
Definition: common/entity.hh:155
LocalGeometry geometryInFather() const
Provides information how this element has been subdivided from its father element.
Definition: common/entity.hh:625
GridImp::template Codim< cd >::Entity Entity
Definition: common/entity.hh:332
GridImp::template Codim< cd >::Geometry Geometry
The corresponding geometry type.
Definition: common/entity.hh:97
GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: common/entity.hh:811
Entity(EntityImp< cd, dim, GridImp > &&e)
Move constructor from EntityImp.
Definition: common/entity.hh:251
Wrapper class for entities.
Definition: common/entity.hh:61
GridImp::template Codim< cd >::EntitySeed EntitySeed
The corresponding entity seed (for storage of entities)
Definition: common/entity.hh:100