diff --git a/src/main.cpp b/src/main.cpp index e1415bb..ca2ed0a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,21 +20,28 @@ int main() sim::reactor::reactor<5, 5> reactor = sim::reactor::builder<5, 5>( sim::reactor::fuel::fuel_rod(100, 400), - sim::reactor::control::control_rod(1000), + sim::reactor::control::control_rod(1000, 0.1), sim::reactor::coolant::pipe(), { - " P ", - " FCF ", + " PPP ", + "PFCFP", "PCPCP", - " FCF ", - " P " + "PFCFP", + " PPP " }); + double secs = 0; + for(;;) { - reactor.update(1); + reactor.update(0.01); + + std::stringstream ss; + ss << "Reactor Core: " << secs << " s\n"; + + secs += 0.01; erase(); - display::draw_text(1, 0, "Reactor Core:"); + display::draw_text(1, 0, ss.str().c_str()); const int X = 3, Y = 4; const int W = 32, H = 8; @@ -76,10 +83,10 @@ int main() reactor.move_cursor(1); break; case KEY_UP: - reactor.update_selected(0.001); + reactor.update_selected(0.01); break; case KEY_DOWN: - reactor.update_selected(-0.001); + reactor.update_selected(-0.01); break; case ' ': reactor.toggle_selected(); diff --git a/src/reactor/control/control_rod.cpp b/src/reactor/control/control_rod.cpp index c735756..847240e 100644 --- a/src/reactor/control/control_rod.cpp +++ b/src/reactor/control/control_rod.cpp @@ -1,11 +1,14 @@ #include "control_rod.hpp" +#include + using namespace sim::reactor::control; -control_rod::control_rod(double limit) +control_rod::control_rod(double limit, double max) { this->limit = limit; + this->max = max; } void control_rod::display(std::ostream& o) const @@ -38,7 +41,7 @@ void control_rod::update(double secs) { update_rod(); - double m = (1 - absorbed / limit) * inserted; + double m = 1 - std::pow(0.5, (1 - absorbed / limit) * inserted * max); double r_fast = vals[val_t::N_FAST] * m; double r_slow = vals[val_t::N_SLOW] * m; diff --git a/src/reactor/control/control_rod.hpp b/src/reactor/control/control_rod.hpp index 9a7c39d..9d19ef6 100644 --- a/src/reactor/control/control_rod.hpp +++ b/src/reactor/control/control_rod.hpp @@ -11,6 +11,7 @@ class control_rod : public sim::reactor::rod double inserted = 1; double absorbed = 0; double limit; + double max; virtual double get_k(sim::reactor::rod::val_t type) const; virtual void display(std::ostream& o) const; @@ -20,7 +21,7 @@ class control_rod : public sim::reactor::rod public: - control_rod(double limit); + control_rod(double limit, double max); virtual void update(double secs); void set_reactivity(double a); diff --git a/src/reactor/coolant/pipe.hpp b/src/reactor/coolant/pipe.hpp index 13405a5..b6a8ae5 100644 --- a/src/reactor/coolant/pipe.hpp +++ b/src/reactor/coolant/pipe.hpp @@ -10,7 +10,7 @@ class pipe : public sim::reactor::rod { virtual double get_k(sim::reactor::rod::val_t type) const; - virtual const char* get_name() const { return "Coolant Pipe"; } + virtual const char* get_name() const { return "Coolant"; } virtual bool should_display() const { return true; } public: diff --git a/src/reactor/fuel/fuel_rod.cpp b/src/reactor/fuel/fuel_rod.cpp index b476fc8..3dd2bb3 100644 --- a/src/reactor/fuel/fuel_rod.cpp +++ b/src/reactor/fuel/fuel_rod.cpp @@ -11,6 +11,7 @@ fuel_rod::fuel_rod(double fuel, double mass) : s(fuel, mass) void fuel_rod::display(std::ostream& o) const { o << "Fuel: " << s.get_fuel() << " / " << s.get_mass() << "\n"; + o << "Efficiency: " << s.get_efficiency() << "\n"; o << "Energy: " << s.get_energy() << "\n"; } diff --git a/src/reactor/fuel/sample.cpp b/src/reactor/fuel/sample.cpp index b1aa35b..e6058bc 100644 --- a/src/reactor/fuel/sample.cpp +++ b/src/reactor/fuel/sample.cpp @@ -4,7 +4,6 @@ using namespace sim::reactor::fuel; -static const double Xe_135_M = 1e4; static const double NEUTRON_BG = 1e-10; sample::sample(double fuel, double mass) @@ -45,14 +44,28 @@ void sample::update(double secs) slow_neutrons = 0; // deal with these edge cases - if(neutrons_fuel > fuel) neutrons_fuel = fuel; - if(neutrons_xenon > xe_135) neutrons_xenon = xe_135; - if(neutrons_iodine > i_135) neutrons_iodine = i_135; + + if(neutrons_fuel > fuel) + { + slow_neutrons += neutrons_fuel - fuel; + neutrons_fuel = fuel; + } + + if(neutrons_xenon > xe_135) + { + slow_neutrons += neutrons_xenon - xe_135; + neutrons_xenon = xe_135; + } + + if(neutrons_iodine > i_135) + { + slow_neutrons += neutrons_iodine - i_135; + neutrons_iodine = i_135; + } // sim::reactor::fuelulate fuel use fuel -= neutrons_fuel; energy += neutrons_fuel; - fast_neutrons += neutrons_fuel * 3; waste.add_fissile(neutrons_fuel * 2); // do the poison @@ -61,11 +74,6 @@ void sample::update(double secs) i_135 -= neutrons_iodine; } -double sample::get_volume() const -{ - return mass + xe_135 * Xe_135_M; -} - double sample::extract_energy() { double v = energy; diff --git a/src/reactor/fuel/sample.hpp b/src/reactor/fuel/sample.hpp index 7b20a2c..4278319 100644 --- a/src/reactor/fuel/sample.hpp +++ b/src/reactor/fuel/sample.hpp @@ -10,6 +10,8 @@ namespace sim::reactor::fuel class sample { + constexpr static const double Xe_135_M = 1e3; + sim::reactor::fuel::waste waste; double fuel = 0; @@ -36,8 +38,8 @@ public: constexpr double get_fuel() const { return fuel; } constexpr double get_mass() const { return mass; } constexpr double get_energy() const { return energy; } - - double get_volume() const; + constexpr double get_volume() const { return mass + xe_135 * Xe_135_M; } + constexpr double get_efficiency() const { return fuel / get_volume(); } friend std::ostream& operator<<(std::ostream& o, const sample& s) { diff --git a/src/reactor/fuel/waste.cpp b/src/reactor/fuel/waste.cpp index 45178f5..7225895 100644 --- a/src/reactor/fuel/waste.cpp +++ b/src/reactor/fuel/waste.cpp @@ -4,10 +4,13 @@ using namespace sim::reactor::fuel; +static const double SLOWDOWN_M = 1.0 / 4.0; + void waste::update(double secs) { double hl = 1; - double next[waste::N - 1] = {0}; + double next_h[waste::N - 1] = {0}; + double next_l[waste::N - 1] = {0}; for(int i = 0; i < waste::N - 1; i++) { @@ -15,7 +18,8 @@ void waste::update(double secs) double h = high[i] * m; double l = low[i] * m; - next[i] += h + l; + next_h[i] += h * (1 - SLOWDOWN_M); + next_l[i] += l + h * SLOWDOWN_M; high[i] -= h; low[i] -= l; @@ -26,7 +30,8 @@ void waste::update(double secs) for(int i = 0; i < waste::N - 1; i++) { - low[i + 1] += next[i]; + high[i + 1] += next_h[i]; + low[i + 1] += next_l[i]; } } diff --git a/src/reactor/rod.hpp b/src/reactor/rod.hpp index 2590d3d..a8aad26 100644 --- a/src/reactor/rod.hpp +++ b/src/reactor/rod.hpp @@ -37,7 +37,7 @@ public: o << r.get_name() << "\n"; r.display(o); - o << "Heat: " << r.get(val_t::HEAT) << "\n"; +// o << "Heat: " << r.get(val_t::HEAT) << "\n"; o << "Fast: " << r.get(val_t::N_FAST) << "\n"; o << "Slow: " << r.get(val_t::N_SLOW) << "\n";