diff --git a/src/main.cpp b/src/main.cpp index 960c137..b9c5ecb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,8 +3,10 @@ #include "reactor/control/control_rod.hpp" #include "reactor/fuel/fuel_rod.hpp" #include "reactor/coolant/pipe.hpp" +#include "reactor/coolant/vessel.hpp" #include "display.hpp" +#include #include #include #include @@ -18,33 +20,60 @@ int main() nodelay(stdscr, TRUE); curs_set(0); + sim::reactor::coolant::vessel vessel(100, 400); sim::reactor::reactor<5, 5> reactor = sim::reactor::builder<5, 5>( sim::reactor::fuel::fuel_rod(100, 400), - sim::reactor::control::control_rod(1000, 0.1), - sim::reactor::coolant::pipe(), { - " PPP ", - "PFCFP", - "PCPCP", - "PFCFP", - " PPP " + sim::reactor::control::control_rod(1000, 1), + sim::reactor::coolant::pipe(vessel), { + "## ##", + "#FCF#", + " C C ", + "#FCF#", + "## ##" }); double secs = 0; for(;;) { - reactor.update(0.01); std::stringstream ss; - ss << "Reactor Core: " << secs << " s\n"; + ss << "Reactor Core\n\n"; - secs += 0.01; + { + long mins = secs / 60; + double s = fmod(secs, 60); + + long hours = mins / 60; + mins %= 60; + + long days = hours / 24; + hours %= 24; + + long years = days / 365; + days %= 365; + + ss << "Time:\n"; + + if(years > 0) ss << years << "y "; + if(days > 0) ss << days << "d "; + if(hours > 0) ss << hours << "h "; + if(mins > 0) ss << mins << "m "; + + ss << s << "s\n\n"; + } + + reactor.update(1); + vessel.update(); + secs += 1; + + ss << "Vessel\n" << vessel << "\n"; erase(); display::draw_text(1, 0, ss.str().c_str()); - const int X = 3, Y = 4; - const int W = 32, H = 8; + const int X = 2, Y = 40; + const int W = 32, H = 10; for(int x = 0; x < reactor.width; x++) for(int y = 0; y < reactor.height; y++) diff --git a/src/reactor/builder.hpp b/src/reactor/builder.hpp index 64f1e6a..144ce1d 100644 --- a/src/reactor/builder.hpp +++ b/src/reactor/builder.hpp @@ -29,10 +29,10 @@ reactor builder(fuel::fuel_rod fr, control::control_rod cr, coolant::pipe case 'C': r = new control::control_rod(cr); break; - case 'P': + case ' ': r = new coolant::pipe(p); break; - default: + case '#': r = new rod(); } diff --git a/src/reactor/coolant/pipe.cpp b/src/reactor/coolant/pipe.cpp index 0dd6385..a5d6d63 100644 --- a/src/reactor/coolant/pipe.cpp +++ b/src/reactor/coolant/pipe.cpp @@ -3,26 +3,33 @@ using namespace sim::reactor::coolant; +pipe::pipe(coolant::vessel& v) +{ + this->vessel = &v; + this->steam = 0; +} + +void pipe::display(std::ostream& o) const +{ + o << "Steam: +" << steam << "\n"; +} + double pipe::get_k(val_t type) const { - switch(type) - { - case val_t::HEAT: - return 1.0 / 16.0; - case val_t::N_SLOW: - return 1.0 / 4.0; - case val_t::N_FAST: - return 1.0 / 2.0; - } - - return 0; + return vessel->get_level() / vessel->get_volume(); } void pipe::update(double secs) { + double v; + update_rod(); + + v = vessel->add_steam(vals[val_t::HEAT]); + steam = vals[val_t::HEAT] - v; + vals[val_t::HEAT] = v; - double v = vals[val_t::N_FAST]; + v = vals[val_t::N_FAST]; vals[val_t::N_FAST] -= v; vals[val_t::N_SLOW] += v; } diff --git a/src/reactor/coolant/pipe.hpp b/src/reactor/coolant/pipe.hpp index 7f24946..a06a186 100644 --- a/src/reactor/coolant/pipe.hpp +++ b/src/reactor/coolant/pipe.hpp @@ -1,6 +1,7 @@ #pragma once +#include "vessel.hpp" #include "../rod.hpp" namespace sim::reactor::coolant @@ -8,12 +9,18 @@ namespace sim::reactor::coolant class pipe : public sim::reactor::rod { + coolant::vessel* vessel; + double steam; + virtual double get_k(sim::reactor::rod::val_t type) const; virtual const char* get_name() const { return "Coolant"; } + virtual void display(std::ostream& o) const; public: + pipe(coolant::vessel& v); + virtual bool should_display() const { return true; } virtual void update(double secs); diff --git a/src/reactor/coolant/vessel.cpp b/src/reactor/coolant/vessel.cpp new file mode 100644 index 0000000..e7bbd7a --- /dev/null +++ b/src/reactor/coolant/vessel.cpp @@ -0,0 +1,43 @@ + +#include "vessel.hpp" + +using namespace sim::reactor::coolant; + +vessel::vessel(double level, double volume) +{ + this->level = level; + this->volume = volume; +} + +void vessel::update() +{ + level += level_in; + steam += steam_in; + level_in = 0; + steam_in = 0; +} + +double vessel::add_steam(double amount) +{ + double th = get_pressure(); + + if(amount > th) + { + amount -= th; + steam_in += amount; + level_in -= amount; + + return th; + } + + return amount; +} + +void vessel::display(std::ostream& o) const +{ + o << "Volume: " << volume << "\n"; + o << "Level: " << level << "\n"; + o << "Steam: " << steam << "\n"; + o << "Pressure: " << get_pressure() << "\n"; +} + diff --git a/src/reactor/coolant/vessel.hpp b/src/reactor/coolant/vessel.hpp new file mode 100644 index 0000000..dd0a321 --- /dev/null +++ b/src/reactor/coolant/vessel.hpp @@ -0,0 +1,40 @@ + +#pragma once + +#include + +namespace sim::reactor::coolant +{ + +class vessel +{ + double volume; + double level; + + double steam = 0; + double level_in = 0; + double steam_in = 0; + + void display(std::ostream& o) const; + +public: + + vessel(double level, double volume); + + void update(); + double add_steam(double amount); + + constexpr double get_volume() const { return volume; } + constexpr double get_level() const { return level; } + constexpr double get_steam() const { return steam; } + constexpr double get_pressure() const { return steam / (volume - level); } + + friend std::ostream& operator<<(std::ostream& o, const vessel& v) + { + v.display(o); + return o; + } +}; + +} + diff --git a/src/reactor/fuel/fuel_rod.cpp b/src/reactor/fuel/fuel_rod.cpp index 3dd2bb3..1eaae81 100644 --- a/src/reactor/fuel/fuel_rod.cpp +++ b/src/reactor/fuel/fuel_rod.cpp @@ -12,7 +12,7 @@ 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"; + o << "Energy: +" << s.get_energy() << "\n"; } double fuel_rod::get_k(val_t type) const @@ -36,7 +36,7 @@ void fuel_rod::update(double secs) s.add_slow_neutrons(vals[val_t::N_SLOW]); - vals[val_t::HEAT] += s.extract_energy() / s.get_mass(); + vals[val_t::HEAT] += s.extract_energy(); vals[val_t::N_FAST] += s.extract_fast_neutrons(); vals[val_t::N_SLOW] = 0; diff --git a/src/reactor/rod.hpp b/src/reactor/rod.hpp index 9840a0e..c6aafa7 100644 --- a/src/reactor/rod.hpp +++ b/src/reactor/rod.hpp @@ -38,7 +38,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";