interpolationLookUpTable.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 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 namespace radiationModels
54 {
55 namespace absorptionEmissionModels
56 {
57 
58 /*---------------------------------------------------------------------------*\
59  Class interpolationLookUpTable Declaration
60 \*---------------------------------------------------------------------------*/
61 
63 :
64  public List<scalarField>
65 {
66  // Private 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 lookup table
90  List<label> entryIndices_;
91 
92  //- Output indices from the lookup 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 objectRegistry&);
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 returning a 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&,
147  const word& instance,
148  const objectRegistry&
149  );
150 
151  //- Construct from dictionary
153 
154  //- Construct copy
156 
157 
158  // Member Functions
159 
160  //- Return true if the field 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 lookup table to filename.
167  void write
168  (
169  Ostream&,
170  const fileName&,
171  const word& instance,
172  const objectRegistry&
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
206  const scalarField& operator[](const label) const;
207 
208  //- Return an element
209  scalarField& operator[](const label);
210 
211 };
212 
213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214 
215 } // End namespace absorptionEmissionModels
216 } // End namespace radiationModels
217 } // End namespace Foam
218 
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 
222 
223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
224 
225 #endif
226 
227 // ************************************************************************* //
A class for handling file names.
Definition: fileName.H:79
const List< scalar > & min() const
Return const access to the list of min dimensions.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
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
label findFieldIndex(const word &fieldName) const
Return the index of a field by name.
Various functions to operate on Lists.
const List< scalar > & lookUp(const scalar)
Return the output list given a single input scalar.
void write(Ostream &, const fileName &, const word &instance, const objectRegistry &) const
Write lookup table to filename.
A class for handling words, derived from string.
Definition: word.H:59
const List< label > & dim() const
Return const access to the list of dimensions.
const scalarField & operator[](const label) const
Return an element.
An STL-conforming hash table.
Definition: HashTable.H:61
const List< scalar > & max() const
Return const access to the list of max dimensions.
const List< dictionary > & entries() const
Return const access tp the dictionary entries.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
Registry of regIOobjects.
const List< scalar > & delta() const
Return const access to the deltas in each dimension.
const List< dictionary > & output() const
Return const access to the output dictionaries.
bool found(const word &fieldName) const
Return true if the field exists in the table.
Namespace for OpenFOAM.