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

An engine view that uses a user-defined reaction network from a file. More...

#include <engine_defined.h>

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

Public Member Functions

 FileDefinedEngineView (DynamicEngine &baseEngine, const std::string &fileName, const io::NetworkFileParser &parser)
 Constructs a FileDefinedEngineView.
 
const DynamicEnginegetBaseEngine () const override
 Gets the base engine.
 
const std::vector< fourdst::atomic::Species > & getNetworkSpecies () const override
 Gets the list of active species in the network defined by the file.
 
StepDerivatives< double > calculateRHSAndEnergy (const std::vector< double > &Y_defined, 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_defined, const double T9, const double rho) override
 Generates the Jacobian matrix for the active species.
 
double getJacobianMatrixEntry (const int i_defined, const int j_defined) 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_defined, const int reactionIndex_defined) 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_defined, const double T9, const 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_defined, const double T9, const double rho) const override
 Computes timescales for all active species in the network.
 
void update (const NetIn &netIn) override
 Updates the engine view if it is marked as stale.
 
void setNetworkFile (const std::string &fileName)
 Sets a new network file to define the active reactions.
 
void setScreeningModel (screening::ScreeningType model) override
 Sets the screening model for the base engine.
 
screening::ScreeningType getScreeningModel () const override
 Gets the screening model from the base engine.
 
- 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

void buildFromFile (const std::string &fileName)
 Builds the active species and reaction sets from a file.
 
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 > mapViewToFull (const std::vector< double > &defined) const
 Maps a vector of culled abundances to a vector of full abundances.
 
std::vector< double > mapFullToView (const std::vector< double > &full) const
 Maps a vector of full abundances to a vector of culled abundances.
 
size_t mapViewToFullSpeciesIndex (size_t definedSpeciesIndex) const
 Maps a culled species index to a full species index.
 
size_t mapViewToFullReactionIndex (size_t definedReactionIndex) const
 Maps a culled reaction index to a full reaction index.
 
void validateNetworkState () const
 Validates that the FileDefinedEngineView is not stale.
 

Private Attributes

Configm_config = Config::getInstance()
 A reference to the singleton Config instance.
 
quill::Logger * m_logger = LogManager::getInstance().getLogger("log")
 A pointer to the logger instance.
 
DynamicEnginem_baseEngine
 The underlying engine to which this view delegates calculations.
 
std::string m_fileName
 Parser for the network file.
 
const io::NetworkFileParserm_parser
 Active species in the defined engine.
 
std::vector< fourdst::atomic::Species > m_activeSpecies
 Active reactions in the defined engine.
 
reaction::LogicalReactionSet m_activeReactions
 Maps indices of active species to indices in the full network.
 
std::vector< size_t > m_speciesIndexMap
 Maps indices of active reactions to indices in the full network.
 
std::vector< size_t > m_reactionIndexMap
 
bool m_isStale = true
 A flag indicating whether the view is stale and needs to be updated.
 

Detailed Description

An engine view that uses a user-defined reaction network from a file.

This class implements an EngineView that restricts the reaction network to a specific set of reactions defined in an external file. It acts as a filter or a view on a larger, more comprehensive base engine. The file provides a list of reaction identifiers, and this view will only consider those reactions and the species involved in them.

This is useful for focusing on a specific sub-network for analysis, debugging, or performance reasons, without modifying the underlying full network.

The view maintains mappings between the indices of its active (defined) species and reactions and the corresponding indices in the full network of the base engine. All calculations are delegated to the base engine after mapping the inputs from the view's context to the full network context, and the results are mapped back.

<DynamicEngine>

Definition at line 36 of file engine_defined.h.

Member Typedef Documentation

◆ Config

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

Definition at line 223 of file engine_defined.h.

◆ LogManager

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

Definition at line 224 of file engine_defined.h.

Constructor & Destructor Documentation

◆ FileDefinedEngineView()

gridfire::FileDefinedEngineView::FileDefinedEngineView ( DynamicEngine & baseEngine,
const std::string & fileName,
const io::NetworkFileParser & parser )
explicit

Constructs a FileDefinedEngineView.

Parameters
baseEngineThe underlying DynamicEngine to which this view delegates calculations.
fileNameThe path to the file that defines the reaction network for this view.
parserA reference to a parser object capable of parsing the network file.
Usage Example:
MyParser parser;
DynamicEngine baseEngine(...);
FileDefinedEngineView view(baseEngine, "my_network.net", parser);
Abstract class for engines supporting Jacobian and stoichiometry operations.
FileDefinedEngineView(DynamicEngine &baseEngine, const std::string &fileName, const io::NetworkFileParser &parser)
Constructs a FileDefinedEngineView.
Postcondition
The view is initialized with the reactions and species from the specified file.
Exceptions
std::runtime_errorIf a reaction from the file is not found in the base engine.

Definition at line 8 of file engine_defined.cpp.

Member Function Documentation

◆ buildFromFile()

void gridfire::FileDefinedEngineView::buildFromFile ( const std::string & fileName)
private

