GridFire 0.0.1a General Purpose Nuclear Network

Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
gridfire::GraphEngine Class Referencefinal

A reaction network engine that uses a graph-based representation. More...

`#include <engine_graph.h>`

Inheritance diagram for gridfire::GraphEngine:

## Classes
class | AtomicReverseRate
struct | constants
struct | PrecomputedReaction

## Public Member Functions
| GraphEngine (const fourdst::composition::Composition &composition, const BuildDepthType=NetworkBuildDepth::Full)
| Constructs a GraphEngine from a composition.
| GraphEngine (const fourdst::composition::Composition &composition, const partition::PartitionFunction &partitionFunction, const BuildDepthType buildDepth=NetworkBuildDepth::Full)
| GraphEngine (const reaction::LogicalReactionSet &reactions)
| Constructs a GraphEngine from a set of reactions.
std::expected< StepDerivatives< double >, expectations::StaleEngineError > | calculateRHSAndEnergy (const std::vector< double > &Y, const double T9, const double rho) const override
| Calculates the right-hand side (dY/dt) and energy generation rate.
void | generateJacobianMatrix (const std::vector< double > &Y_dynamic, const double T9, const double rho) const override
| Generates the Jacobian matrix for the current state.
void | generateJacobianMatrix (const std::vector< double > &Y_dynamic, double T9, double rho, const SparsityPattern &sparsityPattern) const override
void | generateStoichiometryMatrix () override
| Generates the stoichiometry matrix for the network.
double | calculateMolarReactionFlow (const reaction::Reaction &reaction, const std::vector< double > &Y, const double T9, const double rho) const override
| Calculates the molar reaction flow for a given reaction.
const std::vector< fourdst::atomic::Species > & | getNetworkSpecies () const override
| Gets the list of species in the network.
const reaction::LogicalReactionSet & | getNetworkReactions () const override
| Gets the set of logical reactions in the network.
void | setNetworkReactions (const reaction::LogicalReactionSet &reactions) override
double | getJacobianMatrixEntry (const int i, const int j) const override
| Gets an entry from the previously generated Jacobian matrix.
int | getStoichiometryMatrixEntry (const int speciesIndex, const int reactionIndex) const override
| Gets an entry from the stoichiometry matrix.
std::expected< std::unordered_map< fourdst::atomic::Species, double >, expectations::StaleEngineError > | getSpeciesTimescales (const std::vector< double > &Y, double T9, double rho) const override
| Computes timescales for all species in the network.
std::expected< std::unordered_map< fourdst::atomic::Species, double >, expectations::StaleEngineError > | getSpeciesDestructionTimescales (const std::vector< double > &Y, double T9, double rho) const override
fourdst::composition::Composition | update (const NetIn &netIn) override
| Update the internal state of the engine.
bool | isStale (const NetIn &netIn) override
bool | involvesSpecies (const fourdst::atomic::Species &species) const
| Checks if a given species is involved in the network.
void | exportToDot (const std::string &filename) const
| Exports the network to a DOT file for visualization.
void | exportToCSV (const std::string &filename) const
| Exports the network to a CSV file for analysis.
void | setScreeningModel (screening::ScreeningType) override
| Set the electron screening model.
screening::ScreeningType | getScreeningModel () const override
| Get the current electron screening model.
void | setPrecomputation (bool precompute)
bool | isPrecomputationEnabled () const
const partition::PartitionFunction & | getPartitionFunction () const
double | calculateReverseRate (const reaction::Reaction &reaction, double T9) const
double | calculateReverseRateTwoBody (const reaction::Reaction &reaction, const double T9, const double forwardRate, const double expFactor) const
double | calculateReverseRateTwoBodyDerivative (const reaction::Reaction &reaction, const double T9, const double reverseRate) const
bool | isUsingReverseReactions () const
void | setUseReverseReactions (bool useReverse)
int | getSpeciesIndex (const fourdst::atomic::Species &species) const override
std::vector< double > | mapNetInToMolarAbundanceVector (const NetIn &netIn) const override
PrimingReport | primeEngine (const NetIn &netIn) override
BuildDepthType | getDepth () const override
void | rebuild (const fourdst::composition::Composition &comp, const BuildDepthType depth) override
Public Member Functions inherited from gridfire::Engine
virtual | ~Engine ()=default
| Virtual destructor.

## Static Public Member Functions
static std::unordered_map< fourdst::atomic::Species, int > | getNetReactionStoichiometry (const reaction::Reaction &reaction)
| Gets the net stoichiometry for a given reaction.

