GridFire v0.7.0-alpha General Purpose Nuclear Network

Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
gridfire::Reaction Class Referenceabstract

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

`#include <reaction.h>`

Inheritance diagram for gridfire::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 | 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< Reaction > | clone () 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
gridfire::reaction::Reaction
Represents a single nuclear reaction from a specific data source.
Definition reaction.h:92
gridfire::reaction::Reaction::calculate_rate
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 | ( |  | ) |
| virtual default

Virtual destructor for correct polymorphic cleanup.

## Member Function Documentation

## ◆ all_species()

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

Set of all unique species appearing in the reaction.

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

## ◆ 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
| inline nodiscard virtual

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

  T9 | Temperature in GK as CppAD::AD<double>.
  rho | Mass density as CppAD::AD<double>.
  Ye | Electron fraction as CppAD::AD<double> (ignored by default).
  mue | Electron chemical potential as CppAD::AD<double> (ignored by default).
  Y | Composition vector as CppAD::AD<double> values.
  index_to_species_map | Mapping from state-vector index to Species.

Returns
  Energy generation rate as CppAD::AD<double>.

## ◆ 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
| inline nodiscard virtual

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

  T9 | Temperature in GK (10^9 K).
  rho | Mass density (g cm^-3).
  Ye | Electron fraction (ignored by default implementation).
  mue | Electron chemical potential (ignored by default implementation).
  Y | Composition vector.
  index_to_species_map | Mapping from state-vector index to Species.

Returns
  Energy generation rate, typically rate * qValue().

## ◆ 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
| nodiscard pure 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

  T9 | Temperature in GK (10^9 K).
  rho | Mass density (g cm^-3).
  Ye | Electron fraction.
  mue | Electron chemical potential.
  comp | Composition object providing composition in a convenient form.

Returns
  The logarithmic temperature derivative of the rate.

## ◆ 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
| nodiscard pure 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

  T9 | Temperature in GK as CppAD::AD<double>.
  rho | Mass density as CppAD::AD<double>.
  Ye | Electron fraction as CppAD::AD<double>.
  mue | Electron chemical potential as CppAD::AD<double>.
  Y | Composition vector as CppAD::AD<double> values.
  index_to_species_map | Mapping from state-vector index to Species, used to interpret Y.

Returns
  The reaction rate as a CppAD::AD<double> value.

## ◆ 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
| nodiscard pure 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

  T9 | Temperature in GK (10^9 K).
  rho | Mass density (g cm^-3). May be unused for some reaction types.
  Ye | Electron fraction. May be unused depending on the reaction type.
  mue | Electron chemical potential. May be unused depending on the reaction type.
  Y | Composition vector (molar abundances or number fractions) indexed consistently with index_to_species_map.
  index_to_species_map | Mapping 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).

## ◆ clone()

virtual std::unique_ptr< Reaction > gridfire::reaction::Reaction::clone | ( |  | ) | const
| nodiscard pure virtual

Polymorphic deep copy.

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

## ◆ contains()

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

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

Parameters

  species | Species to test.

Returns
  Whether the species participates in the reaction (either side).

## ◆ contains_product()

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

True if the species appears among the products.

Parameters

  species | Species to test.

Returns
  Whether the species is a product.

## ◆ contains_reactant()

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

True if the species appears among the reactants.

Parameters

  species | Species to test.

Returns
  Whether the species is a reactant.

## ◆ getRateCoefficients()

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

## ◆ hash()

virtual uint64_t gridfire::reaction::Reaction::hash | ( | uint64_t | seed | ) | const
| nodiscard pure 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

  seed | Seed value to initialize/mix into the hash.

Returns
  64-bit hash value.

## ◆ id()

virtual std::string_view gridfire::reaction::Reaction::id | ( |  | ) | const
| nodiscard pure virtual

A stable, unique identifier for this reaction instance.

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

## ◆ is_reverse()

virtual bool gridfire::reaction::Reaction::is_reverse | ( |  | ) | const
| nodiscard pure 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.

## ◆ num_species()

virtual size_t gridfire::reaction::Reaction::num_species | ( |  | ) | const
| nodiscard pure virtual

Number of unique species involved in the reaction.

Returns
  Count of distinct species across reactants and products.

## ◆ product_species()

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

Set of unique product species.

Returns
  Unordered set of product species (no duplicates).

## ◆ products()

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

Ordered list of product species.

Multiplicity is represented by duplicates if applicable.

Returns
  Const reference to the vector of products.

## ◆ qValue()

virtual double gridfire::reaction::Reaction::qValue | ( |  | ) | const
| nodiscard pure virtual

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

Returns
  Reaction Q-value used for energy accounting.

## ◆ reactant_species()

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

Set of unique reactant species.

Returns
  Unordered set of reactant species (no duplicates).

## ◆ reactants()

virtual const std::vector< fourdst::atomic::Species > & gridfire::reaction::Reaction::reactants | ( |  | ) | const
| nodiscard pure 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.

## ◆ stoichiometry() [1/2]

virtual std::unordered_map< fourdst::atomic::Species, int > gridfire::reaction::Reaction::stoichiometry | ( |  | ) | const
| nodiscard pure 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.

## ◆ stoichiometry() [2/2]

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

Stoichiometric coefficient for a particular species.

Parameters

  species | Species for which to query the coefficient.

Returns
  Negative for reactants, positive for products, zero if absent.

## ◆ type()

virtual ReactionType gridfire::reaction::Reaction::type | ( |  | ) | const
| nodiscard pure virtual

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

Returns
  Enumerated reaction type for runtime dispatch and filtering.

## 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:

- src/include/gridfire/reaction/reaction.h