wall-functions: Added "updated" check and avoid /0 in the case that the velocity...
[OpenFOAM-1.6.x.git] / src / turbulenceModels / incompressible / RAS / derivedFvPatchFields / wallFunctions / omegaWallFunctions / omegaWallFunction / omegaWallFunctionFvPatchScalarField.C
blob4da1a3063d24b2f85a89c1fbc6810973d39dd5bd
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 incompressible
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     kName_("k"),
70     GName_("RASModel::G"),
71     nuName_("nu"),
72     nutName_("nut"),
73     Cmu_(0.09),
74     kappa_(0.41),
75     E_(9.8),
76     beta1_(0.075)
78     checkType();
82 omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField
84     const omegaWallFunctionFvPatchScalarField& ptf,
85     const fvPatch& p,
86     const DimensionedField<scalar, volMesh>& iF,
87     const fvPatchFieldMapper& mapper
90     fixedInternalValueFvPatchField<scalar>(ptf, p, iF, mapper),
91     UName_(ptf.UName_),
92     kName_(ptf.kName_),
93     GName_(ptf.GName_),
94     nuName_(ptf.nuName_),
95     nutName_(ptf.nutName_),
96     Cmu_(ptf.Cmu_),
97     kappa_(ptf.kappa_),
98     E_(ptf.E_),
99     beta1_(ptf.beta1_)
101     checkType();
105 omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField
107     const fvPatch& p,
108     const DimensionedField<scalar, volMesh>& iF,
109     const dictionary& dict
112     fixedInternalValueFvPatchField<scalar>(p, iF, dict),
113     UName_(dict.lookupOrDefault<word>("U", "U")),
114     kName_(dict.lookupOrDefault<word>("k", "k")),
115     GName_(dict.lookupOrDefault<word>("G", "RASModel::G")),
116     nuName_(dict.lookupOrDefault<word>("nu", "nu")),
117     nutName_(dict.lookupOrDefault<word>("nut", "nut")),
118     Cmu_(dict.lookupOrDefault<scalar>("Cmu", 0.09)),
119     kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
120     E_(dict.lookupOrDefault<scalar>("E", 9.8)),
121     beta1_(dict.lookupOrDefault<scalar>("beta1", 0.075))
123     checkType();
127 omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField
129     const omegaWallFunctionFvPatchScalarField& owfpsf
132     fixedInternalValueFvPatchField<scalar>(owfpsf),
133     UName_(owfpsf.UName_),
134     kName_(owfpsf.kName_),
135     GName_(owfpsf.GName_),
136     nuName_(owfpsf.nuName_),
137     nutName_(owfpsf.nutName_),
138     Cmu_(owfpsf.Cmu_),
139     kappa_(owfpsf.kappa_),
140     E_(owfpsf.E_),
141     beta1_(owfpsf.beta1_)
143     checkType();
147 omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField
149     const omegaWallFunctionFvPatchScalarField& owfpsf,
150     const DimensionedField<scalar, volMesh>& iF
153     fixedInternalValueFvPatchField<scalar>(owfpsf, iF),
154     UName_(owfpsf.UName_),
155     kName_(owfpsf.kName_),
156     GName_(owfpsf.GName_),
157     nuName_(owfpsf.nuName_),
158     nutName_(owfpsf.nutName_),
159     Cmu_(owfpsf.Cmu_),
160     kappa_(owfpsf.kappa_),
161     E_(owfpsf.E_),
162     beta1_(owfpsf.beta1_)
164     checkType();
168 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
170 void omegaWallFunctionFvPatchScalarField::updateCoeffs()
172     if (updated())
173     {
174         return;
175     }
177     const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
178     const scalar yPlusLam = rasModel.yPlusLam(kappa_, E_);
179     const scalarField& y = rasModel.y()[patch().index()];
181     const scalar Cmu25 = pow(Cmu_, 0.25);
183     volScalarField& G = const_cast<volScalarField&>
184         (db().lookupObject<volScalarField>(GName_));
186     volScalarField& omega = const_cast<volScalarField&>
187         (db().lookupObject<volScalarField>(dimensionedInternalField().name()));
189     const scalarField& k = db().lookupObject<volScalarField>(kName_);
191     const scalarField& nuw =
192         patch().lookupPatchField<volScalarField, scalar>(nuName_);
194     const scalarField& nutw =
195         patch().lookupPatchField<volScalarField, scalar>(nutName_);
197     const fvPatchVectorField& Uw =
198         patch().lookupPatchField<volVectorField, vector>(UName_);
200     vectorField n = patch().nf();
202     const scalarField magGradUw = mag(Uw.snGrad());
204     // Set omega and G
205     forAll(nutw, faceI)
206     {
207         label faceCellI = patch().faceCells()[faceI];
209         scalar yPlus = Cmu25*y[faceI]*sqrt(k[faceCellI])/nuw[faceI];
211         scalar omegaVis = 6.0*nuw[faceI]/(beta1_*sqr(y[faceI]));
213         scalar omegaLog = sqrt(k[faceCellI])/(Cmu25*kappa_*y[faceI]);
215         omega[faceCellI] = sqrt(sqr(omegaVis) + sqr(omegaLog));
217         if (yPlus > yPlusLam)
218         {
219             G[faceCellI] =
220                 (nutw[faceI] + nuw[faceI])
221                *magGradUw[faceI]
222                *Cmu25*sqrt(k[faceCellI])
223                /(kappa_*y[faceI]);
224         }
225         else
226         {
227             G[faceCellI] = 0.0;
228         }
229     }
231     // TODO: perform averaging for cells sharing more than one boundary face
233     fixedInternalValueFvPatchField<scalar>::updateCoeffs();
237 void omegaWallFunctionFvPatchScalarField::write(Ostream& os) const
239     fixedInternalValueFvPatchField<scalar>::write(os);
240     writeEntryIfDifferent<word>(os, "U", "U", UName_);
241     writeEntryIfDifferent<word>(os, "k", "k", kName_);
242     writeEntryIfDifferent<word>(os, "G", "RASModel::G", GName_);
243     writeEntryIfDifferent<word>(os, "nu", "nu", nuName_);
244     writeEntryIfDifferent<word>(os, "nut", "nut", nutName_);
245     os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl;
246     os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl;
247     os.writeKeyword("E") << E_ << token::END_STATEMENT << nl;
248     os.writeKeyword("beta1") << beta1_ << token::END_STATEMENT << nl;
249     writeEntry("value", os);
253 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 makePatchTypeField
257     fvPatchScalarField,
258     omegaWallFunctionFvPatchScalarField
261 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 } // End namespace RASModels
264 } // End namespace incompressible
265 } // End namespace Foam
267 // ************************************************************************* //