initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / turbulenceModels / incompressible / RAS / derivedFvPatchFields / wallFunctions / nutWallFunctions / nutRoughWallFunction / nutRoughWallFunctionFvPatchScalarField.C
blob48d9ba1dde63777ea5ada9c0e274b7fa8a66794f
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 "nutRoughWallFunctionFvPatchScalarField.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 scalar nutRoughWallFunctionFvPatchScalarField::fnRough
46     const scalar KsPlus,
47     const scalar Cs
48 ) const
50     // Return fn based on non-dimensional roughness height
52     if (KsPlus < 90.0)
53     {
54         return pow
55         (
56             (KsPlus - 2.25)/87.75 + Cs*KsPlus,
57             sin(0.4258*(log(KsPlus) - 0.811))
58         );
59     }
60     else
61     {
62         return (1.0 + Cs*KsPlus);
63     }
67 tmp<scalarField> nutRoughWallFunctionFvPatchScalarField::calcNut() const
69     const label patchI = patch().index();
71     const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
72     const scalarField& y = rasModel.y()[patchI];
73     const tmp<volScalarField> tk = rasModel.k();
74     const volScalarField& k = tk();
75     const scalarField& nuw = rasModel.nu().boundaryField()[patchI];
77     const scalar Cmu25 = pow(Cmu_, 0.25);
79     tmp<scalarField> tnutw(new scalarField(patch().size(), 0.0));
80     scalarField& nutw = tnutw();
82     forAll(nutw, faceI)
83     {
84         label faceCellI = patch().faceCells()[faceI];
86         scalar uStar = Cmu25*sqrt(k[faceCellI]);
87         scalar yPlus = uStar*y[faceI]/nuw[faceI];
88         scalar KsPlus = uStar*Ks_[faceI]/nuw[faceI];
90         scalar Edash = E_;
92         if (KsPlus > 2.25)
93         {
94             Edash /= fnRough(KsPlus, Cs_[faceI]);
95         }
97         if (yPlus > yPlusLam_)
98         {
99             scalar limitingNutw = max(nutw[faceI], nuw[faceI]);
101             // To avoid oscillations limit the change in the wall viscosity
102             // which is particularly important if it temporarily becomes zero
103             nutw[faceI] =
104                 max
105                 (
106                     min
107                     (
108                         nuw[faceI]
109                        *(yPlus*kappa_/log(max(Edash*yPlus, 1+1e-4)) - 1),
110                         2*limitingNutw
111                     ), 0.5*limitingNutw
112                 );
113         }
115         if (debug)
116         {
117             Info<< "yPlus = " << yPlus
118                 << ", KsPlus = " << KsPlus
119                 << ", Edash = " << Edash
120                 << ", nutw = " << nutw[faceI]
121                 << endl;
122         }
123     }
125     return tnutw;
129 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
131 nutRoughWallFunctionFvPatchScalarField::nutRoughWallFunctionFvPatchScalarField
133     const fvPatch& p,
134     const DimensionedField<scalar, volMesh>& iF
137     nutWallFunctionFvPatchScalarField(p, iF),
138     Ks_(p.size(), 0.0),
139     Cs_(p.size(), 0.0)
143 nutRoughWallFunctionFvPatchScalarField::nutRoughWallFunctionFvPatchScalarField
145     const nutRoughWallFunctionFvPatchScalarField& ptf,
146     const fvPatch& p,
147     const DimensionedField<scalar, volMesh>& iF,
148     const fvPatchFieldMapper& mapper
151     nutWallFunctionFvPatchScalarField(ptf, p, iF, mapper),
152     Ks_(ptf.Ks_, mapper),
153     Cs_(ptf.Cs_, mapper)
157 nutRoughWallFunctionFvPatchScalarField::nutRoughWallFunctionFvPatchScalarField
159     const fvPatch& p,
160     const DimensionedField<scalar, volMesh>& iF,
161     const dictionary& dict
164     nutWallFunctionFvPatchScalarField(p, iF, dict),
165     Ks_("Ks", dict, p.size()),
166     Cs_("Cs", dict, p.size())
170 nutRoughWallFunctionFvPatchScalarField::nutRoughWallFunctionFvPatchScalarField
172     const nutRoughWallFunctionFvPatchScalarField& rwfpsf
175     nutWallFunctionFvPatchScalarField(rwfpsf),
176     Ks_(rwfpsf.Ks_),
177     Cs_(rwfpsf.Cs_)
181 nutRoughWallFunctionFvPatchScalarField::nutRoughWallFunctionFvPatchScalarField
183     const nutRoughWallFunctionFvPatchScalarField& rwfpsf,
184     const DimensionedField<scalar, volMesh>& iF
187     nutWallFunctionFvPatchScalarField(rwfpsf, iF),
188     Ks_(rwfpsf.Ks_),
189     Cs_(rwfpsf.Cs_)
193 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
195 void nutRoughWallFunctionFvPatchScalarField::autoMap
197     const fvPatchFieldMapper& m
200     nutWallFunctionFvPatchScalarField::autoMap(m);
201     Ks_.autoMap(m);
202     Cs_.autoMap(m);
206 void nutRoughWallFunctionFvPatchScalarField::rmap
208     const fvPatchScalarField& ptf,
209     const labelList& addr
212     nutWallFunctionFvPatchScalarField::rmap(ptf, addr);
214     const nutRoughWallFunctionFvPatchScalarField& nrwfpsf =
215         refCast<const nutRoughWallFunctionFvPatchScalarField>(ptf);
217     Ks_.rmap(nrwfpsf.Ks_, addr);
218     Cs_.rmap(nrwfpsf.Cs_, addr);
222 void nutRoughWallFunctionFvPatchScalarField::write(Ostream& os) const
224     fvPatchField<scalar>::write(os);
225     writeLocalEntries(os);
226     Cs_.writeEntry("Cs", os);
227     Ks_.writeEntry("Ks", os);
228     writeEntry("value", os);
232 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 makePatchTypeField(fvPatchScalarField, nutRoughWallFunctionFvPatchScalarField);
236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
238 } // End namespace RASModels
239 } // End namespace incompressible
240 } // End namespace Foam
242 // ************************************************************************* //