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 | Copyright (C) 2011-2015 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 \*---------------------------------------------------------------------------*/
25 
26 #include "PolynomialEntry.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 (
33  const word& entryName,
34  const dictionary& dict
35 )
36 :
37  DataEntry<Type>(entryName),
38  coeffs_(),
39  canIntegrate_(true),
40  dimensions_(dimless)
41 {
42  Istream& is(dict.lookup(entryName));
43  word entryType(is);
44 
45  token firstToken(is);
46  is.putBack(firstToken);
47  if (firstToken == token::BEGIN_SQR)
48  {
49  is >> this->dimensions_;
50  }
51 
52  is >> coeffs_;
53 
54  if (!coeffs_.size())
55  {
57  << "PolynomialEntry coefficients for entry " << this->name_
58  << " are invalid (empty)" << nl << exit(FatalError);
59  }
60 
61  forAll(coeffs_, i)
62  {
63  if (mag(coeffs_[i].second() + pTraits<Type>::one) < ROOTVSMALL)
64  {
65  canIntegrate_ = false;
66  break;
67  }
68  }
69 
70  if (debug)
71  {
72  if (!canIntegrate_)
73  {
75  << "PolynomialEntry " << this->name_ << " cannot be integrated"
76  << endl;
77  }
78  }
79 }
80 
81 
82 template<class Type>
84 (
85  const word& entryName,
86  const List<Tuple2<Type, Type> >& coeffs
87 )
88 :
89  DataEntry<Type>(entryName),
90  coeffs_(coeffs),
91  canIntegrate_(true),
92  dimensions_(dimless)
93 {
94  if (!coeffs_.size())
95  {
97  << "PolynomialEntry coefficients for entry " << this->name_
98  << " are invalid (empty)" << nl << exit(FatalError);
99  }
100 
101  forAll(coeffs_, i)
102  {
103  if (mag(coeffs_[i].second() + 1) < ROOTVSMALL)
104  {
105  canIntegrate_ = false;
106  break;
107  }
108  }
109 
110  if (debug)
111  {
112  if (!canIntegrate_)
113  {
115  << "PolynomialEntry " << this->name_ << " cannot be integrated"
116  << endl;
117  }
118  }
119 }
120 
121 
122 template<class Type>
124 :
125  DataEntry<Type>(poly),
126  coeffs_(poly.coeffs_),
127  canIntegrate_(poly.canIntegrate_),
128  dimensions_(poly.dimensions_)
129 {}
130 
131 
132 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
133 
134 template<class Type>
136 {}
137 
138 
139 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
140 
141 template<class Type>
143 {
144  forAll(coeffs_, i)
145  {
146  Type value = coeffs_[i].first();
147  for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
148  {
149  setComponent(coeffs_[i].first(), cmpt) =
150  t.userTimeToTime(component(value, cmpt));
151  }
152  }
153 }
154 
155 
156 template<class Type>
157 Type Foam::PolynomialEntry<Type>::value(const scalar x) const
158 {
159  Type y(pTraits<Type>::zero);
160  forAll(coeffs_, i)
161  {
162  y += cmptMultiply
163  (
164  coeffs_[i].first(),
165  cmptPow(pTraits<Type>::one*x, coeffs_[i].second())
166  );
167  }
168 
169  return y;
170 }
171 
172 
173 template<class Type>
175 (
176  const scalar x1,
177  const scalar x2
178 ) const
179 {
180  Type intx(pTraits<Type>::zero);
181 
182  if (canIntegrate_)
183  {
184  forAll(coeffs_, i)
185  {
186  intx += cmptMultiply
187  (
188  cmptDivide
189  (
190  coeffs_[i].first(),
191  coeffs_[i].second() + pTraits<Type>::one
192  ),
193  cmptPow
194  (
196  coeffs_[i].second() + pTraits<Type>::one
197  )
198  - cmptPow
199  (
201  coeffs_[i].second() + pTraits<Type>::one
202  )
203  );
204  }
205  }
206 
207  return intx;
208 }
209 
210 
211 template<class Type>
213 (
214  const scalar x
215 ) const
216 {
217  return dimensioned<Type>("dimensionedValue", dimensions_, value(x));
218 }
219 
220 
221 template<class Type>
223 (
224  const scalar x1,
225  const scalar x2
226 ) const
227 {
228  return dimensioned<Type>
229  (
230  "dimensionedValue",
231  dimensions_,
232  integrate(x1, x2)
233  );
234 }
235 
236 
237 // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
238 
239 #include "PolynomialEntryIO.C"
240 
241 
242 // ************************************************************************* //
Foam::PolynomialEntry
PolynomialEntry container data entry for scalars. Items are stored in a list of Tuple2's....
Definition: PolynomialEntry.H:60
Foam::setComponent
label & setComponent(label &l, const direction)
Definition: label.H:79
Foam::component
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Definition: FieldFieldFunctions.C:41
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Foam::cmptPow
Scalar cmptPow(const Scalar s1, const Scalar s2)
Definition: Scalar.H:249
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::PolynomialEntry::canIntegrate_
bool canIntegrate_
Flag to indicate whether poly can be integrated.
Definition: PolynomialEntry.H:81
Foam::PolynomialEntry::PolynomialEntry
PolynomialEntry(const word &entryName, const dictionary &dict)
Definition: PolynomialEntry.C:32
Foam::cmptMultiply
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
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:55
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::token
A token holds items read from Istream.
Definition: token.H:67
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::PolynomialEntry::integrate
Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: PolynomialEntry.C:175
Foam::PolynomialEntry::dimIntegrate
dimensioned< Type > dimIntegrate(const scalar x1, const scalar x2) const
Integrate between two values and return dimensioned type.
Definition: PolynomialEntry.C:223
Foam::PolynomialEntry::dimValue
dimensioned< Type > dimValue(const scalar) const
Return dimensioned constant value.
Definition: PolynomialEntry.C:213
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::nl
static const char nl
Definition: Ostream.H:260
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::dimensioned< Type >
PolynomialEntry.H
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::cmptDivide
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
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:59
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:50
Foam::Istream::putBack
void putBack(const token &)
Put back token.
Definition: Istream.C:30
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::direction
unsigned char direction
Definition: direction.H:43
PolynomialEntryIO.C
Foam::PolynomialEntry::~PolynomialEntry
virtual ~PolynomialEntry()
Destructor.
Definition: PolynomialEntry.C:135
Foam::Tuple2
A 2-tuple for storing two objects of different types.
Definition: Tuple2.H:47
Foam::PolynomialEntry::convertTimeBase
virtual void convertTimeBase(const Time &t)
Convert time.
Definition: PolynomialEntry.C:142
Foam::PolynomialEntry::value
Type value(const scalar x) const
Return PolynomialEntry value.
Definition: PolynomialEntry.C:157
Foam::DataEntry
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: DataEntry.H:52
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::PolynomialEntry::coeffs_
List< Tuple2< Type, Type > > coeffs_
PolynomialEntry coefficients - list of prefactor, exponent.
Definition: PolynomialEntry.H:78
y
scalar y
Definition: LISASMDCalcMethod1.H:14