Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose entropy to python api #300

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- [[PR232]](https://github.com/lanl/singularity-eos/pull/228) Fixed uninitialized cmake path variables

### Added (new features/APIs/variables/...)
- [[PR300]](https://github.com/lanl/singularity-eos/pull/300) Expose entropy functionality to Python API
- [[PR265]](https://github.com/lanl/singularity-eos/pull/265) Add missing UnitSystem modifier combinations to variant and EOSPAC
- [[PR279]](https://github.com/lanl/singularity-eos/pull/279) added noble-abel EoS
- [[PR274]](https://github.com/lanl/singularity-eos/pull/274) added a stiffened gas EoS
Expand Down
1 change: 1 addition & 0 deletions python/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ PYBIND11_MODULE(singularity_eos, m) {
.def_readwrite("density", &EOSState::density)
.def_readwrite("specific_internal_energy", &EOSState::specific_internal_energy)
.def_readwrite("pressure", &EOSState::pressure)
.def_readwrite("entropy", &EOSState::entropy)
.def_readwrite("temperature", &EOSState::temperature)
.def_readwrite("specific_heat", &EOSState::specific_heat)
.def_readwrite("bulk_modulus", &EOSState::bulk_modulus)
Expand Down
15 changes: 15 additions & 0 deletions python/module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ void func####NoLambdaWithScratch(const T & self, py::array_t<Real> a, py::array_
EOS_VEC_FUNC_TMPL(TemperatureFromDensityInternalEnergy, rhos, sies, temperatures)
EOS_VEC_FUNC_TMPL(InternalEnergyFromDensityTemperature, rhos, temperatures, sies)
EOS_VEC_FUNC_TMPL(PressureFromDensityTemperature, rhos, temperatures, pressures)
EOS_VEC_FUNC_TMPL(EntropyFromDensityTemperature, rhos, temperatures, pressures)
EOS_VEC_FUNC_TMPL(EntropyFromDensityInternalEnergy, rhos, sies, pressures)
EOS_VEC_FUNC_TMPL(PressureFromDensityInternalEnergy, rhos, sies, pressures)
EOS_VEC_FUNC_TMPL(SpecificHeatFromDensityTemperature, rhos, temperatures, cvs)
EOS_VEC_FUNC_TMPL(SpecificHeatFromDensityInternalEnergy, rhos, sies, cvs)
Expand All @@ -111,6 +113,7 @@ struct EOSState {
Real density;
Real specific_internal_energy;
Real pressure;
Real entropy;
Real temperature;
Real specific_heat;
Real bulk_modulus;
Expand All @@ -124,6 +127,7 @@ struct EOSState {
density(std::numeric_limits<Real>::quiet_NaN()),
specific_internal_energy(std::numeric_limits<Real>::quiet_NaN()),
pressure(std::numeric_limits<Real>::quiet_NaN()),
entropy(std::numeric_limits<Real>::quiet_NaN()),
temperature(std::numeric_limits<Real>::quiet_NaN()),
specific_heat(std::numeric_limits<Real>::quiet_NaN()),
bulk_modulus(std::numeric_limits<Real>::quiet_NaN()),
Expand All @@ -139,6 +143,7 @@ struct EOSState {
if(!std::isnan(density)) ss << "density: " << density << std::endl;
if(!std::isnan(specific_internal_energy)) ss << "specific_internal_energy: " << specific_internal_energy << std::endl;
if(!std::isnan(pressure)) ss << "pressure: " << pressure << std::endl;
if(!std::isnan(entropy)) ss << "entropy: " << entropy << std::endl;
if(!std::isnan(temperature)) ss << "temperature: " << temperature << std::endl;
if(!std::isnan(specific_heat)) ss << "specific_heat: " << specific_heat << std::endl;
if(!std::isnan(bulk_modulus)) ss << "bulk_modulus: " << bulk_modulus << std::endl;
Expand All @@ -160,6 +165,8 @@ struct VectorFunctions {
.def("InternalEnergyFromDensityTemperature", &InternalEnergyFromDensityTemperature<T>, py::arg("rhos"), py::arg("temperatures"), py::arg("sies"), py::arg("num"), py::arg("lmbdas"))
.def("PressureFromDensityTemperature", &PressureFromDensityTemperature<T>, py::arg("rhos"), py::arg("temperatures"), py::arg("pressures"), py::arg("num"), py::arg("lmbdas"))
.def("PressureFromDensityInternalEnergy", &PressureFromDensityInternalEnergy<T>, py::arg("rhos"), py::arg("sies"), py::arg("pressures"), py::arg("num"), py::arg("lmbdas"))
.def("EntropyFromDensityTemperature", &EntropyFromDensityTemperature<T>, py::arg("rhos"), py::arg("temperatures"), py::arg("pressures"), py::arg("num"), py::arg("lmbdas"))
.def("EntropyFromDensityInternalEnergy", &EntropyFromDensityInternalEnergy<T>, py::arg("rhos"), py::arg("sies"), py::arg("pressures"), py::arg("num"), py::arg("lmbdas"))
.def("SpecificHeatFromDensityTemperature", &SpecificHeatFromDensityTemperature<T>, py::arg("rhos"), py::arg("temperatures"), py::arg("cvs"), py::arg("num"), py::arg("lmbdas"))
.def("SpecificHeatFromDensityInternalEnergy", &SpecificHeatFromDensityInternalEnergy<T>, py::arg("rhos"), py::arg("sies"), py::arg("cvs"), py::arg("num"), py::arg("lmbdas"))
.def("BulkModulusFromDensityTemperature", &BulkModulusFromDensityTemperature<T>, py::arg("rhos"), py::arg("temperatures"), py::arg("bmods"), py::arg("num"), py::arg("lmbdas"))
Expand All @@ -171,6 +178,8 @@ struct VectorFunctions {
.def("InternalEnergyFromDensityTemperature", &InternalEnergyFromDensityTemperatureNoLambda<T>, py::arg("rhos"), py::arg("temperatures"), py::arg("sies"), py::arg("num"))
.def("PressureFromDensityTemperature", &PressureFromDensityTemperatureNoLambda<T>, py::arg("rhos"), py::arg("temperatures"), py::arg("pressures"), py::arg("num"))
.def("PressureFromDensityInternalEnergy", &PressureFromDensityInternalEnergyNoLambda<T>, py::arg("rhos"), py::arg("sies"), py::arg("pressures"), py::arg("num"))
.def("EntropyFromDensityTemperature", &EntropyFromDensityTemperatureNoLambda<T>, py::arg("rhos"), py::arg("temperatures"), py::arg("pressures"), py::arg("num"))
.def("EntropyFromDensityInternalEnergy", &EntropyFromDensityInternalEnergyNoLambda<T>, py::arg("rhos"), py::arg("sies"), py::arg("pressures"), py::arg("num"))
.def("SpecificHeatFromDensityTemperature", &SpecificHeatFromDensityTemperatureNoLambda<T>, py::arg("rhos"), py::arg("temperatures"), py::arg("cvs"), py::arg("num"))
.def("SpecificHeatFromDensityInternalEnergy", &SpecificHeatFromDensityInternalEnergyNoLambda<T>, py::arg("rhos"), py::arg("sies"), py::arg("cvs"), py::arg("num"))
.def("BulkModulusFromDensityTemperature", &BulkModulusFromDensityTemperatureNoLambda<T>, py::arg("rhos"), py::arg("temperatures"), py::arg("bmods"), py::arg("num"))
Expand Down Expand Up @@ -218,6 +227,8 @@ struct VectorFunctions<T,true> {
.def("InternalEnergyFromDensityTemperature", &InternalEnergyFromDensityTemperatureWithScratch<T>, py::arg("rhos"), py::arg("temperatures"), py::arg("sies"), py::arg("scratch"), py::arg("num"), py::arg("lmbdas"))
.def("PressureFromDensityTemperature", &PressureFromDensityTemperatureWithScratch<T>, py::arg("rhos"), py::arg("temperatures"), py::arg("pressures"), py::arg("scratch"), py::arg("num"), py::arg("lmbdas"))
.def("PressureFromDensityInternalEnergy", &PressureFromDensityInternalEnergyWithScratch<T>, py::arg("rhos"), py::arg("sies"), py::arg("pressures"), py::arg("scratch"), py::arg("num"), py::arg("lmbdas"))
.def("EntropyFromDensityTemperature", &EntropyFromDensityTemperatureWithScratch<T>, py::arg("rhos"), py::arg("temperatures"), py::arg("pressures"), py::arg("scratch"), py::arg("num"), py::arg("lmbdas"))
.def("EntropyFromDensityInternalEnergy", &EntropyFromDensityInternalEnergyWithScratch<T>, py::arg("rhos"), py::arg("sies"), py::arg("pressures"), py::arg("scratch"), py::arg("num"), py::arg("lmbdas"))
.def("SpecificHeatFromDensityTemperature", &SpecificHeatFromDensityTemperatureWithScratch<T>, py::arg("rhos"), py::arg("temperatures"), py::arg("cvs"), py::arg("scratch"), py::arg("num"), py::arg("lmbdas"))
.def("SpecificHeatFromDensityInternalEnergy", &SpecificHeatFromDensityInternalEnergyWithScratch<T>, py::arg("rhos"), py::arg("sies"), py::arg("cvs"), py::arg("scratch"), py::arg("num"), py::arg("lmbdas"))
.def("BulkModulusFromDensityTemperature", &BulkModulusFromDensityTemperatureWithScratch<T>, py::arg("rhos"), py::arg("temperatures"), py::arg("bmods"), py::arg("scratch"), py::arg("num"), py::arg("lmbdas"))
Expand All @@ -229,6 +240,8 @@ struct VectorFunctions<T,true> {
.def("InternalEnergyFromDensityTemperature", &InternalEnergyFromDensityTemperatureNoLambdaWithScratch<T>, py::arg("rhos"), py::arg("temperatures"), py::arg("sies"), py::arg("scratch"), py::arg("num"))
.def("PressureFromDensityTemperature", &PressureFromDensityTemperatureNoLambdaWithScratch<T>, py::arg("rhos"), py::arg("temperatures"), py::arg("pressures"), py::arg("scratch"), py::arg("num"))
.def("PressureFromDensityInternalEnergy", &PressureFromDensityInternalEnergyNoLambdaWithScratch<T>, py::arg("rhos"), py::arg("sies"), py::arg("pressures"), py::arg("scratch"), py::arg("num"))
.def("EntropyFromDensityTemperature", &EntropyFromDensityTemperatureNoLambdaWithScratch<T>, py::arg("rhos"), py::arg("temperatures"), py::arg("pressures"), py::arg("scratch"), py::arg("num"))
.def("EntropyFromDensityInternalEnergy", &EntropyFromDensityInternalEnergyNoLambdaWithScratch<T>, py::arg("rhos"), py::arg("sies"), py::arg("pressures"), py::arg("scratch"), py::arg("num"))
.def("SpecificHeatFromDensityTemperature", &SpecificHeatFromDensityTemperatureNoLambdaWithScratch<T>, py::arg("rhos"), py::arg("temperatures"), py::arg("cvs"), py::arg("scratch"), py::arg("num"))
.def("SpecificHeatFromDensityInternalEnergy", &SpecificHeatFromDensityInternalEnergyNoLambdaWithScratch<T>, py::arg("rhos"), py::arg("sies"), py::arg("cvs"), py::arg("scratch"), py::arg("num"))
.def("BulkModulusFromDensityTemperature", &BulkModulusFromDensityTemperatureNoLambdaWithScratch<T>, py::arg("rhos"), py::arg("temperatures"), py::arg("bmods"), py::arg("scratch"), py::arg("num"))
Expand Down Expand Up @@ -277,6 +290,8 @@ py::class_<T> eos_class(py::module_ & m, std::string name) {
.def("InternalEnergyFromDensityTemperature", &two_params<T, &T::InternalEnergyFromDensityTemperature>, py::arg("rho"), py::arg("temperature"), py::arg("lmbda"))
.def("PressureFromDensityTemperature", &two_params<T, &T::PressureFromDensityTemperature>, py::arg("rho"), py::arg("temperature"), py::arg("lmbda"))
.def("PressureFromDensityInternalEnergy", &two_params<T, &T::PressureFromDensityInternalEnergy>, py::arg("rho"), py::arg("sie"), py::arg("lmbda"))
.def("EntropyFromDensityTemperature", &two_params<T, &T::EntropyFromDensityTemperature>, py::arg("rho"), py::arg("temperature"), py::arg("lmbda"))
.def("EntropyFromDensityInternalEnergy", &two_params<T, &T::EntropyFromDensityInternalEnergy>, py::arg("rho"), py::arg("sie"), py::arg("lmbda"))
.def("SpecificHeatFromDensityTemperature", &two_params<T, &T::SpecificHeatFromDensityTemperature>, py::arg("rho"), py::arg("temperature"), py::arg("lmbda"))
.def("SpecificHeatFromDensityInternalEnergy", &two_params<T, &T::SpecificHeatFromDensityInternalEnergy>, py::arg("rho"), py::arg("sie"), py::arg("lmbda"))
.def("BulkModulusFromDensityTemperature", &two_params<T, &T::BulkModulusFromDensityTemperature>, py::arg("rho"), py::arg("temperature"), py::arg("lmbda"))
Expand Down
14 changes: 14 additions & 0 deletions test/python_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,15 @@ def setUp(self):
# Gold standard values
self.pressure_true = np.array((2.0, 8.0, 30.0))
self.temperature_true = np.array((1., 2., 3.))
self.entropy_true = np.array((-13.516481508310815, -11.43703996663098, -11.242295889838465))
self.bulkmodulus_true = np.array((2.8, 11.2, 42.))
self.heatcapacity_true = np.array((Cv, Cv, Cv))
self.gruneisen_true = np.array((gm1, gm1, gm1))

# Create arrays for the outputs
self.temperature = np.zeros(self.num)
self.pressure = np.zeros(self.num)
self.entropy = np.zeros(self.num)
self.heatcapacity = np.zeros(self.num)
self.bulkmodulus = np.zeros(self.num)
self.gruneisen = np.zeros(self.num)
Expand All @@ -296,6 +298,11 @@ def test_pressure(self):
self.eos.PressureFromDensityInternalEnergy(self.density, self.energy, self.pressure, self.num)
assert_allclose(self.pressure, self.pressure_true, rtol=1e-12)

def test_entropy(self):
"""[Vector EOS][IdealGas][Energies and densities] A S(rho, e) lookup is performed"""
self.eos.EntropyFromDensityInternalEnergy(self.density, self.energy, self.entropy, self.num)
assert_allclose(self.entropy, self.entropy_true, rtol=1e-8)

def test_cv(self):
"""[Vector EOS][IdealGas][Energies and densities] A C_v(rho, e) lookup is performed"""
self.eos.SpecificHeatFromDensityInternalEnergy(self.density, self.energy, self.heatcapacity, self.num)
Expand Down Expand Up @@ -333,13 +340,15 @@ def setUp(self):
# Gold standard values
self.energy_true = np.array((250., 500., 750.))
self.pressure_true = np.array((100., 400., 1500.))
self.entropy_true = np.array((6.0436335188299175, 8.123075060509752, 8.317819137302264))
self.bulkmodulus_true = np.array((140., 560., 2100.))
self.heatcapacity_true = np.array((Cv, Cv, Cv))
self.gruneisen_true = np.array((gm1, gm1, gm1))

# Create arrays for the outputs
self.energy = np.zeros(self.num)
self.pressure = np.zeros(self.num)
self.entropy = np.zeros(self.num)
self.heatcapacity = np.zeros(self.num)
self.bulkmodulus = np.zeros(self.num)
self.gruneisen = np.zeros(self.num)
Expand All @@ -354,6 +363,11 @@ def test_pressure(self):
self.eos.PressureFromDensityTemperature(self.density, self.temperature, self.pressure, self.num)
assert_allclose(self.pressure, self.pressure_true, rtol=1e-12)

def test_entropy(self):
"""[Vector EOS][IdealGas][Densities and temperatures] A S(rho, T) lookup is performed"""
self.eos.EntropyFromDensityTemperature(self.density, self.temperature, self.entropy, self.num)
assert_allclose(self.entropy, self.entropy_true, rtol=1e-12)

def test_cv(self):
"""[Vector EOS][IdealGas][Densities and temperatures] A C_v(rho, T) lookup is performed"""
self.eos.SpecificHeatFromDensityTemperature(self.density, self.temperature, self.heatcapacity, self.num)
Expand Down
Loading