made some tweaks

This commit is contained in:
Jay Robson 2024-01-14 23:44:36 +11:00
parent 5c4b8954a0
commit a30687306b
9 changed files with 56 additions and 29 deletions

View File

@ -20,21 +20,28 @@ int main()
sim::reactor::reactor<5, 5> reactor = sim::reactor::builder<5, 5>(
sim::reactor::fuel::fuel_rod(100, 400),
sim::reactor::control::control_rod(1000),
sim::reactor::control::control_rod(1000, 0.1),
sim::reactor::coolant::pipe(), {
" P ",
" FCF ",
" PPP ",
"PFCFP",
"PCPCP",
" FCF ",
" P "
"PFCFP",
" PPP "
});
double secs = 0;
for(;;)
{
reactor.update(1);
reactor.update(0.01);
std::stringstream ss;
ss << "Reactor Core: " << secs << " s\n";
secs += 0.01;
erase();
display::draw_text(1, 0, "Reactor Core:");
display::draw_text(1, 0, ss.str().c_str());
const int X = 3, Y = 4;
const int W = 32, H = 8;
@ -76,10 +83,10 @@ int main()
reactor.move_cursor(1);
break;
case KEY_UP:
reactor.update_selected(0.001);
reactor.update_selected(0.01);
break;
case KEY_DOWN:
reactor.update_selected(-0.001);
reactor.update_selected(-0.01);
break;
case ' ':
reactor.toggle_selected();

View File

@ -1,11 +1,14 @@
#include "control_rod.hpp"
#include <cmath>
using namespace sim::reactor::control;
control_rod::control_rod(double limit)
control_rod::control_rod(double limit, double max)
{
this->limit = limit;
this->max = max;
}
void control_rod::display(std::ostream& o) const
@ -38,7 +41,7 @@ void control_rod::update(double secs)
{
update_rod();
double m = (1 - absorbed / limit) * inserted;
double m = 1 - std::pow(0.5, (1 - absorbed / limit) * inserted * max);
double r_fast = vals[val_t::N_FAST] * m;
double r_slow = vals[val_t::N_SLOW] * m;

View File

@ -11,6 +11,7 @@ class control_rod : public sim::reactor::rod
double inserted = 1;
double absorbed = 0;
double limit;
double max;
virtual double get_k(sim::reactor::rod::val_t type) const;
virtual void display(std::ostream& o) const;
@ -20,7 +21,7 @@ class control_rod : public sim::reactor::rod
public:
control_rod(double limit);
control_rod(double limit, double max);
virtual void update(double secs);
void set_reactivity(double a);

View File

@ -10,7 +10,7 @@ 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 Pipe"; }
virtual const char* get_name() const { return "Coolant"; }
virtual bool should_display() const { return true; }
public:

View File

@ -11,6 +11,7 @@ fuel_rod::fuel_rod(double fuel, double mass) : s(fuel, mass)
void fuel_rod::display(std::ostream& o) const
{
o << "Fuel: " << s.get_fuel() << " / " << s.get_mass() << "\n";
o << "Efficiency: " << s.get_efficiency() << "\n";
o << "Energy: " << s.get_energy() << "\n";
}

View File

@ -4,7 +4,6 @@
using namespace sim::reactor::fuel;
static const double Xe_135_M = 1e4;
static const double NEUTRON_BG = 1e-10;
sample::sample(double fuel, double mass)
@ -45,14 +44,28 @@ void sample::update(double secs)
slow_neutrons = 0;
// deal with these edge cases
if(neutrons_fuel > fuel) neutrons_fuel = fuel;
if(neutrons_xenon > xe_135) neutrons_xenon = xe_135;
if(neutrons_iodine > i_135) neutrons_iodine = i_135;
if(neutrons_fuel > fuel)
{
slow_neutrons += neutrons_fuel - fuel;
neutrons_fuel = fuel;
}
if(neutrons_xenon > xe_135)
{
slow_neutrons += neutrons_xenon - xe_135;
neutrons_xenon = xe_135;
}
if(neutrons_iodine > i_135)
{
slow_neutrons += neutrons_iodine - i_135;
neutrons_iodine = i_135;
}
// sim::reactor::fuelulate fuel use
fuel -= neutrons_fuel;
energy += neutrons_fuel;
fast_neutrons += neutrons_fuel * 3;
waste.add_fissile(neutrons_fuel * 2);
// do the poison
@ -61,11 +74,6 @@ void sample::update(double secs)
i_135 -= neutrons_iodine;
}
double sample::get_volume() const
{
return mass + xe_135 * Xe_135_M;
}
double sample::extract_energy()
{
double v = energy;

View File

@ -10,6 +10,8 @@ namespace sim::reactor::fuel
class sample
{
constexpr static const double Xe_135_M = 1e3;
sim::reactor::fuel::waste waste;
double fuel = 0;
@ -36,8 +38,8 @@ public:
constexpr double get_fuel() const { return fuel; }
constexpr double get_mass() const { return mass; }
constexpr double get_energy() const { return energy; }
double get_volume() const;
constexpr double get_volume() const { return mass + xe_135 * Xe_135_M; }
constexpr double get_efficiency() const { return fuel / get_volume(); }
friend std::ostream& operator<<(std::ostream& o, const sample& s)
{

View File

@ -4,10 +4,13 @@
using namespace sim::reactor::fuel;
static const double SLOWDOWN_M = 1.0 / 4.0;
void waste::update(double secs)
{
double hl = 1;
double next[waste::N - 1] = {0};
double next_h[waste::N - 1] = {0};
double next_l[waste::N - 1] = {0};
for(int i = 0; i < waste::N - 1; i++)
{
@ -15,7 +18,8 @@ void waste::update(double secs)
double h = high[i] * m;
double l = low[i] * m;
next[i] += h + l;
next_h[i] += h * (1 - SLOWDOWN_M);
next_l[i] += l + h * SLOWDOWN_M;
high[i] -= h;
low[i] -= l;
@ -26,7 +30,8 @@ void waste::update(double secs)
for(int i = 0; i < waste::N - 1; i++)
{
low[i + 1] += next[i];
high[i + 1] += next_h[i];
low[i + 1] += next_l[i];
}
}

View File

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