3#ifndef DUNE_GEOGRID_ENTITY_HH
4#define DUNE_GEOGRID_ENTITY_HH
6#include <dune/geometry/referenceelements.hh>
9#include <dune/grid/geometrygrid/capabilities.hh>
10#include <dune/grid/geometrygrid/cornerstorage.hh>
31 template<
int codim,
class Gr
id,
bool fake = !(Capabilities::hasHostEntity< Gr
id, codim >::v) >
46 template<
int codim,
int dim,
class Gr
id >
54 template<
class Gr
id >
55 class HierarchicIterator;
57 template<
class Gr
id,
class HostIntersectionIterator >
58 class IntersectionIterator;
72 template<
int codim,
class Gr
id >
75 typedef typename std::remove_const< Grid >::type::Traits Traits;
82 static const int codimension = codim;
84 static const int dimension = Traits::dimension;
86 static const int mydimension = dimension - codimension;
88 static const int dimensionworld = Traits::dimensionworld;
91 static const bool fake =
false;
99 typedef typename Traits::ctype
ctype;
106 typedef typename Traits::HostGrid HostGrid;
107 typedef typename Traits::CoordFunction CoordFunction;
128 typedef GeoGrid::CoordVector< mydimension, Grid, fake > CoordVector;
141 : hostEntity_( grid.hostGrid().entity( seed.impl().hostEntitySeed() ) )
145 EntityBase (
const Grid &grid,
const HostElement &hostElement,
int i )
146 : hostEntity_( hostElement.template subEntity<codim>(i) )
151 EntityBase (
const GeometryImpl &geo,
const HostEntity &hostEntity )
152 : hostEntity_( hostEntity )
153 , grid_( &geo.grid() )
157 EntityBase (
const GeometryImpl &geo, HostEntity&& hostEntity )
158 : hostEntity_(
std::move( hostEntity ) )
159 , grid_( &geo.grid() )
163 EntityBase (
const Grid &grid,
const HostEntity& hostEntity )
164 : hostEntity_( hostEntity )
168 EntityBase (
const Grid &grid, HostEntity&& hostEntity )
169 : hostEntity_(
std::move( hostEntity ) )
174 EntityBase (
const EntityBase &other )
175 : hostEntity_( other.hostEntity_ )
176 , grid_( other.grid_ )
180 EntityBase ( EntityBase&& other )
181 : hostEntity_(
std::move( other.hostEntity_ ) )
182 , grid_( other.grid_ )
183 , geo_(
std::move( other.geo_ ) )
188 const EntityBase &operator= (
const EntityBase &other )
190 hostEntity_ = other.hostEntity_;
196 const EntityBase &operator= ( EntityBase&& other )
198 hostEntity_ = std::move( other.hostEntity_ );
199 grid_ = std::move( other.grid_ );
200 geo_ = std::move( other.geo_ );
207 return hostEntity_ == other.hostEntity_;
220 return hostEntity().type();
226 return hostEntity().level();
232 return hostEntity().partitionType();
253 CoordVector coords( hostEntity(), grid().coordFunction() );
254 geo_ = GeometryImpl( grid(), type(), coords );
259 unsigned int subEntities (
unsigned int cc )
const
261 return hostEntity().subEntities( cc );
272 const Grid &grid ()
const { assert( grid_ );
return *grid_; }
274 const HostEntity &hostEntity ()
const
293 template<
class HostIndexSet >
294 typename HostIndexSet::IndexType
295 index (
const HostIndexSet &indexSet )
const
297 return indexSet.template index< codimension >( hostEntity() );
309 template<
class HostIndexSet >
310 typename HostIndexSet::IndexType
311 subIndex (
const HostIndexSet &indexSet,
int i,
unsigned int cd )
const
313 return indexSet.subIndex( hostEntity(), i, cd );
323 template<
class HostIndexSet >
326 return indexSet.contains( hostEntity() );
336 template<
class HostIdSet >
337 typename HostIdSet::IdType
id (
const HostIdSet &idSet )
const
339 return idSet.template id< codimension >( hostEntity() );
344 HostEntity hostEntity_;
346 mutable GeometryImpl geo_;
361 template<
int codim,
class Gr
id >
364 typedef typename std::remove_const< Grid >::type::Traits Traits;
371 static const int codimension = codim;
373 static const int dimension = Traits::dimension;
375 static const int mydimension = dimension - codimension;
377 static const int dimensionworld = Traits::dimensionworld;
380 static const bool fake =
true;
387 typedef typename Traits::ctype
ctype;
394 typedef typename Traits::HostGrid HostGrid;
395 typedef typename Traits::CoordFunction CoordFunction;
416 typedef GeoGrid::CoordVector< mydimension, Grid, fake > CoordVector;
429 EntityBase(
const Grid& grid,
const HostElement& hostElement,
unsigned int subEntity)
430 : hostElement_(hostElement)
431 , subEntity_(subEntity)
436 : hostElement_( grid.hostGrid().entity( seed.impl().hostElementSeed() ) )
437 , subEntity_( seed.impl().subEntity() )
441 EntityBase (
const EntityBase &other )
442 : hostElement_( other.hostElement_ )
443 , subEntity_( other.subEntity_ )
448 EntityBase ( EntityBase &&other )
449 : hostElement_(
std::move( other.hostElement_ ) )
450 , subEntity_(
std::move( other.subEntity_ ) )
451 , grid_(
std::move( other.grid_ ) )
452 , geo_(
std::move( other.geo_ ) )
460 EntityBase(
const Grid& grid,
const HostEntity& hostEntity)
462 DUNE_THROW(
Dune::Exception,
"GeometryGrid: Cannot create fake entity of codim " << codimension <<
" from real host entity.");
467 const EntityBase &operator= (
const EntityBase &other )
469 hostElement_ = other.hostElement_;
470 subEntity_ = other.subEntity_;
476 const EntityBase &operator= ( EntityBase&& other )
478 hostElement_ = std::move( other.hostElement_ );
479 subEntity_ = std::move( other.subEntity_ );
480 grid_ = std::move( other.grid_ );
481 geo_ = std::move( other.geo_ );
488 const bool thisEnd = (subEntity() < 0);
489 const bool otherEnd = (other.subEntity() < 0);
490 if( thisEnd || otherEnd )
491 return thisEnd && otherEnd;
493 const int lvl = level();
494 if( lvl != other.level() )
497 const typename Traits::HostGrid::Traits::LevelIndexSet &indexSet
498 = grid().hostGrid().levelIndexSet( lvl );
501 assert( indexSet.contains( thisElement ) );
502 const HostElement &otherElement = other.hostElement();
503 assert( indexSet.contains( otherElement ) );
505 const int thisIndex = indexSet.subIndex( thisElement, subEntity(), codimension );
506 const int otherIndex = indexSet.subIndex( otherElement, other.subEntity(), codimension );
507 return (thisIndex == otherIndex);
519 auto refElement = referenceElement< ctype, dimension >( hostElement().type() );
520 return refElement.type( subEntity_, codimension );
526 return hostElement().level();
532 auto refElement = referenceElement< ctype, dimension >( hostElement().type() );
538 const int numVertices = refElement.size( subEntity_, codimension, dimension );
539 for(
int i = 1; i < numVertices; ++i )
541 PartitionType vtxType = vertexPartitionType( refElement, i );
544 if( type != vtxType )
569 CoordVector coords( hostElement(), subEntity_, grid().coordFunction() );
570 geo_ = GeometryImpl( grid(), type(), coords );
575 unsigned int subEntities (
unsigned int cc )
const
577 auto refElement = referenceElement< ctype, dimension >( hostElement().type() );
578 return refElement.size( subEntity_, codimension, cc );
588 const Grid &grid ()
const { assert( grid_ );
return *grid_; }
590 const HostEntity &hostEntity ()
const
595 const HostElement &hostElement ()
const
600 int subEntity ()
const {
return subEntity_; }
618 template<
class HostIndexSet >
619 typename HostIndexSet::IndexType
index (
const HostIndexSet &indexSet )
const
621 return indexSet.subIndex( hostElement(), subEntity_, codimension );
633 template<
class HostIndexSet >
634 typename HostIndexSet::IndexType
635 subIndex (
const HostIndexSet &indexSet,
int i,
unsigned int cd )
const
637 auto refElement = referenceElement< ctype, dimension >( hostElement().type() );
638 const int j = refElement.subEntity( subEntity_, codimension, i, codimension+cd );
639 return indexSet.subIndex( hostElement(), j, codimension+cd );
649 template<
class HostIndexSet >
652 return indexSet.contains( hostElement() );
662 template<
class HostIdSet >
663 typename HostIdSet::IdType
id (
const HostIdSet &idSet )
const
665 return idSet.subId( hostElement(), subEntity_, codimension );
673 const int j = refElement.subEntity( subEntity_, codimension, i, dimension );
674 return hostElement().template subEntity< dimension >( j ).partitionType();
678 HostElement hostElement_;
679 unsigned int subEntity_;
681 mutable GeometryImpl geo_;
689 template<
int codim,
int dim,
class Gr
id >
696 typedef typename Base::HostEntity HostEntity;
697 typedef typename Base::HostElement HostElement;
698 typedef typename Base::GeometryImpl GeometryImpl;
699 typedef typename Base::EntitySeed EntitySeed;
703 Entity (
const Grid &grid,
const EntitySeed &seed ) :
Base( grid, seed ) {}
705 Entity (
const Grid &grid,
const HostEntity &hostEntity ) :
Base( grid, hostEntity ) {}
706 Entity (
const Grid &grid, HostEntity&& hostEntity ) :
Base( grid, std::move( hostEntity ) ) {}
708 Entity (
const Grid &grid,
const HostElement &hostEntity,
int i ) :
Base( grid, hostEntity, i ) {}
717 template<
int dim,
class Gr
id >
723 typedef typename std::remove_const< Grid >::type::Traits Traits;
725 typedef typename Traits::HostGrid HostGrid;
732 static const int codimension = Base::codimension;
734 static const int dimension = Base::dimension;
736 static const int mydimension = Base::mydimension;
738 static const int dimensionworld = Base::dimensionworld;
741 static const bool fake = Base::fake;
753 typedef typename Traits::HierarchicIterator HierarchicIterator;
755 typedef typename Traits::LeafIntersectionIterator LeafIntersectionIterator;
757 typedef typename Traits::LevelIntersectionIterator LevelIntersectionIterator;
761 typedef typename Base::HostEntity HostEntity;
762 typedef typename Base::HostElement HostElement;
763 typedef typename Base::GeometryImpl GeometryImpl;
764 typedef typename Base::EntitySeed EntitySeed;
767 using Base::hostEntity;
771 Entity (
const Grid &g,
const HostEntity &hostE ) : Base( g, hostE ) {}
772 Entity (
const Grid &g, HostEntity&& hostE ) : Base( g,
std::move( hostE ) ) {}
773 Entity (
const GeometryImpl &geo,
const HostEntity& hostE ) : Base( geo, hostE ) {}
774 Entity (
const GeometryImpl &geo, HostEntity &&hostE ) : Base( geo,
std::move( hostE ) ) {}
776 Entity (
const Grid &g,
const EntitySeed &seed ) : Base( g, seed ) {}
778 Entity (
const Grid &g,
const HostEntity &hostE,
int i ) : Base( g, hostE )
783 template<
int codim >
784 typename Grid::template Codim< codim >::Entity
785 subEntity (
int i )
const
787 typedef typename Traits::template Codim< codim >::EntityImpl EntityImpl;
788 return EntityImpl( grid(), hostEntity(), i );
791 LevelIntersectionIterator ilevelbegin ()
const
793 typedef GeoGrid::IntersectionIterator< Grid, typename HostGrid::LevelIntersectionIterator > LevelIntersectionIteratorImpl;
794 return LevelIntersectionIteratorImpl( *
this, hostEntity().ilevelbegin() );
797 LevelIntersectionIterator ilevelend ()
const
799 typedef GeoGrid::IntersectionIterator< Grid, typename HostGrid::LevelIntersectionIterator > LevelIntersectionIteratorImpl;
800 return LevelIntersectionIteratorImpl( *
this, hostEntity().ilevelend() );
803 LeafIntersectionIterator ileafbegin ()
const
805 typedef GeoGrid::IntersectionIterator< Grid, typename HostGrid::LeafIntersectionIterator > LeafIntersectionIteratorImpl;
806 return LeafIntersectionIteratorImpl( *
this, hostEntity().ileafbegin() );
809 LeafIntersectionIterator ileafend ()
const
811 typedef GeoGrid::IntersectionIterator< Grid, typename HostGrid::LeafIntersectionIterator > LeafIntersectionIteratorImpl;
812 return LeafIntersectionIteratorImpl( *
this, hostEntity().ileafend() );
815 bool hasBoundaryIntersections ()
const
817 return hostEntity().hasBoundaryIntersections();
822 return hostEntity().isLeaf();
825 EntityFacade father ()
const
827 return Entity( grid(), hostEntity().father() );
830 bool hasFather ()
const
832 return hostEntity().hasFather();
835 LocalGeometry geometryInFather ()
const
837 return hostEntity().geometryInFather();
840 HierarchicIterator hbegin (
int maxLevel )
const
842 typedef GeoGrid::HierarchicIterator< Grid > HierarchicIteratorImpl;
843 return HierarchicIteratorImpl( grid(), hostEntity().hbegin( maxLevel ) );
846 HierarchicIterator hend (
int maxLevel )
const
848 typedef GeoGrid::HierarchicIterator< Grid > HierarchicIteratorImpl;
849 return HierarchicIteratorImpl( grid(), hostEntity().hend( maxLevel ) );
852 bool isRegular ()
const
854 return hostEntity().isRegular();
859 return hostEntity().isNew();
862 bool mightVanish ()
const
864 return hostEntity().mightVanish();
Store a reference to an entity with a minimal memory footprint.
Definition: entityseed.hh:24
EntitySeedImp Implementation
type of underlying implementation
Definition: entityseed.hh:35
Wrapper class for entities.
Definition: entity.hh:64
Base class for Dune-Exceptions.
Definition: exceptions.hh:94
GeometryType type() const
obtain the name of the corresponding reference element
Definition: entity.hh:218
bool equals(const EntityBase &other) const
compare two entities
Definition: entity.hh:205
Traits::ctype ctype
coordinate type of the grid
Definition: entity.hh:99
Geometry geometry() const
Definition: entity.hh:249
void initialize(const HostEntity &hostEntity)
initiliaze an entity
Definition: entity.hh:284
EntitySeed seed() const
return EntitySeed of host grid entity
Definition: entity.hh:265
HostIdSet::IdType id(const HostIdSet &idSet) const
obtain the entity's id from a host IdSet
Definition: entity.hh:337
Traits::template Codim< codimension >::Geometry Geometry
type of corresponding geometry
Definition: entity.hh:102
HostGrid::template Codim< codimension >::Entity HostEntity
type of corresponding host entity
Definition: entity.hh:114
Traits::template Codim< codimension >::EntitySeed EntitySeed
type of corresponding entity seed
Definition: entity.hh:117
HostIndexSet::IndexType index(const HostIndexSet &indexSet) const
obtain the entity's index from a host IndexSet
Definition: entity.hh:295
HostGrid::template Codim< 0 >::Entity HostElement
type of host elements, i.e., of host entities of codimension 0
Definition: entity.hh:120
PartitionType partitionType() const
obtain the partition type of this entity
Definition: entity.hh:230
int level() const
obtain the level of this entity
Definition: entity.hh:224
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:311
bool isContained(const HostIndexSet &indexSet) const
check whether the entity is contained in a host index set
Definition: entity.hh:324
int level() const
obtain the level of this entity
Definition: entity.hh:524
HostGrid::template Codim< 0 >::Entity HostElement
type of host elements, i.e., of host entities of codimension 0
Definition: entity.hh:408
PartitionType partitionType() const
obtain the partition type of this entity
Definition: entity.hh:530
bool equals(const EntityBase &other) const
compare two entities
Definition: entity.hh:486
HostIndexSet::IndexType index(const HostIndexSet &indexSet) const
obtain the entity's index from a host IndexSet
Definition: entity.hh:619
Traits::template Codim< codimension >::EntitySeed EntitySeed
type of corresponding entity seed
Definition: entity.hh:405
Traits::template Codim< codimension >::Geometry Geometry
type of corresponding geometry
Definition: entity.hh:390
HostIdSet::IdType id(const HostIdSet &idSet) const
obtain the entity's id from a host IdSet
Definition: entity.hh:663
EntitySeed seed() const
return EntitySeed of host grid entity
Definition: entity.hh:582
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:635
void initialize(const HostElement &hostElement)
initiliaze an entity
Definition: entity.hh:609
Geometry geometry() const
Definition: entity.hh:565
Traits::ctype ctype
coordinate type of the grid
Definition: entity.hh:387
bool isContained(const HostIndexSet &indexSet) const
check whether the entity is contained in a host index set
Definition: entity.hh:650
GeometryType type() const
obtain the name of the corresponding reference element
Definition: entity.hh:517
HostGrid::template Codim< codimension >::Entity HostEntity
type of corresponding host entity
Definition: entity.hh:402
actual implementation of the entity
Definition: entity.hh:32
DUNE-conform implementation of the entity.
Definition: entity.hh:692
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:123
Grid abstract base class.
Definition: grid.hh:372
Default exception for dummy implementations.
Definition: exceptions.hh:261
Different resources needed by all grid implementations.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
unspecified-type ReferenceElement
Returns the type of reference element for the argument types T...
Definition: referenceelements.hh:415
Dune namespace.
Definition: alignedallocator.hh:11
Static tag representing a codimension.
Definition: dimension.hh:22
Static tag representing a dimension.
Definition: dimension.hh:14