Polynomial1.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2024 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::Function1s::Polynomial
26 
27 Description
28  Arbitrary order polynomial Function1.
29 
30  The coefficients in the polynomial are specified in order of increasing
31  exponent, starting from the constant coefficient (i.e., zero exponent).
32 
33  For example, the polynomial y = -1 + x^2 + 2x^3 can be specified as:
34 
35  \verbatim
36  <name> polynomial (-1 0 1 2);
37  \endverbatim
38 
39  Or, alternatively:
40 
41  \verbatim
42  <name>
43  {
44  type polynomial;
45  coeffs (-1 0 1 2);
46  }
47  \endverbatim
48 
49 SourceFiles
50  Polynomial1.C
51 
52 \*---------------------------------------------------------------------------*/
53 
54 #ifndef Polynomial1_H
55 #define Polynomial1_H
56 
57 #include "Function1.H"
58 
59 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 
61 namespace Foam
62 {
63 namespace Function1s
64 {
65 
66 /*---------------------------------------------------------------------------*\
67  Class Polynomial Declaration
68 \*---------------------------------------------------------------------------*/
69 
70 template<class Type>
71 class Polynomial
72 :
73  public FieldFunction1<Type, Polynomial<Type>>
74 {
75  // Private Data
76 
77  //- Polynomial coefficients
78  const List<Type> coeffs_;
79 
80 
81  // Private Member Functions
82 
83  //- Do unit conversions on input data
84  static List<Type> convertRead(const unitConversions&, List<Type>);
85 
86  //- Do unit conversions in order to output data
87  static List<Type> convertWrite(const unitConversions&, List<Type>);
88 
89 
90 public:
91 
92  //- Runtime type information
93  TypeName("polynomial");
94 
95 
96  // Constructors
97 
98  //- Construct from name and dictionary
100  (
101  const word& name,
102  const unitConversions& units,
103  const dictionary& dict
104  );
105 
106  //- Construct from name and Istream
107  Polynomial
108  (
109  const word& name,
110  const unitConversions& units,
111  Istream& is
112  );
113 
114  //- Copy constructor
115  Polynomial(const Polynomial& poly);
116 
117 
118  //- Destructor
119  virtual ~Polynomial();
120 
121 
122  // Member Functions
123 
124  // Evaluation
125 
126  //- Return Polynomial value as a function of scalar x
127  virtual Type value(const scalar x) const;
128 
129  //- Integrate between two scalar fields
130  virtual Type integral(const scalar x1, const scalar x2) const;
131 
132 
133  //- Write in dictionary format
134  virtual void write(Ostream& os, const unitConversions& units) const;
135 
136 
137  // Member Operators
138 
139  //- Disallow default bitwise assignment
140  void operator=(const Polynomial<Type>&) = delete;
141 };
142 
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 } // End namespace Function1s
147 } // End namespace Foam
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 #ifdef NoRepository
152  #include "Polynomial1.C"
153 #endif
154 
155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 
157 #endif
158 
159 // ************************************************************************* //
const word & name() const
Return the name of the entry.
Definition: Function1.C:78
Arbitrary order polynomial Function1.
Definition: Polynomial1.H:73
TypeName("polynomial")
Runtime type information.
void operator=(const Polynomial< Type > &)=delete
Disallow default bitwise assignment.
virtual Type integral(const scalar x1, const scalar x2) const
Integrate between two scalar fields.
Definition: Polynomial1.C:150
Polynomial(const word &name, const unitConversions &units, const dictionary &dict)
Construct from name and dictionary.
Definition: Polynomial1.C:68
virtual void write(Ostream &os, const unitConversions &units) const
Write in dictionary format.
Definition: Polynomial1.C:169
virtual ~Polynomial()
Destructor.
Definition: Polynomial1.C:128
virtual Type value(const scalar x) const
Return Polynomial value as a function of scalar x.
Definition: Polynomial1.C:135
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
const HashTable< unitConversion > & units()
Get the table of unit conversions.
dictionary dict