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  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 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
125 
126 template<class Type>
128 {}
129 
130 
131 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
132 
133 template<class Type>
135 {
136  forAll(coeffs_, i)
137  {
138  Type value = coeffs_[i].first();
139  for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
140  {
141  setComponent(coeffs_[i].first(), cmpt) =
142  t.userTimeToTime(component(value, cmpt));
143  }
144  }
145 }
146 
147 
148 template<class Type>
150 {
151  Type y(Zero);
152  forAll(coeffs_, i)
153  {
154  y += cmptMultiply
155  (
156  coeffs_[i].first(),
157  cmptPow(pTraits<Type>::one*x, coeffs_[i].second())
158  );
159  }
160 
161  return y;
162 }
163 
164 
165 template<class Type>
167 (
168  const scalar x1,
169  const scalar x2
170 ) const
171 {
172  Type intx(Zero);
173 
174  if (canIntegrate_)
175  {
176  forAll(coeffs_, i)
177  {
178  intx += cmptMultiply
179  (
180  cmptDivide
181  (
182  coeffs_[i].first(),
183  coeffs_[i].second() + pTraits<Type>::one
184  ),
185  cmptPow
186  (
188  coeffs_[i].second() + pTraits<Type>::one
189  )
190  - cmptPow
191  (
193  coeffs_[i].second() + pTraits<Type>::one
194  )
195  );
196  }
197  }
198 
199  return intx;
200 }
201 
202 
203 template<class Type>
205 {
207 
208  os << nl << indent << coeffs_ << token::END_STATEMENT << nl;
209 }
210 
211 
212 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::setComponent
label & setComponent(label &l, const direction)
Definition: label.H:127
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:363
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:204
Foam::cmptMultiply
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::Function1Types::Polynomial::integrate
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: PolynomialEntry.C:167
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:337
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:56
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::Function1Types::Polynomial::Polynomial
Polynomial(const word &entryName, const dictionary &dict)
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:116
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:307
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:355
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::Function1Types::Polynomial::~Polynomial
virtual ~Polynomial()
Destructor.
Definition: PolynomialEntry.C:127
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:52
Foam::Function1Types::Polynomial::value
virtual Type value(const scalar x) const
Return Polynomial value.
Definition: PolynomialEntry.C:149
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:134
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:294
y
scalar y
Definition: LISASMDCalcMethod1.H:14