GridFire 0.0.1a
General Purpose Nuclear Network
Loading...
Searching...
No Matches
gridfire::AdaptiveEngineView Class Referencefinal

An engine view that dynamically adapts the reaction network based on runtime conditions. More...

#include <engine_adaptive.h>

Inheritance diagram for gridfire::AdaptiveEngineView:
gridfire::DynamicEngine gridfire::EngineView< DynamicEngine > gridfire::Engine

Classes

struct  ReactionFlow
 A struct to hold a reaction and its flow rate. More...
 

Public Member Functions

 AdaptiveEngineView (DynamicEngine &baseEngine)
 Constructs an AdaptiveEngineView.
 
void update (const NetIn &netIn) override
 Updates the active species and reactions based on the current conditions.
 
const std::vector< fourdst::atomic::Species > & getNetworkSpecies () const override
 Gets the list of active species in the network.
 
StepDerivatives< double > calculateRHSAndEnergy (const std::vector< double > &Y_culled, const double T9, const double rho) const override
 Calculates the right-hand side (dY/dt) and energy generation for the active species.
 
void generateJacobianMatrix (const std::vector< double > &Y_culled, const double T9, const double rho) override
 Generates the Jacobian matrix for the active species.
 
double getJacobianMatrixEntry (const int i_culled, const int j_culled) const override
 Gets an entry from the Jacobian matrix for the active species.
 
void generateStoichiometryMatrix () override
 Generates the stoichiometry matrix for the active reactions and species.
 
int getStoichiometryMatrixEntry (const int speciesIndex_culled, const int reactionIndex_culled) const override
 Gets an entry from the stoichiometry matrix for the active species and reactions.
 
double calculateMolarReactionFlow (const reaction::Reaction &reaction, const std::vector< double > &Y_culled, double T9, double rho) const override
 Calculates the molar reaction flow for a given reaction in the active network.
 
const reaction::LogicalReactionSetgetNetworkReactions () const override
 Gets the set of active logical reactions in the network.
 
std::unordered_map< fourdst::atomic::Species, double > getSpeciesTimescales (const std::vector< double > &Y_culled, double T9, double rho) const override
 Computes timescales for all active species in the network.
 
const DynamicEnginegetBaseEngine () const override
 Gets the base engine.
 
void setScreeningModel (screening::ScreeningType model) override
 
screening::ScreeningType getScreeningModel () const override
 
- 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

using Config = fourdst::config::Config
 
using LogManager = fourdst::logging::LogManager
 

Private Member Functions

std::vector< size_t > constructSpeciesIndexMap () const
 Constructs the species index map.
 
std::vector< size_t > constructReactionIndexMap () const
 Constructs the reaction index map.
 
std::vector< double > mapCulledToFull (const std::vector< double > &culled) const
 Maps a vector of culled abundances to a vector of full abundances.
 
std::vector< double > mapFullToCulled (const std::vector< double > &full) const
 Maps a vector of full abundances to a vector of culled abundances.
 
size_t mapCulledToFullSpeciesIndex (size_t culledSpeciesIndex) const
 Maps a culled species index to a full species index.
 
size_t mapCulledToFullReactionIndex (size_t culledReactionIndex) const
 Maps a culled reaction index to a full reaction index.
 
void validateState () const
 Validates that the AdaptiveEngineView is not stale.
 
std::vector< ReactionFlowcalculateAllReactionFlows (const NetIn &netIn, std::vector< double > &out_Y_Full) const
 
std::unordered_set< fourdst::atomic::Species > findReachableSpecies (const NetIn &netIn) const
 
std::vector< const reaction::LogicalReaction * > cullReactionsByFlow (const std::vector< ReactionFlow > &allFlows, const std::unordered_set< fourdst::atomic::Species > &reachableSpecies, const std::vector< double > &Y_full, double maxFlow) const
 
void finalizeActiveSet (const std::vector< const reaction::LogicalReaction * > &finalReactions)
 

Private Attributes

Configm_config = Config::getInstance()
 
quill::Logger * m_logger = LogManager::getInstance().getLogger("log")
 
DynamicEnginem_baseEngine
 
std::vector< fourdst::atomic::Species > m_activeSpecies
 
reaction::LogicalReactionSet m_activeReactions
 
std::vector< size_t > m_speciesIndexMap
 
std::vector< size_t > m_reactionIndexMap
 
bool m_isStale = true
 

Detailed Description

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:

  1. Reaction Flow Calculation: Calculates the molar reaction flow rate for each reaction in the full network based on the current temperature, density, and composition.
  2. Reaction Culling: Culls reactions with flow rates below a threshold, determined by a relative culling threshold multiplied by the maximum flow rate.
  3. Connectivity Analysis: Performs a connectivity analysis to identify species that are reachable from the initial fuel species through the culled reaction network.
  4. Species Culling: Culls species that are not reachable from the initial fuel.
  5. Index Map Construction: Constructs index maps to map between the full network indices and the active subset indices for species and reactions.

