LRR.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "LRR.H"
27 #include "fvModels.H"
28 #include "fvConstraints.H"
29 #include "wallDist.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace RASModels
36 {
37 
38 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
39 
40 template<class BasicMomentumTransportModel>
42 {
43  tmp<volScalarField> tCmuk2(Cmu_*sqr(k_));
44  epsilon_ = max(epsilon_, tCmuk2()/(this->nutMaxCoeff_*this->nu()));
45  return tCmuk2;
46 }
47 
48 
49 template<class BasicMomentumTransportModel>
51 {
52  this->nut_ = boundEpsilon()/epsilon_;
53  this->nut_.correctBoundaryConditions();
54  fvConstraints::New(this->mesh_).constrain(this->nut_);
55 }
56 
57 
58 template<class BasicMomentumTransportModel>
60 {
61  return tmp<fvScalarMatrix>
62  (
63  new fvScalarMatrix
64  (
65  epsilon_,
66  dimVolume*this->rho_.dimensions()*epsilon_.dimensions()/dimTime
67  )
68  );
69 }
70 
71 
72 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
73 
74 template<class BasicMomentumTransportModel>
76 (
77  const alphaField& alpha,
78  const rhoField& rho,
79  const volVectorField& U,
80  const surfaceScalarField& alphaRhoPhi,
81  const surfaceScalarField& phi,
82  const viscosity& viscosity,
83  const word& type
84 )
85 :
86  ReynoldsStress<RASModel<BasicMomentumTransportModel>>
87  (
88  type,
89  alpha,
90  rho,
91  U,
92  alphaRhoPhi,
93  phi,
94  viscosity
95  ),
96 
97  Cmu_("Cmu", this->typeDict(type), 0.09),
98  C1_("C1", this->typeDict(type), 1.8),
99  C2_("C2", this->typeDict(type), 0.6),
100  Ceps1_("Ceps1", this->typeDict(type), 1.44),
101  Ceps2_("Ceps2", this->typeDict(type), 1.92),
102  Cs_("Cs", this->typeDict(type), 0.25),
103  Ceps_("Ceps", this->typeDict(type), 0.15),
104 
105  wallReflection_
106  (
107  this->typeDict(type).template lookupOrDefault<Switch>
108  (
109  "wallReflection",
110  true
111  )
112  ),
113  kappa_("kappa", this->typeDict(type), 0.41),
114  Cref1_("Cref1", this->typeDict(type), 0.5),
115  Cref2_("Cref2", this->typeDict(type), 0.3),
116 
117  k_
118  (
119  IOobject
120  (
121  this->groupName("k"),
122  this->runTime_.name(),
123  this->mesh_,
124  IOobject::NO_READ,
125  IOobject::AUTO_WRITE
126  ),
127  0.5*tr(this->R_)
128  ),
129  epsilon_
130  (
131  IOobject
132  (
133  this->groupName("epsilon"),
134  this->runTime_.name(),
135  this->mesh_,
136  IOobject::MUST_READ,
137  IOobject::AUTO_WRITE
138  ),
139  this->mesh_,
140  dimensions::turbulentEpsilon
141  )
142 {
143  if (type == typeName)
144  {
145  this->boundNormalStress(this->R_);
146  boundEpsilon();
147  k_ = 0.5*tr(this->R_);
148  }
149 }
150 
151 
152 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
153 
154 template<class BasicMomentumTransportModel>
156 {
158  {
159  Cmu_.readIfPresent(this->typeDict());
160  C1_.readIfPresent(this->typeDict());
161  C2_.readIfPresent(this->typeDict());
162  Ceps1_.readIfPresent(this->typeDict());
163  Ceps2_.readIfPresent(this->typeDict());
164  Cs_.readIfPresent(this->typeDict());
165  Ceps_.readIfPresent(this->typeDict());
166 
167  wallReflection_.readIfPresent("wallReflection", this->typeDict());
168  kappa_.readIfPresent(this->typeDict());
169  Cref1_.readIfPresent(this->typeDict());
170  Cref2_.readIfPresent(this->typeDict());
171 
172  return true;
173  }
174  else
175  {
176  return false;
177  }
178 }
179 
180 
181 template<class BasicMomentumTransportModel>
183 {
185  (
186  "DREff",
187  (Cs_*(this->k_/this->epsilon_))*this->R_ + I*this->nu()
188  );
189 }
190 
191 
192 template<class BasicMomentumTransportModel>
194 {
196  (
197  "DepsilonEff",
198  (Ceps_*(this->k_/this->epsilon_))*this->R_ + I*this->nu()
199  );
200 }
201 
202 
203 template<class BasicMomentumTransportModel>
205 {
206  if (!this->turbulence_)
207  {
208  return;
209  }
210 
211  // Local references
212  const alphaField& alpha = this->alpha_;
213  const rhoField& rho = this->rho_;
214  const surfaceScalarField& alphaRhoPhi = this->alphaRhoPhi_;
215  const volVectorField& U = this->U_;
216  volSymmTensorField& R = this->R_;
217  const Foam::fvModels& fvModels(Foam::fvModels::New(this->mesh_));
219  (
220  Foam::fvConstraints::New(this->mesh_)
221  );
222 
224 
226  const volTensorField& gradU = tgradU();
227 
228  volSymmTensorField P(-twoSymm(R & gradU));
229  volScalarField G(this->GName(), 0.5*mag(tr(P)));
230 
231  // Update epsilon and G at the wall
232  epsilon_.boundaryFieldRef().updateCoeffs();
233 
234  // Dissipation equation
235  tmp<fvScalarMatrix> epsEqn
236  (
237  fvm::ddt(alpha, rho, epsilon_)
238  + fvm::div(alphaRhoPhi, epsilon_)
239  - fvm::laplacian(alpha*rho*DepsilonEff(), epsilon_)
240  ==
241  Ceps1_*alpha*rho*G*epsilon_/k_
242  - fvm::Sp(Ceps2_*alpha*rho*epsilon_/k_, epsilon_)
243  + epsilonSource()
244  + fvModels.source(alpha, rho, epsilon_)
245  );
246 
247  epsEqn.ref().relax();
248  fvConstraints.constrain(epsEqn.ref());
249  epsEqn.ref().boundaryManipulate(epsilon_.boundaryFieldRef());
250  solve(epsEqn);
251  fvConstraints.constrain(epsilon_);
252  boundEpsilon();
253 
254 
255  // Correct the trace of the tensorial production to be consistent
256  // with the near-wall generation from the wall-functions
257  const fvPatchList& patches = this->mesh_.boundary();
258 
260  {
261  const fvPatch& curPatch = patches[patchi];
262 
263  if (isA<wallFvPatch>(curPatch))
264  {
265  forAll(curPatch, facei)
266  {
267  label celli = curPatch.faceCells()[facei];
268  P[celli] *= min
269  (
270  G[celli]/(0.5*mag(tr(P[celli])) + small),
271  1.0
272  );
273  }
274  }
275  }
276 
277  // Reynolds stress equation
279  (
280  fvm::ddt(alpha, rho, R)
281  + fvm::div(alphaRhoPhi, R)
282  - fvm::laplacian(alpha*rho*DREff(), R)
283  + fvm::Sp(C1_*alpha*rho*epsilon_/k_, R)
284  ==
285  alpha*rho*P
286  - (2.0/3.0*(1 - C1_)*I)*alpha*rho*epsilon_
287  - C2_*alpha*rho*dev(P)
288  + this->RSource()
289  + fvModels.source(alpha, rho, R)
290  );
291 
292  // Optionally add wall-refection term
293  if (wallReflection_)
294  {
295  const volVectorField& n(wallDist::New(this->mesh_).n());
296  const volScalarField& y(wallDist::New(this->mesh_).y());
297 
299  (
300  Cref1_*R - ((Cref2_*C2_)*(k_/epsilon_))*dev(P)
301  );
302 
303  REqn.ref() +=
304  ((3*pow(Cmu_, 0.75)/kappa_)*(alpha*rho*sqrt(k_)/y))
305  *dev(symm((n & reflect)*n));
306  }
307 
308  REqn.ref().relax();
309  fvConstraints.constrain(REqn.ref());
310  solve(REqn);
312 
313  this->boundNormalStress(R);
314 
315  k_ = 0.5*tr(R);
316 
317  correctNut();
318 
319  // Correct wall shear-stresses when applying wall-functions
320  this->correctWallShearStress(R);
321 }
322 
323 
324 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
325 
326 } // End namespace RASModels
327 } // End namespace Foam
328 
329 // ************************************************************************* //
scalar y
label n
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
static fvConstraints & New(const word &name, const fvMesh &mesh)
Construct and return the named DemandDrivenMeshObject.
Generic GeometricField class.
static tmp< GeometricField< Type, GeoMesh, PrimitiveField > > New(const word &name, const Internal &, const PtrList< Patch > &, const HashPtrTable< Source > &=HashPtrTable< Source >())
Return a temporary field constructed from name,.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
Templated abstract base class for RAS turbulence models.
Definition: RASModel.H:56
BasicMomentumTransportModel::alphaField alphaField
Definition: LRR.H:146
tmp< volSymmTensorField > DepsilonEff() const
Return the effective diffusivity for epsilon.
Definition: LRR.C:193
virtual tmp< fvScalarMatrix > epsilonSource() const
Source term for the epsilon equation.
Definition: LRR.C:59
volScalarField k_
Definition: LRR.H:128
LRR(const alphaField &alpha, const rhoField &rho, const volVectorField &U, const surfaceScalarField &alphaRhoPhi, const surfaceScalarField &phi, const viscosity &viscosity, const word &type=typeName)
Construct from components.
Definition: LRR.C:76
virtual void correct()
Solve the turbulence equations and correct eddy-Viscosity and.
Definition: LRR.C:204
tmp< volScalarField > boundEpsilon()
Bound epsilon and return Cmu*sqr(k) for nut.
Definition: LRR.C:41
tmp< volSymmTensorField > DREff() const
Return the effective diffusivity for R.
Definition: LRR.C:182
virtual void correctNut()
Correct the eddy-viscosity nut.
Definition: LRR.C:50
virtual bool read()
Read model coefficients if they have changed.
Definition: LRR.C:155
BasicMomentumTransportModel::rhoField rhoField
Definition: LRR.H:147
Reynolds-stress turbulence model base class.
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
Finite volume constraints.
Definition: fvConstraints.H:68
bool constrain(fvMatrix< Type > &eqn) const
Apply constraints to an equation.
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvMatrix.H:118
Finite volume models.
Definition: fvModels.H:69
tmp< fvMatrix< Type > > source(const VolField< Type > &field) const
Return source for an equation.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:58
virtual const labelUList & faceCells() const
Return faceCells.
Definition: fvPatch.C:79
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:197
Template function which returns the un-mangled name of a given type. Useful for types which do not ha...
Abstract base class for all fluid physical properties.
Definition: viscosity.H:50
A class for handling words, derived from string.
Definition: word.H:63
Foam::fvConstraints & fvConstraints(Foam::fvConstraints::New(mesh))
Foam::fvModels & fvModels(Foam::fvModels::New(mesh))
label patchi
const fvPatchList & patches
U
Definition: pEqn.H:72
rho
Definition: pEqn.H:1
volScalarField alpha(IOobject("alpha", runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
void correct(const RdeltaTType &rDeltaT, const RhoType &rho, volScalarField &psi, const surfaceScalarField &phiCorr, const SpType &Sp)
const dimensionedScalar G
Newtonian constant of gravitation.
const dimensionSet turbulentEpsilon
tmp< VolField< typename outerProduct< vector, Type >::type > > grad(const SurfaceField< Type > &ssf)
Definition: fvcGrad.C:46
tmp< fvMatrix< Type > > laplacian(const VolField< Type > &vf, const word &name)
Definition: fvmLaplacian.C:47
tmp< fvMatrix< Type > > div(const surfaceScalarField &flux, const VolField< Type > &vf, const word &name)
Definition: fvmDiv.C:48
tmp< fvMatrix< Type > > Sp(const volScalarField::Internal &, const VolField< Type > &)
tmp< fvMatrix< Type > > ddt(const VolField< Type > &vf)
Definition: fvmDdt.C:46
void reflect(barycentric &coordinates)
Reflection transform. Corrects the coordinates when the track moves.
Definition: tracking.C:1027
Namespace for OpenFOAM.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
const dimensionSet & dimVolume
Definition: dimensions.C:282
static const Identity< scalar > I
Definition: Identity.H:93
void tr(pointPatchField< scalar > &, const pointPatchField< tensor > &)
tmp< DimensionedField< typename outerProduct< Type, Type >::type, GeoMesh, Field >> sqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
const dimensionSet & dimTime
Definition: dimensions.C:277
void dev(pointPatchField< tensor > &, const pointPatchField< tensor > &)
dimensioned< Type > min(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
void symm(pointPatchField< tensor > &, const pointPatchField< tensor > &)
static scalar R(const scalar a, const scalar x)
Definition: invIncGamma.C:102
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
tmp< DimensionedField< typename powProduct< Type, r >::type, GeoMesh, Field > > pow(const DimensionedField< Type, GeoMesh, PrimitiveField > &df, typename powProduct< Type, r >::type)
tmp< DimensionedField< scalar, GeoMesh, Field > > mag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
void twoSymm(pointPatchField< tensor > &, const pointPatchField< tensor > &)
void sqrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
SolverPerformance< Type > solve(fvMatrix< Type > &, const word &)
Solve returning the solution statistics given convergence tolerance.