ReynoldsStress.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 | Copyright (C) 2015-2016 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 BasicTurbulenceModel>
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 BasicTurbulenceModel>
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  tensor gradUw
93  = (faceAreas[facei]/magFaceAreas[facei])*snGradU[facei];
94 
95  // Calculate near-wall shear-stress tensor
96  tensor tauw = -nutw[facei]*2*dev(symm(gradUw));
97 
98  // Reset the shear components of the stress tensor
99  Rw[facei].xy() = tauw.xy();
100  Rw[facei].xz() = tauw.xz();
101  Rw[facei].yz() = tauw.yz();
102  }
103  }
104  }
105 }
106 
107 
108 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
109 
110 template<class BasicTurbulenceModel>
112 (
113  const word& modelName,
114  const alphaField& alpha,
115  const rhoField& rho,
116  const volVectorField& U,
117  const surfaceScalarField& alphaRhoPhi,
118  const surfaceScalarField& phi,
119  const transportModel& transport,
120  const word& propertiesName
121 )
122 :
123  BasicTurbulenceModel
124  (
125  modelName,
126  alpha,
127  rho,
128  U,
129  alphaRhoPhi,
130  phi,
131  transport,
132  propertiesName
133  ),
134 
135  couplingFactor_
136  (
138  (
139  "couplingFactor",
140  this->coeffDict_,
141  0.0
142  )
143  ),
144 
145  R_
146  (
147  IOobject
148  (
149  IOobject::groupName("R", U.group()),
150  this->runTime_.timeName(),
151  this->mesh_,
152  IOobject::MUST_READ,
153  IOobject::AUTO_WRITE
154  ),
155  this->mesh_
156  ),
157 
158  nut_
159  (
160  IOobject
161  (
162  IOobject::groupName("nut", U.group()),
163  this->runTime_.timeName(),
164  this->mesh_,
165  IOobject::MUST_READ,
166  IOobject::AUTO_WRITE
167  ),
168  this->mesh_
169  )
170 {
171  if (couplingFactor_.value() < 0.0 || couplingFactor_.value() > 1.0)
172  {
174  << "couplingFactor = " << couplingFactor_
175  << " is not in range 0 - 1" << nl
176  << exit(FatalError);
177  }
178 }
179 
180 
181 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
182 
183 template<class BasicTurbulenceModel>
185 {
187 }
188 
189 
190 template<class BasicTurbulenceModel>
193 {
194  return R_;
195 }
196 
197 
198 template<class BasicTurbulenceModel>
201 {
202  tmp<Foam::volScalarField> tk(0.5*tr(R_));
203  tk.ref().rename("k");
204  return tk;
205 }
206 
207 
208 template<class BasicTurbulenceModel>
211 {
213  (
215  (
216  IOobject
217  (
218  IOobject::groupName("devRhoReff", this->U_.group()),
219  this->runTime_.timeName(),
220  this->mesh_,
221  IOobject::NO_READ,
222  IOobject::NO_WRITE
223  ),
224  this->alpha_*this->rho_*R_
225  - (this->alpha_*this->rho_*this->nu())
226  *dev(twoSymm(fvc::grad(this->U_)))
227  )
228  );
229 }
230 
231 
232 template<class BasicTurbulenceModel>
235 (
236  volVectorField& U
237 ) const
238 {
239  if (couplingFactor_.value() > 0.0)
240  {
241  return
242  (
244  (
245  (1.0 - couplingFactor_)*this->alpha_*this->rho_*this->nut(),
246  U,
247  "laplacian(nuEff,U)"
248  )
249  + fvc::div
250  (
251  this->alpha_*this->rho_*R_
252  + couplingFactor_
253  *this->alpha_*this->rho_*this->nut()*fvc::grad(U),
254  "div(devRhoReff)"
255  )
256  - fvc::div(this->alpha_*this->rho_*this->nu()*dev2(T(fvc::grad(U))))
257  - fvm::laplacian(this->alpha_*this->rho_*this->nuEff(), U)
258  );
259  }
260  else
261  {
262  return
263  (
265  (
266  this->alpha_*this->rho_*this->nut(),
267  U,
268  "laplacian(nuEff,U)"
269  )
270  + fvc::div(this->alpha_*this->rho_*R_)
271  - fvc::div(this->alpha_*this->rho_*this->nu()*dev2(T(fvc::grad(U))))
272  - fvm::laplacian(this->alpha_*this->rho_*this->nuEff(), U)
273  );
274  }
275 
276  return
277  (
278  - fvc::div((this->alpha_*this->rho_*this->nuEff())*dev2(T(fvc::grad(U))))
279  - fvm::laplacian(this->alpha_*this->rho_*this->nuEff(), U)
280  );
281 }
282 
283 
284 template<class BasicTurbulenceModel>
287 (
288  const volScalarField& rho,
289  volVectorField& U
290 ) const
291 {
292  return
293  (
294  - fvc::div((this->alpha_*rho*this->nuEff())*dev2(T(fvc::grad(U))))
295  - fvm::laplacian(this->alpha_*rho*this->nuEff(), U)
296  );
297 }
298 
299 
300 template<class BasicTurbulenceModel>
302 {
303  correctNut();
304 }
305 
306 
307 template<class BasicTurbulenceModel>
309 {
311 }
312 
313 
314 // ************************************************************************* //
BasicTurbulenceModel::alphaField alphaField
GeometricField< symmTensor, fvPatchField, volMesh > volSymmTensorField
Definition: volFieldsFwd.H:58
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:428
virtual tmp< fvVectorMatrix > divDevRhoReff(volVectorField &U) const
Return the source term for the momentum equation.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
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:61
virtual void correct()=0
Solve the turbulence equations and correct the turbulence viscosity.
const Cmpt & yz() const
Definition: TensorI.H:188
Generic dimensioned Type class.
patches[0]
scalar tauw
tmp< GeometricField< Type, fvPatchField, volMesh > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcLaplacian.C:45
BasicTurbulenceModel::transportModel transportModel
virtual tmp< volScalarField > k() const
Return the turbulence kinetic energy.
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
const Cmpt & xz() const
Definition: TensorI.H:167
bool read(const char *, int32_t &)
Definition: int32IO.C:85
virtual bool read()=0
Re-read model coefficients if they have changed.
dimensionedSymmTensor dev(const dimensionedSymmTensor &dt)
void correctWallShearStress(volSymmTensorField &R) const
virtual tmp< volSymmTensorField > R() const
Return the Reynolds stress tensor.
SymmTensor< scalar > symmTensor
SymmTensor of scalars.
Definition: symmTensor.H:48
A class for handling words, derived from string.
Definition: word.H:59
const Cmpt & xy() const
Definition: TensorI.H:160
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
BasicTurbulenceModel::rhoField rhoField
virtual void validate()
Validate the turbulence fields after construction.
const dimensionSet & dimensions() const
Return dimensions.
virtual tmp< volSymmTensorField > devRhoReff() const
Return the effective stress tensor.
static const char nl
Definition: Ostream.H:262
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/ubuntu/OpenFOAM-4.1/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:72
virtual void rename(const word &newName)
Rename.
Definition: regIOobject.C:408
const volScalarField & T
ReynoldsStress(const word &modelName, const alphaField &alpha, const rhoField &rho, const volVectorField &U, const surfaceScalarField &alphaRhoPhi, const surfaceScalarField &phi, const transportModel &transport, const word &propertiesName)
Construct from components.
label patchi
dimensionedSymmTensor dev2(const dimensionedSymmTensor &dt)
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
dimensionedSymmTensor symm(const dimensionedSymmTensor &dt)
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:62
void max(const dimensioned< Type > &)
void boundNormalStress(volSymmTensorField &R) const
A class for managing temporary objects.
Definition: PtrList.H:54
word group() const
Return group (extension part of name)
Definition: IOobject.C:239
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
volScalarField & nu
scalar nut