PolynomialEntry.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-2017 OpenFOAM Foundation
9  Copyright (C) 2021-2024 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::PolynomialEntry
29 
30 Description
31  PolynomialEntry container data entry for scalars. Items are stored in a
32  list of Tuple2's. Data is input in the form,
33  e.g. for an entry <entryName> that describes y = x^2 + 2x^3
34 
35  Inline specification:
36  \verbatim
37  <entryName> polynomial
38  (
39  (1 2)
40  (2 3)
41  );
42  \endverbatim
43 
44  Dictionary format:
45  \verbatim
46  <entryName>
47  {
48  type polynomial;
49  coeffs
50  (
51  (1 2)
52  (2 3)
53  );
54  }
55  \endverbatim
56 
57 SourceFiles
58  PolynomialEntry.C
59 
60 \*---------------------------------------------------------------------------*/
61 
62 #ifndef Foam_Function1Types_Polynomial_H
63 #define Foam_Function1Types_Polynomial_H
64 
65 #include "Function1.H"
66 #include "Tuple2.H"
67 #include "Function1Fwd.H"
68 
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 
71 namespace Foam
72 {
73 namespace Function1Types
74 {
75 
76 /*---------------------------------------------------------------------------*\
77  Class Polynomial Declaration
78 \*---------------------------------------------------------------------------*/
79 
80 template<class Type>
81 class Polynomial
82 :
83  public Function1<Type>
84 {
85  // Private Data
86 
87  //- Polynomial coefficients - list of prefactor, exponent
88  List<Tuple2<Type, Type>> coeffs_;
89 
90  //- Flag to indicate whether polynomial can be integrated
91  bool canIntegrate_;
92 
93 
94  // Private Member Functions
95 
96  //- Check coefficients and if polynomial can be integrated
97  void checkCoefficients();
98 
99  //- No copy assignment
100  void operator=(const Polynomial<Type>&) = delete;
101 
102 
103 public:
104 
105  //- Runtime type information
106  TypeName("polynomial");
107 
108 
109  // Constructors
110 
111  //- Construct from entry name, dictionary and optional registry
112  Polynomial
113  (
114  const word& entryName,
115  const dictionary& dict,
116  const objectRegistry* obrPtr = nullptr
117  );
118 
119  //- Construct from components
120  Polynomial
121  (
122  const word& entryName,
123  const List<Tuple2<Type, Type>>& coeffs,
124  const objectRegistry* obrPtr = nullptr
125  );
126 
127  //- Copy constructor
128  explicit Polynomial(const Polynomial& poly);
129 
130  //- Return a clone
131  virtual tmp<Function1<Type>> clone() const
132  {
133  return Function1<Type>::Clone(*this);
134  }
135 
136 
137  //- Destructor
138  virtual ~Polynomial() = default;
139 
140 
141  // Member Functions
142 
143  //- Convert time
144  virtual void userTimeToTime(const Time& t);
145 
146  //- Return Polynomial value
147  virtual Type value(const scalar x) const;
148 
149  //- Integrate between two (scalar) values
150  virtual Type integrate(const scalar x1, const scalar x2) const;
151 
152  //- Write as primitive (inline) format
153  virtual void writeData(Ostream& os) const;
154 };
155 
156 
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 
159 } // End namespace Function1Types
160 } // End namespace Foam
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 #ifdef NoRepository
165  #include "PolynomialEntry.C"
166 #endif
167 
168 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169 
170 #endif
171 
172 // ************************************************************************* //
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
Polynomial(const word &entryName, const dictionary &dict, const objectRegistry *obrPtr=nullptr)
Construct from entry name, dictionary and optional registry.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:54
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
const word & entryName
Definition: Function1.H:140
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
static tmp< Function1< Type > > Clone(const Derived &fun)
Clone a Function1.
Definition: Function1.H:190
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual ~Polynomial()=default
Destructor.
virtual void userTimeToTime(const Time &t)
Convert time.
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
const word const dictionary const objectRegistry * obrPtr
Definition: Function1.H:140
virtual tmp< Function1< Type > > clone() const
Return a clone.
TypeName("polynomial")
Runtime type information.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Registry of regIOobjects.
Namespace for OpenFOAM.
virtual void writeData(Ostream &os) const
Write as primitive (inline) format.
virtual Type value(const scalar x) const
Return Polynomial value.