OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

interpolationLookUpTable.H

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