NonUniformTable1.H
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) 2020-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 Class
25  Foam::Function1s::NonUniformTable
26 
27 Description
28  Non-uniform tabulated property function that linearly interpolates between
29  the values.
30 
31  To speed-up the search of the non-uniform table a uniform jump-table is
32  created on construction which is used for fast indirect addressing into
33  the table.
34 
35 Usage
36  \table
37  Property | Description
38  values | List of value pairs
39  \endtable
40 
41  Example for the density of water between 280 and 350K
42  \verbatim
43  rho
44  {
45  type nonUniformTable;
46 
47  values
48  (
49  (280 999.87)
50  (300 995.1)
51  (350 973.7)
52  );
53  }
54  \endverbatim
55 
56 \*---------------------------------------------------------------------------*/
57 
58 #ifndef NonUniformTable1_H
59 #define NonUniformTable1_H
60 
61 #include "Function1.H"
62 #include "Tuple2.H"
63 #include "TableReader.H"
64 
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 
67 namespace Foam
68 {
69 namespace Function1s
70 {
71 
72 /*---------------------------------------------------------------------------*\
73  Class NonUniformTable Declaration
74 \*---------------------------------------------------------------------------*/
75 
76 template<class Type>
77 class NonUniformTable
78 :
79  public FieldFunction1<Type, NonUniformTable<Type>>
80 {
81  // Private member data
82 
83  //- Lowest value in the NonUniformTable
84  scalar low_;
85 
86  //- Highest value in the NonUniformTable
87  scalar high_;
88 
89  //- Table values
91 
92  //- Increment derived from low_, high_ and values_.size()
93  scalar delta_;
94 
95  //- The jump table
96  List<label> jumpTable_;
97 
98  //- Table reader
100 
101 
102 protected:
103 
104  //- Return the lower index of the interval in the table
105  // corresponding to the given value
106  inline label index(scalar x) const;
107 
108 
109 public:
110 
111  //- Runtime type information
112  TypeName("nonUniformTable");
113 
114 
115  // Constructors
116 
117  //- Construct from name and dictionary
119  (
120  const word& name,
122  const dictionary& dict
123  );
124 
125  //- Copy constructor
127 
128 
129  // Member Functions
130 
131  //- Return the non-uniform table of values
132  const List<Tuple2<scalar, Type>>& values() const
133  {
134  return values_;
135  }
136 
137  //- Evaluate the function and return the result
138  virtual Type value(scalar x) const;
139 
140  //- Integrate between two scalar values
141  virtual Type integral(const scalar x1, const scalar x2) const;
142 
143  //- Evaluate the derivative of the function and return the result
144  Type dfdT(scalar T) const;
145 
146  //- Write the function coefficients
147  void write(Ostream& os, const unitConversions& units) const;
148 
149 
150  // Member Operators
151 
152  //- Assignment
153  void operator=(const NonUniformTable<Type>&);
154 };
155 
156 
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 
159 } // End namespace Function1s
160 } // End namespace Foam
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 #include "NonUniformTable1I.H"
165 
166 #ifdef NoRepository
167  #include "NonUniformTable1.C"
168 #endif
169 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 
172 #endif
173 
174 // ************************************************************************* //
const word & name() const
Return the name of the entry.
Definition: Function1.C:78
Non-uniform tabulated property function that linearly interpolates between the values.
NonUniformTable(const word &name, const Function1s::unitConversions &units, const dictionary &dict)
Construct from name and dictionary.
void operator=(const NonUniformTable< Type > &)
Assignment.
Type dfdT(scalar T) const
Evaluate the derivative of the function and return the result.
virtual Type integral(const scalar x1, const scalar x2) const
Integrate between two scalar values.
void write(Ostream &os, const unitConversions &units) const
Write the function coefficients.
label index(scalar x) const
Return the lower index of the interval in the table.
const List< Tuple2< scalar, Type > > & values() const
Return the non-uniform table of values.
virtual Type value(scalar x) const
Evaluate the function and return the result.
TypeName("nonUniformTable")
Runtime type information.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
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
const scalar nut
Namespace for OpenFOAM.
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
const HashTable< unitConversion > & units()
Get the table of unit conversions.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
dictionary dict