## Private Member Functions
void | syncInternalMaps ()
| Synchronizes the internal maps.
void | collectNetworkSpecies ()
| Collects the unique species in the network.
void | populateReactionIDMap ()
| Populates the reaction ID map.
void | populateSpeciesToIndexMap ()
| Populates the species-to-index map.
void | reserveJacobianMatrix () const
| Reserves space for the Jacobian matrix.
void | recordADTape ()
| Records the AD tape for the right-hand side of the ODE.
void | collectAtomicReverseRateAtomicBases ()
void | precomputeNetwork ()
bool | validateConservation () const
| Validates mass and charge conservation across all reactions.
StepDerivatives< double > | calculateAllDerivativesUsingPrecomputation (const std::vector< double > &Y_in, const std::vector< double > &bare_rates, const std::vector< double > &bare_reverse_rates, double T9, double rho) const
template<IsArithmeticOrAD T>
T | calculateMolarReactionFlow (const reaction::Reaction &reaction, const std::vector< T > &Y, const T T9, const T rho) const
| Calculates the molar reaction flow for a given reaction.
template<IsArithmeticOrAD T>
T | calculateReverseMolarReactionFlow (T T9, T rho, std::vector< T > screeningFactors, std::vector< T > Y, size_t reactionIndex, const reaction::LogicalReaction &reaction) const
template<IsArithmeticOrAD T>
StepDerivatives< T > | calculateAllDerivatives (const std::vector< T > &Y_in, T T9, T rho) const
| Calculates all derivatives (dY/dt) and the energy generation rate.
StepDerivatives< double > | calculateAllDerivatives (const std::vector< double > &Y_in, const double T9, const double rho) const
| Calculates all derivatives (dY/dt) and the energy generation rate (double precision).
StepDerivatives< ADDouble > | calculateAllDerivatives (const std::vector< ADDouble > &Y_in, const ADDouble &T9, const ADDouble &rho) const
| Calculates all derivatives (dY/dt) and the energy generation rate (automatic differentiation).

## Private Attributes
Config & | m_config = Config::getInstance()
quill::Logger * | m_logger = LogManager::getInstance().getLogger("log")
constants | m_constants
reaction::LogicalReactionSet | m_reactions
| Set of REACLIB reactions in the network.
std::unordered_map< std::string_view, reaction::Reaction * > | m_reactionIDMap
| Map from reaction ID to REACLIBReaction. //PERF: This makes copies of REACLIBReaction and could be a performance bottleneck.
std::vector< fourdst::atomic::Species > | m_networkSpecies
| Vector of unique species in the network.
std::unordered_map< std::string_view, fourdst::atomic::Species > | m_networkSpeciesMap
| Map from species name to Species object.
std::unordered_map< fourdst::atomic::Species, size_t > | m_speciesToIndexMap
| Map from species to their index in the stoichiometry matrix.
boost::numeric::ublas::compressed_matrix< int > | m_stoichiometryMatrix
| Stoichiometry matrix (species x reactions).
boost::numeric::ublas::compressed_matrix< double > | m_jacobianMatrix
| Jacobian matrix (species x species).
CppAD::ADFun< double > | m_rhsADFun
| CppAD function for the right-hand side of the ODE.
CppAD::sparse_jac_work | m_jac_work
| Work object for sparse Jacobian calculations.
CppAD::sparse_rc< std::vector< size_t > > | m_full_jacobian_sparsity_pattern
| Full sparsity pattern for the Jacobian matrix.
std::vector< std::unique_ptr< AtomicReverseRate > > | m_atomicReverseRates
screening::ScreeningType | m_screeningType = screening::ScreeningType::BARE
| Screening type for the reaction network. Default to no screening.
std::unique_ptr< screening::ScreeningModel > | m_screeningModel = screening::selectScreeningModel(m_screeningType)
bool | m_usePrecomputation = true
| Flag to enable or disable using precomputed reactions for efficiency. Mathematically, this should not change the results. Generally end users should not need to change this.
bool | m_useReverseReactions = true
| Flag to enable or disable reverse reactions. If false, only forward reactions are considered.
BuildDepthType | m_depth
std::vector< PrecomputedReaction > | m_precomputedReactions
| Precomputed reactions for efficiency.
std::unique_ptr< partition::PartitionFunction > | m_partitionFunction
| Partition function for the network.

## Detailed Description

A reaction network engine that uses a graph-based representation.

The GraphEngine class implements the DynamicEngine interface using a graph-based representation of the reaction network. It uses sparse matrices for efficient storage and computation of the stoichiometry and Jacobian matrices. Automatic differentiation (AD) is used to calculate the Jacobian matrix.

