GridFire 0.0.1a General Purpose Nuclear Network

Loading...
Searching...
No Matches
engine_abstract.h
Go to the documentation of this file.
1#pragma once
2
3#include "gridfire/reaction/reaction.h"
4#include "gridfire/network.h"
5#include "gridfire/screening/screening_abstract.h"
6#include "gridfire/screening/screening_types.h"
7
8#include "gridfire/engine/types/reporting.h"
9#include "gridfire/engine/types/building.h"
10
11#include "gridfire/expectations/expected_engine.h"
12
13#include <vector>
14#include <unordered_map>
15#include <utility>
16#include <expected>
17
30
31 namespace gridfire {
32
39 template<typename T>
40 concept IsArithmeticOrAD = std::is_same_v<T, double> || std::is_same_v<T, CppAD::AD<double>>;
41
59 template <IsArithmeticOrAD T>
60 struct StepDerivatives {
61 std::vector<T> dydt;
62 T nuclearEnergyGenerationRate = T(0.0);
63 };
64
65 using SparsityPattern = std::vector<std::pair<size_t, size_t>>;
66
84 class Engine {
85 public:
89 virtual ~Engine() = default;
90
95 [[nodiscard]] virtual const std::vector<fourdst::atomic::Species>& getNetworkSpecies() const = 0;
96
109 [[nodiscard]] virtual std::expected<StepDerivatives<double>, expectations::StaleEngineError> calculateRHSAndEnergy(
110 const std::vector<double>& Y,
111 double T9,
112 double rho
113 ) const = 0;
114 };
115
130 class DynamicEngine : public Engine {
131 public:
142 virtual void generateJacobianMatrix(
143 const std::vector<double>& Y_dynamic,
144 double T9,
145 double rho
146 ) const = 0;
147
148 virtual void generateJacobianMatrix(
149 const std::vector<double>& Y_dynamic,
150 double T9,
151 double rho,
152 const SparsityPattern& sparsityPattern
153 ) const {
154 throw std::logic_error("Sparsity pattern not supported by this engine.");
155 }
156
166 [[nodiscard]] virtual double getJacobianMatrixEntry(
167 int i,
168 int j
169 ) const = 0;
170
171
178 virtual void generateStoichiometryMatrix() = 0;
179
189 [[nodiscard]] virtual int getStoichiometryMatrixEntry(
190 int speciesIndex,
191 int reactionIndex
192 ) const = 0;
193
206 [[nodiscard]] virtual double calculateMolarReactionFlow(
207 const reaction::Reaction& reaction,
208 const std::vector<double>& Y,
209 double T9,
210 double rho
211 ) const = 0;
212
218 [[nodiscard]] virtual const reaction::LogicalReactionSet& getNetworkReactions() const = 0;
219
220 virtual void setNetworkReactions(const reaction::LogicalReactionSet& reactions) = 0;
221
233 [[nodiscard]] virtual std::expected<std::unordered_map<fourdst::atomic::Species, double>, expectations::StaleEngineError> getSpeciesTimescales(
234 const std::vector<double>& Y,
235 double T9,
236 double rho
237 ) const = 0;
238
239 [[nodiscard]] virtual std::expected<std::unordered_map<fourdst::atomic::Species, double>, expectations::StaleEngineError> getSpeciesDestructionTimescales(
240 const std::vector<double>& Y,
241 double T9,
242 double rho
243 ) const = 0;
244
265 virtual fourdst::composition::Composition update(const NetIn &netIn) = 0;
266
267 virtual bool isStale(const NetIn& netIn) = 0;
268
285 virtual void setScreeningModel(screening::ScreeningType model) = 0;
286
297 [[nodiscard]] virtual screening::ScreeningType getScreeningModel() const = 0;
298
299 [[nodiscard]] virtual int getSpeciesIndex(const fourdst::atomic::Species &species) const = 0;
300
301 [[nodiscard]] virtual std::vector<double> mapNetInToMolarAbundanceVector(const NetIn &netIn) const = 0;
302
303 [[nodiscard]] virtual PrimingReport primeEngine(const NetIn &netIn) = 0;
304
305 [[nodiscard]] virtual BuildDepthType getDepth() const {
306 throw std::logic_error("Network depth not supported by this engine.");
307 }
308
309 virtual void rebuild(const fourdst::composition::Composition& comp, BuildDepthType depth) {
310 throw std::logic_error("Setting network depth not supported by this engine.");
311 }
312
313 };
314}
building.h
gridfire::DynamicEngine
Abstract class for engines supporting Jacobian and stoichiometry operations.
Definition engine_abstract.h:130
gridfire::DynamicEngine::getDepth
virtual BuildDepthType getDepth() const
Definition engine_abstract.h:305
gridfire::DynamicEngine::getJacobianMatrixEntry
virtual double getJacobianMatrixEntry(int i, int j) const =0
Get an entry from the previously generated Jacobian matrix.
gridfire::DynamicEngine::primeEngine
virtual PrimingReport primeEngine(const NetIn &netIn)=0
gridfire::DynamicEngine::generateJacobianMatrix
virtual void generateJacobianMatrix(const std::vector< double > &Y_dynamic, double T9, double rho) const =0
Generate the Jacobian matrix for the current state.
gridfire::DynamicEngine::setScreeningModel
virtual void setScreeningModel(screening::ScreeningType model)=0
Set the electron screening model.
gridfire::DynamicEngine::rebuild
virtual void rebuild(const fourdst::composition::Composition &comp, BuildDepthType depth)
Definition engine_abstract.h:309
gridfire::DynamicEngine::mapNetInToMolarAbundanceVector
virtual std::vector< double > mapNetInToMolarAbundanceVector(const NetIn &netIn) const =0
gridfire::DynamicEngine::calculateMolarReactionFlow
virtual double calculateMolarReactionFlow(const reaction::Reaction &reaction, const std::vector< double > &Y, double T9, double rho) const =0
Calculate the molar reaction flow for a given reaction.
gridfire::DynamicEngine::getSpeciesTimescales
virtual std::expected< std::unordered_map< fourdst::atomic::Species, double >, expectations::StaleEngineError > getSpeciesTimescales(const std::vector< double > &Y, double T9, double rho) const =0
Compute timescales for all species in the network.
gridfire::DynamicEngine::getSpeciesDestructionTimescales
virtual std::expected< std::unordered_map< fourdst::atomic::Species, double >, expectations::StaleEngineError > getSpeciesDestructionTimescales(const std::vector< double > &Y, double T9, double rho) const =0
gridfire::DynamicEngine::getScreeningModel
virtual screening::ScreeningType getScreeningModel() const =0
Get the current electron screening model.
gridfire::DynamicEngine::generateJacobianMatrix
virtual void generateJacobianMatrix(const std::vector< double > &Y_dynamic, double T9, double rho, const SparsityPattern &sparsityPattern) const
Definition engine_abstract.h:148
gridfire::DynamicEngine::isStale
virtual bool isStale(const NetIn &netIn)=0
gridfire::DynamicEngine::update
virtual fourdst::composition::Composition update(const NetIn &netIn)=0
Update the internal state of the engine.
gridfire::DynamicEngine::getNetworkReactions
virtual const reaction::LogicalReactionSet & getNetworkReactions() const =0
Get the set of logical reactions in the network.
gridfire::DynamicEngine::getSpeciesIndex
virtual int getSpeciesIndex(const fourdst::atomic::Species &species) const =0
gridfire::DynamicEngine::generateStoichiometryMatrix
virtual void generateStoichiometryMatrix()=0
Generate the stoichiometry matrix for the network.
gridfire::DynamicEngine::getStoichiometryMatrixEntry
virtual int getStoichiometryMatrixEntry(int speciesIndex, int reactionIndex) const =0
Get an entry from the stoichiometry matrix.
gridfire::DynamicEngine::setNetworkReactions
virtual void setNetworkReactions(const reaction::LogicalReactionSet &reactions)=0
gridfire::Engine
Abstract base class for a reaction network engine.
Definition engine_abstract.h:84
gridfire::Engine::getNetworkSpecies
virtual const std::vector< fourdst::atomic::Species > & getNetworkSpecies() const =0
Get the list of species in the network.
gridfire::Engine::~Engine
virtual ~Engine()=default
Virtual destructor.
gridfire::Engine::calculateRHSAndEnergy
virtual std::expected< StepDerivatives< double >, expectations::StaleEngineError > calculateRHSAndEnergy(const std::vector< double > &Y, double T9, double rho) const =0
Calculate the right-hand side (dY/dt) and energy generation.
gridfire::reaction::Reaction
Represents a single nuclear reaction from a specific data source.
Definition reaction.h:72
gridfire::IsArithmeticOrAD
Concept for types allowed in engine calculations.
Definition engine_abstract.h:40
expected_engine.h
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
gridfire::BuildDepthType
std::variant< NetworkBuildDepth, int > BuildDepthType
Variant specifying either a predefined NetworkBuildDepth or a custom integer depth.
Definition building.h:37
gridfire::SparsityPattern
std::vector< std::pair< size_t, size_t > > SparsityPattern
Definition engine_abstract.h:65
network.h
reaction.h
Defines classes for representing and managing nuclear reactions.
reporting.h
screening_abstract.h
screening_types.h
gridfire::NetIn
Definition network.h:53
gridfire::PrimingReport
Captures the result of a network priming operation.
Definition reporting.h:67
gridfire::StepDerivatives
Structure holding derivatives and energy generation for a network step.
Definition engine_abstract.h:60
gridfire::StepDerivatives::nuclearEnergyGenerationRate
T nuclearEnergyGenerationRate
Specific energy generation rate (e.g., erg/g/s).
Definition engine_abstract.h:62
gridfire::StepDerivatives::dydt
std::vector< T > dydt
Derivatives of abundances (dY/dt for each species).
Definition engine_abstract.h:61
gridfire::expectations::StaleEngineError
Definition expected_engine.h:44