initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / interpolations / interpolationTable / interpolationTable.H
blob884c3cabd70261fecdc9768a8f4d2f5ef6848dae
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::interpolationTable
28 Description
29     A list of times and values.
30     The time values must be positive and monotonically increasing.
32     The handling of out-of-bounds values depends on the current setting
33     of @a outOfBounds.
35     If @a REPEAT is chosen for the out-of-bounds handling, the final time
36     value is treated as being equivalent to time=0 for the following periods.
38 Note
39     - Accessing an empty list results in an error.
40     - Accessing a list with a single element always returns the same value.
42 SourceFiles
43     interpolationTable.C
45 \*---------------------------------------------------------------------------*/
47 #ifndef interpolationTable_H
48 #define interpolationTable_H
50 #include "List.H"
51 #include "Tuple2.H"
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 namespace Foam
58 /*---------------------------------------------------------------------------*\
59                     Class interpolationTable Declaration
60 \*---------------------------------------------------------------------------*/
62 template<class Type>
63 class interpolationTable
65     public List<Tuple2<scalar, Type> >
67 public:
69     // Public data types
71         //- Enumeration for handling out-of-bound values
72         enum boundsHandling
73         {
74             ERROR,          /*!< Exit with a FatalError */
75             WARN,           /*!< Issue warning and clamp value (default) */
76             CLAMP,          /*!< Clamp value to the start/end value */
77             REPEAT          /*!< Treat as a repeating list */
78         };
81 private:
83     // Private data
85         //- Enumeration for handling out-of-bound values
86         boundsHandling boundsHandling_;
88         //- File name
89         fileName fileName_;
92     // Private Member Functions
94         //- Read the table of data from file
95         void readTable();
98 public:
100     // Constructors
102         //- Construct null
103         interpolationTable();
105         //- Construct from components
106         interpolationTable
107         (
108             const List<Tuple2<scalar, Type> >& values,
109             const boundsHandling bounds,
110             const fileName& fName
111         );
113         //- Construct given the name of the file containing the table of data
114         interpolationTable(const fileName& fName);
116         //- Construct by reading the fileName and boundsHandling from dictionary
117         //  and read the table from that file.
118         //  This is a specialised constructor used by patchFields
119         interpolationTable(const dictionary& dict);
121         //- Construct copy
122         interpolationTable(const interpolationTable& interpTable);
125     // Member Functions
127         //- Return the out-of-bounds handling as a word
128         word boundsHandlingToWord(const boundsHandling& bound) const;
130         //- Return the out-of-bounds handling as an enumeration
131         boundsHandling wordToBoundsHandling(const word& bound) const;
133         //- Set the out-of-bounds handling from enum, return previous setting
134         boundsHandling outOfBounds(const boundsHandling& bound);
136         //- Check that list is monotonically increasing
137         //  Exit with a FatalError if there is a problem
138         void check() const;
140         //- Write
141         void write(Ostream& os) const;
144     // Member Operators
146         //- Return an element of constant Tuple2<scalar, Type>
147         const Tuple2<scalar, Type>& operator[](const label) const;
149         //- Return an interpolated value
150         Type operator()(const scalar) const;
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 } // End namespace Foam
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 #ifdef NoRepository
161 #   include "interpolationTable.C"
162 #endif
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
166 #endif
168 // ************************************************************************* //