kL.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2021-2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "kL.H"
29 #include "fvOptions.H"
30 #include "bound.H"
31 #include "gravityMeshObject.H"
32 #include "wallDist.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace RASModels
39 {
40 
41 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
42 
43 template<class BasicTurbulenceModel>
44 tmp<volScalarField> kL<BasicTurbulenceModel>::Cmu() const
45 {
46  // (A:Eq. 31)
47  return (0.556 + 0.108*Rt_)/(1.0 + 0.308*Rt_ + 0.00837*sqr(Rt_));
48 }
49 
50 
51 template<class BasicTurbulenceModel>
52 tmp<volScalarField> kL<BasicTurbulenceModel>::CmuPrime() const
53 {
54  // (A:Eq. 32)
55  return 0.556/(1.0 + 0.277*Rt_);
56 }
57 
58 
59 template<class BasicTurbulenceModel>
60 tmp<volScalarField> kL<BasicTurbulenceModel>::nutPrime() const
61 {
62  // (A:Eq. 12)
63  return CmuPrime()*sqrt(k_)*L_;
64 }
65 
66 
67 template<class BasicTurbulenceModel>
68 tmp<volScalarField> kL<BasicTurbulenceModel>::epsilonCanopy() const
69 {
70  const auto* CdPtr = this->mesh_.template findObject<volScalarField>("Cd");
71  const auto* LADPtr = this->mesh_.template findObject<volScalarField>("LAD");
72  const volVectorField& U = this->U_;
73 
74  if (CdPtr && LADPtr)
75  {
76  const auto& Cd = *CdPtr;
77  const auto& LAD = *LADPtr;
78 
79  // (W:Eq. 13)
80  return Cd*LAD*mag(U)*k_;
81  }
82 
84  (
85  IOobject
86  (
87  IOobject::groupName("epsilonCanopy", this->alphaRhoPhi_.group()),
88  this->runTime_.timeName(),
89  this->mesh_,
93  ),
94  this->mesh_,
96  );
97 }
98 
99 
100 template<class BasicTurbulenceModel>
101 tmp<volScalarField> kL<BasicTurbulenceModel>::epsilon() const
102 {
103  // (W:Eq. 13)
104  tmp<volScalarField> tepsilonCanopy = epsilonCanopy();
105 
106  // (A:Eq. 19)
107  tmp<volScalarField> tepsilonPlain = pow3(Cmu0_)*pow(k_, 1.5)/L_;
108 
109  // (W:Eq. 13)
110  tmp<volScalarField> tepsilon = max(tepsilonPlain, tepsilonCanopy);
111  volScalarField& epsilon = tepsilon.ref();
112  bound(epsilon, this->epsilonMin_);
113 
114  return tepsilon;
115 }
116 
117 
118 template<class BasicTurbulenceModel>
119 tmp<volScalarField> kL<BasicTurbulenceModel>::canopyHeight() const
120 {
121  const auto* canopyHeightPtr =
122  this->mesh_.template findObject<volScalarField>("canopyHeight");
123 
124  if (canopyHeightPtr)
125  {
126  const auto& canopyHeight = *canopyHeightPtr;
127  return canopyHeight;
128  }
129 
131  (
132  IOobject
133  (
134  IOobject::groupName("canopyHeight", this->alphaRhoPhi_.group()),
135  this->runTime_.timeName(),
136  this->mesh_,
140  ),
141  this->mesh_,
143  );
144 }
145 
146 
147 template<class BasicTurbulenceModel>
148 tmp<volScalarField> kL<BasicTurbulenceModel>::L() const
149 {
150  // (A:Eq. 22)
151  const volScalarField Lplain(kappa_*y_);
152 
153  // Increase roughness for canopy (forest, vegetation etc)
154  tmp<volScalarField> tLcanopy = kappa_*canopyHeight();
155  const volScalarField& Lcanopy = tLcanopy;
156 
157  // (W:Eq. 16)
158  return max(Lcanopy, Lplain);
159 }
160 
161 
162 template<class BasicTurbulenceModel>
163 void kL<BasicTurbulenceModel>::stratification(const volScalarField& fVB)
164 {
165  tmp<volScalarField> tLg = L();
166  const volScalarField& Lg = tLg.cref();
167 
168  tmp<volScalarField> tcanopyHeight = canopyHeight();
169  const volScalarField& canopyHeight = tcanopyHeight;
170 
171  tmp<volScalarField> tLcanopy = kappa_*canopyHeight;
172  const volScalarField& Lcanopy = tLcanopy;
173 
174  const scalar Cmu0 = Cmu0_.value();
175  const scalar CbStable = CbStable_.value();
176  const scalar CbUnstable = CbUnstable_.value();
177 
178  forAll(L_, i)
179  {
180  if (y_[i] > canopyHeight[i])
181  {
182  if (fVB[i] > 0)
183  {
184  // (A:Eq. 23)
185  const scalar Lb = CbStable*sqrt(k_[i])/sqrt(fVB[i]);
186 
187  // (A:Eq. 26)
188  L_[i] = sqrt(sqr(Lg[i]*Lb)/(sqr(Lg[i]) + sqr(Lb)));
189  }
190  else
191  {
192  // For unstable/neutral boundary layer (A:p. 80)
193  // Smoothing function for turbulent Richardson
194  // number to ensure gentle transition into
195  // the regime of strong convection
196  Rt_[i] =
197  min
198  (
199  max(Rt_[i], -1.0),
200  Rt_[i] - sqr(Rt_[i] + 1.0)/(Rt_[i] - 1.0)
201  );
202 
203  // (A:Eq. 28)
204  L_[i] =
205  Lg[i]
206  *sqrt(1.0 - pow(Cmu0, 6.0)*pow(CbUnstable, -2.0)*Rt_[i]);
207  }
208  }
209  else
210  {
211  L_[i] = Lcanopy[i];
212  }
213  }
214 
215  // Limit characteristic length scale
216  L_ = min(L_, Lmax_);
217 }
218 
219 
220 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
221 
222 template<class BasicTurbulenceModel>
224 {
225  this->nut_ = Cmu()*sqrt(k_)*L_;
226  this->nut_.correctBoundaryConditions();
227  fv::options::New(this->mesh_).correct(this->nut_);
228 
229  BasicTurbulenceModel::correctNut();
230 }
231 
232 
233 template<class BasicTurbulenceModel>
235 {
237  (
238  k_,
239  dimVolume*this->rho_.dimensions()*k_.dimensions()/dimTime
240  );
241 }
242 
243 
244 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
245 
246 template<class BasicTurbulenceModel>
248 (
249  const alphaField& alpha,
250  const rhoField& rho,
251  const volVectorField& U,
252  const surfaceScalarField& alphaRhoPhi,
253  const surfaceScalarField& phi,
254  const transportModel& transport,
255  const word& propertiesName,
256  const word& type
257 )
258 :
259  eddyViscosity<RASModel<BasicTurbulenceModel>>
260  (
261  type,
262  alpha,
263  rho,
264  U,
265  alphaRhoPhi,
266  phi,
267  transport,
268  propertiesName
269  ),
270 
271  kappa_
272  (
273  dimensioned<scalar>::getOrAddToDict
274  (
275  "kappa",
276  this->coeffDict_,
277  0.41
278  )
279  ),
280  sigmak_
281  (
282  dimensioned<scalar>::getOrAddToDict
283  (
284  "sigmak",
285  this->coeffDict_,
286  1.0
287  )
288  ),
289  beta_
290  (
291  dimensioned<scalar>::getOrAddToDict
292  (
293  "beta",
294  this->coeffDict_,
296  3.3e-03
297  )
298  ),
299  Cmu0_
300  (
301  dimensioned<scalar>::getOrAddToDict
302  (
303  "Cmu0",
304  this->coeffDict_,
305  0.556
306  )
307  ),
308  Lmax_
309  (
310  dimensioned<scalar>::getOrAddToDict
311  (
312  "Lmax",
313  this->coeffDict_,
314  dimLength,
315  GREAT
316  )
317  ),
318  CbStable_
319  (
320  dimensioned<scalar>::getOrAddToDict
321  (
322  "CbStable",
323  this->coeffDict_,
324  0.25
325  )
326  ),
327  CbUnstable_
328  (
329  dimensioned<scalar>::getOrAddToDict
330  (
331  "CbUnstable",
332  this->coeffDict_,
333  0.35
334  )
335  ),
336 
337  k_
338  (
339  IOobject
340  (
341  IOobject::groupName("k", alphaRhoPhi.group()),
342  this->runTime_.timeName(),
343  this->mesh_,
344  IOobject::MUST_READ,
345  IOobject::AUTO_WRITE
346  ),
347  this->mesh_
348  ),
349  L_
350  (
351  IOobject
352  (
353  IOobject::groupName("L", alphaRhoPhi.group()),
354  this->runTime_.timeName(),
355  this->mesh_,
356  IOobject::READ_IF_PRESENT,
357  IOobject::AUTO_WRITE
358  ),
359  this->mesh_,
360  dimensionedScalar(dimLength, scalar(1))
361  ),
362  Rt_
363  (
364  IOobject
365  (
366  IOobject::groupName("Rt", alphaRhoPhi.group()),
367  this->runTime_.timeName(),
368  this->mesh_,
369  IOobject::READ_IF_PRESENT,
370  IOobject::AUTO_WRITE
371  ),
372  this->mesh_,
374  ),
375  g_(meshObjects::gravity::New(this->mesh_.time())),
376  y_(wallDist::New(this->mesh_).y())
377 {
378  bound(k_, this->kMin_);
379 
380  if (type == typeName)
381  {
382  this->printCoeffs(type);
383  }
384 }
385 
386 
387 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
388 
389 template<class BasicTurbulenceModel>
391 {
393  {
394  kappa_.readIfPresent(this->coeffDict());
395  sigmak_.readIfPresent(this->coeffDict());
396  beta_.readIfPresent(this->coeffDict());
397  Cmu0_.readIfPresent(this->coeffDict());
398  Lmax_.readIfPresent(this->coeffDict());
399  CbStable_.readIfPresent(this->coeffDict());
400  CbUnstable_.readIfPresent(this->coeffDict());
401 
402  return true;
403  }
404 
405  return false;
406 }
407 
408 
409 template<class BasicTurbulenceModel>
411 {
412  if (!this->turbulence_)
413  {
414  return;
415  }
416 
417  // Construct local convenience references
418  const alphaField& alpha = this->alpha_;
419  const rhoField& rho = this->rho_;
420  const surfaceScalarField& alphaRhoPhi = this->alphaRhoPhi_;
421  const volVectorField& U = this->U_;
422  const volScalarField& nut = this->nut_;
423 
424  fv::options& fvOptions(fv::options::New(this->mesh_));
425 
426  eddyViscosity<RASModel<BasicTurbulenceModel>>::correct();
427 
428  // Turbulent kinetic energy production rate
429  tmp<volTensorField> tgradU = fvc::grad(U);
431  (
432  this->GName(),
433  nut.v()*2*magSqr(devSymm(tgradU.cref().v()))
434  );
435  tgradU.clear();
436 
437  // Square of Brunt-Vaisala (buoyancy) frequency
438  const auto& T = U.mesh().lookupObject<volScalarField>("T");
439  tmp<volScalarField> tfBV = -beta_*(fvc::grad(T) & g_);
440  const volScalarField& fBV = tfBV.cref();
441 
442  // Sink or source of TKE depending on stratification type (A:Eq. 15)
443  tmp<volScalarField> tPb = -fBV*nutPrime();
444  const volScalarField& Pb = tPb.cref();
445 
446  // Turbulent kinetic energy dissipation rate due to plains and canopy
447  tmp<volScalarField> tepsilon = epsilon();
448  const volScalarField& epsilon = tepsilon.cref();
449 
450  // Divergence of velocity
451  tmp<volScalarField> tdivU = fvc::div(fvc::absolute(this->phi(), U));
452  const volScalarField::Internal& divU = tdivU.cref().v();
453 
454  // Turbulent kinetic energy equation
455  tmp<fvScalarMatrix> kEqn
456  (
457  fvm::ddt(alpha, rho, k_)
458  + fvm::div(alphaRhoPhi, k_)
459  - fvm::laplacian(alpha*rho*DkEff(), k_)
460  ==
461  alpha()*rho()*G
462  + fvm::SuSp((Pb - epsilon)/k_, k_)
463  - fvm::SuSp((2.0/3.0)*alpha()*rho()*divU, k_)
464  + kSource()
465  + fvOptions(alpha, rho, k_)
466  );
467 
468  tdivU.clear();
469  tPb.clear();
470 
471  kEqn.ref().relax();
472  fvOptions.constrain(kEqn.ref());
473  solve(kEqn);
474  fvOptions.correct(k_);
475  bound(k_, this->kMin_);
476 
477  // Turbulent Richardson number (A:Eq. 29)
478  Rt_ = fBV*sqr(k_/tepsilon);
479 
480  stratification(fBV);
481  tfBV.clear();
482 
483  correctNut();
484 }
485 
486 
487 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
488 
489 } // End namespace RASModels
490 } // End namespace Foam
491 
492 // ************************************************************************* //
void correct(GeometricField< Type, PatchField, GeoMesh > &field)
Apply correction to field.
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:47
dimensionedScalar kMin_
Lower limit of k.
Definition: RASModel.H:109
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
const vector L(dict.get< vector >("L"))
const dimensionedScalar G
Newtonian constant of gravitation.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
dimensionedSymmTensor sqr(const dimensionedVector &dv)
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcDiv.C:42
dimensionedScalar sqrt(const dimensionedScalar &ds)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
SymmTensor< Cmpt > devSymm(const SymmTensor< Cmpt > &st)
Return the deviatoric part of the symmetric part of a SymmTensor.
Definition: SymmTensorI.H:481
Generic dimensioned Type class.
Ignore writing from objectRegistry::writeObject()
const dimensionSet dimless
Dimensionless.
Eddy viscosity turbulence model base class.
Definition: eddyViscosity.H:51
virtual tmp< fvScalarMatrix > kSource() const
Add explicit source for turbulent kinetic energy.
Definition: kL.C:227
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:82
DimensionedField< scalar, volMesh > Internal
The internal field type from which this GeometricField is derived.
fv::options & fvOptions
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:127
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
Templated abstract base class for RAS turbulence models.
Definition: RASModel.H:77
constexpr const char *const group
Group name for atomic constants.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:81
volScalarField k_
Turbulent kinetic energy [m2/s2].
Definition: kL.H:328
word timeName
Definition: getTimeIndex.H:3
A one-equation (turbulent kinetic energy k) turbulence closure model for incompressible and compressi...
Definition: kL.H:218
virtual bool read()
Re-read model coefficients if they have changed.
Definition: kL.C:383
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
const dimensionSet dimVolume(pow3(dimLength))
Definition: dimensionSets.H:58
scalar y
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
virtual void correctNut()
Correct the turbulence viscosity.
Definition: kL.C:216
A class for handling words, derived from Foam::string.
Definition: word.H:63
const dimensionSet dimTemperature(0, 0, 0, 1, 0, 0, 0)
Definition: dimensionSets.H:52
tmp< fvMatrix< Type > > ddt(const GeometricField< Type, fvPatchField, volMesh > &vf)
Definition: fvmDdt.C:41
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition: tmp.H:206
zeroField SuSp(const Foam::zero, const GeometricField< Type, fvPatchField, volMesh > &)
A no-op source.
virtual void printCoeffs(const word &type)
Print model coefficients.
Definition: RASModel.C:27
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
SolverPerformance< Type > solve(faMatrix< Type > &, const dictionary &solverControls)
Solve returning the solution statistics given convergence tolerance.
tmp< fvMatrix< Type > > div(const surfaceScalarField &flux, const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvmDiv.C:41
Bound the given scalar field if it has gone unbounded.
Info<< "Predicted p max-min : "<< max(p).value()<< " "<< min(p).value()<< endl;rho==max(psi *p+alphal *rhol0+((alphav *psiv+alphal *psil) - psi) *pSat, rhoMin);# 1 "/home/chef2/andy/OpenFOAM/release/v2312/OpenFOAM-v2312/applications/solvers/multiphase/cavitatingFoam/alphavPsi.H" 1{ alphav=clamp((rho - rholSat)/(rhovSat - rholSat), zero_one{});alphal=1.0 - alphav;Info<< "max-min alphav: "<< max(alphav).value()<< " "<< min(alphav).value()<< endl;psiModel-> correct()
Definition: pEqn.H:63
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
dimensionedScalar pow3(const dimensionedScalar &ds)
tmp< surfaceScalarField > absolute(const tmp< surfaceScalarField > &tphi, const volVectorField &U)
Return the given relative flux in absolute form.
Definition: fvcMeshPhi.C:183
U
Definition: pEqn.H:72
volScalarField & bound(volScalarField &, const dimensionedScalar &lowerBound)
Bound the given scalar field if it has gone unbounded.
Definition: bound.C:29
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
tmp< fvMatrix< Type > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvmLaplacian.C:41
Base-class for all transport models used by the incompressible turbulence models. ...
scalar epsilon
Nothing to be read.
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:51
Interface to run-time selectable methods to calculate the distance-to-wall and normal-to-wall fields...
Definition: wallDist.H:71
virtual void correct()
Solve the turbulence equations and correct the turbulence viscosity.
Definition: kL.C:403
zeroField divU
Definition: alphaSuSp.H:3
A class for managing temporary objects.
Definition: HashPtrTable.H:50
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
static options & New(const fvMesh &mesh)
Construct fvOptions and register to database if not present.
Definition: fvOptions.C:96
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Do not request registration (bool: false)
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
scalar nut
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127