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