feat(python/eos): added EOSInput class and getTable method to EOSio
This commit is contained in:
@@ -35,8 +35,8 @@
|
||||
#include "debug.h"
|
||||
|
||||
namespace serif::eos::helmholtz {
|
||||
constexpr int IMAX = 541;
|
||||
constexpr int JMAX = 201;
|
||||
static constexpr int IMAX = 541;
|
||||
static constexpr int JMAX = 201;
|
||||
/**
|
||||
* @brief 2D array template alias.
|
||||
* @tparam T Type of the array elements.
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "bindings.h"
|
||||
#include "EOSio.h"
|
||||
#include "helm.h"
|
||||
#include "../../eos/public/EOSio.h"
|
||||
#include "../../eos/public/helm.h"
|
||||
|
||||
namespace serif::eos {
|
||||
class EOSio;
|
||||
@@ -22,7 +24,18 @@ void register_eos_bindings(pybind11::module &eos_submodule) {
|
||||
.def(py::init<std::string>(), py::arg("filename"))
|
||||
// .def("load", &EOSio::load)
|
||||
.def("getFormat", &serif::eos::EOSio::getFormat, "Get the format of the EOS table.")
|
||||
.def("getTable", [](serif::eos::EOSio &self) -> serif::eos::helmholtz::HELMTable* {
|
||||
auto& table_variant = self.getTable();
|
||||
|
||||
// Use std::get_if to safely access the contents of the variant.
|
||||
// This returns a pointer to the value if the variant holds that type, otherwise nullptr.
|
||||
if (auto* ptr_to_unique_ptr = std::get_if<std::unique_ptr<serif::eos::helmholtz::HELMTable>>(&table_variant)) {
|
||||
return (*ptr_to_unique_ptr).get();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}, py::return_value_policy::reference_internal, // IMPORTANT: Keep this policy!
|
||||
"Get the EOS table data.")
|
||||
.def("__repr__", [](const serif::eos::EOSio &eos) {
|
||||
return "<EOSio(filename='" + eos.getFilename() + "', format='" + eos.getFormat() + "')>";
|
||||
});
|
||||
@@ -77,4 +90,17 @@ void register_eos_bindings(pybind11::module &eos_submodule) {
|
||||
py::cast(table) // Owner object (keeps C++ object alive)
|
||||
);
|
||||
}, py::return_value_policy::reference_internal); // Keep parent 'table' alive
|
||||
}
|
||||
|
||||
py::class_<serif::eos::helmholtz::EOSInput>(eos_submodule, "EOSInput")
|
||||
.def(py::init<>())
|
||||
.def_readwrite("T", &serif::eos::helmholtz::EOSInput::T)
|
||||
.def_readwrite("rho", &serif::eos::helmholtz::EOSInput::rho)
|
||||
.def_readwrite("abar", &serif::eos::helmholtz::EOSInput::abar)
|
||||
.def_readwrite("zbar", &serif::eos::helmholtz::EOSInput::zbar)
|
||||
.def("__repr__", [](const serif::eos::helmholtz::EOSInput &input) {
|
||||
return "<EOSInput(T=" + std::to_string(input.T) +
|
||||
", rho=" + std::to_string(input.rho) +
|
||||
", abar=" + std::to_string(input.abar) +
|
||||
", zbar=" + std::to_string(input.zbar) + ")>";
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user