wall-functions: Added "updated" check and avoid /0 in the case that the velocity...
[OpenFOAM-1.6.x.git] / src / turbulenceModels / incompressible / RAS / derivedFvPatchFields / wallFunctions / nutWallFunctions / nutSpalartAllmarasWallFunction / nutSpalartAllmarasWallFunctionFvPatchScalarField.C
blobeef98df9fa97b3dc53bf17ac6f4d9f00e1adcf0d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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"
28 #include "RASModel.H"
29 #include "fvPatchFieldMapper.H"
30 #include "volFields.H"
31 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 namespace Foam
37 namespace incompressible
39 namespace RASModels
42 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
44 tmp<scalarField>
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
55     (
56         scalar(0),
57         sqr(calcUTau(magGradU))/(magGradU + ROOTVSMALL) - nuw
58     );
62 tmp<scalarField> nutSpalartAllmarasWallFunctionFvPatchScalarField::calcUTau
64     const scalarField& magGradU
65 ) const
67     const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
68     const scalarField& y = rasModel.y()[patch().index()];
70     const fvPatchVectorField& Uw =
71         rasModel.U().boundaryField()[patch().index()];
72     const scalarField magUp = mag(Uw.patchInternalField() - Uw);
74     const scalarField& nuw = rasModel.nu().boundaryField()[patch().index()];
75     const scalarField& nutw = *this;
77     tmp<scalarField> tuTau(new scalarField(patch().size(), 0.0));
78     scalarField& uTau = tuTau();
80     forAll(uTau, facei)
81     {
82         scalar magUpara = magUp[facei];
84         scalar ut = sqrt((nutw[facei] + nuw[facei])*magGradU[facei]);
86         if (ut > VSMALL)
87         {
88             int iter = 0;
89             scalar err = GREAT;
91             do
92             {
93                 scalar kUu = min(kappa_*magUpara/ut, 50);
94                 scalar fkUu = exp(kUu) - 1 - kUu*(1 + 0.5*kUu);
96                 scalar f =
97                     - ut*y[facei]/nuw[facei]
98                     + magUpara/ut
99                     + 1/E_*(fkUu - 1.0/6.0*kUu*sqr(kUu));
101                 scalar df =
102                     y[facei]/nuw[facei]
103                   + magUpara/sqr(ut)
104                   + 1/E_*kUu*fkUu/ut;
106                 scalar uTauNew = ut + f/df;
107                 err = mag((ut - uTauNew)/ut);
108                 ut = uTauNew;
110             } while (ut > VSMALL && err > 0.01 && ++iter < 10);
111             uTau[facei] = max(0.0, ut);
112         }
113     }
115     return tuTau;
119 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
121 nutSpalartAllmarasWallFunctionFvPatchScalarField::
122 nutSpalartAllmarasWallFunctionFvPatchScalarField
124     const fvPatch& p,
125     const DimensionedField<scalar, volMesh>& iF
128     nutWallFunctionFvPatchScalarField(p, iF)
132 nutSpalartAllmarasWallFunctionFvPatchScalarField::
133 nutSpalartAllmarasWallFunctionFvPatchScalarField
135     const nutSpalartAllmarasWallFunctionFvPatchScalarField& ptf,
136     const fvPatch& p,
137     const DimensionedField<scalar, volMesh>& iF,
138     const fvPatchFieldMapper& mapper
141     nutWallFunctionFvPatchScalarField(ptf, p, iF, mapper)
145 nutSpalartAllmarasWallFunctionFvPatchScalarField::
146 nutSpalartAllmarasWallFunctionFvPatchScalarField
148     const fvPatch& p,
149     const DimensionedField<scalar, volMesh>& iF,
150     const dictionary& dict
153     nutWallFunctionFvPatchScalarField(p, iF, dict)
157 nutSpalartAllmarasWallFunctionFvPatchScalarField::
158 nutSpalartAllmarasWallFunctionFvPatchScalarField
160     const nutSpalartAllmarasWallFunctionFvPatchScalarField& wfpsf
163     nutWallFunctionFvPatchScalarField(wfpsf)
167 nutSpalartAllmarasWallFunctionFvPatchScalarField::
168 nutSpalartAllmarasWallFunctionFvPatchScalarField
170     const nutSpalartAllmarasWallFunctionFvPatchScalarField& wfpsf,
171     const DimensionedField<scalar, volMesh>& iF
174     nutWallFunctionFvPatchScalarField(wfpsf, iF)
178 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
180 tmp<scalarField>
181 nutSpalartAllmarasWallFunctionFvPatchScalarField::yPlus() const
183     const label patchI = patch().index();
185     const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
186     const scalarField& y = rasModel.y()[patchI];
187     const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI];
188     const scalarField& nuw = rasModel.nu().boundaryField()[patchI];
190     return y*calcUTau(mag(Uw.snGrad()))/nuw;
194 void nutSpalartAllmarasWallFunctionFvPatchScalarField::write
196     Ostream& os
197 ) const
199     fvPatchField<scalar>::write(os);
200     writeLocalEntries(os);
201     writeEntry("value", os);
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 makePatchTypeField
209     fvPatchScalarField,
210     nutSpalartAllmarasWallFunctionFvPatchScalarField
213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 } // End namespace RASModels
216 } // End namespace incompressible
217 } // End namespace Foam
219 // ************************************************************************* //