BUG: Corrected reference to tmp in incompressible RAS models (mantis #360)
[OpenFOAM-2.0.x.git] / src / turbulenceModels / incompressible / RAS / derivedFvPatchFields / wallFunctions / nutWallFunctions / nutUWallFunction / nutUWallFunctionFvPatchScalarField.C
blob77fc20e46a0b44209fd19ea12dc32b2ab21e6bb6
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "nutUWallFunctionFvPatchScalarField.H"
27 #include "RASModel.H"
28 #include "fvPatchFieldMapper.H"
29 #include "volFields.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 namespace Foam
36 namespace incompressible
38 namespace RASModels
41 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
43 tmp<scalarField> nutUWallFunctionFvPatchScalarField::calcNut() const
45     const label patchI = patch().index();
47     const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
48     const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI];
49     const scalarField magUp(mag(Uw.patchInternalField() - Uw));
50     const tmp<volScalarField> tnu = rasModel.nu();
51     const volScalarField& nu = tnu();
52     const scalarField& nuw = nu.boundaryField()[patchI];
54     tmp<scalarField> tyPlus = calcYPlus(magUp);
55     scalarField& yPlus = tyPlus();
57     tmp<scalarField> tnutw(new scalarField(patch().size(), 0.0));
58     scalarField& nutw = tnutw();
60     forAll(yPlus, facei)
61     {
62         if (yPlus[facei] > yPlusLam_)
63         {
64             nutw[facei] =
65                 nuw[facei]*(yPlus[facei]*kappa_/log(E_*yPlus[facei]) - 1.0);
66         }
67     }
69     return tnutw;
73 tmp<scalarField> nutUWallFunctionFvPatchScalarField::calcYPlus
75     const scalarField& magUp
76 ) const
78     const label patchI = patch().index();
80     const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
81     const scalarField& y = rasModel.y()[patchI];
82     const tmp<volScalarField> tnu = rasModel.nu();
83     const volScalarField& nu = tnu();
84     const scalarField& nuw = nu.boundaryField()[patchI];
86     tmp<scalarField> tyPlus(new scalarField(patch().size(), 0.0));
87     scalarField& yPlus = tyPlus();
89     forAll(yPlus, facei)
90     {
91         scalar kappaRe = kappa_*magUp[facei]*y[facei]/nuw[facei];
93         scalar yp = yPlusLam_;
94         scalar ryPlusLam = 1.0/yp;
96         int iter = 0;
97         scalar yPlusLast = 0.0;
99         do
100         {
101             yPlusLast = yp;
102             yp = (kappaRe + yp)/(1.0 + log(E_*yp));
104         } while (mag(ryPlusLam*(yp - yPlusLast)) > 0.01 && ++iter < 10 );
106         yPlus[facei] = max(0.0, yp);
107     }
109     return tyPlus;
113 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
115 nutUWallFunctionFvPatchScalarField::nutUWallFunctionFvPatchScalarField
117     const fvPatch& p,
118     const DimensionedField<scalar, volMesh>& iF
121     nutkWallFunctionFvPatchScalarField(p, iF)
125 nutUWallFunctionFvPatchScalarField::nutUWallFunctionFvPatchScalarField
127     const nutUWallFunctionFvPatchScalarField& ptf,
128     const fvPatch& p,
129     const DimensionedField<scalar, volMesh>& iF,
130     const fvPatchFieldMapper& mapper
133     nutkWallFunctionFvPatchScalarField(ptf, p, iF, mapper)
137 nutUWallFunctionFvPatchScalarField::nutUWallFunctionFvPatchScalarField
139     const fvPatch& p,
140     const DimensionedField<scalar, volMesh>& iF,
141     const dictionary& dict
144     nutkWallFunctionFvPatchScalarField(p, iF, dict)
148 nutUWallFunctionFvPatchScalarField::nutUWallFunctionFvPatchScalarField
150     const nutUWallFunctionFvPatchScalarField& sawfpsf
153     nutkWallFunctionFvPatchScalarField(sawfpsf)
157 nutUWallFunctionFvPatchScalarField::nutUWallFunctionFvPatchScalarField
159     const nutUWallFunctionFvPatchScalarField& sawfpsf,
160     const DimensionedField<scalar, volMesh>& iF
163     nutkWallFunctionFvPatchScalarField(sawfpsf, iF)
167 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
169 tmp<scalarField> nutUWallFunctionFvPatchScalarField::yPlus() const
171     const label patchI = patch().index();
172     const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
173     const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI];
174     const scalarField magUp(mag(Uw.patchInternalField() - Uw));
176     return calcYPlus(magUp);
180 void nutUWallFunctionFvPatchScalarField::write(Ostream& os) const
182     fvPatchField<scalar>::write(os);
183     writeLocalEntries(os);
184     writeEntry("value", os);
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 makePatchTypeField
192     fvPatchScalarField,
193     nutUWallFunctionFvPatchScalarField
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 } // End namespace RASModels
199 } // End namespace incompressible
200 } // End namespace Foam
202 // ************************************************************************* //