GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/freeflow/rans/twoeq/sst/staggered/fluxvariables.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 61 72 84.7%
Functions: 8 16 50.0%
Branches: 22 46 47.8%

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 * \copydoc Dumux::SSTFluxVariablesImpl
11 */
12 #ifndef DUMUX_SST_STAGGERED_FLUXVARIABLES_HH
13 #define DUMUX_SST_STAGGERED_FLUXVARIABLES_HH
14
15 #include <numeric>
16 #include <dune/common/exceptions.hh>
17 #include <dumux/common/properties.hh>
18 #include <dumux/flux/fluxvariablesbase.hh>
19 #include <dumux/discretization/method.hh>
20 #include <dumux/discretization/extrusion.hh>
21 #include <dumux/freeflow/turbulencemodel.hh>
22 #include <dumux/freeflow/navierstokes/fluxvariables.hh>
23 #include <dumux/freeflow/rans/twoeq/sst/fluxvariables.hh>
24
25 namespace Dumux {
26
27 /*!
28 * \ingroup SSTModel
29 * \brief The flux variables class for the SST model using the staggered grid discretization.
30 */
31
32 // forward declaration
33 template<class TypeTag, class BaseFluxVariables, class DiscretizationMethod>
34 class SSTFluxVariablesImpl;
35
36 template<class TypeTag, class BaseFluxVariables>
37 class SSTFluxVariablesImpl<TypeTag, BaseFluxVariables, DiscretizationMethods::Staggered>
38 : public BaseFluxVariables
39 {
40 using ParentType = BaseFluxVariables;
41
42 using GridVariables = GetPropType<TypeTag, Properties::GridVariables>;
43
44 using GridVolumeVariables = typename GridVariables::GridVolumeVariables;
45 using ElementVolumeVariables = typename GridVolumeVariables::LocalView;
46 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
47
48 using GridFluxVariablesCache = typename GridVariables::GridFluxVariablesCache;
49 using FluxVariablesCache = typename GridFluxVariablesCache::FluxVariablesCache;
50
51 using GridFaceVariables = typename GridVariables::GridFaceVariables;
52 using ElementFaceVariables = typename GridFaceVariables::LocalView;
53 using FaceVariables = typename GridFaceVariables::FaceVariables;
54
55 using ModelTraits = GetPropType<TypeTag, Properties::ModelTraits>;
56 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
57 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
58 using FVElementGeometry = typename GridGeometry::LocalView;
59 using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace;
60 using Extrusion = Extrusion_t<GridGeometry>;
61 using GridView = typename GridGeometry::GridView;
62 using Problem = GetPropType<TypeTag, Properties::Problem>;
63 using Element = typename GridView::template Codim<0>::Entity;
64 using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices;
65 using CellCenterPrimaryVariables = GetPropType<TypeTag, Properties::CellCenterPrimaryVariables>;
66 using FacePrimaryVariables = GetPropType<TypeTag, Properties::FacePrimaryVariables>;
67
68 static constexpr int turbulentKineticEnergyEqIdx = Indices::turbulentKineticEnergyEqIdx - ModelTraits::dim();
69 static constexpr int dissipationEqIdx = Indices::dissipationEqIdx - ModelTraits::dim();
70
71 public:
72
73 /*!
74 * \brief Computes the flux for the cell center residual.
75 */
76 23407464 CellCenterPrimaryVariables computeMassFlux(const Problem& problem,
77 const Element &element,
78 const FVElementGeometry& fvGeometry,
79 const ElementVolumeVariables& elemVolVars,
80 const ElementFaceVariables& elemFaceVars,
81 const SubControlVolumeFace &scvf,
82 const FluxVariablesCache& fluxVarsCache)
83 {
84 23407464 CellCenterPrimaryVariables flux = ParentType::computeMassFlux(problem, element, fvGeometry,
85 elemVolVars, elemFaceVars, scvf, fluxVarsCache);
86
87 // calculate advective flux
88 auto upwindTermK = [](const auto& volVars)
89 93629856 { return volVars.turbulentKineticEnergy() * volVars.density(); };
90 auto upwindTermOmega = [](const auto& volVars)
91 93629856 { return volVars.dissipation() * volVars.density(); };
92
93 46814928 flux[turbulentKineticEnergyEqIdx]
94 23407464 = ParentType::advectiveFluxForCellCenter(problem, fvGeometry, elemVolVars, elemFaceVars, scvf, upwindTermK);
95 46814928 flux[dissipationEqIdx]
96 23407464 = ParentType::advectiveFluxForCellCenter(problem, fvGeometry, elemVolVars, elemFaceVars, scvf, upwindTermOmega);
97
98 // calculate diffusive flux
99 46814928 const auto& insideScv = fvGeometry.scv(scvf.insideScvIdx());
100 46814928 const auto& outsideScv = fvGeometry.scv(scvf.outsideScvIdx());
101 46814928 const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()];
102 46814928 const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()];
103 23407464 Scalar insideCoeff_k = 0.0, insideCoeff_w = 0.0, outsideCoeff_k = 0.0, outsideCoeff_w = 0.0;
104
105
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23407464 times.
23407464 if(problem.sstModelVersion() == SSTModel::BSL)
106 {
107 insideCoeff_k = insideVolVars.viscosity()
108 + ( insideVolVars.sigmaKBSL() * insideVolVars.dynamicEddyViscosity() );
109 outsideCoeff_k = outsideVolVars.viscosity()
110 + ( outsideVolVars.sigmaKBSL() * outsideVolVars.dynamicEddyViscosity() );
111 insideCoeff_w = insideVolVars.viscosity()
112 + ( insideVolVars.sigmaOmegaBSL() * insideVolVars.dynamicEddyViscosity() );
113 outsideCoeff_w = outsideVolVars.viscosity()
114 + ( outsideVolVars.sigmaOmegaBSL() * outsideVolVars.dynamicEddyViscosity() );
115 }
116
1/2
✓ Branch 0 taken 23407464 times.
✗ Branch 1 not taken.
23407464 else if(problem.sstModelVersion() == SSTModel::SST)
117 {
118 23407464 insideCoeff_k = insideVolVars.viscosity()
119 46814928 + ( insideVolVars.sigmaKSST() * insideVolVars.dynamicEddyViscosity() );
120 23407464 outsideCoeff_k = outsideVolVars.viscosity()
121 46814928 + ( outsideVolVars.sigmaKSST() * outsideVolVars.dynamicEddyViscosity() );
122 23407464 insideCoeff_w = insideVolVars.viscosity()
123 46814928 + ( insideVolVars.sigmaOmegaSST() * insideVolVars.dynamicEddyViscosity() );
124 23407464 outsideCoeff_w = outsideVolVars.viscosity()
125 46814928 + ( outsideVolVars.sigmaOmegaSST() * outsideVolVars.dynamicEddyViscosity() );
126 }
127 else
128 DUNE_THROW(Dune::NotImplemented, "\nThis SST Model is not implemented.\n");
129
130
131 // scale by extrusion factor
132 23407464 insideCoeff_k *= insideVolVars.extrusionFactor();
133 23407464 outsideCoeff_k *= outsideVolVars.extrusionFactor();
134 23407464 insideCoeff_w *= insideVolVars.extrusionFactor();
135 23407464 outsideCoeff_w *= outsideVolVars.extrusionFactor();
136
137 23407464 Scalar distance = 0.0;
138 23407464 Scalar coeff_k = 0.0;
139 23407464 Scalar coeff_w = 0.0;
140
2/2
✓ Branch 0 taken 1350456 times.
✓ Branch 1 taken 22057008 times.
23407464 if (scvf.boundary())
141 {
142 5401824 distance = (insideScv.dofPosition() - scvf.ipGlobal()).two_norm();
143 1350456 coeff_k = insideCoeff_k;
144 1350456 coeff_w = insideCoeff_w;
145 }
146 else
147 {
148 // average and distance
149
1/2
✓ Branch 0 taken 22057008 times.
✗ Branch 1 not taken.
22057008 coeff_k = arithmeticMean(insideCoeff_k, outsideCoeff_k,
150 88228032 (outsideScv.dofPosition() - scvf.ipGlobal()).two_norm(),
151 88228032 (insideScv.dofPosition() - scvf.ipGlobal()).two_norm());
152
1/2
✓ Branch 0 taken 22057008 times.
✗ Branch 1 not taken.
22057008 coeff_w = arithmeticMean(insideCoeff_w, outsideCoeff_w,
153 88228032 (outsideScv.dofPosition() - scvf.ipGlobal()).two_norm(),
154 88228032 (insideScv.dofPosition() - scvf.ipGlobal()).two_norm());
155 110285040 distance = (outsideScv.dofPosition() - insideScv.dofPosition()).two_norm();
156 }
157
158 23407464 const auto bcTypes = problem.boundaryTypes(element, scvf);
159
2/2
✓ Branch 0 taken 1350456 times.
✓ Branch 1 taken 22057008 times.
23407464 if (!(scvf.boundary() && (bcTypes.isOutflow(Indices::turbulentKineticEnergyEqIdx)
160
6/8
✓ Branch 0 taken 871328 times.
✓ Branch 1 taken 479128 times.
✓ Branch 2 taken 871328 times.
✓ Branch 3 taken 479128 times.
✓ Branch 4 taken 871328 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 871328 times.
✗ Branch 7 not taken.
2700912 || bcTypes.isSymmetry())))
161 {
162 68785008 flux[turbulentKineticEnergyEqIdx]
163 22928336 += coeff_k / distance
164 22928336 * (insideVolVars.turbulentKineticEnergy() - outsideVolVars.turbulentKineticEnergy())
165 45856672 * Extrusion::area(fvGeometry, scvf);
166 }
167
2/2
✓ Branch 0 taken 1350456 times.
✓ Branch 1 taken 22057008 times.
23407464 if (!(scvf.boundary() && (bcTypes.isOutflow(Indices::dissipationEqIdx)
168
6/8
✓ Branch 0 taken 871328 times.
✓ Branch 1 taken 479128 times.
✓ Branch 2 taken 871328 times.
✓ Branch 3 taken 479128 times.
✓ Branch 4 taken 871328 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 871328 times.
✗ Branch 7 not taken.
2700912 || bcTypes.isSymmetry())))
169 {
170 68785008 flux[dissipationEqIdx]
171 22928336 += coeff_w / distance
172 22928336 * (insideVolVars.dissipation() - outsideVolVars.dissipation())
173 45856672 * Extrusion::area(fvGeometry, scvf);
174 }
175 23407464 return flux;
176 }
177
178 /*!
179 * \brief Returns the momentum flux over all staggered faces.
180 */
181 19127552 FacePrimaryVariables computeMomentumFlux(const Problem& problem,
182 const Element& element,
183 const SubControlVolumeFace& scvf,
184 const FVElementGeometry& fvGeometry,
185 const ElementVolumeVariables& elemVolVars,
186 const ElementFaceVariables& elemFaceVars,
187 const GridFluxVariablesCache& gridFluxVarsCache)
188 {
189 38255104 const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()];
190
191 19127552 return ParentType::computeFrontalMomentumFlux(problem, element, scvf, fvGeometry, elemVolVars, elemFaceVars, gridFluxVarsCache)
192 76510208 + ParentType::computeLateralMomentumFlux(problem, element, scvf, fvGeometry, elemVolVars, elemFaceVars, gridFluxVarsCache)
193 19127552 + 2.0 / ModelTraits::dim() * insideVolVars.density() * insideVolVars.turbulentKineticEnergy()
194 38255104 * Extrusion::area(fvGeometry, scvf) * scvf.directionSign() * insideVolVars.extrusionFactor();
195 }
196 };
197
198 } // end namespace
199
200 #endif
201