GridFire 0.0.1a
General Purpose Nuclear Network
Loading...
Searching...
No Matches
gridfire::reaction::Reaction Class Reference

Represents a single nuclear reaction from a specific data source. More...

#include <reaction.h>

Inheritance diagram for gridfire::reaction::Reaction:
gridfire::reaction::LogicalReaction

Public Member Functions

virtual ~Reaction ()=default
 Virtual destructor.
 
 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.
 
virtual double calculate_rate (const double T9) const
 Calculates the reaction rate for a given temperature.
 
virtual CppAD::AD< double > calculate_rate (const CppAD::AD< double > T9) const
 Calculates the reaction rate for a given temperature using CppAD types.
 
virtual std::string_view peName () const
 Gets the reaction name in (projectile, ejectile) notation.
 
int chapter () const
 Gets the REACLIB chapter number.
 
std::string_view sourceLabel () const
 Gets the source label for the rate data.
 
const RateCoefficientSetrateCoefficients () const
 Gets the set of rate coefficients.
 
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.
 
bool contains_product (const fourdst::atomic::Species &species) const
 Checks if the reaction involves a given species as a product.
 
std::unordered_set< fourdst::atomic::Species > all_species () const
 Gets a set of all unique species involved in the reaction.
 
std::unordered_set< fourdst::atomic::Species > reactant_species () const
 Gets a set of all unique reactant species.
 
std::unordered_set< fourdst::atomic::Species > product_species () const
 Gets a set of all unique product species.
 
size_t num_species () const
 Gets the number of unique species involved in the reaction.
 
int stoichiometry (const fourdst::atomic::Species &species) const
 Calculates the stoichiometric coefficient for a given species.
 
std::unordered_map< fourdst::atomic::Species, int > stoichiometry () const
 Gets a map of all species to their stoichiometric coefficients.
 
std::string_view id () const
 Gets the unique identifier of the reaction.
 
double qValue () const
 Gets the Q-value of the reaction.
 
const std::vector< fourdst::atomic::Species > & reactants () const
 Gets the vector of reactant species.
 
const std::vector< fourdst::atomic::Species > & products () const
 Gets the vector of product species.
 
bool is_reverse () const
 Checks if this is a reverse reaction rate.
 
double excess_energy () const
 Calculates the excess energy from the mass difference of reactants and products.
 
bool operator== (const Reaction &other) const
 Compares this reaction with another for equality based on their IDs.
 
bool operator!= (const Reaction &other) const
 Compares this reaction with another for inequality.
 
uint64_t hash (uint64_t seed=0) const
 Computes a hash for the reaction based on its ID.
 

Protected Attributes

quill::Logger * m_logger = fourdst::logging::LogManager::getInstance().getLogger("log")
 
std::string m_id
 Unique identifier for the reaction (e.g., "h1+h1=>h2+e+nu").
 
std::string m_peName
 Name of the reaction in (projectile, ejectile) notation (e.g. "p(p,g)d").
 
int m_chapter
 Chapter number from the REACLIB database, defining the reaction structure.
 
double m_qValue = 0.0
 Q-value of the reaction in MeV.
 
std::vector< fourdst::atomic::Species > m_reactants
 Reactants of the reaction.
 
std::vector< fourdst::atomic::Species > m_products
 Products of the reaction.
 
std::string m_sourceLabel
 Source label for the rate data (e.g., "wc12w", "st08").
 
RateCoefficientSet m_rateCoefficients
 The seven rate coefficients.
 
bool m_reverse = false
 Flag indicating if this is a reverse reaction rate.
 

Private Member Functions

template<typename T>
calculate_rate (const T T9) const
 Template implementation for calculating the reaction rate.
 

Friends

std::ostream & operator<< (std::ostream &os, const Reaction &r)
 

Detailed Description

Represents a single nuclear reaction from a specific data source.

This class encapsulates all properties of a single nuclear reaction as defined in formats like REACLIB, including reactants, products, Q-value, and rate coefficients from a particular evaluation (source).

Example:

// Assuming species and rate coefficients are defined
Reaction p_gamma_d(
"H_1_H_1_to_H_2", "p(p,g)d", 1, {H_1, H_1}, {H_2}, 5.493, "st08", rate_coeffs
);
double rate = p_gamma_d.calculate_rate(0.1); // T9 = 0.1
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.
Definition reaction.cpp:19

Definition at line 72 of file reaction.h.

Constructor & Destructor Documentation

◆ ~Reaction()

virtual gridfire::reaction::Reaction::~Reaction ( )
virtualdefault

Virtual destructor.

◆ Reaction()

gridfire::reaction::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.

Parameters
idA unique identifier for the reaction.
peNameThe name in (projectile, ejectile) notation (e.g., "p(p,g)d").
chapterThe REACLIB chapter number, defining reaction structure.
reactantsA vector of reactant species.
productsA vector of product species.
qValueThe Q-value of the reaction in MeV.
labelThe source label for the rate data (e.g., "wc12", "st08").
setsThe set of rate coefficients.
reverseTrue if this is a reverse reaction rate.

