49 template <
typename Scalar>
50 int checker(
const Scalar & theory,
const Scalar & computed,
const std::string& words)
54 const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 500;
56 const Scalar rel_error = std::abs( (computed - theory)/theory);
59 std::cerr <<
"Error: Mismatch between theory and regression values in test " << words << std::endl;
60 std::cout << std::scientific << std::setprecision(16)
61 <<
"theory value = " << theory << std::endl
62 <<
"computed value = " << computed << std::endl
63 <<
"relative difference = " << rel_error << std::endl
64 <<
"tolerance = " << tol << std::endl << std::endl;
72 template <
typename Scalar>
73 int tester(
const std::string& input_name)
77 std::vector<std::string> species_str_list;
78 const unsigned int n_species = 5;
79 species_str_list.reserve(n_species);
80 species_str_list.push_back(
"N2" );
81 species_str_list.push_back(
"O2" );
82 species_str_list.push_back(
"N" );
83 species_str_list.push_back(
"O" );
84 species_str_list.push_back(
"NO" );
90 Antioch::read_reaction_set_data_xml<Scalar>( input_name,
true, reaction_set );
92 const Scalar T = 1500.0;
93 const Scalar P = 1.0e5;
97 std::vector<Scalar> Y(n_species,0.2);
99 const Scalar R_mix = chem_mixture.
R(Y);
101 const Scalar rho = P/(R_mix*T);
103 std::vector<Scalar> molar_densities(n_species,0.0);
106 std::vector<Scalar> h_RT_minus_s_R(n_species);
107 std::vector<Scalar> dh_RT_minus_s_R_dT(n_species);
115 std::vector<Scalar> omega_dot(n_species);
116 std::vector<Scalar> omega_dot_2(n_species);
117 std::vector<Scalar> omega_dot_3(n_species);
118 std::vector<Scalar> omega_dot_4(n_species);
119 std::vector<Scalar> domega_dot_dT(n_species);
120 std::vector<Scalar> domega_dot_dT_2(n_species);
122 std::vector<std::vector<Scalar> > domega_dot_drho_s(n_species);
123 std::vector<std::vector<Scalar> > domega_dot_drho_s_2(n_species);
124 for(
unsigned int s = 0; s < n_species; s++ )
126 domega_dot_drho_s[s].resize(n_species);
127 domega_dot_drho_s_2[s].resize(n_species);
135 omega_dot_2, domega_dot_dT, domega_dot_drho_s );
142 omega_dot_4, domega_dot_dT_2, domega_dot_drho_s_2 );
144 for(
unsigned int s = 0; s < n_species; s++)
146 std::cout << std::scientific << std::setprecision(16)
147 <<
"domega_dot_dT(" << chem_mixture.
chemical_species()[s]->species() <<
") = "
148 << domega_dot_dT[s] << std::endl;
151 for(
unsigned int s = 0; s < n_species; s++)
153 for(
unsigned int t = 0; t < n_species; t++)
155 std::cout << std::scientific << std::setprecision(16)
158 << domega_dot_drho_s[s][t] << std::endl;
165 std::vector<Scalar> omega_dot_reg(n_species);
166 omega_dot_reg[0] = 9.1623705357123753e+04;
167 omega_dot_reg[1] = -3.3462025680272243e+05;
168 omega_dot_reg[2] = -2.1139216712069495e+05;
169 omega_dot_reg[3] = 1.9782018625609628e+05;
170 omega_dot_reg[4] = 2.5656853231019735e+05;
174 for(
unsigned int s = 0; s < n_species; s++)
176 return_flag =
checker(omega_dot_reg[s],omega_dot_2[s],
"omega dot2 of species " + chem_mixture.
chemical_species()[s]->species()) || return_flag;
177 return_flag =
checker(omega_dot_reg[s],omega_dot_3[s],
"omega dot3 of species " + chem_mixture.
chemical_species()[s]->species()) || return_flag;
178 return_flag =
checker(omega_dot_reg[s],omega_dot_4[s],
"omega dot4 of species " + chem_mixture.
chemical_species()[s]->species()) || return_flag;
182 std::vector<Scalar> domega_dot_reg_dT(n_species);
183 domega_dot_reg_dT[0] = 1.8014990183270937e+02;
184 domega_dot_reg_dT[1] = -5.2724437115534380e+02;
185 domega_dot_reg_dT[2] = -3.0930094476883017e+02;
186 domega_dot_reg_dT[3] = 3.7972747459781005e+02;
187 domega_dot_reg_dT[4] = 2.7666793949365456e+02;
189 for(
unsigned int s = 0; s < n_species; s++)
191 return_flag =
checker(domega_dot_reg_dT[s],domega_dot_dT[s],
"domega_dot_dT of species " + chem_mixture.
chemical_species()[s]->species()) || return_flag;
192 return_flag =
checker(domega_dot_reg_dT[s],domega_dot_dT_2[s],
"domega_dot_dT2 of species " + chem_mixture.
chemical_species()[s]->species()) || return_flag;
196 std::vector<std::vector<Scalar> > domega_dot_reg_drhos(n_species);
197 for(
unsigned int s = 0; s < n_species; s++)
199 domega_dot_reg_drhos[s].resize(n_species);
202 domega_dot_reg_drhos[0][0] = 1.9675775188085109e+04;
203 domega_dot_reg_drhos[0][1] = 1.7226141262419737e+04;
204 domega_dot_reg_drhos[0][2] = 3.2159299284723610e+06;
205 domega_dot_reg_drhos[0][3] = 1.4765214711933021e+05;
206 domega_dot_reg_drhos[0][4] = 2.3225053279918131e+06;
208 domega_dot_reg_drhos[1][0] = 8.8927385505978492e+03;
209 domega_dot_reg_drhos[1][1] = -9.9560178070099482e+06;
210 domega_dot_reg_drhos[1][2] = -9.8748760140991123e+06;
211 domega_dot_reg_drhos[1][3] = 4.6143036700500813e+05;
212 domega_dot_reg_drhos[1][4] = 8.3487375168772399e+03;
214 domega_dot_reg_drhos[2][0] = -2.2420842426881281e+04;
215 domega_dot_reg_drhos[2][1] = -4.3812843857644886e+06;
216 domega_dot_reg_drhos[2][2] = -6.8343593463263955e+06;
217 domega_dot_reg_drhos[2][3] = -5.4143671040862988e+05;
218 domega_dot_reg_drhos[2][4] = -1.2267997668149246e+06;
220 domega_dot_reg_drhos[3][0] = -1.2028166578920147e+04;
221 domega_dot_reg_drhos[3][1] = 4.9713710400172938e+06;
222 domega_dot_reg_drhos[3][2] = 5.7418898143800552e+06;
223 domega_dot_reg_drhos[3][3] = -9.1121284934572734e+05;
224 domega_dot_reg_drhos[3][4] = 1.2431710353864791e+06;
226 domega_dot_reg_drhos[4][0] = 5.8804952671184686e+03;
227 domega_dot_reg_drhos[4][1] = 9.3487050114947233e+06;
228 domega_dot_reg_drhos[4][2] = 7.7514156175730915e+06;
229 domega_dot_reg_drhos[4][3] = 8.4356704563001888e+05;
230 domega_dot_reg_drhos[4][4] = -2.3472253340802449e+06;
232 for(
unsigned int s = 0; s < n_species; s++)
234 for(
unsigned int t = 0; t < n_species; t++)
236 return_flag =
checker(domega_dot_reg_drhos[s][t],domega_dot_drho_s[s][t] ,
"domega_dot_drhos of species "
238 +
" with respect to species "
240 return_flag =
checker(domega_dot_reg_drhos[s][t],domega_dot_drho_s_2[s][t],
"domega_dot_drhos of species "
242 +
" with respect to species "
248 std::string reaction_id(
"0001");
249 std::vector<std::string> keywords;
250 keywords.push_back(
"A");
251 Scalar new_value(6e15L);
253 reaction_id =
"0002";
254 keywords[0] =
"efficiencies";
255 keywords.push_back(
"O2");
264 omega_dot_reg[0] = 8.9806036413183845e4;
265 omega_dot_reg[1] = -3.3456693672788515e5;
266 omega_dot_reg[2] = -2.0957449817675504e5;
267 omega_dot_reg[3] = 1.9776686618125900e5;
268 omega_dot_reg[4] = 2.5656853231019735e5;
270 for(
unsigned int s = 0; s < n_species; s++)
272 return_flag =
checker(omega_dot_reg[s],omega_dot[s] ,
"resetted omega dot of species " + chem_mixture.
chemical_species()[s]->species()) || return_flag;
276 reaction_id =
"0004";
277 const Scalar val(1.1L);
279 keywords.push_back(
"E");
289 omega_dot_reg[0] = 1.541307374714467399842142e4;
290 omega_dot_reg[1] = -3.345669367278851525665733e5;
291 omega_dot_reg[2] = -1.723780168437354542966397e5;
292 omega_dot_reg[3] = 1.552808795073360031682657e5;
293 omega_dot_reg[4] = 3.362510003171399296965259e5;
295 for(
unsigned int s = 0; s < n_species; s++)
297 return_flag =
checker(omega_dot_reg[s],omega_dot[s] ,
"loop-resetted omega dot of species " + chem_mixture.
chemical_species()[s]->species()) || return_flag;
303 int main(
int argc,
char* argv[])
309 std::cerr <<
"Error: Must specify reaction set XML input file." << std::endl;
313 return (tester<float>(std::string(argv[1])) ||
314 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].
void compute_mass_sources(const KC &conditions, const VectorStateType &molar_densities, const VectorStateType &h_RT_minus_s_R, VectorStateType &mass_sources)
Compute species production/destruction rates per unit volume.
void set_parameter_of_reaction(const std::string &reaction_id, const std::vector< std::string > &keywords, ParamType value)
change a parameter of a reaction
int main(int argc, char *argv[])
int tester(const std::string &input_name)
StateType dh_RT_minus_s_R_dT(const Cache< StateType > &cache, unsigned int species) const
We currently need different specializations for scalar vs vector inputs here.
int checker(const Scalar &theory, const Scalar &computed, const std::string &words)
CoeffType get_parameter_of_reaction(const std::string &reaction_id, const std::vector< std::string > &keywords) const
void set_zero(_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &a)
Class to handle computing mass source terms for a given ReactionSet.
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.
void compute_mass_sources_and_derivs(const KC &conditions, const VectorStateType &molar_densities, const VectorStateType &h_RT_minus_s_R, const VectorStateType &dh_RT_minus_s_R_dT, VectorStateType &mass_sources, VectorStateType &dmass_dT, std::vector< VectorStateType > &dmass_drho_s)
Compute species production/destruction rate derivatives.
const std::vector< ChemicalSpecies< CoeffType > * > & chemical_species() const
This class contains the conditions of the chemistry.
We parse the file here, with an exhaustive unit management.