initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / turbulenceModels / incompressible / RAS / derivedFvPatchFields / wallFunctions / nutWallFunctions / nutWallFunction / nutWallFunctionFvPatchScalarField.C
blobaef4df68b32688eca2b523013c2e879f1a573c10
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2008-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 "nutWallFunctionFvPatchScalarField.H"
28 #include "RASModel.H"
29 #include "fvPatchFieldMapper.H"
30 #include "volFields.H"
31 #include "wallFvPatch.H"
32 #include "addToRunTimeSelectionTable.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 namespace Foam
38 namespace incompressible
40 namespace RASModels
43 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
45 void nutWallFunctionFvPatchScalarField::checkType()
47     if (!isA<wallFvPatch>(patch()))
48     {
49         FatalErrorIn("nutWallFunctionFvPatchScalarField::checkType()")
50             << "Invalid wall function specification" << nl
51             << "    Patch type for patch " << patch().name()
52             << " must be wall" << nl
53             << "    Current patch type is " << patch().type() << nl << endl
54             << abort(FatalError);
55     }
59 scalar nutWallFunctionFvPatchScalarField::calcYPlusLam
61     const scalar kappa,
62     const scalar E
63 ) const
65     scalar ypl = 11.0;
67     for (int i=0; i<10; i++)
68     {
69         ypl = log(E*ypl)/kappa;
70     }
72     return ypl;
76 tmp<scalarField> nutWallFunctionFvPatchScalarField::calcNut() 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> tk = rasModel.k();
83     const volScalarField& k = tk();
84     const scalarField& nuw = rasModel.nu().boundaryField()[patchI];
86     const scalar Cmu25 = pow(Cmu_, 0.25);
88     tmp<scalarField> tnutw(new scalarField(patch().size(), 0.0));
89     scalarField& nutw = tnutw();
91     forAll(nutw, faceI)
92     {
93         label faceCellI = patch().faceCells()[faceI];
95         scalar yPlus = Cmu25*y[faceI]*sqrt(k[faceCellI])/nuw[faceI];
97         if (yPlus > yPlusLam_)
98         {
99             nutw[faceI] = nuw[faceI]*(yPlus*kappa_/log(E_*yPlus) - 1.0);
100         }
101     }
103     return tnutw;
107 void nutWallFunctionFvPatchScalarField::writeLocalEntries(Ostream& os) const
109     os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl;
110     os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl;
111     os.writeKeyword("E") << E_ << token::END_STATEMENT << nl;
115 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
117 nutWallFunctionFvPatchScalarField::nutWallFunctionFvPatchScalarField
119     const fvPatch& p,
120     const DimensionedField<scalar, volMesh>& iF
123     fixedValueFvPatchScalarField(p, iF),
124     Cmu_(0.09),
125     kappa_(0.41),
126     E_(9.8),
127     yPlusLam_(calcYPlusLam(kappa_, E_))
129     checkType();
133 nutWallFunctionFvPatchScalarField::nutWallFunctionFvPatchScalarField
135     const nutWallFunctionFvPatchScalarField& ptf,
136     const fvPatch& p,
137     const DimensionedField<scalar, volMesh>& iF,
138     const fvPatchFieldMapper& mapper
141     fixedValueFvPatchScalarField(ptf, p, iF, mapper),
142     Cmu_(ptf.Cmu_),
143     kappa_(ptf.kappa_),
144     E_(ptf.E_),
145     yPlusLam_(ptf.yPlusLam_)
147     checkType();
151 nutWallFunctionFvPatchScalarField::nutWallFunctionFvPatchScalarField
153     const fvPatch& p,
154     const DimensionedField<scalar, volMesh>& iF,
155     const dictionary& dict
158     fixedValueFvPatchScalarField(p, iF, dict),
159     Cmu_(dict.lookupOrDefault<scalar>("Cmu", 0.09)),
160     kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
161     E_(dict.lookupOrDefault<scalar>("E", 9.8)),
162     yPlusLam_(calcYPlusLam(kappa_, E_))
164     checkType();
168 nutWallFunctionFvPatchScalarField::nutWallFunctionFvPatchScalarField
170     const nutWallFunctionFvPatchScalarField& wfpsf
173     fixedValueFvPatchScalarField(wfpsf),
174     Cmu_(wfpsf.Cmu_),
175     kappa_(wfpsf.kappa_),
176     E_(wfpsf.E_),
177     yPlusLam_(wfpsf.yPlusLam_)
179     checkType();
183 nutWallFunctionFvPatchScalarField::nutWallFunctionFvPatchScalarField
185     const nutWallFunctionFvPatchScalarField& wfpsf,
186     const DimensionedField<scalar, volMesh>& iF
189     fixedValueFvPatchScalarField(wfpsf, iF),
190     Cmu_(wfpsf.Cmu_),
191     kappa_(wfpsf.kappa_),
192     E_(wfpsf.E_),
193     yPlusLam_(wfpsf.yPlusLam_)
195     checkType();
199 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
201 void nutWallFunctionFvPatchScalarField::updateCoeffs()
203     operator==(calcNut());
205     fixedValueFvPatchScalarField::updateCoeffs();
209 tmp<scalarField> nutWallFunctionFvPatchScalarField::yPlus() const
211     const label patchI = patch().index();
213     const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
214     const scalarField& y = rasModel.y()[patchI];
216     const tmp<volScalarField> tk = rasModel.k();
217     const volScalarField& k = tk();
218     const scalarField kwc = k.boundaryField()[patchI].patchInternalField();
219     const scalarField& nuw = rasModel.nu().boundaryField()[patchI];
221     return pow(Cmu_, 0.25)*y*sqrt(kwc)/nuw;
225 void nutWallFunctionFvPatchScalarField::write(Ostream& os) const
227     fvPatchField<scalar>::write(os);
228     writeLocalEntries(os);
229     writeEntry("value", os);
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
235 makePatchTypeField(fvPatchScalarField, nutWallFunctionFvPatchScalarField);
237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239 } // End namespace RASModels
240 } // End namespace incompressible
241 } // End namespace Foam
243 // ************************************************************************* //