1 #ifndef DUNE_GEOGRID_ENTITY_HH
2 #define DUNE_GEOGRID_ENTITY_HH
4 #include <dune/common/nullptr.hh>
6 #include <dune/geometry/referenceelements.hh>
31 template< int codim, class Grid, bool fake = !(Capabilities::hasHostEntity< Grid, codim >::v) >
46 template<
int codim,
int dim,
class Gr
id >
54 template<
class Gr
id >
57 template<
class Gr
id >
60 template<
class Gr
id >
75 template<
int codim,
class Gr
id >
78 typedef typename remove_const< Grid >::type::Traits Traits;
85 static const int codimension = codim;
87 static const int dimension = Traits::dimension;
89 static const int mydimension = dimension - codimension;
91 static const int dimensionworld = Traits::dimensionworld;
94 static const bool fake =
false;
102 typedef typename Traits::ctype
ctype;
105 typedef typename Traits::template Codim< codimension >::Geometry
Geometry;
109 typedef typename Traits::HostGrid HostGrid;
110 typedef typename Traits::CoordFunction CoordFunction;
117 typedef typename HostGrid::template Codim< codimension >::Entity
HostEntity;
122 typedef typename Traits::template Codim< codimension >::EntitySeed
EntitySeed;
125 typedef typename HostGrid::template Codim< 0 >::Entity
HostElement;
128 typedef typename Traits::template Codim< codim >::GeometryImpl
GeometryImpl;
131 typedef typename HostGrid::template Codim< codimension >::Geometry HostGeometry;
147 hostEntity_( nullptr )
158 hostEntity_( nullptr )
162 : geo_( other.geo_ ),
163 hostEntity_( nullptr )
171 hostEntity_ =
nullptr;
175 operator bool ()
const {
return bool( hostEntity_ ); }
187 return hostEntity().type();
190 unsigned int topologyId () const DUNE_DEPRECATED
198 return hostEntity().level();
204 return hostEntity().partitionType();
225 CoordVector coords( hostEntity(), grid().coordFunction() );
263 template<
class HostIndexSet >
264 typename HostIndexSet::IndexType
265 index (
const HostIndexSet &indexSet )
const
267 return indexSet.template index< codimension >( hostEntity() );
279 template<
class HostIndexSet >
280 typename HostIndexSet::IndexType
281 subIndex (
const HostIndexSet &indexSet,
int i,
unsigned int cd )
const
283 return indexSet.subIndex( hostEntity(), i, cd );
293 template<
class HostIndexSet >
294 bool isContained (
const HostIndexSet &indexSet )
const
296 return indexSet.contains( hostEntity() );
306 template<
class HostIdSet >
307 typename HostIdSet::IdType id (
const HostIdSet &idSet )
const
309 return idSet.template id< codimension >( hostEntity() );
314 mutable GeometryImpl geo_;
315 const HostEntity *hostEntity_;
330 template<
int codim,
class Gr
id >
333 typedef typename remove_const< Grid >::type::Traits Traits;
340 static const int codimension = codim;
342 static const int dimension = Traits::dimension;
344 static const int mydimension = dimension - codimension;
346 static const int dimensionworld = Traits::dimensionworld;
349 static const bool fake =
true;
356 typedef typename Traits::ctype
ctype;
359 typedef typename Traits::template Codim< codimension >::Geometry
Geometry;
363 typedef typename Traits::HostGrid HostGrid;
364 typedef typename Traits::CoordFunction CoordFunction;
371 typedef typename HostGrid::template Codim< codimension >::Entity
HostEntity;
376 typedef typename Traits::template Codim< codimension >::EntitySeed
EntitySeed;
379 typedef typename HostGrid::template Codim< 0 >::Entity
HostElement;
382 typedef typename Traits::template Codim< codimension >::GeometryImpl
GeometryImpl;
385 typedef typename HostGrid::template Codim< 0 >::Geometry HostGeometry;
386 typedef typename HostGrid::template Codim< dimension >::EntityPointer HostVertexPointer;
403 hostElement_( nullptr ),
404 subEntity_( subEntity )
416 hostElement_( nullptr ),
417 subEntity_( subEntity )
421 : geo_( other.geo_ ),
422 hostElement_( nullptr ),
423 subEntity_( other.subEntity_ )
431 hostElement_ =
nullptr;
432 subEntity_ = other.subEntity_;
436 operator bool ()
const {
return bool( hostElement_ ); }
447 const GenericReferenceElement< ctype, dimension > &refElement
448 = GenericReferenceElements< ctype, dimension >::general( hostElement().type() );
449 return refElement.type( subEntity_, codimension );
452 unsigned int topologyId () const DUNE_DEPRECATED
454 const GenericReferenceElement< ctype, dimension > &refElement
455 = GenericReferenceElements< ctype, dimension >::general( hostElement().type() );
456 return refElement.topologyId( subEntity_, codimension );
462 return hostElement().level();
471 const GenericReferenceElement< ctype, dimension > &refElement
472 = GenericReferenceElements< ctype, dimension >::general( hostElement().type() );
478 const int numVertices = refElement.size( subEntity_, codimension, dimension );
479 for(
int i = 1; i < numVertices; ++i )
481 PartitionType vtxType = vertexPartitionType( refElement, i );
484 if( type != vtxType )
509 CoordVector coords( hostElement(), subEntity_, grid().coordFunction() );
526 DUNE_THROW( NotImplemented,
"HostGrid has no entities of codimension " << codimension <<
"." );
532 return *hostElement_;
553 template<
class HostIndexSet >
554 typename HostIndexSet::IndexType index (
const HostIndexSet &indexSet )
const
556 return indexSet.subIndex( hostElement(), subEntity_, codimension );
568 template<
class HostIndexSet >
569 typename HostIndexSet::IndexType
570 subIndex (
const HostIndexSet &indexSet,
int i,
unsigned int cd )
const
572 const GenericReferenceElement< ctype, dimension > &refElement
573 = GenericReferenceElements< ctype, dimension >::general( hostElement().type() );
574 const int j = refElement.subEntity( subEntity_, codimension, i, codimension+cd );
575 return indexSet.subIndex( hostElement(), j, codimension+cd );
585 template<
class HostIndexSet >
586 bool isContained (
const HostIndexSet &indexSet )
const
588 return indexSet.contains( hostElement() );
598 template<
class HostIdSet >
599 typename HostIdSet::IdType id (
const HostIdSet &idSet )
const
601 return idSet.subId( hostElement(), subEntity_, codimension );
607 vertexPartitionType (
const GenericReferenceElement< ctype, dimension > &refElement,
int i )
const
609 const int j = refElement.subEntity( subEntity_, codimension, 0, dimension );
610 return hostElement().template subEntity< dimension >( j )->partitionType();
614 mutable GeometryImpl geo_;
615 const HostElement *hostElement_;
616 unsigned int subEntity_;
624 template<
int codim,
int dim,
class Gr
id >
626 :
public EntityBase< codim, Grid >
628 typedef EntityBase< codim, Grid > Base;
644 :
Base( grid, subEntity )
648 :
Base( geo, subEntity )
657 template<
int dim,
class Gr
id >
663 typedef typename remove_const< Grid >::type::Traits Traits;
670 static const int codimension = Base::codimension;
672 static const int dimension = Base::dimension;
674 static const int mydimension = Base::mydimension;
676 static const int dimensionworld = Base::dimensionworld;
679 static const bool fake = Base::fake;
686 typedef typename Traits::template Codim< codimension >::LocalGeometry
LocalGeometry;
688 typedef typename Traits::template Codim< codimension >::EntityPointer
EntityPointer;
704 using Base::hostEntity;
714 template<
int codim >
717 return hostEntity().template count< codim >();
720 template<
int codim >
721 typename Grid::template Codim< codim >::EntityPointer
722 subEntity (
int i )
const
724 typedef typename Traits::template Codim< codim >::EntityPointerImpl EntityPointerImpl;
725 return EntityPointerImpl( grid(), hostEntity(), i );
731 return LevelIntersectionIteratorImpl( *
this, hostEntity().ilevelbegin() );
737 return LevelIntersectionIteratorImpl( *
this, hostEntity().ilevelend() );
743 return LeafIntersectionIteratorImpl( *
this, hostEntity().ileafbegin() );
749 return LeafIntersectionIteratorImpl( *
this, hostEntity().ileafend() );
752 bool hasBoundaryIntersections ()
const
754 return hostEntity().hasBoundaryIntersections();
759 return hostEntity().isLeaf();
764 typedef typename Traits::template Codim< 0 >::EntityPointerImpl EntityPointerImpl;
765 return EntityPointerImpl( grid(), hostEntity().father() );
768 bool hasFather ()
const
770 return hostEntity().hasFather();
775 return hostEntity().geometryInFather();
781 return HierarchicIteratorImpl( grid(), hostEntity().hbegin( maxLevel ) );
787 return HierarchicIteratorImpl( grid(), hostEntity().hend( maxLevel ) );
790 bool isRegular ()
const
792 return hostEntity().isRegular();
797 return hostEntity().isNew();
800 bool mightVanish ()
const
802 return hostEntity().mightVanish();
810 #endif // #ifndef DUNE_GEOGRID_ENTITY_HH