dune-grid  2.5-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  {
104  typedef PersistentContainerVector< YaspGrid<dim, CoordCont>, IndexSet, std::vector<T> > Base;
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
G Grid
Definition: persistentcontainervector.hh:53
vector-based implementation of the PersistentContainer
Definition: persistentcontainervector.hh:48
std::size_t size(int codim) const
Return total number of entities of given geometry type in entity set .
Definition: yaspgridpersistentcontainer.hh:65
Base::Grid Grid
Definition: yaspgridpersistentcontainer.hh:107
Vector::value_type Value
Definition: persistentcontainervector.hh:55
YaspPersistentContainerIndex(const Grid &grid, int codim)
Definition: yaspgridpersistentcontainer.hh:36
IndexType subIndex(const Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition: yaspgridpersistentcontainer.hh:56
std::size_t IndexType
The type used for the indices.
Definition: yaspgridpersistentcontainer.hh:43
Know your own codimension.
Definition: common/entity.hh:107
PersistentContainer(const Grid &grid, int codim, const Value &value=Value())
Definition: yaspgridpersistentcontainer.hh:112
Base::Value Value
Definition: yaspgridpersistentcontainer.hh:108
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
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
Include standard header files.
Definition: agrid.hh:59
[ provides Dune::Grid ]
Definition: yaspgrid.hh:56
int level() const
The level of this entity.
Definition: common/entity.hh:128
Wrapper class for entities.
Definition: common/entity.hh:64
Definition: yaspgrid.hh:67
A class for storing data during an adaptation cycle.
Definition: utility/persistentcontainer.hh:18
Grid abstract base classThis class is the base class for all grid implementations. Although no virtual functions are used we call it abstract since its methods do not contain an implementation but forward to the methods of the derived class via the Barton-Nackman trick.
Definition: common/grid.hh:373