GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/freeflow/rans/volumevariables.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 37 63 58.7%
Functions: 66 536 12.3%
Branches: 156 238 65.5%

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 98292464 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 98295864 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 294887592 elementIdx_ = problem.gridGeometry().elementMapper().index(element);
84 98295864 wallDistance_ = problem.wallDistance(elementIdx_);
85 98295864 ccVelocityVector_ = problem.ccVelocityVector(elementIdx_);
86 98295864 velocityGradientTensor_ = problem.velocityGradientTensor(elementIdx_);
87
88 98295864 karmanConstant_ = problem.karmanConstant();
89 98295864 velocityMaximum_ = problem.velocityMaximum(elementIdx_);
90 98295864 velocityMinimum_ = problem.velocityMinimum(elementIdx_);
91
2/2
✓ Branch 1 taken 85352816 times.
✓ Branch 2 taken 12939648 times.
98295864 if (problem.isFlatWallBounded())
92 {
93 85356216 const auto flowDirectionAxis = problem.flowDirectionAxis(elementIdx_);
94 85356216 const auto wallNormalAxis = problem.wallNormalAxis(elementIdx_);
95 85356216 velocityMaximum_ = problem.velocityMaximum(problem.wallElementIndex(elementIdx_));
96 85356216 velocityMinimum_ = problem.velocityMinimum(problem.wallElementIndex(elementIdx_));
97 170712432 uStar_ = sqrt(problem.kinematicViscosity(problem.wallElementIndex(elementIdx_))
98
4/4
✓ Branch 3 taken 136136 times.
✓ Branch 4 taken 85216680 times.
✓ Branch 5 taken 136136 times.
✓ Branch 6 taken 85216680 times.
85356216 * abs(problem.velocityGradient(problem.wallElementIndex(elementIdx_), flowDirectionAxis, wallNormalAxis)));
99
2/2
✓ Branch 0 taken 136136 times.
✓ Branch 1 taken 85216680 times.
85356216 uStar_ = max(uStar_, 1e-10); // zero values lead to numerical problems in some turbulence models
100 85356216 yPlus_ = wallDistance_ * uStar_ / problem.kinematicViscosity(elementIdx_);
101 170712432 uPlus_ = problem.ccVelocity(elementIdx_, flowDirectionAxis) / uStar_;
102 }
103 98295864 }
104
105 /*!
106 * \brief Return the element Idx of the control volume.
107 */
108 unsigned int elementIdx() const
109 29757704 { 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 5694020 { 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 1179629056 { 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.
366686860 { 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
126/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 33057 times.
✗ Branch 61 not taken.
✓ Branch 62 taken 33057 times.
✗ Branch 63 not taken.
✓ Branch 64 taken 33057 times.
✗ Branch 65 not taken.
✓ Branch 66 taken 33057 times.
✗ Branch 67 not taken.
✓ Branch 68 taken 33057 times.
✗ Branch 69 not taken.
✓ Branch 70 taken 33057 times.
✗ Branch 71 not taken.
✓ Branch 72 taken 33057 times.
✗ Branch 73 not taken.
✓ Branch 74 taken 33057 times.
✗ Branch 75 not taken.
✓ Branch 76 taken 33057 times.
✗ Branch 77 not taken.
✓ Branch 78 taken 33057 times.
✗ Branch 79 not taken.
✓ Branch 80 taken 33057 times.
✗ Branch 81 not taken.
✓ Branch 82 taken 33057 times.
✗ Branch 83 not taken.
✓ Branch 84 taken 25 times.
✗ Branch 85 not taken.
✓ Branch 86 taken 25 times.
✗ Branch 87 not taken.
✓ Branch 88 taken 25 times.
✗ Branch 89 not taken.
✓ Branch 90 taken 25 times.
✗ Branch 91 not taken.
✓ Branch 92 taken 25 times.
✗ Branch 93 not taken.
✓ Branch 94 taken 25 times.
✗ Branch 95 not taken.
✓ Branch 96 taken 25 times.
✗ Branch 97 not taken.
✓ Branch 98 taken 25 times.
✗ Branch 99 not taken.
✓ Branch 100 taken 25 times.
✗ Branch 101 not taken.
✓ Branch 102 taken 25 times.
✗ Branch 103 not taken.
✓ Branch 104 taken 25 times.
✗ Branch 105 not taken.
✓ Branch 106 taken 25 times.
✗ Branch 107 not taken.
✓ Branch 108 taken 25 times.
✗ Branch 109 not taken.
✓ Branch 110 taken 25 times.
✗ Branch 111 not taken.
✓ Branch 112 taken 25 times.
✗ Branch 113 not taken.
✓ Branch 114 taken 25 times.
✗ Branch 115 not taken.
✓ Branch 116 taken 25 times.
✗ Branch 117 not taken.
✓ Branch 118 taken 25 times.
✗ Branch 119 not taken.
✓ Branch 120 taken 25 times.
✗ Branch 121 not taken.
✓ Branch 122 taken 25 times.
✗ Branch 123 not taken.
✓ Branch 124 taken 25 times.
✗ Branch 125 not taken.
✓ Branch 126 taken 25 times.
✗ Branch 127 not taken.
✓ Branch 128 taken 25 times.
✗ Branch 129 not taken.
✓ Branch 130 taken 25 times.
✗ Branch 131 not taken.
✓ Branch 132 taken 25 times.
✗ Branch 133 not taken.
✓ Branch 134 taken 25 times.
✗ Branch 135 not taken.
✓ Branch 136 taken 25 times.
✗ Branch 137 not taken.
✓ Branch 138 taken 25 times.
✗ Branch 139 not taken.
✓ Branch 140 taken 25 times.
✗ Branch 141 not taken.
✓ Branch 142 taken 25 times.
✗ Branch 143 not taken.
✓ Branch 144 taken 25 times.
✗ Branch 145 not taken.
✓ Branch 146 taken 25 times.
✗ Branch 147 not taken.
✓ Branch 148 taken 25 times.
✗ Branch 149 not taken.
✓ Branch 150 taken 25 times.
✗ Branch 151 not taken.
✓ Branch 152 taken 25 times.
✗ Branch 153 not taken.
✓ Branch 154 taken 25 times.
✗ Branch 155 not taken.
✓ Branch 156 taken 25 times.
✗ Branch 157 not taken.
✓ Branch 158 taken 25 times.
✗ Branch 159 not taken.
✓ Branch 160 taken 25 times.
✗ Branch 161 not taken.
✓ Branch 162 taken 25 times.
✗ Branch 163 not taken.
✓ Branch 164 taken 25 times.
✗ Branch 165 not taken.
✓ Branch 166 taken 25 times.
✗ Branch 167 not taken.
✓ Branch 168 taken 25 times.
✗ Branch 169 not taken.
✓ Branch 170 taken 25 times.
✗ Branch 171 not taken.
✓ Branch 172 taken 25 times.
✗ Branch 173 not taken.
✓ Branch 174 taken 25 times.
✗ Branch 175 not taken.
✓ Branch 176 taken 25 times.
✗ Branch 177 not taken.
✓ Branch 178 taken 25 times.
✗ Branch 179 not taken.
✓ Branch 180 taken 25 times.
✗ Branch 181 not taken.
✓ Branch 182 taken 25 times.
✗ Branch 183 not taken.
✓ Branch 184 taken 25 times.
✗ Branch 185 not taken.
✓ Branch 186 taken 25 times.
✗ Branch 187 not taken.
✓ Branch 188 taken 25 times.
✗ Branch 189 not taken.
✓ Branch 190 taken 25 times.
✗ Branch 191 not taken.
✓ Branch 192 taken 25 times.
✗ Branch 193 not taken.
✓ Branch 194 taken 25 times.
✗ Branch 195 not taken.
✓ Branch 196 taken 25 times.
✗ Branch 197 not taken.
✓ Branch 198 taken 25 times.
✗ Branch 199 not taken.
✓ Branch 200 taken 25 times.
✗ Branch 201 not taken.
✓ Branch 202 taken 25 times.
✗ Branch 203 not taken.
887741580 { 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 98292464 eddyDiffusivity_ = kinematicEddyViscosity()
201 196584928 / 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 42908482 void calculateEddyThermalConductivity(const Problem& problem)
210 {
211 42908482 eddyThermalConductivity_ = kinematicEddyViscosity()
212 85816964 * NavierStokesParentType::density()
213 42908482 * NavierStokesParentType::heatCapacity()
214 42908482 / problem.turbulentPrandtlNumber();
215 42908482 }
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 55384282 { 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 2458440 times.
✓ Branch 2 taken 70024800 times.
72565390 { 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 232306000 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
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 5261698 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 150 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 150 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 150 times.
104808789 { 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