7#ifndef DUNE_FUNCTIONS_COMMON_MAPPERUTILITIES_HH
8#define DUNE_FUNCTIONS_COMMON_MAPPERUTILITIES_HH
14#include <dune/grid/common/rangegenerators.hh>
17namespace Dune::Functions {
33 class MapperElementSubIndices
35 using IndexContainer = std::vector<typename Dune::MultipleCodimMultipleGeomTypeMapper<GV>::Index>;
40 using Element =
typename GridView::template Codim<0>::Entity;
42 MapperElementSubIndices(
const Mapper& mapper)
47 void bind(
const Element& element)
51 auto referenceElement = Dune::referenceElement<double, dimension>(element.type());
52 for (
auto codim : Dune::range(dimension + 1)) {
54 std::size_t c = mapper_.layout()(
referenceElement.type(subEntity, codim), dimension);
56 std::size_t firstIndex = mapper_.subIndex(element, subEntity, codim);
57 for (
auto j : Dune::range(firstIndex, firstIndex + c)) {
58 indices_.push_back(j);
67 return indices_.begin();
72 return indices_.end();
77 IndexContainer indices_;
94 template<
class FieldType =
double,
class Mapper>
95 auto computeAverageSubEntityMeshSize(
const Mapper& mapper)
97 constexpr auto dimension = Mapper::GridView::dimension;
98 std::vector<unsigned int> adjacentElements(mapper.size(), 0);
99 std::vector<FieldType> subEntityMeshSize(mapper.size(), 0.0);
100 auto subIndices = Impl::MapperElementSubIndices(mapper);
101 for(
const auto& element : Dune::elements(mapper.gridView()))
103 auto A = element.geometry().volume();
104 subIndices.bind(element);
105 for(
auto i : subIndices)
107 subEntityMeshSize[i] += A;
108 ++(adjacentElements[i]);
111 for(
auto i : Dune::range(mapper.size()))
112 subEntityMeshSize[i] = std::pow(subEntityMeshSize[i]/adjacentElements[i], 1./dimension);
113 return subEntityMeshSize;
GV::IndexSet::IndexType Index
Number type used for indices.
Definition: mcmgmapper.hh:136
static constexpr int dimension
The dimension of the grid.
Definition: gridview.hh:134
unspecified value type referenceElement(T &&... t)
Returns a reference element for the objects t....
Mapper for multiple codim and multiple geometry types.
Utilities for reduction like operations on ranges.