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 "nutWallFunctionFvPatchScalarField.H"
29 #include "fvPatchFieldMapper.H"
30 #include "volFields.H"
31 #include "wallFvPatch.H"
32 #include "addToRunTimeSelectionTable.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 namespace incompressible
43 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
45 void nutWallFunctionFvPatchScalarField::checkType()
47 if (!isA<wallFvPatch>(patch()))
49 FatalErrorIn("nutWallFunctionFvPatchScalarField::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 scalar nutWallFunctionFvPatchScalarField::calcYPlusLam
67 for (int i=0; i<10; i++)
69 ypl = log(E*ypl)/kappa;
76 tmp<scalarField> nutWallFunctionFvPatchScalarField::calcNut() const
78 const label patchI = patch().index();
80 const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
81 const scalarField& y = rasModel.y()[patchI];
82 const tmp<volScalarField> tk = rasModel.k();
83 const volScalarField& k = tk();
84 const scalarField& nuw = rasModel.nu().boundaryField()[patchI];
86 const scalar Cmu25 = pow(Cmu_, 0.25);
88 tmp<scalarField> tnutw(new scalarField(patch().size(), 0.0));
89 scalarField& nutw = tnutw();
93 label faceCellI = patch().faceCells()[faceI];
95 scalar yPlus = Cmu25*y[faceI]*sqrt(k[faceCellI])/nuw[faceI];
97 if (yPlus > yPlusLam_)
99 nutw[faceI] = nuw[faceI]*(yPlus*kappa_/log(E_*yPlus) - 1.0);
107 void nutWallFunctionFvPatchScalarField::writeLocalEntries(Ostream& os) const
109 os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl;
110 os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl;
111 os.writeKeyword("E") << E_ << token::END_STATEMENT << nl;
115 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
117 nutWallFunctionFvPatchScalarField::nutWallFunctionFvPatchScalarField
120 const DimensionedField<scalar, volMesh>& iF
123 fixedValueFvPatchScalarField(p, iF),
127 yPlusLam_(calcYPlusLam(kappa_, E_))
133 nutWallFunctionFvPatchScalarField::nutWallFunctionFvPatchScalarField
135 const nutWallFunctionFvPatchScalarField& ptf,
137 const DimensionedField<scalar, volMesh>& iF,
138 const fvPatchFieldMapper& mapper
141 fixedValueFvPatchScalarField(ptf, p, iF, mapper),
145 yPlusLam_(ptf.yPlusLam_)
151 nutWallFunctionFvPatchScalarField::nutWallFunctionFvPatchScalarField
154 const DimensionedField<scalar, volMesh>& iF,
155 const dictionary& dict
158 fixedValueFvPatchScalarField(p, iF, dict),
159 Cmu_(dict.lookupOrDefault<scalar>("Cmu", 0.09)),
160 kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
161 E_(dict.lookupOrDefault<scalar>("E", 9.8)),
162 yPlusLam_(calcYPlusLam(kappa_, E_))
168 nutWallFunctionFvPatchScalarField::nutWallFunctionFvPatchScalarField
170 const nutWallFunctionFvPatchScalarField& wfpsf
173 fixedValueFvPatchScalarField(wfpsf),
175 kappa_(wfpsf.kappa_),
177 yPlusLam_(wfpsf.yPlusLam_)
183 nutWallFunctionFvPatchScalarField::nutWallFunctionFvPatchScalarField
185 const nutWallFunctionFvPatchScalarField& wfpsf,
186 const DimensionedField<scalar, volMesh>& iF
189 fixedValueFvPatchScalarField(wfpsf, iF),
191 kappa_(wfpsf.kappa_),
193 yPlusLam_(wfpsf.yPlusLam_)
199 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
201 void nutWallFunctionFvPatchScalarField::updateCoeffs()
203 operator==(calcNut());
205 fixedValueFvPatchScalarField::updateCoeffs();
209 tmp<scalarField> nutWallFunctionFvPatchScalarField::yPlus() const
211 const label patchI = patch().index();
213 const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
214 const scalarField& y = rasModel.y()[patchI];
216 const tmp<volScalarField> tk = rasModel.k();
217 const volScalarField& k = tk();
218 const scalarField kwc = k.boundaryField()[patchI].patchInternalField();
219 const scalarField& nuw = rasModel.nu().boundaryField()[patchI];
221 return pow(Cmu_, 0.25)*y*sqrt(kwc)/nuw;
225 void nutWallFunctionFvPatchScalarField::write(Ostream& os) const
227 fvPatchField<scalar>::write(os);
228 writeLocalEntries(os);
229 writeEntry("value", os);
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
235 makePatchTypeField(fvPatchScalarField, nutWallFunctionFvPatchScalarField);
237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239 } // End namespace RASModels
240 } // End namespace incompressible
241 } // End namespace Foam
243 // ************************************************************************* //