<DynamicEngine>

See also
engine_abstract.h
engine_view_abstract.h
AdaptiveEngineView::update()

Definition at line 47 of file engine_adaptive.h.

Member Typedef Documentation

◆ Config

using gridfire::AdaptiveEngineView::Config = fourdst::config::Config
private

Definition at line 232 of file engine_adaptive.h.

◆ LogManager

using gridfire::AdaptiveEngineView::LogManager = fourdst::logging::LogManager
private

Definition at line 233 of file engine_adaptive.h.

Constructor & Destructor Documentation

◆ AdaptiveEngineView()

gridfire::AdaptiveEngineView::AdaptiveEngineView ( DynamicEngine & baseEngine)
explicit

Constructs an AdaptiveEngineView.

Parameters
baseEngineThe underlying DynamicEngine to which this view delegates calculations.

Initializes the active species and reactions to the full network, and constructs the initial index maps.

Definition at line 13 of file engine_adaptive.cpp.

Member Function Documentation

◆ calculateAllReactionFlows()

std::vector< AdaptiveEngineView::ReactionFlow > gridfire::AdaptiveEngineView::calculateAllReactionFlows ( const NetIn & netIn,
std::vector< double > & out_Y_Full ) const
private

Definition at line 268 of file engine_adaptive.cpp.

◆ calculateMolarReactionFlow()

double gridfire::AdaptiveEngineView::calculateMolarReactionFlow ( const reaction::Reaction & reaction,
const std::vector< double > & Y_culled,
double T9,
double rho ) const
nodiscardoverridevirtual

Calculates the molar reaction flow for a given reaction in the active network.

Parameters
reactionThe reaction for which to calculate the flow.
Y_culledVector of current abundances for the active species.
T9Temperature in units of 10^9 K.
rhoDensity in g/cm^3.
Returns
Molar flow rate for the reaction (e.g., mol/g/s).

This method maps the culled abundances to the full network abundances and calls the base engine to calculate the molar reaction flow.

Exceptions
std::runtime_errorIf the AdaptiveEngineView is stale (i.e., update() has not been called).
std::runtime_errorIf the reaction is not part of the active reactions in the adaptive engine view.

Implements gridfire::DynamicEngine.

Definition at line 175 of file engine_adaptive.cpp.

◆ calculateRHSAndEnergy()

StepDerivatives< double > gridfire::AdaptiveEngineView::calculateRHSAndEnergy ( const std::vector< double > & Y_culled,
const double T9,
const double rho ) const
nodiscardoverridevirtual

Calculates the right-hand side (dY/dt) and energy generation for the active species.

Parameters
Y_culledA vector of abundances for the active species.
T9The temperature in units of 10^9 K.
rhoThe density in g/cm^3.
Returns
A StepDerivatives struct containing the derivatives of the active species and the nuclear energy generation rate.

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.

Exceptions
std::runtime_errorIf the AdaptiveEngineView is stale (i.e., update() has not been called).
See also
AdaptiveEngineView::update()

Implements gridfire::Engine.

Definition at line 120 of file engine_adaptive.cpp.

◆ constructReactionIndexMap()

std::vector< size_t > gridfire::AdaptiveEngineView::constructReactionIndexMap ( ) const
nodiscardprivate

Constructs the reaction index map.

Returns
A vector mapping culled reaction indices to full reaction indices.

This method creates a map from the indices of the active reactions to the indices of the corresponding reactions in the full network.

See also
AdaptiveEngineView::update()

Definition at line 53 of file engine_adaptive.cpp.

◆ constructSpeciesIndexMap()

std::vector< size_t > gridfire::AdaptiveEngineView::constructSpeciesIndexMap ( ) const
nodiscardprivate

Constructs the species index map.

Returns
A vector mapping culled species indices to full species indices.

This method creates a map from the indices of the active species to the indices of the corresponding species in the full network.

See also
AdaptiveEngineView::update()

Definition at line 24 of file engine_adaptive.cpp.

◆ cullReactionsByFlow()

std::vector< const reaction::LogicalReaction * > gridfire::AdaptiveEngineView::cullReactionsByFlow ( const std::vector< ReactionFlow > & allFlows,
const std::unordered_set< fourdst::atomic::Species > & reachableSpecies,
const std::vector< double > & Y_full,
double maxFlow ) const
nodiscardprivate

Definition at line 342 of file engine_adaptive.cpp.

◆ finalizeActiveSet()

void gridfire::AdaptiveEngineView::finalizeActiveSet ( const std::vector< const reaction::LogicalReaction * > & finalReactions)
private

Definition at line 385 of file engine_adaptive.cpp.

◆ findReachableSpecies()

