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

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