12#ifndef DUMUX_FV_LOCAL_RESIDUAL_HH
13#define DUMUX_FV_LOCAL_RESIDUAL_HH
15#include <dune/common/exceptions.hh>
16#include <dune/istl/bvector.hh>
18#include <dumux/common/typetraits/localdofs_.hh>
34template<
class TypeTag>
41 using Element =
typename GridView::template Codim<0>::Entity;
45 using SubControlVolume =
typename GridGeometry::SubControlVolume;
46 using SubControlVolumeFace =
typename GridGeometry::SubControlVolumeFace;
88 const Element &element,
89 const GridGeometry& gridGeometry,
90 const GridVariables& gridVariables,
91 const SolutionVector& sol)
const
94 const auto fvGeometry =
localView(gridGeometry).bind(element);
95 const auto elemVolVars =
localView(gridVariables.curGridVolVars()).bind(element, fvGeometry, sol);
101 for (
auto&& scv :
scvs(fvGeometry))
103 auto localScvIdx = scv.localDofIndex();
104 const auto& volVars = elemVolVars[scv];
105 storage[localScvIdx] =
asImp().computeStorage(
problem, scv, volVars);
106 storage[localScvIdx] *=
Extrusion::volume(fvGeometry, scv) * volVars.extrusionFactor();
133 const FVElementGeometry& fvGeometry,
134 const ElementVolumeVariables& prevElemVolVars,
135 const ElementVolumeVariables& curElemVolVars)
const
137 assert(timeLoop_ &&
"no time loop set for storage term evaluation");
144 for (
auto&& scv :
scvs(fvGeometry))
145 asImp().evalStorage(residual, this->
problem(), element, fvGeometry, prevElemVolVars, curElemVolVars, scv);
151 const FVElementGeometry& fvGeometry,
152 const ElementVolumeVariables& elemVolVars,
153 const ElementFluxVariablesCache& elemFluxVarsCache,
154 const ElementBoundaryTypes &bcTypes)
const
161 for (
auto&& scv :
scvs(fvGeometry))
162 asImp().evalSource(residual, this->
problem(), element, fvGeometry, elemVolVars, scv);
165 for (
auto&& scvf : scvfs(fvGeometry))
166 asImp().evalFlux(residual, this->
problem(), element, fvGeometry, elemVolVars, bcTypes, elemFluxVarsCache, scvf);
190 const SubControlVolume& scv,
191 const VolumeVariables& volVars)
const
193 DUNE_THROW(Dune::NotImplemented,
"This model does not implement a storage method!");
210 const Element& element,
211 const FVElementGeometry& fvGeometry,
212 const ElementVolumeVariables& elemVolVars,
213 const SubControlVolume &scv)
const
215 NumEqVector source(0.0);
218 source +=
problem.source(element, fvGeometry, elemVolVars, scv);
221 if (!
problem.pointSourceMap().empty())
222 source +=
problem.scvPointSources(element, fvGeometry, elemVolVars, scv);
242 const Element& element,
243 const FVElementGeometry& fvGeometry,
244 const ElementVolumeVariables& elemVolVars,
245 const SubControlVolumeFace& scvf,
246 const ElementFluxVariablesCache& elemFluxVarsCache)
const
248 DUNE_THROW(Dune::NotImplemented,
"This model does not implement a flux method!");
276 const Element& element,
277 const FVElementGeometry& fvGeometry,
278 const ElementVolumeVariables& prevElemVolVars,
279 const ElementVolumeVariables& curElemVolVars,
280 const SubControlVolume& scv)
const
282 const auto& curVolVars = curElemVolVars[scv];
283 const auto& prevVolVars = prevElemVolVars[scv];
293 NumEqVector prevStorage =
asImp().computeStorage(
problem, scv, prevVolVars);
294 NumEqVector storage =
asImp().computeStorage(
problem, scv, curVolVars);
296 prevStorage *= prevVolVars.extrusionFactor();
297 storage *= curVolVars.extrusionFactor();
299 storage -= prevStorage;
303 residual[scv.localDofIndex()] += storage;
321 const Element& element,
322 const FVElementGeometry& fvGeometry,
323 const ElementVolumeVariables& curElemVolVars,
324 const SubControlVolume& scv)
const
327 const auto& curVolVars = curElemVolVars[scv];
328 NumEqVector source =
asImp().computeSource(
problem, element, fvGeometry, curElemVolVars, scv);
332 residual[scv.localDofIndex()] -= source;
351 const Element& element,
352 const FVElementGeometry& fvGeometry,
353 const ElementVolumeVariables& elemVolVars,
354 const ElementBoundaryTypes& elemBcTypes,
355 const ElementFluxVariablesCache& elemFluxVarsCache,
356 const SubControlVolumeFace& scvf)
const {}
372 const Element& element,
373 const FVElementGeometry& fvGeometry,
374 const ElementVolumeVariables& elemVolVars,
375 const ElementFluxVariablesCache& elemFluxVarsCache,
376 const SubControlVolumeFace& scvf)
const
378 return asImp().evalFlux(
problem, element, fvGeometry, elemVolVars, elemFluxVarsCache, scvf);
389 template<
class PartialDerivativeMatrix>
392 const Element& element,
393 const FVElementGeometry& fvGeometry,
394 const VolumeVariables& curVolVars,
395 const SubControlVolume& scv)
const
397 DUNE_THROW(Dune::NotImplemented,
"analytic storage derivative");
401 template<
class PartialDerivativeMatrix>
404 const Element& element,
405 const FVElementGeometry& fvGeometry,
406 const VolumeVariables& curVolVars,
407 const SubControlVolume& scv)
const
409 DUNE_THROW(Dune::NotImplemented,
"analytic source derivative");
413 template<
class PartialDerivativeMatrices,
class T = TypeTag>
417 const Element& element,
418 const FVElementGeometry& fvGeometry,
419 const ElementVolumeVariables& curElemVolVars,
420 const ElementFluxVariablesCache& elemFluxVarsCache,
421 const SubControlVolumeFace& scvf)
const
423 DUNE_THROW(Dune::NotImplemented,
"analytic flux derivative for cell-centered models");
427 template<
class JacobianMatrix,
class T = TypeTag>
431 const Element& element,
432 const FVElementGeometry& fvGeometry,
433 const ElementVolumeVariables& curElemVolVars,
434 const ElementFluxVariablesCache& elemFluxVarsCache,
435 const SubControlVolumeFace& scvf)
const
437 DUNE_THROW(Dune::NotImplemented,
"analytic flux derivative for box models");
441 template<
class PartialDerivativeMatrices>
444 const Element& element,
445 const FVElementGeometry& fvGeometry,
446 const ElementVolumeVariables& curElemVolVars,
447 const ElementFluxVariablesCache& elemFluxVarsCache,
448 const SubControlVolumeFace& scvf)
const
450 DUNE_THROW(Dune::NotImplemented,
"analytic Dirichlet flux derivative");
454 template<
class PartialDerivativeMatrices>
457 const Element& element,
458 const FVElementGeometry& fvGeometry,
459 const ElementVolumeVariables& curElemVolVars,
460 const ElementFluxVariablesCache& elemFluxVarsCache,
461 const SubControlVolumeFace& scvf)
const
463 DUNE_THROW(Dune::NotImplemented,
"analytic Robin flux derivative");
475 {
return *problem_; }
480 {
return *timeLoop_; }
484 {
return !timeLoop_; }
490 {
return *
static_cast<Implementation*
>(
this); }
493 {
return *
static_cast<const Implementation*
>(
this); }
496 const Problem* problem_;
The element-wise residual for finite volume schemes.
Definition: fvlocalresidual.hh:36
Implementation & asImp()
Definition: fvlocalresidual.hh:489
NumEqVector computeSource(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolume &scv) const
Calculate the source term of the equation.
Definition: fvlocalresidual.hh:209
void addRobinFluxDerivatives(PartialDerivativeMatrices &derivativeMatrices, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &curElemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
Compute the derivative of Robin type boundary conditions ("solution dependent Neumann")
Definition: fvlocalresidual.hh:455
NumEqVector computeStorage(const Problem &problem, const SubControlVolume &scv, const VolumeVariables &volVars) const
Calculate the source term of the equation.
Definition: fvlocalresidual.hh:189
void evalFlux(ElementResidualVector &residual, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const ElementBoundaryTypes &elemBcTypes, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
Compute the flux local residual, i.e. the deviation of the flux term from zero.
Definition: fvlocalresidual.hh:349
const Problem & problem() const
the problem
Definition: fvlocalresidual.hh:474
void addSourceDerivatives(PartialDerivativeMatrix &partialDerivatives, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const VolumeVariables &curVolVars, const SubControlVolume &scv) const
Compute the derivative of the source residual.
Definition: fvlocalresidual.hh:402
const TimeLoop & timeLoop() const
Definition: fvlocalresidual.hh:479
void addStorageDerivatives(PartialDerivativeMatrix &partialDerivatives, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const VolumeVariables &curVolVars, const SubControlVolume &scv) const
Compute the derivative of the storage residual.
Definition: fvlocalresidual.hh:390
bool isStationary() const
returns true if the residual is stationary
Definition: fvlocalresidual.hh:483
NumEqVector evalFlux(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
Compute the flux local residual, i.e. the deviation of the flux term from zero.
Definition: fvlocalresidual.hh:371
const Implementation & asImp() const
Definition: fvlocalresidual.hh:492
ElementResidualVector evalStorage(const Problem &problem, const Element &element, const GridGeometry &gridGeometry, const GridVariables &gridVariables, const SolutionVector &sol) const
Compute the storage term for the current solution.
Definition: fvlocalresidual.hh:87
FVLocalResidual(const Problem *problem, const TimeLoop *timeLoop=nullptr)
the constructor
Definition: fvlocalresidual.hh:61
ElementResidualVector evalStorage(const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &prevElemVolVars, const ElementVolumeVariables &curElemVolVars) const
Compute the storage local residual, i.e. the deviation of the storage term from zero for instationary...
Definition: fvlocalresidual.hh:132
std::enable_if_t< GetPropType< T, Properties::GridGeometry >::discMethod !=DiscretizationMethods::box, void > addFluxDerivatives(PartialDerivativeMatrices &derivativeMatrices, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &curElemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
Compute the derivative of the flux residual.
Definition: fvlocalresidual.hh:415
void evalSource(ElementResidualVector &residual, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &curElemVolVars, const SubControlVolume &scv) const
Compute the source local residual, i.e. the deviation of the source term from zero.
Definition: fvlocalresidual.hh:319
std::enable_if_t< GetPropType< T, Properties::GridGeometry >::discMethod==DiscretizationMethods::box, void > addFluxDerivatives(JacobianMatrix &A, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &curElemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
Compute the derivative of the flux residual for the box method.
Definition: fvlocalresidual.hh:429
ElementResidualVector evalFluxAndSource(const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const ElementBoundaryTypes &bcTypes) const
Definition: fvlocalresidual.hh:150
void evalStorage(ElementResidualVector &residual, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &prevElemVolVars, const ElementVolumeVariables &curElemVolVars, const SubControlVolume &scv) const
Compute the storage local residual, i.e. the deviation of the storage term from zero for instationary...
Definition: fvlocalresidual.hh:274
void addCCDirichletFluxDerivatives(PartialDerivativeMatrices &derivativeMatrices, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &curElemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
Compute the derivative of the Dirichlet flux residual for cell-centered schemes.
Definition: fvlocalresidual.hh:442
NumEqVector computeFlux(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolumeFace &scvf, const ElementFluxVariablesCache &elemFluxVarsCache) const
Calculate the flux term of the equation.
Definition: fvlocalresidual.hh:241
A arithmetic block vector type based on DUNE's reserved vector.
Definition: reservedblockvector.hh:26
virtual Scalar timeStepSize() const =0
Returns the suggested time step length .
The default time loop for instationary simulations.
Definition: common/timeloop.hh:139
Defines all properties used in Dumux.
Manages the handling of time dependent problems.
Helper classes to compute the integration elements.
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
auto volume(const Geometry &geo, unsigned int integrationOrder=4)
The volume of a given geometry.
Definition: volume.hh:159
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:296
The available discretization methods in Dumux.
constexpr Box box
Definition: method.hh:147
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:166
std::ranges::range auto scvs(const FVElementGeometry &fvGeometry, const LocalDof &localDof)
Definition: localdof.hh:79
A helper to deduce a vector with the same size as numbers of equations.
A arithmetic block vector type based on DUNE's reserved vector.