std::unordered_set< Species > gridfire::AdaptiveEngineView::findReachableSpecies ( const NetIn & netIn) const
nodiscardprivate

Definition at line 299 of file engine_adaptive.cpp.

◆ generateJacobianMatrix()

void gridfire::AdaptiveEngineView::generateJacobianMatrix ( const std::vector< double > & Y_culled,
const double T9,
const double rho )
overridevirtual

Generates the Jacobian matrix for the active species.

Parameters
Y_culledA vector of abundances for the active species.
T9The temperature in units of 10^9 K.
rhoThe 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.

Exceptions
std::runtime_errorIf the AdaptiveEngineView is stale (i.e., update() has not been called).
See also
AdaptiveEngineView::update()

Implements gridfire::DynamicEngine.

Definition at line 138 of file engine_adaptive.cpp.

◆ generateStoichiometryMatrix()

void gridfire::AdaptiveEngineView::generateStoichiometryMatrix ( )
overridevirtual

Generates the stoichiometry matrix for the active reactions and species.

This method calls the base engine to generate the stoichiometry matrix.

Exceptions
std::runtime_errorIf the AdaptiveEngineView is stale (i.e., update() has not been called).
Note
The stoichiometry matrix generated by the base engine is assumed to be consistent with the active species and reactions in this view.

Implements gridfire::DynamicEngine.

Definition at line 160 of file engine_adaptive.cpp.

◆ getBaseEngine()

const DynamicEngine & gridfire::AdaptiveEngineView::getBaseEngine ( ) const
inlinenodiscardoverridevirtual

Gets the base engine.

Returns
A const reference to the base engine.

Implements gridfire::EngineView< DynamicEngine >.

Definition at line 226 of file engine_adaptive.h.

◆ getJacobianMatrixEntry()

double gridfire::AdaptiveEngineView::getJacobianMatrixEntry ( const int i_culled,
const int j_culled ) const
nodiscardoverridevirtual

Gets an entry from the Jacobian matrix for the active species.

Parameters
i_culledThe row index (species index) in the culled matrix.
j_culledThe column index (species index) in the culled matrix.
Returns
The value of the Jacobian matrix at (i_culled, j_culled).

This method maps the culled indices to the full network indices and calls the base engine to get the Jacobian matrix entry.

Exceptions
std::runtime_errorIf the AdaptiveEngineView is stale (i.e., update() has not been called).
std::out_of_rangeIf the culled index is out of bounds for the species index map.
See also
AdaptiveEngineView::update()

Implements gridfire::DynamicEngine.

Definition at line 149 of file engine_adaptive.cpp.

◆ getNetworkReactions()

const reaction::LogicalReactionSet & gridfire::AdaptiveEngineView::getNetworkReactions ( ) const
nodiscardoverridevirtual

Gets the set of active logical reactions in the network.

Returns
Reference to the LogicalReactionSet containing all active reactions.

Implements gridfire::DynamicEngine.

Definition at line 192 of file engine_adaptive.cpp.

◆ getNetworkSpecies()

const std::vector< Species > & gridfire::AdaptiveEngineView::getNetworkSpecies ( ) const
nodiscardoverridevirtual

Gets the list of active species in the network.

Returns
A const reference to the vector of active species.

Implements gridfire::Engine.

Definition at line 116 of file engine_adaptive.cpp.

◆ getScreeningModel()

screening::ScreeningType gridfire::AdaptiveEngineView::getScreeningModel ( ) const
nodiscardoverridevirtual

Implements gridfire::DynamicEngine.

Definition at line 220 of file engine_adaptive.cpp.

◆ getSpeciesTimescales()

std::unordered_map< Species, double > gridfire::AdaptiveEngineView::getSpeciesTimescales ( const std::vector< double > & Y_culled,
double T9,
double rho ) const
nodiscardoverridevirtual

Computes timescales for all active species in the network.

Parameters
Y_culledVector of current abundances for the active species.
T9Temperature in units of 10^9 K.
rhoDensity in g/cm^3.
Returns
Map from Species to their characteristic timescales (s).

This method maps the culled abundances to the full network abundances and calls the base engine to compute the species timescales.

Exceptions
std::runtime_errorIf the AdaptiveEngineView is stale (i.e., update() has not been called).

Implements gridfire::DynamicEngine.

Definition at line 196 of file engine_adaptive.cpp.

◆ getStoichiometryMatrixEntry()

int gridfire::AdaptiveEngineView::getStoichiometryMatrixEntry ( const int speciesIndex_culled,
const int reactionIndex_culled ) const
nodiscardoverridevirtual

Gets an entry from the stoichiometry matrix for the active species and reactions.

Parameters
speciesIndex_culledThe index of the species in the culled species list.
reactionIndex_culledThe index of the reaction in the culled reaction list.
Returns
The stoichiometric coefficient for the given species and reaction.

