24#ifndef DUMUX_KEPSILON_PROBLEM_HH
25#define DUMUX_KEPSILON_PROBLEM_HH
47template<
class TypeTag>
55 using GridView =
typename GridGeometry::GridView;
56 using Element =
typename GridView::template Codim<0>::Entity;
59 using GridFaceVariables =
typename GridVariables::GridFaceVariables;
60 using ElementFaceVariables =
typename GridFaceVariables::LocalView;
61 using GridVolumeVariables =
typename GridVariables::GridVolumeVariables;
62 using ElementVolumeVariables =
typename GridVolumeVariables::LocalView;
65 using SubControlVolumeFace =
typename FVElementGeometry::SubControlVolumeFace;
66 using GlobalPosition =
typename SubControlVolumeFace::GlobalPosition;
74 using Indices =
typename ModelTraits::Indices;
76 static constexpr bool enableEnergyBalance = ModelTraits::enableEnergyBalance();
77 static constexpr bool isCompositional = ModelTraits::numFluidComponents() > 1;
80 static constexpr auto cellCenterOffset = ModelTraits::numEq() - CellCenterPrimaryVariables::dimension;
81 static_assert(cellCenterOffset == ModelTraits::dim(),
"cellCenterOffset must equal dim for staggered NavierStokes");
97 DUNE_THROW(Dune::NotImplemented,
"\n Due to grid/geometric concerns, k-epsilon models should only be used for "
98 <<
" wall bounded flows with flat channel geometries. "
99 <<
"\n If your geometry is a flat channel, please set the runtime parameter RANS.IsFlatWallBounded to true. \n");
104 matchingPointIdx_.resize(this->
gridGeometry().elementMapper().size(), 0);
105 storedDissipation_.resize(this->
gridGeometry().elementMapper().size(), 0.0);
106 storedTurbulentKineticEnergy_.resize(this->
gridGeometry().elementMapper().size(), 0.0);
107 storedDynamicEddyViscosity_.resize(this->
gridGeometry().elementMapper().size(), 0.0);
108 zeroEqDynamicEddyViscosity_.resize(this->
gridGeometry().elementMapper().size(), 0.0);
116 template<
class SolutionVector>
123 for (
const auto& element : elements(this->
gridGeometry().gridView()))
125 unsigned int elementIdx = this->
gridGeometry().elementMapper().index(element);
126 fvGeometry.bindElement(element);
127 for (
auto&& scv : scvs(fvGeometry))
129 const int dofIdx = scv.dofIndex();
130 const auto& cellCenterPriVars = curSol[GridGeometry::cellCenterIdx()][dofIdx];
134 storedDissipation_[elementIdx] = elemSol[0][Indices::dissipationEqIdx];
135 storedTurbulentKineticEnergy_[elementIdx] = elemSol[0][Indices::turbulentKineticEnergyEqIdx];
137 VolumeVariables volVars;
138 volVars.update(elemSol, asImp_(), element, scv);
139 storedDynamicEddyViscosity_[elementIdx] = volVars.calculateEddyViscosity();
144 unsigned int numElementsInNearWallRegion = 0;
145 for (
const auto& element : elements(this->
gridGeometry().gridView()))
147 unsigned int elementIdx = this->
gridGeometry().elementMapper().index(element);
148 unsigned int wallNormalAxis = asImp_().wallNormalAxis(elementIdx);
149 unsigned int neighborIndex0 = asImp_().neighborIndex(elementIdx,
wallNormalAxis, 0);
150 unsigned int neighborIndex1 = asImp_().neighborIndex(elementIdx,
wallNormalAxis, 1);
152 ? numElementsInNearWallRegion + 1
153 : numElementsInNearWallRegion + 0;
158 matchingPointIdx_[asImp_().wallElementIndex(elementIdx)] = elementIdx;
161 std::cout <<
"numElementsInNearWallRegion: " << numElementsInNearWallRegion << std::endl;
164 for (
const auto& element : elements(this->
gridGeometry().gridView()))
166 unsigned int elementIdx = this->
gridGeometry().elementMapper().index(element);
171 static const auto enableZeroEqScaling
173 if (enableZeroEqScaling)
175 for (
const auto& element : elements(this->
gridGeometry().gridView()))
177 unsigned int elementIdx = this->
gridGeometry().elementMapper().index(element);
181 / zeroEqDynamicEddyViscosity_[matchingPointIndex];
183 && !std::isnan(scalingFactor) && !std::isinf(scalingFactor))
185 zeroEqDynamicEddyViscosity_[elementIdx] *= scalingFactor;
188 for (
const auto& element : elements(this->
gridGeometry().gridView()))
190 unsigned int elementIdx = this->
gridGeometry().elementMapper().index(element);
205 unsigned int wallElementIdx = asImp_().wallElementIndex(elementIdx);
220 const Scalar
yPlus(
unsigned int elementIdx)
const
222 return asImp_().wallDistance(elementIdx) *
uStar(elementIdx)
223 / asImp_().kinematicViscosity(elementIdx);
230 return asImp_().wallDistance(elementIdx) *
uStarNominal(elementIdx)
231 / asImp_().kinematicViscosity(elementIdx);
244 Scalar yPlusValue =
yPlus(elementIdx);
245 Scalar mixingLength = 0.0;
246 if (yPlusValue > 0.0)
248 mixingLength = asImp_().karmanConstant() * asImp_().wallDistance(elementIdx)
249 * (1.0 - exp(-yPlusValue / 26.0 ))
250 / sqrt(1.0 - exp(-0.26 * yPlusValue));
253 unsigned int wallNormalAxis = asImp_().wallNormalAxis(elementIdx);
256 return mixingLength * mixingLength * abs(
velocityGradient) * asImp_().storedDensity(elementIdx);
260 const Scalar
uStar(
unsigned int elementIdx)
const
264 unsigned int wallElementIdx = asImp_().wallElementIndex(elementIdx);
265 unsigned int wallNormalAxis = asImp_().wallNormalAxis(elementIdx);
286 / asImp_().karmanConstant() / asImp_().wallDistance(elementIdx);
302 Scalar velocityNominal =
uStarNominal(elementIdx) * (1.0 / asImp_().karmanConstant() * log(
yPlusNominal(elementIdx)) + 5.0);
308 const SubControlVolumeFace& localSubFace,
309 const int& eqIdx)
const
311 unsigned int elementIdx = asImp_().gridGeometry().elementMapper().index(element);
312 auto bcTypes = asImp_().boundaryTypes(element, localSubFace);
314 return bcTypes.hasWall()
315 && bcTypes.isDirichlet(eqIdx)
321 const FVElementGeometry& fvGeometry,
322 const ElementVolumeVariables& elemVolVars,
323 const ElementFaceVariables& elemFaceVars,
324 const SubControlVolumeFace& scvf,
325 const SubControlVolumeFace& localSubFace)
const
327 unsigned int elementIdx = asImp_().gridGeometry().elementMapper().index(element);
333 template<
bool eB = enableEnergyBalance,
bool compositional = isCompositional,
334 typename std::enable_if_t<eB && compositional, int> = 0>
336 const FVElementGeometry& fvGeometry,
337 const ElementVolumeVariables& elemVolVars,
338 const ElementFaceVariables& elemFaceVars,
339 const SubControlVolumeFace& scvf)
const
346 template<
bool eB = enableEnergyBalance,
bool compositional = isCompositional,
347 typename std::enable_if_t<!eB && compositional, int> = 0>
349 const FVElementGeometry& fvGeometry,
350 const ElementVolumeVariables& elemVolVars,
351 const ElementFaceVariables& elemFaceVars,
352 const SubControlVolumeFace& scvf)
const
356 template<
bool eB = enableEnergyBalance,
bool compositional = isCompositional,
357 typename std::enable_if_t<eB && !compositional, int> = 0>
359 const FVElementGeometry& fvGeometry,
360 const ElementVolumeVariables& elemVolVars,
361 const ElementFaceVariables& elemFaceVars,
362 const SubControlVolumeFace& scvf)
const
366 template<
bool eB = enableEnergyBalance,
bool compositional = isCompositional,
367 typename std::enable_if_t<!eB && !compositional, int> = 0>
369 const FVElementGeometry& fvGeometry,
370 const ElementVolumeVariables& elemVolVars,
371 const ElementFaceVariables& elemFaceVars,
372 const SubControlVolumeFace& scvf)
const
373 {
return CellCenterPrimaryVariables(0.0); }
377 const FVElementGeometry& fvGeometry,
378 const ElementVolumeVariables& elemVolVars,
379 const ElementFaceVariables& elemFaceVars,
380 const SubControlVolumeFace& scvf)
const
383 auto wallFunctionFlux = CellCenterPrimaryVariables(0.0);
384 unsigned int elementIdx = asImp_().gridGeometry().elementMapper().index(element);
387 for (
int compIdx = 0; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
389 if (ModelTraits::replaceCompEqIdx() == compIdx)
392 Scalar schmidtNumber = elemVolVars[scvf.insideScvIdx()].kinematicViscosity()
393 / elemVolVars[scvf.insideScvIdx()].diffusionCoefficient(0, 0, compIdx);
394 Scalar moleToMassConversionFactor = ModelTraits::useMoles()
395 ? 1.0 : FluidSystem::molarMass(compIdx);
396 wallFunctionFlux[compIdx] +=
397 -1.0 * (asImp_().dirichlet(element, scvf)[Indices::conti0EqIdx + compIdx]
398 - elemVolVars[scvf.insideScvIdx()].moleFraction(compIdx))
399 * elemVolVars[scvf.insideScvIdx()].molarDensity()
400 * moleToMassConversionFactor
402 / asImp_().turbulentSchmidtNumber()
403 / (1. / asImp_().karmanConstant() * log(
yPlusNominal(elementIdx) * 9.793)
407 if (ModelTraits::replaceCompEqIdx() < ModelTraits::numFluidComponents())
409 wallFunctionFlux[ModelTraits::replaceCompEqIdx()] =
410 -std::accumulate(wallFunctionFlux.begin(), wallFunctionFlux.end(), 0.0);
413 return wallFunctionFlux;
418 const FVElementGeometry& fvGeometry,
419 const ElementVolumeVariables& elemVolVars,
420 const ElementFaceVariables& elemFaceVars,
421 const SubControlVolumeFace& scvf)
const
424 auto wallFunctionFlux = CellCenterPrimaryVariables(0.0);
425 unsigned int elementIdx = asImp_().gridGeometry().elementMapper().index(element);
427 Scalar prandtlNumber = elemVolVars[scvf.insideScvIdx()].kinematicViscosity()
428 * elemVolVars[scvf.insideScvIdx()].density()
429 * elemVolVars[scvf.insideScvIdx()].heatCapacity()
430 / elemVolVars[scvf.insideScvIdx()].thermalConductivity();
431 wallFunctionFlux[Indices::energyEqIdx - cellCenterOffset] +=
432 -1.0 * (asImp_().dirichlet(element, scvf)[Indices::temperatureIdx]
433 - elemVolVars[scvf.insideScvIdx()].temperature())
434 * elemVolVars[scvf.insideScvIdx()].density()
435 * elemVolVars[scvf.insideScvIdx()].heatCapacity()
437 / asImp_().turbulentPrandtlNumber()
438 / (1. / asImp_().karmanConstant() * log(
yPlusNominal(elementIdx) * 9.793)
441 return wallFunctionFlux;
445 const Scalar
pFunction(Scalar molecularNumber, Scalar turbulentNumber)
const
450 * (pow(molecularNumber / turbulentNumber, 0.75) - 1.0)
451 * (1.0 + 0.28 * exp(-0.007 * molecularNumber / turbulentNumber));
471 {
return storedDissipation_[elementIdx]; }
474 {
return storedTurbulentKineticEnergy_[elementIdx]; }
477 {
return storedDynamicEddyViscosity_[elementIdx]; }
480 {
return zeroEqDynamicEddyViscosity_[elementIdx]; }
483 {
return matchingPointIdx_[elementIdx]; }
486 std::vector<unsigned int> matchingPointIdx_;
487 std::vector<Scalar> storedDissipation_;
488 std::vector<Scalar> storedTurbulentKineticEnergy_;
489 std::vector<Scalar> storedDynamicEddyViscosity_;
490 std::vector<Scalar> zeroEqDynamicEddyViscosity_;
493 Implementation &asImp_()
494 {
return *
static_cast<Implementation *
>(
this); }
497 const Implementation &asImp_()
const
498 {
return *
static_cast<const Implementation *
>(
this); }
Base class for all staggered fv problems.
Free function to get the local view of a grid cache object.
The available discretization methods in Dumux.
The available free flow turbulence models in Dumux.
TurbulenceModel
The available free flow turbulence models in Dumux.
Definition turbulencemodel.hh:38
@ kepsilon
Definition turbulencemodel.hh:39
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition localview.hh:38
auto elementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gg) -> std::enable_if_t< GridGeometry::discMethod==DiscretizationMethods::box, BoxElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for box schemes.
Definition box/elementsolution.hh:118
PrimaryVariables makePriVarsFromCellCenterPriVars(const CellCenterPrimaryVariables &cellCenterPriVars)
Helper function to create a PrimaryVariables object from CellCenterPrimaryVariables.
Definition staggered/elementsolution.hh:41
T getParamFromGroup(Args &&... args)
A free function to get a parameter from the parameter tree singleton with a model group.
Definition parameters.hh:161
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition adapt.hh:29
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition propertysystem.hh:180
const std::string & paramGroup() const
The parameter group in which to retrieve runtime parameters.
Definition common/fvproblem.hh:544
const GridGeometry & gridGeometry() const
The finite volume grid geometry.
Definition common/fvproblem.hh:540
unsigned int wallElementIndex(const int elementIdx) const
Definition freeflow/rans/problem.hh:256
int flowDirectionAxis(const int elementIdx) const
Definition freeflow/rans/problem.hh:246
void updateDynamicWallProperties(const SolutionVector &curSol)
Update the dynamic (solution dependent) turbulence parameters.
Definition freeflow/rans/problem.hh:143
void updateStaticWallProperties()
Update the static (solution independent) relations to the walls and neighbors.
Definition freeflow/rans/problem.hh:127
Scalar velocityGradient(const int elementIdx, const int i, const int j) const
Definition freeflow/rans/problem.hh:294
Scalar kinematicViscosity(const int elementIdx) const
Definition freeflow/rans/problem.hh:309
Scalar turbulentSchmidtNumber() const
Return the turbulent Schmidt number which is used to convert the eddy viscosity to an eddy diffusivi...
Definition freeflow/rans/problem.hh:229
Scalar storedDensity(const int elementIdx) const
Definition freeflow/rans/problem.hh:306
Scalar turbulentPrandtlNumber() const
Return the turbulent Prandtl number which is used to convert the eddy viscosity to an eddy thermal c...
Definition freeflow/rans/problem.hh:218
int wallNormalAxis(const int elementIdx) const
Definition freeflow/rans/problem.hh:236
RANSProblemBase(std::shared_ptr< const GridGeometry > gridGeometry, const std::string ¶mGroup="")
The constructor.
Definition freeflow/rans/problem.hh:102
bool isFlatWallBounded() const
Returns whether a given sub control volume face is on a wall.
Definition freeflow/rans/problem.hh:198
const Scalar tangentialMomentumWallFunction(unsigned int elementIdx, Scalar velocity) const
Returns the nominal wall shear stress (accounts for poor approximation of viscous sublayer).
Definition freeflow/rans/twoeq/kepsilon/problem.hh:299
Scalar yPlusThreshold() const
Definition freeflow/rans/twoeq/kepsilon/problem.hh:458
void updateDynamicWallProperties(const SolutionVector &curSol)
Update the dynamic (solution dependent) relations to the walls.
Definition freeflow/rans/twoeq/kepsilon/problem.hh:117
const Scalar yPlus(unsigned int elementIdx) const
Returns the value at an element center.
Definition freeflow/rans/twoeq/kepsilon/problem.hh:220
bool useStoredEddyViscosity() const
Definition freeflow/rans/twoeq/kepsilon/problem.hh:464
unsigned int matchingPointIdx(const int elementIdx) const
Definition freeflow/rans/twoeq/kepsilon/problem.hh:482
const Scalar zeroEqEddyViscosityModel(unsigned int elementIdx) const
Returns the kinematic eddy viscosity of a 0-Eq. model.
Definition freeflow/rans/twoeq/kepsilon/problem.hh:237
const Scalar cMu() const
Returns the constant.
Definition freeflow/rans/twoeq/kepsilon/problem.hh:455
bool inNearWallRegion(unsigned int elementIdx) const
Returns if an element is located in the near-wall region.
Definition freeflow/rans/twoeq/kepsilon/problem.hh:203
CellCenterPrimaryVariables wallFunction(const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const ElementFaceVariables &elemFaceVars, const SubControlVolumeFace &scvf) const
Returns the flux for non-isothermal and compositional RANS models.
Definition freeflow/rans/twoeq/kepsilon/problem.hh:335
Scalar storedTurbulentKineticEnergy(const int elementIdx) const
Definition freeflow/rans/twoeq/kepsilon/problem.hh:473
Scalar storedDissipation(const int elementIdx) const
Definition freeflow/rans/twoeq/kepsilon/problem.hh:470
Scalar zeroEqDynamicEddyViscosity(const int elementIdx) const
Definition freeflow/rans/twoeq/kepsilon/problem.hh:479
CellCenterPrimaryVariables wallFunctionEnergy(const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const ElementFaceVariables &elemFaceVars, const SubControlVolumeFace &scvf) const
Returns the energy wall-function flux.
Definition freeflow/rans/twoeq/kepsilon/problem.hh:417
FacePrimaryVariables wallFunction(const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const ElementFaceVariables &elemFaceVars, const SubControlVolumeFace &scvf, const SubControlVolumeFace &localSubFace) const
Returns an additional wall function momentum flux (only needed for RANS models).
Definition freeflow/rans/twoeq/kepsilon/problem.hh:320
const Scalar uStarNominal(unsigned int elementIdx) const
Returns the nominal wall shear stress velocity (accounts for poor approximation of viscous sublayer).
Definition freeflow/rans/twoeq/kepsilon/problem.hh:272
const Scalar uStar(unsigned int elementIdx) const
Returns the wall shear stress velocity.
Definition freeflow/rans/twoeq/kepsilon/problem.hh:260
const Scalar dissipationWallFunction(unsigned int elementIdx) const
Returns the dissipation calculated from the wall function consideration.
Definition freeflow/rans/twoeq/kepsilon/problem.hh:283
RANSProblemImpl(std::shared_ptr< const GridGeometry > gridGeometry, const std::string ¶mGroup="")
The constructor sets the gravity, if desired by the user.
Definition freeflow/rans/twoeq/kepsilon/problem.hh:86
const Scalar yPlusNominal(unsigned int elementIdx) const
Returns the nominal value at an element center.
Definition freeflow/rans/twoeq/kepsilon/problem.hh:228
Scalar storedDynamicEddyViscosity(const int elementIdx) const
Definition freeflow/rans/twoeq/kepsilon/problem.hh:476
const Scalar pFunction(Scalar molecularNumber, Scalar turbulentNumber) const
Returns the value of the P-function after Jayatilleke versteeg2009a.
Definition freeflow/rans/twoeq/kepsilon/problem.hh:445
CellCenterPrimaryVariables wallFunctionComponent(const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const ElementFaceVariables &elemFaceVars, const SubControlVolumeFace &scvf) const
Returns the component wall-function flux.
Definition freeflow/rans/twoeq/kepsilon/problem.hh:376
void updateStaticWallProperties()
Correct size of the static (solution independent) wall variables.
Definition freeflow/rans/twoeq/kepsilon/problem.hh:93
bool useWallFunction(const Element &element, const SubControlVolumeFace &localSubFace, const int &eqIdx) const
Checks whether a wall function should be used.
Definition freeflow/rans/twoeq/kepsilon/problem.hh:307
bool isMatchingPoint(unsigned int elementIdx) const
Returns if an element is the matching point.
Definition freeflow/rans/twoeq/kepsilon/problem.hh:214
const Scalar turbulentKineticEnergyWallFunction(unsigned int elementIdx) const
Returns the turbulentKineticEnergy calculated from the wall function consideration.
Definition freeflow/rans/twoeq/kepsilon/problem.hh:292
Declares all properties used in Dumux.
A single-phase, isothermal k-epsilon model.
the turbulence-model-specfic RANS problem
The local element solution class for staggered methods.