The engine supports:

- Calculation of the right-hand side (dY/dt) and energy generation rate.
- Generation and access to the Jacobian matrix.
- Generation and access to the stoichiometry matrix.
- Calculation of molar reaction flows.
- Access to the set of logical reactions in the network.
- Computation of timescales for each species.
- Exporting the network to DOT and CSV formats for visualization and analysis.

See also
  engine_abstract.h

Definition at line 100 of file engine_graph.h.

## Constructor & Destructor Documentation

## ◆ GraphEngine() [1/3]

gridfire::GraphEngine::GraphEngine | ( | const fourdst::composition::Composition & | composition,
|  | const BuildDepthType | buildDepth = NetworkBuildDepth::Full )
| explicit

Constructs a GraphEngine from a composition.

Parameters

  composition | The composition of the material.

This constructor builds the reaction network from the given composition using the `build_reaclib_nuclear_network` function.

See also
  build_reaclib_nuclear_network

Definition at line 34 of file engine_graph.cpp.

## ◆ GraphEngine() [2/3]

gridfire::GraphEngine::GraphEngine | ( | const fourdst::composition::Composition & | composition,
|  | const partition::PartitionFunction & | partitionFunction,
|  | const BuildDepthType | buildDepth = NetworkBuildDepth::Full )
| explicit

Definition at line 39 of file engine_graph.cpp.

## ◆ GraphEngine() [3/3]

gridfire::GraphEngine::GraphEngine | ( | const reaction::LogicalReactionSet & | reactions | ) |
| explicit

Constructs a GraphEngine from a set of reactions.

Parameters

  reactions | The set of reactions to use in the network.

This constructor uses the given set of reactions to construct the reaction network.

Definition at line 50 of file engine_graph.cpp.

## Member Function Documentation

## ◆ calculateAllDerivatives() [1/3]

StepDerivatives< ADDouble > gridfire::GraphEngine::calculateAllDerivatives | ( | const std::vector< ADDouble > & | Y_in,
|  | const ADDouble & | T9,
|  | const ADDouble & | rho ) const
| nodiscard private

Calculates all derivatives (dY/dt) and the energy generation rate (automatic differentiation).

Parameters

  Y_in | Vector of current abundances for all species.
  T9 | Temperature in units of 10^9 K.
  rho | Density in g/cm^3.

Returns
  StepDerivatives<ADDouble> containing dY/dt and energy generation rate.

This method calculates the time derivatives of all species and the specific nuclear energy generation rate for the current state using automatic differentiation.

Definition at line 594 of file engine_graph.cpp.

## ◆ calculateAllDerivatives() [2/3]

StepDerivatives< double > gridfire::GraphEngine::calculateAllDerivatives | ( | const std::vector< double > & | Y_in,
|  | const double | T9,
|  | const double | rho ) const
| nodiscard private

Calculates all derivatives (dY/dt) and the energy generation rate (double precision).

Parameters

  Y_in | Vector of current abundances for all species.
  T9 | Temperature in units of 10^9 K.
  rho | Density in g/cm^3.

Returns
  StepDerivatives<double> containing dY/dt and energy generation rate.

This method calculates the time derivatives of all species and the specific nuclear energy generation rate for the current state using double precision arithmetic.

Definition at line 586 of file engine_graph.cpp.

## ◆ calculateAllDerivatives() [3/3]

template<IsArithmeticOrAD T>

StepDerivatives< T > gridfire::GraphEngine::calculateAllDerivatives | ( | const std::vector< T > & | Y_in,
|  | T | T9,
|  | T | rho ) const
| nodiscard private

Calculates all derivatives (dY/dt) and the energy generation rate.

Template Parameters

  T | The numeric type to use for the calculation.

Parameters

  Y_in | Vector of current abundances for all species.
  T9 | Temperature in units of 10^9 K.
  rho | Density in g/cm^3.

Returns
  StepDerivatives<T> containing dY/dt and energy generation rate.

This method calculates the time derivatives of all species and the specific nuclear energy generation rate for the current state.

Definition at line 715 of file engine_graph.h.

## ◆ calculateAllDerivativesUsingPrecomputation()

StepDerivatives< double > gridfire::GraphEngine::calculateAllDerivativesUsingPrecomputation | ( | const std::vector< double > & | Y_in,
|  | const std::vector< double > & | bare_rates,
|  | const std::vector< double > & | bare_reverse_rates,
|  | double | T9,
|  | double | rho ) const
| nodiscard private

Definition at line 448 of file engine_graph.cpp.

## ◆ calculateMolarReactionFlow() [1/2]

