12#ifndef DUMUX_CCMPFA_FACETCOUPLING_MAPPER_HH
13#define DUMUX_CCMPFA_FACETCOUPLING_MAPPER_HH
15#include <dune/common/indices.hh>
16#include <dune/common/float_cmp.hh>
38template<
class BulkFVG,
class LowDimFVG, std::
size_t bulkId, std::
size_t lowDimId>
44 using BulkFVElementGeometry =
typename BulkFVG::LocalView;
45 using BulkSubControlVolumeFace =
typename BulkFVG::SubControlVolumeFace;
50 using LowDimElement =
typename LowDimFVG::GridView::template Codim<0>::Entity;
51 using GlobalPosition =
typename LowDimElement::Geometry::GlobalCoordinate;
52 static constexpr int lowDimDim = LowDimFVG::GridView::dimension;
56 using ParentType::bulkGridId;
57 using ParentType::facetGridId;
67 template<
class Embeddings >
68 void update(
const BulkFVG& bulkFvGridGeometry,
69 const LowDimFVG& lowDimFvGridGeometry,
70 std::shared_ptr<const Embeddings> embeddings)
74 update(bulkFvGridGeometry, lowDimFvGridGeometry, embeddings, GridAdapter(embeddings));
86 template<
class Embeddings,
class CodimOneGr
idAdapter >
87 void update(
const BulkFVG& bulkFvGridGeometry,
88 const LowDimFVG& lowDimFvGridGeometry,
89 std::shared_ptr<const Embeddings> embeddings,
93 auto addCouplingEntryPolicy = [&] (
auto&& adjoinedEntityIndices,
94 const LowDimElement& lowDimElement,
95 const LowDimFVG& lowDimFvGridGeometry,
96 const BulkFVG& bulkFvGridGeometry)
98 const auto lowDimElemIdx = lowDimFvGridGeometry.elementMapper().index(lowDimElement);
99 auto& lowDimData = this->couplingMap_(facetGridId, bulkGridId)[lowDimElemIdx];
102 const auto& lowDimGeometry = lowDimElement.geometry();
103 const auto numElementCorners = lowDimElement.subEntities(lowDimDim);
104 std::vector<BulkIndexType> elemCornerIndices(numElementCorners);
105 for (
int i = 0; i < numElementCorners; ++i)
106 elemCornerIndices[i] = codimOneGridAdapter.
bulkGridVertexIndex(lowDimElement.template subEntity<lowDimDim>(i));
109 auto fvGeometry =
localView(bulkFvGridGeometry);
110 for (
auto bulkElemIdx : adjoinedEntityIndices)
112 const auto bulkElement = bulkFvGridGeometry.element(bulkElemIdx);
113 fvGeometry.bind(bulkElement);
115 std::vector<BulkIndexType> embeddedScvfIndices;
116 for (
const auto& scvf : scvfs(fvGeometry))
120 if (!scvf.boundary())
122 if ( std::count(adjoinedEntityIndices.begin(), adjoinedEntityIndices.end(), scvf.outsideScvIdx()) )
123 embeddedScvfIndices.push_back(scvf.index());
129 const auto eps = lowDimGeometry.volume()*1e-8;
130 const auto diffVec = lowDimGeometry.center()-fvGeometry.facetCorner(scvf);
132 if ( Dune::FloatCmp::eq<GlobalPosition, Dune::FloatCmp::CmpStyle::absolute>(diffVec, GlobalPosition(0.0), eps) )
133 embeddedScvfIndices.push_back(scvf.index());
138 if ( embeddedScvfIndices.size() != numElementCorners )
139 DUNE_THROW(Dune::InvalidStateException,
"Could not find all coupling scvfs in embedment");
142 auto& bulkData = this->couplingMap_(bulkGridId, facetGridId)[bulkElemIdx];
144 ? this->extractNodalDofs_(lowDimElement, lowDimFvGridGeometry)
145 : std::vector<LowDimIndexType>( {lowDimElemIdx} );
148 for (
auto dofIdx : lowDimElementDofs)
149 for (
auto scvfIdx : embeddedScvfIndices)
150 this->addCouplingsFromIV_(bulkFvGridGeometry, fvGeometry.scvf(scvfIdx), fvGeometry, lowDimElemIdx, dofIdx);
156 const auto copy = embeddedScvfIndices;
158 for (
unsigned int i = 0; i < numElementCorners; ++i)
160 const auto& scvf = fvGeometry.scvf(copy[i]);
161 auto it = std::find(elemCornerIndices.begin(), elemCornerIndices.end(), scvf.vertexIndex());
162 assert(it != elemCornerIndices.end());
163 embeddedScvfIndices[
std::distance(elemCornerIndices.begin(), it) ] = copy[i];
168 auto& elemToScvfMap = bulkData.elementToScvfMap[lowDimElemIdx];
169 elemToScvfMap.insert(elemToScvfMap.end(), embeddedScvfIndices.begin(), embeddedScvfIndices.end());
172 lowDimData.embedments.emplace_back( bulkElemIdx, std::move(embeddedScvfIndices) );
177 ParentType::update_(bulkFvGridGeometry, lowDimFvGridGeometry, embeddings, addCouplingEntryPolicy);
180 auto makeUnique = [] (
auto& c)
182 std::sort(c.begin(), c.end());
183 c.erase( std::unique(c.begin(), c.end()), c.end() );
187 auto makeBulkMapEntryUnique = [&makeUnique] (
auto& data)
189 makeUnique(data.second.couplingStencil);
190 makeUnique(data.second.couplingElementStencil);
191 std::for_each(data.second.dofToCouplingScvfMap.begin(),
192 data.second.dofToCouplingScvfMap.end(),
193 [&makeUnique] (
auto& pair) { makeUnique(pair.second); });
197 auto& bulkCouplingData = this->couplingMap_(bulkGridId, facetGridId);
198 std::for_each(bulkCouplingData.begin(), bulkCouplingData.end(), makeBulkMapEntryUnique);
201 auto& lowDimCouplingData = this->couplingMap_(facetGridId, bulkGridId);
202 std::for_each(lowDimCouplingData.begin(),
203 lowDimCouplingData.end(),
204 [&makeUnique] (
auto& pair) { makeUnique(pair.second.couplingStencil); });
208 void addCouplingsFromIV_(
const BulkFVG& bulkFvGridGeometry,
209 const BulkSubControlVolumeFace& scvf,
210 const BulkFVElementGeometry& fvGeometry,
211 LowDimIndexType lowDimElemIdx,
212 LowDimIndexType lowDimDofIdx)
214 const auto& gridIvIndexSets = bulkFvGridGeometry.gridInteractionVolumeIndexSets();
215 if (bulkFvGridGeometry.vertexUsesSecondaryInteractionVolume(scvf.vertexIndex()))
216 addCouplingsFromIVIndexSet_(gridIvIndexSets.secondaryIndexSet(scvf), fvGeometry, lowDimElemIdx, lowDimDofIdx);
218 addCouplingsFromIVIndexSet_(gridIvIndexSets.primaryIndexSet(scvf), fvGeometry, lowDimElemIdx, lowDimDofIdx);
221 template<
class IVIndexSet >
222 void addCouplingsFromIVIndexSet_(
const IVIndexSet& indexSet,
223 const BulkFVElementGeometry& fvGeometry,
224 LowDimIndexType lowDimElemIdx,
225 LowDimIndexType lowDimDofIdx)
227 auto& lowDimData = this->couplingMap_(facetGridId, bulkGridId)[lowDimElemIdx];
228 for (
auto bulkElemIdx : indexSet.gridScvIndices())
230 auto& bulkData = this->couplingMap_(bulkGridId, facetGridId)[bulkElemIdx];
232 lowDimData.couplingStencil.push_back( bulkElemIdx );
233 bulkData.couplingStencil.push_back( lowDimDofIdx );
234 bulkData.couplingElementStencil.push_back( lowDimElemIdx );
238 for (
auto scvfIdx : indexSet.gridScvfIndices())
240 const auto& scvf = fvGeometry.scvf(scvfIdx);
241 auto& bulkData = this->couplingMap_(bulkGridId, facetGridId)[scvf.insideScvIdx()];
242 auto& couplingScvfs = bulkData.dofToCouplingScvfMap[lowDimDofIdx];
243 couplingScvfs.insert(couplingScvfs.end(), scvfIdx);
Adapter that allows retrieving information on a d-dimensional grid for entities of a (d-1)-dimensiona...
Definition: codimonegridadapter.hh:40
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:133
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:87
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:68
Base class for the coupling mapper that sets up and stores the coupling maps between two domains of d...
Definition: couplingmapperbase.hh:41
Implementation for the coupling mapper that sets up and stores the coupling maps between two domains ...
Definition: facet/couplingmapper.hh:42
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:26
static ctype distance(const Dune::FieldVector< ctype, dimWorld > &a, const Dune::FieldVector< ctype, dimWorld > &b)
Compute the shortest distance between two points.
Definition: distance.hh:282
The available discretization methods in Dumux.
constexpr Box box
Definition: method.hh:147
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:27