GridFire 0.0.1a
General Purpose Nuclear Network
Loading...
Searching...
No Matches
partition_composite.cpp
Go to the documentation of this file.
2
3#include <vector>
4#include <set>
5
8#include "quill/LogMacros.h"
9
10namespace gridfire::partition {
12 const std::vector<BasePartitionType>& partitionFunctions
13 ) {
14 for (const auto& type : partitionFunctions) {
15 LOG_TRACE_L2(m_logger, "Adding partition function of type: {}", basePartitionTypeToString[type]);
17 }
18 }
19
21 m_partitionFunctions.reserve(other.m_partitionFunctions.size());
22 for (const auto& pf : other.m_partitionFunctions) {
23 m_partitionFunctions.push_back(pf->clone());
24 }
25 }
26
27 double CompositePartitionFunction::evaluate(int z, int a, double T9) const {
28 LOG_TRACE_L3(m_logger, "Evaluating partition function for Z={} A={} T9={}", z, a, T9);
29 for (const auto& partitionFunction : m_partitionFunctions) {
30 if (partitionFunction->supports(z, a)) {
31 LOG_TRACE_L3(m_logger, "Partition function of type {} supports Z={} A={}", partitionFunction->type(), z, a);
32 return partitionFunction->evaluate(z, a, T9);
33 } else {
34 LOG_TRACE_L3(m_logger, "Partition function of type {} does not support Z={} A={}", partitionFunction->type(), z, a);
35 }
36 }
37 LOG_ERROR(
39 "No partition function supports Z={} A={} T9={}. Tried: {}",
40 z,
41 a,
42 T9,
43 type()
44 );
45 throw std::runtime_error("No partition function supports the given Z, A, and T9 values.");
46 }
47
48 double CompositePartitionFunction::evaluateDerivative(int z, int a, double T9) const {
49 for (const auto& partitionFunction : m_partitionFunctions) {
50 if (partitionFunction->supports(z, a)) {
51 LOG_TRACE_L3(m_logger, "Evaluating derivative of partition function for Z={} A={} T9={}", z, a, T9);
52 return partitionFunction->evaluateDerivative(z, a, T9);
53 }
54 }
55 LOG_ERROR(
57 "No partition function supports Z={} A={} T9={}. Tried: {}",
58 z,
59 a,
60 T9,
61 type()
62 );
63 throw std::runtime_error("No partition function supports the given Z, A, and T9 values.");
64 }
65
66 bool CompositePartitionFunction::supports(int z, int a) const {
67 for (const auto& partitionFunction : m_partitionFunctions) {
68 if (partitionFunction->supports(z, a)) {
69 LOG_TRACE_L2(m_logger, "Partition function supports Z={} A={}", z, a);
70 return true;
71 }
72 }
73 return false;
74 }
75
77 std::stringstream ss;
78 ss << "CompositePartitionFunction(";
79 size_t count = 0;
80 for (const auto& partitionFunction : m_partitionFunctions) {
81 ss << partitionFunction->type();
82 if (count < m_partitionFunctions.size() - 1) {
83 ss << ", ";
84 }
85 count++;
86 }
87 ss << ")";
88 std::string types = ss.str();
89 return types;
90 }
91
92 std::unique_ptr<PartitionFunction> CompositePartitionFunction::selectPartitionFunction(
94 ) const {
95 switch (type) {
96 case RauscherThielemann: {
97 return std::make_unique<RauscherThielemannPartitionFunction>();
98 }
99 case GroundState: {
100 return std::make_unique<GroundStatePartitionFunction>();
101 }
102 default: {
103 LOG_ERROR(m_logger, "Unknown partition function type");
104 throw std::runtime_error("Unknown partition function type");
105 }
106 }
107 }
108}
std::unique_ptr< PartitionFunction > selectPartitionFunction(const BasePartitionType type) const
std::vector< std::unique_ptr< PartitionFunction > > m_partitionFunctions
Set of partition functions to use in the composite partition function.
double evaluate(int z, int a, double T9) const override
double evaluateDerivative(int z, int a, double T9) const override
CompositePartitionFunction(const std::vector< BasePartitionType > &partitionFunctions)
std::unordered_map< BasePartitionType, std::string > basePartitionTypeToString
Mapping from BasePartitionType enum to human-readable string.
BasePartitionType
Enumerates available partition function implementations.
@ RauscherThielemann
Rauscher-Thielemann partition function.
@ GroundState
Ground state partition function.