Dune Core Modules (unstable)

mcmgmapper.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5
6#ifndef DUNE_GRID_COMMON_MCMGMAPPER_HH
7#define DUNE_GRID_COMMON_MCMGMAPPER_HH
8
9#include <functional>
10#include <iostream>
11
14#include <dune/geometry/dimension.hh>
15#include <dune/geometry/referenceelements.hh>
16#include <dune/geometry/type.hh>
18
19#include "mapper.hh"
20
27namespace Dune
28{
36 //
37 // Common Layout templates
38 //
39
64 using MCMGLayout = std::function<size_t(GeometryType, int)>;
65
71 template<int codim>
73 {
74 return [](GeometryType gt, int dimgrid) {
75 return dimgrid - gt.dim() == codim;
76 };
77 }
78
84 template<int dim>
86 {
87 return [](GeometryType gt, int) {
88 return gt.dim() == dim;
89 };
90 }
91
98 {
99 return mcmgLayout(Codim<0>());
100 }
101
108 {
109 return mcmgLayout(Dim<0>());
110 }
111
113 //
114 // MultipleCodimMultipleGeomTypeMapper
115 //
116
126 template <typename GV>
128 public Mapper<typename GV::Grid,MultipleCodimMultipleGeomTypeMapper<GV>, typename GV::IndexSet::IndexType >
129 {
130 public:
131
133 typedef GV GridView;
134
136 typedef typename GV::IndexSet::IndexType Index;
137
142 using size_type = decltype(std::declval<typename GV::IndexSet>().size(0));
143
155 MultipleCodimMultipleGeomTypeMapper(const GV& gridView, const MCMGLayout& layout)
156 : gridView_(gridView)
157 , indexSet_(&gridView_.indexSet())
158 , layout_(layout)
159 {
160 update(gridView);
161 }
162
167 : gridView_(other.gridView_)
168 , indexSet_(&gridView_.indexSet())
169 , layout_(other.layout_)
170 {
171 update_();
172 }
173
178 : gridView_(std::move(other.gridView_))
179 , indexSet_(&gridView_.indexSet())
180 , layout_(std::move(other.layout_))
181 {
182 update_();
183 }
184
189 {
190 layout_ = other.layout_;
191 update(other.gridView_);
192 return *this;
193 }
194
199 {
200 layout_ = std::move(other.layout_);
201 update(std::move(other.gridView_));
202 return *this;
203 }
204
212 template<class EntityType>
213 Index index (const EntityType& e) const
214 {
215 const GeometryType gt = e.type();
216 assert(offset(gt) != invalidOffset);
217 return indexSet_->index(e)*blockSize(gt) + offset(gt);
218 }
219
227 Index subIndex (const typename GV::template Codim<0>::Entity& e, int i, unsigned int codim) const
228 {
229 const GeometryType eType = e.type();
230 GeometryType gt = eType.isNone() ?
231 GeometryTypes::none( GV::dimension - codim ) :
233 //GeometryType gt=ReferenceElements<double,GV::dimension>::general(e.type()).type(i,codim);
234 assert(offset(gt) != invalidOffset);
235 return indexSet_->subIndex(e, i, codim)*blockSize(gt) + offset(gt);
236 }
237
247 {
248 return n;
249 }
250
253 {
254 return blockSize(gt);
255 }
256
258 const std::vector< GeometryType >& types ( int codim ) const
259 {
260 return myTypes_[ codim ];
261 }
262
272 template<class EntityType>
273 IntegralRange<Index> indices (const EntityType& e) const
274 {
275 if(!indexSet_->contains(e) || offset(e.type()) == invalidOffset)
276 return {0,0};
277 Index start = index(e);
278 return {start, start+blockSize(e.type())};
279 }
280
292 IntegralRange<Index> indices (const typename GV::template Codim<0>::Entity& e, int i, int cc) const
293 {
294 const GeometryType eType = e.type();
295 const GeometryType gt = eType.isNone() ?
296 GeometryTypes::none(GV::dimension - cc) :
298 if (offset(gt) == invalidOffset)
299 return {0,0};
300 else
301 {
302 Index start = subIndex(e,i,cc);
303 return {start, start+blockSize(gt)};
304 }
305 }
306
313 template<class EntityType>
314 bool contains (const EntityType& e, Index& result) const
315 {
316 if(!indexSet_->contains(e) || offset(e.type()) == invalidOffset)
317 {
318 result = 0;
319 return false;
320 }
321 result = index(e);
322 return true;
323 }
324
333 bool contains (const typename GV::template Codim<0>::Entity& e, int i, int cc, Index& result) 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 false;
341 result = indexSet_->subIndex(e, i, cc)*blockSize(gt) + offset(gt);
342 return true;
343 }
344
350 void update (const GV& gridView)
351 {
352 gridView_ = gridView;
353 indexSet_ = &gridView_.indexSet();
354 update_();
355 }
356
362 void update (GV&& gridView)
363 {
364 gridView_ = std::move(gridView);
365 indexSet_ = &gridView_.indexSet();
366 update_();
367 }
368
369 const MCMGLayout &layout () const { return layout_; }
370 const GridView &gridView () const { return gridView_; }
371
372 private:
373 void update_()
374 {
375 n = 0;
376
377 std::fill(offsets.begin(),offsets.end(),Index(0));
378 std::fill(blocks.begin(),blocks.end(),Index(0));
379
380 for (unsigned int codim = 0; codim <= GV::dimension; ++codim)
381 {
382 // walk over all geometry types in the codimension
383 for (const GeometryType& gt : indexSet_->types(codim)) {
384 Index offset;
385 size_t block = layout()(gt, GV::Grid::dimension);
386
387 // if the geometry type is contained in the layout, increment offset
388 // and store geometry type
389 if (block) {
390 offset = n;
391 n += indexSet_->size(gt) * block;
392 myTypes_[codim].push_back(gt);
393 }
394 else {
395 offset = invalidOffset;
396 }
397
398 offsets[GlobalGeometryTypeIndex::index(gt)] = offset;
399 blocks[GlobalGeometryTypeIndex::index(gt)] = block;
400 }
401 }
402 }
403
404 Index offset(GeometryType gt) const
405 { return offsets[GlobalGeometryTypeIndex::index(gt)]; }
406 Index blockSize(GeometryType gt) const
407 { return blocks[GlobalGeometryTypeIndex::index(gt)]; }
408
409 static const Index invalidOffset = std::numeric_limits<Index>::max();
410
411 // number of data elements required
412 unsigned int n;
413 // GridView is needed to keep the IndexSet valid
414 GV gridView_;
415 const typename GV::IndexSet* indexSet_;
416 // provide an array for the offsets
417 std::array<Index, GlobalGeometryTypeIndex::size(GV::dimension)> offsets;
418 std::array<Index, GlobalGeometryTypeIndex::size(GV::dimension)> blocks;
419 MCMGLayout layout_; // get layout object
420 std::vector<GeometryType> myTypes_[GV::dimension+1];
421 };
422
424}
425#endif
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
constexpr bool isNone() const
Return true if entity is a singular of any dimension.
Definition: type.hh:355
static constexpr std::size_t index(const GeometryType &gt)
Compute the index for the given geometry type over all dimensions.
Definition: typeindex.hh:138
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:125
dynamic integer range for use in range-based for loops
Definition: rangeutilities.hh:171
Mapper interface.
Definition: mapper.hh:110
Implementation class for a multiple codim and multiple geometry type mapper.
Definition: mcmgmapper.hh:129
bool contains(const EntityType &e, Index &result) const
Returns true if the entity is contained in the index set.
Definition: mcmgmapper.hh:314
size_type size() const
Return total number of entities in the entity set managed by the mapper.
Definition: mcmgmapper.hh:246
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:227
MultipleCodimMultipleGeomTypeMapper(const GV &gridView, const MCMGLayout &layout)
construct mapper from grid and layout description
Definition: mcmgmapper.hh:155
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:333
MultipleCodimMultipleGeomTypeMapper(const MultipleCodimMultipleGeomTypeMapper &other)
Copy constructor.
Definition: mcmgmapper.hh:166
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:273
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:142
Index index(const EntityType &e) const
Map entity to starting index in array for dof block.
Definition: mcmgmapper.hh:213
MultipleCodimMultipleGeomTypeMapper(MultipleCodimMultipleGeomTypeMapper &&other)
Move constructor.
Definition: mcmgmapper.hh:177
void update(const GV &gridView)
Recalculates indices after grid adaptation.
Definition: mcmgmapper.hh:350
GV::IndexSet::IndexType Index
Number type used for indices.
Definition: mcmgmapper.hh:136
MultipleCodimMultipleGeomTypeMapper & operator=(MultipleCodimMultipleGeomTypeMapper &&other)
Move assignment.
Definition: mcmgmapper.hh:198
size_type size(GeometryType gt) const
return number of entries for a given geometry type
Definition: mcmgmapper.hh:252
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:292
MultipleCodimMultipleGeomTypeMapper & operator=(const MultipleCodimMultipleGeomTypeMapper &other)
Copy assignment.
Definition: mcmgmapper.hh:188
GV GridView
Underlying GridView.
Definition: mcmgmapper.hh:133
const std::vector< GeometryType > & types(int codim) const
return the geometry types with entries
Definition: mcmgmapper.hh:258
void update(GV &&gridView)
Recalculates indices after grid adaptation.
Definition: mcmgmapper.hh:362
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:158
constexpr GeometryType none(unsigned int dim)
Returns a GeometryType representing a singular of dimension dim.
Definition: type.hh:471
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:489
MCMGLayout mcmgLayout(Codim< codim >)
layout for entities of codimension codim
Definition: mcmgmapper.hh:72
MCMGLayout mcmgElementLayout()
layout for elements (codim-0 entities)
Definition: mcmgmapper.hh:97
std::function< size_t(GeometryType, int)> MCMGLayout
layout function for MultipleCodimMultipleGeomTypeMapper
Definition: mcmgmapper.hh:64
MCMGLayout mcmgVertexLayout()
layout for vertices (dim-0 entities)
Definition: mcmgmapper.hh:107
Provides classes with basic mappers which are used to attach data to a grid.
Dune namespace
Definition: alignedallocator.hh:13
STL namespace.
Utilities for reduction like operations on ranges.
Static tag representing a codimension.
Definition: dimension.hh:24
Static tag representing a dimension.
Definition: dimension.hh:16
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:156
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 & Uni Heidelberg  |  generated with Hugo v0.111.3 (Jun 2, 23:00, 2026)