GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/freeflow/rans/twoeq/sst/problem.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 47 50 94.0%
Functions: 16 20 80.0%
Branches: 27 62 43.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 SSTModel
10 * \brief SST turbulence model problem base class.
11 */
12 #ifndef DUMUX_SST_PROBLEM_HH
13 #define DUMUX_SST_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 SSTModel
29 * \brief SST turbulence model problem base class.
30 *
31 * This implements the 2-equation SST turbulence model developed in Menter1994
32 */
33 template<class TypeTag>
34 class RANSProblemImpl<TypeTag, TurbulenceModel::sst> : 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 4 RANSProblemImpl(std::shared_ptr<const GridGeometry> gridGeometry, const std::string& paramGroup = "")
53
7/24
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 4 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
24 : ParentType(gridGeometry, paramGroup)
54 {
55
3/10
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
4 sstModelVersion_ = sstModelFromString(getParamFromGroup<std::string>(paramGroup, "RANS.SSTModelVersion", "SST"));
56 4 }
57
58 /*!
59 * \brief Correct size of the static (solution independent) wall variables
60 */
61 4 void updateStaticWallProperties()
62 {
63 4 ParentType::updateStaticWallProperties();
64 // update size and initial values of the global vectors
65 16 storedDynamicEddyViscosity_.resize(this->gridGeometry().elementMapper().size(), 0.0);
66 16 storedDissipation_.resize(this->gridGeometry().elementMapper().size(), 0.0);
67 20 storedDissipationGradient_.resize(this->gridGeometry().elementMapper().size(), DimVector(0.0));
68 16 storedTurbulentKineticEnergy_.resize(this->gridGeometry().elementMapper().size(), 0.0);
69 20 storedTurbulentKineticEnergyGradient_.resize(this->gridGeometry().elementMapper().size(), DimVector(0.0));
70 4 }
71
72 /*!
73 * \brief Update the dynamic (solution dependent) relations to the walls
74 *
75 * \param curSol The solution vector.
76 */
77 template<class SolutionVector>
78 155 void updateDynamicWallProperties(const SolutionVector& curSol)
79 {
80 155 ParentType::updateDynamicWallProperties(curSol);
81
82
1/2
✓ Branch 3 taken 35019 times.
✗ Branch 4 not taken.
70193 for (const auto& element : elements(this->gridGeometry().gridView()))
83 {
84 104592 unsigned int elementIdx = this->gridGeometry().elementMapper().index(element);
85
86 69728 auto fvGeometry = localView(this->gridGeometry());
87 34864 fvGeometry.bindElement(element);
88
4/4
✓ Branch 2 taken 34864 times.
✓ Branch 3 taken 34864 times.
✓ Branch 4 taken 34864 times.
✓ Branch 5 taken 34864 times.
139456 for (auto&& scv : scvs(fvGeometry))
89 {
90 34864 const int dofIdx = scv.dofIndex();
91 69728 const auto& cellCenterPriVars = curSol[GridGeometry::cellCenterIdx()][dofIdx];
92 34864 PrimaryVariables priVars = makePriVarsFromCellCenterPriVars<PrimaryVariables>(cellCenterPriVars);
93
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
69728 auto elemSol = elementSolution<typename GridGeometry::LocalView>(std::move(priVars));
94 // NOTE: first update the turbulence quantities
95 69728 storedDissipation_[elementIdx] = elemSol[0][Indices::dissipationEqIdx];
96 69728 storedTurbulentKineticEnergy_[elementIdx] = elemSol[0][Indices::turbulentKineticEnergyEqIdx];
97 // NOTE: then update the volVars
98 34864 VolumeVariables volVars;
99
1/2
✓ Branch 1 taken 34864 times.
✗ Branch 2 not taken.
34864 volVars.update(elemSol, asImp_(), element, scv);
100
3/6
✓ Branch 1 taken 34864 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 34864 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 34864 times.
✗ Branch 6 not taken.
34864 storedDynamicEddyViscosity_[elementIdx] = volVars.calculateEddyViscosity(*this);
101 }
102 }
103
104 // calculate cell-centered gradients
105
1/2
✓ Branch 3 taken 35019 times.
✗ Branch 4 not taken.
70193 for (const auto& element : elements(this->gridGeometry().gridView()))
106 {
107 69728 const unsigned int elementIdx = this->gridGeometry().elementMapper().index(element);
108
109
2/2
✓ Branch 1 taken 69728 times.
✓ Branch 2 taken 34864 times.
104592 for (unsigned int axisIdx = 0; axisIdx < DimVector::dimension; ++axisIdx)
110 {
111 69728 const unsigned neighborIdx0 = ParentType::neighborIndex(elementIdx, axisIdx, 0);
112 69728 const unsigned neighborIdx1 = ParentType::neighborIndex(elementIdx, axisIdx, 1);
113
114 // Cell centered TKE Gradient
115 69728 storedTurbulentKineticEnergyGradient_[elementIdx][axisIdx]
116 209184 = (storedTurbulentKineticEnergy(neighborIdx1) - storedTurbulentKineticEnergy(neighborIdx0))
117 139456 / (ParentType::cellCenter(neighborIdx1)[axisIdx] - ParentType::cellCenter(neighborIdx0)[axisIdx]);
118 // Cell centered Omega Gradient
119 69728 storedDissipationGradient_[elementIdx][axisIdx]
120 209184 = (storedDissipation(neighborIdx1) - storedDissipation(neighborIdx0))
121 139456 / (ParentType::cellCenter(neighborIdx1)[axisIdx] - ParentType::cellCenter(neighborIdx0)[axisIdx]);
122 }
123 }
124 155 }
125
126 16416128 bool useStoredEddyViscosity() const
127 {
128
5/8
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 16416124 times.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 4 times.
✗ Branch 10 not taken.
16416128 static const bool useStoredEddyViscosity = getParamFromGroup<bool>(this->paramGroup(), "RANS.UseStoredEddyViscosity", false);
129 16416128 return useStoredEddyViscosity;
130 }
131
132 Scalar storedDynamicEddyViscosity(const int elementIdx) const
133 { return storedDynamicEddyViscosity_[elementIdx]; }
134
135 Scalar storedTurbulentKineticEnergy(const int elementIdx) const
136 33041440 { return storedTurbulentKineticEnergy_[elementIdx]; }
137
138 Scalar storedDissipation(const int elementIdx) const
139 33041440 { return storedDissipation_[elementIdx]; }
140
141 DimVector storedTurbulentKineticEnergyGradient(const int elementIdx) const
142 32832256 { return storedTurbulentKineticEnergyGradient_[elementIdx]; }
143
144 DimVector storedDissipationGradient(const int elementIdx) const
145 32832256 { return storedDissipationGradient_[elementIdx]; }
146
147 SSTModel sstModelVersion() const
148 { return sstModelVersion_; }
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 SSTModel sstModelVersion_;
158
159 //! Returns the implementation of the problem (i.e. static polymorphism)
160 Implementation &asImp_()
161 { return *static_cast<Implementation *>(this); }
162
163 //! \copydoc asImp_()
164 const Implementation &asImp_() const
165 { return *static_cast<const Implementation *>(this); }
166 };
167
168 } // end namespace Dumux
169
170 #endif
171