wall-functions: Added "updated" check and avoid /0 in the case that the velocity...
[OpenFOAM-1.6.x.git] / src / turbulenceModels / compressible / RAS / derivedFvPatchFields / wallFunctions / omegaWallFunctions / omegaWallFunction / omegaWallFunctionFvPatchScalarField.C
blob171d60f07e7c0426db325afbaa969e92ce7cf564
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2008-2009 OpenCFD Ltd.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "omegaWallFunctionFvPatchScalarField.H"
28 #include "RASModel.H"
29 #include "fvPatchFieldMapper.H"
30 #include "volFields.H"
31 #include "addToRunTimeSelectionTable.H"
32 #include "wallFvPatch.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 namespace Foam
38 namespace compressible
40 namespace RASModels
43 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
45 void omegaWallFunctionFvPatchScalarField::checkType()
47     if (!isA<wallFvPatch>(patch()))
48     {
49         FatalErrorIn("omegaWallFunctionFvPatchScalarField::checkType()")
50             << "Invalid wall function specification" << nl
51             << "    Patch type for patch " << patch().name()
52             << " must be wall" << nl
53             << "    Current patch type is " << patch().type() << nl << endl
54             << abort(FatalError);
55     }
59 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
61 omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField
63     const fvPatch& p,
64     const DimensionedField<scalar, volMesh>& iF
67     fixedInternalValueFvPatchField<scalar>(p, iF),
68     UName_("U"),
69     rhoName_("rho"),
70     kName_("k"),
71     GName_("RASModel::G"),
72     muName_("mu"),
73     mutName_("mut"),
74     Cmu_(0.09),
75     kappa_(0.41),
76     E_(9.8),
77     beta1_(0.075)
79     checkType();
83 omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField
85     const omegaWallFunctionFvPatchScalarField& ptf,
86     const fvPatch& p,
87     const DimensionedField<scalar, volMesh>& iF,
88     const fvPatchFieldMapper& mapper
91     fixedInternalValueFvPatchField<scalar>(ptf, p, iF, mapper),
92     UName_(ptf.UName_),
93     rhoName_(ptf.rhoName_),
94     kName_(ptf.kName_),
95     GName_(ptf.GName_),
96     muName_(ptf.muName_),
97     mutName_(ptf.mutName_),
98     Cmu_(ptf.Cmu_),
99     kappa_(ptf.kappa_),
100     E_(ptf.E_),
101     beta1_(ptf.beta1_)
103     checkType();
107 omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField
109     const fvPatch& p,
110     const DimensionedField<scalar, volMesh>& iF,
111     const dictionary& dict
114     fixedInternalValueFvPatchField<scalar>(p, iF, dict),
115     UName_(dict.lookupOrDefault<word>("U", "U")),
116     rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
117     kName_(dict.lookupOrDefault<word>("k", "k")),
118     GName_(dict.lookupOrDefault<word>("G", "RASModel::G")),
119     muName_(dict.lookupOrDefault<word>("mu", "mu")),
120     mutName_(dict.lookupOrDefault<word>("mut", "mut")),
121     Cmu_(dict.lookupOrDefault<scalar>("Cmu", 0.09)),
122     kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
123     E_(dict.lookupOrDefault<scalar>("E", 9.8)),
124     beta1_(dict.lookupOrDefault<scalar>("beta1", 0.075))
126     checkType();
130 omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField
132     const omegaWallFunctionFvPatchScalarField& owfpsf
135     fixedInternalValueFvPatchField<scalar>(owfpsf),
136     UName_(owfpsf.UName_),
137     rhoName_(owfpsf.rhoName_),
138     kName_(owfpsf.kName_),
139     GName_(owfpsf.GName_),
140     muName_(owfpsf.muName_),
141     mutName_(owfpsf.mutName_),
142     Cmu_(owfpsf.Cmu_),
143     kappa_(owfpsf.kappa_),
144     E_(owfpsf.E_),
145     beta1_(owfpsf.beta1_)
147     checkType();
151 omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField
153     const omegaWallFunctionFvPatchScalarField& owfpsf,
154     const DimensionedField<scalar, volMesh>& iF
157     fixedInternalValueFvPatchField<scalar>(owfpsf, iF),
158     UName_(owfpsf.UName_),
159     rhoName_(owfpsf.rhoName_),
160     kName_(owfpsf.kName_),
161     GName_(owfpsf.GName_),
162     muName_(owfpsf.muName_),
163     mutName_(owfpsf.mutName_),
164     Cmu_(owfpsf.Cmu_),
165     kappa_(owfpsf.kappa_),
166     E_(owfpsf.E_),
167     beta1_(owfpsf.beta1_)
169     checkType();
173 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
175 void omegaWallFunctionFvPatchScalarField::updateCoeffs()
177     if (updated())
178     {
179         return;
180     }
182     const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
183     const scalar yPlusLam = rasModel.yPlusLam(kappa_, E_);
184     const scalarField& y = rasModel.y()[patch().index()];
186     const scalar Cmu25 = pow(Cmu_, 0.25);
188     volScalarField& G = const_cast<volScalarField&>
189         (db().lookupObject<volScalarField>(GName_));
191     volScalarField& omega = const_cast<volScalarField&>
192         (db().lookupObject<volScalarField>(dimensionedInternalField().name()));
194     const scalarField& k = db().lookupObject<volScalarField>(kName_);
196     const scalarField& rhow =
197         patch().lookupPatchField<volScalarField, scalar>(rhoName_);
199     const scalarField& muw =
200         patch().lookupPatchField<volScalarField, scalar>(muName_);
202     const scalarField& mutw =
203         patch().lookupPatchField<volScalarField, scalar>(mutName_);
205     const fvPatchVectorField& Uw =
206         patch().lookupPatchField<volVectorField, vector>(UName_);
208     const scalarField magGradUw = mag(Uw.snGrad());
210     // Set omega and G
211     forAll(mutw, faceI)
212     {
213         label faceCellI = patch().faceCells()[faceI];
215         scalar yPlus =
216             Cmu25*y[faceI]*sqrt(k[faceCellI])
217            /(muw[faceI]/rhow[faceI]);
219         scalar omegaVis = 6.0*(muw[faceI]/rhow[faceI])/(beta1_*sqr(y[faceI]));
221         scalar omegaLog = sqrt(k[faceCellI])/(Cmu25*kappa_*y[faceI]);
223         omega[faceCellI] = sqrt(sqr(omegaVis) + sqr(omegaLog));
225         if (yPlus > yPlusLam)
226         {
227             G[faceCellI] =
228                 (mutw[faceI] + muw[faceI])
229                *magGradUw[faceI]
230                *Cmu25*sqrt(k[faceCellI])
231                /(kappa_*y[faceI]);
232         }
233         else
234         {
235             G[faceCellI] = 0.0;
236         }
237     }
239     // TODO: perform averaging for cells sharing more than one boundary face
241     fixedInternalValueFvPatchField<scalar>::updateCoeffs();
245 void omegaWallFunctionFvPatchScalarField::write(Ostream& os) const
247     fixedInternalValueFvPatchField<scalar>::write(os);
248     writeEntryIfDifferent<word>(os, "U", "U", UName_);
249     writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
250     writeEntryIfDifferent<word>(os, "k", "k", kName_);
251     writeEntryIfDifferent<word>(os, "G", "RASModel::G", GName_);
252     writeEntryIfDifferent<word>(os, "mu", "mu", muName_);
253     writeEntryIfDifferent<word>(os, "mut", "mut", mutName_);
254     os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl;
255     os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl;
256     os.writeKeyword("E") << E_ << token::END_STATEMENT << nl;
257     os.writeKeyword("beta1") << beta1_ << token::END_STATEMENT << nl;
258     writeEntry("value", os);
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
264 makePatchTypeField
266     fvPatchScalarField,
267     omegaWallFunctionFvPatchScalarField
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 } // End namespace RASModels
273 } // End namespace compressible
274 } // End namespace Foam
276 // ************************************************************************* //