added vessel

This commit is contained in:
Jay Robson 2024-01-15 15:29:28 +11:00
parent 4b018437e3
commit bd009617ad
8 changed files with 155 additions and 29 deletions

View File

@ -3,8 +3,10 @@
#include "reactor/control/control_rod.hpp" #include "reactor/control/control_rod.hpp"
#include "reactor/fuel/fuel_rod.hpp" #include "reactor/fuel/fuel_rod.hpp"
#include "reactor/coolant/pipe.hpp" #include "reactor/coolant/pipe.hpp"
#include "reactor/coolant/vessel.hpp"
#include "display.hpp" #include "display.hpp"
#include <cmath>
#include <sstream> #include <sstream>
#include <unistd.h> #include <unistd.h>
#include <curses.h> #include <curses.h>
@ -18,33 +20,60 @@ int main()
nodelay(stdscr, TRUE); nodelay(stdscr, TRUE);
curs_set(0); curs_set(0);
sim::reactor::coolant::vessel vessel(100, 400);
sim::reactor::reactor<5, 5> reactor = sim::reactor::builder<5, 5>( sim::reactor::reactor<5, 5> reactor = sim::reactor::builder<5, 5>(
sim::reactor::fuel::fuel_rod(100, 400), sim::reactor::fuel::fuel_rod(100, 400),
sim::reactor::control::control_rod(1000, 0.1), sim::reactor::control::control_rod(1000, 1),
sim::reactor::coolant::pipe(), { sim::reactor::coolant::pipe(vessel), {
" PPP ", "## ##",
"PFCFP", "#FCF#",
"PCPCP", " C C ",
"PFCFP", "#FCF#",
" PPP " "## ##"
}); });
double secs = 0; double secs = 0;
for(;;) for(;;)
{ {
reactor.update(0.01);
std::stringstream ss; 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(); erase();
display::draw_text(1, 0, ss.str().c_str()); display::draw_text(1, 0, ss.str().c_str());
const int X = 3, Y = 4; const int X = 2, Y = 40;
const int W = 32, H = 8; const int W = 32, H = 10;
for(int x = 0; x < reactor.width; x++) for(int x = 0; x < reactor.width; x++)
for(int y = 0; y < reactor.height; y++) for(int y = 0; y < reactor.height; y++)

View File

@ -29,10 +29,10 @@ reactor<W, H> builder(fuel::fuel_rod fr, control::control_rod cr, coolant::pipe
case 'C': case 'C':
r = new control::control_rod(cr); r = new control::control_rod(cr);
break; break;
case 'P': case ' ':
r = new coolant::pipe(p); r = new coolant::pipe(p);
break; break;
default: case '#':
r = new rod(); r = new rod();
} }

View File

@ -3,26 +3,33 @@
using namespace sim::reactor::coolant; 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 double pipe::get_k(val_t type) const
{ {
switch(type) return vessel->get_level() / vessel->get_volume();
{
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;
} }
void pipe::update(double secs) void pipe::update(double secs)
{ {
double v;
update_rod(); 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_FAST] -= v;
vals[val_t::N_SLOW] += v; vals[val_t::N_SLOW] += v;
} }

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "vessel.hpp"
#include "../rod.hpp" #include "../rod.hpp"
namespace sim::reactor::coolant namespace sim::reactor::coolant
@ -8,12 +9,18 @@ namespace sim::reactor::coolant
class pipe : public sim::reactor::rod class pipe : public sim::reactor::rod
{ {
coolant::vessel* vessel;
double steam;
virtual double get_k(sim::reactor::rod::val_t type) const; virtual double get_k(sim::reactor::rod::val_t type) const;
virtual const char* get_name() const { return "Coolant"; } virtual const char* get_name() const { return "Coolant"; }
virtual void display(std::ostream& o) const;
public: public:
pipe(coolant::vessel& v);
virtual bool should_display() const { return true; } virtual bool should_display() const { return true; }
virtual void update(double secs); virtual void update(double secs);

View File

@ -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";
}

View File

@ -0,0 +1,40 @@
#pragma once
#include <ostream>
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;
}
};
}

View File

@ -12,7 +12,7 @@ void fuel_rod::display(std::ostream& o) const
{ {
o << "Fuel: " << s.get_fuel() << " / " << s.get_mass() << "\n"; o << "Fuel: " << s.get_fuel() << " / " << s.get_mass() << "\n";
o << "Efficiency: " << s.get_efficiency() << "\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 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]); 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_FAST] += s.extract_fast_neutrons();
vals[val_t::N_SLOW] = 0; vals[val_t::N_SLOW] = 0;

View File

@ -38,7 +38,7 @@ public:
o << r.get_name() << "\n"; o << r.get_name() << "\n";
r.display(o); 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 << "Fast: " << r.get(val_t::N_FAST) << "\n";
o << "Slow: " << r.get(val_t::N_SLOW) << "\n"; o << "Slow: " << r.get(val_t::N_SLOW) << "\n";