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 | Copyright (C) 2011-2016 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::interpolationTable
26 
27 Description
28  An interpolation/look-up table of scalar vs <Type> values.
29  The reference scalar values must be monotonically increasing.
30 
31  The handling of out-of-bounds values depends on the current setting
32  of \c outOfBounds.
33 
34  If \c repeat is chosen for the out-of-bounds handling, the final time
35  value is treated as being equivalent to time=0 for the following periods.
36 
37 
38  The construct from dictionary reads a filename from a dictionary and
39  has an optional readerType. Default is to read OpenFOAM format. The only
40  other format is csv (comma separated values):
41 
42  Read csv format:
43  \verbatim
44  readerType csv;
45  fileName "$FOAM_CASE/constant/p0vsTime.csv";
46  hasHeaderLine true; // skip first line
47  timeColumn 0; // time is in column 0
48  valueColumns (1); // value starts in column 1
49  \endverbatim
50 
51 
52 Note
53  - Accessing an empty list results in an error.
54  - Accessing a list with a single element always returns the same value.
55 
56 SourceFiles
57  interpolationTable.C
58 
59 \*---------------------------------------------------------------------------*/
60 
61 #ifndef interpolationTable_H
62 #define interpolationTable_H
63 
64 #include "List.H"
65 #include "Tuple2.H"
66 
67 #include "tableReader.H"
68 #include "autoPtr.H"
69 
70 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
71 
72 namespace Foam
73 {
74 
75 /*---------------------------------------------------------------------------*\
76  Class interpolationTable Declaration
77 \*---------------------------------------------------------------------------*/
78 
79 template<class Type>
81 :
82  public List<Tuple2<scalar, Type>>
83 {
84 public:
85 
86  // Public data types
87 
88  //- Enumeration for handling out-of-bound values
89  enum boundsHandling
90  {
92  WARN,
94  REPEAT
95  };
96 
97 
98 private:
99 
100  // Private data
101 
102  //- Enumeration for handling out-of-bound values
103  boundsHandling boundsHandling_;
104 
105  //- File name
106  fileName fileName_;
107 
108  //- The actual reader
109  autoPtr<tableReader<Type>> reader_;
110 
111  // Private Member Functions
112 
113  //- Read the table of data from file
114  void readTable();
115 
116 
117 public:
118 
119  // Constructors
120 
121  //- Construct null
123 
124  //- Construct from components
126  (
127  const List<Tuple2<scalar, Type>>& values,
128  const boundsHandling bounds,
129  const fileName& fName
130  );
131 
132  //- Construct given the name of the file containing the table of data
133  interpolationTable(const fileName& fName);
134 
135  //- Construct by reading the fileName and boundsHandling from dictionary
136  // and read the table from that file.
137  // This is a specialised constructor used by patchFields
139 
140  //- Construct copy
141  interpolationTable(const interpolationTable& interpTable);
142 
143 
144  // Member Functions
145 
146  //- Return the out-of-bounds handling as a word
148 
149  //- Return the out-of-bounds handling as an enumeration
151 
152  //- Set the out-of-bounds handling from enum, return previous setting
154 
155  //- Check that list is monotonically increasing
156  // Exit with a FatalError if there is a problem
157  void check() const;
158 
159  //- Write
160  void write(Ostream& os) const;
161 
162  //- Return the rate of change at the interpolation location
163  // for the give value
164  Type rateOfChange(const scalar) const;
165 
166 
167  // Member Operators
168 
169  //- Return an element of constant Tuple2<scalar, Type>
170  const Tuple2<scalar, Type>& operator[](const label) const;
171 
172  //- Return an interpolated value
173  Type operator()(const scalar) const;
174 };
175 
176 
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 
179 } // End namespace Foam
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 #ifdef NoRepository
184  #include "interpolationTable.C"
185 #endif
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 #endif
190 
191 // ************************************************************************* //
Type rateOfChange(const scalar) const
Return the rate of change at the interpolation location.
word boundsHandlingToWord(const boundsHandling &bound) const
Return the out-of-bounds handling as a word.
void check() const
Check that list is monotonically increasing.
dictionary dict
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:59
A class for handling file names.
Definition: fileName.H:69
interpolationTable()
Construct null.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
A 2-tuple for storing two objects of different types.
Definition: Tuple2.H:47
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
const Tuple2< scalar, Type > & operator[](const label) const
Return an element of constant Tuple2<scalar, Type>
Type operator()(const scalar) const
Return an interpolated value.
boundsHandling outOfBounds(const boundsHandling &bound)
Set the out-of-bounds handling from enum, return previous setting.
A class for handling words, derived from string.
Definition: word.H:59
Clamp value to the start/end value.
An interpolation/look-up table of scalar vs <Type> values. The reference scalar values must be monoto...
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Exit with a FatalError.
Issue warning and clamp value (default)
boundsHandling
Enumeration for handling out-of-bound values.
volScalarField & bound(volScalarField &, const dimensionedScalar &lowerBound)
Bound the given scalar field if it has gone unbounded.
Definition: bound.C:33
Treat as a repeating list.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
boundsHandling wordToBoundsHandling(const word &bound) const
Return the out-of-bounds handling as an enumeration.
void write(Ostream &os) const
Write.
Namespace for OpenFOAM.