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

mutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField.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 "mutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField.H"
00028 #include "fvPatchFieldMapper.H"
00029 #include "volFields.H"
00030 #include "RASModel.H"
00031 #include "addToRunTimeSelectionTable.H"
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037 namespace compressible
00038 {
00039 namespace RASModels
00040 {
00041 
00042 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
00043 
00044 tmp<scalarField>
00045 mutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::calcYPlus
00046 (
00047     const scalarField& magUp
00048 ) const
00049 {
00050     const label patchI = patch().index();
00051 
00052     const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
00053     const scalarField& y = rasModel.y()[patchI];
00054     const scalarField& muw = rasModel.mu().boundaryField()[patchI];
00055     const fvPatchScalarField& rho = rasModel.rho().boundaryField()[patchI];
00056 
00057     tmp<scalarField> tyPlus(new scalarField(patch().size(), 0.0));
00058     scalarField& yPlus = tyPlus();
00059 
00060     if (roughnessHeight_ > 0.0)
00061     {
00062         // Rough Walls
00063         const scalar c_1 = 1/(90 - 2.25) + roughnessConstant_;
00064         static const scalar c_2 = 2.25/(90 - 2.25);
00065         static const scalar c_3 = 2.0*atan(1.0)/log(90/2.25);
00066         static const scalar c_4 = c_3*log(2.25);
00067 
00068         //if (KsPlusBasedOnYPlus_)
00069         {
00070             // If KsPlus is based on YPlus the extra term added to the law
00071             // of the wall will depend on yPlus
00072             forAll(yPlus, facei)
00073             {
00074                 const scalar magUpara = magUp[facei];
00075                 const scalar Re = rho[facei]*magUpara*y[facei]/muw[facei];
00076                 const scalar kappaRe = kappa_*Re;
00077 
00078                 scalar yp = yPlusLam_;
00079                 const scalar ryPlusLam = 1.0/yp;
00080 
00081                 int iter = 0;
00082                 scalar yPlusLast = 0.0;
00083                 scalar dKsPlusdYPlus = roughnessHeight_/y[facei];
00084 
00085                 // Enforce the roughnessHeight to be less than the distance to
00086                 // the first cell centre.
00087                 if (dKsPlusdYPlus > 1)
00088                 {
00089                     dKsPlusdYPlus = 1;
00090                 }
00091 
00092                 // Additional tuning parameter (fudge factor) - nominally = 1
00093                 dKsPlusdYPlus *= roughnessFudgeFactor_;
00094 
00095                 do
00096                 {
00097                     yPlusLast = yp;
00098 
00099                     // The non-dimensional roughness height
00100                     scalar KsPlus = yp*dKsPlusdYPlus;
00101 
00102                     // The extra term in the law-of-the-wall
00103                     scalar G = 0.0;
00104 
00105                     scalar yPlusGPrime = 0.0;
00106 
00107                     if (KsPlus >= 90)
00108                     {
00109                         const scalar t_1 = 1 + roughnessConstant_*KsPlus;
00110                         G = log(t_1);
00111                         yPlusGPrime = roughnessConstant_*KsPlus/t_1;
00112                     }
00113                     else if (KsPlus > 2.25)
00114                     {
00115                         const scalar t_1 = c_1*KsPlus - c_2;
00116                         const scalar t_2 = c_3*log(KsPlus) - c_4;
00117                         const scalar sint_2 = sin(t_2);
00118                         const scalar logt_1 = log(t_1);
00119                         G = logt_1*sint_2;
00120                         yPlusGPrime =
00121                             (c_1*sint_2*KsPlus/t_1) + (c_3*logt_1*cos(t_2));
00122                     }
00123 
00124                     scalar denom = 1.0 + log(E_*yp) - G - yPlusGPrime;
00125                     if (mag(denom) > VSMALL)
00126                     {
00127                         yp = (kappaRe + yp*(1 - yPlusGPrime))/denom;
00128                     }
00129 
00130                 } while
00131                 (
00132                     mag(ryPlusLam*(yp - yPlusLast)) > 0.0001
00133                  && ++iter < 10
00134                  && yp > VSMALL
00135                 );
00136 
00137                 yPlus[facei] = max(0.0, yp);
00138             }
00139         }
00140     }
00141     else
00142     {
00143         // Smooth Walls
00144         forAll(yPlus, facei)
00145         {
00146             const scalar magUpara = magUp[facei];
00147             const scalar Re = rho[facei]*magUpara*y[facei]/muw[facei];
00148             const scalar kappaRe = kappa_*Re;
00149 
00150             scalar yp = yPlusLam_;
00151             const scalar ryPlusLam = 1.0/yp;
00152 
00153             int iter = 0;
00154             scalar yPlusLast = 0.0;
00155 
00156             do
00157             {
00158                 yPlusLast = yp;
00159                 yp = (kappaRe + yp)/(1.0 + log(E_*yp));
00160 
00161             } while
00162             (
00163                 mag(ryPlusLam*(yp - yPlusLast)) > 0.0001
00164              && ++iter < 10
00165             );
00166 
00167             yPlus[facei] = max(0.0, yp);
00168         }
00169     }
00170 
00171     return tyPlus;
00172 }
00173 
00174 
00175 tmp<scalarField>
00176 mutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::calcMut() const
00177 {
00178     const label patchI = patch().index();
00179 
00180     const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
00181     const scalarField& y = rasModel.y()[patchI];
00182     const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI];
00183     const scalarField& muw = rasModel.mu().boundaryField()[patchI];
00184     const fvPatchScalarField& rho = rasModel.rho().boundaryField()[patchI];
00185 
00186     scalarField magUp = mag(Uw.patchInternalField() - Uw);
00187 
00188     tmp<scalarField> tyPlus = calcYPlus(magUp);
00189     scalarField& yPlus = tyPlus();
00190 
00191     tmp<scalarField> tmutw(new scalarField(patch().size(), 0.0));
00192     scalarField& mutw = tmutw();
00193 
00194     forAll(yPlus, facei)
00195     {
00196         if (yPlus[facei] > yPlusLam_)
00197         {
00198             const scalar Re = rho[facei]*magUp[facei]*y[facei]/muw[facei];
00199             mutw[facei] = muw[facei]*(sqr(yPlus[facei])/Re - 1);
00200         }
00201     }
00202 
00203     return tmutw;
00204 }
00205 
00206 
00207 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00208 
00209 mutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::
00210 mutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField
00211 (
00212     const fvPatch& p,
00213     const DimensionedField<scalar, volMesh>& iF
00214 )
00215 :
00216     mutWallFunctionFvPatchScalarField(p, iF),
00217     roughnessHeight_(pTraits<scalar>::zero),
00218     roughnessConstant_(pTraits<scalar>::zero),
00219     roughnessFudgeFactor_(pTraits<scalar>::zero)
00220 {}
00221 
00222 
00223 mutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::
00224 mutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField
00225 (
00226     const mutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField& ptf,
00227     const fvPatch& p,
00228     const DimensionedField<scalar, volMesh>& iF,
00229     const fvPatchFieldMapper& mapper
00230 )
00231 :
00232     mutWallFunctionFvPatchScalarField(ptf, p, iF, mapper),
00233     roughnessHeight_(ptf.roughnessHeight_),
00234     roughnessConstant_(ptf.roughnessConstant_),
00235     roughnessFudgeFactor_(ptf.roughnessFudgeFactor_)
00236 {}
00237 
00238 
00239 mutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::
00240 mutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField
00241 (
00242     const fvPatch& p,
00243     const DimensionedField<scalar, volMesh>& iF,
00244     const dictionary& dict
00245 )
00246 :
00247     mutWallFunctionFvPatchScalarField(p, iF, dict),
00248     roughnessHeight_(readScalar(dict.lookup("roughnessHeight"))),
00249     roughnessConstant_(readScalar(dict.lookup("roughnessConstant"))),
00250     roughnessFudgeFactor_(readScalar(dict.lookup("roughnessFudgeFactor")))
00251 {}
00252 
00253 
00254 mutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::
00255 mutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField
00256 (
00257     const mutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField& rwfpsf
00258 )
00259 :
00260     mutWallFunctionFvPatchScalarField(rwfpsf),
00261     roughnessHeight_(rwfpsf.roughnessHeight_),
00262     roughnessConstant_(rwfpsf.roughnessConstant_),
00263     roughnessFudgeFactor_(rwfpsf.roughnessFudgeFactor_)
00264 {}
00265 
00266 
00267 mutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::
00268 mutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField
00269 (
00270     const mutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField& rwfpsf,
00271     const DimensionedField<scalar, volMesh>& iF
00272 )
00273 :
00274     mutWallFunctionFvPatchScalarField(rwfpsf, iF),
00275     roughnessHeight_(rwfpsf.roughnessHeight_),
00276     roughnessConstant_(rwfpsf.roughnessConstant_),
00277     roughnessFudgeFactor_(rwfpsf.roughnessFudgeFactor_)
00278 {}
00279 
00280 
00281 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00282 
00283 tmp<scalarField>
00284 mutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::yPlus() const
00285 {
00286     const label patchI = patch().index();
00287 
00288     const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
00289     const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI];
00290     const scalarField magUp = mag(Uw.patchInternalField() - Uw);
00291 
00292     return calcYPlus(magUp);
00293 }
00294 
00295 
00296 void mutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::write
00297 (
00298     Ostream& os
00299 ) const
00300 {
00301     fixedValueFvPatchScalarField::write(os);
00302     writeLocalEntries(os);
00303     os.writeKeyword("roughnessHeight")
00304         << roughnessHeight_ << token::END_STATEMENT << nl;
00305     os.writeKeyword("roughnessConstant")
00306         << roughnessConstant_ << token::END_STATEMENT << nl;
00307     os.writeKeyword("roughnessFudgeFactor")
00308         << roughnessFudgeFactor_ << token::END_STATEMENT << nl;
00309 }
00310 
00311 
00312 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00313 
00314 makePatchTypeField
00315 (
00316     fvPatchScalarField,
00317     mutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField
00318 );
00319 
00320 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00321 
00322 } // End namespace RASModels
00323 } // End namespace compressible
00324 } // End namespace Foam
00325 
00326 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd