6#ifndef DUNE_GRID_COMMON_MCMGMAPPER_HH
7#define DUNE_GRID_COMMON_MCMGMAPPER_HH
12#include <dune/common/exceptions.hh>
13#include <dune/common/rangeutilities.hh>
14#include <dune/geometry/dimension.hh>
15#include <dune/geometry/referenceelements.hh>
16#include <dune/geometry/type.hh>
17#include <dune/geometry/typeindex.hh>
64 using MCMGLayout = std::function<size_t(GeometryType,
int)>;
74 return [](GeometryType gt,
int dimgrid) {
75 return dimgrid - gt.dim() == codim;
87 return [](GeometryType gt, int) {
88 return gt.dim() == dim;
126 template <
typename GV>
128 public Mapper<typename GV::Grid,MultipleCodimMultipleGeomTypeMapper<GV>, typename GV::IndexSet::IndexType >
136 typedef typename GV::IndexSet::IndexType
Index;
142 using size_type =
decltype(std::declval<typename GV::IndexSet>().size(0));
157 , indexSet_(&gridView_.indexSet())
170 template<
class EntityType>
173 const GeometryType gt = e.type();
174 assert(offset(gt) != invalidOffset);
175 return indexSet_->index(e)*blockSize(gt) + offset(gt);
185 Index subIndex (
const typename GV::template Codim<0>::Entity& e,
int i,
unsigned int codim)
const
187 const GeometryType eType = e.type();
188 GeometryType gt = eType.isNone() ?
189 GeometryTypes::none( GV::dimension - codim ) :
190 ReferenceElements<double,GV::dimension>::general(eType).type(i,codim) ;
192 assert(offset(gt) != invalidOffset);
193 return indexSet_->subIndex(e, i, codim)*blockSize(gt) + offset(gt);
212 return blockSize(gt);
216 const std::vector< GeometryType >&
types (
int codim )
const
218 return myTypes_[ codim ];
230 template<
class EntityType>
231 IntegralRange<Index>
indices (
const EntityType& e)
const
233 if(!indexSet_->contains(e) || offset(e.type()) == invalidOffset)
236 return {start, start+blockSize(e.type())};
250 IntegralRange<Index>
indices (
const typename GV::template Codim<0>::Entity& e,
int i,
int cc)
const
252 const GeometryType eType = e.type();
253 const GeometryType gt = eType.isNone() ?
254 GeometryTypes::none(GV::dimension - cc) :
255 ReferenceElements<double,GV::dimension>::general(eType).type(i,cc) ;
256 if (offset(gt) == invalidOffset)
261 return {start, start+blockSize(gt)};
271 template<
class EntityType>
274 if(!indexSet_->contains(e) || offset(e.type()) == invalidOffset)
291 bool contains (
const typename GV::template Codim<0>::Entity& e,
int i,
int cc,
Index& result)
const
293 const GeometryType eType = e.type();
294 const GeometryType gt = eType.isNone() ?
295 GeometryTypes::none( GV::dimension - cc ) :
296 ReferenceElements<double,GV::dimension>::general(eType).type(i,cc) ;
297 if (offset(gt) == invalidOffset)
299 result = indexSet_->subIndex(e, i, cc)*blockSize(gt) + offset(gt);
311 indexSet_ = &gridView_.indexSet();
323 indexSet_ = &gridView_.indexSet();
335 std::fill(offsets.begin(),offsets.end(),
Index(0));
336 std::fill(blocks.begin(),blocks.end(),
Index(0));
338 for (
unsigned int codim = 0; codim <= GV::dimension; ++codim)
341 for (
const GeometryType& gt : indexSet_->
types(codim)) {
343 size_t block =
layout()(gt, GV::Grid::dimension);
349 n += indexSet_->size(gt) * block;
350 myTypes_[codim].push_back(gt);
353 offset = invalidOffset;
356 offsets[GlobalGeometryTypeIndex::index(gt)] = offset;
357 blocks[GlobalGeometryTypeIndex::index(gt)] = block;
362 Index offset(GeometryType gt)
const
363 {
return offsets[GlobalGeometryTypeIndex::index(gt)]; }
364 Index blockSize(GeometryType gt)
const
365 {
return blocks[GlobalGeometryTypeIndex::index(gt)]; }
367 static const Index invalidOffset = std::numeric_limits<Index>::max();
373 const typename GV::IndexSet* indexSet_;
375 std::array<
Index, GlobalGeometryTypeIndex::size(GV::dimension)> offsets;
376 std::array<
Index, GlobalGeometryTypeIndex::size(GV::dimension)> blocks;
378 std::vector<GeometryType> myTypes_[GV::dimension+1];
Provides classes with basic mappers which are used to attach data to a grid.
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
Include standard header files.
Definition agrid.hh:60
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
const GridView & gridView() const
Definition mcmgmapper.hh:328
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
const MCMGLayout & layout() const
Definition mcmgmapper.hh:327
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
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