refactor(python/composition): updated python comp bindings to use register model

This commit is contained in:
2025-05-05 12:00:40 -04:00
parent 6bcd9d2e69
commit 7df3481ff4
2 changed files with 35 additions and 28 deletions

View File

@@ -7,6 +7,8 @@
#include "composition.h" #include "composition.h"
#include "atomicSpecies.h" #include "atomicSpecies.h"
#include "bindings.h"
namespace py = pybind11; namespace py = pybind11;
std::string sv_to_string(std::string_view sv) { std::string sv_to_string(std::string_view sv) {
@@ -19,12 +21,8 @@ std::string get_ostream_str(const composition::Composition& comp) {
return oss.str(); return oss.str();
} }
PYBIND11_MODULE(fourdsse_bindings, m) { // Module name must match meson.build
m.doc() = "Python bindings for the 4DSSE project"; // Optional module docstring
auto comp_submodule = m.def_submodule("composition", "Bindings for the Composition module");
auto chem_submodule = m.def_submodule("species", "Bindings for the Chemical Species module");
void register_comp_bindings(pybind11::module &comp_submodule) {
// --- Bindings for composition and species module --- // --- Bindings for composition and species module ---
py::class_<composition::GlobalComposition>(comp_submodule, "GlobalComposition") py::class_<composition::GlobalComposition>(comp_submodule, "GlobalComposition")
.def_readonly("specificNumberDensity", &composition::GlobalComposition::specificNumberDensity) .def_readonly("specificNumberDensity", &composition::GlobalComposition::specificNumberDensity)
@@ -135,6 +133,11 @@ PYBIND11_MODULE(fourdsse_bindings, m) { // Module name must match meson.build
return get_ostream_str(comp); // Use helper for C++ operator<< return get_ostream_str(comp); // Use helper for C++ operator<<
}); });
}
void register_species_bindings(pybind11::module &chem_submodule) {
// --- Bindings for species module --- // --- Bindings for species module ---
py::class_<chemSpecies::Species>(chem_submodule, "Species") py::class_<chemSpecies::Species>(chem_submodule, "Species")
.def("mass", &chemSpecies::Species::mass, "Get atomic mass (amu)") .def("mass", &chemSpecies::Species::mass, "Get atomic mass (amu)")
@@ -157,6 +160,4 @@ PYBIND11_MODULE(fourdsse_bindings, m) { // Module name must match meson.build
}); });
chem_submodule.attr("species") = py::cast(chemSpecies::species); // Expose the species map chem_submodule.attr("species") = py::cast(chemSpecies::species); // Expose the species map
} }

View File

@@ -0,0 +1,6 @@
#pragma once
#include <pybind11/pybind11.h>
void register_comp_bindings(pybind11::module &m);
void register_species_bindings(pybind11::module &m);