BUG: Corrected reference to tmp in incompressible RAS models (mantis #360)
[OpenFOAM-2.0.x.git] / src / turbulenceModels / incompressible / RAS / derivedFvPatchFields / wallFunctions / kappatWallFunctions / kappatJayatillekeWallFunction / kappatJayatillekeWallFunctionFvPatchScalarField.C
blob917c65ca5f0beab8a0a8d8e2ab6d310a8609091a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "kappatJayatillekeWallFunctionFvPatchScalarField.H"
27 #include "RASModel.H"
28 #include "fvPatchFieldMapper.H"
29 #include "volFields.H"
30 #include "wallFvPatch.H"
31 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 namespace Foam
37 namespace incompressible
39 namespace RASModels
42 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
44 scalar kappatJayatillekeWallFunctionFvPatchScalarField::tolerance_ = 0.01;
45 label kappatJayatillekeWallFunctionFvPatchScalarField::maxIters_ = 10;
47 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
49 void kappatJayatillekeWallFunctionFvPatchScalarField::checkType()
51     if (!isA<wallFvPatch>(patch()))
52     {
53         FatalErrorIn
54         (
55             "kappatJayatillekeWallFunctionFvPatchScalarField::checkType()"
56         )   << "Invalid wall function specification" << nl
57             << "    Patch type for patch " << patch().name()
58             << " must be wall" << nl
59             << "    Current patch type is " << patch().type() << nl << endl
60             << abort(FatalError);
61     }
65 scalar kappatJayatillekeWallFunctionFvPatchScalarField::Psmooth
67     const scalar Prat
68 ) const
70     return 9.24*(pow(Prat, 0.75) - 1.0)*(1.0 + 0.28*exp(-0.007*Prat));
74 scalar kappatJayatillekeWallFunctionFvPatchScalarField::yPlusTherm
76     const scalar P,
77     const scalar Prat
78 ) const
80     scalar ypt = 11.0;
82     for (int i=0; i<maxIters_; i++)
83     {
84         scalar f = ypt - (log(E_*ypt)/kappa_ + P)/Prat;
85         scalar df = 1.0 - 1.0/(ypt*kappa_*Prat);
86         scalar yptNew = ypt - f/df;
88         if (yptNew < VSMALL)
89         {
90             return 0;
91         }
92         else if (mag(yptNew - ypt) < tolerance_)
93         {
94             return yptNew;
95         }
96         else
97         {
98             ypt = yptNew;
99         }
100      }
102     return ypt;
106 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
108 kappatJayatillekeWallFunctionFvPatchScalarField::
109 kappatJayatillekeWallFunctionFvPatchScalarField
111     const fvPatch& p,
112     const DimensionedField<scalar, volMesh>& iF
115     fixedValueFvPatchScalarField(p, iF),
116     Prt_(0.85),
117     Cmu_(0.09),
118     kappa_(0.41),
119     E_(9.8)
121     checkType();
125 kappatJayatillekeWallFunctionFvPatchScalarField::
126 kappatJayatillekeWallFunctionFvPatchScalarField
128     const kappatJayatillekeWallFunctionFvPatchScalarField& ptf,
129     const fvPatch& p,
130     const DimensionedField<scalar, volMesh>& iF,
131     const fvPatchFieldMapper& mapper
134     fixedValueFvPatchScalarField(ptf, p, iF, mapper),
135     Prt_(ptf.Prt_),
136     Cmu_(ptf.Cmu_),
137     kappa_(ptf.kappa_),
138     E_(ptf.E_)
140     checkType();
144 kappatJayatillekeWallFunctionFvPatchScalarField::
145 kappatJayatillekeWallFunctionFvPatchScalarField
147     const fvPatch& p,
148     const DimensionedField<scalar, volMesh>& iF,
149     const dictionary& dict
152     fixedValueFvPatchScalarField(p, iF, dict),
153     Prt_(readScalar(dict.lookup("Prt"))), // force read to avoid ambiguity
154     Cmu_(dict.lookupOrDefault<scalar>("Cmu", 0.09)),
155     kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
156     E_(dict.lookupOrDefault<scalar>("E", 9.8))
158     checkType();
162 kappatJayatillekeWallFunctionFvPatchScalarField::
163 kappatJayatillekeWallFunctionFvPatchScalarField
165     const kappatJayatillekeWallFunctionFvPatchScalarField& wfpsf
168     fixedValueFvPatchScalarField(wfpsf),
169     Prt_(wfpsf.Prt_),
170     Cmu_(wfpsf.Cmu_),
171     kappa_(wfpsf.kappa_),
172     E_(wfpsf.E_)
174     checkType();
178 kappatJayatillekeWallFunctionFvPatchScalarField::
179 kappatJayatillekeWallFunctionFvPatchScalarField
181     const kappatJayatillekeWallFunctionFvPatchScalarField& wfpsf,
182     const DimensionedField<scalar, volMesh>& iF
185     fixedValueFvPatchScalarField(wfpsf, iF),
186     Prt_(wfpsf.Prt_),
187     Cmu_(wfpsf.Cmu_),
188     kappa_(wfpsf.kappa_),
189     E_(wfpsf.E_)
191     checkType();
195 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
197 void kappatJayatillekeWallFunctionFvPatchScalarField::updateCoeffs()
199     if (updated())
200     {
201         return;
202     }
204     const label patchI = patch().index();
206     // Retrieve turbulence properties from model
207     const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
208     const scalar Cmu25 = pow(Cmu_, 0.25);
209     const scalarField& y = rasModel.y()[patchI];
210     const tmp<volScalarField> tnu = rasModel.nu();
211     const volScalarField& nu = tnu();
212     const scalarField& nuw = nu.boundaryField()[patchI];
213     const tmp<volScalarField> tk = rasModel.k();
214     const volScalarField& k = tk();
216     // Molecular Prandtl number
217     const scalar
218         Pr(dimensionedScalar(rasModel.transport().lookup("Pr")).value());
220     // Populate boundary values
221     scalarField& kappatw = *this;
222     forAll(kappatw, faceI)
223     {
224         label faceCellI = patch().faceCells()[faceI];
226         // y+
227         scalar yPlus = Cmu25*sqrt(k[faceCellI])*y[faceI]/nuw[faceI];
229         // Molecular-to-turbulent Prandtl number ratio
230         scalar Prat = Pr/Prt_;
232         // Thermal sublayer thickness
233         scalar P = Psmooth(Prat);
234         scalar yPlusTherm = this->yPlusTherm(P, Prat);
236         // Update turbulent thermal conductivity
237         if (yPlus > yPlusTherm)
238         {
239             scalar nu = nuw[faceI];
240             scalar kt = nu*(yPlus/(Prt_*(log(E_*yPlus)/kappa_ + P)) - 1/Pr);
241             kappatw[faceI] = max(0.0, kt);
242         }
243         else
244         {
245             kappatw[faceI] = 0.0;
246         }
247     }
249     fixedValueFvPatchField<scalar>::updateCoeffs();
253 void kappatJayatillekeWallFunctionFvPatchScalarField::write(Ostream& os) const
255     fvPatchField<scalar>::write(os);
256     os.writeKeyword("Prt") << Prt_ << token::END_STATEMENT << nl;
257     os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl;
258     os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl;
259     os.writeKeyword("E") << E_ << token::END_STATEMENT << nl;
260     writeEntry("value", os);
264 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
266 makePatchTypeField
268     fvPatchScalarField,
269     kappatJayatillekeWallFunctionFvPatchScalarField
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274 } // End namespace RASModels
275 } // End namespace incompressible
276 } // End namespace Foam
278 // ************************************************************************* //