antioch-0.4.0
duplicate_process_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 
32 #include "antioch/reaction.h"
34 
35 template <typename Scalar>
36 int tester()
37 {
38  using std::abs;
39  using std::exp;
40  using std::pow;
41 
42 
43  const Scalar Cf1 = 1.4;
44  const Scalar Ea1 = 5.0;
45  const Scalar beta1 = 1.2;
46  const Scalar D1 = 2.5e-2;
47  const Scalar Cf2 = 2.0;
48  const Scalar Ea2 = 3.0;
49  const Scalar beta2 = 0.8;
50  const Scalar D2 = 3.0e-2;
51 
52  const std::string equation("A + B -> C + D");
53  const unsigned int n_species(4);
54 
55  int return_flag = 0;
56  std::vector<Scalar> mol_densities;
57  mol_densities.push_back(1e-2);
58  mol_densities.push_back(1e-2);
59  mol_densities.push_back(1e-2);
60  mol_densities.push_back(1e-2);
61 
62  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 100;
63 
64  for(Scalar T = 300.1; T <= 2500.1; T += 10.)
65  {
66 
67  const Antioch::KineticsConditions<Scalar> conditions(T);
68 
69  for(unsigned int ikinmod = 0; ikinmod < 6; ikinmod++)
70  {
71 
72  Antioch::KineticsType<Scalar> *rate_kinetics1(NULL);
73  Antioch::KineticsType<Scalar> *rate_kinetics2(NULL);
74  Scalar rate_exact;
75  Scalar derive_exact;
77 
78  switch(ikinmod)
79  {
80  case 0:
81  {
83  rate_kinetics1 = new Antioch::HercourtEssenRate<Scalar>(Cf1,beta1,1.);
84  rate_kinetics2 = new Antioch::HercourtEssenRate<Scalar>(Cf2,beta2,1.);
85  rate_exact = Cf1 * pow(T,beta1) + Cf2 * pow(T,beta2);
86  derive_exact = Cf1 * pow (T,beta1) * beta1/T + Cf2 * pow (T,beta2) * beta2/T;
87  break;
88  }
89  case 1:
90  {
92  rate_kinetics1 = new Antioch::BerthelotRate<Scalar>(Cf1,D1);
93  rate_kinetics2 = new Antioch::BerthelotRate<Scalar>(Cf2,D2);
94  rate_exact = Cf1 * exp(D1*T) + Cf2 * exp(D2*T);
95  derive_exact = Cf1 * exp(D1*T) * D1 + Cf2 * exp(D2*T) * D2;
96  break;
97  }
98  case 2:
99  {
101  rate_kinetics1 = new Antioch::ArrheniusRate<Scalar>(Cf1,Ea1,1.);
102  rate_kinetics2 = new Antioch::ArrheniusRate<Scalar>(Cf2,Ea2,1.);
103  rate_exact = Cf1 * exp(-Ea1/T) + Cf2 * exp(-Ea2/T);
104  derive_exact = Cf1 * exp(-Ea1/T) * Ea1/pow(T,2) + Cf2 * exp(-Ea2/T) * Ea2/pow(T,2);
105  break;
106  }
107  case 3:
108  {
109  kin_mod = Antioch::KineticsModel::BHE;
110  rate_kinetics1 = new Antioch::BerthelotHercourtEssenRate<Scalar>(Cf1,beta1,D1,1.);
111  rate_kinetics2 = new Antioch::BerthelotHercourtEssenRate<Scalar>(Cf2,beta2,D2,1.);
112  rate_exact = Cf1 * pow(T,beta1) * exp(D1 * T) + Cf2 * pow(T,beta2) * exp(D2 * T);
113  derive_exact = Cf1 * pow(T,beta1) * exp(D1 * T) * (beta1/T + D1) + Cf2 * pow(T,beta2) * exp(D2 * T) * (beta2/T + D2);
114  break;
115  }
116  case 4:
117  {
119  rate_kinetics1 = new Antioch::KooijRate<Scalar>(Cf1,beta1,Ea1,1.,1.);
120  rate_kinetics2 = new Antioch::KooijRate<Scalar>(Cf2,beta2,Ea2,1.,1.);
121  rate_exact = Cf1 * pow(T,beta1) * exp(-Ea1/T) + Cf2 * pow(T,beta2) * exp(-Ea2/T);
122  derive_exact = Cf1 * pow(T,beta1) * exp(-Ea1/T) * (beta1/T + Ea1/pow(T,2)) + Cf2 * pow(T,beta2) * exp(-Ea2/T) * (beta2/T + Ea2/pow(T,2));
123  break;
124  }
125  case 5:
126  {
128  rate_kinetics1 = new Antioch::VantHoffRate<Scalar>(Cf1,beta1,Ea1,D1,1.,1.);
129  rate_kinetics2 = new Antioch::VantHoffRate<Scalar>(Cf2,beta2,Ea2,D2,1.,1.);
130  rate_exact = Cf1 * pow(T,beta1) * exp(-Ea1/T + D1 * T) + Cf2 * pow(T,beta2) * exp(-Ea2/T + D2 * T);
131  derive_exact = Cf1 * pow(T,beta1) * exp(-Ea1/T + D1 * T) * (D1 + beta1/T + Ea1/pow(T,2))
132  + Cf2 * pow(T,beta2) * exp(-Ea2/T + D2 * T) * (D2 + beta2/T + Ea2/pow(T,2));
133  break;
134  }
135  }
136 
137  Antioch::DuplicateReaction<Scalar> * dupl_reaction = new Antioch::DuplicateReaction<Scalar>(n_species,equation,true,kin_mod);
138  dupl_reaction->add_forward_rate(rate_kinetics1);
139  dupl_reaction->add_forward_rate(rate_kinetics2);
140  Scalar rate1 = dupl_reaction->compute_forward_rate_coefficient(mol_densities,conditions);
141  Scalar rate(0.);
142  Scalar drate_dT(0.);
143  std::vector<Scalar> drate_dx;
144  drate_dx.resize(n_species);
145  dupl_reaction->compute_forward_rate_coefficient_and_derivatives(mol_densities,conditions,rate,drate_dT,drate_dx);
146 
147  if( abs( (rate1 - rate_exact)/rate_exact ) > tol )
148  {
149  std::cout << std::scientific << std::setprecision(16)
150  << "Error: Mismatch in rate values." << std::endl
151  << "Kinetics model (see enum) " << kin_mod << std::endl
152  << "T = " << T << " K" << std::endl
153  << "rate(T) = " << rate1 << std::endl
154  << "rate_exact = " << rate_exact << std::endl;
155 
156  return_flag = 1;
157  }
158  if( abs( (rate - rate_exact)/rate_exact ) > tol )
159  {
160  std::cout << std::scientific << std::setprecision(16)
161  << "Error: Mismatch in rate values." << std::endl
162  << "Kinetics model (see enum) " << kin_mod << std::endl
163  << "T = " << T << " K" << std::endl
164  << "rate(T) = " << rate << std::endl
165  << "rate_exact = " << rate_exact << std::endl;
166 
167  return_flag = 1;
168  }
169  if( abs( (drate_dT - derive_exact)/derive_exact ) > tol )
170  {
171  std::cout << std::scientific << std::setprecision(16)
172  << "Error: Mismatch in rate derivative values." << std::endl
173  << "Kinetics model (see enum) " << kin_mod << std::endl
174  << "T = " << T << " K" << std::endl
175  << "drate_dT(T) = " << drate_dT << std::endl
176  << "derive_exact = " << derive_exact << std::endl;
177 
178  return_flag = 1;
179  }
180  delete dupl_reaction;
181  if(return_flag)return return_flag;
182  }
183  }
184 
185  return return_flag;
186 }
187 
188 int main()
189 {
190  return (tester<double>() ||
191  tester<long double>() ||
192  tester<float>());
193 }
Berthelot rate equation.
base class for kinetics models
Definition: kinetics_type.h:82
Berthelot Hercourt-Essen rate equation.
void compute_forward_rate_coefficient_and_derivatives(const VectorStateType &molar_densities, const KineticsConditions< StateType, VectorStateType > &conditions, StateType &kfwd, StateType &dkfwd_dT, VectorStateType &dkfwd_dX) const
Antioch::enable_if_c< Antioch::is_valarray< T >::value, typename Antioch::state_type< T >::type >::type pow(const T &in, const T2 &n)
int tester()
int main()
void add_forward_rate(KineticsType< CoeffType, VectorCoeffType > *rate)
Add a forward rate object.
A single reaction mechanism.
Van't Hoff rate equation.
Definition: kinetics_type.h:62
Hercourt-Essen rate equation.
Kooij rate equation.
Definition: kinetics_type.h:59
StateType compute_forward_rate_coefficient(const VectorStateType &molar_densities, const KineticsConditions< StateType, VectorStateType > &conditions) const
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