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-2022 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 data
133  List<Tuple2<scalar, Type>> values_;
134 
135  //- Extracted values
136  mutable autoPtr<scalarField> tableSamplesPtr_;
137 
138  //- Interpolator method
139  mutable autoPtr<interpolationWeights> interpolatorPtr_;
140 
141  //- Cached indices
142  mutable labelList indices_;
143 
144  //- Cached weights
145  mutable scalarField weights_;
146 
147  //- Table reader
148  const autoPtr<TableReader<Type>> reader_;
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  //- Bound the argument to the table. Errors or warns, or shifts the
160  // value if the table repeats. Does not clamp to the ends of the table
161  // as the interpolator already performs that function.
162  scalar bound(const scalar x) const;
163 
164 
165 public:
166 
167  //- Runtime type information
168  TypeName("table");
169 
170 
171  // Constructors
172 
173  //- Construct from components
174  Table
175  (
176  const word& name,
178  const word& interpolationScheme,
180  const List<Tuple2<scalar, Type>>& table
181  );
182 
183  //- Construct from name and dictionary
184  Table(const word& name, const dictionary& dict);
185 
186  //- Copy constructor
187  Table(const Table<Type>& tbl);
188 
189 
190  //- Destructor
191  virtual ~Table();
192 
193 
194  // Member Functions
195 
196  //- Return the handling out-of-bound values
198  {
199  return boundsHandling_;
200  }
201 
202  //- Return the interpolation scheme
203  const word& interpolationScheme() const
204  {
205  return interpolationScheme_;
206  }
207 
208  //- Return the reader
209  const autoPtr<TableReader<Type>>& reader() const
210  {
211  return reader_;
212  }
213 
214  //- Return table data
215  const List<Tuple2<scalar, Type>>& values() const
216  {
217  return values_;
218  }
219 
220  //- Return Table value as a function of scalar x
221  virtual Type value(const scalar x) const;
222 
223  //- Integrate between two scalars
224  virtual Type integral(const scalar x1, const scalar x2) const;
225 
226  //- Return the reference values
227  virtual tmp<scalarField> x() const;
228 
229  //- Return the dependent values
230  virtual tmp<Field<Type>> y() const;
231 
232  //- Write data to dictionary stream
233  virtual void write(Ostream& os) const;
234 
235 
236  // Member Operators
237 
238  //- Disallow default bitwise assignment
239  void operator=(const Table<Type>&) = delete;
240 };
241 
242 
243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 
245 } // End namespace Function1s
246 } // End namespace Foam
247 
248 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
249 
250 #ifdef NoRepository
251  #include "Table.C"
252 #endif
253 
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 
256 #endif
257 
258 // ************************************************************************* //
const word & name() const
Return the name of the entry.
Definition: Function1.C:82
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:196
const word & interpolationScheme() const
Return the interpolation scheme.
Definition: Table.H:202
virtual tmp< scalarField > x() const
Return the reference values.
Definition: Table.C:268
virtual Type integral(const scalar x1, const scalar x2) const
Integrate between two scalars.
Definition: Table.C:226
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:137
virtual void write(Ostream &os) const
Write data to dictionary stream.
Definition: Table.C:299
void operator=(const Table< Type > &)=delete
Disallow default bitwise assignment.
const List< Tuple2< scalar, Type > > & values() const
Return table data.
Definition: Table.H:214
virtual tmp< Field< Type > > y() const
Return the dependent values.
Definition: Table.C:284
const autoPtr< TableReader< Type > > & reader() const
Return the reader.
Definition: Table.H:208
virtual Type value(const scalar x) const
Return Table value as a function of scalar x.
Definition: Table.C:206
virtual ~Table()
Destructor.
Definition: Table.C:198
boundsHandling
Enumeration for handling out-of-bound values.
Definition: tableBase.H:55
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:63
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:160
Abstract base class for interpolating in 1D.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
dictionary dict