polynomialFunction.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::polynomialFunction
29
30Description
31 Polynomial function representation
32
33 \verbatim
34 poly = logCoeff*log(x) + sum(coeffs[i]*x^i)
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 integrate(x1, x2) between two scalar values
42 - \c integral() to return a new, integral coeff polynomial
43 - increases the size (order)
44 - \c integralMinus1() to return a new, integral coeff polynomial where
45 the base poly starts at order -1
46
47See also
48 Foam::Polynomial for a templated implementation
49
50SourceFiles
51 polynomialFunction.C
52
53\*---------------------------------------------------------------------------*/
54
55#ifndef polynomialFunction_H
56#define polynomialFunction_H
57
58#include "scalarList.H"
59#include "Ostream.H"
61
62// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
63
64namespace Foam
65{
66
67// Forward Declarations
68class polynomialFunction;
69
70Istream& operator>>(Istream&, polynomialFunction& poly);
71Ostream& operator<<(Ostream&, const polynomialFunction& poly);
72
73/*---------------------------------------------------------------------------*\
74 Class polynomialFunction Declaration
75\*---------------------------------------------------------------------------*/
78:
79 private scalarList
80{
81 // Private Data
82
83 //- Include the log term? - only activated using integralMinus1()
84 bool logActive_;
85
86 //- Log coefficient - only activated using integralMinus1()
87 scalar logCoeff_;
88
89
90 // Private Member Functions
91
92 //- Return integral coefficients.
93 // Argument becomes zeroth element (constant of integration)
94 static polynomialFunction cloneIntegral
95 (
96 const polynomialFunction&,
97 const scalar intConstant = 0
98 );
99
100 //- Return integral coefficients when lowest order is -1.
101 // Argument becomes zeroth element (constant of integration)
102 static polynomialFunction cloneIntegralMinus1
103 (
104 const polynomialFunction&,
105 const scalar intConstant = 0
106 );
107
108 //- Check size is non-zero or trigger FatalErrot
109 void checkSize() const;
110
111
112public:
113
114 //- Runtime type information
115 TypeName("polynomialFunction");
116
117
118 // Generated Methods: copy construct, copy assignment
119
120
121 // Constructors
122
123 //- Default construct as size 1 with coefficient == 0
125
126 //- Construct a particular size, with all coefficients == 0
127 explicit polynomialFunction(const label order);
128
129 //- Construct from an initializer list of coefficients
130 explicit polynomialFunction(std::initializer_list<scalar> coeffs);
131
132 //- Construct from a list of coefficients
133 explicit polynomialFunction(const UList<scalar>& coeffs);
134
135 //- Construct from Istream
136 explicit polynomialFunction(Istream& is);
137
138
139 //- Destructor
140 virtual ~polynomialFunction() = default;
141
142
143 // Member Functions
144
145 //- Non-zero number of coefficients
146 using scalarList::empty;
147
148 //- The number of coefficients
149 using scalarList::size;
150
151 //- Return coefficient at given index
152 using scalarList::operator[];
153
154
155 // Access
156
157 //- True if the log term is active
158 bool logActive() const;
159
160 //- The log coefficient
161 scalar logCoeff() const;
162
163
164 // Evaluation
165
166 //- Return polynomial value
167 scalar value(const scalar x) const;
168
169 //- Integrate between two values
170 scalar integrate(const scalar x1, const scalar x2) const;
171
172
173 //- Return integral coefficients.
174 // Argument becomes zeroth element (constant of integration)
176 (
177 const scalar intConstant = 0
178 ) const;
179
180 //- Return integral coefficients when lowest order is -1.
181 // Argument becomes zeroth element (constant of integration)
183 (
184 const scalar intConstant = 0
185 ) const;
186
187
188 // Member Operators
189
190 //- Equality of coefficients, and logCoeff (if active)
191 bool operator==(const polynomialFunction& rhs) const;
193 bool operator!=(const polynomialFunction& rhs) const
194 {
195 return !operator==(rhs);
196 }
197
200
201 polynomialFunction& operator*=(const scalar);
202 polynomialFunction& operator/=(const scalar);
203
204
205 // IOstream Operators
208 friend Ostream& operator<<(Ostream&, const polynomialFunction& poly);
209};
210
211
212// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
213
214polynomialFunction operator+
215(
216 const polynomialFunction&,
217 const polynomialFunction&
218);
219
220
221polynomialFunction operator-
222(
223 const polynomialFunction&,
224 const polynomialFunction&
225);
226
227
228polynomialFunction operator*
229(
230 const scalar,
231 const polynomialFunction&
232);
233
234
235polynomialFunction operator/
236(
237 const scalar,
238 const polynomialFunction&
239);
240
241
242polynomialFunction operator*
243(
244 const polynomialFunction&,
245 const scalar
246);
247
248
249polynomialFunction operator/
250(
251 const polynomialFunction&,
252 const scalar
253);
254
255
256// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257
258} // End namespace Foam
259
260// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261
262#endif
263
264// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
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:94
friend Ostream & operator(Ostream &, const faMatrix< Type > &)
Polynomial function representation.
friend Istream & operator>>(Istream &, polynomialFunction &poly)
scalar logCoeff() const
The log coefficient.
TypeName("polynomialFunction")
Runtime type information.
scalar integrate(const scalar x1, const scalar x2) const
Integrate between two values.
polynomialFunction & operator/=(const scalar)
scalar value(const scalar x) const
Return polynomial value.
polynomialFunction & operator+=(const polynomialFunction &)
polynomialFunction()
Default construct as size 1 with coefficient == 0.
polynomialFunction & operator-=(const polynomialFunction &)
virtual ~polynomialFunction()=default
Destructor.
polynomialFunction & operator*=(const scalar)
bool logActive() const
True if the log term is active.
polynomialFunction integral(const scalar intConstant=0) const
Return integral coefficients.
polynomialFunction integralMinus1(const scalar intConstant=0) const
Return integral coefficients when lowest order is -1.
friend Ostream & operator<<(Ostream &, const polynomialFunction &poly)
bool operator!=(const polynomialFunction &rhs) const
bool operator==(const polynomialFunction &rhs) const
Equality of coefficients, and logCoeff (if active)
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Istream & operator>>(Istream &, directionInfo &)
Macros to ease declaration of run-time selection tables.
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73