dune-grid  2.3.0
geometrygrid/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_GEOGRID_ENTITY_HH
4 #define DUNE_GEOGRID_ENTITY_HH
5 
6 #include <dune/common/nullptr.hh>
7 
8 #include <dune/geometry/referenceelements.hh>
9 
10 #include <dune/grid/common/grid.hh>
13 
14 namespace Dune
15 {
16 
17  namespace GeoGrid
18  {
19 
20  // Internal Forward Declarations
21  // -----------------------------
22 
33  template< int codim, class Grid, bool fake = !(Capabilities::hasHostEntity< Grid, codim >::v) >
34  class EntityBase;
35 
48  template< int codim, int dim, class Grid >
49  class Entity;
50 
51 
52 
53  // External Forward Declarations
54  // -----------------------------
55 
56  template< class Grid >
58 
59  template< class Grid, class HostIntersectionIterator >
61 
62 
63 
64  // EntityBase (real)
65  // -----------------
66 
74  template< int codim, class Grid >
75  class EntityBase< codim, Grid, false >
76  {
77  typedef typename remove_const< Grid >::type::Traits Traits;
78 
79  public:
83  static const int codimension = codim;
86  static const int dimension = Traits::dimension;
88  static const int mydimension = dimension - codimension;
90  static const int dimensionworld = Traits::dimensionworld;
91 
93  static const bool fake = false;
94 
100  typedef typename Traits::ctype ctype;
102 
104  typedef typename Traits::template Codim< codimension >::Geometry Geometry;
107  private:
108  typedef typename Traits::HostGrid HostGrid;
109  typedef typename Traits::CoordFunction CoordFunction;
110 
111  public:
115  typedef typename HostGrid::template Codim< codimension >::Entity HostEntity;
118  typedef typename HostGrid::template Codim< codimension >::EntityPointer HostEntityPointer;
119 
121  typedef typename Traits::template Codim< codimension >::EntitySeed EntitySeed;
122 
124  typedef typename HostGrid::template Codim< 0 >::Entity HostElement;
127  typedef typename Traits::template Codim< codim >::GeometryImpl GeometryImpl;
128 
129  private:
130  typedef typename HostGrid::template Codim< codimension >::Geometry HostGeometry;
131 
133 
134  public:
144  explicit EntityBase ( const Grid &grid )
145  : geo_( grid ),
146  hostEntity_( nullptr )
147  {}
148 
155  explicit EntityBase ( const GeometryImpl &geo )
156  : geo_( geo ),
157  hostEntity_( nullptr )
158  {}
159 
160  EntityBase ( const EntityBase &other )
161  : geo_( other.geo_ ),
162  hostEntity_( nullptr )
163  {}
164 
167  const EntityBase &operator= ( const EntityBase &other )
168  {
169  geo_ = other.geo_;
170  hostEntity_ = nullptr;
171  return *this;
172  }
173 
174  operator bool () const { return bool( hostEntity_ ); }
175 
176  public:
185  {
186  return hostEntity().type();
187  }
188 
190  int level () const
191  {
192  return hostEntity().level();
193  }
194 
197  {
198  return hostEntity().partitionType();
199  }
200 
216  {
217  if( !geo_ )
218  {
219  CoordVector coords( hostEntity(), grid().coordFunction() );
220  geo_ = GeometryImpl( grid(), type(), coords );
221  }
222  return Geometry( geo_ );
223  }
224 
226  EntitySeed seed () const { return typename EntitySeed::Implementation( hostEntity().seed() ); }
233  const Grid &grid () const { return geo_.grid(); }
234 
235  const HostEntity &hostEntity () const
236  {
237  assert( *this );
238  return *hostEntity_;
239  }
240 
248  void initialize ( const HostEntity &hostEntity ) { hostEntity_ = &hostEntity; }
249 
257  template< class HostIndexSet >
258  typename HostIndexSet::IndexType
259  index ( const HostIndexSet &indexSet ) const
260  {
261  return indexSet.template index< codimension >( hostEntity() );
262  }
263 
273  template< class HostIndexSet >
274  typename HostIndexSet::IndexType
275  subIndex ( const HostIndexSet &indexSet, int i, unsigned int cd ) const
276  {
277  return indexSet.subIndex( hostEntity(), i, cd );
278  }
279 
287  template< class HostIndexSet >
288  bool isContained ( const HostIndexSet &indexSet ) const
289  {
290  return indexSet.contains( hostEntity() );
291  }
292 
300  template< class HostIdSet >
301  typename HostIdSet::IdType id ( const HostIdSet &idSet ) const
302  {
303  return idSet.template id< codimension >( hostEntity() );
304  }
307  private:
308  mutable GeometryImpl geo_;
309  const HostEntity *hostEntity_;
310  };
311 
312 
313 
314  // EntityBase (fake)
315  // -----------------
316 
324  template< int codim, class Grid >
325  class EntityBase< codim, Grid, true >
326  {
327  typedef typename remove_const< Grid >::type::Traits Traits;
328 
329  public:
333  static const int codimension = codim;
336  static const int dimension = Traits::dimension;
338  static const int mydimension = dimension - codimension;
340  static const int dimensionworld = Traits::dimensionworld;
341 
343  static const bool fake = true;
349  typedef typename Traits::ctype ctype;
351 
353  typedef typename Traits::template Codim< codimension >::Geometry Geometry;
356  private:
357  typedef typename Traits::HostGrid HostGrid;
358  typedef typename Traits::CoordFunction CoordFunction;
359 
360  public:
364  typedef typename HostGrid::template Codim< codimension >::Entity HostEntity;
367  typedef typename HostGrid::template Codim< codimension >::EntityPointer HostEntityPointer;
368 
370  typedef typename Traits::template Codim< codimension >::EntitySeed EntitySeed;
371 
373  typedef typename HostGrid::template Codim< 0 >::Entity HostElement;
376  typedef typename Traits::template Codim< codimension >::GeometryImpl GeometryImpl;
377 
378  private:
379  typedef typename HostGrid::template Codim< 0 >::Geometry HostGeometry;
380  typedef typename HostGrid::template Codim< dimension >::EntityPointer HostVertexPointer;
381 
383 
384  public:
395  EntityBase ( const Grid &grid, int subEntity )
396  : geo_( grid ),
397  hostElement_( nullptr ),
398  subEntity_( subEntity )
399  {}
400 
408  EntityBase ( const GeometryImpl &geo, int subEntity )
409  : geo_( geo ),
410  hostElement_( nullptr ),
411  subEntity_( subEntity )
412  {}
413 
414  EntityBase ( const EntityBase &other )
415  : geo_( other.geo_ ),
416  hostElement_( nullptr ),
417  subEntity_( other.subEntity_ )
418  {}
419 
422  const EntityBase &operator= ( const EntityBase &other )
423  {
424  geo_ = other.geo_;
425  hostElement_ = nullptr;
426  subEntity_ = other.subEntity_;
427  return *this;
428  }
429 
430  operator bool () const { return bool( hostElement_ ); }
431 
440  {
441  const ReferenceElement< ctype, dimension > &refElement
442  = ReferenceElements< ctype, dimension >::general( hostElement().type() );
443  return refElement.type( subEntity_, codimension );
444  }
445 
447  int level () const
448  {
449  return hostElement().level();
450  }
451 
454  {
456  return InteriorEntity;
457 
458  const ReferenceElement< ctype, dimension > &refElement
459  = ReferenceElements< ctype, dimension >::general( hostElement().type() );
460 
461  PartitionType type = vertexPartitionType( refElement, 0 );
462  if( (type != BorderEntity) && (type != FrontEntity) )
463  return type;
464 
465  const int numVertices = refElement.size( subEntity_, codimension, dimension );
466  for( int i = 1; i < numVertices; ++i )
467  {
468  PartitionType vtxType = vertexPartitionType( refElement, i );
469  if( (vtxType != BorderEntity) && (vtxType != FrontEntity) )
470  return vtxType;
471  if( type != vtxType )
472  return OverlapEntity;
473  }
474  assert( (type == BorderEntity) || (type == FrontEntity) );
475  return type;
476  }
477 
493  {
494  if( !geo_ )
495  {
496  CoordVector coords( hostElement(), subEntity_, grid().coordFunction() );
497  geo_ = GeometryImpl( grid(), type(), coords );
498  }
499  return Geometry( geo_ );
500  }
501 
503  EntitySeed seed () const { return typename EntitySeed::Implementation( hostElement().seed(), subEntity_ ); }
509  const Grid &grid () const { return geo_.grid(); }
510 
511  const HostEntity &hostEntity () const
512  {
513  DUNE_THROW( NotImplemented, "HostGrid has no entities of codimension " << codimension << "." );
514  }
515 
516  const HostElement &hostElement () const
517  {
518  assert( *this );
519  return *hostElement_;
520  }
521 
522  int subEntity () const { return subEntity_; }
523 
531  void initialize ( const HostElement &hostElement ) { hostElement_ = &hostElement; }
532 
540  template< class HostIndexSet >
541  typename HostIndexSet::IndexType index ( const HostIndexSet &indexSet ) const
542  {
543  return indexSet.subIndex( hostElement(), subEntity_, codimension );
544  }
545 
555  template< class HostIndexSet >
556  typename HostIndexSet::IndexType
557  subIndex ( const HostIndexSet &indexSet, int i, unsigned int cd ) const
558  {
559  const ReferenceElement< ctype, dimension > &refElement
560  = ReferenceElements< ctype, dimension >::general( hostElement().type() );
561  const int j = refElement.subEntity( subEntity_, codimension, i, codimension+cd );
562  return indexSet.subIndex( hostElement(), j, codimension+cd );
563  }
564 
572  template< class HostIndexSet >
573  bool isContained ( const HostIndexSet &indexSet ) const
574  {
575  return indexSet.contains( hostElement() );
576  }
577 
585  template< class HostIdSet >
586  typename HostIdSet::IdType id ( const HostIdSet &idSet ) const
587  {
588  return idSet.subId( hostElement(), subEntity_, codimension );
589  }
592  private:
594  vertexPartitionType ( const ReferenceElement< ctype, dimension > &refElement, int i ) const
595  {
596  const int j = refElement.subEntity( subEntity_, codimension, 0, dimension );
597  return hostElement().template subEntity< dimension >( j )->partitionType();
598  }
599 
600  private:
601  mutable GeometryImpl geo_;
602  const HostElement *hostElement_;
603  unsigned int subEntity_;
604  };
605 
606 
607 
608  // Entity
609  // ------
610 
611  template< int codim, int dim, class Grid >
612  class Entity
613  : public EntityBase< codim, Grid >
614  {
615  typedef EntityBase< codim, Grid > Base;
616 
617  public:
618  typedef typename Base::HostEntity HostEntity;
619  typedef typename Base::HostElement HostElement;
620  typedef typename Base::GeometryImpl GeometryImpl;
621 
622  explicit Entity ( const Grid &grid )
623  : Base( grid )
624  {}
625 
626  explicit Entity ( const GeometryImpl &geo )
627  : Base( geo )
628  {}
629 
630  Entity ( const Grid &grid, int subEntity )
631  : Base( grid, subEntity )
632  {}
633 
634  Entity ( const GeometryImpl &geo, int subEntity )
635  : Base( geo, subEntity )
636  {}
637  };
638 
639 
640 
641  // Entity for codimension 0
642  // ------------------------
643 
644  template< int dim, class Grid >
645  class Entity< 0, dim, Grid >
646  : public EntityBase< 0, Grid >
647  {
648  typedef EntityBase< 0, Grid > Base;
649 
650  typedef typename remove_const< Grid >::type::Traits Traits;
651 
652  typedef typename Traits::HostGrid HostGrid;
653 
654  public:
658  static const int codimension = Base::codimension;
661  static const int dimension = Base::dimension;
663  static const int mydimension = Base::mydimension;
665  static const int dimensionworld = Base::dimensionworld;
666 
668  static const bool fake = Base::fake;
674  typedef typename Traits::template Codim< codimension >::LocalGeometry LocalGeometry;
677  typedef typename Traits::template Codim< codimension >::EntityPointer EntityPointer;
678 
680  typedef typename Traits::HierarchicIterator HierarchicIterator;
682  typedef typename Traits::LeafIntersectionIterator LeafIntersectionIterator;
684  typedef typename Traits::LevelIntersectionIterator LevelIntersectionIterator;
685 
688  typedef typename Base::HostEntity HostEntity;
689  typedef typename Base::HostElement HostElement;
690  typedef typename Base::GeometryImpl GeometryImpl;
691 
692  using Base::grid;
693  using Base::hostEntity;
694 
695  explicit Entity ( const Grid &grid )
696  : Base( grid )
697  {}
698 
699  explicit Entity ( const GeometryImpl &geo )
700  : Base( geo )
701  {}
702 
703  template< int codim >
704  int count () const
705  {
706  return hostEntity().template count< codim >();
707  }
708 
709  template< int codim >
710  typename Grid::template Codim< codim >::EntityPointer
711  subEntity ( int i ) const
712  {
713  typedef typename Traits::template Codim< codim >::EntityPointerImpl EntityPointerImpl;
714  return EntityPointerImpl( grid(), hostEntity(), i );
715  }
716 
718  {
720  return LevelIntersectionIteratorImpl( *this, hostEntity().ilevelbegin() );
721  }
722 
724  {
726  return LevelIntersectionIteratorImpl( *this, hostEntity().ilevelend() );
727  }
728 
730  {
732  return LeafIntersectionIteratorImpl( *this, hostEntity().ileafbegin() );
733  }
734 
736  {
738  return LeafIntersectionIteratorImpl( *this, hostEntity().ileafend() );
739  }
740 
742  {
743  return hostEntity().hasBoundaryIntersections();
744  }
745 
746  bool isLeaf () const
747  {
748  return hostEntity().isLeaf();
749  }
750 
752  {
753  typedef typename Traits::template Codim< 0 >::EntityPointerImpl EntityPointerImpl;
754  return EntityPointerImpl( grid(), hostEntity().father() );
755  }
756 
757  bool hasFather () const
758  {
759  return hostEntity().hasFather();
760  }
761 
763  {
764  return hostEntity().geometryInFather();
765  }
766 
767  HierarchicIterator hbegin ( int maxLevel ) const
768  {
769  typedef GeoGrid::HierarchicIterator< Grid > HierarchicIteratorImpl;
770  return HierarchicIteratorImpl( grid(), hostEntity().hbegin( maxLevel ) );
771  }
772 
773  HierarchicIterator hend ( int maxLevel ) const
774  {
775  typedef GeoGrid::HierarchicIterator< Grid > HierarchicIteratorImpl;
776  return HierarchicIteratorImpl( grid(), hostEntity().hend( maxLevel ) );
777  }
778 
779  bool isRegular () const
780  {
781  return hostEntity().isRegular();
782  }
783 
784  bool isNew () const
785  {
786  return hostEntity().isNew();
787  }
788 
789  bool mightVanish () const
790  {
791  return hostEntity().mightVanish();
792  }
793  };
794 
795  } // namespace GeoGrid
796 
797 } // namespace Dune
798 
799 #endif // #ifndef DUNE_GEOGRID_ENTITY_HH
EntityBase(const GeometryImpl &geo, int subEntity)
construct an uninitialized entity
Definition: geometrygrid/entity.hh:408
on boundary between overlap and ghost
Definition: gridenums.hh:28
Base::GeometryImpl GeometryImpl
Definition: geometrygrid/entity.hh:620
HostGrid::template Codim< codimension >::Entity HostEntity
type of corresponding host entity
Definition: geometrygrid/entity.hh:365
PartitionType partitionType() const
obtain the partition type of this entity
Definition: geometrygrid/entity.hh:453
bool isContained(const HostIndexSet &indexSet) const
check whether the entity is contained in a host index set
Definition: geometrygrid/entity.hh:288
HostIndexSet::IndexType subIndex(const HostIndexSet &indexSet, int i, unsigned int cd) const
obtain the index of a subentity from a host IndexSet
Definition: geometrygrid/entity.hh:275
Entity(const GeometryImpl &geo)
Definition: geometrygrid/entity.hh:699
HierarchicIterator hend(int maxLevel) const
Definition: geometrygrid/entity.hh:773
Grid::template Codim< codim >::EntityPointer subEntity(int i) const
Definition: geometrygrid/entity.hh:711
Traits::LevelIntersectionIterator LevelIntersectionIterator
type of level intersection iterator
Definition: geometrygrid/entity.hh:684
HostGrid::template Codim< 0 >::Entity HostElement
type of host elements, i.e., of host entities of codimension 0
Definition: geometrygrid/entity.hh:373
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
EntityBase(const EntityBase &other)
Definition: geometrygrid/entity.hh:160
HostIndexSet::IndexType index(const HostIndexSet &indexSet) const
obtain the entity's index from a host IndexSet
Definition: geometrygrid/entity.hh:541
Base::HostElement HostElement
Definition: geometrygrid/entity.hh:689
Traits::ctype ctype
coordinate type of the grid
Definition: geometrygrid/entity.hh:101
Traits::template Codim< codim >::GeometryImpl GeometryImpl
Definition: geometrygrid/entity.hh:127
bool hasBoundaryIntersections() const
Definition: geometrygrid/entity.hh:741
HierarchicIterator hbegin(int maxLevel) const
Definition: geometrygrid/entity.hh:767
Traits::template Codim< codimension >::Geometry Geometry
type of corresponding geometry
Definition: geometrygrid/entity.hh:104
HostGrid::template Codim< codimension >::Entity HostEntity
type of corresponding host entity
Definition: geometrygrid/entity.hh:116
bool mightVanish() const
Definition: geometrygrid/entity.hh:789
HostGrid::template Codim< codimension >::EntityPointer HostEntityPointer
type of corresponding host entity pointer
Definition: geometrygrid/entity.hh:118
void initialize(const HostElement &hostElement)
initiliaze an entity
Definition: geometrygrid/entity.hh:531
DUNE-conform implementation of the entityThis class merely changes the template parameters of the ent...
Definition: geometrygrid/entity.hh:49
EntityPointer father() const
Definition: geometrygrid/entity.hh:751
EntityBase(const EntityBase &other)
Definition: geometrygrid/entity.hh:414
GeometryType type() const
obtain the name of the corresponding reference element
Definition: geometrygrid/entity.hh:184
Entity(const Grid &grid)
Definition: geometrygrid/entity.hh:622
Traits::template Codim< codimension >::LocalGeometry LocalGeometry
type of corresponding local geometry
Definition: geometrygrid/entity.hh:675
const Grid & grid() const
Definition: geometrygrid/entity.hh:233
Entity(const Grid &grid, int subEntity)
Definition: geometrygrid/entity.hh:630
bool isNew() const
Definition: geometrygrid/entity.hh:784
Traits::template Codim< codimension >::Geometry Geometry
type of corresponding geometry
Definition: geometrygrid/entity.hh:353
on boundary between interior and overlap
Definition: gridenums.hh:26
EntitySeedImp Implementation
Export the implementation type.
Definition: common/entityseed.hh:31
Base::HostEntity HostEntity
Definition: geometrygrid/entity.hh:688
Geometry geometry() const
Definition: geometrygrid/entity.hh:215
int count() const
Definition: geometrygrid/entity.hh:704
const Grid & grid() const
Definition: geometrygrid/entity.hh:509
EntityBase(const GeometryImpl &geo)
construct an uninitialized entity
Definition: geometrygrid/entity.hh:155
GeometryType type() const
obtain the name of the corresponding reference element
Definition: geometrygrid/entity.hh:439
LeafIntersectionIterator ileafend() const
Definition: geometrygrid/entity.hh:735
actual implementation of the entity
Definition: geometrygrid/entity.hh:34
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:24
HostIdSet::IdType id(const HostIdSet &idSet) const
obtain the entity's id from a host IdSet
Definition: geometrygrid/entity.hh:586
Traits::template Codim< codimension >::EntityPointer EntityPointer
type of corresponding entity pointer
Definition: geometrygrid/entity.hh:677
bool isLeaf() const
Definition: geometrygrid/entity.hh:746
EntitySeed seed() const
return EntitySeed of host grid entity
Definition: geometrygrid/entity.hh:503
Traits::template Codim< codimension >::GeometryImpl GeometryImpl
Definition: geometrygrid/entity.hh:376
Grid abstract base classThis class is the base class for all grid implementations. Although no virtual functions are used we call it abstract since its methods do not contain an implementation but forward to the methods of the derived class via the Barton-Nackman trick.
Definition: common/grid.hh:386
void initialize(const HostEntity &hostEntity)
initiliaze an entity
Definition: geometrygrid/entity.hh:248
EntityBase(const Grid &grid)
construct an uninitialized entity
Definition: geometrygrid/entity.hh:144
Traits::template Codim< codimension >::EntitySeed EntitySeed
type of corresponding entity seed
Definition: geometrygrid/entity.hh:370
Entity(const GeometryImpl &geo, int subEntity)
Definition: geometrygrid/entity.hh:634
bool isRegular() const
Definition: geometrygrid/entity.hh:779
HostIndexSet::IndexType index(const HostIndexSet &indexSet) const
obtain the entity's index from a host IndexSet
Definition: geometrygrid/entity.hh:259
LevelIntersectionIterator ilevelbegin() const
Definition: geometrygrid/entity.hh:717
Specialize with 'true' if implementation supports parallelism. (default=false)
Definition: common/capabilities.hh:64
Traits::ctype ctype
coordinate type of the grid
Definition: geometrygrid/entity.hh:350
Geometry geometry() const
Definition: geometrygrid/entity.hh:492
Traits::HierarchicIterator HierarchicIterator
type of hierarchic iterator
Definition: geometrygrid/entity.hh:680
LeafIntersectionIterator ileafbegin() const
Definition: geometrygrid/entity.hh:729
Traits::LeafIntersectionIterator LeafIntersectionIterator
type of leaf intersection iterator
Definition: geometrygrid/entity.hh:682
HostGrid::template Codim< codimension >::EntityPointer HostEntityPointer
type of corresponding host entity pointer
Definition: geometrygrid/entity.hh:367
HostIdSet::IdType id(const HostIdSet &idSet) const
obtain the entity's id from a host IdSet
Definition: geometrygrid/entity.hh:301
Traits::template Codim< codimension >::EntitySeed EntitySeed
type of corresponding entity seed
Definition: geometrygrid/entity.hh:121
all entities lying in the overlap zone
Definition: gridenums.hh:27
LevelIntersectionIterator ilevelend() const
Definition: geometrygrid/entity.hh:723
Different resources needed by all grid implementations.
Definition: cornerstorage.hh:20
bool isContained(const HostIndexSet &indexSet) const
check whether the entity is contained in a host index set
Definition: geometrygrid/entity.hh:573
HostGrid::template Codim< 0 >::Entity HostElement
type of host elements, i.e., of host entities of codimension 0
Definition: geometrygrid/entity.hh:124
const HostEntity & hostEntity() const
Definition: geometrygrid/entity.hh:511
Definition: geometrygrid/entity.hh:57
int level() const
obtain the level of this entity
Definition: geometrygrid/entity.hh:447
int level() const
obtain the level of this entity
Definition: geometrygrid/entity.hh:190
Base::HostEntity HostEntity
Definition: geometrygrid/entity.hh:618
HostIndexSet::IndexType subIndex(const HostIndexSet &indexSet, int i, unsigned int cd) const
obtain the index of a subentity from a host IndexSet
Definition: geometrygrid/entity.hh:557
Base::GeometryImpl GeometryImpl
Definition: geometrygrid/entity.hh:690
EntityBase(const Grid &grid, int subEntity)
construct an uninitialized entity
Definition: geometrygrid/entity.hh:395
EntitySeed seed() const
return EntitySeed of host grid entity
Definition: geometrygrid/entity.hh:226
Base::HostElement HostElement
Definition: geometrygrid/entity.hh:619
LocalGeometry geometryInFather() const
Definition: geometrygrid/entity.hh:762
bool hasFather() const
Definition: geometrygrid/entity.hh:757
int subEntity() const
Definition: geometrygrid/entity.hh:522
const HostElement & hostElement() const
Definition: geometrygrid/entity.hh:516
all interior entities
Definition: gridenums.hh:25
const HostEntity & hostEntity() const
Definition: geometrygrid/entity.hh:235
PartitionType partitionType() const
obtain the partition type of this entity
Definition: geometrygrid/entity.hh:196
Entity(const GeometryImpl &geo)
Definition: geometrygrid/entity.hh:626
Definition: geometrygrid/entity.hh:60
Entity(const Grid &grid)
Definition: geometrygrid/entity.hh:695