ReynoldsStress.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) 2015-2021 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 "ReynoldsStress.H"
27 #include "fvc.H"
28 #include "fvm.H"
29 #include "wallFvPatch.H"
30 
31 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
32 
33 template<class BasicMomentumTransportModel>
35 (
37 ) const
38 {
39  scalar kMin = this->kMin_.value();
40 
41  R.max
42  (
44  (
45  "zero",
46  R.dimensions(),
48  (
49  kMin, -great, -great,
50  kMin, -great,
51  kMin
52  )
53  )
54  );
55 }
56 
57 
58 template<class BasicMomentumTransportModel>
60 (
62 ) const
63 {
64  const fvPatchList& patches = this->mesh_.boundary();
65 
66  volSymmTensorField::Boundary& RBf = R.boundaryFieldRef();
67 
68  forAll(patches, patchi)
69  {
70  const fvPatch& curPatch = patches[patchi];
71 
72  if (isA<wallFvPatch>(curPatch))
73  {
74  symmTensorField& Rw = RBf[patchi];
75 
76  const scalarField& nutw = this->nut_.boundaryField()[patchi];
77 
78  const vectorField snGradU
79  (
80  this->U_.boundaryField()[patchi].snGrad()
81  );
82 
83  const vectorField& faceAreas
84  = this->mesh_.Sf().boundaryField()[patchi];
85 
86  const scalarField& magFaceAreas
87  = this->mesh_.magSf().boundaryField()[patchi];
88 
89  forAll(curPatch, facei)
90  {
91  // Calculate near-wall velocity gradient
92  const tensor gradUw
93  = (faceAreas[facei]/magFaceAreas[facei])*snGradU[facei];
94 
95  // Set the wall Reynolds-stress to the near-wall shear-stress
96  // Note: the spherical part of the normal stress is included in
97  // the pressure
98  Rw[facei] = -nutw[facei]*2*dev(symm(gradUw));
99  }
100  }
101  }
102 }
103 
104 
105 template<class BasicMomentumTransportModel>
108 {
110  (
112  (
113  this->R_,
114  dimVolume*this->rho_.dimensions()*this->R_.dimensions()/dimTime
115  )
116  );
117 }
118 
119 
120 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
121 
122 template<class BasicMomentumTransportModel>
124 (
125  const word& modelName,
126  const alphaField& alpha,
127  const rhoField& rho,
128  const volVectorField& U,
129  const surfaceScalarField& alphaRhoPhi,
130  const surfaceScalarField& phi,
131  const transportModel& transport
132 )
133 :
134  BasicMomentumTransportModel
135  (
136  modelName,
137  alpha,
138  rho,
139  U,
140  alphaRhoPhi,
141  phi,
142  transport
143  ),
144 
145  couplingFactor_
146  (
148  (
149  "couplingFactor",
150  this->coeffDict_,
151  0.0
152  )
153  ),
154 
155  R_
156  (
157  IOobject
158  (
159  IOobject::groupName("R", alphaRhoPhi.group()),
160  this->runTime_.timeName(),
161  this->mesh_,
162  IOobject::MUST_READ,
163  IOobject::AUTO_WRITE
164  ),
165  this->mesh_
166  ),
167 
168  nut_
169  (
170  IOobject
171  (
172  IOobject::groupName("nut", alphaRhoPhi.group()),
173  this->runTime_.timeName(),
174  this->mesh_,
175  IOobject::MUST_READ,
176  IOobject::AUTO_WRITE
177  ),
178  this->mesh_
179  )
180 {
181  if (couplingFactor_.value() < 0.0 || couplingFactor_.value() > 1.0)
182  {
184  << "couplingFactor = " << couplingFactor_
185  << " is not in range 0 - 1" << nl
186  << exit(FatalError);
187  }
188 }
189 
190 
191 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
192 
193 template<class BasicMomentumTransportModel>
195 {
197 }
198 
199 
200 template<class BasicMomentumTransportModel>
203 {
204  return R_;
205 }
206 
207 
208 template<class BasicMomentumTransportModel>
211 {
212  tmp<Foam::volScalarField> tk(0.5*tr(R_));
213  tk.ref().rename("k");
214  return tk;
215 }
216 
217 
218 template<class BasicMomentumTransportModel>
221 {
223  (
224  IOobject::groupName("devTau", this->alphaRhoPhi_.group()),
225  this->alpha_*this->rho_*R_
226  - (this->alpha_*this->rho_*this->nu())
227  *dev(twoSymm(fvc::grad(this->U_)))
228  );
229 }
230 
231 
232 template<class BasicMomentumTransportModel>
233 template<class RhoFieldType>
236 (
237  const RhoFieldType& rho,
238  volVectorField& U
239 ) const
240 {
241  if (couplingFactor_.value() > 0.0)
242  {
243  return
244  (
246  (
247  (1.0 - couplingFactor_)*this->alpha_*rho*this->nut(),
248  U,
249  "laplacian(nuEff,U)"
250  )
251  + fvc::div
252  (
253  this->alpha_*rho*R_
254  + couplingFactor_
255  *this->alpha_*rho*this->nut()*fvc::grad(U),
256  "div(devTau)"
257  )
258  - fvc::div(this->alpha_*rho*this->nu()*dev2(T(fvc::grad(U))))
259  - fvm::laplacian(this->alpha_*rho*this->nuEff(), U)
260  );
261  }
262  else
263  {
264  return
265  (
267  (
268  this->alpha_*rho*this->nut(),
269  U,
270  "laplacian(nuEff,U)"
271  )
272  + fvc::div(this->alpha_*rho*R_)
273  - fvc::div(this->alpha_*rho*this->nu()*dev2(T(fvc::grad(U))))
274  - fvm::laplacian(this->alpha_*rho*this->nuEff(), U)
275  );
276  }
277 }
278 
279 
280 template<class BasicMomentumTransportModel>
283 (
284  volVectorField& U
285 ) const
286 {
287  return DivDevRhoReff(this->rho_, U);
288 }
289 
290 
291 template<class BasicMomentumTransportModel>
294 (
295  const volScalarField& rho,
296  volVectorField& U
297 ) const
298 {
299  return DivDevRhoReff(rho, U);
300 }
301 
302 
303 template<class BasicMomentumTransportModel>
305 {
306  correctNut();
307 }
308 
309 
310 template<class BasicMomentumTransportModel>
312 {
314 }
315 
316 
317 // ************************************************************************* //
void correctWallShearStress(volSymmTensorField &R) const
static word group(const word &name)
Return group (extension part of name)
Definition: IOobject.C:134
virtual tmp< fvVectorMatrix > divDevTau(volVectorField &U) const
Return the source term for the momentum equation.
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:52
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
ReynoldsStress(const word &modelName, const alphaField &alpha, const rhoField &rho, const volVectorField &U, const surfaceScalarField &alphaRhoPhi, const surfaceScalarField &phi, const transportModel &transport)
Construct from components.
virtual tmp< volSymmTensorField > sigma() const
Return the Reynolds stress tensor [m^2/s^2].
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
virtual tmp< fvSymmTensorMatrix > RSource() const
Source term for the R equation.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
tmp< fvVectorMatrix > DivDevRhoReff(const RhoFieldType &rho, volVectorField &U) const
Return the source term for the momentum equation.
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcDiv.C:47
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:62
virtual void correct()=0
Solve the turbulence equations and correct the turbulence viscosity.
fvMatrix< symmTensor > fvSymmTensorMatrix
Definition: fvMatricesFwd.H:47
Generic dimensioned Type class.
patches[0]
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
tmp< GeometricField< Type, fvPatchField, volMesh > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcLaplacian.C:45
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
const dimensionSet dimTime
const dimensionSet & dimensions() const
Return dimensions.
virtual bool read()=0
Re-read model coefficients if they have changed.
dimensionedSymmTensor dev(const dimensionedSymmTensor &dt)
autoPtr< BasicCompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleMomentumTransportModel::transportModel &transport)
SymmTensor< scalar > symmTensor
SymmTensor of scalars.
Definition: symmTensor.H:48
A class for handling words, derived from string.
Definition: word.H:59
Info<< "Predicted p max-min : "<< max(p).value()<< " "<< min(p).value()<< endl;rho==max(rho0+psi *p, rhoMin);# 1 "/home/ubuntu/OpenFOAM-9/applications/solvers/multiphase/cavitatingFoam/alphavPsi.H" 1{ alphav=max(min((rho - rholSat)/(rhovSat - rholSat), scalar(1)), scalar(0));alphal=1.0 - alphav;Info<< "max-min alphav: "<< max(alphav).value()<< " "<< min(alphav).value()<< endl;psiModel-> correct()
Definition: pEqn.H:68
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
virtual void validate()
Validate the turbulence fields after construction.
void boundNormalStress(volSymmTensorField &R) const
static const char nl
Definition: Ostream.H:260
BasicMomentumTransportModel::rhoField rhoField
Definition: LESModel.H:99
virtual void rename(const word &newName)
Rename.
Definition: regIOobject.C:376
const volScalarField & T
BasicMomentumTransportModel::transportModel transportModel
Definition: LESModel.H:100
label patchi
dimensionedSymmTensor dev2(const dimensionedSymmTensor &dt)
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
dimensionedSymmTensor symm(const dimensionedSymmTensor &dt)
virtual tmp< volSymmTensorField > devTau() const
Return the effective stress tensor.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:70
void max(const dimensioned< Type > &)
virtual tmp< volScalarField > k() const
Return the turbulence kinetic energy.
const dimensionSet dimVolume
BasicMomentumTransportModel::alphaField alphaField
Definition: LESModel.H:98
A class for managing temporary objects.
Definition: PtrList.H:53
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
scalar nut