Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / foam / primitives / functions / PolynomialTemplate / PolynomialTemplate.H
blob64f819e09ad7d60b4dde90d536f4cf8064bf9c2d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::Polynomial
27 Description
28     Polynomial templated on size (order):
30         poly = logCoeff*log(x) + sum(coeff_[i]*x^i)
32     where 0 <= i <= n
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
42 SourceFiles
43     PolynomialTemplate.C
45 \*---------------------------------------------------------------------------*/
47 #ifndef PolynomialTemplate_H
48 #define PolynomialTemplate_H
50 #include "word.H"
51 #include "scalar.H"
52 #include "Ostream.H"
53 #include "VectorSpace.H"
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 namespace Foam
60 // Forward declaration of classes
61 template<int PolySize>
62 class Polynomial;
64 // Forward declaration of friend functions
65 template<int PolySize>
66 Ostream& operator<<
68     Ostream&,
69     const Polynomial<PolySize>&
73 /*---------------------------------------------------------------------------*\
74                         Class Polynomial Declaration
75 \*---------------------------------------------------------------------------*/
77 template<int PolySize>
78 class Polynomial
80     public VectorSpace<Polynomial<PolySize>, scalar, PolySize>
82     // Private data
84         //- Include the log term? - only activated using integrateMinus1()
85         bool logActive_;
87         //- Log coefficient - only activated using integrateMinus1()
88         scalar logCoeff_;
91 public:
93     typedef Polynomial<PolySize> polyType;
95     typedef Polynomial<PolySize+1> intPolyType;
98     // Constructors
100         //- Construct null
101         Polynomial();
103         //- Construct from name and Istream
104         Polynomial(const word& name, Istream& is);
106         //- Copy constructor
107         Polynomial(const Polynomial& poly);
110     // Member Functions
112         // Access
114             //- Return access to the log term active flag
115             bool& logActive();
117             //- Return access to the log coefficient
118             scalar& logCoeff();
121         // Evaluation
123             //- Return polynomial value
124             scalar evaluate(const scalar x) const;
126             //- Return integrated polynomial coefficients
127             //  argument becomes zeroth element (constant of integration)
128             intPolyType integrate(const scalar intConstant = 0.0);
130             //- Return integrated polynomial coefficients when lowest order
131             //  is -1. Argument added to zeroth element
132             polyType integrateMinus1(const scalar intConstant = 0.0);
134             //- Integrate between two values
135             scalar integrateLimits(const scalar x1, const scalar x2) const;
138     //- Ostream Operator
139     friend Ostream& operator<< <PolySize>
140     (
141         Ostream&,
142         const Polynomial&
143     );
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 } // End namespace Foam
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
153 #ifdef NoRepository
154 #   include "PolynomialTemplate.C"
155 #   include "PolynomialTemplateIO.C"
156 #endif
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 #endif
162 // ************************************************************************* //