antioch-0.4.0
lindemann_falloff_threebody_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 // Antioch
30 #include "antioch/vector_utils.h"
31 
33 #include "antioch/reaction.h"
36 
37 template <typename Scalar>
38 int tester(const std::string & type)
39 {
40  using std::abs;
41  using std::exp;
42  using std::pow;
43 
44 
45 //values for 2 CH3 (+M) <=> C2H6 (+M) for the Kooij model, Ds are made up
46 
47  const Scalar Cf1 = 1.135e36L * 1e6L * 1e-12L; //(cm3/mol)^2/s -> kmol -> m3
48  const Scalar beta1 = 1.246L; //true value is -5.246
49  const Scalar Ea1 = 1704.8L / 1.9858775L; //cal/mol
50  const Scalar D1 = -4e-2L; // K^-1
51  const Scalar Cf2 = 6.22e16L * 1e3L * 1e-12L; //cm3/mol/s -> kmol -> m3
52  const Scalar beta2 = -1.174L;
53  const Scalar Ea2 = 635.8L / 1.9858775L; //cal/mol
54  const Scalar D2 = -5e-3L;
55 
56  const std::string equation("A + B -> C + D");
57  const unsigned int n_species(4);
58 
59  int return_flag = 0;
60  std::vector<Scalar> mol_densities;
61  mol_densities.push_back(1e-2);
62  mol_densities.push_back(1e-2);
63  mol_densities.push_back(1e-2);
64  mol_densities.push_back(1e-2);
65 
66  std::vector<Scalar> epsilon;
67  epsilon.push_back(2);
68  epsilon.push_back(5);
69  epsilon.push_back(8.5);
70  epsilon.push_back(40);
71 
72  Scalar M = epsilon[0] * mol_densities[0];
73  for(unsigned int i = 1; i < n_species; i++)
74  {
75  M += epsilon[i] * mol_densities[i];
76  }
77 
78  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 70;
79  std::cout << type << ", tolerance = " << tol;
80  Scalar max_diff(-1.L);
81 
82  for(Scalar T = 300.1; T <= 1500.1; T += 10.)
83  {
84  for(unsigned int ikinmod = 0; ikinmod < 6; ikinmod++)
85  {
86 
87  Antioch::KineticsType<Scalar> *rate_kinetics1(NULL);
88  Antioch::KineticsType<Scalar> *rate_kinetics2(NULL);
89  Scalar k0,kinf,dk0_dT,dkinf_dT;
90  Scalar rate_exact;
91  Scalar derive_exact;
92  std::vector<Scalar> derive_dX_exact;
93  derive_dX_exact.resize(n_species);
95 
96  switch(ikinmod)
97  {
98  case 0:
99  {
101  rate_kinetics1 = new Antioch::HercourtEssenRate<Scalar>(Cf1,beta1,1.);
102  rate_kinetics2 = new Antioch::HercourtEssenRate<Scalar>(Cf2,beta2,1.);
103  k0 = Cf1 * pow(T,beta1); kinf = Cf2 * pow(T,beta2);
104  dk0_dT = Cf1 * pow (T,beta1) * beta1/T; dkinf_dT = Cf2 * pow (T,beta2) * beta2/T;
105  break;
106  }
107  case 1:
108  {
110  rate_kinetics1 = new Antioch::BerthelotRate<Scalar>(Cf1,D1);
111  rate_kinetics2 = new Antioch::BerthelotRate<Scalar>(Cf2,D2);
112  k0 = Cf1 * exp(D1*T); kinf = Cf2 * exp(D2*T);
113  dk0_dT = Cf1 * exp(D1*T) * D1; dkinf_dT = Cf2 * exp(D2*T) * D2;
114  break;
115  }
116  case 2:
117  {
119  rate_kinetics1 = new Antioch::ArrheniusRate<Scalar>(Cf1,Ea1,1.);
120  rate_kinetics2 = new Antioch::ArrheniusRate<Scalar>(Cf2,Ea2,1.);
121  k0 = Cf1 * exp(-Ea1/T); kinf = Cf2 * exp(-Ea2/T);
122  dk0_dT = Cf1 * exp(-Ea1/T) * Ea1/pow(T,2); dkinf_dT = Cf2 * exp(-Ea2/T) * Ea2/pow(T,2);
123  break;
124  }
125  case 3:
126  {
127  kin_mod = Antioch::KineticsModel::BHE;
128  rate_kinetics1 = new Antioch::BerthelotHercourtEssenRate<Scalar>(Cf1,beta1,D1,1.);
129  rate_kinetics2 = new Antioch::BerthelotHercourtEssenRate<Scalar>(Cf2,beta2,D2,1.);
130  k0 = Cf1 * pow(T,beta1) * exp(D1 * T); kinf = Cf2 * pow(T,beta2) * exp(D2 * T);
131  dk0_dT = Cf1 * pow(T,beta1) * exp(D1 * T) * (beta1/T + D1); dkinf_dT = Cf2 * pow(T,beta2) * exp(D2 * T) * (beta2/T + D2);
132  break;
133  }
134  case 4:
135  {
137  rate_kinetics1 = new Antioch::KooijRate<Scalar>(Cf1,beta1,Ea1,1.,1.);
138  rate_kinetics2 = new Antioch::KooijRate<Scalar>(Cf2,beta2,Ea2,1.,1.);
139  k0 = Cf1 * pow(T,beta1) * exp(-Ea1/T); kinf = Cf2 * pow(T,beta2) * exp(-Ea2/T);
140  dk0_dT = Cf1 * pow(T,beta1) * exp(-Ea1/T) * (beta1/T + Ea1/pow(T,2)); dkinf_dT = Cf2 * pow(T,beta2) * exp(-Ea2/T) * (beta2/T + Ea2/pow(T,2));
141  break;
142  }
143  case 5:
144  {
146  rate_kinetics1 = new Antioch::VantHoffRate<Scalar>(Cf1,beta1,Ea1,D1,1.,1.);
147  rate_kinetics2 = new Antioch::VantHoffRate<Scalar>(Cf2,beta2,Ea2,D2,1.,1.);
148  k0 = Cf1 * pow(T,beta1) * exp(-Ea1/T + D1 * T); kinf = Cf2 * pow(T,beta2) * exp(-Ea2/T + D2 * T);
149  dk0_dT = Cf1 * pow(T,beta1) * exp(-Ea1/T + D1 * T) * (D1 + beta1/T + Ea1/pow(T,2));
150  dkinf_dT = Cf2 * pow(T,beta2) * exp(-Ea2/T + D2 * T) * (D2 + beta2/T + Ea2/pow(T,2));
151  break;
152  }
153  }
154  rate_exact = k0 / (1.L/M + k0/kinf);
155  derive_exact = rate_exact * (dk0_dT/k0 - dk0_dT/(kinf/M + k0) + k0 * dkinf_dT/(pow(kinf,2)/M + k0*kinf));
156 
157  for(unsigned int i = 0; i < n_species; i++)
158  {
159  derive_dX_exact[i] = epsilon[i] * rate_exact/(M + pow(M,2)*k0/kinf);
160  }
161 
164 
165  fall_reaction->add_forward_rate(rate_kinetics1);
166  fall_reaction->add_forward_rate(rate_kinetics2);
167  for(unsigned int s = 0; s < n_species; s++)
168  {
169  fall_reaction->set_efficiency("",s,epsilon[s]);
170  }
171 
173  Scalar rate1 = fall_reaction->compute_forward_rate_coefficient(mol_densities,cond);
174  Scalar rate;
175  Scalar drate_dT;
176  std::vector<Scalar> drate_dx;
177  drate_dx.resize(n_species);
178  fall_reaction->compute_forward_rate_coefficient_and_derivatives(mol_densities,cond,rate,drate_dT,drate_dx);
179 
180  for(unsigned int i = 0; i < n_species; i++)
181  {
182  Scalar diff = abs( (drate_dx[i] - derive_dX_exact[i])/derive_dX_exact[i] );
183  if(diff > max_diff)max_diff = diff;
184  if( diff > tol )
185  {
186  std::cout << std::scientific << std::setprecision(16)
187  << "\nError: Mismatch in rate values." << std::endl
188  << "Kinetics model (see enum) " << kin_mod << std::endl
189  << "species " << i << std::endl
190  << "drate_dc(T) = " << drate_dx[i] << std::endl
191  << "drate_dc_exact = " << derive_dX_exact[i] << std::endl
192  << "relative error = " << abs((drate_dx[i] - derive_dX_exact[i])/derive_dX_exact[i]) << std::endl
193  << "tolerance = " << tol << std::endl;
194  return_flag = 1;
195  }
196  }
197  Scalar diff = abs( (rate1 - rate_exact)/rate_exact );
198  if(diff > max_diff)max_diff = diff;
199  if( diff > tol )
200  {
201  std::cout << std::scientific << std::setprecision(16)
202  << "\nError: Mismatch in rate values." << std::endl
203  << "Kinetics model (see enum) " << kin_mod << std::endl
204  << "T = " << T << " K" << std::endl
205  << "rate(T) = " << rate1 << std::endl
206  << "rate_exact = " << rate_exact << std::endl
207  << "relative error = " << abs((rate1 - rate_exact)/rate_exact) << std::endl
208  << "tolerance = " << tol << std::endl;
209 
210  return_flag = 1;
211  }
212  diff = abs( (rate - rate_exact)/rate_exact );
213  if(diff > max_diff)max_diff = diff;
214  if( diff > tol )
215  {
216  std::cout << std::scientific << std::setprecision(16)
217  << "\nError: Mismatch in rate values." << std::endl
218  << "Kinetics model (see enum) " << kin_mod << std::endl
219  << "T = " << T << " K" << std::endl
220  << "rate(T) = " << rate << std::endl
221  << "rate_exact = " << rate_exact << std::endl
222  << "relative error = " << abs((rate - rate_exact)/rate_exact) << std::endl
223  << "tolerance = " << tol << std::endl;
224 
225  return_flag = 1;
226  }
227  diff = abs( (drate_dT - derive_exact)/derive_exact );
228  if(diff > max_diff)max_diff = diff;
229  if( diff > tol )
230  {
231  std::cout << std::scientific << std::setprecision(16)
232  << "\nError: Mismatch in rate derivative values." << std::endl
233  << "Kinetics model (see enum) " << kin_mod << std::endl
234  << "T = " << T << " K" << std::endl
235  << "drate_dT(T) = " << drate_dT << std::endl
236  << "derive_exact = " << derive_exact << std::endl
237  << "relative error = " << abs((drate_dT - derive_exact)/derive_exact) << std::endl
238  << "tolerance = " << tol << std::endl;
239 
240  return_flag = 1;
241  }
242 
243  delete fall_reaction;
244  }
245  }
246 
247  std::cout << " and maximum difference = " << max_diff << std::endl;
248  return return_flag;
249 }
250 
251 int main()
252 {
253  return (tester<double>("double") ||
254  tester<long double>("long double") ||
255  tester<float>("float"));
256 }
Berthelot rate equation.
int tester(const std::string &type)
base class for kinetics models
Definition: kinetics_type.h:82
Base class for falloff processes coupled with efficiencies.
Berthelot Hercourt-Essen rate equation.
Antioch::enable_if_c< Antioch::is_valarray< T >::value, typename Antioch::state_type< T >::type >::type pow(const T &in, const T2 &n)
void compute_forward_rate_coefficient_and_derivatives(const VectorStateType &molar_densities, const KineticsConditions< StateType, VectorStateType > &conditions, StateType &kfwd, StateType &dkfwd_dT, VectorStateType &dkfkwd_dX) const
StateType compute_forward_rate_coefficient(const VectorStateType &molar_densities, const KineticsConditions< StateType, VectorStateType > &conditions) const
void add_forward_rate(KineticsType< CoeffType, VectorCoeffType > *rate)
Add a forward rate object.
Van't Hoff rate equation.
Definition: kinetics_type.h:62
Hercourt-Essen rate equation.
Kooij rate equation.
Definition: kinetics_type.h:59
void set_efficiency(const std::string &, const unsigned int s, const CoeffType efficiency)
This class contains the conditions of the chemistry.

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