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
3#include "gridfire/engine/engine_graph.h"
4#include "gridfire/engine/engine_abstract.h"
5#include "../engine/views/engine_adaptive.h"
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
15 namespace gridfire::solver {
26 template <typename EngineT>
27 class NetworkSolverStrategy {
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
53 using DynamicNetworkSolverStrategy = NetworkSolverStrategy<DynamicEngine>;
54
65 class DirectNetworkSolver final : public DynamicNetworkSolverStrategy {
66 public:
71 using DynamicNetworkSolverStrategy::DynamicNetworkSolverStrategy;
72
78 NetOut evaluate(const NetIn& netIn) override;
79 private:
88 struct RHSManager {
89 DynamicEngine& m_engine;
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
109 RHSManager(
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
143 struct JacobianFunctor {
144 DynamicEngine& m_engine;
145 const double m_T9;
146 const double m_rho;
147
154 JacobianFunctor(
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}
gridfire::DynamicEngine
Abstract class for engines supporting Jacobian and stoichiometry operations.
Definition engine_abstract.h:130
gridfire::solver::DirectNetworkSolver
A network solver that directly integrates the reaction network ODEs.
Definition solver.h:65
gridfire::solver::DirectNetworkSolver::m_logger
quill::Logger * m_logger
Logger instance.
Definition solver.h:180
gridfire::solver::DirectNetworkSolver::evaluate
NetOut evaluate(const NetIn &netIn) override
Evaluates the network for a given timestep using direct integration.
Definition solver.cpp:22
gridfire::solver::DirectNetworkSolver::m_config
Config & m_config
Configuration instance.
Definition solver.h:181
gridfire::solver::NetworkSolverStrategy
Abstract base class for network solver strategies.
Definition solver.h:27
gridfire::solver::NetworkSolverStrategy::NetworkSolverStrategy
NetworkSolverStrategy(EngineT &engine)
Constructor for the NetworkSolverStrategy.
Definition solver.h:33
gridfire::solver::NetworkSolverStrategy::~NetworkSolverStrategy
virtual ~NetworkSolverStrategy()=default
Virtual destructor.
gridfire::solver::NetworkSolverStrategy< DynamicEngine >::m_engine
DynamicEngine & m_engine
Definition solver.h:47
gridfire::solver::NetworkSolverStrategy::evaluate
virtual NetOut evaluate(const NetIn &netIn)=0
Evaluates the network for a given timestep.
engine_abstract.h
Abstract interfaces for reaction network engines in GridFire.
engine_adaptive.h
engine_graph.h
gridfire::solver
Definition solver.h:15
gridfire::solver::DynamicNetworkSolverStrategy
NetworkSolverStrategy< DynamicEngine > DynamicNetworkSolverStrategy
Type alias for a network solver strategy that uses a DynamicEngine.
Definition solver.h:53
network.h
gridfire::NetIn
Definition network.h:53
gridfire::NetOut
Definition network.h:65
gridfire::solver::DirectNetworkSolver::JacobianFunctor::m_engine
DynamicEngine & m_engine
The engine used to evaluate the network.
Definition solver.h:144
gridfire::solver::DirectNetworkSolver::JacobianFunctor::m_T9
const double m_T9
Temperature in units of 10^9 K.
Definition solver.h:145
gridfire::solver::DirectNetworkSolver::JacobianFunctor::m_rho
const double m_rho
Density in g/cm^3.
Definition solver.h:146
gridfire::solver::DirectNetworkSolver::JacobianFunctor::operator()
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
gridfire::solver::DirectNetworkSolver::JacobianFunctor::JacobianFunctor
JacobianFunctor(DynamicEngine &engine, const double T9, const double rho)
Constructor for the JacobianFunctor.
Definition solver.h:154
gridfire::solver::DirectNetworkSolver::RHSManager::m_engine
DynamicEngine & m_engine
The engine used to evaluate the network.
Definition solver.h:89
gridfire::solver::DirectNetworkSolver::RHSManager::m_cached_time
double m_cached_time
Definition solver.h:93
gridfire::solver::DirectNetworkSolver::RHSManager::observe
void observe(const boost::numeric::ublas::vector< double > &state, double t) const
Definition solver.cpp:167
gridfire::solver::DirectNetworkSolver::RHSManager::m_T9
const double m_T9
Temperature in units of 10^9 K.
Definition solver.h:90
gridfire::solver::DirectNetworkSolver::RHSManager::m_last_observed_time
double m_last_observed_time
Last time the state was observed.
Definition solver.h:96
gridfire::solver::DirectNetworkSolver::RHSManager::compute_and_cache
void compute_and_cache(const boost::numeric::ublas::vector< double > &state, double t) const
Definition solver.cpp:189
gridfire::solver::DirectNetworkSolver::RHSManager::m_last_step_time
double m_last_step_time
Definition solver.h:101
gridfire::solver::DirectNetworkSolver::RHSManager::m_logger
quill::Logger * m_logger
Logger instance.
Definition solver.h:99
gridfire::solver::DirectNetworkSolver::RHSManager::m_rho
const double m_rho
Density in g/cm^3.
Definition solver.h:91
gridfire::solver::DirectNetworkSolver::RHSManager::m_cached_result
std::optional< StepDerivatives< double > > m_cached_result
Definition solver.h:94
gridfire::solver::DirectNetworkSolver::RHSManager::m_num_steps
int m_num_steps
Definition solver.h:100
gridfire::solver::DirectNetworkSolver::RHSManager::operator()
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
gridfire::solver::DirectNetworkSolver::RHSManager::RHSManager
RHSManager(DynamicEngine &engine, const double T9, const double rho)
Constructor for the RHSFunctor.
Definition solver.h:109