initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / turbulenceModels / incompressible / RAS / derivedFvPatchFields / wallFunctions / nutWallFunctions / nutSpalartAllmarasWallFunction / nutSpalartAllmarasWallFunctionFvPatchScalarField.C
blob8b968a4fa20c4e9e1c5add49ff8b40d34b7798a2
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(scalar(0), sqr(calcUTau(magGradU))/magGradU - nuw);
58 tmp<scalarField> nutSpalartAllmarasWallFunctionFvPatchScalarField::calcUTau
60     const scalarField& magGradU
61 ) const
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();
76     forAll(uTau, facei)
77     {
78         scalar magUpara = magUp[facei];
80         scalar ut = sqrt((nutw[facei] + nuw[facei])*magGradU[facei]);
82         if (ut > VSMALL)
83         {
84             int iter = 0;
85             scalar err = GREAT;
87             do
88             {
89                 scalar kUu = min(kappa_*magUpara/ut, 50);
90                 scalar fkUu = exp(kUu) - 1 - kUu*(1 + 0.5*kUu);
92                 scalar f =
93                     - ut*y[facei]/nuw[facei]
94                     + magUpara/ut
95                     + 1/E_*(fkUu - 1.0/6.0*kUu*sqr(kUu));
97                 scalar df =
98                     y[facei]/nuw[facei]
99                   + magUpara/sqr(ut)
100                   + 1/E_*kUu*fkUu/ut;
102                 scalar uTauNew = ut + f/df;
103                 err = mag((ut - uTauNew)/ut);
104                 ut = uTauNew;
106             } while (ut > VSMALL && err > 0.01 && ++iter < 10);
107             uTau[facei] = max(0.0, ut);
108         }
109     }
111     return tuTau;
115 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
117 nutSpalartAllmarasWallFunctionFvPatchScalarField::
118 nutSpalartAllmarasWallFunctionFvPatchScalarField
120     const fvPatch& p,
121     const DimensionedField<scalar, volMesh>& iF
124     nutWallFunctionFvPatchScalarField(p, iF)
128 nutSpalartAllmarasWallFunctionFvPatchScalarField::
129 nutSpalartAllmarasWallFunctionFvPatchScalarField
131     const nutSpalartAllmarasWallFunctionFvPatchScalarField& ptf,
132     const fvPatch& p,
133     const DimensionedField<scalar, volMesh>& iF,
134     const fvPatchFieldMapper& mapper
137     nutWallFunctionFvPatchScalarField(ptf, p, iF, mapper)
141 nutSpalartAllmarasWallFunctionFvPatchScalarField::
142 nutSpalartAllmarasWallFunctionFvPatchScalarField
144     const fvPatch& p,
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  * * * * * * * * * * * * * //
176 tmp<scalarField>
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
192     Ostream& os
193 ) const
195     fvPatchField<scalar>::write(os);
196     writeLocalEntries(os);
197     writeEntry("value", os);
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 makePatchTypeField
205     fvPatchScalarField,
206     nutSpalartAllmarasWallFunctionFvPatchScalarField
209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 } // End namespace RASModels
212 } // End namespace incompressible
213 } // End namespace Foam
215 // ************************************************************************* //