Dune Core Modules (unstable)

yaspgridpersistentcontainer.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_YASPGRIDPERSISTENTCONTAINER_HH
6 #define DUNE_GRID_YASPGRIDPERSISTENTCONTAINER_HH
7 
12 #include <cassert>
13 #include <vector>
14 
15 #include <dune/grid/utility/persistentcontainer.hh>
16 #include <dune/grid/utility/persistentcontainervector.hh>
17 #include "../yaspgrid.hh"
18 
19 namespace Dune
20 {
21 
33  template<typename Grid>
35  {
36 
37  public:
38  YaspPersistentContainerIndex(const Grid & grid, int codim)
39  : _grid(grid), _codim(codim)
40  {
41  recomputeOffsets();
42  }
43 
45  typedef std::size_t IndexType;
46 
48  template<class Entity>
49  IndexType index (const Entity& e) const
50  {
51  static const int cc = Entity::codimension;
52  std::size_t level = e.level();
53  return _grid.indexsets[level]->template index<cc>(e) + _offsets[level];
54  }
55 
57  template< class Entity >
58  IndexType subIndex ( const Entity &e, int i, unsigned int codim ) const
59  {
60 
61  static const int cc = Entity::codimension;
62  std::size_t level = e.level();
63  return _grid.indexsets[level]->template subIndex<cc>(e,i,codim) + _offsets[level];
64  }
65 
67  std::size_t size (int /* codim */) const
68  {
69  if (_grid.indexsets.size()+1 != _offsets.size())
70  recomputeOffsets();
71  return _offsets.back();
72  }
73 
74  private:
75  void recomputeOffsets() const
76  {
77  _offsets.resize(_grid.indexsets.size()+1,0);
78  _offsets[0] = 0;
79  for (std::size_t i=0; i<_grid.indexsets.size(); i++)
80  _offsets[i+1] = _offsets[i] + _grid.indexsets[i]->size(_codim);
81  }
82 
83  const Grid& _grid;
84  int _codim;
85  mutable std::vector<std::size_t> _offsets;
86  };
87 
94  template<int dim, class CoordCont, class T>
95  class PersistentContainer< YaspGrid<dim, CoordCont>, T >
96  /* We have to pass the reference to the IndexSet to the constructor
97  of the PersistentContainerVector. In order to have a valid
98  indexset available, we inherit from a private indexset
99  */
100  : private YaspPersistentContainerIndex< const YaspGrid<dim, CoordCont> >,
101  public PersistentContainerVector< YaspGrid<dim, CoordCont>,
102  YaspPersistentContainerIndex< const YaspGrid<dim, CoordCont> >,
103  std::vector<T> >
104  {
107 
108  public:
109  typedef typename Base::Grid Grid;
110  typedef typename Base::Value Value;
111 
112  using Base::size;
113 
114  PersistentContainer ( const Grid &grid, int codim, const Value &value = Value() )
115  : IndexSet(grid, codim),
116  Base(*this, codim, value)
117  {}
118  };
119 
120 } // end namespace Dune
121 
122 #endif // end DUNE_GRID_YASPGRIDPERSISTENTCONTAINER_HH
Wrapper class for entities.
Definition: entity.hh:66
constexpr static int codimension
Know your own codimension.
Definition: entity.hh:106
int level() const
The level of this entity.
Definition: entity.hh:124
Grid abstract base class.
Definition: grid.hh:375
int size(int level, int codim) const
Return number of grid entities of a given codim on a given level in this process.
Definition: grid.hh:538
vector-based implementation of the PersistentContainer
Definition: persistentcontainervector.hh:51
A class for storing data during an adaptation cycle.
Definition: persistentcontainer.hh:22
[ provides Dune::Grid ]
Definition: yaspgrid.hh:166
implement a consecutive index for all entities of given codim of a YaspGrid
Definition: yaspgridpersistentcontainer.hh:35
IndexType index(const Entity &e) const
Map entity to index. The result of calling this method with an entity that is not in the index set is...
Definition: yaspgridpersistentcontainer.hh:49
std::size_t size(int) const
Return total number of entities of given geometry type in entity set .
Definition: yaspgridpersistentcontainer.hh:67
IndexType subIndex(const Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition: yaspgridpersistentcontainer.hh:58
std::size_t IndexType
The type used for the indices.
Definition: yaspgridpersistentcontainer.hh:45
concept Grid
Requirements for implementations of the Dune::Grid interface.
Definition: grid.hh:98
concept IndexSet
Model of an index set.
Definition: indexidset.hh:44
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Apr 27, 22:29, 2024)