Definition at line 19 of file reaction.cpp.

Member Function Documentation

◆ all_species()

std::unordered_set< Species > gridfire::reaction::Reaction::all_species ( ) const
nodiscard

Gets a set of all unique species involved in the reaction.

Returns
An unordered_set of all reactant and product species.

Definition at line 70 of file reaction.cpp.

◆ calculate_rate() [1/3]

CppAD::AD< double > gridfire::reaction::Reaction::calculate_rate ( const CppAD::AD< double > T9) const
nodiscardvirtual

Calculates the reaction rate for a given temperature using CppAD types.

Parameters
T9The temperature in units of 10^9 K, as a CppAD::AD<double>.
Returns
The calculated reaction rate, as a CppAD::AD<double>.

Reimplemented in gridfire::reaction::LogicalReaction.

Definition at line 43 of file reaction.cpp.

◆ calculate_rate() [2/3]

double gridfire::reaction::Reaction::calculate_rate ( const double T9) const
nodiscardvirtual

Calculates the reaction rate for a given temperature.

Parameters
T9The temperature in units of 10^9 K.
Returns
The calculated reaction rate.

Reimplemented in gridfire::reaction::LogicalReaction.

Definition at line 39 of file reaction.cpp.

◆ calculate_rate() [3/3]

template<typename T>
T gridfire::reaction::Reaction::calculate_rate ( const T T9) const
inlinenodiscardprivate

Template implementation for calculating the reaction rate.

Template Parameters
TThe numeric type (double or CppAD::AD<double>).
Parameters
T9The temperature in units of 10^9 K.
Returns
The calculated reaction rate.

The rate is calculated using the standard REACLIB formula: rate = exp(a0 + a1/T9 + a2/T9^(1/3) + a3*T9^(1/3) + a4*T9 + a5*T9^(5/3) + a6*ln(T9))

Definition at line 281 of file reaction.h.

◆ chapter()

int gridfire::reaction::Reaction::chapter ( ) const
inlinenodiscard

Gets the REACLIB chapter number.

Returns
The chapter number.

Definition at line 126 of file reaction.h.

◆ contains()

bool gridfire::reaction::Reaction::contains ( const fourdst::atomic::Species & species) const
nodiscard

Checks if the reaction involves a given species as a reactant or product.

Parameters
speciesThe species to check for.
Returns
True if the species is involved, false otherwise.

Definition at line 47 of file reaction.cpp.

◆ contains_product()

bool gridfire::reaction::Reaction::contains_product ( const fourdst::atomic::Species & species) const
nodiscard

Checks if the reaction involves a given species as a product.

Parameters
speciesThe species to check for.
Returns
True if the species is a product, false otherwise.

Definition at line 61 of file reaction.cpp.

◆ contains_reactant()

bool gridfire::reaction::Reaction::contains_reactant ( const fourdst::atomic::Species & species) const
nodiscard

Checks if the reaction involves a given species as a reactant.

Parameters
speciesThe species to check for.
Returns
True if the species is a reactant, false otherwise.

Definition at line 52 of file reaction.cpp.

◆ excess_energy()

double gridfire::reaction::Reaction::excess_energy ( ) const
nodiscard

Calculates the excess energy from the mass difference of reactants and products.

Returns
The excess energy in MeV.

Definition at line 123 of file reaction.cpp.

◆ hash()

uint64_t gridfire::reaction::Reaction::hash ( uint64_t seed = 0) const
nodiscard

Computes a hash for the reaction based on its ID.

Parameters
seedThe seed for the hash function.
Returns
A 64-bit hash value.

Uses the XXHash64 algorithm on the reaction's ID string.

Definition at line 136 of file reaction.cpp.

◆ id()

std::string_view gridfire::reaction::Reaction::id ( ) const
inlinenodiscard

Gets the unique identifier of the reaction.

Returns
The reaction ID.

Definition at line 202 of file reaction.h.

◆ is_reverse()

bool gridfire::reaction::Reaction::is_reverse ( ) const
inlinenodiscard

Checks if this is a reverse reaction rate.

Returns
True if it is a reverse rate, false otherwise.

Definition at line 226 of file reaction.h.

◆ num_species()

size_t gridfire::reaction::Reaction::num_species ( ) const
nodiscard

Gets the number of unique species involved in the reaction.

Returns
The count of unique species.

Definition at line 108 of file reaction.cpp.

◆ operator!=()

bool gridfire::reaction::Reaction::operator!= ( const Reaction & other) const
inline

Compares this reaction with another for inequality.

Parameters
otherThe other Reaction to compare with.
Returns
True if the reactions are not equal.

Definition at line 246 of file reaction.h.

◆ operator==()

bool gridfire::reaction::Reaction::operator== ( const Reaction & other) const
inline

Compares this reaction with another for equality based on their IDs.

