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()
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());
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)
210 (nutw[faceI] + nuw[faceI])
212 *Cmu25*sqrt(k[faceCellI])
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256 epsilonWallFunctionFvPatchScalarField
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261 } // End namespace RASModels
262 } // End namespace incompressible
263 } // End namespace Foam
265 // ************************************************************************* //