refactor(reaction): refactored to an abstract reaction class in prep for weak reactions
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h> // Needed for vectors, maps, sets, strings
|
||||
#include <pybind11/stl_bind.h> // Needed for binding std::vector, std::map etc if needed directly
|
||||
|
||||
#include <iostream>
|
||||
#include <pybind11/stl_bind.h> // Needed for binding std::vector, std::map etc. if needed directly
|
||||
|
||||
#include "bindings.h"
|
||||
|
||||
@@ -152,7 +150,7 @@ void register_engine_bindings(py::module &m) {
|
||||
);
|
||||
}
|
||||
|
||||
void register_base_engine_bindings(pybind11::module &m) {
|
||||
void register_base_engine_bindings(const pybind11::module &m) {
|
||||
|
||||
py::class_<gridfire::StepDerivatives<double>>(m, "StepDerivatives")
|
||||
.def_readonly("dYdt", &gridfire::StepDerivatives<double>::dydt, "The right-hand side (dY/dt) of the ODE system.")
|
||||
@@ -165,15 +163,15 @@ void register_base_engine_bindings(pybind11::module &m) {
|
||||
con_stype_register_graph_engine_bindings(m);
|
||||
}
|
||||
|
||||
void abs_stype_register_engine_bindings(pybind11::module &m) {
|
||||
void abs_stype_register_engine_bindings(const pybind11::module &m) {
|
||||
py::class_<gridfire::Engine, PyEngine>(m, "Engine");
|
||||
}
|
||||
|
||||
void abs_stype_register_dynamic_engine_bindings(pybind11::module &m) {
|
||||
void abs_stype_register_dynamic_engine_bindings(const pybind11::module &m) {
|
||||
const auto a = py::class_<gridfire::DynamicEngine, PyDynamicEngine>(m, "DynamicEngine");
|
||||
}
|
||||
|
||||
void con_stype_register_graph_engine_bindings(pybind11::module &m) {
|
||||
void con_stype_register_graph_engine_bindings(const pybind11::module &m) {
|
||||
py::enum_<gridfire::NetworkBuildDepth>(m, "NetworkBuildDepth")
|
||||
.value("Full", gridfire::NetworkBuildDepth::Full, "Full network build depth")
|
||||
.value("Shallow", gridfire::NetworkBuildDepth::Shallow, "Shallow network build depth")
|
||||
@@ -199,7 +197,7 @@ void con_stype_register_graph_engine_bindings(pybind11::module &m) {
|
||||
py::arg("depth") = gridfire::NetworkBuildDepth::Full,
|
||||
"Initialize GraphEngine with a composition, partition function and build depth."
|
||||
);
|
||||
py_dynamic_engine_bindings.def(py::init<const gridfire::reaction::LogicalReactionSet &>(),
|
||||
py_dynamic_engine_bindings.def(py::init<const gridfire::reaction::ReactionSet &>(),
|
||||
py::arg("reactions"),
|
||||
"Initialize GraphEngine with a set of reactions."
|
||||
);
|
||||
@@ -267,7 +265,7 @@ void con_stype_register_graph_engine_bindings(pybind11::module &m) {
|
||||
registerDynamicEngineDefs<gridfire::GraphEngine, gridfire::DynamicEngine>(py_dynamic_engine_bindings);
|
||||
}
|
||||
|
||||
void register_engine_view_bindings(pybind11::module &m) {
|
||||
void register_engine_view_bindings(const pybind11::module &m) {
|
||||
auto py_defined_engine_view_bindings = py::class_<gridfire::DefinedEngineView, gridfire::DynamicEngine>(m, "DefinedEngineView");
|
||||
|
||||
py_defined_engine_view_bindings.def(py::init<std::vector<std::string>, gridfire::DynamicEngine&>(),
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
|
||||
void register_engine_bindings(pybind11::module &m);
|
||||
|
||||
void register_base_engine_bindings(pybind11::module &m);
|
||||
void register_base_engine_bindings(const pybind11::module &m);
|
||||
|
||||
void register_engine_view_bindings(pybind11::module &m);
|
||||
void register_engine_view_bindings(const pybind11::module &m);
|
||||
|
||||
void abs_stype_register_engine_bindings(pybind11::module &m);
|
||||
void abs_stype_register_dynamic_engine_bindings(pybind11::module &m);
|
||||
void abs_stype_register_engine_bindings(const pybind11::module &m);
|
||||
void abs_stype_register_dynamic_engine_bindings(const pybind11::module &m);
|
||||
|
||||
void con_stype_register_graph_engine_bindings(pybind11::module &m);
|
||||
void con_stype_register_graph_engine_bindings(const pybind11::module &m);
|
||||
|
||||
|
||||
|
||||
@@ -23,10 +23,9 @@ const std::vector<fourdst::atomic::Species>& PyEngine::getNetworkSpecies() const
|
||||
/*
|
||||
* get_override() looks for a Python method that overrides this C++ one.
|
||||
*/
|
||||
py::function override = py::get_override(this, "getNetworkSpecies");
|
||||
|
||||
if (override) {
|
||||
py::object result = override();
|
||||
if (const py::function override = py::get_override(this, "getNetworkSpecies")) {
|
||||
const py::object result = override();
|
||||
m_species_cache = result.cast<std::vector<fourdst::atomic::Species>>();
|
||||
return m_species_cache;
|
||||
}
|
||||
@@ -57,10 +56,9 @@ const std::vector<fourdst::atomic::Species>& PyDynamicEngine::getNetworkSpecies(
|
||||
/*
|
||||
* get_override() looks for a Python method that overrides this C++ one.
|
||||
*/
|
||||
py::function override = py::get_override(this, "getNetworkSpecies");
|
||||
|
||||
if (override) {
|
||||
py::object result = override();
|
||||
if (const py::function override = py::get_override(this, "getNetworkSpecies")) {
|
||||
const py::object result = override();
|
||||
m_species_cache = result.cast<std::vector<fourdst::atomic::Species>>();
|
||||
return m_species_cache;
|
||||
}
|
||||
@@ -129,15 +127,15 @@ double PyDynamicEngine::calculateMolarReactionFlow(const gridfire::reaction::Rea
|
||||
);
|
||||
}
|
||||
|
||||
const gridfire::reaction::LogicalReactionSet& PyDynamicEngine::getNetworkReactions() const {
|
||||
const gridfire::reaction::ReactionSet& PyDynamicEngine::getNetworkReactions() const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
const gridfire::reaction::LogicalReactionSet&,
|
||||
const gridfire::reaction::ReactionSet&,
|
||||
gridfire::DynamicEngine,
|
||||
getNetworkReactions
|
||||
);
|
||||
}
|
||||
|
||||
void PyDynamicEngine::setNetworkReactions(const gridfire::reaction::LogicalReactionSet& reactions) {
|
||||
void PyDynamicEngine::setNetworkReactions(const gridfire::reaction::ReactionSet& reactions) {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
void,
|
||||
gridfire::DynamicEngine,
|
||||
@@ -199,7 +197,7 @@ gridfire::screening::ScreeningType PyDynamicEngine::getScreeningModel() const {
|
||||
);
|
||||
}
|
||||
|
||||
int PyDynamicEngine::getSpeciesIndex(const fourdst::atomic::Species &species) const {
|
||||
size_t PyDynamicEngine::getSpeciesIndex(const fourdst::atomic::Species &species) const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
int,
|
||||
gridfire::DynamicEngine,
|
||||
|
||||
@@ -27,15 +27,16 @@ public:
|
||||
void generateStoichiometryMatrix() override;
|
||||
int getStoichiometryMatrixEntry(int speciesIndex, int reactionIndex) const override;
|
||||
double calculateMolarReactionFlow(const gridfire::reaction::Reaction &reaction, const std::vector<double> &Y, double T9, double rho) const override;
|
||||
const gridfire::reaction::LogicalReactionSet& getNetworkReactions() const override;
|
||||
void setNetworkReactions(const gridfire::reaction::LogicalReactionSet& reactions) override;
|
||||
const gridfire::reaction::ReactionSet& getNetworkReactions() const override;
|
||||
void setNetworkReactions(const gridfire::reaction::ReactionSet& reactions) override;
|
||||
std::expected<std::unordered_map<fourdst::atomic::Species, double>, gridfire::expectations::StaleEngineError> getSpeciesTimescales(const std::vector<double> &Y, double T9, double rho) const override;
|
||||
std::expected<std::unordered_map<fourdst::atomic::Species, double>, gridfire::expectations::StaleEngineError> getSpeciesDestructionTimescales(const std::vector<double> &Y, double T9, double rho) const override;
|
||||
fourdst::composition::Composition update(const gridfire::NetIn &netIn) override;
|
||||
bool isStale(const gridfire::NetIn &netIn) override;
|
||||
void setScreeningModel(gridfire::screening::ScreeningType model) override;
|
||||
gridfire::screening::ScreeningType getScreeningModel() const override;
|
||||
int getSpeciesIndex(const fourdst::atomic::Species &species) const override;
|
||||
|
||||
size_t getSpeciesIndex(const fourdst::atomic::Species &species) const override;
|
||||
std::vector<double> mapNetInToMolarAbundanceVector(const gridfire::NetIn &netIn) const override;
|
||||
gridfire::PrimingReport primeEngine(const gridfire::NetIn &netIn) override;
|
||||
gridfire::BuildDepthType getDepth() const override {
|
||||
|
||||
Reference in New Issue
Block a user