dune-grid  2.11
identitygrid.hh
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 // vi: set et ts=4 sw=2 sts=2:
5 #ifndef DUNE_GRID_IDENTITYGRID_HH
6 #define DUNE_GRID_IDENTITYGRID_HH
7 
12 #include <string>
13 #include <map>
14 
15 #include <dune/common/parallel/communication.hh>
17 #include <dune/grid/common/grid.hh>
18 
19 // 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  template<int dim, class HostGrid>
41  {
42 
43  public:
44 
45  typedef GridTraits<
46  dim,
47  HostGrid::dimensionworld,
61  typename HostGrid::Traits::GlobalIdSet::IdType,
63  typename HostGrid::Traits::LocalIdSet::IdType,
64  Communication<No_Comm>,
69  typename HostGrid::Traits::LevelIndexSet::IndexType,
70  typename HostGrid::Traits::LevelIndexSet::Types,
71  typename HostGrid::Traits::LeafIndexSet::IndexType,
72  typename HostGrid::Traits::LeafIndexSet::Types
73  > Traits;
74 
75  };
76 
77  //**********************************************************************
78  //
79  // --IdentityGrid
80  //
81  //************************************************************************
89  template <class HostGrid>
90  class IdentityGrid
91  : public GridDefaultImplementation<HostGrid::dimension, HostGrid::dimensionworld,
92  typename HostGrid::ctype, IdentityGridFamily<HostGrid::dimension, HostGrid> >
93  {
94  friend class IdentityGridLevelIndexSet<const IdentityGrid<HostGrid> >;
95  friend class IdentityGridLeafIndexSet<const IdentityGrid<HostGrid> >;
96  friend class IdentityGridGlobalIdSet<const IdentityGrid<HostGrid> >;
97  friend class IdentityGridLocalIdSet<const IdentityGrid<HostGrid> >;
98  friend class IdentityGridHierarchicIterator<const IdentityGrid<HostGrid> >;
99  friend class IdentityGridLevelIntersectionIterator<const IdentityGrid<HostGrid> >;
100  friend class IdentityGridLeafIntersectionIterator<const IdentityGrid<HostGrid> >;
101 
102  template<int codim, PartitionIteratorType pitype, class GridImp_>
104 
105  template<int codim, PartitionIteratorType pitype, class GridImp_>
107 
108 
109  template<int codim_, int dim_, class GridImp_>
110  friend class IdentityGridEntity;
111 
112  friend struct HostGridAccess< IdentityGrid< HostGrid > >;
113 
114  public:
115 
117  typedef HostGrid HostGridType;
118 
119  //**********************************************************
120  // The Interface Methods
121  //**********************************************************
122 
125 
128 
130  typedef typename HostGrid::ctype ctype;
131 
132 
137  explicit IdentityGrid(HostGrid& hostgrid) :
138  hostgrid_(&hostgrid),
139  leafIndexSet_(*this),
140  globalIdSet_(*this),
141  localIdSet_(*this)
142  {
143  setIndices();
144  }
145 
148  {
149  // Delete level index sets
150  for (size_t i=0; i<levelIndexSets_.size(); i++)
151  if (levelIndexSets_[i])
152  delete (levelIndexSets_[i]);
153  }
154 
155 
160  int maxLevel() const {
161  return hostgrid_->maxLevel();
162  }
163 
165  template<int codim>
166  typename Traits::template Codim<codim>::LevelIterator lbegin (int level) const {
168  }
169 
170 
172  template<int codim>
173  typename Traits::template Codim<codim>::LevelIterator lend (int level) const {
175  }
176 
177 
179  template<int codim, PartitionIteratorType PiType>
180  typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lbegin (int level) const {
182  }
183 
184 
186  template<int codim, PartitionIteratorType PiType>
187  typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lend (int level) const {
189  }
190 
191 
193  template<int codim>
194  typename Traits::template Codim<codim>::LeafIterator leafbegin() const {
196  }
197 
198 
200  template<int codim>
201  typename Traits::template Codim<codim>::LeafIterator leafend() const {
203  }
204 
205 
207  template<int codim, PartitionIteratorType PiType>
208  typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafbegin() const {
210  }
211 
212 
214  template<int codim, PartitionIteratorType PiType>
215  typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafend() const {
217  }
218 
219 
222  int size (int level, int codim) const {
223  return hostgrid_->size(level,codim);
224  }
225 
228  size_t numBoundarySegments () const {
229  return hostgrid_->numBoundarySegments();
230  }
231 
233  int size (int codim) const {
234  return leafIndexSet().size(codim);
235  }
236 
237 
239  int size (int level, GeometryType type) const {
240  return levelIndexSets_[level]->size(type);
241  }
242 
243 
245  int size (GeometryType type) const
246  {
247  return leafIndexSet().size(type);
248  }
249 
250 
252  const typename Traits::GlobalIdSet& globalIdSet() const {
253  return globalIdSet_;
254  }
255 
256 
258  const typename Traits::LocalIdSet& localIdSet() const {
259  return localIdSet_;
260  }
261 
262 
264  const typename Traits::LevelIndexSet& levelIndexSet(int level) const
265  {
266  if (level < 0 || level > maxLevel())
267  {
268  DUNE_THROW(GridError, "levelIndexSet of nonexisting level " << level << " requested!");
269  }
270  return *levelIndexSets_[level];
271  }
272 
273 
275  const typename Traits::LeafIndexSet& leafIndexSet() const
276  {
277  return leafIndexSet_;
278  }
279 
280 
282  template < class EntitySeed >
283  typename Traits::template Codim<EntitySeed::codimension>::Entity
284  entity(const EntitySeed& seed) const
285  {
286  typedef IdentityGridEntity<
288  HostGrid::dimension,
289  const typename Traits::Grid
290  > EntityImp;
291 
292  return EntityImp(this, hostgrid_->entity(seed.impl().hostEntitySeed()));
293  }
294 
295 
298 
299 
303  void globalRefine (int refCount)
304  {
305  hostgrid_->globalRefine(refCount);
306  }
307 
318  bool mark(int refCount, const typename Traits::template Codim<0>::Entity & e)
319  {
320  return hostgrid_->mark(refCount, getHostEntity<0>(e));
321  }
322 
327  int getMark(const typename Traits::template Codim<0>::Entity & e) const
328  {
329  return hostgrid_->getMark(getHostEntity<0>(e));
330  }
331 
333  bool preAdapt() {
334  return hostgrid_->preAdapt();
335  }
336 
337 
339  bool adapt()
340  {
341  return hostgrid_->adapt();
342  }
343 
345  void postAdapt() {
346  return hostgrid_->postAdapt();
347  }
348 
352  unsigned int overlapSize(int codim) const {
353  return hostgrid_->leafGridView().overlapSize(codim);
354  }
355 
356 
358  unsigned int ghostSize(int codim) const {
359  return hostgrid_->leafGridView().ghostSize(codim);
360  }
361 
362 
364  unsigned int overlapSize(int level, int codim) const {
365  return hostgrid_->levelGridView(level).overlapSize(codim);
366  }
367 
368 
370  unsigned int ghostSize(int level, int codim) const {
371  return hostgrid_->levelGridView(level).ghostSize(codim);
372  }
373 
374 
375 #if 0
376 
381  void loadBalance(int strategy, int minlevel, int depth, int maxlevel, int minelement){
382  DUNE_THROW(NotImplemented, "IdentityGrid::loadBalance()");
383  }
384 #endif
385 
386 
388  const Communication<No_Comm>& comm () const
389  {
390  return ccobj;
391  }
392 
394  template <class DataHandle>
395  void communicate (DataHandle& handle, InterfaceType iftype,
396  CommunicationDirection dir, int level) const
397  {
398  hostgrid_->levelGridView(level).communicate(handle,iftype,dir);
399  }
400 
402  template <class DataHandle>
403  void communicate (DataHandle& handle, InterfaceType iftype,
404  CommunicationDirection dir) const
405  {
406  hostgrid_->leafGridView().communicate(handle,iftype,dir);
407  }
408 
409 
410  // **********************************************************
411  // End of Interface Methods
412  // **********************************************************
413 
416  {
417  return *hostgrid_;
418  }
419 
420 
422  template <int codim>
423  const typename HostGrid::Traits::template Codim<codim>::Entity& getHostEntity(const typename Traits::template Codim<codim>::Entity& e) const
424  {
425  return e.impl().hostEntity_;
426  }
427 
428  protected:
429 
431  HostGrid* hostgrid_;
432 
433  private:
434 
436  void setIndices()
437  {
438  localIdSet_.update();
439 
440  globalIdSet_.update();
441 
442  // //////////////////////////////////////////
443  // Create the index sets
444  // //////////////////////////////////////////
445  for (int i=levelIndexSets_.size(); i<=maxLevel(); i++) {
448  levelIndexSets_.push_back(p);
449  }
450 
451  for (int i=0; i<=maxLevel(); i++)
452  if (levelIndexSets_[i])
453  levelIndexSets_[i]->update(*this, i);
454 
455  leafIndexSet_.update(*this);
456 
457  }
458 
460  Communication<No_Comm> ccobj;
461 
463  std::vector<IdentityGridLevelIndexSet<const IdentityGrid<HostGrid> >*> levelIndexSets_;
464 
467 
470 
473 
474  }; // end Class IdentityGrid
475 
476 
477 
478 
479  namespace Capabilities
480  {
484  template<class HostGrid, int codim>
485  struct hasEntity<IdentityGrid<HostGrid>, codim>
486  {
487  static const bool v = hasEntity<HostGrid,codim>::v;
488  };
489 
490  template<class HostGrid, int codim>
491  struct hasEntityIterator<IdentityGrid<HostGrid>, codim>
492  {
494  };
495 
499  template<class HostGrid, int codim>
500  struct canCommunicate<IdentityGrid<HostGrid>, codim>
501  {
503  };
504 
508  template<class HostGrid>
510  {
512  };
513 
517  template<class HostGrid>
519  {
521  };
522  } // end namespace Capabilities
523 
524 } // namespace Dune
525 
526 #endif // DUNE_GRID_IDENTITYGRID_HH
Definition: identitygridindexsets.hh:234
Definition: identitygridindexsets.hh:20
Store a reference to an entity with a minimal memory footprint.
Definition: common/entityseed.hh:25
HostGrid::ctype ctype
The type used to store coordinates, inherited from the HostGrid.
Definition: identitygrid.hh:130
A Traits struct that collects all associated types of one implementation.
Definition: common/grid.hh:410
auto size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: common/indexidset.hh:223
typename GridFamily::Traits::Communication Communication
A type that is a model of Dune::Communication. It provides a portable way for communication on the se...
Definition: common/grid.hh:515
Index Set Interface base class.
Definition: common/grid.hh:348
void communicate(DataHandle &handle, InterfaceType iftype, CommunicationDirection dir, int level) const
Communicate data of level gridView.
Definition: identitygrid.hh:395
Definition: identitygridindexsets.hh:182
static const bool v
Definition: common/capabilities.hh:98
unsigned int overlapSize(int codim) const
Size of the overlap on the leaf level.
Definition: identitygrid.hh:352
unsigned int overlapSize(int level, int codim) const
Size of the overlap on a given level.
Definition: identitygrid.hh:364
Implementation & impl()
access to the underlying implementation
Definition: common/entity.hh:80
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
Create Entity from EntitySeed.
Definition: identitygrid.hh:284
bool loadBalance()
default implementation of load balance does nothing and returns false
Definition: common/grid.hh:962
Definition: defaultgridview.hh:25
bool mark(int refCount, const typename Traits::template Codim< 0 >::Entity &e)
Mark entity for refinement.
Definition: identitygrid.hh:318
An intersection with a leaf neighbor elementMesh entities of codimension 0 ("elements") allow to visi...
Definition: identitygridintersections.hh:32
static const bool v
Definition: common/capabilities.hh:116
int maxLevel() const
Return maximum level defined in this grid.
Definition: identitygrid.hh:160
Traits::template Codim< codim >::template Partition< PiType >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
Definition: identitygrid.hh:180
Specialize with &#39;true&#39; for all codims that a grid implements entities for. (default=false) ...
Definition: common/capabilities.hh:57
bool preAdapt()
returns true, if at least one entity is marked for adaption
Definition: identitygrid.hh:333
The IdentityGridLeafIterator class.
Provides a meta grid that is identical to its host.
Definition: identitygrid.hh:33
The IdentityGridHierarchicIterator class.
IdentityGridFamily< HostGrid::dimension, HostGrid > GridFamily
type of the used GridFamily for this grid
Definition: identitygrid.hh:124
int size(int codim) const
number of leaf entities per codim in this process
Definition: identitygrid.hh:233
const Traits::LeafIndexSet & leafIndexSet() const
Access to the LeafIndexSet.
Definition: identitygrid.hh:275
Different resources needed by all grid implementations.
void globalRefine(int refCount)
Definition: identitygrid.hh:303
IdentityGridFamily< HostGrid::dimension, HostGrid >::Traits Traits
the Traits
Definition: identitygrid.hh:127
Specialize with &#39;true&#39; if implementation guarantees a conforming leaf grid. (default=false) ...
Definition: common/capabilities.hh:114
const Traits::LevelIndexSet & levelIndexSet(int level) const
Access to the LevelIndexSets.
Definition: identitygrid.hh:264
const Communication< No_Comm > & comm() const
dummy communication
Definition: identitygrid.hh:388
Traits::template Codim< codim >::template Partition< PiType >::LevelIterator lend(int level) const
one past the end on this level
Definition: identitygrid.hh:187
HostGrid * hostgrid_
The host grid which contains the actual grid hierarchy structure.
Definition: identitygrid.hh:431
Traits::template Codim< codim >::LeafIterator leafend() const
one past the end of the sequence of leaf entities
Definition: identitygrid.hh:201
~IdentityGrid()
Destructor.
Definition: identitygrid.hh:147
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:170
Iterator over all entities of a given codimension and level of a grid.
Definition: identitygridleafiterator.hh:21
Definition: identitygridentity.hh:26
The IdentityGridLevelIterator class.
The index and id sets for the IdentityGrid class.
unsigned int ghostSize(int codim) const
Size of the ghost cell layer on the leaf level.
Definition: identitygrid.hh:358
HostGridType & getHostGrid() const
Returns the hostgrid this IdentityGrid lives in.
Definition: identitygrid.hh:415
The IdentityGridEntity class.
Traits::template Codim< codim >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim.
Definition: identitygrid.hh:194
Definition: defaultgridview.hh:211
Definition: identitygrid.hh:40
Definition: common/geometry.hh:28
int size(GeometryType type) const
number of leaf entities per codim and geometry type in this process
Definition: identitygrid.hh:245
Definition: identitygridgeometry.hh:19
const Traits::GlobalIdSet & globalIdSet() const
Access to the GlobalIdSet.
Definition: identitygrid.hh:252
The IdentityGridLeafIntersectionIterator and IdentityGridLevelIntersectionIterator classes...
Include standard header files.
Definition: agrid.hh:59
Definition: identitygridintersections.hh:191
The IdentityGridEntitySeed class.
static const bool v
Definition: common/capabilities.hh:75
static constexpr int codimension
codimension of underlying entity
Definition: common/entityseed.hh:30
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:86
Specialize with &#39;true&#39; if implementation guarantees conforming level grids. (default=false) ...
Definition: common/capabilities.hh:105
static const bool v
Definition: common/capabilities.hh:107
The IdentityGridGeometry class and its specializations.
specialize with &#39;true&#39; for all codims that a grid provides an iterator for (default=hasEntity<codim>:...
Definition: common/capabilities.hh:73
A traits struct that collects all associated types of one grid model.
Definition: common/grid.hh:1012
Traits::template Codim< codim >::LevelIterator lend(int level) const
one past the end on this level
Definition: identitygrid.hh:173
Traits::template Codim< codim >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
Definition: identitygrid.hh:166
provides access to host grid objects from GeometryGrid
Definition: identitygrid.hh:37
static const bool v
Definition: common/capabilities.hh:59
int size(int level, GeometryType type) const
number of entities per level, codim and geometry type in this process
Definition: identitygrid.hh:239
const Traits::LocalIdSet & localIdSet() const
Access to the LocalIdSet.
Definition: identitygrid.hh:258
Iterator over the descendants of an entity.Mesh entities of codimension 0 ("elements") allow to visit...
Definition: identitygridentity.hh:32
Iterator over all entities of a given codimension and level of a grid.
Definition: identitygridentity.hh:23
specialize with &#39;true&#39; for all codims that a grid can communicate data on (default=false) ...
Definition: common/capabilities.hh:96
int getMark(const typename Traits::template Codim< 0 >::Entity &e) const
Return refinement mark for entity.
Definition: identitygrid.hh:327
GeometryType
Type representing VTK&#39;s entity geometry types.
Definition: common.hh:132
GridImp Grid
The type that implements the grid.
Definition: common/grid.hh:1015
Implementation & impl()
access to the underlying implementation
Definition: common/entityseed.hh:59
Definition: identitygridindexsets.hh:90
HostGrid HostGridType
Definition: identitygrid.hh:117
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:18
void communicate(DataHandle &handle, InterfaceType iftype, CommunicationDirection dir) const
Communicate data of leaf gridView.
Definition: identitygrid.hh:403
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafend() const
one past the end of the sequence of leaf entities
Definition: identitygrid.hh:215
A set of traits classes to store static information about grid implementation.
The EntitySeed class provides the minimal information needed to restore an Entity using the grid...
Definition: identitygridentityseed.hh:23
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim.
Definition: identitygrid.hh:208
GridFamily::Traits::template Codim< cd >::Entity Entity
A type that is a model of a Dune::Entity<cd,dim,...>.
Definition: common/grid.hh:419
Iterator over all element neighborsMesh entities of codimension 0 ("elements") allow to visit all nei...
Definition: identitygridentity.hh:29
void postAdapt()
Clean up refinement markers.
Definition: identitygrid.hh:345
size_t numBoundarySegments() const
returns the number of boundary segments within the macro grid
Definition: identitygrid.hh:228
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:20
bool adapt()
Triggers the grid refinement process.
Definition: identitygrid.hh:339
Id Set Interface.
Definition: common/grid.hh:349
unsigned int ghostSize(int level, int codim) const
Size of the ghost cell layer on a given level.
Definition: identitygrid.hh:370
int size(int level, int codim) const
Number of grid entities per level and codim.
Definition: identitygrid.hh:222
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:423
IdentityGrid(HostGrid &hostgrid)
Constructor.
Definition: identitygrid.hh:137
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, Communication< No_Comm >, DefaultLevelGridViewTraits, DefaultLeafGridViewTraits, IdentityGridEntitySeed, IdentityGridGeometry, typename HostGrid::Traits::LevelIndexSet::IndexType, typename HostGrid::Traits::LevelIndexSet::Types, typename HostGrid::Traits::LeafIndexSet::IndexType, typename HostGrid::Traits::LeafIndexSet::Types > Traits
Definition: identitygrid.hh:73