GridFire 0.0.1a General Purpose Nuclear Network

Loading...
Searching...
No Matches
bindings.cpp
Go to the documentation of this file.
1#include <pybind11/pybind11.h>
2#include <pybind11/stl.h> // Needed for vectors, maps, sets, strings
3#include <pybind11/stl_bind.h> // Needed for binding std::vector, std::map etc if needed directly
4
5#include <iostream>
6#include <memory>
7
8#include "bindings.h"
9
10#include "gridfire/partition/partition.h"
11
12PYBIND11_DECLARE_HOLDER_TYPE(T, std::unique_ptr<T>, true) // Declare unique_ptr as a holder type for pybind11
13
14#include "trampoline/py_partition.h"
15
16
17 namespace py = pybind11;
18
19
20 void register_partition_bindings(pybind11::module &m) {
21 using PF = gridfire::partition::PartitionFunction;
22 py::class_<PF, PyPartitionFunction>(m, "PartitionFunction");
23
24 register_partition_types_bindings(m);
25 register_ground_state_partition_bindings(m);
26 register_rauscher_thielemann_partition_data_record_bindings(m);
27 register_rauscher_thielemann_partition_bindings(m);
28
29 register_composite_partition_bindings(m);
30}
31
32 void register_partition_types_bindings(pybind11::module &m) {
33 py::enum_<gridfire::partition::BasePartitionType>(m, "BasePartitionType")
34 .value("RauscherThielemann", gridfire::partition::BasePartitionType::RauscherThielemann)
35 .value("GroundState", gridfire::partition::BasePartitionType::GroundState)
36 .export_values();
37
38 m.def("basePartitionTypeToString", [](gridfire::partition::BasePartitionType type) {
39 return gridfire::partition::basePartitionTypeToString[type];
40 }, py::arg("type"), "Convert BasePartitionType to string.");
41
42 m.def("stringToBasePartitionType", [](const std::string &typeStr) {
43 return gridfire::partition::stringToBasePartitionType[typeStr];
44 }, py::arg("typeStr"), "Convert string to BasePartitionType.");
45}
46
47 void register_ground_state_partition_bindings(pybind11::module &m) {
48 using GSPF = gridfire::partition::GroundStatePartitionFunction;
49 using PF = gridfire::partition::PartitionFunction;
50 py::class_<GSPF, PF>(m, "GroundStatePartitionFunction")
51 .def(py::init<>())
52 .def("evaluate", &gridfire::partition::GroundStatePartitionFunction::evaluate,
53 py::arg("z"), py::arg("a"), py::arg("T9"),
54 "Evaluate the ground state partition function for given Z, A, and T9.")
55 .def("evaluateDerivative", &gridfire::partition::GroundStatePartitionFunction::evaluateDerivative,
56 py::arg("z"), py::arg("a"), py::arg("T9"),
57 "Evaluate the derivative of the ground state partition function for given Z, A, and T9.")
58 .def("supports", &gridfire::partition::GroundStatePartitionFunction::supports,
59 py::arg("z"), py::arg("a"),
60 "Check if the ground state partition function supports given Z and A.")
61 .def("get_type", &gridfire::partition::GroundStatePartitionFunction::type,
62 "Get the type of the partition function (should return 'GroundState').");
63}
64
65 void register_rauscher_thielemann_partition_data_record_bindings(pybind11::module &m) {
66 py::class_<gridfire::partition::record::RauscherThielemannPartitionDataRecord>(m, "RauscherThielemannPartitionDataRecord")
67 .def_readonly("z", &gridfire::partition::record::RauscherThielemannPartitionDataRecord::z, "Atomic number")
68 .def_readonly("a", &gridfire::partition::record::RauscherThielemannPartitionDataRecord::a, "Mass number")
69 .def_readonly("ground_state_spin", &gridfire::partition::record::RauscherThielemannPartitionDataRecord::ground_state_spin, "Ground state spin")
70 .def_readonly("normalized_g_values", &gridfire::partition::record::RauscherThielemannPartitionDataRecord::normalized_g_values, "Normalized g-values for the first 24 energy levels");
71}
72
73
74 void register_rauscher_thielemann_partition_bindings(pybind11::module &m) {
75 using RTPF = gridfire::partition::RauscherThielemannPartitionFunction;
76 using PF = gridfire::partition::PartitionFunction;
77 py::class_<RTPF, PF>(m, "RauscherThielemannPartitionFunction")
78 .def(py::init<>())
79 .def("evaluate", &gridfire::partition::RauscherThielemannPartitionFunction::evaluate,
80 py::arg("z"), py::arg("a"), py::arg("T9"),
81 "Evaluate the Rauscher-Thielemann partition function for given Z, A, and T9.")
82 .def("evaluateDerivative", &gridfire::partition::RauscherThielemannPartitionFunction::evaluateDerivative,
83 py::arg("z"), py::arg("a"), py::arg("T9"),
84 "Evaluate the derivative of the Rauscher-Thielemann partition function for given Z, A, and T9.")
85 .def("supports", &gridfire::partition::RauscherThielemannPartitionFunction::supports,
86 py::arg("z"), py::arg("a"),
87 "Check if the Rauscher-Thielemann partition function supports given Z and A.")
88 .def("get_type", &gridfire::partition::RauscherThielemannPartitionFunction::type,
89 "Get the type of the partition function (should return 'RauscherThielemann').");
90}
91
92 void register_composite_partition_bindings(pybind11::module &m) {
93 py::class_<gridfire::partition::CompositePartitionFunction>(m, "CompositePartitionFunction")
94 .def(py::init<const std::vector<gridfire::partition::BasePartitionType>&>(),
95 py::arg("partitionFunctions"),
96 "Create a composite partition function from a list of base partition types.")
97 .def(py::init<const gridfire::partition::CompositePartitionFunction&>(),
98 "Copy constructor for CompositePartitionFunction.")
99 .def("evaluate", &gridfire::partition::CompositePartitionFunction::evaluate,
100 py::arg("z"), py::arg("a"), py::arg("T9"),
101 "Evaluate the composite partition function for given Z, A, and T9.")
102 .def("evaluateDerivative", &gridfire::partition::CompositePartitionFunction::evaluateDerivative,
103 py::arg("z"), py::arg("a"), py::arg("T9"),
104 "Evaluate the derivative of the composite partition function for given Z, A, and T9.")
105 .def("supports", &gridfire::partition::CompositePartitionFunction::supports,
106 py::arg("z"), py::arg("a"),
107 "Check if the composite partition function supports given Z and A.")
108 .def("get_type", &gridfire::partition::CompositePartitionFunction::type,
109 "Get the type of the partition function (should return 'Composite').");
110}
111
112
113
gridfire::partition::CompositePartitionFunction::type
std::string type() const override
Definition partition_composite.cpp:76
gridfire::partition::CompositePartitionFunction::evaluate
double evaluate(int z, int a, double T9) const override
Definition partition_composite.cpp:27
gridfire::partition::CompositePartitionFunction::evaluateDerivative
double evaluateDerivative(int z, int a, double T9) const override
Definition partition_composite.cpp:48
gridfire::partition::CompositePartitionFunction::supports
bool supports(int z, int a) const override
Definition partition_composite.cpp:66
gridfire::partition::GroundStatePartitionFunction
Partition function implementation for nuclear ground states.
Definition partition_ground.h:22
gridfire::partition::GroundStatePartitionFunction::evaluateDerivative
double evaluateDerivative(const int z, const int a, const double T9) const override
Definition partition_ground.cpp:29
gridfire::partition::GroundStatePartitionFunction::supports
bool supports(const int z, const int a) const override
Definition partition_ground.cpp:38
gridfire::partition::GroundStatePartitionFunction::evaluate
double evaluate(const int z, const int a, const double T9) const override
Definition partition_ground.cpp:18
gridfire::partition::GroundStatePartitionFunction::type
std::string type() const override
Definition partition_ground.h:82
gridfire::partition::PartitionFunction
Abstract interface for evaluating nuclear partition functions.
Definition partition_abstract.h:17
gridfire::partition::RauscherThielemannPartitionFunction
Partition function using Rauscher-Thielemann tabulated normalized G-values.
Definition partition_rauscher_thielemann.h:26
gridfire::partition::RauscherThielemannPartitionFunction::type
std::string type() const override
Get type identifier for this partition function.
Definition partition_rauscher_thielemann.h:75
gridfire::partition::RauscherThielemannPartitionFunction::supports
bool supports(int z, int a) const override
Check if partition data exists for given isotope.
Definition partition_rauscher_thielemann.cpp:98
gridfire::partition::RauscherThielemannPartitionFunction::evaluateDerivative
double evaluateDerivative(int z, int a, double T9) const override
Evaluate temperature derivative of partition function.
Definition partition_rauscher_thielemann.cpp:78
gridfire::partition::RauscherThielemannPartitionFunction::evaluate
double evaluate(int z, int a, double T9) const override
Evaluate partition function for isotope at temperature.
Definition partition_rauscher_thielemann.cpp:43
gridfire::partition::stringToBasePartitionType
std::unordered_map< std::string, BasePartitionType > stringToBasePartitionType
Mapping from string to BasePartitionType enum.
Definition partition_types.h:42
gridfire::partition::basePartitionTypeToString
std::unordered_map< BasePartitionType, std::string > basePartitionTypeToString
Mapping from BasePartitionType enum to human-readable string.
Definition partition_types.h:28
gridfire::partition::BasePartitionType
BasePartitionType
Enumerates available partition function implementations.
Definition partition_types.h:15
gridfire::partition::RauscherThielemann
@ RauscherThielemann
Rauscher-Thielemann partition function.
Definition partition_types.h:16
gridfire::partition::GroundState
@ GroundState
Ground state partition function.
Definition partition_types.h:17
register_partition_bindings
void register_partition_bindings(pybind11::module &m)
Definition bindings.cpp:20
register_partition_types_bindings
void register_partition_types_bindings(pybind11::module &m)
Definition bindings.cpp:32
register_rauscher_thielemann_partition_bindings
void register_rauscher_thielemann_partition_bindings(pybind11::module &m)
Definition bindings.cpp:74
register_ground_state_partition_bindings
void register_ground_state_partition_bindings(pybind11::module &m)
Definition bindings.cpp:47
register_rauscher_thielemann_partition_data_record_bindings
void register_rauscher_thielemann_partition_data_record_bindings(pybind11::module &m)
Definition bindings.cpp:65
register_composite_partition_bindings
void register_composite_partition_bindings(pybind11::module &m)
Definition bindings.cpp:92
bindings.h
partition.h
gridfire::partition::record::RauscherThielemannPartitionDataRecord::normalized_g_values
double normalized_g_values[24]
Normalized g-values for the first 24 energy levels.
Definition rauscher_thielemann_partition_data_record.h:21
gridfire::partition::record::RauscherThielemannPartitionDataRecord::a
uint32_t a
Mass number.
Definition rauscher_thielemann_partition_data_record.h:19
gridfire::partition::record::RauscherThielemannPartitionDataRecord::z
uint32_t z
Atomic number.
Definition rauscher_thielemann_partition_data_record.h:18
gridfire::partition::record::RauscherThielemannPartitionDataRecord::ground_state_spin
double ground_state_spin
Ground state spin.
Definition rauscher_thielemann_partition_data_record.h:20