22#ifndef DUMUX_CCMPFA_FACETCOUPLING_MAPPER_HH
23#define DUMUX_CCMPFA_FACETCOUPLING_MAPPER_HH
25#include <dune/common/indices.hh>
26#include <dune/common/float_cmp.hh>
48template<
class BulkFVG,
class LowDimFVG, std::
size_t bulkId, std::
size_t lowDimId>
54 using BulkFVElementGeometry =
typename BulkFVG::LocalView;
55 using BulkSubControlVolumeFace =
typename BulkFVG::SubControlVolumeFace;
60 using LowDimElement =
typename LowDimFVG::GridView::template Codim<0>::Entity;
61 using GlobalPosition =
typename LowDimElement::Geometry::GlobalCoordinate;
62 static constexpr int lowDimDim = LowDimFVG::GridView::dimension;
66 using ParentType::bulkGridId;
67 using ParentType::facetGridId;
77 template<
class Embeddings >
78 void update(
const BulkFVG& bulkFvGridGeometry,
79 const LowDimFVG& lowDimFvGridGeometry,
80 std::shared_ptr<const Embeddings> embeddings)
84 update(bulkFvGridGeometry, lowDimFvGridGeometry, embeddings, GridAdapter(embeddings));
96 template<
class Embeddings,
class CodimOneGr
idAdapter >
97 void update(
const BulkFVG& bulkFvGridGeometry,
98 const LowDimFVG& lowDimFvGridGeometry,
99 std::shared_ptr<const Embeddings> embeddings,
103 auto addCouplingEntryPolicy = [&] (
auto&& adjoinedEntityIndices,
104 const LowDimElement& lowDimElement,
105 const LowDimFVG& lowDimFvGridGeometry,
106 const BulkFVG& bulkFvGridGeometry)
108 const auto lowDimElemIdx = lowDimFvGridGeometry.elementMapper().index(lowDimElement);
109 auto& lowDimData = this->couplingMap_(facetGridId, bulkGridId)[lowDimElemIdx];
112 const auto& lowDimGeometry = lowDimElement.geometry();
113 const auto numElementCorners = lowDimElement.subEntities(lowDimDim);
114 std::vector<BulkIndexType> elemCornerIndices(numElementCorners);
115 for (
int i = 0; i < numElementCorners; ++i)
116 elemCornerIndices[i] = codimOneGridAdapter.
bulkGridVertexIndex(lowDimElement.template subEntity<lowDimDim>(i));
119 for (
auto bulkElemIdx : adjoinedEntityIndices)
121 const auto bulkElement = bulkFvGridGeometry.element(bulkElemIdx);
123 auto fvGeometry =
localView(bulkFvGridGeometry);
124 fvGeometry.bind(bulkElement);
126 std::vector<BulkIndexType> embeddedScvfIndices;
127 for (
const auto& scvf : scvfs(fvGeometry))
131 if (!scvf.boundary())
133 if ( std::count(adjoinedEntityIndices.begin(), adjoinedEntityIndices.end(), scvf.outsideScvIdx()) )
134 embeddedScvfIndices.push_back(scvf.index());
140 const auto eps = lowDimGeometry.volume()*1e-8;
141 const auto diffVec = lowDimGeometry.center()-scvf.facetCorner();
143 if ( Dune::FloatCmp::eq<GlobalPosition, Dune::FloatCmp::CmpStyle::absolute>(diffVec, GlobalPosition(0.0), eps) )
144 embeddedScvfIndices.push_back(scvf.index());
149 if ( embeddedScvfIndices.size() != numElementCorners )
150 DUNE_THROW(Dune::InvalidStateException,
"Could not find all coupling scvfs in embedment");
153 auto& bulkData = this->couplingMap_(bulkGridId, facetGridId)[bulkElemIdx];
155 ? this->extractNodalDofs_(lowDimElement, lowDimFvGridGeometry)
156 : std::vector<LowDimIndexType>( {lowDimElemIdx} );
159 for (
auto dofIdx : lowDimElementDofs)
160 for (
auto scvfIdx : embeddedScvfIndices)
161 this->addCouplingsFromIV_(bulkFvGridGeometry, fvGeometry.scvf(scvfIdx), fvGeometry, lowDimElemIdx, dofIdx);
167 const auto copy = embeddedScvfIndices;
169 for (
unsigned int i = 0; i < numElementCorners; ++i)
171 const auto& scvf = fvGeometry.scvf(copy[i]);
172 auto it = std::find(elemCornerIndices.begin(), elemCornerIndices.end(), scvf.vertexIndex());
173 assert(it != elemCornerIndices.end());
174 embeddedScvfIndices[
std::distance(elemCornerIndices.begin(), it) ] = copy[i];
179 auto& elemToScvfMap = bulkData.elementToScvfMap[lowDimElemIdx];
180 elemToScvfMap.insert(elemToScvfMap.end(), embeddedScvfIndices.begin(), embeddedScvfIndices.end());
183 lowDimData.embedments.emplace_back( bulkElemIdx, std::move(embeddedScvfIndices) );
188 ParentType::update_(bulkFvGridGeometry, lowDimFvGridGeometry, embeddings, addCouplingEntryPolicy);
191 auto makeUnique = [] (
auto& c)
193 std::sort(c.begin(), c.end());
194 c.erase( std::unique(c.begin(), c.end()), c.end() );
198 auto makeBulkMapEntryUnique = [&makeUnique] (
auto& data)
200 makeUnique(data.second.couplingStencil);
201 makeUnique(data.second.couplingElementStencil);
202 std::for_each(data.second.dofToCouplingScvfMap.begin(),
203 data.second.dofToCouplingScvfMap.end(),
204 [&makeUnique] (
auto& pair) { makeUnique(pair.second); });
208 auto& bulkCouplingData = this->couplingMap_(bulkGridId, facetGridId);
209 std::for_each(bulkCouplingData.begin(), bulkCouplingData.end(), makeBulkMapEntryUnique);
212 auto& lowDimCouplingData = this->couplingMap_(facetGridId, bulkGridId);
213 std::for_each(lowDimCouplingData.begin(),
214 lowDimCouplingData.end(),
215 [&makeUnique] (
auto& pair) { makeUnique(pair.second.couplingStencil); });
219 void addCouplingsFromIV_(
const BulkFVG& bulkFvGridGeometry,
220 const BulkSubControlVolumeFace& scvf,
221 const BulkFVElementGeometry& fvGeometry,
222 LowDimIndexType lowDimElemIdx,
223 LowDimIndexType lowDimDofIdx)
225 const auto& gridIvIndexSets = bulkFvGridGeometry.gridInteractionVolumeIndexSets();
226 if (bulkFvGridGeometry.vertexUsesSecondaryInteractionVolume(scvf.vertexIndex()))
227 addCouplingsFromIVIndexSet_(gridIvIndexSets.secondaryIndexSet(scvf), fvGeometry, lowDimElemIdx, lowDimDofIdx);
229 addCouplingsFromIVIndexSet_(gridIvIndexSets.primaryIndexSet(scvf), fvGeometry, lowDimElemIdx, lowDimDofIdx);
232 template<
class IVIndexSet >
233 void addCouplingsFromIVIndexSet_(
const IVIndexSet& indexSet,
234 const BulkFVElementGeometry& fvGeometry,
235 LowDimIndexType lowDimElemIdx,
236 LowDimIndexType lowDimDofIdx)
238 auto& lowDimData = this->couplingMap_(facetGridId, bulkGridId)[lowDimElemIdx];
239 for (
auto bulkElemIdx : indexSet.gridScvIndices())
241 auto& bulkData = this->couplingMap_(bulkGridId, facetGridId)[bulkElemIdx];
243 lowDimData.couplingStencil.push_back( bulkElemIdx );
244 bulkData.couplingStencil.push_back( lowDimDofIdx );
245 bulkData.couplingElementStencil.push_back( lowDimElemIdx );
249 for (
auto scvfIdx : indexSet.gridScvfIndices())
251 const auto& scvf = fvGeometry.scvf(scvfIdx);
252 auto& bulkData = this->couplingMap_(bulkGridId, facetGridId)[scvf.insideScvIdx()];
253 auto& couplingScvfs = bulkData.dofToCouplingScvfMap[lowDimDofIdx];
254 couplingScvfs.insert(couplingScvfs.end(), scvfIdx);
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/cellcentered/mpfa/couplingmapper.hh:78
void update(const BulkFVG &bulkFvGridGeometry, const LowDimFVG &lowDimFvGridGeometry, std::shared_ptr< const Embeddings > embeddings, const CodimOneGridAdapter &codimOneGridAdapter)
Update coupling maps. This is the standard interface required by any mapper implementation.
Definition: facet/cellcentered/mpfa/couplingmapper.hh:97
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