interpolation2DTable.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-2019 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::interpolation2DTable
26 
27 Description
28  2D table interpolation. The data must be in ascending order in both
29  dimensions x and y.
30 
31 SourceFiles
32  interpolation2DTable.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef interpolation2DTable_H
37 #define interpolation2DTable_H
38 
39 #include "List.H"
40 #include "Tuple2.H"
41 #include "tableReader.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class interpolation2DTable Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 template<class Type>
54 :
55  public List<Tuple2<scalar, List<Tuple2<scalar, Type>>>>
56 {
57 public:
58 
59  // Public data types
60 
61  //- Enumeration for handling out-of-bound values
62  enum boundsHandling
63  {
65  WARN,
66  CLAMP
67  };
68 
69  //- Cconvenience typedef
71 
72 
73 private:
74 
75  // Private Data
76 
77  //- Enumeration for handling out-of-bound values
78  boundsHandling boundsHandling_;
79 
80  //- File name
81  fileName fileName_;
82 
83  //- The actual reader
85 
86 
87  // Private Member Functions
88 
89  //- Read the table of data from file
90  void readTable();
91 
92  //- Return interpolated value in List
93  Type interpolateValue
94  (
96  const scalar
97  ) const;
98 
99  //- Return an X index from the matrix
100  template<class BinaryOp>
101  label Xi
102  (
103  const BinaryOp& bop,
104  const scalar valueX,
105  const bool reverse
106  ) const;
107 
108 
109 public:
110 
111  // Constructors
112 
113  //- Construct null
115 
116  //- Construct from components
118  (
119  const List<Tuple2<scalar, List<Tuple2<scalar, Type>>>>& values,
120  const boundsHandling bounds,
121  const fileName& fName
122  );
123 
124  //- Construct given the name of the file containing the table of data
125  interpolation2DTable(const fileName& fName);
126 
127  //- Construct by reading the fileName and boundsHandling from dictionary
129 
130  //- Construct copy
131  interpolation2DTable(const interpolation2DTable& interpTable);
132 
133 
134  // Member Functions
135 
136  //- Return the out-of-bounds handling as a word
138 
139  //- Return the out-of-bounds handling as an enumeration
141 
142  //- Set the out-of-bounds handling from enum, return previous setting
144 
145  //- Check that list is monotonically increasing
146  // Exit with a FatalError if there is a problem
147  void checkOrder() const;
148 
149  //- Write
150  void write(Ostream& os) const;
151 
152 
153  // Member Operators
154 
155  //- Return an element of constant Tuple2<scalar, Type>
156  const List<Tuple2<scalar, Type>>& operator[](const label) const;
157 
158  //- Return an interpolated value
159  Type operator()(const scalar, const scalar) const;
160 };
161 
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 } // End namespace Foam
166 
167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168 
169 #ifdef NoRepository
170  #include "interpolation2DTable.C"
171 #endif
172 
173 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174 
175 #endif
176 
177 // ************************************************************************* //
dictionary dict
List< Tuple2< scalar, List< Tuple2< scalar, Type > > > > table
Cconvenience typedef.
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:79
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
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
Clamp value to the start/end value.
const List< Tuple2< scalar, Type > > & operator[](const label) const
Return an element of constant Tuple2<scalar, Type>
2D table interpolation. The data must be in ascending order in both dimensions x and y...
word boundsHandlingToWord(const boundsHandling &bound) const
Return the out-of-bounds handling as a word.
interpolation2DTable()
Construct null.
A class for handling words, derived from string.
Definition: word.H:59
Issue warning and clamp value (default)
Type operator()(const scalar, const scalar) const
Return an interpolated value.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void reverse(UList< T > &, const label n)
Definition: UListI.H:322
void write(Ostream &os) const
Write.
Database for solution and other reduced data.
Definition: data.H:51
boundsHandling outOfBounds(const boundsHandling &bound)
Set the out-of-bounds handling from enum, return previous setting.
volScalarField & bound(volScalarField &, const dimensionedScalar &lowerBound)
Bound the given scalar field if it has gone unbounded.
Definition: bound.C:33
void checkOrder() const
Check that list is monotonically increasing.
boundsHandling wordToBoundsHandling(const word &bound) const
Return the out-of-bounds handling as an enumeration.
boundsHandling
Enumeration for handling out-of-bound values.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Namespace for OpenFOAM.