GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/freeflow/rans/twoeq/komega/problem.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 46 49 93.9%
Functions: 32 40 80.0%
Branches: 66 124 53.2%

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 KOmegaModel
10 * \brief K-Omega turbulence model problem base class.
11 */
12 #ifndef DUMUX_KOMEGA_PROBLEM_HH
13 #define DUMUX_KOMEGA_PROBLEM_HH
14
15 #include <dumux/common/properties.hh>
16 #include <dumux/common/staggeredfvproblem.hh>
17 #include <dumux/discretization/localview.hh>
18 #include <dumux/discretization/staggered/elementsolution.hh>
19 #include <dumux/discretization/method.hh>
20 #include <dumux/freeflow/rans/problem.hh>
21 #include <dumux/freeflow/turbulencemodel.hh>
22
23 #include "model.hh"
24
25 namespace Dumux {
26
27 /*!
28 * \ingroup KOmegaModel
29 * \brief K-Omega turbulence model problem base class.
30 *
31 * This implements the 2-equation k-omega turbulence model developed in Wilcox08 and Wilcox88
32 */
33 template<class TypeTag>
34 class RANSProblemImpl<TypeTag, TurbulenceModel::komega> : public RANSProblemBase<TypeTag>
35 {
36 using ParentType = RANSProblemBase<TypeTag>;
37 using Implementation = GetPropType<TypeTag, Properties::Problem>;
38 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
39
40 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
41 using FVElementGeometry = typename GetPropType<TypeTag, Properties::GridGeometry>::LocalView;
42
43 using VolumeVariables = GetPropType<TypeTag, Properties::VolumeVariables>;
44 using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
45 using CellCenterPrimaryVariables = GetPropType<TypeTag, Properties::CellCenterPrimaryVariables>;
46 using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices;
47
48 using Element = typename GridGeometry::GridView::template Codim<0>::Entity;
49 using DimVector = typename Element::Geometry::GlobalCoordinate;
50
51 public:
52 14 RANSProblemImpl(std::shared_ptr<const GridGeometry> gridGeometry, const std::string& paramGroup = "")
53
2/6
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
84 : ParentType(gridGeometry, paramGroup)
54 14 { }
55
56 /*!
57 * \brief Correct size of the static (solution independent) wall variables
58 */
59 14 void updateStaticWallProperties()
60 {
61 14 ParentType::updateStaticWallProperties();
62
63 // update size and initial values of the global vectors
64 56 storedDynamicEddyViscosity_.resize(this->gridGeometry().elementMapper().size(), 0.0);
65 56 storedDissipation_.resize(this->gridGeometry().elementMapper().size(), 0.0);
66 70 storedDissipationGradient_.resize(this->gridGeometry().elementMapper().size(), DimVector(0.0));
67 56 storedTurbulentKineticEnergy_.resize(this->gridGeometry().elementMapper().size(), 0.0);
68 70 storedTurbulentKineticEnergyGradient_.resize(this->gridGeometry().elementMapper().size(), DimVector(0.0));
69 14 }
70
71 /*!
72 * \brief Update the dynamic (solution dependent) relations to the walls
73 *
74 * \param curSol The solution vector.
75 */
76 template<class SolutionVector>
77 222 void updateDynamicWallProperties(const SolutionVector& curSol)
78 {
79 222 ParentType::updateDynamicWallProperties(curSol);
80
81
2/4
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
444 auto fvGeometry = localView(this->gridGeometry());
82
5/9
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 49374 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 104 times.
✗ Branch 10 not taken.
99386 for (const auto& element : elements(this->gridGeometry().gridView()))
83 {
84 148080 unsigned int elementIdx = this->gridGeometry().elementMapper().index(element);
85
1/2
✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
49360 fvGeometry.bindElement(element);
86
87
6/6
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 49160 times.
✓ Branch 3 taken 49160 times.
✓ Branch 4 taken 49160 times.
✓ Branch 5 taken 49160 times.
197040 for (auto&& scv : scvs(fvGeometry))
88 {
89 49360 const int dofIdx = scv.dofIndex();
90 98720 const auto& cellCenterPriVars = curSol[GridGeometry::cellCenterIdx()][dofIdx];
91 49360 PrimaryVariables priVars = makePriVarsFromCellCenterPriVars<PrimaryVariables>(cellCenterPriVars);
92
1/4
✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
98720 auto elemSol = elementSolution<typename GridGeometry::LocalView>(std::move(priVars));
93 // NOTE: first update the turbulence quantities
94 98720 storedDissipation_[elementIdx] = elemSol[0][Indices::dissipationEqIdx];
95 98720 storedTurbulentKineticEnergy_[elementIdx] = elemSol[0][Indices::turbulentKineticEnergyEqIdx];
96 // NOTE: then update the volVars
97 49360 VolumeVariables volVars;
98
1/2
✓ Branch 1 taken 49260 times.
✗ Branch 2 not taken.
49360 volVars.update(elemSol, asImp_(), element, scv);
99
3/6
✓ Branch 1 taken 49260 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 49260 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 49260 times.
✗ Branch 6 not taken.
49360 storedDynamicEddyViscosity_[elementIdx] = volVars.calculateEddyViscosity(*this);
100 }
101 }
102
103 // calculate cell-centered gradients
104
5/9
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 49374 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 104 times.
✗ Branch 10 not taken.
99394 for (const auto& element : elements(this->gridGeometry().gridView()))
105 {
106 98720 const unsigned int elementIdx = this->gridGeometry().elementMapper().index(element);
107
108
2/2
✓ Branch 1 taken 98520 times.
✓ Branch 2 taken 49260 times.
148080 for (unsigned int axisIdx = 0; axisIdx < DimVector::dimension; ++axisIdx)
109 {
110
1/2
✓ Branch 1 taken 200 times.
✗ Branch 2 not taken.
98720 const unsigned neighborIdx0 = ParentType::neighborIndex(elementIdx, axisIdx, 0);
111
1/2
✓ Branch 1 taken 200 times.
✗ Branch 2 not taken.
98720 const unsigned neighborIdx1 = ParentType::neighborIndex(elementIdx, axisIdx, 1);
112
113 // Cell centered TKE Gradient
114
1/2
✓ Branch 1 taken 200 times.
✗ Branch 2 not taken.
98720 storedTurbulentKineticEnergyGradient_[elementIdx][axisIdx]
115 296160 = (storedTurbulentKineticEnergy(neighborIdx1) - storedTurbulentKineticEnergy(neighborIdx0))
116
4/8
✓ Branch 1 taken 200 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 200 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 200 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 200 times.
✗ Branch 11 not taken.
197440 / (ParentType::cellCenter(neighborIdx1)[axisIdx] - ParentType::cellCenter(neighborIdx0)[axisIdx]);
117 // Cell centered Omega Gradient
118 98720 storedDissipationGradient_[elementIdx][axisIdx]
119 296160 = (storedDissipation(neighborIdx1) - storedDissipation(neighborIdx0))
120
2/4
✓ Branch 1 taken 200 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 200 times.
✗ Branch 5 not taken.
197440 / (ParentType::cellCenter(neighborIdx1)[axisIdx] - ParentType::cellCenter(neighborIdx0)[axisIdx]);
121 }
122 }
123 222 }
124
125 //! \brief Returns the \f$ \beta_{\omega} \f$ constant
126 const Scalar betaOmega() const
127 { return 0.0708; }
128
129 22318504 bool useStoredEddyViscosity() const
130 {
131
5/8
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 22317794 times.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 10 times.
✗ Branch 10 not taken.
22318504 static const bool useStoredEddyViscosity = getParamFromGroup<bool>(this->paramGroup(), "RANS.UseStoredEddyViscosity", false);
132 22318504 return useStoredEddyViscosity;
133 }
134
135 Scalar storedDynamicEddyViscosity(const int elementIdx) const
136 { return storedDynamicEddyViscosity_[elementIdx]; }
137
138 Scalar storedTurbulentKineticEnergy(const int elementIdx) const
139
12/24
✓ Branch 9 taken 50 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 50 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 50 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 50 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 50 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 50 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 50 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 50 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 50 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 50 times.
✗ Branch 37 not taken.
✓ Branch 39 taken 50 times.
✗ Branch 40 not taken.
✓ Branch 42 taken 50 times.
✗ Branch 43 not taken.
44931168 { return storedTurbulentKineticEnergy_[elementIdx]; }
140
141 Scalar storedDissipation(const int elementIdx) const
142
12/24
✓ Branch 9 taken 50 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 50 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 50 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 50 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 50 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 50 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 50 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 50 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 50 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 50 times.
✗ Branch 37 not taken.
✓ Branch 39 taken 50 times.
✗ Branch 40 not taken.
✓ Branch 42 taken 50 times.
✗ Branch 43 not taken.
44931168 { return storedDissipation_[elementIdx]; }
143
144 DimVector storedTurbulentKineticEnergyGradient(const int elementIdx) const
145 44635608 { return storedTurbulentKineticEnergyGradient_[elementIdx]; }
146
147 DimVector storedDissipationGradient(const int elementIdx) const
148 44635608 { return storedDissipationGradient_[elementIdx]; }
149
150 private:
151 std::vector<Scalar> storedDynamicEddyViscosity_;
152 std::vector<Scalar> storedTurbulentKineticEnergy_;
153 std::vector<Scalar> storedDissipation_;
154 std::vector<DimVector> storedDissipationGradient_;
155 std::vector<DimVector> storedTurbulentKineticEnergyGradient_;
156
157 //! Returns the implementation of the problem (i.e. static polymorphism)
158 Implementation &asImp_()
159 { return *static_cast<Implementation *>(this); }
160
161 //! \copydoc asImp_()
162 const Implementation &asImp_() const
163 { return *static_cast<const Implementation *>(this); }
164 };
165
166 } // end namespace Dumux
167
168 #endif
169