atmAlphatkWallFunctionFvPatchScalarField.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) 2020 ENERCON GmbH
9  Copyright (C) 2020-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 "turbulenceModel.H"
31 #include "fvPatchFieldMapper.H"
32 #include "volFields.H"
33 #include "wallFvPatch.H"
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 
41 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
42 
45 
46 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
47 
49 {
50  if (!isA<wallFvPatch>(patch()))
51  {
53  << "Invalid wall function specification" << nl
54  << " Patch type for patch " << patch().name()
55  << " must be wall" << nl
56  << " Current patch type is " << patch().type() << nl << endl
57  << abort(FatalError);
58  }
59 }
60 
61 
63 (
64  Ostream& os
65 ) const
66 {
67  os.writeEntryIfDifferent<scalar>("Cmu", 0.09, Cmu_);
68  os.writeEntryIfDifferent<scalar>("kappa", 0.41, kappa_);
69 
70  if (Pr_)
71  {
72  Pr_->writeData(os);
73  }
74  if (Prt_)
75  {
76  Prt_->writeData(os);
77  }
78  if (z0_)
79  {
80  z0_->writeData(os);
81  }
82 }
83 
84 
85 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
86 
89 (
90  const fvPatch& p,
92 )
93 :
94  parent_bctype(p, iF),
95  Cmu_(0.09),
96  kappa_(0.41),
97  Pr_(nullptr),
98  Prt_(nullptr),
99  z0_(nullptr)
100 {
101  checkType();
102 }
103 
104 
107 (
108  const this_bctype& ptf,
109  const fvPatch& p,
111  const fvPatchFieldMapper& mapper
112 )
113 :
114  parent_bctype(ptf, p, iF, mapper),
115  Cmu_(ptf.Cmu_),
116  kappa_(ptf.kappa_),
117  Pr_(ptf.Pr_.clone()),
118  Prt_(ptf.Prt_.clone(p.patch())),
119  z0_(ptf.z0_.clone(p.patch()))
120 {
121  checkType();
122 }
123 
124 
127 (
128  const fvPatch& p,
130  const dictionary& dict
131 )
132 :
133  parent_bctype(p, iF, dict),
134  Cmu_
135  (
136  dict.getCheckOrDefault<scalar>
137  (
138  "Cmu",
139  0.09,
140  scalarMinMax::ge(SMALL)
141  )
142  ),
143  kappa_
144  (
145  dict.getCheckOrDefault<scalar>
146  (
147  "kappa",
148  0.41,
149  scalarMinMax::ge(SMALL)
150  )
151  ),
152  Pr_(Function1<scalar>::New("Pr", dict, &db())),
153  Prt_(PatchFunction1<scalar>::New(p.patch(), "Prt", dict)),
154  z0_(PatchFunction1<scalar>::New(p.patch(), "z0", dict))
155 {
156  checkType();
157 }
158 
159 
162 (
163  const this_bctype& wfpsf,
165 )
166 :
167  parent_bctype(wfpsf, iF),
168  Cmu_(wfpsf.Cmu_),
169  kappa_(wfpsf.kappa_),
170  Pr_(wfpsf.Pr_.clone()),
171  Prt_(wfpsf.Prt_.clone(this->patch().patch())),
172  z0_(wfpsf.z0_.clone(this->patch().patch()))
173 {
174  checkType();
175 }
176 
177 
178 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
179 
181 {
182  if (updated())
183  {
184  return;
185  }
186 
187  const label patchi = patch().index();
188 
189  // Retrieve turbulence properties from model
190  const auto& turbModel = db().lookupObject<turbulenceModel>
191  (
193  (
195  internalField().group()
196  )
197  );
198 
199  const scalarField& y = turbModel.y()[patchi];
200 
201  const tmp<scalarField> tnuw = turbModel.nu(patchi);
202  const scalarField& nuw = tnuw();
203 
204  const tmp<volScalarField> tk = turbModel.k();
205  const volScalarField& k = tk();
206 
207  const scalar Cmu25 = pow025(Cmu_);
208 
209  const scalar t = db().time().timeOutputValue();
210  const scalar Pr = Pr_->value(t);
211 
212  #ifdef FULLDEBUG
213  if (Pr < VSMALL)
214  {
216  << "Pr cannot be negative or zero. "
217  << "Please check input Pr = " << Pr
218  << exit(FatalError);
219  }
220  #endif
221 
222  const scalarField Prt(Prt_->value(t));
223  const scalarField z0(z0_->value(t));
224 
225  #ifdef FULLDEBUG
226  forAll(Prt, i)
227  {
228  if (Prt[i] < VSMALL || z0[i] < VSMALL)
229  {
231  << "Elements of input surface fields can only be positive. "
232  << "Please check input fields z0 and Prt."
233  << exit(FatalError);
234  }
235  }
236  #endif
237 
238  const labelUList& faceCells = patch().faceCells();
239 
240  scalarField& alphatw = *this;
241 
242  forAll(alphatw, facei)
243  {
244  const label celli = faceCells[facei];
245 
246  const scalar uStar = Cmu25*Foam::sqrt(k[celli]);
247  const scalar Edash = (y[facei] + z0[facei])/(z0[facei] + 1e-4);
248 
249  // Update turbulent thermal conductivity
250  alphatw[facei] =
251  uStar*kappa_*y[facei]/(Prt[facei]*log(max(Edash, 1 + 1e-4)))
252  + nuw[facei]/Pr;
253  }
254 
255  // lower bound values to avoid unrealistic
256  // negative temperatures on the ground
257  alphatw = max(alphatw, scalar(0.01));
258 
260 }
261 
262 
264 (
265  const fvPatchFieldMapper& m
266 )
267 {
268  this->parent_bctype::autoMap(m);
269 
270  if (Prt_)
271  {
272  Prt_->autoMap(m);
273  }
274  if (z0_)
275  {
276  z0_->autoMap(m);
277  }
278 }
279 
280 
282 (
283  const fvPatchScalarField& ptf,
284  const labelList& addr
285 )
286 {
287  this->parent_bctype::rmap(ptf, addr);
288 
289  const auto& nrwfpsf = refCast<const this_bctype>(ptf);
290 
291  if (Prt_ && nrwfpsf.Prt_)
292  {
293  Prt_->rmap(nrwfpsf.Prt_(), addr);
294  }
295  if (z0_ && nrwfpsf.z0_)
296  {
297  z0_->rmap(nrwfpsf.z0_(), addr);
298  }
299 }
300 
301 
303 {
305  writeLocalEntries(os);
307 }
308 
309 
310 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
311 
313 (
315  atmAlphatkWallFunctionFvPatchScalarField
316 );
317 
318 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
319 
320 } // End namespace Foam
321 
322 // ************************************************************************* //
dimensionedScalar Pr("Pr", dimless, laminarTransport)
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
dictionary dict
dimensionedScalar log(const dimensionedScalar &ds)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
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
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
virtual void write(Ostream &) const
Write.
autoPtr< PatchFunction1< scalar > > Prt_
Turbulent Prandtl number field.
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
dimensionedScalar pow025(const dimensionedScalar &ds)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
void writeValueEntry(Ostream &os) const
Write *this field as a "value" entry.
Definition: fvPatchField.H:425
label k
Boltzmann constant.
Macros for easy insertion into run-time selection tables.
UList< label > labelUList
A UList of labels.
Definition: UList.H:76
autoPtr< PatchFunction1< scalar > > z0_
Surface roughness length [m].
atmAlphatkWallFunctionFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:400
constexpr const char *const group
Group name for atomic constants.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:72
scalar y
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
fvPatchField< scalar > fvPatchScalarField
static const word propertiesName
Default name of the turbulence properties dictionary.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
A FieldMapper for finite-volume patch fields.
virtual void rmap(const fvPatchScalarField &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
errorManip< error > abort(error &err)
Definition: errorManip.H:139
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
dimensionedScalar Prt("Prt", dimless, laminarTransport)
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.
List< label > labelList
A List of labels.
Definition: List.H:61
volScalarField & p
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
autoPtr< Function1< scalar > > Pr_
Molecular Prandtl number.
Namespace for OpenFOAM.
void writeLocalEntries(Ostream &) const
Write local wall function variables.