LRR.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "LRR.H"
30 #include "fvOptions.H"
31 #include "wallFvPatch.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace RASModels
38 {
39 
40 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
41 
42 template<class BasicTurbulenceModel>
44 {
45  this->nut_ = this->Cmu_*sqr(k_)/epsilon_;
46  this->nut_.correctBoundaryConditions();
47  fv::options::New(this->mesh_).correct(this->nut_);
48 
49  BasicTurbulenceModel::correctNut();
50 }
51 
52 
53 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54 
55 template<class BasicTurbulenceModel>
57 (
58  const alphaField& alpha,
59  const rhoField& rho,
60  const volVectorField& U,
61  const surfaceScalarField& alphaRhoPhi,
62  const surfaceScalarField& phi,
63  const transportModel& transport,
64  const word& propertiesName,
65  const word& type
66 )
67 :
68  ReynoldsStress<RASModel<BasicTurbulenceModel>>
69  (
70  type,
71  alpha,
72  rho,
73  U,
74  alphaRhoPhi,
75  phi,
76  transport,
77  propertiesName
78  ),
79 
80  Cmu_
81  (
82  dimensioned<scalar>::getOrAddToDict
83  (
84  "Cmu",
85  this->coeffDict_,
86  0.09
87  )
88  ),
89  C1_
90  (
91  dimensioned<scalar>::getOrAddToDict
92  (
93  "C1",
94  this->coeffDict_,
95  1.8
96  )
97  ),
98  C2_
99  (
100  dimensioned<scalar>::getOrAddToDict
101  (
102  "C2",
103  this->coeffDict_,
104  0.6
105  )
106  ),
107  Ceps1_
108  (
109  dimensioned<scalar>::getOrAddToDict
110  (
111  "Ceps1",
112  this->coeffDict_,
113  1.44
114  )
115  ),
116  Ceps2_
117  (
118  dimensioned<scalar>::getOrAddToDict
119  (
120  "Ceps2",
121  this->coeffDict_,
122  1.92
123  )
124  ),
125  Cs_
126  (
127  dimensioned<scalar>::getOrAddToDict
128  (
129  "Cs",
130  this->coeffDict_,
131  0.25
132  )
133  ),
134  Ceps_
135  (
136  dimensioned<scalar>::getOrAddToDict
137  (
138  "Ceps",
139  this->coeffDict_,
140  0.15
141  )
142  ),
143 
144  wallReflection_
145  (
146  Switch::getOrAddToDict
147  (
148  "wallReflection",
149  this->coeffDict_,
150  true
151  )
152  ),
153  kappa_
154  (
155  dimensioned<scalar>::getOrAddToDict
156  (
157  "kappa",
158  this->coeffDict_,
159  0.41
160  )
161  ),
162  Cref1_
163  (
164  dimensioned<scalar>::getOrAddToDict
165  (
166  "Cref1",
167  this->coeffDict_,
168  0.5
169  )
170  ),
171  Cref2_
172  (
173  dimensioned<scalar>::getOrAddToDict
174  (
175  "Cref2",
176  this->coeffDict_,
177  0.3
178  )
179  ),
180 
181  k_
182  (
183  IOobject
184  (
185  "k",
186  this->runTime_.timeName(),
187  this->mesh_,
188  IOobject::NO_READ,
189  IOobject::AUTO_WRITE
190  ),
191  0.5*tr(this->R_)
192  ),
193  epsilon_
194  (
195  IOobject
196  (
197  "epsilon",
198  this->runTime_.timeName(),
199  this->mesh_,
200  IOobject::MUST_READ,
201  IOobject::AUTO_WRITE
202  ),
203  this->mesh_
204  )
205 {
206  if (type == typeName)
207  {
208  this->printCoeffs(type);
209 
210  this->boundNormalStress(this->R_);
211  bound(epsilon_, this->epsilonMin_);
212  k_ = 0.5*tr(this->R_);
213  }
214 }
215 
216 
217 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
218 
219 template<class BasicTurbulenceModel>
221 {
223  {
224  Cmu_.readIfPresent(this->coeffDict());
225  C1_.readIfPresent(this->coeffDict());
226  C2_.readIfPresent(this->coeffDict());
227  Ceps1_.readIfPresent(this->coeffDict());
228  Ceps2_.readIfPresent(this->coeffDict());
229  Cs_.readIfPresent(this->coeffDict());
230  Ceps_.readIfPresent(this->coeffDict());
231 
232  wallReflection_.readIfPresent("wallReflection", this->coeffDict());
233  kappa_.readIfPresent(this->coeffDict());
234  Cref1_.readIfPresent(this->coeffDict());
235  Cref2_.readIfPresent(this->coeffDict());
236 
237  return true;
238  }
239 
240  return false;
241 }
242 
243 
244 template<class BasicTurbulenceModel>
246 {
248  (
250  (
251  "DREff",
252  (Cs_*(this->k_/this->epsilon_))*this->R_ + I*this->nu()
253  )
254  );
255 }
256 
257 
258 template<class BasicTurbulenceModel>
260 {
262  (
264  (
265  "DepsilonEff",
266  (Ceps_*(this->k_/this->epsilon_))*this->R_ + I*this->nu()
267  )
268  );
269 }
270 
271 
272 template<class BasicTurbulenceModel>
274 {
275  if (!this->turbulence_)
276  {
277  return;
278  }
279 
280  // Local references
281  const alphaField& alpha = this->alpha_;
282  const rhoField& rho = this->rho_;
283  const surfaceScalarField& alphaRhoPhi = this->alphaRhoPhi_;
284  const volVectorField& U = this->U_;
285  volSymmTensorField& R = this->R_;
286  fv::options& fvOptions(fv::options::New(this->mesh_));
287 
289 
291  const volTensorField& gradU = tgradU();
292 
293  volSymmTensorField P(-twoSymm(R & gradU));
294  volScalarField G(this->GName(), 0.5*mag(tr(P)));
295 
296  // Update epsilon and G at the wall
297  epsilon_.boundaryFieldRef().updateCoeffs();
298  // Push any changed cell values to coupled neighbours
299  epsilon_.boundaryFieldRef().template evaluateCoupled<coupledFvPatch>();
300 
301  // Dissipation equation
302  tmp<fvScalarMatrix> epsEqn
303  (
304  fvm::ddt(alpha, rho, epsilon_)
305  + fvm::div(alphaRhoPhi, epsilon_)
306  - fvm::laplacian(alpha*rho*DepsilonEff(), epsilon_)
307  ==
308  Ceps1_*alpha*rho*G*epsilon_/k_
309  - fvm::Sp(Ceps2_*alpha*rho*epsilon_/k_, epsilon_)
310  + fvOptions(alpha, rho, epsilon_)
311  );
312 
313  epsEqn.ref().relax();
314  fvOptions.constrain(epsEqn.ref());
315  epsEqn.ref().boundaryManipulate(epsilon_.boundaryFieldRef());
316  solve(epsEqn);
317  fvOptions.correct(epsilon_);
318  bound(epsilon_, this->epsilonMin_);
319 
320 
321  // Correct the trace of the tensorial production to be consistent
322  // with the near-wall generation from the wall-functions
323  const fvPatchList& patches = this->mesh_.boundary();
324 
325  forAll(patches, patchi)
326  {
327  const fvPatch& curPatch = patches[patchi];
328 
329  if (isA<wallFvPatch>(curPatch))
330  {
331  forAll(curPatch, facei)
332  {
333  label celli = curPatch.faceCells()[facei];
334  P[celli] *= min
335  (
336  G[celli]/(0.5*mag(tr(P[celli])) + SMALL),
337  1.0
338  );
339  }
340  }
341  }
342 
343  // Reynolds stress equation
344  tmp<fvSymmTensorMatrix> REqn
345  (
346  fvm::ddt(alpha, rho, R)
347  + fvm::div(alphaRhoPhi, R)
348  - fvm::laplacian(alpha*rho*DREff(), R)
349  + fvm::Sp(C1_*alpha*rho*epsilon_/k_, R)
350  ==
351  alpha*rho*P
352  - (2.0/3.0*(1 - C1_)*I)*alpha*rho*epsilon_
353  - C2_*alpha*rho*dev(P)
354  + fvOptions(alpha, rho, R)
355  );
356 
357  // Optionally add wall-refection term
358  if (wallReflection_)
359  {
360  const volVectorField& n_(wallDist::New(this->mesh_).n());
361  const volScalarField& y_(wallDist::New(this->mesh_).y());
362 
363  const volSymmTensorField reflect
364  (
365  Cref1_*R - ((Cref2_*C2_)*(k_/epsilon_))*dev(P)
366  );
367 
368  REqn.ref() +=
369  ((3*pow(Cmu_, 0.75)/kappa_)*(alpha*rho*sqrt(k_)/y_))
370  *devSymm((n_ & reflect)*n_);
371  }
372 
373  REqn.ref().relax();
374  fvOptions.constrain(REqn.ref());
375  solve(REqn);
376  fvOptions.correct(R);
377 
378  this->boundNormalStress(R);
379 
380  k_ = 0.5*tr(R);
381 
382  correctNut();
383 
384  // Correct wall shear-stresses when applying wall-functions
385  this->correctWallShearStress(R);
386 }
387 
388 
389 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
390 
391 } // End namespace RASModels
392 } // End namespace Foam
393 
394 // ************************************************************************* //
void correct(GeometricField< Type, PatchField, GeoMesh > &field)
Apply correction to field.
GeometricField< symmTensor, fvPatchField, volMesh > volSymmTensorField
Definition: volFieldsFwd.H:85
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:47
volScalarField epsilon_
Definition: LRR.H:144
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
tmp< volSymmTensorField > DREff() const
Return the effective diffusivity for R.
Definition: LRR.C:238
static const wallDist & New(const fvMesh &mesh, Args &&... args)
Get existing or create a new MeshObject. Registered with typeName.
Definition: MeshObject.C:53
const dimensionedScalar G
Newtonian constant of gravitation.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
dimensionedScalar sqrt(const dimensionedScalar &ds)
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, any/none. Also accepts 0/1 as a string and shortcuts t/f, y/n.
Definition: Switch.H:77
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.
virtual bool read()
Read model coefficients if they have changed.
Definition: LRR.C:213
Finite-volume options.
Definition: fvOptions.H:51
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:82
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
tmp< volSymmTensorField > DepsilonEff() const
Return the effective diffusivity for epsilon.
Definition: LRR.C:252
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
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:81
word timeName
Definition: getTimeIndex.H:3
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
scalar y
Launder, Reece and Rodi Reynolds-stress turbulence model for incompressible and compressible flows...
Definition: LRR.H:99
dimensionedSymmTensor dev(const dimensionedSymmTensor &dt)
static const Identity< scalar > I
Definition: Identity.H:100
virtual void correctNut()
Update the eddy-viscosity.
Definition: LRR.C:36
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual const labelUList & faceCells() const
Return faceCells.
Definition: fvPatch.C:107
tmp< fvMatrix< Type > > ddt(const GeometricField< Type, fvPatchField, volMesh > &vf)
Definition: fvmDdt.C:41
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
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
zeroField Sp(const Foam::zero, const GeometricField< Type, fvPatchField, volMesh > &)
A no-op source.
SolverPerformance< Type > solve(faMatrix< Type > &, const dictionary &solverControls)
Solve returning the solution statistics given convergence tolerance.
void boundNormalStress(volSymmTensorField &R) const
tmp< fvMatrix< Type > > div(const surfaceScalarField &flux, const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvmDiv.C:41
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
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
virtual void correct()
Solve the turbulence equations and correct eddy-Viscosity and.
Definition: LRR.C:266
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
#define R(A, B, C, D, E, F, K, M)
tmp< fvMatrix< Type > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvmLaplacian.C:41
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
Base-class for all transport models used by the incompressible turbulence models. ...
const polyBoundaryMesh & patches
label n
A class for managing temporary objects.
Definition: HashPtrTable.H:50
volScalarField k_
Definition: LRR.H:143
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
volScalarField & nu
dimensionedScalar epsilonMin_
Lower limit of epsilon.
Definition: RASModel.H:114
Namespace for OpenFOAM.
Reynolds-stress turbulence model base class.