Loading...
Searching...
No Matches
engine_defined.h
Go to the documentation of this file.
#pragma once
#include "gridfire/engine/views/engine_view_abstract.h"
#include "gridfire/engine/engine_abstract.h"
#include "gridfire/io/network_file.h"
#include "gridfire/network.h"
#include "fourdst/config/config.h"
#include "fourdst/logging/logging.h"
#include "quill/Logger.h"
#include <string>
namespace gridfire{
class DefinedEngineView : public DynamicEngine, public EngineView<DynamicEngine> {
public:
DefinedEngineView(const std::vector<std::string>& peNames, DynamicEngine& baseEngine);
const DynamicEngine& getBaseEngine() const override;
// --- Engine Interface ---
const std::vector<fourdst::atomic::Species>& getNetworkSpecies() const override;
// --- DynamicEngine Interface ---
std::expected<StepDerivatives<double>, expectations::StaleEngineError> calculateRHSAndEnergy(
const std::vector<double>& Y_defined,
const double T9,
const double rho
) const override;
void generateJacobianMatrix(
const std::vector<double>& Y_dynamic,
const double T9,
const double rho
) const override;
double getJacobianMatrixEntry(
const int i_defined,
const int j_defined
) const override;
void generateStoichiometryMatrix() override;
int getStoichiometryMatrixEntry(
const int speciesIndex_defined,
const int reactionIndex_defined
) const override;
double calculateMolarReactionFlow(
const reaction::Reaction& reaction,
const std::vector<double>& Y_defined,
const double T9,
const double rho
) const override;
const reaction::LogicalReactionSet& getNetworkReactions() const override;
void setNetworkReactions(const reaction::LogicalReactionSet& reactions) override;
[[nodiscard]] 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;
[[nodiscard]] 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;
fourdst::composition::Composition update(const NetIn &netIn) override;
bool isStale(const NetIn& netIn) override;
void setScreeningModel(screening::ScreeningType model) override;
[[nodiscard]] screening::ScreeningType getScreeningModel() const override;
[[nodiscard]] int getSpeciesIndex(const fourdst::atomic::Species &species) const override;
[[nodiscard]] std::vector<double> mapNetInToMolarAbundanceVector(const NetIn &netIn) const override;
[[nodiscard]] PrimingReport primeEngine(const NetIn &netIn) override;
protected:
bool m_isStale = true;
DynamicEngine& m_baseEngine;
private:
quill::Logger* m_logger = fourdst::logging::LogManager::getInstance().getLogger("log");
std::vector<fourdst::atomic::Species> m_activeSpecies;
reaction::LogicalReactionSet m_activeReactions;
std::vector<size_t> m_speciesIndexMap;
std::vector<size_t> m_reactionIndexMap;
private:
std::vector<size_t> constructSpeciesIndexMap() const;
std::vector<size_t> constructReactionIndexMap() const;
std::vector<double> mapViewToFull(const std::vector<double>& defined) const;
std::vector<double> mapFullToView(const std::vector<double>& full) const;
size_t mapViewToFullSpeciesIndex(size_t definedSpeciesIndex) const;
size_t mapViewToFullReactionIndex(size_t definedReactionIndex) const;
void validateNetworkState() const;
void collect(const std::vector<std::string>& peNames);
};
class FileDefinedEngineView final: public DefinedEngineView {
public:
explicit FileDefinedEngineView(
DynamicEngine& baseEngine,
const std::string& fileName,
const io::NetworkFileParser& parser
);
std::string getNetworkFile() const { return m_fileName; }
const io::NetworkFileParser& getParser() const { return m_parser; }
private:
using Config = fourdst::config::Config;
using LogManager = fourdst::logging::LogManager;
Config& m_config = Config::getInstance();
quill::Logger* m_logger = LogManager::getInstance().getLogger("log");
std::string m_fileName;
const io::NetworkFileParser& m_parser;
};
}
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