diff --git a/src/coolant/pump.hpp b/src/coolant/pump.hpp new file mode 100644 index 0000000..a1f928c --- /dev/null +++ b/src/coolant/pump.hpp @@ -0,0 +1,57 @@ + +#pragma once + +#include + +namespace sim::coolant +{ + +template +class pump +{ + const double max; + const double heat; + + A* a; + double rate = 0; + +public: + + constexpr pump(A& a, double max, double heat) : a(&a), max(max), heat(heat) + { + + } + + constexpr double get_rate() const + { + return rate; + } + + constexpr double get_flow() const + { + return rate * max; + } + + constexpr void change_speed(double amount) + { + rate += amount; + + if(rate < 0) rate = 0; + if(rate > 1) rate = 1; + } + + void update(double secs) + { + a->add_fluid(rate * max * secs, heat); + } + + friend std::ostream& operator<<(std::ostream& o, const pump& p) + { + o << "Rate: " << (p.get_rate() * 100) << " %\n"; + o << "Flow: " << (p.get_flow() * 0.001) << " kg/s\n"; + return o; + } +}; + +}; + diff --git a/src/main.cpp b/src/main.cpp index 691bdbf..498291c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,6 +7,7 @@ #include "reactor/coolant/vessel.hpp" #include "coolant/fluid_t.hpp" #include "coolant/valve.hpp" +#include "coolant/pump.hpp" #include "display.hpp" #include @@ -52,7 +53,8 @@ int main() "#C#C#" }); - sim::coolant::valve valve(vessel, 1, 101000); + sim::coolant::valve valve(vessel, 1, 500); + sim::coolant::pump pump(vessel, 1e4, 15); double secs = 0; long clock = get_now(); @@ -97,13 +99,15 @@ secs: ss << s << "s\n"; { double dt = speed / framerate / steps_extra; reactor.update(rand, dt); - vessel.update(); + pump.update(dt); valve.update(dt); + vessel.update(); secs += dt; } ss << "Vessel\n" << vessel << "\n"; ss << "Steam Valve\n" << valve << "\n"; + ss << "Coolant Pump\n" << pump << "\n"; if(do_graphics) { @@ -185,6 +189,12 @@ secs: ss << s << "s\n"; case 'f': valve.open(-0.001); break; + case 'e': + pump.change_speed(0.01); + break; + case 'd': + pump.change_speed(-0.01); + break; } if(do_clock) diff --git a/src/reactor/coolant/vessel.cpp b/src/reactor/coolant/vessel.cpp index 0c154a7..0e83547 100644 --- a/src/reactor/coolant/vessel.cpp +++ b/src/reactor/coolant/vessel.cpp @@ -52,13 +52,31 @@ double vessel::add_heat(double t1) { double t2 = get_heat(); double t = t1 - t2; - double m1 = 1000000; + double m1 = 1e6; double m2 = (fluid.l_to_g(level) + steam) * fluid.jPgk; double m = m1 + m2; return heat = t1 - t * m2 / m; } +double vessel::add_fluid(double m2, double t2) +{ + double m1 = get_mass(); + double t1 = get_heat(); + double t = t1 - t2; + + m2 = fluid.g_to_l(m2); + + if(level + m2 > volume) + { + m2 = volume - level; + } + + heat = t1 - t * m2 / (m1 + m2); + level += m2; + return m2; +} + double vessel::extract_steam(double dt, double a, double p2) { // calculate the mass moved diff --git a/src/reactor/coolant/vessel.hpp b/src/reactor/coolant/vessel.hpp index e6d575f..13c2f6a 100644 --- a/src/reactor/coolant/vessel.hpp +++ b/src/reactor/coolant/vessel.hpp @@ -23,12 +23,14 @@ public: void update(); double add_heat(double amount); + double add_fluid(double amount, double heat); double extract_steam(double dt, double a, double p2); constexpr double get_volume() const { return volume; } constexpr double get_level() const { return level; } constexpr double get_heat() const { return heat; } constexpr double get_steam() const { return steam; } + constexpr double get_mass() const { return fluid.l_to_g(level) + steam; } double get_pressure() const; }; diff --git a/src/reactor/rod.cpp b/src/reactor/rod.cpp index 8b5ed22..75b02c5 100644 --- a/src/reactor/rod.cpp +++ b/src/reactor/rod.cpp @@ -45,7 +45,7 @@ void rod::interact(rod* o, double secs) double rod::get_speed() const { int m = motion < 0 ? -1 : 1; - return motion == 0 ? 0 : (std::pow(10, std::abs(motion)) * 1e-10 * m); + return motion == 0 ? 0 : (std::pow(10, std::abs(motion)) * 1e-6 * m); } void rod::update_rod(double secs) @@ -70,7 +70,7 @@ void rod::update_rod_selected(int m) { motion += m; - if(motion > 10) motion = 10; - if(motion < -10) motion = -10; + if(motion > 5) motion = 5; + if(motion < -5) motion = -5; }