dune-grid  2.3.1-rc1
geometrygrid/entitypointer.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_GEOGRID_ENTITYPOINTER_HH
4 #define DUNE_GEOGRID_ENTITYPOINTER_HH
5 
7 
11 
12 namespace Dune
13 {
14 
15  namespace GeoGrid
16  {
17 
18  // External Forward Declarations
19  // -----------------------------
20 
21  template< int, int, class >
22  class Entity;
23 
24  template< class, class >
25  class ExportParams;
26 
27 
28 
29 
30  // Internal Forward Declarations
31  // -----------------------------
32 
33  template< int codim, class Grid >
35 
36  template< class Traits, bool fake = Traits::fake >
38 
39 
40 
41  // EntityPointerTraits
42  // -------------------
43 
44  template< int codim, class Grid >
45  struct EntityPointerTraits;
46 
48  template< int codim, class Grid >
49  struct EntityPointerTraits< codim, const Grid >
50  : public EntityPointerTraits< codim, Grid >
51  {};
54  template< int codim, class HostGrid, class CoordFunction, class Allocator >
55  struct EntityPointerTraits< codim, GeometryGrid< HostGrid, CoordFunction, Allocator > >
56  : public ExportParams< HostGrid, CoordFunction >
57  {
59 
61 
62  typedef typename HostGrid::ctype ctype;
63 
64  static const int dimension = HostGrid::dimension;
65  static const int codimension = codim;
66 
69 
70  typedef typename HostGrid::template Codim< codim >::Entity HostEntity;
71  typedef typename HostGrid::template Codim< codim >::EntityPointer HostEntityPointer;
73 
74  typedef typename HostGrid::template Codim< 0 >::Entity HostElement;
75  typedef typename HostGrid::template Codim< 0 >::EntityPointer HostElementIterator;
76  };
77 
78 
79 
80  // EntityPointer (real)
81  // --------------------
82 
83  template< class Traits >
84  class EntityPointer< Traits, false >
85  {
87 
88  typedef typename Traits::Grid Grid;
89 
91  friend class EntityPointer< BaseTraits, false >;
92 
93  public:
94  static const int dimension = Traits::dimension;
95  static const int codimension = Traits::codimension;
96 
97  typedef typename Traits::Entity Entity;
98 
99  static const bool fake = Traits::fake;
100 
102 
103  protected:
104  typedef typename Traits::HostEntityPointer HostEntityPointer;
105  typedef typename Traits::HostEntityIterator HostEntityIterator;
106  typedef typename Traits::HostElement HostElement;
107 
108  typedef typename Traits::EntitySeed EntitySeed;
109 
112 
113  public:
114  EntityPointer ( const GeometryImpl &geo, const HostEntityIterator &hostEntityIterator )
115  : entity_( EntityImpl( geo ) ),
116  hostEntityIterator_( hostEntityIterator )
117  {}
118 
119  EntityPointer ( const Grid &grid, const HostEntityIterator &hostEntityIterator )
120  : entity_( EntityImpl( grid ) ),
121  hostEntityIterator_( hostEntityIterator )
122  {}
123 
124  EntityPointer ( const Grid &grid, const HostElement &hostElement, int subEntity )
125  : entity_( EntityImpl( grid ) ),
126  hostEntityIterator_( hostElement.template subEntity< codimension >( subEntity ) )
127  {}
128 
129  EntityPointer ( const Grid &grid, const EntitySeed &seed )
130  : entity_( EntityImpl( grid ) ),
131  hostEntityIterator_( grid.hostGrid().entityPointer( grid.getRealImplementation(seed).hostEntitySeed() ) )
132  {}
133 
134  explicit EntityPointer ( const EntityImpl &entity )
135  : entity_( entity ),
136  hostEntityIterator_( entity.hostEntity() )
137  {}
138 
139  EntityPointer ( const This &other )
140  : entity_( other.entityImpl() ),
141  hostEntityIterator_( other.hostEntityIterator_ )
142  {}
143 
144  template< class T >
145  explicit EntityPointer ( const EntityPointer< T, fake > &other )
146  : entity_( other.entityImpl() ),
147  hostEntityIterator_( other.hostEntityIterator_ )
148  {}
149 
150  const This &operator= ( const This &other )
151  {
152  entityImpl() = other.entityImpl();
153  hostEntityIterator_ = other.hostEntityIterator_;
154  return *this;
155  }
156 
157  template< class T >
158  const This &operator= ( const EntityPointer< T, fake > &other )
159  {
160  entityImpl() = other.entityImpl();
161  hostEntityIterator_ = other.hostEntityIterator_;
162  return *this;
163  }
164 
165  template< class T >
166  bool equals ( const EntityPointer< T, fake > &other ) const
167  {
168  return (hostIterator() == other.hostIterator());
169  }
170 
171  Entity &dereference () const
172  {
173  if( !entityImpl() )
174  entityImpl().initialize( *hostIterator() );
175  return entity_;
176  }
177 
178  int level () const { return hostIterator().level(); }
179 
180  const HostEntityIterator &hostIterator() const { return hostEntityIterator_; }
181 
182  const Grid &grid () const { return entityImpl().grid(); }
183 
184  protected:
186  {
187  return Grid::getRealImplementation( entity_ );
188  }
189 
190  private:
191  mutable Entity entity_;
192 
193  protected:
195  };
196 
197 
198 
199  // EntityPointer (fake)
200  // --------------------
201 
202  template< class Traits >
203  class EntityPointer< Traits, true >
204  {
206 
207  typedef typename Traits::Grid Grid;
208 
210  friend class EntityPointer< BaseTraits, true >;
211 
212  public:
213  static const int dimension = Traits::dimension;
214  static const int codimension = Traits::codimension;
215 
216  typedef typename Traits::Entity Entity;
217 
218  static const bool fake = Traits::fake;
219 
221 
222  protected:
223  typedef typename Traits::HostEntityPointer HostEntityPointer;
224  typedef typename Traits::HostElementIterator HostElementIterator;
225  typedef typename Traits::HostElement HostElement;
226 
227  typedef typename Traits::EntitySeed EntitySeed;
228 
231 
232  public:
233  EntityPointer ( const GeometryImpl &geo, const HostElementIterator &hostElementIterator, int subEntity )
234  : entity_( EntityImpl( geo, subEntity ) ),
235  hostElementIterator_( hostElementIterator )
236  {}
237 
238  EntityPointer ( const Grid &grid, const HostElementIterator &hostElementIterator, int subEntity )
239  : entity_( EntityImpl( grid, subEntity ) ),
240  hostElementIterator_( hostElementIterator )
241  {}
242 
243  EntityPointer ( const Grid &grid, const HostElement &hostElement, int subEntity )
244  : entity_( EntityImpl( grid, subEntity ) ),
245  hostElementIterator_( hostElement )
246  {}
247 
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() ) )
251  {}
252 
253  explicit EntityPointer ( const EntityImpl &entity )
254  : entity_( entity ),
255  hostElementIterator_( entity.hostElement() )
256  {}
257 
258  EntityPointer ( const This &other )
259  : entity_( other.entityImpl() ),
260  hostElementIterator_( other.hostElementIterator_ )
261  {}
262 
263  template< class T >
264  explicit EntityPointer ( const EntityPointer< T, fake > &other )
265  : entity_( other.entityImpl() ),
266  hostElementIterator_( other.hostElementIterator_ )
267  {}
268 
269  const This &operator= ( const This &other )
270  {
271  entityImpl() = other.entityImpl();
272  hostElementIterator_ = other.hostElementIterator_;
273  return *this;
274  }
275 
276  template< class T >
277  const This &operator= ( const EntityPointer< T, fake > &other )
278  {
279  entityImpl() = other.entityImpl();
280  hostElementIterator_ = other.hostElementIterator_;
281  return *this;
282  }
283 
284  template< class T >
285  bool equals ( const EntityPointer< T, fake > &other ) const
286  {
287  const bool thisEnd = (subEntity() < 0);
288  const bool otherEnd = (other.subEntity() < 0);
289  if( thisEnd || otherEnd )
290  return thisEnd && otherEnd;
291 
292  const int lvl = level();
293  if( lvl != other.level() )
294  return false;
295 
296  const typename Traits::HostGrid::Traits::LevelIndexSet &indexSet
297  = grid().hostGrid().levelIndexSet( lvl );
298 
299  const HostElement &thisElement = *hostElementIterator();
300  assert( indexSet.contains( thisElement ) );
301  const HostElement &otherElement = *(other.hostElementIterator());
302  assert( indexSet.contains( otherElement ) );
303 
304  const int thisIndex = indexSet.subIndex( thisElement, subEntity(), codimension );
305  const int otherIndex = indexSet.subIndex( otherElement, other.subEntity(), codimension );
306  return (thisIndex == otherIndex);
307  }
308 
309  Entity &dereference () const
310  {
311  if( !entityImpl() )
312  entityImpl().initialize( *hostElementIterator() );
313  return entity_;
314  }
315 
316  int level () const { return hostElementIterator().level(); }
317 
318  const Grid &grid () const { return entityImpl().grid(); }
319  int subEntity () const { return entityImpl().subEntity(); }
320 
321  protected:
323  {
324  return Grid::getRealImplementation( entity_ );
325  }
326 
328  {
329  return hostElementIterator_;
330  }
331 
332  private:
333  mutable Entity entity_;
334 
335  protected:
337  };
338 
339  } // namespace GeoGrid
340 
341 } // namespace Dune
342 
343 #endif // #ifndef DUNE_GEOGRID_ENTITYPOINTER_HH
Base::GeometryImpl GeometryImpl
Definition: geometrygrid/entity.hh:620
CF CoordFunction
Definition: geometrygrid/gridfamily.hh:42
Traits::EntitySeed EntitySeed
Definition: geometrygrid/entitypointer.hh:108
EntityPointer(const Grid &grid, const EntitySeed &seed)
Definition: geometrygrid/entitypointer.hh:129
HostEntityIterator hostEntityIterator_
Definition: geometrygrid/entitypointer.hh:194
GeoGrid::Entity< codimension, dimension, const Grid > EntityImpl
Definition: geometrygrid/entitypointer.hh:110
Wrapper class for entities.
Definition: common/entity.hh:56
EntityPointer(const This &other)
Definition: geometrygrid/entitypointer.hh:139
EntityPointer(const GeometryImpl &geo, const HostEntityIterator &hostEntityIterator)
Definition: geometrygrid/entitypointer.hh:114
EntityPointer< BaseTraits, fake > EntityPointerImp
Definition: geometrygrid/entitypointer.hh:101
EntityPointer(const This &other)
Definition: geometrygrid/entitypointer.hh:258
HostGrid::template Codim< 0 >::EntityPointer HostElementIterator
Definition: geometrygrid/entitypointer.hh:75
Definition: geometrygrid/entitypointer.hh:84
EntityPointer(const EntityImpl &entity)
Definition: geometrygrid/entitypointer.hh:253
HostGrid::template Codim< codim >::EntityPointer HostEntityPointer
Definition: geometrygrid/entitypointer.hh:71
Dune::GeometryGrid< HostGrid, CoordFunction, Allocator > Grid
Definition: geometrygrid/entitypointer.hh:58
HostGrid::template Codim< codim >::Entity HostEntity
Definition: geometrygrid/entitypointer.hh:70
DUNE-conform implementation of the entityThis class merely changes the template parameters of the ent...
Definition: geometrygrid/entity.hh:49
EntityImpl::GeometryImpl GeometryImpl
Definition: geometrygrid/entitypointer.hh:111
Traits::HostElement HostElement
Definition: geometrygrid/entitypointer.hh:225
HostGrid::template Codim< 0 >::Entity HostElement
Definition: geometrygrid/entitypointer.hh:74
EntityPointer(const Grid &grid, const EntitySeed &seed)
Definition: geometrygrid/entitypointer.hh:248
Dune::EntitySeed< const Grid, GeoGrid::EntitySeed< codimension, const Grid > > EntitySeed
Definition: geometrygrid/entitypointer.hh:68
EntityPointer(const GeometryImpl &geo, const HostElementIterator &hostElementIterator, int subEntity)
Definition: geometrygrid/entitypointer.hh:233
Definition: geometrygrid/entitypointer.hh:37
Entity & dereference() const
Definition: geometrygrid/entitypointer.hh:171
EntityPointer(const Grid &grid, const HostElement &hostElement, int subEntity)
Definition: geometrygrid/entitypointer.hh:124
EntityPointer(const Grid &grid, const HostEntityIterator &hostEntityIterator)
Definition: geometrygrid/entitypointer.hh:119
EntityImpl & entityImpl() const
Definition: geometrygrid/entitypointer.hh:322
Traits::EntitySeed EntitySeed
Definition: geometrygrid/entitypointer.hh:227
HG HostGrid
Definition: geometrygrid/gridfamily.hh:41
Traits::Entity Entity
Definition: geometrygrid/entitypointer.hh:97
Traits::HostEntityIterator HostEntityIterator
Definition: geometrygrid/entitypointer.hh:105
Traits::HostEntityPointer HostEntityPointer
Definition: geometrygrid/entitypointer.hh:223
Grid abstract base classThis class is the base class for all grid implementations. Although no virtual functions are used we call it abstract since its methods do not contain an implementation but forward to the methods of the derived class via the Barton-Nackman trick.
Definition: common/grid.hh:386
int level() const
Definition: geometrygrid/entitypointer.hh:316
EntityPointer< BaseTraits, fake > EntityPointerImp
Definition: geometrygrid/entitypointer.hh:220
EntityPointer(const EntityImpl &entity)
Definition: geometrygrid/entitypointer.hh:134
Definition: geometrygrid/entitypointer.hh:34
Entity & dereference() const
Definition: geometrygrid/entitypointer.hh:309
HostElementIterator hostElementIterator_
Definition: geometrygrid/entitypointer.hh:336
EntityImpl & entityImpl() const
Definition: geometrygrid/entitypointer.hh:185
bool equals(const EntityPointer< T, fake > &other) const
Definition: geometrygrid/entitypointer.hh:285
bool equals(const EntityPointer< T, fake > &other) const
Definition: geometrygrid/entitypointer.hh:166
Store a reference to an entity with a minimal memory footprint.
Definition: common/entityseed.hh:23
EntityPointer(const EntityPointer< T, fake > &other)
Definition: geometrygrid/entitypointer.hh:145
EntityPointer(const EntityPointer< T, fake > &other)
Definition: geometrygrid/entitypointer.hh:264
int level() const
Definition: geometrygrid/entitypointer.hh:178
const HostEntityIterator & hostIterator() const
Definition: geometrygrid/entitypointer.hh:180
GeoGrid::Entity< codimension, dimension, const Grid > EntityImpl
Definition: geometrygrid/entitypointer.hh:229
Definition: geometrygrid/capabilities.hh:91
Different resources needed by all grid implementations.
Definition: geometrygrid/entitypointer.hh:25
EntityPointer(const Grid &grid, const HostElement &hostElement, int subEntity)
Definition: geometrygrid/entitypointer.hh:243
HostEntityPointer HostEntityIterator
Definition: geometrygrid/entitypointer.hh:72
Traits::HostElement HostElement
Definition: geometrygrid/entitypointer.hh:106
const Grid & grid() const
Definition: geometrygrid/entitypointer.hh:318
Definition: geometrygrid/entitypointer.hh:203
EntityPointer(const Grid &grid, const HostElementIterator &hostElementIterator, int subEntity)
Definition: geometrygrid/entitypointer.hh:238
int subEntity() const
Definition: geometrygrid/entitypointer.hh:319
EntityImpl::GeometryImpl GeometryImpl
Definition: geometrygrid/entitypointer.hh:230
grid wrapper replacing the geometriesGeometryGrid wraps another DUNE grid and replaces its geometry b...
Definition: geometrygrid/declaration.hh:10
Dune::Entity< codimension, dimension, const Grid, GeoGrid::Entity > Entity
Definition: geometrygrid/entitypointer.hh:67
Traits::HostEntityPointer HostEntityPointer
Definition: geometrygrid/entitypointer.hh:104
const HostElementIterator & hostElementIterator() const
Definition: geometrygrid/entitypointer.hh:327
Traits::Entity Entity
Definition: geometrygrid/entitypointer.hh:216
Traits::HostElementIterator HostElementIterator
Definition: geometrygrid/entitypointer.hh:224
const Grid & grid() const
Definition: geometrygrid/entitypointer.hh:182