GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/freeflow/rans/oneeq/problem.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 49 50 98.0%
Functions: 16 32 50.0%
Branches: 33 135 24.4%

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 OneEqModel
10 * \brief One-equation turbulence problem base class.
11 */
12 #ifndef DUMUX_ONEEQ_PROBLEM_HH
13 #define DUMUX_ONEEQ_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 OneEqModel
29 * \brief One-equation turbulence problem base class.
30 *
31 * This implements some base functionality for one-equation Spalart-Allmaras model.
32 */
33 template<class TypeTag>
34 class RANSProblemImpl<TypeTag, TurbulenceModel::oneeq> : public RANSProblemBase<TypeTag>
35 {
36
37 using ParentType = RANSProblemBase<TypeTag>;
38 using Implementation = GetPropType<TypeTag, Properties::Problem>;
39 using GridView = typename GetPropType<TypeTag, Properties::GridGeometry>::GridView;
40 using Grid = typename GridView::Grid;
41
42 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
43 using DimVector = Dune::FieldVector<Scalar, Grid::dimension>;
44
45 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
46 using FVElementGeometry = typename GetPropType<TypeTag, Properties::GridGeometry>::LocalView;
47 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
48
49 using VolumeVariables = GetPropType<TypeTag, Properties::VolumeVariables>;
50 using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
51 using CellCenterPrimaryVariables = GetPropType<TypeTag, Properties::CellCenterPrimaryVariables>;
52 using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices;
53
54 public:
55 //! The constructor sets the gravity, if desired by the user.
56 4 RANSProblemImpl(std::shared_ptr<const GridGeometry> gridGeometry, const std::string& paramGroup = "")
57
2/6
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
16 : ParentType(gridGeometry, paramGroup)
58 4 { }
59
60 /*!
61 * \brief Correct size of the static (solution independent) wall variables
62 */
63 4 void updateStaticWallProperties()
64 {
65 4 ParentType::updateStaticWallProperties();
66
67 // update size and initial values of the global vectors
68 16 storedDynamicEddyViscosity_.resize(this->gridGeometry().elementMapper().size(), 0.0);
69 16 storedViscosityTilde_.resize(this->gridGeometry().elementMapper().size(), 0.0);
70 20 storedViscosityTildeGradient_.resize(this->gridGeometry().elementMapper().size(), DimVector(0.0));
71 4 }
72
73 /*!
74 * \brief Update the dynamic (solution dependent) relations to the walls
75 *
76 * \param curSol The solution vector.
77 */
78 template<class SolutionVector>
79 148 void updateDynamicWallProperties(const SolutionVector& curSol)
80 {
81 148 ParentType::updateDynamicWallProperties(curSol);
82
83
0/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
296 auto fvGeometry = localView(this->gridGeometry());
84
1/9
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 33180 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
66508 for (const auto& element : elements(this->gridGeometry().gridView()))
85 {
86 99096 unsigned int elementIdx = this->gridGeometry().elementMapper().index(element);
87
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
33032 fvGeometry.bindElement(element);
88
89
4/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 33032 times.
✓ Branch 3 taken 33032 times.
✓ Branch 4 taken 33032 times.
✓ Branch 5 taken 33032 times.
132128 for (auto&& scv : scvs(fvGeometry))
90 {
91 33032 const int dofIdx = scv.dofIndex();
92 66064 const auto& cellCenterPriVars = curSol[GridGeometry::cellCenterIdx()][dofIdx];
93 33032 PrimaryVariables priVars = makePriVarsFromCellCenterPriVars<PrimaryVariables>(cellCenterPriVars);
94
0/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
66064 auto elemSol = elementSolution<typename GridGeometry::LocalView>(std::move(priVars));
95 // NOTE: first update the turbulence quantities
96 66064 storedViscosityTilde_[elementIdx] = elemSol[0][Indices::viscosityTildeIdx];
97 // NOTE: then update the volVars
98 33032 VolumeVariables volVars;
99
1/2
✓ Branch 1 taken 33032 times.
✗ Branch 2 not taken.
33032 volVars.update(elemSol, asImp_(), element, scv);
100
3/6
✓ Branch 0 taken 33032 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33032 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 33032 times.
✗ Branch 5 not taken.
99096 storedDynamicEddyViscosity_[elementIdx] = volVars.calculateEddyViscosity();
101 }
102 }
103
104 // calculate cell-center-averaged gradient
105
1/9
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 33180 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
66508 for (const auto& element : elements(this->gridGeometry().gridView()))
106 {
107 99096 const unsigned int elementIdx = this->gridGeometry().elementMapper().index(element);
108
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
33032 fvGeometry.bindElement(element);
109
110
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 66064 times.
✓ Branch 2 taken 33032 times.
99096 for (unsigned int axisIdx = 0; axisIdx < Grid::dimension; ++axisIdx)
111 {
112
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
66064 const unsigned int neighborIndex0 = ParentType::neighborIndex(elementIdx, axisIdx, 0);
113
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
66064 const unsigned int neighborIndex1 = ParentType::neighborIndex(elementIdx, axisIdx, 1);
114
115 // calculate cell-centered turbulentEddyViscosity (viscosityTilde) gradient
116 66064 storedViscosityTildeGradient_[elementIdx][axisIdx]
117 198192 = (storedViscosityTilde(neighborIndex1) - storedViscosityTilde(neighborIndex0))
118
0/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
132128 / (ParentType::cellCenter(neighborIndex1)[axisIdx] - ParentType::cellCenter(neighborIndex0)[axisIdx]);
119 }
120
121 // Adjust for dirichlet boundary conditions
122
6/6
✓ Branch 0 taken 132128 times.
✓ Branch 1 taken 33032 times.
✓ Branch 2 taken 132128 times.
✓ Branch 3 taken 33032 times.
✓ Branch 4 taken 9516 times.
✓ Branch 5 taken 122612 times.
198192 for (auto&& scvf : scvfs(fvGeometry))
123 {
124 132128 const unsigned int normDim = scvf.directionIndex();
125
4/4
✓ Branch 0 taken 9516 times.
✓ Branch 1 taken 122612 times.
✓ Branch 3 taken 3734 times.
✓ Branch 4 taken 5782 times.
135862 if (scvf.boundary() && asImp_().boundaryTypes(element, scvf).isDirichlet(Indices::viscosityTildeIdx))
126 {
127 // face Value
128
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
5782 Scalar dirichletViscosityTilde = asImp_().dirichlet(element, scvf)[Indices::viscosityTildeIdx];
129
130
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
5782 unsigned int neighborIndex = ParentType::neighborIndex(elementIdx, normDim, 0);
131
4/12
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4758 times.
✓ Branch 4 taken 1024 times.
✓ Branch 5 taken 4758 times.
✓ Branch 6 taken 1024 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
17346 if (scvf.center()[normDim] < ParentType::cellCenter(elementIdx)[normDim])
132 9516 neighborIndex = ParentType::neighborIndex(elementIdx, normDim, 1);
133
134 5782 storedViscosityTildeGradient_[elementIdx][normDim]
135 11564 = (storedViscosityTilde(neighborIndex) - dirichletViscosityTilde)
136 28910 / (ParentType::cellCenter(neighborIndex)[normDim] - scvf.center()[normDim]);
137 }
138 }
139 }
140 148 }
141
142 10449652 bool useStoredEddyViscosity() const
143 {
144
5/8
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 10449648 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.
10449652 static const bool useStoredEddyViscosity = getParamFromGroup<bool>(this->paramGroup(), "RANS.UseStoredEddyViscosity", false);
145 10449652 return useStoredEddyViscosity;
146 }
147
148 Scalar storedDynamicEddyViscosity(const int elementIdx) const
149 { return storedDynamicEddyViscosity_[elementIdx]; }
150
151 Scalar storedViscosityTilde(const int elementIdx) const
152
0/40
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
21109060 { return storedViscosityTilde_[elementIdx]; }
153
154 DimVector storedViscosityTildeGradient(const int elementIdx) const
155 20899304 { return storedViscosityTildeGradient_[elementIdx]; }
156
157 private:
158 std::vector<Scalar> storedDynamicEddyViscosity_;
159 std::vector<Scalar> storedViscosityTilde_;
160 std::vector<DimVector> storedViscosityTildeGradient_;
161
162 //! Returns the implementation of the problem (i.e. static polymorphism)
163 Implementation &asImp_()
164 { return *static_cast<Implementation *>(this); }
165
166 //! \copydoc asImp_()
167 const Implementation &asImp_() const
168 { return *static_cast<const Implementation *>(this); }
169 };
170
171 } // end namespace Dumux
172
173 #endif
174