fix(python-bindings): Updated python bindings to new interface
The python bindings now work with the polymorphic reaction class and the CVODE solver
This commit is contained in:
@@ -33,12 +33,12 @@ const std::vector<fourdst::atomic::Species>& PyEngine::getNetworkSpecies() const
|
||||
py::pybind11_fail("Tried to call pure virtual function \"DynamicEngine::getNetworkSpecies\"");
|
||||
}
|
||||
|
||||
std::expected<gridfire::StepDerivatives<double>, gridfire::expectations::StaleEngineError> PyEngine::calculateRHSAndEnergy(const std::vector<double> &Y, double T9, double rho) const {
|
||||
std::expected<gridfire::StepDerivatives<double>, gridfire::expectations::StaleEngineError> PyEngine::calculateRHSAndEnergy(const fourdst::composition::Composition &comp, double T9, double rho) const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
PYBIND11_TYPE(std::expected<gridfire::StepDerivatives<double>, gridfire::expectations::StaleEngineError>),
|
||||
gridfire::Engine,
|
||||
calculateRHSAndEnergy,
|
||||
Y, T9, rho
|
||||
comp, T9, rho
|
||||
);
|
||||
}
|
||||
|
||||
@@ -65,39 +65,62 @@ const std::vector<fourdst::atomic::Species>& PyDynamicEngine::getNetworkSpecies(
|
||||
|
||||
py::pybind11_fail("Tried to call pure virtual function \"DynamicEngine::getNetworkSpecies\"");
|
||||
}
|
||||
std::expected<gridfire::StepDerivatives<double>, gridfire::expectations::StaleEngineError> PyDynamicEngine::calculateRHSAndEnergy(const std::vector<double> &Y, double T9, double rho) const {
|
||||
std::expected<gridfire::StepDerivatives<double>, gridfire::expectations::StaleEngineError> PyDynamicEngine::calculateRHSAndEnergy(const fourdst::composition::Composition &comp, double T9, double rho) const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
PYBIND11_TYPE(std::expected<gridfire::StepDerivatives<double>, gridfire::expectations::StaleEngineError>),
|
||||
gridfire::Engine,
|
||||
calculateRHSAndEnergy,
|
||||
Y, T9, rho
|
||||
comp, T9, rho
|
||||
);
|
||||
}
|
||||
|
||||
void PyDynamicEngine::generateJacobianMatrix(const std::vector<double> &Y_dynamic, double T9, double rho) const {
|
||||
void PyDynamicEngine::generateJacobianMatrix(const fourdst::composition::Composition& comp, double T9, double rho) const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
void,
|
||||
gridfire::DynamicEngine,
|
||||
generateJacobianMatrix,
|
||||
Y_dynamic, T9, rho
|
||||
comp,
|
||||
T9,
|
||||
rho
|
||||
);
|
||||
}
|
||||
|
||||
void PyDynamicEngine::generateJacobianMatrix(const std::vector<double> &Y_dynamic, double T9, double rho, const gridfire::SparsityPattern &sparsityPattern) const {
|
||||
void PyDynamicEngine::generateJacobianMatrix(
|
||||
const fourdst::composition::Composition &comp,
|
||||
const double T9,
|
||||
const double rho,
|
||||
const std::vector<fourdst::atomic::Species> &activeSpecies
|
||||
) const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
void,
|
||||
gridfire::DynamicEngine,
|
||||
generateJacobianMatrix,
|
||||
Y_dynamic, T9, rho, sparsityPattern
|
||||
comp,
|
||||
T9,
|
||||
rho,
|
||||
activeSpecies
|
||||
);
|
||||
}
|
||||
|
||||
double PyDynamicEngine::getJacobianMatrixEntry(int i, int j) const {
|
||||
void PyDynamicEngine::generateJacobianMatrix(const fourdst::composition::Composition &comp, double T9, double rho, const gridfire::SparsityPattern &sparsityPattern) const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
void,
|
||||
gridfire::DynamicEngine,
|
||||
generateJacobianMatrix,
|
||||
comp,
|
||||
T9,
|
||||
rho,
|
||||
sparsityPattern
|
||||
);
|
||||
}
|
||||
|
||||
double PyDynamicEngine::getJacobianMatrixEntry(const fourdst::atomic::Species& rowSpecies, const fourdst::atomic::Species& colSpecies) const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
double,
|
||||
gridfire::DynamicEngine,
|
||||
getJacobianMatrixEntry,
|
||||
i, j
|
||||
rowSpecies,
|
||||
colSpecies
|
||||
);
|
||||
}
|
||||
|
||||
@@ -109,21 +132,25 @@ void PyDynamicEngine::generateStoichiometryMatrix() {
|
||||
);
|
||||
}
|
||||
|
||||
int PyDynamicEngine::getStoichiometryMatrixEntry(int speciesIndex, int reactionIndex) const {
|
||||
int PyDynamicEngine::getStoichiometryMatrixEntry(const fourdst::atomic::Species& species, const gridfire::reaction::Reaction& reaction) const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
int,
|
||||
gridfire::DynamicEngine,
|
||||
getStoichiometryMatrixEntry,
|
||||
speciesIndex, reactionIndex
|
||||
species,
|
||||
reaction
|
||||
);
|
||||
}
|
||||
|
||||
double PyDynamicEngine::calculateMolarReactionFlow(const gridfire::reaction::Reaction &reaction, const std::vector<double> &Y, double T9, double rho) const {
|
||||
double PyDynamicEngine::calculateMolarReactionFlow(const gridfire::reaction::Reaction &reaction, const fourdst::composition::Composition &comp, double T9, double rho) const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
double,
|
||||
gridfire::DynamicEngine,
|
||||
calculateMolarReactionFlow,
|
||||
reaction, Y, T9, rho
|
||||
reaction,
|
||||
comp,
|
||||
T9,
|
||||
rho
|
||||
);
|
||||
}
|
||||
|
||||
@@ -144,21 +171,23 @@ void PyDynamicEngine::setNetworkReactions(const gridfire::reaction::ReactionSet&
|
||||
);
|
||||
}
|
||||
|
||||
std::expected<std::unordered_map<fourdst::atomic::Species, double>, gridfire::expectations::StaleEngineError> PyDynamicEngine::getSpeciesTimescales(const std::vector<double> &Y, double T9, double rho) const {
|
||||
std::expected<std::unordered_map<fourdst::atomic::Species, double>, gridfire::expectations::StaleEngineError> PyDynamicEngine::getSpeciesTimescales(const fourdst::composition::Composition &comp, double T9, double rho) const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
PYBIND11_TYPE(std::expected<std::unordered_map<fourdst::atomic::Species, double>, gridfire::expectations::StaleEngineError>),
|
||||
gridfire::DynamicEngine,
|
||||
getSpeciesTimescales,
|
||||
Y, T9, rho
|
||||
comp,
|
||||
T9,
|
||||
rho
|
||||
);
|
||||
}
|
||||
|
||||
std::expected<std::unordered_map<fourdst::atomic::Species, double>, gridfire::expectations::StaleEngineError> PyDynamicEngine::getSpeciesDestructionTimescales(const std::vector<double> &Y, double T9, double rho) const {
|
||||
std::expected<std::unordered_map<fourdst::atomic::Species, double>, gridfire::expectations::StaleEngineError> PyDynamicEngine::getSpeciesDestructionTimescales(const fourdst::composition::Composition &comp, double T9, double rho) const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
PYBIND11_TYPE(std::expected<std::unordered_map<fourdst::atomic::Species, double>, gridfire::expectations::StaleEngineError>),
|
||||
gridfire::DynamicEngine,
|
||||
getSpeciesDestructionTimescales,
|
||||
Y, T9, rho
|
||||
comp, T9, rho
|
||||
);
|
||||
}
|
||||
|
||||
@@ -224,6 +253,31 @@ gridfire::PrimingReport PyDynamicEngine::primeEngine(const gridfire::NetIn &netI
|
||||
);
|
||||
}
|
||||
|
||||
gridfire::EnergyDerivatives PyDynamicEngine::calculateEpsDerivatives(
|
||||
const fourdst::composition::Composition &comp,
|
||||
const double T9,
|
||||
const double rho) const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
gridfire::EnergyDerivatives,
|
||||
gridfire::DynamicEngine,
|
||||
calculateEpsDerivatives,
|
||||
comp,
|
||||
T9,
|
||||
rho
|
||||
);
|
||||
}
|
||||
|
||||
fourdst::composition::Composition PyDynamicEngine::collectComposition(
|
||||
fourdst::composition::Composition &comp
|
||||
) const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
fourdst::composition::Composition,
|
||||
gridfire::DynamicEngine,
|
||||
collectComposition,
|
||||
comp
|
||||
);
|
||||
}
|
||||
|
||||
const gridfire::Engine& PyEngineView::getBaseEngine() const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
const gridfire::Engine&,
|
||||
|
||||
@@ -12,7 +12,12 @@
|
||||
class PyEngine final : public gridfire::Engine {
|
||||
public:
|
||||
const std::vector<fourdst::atomic::Species>& getNetworkSpecies() const override;
|
||||
std::expected<gridfire::StepDerivatives<double>,gridfire::expectations::StaleEngineError> calculateRHSAndEnergy(const std::vector<double> &Y, double T9, double rho) const override;
|
||||
|
||||
std::expected<gridfire::StepDerivatives<double>,gridfire::expectations::StaleEngineError> calculateRHSAndEnergy(
|
||||
const fourdst::composition::Composition& comp,
|
||||
double T9,
|
||||
double rho
|
||||
) const override;
|
||||
private:
|
||||
mutable std::vector<fourdst::atomic::Species> m_species_cache;
|
||||
};
|
||||
@@ -20,41 +25,124 @@ private:
|
||||
class PyDynamicEngine final : public gridfire::DynamicEngine {
|
||||
public:
|
||||
const std::vector<fourdst::atomic::Species>& getNetworkSpecies() const override;
|
||||
std::expected<gridfire::StepDerivatives<double>,gridfire::expectations::StaleEngineError> calculateRHSAndEnergy(const std::vector<double> &Y, double T9, double rho) const override;
|
||||
void generateJacobianMatrix(const std::vector<double> &Y_dynamic, double T9, double rho) const override;
|
||||
void generateJacobianMatrix(const std::vector<double> &Y_dynamic, double T9, double rho, const gridfire::SparsityPattern &sparsityPattern) const override;
|
||||
double getJacobianMatrixEntry(int i, int j) const override;
|
||||
|
||||
std::expected<gridfire::StepDerivatives<double>, gridfire::expectations::StaleEngineError> calculateRHSAndEnergy(
|
||||
const fourdst::composition::Composition& comp,
|
||||
double T9,
|
||||
double rho
|
||||
) const override;
|
||||
|
||||
void generateJacobianMatrix(
|
||||
const fourdst::composition::Composition& comp,
|
||||
double T9,
|
||||
double rho
|
||||
) const override;
|
||||
|
||||
void generateJacobianMatrix(
|
||||
const fourdst::composition::Composition &comp,
|
||||
double T9,
|
||||
double rho,
|
||||
const std::vector<fourdst::atomic::Species> &activeSpecies
|
||||
) const override;
|
||||
|
||||
void generateJacobianMatrix(
|
||||
const fourdst::composition::Composition& comp,
|
||||
double T9,
|
||||
double rho,
|
||||
const gridfire::SparsityPattern &sparsityPattern
|
||||
) const override;
|
||||
|
||||
double getJacobianMatrixEntry(
|
||||
const fourdst::atomic::Species& rowSpecies,
|
||||
const fourdst::atomic::Species& colSpecies
|
||||
) const override;
|
||||
|
||||
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;
|
||||
|
||||
int getStoichiometryMatrixEntry(
|
||||
const fourdst::atomic::Species& species,
|
||||
const gridfire::reaction::Reaction& reaction
|
||||
) const override;
|
||||
|
||||
double calculateMolarReactionFlow(
|
||||
const gridfire::reaction::Reaction &reaction,
|
||||
const fourdst::composition::Composition& comp,
|
||||
double T9,
|
||||
double rho
|
||||
) const 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;
|
||||
|
||||
void setNetworkReactions(
|
||||
const gridfire::reaction::ReactionSet& reactions
|
||||
) override;
|
||||
|
||||
std::expected<std::unordered_map<fourdst::atomic::Species, double>, gridfire::expectations::StaleEngineError> getSpeciesTimescales(
|
||||
const fourdst::composition::Composition& comp,
|
||||
double T9,
|
||||
double rho
|
||||
) const override;
|
||||
|
||||
std::expected<std::unordered_map<fourdst::atomic::Species, double>, gridfire::expectations::StaleEngineError> getSpeciesDestructionTimescales(
|
||||
const fourdst::composition::Composition &comp,
|
||||
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;
|
||||
|
||||
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;
|
||||
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 {
|
||||
throw std::logic_error("Network depth not supported by this engine.");
|
||||
}
|
||||
void rebuild(const fourdst::composition::Composition& comp, gridfire::BuildDepthType depth) override {
|
||||
void rebuild(
|
||||
const fourdst::composition::Composition& comp,
|
||||
gridfire::BuildDepthType depth
|
||||
) override {
|
||||
throw std::logic_error("Setting network depth not supported by this engine.");
|
||||
}
|
||||
|
||||
[[nodiscard]] gridfire::EnergyDerivatives calculateEpsDerivatives(
|
||||
const fourdst::composition::Composition &comp,
|
||||
double T9,
|
||||
double rho
|
||||
) const override;
|
||||
|
||||
fourdst::composition::Composition collectComposition(
|
||||
fourdst::composition::Composition &comp
|
||||
) const override;
|
||||
|
||||
private:
|
||||
mutable std::vector<fourdst::atomic::Species> m_species_cache;
|
||||
|
||||
|
||||
};
|
||||
|
||||
class PyEngineView final : public gridfire::EngineView<gridfire::Engine> {
|
||||
const gridfire::Engine& getBaseEngine() const override;
|
||||
[[nodiscard]] const gridfire::Engine& getBaseEngine() const override;
|
||||
};
|
||||
|
||||
class PyDynamicEngineView final : public gridfire::EngineView<gridfire::DynamicEngine> {
|
||||
const gridfire::DynamicEngine& getBaseEngine() const override;
|
||||
[[nodiscard]] const gridfire::DynamicEngine& getBaseEngine() const override;
|
||||
};
|
||||
Reference in New Issue
Block a user