dune-grid  2.4.1
mcmgmapper.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 
4 #ifndef DUNE_GRID_COMMON_MCMGMAPPER_HH
5 #define DUNE_GRID_COMMON_MCMGMAPPER_HH
6 
7 #include <iostream>
8 #include <map>
9 
10 #include <dune/geometry/referenceelements.hh>
11 #include <dune/geometry/type.hh>
12 #include <dune/geometry/typeindex.hh>
13 
14 #include "mapper.hh"
15 
22 namespace Dune
23 {
30  //
32  // Common Layout templates
33  //
34 
36 
43  template<int dimgrid> struct MCMGElementLayout {
46  bool contains (Dune::GeometryType gt) { return gt.dim()==dimgrid; }
47  };
48 
50 
57  template<int dim> struct MCMGVertexLayout {
60  bool contains (Dune::GeometryType gt) { return gt.dim()==0; }
61  };
62 
64  //
65  // MultipleCodimMultipleGeomTypeMapper
66  //
67 
101  template <typename GV, template<int> class Layout>
103  public Mapper<typename GV::Grid,MultipleCodimMultipleGeomTypeMapper<GV,Layout>, typename GV::IndexSet::IndexType >
104  {
105  public:
106 
108  typedef typename GV::IndexSet::IndexType Index;
109 
118  MultipleCodimMultipleGeomTypeMapper (const GV& gridView_, const Layout<GV::dimension> layout)
119  : gridView(gridView_),
120  is(gridView.indexSet()),
121  offset(GlobalGeometryTypeIndex::size(GV::dimension)),
122  layout(layout)
123  {
124  update();
125  }
126 
132  : gridView(gridView_),
133  is(gridView.indexSet()),
134  offset(GlobalGeometryTypeIndex::size(GV::dimension))
135  {
136  update();
137  }
138 
146  template<class EntityType>
147  Index DUNE_DEPRECATED_MSG("Will be removed after dune-grid-2.4. Use method 'index' instead!") map (const EntityType& e) const
148  {
149  const GeometryType gt = e.type();
150  assert(layout.contains(gt));
151  return is.index(e) + offset[GlobalGeometryTypeIndex::index(gt)];
152  }
153 
161  template<class EntityType>
162  Index index (const EntityType& e) const
163  {
164  const GeometryType gt = e.type();
165  assert(layout.contains(gt));
166  return is.index(e) + offset[GlobalGeometryTypeIndex::index(gt)];
167  }
168 
176  Index DUNE_DEPRECATED_MSG("Will be removed after dune-grid-2.4. Use method 'subIndex' instead!") map (const typename GV::template Codim<0>::Entity& e, int i, unsigned int codim) const
177  {
178  GeometryType gt=ReferenceElements<double,GV::dimension>::general(e.type()).type(i,codim);
179  assert(layout.contains(gt));
180  return is.subIndex(e, i, codim) + offset[GlobalGeometryTypeIndex::index(gt)];
181  }
182 
190  Index subIndex (const typename GV::template Codim<0>::Entity& e, int i, unsigned int codim) const
191  {
192  GeometryType gt=ReferenceElements<double,GV::dimension>::general(e.type()).type(i,codim);
193  assert(layout.contains(gt));
194  return is.subIndex(e, i, codim) + offset[GlobalGeometryTypeIndex::index(gt)];
195  }
196 
205  int size () const
206  {
207  return n;
208  }
209 
216  template<class EntityType>
217  bool contains (const EntityType& e, Index& result) const
218  {
219  if(!is.contains(e) || !layout.contains(e.type()))
220  {
221  result = 0;
222  return false;
223  }
224  result = map(e);
225  return true;
226  }
227 
236  bool contains (const typename GV::template Codim<0>::Entity& e, int i, int cc, Index& result) const
237  {
238  GeometryType gt=ReferenceElements<double,GV::dimension>::general(e.type()).type(i,cc);
239  if (not layout.contains(gt))
240  return false;
241  result = is.subIndex(e, i, cc) + offset[GlobalGeometryTypeIndex::index(gt)];
242  return true;
243  }
244 
247  void update ()
248  {
249  n = 0;
250 
251  for (unsigned int codim = 0; codim <= GV::dimension; ++codim)
252  {
253  // walk over all geometry types in the codimension
254  typedef typename GV::IndexSet::Types GTV;
255  GTV gtv = is.types(codim);
256  for (typename GTV::const_iterator it = gtv.begin(); it != gtv.end(); ++it)
257  {
258  // if the geometry type is contained in the layout, increment offset
259  if (layout.contains(*it))
260  {
261  offset[GlobalGeometryTypeIndex::index(*it)] = n;
262  n += is.size(*it);
263  }
264  }
265  }
266  }
267 
268  private:
269  // number of data elements required
270  unsigned int n;
271  // GridView is needed to keep the IndexSet valid
272  const GV gridView;
273  const typename GV::IndexSet& is;
274  // provide an array for the offsets
275  std::vector<int> offset;
276  mutable Layout<GV::dimension> layout; // get layout object
277  };
278 
280  //
281  // Leaf and level mapper
282  //
283 
294  template <typename G, template<int> class Layout>
296  : public MultipleCodimMultipleGeomTypeMapper<typename G::LeafGridView,Layout>
297  {
298  typedef MultipleCodimMultipleGeomTypeMapper<typename G::LeafGridView,
299  Layout> Base;
300  public:
305  : Base(grid.leafGridView())
306  {}
307 
316  LeafMultipleCodimMultipleGeomTypeMapper (const G& grid, const Layout<G::dimension> layout)
317  : Base(grid.leafGridView(),layout)
318  {}
319 
320  };
321 
333  template <typename G, template<int> class Layout>
335  : public MultipleCodimMultipleGeomTypeMapper<typename G::LevelGridView,Layout> {
336  typedef MultipleCodimMultipleGeomTypeMapper<typename G::LevelGridView,
337  Layout> Base;
338  public:
343  LevelMultipleCodimMultipleGeomTypeMapper (const G& grid, int level)
344  : Base(grid.levelGridView(level))
345  {}
346 
356  LevelMultipleCodimMultipleGeomTypeMapper (const G& grid, int level, const Layout<G::dimension> layout)
357  : Base(grid.levelGridView(level),layout)
358  {}
359 
360  };
361 
363 }
364 #endif
Mapper interface.
Definition: mapper.hh:108
LevelMultipleCodimMultipleGeomTypeMapper(const G &grid, int level, const Layout< G::dimension > layout)
The constructor.
Definition: mcmgmapper.hh:356
Implementation class for a multiple codim and multiple geometry type mapper.
Definition: mcmgmapper.hh:102
Multiple codim and multiple geometry type mapper for leaf entities.
Definition: mcmgmapper.hh:295
Index map(const EntityType &e) const
Map entity to array index.
Definition: mcmgmapper.hh:147
Wrapper class for entities.
Definition: common/entity.hh:61
LeafMultipleCodimMultipleGeomTypeMapper(const G &grid, const Layout< G::dimension > layout)
The constructor.
Definition: mcmgmapper.hh:316
bool contains(const typename GV::template Codim< 0 >::Entity &e, int i, int cc, Index &result) const
Returns true if the entity is contained in the index set.
Definition: mcmgmapper.hh:236
Index subIndex(const typename GV::template Codim< 0 >::Entity &e, int i, unsigned int codim) const
Map subentity of codim 0 entity to array index.
Definition: mcmgmapper.hh:190
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
MultipleCodimMultipleGeomTypeMapper(const GV &gridView_)
Construct mapper from grid and one of its index sets.
Definition: mcmgmapper.hh:131
LeafMultipleCodimMultipleGeomTypeMapper(const G &grid)
The constructor.
Definition: mcmgmapper.hh:304
int size() const
Return total number of entities in the entity set managed by the mapper.
Definition: mcmgmapper.hh:205
Layout template for vertices.
Definition: mcmgmapper.hh:57
MultipleCodimMultipleGeomTypeMapper(const GV &gridView_, const Layout< GV::dimension > layout)
Construct mapper from grid and one of its index sets.
Definition: mcmgmapper.hh:118
bool contains(const EntityType &e, Index &result) const
Returns true if the entity is contained in the index set.
Definition: mcmgmapper.hh:217
void update()
Recalculates map after mesh adaptation.
Definition: mcmgmapper.hh:247
GV::IndexSet::IndexType Index
Number type used for indices.
Definition: mcmgmapper.hh:108
Layout template for elements.
Definition: mcmgmapper.hh:43
Multiple codim and multiple geometry type mapper for entities of one level.
Definition: mcmgmapper.hh:334
LevelMultipleCodimMultipleGeomTypeMapper(const G &grid, int level)
The constructor.
Definition: mcmgmapper.hh:343
bool contains(Dune::GeometryType gt)
Definition: mcmgmapper.hh:60
Provides classes with basic mappers which are used to attach data to a grid.
bool contains(Dune::GeometryType gt)
Definition: mcmgmapper.hh:46
Index index(const EntityType &e) const
Map entity to array index.
Definition: mcmgmapper.hh:162