PolynomialEntry.C
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-2016 OpenFOAM Foundation
9  Copyright (C) 2020 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 \*---------------------------------------------------------------------------*/
28 
29 #include "PolynomialEntry.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class Type>
35 (
36  const word& entryName,
37  const dictionary& dict
38 )
39 :
40  Function1<Type>(entryName, dict),
41  coeffs_(),
42  canIntegrate_(true)
43 {
44  Istream& is = dict.lookup(entryName);
45  const word entryType(is);
46 
47  is >> coeffs_;
48 
49  if (!coeffs_.size())
50  {
52  << "Invalid (empty) polynomial coefficients for "
53  << this->name() << nl
54  << exit(FatalError);
55  }
56 
57  forAll(coeffs_, i)
58  {
59  if (mag(coeffs_[i].second() + pTraits<Type>::one) < ROOTVSMALL)
60  {
61  canIntegrate_ = false;
62  break;
63  }
64  }
65 
66  if (debug)
67  {
68  if (!canIntegrate_)
69  {
71  << "Polynomial " << this->name() << " cannot be integrated"
72  << endl;
73  }
74  }
75 }
76 
77 
78 template<class Type>
80 (
81  const word& entryName,
82  const List<Tuple2<Type, Type>>& coeffs
83 )
84 :
85  Function1<Type>(entryName),
86  coeffs_(coeffs),
87  canIntegrate_(true)
88 {
89  if (!coeffs_.size())
90  {
92  << "Invalid (empty) polynomial coefficients for "
93  << this->name() << nl
94  << exit(FatalError);
95  }
96 
97  forAll(coeffs_, i)
98  {
99  if (mag(coeffs_[i].second() + 1) < ROOTVSMALL)
100  {
101  canIntegrate_ = false;
102  break;
103  }
104  }
105 
106  if (debug)
107  {
108  if (!canIntegrate_)
109  {
111  << "Polynomial " << this->name() << " cannot be integrated"
112  << endl;
113  }
114  }
115 }
116 
117 
118 template<class Type>
120 :
121  Function1<Type>(poly),
122  coeffs_(poly.coeffs_),
123  canIntegrate_(poly.canIntegrate_)
124 {}
125 
126 
127 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
128 
129 template<class Type>
131 {
132  forAll(coeffs_, i)
133  {
134  Type value = coeffs_[i].first();
135  for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
136  {
137  setComponent(coeffs_[i].first(), cmpt) =
138  t.userTimeToTime(component(value, cmpt));
139  }
140  }
141 }
142 
143 
144 template<class Type>
146 {
147  Type y(Zero);
148  forAll(coeffs_, i)
149  {
150  y += cmptMultiply
151  (
152  coeffs_[i].first(),
153  cmptPow(pTraits<Type>::one*x, coeffs_[i].second())
154  );
155  }
156 
157  return y;
158 }
159 
160 
161 template<class Type>
163 (
164  const scalar x1,
165  const scalar x2
166 ) const
167 {
168  Type intx(Zero);
169 
170  if (canIntegrate_)
171  {
172  forAll(coeffs_, i)
173  {
174  intx += cmptMultiply
175  (
176  cmptDivide
177  (
178  coeffs_[i].first(),
179  coeffs_[i].second() + pTraits<Type>::one
180  ),
181  cmptPow
182  (
184  coeffs_[i].second() + pTraits<Type>::one
185  )
186  - cmptPow
187  (
189  coeffs_[i].second() + pTraits<Type>::one
190  )
191  );
192  }
193  }
194 
195  return intx;
196 }
197 
198 
199 template<class Type>
201 {
203 
204  os << nl << indent << coeffs_ << token::END_STATEMENT << nl;
205 }
206 
207 
208 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::setComponent
label & setComponent(label &l, const direction)
Definition: label.H:123
Foam::component
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Definition: FieldFieldFunctions.C:44
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::cmptPow
Scalar cmptPow(const Scalar s1, const Scalar s2)
Definition: Scalar.H:364
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::Function1Types::Polynomial::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: PolynomialEntry.C:200
Foam::cmptMultiply
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::Function1Types::Polynomial::integrate
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: PolynomialEntry.C:163
Foam::TimeState::userTimeToTime
virtual scalar userTimeToTime(const scalar theta) const
Convert the user-time (e.g. CA deg) to real-time (s).
Definition: TimeState.C:49
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:86
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::Function1Types::Polynomial::Polynomial
Polynomial(const word &entryName, const dictionary &dict)
Construct from entry name and dictionary.
Definition: PolynomialEntry.C:35
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::Function1::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Function1.C:166
Foam::token::END_STATEMENT
End entry [isseparator].
Definition: token.H:121
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
PolynomialEntry.H
Foam::indent
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:320
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::cmptDivide
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::Function1Types::Polynomial
Definition: PolynomialEntry.H:65
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::nl
constexpr char nl
Definition: Ostream.H:385
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::pTraits
Traits class for primitives.
Definition: pTraits.H:54
Foam::Function1Types::Polynomial::value
virtual Type value(const scalar x) const
Return Polynomial value.
Definition: PolynomialEntry.C:145
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::direction
uint8_t direction
Definition: direction.H:52
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::Function1Types::Polynomial::convertTimeBase
virtual void convertTimeBase(const Time &t)
Convert time.
Definition: PolynomialEntry.C: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: Tuple2.H:57
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:303
y
scalar y
Definition: LISASMDCalcMethod1.H:14