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{
16 class DefinedEngineView : public DynamicEngine, public EngineView<DynamicEngine> {
17 public:
18 DefinedEngineView(const std::vector<std::string>& peNames, DynamicEngine& baseEngine);
19 const DynamicEngine& getBaseEngine() const override;
20
21 // --- Engine Interface ---
26 const std::vector<fourdst::atomic::Species>& getNetworkSpecies() const override;
27
28 // --- DynamicEngine Interface ---
40 std::expected<StepDerivatives<double>, expectations::StaleEngineError> calculateRHSAndEnergy(
41 const std::vector<double>& Y_defined,
42 const double T9,
43 const double rho
44 ) const override;
55 const std::vector<double>& Y_dynamic,
56 const double T9,
57 const double rho
58 ) const override;
70 const int i_defined,
71 const int j_defined
72 ) const override;
78 void generateStoichiometryMatrix() override;
90 const int speciesIndex_defined,
91 const int reactionIndex_defined
92 ) const override;
106 const std::vector<double>& Y_defined,
107 const double T9,
108 const double rho
109 ) const override;
118
119 void setNetworkReactions(const reaction::LogicalReactionSet& reactions) override;
130 [[nodiscard]] std::expected<std::unordered_map<fourdst::atomic::Species, double>, expectations::StaleEngineError> getSpeciesTimescales(
131 const std::vector<double>& Y_defined,
132 const double T9,
133 const double rho
134 ) const override;
135
136 [[nodiscard]] std::expected<std::unordered_map<fourdst::atomic::Species, double>, expectations::StaleEngineError> getSpeciesDestructionTimescales(
137 const std::vector<double>& Y_defined,
138 const double T9,
139 const double rho
140 ) const override;
141
153 fourdst::composition::Composition update(const NetIn &netIn) override;
154
155 bool isStale(const NetIn& netIn) override;
156
162 void setScreeningModel(screening::ScreeningType model) override;
163
169 [[nodiscard]] screening::ScreeningType getScreeningModel() const override;
170
171 [[nodiscard]] int getSpeciesIndex(const fourdst::atomic::Species &species) const override;
172
173 [[nodiscard]] std::vector<double> mapNetInToMolarAbundanceVector(const NetIn &netIn) const override;
174
175 [[nodiscard]] PrimingReport primeEngine(const NetIn &netIn) override;
176 protected:
177 bool m_isStale = true;
179 private:
180 quill::Logger* m_logger = fourdst::logging::LogManager::getInstance().getLogger("log");
182 std::vector<fourdst::atomic::Species> m_activeSpecies;
185
187 std::vector<size_t> m_speciesIndexMap;
189 std::vector<size_t> m_reactionIndexMap;
190 private:
201 std::vector<size_t> constructSpeciesIndexMap() const;
202
213 std::vector<size_t> constructReactionIndexMap() const;
214
222 std::vector<double> mapViewToFull(const std::vector<double>& defined) const;
223
231 std::vector<double> mapFullToView(const std::vector<double>& full) const;
232
241 size_t mapViewToFullSpeciesIndex(size_t definedSpeciesIndex) const;
242
251 size_t mapViewToFullReactionIndex(size_t definedReactionIndex) const;
252
253 void validateNetworkState() const;
254
255 void collect(const std::vector<std::string>& peNames);
256
257 };
258
260 public:
261 explicit FileDefinedEngineView(
262 DynamicEngine& baseEngine,
263 const std::string& fileName,
264 const io::NetworkFileParser& parser
265 );
266 std::string getNetworkFile() const { return m_fileName; }
267 const io::NetworkFileParser& getParser() const { return m_parser; }
268 private:
269 using Config = fourdst::config::Config;
270 using LogManager = fourdst::logging::LogManager;
271 Config& m_config = Config::getInstance();
272 quill::Logger* m_logger = LogManager::getInstance().getLogger("log");
273 std::string m_fileName;
276 };
277}
PrimingReport primeEngine(const NetIn &netIn) override
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 std::vector< fourdst::atomic::Species > & getNetworkSpecies() const override
Gets the list of active species in the network defined by the file.
double getJacobianMatrixEntry(const int i_defined, const int j_defined) const override
Gets an entry from the Jacobian matrix for the active species.
std::vector< double > mapFullToView(const std::vector< double > &full) const
Maps a vector of full abundances to a vector of culled abundances.
reaction::LogicalReactionSet m_activeReactions
Maps indices of active species to indices in the full network.
screening::ScreeningType getScreeningModel() const override
Gets the screening model from the base engine.
std::expected< std::unordered_map< fourdst::atomic::Species, double >, expectations::StaleEngineError > getSpeciesDestructionTimescales(const std::vector< double > &Y_defined, const double T9, const double rho) const override
std::expected< StepDerivatives< double >, expectations::StaleEngineError > 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.
quill::Logger * m_logger
Active species in the defined engine.
std::vector< double > mapViewToFull(const std::vector< double > &defined) const
Maps a vector of culled abundances to a vector of full abundances.
std::vector< fourdst::atomic::Species > m_activeSpecies
Active reactions in the defined engine.
const DynamicEngine & getBaseEngine() const override
Access the underlying engine instance.
std::vector< double > mapNetInToMolarAbundanceVector(const NetIn &netIn) const override
bool isStale(const NetIn &netIn) override
void setNetworkReactions(const reaction::LogicalReactionSet &reactions) override
DefinedEngineView(const std::vector< std::string > &peNames, DynamicEngine &baseEngine)
std::vector< size_t > constructSpeciesIndexMap() const
Constructs the species index map.
size_t mapViewToFullReactionIndex(size_t definedReactionIndex) const
Maps a culled reaction index to a full reaction index.
std::vector< size_t > constructReactionIndexMap() const
Constructs the reaction index map.
void setScreeningModel(screening::ScreeningType model) override
Sets the screening model for the base engine.
int getSpeciesIndex(const fourdst::atomic::Species &species) const override
std::expected< std::unordered_map< fourdst::atomic::Species, double >, expectations::StaleEngineError > getSpeciesTimescales(const std::vector< double > &Y_defined, const double T9, const double rho) const override
Computes timescales for all active species in the network.
std::vector< size_t > m_speciesIndexMap
Maps indices of active reactions to indices in the full network.
void generateStoichiometryMatrix() override
Generates the stoichiometry matrix for the active reactions and species.
void generateJacobianMatrix(const std::vector< double > &Y_dynamic, const double T9, const double rho) const override
Generates the Jacobian matrix for the active species.
void collect(const std::vector< std::string > &peNames)
const reaction::LogicalReactionSet & getNetworkReactions() const override
Gets the set of active logical reactions in the network.
fourdst::composition::Composition update(const NetIn &netIn) override
Updates the engine view if it is marked as stale.
size_t mapViewToFullSpeciesIndex(size_t definedSpeciesIndex) const
Maps a culled species index to a full species index.
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.
std::vector< size_t > m_reactionIndexMap
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
std::string m_fileName
Parser for the network file.
fourdst::config::Config Config
FileDefinedEngineView(DynamicEngine &baseEngine, const std::string &fileName, const io::NetworkFileParser &parser)
FileDefinedEngineView Implementation ///.
fourdst::logging::LogManager LogManager
std::string getNetworkFile() const
const io::NetworkFileParser & getParser() const
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:563
ScreeningType
Enumerates the available plasma screening models.
Captures the result of a network priming operation.
Definition reporting.h:67