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
12#include "quill/Logger.h"
13
14namespace gridfire {
47 class AdaptiveEngineView final : public DynamicEngine, public EngineView<DynamicEngine> {
48 public:
57 explicit AdaptiveEngineView(DynamicEngine& baseEngine);
58
76 void update(const NetIn& netIn) override;
77
82 [[nodiscard]] const std::vector<fourdst::atomic::Species>& getNetworkSpecies() const override;
83
101 const std::vector<double> &Y_culled,
102 const double T9,
103 const double rho
104 ) const override;
105
120 const std::vector<double> &Y_culled,
121 const double T9,
122 const double rho
123 ) override;
124
139 [[nodiscard]] double getJacobianMatrixEntry(
140 const int i_culled,
141 const int j_culled
142 ) const override;
143
153 void generateStoichiometryMatrix() override;
154
169 [[nodiscard]] int getStoichiometryMatrixEntry(
170 const int speciesIndex_culled,
171 const int reactionIndex_culled
172 ) const override;
173
189 [[nodiscard]] double calculateMolarReactionFlow(
191 const std::vector<double> &Y_culled,
192 double T9,
193 double rho
194 ) const override;
195
201 [[nodiscard]] const reaction::LogicalReactionSet& getNetworkReactions() const override;
202
216 [[nodiscard]] std::unordered_map<fourdst::atomic::Species, double> getSpeciesTimescales(
217 const std::vector<double> &Y_culled,
218 double T9,
219 double rho
220 ) const override;
221
226 [[nodiscard]] const DynamicEngine& getBaseEngine() const override { return m_baseEngine; }
227
228 void setScreeningModel(screening::ScreeningType model) override;
229
230 [[nodiscard]] screening::ScreeningType getScreeningModel() const override;
231 private:
232 using Config = fourdst::config::Config;
233 using LogManager = fourdst::logging::LogManager;
234 Config& m_config = Config::getInstance();
235 quill::Logger* m_logger = LogManager::getInstance().getLogger("log");
236
238
239 std::vector<fourdst::atomic::Species> m_activeSpecies;
241
242 std::vector<size_t> m_speciesIndexMap;
243 std::vector<size_t> m_reactionIndexMap;
244
245 bool m_isStale = true;
246
247 private:
255 private:
266 [[nodiscard]] std::vector<size_t> constructSpeciesIndexMap() const;
267
278 [[nodiscard]] std::vector<size_t> constructReactionIndexMap() const;
279
287 [[nodiscard]] std::vector<double> mapCulledToFull(const std::vector<double>& culled) const;
288
296 [[nodiscard]] std::vector<double> mapFullToCulled(const std::vector<double>& full) const;
297
306 [[nodiscard]] size_t mapCulledToFullSpeciesIndex(size_t culledSpeciesIndex) const;
307
316 [[nodiscard]] size_t mapCulledToFullReactionIndex(size_t culledReactionIndex) const;
317
323 void validateState() const;
324
325 std::vector<ReactionFlow> calculateAllReactionFlows(
326 const NetIn& netIn,
327 std::vector<double>& out_Y_Full
328 ) const;
329 [[nodiscard]] std::unordered_set<fourdst::atomic::Species> findReachableSpecies(
330 const NetIn& netIn
331 ) const;
332 [[nodiscard]] std::vector<const reaction::LogicalReaction*> cullReactionsByFlow(
333 const std::vector<ReactionFlow>& allFlows,
334 const std::unordered_set<fourdst::atomic::Species>& reachableSpecies,
335 const std::vector<double>& Y_full,
336 double maxFlow
337 ) const;
339 const std::vector<const reaction::LogicalReaction*>& finalReactions
340 );
341 };
342}
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
std::unordered_set< fourdst::atomic::Species > findReachableSpecies(const NetIn &netIn) const
const reaction::LogicalReactionSet & getNetworkReactions() const override
Gets the set of active logical reactions in the network.
reaction::LogicalReactionSet m_activeReactions
std::vector< size_t > m_reactionIndexMap
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.
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
double getJacobianMatrixEntry(const int i_culled, const int j_culled) const override
Gets an entry from the Jacobian matrix for the active species.
fourdst::logging::LogManager LogManager
std::vector< size_t > m_speciesIndexMap
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.
StepDerivatives< double > 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.
void update(const NetIn &netIn) override
Updates the active species and reactions based on the current conditions.
std::vector< size_t > constructReactionIndexMap() const
Constructs the reaction index map.
std::vector< size_t > constructSpeciesIndexMap() const
Constructs the species index map.
size_t mapCulledToFullReactionIndex(size_t culledReactionIndex) const
Maps a culled reaction index to a full reaction index.
std::unordered_map< fourdst::atomic::Species, double > getSpeciesTimescales(const std::vector< double > &Y_culled, double T9, double rho) const override
Computes timescales for all active species in the network.
void finalizeActiveSet(const std::vector< const reaction::LogicalReaction * > &finalReactions)
void setScreeningModel(screening::ScreeningType model) override
std::vector< ReactionFlow > calculateAllReactionFlows(const NetIn &netIn, std::vector< double > &out_Y_Full) const
const std::vector< fourdst::atomic::Species > & getNetworkSpecies() const override
Gets the list of active species in the network.
void generateJacobianMatrix(const std::vector< double > &Y_culled, const double T9, const double rho) override
Generates the Jacobian matrix for the active species.
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
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:308
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
A struct to hold a reaction and its flow rate.
const reaction::LogicalReaction * reactionPtr
Structure holding derivatives and energy generation for a network step.