14#ifndef DUMUX_MULTIDOMAIN_SUBDOMAIN_CVFE_LOCAL_ASSEMBLER_HH
15#define DUMUX_MULTIDOMAIN_SUBDOMAIN_CVFE_LOCAL_ASSEMBLER_HH
19#include <dune/common/reservedvector.hh>
20#include <dune/common/indices.hh>
21#include <dune/common/hybridutilities.hh>
22#include <dune/grid/common/gridenums.hh>
23#include <dune/istl/matrixindexset.hh>
25#include <dumux/common/typetraits/localdofs_.hh>
26#include <dumux/common/typetraits/boundary_.hh>
51template<std::
size_t id,
class TypeTag,
class Assembler,
class Implementation, DiffMethod dm,
bool implicit>
59 using SolutionVector =
typename Assembler::SolutionVector;
63 using GridVolumeVariables =
typename GridVariables::GridVolumeVariables;
64 using ElementVolumeVariables =
typename GridVolumeVariables::LocalView;
65 using ElementFluxVariablesCache =
typename GridVariables::GridFluxVariablesCache::LocalView;
66 using Scalar =
typename GridVariables::Scalar;
68 using GridGeometry =
typename GridVariables::GridGeometry;
69 using FVElementGeometry =
typename GridGeometry::LocalView;
71 using GridView =
typename GridGeometry::GridView;
72 using Element =
typename GridView::template Codim<0>::Entity;
74 using CouplingManager =
typename Assembler::CouplingManager;
80 static constexpr auto domainId =
typename Dune::index_constant<id>();
82 using ParentType::ParentType;
88 const Assembler& assembler,
89 const Element& element,
90 const SolutionVector&
curSol,
93 : ParentType(assembler,
101 (element.partitionType() ==
Dune::GhostEntity))
109 template<
class JacobianMatrixRow,
class SubRes
idualVector,
class Gr
idVariablesTuple>
112 auto assembleCouplingBlocks = [&](
const auto& residual)
115 using namespace Dune::Hybrid;
116 forEach(integralRange(Dune::Hybrid::size(jacRow)), [&](
auto&& i)
118 if constexpr (std::decay_t<
decltype(i)>{} != id)
125 ParentType::assembleJacobianAndResidual(jacRow[
domainId], res, *std::get<domainId>(gridVariables), noReassembler, assembleCouplingBlocks);
132 template<std::size_t otherId,
class JacRow,
class GridVariables,
133 typename std::enable_if_t<(otherId == id),
int> = 0>
141 template<std::size_t otherId,
class JacRow,
class GridVariables,
142 typename std::enable_if_t<(otherId != id),
int> = 0>
146 this->asImp_().assembleJacobianCoupling(domainJ, jacRow[domainJ], res, *std::get<domainId>(gridVariables));
154 static_assert(!Detail::LocalDofs::hasNonCVLocalDofsInterface<FVElementGeometry>(),
"Separate source calculation not implemented for hybrid schemes.");
161 for (
const auto& scv :
scvs(this->fvGeometry()))
163 const auto& curVolVars = elemVolVars[scv];
164 auto source = this->localResidual().computeSource(
problem(), element, this->fvGeometry(), elemVolVars, scv);
165 source *= -Extrusion::volume(this->fvGeometry(), scv)*curVolVars.extrusionFactor();
166 residual[scv.localDofIndex()] = std::move(source);
176 {
return this->
evalLocalSourceResidual(neighbor, implicit ? this->curElemVolVars() : this->prevElemVolVars()); }
184 const auto& element = this->element();
186 auto&& fvGeometry = this->fvGeometry();
187 auto&& curElemVolVars = this->curElemVolVars();
188 auto&& elemFluxVarsCache = this->elemFluxVarsCache();
191 couplingManager_.bindCouplingContext(
domainId, element, this->assembler());
192 fvGeometry.bind(element);
194 if constexpr (implicit)
196 curElemVolVars.bind(element, fvGeometry,
curSol);
197 elemFluxVarsCache.bind(element, fvGeometry, curElemVolVars);
198 if (!this->assembler().isStationaryProblem())
199 this->prevElemVolVars().bindElement(element, fvGeometry, this->assembler().prevSol()[
domainId]);
203 auto& prevElemVolVars = this->prevElemVolVars();
204 const auto& prevSol = this->assembler().prevSol()[
domainId];
206 curElemVolVars.bindElement(element, fvGeometry,
curSol);
207 prevElemVolVars.bind(element, fvGeometry, prevSol);
208 elemFluxVarsCache.bind(element, fvGeometry, prevElemVolVars);
211 this->elemBcTypes().update(
problem(), this->element(), this->fvGeometry());
215 template<std::
size_t i = domainId>
217 {
return this->assembler().problem(
domainId); }
220 template<std::
size_t i = domainId>
222 {
return ParentType::curSol()[dId]; }
226 {
return couplingManager_; }
243template<std::
size_t id,
class TypeTag,
class Assembler, DiffMethod DM = DiffMethod::numeric,
bool implicit = true>
252template<std::
size_t id,
class TypeTag,
class Assembler>
261 using GridView =
typename GridGeometry::GridView;
262 using FVElementGeometry =
typename GridGeometry::LocalView;
263 using Element =
typename GridView::template Codim<0>::Entity;
267 static constexpr int dim = GridView::dimension;
271 static constexpr auto domainI = Dune::index_constant<id>();
274 using ParentType::ParentType;
281 template<
class ScvOrLocalDof,
class ElemSol>
284 this->
couplingManager().updateCouplingContext(domainI, *
this, domainI, scvOrLocalDof.dofIndex(), elemSol[Detail::LocalDofs::index(scvOrLocalDof)], pvIdx);
290 template<
class JacobianMatrixDiagBlock,
class Gr
idVariables>
293 this->
couplingManager().evalAdditionalDomainDerivatives(domainI, *
this, origResiduals, A, gridVariables);
300 template<std::
size_t otherId,
class JacobianBlock,
class Gr
idVariables>
309 const auto& element = this->element();
310 const auto& fvGeometry = this->fvGeometry();
311 auto&& curElemVolVars = this->curElemVolVars();
312 auto&& elemFluxVarsCache = this->elemFluxVarsCache();
315 auto updateCoupledVariables = [&] ()
319 if constexpr (enableGridFluxVarsCache)
321 if constexpr (enableGridVolVarsCache)
322 this->
couplingManager().updateCoupledVariables(domainI, *
this, gridVariables.curGridVolVars(), gridVariables.gridFluxVarsCache());
324 this->
couplingManager().updateCoupledVariables(domainI, *
this, curElemVolVars, gridVariables.gridFluxVarsCache());
328 if constexpr (enableGridVolVarsCache)
329 this->
couplingManager().updateCoupledVariables(domainI, *
this, gridVariables.curGridVolVars(), elemFluxVarsCache);
331 this->
couplingManager().updateCoupledVariables(domainI, *
this, curElemVolVars, elemFluxVarsCache);
336 const auto& stencil = this->
couplingManager().couplingStencil(domainI, element, domainJ);
337 const auto& curSolJ = this->
curSol(domainJ);
338 for (
const auto globalJ : stencil)
341 const auto origPriVarsJ = curSolJ[globalJ];
342 auto priVarsJ = origPriVarsJ;
345 const auto origResidual = this->
couplingManager().evalCouplingResidual(domainI, *
this, domainJ, globalJ);
347 for (
int pvIdx = 0; pvIdx < JacobianBlock::block_type::cols; ++pvIdx)
349 auto evalCouplingResidual = [&](
auto priVar)
351 priVarsJ[pvIdx] = priVar;
352 this->
couplingManager().updateCouplingContext(domainI, *
this, domainJ, globalJ, priVarsJ, pvIdx);
353 updateCoupledVariables();
354 return this->
couplingManager().evalCouplingResidual(domainI, *
this, domainJ, globalJ);
360 const auto& paramGroup = this->assembler().problem(domainJ).paramGroup();
362 static const auto epsCoupl = this->
couplingManager().numericEpsilon(domainJ, paramGroup);
365 epsCoupl(origPriVarsJ[pvIdx], pvIdx), numDiffMethod);
368 for (
const auto& scv :
scvs(fvGeometry))
370 for (
int eqIdx = 0; eqIdx < numEq; eqIdx++)
376 A[scv.dofIndex()][globalJ][eqIdx][pvIdx] += partialDerivs[scv.localDofIndex()][eqIdx];
380 if constexpr (!Detail::hasProblemBoundaryTypesForFaceFunction<Problem, FVElementGeometry>())
384 if (this->elemBcTypes().hasDirichlet())
386 const auto bcTypes = this->elemBcTypes().get(fvGeometry, scv);
387 if (bcTypes.isCouplingDirichlet(eqIdx))
388 A[scv.dofIndex()][globalJ][eqIdx][pvIdx] = partialDerivs[scv.localDofIndex()][eqIdx];
389 else if (bcTypes.isDirichlet(eqIdx))
390 A[scv.dofIndex()][globalJ][eqIdx][pvIdx] = 0.0;
395 if constexpr (Problem::enableInternalDirichletConstraints())
397 const auto internalDirichletConstraints = this->
problem().hasInternalDirichletConstraint(this->element(), scv);
398 if (internalDirichletConstraints[eqIdx])
399 A[scv.dofIndex()][globalJ][eqIdx][pvIdx] = 0.0;
405 if constexpr (Detail::LocalDofs::hasNonCVLocalDofsInterface<FVElementGeometry>())
407 for (
const auto& localDof : nonCVLocalDofs(fvGeometry))
409 for (
int eqIdx = 0; eqIdx < numEq; eqIdx++)
415 A[localDof.dofIndex()][globalJ][eqIdx][pvIdx] += partialDerivs[localDof.index()][eqIdx];
421 priVarsJ[pvIdx] = origPriVarsJ[pvIdx];
424 this->
couplingManager().updateCouplingContext(domainI, *
this, domainJ, globalJ, priVarsJ, pvIdx);
431 updateCoupledVariables();
442template<std::
size_t id,
class TypeTag,
class Assembler>
445 SubDomainCVFELocalAssembler<id, TypeTag, Assembler, DiffMethod::numeric, false>, DiffMethod::numeric, false >
451 using ParentType::ParentType;
461 template<std::
size_t otherId,
class JacobianBlock,
class Gr
idVariables>
An assembler for Jacobian and residual contribution per element (CVFE methods).
An assembler for Jacobian and residual contribution per element (CVFE methods).
Definition assembly/cvfelocalassembler.hh:335
The interface of the coupling manager for multi domain problems.
Definition multidomain/couplingmanager.hh:37
Definition partialreassembler.hh:32
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
typename ParentType::LocalResidual::ElementResidualVector ElementResidualVector
export element residual vector type
Definition multidomain/subdomaincvfelocalassembler.hh:453
void assembleJacobianCoupling(Dune::index_constant< otherId > domainJ, JacobianBlock &A, const ElementResidualVector &res, GridVariables &gridVariables)
Computes the coupling derivatives with respect to the given element and adds them to the global matri...
Definition multidomain/subdomaincvfelocalassembler.hh:462
void maybeEvalAdditionalDomainDerivatives(const ElementResidualVector &origResiduals, JacobianMatrixDiagBlock &A, GridVariables &gridVariables)
Update the additional domain derivatives for coupled models.
Definition multidomain/subdomaincvfelocalassembler.hh:291
typename ParentType::LocalResidual::ElementResidualVector ElementResidualVector
export element residual vector type
Definition multidomain/subdomaincvfelocalassembler.hh:276
void assembleJacobianCoupling(Dune::index_constant< otherId > domainJ, JacobianBlock &A, const ElementResidualVector &res, GridVariables &gridVariables)
Computes the derivatives with respect to the given element and adds them to the global matrix.
Definition multidomain/subdomaincvfelocalassembler.hh:301
void maybeUpdateCouplingContext(const ScvOrLocalDof &scvOrLocalDof, ElemSol &elemSol, const int pvIdx)
Update the coupling context for coupled models.
Definition multidomain/subdomaincvfelocalassembler.hh:282
const auto & curSol(Dune::index_constant< i > dId=domainId) const
Definition multidomain/subdomaincvfelocalassembler.hh:221
static constexpr auto domainId
Definition multidomain/subdomaincvfelocalassembler.hh:80
SubDomainCVFELocalAssemblerBase(const Assembler &assembler, const Element &element, const SolutionVector &curSol, CouplingManager &couplingManager)
Definition multidomain/subdomaincvfelocalassembler.hh:87
ElementResidualVector evalLocalSourceResidual(const Element &element, const ElementVolumeVariables &elemVolVars) const
Evaluates the local source term for an element and given element volume variables.
Definition multidomain/subdomaincvfelocalassembler.hh:152
void bindLocalViews()
Prepares all local views necessary for local assembly.
Definition multidomain/subdomaincvfelocalassembler.hh:181
typename ParentType::LocalResidual::ElementResidualVector ElementResidualVector
export element residual vector type
Definition multidomain/subdomaincvfelocalassembler.hh:84
ElementResidualVector evalLocalSourceResidual(const Element &neighbor) const
Evaluates the local source term depending on time discretization scheme.
Definition multidomain/subdomaincvfelocalassembler.hh:175
const Problem & problem(Dune::index_constant< i > dId=domainId) const
return reference to the underlying problem
Definition multidomain/subdomaincvfelocalassembler.hh:216
CouplingManager & couplingManager()
Definition multidomain/subdomaincvfelocalassembler.hh:225
void assembleJacobianCoupling(Dune::index_constant< otherId > domainJ, JacRow &jacRow, const ElementResidualVector &res, GridVariables &gridVariables)
Assemble the entries in a coupling block of the jacobian. There is no coupling block between a domain...
Definition multidomain/subdomaincvfelocalassembler.hh:134
void assembleJacobianAndResidual(JacobianMatrixRow &jacRow, SubResidualVector &res, GridVariablesTuple &gridVariables)
Computes the derivatives with respect to the given element and adds them to the global matrix....
Definition multidomain/subdomaincvfelocalassembler.hh:110
The CVFE scheme multidomain local assembler.
Definition multidomain/subdomaincvfelocalassembler.hh:244
Defines all properties used in Dumux.
An enum class to define various differentiation methods available in order to compute the derivatives...
Helper classes to compute the integration elements.
DiffMethod
Differentiation methods in order to compute the derivatives of the residual i.e. the entries in the j...
Definition diffmethod.hh:25
@ numeric
Definition diffmethod.hh:26
typename NumEqVectorTraits< PrimaryVariables >::type NumEqVector
A vector with the same size as numbers of equations This is the default implementation and has to be ...
Definition numeqvector.hh:34
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition localview.hh:26
T getParamFromGroup(Args &&... args)
A free function to get a parameter from the parameter tree singleton with a model group.
Definition parameters.hh:165
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition propertysystem.hh:296
Class representing dofs on elements for control-volume finite element schemes.
std::ranges::range auto scvs(const FVElementGeometry &fvGeometry, const LocalDof &localDof)
Definition localdof.hh:82
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition extrusion.hh:257
Definition common/pdesolver.hh:24
A helper to deduce a vector with the same size as numbers of equations.
A class for numeric differentiation.
An adapter class for local assemblers using numeric differentiation.
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
A arithmetic block vector type based on DUNE's reserved vector.