dune-grid-dev-howto  2.3.1
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
~IdentityGrid()
Desctructor.
Definition: identitygrid.hh:141
HostGrid HostGridType
Definition: identitygrid.hh:112
Definition: identitygridindexsets.hh:172
bool adapt()
Triggers the grid refinement process.
Definition: identitygrid.hh:327
The IdentityGridEntity class.
HostGrid::Traits::template Codim< codim >::EntityPointer getHostEntityPointer(const typename Traits::template Codim< codim >::Entity &e) const
Returns the hostgrid entity encapsulated in given IdentityGrid entity.
Definition: identitygrid.hh:421
HostGrid * hostgrid_
The host grid which contains the actual grid hierarchy structure.
Definition: identitygrid.hh:429
Iterator over all entities of a given codimension and level of a grid.
Definition: identitygridleafiterator.hh:19
[ provides Dune::Grid ]
Definition: identitygrid.hh:33
Traits::template Codim< codim >::template Partition< PiType >::LevelIterator lend(int level) const
one past the end on this level
Definition: identitygrid.hh:180
unsigned int ghostSize(int codim) const
Size of the ghost cell layer on the leaf level.
Definition: identitygrid.hh:346
void globalRefine(int refCount)
Definition: identitygrid.hh:291
The IdentityGridGeometry class and its specializations.
void postAdapt()
Clean up refinement markers.
Definition: identitygrid.hh:333
The IdentityGridLeafIterator class.
const CollectiveCommunication< IdentityGrid > & comm() const
Definition: identitygrid.hh:402
bool preAdapt()
Definition: identitygrid.hh:321
const Traits::LeafIndexSet & leafIndexSet() const
Access to the LeafIndexSet.
Definition: identitygrid.hh:266
Traits::template Codim< codim >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
Definition: identitygrid.hh:159
Traits::template Codim< codim >::template Partition< PiType >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
Definition: identitygrid.hh:173
Definition: identitygridentity.hh:27
GridTraits< dim, HostGrid::dimensionworld, Dune::IdentityGrid< HostGrid >, IdentityGridGeometry, IdentityGridEntity, IdentityGridEntityPointer, IdentityGridLevelIterator, IdentityGridLeafIntersection, IdentityGridLevelIntersection, IdentityGridLeafIntersectionIterator, IdentityGridLevelIntersectionIterator, IdentityGridHierarchicIterator, IdentityGridLeafIterator, IdentityGridLevelIndexSet< const IdentityGrid< HostGrid > >, IdentityGridLeafIndexSet< const IdentityGrid< HostGrid > >, IdentityGridGlobalIdSet< const IdentityGrid< HostGrid > >, typename HostGrid::Traits::GlobalIdSet::IdType, IdentityGridLocalIdSet< const IdentityGrid< HostGrid > >, typename HostGrid::Traits::LocalIdSet::IdType, CollectiveCommunication< IdentityGrid< HostGrid > >, DefaultLevelGridViewTraits, DefaultLeafGridViewTraits, IdentityGridEntitySeed > Traits
Definition: identitygrid.hh:69
Definition: identitygridentity.hh:21
unsigned int overlapSize(int level, int codim) const
Size of the overlap on a given level.
Definition: identitygrid.hh:352
int size(int level, int codim) const
Number of grid entities per level and codim.
Definition: identitygrid.hh:215
int size(GeometryType type) const
number of leaf entities per codim and geometry type in this process
Definition: identitygrid.hh:238
Traits::template Codim< codim >::LeafIterator leafend() const
one past the end of the sequence of leaf entities
Definition: identitygrid.hh:194
IdentityGrid(HostGrid &hostgrid)
Constructor.
Definition: identitygrid.hh:130
int getMark(const typename Traits::template Codim< 0 >::EntityPointer &e) const
Return refinement mark for entity.
Definition: identitygrid.hh:315
Traits::template Codim< codim >::LevelIterator lend(int level) const
one past the end on this level
Definition: identitygrid.hh:166
Definition: identitygridgeometry.hh:17
Iterator over all element neighborsMesh entities of codimension 0 ("elements") allow to visit all nei...
Definition: identitygridentity.hh:30
Definition: identitygridindexsets.hh:84
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim.
Definition: identitygrid.hh:201
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafend() const
one past the end of the sequence of leaf entities
Definition: identitygrid.hh:208
The IdentityGridEntitySeed class.
Definition: identitygridintersections.hh:181
HostGridType & getHostGrid() const
Returns the hostgrid this IdentityGrid lives in.
Definition: identitygrid.hh:413
The index and id sets for the IdentityGrid class.
Definition: identitygridindexsets.hh:224
int size(int codim) const
number of leaf entities per codim in this process
Definition: identitygrid.hh:226
size_t numBoundarySegments() const
returns the number of boundary segments within the macro grid
Definition: identitygrid.hh:221
An intersection with a leaf neighbor elementMesh entities of codimension 0 ("elements") allow to visi...
Definition: identitygridintersections.hh:29
Iterator over the descendants of an entity.Mesh entities of codimension 0 ("elements") allow to visit...
Definition: identitygridentity.hh:33
int size(int level, GeometryType type) const
number of entities per level, codim and geometry type in this process
Definition: identitygrid.hh:232
Traits::template Codim< codim >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim.
Definition: identitygrid.hh:187
IdentityGridFamily< HostGrid::dimension, HostGrid >::Traits Traits
the Traits
Definition: identitygrid.hh:122
int maxLevel() const
Definition: identitygrid.hh:152
The IdentityGridLeafIntersectionIterator and IdentityGridLevelIntersectionIterator classes...
Definition: identitygrid.hh:43
The IdentityGridHierarchicIterator class.
IdentityGridFamily< HostGrid::dimension, HostGrid > GridFamily
type of the used GridFamily for this grid
Definition: identitygrid.hh:119
const Traits::LocalIdSet & localIdSet() const
Access to the LocalIdSet.
Definition: identitygrid.hh:251
unsigned int ghostSize(int level, int codim) const
Size of the ghost cell layer on a given level.
Definition: identitygrid.hh:358
HostGrid::ctype ctype
The type used to store coordinates, inherited from the HostGrid.
Definition: identitygrid.hh:125
The IdentityGridEntityPointer class.
unsigned int overlapSize(int codim) const
Size of the overlap on the leaf level.
Definition: identitygrid.hh:340
Definition: identitygridindexsets.hh:18
The implementation of entities in a IdentityGridA Grid is a container of grid entities. An entity is parametrized by the codimension. An entity of codimension c in dimension d is a d-c dimensional object.
Definition: identitygridentity.hh:18
bool mark(int refCount, const typename Traits::template Codim< 0 >::EntityPointer &e)
Mark entity for refinement.
Definition: identitygrid.hh:306
const Traits::LevelIndexSet & levelIndexSet(int level) const
Access to the LevelIndexSets.
Definition: identitygrid.hh:257
Definition: identitygridentity.hh:38
const Traits::GlobalIdSet & globalIdSet() const
Access to the GlobalIdSet.
Definition: identitygrid.hh:245
Traits::template Codim< EntitySeed::codimension >::EntityPointer entityPointer(const EntitySeed &seed) const
Create EntityPointer from EntitySeed.
Definition: identitygrid.hh:275
Iterator over all entities of a given codimension and level of a grid.
Definition: identitygridentity.hh:24
The IdentityGridLevelIterator class and its specializations.
The EntitySeed class provides the minimal information needed to restore an Entity using the grid...
Definition: identitygridentityseed.hh:21