added the pump

This commit is contained in:
Jay Robson 2024-01-18 19:41:13 +11:00
parent 67773f14bd
commit 714300930f
5 changed files with 93 additions and 6 deletions

57
src/coolant/pump.hpp Normal file
View File

@ -0,0 +1,57 @@
#pragma once
#include <ostream>
namespace sim::coolant
{
template <class A>
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;
}
};
};

View File

@ -7,6 +7,7 @@
#include "reactor/coolant/vessel.hpp" #include "reactor/coolant/vessel.hpp"
#include "coolant/fluid_t.hpp" #include "coolant/fluid_t.hpp"
#include "coolant/valve.hpp" #include "coolant/valve.hpp"
#include "coolant/pump.hpp"
#include "display.hpp" #include "display.hpp"
#include <cmath> #include <cmath>
@ -52,7 +53,8 @@ int main()
"#C#C#" "#C#C#"
}); });
sim::coolant::valve<sim::reactor::coolant::vessel> valve(vessel, 1, 101000); sim::coolant::valve<sim::reactor::coolant::vessel> valve(vessel, 1, 500);
sim::coolant::pump<sim::reactor::coolant::vessel> pump(vessel, 1e4, 15);
double secs = 0; double secs = 0;
long clock = get_now(); long clock = get_now();
@ -97,13 +99,15 @@ secs: ss << s << "s\n";
{ {
double dt = speed / framerate / steps_extra; double dt = speed / framerate / steps_extra;
reactor.update(rand, dt); reactor.update(rand, dt);
vessel.update(); pump.update(dt);
valve.update(dt); valve.update(dt);
vessel.update();
secs += dt; secs += dt;
} }
ss << "Vessel\n" << vessel << "\n"; ss << "Vessel\n" << vessel << "\n";
ss << "Steam Valve\n" << valve << "\n"; ss << "Steam Valve\n" << valve << "\n";
ss << "Coolant Pump\n" << pump << "\n";
if(do_graphics) if(do_graphics)
{ {
@ -185,6 +189,12 @@ secs: ss << s << "s\n";
case 'f': case 'f':
valve.open(-0.001); valve.open(-0.001);
break; break;
case 'e':
pump.change_speed(0.01);
break;
case 'd':
pump.change_speed(-0.01);
break;
} }
if(do_clock) if(do_clock)

View File

@ -52,13 +52,31 @@ double vessel::add_heat(double t1)
{ {
double t2 = get_heat(); double t2 = get_heat();
double t = t1 - t2; double t = t1 - t2;
double m1 = 1000000; double m1 = 1e6;
double m2 = (fluid.l_to_g(level) + steam) * fluid.jPgk; double m2 = (fluid.l_to_g(level) + steam) * fluid.jPgk;
double m = m1 + m2; double m = m1 + m2;
return heat = t1 - t * m2 / m; 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) double vessel::extract_steam(double dt, double a, double p2)
{ {
// calculate the mass moved // calculate the mass moved

View File

@ -23,12 +23,14 @@ public:
void update(); void update();
double add_heat(double amount); double add_heat(double amount);
double add_fluid(double amount, double heat);
double extract_steam(double dt, double a, double p2); double extract_steam(double dt, double a, double p2);
constexpr double get_volume() const { return volume; } constexpr double get_volume() const { return volume; }
constexpr double get_level() const { return level; } constexpr double get_level() const { return level; }
constexpr double get_heat() const { return heat; } constexpr double get_heat() const { return heat; }
constexpr double get_steam() const { return steam; } constexpr double get_steam() const { return steam; }
constexpr double get_mass() const { return fluid.l_to_g(level) + steam; }
double get_pressure() const; double get_pressure() const;
}; };

View File

@ -45,7 +45,7 @@ void rod::interact(rod* o, double secs)
double rod::get_speed() const double rod::get_speed() const
{ {
int m = motion < 0 ? -1 : 1; 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) void rod::update_rod(double secs)
@ -70,7 +70,7 @@ void rod::update_rod_selected(int m)
{ {
motion += m; motion += m;
if(motion > 10) motion = 10; if(motion > 5) motion = 5;
if(motion < -10) motion = -10; if(motion < -5) motion = -5;
} }