1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2008-2009 OpenCFD Ltd.
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"
32 #include "wallFvPatch.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 namespace incompressible
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 void epsilonWallFunctionFvPatchScalarField::checkType()
47 if (!isA<wallFvPatch>(patch()))
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
59 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
61 epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField
64 const DimensionedField<scalar, volMesh>& iF
67 fixedInternalValueFvPatchField<scalar>(p, iF),
70 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),
94 nutName_(ptf.nutName_),
103 epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField
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))
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_),
136 kappa_(ewfpsf.kappa_),
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_),
156 kappa_(ewfpsf.kappa_),
163 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
165 void epsilonWallFunctionFvPatchScalarField::updateCoeffs()
167 const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
168 const scalar yPlusLam = rasModel.yPlusLam(kappa_, E_);
169 const scalarField& y = rasModel.y()[patch().index()];
171 const scalar Cmu25 = pow(Cmu_, 0.25);
172 const scalar Cmu75 = pow(Cmu_, 0.75);
174 volScalarField& G = const_cast<volScalarField&>
175 (db().lookupObject<volScalarField>(GName_));
177 volScalarField& epsilon = const_cast<volScalarField&>
178 (db().lookupObject<volScalarField>(dimensionedInternalField().name()));
180 const volScalarField& k = db().lookupObject<volScalarField>(kName_);
182 const scalarField& nuw =
183 patch().lookupPatchField<volScalarField, scalar>(nuName_);
185 const scalarField& nutw =
186 patch().lookupPatchField<volScalarField, scalar>(nutName_);
188 const fvPatchVectorField& Uw =
189 patch().lookupPatchField<volVectorField, vector>(UName_);
191 const scalarField magGradUw = mag(Uw.snGrad());
196 label faceCellI = patch().faceCells()[faceI];
198 scalar yPlus = Cmu25*y[faceI]*sqrt(k[faceCellI])/nuw[faceI];
200 epsilon[faceCellI] = Cmu75*pow(k[faceCellI], 1.5)/(kappa_*y[faceI]);
202 if (yPlus > yPlusLam)
205 (nutw[faceI] + nuw[faceI])
207 *Cmu25*sqrt(k[faceCellI])
216 // TODO: perform averaging for cells sharing more than one boundary face
220 void epsilonWallFunctionFvPatchScalarField::evaluate
222 const Pstream::commsTypes commsType
225 fixedInternalValueFvPatchField<scalar>::evaluate(commsType);
229 void epsilonWallFunctionFvPatchScalarField::write(Ostream& os) const
231 fixedInternalValueFvPatchField<scalar>::write(os);
232 writeEntryIfDifferent<word>(os, "U", "U", UName_);
233 writeEntryIfDifferent<word>(os, "k", "k", kName_);
234 writeEntryIfDifferent<word>(os, "G", "RASModel::G", GName_);
235 writeEntryIfDifferent<word>(os, "nu", "nu", nuName_);
236 writeEntryIfDifferent<word>(os, "nut", "nut", nutName_);
237 os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl;
238 os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl;
239 os.writeKeyword("E") << E_ << token::END_STATEMENT << nl;
240 writeEntry("value", os);
244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
249 epsilonWallFunctionFvPatchScalarField
252 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
254 } // End namespace RASModels
255 } // End namespace incompressible
256 } // End namespace Foam
258 // ************************************************************************* //