13#ifndef DUMUX_MULTIDOMAIN_EMBEDDED_EXTENDEDSOURCESTENCIL_HH
14#define DUMUX_MULTIDOMAIN_EMBEDDED_EXTENDEDSOURCESTENCIL_HH
18#include <dune/common/indices.hh>
36template<
class CouplingManager>
39 using MDTraits =
typename CouplingManager::MultiDomainTraits;
41 template<std::
size_t id>
using SubDomainTypeTag =
typename MDTraits::template SubDomain<id>::TypeTag;
43 template<std::
size_t id>
using GridView =
typename GridGeometry<id>::GridView;
44 template<std::
size_t id>
using Element =
typename GridView<id>::template Codim<0>::Entity;
46 static constexpr auto bulkIdx =
typename MDTraits::template SubDomain<0>::Index();
47 static constexpr auto lowDimIdx =
typename MDTraits::template SubDomain<1>::Index();
49 template<std::
size_t id>
50 static constexpr bool isCVFE()
59 template<std::
size_t id,
class JacobianPattern>
63 for (
const auto& element : elements(couplingManager.gridView(domainI)))
65 const auto& dofs = extendedSourceStencil_(couplingManager, domainI, element);
66 if constexpr (isCVFE<domainI>())
69 for (
const auto globalI : couplingManager.elementDofIndices(domainI, eIdx))
70 for (
const auto globalJ : dofs)
71 pattern.add(globalI, globalJ);
76 for (
const auto globalJ : dofs)
77 pattern.add(globalI, globalJ);
88 template<std::
size_t i,
class LocalAssemblerI,
class JacobianMatrixDiagBlock,
class Gr
idVariables>
90 Dune::index_constant<i> domainI,
91 const LocalAssemblerI& localAssemblerI,
92 JacobianMatrixDiagBlock& A,
93 GridVariables& gridVariables)
const
95 const auto& curSolI = couplingManager.
curSol(domainI);
96 constexpr auto numEq = std::decay_t<
decltype(curSolI[0])>::size();
97 using PrimaryVariable =
typename std::decay_t<
decltype(curSolI[0])>::value_type;
98 const auto& elementI = localAssemblerI.element();
101 if (extendedSourceStencil_(couplingManager, domainI, elementI).empty())
105 const auto origResidual = localAssemblerI.evalLocalSourceResidual(elementI);
108 for (
const auto dofIndex : extendedSourceStencil_(couplingManager, domainI, elementI))
110 auto partialDerivs = origResidual;
111 const auto origPriVars = curSolI[dofIndex];
112 auto priVars = origPriVars;
115 for (
int pvIdx = 0; pvIdx < numEq; pvIdx++)
120 const auto evalResiduals = [&](
const PrimaryVariable priVar)
123 priVars[pvIdx] = priVar;
125 return localAssemblerI.evalLocalSourceResidual(elementI);
130 static const int numDiffMethod =
getParamFromGroup<int>(localAssemblerI.problem().paramGroup(),
"Assembly.NumericDifferenceMethod");
132 evalResiduals, priVars[pvIdx], partialDerivs, origResidual, eps_(priVars[pvIdx], pvIdx), numDiffMethod
136 const auto& elemDiscI = [&]() ->
decltype(
auto) {
137 if constexpr (
requires { localAssemblerI.elemDisc(); })
138 return localAssemblerI.elemDisc();
140 return localAssemblerI.fvGeometry();
142 if constexpr (isCVFE<i>())
144 for (
const auto& localDof :
localDofs(elemDiscI))
146 for (
int eqIdx = 0; eqIdx < numEq; eqIdx++)
152 A[localDof.dofIndex()][dofIndex][eqIdx][pvIdx] += partialDerivs[localDof.index()][eqIdx];
158 for (
const auto& scvJ :
scvs(elemDiscI))
159 for (
int eqIdx = 0; eqIdx < numEq; eqIdx++)
160 A[scvJ.dofIndex()][dofIndex][eqIdx][pvIdx] += partialDerivs[scvJ.indexInElement()][eqIdx];
164 priVars[pvIdx] = origPriVars[pvIdx];
167 couplingManager.
updateCouplingContext(domainI, localAssemblerI, domainI, dofIndex, origPriVars, pvIdx);
173 void clear() { sourceStencils_.clear(); }
176 typename CouplingManager::template CouplingStencils<bulkIdx>&
stencil()
177 {
return sourceStencils_; }
180 const typename CouplingManager::template CouplingStencils<bulkIdx>&
stencil()
const
181 {
return sourceStencils_; }
185 template<std::
size_t id>
186 const auto& extendedSourceStencil_(
const CouplingManager& couplingManager, Dune::index_constant<id> domainId,
const Element<id>& element)
const
188 if constexpr (domainId == bulkIdx)
191 if (
auto stencil = sourceStencils_.find(bulkElementIdx);
stencil != sourceStencils_.end())
195 return couplingManager.emptyStencil(domainId);
199 typename CouplingManager::template CouplingStencils<bulkIdx> sourceStencils_;
The interface of the coupling manager for multi domain problems.
Definition multidomain/couplingmanager.hh:37
const Problem< i > & problem(Dune::index_constant< i > domainIdx) const
Return a reference to the sub problem.
Definition multidomain/couplingmanager.hh:318
SubSolutionVector< i > & curSol(Dune::index_constant< i > domainIdx)
the solution vector of the subproblem
Definition multidomain/couplingmanager.hh:347
A class managing an extended source stencil.
Definition embedded/extendedsourcestencil.hh:38
void evalAdditionalDomainDerivatives(CouplingManager &couplingManager, Dune::index_constant< i > domainI, const LocalAssemblerI &localAssemblerI, JacobianMatrixDiagBlock &A, GridVariables &gridVariables) const
evaluate additional derivatives of the element residual of a domain with respect to dofs in the same ...
Definition embedded/extendedsourcestencil.hh:89
void extendJacobianPattern(const CouplingManager &couplingManager, Dune::index_constant< id > domainI, JacobianPattern &pattern) const
extend the jacobian pattern of the diagonal block of domain i by those entries that are not already i...
Definition embedded/extendedsourcestencil.hh:60
const CouplingManager::template CouplingStencils< bulkIdx > & stencil() const
return a const reference to the stencil
Definition embedded/extendedsourcestencil.hh:180
void clear()
clear the internal data
Definition embedded/extendedsourcestencil.hh:173
CouplingManager::template CouplingStencils< bulkIdx > & stencil()
return a reference to the stencil
Definition embedded/extendedsourcestencil.hh:176
static void partialDerivative(const Function &function, Scalar x0, FunctionEvalType &derivative, const FunctionEvalType &fx0, const int numericDifferenceMethod=1)
Computes the derivative of a function with respect to a function parameter.
Definition numericdifferentiation.hh:56
A helper class for local assemblers using numeric differentiation to determine the epsilon.
Definition numericepsilon.hh:33
Defines all properties used in Dumux.
Type traits for classes providing a grid discretization.
void updateCouplingContext(Dune::index_constant< i > domainI, const LocalAssemblerI &localAssemblerI, Dune::index_constant< j > domainJ, std::size_t dofIdxGlobalJ, const PrimaryVariables< j > &priVarsJ, int pvIdxJ)
updates all data and variables that are necessary to evaluate the residual of the element of domain i...
Definition multidomain/couplingmanager.hh:171
T getParamFromGroup(Args &&... args)
A free function to get a parameter from the parameter tree singleton with a model group.
Definition parameters.hh:168
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition propertysystem.hh:296
decltype(auto) gridDiscretization(const T &t, Args &&... args)
The grid discretization.
Definition griddiscretization.hh:98
Class representing dofs on elements for control-volume finite element schemes.
The available discretization methods in Dumux.
constexpr bool isCVFE
Definition method.hh:67
Definition circlepoints.hh:24
std::ranges::range auto scvs(const FVElementGeometry &fvGeometry, const LocalDof &localDof)
Definition localdof.hh:82
auto localDofs(const FVElementGeometry &fvGeometry)
range over local dofs
Definition localdof.hh:50
A class for numeric differentiation.
An adapter class for local assemblers using numeric differentiation.
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.