double gridfire::GraphEngine::calculateMolarReactionFlow | ( | const reaction::Reaction & | reaction,
|  | const std::vector< double > & | Y,
|  | const double | T9,
|  | const double | rho ) const
| nodiscard override virtual

Calculates the molar reaction flow for a given reaction.

Parameters

  reaction | The reaction for which to calculate the flow.
  Y | Vector of current abundances.
  T9 | Temperature in units of 10^9 K.
  rho | Density in g/cm^3.

Returns
  Molar flow rate for the reaction (e.g., mol/g/s).

This method computes the net rate at which the given reaction proceeds under the current state.

Implements gridfire::DynamicEngine.

Definition at line 623 of file engine_graph.cpp.

## ◆ calculateMolarReactionFlow() [2/2]

template<IsArithmeticOrAD T>

T gridfire::GraphEngine::calculateMolarReactionFlow | ( | const reaction::Reaction & | reaction,
|  | const std::vector< T > & | Y,
|  | const T | T9,
|  | const T | rho ) const
| private

Calculates the molar reaction flow for a given reaction.

Template Parameters

  T | The numeric type to use for the calculation.

Parameters

  reaction | The reaction for which to calculate the flow.
  Y | Vector of current abundances.
  T9 | Temperature in units of 10^9 K.
  rho | Density in g/cm^3.

Returns
  Molar flow rate for the reaction (e.g., mol/g/s).

This method computes the net rate at which the given reaction proceeds under the current state.

Definition at line 796 of file engine_graph.h.

## ◆ calculateReverseMolarReactionFlow()

template<IsArithmeticOrAD T>

T gridfire::GraphEngine::calculateReverseMolarReactionFlow | ( | T | T9,
|  | T | rho,
|  | std::vector< T > | screeningFactors,
|  | std::vector< T > | Y,
|  | size_t | reactionIndex,
|  | const reaction::LogicalReaction & | reaction ) const
| private

Definition at line 648 of file engine_graph.h.

## ◆ calculateReverseRate()

double gridfire::GraphEngine::calculateReverseRate | ( | const reaction::Reaction & | reaction,
|  | double | T9 ) const
| nodiscard

Definition at line 242 of file engine_graph.cpp.

## ◆ calculateReverseRateTwoBody()

double gridfire::GraphEngine::calculateReverseRateTwoBody | ( | const reaction::Reaction & | reaction,
|  | const double | T9,
|  | const double | forwardRate,
|  | const double | expFactor ) const
| nodiscard

Definition at line 269 of file engine_graph.cpp.

## ◆ calculateReverseRateTwoBodyDerivative()

double gridfire::GraphEngine::calculateReverseRateTwoBodyDerivative | ( | const reaction::Reaction & | reaction,
|  | const double | T9,
|  | const double | reverseRate ) const
| nodiscard

Definition at line 346 of file engine_graph.cpp.

## ◆ calculateRHSAndEnergy()

std::expected< StepDerivatives< double >, expectations::StaleEngineError > gridfire::GraphEngine::calculateRHSAndEnergy | ( | const std::vector< double > & | Y,
|  | const double | T9,
|  | const double | rho ) const
| nodiscard override virtual

Calculates the right-hand side (dY/dt) and energy generation rate.

Parameters

  Y | Vector of current abundances for all species.
  T9 | Temperature in units of 10^9 K.
  rho | Density in g/cm^3.

Returns
  StepDerivatives<double> containing dY/dt and energy generation rate.

This method calculates the time derivatives of all species and the specific nuclear energy generation rate for the current state.

See also
  StepDerivatives

Implements gridfire::Engine.

Definition at line 57 of file engine_graph.cpp.

## ◆ collectAtomicReverseRateAtomicBases()

void gridfire::GraphEngine::collectAtomicReverseRateAtomicBases | ( |  | ) |
| private

Definition at line 947 of file engine_graph.cpp.

## ◆ collectNetworkSpecies()

void gridfire::GraphEngine::collectNetworkSpecies | ( |  | ) |
| private

Collects the unique species in the network.

This method collects the unique species in the network from the reactants and products of all reactions.

Definition at line 106 of file engine_graph.cpp.

## ◆ exportToCSV()

void gridfire::GraphEngine::exportToCSV | ( | const std::string & | filename | ) | const

Exports the network to a CSV file for analysis.

Parameters

  filename | The name of the CSV file to create.

This method generates a CSV file containing information about the reactions in the network, including the reactants, products, Q-value, and reaction rate coefficients.

Exceptions

  std::runtime_error | If the file cannot be opened for writing.

Example usage:

engine.exportToCSV("network.csv");

