TableBase.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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 
108 private:
109 
110  //- Disallow default bitwise assignment
111  void operator=(const TableBase<Type>&) = delete;
112 
113 
114 public:
115 
116  // Constructors
117 
118  //- Construct from dictionary - note table is not populated
119  TableBase(const word& name, const dictionary& dict);
120 
121  //- Copy constructor. Note: steals interpolator, tableSamples
122  TableBase(const TableBase<Type>& tbl);
123 
124 
125  //- Destructor
126  virtual ~TableBase();
127 
128 
129  // Member Functions
130 
131  //- Return the out-of-bounds handling as a word
133 
134  //- Return the out-of-bounds handling as an enumeration
136 
137  //- Set the out-of-bounds handling from enum, return previous setting
139 
140  //- Check the table for size and consistency
141  void check() const;
142 
143  //- Check minimum table bounds
144  bool checkMinBounds(const scalar x, scalar& xDash) const;
145 
146  //- Check maximum table bounds
147  bool checkMaxBounds(const scalar x, scalar& xDash) const;
148 
149  //- Convert time
150  virtual void convertTimeBase(const Time& t);
151 
152  //- Return Table value
153  virtual Type value(const scalar x) const;
154 
155  //- Integrate between two (scalar) values
156  virtual Type integrate(const scalar x1, const scalar x2) const;
157 
158  //- Return the reference values
159  virtual tmp<scalarField> x() const;
160 
161  //- Return the dependent values
162  virtual tmp<Field<Type>> y() const;
163 
164  //- Write all table data in dictionary format
165  virtual void writeData(Ostream& os) const;
166 
167  //- Write keywords only in dictionary format. Used for non-inline
168  // table types
169  virtual void writeEntries(Ostream& os) const;
170 };
171 
172 
173 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174 
175 } // End namespace Function1Types
176 } // End namespace Foam
177 
178 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 
180 #ifdef NoRepository
181  #include "TableBase.C"
182 #endif
183 
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 
186 #endif
187 
188 // ************************************************************************* //
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
boundsHandling outOfBounds(const boundsHandling &bound)
Set the out-of-bounds handling from enum, return previous setting.
Definition: TableBase.C:177
const word const dictionary & dict
Definition: Function1.H:85
TableBase(const word &name, const dictionary &dict)
Construct from dictionary - note table is not populated.
Definition: TableBase.C:60
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:158
const interpolationWeights & interpolator() const
Return (demand driven) interpolator.
Definition: TableBase.C:34
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
const word & name() const
Return the name of the entry.
Definition: Function1.C:56
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
virtual ~TableBase()
Destructor.
Definition: TableBase.C:98
boundsHandling wordToBoundsHandling(const word &bound) const
Return the out-of-bounds handling as an enumeration.
Definition: TableBase.C:143
Treat as a repeating list.
Definition: TableBase.H:69
Base class for table with bounds handling, interpolation and integration.
Definition: TableBase.H:55
const word name_
Table name.
Definition: TableBase.H:78
A class for handling words, derived from string.
Definition: word.H:59
virtual Type value(const scalar x) const
Return Table value.
Definition: TableBase.C:334
bool checkMinBounds(const scalar x, scalar &xDash) const
Check minimum table bounds.
Definition: TableBase.C:219
void check() const
Check the table for size and consistency.
Definition: TableBase.C:189
virtual tmp< scalarField > x() const
Return the reference values.
Definition: TableBase.C:382
word boundsHandlingToWord(const boundsHandling &bound) const
Return the out-of-bounds handling as a word.
Definition: TableBase.C:106
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: TableBase.C:363
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
virtual tmp< Field< Type > > y() const
Return the dependent values.
Definition: TableBase.C:397
const word interpolationScheme_
Interpolation type.
Definition: TableBase.H:84
virtual void convertTimeBase(const Time &t)
Convert time.
Definition: TableBase.C:320
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
bool checkMaxBounds(const scalar x, scalar &xDash) const
Check maximum table bounds.
Definition: TableBase.C:270
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
A class for managing temporary objects.
Definition: PtrList.H:53
virtual void writeData(Ostream &os) const
Write all table data in dictionary format.
Definition: TableBase.C:426
Clamp value to the start/end value.
Definition: TableBase.H:68
boundsHandling
Enumeration for handling out-of-bound values.
Definition: TableBase.H:64
virtual void writeEntries(Ostream &os) const
Write keywords only in dictionary format. Used for non-inline.
Definition: TableBase.C:412
Namespace for OpenFOAM.