Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::Polynomial
29
30Description
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
48SourceFiles
49 Polynomial.C
50
51\*---------------------------------------------------------------------------*/
52
53#ifndef Foam_Polynomial_H
54#define Foam_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
65namespace Foam
66{
67
68// Forward Declarations
69template<int PolySize> class Polynomial;
70
71/*---------------------------------------------------------------------------*\
72 Class Polynomial Declaration
73\*---------------------------------------------------------------------------*/
74
75template<int PolySize>
76class 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
91public:
92
93 // Public Typedefs
97
98
99 // Generated Methods: copy construct, copy assignment
100
101
102 // Constructors
103
104 //- Default construct, with all coefficients = 0
105 Polynomial();
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);
122
123 // Member Functions
124
125 // Access
127 //- Return true if the log term is active
128 bool logActive() const noexcept;
129
130 //- Return the log coefficient
131 scalar logCoeff() const noexcept;
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;
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// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160} // End namespace Foam
161
162// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163
164#ifdef NoRepository
165 #include "Polynomial.C"
166#endif
167
168// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169
170#endif
172// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
Polynomial templated on size (order):
Definition Polynomial.H:74
bool logActive() const noexcept
Return true if the log term is active.
Definition Polynomial.C:131
Polynomial()
Default construct, with all coefficients = 0.
Definition Polynomial.C:27
Polynomial< PolySize+1 > intPolyType
Definition Polynomial.H:95
scalar value(const scalar x) const
Polynomial(const UList< scalar > &coeffs)
Construct from a list of coefficients.
Definition Polynomial.C:74
scalar derivative(const scalar x) const
Polynomial(const word &name, Istream &is)
Construct from name and Istream.
Definition Polynomial.C:105
scalar logCoeff() const noexcept
Polynomial(Istream &is)
Construct from Istream.
Definition Polynomial.C:96
scalar integral(const scalar x1, const scalar x2) const
polyType integralMinus1(const scalar intConstant=0.0) const
Polynomial(std::initializer_list< scalar > coeffs)
Construct from an initializer list of coefficients.
Definition Polynomial.C:36
Polynomial< PolySize > polyType
Definition Polynomial.H:94
Polynomial(const scalar coeffs[PolySize])
Construct from C-array of coefficients.
Definition Polynomial.C:60
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:89
A class for handling words, derived from Foam::string.
Definition word.H:66
Namespace for OpenFOAM.
const direction noexcept
Definition scalarImpl.H:265
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127