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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::interpolationLookUpTable
28 
29 Description
30  A list of lists. Interpolates based on the first dimension.
31  The values must be positive and monotonically increasing in each dimension
32 
33 Note
34  - Accessing an empty list results in an error.
35  - Accessing a list with a single element always returns the same value.
36 
37 SourceFiles
38  interpolationLookUpTable.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef Foam_interpolationLookUpTable_H
43 #define Foam_interpolationLookUpTable_H
44 
45 #include "List.H"
46 #include "ListOps.H"
47 #include "scalarField.H"
48 #include "HashTable.H"
49 #include "IOdictionary.H"
50 
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 
53 namespace Foam
54 {
55 
56 // Forward declaration of classes
57 class fvMesh;
58 
59 /*---------------------------------------------------------------------------*\
60  Class interpolationLookUpTable Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 template<class Type>
65 :
66  public List<scalarField>
67 {
68 private:
69 
70  // Private data
71 
72  //- File name
73  fileName fileName_;
74 
75  //- Table dimensions
76  List<label> dim_;
77 
78  //- Min on each dimension
79  List<scalar> min_;
80 
81  //- Deltas on each dimension
82  List<scalar> delta_;
83 
84  //- Maximum on each dimension
85  List<scalar> max_;
86 
87  //- Dictionary entries
88  List<dictionary> entries_;
89 
90  //- Output dictionaries
91  List<dictionary> output_;
92 
93  //- Input indices from the lookup table
94  List<label> entryIndices_;
95 
96  //- Output indices from the lookup Table
97  List<label> outputIndices_;
98 
99  //- Field names and indices
100  HashTable<label> fieldIndices_;
101 
102  //- Output list containing input and interpolation values of outputs
103  List<scalar> interpOutput_;
104 
105 
106  // Private Member Functions
107 
108  //- Read the table of data from file
109  void readTable(const word& instance, const objectRegistry&);
110 
111  //- Dimension table from dictionaries input and output
112  void dimensionTable();
113 
114  //- Find table index by scalarList
115  label index(const List<scalar>&, const bool lastDim=true) const;
116 
117  //- Find table index by scalar
118  label index(const scalar) const;
119 
120  //- Check range of lookup value
121  bool checkRange(const scalar, const label) const;
122 
123  //- Interpolate function returning a scalar
124  scalar interpolate
125  (
126  const label lo,
127  const label hi,
128  const scalar lookUpValue,
129  const label ofield,
130  const label interfield
131  ) const;
132 
133  // Check list is monotonically increasing
134  void check() const;
135 
136  // find hi index, interpolate and populate interpOutput_
137  void findHi(const label lo, const scalar retvals);
138 
139 
140 public:
141 
142  // Constructors
143 
144  //- Construct null
146 
147  //- Construct given the name of the file containing the table of data
149  (
150  const fileName&,
151  const word& instance,
152  const objectRegistry&
153  );
154 
155  //- Construct from dictionary
157 
158  //- Construct copy
160 
161 
162  // Member Functions
163 
164  //- Return true if the field exists in the table
165  bool contains(const word& fieldName) const;
166 
167  //- Return the output list given a single input scalar
168  const List<scalar>& lookUp(const scalar);
169 
170  //- Write lookup table to filename.
171  void write
172  (
173  Ostream&,
174  const fileName&,
175  const word& instance,
176  const objectRegistry&
177  ) const;
178 
179 
180  // Access
181 
182  //- Return the index of a field by name
183  inline label findFieldIndex(const word& fieldName) const;
184 
185  //- Return const access to the output dictionaries
186  inline const List<dictionary>& output() const;
187 
188  //- Return const access tp the dictionary entries
189  inline const List<dictionary>& entries() const;
190 
191  //- Return const access to the list of min dimensions
192  inline const List<scalar>& min() const;
193 
194  //- Return const access to the list of dimensions
195  inline const List<label>& dim() const;
196 
197  //- Return const access to the deltas in each dimension
198  inline const List<scalar>& delta() const;
199 
200  //- Return const access to the list of max dimensions
201  inline const List<scalar>& max() const;
202 
203  //- Return const access to the table name
204  inline word tableName() const;
205 
206 
207  // Member Operators
208 
209  //- Return an element of constant List<scalar, Type>
210  const scalarField& operator[](const label) const;
211 
212  //- Return an element of List<scalar, Type>
213  scalarField& operator[](const label);
214 
215 
216  // Housekeeping
217 
218  //- Same as contains()
219  bool found(const word& fieldName) const
220  {
221  return this->contains(fieldName);
222  }
223 };
224 
225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 
227 } // End namespace Foam
228 
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 
232 
233 #ifdef NoRepository
234  #include "interpolationLookUpTable.C"
235 #endif
236 
237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
238 
239 #endif
240 
241 // ************************************************************************* //
A class for handling file names.
Definition: fileName.H:72
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
const List< scalar > & max() const
Return const access to the list of max dimensions.
bool contains(const word &fieldName) const
Return true if the field exists in the table.
Various functions to operate on Lists.
void write(Ostream &, const fileName &, const word &instance, const objectRegistry &) const
Write lookup table to filename.
const List< dictionary > & entries() const
Return const access tp the dictionary entries.
A class for handling words, derived from Foam::string.
Definition: word.H:63
const List< label > & dim() const
Return const access to the list of dimensions.
A list of lists. Interpolates based on the first dimension. The values must be positive and monotonic...
const scalarField & operator[](const label) const
Return an element of constant List<scalar, Type>
const List< scalar > & lookUp(const scalar)
Return the output list given a single input scalar.
const List< scalar > & delta() const
Return const access to the deltas in each dimension.
bool found(const word &fieldName) const
Same as contains()
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const List< scalar > & min() const
Return const access to the list of min dimensions.
word tableName() const
Return const access to the table name.
const List< dictionary > & output() const
Return const access to the output dictionaries.
label findFieldIndex(const word &fieldName) const
Return the index of a field by name.
Registry of regIOobjects.
Namespace for OpenFOAM.