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 -------------------------------------------------------------------------------
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::polynomialFunction
29 
30 Description
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 
47 See also
48  Foam::Polynomial for a templated implementation
49 
50 SourceFiles
51  polynomialFunction.C
52 
53 \*---------------------------------------------------------------------------*/
54 
55 #ifndef polynomialFunction_H
56 #define polynomialFunction_H
57 
58 #include "scalarList.H"
59 #include "Ostream.H"
60 #include "runTimeSelectionTables.H"
61 
62 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
63 
64 namespace Foam
65 {
66 
67 // Forward Declarations
68 class polynomialFunction;
69 
70 Istream& operator>>(Istream&, polynomialFunction& poly);
71 Ostream& operator<<(Ostream&, const polynomialFunction& poly);
72 
73 /*---------------------------------------------------------------------------*\
74  Class polynomialFunction Declaration
75 \*---------------------------------------------------------------------------*/
76 
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 
112 public:
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;
192 
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
206 
207  friend Istream& operator>>(Istream&, polynomialFunction& poly);
208  friend Ostream& operator<<(Ostream&, const polynomialFunction& poly);
209 };
210 
211 
212 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
213 
214 polynomialFunction operator+
215 (
216  const polynomialFunction&,
217  const polynomialFunction&
218 );
219 
220 
221 polynomialFunction operator-
222 (
223  const polynomialFunction&,
224  const polynomialFunction&
225 );
226 
227 
228 polynomialFunction operator*
229 (
230  const scalar,
231  const polynomialFunction&
232 );
233 
234 
235 polynomialFunction operator/
236 (
237  const scalar,
238  const polynomialFunction&
239 );
240 
241 
242 polynomialFunction operator*
243 (
244  const polynomialFunction&,
245  const scalar
246 );
247 
248 
249 polynomialFunction operator/
250 (
251  const polynomialFunction&,
252  const scalar
253 );
254 
255 
256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257 
258 } // End namespace Foam
259 
260 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261 
262 #endif
263 
264 // ************************************************************************* //
Foam::polynomialFunction::operator>>
friend Istream & operator>>(Istream &, polynomialFunction &poly)
Foam::polynomialFunction::TypeName
TypeName("polynomialFunction")
Runtime type information.
Foam::polynomialFunction::operator==
bool operator==(const polynomialFunction &rhs) const
Equality of coefficients, and logCoeff (if active)
Definition: polynomialFunction.C:233
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
scalarList.H
Foam::polynomialFunction::integrate
scalar integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: polynomialFunction.C:187
Foam::polynomialFunction::operator*=
polynomialFunction & operator*=(const scalar)
Definition: polynomialFunction.C:283
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::polynomialFunction::~polynomialFunction
virtual ~polynomialFunction()=default
Destructor.
Foam::polynomialFunction::logCoeff
scalar logCoeff() const
The log coefficient.
Definition: polynomialFunction.C:158
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::polynomialFunction::value
scalar value(const scalar x) const
Return polynomial value.
Definition: polynomialFunction.C:164
Ostream.H
Foam::polynomialFunction::operator+=
polynomialFunction & operator+=(const polynomialFunction &)
Definition: polynomialFunction.C:245
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::polynomialFunction::integralMinus1
polynomialFunction integralMinus1(const scalar intConstant=0) const
Return integral coefficients when lowest order is -1.
Definition: polynomialFunction.C:225
Foam::polynomialFunction::operator<<
friend Ostream & operator<<(Ostream &, const polynomialFunction &poly)
Foam::List< scalar >
Foam::polynomialFunction::operator-=
polynomialFunction & operator-=(const polynomialFunction &)
Definition: polynomialFunction.C:264
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::polynomialFunction::operator!=
bool operator!=(const polynomialFunction &rhs) const
Definition: polynomialFunction.H:192
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::polynomialFunction::operator/=
polynomialFunction & operator/=(const scalar)
Definition: polynomialFunction.C:296
Foam::polynomialFunction
Polynomial function representation.
Definition: polynomialFunction.H:76
Foam::polynomialFunction::logActive
bool logActive() const
True if the log term is active.
Definition: polynomialFunction.C:152
Foam::polynomialFunction::integral
polynomialFunction integral(const scalar intConstant=0) const
Return integral coefficients.
Definition: polynomialFunction.C:218
Foam::polynomialFunction::polynomialFunction
polynomialFunction()
Default construct as size 1 with coefficient == 0.
Definition: polynomialFunction.C:99