interpolationLookUpTable.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::interpolationLookUpTable
26 
27 Description
28  A list of lists. Interpolates based on the first dimension.
29  The values must be positive and monotonically increasing in each dimension
30 
31 Note
32  - Accessing an empty list results in an error.
33  - Accessing a list with a single element always returns the same value.
34 
35 SourceFiles
36  interpolationLookUpTable.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef interpolationLookUpTable_H
41 #define interpolationLookUpTable_H
42 
43 #include "List.H"
44 #include "ListOps.H"
45 #include "scalarField.H"
46 #include "HashTable.H"
47 #include "IOdictionary.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 // Forward declaration of classes
55 class fvMesh;
56 
57 /*---------------------------------------------------------------------------*\
58  Class interpolationLookUpTable Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 template<class Type>
63 :
64  public List<scalarField>
65 {
66 private:
67 
68  // Private data
69 
70  //- File name
71  fileName fileName_;
72 
73  //- Table dimensions
74  List<label> dim_;
75 
76  //- Min on each dimension
77  List<scalar> min_;
78 
79  //- Deltas on each dimension
80  List<scalar> delta_;
81 
82  //- Maximum on each dimension
83  List<scalar> max_;
84 
85  //- Dictionary entries
86  List<dictionary> entries_;
87 
88  //- Output dictionaries
89  List<dictionary> output_;
90 
91  //- Input indices from the lookup table
92  List<label> entryIndices_;
93 
94  //- Output indices from the lookup Table
95  List<label> outputIndices_;
96 
97  //- Field names and indices
98  HashTable<label> fieldIndices_;
99 
100  //- Output list containing input and interpolation values of outputs
101  List<scalar> interpOutput_;
102 
103 
104  // Private Member Functions
105 
106  //- Read the table of data from file
107  void readTable(const word& instance, const objectRegistry&);
108 
109  //- Dimension table from dictionaries input and output
110  void dimensionTable();
111 
112  //- Find table index by scalarList
113  label index(const List<scalar>&, const bool lastDim=true) const;
114 
115  //- Find table index by scalar
116  label index(const scalar) const;
117 
118  //- Check range of lookup value
119  bool checkRange(const scalar, const label) const;
120 
121  //- Interpolate function returning a scalar
122  scalar interpolate
123  (
124  const label lo,
125  const label hi,
126  const scalar lookUpValue,
127  const label ofield,
128  const label interfield
129  ) const;
130 
131  // Check list is monotonically increasing
132  void check() const;
133 
134  // find hi index, interpolate and populate interpOutput_
135  void findHi(const label lo, const scalar retvals);
136 
137 
138 public:
139 
140  // Constructors
141 
142  //- Construct null
144 
145  //- Construct given the name of the file containing the table of data
147  (
148  const fileName&,
149  const word& instance,
150  const objectRegistry&
151  );
152 
153  //- Construct from dictionary
155 
156  //- Construct copy
158 
159 
160  // Member Functions
161 
162  //- Return true if the field exists in the table
163  bool found(const word& fieldName) const;
164 
165  //- Return the output list given a single input scalar
166  const List<scalar>& lookUp(const scalar);
167 
168  //- Write lookup table to filename.
169  void write
170  (
171  Ostream&,
172  const fileName&,
173  const word& instance,
174  const objectRegistry&
175  ) const;
176 
177 
178  // Access
179 
180  //- Return the index of a field by name
181  inline label findFieldIndex(const word& fieldName) const;
182 
183  //- Return const access to the output dictionaries
184  inline const List<dictionary>& output() const;
185 
186  //- Return const access tp the dictionary entries
187  inline const List<dictionary>& entries() const;
188 
189  //- Return const access to the list of min dimensions
190  inline const List<scalar>& min() const;
191 
192  //- Return const access to the list of dimensions
193  inline const List<label>& dim() const;
194 
195  //- Return const access to the deltas in each dimension
196  inline const List<scalar>& delta() const;
197 
198  //- Return const access to the list of max dimensions
199  inline const List<scalar>& max() const;
200 
201  //- Return const access to the table name
202  inline word tableName() const;
203 
204 
205  // Member Operators
206 
207  //- Return an element of constant List<scalar, Type>
208  const scalarField& operator[](const label) const;
209 
210  //- Return an element of List<scalar, Type>
211  scalarField& operator[](const label);
212 
213 };
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 } // End namespace Foam
218 
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 
222 
223 #ifdef NoRepository
224  #include "interpolationLookUpTable.C"
225 #endif
226 
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
228 
229 #endif
230 
231 // ************************************************************************* //
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
label findFieldIndex(const word &fieldName) const
Return the index of a field by name.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
bool found(const word &fieldName) const
Return true if the field exists in the table.
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 List< dictionary > & output() const
Return const access to the output dictionaries.
const List< scalar > & delta() const
Return const access to the deltas in each dimension.
const List< scalar > & max() const
Return const access to the list of max dimensions.
Various functions to operate on Lists.
void write(Ostream &, const fileName &, const word &instance, const objectRegistry &) const
Write lookup table to filename.
const scalarField & operator[](const label) const
Return an element of constant List<scalar, Type>
const List< scalar > & min() const
Return const access to the list of min dimensions.
word tableName() const
Return const access to the table name.
A class for handling words, derived from string.
Definition: word.H:59
A list of lists. Interpolates based on the first dimension. The values must be positive and monotonic...
const List< scalar > & lookUp(const scalar)
Return the output list given a single input scalar.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
const List< label > & dim() const
Return const access to the list of dimensions.
Registry of regIOobjects.
const List< dictionary > & entries() const
Return const access tp the dictionary entries.
Namespace for OpenFOAM.