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 "nutSpalartAllmarasWallFunctionFvPatchScalarField.H"
29 #include "fvPatchFieldMapper.H"
30 #include "volFields.H"
31 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 namespace incompressible
42 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
45 nutSpalartAllmarasWallFunctionFvPatchScalarField::calcNut() const
47 const label patchI = patch().index();
49 const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
50 const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI];
51 const scalarField magGradU = mag(Uw.snGrad());
52 const scalarField& nuw = rasModel.nu().boundaryField()[patchI];
54 return max(scalar(0), sqr(calcUTau(magGradU))/magGradU - nuw);
58 tmp<scalarField> nutSpalartAllmarasWallFunctionFvPatchScalarField::calcUTau
60 const scalarField& magGradU
63 const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
64 const scalarField& y = rasModel.y()[patch().index()];
66 const fvPatchVectorField& Uw =
67 rasModel.U().boundaryField()[patch().index()];
68 const scalarField magUp = mag(Uw.patchInternalField() - Uw);
70 const scalarField& nuw = rasModel.nu().boundaryField()[patch().index()];
71 const scalarField& nutw = *this;
73 tmp<scalarField> tuTau(new scalarField(patch().size(), 0.0));
74 scalarField& uTau = tuTau();
78 scalar magUpara = magUp[facei];
80 scalar ut = sqrt((nutw[facei] + nuw[facei])*magGradU[facei]);
89 scalar kUu = min(kappa_*magUpara/ut, 50);
90 scalar fkUu = exp(kUu) - 1 - kUu*(1 + 0.5*kUu);
93 - ut*y[facei]/nuw[facei]
95 + 1/E_*(fkUu - 1.0/6.0*kUu*sqr(kUu));
102 scalar uTauNew = ut + f/df;
103 err = mag((ut - uTauNew)/ut);
106 } while (ut > VSMALL && err > 0.01 && ++iter < 10);
107 uTau[facei] = max(0.0, ut);
115 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
117 nutSpalartAllmarasWallFunctionFvPatchScalarField::
118 nutSpalartAllmarasWallFunctionFvPatchScalarField
121 const DimensionedField<scalar, volMesh>& iF
124 nutWallFunctionFvPatchScalarField(p, iF)
128 nutSpalartAllmarasWallFunctionFvPatchScalarField::
129 nutSpalartAllmarasWallFunctionFvPatchScalarField
131 const nutSpalartAllmarasWallFunctionFvPatchScalarField& ptf,
133 const DimensionedField<scalar, volMesh>& iF,
134 const fvPatchFieldMapper& mapper
137 nutWallFunctionFvPatchScalarField(ptf, p, iF, mapper)
141 nutSpalartAllmarasWallFunctionFvPatchScalarField::
142 nutSpalartAllmarasWallFunctionFvPatchScalarField
145 const DimensionedField<scalar, volMesh>& iF,
146 const dictionary& dict
149 nutWallFunctionFvPatchScalarField(p, iF, dict)
153 nutSpalartAllmarasWallFunctionFvPatchScalarField::
154 nutSpalartAllmarasWallFunctionFvPatchScalarField
156 const nutSpalartAllmarasWallFunctionFvPatchScalarField& wfpsf
159 nutWallFunctionFvPatchScalarField(wfpsf)
163 nutSpalartAllmarasWallFunctionFvPatchScalarField::
164 nutSpalartAllmarasWallFunctionFvPatchScalarField
166 const nutSpalartAllmarasWallFunctionFvPatchScalarField& wfpsf,
167 const DimensionedField<scalar, volMesh>& iF
170 nutWallFunctionFvPatchScalarField(wfpsf, iF)
174 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
177 nutSpalartAllmarasWallFunctionFvPatchScalarField::yPlus() const
179 const label patchI = patch().index();
181 const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
182 const scalarField& y = rasModel.y()[patchI];
183 const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI];
184 const scalarField& nuw = rasModel.nu().boundaryField()[patchI];
186 return y*calcUTau(mag(Uw.snGrad()))/nuw;
190 void nutSpalartAllmarasWallFunctionFvPatchScalarField::write
195 fvPatchField<scalar>::write(os);
196 writeLocalEntries(os);
197 writeEntry("value", os);
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206 nutSpalartAllmarasWallFunctionFvPatchScalarField
209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 } // End namespace RASModels
212 } // End namespace incompressible
213 } // End namespace Foam
215 // ************************************************************************* //