antioch-0.4.0
Functions
kooij_rate_unit.C File Reference
#include <limits>
#include <vector>
#include "antioch/kooij_rate.h"
#include "antioch/physical_constants.h"
#include "antioch/units.h"

Go to the source code of this file.

Functions

template<typename Scalar >
int check_rate_and_derivative (const Scalar &rate_exact, const Scalar &derive_exact, const Scalar &rate, const Scalar &derive, const Scalar &T)
 
template<typename Scalar >
int test_values (const Scalar &Cf, const Scalar &eta, const Scalar &Ea, const Scalar &Tref, const Scalar &R, const Antioch::KooijRate< Scalar > &kooij_rate)
 
template<typename Scalar >
int tester ()
 
int main ()
 

Function Documentation

template<typename Scalar >
int check_rate_and_derivative ( const Scalar &  rate_exact,
const Scalar &  derive_exact,
const Scalar &  rate,
const Scalar &  derive,
const Scalar &  T 
)

Definition at line 36 of file kooij_rate_unit.C.

Referenced by test_values().

38 {
39  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 2;
40  int return_flag(0);
41  if( abs( (rate - rate_exact)/rate_exact ) > tol )
42  {
43  std::cout << std::scientific << std::setprecision(16)
44  << "Error: Mismatch in rate values." << std::endl
45  << "T = " << T << " K" << std::endl
46  << "rate(T) = " << rate << std::endl
47  << "rate_exact = " << rate_exact << std::endl
48  << "relative difference = " << abs( (rate - rate_exact)/rate_exact ) << std::endl
49  << "tolerance = " << tol << std::endl;
50 
51  return_flag = 1;
52  }
53  if( abs( (derive - derive_exact)/derive_exact ) > tol )
54  {
55  std::cout << std::scientific << std::setprecision(16)
56  << "Error: Mismatch in rate derivative values." << std::endl
57  << "T = " << T << " K" << std::endl
58  << "drate_dT(T) = " << derive << std::endl
59  << "derive_exact = " << derive_exact << std::endl
60  << "relative difference = " << abs( (derive - derive_exact)/derive_exact ) << std::endl
61  << "tolerance = " << tol << std::endl;
62 
63  return_flag = 1;
64  }
65 
66  return return_flag;
67 }
int main ( )

Definition at line 165 of file kooij_rate_unit.C.

166 {
167  return (tester<double>() ||
168  tester<long double>() ||
169  tester<float>());
170 }
template<typename Scalar >
int test_values ( const Scalar &  Cf,
const Scalar &  eta,
const Scalar &  Ea,
const Scalar &  Tref,
const Scalar &  R,
const Antioch::KooijRate< Scalar > &  kooij_rate 
)

Definition at line 70 of file kooij_rate_unit.C.

References check_rate_and_derivative(), Antioch::KooijRate< CoeffType >::derivative(), std::pow(), and Antioch::KooijRate< CoeffType >::rate_and_derivative.

Referenced by tester().