Definition at line 788 of file engine_graph.cpp.

## ◆ exportToDot()

void gridfire::GraphEngine::exportToDot | ( | const std::string & | filename | ) | const

Exports the network to a DOT file for visualization.

Parameters

  filename | The name of the DOT file to create.

This method generates a DOT file that can be used to visualize the reaction network as a graph. The DOT file can be converted to a graphical image using Graphviz.

Exceptions

  std::runtime_error | If the file cannot be opened for writing.

Example usage:

engine.exportToDot("network.dot");

Definition at line 740 of file engine_graph.cpp.

## ◆ generateJacobianMatrix() [1/2]

void gridfire::GraphEngine::generateJacobianMatrix | ( | const std::vector< double > & | Y_dynamic,
|  | const double | T9,
|  | const double | rho ) const
| override virtual

Generates the Jacobian matrix for the current state.

Parameters

  Y_dynamic | Vector of current abundances.
  T9 | Temperature in units of 10^9 K.
  rho | Density in g/cm^3.

This method computes and stores the Jacobian matrix (∂(dY/dt)_i/∂Y_j) for the current state using automatic differentiation. The matrix can then be accessed via `getJacobianMatrixEntry()`.

See also
  getJacobianMatrixEntry()

Implements gridfire::DynamicEngine.

Definition at line 632 of file engine_graph.cpp.

## ◆ generateJacobianMatrix() [2/2]

void gridfire::GraphEngine::generateJacobianMatrix | ( | const std::vector< double > & | Y_dynamic,
|  | double | T9,
|  | double | rho,
|  | const SparsityPattern & | sparsityPattern ) const
| override virtual

Reimplemented from gridfire::DynamicEngine.

Definition at line 665 of file engine_graph.cpp.

## ◆ generateStoichiometryMatrix()

void gridfire::GraphEngine::generateStoichiometryMatrix | ( |  | ) |
| override virtual

Generates the stoichiometry matrix for the network.

This method computes and stores the stoichiometry matrix, which encodes the net change of each species in each reaction.

Implements gridfire::DynamicEngine.

Definition at line 545 of file engine_graph.cpp.

## ◆ getDepth()

BuildDepthType gridfire::GraphEngine::getDepth | ( |  | ) | const
| nodiscard override virtual

Reimplemented from gridfire::DynamicEngine.

Definition at line 434 of file engine_graph.cpp.

## ◆ getJacobianMatrixEntry()

double gridfire::GraphEngine::getJacobianMatrixEntry | ( | const int | i,
|  | const int | j ) const
| nodiscard override virtual

Gets an entry from the previously generated Jacobian matrix.

Parameters

  i | Row index (species index).
  j | Column index (species index).

Returns
  Value of the Jacobian matrix at (i, j).

The Jacobian must have been generated by `generateJacobianMatrix()` before calling this.

See also
  generateJacobianMatrix()

Implements gridfire::DynamicEngine.

Definition at line 722 of file engine_graph.cpp.

## ◆ getNetReactionStoichiometry()

std::unordered_map< fourdst::atomic::Species, int > gridfire::GraphEngine::getNetReactionStoichiometry | ( | const reaction::Reaction & | reaction | ) |
| static nodiscard

Gets the net stoichiometry for a given reaction.

Parameters

  reaction | The reaction for which to get the stoichiometry.

Returns
  Map of species to their stoichiometric coefficients.

Definition at line 727 of file engine_graph.cpp.

## ◆ getNetworkReactions()

const reaction::LogicalReactionSet & gridfire::GraphEngine::getNetworkReactions | ( |  | ) | const
| nodiscard override virtual

Gets the set of logical reactions in the network.

Returns
  Reference to the LogicalReactionSet containing all reactions.

Implements gridfire::DynamicEngine.

Definition at line 168 of file engine_graph.cpp.

## ◆ getNetworkSpecies()

const std::vector< fourdst::atomic::Species > & gridfire::GraphEngine::getNetworkSpecies | ( |  | ) | const
| nodiscard override virtual

Gets the list of species in the network.

Returns
  Vector of Species objects representing all network species.

Implements gridfire::Engine.

Definition at line 162 of file engine_graph.cpp.

## ◆ getPartitionFunction()

const partition::PartitionFunction & gridfire::GraphEngine::getPartitionFunction | ( |  | ) | const
| nodiscard

Definition at line 619 of file engine_graph.cpp.

## ◆ getScreeningModel()

screening::ScreeningType gridfire::GraphEngine::getScreeningModel | ( |  | ) | const
| nodiscard override virtual

Get the current electron screening model.

