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 / epsilonWallFunctions / epsilonWallFunction / epsilonWallFunctionFvPatchScalarField.C
blobde9a768d1990a2993139beb2f567637250f143f2
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 "epsilonWallFunctionFvPatchScalarField.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 epsilonWallFunctionFvPatchScalarField::checkType()
47     if (!isA<wallFvPatch>(patch()))
48     {
49         FatalErrorIn("epsilonWallFunctionFvPatchScalarField::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 epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField
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)
77     checkType();
81 epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField
83     const epsilonWallFunctionFvPatchScalarField& ptf,
84     const fvPatch& p,
85     const DimensionedField<scalar, volMesh>& iF,
86     const fvPatchFieldMapper& mapper
89     fixedInternalValueFvPatchField<scalar>(ptf, p, iF, mapper),
90     UName_(ptf.UName_),
91     kName_(ptf.kName_),
92     GName_(ptf.GName_),
93     nuName_(ptf.nuName_),
94     nutName_(ptf.nutName_),
95     Cmu_(ptf.Cmu_),
96     kappa_(ptf.kappa_),
97     E_(ptf.E_)
99     checkType();
103 epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField
105     const fvPatch& p,
106     const DimensionedField<scalar, volMesh>& iF,
107     const dictionary& dict
110     fixedInternalValueFvPatchField<scalar>(p, iF, dict),
111     UName_(dict.lookupOrDefault<word>("U", "U")),
112     kName_(dict.lookupOrDefault<word>("k", "k")),
113     GName_(dict.lookupOrDefault<word>("G", "RASModel::G")),
114     nuName_(dict.lookupOrDefault<word>("nu", "nu")),
115     nutName_(dict.lookupOrDefault<word>("nut", "nut")),
116     Cmu_(dict.lookupOrDefault<scalar>("Cmu", 0.09)),
117     kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
118     E_(dict.lookupOrDefault<scalar>("E", 9.8))
120     checkType();
124 epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField
126     const epsilonWallFunctionFvPatchScalarField& ewfpsf
129     fixedInternalValueFvPatchField<scalar>(ewfpsf),
130     UName_(ewfpsf.UName_),
131     kName_(ewfpsf.kName_),
132     GName_(ewfpsf.GName_),
133     nuName_(ewfpsf.nuName_),
134     nutName_(ewfpsf.nutName_),
135     Cmu_(ewfpsf.Cmu_),
136     kappa_(ewfpsf.kappa_),
137     E_(ewfpsf.E_)
139     checkType();
143 epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField
145     const epsilonWallFunctionFvPatchScalarField& ewfpsf,
146     const DimensionedField<scalar, volMesh>& iF
149     fixedInternalValueFvPatchField<scalar>(ewfpsf, iF),
150     UName_(ewfpsf.UName_),
151     kName_(ewfpsf.kName_),
152     GName_(ewfpsf.GName_),
153     nuName_(ewfpsf.nuName_),
154     nutName_(ewfpsf.nutName_),
155     Cmu_(ewfpsf.Cmu_),
156     kappa_(ewfpsf.kappa_),
157     E_(ewfpsf.E_)
159     checkType();
163 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
165 void epsilonWallFunctionFvPatchScalarField::updateCoeffs()
167     if (updated())
168     {
169         return;
170     }
172     const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
173     const scalar yPlusLam = rasModel.yPlusLam(kappa_, E_);
174     const scalarField& y = rasModel.y()[patch().index()];
176     const scalar Cmu25 = pow(Cmu_, 0.25);
177     const scalar Cmu75 = pow(Cmu_, 0.75);
179     volScalarField& G = const_cast<volScalarField&>
180         (db().lookupObject<volScalarField>(GName_));
182     volScalarField& epsilon = const_cast<volScalarField&>
183         (db().lookupObject<volScalarField>(dimensionedInternalField().name()));
185     const volScalarField& k = db().lookupObject<volScalarField>(kName_);
187     const scalarField& nuw =
188         patch().lookupPatchField<volScalarField, scalar>(nuName_);
190     const scalarField& nutw =
191         patch().lookupPatchField<volScalarField, scalar>(nutName_);
193     const fvPatchVectorField& Uw =
194         patch().lookupPatchField<volVectorField, vector>(UName_);
196     const scalarField magGradUw = mag(Uw.snGrad());
198     // Set epsilon and G
199     forAll(nutw, faceI)
200     {
201         label faceCellI = patch().faceCells()[faceI];
203         scalar yPlus = Cmu25*y[faceI]*sqrt(k[faceCellI])/nuw[faceI];
205         epsilon[faceCellI] = Cmu75*pow(k[faceCellI], 1.5)/(kappa_*y[faceI]);
207         if (yPlus > yPlusLam)
208         {
209             G[faceCellI] =
210                 (nutw[faceI] + nuw[faceI])
211                *magGradUw[faceI]
212                *Cmu25*sqrt(k[faceCellI])
213                /(kappa_*y[faceI]);
214         }
215         else
216         {
217             G[faceCellI] = 0.0;
218         }
219     }
221     // TODO: perform averaging for cells sharing more than one boundary face
223     fixedInternalValueFvPatchField<scalar>::updateCoeffs();
227 void epsilonWallFunctionFvPatchScalarField::evaluate
229     const Pstream::commsTypes commsType
232     fixedInternalValueFvPatchField<scalar>::evaluate(commsType);
236 void epsilonWallFunctionFvPatchScalarField::write(Ostream& os) const
238     fixedInternalValueFvPatchField<scalar>::write(os);
239     writeEntryIfDifferent<word>(os, "U", "U", UName_);
240     writeEntryIfDifferent<word>(os, "k", "k", kName_);
241     writeEntryIfDifferent<word>(os, "G", "RASModel::G", GName_);
242     writeEntryIfDifferent<word>(os, "nu", "nu", nuName_);
243     writeEntryIfDifferent<word>(os, "nut", "nut", nutName_);
244     os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl;
245     os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl;
246     os.writeKeyword("E") << E_ << token::END_STATEMENT << nl;
247     writeEntry("value", os);
251 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
253 makePatchTypeField
255     fvPatchScalarField,
256     epsilonWallFunctionFvPatchScalarField
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261 } // End namespace RASModels
262 } // End namespace incompressible
263 } // End namespace Foam
265 // ************************************************************************* //