45 template <
typename Scalar>
46 bool test_relative(
const Scalar val,
const Scalar truth,
const Scalar tol)
50 if( abs( (val-truth)/truth ) > tol )
56 template <
typename Scalar>
67 template <
typename Scalar>
70 const Scalar Mm_N = 14.008e-3;
71 const Scalar Mm_O = 16e-3;
72 const Scalar Mm_N2 = 2.L * Mm_N;
73 const Scalar Mm_O2 = 2.L * Mm_O;
74 const Scalar Mm_NO = Mm_O + Mm_N;
76 std::vector<std::string> species_str_list;
77 const unsigned int n_species = 5;
78 species_str_list.reserve(n_species);
79 species_str_list.push_back(
"N2" );
80 species_str_list.push_back(
"O2" );
81 species_str_list.push_back(
"N" );
82 species_str_list.push_back(
"O" );
83 species_str_list.push_back(
"NO" );
91 std::vector<Scalar> mass_fractions( 5, 0.2 );
92 mass_fractions[0] = 0.5;
93 mass_fractions[1] = 0.2;
94 mass_fractions[2] = 0.1;
95 mass_fractions[3] = 0.1;
96 mass_fractions[4] = 0.1;
98 Scalar cv_tr_mix = 0.0;
100 const Scalar R_N2 = Antioch::Constants::R_universal<Scalar>() / Mm_N2;
101 const Scalar R_O2 = Antioch::Constants::R_universal<Scalar>() / Mm_O2;
102 const Scalar R_N = Antioch::Constants::R_universal<Scalar>() / Mm_N;
103 const Scalar R_O = Antioch::Constants::R_universal<Scalar>() / Mm_O;
104 const Scalar R_NO = Antioch::Constants::R_universal<Scalar>() / Mm_NO;
108 Scalar tol = std::numeric_limits<Scalar>::epsilon() * 2;
112 Scalar cv_N2 = sm_thermo.
cv_tr(0);
116 std::cerr << std::scientific << std::setprecision(20);
117 std::cerr <<
"Error: Mismatch in cv_tr for N2."
118 <<
"\n Expected = " << R_N2*Scalar(2.5)
119 <<
"\n Computed = " << cv_N2
120 <<
"\n Diff = " << cv_N2 - R_N2*Scalar(2.5)
125 cv_tr_mix += cv_N2*mass_fractions[0];
130 Scalar cv_O2 = sm_thermo.
cv_tr(1);
134 std::cerr << std::scientific << std::setprecision(20);
135 std::cerr <<
"Error: Mismatch in cv_tr for O2."
136 <<
"\n Expected = " << R_O2*Scalar(2.5)
137 <<
"\n Computed = " << cv_O2
138 <<
"\n Diff = " << cv_O2 - R_O2*Scalar(2.5)
143 cv_tr_mix += cv_O2*mass_fractions[1];
148 Scalar cv_N = sm_thermo.
cv_tr(2);
152 std::cerr << std::scientific << std::setprecision(20);
153 std::cerr <<
"Error: Mismatch in cv_tr for N."
154 <<
"\n Expected = " << R_N*Scalar(1.5)
155 <<
"\n Computed = " << cv_N
156 <<
"\n Diff = " << cv_N - R_N*Scalar(2.5)
161 cv_tr_mix += cv_N*mass_fractions[2];
166 Scalar cv_O = sm_thermo.
cv_tr(3);
170 std::cerr << std::scientific << std::setprecision(20);
171 std::cerr <<
"Error: Mismatch in cv_tr for O."
172 <<
"\n Expected = " << R_O*Scalar(1.5)
173 <<
"\n Computed = " << cv_O
174 <<
"\n Diff = " << cv_O - R_O*Scalar(2.5)
179 cv_tr_mix += cv_O*mass_fractions[3];
184 Scalar cv_NO = sm_thermo.
cv_tr(4);
188 std::cerr << std::scientific << std::setprecision(20);
189 std::cerr <<
"Error: Mismatch in cv_tr for NO."
190 <<
"\n Expected = " << R_NO*Scalar(2.5)
191 <<
"\n Computed = " << cv_NO
192 <<
"\n Diff = " << cv_NO - R_NO*Scalar(2.5)
197 cv_tr_mix += cv_NO*mass_fractions[4];
202 Scalar cv = sm_thermo.
cv_tr(mass_fractions);
206 std::cerr << std::scientific << std::setprecision(20);
207 std::cerr <<
"Error: Mismatch in mixture cv_tr."
208 <<
"\n Expected = " << cv_tr_mix
209 <<
"\n Computed = " << cv
210 <<
"\n Diff = " << cv - cv_tr_mix
219 template <
typename Scalar>
224 const Scalar Mm_N = 14.008e-3;
225 const Scalar Mm_O = 16e-3;
226 const Scalar Mm_N2 = 2.L * Mm_N;
227 const Scalar Mm_O2 = 2.L * Mm_O;
228 const Scalar Mm_NO = Mm_O + Mm_N;
230 std::vector<std::string> species_str_list;
231 const unsigned int n_species = 5;
232 species_str_list.reserve(n_species);
233 species_str_list.push_back(
"N2" );
234 species_str_list.push_back(
"O2" );
235 species_str_list.push_back(
"N" );
236 species_str_list.push_back(
"O" );
237 species_str_list.push_back(
"NO" );
245 std::vector<Scalar> mass_fractions( 5, 0.2 );
246 mass_fractions[0] = 0.5;
247 mass_fractions[1] = 0.2;
248 mass_fractions[2] = 0.1;
249 mass_fractions[3] = 0.1;
250 mass_fractions[4] = 0.1;
252 const Scalar R_N2 = Antioch::Constants::R_universal<Scalar>() / Mm_N2;
253 const Scalar R_O2 = Antioch::Constants::R_universal<Scalar>() / Mm_O2;
254 const Scalar R_NO = Antioch::Constants::R_universal<Scalar>() / Mm_NO;
256 const Scalar th0_N2 = 3.39500e+03;
257 const Scalar th0_O2 = 2.23900e+03;
258 const Scalar th0_NO = 2.81700e+03;
261 const Scalar Tv = 1000.0;
263 const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 2;
264 const Scalar ztol = std::numeric_limits<Scalar>::epsilon();
268 Scalar cv_vib_mix = 0.0;
272 Scalar cv_vib_N2 = sm_thermo.
cv_vib (0, Tv);
274 const Scalar expv = exp(th0_N2/Tv);
275 const Scalar expvmi = expv - Scalar(1.0);
276 Scalar cv_vib_N2_true = R_N2*th0_N2*th0_N2*expv/expvmi/expvmi/Tv/Tv;
280 std::cerr << std::scientific << std::setprecision(20);
281 std::cerr <<
"Error: Mismatch in cv_vib for N2."
282 <<
"\n Expected = " << cv_vib_N2_true
283 <<
"\n Computed = " << cv_vib_N2
284 <<
"\n Diff = " << cv_vib_N2_true - cv_vib_N2
289 cv_vib_mix += mass_fractions[0]*cv_vib_N2_true;
294 Scalar cv_vib_O2 = sm_thermo.
cv_vib (1, Tv);
296 const Scalar expv = exp(th0_O2/Tv);
297 const Scalar expvmi = expv - Scalar(1.0);
298 Scalar cv_vib_O2_true = R_O2*th0_O2*th0_O2*expv/expvmi/expvmi/Tv/Tv;
302 std::cerr << std::scientific << std::setprecision(20);
303 std::cerr <<
"Error: Mismatch in cv_vib for O2."
304 <<
"\n Expected = " << cv_vib_O2_true
305 <<
"\n Computed = " << cv_vib_O2
306 <<
"\n Diff = " << cv_vib_O2_true - cv_vib_O2
311 cv_vib_mix += mass_fractions[1]*cv_vib_O2_true;
316 Scalar cv_vib_O = sm_thermo.
cv_vib (2, Tv);
320 std::cerr << std::scientific << std::setprecision(20);
321 std::cerr <<
"Error: Mismatch in cv_vib for O."
322 <<
"\n Expected = " << Scalar(0.0)
323 <<
"\n Computed = " << cv_vib_O
324 <<
"\n Diff = " << cv_vib_O
334 Scalar cv_vib_N = sm_thermo.
cv_vib (3, Tv);
338 std::cerr << std::scientific << std::setprecision(20);
339 std::cerr <<
"Error: Mismatch in cv_vib for N."
340 <<
"\n Expected = " << Scalar(0.0)
341 <<
"\n Computed = " << cv_vib_N
342 <<
"\n Diff = " << cv_vib_N
352 Scalar cv_vib_NO = sm_thermo.
cv_vib (4, Tv);
354 const Scalar expv = exp(th0_NO/Tv);
355 const Scalar expvmi = expv - Scalar(1.0);
356 Scalar cv_vib_NO_true = R_NO*th0_NO*th0_NO*expv/expvmi/expvmi/Tv/Tv;
360 std::cerr << std::scientific << std::setprecision(20);
361 std::cerr <<
"Error: Mismatch in cv_vib for NO."
362 <<
"\n Expected = " << cv_vib_NO_true
363 <<
"\n Computed = " << cv_vib_NO
364 <<
"\n Diff = " << cv_vib_NO_true - cv_vib_NO
369 cv_vib_mix += mass_fractions[4]*cv_vib_NO_true;
374 Scalar cv = sm_thermo.
cv_vib(Tv, mass_fractions);
378 std::cerr << std::scientific << std::setprecision(20);
379 std::cerr <<
"Error: Mismatch in mixture cv_vib."
380 <<
"\n Expected = " << cv_vib_mix
381 <<
"\n Computed = " << cv
382 <<
"\n Diff = " << cv - cv_vib_mix
391 template <
typename Scalar>
393 const Scalar Rs,
const Scalar Te,
unsigned int N )
399 Scalar num=0.0, den=0.0, dnum=0.0, dden=0.0;
401 for (
unsigned int i=0; i<N; ++i)
403 num += theta[i]*
static_cast<Scalar
>(g[i])*exp(-theta[i]/Te);
404 dnum += theta[i]*
static_cast<Scalar
>(g[i])*exp(-theta[i]/Te)*(theta[i]/Te/Te);
406 den +=
static_cast<Scalar
>(g[i])*exp(-theta[i]/Te);
407 dden +=
static_cast<Scalar
>(g[i])*exp(-theta[i]/Te)*(theta[i]/Te/Te);
410 cv = Rs*(dnum/den - num*dden/den/den);
415 template <
typename Scalar>
419 const Scalar Mm_O = 16.e-3L;
420 const Scalar Mm_O2 = 2.L * Mm_O;
422 std::vector<std::string> species_str_list;
423 const unsigned int n_species = 2;
424 species_str_list.reserve(n_species);
425 species_str_list.push_back(
"O2" );
426 species_str_list.push_back(
"O" );
434 std::vector<Scalar> mass_fractions( n_species, 0.2 );
435 mass_fractions[0] = 0.9;
436 mass_fractions[1] = 0.1;
438 const Scalar R_O2 = Antioch::Constants::R_universal<Scalar>() / Mm_O2;
439 const Scalar R_O = Antioch::Constants::R_universal<Scalar>() / Mm_O;
442 unsigned int g_O[5] = {5, 3, 1, 5, 1};
443 Scalar theta_O[5] = {0.00000e+00,
449 unsigned int g_O2[7] = {3, 2, 1, 1, 6, 3, 3};
450 Scalar theta_O2[7] = {0.00000e+00,
458 const Scalar Te = 1000.0;
460 const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 8;
462 Scalar cv_el_mix_true = 0.0;
468 Scalar cv_el_O2 = sm_thermo.
cv_el (0, Te);
469 Scalar cv_el_O2_true =
cv_el_compare(g_O2, theta_O2, R_O2, Te, 7);
473 std::cerr << std::scientific << std::setprecision(20);
474 std::cerr <<
"Error: Mismatch in cv_el for O2."
475 <<
"\n Expected = " << cv_el_O2_true
476 <<
"\n Computed = " << cv_el_O2
477 <<
"\n Diff = " << cv_el_O2_true - cv_el_O2
478 <<
"\n Tol = " << tol
483 cv_el_mix_true += mass_fractions[0]*cv_el_O2_true;
488 Scalar cv_el_O = sm_thermo.
cv_el (1, Te);
489 Scalar cv_el_O_true =
cv_el_compare(g_O, theta_O, R_O, Te, 5);
493 std::cerr << std::scientific << std::setprecision(20);
494 std::cerr <<
"Error: Mismatch in cv_el for O."
495 <<
"\n Expected = " << cv_el_O_true
496 <<
"\n Computed = " << cv_el_O
497 <<
"\n Diff = " << cv_el_O_true - cv_el_O
498 <<
"\n Tol = " << tol
503 cv_el_mix_true += mass_fractions[1]*cv_el_O_true;
508 Scalar cv_el = sm_thermo.
cv_el (Te, mass_fractions);
512 std::cerr << std::scientific << std::setprecision(20);
513 std::cerr <<
"Error: Mismatch in cv_el for mixture."
514 <<
"\n Expected = " << cv_el_mix_true
515 <<
"\n Computed = " << cv_el
516 <<
"\n Diff = " << cv_el_mix_true - cv_el
517 <<
"\n Tol = " << tol
527 template <
typename Scalar>
530 std::vector<std::string> species_str_list;
531 const unsigned int n_species = 5;
532 species_str_list.reserve(n_species);
533 species_str_list.push_back(
"N2" );
534 species_str_list.push_back(
"O2" );
535 species_str_list.push_back(
"N" );
536 species_str_list.push_back(
"O" );
537 species_str_list.push_back(
"NO" );
545 std::vector<Scalar> mass_fractions( 5, 0.2 );
546 mass_fractions[0] = 0.5;
547 mass_fractions[1] = 0.2;
548 mass_fractions[2] = 0.1;
549 mass_fractions[3] = 0.1;
550 mass_fractions[4] = 0.1;
556 const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 100;
560 const Scalar Texact = 300.0;
563 const Scalar e_tot = sm_thermo.
e_tot(Texact, mass_fractions);
566 const Scalar T = sm_thermo.
T_from_e_tot(e_tot, mass_fractions);
570 std::cerr << std::scientific << std::setprecision(20);
571 std::cerr <<
"Error: Mismatch in T_from_e_tot."
572 <<
"\n Expected = " << Texact
573 <<
"\n Computed = " << T
574 <<
"\n Diff = " << Texact - T
575 <<
"\n Tol = " << tol
583 const Scalar Texact = 1000.0;
586 const Scalar e_tot = sm_thermo.
e_tot(Texact, mass_fractions);
589 const Scalar T = sm_thermo.
T_from_e_tot(e_tot, mass_fractions);
593 std::cerr << std::scientific << std::setprecision(20);
594 std::cerr <<
"Error: Mismatch in T_from_e_tot."
595 <<
"\n Expected = " << Texact
596 <<
"\n Computed = " << T
597 <<
"\n Diff = " << Texact - T
598 <<
"\n Tol = " << tol
606 const Scalar Texact = 5010.0;
609 const Scalar e_tot = sm_thermo.
e_tot(Texact, mass_fractions);
612 const Scalar T = sm_thermo.
T_from_e_tot(e_tot, mass_fractions);
616 std::cerr << std::scientific << std::setprecision(20);
617 std::cerr <<
"Error: Mismatch in T_from_e_tot."
618 <<
"\n Expected = " << Texact
619 <<
"\n Computed = " << T
620 <<
"\n Diff = " << Texact - T
621 <<
"\n Tol = " << tol
634 int ierr = (test_cv_tr<double>() ||
636 test_cv_tr<float>());
639 ierr += (test_cv_vib<double>() ||
641 test_cv_vib<float>());
644 ierr += (test_cv_el<double>() ||
646 test_cv_el<float>());
649 ierr += (test_T_from_e_tot<double>() ||
651 test_T_from_e_tot<float>());
bool test_relative(const Scalar val, const Scalar truth, const Scalar tol)
Scalar cv_el_compare(const unsigned int g[], const Scalar theta[], const Scalar Rs, const Scalar Te, unsigned int N)
bool test_zero(const Scalar val, const Scalar tol)
CoeffType cv_tr(const unsigned int species) const
enable_if_c< has_size< VectorStateType >::value, typename Antioch::value_type< VectorStateType >::type >::type T_from_e_tot(const typename Antioch::value_type< VectorStateType >::type &e_tot, const VectorStateType &mass_fractions, typename Antioch::value_type< VectorStateType >::type T=-1) const
StateType cv_el(const unsigned int species, const StateType &Te) const
StateType e_tot(const unsigned int species, const StateType &T, const StateType &Tv) const
StateType cv_vib(const unsigned int species, const StateType &Tv) const
Class storing chemical mixture properties.
Scalar g(const std::vector< Scalar > &thermo, const Scalar &T)