dune-grid  2.6-git
yaspgridpersistentcontainer.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_YASPGRIDPERSISTENTCONTAINER_HH
4 #define DUNE_GRID_YASPGRIDPERSISTENTCONTAINER_HH
5 
10 #include <cassert>
11 #include <vector>
12 
15 #include "../yaspgrid.hh"
16 
17 namespace Dune
18 {
19 
31  template<typename Grid>
32  class YaspPersistentContainerIndex
33  {
34 
35  public:
36  YaspPersistentContainerIndex(const Grid & grid, int codim)
37  : _grid(grid), _codim(codim)
38  {
39  recomputeOffsets();
40  }
41 
43  typedef std::size_t IndexType;
44 
46  template<class Entity>
47  IndexType index (const Entity& e) const
48  {
49  static const int cc = Entity::codimension;
50  std::size_t level = e.level();
51  return _grid.indexsets[level]->template index<cc>(e) + _offsets[level];
52  }
53 
55  template< class Entity >
56  IndexType subIndex ( const Entity &e, int i, unsigned int codim ) const
57  {
58 
59  static const int cc = Entity::codimension;
60  std::size_t level = e.level();
61  return _grid.indexsets[level]->template subIndex<cc>(e,i,codim) + _offsets[level];
62  }
63 
65  std::size_t size (int codim) const
66  {
67  if (_grid.indexsets.size()+1 != _offsets.size())
68  recomputeOffsets();
69  return _offsets.back();
70  }
71 
72  private:
73  void recomputeOffsets() const
74  {
75  _offsets.resize(_grid.indexsets.size()+1,0);
76  _offsets[0] = 0;
77  for (std::size_t i=0; i<_grid.indexsets.size(); i++)
78  _offsets[i+1] = _offsets[i] + _grid.indexsets[i]->size(_codim);
79  }
80 
81  const Grid& _grid;
82  int _codim;
83  mutable std::vector<std::size_t> _offsets;
84  };
85 
92  template<int dim, class CoordCont, class T>
93  class PersistentContainer< YaspGrid<dim, CoordCont>, T >
94  /* We have to pass the reference to the IndexSet to the constructor
95  of the PersistentContainerVector. In order to have a valid
96  indexset available, we inherit from a private indexset
97  */
98  : private YaspPersistentContainerIndex< const YaspGrid<dim, CoordCont> >,
99  public PersistentContainerVector< YaspGrid<dim, CoordCont>,
100  YaspPersistentContainerIndex< const YaspGrid<dim, CoordCont> >,
101  std::vector<T> >
102  {
105 
106  public:
107  typedef typename Base::Grid Grid;
108  typedef typename Base::Value Value;
109 
110  using Base::size;
111 
112  PersistentContainer ( const Grid &grid, int codim, const Value &value = Value() )
113  : IndexSet(grid, codim),
114  Base(*this, codim, value)
115  {}
116  };
117 
118 } // end namespace Dune
119 
120 #endif // end DUNE_GRID_YASPGRIDPERSISTENTCONTAINER_HH
Dune::Entity
Wrapper class for entities.
Definition: common/entity.hh:63
Dune::YaspPersistentContainerIndex::YaspPersistentContainerIndex
YaspPersistentContainerIndex(const Grid &grid, int codim)
Definition: yaspgridpersistentcontainer.hh:36
Dune::PersistentContainer< YaspGrid< dim, CoordCont >, T >::Grid
Base::Grid Grid
Definition: yaspgridpersistentcontainer.hh:107
Dune::PersistentContainer< YaspGrid< dim, CoordCont >, T >::Value
Base::Value Value
Definition: yaspgridpersistentcontainer.hh:108
Dune::YaspPersistentContainerIndex::index
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:47
Dune::YaspGrid
[ provides Dune::Grid ]
Definition: yaspgrid.hh:58
Dune::PersistentContainer::Value
Base::Value Value
Definition: utility/persistentcontainer.hh:25
Dune::Entity::level
int level() const
The level of this entity.
Definition: common/entity.hh:126
Dune::Grid
Grid abstract base class.
Definition: common/grid.hh:373
Dune::PersistentContainerMap< G, G::LocalIdSet, std::map< G::LocalIdSet::IdType, T > >::grid
const Grid & grid() const
Definition: persistentcontainermap.hh:111
Dune::PersistentContainerVector
vector-based implementation of the PersistentContainer
Definition: persistentcontainervector.hh:48
Dune::YaspPersistentContainerIndex::IndexType
std::size_t IndexType
The type used for the indices.
Definition: yaspgridpersistentcontainer.hh:43
Dune::YaspPersistentContainerIndex
Definition: yaspgrid.hh:68
persistentcontainer.hh
Dune::PersistentContainerVector::Value
Vector::value_type Value
Definition: persistentcontainervector.hh:55
Dune::PersistentContainerMap::size
Size size() const
Definition: persistentcontainermap.hh:82
persistentcontainervector.hh
Dune::PersistentContainer
A class for storing data during an adaptation cycle.
Definition: utility/persistentcontainer.hh:18
Dune::Entity::codimension
@ codimension
Know your own codimension.
Definition: common/entity.hh:105
Dune::YaspPersistentContainerIndex::size
std::size_t size(int codim) const
Return total number of entities of given geometry type in entity set .
Definition: yaspgridpersistentcontainer.hh:65
Dune::PersistentContainerVector::Grid
G Grid
Definition: persistentcontainervector.hh:53
Dune::Grid::size
int size(int level, int codim) const
Return number of grid entities of a given codim on a given level in this process.
Definition: common/grid.hh:542
Dune
Include standard header files.
Definition: agrid.hh:58
Dune::YaspPersistentContainerIndex::subIndex
IndexType subIndex(const Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition: yaspgridpersistentcontainer.hh:56
Dune::PersistentContainer< YaspGrid< dim, CoordCont >, T >::PersistentContainer
PersistentContainer(const Grid &grid, int codim, const Value &value=Value())
Definition: yaspgridpersistentcontainer.hh:112