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

Go to the source code of this file.

Functions

template<typename Scalar >
int test_values (const Scalar &Cf, const Scalar &eta, const Scalar &Ea, const Scalar &D, const Scalar &Tref, const Scalar &R, const Antioch::VantHoffRate< Scalar > &vanthoff_rate)
 
template<typename Scalar >
int tester ()
 
int main ()
 

Function Documentation

int main ( )

Definition at line 172 of file vanthoff_rate_unit.C.

173 {
174  return (tester<double>() ||
175  tester<long double>() ||
176  tester<float>());
177 }
template<typename Scalar >
int test_values ( const Scalar &  Cf,
const Scalar &  eta,
const Scalar &  Ea,
const Scalar &  D,
const Scalar &  Tref,
const Scalar &  R,
const Antioch::VantHoffRate< Scalar > &  vanthoff_rate 
)

Definition at line 36 of file vanthoff_rate_unit.C.

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

Referenced by tester().

37 {
38  using std::abs;
39  using std::exp;
40  using std::pow;
41 
42  int return_flag = 0;
43  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 100;
44 
45  for(Scalar T = 300.1L; T <= 2500.1L; T += 10.L)
46  {
47  const Scalar rate_exact = Cf * pow(T/Tref,eta) * exp(-Ea/(R*T) + D*T);
48  const Scalar derive_exact = Cf * pow(T/Tref,eta) * exp(-Ea/(R*T) + D*T) * (D + eta/T + Ea/(R*T*T));
49 
50  Scalar rate1 = vanthoff_rate(T);
51  Scalar deriveRate1 = vanthoff_rate.derivative(T);
52  Scalar rate;
53  Scalar deriveRate;
54 
55  vanthoff_rate.rate_and_derivative(T,rate,deriveRate);
56 
57  if( abs( (rate1 - rate_exact)/rate_exact ) > tol )
58  {
59  std::cout << std::scientific << std::setprecision(16)
60  << "Error: Mismatch in rate values." << std::endl
61  << "T = " << T << " K" << std::endl
62  << "rate(T) = " << rate1 << std::endl
63  << "rate_exact = " << rate_exact << std::endl
64  << "Van't Hoff: " << vanthoff_rate << std::endl;
65 
66  return_flag = 1;
67  }
68  if( abs( (rate - rate_exact)/rate_exact ) > tol )
69  {
70  std::cout << std::scientific << std::setprecision(16)
71  << "Error: Mismatch in rate values." << std::endl
72  << "T = " << T << " K" << std::endl
73  << "rate(T) = " << rate << std::endl
74  << "rate_exact = " << rate_exact << std::endl
75  << "Van't Hoff: " << vanthoff_rate << std::endl;
76 
77  return_flag = 1;
78  }
79  if( abs( (deriveRate1 - derive_exact)/derive_exact ) > tol )
80  {
81  std::cout << std::scientific << std::setprecision(16)
82  << "Error: Mismatch in rate derivative values." << std::endl
83  << "T = " << T << " K" << std::endl
84  << "drate_dT(T) = " << deriveRate1 << std::endl
85  << "derive_exact = " << derive_exact << std::endl
86  << "Van't Hoff: " << vanthoff_rate << std::endl;
87 
88  return_flag = 1;
89  }
90  if( abs( (deriveRate - derive_exact)/derive_exact ) > tol )
91  {
92  std::cout << std::scientific << std::setprecision(16)
93  << "Error: Mismatch in rate derivative values." << std::endl
94  << "T = " << T << " K" << std::endl
95  << "drate_dT(T) = " << deriveRate << std::endl
96  << "derive_exact = " << derive_exact << std::endl
97  << "Van't Hoff: " << vanthoff_rate << std::endl;
98 
99  return_flag = 1;
100  }
101  if(return_flag)break;
102  }
103 
104  return return_flag;
105 }
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
_Cf VectorStateType VectorStateType derivative(const KineticsConditions< StateType, VectorStateType > &T) const ANTIOCH_AUTOFUNC(StateType
template<typename Scalar >
int tester ( )

Definition at line 108 of file vanthoff_rate_unit.C.

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

109 {
110 
111  Scalar Cf = 1.4L;
112  Scalar eta = 1.2L;
113  Scalar Ea = 298.L;
114  Scalar D = 2.50L;
115  Scalar Tref = 1.L;
116  Scalar R = 1.L;
117 
118  Antioch::VantHoffRate<Scalar> vanthoff_rate(Cf,eta,Ea,D,Tref,R);
119 
120  int return_flag = test_values(Cf,eta,Ea,D,Tref,R,vanthoff_rate);
121 
122  Cf = 1e-7L;
123  eta = 0.8L;
124  Ea = 36000.L;
125  D = -5.0L;
126  Tref = 298.;
127  R = Antioch::Constants::R_universal<Scalar>() * Antioch::Units<Scalar>("cal").get_SI_factor();
128 
129  vanthoff_rate.set_Cf(Cf);
130  vanthoff_rate.set_eta(eta);
131  vanthoff_rate.set_Ea(Ea);
132  vanthoff_rate.set_D(D);
133  vanthoff_rate.set_Tref(Tref);
134  vanthoff_rate.set_rscale(R);
135 
136  return_flag = test_values(Cf,eta,Ea,D,Tref,R,vanthoff_rate) || return_flag;
137 
138  Cf = 2.8e-7L;
139  eta = 0.3L;
140  Ea = 45000.L;
141  D = -4.2L;
142  std::vector<Scalar> values(4);
143  values[0] = Cf;
144  values[1] = eta;
145  values[2] = Ea;
146  values[3] = D;
147  vanthoff_rate.reset_coefs(values);
148 
149  return_flag = test_values(Cf,eta,Ea,D,Tref,R,vanthoff_rate) || return_flag;
150 
151  Cf = 3.6e-11L;
152  eta = 0.235L;
153  Ea = 100000.L;
154  D = 0.025L;
155  Tref = 300.L;
156  R = Antioch::Constants::R_universal<Scalar>();
157  values.resize(6);
158  values[0] = Cf;
159  values[1] = eta;
160  values[2] = Ea;
161  values[3] = D;
162  values[4] = Tref;
163  values[5] = R;
164  vanthoff_rate.reset_coefs(values);
165 
166  return_flag = test_values(Cf,eta,Ea,D,Tref,R,vanthoff_rate) || return_flag;
167 
168 
169  return return_flag;
170 }
T get_SI_factor() const
Multiplicative coefficient getter.
Definition: units.h:334
Van't Hoff rate equation.
Definition: kinetics_type.h:62
An advanced unit class.
Definition: units.h:111
int test_values(const Scalar &Cf, const Scalar &eta, const Scalar &Ea, const Scalar &D, const Scalar &Tref, const Scalar &R, const Antioch::VantHoffRate< Scalar > &vanthoff_rate)

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