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

nutRoughWallFunctionFvPatchScalarField.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-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 "nutRoughWallFunctionFvPatchScalarField.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 scalar nutRoughWallFunctionFvPatchScalarField::fnRough
00044 (
00045     const scalar KsPlus,
00046     const scalar Cs
00047 ) const
00048 {
00049     // Return fn based on non-dimensional roughness height
00050 
00051     if (KsPlus < 90.0)
00052     {
00053         return pow
00054         (
00055             (KsPlus - 2.25)/87.75 + Cs*KsPlus,
00056             sin(0.4258*(log(KsPlus) - 0.811))
00057         );
00058     }
00059     else
00060     {
00061         return (1.0 + Cs*KsPlus);
00062     }
00063 }
00064 
00065 
00066 tmp<scalarField> nutRoughWallFunctionFvPatchScalarField::calcNut() const
00067 {
00068     const label patchI = patch().index();
00069 
00070     const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
00071     const scalarField& y = rasModel.y()[patchI];
00072     const tmp<volScalarField> tk = rasModel.k();
00073     const volScalarField& k = tk();
00074     const scalarField& nuw = rasModel.nu().boundaryField()[patchI];
00075 
00076     const scalar Cmu25 = pow(Cmu_, 0.25);
00077 
00078     tmp<scalarField> tnutw(new scalarField(*this));
00079     scalarField& nutw = tnutw();
00080 
00081     forAll(nutw, faceI)
00082     {
00083         label faceCellI = patch().faceCells()[faceI];
00084 
00085         scalar uStar = Cmu25*sqrt(k[faceCellI]);
00086         scalar yPlus = uStar*y[faceI]/nuw[faceI];
00087         scalar KsPlus = uStar*Ks_[faceI]/nuw[faceI];
00088 
00089         scalar Edash = E_;
00090 
00091         if (KsPlus > 2.25)
00092         {
00093             Edash /= fnRough(KsPlus, Cs_[faceI]);
00094         }
00095 
00096         if (yPlus > yPlusLam_)
00097         {
00098             scalar limitingNutw = max(nutw[faceI], nuw[faceI]);
00099 
00100             // To avoid oscillations limit the change in the wall viscosity
00101             // which is particularly important if it temporarily becomes zero
00102             nutw[faceI] =
00103                 max
00104                 (
00105                     min
00106                     (
00107                         nuw[faceI]
00108                        *(yPlus*kappa_/log(max(Edash*yPlus, 1+1e-4)) - 1),
00109                         2*limitingNutw
00110                     ), 0.5*limitingNutw
00111                 );
00112         }
00113 
00114         if (debug)
00115         {
00116             Info<< "yPlus = " << yPlus
00117                 << ", KsPlus = " << KsPlus
00118                 << ", Edash = " << Edash
00119                 << ", nutw = " << nutw[faceI]
00120                 << endl;
00121         }
00122     }
00123 
00124     return tnutw;
00125 }
00126 
00127 
00128 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00129 
00130 nutRoughWallFunctionFvPatchScalarField::nutRoughWallFunctionFvPatchScalarField
00131 (
00132     const fvPatch& p,
00133     const DimensionedField<scalar, volMesh>& iF
00134 )
00135 :
00136     nutWallFunctionFvPatchScalarField(p, iF),
00137     Ks_(p.size(), 0.0),
00138     Cs_(p.size(), 0.0)
00139 {}
00140 
00141 
00142 nutRoughWallFunctionFvPatchScalarField::nutRoughWallFunctionFvPatchScalarField
00143 (
00144     const nutRoughWallFunctionFvPatchScalarField& ptf,
00145     const fvPatch& p,
00146     const DimensionedField<scalar, volMesh>& iF,
00147     const fvPatchFieldMapper& mapper
00148 )
00149 :
00150     nutWallFunctionFvPatchScalarField(ptf, p, iF, mapper),
00151     Ks_(ptf.Ks_, mapper),
00152     Cs_(ptf.Cs_, mapper)
00153 {}
00154 
00155 
00156 nutRoughWallFunctionFvPatchScalarField::nutRoughWallFunctionFvPatchScalarField
00157 (
00158     const fvPatch& p,
00159     const DimensionedField<scalar, volMesh>& iF,
00160     const dictionary& dict
00161 )
00162 :
00163     nutWallFunctionFvPatchScalarField(p, iF, dict),
00164     Ks_("Ks", dict, p.size()),
00165     Cs_("Cs", dict, p.size())
00166 {}
00167 
00168 
00169 nutRoughWallFunctionFvPatchScalarField::nutRoughWallFunctionFvPatchScalarField
00170 (
00171     const nutRoughWallFunctionFvPatchScalarField& rwfpsf
00172 )
00173 :
00174     nutWallFunctionFvPatchScalarField(rwfpsf),
00175     Ks_(rwfpsf.Ks_),
00176     Cs_(rwfpsf.Cs_)
00177 {}
00178 
00179 
00180 nutRoughWallFunctionFvPatchScalarField::nutRoughWallFunctionFvPatchScalarField
00181 (
00182     const nutRoughWallFunctionFvPatchScalarField& rwfpsf,
00183     const DimensionedField<scalar, volMesh>& iF
00184 )
00185 :
00186     nutWallFunctionFvPatchScalarField(rwfpsf, iF),
00187     Ks_(rwfpsf.Ks_),
00188     Cs_(rwfpsf.Cs_)
00189 {}
00190 
00191 
00192 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00193 
00194 void nutRoughWallFunctionFvPatchScalarField::autoMap
00195 (
00196     const fvPatchFieldMapper& m
00197 )
00198 {
00199     nutWallFunctionFvPatchScalarField::autoMap(m);
00200     Ks_.autoMap(m);
00201     Cs_.autoMap(m);
00202 }
00203 
00204 
00205 void nutRoughWallFunctionFvPatchScalarField::rmap
00206 (
00207     const fvPatchScalarField& ptf,
00208     const labelList& addr
00209 )
00210 {
00211     nutWallFunctionFvPatchScalarField::rmap(ptf, addr);
00212 
00213     const nutRoughWallFunctionFvPatchScalarField& nrwfpsf =
00214         refCast<const nutRoughWallFunctionFvPatchScalarField>(ptf);
00215 
00216     Ks_.rmap(nrwfpsf.Ks_, addr);
00217     Cs_.rmap(nrwfpsf.Cs_, addr);
00218 }
00219 
00220 
00221 void nutRoughWallFunctionFvPatchScalarField::write(Ostream& os) const
00222 {
00223     fvPatchField<scalar>::write(os);
00224     writeLocalEntries(os);
00225     Cs_.writeEntry("Cs", os);
00226     Ks_.writeEntry("Ks", os);
00227     writeEntry("value", os);
00228 }
00229 
00230 
00231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00232 
00233 makePatchTypeField(fvPatchScalarField, nutRoughWallFunctionFvPatchScalarField);
00234 
00235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00236 
00237 } // End namespace RASModels
00238 } // End namespace incompressible
00239 } // End namespace Foam
00240 
00241 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines