5#include "fourdst/composition/atomicSpecies.h"
6#include "fourdst/logging/logging.h"
7#include "quill/Logger.h"
8#include <unordered_map>
10#include <unordered_set>
13#include "cppad/cppad.hpp"
48 os <<
"[" << r.
a0 <<
", " << r.
a1 <<
", " << r.
a2 <<
", "
49 << r.
a3 <<
", " << r.
a4 <<
", " << r.
a5 <<
", " << r.
a6 <<
"]";
91 const std::string_view
id,
92 const std::string_view
peName,
94 const std::vector<fourdst::atomic::Species> &
reactants,
95 const std::vector<fourdst::atomic::Species> &
products,
97 const std::string_view label,
99 const bool reverse =
false);
106 [[nodiscard]]
virtual double calculate_rate(
const double T9)
const;
113 [[nodiscard]]
virtual CppAD::AD<double>
calculate_rate(
const CppAD::AD<double> T9)
const;
144 [[nodiscard]]
bool contains(
const fourdst::atomic::Species& species)
const;
151 [[nodiscard]]
bool contains_reactant(
const fourdst::atomic::Species& species)
const;
158 [[nodiscard]]
bool contains_product(
const fourdst::atomic::Species& species)
const;
164 [[nodiscard]] std::unordered_set<fourdst::atomic::Species>
all_species()
const;
170 [[nodiscard]] std::unordered_set<fourdst::atomic::Species>
reactant_species()
const;
176 [[nodiscard]] std::unordered_set<fourdst::atomic::Species>
product_species()
const;
189 [[nodiscard]]
int stoichiometry(
const fourdst::atomic::Species& species)
const;
195 [[nodiscard]] std::unordered_map<fourdst::atomic::Species, int>
stoichiometry()
const;
201 [[nodiscard]] std::string_view
id()
const {
return m_id; }
253 [[nodiscard]] uint64_t
hash(uint64_t seed = 0)
const;
256 quill::Logger*
m_logger = fourdst::logging::LogManager::getInstance().getLogger(
"log");
275 template <
typename T>
277 const T T913 = CppAD::pow(T9, 1.0/3.0);
278 const T T953 = CppAD::pow(T9, 5.0/3.0);
279 const T logT9 = CppAD::log(T9);
287 return CppAD::exp(exponent);
313 explicit ReactionSet(std::vector<Reaction> reactions);
350 [[nodiscard]]
bool contains(
const std::string_view&
id)
const;
375 [[nodiscard]]
bool contains_species(
const fourdst::atomic::Species& species)
const;
382 [[nodiscard]]
bool contains_reactant(
const fourdst::atomic::Species& species)
const;
389 [[nodiscard]]
bool contains_product(
const fourdst::atomic::Species& species)
const;
429 [[nodiscard]] uint64_t
hash(uint64_t seed = 0)
const;
441 quill::Logger*
m_logger = fourdst::logging::LogManager::getInstance().getLogger(
"log");
493 [[nodiscard]]
double calculate_rate(
const double T9)
const override;
500 [[nodiscard]] CppAD::AD<double>
calculate_rate(
const CppAD::AD<double> T9)
const override;
525 template <
typename T>
527 T sum =
static_cast<T
>(0.0);
528 const T T913 = CppAD::pow(T9, 1.0/3.0);
529 const T T953 = CppAD::pow(T9, 5.0/3.0);
530 const T logT9 = CppAD::log(T9);
532 for (
const auto& rate :
m_rates) {
533 const T exponent = rate.a0 +
540 sum += CppAD::exp(exponent);
592 quill::Logger*
m_logger = fourdst::logging::LogManager::getInstance().getLogger(
"log");
Represents a "logical" reaction that aggregates rates from multiple sources.
T calculate_rate(const T T9) const
Template implementation for calculating the total reaction rate.
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.
std::vector< std::string > sources() const
Gets the list of source labels for the aggregated rates.
size_t size() const
Gets the number of source rates contributing to this logical reaction.
const LogicalReaction & operator[](size_t index) const
Accesses a logical reaction by its index.
std::vector< LogicalReaction > m_reactions
size_t size() const
Gets the number of logical reactions in the set.
std::unordered_map< std::string, LogicalReaction > m_reactionNameMap
Maps reaction IDs to LogicalReaction objects for quick lookup.
LogicalReactionSet()=delete
Deleted default constructor.
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.
bool operator!=(const Reaction &other) const
Compares this reaction with another for inequality.
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").
T calculate_rate(const T T9) const
Template implementation for calculating the reaction rate.
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.
int stoichiometry(const fourdst::atomic::Species &species) const
Calculates the stoichiometric coefficient for a given species.
virtual ~Reaction()=default
Virtual destructor.
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.
bool operator==(const Reaction &other) const
Compares this reaction with another for equality based on their IDs.
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.
A collection of Reaction objects.
virtual void remove_reaction(const Reaction &reaction)
Removes a reaction from the set.
bool contains_reactant(const fourdst::atomic::Species &species) const
Checks if any reaction in the set contains the given species as a reactant.
uint64_t hash(uint64_t seed=0) const
Computes a hash for the entire set.
virtual const Reaction & operator[](size_t index) const
Accesses a reaction by its index.
bool contains_product(const fourdst::atomic::Species &species) const
Checks if any reaction in the set contains the given species as a product.
bool operator==(const ReactionSet &other) const
Compares this set with another for equality.
bool operator!=(const ReactionSet &other) const
Compares this set with another for inequality.
bool contains_species(const fourdst::atomic::Species &species) const
Checks if any reaction in the set involves the given species.
virtual ~ReactionSet()=default
Virtual destructor.
virtual size_t size() const
Gets the number of reactions in the set.
void clear()
Removes all reactions from the set.
std::vector< Reaction > m_reactions
ReactionSet & operator=(const ReactionSet &other)
Copy assignment operator.
virtual void add_reaction(Reaction reaction)
Adds a reaction to the set.
std::unordered_map< std::string, Reaction > m_reactionNameMap
Maps reaction IDs to Reaction objects for quick lookup.
bool contains(const std::string_view &id) const
Checks if the set contains a reaction with the given ID.
ReactionSet(std::vector< Reaction > reactions)
Constructs a ReactionSet from a vector of reactions.
Holds the seven coefficients for the REACLIB rate equation.
friend std::ostream & operator<<(std::ostream &os, const RateCoefficientSet &r)
Overloads the stream insertion operator for easy printing.