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-2016 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::Function1Types::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 "Function1.H"
39 #include "Tuple2.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 class interpolationWeights;
47 
48 namespace Function1Types
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class TableBase Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 template<class Type>
56 class TableBase
57 :
58  public Function1<Type>
59 {
60 public:
61 
62  // Public data types
63 
64  //- Enumeration for handling out-of-bound values
65  enum boundsHandling
66  {
68  WARN,
70  REPEAT
71  };
72 
73 
74 protected:
75 
76  // Protected data
77 
78  //- Table name
79  const word name_;
80 
81  //- Enumeration for handling out-of-bound values
83 
84  //- Interpolation type
86 
87  //- Table data
89 
90  //- Extracted values
92 
93  //- Interpolator method
95 
96  //- Cached indices and weights
97  mutable labelList currentIndices_;
98 
100 
101 
102  // Protected Member Functions
103 
104  //- Return (demand driven) interpolator
105  const interpolationWeights& interpolator() const;
106 
107  //- Disallow default bitwise assignment
108  void operator=(const TableBase<Type>&);
109 
110 
111 public:
112 
113  // Constructors
114 
115  //- Construct from dictionary - note table is not populated
116  TableBase(const word& name, const dictionary& dict);
117 
118  //- Copy constructor. Note: steals interpolator, tableSamples
119  TableBase(const TableBase<Type>& tbl);
120 
121 
122  //- Destructor
123  virtual ~TableBase();
124 
125 
126  // Member Functions
127 
128  //- Return the out-of-bounds handling as a word
130 
131  //- Return the out-of-bounds handling as an enumeration
133 
134  //- Set the out-of-bounds handling from enum, return previous setting
136 
137  //- Check the table for size and consistency
138  void check() const;
139 
140  //- Check minimum table bounds
141  bool checkMinBounds(const scalar x, scalar& xDash) const;
142 
143  //- Check maximum table bounds
144  bool checkMaxBounds(const scalar x, scalar& xDash) const;
145 
146  //- Convert time
147  virtual void convertTimeBase(const Time& t);
148 
149  //- Return Table value
150  virtual Type value(const scalar x) const;
151 
152  //- Integrate between two (scalar) values
153  virtual Type integrate(const scalar x1, const scalar x2) const;
154 
155  //- Return the reference values
156  virtual tmp<scalarField> x() const;
157 
158  //- Return the dependent values
159  virtual tmp<Field<Type>> y() const;
160 
161  //- Write all table data in dictionary format
162  virtual void writeData(Ostream& os) const;
163 
164  //- Write keywords only in dictionary format. Used for non-inline
165  // table types
166  virtual void writeEntries(Ostream& os) const;
167 };
168 
169 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 
172 } // End namespace Function1Types
173 } // End namespace Foam
174 
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 
177 #ifdef NoRepository
178  #include "TableBase.C"
179 #endif
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 #endif
184 
185 // ************************************************************************* //
Issue warning and clamp value (default)
Definition: TableBase.H:67
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:53
virtual Type value(const scalar x) const
Return Table value.
Definition: TableBase.C:332
bool checkMinBounds(const scalar x, scalar &xDash) const
Check minimum table bounds.
Definition: TableBase.C:219
boundsHandling wordToBoundsHandling(const word &bound) const
Return the out-of-bounds handling as an enumeration.
Definition: TableBase.C:143
boundsHandling outOfBounds(const boundsHandling &bound)
Set the out-of-bounds handling from enum, return previous setting.
Definition: TableBase.C:177
const word & name() const
Return the name of the entry.
Definition: Function1.C:56
const word const dictionary & dict
Definition: Function1.H:88
TableBase(const word &name, const dictionary &dict)
Construct from dictionary - note table is not populated.
Definition: TableBase.C:60
virtual void writeEntries(Ostream &os) const
Write keywords only in dictionary format. Used for non-inline.
Definition: TableBase.C:410
List< Tuple2< scalar, Type > > table_
Table data.
Definition: TableBase.H:87
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
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
Exit with a FatalError.
Definition: TableBase.H:66
void operator=(const TableBase< Type > &)
Disallow default bitwise assignment.
autoPtr< interpolationWeights > interpolatorPtr_
Interpolator method.
Definition: TableBase.H:93
Abstract base class for interpolating in 1D.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
word boundsHandlingToWord(const boundsHandling &bound) const
Return the out-of-bounds handling as a word.
Definition: TableBase.C:106
virtual ~TableBase()
Destructor.
Definition: TableBase.C:98
Treat as a repeating list.
Definition: TableBase.H:69
Base class for table with bounds handling, interpolation and integration.
Definition: TableBase.H:55
bool checkMaxBounds(const scalar x, scalar &xDash) const
Check maximum table bounds.
Definition: TableBase.C:269
const word name_
Table name.
Definition: TableBase.H:78
A class for handling words, derived from string.
Definition: word.H:59
const interpolationWeights & interpolator() const
Return (demand driven) interpolator.
Definition: TableBase.C:34
virtual tmp< scalarField > x() const
Return the reference values.
Definition: TableBase.C:380
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: TableBase.C:361
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void check() const
Check the table for size and consistency.
Definition: TableBase.C:189
virtual tmp< Field< Type > > y() const
Return the dependent values.
Definition: TableBase.C:395
const word interpolationScheme_
Interpolation type.
Definition: TableBase.H:84
virtual void convertTimeBase(const Time &t)
Convert time.
Definition: TableBase.C:318
autoPtr< scalarField > tableSamplesPtr_
Extracted values.
Definition: TableBase.H:90
const boundsHandling boundsHandling_
Enumeration for handling out-of-bound values.
Definition: TableBase.H:81
labelList currentIndices_
Cached indices and weights.
Definition: TableBase.H:96
volScalarField & bound(volScalarField &, const dimensionedScalar &lowerBound)
Bound the given scalar field if it has gone unbounded.
Definition: bound.C:33
virtual void writeData(Ostream &os) const
Write all table data in dictionary format.
Definition: TableBase.C:426
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
A class for managing temporary objects.
Definition: PtrList.H:54
Clamp value to the start/end value.
Definition: TableBase.H:68
boundsHandling
Enumeration for handling out-of-bound values.
Definition: TableBase.H:64
Namespace for OpenFOAM.