|
GridFire v0.7.6rc4.0
General Purpose Nuclear Network
|
An engine view that dynamically adapts the reaction network based on runtime conditions. More...
#include <engine_adaptive.h>
Classes | |
| struct | ReactionFlow |
| A struct to hold a reaction and its flow rate. More... | |
Public Member Functions | |
| AdaptiveEngineView (DynamicEngine &baseEngine) | |
| Constructs an AdaptiveEngineView. | |
| fourdst::composition::Composition | project (scratch::StateBlob &ctx, const NetIn &netIn) const override |
| Updates the active species and reactions based on the current conditions. | |
| const std::vector< fourdst::atomic::Species > & | getNetworkSpecies (scratch::StateBlob &ctx) const override |
| Gets the list of active species in the network. | |
| std::expected< StepDerivatives< double >, EngineStatus > | calculateRHSAndEnergy (scratch::StateBlob &ctx, const fourdst::composition::CompositionAbstract &comp, double T9, double rho, bool trust) const override |
| Calculates the right-hand side (dY/dt) and energy generation for the active species. | |
| EnergyDerivatives | calculateEpsDerivatives (scratch::StateBlob &ctx, const fourdst::composition::CompositionAbstract &comp, double T9, double rho) const override |
| NetworkJacobian | generateJacobianMatrix (scratch::StateBlob &ctx, const fourdst::composition::CompositionAbstract &comp, double T9, double rho) const override |
| Generates the Jacobian matrix for the active species. | |
| NetworkJacobian | generateJacobianMatrix (scratch::StateBlob &ctx, const fourdst::composition::CompositionAbstract &comp, double T9, double rho, const std::vector< fourdst::atomic::Species > &activeSpecies) const override |
| Generates the Jacobian matrix for some set of active species such that that set is a subset of the active species in the view. | |
| NetworkJacobian | generateJacobianMatrix (scratch::StateBlob &ctx, const fourdst::composition::CompositionAbstract &comp, double T9, double rho, const SparsityPattern &sparsityPattern) const override |
| Generates the Jacobian matrix for the active species with a given sparsity pattern. | |
| double | calculateMolarReactionFlow (scratch::StateBlob &ctx, const reaction::Reaction &reaction, const fourdst::composition::CompositionAbstract &comp, double T9, double rho) const override |
| Calculates the molar reaction flow for a given reaction in the active network. | |
| const reaction::ReactionSet & | getNetworkReactions (scratch::StateBlob &ctx) const override |
| Gets the set of active logical reactions in the network. | |
| reaction::ReactionSet | getInactiveNetworkReactions (scratch::StateBlob &ctx) const override |
| Gets the set of inactive logical reactions in the network. | |
| double | getInactiveReactionMolarReactionFlow (scratch::StateBlob &ctx, const reaction::Reaction &reaction, const fourdst::composition::CompositionAbstract &comp, double T9, double rho) const override |
| std::expected< std::unordered_map< fourdst::atomic::Species, double >, EngineStatus > | getSpeciesTimescales (scratch::StateBlob &ctx, const fourdst::composition::CompositionAbstract &comp, double T9, double rho) const override |
| Computes timescales for all active species in the network. | |
| std::expected< std::unordered_map< fourdst::atomic::Species, double >, EngineStatus > | getSpeciesDestructionTimescales (scratch::StateBlob &ctx, const fourdst::composition::CompositionAbstract &comp, double T9, double rho) const override |
| Computes destruction timescales for all active species in the network. | |
| const DynamicEngine & | getBaseEngine () const override |
| Gets the base engine. | |
| screening::ScreeningType | getScreeningModel (scratch::StateBlob &ctx) const override |
| Gets the screening model from the base engine. | |
| size_t | getSpeciesIndex (scratch::StateBlob &ctx, const fourdst::atomic::Species &species) const override |
| Gets the index of a species in the active species list. | |
| PrimingReport | primeEngine (scratch::StateBlob &ctx, const NetIn &netIn) const override |
| Primes the engine with the given network input. | |
| fourdst::composition::Composition | collectComposition (scratch::StateBlob &ctx, const fourdst::composition::CompositionAbstract &comp, double T9, double rho) const override |
| Collect the composition of the base engine, ensure all active species are registered, and pass the composition back to the caller. | |
| SpeciesStatus | getSpeciesStatus (scratch::StateBlob &ctx, const fourdst::atomic::Species &species) const override |
| Gets the status of a species in the network. | |
| std::optional< StepDerivatives< double > > | getMostRecentRHSCalculation (scratch::StateBlob &ctx) const override |
| std::unique_ptr< scratch::StateBlob > | constructStateBlob (const scratch::StateBlob *blob) const override |
Public Member Functions inherited from gridfire::engine::Engine | |
| virtual | ~Engine ()=default |
| Virtual destructor. | |
Public Member Functions inherited from gridfire::engine::EngineView< DynamicEngine > | |
| virtual | ~EngineView ()=default |
| Virtual destructor. | |
Private Types | |
| using | LogManager = fourdst::logging::LogManager |
| typedef std::pair< std::unordered_set< const reaction::Reaction * >, std::unordered_set< fourdst::atomic::Species > > | RescueSet |
Private Member Functions | |
| std::pair< std::vector< ReactionFlow >, fourdst::composition::Composition > | calculateAllReactionFlows (scratch::StateBlob &ctx, const NetIn &netIn) const |
| Calculates the molar reaction flow rate for all reactions in the full network. | |
| std::unordered_set< fourdst::atomic::Species > | findReachableSpecies (scratch::StateBlob &ctx, const NetIn &netIn) const |
| Finds all species that are reachable from the initial fuel through the reaction network. | |
| std::vector< const reaction::Reaction * > | cullReactionsByFlow (scratch::StateBlob &ctx, const std::vector< ReactionFlow > &allFlows, const std::unordered_set< fourdst::atomic::Species > &reachableSpecies, const fourdst::composition::Composition &comp, double maxFlow) const |
| Culls reactions from the network based on their flow rates. | |
| RescueSet | rescueEdgeSpeciesDestructionChannel (scratch::StateBlob &ctx, const fourdst::composition::Composition &comp, double T9, double rho) const |
| void | finalizeActiveSet (scratch::StateBlob &ctx, const std::vector< const reaction::Reaction * > &finalReactions) const |
| Finalizes the set of active species and reactions. | |
Private Attributes | |
| fourdst::config::Config< config::GridFireConfig > | m_config |
| quill::Logger * | m_logger = LogManager::getInstance().getLogger("log") |
| A pointer to the logger instance, used for logging messages. | |
| DynamicEngine & | m_baseEngine |
| The underlying engine to which this view delegates calculations. | |
An engine view that dynamically adapts the reaction network based on runtime conditions.
This class implements an EngineView that dynamically culls species and reactions from the full reaction network based on their reaction flow rates and connectivity. This allows for efficient simulation of reaction networks by focusing computational effort on the most important species and reactions.
The AdaptiveEngineView maintains a subset of "active" species and reactions, and maps between the full network indices and the active subset indices. This allows the base engine to operate on the full network data, while the AdaptiveEngineView provides a reduced view for external clients.
The adaptation process is driven by the update() method, which performs the following steps:
<DynamicEngine>
|
private |
|
private |
|
explicit |
Constructs an AdaptiveEngineView.
| baseEngine | The underlying DynamicEngine to which this view delegates calculations. |
Initializes the active species and reactions to the full network, and constructs the initial index maps.
|
nodiscardprivate |
Calculates the molar reaction flow rate for all reactions in the full network.
This method iterates through all reactions in the base engine's network and calculates their molar flow rates based on the provided network input conditions (temperature, density, and composition). It also constructs a vector of molar abundances for all species in the full network.
| ctx | The scratchpad context for storing thread-local data. |
| netIn | The current network input, containing temperature, density, and composition. |
netIn.composition. If the species is not found, its abundance is set to 0.0.calculateMolarReactionFlow to get the flow rate.ReactionFlow struct and adds it to the returned vector.
|
nodiscardoverridevirtual |
| ctx | The scratchpad context for storing thread-local data. |
| comp | The current composition of the system. |
| T9 | The temperature in units of 10^9 K. |
| rho | The density in g/cm^3. |
Implements gridfire::engine::DynamicEngine.
|
nodiscardoverridevirtual |
Calculates the molar reaction flow for a given reaction in the active network.
| ctx | The scratchpad context for storing thread-local data. |
| reaction | The reaction for which to calculate the flow. |
| comp | Composition object containing current abundances. |
| T9 | Temperature in units of 10^9 K. |
| rho | Density in g/cm^3. |
This method maps the culled abundances to the full network abundances and calls the base engine to calculate the molar reaction flow.
| std::runtime_error | If the AdaptiveEngineView is stale (i.e., update() has not been called). |
| std::runtime_error | If the reaction is not part of the active reactions in the adaptive engine view. |
Implements gridfire::engine::DynamicEngine.
|
nodiscardoverridevirtual |
Calculates the right-hand side (dY/dt) and energy generation for the active species.
| ctx | The scratchpad context for storing thread-local data. |
| comp | The current composition of the system. |
| T9 | The temperature in units of 10^9 K. |
| rho | The density in g/cm^3. |
| trust |
This method maps the culled abundances to the full network abundances, calls the base engine to calculate the RHS and energy generation, and then maps the full network derivatives back to the culled derivatives.
| std::runtime_error | If the AdaptiveEngineView is stale (i.e., update() has not been called). |
Implements gridfire::engine::Engine.
|
nodiscardoverridevirtual |
Collect the composition of the base engine, ensure all active species are registered, and pass the composition back to the caller.
| ctx | The scratchpad context for storing thread-local data. |
| comp | The current composition of the system. |
| T9 | The temperature in units of 10^9 K. |
| rho | The density in g/cm^3. |
Implements gridfire::engine::DynamicEngine.
|
nodiscardoverridevirtual |
Implements gridfire::engine::DynamicEngine.
|
nodiscardprivate |
Culls reactions from the network based on their flow rates.
This method filters the list of all reactions, keeping only those with a flow rate above an absolute culling threshold. The threshold is calculated by multiplying the maximum flow rate by a relative culling threshold read from the configuration.
| ctx | The scratchpad context for storing thread-local data. |
| allFlows | A vector of all reactions and their flow rates. |
| reachableSpecies | A set of all species reachable from the initial fuel. |
| comp | The current composition of the system. |
| maxFlow | The maximum reaction flow rate in the network. |
RelativeCullingThreshold from the configuration.absoluteCullingThreshold by multiplying maxFlow with the relative threshold.allFlows.flowRate is greater than the absoluteCullingThreshold.
|
private |
Finalizes the set of active species and reactions.
This method takes the final list of culled reactions and populates the m_activeReactions and m_activeSpecies members. The active species are determined by collecting all reactants and products from the final reactions. The active species list is then sorted by mass.
| ctx | The scratchpad context for storing thread-local data. |
| finalReactions | A vector of pointers to the reactions to be included in the active set. |
m_activeReactions is cleared and populated with the reactions from finalReactions.m_activeSpecies is cleared and populated with all unique species present in finalReactions.m_activeSpecies is sorted by atomic mass.
|
nodiscardprivate |
Finds all species that are reachable from the initial fuel through the reaction network.
This method performs a connectivity analysis to identify all species that can be produced starting from the initial fuel species. A species is considered part of the initial fuel if its mass fraction is above a certain threshold (ABUNDANCE_FLOOR).
| ctx | The scratchpad context for storing thread-local data. |
| netIn | The current network input, containing the initial composition. |
reachable and a queue to_visit with the initial fuel species.reachable set, all products of that reaction are added to the reachable set.reachable set.
|
nodiscardoverridevirtual |
Generates the Jacobian matrix for the active species.
| ctx | The scratchpad context for storing thread-local data. |
| comp | The current composition of the system. |
| T9 | The temperature in units of 10^9 K. |
| rho | The density in g/cm^3. |
This method maps the culled abundances to the full network abundances and calls the base engine to generate the Jacobian matrix.
| std::runtime_error | If the AdaptiveEngineView is stale (i.e., update() has not been called). |
Implements gridfire::engine::DynamicEngine.
|
nodiscardoverridevirtual |
Generates the Jacobian matrix for the active species with a given sparsity pattern.
| ctx | The scratchpad context for storing thread-local data. |
| comp | The current composition of the system. |
| T9 | The temperature in units of 10^9 K. |
| rho | The density in g/cm^3. |
| sparsityPattern | The sparsity pattern to use for the Jacobian matrix. |
This method maps the culled abundances to the full network abundances and calls the base engine to generate the Jacobian matrix.
| std::runtime_error | If the AdaptiveEngineView is stale (i.e., update() has not been called). |
Implements gridfire::engine::DynamicEngine.
|
nodiscardoverridevirtual |
Generates the Jacobian matrix for some set of active species such that that set is a subset of the active species in the view.
| ctx | The scratchpad context for storing thread-local data. |
| comp | The current composition of the system. |
| T9 | The temperature in units of 10^9 K. |
| rho | The density in g/cm^3. |
| activeSpecies | The list of active species for which to generate the Jacobian. |
This method maps the culled abundances to the full network abundances and calls the base engine to generate the Jacobian matrix.
| std::runtime_error | If the AdaptiveEngineView is stale (i.e., update() has not been called). |
Implements gridfire::engine::DynamicEngine.
|
inlinenodiscardoverridevirtual |
Gets the base engine.
Implements gridfire::engine::EngineView< DynamicEngine >.
|
nodiscardoverridevirtual |
Gets the set of inactive logical reactions in the network.
This method returns the set of reactions that have been culled from the active network based on the adaptation criteria.
Reimplemented from gridfire::engine::DynamicEngine.
|
nodiscardoverridevirtual |
Reimplemented from gridfire::engine::DynamicEngine.
|
nodiscardoverridevirtual |
Implements gridfire::engine::DynamicEngine.
|
nodiscardoverridevirtual |
Gets the set of active logical reactions in the network.
Implements gridfire::engine::DynamicEngine.
|
nodiscardoverridevirtual |
Gets the list of active species in the network.
Implements gridfire::engine::Engine.
|
nodiscardoverridevirtual |
Gets the screening model from the base engine.
This method delegates the call to the base engine to get the screening model.
Implements gridfire::engine::DynamicEngine.
|
nodiscardoverridevirtual |
Computes destruction timescales for all active species in the network.
| ctx | The scratchpad context for storing thread-local data. |
| comp | Composition object containing current abundances. |
| T9 | Temperature in units of 10^9 K. |
| rho | Density in g/cm^3. |
This method maps the culled abundances to the full network abundances and calls the base engine to compute the species destruction timescales.
| std::runtime_error | If the AdaptiveEngineView is stale (i.e., update() has not been called). |
Implements gridfire::engine::DynamicEngine.
|
nodiscardoverridevirtual |
Gets the index of a species in the active species list.
| ctx | The scratchpad context for storing thread-local data. |
| species | The species for which to get the index. |
| std::runtime_error | If the AdaptiveEngineView is stale (i.e., update() has not been called). |
| std::out_of_range | If the species is not part of the active species in the adaptive engine view. |
Implements gridfire::engine::DynamicEngine.
|
nodiscardoverridevirtual |
Gets the status of a species in the network.
| ctx | The scratchpad context for storing thread-local data. |
| species | The species for which to get the status. |
This method delegates the call to the base engine to get the species status. If the base engine says that the species is active, but it is not in the active species list of this view, the status is returned as INACTIVE_FLOW.
Implements gridfire::engine::DynamicEngine.
|
nodiscardoverridevirtual |
Computes timescales for all active species in the network.
| ctx | The scratchpad context for storing thread-local data. |
| comp | Composition object containing current abundances. |
| T9 | Temperature in units of 10^9 K. |
| rho | Density in g/cm^3. |
This method maps the culled abundances to the full network abundances and calls the base engine to compute the species timescales.
| std::runtime_error | If the AdaptiveEngineView is stale (i.e., update() has not been called). |
Implements gridfire::engine::DynamicEngine.
|
nodiscardoverridevirtual |
Primes the engine with the given network input.
| ctx | The scratchpad context for storing thread-local data. |
| netIn | The current network input, containing temperature, density, and composition. |
This method delegates the priming operation to the base engine.
Implements gridfire::engine::DynamicEngine.
|
overridevirtual |
Updates the active species and reactions based on the current conditions.
| ctx | The scratchpad context for storing thread-local data. |
| netIn | The current network input, containing temperature, density, and composition. |
This method performs the reaction flow calculation, reaction culling, connectivity analysis, and index map construction steps described above.
The culling thresholds are read from the configuration using the following keys:
gridfire:AdaptiveEngineView:RelativeCullingThreshold (default: 1e-75)| std::runtime_error | If there is a mismatch between the active reactions and the base engine. |
Implements gridfire::engine::DynamicEngine.
|
nodiscardprivate |
|
private |
The underlying engine to which this view delegates calculations.
|
private |
|
private |
A pointer to the logger instance, used for logging messages.