From 5cfd4309716aaac216a21e8ebe9b8101b10d3368 Mon Sep 17 00:00:00 2001 From: Jay Robson Date: Tue, 16 Jan 2024 23:36:11 +1100 Subject: [PATCH] fixed a math issue --- src/main.cpp | 9 ++++--- src/reactor/builder.hpp | 4 +++ src/reactor/coolant/heater.cpp | 27 ++++++++++++++++++++ src/reactor/coolant/heater.hpp | 27 ++++++++++++++++++++ src/reactor/coolant/vessel.cpp | 45 +++++++++++++++++++--------------- src/reactor/coolant/vessel.hpp | 2 +- src/reactor/fuel/sample.hpp | 2 +- 7 files changed, 90 insertions(+), 26 deletions(-) create mode 100644 src/reactor/coolant/heater.cpp create mode 100644 src/reactor/coolant/heater.hpp diff --git a/src/main.cpp b/src/main.cpp index 42e74a0..639238e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,6 +3,7 @@ #include "reactor/control/control_rod.hpp" #include "reactor/fuel/fuel_rod.hpp" #include "reactor/coolant/pipe.hpp" +#include "reactor/coolant/heater.hpp" #include "reactor/coolant/vessel.hpp" #include "coolant/fluid_t.hpp" #include "display.hpp" @@ -26,11 +27,11 @@ int main() sim::reactor::fuel::fuel_rod(1000, 4000), sim::reactor::control::control_rod(10000, 1), sim::reactor::coolant::pipe(vessel), { - "## ##", - "#FCF#", + "# #", + " FCF ", " C C ", - "#FCF#", - "## ##" + " FCF ", + "# #" }); double secs = 0; diff --git a/src/reactor/builder.hpp b/src/reactor/builder.hpp index 144ce1d..cc2f858 100644 --- a/src/reactor/builder.hpp +++ b/src/reactor/builder.hpp @@ -5,6 +5,7 @@ #include "fuel/fuel_rod.hpp" #include "control/control_rod.hpp" #include "coolant/pipe.hpp" +#include "coolant/heater.hpp" #include "reactor.hpp" namespace sim::reactor @@ -29,6 +30,9 @@ reactor builder(fuel::fuel_rod fr, control::control_rod cr, coolant::pipe case 'C': r = new control::control_rod(cr); break; + case 'H': + r = new coolant::heater(); + break; case ' ': r = new coolant::pipe(p); break; diff --git a/src/reactor/coolant/heater.cpp b/src/reactor/coolant/heater.cpp new file mode 100644 index 0000000..b840bcd --- /dev/null +++ b/src/reactor/coolant/heater.cpp @@ -0,0 +1,27 @@ + +#include "heater.hpp" + +using namespace sim::reactor::coolant; + +void heater::update(double secs) +{ + update_rod(secs); + + vals[val_t::HEAT] += rate * secs; +} + +void heater::update_selected(double a) +{ + rate += a; +} + +double heater::get_k(sim::reactor::rod::val_t type) const +{ + return 0.5; +} + +void heater::display(std::ostream& o) const +{ + o << "Rate: " << rate << "\n"; +} + diff --git a/src/reactor/coolant/heater.hpp b/src/reactor/coolant/heater.hpp new file mode 100644 index 0000000..c6d90f4 --- /dev/null +++ b/src/reactor/coolant/heater.hpp @@ -0,0 +1,27 @@ + +#pragma once + +#include "../rod.hpp" + +namespace sim::reactor::coolant +{ + +class heater : public sim::reactor::rod +{ + double rate = 0; + + virtual double get_k(sim::reactor::rod::val_t type) const; + virtual void display(std::ostream& o) const; + + virtual const char* get_name() const { return "Heater"; } + +public: + + virtual void update(double secs); + 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/vessel.cpp b/src/reactor/coolant/vessel.cpp index ee2d795..3754e63 100644 --- a/src/reactor/coolant/vessel.cpp +++ b/src/reactor/coolant/vessel.cpp @@ -14,41 +14,46 @@ vessel::vessel(double level, double volume, sim::coolant::fluid_t fluid) : volum void vessel::update() { - double vp = fluid.vapor_pressure.calc_p(heat); - double sc = vp * (volume - level) / (constants::R * conversions::temperature::c_to_k(heat)) - steam; - double sc_l = fluid.mol_to_l(sc); + double V = (volume - level) * 0.001; + double P = fluid.vapor_pressure.calc_p(heat); + double T = conversions::temperature::c_to_k(heat); + double n = fluid.mol_to_g((V * P) / (T * constants::R)) - steam; - if(sc_l > level) sc_l = level; + steam += n; + level -= fluid.g_to_l(n); - steam += fluid.l_to_mol(sc_l); - level -= sc_l; + if(fluid.g_to_l(steam) > volume) + { + steam = fluid.l_to_g(volume); + level = 0; + } } -double vessel::add_heat(double amount) +double vessel::add_heat(double t1) { - double th = get_heat(); - - if(amount > th) - { - amount -= th; - heat += amount / level; - - return th; - } - - return amount; + double t2 = get_heat(); + double t = t1 - t2; + double m1 = 1; + double m2 = level + fluid.g_to_l(steam); + double m = m1 + m2; + + return heat = t1 - t * m2 / m; } double vessel::get_pressure() const { - return (steam * conversions::temperature::c_to_k(heat) * constants::R) / (volume - level); + double T = conversions::temperature::c_to_k(heat); + double V = (volume - level) * 0.001; + double n = fluid.g_to_mol(steam); + + return (n * T * constants::R) / V; } std::ostream& operator<<(std::ostream& o, const vessel& v) { o << "Volume: " << v.get_volume() << " L\n"; o << "Level: " << v.get_level() << " L\n"; - o << "Steam: " << v.get_steam() << " mol\n"; + o << "Steam: " << v.get_steam() << " g\n"; o << "Heat: " << v.get_heat() << " C\n"; o << "Pressure: " << v.get_pressure() << " Pa\n"; o << "Vapor Pressure: " << v.fluid.vapor_pressure.calc_p(v.get_heat()) << " Pa\n"; diff --git a/src/reactor/coolant/vessel.hpp b/src/reactor/coolant/vessel.hpp index 2f70a17..43d0206 100644 --- a/src/reactor/coolant/vessel.hpp +++ b/src/reactor/coolant/vessel.hpp @@ -12,7 +12,7 @@ class vessel { double level; // litres double heat = 0; // celcius - double steam = 0; // moles + double steam = 0; // grams public: diff --git a/src/reactor/fuel/sample.hpp b/src/reactor/fuel/sample.hpp index 6efc848..4278319 100644 --- a/src/reactor/fuel/sample.hpp +++ b/src/reactor/fuel/sample.hpp @@ -10,7 +10,7 @@ namespace sim::reactor::fuel class sample { - constexpr static const double Xe_135_M = 1e4; + constexpr static const double Xe_135_M = 1e3; sim::reactor::fuel::waste waste;