Dune Core Modules (2.9.0)

mcmgmapper.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 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
170 template<class EntityType>
171 Index index (const EntityType& e) const
172 {
173 const GeometryType gt = e.type();
174 assert(offset(gt) != invalidOffset);
175 return indexSet_->index(e)*blockSize(gt) + offset(gt);
176 }
177
185 Index subIndex (const typename GV::template Codim<0>::Entity& e, int i, unsigned int codim) const
186 {
187 const GeometryType eType = e.type();
188 GeometryType gt = eType.isNone() ?
189 GeometryTypes::none( GV::dimension - codim ) :
191 //GeometryType gt=ReferenceElements<double,GV::dimension>::general(e.type()).type(i,codim);
192 assert(offset(gt) != invalidOffset);
193 return indexSet_->subIndex(e, i, codim)*blockSize(gt) + offset(gt);
194 }
195
205 {
206 return n;
207 }
208
211 {
212 return blockSize(gt);
213 }
214
216 const std::vector< GeometryType >& types ( int codim ) const
217 {
218 return myTypes_[ codim ];
219 }
220
230 template<class EntityType>
231 IntegralRange<Index> indices (const EntityType& e) const
232 {
233 if(!indexSet_->contains(e) || offset(e.type()) == invalidOffset)
234 return {0,0};
235 Index start = index(e);
236 return {start, start+blockSize(e.type())};
237 }
238
250 IntegralRange<Index> indices (const typename GV::template Codim<0>::Entity& e, int i, int cc) const
251 {
252 const GeometryType eType = e.type();
253 const GeometryType gt = eType.isNone() ?
254 GeometryTypes::none(GV::dimension - cc) :
256 if (offset(gt) == invalidOffset)
257 return {0,0};
258 else
259 {
260 Index start = subIndex(e,i,cc);
261 return {start, start+blockSize(gt)};
262 }
263 }
264
271 template<class EntityType>
272 bool contains (const EntityType& e, Index& result) const
273 {
274 if(!indexSet_->contains(e) || offset(e.type()) == invalidOffset)
275 {
276 result = 0;
277 return false;
278 }
279 result = index(e);
280 return true;
281 }
282
291 bool contains (const typename GV::template Codim<0>::Entity& e, int i, int cc, Index& result) const
292 {
293 const GeometryType eType = e.type();
294 const GeometryType gt = eType.isNone() ?
295 GeometryTypes::none( GV::dimension - cc ) :
297 if (offset(gt) == invalidOffset)
298 return false;
299 result = indexSet_->subIndex(e, i, cc)*blockSize(gt) + offset(gt);
300 return true;
301 }
302
308 void update (const GV& gridView)
309 {
310 gridView_ = gridView;
311 indexSet_ = &gridView_.indexSet();
312 update_();
313 }
314
320 void update (GV&& gridView)
321 {
322 gridView_ = std::move(gridView);
323 indexSet_ = &gridView_.indexSet();
324 update_();
325 }
326
329 [[deprecated("Use update(gridView) instead! Will be removed after release 2.8.")]]
330 void update ()
331 {
332 update_();
333 }
334
335 const MCMGLayout &layout () const { return layout_; }
336 const GridView &gridView () const { return gridView_; }
337
338 private:
339 void update_()
340 {
341 n = 0;
342
343 std::fill(offsets.begin(),offsets.end(),Index(0));
344 std::fill(blocks.begin(),blocks.end(),Index(0));
345
346 for (unsigned int codim = 0; codim <= GV::dimension; ++codim)
347 {
348 // walk over all geometry types in the codimension
349 for (const GeometryType& gt : indexSet_->types(codim)) {
350 Index offset;
351 size_t block = layout()(gt, GV::Grid::dimension);
352
353 // if the geometry type is contained in the layout, increment offset
354 // and store geometry type
355 if (block) {
356 offset = n;
357 n += indexSet_->size(gt) * block;
358 myTypes_[codim].push_back(gt);
359 }
360 else {
361 offset = invalidOffset;
362 }
363
364 offsets[GlobalGeometryTypeIndex::index(gt)] = offset;
365 blocks[GlobalGeometryTypeIndex::index(gt)] = block;
366 }
367 }
368 }
369
370 Index offset(GeometryType gt) const
371 { return offsets[GlobalGeometryTypeIndex::index(gt)]; }
372 Index blockSize(GeometryType gt) const
373 { return blocks[GlobalGeometryTypeIndex::index(gt)]; }
374
375 static const Index invalidOffset = std::numeric_limits<Index>::max();
376
377 // number of data elements required
378 unsigned int n;
379 // GridView is needed to keep the IndexSet valid
380 GV gridView_;
381 const typename GV::IndexSet* indexSet_;
382 // provide an array for the offsets
383 std::array<Index, GlobalGeometryTypeIndex::size(GV::dimension)> offsets;
384 std::array<Index, GlobalGeometryTypeIndex::size(GV::dimension)> blocks;
385 const MCMGLayout layout_; // get layout object
386 std::vector<GeometryType> myTypes_[GV::dimension+1];
387 };
388
390 //
391 // Leaf and level mapper
392 //
393
400 template <typename G>
401 class [[deprecated("Use MultipleCodimMultipleGeomTypeMapper instead! Will be removed after release 2.8.")]]
403 : public MultipleCodimMultipleGeomTypeMapper<typename G::LeafGridView>
404 {
406 public:
407
415 : Base(grid.leafGridView(), layout)
416 , gridPtr_(&grid)
417 {}
418
424 void update ()
425 {
426 Base::update(gridPtr_->leafGridView());
427 }
428
429 private:
430 const G* gridPtr_;
431 };
432
440 template <typename G>
441 class [[deprecated("Use MultipleCodimMultipleGeomTypeMapper instead! Will be removed after release 2.8.")]]
443 : public MultipleCodimMultipleGeomTypeMapper<typename G::LevelGridView> {
445 public:
446
454 LevelMultipleCodimMultipleGeomTypeMapper (const G& grid, int level, const MCMGLayout& layout)
455 : Base(grid.levelGridView(level),layout)
456 , gridPtr_(&grid)
457 , level_(level)
458 {}
459
465 void update ()
466 {
467 Base::update(gridPtr_->levelGridView(level_));
468 }
469
470 private:
471 const G* gridPtr_;
472 int level_;
473 };
474
476}
477#endif
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:125
constexpr bool isNone() const
Return true if entity is a singular of any dimension.
Definition: type.hh:366
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:175
Multiple codim and multiple geometry type mapper for leaf entities.
Definition: mcmgmapper.hh:404
void update()
Recalculates indices after grid adaptation.
Definition: mcmgmapper.hh:424
LeafMultipleCodimMultipleGeomTypeMapper(const G &grid, const MCMGLayout &layout)
constructor
Definition: mcmgmapper.hh:414
Multiple codim and multiple geometry type mapper for entities of one level.
Definition: mcmgmapper.hh:443
void update()
Recalculates indices after grid adaptation.
Definition: mcmgmapper.hh:465
LevelMultipleCodimMultipleGeomTypeMapper(const G &grid, int level, const MCMGLayout &layout)
constructor
Definition: mcmgmapper.hh:454
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:272
size_type size() const
Return total number of entities in the entity set managed by the mapper.
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:185
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:291
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:231
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:171
void update(const GV &gridView)
Recalculates indices after grid adaptation.
Definition: mcmgmapper.hh:308
GV::IndexSet::IndexType Index
Number type used for indices.
Definition: mcmgmapper.hh:136
size_type size(GeometryType gt) const
return number of entries for a given geometry type
Definition: mcmgmapper.hh:210
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:250
void update()
Recalculates indices after grid adaptation.
Definition: mcmgmapper.hh:330
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:216
void update(GV &&gridView)
Recalculates indices after grid adaptation.
Definition: mcmgmapper.hh:320
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
Grid< dim, dimworld, ct, GridFamily >::LeafGridView leafGridView(const Grid< dim, dimworld, ct, GridFamily > &grid)
leaf grid view for the given grid
Definition: grid.hh:819
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:802
constexpr GeometryType none(unsigned int dim)
Returns a GeometryType representing a singular of dimension dim.
Definition: type.hh:481
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
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:81
Provides classes with basic mappers which are used to attach data to a grid.
Dune namespace.
Definition: alignedallocator.hh:13
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:198
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 (Dec 21, 23:30, 2024)