Dune Core Modules (2.4.1)

entity.hh
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>
8
9#include <dune/geometry/dimension.hh>
10
11#include "grid.hh"
12#include "entitypointer.hh"
13#include "rangegenerators.hh"
14
15namespace 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:
86 Implementation realEntity;
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 {
104 codimension=cd
105 };
106 enum {
108 dimension=dim
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
190 Entity()
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
297 Implementation &impl () { return realEntity; }
299 const Implementation &impl () const { return realEntity; }
300
301 protected:
302 Implementation realEntity;
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 {
347 dimension=dim
348 };
349 enum {
351 mydimension=dim
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
417 Entity()
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
562#ifdef DOXYGEN
563 Entity
564 father () const
565#else
566 template<typename Foo = void>
567 typename std::conditional<
568 std::is_same<
569 decltype(realEntity.father()),
570 Entity
571 >::value,
572 Entity,
574 >::type
575 father (typename std::enable_if<std::is_same<Foo,void>::value,void*>::type = nullptr) const
576#endif
577 {
578 warnOnDeprecatedEntityPointer<decltype(realEntity.father())>();
579 return realEntity.father();
580 }
581
585 bool hasFather () const
586 {
587 return realEntity.hasFather();
588 }
589
591 bool isLeaf () const
592 {
593 return realEntity.isLeaf();
594 }
595
599 bool isRegular() const { return realEntity.isRegular(); }
600
626 LocalGeometry geometryInFather () const { return realEntity.geometryInFather(); }
627
639 HierarchicIterator hbegin (int maxLevel) const
640 {
641 return realEntity.hbegin(maxLevel);
642 }
643
651 HierarchicIterator hend (int maxLevel) const
652 {
653 return realEntity.hend(maxLevel);
654 }
655
658 bool isNew () const { return realEntity.isNew(); }
659
664 bool mightVanish () const { return realEntity.mightVanish(); }
665
668 bool hasBoundaryIntersections () const { return realEntity.hasBoundaryIntersections(); }
669
670
671 //===========================================================
675 //===========================================================
676
678 Entity(const EntityImp<0,dim,GridImp> & e) : realEntity(e) {}
679
681 Entity(EntityImp<0,dim,GridImp> && e) : realEntity(std::move(e)) {}
682
684
685#ifndef DOXYGEN
686
687 // these two methods are just here for the 2.4 transition from EntityPointer to Entity
688 // they will generate a compile time warning if the grid implementation still returns
689 // an EntityPointer from certain interface methods.
690 // These methods are also required by the intersection facade, so I just made them public
691 // and hid them from Doxygen. As they don't do anything remotely useful, I don't think any
692 // user will try to call them manually... :-P
693
694 // this non-warning version only matches if E is an entity that has been correctly wrapped
695 // in a facade class
696 template<typename E>
697 static typename std::enable_if<
698 std::is_same<
699 E,
701 >::value
702 >::type
703 warnOnDeprecatedEntityPointer()
704 {}
705
706 template<typename E>
707 DUNE_DEPRECATED_MSG("This grid still returns EntityPointers instead of Entities")
708 static typename std::enable_if<
709 not std::is_same<
710 E,
711 typename Codim<E::codimension>::Entity
712 >::value
713 >::type
714 warnOnDeprecatedEntityPointer()
715 {}
716
717#endif // DOXYGEN
718
719 protected:
720 // needed to make copy constructor from EntityPointer work for any iterator
721 template< class, class > friend class Dune::EntityPointer;
722
723 };
724
725
726
727 //********************************************************************
738 template<int cd, int dim, class GridImp, template<int,int,class> class EntityImp>
740 {
741 public:
743 enum { codimension=cd };
744
746 enum { dimension=dim };
747
749 enum { mydimension=dim-cd };
750
752 typedef typename GridImp::template Codim<cd>::EntitySeed EntitySeed;
753
755 typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
756
760 GeometryType type () const { return asImp().geometry().type(); }
761
762 private:
764 EntityImp<cd,dim,GridImp>& asImp ()
765 {
766 return static_cast<EntityImp<cd,dim,GridImp>&>(*this);
767 }
768 const EntityImp<cd,dim,GridImp>& asImp () const
769 {
770 return static_cast<const EntityImp<cd,dim,GridImp>&>(*this);
771 }
772 }; // end EntityDefaultImplementation
773
774 //********************************************************************
785 template<int dim, class GridImp, template<int,int,class> class EntityImp>
786 class EntityDefaultImplementation <0,dim,GridImp,EntityImp>
787 {
788 public:
790 enum { codimension=0 };
791
793 enum { dimension=dim };
794
796 enum { mydimension=dim };
797
799 typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed;
800
802 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
803
807 bool isRegular() const { return true; }
808
812 GeometryType type () const { return asImp().geometry().type(); }
813
816 bool isNew () const { return false; }
817
820 bool mightVanish () const { return false; }
821
827 {
828 typedef typename GridImp::LevelIntersectionIterator IntersectionIterator;
829 IntersectionIterator end = asImp().ilevelend();
830 for (IntersectionIterator it = asImp().ilevelbegin(); it != end; ++it)
831 if( it->boundary() )
832 return true;
833
834 return false;
835 }
836
837 private:
838 // Barton-Nackman trick
839 EntityImp<0,dim,GridImp>& asImp () { return static_cast<EntityImp<0,dim,GridImp>&>(*this); }
840 const EntityImp<0,dim,GridImp>& asImp () const { return static_cast<const EntityImp<0,dim,GridImp>&>(*this); }
841 };
842
843}
844
845#endif // DUNE_GRID_ENTITY_HH
bool isNew() const
Returns true, if the entity has been created during the last call to adapt()
Definition: entity.hh:816
bool isRegular() const
Returns true if element is of regular type in red/green type refinement. In bisection or hanging node...
Definition: entity.hh:807
bool hasBoundaryIntersections() const
Returns true, if entity has intersections with boundary, this implementation uses the Level- and Leaf...
Definition: entity.hh:826
GridImp::template Codim< 0 >::EntityPointer EntityPointer
The corresponding entity seed (for storage of entities)
Definition: entity.hh:802
GridImp::template Codim< 0 >::EntitySeed EntitySeed
The corresponding entity seed (for storage of entities)
Definition: entity.hh:799
GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: entity.hh:812
bool mightVanish() const
Returns true, if entity might disappear during the next call to adapt()
Definition: entity.hh:820
Default Implementations for EntityImp.
Definition: entity.hh:740
GridImp::template Codim< cd >::EntityPointer EntityPointer
The corresponding entity seed (for storage of entities)
Definition: entity.hh:755
GridImp::template Codim< cd >::EntitySeed EntitySeed
The corresponding entity seed (for storage of entities)
Definition: entity.hh:752
GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: entity.hh:760
Wrapper class for pointers to entities.
Definition: entitypointer.hh:113
GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: entity.hh:374
bool mightVanish() const
Returns true, if entity might disappear during the next call to adapt(). If the method returns false,...
Definition: entity.hh:664
HierarchicIterator hend(int maxLevel) const
Returns iterator to one past the last son element.
Definition: entity.hh:651
GridImp::template Codim< 0 >::Geometry Geometry
The geometry type of this entity.
Definition: entity.hh:313
const Entity & operator*() const DUNE_DEPRECATED_MSG("This is now an Entity instead of an EntityPointer. You do not have to dereference it anymore!")
Dereference Entity to itself for backwards compatibility with EntityPointer.
Definition: entity.hh:449
Entity & operator=(const Entity &other)
Copy assignment operator from an existing entity.
Definition: entity.hh:431
unsigned int subEntities(unsigned int codim) const
Number of subentities with codimension codim.
Definition: entity.hh:489
Codim< codim >::Entity subEntity(int i) const
Obtain a subentity.
Definition: entity.hh:546
Entity(EntityImp< 0, dim, GridImp > &&e)
Move constructor from EntityImp.
Definition: entity.hh:681
Entity(Entity &&other)
Move constructor from an existing entity.
Definition: entity.hh:426
Entity father() const
Inter-level access to father entity on the next-coarser grid. The given entity resulted directly from...
Definition: entity.hh:564
Entity & operator=(Entity &&other)
Move assignment operator from an existing entity.
Definition: entity.hh:438
Entity(const EntityImp< 0, dim, GridImp > &e)
Copy constructor from EntityImp.
Definition: entity.hh:678
int DUNE_DEPRECATED_MSG("Use subEntities(unsigned int) instead!") count() const
Number of subentities with codimension cc.
Definition: entity.hh:482
HierarchicIterator hbegin(int maxLevel) const
Inter-level access to elements that resulted from (recursive) subdivision of this element.
Definition: entity.hh:639
bool hasBoundaryIntersections() const
Returns true, if entity has intersections with boundary.
Definition: entity.hh:668
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: entity.hh:379
Entity(const Entity &other)
Copy constructor from an existing entity.
Definition: entity.hh:421
Geometry geometry() const
obtain geometric realization of the entity
Definition: entity.hh:369
bool operator==(const Entity &other) const
Compares two entities for equality.
Definition: entity.hh:382
bool hasFather() const
Return true if entity has a father entity which can be accessed using the father() method.
Definition: entity.hh:585
int level() const
The level of this entity.
Definition: entity.hh:363
GridImp::template Codim< 0 >::EntitySeed EntitySeed
The corresponding entity seed (for storage of entities)
Definition: entity.hh:316
GridImp::template Codim< 0 >::LocalGeometry LocalGeometry
The geometry type of this entity when the geometry is expressed embedded in the father element.
Definition: entity.hh:325
bool isNew() const
Returns true, if the entity has been created during the last call to adapt()
Definition: entity.hh:658
bool isLeaf() const
Returns true if the entity is contained in the leaf grid.
Definition: entity.hh:591
PartitionType partitionType() const
Partition type of this entity.
Definition: entity.hh:366
const Implementation & impl() const
Return const reference to the real implementation.
Definition: entity.hh:299
bool isRegular() const
Returns true if element is of regular type in red/green type refinement. In bisection or hanging node...
Definition: entity.hh:599
bool operator!=(const Entity &other) const
Compares two entities for inequality.
Definition: entity.hh:388
LocalGeometry geometryInFather() const
Provides information how this element has been subdivided from its father element.
Definition: entity.hh:626
const Entity * operator->() const DUNE_DEPRECATED_MSG("This is now an Entity instead of an EntityPointer. You do not have to dereference it anymore!")
Dereference Entity to itself for backwards compatibility with EntityPointer.
Definition: entity.hh:460
GridImp::template Codim< 0 >::EntityPointer EntityPointer
The codim==0 EntityPointer type.
Definition: entity.hh:336
GridImp::HierarchicIterator HierarchicIterator
The HierarchicIterator type.
Definition: entity.hh:339
Wrapper class for entities.
Definition: entity.hh:62
const Implementation & impl() const
Return const reference to the real implementation.
Definition: entity.hh:83
bool operator!=(const Entity &other) const
Compares two entities for inequality.
Definition: entity.hh:161
PartitionType partitionType() const
Partition type of this entity.
Definition: entity.hh:128
Entity & operator=(Entity &&other)
Move assignment operator from an existing entity.
Definition: entity.hh:211
Entity(Entity &&other)
Move constructor from an existing entity.
Definition: entity.hh:199
@ mydimension
Dimensionality of the reference element of the entity.
Definition: entity.hh:112
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: entity.hh:152
@ codimension
Know your own codimension.
Definition: entity.hh:104
Geometry geometry() const
obtain geometric realization of the entity
Definition: entity.hh:142
Entity & operator=(const Entity &other)
Copy assignment operator from an existing entity.
Definition: entity.hh:204
const Entity * operator->() const DUNE_DEPRECATED_MSG("This is now an Entity instead of an EntityPointer. You do not have to dereference it anymore!")
Dereference Entity to itself for backwards compatibility with EntityPointer.
Definition: entity.hh:233
GridImp::template Codim< cd >::Geometry Geometry
The corresponding geometry type.
Definition: entity.hh:97
GridImp::template Codim< cd >::EntitySeed EntitySeed
The corresponding entity seed (for storage of entities)
Definition: entity.hh:100
int level() const
The level of this entity.
Definition: entity.hh:125
Implementation & impl()
Return reference to the real implementation.
Definition: entity.hh:81
Entity(const Entity &other)
Copy constructor from an existing entity.
Definition: entity.hh:194
bool operator==(const Entity &other) const
Compares two entities for equality.
Definition: entity.hh:155
Entity(const EntityImp< cd, dim, GridImp > &e)
Copy constructor from EntityImp.
Definition: entity.hh:248
const Entity & operator*() const DUNE_DEPRECATED_MSG("This is now an Entity instead of an EntityPointer. You do not have to dereference it anymore!")
Dereference Entity to itself for backwards compatibility with EntityPointer.
Definition: entity.hh:222
@ dimension
Know the grid dimension.
Definition: entity.hh:108
GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: entity.hh:147
Entity(EntityImp< cd, dim, GridImp > &&e)
Move constructor from EntityImp.
Definition: entity.hh:251
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
Definition: grid.hh:1030
Mesh entities of codimension 0 ("elements") allow to visit all intersections with "neighboring" eleme...
Definition: intersectioniterator.hh:84
Wrapper and interface class for a static iterator (EntityPointer)
#define DUNE_DEPRECATED_MSG(text)
Mark some entity as deprecated.
Definition: deprecated.hh:169
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:28
Dune namespace.
Definition: alignment.hh:10
STL namespace.
Static tag representing a codimension.
Definition: dimension.hh:22
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)