interpolationTable.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::interpolationTable
29 
30 Description
31  An interpolation/look-up table of scalar vs <Type> values.
32  The reference scalar values must be monotonically increasing.
33 
34  The handling of out-of-bounds values depends on the current setting
35  of \c outOfBounds.
36 
37  If \c repeat is chosen for the out-of-bounds handling, the final time
38  value is treated as being equivalent to time=0 for the following periods.
39 
40  The construct from dictionary reads a filename from a dictionary and
41  has an optional readerType. Default is to read OpenFOAM format. The only
42  other format is csv (comma separated values):
43 
44  Read csv format:
45  \verbatim
46  readerType csv;
47  file "<constant>/p0vsTime.csv";
48  hasHeaderLine true; // skip first line
49  timeColumn 0; // time is in column 0
50  valueColumns (1); // value starts in column 1
51  \endverbatim
52 
53 
54 Note
55  - Accessing an empty list results in an error.
56  - Accessing a list with a single element always returns the same value.
57 
58 SourceFiles
59  interpolationTable.C
60 
61 \*---------------------------------------------------------------------------*/
62 
63 #ifndef interpolationTable_H
64 #define interpolationTable_H
65 
66 #include "List.H"
67 #include "Tuple2.H"
68 #include "tableBounds.H"
69 #include "tableReader.H"
70 #include "autoPtr.H"
71 #include "Field.H"
72 
73 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
74 
75 namespace Foam
76 {
77 
78 /*---------------------------------------------------------------------------*\
79  Class interpolationTable Declaration
80 \*---------------------------------------------------------------------------*/
81 
82 template<class Type>
84 :
85  public List<Tuple2<scalar, Type>>
86 {
87  // Private Data
88 
89  //- Handling for out-of-bound values
91 
92  //- File name
93  fileName fileName_;
94 
95  //- The actual reader
97 
98 
99  // Private Member Functions
100 
101  //- Read the table of data from file
102  void readTable();
103 
104 
105 public:
106 
107  // Public Data Types
108 
109  //- The element data type
111 
112  //- The mapped data type
113  typedef Type mapped_type;
114 
115 
116  // Constructors
117 
118  //- Construct null
120 
121  //- Construct from components
123  (
125  const bounds::repeatableBounding bounding,
126  const fileName& fName
127  );
128 
129  //- Construct given the name of the file containing the table of data
130  explicit interpolationTable(const fileName& fName);
131 
132  //- Construct by reading file name and outOfBounds from dictionary
133  //- and read the table from that file.
134  // This is a specialised constructor used by patchFields
135  explicit interpolationTable(const dictionary& dict);
136 
137  //- Copy construct
138  interpolationTable(const interpolationTable& interpTable);
139 
140 
141  // Member Functions
142 
143  //- Return an interpolated value in List
144  static Type interpolateValue
145  (
146  const List<Tuple2<scalar, Type>>& list,
147  scalar lookupValue,
149  );
150 
151 
152  //- Check that list is monotonically increasing
153  // Exit with a FatalError if there is a problem
154  void check() const;
155 
156  //- Write
157  void write(Ostream& os) const;
158 
159  //- Return the rate of change at the interpolation location
160  //- for the given lookup value
161  Type rateOfChange(scalar lookupValue) const;
162 
163  //- Return an interpolated value
164  Type interpolateValue(scalar lookupValue) const;
165 
166  //- Return multiple interpolated values
168  (
169  const UList<scalar>& vals
170  ) const;
171 
172 
173  // Member Operators
174 
175  //- Return an element of constant Tuple2<scalar, Type>
176  const Tuple2<scalar, Type>& operator[](label idx) const;
177 
178  //- Return an interpolated value
179  Type operator()(scalar lookupValue) const;
180 };
181 
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 } // End namespace Foam
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 #ifdef NoRepository
190  #include "interpolationTable.C"
191 #endif
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 #endif
196 
197 // ************************************************************************* //
List.H
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Tuple2.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
interpolationTable.C
Foam::interpolationTable::interpolateValues
tmp< Field< Type > > interpolateValues(const UList< scalar > &vals) const
Return multiple interpolated values.
Definition: interpolationTable.C:476
Foam::bounds::repeatableBounding
repeatableBounding
Enumeration for handling out-of-bound values that are repeatable.
Definition: tableBounds.H:61
Foam::interpolationTable::operator()
Type operator()(scalar lookupValue) const
Return an interpolated value.
Definition: interpolationTable.C:592
Foam::interpolationTable::write
void write(Ostream &os) const
Write.
Definition: interpolationTable.C:161
Foam::label
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:62
Field.H
Foam::interpolationTable::interpolationTable
interpolationTable()
Construct null.
Definition: interpolationTable.C:61
Foam::interpolationTable::value_type
Tuple2< scalar, Type > value_type
The element data type.
Definition: interpolationTable.H:109
Foam::interpolationTable::mapped_type
Type mapped_type
The mapped data type.
Definition: interpolationTable.H:112
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::bounds::normalBounding::CLAMP
Clamp value to the start/end value.
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::interpolationTable::interpolateValue
static Type interpolateValue(const List< Tuple2< scalar, Type >> &list, scalar lookupValue, bounds::repeatableBounding=bounds::repeatableBounding::CLAMP)
Return an interpolated value in List.
Definition: interpolationTable.C:312
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
tableBounds.H
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::interpolationTable::check
void check() const
Check that list is monotonically increasing.
Definition: interpolationTable.C:135
Foam::interpolationTable::rateOfChange
Type rateOfChange(scalar lookupValue) const
Definition: interpolationTable.C:173
Foam::interpolationTable
An interpolation/look-up table of scalar vs <Type> values. The reference scalar values must be monoto...
Definition: interpolationTable.H:82
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Tuple2
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: Tuple2.H:57
Foam::interpolationTable::operator[]
const Tuple2< scalar, Type > & operator[](label idx) const
Return an element of constant Tuple2<scalar, Type>
Definition: interpolationTable.C:496
tableReader.H
autoPtr.H