3#ifndef DUNE_GEOGRID_ENTITY_HH
4#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 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;
132 typedef GeoGrid::CoordVector< mydimension, Grid, fake > CoordVector;
145 : hostEntity_( grid.hostGrid().entity( grid.getRealImplementation(seed).hostEntitySeed() ) )
149 EntityBase (
const Grid &grid,
const HostElement &hostElement,
int i )
150 : hostEntity_( hostElement.template subEntity<codim>(i) )
155 EntityBase (
const GeometryImpl &geo,
const HostEntity &hostEntity )
156 : hostEntity_( hostEntity )
157 , grid_( &geo.grid() )
161 EntityBase (
const GeometryImpl &geo, HostEntity&& hostEntity )
162 : hostEntity_(
std::move( hostEntity ) )
163 , grid_( &geo.grid() )
167 EntityBase (
const Grid &grid,
const HostEntity& hostEntity )
168 : hostEntity_( hostEntity )
172 EntityBase (
const Grid &grid, HostEntity&& hostEntity )
173 : hostEntity_(
std::move( hostEntity ) )
178 EntityBase (
const EntityBase &other )
179 : hostEntity_( other.hostEntity_ )
180 , grid_( other.grid_ )
184 EntityBase ( EntityBase&& other )
185 : hostEntity_(
std::move( other.hostEntity_ ) )
186 , grid_( other.grid_ )
187 , geo_(
std::move( other.geo_ ) )
192 const EntityBase &operator= (
const EntityBase &other )
194 hostEntity_ = other.hostEntity_;
200 const EntityBase &operator= ( EntityBase&& other )
202 hostEntity_ = std::move( other.hostEntity_ );
203 grid_ = std::move( other.grid_ );
204 geo_ = std::move( other.geo_ );
211 return hostEntity_ == other.hostEntity_;
224 return hostEntity().type();
230 return hostEntity().level();
236 return hostEntity().partitionType();
257 CoordVector coords( hostEntity(), grid().coordFunction() );
258 geo_ = GeometryImpl( grid(), type(), coords );
271 const Grid &grid ()
const { assert( grid_ );
return *grid_; }
273 const HostEntity &hostEntity ()
const
292 template<
class HostIndexSet >
293 typename HostIndexSet::IndexType
294 index (
const HostIndexSet &indexSet )
const
296 return indexSet.template index< codimension >( hostEntity() );
308 template<
class HostIndexSet >
309 typename HostIndexSet::IndexType
310 subIndex (
const HostIndexSet &indexSet,
int i,
unsigned int cd )
const
312 return indexSet.subIndex( hostEntity(), i, cd );
322 template<
class HostIndexSet >
325 return indexSet.contains( hostEntity() );
335 template<
class HostIdSet >
336 typename HostIdSet::IdType
id (
const HostIdSet &idSet )
const
338 return idSet.template id< codimension >( hostEntity() );
343 HostEntity hostEntity_;
345 mutable GeometryImpl geo_;
360 template<
int codim,
class Gr
id >
363 typedef typename remove_const< Grid >::type::Traits Traits;
370 static const int codimension = codim;
372 static const int dimension = Traits::dimension;
374 static const int mydimension = dimension - codimension;
376 static const int dimensionworld = Traits::dimensionworld;
379 static const bool fake =
true;
386 typedef typename Traits::ctype
ctype;
393 typedef typename Traits::HostGrid HostGrid;
394 typedef typename Traits::CoordFunction CoordFunction;
418 typedef GeoGrid::CoordVector< mydimension, Grid, fake > CoordVector;
424 EntityBase () : geo_(), hostElement_(), subEntity_( -1 ) {}
428 : hostElement_( grid.hostGrid().entity( grid.getRealImplementation(seed).hostElementSeed() ) )
430 , subEntity_( grid.getRealImplementation(seed).subEntity() )
433 EntityBase (
const EntityBase &other )
434 : geo_( other.geo_ ),
435 hostElement_( other.hostElement_ ),
436 subEntity_( other.subEntity_ )
439 EntityBase ( EntityBase &&other )
440 : geo_(
std::move( other.geo_ ) ),
441 hostElement_(
std::move( other.hostElement_ ) ),
442 subEntity_(
std::move( other.subEntity_ ) )
447 const EntityBase &operator= (
const EntityBase &other )
450 hostElement_ = other.hostElement_;
451 subEntity_ = other.subEntity_;
455 const EntityBase &operator= ( EntityBase&& other )
457 geo_ = std::move( other.geo_ );
458 hostElement_ = std::move( other.hostElement_ );
459 subEntity_ = std::move( other.subEntity_ );
466 const bool thisEnd = (subEntity() < 0);
467 const bool otherEnd = (other.subEntity() < 0);
468 if( thisEnd || otherEnd )
469 return thisEnd && otherEnd;
471 const int lvl = level();
472 if( lvl != other.level() )
475 const typename Traits::HostGrid::Traits::LevelIndexSet &indexSet
476 = grid().hostGrid().levelIndexSet( lvl );
479 assert( indexSet.contains( thisElement ) );
480 const HostElement &otherElement = other.hostElement();
481 assert( indexSet.contains( otherElement ) );
483 const int thisIndex = indexSet.subIndex( thisElement, subEntity(), codimension );
484 const int otherIndex = indexSet.subIndex( otherElement, other.subEntity(), codimension );
485 return (thisIndex == otherIndex);
499 return refElement.
type( subEntity_, codimension );
505 return hostElement().level();
521 const int numVertices = refElement.
size( subEntity_, codimension, dimension );
522 for(
int i = 1; i < numVertices; ++i )
524 PartitionType vtxType = vertexPartitionType( refElement, i );
527 if( type != vtxType )
552 CoordVector coords( hostElement(), subEntity_, grid().coordFunction() );
553 geo_ = GeometryImpl( grid(), type(), coords );
565 const Grid &grid ()
const { assert( grid_ );
return *grid_; }
567 const HostEntity &hostEntity ()
const
572 const HostElement &hostElement ()
const
578 int subEntity ()
const {
return subEntity_; }
596 template<
class HostIndexSet >
597 typename HostIndexSet::IndexType
index (
const HostIndexSet &indexSet )
const
599 return indexSet.subIndex( hostElement(), subEntity_, codimension );
611 template<
class HostIndexSet >
612 typename HostIndexSet::IndexType
613 subIndex (
const HostIndexSet &indexSet,
int i,
unsigned int cd )
const
617 const int j = refElement.
subEntity( subEntity_, codimension, i, codimension+cd );
618 return indexSet.subIndex( hostElement(), j, codimension+cd );
628 template<
class HostIndexSet >
631 return indexSet.contains( hostElement() );
641 template<
class HostIdSet >
642 typename HostIdSet::IdType
id (
const HostIdSet &idSet )
const
644 return idSet.subId( hostElement(), subEntity_, codimension );
652 const int j = refElement.
subEntity( subEntity_, codimension, 0, dimension );
653 return hostElement().template subEntity< dimension >( j )->partitionType();
657 HostElement hostElement_;
658 unsigned int subEntity_;
660 mutable GeometryImpl geo_;
668 template<
int codim,
int dim,
class Gr
id >
675 typedef typename Base::HostEntity HostEntity;
676 typedef typename Base::HostElement HostElement;
677 typedef typename Base::GeometryImpl GeometryImpl;
678 typedef typename Base::EntitySeed EntitySeed;
682 Entity (
const Grid &grid,
const EntitySeed &seed ) :
Base( grid, seed ) {}
684 Entity (
const Grid &grid,
const HostEntity &hostEntity ) :
Base( grid, hostEntity ) {}
685 Entity (
const Grid &grid, HostEntity&& hostEntity ) :
Base( grid, std::move( hostEntity ) ) {}
687 Entity (
const Grid &grid,
const HostElement &hostEntity,
int i ) :
Base( grid, hostEntity, i ) {}
696 template<
int dim,
class Gr
id >
702 typedef typename remove_const< Grid >::type::Traits Traits;
704 typedef typename Traits::HostGrid HostGrid;
711 static const int codimension = Base::codimension;
713 static const int dimension = Base::dimension;
715 static const int mydimension = Base::mydimension;
717 static const int dimensionworld = Base::dimensionworld;
720 static const bool fake = Base::fake;
734 typedef typename Traits::HierarchicIterator HierarchicIterator;
736 typedef typename Traits::LeafIntersectionIterator LeafIntersectionIterator;
738 typedef typename Traits::LevelIntersectionIterator LevelIntersectionIterator;
742 typedef typename Base::HostEntity HostEntity;
743 typedef typename Base::HostElement HostElement;
744 typedef typename Base::GeometryImpl GeometryImpl;
745 typedef typename Base::EntitySeed EntitySeed;
748 using Base::hostEntity;
752 Entity (
const Grid &grid,
const HostEntity &hostEntity ) : Base( grid, hostEntity ) {}
753 Entity (
const Grid &grid, HostEntity&& hostEntity ) : Base( grid,
std::move( hostEntity ) ) {}
754 Entity (
const GeometryImpl &geo,
const HostEntity& hostEntity ) : Base( geo, hostEntity ) {}
755 Entity (
const GeometryImpl &geo, HostEntity &&hostEntity ) : Base( geo,
std::move( hostEntity ) ) {}
757 Entity (
const Grid &grid,
const EntitySeed &seed ) : Base( grid, seed ) {}
759 Entity (
const Grid &grid,
const HostEntity &hostEntity,
int i ) : Base( grid, hostEntity )
764 template<
int codim >
767 return hostEntity().template count< codim >();
770 unsigned int subEntities (
unsigned int codim)
const
772 return hostEntity().subEntities(codim);
775 template<
int codim >
776 typename Grid::template Codim< codim >::Entity
777 subEntity (
int i )
const
779 typedef typename Traits::template Codim< codim >::EntityImpl EntityImpl;
780 return EntityImpl( grid(), hostEntity(), i );
783 LevelIntersectionIterator ilevelbegin ()
const
785 typedef GeoGrid::IntersectionIterator< Grid, typename HostGrid::LevelIntersectionIterator > LevelIntersectionIteratorImpl;
786 return LevelIntersectionIteratorImpl( *
this, hostEntity().ilevelbegin() );
789 LevelIntersectionIterator ilevelend ()
const
791 typedef GeoGrid::IntersectionIterator< Grid, typename HostGrid::LevelIntersectionIterator > LevelIntersectionIteratorImpl;
792 return LevelIntersectionIteratorImpl( *
this, hostEntity().ilevelend() );
795 LeafIntersectionIterator ileafbegin ()
const
797 typedef GeoGrid::IntersectionIterator< Grid, typename HostGrid::LeafIntersectionIterator > LeafIntersectionIteratorImpl;
798 return LeafIntersectionIteratorImpl( *
this, hostEntity().ileafbegin() );
801 LeafIntersectionIterator ileafend ()
const
803 typedef GeoGrid::IntersectionIterator< Grid, typename HostGrid::LeafIntersectionIterator > LeafIntersectionIteratorImpl;
804 return LeafIntersectionIteratorImpl( *
this, hostEntity().ileafend() );
807 bool hasBoundaryIntersections ()
const
809 return hostEntity().hasBoundaryIntersections();
814 return hostEntity().isLeaf();
817 EntityFacade father ()
const
819 return Entity( grid(), hostEntity().father() );
822 bool hasFather ()
const
824 return hostEntity().hasFather();
827 LocalGeometry geometryInFather ()
const
829 return hostEntity().geometryInFather();
832 HierarchicIterator hbegin (
int maxLevel )
const
834 typedef GeoGrid::HierarchicIterator< Grid > HierarchicIteratorImpl;
835 return HierarchicIteratorImpl( grid(), hostEntity().hbegin( maxLevel ) );
838 HierarchicIterator hend (
int maxLevel )
const
840 typedef GeoGrid::HierarchicIterator< Grid > HierarchicIteratorImpl;
841 return HierarchicIteratorImpl( grid(), hostEntity().hend( maxLevel ) );
844 bool isRegular ()
const
846 return hostEntity().isRegular();
851 return hostEntity().isNew();
854 bool mightVanish ()
const
856 return hostEntity().mightVanish();
Wrapper class for pointers to entities.
Definition: entitypointer.hh:113
EntitySeedImp Implementation
Export the implementation type.
Definition: entityseed.hh:31
Wrapper class for entities.
Definition: entity.hh:62
GeometryType type() const
obtain the name of the corresponding reference element
Definition: entity.hh:222
bool equals(const EntityBase &other) const
compare two entities
Definition: entity.hh:209
Traits::ctype ctype
coordinate type of the grid
Definition: entity.hh:101
Geometry geometry() const
Definition: entity.hh:253
void initialize(const HostEntity &hostEntity)
initiliaze an entity
Definition: entity.hh:283
EntitySeed seed() const
return EntitySeed of host grid entity
Definition: entity.hh:264
HostIdSet::IdType id(const HostIdSet &idSet) const
obtain the entity's id from a host IdSet
Definition: entity.hh:336
HostGrid::template Codim< codimension >::EntityPointer HostEntityPointer
type of corresponding host entity pointer
Definition: entity.hh:118
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:121
HostIndexSet::IndexType index(const HostIndexSet &indexSet) const
obtain the entity's index from a host IndexSet
Definition: entity.hh:294
HostGrid::template Codim< 0 >::Entity HostElement
type of host elements, i.e., of host entities of codimension 0
Definition: entity.hh:124
PartitionType partitionType() const
obtain the partition type of this entity
Definition: entity.hh:234
int level() const
obtain the level of this entity
Definition: entity.hh:228
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:310
bool isContained(const HostIndexSet &indexSet) const
check whether the entity is contained in a host index set
Definition: entity.hh:323
int level() const
obtain the level of this entity
Definition: entity.hh:503
HostGrid::template Codim< 0 >::Entity HostElement
type of host elements, i.e., of host entities of codimension 0
Definition: entity.hh:409
PartitionType partitionType() const
obtain the partition type of this entity
Definition: entity.hh:509
bool equals(const EntityBase &other) const
compare two entities
Definition: entity.hh:464
HostIndexSet::IndexType index(const HostIndexSet &indexSet) const
obtain the entity's index from a host IndexSet
Definition: entity.hh:597
Traits::template Codim< codimension >::EntitySeed EntitySeed
type of corresponding entity seed
Definition: entity.hh:406
Traits::template Codim< codimension >::Geometry Geometry
type of corresponding geometry
Definition: entity.hh:389
HostGrid::template Codim< codimension >::EntityPointer HostEntityPointer
type of corresponding host entity pointer
Definition: entity.hh:403
HostIdSet::IdType id(const HostIdSet &idSet) const
obtain the entity's id from a host IdSet
Definition: entity.hh:642
EntitySeed seed() const
return EntitySeed of host grid entity
Definition: entity.hh:559
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:613
void initialize(const HostElement &hostElement)
initiliaze an entity
Definition: entity.hh:587
Geometry geometry() const
Definition: entity.hh:548
Traits::ctype ctype
coordinate type of the grid
Definition: entity.hh:386
bool isContained(const HostIndexSet &indexSet) const
check whether the entity is contained in a host index set
Definition: entity.hh:629
GeometryType type() const
obtain the name of the corresponding reference element
Definition: entity.hh:495
HostGrid::template Codim< codimension >::Entity HostEntity
type of corresponding host entity
Definition: entity.hh:401
actual implementation of the entity
Definition: entity.hh:34
DUNE-conform implementation of the entity.
Definition: entity.hh:671
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
Grid abstract base class.
Definition: grid.hh:388
Default exception for dummy implementations.
Definition: exceptions.hh:288
This class provides access to geometric and topological properties of a reference element.
Definition: referenceelements.hh:55
int size(int c) const
number of subentities of codimension c
Definition: referenceelements.hh:82
int subEntity(int i, int c, int ii, int cc) const
obtain number of ii-th subentity with codim cc of (i,c)
Definition: referenceelements.hh:118
const GeometryType & type(int i, int c) const
obtain the type of subentity (i,c)
Definition: referenceelements.hh:132
Different resources needed by all grid implementations.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:243
Dune namespace.
Definition: alignment.hh:10
Fallback implementation of the nullptr object in C++0x.
Specialize with 'true' if implementation supports parallelism. (default=false)
Definition: capabilities.hh:73
Static tag representing a codimension.
Definition: dimension.hh:22
static const ReferenceElement< ctype, dim > & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:484