GridFire 0.0.1a
General Purpose Nuclear Network
Loading...
Searching...
No Matches
solver.h
Go to the documentation of this file.
1#pragma once
2
6#include "gridfire/network.h"
7
8#include "fourdst/logging/logging.h"
9#include "fourdst/config/config.h"
10
11#include "quill/Logger.h"
12
13#include <vector>
14
26 template <typename EngineT>
28 public:
33 explicit NetworkSolverStrategy(EngineT& engine) : m_engine(engine) {};
34
38 virtual ~NetworkSolverStrategy() = default;
39
45 virtual NetOut evaluate(const NetIn& netIn) = 0;
46 protected:
47 EngineT& m_engine;
48 };
49
54
66 public:
71 using DynamicNetworkSolverStrategy::DynamicNetworkSolverStrategy;
72
78 NetOut evaluate(const NetIn& netIn) override;
79 private:
88 struct RHSManager {
90 const double m_T9;
91 const double m_rho;
92
93 mutable double m_cached_time;
94 mutable std::optional<StepDerivatives<double>> m_cached_result;
95
96 mutable double m_last_observed_time = 0.0;
97
98
99 quill::Logger* m_logger = LogManager::getInstance().newFileLogger("integration.log", "GridFire");
100 mutable int m_num_steps = 0;
101 mutable double m_last_step_time = 1e-20;
102
110 DynamicEngine& engine,
111 const double T9,
112 const double rho
113 ) :
114 m_engine(engine),
115 m_T9(T9),
116 m_rho(rho),
117 m_cached_time(0) {}
118
125 void operator()(
126 const boost::numeric::ublas::vector<double>& Y,
127 boost::numeric::ublas::vector<double>& dYdt,
128 double t
129 ) const;
130
131 void observe(const boost::numeric::ublas::vector<double>& state, double t) const;
132 void compute_and_cache(const boost::numeric::ublas::vector<double>& state, double t) const;
133
134 };
135
145 const double m_T9;
146 const double m_rho;
147
155 DynamicEngine& engine,
156 const double T9,
157 const double rho
158 ) :
159 m_engine(engine),
160 m_T9(T9),
161 m_rho(rho) {}
162
170 void operator()(
171 const boost::numeric::ublas::vector<double>& Y,
172 boost::numeric::ublas::matrix<double>& J,
173 double t,
174 boost::numeric::ublas::vector<double>& dfdt
175 ) const;
176
177 };
178
179 private:
180 quill::Logger* m_logger = LogManager::getInstance().getLogger("log");
181 Config& m_config = Config::getInstance();
182 };
183}
Abstract class for engines supporting Jacobian and stoichiometry operations.
A network solver that directly integrates the reaction network ODEs.
Definition solver.h:65
quill::Logger * m_logger
Logger instance.
Definition solver.h:180
NetOut evaluate(const NetIn &netIn) override
Evaluates the network for a given timestep using direct integration.
Definition solver.cpp:22
Config & m_config
Configuration instance.
Definition solver.h:181
Abstract base class for network solver strategies.
Definition solver.h:27
NetworkSolverStrategy(EngineT &engine)
Constructor for the NetworkSolverStrategy.
Definition solver.h:33
virtual ~NetworkSolverStrategy()=default
Virtual destructor.
virtual NetOut evaluate(const NetIn &netIn)=0
Evaluates the network for a given timestep.
Abstract interfaces for reaction network engines in GridFire.
NetworkSolverStrategy< DynamicEngine > DynamicNetworkSolverStrategy
Type alias for a network solver strategy that uses a DynamicEngine.
Definition solver.h:53
DynamicEngine & m_engine
The engine used to evaluate the network.
Definition solver.h:144
const double m_T9
Temperature in units of 10^9 K.
Definition solver.h:145
void operator()(const boost::numeric::ublas::vector< double > &Y, boost::numeric::ublas::matrix< double > &J, double t, boost::numeric::ublas::vector< double > &dfdt) const
Calculates the Jacobian matrix.
Definition solver.cpp:215
JacobianFunctor(DynamicEngine &engine, const double T9, const double rho)
Constructor for the JacobianFunctor.
Definition solver.h:154
DynamicEngine & m_engine
The engine used to evaluate the network.
Definition solver.h:89
void observe(const boost::numeric::ublas::vector< double > &state, double t) const
Definition solver.cpp:167
const double m_T9
Temperature in units of 10^9 K.
Definition solver.h:90
double m_last_observed_time
Last time the state was observed.
Definition solver.h:96
void compute_and_cache(const boost::numeric::ublas::vector< double > &state, double t) const
Definition solver.cpp:189
quill::Logger * m_logger
Logger instance.
Definition solver.h:99
const double m_rho
Density in g/cm^3.
Definition solver.h:91
std::optional< StepDerivatives< double > > m_cached_result
Definition solver.h:94
void operator()(const boost::numeric::ublas::vector< double > &Y, boost::numeric::ublas::vector< double > &dYdt, double t) const
Calculates the time derivatives of the species abundances.
Definition solver.cpp:152
RHSManager(DynamicEngine &engine, const double T9, const double rho)
Constructor for the RHSFunctor.
Definition solver.h:109