antioch-0.4.0
vanthoff_rate_unit.C
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 // C++
28 #include <limits>
29 #include <vector>
30 // Antioch
31 #include "antioch/vanthoff_rate.h"
33 #include "antioch/units.h"
34 
35 template <typename Scalar>
36 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)
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 }
106 
107 template <typename Scalar>
108 int tester()
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 }
171 
172 int main()
173 {
174  return (tester<double>() ||
175  tester<long double>() ||
176  tester<float>());
177 }
int main()
void reset_coefs(const VectorCoeffType &coefficients)
reset the coeffs
int tester()
Antioch::enable_if_c< Antioch::is_valarray< T >::value, typename Antioch::state_type< T >::type >::type pow(const T &in, const T2 &n)
void set_Cf(const CoeffType Cf)
T get_SI_factor() const
Multiplicative coefficient getter.
Definition: units.h:334
void set_D(const CoeffType D)
void set_Tref(const CoeffType Tref)
Advanced unit class.
_Cf VectorStateType VectorStateType(*) VectorStateType voi rate_and_derivative)(const KineticsConditions< StateType, VectorStateType > &T, StateType &rate, StateType &drate_dT) const
Van't Hoff rate equation.
Definition: kinetics_type.h:62
void set_rscale(const CoeffType rscale)
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)
void set_Ea(const CoeffType Ea)
set _raw_Ea, unit is known (cal.mol-1, J.mol-1, whatever), _Ea is computed
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:47 for antioch-0.4.0 by  doxygen 1.8.8