dune-grid  2.2.0
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/type.hh>
11 #include <dune/geometry/referenceelements.hh>
12 
13 #include "mapper.hh"
14 
21 namespace Dune
22 {
29 
30  //
31  // Common Layout templates
32  //
33 
35 
42  template<int dimgrid> struct MCMGElementLayout {
45  bool contains (Dune::GeometryType gt) { return gt.dim()==dimgrid; }
46  };
47 
49 
56  template<int dim> struct MCMGVertexLayout {
59  bool contains (Dune::GeometryType gt) { return gt.dim()==0; }
60  };
61 
63  //
64  // MultipleCodimMultipleGeomTypeMapper
65  //
66 
100  template <typename GV, template<int> class Layout>
102  public Mapper<typename GV::Grid,MultipleCodimMultipleGeomTypeMapper<GV,Layout> >
103  {
104  public:
105 
106  // the following lines need to be skipped for intel compilers, because they
107  // lead to ambiguous calls to methods
108 #ifndef __INTEL_COMPILER
109 
110 
113 #endif
114 
123  MultipleCodimMultipleGeomTypeMapper (const GV& gridView, const Layout<GV::dimension> layout)
124  : is(gridView.indexSet()), layout(layout)
125  {
126  update();
127  }
128 
134  : is(gridView.indexSet())
135  {
136  update();
137  }
138 
144  template<class EntityType>
145  int map (const EntityType& e) const
146  {
147  return is.index(e) + offset.find(e.type())->second;
148  }
149 
157  int map (const typename GV::template Codim<0>::Entity& e, int i, unsigned int codim) const
158  {
159  GeometryType gt=GenericReferenceElements<double,GV::dimension>::general(e.type()).type(i,codim);
160  return is.subIndex(e,i,codim) + offset.find(gt)->second;
161  }
162 
171  int size () const
172  {
173  return n;
174  }
175 
182  template<class EntityType>
183  bool contains (const EntityType& e, int& result) const
184  {
185  if(!is.contains(e) || !layout.contains(e.type()))
186  {
187  result = 0;
188  return false;
189  }
190  result = map(e);
191  return true;
192  }
193 
202  bool contains (const typename GV::template Codim<0>::Entity& e, int i, int cc, int& result) const
203  {
204  result = this->map(e,i,cc);
205  return true;
206  }
207 
208 
211  void update ()
212  {
213  n=0; // zero data elements
214  for (int c=0; c<=GV::dimension; c++)
215  offset.clear(); // clear all maps
216 
217  // Compute offsets for the different geometry types.
218  // Note that mapper becomes invalid when the grid is modified.
219  for (int c=0; c<=GV::dimension; c++)
220  for (size_t i=0; i<is.geomTypes(c).size(); i++)
221  if (layout.contains(is.geomTypes(c)[i]))
222  {
223  offset[is.geomTypes(c)[i]] = n;
224  n += is.size(is.geomTypes(c)[i]);
225  }
226  }
227 
228  private:
229  int n; // number of data elements required
230  const typename GV::IndexSet& is;
231  std::map<GeometryType,int> offset; // provide a map with all geometry types
232  mutable Layout<GV::dimension> layout; // get layout object
233  };
234 
236  //
237  // Leaf and level mapper
238  //
239 
250  template <typename G, template<int> class Layout>
252  : public MultipleCodimMultipleGeomTypeMapper<typename G::LeafGridView,Layout>
253  {
254  typedef MultipleCodimMultipleGeomTypeMapper<typename G::LeafGridView,
255  Layout> Base;
256  public:
261  : Base(grid.leafView())
262  {}
263 
272  LeafMultipleCodimMultipleGeomTypeMapper (const G& grid, const Layout<G::dimension> layout)
273  : Base(grid.leafView(),layout)
274  {}
275 
276  };
277 
289  template <typename G, template<int> class Layout>
291  : public MultipleCodimMultipleGeomTypeMapper<typename G::LevelGridView,Layout> {
292  typedef MultipleCodimMultipleGeomTypeMapper<typename G::LevelGridView,
293  Layout> Base;
294  public:
299  LevelMultipleCodimMultipleGeomTypeMapper (const G& grid, int level)
300  : Base(grid.levelView(level))
301  {}
302 
312  LevelMultipleCodimMultipleGeomTypeMapper (const G& grid, int level, const Layout<G::dimension> layout)
313  : Base(grid.levelView(level),layout)
314  {}
315 
316  };
317 
319 }
320 #endif