Loading...
Searching...
No Matches
engine_abstract.h
Go to the documentation of this file.
#pragma once
#include "gridfire/reaction/reaction.h"
#include "gridfire/network.h"
#include "gridfire/screening/screening_abstract.h"
#include "gridfire/screening/screening_types.h"
#include "gridfire/engine/types/reporting.h"
#include "gridfire/engine/types/building.h"
#include "gridfire/expectations/expected_engine.h"
#include <vector>
#include <unordered_map>
#include <utility>
#include <expected>
namespace gridfire {
template<typename T>
concept IsArithmeticOrAD = std::is_same_v<T, double> || std::is_same_v<T, CppAD::AD<double>>;
template <IsArithmeticOrAD T>
struct StepDerivatives {
std::vector<T> dydt;
T nuclearEnergyGenerationRate = T(0.0);
};
using SparsityPattern = std::vector<std::pair<size_t, size_t>>;
class Engine {
public:
virtual ~Engine() = default;
[[nodiscard]] virtual const std::vector<fourdst::atomic::Species>& getNetworkSpecies() const = 0;
[[nodiscard]] virtual std::expected<StepDerivatives<double>, expectations::StaleEngineError> calculateRHSAndEnergy(
const std::vector<double>& Y,
double T9,
double rho
) const = 0;
};
class DynamicEngine : public Engine {
public:
virtual void generateJacobianMatrix(
const std::vector<double>& Y_dynamic,
double T9,
double rho
) const = 0;
virtual void generateJacobianMatrix(
const std::vector<double>& Y_dynamic,
double T9,
double rho,
const SparsityPattern& sparsityPattern
) const {
throw std::logic_error("Sparsity pattern not supported by this engine.");
}
[[nodiscard]] virtual double getJacobianMatrixEntry(
int i,
int j
) const = 0;
virtual void generateStoichiometryMatrix() = 0;
[[nodiscard]] virtual int getStoichiometryMatrixEntry(
int speciesIndex,
int reactionIndex
) const = 0;
[[nodiscard]] virtual double calculateMolarReactionFlow(
const reaction::Reaction& reaction,
const std::vector<double>& Y,
double T9,
double rho
) const = 0;
[[nodiscard]] virtual const reaction::LogicalReactionSet& getNetworkReactions() const = 0;
virtual void setNetworkReactions(const reaction::LogicalReactionSet& reactions) = 0;
[[nodiscard]] virtual std::expected<std::unordered_map<fourdst::atomic::Species, double>, expectations::StaleEngineError> getSpeciesTimescales(
const std::vector<double>& Y,
double T9,
double rho
) const = 0;
[[nodiscard]] virtual std::expected<std::unordered_map<fourdst::atomic::Species, double>, expectations::StaleEngineError> getSpeciesDestructionTimescales(
const std::vector<double>& Y,
double T9,
double rho
) const = 0;
virtual fourdst::composition::Composition update(const NetIn &netIn) = 0;
virtual bool isStale(const NetIn& netIn) = 0;
virtual void setScreeningModel(screening::ScreeningType model) = 0;
[[nodiscard]] virtual screening::ScreeningType getScreeningModel() const = 0;
[[nodiscard]] virtual int getSpeciesIndex(const fourdst::atomic::Species &species) const = 0;
[[nodiscard]] virtual std::vector<double> mapNetInToMolarAbundanceVector(const NetIn &netIn) const = 0;
[[nodiscard]] virtual PrimingReport primeEngine(const NetIn &netIn) = 0;
[[nodiscard]] virtual BuildDepthType getDepth() const {
throw std::logic_error("Network depth not supported by this engine.");
}
virtual void rebuild(const fourdst::composition::Composition& comp, BuildDepthType depth) {
throw std::logic_error("Setting network depth not supported by this engine.");
}
};
}
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