OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

SpalartAllmaras.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "SpalartAllmaras.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 
00030 #include "backwardsCompatibilityWallFunctions.H"
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036 namespace compressible
00037 {
00038 namespace RASModels
00039 {
00040 
00041 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00042 
00043 defineTypeNameAndDebug(SpalartAllmaras, 0);
00044 addToRunTimeSelectionTable(RASModel, SpalartAllmaras, dictionary);
00045 
00046 // * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * * //
00047 
00048 tmp<volScalarField> SpalartAllmaras::chi() const
00049 {
00050     return rho_*nuTilda_/mu();
00051 }
00052 
00053 
00054 tmp<volScalarField> SpalartAllmaras::fv1(const volScalarField& chi) const
00055 {
00056     volScalarField chi3 = pow3(chi);
00057     return chi3/(chi3 + pow3(Cv1_));
00058 }
00059 
00060 
00061 tmp<volScalarField> SpalartAllmaras::fv2
00062 (
00063     const volScalarField& chi,
00064     const volScalarField& fv1
00065 ) const
00066 {
00067     return 1.0/pow3(scalar(1) + chi/Cv2_);
00068 }
00069 
00070 
00071 tmp<volScalarField> SpalartAllmaras::fv3
00072 (
00073     const volScalarField& chi,
00074     const volScalarField& fv1
00075 ) const
00076 {
00077     volScalarField chiByCv2 = (1/Cv2_)*chi;
00078 
00079     return
00080         (scalar(1) + chi*fv1)
00081        *(1/Cv2_)
00082        *(3*(scalar(1) + chiByCv2) + sqr(chiByCv2))
00083        /pow3(scalar(1) + chiByCv2);
00084 }
00085 
00086 
00087 tmp<volScalarField> SpalartAllmaras::fw(const volScalarField& Stilda) const
00088 {
00089     volScalarField r = min
00090     (
00091         nuTilda_
00092        /(
00093            max(Stilda, dimensionedScalar("SMALL", Stilda.dimensions(), SMALL))
00094            *sqr(kappa_*d_)
00095         ),
00096         scalar(10.0)
00097     );
00098     r.boundaryField() == 0.0;
00099 
00100     volScalarField g = r + Cw2_*(pow6(r) - r);
00101 
00102     return g*pow((1.0 + pow6(Cw3_))/(pow6(g) + pow6(Cw3_)), 1.0/6.0);
00103 }
00104 
00105 
00106 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00107 
00108 SpalartAllmaras::SpalartAllmaras
00109 (
00110     const volScalarField& rho,
00111     const volVectorField& U,
00112     const surfaceScalarField& phi,
00113     const basicThermo& thermophysicalModel
00114 )
00115 :
00116     RASModel(typeName, rho, U, phi, thermophysicalModel),
00117 
00118     sigmaNut_
00119     (
00120         dimensioned<scalar>::lookupOrAddToDict
00121         (
00122             "sigmaNut",
00123             coeffDict_,
00124             0.66666
00125         )
00126     ),
00127     kappa_
00128     (
00129         dimensioned<scalar>::lookupOrAddToDict
00130         (
00131             "kappa",
00132             coeffDict_,
00133             0.41
00134         )
00135     ),
00136     Prt_
00137     (
00138         dimensioned<scalar>::lookupOrAddToDict
00139         (
00140             "Prt",
00141             coeffDict_,
00142             1.0
00143         )
00144     ),
00145 
00146     Cb1_
00147     (
00148         dimensioned<scalar>::lookupOrAddToDict
00149         (
00150             "Cb1",
00151             coeffDict_,
00152             0.1355
00153         )
00154     ),
00155     Cb2_
00156     (
00157         dimensioned<scalar>::lookupOrAddToDict
00158         (
00159             "Cb2",
00160             coeffDict_,
00161             0.622
00162         )
00163     ),
00164     Cw1_(Cb1_/sqr(kappa_) + (1.0 + Cb2_)/sigmaNut_),
00165     Cw2_
00166     (
00167         dimensioned<scalar>::lookupOrAddToDict
00168         (
00169             "Cw2",
00170             coeffDict_,
00171             0.3
00172         )
00173     ),
00174     Cw3_
00175     (
00176         dimensioned<scalar>::lookupOrAddToDict
00177         (
00178             "Cw3",
00179             coeffDict_,
00180             2.0
00181         )
00182     ),
00183     Cv1_
00184     (
00185         dimensioned<scalar>::lookupOrAddToDict
00186         (
00187             "Cv1",
00188             coeffDict_,
00189             7.1
00190         )
00191     ),
00192     Cv2_
00193     (
00194         dimensioned<scalar>::lookupOrAddToDict
00195         (
00196             "Cv2",
00197             coeffDict_,
00198             5.0
00199         )
00200     ),
00201 
00202     nuTilda_
00203     (
00204         IOobject
00205         (
00206             "nuTilda",
00207             runTime_.timeName(),
00208             mesh_,
00209             IOobject::MUST_READ,
00210             IOobject::AUTO_WRITE
00211         ),
00212         mesh_
00213     ),
00214 
00215     mut_
00216     (
00217         IOobject
00218         (
00219             "mut",
00220             runTime_.timeName(),
00221             mesh_,
00222             IOobject::MUST_READ,
00223             IOobject::AUTO_WRITE
00224         ),
00225         mesh_
00226     ),
00227 
00228     alphat_
00229     (
00230         IOobject
00231         (
00232             "alphat",
00233             runTime_.timeName(),
00234             mesh_,
00235             IOobject::NO_READ,
00236             IOobject::AUTO_WRITE
00237         ),
00238         autoCreateAlphat("alphat", mesh_)
00239     ),
00240 
00241     d_(mesh_)
00242 {
00243     alphat_ = mut_/Prt_;
00244     alphat_.correctBoundaryConditions();
00245 
00246     printCoeffs();
00247 }
00248 
00249 
00250 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00251 
00252 tmp<volSymmTensorField> SpalartAllmaras::R() const
00253 {
00254     return tmp<volSymmTensorField>
00255     (
00256         new volSymmTensorField
00257         (
00258             IOobject
00259             (
00260                 "R",
00261                 runTime_.timeName(),
00262                 mesh_,
00263                 IOobject::NO_READ,
00264                 IOobject::NO_WRITE
00265             ),
00266             ((2.0/3.0)*I)*k() - (mut_/rho_)*dev(twoSymm(fvc::grad(U_)))
00267         )
00268     );
00269 }
00270 
00271 
00272 tmp<volSymmTensorField> SpalartAllmaras::devRhoReff() const
00273 {
00274     return tmp<volSymmTensorField>
00275     (
00276         new volSymmTensorField
00277         (
00278             IOobject
00279             (
00280                 "devRhoReff",
00281                 runTime_.timeName(),
00282                 mesh_,
00283                 IOobject::NO_READ,
00284                 IOobject::NO_WRITE
00285             ),
00286            -muEff()*dev(twoSymm(fvc::grad(U_)))
00287         )
00288     );
00289 }
00290 
00291 
00292 tmp<fvVectorMatrix> SpalartAllmaras::divDevRhoReff(volVectorField& U) const
00293 {
00294     volScalarField muEff_ = muEff();
00295 
00296     return
00297     (
00298       - fvm::laplacian(muEff_, U)
00299       - fvc::div(muEff_*dev2(fvc::grad(U)().T()))
00300     );
00301 }
00302 
00303 
00304 bool SpalartAllmaras::read()
00305 {
00306     if (RASModel::read())
00307     {
00308         sigmaNut_.readIfPresent(coeffDict());
00309         kappa_.readIfPresent(coeffDict());
00310         Prt_.readIfPresent(coeffDict());
00311 
00312         Cb1_.readIfPresent(coeffDict());
00313         Cb2_.readIfPresent(coeffDict());
00314         Cw1_ = Cb1_/sqr(kappa_) + (1.0 + Cb2_)/sigmaNut_;
00315         Cw2_.readIfPresent(coeffDict());
00316         Cw3_.readIfPresent(coeffDict());
00317         Cv1_.readIfPresent(coeffDict());
00318         Cv2_.readIfPresent(coeffDict());
00319 
00320         return true;
00321     }
00322     else
00323     {
00324         return false;
00325     }
00326 }
00327 
00328 
00329 void SpalartAllmaras::correct()
00330 {
00331     if (!turbulence_)
00332     {
00333         // Re-calculate viscosity
00334         mut_ = rho_*nuTilda_*fv1(chi());
00335         mut_.correctBoundaryConditions();
00336 
00337         // Re-calculate thermal diffusivity
00338         alphat_ = mut_/Prt_;
00339         alphat_.correctBoundaryConditions();
00340 
00341         return;
00342     }
00343 
00344     RASModel::correct();
00345 
00346     if (mesh_.changing())
00347     {
00348         d_.correct();
00349     }
00350 
00351     volScalarField chi = this->chi();
00352     volScalarField fv1 = this->fv1(chi);
00353 
00354     volScalarField Stilda =
00355         fv3(chi, fv1)*::sqrt(2.0)*mag(skew(fvc::grad(U_)))
00356       + fv2(chi, fv1)*nuTilda_/sqr(kappa_*d_);
00357 
00358     tmp<fvScalarMatrix> nuTildaEqn
00359     (
00360         fvm::ddt(rho_, nuTilda_)
00361       + fvm::div(phi_, nuTilda_)
00362       - fvm::laplacian(DnuTildaEff(), nuTilda_)
00363       - Cb2_/sigmaNut_*rho_*magSqr(fvc::grad(nuTilda_))
00364      ==
00365         Cb1_*rho_*Stilda*nuTilda_
00366       - fvm::Sp(Cw1_*fw(Stilda)*nuTilda_*rho_/sqr(d_), nuTilda_)
00367     );
00368 
00369     nuTildaEqn().relax();
00370     solve(nuTildaEqn);
00371     bound(nuTilda_, dimensionedScalar("0", nuTilda_.dimensions(), 0.0));
00372     nuTilda_.correctBoundaryConditions();
00373 
00374     // Re-calculate viscosity
00375     mut_.internalField() = fv1*nuTilda_.internalField()*rho_.internalField();
00376     mut_.correctBoundaryConditions();
00377 
00378     // Re-calculate thermal diffusivity
00379     alphat_ = mut_/Prt_;
00380     alphat_.correctBoundaryConditions();
00381 }
00382 
00383 
00384 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00385 
00386 } // End namespace RASModels
00387 } // End namespace compressible
00388 } // End namespace Foam
00389 
00390 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd