00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2011 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::interpolationTable 00026 00027 Description 00028 A list of times and values. 00029 The time values must be positive and monotonically increasing. 00030 00031 The handling of out-of-bounds values depends on the current setting 00032 of @a outOfBounds. 00033 00034 If @a REPEAT is chosen for the out-of-bounds handling, the final time 00035 value is treated as being equivalent to time=0 for the following periods. 00036 00037 00038 The construct from dictionary reads a filename from a dictionary and 00039 has an optional readerType. Default is to read OpenFOAM format. The only 00040 other format is csv (comma separated values): 00041 00042 Read csv format: 00043 readerType csv; 00044 fileName "$FOAM_CASE/constant/p0vsTime.csv"; 00045 hasHeaderLine true; // skip first line 00046 timeColumn 0; // time is in column 0 00047 valueColumns (1); // value starts in column 1 00048 00049 00050 Note 00051 - Accessing an empty list results in an error. 00052 - Accessing a list with a single element always returns the same value. 00053 00054 SourceFiles 00055 interpolationTable.C 00056 00057 \*---------------------------------------------------------------------------*/ 00058 00059 #ifndef interpolationTable_H 00060 #define interpolationTable_H 00061 00062 #include <OpenFOAM/List.H> 00063 #include <OpenFOAM/Tuple2.H> 00064 00065 #include <OpenFOAM/tableReader.H> 00066 #include <OpenFOAM/autoPtr.H> 00067 00068 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00069 00070 namespace Foam 00071 { 00072 00073 /*---------------------------------------------------------------------------*\ 00074 Class interpolationTable Declaration 00075 \*---------------------------------------------------------------------------*/ 00076 00077 template<class Type> 00078 class interpolationTable 00079 : 00080 public List<Tuple2<scalar, Type> > 00081 { 00082 public: 00083 00084 // Public data types 00085 00086 //- Enumeration for handling out-of-bound values 00087 enum boundsHandling 00088 { 00089 ERROR, 00090 WARN, 00091 CLAMP, 00092 REPEAT 00093 }; 00094 00095 00096 private: 00097 00098 // Private data 00099 00100 //- Enumeration for handling out-of-bound values 00101 boundsHandling boundsHandling_; 00102 00103 //- File name 00104 fileName fileName_; 00105 00106 //- the actual reader 00107 autoPtr<tableReader<Type> > reader_; 00108 00109 // Private Member Functions 00110 00111 //- Read the table of data from file 00112 void readTable(); 00113 00114 00115 public: 00116 00117 // Constructors 00118 00119 //- Construct null 00120 interpolationTable(); 00121 00122 //- Construct from components 00123 interpolationTable 00124 ( 00125 const List<Tuple2<scalar, Type> >& values, 00126 const boundsHandling bounds, 00127 const fileName& fName 00128 ); 00129 00130 //- Construct given the name of the file containing the table of data 00131 interpolationTable(const fileName& fName); 00132 00133 //- Construct by reading the fileName and boundsHandling from dictionary 00134 // and read the table from that file. 00135 // This is a specialised constructor used by patchFields 00136 interpolationTable(const dictionary& dict); 00137 00138 //- Construct copy 00139 interpolationTable(const interpolationTable& interpTable); 00140 00141 00142 // Member Functions 00143 00144 //- Return the out-of-bounds handling as a word 00145 word boundsHandlingToWord(const boundsHandling& bound) const; 00146 00147 //- Return the out-of-bounds handling as an enumeration 00148 boundsHandling wordToBoundsHandling(const word& bound) const; 00149 00150 //- Set the out-of-bounds handling from enum, return previous setting 00151 boundsHandling outOfBounds(const boundsHandling& bound); 00152 00153 //- Check that list is monotonically increasing 00154 // Exit with a FatalError if there is a problem 00155 void check() const; 00156 00157 //- Write 00158 void write(Ostream& os) const; 00159 00160 00161 // Member Operators 00162 00163 //- Return an element of constant Tuple2<scalar, Type> 00164 const Tuple2<scalar, Type>& operator[](const label) const; 00165 00166 //- Return an interpolated value 00167 Type operator()(const scalar) const; 00168 }; 00169 00170 00171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00172 00173 } // End namespace Foam 00174 00175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00176 00177 #ifdef NoRepository 00178 # include <OpenFOAM/interpolationTable.C> 00179 #endif 00180 00181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00182 00183 #endif 00184 00185 // ************************ vim: set sw=4 sts=4 et: ************************ //