TableBase.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 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::TableBase
26 
27 Description
28  Base class for table with bounds handling, interpolation and integration
29 
30 SourceFiles
31  TableBase.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef TableBase_H
36 #define TableBase_H
37 
38 #include "DataEntry.H"
39 #include "Tuple2.H"
40 #include "dimensionSet.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 template<class Type>
48 class TableBase;
49 
50 template<class Type>
51 Ostream& operator<<
52 (
53  Ostream&,
54  const TableBase<Type>&
55 );
56 
58 
59 /*---------------------------------------------------------------------------*\
60  Class TableBase Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 template<class Type>
64 class TableBase
65 :
66  public DataEntry<Type>
67 {
68 public:
69 
70  // Public data types
71 
72  //- Enumeration for handling out-of-bound values
73  enum boundsHandling
74  {
76  WARN,
78  REPEAT
79  };
80 
81 
82 protected:
83 
84  // Protected data
85 
86  //- Table name
87  const word name_;
88 
89  //- Enumeration for handling out-of-bound values
91 
92  //- Interpolation type
94 
95  //- Table data
97 
98  //- The dimension set
100 
101  //- Extracted values
103 
104  //- Interpolator method
106 
107  //- Cached indices and weights
108  mutable labelList currentIndices_;
111 
112 
113  // Protected Member Functions
114 
115 
116  //- Return (demand driven) interpolator
117  const interpolationWeights& interpolator() const;
118 
119  //- Disallow default bitwise assignment
120  void operator=(const TableBase<Type>&);
121 
122 
123 public:
124 
125  // Constructors
126 
127  //- Construct from dictionary - note table is not populated
128  TableBase(const word& name, const dictionary& dict);
129 
130  //- Copy constructor. Note: steals interpolator, tableSamples
131  TableBase(const TableBase<Type>& tbl);
132 
133 
134  //- Destructor
135  virtual ~TableBase();
136 
137 
138  // Member Functions
139 
140  //- Return the out-of-bounds handling as a word
142 
143  //- Return the out-of-bounds handling as an enumeration
145 
146  //- Set the out-of-bounds handling from enum, return previous setting
148 
149  //- Check the table for size and consistency
150  void check() const;
151 
152  //- Check minimum table bounds
153  bool checkMinBounds(const scalar x, scalar& xDash) const;
154 
155  //- Check maximum table bounds
156  bool checkMaxBounds(const scalar x, scalar& xDash) const;
157 
158  //- Convert time
159  virtual void convertTimeBase(const Time& t);
160 
161  //- Return Table value
162  virtual Type value(const scalar x) const;
163 
164  //- Integrate between two (scalar) values
165  virtual Type integrate(const scalar x1, const scalar x2) const;
166 
167  //- Return dimensioned constant value
168  virtual dimensioned<Type> dimValue(const scalar x) const;
169 
170  //- Integrate between two values and return dimensioned type
172  (
173  const scalar x1,
174  const scalar x2
175  ) const;
176 
177  //- Return the reference values
178  virtual tmp<scalarField> x() const;
179 
180  //- Return the dependent values
181  virtual tmp<Field<Type> > y() const;
182 
183 
184  // I/O
185 
186  //- Ostream Operator
187  friend Ostream& operator<< <Type>
188  (
189  Ostream& os,
190  const TableBase<Type>& tbl
191  );
192 
193  //- Write all table data in dictionary format
194  virtual void writeData(Ostream& os) const;
195 
196  //- Write keywords only in dictionary format. Used for non-inline
197  // table types
198  virtual void writeEntries(Ostream& os) const;
199 };
200 
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 
204 } // End namespace Foam
205 
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 
208 #ifdef NoRepository
209 # include "TableBase.C"
210 #endif
211 
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 
214 #endif
215 
216 // ************************************************************************* //
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: TableBase.C:381
bool checkMinBounds(const scalar x, scalar &xDash) const
Check minimum table bounds.
Definition: TableBase.C:216
virtual ~TableBase()
Destructor.
Definition: TableBase.C:95
boundsHandling
Enumeration for handling out-of-bound values.
Definition: TableBase.H:72
virtual void writeData(Ostream &os) const
Write all table data in dictionary format.
Definition: TableBaseIO.C:63
Base class for table with bounds handling, interpolation and integration.
Definition: TableBase.H:47
volScalarField & bound(volScalarField &, const dimensionedScalar &lowerBound)
Bound the given scalar field if it has gone unbounded.
Definition: bound.C:33
A class for handling words, derived from string.
Definition: word.H:59
const word interpolationScheme_
Interpolation type.
Definition: TableBase.H:92
virtual tmp< scalarField > x() const
Return the reference values.
Definition: TableBase.C:420
const word const dictionary & dict
Definition: DataEntry.H:93
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
autoPtr< interpolationWeights > interpolatorPtr_
Interpolator method.
Definition: TableBase.H:104
boundsHandling wordToBoundsHandling(const word &bound) const
Return the out-of-bounds handling as an enumeration.
Definition: TableBase.C:140
virtual tmp< Field< Type > > y() const
Return the dependent values.
Definition: TableBase.C:435
List< Tuple2< scalar, Type > > table_
Table data.
Definition: TableBase.H:95
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
virtual void writeEntries(Ostream &os) const
Write keywords only in dictionary format. Used for non-inline.
Definition: TableBaseIO.C:72
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Generic dimensioned Type class.
const boundsHandling boundsHandling_
Enumeration for handling out-of-bound values.
Definition: TableBase.H:89
const word name_
Table name.
Definition: TableBase.H:86
Dimension set for the base types.
Definition: dimensionSet.H:116
virtual void convertTimeBase(const Time &t)
Convert time.
Definition: TableBase.C:339
const word & name() const
Return the name of the entry.
Definition: DataEntry.C:57
virtual Type value(const scalar x) const
Return Table value.
Definition: TableBase.C:353
boundsHandling outOfBounds(const boundsHandling &bound)
Set the out-of-bounds handling from enum, return previous setting.
Definition: TableBase.C:174
scalarField currentWeights_
Definition: TableBase.H:109
bool checkMaxBounds(const scalar x, scalar &xDash) const
Check maximum table bounds.
Definition: TableBase.C:278
void check() const
Check the table for size and consistency.
Definition: TableBase.C:186
const interpolationWeights & interpolator() const
Return (demand driven) interpolator.
Definition: TableBase.C:33
dimensionSet dimensions_
The dimension set.
Definition: TableBase.H:98
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
labelList currentIndices_
Cached indices and weights.
Definition: TableBase.H:107
Abstract base class for interpolating in 1D.
word boundsHandlingToWord(const boundsHandling &bound) const
Return the out-of-bounds handling as a word.
Definition: TableBase.C:103
TableBase(const word &name, const dictionary &dict)
Construct from dictionary - note table is not populated.
Definition: TableBase.C:58
void operator=(const TableBase< Type > &)
Disallow default bitwise assignment.
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: DataEntry.H:52
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
A class for managing temporary objects.
Definition: PtrList.H:118
virtual dimensioned< Type > dimValue(const scalar x) const
Return dimensioned constant value.
Definition: TableBase.C:398
autoPtr< scalarField > tableSamplesPtr_
Extracted values.
Definition: TableBase.H:101
virtual dimensioned< Type > dimIntegrate(const scalar x1, const scalar x2) const
Integrate between two values and return dimensioned type.
Definition: TableBase.C:406