1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2008-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "nutkWallFunctionFvPatchScalarField.H"
28 #include "fvPatchFieldMapper.H"
29 #include "volFields.H"
30 #include "wallFvPatch.H"
31 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 namespace incompressible
42 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
44 void nutkWallFunctionFvPatchScalarField::checkType()
46 if (!isA<wallFvPatch>(patch()))
48 FatalErrorIn("nutkWallFunctionFvPatchScalarField::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 scalar nutkWallFunctionFvPatchScalarField::calcYPlusLam
66 for (int i=0; i<10; i++)
68 ypl = log(E*ypl)/kappa;
75 tmp<scalarField> nutkWallFunctionFvPatchScalarField::calcNut() const
77 const label patchI = patch().index();
79 const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
80 const scalarField& y = rasModel.y()[patchI];
81 const tmp<volScalarField> tk = rasModel.k();
82 const volScalarField& k = tk();
83 const scalarField& nuw = rasModel.nu()().boundaryField()[patchI];
85 const scalar Cmu25 = pow025(Cmu_);
87 tmp<scalarField> tnutw(new scalarField(patch().size(), 0.0));
88 scalarField& nutw = tnutw();
92 label faceCellI = patch().faceCells()[faceI];
94 scalar yPlus = Cmu25*y[faceI]*sqrt(k[faceCellI])/nuw[faceI];
96 if (yPlus > yPlusLam_)
98 nutw[faceI] = nuw[faceI]*(yPlus*kappa_/log(E_*yPlus) - 1.0);
106 void nutkWallFunctionFvPatchScalarField::writeLocalEntries(Ostream& os) const
108 os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl;
109 os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl;
110 os.writeKeyword("E") << E_ << token::END_STATEMENT << nl;
114 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
116 nutkWallFunctionFvPatchScalarField::nutkWallFunctionFvPatchScalarField
119 const DimensionedField<scalar, volMesh>& iF
122 fixedValueFvPatchScalarField(p, iF),
126 yPlusLam_(calcYPlusLam(kappa_, E_))
132 nutkWallFunctionFvPatchScalarField::nutkWallFunctionFvPatchScalarField
134 const nutkWallFunctionFvPatchScalarField& ptf,
136 const DimensionedField<scalar, volMesh>& iF,
137 const fvPatchFieldMapper& mapper
140 fixedValueFvPatchScalarField(ptf, p, iF, mapper),
144 yPlusLam_(ptf.yPlusLam_)
150 nutkWallFunctionFvPatchScalarField::nutkWallFunctionFvPatchScalarField
153 const DimensionedField<scalar, volMesh>& iF,
154 const dictionary& dict
157 fixedValueFvPatchScalarField(p, iF, dict),
158 Cmu_(dict.lookupOrDefault<scalar>("Cmu", 0.09)),
159 kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
160 E_(dict.lookupOrDefault<scalar>("E", 9.8)),
161 yPlusLam_(calcYPlusLam(kappa_, E_))
167 nutkWallFunctionFvPatchScalarField::nutkWallFunctionFvPatchScalarField
169 const nutkWallFunctionFvPatchScalarField& wfpsf
172 fixedValueFvPatchScalarField(wfpsf),
174 kappa_(wfpsf.kappa_),
176 yPlusLam_(wfpsf.yPlusLam_)
182 nutkWallFunctionFvPatchScalarField::nutkWallFunctionFvPatchScalarField
184 const nutkWallFunctionFvPatchScalarField& wfpsf,
185 const DimensionedField<scalar, volMesh>& iF
188 fixedValueFvPatchScalarField(wfpsf, iF),
190 kappa_(wfpsf.kappa_),
192 yPlusLam_(wfpsf.yPlusLam_)
198 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
200 void nutkWallFunctionFvPatchScalarField::updateCoeffs()
207 operator==(calcNut());
209 fixedValueFvPatchScalarField::updateCoeffs();
213 tmp<scalarField> nutkWallFunctionFvPatchScalarField::yPlus() const
215 const label patchI = patch().index();
217 const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
218 const scalarField& y = rasModel.y()[patchI];
220 const tmp<volScalarField> tk = rasModel.k();
221 const volScalarField& k = tk();
222 tmp<scalarField> kwc = k.boundaryField()[patchI].patchInternalField();
223 const scalarField& nuw = rasModel.nu()().boundaryField()[patchI];
225 return pow025(Cmu_)*y*sqrt(kwc)/nuw;
229 void nutkWallFunctionFvPatchScalarField::write(Ostream& os) const
231 fvPatchField<scalar>::write(os);
232 writeLocalEntries(os);
233 writeEntry("value", os);
237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 nutkWallFunctionFvPatchScalarField
245 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
247 } // End namespace RASModels
248 } // End namespace incompressible
249 } // End namespace Foam
251 // ************************************************************************* //