Loading...
Searching...
No Matches
solver.h
Go to the documentation of this file.
#pragma once
#include "gridfire/engine/engine_graph.h"
#include "gridfire/engine/engine_abstract.h"
#include "../engine/views/engine_adaptive.h"
#include "gridfire/network.h"
#include "fourdst/logging/logging.h"
#include "fourdst/config/config.h"
#include "quill/Logger.h"
#include <vector>
namespace gridfire::solver {
template <typename EngineT>
class NetworkSolverStrategy {
public:
explicit NetworkSolverStrategy(EngineT& engine) : m_engine(engine) {};
virtual ~NetworkSolverStrategy() = default;
virtual NetOut evaluate(const NetIn& netIn) = 0;
protected:
EngineT& m_engine;
};
using DynamicNetworkSolverStrategy = NetworkSolverStrategy<DynamicEngine>;
class DirectNetworkSolver final : public DynamicNetworkSolverStrategy {
public:
using DynamicNetworkSolverStrategy::DynamicNetworkSolverStrategy;
NetOut evaluate(const NetIn& netIn) override;
private:
struct RHSManager {
DynamicEngine& m_engine;
const double m_T9;
const double m_rho;
mutable double m_cached_time;
mutable std::optional<StepDerivatives<double>> m_cached_result;
mutable double m_last_observed_time = 0.0;
quill::Logger* m_logger = LogManager::getInstance().newFileLogger("integration.log", "GridFire");
mutable int m_num_steps = 0;
mutable double m_last_step_time = 1e-20;
RHSManager(
DynamicEngine& engine,
const double T9,
const double rho
) :
m_engine(engine),
m_T9(T9),
m_rho(rho),
m_cached_time(0) {}
void operator()(
const boost::numeric::ublas::vector<double>& Y,
boost::numeric::ublas::vector<double>& dYdt,
double t
) const;
void observe(const boost::numeric::ublas::vector<double>& state, double t) const;
void compute_and_cache(const boost::numeric::ublas::vector<double>& state, double t) const;
};
struct JacobianFunctor {
DynamicEngine& m_engine;
const double m_T9;
const double m_rho;
JacobianFunctor(
DynamicEngine& engine,
const double T9,
const double rho
) :
m_engine(engine),
m_T9(T9),
m_rho(rho) {}
void operator()(
const boost::numeric::ublas::vector<double>& Y,
boost::numeric::ublas::matrix<double>& J,
double t,
boost::numeric::ublas::vector<double>& dfdt
) const;
};
private:
quill::Logger* m_logger = LogManager::getInstance().getLogger("log");
Config& m_config = Config::getInstance();
};
}
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