3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
flux.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 *****************************************************************************/
24#ifndef DUMUX_NAVIERSTOKES_MOMENTUM_CVFE_FLUXVARIABLES_HH
25#define DUMUX_NAVIERSTOKES_MOMENTUM_CVFE_FLUXVARIABLES_HH
26
27#include <dune/common/fmatrix.hh>
28
29#include <dumux/common/math.hh>
32
34
35namespace Dumux {
36
46template<class Problem,
47 class FVElementGeometry,
48 class ElementVolumeVariables,
49 class ElementFluxVariablesCache>
51{
52 using Element = typename FVElementGeometry::Element;
53 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
54public:
55
58 const Problem& problem,
59 const FVElementGeometry& fvGeometry,
60 const ElementVolumeVariables& elemVolVars,
61 const ElementFluxVariablesCache& elemFluxVarsCache,
62 const SubControlVolumeFace& scvf
63 )
64 : problem_(problem)
65 , fvGeometry_(fvGeometry)
66 , elemVolVars_(elemVolVars)
67 , elemFluxVarsCache_(elemFluxVarsCache)
68 , scvf_(scvf)
69 {}
70
71 const Problem& problem() const
72 { return problem_; }
73
74 const Element& element() const
75 { return fvGeometry_.element(); }
76
77 const SubControlVolumeFace& scvFace() const
78 { return scvf_; }
79
80 const FVElementGeometry& fvGeometry() const
81 { return fvGeometry_; }
82
83 const ElementVolumeVariables& elemVolVars() const
84 { return elemVolVars_; }
85
86 const ElementFluxVariablesCache& elemFluxVarsCache() const
87 { return elemFluxVarsCache_; }
88
89private:
90 const Problem& problem_;
91 const FVElementGeometry& fvGeometry_;
92 const ElementVolumeVariables& elemVolVars_;
93 const ElementFluxVariablesCache& elemFluxVarsCache_;
94 const SubControlVolumeFace& scvf_;
95};
96
101template<class GridGeometry, class NumEqVector>
103{
104 using GridView = typename GridGeometry::GridView;
105 using Element = typename GridView::template Codim<0>::Entity;
106 using Scalar = typename NumEqVector::value_type;
107
108 using Extrusion = Extrusion_t<GridGeometry>;
109
110 static constexpr int dim = GridView::dimension;
111 static constexpr int dimWorld = GridView::dimensionworld;
112
113 using Tensor = Dune::FieldMatrix<Scalar, dim, dimWorld>;
114 static_assert(NumEqVector::dimension == dimWorld, "Wrong dimension of velocity vector");
115
116public:
120 template<class Context>
121 NumEqVector advectiveMomentumFlux(const Context& context) const
122 {
123 if (!context.problem().enableInertiaTerms())
124 return NumEqVector(0.0);
125
126 const auto& fvGeometry = context.fvGeometry();
127 const auto& elemVolVars = context.elemVolVars();
128 const auto& scvf = context.scvFace();
129 const auto& fluxVarCache = context.elemFluxVarsCache()[scvf];
130 const auto& shapeValues = fluxVarCache.shapeValues();
131
132 // interpolate velocity at scvf
133 NumEqVector v(0.0);
134 for (const auto& scv : scvs(fvGeometry))
135 v.axpy(shapeValues[scv.indexInElement()][0], elemVolVars[scv].velocity());
136
137 // get density from the problem
138 const Scalar density = context.problem().density(context.element(), context.fvGeometry(), scvf);
139
140 const auto vn = v*scvf.unitOuterNormal();
141 const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()];
142 const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()];
143 const auto upwindVelocity = vn > 0 ? insideVolVars.velocity() : outsideVolVars.velocity();
144 const auto downwindVelocity = vn > 0 ? outsideVolVars.velocity() : insideVolVars.velocity();
145 static const auto upwindWeight = getParamFromGroup<Scalar>(context.problem().paramGroup(), "Flux.UpwindWeight");
146 const auto advectiveTermIntegrand = density*vn * (upwindWeight * upwindVelocity + (1.0-upwindWeight)*downwindVelocity);
147
148 return advectiveTermIntegrand * Extrusion::area(fvGeometry, scvf) * insideVolVars.extrusionFactor();
149 }
150
154 template<class Context>
155 NumEqVector diffusiveMomentumFlux(const Context& context) const
156 {
157 const auto& element = context.element();
158 const auto& fvGeometry = context.fvGeometry();
159 const auto& elemVolVars = context.elemVolVars();
160 const auto& scvf = context.scvFace();
161 const auto& fluxVarCache = context.elemFluxVarsCache()[scvf];
162
163 // interpolate velocity gradient at scvf
164 Tensor gradV(0.0);
165 for (const auto& scv : scvs(fvGeometry))
166 {
167 const auto& volVars = elemVolVars[scv];
168 for (int dir = 0; dir < dim; ++dir)
169 gradV[dir].axpy(volVars.velocity(dir), fluxVarCache.gradN(scv.indexInElement()));
170 }
171
172 // get viscosity from the problem
173 const auto mu = context.problem().effectiveViscosity(element, fvGeometry, scvf);
174
175 static const bool enableUnsymmetrizedVelocityGradient
176 = getParamFromGroup<bool>(context.problem().paramGroup(), "FreeFlow.EnableUnsymmetrizedVelocityGradient", false);
177
178 // compute -mu*gradV*n*dA
179 NumEqVector diffusiveFlux = enableUnsymmetrizedVelocityGradient ?
180 mv(gradV, scvf.unitOuterNormal())
181 : mv(gradV + getTransposed(gradV),scvf.unitOuterNormal());
182
183 diffusiveFlux *= -mu;
184
185 static const bool enableDilatationTerm = getParamFromGroup<bool>(context.problem().paramGroup(), "FreeFlow.EnableDilatationTerm", false);
186 if (enableDilatationTerm)
187 diffusiveFlux += 2.0/3.0 * mu * trace(gradV) * scvf.unitOuterNormal();
188
189 diffusiveFlux *= Extrusion::area(fvGeometry, scvf) * elemVolVars[scvf.insideScvIdx()].extrusionFactor();
190 return diffusiveFlux;
191 }
192
193 template<class Context>
194 NumEqVector pressureContribution(const Context& context) const
195 {
196 const auto& element = context.element();
197 const auto& fvGeometry = context.fvGeometry();
198 const auto& elemVolVars = context.elemVolVars();
199 const auto& scvf = context.scvFace();
200
201 // The pressure force needs to take the extruded scvf area into account
202 const auto pressure = context.problem().pressure(element, fvGeometry, scvf);
203
204 // The pressure contribution calculated above might have a much larger numerical value compared to the viscous or inertial forces.
205 // This may lead to numerical inaccuracies due to loss of significance (cancellation) for the final residual value.
206 // In the end, we are only interested in a pressure gradient between the two relevant faces so we can
207 // subtract a constant reference value from the actual pressure contribution.
208 const auto referencePressure = context.problem().referencePressure();
209
210 NumEqVector pn(scvf.unitOuterNormal());
211 pn *= (pressure-referencePressure)*Extrusion::area(fvGeometry, scvf)*elemVolVars[scvf.insideScvIdx()].extrusionFactor();
212
213 return pn;
214 }
215};
216
217} // end namespace Dumux
218
219#endif
Some exceptions thrown in DuMux
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
Define some often used mathematical functions.
Helper classes to compute the integration elements.
Dune::DenseVector< V >::derived_type mv(const Dune::DenseMatrix< MAT > &M, const Dune::DenseVector< V > &v)
Returns the result of the projection of a vector v with a Matrix M.
Definition: math.hh:812
Dune::DenseMatrix< MatrixType >::field_type trace(const Dune::DenseMatrix< MatrixType > &M)
Trace of a dense matrix.
Definition: math.hh:783
Dune::FieldMatrix< Scalar, n, m > getTransposed(const Dune::FieldMatrix< Scalar, m, n > &M)
Transpose a FieldMatrix.
Definition: math.hh:695
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:46
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:251
std::string pressure(int phaseIdx) noexcept
I/O name of pressure for multiphase systems.
Definition: name.hh:34
std::string density(int phaseIdx) noexcept
I/O name of density for multiphase systems.
Definition: name.hh:65
Context for computing fluxes.
Definition: flux.hh:51
const Element & element() const
Definition: flux.hh:74
const FVElementGeometry & fvGeometry() const
Definition: flux.hh:80
NavierStokesMomentumFluxContext(const Problem &problem, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf)
Initialize the flux variables storing some temporary pointers.
Definition: flux.hh:57
const SubControlVolumeFace & scvFace() const
Definition: flux.hh:77
const ElementVolumeVariables & elemVolVars() const
Definition: flux.hh:83
const ElementFluxVariablesCache & elemFluxVarsCache() const
Definition: flux.hh:86
const Problem & problem() const
Definition: flux.hh:71
The flux variables class for the Navier-Stokes model using control-volume finite element schemes.
Definition: flux.hh:103
NumEqVector advectiveMomentumFlux(const Context &context) const
Returns the diffusive momentum flux due to viscous forces.
Definition: flux.hh:121
NumEqVector diffusiveMomentumFlux(const Context &context) const
Returns the diffusive momentum flux due to viscous forces.
Definition: flux.hh:155
NumEqVector pressureContribution(const Context &context) const
Definition: flux.hh:194