1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "SpalartAllmaras.H"
27 #include "addToRunTimeSelectionTable.H"
29 #include "backwardsCompatibilityWallFunctions.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 namespace compressible
40 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
42 defineTypeNameAndDebug(SpalartAllmaras, 0);
43 addToRunTimeSelectionTable(RASModel, SpalartAllmaras, dictionary);
45 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
47 tmp<volScalarField> SpalartAllmaras::chi() const
49 return rho_*nuTilda_/mu();
53 tmp<volScalarField> SpalartAllmaras::fv1(const volScalarField& chi) const
55 volScalarField chi3(pow3(chi));
56 return chi3/(chi3 + pow3(Cv1_));
60 tmp<volScalarField> SpalartAllmaras::fv2
62 const volScalarField& chi,
63 const volScalarField& fv1
66 return 1.0/pow3(scalar(1) + chi/Cv2_);
70 tmp<volScalarField> SpalartAllmaras::fv3
72 const volScalarField& chi,
73 const volScalarField& fv1
76 volScalarField chiByCv2((1/Cv2_)*chi);
81 *(3*(scalar(1) + chiByCv2) + sqr(chiByCv2))
82 /pow3(scalar(1) + chiByCv2);
86 tmp<volScalarField> SpalartAllmaras::fw(const volScalarField& Stilda) const
97 dimensionedScalar("SMALL", Stilda.dimensions(), SMALL)
104 r.boundaryField() == 0.0;
106 volScalarField g(r + Cw2_*(pow6(r) - r));
108 return g*pow((1.0 + pow6(Cw3_))/(pow6(g) + pow6(Cw3_)), 1.0/6.0);
112 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
114 SpalartAllmaras::SpalartAllmaras
116 const volScalarField& rho,
117 const volVectorField& U,
118 const surfaceScalarField& phi,
119 const basicThermo& thermophysicalModel,
120 const word& turbulenceModelName,
121 const word& modelName
124 RASModel(modelName, rho, U, phi, thermophysicalModel, turbulenceModelName),
128 dimensioned<scalar>::lookupOrAddToDict
137 dimensioned<scalar>::lookupOrAddToDict
146 dimensioned<scalar>::lookupOrAddToDict
156 dimensioned<scalar>::lookupOrAddToDict
165 dimensioned<scalar>::lookupOrAddToDict
172 Cw1_(Cb1_/sqr(kappa_) + (1.0 + Cb2_)/sigmaNut_),
175 dimensioned<scalar>::lookupOrAddToDict
184 dimensioned<scalar>::lookupOrAddToDict
193 dimensioned<scalar>::lookupOrAddToDict
202 dimensioned<scalar>::lookupOrAddToDict
246 autoCreateAlphat("alphat", mesh_)
252 alphat_.correctBoundaryConditions();
258 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
260 tmp<volScalarField> SpalartAllmaras::k() const
262 WarningIn("tmp<volScalarField> SpalartAllmaras::k() const")
263 << "Turbulence kinetic energy not defined for Spalart-Allmaras model. "
264 << "Returning zero field"
267 return tmp<volScalarField>
278 dimensionedScalar("0", dimensionSet(0, 2, -2, 0, 0), 0)
284 tmp<volScalarField> SpalartAllmaras::epsilon() const
286 WarningIn("tmp<volScalarField> SpalartAllmaras::epsilon() const")
287 << "Turbulence kinetic energy dissipation rate not defined for "
288 << "Spalart-Allmaras model. Returning zero field"
291 return tmp<volScalarField>
302 dimensionedScalar("0", dimensionSet(0, 2, -3, 0, 0), 0)
308 tmp<volSymmTensorField> SpalartAllmaras::R() const
310 return tmp<volSymmTensorField>
312 new volSymmTensorField
322 ((2.0/3.0)*I)*k() - (mut_/rho_)*dev(twoSymm(fvc::grad(U_)))
328 tmp<volSymmTensorField> SpalartAllmaras::devRhoReff() const
330 return tmp<volSymmTensorField>
332 new volSymmTensorField
342 -muEff()*dev(twoSymm(fvc::grad(U_)))
348 tmp<fvVectorMatrix> SpalartAllmaras::divDevRhoReff(volVectorField& U) const
350 volScalarField muEff_(muEff());
354 - fvm::laplacian(muEff_, U)
355 - fvc::div(muEff_*dev2(T(fvc::grad(U))))
360 bool SpalartAllmaras::read()
362 if (RASModel::read())
364 sigmaNut_.readIfPresent(coeffDict());
365 kappa_.readIfPresent(coeffDict());
366 Prt_.readIfPresent(coeffDict());
368 Cb1_.readIfPresent(coeffDict());
369 Cb2_.readIfPresent(coeffDict());
370 Cw1_ = Cb1_/sqr(kappa_) + (1.0 + Cb2_)/sigmaNut_;
371 Cw2_.readIfPresent(coeffDict());
372 Cw3_.readIfPresent(coeffDict());
373 Cv1_.readIfPresent(coeffDict());
374 Cv2_.readIfPresent(coeffDict());
385 void SpalartAllmaras::correct()
389 // Re-calculate viscosity
390 mut_ = rho_*nuTilda_*fv1(chi());
391 mut_.correctBoundaryConditions();
393 // Re-calculate thermal diffusivity
395 alphat_.correctBoundaryConditions();
402 if (mesh_.changing())
407 volScalarField chi(this->chi());
408 volScalarField fv1(this->fv1(chi));
410 volScalarField Stilda
412 fv3(chi, fv1)*::sqrt(2.0)*mag(skew(fvc::grad(U_)))
413 + fv2(chi, fv1)*nuTilda_/sqr(kappa_*d_)
416 tmp<fvScalarMatrix> nuTildaEqn
418 fvm::ddt(rho_, nuTilda_)
419 + fvm::div(phi_, nuTilda_)
420 - fvm::laplacian(DnuTildaEff(), nuTilda_)
421 - Cb2_/sigmaNut_*rho_*magSqr(fvc::grad(nuTilda_))
423 Cb1_*rho_*Stilda*nuTilda_
424 - fvm::Sp(Cw1_*fw(Stilda)*nuTilda_*rho_/sqr(d_), nuTilda_)
427 nuTildaEqn().relax();
429 bound(nuTilda_, dimensionedScalar("0", nuTilda_.dimensions(), 0.0));
430 nuTilda_.correctBoundaryConditions();
432 // Re-calculate viscosity
433 mut_.internalField() = fv1*nuTilda_.internalField()*rho_.internalField();
434 mut_.correctBoundaryConditions();
436 // Re-calculate thermal diffusivity
438 alphat_.correctBoundaryConditions();
442 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
444 } // End namespace RASModels
445 } // End namespace compressible
446 } // End namespace Foam
448 // ************************************************************************* //