GridFire 0.0.1a
General Purpose Nuclear Network
|
An engine view that uses a user-defined reaction network from a file. More...
#include <engine_defined.h>
Public Member Functions | |
FileDefinedEngineView (DynamicEngine &baseEngine, const std::string &fileName, const io::NetworkFileParser &parser) | |
Constructs a FileDefinedEngineView. | |
const DynamicEngine & | getBaseEngine () 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::LogicalReactionSet & | getNetworkReactions () 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. | |
![]() | |
virtual | ~Engine ()=default |
Virtual destructor. | |
![]() | |
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 | |
Config & | m_config = Config::getInstance() |
A reference to the singleton Config instance. | |
quill::Logger * | m_logger = LogManager::getInstance().getLogger("log") |
A pointer to the logger instance. | |
DynamicEngine & | m_baseEngine |
The underlying engine to which this view delegates calculations. | |
std::string | m_fileName |
Parser for the network file. | |
const io::NetworkFileParser & | m_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. | |
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.
|
private |
Definition at line 223 of file engine_defined.h.
|
private |
Definition at line 224 of file engine_defined.h.
|
explicit |
Constructs a FileDefinedEngineView.
baseEngine | The underlying DynamicEngine to which this view delegates calculations. |
fileName | The path to the file that defines the reaction network for this view. |
parser | A reference to a parser object capable of parsing the network file. |
std::runtime_error | If a reaction from the file is not found in the base engine. |
Definition at line 8 of file engine_defined.cpp.
|
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.
fileName | The path to the network definition file. |
m_activeReactions
and m_activeSpecies
are populated.m_speciesIndexMap
and m_reactionIndexMap
are constructed.m_isStale
is set to false.std::runtime_error | If a reaction from the file is not found in the base engine. |
Definition at line 208 of file engine_defined.cpp.
|
overridevirtual |
Calculates the molar reaction flow for a given reaction in the active network.
reaction | The reaction for which to calculate the flow. |
Y_defined | Vector of current abundances for the active species. |
T9 | Temperature in units of 10^9 K. |
rho | Density in g/cm^3. |
std::runtime_error | If 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.
|
overridevirtual |
Calculates the right-hand side (dY/dt) and energy generation for the active species.
Y_defined | A vector of abundances for the active species. |
T9 | The temperature in units of 10^9 K. |
rho | The density in g/cm^3. |
std::runtime_error | If 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.
|
private |
Constructs the reaction index map.
This method creates a map from the indices of the active reactions to the indices of the corresponding reactions in the full network.
std::runtime_error | If an active reaction is not found in the base engine's reaction list. |
Definition at line 176 of file engine_defined.cpp.
|
private |
Constructs the species index map.
This method creates a map from the indices of the active species to the indices of the corresponding species in the full network.
std::runtime_error | If an active species is not found in the base engine's species list. |
Definition at line 147 of file engine_defined.cpp.
|
overridevirtual |
Generates the Jacobian matrix for the active species.
Y_defined | A vector of abundances for the active species. |
T9 | The temperature in units of 10^9 K. |
rho | The density in g/cm^3. |
std::runtime_error | If the view is stale. |
Implements gridfire::DynamicEngine.
Definition at line 45 of file engine_defined.cpp.
|
overridevirtual |
Generates the stoichiometry matrix for the active reactions and species.
std::runtime_error | If the view is stale. |
Implements gridfire::DynamicEngine.
Definition at line 68 of file engine_defined.cpp.
|
overridevirtual |
Gets the base engine.
Implements gridfire::EngineView< DynamicEngine >.
Definition at line 21 of file engine_defined.cpp.
|
overridevirtual |
Gets an entry from the Jacobian matrix for the active species.
i_defined | The row index (species index) in the defined matrix. |
j_defined | The column index (species index) in the defined matrix. |
std::runtime_error | If the view is stale. |
std::out_of_range | If an index is out of bounds. |
Implements gridfire::DynamicEngine.
Definition at line 56 of file engine_defined.cpp.
|
overridevirtual |
Gets the set of active logical reactions in the network.
std::runtime_error | If the view is stale. |
Implements gridfire::DynamicEngine.
Definition at line 102 of file engine_defined.cpp.
|
overridevirtual |
Gets the list of active species in the network defined by the file.
Implements gridfire::Engine.
Definition at line 25 of file engine_defined.cpp.
|
nodiscardoverridevirtual |
Gets the screening model from the base engine.
Implements gridfire::DynamicEngine.
Definition at line 143 of file engine_defined.cpp.
|
overridevirtual |
Computes timescales for all active species in the network.
Y_defined | Vector of current abundances for the active species. |
T9 | Temperature in units of 10^9 K. |
rho | Density in g/cm^3. |
std::runtime_error | If the view is stale. |
Implements gridfire::DynamicEngine.
Definition at line 108 of file engine_defined.cpp.
|
overridevirtual |
Gets an entry from the stoichiometry matrix for the active species and reactions.
speciesIndex_defined | The index of the species in the defined species list. |
reactionIndex_defined | The index of the reaction in the defined reaction list. |
std::runtime_error | If the view is stale. |
std::out_of_range | If an index is out of bounds. |
Implements gridfire::DynamicEngine.
Definition at line 74 of file engine_defined.cpp.
|
private |
Maps a vector of full abundances to a vector of culled abundances.
full | A vector of abundances for the full network. |
Definition at line 276 of file engine_defined.cpp.
|
private |
Maps a vector of culled abundances to a vector of full abundances.
defined | A vector of abundances for the active species. |
Definition at line 267 of file engine_defined.cpp.
|
private |
Maps a culled reaction index to a full reaction index.
definedReactionIndex | The index of the reaction in the defined reaction list. |
std::out_of_range | If the defined index is out of bounds for the reaction index map. |
Definition at line 294 of file engine_defined.cpp.
|
private |
Maps a culled species index to a full species index.
definedSpeciesIndex | The index of the species in the defined species list. |
std::out_of_range | If the defined index is out of bounds for the species index map. |
Definition at line 285 of file engine_defined.cpp.
void gridfire::FileDefinedEngineView::setNetworkFile | ( | const std::string & | fileName | ) |
Sets a new network file to define the active reactions.
fileName | The path to the new network definition file. |
update()
must be called before further use. Definition at line 133 of file engine_defined.cpp.
|
overridevirtual |
Sets the screening model for the base engine.
model | The screening model to set. |
Implements gridfire::DynamicEngine.
Definition at line 139 of file engine_defined.cpp.
|
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.
netIn | The current network input (unused). |
Implements gridfire::DynamicEngine.
Definition at line 127 of file engine_defined.cpp.
|
private |
Validates that the FileDefinedEngineView is not stale.
std::runtime_error | If 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.
|
private |
Maps indices of active species to indices in the full network.
Definition at line 240 of file engine_defined.h.
|
private |
Active reactions in the defined engine.
Definition at line 238 of file engine_defined.h.
|
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.
|
private |
A reference to the singleton Config instance.
Definition at line 226 of file engine_defined.h.
|
private |
Parser for the network file.
Definition at line 233 of file engine_defined.h.
|
private |
A flag indicating whether the view is stale and needs to be updated.
Definition at line 248 of file engine_defined.h.
|
private |
A pointer to the logger instance.
Definition at line 228 of file engine_defined.h.
|
private |
Active species in the defined engine.
Definition at line 235 of file engine_defined.h.
|
private |
Definition at line 245 of file engine_defined.h.
|
private |
Maps indices of active reactions to indices in the full network.
Definition at line 243 of file engine_defined.h.