25#ifndef DUMUX_MULTIDOMAIN_EMBEDDED_EXTENDEDSOURCESTENCIL_HH
26#define DUMUX_MULTIDOMAIN_EMBEDDED_EXTENDEDSOURCESTENCIL_HH
30#include <dune/common/indices.hh>
38namespace EmbeddedCoupling {
45template<
class CouplingManager>
48 using MDTraits =
typename CouplingManager::MultiDomainTraits;
49 using Scalar =
typename MDTraits::Scalar;
51 template<std::
size_t id>
using SubDomainTypeTag =
typename MDTraits::template SubDomain<id>::TypeTag;
53 template<std::
size_t id>
using GridView =
typename GridGeometry<id>::GridView;
54 template<std::
size_t id>
using Element =
typename GridView<id>::template Codim<0>::Entity;
56 static constexpr auto bulkIdx =
typename MDTraits::template SubDomain<0>::Index();
57 static constexpr auto lowDimIdx =
typename MDTraits::template SubDomain<1>::Index();
59 template<std::
size_t id>
60 static constexpr bool isBox()
69 template<std::
size_t id,
class JacobianPattern>
73 for (
const auto& element : elements(couplingManager.gridView(domainI)))
75 const auto& dofs = extendedSourceStencil_(couplingManager, domainI, element);
79 for (
int i = 0; i < element.subEntities(GridView<domainI>::dimension); ++i)
80 for (
const auto globalJ : dofs)
81 pattern.add(couplingManager.
problem(domainI).gridGeometry().vertexMapper().subIndex(element, i, GridView<domainI>::dimension), globalJ);
85 const auto globalI = couplingManager.
problem(domainI).gridGeometry().elementMapper().index(element);
86 for (
const auto globalJ : dofs)
87 pattern.add(globalI, globalJ);
99 template<std::
size_t i,
class LocalAssemblerI,
class SolutionVector,
class JacobianMatrixDiagBlock,
class Gr
idVariables>
101 Dune::index_constant<i> domainI,
102 const LocalAssemblerI& localAssemblerI,
103 const SolutionVector& curSol,
104 JacobianMatrixDiagBlock& A,
105 GridVariables& gridVariables)
const
107 constexpr auto numEq = std::decay_t<
decltype(curSol[domainI][0])>::dimension;
108 const auto& elementI = localAssemblerI.element();
111 if (extendedSourceStencil_(couplingManager, domainI, elementI).empty())
115 const auto origResidual = localAssemblerI.evalLocalSourceResidual(elementI);
118 for (
const auto dofIndex : extendedSourceStencil_(couplingManager, domainI, elementI))
120 auto partialDerivs = origResidual;
121 const auto origPriVars = curSol[domainI][dofIndex];
124 for (
int pvIdx = 0; pvIdx < numEq; pvIdx++)
129 auto evalResiduals = [&](Scalar priVar)
132 auto priVars = origPriVars;
133 priVars[pvIdx] = priVar;
135 return localAssemblerI.evalLocalSourceResidual(elementI);
139 static const int numDiffMethod = getParam<int>(
"Assembly.NumericDifferenceMethod");
141 partialDerivs, origResidual, numDiffMethod);
144 for (
auto&& scvJ : scvs(localAssemblerI.fvGeometry()))
146 for (
int eqIdx = 0; eqIdx < numEq; eqIdx++)
152 A[scvJ.dofIndex()][dofIndex][eqIdx][pvIdx] += partialDerivs[scvJ.indexInElement()][eqIdx];
157 couplingManager.
updateCouplingContext(domainI, localAssemblerI, domainI, dofIndex, origPriVars, pvIdx);
163 typename CouplingManager::CouplingStencils&
stencil()
164 {
return sourceStencils_; }
168 const std::vector<std::size_t>& extendedSourceStencil_(
const CouplingManager& couplingManager, Dune::index_constant<0> bulkDomain,
const Element<0>& bulkElement)
const
170 const auto bulkElementIdx = couplingManager.
problem(bulkIdx).gridGeometry().elementMapper().index(bulkElement);
171 if (sourceStencils_.count(bulkElementIdx))
172 return sourceStencils_.at(bulkElementIdx);
174 return couplingManager.emptyStencil();
178 const std::vector<std::size_t>& extendedSourceStencil_(
const CouplingManager& couplingManager, Dune::index_constant<1> bulkDomain,
const Element<1>& lowDimElement)
const
179 {
return couplingManager.emptyStencil(); }
182 typename CouplingManager::CouplingStencils sourceStencils_;
A class for numeric differentiation.
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
The available discretization methods in Dumux.
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:152
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
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
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
Definition: common/properties.hh:150
Definition: multidomain/couplingmanager.hh:46
const Problem< i > & problem(Dune::index_constant< i > domainIdx) const
Return a reference to the sub problem.
Definition: multidomain/couplingmanager.hh:264
A class managing an extended source stencil.
Definition: extendedsourcestencil.hh:47
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: extendedsourcestencil.hh:70
void evalAdditionalDomainDerivatives(CouplingManager &couplingManager, Dune::index_constant< i > domainI, const LocalAssemblerI &localAssemblerI, const SolutionVector &curSol, JacobianMatrixDiagBlock &A, GridVariables &gridVariables) const
evaluate additional derivatives of the element residual of a domain with respect to dofs in the same ...
Definition: extendedsourcestencil.hh:100
CouplingManager::CouplingStencils & stencil()
return a reference to the stencil
Definition: extendedsourcestencil.hh:163
Declares all properties used in Dumux.