24#ifndef DUMUX_CCMPFA_FACETCOUPLING_MAPPER_HH
25#define DUMUX_CCMPFA_FACETCOUPLING_MAPPER_HH
27#include <dune/common/indices.hh>
28#include <dune/common/float_cmp.hh>
50template<
class BulkFVG,
class LowDimFVG, std::
size_t bulkId, std::
size_t lowDimId>
56 using BulkFVElementGeometry =
typename BulkFVG::LocalView;
57 using BulkSubControlVolumeFace =
typename BulkFVG::SubControlVolumeFace;
62 using LowDimElement =
typename LowDimFVG::GridView::template Codim<0>::Entity;
63 using GlobalPosition =
typename LowDimElement::Geometry::GlobalCoordinate;
64 static constexpr int lowDimDim = LowDimFVG::GridView::dimension;
68 using ParentType::bulkGridId;
69 using ParentType::facetGridId;
79 template<
class Embeddings >
80 void update(
const BulkFVG& bulkFvGridGeometry,
81 const LowDimFVG& lowDimFvGridGeometry,
82 std::shared_ptr<const Embeddings> embeddings)
86 update(bulkFvGridGeometry, lowDimFvGridGeometry, embeddings, GridAdapter(embeddings));
98 template<
class Embeddings,
class CodimOneGr
idAdapter >
99 void update(
const BulkFVG& bulkFvGridGeometry,
100 const LowDimFVG& lowDimFvGridGeometry,
101 std::shared_ptr<const Embeddings> embeddings,
105 auto addCouplingEntryPolicy = [&] (
auto&& adjoinedEntityIndices,
106 const LowDimElement& lowDimElement,
107 const LowDimFVG& lowDimFvGridGeometry,
108 const BulkFVG& bulkFvGridGeometry)
110 const auto lowDimElemIdx = lowDimFvGridGeometry.elementMapper().index(lowDimElement);
111 auto& lowDimData = this->couplingMap_(facetGridId, bulkGridId)[lowDimElemIdx];
114 const auto& lowDimGeometry = lowDimElement.geometry();
115 const auto numElementCorners = lowDimElement.subEntities(lowDimDim);
116 std::vector<BulkIndexType> elemCornerIndices(numElementCorners);
117 for (
int i = 0; i < numElementCorners; ++i)
118 elemCornerIndices[i] = codimOneGridAdapter.
bulkGridVertexIndex(lowDimElement.template subEntity<lowDimDim>(i));
121 auto fvGeometry =
localView(bulkFvGridGeometry);
122 for (
auto bulkElemIdx : adjoinedEntityIndices)
124 const auto bulkElement = bulkFvGridGeometry.element(bulkElemIdx);
125 fvGeometry.bind(bulkElement);
127 std::vector<BulkIndexType> embeddedScvfIndices;
128 for (
const auto& scvf : scvfs(fvGeometry))
132 if (!scvf.boundary())
134 if ( std::count(adjoinedEntityIndices.begin(), adjoinedEntityIndices.end(), scvf.outsideScvIdx()) )
135 embeddedScvfIndices.push_back(scvf.index());
141 const auto eps = lowDimGeometry.volume()*1e-8;
142 const auto diffVec = lowDimGeometry.center()-scvf.facetCorner();
144 if ( Dune::FloatCmp::eq<GlobalPosition, Dune::FloatCmp::CmpStyle::absolute>(diffVec, GlobalPosition(0.0), eps) )
145 embeddedScvfIndices.push_back(scvf.index());
150 if ( embeddedScvfIndices.size() != numElementCorners )
151 DUNE_THROW(Dune::InvalidStateException,
"Could not find all coupling scvfs in embedment");
154 auto& bulkData = this->couplingMap_(bulkGridId, facetGridId)[bulkElemIdx];
156 ? this->extractNodalDofs_(lowDimElement, lowDimFvGridGeometry)
157 : std::vector<LowDimIndexType>( {lowDimElemIdx} );
160 for (
auto dofIdx : lowDimElementDofs)
161 for (
auto scvfIdx : embeddedScvfIndices)
162 this->addCouplingsFromIV_(bulkFvGridGeometry, fvGeometry.scvf(scvfIdx), fvGeometry, lowDimElemIdx, dofIdx);
168 const auto copy = embeddedScvfIndices;
170 for (
unsigned int i = 0; i < numElementCorners; ++i)
172 const auto& scvf = fvGeometry.scvf(copy[i]);
173 auto it = std::find(elemCornerIndices.begin(), elemCornerIndices.end(), scvf.vertexIndex());
174 assert(it != elemCornerIndices.end());
175 embeddedScvfIndices[
std::distance(elemCornerIndices.begin(), it) ] = copy[i];
180 auto& elemToScvfMap = bulkData.elementToScvfMap[lowDimElemIdx];
181 elemToScvfMap.insert(elemToScvfMap.end(), embeddedScvfIndices.begin(), embeddedScvfIndices.end());
184 lowDimData.embedments.emplace_back( bulkElemIdx, std::move(embeddedScvfIndices) );
189 ParentType::update_(bulkFvGridGeometry, lowDimFvGridGeometry, embeddings, addCouplingEntryPolicy);
192 auto makeUnique = [] (
auto& c)
194 std::sort(c.begin(), c.end());
195 c.erase( std::unique(c.begin(), c.end()), c.end() );
199 auto makeBulkMapEntryUnique = [&makeUnique] (
auto& data)
201 makeUnique(data.second.couplingStencil);
202 makeUnique(data.second.couplingElementStencil);
203 std::for_each(data.second.dofToCouplingScvfMap.begin(),
204 data.second.dofToCouplingScvfMap.end(),
205 [&makeUnique] (
auto& pair) { makeUnique(pair.second); });
209 auto& bulkCouplingData = this->couplingMap_(bulkGridId, facetGridId);
210 std::for_each(bulkCouplingData.begin(), bulkCouplingData.end(), makeBulkMapEntryUnique);
213 auto& lowDimCouplingData = this->couplingMap_(facetGridId, bulkGridId);
214 std::for_each(lowDimCouplingData.begin(),
215 lowDimCouplingData.end(),
216 [&makeUnique] (
auto& pair) { makeUnique(pair.second.couplingStencil); });
220 void addCouplingsFromIV_(
const BulkFVG& bulkFvGridGeometry,
221 const BulkSubControlVolumeFace& scvf,
222 const BulkFVElementGeometry& fvGeometry,
223 LowDimIndexType lowDimElemIdx,
224 LowDimIndexType lowDimDofIdx)
226 const auto& gridIvIndexSets = bulkFvGridGeometry.gridInteractionVolumeIndexSets();
227 if (bulkFvGridGeometry.vertexUsesSecondaryInteractionVolume(scvf.vertexIndex()))
228 addCouplingsFromIVIndexSet_(gridIvIndexSets.secondaryIndexSet(scvf), fvGeometry, lowDimElemIdx, lowDimDofIdx);
230 addCouplingsFromIVIndexSet_(gridIvIndexSets.primaryIndexSet(scvf), fvGeometry, lowDimElemIdx, lowDimDofIdx);
233 template<
class IVIndexSet >
234 void addCouplingsFromIVIndexSet_(
const IVIndexSet& indexSet,
235 const BulkFVElementGeometry& fvGeometry,
236 LowDimIndexType lowDimElemIdx,
237 LowDimIndexType lowDimDofIdx)
239 auto& lowDimData = this->couplingMap_(facetGridId, bulkGridId)[lowDimElemIdx];
240 for (
auto bulkElemIdx : indexSet.gridScvIndices())
242 auto& bulkData = this->couplingMap_(bulkGridId, facetGridId)[bulkElemIdx];
244 lowDimData.couplingStencil.push_back( bulkElemIdx );
245 bulkData.couplingStencil.push_back( lowDimDofIdx );
246 bulkData.couplingElementStencil.push_back( lowDimElemIdx );
250 for (
auto scvfIdx : indexSet.gridScvfIndices())
252 const auto& scvf = fvGeometry.scvf(scvfIdx);
253 auto& bulkData = this->couplingMap_(bulkGridId, facetGridId)[scvf.insideScvIdx()];
254 auto& couplingScvfs = bulkData.dofToCouplingScvfMap[lowDimDofIdx];
255 couplingScvfs.insert(couplingScvfs.end(), scvfIdx);
Defines the index types used for grid and local indices.
The available discretization methods in Dumux.
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:294
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:38
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
constexpr Box box
Definition: method.hh:136
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:39
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:99
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:80
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:54
Base class for the coupling mapper that sets up and stores the coupling maps between two domains of d...
Definition: couplingmapperbase.hh:53