interpolation2DTable.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 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::interpolation2DTable
29 
30 Description
31  2D table interpolation.
32  The data must be in ascending order in both dimensions x and y.
33 
34 SourceFiles
35  interpolation2DTable.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef interpolation2DTable_H
40 #define interpolation2DTable_H
41 
42 #include "interpolationTable.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 /*---------------------------------------------------------------------------*\
50  Class interpolation2DTable Declaration
51 \*---------------------------------------------------------------------------*/
52 
53 template<class Type>
55 :
56  public List<Tuple2<scalar, List<Tuple2<scalar, Type>>>>
57 {
58  // Private Data
59 
60  //- Handling for out-of-bound values
61  bounds::normalBounding bounding_;
62 
63  //- File name
64  fileName fileName_;
65 
66  //- Table reader
68 
69 
70  // Private Member Functions
71 
72  //- Read the table of data from file
73  void readTable();
74 
75  //- Interpolated value within 1-D list
76  Type interpolateValue
77  (
78  const List<Tuple2<scalar, Type>>& list,
79  scalar lookupValue
80  ) const;
81 
82  //- Return an X index from the matrix
83  template<class BinaryOp>
84  label Xi
85  (
86  const BinaryOp& bop,
87  const scalar valueX,
88  const bool reverse
89  ) const;
90 
91 
92 public:
93 
94  // Public Data Types
95 
96  //- The element data type
98 
99  //- Convenience typedef
101 
102 
103  // Constructors
104 
105  //- Default construct
107 
108  //- Construct from components
110  (
111  const List<Tuple2<scalar, List<Tuple2<scalar, Type>>>>& values,
112  const bounds::normalBounding bounding,
113  const fileName& fName
114  );
115 
116  //- Construct given the name of the file containing the table of data
117  explicit interpolation2DTable(const fileName& fName);
118 
119  //- Construct by reading file name and outOfBounds from dictionary
120  explicit interpolation2DTable(const dictionary& dict);
121 
122  //- Copy construct
124 
125 
126  // Member Functions
127 
128  //- Check that list is monotonically increasing
129  // Exit with a FatalError if there is a problem
130  void check() const;
131 
132  //- Write
133  void write(Ostream& os) const;
134 
135 
136  // Member Operators
137 
138  //- Copy assignment
139  void operator=(const interpolation2DTable<Type>& rhs);
140 
141  //- Return an interpolated value
142  Type operator()(const scalar valueX, const scalar valueY) const;
143 
144 
145  // Housekeeping
146 
147  //- Deprecated(2019-08) check list is monotonically increasing
148  // \deprecated(2019-08) - older name for check() method
149  void checkOrder() const { check(); }
150 };
151 
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 } // End namespace Foam
156 
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 
159 #ifdef NoRepository
160  #include "interpolation2DTable.C"
161 #endif
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 #endif
166 
167 // ************************************************************************* //
Foam::reverse
void reverse(UList< T > &list, const label n)
Definition: UListI.H:449
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
Foam::interpolation2DTable::interpolation2DTable
interpolation2DTable()
Default construct.
Definition: interpolation2DTable.C:57
interpolationTable.H
Foam::interpolation2DTable::value_type
Tuple2< scalar, List< Tuple2< scalar, Type > > > value_type
The element data type.
Definition: interpolation2DTable.H:96
Foam::bounds::normalBounding
normalBounding
Enumeration for handling out-of-bound values.
Definition: tableBounds.H:53
Foam::interpolation2DTable
2D table interpolation. The data must be in ascending order in both dimensions x and y.
Definition: interpolation2DTable.H:53
Foam::interpolation2DTable::operator=
void operator=(const interpolation2DTable< Type > &rhs)
Copy assignment.
Definition: interpolation2DTable.C:223
Foam::interpolation2DTable::checkOrder
void checkOrder() const
Deprecated(2019-08) check list is monotonically increasing.
Definition: interpolation2DTable.H:148
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::interpolation2DTable::check
void check() const
Check that list is monotonically increasing.
Definition: interpolation2DTable.C:288
os
OBJstream os(runTime.globalPath()/outputName)
interpolation2DTable.C
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::interpolation2DTable::operator()
Type operator()(const scalar valueX, const scalar valueY) const
Return an interpolated value.
Definition: interpolation2DTable.C:241
Foam::interpolation2DTable::table
List< Tuple2< scalar, List< Tuple2< scalar, Type > > > > table
Convenience typedef.
Definition: interpolation2DTable.H:99
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Tuple2
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:60
Foam::interpolation2DTable::write
void write(Ostream &os) const
Write.
Definition: interpolation2DTable.C:314