From 4441aa3420794c4ad5a25646d8f2aab05b3a6711 Mon Sep 17 00:00:00 2001 From: Jay Robson Date: Mon, 15 Jan 2024 12:45:22 +1100 Subject: [PATCH] fixed math, improved display --- src/main.cpp | 8 +++++++- src/reactor/control/control_rod.hpp | 2 +- src/reactor/coolant/pipe.hpp | 3 ++- src/reactor/fuel/fuel_rod.hpp | 3 ++- src/reactor/rod.cpp | 4 +++- src/reactor/rod.hpp | 2 +- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ca2ed0a..960c137 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,8 +49,14 @@ int main() for(int x = 0; x < reactor.width; x++) for(int y = 0; y < reactor.height; y++) { - std::stringstream ss; sim::reactor::rod* r = reactor.rods[x][y]; + + if(!r->should_display()) + { + continue; + } + + std::stringstream ss; ss << *r; int px = X + (H - 1) * y; diff --git a/src/reactor/control/control_rod.hpp b/src/reactor/control/control_rod.hpp index 9d19ef6..d83c877 100644 --- a/src/reactor/control/control_rod.hpp +++ b/src/reactor/control/control_rod.hpp @@ -17,7 +17,6 @@ class control_rod : public sim::reactor::rod virtual void display(std::ostream& o) const; virtual const char* get_name() const { return "Control Rod"; } - virtual bool should_display() const { return true; } public: @@ -26,6 +25,7 @@ public: virtual void update(double secs); void set_reactivity(double a); + virtual bool should_display() const { return true; } virtual bool should_select() const { return true; } virtual void update_selected(double a); }; diff --git a/src/reactor/coolant/pipe.hpp b/src/reactor/coolant/pipe.hpp index b6a8ae5..7f24946 100644 --- a/src/reactor/coolant/pipe.hpp +++ b/src/reactor/coolant/pipe.hpp @@ -11,10 +11,11 @@ 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"; } - virtual bool should_display() const { return true; } public: + virtual bool should_display() const { return true; } + virtual void update(double secs); }; diff --git a/src/reactor/fuel/fuel_rod.hpp b/src/reactor/fuel/fuel_rod.hpp index 5f1d5b3..3c08b49 100644 --- a/src/reactor/fuel/fuel_rod.hpp +++ b/src/reactor/fuel/fuel_rod.hpp @@ -15,12 +15,13 @@ class fuel_rod : public sim::reactor::rod virtual void display(std::ostream& o) const; virtual const char* get_name() const { return "Fuel"; } - virtual bool should_display() const { return true; } public: fuel_rod(double fuel, double mass); + virtual bool should_display() const { return true; } + virtual void update(double secs); }; diff --git a/src/reactor/rod.cpp b/src/reactor/rod.cpp index b8390f5..847c041 100644 --- a/src/reactor/rod.cpp +++ b/src/reactor/rod.cpp @@ -1,6 +1,8 @@ #include "rod.hpp" +#include + using namespace sim::reactor; double rod::get(val_t type) const @@ -15,7 +17,7 @@ void rod::add(val_t type, double v) double rod::extract(val_t type, double k, double o) { - double v = k * get_k(type) * 0.5 * (get(type) - o); + double v = (1 - std::pow(0.5, k * get_k(type))) * 0.5 * (get(type) - o); vals_in[type] -= v; return v; } diff --git a/src/reactor/rod.hpp b/src/reactor/rod.hpp index a8aad26..9840a0e 100644 --- a/src/reactor/rod.hpp +++ b/src/reactor/rod.hpp @@ -25,6 +25,7 @@ public: virtual double extract(val_t type, double k, double o); virtual double get(val_t type) const; + virtual bool should_display() const { return false; } virtual bool should_select() const { return false; } virtual void update_selected(double a) { } @@ -53,7 +54,6 @@ protected: virtual void display(std::ostream& o) const { }; virtual double get_k(val_t type) const { return 0; } virtual const char* get_name() const { return "Empty"; } - virtual bool should_display() const { return false; } void update_rod(); };