dune-grid  2.8.0
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_GRID_IDENTITYGRID_HH
4 #define DUNE_GRID_IDENTITYGRID_HH
5 
10 #include <string>
11 #include <map>
12 
13 #include <dune/common/parallel/communication.hh>
15 #include <dune/grid/common/grid.hh>
16 
17 // The components of the IdentityGrid interface
26 
27 namespace Dune
28 {
29  // Forward declaration
30  template <class HostGrid>
31  class IdentityGrid;
32 
33  // External forward declarations
34  template< class Grid >
35  struct HostGridAccess;
36 
37  template<int dim, class HostGrid>
39  {
40 
41  public:
42 
43  typedef GridTraits<
44  dim,
45  HostGrid::dimensionworld,
59  typename HostGrid::Traits::GlobalIdSet::IdType,
61  typename HostGrid::Traits::LocalIdSet::IdType,
62  CollectiveCommunication<No_Comm>,
66  > Traits;
67 
68  };
69 
70  //**********************************************************************
71  //
72  // --IdentityGrid
73  //
74  //************************************************************************
82  template <class HostGrid>
84  : public GridDefaultImplementation<HostGrid::dimension, HostGrid::dimensionworld,
85  typename HostGrid::ctype, IdentityGridFamily<HostGrid::dimension, HostGrid> >
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 
130  explicit IdentityGrid(HostGrid& hostgrid) :
131  hostgrid_(&hostgrid),
132  leafIndexSet_(*this),
133  globalIdSet_(*this),
134  localIdSet_(*this)
135  {
136  setIndices();
137  }
138 
141  {
142  // Delete level index sets
143  for (size_t i=0; i<levelIndexSets_.size(); i++)
144  if (levelIndexSets_[i])
145  delete (levelIndexSets_[i]);
146  }
147 
148 
153  int maxLevel() const {
154  return hostgrid_->maxLevel();
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  {
261  DUNE_THROW(GridError, "levelIndexSet of nonexisting level " << level << " requested!");
262  }
263  return *levelIndexSets_[level];
264  }
265 
266 
268  const typename Traits::LeafIndexSet& leafIndexSet() const
269  {
270  return leafIndexSet_;
271  }
272 
273 
275  template < class EntitySeed >
276  typename Traits::template Codim<EntitySeed::codimension>::Entity
277  entity(const EntitySeed& seed) const
278  {
279  typedef IdentityGridEntity<
281  HostGrid::dimension,
282  const typename Traits::Grid
283  > EntityImp;
284 
285  return EntityImp(this, hostgrid_->entity(seed.impl().hostEntitySeed()));
286  }
287 
288 
291 
292 
296  void globalRefine (int refCount)
297  {
298  hostgrid_->globalRefine(refCount);
299  }
300 
311  bool mark(int refCount, const typename Traits::template Codim<0>::Entity & e)
312  {
313  return hostgrid_->mark(refCount, getHostEntity<0>(e));
314  }
315 
320  int getMark(const typename Traits::template Codim<0>::Entity & e) const
321  {
322  return hostgrid_->getMark(getHostEntity<0>(e));
323  }
324 
326  bool preAdapt() {
327  return hostgrid_->preAdapt();
328  }
329 
330 
332  bool adapt()
333  {
334  return hostgrid_->adapt();
335  }
336 
338  void postAdapt() {
339  return hostgrid_->postAdapt();
340  }
341 
345  unsigned int overlapSize(int codim) const {
346  return hostgrid_->leafGridView().overlapSize(codim);
347  }
348 
349 
351  unsigned int ghostSize(int codim) const {
352  return hostgrid_->leafGridView().ghostSize(codim);
353  }
354 
355 
357  unsigned int overlapSize(int level, int codim) const {
358  return hostgrid_->levelGridView(level).overlapSize(codim);
359  }
360 
361 
363  unsigned int ghostSize(int level, int codim) const {
364  return hostgrid_->levelGridView(level).ghostSize(codim);
365  }
366 
367 
368 #if 0
374  void loadBalance(int strategy, int minlevel, int depth, int maxlevel, int minelement){
375  DUNE_THROW(NotImplemented, "IdentityGrid::loadBalance()");
376  }
377 #endif
378 
379 
382  {
383  return ccobj;
384  }
385 
386 
387  // **********************************************************
388  // End of Interface Methods
389  // **********************************************************
390 
393  {
394  return *hostgrid_;
395  }
396 
397 
399  template <int codim>
400  const typename HostGrid::Traits::template Codim<codim>::Entity& getHostEntity(const typename Traits::template Codim<codim>::Entity& e) const
401  {
402  return e.impl().hostEntity_;
403  }
404 
405  protected:
406 
408  HostGrid* hostgrid_;
409 
410  private:
411 
413  void setIndices()
414  {
415  localIdSet_.update();
416 
417  globalIdSet_.update();
418 
419  // //////////////////////////////////////////
420  // Create the index sets
421  // //////////////////////////////////////////
422  for (int i=levelIndexSets_.size(); i<=maxLevel(); i++) {
425  levelIndexSets_.push_back(p);
426  }
427 
428  for (int i=0; i<=maxLevel(); i++)
429  if (levelIndexSets_[i])
430  levelIndexSets_[i]->update(*this, i);
431 
432  leafIndexSet_.update(*this);
433 
434  }
435 
437  CollectiveCommunication<No_Comm> ccobj;
438 
440  std::vector<IdentityGridLevelIndexSet<const IdentityGrid<HostGrid> >*> levelIndexSets_;
441 
444 
447 
450 
451  }; // end Class IdentityGrid
452 
453 
454 
455 
456  namespace Capabilities
457  {
461  template<class HostGrid, int codim>
462  struct hasEntity<IdentityGrid<HostGrid>, codim>
463  {
464  static const bool v = hasEntity<HostGrid,codim>::v;
465  };
466 
467  template<class HostGrid, int codim>
468  struct hasEntityIterator<IdentityGrid<HostGrid>, codim>
469  {
471  };
472 
476  template<class HostGrid, int codim>
477  struct canCommunicate<IdentityGrid<HostGrid>, codim>
478  {
480  };
481 
485  template<class HostGrid>
487  {
489  };
490 
494  template<class HostGrid>
496  {
498  };
499  } // end namespace Capabilities
500 
501 } // namespace Dune
502 
503 #endif // DUNE_GRID_IDENTITYGRID_HH
The IdentityGridEntity class.
The IdentityGridEntitySeed class.
The IdentityGridGeometry class and its specializations.
The IdentityGridHierarchicIterator class.
The index and id sets for the IdentityGrid class.
The IdentityGridLeafIntersectionIterator and IdentityGridLevelIntersectionIterator classes.
The IdentityGridLeafIterator class.
The IdentityGridLevelIterator class.
Include standard header files.
Definition: agrid.hh:58
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:130
Specialize with 'true' for all codims that a grid implements entities for. (default=false)
Definition: common/capabilities.hh:56
static const bool v
Definition: common/capabilities.hh:57
specialize with 'true' for all codims that a grid provides an iterator for (default=hasEntity<codim>:...
Definition: common/capabilities.hh:72
static const bool v
Definition: common/capabilities.hh:73
specialize with 'true' for all codims that a grid can communicate data on (default=false)
Definition: common/capabilities.hh:95
static const bool v
Definition: common/capabilities.hh:96
Specialize with 'true' if implementation guarantees conforming level grids. (default=false)
Definition: common/capabilities.hh:104
static const bool v
Definition: common/capabilities.hh:105
Specialize with 'true' if implementation guarantees a conforming leaf grid. (default=false)
Definition: common/capabilities.hh:113
static const bool v
Definition: common/capabilities.hh:114
Definition: defaultgridview.hh:24
Definition: defaultgridview.hh:206
Implementation & impl()
access to the underlying implementation
Definition: common/entity.hh:78
Store a reference to an entity with a minimal memory footprint.
Definition: common/entityseed.hh:24
Implementation & impl()
access to the underlying implementation
Definition: common/entityseed.hh:57
@ codimension
Definition: common/entityseed.hh:28
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:18
Definition: common/grid.hh:851
bool loadBalance()
default implementation of load balance does nothing and returns false
Definition: common/grid.hh:937
Index Set Interface base class.
Definition: indexidset.hh:76
auto size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:221
Id Set Interface.
Definition: indexidset.hh:450
GridFamily::Traits::CollectiveCommunication CollectiveCommunication
A type that is a model of Dune::CollectiveCommunication. It provides a portable way for collective co...
Definition: common/grid.hh:518
A Traits struct that collects all associated types of one implementation.
Definition: common/grid.hh:414
GridFamily::Traits::template Codim< cd >::Entity Entity
A type that is a model of a Dune::Entity<cd,dim,...>.
Definition: common/grid.hh:422
A traits struct that collects all associated types of one grid model.
Definition: common/grid.hh:984
GridImp Grid
The type that implements the grid.
Definition: common/grid.hh:986
Provides a meta grid that is identical to its host.
Definition: identitygrid.hh:86
bool mark(int refCount, const typename Traits::template Codim< 0 >::Entity &e)
Mark entity for refinement.
Definition: identitygrid.hh:311
const Traits::LevelIndexSet & levelIndexSet(int level) const
Access to the LevelIndexSets.
Definition: identitygrid.hh:257
IdentityGridFamily< HostGrid::dimension, HostGrid >::Traits Traits
the Traits
Definition: identitygrid.hh:120
int size(int level, int codim) const
Number of grid entities per level and codim.
Definition: identitygrid.hh:215
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 >::template Partition< PiType >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
Definition: identitygrid.hh:173
unsigned int ghostSize(int level, int codim) const
Size of the ghost cell layer on a given level.
Definition: identitygrid.hh:363
HostGrid HostGridType
Definition: identitygrid.hh:110
const CollectiveCommunication< No_Comm > & comm() const
dummy collective communication
Definition: identitygrid.hh:381
void postAdapt()
Clean up refinement markers.
Definition: identitygrid.hh:338
bool adapt()
Triggers the grid refinement process.
Definition: identitygrid.hh:332
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim.
Definition: identitygrid.hh:201
HostGrid * hostgrid_
The host grid which contains the actual grid hierarchy structure.
Definition: identitygrid.hh:408
Traits::template Codim< codim >::LevelIterator lend(int level) const
one past the end on this level
Definition: identitygrid.hh:166
int size(int codim) const
number of leaf entities per codim in this process
Definition: identitygrid.hh:226
const Traits::GlobalIdSet & globalIdSet() const
Access to the GlobalIdSet.
Definition: identitygrid.hh:245
int size(GeometryType type) const
number of leaf entities per codim and geometry type in this process
Definition: identitygrid.hh:238
int maxLevel() const
Return maximum level defined in this grid.
Definition: identitygrid.hh:153
HostGrid::ctype ctype
The type used to store coordinates, inherited from the HostGrid.
Definition: identitygrid.hh:123
Traits::template Codim< codim >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
Definition: identitygrid.hh:159
~IdentityGrid()
Desctructor.
Definition: identitygrid.hh:140
HostGridType & getHostGrid() const
Returns the hostgrid this IdentityGrid lives in.
Definition: identitygrid.hh:392
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
Create Entity from EntitySeed.
Definition: identitygrid.hh:277
size_t numBoundarySegments() const
returns the number of boundary segments within the macro grid
Definition: identitygrid.hh:221
Traits::template Codim< codim >::LeafIterator leafend() const
one past the end of the sequence of leaf entities
Definition: identitygrid.hh:194
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafend() const
one past the end of the sequence of leaf entities
Definition: identitygrid.hh:208
IdentityGridFamily< HostGrid::dimension, HostGrid > GridFamily
type of the used GridFamily for this grid
Definition: identitygrid.hh:117
void globalRefine(int refCount)
Definition: identitygrid.hh:296
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 overlapSize(int codim) const
Size of the overlap on the leaf level.
Definition: identitygrid.hh:345
const Traits::LeafIndexSet & leafIndexSet() const
Access to the LeafIndexSet.
Definition: identitygrid.hh:268
const HostGrid::Traits::template Codim< codim >::Entity & getHostEntity(const typename Traits::template Codim< codim >::Entity &e) const
Returns the hostgrid entity encapsulated in given IdentityGrid entity.
Definition: identitygrid.hh:400
const Traits::LocalIdSet & localIdSet() const
Access to the LocalIdSet.
Definition: identitygrid.hh:251
IdentityGrid(HostGrid &hostgrid)
Constructor.
Definition: identitygrid.hh:130
Traits::template Codim< codim >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim.
Definition: identitygrid.hh:187
unsigned int overlapSize(int level, int codim) const
Size of the overlap on a given level.
Definition: identitygrid.hh:357
bool preAdapt()
returns true, if at least one entity is marked for adaption
Definition: identitygrid.hh:326
unsigned int ghostSize(int codim) const
Size of the ghost cell layer on the leaf level.
Definition: identitygrid.hh:351
int getMark(const typename Traits::template Codim< 0 >::Entity &e) const
Return refinement mark for entity.
Definition: identitygrid.hh:320
provides access to host grid objects from GeometryGrid
Definition: hostgridaccess.hh:27
Definition: identitygrid.hh:39
GridTraits< dim, HostGrid::dimensionworld, Dune::IdentityGrid< HostGrid >, IdentityGridGeometry, IdentityGridEntity, 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< No_Comm >, DefaultLevelGridViewTraits, DefaultLeafGridViewTraits, IdentityGridEntitySeed > Traits
Definition: identitygrid.hh:66
The implementation of entities in a IdentityGrid.
Definition: identitygridentity.hh:53
Iterator over all entities of a given codimension and level of a grid.
Definition: identitygridleveliterator.hh:19
Definition: identitygridintersectioniterator.hh:82
Iterator over all element neighborsMesh entities of codimension 0 ("elements") allow to visit all nei...
Definition: identitygridintersectioniterator.hh:27
Iterator over the descendants of an entity.Mesh entities of codimension 0 ("elements") allow to visit...
Definition: identitygridhierarchiciterator.hh:24
The EntitySeed class provides the minimal information needed to restore an Entity using the grid.
Definition: identitygridentityseed.hh:22
Definition: identitygridgeometry.hh:19
Definition: identitygridindexsets.hh:24
Definition: identitygridindexsets.hh:101
Definition: identitygridindexsets.hh:197
Definition: identitygridindexsets.hh:249
An intersection with a leaf neighbor elementMesh entities of codimension 0 ("elements") allow to visi...
Definition: identitygridintersections.hh:31
Definition: identitygridintersections.hh:190
Iterator over all entities of a given codimension and level of a grid.
Definition: identitygridleafiterator.hh:20
A set of traits classes to store static information about grid implementation.
Different resources needed by all grid implementations.