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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2020 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::Polynomial
29 
30 Description
31  Polynomial templated on size (order):
32 
33  \verbatim
34  poly = sum(coeffs[i]*x^i) + logCoeff*log(x)
35  \endverbatim
36 
37  where <tt> 0 <= i <= N </tt>
38 
39  - integer powers, starting at zero
40  - \c value(x) to evaluate the poly for a given value
41  - \c derivative(x) returns derivative at value
42  - \c integral(x1, x2) returns integral between two scalar values
43  - \c integral() to return a new, integral coeff polynomial
44  - increases the size (order)
45  - \c integralMinus1() to return a new, integral coeff polynomial where
46  the base poly starts at order -1
47 
48 SourceFiles
49  Polynomial.C
50 
51 \*---------------------------------------------------------------------------*/
52 
53 #ifndef Polynomial_H
54 #define Polynomial_H
55 
56 #include "word.H"
57 #include "scalar.H"
58 #include "Ostream.H"
59 #include "VectorSpace.H"
60 #include <initializer_list>
61 #include <type_traits>
62 
63 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
64 
65 namespace Foam
66 {
67 
68 // Forward Declarations
69 template<int PolySize> class Polynomial;
70 
71 /*---------------------------------------------------------------------------*\
72  Class Polynomial Declaration
73 \*---------------------------------------------------------------------------*/
74 
75 template<int PolySize>
76 class Polynomial
77 :
78  public VectorSpace<Polynomial<PolySize>, scalar, PolySize>
79 {
80  static_assert(PolySize > 0, "Size must be positive (non-zero)");
81 
82  // Private Data
83 
84  //- Include the log term? - only activated using integralMinus1()
85  bool logActive_;
86 
87  //- Log coefficient - only activated using integralMinus1()
88  scalar logCoeff_;
89 
90 
91 public:
92 
93  // Public Typedefs
94 
97 
98 
99  // Generated Methods: copy construct, copy assignment
100 
101 
102  // Constructors
103 
104  //- Default construct, with all coefficients = 0
105  Polynomial();
106 
107  //- Construct from an initializer list of coefficients
108  Polynomial(std::initializer_list<scalar> coeffs);
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
117  explicit Polynomial(Istream& is);
118 
119  //- Construct from name and Istream
120  Polynomial(const word& name, Istream& is);
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  // IOstream Operators - uses VectorSpace operators
155 };
156 
157 
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 
160 } // End namespace Foam
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 #ifdef NoRepository
165  #include "Polynomial.C"
166 #endif
167 
168 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169 
170 #endif
171 
172 // ************************************************************************* //
VectorSpace.H
Foam::Polynomial::integralMinus1
polyType integralMinus1(const scalar intConstant=0.0) const
Return integral coefficients when lowest order is -1.
Definition: Polynomial.C:246
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::Polynomial::polyType
Polynomial< PolySize > polyType
Definition: Polynomial.H:94
Foam::Polynomial::derivative
scalar derivative(const scalar x) const
Return derivative of the polynomial at the given x.
Definition: Polynomial.C:174
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:56
Foam::Polynomial::integral
scalar integral(const scalar x1, const scalar x2) const
Return integral between two values.
Definition: Polynomial.C:202
Foam::Polynomial::intPolyType
Polynomial< PolySize+1 > intPolyType
Definition: Polynomial.H:95
Foam::Polynomial::Polynomial
Polynomial()
Default construct, with all coefficients = 0.
Definition: Polynomial.C:34
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::Polynomial::logActive
bool logActive() const
Return true if the log term is active.
Definition: Polynomial.C:138
Foam::Polynomial::value
scalar value(const scalar x) const
Return polynomial value.
Definition: Polynomial.C:152
scalar.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Ostream.H
Foam::Polynomial
Polynomial templated on size (order):
Definition: Polynomial.H:68
Foam::Polynomial::logCoeff
scalar logCoeff() const
Return the log coefficient.
Definition: Polynomial.C:145
Foam::UList
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:103
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
word.H
Polynomial.C