GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/freeflow/rans/oneeq/problem.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 51 53 96.2%
Functions: 32 32 100.0%
Branches: 48 76 63.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-FileCopyrightText: 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 12 RANSProblemImpl(std::shared_ptr<const GridGeometry> gridGeometry, const std::string& paramGroup = "")
57
1/2
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
24 : ParentType(gridGeometry, paramGroup)
58 12 { }
59
60 /*!
61 * \brief Correct size of the static (solution independent) wall variables
62 */
63 12 void updateStaticWallProperties()
64 {
65 12 ParentType::updateStaticWallProperties();
66
67 // update size and initial values of the global vectors
68 12 storedDynamicEddyViscosity_.resize(this->gridGeometry().elementMapper().size(), 0.0);
69 12 storedViscosityTilde_.resize(this->gridGeometry().elementMapper().size(), 0.0);
70 24 storedViscosityTildeGradient_.resize(this->gridGeometry().elementMapper().size(), DimVector(0.0));
71 12 }
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 156 void updateDynamicWallProperties(const SolutionVector& curSol)
80 {
81 156 ParentType::updateDynamicWallProperties(curSol);
82
83
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
156 auto fvGeometry = localView(this->gridGeometry());
84
3/5
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 33180 times.
✓ Branch 4 taken 104 times.
✗ Branch 5 not taken.
✗ Branch 3 not taken.
99852 for (const auto& element : elements(this->gridGeometry().gridView()))
85 {
86
1/2
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
33232 unsigned int elementIdx = this->gridGeometry().elementMapper().index(element);
87 33432 fvGeometry.bindElement(element);
88
89
2/2
✓ Branch 0 taken 33132 times.
✓ Branch 1 taken 33132 times.
66464 for (auto&& scv : scvs(fvGeometry))
90 {
91 33232 const int dofIdx = scv.dofIndex();
92 33232 const auto& cellCenterPriVars = curSol[GridGeometry::cellCenterIdx()][dofIdx];
93 33232 PrimaryVariables priVars = makePriVarsFromCellCenterPriVars<PrimaryVariables>(cellCenterPriVars);
94
1/2
✓ Branch 1 taken 33132 times.
✗ Branch 2 not taken.
33232 auto elemSol = elementSolution<typename GridGeometry::LocalView>(std::move(priVars));
95 // NOTE: first update the turbulence quantities
96 33232 storedViscosityTilde_[elementIdx] = elemSol[0][Indices::viscosityTildeIdx];
97 // NOTE: then update the volVars
98 33232 VolumeVariables volVars;
99
1/2
✓ Branch 1 taken 33132 times.
✗ Branch 2 not taken.
33232 volVars.update(elemSol, asImp_(), element, scv);
100
1/2
✓ Branch 0 taken 33132 times.
✗ Branch 1 not taken.
33232 storedDynamicEddyViscosity_[elementIdx] = volVars.calculateEddyViscosity();
101 }
102 }
103
104 // calculate cell-center-averaged gradient
105
3/5
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 33180 times.
✓ Branch 4 taken 104 times.
✗ Branch 5 not taken.
✗ Branch 3 not taken.
99852 for (const auto& element : elements(this->gridGeometry().gridView()))
106 {
107
1/2
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
33232 const unsigned int elementIdx = this->gridGeometry().elementMapper().index(element);
108 33632 fvGeometry.bindElement(element);
109
110
2/2
✓ Branch 0 taken 66264 times.
✓ Branch 1 taken 33132 times.
99696 for (unsigned int axisIdx = 0; axisIdx < Grid::dimension; ++axisIdx)
111 {
112
1/2
✓ Branch 1 taken 200 times.
✗ Branch 2 not taken.
66464 const unsigned int neighborIndex0 = ParentType::neighborIndex(elementIdx, axisIdx, 0);
113 66464 const unsigned int neighborIndex1 = ParentType::neighborIndex(elementIdx, axisIdx, 1);
114
115 // calculate cell-centered turbulentEddyViscosity (viscosityTilde) gradient
116 66464 storedViscosityTildeGradient_[elementIdx][axisIdx]
117 66464 = (storedViscosityTilde(neighborIndex1) - storedViscosityTilde(neighborIndex0))
118
1/2
✓ Branch 1 taken 200 times.
✗ Branch 2 not taken.
66464 / (ParentType::cellCenter(neighborIndex1)[axisIdx] - ParentType::cellCenter(neighborIndex0)[axisIdx]);
119 }
120
121 // Adjust for dirichlet boundary conditions
122
4/4
✓ Branch 0 taken 9596 times.
✓ Branch 1 taken 122932 times.
✓ Branch 2 taken 132528 times.
✓ Branch 3 taken 33132 times.
166160 for (auto&& scvf : scvfs(fvGeometry))
123 {
124
2/2
✓ Branch 0 taken 9596 times.
✓ Branch 1 taken 122932 times.
132928 const unsigned int normDim = scvf.directionIndex();
125
5/6
✓ Branch 0 taken 9596 times.
✓ Branch 1 taken 122932 times.
✓ Branch 2 taken 3794 times.
✓ Branch 3 taken 5802 times.
✓ Branch 4 taken 3794 times.
✗ Branch 5 not taken.
132928 if (scvf.boundary() && asImp_().boundaryTypes(element, scvf).isDirichlet(Indices::viscosityTildeIdx))
126 {
127 // face Value
128
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
5862 Scalar dirichletViscosityTilde = asImp_().dirichlet(element, scvf)[Indices::viscosityTildeIdx];
129
130
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
5822 unsigned int neighborIndex = ParentType::neighborIndex(elementIdx, normDim, 0);
131
3/4
✓ Branch 1 taken 4778 times.
✓ Branch 2 taken 1024 times.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
5822 if (scvf.center()[normDim] < ParentType::cellCenter(elementIdx)[normDim])
132 4798 neighborIndex = ParentType::neighborIndex(elementIdx, normDim, 1);
133
134 5822 storedViscosityTildeGradient_[elementIdx][normDim]
135 5822 = (storedViscosityTilde(neighborIndex) - dirichletViscosityTilde)
136
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
5822 / (ParentType::cellCenter(neighborIndex)[normDim] - scvf.center()[normDim]);
137 }
138 }
139 }
140 156 }
141
142 10451052 bool useStoredEddyViscosity() const
143 {
144
4/6
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 10450344 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
10451052 static const bool useStoredEddyViscosity = getParamFromGroup<bool>(this->paramGroup(), "RANS.UseStoredEddyViscosity", false);
145 10451052 return useStoredEddyViscosity;
146 }
147
148 Scalar storedDynamicEddyViscosity(const int elementIdx) const
149 { return storedDynamicEddyViscosity_[elementIdx]; }
150
151 10522418 Scalar storedViscosityTilde(const int elementIdx) const
152
8/16
✓ Branch 5 taken 50 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 50 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 5 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 50 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 5 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 50 times.
✗ Branch 24 not taken.
✓ Branch 26 taken 5 times.
✗ Branch 27 not taken.
10522418 { return storedViscosityTilde_[elementIdx]; }
153
154 10450352 DimVector storedViscosityTildeGradient(const int elementIdx) const
155 10450352 { 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