GridFire v0.7.0_rc2
General Purpose Nuclear Network
Loading...
Searching...
No Matches
gridfire::reaction::Reaction Class Referenceabstract

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

#include <reaction.h>

Inheritance diagram for gridfire::reaction::Reaction:
[legend]

Public Member Functions

virtual ~Reaction ()=default
 Virtual destructor for correct polymorphic cleanup.
 
virtual double calculate_rate (double T9, double rho, double Ye, double mue, const std::vector< double > &Y, const std::unordered_map< size_t, fourdst::atomic::Species > &index_to_species_map) const =0
 Compute the temperature- and composition-dependent reaction rate.
 
virtual CppAD::AD< double > calculate_rate (CppAD::AD< double > T9, CppAD::AD< double > rho, CppAD::AD< double > Ye, CppAD::AD< double > mue, const std::vector< CppAD::AD< double > > &Y, const std::unordered_map< size_t, fourdst::atomic::Species > &index_to_species_map) const =0
 AD-enabled reaction rate for algorithmic differentiation.
 
virtual std::string_view id () const =0
 A stable, unique identifier for this reaction instance.
 
virtual const std::vector< fourdst::atomic::Species > & reactants () const =0
 Ordered list of reactant species.
 
virtual const std::vector< fourdst::atomic::Species > & products () const =0
 Ordered list of product species.
 
virtual bool contains (const fourdst::atomic::Species &species) const =0
 True if the species appears as a reactant or a product.
 
virtual bool contains_reactant (const fourdst::atomic::Species &species) const =0
 True if the species appears among the reactants.
 
virtual bool contains_product (const fourdst::atomic::Species &species) const =0
 True if the species appears among the products.
 
virtual bool is_reverse () const =0
 Whether this object represents a reverse (backward) rate.
 
virtual std::unordered_set< fourdst::atomic::Species > all_species () const =0
 Set of all unique species appearing in the reaction.
 
virtual std::unordered_set< fourdst::atomic::Species > reactant_species () const =0
 Set of unique reactant species.
 
virtual std::unordered_set< fourdst::atomic::Species > product_species () const =0
 Set of unique product species.
 
virtual size_t countReactantOccurrences (const fourdst::atomic::Species &species) const =0
 
virtual size_t countProductOccurrences (const fourdst::atomic::Species &species) const =0
 
virtual size_t num_species () const =0
 Number of unique species involved in the reaction.
 
virtual std::unordered_map< fourdst::atomic::Species, int > stoichiometry () const =0
 Full stoichiometry map for this reaction.
 
virtual int stoichiometry (const fourdst::atomic::Species &species) const =0
 Stoichiometric coefficient for a particular species.
 
virtual uint64_t hash (uint64_t seed) const =0
 Stable content-based hash for this reaction.
 
virtual double qValue () const =0
 Q-value of the reaction (typically MeV), positive if exothermic.
 
virtual double calculate_energy_generation_rate (const double T9, const double rho, const double Ye, double mue, const std::vector< double > &Y, const std::unordered_map< size_t, fourdst::atomic::Species > &index_to_species_map) const
 Convenience: energy generation rate from this reaction (double version).
 
virtual CppAD::AD< double > calculate_energy_generation_rate (const CppAD::AD< double > &T9, const CppAD::AD< double > &rho, const CppAD::AD< double > &Ye, const CppAD::AD< double > &mue, const std::vector< CppAD::AD< double > > &Y, const std::unordered_map< size_t, fourdst::atomic::Species > &index_to_species_map) const
 Convenience: AD-enabled energy generation rate (AD version).
 
virtual double calculate_log_rate_partial_deriv_wrt_T9 (double T9, double rho, double Ye, double mue, const fourdst::composition::Composition &comp) const =0
 Logarithmic partial derivative of the rate with respect to temperature.
 
virtual ReactionType type () const =0
 Category of this reaction (e.g., REACLIB, WEAK, LOGICAL_REACLIB).
 
virtual std::unique_ptr< Reactionclone () const =0
 Polymorphic deep copy.
 
