dune-grid 3.0-git
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
9#include <dune/geometry/referenceelements.hh>
10#include <dune/geometry/type.hh>
11#include <dune/geometry/typeindex.hh>
12
13#include "mapper.hh"
14
21namespace Dune
22{
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>, typename GV::IndexSet::IndexType >
103 {
104 public:
105
107 typedef typename GV::IndexSet::IndexType Index;
108
117 MultipleCodimMultipleGeomTypeMapper (const GV& gridView_, const Layout<GV::dimension> layout)
118 : gridView(gridView_),
119 is(gridView.indexSet()),
120 offset(GlobalGeometryTypeIndex::size(GV::dimension)),
121 layout(layout)
122 {
123 update();
124 }
125
131 : gridView(gridView_),
132 is(gridView.indexSet()),
133 offset(GlobalGeometryTypeIndex::size(GV::dimension))
134 {
135 update();
136 }
137
145 template<class EntityType>
146 Index index (const EntityType& e) const
147 {
148 const GeometryType gt = e.type();
149 assert(layout.contains(gt));
150 return is.index(e) + offset[GlobalGeometryTypeIndex::index(gt)];
151 }
152
160 Index subIndex (const typename GV::template Codim<0>::Entity& e, int i, unsigned int codim) const
161 {
162 GeometryType gt=ReferenceElements<double,GV::dimension>::general(e.type()).type(i,codim);
163 assert(layout.contains(gt));
164 return is.subIndex(e, i, codim) + offset[GlobalGeometryTypeIndex::index(gt)];
165 }
166
175 int size () const
176 {
177 return n;
178 }
179
186 template<class EntityType>
187 bool contains (const EntityType& e, Index& result) const
188 {
189 if(!is.contains(e) || !layout.contains(e.type()))
190 {
191 result = 0;
192 return false;
193 }
194 result = index(e);
195 return true;
196 }
197
206 bool contains (const typename GV::template Codim<0>::Entity& e, int i, int cc, Index& result) const
207 {
208 GeometryType gt=ReferenceElements<double,GV::dimension>::general(e.type()).type(i,cc);
209 if (not layout.contains(gt))
210 return false;
211 result = is.subIndex(e, i, cc) + offset[GlobalGeometryTypeIndex::index(gt)];
212 return true;
213 }
214
217 void update ()
218 {
219 n = 0;
220
221 for (unsigned int codim = 0; codim <= GV::dimension; ++codim)
222 {
223 // walk over all geometry types in the codimension
224 typedef typename GV::IndexSet::Types GTV;
225 GTV gtv = is.types(codim);
226 for (typename GTV::const_iterator it = gtv.begin(); it != gtv.end(); ++it)
227 {
228 // if the geometry type is contained in the layout, increment offset
229 if (layout.contains(*it))
230 {
231 offset[GlobalGeometryTypeIndex::index(*it)] = n;
232 n += is.size(*it);
233 }
234 }
235 }
236 }
237
238 private:
239 // number of data elements required
240 unsigned int n;
241 // GridView is needed to keep the IndexSet valid
242 const GV gridView;
243 const typename GV::IndexSet& is;
244 // provide an array for the offsets
245 std::vector<int> offset;
246 mutable Layout<GV::dimension> layout; // get layout object
247 };
248
250 //
251 // Leaf and level mapper
252 //
253
264 template <typename G, template<int> class Layout>
266 : public MultipleCodimMultipleGeomTypeMapper<typename G::LeafGridView,Layout>
267 {
268 typedef MultipleCodimMultipleGeomTypeMapper<typename G::LeafGridView,
269 Layout> Base;
270 public:
275 : Base(grid.leafGridView())
276 {}
277
286 LeafMultipleCodimMultipleGeomTypeMapper (const G& grid, const Layout<G::dimension> layout)
287 : Base(grid.leafGridView(),layout)
288 {}
289
290 };
291
303 template <typename G, template<int> class Layout>
305 : public MultipleCodimMultipleGeomTypeMapper<typename G::LevelGridView,Layout> {
306 typedef MultipleCodimMultipleGeomTypeMapper<typename G::LevelGridView,
307 Layout> Base;
308 public:
314 : Base(grid.levelGridView(level))
315 {}
316
326 LevelMultipleCodimMultipleGeomTypeMapper (const G& grid, int level, const Layout<G::dimension> layout)
327 : Base(grid.levelGridView(level),layout)
328 {}
329
330 };
331
333}
334#endif
Provides classes with basic mappers which are used to attach data to a grid.
Grid< dim, dimworld, ct, GridFamily >::LeafGridView leafGridView(const Grid< dim, dimworld, ct, GridFamily > &grid)
leaf grid view for the given grid
Definition common/grid.hh:878
Grid< dim, dimworld, ct, GridFamily >::LevelGridView levelGridView(const Grid< dim, dimworld, ct, GridFamily > &grid, int level)
level grid view for the given grid and level.
Definition common/grid.hh:861
Include standard header files.
Definition agrid.hh:60
Mapper interface.
Definition mapper.hh:107
Layout template for elements.
Definition mcmgmapper.hh:42
bool contains(Dune::GeometryType gt)
Definition mcmgmapper.hh:45
Layout template for vertices.
Definition mcmgmapper.hh:56
bool contains(Dune::GeometryType gt)
Definition mcmgmapper.hh:59
Implementation class for a multiple codim and multiple geometry type mapper.
Definition mcmgmapper.hh:103
MultipleCodimMultipleGeomTypeMapper(const GV &gridView_)
Construct mapper from grid and one of its index sets.
Definition mcmgmapper.hh:130
void update()
Recalculates map after mesh adaptation.
Definition mcmgmapper.hh:217
bool contains(const EntityType &e, Index &result) const
Returns true if the entity is contained in the index set.
Definition mcmgmapper.hh:187
Index index(const EntityType &e) const
Map entity to array index.
Definition mcmgmapper.hh:146
GV::IndexSet::IndexType Index
Number type used for indices.
Definition mcmgmapper.hh:107
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:206
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:160
MultipleCodimMultipleGeomTypeMapper(const GV &gridView_, const Layout< GV::dimension > layout)
Construct mapper from grid and one of its index sets.
Definition mcmgmapper.hh:117
int size() const
Return total number of entities in the entity set managed by the mapper.
Definition mcmgmapper.hh:175
Multiple codim and multiple geometry type mapper for leaf entities.
Definition mcmgmapper.hh:267
LeafMultipleCodimMultipleGeomTypeMapper(const G &grid, const Layout< G::dimension > layout)
The constructor.
Definition mcmgmapper.hh:286
LeafMultipleCodimMultipleGeomTypeMapper(const G &grid)
The constructor.
Definition mcmgmapper.hh:274
Multiple codim and multiple geometry type mapper for entities of one level.
Definition mcmgmapper.hh:305
LevelMultipleCodimMultipleGeomTypeMapper(const G &grid, int level)
The constructor.
Definition mcmgmapper.hh:313
LevelMultipleCodimMultipleGeomTypeMapper(const G &grid, int level, const Layout< G::dimension > layout)
The constructor.
Definition mcmgmapper.hh:326