FreeFOAM The Cross-Platform CFD Toolkit
mutkWallFunctionFvPatchScalarField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2008-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
29 #include <finiteVolume/volFields.H>
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace compressible
38 {
39 namespace RASModels
40 {
41 
42 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
43 
44 void mutkWallFunctionFvPatchScalarField::checkType()
45 {
46  if (!isA<wallFvPatch>(patch()))
47  {
48  FatalErrorIn("mutkWallFunctionFvPatchScalarField::checkType()")
49  << "Invalid wall function specification" << nl
50  << " Patch type for patch " << patch().name()
51  << " must be wall" << nl
52  << " Current patch type is " << patch().type() << nl << endl
53  << abort(FatalError);
54  }
55 }
56 
57 
58 scalar mutkWallFunctionFvPatchScalarField::calcYPlusLam
59 (
60  const scalar kappa,
61  const scalar E
62 ) const
63 {
64  scalar ypl = 11.0;
65 
66  for (int i=0; i<10; i++)
67  {
68  ypl = log(E*ypl)/kappa;
69  }
70 
71  return ypl;
72 }
73 
74 
75 tmp<scalarField> mutkWallFunctionFvPatchScalarField::calcMut() const
76 {
77  const label patchI = patch().index();
78  const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
79  const scalarField& y = rasModel.y()[patchI];
80  const scalarField& rhow = rasModel.rho().boundaryField()[patchI];
81  const tmp<volScalarField> tk = rasModel.k();
82  const volScalarField& k = tk();
83  const scalarField& muw = rasModel.mu().boundaryField()[patchI];
84 
85  const scalar Cmu25 = pow(Cmu_, 0.25);
86 
87  tmp<scalarField> tmutw(new scalarField(patch().size(), 0.0));
88  scalarField& mutw = tmutw();
89 
90  forAll(mutw, faceI)
91  {
92  label faceCellI = patch().faceCells()[faceI];
93 
94  scalar yPlus =
95  Cmu25*y[faceI]*sqrt(k[faceCellI])/(muw[faceI]/rhow[faceI]);
96 
97  if (yPlus > yPlusLam_)
98  {
99  mutw[faceI] = muw[faceI]*(yPlus*kappa_/log(E_*yPlus) - 1);
100  }
101  }
102 
103  return tmutw;
104 }
105 
106 
107 void mutkWallFunctionFvPatchScalarField::writeLocalEntries(Ostream& os) const
108 {
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;
112 }
113 
114 
115 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
116 
117 mutkWallFunctionFvPatchScalarField::mutkWallFunctionFvPatchScalarField
118 (
119  const fvPatch& p,
121 )
122 :
123  fixedValueFvPatchScalarField(p, iF),
124  Cmu_(0.09),
125  kappa_(0.41),
126  E_(9.8),
127  yPlusLam_(calcYPlusLam(kappa_, E_))
128 {}
129 
130 
131 mutkWallFunctionFvPatchScalarField::mutkWallFunctionFvPatchScalarField
132 (
134  const fvPatch& p,
136  const fvPatchFieldMapper& mapper
137 )
138 :
139  fixedValueFvPatchScalarField(ptf, p, iF, mapper),
140  Cmu_(ptf.Cmu_),
141  kappa_(ptf.kappa_),
142  E_(ptf.E_),
143  yPlusLam_(ptf.yPlusLam_)
144 {}
145 
146 
147 mutkWallFunctionFvPatchScalarField::mutkWallFunctionFvPatchScalarField
148 (
149  const fvPatch& p,
151  const dictionary& dict
152 )
153 :
154  fixedValueFvPatchScalarField(p, iF, dict),
155  Cmu_(dict.lookupOrDefault<scalar>("Cmu", 0.09)),
156  kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
157  E_(dict.lookupOrDefault<scalar>("E", 9.8)),
158  yPlusLam_(calcYPlusLam(kappa_, E_))
159 {}
160 
161 
162 mutkWallFunctionFvPatchScalarField::mutkWallFunctionFvPatchScalarField
163 (
165 )
166 :
167  fixedValueFvPatchScalarField(wfpsf),
168  Cmu_(wfpsf.Cmu_),
169  kappa_(wfpsf.kappa_),
170  E_(wfpsf.E_),
171  yPlusLam_(wfpsf.yPlusLam_)
172 {}
173 
174 
175 mutkWallFunctionFvPatchScalarField::mutkWallFunctionFvPatchScalarField
176 (
179 )
180 :
181  fixedValueFvPatchScalarField(wfpsf, iF),
182  Cmu_(wfpsf.Cmu_),
183  kappa_(wfpsf.kappa_),
184  E_(wfpsf.E_),
185  yPlusLam_(wfpsf.yPlusLam_)
186 {}
187 
188 
189 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
190 
191 void mutkWallFunctionFvPatchScalarField::updateCoeffs()
192 {
193  if (updated())
194  {
195  return;
196  }
197 
198  operator==(calcMut());
199 
200  fixedValueFvPatchScalarField::updateCoeffs();
201 }
202 
203 
204 tmp<scalarField> mutkWallFunctionFvPatchScalarField::yPlus() const
205 {
206  const label patchI = patch().index();
207 
208  const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
209  const scalarField& y = rasModel.y()[patchI];
210 
211  const tmp<volScalarField> tk = rasModel.k();
212  const volScalarField& k = tk();
213  const scalarField kwc = k.boundaryField()[patchI].patchInternalField();
214  const scalarField& muw = rasModel.mu().boundaryField()[patchI];
215  const scalarField& rhow = rasModel.rho().boundaryField()[patchI];
216 
217  return pow(Cmu_, 0.25)*y*sqrt(kwc)/(muw/rhow);
218 }
219 
220 
221 void mutkWallFunctionFvPatchScalarField::write(Ostream& os) const
222 {
224  writeLocalEntries(os);
225  writeEntry("value", os);
226 }
227 
228 
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 
232 
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 
235 } // End namespace RASModels
236 } // End namespace compressible
237 } // End namespace Foam
238 
239 // ************************ vim: set sw=4 sts=4 et: ************************ //