35 template <
typename Scalar>
42 const Scalar Cf = 1.4;
43 const Scalar Ea = 5.0;
44 const Scalar beta = 1.2;
45 const Scalar
D = 2.5e-2;
47 const std::string equation(
"A + B -> C + D");
48 const unsigned int n_species(4);
51 std::vector<Scalar> mol_densities;
52 mol_densities.push_back(1e-2);
53 mol_densities.push_back(1e-2);
54 mol_densities.push_back(1e-2);
55 mol_densities.push_back(1e-2);
56 std::vector<Scalar> species_eff;
57 species_eff.push_back(0.4);
58 species_eff.push_back(0.54);
59 species_eff.push_back(0.5);
60 species_eff.push_back(1.0);
63 for(
unsigned int i = 0; i < n_species; i++)
65 TB_term += species_eff[i] * mol_densities[i];
69 const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 100;
71 for(Scalar T = 300.1; T <= 2500.1; T += 10.)
76 for(
unsigned int ikinmod = 0; ikinmod < 6; ikinmod++)
82 std::vector<Scalar> derive_dX_exact;
83 derive_dX_exact.resize(n_species);
92 rate_exact = Cf *
pow(T,beta) * TB_term;
93 derive_exact = Cf *
pow (T,beta) * beta/T * TB_term;
94 for(
unsigned int i = 0; i < n_species; i++)
96 derive_dX_exact[i] = Cf *
pow(T,beta) * species_eff[i];
104 rate_exact = Cf * exp(D*T) * TB_term;
105 derive_exact = Cf * exp(D*T) * D * TB_term;
106 for(
unsigned int i = 0; i < n_species; i++)
108 derive_dX_exact[i] = Cf * exp(D*T) * species_eff[i];
116 rate_exact = Cf * exp(-Ea/T) * TB_term;
117 derive_exact = Cf * exp(-Ea/T) * Ea/
pow(T,2) * TB_term;
118 for(
unsigned int i = 0; i < n_species; i++)
120 derive_dX_exact[i] = Cf * exp(-Ea/T) * species_eff[i];
128 rate_exact = Cf *
pow(T,beta) * exp(D * T) * TB_term;
129 derive_exact = Cf *
pow(T,beta) * exp(D * T) * (beta/T +
D) * TB_term;
130 for(
unsigned int i = 0; i < n_species; i++)
132 derive_dX_exact[i] = Cf *
pow(T,beta) * exp(D * T) * species_eff[i];
140 rate_exact = Cf *
pow(T,beta) * exp(-Ea/T) * TB_term;
141 derive_exact = Cf *
pow(T,beta) * exp(-Ea/T) * (beta/T + Ea/
pow(T,2)) * TB_term;
142 for(
unsigned int i = 0; i < n_species; i++)
144 derive_dX_exact[i] = Cf *
pow(T,beta) * exp(-Ea/T) * species_eff[i];
152 rate_exact = Cf *
pow(T,beta) * exp(-Ea/T + D * T) * TB_term;
153 derive_exact = Cf *
pow(T,beta) * exp(-Ea/T + D * T) * (D + beta/T + Ea/
pow(T,2)) * TB_term;
154 for(
unsigned int i = 0; i < n_species; i++)
156 derive_dX_exact[i] = Cf *
pow(T,beta) * exp(-Ea/T + D * T) * species_eff[i];
164 for(
unsigned int i = 0; i < n_species; i++)
171 std::vector<Scalar> drate_dx;
172 drate_dx.resize(n_species);
176 for(
unsigned int i = 0; i < n_species; i++)
178 if( abs( (drate_dx[i] - derive_dX_exact[i])/derive_dX_exact[i] ) > tol )
180 std::cout << std::scientific << std::setprecision(16)
181 <<
"Error: Mismatch in derivative values." << std::endl
182 <<
"Kinetics model (see enum) " << kin_mod << std::endl
183 <<
"species " << i << std::endl
184 <<
"species molar densities " << mol_densities[i] << std::endl
185 <<
"species efficiency " << species_eff[i] << std::endl
186 <<
"drate_dX = " << drate_dx[i] << std::endl
187 <<
"drate_dX_exact = " << derive_dX_exact[i] << std::endl;
191 if( abs( (rate1 - rate_exact)/rate_exact ) > tol )
193 std::cout << std::scientific << std::setprecision(16)
194 <<
"Error: Mismatch in rate values." << std::endl
195 <<
"Kinetics model (see enum) " << kin_mod << std::endl
196 <<
"T = " << T <<
" K" << std::endl
197 <<
"rate(T) = " << rate1 << std::endl
198 <<
"rate_exact = " << rate_exact << std::endl;
202 if( abs( (rate - rate_exact)/rate_exact ) > tol )
204 std::cout << std::scientific << std::setprecision(16)
205 <<
"Error: Mismatch in rate values." << std::endl
206 <<
"Kinetics model (see enum) " << kin_mod << std::endl
207 <<
"T = " << T <<
" K" << std::endl
208 <<
"rate(T) = " << rate << std::endl
209 <<
"rate_exact = " << rate_exact << std::endl;
213 if( abs( (drate_dT - derive_exact)/derive_exact ) > tol )
215 std::cout << std::scientific << std::setprecision(16)
216 <<
"Error: Mismatch in rate derivative values." << std::endl
217 <<
"Kinetics model (see enum) " << kin_mod << std::endl
218 <<
"T = " << T <<
" K" << std::endl
219 <<
"drate_dT(T) = " << drate_dT << std::endl
220 <<
"derive_exact = " << derive_exact << std::endl;
225 if(return_flag)
return return_flag;
234 return (tester<double>() ||
235 tester<long double>() ||
base class for kinetics models
Berthelot Hercourt-Essen rate equation.
A single reaction mechanism.
Antioch::enable_if_c< Antioch::is_valarray< T >::value, typename Antioch::state_type< T >::type >::type pow(const T &in, const T2 &n)
void add_forward_rate(KineticsType< CoeffType, VectorCoeffType > *rate)
Add a forward rate object.
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
void set_zero(_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &a)
Van't Hoff rate equation.
Hercourt-Essen rate equation.
StateType compute_forward_rate_coefficient(const VectorStateType &molar_densities, const KineticsConditions< StateType, VectorStateType > &conditions) const
void set_efficiency(const std::string &, const unsigned int s, const CoeffType efficiency)
This class contains the conditions of the chemistry.