FreeFOAM The Cross-Platform CFD Toolkit
mutSpalartAllmarasWallFunctionFvPatchScalarField.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) 1991-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 
28 #include <finiteVolume/volFields.H>
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace compressible
37 {
38 namespace RASModels
39 {
40 
41 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
42 
43 tmp<scalarField> mutSpalartAllmarasWallFunctionFvPatchScalarField::calcUTau
44 (
45  const scalarField& magGradU
46 ) const
47 {
48  const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
49  const scalarField& y = rasModel.y()[patch().index()];
50 
51  const fvPatchVectorField& Uw =
52  rasModel.U().boundaryField()[patch().index()];
53 
54  scalarField magUp = mag(Uw.patchInternalField() - Uw);
55 
56  const fvPatchScalarField& rhow =
57  rasModel.rho().boundaryField()[patch().index()];
58 
59  const fvPatchScalarField& muw =
60  rasModel.mu().boundaryField()[patch().index()];
61  const scalarField& mutw = *this;
62 
63  tmp<scalarField> tuTau(new scalarField(patch().size(), 0.0));
64  scalarField& uTau = tuTau();
65 
66  forAll(mutw, faceI)
67  {
68  scalar magUpara = magUp[faceI];
69 
70  scalar ut =
71  sqrt((mutw[faceI] + muw[faceI])*magGradU[faceI]/rhow[faceI]);
72 
73  if (ut > VSMALL)
74  {
75  int iter = 0;
76  scalar err = GREAT;
77 
78  do
79  {
80  scalar kUu = min(kappa_*magUpara/ut, 50);
81  scalar fkUu = exp(kUu) - 1 - kUu*(1 + 0.5*kUu);
82 
83  scalar f =
84  - ut*y[faceI]/(muw[faceI]/rhow[faceI])
85  + magUpara/ut
86  + 1/E_*(fkUu - 1.0/6.0*kUu*sqr(kUu));
87 
88  scalar df =
89  y[faceI]/(muw[faceI]/rhow[faceI])
90  + magUpara/sqr(ut)
91  + 1/E_*kUu*fkUu/ut;
92 
93  scalar uTauNew = ut + f/df;
94  err = mag((ut - uTauNew)/ut);
95  ut = uTauNew;
96 
97  } while (ut > VSMALL && err > 0.01 && ++iter < 10);
98 
99  uTau[faceI] = max(0.0, ut);
100  }
101  }
102 
103  return tuTau;
104 }
105 
106 
108 mutSpalartAllmarasWallFunctionFvPatchScalarField::calcMut() const
109 {
110  const label patchI = patch().index();
111 
112  const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
113  const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI];
114  const scalarField magGradU = mag(Uw.snGrad());
115  const scalarField& rhow = rasModel.rho().boundaryField()[patchI];
116  const scalarField& muw = rasModel.mu().boundaryField()[patchI];
117 
118  return max
119  (
120  scalar(0),
121  rhow*sqr(calcUTau(magGradU))/(magGradU + ROOTVSMALL) - muw
122  );
123 }
124 
125 
126 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
127 
128 mutSpalartAllmarasWallFunctionFvPatchScalarField::
129 mutSpalartAllmarasWallFunctionFvPatchScalarField
130 (
131  const fvPatch& p,
133 )
134 :
136 {}
137 
138 
139 mutSpalartAllmarasWallFunctionFvPatchScalarField::
140 mutSpalartAllmarasWallFunctionFvPatchScalarField
141 (
143  const fvPatch& p,
145  const fvPatchFieldMapper& mapper
146 )
147 :
148  mutWallFunctionFvPatchScalarField(ptf, p, iF, mapper)
149 {}
150 
151 
152 mutSpalartAllmarasWallFunctionFvPatchScalarField::
153 mutSpalartAllmarasWallFunctionFvPatchScalarField
154 (
155  const fvPatch& p,
157  const dictionary& dict
158 )
159 :
161 {}
162 
163 
164 mutSpalartAllmarasWallFunctionFvPatchScalarField::
165 mutSpalartAllmarasWallFunctionFvPatchScalarField
166 (
168 )
169 :
171 {}
172 
173 
174 mutSpalartAllmarasWallFunctionFvPatchScalarField::
175 mutSpalartAllmarasWallFunctionFvPatchScalarField
176 (
179 )
180 :
182 {}
183 
184 
185 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
186 
188 mutSpalartAllmarasWallFunctionFvPatchScalarField::yPlus() const
189 {
190  const label patchI = patch().index();
191 
192  const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
193  const scalarField& y = rasModel.y()[patchI];
194  const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI];
195  const scalarField& rhow = rasModel.rho().boundaryField()[patchI];
196  const scalarField& muw = rasModel.mu().boundaryField()[patchI];
197 
198  return y*calcUTau(mag(Uw.snGrad()))/(muw/rhow);
199 }
200 
201 
202 void mutSpalartAllmarasWallFunctionFvPatchScalarField::write
203 (
204  Ostream& os
205 ) const
206 {
208  writeLocalEntries(os);
209  writeEntry("value", os);
210 }
211 
212 
213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214 
216 
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
218 
219 } // End namespace RASModels
220 } // End namespace compressible
221 } // End namespace Foam
222 
223 // ************************ vim: set sw=4 sts=4 et: ************************ //