dune-grid-dev-howto  2.3beta2
identitygridentity.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_IDENTITYGRIDENTITY_HH
4 #define DUNE_IDENTITYGRIDENTITY_HH
5 
10 #include <dune/grid/common/grid.hh>
11 
12 namespace Dune {
13 
14 
15  // Forward declarations
16 
17  template<int codim, int dim, class GridImp>
18  class IdentityGridEntity;
19 
20  template<int codim, class GridImp>
22 
23  template<int codim, PartitionIteratorType pitype, class GridImp>
25 
26  template<class GridImp>
28 
29  template<class GridImp>
31 
32  template<class GridImp>
34 
35 
36  // External forward declarations
37  template< class Grid >
38  struct HostGridAccess;
39 
40 
41 
42  template<int codim, int dim, class GridImp>
44  public GridImp::template Codim<codim>::Entity
45  {
46  public:
47 
48  // The codimension of this entitypointer wrt the host grid
49  enum {CodimInHostGrid = GridImp::HostGridType::dimension - GridImp::dimension + codim};
50 
51  // EntityPointer to the equivalent entity in the host grid
52  typedef typename GridImp::HostGridType::Traits::template Codim<CodimInHostGrid>::EntityPointer HostGridEntityPointer;
53 
54 
56  template< class HostGridEntityPointer >
57  IdentityGridMakeableEntity(const GridImp* identityGrid, const HostGridEntityPointer& hostEntity) :
58  GridImp::template Codim<codim>::Entity (IdentityGridEntity<codim, dim, const GridImp>(identityGrid,hostEntity)),
59  identityGrid_(identityGrid)
60  {}
61 
62 
64  template< class HostGridEntityPointer >
65  void setToTarget(const HostGridEntityPointer& hostEntity) {
66  this->realEntity.setToTarget(hostEntity);
67  }
68 
69 
72  return this->realEntity.hostEntity_;
73  }
74 
75 
76  private:
77 
78  const GridImp* identityGrid_;
79  };
80 
81 
82  //**********************************************************************
83  //
84  // --IdentityGridEntity
85  // --Entity
86  //
94  template<int codim, int dim, class GridImp>
96  public EntityDefaultImplementation <codim,dim,GridImp,IdentityGridEntity>
97  {
98  friend class IdentityGridMakeableEntity<codim,dim,GridImp>;
99 
100  template <class GridImp_>
102 
103  template <class GridImp_>
105 
106  template <class GridImp_>
108 
109  template <class GridImp_>
111 
112  friend class IdentityGridEntityPointer<codim,GridImp>;
113 
114  friend struct HostGridAccess< typename remove_const< GridImp >::type >;
115 
116 
117  private:
118 
119  typedef typename GridImp::ctype ctype;
120 
121  // The codimension of this entitypointer wrt the host grid
122  enum {CodimInHostGrid = GridImp::HostGridType::dimension - GridImp::dimension + codim};
123 
124  // EntityPointer to the equivalent entity in the host grid
125  typedef typename GridImp::HostGridType::Traits::template Codim<CodimInHostGrid>::EntityPointer HostGridEntityPointer;
126 
127 
128  public:
129 
130  typedef typename GridImp::template Codim<codim>::Geometry Geometry;
131 
133  typedef typename GridImp::template Codim<codim>::EntitySeed EntitySeed;
134 
136  template< class HostGridEntityPointer >
137  IdentityGridEntity(const GridImp* identityGrid, const HostGridEntityPointer& hostEntity) :
138  hostEntity_(hostEntity),
139  identityGrid_(identityGrid)
140  {}
141 
142 
145  hostEntity_(original.hostEntity_),
146  identityGrid_(original.identityGrid_)
147  {}
148 
149 
152  {
153  if (this != &original)
154  {
155  identityGrid_ = original.identityGrid_;
156  hostEntity_ = original.hostEntity_;
157  }
158  return *this;
159  }
160 
162  bool hasFather () const {
163  return hostEntity_->hasFather();
164  }
165 
167  EntitySeed seed () const
168  {
169  return EntitySeed(*hostEntity_);
170  }
171 
173  int level () const {
174  return hostEntity_->level();
175  }
176 
177 
180  PartitionType partitionType () const {
181  return hostEntity_->partitionType();
182  }
183 
184 
188  template<int cc> int count () const {
189  return hostEntity_->template count<cc>();
190  }
191 
192 
195  {
196  return Geometry( hostEntity_->geometry() );
197  }
198 
199 
200  HostGridEntityPointer hostEntity_;
201 
202 
203  private:
204 
206  template< class HostGridEntityPointer >
207  void setToTarget(const HostGridEntityPointer& target)
208  {
209  hostEntity_ = target;
210  }
211 
212 
213  const GridImp* identityGrid_;
214 
216  };
217 
218 
219 
220 
221  //***********************
222  //
223  // --IdentityGridEntity
224  //
225  //***********************
233  template<int dim, class GridImp>
234  class IdentityGridEntity<0,dim,GridImp> :
235  public EntityDefaultImplementation<0,dim,GridImp, IdentityGridEntity>
236  {
237  friend struct HostGridAccess< typename remove_const< GridImp >::type >;
238 
239  public:
240 
241  // The codimension of this entitypointer wrt the host grid
242  enum {CodimInHostGrid = GridImp::HostGridType::dimension - GridImp::dimension};
243 
244  // EntityPointer to the equivalent entity in the host grid
245  typedef typename GridImp::HostGridType::Traits::template Codim<CodimInHostGrid>::EntityPointer HostGridEntityPointer;
246 
247  typedef typename GridImp::template Codim<0>::Geometry Geometry;
248 
249  typedef typename GridImp::template Codim<0>::LocalGeometry LocalGeometry;
250 
253 
256 
259 
261  typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed;
262 
264  template< class HostGridEntityPointer >
265  IdentityGridEntity(const GridImp* identityGrid, const HostGridEntityPointer& hostEntity) :
266  identityGrid_(identityGrid),
267  hostEntity_(hostEntity)
268  {}
269 
270 
273  identityGrid_(original.identityGrid_),
274  hostEntity_(original.hostEntity_)
275  {}
276 
277 
280  {
281  if (this != &original)
282  {
283  identityGrid_ = original.identityGrid_;
284  hostEntity_ = original.hostEntity_;
285  }
286  return *this;
287  }
288 
290  bool hasFather () const {
291  return hostEntity_->hasFather();
292  }
293 
295  EntitySeed seed () const
296  {
297  return EntitySeed(*hostEntity_);
298  }
299 
301  int level () const
302  {
303  return hostEntity_->level();
304  }
305 
306 
308  PartitionType partitionType () const {
309  return hostEntity_->partitionType();
310  }
311 
312 
315  {
316  return Geometry( hostEntity_->geometry() );
317  }
318 
319 
322  template<int cc>
323  int count () const
324  {
325  return hostEntity_->template count<cc>();
326  }
327 
328 
332  template<int cc>
333  typename GridImp::template Codim<cc>::EntityPointer subEntity (int i) const {
334  return IdentityGridEntityPointer<cc,GridImp>(identityGrid_, hostEntity_->template subEntity<cc>(i));
335  }
336 
337 
341  hostEntity_->ilevelbegin());
342  }
343 
344 
348  hostEntity_->ilevelend());
349  }
350 
351 
355  hostEntity_->ileafbegin());
356  }
357 
358 
362  hostEntity_->ileafend());
363  }
364 
365 
367  bool isLeaf() const {
368  return hostEntity_->isLeaf();
369  }
370 
371 
375  return IdentityGridEntityPointer<0,GridImp>(identityGrid_, hostEntity_->father());
376  }
377 
378 
388  LocalGeometry geometryInFather () const
389  {
390  return LocalGeometry( hostEntity_->geometryInFather() );
391  }
392 
393 
398  IdentityGridHierarchicIterator<GridImp> hbegin (int maxLevel) const
399  {
400  return IdentityGridHierarchicIterator<const GridImp>(identityGrid_, *this, maxLevel);
401  }
402 
403 
405  IdentityGridHierarchicIterator<GridImp> hend (int maxLevel) const
406  {
407  return IdentityGridHierarchicIterator<const GridImp>(identityGrid_, *this, maxLevel, true);
408  }
409 
410 
412  bool wasRefined () const
413  {
414  if (identityGrid_->adaptationStep!=GridImp::adaptDone)
415  return false;
416 
417  int level = this->level();
418  int index = identityGrid_->levelIndexSet(level).index(*this);
419  return identityGrid_->refinementMark_[level][index];
420  }
421 
422 
424  bool mightBeCoarsened () const
425  {
426  return true;
427  }
428 
429 
430  // /////////////////////////////////////////
431  // Internal stuff
432  // /////////////////////////////////////////
433 
434 
436  template< class HostGridEntityPointer >
437  void setToTarget(const HostGridEntityPointer& target)
438  {
439  hostEntity_ = target;
440  }
441 
442 
443  const GridImp* identityGrid_;
444 
447 
448 
449  private:
450 
451  typedef typename GridImp::ctype ctype;
452 
453  }; // end of IdentityGridEntity codim = 0
454 
455 
456 } // namespace Dune
457 
458 
459 #endif