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-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 "ReynoldsStress.H"
27 #include "fvcSnGrad.H"
28 #include "wallFvPatch.H"
29 
30 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
31 
32 template<class BasicMomentumTransportModel>
34 (
36 ) const
37 {
38  scalar kMin = this->kMin_.value();
39 
40  R.max
41  (
43  (
44  "zero",
45  R.dimensions(),
47  (
48  kMin, -great, -great,
49  kMin, -great,
50  kMin
51  )
52  )
53  );
54 }
55 
56 
57 template<class BasicMomentumTransportModel>
59 (
61 ) const
62 {
63  const fvPatchList& patches = this->mesh_.boundary();
64 
65  volSymmTensorField::Boundary& RBf = R.boundaryFieldRef();
66 
68  {
69  const fvPatch& curPatch = patches[patchi];
70 
71  if (isA<wallFvPatch>(curPatch))
72  {
73  symmTensorField& Rw = RBf[patchi];
74 
75  const scalarField& nutw = this->nut_.boundaryField()[patchi];
76 
77  const vectorField snGradUw
78  (
79  this->U_.boundaryField()[patchi].snGrad()
80  );
81 
82  const vectorField& Sf = this->mesh_.Sf().boundaryField()[patchi];
83 
84  const scalarField& magSf =
85  this->mesh_.magSf().boundaryField()[patchi];
86 
87  forAll(curPatch, facei)
88  {
89  // Calculate near-wall velocity gradient
90  const tensor gradUw
91  = (Sf[facei]/magSf[facei])*snGradUw[facei];
92 
93  // Set the wall Reynolds-stress to the near-wall shear-stress
94  // Note: the spherical part of the normal stress is included in
95  // the pressure
96  Rw[facei] = -nutw[facei]*dev(twoSymm(gradUw));
97  }
98  }
99  }
100 }
101 
102 
103 template<class BasicMomentumTransportModel>
106 {
108  (
110  (
111  this->R_,
112  dimVolume*this->rho_.dimensions()*this->R_.dimensions()/dimTime
113  )
114  );
115 }
116 
117 
118 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
119 
120 template<class BasicMomentumTransportModel>
122 (
123  const word& type,
124  const alphaField& alpha,
125  const rhoField& rho,
126  const volVectorField& U,
127  const surfaceScalarField& alphaRhoPhi,
128  const surfaceScalarField& phi,
129  const viscosity& viscosity
130 )
131 :
132  BasicMomentumTransportModel
133  (
134  type,
136  rho,
137  U,
138  alphaRhoPhi,
139  phi,
140  viscosity
141  ),
142 
143  couplingFactor_("couplingFactor", this->typeDict(type), 1),
144 
145  R_
146  (
148  (
149  this->groupName("R"),
150  this->runTime_.name(),
151  this->mesh_,
152  IOobject::MUST_READ,
153  IOobject::AUTO_WRITE
154  ),
155  this->mesh_,
156  dimensions::ReynoldsStress
157  ),
158 
159  nut_
160  (
161  IOobject
162  (
163  this->groupName("nut"),
164  this->runTime_.name(),
165  this->mesh_,
166  IOobject::MUST_READ,
167  IOobject::AUTO_WRITE
168  ),
169  this->mesh_,
170  dimensions::turbulentViscosity
171  )
172 {
173  if (couplingFactor_.value() < 0 || couplingFactor_.value() > 1)
174  {
176  << "couplingFactor = " << couplingFactor_
177  << " is not in range 0 - 1" << nl
178  << exit(FatalError);
179  }
180 }
181 
182 
183 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
184 
185 template<class BasicMomentumTransportModel>
187 {
189 }
190 
191 
192 template<class BasicMomentumTransportModel>
195 {
196  return R_;
197 }
198 
199 
200 template<class BasicMomentumTransportModel>
203 {
204  tmp<Foam::volScalarField> tk(0.5*tr(R_));
205  tk.ref().rename("k");
206  return tk;
207 }
208 
209 
210 template<class BasicMomentumTransportModel>
213 (
214  const volVectorField& U
215 ) const
216 {
217  tmp<volTensorField> tgradU = fvc::grad(U);
218  const volTensorField& gradU = tgradU();
219  const surfaceTensorField gradUf(fvc::interpolate(gradU));
220 
221  // Interpolate Reynolds stress to the faces
222  // with either a stress or velocity coupling correction
223  return
224  (
225  (this->mesh().Sf() & fvc::interpolate(R_))
226 
227  // Stress coupling
228  + couplingFactor_
229  *(this->mesh().Sf() & fvc::interpolate(this->nut()*gradU))
230 
231  // or velocity gradient coupling
232  // + couplingFactor_
233  // *fvc::interpolate(this->nut())*(this->mesh().Sf() & gradUf)
234 
235  - fvc::interpolate(couplingFactor_*this->nut() + this->nu())
236  *this->mesh().magSf()*fvc::snGrad(U)
237  - fvc::interpolate(this->nu())*(this->mesh().Sf() & dev2(gradUf.T()))
238  );
239 }
240 
241 
242 template<class BasicMomentumTransportModel>
245 {
247  (
248  this->groupName("devTau"),
249  fvc::interpolate(this->alpha_*this->rho_)*Refff(this->U_)
250  /this->mesh().magSf()
251  );
252 }
253 
254 
255 template<class BasicMomentumTransportModel>
256 template<class RhoFieldType>
259 (
260  const RhoFieldType& rho,
262 ) const
263 {
264  return
265  (
266  fvc::div(fvc::interpolate(this->alpha_*rho)*Refff(U))
267  - correction(fvm::laplacian(this->alpha_*rho*this->nuEff(), U))
268  );
269 }
270 
271 
272 template<class BasicMomentumTransportModel>
275 (
277 ) const
278 {
279  return DivDevTau(this->rho_, U);
280 }
281 
282 
283 template<class BasicMomentumTransportModel>
286 (
287  const volScalarField& rho,
289 ) const
290 {
291  return DivDevTau(rho, U);
292 }
293 
294 
295 template<class BasicMomentumTransportModel>
297 {
298  correctNut();
299 }
300 
301 
302 template<class BasicMomentumTransportModel>
304 {
306 }
307 
308 
309 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Generic GeometricBoundaryField class.
Generic GeometricField class.
tmp< GeometricField< Type, GeoMesh, Field > > T() const
Return transpose (only if it is a tensor field)
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
Reynolds-stress turbulence model base class.
BasicMomentumTransportModel::alphaField alphaField
virtual tmp< volSymmTensorField > R() const
Return the Reynolds stress tensor [m^2/s^2].
void boundNormalStress(volSymmTensorField &R) const
virtual tmp< surfaceVectorField > devTau() const
Return the effective surface stress.
virtual tmp< volScalarField > k() const
Return the turbulence kinetic energy.
virtual void validate()
Validate the turbulence fields after construction.
ReynoldsStress(const word &type, const alphaField &alpha, const rhoField &rho, const volVectorField &U, const surfaceScalarField &alphaRhoPhi, const surfaceScalarField &phi, const viscosity &viscosity)
Construct from components.
virtual bool read()=0
Re-read model coefficients if they have changed.
virtual void correct()=0
Solve the turbulence equations and correct the turbulence viscosity.
tmp< surfaceVectorField > Refff(const volVectorField &U) const
Return the effective Reynolds stress flux.
virtual tmp< fvVectorMatrix > divDevTau(volVectorField &U) const
Return the source term for the momentum equation.
virtual tmp< fvSymmTensorMatrix > RSource() const
Source term for the R equation.
void correctWallShearStress(volSymmTensorField &R) const
BasicMomentumTransportModel::rhoField rhoField
Generic dimensioned Type class.
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvMatrix.H:118
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:58
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
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::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const scalar nut
const scalar nuEff
Calculate the snGrad of the given volField.
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))
const volSymmTensorField R(IOobject("R", runTime.name(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), turbulence->R())
void correct(const RdeltaTType &rDeltaT, const RhoType &rho, volScalarField &psi, const surfaceScalarField &phiCorr, const SpType &Sp)
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
const dimensionSet turbulentViscosity
static tmp< SurfaceField< Type > > interpolate(const VolField< Type > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
tmp< VolField< Type > > laplacian(const VolField< Type > &vf, const word &name)
Definition: fvcLaplacian.C:45
tmp< VolField< typename outerProduct< vector, Type >::type > > grad(const SurfaceField< Type > &ssf)
Definition: fvcGrad.C:46
tmp< VolField< Type > > div(const SurfaceField< Type > &ssf)
Definition: fvcDiv.C:47
tmp< SurfaceField< Type > > snGrad(const VolField< Type > &vf, const word &name)
Definition: fvcSnGrad.C:45
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const dimensionSet & dimVolume
Definition: dimensions.C:282
void dev2(pointPatchField< tensor > &, const pointPatchField< tensor > &)
void tr(pointPatchField< scalar > &, const pointPatchField< tensor > &)
const dimensionSet & dimTime
Definition: dimensions.C:277
void dev(pointPatchField< tensor > &, const pointPatchField< tensor > &)
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Return the correction form of the given matrix.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
void twoSymm(pointPatchField< tensor > &, const pointPatchField< tensor > &)
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
static const char nl
Definition: Ostream.H:297
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488