GridFire 0.0.1a General Purpose Nuclear Network

Loading...
Searching...
No Matches
partition_composite.cpp
Go to the documentation of this file.
1#include "gridfire/partition/composite/partition_composite.h"
2
3#include <vector>
4#include <set>
5
6#include "gridfire/partition/partition_ground.h"
7#include "gridfire/partition/partition_rauscher_thielemann.h"
8#include "quill/LogMacros.h"
9
10 namespace gridfire::partition {
11 CompositePartitionFunction::CompositePartitionFunction(
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]);
16 m_partitionFunctions.push_back(selectPartitionFunction(type));
17 }
18 }
19
20 CompositePartitionFunction::CompositePartitionFunction(const CompositePartitionFunction &other) {
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(
38 m_logger,
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(
56 m_logger,
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
76 std::string CompositePartitionFunction::type() const {
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(
93 const BasePartitionType type
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}
gridfire::partition::CompositePartitionFunction::selectPartitionFunction
std::unique_ptr< PartitionFunction > selectPartitionFunction(const BasePartitionType type) const
Definition partition_composite.cpp:92
gridfire::partition::CompositePartitionFunction::type
std::string type() const override
Definition partition_composite.cpp:76
gridfire::partition::CompositePartitionFunction::m_partitionFunctions
std::vector< std::unique_ptr< PartitionFunction > > m_partitionFunctions
Set of partition functions to use in the composite partition function.
Definition partition_composite.h:93
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::CompositePartitionFunction
CompositePartitionFunction(const std::vector< BasePartitionType > &partitionFunctions)
Definition partition_composite.cpp:11
gridfire::partition::CompositePartitionFunction::m_logger
quill::Logger * m_logger
Definition partition_composite.h:92
gridfire::partition::CompositePartitionFunction::supports
bool supports(int z, int a) const override
Definition partition_composite.cpp:66
gridfire::partition
Definition partition_composite.h:15
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
partition_composite.h
partition_ground.h
partition_rauscher_thielemann.h