Dune Core Modules (2.5.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_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>
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 const GeometryType eType = e.type();
163 GeometryType gt = eType.isNone() ?
164 GeometryType( GeometryType::none, GV::dimension - codim ) :
166 //GeometryType gt=ReferenceElements<double,GV::dimension>::general(e.type()).type(i,codim);
167 assert(layout.contains(gt));
168 return is.subIndex(e, i, codim) + offset[GlobalGeometryTypeIndex::index(gt)];
169 }
170
179 int size () const
180 {
181 return n;
182 }
183
190 template<class EntityType>
191 bool contains (const EntityType& e, Index& result) const
192 {
193 if(!is.contains(e) || !layout.contains(e.type()))
194 {
195 result = 0;
196 return false;
197 }
198 result = index(e);
199 return true;
200 }
201
210 bool contains (const typename GV::template Codim<0>::Entity& e, int i, int cc, Index& result) const
211 {
212 const GeometryType eType = e.type();
213 const GeometryType gt = eType.isNone() ?
214 GeometryType( GeometryType::none, GV::dimension - cc ) :
216 //GeometryType gt=ReferenceElements<double,GV::dimension>::general(e.type()).type(i,cc);
217 if (not layout.contains(gt))
218 return false;
219 result = is.subIndex(e, i, cc) + offset[GlobalGeometryTypeIndex::index(gt)];
220 return true;
221 }
222
225 void update ()
226 {
227 n = 0;
228
229 for (unsigned int codim = 0; codim <= GV::dimension; ++codim)
230 {
231 // walk over all geometry types in the codimension
232 typedef typename GV::IndexSet::Types GTV;
233 GTV gtv = is.types(codim);
234 for (typename GTV::const_iterator it = gtv.begin(); it != gtv.end(); ++it)
235 {
236 // if the geometry type is contained in the layout, increment offset
237 if (layout.contains(*it))
238 {
239 offset[GlobalGeometryTypeIndex::index(*it)] = n;
240 n += is.size(*it);
241 }
242 }
243 }
244 }
245
246 private:
247 // number of data elements required
248 unsigned int n;
249 // GridView is needed to keep the IndexSet valid
250 const GV gridView;
251 const typename GV::IndexSet& is;
252 // provide an array for the offsets
253 std::vector<int> offset;
254 mutable Layout<GV::dimension> layout; // get layout object
255 };
256
258 //
259 // Leaf and level mapper
260 //
261
272 template <typename G, template<int> class Layout>
274 : public MultipleCodimMultipleGeomTypeMapper<typename G::LeafGridView,Layout>
275 {
276 typedef MultipleCodimMultipleGeomTypeMapper<typename G::LeafGridView,
277 Layout> Base;
278 public:
283 : Base(grid.leafGridView())
284 {}
285
294 LeafMultipleCodimMultipleGeomTypeMapper (const G& grid, const Layout<G::dimension> layout)
295 : Base(grid.leafGridView(),layout)
296 {}
297
298 };
299
311 template <typename G, template<int> class Layout>
313 : public MultipleCodimMultipleGeomTypeMapper<typename G::LevelGridView,Layout> {
314 typedef MultipleCodimMultipleGeomTypeMapper<typename G::LevelGridView,
315 Layout> Base;
316 public:
322 : Base(grid.levelGridView(level))
323 {}
324
334 LevelMultipleCodimMultipleGeomTypeMapper (const G& grid, int level, const Layout<G::dimension> layout)
335 : Base(grid.levelGridView(level),layout)
336 {}
337
338 };
339
341}
342#endif
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:268
bool isNone() const
Return true if entity is a singular of any dimension.
Definition: type.hh:560
@ none
Generic element in any nonnegative dimension.
Definition: type.hh:278
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:275
LeafMultipleCodimMultipleGeomTypeMapper(const G &grid, const Layout< G::dimension > layout)
The constructor.
Definition: mcmgmapper.hh:294
LeafMultipleCodimMultipleGeomTypeMapper(const G &grid)
The constructor.
Definition: mcmgmapper.hh:282
Multiple codim and multiple geometry type mapper for entities of one level.
Definition: mcmgmapper.hh:313
LevelMultipleCodimMultipleGeomTypeMapper(const G &grid, int level)
The constructor.
Definition: mcmgmapper.hh:321
LevelMultipleCodimMultipleGeomTypeMapper(const G &grid, int level, const Layout< G::dimension > layout)
The constructor.
Definition: mcmgmapper.hh:334
Mapper interface.
Definition: mapper.hh:107
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:225
bool contains(const EntityType &e, Index &result) const
Returns true if the entity is contained in the index set.
Definition: mcmgmapper.hh:191
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:210
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:179
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:132
Grid< dim, dimworld, ct, GridFamily >::LeafGridView leafGridView(const Grid< dim, dimworld, ct, GridFamily > &grid)
leaf grid view for the given grid
Definition: grid.hh:874
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: grid.hh:857
Provides classes with basic mappers which are used to attach data to a grid.
Dune namespace.
Definition: alignment.hh:11
Static tag representing a codimension.
Definition: dimension.hh:22
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
static const ReferenceElement< ctype, dim > & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:757
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 (Nov 23, 23:29, 2024)