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