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-2020 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 dictionary& dict
35 )
36 :
37  FieldFunction1<Type, UniformTable<Type>>(name),
38  dictName_(dict.name()),
39  low_(dict.lookup<scalar>("low")),
40  high_(dict.lookup<scalar>("high")),
41  values_(dict.lookup("values"))
42 {
43  if (values_.size() < 2)
44  {
46  << "Table " << nl
47  << " " << dictName_ << nl
48  << " has less than 2 entries."
49  << exit(FatalError);
50  }
51  else
52  {
53  delta_ = (high_ - low_)/(values_.size() - 1);
54  }
55 }
56 
57 
58 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
59 
60 template<class Type>
62 {
63  const scalar nd = (x - low_)/delta_;
64  const label i = nd;
65 
66  if (nd < 0 || i > values_.size() - 2)
67  {
69  << x << " out of range "
70  << low_ << " to " << high_ << nl
71  << " of table " << dictName_
72  << exit(FatalError);
73  }
74 
75  const scalar xi = low_ + i*delta_;
76  const scalar lambda = (x - xi)/delta_;
77 
78  return values_[i] + lambda*(values_[i + 1] - values_[i]);
79 }
80 
81 
82 template<class Type>
84 (
85  const scalar x1,
86  const scalar x2
87 ) const
88 {
90  return Zero;
91 }
92 
93 
94 template<class Type>
96 {
97  writeEntry(os, "low", low_);
98  writeEntry(os, "high", high_);
99  writeEntry(os, "values", values_);
100 }
101 
102 
103 // ************************************************************************* //
Tabulated property function that linearly interpolates between the UniformTable values.
Definition: UniformTable1.H:90
UniformTable(const word &name, 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:84
void write(Ostream &os) const
Write the function coefficients.
Definition: UniformTable1.C:95
virtual Type value(scalar x) const
Evaluate the function and return the result.
Definition: UniformTable1.C:61
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:160
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:353
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
dimensionedScalar lambda(viscosity->lookup("lambda"))
void writeEntry(Ostream &os, const omega &a)
Definition: omega.C:85
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
error FatalError
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
static const char nl
Definition: Ostream.H:260
dictionary dict