2025-07-02 11:32:45 -04:00
|
|
|
#include "gridfire/partition/composite/partition_composite.h"
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
|
|
#include "gridfire/partition/partition_ground.h"
|
|
|
|
|
#include "gridfire/partition/partition_rauscher_thielemann.h"
|
|
|
|
|
#include "quill/LogMacros.h"
|
|
|
|
|
|
|
|
|
|
namespace gridfire::partition {
|
|
|
|
|
CompositePartitionFunction::CompositePartitionFunction(
|
|
|
|
|
const std::vector<BasePartitionType>& partitionFunctions
|
|
|
|
|
) {
|
|
|
|
|
for (const auto& type : partitionFunctions) {
|
|
|
|
|
LOG_TRACE_L2(m_logger, "Adding partition function of type: {}", basePartitionTypeToString[type]);
|
|
|
|
|
m_partitionFunctions.push_back(selectPartitionFunction(type));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-03 09:55:10 -04:00
|
|
|
CompositePartitionFunction::CompositePartitionFunction(const CompositePartitionFunction &other) {
|
|
|
|
|
m_partitionFunctions.reserve(other.m_partitionFunctions.size());
|
|
|
|
|
for (const auto& pf : other.m_partitionFunctions) {
|
|
|
|
|
m_partitionFunctions.push_back(pf->clone());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-02 11:32:45 -04:00
|
|
|
double CompositePartitionFunction::evaluate(int z, int a, double T9) const {
|
2025-07-10 09:36:05 -04:00
|
|
|
LOG_TRACE_L3(m_logger, "Evaluating partition function for Z={} A={} T9={}", z, a, T9);
|
2025-07-02 11:32:45 -04:00
|
|
|
for (const auto& partitionFunction : m_partitionFunctions) {
|
|
|
|
|
if (partitionFunction->supports(z, a)) {
|
2025-07-10 09:36:05 -04:00
|
|
|
LOG_TRACE_L3(m_logger, "Partition function of type {} supports Z={} A={}", partitionFunction->type(), z, a);
|
2025-07-02 11:32:45 -04:00
|
|
|
return partitionFunction->evaluate(z, a, T9);
|
|
|
|
|
} else {
|
2025-07-10 09:36:05 -04:00
|
|
|
LOG_TRACE_L3(m_logger, "Partition function of type {} does not support Z={} A={}", partitionFunction->type(), z, a);
|
2025-07-02 11:32:45 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
LOG_ERROR(
|
|
|
|
|
m_logger,
|
|
|
|
|
"No partition function supports Z={} A={} T9={}. Tried: {}",
|
|
|
|
|
z,
|
|
|
|
|
a,
|
|
|
|
|
T9,
|
|
|
|
|
type()
|
|
|
|
|
);
|
|
|
|
|
throw std::runtime_error("No partition function supports the given Z, A, and T9 values.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double CompositePartitionFunction::evaluateDerivative(int z, int a, double T9) const {
|
|
|
|
|
for (const auto& partitionFunction : m_partitionFunctions) {
|
|
|
|
|
if (partitionFunction->supports(z, a)) {
|
2025-07-10 09:36:05 -04:00
|
|
|
LOG_TRACE_L3(m_logger, "Evaluating derivative of partition function for Z={} A={} T9={}", z, a, T9);
|
2025-07-02 11:32:45 -04:00
|
|
|
return partitionFunction->evaluateDerivative(z, a, T9);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
LOG_ERROR(
|
|
|
|
|
m_logger,
|
|
|
|
|
"No partition function supports Z={} A={} T9={}. Tried: {}",
|
|
|
|
|
z,
|
|
|
|
|
a,
|
|
|
|
|
T9,
|
|
|
|
|
type()
|
|
|
|
|
);
|
|
|
|
|
throw std::runtime_error("No partition function supports the given Z, A, and T9 values.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CompositePartitionFunction::supports(int z, int a) const {
|
|
|
|
|
for (const auto& partitionFunction : m_partitionFunctions) {
|
|
|
|
|
if (partitionFunction->supports(z, a)) {
|
|
|
|
|
LOG_TRACE_L2(m_logger, "Partition function supports Z={} A={}", z, a);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string CompositePartitionFunction::type() const {
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << "CompositePartitionFunction(";
|
|
|
|
|
int count = 0;
|
|
|
|
|
for (const auto& partitionFunction : m_partitionFunctions) {
|
|
|
|
|
ss << partitionFunction->type();
|
|
|
|
|
if (count < m_partitionFunctions.size() - 1) {
|
|
|
|
|
ss << ", ";
|
|
|
|
|
}
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
ss << ")";
|
|
|
|
|
std::string types = ss.str();
|
|
|
|
|
return types;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<PartitionFunction> CompositePartitionFunction::selectPartitionFunction(
|
|
|
|
|
const BasePartitionType type
|
|
|
|
|
) const {
|
|
|
|
|
switch (type) {
|
|
|
|
|
case RauscherThielemann: {
|
|
|
|
|
return std::make_unique<RauscherThielemannPartitionFunction>();
|
|
|
|
|
}
|
|
|
|
|
case GroundState: {
|
|
|
|
|
return std::make_unique<GroundStatePartitionFunction>();
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
LOG_ERROR(m_logger, "Unknown partition function type");
|
|
|
|
|
throw std::runtime_error("Unknown partition function type");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|