dune-grid-dev-howto  2.3beta2
identitygrid.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_IDENTITYGRID_HH
4 #define DUNE_IDENTITYGRID_HH
5 
10 #include <string>
11 #include <map>
12 
13 #include <dune/common/parallel/collectivecommunication.hh>
14 #include <dune/grid/common/capabilities.hh>
15 #include <dune/grid/common/grid.hh>
16 #include <dune/common/timer.hh>
17 
18 // The components of the Identitygrid interface
28 
29 namespace Dune {
30 
31  // Forward declaration
32  template <class HostGrid>
33  class IdentityGrid;
34 
35 
36  // External forward declarations
37  template< class Grid >
38  struct HostGridAccess;
39 
40 
41 
42  template<int dim, class HostGrid>
44  {
45  typedef GridTraits<
46  dim,
47  HostGrid::dimensionworld,
62  typename HostGrid::Traits::GlobalIdSet::IdType,
64  typename HostGrid::Traits::LocalIdSet::IdType,
65  CollectiveCommunication<IdentityGrid<HostGrid> >,
66  DefaultLevelGridViewTraits,
67  DefaultLeafGridViewTraits,
69  > Traits;
70  };
71 
72 
73 
74 
75  //**********************************************************************
76  //
77  // --IdentityGrid
78  //
79  //**********************************************************************
80 
84  template <class HostGrid>
85  class IdentityGrid :
86  public GridDefaultImplementation <HostGrid::dimension, HostGrid::dimensionworld, double, IdentityGridFamily<HostGrid::dimension,HostGrid> >
87  {
88 
89  friend class IdentityGridLevelIndexSet<const IdentityGrid<HostGrid> >;
90  friend class IdentityGridLeafIndexSet<const IdentityGrid<HostGrid> >;
91  friend class IdentityGridGlobalIdSet<const IdentityGrid<HostGrid> >;
92  friend class IdentityGridLocalIdSet<const IdentityGrid<HostGrid> >;
93  friend class IdentityGridHierarchicIterator<const IdentityGrid<HostGrid> >;
94  friend class IdentityGridLevelIntersectionIterator<const IdentityGrid<HostGrid> >;
95  friend class IdentityGridLeafIntersectionIterator<const IdentityGrid<HostGrid> >;
96 
97  template<int codim, PartitionIteratorType pitype, class GridImp_>
99 
100  template<int codim, PartitionIteratorType pitype, class GridImp_>
102 
103 
104  template<int codim_, int dim_, class GridImp_>
105  friend class IdentityGridEntity;
106 
107  friend struct HostGridAccess< IdentityGrid< HostGrid > >;
108 
109  public:
110 
112  typedef HostGrid HostGridType;
113 
114  //**********************************************************
115  // The Interface Methods
116  //**********************************************************
117 
120 
123 
125  typedef typename HostGrid::ctype ctype;
126 
127 
130  explicit IdentityGrid(HostGrid& hostgrid) :
131  hostgrid_(&hostgrid),
132  leafIndexSet_(*this),
133  globalIdSet_(*this),
134  localIdSet_(*this)
135  {
136  setIndices();
137  }
138 
139 
142  {
143  // Delete level index sets
144  for (size_t i=0; i<levelIndexSets_.size(); i++)
145  if (levelIndexSets_[i])
146  delete (levelIndexSets_[i]);
147  }
148 
149 
152  int maxLevel() const {
153  return hostgrid_->maxLevel();
154  }
155 
156 
158  template<int codim>
159  typename Traits::template Codim<codim>::LevelIterator lbegin (int level) const {
161  }
162 
163 
165  template<int codim>
166  typename Traits::template Codim<codim>::LevelIterator lend (int level) const {
168  }
169 
170 
172  template<int codim, PartitionIteratorType PiType>
173  typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lbegin (int level) const {
175  }
176 
177 
179  template<int codim, PartitionIteratorType PiType>
180  typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lend (int level) const {
182  }
183 
184 
186  template<int codim>
187  typename Traits::template Codim<codim>::LeafIterator leafbegin() const {
189  }
190 
191 
193  template<int codim>
194  typename Traits::template Codim<codim>::LeafIterator leafend() const {
196  }
197 
198 
200  template<int codim, PartitionIteratorType PiType>
201  typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafbegin() const {
203  }
204 
205 
207  template<int codim, PartitionIteratorType PiType>
208  typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafend() const {
210  }
211 
212 
215  int size (int level, int codim) const {
216  return hostgrid_->size(level,codim);
217  }
218 
221  size_t numBoundarySegments () const {
222  return hostgrid_->numBoundarySegments();
223  }
224 
226  int size (int codim) const {
227  return leafIndexSet().size(codim);
228  }
229 
230 
232  int size (int level, GeometryType type) const {
233  return levelIndexSets_[level]->size(type);
234  }
235 
236 
238  int size (GeometryType type) const
239  {
240  return leafIndexSet().size(type);
241  }
242 
243 
245  const typename Traits::GlobalIdSet& globalIdSet() const {
246  return globalIdSet_;
247  }
248 
249 
251  const typename Traits::LocalIdSet& localIdSet() const {
252  return localIdSet_;
253  }
254 
255 
257  const typename Traits::LevelIndexSet& levelIndexSet(int level) const
258  {
259  if (level<0 || level>maxLevel())
260  DUNE_THROW(GridError, "levelIndexSet of nonexisting level " << level << " requested!");
261  return *levelIndexSets_[level];
262  }
263 
264 
266  const typename Traits::LeafIndexSet& leafIndexSet() const
267  {
268  return leafIndexSet_;
269  }
270 
271 
273  template < class EntitySeed >
274  typename Traits::template Codim<EntitySeed::codimension>::EntityPointer
275  entityPointer(const EntitySeed& seed) const
276  {
277  typedef typename Traits::template Codim<EntitySeed::codimension>::EntityPointer EntityPointer;
279 
280  return EntityPointer(EntityPointerImp(this, hostgrid_->entityPointer(this->getRealImplementation(seed).hostEntitySeed())));
281  }
282 
283 
286 
287 
291  void globalRefine (int refCount)
292  {
293  hostgrid_->globalRefine(refCount);
294  }
295 
306  bool mark(int refCount, const typename Traits::template Codim<0>::EntityPointer & e)
307  {
308  return hostgrid_->mark(refCount, *getHostEntityPointer<0>(*e));
309  }
310 
315  int getMark(const typename Traits::template Codim<0>::EntityPointer & e) const
316  {
317  return hostgrid_->getMark(*getHostEntityPointer<0>(*e));
318  }
319 
321  bool preAdapt() {
322  return hostgrid_->preAdapt();
323  }
324 
325 
327  bool adapt()
328  {
329  return hostgrid_->adapt();
330  }
331 
333  void postAdapt() {
334  return hostgrid_->postAdapt();
335  }
336 
340  unsigned int overlapSize(int codim) const {
341  return hostgrid_->overlapSize(codim);
342  }
343 
344 
346  unsigned int ghostSize(int codim) const {
347  return hostgrid_->ghostSize(codim);
348  }
349 
350 
352  unsigned int overlapSize(int level, int codim) const {
353  return hostgrid_->overlapSize(level,codim);
354  }
355 
356 
358  unsigned int ghostSize(int level, int codim) const {
359  return hostgrid_->ghostSize(level,codim);
360  }
361 
362 
363 #if 0
364 
369  void loadBalance(int strategy, int minlevel, int depth, int maxlevel, int minelement){
370  DUNE_THROW(NotImplemented, "IdentityGrid::loadBalance()");
371  }
372 
384  template<class T, template<class> class P, int codim>
385  void communicate (T& t, InterfaceType iftype, CommunicationDirection dir, int level);
386 
391  template<class DataHandle>
392  void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir, int level) const
393  {}
394 
395  template<class DataHandle>
396  void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir) const
397  {}
398 #endif
399 
400 
402  const CollectiveCommunication<IdentityGrid>& comm () const
403  {
404  return ccobj;
405  }
406 
407 
408  // **********************************************************
409  // End of Interface Methods
410  // **********************************************************
411 
414  {
415  return *hostgrid_;
416  }
417 
418 
420  template <int codim>
421  typename HostGrid::Traits::template Codim<codim>::EntityPointer getHostEntityPointer(const typename Traits::template Codim<codim>::Entity& e) const
422  {
423  return this->getRealImplementation(e).hostEntity_;
424  }
425 
426  protected:
427 
429  HostGrid* hostgrid_;
430 
431  private:
432 
434  void setIndices()
435  {
436  localIdSet_.update();
437 
438  globalIdSet_.update();
439 
440  // //////////////////////////////////////////
441  // Create the index sets
442  // //////////////////////////////////////////
443  for (int i=levelIndexSets_.size(); i<=maxLevel(); i++) {
446  levelIndexSets_.push_back(p);
447  }
448 
449  for (int i=0; i<=maxLevel(); i++)
450  if (levelIndexSets_[i])
451  levelIndexSets_[i]->update(*this, i);
452 
453  leafIndexSet_.update(*this);
454 
455  }
456 
458  CollectiveCommunication<IdentityGrid> ccobj;
459 
461  std::vector<IdentityGridLevelIndexSet<const IdentityGrid<HostGrid> >*> levelIndexSets_;
462 
465 
468 
471 
472  }; // end Class IdentityGrid
473 
474 
475 
476 
477  namespace Capabilities
478  {
480  template<class HostGrid, int codim>
481  struct hasEntity< IdentityGrid<HostGrid>, codim>
482  {
483  static const bool v = hasEntity<HostGrid,codim>::v;
484  };
485 
486 
488  template<class HostGrid>
489  struct isParallel< IdentityGrid<HostGrid> >
490  {
491  static const bool v = isParallel<HostGrid>::v;
492  };
493 
494 
497  template<class HostGrid>
498  struct isLevelwiseConforming< IdentityGrid<HostGrid> >
499  {
500  static const bool v = isLevelwiseConforming<HostGrid>::v;
501  };
502 
504  template<class HostGrid>
505  struct isLeafwiseConforming< IdentityGrid<HostGrid> >
506  {
507  static const bool v = isLeafwiseConforming<HostGrid>::v;
508  };
509  }
510 
511 } // namespace Dune
512 
513 #endif