Returns
  The currently active screening model type.

Usage Example:
  screening::ScreeningType currentModel = myEngine.getScreeningModel();
  gridfire::screening::ScreeningType
  ScreeningType
  Enumerates the available plasma screening models.
  Definition screening_types.h:15

Implements gridfire::DynamicEngine.

Definition at line 607 of file engine_graph.cpp.

## ◆ getSpeciesDestructionTimescales()

std::expected< std::unordered_map< fourdst::atomic::Species, double >, expectations::StaleEngineError > gridfire::GraphEngine::getSpeciesDestructionTimescales | ( | const std::vector< double > & | Y,
|  | double | T9,
|  | double | rho ) const
| nodiscard override virtual

Implements gridfire::DynamicEngine.

Definition at line 861 of file engine_graph.cpp.

## ◆ getSpeciesIndex()

int gridfire::GraphEngine::getSpeciesIndex | ( | const fourdst::atomic::Species & | species | ) | const
| nodiscard override virtual

Implements gridfire::DynamicEngine.

Definition at line 395 of file engine_graph.cpp.

## ◆ getSpeciesTimescales()

std::expected< std::unordered_map< fourdst::atomic::Species, double >, expectations::StaleEngineError > gridfire::GraphEngine::getSpeciesTimescales | ( | const std::vector< double > & | Y,
|  | double | T9,
|  | double | rho ) const
| nodiscard override virtual

Computes timescales for all species in the network.

Parameters

  Y | Vector of current abundances.
  T9 | Temperature in units of 10^9 K.
  rho | Density in g/cm^3.

Returns
  Map from Species to their characteristic timescales (s).

This method estimates the timescale for abundance change of each species, which can be used for timestep control or diagnostics.

Implements gridfire::DynamicEngine.

Definition at line 842 of file engine_graph.cpp.

## ◆ getStoichiometryMatrixEntry()

int gridfire::GraphEngine::getStoichiometryMatrixEntry | ( | const int | speciesIndex,
|  | const int | reactionIndex ) const
| nodiscard override virtual

Gets an entry from the stoichiometry matrix.

Parameters

  speciesIndex | Index of the species.
  reactionIndex | Index of the reaction.

Returns
  Stoichiometric coefficient for the species in the reaction.

The stoichiometry matrix must have been generated by `generateStoichiometryMatrix()`.

See also
  generateStoichiometryMatrix()

Implements gridfire::DynamicEngine.

Definition at line 733 of file engine_graph.cpp.

## ◆ involvesSpecies()

bool gridfire::GraphEngine::involvesSpecies | ( | const fourdst::atomic::Species & | species | ) | const
| nodiscard

Checks if a given species is involved in the network.

Parameters

  species | The species to check.

Returns
  True if the species is involved in the network, false otherwise.

Definition at line 179 of file engine_graph.cpp.

## ◆ isPrecomputationEnabled()

bool gridfire::GraphEngine::isPrecomputationEnabled | ( |  | ) | const
| nodiscard

Definition at line 615 of file engine_graph.cpp.

## ◆ isStale()

bool gridfire::GraphEngine::isStale | ( | const NetIn & | netIn | ) |
| override virtual

Implements gridfire::DynamicEngine.

Definition at line 898 of file engine_graph.cpp.

## ◆ isUsingReverseReactions()

bool gridfire::GraphEngine::isUsingReverseReactions | ( |  | ) | const
| nodiscard

Definition at line 387 of file engine_graph.cpp.

## ◆ mapNetInToMolarAbundanceVector()

std::vector< double > gridfire::GraphEngine::mapNetInToMolarAbundanceVector | ( | const NetIn & | netIn | ) | const
| nodiscard override virtual

Implements gridfire::DynamicEngine.

Definition at line 399 of file engine_graph.cpp.

## ◆ populateReactionIDMap()

void gridfire::GraphEngine::populateReactionIDMap | ( |  | ) |
| private

Populates the reaction ID map.

This method populates the reaction ID map, which maps reaction IDs to REACLIBReaction objects.

Definition at line 135 of file engine_graph.cpp.

## ◆ populateSpeciesToIndexMap()

void gridfire::GraphEngine::populateSpeciesToIndexMap | ( |  | ) |
| private

Populates the species-to-index map.

This method populates the species-to-index map, which maps species to their index in the stoichiometry matrix.

Definition at line 144 of file engine_graph.cpp.

## ◆ precomputeNetwork()

void gridfire::GraphEngine::precomputeNetwork | ( |  | ) |
| private

Definition at line 960 of file engine_graph.cpp.

## ◆ primeEngine()

