1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-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 "nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField.H"
29 #include "fvPatchFieldMapper.H"
30 #include "volFields.H"
31 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 namespace incompressible
42 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
45 nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::calcNut() const
47 const label patchI = patch().index();
49 const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
50 const scalarField& y = rasModel.y()[patchI];
51 const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI];
52 const scalarField& nuw = rasModel.nu().boundaryField()[patchI];
54 // The flow velocity at the adjacent cell centre
55 const scalarField magUp = mag(Uw.patchInternalField() - Uw);
57 tmp<scalarField> tyPlus = calcYPlus(magUp);
58 scalarField& yPlus = tyPlus();
60 tmp<scalarField> tnutw(new scalarField(patch().size(), 0.0));
61 scalarField& nutw = tnutw();
65 if (yPlus[facei] > yPlusLam_)
67 const scalar Re = magUp[facei]*y[facei]/nuw[facei];
68 nutw[facei] = nuw[facei]*(sqr(yPlus[facei])/Re - 1);
77 nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::calcYPlus
79 const scalarField& magUp
82 const label patchI = patch().index();
84 const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
85 const scalarField& y = rasModel.y()[patchI];
86 const scalarField& nuw = rasModel.nu().boundaryField()[patchI];
88 tmp<scalarField> tyPlus(new scalarField(patch().size(), 0.0));
89 scalarField& yPlus = tyPlus();
91 if (roughnessHeight_ > 0.0)
94 const scalar c_1 = 1/(90 - 2.25) + roughnessConstant_;
95 static const scalar c_2 = 2.25/(90 - 2.25);
96 static const scalar c_3 = 2.0*atan(1.0)/log(90/2.25);
97 static const scalar c_4 = c_3*log(2.25);
99 //if (KsPlusBasedOnYPlus_)
101 // If KsPlus is based on YPlus the extra term added to the law
102 // of the wall will depend on yPlus
105 const scalar magUpara = magUp[facei];
106 const scalar Re = magUpara*y[facei]/nuw[facei];
107 const scalar kappaRe = kappa_*Re;
109 scalar yp = yPlusLam_;
110 const scalar ryPlusLam = 1.0/yp;
113 scalar yPlusLast = 0.0;
114 scalar dKsPlusdYPlus = roughnessHeight_/y[facei];
116 // Enforce the roughnessHeight to be less than the distance to
117 // the first cell centre
118 if (dKsPlusdYPlus > 1)
123 // Additional tuning parameter (fudge factor) - nominally = 1
124 dKsPlusdYPlus *= roughnessFudgeFactor_;
130 // The non-dimensional roughness height
131 scalar KsPlus = yp*dKsPlusdYPlus;
133 // The extra term in the law-of-the-wall
136 scalar yPlusGPrime = 0.0;
140 const scalar t_1 = 1 + roughnessConstant_*KsPlus;
142 yPlusGPrime = roughnessConstant_*KsPlus/t_1;
144 else if (KsPlus > 2.25)
146 const scalar t_1 = c_1*KsPlus - c_2;
147 const scalar t_2 = c_3*log(KsPlus) - c_4;
148 const scalar sint_2 = sin(t_2);
149 const scalar logt_1 = log(t_1);
152 (c_1*sint_2*KsPlus/t_1) + (c_3*logt_1*cos(t_2));
155 scalar denom = 1.0 + log(E_*yp) - G - yPlusGPrime;
156 if (mag(denom) > VSMALL)
158 yp = (kappaRe + yp*(1 - yPlusGPrime))/denom;
162 mag(ryPlusLam*(yp - yPlusLast)) > 0.0001
167 yPlus[facei] = max(0.0, yp);
176 const scalar magUpara = magUp[facei];
177 const scalar Re = magUpara*y[facei]/nuw[facei];
178 const scalar kappaRe = kappa_*Re;
180 scalar yp = yPlusLam_;
181 const scalar ryPlusLam = 1.0/yp;
184 scalar yPlusLast = 0.0;
189 yp = (kappaRe + yp)/(1.0 + log(E_*yp));
191 } while(mag(ryPlusLam*(yp - yPlusLast)) > 0.0001 && ++iter < 10);
193 yPlus[facei] = max(0.0, yp);
201 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
203 nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::
204 nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField
207 const DimensionedField<scalar, volMesh>& iF
210 nutWallFunctionFvPatchScalarField(p, iF),
211 roughnessHeight_(pTraits<scalar>::zero),
212 roughnessConstant_(pTraits<scalar>::zero),
213 roughnessFudgeFactor_(pTraits<scalar>::zero)
217 nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::
218 nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField
220 const nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField& ptf,
222 const DimensionedField<scalar, volMesh>& iF,
223 const fvPatchFieldMapper& mapper
226 nutWallFunctionFvPatchScalarField(ptf, p, iF, mapper),
227 roughnessHeight_(ptf.roughnessHeight_),
228 roughnessConstant_(ptf.roughnessConstant_),
229 roughnessFudgeFactor_(ptf.roughnessFudgeFactor_)
233 nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::
234 nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField
237 const DimensionedField<scalar, volMesh>& iF,
238 const dictionary& dict
241 nutWallFunctionFvPatchScalarField(p, iF, dict),
242 roughnessHeight_(readScalar(dict.lookup("roughnessHeight"))),
243 roughnessConstant_(readScalar(dict.lookup("roughnessConstant"))),
244 roughnessFudgeFactor_(readScalar(dict.lookup("roughnessFudgeFactor")))
248 nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::
249 nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField
251 const nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField& rwfpsf
254 nutWallFunctionFvPatchScalarField(rwfpsf),
255 roughnessHeight_(rwfpsf.roughnessHeight_),
256 roughnessConstant_(rwfpsf.roughnessConstant_),
257 roughnessFudgeFactor_(rwfpsf.roughnessFudgeFactor_)
261 nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::
262 nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField
264 const nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField& rwfpsf,
265 const DimensionedField<scalar, volMesh>& iF
268 nutWallFunctionFvPatchScalarField(rwfpsf, iF),
269 roughnessHeight_(rwfpsf.roughnessHeight_),
270 roughnessConstant_(rwfpsf.roughnessConstant_),
271 roughnessFudgeFactor_(rwfpsf.roughnessFudgeFactor_)
275 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
278 nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::yPlus() const
280 const label patchI = patch().index();
282 const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
283 const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI];
284 const scalarField magUp = mag(Uw.patchInternalField() - Uw);
286 return calcYPlus(magUp);
290 void nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField::write
295 fvPatchField<scalar>::write(os);
296 writeLocalEntries(os);
297 os.writeKeyword("roughnessHeight")
298 << roughnessHeight_ << token::END_STATEMENT << nl;
299 os.writeKeyword("roughnessConstant")
300 << roughnessConstant_ << token::END_STATEMENT << nl;
301 os.writeKeyword("roughnessFudgeFactor")
302 << roughnessFudgeFactor_ << token::END_STATEMENT << nl;
303 writeEntry("value", os);
307 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
312 nutSpalartAllmarasStandardRoughWallFunctionFvPatchScalarField
315 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
317 } // End namespace RASModels
318 } // End namespace incompressible
319 } // End namespace Foam
321 // ************************************************************************* //