alphatJayatillekeWallFunctionFvPatchScalarField.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2022 OpenCFD Ltd
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
30 #include "fvPatchFieldMapper.H"
31 #include "volFields.H"
33 #include "wallFvPatch.H"
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 namespace compressible
41 {
42 
43 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
44 
45 scalar alphatJayatillekeWallFunctionFvPatchScalarField::maxExp_ = 50.0;
46 scalar alphatJayatillekeWallFunctionFvPatchScalarField::tolerance_ = 0.01;
47 label alphatJayatillekeWallFunctionFvPatchScalarField::maxIters_ = 10;
48 
49 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 
51 void alphatJayatillekeWallFunctionFvPatchScalarField::checkType()
52 {
53  if (!isA<wallFvPatch>(patch()))
54  {
56  << "Patch type for patch " << patch().name() << " must be wall\n"
57  << "Current patch type is " << patch().type() << nl
58  << exit(FatalError);
59  }
60 }
61 
62 
63 tmp<scalarField> alphatJayatillekeWallFunctionFvPatchScalarField::yPlus
64 (
65  const compressible::turbulenceModel& turbModel
66 ) const
67 {
68  const label patchi = patch().index();
69 
70  const tmp<volScalarField> tnut = turbModel.nut();
71  const volScalarField& nut = tnut();
72 
73  if (isA<nutWallFunctionFvPatchScalarField>(nut.boundaryField()[patchi]))
74  {
75  const auto& nutPf =
76  dynamic_cast<const nutWallFunctionFvPatchScalarField&>
77  (
78  nut.boundaryField()[patchi]
79  );
80 
81  return nutPf.yPlus();
82  }
83  else
84  {
85  const scalarField& y = turbModel.y()[patchi];
86  const fvPatchVectorField& Uw = turbModel.U().boundaryField()[patchi];
87 
88  return
89  y*sqrt(turbModel.nuEff(patchi)*mag(Uw.snGrad()))
90  /turbModel.nu(patchi);
91  }
92 }
93 
94 
95 scalar alphatJayatillekeWallFunctionFvPatchScalarField::Psmooth
96 (
97  const scalar Prat
98 ) const
99 {
100  return 9.24*(pow(Prat, 0.75) - 1.0)*(1.0 + 0.28*exp(-0.007*Prat));
101 }
102 
103 
104 scalar alphatJayatillekeWallFunctionFvPatchScalarField::yPlusTherm
105 (
106  const scalar P,
107  const scalar Prat
108 ) const
109 {
110  scalar ypt = 11;
111 
112  for (int iter = 0; iter < maxIters_; ++iter)
113  {
114  const scalar f = ypt - (log(E_*ypt)/kappa_ + P)/Prat;
115  const scalar df = 1.0 - 1.0/(ypt*kappa_*Prat);
116  const scalar yptNew = ypt - f/df;
117 
118  if (yptNew < VSMALL)
119  {
120  return 0;
121  }
122  else if (mag(yptNew - ypt) < tolerance_)
123  {
124  return yptNew;
125  }
126  else
127  {
128  ypt = yptNew;
129  }
130  }
131 
132  return ypt;
133 }
134 
135 
136 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
137 
140 (
141  const fvPatch& p,
143 )
144 :
145  parent_bctype(p, iF),
146  Prt_(0.85),
147  kappa_(0.41),
148  E_(9.8)
149 {
150  checkType();
151 }
152 
153 
156 (
157  const this_bctype& ptf,
158  const fvPatch& p,
160  const fvPatchFieldMapper& mapper
161 )
162 :
163  parent_bctype(ptf, p, iF, mapper),
164  Prt_(ptf.Prt_),
165  kappa_(ptf.kappa_),
166  E_(ptf.E_)
167 {}
168 
169 
172 (
173  const fvPatch& p,
175  const dictionary& dict
176 )
177 :
178  parent_bctype(p, iF, dict),
179  Prt_(dict.getOrDefault<scalar>("Prt", 0.85)),
180  kappa_(dict.getOrDefault<scalar>("kappa", 0.41)),
181  E_(dict.getOrDefault<scalar>("E", 9.8))
182 {
183  checkType();
184 }
185 
186 
189 (
190  const this_bctype& awfpsf,
192 )
193 :
194  parent_bctype(awfpsf, iF),
195  Prt_(awfpsf.Prt_),
196  kappa_(awfpsf.kappa_),
197  E_(awfpsf.E_)
198 {
199  checkType();
200 }
201 
202 
203 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
204 
206 {
207  if (updated())
208  {
209  return;
210  }
211 
212  const label patchi = patch().index();
213 
214  // Retrieve turbulence properties from model
215  const auto& turbModel = db().lookupObject<compressible::turbulenceModel>
216  (
218  (
219  compressible::turbulenceModel::propertiesName,
220  internalField().group()
221  )
222  );
223 
224  const scalarField yPlusp(yPlus(turbModel));
225 
226  const scalarField& y = turbModel.y()[patchi];
227 
228  const tmp<scalarField> tmuw = turbModel.mu(patchi);
229  const scalarField& muw = tmuw();
230 
231  const tmp<scalarField> talphaw = turbModel.alpha(patchi);
232  const scalarField& alphaw = talphaw();
233 
234  const fvPatchVectorField& Uw = turbModel.U().boundaryField()[patchi];
235  const scalarField magUp(mag(Uw.patchInternalField() - Uw));
236  const scalarField magGradUw(mag(Uw.snGrad()));
237 
238  const scalarField& rhow = turbModel.rho().boundaryField()[patchi];
239  const fvPatchScalarField& hew =
240  turbModel.transport().he().boundaryField()[patchi];
241 
242  scalarField& alphatw = *this;
243 
244  // Heat flux [W/m2] - lagging alphatw
245  const scalarField qDot
246  (
247  turbModel.transport().alphaEff(alphatw, patchi)*hew.snGrad()
248  );
249 
250  // Populate boundary values
251  forAll(alphatw, facei)
252  {
253  const scalar yPlus = yPlusp[facei];
254 
255  const scalar uTau = yPlus/y[facei]*(muw[facei]/rhow[facei]);
256 
257  // Molecular Prandtl number
258  const scalar Pr = muw[facei]/alphaw[facei];
259 
260  // Molecular-to-turbulent Prandtl number ratio
261  const scalar Prat = Pr/Prt_;
262 
263  // Thermal sublayer thickness
264  const scalar P = Psmooth(Prat);
265  const scalar yPlusTherm = this->yPlusTherm(P, Prat);
266 
267  // Evaluate new effective thermal diffusivity
268  scalar alphaEff = 0;
269  if (yPlus < yPlusTherm)
270  {
271  const scalar A = qDot[facei]*rhow[facei]*uTau*y[facei];
272  const scalar B = qDot[facei]*Pr*yPlus;
273  const scalar C = Pr*0.5*rhow[facei]*uTau*sqr(magUp[facei]);
274 
275  alphaEff = A/(B + C + VSMALL);
276  }
277  else
278  {
279  const scalar A = qDot[facei]*rhow[facei]*uTau*y[facei];
280  const scalar B = qDot[facei]*Prt_*(1.0/kappa_*log(E_*yPlus) + P);
281  const scalar magUc =
282  uTau/kappa_*log(E_*yPlusTherm) - mag(Uw[facei]);
283  const scalar C =
284  0.5*rhow[facei]*uTau
285  *(Prt_*sqr(magUp[facei]) + (Pr - Prt_)*sqr(magUc));
286 
287  alphaEff = A/(B + C + VSMALL);
288  }
289 
290  // Update turbulent thermal diffusivity
291  alphatw[facei] = max(scalar(0), alphaEff - alphaw[facei]);
292 
293  if (debug)
294  {
295  Info<< " uTau = " << uTau << nl
296  << " Pr = " << Pr << nl
297  << " Prt = " << Prt_ << nl
298  << " qDot = " << qDot[facei] << nl
299  << " yPlus = " << yPlus << nl
300  << " yPlusTherm = " << yPlusTherm << nl
301  << " alphaEff = " << alphaEff << nl
302  << " alphaw = " << alphaw[facei] << nl
303  << " alphatw = " << alphatw[facei] << nl
304  << endl;
305  }
306  }
307 
309 }
310 
311 
313 {
315  os.writeEntryIfDifferent<scalar>("Prt", 0.85, Prt_);
316  os.writeEntryIfDifferent<scalar>("kappa", 0.41, kappa_);
317  os.writeEntryIfDifferent<scalar>("E", 9.8, E_);
319 }
320 
321 
322 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
323 
325 (
327  alphatJayatillekeWallFunctionFvPatchScalarField
328 );
329 
330 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
331 
332 } // End namespace compressible
333 } // End namespace Foam
334 
335 // ************************************************************************* //
dimensionedScalar Pr("Pr", dimless, laminarTransport)
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
dictionary dict
Graphite solid properties.
Definition: C.H:46
fvPatchField< vector > fvPatchVectorField
dimensionedScalar log(const dimensionedScalar &ds)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:130
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:652
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
dimensionedSymmTensor sqr(const dimensionedVector &dv)
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
virtual void write(Ostream &) const
Write.
ThermalDiffusivity< CompressibleTurbulenceModel< fluidThermo > > turbulenceModel
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:518
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
void writeValueEntry(Ostream &os) const
Write *this field as a "value" entry.
Definition: fvPatchField.H:425
Templated wrapper class to provide compressible turbulence models thermal diffusivity based thermal t...
Macros for easy insertion into run-time selection tables.
scalar magUp
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:400
constexpr const char *const group
Group name for atomic constants.
makePatchTypeField(fvPatchScalarField, alphatFixedDmdtWallBoilingWallFunctionFvPatchScalarField)
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:72
scalar uTau
alphatJayatillekeWallFunctionFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
scalar y
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
dimensionedScalar exp(const dimensionedScalar &ds)
fvPatchField< scalar > fvPatchScalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
A FieldMapper for finite-volume patch fields.
bool compressible
Definition: pEqn.H:2
int debug
Static debugging option.
volScalarField & C
labelList f(nPoints)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
scalar yPlus
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const std::string patch
OpenFOAM patch number as a std::string.
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual tmp< Field< Type > > patchInternalField() const
Return internal field next to patch.
volScalarField alphaEff("alphaEff", turbulence->nu()/Pr+alphat)
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
static const Foam::dimensionedScalar B("", Foam::dimless, 18.678)
scalar nut
Namespace for OpenFOAM.