feat(python): added robust python bindings covering the entire codebase

This commit is contained in:
2025-07-23 16:26:30 -04:00
parent 6a22cb65b8
commit f20bffc411
134 changed files with 2202 additions and 170 deletions

View File

@@ -0,0 +1,33 @@
#pragma once
#include "gridfire/partition/partition_abstract.h"
#include "gridfire/partition/partition_types.h"
#include "fourdst/logging/logging.h"
#include <string>
#include <unordered_map>
#include <vector>
#include <memory>
namespace gridfire::partition {
class CompositePartitionFunction final : public PartitionFunction {
public:
explicit CompositePartitionFunction(const std::vector<BasePartitionType>& partitionFunctions);
CompositePartitionFunction(const CompositePartitionFunction& other);
[[nodiscard]] double evaluate(int z, int a, double T9) const override;
[[nodiscard]] double evaluateDerivative(int z, int a, double T9) const override;
[[nodiscard]] bool supports(int z, int a) const override;
[[nodiscard]] std::string type() const override;
[[nodiscard]] std::unique_ptr<PartitionFunction> clone() const override {
return std::make_unique<CompositePartitionFunction>(*this);
}
private:
quill::Logger* m_logger = fourdst::logging::LogManager::getInstance().getLogger("log");
std::vector<std::unique_ptr<PartitionFunction>> m_partitionFunctions; ///< Set of partition functions to use in the composite partition function.
private:
std::unique_ptr<PartitionFunction> selectPartitionFunction(const BasePartitionType type) const;
};
}

View File

@@ -0,0 +1,8 @@
#pragma once
#include "gridfire/partition/partition_types.h"
#include "gridfire/partition/partition_abstract.h"
#include "gridfire/partition/partition_ground.h"
#include "gridfire/partition/partition_rauscher_thielemann.h"
#include "gridfire/partition/rauscher_thielemann_partition_data_record.h"
#include "gridfire/partition/composite/partition_composite.h"

View File

@@ -0,0 +1,16 @@
#pragma once
#include <string>
#include <memory>
namespace gridfire::partition {
class PartitionFunction {
public:
virtual ~PartitionFunction() = default;
[[nodiscard]] virtual double evaluate(int z, int a, double T9) const = 0;
[[nodiscard]] virtual double evaluateDerivative(int z, int a, double T9) const = 0;
[[nodiscard]] virtual bool supports(int z, int a) const = 0;
[[nodiscard]] virtual std::string type() const = 0;
[[nodiscard]] virtual std::unique_ptr<PartitionFunction> clone() const = 0;
};
}

View File

@@ -0,0 +1,42 @@
#pragma once
#include "gridfire/partition/partition_abstract.h"
#include "fourdst/logging/logging.h"
#include <unordered_map>
#include <memory>
#include "quill/Logger.h"
namespace gridfire::partition {
class GroundStatePartitionFunction final : public PartitionFunction {
public:
GroundStatePartitionFunction();
double evaluate(
const int z,
const int a,
const double T9
) const override;
double evaluateDerivative(
const int z,
const int a,
const double T9
) const override;
bool supports(
const int z,
const int a
) const override;
std::string type() const override { return "GroundState"; }
std::unique_ptr<PartitionFunction> clone() const override {
return std::make_unique<GroundStatePartitionFunction>(*this);
}
private:
quill::Logger* m_logger = fourdst::logging::LogManager::getInstance().getLogger("log");
std::unordered_map<int, double> m_ground_state_spin;
static constexpr int make_key(
const int z,
const int a);
};
}

View File

@@ -0,0 +1,60 @@
#pragma once
#include "gridfire/partition/partition_abstract.h"
#include "fourdst/logging/logging.h"
#include <string>
#include <vector>
#include <unordered_map>
#include <array>
#include <utility>
#include <memory>
namespace gridfire::partition {
class RauscherThielemannPartitionFunction final : public PartitionFunction {
public:
RauscherThielemannPartitionFunction();
double evaluate(int z, int a, double T9) const override;
double evaluateDerivative(int z, int a, double T9) const override;
bool supports(int z, int a) const override;
std::string type() const override { return "RauscherThielemann"; }
private:
enum Bounds {
FRONT,
BACK,
MIDDLE
};
private:
struct IsotopeData {
double ground_state_spin;
std::array<double, 24> normalized_g_values;
};
struct InterpolationPoints {
double T9_high;
double G_norm_high;
double T9_low;
double G_norm_low;
};
struct IdentifiedIsotope {
Bounds bound;
const IsotopeData& data;
size_t upperIndex;
size_t lowerIndex;
};
std::unique_ptr<PartitionFunction> clone() const override {
return std::make_unique<RauscherThielemannPartitionFunction>(*this);
}
private:
quill::Logger* m_logger = fourdst::logging::LogManager::getInstance().getLogger("log");
std::unordered_map<int, IsotopeData> m_partitionData;
private:
static InterpolationPoints get_interpolation_points(
const size_t upper_index,
const size_t lower_index,
const std::array<double, 24>& normalized_g_values
);
IdentifiedIsotope find(int z, int a, double T9) const;
static constexpr int make_key(int z, int a);
};
}

View File

@@ -0,0 +1,21 @@
#pragma once
#include <unordered_map>
#include <string>
namespace gridfire::partition {
enum BasePartitionType {
RauscherThielemann, ///< Rauscher-Thielemann partition function
GroundState, ///< Ground state partition function
};
inline std::unordered_map<BasePartitionType, std::string> basePartitionTypeToString = {
{RauscherThielemann, "RauscherThielemann"},
{GroundState, "GroundState"}
};
inline std::unordered_map<std::string, BasePartitionType> stringToBasePartitionType = {
{"RauscherThielemann", RauscherThielemann},
{"GroundState", GroundState}
};
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,14 @@
#pragma once
#include <cstdint>
namespace gridfire::partition::record {
#pragma pack(push, 1)
struct RauscherThielemannPartitionDataRecord {
uint32_t z; ///< Atomic number
uint32_t a; ///< Mass number
double ground_state_spin; ///< Ground state spin
double normalized_g_values[24]; ///< Normalized g-values for the first 24 energy levels
};
#pragma pack(pop)
}