Dune Core Modules (2.3.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_MCMGMAPPER_HH
5 #define DUNE_MCMGMAPPER_HH
6 
7 #include <iostream>
8 #include <map>
9 
10 #include <dune/geometry/referenceelements.hh>
11 #include <dune/geometry/type.hh>
13 
14 #include "mapper.hh"
15 
22 namespace Dune
23 {
31  //
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> >
104  {
105  public:
106 
107  // the following lines need to be skipped for intel compilers, because they
108  // lead to ambiguous calls to methods
109 #ifndef __INTEL_COMPILER
114 #endif
115 
124  MultipleCodimMultipleGeomTypeMapper (const GV& gridView_, const Layout<GV::dimension> layout)
125  : gridView(gridView_),
126  is(gridView.indexSet()),
127  offset(GlobalGeometryTypeIndex::size(GV::dimension)),
128  layout(layout)
129  {
130  update();
131  }
132 
138  : gridView(gridView_),
139  is(gridView.indexSet()),
140  offset(GlobalGeometryTypeIndex::size(GV::dimension))
141  {
142  update();
143  }
144 
152  template<class EntityType>
153  int map (const EntityType& e) const
154  {
155  const GeometryType gt = e.type();
156  return is.index(e) + offset[GlobalGeometryTypeIndex::index(gt)];
157  }
158 
166  int map (const typename GV::template Codim<0>::Entity& e, int i, unsigned int codim) const
167  {
169  assert(GlobalGeometryTypeIndex::index(gt) < n);
170  return is.subIndex(e, i, codim) + offset[GlobalGeometryTypeIndex::index(gt)];
171  }
172 
181  int size () const
182  {
183  return n;
184  }
185 
192  template<class EntityType>
193  bool contains (const EntityType& e, int& result) const
194  {
195  if(!is.contains(e) || !layout.contains(e.type()))
196  {
197  result = 0;
198  return false;
199  }
200  result = map(e);
201  return true;
202  }
203 
212  bool contains (const typename GV::template Codim<0>::Entity& e, int i, int cc, int& result) const
213  {
214  result = this->map(e,i,cc);
215  return true;
216  }
217 
220  void update ()
221  {
222  n = 0;
223 
224  for (unsigned int codim = 0; codim <= GV::dimension; ++codim)
225  {
226  // walk over all geometry types in the codimension
227  typedef std::vector<GeometryType> GTV;
228  const GTV &gtv = is.geomTypes(codim);
229  for (typename GTV::const_iterator it = gtv.begin(); it != gtv.end(); ++it)
230  {
231  // if the geometry type is contained in the layout, increment offset
232  if (layout.contains(*it))
233  {
234  offset[GlobalGeometryTypeIndex::index(*it)] = n;
235  n += is.size(*it);
236  }
237  }
238  }
239  }
240 
241  private:
242  // number of data elements required
243  unsigned int n;
244  // GridView is needed to keep the IndexSet valid
245  const GV gridView;
246  const typename GV::IndexSet& is;
247  // provide an array for the offsets
248  std::vector<int> offset;
249  mutable Layout<GV::dimension> layout; // get layout object
250  };
251 
253  //
254  // Leaf and level mapper
255  //
256 
267  template <typename G, template<int> class Layout>
269  : public MultipleCodimMultipleGeomTypeMapper<typename G::LeafGridView,Layout>
270  {
271  typedef MultipleCodimMultipleGeomTypeMapper<typename G::LeafGridView,
272  Layout> Base;
273  public:
278  : Base(grid.leafView())
279  {}
280 
289  LeafMultipleCodimMultipleGeomTypeMapper (const G& grid, const Layout<G::dimension> layout)
290  : Base(grid.leafView(),layout)
291  {}
292 
293  };
294 
306  template <typename G, template<int> class Layout>
308  : public MultipleCodimMultipleGeomTypeMapper<typename G::LevelGridView,Layout> {
309  typedef MultipleCodimMultipleGeomTypeMapper<typename G::LevelGridView,
310  Layout> Base;
311  public:
316  LevelMultipleCodimMultipleGeomTypeMapper (const G& grid, int level)
317  : Base(grid.levelGridView(level))
318  {}
319 
329  LevelMultipleCodimMultipleGeomTypeMapper (const G& grid, int level, const Layout<G::dimension> layout)
330  : Base(grid.levelGridView(level),layout)
331  {}
332 
333  };
334 
336 }
337 #endif
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
Compute indices for geometry types, taking the dimension into account.
Definition: typeindex.hh:97
static std::size_t index(const GeometryType &gt)
Compute the index for the given geometry type over all dimensions.
Definition: typeindex.hh:145
Multiple codim and multiple geometry type mapper for leaf entities.
Definition: mcmgmapper.hh:270
LeafMultipleCodimMultipleGeomTypeMapper(const G &grid, const Layout< G::dimension > layout)
The constructor.
Definition: mcmgmapper.hh:289
LeafMultipleCodimMultipleGeomTypeMapper(const G &grid)
The constructor.
Definition: mcmgmapper.hh:277
Multiple codim and multiple geometry type mapper for entities of one level.
Definition: mcmgmapper.hh:308
LevelMultipleCodimMultipleGeomTypeMapper(const G &grid, int level)
The constructor.
Definition: mcmgmapper.hh:316
LevelMultipleCodimMultipleGeomTypeMapper(const G &grid, int level, const Layout< G::dimension > layout)
The constructor.
Definition: mcmgmapper.hh:329
Mapper interface.
Definition: mapper.hh:110
Implementation class for a multiple codim and multiple geometry type mapper.
Definition: mcmgmapper.hh:104
MultipleCodimMultipleGeomTypeMapper(const GV &gridView_)
Construct mapper from grid and one of its index sets.
Definition: mcmgmapper.hh:137
void update()
Recalculates map after mesh adaptation.
Definition: mcmgmapper.hh:220
bool contains(const typename GV::template Codim< 0 >::Entity &e, int i, int cc, int &result) const
Returns true if the entity is contained in the index set.
Definition: mcmgmapper.hh:212
int map(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:166
int map(const EntityType &e) const
Map entity to array index.
Definition: mcmgmapper.hh:153
bool contains(const EntityType &e, int &result) const
Returns true if the entity is contained in the index set.
Definition: mcmgmapper.hh:193
MultipleCodimMultipleGeomTypeMapper(const GV &gridView_, const Layout< GV::dimension > layout)
Construct mapper from grid and one of its index sets.
Definition: mcmgmapper.hh:124
int size() const
Return total number of entities in the entity set managed by the mapper.
Definition: mcmgmapper.hh:181
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:132
Provides classes with basic mappers which are used to attach data to a grid.
Dune namespace.
Definition: alignment.hh:14
Layout template for elements.
Definition: mcmgmapper.hh:43
bool contains(Dune::GeometryType gt)
Definition: mcmgmapper.hh:46
Layout template for vertices.
Definition: mcmgmapper.hh:57
bool contains(Dune::GeometryType gt)
Definition: mcmgmapper.hh:60
static const ReferenceElement< ctype, dim > & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:568
A unique label for each type of element that can occur in a grid.
Helper classes to provide indices for geometrytypes for use in a vector.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 16, 22:29, 2024)