Dune Core Modules (2.8.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 <functional>
8#include <iostream>
9
12#include <dune/geometry/dimension.hh>
13#include <dune/geometry/referenceelements.hh>
14#include <dune/geometry/type.hh>
16
17#include "mapper.hh"
18
25namespace Dune
26{
34 //
35 // Common Layout templates
36 //
37
62 using MCMGLayout = std::function<size_t(GeometryType, int)>;
63
69 template<int codim>
71 {
72 return [](GeometryType gt, int dimgrid) {
73 return dimgrid - gt.dim() == codim;
74 };
75 }
76
82 template<int dim>
84 {
85 return [](GeometryType gt, int) {
86 return gt.dim() == dim;
87 };
88 }
89
96 {
97 return mcmgLayout(Codim<0>());
98 }
99
106 {
107 return mcmgLayout(Dim<0>());
108 }
109
111 //
112 // MultipleCodimMultipleGeomTypeMapper
113 //
114
124 template <typename GV>
126 public Mapper<typename GV::Grid,MultipleCodimMultipleGeomTypeMapper<GV>, typename GV::IndexSet::IndexType >
127 {
128 public:
129
131 typedef GV GridView;
132
134 typedef typename GV::IndexSet::IndexType Index;
135
140 using size_type = decltype(std::declval<typename GV::IndexSet>().size(0));
141
153 MultipleCodimMultipleGeomTypeMapper(const GV& gridView, const MCMGLayout& layout)
154 : gridView_(gridView)
155 , indexSet_(&gridView_.indexSet())
156 , layout_(layout)
157 {
158 update(gridView);
159 }
160
168 template<class EntityType>
169 Index index (const EntityType& e) const
170 {
171 const GeometryType gt = e.type();
172 assert(offset(gt) != invalidOffset);
173 return indexSet_->index(e)*blockSize(gt) + offset(gt);
174 }
175
183 Index subIndex (const typename GV::template Codim<0>::Entity& e, int i, unsigned int codim) const
184 {
185 const GeometryType eType = e.type();
186 GeometryType gt = eType.isNone() ?
187 GeometryTypes::none( GV::dimension - codim ) :
189 //GeometryType gt=ReferenceElements<double,GV::dimension>::general(e.type()).type(i,codim);
190 assert(offset(gt) != invalidOffset);
191 return indexSet_->subIndex(e, i, codim)*blockSize(gt) + offset(gt);
192 }
193
203 {
204 return n;
205 }
206
209 {
210 return blockSize(gt);
211 }
212
214 const std::vector< GeometryType >& types ( int codim ) const
215 {
216 return myTypes_[ codim ];
217 }
218
228 template<class EntityType>
229 IntegralRange<Index> indices (const EntityType& e) const
230 {
231 if(!indexSet_->contains(e) || offset(e.type()) == invalidOffset)
232 return {0,0};
233 Index start = index(e);
234 return {start, start+blockSize(e.type())};
235 }
236
248 IntegralRange<Index> indices (const typename GV::template Codim<0>::Entity& e, int i, int cc) const
249 {
250 const GeometryType eType = e.type();
251 const GeometryType gt = eType.isNone() ?
252 GeometryTypes::none(GV::dimension - cc) :
254 if (offset(gt) == invalidOffset)
255 return {0,0};
256 else
257 {
258 Index start = subIndex(e,i,cc);
259 return {start, start+blockSize(gt)};
260 }
261 }
262
269 template<class EntityType>
270 bool contains (const EntityType& e, Index& result) const
271 {
272 if(!indexSet_->contains(e) || offset(e.type()) == invalidOffset)
273 {
274 result = 0;
275 return false;
276 }
277 result = index(e);
278 return true;
279 }
280
289 bool contains (const typename GV::template Codim<0>::Entity& e, int i, int cc, Index& result) const
290 {
291 const GeometryType eType = e.type();
292 const GeometryType gt = eType.isNone() ?
293 GeometryTypes::none( GV::dimension - cc ) :
295 if (offset(gt) == invalidOffset)
296 return false;
297 result = indexSet_->subIndex(e, i, cc)*blockSize(gt) + offset(gt);
298 return true;
299 }
300
306 void update (const GV& gridView)
307 {
308 gridView_ = gridView;
309 indexSet_ = &gridView_.indexSet();
310 update_();
311 }
312
318 void update (GV&& gridView)
319 {
320 gridView_ = std::move(gridView);
321 indexSet_ = &gridView_.indexSet();
322 update_();
323 }
324
327 [[deprecated("Use update(gridView) instead! Will be removed after release 2.8.")]]
328 void update ()
329 {
330 update_();
331 }
332
333 const MCMGLayout &layout () const { return layout_; }
334 const GridView &gridView () const { return gridView_; }
335
336 private:
337 void update_()
338 {
339 n = 0;
340
341 std::fill(offsets.begin(),offsets.end(),Index(0));
342 std::fill(blocks.begin(),blocks.end(),Index(0));
343
344 for (unsigned int codim = 0; codim <= GV::dimension; ++codim)
345 {
346 // walk over all geometry types in the codimension
347 for (const GeometryType& gt : indexSet_->types(codim)) {
348 Index offset;
349 size_t block = layout()(gt, GV::Grid::dimension);
350
351 // if the geometry type is contained in the layout, increment offset
352 // and store geometry type
353 if (block) {
354 offset = n;
355 n += indexSet_->size(gt) * block;
356 myTypes_[codim].push_back(gt);
357 }
358 else {
359 offset = invalidOffset;
360 }
361
362 offsets[GlobalGeometryTypeIndex::index(gt)] = offset;
363 blocks[GlobalGeometryTypeIndex::index(gt)] = block;
364 }
365 }
366 }
367
368 Index offset(GeometryType gt) const
369 { return offsets[GlobalGeometryTypeIndex::index(gt)]; }
370 Index blockSize(GeometryType gt) const
371 { return blocks[GlobalGeometryTypeIndex::index(gt)]; }
372
373 static const Index invalidOffset = std::numeric_limits<Index>::max();
374
375 // number of data elements required
376 unsigned int n;
377 // GridView is needed to keep the IndexSet valid
378 GV gridView_;
379 const typename GV::IndexSet* indexSet_;
380 // provide an array for the offsets
381 std::array<Index, GlobalGeometryTypeIndex::size(GV::dimension)> offsets;
382 std::array<Index, GlobalGeometryTypeIndex::size(GV::dimension)> blocks;
383 const MCMGLayout layout_; // get layout object
384 std::vector<GeometryType> myTypes_[GV::dimension+1];
385 };
386
388 //
389 // Leaf and level mapper
390 //
391
398 template <typename G>
399 class [[deprecated("Use MultipleCodimMultipleGeomTypeMapper instead! Will be removed after release 2.8.")]]
401 : public MultipleCodimMultipleGeomTypeMapper<typename G::LeafGridView>
402 {
404 public:
405
413 : Base(grid.leafGridView(), layout)
414 , gridPtr_(&grid)
415 {}
416
422 void update ()
423 {
424 Base::update(gridPtr_->leafGridView());
425 }
426
427 private:
428 const G* gridPtr_;
429 };
430
438 template <typename G>
439 class [[deprecated("Use MultipleCodimMultipleGeomTypeMapper instead! Will be removed after release 2.8.")]]
441 : public MultipleCodimMultipleGeomTypeMapper<typename G::LevelGridView> {
443 public:
444
452 LevelMultipleCodimMultipleGeomTypeMapper (const G& grid, int level, const MCMGLayout& layout)
453 : Base(grid.levelGridView(level),layout)
454 , gridPtr_(&grid)
455 , level_(level)
456 {}
457
463 void update ()
464 {
465 Base::update(gridPtr_->levelGridView(level_));
466 }
467
468 private:
469 const G* gridPtr_;
470 int level_;
471 };
472
474}
475#endif
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:123
constexpr bool isNone() const
Return true if entity is a singular of any dimension.
Definition: type.hh:364
static constexpr std::size_t index(const GeometryType &gt)
Compute the index for the given geometry type over all dimensions.
Definition: typeindex.hh:136
static constexpr std::size_t size(std::size_t maxdim)
Compute total number of geometry types up to and including the given dimension.
Definition: typeindex.hh:123
dynamic integer range for use in range-based for loops
Definition: rangeutilities.hh:173
Multiple codim and multiple geometry type mapper for leaf entities.
Definition: mcmgmapper.hh:402
void update()
Recalculates indices after grid adaptation.
Definition: mcmgmapper.hh:422
LeafMultipleCodimMultipleGeomTypeMapper(const G &grid, const MCMGLayout &layout)
constructor
Definition: mcmgmapper.hh:412
Multiple codim and multiple geometry type mapper for entities of one level.
Definition: mcmgmapper.hh:441
void update()
Recalculates indices after grid adaptation.
Definition: mcmgmapper.hh:463
LevelMultipleCodimMultipleGeomTypeMapper(const G &grid, int level, const MCMGLayout &layout)
constructor
Definition: mcmgmapper.hh:452
Mapper interface.
Definition: mapper.hh:108
Implementation class for a multiple codim and multiple geometry type mapper.
Definition: mcmgmapper.hh:127
bool contains(const EntityType &e, Index &result) const
Returns true if the entity is contained in the index set.
Definition: mcmgmapper.hh:270
size_type size() const
Return total number of entities in the entity set managed by the mapper.
Definition: mcmgmapper.hh:202
Index subIndex(const typename GV::template Codim< 0 >::Entity &e, int i, unsigned int codim) const
Map subentity of codim 0 entity to starting index in array for dof block.
Definition: mcmgmapper.hh:183
MultipleCodimMultipleGeomTypeMapper(const GV &gridView, const MCMGLayout &layout)
construct mapper from grid and layout description
Definition: mcmgmapper.hh:153
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:289
IntegralRange< Index > indices(const EntityType &e) const
Returns a pair with the starting point in the dof vector and the number of degrees of freedom if the ...
Definition: mcmgmapper.hh:229
decltype(std::declval< typename GV::IndexSet >().size(0)) size_type
Number type used for the overall size (the return value of the 'size' method)
Definition: mcmgmapper.hh:140
Index index(const EntityType &e) const
Map entity to starting index in array for dof block.
Definition: mcmgmapper.hh:169
void update(const GV &gridView)
Recalculates indices after grid adaptation.
Definition: mcmgmapper.hh:306
GV::IndexSet::IndexType Index
Number type used for indices.
Definition: mcmgmapper.hh:134
size_type size(GeometryType gt) const
return number of entries for a given geometry type
Definition: mcmgmapper.hh:208
IntegralRange< Index > indices(const typename GV::template Codim< 0 >::Entity &e, int i, int cc) const
Returns a pair with the starting point in the dof vector and the number of degrees of freedom if the ...
Definition: mcmgmapper.hh:248
void update()
Recalculates indices after grid adaptation.
Definition: mcmgmapper.hh:328
GV GridView
Underlying GridView.
Definition: mcmgmapper.hh:131
const std::vector< GeometryType > & types(int codim) const
return the geometry types with entries
Definition: mcmgmapper.hh:214
void update(GV &&gridView)
Recalculates indices after grid adaptation.
Definition: mcmgmapper.hh:318
A few common exception classes.
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:156
Grid< dim, dimworld, ct, GridFamily >::LeafGridView leafGridView(const Grid< dim, dimworld, ct, GridFamily > &grid)
leaf grid view for the given grid
Definition: grid.hh:808
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:791
constexpr GeometryType none(unsigned int dim)
Returns a GeometryType representing a singular of dimension dim.
Definition: type.hh:479
MCMGLayout mcmgLayout(Codim< codim >)
layout for entities of codimension codim
Definition: mcmgmapper.hh:70
MCMGLayout mcmgElementLayout()
layout for elements (codim-0 entities)
Definition: mcmgmapper.hh:95
std::function< size_t(GeometryType, int)> MCMGLayout
layout function for MultipleCodimMultipleGeomTypeMapper
Definition: mcmgmapper.hh:62
MCMGLayout mcmgVertexLayout()
layout for vertices (dim-0 entities)
Definition: mcmgmapper.hh:105
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:79
Provides classes with basic mappers which are used to attach data to a grid.
Dune namespace.
Definition: alignedallocator.hh:11
Utilities for reduction like operations on ranges.
Static tag representing a codimension.
Definition: dimension.hh:22
Static tag representing a dimension.
Definition: dimension.hh:14
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:196
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 12, 23:30, 2024)