version 3.8
fclocalresidual.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
13#ifndef DUMUX_FACECENTERED_LOCAL_RESIDUAL_HH
14#define DUMUX_FACECENTERED_LOCAL_RESIDUAL_HH
15
16#include <dune/geometry/type.hh>
17#include <dune/istl/matrix.hh>
18
23
24namespace Dumux {
25
32template<class TypeTag>
34{
39 using GridView = typename GridGeometry::GridView;
40 using Element = typename GridView::template Codim<0>::Entity;
42 using FVElementGeometry = typename GridGeometry::LocalView;
43 using ElementVolumeVariables = typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView;
44 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
45 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
46 using ElementFluxVariablesCache = typename GetPropType<TypeTag, Properties::GridFluxVariablesCache>::LocalView;
48 using Extrusion = Extrusion_t<GridGeometry>;
49
50public:
52 using ParentType::ParentType;
53
56 const Problem& problem,
57 const Element& element,
58 const FVElementGeometry& fvGeometry,
59 const ElementVolumeVariables& elemVolVars,
60 const ElementBoundaryTypes& elemBcTypes,
61 const ElementFluxVariablesCache& elemFluxVarsCache,
62 const SubControlVolumeFace& scvf) const
63 {
64 const auto flux = evalFlux(problem, element, fvGeometry, elemVolVars, elemBcTypes, elemFluxVarsCache, scvf);
65 const auto& insideScv = fvGeometry.scv(scvf.insideScvIdx());
66 residual[insideScv.localDofIndex()] += flux;
67 }
68
70 NumEqVector evalFlux(const Problem& problem,
71 const Element& element,
72 const FVElementGeometry& fvGeometry,
73 const ElementVolumeVariables& elemVolVars,
74 const ElementBoundaryTypes& elemBcTypes,
75 const ElementFluxVariablesCache& elemFluxVarsCache,
76 const SubControlVolumeFace& scvf) const
77 {
78 if (elemBcTypes.hasDirichlet())
79 return this->asImp().maybeHandleDirichletBoundary(problem, element, fvGeometry, elemVolVars, elemBcTypes, elemFluxVarsCache, scvf);
80
81 if (elemBcTypes.hasNeumann())
82 return this->asImp().maybeHandleNeumannBoundary(problem, element, fvGeometry, elemVolVars, elemBcTypes, elemFluxVarsCache, scvf);
83
84 return this->asImp().computeFlux(problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache, elemBcTypes);
85 }
86
100 NumEqVector computeSource(const Problem& problem,
101 const Element& element,
102 const FVElementGeometry& fvGeometry,
103 const ElementVolumeVariables& elemVolVars,
104 const SubControlVolume& scv) const
105 {
106 NumEqVector source(0.0);
107
108 // add contributions from volume flux sources
109 source += problem.source(element, fvGeometry, elemVolVars, scv)[scv.dofAxis()];
110
111 // add contribution from possible point sources
112 source += problem.scvPointSources(element, fvGeometry, elemVolVars, scv)[scv.dofAxis()];
113
114 return source;
115 }
116
118
135 const Problem& problem,
136 const Element& element,
137 const FVElementGeometry& fvGeometry,
138 const ElementVolumeVariables& prevElemVolVars,
139 const ElementVolumeVariables& curElemVolVars,
140 const SubControlVolume& scv) const
141 {
142 const auto& curVolVars = curElemVolVars[scv];
143 const auto& prevVolVars = prevElemVolVars[scv];
144
145 // mass balance within the element. this is the
146 // \f$\frac{m}{\partial t}\f$ term if using implicit or explicit
147 // euler as time discretization.
148 //
149
151 NumEqVector prevStorage = this->asImp().computeStorage(problem, scv, prevVolVars, true/*isPreviousStorage*/);
152 NumEqVector storage = this->asImp().computeStorage(problem, scv, curVolVars, false/*isPreviousStorage*/);
153
154 prevStorage *= prevVolVars.extrusionFactor();
155 storage *= curVolVars.extrusionFactor();
156
157 storage -= prevStorage;
158 storage *= Extrusion::volume(fvGeometry, scv);
159 storage /= this->timeLoop().timeStepSize();
160
161 residual[scv.localDofIndex()] += storage;
162 }
163};
164
165} // end namespace Dumux
166
167#endif
The element-wise residual for finite volume schemes.
Definition: fvlocalresidual.hh:35
Implementation & asImp()
Definition: fvlocalresidual.hh:487
const Problem & problem() const
the problem
Definition: fvlocalresidual.hh:472
ReservedBlockVector< NumEqVector, FVElementGeometry::maxNumElementScvs > ElementResidualVector
the container storing all element residuals
Definition: fvlocalresidual.hh:57
const TimeLoop & timeLoop() const
Definition: fvlocalresidual.hh:477
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:86
The element-wise residual for the box scheme.
Definition: fclocalresidual.hh:34
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: fclocalresidual.hh:134
typename ParentType::ElementResidualVector ElementResidualVector
Definition: fclocalresidual.hh:51
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
evaluate flux residuals for one sub control volume face and add to residual
Definition: fclocalresidual.hh:55
NumEqVector evalFlux(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const ElementBoundaryTypes &elemBcTypes, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
evaluate flux residuals for one sub control volume face
Definition: fclocalresidual.hh:70
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: fclocalresidual.hh:100
virtual Scalar timeStepSize() const =0
Returns the suggested time step length .
Defines all properties used in Dumux.
Helper classes to compute the integration elements.
The element-wise residual for finite volume schemes.
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
Definition: adapt.hh:17
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:166
A helper to deduce a vector with the same size as numbers of equations.