10#include "quill/LogMacros.h"
12#include "fourdst/composition/atomicSpecies.h"
17 using namespace fourdst::atomic;
20 const std::string_view
id,
21 const std::string_view
peName,
24 const std::vector<Species>&
products,
26 const std::string_view label,
54 if (reactant == species) {
63 if (product == species) {
73 rs.insert(ps.begin(), ps.end());
78 std::unordered_set<Species> reactantsSet;
80 reactantsSet.insert(reactant);
86 std::unordered_set<Species> productsSet;
88 productsSet.insert(product);
96 if (reactant == species) {
101 if (product == species) {
113 std::unordered_map<Species, int> stoichiometryMap;
115 stoichiometryMap[reactant]--;
118 stoichiometryMap[product]++;
120 return stoichiometryMap;
124 double reactantMass = 0.0;
125 double productMass = 0.0;
126 constexpr double AMU2MeV = 931.494893;
128 reactantMass += reactant.mass();
131 productMass += product.mass();
133 return (reactantMass - productMass) * AMU2MeV;
137 return XXHash64::hash(
m_id.data(),
m_id.size(), seed);
159 "LogicalReaction constructed with reactions having different Q-values. Expected {} got {}.",
164 throw std::runtime_error(
"LogicalReaction constructed with reactions having different Q-values. Expected " + std::to_string(
m_qValue) +
" got " + std::to_string(
reaction.qValue()) +
" (difference : " + std::to_string(std::abs(
reaction.qValue() -
m_qValue)) +
").");
173 LOG_ERROR(
m_logger,
"Cannot add reaction with different peName to LogicalReaction. Expected {} got {}.",
m_id,
reaction.peName());
175 throw std::runtime_error(
"Cannot add reaction with different peName to LogicalReaction. Expected " + std::string(
m_id) +
" got " + std::string(
reaction.peName()) +
".");
178 if (source ==
reaction.sourceLabel()) {
179 LOG_ERROR(
m_logger,
"Cannot add reaction with duplicate source label {} to LogicalReaction.",
reaction.sourceLabel());
181 throw std::runtime_error(
"Cannot add reaction with duplicate source label " + std::string(
reaction.sourceLabel()) +
" to LogicalReaction.");
185 LOG_ERROR(
m_logger,
"LogicalReaction constructed with reactions having different Q-values. Expected {} got {}.",
m_qValue,
reaction.qValue());
187 throw std::runtime_error(
"LogicalReaction constructed with reactions having different Q-values. Expected " + std::to_string(
m_qValue) +
" got " + std::to_string(
reaction.qValue()) +
".");
202 std::unordered_map<std::string_view, std::vector<Reaction>> groupedReactions;
204 for (
const auto&
reaction: reactionSet) {
208 std::vector<LogicalReaction> reactions;
209 reactions.reserve(groupedReactions.size());
211 for (
const auto &reactionsGroup: groupedReactions | std::views::values) {
213 reactions.push_back(logicalReaction);
235 struct hash<
gridfire::reaction::LogicalReactionSet> {
Represents a "logical" reaction that aggregates rates from multiple sources.
void add_reaction(const Reaction &reaction)
Adds another Reaction source to this logical reaction.
double calculate_rate(const double T9) const override
Calculates the total reaction rate by summing all source rates.
LogicalReaction(const std::vector< Reaction > &reactions)
Constructs a LogicalReaction from a vector of Reaction objects.
std::vector< std::string > m_sources
List of source labels.
std::vector< RateCoefficientSet > m_rates
List of rate coefficient sets from each source.
Represents a single nuclear reaction from a specific data source.
std::string m_sourceLabel
Source label for the rate data (e.g., "wc12w", "st08").
std::unordered_set< fourdst::atomic::Species > product_species() const
Gets a set of all unique product species.
bool contains_product(const fourdst::atomic::Species &species) const
Checks if the reaction involves a given species as a product.
std::string_view id() const
Gets the unique identifier of the reaction.
bool m_reverse
Flag indicating if this is a reverse reaction rate.
const std::vector< fourdst::atomic::Species > & reactants() const
Gets the vector of reactant species.
int m_chapter
Chapter number from the REACLIB database, defining the reaction structure.
size_t num_species() const
Gets the number of unique species involved in the reaction.
std::string_view sourceLabel() const
Gets the source label for the rate data.
std::vector< fourdst::atomic::Species > m_products
Products of the reaction.
double m_qValue
Q-value of the reaction in MeV.
std::string m_id
Unique identifier for the reaction (e.g., "h1+h1=>h2+e+nu").
int chapter() const
Gets the REACLIB chapter number.
std::string m_peName
Name of the reaction in (projectile, ejectile) notation (e.g. "p(p,g)d").
const std::vector< fourdst::atomic::Species > & products() const
Gets the vector of product species.
virtual std::string_view peName() const
Gets the reaction name in (projectile, ejectile) notation.
std::unordered_set< fourdst::atomic::Species > all_species() const
Gets a set of all unique species involved in the reaction.
Reaction(const std::string_view id, const std::string_view peName, const int chapter, const std::vector< fourdst::atomic::Species > &reactants, const std::vector< fourdst::atomic::Species > &products, const double qValue, const std::string_view label, const RateCoefficientSet &sets, const bool reverse=false)
Constructs a Reaction object.
std::unordered_set< fourdst::atomic::Species > reactant_species() const
Gets a set of all unique reactant species.
const RateCoefficientSet & rateCoefficients() const
Gets the set of rate coefficients.
std::vector< fourdst::atomic::Species > m_reactants
Reactants of the reaction.
double excess_energy() const
Calculates the excess energy from the mass difference of reactants and products.
RateCoefficientSet m_rateCoefficients
The seven rate coefficients.
bool is_reverse() const
Checks if this is a reverse reaction rate.
bool contains(const fourdst::atomic::Species &species) const
Checks if the reaction involves a given species as a reactant or product.
bool contains_reactant(const fourdst::atomic::Species &species) const
Checks if the reaction involves a given species as a reactant.
double qValue() const
Gets the Q-value of the reaction.
std::unordered_map< fourdst::atomic::Species, int > stoichiometry() const
Gets a map of all species to their stoichiometric coefficients.
virtual double calculate_rate(const double T9) const
Calculates the reaction rate for a given temperature.
uint64_t hash(uint64_t seed=0) const
Computes a hash for the reaction based on its ID.
TemplatedReactionSet< LogicalReaction > LogicalReactionSet
A set of logical reactions.
LogicalReactionSet packReactionSetToLogicalReactionSet(const ReactionSet &reactionSet)
TemplatedReactionSet< Reaction > ReactionSet
A set of reactions, typically from a single source like REACLIB.
Defines classes for representing and managing nuclear reactions.
Holds the seven coefficients for the REACLIB rate equation.
size_t operator()(const gridfire::reaction::LogicalReactionSet &s) const noexcept
size_t operator()(const gridfire::reaction::Reaction &r) const noexcept
size_t operator()(const gridfire::reaction::ReactionSet &s) const noexcept