Dune Core Modules (unstable)

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 
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 >
37  struct HostGridAccess;
38 
39  template<int dim, class HostGrid>
40  struct IdentityGridFamily
41  {
42 
43  public:
44 
45  typedef GridTraits<
46  dim,
47  HostGrid::dimensionworld,
49  IdentityGridGeometry,
50  IdentityGridEntity,
51  IdentityGridLevelIterator,
52  IdentityGridLeafIntersection,
53  IdentityGridLevelIntersection,
54  IdentityGridLeafIntersectionIterator,
55  IdentityGridLevelIntersectionIterator,
56  IdentityGridHierarchicIterator,
57  IdentityGridLeafIterator,
58  IdentityGridLevelIndexSet< const IdentityGrid<HostGrid> >,
59  IdentityGridLeafIndexSet< const IdentityGrid<HostGrid> >,
60  IdentityGridGlobalIdSet< const IdentityGrid<HostGrid> >,
61  typename HostGrid::Traits::GlobalIdSet::IdType,
62  IdentityGridLocalIdSet< const IdentityGrid<HostGrid> >,
63  typename HostGrid::Traits::LocalIdSet::IdType,
64  Communication<No_Comm>,
65  DefaultLevelGridViewTraits,
66  DefaultLeafGridViewTraits,
67  IdentityGridEntitySeed,
68  IdentityGridGeometry,
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>
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_>
103  friend class IdentityGridLevelIterator;
104 
105  template<int codim, PartitionIteratorType pitype, class GridImp_>
106  friend class IdentityGridLeafIterator;
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 
124  typedef IdentityGridFamily<HostGrid::dimension,HostGrid> GridFamily;
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
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 
461 
463  std::vector<IdentityGridLevelIndexSet<const IdentityGrid<HostGrid> >*> levelIndexSets_;
464 
466  IdentityGridLeafIndexSet<const IdentityGrid<HostGrid> > leafIndexSet_;
467 
469  IdentityGridGlobalIdSet<const IdentityGrid<HostGrid> > globalIdSet_;
470 
472  IdentityGridLocalIdSet<const IdentityGrid<HostGrid> > localIdSet_;
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  {
493  static const bool v = hasEntityIterator<HostGrid, codim>::v;
494  };
495 
499  template<class HostGrid, int codim>
500  struct canCommunicate<IdentityGrid<HostGrid>, codim>
501  {
502  static const bool v = canCommunicate<HostGrid, codim>::v;
503  };
504 
508  template<class HostGrid>
510  {
511  static const bool v = isLevelwiseConforming<HostGrid>::v;
512  };
513 
517  template<class HostGrid>
519  {
520  static const bool v = isLeafwiseConforming<HostGrid>::v;
521  };
522  } // end namespace Capabilities
523 
524 } // namespace Dune
525 
526 #endif // DUNE_GRID_IDENTITYGRID_HH
Store a reference to an entity with a minimal memory footprint.
Definition: entityseed.hh:26
Implementation & impl()
access to the underlying implementation
Definition: entityseed.hh:59
constexpr static int codimension
codimension of underlying entity
Definition: entityseed.hh:30
Implementation & impl()
access to the underlying implementation
Definition: entity.hh:80
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
Definition: grid.hh:848
bool loadBalance()
default implementation of load balance does nothing and returns false
Definition: grid.hh:962
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:20
Id Set Interface.
Definition: indexidset.hh:447
The implementation of entities in a IdentityGrid.
Definition: identitygridentity.hh:55
Iterator over the descendants of an entity.Mesh entities of codimension 0 ("elements") allow to visit...
Definition: identitygridhierarchiciterator.hh:26
Iterator over all element neighborsMesh entities of codimension 0 ("elements") allow to visit all nei...
Definition: identitygridintersectioniterator.hh:29
Iterator over all entities of a given codimension and level of a grid.
Definition: identitygridleafiterator.hh:22
Definition: identitygridindexsets.hh:26
Definition: identitygridintersectioniterator.hh:84
Iterator over all entities of a given codimension and level of a grid.
Definition: identitygridleveliterator.hh:21
Provides a meta grid that is identical to its host.
Definition: identitygrid.hh:93
bool mark(int refCount, const typename Traits::template Codim< 0 >::Entity &e)
Mark entity for refinement.
Definition: identitygrid.hh:318
const Traits::LevelIndexSet & levelIndexSet(int level) const
Access to the LevelIndexSets.
Definition: identitygrid.hh:264
IdentityGridFamily< HostGrid::dimension, HostGrid >::Traits Traits
the Traits
Definition: identitygrid.hh:127
int size(int level, int codim) const
Number of grid entities per level and codim.
Definition: identitygrid.hh:222
int size(int level, GeometryType type) const
number of entities per level, codim and geometry type in this process
Definition: identitygrid.hh:239
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
unsigned int ghostSize(int level, int codim) const
Size of the ghost cell layer on a given level.
Definition: identitygrid.hh:370
HostGrid HostGridType
Definition: identitygrid.hh:117
void postAdapt()
Clean up refinement markers.
Definition: identitygrid.hh:345
bool adapt()
Triggers the grid refinement process.
Definition: identitygrid.hh:339
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim.
Definition: identitygrid.hh:208
HostGrid * hostgrid_
The host grid which contains the actual grid hierarchy structure.
Definition: identitygrid.hh:431
Traits::template Codim< codim >::LevelIterator lend(int level) const
one past the end on this level
Definition: identitygrid.hh:173
int size(int codim) const
number of leaf entities per codim in this process
Definition: identitygrid.hh:233
const Traits::GlobalIdSet & globalIdSet() const
Access to the GlobalIdSet.
Definition: identitygrid.hh:252
int size(GeometryType type) const
number of leaf entities per codim and geometry type in this process
Definition: identitygrid.hh:245
int maxLevel() const
Return maximum level defined in this grid.
Definition: identitygrid.hh:160
HostGrid::ctype ctype
The type used to store coordinates, inherited from the HostGrid.
Definition: identitygrid.hh:130
void communicate(DataHandle &handle, InterfaceType iftype, CommunicationDirection dir, int level) const
Communicate data of level gridView.
Definition: identitygrid.hh:395
Traits::template Codim< codim >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
Definition: identitygrid.hh:166
~IdentityGrid()
Destructor.
Definition: identitygrid.hh:147
HostGridType & getHostGrid() const
Returns the hostgrid this IdentityGrid lives in.
Definition: identitygrid.hh:415
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
Create Entity from EntitySeed.
Definition: identitygrid.hh:284
size_t numBoundarySegments() const
returns the number of boundary segments within the macro grid
Definition: identitygrid.hh:228
Traits::template Codim< codim >::LeafIterator leafend() const
one past the end of the sequence of leaf entities
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:215
IdentityGridFamily< HostGrid::dimension, HostGrid > GridFamily
type of the used GridFamily for this grid
Definition: identitygrid.hh:124
void globalRefine(int refCount)
Definition: identitygrid.hh:303
Traits::template Codim< codim >::template Partition< PiType >::LevelIterator lend(int level) const
one past the end on this level
Definition: identitygrid.hh:187
unsigned int overlapSize(int codim) const
Size of the overlap on the leaf level.
Definition: identitygrid.hh:352
const Traits::LeafIndexSet & leafIndexSet() const
Access to the LeafIndexSet.
Definition: identitygrid.hh:275
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
const Communication< No_Comm > & comm() const
dummy communication
Definition: identitygrid.hh:388
const Traits::LocalIdSet & localIdSet() const
Access to the LocalIdSet.
Definition: identitygrid.hh:258
IdentityGrid(HostGrid &hostgrid)
Constructor.
Definition: identitygrid.hh:137
Traits::template Codim< codim >::LeafIterator leafbegin() const
Iterator to first leaf entity of given codim.
Definition: identitygrid.hh:194
unsigned int overlapSize(int level, int codim) const
Size of the overlap on a given level.
Definition: identitygrid.hh:364
bool preAdapt()
returns true, if at least one entity is marked for adaption
Definition: identitygrid.hh:333
unsigned int ghostSize(int codim) const
Size of the ghost cell layer on the leaf level.
Definition: identitygrid.hh:358
void communicate(DataHandle &handle, InterfaceType iftype, CommunicationDirection dir) const
Communicate data of leaf gridView.
Definition: identitygrid.hh:403
int getMark(const typename Traits::template Codim< 0 >::Entity &e) const
Return refinement mark for entity.
Definition: identitygrid.hh:327
Index Set Interface base class.
Definition: indexidset.hh:78
auto size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:223
Default exception for dummy implementations.
Definition: exceptions.hh:263
A set of traits classes to store static information about grid implementation.
Different resources needed by all grid implementations.
Implements an utility class that provides collective communication methods for sequential programs.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:170
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:86
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.
Dune namespace.
Definition: alignedallocator.hh:13
specialize with 'true' for all codims that a grid can communicate data on (default=false)
Definition: capabilities.hh:97
specialize with 'true' for all codims that a grid provides an iterator for (default=hasEntity<codim>:...
Definition: capabilities.hh:74
Specialize with 'true' for all codims that a grid implements entities for. (default=false)
Definition: capabilities.hh:58
Specialize with 'true' if implementation guarantees a conforming leaf grid. (default=false)
Definition: capabilities.hh:115
Specialize with 'true' if implementation guarantees conforming level grids. (default=false)
Definition: capabilities.hh:106
Static tag representing a codimension.
Definition: dimension.hh:24
A traits struct that collects all associated types of one grid model.
Definition: grid.hh:1013
GridImp Grid
The type that implements the grid.
Definition: grid.hh:1015
A Traits struct that collects all associated types of one implementation.
Definition: grid.hh:411
provides access to host grid objects from GeometryGrid
Definition: hostgridaccess.hh:29
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Apr 27, 22:29, 2024)