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

RASModel.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 "RASModel.H"
00028 #include "wallFvPatch.H"
00029 #include "addToRunTimeSelectionTable.H"
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035 namespace compressible
00036 {
00037 
00038 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00039 
00040 defineTypeNameAndDebug(RASModel, 0);
00041 defineRunTimeSelectionTable(RASModel, dictionary);
00042 addToRunTimeSelectionTable(turbulenceModel, RASModel, turbulenceModel);
00043 
00044 // * * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * //
00045 
00046 void RASModel::printCoeffs()
00047 {
00048     if (printCoeffs_)
00049     {
00050         Info<< type() << "Coeffs" << coeffDict_ << endl;
00051     }
00052 }
00053 
00054 
00055 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00056 
00057 RASModel::RASModel
00058 (
00059     const word& type,
00060     const volScalarField& rho,
00061     const volVectorField& U,
00062     const surfaceScalarField& phi,
00063     const basicThermo& thermophysicalModel
00064 )
00065 :
00066     turbulenceModel(rho, U, phi, thermophysicalModel),
00067 
00068     IOdictionary
00069     (
00070         IOobject
00071         (
00072             "RASProperties",
00073             U.time().constant(),
00074             U.db(),
00075             IOobject::MUST_READ,
00076             IOobject::NO_WRITE
00077         )
00078     ),
00079 
00080     turbulence_(lookup("turbulence")),
00081     printCoeffs_(lookupOrDefault<Switch>("printCoeffs", false)),
00082     coeffDict_(subDictPtr(type + "Coeffs")),
00083 
00084     k0_("k0", dimVelocity*dimVelocity, SMALL),
00085     epsilon0_("epsilon", k0_.dimensions()/dimTime, SMALL),
00086     epsilonSmall_("epsilonSmall", epsilon0_.dimensions(), SMALL),
00087     omega0_("omega", dimless/dimTime, SMALL),
00088     omegaSmall_("omegaSmall", omega0_.dimensions(), SMALL),
00089 
00090     y_(mesh_)
00091 {}
00092 
00093 
00094 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
00095 
00096 autoPtr<RASModel> RASModel::New
00097 (
00098     const volScalarField& rho,
00099     const volVectorField& U,
00100     const surfaceScalarField& phi,
00101     const basicThermo& thermophysicalModel
00102 )
00103 {
00104     word modelName;
00105 
00106     // Enclose the creation of the dictionary to ensure it is deleted
00107     // before the turbulenceModel is created otherwise the dictionary is
00108     // entered in the database twice
00109     {
00110         IOdictionary dict
00111         (
00112             IOobject
00113             (
00114                 "RASProperties",
00115                 U.time().constant(),
00116                 U.db(),
00117                 IOobject::MUST_READ,
00118                 IOobject::NO_WRITE
00119             )
00120         );
00121 
00122         dict.lookup("RASModel") >> modelName;
00123     }
00124 
00125     Info<< "Selecting RAS turbulence model " << modelName << endl;
00126 
00127     dictionaryConstructorTable::iterator cstrIter =
00128         dictionaryConstructorTablePtr_->find(modelName);
00129 
00130     if (cstrIter == dictionaryConstructorTablePtr_->end())
00131     {
00132         FatalErrorIn
00133         (
00134             "RASModel::New(const volScalarField&, "
00135             "const volVectorField&, const surfaceScalarField&, "
00136             "basicThermo&)"
00137         )   << "Unknown RASModel type " << modelName
00138             << endl << endl
00139             << "Valid RASModel types are :" << endl
00140             << dictionaryConstructorTablePtr_->toc()
00141             << exit(FatalError);
00142     }
00143 
00144     return autoPtr<RASModel>
00145     (
00146         cstrIter()(rho, U, phi, thermophysicalModel)
00147     );
00148 }
00149 
00150 
00151 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00152 
00153 scalar RASModel::yPlusLam(const scalar kappa, const scalar E) const
00154 {
00155     scalar ypl = 11.0;
00156 
00157     for (int i=0; i<10; i++)
00158     {
00159         ypl = log(E*ypl)/kappa;
00160     }
00161 
00162     return ypl;
00163 }
00164 
00165 
00166 tmp<scalarField> RASModel::yPlus(const label patchNo, const scalar Cmu) const
00167 {
00168     const fvPatch& curPatch = mesh_.boundary()[patchNo];
00169 
00170     tmp<scalarField> tYp(new scalarField(curPatch.size()));
00171     scalarField& Yp = tYp();
00172 
00173     if (isType<wallFvPatch>(curPatch))
00174     {
00175         Yp = pow(Cmu, 0.25)
00176             *y_[patchNo]
00177             *sqrt(k()().boundaryField()[patchNo].patchInternalField())
00178            /(
00179                 mu().boundaryField()[patchNo].patchInternalField()
00180                /rho_.boundaryField()[patchNo]
00181             );
00182     }
00183     else
00184     {
00185         WarningIn
00186         (
00187             "tmp<scalarField> RASModel::yPlus(const label patchNo) const"
00188         )   << "Patch " << patchNo << " is not a wall. Returning null field"
00189             << nl << endl;
00190 
00191         Yp.setSize(0);
00192     }
00193 
00194     return tYp;
00195 }
00196 
00197 
00198 void RASModel::correct()
00199 {
00200     if (mesh_.changing())
00201     {
00202         y_.correct();
00203     }
00204 }
00205 
00206 
00207 bool RASModel::read()
00208 {
00209     if (regIOobject::read())
00210     {
00211         lookup("turbulence") >> turbulence_;
00212 
00213         if (const dictionary* dictPtr = subDictPtr(type() + "Coeffs"))
00214         {
00215             coeffDict_ <<= *dictPtr;
00216         }
00217 
00218         k0_.readIfPresent(*this);
00219         epsilon0_.readIfPresent(*this);
00220         epsilonSmall_.readIfPresent(*this);
00221         omega0_.readIfPresent(*this);
00222         omegaSmall_.readIfPresent(*this);
00223 
00224         return true;
00225     }
00226     else
00227     {
00228         return false;
00229     }
00230 }
00231 
00232 
00233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00234 
00235 } // End namespace compressible
00236 } // End namespace Foam
00237 
00238 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd