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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "PolynomialEntry.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 template<class Type>
34 (
35  const word& entryName,
36  const dictionary& dict
37 )
38 :
39  Function1<Type>(entryName),
40  coeffs_(),
41  canIntegrate_(true)
42 {
43  Istream& is = dict.lookup(entryName);
44  const word entryType(is);
45 
46  is >> coeffs_;
47 
48  if (!coeffs_.size())
49  {
51  << "Polynomial coefficients for entry " << this->name_
52  << " are invalid (empty)" << nl << exit(FatalError);
53  }
54 
55  forAll(coeffs_, i)
56  {
57  if (mag(coeffs_[i].second() + pTraits<Type>::one) < ROOTVSMALL)
58  {
59  canIntegrate_ = false;
60  break;
61  }
62  }
63 
64  if (debug)
65  {
66  if (!canIntegrate_)
67  {
69  << "Polynomial " << this->name_ << " cannot be integrated"
70  << endl;
71  }
72  }
73 }
74 
75 
76 template<class Type>
78 (
79  const word& entryName,
80  const List<Tuple2<Type, Type>>& coeffs
81 )
82 :
83  Function1<Type>(entryName),
84  coeffs_(coeffs),
85  canIntegrate_(true)
86 {
87  if (!coeffs_.size())
88  {
90  << "Polynomial coefficients for entry " << this->name_
91  << " are invalid (empty)" << nl << exit(FatalError);
92  }
93 
94  forAll(coeffs_, i)
95  {
96  if (mag(coeffs_[i].second() + 1) < ROOTVSMALL)
97  {
98  canIntegrate_ = false;
99  break;
100  }
101  }
102 
103  if (debug)
104  {
105  if (!canIntegrate_)
106  {
108  << "Polynomial " << this->name_ << " cannot be integrated"
109  << endl;
110  }
111  }
112 }
113 
114 
115 template<class Type>
117 :
118  Function1<Type>(poly),
119  coeffs_(poly.coeffs_),
120  canIntegrate_(poly.canIntegrate_)
121 {}
122 
123 
124 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
125 
126 template<class Type>
128 {
129  forAll(coeffs_, i)
130  {
131  Type value = coeffs_[i].first();
132  for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
133  {
134  setComponent(coeffs_[i].first(), cmpt) =
135  t.userTimeToTime(component(value, cmpt));
136  }
137  }
138 }
139 
140 
141 template<class Type>
143 {
144  Type y(Zero);
145  forAll(coeffs_, i)
146  {
147  y += cmptMultiply
148  (
149  coeffs_[i].first(),
150  cmptPow(pTraits<Type>::one*x, coeffs_[i].second())
151  );
152  }
153 
154  return y;
155 }
156 
157 
158 template<class Type>
160 (
161  const scalar x1,
162  const scalar x2
163 ) const
164 {
165  Type intx(Zero);
166 
167  if (canIntegrate_)
168  {
169  forAll(coeffs_, i)
170  {
171  intx += cmptMultiply
172  (
173  cmptDivide
174  (
175  coeffs_[i].first(),
176  coeffs_[i].second() + pTraits<Type>::one
177  ),
178  cmptPow
179  (
181  coeffs_[i].second() + pTraits<Type>::one
182  )
183  - cmptPow
184  (
186  coeffs_[i].second() + pTraits<Type>::one
187  )
188  );
189  }
190  }
191 
192  return intx;
193 }
194 
195 
196 template<class Type>
198 {
200 
201  os << nl << indent << coeffs_ << token::END_STATEMENT << nl;
202 }
203 
204 
205 // ************************************************************************* //
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:197
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:160
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:34
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::Function1::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Function1.C:165
Foam::token::END_STATEMENT
End entry [isseparator].
Definition: token.H:122
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:372
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: HashTable.H:102
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:142
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::direction
uint8_t direction
Definition: direction.H:47
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::Function1Types::Polynomial::convertTimeBase
virtual void convertTimeBase(const Time &t)
Convert time.
Definition: PolynomialEntry.C:127
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:298
y
scalar y
Definition: LISASMDCalcMethod1.H:14