general.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) 2020 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 
29 #include "general.H"
31 #include "Tuple2.H"
32 #include "Switch.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  namespace tabulatedWallFunctions
39  {
42  (
43  tabulatedWallFunction,
44  general,
45  dictionary
46  );
47  }
48 }
49 
50 const Foam::Enum
51 <
53 >
55 ({
56  { interpolationType::itLinear, "linear" },
57 });
58 
59 
60 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
61 
63 {
64  scalarList Rey(uPlus_.size(), Zero);
65 
66  // Calculate Reynolds number
67  forAll(uPlus_, i)
68  {
69  Rey[i] = yPlus_[i]*uPlus_[i];
70  if (invertedTable_.log10())
71  {
72  Rey[i] = ::log10(max(ROOTVSMALL, Rey[i]));
73  }
74  }
75 
76  // Populate the U+ vs Re table
78  {
79  scalar Re = i*invertedTable_.dx() + invertedTable_.x0();
81  }
82 }
83 
84 
86 (
87  const scalar xi,
88  const scalarList& x,
89  const scalarList& fx
90 ) const
91 {
92  switch (interpType_)
93  {
94  case itLinear:
95  {
96  if (xi <= x[0])
97  {
98  return fx[0];
99  }
100  else if (xi >= x.last())
101  {
102  return fx.last();
103  }
104  else
105  {
106  label i2 = 0;
107  while (x[i2] < xi)
108  {
109  i2++;
110  }
111  label i1 = i2 - 1;
112 
113  return (xi - x[i1])/(x[i2] - x[i1])*(fx[i2] - fx[i1]) + fx[i1];
114  }
115 
116  break;
117  }
118  default:
119  {
121  << "Unknown interpolation method" << nl
122  << abort(FatalError);
123  }
124  }
125 
126  return 0.0;
127 }
128 
129 
130 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
131 
133 (
134  const dictionary& dict,
135  const polyMesh& mesh
136 )
137 :
138  tabulatedWallFunction(dict, mesh, typeName),
139  interpType_(interpolationTypeNames_.get("interpType", coeffDict_)),
140  log10YPlus_(coeffDict_.get<bool>("log10YPlus")),
141  log10UPlus_(coeffDict_.get<bool>("log10UPlus")),
142  yPlus_(),
143  uPlus_()
144 {
145  List<Tuple2<scalar, scalar>> inputTable;
146 
147  coeffDict_.readEntry("inputTable", inputTable);
148 
149  if (inputTable.size() < 2)
150  {
152  << "Input table must have at least 2 values" << nl
153  << exit(FatalError);
154  }
155 
156  yPlus_.setSize(inputTable.size());
157  uPlus_.setSize(inputTable.size());
158 
159  forAll(inputTable, i)
160  {
161  if (log10YPlus_)
162  {
163  yPlus_[i] = pow(10, inputTable[i].first());
164  }
165  else
166  {
167  yPlus_[i] = inputTable[i].first();
168  }
169 
170  if (log10UPlus_)
171  {
172  uPlus_[i] = pow(10, inputTable[i].second());
173  }
174  else
175  {
176  uPlus_[i] = inputTable[i].second();
177  }
178  }
179 
180  invertTable();
181 
182  if (debug)
183  {
184  writeData(Info);
185  }
186 }
187 
188 
189 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
190 
192 {}
193 
194 
195 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
196 
198 (
199  const scalar uPlus
200 ) const
201 {
202  return interpolate(uPlus, uPlus_, yPlus_);
203 }
204 
205 
207 (
208  const scalar uPlus
209 ) const
210 {
211  return uPlus*yPlus(uPlus);
212 }
213 
214 
215 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
216 
218 {
219  if (invertedTable_.log10())
220  {
221  os << "log10(Re), y+, u+:" << endl;
222  forAll(invertedTable_, i)
223  {
224  scalar uPlus = invertedTable_[i];
225  scalar Re = ::log10(this->Re(uPlus));
226  scalar yPlus = this->yPlus(uPlus);
227  os << Re << ", " << yPlus << ", " << uPlus << endl;
228  }
229  }
230  else
231  {
232  os << "Re, y+, u+:" << endl;
233  forAll(invertedTable_, i)
234  {
235  scalar uPlus = invertedTable_[i];
236  scalar Re = this->Re(uPlus);
237  scalar yPlus = this->yPlus(uPlus);
238  os << Re << ", " << yPlus << ", " << uPlus << endl;
239  }
240  }
241 }
242 
243 
244 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::scalarList
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:61
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:53
Foam::uniformInterpolationTable::log10
const Switch & log10() const
Definition: uniformInterpolationTableI.H:36
Tuple2.H
Foam::tabulatedWallFunctions::general::yPlus_
List< scalar > yPlus_
Definition: general.H:108
Foam::Zero
static constexpr const zero Zero
Definition: zero.H:131
Foam::uniformInterpolationTable::x0
scalar x0() const
Definition: uniformInterpolationTableI.H:22
uPlus
scalar uPlus
Definition: evaluateNearWall.H:18
Foam::endl
Ostream & endl(Ostream &os)
Definition: Ostream.H:381
Foam::tabulatedWallFunctions::general::~general
virtual ~general()
forAll
#define forAll(list, i)
Definition: stdFoam.H:349
Foam::tabulatedWallFunctions::general::general
general(const dictionary &dict, const polyMesh &mesh)
Foam::uniformInterpolationTable::dx
scalar dx() const
Definition: uniformInterpolationTableI.H:29
Foam::interpolate
bool interpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
Definition: curveTools.C:75
Foam::tabulatedWallFunctions::general::interpolationType
interpolationType
Definition: general.H:86
general
General relative velocity model.
Foam::Info
messageStream Info
Foam::tabulatedWallFunctions::general::invertTable
virtual void invertTable()
Foam::log10
dimensionedScalar log10(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:256
Switch.H
Foam::pow
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Definition: dimensionedScalar.C:68
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Definition: hashSets.C:40
Foam::tabulatedWallFunctions::general::writeData
virtual void writeData(Ostream &os) const
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::writeData
static void writeData(Ostream &os, const Type &val)
Definition: rawSurfaceWriterImpl.C:38
Foam::FatalError
error FatalError
Foam::tabulatedWallFunctions::general::uPlus_
List< scalar > uPlus_
Definition: general.H:111
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::tabulatedWallFunctions::general::yPlus
virtual scalar yPlus(const scalar uPlus) const
Foam::tabulatedWallFunctions::general::interpolate
virtual scalar interpolate(const scalar xi, const scalarList &x, const scalarList &fx) const
Foam
Definition: atmBoundaryLayer.C:26
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:139
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
Foam::tabulatedWallFunctions::general::interpolationTypeNames_
static const Enum< interpolationType > interpolationTypeNames_
Definition: general.H:91
FatalErrorInFunction
#define FatalErrorInFunction
Definition: error.H:465
Foam::nl
constexpr char nl
Definition: Ostream.H:424
Foam::Re
scalarField Re(const UList< complex > &cf)
Definition: complexField.C:152
bool
bool
Definition: EEqn.H:20
x
x
Definition: LISASMDCalcMethod2.H:52
Rey
scalar Rey
Definition: evaluateNearWall.H:28
Foam::PtrListOps::get
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
yPlus
scalar yPlus
Definition: evaluateNearWall.H:16
Foam::tabulatedWallFunctions::general::Re
virtual scalar Re(const scalar uPlus) const
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::tabulatedWallFunctions::tabulatedWallFunction::invertedTable_
uniformInterpolationTable< scalar > invertedTable_
Definition: tabulatedWallFunction.H:71