1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
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
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"
29 #include "fvPatchFieldMapper.H"
30 #include "volFields.H"
31 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 namespace compressible
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44 void epsilonWallFunctionFvPatchScalarField::checkType()
46 if (!patch().isWall())
48 FatalErrorIn("epsilonWallFunctionFvPatchScalarField::checkType()")
49 << "Invalid wall function specification" << nl
50 << " Patch type for patch " << patch().name()
51 << " must be wall" << nl
52 << " Current patch type is " << patch().type() << nl << endl
58 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
60 epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField
63 const DimensionedField<scalar, volMesh>& iF
66 fixedInternalValueFvPatchField<scalar>(p, iF),
69 GName_("RASModel::G"),
81 epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField
83 const epsilonWallFunctionFvPatchScalarField& ptf,
85 const DimensionedField<scalar, volMesh>& iF,
86 const fvPatchFieldMapper& mapper
89 fixedInternalValueFvPatchField<scalar>(ptf, p, iF, mapper),
93 rhoName_(ptf.rhoName_),
95 mutName_(ptf.mutName_),
104 epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField
107 const DimensionedField<scalar, volMesh>& iF,
108 const dictionary& dict
111 fixedInternalValueFvPatchField<scalar>(p, iF, dict),
112 UName_(dict.lookupOrDefault<word>("U", "U")),
113 kName_(dict.lookupOrDefault<word>("k", "k")),
114 GName_(dict.lookupOrDefault<word>("G", "RASModel::G")),
115 rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
116 muName_(dict.lookupOrDefault<word>("mu", "mu")),
117 mutName_(dict.lookupOrDefault<word>("mut", "mut")),
118 Cmu_(dict.lookupOrDefault<scalar>("Cmu", 0.09)),
119 kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
120 E_(dict.lookupOrDefault<scalar>("E", 9.8))
126 epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField
128 const epsilonWallFunctionFvPatchScalarField& ewfpsf
131 fixedInternalValueFvPatchField<scalar>(ewfpsf),
132 UName_(ewfpsf.UName_),
133 kName_(ewfpsf.kName_),
134 GName_(ewfpsf.GName_),
135 rhoName_(ewfpsf.rhoName_),
136 muName_(ewfpsf.muName_),
137 mutName_(ewfpsf.mutName_),
139 kappa_(ewfpsf.kappa_),
146 epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField
148 const epsilonWallFunctionFvPatchScalarField& ewfpsf,
149 const DimensionedField<scalar, volMesh>& iF
152 fixedInternalValueFvPatchField<scalar>(ewfpsf, iF),
153 UName_(ewfpsf.UName_),
154 kName_(ewfpsf.kName_),
155 GName_(ewfpsf.GName_),
156 rhoName_(ewfpsf.rhoName_),
157 muName_(ewfpsf.muName_),
158 mutName_(ewfpsf.mutName_),
160 kappa_(ewfpsf.kappa_),
167 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
169 void epsilonWallFunctionFvPatchScalarField::updateCoeffs()
176 // If G field is not present, execute zero gradient evaluation
178 if (!db().foundObject<volScalarField>(GName_))
180 zeroGradientFvPatchScalarField::updateCoeffs();
185 const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
187 const scalar Cmu25 = pow(Cmu_, 0.25);
188 const scalar Cmu75 = pow(Cmu_, 0.75);
189 const scalar yPlusLam = rasModel.yPlusLam(kappa_, E_);
191 const scalarField& y = rasModel.y()[patch().index()];
193 volScalarField& G = const_cast<volScalarField&>
194 (db().lookupObject<volScalarField>(GName_));
196 volScalarField& epsilon = const_cast<volScalarField&>
197 (db().lookupObject<volScalarField>(dimensionedInternalField().name()));
199 const volScalarField& k = db().lookupObject<volScalarField>(kName_);
201 const scalarField& rhow =
202 patch().lookupPatchField<volScalarField, scalar>(rhoName_);
204 const scalarField& muw =
205 patch().lookupPatchField<volScalarField, scalar>(muName_);
207 const scalarField& mutw =
208 patch().lookupPatchField<volScalarField, scalar>(mutName_);
210 const fvPatchVectorField& Uw =
211 patch().lookupPatchField<volVectorField, vector>(UName_);
213 const scalarField magGradUw = mag(Uw.snGrad());
218 label faceCellI = patch().faceCells()[faceI];
221 Cmu25*y[faceI]*sqrt(k[faceCellI])
222 /(muw[faceI]/rhow[faceI]);
224 epsilon[faceCellI] = Cmu75*pow(k[faceCellI], 1.5)/(kappa_*y[faceI]);
226 if (yPlus > yPlusLam)
229 (mutw[faceI] + muw[faceI])
231 *Cmu25*sqrt(k[faceCellI])
240 // TODO: perform averaging for cells sharing more than one boundary face
242 fixedInternalValueFvPatchField<scalar>::updateCoeffs();
246 void epsilonWallFunctionFvPatchScalarField::evaluate
248 const Pstream::commsTypes commsType
251 fixedInternalValueFvPatchField<scalar>::evaluate(commsType);
255 void epsilonWallFunctionFvPatchScalarField::write(Ostream& os) const
257 fixedInternalValueFvPatchField<scalar>::write(os);
258 writeEntryIfDifferent<word>(os, "U", "U", UName_);
259 writeEntryIfDifferent<word>(os, "k", "k", kName_);
260 writeEntryIfDifferent<word>(os, "G", "RASModel::G", GName_);
261 writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
262 writeEntryIfDifferent<word>(os, "mu", "mu", muName_);
263 writeEntryIfDifferent<word>(os, "mut", "mut", mutName_);
264 os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl;
265 os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl;
266 os.writeKeyword("E") << E_ << token::END_STATEMENT << nl;
267 writeEntry("value", os);
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 epsilonWallFunctionFvPatchScalarField
279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281 } // End namespace RASModels
282 } // End namespace compressible
283 } // End namespace Foam
285 // ************************************************************************* //