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_;
109 
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 // ************************************************************************* //
Foam::TableBase::CLAMP
@ CLAMP
Definition: TableBase.H:76
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Foam::TableBase::x
virtual tmp< scalarField > x() const
Return the reference values.
Definition: TableBase.C:396
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::TableBase::y
virtual tmp< Field< Type > > y() const
Return the dependent values.
Definition: TableBase.C:411
Tuple2.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::TableBase::interpolatorPtr_
autoPtr< interpolationWeights > interpolatorPtr_
Interpolator method.
Definition: TableBase.H:104
Foam::TableBase::dimValue
virtual dimensioned< Type > dimValue(const scalar x) const
Return dimensioned constant value.
Definition: TableBase.C:374
Foam::bound
volScalarField & bound(volScalarField &, const dimensionedScalar &lowerBound)
Bound the given scalar field if it has gone unbounded.
Definition: bound.C:33
Foam::TableBase::writeEntries
virtual void writeEntries(Ostream &os) const
Write keywords only in dictionary format. Used for non-inline.
Definition: TableBaseIO.C:72
Foam::TableBase::currentIndices_
labelList currentIndices_
Cached indices and weights.
Definition: TableBase.H:107
Foam::TableBase::table_
List< Tuple2< scalar, Type > > table_
Table data.
Definition: TableBase.H:95
Foam::dimensionSet
Dimension set for the base types.
Definition: dimensionSet.H:116
Foam::TableBase::name_
const word name_
Table name.
Definition: TableBase.H:86
Foam::TableBase::boundsHandling
boundsHandling
Enumeration for handling out-of-bound values.
Definition: TableBase.H:72
Foam::TableBase::WARN
@ WARN
Definition: TableBase.H:75
Foam::TableBase::interpolationScheme_
const word interpolationScheme_
Interpolation type.
Definition: TableBase.H:92
Foam::TableBase::checkMinBounds
bool checkMinBounds(const scalar x, scalar &xDash) const
Check minimum table bounds.
Definition: TableBase.C:216
Foam::TableBase::integrate
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: TableBase.C:357
Foam::TableBase::writeData
virtual void writeData(Ostream &os) const
Write all table data in dictionary format.
Definition: TableBaseIO.C:63
DataEntry.H
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::TableBase::currentWeights_
scalarField currentWeights_
Definition: TableBase.H:109
Foam::TableBase::operator=
void operator=(const TableBase< Type > &)
Disallow default bitwise assignment.
Foam::TableBase::dimensions_
dimensionSet dimensions_
The dimension set.
Definition: TableBase.H:98
Foam::TableBase::REPEAT
@ REPEAT
Definition: TableBase.H:77
dimensionSet.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::TableBase::TableBase
TableBase(const word &name, const dictionary &dict)
Construct from dictionary - note table is not populated.
Definition: TableBase.C:58
Foam::TableBase::~TableBase
virtual ~TableBase()
Destructor.
Definition: TableBase.C:95
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::interpolationWeights
Abstract base class for interpolating in 1D.
Definition: interpolationWeights.H:55
Foam::dimensioned< Type >
Foam::TableBase::checkMaxBounds
bool checkMaxBounds(const scalar x, scalar &xDash) const
Check maximum table bounds.
Definition: TableBase.C:266
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::TableBase::tableSamplesPtr_
autoPtr< scalarField > tableSamplesPtr_
Extracted values.
Definition: TableBase.H:101
Foam::TableBase::outOfBounds
boundsHandling outOfBounds(const boundsHandling &bound)
Set the out-of-bounds handling from enum, return previous setting.
Definition: TableBase.C:174
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::List
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
Foam::TableBase::boundsHandlingToWord
word boundsHandlingToWord(const boundsHandling &bound) const
Return the out-of-bounds handling as a word.
Definition: TableBase.C:103
TableBase.C
Foam::TableBase::value
virtual Type value(const scalar x) const
Return Table value.
Definition: TableBase.C:329
Foam::TableBase::check
void check() const
Check the table for size and consistency.
Definition: TableBase.C:186
Foam::TableBase::ERROR
@ ERROR
Definition: TableBase.H:74
Foam::TableBase::wordToBoundsHandling
boundsHandling wordToBoundsHandling(const word &bound) const
Return the out-of-bounds handling as an enumeration.
Definition: TableBase.C:140
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::TableBase::convertTimeBase
virtual void convertTimeBase(const Time &t)
Convert time.
Definition: TableBase.C:315
Foam::TableBase::dimIntegrate
virtual dimensioned< Type > dimIntegrate(const scalar x1, const scalar x2) const
Integrate between two values and return dimensioned type.
Definition: TableBase.C:382
Foam::TableBase::interpolator
const interpolationWeights & interpolator() const
Return (demand driven) interpolator.
Definition: TableBase.C:33
Foam::TableBase::boundsHandling_
const boundsHandling boundsHandling_
Enumeration for handling out-of-bound values.
Definition: TableBase.H:89
Foam::DataEntry
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: DataEntry.H:52
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::TableBase
Base class for table with bounds handling, interpolation and integration.
Definition: TableBase.H:47