FreeFOAM The Cross-Platform CFD Toolkit
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) 2008-2010 OpenCFD Ltd.
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 <OpenFOAM/List.H>
44 #include <OpenFOAM/ListOps.H>
45 #include <OpenFOAM/scalarField.H>
46 #include <OpenFOAM/HashTable.H>
47 #include <OpenFOAM/IOdictionary.H>
48 #include <finiteVolume/fvCFD.H>
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 /*---------------------------------------------------------------------------*\
56  Class interpolationLookUpTable Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 template<class Type>
61 :
62  public List<scalarField>
63 {
64 private:
65 
66  // Privsate data
67 
68  //- File name
69  fileName fileName_;
70 
71  //- Table dimensions
72  List<label> dim_;
73 
74  //- Min on each dimension
75  List<scalar> min_;
76 
77  //- Deltas on each dimension
78  List<scalar> delta_;
79 
80  //- Maximum on each dimension
81  List<scalar> max_;
82 
83  //- Dictionary entries
84  List<dictionary> entries_;
85 
86  //- Output dictionaries
87  List<dictionary> output_;
88 
89  //- Input indices from the look up table
90  List<label> entryIndices_;
91 
92  //- Output Indeces from the Look Up Table
93  List<label> outputIndices_;
94 
95  //- Field names and indices
96  HashTable<label> fieldIndices_;
97 
98  //- Output list containing input and interpolation values of outputs
99  List<scalar> interpOutput_;
100 
101 
102  // Private Member Functions
103 
104  //- Read the table of data from file
105  void readTable(const word& instance, const fvMesh& mesh);
106 
107  //- Dimension table from dictionaries input and output
108  void dimensionTable();
109 
110  //- Find table index by scalarList
111  label index(const List<scalar>&, const bool lastDim=true) const;
112 
113  //- Find table index by scalar
114  label index(const scalar) const;
115 
116  //- Check range of lookup value
117  bool checkRange(const scalar, const label) const;
118 
119  //- Interpolate function return an scalar
120  scalar interpolate
121  (
122  const label lo,
123  const label hi,
124  const scalar lookUpValue,
125  const label ofield,
126  const label interfield
127  ) const;
128 
129  // Check list is monotonically increasing
130  void check() const;
131 
132  // find hi index, interpolate and populate interpOutput_
133  void findHi(const label lo, const scalar retvals);
134 
135 
136 public:
137 
138  // Constructors
139 
140  //- Construct null
142 
143  //- Construct given the name of the file containing the table of data
145  (
146  const fileName& fn,
147  const word& instance,
148  const fvMesh& mesh
149  );
150 
151  //- Construct from dictionary
153 
154  //- Construct copy
156 
157 
158  // Member Functions
159 
160  //- Return true if the filed exists in the table
161  bool found(const word& fieldName) const;
162 
163  //- Return the output list given a single input scalar
164  const List<scalar>& lookUp(const scalar);
165 
166  //- Write Look Up Table to filename.
167  void write
168  (
169  Ostream& os,
170  const fileName& fn,
171  const word& instance,
172  const fvMesh& mesh
173  ) const;
174 
175 
176  // Access
177 
178  //- Return the index of a field by name
179  inline label findFieldIndex(const word& fieldName) const;
180 
181  //- Return const access to the output dictionaries
182  inline const List<dictionary>& output() const;
183 
184  //- Return const access tp the dictionary entries
185  inline const List<dictionary>& entries() const;
186 
187  //- Return const access to the list of min dimensions
188  inline const List<scalar>& min() const;
189 
190  //- Return const access to the list of dimensions
191  inline const List<label>& dim() const;
192 
193  //- Return const access to the deltas in each dimension
194  inline const List<scalar>& delta() const;
195 
196  //- Return const access to the list of max dimensions
197  inline const List<scalar>& max() const;
198 
199  //- Return const access to the table name
200  inline word tableName() const;
201 
202 
203  // Member Operators
204 
205  //- Return an element of constant List<scalar, Type>
206  const scalarField& operator[](const label) const;
207 
208  //- Return an element of List<scalar, Type>
209  scalarField& operator[](const label);
210 
211 };
212 
213 
214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 
217 
218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 
220 } // End namespace Foam
221 
222 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223 
224 
225 #ifdef NoRepository
226 # include "interpolationLookUpTable.C"
227 #endif
228 
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 
231 #endif
232 
233 // ************************ vim: set sw=4 sts=4 et: ************************ //