immersedBoundaryOmegaWallFunctionFvPatchScalarField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | foam-extend: Open Source CFD
4  \\ / O peration | Version: 3.2
5  \\ / A nd | Web: http://www.foam-extend.org
6  \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9  This file is part of foam-extend.
10 
11  foam-extend 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 3 of the License, or (at your
14  option) any later version.
15 
16  foam-extend is distributed in the hope that it will be useful, but
17  WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
28 #include "RASModel.H"
29 #include "fvPatchFieldMapper.H"
30 #include "volFields.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace incompressible
38 {
39 namespace RASModels
40 {
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
46 (
47  const fvPatch& p,
49 )
50 :
51  immersedBoundaryWallFunctionFvPatchScalarField(p, iF),
52  UName_("U"),
53  kName_("k"),
54  GName_("RASModel::G"),
55  nuName_("nu"),
56  nutName_("nut"),
57  Cmu_(0.09),
58  kappa_(0.41),
59  E_(9.8),
60  beta1_(0.075)
61 {}
62 
63 
66 (
67  const fvPatch& p,
69  const dictionary& dict
70 )
71 :
72  immersedBoundaryWallFunctionFvPatchScalarField(p, iF, dict),
73  UName_(dict.lookupOrDefault<word>("U", "U")),
74  kName_(dict.lookupOrDefault<word>("k", "k")),
75  GName_(dict.lookupOrDefault<word>("G", "RASModel::G")),
76  nuName_(dict.lookupOrDefault<word>("nu", "nu")),
77  nutName_(dict.lookupOrDefault<word>("nut", "nut")),
78  Cmu_(dict.lookupOrDefault<scalar>("Cmu", 0.09)),
79  kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
80  E_(dict.lookupOrDefault<scalar>("E", 9.8)),
81  beta1_(dict.lookupOrDefault<scalar>("beta1", 0.075))
82 {}
83 
84 
87 (
89  const fvPatch& p,
91  const fvPatchFieldMapper& mapper
92 )
93 :
94  immersedBoundaryWallFunctionFvPatchScalarField(ptf, p, iF, mapper),
95  UName_(ptf.UName_),
96  kName_(ptf.kName_),
97  GName_(ptf.GName_),
98  nuName_(ptf.nuName_),
99  nutName_(ptf.nutName_),
100  Cmu_(ptf.Cmu_),
101  kappa_(ptf.kappa_),
102  E_(ptf.E_),
103  beta1_(ptf.beta1_)
104 {}
105 
106 
109 (
111 )
112 :
113  immersedBoundaryWallFunctionFvPatchScalarField(owfpsf),
114  UName_(owfpsf.UName_),
115  kName_(owfpsf.kName_),
116  GName_(owfpsf.GName_),
117  nuName_(owfpsf.nuName_),
118  nutName_(owfpsf.nutName_),
119  Cmu_(owfpsf.Cmu_),
120  kappa_(owfpsf.kappa_),
121  E_(owfpsf.E_),
122  beta1_(owfpsf.beta1_)
123 {}
124 
125 
128 (
131 )
132 :
133  immersedBoundaryWallFunctionFvPatchScalarField(owfpsf, iF),
134  UName_(owfpsf.UName_),
135  kName_(owfpsf.kName_),
136  GName_(owfpsf.GName_),
137  nuName_(owfpsf.nuName_),
138  nutName_(owfpsf.nutName_),
139  Cmu_(owfpsf.Cmu_),
140  kappa_(owfpsf.kappa_),
141  E_(owfpsf.E_),
142  beta1_(owfpsf.beta1_)
143 {}
144 
145 
146 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
147 
149 {
150  if (updated())
151  {
152  return;
153  }
154 
155  // If G field is not present, execute zero gradient evaluation
156  // HJ, 20/Mar/2011
157  if (!db().foundObject<volScalarField>(GName_))
158  {
159  InfoIn
160  (
161  "void immersedBoundaryOmegaWallFunctionFvPatchScalarField::"
162  "updateCoeffs()"
163  ) << "Cannot access " << GName_ << " field. for patch "
164  << patch().name() << ". Evaluating as regular immersed boundary"
165  << endl;
166 
167  immersedBoundaryWallFunctionFvPatchScalarField::evaluate();
168 
169  return;
170  }
171 
172  const vectorField& n = ibPatch().ibNormals();
173 
174  const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
175  const scalar yPlusLam = rasModel.yPlusLam(kappa_, E_);
176 
177  const scalar Cmu25 = pow(Cmu_, 0.25);
178  const scalar Cmu50 = sqrt(Cmu_);
179 
180  volScalarField& G = const_cast<volScalarField&>
181  (db().lookupObject<volScalarField>(GName_));
182 
183  // Grab values of other fields required for wall functions
184 
185  // Velocity
186  const fvPatchVectorField& Uwg =
187  patch().lookupPatchField<volVectorField, vector>(UName_);
189  refCast<const immersedBoundaryVelocityWallFunctionFvPatchVectorField>
190  (
191  Uwg
192  );
193 
194  // Calculate tangential component, taking into account wall velocity
195  const vectorField UtanOld =
196  (I - sqr(n)) & (Uw.ibSamplingPointValue() - Uw.ibValue());
197  const scalarField magUtanOld = mag(UtanOld);
198 
199  // Tangential velocity component
200  scalarField& UTangentialNew = Uw.wallTangentialValue();
201 
202  // Wall shear stress
203  vectorField& tauWall = Uw.tauWall();
204 
205  // Turbulence kinetic energy
206  const fvPatchScalarField& kg =
207  patch().lookupPatchField<volScalarField, scalar>(kName_);
208  const immersedBoundaryWallFunctionFvPatchScalarField& kw =
209  refCast<const immersedBoundaryWallFunctionFvPatchScalarField>(kg);
210 
211  // Current and new values of k at sampling point
212  scalarField k = kw.ibSamplingPointValue();
213  scalarField& kNew = kw.wallValue();
214 
215  // Laminar viscosity
216  const fvPatchScalarField& nuwg =
217  patch().lookupPatchField<volScalarField, scalar>(nuName_);
218  const immersedBoundaryFvPatchScalarField& nuw =
219  refCast<const immersedBoundaryFvPatchScalarField>(nuwg);
220  scalarField nu = nuw.ibCellValue();
221 
222  // Turbulent viscosity
223  const fvPatchScalarField& nutwg =
224  patch().lookupPatchField<volScalarField, scalar>(nutName_);
225  const immersedBoundaryWallFunctionFvPatchScalarField& nutw =
226  refCast<const immersedBoundaryWallFunctionFvPatchScalarField>(nutwg);
227 
228  // New values of nut
229  scalarField nutOld = nutw.ibCellValue();
230  scalarField& nutNew = nutw.wallValue();
231 
232  const scalarField magGradUw = mag(Uw.ibGrad());
233 
234  // Get the IB addressing and distance
235  const labelList& ibc = ibPatch().ibCells();
236 
237  // Distance to sampling point
238  const scalarField& ySample = ibPatch().ibSamplingPointDelta();
239 
240  // Distance from wall to IB point
241  const scalarField& y = ibPatch().ibDelta();
242 
243  // Omega: store IB cell values for direct insertion
244  scalarField omegaSample = this->ibSamplingPointValue();
245 
246  scalarField& omegaNew = this->wallValue();
247 
248  // Mark values to be fixed
249  boolList wf(ibc.size(), false);
250 
251  // Calculate yPlus for sample points
252  scalarField ypd = Cmu25*ySample*sqrt(k)/nu;
253 
254  // Calculate wall function conditions
255  forAll (ibc, ibCellI)
256  {
257 
258  // Calculate yPlus from k and laminar viscosity for the IB point
259  const scalar yPlusSample = ypd[ibCellI];
260 
261  scalar tauW, uTau; // wall-shear and friction velocity from LOW
262 
263  if (yPlusSample > yPlusLam)
264  {
265  // Calculate tauW from log-law using k and U at sampling point
266 
267  tauW = magUtanOld[ibCellI]*Cmu25*sqrt(k[ibCellI])*kappa_
268  /log(E_*yPlusSample);
269  }
270  else
271  {
272  // Sampling point is in laminar sublayer
273  tauW = magUtanOld[ibCellI]*Cmu25*sqrt(k[ibCellI])/yPlusSample;
274  }
275 
276  // friction velocity computed from k and U at sampling point
277  uTau = sqrt(tauW);
278 
279  tauWall[ibCellI] = tauW*UtanOld[ibCellI]/(magUtanOld[ibCellI] + SMALL);
280 
281  // Calculate yPlus for IB point
282 
283  scalar yPlusIB = yPlusSample*y[ibCellI]/ySample[ibCellI];
284 
285  // Calculate wall function data in the immersed boundary point
286  if (yPlusIB > yPlusLam)
287  {
288  const scalar nuLam = nu[ibCellI];
289  // Logarithmic region
290  wf[ibCellI] = true;
291 
292  // turbulent viscosity at IB cell and at wall
293  scalar nutw = nuLam*(yPlusIB*kappa_/log(E_*yPlusIB) - 1);
294 
295  // Fix generation even though it if is not used
296  G[ibc[ibCellI]] =
297  sqr((nutw + nuLam)*magGradUw[ibCellI])/
298  (Cmu25*sqrt(k[ibCellI])*kappa_*y[ibCellI]);
299 
300  // Compute k at the IB cell
301  kNew[ibCellI] = tauW/Cmu50; // equilibrium boundary layer
302  // kNew[ibCellI] = k[ibCellI]; // zero-Gradient (less stable)
303 
304  // Compute omega at the IB cell
305  omegaNew[ibCellI] = sqrt(kNew[ibCellI])/(Cmu25*kappa_*y[ibCellI]);
306 
307  // Log-Law for tangential velocity - uTau = Cmu25*sqrt(kNew)
308  UTangentialNew[ibCellI] = uTau/kappa_*log(E_*yPlusIB);
309 
310  // Calculate turbulent viscosity
311  nutNew[ibCellI] = nutw;
312  }
313  else
314  {
315  // Laminar sub-layer
316  wf[ibCellI] = false;
317 
318  // G is zero - immaterial!
319  // G[ibc[ibCellI]] = 0;
320 
321  // quadratic fit
322  kNew[ibCellI] = k[ibCellI]*sqr(yPlusIB/yPlusLam);
323 
324  // Compute omega at the IB cell
325  omegaNew[ibCellI] = 6.0*nu[ibCellI]/(beta1_*sqr(y[ibCellI]));
326 
327  // Bugfix - set zeroGradient bc for large omega values at ib boundary
328  // to avoid k unboundedness (IG 30/OCT/2015), not
329  // sure if this is a good criteria
330  if(omegaNew[ibCellI] > 10.0)
331  {
332  wf[ibCellI] = true;
333  }
334 
335  // Laminar sub-layer for tangential velocity: uPlus = yPlus
336  UTangentialNew[ibCellI] = uTau*yPlusIB;
337 
338  // Turbulent viscosity is zero
339  nutNew[ibCellI] = SMALL;
340  }
341  }
342 
343 // Info<< "UTangentialNew " << min(UTangentialNew) << " " << max(UTangentialNew) << endl;
344 // Info<< "nutNew " << min(nutNew) << " " << max(nutNew) << endl;
345 // Info<< "kNew " << min(kNew) << " " << max(kNew) << endl;
346 // Info<< "epsilonNew " << min(epsilonNew) << " " << max(epsilonNew) << endl;
347 
348  // Set the fields to calculated wall function values
349  Uw.wallMask() = true;
350  kw.wallMask() = wf;
351  nutw.wallMask() = true;
352  this->wallMask() = true;
353 
354  // Insert epsilon values into the internal field
355  immersedBoundaryWallFunctionFvPatchScalarField::updateCoeffs();
356 }
357 
358 
360 (
361  const Pstream::commsTypes commsType
362 )
363 {
364  // Insert epsilon values into the internal field
365  this->setIbCellValues(this->wallValue());
366 
367  fvPatchScalarField::evaluate(commsType);
368 }
369 
370 
372 write(Ostream& os) const
373 {
375  writeEntryIfDifferent<word>(os, "U", "U", UName_);
376  writeEntryIfDifferent<word>(os, "k", "k", kName_);
377  writeEntryIfDifferent<word>(os, "G", "RASModel::G", GName_);
378  writeEntryIfDifferent<word>(os, "nu", "nu", nuName_);
379  writeEntryIfDifferent<word>(os, "nut", "nut", nutName_);
380  os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl;
381  os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl;
382  os.writeKeyword("E") << E_ << token::END_STATEMENT << nl;
383  os.writeKeyword("beta1") << beta1_ << token::END_STATEMENT << nl;
384 }
385 
386 
387 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
388 
390 (
393 );
394 
395 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
396 
397 } // End namespace RASModels
398 } // End namespace incompressible
399 } // End namespace Foam
400 
401 // ************************************************************************* //
Foam::incompressible::RASModels::immersedBoundaryOmegaWallFunctionFvPatchScalarField::evaluate
virtual void evaluate(const Pstream::commsTypes=Pstream::blocking)
Evaluate the patchField.
Definition: immersedBoundaryOmegaWallFunctionFvPatchScalarField.C:360
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:65
volFields.H
Foam::token::END_STATEMENT
@ END_STATEMENT
Definition: token.H:99
Foam::fvPatchField::evaluate
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::blocking)
Evaluate the patch field, sets Updated to false.
Definition: fvPatchField.C:318
InfoIn
#define InfoIn(functionName)
Report a information message using Foam::Info.
Definition: messageStream.H:276
p
p
Definition: pEqn.H:62
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::incompressible::RASModel
RASModel< turbulenceModel > RASModel
Definition: turbulentTransportModel.H:59
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::constant::universal::G
const dimensionedScalar G
Newtonian constant of gravitation.
Foam::incompressible::RASModels::immersedBoundaryVelocityWallFunctionFvPatchVectorField
Boundary condition for velocity when using wall functions.
Definition: immersedBoundaryVelocityWallFunctionFvPatchVectorField.H:55
Foam::incompressible::RASModels::immersedBoundaryOmegaWallFunctionFvPatchScalarField
Provides a wall function boundary condition/constraint on omega.
Definition: immersedBoundaryOmegaWallFunctionFvPatchScalarField.H:68
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
fvPatchFieldMapper.H
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::incompressible::RASModels::immersedBoundaryOmegaWallFunctionFvPatchScalarField::nuName_
word nuName_
Name of laminar viscosity field.
Definition: immersedBoundaryOmegaWallFunctionFvPatchScalarField.H:84
Foam::incompressible::RASModels::immersedBoundaryOmegaWallFunctionFvPatchScalarField::GName_
word GName_
Name of turbulence generation field.
Definition: immersedBoundaryOmegaWallFunctionFvPatchScalarField.H:81
Foam::incompressible::RASModels::immersedBoundaryOmegaWallFunctionFvPatchScalarField::Cmu_
scalar Cmu_
Cmu coefficient.
Definition: immersedBoundaryOmegaWallFunctionFvPatchScalarField.H:90
nu
volScalarField & nu
Definition: readMechanicalProperties.H:179
n
label n
Definition: TABSMDCalcMethod2.H:31
immersedBoundaryVelocityWallFunctionFvPatchVectorField.H
Foam::incompressible::RASModels::immersedBoundaryOmegaWallFunctionFvPatchScalarField::UName_
word UName_
Name of velocity field.
Definition: immersedBoundaryOmegaWallFunctionFvPatchScalarField.H:75
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::incompressible::RASModels::immersedBoundaryOmegaWallFunctionFvPatchScalarField::nutName_
word nutName_
Name of turbulent viscosity field.
Definition: immersedBoundaryOmegaWallFunctionFvPatchScalarField.H:87
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:61
Foam::incompressible::RASModels::makePatchTypeField
makePatchTypeField(fvPatchScalarField, immersedBoundaryEpsilonWallFunctionFvPatchScalarField)
Foam::incompressible::RASModels::immersedBoundaryOmegaWallFunctionFvPatchScalarField::E_
scalar E_
E coefficient.
Definition: immersedBoundaryOmegaWallFunctionFvPatchScalarField.H:96
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:52
Foam::pow
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Definition: dimensionedScalar.C:73
uTau
scalar uTau
Definition: evaluateNearWall.H:14
Foam::I
static const sphericalTensor I(1)
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::incompressible::RASModels::immersedBoundaryOmegaWallFunctionFvPatchScalarField::kName_
word kName_
Name of turbulence kinetic energy field.
Definition: immersedBoundaryOmegaWallFunctionFvPatchScalarField.H:78
RASModel.H
Foam::log
dimensionedScalar log(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:253
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::volVectorField
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:55
immersedBoundaryOmegaWallFunctionFvPatchScalarField.H
Foam::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:64
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:142
Foam::incompressible::RASModels::immersedBoundaryOmegaWallFunctionFvPatchScalarField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: immersedBoundaryOmegaWallFunctionFvPatchScalarField.C:148
Foam::Ostream::writeKeyword
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:59
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::incompressible::RASModels::immersedBoundaryOmegaWallFunctionFvPatchScalarField::immersedBoundaryOmegaWallFunctionFvPatchScalarField
immersedBoundaryOmegaWallFunctionFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
Definition: immersedBoundaryOmegaWallFunctionFvPatchScalarField.C:46
Foam::incompressible::RASModels::immersedBoundaryOmegaWallFunctionFvPatchScalarField::kappa_
scalar kappa_
Von Karman constant.
Definition: immersedBoundaryOmegaWallFunctionFvPatchScalarField.H:93
Foam::fvPatchFieldMapper
Foam::fvPatchFieldMapper.
Definition: fvPatchFieldMapper.H:45
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::incompressible::RASModels::immersedBoundaryOmegaWallFunctionFvPatchScalarField::write
void write(Ostream &) const
Write.
Definition: immersedBoundaryOmegaWallFunctionFvPatchScalarField.C:372
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::incompressible::RASModels::immersedBoundaryOmegaWallFunctionFvPatchScalarField::beta1_
scalar beta1_
beta1 coefficient
Definition: immersedBoundaryOmegaWallFunctionFvPatchScalarField.H:99
write
Tcoeff write()
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:51
y
scalar y
Definition: LISASMDCalcMethod1.H:14