45 template <
typename Scalar>
48 const std::string& species_name,
49 Scalar molar_mass, Scalar gas_constant, Scalar formation_enthalpy,
50 Scalar n_tr_dofs,
int charge,
58 if( chem_species.
species() != species_name )
60 std::cerr <<
"Error: Name mismatch for "<< species_name << std::endl
61 <<
"name = " << chem_species.
species() << std::endl;
65 if( std::abs(chem_species.
molar_mass() - molar_mass)/molar_mass > tol )
67 std::cerr <<
"Error: Molar mass mismatch for "<< species_name << std::endl
68 <<
"molar mass = " << chem_species.
molar_mass() << std::endl;
72 if( std::abs(chem_species.
gas_constant() - gas_constant)/gas_constant > tol )
74 std::cerr <<
"Error: Gas constant mismatch for "<< species_name << std::endl
75 <<
"gas constant = " << chem_species.
gas_constant() << std::endl;
79 if( std::abs(chem_species.
formation_enthalpy() - formation_enthalpy)/formation_enthalpy > tol )
81 std::cerr <<
"Error: Formation enthalpy mismatch for "<< species_name << std::endl
86 if( chem_species.
n_tr_dofs() != n_tr_dofs )
88 std::cerr <<
"Error: Number translational DoFs mismatch for "<< species_name << std::endl
89 <<
"n_tr_dofs = " << chem_species.
n_tr_dofs() << std::endl;
93 if( chem_species.
charge() != charge )
95 std::cerr <<
"Error: Charge mismatch for "<< species_name << std::endl
96 <<
"charge = " << chem_species.
charge() << std::endl;
104 template <
typename Scalar>
109 std::vector<std::string> species_str_list;
110 const unsigned int n_species = 5;
111 species_str_list.reserve(n_species);
112 species_str_list.push_back(
"N2" );
113 species_str_list.push_back(
"O2" );
114 species_str_list.push_back(
"N" );
115 species_str_list.push_back(
"O" );
116 species_str_list.push_back(
"NO" );
118 const Scalar Mm_N = 14.008e-3L;
119 const Scalar Mm_O = 16.000e-3L;
120 const Scalar Mm_N2 = 2.L * Mm_N;
121 const Scalar Mm_O2 = 2.L * Mm_O;
122 const Scalar Mm_NO = Mm_N + Mm_O;
133 const std::map<std::string,Antioch::Species>& species_name_map = chem_mixture.
species_name_map();
135 const std::vector<Antioch::ChemicalSpecies<Scalar>*>& chemical_species = chem_mixture.
chemical_species();
136 const std::vector<Antioch::Species> species_list = chem_mixture.
species_list();
137 const std::vector<Antioch::ChemicalSpecies<Scalar>*>& default_species = default_mixture.
chemical_species();
140 const Scalar tol = (std::numeric_limits<Scalar>::epsilon() * 10 < 5e-17)?5e-17:
141 std::numeric_limits<Scalar>::epsilon() * 10;
144 for(
unsigned int i = 0; i < n_species; i++ )
146 if( species_name_map.find( species_str_list[i] )->second != species_list[i] )
148 std::cerr <<
"Error: species name map and species list ordering mismatch" << std::endl
149 <<
"species_name_map = " << species_name_map.find( species_str_list[i] )->second
150 <<
", species_list = " << species_list[i] << std::endl;
156 for(
unsigned int i = 0; i < n_species; i++ )
158 if( species_inverse_name_map.find( species_list[i] )->second != species_str_list[i] )
160 std::cerr <<
"Error: species inverse name map and species list ordering mismatch" << std::endl
161 <<
"species_inverse_name_map = " << species_inverse_name_map.find( species_list[i] )->second
162 <<
", species_str_list = " << species_str_list[i] << std::endl;
169 unsigned int index = 0;
170 Scalar molar_mass = Mm_N2;
171 if( std::abs(molar_mass - chem_mixture.
M(index))/molar_mass > tol ||
172 std::abs(molar_mass - default_mixture.
M(iN2))/molar_mass > tol)
174 std::cerr <<
"Error: Molar mass inconsistency in mixture" << std::endl
175 <<
"molar mass = " << chem_mixture.
M(index) << std::endl
176 <<
"molar mass (default mixture) = " << default_mixture.
M(iN2) << std::endl;
179 return_flag = return_flag ||
180 test_species( index, chemical_species,
"N2", molar_mass,
181 Scalar(Antioch::Constants::R_universal<Scalar>()/molar_mass),
182 Scalar(0.0), Scalar(2.5), Scalar(0), tol) ||
184 Scalar(Antioch::Constants::R_universal<Scalar>()/molar_mass),
185 Scalar(0.0), Scalar(2.5), Scalar(0), tol);
190 unsigned int index = 1;
191 Scalar molar_mass = Mm_O2;
192 if( std::abs(molar_mass - chem_mixture.
M(index)) > tol ||
193 std::abs(molar_mass - default_mixture.
M(iO2))/molar_mass > tol)
195 std::cerr <<
"Error: Molar mass inconsistency in mixture" << std::endl
196 <<
"molar mass = " << chem_mixture.
M(index) << std::endl
197 <<
"molar mass (default mixture) = " << default_mixture.
M(iO2) << std::endl;
200 return_flag = return_flag ||
201 test_species( index, chemical_species,
"O2", molar_mass,
202 Scalar(Antioch::Constants::R_universal<Scalar>()/molar_mass),
203 Scalar(0.0), Scalar(2.5), Scalar(0), tol) ||
205 Scalar(Antioch::Constants::R_universal<Scalar>()/molar_mass),
206 Scalar(0.0), Scalar(2.5), Scalar(0), tol);
211 unsigned int index = 2;
212 Scalar molar_mass = Mm_N;
213 if( std::abs(molar_mass - chem_mixture.
M(index)) > tol ||
214 std::abs(molar_mass - default_mixture.
M(iN))/molar_mass > tol)
216 std::cerr <<
"Error: Molar mass inconsistency in mixture" << std::endl
217 <<
"molar mass = " << chem_mixture.
M(index) << std::endl
218 <<
"molar mass (default mixture) = " << default_mixture.
M(iN) << std::endl;
221 return_flag = return_flag ||
223 Scalar(Antioch::Constants::R_universal<Scalar>()/molar_mass),
224 Scalar(3.3621610000e7), Scalar(1.5), Scalar(0), tol) ||
226 Scalar(Antioch::Constants::R_universal<Scalar>()/molar_mass),
227 Scalar(3.3621610000e7), Scalar(1.5), Scalar(0), tol);
232 unsigned int index = 3;
233 Scalar molar_mass = Mm_O;
234 if( std::abs(molar_mass - chem_mixture.
M(index)) > tol ||
235 std::abs(molar_mass - default_mixture.
M(iO)) > tol )
237 std::cerr <<
"Error: Molar mass inconsistency in mixture" << std::endl
238 <<
"molar mass = " << chem_mixture.
M(index) << std::endl
239 <<
"molar mass (default mixture) = " << default_mixture.
M(iO) << std::endl;
242 return_flag = return_flag ||
244 Scalar(Antioch::Constants::R_universal<Scalar>()/molar_mass),
245 Scalar(1.5420000000e7), Scalar(1.5), Scalar(0), tol) ||
247 Scalar(Antioch::Constants::R_universal<Scalar>()/molar_mass),
248 Scalar(1.5420000000e7), Scalar(1.5), Scalar(0), tol);
253 unsigned int index = 4;
254 Scalar molar_mass = Mm_NO;
255 if( std::abs(molar_mass - chem_mixture.
M(index)) > tol ||
256 std::abs(molar_mass - default_mixture.
M(iNO)) > tol )
258 std::cerr <<
"Error: Molar mass inconsistency in mixture" << std::endl
259 <<
"molar mass = " << chem_mixture.
M(index) << std::endl
260 <<
"molar mass (default mixture) = " << default_mixture.
M(iNO) << std::endl;
263 return_flag = return_flag ||
264 test_species( index, chemical_species,
"NO", molar_mass,
265 Scalar(Antioch::Constants::R_universal<Scalar>()/molar_mass),
266 Scalar(2.9961230000e6), Scalar(2.5), Scalar(0), tol) ||
268 Scalar(Antioch::Constants::R_universal<Scalar>()/molar_mass),
269 Scalar(2.9961230000e6), Scalar(2.5), Scalar(0), tol);
272 std::vector<Scalar> mass_fractions( 5, 0.2L );
274 Scalar R_exact = Antioch::Constants::R_universal<Scalar>()*( 0.2L/Mm_N2 + 0.2L/Mm_O2 + 0.2L/Mm_N + 0.2L/Mm_O + 0.2L/Mm_NO );
275 Scalar M_exact = 1.0L/( 0.2L*( 1.0L/Mm_N2 + 1.0L/Mm_O2 + 1.0L/Mm_N + 1.0L/Mm_O + 1.0L/Mm_NO) );
277 std::vector<Scalar> X_exact(5, 0.0L);
278 X_exact[0] = 0.2L*M_exact/Mm_N2;
279 X_exact[1] = 0.2L*M_exact/Mm_O2;
280 X_exact[2] = 0.2L*M_exact/Mm_N;
281 X_exact[3] = 0.2L*M_exact/Mm_O;
282 X_exact[4] = 0.2L*M_exact/Mm_NO;
284 if( abs( (chem_mixture.
R(mass_fractions) - R_exact)/R_exact) > tol )
286 std::cerr <<
"Error: Mismatch in mixture gas constant." << std::endl
287 << std::setprecision(16) << std::scientific
288 <<
"R = " << chem_mixture.
R(mass_fractions) << std::endl
289 <<
"R_exact = " << R_exact << std::endl;
293 if( abs( (chem_mixture.
M(mass_fractions) - M_exact)/M_exact ) > tol )
295 std::cerr <<
"Error: Mismatch in mixture molar mass." << std::endl
296 << std::setprecision(16) << std::scientific
297 <<
"M = " << chem_mixture.
M(mass_fractions) << std::endl
298 <<
"M_exact = " << M_exact << std::endl;
302 std::vector<Scalar> X(5, 0);
303 chem_mixture.X( chem_mixture.
M(mass_fractions), mass_fractions, X );
304 for(
unsigned int s = 0; s < 5; s++ )
306 if( abs( (X[s] - X_exact[s])/X_exact[s]) > tol )
308 std::cerr <<
"Error: Mismatch in mole fraction for species " << s << std::endl
309 << std::setprecision(16) << std::scientific
310 <<
"X = " << X[s] << std::endl
311 <<
"X_exact = " << X_exact[s] << std::endl;
322 return (tester<double>() ||
323 tester<long double>() ||
CoeffType formation_enthalpy() const
Returns formation enthalpy in units of [J/kg].
CoeffType R(const unsigned int s) const
Gas constant for species s in [J/kg-K].
const std::vector< Species > & species_list() const
const std::string & species() const
Returns a descriptive name for this species.
CoeffType M(const unsigned int s) const
Molecular weight (molar mass) for species s in kg/mol.
int test_species(const unsigned int species, const std::vector< Antioch::ChemicalSpecies< Scalar > * > &chemical_species, const std::string &species_name, Scalar molar_mass, Scalar gas_constant, Scalar formation_enthalpy, Scalar n_tr_dofs, int charge, const Scalar tol)
const std::map< std::string, Species > & species_name_map() const
Class to encapsulate data for each chemical species.
const std::map< Species, std::string > & species_inverse_name_map() const
int charge() const
Returns electrical charge number.
CoeffType n_tr_dofs() const
Returns number of translational degrees of freedom.
CoeffType gas_constant() const
Returns the species ideal gas constant in [J/kg-K].
Class storing chemical mixture properties.
CoeffType molar_mass() const
Returns the molar mass in (kg/mol)
const std::vector< ChemicalSpecies< CoeffType > * > & chemical_species() const