Builds the active species and reaction sets from a file.

This method uses the provided parser to read reaction names from the given file. It then finds these reactions in the base engine's full network and populates the m_activeReactions and m_activeSpecies members. Finally, it constructs the index maps for the active sets.

Parameters
fileNameThe path to the network definition file.
Postcondition
  • m_activeReactions and m_activeSpecies are populated.
  • m_speciesIndexMap and m_reactionIndexMap are constructed.
  • m_isStale is set to false.
Exceptions
std::runtime_errorIf a reaction from the file is not found in the base engine.

Definition at line 208 of file engine_defined.cpp.

◆ calculateMolarReactionFlow()

double gridfire::FileDefinedEngineView::calculateMolarReactionFlow ( const reaction::Reaction & reaction,
const std::vector< double > & Y_defined,
const double T9,
const double rho ) const
overridevirtual

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

Parameters
reactionThe reaction for which to calculate the flow.
Y_definedVector 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).
Exceptions
std::runtime_errorIf the view is stale or if the reaction is not in the active set.

Implements gridfire::DynamicEngine.

Definition at line 85 of file engine_defined.cpp.

◆ calculateRHSAndEnergy()

StepDerivatives< double > gridfire::FileDefinedEngineView::calculateRHSAndEnergy ( const std::vector< double > & Y_defined,
const double T9,
const double rho ) const
overridevirtual

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

Parameters
Y_definedA 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.
Exceptions
std::runtime_errorIf the view is stale (i.e., update() has not been called after setNetworkFile()).

Implements gridfire::Engine.

Definition at line 29 of file engine_defined.cpp.

◆ constructReactionIndexMap()

std::vector< size_t > gridfire::FileDefinedEngineView::constructReactionIndexMap ( ) const
private

Constructs the reaction index map.

Returns
A vector mapping defined 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.

Exceptions
std::runtime_errorIf an active reaction is not found in the base engine's reaction list.

Definition at line 176 of file engine_defined.cpp.

◆ constructSpeciesIndexMap()

std::vector< size_t > gridfire::FileDefinedEngineView::constructSpeciesIndexMap ( ) const
private

Constructs the species index map.

Returns
A vector mapping defined 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.

Exceptions
std::runtime_errorIf an active species is not found in the base engine's species list.

Definition at line 147 of file engine_defined.cpp.

◆ generateJacobianMatrix()

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

Generates the Jacobian matrix for the active species.

Parameters
Y_definedA vector of abundances for the active species.
T9The temperature in units of 10^9 K.
rhoThe density in g/cm^3.
Exceptions
std::runtime_errorIf the view is stale.

Implements gridfire::DynamicEngine.

Definition at line 45 of file engine_defined.cpp.

◆ generateStoichiometryMatrix()

void gridfire::FileDefinedEngineView::generateStoichiometryMatrix ( )
overridevirtual

Generates the stoichiometry matrix for the active reactions and species.

Exceptions
std::runtime_errorIf the view is stale.

Implements gridfire::DynamicEngine.

Definition at line 68 of file engine_defined.cpp.

◆ getBaseEngine()

const DynamicEngine & gridfire::FileDefinedEngineView::getBaseEngine ( ) const
overridevirtual

Gets the base engine.

Returns
A const reference to the base engine.

Implements gridfire::EngineView< DynamicEngine >.

Definition at line 21 of file engine_defined.cpp.

◆ getJacobianMatrixEntry()

double gridfire::FileDefinedEngineView::getJacobianMatrixEntry ( const int i_defined,
const int j_defined ) const
overridevirtual

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

Parameters
i_definedThe row index (species index) in the defined matrix.
j_definedThe column index (species index) in the defined matrix.
Returns
The value of the Jacobian matrix at (i_defined, j_defined).
Exceptions
std::runtime_errorIf the view is stale.
std::out_of_rangeIf an index is out of bounds.

Implements gridfire::DynamicEngine.

Definition at line 56 of file engine_defined.cpp.

◆ getNetworkReactions()

const reaction::LogicalReactionSet & gridfire::FileDefinedEngineView::getNetworkReactions ( ) const
overridevirtual

Gets the set of active logical reactions in the network.

Returns
Reference to the LogicalReactionSet containing all active reactions.
Exceptions
std::runtime_errorIf the view is stale.

Implements gridfire::DynamicEngine.

Definition at line 102 of file engine_defined.cpp.

◆ getNetworkSpecies()

const std::vector< Species > & gridfire::FileDefinedEngineView::getNetworkSpecies ( ) const
overridevirtual

Gets the list of active species in the network defined by the file.

Returns
A const reference to the vector of active species.

Implements gridfire::Engine.

Definition at line 25 of file engine_defined.cpp.

◆ getScreeningModel()

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

Gets the screening model from the base engine.

Returns
The current screening model type.

Implements gridfire::DynamicEngine.

Definition at line 143 of file engine_defined.cpp.

◆ getSpeciesTimescales()

