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 | Copyright (C) 2011-2016 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::polynomialFunction
26 
27 Description
28  Polynomial function representation
29 
30  \verbatim
31  poly = logCoeff*log(x) + sum(coeffs[i]*x^i)
32  \endverbatim
33 
34  where <tt> 0 <= i <= N </tt>
35 
36  - integer powers, starting at zero
37  - \c value(x) to evaluate the poly for a given value
38  - \c integrate(x1, x2) between two scalar values
39  - \c integral() to return a new, integral coeff polynomial
40  - increases the size (order)
41  - \c integralMinus1() to return a new, integral coeff polynomial where
42  the base poly starts at order -1
43 
44 See also
45  Foam::Polynomial for a templated implementation
46 
47 SourceFiles
48  polynomialFunction.C
49 
50 \*---------------------------------------------------------------------------*/
51 
52 #ifndef polynomialFunction_H
53 #define polynomialFunction_H
54 
55 #include "scalarList.H"
56 #include "Ostream.H"
57 #include "runTimeSelectionTables.H"
58 
59 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 
61 namespace Foam
62 {
63 
64 // Forward declaration of classes
65 class polynomialFunction;
66 
67 // Forward declaration of friend functions
68 Ostream& operator<<(Ostream&, const polynomialFunction&);
69 
70 
71 /*---------------------------------------------------------------------------*\
72  Class polynomialFunction Declaration
73 \*---------------------------------------------------------------------------*/
74 
76 :
77  private scalarList
78 {
79  // Private data
80 
81  //- Include the log term? - only activated using integralMinus1()
82  bool logActive_;
83 
84  //- Log coefficient - only activated using integralMinus1()
85  scalar logCoeff_;
86 
87 
88  // Private Member Functions
89 
90  //- Return integral coefficients.
91  // Argument becomes zeroth element (constant of integration)
92  static polynomialFunction cloneIntegral
93  (
94  const polynomialFunction&,
95  const scalar intConstant = 0.0
96  );
97 
98  //- Return integral coefficients when lowest order is -1.
99  // Argument becomes zeroth element (constant of integration)
100  static polynomialFunction cloneIntegralMinus1
101  (
102  const polynomialFunction&,
103  const scalar intConstant = 0.0
104  );
105 
106 
107  //- Disallow default bitwise assignment
108  void operator=(const polynomialFunction&);
109 
110 
111 
112 public:
113 
114  //- Runtime type information
115  TypeName("polynomialFunction");
116 
117 
118  // Constructors
119 
120  //- Construct a particular size, with all coefficients = 0.0
121  explicit polynomialFunction(const label);
122 
123  //- Copy constructor
125 
126  //- Construct from a list of coefficients
127  explicit polynomialFunction(const UList<scalar>& coeffs);
128 
129  //- Construct from Istream
131 
132 
133  //- Destructor
134  virtual ~polynomialFunction();
135 
136 
137  // Member Functions
138 
139  //- Return the number of coefficients
140  using scalarList::size;
141 
142  //- Return coefficient
143  using scalarList::operator[];
144 
145 
146  // Access
147 
148 
149  //- Return true if the log term is active
150  bool logActive() const;
151 
152  //- Return the log coefficient
153  scalar logCoeff() const;
154 
155 
156  // Evaluation
157 
158  //- Return polynomial value
159  scalar value(const scalar x) const;
160 
161  //- Integrate between two values
162  scalar integrate(const scalar x1, const scalar x2) const;
163 
164 
165  //- Return integral coefficients.
166  // Argument becomes zeroth element (constant of integration)
168  (
169  const scalar intConstant = 0.0
170  ) const;
171 
172  //- Return integral coefficients when lowest order is -1.
173  // Argument becomes zeroth element (constant of integration)
175  (
176  const scalar intConstant = 0.0
177  ) const;
178 
179 
180  // Member Operators
181 
184 
185  polynomialFunction& operator*=(const scalar);
186  polynomialFunction& operator/=(const scalar);
187 
188 
189  //- Ostream Operator
190  friend Ostream& operator<<(Ostream&, const polynomialFunction&);
191 };
192 
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
197 
198 polynomialFunction operator+
199 (
200  const polynomialFunction&,
201  const polynomialFunction&
202 );
203 
204 
205 polynomialFunction operator-
206 (
207  const polynomialFunction&,
208  const polynomialFunction&
209 );
210 
211 
212 polynomialFunction operator*
213 (
214  const scalar,
215  const polynomialFunction&
216 );
217 
218 
219 polynomialFunction operator/
220 (
221  const scalar,
222  const polynomialFunction&
223 );
224 
225 
226 polynomialFunction operator*
227 (
228  const polynomialFunction&,
229  const scalar
230 );
231 
232 
233 polynomialFunction operator/
234 (
235  const polynomialFunction&,
236  const scalar
237 );
238 
239 
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 
242 } // End namespace Foam
243 
244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
245 
246 #endif
247 
248 // ************************************************************************* //
polynomialFunction & operator/=(const scalar)
polynomialFunction & operator+=(const polynomialFunction &)
polynomialFunction integral(const scalar intConstant=0.0) const
Return integral coefficients.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
friend Ostream & operator(Ostream &, const UList< T > &)
TypeName("polynomialFunction")
Runtime type information.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
polynomialFunction(const label)
Construct a particular size, with all coefficients = 0.0.
scalar integrate(const scalar x1, const scalar x2) const
Integrate between two values.
polynomialFunction & operator*=(const scalar)
Polynomial function representation.
scalar value(const scalar x) const
Return polynomial value.
friend Ostream & operator<<(Ostream &, const polynomialFunction &)
Ostream Operator.
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:61
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
scalar logCoeff() const
Return the log coefficient.
bool logActive() const
Return true if the log term is active.
polynomialFunction & operator-=(const polynomialFunction &)
polynomialFunction integralMinus1(const scalar intConstant=0.0) const
Return integral coefficients when lowest order is -1.
Ostream & operator<<(Ostream &, const ensightPart &)
Macros to ease declaration of run-time selection tables.
virtual ~polynomialFunction()
Destructor.
label size() const
Return the number of elements in the UList.
Definition: ListI.H:170
Namespace for OpenFOAM.