Table.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) 2011-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::Table
26 
27 Description
28  Templated interpolated tabulated data Function1.
29 
30  Items are stored in a list of Tuple2's. First column is always stored as
31  scalar entries. Data is read in Tuple2 form:
32 
33 Usage
34  \verbatim
35  <name> table
36  (
37  (0.0 (1 2 3))
38  (1.0 (4 5 6))
39  );
40  \endverbatim
41 
42  or in dictionary form which supports the setting of options, e.g.
43  \verbatim
44  <name> table;
45 
46  values
47  (
48  (0.0 (1 2 3))
49  (1.0 (4 5 6))
50  );
51 
52  outOfBounds clamp; // optional out-of-bounds handling
53  interpolationScheme linear; // optional interpolation method
54  \endverbatim
55 
56  or in sub-dictionary form which avoids clashes between table entries and
57  other entries in the dictionary:
58 
59  \verbatim
60  <name>
61  {
62  type table;
63 
64  values
65  (
66  (0.0 (1 2 3))
67  (1.0 (4 5 6))
68  );
69 
70  outOfBounds clamp; // optional out-of-bounds handling
71  interpolationScheme linear; // optional interpolation method
72  }
73  \endverbatim
74 
75  The data may be read from a separate file in either native or CSV format:
76 
77  \verbatim
78  <name>
79  {
80  type table;
81  file "<file path>"; // Name/path of thedata file
82  format foam; // data format (optional)
83  outOfBounds clamp; // optional out-of-bounds handling
84  interpolationScheme linear; // optional interpolation method
85  }
86  \endverbatim
87 
88 SourceFiles
89  Table.C
90 
91 See also
92  FoamTableReader.C
93  CsvTableReader.C
94 
95 \*---------------------------------------------------------------------------*/
96 
97 #ifndef Table_H
98 #define Table_H
99 
100 #include "tableBase.H"
101 #include "Function1.H"
102 #include "TableReader.H"
103 
104 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
105 
106 namespace Foam
107 {
108 
109 class interpolationWeights;
110 
111 namespace Function1s
112 {
113 
114 /*---------------------------------------------------------------------------*\
115  Class Table Declaration
116 \*---------------------------------------------------------------------------*/
117 
118 template<class Type>
119 class Table
120 :
121  public tableBase,
122  public FieldFunction1<Type, Table<Type>>
123 {
124  // Private Data
125 
126  //- Enumeration for handling out-of-bound values
127  const tableBase::boundsHandling boundsHandling_;
128 
129  //- Interpolation scheme
130  const word interpolationScheme_;
131 
132  //- Table reader
133  const autoPtr<TableReader<Type>> reader_;
134 
135  //- Table data
136  const List<Tuple2<scalar, Type>> values_;
137 
138  //- Extracted values
139  mutable autoPtr<scalarField> tableSamplesPtr_;
140 
141  //- Interpolator method
142  mutable autoPtr<interpolationWeights> interpolatorPtr_;
143 
144  //- Cached indices
145  mutable labelList indices_;
146 
147  //- Cached weights
148  mutable scalarField weights_;
149 
150 
151  // Private Member Functions
152 
153  //- Return (demand driven) interpolator
154  const interpolationWeights& interpolator() const;
155 
156  //- Check the table for size and consistency
157  void check() const;
158 
159  //- Check the validity of a given argument value
160  void checkX(const scalar x) const;
161 
162 
163 public:
164 
165  //- Runtime type information
166  TypeName("table");
167 
168 
169  // Constructors
170 
171  //- Construct from components
172  Table
173  (
174  const word& name,
176  const word& interpolationScheme,
177  const autoPtr<TableReader<Type>>& reader,
178  const List<Tuple2<scalar, Type>>& table
179  );
180 
181  //- Construct from name and dictionary
182  Table
183  (
184  const word& name,
185  const unitConversions& units,
186  const dictionary& dict
187  );
188 
189  //- Construct from name and dictionary
190  Table
191  (
192  const word& name,
193  const unitConversion& xUnits,
194  const unitConversion& valueUnits,
195  const dictionary& dict
196  );
197 
198  //- Construct from name and Istream
199  Table
200  (
201  const word& name,
202  const unitConversions& units,
203  Istream& dict
204  );
205 
206  //- Copy constructor
207  Table(const Table<Type>& tbl);
208 
209 
210  //- Destructor
211  virtual ~Table();
212 
213 
214  // Member Functions
215 
216  //- Return the handling out-of-bound values
218  {
219  return boundsHandling_;
220  }
221 
222  //- Return the interpolation scheme
223  const word& interpolationScheme() const
224  {
225  return interpolationScheme_;
226  }
227 
228  //- Return table data
229  const List<Tuple2<scalar, Type>>& values() const
230  {
231  return values_;
232  }
233 
234  //- Return Table value as a function of scalar x
235  virtual Type value(const scalar x) const;
236 
237  //- Integrate between two scalars
238  virtual Type integral(const scalar xA, const scalar xB) const;
239 
240  //- Return the reference values
241  virtual tmp<scalarField> x() const;
242 
243  //- Return the dependent values
244  virtual tmp<Field<Type>> y() const;
245 
246  //- Write data to dictionary stream
247  virtual void write(Ostream& os, const unitConversions& units) const;
248 
249 
250  // Member Operators
251 
252  //- Disallow default bitwise assignment
253  void operator=(const Table<Type>&) = delete;
254 };
255 
256 
257 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
258 
259 } // End namespace Function1s
260 } // End namespace Foam
261 
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 
264 #ifdef NoRepository
265  #include "Table.C"
266 #endif
267 
268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
269 
270 #endif
271 
272 // ************************************************************************* //
const word & name() const
Return the name of the entry.
Definition: Function1.C:78
Templated interpolated tabulated data Function1.
Definition: Table.H:122
TypeName("table")
Runtime type information.
const tableBase::boundsHandling & boundsHandling() const
Return the handling out-of-bound values.
Definition: Table.H:216
virtual Type integral(const scalar xA, const scalar xB) const
Integrate between two scalars.
Definition: Table.C:280
const word & interpolationScheme() const
Return the interpolation scheme.
Definition: Table.H:222
virtual tmp< scalarField > x() const
Return the reference values.
Definition: Table.C:346
Table(const word &name, const tableBase::boundsHandling boundsHandling, const word &interpolationScheme, const autoPtr< TableReader< Type >> &reader, const List< Tuple2< scalar, Type >> &table)
Construct from components.
Definition: Table.C:124
virtual void write(Ostream &os, const unitConversions &units) const
Write data to dictionary stream.
Definition: Table.C:378
void operator=(const Table< Type > &)=delete
Disallow default bitwise assignment.
const List< Tuple2< scalar, Type > > & values() const
Return table data.
Definition: Table.H:228
virtual tmp< Field< Type > > y() const
Return the dependent values.
Definition: Table.C:362
virtual Type value(const scalar x) const
Return Table value as a function of scalar x.
Definition: Table.C:225
virtual ~Table()
Destructor.
Definition: Table.C:217
boundsHandling
Enumeration for handling out-of-bound values.
Definition: tableBase.H:55
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
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
Base class to read table data for tables.
Definition: TableReader.H:51
A 2-tuple for storing two objects of different types.
Definition: Tuple2.H:66
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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Abstract base class for interpolating in 1D.
A class for managing temporary objects.
Definition: tmp.H:55
Unit conversion structure. Contains the associated dimensions and the multiplier with which to conver...
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
const HashTable< unitConversion > & units()
Get the table of unit conversions.
dictionary dict