22#ifndef DUMUX_BOX_FACETCOUPLING_MAPPER_HH
23#define DUMUX_BOX_FACETCOUPLING_MAPPER_HH
25#include <dune/common/indices.hh>
26#include <dune/geometry/referenceelements.hh>
47template<
class BulkFVG,
class LowDimFVG, std::
size_t bulkId, std::
size_t lowDimId>
52 using LowDimElement =
typename LowDimFVG::GridView::template Codim<0>::Entity;
55 using BulkGridView =
typename BulkFVG::GridView;
56 using LowDimGridView =
typename LowDimFVG::GridView;
57 static constexpr int bulkDim = BulkGridView::dimension;
58 static constexpr int lowDimDim = LowDimGridView::dimension;
62 using ParentType::bulkGridId;
63 using ParentType::facetGridId;
73 template<
class Embeddings >
74 void update(
const BulkFVG& bulkFvGridGeometry,
75 const LowDimFVG& lowDimFvGridGeometry,
76 std::shared_ptr<const Embeddings> embeddings)
80 update(bulkFvGridGeometry, lowDimFvGridGeometry, embeddings, GridAdapter(embeddings));
91 template<
class Embeddings,
class CodimOneGr
idAdapter >
92 void update(
const BulkFVG& bulkFvGridGeometry,
93 const LowDimFVG& lowDimFvGridGeometry,
94 std::shared_ptr<const Embeddings> embeddings,
98 auto addCouplingEntryPolicy = [&] (
auto&& adjoinedEntityIndices,
99 const LowDimElement& lowDimElement,
100 const LowDimFVG& lowDimFvGridGeometry,
101 const BulkFVG& bulkFvGridGeometry)
105 using BulkReferenceElements = Dune::ReferenceElements<typename BulkGridView::ctype, bulkDim>;
107 const auto lowDimElemIdx = lowDimFvGridGeometry.elementMapper().index(lowDimElement);
108 auto& lowDimData = this->couplingMap_(facetGridId, bulkGridId)[lowDimElemIdx];
111 const auto& eg = lowDimElement.geometry();
112 const auto numElementCorners = eg.corners();
113 std::vector<BulkIndexType> elementCorners(numElementCorners);
114 for (
int i = 0; i < numElementCorners; ++i)
115 elementCorners[i] = codimOneGridAdapter.
bulkGridVertexIndex(lowDimElement.template subEntity<lowDimDim>(i));
118 const auto unsortedElemCorners = elementCorners;
119 std::sort(elementCorners.begin(), elementCorners.end());
120 for (
auto bulkElemIdx : adjoinedEntityIndices)
122 const auto bulkElement = bulkFvGridGeometry.element(bulkElemIdx);
123 const auto bulkRefElem = BulkReferenceElements::general(bulkElement.type());
127 unsigned int coupledFacetIndex;
128 std::vector<unsigned int> handledFacets;
129 for (
const auto& is :
intersections(bulkFvGridGeometry.gridView(), bulkElement))
132 if (std::count(handledFacets.begin(), handledFacets.end(), is.indexInInside()))
135 handledFacets.push_back(is.indexInInside());
138 const auto numCorners = is.geometry().corners();
139 std::vector<BulkIndexType> facetIndices(numCorners);
140 for (
int i = 0; i < numCorners; ++i)
142 const auto vIdxLocal = bulkRefElem.subEntity(is.indexInInside(), 1, i, bulkDim);
143 facetIndices[i] = bulkFvGridGeometry.vertexMapper().vertexIndex(bulkElement.template subEntity<bulkDim>(vIdxLocal));
146 std::sort(facetIndices.begin(), facetIndices.end());
147 if ( std::equal(facetIndices.begin(), facetIndices.end(), elementCorners.begin(), elementCorners.end()) )
149 coupledFacetIndex = is.indexInInside();
156 DUNE_THROW(Dune::InvalidStateException,
"Could not find the bulk element coupling facet!");
159 auto fvGeometry =
localView(bulkFvGridGeometry);
160 fvGeometry.bindElement(bulkElement);
162 unsigned int foundCounter = 0;
163 std::vector<BulkIndexType> embeddedScvfIndices(numElementCorners);
164 for (
const auto& scvf : scvfs(fvGeometry))
166 if (scvf.interiorBoundary() && scvf.facetIndexInElement() == coupledFacetIndex)
171 const auto vIdxLocal = bulkRefElem.subEntity(coupledFacetIndex, 1, scvf.indexInElementFacet(), bulkDim);
172 const auto vIdxGlobal = bulkFvGridGeometry.vertexMapper().vertexIndex(bulkElement, vIdxLocal, bulkDim);
173 const auto it = std::find(unsortedElemCorners.begin(), unsortedElemCorners.end(), vIdxGlobal);
174 assert(it != unsortedElemCorners.end());
175 const auto lowDimElemLocalCornerIdx = std::distance(unsortedElemCorners.begin(), it);
176 embeddedScvfIndices[lowDimElemLocalCornerIdx] = scvf.index();
182 if (foundCounter != numElementCorners)
183 DUNE_THROW(Dune::InvalidStateException,
"Found " << foundCounter <<
" instead of " << numElementCorners <<
" coupling scvfs in the bulk element");
186 auto& bulkData = this->couplingMap_(bulkGridId, facetGridId)[bulkElemIdx];
188 ? this->extractNodalDofs_(lowDimElement, lowDimFvGridGeometry)
189 : std::vector<LowDimIndexType>({lowDimElemIdx});
191 for (
auto lowDimDofIdx : lowDimElementDofs)
193 bulkData.couplingStencil.push_back(lowDimDofIdx);
194 auto& couplingScvfs = bulkData.dofToCouplingScvfMap[lowDimDofIdx];
195 couplingScvfs.insert(couplingScvfs.end(), embeddedScvfIndices.begin(), embeddedScvfIndices.end());
199 bulkData.couplingElementStencil.push_back(lowDimElemIdx);
200 auto& elemToScvfMap = bulkData.elementToScvfMap[lowDimElemIdx];
201 elemToScvfMap.insert(elemToScvfMap.end(), embeddedScvfIndices.begin(), embeddedScvfIndices.end());
204 lowDimData.embedments.emplace_back(bulkElemIdx, std::move(embeddedScvfIndices));
206 const auto bulkElementDofs = this->extractNodalDofs_(bulkElement, bulkFvGridGeometry);
207 for (
auto bulkDofIdx : bulkElementDofs)
208 lowDimData.couplingStencil.push_back(bulkDofIdx);
213 ParentType::update_(bulkFvGridGeometry, lowDimFvGridGeometry, embeddings, addCouplingEntryPolicy);
216 auto makeStencilUnique = [] (
auto& data)
218 auto& cs = data.second.couplingStencil;
219 std::sort(cs.begin(), cs.end());
220 cs.erase( std::unique(cs.begin(), cs.end()), cs.end() );
223 auto& lowDimCouplingData = this->couplingMap_(facetGridId, bulkGridId);
224 std::for_each(lowDimCouplingData.begin(), lowDimCouplingData.end(), makeStencilUnique);
229 auto& bulkCouplingData = this->couplingMap_(bulkGridId, facetGridId);
230 std::for_each(bulkCouplingData.begin(), bulkCouplingData.end(), makeStencilUnique);
Defines the index types used for grid and local indices.
The available discretization methods in Dumux.
copydoc Dumux::CodimOneGridAdapter
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
Dune::IteratorRange< typename MultiDomainGlue< DomainGridView, TargetGridView, DomainMapper, TargetMapper >::Intersections::const_iterator > intersections(const MultiDomainGlue< DomainGridView, TargetGridView, DomainMapper, TargetMapper > &glue)
Range generator to iterate with range-based for loops over all intersections as follows: for (const a...
Definition: glue.hh:62
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
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:74
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:92
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:146
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