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-2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::interpolationTable
29
30Description
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 refColumn 0; // reference (eg, time) is in column 0
50 componentColumns (1); // component values starts in column 1
51 \endverbatim
52
53Note
54 - Accessing an empty list results in an error.
55 - Accessing a list with a single element always returns the same value.
56
57SourceFiles
58 interpolationTable.C
59
60\*---------------------------------------------------------------------------*/
61
62#ifndef interpolationTable_H
63#define interpolationTable_H
64
65#include "List.H"
66#include "Tuple2.H"
67#include "tableBounds.H"
68#include "tableReader.H"
69#include "autoPtr.H"
70#include "Field.H"
71
72// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
73
74namespace Foam
75{
76
77/*---------------------------------------------------------------------------*\
78 Class interpolationTable Declaration
79\*---------------------------------------------------------------------------*/
80
81template<class Type>
83:
84 public List<Tuple2<scalar, Type>>
85{
86 // Private Data
87
88 //- Handling for out-of-bound values
90
91 //- File name
92 fileName fileName_;
93
94 //- Table reader
96
97
98 // Private Member Functions
99
100 //- Read the table of data from file
101 void readTable();
102
103
104public:
105
106 // Public Data Types
107
108 //- The element data type
110
111 //- The mapped data type
112 typedef Type mapped_type;
113
114
115 // Constructors
116
117 //- Default construct
119
120 //- Construct from components
122 (
123 const List<Tuple2<scalar, Type>>& values,
124 const bounds::repeatableBounding bounding,
125 const fileName& fName
126 );
127
128 //- Construct given the name of the file containing the table of data
129 explicit interpolationTable(const fileName& fName);
130
131 //- Construct by reading file name and outOfBounds from dictionary
132 //- and read the table from that file.
133 // This is a specialised constructor used by patchFields
134 explicit interpolationTable(const dictionary& dict);
135
136 //- Copy construct
138
139
140 // Member Functions
141
142 //- Return an interpolated value in List
143 static Type interpolateValue
144 (
145 const List<Tuple2<scalar, Type>>& list,
146 scalar lookupValue,
148 );
149
150
151 //- Check that list is monotonically increasing
152 // Exit with a FatalError if there is a problem
153 void check() const;
154
155 //- Write
156 void write(Ostream& os) const;
157
158 //- Return the rate of change at the interpolation location
159 //- for the given lookup value
160 Type rateOfChange(scalar lookupValue) const;
161
162 //- Return an interpolated value
163 Type interpolateValue(scalar lookupValue) const;
164
165 //- Return multiple interpolated values
167 (
168 const UList<scalar>& vals
169 ) const;
170
171
172 // Member Operators
173
174 //- Copy assignment
175 void operator=(const interpolationTable<Type>& rhs);
176
177 //- Return an element of constant Tuple2<scalar, Type>
178 const Tuple2<scalar, Type>& operator[](label idx) const;
179
180 //- Return an interpolated value
181 Type operator()(scalar lookupValue) const;
182};
183
184
185// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186
187} // End namespace Foam
188
189// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190
191#ifdef NoRepository
192 #include "interpolationTable.C"
193#endif
194
195// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196
197#endif
198
199// ************************************************************************* //
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: Tuple2.H:58
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A class for handling file names.
Definition: fileName.H:76
An interpolation/look-up table of scalar vs <Type> values. The reference scalar values must be monoto...
void operator=(const interpolationTable< Type > &rhs)
Copy assignment.
void check() const
Check that list is monotonically increasing.
interpolationTable()
Default construct.
tmp< Field< Type > > interpolateValues(const UList< scalar > &vals) const
Return multiple interpolated values.
Type mapped_type
The mapped data type.
Tuple2< scalar, Type > value_type
The element data type.
Type operator()(scalar lookupValue) const
Return an interpolated value.
static Type interpolateValue(const List< Tuple2< scalar, Type > > &list, scalar lookupValue, bounds::repeatableBounding=bounds::repeatableBounding::CLAMP)
Return an interpolated value in List.
Type rateOfChange(scalar lookupValue) const
const Tuple2< scalar, Type > & operator[](label idx) const
Return an element of constant Tuple2<scalar, Type>
A class for managing temporary objects.
Definition: tmp.H:65
OBJstream os(runTime.globalPath()/outputName)
repeatableBounding
Enumeration for handling out-of-bound values that are repeatable.
Definition: tableBounds.H:62
@ CLAMP
Clamp value to the start/end value.
Namespace for OpenFOAM.
runTime write()
dictionary dict