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 KEpsilonModel | ||
10 | * \copydoc Dumux::KEpsilonFluxVariablesImpl | ||
11 | */ | ||
12 | #ifndef DUMUX_KEPSILON_STAGGERED_FLUXVARIABLES_HH | ||
13 | #define DUMUX_KEPSILON_STAGGERED_FLUXVARIABLES_HH | ||
14 | |||
15 | #include <numeric> | ||
16 | #include <dumux/common/properties.hh> | ||
17 | #include <dumux/flux/fluxvariablesbase.hh> | ||
18 | #include <dumux/discretization/method.hh> | ||
19 | #include <dumux/discretization/extrusion.hh> | ||
20 | #include <dumux/freeflow/navierstokes/fluxvariables.hh> | ||
21 | #include <dumux/freeflow/rans/twoeq/kepsilon/fluxvariables.hh> | ||
22 | |||
23 | namespace Dumux { | ||
24 | |||
25 | /*! | ||
26 | * \ingroup KEpsilonModel | ||
27 | * \brief The flux variables class for the k-epsilon model using the staggered grid discretization. | ||
28 | */ | ||
29 | |||
30 | // forward declaration | ||
31 | template<class TypeTag, class BaseFluxVariables, class DiscretizationMethod> | ||
32 | class KEpsilonFluxVariablesImpl; | ||
33 | |||
34 | template<class TypeTag, class BaseFluxVariables> | ||
35 | class KEpsilonFluxVariablesImpl<TypeTag, BaseFluxVariables, DiscretizationMethods::Staggered> | ||
36 | : public BaseFluxVariables | ||
37 | { | ||
38 | using ParentType = BaseFluxVariables; | ||
39 | |||
40 | using GridVariables = GetPropType<TypeTag, Properties::GridVariables>; | ||
41 | |||
42 | using GridVolumeVariables = typename GridVariables::GridVolumeVariables; | ||
43 | using ElementVolumeVariables = typename GridVolumeVariables::LocalView; | ||
44 | using VolumeVariables = typename GridVolumeVariables::VolumeVariables; | ||
45 | |||
46 | using GridFluxVariablesCache = typename GridVariables::GridFluxVariablesCache; | ||
47 | using FluxVariablesCache = typename GridFluxVariablesCache::FluxVariablesCache; | ||
48 | |||
49 | using GridFaceVariables = typename GridVariables::GridFaceVariables; | ||
50 | using ElementFaceVariables = typename GridFaceVariables::LocalView; | ||
51 | using FaceVariables = typename GridFaceVariables::FaceVariables; | ||
52 | |||
53 | using ModelTraits = GetPropType<TypeTag, Properties::ModelTraits>; | ||
54 | using Scalar = GetPropType<TypeTag, Properties::Scalar>; | ||
55 | using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>; | ||
56 | using FVElementGeometry = typename GridGeometry::LocalView; | ||
57 | using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace; | ||
58 | using GlobalPosition = typename SubControlVolumeFace::GlobalPosition; | ||
59 | using Extrusion = Extrusion_t<GridGeometry>; | ||
60 | using GridView = typename GridGeometry::GridView; | ||
61 | using Problem = GetPropType<TypeTag, Properties::Problem>; | ||
62 | using Element = typename GridView::template Codim<0>::Entity; | ||
63 | using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices; | ||
64 | using CellCenterPrimaryVariables = GetPropType<TypeTag, Properties::CellCenterPrimaryVariables>; | ||
65 | using FacePrimaryVariables = GetPropType<TypeTag, Properties::FacePrimaryVariables>; | ||
66 | |||
67 | static constexpr int turbulentKineticEnergyEqIdx = Indices::turbulentKineticEnergyEqIdx - ModelTraits::dim(); | ||
68 | static constexpr int dissipationEqIdx = Indices::dissipationEqIdx - ModelTraits::dim(); | ||
69 | |||
70 | public: | ||
71 | |||
72 | /*! | ||
73 | * \brief Computes the flux for the cell center residual. | ||
74 | */ | ||
75 | 43371302 | CellCenterPrimaryVariables computeMassFlux(const Problem& problem, | |
76 | const Element &element, | ||
77 | const FVElementGeometry& fvGeometry, | ||
78 | const ElementVolumeVariables& elemVolVars, | ||
79 | const ElementFaceVariables& elemFaceVars, | ||
80 | const SubControlVolumeFace &scvf, | ||
81 | const FluxVariablesCache& fluxVarsCache) | ||
82 | { | ||
83 | 43371302 | CellCenterPrimaryVariables flux = ParentType::computeMassFlux(problem, element, fvGeometry, | |
84 | elemVolVars, elemFaceVars, scvf, fluxVarsCache); | ||
85 | |||
86 | // calculate advective flux | ||
87 | ✗ | auto upwindTermK = [](const auto& volVars) | |
88 | { | ||
89 | 173485208 | return volVars.turbulentKineticEnergy() * volVars.density(); | |
90 | }; | ||
91 | ✗ | auto upwindTermEpsilon = [](const auto& volVars) | |
92 | { | ||
93 | 173485208 | return volVars.dissipation() * volVars.density(); | |
94 | }; | ||
95 | |||
96 | 86742604 | flux[turbulentKineticEnergyEqIdx] | |
97 | 43371302 | = ParentType::advectiveFluxForCellCenter(problem, fvGeometry, elemVolVars, elemFaceVars, scvf, upwindTermK); | |
98 | 86742604 | flux[dissipationEqIdx ] | |
99 | 43371302 | = ParentType::advectiveFluxForCellCenter(problem, fvGeometry, elemVolVars, elemFaceVars, scvf, upwindTermEpsilon); | |
100 | |||
101 | // calculate diffusive flux | ||
102 | 86742604 | const auto& insideScv = fvGeometry.scv(scvf.insideScvIdx()); | |
103 | 86742604 | const auto& outsideScv = fvGeometry.scv(scvf.outsideScvIdx()); | |
104 | 86742604 | const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()]; | |
105 | 86742604 | const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()]; | |
106 | |||
107 | // effective diffusion coefficients | ||
108 |
2/2✓ Branch 0 taken 2306480 times.
✓ Branch 1 taken 41064822 times.
|
43371302 | Scalar insideCoeff_k = (insideVolVars.dynamicEddyViscosity() / insideVolVars.sigmaK()) + insideVolVars.viscosity(); |
109 |
2/2✓ Branch 0 taken 2306480 times.
✓ Branch 1 taken 41064822 times.
|
43371302 | Scalar outsideCoeff_k = (outsideVolVars.dynamicEddyViscosity() / outsideVolVars.sigmaK()) + outsideVolVars.viscosity(); |
110 |
2/2✓ Branch 0 taken 2306480 times.
✓ Branch 1 taken 41064822 times.
|
43371302 | Scalar insideCoeff_e = (insideVolVars.dynamicEddyViscosity() / insideVolVars.sigmaEpsilon()) + insideVolVars.viscosity(); |
111 |
2/2✓ Branch 0 taken 2306480 times.
✓ Branch 1 taken 41064822 times.
|
43371302 | Scalar outsideCoeff_e = (outsideVolVars.dynamicEddyViscosity() / outsideVolVars.sigmaEpsilon()) + outsideVolVars.viscosity(); |
112 | |||
113 | // scale by extrusion factor | ||
114 | 43371302 | insideCoeff_k *= insideVolVars.extrusionFactor(); | |
115 | 43371302 | outsideCoeff_k *= outsideVolVars.extrusionFactor(); | |
116 | 43371302 | insideCoeff_e *= insideVolVars.extrusionFactor(); | |
117 | 43371302 | outsideCoeff_e *= outsideVolVars.extrusionFactor(); | |
118 | |||
119 | 43371302 | Scalar coeff_k = 0.0; | |
120 | 43371302 | Scalar coeff_e = 0.0; | |
121 | 43371302 | Scalar distance = 0.0; | |
122 |
2/2✓ Branch 0 taken 2306480 times.
✓ Branch 1 taken 41064822 times.
|
43371302 | if (scvf.boundary()) |
123 | { | ||
124 | 2306480 | coeff_k = insideCoeff_k; | |
125 | 2306480 | coeff_e = insideCoeff_e; | |
126 | 11532400 | distance = (insideScv.dofPosition() - scvf.ipGlobal()).two_norm(); | |
127 | } | ||
128 | else | ||
129 | { | ||
130 | // average and distance | ||
131 | // is more stable with simple/unweighted arithmetic mean | ||
132 |
2/2✓ Branch 0 taken 40508826 times.
✓ Branch 1 taken 555996 times.
|
41064822 | coeff_k = arithmeticMean(insideCoeff_k, outsideCoeff_k); |
133 |
2/2✓ Branch 0 taken 40507770 times.
✓ Branch 1 taken 557052 times.
|
41064822 | coeff_e = arithmeticMean(insideCoeff_e, outsideCoeff_e); |
134 | 205324110 | distance = (outsideScv.dofPosition() - insideScv.dofPosition()).two_norm(); | |
135 | } | ||
136 | |||
137 | 43371302 | const auto bcTypes = problem.boundaryTypes(element, scvf); | |
138 | |||
139 |
2/2✓ Branch 0 taken 2306480 times.
✓ Branch 1 taken 41064822 times.
|
43371302 | if (!(scvf.boundary() && (bcTypes.isOutflow(Indices::turbulentKineticEnergyEqIdx) |
140 |
6/8✓ Branch 0 taken 1605678 times.
✓ Branch 1 taken 700802 times.
✓ Branch 2 taken 1605678 times.
✓ Branch 3 taken 700802 times.
✓ Branch 4 taken 1605678 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1605678 times.
✗ Branch 7 not taken.
|
4612960 | || bcTypes.isSymmetry() |
141 |
2/2✓ Branch 0 taken 700802 times.
✓ Branch 1 taken 904876 times.
|
1605678 | || bcTypes.hasWall()))) |
142 | { | ||
143 |
2/2✓ Branch 0 taken 1854479 times.
✓ Branch 1 taken 1838278 times.
|
3692757 | if (!(insideVolVars.isMatchingPoint() && outsideVolVars.isMatchingPoint()) |
144 |
2/2✓ Branch 0 taken 5880 times.
✓ Branch 1 taken 1848599 times.
|
1854479 | || !(insideVolVars.isMatchingPoint() && outsideVolVars.inNearWallRegion()) |
145 |
3/4✓ Branch 0 taken 3692757 times.
✓ Branch 1 taken 38072867 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5880 times.
|
41771504 | || !(insideVolVars.inNearWallRegion() && outsideVolVars.isMatchingPoint())) |
146 | { | ||
147 | 125279232 | flux[turbulentKineticEnergyEqIdx] | |
148 | 41759744 | += coeff_k / distance | |
149 | 41759744 | * (insideVolVars.turbulentKineticEnergy() - outsideVolVars.turbulentKineticEnergy()) | |
150 | 83519488 | * Extrusion::area(fvGeometry, scvf); | |
151 | } | ||
152 | } | ||
153 | |||
154 |
2/2✓ Branch 0 taken 2306480 times.
✓ Branch 1 taken 41064822 times.
|
43371302 | if (!(scvf.boundary() && (bcTypes.isOutflow(Indices::dissipationEqIdx) |
155 |
6/8✓ Branch 0 taken 1605678 times.
✓ Branch 1 taken 700802 times.
✓ Branch 2 taken 1605678 times.
✓ Branch 3 taken 700802 times.
✓ Branch 4 taken 1605678 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1605678 times.
✗ Branch 7 not taken.
|
4612960 | || bcTypes.isSymmetry()))) |
156 | { | ||
157 | 128011500 | flux[dissipationEqIdx] | |
158 | 42670500 | += coeff_e / distance | |
159 | 42670500 | * (insideVolVars.dissipation() - outsideVolVars.dissipation()) | |
160 | 85341000 | * Extrusion::area(fvGeometry, scvf); | |
161 | } | ||
162 | 43371302 | return flux; | |
163 | } | ||
164 | |||
165 | /*! | ||
166 | * \brief Returns the momentum flux over all staggered faces. | ||
167 | */ | ||
168 | 36333004 | FacePrimaryVariables computeMomentumFlux(const Problem& problem, | |
169 | const Element& element, | ||
170 | const SubControlVolumeFace& scvf, | ||
171 | const FVElementGeometry& fvGeometry, | ||
172 | const ElementVolumeVariables& elemVolVars, | ||
173 | const ElementFaceVariables& elemFaceVars, | ||
174 | const GridFluxVariablesCache& gridFluxVarsCache) | ||
175 | { | ||
176 | 108999012 | const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()]; | |
177 | |||
178 | 36333004 | return ParentType::computeFrontalMomentumFlux(problem, element, scvf, fvGeometry, elemVolVars, elemFaceVars, gridFluxVarsCache) | |
179 | 145332016 | + ParentType::computeLateralMomentumFlux(problem, element, scvf, fvGeometry, elemVolVars, elemFaceVars, gridFluxVarsCache) | |
180 | 36333004 | + 2.0 / ModelTraits::dim() * insideVolVars.density() * insideVolVars.turbulentKineticEnergy() | |
181 | 72666008 | * Extrusion::area(fvGeometry, scvf) * scvf.directionSign() * insideVolVars.extrusionFactor(); | |
182 | } | ||
183 | |||
184 | }; | ||
185 | |||
186 | } // end namespace | ||
187 | |||
188 | #endif | ||
189 |