12#ifndef DUMUX_BASE_LOCAL_RESIDUAL_HH
13#define DUMUX_BASE_LOCAL_RESIDUAL_HH
17#include <dune/common/exceptions.hh>
19#include <dumux/common/typetraits/localdofs_.hh>
35template<
class TypeTag>
42 using Element =
typename GridView::template Codim<0>::Entity;
50 using ElementVariables =
typename GridVariablesCache::LocalView;
81 const FVElementGeometry& fvGeometry,
82 const ElementVariables& prevElemVars,
83 const ElementVariables& curElemVars)
const
85 assert(!this->
isStationary() &&
"no time loop set for storage term evaluation");
92 for (
const auto& scv :
scvs(fvGeometry))
93 this->
asImp().evalStorage(residual, this->
problem(), element, fvGeometry, prevElemVars, curElemVars, scv);
96 this->
asImp().addToElementStorageResidual(residual, this->
problem(), element, fvGeometry, prevElemVars, curElemVars);
111 const FVElementGeometry& fvGeometry,
112 const ElementVariables& elemVars,
113 const ElementBoundaryTypes& bcTypes)
const
120 for (
const auto& scv :
scvs(fvGeometry))
121 this->
asImp().evalSource(residual, this->
problem(), element, fvGeometry, elemVars, scv);
124 for (
auto&& scvf : scvfs(fvGeometry))
125 this->
asImp().evalFlux(residual, this->
problem(), element, fvGeometry, elemVars, bcTypes, scvf);
128 this->
asImp().addToElementFluxAndSourceResidual(residual, this->
problem(), element, fvGeometry, elemVars, bcTypes);
136 const Element& element,
137 const FVElementGeometry& fvGeometry,
138 const ElementVariables& prevElemVars,
139 const ElementVariables& curElemVars)
const
145 const Element& element,
146 const FVElementGeometry& fvGeometry,
147 const ElementVariables& curElemVars,
148 const ElementBoundaryTypes& bcTypes)
const
169 template<
class SubControlVolume>
171 const ElementVariables& elemVars,
172 const SubControlVolume& scv,
173 bool isPreviousTimeLevel)
const
175 DUNE_THROW(Dune::NotImplemented,
"This model does not implement a storageIntegral method!");
188 template<
class SubControlVolume>
190 const ElementVariables& elemVars,
191 const SubControlVolume& scv)
const
193 NumEqVector source(0.0);
197 source += qpData.weight() *
problem.source(fvGeometry, elemVars, qpData.ipData());
201 if (!
problem.pointSourceMap().empty())
202 source +=
Extrusion::volume(fvGeometry, scv) *
problem.scvPointSources(fvGeometry.element(), fvGeometry, elemVars, scv);
204 source *= elemVars[scv].extrusionFactor();
219 template<
class SubControlVolumeFace>
221 const ElementVariables& elemVars,
222 const SubControlVolumeFace& scvf)
const
224 DUNE_THROW(Dune::NotImplemented,
"This model does not implement a fluxIntegral method!");
248 template<
class SubControlVolume>
251 const Element& element,
252 const FVElementGeometry& fvGeometry,
253 const ElementVariables& prevElemVars,
254 const ElementVariables& curElemVars,
255 const SubControlVolume& scv)
const
265 NumEqVector prevStorage = this->
asImp().storageIntegral(fvGeometry, prevElemVars, scv,
true);
266 NumEqVector storage = this->
asImp().storageIntegral(fvGeometry, curElemVars, scv,
false);
268 storage -= prevStorage;
271 residual[scv.localDofIndex()] += storage;
286 template<
class SubControlVolume>
289 const Element& element,
290 const FVElementGeometry& fvGeometry,
291 const ElementVariables& curElemVars,
292 const SubControlVolume& scv)
const
295 NumEqVector source = this->
asImp().sourceIntegral(fvGeometry, curElemVars, scv);
297 residual[scv.localDofIndex()] -= source;
311 template<
class SubControlVolumeFace>
314 const Element& element,
315 const FVElementGeometry& fvGeometry,
316 const ElementVariables& elemVars,
317 const ElementBoundaryTypes& elemBcTypes,
318 const SubControlVolumeFace& scvf)
const {}
330 template<
class SubControlVolumeFace>
332 const Element& element,
333 const FVElementGeometry& fvGeometry,
334 const ElementVariables& elemVars,
335 const SubControlVolumeFace& scvf)
const
337 return asImp().evalFlux(
problem, element, fvGeometry, elemVars, scvf);
349 {
return *problem_; }
354 {
return *timeLoop_; }
358 {
return !timeLoop_; }
364 {
return *
static_cast<Implementation*
>(
this); }
367 {
return *
static_cast<const Implementation*
>(
this); }
370 const Problem* problem_;
GVC GridVariablesCache
export type of the grid variables cache
Definition: discretization/gridvariables.hh:33
The element-wise residual for grid-based discretization schemes.
Definition: assembly/localresidual.hh:37
LocalResidual(const Problem *problem, const TimeLoop *timeLoop=nullptr)
the constructor
Definition: assembly/localresidual.hh:58
void addToElementStorageResidual(ElementResidualVector &residual, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVariables &prevElemVars, const ElementVariables &curElemVars) const
add additional storage contributions (e.g. hybrid CVFE or FE schemes)
Definition: assembly/localresidual.hh:134
void evalFlux(ElementResidualVector &residual, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVariables &elemVars, const ElementBoundaryTypes &elemBcTypes, const SubControlVolumeFace &scvf) const
Compute the fluxes of the local residual.
Definition: assembly/localresidual.hh:312
NumEqVector evalFlux(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVariables &elemVars, const SubControlVolumeFace &scvf) const
Compute the fluxes of the local residual.
Definition: assembly/localresidual.hh:331
const Problem & problem() const
the problem
Definition: assembly/localresidual.hh:348
ElementResidualVector evalStorage(const Element &element, const FVElementGeometry &fvGeometry, const ElementVariables &prevElemVars, const ElementVariables &curElemVars) const
Compute the storage local residual, i.e. the deviation of the storage term from zero for instationary...
Definition: assembly/localresidual.hh:80
void evalStorage(ElementResidualVector &residual, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVariables &prevElemVars, const ElementVariables &curElemVars, const SubControlVolume &scv) const
Compute the storage local residual, i.e. the deviation of the storage term from zero for instationary...
Definition: assembly/localresidual.hh:249
const TimeLoop & timeLoop() const
Definition: assembly/localresidual.hh:353
void evalSource(ElementResidualVector &residual, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVariables &curElemVars, const SubControlVolume &scv) const
Compute the source local residual, i.e. the deviation of the source term from zero.
Definition: assembly/localresidual.hh:287
bool isStationary() const
returns true if the residual is stationary
Definition: assembly/localresidual.hh:357
const Implementation & asImp() const
Definition: assembly/localresidual.hh:366
NumEqVector fluxIntegral(const FVElementGeometry &fvGeometry, const ElementVariables &elemVars, const SubControlVolumeFace &scvf) const
Calculate the flux integral of the equation.
Definition: assembly/localresidual.hh:220
NumEqVector sourceIntegral(const FVElementGeometry &fvGeometry, const ElementVariables &elemVars, const SubControlVolume &scv) const
Calculate the source term integral of the equation.
Definition: assembly/localresidual.hh:189
Implementation & asImp()
Definition: assembly/localresidual.hh:363
NumEqVector storageIntegral(const FVElementGeometry &fvGeometry, const ElementVariables &elemVars, const SubControlVolume &scv, bool isPreviousTimeLevel) const
Calculate the source term integral of the equation.
Definition: assembly/localresidual.hh:170
void addToElementFluxAndSourceResidual(ElementResidualVector &residual, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVariables &curElemVars, const ElementBoundaryTypes &bcTypes) const
add additional flux and source contributions (e.g. hybrid CVFE or FE schemes)
Definition: assembly/localresidual.hh:143
ElementResidualVector evalFluxAndSource(const Element &element, const FVElementGeometry &fvGeometry, const ElementVariables &elemVars, const ElementBoundaryTypes &bcTypes) const
Compute the flux and source.
Definition: assembly/localresidual.hh:110
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
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
auto quadratureRule(const FVElementGeometry &fvGeometry, const typename FVElementGeometry::SubControlVolume &scv, QuadratureRules::MidpointQuadrature)
Midpoint quadrature for scv.
Definition: quadraturerules.hh:148
Definition: assembly/assembler.hh:44
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.
Quadrature rules over sub-control volumes and sub-control volume faces.
A arithmetic block vector type based on DUNE's reserved vector.