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

muSgsWallFunctionFvPatchScalarField.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 "muSgsWallFunctionFvPatchScalarField.H"
00027 #include <compressibleLESModels/LESModel.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 compressible
00037 {
00038 namespace LESModels
00039 {
00040 
00041 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00042 
00043 muSgsWallFunctionFvPatchScalarField::muSgsWallFunctionFvPatchScalarField
00044 (
00045     const fvPatch& p,
00046     const DimensionedField<scalar, volMesh>& iF
00047 )
00048 :
00049     fixedValueFvPatchScalarField(p, iF),
00050     UName_("U"),
00051     rhoName_("rho"),
00052     muName_("mu"),
00053     kappa_(0.41),
00054     E_(9.8)
00055 {}
00056 
00057 
00058 muSgsWallFunctionFvPatchScalarField::muSgsWallFunctionFvPatchScalarField
00059 (
00060     const muSgsWallFunctionFvPatchScalarField& ptf,
00061     const fvPatch& p,
00062     const DimensionedField<scalar, volMesh>& iF,
00063     const fvPatchFieldMapper& mapper
00064 )
00065 :
00066     fixedValueFvPatchScalarField(ptf, p, iF, mapper),
00067     UName_(ptf.UName_),
00068     rhoName_(ptf.rhoName_),
00069     muName_(ptf.muName_),
00070     kappa_(ptf.kappa_),
00071     E_(ptf.E_)
00072 {}
00073 
00074 
00075 muSgsWallFunctionFvPatchScalarField::muSgsWallFunctionFvPatchScalarField
00076 (
00077     const fvPatch& p,
00078     const DimensionedField<scalar, volMesh>& iF,
00079     const dictionary& dict
00080 )
00081 :
00082     fixedValueFvPatchScalarField(p, iF, dict),
00083     UName_(dict.lookupOrDefault<word>("U", "U")),
00084     rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
00085     muName_(dict.lookupOrDefault<word>("mu", "mu")),
00086     kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
00087     E_(dict.lookupOrDefault<scalar>("E", 9.8))
00088 {}
00089 
00090 
00091 muSgsWallFunctionFvPatchScalarField::muSgsWallFunctionFvPatchScalarField
00092 (
00093     const muSgsWallFunctionFvPatchScalarField& mwfpsf
00094 )
00095 :
00096     fixedValueFvPatchScalarField(mwfpsf),
00097     UName_(mwfpsf.UName_),
00098     rhoName_(mwfpsf.rhoName_),
00099     muName_(mwfpsf.muName_),
00100     kappa_(mwfpsf.kappa_),
00101     E_(mwfpsf.E_)
00102 {}
00103 
00104 
00105 muSgsWallFunctionFvPatchScalarField::muSgsWallFunctionFvPatchScalarField
00106 (
00107     const muSgsWallFunctionFvPatchScalarField& mwfpsf,
00108     const DimensionedField<scalar, volMesh>& iF
00109 )
00110 :
00111     fixedValueFvPatchScalarField(mwfpsf, iF),
00112     UName_(mwfpsf.UName_),
00113     rhoName_(mwfpsf.rhoName_),
00114     muName_(mwfpsf.muName_),
00115     kappa_(mwfpsf.kappa_),
00116     E_(mwfpsf.E_)
00117 {}
00118 
00119 
00120 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00121 
00122 void muSgsWallFunctionFvPatchScalarField::evaluate
00123 (
00124     const Pstream::commsTypes
00125 )
00126 {
00127     const scalarField& ry = patch().deltaCoeffs();
00128 
00129     const fvPatchVectorField& U =
00130         patch().lookupPatchField<volVectorField, vector>(UName_);
00131 
00132     scalarField magUp = mag(U.patchInternalField() - U);
00133 
00134     const scalarField& muw =
00135         patch().lookupPatchField<volScalarField, scalar>(muName_);
00136 
00137     const scalarField& rhow =
00138         patch().lookupPatchField<volScalarField, scalar>(rhoName_);
00139 
00140     scalarField& muSgsw = *this;
00141 
00142     scalarField magFaceGradU = mag(U.snGrad());
00143 
00144     forAll(muSgsw, facei)
00145     {
00146         scalar magUpara = magUp[facei];
00147 
00148         scalar utau =
00149             sqrt((muSgsw[facei] + muw[facei])*magFaceGradU[facei]/rhow[facei]);
00150 
00151         if (utau > 0)
00152         {
00153             int iter = 0;
00154             scalar err = GREAT;
00155 
00156             do
00157             {
00158                 scalar kUu = kappa_*magUpara/utau;
00159                 scalar fkUu = exp(kUu) - 1 - kUu*(1 + 0.5*kUu);
00160 
00161                 scalar f =
00162                     - utau/(ry[facei]*muw[facei]/rhow[facei])
00163                     + magUpara/utau
00164                     + 1/E_*(fkUu - 1.0/6.0*kUu*sqr(kUu));
00165 
00166                 scalar df =
00167                     - 1.0/(ry[facei]*muw[facei]/rhow[facei])
00168                     - magUpara/sqr(utau)
00169                     - 1/E_*kUu*fkUu/utau;
00170 
00171                 scalar utauNew = utau - f/df;
00172                 err = mag((utau - utauNew)/utau);
00173                 utau = utauNew;
00174 
00175             } while (utau > VSMALL && err > 0.01 && ++iter < 10);
00176 
00177             muSgsw[facei] =
00178                 max
00179                 (
00180                     rhow[facei]*sqr(utau)/magFaceGradU[facei] - muw[facei],
00181                     0.0
00182                 );
00183         }
00184         else
00185         {
00186             muSgsw[facei] = 0;
00187         }
00188     }
00189 }
00190 
00191 
00192 void muSgsWallFunctionFvPatchScalarField::write(Ostream& os) const
00193 {
00194     fvPatchField<scalar>::write(os);
00195     writeEntryIfDifferent<word>(os, "U", "U", UName_);
00196     writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
00197     writeEntryIfDifferent<word>(os, "mu", "mu", muName_);
00198     os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl;
00199     os.writeKeyword("E") << E_ << token::END_STATEMENT << nl;
00200     writeEntry("value", os);
00201 }
00202 
00203 
00204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00205 
00206 makePatchTypeField
00207 (
00208     fvPatchScalarField,
00209     muSgsWallFunctionFvPatchScalarField
00210 );
00211 
00212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00213 
00214 } // End namespace LESModels
00215 } // End namespace compressible
00216 } // End namespace Foam
00217 
00218 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines