antioch-0.4.0
vanthoff_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_VAN_T_HOFF_RATE_H
28 #define ANTIOCH_VAN_T_HOFF_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 VantHoffRate: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 _D;
70  CoeffType _Tref;
71  CoeffType _rscale;
72 
73  public:
74 
75  VantHoffRate (const CoeffType Cf=0., const CoeffType eta=0., const CoeffType Ea=0.,
76  const CoeffType D=0., const CoeffType Tref = 1.,
77  const CoeffType rscale = Constants::R_universal<CoeffType>());
78 
79  ~VantHoffRate();
80 
81  void set_Cf( const CoeffType Cf );
82  void set_eta( const CoeffType eta );
84  void set_Ea( const CoeffType Ea );
86  void reset_Ea( const CoeffType Ea );
87  void set_D( const CoeffType D );
88  void set_Tref( const CoeffType Tref );
89  void set_rscale(const CoeffType rscale );
90 
92  void set_parameter(KineticsModel::Parameters parameter, CoeffType new_value);
93 
95  CoeffType get_parameter(KineticsModel::Parameters parameter) const;
96 
98  //
99  // \todo, solve this
100  template <typename VectorCoeffType>
101  void set_parameter(KineticsModel::Parameters parameter, VectorCoeffType new_value){antioch_error();}
102 
113  template <typename VectorCoeffType>
114  void reset_coefs(const VectorCoeffType & coefficients);
115 
116  CoeffType Cf() const;
117  CoeffType eta() const;
118  CoeffType Ea() const;
119  CoeffType Ea_K() const;
120  CoeffType D() const;
121  CoeffType Tref() const;
122  CoeffType rscale() const;
123 
125  template <typename StateType>
126  ANTIOCH_AUTO(StateType)
127  rate(const StateType& T) const
128  ANTIOCH_AUTOFUNC(StateType, _Cf* (ant_pow(T,_eta)*ant_exp(-_Ea/T + _D*T)))
129 
131  template <typename StateType>
132  ANTIOCH_AUTO(StateType)
133  operator()(const StateType& T) const
134  ANTIOCH_AUTOFUNC(StateType, this->rate(T))
135 
137  template <typename StateType>
138  ANTIOCH_AUTO(StateType)
139  derivative( const StateType& T ) const
140  ANTIOCH_AUTOFUNC(StateType, (*this)(T)*(_D + _eta/T + _Ea/(T*T)))
141 
143  template <typename StateType>
144  void rate_and_derivative(const StateType& T, StateType& rate, StateType& drate_dT) const;
145 
146 // KineticsConditions overloads
147 
149  template <typename StateType, typename VectorStateType>
150  ANTIOCH_AUTO(StateType)
151  rate(const KineticsConditions<StateType,VectorStateType>& T) const
152  ANTIOCH_AUTOFUNC(StateType, _Cf * ant_exp(_eta * T.temp_cache().lnT - _Ea/T.T() + _D*T.T()))
153 
155  template <typename StateType, typename VectorStateType>
156  ANTIOCH_AUTO(StateType)
157  operator()(const KineticsConditions<StateType,VectorStateType>& T) const
158  ANTIOCH_AUTOFUNC(StateType, this->rate(T))
159 
161  template <typename StateType, typename VectorStateType>
162  ANTIOCH_AUTO(StateType)
163  derivative( const KineticsConditions<StateType,VectorStateType>& T ) const
164  ANTIOCH_AUTOFUNC(StateType, (*this)(T)*(_D + _eta/T.T() + _Ea/(T.temp_cache().T2)))
165 
167  template <typename StateType, typename VectorStateType>
168  void rate_and_derivative(const KineticsConditions<StateType,VectorStateType>& T, StateType& rate, StateType& drate_dT) const;
169 
171  const std::string numeric() const;
172 
173  private:
174 
175  void compute_cf();
176 
177  };
178 
179  template<typename CoeffType>
180  VantHoffRate<CoeffType>::VantHoffRate(const CoeffType Cf, const CoeffType eta, const CoeffType Ea, const CoeffType D, const CoeffType Tref, const CoeffType rscale)
181  : KineticsType<CoeffType>(KineticsModel::VANTHOFF),
182  _raw_Cf(Cf),
183  _eta(eta),
184  _raw_Ea(Ea),
185  _D(D),
186  _Tref(Tref),
187  _rscale(rscale)
188  {
189  _Ea = _raw_Ea / _rscale;
190  this->compute_cf();
191 
192  return;
193  }
194 
195  template<typename CoeffType>
197  {
198  return;
199  }
200 
201  template<typename CoeffType>
202  const std::string VantHoffRate<CoeffType>::numeric() const
203  {
204  std::stringstream os;
205  os << _raw_Cf;
206  if (_eta != 0.) os << "*(T/" << _Tref << ")^" << _eta;
207  os << "*exp(-" << _raw_Ea << "/(R*T) + " << _D << "*T)";
208 
209  return os.str();
210  }
211 
212  /* ------------------------- Inline Functions -------------------------*/
213  template<typename CoeffType>
214  inline
215  void VantHoffRate<CoeffType>::set_Cf( const CoeffType Cf )
216  {
217  _raw_Cf = Cf;
218  this->compute_cf();
219 
220  return;
221  }
222 
223  template<typename CoeffType>
224  inline
225  void VantHoffRate<CoeffType>::set_Tref( const CoeffType Tref )
226  {
227  _Tref = Tref;
228  this->compute_cf();
229 
230  return;
231  }
232 
233  template<typename CoeffType>
234  inline
235  void VantHoffRate<CoeffType>::set_eta( const CoeffType eta )
236  {
237  _eta = eta;
238  this->compute_cf();
239  return;
240  }
241 
242  template<typename CoeffType>
243  inline
244  void VantHoffRate<CoeffType>::set_Ea( const CoeffType Ea )
245  {
246  _raw_Ea = Ea;
247  _Ea = _raw_Ea / _rscale;
248  return;
249  }
250 
251  template<typename CoeffType>
252  inline
253  void VantHoffRate<CoeffType>::reset_Ea( const CoeffType Ea )
254  {
255  _Ea = Ea;
256  _raw_Ea = _Ea * _rscale;
257  return;
258  }
259 
260  template<typename CoeffType>
261  inline
263  {
264  _rscale = rscale;
265  _Ea = _raw_Ea / _rscale;
266  return;
267  }
268 
269  template<typename CoeffType>
270  inline
271  void VantHoffRate<CoeffType>::set_D( const CoeffType D )
272  {
273  _D = D;
274  return;
275  }
276 
277  template<typename CoeffType>
278  template <typename VectorCoeffType>
279  inline
280  void VantHoffRate<CoeffType>::reset_coefs(const VectorCoeffType & coefficients)
281  {
282  // 4 or 6
283  antioch_assert_greater(coefficients.size(),3);
284  antioch_assert_less(coefficients.size(),7);
285  antioch_assert_not_equal_to(coefficients.size(),5);
286 
287  if(coefficients.size() == 6)
288  {
289  this->set_rscale(coefficients[5]);
290  this->set_Tref(coefficients[4]);
291  }
292  this->set_Cf(coefficients[0]);
293  this->set_eta(coefficients[1]);
294  this->set_Ea(coefficients[2]);
295  this->set_D(coefficients[3]);
296  }
297 
298  template<typename CoeffType>
299  inline
301  {
302  switch(parameter)
303  {
305  {
306  this->set_rscale(new_value);
307  }
308  break;
310  {
311  this->set_Tref(new_value);
312  }
313  break;
315  {
316  this->set_Cf(new_value);
317  }
318  break;
320  {
321  this->set_eta(new_value);
322  }
323  break;
325  {
326  this->reset_Ea(new_value);
327  }
328  break;
330  {
331  this->set_D(new_value);
332  }
333  break;
334  default:
335  {
336  antioch_error();
337  }
338  break;
339  }
340  }
341 
342  template<typename CoeffType>
343  inline
345  {
346  switch(parameter)
347  {
349  {
350  return this->rscale();
351  }
352  break;
354  {
355  return this->Tref();
356  }
357  break;
359  {
360  return this->Cf();
361  }
362  break;
364  {
365  return this->eta();
366  }
367  break;
369  {
370  return this->Ea();
371  }
372  break;
374  {
375  return this->D();
376  }
377  break;
378  default:
379  {
380  antioch_error();
381  }
382  break;
383  }
384 
385  return 0;
386  }
387 
388  template<typename CoeffType>
389  inline
390  CoeffType VantHoffRate<CoeffType>::Cf() const
391  { return _Cf; }
392 
393  template<typename CoeffType>
394  inline
396  { return _eta; }
397 
398  template<typename CoeffType>
399  inline
400  CoeffType VantHoffRate<CoeffType>::Ea() const
401  { return _raw_Ea; }
402 
403  template<typename CoeffType>
404  inline
406  { return _Ea; }
407 
408  template<typename CoeffType>
409  inline
410  CoeffType VantHoffRate<CoeffType>::D() const
411  { return _D; }
412 
413  template<typename CoeffType>
414  inline
416  { return _Tref; }
417 
418  template<typename CoeffType>
419  inline
421  { return _rscale; }
422 
423  template<typename CoeffType>
424  template<typename StateType>
425  inline
426  void VantHoffRate<CoeffType>::rate_and_derivative( const StateType& T,
427  StateType& rate,
428  StateType& drate_dT) const
429  {
430  rate = (*this)(T);
431  drate_dT = rate*(_D + _eta/T + _Ea/(T*T));
432  return;
433  }
434 
435  template<typename CoeffType>
436  template<typename StateType, typename VectorStateType>
437  inline
438  void VantHoffRate<CoeffType>::rate_and_derivative( const KineticsConditions<StateType,VectorStateType>& T,
439  StateType& rate,
440  StateType& drate_dT) const
441  {
442  rate = (*this)(T);
443  drate_dT = rate*(_D + _eta/T.T() + _Ea/(T.temp_cache().T2));
444  return;
445  }
446 
447  template<typename CoeffType>
448  inline
450  {
451  _Cf = _raw_Cf * ant_pow(KineticsModel::Tref<CoeffType>()/_Tref,_eta);
452  return;
453  }
454 
455 } // end namespace Antioch
456 
457 #endif // ANTIOCH_VAN_T_HOFF_RATE_H
void reset_coefs(const VectorCoeffType &coefficients)
reset the coeffs
_Cf * ant_exp(_eta *T.temp_cache().lnT-_Ea/T.T()+_D *T.T())) template< typename StateType
CoeffType D() const
void set_parameter(KineticsModel::Parameters parameter, VectorCoeffType new_value)
for compatibility purpose with photochemistry (particle flux reactions)
base class for kinetics models
Definition: kinetics_type.h:82
CoeffType rscale() const
#define antioch_assert_greater(expr1, expr2)
CoeffType get_parameter(KineticsModel::Parameters parameter) const
get one parameter, characterized by enum
#define antioch_assert_not_equal_to(expr1, expr2)
#define antioch_assert_less(expr1, expr2)
void set_parameter(KineticsModel::Parameters parameter, CoeffType new_value)
set one parameter, characterized by enum
_Cf(*) StateType StateType &drate_d const)
#define antioch_error()
void reset_Ea(const CoeffType Ea)
set _Ea, unit is K, _raw_Ea is computed
void set_Cf(const CoeffType Cf)
CoeffType Ea() const
CoeffType Ea_K() const
const std::string numeric() const
print equation
_Cf(* this)(T)*(_D+_eta/T+_Ea/(T *T))) template< typename StateType > void rate_and_derivative(const StateType &T
Simultaneously evaluate the rate and its derivative at T.
void set_D(const CoeffType D)
VantHoffRate(const CoeffType Cf=0., const CoeffType eta=0., const CoeffType Ea=0., const CoeffType D=0., const CoeffType Tref=1., const CoeffType rscale=Constants::R_universal< CoeffType >())
void set_Tref(const CoeffType Tref)
_Cf * ant_pow(T, _eta)*ant_exp(-_Ea/T+_D *T))) template< typename StateType > operator()(const StateType &T) const template< typename StateType > derivative(const StateType &T) const ANTIOCH_AUTOFUNC(StateType
_Cf VectorStateType VectorStateType(*) VectorStateType voi rate_and_derivative)(const KineticsConditions< StateType, VectorStateType > &T, StateType &rate, StateType &drate_dT) const
#define ANTIOCH_AUTOFUNC(Type, Expr)
const ANTIOCH_AUTO(StateType) KineticsTheoryThermalConductivity< ThermoEvaluator
Van't Hoff rate equation.
Definition: kinetics_type.h:62
void set_rscale(const CoeffType rscale)
_Cf(*) StateType rate)
The parameters are reduced parameters.
CoeffType Tref() const
void set_Ea(const CoeffType Ea)
set _raw_Ea, unit is known (cal.mol-1, J.mol-1, whatever), _Ea is computed
CoeffType eta() const
CoeffType Cf() const
This class contains the conditions of the chemistry.
void set_eta(const CoeffType eta)
_Cf VectorStateType VectorStateType derivative(const KineticsConditions< StateType, VectorStateType > &T) const ANTIOCH_AUTOFUNC(StateType

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