PolynomialEntry.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::Function1Types::PolynomialEntry
29 
30 Description
31  PolynomialEntry container data entry for scalars. Items are stored in a
32  list of Tuple2's. Data is input in the form,
33  e.g. for an entry <entryName> that describes y = x^2 + 2x^3
34 
35  Inline specification:
36  \verbatim
37  <entryName> polynomial
38  (
39  (1 2)
40  (2 3)
41  );
42  \endverbatim
43 
44  Dictionary format:
45  \verbatim
46  <entryName>
47  {
48  type polynomial;
49  coeffs
50  (
51  (1 2)
52  (2 3)
53  );
54  }
55  \endverbatim
56 
57 SourceFiles
58  PolynomialEntry.C
59 
60 \*---------------------------------------------------------------------------*/
61 
62 #ifndef Function1Types_Polynomial_H
63 #define Function1Types_Polynomial_H
64 
65 #include "Function1.H"
66 #include "Tuple2.H"
67 #include "Function1Fwd.H"
68 
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 
71 namespace Foam
72 {
73 namespace Function1Types
74 {
75 
76 /*---------------------------------------------------------------------------*\
77  Class Polynomial Declaration
78 \*---------------------------------------------------------------------------*/
79 
80 template<class Type>
81 class Polynomial
82 :
83  public Function1<Type>
84 {
85  // Private Data
86 
87  //- Polynomial coefficients - list of prefactor, exponent
88  List<Tuple2<Type, Type>> coeffs_;
89 
90  //- Flag to indicate whether polynomial can be integrated
91  bool canIntegrate_;
92 
93 
94  // Private Member Functions
95 
96  //- Check coefficients and if polynomial can be integrated
97  void checkCoefficients();
98 
99  //- No copy assignment
100  void operator=(const Polynomial<Type>&) = delete;
101 
102 
103 public:
104 
105  //- Runtime type information
106  TypeName("polynomial");
107 
108 
109  // Constructors
110 
111  //- Construct from entry name, dictionary and optional registry
112  Polynomial
113  (
114  const word& entryName,
115  const dictionary& dict,
116  const objectRegistry* obrPtr = nullptr
117  );
118 
119  //- Construct from components
120  Polynomial
121  (
122  const word& entryName,
123  const List<Tuple2<Type, Type>>& coeffs,
124  const objectRegistry* obrPtr = nullptr
125  );
126 
127  //- Copy constructor
128  explicit Polynomial(const Polynomial& poly);
129 
130  //- Construct and return a clone
131  virtual tmp<Function1<Type>> clone() const
132  {
133  return tmp<Function1<Type>>(new Polynomial<Type>(*this));
134  }
135 
136 
137  //- Destructor
138  virtual ~Polynomial() = default;
139 
140 
141  // Member Functions
142 
143  //- Convert time
144  virtual void userTimeToTime(const Time& t);
145 
146  //- Return Polynomial value
147  virtual Type value(const scalar x) const;
148 
149  //- Integrate between two (scalar) values
150  virtual Type integrate(const scalar x1, const scalar x2) const;
151 
152  //- Write as primitive (inline) format
153  virtual void writeData(Ostream& os) const;
154 };
155 
156 
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 
159 } // End namespace Function1Types
160 } // End namespace Foam
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 #ifdef NoRepository
165  #include "PolynomialEntry.C"
166 #endif
167 
168 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169 
170 #endif
171 
172 // ************************************************************************* //
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::Function1Types::Polynomial::Polynomial
Polynomial(const word &entryName, const dictionary &dict, const objectRegistry *obrPtr=nullptr)
Construct from entry name, dictionary and optional registry.
Definition: PolynomialEntry.C:66
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::Function1Types::Polynomial::writeData
virtual void writeData(Ostream &os) const
Write as primitive (inline) format.
Definition: PolynomialEntry.C:202
Tuple2.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Function1Types::Polynomial::integrate
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: PolynomialEntry.C:165
Foam::Function1::entryName
const word & entryName
Definition: Function1.H:133
Function1.H
Foam::Function1::dict
const word const dictionary & dict
Definition: Function1.H:134
PolynomialEntry.C
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: propellerInfo.H:291
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::Function1::obrPtr
const word const dictionary const objectRegistry * obrPtr
Definition: Function1.H:136
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Function1Types::Polynomial
Definition: PolynomialEntry.H:80
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::Function1Types::Polynomial::value
virtual Type value(const scalar x) const
Return Polynomial value.
Definition: PolynomialEntry.C:147
x
x
Definition: LISASMDCalcMethod2.H:52
Function1Fwd.H
Foam::Function1Types::Polynomial::TypeName
TypeName("polynomial")
Runtime type information.
Foam::Function1Types::Polynomial::clone
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: PolynomialEntry.H:130
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Tuple2
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:60
Foam::Function1Types::Polynomial::userTimeToTime
virtual void userTimeToTime(const Time &t)
Convert time.
Definition: PolynomialEntry.C:132
Foam::Function1Types::Polynomial::~Polynomial
virtual ~Polynomial()=default
Destructor.