00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 2008-2010 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software: you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. 00023 00024 Class 00025 Foam::interpolationLookUpTable 00026 00027 Description 00028 A list of lists. Interpolates based on the first dimension. 00029 The values must be positive and monotonically increasing in each dimension 00030 00031 Note 00032 - Accessing an empty list results in an error. 00033 - Accessing a list with a single element always returns the same value. 00034 00035 SourceFiles 00036 interpolationLookUpTable.C 00037 00038 \*---------------------------------------------------------------------------*/ 00039 00040 #ifndef interpolationLookUpTable_H 00041 #define interpolationLookUpTable_H 00042 00043 #include <OpenFOAM/List.H> 00044 #include <OpenFOAM/ListOps.H> 00045 #include <OpenFOAM/scalarField.H> 00046 #include <OpenFOAM/HashTable.H> 00047 #include <OpenFOAM/IOdictionary.H> 00048 #include <finiteVolume/fvCFD.H> 00049 00050 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00051 00052 namespace Foam 00053 { 00054 00055 /*---------------------------------------------------------------------------*\ 00056 Class interpolationLookUpTable Declaration 00057 \*---------------------------------------------------------------------------*/ 00058 00059 template<class Type> 00060 class interpolationLookUpTable 00061 : 00062 public List<scalarField> 00063 { 00064 private: 00065 00066 // Privsate data 00067 00068 //- File name 00069 fileName fileName_; 00070 00071 //- Table dimensions 00072 List<label> dim_; 00073 00074 //- Min on each dimension 00075 List<scalar> min_; 00076 00077 //- Deltas on each dimension 00078 List<scalar> delta_; 00079 00080 //- Maximum on each dimension 00081 List<scalar> max_; 00082 00083 //- Dictionary entries 00084 List<dictionary> entries_; 00085 00086 //- Output dictionaries 00087 List<dictionary> output_; 00088 00089 //- Input indices from the look up table 00090 List<label> entryIndices_; 00091 00092 //- Output Indeces from the Look Up Table 00093 List<label> outputIndices_; 00094 00095 //- Field names and indices 00096 HashTable<label> fieldIndices_; 00097 00098 //- Output list containing input and interpolation values of outputs 00099 List<scalar> interpOutput_; 00100 00101 00102 // Private Member Functions 00103 00104 //- Read the table of data from file 00105 void readTable(const word& instance, const fvMesh& mesh); 00106 00107 //- Dimension table from dictionaries input and output 00108 void dimensionTable(); 00109 00110 //- Find table index by scalarList 00111 label index(const List<scalar>&, const bool lastDim=true) const; 00112 00113 //- Find table index by scalar 00114 label index(const scalar) const; 00115 00116 //- Check range of lookup value 00117 bool checkRange(const scalar, const label) const; 00118 00119 //- Interpolate function return an scalar 00120 scalar interpolate 00121 ( 00122 const label lo, 00123 const label hi, 00124 const scalar lookUpValue, 00125 const label ofield, 00126 const label interfield 00127 ) const; 00128 00129 // Check list is monotonically increasing 00130 void check() const; 00131 00132 // find hi index, interpolate and populate interpOutput_ 00133 void findHi(const label lo, const scalar retvals); 00134 00135 00136 public: 00137 00138 // Constructors 00139 00140 //- Construct null 00141 interpolationLookUpTable(); 00142 00143 //- Construct given the name of the file containing the table of data 00144 interpolationLookUpTable 00145 ( 00146 const fileName& fn, 00147 const word& instance, 00148 const fvMesh& mesh 00149 ); 00150 00151 //- Construct from dictionary 00152 interpolationLookUpTable(const dictionary& dict); 00153 00154 //- Construct copy 00155 interpolationLookUpTable(const interpolationLookUpTable& interpTable); 00156 00157 00158 // Member Functions 00159 00160 //- Return true if the filed exists in the table 00161 bool found(const word& fieldName) const; 00162 00163 //- Return the output list given a single input scalar 00164 const List<scalar>& lookUp(const scalar); 00165 00166 //- Write Look Up Table to filename. 00167 void write 00168 ( 00169 Ostream& os, 00170 const fileName& fn, 00171 const word& instance, 00172 const fvMesh& mesh 00173 ) const; 00174 00175 00176 // Access 00177 00178 //- Return the index of a field by name 00179 inline label findFieldIndex(const word& fieldName) const; 00180 00181 //- Return const access to the output dictionaries 00182 inline const List<dictionary>& output() const; 00183 00184 //- Return const access tp the dictionary entries 00185 inline const List<dictionary>& entries() const; 00186 00187 //- Return const access to the list of min dimensions 00188 inline const List<scalar>& min() const; 00189 00190 //- Return const access to the list of dimensions 00191 inline const List<label>& dim() const; 00192 00193 //- Return const access to the deltas in each dimension 00194 inline const List<scalar>& delta() const; 00195 00196 //- Return const access to the list of max dimensions 00197 inline const List<scalar>& max() const; 00198 00199 //- Return const access to the table name 00200 inline word tableName() const; 00201 00202 00203 // Member Operators 00204 00205 //- Return an element of constant List<scalar, Type> 00206 const scalarField& operator[](const label) const; 00207 00208 //- Return an element of List<scalar, Type> 00209 scalarField& operator[](const label); 00210 00211 }; 00212 00213 00214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00215 00216 #include "interpolationLookUpTableI.H" 00217 00218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00219 00220 } // End namespace Foam 00221 00222 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00223 00224 00225 #ifdef NoRepository 00226 # include "interpolationLookUpTable.C" 00227 #endif 00228 00229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00230 00231 #endif 00232 00233 // ************************ vim: set sw=4 sts=4 et: ************************ //