13#ifndef DUMUX_VERTEX_ENRICHMENT_HELPER_HH
14#define DUMUX_VERTEX_ENRICHMENT_HELPER_HH
18#include <unordered_map>
19#include <unordered_set>
21#include <dune/common/exceptions.hh>
22#include <dune/common/reservedvector.hh>
24#include <dune/grid/common/mcmgmapper.hh>
42template<
class Gr
idView,
class CodimOneGr
idView >
45 static constexpr int dim = GridView::dimension;
46 static constexpr int dimWorld = GridView::dimensionworld;
47 static_assert(dim == 2 || dim == 3,
"Grid dimension must be two or three");
48 static_assert(dimWorld == int(CodimOneGridView::dimensionworld),
"world dimension mismatch");
50 using Intersection =
typename GridView::Intersection;
51 using MCMGMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
53 using Element =
typename GridView::template Codim<0>::Entity;
54 using GlobalPosition =
typename Element::Geometry::GlobalCoordinate;
56 using ElementPath = std::vector< GridIndexType >;
57 using NodalElementPaths = std::vector< std::vector<ElementPath> >;
76 template<
class IndexMap,
class CodimOneGr
idAdapter >
77 static std::size_t
enrich(IndexMap& indexMap,
78 const std::vector<bool>& vertexMarkers,
79 const GridView& gridView,
80 const MCMGMapper& vertexMapper,
81 const MCMGMapper& elementMapper,
82 const CodimOneGridView& codimOneGridView,
86 NodalElementPaths nodalPaths(gridView.size(dim));
87 for (
const auto& e : elements(gridView))
89 const auto eIdx = elementMapper.index(e);
91 std::vector<unsigned int> handledFacets;
92 const auto refElement = referenceElement(e);
93 for (
const auto& is : intersections(gridView, e))
100 if (std::find(handledFacets.begin(), handledFacets.end(), is.indexInInside()) != handledFacets.end())
104 const auto numCorners = is.geometry().corners();
105 std::vector<GridIndexType> faceVertexIndices(
numCorners);
107 faceVertexIndices[i] = vertexMapper.subIndex( e,
108 refElement.subEntity(is.indexInInside(), 1, i, dim),
114 handledFacets.push_back(is.indexInInside());
118 const auto vIdxGlobal = faceVertexIndices[i];
119 if (!vertexMarkers[vIdxGlobal])
124 for (
const auto& path : nodalPaths[vIdxGlobal])
125 if (std::find(path.begin(), path.end(), eIdx) != path.end())
126 { found =
true;
break; }
137 path.push_back(eIdx);
138 continuePathSearch_(path, gridView, elementMapper, vertexMapper, codimOneGridAdapter, e, refElement, is, vIdxGlobal);
139 nodalPaths[vIdxGlobal].emplace_back(std::move(path));
147 std::vector<std::size_t> bulkVertexIndexOffsets(gridView.size(dim), 0);
148 for (
const auto& v : vertices(gridView))
150 const auto vIdx = vertexMapper.index(v);
151 if (vertexMarkers[vIdx])
152 bulkVertexIndexOffsets[vIdx] = nodalPaths[vIdx].size()-1;
156 std::size_t sumOffset = 0;
157 std::size_t size = 0;
158 for (
auto& nodalOffset : bulkVertexIndexOffsets)
160 const auto os = nodalOffset;
161 nodalOffset = sumOffset;
163 size += (os == 0) ? 1 : os + 1;
167 for (
const auto& e : elements(gridView))
169 const auto& eg = e.geometry();
170 const auto eIdx = elementMapper.index(e);
171 for (
int i = 0; i < eg.corners(); ++i)
173 const auto origVIdx = vertexMapper.subIndex(e, i, dim);
176 if (!vertexMarkers[origVIdx])
177 indexMap[eIdx][i] += bulkVertexIndexOffsets[origVIdx];
183 const auto& paths = nodalPaths[ origVIdx ];
184 for (
int pathIdx = 0; pathIdx < paths.size(); ++pathIdx)
186 const auto& curPath = paths[pathIdx];
187 if ( std::find(curPath.begin(), curPath.end(), eIdx) != curPath.end() )
189 indexMap[eIdx][i] += bulkVertexIndexOffsets[origVIdx] + pathIdx;
196 DUNE_THROW(Dune::InvalidStateException,
"Element not found in any path");
206 template<
class ReferenceElement,
class CodimOneGr
idAdapter >
207 static void continuePathSearch_(ElementPath& path,
208 const GridView& gridView,
209 const MCMGMapper& elementMapper,
210 const MCMGMapper& vertexMapper,
212 const Element& element,
213 const ReferenceElement& refElement,
214 const Intersection& prevIntersection,
215 GridIndexType vIdxGlobal)
218 static constexpr int numIsToFind = dim == 3 ? 2 : 1;
221 unsigned int foundCounter = 0;
222 std::vector<unsigned int> handledFacets;
223 for (
const auto& is : intersections(gridView, element))
226 if (is.indexInInside() == prevIntersection.indexInInside())
230 if (std::count(handledFacets.begin(), handledFacets.end(), is.indexInInside()))
234 const auto numCorners = is.geometry().corners();
235 std::vector<GridIndexType> faceVertexIndices(
numCorners);
237 faceVertexIndices[i] = vertexMapper.subIndex( element,
238 refElement.subEntity(is.indexInInside(), 1, i, dim),
242 if (std::find(faceVertexIndices.begin(), faceVertexIndices.end(), vIdxGlobal) != faceVertexIndices.end())
245 handledFacets.push_back(is.indexInInside());
257 const auto outsideElement = is.outside();
258 const auto outsideElemIdx = elementMapper.index(outsideElement);
259 if (std::find(path.begin(), path.end(), outsideElemIdx) == path.end())
261 const auto idxInOutside = is.indexInOutside();
262 const auto outsideRefElement = referenceElement(outsideElement);
263 path.push_back(outsideElemIdx);
266 for (
const auto& outsideIs : intersections(gridView, outsideElement))
268 if (outsideIs.indexInInside() == idxInOutside)
271 if (foundCounter == numIsToFind)
272 return continuePathSearch_(path,
284 continuePathSearch_(path,
299 if (foundCounter != numIsToFind)
300 DUNE_THROW(Dune::InvalidStateException,
"Found " << foundCounter <<
" instead of " << numIsToFind <<
" intersections around vertex");
Adapter that allows retrieving information on a d-dimensional grid for entities of a (d-1)-dimensiona...
Definition: codimonegridadapter.hh:40
bool composeFacetElement(const IndexStorage &bulkVertexIndices) const
Returns true if a given set of bulk vertex indices make up a facet grid element.
Definition: codimonegridadapter.hh:180
Specialization of the enrichment helper class for 2d grids. In this case, we look for two-dimensional...
Definition: enrichmenthelper.hh:44
static std::size_t enrich(IndexMap &indexMap, const std::vector< bool > &vertexMarkers, const GridView &gridView, const MCMGMapper &vertexMapper, const MCMGMapper &elementMapper, const CodimOneGridView &codimOneGridView, const CodimOneGridAdapter &codimOneGridAdapter)
Enriches the dof map subject to a (dim-1)-dimensional grid.
Definition: enrichmenthelper.hh:77
Define some often used mathematical functions.
std::size_t numCorners(Shape shape)
Returns the number of corners of a given geometry.
Definition: throatproperties.hh:220
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:27