Polynomial.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-2020 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::Polynomial
26 
27 Description
28  Polynomial templated on size (order):
29 
30  \verbatim
31  poly = sum(coeffs[i]*x^i) + logCoeff*log(x)
32  \endverbatim
33 
34  where <tt> 0 <= i <= N </tt>
35 
36  - integer powers, starting at zero
37  - \c value(x) to evaluate the poly for a given value
38  - \c derivative(x) returns derivative at value
39  - \c integral(x1, x2) returns integral between two scalar values
40  - \c integral() to return a new, integral coeff polynomial
41  - increases the size (order)
42  - \c integralMinus1() to return a new, integral coeff polynomial where
43  the base poly starts at order -1
44 
45 SourceFiles
46  Polynomial.C
47 
48 \*---------------------------------------------------------------------------*/
49 
50 #ifndef Polynomial_H
51 #define Polynomial_H
52 
53 #include "word.H"
54 #include "scalar.H"
55 #include "Ostream.H"
56 #include "VectorSpace.H"
57 #include <type_traits>
58 
59 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 
61 namespace Foam
62 {
63 
64 // Forward declaration of classes
65 template<int PolySize>
66 class Polynomial;
67 
68 // Forward declaration of friend functions
69 template<int PolySize>
70 Ostream& operator<<
71 (
72  Ostream&,
74 );
75 
76 
77 /*---------------------------------------------------------------------------*\
78  Class Polynomial Declaration
79 \*---------------------------------------------------------------------------*/
80 
81 template<int PolySize>
82 class Polynomial
83 :
84  public VectorSpace<Polynomial<PolySize>, scalar, PolySize>
85 {
86  static_assert(PolySize > 0, "Size must be positive (non-zero)");
87 
88  // Private Data
89 
90  //- Include the log term? - only activated using integralMinus1()
91  bool logActive_;
92 
93  //- Log coefficient - only activated using integralMinus1()
94  scalar logCoeff_;
95 
96 
97 public:
98 
100 
102 
103 
104  // Constructors
105 
106  //- Construct null, with all coefficients = 0.0
107  Polynomial();
108 
109  //- Construct from C-array of coefficients
110  explicit Polynomial(const scalar coeffs[PolySize]);
111 
112  //- Construct from a list of coefficients
113  explicit Polynomial(const UList<scalar>& coeffs);
114 
115  //- Construct from Istream
117 
118  //- Construct from name and Istream
119  Polynomial(const word& name, Istream&);
120 
121 
122  // Member Functions
123 
124  // Access
125 
126  //- Return true if the log term is active
127  bool logActive() const;
128 
129  //- Return the log coefficient
130  scalar logCoeff() const;
131 
132 
133  // Evaluation
134 
135  //- Return polynomial value
136  scalar value(const scalar x) const;
137 
138  //- Return derivative of the polynomial at the given x
139  scalar derivative(const scalar x) const;
140 
141  //- Return integral between two values
142  scalar integral(const scalar x1, const scalar x2) const;
143 
144  //- Return integral coefficients.
145  // Argument becomes zero'th element (constant of integration)
146  intPolyType integral(const scalar intConstant = 0.0) const;
147 
148  //- Return integral coefficients when lowest order is -1.
149  // Argument becomes zero'th element (constant of integration)
150  polyType integralMinus1(const scalar intConstant = 0.0) const;
151 
152 
153  //- Ostream Operator
154  friend Ostream& operator<< <PolySize>
155  (
156  Ostream&,
157  const Polynomial&
158  );
159 };
160 
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 } // End namespace Foam
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 #ifdef NoRepository
169  #include "Polynomial.C"
170  #include "PolynomialIO.C"
171 #endif
172 
173 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174 
175 #endif
176 
177 // ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Polynomial templated on size (order):
Definition: Polynomial.H:84
scalar logCoeff() const
Return the log coefficient.
Definition: Polynomial.C:127
Polynomial()
Construct null, with all coefficients = 0.0.
Definition: Polynomial.C:31
Polynomial< PolySize+1 > intPolyType
Definition: Polynomial.H:100
scalar value(const scalar x) const
Return polynomial value.
Definition: Polynomial.C:134
scalar derivative(const scalar x) const
Return derivative of the polynomial at the given x.
Definition: Polynomial.C:155
bool logActive() const
Return true if the log term is active.
Definition: Polynomial.C:120
scalar integral(const scalar x1, const scalar x2) const
Return integral between two values.
Definition: Polynomial.C:182
polyType integralMinus1(const scalar intConstant=0.0) const
Return integral coefficients when lowest order is -1.
Definition: Polynomial.C:225
Polynomial< PolySize > polyType
Definition: Polynomial.H:98
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:74
Templated vector space.
Definition: VectorSpace.H:85
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39