dune-grid-dev-howto  2.2.1
identitygrid.hh
Go to the documentation of this file.
1 #ifndef DUNE_IDENTITYGRID_HH
2 #define DUNE_IDENTITYGRID_HH
3 
8 #include <string>
9 #include <map>
10 
11 #include <dune/common/collectivecommunication.hh>
12 #include <dune/grid/common/capabilities.hh>
13 #include <dune/grid/common/grid.hh>
14 #include <dune/common/timer.hh>
15 
16 // The components of the Identitygrid interface
26 
27 namespace Dune {
28 
29 // Forward declaration
30 template <class HostGrid>
31 class IdentityGrid;
32 
33 
34 // External forward declarations
35 template< class Grid >
36 struct HostGridAccess;
37 
38 
39 
40 template<int dim, class HostGrid>
42 {
43  typedef GridTraits<
44  dim,
45  HostGrid::dimensionworld,
60  typename HostGrid::Traits::GlobalIdSet::IdType,
62  typename HostGrid::Traits::LocalIdSet::IdType,
63  CollectiveCommunication<IdentityGrid<HostGrid> >,
64  DefaultLevelGridViewTraits,
65  DefaultLeafGridViewTraits,
67  > Traits;
68 };
69 
70 
71 
72 
73 //**********************************************************************
74 //
75 // --IdentityGrid
76 //
77 //**********************************************************************
78 
82 template <class HostGrid>
83 class IdentityGrid :
84  public GridDefaultImplementation <HostGrid::dimension, HostGrid::dimensionworld, double, IdentityGridFamily<HostGrid::dimension,HostGrid> >
85 {
86 
87  friend class IdentityGridLevelIndexSet<const IdentityGrid<HostGrid> >;
88  friend class IdentityGridLeafIndexSet<const IdentityGrid<HostGrid> >;
89  friend class IdentityGridGlobalIdSet<const IdentityGrid<HostGrid> >;
90  friend class IdentityGridLocalIdSet<const IdentityGrid<HostGrid> >;
91  friend class IdentityGridHierarchicIterator<const IdentityGrid<HostGrid> >;
92  friend class IdentityGridLevelIntersectionIterator<const IdentityGrid<HostGrid> >;
93  friend class IdentityGridLeafIntersectionIterator<const IdentityGrid<HostGrid> >;
94 
95  template<int codim, PartitionIteratorType pitype, class GridImp_>
97 
98  template<int codim, PartitionIteratorType pitype, class GridImp_>
100 
101 
102  template<int codim_, int dim_, class GridImp_>
103  friend class IdentityGridEntity;
104 
105  friend struct HostGridAccess< IdentityGrid< HostGrid > >;
106 
107  public:
108 
110  typedef HostGrid HostGridType;
111 
112  //**********************************************************
113  // The Interface Methods
114  //**********************************************************
115 
118 
121 
123  typedef typename HostGrid::ctype ctype;
124 
125 
128  explicit IdentityGrid(HostGrid& hostgrid) :
129  hostgrid_(&hostgrid),
130  leafIndexSet_(*this),
131  globalIdSet_(*this),
132  localIdSet_(*this)
133  {
134  setIndices();
135  }
136 
137 
140  {
141  // Delete level index sets
142  for (size_t i=0; i<levelIndexSets_.size(); i++)
143  if (levelIndexSets_[i])
144  delete (levelIndexSets_[i]);
145  }
146 
147 
150  int maxLevel() const {
151  return hostgrid_->maxLevel();
152  }
153 
154 
156  template<int codim>
157  typename Traits::template Codim<codim>::LevelIterator lbegin (int level) const{
159  }
160 
161 
163  template<int codim>
164  typename Traits::template Codim<codim>::LevelIterator lend (int level) const{
166  }
167 
168 
170  template<int codim, PartitionIteratorType PiType>
171  typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lbegin (int level) const{
173  }
174 
175 
177  template<int codim, PartitionIteratorType PiType>
178  typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lend (int level) const{
180  }
181 
182 
184  template<int codim>
185  typename Traits::template Codim<codim>::LeafIterator leafbegin() const {
187  }
188 
189 
191  template<int codim>
192  typename Traits::template Codim<codim>::LeafIterator leafend() const {
194  }
195 
196 
198  template<int codim, PartitionIteratorType PiType>
199  typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafbegin() const {
201  }
202 
203 
205  template<int codim, PartitionIteratorType PiType>
206  typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafend() const {
208  }
209 
210 
213  int size (int level, int codim) const {
214  return hostgrid_->size(level,codim);
215  }
216 
219  size_t numBoundarySegments () const {
220  return hostgrid_->numBoundarySegments();
221  }
222 
224  int size (int codim) const{
225  return leafIndexSet().size(codim);
226  }
227 
228 
230  int size (int level, GeometryType type) const {
231  return levelIndexSets_[level]->size(type);
232  }
233 
234 
236  int size (GeometryType type) const
237  {
238  return leafIndexSet().size(type);
239  }
240 
241 
243  const typename Traits::GlobalIdSet& globalIdSet() const{
244  return globalIdSet_;
245  }
246 
247 
249  const typename Traits::LocalIdSet& localIdSet() const{
250  return localIdSet_;
251  }
252 
253 
255  const typename Traits::LevelIndexSet& levelIndexSet(int level) const
256  {
257  if (level<0 || level>maxLevel())
258  DUNE_THROW(GridError, "levelIndexSet of nonexisting level " << level << " requested!");
259  return *levelIndexSets_[level];
260  }
261 
262 
264  const typename Traits::LeafIndexSet& leafIndexSet() const
265  {
266  return leafIndexSet_;
267  }
268 
269 
271  template < class EntitySeed >
272  typename Traits::template Codim<EntitySeed::codimension>::EntityPointer
273  entityPointer(const EntitySeed& seed) const
274  {
275  typedef typename Traits::template Codim<EntitySeed::codimension>::EntityPointer EntityPointer;
277 
278  return EntityPointer(EntityPointerImp(this, hostgrid_->entityPointer(seed.hostEntitySeed())));
279  }
280 
281 
284 
285 
289  void globalRefine (int refCount)
290  {
291  hostgrid_->globalRefine(refCount);
292  }
293 
304  bool mark(int refCount, const typename Traits::template Codim<0>::EntityPointer & e)
305  {
306  return hostgrid_->mark(refCount, *getHostEntityPointer<0>(*e));
307  }
308 
313  int getMark(const typename Traits::template Codim<0>::EntityPointer & e) const
314  {
315  return hostgrid_->getMark(*getHostEntityPointer<0>(*e));
316  }
317 
319  bool preAdapt() {
320  return hostgrid_->preAdapt();
321  }
322 
323 
325  bool adapt()
326  {
327  return hostgrid_->adapt();
328  }
329 
331  void postAdapt() {
332  return hostgrid_->postAdapt();
333  }
334 
338  unsigned int overlapSize(int codim) const {
339  return hostgrid_->overlapSize(codim);
340  }
341 
342 
344  unsigned int ghostSize(int codim) const {
345  return hostgrid_->ghostSize(codim);
346  }
347 
348 
350  unsigned int overlapSize(int level, int codim) const {
351  return hostgrid_->overlapSize(level,codim);
352  }
353 
354 
356  unsigned int ghostSize(int level, int codim) const {
357  return hostgrid_->ghostSize(level,codim);
358  }
359 
360 
361 #if 0
362 
367  void loadBalance(int strategy, int minlevel, int depth, int maxlevel, int minelement){
368  DUNE_THROW(NotImplemented, "IdentityGrid::loadBalance()");
369  }
370 
382  template<class T, template<class> class P, int codim>
383  void communicate (T& t, InterfaceType iftype, CommunicationDirection dir, int level);
384 
389  template<class DataHandle>
390  void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir, int level) const
391  {}
392 
393  template<class DataHandle>
394  void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir) const
395  {}
396 #endif
397 
398 
400  const CollectiveCommunication<IdentityGrid>& comm () const
401  {
402  return ccobj;
403  }
404 
405 
406  // **********************************************************
407  // End of Interface Methods
408  // **********************************************************
409 
412  {
413  return *hostgrid_;
414  }
415 
416 
418  template <int codim>
419  typename HostGrid::Traits::template Codim<codim>::EntityPointer getHostEntityPointer(const typename Traits::template Codim<codim>::Entity& e) const
420  {
421  return this->getRealImplementation(e).hostEntity_;
422  }
423 
424  protected:
425 
427  HostGrid* hostgrid_;
428 
429  private:
430 
432  void setIndices()
433  {
434  localIdSet_.update();
435 
436  globalIdSet_.update();
437 
438  // //////////////////////////////////////////
439  // Create the index sets
440  // //////////////////////////////////////////
441  for (int i=levelIndexSets_.size(); i<=maxLevel(); i++) {
444  levelIndexSets_.push_back(p);
445  }
446 
447  for (int i=0; i<=maxLevel(); i++)
448  if (levelIndexSets_[i])
449  levelIndexSets_[i]->update(*this, i);
450 
451  leafIndexSet_.update(*this);
452 
453  }
454 
456  CollectiveCommunication<IdentityGrid> ccobj;
457 
459  std::vector<IdentityGridLevelIndexSet<const IdentityGrid<HostGrid> >*> levelIndexSets_;
460 
463 
466 
469 
470 }; // end Class IdentityGrid
471 
472 
473 
474 
475 namespace Capabilities
476 {
478  template<class HostGrid, int codim>
479  struct hasEntity< IdentityGrid<HostGrid>, codim>
480  {
481  static const bool v = hasEntity<HostGrid,codim>::v;
482  };
483 
484 
486  template<class HostGrid>
487  struct isParallel< IdentityGrid<HostGrid> >
488  {
489  static const bool v = isParallel<HostGrid>::v;
490  };
491 
492 
495  template<class HostGrid>
496  struct isLevelwiseConforming< IdentityGrid<HostGrid> >
497  {
498  static const bool v = isLevelwiseConforming<HostGrid>::v;
499  };
500 
502  template<class HostGrid>
503  struct isLeafwiseConforming< IdentityGrid<HostGrid> >
504  {
505  static const bool v = isLeafwiseConforming<HostGrid>::v;
506  };
507 }
508 
509 } // namespace Dune
510 
511 #endif