UniformTable1.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2019-2024 OpenFOAM Foundation
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 
26 #include "UniformTable1.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 (
33  const word& name,
34  const unitConversions& units,
35  const dictionary& dict
36 )
37 :
38  FieldFunction1<Type, UniformTable<Type>>(name),
39  dictName_(dict.name()),
40  low_(dict.lookup<scalar>("low")),
41  high_(dict.lookup<scalar>("high")),
42  values_(dict.lookup("values"))
43 {
44  assertNoConvertUnits(typeName, units, dict);
45 
46  if (values_.size() < 2)
47  {
49  << "Table " << nl
50  << " " << dictName_ << nl
51  << " has less than 2 entries."
52  << exit(FatalIOError);
53  }
54  else
55  {
56  delta_ = (high_ - low_)/(values_.size() - 1);
57  }
58 }
59 
60 
61 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
62 
63 template<class Type>
65 {
66  const scalar nd = (x - low_)/delta_;
67  const label i = nd;
68 
69  if (nd < 0 || i > values_.size() - 2)
70  {
72  << x << " out of range "
73  << low_ << " to " << high_ << nl
74  << " of table " << dictName_
75  << exit(FatalError);
76  }
77 
78  const scalar xi = low_ + i*delta_;
79  const scalar lambda = (x - xi)/delta_;
80 
81  return values_[i] + lambda*(values_[i + 1] - values_[i]);
82 }
83 
84 
85 template<class Type>
87 (
88  const scalar x1,
89  const scalar x2
90 ) const
91 {
93  return Zero;
94 }
95 
96 
97 template<class Type>
99 (
100  Ostream& os,
101  const unitConversions& units
102 ) const
103 {
104  writeEntry(os, "low", low_);
105  writeEntry(os, "high", high_);
106  writeEntry(os, "values", values_);
107 }
108 
109 
110 // ************************************************************************* //
Tabulated property function that linearly interpolates between the UniformTable values.
Definition: UniformTable1.H:90
UniformTable(const word &name, const unitConversions &units, const dictionary &dict)
Construct from name and dictionary.
Definition: UniformTable1.C:32
virtual Type integral(const scalar x1, const scalar x2) const
Integrate between two scalar values.
Definition: UniformTable1.C:87
void write(Ostream &os, const unitConversions &units) const
Write the function coefficients.
Definition: UniformTable1.C:99
virtual Type value(scalar x) const
Evaluate the function and return the result.
Definition: UniformTable1.C:64
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
A class for handling words, derived from string.
Definition: word.H:62
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:381
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
dimensionedScalar lambda(viscosity->lookup("lambda"))
void writeEntry(Ostream &os, const omega &a)
Definition: omega1.C:97
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static const zero Zero
Definition: zero.H:97
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
const HashTable< unitConversion > & units()
Get the table of unit conversions.
IOerror FatalIOError
error FatalError
void assertNoConvertUnits(const word &typeName, const Function1s::unitConversions &units, const dictionary &dict)
Generate an error in an context where unit conversions are not supported.
static const char nl
Definition: Ostream.H:266
dictionary dict