virtual std::optional< std::vector< RateCoefficientSet > > getRateCoefficients () const =0
 

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
Represents a single nuclear reaction from a specific data source.
Definition reaction.h:98
virtual double calculate_rate(double T9, double rho, double Ye, double mue, const std::vector< double > &Y, const std::unordered_map< size_t, fourdst::atomic::Species > &index_to_species_map) const =0
Compute the temperature- and composition-dependent reaction rate.

Constructor & Destructor Documentation

◆ ~Reaction()

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

Virtual destructor for correct polymorphic cleanup.

Member Function Documentation

◆ all_species()

virtual std::unordered_set< fourdst::atomic::Species > gridfire::reaction::Reaction::all_species ( ) const
nodiscardpure virtual

Set of all unique species appearing in the reaction.

Returns
Unordered set of all reactants and products (no duplicates).

Implemented in gridfire::rates::weak::WeakReaction, and gridfire::reaction::ReaclibReaction.

◆ calculate_energy_generation_rate() [1/2]

virtual CppAD::AD< double > gridfire::reaction::Reaction::calculate_energy_generation_rate ( const CppAD::AD< double > & T9,
const CppAD::AD< double > & rho,
const CppAD::AD< double > & Ye,
const CppAD::AD< double > & mue,
const std::vector< CppAD::AD< double > > & Y,
const std::unordered_map< size_t, fourdst::atomic::Species > & index_to_species_map ) const
inlinenodiscardvirtual

Convenience: AD-enabled energy generation rate (AD version).

Default implementation multiplies the AD rate by the reaction Q-value. Electron quantities (Ye, mue) are ignored in this default, so override if they contribute.

Parameters
T9Temperature in GK as CppAD::AD<double>.
rhoMass density as CppAD::AD<double>.
YeElectron fraction as CppAD::AD<double> (ignored by default).
mueElectron chemical potential as CppAD::AD<double> (ignored by default).
YComposition vector as CppAD::AD<double> values.
index_to_species_mapMapping from state-vector index to Species.
Returns
Energy generation rate as CppAD::AD<double>.

Reimplemented in gridfire::rates::weak::WeakReaction.

◆ calculate_energy_generation_rate() [2/2]

virtual double gridfire::reaction::Reaction::calculate_energy_generation_rate ( const double T9,
const double rho,
const double Ye,
double mue,
const std::vector< double > & Y,
const std::unordered_map< size_t, fourdst::atomic::Species > & index_to_species_map ) const
inlinenodiscardvirtual

Convenience: energy generation rate from this reaction (double version).

Default implementation multiplies the scalar rate by the reaction Q-value. Electron quantities (Ye, mue) are ignored in this default, so override in derived classes if needed. Sign convention follows qValue().

Parameters
T9Temperature in GK (10^9 K).
rhoMass density (g cm^-3).
YeElectron fraction (ignored by default implementation).
mueElectron chemical potential (ignored by default implementation).
YComposition vector.
index_to_species_mapMapping from state-vector index to Species.
Returns
Energy generation rate, typically rate * qValue().

Reimplemented in gridfire::rates::weak::WeakReaction.

◆ calculate_log_rate_partial_deriv_wrt_T9()

virtual double gridfire::reaction::Reaction::calculate_log_rate_partial_deriv_wrt_T9 ( double T9,
double rho,
double Ye,
double mue,
const fourdst::composition::Composition & comp ) const
nodiscardpure virtual

Logarithmic partial derivative of the rate with respect to temperature.

Implementations return d(ln rate)/d(ln T9) or an equivalent measure (as documented by the concrete class), evaluated at the provided state.

Parameters
T9Temperature in GK (10^9 K).
rhoMass density (g cm^-3).
YeElectron fraction.
mueElectron chemical potential.
compComposition object providing composition in a convenient form.
Returns
The logarithmic temperature derivative of the rate.

Implemented in gridfire::rates::weak::WeakReaction, gridfire::reaction::LogicalReaclibReaction, and gridfire::reaction::ReaclibReaction.

◆ calculate_rate() [1/2]

virtual CppAD::AD< double > gridfire::reaction::Reaction::calculate_rate ( CppAD::AD< double > T9,
CppAD::AD< double > rho,
CppAD::AD< double > Ye,
CppAD::AD< double > mue,
const std::vector< CppAD::AD< double > > & Y,
const std::unordered_map< size_t, fourdst::atomic::Species > & index_to_species_map ) const
nodiscardpure virtual

