5#ifndef DUNE_GEOGRID_ENTITY_HH
6#define DUNE_GEOGRID_ENTITY_HH
8#include <dune/geometry/referenceelements.hh>
11#include <dune/grid/geometrygrid/capabilities.hh>
12#include <dune/grid/geometrygrid/cornerstorage.hh>
33 template<
int codim,
class Gr
id,
bool fake = !(Capabilities::hasHostEntity< Gr
id, codim >::v) >
48 template<
int codim,
int dim,
class Gr
id >
56 template<
class Gr
id >
57 class HierarchicIterator;
59 template<
class Gr
id,
class HostIntersectionIterator >
60 class IntersectionIterator;
74 template<
int codim,
class Gr
id >
77 typedef typename std::remove_const< Grid >::type::Traits Traits;
84 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;
93 static const bool fake =
false;
101 typedef typename Traits::ctype
ctype;
108 typedef typename Traits::HostGrid HostGrid;
109 typedef typename Traits::CoordFunction CoordFunction;
130 typedef GeoGrid::CoordVector< mydimension, Grid, fake > CoordVector;
143 : hostEntity_( grid.hostGrid().entity( seed.impl().hostEntitySeed() ) )
147 EntityBase (
const Grid &grid,
const HostElement &hostElement,
int i )
148 : hostEntity_( hostElement.template subEntity<codim>(i) )
153 EntityBase (
const GeometryImpl &geo,
const HostEntity &hostEntity )
154 : hostEntity_( hostEntity )
155 , grid_( &geo.grid() )
159 EntityBase (
const GeometryImpl &geo, HostEntity&& hostEntity )
160 : hostEntity_(
std::move( hostEntity ) )
161 , grid_( &geo.grid() )
165 EntityBase (
const Grid &grid,
const HostEntity& hostEntity )
166 : hostEntity_( hostEntity )
170 EntityBase (
const Grid &grid, HostEntity&& hostEntity )
171 : hostEntity_(
std::move( hostEntity ) )
176 EntityBase (
const EntityBase &other )
177 : hostEntity_( other.hostEntity_ )
178 , grid_( other.grid_ )
182 EntityBase ( EntityBase&& other )
183 : hostEntity_(
std::move( other.hostEntity_ ) )
184 , grid_( other.grid_ )
185 , geo_(
std::move( other.geo_ ) )
190 const EntityBase &operator= (
const EntityBase &other )
192 hostEntity_ = other.hostEntity_;
198 const EntityBase &operator= ( EntityBase&& other )
200 hostEntity_ = std::move( other.hostEntity_ );
201 grid_ = std::move( other.grid_ );
202 geo_ = std::move( other.geo_ );
209 return hostEntity_ == other.hostEntity_;
222 return hostEntity().type();
228 return hostEntity().level();
234 return hostEntity().partitionType();
255 CoordVector coords( hostEntity(), grid().coordFunction() );
256 geo_ = GeometryImpl( grid(), type(), coords );
261 unsigned int subEntities (
unsigned int cc )
const
263 return hostEntity().subEntities( cc );
274 const Grid &grid ()
const { assert( grid_ );
return *grid_; }
276 const HostEntity &hostEntity ()
const
295 template<
class HostIndexSet >
296 typename HostIndexSet::IndexType
297 index (
const HostIndexSet &indexSet )
const
299 return indexSet.template index< codimension >( hostEntity() );
311 template<
class HostIndexSet >
312 typename HostIndexSet::IndexType
313 subIndex (
const HostIndexSet &indexSet,
int i,
unsigned int cd )
const
315 return indexSet.subIndex( hostEntity(), i, cd );
325 template<
class HostIndexSet >
328 return indexSet.contains( hostEntity() );
338 template<
class HostIdSet >
339 typename HostIdSet::IdType
id (
const HostIdSet &idSet )
const
341 return idSet.template id< codimension >( hostEntity() );
346 HostEntity hostEntity_;
348 mutable GeometryImpl geo_;
363 template<
int codim,
class Gr
id >
366 typedef typename std::remove_const< Grid >::type::Traits Traits;
373 static const int codimension = codim;
375 static const int dimension = Traits::dimension;
377 static const int mydimension = dimension - codimension;
379 static const int dimensionworld = Traits::dimensionworld;
382 static const bool fake =
true;
389 typedef typename Traits::ctype
ctype;
396 typedef typename Traits::HostGrid HostGrid;
397 typedef typename Traits::CoordFunction CoordFunction;
418 typedef GeoGrid::CoordVector< mydimension, Grid, fake > CoordVector;
431 EntityBase(
const Grid& grid,
const HostElement& hostElement,
unsigned int subEntity)
432 : hostElement_(hostElement)
433 , subEntity_(subEntity)
438 : hostElement_( grid.hostGrid().entity( seed.impl().hostElementSeed() ) )
439 , subEntity_( seed.impl().subEntity() )
443 EntityBase (
const EntityBase &other )
444 : hostElement_( other.hostElement_ )
445 , subEntity_( other.subEntity_ )
450 EntityBase ( EntityBase &&other )
451 : hostElement_(
std::move( other.hostElement_ ) )
452 , subEntity_(
std::move( other.subEntity_ ) )
453 , grid_(
std::move( other.grid_ ) )
454 , geo_(
std::move( other.geo_ ) )
462 EntityBase(
const Grid& grid,
const HostEntity& hostEntity)
464 DUNE_THROW(
Dune::Exception,
"GeometryGrid: Cannot create fake entity of codim " << codimension <<
" from real host entity.");
469 const EntityBase &operator= (
const EntityBase &other )
471 hostElement_ = other.hostElement_;
472 subEntity_ = other.subEntity_;
478 const EntityBase &operator= ( EntityBase&& other )
480 hostElement_ = std::move( other.hostElement_ );
481 subEntity_ = std::move( other.subEntity_ );
482 grid_ = std::move( other.grid_ );
483 geo_ = std::move( other.geo_ );
490 const bool thisEnd = (subEntity() < 0);
491 const bool otherEnd = (other.subEntity() < 0);
492 if( thisEnd || otherEnd )
493 return thisEnd && otherEnd;
495 const int lvl = level();
496 if( lvl != other.level() )
499 const typename Traits::HostGrid::Traits::LevelIndexSet &indexSet
500 = grid().hostGrid().levelIndexSet( lvl );
503 assert( indexSet.contains( thisElement ) );
504 const HostElement &otherElement = other.hostElement();
505 assert( indexSet.contains( otherElement ) );
507 const int thisIndex = indexSet.subIndex( thisElement, subEntity(), codimension );
508 const int otherIndex = indexSet.subIndex( otherElement, other.subEntity(), codimension );
509 return (thisIndex == otherIndex);
521 auto refElement = referenceElement< ctype, dimension >( hostElement().type() );
522 return refElement.type( subEntity_, codimension );
528 return hostElement().level();
534 auto refElement = referenceElement< ctype, dimension >( hostElement().type() );
540 const int numVertices = refElement.size( subEntity_, codimension, dimension );
541 for(
int i = 1; i < numVertices; ++i )
543 PartitionType vtxType = vertexPartitionType( refElement, i );
546 if( type != vtxType )
571 CoordVector coords( hostElement(), subEntity_, grid().coordFunction() );
572 geo_ = GeometryImpl( grid(), type(), coords );
577 unsigned int subEntities (
unsigned int cc )
const
579 auto refElement = referenceElement< ctype, dimension >( hostElement().type() );
580 return refElement.size( subEntity_, codimension, cc );
590 const Grid &grid ()
const { assert( grid_ );
return *grid_; }
592 const HostEntity &hostEntity ()
const
597 const HostElement &hostElement ()
const
602 int subEntity ()
const {
return subEntity_; }
620 template<
class HostIndexSet >
621 typename HostIndexSet::IndexType
index (
const HostIndexSet &indexSet )
const
623 return indexSet.subIndex( hostElement(), subEntity_, codimension );
635 template<
class HostIndexSet >
636 typename HostIndexSet::IndexType
637 subIndex (
const HostIndexSet &indexSet,
int i,
unsigned int cd )
const
639 auto refElement = referenceElement< ctype, dimension >( hostElement().type() );
640 const int j = refElement.subEntity( subEntity_, codimension, i, codimension+cd );
641 return indexSet.subIndex( hostElement(), j, codimension+cd );
651 template<
class HostIndexSet >
654 return indexSet.contains( hostElement() );
664 template<
class HostIdSet >
665 typename HostIdSet::IdType
id (
const HostIdSet &idSet )
const
667 return idSet.subId( hostElement(), subEntity_, codimension );
675 const int j = refElement.subEntity( subEntity_, codimension, i, dimension );
676 return hostElement().template subEntity< dimension >( j ).partitionType();
680 HostElement hostElement_;
681 unsigned int subEntity_;
683 mutable GeometryImpl geo_;
691 template<
int codim,
int dim,
class Gr
id >
698 typedef typename Base::HostEntity HostEntity;
699 typedef typename Base::HostElement HostElement;
700 typedef typename Base::GeometryImpl GeometryImpl;
701 typedef typename Base::EntitySeed EntitySeed;
705 Entity (
const Grid &grid,
const EntitySeed &seed ) :
Base( grid, seed ) {}
707 Entity (
const Grid &grid,
const HostEntity &hostEntity ) :
Base( grid, hostEntity ) {}
708 Entity (
const Grid &grid, HostEntity&& hostEntity ) :
Base( grid, std::move( hostEntity ) ) {}
710 Entity (
const Grid &grid,
const HostElement &hostEntity,
int i ) :
Base( grid, hostEntity, i ) {}
719 template<
int dim,
class Gr
id >
725 typedef typename std::remove_const< Grid >::type::Traits Traits;
727 typedef typename Traits::HostGrid HostGrid;
734 static const int codimension = Base::codimension;
736 static const int dimension = Base::dimension;
738 static const int mydimension = Base::mydimension;
740 static const int dimensionworld = Base::dimensionworld;
743 static const bool fake = Base::fake;
755 typedef typename Traits::HierarchicIterator HierarchicIterator;
757 typedef typename Traits::LeafIntersectionIterator LeafIntersectionIterator;
759 typedef typename Traits::LevelIntersectionIterator LevelIntersectionIterator;
763 typedef typename Base::HostEntity HostEntity;
764 typedef typename Base::HostElement HostElement;
765 typedef typename Base::GeometryImpl GeometryImpl;
766 typedef typename Base::EntitySeed EntitySeed;
769 using Base::hostEntity;
773 Entity (
const Grid &g,
const HostEntity &hostE ) : Base( g, hostE ) {}
774 Entity (
const Grid &g, HostEntity&& hostE ) : Base( g,
std::move( hostE ) ) {}
775 Entity (
const GeometryImpl &geo,
const HostEntity& hostE ) : Base( geo, hostE ) {}
776 Entity (
const GeometryImpl &geo, HostEntity &&hostE ) : Base( geo,
std::move( hostE ) ) {}
778 Entity (
const Grid &g,
const EntitySeed &seed ) : Base( g, seed ) {}
780 Entity (
const Grid &g,
const HostEntity &hostE,
int i ) : Base( g, hostE )
785 template<
int codim >
786 typename Grid::template Codim< codim >::Entity
787 subEntity (
int i )
const
789 typedef typename Traits::template Codim< codim >::EntityImpl EntityImpl;
790 return EntityImpl( grid(), hostEntity(), i );
793 LevelIntersectionIterator ilevelbegin ()
const
795 typedef GeoGrid::IntersectionIterator< Grid, typename HostGrid::LevelIntersectionIterator > LevelIntersectionIteratorImpl;
796 return LevelIntersectionIteratorImpl( *
this, hostEntity().ilevelbegin() );
799 LevelIntersectionIterator ilevelend ()
const
801 typedef GeoGrid::IntersectionIterator< Grid, typename HostGrid::LevelIntersectionIterator > LevelIntersectionIteratorImpl;
802 return LevelIntersectionIteratorImpl( *
this, hostEntity().ilevelend() );
805 LeafIntersectionIterator ileafbegin ()
const
807 typedef GeoGrid::IntersectionIterator< Grid, typename HostGrid::LeafIntersectionIterator > LeafIntersectionIteratorImpl;
808 return LeafIntersectionIteratorImpl( *
this, hostEntity().ileafbegin() );
811 LeafIntersectionIterator ileafend ()
const
813 typedef GeoGrid::IntersectionIterator< Grid, typename HostGrid::LeafIntersectionIterator > LeafIntersectionIteratorImpl;
814 return LeafIntersectionIteratorImpl( *
this, hostEntity().ileafend() );
817 bool hasBoundaryIntersections ()
const
819 return hostEntity().hasBoundaryIntersections();
824 return hostEntity().isLeaf();
827 EntityFacade father ()
const
829 return Entity( grid(), hostEntity().father() );
832 bool hasFather ()
const
834 return hostEntity().hasFather();
837 LocalGeometry geometryInFather ()
const
839 return hostEntity().geometryInFather();
842 HierarchicIterator hbegin (
int maxLevel )
const
844 typedef GeoGrid::HierarchicIterator< Grid > HierarchicIteratorImpl;
845 return HierarchicIteratorImpl( grid(), hostEntity().hbegin( maxLevel ) );
848 HierarchicIterator hend (
int maxLevel )
const
850 typedef GeoGrid::HierarchicIterator< Grid > HierarchicIteratorImpl;
851 return HierarchicIteratorImpl( grid(), hostEntity().hend( maxLevel ) );
854 bool isRegular ()
const
856 return hostEntity().isRegular();
861 return hostEntity().isNew();
864 bool mightVanish ()
const
866 return hostEntity().mightVanish();
Store a reference to an entity with a minimal memory footprint.
Definition: entityseed.hh:26
EntitySeedImp Implementation
type of underlying implementation
Definition: entityseed.hh:37
Wrapper class for entities.
Definition: entity.hh:66
Base class for Dune-Exceptions.
Definition: exceptions.hh:96
GeometryType type() const
obtain the name of the corresponding reference element
Definition: entity.hh:220
bool equals(const EntityBase &other) const
compare two entities
Definition: entity.hh:207
Traits::ctype ctype
coordinate type of the grid
Definition: entity.hh:101
Geometry geometry() const
Definition: entity.hh:251
void initialize(const HostEntity &hostEntity)
initialize an entity
Definition: entity.hh:286
EntitySeed seed() const
return EntitySeed of host grid entity
Definition: entity.hh:267
HostIdSet::IdType id(const HostIdSet &idSet) const
obtain the entity's id from a host IdSet
Definition: entity.hh:339
Traits::template Codim< codimension >::Geometry Geometry
type of corresponding geometry
Definition: entity.hh:104
HostGrid::template Codim< codimension >::Entity HostEntity
type of corresponding host entity
Definition: entity.hh:116
Traits::template Codim< codimension >::EntitySeed EntitySeed
type of corresponding entity seed
Definition: entity.hh:119
HostIndexSet::IndexType index(const HostIndexSet &indexSet) const
obtain the entity's index from a host IndexSet
Definition: entity.hh:297
HostGrid::template Codim< 0 >::Entity HostElement
type of host elements, i.e., of host entities of codimension 0
Definition: entity.hh:122
PartitionType partitionType() const
obtain the partition type of this entity
Definition: entity.hh:232
int level() const
obtain the level of this entity
Definition: entity.hh:226
HostIndexSet::IndexType subIndex(const HostIndexSet &indexSet, int i, unsigned int cd) const
obtain the index of a subentity from a host IndexSet
Definition: entity.hh:313
bool isContained(const HostIndexSet &indexSet) const
check whether the entity is contained in a host index set
Definition: entity.hh:326
int level() const
obtain the level of this entity
Definition: entity.hh:526
HostGrid::template Codim< 0 >::Entity HostElement
type of host elements, i.e., of host entities of codimension 0
Definition: entity.hh:410
PartitionType partitionType() const
obtain the partition type of this entity
Definition: entity.hh:532
bool equals(const EntityBase &other) const
compare two entities
Definition: entity.hh:488
HostIndexSet::IndexType index(const HostIndexSet &indexSet) const
obtain the entity's index from a host IndexSet
Definition: entity.hh:621
Traits::template Codim< codimension >::EntitySeed EntitySeed
type of corresponding entity seed
Definition: entity.hh:407
Traits::template Codim< codimension >::Geometry Geometry
type of corresponding geometry
Definition: entity.hh:392
HostIdSet::IdType id(const HostIdSet &idSet) const
obtain the entity's id from a host IdSet
Definition: entity.hh:665
EntitySeed seed() const
return EntitySeed of host grid entity
Definition: entity.hh:584
HostIndexSet::IndexType subIndex(const HostIndexSet &indexSet, int i, unsigned int cd) const
obtain the index of a subentity from a host IndexSet
Definition: entity.hh:637
void initialize(const HostElement &hostElement)
initialize an entity
Definition: entity.hh:611
Geometry geometry() const
Definition: entity.hh:567
Traits::ctype ctype
coordinate type of the grid
Definition: entity.hh:389
bool isContained(const HostIndexSet &indexSet) const
check whether the entity is contained in a host index set
Definition: entity.hh:652
GeometryType type() const
obtain the name of the corresponding reference element
Definition: entity.hh:519
HostGrid::template Codim< codimension >::Entity HostEntity
type of corresponding host entity
Definition: entity.hh:404
actual implementation of the entity
Definition: entity.hh:34
DUNE-conform implementation of the entity.
Definition: entity.hh:694
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
Grid abstract base class.
Definition: grid.hh:375
Default exception for dummy implementations.
Definition: exceptions.hh:355
Different resources needed by all grid implementations.
#define DUNE_THROW(E,...)
Definition: exceptions.hh:312
Dune namespace.
Definition: alignedallocator.hh:13
Static tag representing a codimension.
Definition: dimension.hh:24
typename Container::ReferenceElement ReferenceElement
The reference element type.
Definition: referenceelements.hh:146