Dune Core Modules (2.7.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 <functional>
8#include <iostream>
9
13#include <dune/geometry/dimension.hh>
14#include <dune/geometry/referenceelements.hh>
15#include <dune/geometry/type.hh>
17
18#include "mapper.hh"
19
26namespace Dune
27{
35 //
36 // Common Layout templates
37 //
38
40
49 template<int dimgrid> struct DUNE_DEPRECATED_MSG("The MCMG layout classes have been deprecated. Pass `mcmgElementLayout()` to the constructor instead")
53 bool contains (Dune::GeometryType gt) const { return gt.dim()==dimgrid; }
54 };
55
57
66 template<int dim> struct DUNE_DEPRECATED_MSG("The MCMG layout classes have been deprecated. Pass `mcmgVertexLayout()` to the constructor instead")
70 bool contains (Dune::GeometryType gt) const { return gt.dim()==0; }
71 };
72
73 namespace Impl {
74
75 /*
76 * Dummy layout to be used as the default for
77 * `MultipleCodimMultipleGeomTypeMapper`. It should never be used, but
78 * we need a default.
79 *
80 * This class can be removed once the `LayoutClass` template parameter
81 * of `MultipleCodimMultipleGeomTypeMapper` is removed.
82 */
83 template<int dimgrid>
84 struct MCMGFailLayout {
85 MCMGFailLayout()
86 { DUNE_THROW(Exception, "The default layout class cannot be used"); }
87 bool contains(GeometryType gt) const
88 { DUNE_THROW(Exception, "The default layout class cannot be used"); }
89 };
90
91 } /* namespace Impl */
92
117 using MCMGLayout = std::function<size_t(GeometryType, int)>;
118
124 template<int codim>
126 {
127 return [](GeometryType gt, int dimgrid) {
128 return dimgrid - gt.dim() == codim;
129 };
130 }
131
137 template<int dim>
139 {
140 return [](GeometryType gt, int) {
141 return gt.dim() == dim;
142 };
143 }
144
151 {
152 return mcmgLayout(Codim<0>());
153 }
154
161 {
162 return mcmgLayout(Dim<0>());
163 }
164
166 //
167 // MultipleCodimMultipleGeomTypeMapper
168 //
169
197 template <typename GV, template<int> class LayoutClass = Impl::MCMGFailLayout>
199 public Mapper<typename GV::Grid,MultipleCodimMultipleGeomTypeMapper<GV,LayoutClass>, typename GV::IndexSet::IndexType >
200 {
201 public:
202
204 typedef GV GridView;
205
207 typedef typename GV::IndexSet::IndexType Index;
208
213 using size_type = decltype(std::declval<typename GV::IndexSet>().size(0));
214
222 MultipleCodimMultipleGeomTypeMapper(const GV& gridView, const LayoutClass<GV::dimension> layout = {})
223 DUNE_DEPRECATED_MSG("Use the constructor taking a `MCMGLayout` functional instead")
225 {}
226
238 MultipleCodimMultipleGeomTypeMapper(const GV& gridView, const MCMGLayout& layout)
239 : gridView_(gridView)
240 , is(gridView_.indexSet())
241 , layout_(layout)
242 {
243 update();
244 }
245
253 template<class EntityType>
254 Index index (const EntityType& e) const
255 {
256 const GeometryType gt = e.type();
257 assert(offset(gt) != invalidOffset);
258 return is.index(e)*blockSize(gt) + offset(gt);
259 }
260
268 Index subIndex (const typename GV::template Codim<0>::Entity& e, int i, unsigned int codim) const
269 {
270 const GeometryType eType = e.type();
271 GeometryType gt = eType.isNone() ?
272 GeometryTypes::none( GV::dimension - codim ) :
274 //GeometryType gt=ReferenceElements<double,GV::dimension>::general(e.type()).type(i,codim);
275 assert(offset(gt) != invalidOffset);
276 return is.subIndex(e, i, codim)*blockSize(gt) + offset(gt);
277 }
278
288 {
289 return n;
290 }
291
294 {
295 return blockSize(gt);
296 }
297
299 const std::vector< GeometryType >& types ( int codim ) const
300 {
301 return myTypes_[ codim ];
302 }
303
313 template<class EntityType>
314 IntegralRange<Index> indices (const EntityType& e) const
315 {
316 if(!is.contains(e) || offset(e.type()) == invalidOffset)
317 return {0,0};
318 Index start = index(e);
319 return {start, start+blockSize(e.type())};
320 }
321
333 IntegralRange<Index> indices (const typename GV::template Codim<0>::Entity& e, int i, int cc) const
334 {
335 const GeometryType eType = e.type();
336 const GeometryType gt = eType.isNone() ?
337 GeometryTypes::none(GV::dimension - cc) :
339 if (offset(gt) == invalidOffset)
340 return {0,0};
341 else
342 {
343 Index start = subIndex(e,i,cc);
344 return {start, start+blockSize(gt)};
345 }
346 }
347
354 template<class EntityType>
355 bool contains (const EntityType& e, Index& result) const
356 {
357 if(!is.contains(e) || offset(e.type()) == invalidOffset)
358 {
359 result = 0;
360 return false;
361 }
362 result = index(e);
363 return true;
364 }
365
374 bool contains (const typename GV::template Codim<0>::Entity& e, int i, int cc, Index& result) const
375 {
376 const GeometryType eType = e.type();
377 const GeometryType gt = eType.isNone() ?
378 GeometryTypes::none( GV::dimension - cc ) :
380 if (offset(gt) == invalidOffset)
381 return false;
382 result = is.subIndex(e, i, cc)*blockSize(gt) + offset(gt);
383 return true;
384 }
385
388 void update ()
389 {
390 n = 0;
391
392 std::fill(offsets.begin(),offsets.end(),Index(0));
393 std::fill(blocks.begin(),blocks.end(),Index(0));
394
395 for (unsigned int codim = 0; codim <= GV::dimension; ++codim)
396 {
397 // walk over all geometry types in the codimension
398 for (const GeometryType& gt : is.types(codim)) {
399 Index offset;
400 size_t block = layout()(gt, GV::Grid::dimension);
401
402 // if the geometry type is contained in the layout, increment offset
403 // and store geometry type
404 if (block) {
405 offset = n;
406 n += is.size(gt) * block;
407 myTypes_[codim].push_back(gt);
408 }
409 else {
410 offset = invalidOffset;
411 }
412
413 offsets[GlobalGeometryTypeIndex::index(gt)] = offset;
414 blocks[GlobalGeometryTypeIndex::index(gt)] = block;
415 }
416 }
417 }
418
419 const MCMGLayout &layout () const { return layout_; }
420 const GridView &gridView () const { return gridView_; }
421
422 private:
423 Index offset(GeometryType gt) const
424 { return offsets[GlobalGeometryTypeIndex::index(gt)]; }
425 Index blockSize(GeometryType gt) const
426 { return blocks[GlobalGeometryTypeIndex::index(gt)]; }
427
428 static const Index invalidOffset = std::numeric_limits<Index>::max();
429
430 // number of data elements required
431 unsigned int n;
432 // GridView is needed to keep the IndexSet valid
433 const GV gridView_;
434 const typename GV::IndexSet& is;
435 // provide an array for the offsets
436 std::array<Index, GlobalGeometryTypeIndex::size(GV::dimension)> offsets;
437 std::array<Index, GlobalGeometryTypeIndex::size(GV::dimension)> blocks;
438 const MCMGLayout layout_; // get layout object
439 std::vector<GeometryType> myTypes_[GV::dimension+1];
440
441 protected:
445 static MCMGLayout wrapLayoutClass(const LayoutClass<GV::dimension>& layout)
446 {
447 /* `mutable` as the `contains()` method is not required to be const */
448 return [layout = layout](GeometryType gt, int) mutable {
449 return layout.contains(gt);
450 };
451 }
452 };
453
455 //
456 // Leaf and level mapper
457 //
458
469 template <typename G, template<int> class LayoutClass = Impl::MCMGFailLayout>
471 : public MultipleCodimMultipleGeomTypeMapper<typename G::LeafGridView,LayoutClass>
472 {
473 typedef MultipleCodimMultipleGeomTypeMapper<typename G::LeafGridView,
474 LayoutClass> Base;
475 public:
483 LeafMultipleCodimMultipleGeomTypeMapper (const G& grid, const LayoutClass<G::dimension> layout = {})
484 DUNE_DEPRECATED_MSG("Use the constructor taking a `MCMGLayout` functional instead")
486 {}
487
495 : Base(grid.leafGridView(), layout)
496 {}
497 };
498
510 template <typename G, template<int> class LayoutClass = Impl::MCMGFailLayout>
512 : public MultipleCodimMultipleGeomTypeMapper<typename G::LevelGridView,LayoutClass> {
513 typedef MultipleCodimMultipleGeomTypeMapper<typename G::LevelGridView,
514 LayoutClass> Base;
515 public:
524 LevelMultipleCodimMultipleGeomTypeMapper (const G& grid, int level, const LayoutClass<G::dimension> layout = {})
525 DUNE_DEPRECATED_MSG("Use the constructor taking a `MCMGLayout` functional instead")
527 {}
528
536 LevelMultipleCodimMultipleGeomTypeMapper (const G& grid, int level, const MCMGLayout& layout)
537 : Base(grid.levelGridView(level),layout)
538 {}
539 };
540
542}
543#endif
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:279
constexpr bool isNone() const
Return true if entity is a singular of any dimension.
Definition: type.hh:639
static constexpr std::size_t index(const GeometryType &gt)
Compute the index for the given geometry type over all dimensions.
Definition: typeindex.hh:133
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:120
dynamic integer range for use in range-based for loops
Definition: rangeutilities.hh:172
Multiple codim and multiple geometry type mapper for leaf entities.
Definition: mcmgmapper.hh:472
LeafMultipleCodimMultipleGeomTypeMapper(const G &grid, const MCMGLayout &layout)
constructor
Definition: mcmgmapper.hh:494
LeafMultipleCodimMultipleGeomTypeMapper(const G &grid, const LayoutClass< G::dimension > layout={})
The constructor.
Definition: mcmgmapper.hh:483
Multiple codim and multiple geometry type mapper for entities of one level.
Definition: mcmgmapper.hh:512
LevelMultipleCodimMultipleGeomTypeMapper(const G &grid, int level, const LayoutClass< G::dimension > layout={})
The constructor.
Definition: mcmgmapper.hh:524
LevelMultipleCodimMultipleGeomTypeMapper(const G &grid, int level, const MCMGLayout &layout)
constructor
Definition: mcmgmapper.hh:536
Mapper interface.
Definition: mapper.hh:107
Implementation class for a multiple codim and multiple geometry type mapper.
Definition: mcmgmapper.hh:200
static MCMGLayout wrapLayoutClass(const LayoutClass< GV::dimension > &layout)
wrap legacy layout classes
Definition: mcmgmapper.hh:445
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:213
GV GridView
Underlying GridView.
Definition: mcmgmapper.hh:204
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:268
const std::vector< GeometryType > & types(int codim) const
return the geometry types with entries
Definition: mcmgmapper.hh:299
void update()
Recalculates map after mesh adaptation.
Definition: mcmgmapper.hh:388
bool contains(const EntityType &e, Index &result) const
Returns true if the entity is contained in the index set.
Definition: mcmgmapper.hh:355
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:314
size_type size() const
Return total number of entities in the entity set managed by the mapper.
Definition: mcmgmapper.hh:287
size_type size(GeometryType gt) const
return number of entries for a given geometry type
Definition: mcmgmapper.hh:293
MultipleCodimMultipleGeomTypeMapper(const GV &gridView, const LayoutClass< GV::dimension > layout={})
Construct mapper from grid and one of its index sets.
Definition: mcmgmapper.hh:222
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:374
Index index(const EntityType &e) const
Map entity to starting index in array for dof block.
Definition: mcmgmapper.hh:254
MultipleCodimMultipleGeomTypeMapper(const GV &gridView, const MCMGLayout &layout)
construct mapper from grid and layout description
Definition: mcmgmapper.hh:238
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:333
GV::IndexSet::IndexType Index
Number type used for indices.
Definition: mcmgmapper.hh:207
Definition of the DUNE_DEPRECATED macro for the case that config.h is not available.
A few common exception classes.
#define DUNE_DEPRECATED_MSG(text)
Mark some entity as deprecated.
Definition: deprecated.hh:169
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
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:809
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:792
constexpr GeometryType none(unsigned int dim)
Returns a GeometryType representing a singular of dimension dim.
Definition: type.hh:784
MCMGLayout mcmgLayout(Codim< codim >)
layout for entities of codimension codim
Definition: mcmgmapper.hh:125
MCMGLayout mcmgElementLayout()
layout for elements (codim-0 entities)
Definition: mcmgmapper.hh:150
std::function< size_t(GeometryType, int)> MCMGLayout
layout function for MultipleCodimMultipleGeomTypeMapper
Definition: mcmgmapper.hh:117
MCMGLayout mcmgVertexLayout()
layout for vertices (dim-0 entities)
Definition: mcmgmapper.hh:160
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:14
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
Layout template for elements.
Definition: mcmgmapper.hh:50
bool contains(Dune::GeometryType gt) const
Definition: mcmgmapper.hh:53
Layout template for vertices.
Definition: mcmgmapper.hh:67
bool contains(Dune::GeometryType gt) const
Definition: mcmgmapper.hh:70
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)