AD-enabled reaction rate for algorithmic differentiation.

This overload mirrors calculate_rate(double, ...) but operates on CppAD types to enable derivative calculations w.r.t. its inputs.

Parameters
T9Temperature in GK as CppAD::AD<double>.
rhoMass density as CppAD::AD<double>.
YeElectron fraction as CppAD::AD<double>.
mueElectron chemical potential as CppAD::AD<double>.
YComposition vector as CppAD::AD<double> values.
index_to_species_mapMapping from state-vector index to Species, used to interpret Y.
Returns
The reaction rate as a CppAD::AD<double> value.

Implemented in gridfire::rates::weak::WeakReaction, gridfire::reaction::LogicalReaclibReaction, and gridfire::reaction::ReaclibReaction.

◆ calculate_rate() [2/2]

virtual double gridfire::reaction::Reaction::calculate_rate ( double T9,
double rho,
double Ye,
double mue,
const std::vector< double > & Y,
const std::unordered_map< size_t, fourdst::atomic::Species > & index_to_species_map ) const
nodiscardpure virtual

Compute the temperature- and composition-dependent reaction rate.

This is the primary interface used by the network to obtain the rate of a single reaction at the given thermodynamic state and composition. The exact units and normalization are defined by the concrete implementation (e.g., REACLIB typically provides NA<sigma v> with units depending on the reaction order). Implementations may use density/electron properties for weak processes or screening, and the composition vector for multi-body reactions.

Parameters
T9Temperature in GK (10^9 K).
rhoMass density (g cm^-3). May be unused for some reaction types.
YeElectron fraction. May be unused depending on the reaction type.
mueElectron chemical potential. May be unused depending on the reaction type.
YComposition vector (molar abundances or number fractions) indexed consistently with index_to_species_map.
index_to_species_mapMapping from state-vector index to Species, used to interpret Y.
Returns
The reaction rate for the forward direction, with units/normalization defined by the specific model (implementation must document its convention).

Implemented in gridfire::rates::weak::WeakReaction, gridfire::reaction::LogicalReaclibReaction, and gridfire::reaction::ReaclibReaction.

◆ clone()

virtual std::unique_ptr< Reaction > gridfire::reaction::Reaction::clone ( ) const
nodiscardpure virtual

Polymorphic deep copy.

Returns
A std::unique_ptr owning a new Reaction equal to this one.

Implemented in gridfire::rates::weak::WeakReaction, gridfire::reaction::LogicalReaclibReaction, gridfire::reaction::ReaclibReaction, and gridfire::reaction::WeakReaclibReaction.

◆ contains()

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

True if the species appears as a reactant or a product.

Parameters
speciesSpecies to test.
Returns
Whether the species participates in the reaction (either side).

Implemented in gridfire::rates::weak::WeakReaction, and gridfire::reaction::ReaclibReaction.

◆ contains_product()

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

True if the species appears among the products.

Parameters
speciesSpecies to test.
Returns
Whether the species is a product.

Implemented in gridfire::rates::weak::WeakReaction, and gridfire::reaction::ReaclibReaction.

◆ contains_reactant()

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

True if the species appears among the reactants.

Parameters
speciesSpecies to test.
Returns
Whether the species is a reactant.

Implemented in gridfire::rates::weak::WeakReaction, and gridfire::reaction::ReaclibReaction.

◆ countProductOccurrences()

virtual size_t gridfire::reaction::Reaction::countProductOccurrences ( const fourdst::atomic::Species & species) const
nodiscardpure virtual

◆ countReactantOccurrences()

virtual size_t gridfire::reaction::Reaction::countReactantOccurrences ( const fourdst::atomic::Species & species) const
nodiscardpure virtual

◆ getRateCoefficients()

virtual std::optional< std::vector< RateCoefficientSet > > gridfire::reaction::Reaction::getRateCoefficients ( ) const
nodiscardpure virtual

◆ hash()

virtual uint64_t gridfire::reaction::Reaction::hash ( uint64_t seed) const
nodiscardpure virtual

Stable content-based hash for this reaction.

Intended for use in caches, sets, and order-independent hashing of Reaction collections. Implementations should produce the same value across processes for the same content and seed.

Parameters
seedSeed value to initialize/mix into the hash.
Returns
64-bit hash value.

