FreeFOAM The Cross-Platform CFD Toolkit
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 | Copyright (C) 2008-2010 OpenCFD Ltd.
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::Polynomial
26 
27 Description
28  Polynomial templated on size (order):
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  - evaluate(x) to evaluate the poly for a given value
36  - integrate(x1, x2) between two scalar values
37  - integrate() to return a new, intergated coeff polynomial
38  - increases the size (order)
39  - integrateMinus1() to return a new, integrated coeff polynomial where
40  the base poly starts at order -1
41 
42 SourceFiles
43  Polynomial.C
44 
45 \*---------------------------------------------------------------------------*/
46 
47 #ifndef Polynomial_H
48 #define Polynomial_H
49 
50 #include <OpenFOAM/word.H>
51 #include <OpenFOAM/scalar.H>
52 #include <OpenFOAM/Ostream.H>
53 #include <OpenFOAM/VectorSpace.H>
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 
60 // Forward declaration of classes
61 template<int PolySize>
62 class Polynomial;
63 
64 // Forward declaration of friend functions
65 template<int PolySize>
66 Ostream& operator<<
67 (
68  Ostream&,
69  const Polynomial<PolySize>&
70 );
71 
72 
73 /*---------------------------------------------------------------------------*\
74  Class Polynomial Declaration
75 \*---------------------------------------------------------------------------*/
76 
77 template<int PolySize>
79 :
80  public VectorSpace<Polynomial<PolySize>, scalar, PolySize>
81 {
82  // Private data
83 
84  //- Include the log term? - only activated using integrateMinus1()
85  bool logActive_;
86 
87  //- Log coefficient - only activated using integrateMinus1()
88  scalar logCoeff_;
89 
90 
91 public:
92 
94 
96 
97 
98  // Constructors
99 
100  //- Construct null
101  Polynomial();
102 
103  //- Construct from name and Istream
104  Polynomial(const word& name, Istream& is);
105 
106  //- Copy constructor
107  Polynomial(const Polynomial& poly);
108 
109 
110  // Member Functions
111 
112  // Access
113 
114  //- Return access to the log term active flag
115  bool& logActive();
116 
117  //- Return access to the log coefficient
118  scalar& logCoeff();
119 
120 
121  // Evaluation
122 
123  //- Return polynomial value
124  scalar evaluate(const scalar x) const;
125 
126  //- Return integrated polynomial coefficients
127  // argument becomes zeroth element (constant of integration)
128  intPolyType integrate(const scalar intConstant = 0.0);
129 
130  //- Return integrated polynomial coefficients when lowest order
131  // is -1. Argument added to zeroth element
132  polyType integrateMinus1(const scalar intConstant = 0.0);
133 
134  //- Integrate between two values
135  scalar integrateLimits(const scalar x1, const scalar x2) const;
136 
137 
138  //- Ostream Operator
139  friend Ostream& operator<< <PolySize>
140  (
141  Ostream&,
142  const Polynomial&
143  );
144 };
145 
146 
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 
149 } // End namespace Foam
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 #ifdef NoRepository
154 # include "Polynomial.C"
155 # include "PolynomialIO.C"
156 #endif
157 
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 
160 #endif
161 
162 // ************************ vim: set sw=4 sts=4 et: ************************ //