Dune Core Modules (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>
13
14#include "mapper.hh"
15
22namespace 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>, 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 {
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 {
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 {
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:
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
Wrapper class for entities.
Definition: entity.hh:62
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:99
static std::size_t index(const GeometryType &gt)
Compute the index for the given geometry type over all dimensions.
Definition: typeindex.hh:147
Multiple codim and multiple geometry type mapper for leaf entities.
Definition: mcmgmapper.hh:297
LeafMultipleCodimMultipleGeomTypeMapper(const G &grid, const Layout< G::dimension > layout)
The constructor.
Definition: mcmgmapper.hh:316
LeafMultipleCodimMultipleGeomTypeMapper(const G &grid)
The constructor.
Definition: mcmgmapper.hh:304
Multiple codim and multiple geometry type mapper for entities of one level.
Definition: mcmgmapper.hh:335
LevelMultipleCodimMultipleGeomTypeMapper(const G &grid, int level)
The constructor.
Definition: mcmgmapper.hh:343
LevelMultipleCodimMultipleGeomTypeMapper(const G &grid, int level, const Layout< G::dimension > layout)
The constructor.
Definition: mcmgmapper.hh:356
Mapper interface.
Definition: mapper.hh:108
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:131
Index index(const EntityType &e) const
Map entity to array index.
Definition: mcmgmapper.hh:162
Index DUNE_DEPRECATED_MSG("Will be removed after dune-grid-2.4. Use method 'index' instead!") map(const EntityType &e) const
Map entity to array index.
Definition: mcmgmapper.hh:147
GV::IndexSet::IndexType Index
Number type used for indices.
Definition: mcmgmapper.hh:108
Index DUNE_DEPRECATED_MSG("Will be removed after dune-grid-2.4. Use method 'subIndex' instead!") map(const typename GV
Map subentity of codim 0 entity to array index.
Definition: mcmgmapper.hh:176
MultipleCodimMultipleGeomTypeMapper(const GV &gridView_, const Layout< GV::dimension > layout)
Construct mapper from grid and one of its index sets.
Definition: mcmgmapper.hh:118
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
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:10
Static tag representing a codimension.
Definition: dimension.hh:22
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:484
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.111.3 (Jul 24, 22:29, 2024)