PrimingReport gridfire::GraphEngine::primeEngine | ( | const NetIn & | netIn | ) |
| nodiscard override virtual

Implements gridfire::DynamicEngine.

Definition at line 407 of file engine_graph.cpp.

## ◆ rebuild()

void gridfire::GraphEngine::rebuild | ( | const fourdst::composition::Composition & | comp,
|  | const BuildDepthType | depth )
| override virtual

Reimplemented from gridfire::DynamicEngine.

Definition at line 438 of file engine_graph.cpp.

## ◆ recordADTape()

void gridfire::GraphEngine::recordADTape | ( |  | ) |
| private

Records the AD tape for the right-hand side of the ODE.

This method records the AD tape for the right-hand side of the ODE, which is used to calculate the Jacobian matrix using automatic differentiation.

Exceptions

  std::runtime_error | If there are no species in the network.

Definition at line 902 of file engine_graph.cpp.

## ◆ reserveJacobianMatrix()

void gridfire::GraphEngine::reserveJacobianMatrix | ( |  | ) | const
| private

Reserves space for the Jacobian matrix.

This method reserves space for the Jacobian matrix, which is used to store the partial derivatives of the right-hand side of the ODE with respect to the species abundances.

Definition at line 151 of file engine_graph.cpp.

## ◆ setNetworkReactions()

void gridfire::GraphEngine::setNetworkReactions | ( | const reaction::LogicalReactionSet & | reactions | ) |
| override virtual

Implements gridfire::DynamicEngine.

Definition at line 174 of file engine_graph.cpp.

## ◆ setPrecomputation()

void gridfire::GraphEngine::setPrecomputation | ( | bool | precompute | ) |

Definition at line 611 of file engine_graph.cpp.

## ◆ setScreeningModel()

void gridfire::GraphEngine::setScreeningModel | ( | screening::ScreeningType | model | ) |
| override virtual

Set the electron screening model.

Parameters

  model | The type of screening model to use for reaction rate calculations.

This method allows changing the screening model at runtime. Screening corrections account for the electrostatic shielding of nuclei by electrons, which affects reaction rates in dense stellar plasmas.

Usage Example:
  myEngine.setScreeningModel(screening::ScreeningType::WEAK);
  gridfire::screening::ScreeningType::WEAK
  @ WEAK
  Weak screening model (Salpeter, 1954).
  Definition screening_types.h:35

Postcondition
  The engine will use the specified screening model for subsequent rate calculations.

Implements gridfire::DynamicEngine.

Definition at line 602 of file engine_graph.cpp.

## ◆ setUseReverseReactions()

void gridfire::GraphEngine::setUseReverseReactions | ( | bool | useReverse | ) |

Definition at line 391 of file engine_graph.cpp.

## ◆ syncInternalMaps()

void gridfire::GraphEngine::syncInternalMaps | ( |  | ) |
| private

Synchronizes the internal maps.

This method synchronizes the internal maps used by the engine, including the species map, reaction ID map, and species-to-index map. It also generates the stoichiometry matrix and records the AD tape.

Definition at line 81 of file engine_graph.cpp.

## ◆ update()

fourdst::composition::Composition gridfire::GraphEngine::update | ( | const NetIn & | netIn | ) |
| override virtual

Update the internal state of the engine.

Parameters

  netIn | A struct containing the current network input, such as temperature, density, and composition.

This method is intended to be implemented by derived classes to update their internal state based on the provided network conditions. For example, an adaptive engine might use this to re-evaluate which reactions and species are active. For other engines that do not support manually updating, this method might do nothing.

Usage Example:
  NetIn input = { ... };
  myEngine.update(input);
  gridfire::NetIn
  Definition network.h:53

Postcondition
  The internal state of the engine is updated to reflect the new conditions.

Implements gridfire::DynamicEngine.

Definition at line 886 of file engine_graph.cpp.

## ◆ validateConservation()

bool gridfire::GraphEngine::validateConservation | ( |  | ) | const
| nodiscard private

Validates mass and charge conservation across all reactions.

Returns
  True if all reactions conserve mass and charge, false otherwise.

This method checks that all reactions in the network conserve mass and charge. If any reaction does not conserve mass or charge, an error message is logged and false is returned.

Definition at line 187 of file engine_graph.cpp.

## Member Data Documentation

## ◆ m_atomicReverseRates

std::vector<std::unique_ptr<AtomicReverseRate> > gridfire::GraphEngine::m_atomicReverseRates
| private

Definition at line 466 of file engine_graph.h.

## ◆ m_config

Config& gridfire::GraphEngine::m_config = Config::getInstance()
| private

