|
GridFire v0.7.0-alpha
General Purpose Nuclear Network
|
An engine view that partitions the reaction network into multiple groups based on timescales. More...
#include <engine_multiscale.h>
Classes | |
| struct | CacheStats |
| Struct for tracking cache statistics. More... | |
| struct | EigenFunctor |
| Functor for solving QSE abundances using Eigen's nonlinear optimization. More... | |
| struct | QSEGroup |
| Struct representing a QSE group. More... | |
Public Member Functions | |
| MultiscalePartitioningEngineView (DynamicEngine &baseEngine) | |
| Constructs a MultiscalePartitioningEngineView. | |
| const std::vector< fourdst::atomic::Species > & | getNetworkSpecies () const override |
| Gets the list of species in the network. | |
| std::expected< StepDerivatives< double >, expectations::StaleEngineError > | calculateRHSAndEnergy (const fourdst::composition::Composition &comp, double T9, double rho) const override |
| Calculates the right-hand side (dY/dt) and energy generation. | |
| EnergyDerivatives | calculateEpsDerivatives (const fourdst::composition::Composition &comp, double T9, double rho) const override |
| Calculate the derivatives of the energy generation rate with respect to T and rho. | |
| void | generateJacobianMatrix (const fourdst::composition::Composition &comp, double T9, double rho) const override |
| Generates the Jacobian matrix for the current state. | |
| void | generateJacobianMatrix (const fourdst::composition::Composition &comp, double T9, double rho, const std::vector< fourdst::atomic::Species > &activeSpecies) const override |
| Generates the Jacobian matrix for a subset of active species. | |
| void | generateJacobianMatrix (const fourdst::composition::Composition &comp, double T9, double rho, const SparsityPattern &sparsityPattern) const override |
| Generates the Jacobian matrix using a sparsity pattern. | |
| double | getJacobianMatrixEntry (const fourdst::atomic::Species &rowSpecies, const fourdst::atomic::Species &colSpecies) const override |
| Gets an entry from the previously generated Jacobian matrix. | |
| void | generateStoichiometryMatrix () override |
| Generates the stoichiometry matrix for the network. | |
| int | getStoichiometryMatrixEntry (const fourdst::atomic::Species &species, const reaction::Reaction &reaction) const override |
| Gets an entry from the stoichiometry matrix. | |
| double | calculateMolarReactionFlow (const reaction::Reaction &reaction, const fourdst::composition::Composition &comp, double T9, double rho) const override |
| Calculates the molar reaction flow for a given reaction. | |
| const reaction::ReactionSet & | getNetworkReactions () const override |
| Gets the set of logical reactions in the network. | |
| void | setNetworkReactions (const reaction::ReactionSet &reactions) override |
| Sets the set of logical reactions in the network. | |
| std::expected< std::unordered_map< fourdst::atomic::Species, double >, expectations::StaleEngineError > | getSpeciesTimescales (const fourdst::composition::Composition &comp, 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 fourdst::composition::Composition &comp, double T9, double rho) const override |
| Computes destruction timescales for all species in the network. | |
| fourdst::composition::Composition | update (const NetIn &netIn) override |
| Updates the internal state of the engine, performing partitioning and QSE equilibration. | |
| bool | isStale (const NetIn &netIn) override |
| Checks if the engine's internal state is stale relative to the provided conditions. | |
| void | setScreeningModel (screening::ScreeningType model) override |
| Sets the electron screening model. | |
| screening::ScreeningType | getScreeningModel () const override |
| Gets the current electron screening model. | |
| const DynamicEngine & | getBaseEngine () const override |
| Gets the base engine. | |
| std::vector< std::vector< fourdst::atomic::Species > > | analyzeTimescalePoolConnectivity (const std::vector< std::vector< fourdst::atomic::Species > > ×cale_pools, const fourdst::composition::Composition &comp, double T9, double rho) const |
| Analyzes the connectivity of timescale pools. | |
| void | partitionNetwork (const fourdst::composition::Composition &comp, double T9, double rho) |
| Partitions the network into dynamic and algebraic (QSE) groups based on timescales. | |
| void | partitionNetwork (const NetIn &netIn) |
Partitions the network based on timescales from a NetIn struct. | |
| void | exportToDot (const std::string &filename, const fourdst::composition::Composition &comp, double T9, double rho) const |
| Exports the network to a DOT file for visualization. | |
| size_t | getSpeciesIndex (const fourdst::atomic::Species &species) const override |
| Gets the index of a species in the full network. | |
| std::vector< double > | mapNetInToMolarAbundanceVector (const NetIn &netIn) const override |
Maps a NetIn struct to a molar abundance vector for the full network. | |
| PrimingReport | primeEngine (const NetIn &netIn) override |
| Primes the engine with a specific species. | |
| std::vector< fourdst::atomic::Species > | getFastSpecies () const |
| Gets the fast species in the network. | |
| const std::vector< fourdst::atomic::Species > & | getDynamicSpecies () const |
| Gets the dynamic species in the network. | |
| fourdst::composition::Composition | equilibrateNetwork (const fourdst::composition::Composition &comp, double T9, double rho) |
| Equilibrates the network by partitioning and solving for QSE abundances. | |
| fourdst::composition::Composition | equilibrateNetwork (const NetIn &netIn) |
Equilibrates the network using QSE from a NetIn struct. | |
| bool | involvesSpecies (const fourdst::atomic::Species &species) const |
| bool | involvesSpeciesInQSE (const fourdst::atomic::Species &species) const |
| bool | involvesSpeciesInDynamic (const fourdst::atomic::Species &species) const |
| fourdst::composition::Composition | collectComposition (fourdst::composition::Composition &comp) const override |
| Collect the composition from this and sub engines. | |
Public Member Functions inherited from gridfire::DynamicEngine | |
| virtual BuildDepthType | getDepth () const |
| Get the depth of the network. | |
| virtual void | rebuild (const fourdst::composition::Composition &comp, BuildDepthType depth) |
| Rebuild the network with a specified depth. | |
Public Member Functions inherited from gridfire::Engine | |
| virtual | ~Engine ()=default |
| Virtual destructor. | |
Public Member Functions inherited from gridfire::EngineView< DynamicEngine > | |
| virtual | ~EngineView ()=default |
| Virtual destructor. | |
Private Types | |
| typedef std::tuple< std::vector< fourdst::atomic::Species >, std::vector< size_t >, std::vector< fourdst::atomic::Species >, std::vector< size_t > > | QSEPartition |
| Type alias for a QSE partition. | |
Private Member Functions | |
| std::vector< std::vector< fourdst::atomic::Species > > | partitionByTimescale (const fourdst::composition::Composition &comp, double T9, double rho) const |
| Partitions the network by timescale. | |
| std::pair< std::vector< MultiscalePartitioningEngineView::QSEGroup >, std::vector< MultiscalePartitioningEngineView ::QSEGroup > > | validateGroupsWithFluxAnalysis (const std::vector< QSEGroup > &candidate_groups, const fourdst::composition::Composition &comp, double T9, double rho) const |
| Validates candidate QSE groups using flux analysis. | |
| fourdst::composition::Composition | solveQSEAbundances (const fourdst::composition::Composition &comp, double T9, double rho) |
| Solves for the QSE abundances of the algebraic species in a given state. | |
| size_t | identifyMeanSlowestPool (const std::vector< std::vector< fourdst::atomic::Species > > &pools, const fourdst::composition::Composition &comp, double T9, double rho) const |
| Identifies the pool with the slowest mean timescale. | |
| std::unordered_map< fourdst::atomic::Species, std::vector< fourdst::atomic::Species > > | buildConnectivityGraph (const std::vector< fourdst::atomic::Species > &species_pool) const |
| Builds a connectivity graph from a species pool. | |
| std::vector< QSEGroup > | constructCandidateGroups (const std::vector< std::vector< fourdst::atomic::Species > > &candidate_pools, const fourdst::composition::Composition &comp, double T9, double rho) const |
| Constructs candidate QSE groups from connected timescale pools. | |
Private Attributes | |
| quill::Logger * | m_logger = LogManager::getInstance().getLogger("log") |
| Logger instance for logging messages. | |
| DynamicEngine & | m_baseEngine |
| The base engine to which this view delegates calculations. | |
| std::vector< QSEGroup > | m_qse_groups |
| The list of identified equilibrium groups. | |
| std::vector< fourdst::atomic::Species > | m_dynamic_species |
| The simplified set of species presented to the solver (the "slow" species). | |
| std::vector< fourdst::atomic::Species > | m_algebraic_species |
| Species that are treated as algebraic (in QSE) in the QSE groups. | |
| std::unordered_map< fourdst::atomic::Species, double > | m_algebraic_abundances |
| Map from species to their calculated abundances in the QSE state. | |
| std::vector< size_t > | m_activeSpeciesIndices |
| Indices of all species considered active in the current partition (dynamic + algebraic). | |
| std::vector< size_t > | m_activeReactionIndices |
| Indices of all reactions involving only active species. | |
| std::unordered_map< QSECacheKey, std::vector< double > > | m_qse_abundance_cache |
| Cache for QSE abundances based on T9, rho, and Y. | |
| CacheStats | m_cacheStats |
| Statistics for the QSE abundance cache. | |
An engine view that partitions the reaction network into multiple groups based on timescales.
partitionNetwork() and equilibrateNetwork() methods. The partitioning process involves:getSpeciesDestructionTimescales from the base engine, all species are sorted by their characteristic timescales.solveQSEAbundances uses a Levenberg-Marquardt nonlinear solver (Eigen::LevenbergMarquardt) to find the equilibrium abundances of the "algebraic" species, holding the "seed" species constant.All calculations are cached using QSECacheKey to avoid re-partitioning and re-solving for similar thermodynamic conditions.
<DynamicEngine>
|
private |
Type alias for a QSE partition.
A QSE partition is a tuple containing the fast species, their indices, the slow species, and their indices.
|
explicit |
Constructs a MultiscalePartitioningEngineView.
| baseEngine | The underlying GraphEngine to which this view delegates calculations. It must be a GraphEngine and not a more general DynamicEngine because this view relies on its specific implementation details. |
| std::vector< std::vector< Species > > gridfire::MultiscalePartitioningEngineView::analyzeTimescalePoolConnectivity | ( | const std::vector< std::vector< fourdst::atomic::Species > > & | timescale_pools, |
| const fourdst::composition::Composition & | comp, | ||
| double | T9, | ||
| double | rho ) const |
Analyzes the connectivity of timescale pools.
| timescale_pools | A vector of vectors of species indices, where each inner vector represents a timescale pool. |
| comp | Vector of current molar abundances for the full network. |
| T9 | Temperature in units of 10^9 K. |
| rho | Density in g/cm^3. |
buildConnectivityGraph. It then finds the connected components within that graph using a Breadth-First Search (BFS). The resulting components from all pools are collected and returned.
|
private |
Builds a connectivity graph from a species pool.
| species_pool | A vector of species indices representing a species pool. |
species_pool (one as a reactant and one as a product), it adds edges between all reactants and products from that reaction that are also in the pool.
|
nodiscardoverridevirtual |
Calculate the derivatives of the energy generation rate with respect to T and rho.
| comp | Composition object containing current abundances. |
| T9 | Temperature in units of 10^9 K. |
| rho | Density in g/cm^3. |
This method computes the partial derivatives of the specific nuclear energy generation rate with respect to temperature and density for the current state.
Implements gridfire::DynamicEngine.
|
nodiscardoverridevirtual |
Calculates the molar reaction flow for a given reaction.
| reaction | The reaction for which to calculate the flow. |
| comp | The current composition. |
| T9 | Temperature in units of 10^9 K. |
| rho | Density in g/cm^3. |
Y_full, overwrites the algebraic species abundances with the cached equilibrium values, and then calls the base engine's calculateMolarReactionFlow with this modified abundance vector.| StaleEngineError | If the QSE cache misses. |
Implements gridfire::DynamicEngine.
|
nodiscardoverridevirtual |
Calculates the right-hand side (dY/dt) and energy generation.
| comp | The current composition. |
| T9 | Temperature in units of 10^9 K. |
| rho | Density in g/cm^3. |
std::expected containing StepDerivatives<double> on success, or a StaleEngineError if the engine's QSE cache does not contain a solution for the given state.m_qse_abundance_cache). If a cache hit occurs, it calls the base engine's calculateRHSAndEnergy. It then manually sets the time derivatives (dydt) of all identified algebraic species to zero, effectively removing their differential equations from the system being solved.update() or equilibrateNetwork() for the current thermodynamic conditions, so that a valid entry exists in the QSE cache. dydt=0 for all algebraic species.| StaleEngineError | If the QSE cache does not contain an entry for the given (T9, rho, Y_full). This indicates update() was not called recently enough. |
Implements gridfire::Engine.
|
overridevirtual |
Collect the composition from this and sub engines.
This method operates by injecting the current equilibrium abundances for algebraic species into the composition object so that they can be bubbled up to the caller.
| comp | Input Composition |
| BadCollectionError | if there is a species in the algebraic species set which does not show up in the reported composition from the base engine.:w |
Implements gridfire::DynamicEngine.
|
private |
Constructs candidate QSE groups from connected timescale pools.
| candidate_pools | A vector of vectors of species indices, where each inner vector represents a connected pool of species with similar fast timescales. |
| comp | Vector of current molar abundances. |
| T9 | Temperature in units of 10^9 K. |
| rho | Density in g/cm^3. |
QSEGroup structs, ready for flux validation.QSEGroup struct.candidate_pools should be connected components from analyzeTimescalePoolConnectivity. QSEGroup objects is returned. | fourdst::composition::Composition gridfire::MultiscalePartitioningEngineView::equilibrateNetwork | ( | const fourdst::composition::Composition & | comp, |
| double | T9, | ||
| double | rho ) |
Equilibrates the network by partitioning and solving for QSE abundances.
| comp | Vector of current molar abundances for the full network. |
| T9 | Temperature in units of 10^9 K. |
| rho | Density in g/cm^3. |
partitionNetwork() with the given state to define the QSE groups. Then, it calls solveQSEAbundances() to compute the new equilibrium abundances for the algebraic species. Finally, it packs the resulting full abundance vector into a new fourdst::composition::Composition object and returns it.| fourdst::composition::Composition gridfire::MultiscalePartitioningEngineView::equilibrateNetwork | ( | const NetIn & | netIn | ) |
Equilibrates the network using QSE from a NetIn struct.
| netIn | A struct containing the current network input. |
equilibrateNetwork.netIn struct into Y, T9, and rho and then calls the primary equilibrateNetwork method. | void gridfire::MultiscalePartitioningEngineView::exportToDot | ( | const std::string & | filename, |
| const fourdst::composition::Composition & | comp, | ||
| double | T9, | ||
| double | rho ) const |
Exports the network to a DOT file for visualization.
| filename | The name of the DOT file to create. |
| comp | Composition object |
| T9 | Temperature in units of 10^9 K. |
| rho | Density in g/cm^3. |
|
overridevirtual |
Generates the Jacobian matrix for the current state.
| comp | The current composition. |
| T9 | Temperature in units of 10^9 K. |
| rho | Density in g/cm^3. |
dydt=0 from calculateRHSAndEnergy).| exceptions::StaleEngineError | If the QSE cache misses, as it cannot proceed without a valid partition. |
Implements gridfire::DynamicEngine.
|
overridevirtual |
Generates the Jacobian matrix using a sparsity pattern.
| comp | The current composition. |
| T9 | Temperature in units of 10^9 K. |
| rho | Density in g/cm^3. |
| sparsityPattern | The sparsity pattern to use for the Jacobian. |
generateJacobianMatrix method with the provided sparsity pattern.| exceptions::StaleEngineError | If the QSE cache misses. |
Implements gridfire::DynamicEngine.
|
overridevirtual |
Generates the Jacobian matrix for a subset of active species.
| comp | The current composition. |
| T9 | Temperature in units of 10^9 K. |
| rho | Density in g/cm^3. |
| activeSpecies | The subset of species to include in the Jacobian. |
generateJacobianMatrix with the specified active species. The returned Jacobian still reflects the full network, but only for the active species subset.| exceptions::StaleEngineError | If the QSE cache misses. |
Implements gridfire::DynamicEngine.
|
overridevirtual |
Generates the stoichiometry matrix for the network.
generateStoichiometryMatrix(). The stoichiometry is based on the full, unpartitioned network. Implements gridfire::DynamicEngine.
|
overridevirtual |
Gets the base engine.
Implements gridfire::EngineView< DynamicEngine >.
|
nodiscard |
Gets the dynamic species in the network.
m_dynamic_species member vector.partitionNetwork() must have been called.
|
nodiscard |
Gets the fast species in the network.
m_algebraic_species member vector.partitionNetwork() must have been called.
|
nodiscardoverridevirtual |
Gets an entry from the previously generated Jacobian matrix.
| rowSpecies | Species corresponding to the row index (i_full). |
| colSpecies | Species corresponding to the column index (j_full). |
getJacobianMatrixEntry. It does not currently modify the Jacobian to reflect the QSE algebraic constraints, as these are handled by setting dY/dt = 0 in calculateRHSAndEnergy.generateJacobianMatrix() must have been called for the current state. Implements gridfire::DynamicEngine.
|
nodiscardoverridevirtual |
Gets the set of logical reactions in the network.
LogicalReactionSet from the base engine, containing all reactions in the full network. Implements gridfire::DynamicEngine.
|
nodiscardoverridevirtual |
Gets the list of species in the network.
Species objects representing all species in the underlying base engine. This view does not alter the species list itself, only how their abundances are evolved. Implements gridfire::Engine.
|
nodiscardoverridevirtual |
Gets the current electron screening model.
getScreeningModel(). Implements gridfire::DynamicEngine.
|
nodiscardoverridevirtual |
Computes destruction timescales for all species in the network.
| comp | The current composition. |
| T9 | Temperature in units of 10^9 K. |
| rho | Density in g/cm^3. |
std::expected containing a map from Species to their characteristic destruction timescales (s) on success, or a StaleEngineError on failure.| StaleEngineError | If the QSE cache misses. |
Implements gridfire::DynamicEngine.
|
nodiscardoverridevirtual |
Gets the index of a species in the full network.
| species | The species to get the index of. |
getSpeciesIndex(). Implements gridfire::DynamicEngine.
|
nodiscardoverridevirtual |
Computes timescales for all species in the network.
| comp | The current composition. |
| T9 | Temperature in units of 10^9 K. |
| rho | Density in g/cm^3. |
std::expected containing a map from Species to their characteristic timescales (s) on success, or a StaleEngineError on failure.Y / (dY/dt) for each species.| StaleEngineError | If the QSE cache misses. |
Implements gridfire::DynamicEngine.
|
nodiscardoverridevirtual |
Gets an entry from the stoichiometry matrix.
| species | Species to look up stoichiometry for. |
| reaction | Reaction to find. |
getStoichiometryMatrixEntry().generateStoichiometryMatrix() must have been called. Implements gridfire::DynamicEngine.
|
private |
Identifies the pool with the slowest mean timescale.
| pools | A vector of vectors of species indices, where each inner vector represents a timescale pool. |
| comp | Vector of current molar abundances for the full network. |
| T9 | Temperature in units of 10^9 K. |
| rho | Density in g/cm^3. |
| bool gridfire::MultiscalePartitioningEngineView::involvesSpecies | ( | const fourdst::atomic::Species & | species | ) | const |
| bool gridfire::MultiscalePartitioningEngineView::involvesSpeciesInDynamic | ( | const fourdst::atomic::Species & | species | ) | const |
| bool gridfire::MultiscalePartitioningEngineView::involvesSpeciesInQSE | ( | const fourdst::atomic::Species & | species | ) | const |
|
overridevirtual |
Checks if the engine's internal state is stale relative to the provided conditions.
| netIn | A struct containing the current network input. |
true if the engine is stale, false otherwise.update() needs to be called.QSECacheKey from the netIn data and checks for its existence in the m_qse_abundance_cache. A cache miss indicates the engine is stale because it does not have a valid QSE partition for the current conditions. It also queries the base engine's isStale() method. Implements gridfire::DynamicEngine.
|
nodiscardoverridevirtual |
Maps a NetIn struct to a molar abundance vector for the full network.
| netIn | A struct containing the current network input. |
mapNetInToMolarAbundanceVector(). Implements gridfire::DynamicEngine.
|
private |
Partitions the network by timescale.
| comp | Vector of current molar abundances for all species. |
| T9 | Temperature in units of 10^9 K. |
| rho | Density in g/cm^3. |
| void gridfire::MultiscalePartitioningEngineView::partitionNetwork | ( | const fourdst::composition::Composition & | comp, |
| double | T9, | ||
| double | rho ) |
Partitions the network into dynamic and algebraic (QSE) groups based on timescales.
| comp | Vector of current molar abundances for the full network. |
| T9 | Temperature in units of 10^9 K. |
| rho | Density in g/cm^3. |
@how
partitionByTimescale: Gets species destruction timescales from the base engine, sorts them, and looks for large gaps to create timescale "pools".identifyMeanSlowestPool: The pool with the slowest average timescale is designated as the core set of dynamic species.analyzeTimescalePoolConnectivity: The other (faster) pools are analyzed for reaction connectivity to form cohesive groups.constructCandidateGroups: These connected groups are processed to identify "seed" species (dynamic species that feed the group) and "algebraic" species (the rest).validateGroupsWithFluxAnalysis: The groups are validated by ensuring their internal reaction flux is much larger than the flux connecting them to the outside network.m_qse_groups, m_dynamic_species, and m_algebraic_species (and their index maps) are populated with the results of the partitioning. | void gridfire::MultiscalePartitioningEngineView::partitionNetwork | ( | const NetIn & | netIn | ) |
Partitions the network based on timescales from a NetIn struct.
| netIn | A struct containing the current network input. |
partitionNetwork.netIn struct into Y, T9, and rho and then calls the primary partitionNetwork method.
|
nodiscardoverridevirtual |
Primes the engine with a specific species.
| netIn | A struct containing the current network input. |
PrimingReport struct containing information about the priming process.primeEngine(). The multiscale view does not currently interact with the priming process. Implements gridfire::DynamicEngine.
|
overridevirtual |
Sets the set of logical reactions in the network.
| reactions | The set of logical reactions to use. |
MultiscalePartitioningEngineView as it would invalidate the partitioning logic. It logs a critical error and throws an exception. Network modifications should be done on the base engine before it is wrapped by this view.| exceptions::UnableToSetNetworkReactionsError | Always. |
Implements gridfire::DynamicEngine.
|
overridevirtual |
Sets the electron screening model.
| model | The type of screening model to use for reaction rate calculations. |
setScreeningModel(). Implements gridfire::DynamicEngine.
|
private |
Solves for the QSE abundances of the algebraic species in a given state.
| comp | Vector of current molar abundances for all species in the base engine. |
| T9 | Temperature in units of 10^9 K. |
| rho | Density in g/cm^3. |
LevenbergMarquardt class. The problem is defined by the EigenFunctor which computes the residuals and Jacobian for the QSE equations.
|
overridevirtual |
Updates the internal state of the engine, performing partitioning and QSE equilibration.
| netIn | A struct containing the current network input: temperature, density, and composition. |
@how
equilibrateNetwork().equilibrateNetwork() in turn calls partitionNetwork() to define the dynamic and algebraic species sets.solveQSEAbundances() to compute the equilibrium abundances.m_qse_abundance_cache.fourdst::composition::Composition object reflecting the equilibrated state is created and returned.netIn struct should contain a valid physical state. m_dynamic_species, m_algebraic_species, etc. are populated). The m_qse_abundance_cache is populated with the QSE solution for the given state. The returned composition reflects the new equilibrium. Implements gridfire::DynamicEngine.
|
private |
Validates candidate QSE groups using flux analysis.
| candidate_groups | A vector of candidate QSE groups. |
| comp | Vector of current molar abundances for the full network. |
| T9 | Temperature in units of 10^9 K. |
| rho | Density in g/cm^3. |
|
private |
Indices of all reactions involving only active species.
|
private |
Indices of all species considered active in the current partition (dynamic + algebraic).
|
private |
Map from species to their calculated abundances in the QSE state.
|
private |
Species that are treated as algebraic (in QSE) in the QSE groups.
|
private |
The base engine to which this view delegates calculations.
|
mutableprivate |
Statistics for the QSE abundance cache.
|
private |
The simplified set of species presented to the solver (the "slow" species).
|
private |
Logger instance for logging messages.
|
mutableprivate |
Cache for QSE abundances based on T9, rho, and Y.
QSECacheKey which hashes the thermodynamic state, and the value is the vector of solved molar abundances for the algebraic species.
|
private |
The list of identified equilibrium groups.