12#ifndef DUMUX_IO_FACET_GRID_MANAGER_HH
13#define DUMUX_IO_FACET_GRID_MANAGER_HH
20#include <dune/grid/common/mcmgmapper.hh>
21#include <dune/geometry/referenceelements.hh>
29namespace Detail::FacetGrid {
31static constexpr std::size_t undefinedIndex = std::numeric_limits<std::size_t>::max();
33template<
typename Gr
id,
typename HostGr
idView,
typename HostGr
idVertexSet,
typename Selector>
34auto fillFactory(Dune::GridFactory<Grid>& factory,
35 const HostGridView& hostGridView,
36 const HostGridVertexSet& hostGridVertexSet,
39 static constexpr int domainDim = HostGridView::dimension;
41 Dune::MultipleCodimMultipleGeomTypeMapper elementMapper{hostGridView, Dune::mcmgElementLayout()};
43 std::vector<unsigned int> localCornerStorage;
44 std::vector<std::size_t> domainToFacetVertex(hostGridVertexSet.size(), undefinedIndex);
46 std::size_t vertexCount = 0;
47 for (
const auto& element : elements(hostGridView))
49 const auto& refElement = Dune::referenceElement(element);
50 const auto& elemGeo =
element.geometry();
52 for (
const auto& is : intersections(hostGridView, element))
54 if (!selector(element, is))
59 if (elementMapper.index(is.inside()) > elementMapper.index(is.outside()))
62 const auto& isGeo = is.geometry();
63 localCornerStorage.clear();
64 localCornerStorage.reserve(isGeo.corners());
65 for (
int c = 0; c < isGeo.corners(); ++c)
67 const auto vIdxLocal = refElement.subEntity(is.indexInInside(), 1, c, domainDim);
68 const auto vIdxGlobal = hostGridVertexSet.index(
element.template subEntity<domainDim>(vIdxLocal));
69 if (domainToFacetVertex.at(vIdxGlobal) == undefinedIndex)
71 factory.insertVertex(elemGeo.global(refElement.position(vIdxLocal, domainDim)));
72 domainToFacetVertex[vIdxGlobal] = vertexCount;
75 localCornerStorage.push_back(domainToFacetVertex[vIdxGlobal]);
78 factory.insertElement(isGeo.type(), localCornerStorage);
82 return domainToFacetVertex;
95template<
typename T,
typename Element,
typename Intersection>
97 = std::invocable<T, const Element&, const Intersection&>
98 and std::convertible_to<bool, std::invoke_result_t<T, const Element&, const Intersection&>>;
108template<
typename HG,
typename FacetGr
id,
typename HostGr
idManager = Gr
idManager<HG>>
111 static constexpr int dim = FacetGrid::dimension;
112 static constexpr int dimWorld = FacetGrid::dimensionworld;
114 static_assert(dim == int(HG::dimension) - 1,
"Facet grids must have codimension 1 w.r.t host grid");
115 static_assert(dimWorld == int(HG::dimensionworld),
"Space dimensions of facet & host grid must match");
117 using HostElement =
typename HG::template Codim<0>::Entity;
118 using HostIntersection =
typename HG::LeafGridView::Intersection;
123 using Vertex =
typename Grid::template Codim<dim>::Entity;
129 template<Concept::FacetSelector<HostElement, HostIntersection> Selector>
132 hostVertexSet_ = std::make_unique<HostVertexSet>(hostGrid.leafGridView());
133 auto hostToFacetVertexInsertionIndex = Detail::FacetGrid::fillFactory(
135 hostGrid.leafGridView(),
143 for (std::size_t hostVertexIndex = 0; hostVertexIndex < hostToFacetVertexInsertionIndex.size(); ++hostVertexIndex)
144 if (hostToFacetVertexInsertionIndex[hostVertexIndex] != Detail::FacetGrid::undefinedIndex)
149 template<Concept::FacetSelector<HostElement, HostIntersection> Selector>
150 void init(
const Selector& selector,
const std::string& paramGroup =
"")
159 if (Dune::MPIHelper::getCommunication().size() > 1)
160 this->
grid().loadBalance();
Grid manager for grids living on the facets of a host grid.
Definition: facetgridmanager.hh:110
FacetGrid Grid
Definition: facetgridmanager.hh:122
typename HostGrid::template Codim< dim+1 >::Entity HostGridVertex
Definition: facetgridmanager.hh:126
void init(const Selector &selector, const std::string ¶mGroup="")
Make the grid and create the host grid internally.
Definition: facetgridmanager.hh:150
HostGridVertex hostGridVertex(const Vertex &v) const
Return the host grid vertex that overlaps with the given facet grid vertex.
Definition: facetgridmanager.hh:176
void loadBalance()
Call loadBalance() function of the grid.
Definition: facetgridmanager.hh:157
std::unique_ptr< HostGridManager > hostGridManager_
Definition: facetgridmanager.hh:192
std::unique_ptr< HostVertexSet > hostVertexSet_
Definition: facetgridmanager.hh:191
Dune::GridFactory< Grid > facetGridFactory_
Definition: facetgridmanager.hh:189
HostGrid & hostGrid_()
Definition: facetgridmanager.hh:186
const Grid & grid() const
Returns a const reference to the grid.
Definition: facetgridmanager.hh:168
void init(const HostGrid &hostGrid, const Selector &selector)
Make the grid using an externally created host grid.
Definition: facetgridmanager.hh:130
void initHostGrid_(const std::string ¶mGroup)
Definition: facetgridmanager.hh:180
std::vector< std::size_t > facetInsertionToHostVertexIndex_
Definition: facetgridmanager.hh:193
std::unique_ptr< Grid > facetGrid_
Definition: facetgridmanager.hh:190
Grid & grid()
Returns a reference to the grid.
Definition: facetgridmanager.hh:164
typename Grid::template Codim< dim >::Entity Vertex
Definition: facetgridmanager.hh:123
bool hasGridData() const
Return true if grid data is available.
Definition: facetgridmanager.hh:172
HG HostGrid
Definition: facetgridmanager.hh:125
An interface for a set of geometric entities based on a GridView.
Definition: geometricentityset.hh:37
Concept for selecting grid intersections to be included in a facet grid.
Definition: facetgridmanager.hh:97
An interface for a set of geometric entities.
Contains the grid manager class that creates the grids in the context of hybrid-dimensional coupled m...