Implemented in gridfire::rates::weak::WeakReaction, and gridfire::reaction::ReaclibReaction.

◆ id()

virtual std::string_view gridfire::reaction::Reaction::id ( ) const
nodiscardpure virtual

A stable, unique identifier for this reaction instance.

Returns
String view of the reaction ID (stable across runs and suitable for lookups).

Implemented in gridfire::rates::weak::WeakReaction, and gridfire::reaction::ReaclibReaction.

◆ is_reverse()

virtual bool gridfire::reaction::Reaction::is_reverse ( ) const
nodiscardpure virtual

Whether this object represents a reverse (backward) rate.

Implementations may pair forward/reverse rates for detailed balance. This flag indicates that the parameterization corresponds to the reverse direction.

Returns
True for a reverse rate, false for a forward rate.

Implemented in gridfire::rates::weak::WeakReaction, and gridfire::reaction::ReaclibReaction.

◆ num_species()

virtual size_t gridfire::reaction::Reaction::num_species ( ) const
nodiscardpure virtual

Number of unique species involved in the reaction.

Returns
Count of distinct species across reactants and products.

Implemented in gridfire::rates::weak::WeakReaction, and gridfire::reaction::ReaclibReaction.

◆ product_species()

virtual std::unordered_set< fourdst::atomic::Species > gridfire::reaction::Reaction::product_species ( ) const
nodiscardpure virtual

Set of unique product species.

Returns
Unordered set of product species (no duplicates).

Implemented in gridfire::rates::weak::WeakReaction, and gridfire::reaction::ReaclibReaction.

◆ products()

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

Ordered list of product species.

Multiplicity is represented by duplicates if applicable.

Returns
Const reference to the vector of products.

Implemented in gridfire::rates::weak::WeakReaction, and gridfire::reaction::ReaclibReaction.

◆ qValue()

virtual double gridfire::reaction::Reaction::qValue ( ) const
nodiscardpure virtual

Q-value of the reaction (typically MeV), positive if exothermic.

Returns
Reaction Q-value used for energy accounting.

Implemented in gridfire::rates::weak::WeakReaction, and gridfire::reaction::ReaclibReaction.

◆ reactant_species()

virtual std::unordered_set< fourdst::atomic::Species > gridfire::reaction::Reaction::reactant_species ( ) const
nodiscardpure virtual

Set of unique reactant species.

Returns
Unordered set of reactant species (no duplicates).

Implemented in gridfire::rates::weak::WeakReaction, and gridfire::reaction::ReaclibReaction.

◆ reactants()

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

Ordered list of reactant species.

Multiplicity is represented by duplicates, e.g., (p, p) would list H1 twice.

Returns
Const reference to the vector of reactants.

Implemented in gridfire::rates::weak::WeakReaction, and gridfire::reaction::ReaclibReaction.

◆ stoichiometry() [1/2]

virtual std::unordered_map< fourdst::atomic::Species, int > gridfire::reaction::Reaction::stoichiometry ( ) const
nodiscardpure virtual

Full stoichiometry map for this reaction.

Coefficients are negative for reactants and positive for products; multiplicity is reflected in the magnitude (e.g., 2H -> He gives H: -2, He: +1).

Returns
Map from Species to integer stoichiometric coefficient.

Implemented in gridfire::rates::weak::WeakReaction, and gridfire::reaction::ReaclibReaction.

◆ stoichiometry() [2/2]

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

Stoichiometric coefficient for a particular species.

Parameters
speciesSpecies for which to query the coefficient.
Returns
Negative for reactants, positive for products, zero if absent.

Implemented in gridfire::rates::weak::WeakReaction, and gridfire::reaction::ReaclibReaction.

◆ type()

virtual ReactionType gridfire::reaction::Reaction::type ( ) const
nodiscardpure virtual

Category of this reaction (e.g., REACLIB, WEAK, LOGICAL_REACLIB).

Returns
Enumerated reaction type for runtime dispatch and filtering.

Implemented in gridfire::rates::weak::WeakReaction, gridfire::reaction::LogicalReaclibReaction, gridfire::reaction::ReaclibReaction, and gridfire::reaction::WeakReaclibReaction.

Friends And Related Symbol Documentation

◆ operator<<

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

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