GridFire 0.0.1a
General Purpose Nuclear Network
Loading...
Searching...
No Matches
engine_defined.h
Go to the documentation of this file.
1#pragma once
2
6#include "gridfire/network.h"
7
8#include "fourdst/config/config.h"
9#include "fourdst/logging/logging.h"
10
11#include "quill/Logger.h"
12
13#include <string>
14
15namespace gridfire{
36 class FileDefinedEngineView final: public DynamicEngine, public EngineView<DynamicEngine> {
37 public:
55 explicit FileDefinedEngineView(
56 DynamicEngine& baseEngine,
57 const std::string& fileName,
58 const io::NetworkFileParser& parser
59 );
60
61 // --- EngineView Interface ---
66 const DynamicEngine& getBaseEngine() const override;
67
68 // --- Engine Interface ---
73 const std::vector<fourdst::atomic::Species>& getNetworkSpecies() const override;
74
75 // --- DynamicEngine Interface ---
88 const std::vector<double>& Y_defined,
89 const double T9,
90 const double rho
91 ) const override;
102 const std::vector<double>& Y_defined,
103 const double T9,
104 const double rho
105 ) override;
117 const int i_defined,
118 const int j_defined
119 ) const override;
125 void generateStoichiometryMatrix() override;
137 const int speciesIndex_defined,
138 const int reactionIndex_defined
139 ) const override;
153 const std::vector<double>& Y_defined,
154 const double T9,
155 const double rho
156 ) const override;
175 std::unordered_map<fourdst::atomic::Species, double> getSpeciesTimescales(
176 const std::vector<double>& Y_defined,
177 const double T9,
178 const double rho
179 ) const override;
180
192 void update(const NetIn &netIn) override;
193
207 void setNetworkFile(const std::string& fileName);
208
214 void setScreeningModel(screening::ScreeningType model) override;
215
221 [[nodiscard]] screening::ScreeningType getScreeningModel() const override;
222 private:
223 using Config = fourdst::config::Config;
224 using LogManager = fourdst::logging::LogManager;
226 Config& m_config = Config::getInstance();
228 quill::Logger* m_logger = LogManager::getInstance().getLogger("log");
229
233 std::string m_fileName;
236
238 std::vector<fourdst::atomic::Species> m_activeSpecies;
241
243 std::vector<size_t> m_speciesIndexMap;
245 std::vector<size_t> m_reactionIndexMap;
246
248 bool m_isStale = true;
249
250 private:
268 void buildFromFile(const std::string& fileName);
269
280 std::vector<size_t> constructSpeciesIndexMap() const;
281
292 std::vector<size_t> constructReactionIndexMap() const;
293
301 std::vector<double> mapViewToFull(const std::vector<double>& defined) const;
302
310 std::vector<double> mapFullToView(const std::vector<double>& full) const;
311
320 size_t mapViewToFullSpeciesIndex(size_t definedSpeciesIndex) const;
321
330 size_t mapViewToFullReactionIndex(size_t definedReactionIndex) const;
331
337 void validateNetworkState() const;
338 };
339}
Abstract class for engines supporting Jacobian and stoichiometry operations.
Abstract base class for a "view" of a reaction network engine.
const io::NetworkFileParser & m_parser
Active species in the defined engine.
double getJacobianMatrixEntry(const int i_defined, const int j_defined) const override
Gets an entry from the Jacobian matrix for the active species.
std::string m_fileName
Parser for the network file.
void generateStoichiometryMatrix() override
Generates the stoichiometry matrix for the active reactions and species.
std::vector< fourdst::atomic::Species > m_activeSpecies
Active reactions in the defined engine.
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 buildFromFile(const std::string &fileName)
Builds the active species and reaction sets from a file.
void generateJacobianMatrix(const std::vector< double > &Y_defined, const double T9, const double rho) override
Generates the Jacobian matrix for the active species.
const DynamicEngine & getBaseEngine() const override
Gets the base engine.
std::vector< size_t > constructSpeciesIndexMap() const
Constructs the species index map.
const reaction::LogicalReactionSet & getNetworkReactions() const override
Gets the set of active logical reactions in the network.
fourdst::config::Config Config
bool m_isStale
A flag indicating whether the view is stale and needs to be updated.
size_t mapViewToFullReactionIndex(size_t definedReactionIndex) const
Maps a culled reaction index to a full reaction index.
Config & m_config
A reference to the singleton Config instance.
const std::vector< fourdst::atomic::Species > & getNetworkSpecies() const override
Gets the list of active species in the network defined by the file.
FileDefinedEngineView(DynamicEngine &baseEngine, const std::string &fileName, const io::NetworkFileParser &parser)
Constructs a FileDefinedEngineView.
void setNetworkFile(const std::string &fileName)
Sets a new network file to define the active reactions.
std::vector< double > mapFullToView(const std::vector< double > &full) const
Maps a vector of full abundances to a vector of culled abundances.
quill::Logger * m_logger
A pointer to the logger instance.
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.
size_t mapViewToFullSpeciesIndex(size_t definedSpeciesIndex) const
Maps a culled species index to a full species index.
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.
fourdst::logging::LogManager LogManager
void update(const NetIn &netIn) override
Updates the engine view if it is marked as stale.
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.
DynamicEngine & m_baseEngine
The underlying engine to which this view delegates calculations.
void setScreeningModel(screening::ScreeningType model) override
Sets the screening model for the base engine.
std::vector< double > mapViewToFull(const std::vector< double > &defined) const
Maps a vector of culled abundances to a vector of full abundances.
screening::ScreeningType getScreeningModel() const override
Gets the screening model from the base engine.
reaction::LogicalReactionSet m_activeReactions
Maps indices of active species to indices in the full network.
void validateNetworkState() const
Validates that the FileDefinedEngineView is not stale.
std::vector< size_t > constructReactionIndexMap() const
Constructs the reaction index map.
std::vector< size_t > m_speciesIndexMap
Maps indices of active reactions to indices in the full network.
std::vector< size_t > m_reactionIndexMap
An abstract base class for network file parsers.
Represents a single nuclear reaction from a specific data source.
Definition reaction.h:72
Abstract interfaces for reaction network engines in GridFire.
Abstract interfaces for engine "views" in GridFire.
TemplatedReactionSet< LogicalReaction > LogicalReactionSet
A set of logical reactions.
Definition reaction.h:557
ScreeningType
Enumerates the available plasma screening models.
Structure holding derivatives and energy generation for a network step.