3#ifndef DUNE_GEOGRID_ENTITYPOINTER_HH
4#define DUNE_GEOGRID_ENTITYPOINTER_HH
8#include <dune/grid/geometrygrid/declaration.hh>
9#include <dune/grid/geometrygrid/capabilities.hh>
10#include <dune/grid/geometrygrid/entityseed.hh>
21 template<
int,
int,
class >
24 template<
class,
class >
33 template<
int codim,
class Gr
id >
34 struct EntityPointerTraits;
36 template<
class Traits,
bool fake = Traits::fake >
44 template<
int codim,
class Gr
id >
45 struct EntityPointerTraits;
48 template<
int codim,
class Gr
id >
49 struct EntityPointerTraits< codim, const Grid >
50 :
public EntityPointerTraits< codim, Grid >
54 template<
int codim,
class HostGr
id,
class CoordFunction,
class Allocator >
55 struct EntityPointerTraits< codim, GeometryGrid< HostGrid, CoordFunction, Allocator > >
56 :
public ExportParams< HostGrid, CoordFunction >
60 static const bool fake = !Capabilities::hasHostEntity< Grid, codim >::v;
62 typedef typename HostGrid::ctype ctype;
64 static const int dimension = HostGrid::dimension;
65 static const int codimension = codim;
70 typedef typename HostGrid::template Codim< codim >::Entity HostEntity;
71 typedef typename HostGrid::template Codim< codim >::EntityPointer HostEntityPointer;
72 typedef HostEntityPointer HostEntityIterator;
74 typedef typename HostGrid::template Codim< 0 >::Entity HostElement;
75 typedef typename HostGrid::template Codim< 0 >::EntityPointer HostElementIterator;
83 template<
class Traits >
84 class EntityPointer< Traits, false >
86 typedef EntityPointer< Traits, false > This;
88 typedef typename Traits::Grid Grid;
90 typedef EntityPointerTraits< Traits::codimension, const Grid > BaseTraits;
91 friend class EntityPointer< BaseTraits, false >;
94 static const int dimension = Traits::dimension;
95 static const int codimension = Traits::codimension;
97 typedef typename Traits::Entity Entity;
99 static const bool fake = Traits::fake;
101 typedef EntityPointer< BaseTraits, fake > EntityPointerImp;
104 typedef typename Traits::HostEntityPointer HostEntityPointer;
105 typedef typename Traits::HostEntityIterator HostEntityIterator;
106 typedef typename Traits::HostElement HostElement;
108 typedef typename Traits::EntitySeed EntitySeed;
110 typedef GeoGrid::Entity< codimension, dimension, const Grid > EntityImpl;
111 typedef typename EntityImpl::GeometryImpl GeometryImpl;
114 EntityPointer (
const GeometryImpl &geo,
const HostEntityIterator &hostEntityIterator )
115 : entity_( EntityImpl( geo ) ),
116 hostEntityIterator_( hostEntityIterator )
119 EntityPointer (
const Grid &grid,
const HostEntityIterator &hostEntityIterator )
120 : entity_( EntityImpl( grid ) ),
121 hostEntityIterator_( hostEntityIterator )
124 EntityPointer (
const Grid &grid,
const HostElement &hostElement,
int subEntity )
125 : entity_( EntityImpl( grid ) ),
126 hostEntityIterator_( hostElement.template subEntity< codimension >( subEntity ) )
129 EntityPointer (
const Grid &grid,
const EntitySeed &seed )
130 : entity_( EntityImpl( grid ) ),
131 hostEntityIterator_( grid.hostGrid().entityPointer( grid.getRealImplementation(seed).hostEntitySeed() ) )
134 explicit EntityPointer (
const EntityImpl &entity )
136 hostEntityIterator_( entity.hostEntity() )
139 EntityPointer (
const This &other )
140 : entity_( other.entityImpl() ),
141 hostEntityIterator_( other.hostEntityIterator_ )
145 explicit EntityPointer (
const EntityPointer< T, fake > &other )
146 : entity_( other.entityImpl() ),
147 hostEntityIterator_( other.hostEntityIterator_ )
150 const This &operator= (
const This &other )
152 entityImpl() = other.entityImpl();
153 hostEntityIterator_ = other.hostEntityIterator_;
158 const This &operator= (
const EntityPointer< T, fake > &other )
160 entityImpl() = other.entityImpl();
161 hostEntityIterator_ = other.hostEntityIterator_;
166 bool equals (
const EntityPointer< T, fake > &other )
const
168 return (hostIterator() == other.hostIterator());
171 Entity &dereference ()
const
174 entityImpl().initialize( *hostIterator() );
178 int level ()
const {
return hostIterator().level(); }
180 const HostEntityIterator &hostIterator()
const {
return hostEntityIterator_; }
182 const Grid &grid ()
const {
return entityImpl().grid(); }
185 EntityImpl &entityImpl ()
const
187 return Grid::getRealImplementation( entity_ );
191 mutable Entity entity_;
194 HostEntityIterator hostEntityIterator_;
202 template<
class Traits >
203 class EntityPointer< Traits, true >
205 typedef EntityPointer< Traits, true > This;
207 typedef typename Traits::Grid Grid;
209 typedef EntityPointerTraits< Traits::codimension, const Grid > BaseTraits;
210 friend class EntityPointer< BaseTraits, true >;
213 static const int dimension = Traits::dimension;
214 static const int codimension = Traits::codimension;
216 typedef typename Traits::Entity Entity;
218 static const bool fake = Traits::fake;
220 typedef EntityPointer< BaseTraits, fake > EntityPointerImp;
223 typedef typename Traits::HostEntityPointer HostEntityPointer;
224 typedef typename Traits::HostElementIterator HostElementIterator;
225 typedef typename Traits::HostElement HostElement;
227 typedef typename Traits::EntitySeed EntitySeed;
229 typedef GeoGrid::Entity< codimension, dimension, const Grid > EntityImpl;
230 typedef typename EntityImpl::GeometryImpl GeometryImpl;
233 EntityPointer (
const GeometryImpl &geo,
const HostElementIterator &hostElementIterator,
int subEntity )
234 : entity_( EntityImpl( geo, subEntity ) ),
235 hostElementIterator_( hostElementIterator )
238 EntityPointer (
const Grid &grid,
const HostElementIterator &hostElementIterator,
int subEntity )
239 : entity_( EntityImpl( grid, subEntity ) ),
240 hostElementIterator_( hostElementIterator )
243 EntityPointer (
const Grid &grid,
const HostElement &hostElement,
int subEntity )
244 : entity_( EntityImpl( grid, subEntity ) ),
245 hostElementIterator_( hostElement )
248 EntityPointer (
const Grid &grid,
const EntitySeed &seed )
249 : entity_( EntityImpl( grid, grid.getRealImplementation(seed).subEntity() ) ),
250 hostElementIterator_( grid.hostGrid().entityPointer( grid.getRealImplementation(seed).hostElementSeed() ) )
253 explicit EntityPointer (
const EntityImpl &entity )
255 hostElementIterator_( entity.hostElement() )
258 EntityPointer (
const This &other )
259 : entity_( other.entityImpl() ),
260 hostElementIterator_( other.hostElementIterator_ )
264 explicit EntityPointer (
const EntityPointer< T, fake > &other )
265 : entity_( other.entityImpl() ),
266 hostElementIterator_( other.hostElementIterator_ )
269 const This &operator= (
const This &other )
271 entityImpl() = other.entityImpl();
272 hostElementIterator_ = other.hostElementIterator_;
277 const This &operator= (
const EntityPointer< T, fake > &other )
279 entityImpl() = other.entityImpl();
280 hostElementIterator_ = other.hostElementIterator_;
285 bool equals (
const EntityPointer< T, fake > &other )
const
287 const bool thisEnd = (subEntity() < 0);
288 const bool otherEnd = (other.subEntity() < 0);
289 if( thisEnd || otherEnd )
290 return thisEnd && otherEnd;
292 const int lvl = level();
293 if( lvl != other.level() )
296 const typename Traits::HostGrid::Traits::LevelIndexSet &indexSet
297 = grid().hostGrid().levelIndexSet( lvl );
299 const HostElement &thisElement = *hostElementIterator();
300 assert( indexSet.contains( thisElement ) );
301 const HostElement &otherElement = *(other.hostElementIterator());
302 assert( indexSet.contains( otherElement ) );
304 const int thisIndex = indexSet.subIndex( thisElement, subEntity(), codimension );
305 const int otherIndex = indexSet.subIndex( otherElement, other.subEntity(), codimension );
306 return (thisIndex == otherIndex);
309 Entity &dereference ()
const
312 entityImpl().initialize( *hostElementIterator() );
316 int level ()
const {
return hostElementIterator().level(); }
318 const Grid &grid ()
const {
return entityImpl().grid(); }
319 int subEntity ()
const {
return entityImpl().subEntity(); }
322 EntityImpl &entityImpl ()
const
324 return Grid::getRealImplementation( entity_ );
327 const HostElementIterator &hostElementIterator ()
const
329 return hostElementIterator_;
333 mutable Entity entity_;
336 HostElementIterator hostElementIterator_;
Store a reference to an entity with a minimal memory footprint.
Definition: entityseed.hh:24
Wrapper class for entities.
Definition: entity.hh:57
grid wrapper replacing the geometries
Definition: grid.hh:83
Different resources needed by all grid implementations.
Dune namespace.
Definition: alignment.hh:14