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-2018 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 
102 
103 
104  // Constructors
105 
106  //- Construct null, with all coefficients = 0.0
107  Polynomial();
108 
109  //- Copy constructor
110  Polynomial(const Polynomial&);
111 
112  //- Construct from C-array of coefficients
113  explicit Polynomial(const scalar coeffs[PolySize]);
114 
115  //- Construct from a list of coefficients
116  explicit Polynomial(const UList<scalar>& coeffs);
117 
118  //- Construct from Istream
120 
121  //- Construct from name and Istream
122  Polynomial(const word& name, Istream&);
123 
124 
125  // Member Functions
126 
127  // Access
128 
129  //- Return true if the log term is active
130  bool logActive() const;
131 
132  //- Return the log coefficient
133  scalar logCoeff() const;
134 
135 
136  // Evaluation
137 
138  //- Return polynomial value
139  scalar value(const scalar x) const;
140 
141  //- Return derivative of the polynomial at the given x
142  scalar derivative(const scalar x) const;
143 
144  //- Return integral between two values
145  scalar integral(const scalar x1, const scalar x2) const;
146 
147  //- Return integral coefficients.
148  // Argument becomes zero'th element (constant of integration)
149  intPolyType integral(const scalar intConstant = 0.0) const;
150 
151  //- Return integral coefficients when lowest order is -1.
152  // Argument becomes zero'th element (constant of integration)
153  polyType integralMinus1(const scalar intConstant = 0.0) const;
154 
155 
156  //- Ostream Operator
157  friend Ostream& operator<< <PolySize>
158  (
159  Ostream&,
160  const Polynomial&
161  );
162 };
163 
164 
165 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
166 
167 } // End namespace Foam
168 
169 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
170 
171 #ifdef NoRepository
172  #include "Polynomial.C"
173  #include "PolynomialIO.C"
174 #endif
175 
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 
178 #endif
179 
180 // ************************************************************************* //
Polynomial< PolySize+1 > intPolyType
Definition: Polynomial.H:100
bool logActive() const
Return true if the log term is active.
Definition: Polynomial.C:132
Polynomial< PolySize > polyType
Definition: Polynomial.H:98
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Templated vector space.
Definition: VectorSpace.H:53
scalar integral(const scalar x1, const scalar x2) const
Return integral between two values.
Definition: Polynomial.C:196
Polynomial()
Construct null, with all coefficients = 0.0.
Definition: Polynomial.C:31
A class for handling words, derived from string.
Definition: word.H:59
scalar value(const scalar x) const
Return polynomial value.
Definition: Polynomial.C:146
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:61
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Polynomial templated on size (order):
Definition: Polynomial.H:65
scalar logCoeff() const
Return the log coefficient.
Definition: Polynomial.C:139
polyType integralMinus1(const scalar intConstant=0.0) const
Return integral coefficients when lowest order is -1.
Definition: Polynomial.C:240
scalar derivative(const scalar x) const
Return derivative of the polynomial at the given x.
Definition: Polynomial.C:168
Namespace for OpenFOAM.