43 template<
typename Scalar>
44 Scalar
HE(
const Scalar &T,
const Scalar &Cf,
const Scalar &eta,
const Scalar &Tf = 1.)
48 template<
typename Scalar>
49 Scalar
Bert(
const Scalar &T,
const Scalar &Cf,
const Scalar &
D)
51 return Cf * std::exp(D * T);
54 template<
typename Scalar>
55 Scalar
BHE(
const Scalar &T,
const Scalar &Cf,
const Scalar &eta,
const Scalar &
D,
const Scalar &Tf = 1.)
57 return Cf *
std::pow(T/Tf,eta) * std::exp(D * T);
60 template<
typename Scalar>
61 Scalar
Arrh(
const Scalar &T,
const Scalar &Cf,
const Scalar &Ea,
const Scalar &R = Antioch::Constants::R_universal<Scalar>())
63 return Cf * std::exp(-Ea /(R * T));
66 template<
typename Scalar>
67 Scalar
Kooij(
const Scalar &T,
const Scalar &Cf,
const Scalar &eta,
const Scalar &Ea,
const Scalar &Tf = 1.,
68 const Scalar &R = Antioch::Constants::R_universal<Scalar>())
70 return Cf *
std::pow(T/Tf,eta) * std::exp(-Ea /(R * T));
73 template<
typename Scalar>
74 Scalar
VH(
const Scalar &T,
const Scalar &Cf,
const Scalar &eta,
const Scalar &Ea,
const Scalar &
D,
75 const Scalar &Tf = 1.,
const Scalar &R = Antioch::Constants::R_universal<Scalar>())
77 return Cf *
std::pow(T/Tf,eta) * std::exp(-Ea /(R * T) + D * T);
80 template<
typename Scalar>
81 Scalar
FcentTroe(
const Scalar &T,
const Scalar &alpha,
const Scalar &T3,
const Scalar &T1,
const Scalar &T2 = -1.)
83 return (T2 < Scalar(0.))?(Scalar(1.) - alpha) * std::exp(-T/T3) + alpha * std::exp(-T/T1):
84 (Scalar(1.) - alpha) * std::exp(-T/T3) + alpha * std::exp(-T/T1) + std::exp(-T2/T);
87 template<
typename Scalar>
88 Scalar
coeffTroe(
const Scalar &coef1,
const Scalar &coef2,
const Scalar &Fcent)
90 return coef1 + coef2 * std::log10(Fcent);
93 template<
typename Scalar>
94 Scalar
cTroe(
const Scalar &Fcent)
101 template<
typename Scalar>
109 template<
typename Scalar>
110 Scalar
FTroe(
const Scalar &Fcent,
const Scalar &Pr)
113 return std::pow(10.L,std::log10(Fcent)/(Scalar(1.) +
115 (
nTroe(Fcent) - d * (std::log10(Pr) +
cTroe(Fcent)) ),2)));
118 template<
typename VectorScalar>
120 const VectorScalar &sigma_lambda,
const VectorScalar &sigma_sigma)
123 VectorScalar sigma_rescaled(solar_lambda.size());
127 for(
unsigned int il = 0; il < solar_irr.size() - 1; il++)
129 _k += sigma_rescaled[il] * solar_irr[il] * (solar_lambda[il+1] - solar_lambda[il]);
135 template<
typename Scalar>
136 int tester(
const std::string &kin_file,
const std::string &solar_file,
const std::string & CH4_cs_file)
139 std::vector<std::string> species_str_list;
140 species_str_list.push_back(
"N2" );
141 species_str_list.push_back(
"O2" );
142 species_str_list.push_back(
"N" );
143 species_str_list.push_back(
"O" );
144 species_str_list.push_back(
"NO" );
145 species_str_list.push_back(
"C" );
146 species_str_list.push_back(
"C2" );
147 species_str_list.push_back(
"CN" );
148 species_str_list.push_back(
"CH4" );
149 species_str_list.push_back(
"CH3" );
150 species_str_list.push_back(
"H" );
151 unsigned int n_species = species_str_list.size();
155 Antioch::read_reaction_set_data_xml<Scalar>( kin_file,
true, reaction_set );
158 std::vector<Scalar> hv,lambda;
159 std::ifstream solar_flux(solar_file);
165 getline(solar_flux,line);
168 Antioch::Units<Scalar> i_unit = solar_irra - (Antioch::Constants::Planck_constant_unit<Scalar>() + Antioch::Constants::light_celerity_unit<Scalar>() - solar_wave);
171 while(!solar_flux.eof())
174 solar_flux >> l >> i >> di;
176 hv.push_back(i /(Antioch::Constants::Planck_constant<Scalar>() * Antioch::Constants::light_celerity<Scalar>() / l)
177 * i_unit.get_SI_factor());
179 if(lambda.size() == 796)
break;
183 std::vector<Scalar> CH4_s,CH4_lambda;
184 std::ifstream CH4_file(CH4_cs_file);
190 Scalar Rcal = Antioch::Constants::R_universal<Scalar>() * Antioch::Constants::R_universal_unit<Scalar>().factor_to_some_unit(
"cal/mol/K");
191 getline(CH4_file,line);
196 while(!CH4_file.eof())
200 CH4_s.push_back(s * factor_cs);
202 if(CH4_s.size() == 137)
break;
212 std::vector<Scalar> molar_densities(n_species,5e-4);
213 Scalar tot_dens((Scalar)n_species * 5e-4);
216 std::vector<Scalar> k;
220 A = 7e18 * unitA_0.get_SI_factor();
222 k.push_back(
HE(T,A,beta));
225 A = 2e18 * unitA_0.get_SI_factor();
227 k.push_back(
Bert(T,A,D));
230 A = 5e12 * unitA_0.get_SI_factor();
232 k.push_back(
Arrh(T,A,Ea,Rcal));
234 k.push_back(
Kooij(T,A,beta,Ea,Tr,Rcal));
237 A = 5.7e9 * unitA_1.get_SI_factor();
239 k.push_back(
BHE(T,A,beta,D));
242 A = 8.4e9 * unitA_1.get_SI_factor();
245 k.push_back(
Kooij(T,A,beta,Ea,Tr,Rcal));
246 k.push_back(
Arrh(T,A,Ea,Rcal));
249 A = 3.7e11 * unitA_0.get_SI_factor();
253 k.push_back(
Kooij(T,A,beta,Ea,Tr,Scalar(1)));
256 A = 2.5e11 * unitA_0.get_SI_factor();
260 k.push_back(
VH(T,A,beta,Ea,D,Tr,Rcal));
263 Scalar A2,beta2,Ea2,D2,A3,beta3,Ea3,D3,A4,Ea4;
266 A = 7e18 * unitA_0.get_SI_factor();
268 A2 = 5e17 * unitA_0.get_SI_factor();
270 A3 = 3e18 * unitA_0.get_SI_factor();
272 k.push_back(
HE(T,A,beta) +
HE(T,A2,beta2) +
HE(T,A3,beta3));
275 A = 2e18 * unitA_0.get_SI_factor();
277 A2 = 2e+16 * unitA_0.get_SI_factor();
279 k.push_back(
Bert(T,A,D) +
Bert(T,A2,D2));
282 A = 5e+12 * unitA_0.get_SI_factor();
284 A2 = 3.5e+10 * unitA_0.get_SI_factor();
286 A3 = 1.5e+8 * unitA_0.get_SI_factor();
288 A4 = 5.5e+8 * unitA_0.get_SI_factor();
290 k.push_back(
Arrh(T,A,Ea,Rcal) +
Arrh(T,A2,Ea2,Rcal) +
Arrh(T,A3,Ea3,Rcal) +
Arrh(T,A4,Ea4,Rcal));
293 A = 5.7e+9 * unitA_1.get_SI_factor();
296 A2 = 7e+7 * unitA_1.get_SI_factor();
299 k.push_back(
BHE(T,A,beta,D) +
BHE(T,A2,beta2,D2));
302 A = 8.4e+09 * unitA_1.get_SI_factor();
305 A2 = 4e+07 * unitA_1.get_SI_factor();
308 A3 = 5e+10 * unitA_1.get_SI_factor();
311 k.push_back(
Kooij(T,A,beta,Ea,Tr,Rcal) +
Kooij(T,A2,beta2,Ea2,Tr,Rcal) +
Kooij(T,A3,beta3,Ea3,Tr,Rcal));
314 A = 3.7e+11 * unitA_0.get_SI_factor();
317 A2 = 5.0e+10 * unitA_0.get_SI_factor();
320 k.push_back(
Kooij(T,A,beta,Ea,Tr,Rcal) +
Kooij(T,A2,beta2,Ea2,Tr,Rcal));
323 A = 2.5e+11 * unitA_0.get_SI_factor();
327 A2 = 5e+10 * unitA_0.get_SI_factor();
331 A3 = 3.2e+10 * unitA_0.get_SI_factor();
335 k.push_back(
VH(T,A,beta,Ea,D,Tr,Rcal) +
VH(T,A2,beta2,Ea2,D2,Tr,Rcal) +
VH(T,A3,beta3,Ea3,D3,Tr,Rcal));
339 A = 7e18 * unitA_1.get_SI_factor();
342 k.push_back(
HE(T,A,beta) * (Scalar(n_species) - 2. + 4.2857 + 4.2857) * 5e-4);
345 A = 2e18 * unitA_1.get_SI_factor();
347 k.push_back(
Bert(T,A,D) * (Scalar(n_species) - 2. + 5.0 + 5.0) * 5e-4);
350 A = 5e12 * unitA_1.get_SI_factor();
351 k.push_back(
Arrh(T,A,Ea,Rcal) * (Scalar(n_species) - 3. + 22.0 + 22.0 + 22.0) * 5e-4);
357 k.push_back(
BHE(T,A,beta,D) * (Scalar(n_species) - 3. + 22.0 + 22.0 + 22.0) * 5e-4);
363 k.push_back(
Kooij(T,A,beta,Ea,Tr,Rcal) * (Scalar(n_species) - 3. + 22.0 + 22.0 + 22.0) * 5e-4);
366 A = 3.7e11 * unitA_1.get_SI_factor();
369 k.push_back(
Kooij(T,A,beta,Ea,Tr,Rcal) * Scalar(n_species) * 5e-4);
372 A = 2.5e11 * unitA_1.get_SI_factor();
376 k.push_back(
VH(T,A,beta,Ea,D,Tr,Rcal) * Scalar(n_species) * 5e-4);
382 A = 7e18 * unitA_1.get_SI_factor();
384 A2 = 5e15 * unitA_0.get_SI_factor();
386 k.push_back(
HE(T,A,beta) / (1./tot_dens +
HE(T,A,beta)/
HE(T,A2,beta2)) );
389 A = 5e17 * unitA_1.get_SI_factor();
391 A2 = 2e18 * unitA_0.get_SI_factor();
393 k.push_back(
Bert(T,A,D) / (1./tot_dens +
Bert(T,A,D)/
Bert(T,A2,D2)) );
396 A = 5.e+12 * unitA_1.get_SI_factor();
398 A2 = 3e+15 * unitA_0.get_SI_factor();
400 k.push_back(
Arrh(T,A,Ea,Rcal) / (1./tot_dens +
Arrh(T,A,Ea,Rcal)/
Arrh(T,A2,Ea2,Rcal)) );
406 A2 = 5.7e+9 * unitA_1.get_SI_factor();
409 k.push_back(
BHE(T,A,beta,D) / (1./tot_dens +
BHE(T,A,beta,D)/
BHE(T,A2,beta2,D2)) );
415 A2 = 8.4e+05 * unitA_1.get_SI_factor();
418 k.push_back(
Kooij(T,A,beta,Ea,Tr,Rcal) / (1./tot_dens +
Kooij(T,A,beta,Ea,Tr,Rcal)/
Kooij(T,A2,beta2,Ea2,Tr,Rcal)) );
421 A = 3.7e+11 * unitA_1.get_SI_factor();
424 A2 = 3.7e+12 * unitA_0.get_SI_factor();
427 k.push_back(
Kooij(T,A,beta,Ea,Tr,Rcal) / (1./tot_dens +
Kooij(T,A,beta,Ea,Tr,Rcal)/
Kooij(T,A2,beta2,Ea2,Tr,Rcal)) );
430 A = 5e+10 * unitA_1.get_SI_factor();
434 A2 = 2.5e+11 * unitA_0.get_SI_factor();
438 k.push_back(
VH(T,A,beta,Ea,D,Tr,Rcal) / (1./tot_dens +
VH(T,A,beta,Ea,D,Tr,Rcal)/
VH(T,A2,beta2,Ea2,D2,Tr,Rcal)) );
443 Scalar Fc,alpha,T1,T2,T3;
451 A = 7.e+18 * unitA_1.get_SI_factor();
453 A2 = 5.e+15 * unitA_0.get_SI_factor();
456 kinf =
HE(T,A2,beta2);
457 Pr = tot_dens * k0/kinf;
458 k.push_back(k0 / (1./tot_dens + k0/kinf) *
FTroe(Fc,Pr));
461 A = 5e17 * unitA_1.get_SI_factor();
463 A2 = 2e18 * unitA_0.get_SI_factor();
466 kinf =
Bert(T,A2,D2);
467 Pr = tot_dens * k0/kinf;
468 k.push_back(k0 / (1./tot_dens + k0/kinf) *
FTroe(Fc,Pr));
471 A = 5.e+12 * unitA_1.get_SI_factor();
473 A2 = 3e+15 * unitA_0.get_SI_factor();
475 k0 =
Arrh(T,A,Ea,Rcal);
476 kinf =
Arrh(T,A2,Ea2,Rcal);
477 Pr = tot_dens * k0/kinf;
478 k.push_back(k0 / (1./tot_dens + k0/kinf) *
FTroe(Fc,Pr));
484 A2 = 5.7e+9 * unitA_1.get_SI_factor();
487 k0 =
BHE(T,A,beta,D);
488 kinf =
BHE(T,A2,beta2,D2);
489 Pr = tot_dens * k0/kinf;
490 k.push_back(k0 / (1./tot_dens + k0/kinf) *
FTroe(Fc,Pr));
496 A2 = 8.4e+05 * unitA_1.get_SI_factor();
499 k0 =
Kooij(T,A,beta,Ea,Tr,Rcal);
500 kinf =
Kooij(T,A2,beta2,Ea2,Tr,Rcal);
501 Pr = tot_dens * k0/kinf;
502 k.push_back(k0 / (1./tot_dens + k0/kinf) *
FTroe(Fc,Pr));
505 A = 3.7e+11 * unitA_1.get_SI_factor();
508 A2 = 3.7e+12 * unitA_0.get_SI_factor();
511 k0 =
Kooij(T,A,beta,Ea,Tr,Rcal);
512 kinf =
Kooij(T,A2,beta2,Ea2,Tr,Rcal);
513 Pr = tot_dens * k0/kinf;
514 k.push_back(k0 / (1./tot_dens + k0/kinf) *
FTroe(Fc,Pr));
517 A = 5e+10 * unitA_1.get_SI_factor();
521 A2 = 2.5e+11 * unitA_0.get_SI_factor();
525 k0 =
VH(T,A,beta,Ea,D,Tr,Rcal);
526 kinf =
VH(T,A2,beta2,Ea2,D2,Tr,Rcal);
527 Pr = tot_dens * k0/kinf;
528 k.push_back(k0 / (1./tot_dens + k0/kinf) *
FTroe(Fc,Pr));
531 k.push_back(
k_photo(lambda,hv,CH4_lambda,CH4_s));
537 const Scalar tol = (std::numeric_limits<Scalar>::epsilon() < 1e-17L)?
538 std::numeric_limits<Scalar>::epsilon() * 5000:
539 std::numeric_limits<Scalar>::epsilon() * 100;
541 for(
unsigned int ir = 0; ir < k.size(); ir++)
546 std::cout << *reac << std::endl;
547 std::cout << std::scientific << std::setprecision(16)
548 <<
"Error in kinetics comparison\n"
549 <<
"reaction #" << ir <<
"\n"
550 <<
"temperature: " << T <<
" K" <<
"\n"
551 <<
"theory: " << k[ir] <<
"\n"
554 <<
"tolerance = " << tol
563 int main(
int argc,
char* argv[])
565 return (tester<float>(std::string(argv[1]),std::string(argv[2]),std::string(argv[3])) ||
566 tester<double>(std::string(argv[1]),std::string(argv[2]),std::string(argv[3])) ||
567 tester<long double>(std::string(argv[1]),std::string(argv[2]),std::string(argv[3])));
StateType compute_forward_rate_coefficient(const VectorStateType &molar_densities, const KineticsConditions< StateType, VectorStateType > &conditions) const
A single reaction mechanism.
int tester(const std::string &kin_file, const std::string &solar_file, const std::string &CH4_cs_file)
This class encapsulates all the reaction mechanisms considered in a chemical nonequilibrium simulatio...
Scalar Arrh(const Scalar &T, const Scalar &Cf, const Scalar &Ea, const Scalar &R=Antioch::Constants::R_universal< Scalar >())
Stores the incoming flux of particles.
const Reaction< CoeffType > & reaction(const unsigned int r) const
Scalar Kooij(const Scalar &T, const Scalar &Cf, const Scalar &eta, const Scalar &Ea, const Scalar &Tf=1., const Scalar &R=Antioch::Constants::R_universal< Scalar >())
Scalar VH(const Scalar &T, const Scalar &Cf, const Scalar &eta, const Scalar &Ea, const Scalar &D, const Scalar &Tf=1., const Scalar &R=Antioch::Constants::R_universal< Scalar >())
Scalar HE(const Scalar &T, const Scalar &Cf, const Scalar &eta, const Scalar &Tf=1.)
Scalar BHE(const Scalar &T, const Scalar &Cf, const Scalar &eta, const Scalar &D, const Scalar &Tf=1.)
Antioch::enable_if_c< Antioch::is_valarray< T >::value, typename Antioch::state_type< T >::type >::type pow(const T &in, const T2 &n)
T get_SI_factor() const
Multiplicative coefficient getter.
Scalar Bert(const Scalar &T, const Scalar &Cf, const Scalar &D)
T factor_to_some_unit(const Units< T > &target) const
Calculates the factor to any given unit.
Scalar FcentTroe(const Scalar &T, const Scalar &alpha, const Scalar &T3, const Scalar &T1, const Scalar &T2=-1.)
Scalar FTroe(const Scalar &Fcent, const Scalar &Pr)
int main(int argc, char *argv[])
void y_on_custom_grid(const VectorCoeffType &x_old, const VectorCoeffType &y_old, const VectorStateType &x_new, VectorStateType &y_new) const
Class storing chemical mixture properties.
Scalar nTroe(const Scalar &Fcent)
This class contains the conditions of the chemistry.
We parse the file here, with an exhaustive unit management.
Antioch::value_type< VectorScalar >::type k_photo(const VectorScalar &solar_lambda, const VectorScalar &solar_irr, const VectorScalar &sigma_lambda, const VectorScalar &sigma_sigma)
void add_particle_flux(const ParticleFlux< VectorStateType > &pf, unsigned int nr)
Scalar cTroe(const Scalar &Fcent)
Scalar coeffTroe(const Scalar &coef1, const Scalar &coef2, const Scalar &Fcent)