50 template <
typename Scalar>
51 int check_test(
const Scalar &exact,
const Scalar &cal,
const std::string &words,
unsigned int rxn)
53 const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 100;
55 if(std::abs(exact - cal)/exact > tol)
57 std::cout << std::scientific << std::setprecision(20)
58 <<
"Erreur in tests of " << words <<
"\n"
59 <<
"of reaction #" << rxn <<
"\n"
60 <<
"Calculated value is " << cal <<
"\n"
61 <<
"Exact value is " << exact <<
"\n"
62 <<
"Relative error is " << std::abs(exact - cal)/exact <<
"\n"
63 <<
"Tolerance is " << tol << std::endl;
69 template <
typename Scalar>
70 int tester(
const std::string& input_name)
74 std::vector<std::string> species_str_list;
75 const unsigned int n_species = 5;
76 species_str_list.reserve(n_species);
77 species_str_list.push_back(
"N2" );
78 species_str_list.push_back(
"O2" );
79 species_str_list.push_back(
"N" );
80 species_str_list.push_back(
"O" );
81 species_str_list.push_back(
"NO" );
87 Antioch::read_reaction_set_data_xml<Scalar>( input_name,
true, reaction_set );
89 const Scalar T = 1500.0;
90 const Scalar P = 1.0e5;
95 std::vector<Scalar> Y(n_species,0.2);
97 const Scalar R_mix = chem_mixture.
R(Y);
99 const Scalar rho = P/(R_mix*T);
101 std::vector<Scalar> molar_densities(n_species,0.0);
104 std::vector<Scalar> h_RT_minus_s_R(n_species);
109 std::vector<Scalar> net_rates,kfwd_const,kbkwd_const,kfwd,kbkwd,fwd_conc,bkwd_conc;
112 kfwd_const,kbkwd_const,kfwd,kbkwd,fwd_conc,bkwd_conc);
114 std::vector<Scalar> net_rates_exact,
121 net_rates_exact.resize(5,0.L);
122 kfwd_const_exact.resize(5,0.L);
123 kbkwd_const_exact.resize(5,0.L);
124 kfwd_exact.resize(5,0.L);
125 kbkwd_exact.resize(5,0.L);
126 fwd_conc_exact.resize(5,1.L);
127 bkwd_conc_exact.resize(5,1.L);
129 const Scalar Rcal = Antioch::Constants::R_universal<Scalar>() * Antioch::Constants::R_universal_unit<Scalar>().factor_to_some_unit(
"cal/mol/K");
130 const Scalar P0_RT(1.0e5/Antioch::Constants::R_universal<Scalar>()/T);
132 kfwd_const_exact[0] = 7e15L *
std::pow(T,-1.6L) * std::exp(-224801.3L/(Rcal * T)) *
133 (4.2857L * (molar_densities[2] + molar_densities[3])
134 + molar_densities[0] + molar_densities[1] + molar_densities[4] );
135 fwd_conc_exact[0] = molar_densities[0];
136 bkwd_conc_exact[0] =
std::pow(molar_densities[2],2);
139 kfwd_const_exact[1] = 2e15L *
std::pow(T,-1.5L) * std::exp(-117881.7L/(Rcal * T)) *
140 (5.0L * (molar_densities[2] + molar_densities[3])
141 + molar_densities[0] + molar_densities[1] + molar_densities[4] );
142 fwd_conc_exact[1] = molar_densities[1];
143 bkwd_conc_exact[1] =
std::pow(molar_densities[3],2);
146 kfwd_const_exact[2] = 5e9L * std::exp(-149943.0L/(Rcal * T)) *
147 (22.0L * (molar_densities[2] + molar_densities[3] + molar_densities[4])
148 + molar_densities[0] + molar_densities[1]);
149 fwd_conc_exact[2] = molar_densities[4];
150 bkwd_conc_exact[2] = molar_densities[2] * molar_densities[3];
153 kfwd_const_exact[3] = 5.7e9L *
std::pow(T,0.42) * std::exp(-85269.6L/(Rcal * T));
154 fwd_conc_exact[3] = molar_densities[0] * molar_densities[3];
157 kfwd_const_exact[4] = 8.4e9L * std::exp(-38526.0L/(Rcal * T));
158 fwd_conc_exact[4] = molar_densities[4] * molar_densities[3];
160 for(
unsigned int rxn = 0; rxn < 5; rxn++)
164 kbkwd_const_exact[rxn] = kfwd_const_exact[rxn]/reaction_set.
reaction(rxn).equilibrium_constant(P0_RT,h_RT_minus_s_R);
165 kbkwd_exact[rxn] = kbkwd_const_exact[rxn] * bkwd_conc_exact[rxn];
167 kfwd_exact[rxn] = kfwd_const_exact[rxn] * fwd_conc_exact[rxn];
168 net_rates_exact[rxn] = kfwd_exact[rxn] - kbkwd_exact[rxn];
172 for(
unsigned int rxn = 0; rxn < 5; rxn++)
174 return_flag =
check_test(net_rates_exact[rxn],net_rates[rxn],
"net rates",rxn) ||
176 return_flag =
check_test(kfwd_const_exact[rxn],kfwd_const[rxn],
"rate constant forward",rxn) ||
178 return_flag =
check_test(kfwd_exact[rxn],kfwd[rxn],
"rate forward",rxn) ||
180 return_flag =
check_test(fwd_conc_exact[rxn],fwd_conc[rxn],
"concentrations forward",rxn) ||
185 return_flag =
check_test(kbkwd_const_exact[rxn],kbkwd_const[rxn],
"rate constant backward",rxn) ||
187 return_flag =
check_test(kbkwd_exact[rxn],kbkwd[rxn],
"rate backward",rxn) ||
189 return_flag =
check_test(bkwd_conc_exact[rxn],bkwd_conc[rxn],
"concentrations backward",rxn) ||
196 int main(
int argc,
char* argv[])
202 std::cerr <<
"Error: Must specify reaction set XML input file." << std::endl;
206 return (tester<float>(std::string(argv[1])) ||
207 tester<double>(std::string(argv[1])));
This class encapsulates all the reaction mechanisms considered in a chemical nonequilibrium simulatio...
CoeffType R(const unsigned int s) const
Gas constant for species s in [J/kg-K].
const Reaction< CoeffType > & reaction(const unsigned int r) 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(const std::string &input_name)
int check_test(const Scalar &exact, const Scalar &cal, const std::string &words, unsigned int rxn)
X(const unsigned int species, const StateType &M, const StateType &mass_fraction) const template< typename VectorStateType > void X(typename Antioch VectorStateType void molar_densities(const StateType &rho, const VectorStateType &mass_fractions, VectorStateType &molar_densities) const
Class storing chemical mixture properties.
StateType h_RT_minus_s_R(const Cache< StateType > &cache, unsigned int species) const
We currently need different specializations for scalar vs vector inputs here.
int main(int argc, char *argv[])
This class contains the conditions of the chemistry.
void get_reactive_scheme(const KineticsConditions< StateType, VectorStateType > &conditions, const VectorStateType &molar_densities, const VectorStateType &h_RT_minus_s_R, VectorStateType &net_rates, VectorStateType &kfwd_const, VectorStateType &kbkwd_const, VectorStateType &kfwd, VectorStateType &kbkwd, VectorStateType &fwd_conc, VectorStateType &bkwd_conc) const
We parse the file here, with an exhaustive unit management.