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 interpolationLookUpTable_H
43 #define 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 found(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 
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
218 
219 } // End namespace Foam
220 
221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
222 
224 
225 #ifdef NoRepository
226  #include "interpolationLookUpTable.C"
227 #endif
228 
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 
231 #endif
232 
233 // ************************************************************************* //
Foam::interpolationLookUpTable::delta
const List< scalar > & delta() const
Return const access to the deltas in each dimension.
Definition: interpolationLookUpTableI.H:73
List.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
HashTable.H
scalarField.H
Foam::interpolationLookUpTable::min
const List< scalar > & min() const
Return const access to the list of min dimensions.
Definition: interpolationLookUpTableI.H:57
Foam::interpolationLookUpTable::found
bool found(const word &fieldName) const
Return true if the field exists in the table.
Definition: interpolationLookUpTable.C:427
Foam::interpolationLookUpTable::tableName
word tableName() const
Return const access to the table name.
Definition: interpolationLookUpTableI.H:88
interpolationLookUpTableI.H
Foam::interpolationLookUpTable::entries
const List< dictionary > & entries() const
Return const access tp the dictionary entries.
Definition: interpolationLookUpTableI.H:49
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::interpolationLookUpTable::operator[]
const scalarField & operator[](const label) const
Return an element of constant List<scalar, Type>
Definition: interpolationLookUpTable.C:401
Foam::interpolationLookUpTable::output
const List< dictionary > & output() const
Return const access to the output dictionaries.
Definition: interpolationLookUpTableI.H:41
Foam::Field< scalar >
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::interpolationLookUpTable::interpolationLookUpTable
interpolationLookUpTable()
Construct null.
Definition: interpolationLookUpTable.C:231
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::interpolationLookUpTable::dim
const List< label > & dim() const
Return const access to the list of dimensions.
Definition: interpolationLookUpTableI.H:65
Foam::HashTable< label >
IOdictionary.H
interpolationLookUpTable.C
Foam::interpolationLookUpTable::max
const List< scalar > & max() const
Return const access to the list of max dimensions.
Definition: interpolationLookUpTableI.H:81
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::interpolationLookUpTable::lookUp
const List< scalar > & lookUp(const scalar)
Return the output list given a single input scalar.
Definition: interpolationLookUpTable.C:435
Foam::interpolationLookUpTable::findFieldIndex
label findFieldIndex(const word &fieldName) const
Return the index of a field by name.
Definition: interpolationLookUpTableI.H:31
ListOps.H
Various functions to operate on Lists.
Foam::interpolationLookUpTable
A list of lists. Interpolates based on the first dimension. The values must be positive and monotonic...
Definition: interpolationLookUpTable.H:63
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::interpolationLookUpTable::write
void write(Ostream &, const fileName &, const word &instance, const objectRegistry &) const
Write lookup table to filename.
Definition: interpolationLookUpTable.C:338