dune-grid  2.4.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_GRID_IDENTITYGRID_HH
4 #define DUNE_GRID_IDENTITYGRID_HH
5 
10 #include <string>
11 #include <map>
12 
13 #include <dune/common/deprecated.hh>
14 #include <dune/common/parallel/collectivecommunication.hh>
16 #include <dune/grid/common/grid.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  // External forward declarations
36  template< class Grid >
38 
39  namespace {
40 
41  // This is just a placeholder to stuff into the standard
42  // GridTraits, as those expect an EntityPointer implementation
43  // with two template parameters, but our EntityPointer uses three.
44  template<int,typename>
45  struct DummyIdentityGridEntityPointer
46  {};
47 
48  }
49 
50 
51  template<int dim, class HostGrid>
53  {
54 
55  private:
56 
57  // The type signature of our EntityPointer implementation does not fit into
58  // the scheme expected by GridTraits, so we have to provide our own Traits
59  // On the other hand, we don't want to retype everything, so we just inherit
60  // from the default Traits and just tweak the EntityPointer type in the derived
61  // Traits class
62 
63  typedef GridTraits<
64  dim,
65  HostGrid::dimensionworld,
69  DummyIdentityGridEntityPointer, // placeholder
80  typename HostGrid::Traits::GlobalIdSet::IdType,
82  typename HostGrid::Traits::LocalIdSet::IdType,
83  CollectiveCommunication<IdentityGrid<HostGrid> >,
87  > BaseTraits;
88 
89  public:
90 
91  // inherit everyting from the default Traits...
92  struct Traits
93  : public BaseTraits
94  {
95 
96  // Except for the Codim struct, which we reimplement, but which
97  // again inherits everything from the base class...
98  template<int codim>
99  struct Codim
100  : public BaseTraits::template Codim<codim>
101  {
102 
103  // ... except for the EntityPointer, which we override with our
104  // actual implementation
105  typedef Dune::EntityPointer<
106  const typename BaseTraits::Grid,
108  codim,
109  const typename BaseTraits::Grid,
110  typename HostGrid::template Codim<codim>::EntityPointer
111  >
113 
114  };
115 
116  };
117 
118  };
119 
120  //**********************************************************************
121  //
122  // --IdentityGrid
123  //
124  //************************************************************************
132  template <class HostGrid>
133  class IdentityGrid
134  : public GridDefaultImplementation<HostGrid::dimension, HostGrid::dimensionworld,
135  typename HostGrid::ctype, IdentityGridFamily<HostGrid::dimension, HostGrid> >
136  {
137  friend class IdentityGridLevelIndexSet<const IdentityGrid<HostGrid> >;
138  friend class IdentityGridLeafIndexSet<const IdentityGrid<HostGrid> >;
139  friend class IdentityGridGlobalIdSet<const IdentityGrid<HostGrid> >;
140  friend class IdentityGridLocalIdSet<const IdentityGrid<HostGrid> >;
141  friend class IdentityGridHierarchicIterator<const IdentityGrid<HostGrid> >;
142  friend class IdentityGridLevelIntersectionIterator<const IdentityGrid<HostGrid> >;
143  friend class IdentityGridLeafIntersectionIterator<const IdentityGrid<HostGrid> >;
144 
145  template<int codim, PartitionIteratorType pitype, class GridImp_>
147 
148  template<int codim, PartitionIteratorType pitype, class GridImp_>
150 
151 
152  template<int codim_, int dim_, class GridImp_>
153  friend class IdentityGridEntity;
154 
155  friend struct HostGridAccess< IdentityGrid< HostGrid > >;
156 
157  public:
158 
160  typedef HostGrid HostGridType;
161 
162  //**********************************************************
163  // The Interface Methods
164  //**********************************************************
165 
168 
171 
173  typedef typename HostGrid::ctype ctype;
174 
175 
180  explicit IdentityGrid(HostGrid& hostgrid) :
181  hostgrid_(&hostgrid),
182  leafIndexSet_(*this),
183  globalIdSet_(*this),
184  localIdSet_(*this)
185  {
186  setIndices();
187  }
188 
191  {
192  // Delete level index sets
193  for (size_t i=0; i<levelIndexSets_.size(); i++)
194  if (levelIndexSets_[i])
195  delete (levelIndexSets_[i]);
196  }
197 
198 
203  int maxLevel() const {
204  return hostgrid_->maxLevel();
205  }
206 
208  template<int codim>
209  typename Traits::template Codim<codim>::LevelIterator lbegin (int level) const {
211  }
212 
213 
215  template<int codim>
216  typename Traits::template Codim<codim>::LevelIterator lend (int level) const {
218  }
219 
220 
222  template<int codim, PartitionIteratorType PiType>
223  typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lbegin (int level) const {
225  }
226 
227 
229  template<int codim, PartitionIteratorType PiType>
230  typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lend (int level) const {
232  }
233 
234 
236  template<int codim>
237  typename Traits::template Codim<codim>::LeafIterator leafbegin() const {
239  }
240 
241 
243  template<int codim>
244  typename Traits::template Codim<codim>::LeafIterator leafend() const {
246  }
247 
248 
250  template<int codim, PartitionIteratorType PiType>
253  }
254 
255 
257  template<int codim, PartitionIteratorType PiType>
260  }
261 
262 
265  int size (int level, int codim) const {
266  return hostgrid_->size(level,codim);
267  }
268 
271  size_t numBoundarySegments () const {
272  return hostgrid_->numBoundarySegments();
273  }
274 
276  int size (int codim) const {
277  return leafIndexSet().size(codim);
278  }
279 
280 
282  int size (int level, GeometryType type) const {
283  return levelIndexSets_[level]->size(type);
284  }
285 
286 
288  int size (GeometryType type) const
289  {
290  return leafIndexSet().size(type);
291  }
292 
293 
295  const typename Traits::GlobalIdSet& globalIdSet() const {
296  return globalIdSet_;
297  }
298 
299 
301  const typename Traits::LocalIdSet& localIdSet() const {
302  return localIdSet_;
303  }
304 
305 
307  const typename Traits::LevelIndexSet& levelIndexSet(int level) const
308  {
309  if (level < 0 || level > maxLevel())
310  {
311  DUNE_THROW(GridError, "levelIndexSet of nonexisting level " << level << " requested!");
312  }
313  return *levelIndexSets_[level];
314  }
315 
316 
318  const typename Traits::LeafIndexSet& leafIndexSet() const
319  {
320  return leafIndexSet_;
321  }
322 
323 
332  template < class EntitySeed >
333  DUNE_DEPRECATED_MSG("entityPointer() is deprecated and will be removed after the release of dune-grid 2.4. Use entity() instead to directly obtain an Entity object.")
334  typename Traits::template Codim<EntitySeed::codimension>::EntityPointer
335  entityPointer(const EntitySeed& seed) const
336  {
337  typedef typename Traits::template Codim<EntitySeed::codimension>::EntityPointer EntityPointer;
340  const typename Traits::Grid,
341  typename HostGrid::template Codim<EntitySeed::codimension>::EntityPointer
342  > EntityPointerImp;
343 
344  return EntityPointer(EntityPointerImp(this, hostgrid_->entity(this->getRealImplementation(seed).hostEntitySeed())));
345  }
346 
348  template < class EntitySeed >
349  typename Traits::template Codim<EntitySeed::codimension>::Entity
350  entity(const EntitySeed& seed) const
351  {
352  typedef IdentityGridEntity<
354  HostGrid::dimension,
355  const typename Traits::Grid
356  > EntityImp;
357 
358  return EntityImp(this, hostgrid_->entity(this->getRealImplementation(seed).hostEntitySeed()));
359  }
360 
361 
364 
365 
369  void globalRefine (int refCount)
370  {
371  hostgrid_->globalRefine(refCount);
372  }
373 
384  bool mark(int refCount, const typename Traits::template Codim<0>::Entity & e)
385  {
386  return hostgrid_->mark(refCount, getHostEntity<0>(e));
387  }
388 
393  int getMark(const typename Traits::template Codim<0>::Entity & e) const
394  {
395  return hostgrid_->getMark(getHostEntity<0>(e));
396  }
397 
399  bool preAdapt() {
400  return hostgrid_->preAdapt();
401  }
402 
403 
405  bool adapt()
406  {
407  return hostgrid_->adapt();
408  }
409 
411  void postAdapt() {
412  return hostgrid_->postAdapt();
413  }
414 
418  unsigned int overlapSize(int codim) const {
419  return hostgrid_->overlapSize(codim);
420  }
421 
422 
424  unsigned int ghostSize(int codim) const {
425  return hostgrid_->ghostSize(codim);
426  }
427 
428 
430  unsigned int overlapSize(int level, int codim) const {
431  return hostgrid_->overlapSize(level,codim);
432  }
433 
434 
436  unsigned int ghostSize(int level, int codim) const {
437  return hostgrid_->ghostSize(level,codim);
438  }
439 
440 
441 #if 0
442 
447  void loadBalance(int strategy, int minlevel, int depth, int maxlevel, int minelement){
448  DUNE_THROW(NotImplemented, "IdentityGrid::loadBalance()");
449  }
450 
462  template<class T, template<class> class P, int codim>
463  void communicate (T& t, InterfaceType iftype, CommunicationDirection dir, int level);
464 
469  template<class DataHandle>
470  void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir, int level) const
471  {}
472 
473  template<class DataHandle>
474  void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir) const
475  {}
476 #endif
477 
478 
481  {
482  return ccobj;
483  }
484 
485 
486  // **********************************************************
487  // End of Interface Methods
488  // **********************************************************
489 
491  HostGridType& getHostGrid() const
492  {
493  return *hostgrid_;
494  }
495 
496 
498  template <int codim>
499  DUNE_DEPRECATED_MSG("getHostEntityPointer() is deprecated and will be removed after the release of dune-grid 2.4. Use getHostEntity() instead to obtain a reference to the host entity object.")
500  typename HostGrid::Traits::template Codim<codim>::EntityPointer getHostEntityPointer(const typename Traits::template Codim<codim>::Entity& e) const
501  {
502  return this->getRealImplementation(e).hostEntity_;
503  }
504 
505  template <int codim>
506  const typename HostGrid::Traits::template Codim<codim>::Entity& getHostEntity(const typename Traits::template Codim<codim>::Entity& e) const
507  {
508  return this->getRealImplementation(e).hostEntity_;
509  }
510 
511  protected:
512 
514  HostGrid* hostgrid_;
515 
516  private:
517 
519  void setIndices()
520  {
521  localIdSet_.update();
522 
523  globalIdSet_.update();
524 
525  // //////////////////////////////////////////
526  // Create the index sets
527  // //////////////////////////////////////////
528  for (int i=levelIndexSets_.size(); i<=maxLevel(); i++) {
531  levelIndexSets_.push_back(p);
532  }
533 
534  for (int i=0; i<=maxLevel(); i++)
535  if (levelIndexSets_[i])
536  levelIndexSets_[i]->update(*this, i);
537 
538  leafIndexSet_.update(*this);
539 
540  }
541 
543  CollectiveCommunication<IdentityGrid> ccobj;
544 
546  std::vector<IdentityGridLevelIndexSet<const IdentityGrid<HostGrid> >*> levelIndexSets_;
547 
550 
553 
556 
557  }; // end Class IdentityGrid
558 
559 
560 
561 
562  namespace Capabilities
563  {
567  template<class HostGrid, int codim>
568  struct hasEntity<IdentityGrid<HostGrid>, codim>
569  {
570  static const bool v = hasEntity<HostGrid,codim>::v;
571  };
572 
576  template<class HostGrid>
577  struct DUNE_DEPRECATED_MSG("Capabilities::isParallel will be removed after dune-grid-2.4.") isParallel<IdentityGrid<HostGrid> >
578  {
579  static const bool DUNE_DEPRECATED_MSG("Capabilities::isParallel will be removed after dune-grid-2.4.") v = isParallel<HostGrid>::v;
580  };
581 
585  template<class HostGrid>
587  {
588  static const bool v = isLevelwiseConforming<HostGrid>::v;
589  };
590 
594  template<class HostGrid>
596  {
597  static const bool v = isLeafwiseConforming<HostGrid>::v;
598  };
599  } // end namespace Capabilities
600 
601 } // namespace Dune
602 
603 #endif // DUNE_GRID_IDENTITYGRID_HH
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafend() const
one past the end of the sequence of leaf entities
Definition: identitygrid.hh:258
Definition: identitygridindexsets.hh:194
The IdentityGridEntitySeed class.
int getMark(const typename Traits::template Codim< 0 >::Entity &e) const
Return refinement mark for entity.
Definition: identitygrid.hh:393
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:168
int size(GeometryType type) const
number of leaf entities per codim and geometry type in this process
Definition: identitygrid.hh:288
Index Set Interface base class.
Definition: common/grid.hh:361
Definition: common/entityseed.hh:28
Traits::template Codim< codim >::template Partition< PiType >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
Definition: identitygrid.hh:223
An intersection with a leaf neighbor elementMesh entities of codimension 0 ("elements") allow to visi...
Definition: identitygridintersections.hh:29
Store a reference to an entity with a minimal memory footprint.
Definition: common/entityseed.hh:23
The index and id sets for the IdentityGrid class.
size_t numBoundarySegments() const
returns the number of boundary segments within the macro grid
Definition: identitygrid.hh:271
Definition: identitygridentity.hh:27
int size(int level, GeometryType type) const
number of entities per level, codim and geometry type in this process
Definition: identitygrid.hh:282
Definition: identitygridentity.hh:21
The IdentityGridLeafIterator class.
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
Types for GridView.
Definition: common/grid.hh:420
int size(int codim) const
number of leaf entities per codim in this process
Definition: identitygrid.hh:276
Wrapper class for entities.
Definition: common/entity.hh:61
IdentityGridFamily< HostGrid::dimension, HostGrid > GridFamily
type of the used GridFamily for this grid
Definition: identitygrid.hh:167
Specialize with 'true' if implementation supports parallelism. (default=false)
Definition: common/capabilities.hh:68
void postAdapt()
Clean up refinement markers.
Definition: identitygrid.hh:411
Specialize with 'true' if implementation guarantees conforming level grids. (default=false) ...
Definition: common/capabilities.hh:98
The IdentityGridEntityPointer class.
IdentityGridFamily< HostGrid::dimension, HostGrid >::Traits Traits
the Traits
Definition: identitygrid.hh:170
Traits::template Codim< codim >::LeafIterator leafend() const
one past the end of the sequence of leaf entities
Definition: identitygrid.hh:244
static std::conditional< std::is_reference< InterfaceType >::value, typename std::add_lvalue_reference< typename ReturnImplementationType< typename std::remove_reference< InterfaceType >::type >::ImplementationType >::type, typename std::remove_const< typename ReturnImplementationType< typename std::remove_reference< InterfaceType >::type >::ImplementationType >::type >::type getRealImplementation(InterfaceType &&i)
return real implementation of interface class
Definition: common/grid.hh:1305
provides access to host grid objects from GeometryGrid
Definition: identitygrid.hh:37
unsigned int overlapSize(int level, int codim) const
Size of the overlap on a given level.
Definition: identitygrid.hh:430
Wrapper class for pointers to entities.
Definition: common/entitypointer.hh:112
int size(int level, int codim) const
Number of grid entities per level and codim.
Definition: identitygrid.hh:265
Specialize with 'true' if implementation guarantees a conforming leaf grid. (default=false) ...
Definition: common/capabilities.hh:107
const Traits::LocalIdSet & localIdSet() const
Access to the LocalIdSet.
Definition: identitygrid.hh:301
Id Set Interface.
Definition: common/grid.hh:362
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim.
Definition: identitygrid.hh:251
The IdentityGridLevelIterator class and its specializations.
Definition: identitygridgeometry.hh:17
Traits::template Codim< EntitySeed::codimension >::EntityPointer entityPointer(const EntitySeed &seed) const
Create EntityPointer from EntitySeed.
Definition: identitygrid.hh:335
Definition: identitygrid.hh:92
unsigned int overlapSize(int codim) const
Size of the overlap on the leaf level.
Definition: identitygrid.hh:418
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:16
Definition: identitygridindexsets.hh:95
Specialize with 'true' for all codims that a grid implements entities for. (default=false) ...
Definition: common/capabilities.hh:57
The IdentityGridHierarchicIterator class.
~IdentityGrid()
Desctructor.
Definition: identitygrid.hh:190
Different resources needed by all grid implementations.
Definition: identitygridintersections.hh:195
Iterator over all entities of a given codimension and level of a grid.
Definition: identitygridleafiterator.hh:19
Definition: defaultgridview.hh:23
const HostGrid::Traits::template Codim< codim >::Entity & getHostEntity(const typename Traits::template Codim< codim >::Entity &e) const
Definition: identitygrid.hh:506
Provides a meta grid that is identical to its host.
Definition: identitygrid.hh:33
void communicate(CommDataHandleIF< DataHandleImp, DataTypeImp > &data, InterfaceType iftype, CommunicationDirection dir, int level) const
Definition: common/grid.hh:1209
HostGrid::ctype ctype
The type used to store coordinates, inherited from the HostGrid.
Definition: identitygrid.hh:173
static const bool v
Definition: common/capabilities.hh:59
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:84
Definition: identitygridindexsets.hh:246
Definition: identitygrid.hh:52
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:500
The IdentityGridEntity class.
unsigned int ghostSize(int level, int codim) const
Size of the ghost cell layer on a given level.
Definition: identitygrid.hh:436
bool preAdapt()
returns true, if at least one entity is marked for adaption
Definition: identitygrid.hh:399
int maxLevel() const
Return maximum level defined in this grid.
Definition: identitygrid.hh:203
A traits struct that collects all associated types of one grid model.
Definition: common/grid.hh:1343
const Traits::GlobalIdSet & globalIdSet() const
Access to the GlobalIdSet.
Definition: identitygrid.hh:295
IdentityGrid(HostGrid &hostgrid)
Constructor.
Definition: identitygrid.hh:180
Definition: common/geometry.hh:24
void globalRefine(int refCount)
Definition: identitygrid.hh:369
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
Create Entity from EntitySeed.
Definition: identitygrid.hh:350
The IdentityGridGeometry class and its specializations.
Definition: identitygridindexsets.hh:18
Iterator over all element neighborsMesh entities of codimension 0 ("elements") allow to visit all nei...
Definition: identitygridentity.hh:30
GridImp Grid
The type that implements the grid.
Definition: common/grid.hh:1346
The IdentityGridLeafIntersectionIterator and IdentityGridLevelIntersectionIterator classes...
const CollectiveCommunication< IdentityGrid > & comm() const
dummy collective communication
Definition: identitygrid.hh:480
Dune::EntityPointer< const typename BaseTraits::Grid, IdentityGridEntityPointer< codim, const typename BaseTraits::Grid, typename HostGrid::template Codim< codim >::EntityPointer > > EntityPointer
Definition: identitygrid.hh:112
bool adapt()
Triggers the grid refinement process.
Definition: identitygrid.hh:405
bool mark(int refCount, const typename Traits::template Codim< 0 >::Entity &e)
Mark entity for refinement.
Definition: identitygrid.hh:384
bool loadBalance()
default implementation of load balance does nothing and returns false
Definition: common/grid.hh:1220
HostGrid * hostgrid_
The host grid which contains the actual grid hierarchy structure.
Definition: identitygrid.hh:514
Iterator over the descendants of an entity.Mesh entities of codimension 0 ("elements") allow to visit...
Definition: identitygridentity.hh:33
Definition: identitygrid.hh:99
unsigned int ghostSize(int codim) const
Size of the ghost cell layer on the leaf level.
Definition: identitygrid.hh:424
Traits::template Codim< codim >::template Partition< PiType >::LevelIterator lend(int level) const
one past the end on this level
Definition: identitygrid.hh:230
HostGrid HostGridType
Definition: identitygrid.hh:160
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:545
HostGridType & getHostGrid() const
Returns the hostgrid this IdentityGrid lives in.
Definition: identitygrid.hh:491
const Traits::LeafIndexSet & leafIndexSet() const
Access to the LeafIndexSet.
Definition: identitygrid.hh:318
Definition: defaultgridview.hh:223
Traits::template Codim< codim >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
Definition: identitygrid.hh:209
Include standard header files.
Definition: agrid.hh:59
A Traits struct that collects all associated types of one implementation.
Definition: common/grid.hh:437
Iterator over all entities of a given codimension and level of a grid.
Definition: identitygridentity.hh:24
IndexType size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:232
Traits::template Codim< codim >::LevelIterator lend(int level) const
one past the end on this level
Definition: identitygrid.hh:216
The EntitySeed class provides the minimal information needed to restore an Entity using the grid...
Definition: identitygridentityseed.hh:21
Traits::template Codim< codim >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim.
Definition: identitygrid.hh:237
A set of traits classes to store static information about grid implementation.
const Traits::LevelIndexSet & levelIndexSet(int level) const
Access to the LevelIndexSets.
Definition: identitygrid.hh:307
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178