3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
boxlocalresidual.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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
25#ifndef DUMUX_BOX_LOCAL_RESIDUAL_HH
26#define DUMUX_BOX_LOCAL_RESIDUAL_HH
27
28#include <dune/geometry/type.hh>
29#include <dune/istl/matrix.hh>
30
34
35namespace Dumux {
36
43template<class TypeTag>
44class BoxLocalResidual : public FVLocalResidual<TypeTag>
45{
50 using Element = typename GridView::template Codim<0>::Entity;
52 using FVElementGeometry = typename GetPropType<TypeTag, Properties::GridGeometry>::LocalView;
53 using ElementVolumeVariables = typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView;
54 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
55 using ElementFluxVariablesCache = typename GetPropType<TypeTag, Properties::GridFluxVariablesCache>::LocalView;
57
58public:
60 using ParentType::ParentType;
61
64 const Problem& problem,
65 const Element& element,
66 const FVElementGeometry& fvGeometry,
67 const ElementVolumeVariables& elemVolVars,
68 const ElementBoundaryTypes& elemBcTypes,
69 const ElementFluxVariablesCache& elemFluxVarsCache,
70 const SubControlVolumeFace& scvf) const
71 {
72 const auto flux = evalFlux(problem, element, fvGeometry, elemVolVars, elemBcTypes, elemFluxVarsCache, scvf);
73 if (!scvf.boundary())
74 {
75 const auto& insideScv = fvGeometry.scv(scvf.insideScvIdx());
76 const auto& outsideScv = fvGeometry.scv(scvf.outsideScvIdx());
77 residual[insideScv.localDofIndex()] += flux;
78 residual[outsideScv.localDofIndex()] -= flux;
79 }
80 else
81 {
82 const auto& insideScv = fvGeometry.scv(scvf.insideScvIdx());
83 residual[insideScv.localDofIndex()] += flux;
84 }
85 }
86
88 NumEqVector evalFlux(const Problem& problem,
89 const Element& element,
90 const FVElementGeometry& fvGeometry,
91 const ElementVolumeVariables& elemVolVars,
92 const ElementBoundaryTypes& elemBcTypes,
93 const ElementFluxVariablesCache& elemFluxVarsCache,
94 const SubControlVolumeFace& scvf) const
95 {
96 NumEqVector flux(0.0);
97
98 // inner faces
99 if (!scvf.boundary())
100 {
101 flux += this->asImp().computeFlux(problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache);
102 }
103
104 // boundary faces
105 else
106 {
107 const auto& scv = fvGeometry.scv(scvf.insideScvIdx());
108 const auto& bcTypes = elemBcTypes[scv.localDofIndex()];
109
110 // Treat Neumann and Robin ("solution dependent Neumann") boundary conditions.
111 // For Dirichlet there is no addition to the residual here but they
112 // are enforced strongly by replacing the residual entry afterwards.
113 if (bcTypes.hasNeumann())
114 {
115 auto neumannFluxes = problem.neumann(element, fvGeometry, elemVolVars, elemFluxVarsCache, scvf);
116
117 // multiply neumann fluxes with the area and the extrusion factor
118 neumannFluxes *= scvf.area()*elemVolVars[scv].extrusionFactor();
119
120 // only add fluxes to equations for which Neumann is set
121 for (int eqIdx = 0; eqIdx < NumEqVector::dimension; ++eqIdx)
122 if (bcTypes.isNeumann(eqIdx))
123 flux[eqIdx] += neumannFluxes[eqIdx];
124 }
125 }
126
127 return flux;
128 }
129};
130
131} // end namespace Dumux
132
133#endif
The element-wise residual for finite volume schemes.
Helpers for deprecation.
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
The element-wise residual for the box scheme.
Definition: boxlocalresidual.hh:45
typename ParentType::ElementResidualVector ElementResidualVector
Definition: boxlocalresidual.hh:59
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: boxlocalresidual.hh:88
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: boxlocalresidual.hh:63
The element-wise residual for finite volume schemes.
Definition: fvlocalresidual.hh:45
Implementation & asImp()
Definition: fvlocalresidual.hh:501
const Problem & problem() const
the problem
Definition: fvlocalresidual.hh:486
ReservedBlockVector< NumEqVector, FVElementGeometry::maxNumElementScvs > ElementResidualVector
the container storing all element residuals
Definition: fvlocalresidual.hh:66
Declares all properties used in Dumux.