FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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