This method maps the culled indices to the full network indices and calls the base engine to get the stoichiometry matrix entry.

Exceptions
std::runtime_errorIf the AdaptiveEngineView is stale (i.e., update() has not been called).
std::out_of_rangeIf the culled index is out of bounds for the species or reaction index map.
See also
AdaptiveEngineView::update()

Implements gridfire::DynamicEngine.

Definition at line 165 of file engine_adaptive.cpp.

◆ mapCulledToFull()

std::vector< double > gridfire::AdaptiveEngineView::mapCulledToFull ( const std::vector< double > & culled) const
nodiscardprivate

Maps a vector of culled abundances to a vector of full abundances.

Parameters
culledA vector of abundances for the active species.
Returns
A vector of abundances for the full network, with the abundances of the active species copied from the culled vector.

Definition at line 224 of file engine_adaptive.cpp.

◆ mapCulledToFullReactionIndex()

size_t gridfire::AdaptiveEngineView::mapCulledToFullReactionIndex ( size_t culledReactionIndex) const
nodiscardprivate

Maps a culled reaction index to a full reaction index.

Parameters
culledReactionIndexThe index of the reaction in the culled reaction list.
Returns
The index of the corresponding reaction in the full network.
Exceptions
std::out_of_rangeIf the culled index is out of bounds for the reaction index map.

Definition at line 251 of file engine_adaptive.cpp.

◆ mapCulledToFullSpeciesIndex()

size_t gridfire::AdaptiveEngineView::mapCulledToFullSpeciesIndex ( size_t culledSpeciesIndex) const
nodiscardprivate

Maps a culled species index to a full species index.

Parameters
culledSpeciesIndexThe index of the species in the culled species list.
Returns
The index of the corresponding species in the full network.
Exceptions
std::out_of_rangeIf the culled index is out of bounds for the species index map.

Definition at line 242 of file engine_adaptive.cpp.

◆ mapFullToCulled()

std::vector< double > gridfire::AdaptiveEngineView::mapFullToCulled ( const std::vector< double > & full) const
nodiscardprivate

Maps a vector of full abundances to a vector of culled abundances.

Parameters
fullA vector of abundances for the full network.
Returns
A vector of abundances for the active species, with the abundances of the active species copied from the full vector.

Definition at line 233 of file engine_adaptive.cpp.

◆ setScreeningModel()

void gridfire::AdaptiveEngineView::setScreeningModel ( screening::ScreeningType model)
overridevirtual

Implements gridfire::DynamicEngine.

Definition at line 216 of file engine_adaptive.cpp.

◆ update()

void gridfire::AdaptiveEngineView::update ( const NetIn & netIn)
overridevirtual

Updates the active species and reactions based on the current conditions.

Parameters
netInThe 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)
Exceptions
std::runtime_errorIf there is a mismatch between the active reactions and the base engine.
Postcondition
The active species and reactions are updated, and the index maps are reconstructed.
See also
AdaptiveEngineView
AdaptiveEngineView::constructSpeciesIndexMap()
AdaptiveEngineView::constructReactionIndexMap()

Implements gridfire::DynamicEngine.

Definition at line 85 of file engine_adaptive.cpp.

◆ validateState()

void gridfire::AdaptiveEngineView::validateState ( ) const
private

Validates that the AdaptiveEngineView is not stale.

Exceptions
std::runtime_errorIf the AdaptiveEngineView is stale (i.e., update() has not been called).

Definition at line 260 of file engine_adaptive.cpp.

Member Data Documentation

◆ m_activeReactions

reaction::LogicalReactionSet gridfire::AdaptiveEngineView::m_activeReactions
private

Definition at line 240 of file engine_adaptive.h.

◆ m_activeSpecies

std::vector<fourdst::atomic::Species> gridfire::AdaptiveEngineView::m_activeSpecies
private

Definition at line 239 of file engine_adaptive.h.

◆ m_baseEngine

DynamicEngine& gridfire::AdaptiveEngineView::m_baseEngine
private

Definition at line 237 of file engine_adaptive.h.

◆ m_config

Config& gridfire::AdaptiveEngineView::m_config = Config::getInstance()
private

Definition at line 234 of file engine_adaptive.h.

◆ m_isStale

bool gridfire::AdaptiveEngineView::m_isStale = true
private

Definition at line 245 of file engine_adaptive.h.

◆ m_logger

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

Definition at line 235 of file engine_adaptive.h.

◆ m_reactionIndexMap

std::vector<size_t> gridfire::AdaptiveEngineView::m_reactionIndexMap
private

Definition at line 243 of file engine_adaptive.h.

◆ m_speciesIndexMap

std::vector<size_t> gridfire::AdaptiveEngineView::m_speciesIndexMap
private

Definition at line 242 of file engine_adaptive.h.


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