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