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-2012 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 "StaticAssert.H"
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  //- Size must be positive (non-zero)
85  StaticAssert(PolySize > 0);
86 
87  // Private data
88 
89  //- Include the log term? - only activated using integralMinus1()
90  bool logActive_;
91 
92  //- Log coefficient - only activated using integralMinus1()
93  scalar logCoeff_;
94 
95 
96 public:
97 
99 
101 
102 
103  // Constructors
104 
105  //- Construct null, with all coefficients = 0.0
106  Polynomial();
107 
108  //- Copy constructor
109  Polynomial(const Polynomial&);
110 
111  //- Construct from C-array of coefficients
112  explicit Polynomial(const scalar coeffs[PolySize]);
113 
114  //- Construct from a list of coefficients
115  explicit Polynomial(const UList<scalar>& coeffs);
116 
117  //- Construct from Istream
119 
120  //- Construct from name and Istream
121  Polynomial(const word& name, Istream&);
122 
123 
124  // Member Functions
125 
126  // Access
127 
128  //- Return true if the log term is active
129  bool logActive() const;
130 
131  //- Return the log coefficient
132  scalar logCoeff() const;
133 
134 
135  // Evaluation
136 
137  //- Return polynomial value
138  scalar value(const scalar x) const;
139 
140  //- Return derivative of the polynomial at the given x
141  scalar derivative(const scalar x) const;
142 
143  //- Return integral between two values
144  scalar integral(const scalar x1, const scalar x2) const;
145 
146  //- Return integral coefficients.
147  // Argument becomes zero'th element (constant of integration)
148  intPolyType integral(const scalar intConstant = 0.0) const;
149 
150  //- Return integral coefficients when lowest order is -1.
151  // Argument becomes zero'th element (constant of integration)
152  polyType integralMinus1(const scalar intConstant = 0.0) const;
153 
154 
155  //- Ostream Operator
156  friend Ostream& operator<< <PolySize>
157  (
158  Ostream&,
159  const Polynomial&
160  );
161 };
162 
163 
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165 
166 } // End namespace Foam
167 
168 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169 
170 #ifdef NoRepository
171 # include "Polynomial.C"
172 # include "PolynomialIO.C"
173 #endif
174 
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 
177 #endif
178 
179 // ************************************************************************* //
Polynomial()
Construct null, with all coefficients = 0.0.
Definition: Polynomial.C:31
Templated vector space.
Definition: VectorSpace.H:52
scalar integral(const scalar x1, const scalar x2) const
Return integral between two values.
Definition: Polynomial.C:202
Polynomial< PolySize > polyType
Definition: Polynomial.H:97
Polynomial< PolySize+1 > intPolyType
Definition: Polynomial.H:99
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
Polynomial templated on size (order):
Definition: Polynomial.H:63
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
scalar derivative(const scalar x) const
Return derivative of the polynomial at the given x.
Definition: Polynomial.C:174
scalar logCoeff() const
Return the log coefficient.
Definition: Polynomial.C:145
A class for handling words, derived from string.
Definition: word.H:59
scalar value(const scalar x) const
Return polynomial value.
Definition: Polynomial.C:152
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
polyType integralMinus1(const scalar intConstant=0.0) const
Return integral coefficients when lowest order is -1.
Definition: Polynomial.C:246
bool logActive() const
Return true if the log term is active.
Definition: Polynomial.C:138