All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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::Function1s::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 "tableBase.H"
39 #include "Function1.H"
40 #include "Tuple2.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 class interpolationWeights;
48 
49 namespace Function1s
50 {
51 
52 /*---------------------------------------------------------------------------*\
53  Class TableBase Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 template<class Type, class Function1Type>
57 class TableBase
58 :
59  public tableBase,
60  public FieldFunction1<Type, Function1Type>
61 {
62 protected:
63 
64  // Protected data
65 
66  //- Table name
67  const word name_;
68 
69  //- Enumeration for handling out-of-bound values
71 
72  //- Interpolation type
74 
75  //- Table data
77 
78  //- Extracted values
80 
81  //- Interpolator method
83 
84  //- Cached indices
85  mutable labelList indices_;
86 
87  //- Cached weights
88  mutable scalarField weights_;
89 
90 
91  // Protected Member Functions
92 
93  //- Return (demand driven) interpolator
94  const interpolationWeights& interpolator() const;
95 
96  //- Check the table for size and consistency
97  void check() const;
98 
99  //- Bound the argument to the table. Errors or warns, or shifts the
100  // value if the table repeats. Does not clamp to the ends of the table
101  // as the interpolator already performs that function.
102  scalar bound(const scalar x) const;
103 
104 
105 public:
106 
107  // Constructors
108 
109  //- Construct from dictionary. Table is not populated.
110  TableBase(const word& name, const dictionary& dict);
111 
112  //- Construct from components
113  TableBase
114  (
115  const word& name,
117  const word& interpolationScheme,
118  const List<Tuple2<scalar, Type>>& table
119  );
120 
121  //- Copy constructor. Note: Steals interpolator and tableSamples.
123 
124 
125  //- Destructor
126  virtual ~TableBase();
127 
128 
129  // Member Functions
130 
131  //- Return Table value
132  virtual Type value(const scalar x) const;
133 
134  //- Integrate between two (scalar) values
135  virtual Type integrate(const scalar x1, const scalar x2) const;
136 
137  //- Return the reference values
138  virtual tmp<scalarField> x() const;
139 
140  //- Return the dependent values
141  virtual tmp<Field<Type>> y() const;
142 
143  //- Write entries only in dictionary format
144  virtual void writeEntries(Ostream& os) const;
145 
146  //- Write all table data in dictionary format
147  virtual void writeData(Ostream& os) const;
148 
149 
150  // Member Operators
151 
152  //- Disallow default bitwise assignment
153  void operator=(const TableBase<Type, Function1Type>&) = delete;
154 };
155 
156 
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 
159 } // End namespace Function1s
160 } // End namespace Foam
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 #ifdef NoRepository
165  #include "TableBase.C"
166 #endif
167 
168 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169 
170 #endif
171 
172 // ************************************************************************* //
labelList indices_
Cached indices.
Definition: TableBase.H:84
void operator=(const TableBase< Type, Function1Type > &)=delete
Disallow default bitwise assignment.
const word const dictionary & dict
Definition: Function1.H:84
List< Tuple2< scalar, Type > > table_
Table data.
Definition: TableBase.H:75
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
A 2-tuple for storing two objects of different types.
Definition: HashTable.H:65
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
const word & name() const
Return the name of the entry.
Definition: Function1.C:91
virtual Type value(const scalar x) const
Return Table value.
Definition: TableBase.C:210
Abstract base class for interpolating in 1D.
const word interpolationScheme_
Interpolation type.
Definition: TableBase.H:72
const tableBase::boundsHandling boundsHandling_
Enumeration for handling out-of-bound values.
Definition: TableBase.H:69
scalarField weights_
Cached weights.
Definition: TableBase.H:87
A class for handling words, derived from string.
Definition: word.H:59
scalar bound(const scalar x) const
Bound the argument to the table. Errors or warns, or shifts the.
Definition: TableBase.C:87
virtual ~TableBase()
Destructor.
Definition: TableBase.C:202
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: TableBase.C:230
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
boundsHandling
Enumeration for handling out-of-bound values.
Definition: tableBase.H:54
const word name_
Table name.
Definition: TableBase.H:66
virtual tmp< Field< Type > > y() const
Return the dependent values.
Definition: TableBase.C:288
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
TableBase(const word &name, const dictionary &dict)
Construct from dictionary. Table is not populated.
Definition: TableBase.C:138
virtual tmp< scalarField > x() const
Return the reference values.
Definition: TableBase.C:272
A class for managing temporary objects.
Definition: PtrList.H:53
const interpolationWeights & interpolator() const
Return (demand driven) interpolator.
Definition: TableBase.C:34
autoPtr< interpolationWeights > interpolatorPtr_
Interpolator method.
Definition: TableBase.H:81
virtual void writeEntries(Ostream &os) const
Write entries only in dictionary format.
Definition: TableBase.C:304
autoPtr< scalarField > tableSamplesPtr_
Extracted values.
Definition: TableBase.H:78
Base class for table with bounds handling, interpolation and integration.
Definition: TableBase.H:56
virtual void writeData(Ostream &os) const
Write all table data in dictionary format.
Definition: TableBase.C:328
void check() const
Check the table for size and consistency.
Definition: TableBase.C:57
Namespace for OpenFOAM.