7#ifndef DUNE_FUNCTIONS_COMMON_MAPPERUTILITIES_HH
8#define DUNE_FUNCTIONS_COMMON_MAPPERUTILITIES_HH
13#include <dune/common/rangeutilities.hh>
15#include <dune/grid/common/rangegenerators.hh>
16#include <dune/grid/common/mcmgmapper.hh>
34 class MapperElementSubIndices
36 using IndexContainer = std::vector<typename Dune::MultipleCodimMultipleGeomTypeMapper<GV>::Index>;
39 using Mapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
40 using Index =
typename Mapper::Index;
41 using Element =
typename GridView::template Codim<0>::Entity;
43 MapperElementSubIndices(
const Mapper& mapper)
48 void bind(
const Element& element)
50 constexpr auto dimension = GridView::dimension;
52 auto referenceElement = Dune::referenceElement<double, dimension>(element.type());
53 for (
auto codim : Dune::range(dimension + 1)) {
54 for (
auto subEntity : Dune::range(referenceElement.size(codim))) {
55 std::size_t c = mapper_.layout()(referenceElement.type(subEntity, codim), dimension);
57 std::size_t firstIndex = mapper_.subIndex(element, subEntity, codim);
58 for (
auto j : Dune::range(firstIndex, firstIndex + c)) {
59 indices_.push_back(j);
68 return indices_.begin();
73 return indices_.end();
78 IndexContainer indices_;
95 template<
class FieldType =
double,
class Mapper>
96 auto computeAverageSubEntityMeshSize(
const Mapper& mapper)
98 constexpr auto dimension = Mapper::GridView::dimension;
99 std::vector<unsigned int> adjacentElements(mapper.size(), 0);
100 std::vector<FieldType> subEntityMeshSize(mapper.size(), 0.0);
101 auto subIndices = Impl::MapperElementSubIndices(mapper);
102 for(
const auto& element : Dune::elements(mapper.gridView()))
104 auto A = element.geometry().volume();
105 subIndices.bind(element);
106 for(
auto i : subIndices)
108 subEntityMeshSize[i] += A;
109 ++(adjacentElements[i]);
112 for(
auto i : Dune::range(mapper.size()))
113 subEntityMeshSize[i] = std::pow(subEntityMeshSize[i]/adjacentElements[i], 1./dimension);
114 return subEntityMeshSize;
128 template<
class ElementMapper>
129 std::vector<std::bitset<3>> computeEdgeOrientations(ElementMapper mapper)
131 constexpr int dim = 2;
132 static_assert(dim == ElementMapper::GridView::dimension);
134 auto const& gridView = mapper.gridView();
135 std::vector<std::bitset<3>> orientations;
136 orientations.resize(gridView.size(0));
138 auto const& idSet = gridView.grid().globalIdSet();
140 for (
const auto &element :
elements(gridView))
142 const auto &refElement = referenceElement(element);
143 auto elementIndex = mapper.index(element);
145 std::bitset<3>& orientation = orientations[elementIndex];
148 for (std::size_t i = 0; i < element.subEntities(dim - 1); i++)
151 auto localV0 = refElement.subEntity(i, dim - 1, 0, dim);
152 auto localV1 = refElement.subEntity(i, dim - 1, 1, dim);
155 auto globalV0 = idSet.subId(element, localV0, dim);
156 auto globalV1 = idSet.subId(element, localV1, dim);
159 orientation[i] = globalV0 > globalV1;
auto elements(const SubDomainGridView< HostGridView > &subDomainGridView)
ADL findable access to element range for a SubDomainGridView.
Definition subdomain.hh:487
Definition monomialset.hh:19