dune-grid-dev-howto  2.2.1
identitygridentity.hh
Go to the documentation of this file.
1 #ifndef DUNE_IDENTITYGRIDENTITY_HH
2 #define DUNE_IDENTITYGRIDENTITY_HH
3 
8 #include <dune/grid/common/grid.hh>
9 
10 namespace Dune {
11 
12 
13 // Forward declarations
14 
15 template<int codim, int dim, class GridImp>
16 class IdentityGridEntity;
17 
18 template<int codim, class GridImp>
20 
21 template<int codim, PartitionIteratorType pitype, class GridImp>
23 
24 template<class GridImp>
26 
27 template<class GridImp>
29 
30 template<class GridImp>
32 
33 
34 // External forward declarations
35 template< class Grid >
36 struct HostGridAccess;
37 
38 
39 
40 template<int codim, int dim, class GridImp>
42  public GridImp::template Codim<codim>::Entity
43 {
44  public:
45 
46  // The codimension of this entitypointer wrt the host grid
47  enum {CodimInHostGrid = GridImp::HostGridType::dimension - GridImp::dimension + codim};
48 
49  // EntityPointer to the equivalent entity in the host grid
50  typedef typename GridImp::HostGridType::Traits::template Codim<CodimInHostGrid>::EntityPointer HostGridEntityPointer;
51 
52 
54  template< class HostGridEntityPointer >
55  IdentityGridMakeableEntity(const GridImp* identityGrid, const HostGridEntityPointer& hostEntity) :
56  GridImp::template Codim<codim>::Entity (IdentityGridEntity<codim, dim, const GridImp>(identityGrid,hostEntity)),
57  identityGrid_(identityGrid)
58  {}
59 
60 
62  template< class HostGridEntityPointer >
63  void setToTarget(const HostGridEntityPointer& hostEntity) {
64  this->realEntity.setToTarget(hostEntity);
65  }
66 
67 
70  return this->realEntity.hostEntity_;
71  }
72 
73 
74  private:
75 
76  const GridImp* identityGrid_;
77 };
78 
79 
80 //**********************************************************************
81 //
82 // --IdentityGridEntity
83 // --Entity
84 //
92 template<int codim, int dim, class GridImp>
94  public EntityDefaultImplementation <codim,dim,GridImp,IdentityGridEntity>
95 {
96  friend class IdentityGridMakeableEntity<codim,dim,GridImp>;
97 
98  template <class GridImp_>
100 
101  template <class GridImp_>
103 
104  template <class GridImp_>
106 
107  template <class GridImp_>
109 
110  friend class IdentityGridEntityPointer<codim,GridImp>;
111 
112  friend struct HostGridAccess< typename remove_const< GridImp >::type >;
113 
114 
115  private:
116 
117  typedef typename GridImp::ctype ctype;
118 
119  // The codimension of this entitypointer wrt the host grid
120  enum {CodimInHostGrid = GridImp::HostGridType::dimension - GridImp::dimension + codim};
121 
122  // EntityPointer to the equivalent entity in the host grid
123  typedef typename GridImp::HostGridType::Traits::template Codim<CodimInHostGrid>::EntityPointer HostGridEntityPointer;
124 
125 
126  public:
127 
128  typedef typename GridImp::template Codim<codim>::Geometry Geometry;
129 
131  typedef typename GridImp::template Codim<codim>::EntitySeed EntitySeed;
132 
134  template< class HostGridEntityPointer >
135  IdentityGridEntity(const GridImp* identityGrid, const HostGridEntityPointer& hostEntity) :
136  hostEntity_(hostEntity),
137  identityGrid_(identityGrid)
138  {}
139 
140 
143  hostEntity_(original.hostEntity_),
144  identityGrid_(original.identityGrid_)
145  {}
146 
147 
150  {
151  if (this != &original)
152  {
153  identityGrid_ = original.identityGrid_;
154  hostEntity_ = original.hostEntity_;
155  }
156  return *this;
157  }
158 
160  bool hasFather () const {
161  return hostEntity_->hasFather();
162  }
163 
165  EntitySeed seed () const
166  {
167  return EntitySeed(*hostEntity_);
168  }
169 
171  int level () const {
172  return hostEntity_->level();
173  }
174 
175 
178  PartitionType partitionType () const {
179  return hostEntity_->partitionType();
180  }
181 
182 
186  template<int cc> int count () const{
187  return hostEntity_->template count<cc>();
188  }
189 
190 
193  {
194  return Geometry( hostEntity_->geometry() );
195  }
196 
197 
198  HostGridEntityPointer hostEntity_;
199 
200 
201  private:
202 
204  template< class HostGridEntityPointer >
205  void setToTarget(const HostGridEntityPointer& target)
206  {
207  hostEntity_ = target;
208  }
209 
210 
211  const GridImp* identityGrid_;
212 
214 };
215 
216 
217 
218 
219 //***********************
220 //
221 // --IdentityGridEntity
222 //
223 //***********************
231 template<int dim, class GridImp>
232 class IdentityGridEntity<0,dim,GridImp> :
233  public EntityDefaultImplementation<0,dim,GridImp, IdentityGridEntity>
234 {
235  friend struct HostGridAccess< typename remove_const< GridImp >::type >;
236 
237  public:
238 
239  // The codimension of this entitypointer wrt the host grid
240  enum {CodimInHostGrid = GridImp::HostGridType::dimension - GridImp::dimension};
241 
242  // EntityPointer to the equivalent entity in the host grid
243  typedef typename GridImp::HostGridType::Traits::template Codim<CodimInHostGrid>::EntityPointer HostGridEntityPointer;
244 
245  typedef typename GridImp::template Codim<0>::Geometry Geometry;
246 
247  typedef typename GridImp::template Codim<0>::LocalGeometry LocalGeometry;
248 
251 
254 
257 
259  typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed;
260 
262  template< class HostGridEntityPointer >
263  IdentityGridEntity(const GridImp* identityGrid, const HostGridEntityPointer& hostEntity) :
264  identityGrid_(identityGrid),
265  hostEntity_(hostEntity)
266  {}
267 
268 
271  identityGrid_(original.identityGrid_),
272  hostEntity_(original.hostEntity_)
273  {}
274 
275 
278  {
279  if (this != &original)
280  {
281  identityGrid_ = original.identityGrid_;
282  hostEntity_ = original.hostEntity_;
283  }
284  return *this;
285  }
286 
288  bool hasFather () const {
289  return hostEntity_->hasFather();
290  }
291 
293  EntitySeed seed () const
294  {
295  return EntitySeed(*hostEntity_);
296  }
297 
299  int level () const
300  {
301  return hostEntity_->level();
302  }
303 
304 
306  PartitionType partitionType () const {
307  return hostEntity_->partitionType();
308  }
309 
310 
313  {
314  return Geometry( hostEntity_->geometry() );
315  }
316 
317 
320  template<int cc>
321  int count () const
322  {
323  return hostEntity_->template count<cc>();
324  }
325 
326 
330  template<int cc>
331  typename GridImp::template Codim<cc>::EntityPointer subEntity (int i) const{
332  return IdentityGridEntityPointer<cc,GridImp>(identityGrid_, hostEntity_->template subEntity<cc>(i));
333  }
334 
335 
339  hostEntity_->ilevelbegin());
340  }
341 
342 
346  hostEntity_->ilevelend());
347  }
348 
349 
353  hostEntity_->ileafbegin());
354  }
355 
356 
360  hostEntity_->ileafend());
361  }
362 
363 
365  bool isLeaf() const {
366  return hostEntity_->isLeaf();
367  }
368 
369 
373  return IdentityGridEntityPointer<0,GridImp>(identityGrid_, hostEntity_->father());
374  }
375 
376 
386  LocalGeometry geometryInFather () const
387  {
388  return LocalGeometry( hostEntity_->geometryInFather() );
389  }
390 
391 
396  IdentityGridHierarchicIterator<GridImp> hbegin (int maxLevel) const
397  {
398  return IdentityGridHierarchicIterator<const GridImp>(identityGrid_, *this, maxLevel);
399  }
400 
401 
403  IdentityGridHierarchicIterator<GridImp> hend (int maxLevel) const
404  {
405  return IdentityGridHierarchicIterator<const GridImp>(identityGrid_, *this, maxLevel, true);
406  }
407 
408 
410  bool wasRefined () const
411  {
412  if (identityGrid_->adaptationStep!=GridImp::adaptDone)
413  return false;
414 
415  int level = this->level();
416  int index = identityGrid_->levelIndexSet(level).index(*this);
417  return identityGrid_->refinementMark_[level][index];
418  }
419 
420 
422  bool mightBeCoarsened () const
423  {
424  return true;
425  }
426 
427 
428  // /////////////////////////////////////////
429  // Internal stuff
430  // /////////////////////////////////////////
431 
432 
434  template< class HostGridEntityPointer >
435  void setToTarget(const HostGridEntityPointer& target)
436  {
437  hostEntity_ = target;
438  }
439 
440 
441  const GridImp* identityGrid_;
442 
445 
446 
447  private:
448 
449  typedef typename GridImp::ctype ctype;
450 
451 }; // end of IdentityGridEntity codim = 0
452 
453 
454 } // namespace Dune
455 
456 
457 #endif