GridFire 0.0.1a
General Purpose Nuclear Network
Loading...
Searching...
No Matches
engine_adaptive.h
Go to the documentation of this file.
1#pragma once
6#include "gridfire/network.h"
7
8#include "fourdst/composition/atomicSpecies.h"
9#include "fourdst/config/config.h"
10#include "fourdst/logging/logging.h"
11
14
15#include "quill/Logger.h"
16
17namespace gridfire {
50 class AdaptiveEngineView final : public DynamicEngine, public EngineView<DynamicEngine> {
51 public:
60 explicit AdaptiveEngineView(DynamicEngine& baseEngine);
61
79 fourdst::composition::Composition update(const NetIn &netIn) override;
80
81 bool isStale(const NetIn& netIn) override;
82
87 [[nodiscard]] const std::vector<fourdst::atomic::Species>& getNetworkSpecies() const override;
88
105 [[nodiscard]] std::expected<StepDerivatives<double>, expectations::StaleEngineError> calculateRHSAndEnergy(
106 const std::vector<double> &Y_culled,
107 const double T9,
108 const double rho
109 ) const override;
110
125 const std::vector<double> &Y_dynamic,
126 const double T9,
127 const double rho
128 ) const override;
129
144 [[nodiscard]] double getJacobianMatrixEntry(
145 const int i_culled,
146 const int j_culled
147 ) const override;
148
158 void generateStoichiometryMatrix() override;
159
174 [[nodiscard]] int getStoichiometryMatrixEntry(
175 const int speciesIndex_culled,
176 const int reactionIndex_culled
177 ) const override;
178
194 [[nodiscard]] double calculateMolarReactionFlow(
196 const std::vector<double> &Y_culled,
197 double T9,
198 double rho
199 ) const override;
200
206 [[nodiscard]] const reaction::LogicalReactionSet& getNetworkReactions() const override;
207
208 void setNetworkReactions(const reaction::LogicalReactionSet& reactions) override;
209
223 [[nodiscard]] std::expected<std::unordered_map<fourdst::atomic::Species, double>, expectations::StaleEngineError> getSpeciesTimescales(
224 const std::vector<double> &Y_culled,
225 double T9,
226 double rho
227 ) const override;
228
229 [[nodiscard]] std::expected<std::unordered_map<fourdst::atomic::Species, double>, expectations::StaleEngineError> getSpeciesDestructionTimescales(
230 const std::vector<double> &Y,
231 double T9,
232 double rho
233 ) const override;
234
239 [[nodiscard]] const DynamicEngine& getBaseEngine() const override { return m_baseEngine; }
240
256 void setScreeningModel(screening::ScreeningType model) override;
257
271 [[nodiscard]] screening::ScreeningType getScreeningModel() const override;
272
273 [[nodiscard]] int getSpeciesIndex(const fourdst::atomic::Species &species) const override;
274
275 [[nodiscard]] std::vector<double> mapNetInToMolarAbundanceVector(const NetIn &netIn) const override;
276
277 [[nodiscard]] PrimingReport primeEngine(const NetIn &netIn) override;
278 private:
279 using Config = fourdst::config::Config;
280 using LogManager = fourdst::logging::LogManager;
282 Config& m_config = Config::getInstance();
284 quill::Logger* m_logger = LogManager::getInstance().getLogger("log");
285
288
290 std::vector<fourdst::atomic::Species> m_activeSpecies;
293
295 std::vector<size_t> m_speciesIndexMap;
297 std::vector<size_t> m_reactionIndexMap;
298
300 bool m_isStale = true;
301
302 private:
310 private:
321 [[nodiscard]] std::vector<size_t> constructSpeciesIndexMap() const;
322
333 [[nodiscard]] std::vector<size_t> constructReactionIndexMap() const;
334
342 [[nodiscard]] std::vector<double> mapCulledToFull(const std::vector<double>& culled) const;
343
351 [[nodiscard]] std::vector<double> mapFullToCulled(const std::vector<double>& full) const;
352
361 [[nodiscard]] size_t mapCulledToFullSpeciesIndex(size_t culledSpeciesIndex) const;
362
371 [[nodiscard]] size_t mapCulledToFullReactionIndex(size_t culledReactionIndex) const;
372
378 void validateState() const;
379
401 std::vector<ReactionFlow> calculateAllReactionFlows(
402 const NetIn& netIn,
403 std::vector<double>& out_Y_Full
404 ) const;
422 [[nodiscard]] std::unordered_set<fourdst::atomic::Species> findReachableSpecies(
423 const NetIn& netIn
424 ) const;
445 [[nodiscard]] std::vector<const reaction::LogicalReaction*> cullReactionsByFlow(
446 const std::vector<ReactionFlow>& allFlows,
447 const std::unordered_set<fourdst::atomic::Species>& reachableSpecies,
448 const std::vector<double>& Y_full,
449 double maxFlow
450 ) const;
451
452 typedef std::pair<std::unordered_set<const reaction::LogicalReaction*>, std::unordered_set<fourdst::atomic::Species>> RescueSet;
454 const std::vector<double>& Y_full,
455 const double T9,
456 const double rho,
457 const std::vector<fourdst::atomic::Species>& activeSpecies,
458 const reaction::LogicalReactionSet& activeReactions
459 ) const;
476 const std::vector<const reaction::LogicalReaction*>& finalReactions
477 );
478 };
479}
void generateJacobianMatrix(const std::vector< double > &Y_dynamic, const double T9, const double rho) const override
Generates the Jacobian matrix for the active species.
double calculateMolarReactionFlow(const reaction::Reaction &reaction, const std::vector< double > &Y_culled, double T9, double rho) const override
Calculates the molar reaction flow for a given reaction in the active network.
screening::ScreeningType getScreeningModel() const override
Gets the screening model from the base engine.
std::unordered_set< fourdst::atomic::Species > findReachableSpecies(const NetIn &netIn) const
Finds all species that are reachable from the initial fuel through the reaction network.
const reaction::LogicalReactionSet & getNetworkReactions() const override
Gets the set of active logical reactions in the network.
Config & m_config
A reference to the singleton Config instance, used for retrieving configuration parameters.
reaction::LogicalReactionSet m_activeReactions
The set of reactions that are currently active in the network.
std::vector< size_t > m_reactionIndexMap
A map from the indices of the active reactions to the indices of the corresponding reactions in the f...
void generateStoichiometryMatrix() override
Generates the stoichiometry matrix for the active reactions and species.
size_t mapCulledToFullSpeciesIndex(size_t culledSpeciesIndex) const
Maps a culled species index to a full species index.
fourdst::composition::Composition update(const NetIn &netIn) override
Updates the active species and reactions based on the current conditions.
std::vector< double > mapFullToCulled(const std::vector< double > &full) const
Maps a vector of full abundances to a vector of culled abundances.
std::vector< const reaction::LogicalReaction * > cullReactionsByFlow(const std::vector< ReactionFlow > &allFlows, const std::unordered_set< fourdst::atomic::Species > &reachableSpecies, const std::vector< double > &Y_full, double maxFlow) const
Culls reactions from the network based on their flow rates.
double getJacobianMatrixEntry(const int i_culled, const int j_culled) const override
Gets an entry from the Jacobian matrix for the active species.
DynamicEngine & m_baseEngine
The underlying engine to which this view delegates calculations.
std::expected< std::unordered_map< fourdst::atomic::Species, double >, expectations::StaleEngineError > getSpeciesTimescales(const std::vector< double > &Y_culled, double T9, double rho) const override
Computes timescales for all active species in the network.
std::pair< std::unordered_set< const reaction::LogicalReaction * >, std::unordered_set< fourdst::atomic::Species > > RescueSet
std::expected< std::unordered_map< fourdst::atomic::Species, double >, expectations::StaleEngineError > getSpeciesDestructionTimescales(const std::vector< double > &Y, double T9, double rho) const override
fourdst::logging::LogManager LogManager
std::vector< size_t > m_speciesIndexMap
A map from the indices of the active species to the indices of the corresponding species in the full ...
bool m_isStale
A flag indicating whether the view is stale and needs to be updated.
int getStoichiometryMatrixEntry(const int speciesIndex_culled, const int reactionIndex_culled) const override
Gets an entry from the stoichiometry matrix for the active species and reactions.
std::vector< double > mapCulledToFull(const std::vector< double > &culled) const
Maps a vector of culled abundances to a vector of full abundances.
PrimingReport primeEngine(const NetIn &netIn) override
void setNetworkReactions(const reaction::LogicalReactionSet &reactions) override
std::vector< double > mapNetInToMolarAbundanceVector(const NetIn &netIn) const override
RescueSet rescueEdgeSpeciesDestructionChannel(const std::vector< double > &Y_full, const double T9, const double rho, const std::vector< fourdst::atomic::Species > &activeSpecies, const reaction::LogicalReactionSet &activeReactions) const
std::vector< size_t > constructReactionIndexMap() const
Constructs the reaction index map.
std::vector< size_t > constructSpeciesIndexMap() const
Constructs the species index map.
int getSpeciesIndex(const fourdst::atomic::Species &species) const override
size_t mapCulledToFullReactionIndex(size_t culledReactionIndex) const
Maps a culled reaction index to a full reaction index.
void finalizeActiveSet(const std::vector< const reaction::LogicalReaction * > &finalReactions)
Finalizes the set of active species and reactions.
void setScreeningModel(screening::ScreeningType model) override
Sets the screening model for the base engine.
std::vector< ReactionFlow > calculateAllReactionFlows(const NetIn &netIn, std::vector< double > &out_Y_Full) const
Calculates the molar reaction flow rate for all reactions in the full network.
quill::Logger * m_logger
A pointer to the logger instance, used for logging messages.
const std::vector< fourdst::atomic::Species > & getNetworkSpecies() const override
Gets the list of active species in the network.
bool isStale(const NetIn &netIn) override
AdaptiveEngineView(DynamicEngine &baseEngine)
Constructs an AdaptiveEngineView.
void validateState() const
Validates that the AdaptiveEngineView is not stale.
const DynamicEngine & getBaseEngine() const override
Gets the base engine.
std::vector< fourdst::atomic::Species > m_activeSpecies
The set of species that are currently active in the network.
std::expected< StepDerivatives< double >, expectations::StaleEngineError > calculateRHSAndEnergy(const std::vector< double > &Y_culled, const double T9, const double rho) const override
Calculates the right-hand side (dY/dt) and energy generation for the active species.
fourdst::config::Config Config
Abstract class for engines supporting Jacobian and stoichiometry operations.
Abstract base class for a "view" of a reaction network engine.
Represents a "logical" reaction that aggregates rates from multiple sources.
Definition reaction.h:310
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.
A struct to hold a reaction and its flow rate.
const reaction::LogicalReaction * reactionPtr
Captures the result of a network priming operation.
Definition reporting.h:67