7#ifndef DUNE_FUNCTIONS_COMMON_MAPPERUTILITIES_HH
8#define DUNE_FUNCTIONS_COMMON_MAPPERUTILITIES_HH
12#include <dune/common/rangeutilities.hh>
14#include <dune/grid/common/rangegenerators.hh>
15#include <dune/grid/common/mcmgmapper.hh>
17namespace Dune::Functions {
33 class MapperElementSubIndices
35 using IndexContainer = std::vector<typename Dune::MultipleCodimMultipleGeomTypeMapper<GV>::Index>;
38 using Mapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
39 using Index =
typename Mapper::Index;
40 using Element =
typename GridView::template Codim<0>::Entity;
42 MapperElementSubIndices(
const Mapper& mapper)
47 void bind(
const Element& element)
49 constexpr auto dimension = GridView::dimension;
51 auto referenceElement = Dune::referenceElement<double, dimension>(element.type());
52 for (
auto codim : Dune::range(dimension + 1)) {
53 for (
auto subEntity : Dune::range(referenceElement.size(codim))) {
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;