FreeFOAM The Cross-Platform CFD Toolkit
muSgsWallFunctionFvPatchScalarField.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 
29 #include <finiteVolume/volFields.H>
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace compressible
37 {
38 namespace LESModels
39 {
40 
41 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 
43 muSgsWallFunctionFvPatchScalarField::muSgsWallFunctionFvPatchScalarField
44 (
45  const fvPatch& p,
47 )
48 :
49  fixedValueFvPatchScalarField(p, iF),
50  UName_("U"),
51  rhoName_("rho"),
52  muName_("mu"),
53  kappa_(0.41),
54  E_(9.8)
55 {}
56 
57 
58 muSgsWallFunctionFvPatchScalarField::muSgsWallFunctionFvPatchScalarField
59 (
61  const fvPatch& p,
63  const fvPatchFieldMapper& mapper
64 )
65 :
66  fixedValueFvPatchScalarField(ptf, p, iF, mapper),
67  UName_(ptf.UName_),
68  rhoName_(ptf.rhoName_),
69  muName_(ptf.muName_),
70  kappa_(ptf.kappa_),
71  E_(ptf.E_)
72 {}
73 
74 
75 muSgsWallFunctionFvPatchScalarField::muSgsWallFunctionFvPatchScalarField
76 (
77  const fvPatch& p,
79  const dictionary& dict
80 )
81 :
82  fixedValueFvPatchScalarField(p, iF, dict),
83  UName_(dict.lookupOrDefault<word>("U", "U")),
84  rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
85  muName_(dict.lookupOrDefault<word>("mu", "mu")),
86  kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
87  E_(dict.lookupOrDefault<scalar>("E", 9.8))
88 {}
89 
90 
91 muSgsWallFunctionFvPatchScalarField::muSgsWallFunctionFvPatchScalarField
92 (
94 )
95 :
96  fixedValueFvPatchScalarField(mwfpsf),
97  UName_(mwfpsf.UName_),
98  rhoName_(mwfpsf.rhoName_),
99  muName_(mwfpsf.muName_),
100  kappa_(mwfpsf.kappa_),
101  E_(mwfpsf.E_)
102 {}
103 
104 
105 muSgsWallFunctionFvPatchScalarField::muSgsWallFunctionFvPatchScalarField
106 (
109 )
110 :
111  fixedValueFvPatchScalarField(mwfpsf, iF),
112  UName_(mwfpsf.UName_),
113  rhoName_(mwfpsf.rhoName_),
114  muName_(mwfpsf.muName_),
115  kappa_(mwfpsf.kappa_),
116  E_(mwfpsf.E_)
117 {}
118 
119 
120 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121 
122 void muSgsWallFunctionFvPatchScalarField::evaluate
123 (
124  const Pstream::commsTypes
125 )
126 {
127  const scalarField& ry = patch().deltaCoeffs();
128 
129  const fvPatchVectorField& U =
130  patch().lookupPatchField<volVectorField, vector>(UName_);
131 
132  scalarField magUp = mag(U.patchInternalField() - U);
133 
134  const scalarField& muw =
135  patch().lookupPatchField<volScalarField, scalar>(muName_);
136 
137  const scalarField& rhow =
138  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
139 
140  scalarField& muSgsw = *this;
141 
142  scalarField magFaceGradU = mag(U.snGrad());
143 
144  forAll(muSgsw, facei)
145  {
146  scalar magUpara = magUp[facei];
147 
148  scalar utau =
149  sqrt((muSgsw[facei] + muw[facei])*magFaceGradU[facei]/rhow[facei]);
150 
151  if (utau > 0)
152  {
153  int iter = 0;
154  scalar err = GREAT;
155 
156  do
157  {
158  scalar kUu = kappa_*magUpara/utau;
159  scalar fkUu = exp(kUu) - 1 - kUu*(1 + 0.5*kUu);
160 
161  scalar f =
162  - utau/(ry[facei]*muw[facei]/rhow[facei])
163  + magUpara/utau
164  + 1/E_*(fkUu - 1.0/6.0*kUu*sqr(kUu));
165 
166  scalar df =
167  - 1.0/(ry[facei]*muw[facei]/rhow[facei])
168  - magUpara/sqr(utau)
169  - 1/E_*kUu*fkUu/utau;
170 
171  scalar utauNew = utau - f/df;
172  err = mag((utau - utauNew)/utau);
173  utau = utauNew;
174 
175  } while (utau > VSMALL && err > 0.01 && ++iter < 10);
176 
177  muSgsw[facei] =
178  max
179  (
180  rhow[facei]*sqr(utau)/magFaceGradU[facei] - muw[facei],
181  0.0
182  );
183  }
184  else
185  {
186  muSgsw[facei] = 0;
187  }
188  }
189 }
190 
191 
192 void muSgsWallFunctionFvPatchScalarField::write(Ostream& os) const
193 {
195  writeEntryIfDifferent<word>(os, "U", "U", UName_);
196  writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
197  writeEntryIfDifferent<word>(os, "mu", "mu", muName_);
198  os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl;
199  os.writeKeyword("E") << E_ << token::END_STATEMENT << nl;
200  writeEntry("value", os);
201 }
202 
203 
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 
207 (
210 );
211 
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 
214 } // End namespace LESModels
215 } // End namespace compressible
216 } // End namespace Foam
217 
218 // ************************ vim: set sw=4 sts=4 et: ************************ //