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-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 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  Usage:
78  \verbatim
79  <name>
80  {
81  type table;
82  file "<file path>"; // Name/path of thedata file
83  format foam; // data format (optional)
84  outOfBounds clamp; // optional out-of-bounds handling
85  interpolationScheme linear; // optional interpolation method
86  }
87  \endverbatim
88 
89 SourceFiles
90  Table.C
91 
92 See also
93  FoamTableReader.C
94  CsvTableReader.C
95 
96 \*---------------------------------------------------------------------------*/
97 
98 #ifndef Table_H
99 #define Table_H
100 
101 #include "tableBase.H"
102 #include "Function1.H"
103 #include "TableReader.H"
104 
105 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
106 
107 namespace Foam
108 {
109 
110 class interpolationWeights;
111 
112 namespace Function1s
113 {
114 
115 /*---------------------------------------------------------------------------*\
116  Class Table Declaration
117 \*---------------------------------------------------------------------------*/
118 
119 template<class Type>
120 class Table
121 :
122  public tableBase,
123  public FieldFunction1<Type, Table<Type>>
124 {
125  // Private Data
126 
127  //- Enumeration for handling out-of-bound values
128  const tableBase::boundsHandling boundsHandling_;
129 
130  //- Interpolation type
131  const word interpolationScheme_;
132 
133  //- Table data
134  List<Tuple2<scalar, Type>> values_;
135 
136  //- Extracted values
137  mutable autoPtr<scalarField> tableSamplesPtr_;
138 
139  //- Interpolator method
140  mutable autoPtr<interpolationWeights> interpolatorPtr_;
141 
142  //- Cached indices
143  mutable labelList indices_;
144 
145  //- Cached weights
146  mutable scalarField weights_;
147 
148  //- Table reader
149  const autoPtr<TableReader<Type>> reader_;
150 
151 
152  // Private Member Functions
153 
154  //- Return (demand driven) interpolator
155  const interpolationWeights& interpolator() const;
156 
157  //- Check the table for size and consistency
158  void check() const;
159 
160  //- Bound the argument to the table. Errors or warns, or shifts the
161  // value if the table repeats. Does not clamp to the ends of the table
162  // as the interpolator already performs that function.
163  scalar bound(const scalar x) const;
164 
165 
166 public:
167 
168  //- Runtime type information
169  TypeName("table");
170 
171 
172  // Constructors
173 
174  //- Construct from components
175  Table
176  (
177  const word& name,
179  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 Table value as a function of scalar x
197  virtual Type value(const scalar x) const;
198 
199  //- Integrate between two scalars
200  virtual Type integral(const scalar x1, const scalar x2) const;
201 
202  //- Return the reference values
203  virtual tmp<scalarField> x() const;
204 
205  //- Return the dependent values
206  virtual tmp<Field<Type>> y() const;
207 
208  //- Write data to dictionary stream
209  virtual void write(Ostream& os) const;
210 
211 
212  // Member Operators
213 
214  //- Disallow default bitwise assignment
215  void operator=(const Table<Type>&) = delete;
216 };
217 
218 
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 
221 } // End namespace Function1s
222 } // End namespace Foam
223 
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 
226 #ifdef NoRepository
227  #include "Table.C"
228 #endif
229 
230 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231 
232 #endif
233 
234 // ************************************************************************* //
const word const dictionary & dict
Definition: Function1.H:84
TypeName("table")
Runtime type information.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
const word & name() const
Return the name of the entry.
A 2-tuple for storing two objects of different types.
Definition: HashTable.H:65
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
virtual Type value(const scalar x) const
Return Table value as a function of scalar x.
Definition: Table.C:204
Table(const word &name, const tableBase::boundsHandling boundsHandling, const word &interpolationScheme, const List< Tuple2< scalar, Type >> &table)
Construct from components.
Definition: Table.C:137
Abstract base class for interpolating in 1D.
Templated interpolated tabulated data Function1.
Definition: Table.H:119
virtual void write(Ostream &os) const
Write data to dictionary stream.
Definition: Table.C:297
A class for handling words, derived from string.
Definition: word.H:59
virtual ~Table()
Destructor.
Definition: Table.C:196
virtual Type integral(const scalar x1, const scalar x2) const
Integrate between two scalars.
Definition: Table.C:224
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
boundsHandling
Enumeration for handling out-of-bound values.
Definition: tableBase.H:54
virtual tmp< Field< Type > > y() const
Return the dependent values.
Definition: Table.C:282
void operator=(const Table< Type > &)=delete
Disallow default bitwise assignment.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
A class for managing temporary objects.
Definition: PtrList.H:53
virtual tmp< scalarField > x() const
Return the reference values.
Definition: Table.C:266
Namespace for OpenFOAM.