Skip to content

Commit 63ac65d

Browse files
BBArrosDiasrdbisme
authored andcommitted
adding new fucntions and test to the python interface
1 parent aefb496 commit 63ac65d

File tree

2 files changed

+188
-12
lines changed

2 files changed

+188
-12
lines changed

interface/python/src/pyMixture.cpp

Lines changed: 99 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,50 @@ void py_export_Mixture(py::module &m) {
2020
py::class_<Mutation::Mixture>(m, "Mixture")
2121
.def(py::init<Mutation::MixtureOptions>())
2222
.def(py::init<std::string &>())
23+
24+
.def("NA",
25+
[](const Mutation::Mixture &self) {
26+
return Mutation::NA;
27+
},
28+
"Returns the Avogadro's number (molecule/mol)."
29+
)
30+
31+
.def("KB",
32+
[](const Mutation::Mixture &self) {
33+
return Mutation::KB;
34+
},
35+
"Returns the Boltzmann's constant (J/molecule-K)")
36+
37+
.def("RU",
38+
[](const Mutation::Mixture &self) {
39+
return Mutation::RU;
40+
},
41+
"Returns the Universal Gas constant (J/mole-K)")
42+
43+
.def("HP",
44+
[](const Mutation::Mixture &self) {
45+
return Mutation::HP;
46+
},
47+
"Returns the Planck's constant (J-s)")
48+
49+
.def("C0",
50+
[](const Mutation::Mixture &self) {
51+
return Mutation::C0;
52+
},
53+
"Returns the Speed of light in vacuum (m/s)")
54+
55+
.def("ONEATM",
56+
[](const Mutation::Mixture &self) {
57+
return Mutation::ONEATM;
58+
},
59+
"Returns the 1 atm in Pa")
60+
61+
.def("SB",
62+
[](const Mutation::Mixture &self) {
63+
return Mutation::SB;
64+
},
65+
"Returns the Stefan-Boltzmann constant (W/m^2-K^4)")
66+
2367
.def("nElements", &Mutation::Mixture::nElements,
2468
"Returns the number of elements considered in the mixture.")
2569

@@ -380,7 +424,7 @@ void py_export_Mixture(py::module &m) {
380424
"elemental mole fractions. "
381425
"If the mole fractions are not given, then the default fractions are "
382426
"used.")
383-
.def(
427+
.def(
384428
"speciesHOverRT",
385429
[](const Mutation::Mixture &self) {
386430
std::vector<double> h_i(self.nSpecies());
@@ -400,16 +444,6 @@ void py_export_Mixture(py::module &m) {
400444
"Returns the unitless vector of species enthalpies \f$ H_i / R_u T "
401445
"\f$.")
402446

403-
.def(
404-
"speciesCpOverR",
405-
[](const Mutation::Mixture &self) {
406-
std::vector<double> h_i(self.nSpecies());
407-
self.speciesCpOverR(h_i.data());
408-
return py::array(py::cast(h_i));
409-
},
410-
"Returns the unitless vector of species specific heat at constant pressure \f$ Cp_i / R_u "
411-
"\f$.")
412-
413447
.def("mixtureHMole",
414448
static_cast<double (Mutation::Mixture::*)(void) const>(
415449
&Mutation::Mixture::mixtureHMole),
@@ -508,6 +542,26 @@ void py_export_Mixture(py::module &m) {
508542
},
509543
"Converts species mass to elemental mass fraction.")
510544

545+
.def(
546+
"convert_xe_to_ye",
547+
[](const Mutation::Mixture &self, std::vector<double> x) {
548+
std::vector<double> y(self.nElements());
549+
self.Mutation::Mixture::Thermodynamics::convert<
550+
Mutation::Thermodynamics::XE_TO_YE>(x.data(), y.data());
551+
return py::array(py::cast(y));
552+
},
553+
"Converts elemental mole fraction to elemental mass fractions.")
554+
555+
.def(
556+
"convert_ye_to_xe",
557+
[](const Mutation::Mixture &self, std::vector<double> x) {
558+
std::vector<double> y(self.nElements());
559+
self.Mutation::Mixture::Thermodynamics::convert<
560+
Mutation::Thermodynamics::YE_TO_XE>(x.data(), y.data());
561+
return py::array(py::cast(y));
562+
},
563+
"Converts elemental mass fraction to elemental mole fractions.")
564+
511565
.def("dRhodP", &Mutation::Mixture::dRhodP,
512566
"Returns the density derivative with respect to pressure for the "
513567
"current equilibrium state.")
@@ -810,5 +864,38 @@ void py_export_Mixture(py::module &m) {
810864
return py::array(py::cast(cv_i));
811865
},
812866
"Fills the constant volume specific heat according to the used "
813-
"StateModel");
867+
"StateModel")
868+
869+
870+
.def(
871+
"getGibbsMass",
872+
[](const Mutation::Mixture &self) {
873+
Eigen::ArrayXd gibbs_i(self.nSpecies());
874+
self.Mutation::Mixture::speciesGOverRT(gibbs_i.data());
875+
gibbs_i*=self.T()* Mutation::RU/self.speciesMw();
876+
return py::array(py::cast(gibbs_i));;
877+
},
878+
"Return an array of gibbs free energy for each species per unit mass")
879+
880+
.def(
881+
"getGibbsMass",
882+
[](const Mutation::Mixture &self, double T, double P) {
883+
Eigen::ArrayXd gibbs_i(self.nSpecies());
884+
self.Mutation::Mixture::speciesGOverRT(T, P, gibbs_i.data());
885+
gibbs_i*=T* Mutation::RU/self.speciesMw();
886+
return py::array(py::cast(gibbs_i));;
887+
},
888+
"Return an array of gibbs free energy for each species per unit mass")
889+
890+
.def(
891+
"getSTGibbsMass",
892+
[](const Mutation::Mixture &self, double T) {
893+
Eigen::ArrayXd gibbs_i(self.nSpecies());
894+
self.Mutation::Mixture::speciesSTGOverRT(T, gibbs_i.data());
895+
gibbs_i*=T* Mutation::RU/self.speciesMw();
896+
return py::array(py::cast(gibbs_i));;
897+
},
898+
"Return an array of gibbs free energy for each species per unit mass at standard pressure")
899+
900+
;
814901
}

tests/python/test_mutation.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22

3+
import numpy as np
34
import mutationpp as mpp
45
import pytest
56

@@ -319,3 +320,91 @@ def test_speciesHOverRT():
319320
3.34133823e-02,
320321
]
321322
assert np.allclose(mixture.speciesHOverRT(301), expected)
323+
324+
def test_getEnergiesMass():
325+
326+
expected = mixture.getEnthalpiesMass() - mixture.T()*mixture.RU()/mixture.speciesMw()
327+
328+
assert mixture.getEnergiesMass() == pytest.approx(expected)
329+
330+
331+
def test_getEnthalpiesMass():
332+
333+
expected = [
334+
7.0098139454e+07,
335+
1.3436541662e+08,
336+
9.8062005405e+07,
337+
3.3017452040e+07,
338+
5.3888226083e+07,
339+
3.6610342011e+07,
340+
3.3732317707e+07,
341+
1.5579800144e+07,
342+
3.0374812162e+06,
343+
1.9226029990e+03,
344+
1.6962169231e+03
345+
]
346+
347+
assert mixture.getEnthalpiesMass() == pytest.approx(expected)
348+
349+
def test_getCpsMass():
350+
351+
expected = [
352+
3.7890886192e+07,
353+
1.5192147894e+03,
354+
1.2992294338e+03,
355+
9.7019017139e+02,
356+
1.0395135823e+03,
357+
9.1103684272e+02,
358+
1.4840168399e+03,
359+
1.2991848864e+03,
360+
9.7219901895e+02,
361+
1.0392575435e+03,
362+
9.1700386827e+02
363+
]
364+
365+
assert mixture.getCpsMass() == pytest.approx(expected)
366+
367+
368+
def test_getGibbsMass():
369+
370+
expected = [
371+
-3.2412103851e+10,
372+
1.3011972425e+08,
373+
9.4435909312e+07,
374+
3.0651845001e+07,
375+
5.1361201327e+07,
376+
3.4318319525e+07,
377+
2.9626009866e+07,
378+
1.1827394569e+07,
379+
5.4328552314e+05,
380+
-2.4612058750e+06,
381+
-2.2814767433e+06
382+
]
383+
384+
assert mixture.getGibbsMass() == pytest.approx(expected)
385+
386+
def test_getCvsMass():
387+
388+
expected = mixture.getCpsMass()- mixture.RU()/mixture.speciesMw()
389+
assert mixture.getCvsMass() == pytest.approx(expected)
390+
391+
def test_mixtureSMass():
392+
assert mixture.mixtureSMass() == pytest.approx(8218.83)
393+
394+
def test_NA():
395+
assert mixture.NA() == pytest.approx(6.0221415E23)
396+
397+
def test_KB():
398+
assert mixture.KB() == pytest.approx(1.3806503E-23)
399+
400+
def test_RU():
401+
assert mixture.RU() == pytest.approx(mixture.KB()* mixture.NA())
402+
403+
def test_HP():
404+
assert mixture.HP() == pytest.approx(6.626068E-34)
405+
406+
def test_C0():
407+
assert mixture.C0() == pytest.approx(299792458.0)
408+
409+
def test_ONEATM():
410+
assert mixture.ONEATM() == pytest.approx(101325.0)

0 commit comments

Comments
 (0)