wall-functions: Added "updated" check and avoid /0 in the case that the velocity...
[OpenFOAM-1.6.x.git] / src / turbulenceModels / compressible / RAS / derivedFvPatchFields / wallFunctions / mutWallFunctions / mutSpalartAllmarasWallFunction / mutSpalartAllmarasWallFunctionFvPatchScalarField.C
blobbecc5dbb3ddc67661647f20e558d7da68232d426
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 "mutSpalartAllmarasWallFunctionFvPatchScalarField.H"
28 #include "fvPatchFieldMapper.H"
29 #include "volFields.H"
30 #include "RASModel.H"
31 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 namespace Foam
37 namespace compressible
39 namespace RASModels
42 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
44 tmp<scalarField> mutSpalartAllmarasWallFunctionFvPatchScalarField::calcUTau
46     const scalarField& magGradU
47 ) const
49     const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
50     const scalarField& y = rasModel.y()[patch().index()];
52     const fvPatchVectorField& Uw =
53         rasModel.U().boundaryField()[patch().index()];
55     scalarField magUp = mag(Uw.patchInternalField() - Uw);
57     const fvPatchScalarField& rhow =
58         rasModel.rho().boundaryField()[patch().index()];
60     const fvPatchScalarField& muw =
61         rasModel.mu().boundaryField()[patch().index()];
62     const scalarField& mutw = *this;
64     tmp<scalarField> tuTau(new scalarField(patch().size(), 0.0));
65     scalarField& uTau = tuTau();
67     forAll(mutw, faceI)
68     {
69         scalar magUpara = magUp[faceI];
71         scalar ut =
72             sqrt((mutw[faceI] + muw[faceI])*magGradU[faceI]/rhow[faceI]);
74         if (ut > VSMALL)
75         {
76             int iter = 0;
77             scalar err = GREAT;
79             do
80             {
81                 scalar kUu = min(kappa_*magUpara/ut, 50);
82                 scalar fkUu = exp(kUu) - 1 - kUu*(1 + 0.5*kUu);
84                 scalar f =
85                     - ut*y[faceI]/(muw[faceI]/rhow[faceI])
86                     + magUpara/ut
87                     + 1/E_*(fkUu - 1.0/6.0*kUu*sqr(kUu));
89                 scalar df =
90                     y[faceI]/(muw[faceI]/rhow[faceI])
91                   + magUpara/sqr(ut)
92                   + 1/E_*kUu*fkUu/ut;
94                 scalar uTauNew = ut + f/df;
95                 err = mag((ut - uTauNew)/ut);
96                 ut = uTauNew;
98             } while (ut > VSMALL && err > 0.01 && ++iter < 10);
100             uTau[faceI] = max(0.0, ut);
101         }
102     }
104     return tuTau;
108 tmp<scalarField>
109 mutSpalartAllmarasWallFunctionFvPatchScalarField::calcMut() const
111     const label patchI = patch().index();
113     const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
114     const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI];
115     const scalarField magGradU = mag(Uw.snGrad());
116     const scalarField& rhow = rasModel.rho().boundaryField()[patchI];
117     const scalarField& muw = rasModel.mu().boundaryField()[patchI];
119     return max
120     (
121         scalar(0),
122         rhow*sqr(calcUTau(magGradU))/(magGradU + ROOTVSMALL) - muw
123     );
127 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
129 mutSpalartAllmarasWallFunctionFvPatchScalarField::
130 mutSpalartAllmarasWallFunctionFvPatchScalarField
132     const fvPatch& p,
133     const DimensionedField<scalar, volMesh>& iF
136     mutWallFunctionFvPatchScalarField(p, iF)
140 mutSpalartAllmarasWallFunctionFvPatchScalarField::
141 mutSpalartAllmarasWallFunctionFvPatchScalarField
143     const mutSpalartAllmarasWallFunctionFvPatchScalarField& ptf,
144     const fvPatch& p,
145     const DimensionedField<scalar, volMesh>& iF,
146     const fvPatchFieldMapper& mapper
149     mutWallFunctionFvPatchScalarField(ptf, p, iF, mapper)
153 mutSpalartAllmarasWallFunctionFvPatchScalarField::
154 mutSpalartAllmarasWallFunctionFvPatchScalarField
156     const fvPatch& p,
157     const DimensionedField<scalar, volMesh>& iF,
158     const dictionary& dict
161     mutWallFunctionFvPatchScalarField(p, iF, dict)
165 mutSpalartAllmarasWallFunctionFvPatchScalarField::
166 mutSpalartAllmarasWallFunctionFvPatchScalarField
168     const mutSpalartAllmarasWallFunctionFvPatchScalarField& wfpsf
171     mutWallFunctionFvPatchScalarField(wfpsf)
175 mutSpalartAllmarasWallFunctionFvPatchScalarField::
176 mutSpalartAllmarasWallFunctionFvPatchScalarField
178     const mutSpalartAllmarasWallFunctionFvPatchScalarField& wfpsf,
179     const DimensionedField<scalar, volMesh>& iF
182     mutWallFunctionFvPatchScalarField(wfpsf, iF)
186 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
188 tmp<scalarField>
189 mutSpalartAllmarasWallFunctionFvPatchScalarField::yPlus() const
191     const label patchI = patch().index();
193     const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
194     const scalarField& y = rasModel.y()[patchI];
195     const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI];
196     const scalarField& rhow = rasModel.rho().boundaryField()[patchI];
197     const scalarField& muw = rasModel.mu().boundaryField()[patchI];
199     return y*calcUTau(mag(Uw.snGrad()))/(muw/rhow);
203 void mutSpalartAllmarasWallFunctionFvPatchScalarField::write
205     Ostream& os
206 ) const
208     fvPatchField<scalar>::write(os);
209     writeLocalEntries(os);
210     writeEntry("value", os);
214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 makePatchTypeField(fvPatchScalarField, mutSpalartAllmarasWallFunctionFvPatchScalarField);
218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 } // End namespace RASModels
221 } // End namespace compressible
222 } // End namespace Foam
224 // ************************************************************************* //