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