71 {
72  using std::abs;
73  using std::exp;
74  using std::pow;
75 
76  int return_flag = 0;
77 
78  for(Scalar T = 300.1L; T <= 2500.1L; T += 10.L)
79  {
80 
81  const Scalar rate_exact = Cf*pow(T/Tref,eta)*exp(-Ea/(R*T));
82  const Scalar derive_exact = exp(-Ea/(R*T)) * pow(T/Tref,eta) * Cf * (Ea/(R*T*T) + eta/T );
84 
85 // KineticsConditions
86  Scalar rate = kooij_rate(cond);
87  Scalar deriveRate = kooij_rate.derivative(cond);
88 
89  return_flag = check_rate_and_derivative(rate_exact,derive_exact,rate,deriveRate,T) || return_flag;
90 
91  kooij_rate.rate_and_derivative(cond,rate,deriveRate);
92 
93  return_flag = check_rate_and_derivative(rate_exact,derive_exact,rate,deriveRate,T) || return_flag;
94 
95 // T
96  rate = kooij_rate(T);
97  deriveRate = kooij_rate.derivative(T);
98 
99  return_flag = check_rate_and_derivative(rate_exact,derive_exact,rate,deriveRate,T) || return_flag;
100 
101  kooij_rate.rate_and_derivative(T,rate,deriveRate);
102 
103  return_flag = check_rate_and_derivative(rate_exact,derive_exact,rate,deriveRate,T) || return_flag;
104 
105  }
106  return return_flag;
107 }
int check_rate_and_derivative(const Scalar &rate_exact, const Scalar &derive_exact, const Scalar &rate, const Scalar &derive, const Scalar &T)
Antioch::enable_if_c< Antioch::is_valarray< T >::value, typename Antioch::state_type< T >::type >::type pow(const T &in, const T2 &n)
_Cf VectorStateType VectorStateType(*) VectorStateType voi rate_and_derivative)(const KineticsConditions< StateType, VectorStateType > &T, StateType &rate, StateType &drate_dT) const
Definition: kooij_rate.h:163
_Cf VectorStateType VectorStateType derivative(const KineticsConditions< StateType, VectorStateType > &T) const ANTIOCH_AUTOFUNC(StateType
This class contains the conditions of the chemistry.
template<typename Scalar >
int tester ( )

Definition at line 110 of file kooij_rate_unit.C.

References Antioch::Units< T >::get_SI_factor(), Antioch::KooijRate< CoeffType >::reset_coefs(), Antioch::KooijRate< CoeffType >::set_Cf(), Antioch::KooijRate< CoeffType >::set_Ea(), Antioch::KooijRate< CoeffType >::set_eta(), Antioch::KooijRate< CoeffType >::set_rscale(), Antioch::KooijRate< CoeffType >::set_Tref(), test_values(), and Antioch::KineticsModel::Tref().

111 {
112 
113  Scalar Cf = 1.4L;
114  Scalar eta = 1.2L;
115  Scalar Ea = 298.0L;
116  Scalar Tref = 1.L;
117  Scalar R = 1.L;
118 
119  Antioch::KooijRate<Scalar> kooij_rate(Cf,eta,Ea,Tref,R);
120 
121  int return_flag = test_values(Cf,eta,Ea,Tref,R,kooij_rate);
122 
123  Cf = 1e-7L;
124  eta = 0.7L;
125  Ea = 36000.0L;
126  Tref = 298.;
127  R = Antioch::Constants::R_universal<Scalar>() * Antioch::Units<Scalar>("cal").get_SI_factor();
128  kooij_rate.set_Cf(Cf);
129  kooij_rate.set_eta(eta);
130  kooij_rate.set_Ea(Ea);
131  kooij_rate.set_Tref(Tref);
132  kooij_rate.set_rscale(R);
133 
134  return_flag = test_values(Cf,eta,Ea,Tref,R,kooij_rate) || return_flag;
135 
136  Cf = 2.1e-7L;
137  eta = 1.1L;
138  Ea = 23000.0L;
139  std::vector<Scalar> values(3);
140  values[0] = Cf;
141  values[1] = eta;
142  values[2] = Ea;
143  kooij_rate.reset_coefs(values);
144 
145  return_flag = test_values(Cf,eta,Ea,Tref,R,kooij_rate) || return_flag;
146 
147  Cf = 2.1e-11L;
148  eta = -0.01L;
149  Ea = 100000.0L;
150  R = Antioch::Constants::R_universal<Scalar>();
151  Tref= 300.L;
152  values.resize(5);
153  values[0] = Cf;
154  values[1] = eta;
155  values[2] = Ea;
156  values[3] = Tref;
157  values[4] = R;
158  kooij_rate.reset_coefs(values);
159 
160  return_flag = test_values(Cf,eta,Ea,Tref,R,kooij_rate) || return_flag;
161 
162  return return_flag;
163 }
T get_SI_factor() const
Multiplicative coefficient getter.
Definition: units.h:334
int test_values(const Scalar &Cf, const Scalar &eta, const Scalar &Ea, const Scalar &Tref, const Scalar &R, const Antioch::KooijRate< Scalar > &kooij_rate)
Kooij rate equation.
Definition: kinetics_type.h:59
An advanced unit class.
Definition: units.h:111

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