Parameters
otherThe other Reaction to compare with.
Returns
True if the reaction IDs are the same.

Definition at line 239 of file reaction.h.

◆ peName()

virtual std::string_view gridfire::reaction::Reaction::peName ( ) const
inlinenodiscardvirtual

Gets the reaction name in (projectile, ejectile) notation.

Returns
The reaction name (e.g., "p(p,g)d").

Definition at line 120 of file reaction.h.

◆ product_species()

std::unordered_set< Species > gridfire::reaction::Reaction::product_species ( ) const
nodiscard

Gets a set of all unique product species.

Returns
An unordered_set of product species.

Definition at line 85 of file reaction.cpp.

◆ products()

const std::vector< fourdst::atomic::Species > & gridfire::reaction::Reaction::products ( ) const
inlinenodiscard

Gets the vector of product species.

Returns
A const reference to the vector of products.

Definition at line 220 of file reaction.h.

◆ qValue()

double gridfire::reaction::Reaction::qValue ( ) const
inlinenodiscard

Gets the Q-value of the reaction.

Returns
The Q-value in whatever units the reaction was defined in (usually MeV).

Definition at line 208 of file reaction.h.

◆ rateCoefficients()

const RateCoefficientSet & gridfire::reaction::Reaction::rateCoefficients ( ) const
inlinenodiscard

Gets the set of rate coefficients.

Returns
A const reference to the RateCoefficientSet.

Definition at line 138 of file reaction.h.

◆ reactant_species()

std::unordered_set< Species > gridfire::reaction::Reaction::reactant_species ( ) const
nodiscard

Gets a set of all unique reactant species.

Returns
An unordered_set of reactant species.

Definition at line 77 of file reaction.cpp.

◆ reactants()

const std::vector< fourdst::atomic::Species > & gridfire::reaction::Reaction::reactants ( ) const
inlinenodiscard

Gets the vector of reactant species.

Returns
A const reference to the vector of reactants.

Definition at line 214 of file reaction.h.

◆ sourceLabel()

std::string_view gridfire::reaction::Reaction::sourceLabel ( ) const
inlinenodiscard

Gets the source label for the rate data.

Returns
The source label (e.g., "wc12w", "st08").

Definition at line 132 of file reaction.h.

◆ stoichiometry() [1/2]

std::unordered_map< Species, int > gridfire::reaction::Reaction::stoichiometry ( ) const
nodiscard

Gets a map of all species to their stoichiometric coefficients.

Returns
An unordered_map from species to their integer coefficients.

Definition at line 112 of file reaction.cpp.

◆ stoichiometry() [2/2]

int gridfire::reaction::Reaction::stoichiometry ( const fourdst::atomic::Species & species) const
nodiscard

Calculates the stoichiometric coefficient for a given species.

Parameters
speciesThe species for which to find the coefficient.
Returns
The stoichiometric coefficient (negative for reactants, positive for products).

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const Reaction & r )
friend

Definition at line 256 of file reaction.h.

Member Data Documentation

◆ m_chapter

int gridfire::reaction::Reaction::m_chapter
protected

Chapter number from the REACLIB database, defining the reaction structure.

Definition at line 264 of file reaction.h.

◆ m_id

std::string gridfire::reaction::Reaction::m_id
protected

Unique identifier for the reaction (e.g., "h1+h1=>h2+e+nu").

Definition at line 262 of file reaction.h.

◆ m_logger

quill::Logger* gridfire::reaction::Reaction::m_logger = fourdst::logging::LogManager::getInstance().getLogger("log")
protected

Definition at line 261 of file reaction.h.

◆ m_peName

std::string gridfire::reaction::Reaction::m_peName
protected

Name of the reaction in (projectile, ejectile) notation (e.g. "p(p,g)d").

Definition at line 263 of file reaction.h.

◆ m_products

std::vector<fourdst::atomic::Species> gridfire::reaction::Reaction::m_products
protected

Products of the reaction.

Definition at line 267 of file reaction.h.

◆ m_qValue

double gridfire::reaction::Reaction::m_qValue = 0.0
protected

Q-value of the reaction in MeV.

Definition at line 265 of file reaction.h.

◆ m_rateCoefficients

RateCoefficientSet gridfire::reaction::Reaction::m_rateCoefficients
protected

The seven rate coefficients.

Definition at line 269 of file reaction.h.

◆ m_reactants

std::vector<fourdst::atomic::Species> gridfire::reaction::Reaction::m_reactants
protected

Reactants of the reaction.

Definition at line 266 of file reaction.h.

◆ m_reverse

bool gridfire::reaction::Reaction::m_reverse = false
protected

Flag indicating if this is a reverse reaction rate.

Definition at line 270 of file reaction.h.

◆ m_sourceLabel

std::string gridfire::reaction::Reaction::m_sourceLabel
protected

Source label for the rate data (e.g., "wc12w", "st08").

Definition at line 268 of file reaction.h.


The documentation for this class was generated from the following files: