24#ifndef DUMUX_CCMPFA_FACETCOUPLING_MANAGER_HH
25#define DUMUX_CCMPFA_FACETCOUPLING_MANAGER_HH
53template<
class MDTraits,
class CouplingMapper, std::
size_t bulkDomainId, std::
size_t lowDimDomainId>
55:
public FacetCouplingManager<MDTraits, CouplingMapper, bulkDomainId, lowDimDomainId, DiscretizationMethod::cctpfa>
60 using BulkIdType =
typename MDTraits::template SubDomain<bulkDomainId>::Index;
61 using LowDimIdType =
typename MDTraits::template SubDomain<lowDimDomainId>::Index;
62 static constexpr auto bulkId = BulkIdType();
63 static constexpr auto lowDimId = LowDimIdType();
66 template<std::
size_t id>
using SubDomainTypeTag =
typename MDTraits::template SubDomain<id>::TypeTag;
73 template<std::
size_t id>
using FVElementGeometry =
typename GridGeometry<id>::LocalView;
74 template<std::
size_t id>
using SubControlVolume =
typename GridGeometry<id>::SubControlVolume;
75 template<std::
size_t id>
using SubControlVolumeFace =
typename GridGeometry<id>::SubControlVolumeFace;
76 template<std::
size_t id>
using GridView =
typename GridGeometry<id>::GridView;
78 template<std::
size_t id>
using Element =
typename GridView<id>::template Codim<0>::Entity;
82 template<std::
size_t id>
using GridVolumeVariables =
typename GridVariables<id>::GridVolumeVariables;
83 template<std::
size_t id>
using ElementVolumeVariables =
typename GridVolumeVariables<id>::LocalView;
86 static constexpr int bulkDim = GridView<bulkDomainId>::dimension;
87 static constexpr int lowDimDim = GridView<lowDimDomainId>::dimension;
88 static constexpr auto bulkGridId = CouplingMapper::template gridId<bulkDim>();
89 static constexpr auto lowDimGridId = CouplingMapper::template gridId<lowDimDim>();
106 void init(std::shared_ptr< Problem<bulkId> > bulkProblem,
107 std::shared_ptr< Problem<lowDimId> > lowDimProblem,
108 std::shared_ptr< CouplingMapper > couplingMapper,
112 ParentType::init(bulkProblem, lowDimProblem, couplingMapper, curSol);
115 bulkScvfIsOnFacetElement_.assign(bulkProblem->gridGeometry().numScvf(),
false);
116 const auto& bulkMap = couplingMapper->couplingMap(bulkGridId, lowDimGridId);
117 for (
const auto& entry : bulkMap)
118 for (
const auto& couplingEntry : entry.second.elementToScvfMap)
119 for (
const auto& scvfIdx : couplingEntry.second)
120 bulkScvfIsOnFacetElement_[scvfIdx] =
true;
123 couplingMapperPtr_ = couplingMapper;
130 const SubControlVolumeFace<bulkId>& scvf)
const
131 {
return bulkScvfIsOnFacetElement_[scvf.index()]; }
133 using ParentType::evalCouplingResidual;
140 template<
class LowDimLocalAssembler >
141 typename LocalResidual<lowDimId>::ElementResidualVector
143 const LowDimLocalAssembler& lowDimLocalAssembler,
145 GridIndexType<bulkId> dofIdxGlobalJ)
146 {
return evalCouplingResidual(lowDimId, lowDimLocalAssembler, bulkId); }
153 template<
class LowDimLocalAssembler >
154 typename LocalResidual<lowDimId>::ElementResidualVector
158 assert(this->lowDimCouplingContext().isSet);
159 assert(this->problem(lowDimId).gridGeometry().elementMapper().index(lowDimLocalAssembler.element()) == this->lowDimCouplingContext().elementIdx);
162 typename LowDimLocalAssembler::LocalResidual::ElementResidualVector res(lowDimLocalAssembler.fvGeometry().numScv());
164 for (
const auto& scv : scvs(lowDimLocalAssembler.fvGeometry()))
165 res[scv.localDofIndex()] -= evalSourcesFromBulk(lowDimLocalAssembler.element(),
166 lowDimLocalAssembler.fvGeometry(),
167 lowDimLocalAssembler.curElemVolVars(),
176 const FVElementGeometry<lowDimId>& fvGeometry,
177 const ElementVolumeVariables<lowDimId>& elemVolVars,
178 const SubControlVolume<lowDimId>& scv)
181 assert(this->problem(lowDimId).gridGeometry().elementMapper().index(element) == this->lowDimCouplingContext().elementIdx);
183 NumEqVector<lowDimId> sources(0.0);
185 const auto& map = couplingMapperPtr_->couplingMap(lowDimGridId, bulkGridId);
186 auto it = map.find(this->lowDimCouplingContext().elementIdx);
190 assert(this->lowDimCouplingContext().isSet);
191 for (
const auto& embedment : it->second.embedments)
196 const auto& coincidingScvfs = embedment.second;
197 const auto& scvfList = lowDimUsesBox ? std::vector<GridIndexType<lowDimId>>{ coincidingScvfs[scv.localDofIndex()] }
200 sources += this->evalBulkFluxes(this->problem(bulkId).gridGeometry().element(embedment.first),
201 *this->lowDimCouplingContext().bulkFvGeometry,
202 *this->lowDimCouplingContext().bulkElemVolVars,
203 *this->lowDimCouplingContext().bulkElemFluxVarsCache,
204 *this->lowDimCouplingContext().bulkLocalResidual,
215 template<
class JacobianPattern>
218 const auto& lowDimFVGridGeometry = this->problem(lowDimId).gridGeometry();
219 for (
const auto& element : elements(lowDimFVGridGeometry.gridView()))
222 const auto eIdx = lowDimFVGridGeometry.elementMapper().index(element);
223 const auto& map = couplingMapperPtr_->couplingMap(lowDimGridId, bulkGridId);
224 auto it = map.find(eIdx);
230 const auto bulkElemIdx = it->second.embedments[0].first;
231 const auto& bulkMapEntry = couplingMapperPtr_->couplingMap(bulkGridId, lowDimGridId).at(bulkElemIdx);
232 const auto& couplingStencil = bulkMapEntry.couplingStencil;
234 for (
auto globalJ : couplingStencil)
238 for (
int i = 0; i < element.subEntities(lowDimDim); ++i)
239 pattern.add(lowDimFVGridGeometry.vertexMapper().subIndex(element, i, lowDimDim), globalJ);
242 pattern.add(eIdx, globalJ);
249 template<
class JacobianPattern>
259 template<
class LowDimLocalAssembler,
class JacobianMatrixDiagBlock,
class Gr
idVariables>
261 const LowDimLocalAssembler& lowDimLocalAssembler,
262 const typename LowDimLocalAssembler::LocalResidual::ElementResidualVector&,
263 JacobianMatrixDiagBlock& A,
264 GridVariables& gridVariables)
268 if (!LowDimLocalAssembler::isImplicit())
272 auto updateContext = [&] (
auto elemIdx,
auto dofIdx,
auto priVars,
auto pvIdx)
275 auto& ldSol = this->curSol()[lowDimId];
276 ldSol[dofIdx][pvIdx] = priVars[pvIdx];
279 assert(this->bulkCouplingContext().isSet);
280 const auto& bulkMap = couplingMapperPtr_->couplingMap(bulkGridId, lowDimGridId);
281 const auto& couplingElementStencil = bulkMap.find(this->bulkCouplingContext().elementIdx)->second.couplingElementStencil;
283 auto it = std::find(couplingElementStencil.begin(), couplingElementStencil.end(), elemIdx);
284 assert(it != couplingElementStencil.end());
285 const auto idxInContext =
std::distance(couplingElementStencil.begin(), it);
287 auto& volVars = this->bulkCouplingContext().lowDimVolVars[idxInContext];
288 const auto& fvGeom = this->bulkCouplingContext().lowDimFvGeometries[idxInContext];
289 const auto& element = this->problem(lowDimId).gridGeometry().element(elemIdx);
294 const auto elemGeom = element.geometry();
299 volVars.update(
elementSolution(element, ldSol, this->problem(lowDimId).gridGeometry()),
300 this->problem(lowDimId),
302 fvGeom.scv(elemIdx) );
305 const auto contextElem = this->problem(bulkId).gridGeometry().element(this->bulkCouplingContext().elementIdx);
306 this->lowDimCouplingContext().bulkElemFluxVarsCache->update(contextElem,
307 *this->lowDimCouplingContext().bulkFvGeometry,
308 *this->lowDimCouplingContext().bulkElemVolVars);
311 const auto eIdx = this->problem(lowDimId).gridGeometry().elementMapper().index(lowDimLocalAssembler.element());
314 assert(this->lowDimCouplingContext().isSet);
315 assert(this->lowDimCouplingContext().elementIdx == eIdx);
318 const auto& map = couplingMapperPtr_->couplingMap(lowDimGridId, bulkGridId);
319 auto it = map.find(eIdx);
321 evalLowDimSourceDerivatives_(updateContext, lowDimLocalAssembler, A);
325 template<
class LocalAssemblerI,
class JacobianMatrixDiagBlock,
class Gr
idVariables>
327 const LocalAssemblerI& localAssemblerI,
328 const typename LocalAssemblerI::LocalResidual::ElementResidualVector& origResiduals,
329 JacobianMatrixDiagBlock& A,
330 GridVariables& gridVariables)
335 template<
class UpdateContext,
class LowDimLocalAssembler,
class JacobianMatrixDiagBlock>
336 void evalLowDimSourceDerivatives_(
const UpdateContext& updateContext,
337 const LowDimLocalAssembler& lowDimLocalAssembler,
338 JacobianMatrixDiagBlock& A)
340 const auto& lowDimFVGridGeometry = this->problem(lowDimId).gridGeometry();
341 const auto eIdx = lowDimFVGridGeometry.elementMapper().index(lowDimLocalAssembler.element());
344 const auto bulkElemIdx = this->bulkCouplingContext().elementIdx;
345 const auto& bulkMapEntry = couplingMapperPtr_->couplingMap(bulkGridId, lowDimGridId).at(bulkElemIdx);
346 const auto& couplingStencil = bulkMapEntry.couplingStencil;
347 const auto& couplingElementStencil = bulkMapEntry.couplingElementStencil;
350 const auto origResidual = evalCouplingResidual(lowDimId, lowDimLocalAssembler, bulkId);
353 std::vector< std::decay_t<
decltype(couplingStencil[0])> > elemDofs;
354 elemDofs.reserve(lowDimLocalAssembler.fvGeometry().numScv());
355 for (
const auto& scv : scvs(lowDimLocalAssembler.fvGeometry()))
356 elemDofs.push_back(scv.dofIndex());
359 for (
const auto couplingElemIdx : couplingElementStencil)
362 if (couplingElemIdx == eIdx)
366 std::vector< std::decay_t<
decltype(couplingStencil[0])> > elemDofsJ;
369 const auto& elemJ = lowDimFVGridGeometry.element(couplingElemIdx);
370 for (
int i = 0; i < elemJ.subEntities(lowDimDim); ++i)
371 elemDofsJ.push_back(lowDimFVGridGeometry.vertexMapper().subIndex(elemJ, i, lowDimDim));
374 elemDofsJ.push_back(couplingElemIdx);
376 for (
auto dofIndex : elemDofsJ)
378 auto partialDerivs = origResidual;
379 const auto origPriVars = this->curSol()[lowDimId][dofIndex];
382 static constexpr auto numEq = std::decay_t<
decltype(origPriVars)>::dimension;
383 for (
int pvIdx = 0; pvIdx < numEq; pvIdx++)
388 auto evalResiduals = [&](Scalar<lowDimId> priVar)
390 auto priVars = origPriVars;
391 priVars[pvIdx] = priVar;
394 updateContext(couplingElemIdx, dofIndex, priVars, pvIdx);
395 return this->evalCouplingResidual(lowDimId, lowDimLocalAssembler, bulkId);
398 static const int numDiffMethod = getParamFromGroup<int>(this->problem(lowDimId).paramGroup(),
"Assembly.NumericDifferenceMethod");
399 static const NumericEpsilon< Scalar<lowDimId>, numEq > eps{this->problem(lowDimId).paramGroup()};
401 origResidual, eps(origPriVars[pvIdx], pvIdx), numDiffMethod);
406 for (
const auto& scv : scvs(lowDimLocalAssembler.fvGeometry()))
407 for (
int eqIdx = 0; eqIdx < numEq; eqIdx++)
408 A[scv.dofIndex()][dofIndex][eqIdx][pvIdx] += partialDerivs[scv.indexInElement()][eqIdx];
411 updateContext(couplingElemIdx, dofIndex, origPriVars, pvIdx);
418 std::vector<bool> bulkScvfIsOnFacetElement_;
421 std::shared_ptr< CouplingMapper > couplingMapperPtr_;
An adapter class for local assemblers using numeric differentiation.
A class for numeric differentiation.
Defines the index types used for grid and local indices.
Element solution classes and factory functions.
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
DiscretizationMethod
The available discretization methods in Dumux.
Definition: method.hh:37
auto elementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gg) -> std::enable_if_t< GridGeometry::discMethod==DiscretizationMethod::box, BoxElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for box schemes.
Definition: box/elementsolution.hh:115
void makeInterpolatedVolVars(VolumeVariables &volVars, const Problem &problem, const SolutionVector &sol, const FVGeometry &fvGeometry, const typename FVGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const typename FVGeometry::GridGeometry::GridView::template Codim< 0 >::Entity::Geometry &elemGeom, const typename FVGeometry::GridGeometry::GridView::template Codim< 0 >::Entity::Geometry::GlobalCoordinate &pos)
Free function that allows the creation of a volume variables object interpolated to a given position ...
Definition: multidomain/facet/couplingmanager.hh:52
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:149
Struture to define the index types used for grid and local indices.
Definition: indextraits.hh:38
static void partialDerivative(const Function &function, Scalar x0, FunctionEvalType &derivative, const FunctionEvalType &fx0, const int numericDifferenceMethod=1)
Computes the derivative of a function with repect to a function parameter.
Definition: numericdifferentiation.hh:61
Property to specify the type of scalar values.
Definition: common/properties.hh:43
A vector of size number equations that can be used for Neumann fluxes, sources, residuals,...
Definition: common/properties.hh:51
Property to specify the type of a problem which has to be solved.
Definition: common/properties.hh:57
Definition: common/properties.hh:77
Definition: common/properties.hh:101
The grid variables object managing variable data on the grid (volvars/fluxvars cache)
Definition: common/properties.hh:122
void init(std::shared_ptr< Problem< bulkId > > bulkProblem, std::shared_ptr< Problem< lowDimId > > lowDimProblem, std::shared_ptr< CouplingMapper > couplingMapper, const SolutionVector &curSol)
Initialize the coupling manager.
Definition: multidomain/facet/cellcentered/mpfa/couplingmanager.hh:106
bool isOnInteriorBoundary(const Element< bulkId > &element, const SubControlVolumeFace< bulkId > &scvf) const
returns true if a bulk scvf coincides with a facet element.
Definition: multidomain/facet/cellcentered/mpfa/couplingmanager.hh:129
void extendJacobianPattern(LowDimIdType, JacobianPattern &pattern) const
Extend the jacobian pattern of the diagonal block of the lowdim domain by the elements that are in th...
Definition: multidomain/facet/cellcentered/mpfa/couplingmanager.hh:216
typename MDTraits::SolutionVector SolutionVector
the type of the solution vector
Definition: multidomain/facet/cellcentered/mpfa/couplingmanager.hh:96
LocalResidual< lowDimId >::ElementResidualVector evalCouplingResidual(LowDimIdType, const LowDimLocalAssembler &lowDimLocalAssembler, BulkIdType)
Evaluates the coupling element residual of a lower-dimensional domain element with respect to a dof i...
Definition: multidomain/facet/cellcentered/mpfa/couplingmanager.hh:155
void evalAdditionalDomainDerivatives(LowDimIdType, const LowDimLocalAssembler &lowDimLocalAssembler, const typename LowDimLocalAssembler::LocalResidual::ElementResidualVector &, JacobianMatrixDiagBlock &A, GridVariables &gridVariables)
evaluate additional derivatives of the element residual of the low-dim domain with respect to dofs in...
Definition: multidomain/facet/cellcentered/mpfa/couplingmanager.hh:260
void evalAdditionalDomainDerivatives(BulkIdType, const LocalAssemblerI &localAssemblerI, const typename LocalAssemblerI::LocalResidual::ElementResidualVector &origResiduals, JacobianMatrixDiagBlock &A, GridVariables &gridVariables)
The bulk domain has no additional derivatives.
Definition: multidomain/facet/cellcentered/mpfa/couplingmanager.hh:326
LocalResidual< lowDimId >::ElementResidualVector evalCouplingResidual(LowDimIdType, const LowDimLocalAssembler &lowDimLocalAssembler, BulkIdType, GridIndexType< bulkId > dofIdxGlobalJ)
Evaluates the coupling element residual of a lower-dimensional domain element with respect to a dof i...
Definition: multidomain/facet/cellcentered/mpfa/couplingmanager.hh:142
void extendJacobianPattern(BulkIdType, JacobianPattern &pattern) const
The bulk domain has no extended jacobian pattern.
Definition: multidomain/facet/cellcentered/mpfa/couplingmanager.hh:250
NumEqVector< lowDimId > evalSourcesFromBulk(const Element< lowDimId > &element, const FVElementGeometry< lowDimId > &fvGeometry, const ElementVolumeVariables< lowDimId > &elemVolVars, const SubControlVolume< lowDimId > &scv)
Computes the sources in a lower-dimensional sub-control volume stemming from the bulk domain.
Definition: multidomain/facet/cellcentered/mpfa/couplingmanager.hh:175
Manages the coupling between bulk elements and lower dimensional elements where the coupling occurs a...
Definition: multidomain/facet/cellcentered/tpfa/couplingmanager.hh:53
Implementation for the coupling manager between two domains of dimension d and (d-1) for models consi...
Definition: multidomain/facet/couplingmanager.hh:95
Declares all properties used in Dumux.
The interface of the coupling manager for multi domain problems.