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 "nutkWallFunctionFvPatchScalarField.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 nutkWallFunctionFvPatchScalarField::checkType()
47 if (!isA<wallFvPatch>(patch()))
49 FatalErrorIn("nutkWallFunctionFvPatchScalarField::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 nutkWallFunctionFvPatchScalarField::calcYPlusLam
67 for (int i=0; i<10; i++)
69 ypl = log(E*ypl)/kappa;
76 tmp<scalarField> nutkWallFunctionFvPatchScalarField::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 nutkWallFunctionFvPatchScalarField::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 nutkWallFunctionFvPatchScalarField::nutkWallFunctionFvPatchScalarField
120 const DimensionedField<scalar, volMesh>& iF
123 fixedValueFvPatchScalarField(p, iF),
127 yPlusLam_(calcYPlusLam(kappa_, E_))
133 nutkWallFunctionFvPatchScalarField::nutkWallFunctionFvPatchScalarField
135 const nutkWallFunctionFvPatchScalarField& ptf,
137 const DimensionedField<scalar, volMesh>& iF,
138 const fvPatchFieldMapper& mapper
141 fixedValueFvPatchScalarField(ptf, p, iF, mapper),
145 yPlusLam_(ptf.yPlusLam_)
151 nutkWallFunctionFvPatchScalarField::nutkWallFunctionFvPatchScalarField
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 nutkWallFunctionFvPatchScalarField::nutkWallFunctionFvPatchScalarField
170 const nutkWallFunctionFvPatchScalarField& wfpsf
173 fixedValueFvPatchScalarField(wfpsf),
175 kappa_(wfpsf.kappa_),
177 yPlusLam_(wfpsf.yPlusLam_)
183 nutkWallFunctionFvPatchScalarField::nutkWallFunctionFvPatchScalarField
185 const nutkWallFunctionFvPatchScalarField& wfpsf,
186 const DimensionedField<scalar, volMesh>& iF
189 fixedValueFvPatchScalarField(wfpsf, iF),
191 kappa_(wfpsf.kappa_),
193 yPlusLam_(wfpsf.yPlusLam_)
199 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
201 void nutkWallFunctionFvPatchScalarField::updateCoeffs()
208 operator==(calcNut());
210 fixedValueFvPatchScalarField::updateCoeffs();
214 tmp<scalarField> nutkWallFunctionFvPatchScalarField::yPlus() const
216 const label patchI = patch().index();
218 const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
219 const scalarField& y = rasModel.y()[patchI];
221 const tmp<volScalarField> tk = rasModel.k();
222 const volScalarField& k = tk();
223 const scalarField kwc = k.boundaryField()[patchI].patchInternalField();
224 const scalarField& nuw = rasModel.nu().boundaryField()[patchI];
226 return pow(Cmu_, 0.25)*y*sqrt(kwc)/nuw;
230 void nutkWallFunctionFvPatchScalarField::write(Ostream& os) const
232 fvPatchField<scalar>::write(os);
233 writeLocalEntries(os);
234 writeEntry("value", os);
238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
240 makePatchTypeField(fvPatchScalarField, nutkWallFunctionFvPatchScalarField);
242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 } // End namespace RASModels
245 } // End namespace incompressible
246 } // End namespace Foam
248 // ************************************************************************* //