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 reader
85 
86 
87  // Private Member Functions
88 
89  //- Return interpolated value in List
90  Type interpolateValue
91  (
93  const scalar
94  ) const;
95 
96  //- Return an X index from the matrix
97  template<class BinaryOp>
98  label Xi
99  (
100  const BinaryOp& bop,
101  const scalar valueX,
102  const bool reverse
103  ) const;
104 
105 
106 public:
107 
108  // Constructors
109 
110  //- Construct null
112 
113  //- Construct from components
115  (
116  const List<Tuple2<scalar, List<Tuple2<scalar, Type>>>>& values,
117  const boundsHandling bounds,
118  const fileName& fName
119  );
120 
121  //- Construct given the name of the file containing the table of data
122  interpolation2DTable(const fileName& fName);
123 
124  //- Construct by reading the fileName and boundsHandling from dictionary
126 
127  //- Construct copy
128  interpolation2DTable(const interpolation2DTable& interpTable);
129 
130 
131  // Member Functions
132 
133  //- Return the out-of-bounds handling as a word
135 
136  //- Return the out-of-bounds handling as an enumeration
138 
139  //- Set the out-of-bounds handling from enum, return previous setting
141 
142  //- Check that list is monotonically increasing
143  // Exit with a FatalError if there is a problem
144  void checkOrder() const;
145 
146  //- Write
147  void write(Ostream& os) const;
148 
149 
150  // Member Operators
151 
152  //- Return an element of constant Tuple2<scalar, Type>
153  const List<Tuple2<scalar, Type>>& operator[](const label) const;
154 
155  //- Return an interpolated value
156  Type operator()(const scalar, const scalar) const;
157 };
158 
159 
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161 
162 } // End namespace Foam
163 
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165 
166 #ifdef NoRepository
167  #include "interpolation2DTable.C"
168 #endif
169 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 
172 #endif
173 
174 // ************************************************************************* //
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:54
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.