Definition at line 447 of file engine_graph.h.

## ◆ m_constants

constants gridfire::GraphEngine::m_constants
| private

Definition at line 450 of file engine_graph.h.

## ◆ m_depth

BuildDepthType gridfire::GraphEngine::m_depth
| private

Definition at line 475 of file engine_graph.h.

## ◆ m_full_jacobian_sparsity_pattern

CppAD::sparse_rc<std::vector<size_t> > gridfire::GraphEngine::m_full_jacobian_sparsity_pattern
| private

Full sparsity pattern for the Jacobian matrix.

Definition at line 464 of file engine_graph.h.

## ◆ m_jac_work

CppAD::sparse_jac_work gridfire::GraphEngine::m_jac_work
| mutable private

Work object for sparse Jacobian calculations.

Definition at line 463 of file engine_graph.h.

## ◆ m_jacobianMatrix

boost::numeric::ublas::compressed_matrix<double> gridfire::GraphEngine::m_jacobianMatrix
| mutable private

Jacobian matrix (species x species).

Definition at line 461 of file engine_graph.h.

## ◆ m_logger

quill::Logger* gridfire::GraphEngine::m_logger = LogManager::getInstance().getLogger("log")
| private

Definition at line 448 of file engine_graph.h.

## ◆ m_networkSpecies

std::vector<fourdst::atomic::Species> gridfire::GraphEngine::m_networkSpecies
| private

Vector of unique species in the network.

Definition at line 455 of file engine_graph.h.

## ◆ m_networkSpeciesMap

std::unordered_map<std::string_view, fourdst::atomic::Species> gridfire::GraphEngine::m_networkSpeciesMap
| private

Map from species name to Species object.

Definition at line 456 of file engine_graph.h.

## ◆ m_partitionFunction

std::unique_ptr<partition::PartitionFunction> gridfire::GraphEngine::m_partitionFunction
| private

Partition function for the network.

Definition at line 478 of file engine_graph.h.

## ◆ m_precomputedReactions

std::vector<PrecomputedReaction> gridfire::GraphEngine::m_precomputedReactions
| private

Precomputed reactions for efficiency.

Definition at line 477 of file engine_graph.h.

## ◆ m_reactionIDMap

std::unordered_map<std::string_view, reaction::Reaction*> gridfire::GraphEngine::m_reactionIDMap
| private

Map from reaction ID to REACLIBReaction. //PERF: This makes copies of REACLIBReaction and could be a performance bottleneck.

Definition at line 453 of file engine_graph.h.

## ◆ m_reactions

reaction::LogicalReactionSet gridfire::GraphEngine::m_reactions
| private

Set of REACLIB reactions in the network.

Definition at line 452 of file engine_graph.h.

## ◆ m_rhsADFun

CppAD::ADFun<double> gridfire::GraphEngine::m_rhsADFun
| mutable private

CppAD function for the right-hand side of the ODE.

Definition at line 462 of file engine_graph.h.

## ◆ m_screeningModel

std::unique_ptr<screening::ScreeningModel> gridfire::GraphEngine::m_screeningModel = screening::selectScreeningModel(m_screeningType)
| private

Definition at line 469 of file engine_graph.h.

## ◆ m_screeningType

screening::ScreeningType gridfire::GraphEngine::m_screeningType = screening::ScreeningType::BARE
| private

Screening type for the reaction network. Default to no screening.

Definition at line 468 of file engine_graph.h.

## ◆ m_speciesToIndexMap

std::unordered_map<fourdst::atomic::Species, size_t> gridfire::GraphEngine::m_speciesToIndexMap
| private

Map from species to their index in the stoichiometry matrix.

Definition at line 457 of file engine_graph.h.

## ◆ m_stoichiometryMatrix

boost::numeric::ublas::compressed_matrix<int> gridfire::GraphEngine::m_stoichiometryMatrix
| private

Stoichiometry matrix (species x reactions).

Definition at line 459 of file engine_graph.h.

## ◆ m_usePrecomputation

bool gridfire::GraphEngine::m_usePrecomputation = true
| private

Flag to enable or disable using precomputed reactions for efficiency. Mathematically, this should not change the results. Generally end users should not need to change this.

Definition at line 471 of file engine_graph.h.

## ◆ m_useReverseReactions

bool gridfire::GraphEngine::m_useReverseReactions = true
| private

Flag to enable or disable reverse reactions. If false, only forward reactions are considered.

Definition at line 473 of file engine_graph.h.

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

- src/include/gridfire/engine/engine_graph.h
- src/lib/engine/engine_graph.cpp