std::unordered_map< Species, double > gridfire::FileDefinedEngineView::getSpeciesTimescales ( const std::vector< double > & Y_defined,
const double T9,
const double rho ) const
overridevirtual

Computes timescales for all active species in the network.

Parameters
Y_definedVector 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).
Exceptions
std::runtime_errorIf the view is stale.

Implements gridfire::DynamicEngine.

Definition at line 108 of file engine_defined.cpp.

◆ getStoichiometryMatrixEntry()

int gridfire::FileDefinedEngineView::getStoichiometryMatrixEntry ( const int speciesIndex_defined,
const int reactionIndex_defined ) const
overridevirtual

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

Parameters
speciesIndex_definedThe index of the species in the defined species list.
reactionIndex_definedThe index of the reaction in the defined reaction list.
Returns
The stoichiometric coefficient for the given species and reaction.
Exceptions
std::runtime_errorIf the view is stale.
std::out_of_rangeIf an index is out of bounds.

Implements gridfire::DynamicEngine.

Definition at line 74 of file engine_defined.cpp.

◆ mapFullToView()

std::vector< double > gridfire::FileDefinedEngineView::mapFullToView ( const std::vector< double > & full) const
private

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 276 of file engine_defined.cpp.

◆ mapViewToFull()

std::vector< double > gridfire::FileDefinedEngineView::mapViewToFull ( const std::vector< double > & defined) const
private

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

Parameters
definedA 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 defined vector.

Definition at line 267 of file engine_defined.cpp.

◆ mapViewToFullReactionIndex()

size_t gridfire::FileDefinedEngineView::mapViewToFullReactionIndex ( size_t definedReactionIndex) const
private

Maps a culled reaction index to a full reaction index.

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

Definition at line 294 of file engine_defined.cpp.

◆ mapViewToFullSpeciesIndex()

size_t gridfire::FileDefinedEngineView::mapViewToFullSpeciesIndex ( size_t definedSpeciesIndex) const
private

Maps a culled species index to a full species index.

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

Definition at line 285 of file engine_defined.cpp.

◆ setNetworkFile()

void gridfire::FileDefinedEngineView::setNetworkFile ( const std::string & fileName)

Sets a new network file to define the active reactions.

Parameters
fileNameThe path to the new network definition file.
Usage Example:
view.setNetworkFile("another_network.net");
view.update(netIn); // Must be called before using the view again
Postcondition
The view is marked as stale. update() must be called before further use.

Definition at line 133 of file engine_defined.cpp.

◆ setScreeningModel()

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

Sets the screening model for the base engine.

Parameters
modelThe screening model to set.

Implements gridfire::DynamicEngine.

Definition at line 139 of file engine_defined.cpp.

◆ update()

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

Updates the engine view if it is marked as stale.

This method checks if the view is stale (e.g., after setNetworkFile was called). If it is, it rebuilds the active network from the currently set file. The netIn parameter is not used by this implementation but is required by the interface.

Parameters
netInThe current network input (unused).
Postcondition
If the view was stale, it is rebuilt and is no longer stale.

Implements gridfire::DynamicEngine.

Definition at line 127 of file engine_defined.cpp.

◆ validateNetworkState()

void gridfire::FileDefinedEngineView::validateNetworkState ( ) const
private

Validates that the FileDefinedEngineView is not stale.

Exceptions
std::runtime_errorIf the view is stale (i.e., update() has not been called after the view was made stale).

Definition at line 303 of file engine_defined.cpp.

Member Data Documentation

◆ m_activeReactions

reaction::LogicalReactionSet gridfire::FileDefinedEngineView::m_activeReactions
private

Maps indices of active species to indices in the full network.

Definition at line 240 of file engine_defined.h.

◆ m_activeSpecies

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

Active reactions in the defined engine.

Definition at line 238 of file engine_defined.h.

◆ m_baseEngine

DynamicEngine& gridfire::FileDefinedEngineView::m_baseEngine
private

The underlying engine to which this view delegates calculations.

Name of the file defining the reaction set considered by the engine view.

Definition at line 231 of file engine_defined.h.

◆ m_config

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

A reference to the singleton Config instance.

Definition at line 226 of file engine_defined.h.

◆ m_fileName

std::string gridfire::FileDefinedEngineView::m_fileName
private

Parser for the network file.

Definition at line 233 of file engine_defined.h.

◆ m_isStale

bool gridfire::FileDefinedEngineView::m_isStale = true
private

A flag indicating whether the view is stale and needs to be updated.

Definition at line 248 of file engine_defined.h.

◆ m_logger

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

A pointer to the logger instance.

Definition at line 228 of file engine_defined.h.

◆ m_parser

const io::NetworkFileParser& gridfire::FileDefinedEngineView::m_parser
private

Active species in the defined engine.

Definition at line 235 of file engine_defined.h.

◆ m_reactionIndexMap

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

Definition at line 245 of file engine_defined.h.

◆ m_speciesIndexMap

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

Maps indices of active reactions to indices in the full network.

Definition at line 243 of file engine_defined.h.


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