dune-grid-dev-howto  2.2.0
identitygridentity.hh
Go to the documentation of this file.
1 #ifndef DUNE_IDENTITYGRIDENTITY_HH
2 #define DUNE_IDENTITYGRIDENTITY_HH
3 
9 namespace Dune {
10 
11 
12 // Forward declarations
13 
14 template<int codim, int dim, class GridImp>
15 class IdentityGridEntity;
16 
17 template<int codim, class GridImp>
19 
20 template<int codim, PartitionIteratorType pitype, class GridImp>
22 
23 template<class GridImp>
25 
26 template<class GridImp>
28 
29 template<class GridImp>
31 
32 
33 // External forward declarations
34 template< class Grid >
35 class HostGridAccess;
36 
37 
38 
39 template<int codim, int dim, class GridImp>
41  public GridImp::template Codim<codim>::Entity
42 {
43  public:
44 
45  // The codimension of this entitypointer wrt the host grid
46  enum {CodimInHostGrid = GridImp::HostGridType::dimension - GridImp::dimension + codim};
47 
48  // EntityPointer to the equivalent entity in the host grid
49  typedef typename GridImp::HostGridType::Traits::template Codim<CodimInHostGrid>::EntityPointer HostGridEntityPointer;
50 
51 
53  template< class HostGridEntityPointer >
54  IdentityGridMakeableEntity(const GridImp* identityGrid, const HostGridEntityPointer& hostEntity) :
55  GridImp::template Codim<codim>::Entity (IdentityGridEntity<codim, dim, const GridImp>(identityGrid,hostEntity)),
56  identityGrid_(identityGrid)
57  {}
58 
59 
61  template< class HostGridEntityPointer >
62  void setToTarget(const HostGridEntityPointer& hostEntity) {
63  this->realEntity.setToTarget(hostEntity);
64  }
65 
66 
69  return this->realEntity.hostEntity_;
70  }
71 
72 
73  private:
74 
75  const GridImp* identityGrid_;
76 };
77 
78 
79 //**********************************************************************
80 //
81 // --IdentityGridEntity
82 // --Entity
83 //
91 template<int codim, int dim, class GridImp>
93  public EntityDefaultImplementation <codim,dim,GridImp,IdentityGridEntity>
94 {
95  friend class IdentityGridMakeableEntity<codim,dim,GridImp>;
96 
97  template <class GridImp_>
99 
100  template <class GridImp_>
102 
103  template <class GridImp_>
105 
106  template <class GridImp_>
108 
109  friend class IdentityGridEntityPointer<codim,GridImp>;
110 
111  friend class HostGridAccess< typename remove_const< GridImp >::type >;
112 
113 
114  private:
115 
116  typedef typename GridImp::ctype ctype;
117 
118  // The codimension of this entitypointer wrt the host grid
119  enum {CodimInHostGrid = GridImp::HostGridType::dimension - GridImp::dimension + codim};
120 
121  // EntityPointer to the equivalent entity in the host grid
122  typedef typename GridImp::HostGridType::Traits::template Codim<CodimInHostGrid>::EntityPointer HostGridEntityPointer;
123 
124 
125  public:
126 
127  typedef typename GridImp::template Codim<codim>::Geometry Geometry;
128 
130  typedef typename GridImp::template Codim<codim>::EntitySeed EntitySeed;
131 
133  template< class HostGridEntityPointer >
134  IdentityGridEntity(const GridImp* identityGrid, const HostGridEntityPointer& hostEntity) :
135  hostEntity_(hostEntity),
136  identityGrid_(identityGrid)
137  {}
138 
139 
142  hostEntity_(original.hostEntity_),
143  identityGrid_(original.identityGrid_)
144  {}
145 
146 
149  {
150  if (this != &original)
151  {
152  identityGrid_ = original.identityGrid_;
153  hostEntity_ = original.hostEntity_;
154  }
155  return *this;
156  }
157 
159  bool hasFather () const {
160  return hostEntity_->hasFather();
161  }
162 
164  EntitySeed seed () const
165  {
166  return EntitySeed(*hostEntity_);
167  }
168 
170  int level () const {
171  return hostEntity_->level();
172  }
173 
174 
177  PartitionType partitionType () const {
178  return hostEntity_->partitionType();
179  }
180 
181 
185  template<int cc> int count () const{
186  return hostEntity_->template count<cc>();
187  }
188 
189 
192  {
193  return Geometry( hostEntity_->geometry() );
194  }
195 
196 
197  HostGridEntityPointer hostEntity_;
198 
199 
200  private:
201 
203  template< class HostGridEntityPointer >
204  void setToTarget(const HostGridEntityPointer& target)
205  {
206  hostEntity_ = target;
207  }
208 
209 
210  const GridImp* identityGrid_;
211 
213 };
214 
215 
216 
217 
218 //***********************
219 //
220 // --IdentityGridEntity
221 //
222 //***********************
230 template<int dim, class GridImp>
231 class IdentityGridEntity<0,dim,GridImp> :
232  public EntityDefaultImplementation<0,dim,GridImp, IdentityGridEntity>
233 {
234  friend class HostGridAccess< typename remove_const< GridImp >::type >;
235 
236  public:
237 
238  // The codimension of this entitypointer wrt the host grid
239  enum {CodimInHostGrid = GridImp::HostGridType::dimension - GridImp::dimension};
240 
241  // EntityPointer to the equivalent entity in the host grid
242  typedef typename GridImp::HostGridType::Traits::template Codim<CodimInHostGrid>::EntityPointer HostGridEntityPointer;
243 
244  typedef typename GridImp::template Codim<0>::Geometry Geometry;
245 
246  typedef typename GridImp::template Codim<0>::LocalGeometry LocalGeometry;
247 
250 
253 
256 
258  typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed;
259 
261  template< class HostGridEntityPointer >
262  IdentityGridEntity(const GridImp* identityGrid, const HostGridEntityPointer& hostEntity) :
263  identityGrid_(identityGrid),
264  hostEntity_(hostEntity)
265  {}
266 
267 
270  identityGrid_(original.identityGrid_),
271  hostEntity_(original.hostEntity_)
272  {}
273 
274 
277  {
278  if (this != &original)
279  {
280  identityGrid_ = original.identityGrid_;
281  hostEntity_ = original.hostEntity_;
282  }
283  return *this;
284  }
285 
287  bool hasFather () const {
288  return hostEntity_->hasFather();
289  }
290 
292  EntitySeed seed () const
293  {
294  return EntitySeed(*hostEntity_);
295  }
296 
298  int level () const
299  {
300  return hostEntity_->level();
301  }
302 
303 
305  PartitionType partitionType () const {
306  return hostEntity_->partitionType();
307  }
308 
309 
312  {
313  return Geometry( hostEntity_->geometry() );
314  }
315 
316 
319  template<int cc>
320  int count () const
321  {
322  return hostEntity_->template count<cc>();
323  }
324 
325 
329  template<int cc>
330  typename GridImp::template Codim<cc>::EntityPointer subEntity (int i) const{
331  return IdentityGridEntityPointer<cc,GridImp>(identityGrid_, hostEntity_->template subEntity<cc>(i));
332  }
333 
334 
338  hostEntity_->ilevelbegin());
339  }
340 
341 
345  hostEntity_->ilevelend());
346  }
347 
348 
352  hostEntity_->ileafbegin());
353  }
354 
355 
359  hostEntity_->ileafend());
360  }
361 
362 
364  bool isLeaf() const {
365  return hostEntity_->isLeaf();
366  }
367 
368 
372  return IdentityGridEntityPointer<0,GridImp>(identityGrid_, hostEntity_->father());
373  }
374 
375 
385  LocalGeometry geometryInFather () const
386  {
387  return LocalGeometry( hostEntity_->geometryInFather() );
388  }
389 
390 
395  IdentityGridHierarchicIterator<GridImp> hbegin (int maxLevel) const
396  {
397  return IdentityGridHierarchicIterator<const GridImp>(identityGrid_, *this, maxLevel);
398  }
399 
400 
402  IdentityGridHierarchicIterator<GridImp> hend (int maxLevel) const
403  {
404  return IdentityGridHierarchicIterator<const GridImp>(identityGrid_, *this, maxLevel, true);
405  }
406 
407 
409  bool wasRefined () const
410  {
411  if (identityGrid_->adaptationStep!=GridImp::adaptDone)
412  return false;
413 
414  int level = this->level();
415  int index = identityGrid_->levelIndexSet(level).index(*this);
416  return identityGrid_->refinementMark_[level][index];
417  }
418 
419 
421  bool mightBeCoarsened () const
422  {
423  return true;
424  }
425 
426 
427  // /////////////////////////////////////////
428  // Internal stuff
429  // /////////////////////////////////////////
430 
431 
433  template< class HostGridEntityPointer >
434  void setToTarget(const HostGridEntityPointer& target)
435  {
436  hostEntity_ = target;
437  }
438 
439 
440  const GridImp* identityGrid_;
441 
444 
445 
446  private:
447 
448  typedef typename GridImp::ctype ctype;
449 
450 }; // end of IdentityGridEntity codim = 0
451 
452 
453 } // namespace Dune
454 
455 
456 #endif