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 | 12 | RANSProblemImpl(std::shared_ptr<const GridGeometry> gridGeometry, const std::string& paramGroup = "") | |
57 |
2/6✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
48 | : 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 | 48 | storedDynamicEddyViscosity_.resize(this->gridGeometry().elementMapper().size(), 0.0); | |
69 | 48 | storedViscosityTilde_.resize(this->gridGeometry().elementMapper().size(), 0.0); | |
70 | 60 | 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 |
2/4✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
|
312 | auto fvGeometry = localView(this->gridGeometry()); |
84 |
5/9✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 33180 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.
|
66932 | for (const auto& element : elements(this->gridGeometry().gridView())) |
85 | { | ||
86 | 99696 | unsigned int elementIdx = this->gridGeometry().elementMapper().index(element); | |
87 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
33232 | fvGeometry.bindElement(element); |
88 | |||
89 |
6/6✓ Branch 0 taken 100 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 33032 times.
✓ Branch 3 taken 33032 times.
✓ Branch 4 taken 33032 times.
✓ Branch 5 taken 33032 times.
|
132528 | for (auto&& scv : scvs(fvGeometry)) |
90 | { | ||
91 | 33232 | const int dofIdx = scv.dofIndex(); | |
92 | 66464 | const auto& cellCenterPriVars = curSol[GridGeometry::cellCenterIdx()][dofIdx]; | |
93 | 33232 | PrimaryVariables priVars = makePriVarsFromCellCenterPriVars<PrimaryVariables>(cellCenterPriVars); | |
94 |
1/4✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
66464 | auto elemSol = elementSolution<typename GridGeometry::LocalView>(std::move(priVars)); |
95 | // NOTE: first update the turbulence quantities | ||
96 | 66464 | 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 |
3/6✓ Branch 0 taken 33132 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33132 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 33132 times.
✗ Branch 5 not taken.
|
99696 | storedDynamicEddyViscosity_[elementIdx] = volVars.calculateEddyViscosity(); |
101 | } | ||
102 | } | ||
103 | |||
104 | // calculate cell-center-averaged gradient | ||
105 |
5/9✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 33180 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.
|
66940 | for (const auto& element : elements(this->gridGeometry().gridView())) |
106 | { | ||
107 | 99696 | const unsigned int elementIdx = this->gridGeometry().elementMapper().index(element); | |
108 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
33232 | fvGeometry.bindElement(element); |
109 | |||
110 |
3/3✓ Branch 0 taken 200 times.
✓ Branch 1 taken 66164 times.
✓ Branch 2 taken 33032 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 |
1/2✓ Branch 1 taken 200 times.
✗ Branch 2 not taken.
|
66464 | const unsigned int neighborIndex1 = ParentType::neighborIndex(elementIdx, axisIdx, 1); |
114 | |||
115 | // calculate cell-centered turbulentEddyViscosity (viscosityTilde) gradient | ||
116 | 66464 | storedViscosityTildeGradient_[elementIdx][axisIdx] | |
117 | 199392 | = (storedViscosityTilde(neighborIndex1) - storedViscosityTilde(neighborIndex0)) | |
118 |
2/4✓ Branch 1 taken 200 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 200 times.
✗ Branch 5 not taken.
|
132928 | / (ParentType::cellCenter(neighborIndex1)[axisIdx] - ParentType::cellCenter(neighborIndex0)[axisIdx]); |
119 | } | ||
120 | |||
121 | // Adjust for dirichlet boundary conditions | ||
122 |
6/6✓ Branch 0 taken 132528 times.
✓ Branch 1 taken 33132 times.
✓ Branch 2 taken 132528 times.
✓ Branch 3 taken 33132 times.
✓ Branch 4 taken 9516 times.
✓ Branch 5 taken 122612 times.
|
199392 | for (auto&& scvf : scvfs(fvGeometry)) |
123 | { | ||
124 | 132928 | const unsigned int normDim = scvf.directionIndex(); | |
125 |
4/4✓ Branch 0 taken 9596 times.
✓ Branch 1 taken 122932 times.
✓ Branch 3 taken 3794 times.
✓ Branch 4 taken 5802 times.
|
136902 | 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 |
8/12✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4758 times.
✓ Branch 4 taken 1044 times.
✓ Branch 5 taken 4758 times.
✓ Branch 6 taken 1024 times.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 20 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 20 times.
✗ Branch 12 not taken.
|
17466 | if (scvf.center()[normDim] < ParentType::cellCenter(elementIdx)[normDim]) |
132 | 9596 | neighborIndex = ParentType::neighborIndex(elementIdx, normDim, 1); | |
133 | |||
134 | 5822 | storedViscosityTildeGradient_[elementIdx][normDim] | |
135 | 11644 | = (storedViscosityTilde(neighborIndex) - dirichletViscosityTilde) | |
136 | 29110 | / (ParentType::cellCenter(neighborIndex)[normDim] - scvf.center()[normDim]); | |
137 | } | ||
138 | } | ||
139 | } | ||
140 | 156 | } | |
141 | |||
142 | 10451052 | bool useStoredEddyViscosity() const | |
143 | { | ||
144 |
5/8✓ 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.
✓ Branch 9 taken 8 times.
✗ Branch 10 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 | Scalar storedViscosityTilde(const int elementIdx) const | ||
152 |
20/40✓ 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 5 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 5 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 5 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 5 times.
✗ Branch 37 not taken.
✓ Branch 39 taken 50 times.
✗ Branch 40 not taken.
✓ Branch 42 taken 50 times.
✗ Branch 43 not taken.
✓ Branch 45 taken 50 times.
✗ Branch 46 not taken.
✓ Branch 48 taken 5 times.
✗ Branch 49 not taken.
✓ Branch 51 taken 5 times.
✗ Branch 52 not taken.
✓ Branch 54 taken 50 times.
✗ Branch 55 not taken.
✓ Branch 57 taken 50 times.
✗ Branch 58 not taken.
✓ Branch 60 taken 50 times.
✗ Branch 61 not taken.
✓ Branch 63 taken 5 times.
✗ Branch 64 not taken.
✓ Branch 66 taken 5 times.
✗ Branch 67 not taken.
|
21111100 | { return storedViscosityTilde_[elementIdx]; } |
153 | |||
154 | DimVector storedViscosityTildeGradient(const int elementIdx) const | ||
155 | 20900704 | { 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 |