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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2020-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::Function1Types::TableBase
29 
30 Description
31  Base class for table with bounds handling, interpolation and integration
32 
33 SourceFiles
34  TableBase.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Function1Types_TableBase_H
39 #define Function1Types_TableBase_H
40 
41 #include "tableBounds.H"
42 #include "Function1.H"
43 #include "Tuple2.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // Forward Declarations
51 class interpolationWeights;
52 
53 namespace Function1Types
54 {
55 
56 /*---------------------------------------------------------------------------*\
57  Class TableBase Declaration
58 \*---------------------------------------------------------------------------*/
59 
60 template<class Type>
61 class TableBase
62 :
63  public Function1<Type>
64 {
65 protected:
66 
67  // Protected Data
68 
69  //- Handling for out-of-bound values
71 
72  //- Interpolation type
74 
75  //- Table data
77 
78  //- Extracted values
80 
81  //- Interpolator method
83 
84  //- Cached indices and weights
85  mutable labelList currentIndices_;
86 
88 
89 
90  // Protected Member Functions
91 
92  //- Return (demand driven) interpolator
93  const interpolationWeights& interpolator() const;
94 
95  //- No copy assignment
96  void operator=(const TableBase<Type>&) = delete;
97 
98 
99 public:
100 
101  // Constructors
102 
103  //- Construct from dictionary - note table is not populated
104  TableBase
105  (
106  const word& name,
107  const dictionary& dict,
108  const objectRegistry* obrPtr = nullptr
109  );
110 
111  //- Copy constructor. Note: steals interpolator, tableSamples
112  explicit TableBase(const TableBase<Type>& tbl);
113 
114 
115  //- Destructor
116  virtual ~TableBase() = default;
117 
118 
119  // Member Functions
120 
121  //- Check the table for size and consistency
122  void initialise();
123 
124  //- Check minimum table bounds
125  bool checkMinBounds(const scalar x, scalar& xDash) const;
126 
127  //- Check maximum table bounds
128  bool checkMaxBounds(const scalar x, scalar& xDash) const;
129 
130  //- Convert time
131  virtual void userTimeToTime(const Time& t);
132 
133  //- Return Table value
134  virtual Type value(const scalar x) const;
135 
136  //- Integrate between two (scalar) values
137  virtual Type integrate(const scalar x1, const scalar x2) const;
138 
139  //- Return the reference values
140  virtual tmp<scalarField> x() const;
141 
142  //- Return the dependent values
143  virtual tmp<Field<Type>> y() const;
144 
145  //- Write all table data in dictionary format
146  virtual void writeData(Ostream& os) const;
147 
148  //- Write keywords only in dictionary format.
149  // Used for non-inline table types
150  virtual void writeEntries(Ostream& os) const;
151 };
152 
153 
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 
156 } // End namespace Function1Types
157 } // End namespace Foam
158 
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 
161 #ifdef NoRepository
162  #include "TableBase.C"
163 #endif
164 
165 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
166 
167 #endif
168 
169 // ************************************************************************* //
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
const word const dictionary & dict
Definition: Function1.H:140
List< Tuple2< scalar, Type > > table_
Table data.
Definition: TableBase.H:77
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
const interpolationWeights & interpolator() const
Return (demand driven) interpolator.
Definition: TableBase.C:30
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
autoPtr< interpolationWeights > interpolatorPtr_
Interpolator method.
Definition: TableBase.H:87
const bounds::repeatableBounding bounding_
Handling for out-of-bound values.
Definition: TableBase.H:67
repeatableBounding
Enumeration for handling out-of-bound values that are repeatable.
Definition: tableBounds.H:61
Abstract base class for interpolating in 1D.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Base class for table with bounds handling, interpolation and integration.
Definition: TableBase.H:56
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual Type value(const scalar x) const
Return Table value.
Definition: TableBase.C:263
bool checkMinBounds(const scalar x, scalar &xDash) const
Check minimum table bounds.
Definition: TableBase.C:135
virtual tmp< scalarField > x() const
Return the reference values.
Definition: TableBase.C:311
void initialise()
Check the table for size and consistency.
Definition: TableBase.C:103
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: TableBase.C:292
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
virtual tmp< Field< Type > > y() const
Return the dependent values.
Definition: TableBase.C:326
TableBase(const word &name, const dictionary &dict, const objectRegistry *obrPtr=nullptr)
Construct from dictionary - note table is not populated.
Definition: TableBase.C:56
OBJstream os(runTime.globalPath()/outputName)
virtual void userTimeToTime(const Time &t)
Convert time.
Definition: TableBase.C:250
const word interpolationScheme_
Interpolation type.
Definition: TableBase.H:72
const word const dictionary const objectRegistry * obrPtr
Definition: Function1.H:140
autoPtr< scalarField > tableSamplesPtr_
Extracted values.
Definition: TableBase.H:82
labelList currentIndices_
Cached indices and weights.
Definition: TableBase.H:92
void operator=(const TableBase< Type > &)=delete
No copy assignment.
bool checkMaxBounds(const scalar x, scalar &xDash) const
Check maximum table bounds.
Definition: TableBase.C:193
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Registry of regIOobjects.
virtual void writeData(Ostream &os) const
Write all table data in dictionary format.
Definition: TableBase.C:362
virtual ~TableBase()=default
Destructor.
virtual void writeEntries(Ostream &os) const
Write keywords only in dictionary format.
Definition: TableBase.C:341
Namespace for OpenFOAM.
const word & name() const noexcept
The name of the entry.