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

nutWallFunctionFvPatchScalarField.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) 2008-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 "nutWallFunctionFvPatchScalarField.H"
00028 #include "RASModel.H"
00029 #include "fvPatchFieldMapper.H"
00030 #include "volFields.H"
00031 #include "wallFvPatch.H"
00032 #include "addToRunTimeSelectionTable.H"
00033 
00034 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00035 
00036 namespace Foam
00037 {
00038 namespace incompressible
00039 {
00040 namespace RASModels
00041 {
00042 
00043 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
00044 
00045 void nutWallFunctionFvPatchScalarField::checkType()
00046 {
00047     if (!isA<wallFvPatch>(patch()))
00048     {
00049         FatalErrorIn("nutWallFunctionFvPatchScalarField::checkType()")
00050             << "Invalid wall function specification" << nl
00051             << "    Patch type for patch " << patch().name()
00052             << " must be wall" << nl
00053             << "    Current patch type is " << patch().type() << nl << endl
00054             << abort(FatalError);
00055     }
00056 }
00057 
00058 
00059 scalar nutWallFunctionFvPatchScalarField::calcYPlusLam
00060 (
00061     const scalar kappa,
00062     const scalar E
00063 ) const
00064 {
00065     scalar ypl = 11.0;
00066 
00067     for (int i=0; i<10; i++)
00068     {
00069         ypl = log(E*ypl)/kappa;
00070     }
00071 
00072     return ypl;
00073 }
00074 
00075 
00076 tmp<scalarField> nutWallFunctionFvPatchScalarField::calcNut() const
00077 {
00078     const label patchI = patch().index();
00079 
00080     const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
00081     const scalarField& y = rasModel.y()[patchI];
00082     const tmp<volScalarField> tk = rasModel.k();
00083     const volScalarField& k = tk();
00084     const scalarField& nuw = rasModel.nu().boundaryField()[patchI];
00085 
00086     const scalar Cmu25 = pow(Cmu_, 0.25);
00087 
00088     tmp<scalarField> tnutw(new scalarField(patch().size(), 0.0));
00089     scalarField& nutw = tnutw();
00090 
00091     forAll(nutw, faceI)
00092     {
00093         label faceCellI = patch().faceCells()[faceI];
00094 
00095         scalar yPlus = Cmu25*y[faceI]*sqrt(k[faceCellI])/nuw[faceI];
00096 
00097         if (yPlus > yPlusLam_)
00098         {
00099             nutw[faceI] = nuw[faceI]*(yPlus*kappa_/log(E_*yPlus) - 1.0);
00100         }
00101     }
00102 
00103     return tnutw;
00104 }
00105 
00106 
00107 void nutWallFunctionFvPatchScalarField::writeLocalEntries(Ostream& os) const
00108 {
00109     os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl;
00110     os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl;
00111     os.writeKeyword("E") << E_ << token::END_STATEMENT << nl;
00112 }
00113 
00114 
00115 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00116 
00117 nutWallFunctionFvPatchScalarField::nutWallFunctionFvPatchScalarField
00118 (
00119     const fvPatch& p,
00120     const DimensionedField<scalar, volMesh>& iF
00121 )
00122 :
00123     fixedValueFvPatchScalarField(p, iF),
00124     Cmu_(0.09),
00125     kappa_(0.41),
00126     E_(9.8),
00127     yPlusLam_(calcYPlusLam(kappa_, E_))
00128 {
00129     checkType();
00130 }
00131 
00132 
00133 nutWallFunctionFvPatchScalarField::nutWallFunctionFvPatchScalarField
00134 (
00135     const nutWallFunctionFvPatchScalarField& ptf,
00136     const fvPatch& p,
00137     const DimensionedField<scalar, volMesh>& iF,
00138     const fvPatchFieldMapper& mapper
00139 )
00140 :
00141     fixedValueFvPatchScalarField(ptf, p, iF, mapper),
00142     Cmu_(ptf.Cmu_),
00143     kappa_(ptf.kappa_),
00144     E_(ptf.E_),
00145     yPlusLam_(ptf.yPlusLam_)
00146 {
00147     checkType();
00148 }
00149 
00150 
00151 nutWallFunctionFvPatchScalarField::nutWallFunctionFvPatchScalarField
00152 (
00153     const fvPatch& p,
00154     const DimensionedField<scalar, volMesh>& iF,
00155     const dictionary& dict
00156 )
00157 :
00158     fixedValueFvPatchScalarField(p, iF, dict),
00159     Cmu_(dict.lookupOrDefault<scalar>("Cmu", 0.09)),
00160     kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
00161     E_(dict.lookupOrDefault<scalar>("E", 9.8)),
00162     yPlusLam_(calcYPlusLam(kappa_, E_))
00163 {
00164     checkType();
00165 }
00166 
00167 
00168 nutWallFunctionFvPatchScalarField::nutWallFunctionFvPatchScalarField
00169 (
00170     const nutWallFunctionFvPatchScalarField& wfpsf
00171 )
00172 :
00173     fixedValueFvPatchScalarField(wfpsf),
00174     Cmu_(wfpsf.Cmu_),
00175     kappa_(wfpsf.kappa_),
00176     E_(wfpsf.E_),
00177     yPlusLam_(wfpsf.yPlusLam_)
00178 {
00179     checkType();
00180 }
00181 
00182 
00183 nutWallFunctionFvPatchScalarField::nutWallFunctionFvPatchScalarField
00184 (
00185     const nutWallFunctionFvPatchScalarField& wfpsf,
00186     const DimensionedField<scalar, volMesh>& iF
00187 )
00188 :
00189     fixedValueFvPatchScalarField(wfpsf, iF),
00190     Cmu_(wfpsf.Cmu_),
00191     kappa_(wfpsf.kappa_),
00192     E_(wfpsf.E_),
00193     yPlusLam_(wfpsf.yPlusLam_)
00194 {
00195     checkType();
00196 }
00197 
00198 
00199 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00200 
00201 void nutWallFunctionFvPatchScalarField::updateCoeffs()
00202 {
00203     operator==(calcNut());
00204 
00205     fixedValueFvPatchScalarField::updateCoeffs();
00206 }
00207 
00208 
00209 tmp<scalarField> nutWallFunctionFvPatchScalarField::yPlus() const
00210 {
00211     const label patchI = patch().index();
00212 
00213     const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
00214     const scalarField& y = rasModel.y()[patchI];
00215 
00216     const tmp<volScalarField> tk = rasModel.k();
00217     const volScalarField& k = tk();
00218     const scalarField kwc = k.boundaryField()[patchI].patchInternalField();
00219     const scalarField& nuw = rasModel.nu().boundaryField()[patchI];
00220 
00221     return pow(Cmu_, 0.25)*y*sqrt(kwc)/nuw;
00222 }
00223 
00224 
00225 void nutWallFunctionFvPatchScalarField::write(Ostream& os) const
00226 {
00227     fvPatchField<scalar>::write(os);
00228     writeLocalEntries(os);
00229     writeEntry("value", os);
00230 }
00231 
00232 
00233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00234 
00235 makePatchTypeField(fvPatchScalarField, nutWallFunctionFvPatchScalarField);
00236 
00237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00238 
00239 } // End namespace RASModels
00240 } // End namespace incompressible
00241 } // End namespace Foam
00242 
00243 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd