GridFire 0.0.1a General Purpose Nuclear Network

Loading...
Searching...
No Matches
error_engine.h
Go to the documentation of this file.
1#pragma once
2
3#include <exception>
4#include <string>
5#include <iostream>
6
7 namespace gridfire::exceptions {
8 class EngineError : public std::exception {};
9
10 class StaleEngineTrigger final : public EngineError {
11 public:
12 struct state {
13 double m_T9;
14 double m_rho;
15 std::vector<double> m_Y;
16 double m_t;
17 int m_total_steps;
18 double m_eps_nuc;
19 };
20 explicit StaleEngineTrigger(const state &s)
21 : m_state(s) {}
22
23 const char* what() const noexcept override{
24 return "Engine reports stale state. This means that the caller should trigger a update of the engine state before continuing with the integration. If you as an end user are seeing this error, it is likely a bug in the code that should be reported. Please provide the input parameters and the context in which this error occurred. Thank you for your help!";
25 }
26
27 state getState() const {
28 return m_state;
29 }
30
31 size_t numSpecies() const {
32 return m_state.m_Y.size();
33 }
34
35 size_t totalSteps() const {
36 return m_state.m_total_steps;
37 }
38
39 double energy() const {
40 return m_state.m_eps_nuc;
41 }
42
43 double getMolarAbundance(const size_t index) const {
44 if (index > m_state.m_Y.size() - 1) {
45 throw std::out_of_range("Index out of bounds for molar abundance vector.");
46 }
47 return m_state.m_Y[index];
48 }
49
50 double temperature() const {
51 return m_state.m_T9 * 1e9; // Convert T9 back to Kelvin
52 }
53
54 double density() const {
55 return m_state.m_rho;
56 }
57 private:
58 state m_state;
59
60 };
61
62 class StaleEngineError final : public EngineError {
63 public:
64 explicit StaleEngineError(const std::string& message)
65 : m_message(message) {}
66
67 const char* what() const noexcept override {
68 return m_message.c_str();
69 }
70
71 private:
72 std::string m_message;
73 };
74
75 class FailedToPartitionEngineError final : public EngineError {
76 public:
77 explicit FailedToPartitionEngineError(const std::string& message)
78 : m_message(message) {}
79
80 const char* what() const noexcept override {
81 return m_message.c_str();
82 }
83 private:
84 std::string m_message;
85 };
86
87 class NetworkResizedError final : public EngineError {
88 public:
89 explicit NetworkResizedError(const std::string& message)
90 : m_message(message) {}
91
92 const char* what() const noexcept override {
93 return m_message.c_str();
94 }
95 private:
96 std::string m_message;
97 };
98
99 class UnableToSetNetworkReactionsError final : public EngineError {
100 public:
101 explicit UnableToSetNetworkReactionsError(const std::string& message)
102 : m_message(message) {}
103
104 const char* what() const noexcept override {
105 return m_message.c_str();
106 }
107
108 private:
109 std::string m_message;
110 };
111
112}
gridfire::exceptions::EngineError
Definition error_engine.h:8
gridfire::exceptions::FailedToPartitionEngineError::m_message
std::string m_message
Definition error_engine.h:84
gridfire::exceptions::FailedToPartitionEngineError::FailedToPartitionEngineError
FailedToPartitionEngineError(const std::string &message)
Definition error_engine.h:77
gridfire::exceptions::FailedToPartitionEngineError::what
const char * what() const noexcept override
Definition error_engine.h:80
gridfire::exceptions::NetworkResizedError::m_message
std::string m_message
Definition error_engine.h:96
gridfire::exceptions::NetworkResizedError::NetworkResizedError
NetworkResizedError(const std::string &message)
Definition error_engine.h:89
gridfire::exceptions::NetworkResizedError::what
const char * what() const noexcept override
Definition error_engine.h:92
gridfire::exceptions::StaleEngineError::what
const char * what() const noexcept override
Definition error_engine.h:67
gridfire::exceptions::StaleEngineError::m_message
std::string m_message
Definition error_engine.h:72
gridfire::exceptions::StaleEngineError::StaleEngineError
StaleEngineError(const std::string &message)
Definition error_engine.h:64
gridfire::exceptions::StaleEngineTrigger::getState
state getState() const
Definition error_engine.h:27
gridfire::exceptions::StaleEngineTrigger::totalSteps
size_t totalSteps() const
Definition error_engine.h:35
gridfire::exceptions::StaleEngineTrigger::temperature
double temperature() const
Definition error_engine.h:50
gridfire::exceptions::StaleEngineTrigger::getMolarAbundance
double getMolarAbundance(const size_t index) const
Definition error_engine.h:43
gridfire::exceptions::StaleEngineTrigger::numSpecies
size_t numSpecies() const
Definition error_engine.h:31
gridfire::exceptions::StaleEngineTrigger::m_state
state m_state
Definition error_engine.h:58
gridfire::exceptions::StaleEngineTrigger::what
const char * what() const noexcept override
Definition error_engine.h:23
gridfire::exceptions::StaleEngineTrigger::density
double density() const
Definition error_engine.h:54
gridfire::exceptions::StaleEngineTrigger::energy
double energy() const
Definition error_engine.h:39
gridfire::exceptions::StaleEngineTrigger::StaleEngineTrigger
StaleEngineTrigger(const state &s)
Definition error_engine.h:20
gridfire::exceptions::UnableToSetNetworkReactionsError::what
const char * what() const noexcept override
Definition error_engine.h:104
gridfire::exceptions::UnableToSetNetworkReactionsError::UnableToSetNetworkReactionsError
UnableToSetNetworkReactionsError(const std::string &message)
Definition error_engine.h:101
gridfire::exceptions::UnableToSetNetworkReactionsError::m_message
std::string m_message
Definition error_engine.h:109
gridfire::exceptions
Definition error_engine.h:7
gridfire::exceptions::StaleEngineTrigger::state
Definition error_engine.h:12
gridfire::exceptions::StaleEngineTrigger::state::m_eps_nuc
double m_eps_nuc
Definition error_engine.h:18
gridfire::exceptions::StaleEngineTrigger::state::m_t
double m_t
Definition error_engine.h:16
gridfire::exceptions::StaleEngineTrigger::state::m_T9
double m_T9
Definition error_engine.h:13
gridfire::exceptions::StaleEngineTrigger::state::m_Y
std::vector< double > m_Y
Definition error_engine.h:15
gridfire::exceptions::StaleEngineTrigger::state::m_rho
double m_rho
Definition error_engine.h:14
gridfire::exceptions::StaleEngineTrigger::state::m_total_steps
int m_total_steps
Definition error_engine.h:17