From 8ee9a6a6090914b8cd3326accb748897ed8b5219 Mon Sep 17 00:00:00 2001 From: Emily Boudreaux Date: Fri, 13 Jun 2025 09:31:05 -0400 Subject: [PATCH] feat(pythonInterface/polytrope): added initial polytrope implimentation to the python interface currently this can only interface with polySolver; however, it does work 100% to run a model. The biggest caveat is that at this time there is no way to get the actual results out of the model other than to visualize them in GLVis or use the limited output dumped in the output directory --- build-python/meson.build | 4 +++- src/python/bindings.cpp | 4 ++++ src/python/eos/bindings.cpp | 3 --- src/python/polytrope/bindings.cpp | 15 +++++++++++++++ src/python/polytrope/bindings.h | 5 +++++ src/python/polytrope/meson.build | 19 +++++++++++++++++++ tests/python/polytrope/runPolytrope.py | 8 ++++++++ 7 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 src/python/polytrope/bindings.cpp create mode 100644 src/python/polytrope/bindings.h create mode 100644 src/python/polytrope/meson.build create mode 100644 tests/python/polytrope/runPolytrope.py diff --git a/build-python/meson.build b/build-python/meson.build index 48236f5..d693f62 100644 --- a/build-python/meson.build +++ b/build-python/meson.build @@ -9,6 +9,7 @@ py_mod = py_installation.extension_module( meson.project_source_root() + '/src/python/const/bindings.cpp', meson.project_source_root() + '/src/python/config/bindings.cpp', meson.project_source_root() + '/src/python/eos/bindings.cpp', + meson.project_source_root() + '/src/python/polytrope/bindings.cpp', ], dependencies : [ pybind11_dep, @@ -16,7 +17,8 @@ py_mod = py_installation.extension_module( config_dep, composition_dep, eos_dep, - species_weight_dep + species_weight_dep, + polysolver_dep, ], cpp_args : ['-UNDEBUG'], # Example: Ensure assertions are enabled if needed install : true, diff --git a/src/python/bindings.cpp b/src/python/bindings.cpp index 411c3f6..b9e14ff 100644 --- a/src/python/bindings.cpp +++ b/src/python/bindings.cpp @@ -6,6 +6,7 @@ #include "composition/bindings.h" #include "config/bindings.h" #include "eos/bindings.h" +#include "polytrope/bindings.h" PYBIND11_MODULE(serif, m) { m.doc() = "Python bindings for the SERiF project"; @@ -21,4 +22,7 @@ PYBIND11_MODULE(serif, m) { auto eosMod = m.def_submodule("eos", "EOS-module bindings"); register_eos_bindings(eosMod); + + auto polytropeMod = m.def_submodule("polytrope", "Polytrope-module bindings"); + register_polytrope_bindings(polytropeMod); } \ No newline at end of file diff --git a/src/python/eos/bindings.cpp b/src/python/eos/bindings.cpp index 40e31d9..e8c6314 100644 --- a/src/python/eos/bindings.cpp +++ b/src/python/eos/bindings.cpp @@ -5,12 +5,9 @@ #include #include "helm.h" -// #include "resourceManager.h" #include "bindings.h" #include "EOSio.h" #include "helm.h" -#include "../../eos/public/EOSio.h" -#include "../../eos/public/helm.h" namespace serif::eos { class EOSio; diff --git a/src/python/polytrope/bindings.cpp b/src/python/polytrope/bindings.cpp new file mode 100644 index 0000000..038b774 --- /dev/null +++ b/src/python/polytrope/bindings.cpp @@ -0,0 +1,15 @@ +#include "bindings.h" +#include "EOSio.h" +#include "helm.h" +#include "polySolver.h" +#include "../../polytrope/solver/public/polySolver.h" +#include "../../polytrope/utils/public/polytropeOperator.h" + +namespace py = pybind11; + +void register_polytrope_bindings(pybind11::module &polytrope_submodule) { + py::class_(polytrope_submodule, "PolySolver") + .def(py::init(), py::arg("polytropic_index"), py::arg("FEM_order")) + .def("solve", &serif::polytrope::PolySolver::solve, "Solve the polytrope equation."); + +} diff --git a/src/python/polytrope/bindings.h b/src/python/polytrope/bindings.h new file mode 100644 index 0000000..5c2283f --- /dev/null +++ b/src/python/polytrope/bindings.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +void register_polytrope_bindings(pybind11::module &polytrope_submodule); diff --git a/src/python/polytrope/meson.build b/src/python/polytrope/meson.build new file mode 100644 index 0000000..45ce25a --- /dev/null +++ b/src/python/polytrope/meson.build @@ -0,0 +1,19 @@ +# Define the library +bindings_sources = files('bindings.cpp') +bindings_headers = files('bindings.h') + +dependencies = [ + polysolver_dep, + config_dep, + resourceManager_dep, + python3_dep, + pybind11_dep, +] + +shared_module('py_polytrope', + bindings_sources, + include_directories: include_directories('.'), + cpp_args: ['-fvisibility=default'], + install : true, + dependencies: dependencies, +) diff --git a/tests/python/polytrope/runPolytrope.py b/tests/python/polytrope/runPolytrope.py new file mode 100644 index 0000000..24428f3 --- /dev/null +++ b/tests/python/polytrope/runPolytrope.py @@ -0,0 +1,8 @@ +from serif import config +from serif.polytrope import PolySolver + +config.loadConfig('../../testsConfig.yaml') +n = config.get("Tests:Poly:Index", 0.0) + +polytrope = PolySolver(n, 1) +polytrope.solve() \ No newline at end of file