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
3#include "gridfire/engine/views/engine_view_abstract.h"
4#include "gridfire/engine/engine_abstract.h"
5#include "gridfire/io/network_file.h"
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
15 namespace 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;
54 void generateJacobianMatrix(
55 const std::vector<double>& Y_dynamic,
56 const double T9,
57 const double rho
58 ) const override;
69 double getJacobianMatrixEntry(
70 const int i_defined,
71 const int j_defined
72 ) const override;
78 void generateStoichiometryMatrix() override;
89 int getStoichiometryMatrixEntry(
90 const int speciesIndex_defined,
91 const int reactionIndex_defined
92 ) const override;
104 double calculateMolarReactionFlow(
105 const reaction::Reaction& reaction,
106 const std::vector<double>& Y_defined,
107 const double T9,
108 const double rho
109 ) const override;
117 const reaction::LogicalReactionSet& getNetworkReactions() 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;
178 DynamicEngine& m_baseEngine;
179 private:
180 quill::Logger* m_logger = fourdst::logging::LogManager::getInstance().getLogger("log");
182 std::vector<fourdst::atomic::Species> m_activeSpecies;
184 reaction::LogicalReactionSet m_activeReactions;
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
259 class FileDefinedEngineView final: public DefinedEngineView {
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;
275 const io::NetworkFileParser& m_parser;
276 };
277}
gridfire::DefinedEngineView::primeEngine
PrimingReport primeEngine(const NetIn &netIn) override
Definition engine_defined.cpp:212
gridfire::DefinedEngineView::calculateMolarReactionFlow
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.
Definition engine_defined.cpp:91
gridfire::DefinedEngineView::getNetworkSpecies
const std::vector< fourdst::atomic::Species > & getNetworkSpecies() const override
Gets the list of active species in the network defined by the file.
Definition engine_defined.cpp:26
gridfire::DefinedEngineView::m_isStale
bool m_isStale
Definition engine_defined.h:177
gridfire::DefinedEngineView::getJacobianMatrixEntry
double getJacobianMatrixEntry(const int i_defined, const int j_defined) const override
Gets an entry from the Jacobian matrix for the active species.
Definition engine_defined.cpp:62
gridfire::DefinedEngineView::mapFullToView
std::vector< double > mapFullToView(const std::vector< double > &full) const
Maps a vector of full abundances to a vector of culled abundances.
Definition engine_defined.cpp:286
gridfire::DefinedEngineView::m_activeReactions
reaction::LogicalReactionSet m_activeReactions
Maps indices of active species to indices in the full network.
Definition engine_defined.h:184
gridfire::DefinedEngineView::getScreeningModel
screening::ScreeningType getScreeningModel() const override
Gets the screening model from the base engine.
Definition engine_defined.cpp:184
gridfire::DefinedEngineView::getSpeciesDestructionTimescales
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
Definition engine_defined.cpp:146
gridfire::DefinedEngineView::calculateRHSAndEnergy
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.
Definition engine_defined.cpp:30
gridfire::DefinedEngineView::m_logger
quill::Logger * m_logger
Active species in the defined engine.
Definition engine_defined.h:180
gridfire::DefinedEngineView::validateNetworkState
void validateNetworkState() const
Definition engine_defined.cpp:313
gridfire::DefinedEngineView::mapViewToFull
std::vector< double > mapViewToFull(const std::vector< double > &defined) const
Maps a vector of culled abundances to a vector of full abundances.
Definition engine_defined.cpp:277
gridfire::DefinedEngineView::m_activeSpecies
std::vector< fourdst::atomic::Species > m_activeSpecies
Active reactions in the defined engine.
Definition engine_defined.h:182
gridfire::DefinedEngineView::getBaseEngine
const DynamicEngine & getBaseEngine() const override
Access the underlying engine instance.
Definition engine_defined.cpp:22
gridfire::DefinedEngineView::m_baseEngine
DynamicEngine & m_baseEngine
Definition engine_defined.h:178
gridfire::DefinedEngineView::mapNetInToMolarAbundanceVector
std::vector< double > mapNetInToMolarAbundanceVector(const NetIn &netIn) const override
Definition engine_defined.cpp:201
gridfire::DefinedEngineView::isStale
bool isStale(const NetIn &netIn) override
Definition engine_defined.cpp:175
gridfire::DefinedEngineView::setNetworkReactions
void setNetworkReactions(const reaction::LogicalReactionSet &reactions) override
Definition engine_defined.cpp:114
gridfire::DefinedEngineView::DefinedEngineView
DefinedEngineView(const std::vector< std::string > &peNames, DynamicEngine &baseEngine)
Definition engine_defined.cpp:17
gridfire::DefinedEngineView::constructSpeciesIndexMap
std::vector< size_t > constructSpeciesIndexMap() const
Constructs the species index map.
Definition engine_defined.cpp:216
gridfire::DefinedEngineView::mapViewToFullReactionIndex
size_t mapViewToFullReactionIndex(size_t definedReactionIndex) const
Maps a culled reaction index to a full reaction index.
Definition engine_defined.cpp:304
gridfire::DefinedEngineView::constructReactionIndexMap
std::vector< size_t > constructReactionIndexMap() const
Constructs the reaction index map.
Definition engine_defined.cpp:245
gridfire::DefinedEngineView::setScreeningModel
void setScreeningModel(screening::ScreeningType model) override
Sets the screening model for the base engine.
Definition engine_defined.cpp:180
gridfire::DefinedEngineView::getSpeciesIndex
int getSpeciesIndex(const fourdst::atomic::Species &species) const override
Definition engine_defined.cpp:188
gridfire::DefinedEngineView::getSpeciesTimescales
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.
Definition engine_defined.cpp:122
gridfire::DefinedEngineView::m_speciesIndexMap
std::vector< size_t > m_speciesIndexMap
Maps indices of active reactions to indices in the full network.
Definition engine_defined.h:187
gridfire::DefinedEngineView::generateStoichiometryMatrix
void generateStoichiometryMatrix() override
Generates the stoichiometry matrix for the active reactions and species.
Definition engine_defined.cpp:74
gridfire::DefinedEngineView::generateJacobianMatrix
void generateJacobianMatrix(const std::vector< double > &Y_dynamic, const double T9, const double rho) const override
Generates the Jacobian matrix for the active species.
Definition engine_defined.cpp:51
gridfire::DefinedEngineView::collect
void collect(const std::vector< std::string > &peNames)
Definition engine_defined.cpp:321
gridfire::DefinedEngineView::getNetworkReactions
const reaction::LogicalReactionSet & getNetworkReactions() const override
Gets the set of active logical reactions in the network.
Definition engine_defined.cpp:108
gridfire::DefinedEngineView::update
fourdst::composition::Composition update(const NetIn &netIn) override
Updates the engine view if it is marked as stale.
Definition engine_defined.cpp:171
gridfire::DefinedEngineView::mapViewToFullSpeciesIndex
size_t mapViewToFullSpeciesIndex(size_t definedSpeciesIndex) const
Maps a culled species index to a full species index.
Definition engine_defined.cpp:295
gridfire::DefinedEngineView::getStoichiometryMatrixEntry
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.
Definition engine_defined.cpp:80
gridfire::DefinedEngineView::m_reactionIndexMap
std::vector< size_t > m_reactionIndexMap
Definition engine_defined.h:189
gridfire::DynamicEngine
Abstract class for engines supporting Jacobian and stoichiometry operations.
Definition engine_abstract.h:130
gridfire::EngineView
Abstract base class for a "view" of a reaction network engine.
Definition engine_view_abstract.h:74
gridfire::FileDefinedEngineView::m_parser
const io::NetworkFileParser & m_parser
Definition engine_defined.h:275
gridfire::FileDefinedEngineView::m_fileName
std::string m_fileName
Parser for the network file.
Definition engine_defined.h:273
gridfire::FileDefinedEngineView::Config
fourdst::config::Config Config
Definition engine_defined.h:269
gridfire::FileDefinedEngineView::m_config
Config & m_config
Definition engine_defined.h:271
gridfire::FileDefinedEngineView::FileDefinedEngineView
FileDefinedEngineView(DynamicEngine &baseEngine, const std::string &fileName, const io::NetworkFileParser &parser)
FileDefinedEngineView Implementation ///.
Definition engine_defined.cpp:379
gridfire::FileDefinedEngineView::m_logger
quill::Logger * m_logger
Definition engine_defined.h:272
gridfire::FileDefinedEngineView::LogManager
fourdst::logging::LogManager LogManager
Definition engine_defined.h:270
gridfire::FileDefinedEngineView::getNetworkFile
std::string getNetworkFile() const
Definition engine_defined.h:266
gridfire::FileDefinedEngineView::getParser
const io::NetworkFileParser & getParser() const
Definition engine_defined.h:267
gridfire::io::NetworkFileParser
An abstract base class for network file parsers.
Definition network_file.h:22
gridfire::reaction::Reaction
Represents a single nuclear reaction from a specific data source.
Definition reaction.h:72
engine_abstract.h
Abstract interfaces for reaction network engines in GridFire.
engine_view_abstract.h
Abstract interfaces for engine "views" in GridFire.
gridfire::reaction
Definition reaction.h:25
gridfire::reaction::LogicalReactionSet
TemplatedReactionSet< LogicalReaction > LogicalReactionSet
A set of logical reactions.
Definition reaction.h:563
gridfire::screening::ScreeningType
ScreeningType
Enumerates the available plasma screening models.
Definition screening_types.h:15
gridfire
Definition engine_abstract.h:31
network.h
network_file.h
gridfire::NetIn
Definition network.h:53
gridfire::PrimingReport
Captures the result of a network priming operation.
Definition reporting.h:67
gridfire::expectations::StaleEngineError
Definition expected_engine.h:44