GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/freeflow/rans/volumevariables.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 37 63 58.7%
Functions: 36 536 6.7%
Branches: 93 238 39.1%

Line Branch Exec Source
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 //
7 /*!
8 * \file
9 * \ingroup RANSModel
10 *
11 * \copydoc Dumux::RANSVolumeVariables
12 */
13 #ifndef DUMUX_RANS_VOLUME_VARIABLES_HH
14 #define DUMUX_RANS_VOLUME_VARIABLES_HH
15
16 #include <dune/common/fvector.hh>
17 #include <dune/common/fmatrix.hh>
18
19 #include <dumux/common/parameters.hh>
20
21 namespace Dumux {
22
23 /*!
24 * \ingroup RANSModel
25 * \brief Volume variables for the isothermal single-phase Reynolds-Averaged Navier-Stokes models.
26 */
27 template <class Traits, class NSVolumeVariables>
28 class RANSVolumeVariables
29 : public NSVolumeVariables
30 {
31 using NavierStokesParentType = NSVolumeVariables;
32
33 using Scalar = typename Traits::PrimaryVariables::value_type;
34
35 enum { dimWorld = Traits::ModelTraits::dim() };
36 using DimVector = Dune::FieldVector<Scalar, dimWorld>;
37 using DimMatrix = Dune::FieldMatrix<Scalar, dimWorld, dimWorld>;
38
39 static constexpr bool enableEnergyBalance = Traits::ModelTraits::enableEnergyBalance();
40
41 public:
42
43 /*!
44 * \brief Update all quantities for a given control volume
45 *
46 * \param elemSol A vector containing all primary variables connected to the element
47 * \param problem The object specifying the problem which ought to
48 * be simulated
49 * \param element An element which contains part of the control volume
50 * \param scv The sub-control volume
51 */
52 template<class ElementSolution, class Problem, class Element, class SubControlVolume>
53 void updateNavierStokesVolVars(const ElementSolution &elemSol,
54 const Problem &problem,
55 const Element &element,
56 const SubControlVolume& scv)
57 {
58 97470064 NavierStokesParentType::update(elemSol, problem, element, scv);
59 }
60
61 /*!
62 * \brief Update all turbulent quantities for a given control volume
63 *
64 * Wall related quantities are stored and the calculateEddyViscosity(...)
65 * function of the turbulence model implementation is called.
66 *
67 * \param elemSol A vector containing all primary variables connected to the element
68 * \param problem The object specifying the problem which ought to be simulated
69 * \param element An element which contains part of the control volume
70 * \param scv The sub-control volume
71 */
72 template<class ElementSolution, class Problem, class Element, class SubControlVolume>
73 97470064 void updateRANSProperties(const ElementSolution &elemSol,
74 const Problem &problem,
75 const Element &element,
76 const SubControlVolume& scv)
77 {
78 using std::abs;
79 using std::max;
80 using std::sqrt;
81
82 // calculate characteristic properties of the turbulent flow
83 292410192 elementIdx_ = problem.gridGeometry().elementMapper().index(element);
84 97470064 wallDistance_ = problem.wallDistance(elementIdx_);
85 97470064 ccVelocityVector_ = problem.ccVelocityVector(elementIdx_);
86 97470064 velocityGradientTensor_ = problem.velocityGradientTensor(elementIdx_);
87
88 97470064 karmanConstant_ = problem.karmanConstant();
89 97470064 velocityMaximum_ = problem.velocityMaximum(elementIdx_);
90 97470064 velocityMinimum_ = problem.velocityMinimum(elementIdx_);
91
2/2
✓ Branch 1 taken 84530416 times.
✓ Branch 2 taken 12939648 times.
97470064 if (problem.isFlatWallBounded())
92 {
93 84530416 const auto flowDirectionAxis = problem.flowDirectionAxis(elementIdx_);
94 84530416 const auto wallNormalAxis = problem.wallNormalAxis(elementIdx_);
95 84530416 velocityMaximum_ = problem.velocityMaximum(problem.wallElementIndex(elementIdx_));
96 84530416 velocityMinimum_ = problem.velocityMinimum(problem.wallElementIndex(elementIdx_));
97 169060832 uStar_ = sqrt(problem.kinematicViscosity(problem.wallElementIndex(elementIdx_))
98
4/4
✓ Branch 3 taken 136136 times.
✓ Branch 4 taken 84394280 times.
✓ Branch 5 taken 136136 times.
✓ Branch 6 taken 84394280 times.
84530416 * abs(problem.velocityGradient(problem.wallElementIndex(elementIdx_), flowDirectionAxis, wallNormalAxis)));
99
2/2
✓ Branch 0 taken 136136 times.
✓ Branch 1 taken 84394280 times.
84530416 uStar_ = max(uStar_, 1e-10); // zero values lead to numerical problems in some turbulence models
100 84530416 yPlus_ = wallDistance_ * uStar_ / problem.kinematicViscosity(elementIdx_);
101 169060832 uPlus_ = problem.ccVelocity(elementIdx_, flowDirectionAxis) / uStar_;
102 }
103 97470064 }
104
105 /*!
106 * \brief Return the element Idx of the control volume.
107 */
108 unsigned int elementIdx() const
109 29757004 { return elementIdx_; }
110
111 /*!
112 * \brief Return the velocity vector \f$\mathrm{[m/s]}\f$ at the control volume center.
113 */
114 DimVector ccVelocityVector() const
115 { return ccVelocityVector_; }
116
117 /*!
118 * \brief Return the maximum velocity vector \f$\mathrm{[m/s]}\f$ of the wall segment.
119 */
120 DimVector velocityMaximum() const
121 { return velocityMaximum_; }
122
123 /*!
124 * \brief Return the minimum velocity vector \f$\mathrm{[m/s]}\f$ of the wall segment.
125 */
126 DimVector velocityMinimum() const
127 { return velocityMinimum_; }
128
129 /*!
130 * \brief Return the velocity gradients \f$\mathrm{[1/s]}\f$ at the control volume center.
131 */
132 DimMatrix velocityGradients() const
133 5689820 { return velocityGradientTensor_; }
134
135 /*!
136 * \brief Return the wall distance \f$\mathrm{[m]}\f$ of the control volume.
137 */
138 Scalar wallDistance() const
139 { return wallDistance_; }
140
141 /*!
142 * \brief Return the Karman constant
143 */
144 Scalar karmanConstant() const
145 { return karmanConstant_; }
146
147 /*!
148 * \brief Return the wall friction velocity \f$\mathrm{[m/s]}\f$
149 */
150 Scalar uStar() const
151 { return uStar_; }
152
153 /*!
154 * \brief Return the dimensionless wall distance \f$\mathrm{[-]}\f$.
155 */
156 Scalar yPlus() const
157 { return yPlus_; }
158
159 /*!
160 * \brief Return the dimensionless velocity \f$\mathrm{[-]}\f$.
161 */
162 Scalar uPlus() const
163 { return uPlus_; }
164
165 /*!
166 * \brief Return the dynamic eddy viscosity \f$\mathrm{[Pa s]}\f$ of the flow within the
167 * control volume.
168 */
169 Scalar dynamicEddyViscosity() const
170 { return dynamicEddyViscosity_; }
171
172 /*!
173 * \brief Return the effective dynamic viscosity \f$\mathrm{[Pa s]}\f$ of the fluid within the
174 * control volume.
175 */
176 Scalar effectiveViscosity() const
177 1171293206 { return NavierStokesParentType::viscosity() + dynamicEddyViscosity(); }
178
179 /*!
180 * \brief Return the kinematic eddy viscosity \f$\mathrm{[m^2/s]}\f$ of the flow within the
181 * control volume.
182 */
183 Scalar kinematicEddyViscosity() const
184
16/16
✓ Branch 0 taken 1173870 times.
✓ Branch 1 taken 19016484 times.
✓ Branch 2 taken 1173870 times.
✓ Branch 3 taken 19016484 times.
✓ Branch 4 taken 1173870 times.
✓ Branch 5 taken 19016484 times.
✓ Branch 6 taken 1173870 times.
✓ Branch 7 taken 19016484 times.
✓ Branch 8 taken 1173870 times.
✓ Branch 9 taken 19016484 times.
✓ Branch 10 taken 1173870 times.
✓ Branch 11 taken 19016484 times.
✓ Branch 12 taken 1173870 times.
✓ Branch 13 taken 19016484 times.
✓ Branch 14 taken 1173870 times.
✓ Branch 15 taken 19016484 times.
363396060 { return dynamicEddyViscosity() / NavierStokesParentType::density(); }
185
186 /*!
187 * \brief Return the kinematic viscosity \f$\mathrm{[m^2/s]}\f$ of the fluid within the
188 * control volume.
189 */
190 Scalar kinematicViscosity() const
191
66/204
✓ Branch 0 taken 150822 times.
✓ Branch 1 taken 27660626 times.
✓ Branch 2 taken 150822 times.
✓ Branch 3 taken 27660626 times.
✓ Branch 4 taken 150822 times.
✓ Branch 5 taken 27660626 times.
✓ Branch 6 taken 150822 times.
✓ Branch 7 taken 27660626 times.
✓ Branch 8 taken 150822 times.
✓ Branch 9 taken 27660626 times.
✓ Branch 10 taken 150822 times.
✓ Branch 11 taken 27660626 times.
✓ Branch 12 taken 150822 times.
✓ Branch 13 taken 27660626 times.
✓ Branch 14 taken 150822 times.
✓ Branch 15 taken 27660626 times.
✓ Branch 16 taken 150822 times.
✓ Branch 17 taken 27660626 times.
✓ Branch 18 taken 150822 times.
✓ Branch 19 taken 27660626 times.
✓ Branch 20 taken 150822 times.
✓ Branch 21 taken 27660626 times.
✓ Branch 22 taken 150822 times.
✓ Branch 23 taken 27660626 times.
✓ Branch 24 taken 150822 times.
✓ Branch 25 taken 27660626 times.
✓ Branch 26 taken 150822 times.
✓ Branch 27 taken 27660626 times.
✓ Branch 28 taken 150822 times.
✓ Branch 29 taken 27660626 times.
✓ Branch 30 taken 150822 times.
✓ Branch 31 taken 27660626 times.
✓ Branch 32 taken 150822 times.
✓ Branch 33 taken 27660626 times.
✓ Branch 34 taken 150822 times.
✓ Branch 35 taken 27660626 times.
✓ Branch 36 taken 150822 times.
✓ Branch 37 taken 27660626 times.
✓ Branch 38 taken 150822 times.
✓ Branch 39 taken 27660626 times.
✓ Branch 40 taken 150822 times.
✓ Branch 41 taken 27660626 times.
✓ Branch 42 taken 150822 times.
✓ Branch 43 taken 27660626 times.
✓ Branch 44 taken 150822 times.
✓ Branch 45 taken 27660626 times.
✓ Branch 46 taken 150822 times.
✓ Branch 47 taken 27660626 times.
✓ Branch 48 taken 33032 times.
✗ Branch 49 not taken.
✓ Branch 50 taken 33032 times.
✗ Branch 51 not taken.
✓ Branch 52 taken 33032 times.
✗ Branch 53 not taken.
✓ Branch 54 taken 33032 times.
✗ Branch 55 not taken.
✓ Branch 56 taken 33032 times.
✗ Branch 57 not taken.
✓ Branch 58 taken 33032 times.
✗ Branch 59 not taken.
✓ Branch 60 taken 33032 times.
✗ Branch 61 not taken.
✓ Branch 62 taken 33032 times.
✗ Branch 63 not taken.
✓ Branch 64 taken 33032 times.
✗ Branch 65 not taken.
✓ Branch 66 taken 33032 times.
✗ Branch 67 not taken.
✓ Branch 68 taken 33032 times.
✗ Branch 69 not taken.
✓ Branch 70 taken 33032 times.
✗ Branch 71 not taken.
✓ Branch 72 taken 33032 times.
✗ Branch 73 not taken.
✓ Branch 74 taken 33032 times.
✗ Branch 75 not taken.
✓ Branch 76 taken 33032 times.
✗ Branch 77 not taken.
✓ Branch 78 taken 33032 times.
✗ Branch 79 not taken.
✓ Branch 80 taken 33032 times.
✗ Branch 81 not taken.
✓ Branch 82 taken 33032 times.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✗ Branch 90 not taken.
✗ Branch 91 not taken.
✗ Branch 92 not taken.
✗ Branch 93 not taken.
✗ Branch 94 not taken.
✗ Branch 95 not taken.
✗ Branch 96 not taken.
✗ Branch 97 not taken.
✗ Branch 98 not taken.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✗ Branch 101 not taken.
✗ Branch 102 not taken.
✗ Branch 103 not taken.
✗ Branch 104 not taken.
✗ Branch 105 not taken.
✗ Branch 106 not taken.
✗ Branch 107 not taken.
✗ Branch 108 not taken.
✗ Branch 109 not taken.
✗ Branch 110 not taken.
✗ Branch 111 not taken.
✗ Branch 112 not taken.
✗ Branch 113 not taken.
✗ Branch 114 not taken.
✗ Branch 115 not taken.
✗ Branch 116 not taken.
✗ Branch 117 not taken.
✗ Branch 118 not taken.
✗ Branch 119 not taken.
✗ Branch 120 not taken.
✗ Branch 121 not taken.
✗ Branch 122 not taken.
✗ Branch 123 not taken.
✗ Branch 124 not taken.
✗ Branch 125 not taken.
✗ Branch 126 not taken.
✗ Branch 127 not taken.
✗ Branch 128 not taken.
✗ Branch 129 not taken.
✗ Branch 130 not taken.
✗ Branch 131 not taken.
✗ Branch 132 not taken.
✗ Branch 133 not taken.
✗ Branch 134 not taken.
✗ Branch 135 not taken.
✗ Branch 136 not taken.
✗ Branch 137 not taken.
✗ Branch 138 not taken.
✗ Branch 139 not taken.
✗ Branch 140 not taken.
✗ Branch 141 not taken.
✗ Branch 142 not taken.
✗ Branch 143 not taken.
✗ Branch 144 not taken.
✗ Branch 145 not taken.
✗ Branch 146 not taken.
✗ Branch 147 not taken.
✗ Branch 148 not taken.
✗ Branch 149 not taken.
✗ Branch 150 not taken.
✗ Branch 151 not taken.
✗ Branch 152 not taken.
✗ Branch 153 not taken.
✗ Branch 154 not taken.
✗ Branch 155 not taken.
✗ Branch 156 not taken.
✗ Branch 157 not taken.
✗ Branch 158 not taken.
✗ Branch 159 not taken.
✗ Branch 160 not taken.
✗ Branch 161 not taken.
✗ Branch 162 not taken.
✗ Branch 163 not taken.
✗ Branch 164 not taken.
✗ Branch 165 not taken.
✗ Branch 166 not taken.
✗ Branch 167 not taken.
✗ Branch 168 not taken.
✗ Branch 169 not taken.
✗ Branch 170 not taken.
✗ Branch 171 not taken.
✗ Branch 172 not taken.
✗ Branch 173 not taken.
✗ Branch 174 not taken.
✗ Branch 175 not taken.
✗ Branch 176 not taken.
✗ Branch 177 not taken.
✗ Branch 178 not taken.
✗ Branch 179 not taken.
✗ Branch 180 not taken.
✗ Branch 181 not taken.
✗ Branch 182 not taken.
✗ Branch 183 not taken.
✗ Branch 184 not taken.
✗ Branch 185 not taken.
✗ Branch 186 not taken.
✗ Branch 187 not taken.
✗ Branch 188 not taken.
✗ Branch 189 not taken.
✗ Branch 190 not taken.
✗ Branch 191 not taken.
✗ Branch 192 not taken.
✗ Branch 193 not taken.
✗ Branch 194 not taken.
✗ Branch 195 not taken.
✗ Branch 196 not taken.
✗ Branch 197 not taken.
✗ Branch 198 not taken.
✗ Branch 199 not taken.
✗ Branch 200 not taken.
✗ Branch 201 not taken.
✗ Branch 202 not taken.
✗ Branch 203 not taken.
887725380 { return NavierStokesParentType::viscosity() / NavierStokesParentType::density(); }
192
193 /*!
194 * \brief Calculates the eddy diffusivity \f$\mathrm{[m^2/s]}\f$ based
195 * on the kinematic eddy viscosity and the turbulent Schmidt number
196 */
197 template<class Problem>
198 void calculateEddyDiffusivity(const Problem& problem)
199 {
200 97470064 eddyDiffusivity_ = kinematicEddyViscosity()
201 194940128 / problem.turbulentSchmidtNumber();
202 }
203
204 /*!
205 * \brief Calculates the eddy thermal conductivity \f$\mathrm{[W/(m*K)]}\f$ based
206 * on the kinematic eddy viscosity and the turbulent Prandtl number
207 */
208 template<class Problem, bool eB = enableEnergyBalance, typename std::enable_if_t<eB, int> = 0>
209 42086082 void calculateEddyThermalConductivity(const Problem& problem)
210 {
211 42086082 eddyThermalConductivity_ = kinematicEddyViscosity()
212 84172164 * NavierStokesParentType::density()
213 42086082 * NavierStokesParentType::heatCapacity()
214 42086082 / problem.turbulentPrandtlNumber();
215 42086082 }
216
217 //! \brief Eddy thermal conductivity is zero for isothermal model
218 template<class Problem, bool eB = enableEnergyBalance, typename std::enable_if_t<!eB, int> = 0>
219 void calculateEddyThermalConductivity(const Problem& problem)
220 55383982 { eddyThermalConductivity_ = 0.0; }
221
222 /*!
223 * \brief Returns the eddy diffusivity \f$\mathrm{[m^2/s]}\f$
224 */
225 Scalar eddyDiffusivity() const
226 { return eddyDiffusivity_; }
227
228 /*!
229 * \brief Returns the eddy thermal conductivity \f$\mathrm{[W/(m*K)]}\f$
230 */
231 Scalar eddyThermalConductivity() const
232 { return eddyThermalConductivity_; }
233
234 /*!
235 * \brief Returns the binary diffusion coefficients for a phase in \f$[m^2/s]\f$.
236 */
237 Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
238
2/2
✓ Branch 1 taken 2386940 times.
✓ Branch 2 taken 67927800 times.
70394840 { return NavierStokesParentType::diffusionCoefficient(0, compIIdx, compJIdx) + eddyDiffusivity(); }
239
240 /*!
241 * \brief Returns the effective thermal conductivity \f$\mathrm{[W/(m*K)]}\f$
242 * of the fluid-flow in the sub-control volume.
243 */
244 template<bool eB = enableEnergyBalance, typename std::enable_if_t<eB, int> = 0>
245 Scalar effectiveThermalConductivity() const
246 {
247 228040000 return NavierStokesParentType::thermalConductivity() + eddyThermalConductivity();
248 }
249
250 protected:
251 /*!
252 * \brief Sets the dynamic eddy viscosity \f$\mathrm{[Pa s]}\f$
253 */
254 Scalar setDynamicEddyViscosity_(Scalar value)
255
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 5261548 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
103986269 { return dynamicEddyViscosity_ = value; }
256
257 DimVector ccVelocityVector_;
258 DimVector velocityMaximum_;
259 DimVector velocityMinimum_;
260 DimMatrix velocityGradientTensor_;
261 std::size_t elementIdx_;
262 Scalar wallDistance_;
263 Scalar karmanConstant_;
264 Scalar uStar_ = 0.0;
265 Scalar yPlus_ = 0.0;
266 Scalar uPlus_ = 0.0;
267 Scalar dynamicEddyViscosity_ = 0.0;
268 Scalar eddyDiffusivity_ = 0.0;
269 Scalar eddyThermalConductivity_ = 0.0;
270 };
271 } // end namespace Dumux
272
273 #endif
274