antioch-0.4.0
kooij_rate.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // Antioch - A Gas Dynamics Thermochemistry Library
5 //
6 // Copyright (C) 2014-2016 Paul T. Bauman, Benjamin S. Kirk,
7 // Sylvain Plessis, Roy H. Stonger
8 //
9 // Copyright (C) 2013 The PECOS Development Team
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the Version 2.1 GNU Lesser General
13 // Public License as published by the Free Software Foundation.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
23 // Boston, MA 02110-1301 USA
24 //
25 //-----------------------------------------------------------------------el-
26 
27 #ifndef ANTIOCH_KOOIJ_RATE_H
28 #define ANTIOCH_KOOIJ_RATE_H
29 
30 //Antioch
32 #include "antioch/cmath_shims.h"
33 #include "antioch/kinetics_type.h"
35 
36 // C++
37 #include <cmath>
38 #include <iostream>
39 #include <sstream>
40 
41 namespace Antioch
42 {
44 
58  template<typename CoeffType=double>
59  class KooijRate : public KineticsType<CoeffType>
60  {
61 
62  private:
63 
64  CoeffType _raw_Cf;
65  CoeffType _Cf;
66  CoeffType _eta;
67  CoeffType _raw_Ea;
68  CoeffType _Ea;
69  CoeffType _Tref;
70  CoeffType _rscale;
71 
72  public:
73 
74  KooijRate (const CoeffType Cf=0., const CoeffType eta=0., const CoeffType Ea=0., const CoeffType Tref = 1.,
75  const CoeffType rscale = Constants::R_universal<CoeffType>());
76  ~KooijRate();
77 
78  void set_Cf( const CoeffType Cf );
79  void set_eta( const CoeffType eta );
81  void set_Ea( const CoeffType Ea );
83  void reset_Ea( const CoeffType Ea );
84  void set_Tref( const CoeffType Tref );
85  void set_rscale(const CoeffType scale );
86 
88  void set_parameter(KineticsModel::Parameters parameter, CoeffType new_value);
89 
91  CoeffType get_parameter(KineticsModel::Parameters parameter) const;
92 
94  //
95  // \todo, solve this
96  template <typename VectorCoeffType>
97  void set_parameter(KineticsModel::Parameters parameter, VectorCoeffType new_value){antioch_error();}
98 
109  template <typename VectorCoeffType>
110  void reset_coefs(const VectorCoeffType & coefficients);
111 
112  CoeffType Cf() const;
113  CoeffType eta() const;
114  CoeffType Ea() const;
115  CoeffType Ea_K() const;
116  CoeffType Tref() const;
117  CoeffType rscale() const;
118 
120  template <typename StateType>
121  ANTIOCH_AUTO(StateType)
122  rate(const StateType& T) const
123  ANTIOCH_AUTOFUNC(StateType, _Cf* (ant_exp(_eta * ant_log(T) - _Ea/T)))
124 
126  template <typename StateType>
127  ANTIOCH_AUTO(StateType)
128  operator()(const StateType& T) const
129  ANTIOCH_AUTOFUNC(StateType, this->rate(T))
130 
132  template <typename StateType>
133  ANTIOCH_AUTO(StateType)
134  derivative( const StateType& T ) const
135  ANTIOCH_AUTOFUNC(StateType, (*this)(T)/T*(_eta + _Ea/T))
136 
138  template <typename StateType>
139  void rate_and_derivative(const StateType& T, StateType& rate, StateType& drate_dT) const;
140 
141 // KineticsConditions overloads
142 
144  template <typename StateType, typename VectorStateType>
145  ANTIOCH_AUTO(StateType)
146  rate(const KineticsConditions<StateType,VectorStateType>& T) const
147  ANTIOCH_AUTOFUNC(StateType, _Cf * ant_exp(_eta * T.temp_cache().lnT - _Ea/T.T()))
148 
150  template <typename StateType, typename VectorStateType>
151  ANTIOCH_AUTO(StateType)
152  operator()(const KineticsConditions<StateType,VectorStateType>& T) const
153  ANTIOCH_AUTOFUNC(StateType, this->rate(T))
154 
156  template <typename StateType, typename VectorStateType>
157  ANTIOCH_AUTO(StateType)
158  derivative( const KineticsConditions<StateType,VectorStateType>& T ) const
159  ANTIOCH_AUTOFUNC(StateType, (*this)(T)/T.T()*(_eta + _Ea/T.T()))
160 
162  template <typename StateType,typename VectorStateType>
163  void rate_and_derivative(const KineticsConditions<StateType,VectorStateType>& T, StateType& rate, StateType& drate_dT) const;
164 
166  const std::string numeric() const;
167 
168  private:
169 
170  void compute_cf();
171 
172  };
173 
174  template<typename CoeffType>
175  KooijRate<CoeffType>::KooijRate(const CoeffType Cf, const CoeffType eta, const CoeffType Ea, const CoeffType Tref, const CoeffType rscale)
176  : KineticsType<CoeffType>(KineticsModel::KOOIJ),
177  _raw_Cf(Cf),
178  _eta(eta),
179  _raw_Ea(Ea),
180  _Tref(Tref),
181  _rscale(rscale)
182  {
183 
184  _Ea = _raw_Ea / _rscale;
185  this->compute_cf();
186 
187  return;
188  }
189 
190  template<typename CoeffType>
192  {
193  return;
194  }
195 
196  template<typename CoeffType>
197  const std::string KooijRate<CoeffType>::numeric() const
198  {
199  std::stringstream os;
200  os << _raw_Cf;
201  if (_eta != 0.) os << "*(T/" << _Tref << ")^" << _eta;
202  os << "*exp(-" << _raw_Ea << "/(R*T))";
203 
204  return os.str();
205  }
206 
207  /* ------------------------- Inline Functions -------------------------*/
208  template<typename CoeffType>
209  inline
210  void KooijRate<CoeffType>::set_Cf( const CoeffType Cf )
211  {
212  _raw_Cf = Cf;
213  this->compute_cf();
214 
215  return;
216  }
217 
218  template<typename CoeffType>
219  inline
220  void KooijRate<CoeffType>::set_Tref( const CoeffType Tref )
221  {
222  _Tref = Tref;
223  this->compute_cf();
224 
225  return;
226  }
227 
228  template<typename CoeffType>
229  inline
230  void KooijRate<CoeffType>::set_eta( const CoeffType eta )
231  {
232  _eta = eta;
233  this->compute_cf();
234  return;
235  }
236 
237  template<typename CoeffType>
238  inline
239  void KooijRate<CoeffType>::set_Ea( const CoeffType Ea )
240  {
241  _raw_Ea = Ea;
242  _Ea = _raw_Ea / _rscale;
243  return;
244  }
245 
246  template<typename CoeffType>
247  inline
248  void KooijRate<CoeffType>::reset_Ea( const CoeffType Ea )
249  {
250  _Ea = Ea;
251  _raw_Ea = _Ea * _rscale;
252  return;
253  }
254 
255  template<typename CoeffType>
256  inline
257  void KooijRate<CoeffType>::set_rscale( const CoeffType rscale )
258  {
259  _rscale = rscale;
260  _Ea = _raw_Ea / _rscale;
261  return;
262  }
263 
264  template<typename CoeffType>
265  template <typename VectorCoeffType>
266  inline
267  void KooijRate<CoeffType>::reset_coefs(const VectorCoeffType & coefficients)
268  {
269  // 3 or 5
270  antioch_assert_greater(coefficients.size(),2);
271  antioch_assert_less(coefficients.size(),6);
272  antioch_assert_not_equal_to(coefficients.size(),4);
273 
274  if(coefficients.size() == 5)
275  {
276  this->set_rscale(coefficients[4]);
277  this->set_Tref(coefficients[3]);
278  }
279  this->set_Cf(coefficients[0]);
280  this->set_eta(coefficients[1]);
281  this->set_Ea(coefficients[2]);
282  }
283 
284  template<typename CoeffType>
285  inline
287  {
288  switch(parameter)
289  {
291  {
292  this->set_rscale(new_value);
293  }
294  break;
296  {
297  this->set_Tref(new_value);
298  }
299  break;
301  {
302  this->set_Cf(new_value);
303  }
304  break;
306  {
307  this->set_eta(new_value);
308  }
309  break;
311  {
312  this->reset_Ea(new_value);
313  }
314  break;
315  default:
316  {
317  antioch_error();
318  }
319  break;
320  }
321  }
322 
323  template<typename CoeffType>
324  inline
326  {
327  switch(parameter)
328  {
330  {
331  return this->rscale();
332  }
333  break;
335  {
336  return this->Tref();
337  }
338  break;
340  {
341  return this->Cf();
342  }
343  break;
345  {
346  return this->eta();
347  }
348  break;
350  {
351  return this->Ea();
352  }
353  break;
354  default:
355  {
356  antioch_error();
357  }
358  break;
359  }
360 
361  return 0;
362  }
363 
364  template<typename CoeffType>
365  inline
366  CoeffType KooijRate<CoeffType>::Cf() const
367  { return _Cf; }
368 
369  template<typename CoeffType>
370  inline
371  CoeffType KooijRate<CoeffType>::eta() const
372  { return _eta; }
373 
374  template<typename CoeffType>
375  inline
376  CoeffType KooijRate<CoeffType>::Ea() const
377  { return _raw_Ea; }
378 
379  template<typename CoeffType>
380  inline
381  CoeffType KooijRate<CoeffType>::Ea_K() const
382  { return _Ea; }
383 
384  template<typename CoeffType>
385  inline
386  CoeffType KooijRate<CoeffType>::Tref() const
387  { return _Tref; }
388 
389  template<typename CoeffType>
390  inline
392  { return _rscale; }
393 
394  template<typename CoeffType>
395  template<typename StateType>
396  inline
397  void KooijRate<CoeffType>::rate_and_derivative( const StateType& T,
398  StateType& rate,
399  StateType& drate_dT) const
400  {
401  rate = (*this)(T);
402  drate_dT = rate/T*(_eta + _Ea/T);
403 
404  return;
405  }
406 
407  template<typename CoeffType>
408  template<typename StateType, typename VectorStateType>
409  inline
410  void KooijRate<CoeffType>::rate_and_derivative( const KineticsConditions<StateType,VectorStateType>& T,
411  StateType& rate,
412  StateType& drate_dT) const
413  {
414  rate = (*this)(T);
415  drate_dT = rate/T.T()*(_eta + _Ea/T.T());
416 
417  return;
418  }
419 
420  template<typename CoeffType>
421  inline
423  {
424  _Cf = _raw_Cf * ant_pow(KineticsModel::Tref<CoeffType>()/_Tref,_eta);
425  return;
426  }
427 
428 } // end namespace Antioch
429 
430 #endif // ANTIOCH_KOOIJ_RATE_H
const std::string numeric() const
print equation
Definition: kooij_rate.h:197
void set_Tref(const CoeffType Tref)
Definition: kooij_rate.h:220
CoeffType Cf() const
Definition: kooij_rate.h:366
CoeffType _raw_Cf
Definition: kooij_rate.h:64
_Cf(* this)(T)/T *(_eta+_Ea/T)) template< typename StateType > void rate_and_derivative(const StateType &T
Simultaneously evaluate the rate and its derivative at T.
Definition: kooij_rate.h:135
void set_Ea(const CoeffType Ea)
set _raw_Ea, unit is known (cal.mol-1, J.mol-1, whatever), _Ea is computed
Definition: kooij_rate.h:239
base class for kinetics models
Definition: kinetics_type.h:82
CoeffType _eta
Definition: kooij_rate.h:66
#define antioch_assert_greater(expr1, expr2)
_Cf * ant_exp(_eta *ant_log(T)-_Ea/T))) template< typename StateType > operator()(const StateType &T) const template< typename StateType > derivative(const StateType &T) const ANTIOCH_AUTOFUNC(StateType
#define antioch_assert_not_equal_to(expr1, expr2)
#define antioch_assert_less(expr1, expr2)
CoeffType Ea_K() const
Definition: kooij_rate.h:381
void set_rscale(const CoeffType scale)
Definition: kooij_rate.h:257
void set_parameter(KineticsModel::Parameters parameter, CoeffType new_value)
set one parameter, characterized by enum
Definition: kooij_rate.h:286
CoeffType Ea() const
Definition: kooij_rate.h:376
_Cf(*) StateType StateType &drate_d const)
Definition: kooij_rate.h:139
CoeffType _Tref
Definition: kooij_rate.h:69
#define antioch_error()
CoeffType eta() const
Definition: kooij_rate.h:371
_Cf VectorStateType VectorStateType(*) VectorStateType voi rate_and_derivative)(const KineticsConditions< StateType, VectorStateType > &T, StateType &rate, StateType &drate_dT) const
Definition: kooij_rate.h:163
CoeffType Tref() const
Definition: kooij_rate.h:386
void set_parameter(KineticsModel::Parameters parameter, VectorCoeffType new_value)
for compatibility purpose with photochemistry (particle flux reactions)
Definition: kooij_rate.h:97
CoeffType _rscale
Definition: kooij_rate.h:70
_Cf VectorStateType VectorStateType derivative(const KineticsConditions< StateType, VectorStateType > &T) const ANTIOCH_AUTOFUNC(StateType
void set_Cf(const CoeffType Cf)
Definition: kooij_rate.h:210
CoeffType get_parameter(KineticsModel::Parameters parameter) const
get one parameter, characterized by enum
Definition: kooij_rate.h:325
void reset_coefs(const VectorCoeffType &coefficients)
reset the coeffs
Definition: kooij_rate.h:267
void reset_Ea(const CoeffType Ea)
set _Ea, unit is K, _raw_Ea is computed
Definition: kooij_rate.h:248
void set_eta(const CoeffType eta)
Definition: kooij_rate.h:230
CoeffType _raw_Ea
Definition: kooij_rate.h:67
CoeffType rscale() const
Definition: kooij_rate.h:391
#define ANTIOCH_AUTOFUNC(Type, Expr)
const ANTIOCH_AUTO(StateType) KineticsTheoryThermalConductivity< ThermoEvaluator
The parameters are reduced parameters.
Kooij rate equation.
Definition: kinetics_type.h:59
_Cf(*) StateType rate)
Definition: kooij_rate.h:139
This class contains the conditions of the chemistry.
KooijRate(const CoeffType Cf=0., const CoeffType eta=0., const CoeffType Ea=0., const CoeffType Tref=1., const CoeffType rscale=Constants::R_universal< CoeffType >())
Definition: kooij_rate.h:175

Generated on Thu Jul 7 2016 11:09:45 for antioch-0.4.0 by  doxygen 1.8.8