22#ifndef DUMUX_BOX_FACETCOUPLING_MAPPER_HH
23#define DUMUX_BOX_FACETCOUPLING_MAPPER_HH
25#include <dune/common/indices.hh>
46template<
class BulkFVG,
class LowDimFVG, std::
size_t bulkId, std::
size_t lowDimId>
51 using LowDimElement =
typename LowDimFVG::GridView::template Codim<0>::Entity;
54 using BulkGridView =
typename BulkFVG::GridView;
55 using LowDimGridView =
typename LowDimFVG::GridView;
56 static constexpr int bulkDim = BulkGridView::dimension;
57 static constexpr int lowDimDim = LowDimGridView::dimension;
61 using ParentType::bulkGridId;
62 using ParentType::facetGridId;
72 template<
class Embeddings >
73 void update(
const BulkFVG& bulkFvGridGeometry,
74 const LowDimFVG& lowDimFvGridGeometry,
75 std::shared_ptr<const Embeddings> embeddings)
79 update(bulkFvGridGeometry, lowDimFvGridGeometry, embeddings, GridAdapter(embeddings));
90 template<
class Embeddings,
class CodimOneGr
idAdapter >
91 void update(
const BulkFVG& bulkFvGridGeometry,
92 const LowDimFVG& lowDimFvGridGeometry,
93 std::shared_ptr<const Embeddings> embeddings,
97 auto addCouplingEntryPolicy = [&] (
auto&& adjoinedEntityIndices,
98 const LowDimElement& lowDimElement,
99 const LowDimFVG& lowDimFvGridGeometry,
100 const BulkFVG& bulkFvGridGeometry)
105 const auto lowDimElemIdx = lowDimFvGridGeometry.elementMapper().index(lowDimElement);
106 auto& lowDimData = this->couplingMap_(facetGridId, bulkGridId)[lowDimElemIdx];
109 const auto& eg = lowDimElement.geometry();
110 const auto numElementCorners = eg.corners();
111 std::vector<BulkIndexType> elementCorners(numElementCorners);
112 for (
int i = 0; i < numElementCorners; ++i)
113 elementCorners[i] = codimOneGridAdapter.
bulkGridVertexIndex(lowDimElement.template subEntity<lowDimDim>(i));
116 const auto unsortedElemCorners = elementCorners;
117 std::sort(elementCorners.begin(), elementCorners.end());
118 for (
auto bulkElemIdx : adjoinedEntityIndices)
120 const auto bulkElement = bulkFvGridGeometry.element(bulkElemIdx);
121 const auto bulkRefElem = referenceElement(bulkElement);
125 unsigned int coupledFacetIndex;
126 std::vector<unsigned int> handledFacets;
127 for (
const auto& is : intersections(bulkFvGridGeometry.gridView(), bulkElement))
130 if (std::count(handledFacets.begin(), handledFacets.end(), is.indexInInside()))
133 handledFacets.push_back(is.indexInInside());
136 const auto numCorners = is.geometry().corners();
137 std::vector<BulkIndexType> facetIndices(numCorners);
138 for (
int i = 0; i < numCorners; ++i)
140 const auto vIdxLocal = bulkRefElem.subEntity(is.indexInInside(), 1, i, bulkDim);
141 facetIndices[i] = bulkFvGridGeometry.vertexMapper().vertexIndex(bulkElement.template subEntity<bulkDim>(vIdxLocal));
144 std::sort(facetIndices.begin(), facetIndices.end());
145 if ( std::equal(facetIndices.begin(), facetIndices.end(), elementCorners.begin(), elementCorners.end()) )
147 coupledFacetIndex = is.indexInInside();
154 DUNE_THROW(Dune::InvalidStateException,
"Could not find the bulk element coupling facet!");
157 auto fvGeometry =
localView(bulkFvGridGeometry);
158 fvGeometry.bindElement(bulkElement);
160 unsigned int foundCounter = 0;
161 std::vector<BulkIndexType> embeddedScvfIndices(numElementCorners);
162 for (
const auto& scvf : scvfs(fvGeometry))
164 if (scvf.interiorBoundary() && scvf.facetIndexInElement() == coupledFacetIndex)
169 const auto vIdxLocal = bulkRefElem.subEntity(coupledFacetIndex, 1, scvf.indexInElementFacet(), bulkDim);
170 const auto vIdxGlobal = bulkFvGridGeometry.vertexMapper().vertexIndex(bulkElement, vIdxLocal, bulkDim);
171 const auto it = std::find(unsortedElemCorners.begin(), unsortedElemCorners.end(), vIdxGlobal);
172 assert(it != unsortedElemCorners.end());
173 const auto lowDimElemLocalCornerIdx =
std::distance(unsortedElemCorners.begin(), it);
174 embeddedScvfIndices[lowDimElemLocalCornerIdx] = scvf.index();
180 if (foundCounter != numElementCorners)
181 DUNE_THROW(Dune::InvalidStateException,
"Found " << foundCounter <<
" instead of " << numElementCorners <<
" coupling scvfs in the bulk element");
184 auto& bulkData = this->couplingMap_(bulkGridId, facetGridId)[bulkElemIdx];
186 ? this->extractNodalDofs_(lowDimElement, lowDimFvGridGeometry)
187 : std::vector<LowDimIndexType>({lowDimElemIdx});
189 for (
auto lowDimDofIdx : lowDimElementDofs)
191 bulkData.couplingStencil.push_back(lowDimDofIdx);
192 auto& couplingScvfs = bulkData.dofToCouplingScvfMap[lowDimDofIdx];
193 couplingScvfs.insert(couplingScvfs.end(), embeddedScvfIndices.begin(), embeddedScvfIndices.end());
197 bulkData.couplingElementStencil.push_back(lowDimElemIdx);
198 auto& elemToScvfMap = bulkData.elementToScvfMap[lowDimElemIdx];
199 elemToScvfMap.insert(elemToScvfMap.end(), embeddedScvfIndices.begin(), embeddedScvfIndices.end());
202 lowDimData.embedments.emplace_back(bulkElemIdx, std::move(embeddedScvfIndices));
204 const auto bulkElementDofs = this->extractNodalDofs_(bulkElement, bulkFvGridGeometry);
205 for (
auto bulkDofIdx : bulkElementDofs)
206 lowDimData.couplingStencil.push_back(bulkDofIdx);
211 ParentType::update_(bulkFvGridGeometry, lowDimFvGridGeometry, embeddings, addCouplingEntryPolicy);
214 auto makeStencilUnique = [] (
auto& data)
216 auto& cs = data.second.couplingStencil;
217 std::sort(cs.begin(), cs.end());
218 cs.erase( std::unique(cs.begin(), cs.end()), cs.end() );
221 auto& lowDimCouplingData = this->couplingMap_(facetGridId, bulkGridId);
222 std::for_each(lowDimCouplingData.begin(), lowDimCouplingData.end(), makeStencilUnique);
227 auto& bulkCouplingData = this->couplingMap_(bulkGridId, facetGridId);
228 std::for_each(bulkCouplingData.begin(), bulkCouplingData.end(), makeStencilUnique);
Defines the index types used for grid and local indices.
The available discretization methods in Dumux.
ctype distance(const Dune::FieldVector< ctype, dimWorld > &a, const Dune::FieldVector< ctype, dimWorld > &b)
Compute the shortest distance between two points.
Definition: geometry/distance.hh:138
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:38
DiscretizationMethod
The available discretization methods in Dumux.
Definition: method.hh:37
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:39
void update(const BulkFVG &bulkFvGridGeometry, const LowDimFVG &lowDimFvGridGeometry, std::shared_ptr< const Embeddings > embeddings)
Update coupling maps. This is the standard interface required by any mapper implementation.
Definition: facet/box/couplingmapper.hh:73
void update(const BulkFVG &bulkFvGridGeometry, const LowDimFVG &lowDimFvGridGeometry, std::shared_ptr< const Embeddings > embeddings, const CodimOneGridAdapter &codimOneGridAdapter)
Update coupling maps with a given grid adapter.
Definition: facet/box/couplingmapper.hh:91
Adapter that allows retrieving information on a d-dimensional grid for entities of a (d-1)-dimensiona...
Definition: codimonegridadapter.hh:52
BulkIndexType bulkGridVertexIndex(const FacetGridVertex &v) const
Returns the index within the d-dimensional grid of a vertex of the (d-1)-dimensional grid.
Definition: codimonegridadapter.hh:145
Implementation for the coupling mapper that sets up and stores the coupling maps between two domains ...
Definition: facet/couplingmapper.hh:52
Base class for the coupling mapper that sets up and stores the coupling maps between two domains of d...
Definition: couplingmapperbase.hh:51