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