added a proper clock, adjusted values

This commit is contained in:
Jay Robson 2024-01-17 11:21:40 +11:00
parent 69b97b23dd
commit 052a65c31c
6 changed files with 30 additions and 32 deletions

View File

@ -12,6 +12,14 @@
#include <sstream> #include <sstream>
#include <unistd.h> #include <unistd.h>
#include <curses.h> #include <curses.h>
#include <sys/time.h>
unsigned long get_now()
{
struct timeval tv;
gettimeofday(&tv, nullptr);
return (unsigned long)tv.tv_sec * 1000000 + tv.tv_usec;
}
int main() int main()
{ {
@ -24,7 +32,7 @@ int main()
sim::reactor::coolant::vessel vessel(200, 400, sim::coolant::WATER); sim::reactor::coolant::vessel vessel(200, 400, sim::coolant::WATER);
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(1000, 4000), sim::reactor::fuel::fuel_rod(2000, 4000),
sim::reactor::control::control_rod(10000, 1), sim::reactor::control::control_rod(10000, 1),
sim::reactor::coolant::pipe(vessel), { sim::reactor::coolant::pipe(vessel), {
"# #", "# #",
@ -35,6 +43,7 @@ int main()
}); });
double secs = 0; double secs = 0;
long clock = get_now();
for(;;) for(;;)
{ {
@ -65,9 +74,9 @@ int main()
ss << s << "s\n\n"; ss << s << "s\n\n";
} }
reactor.update(1); reactor.update(0.01);
vessel.update(); vessel.update();
secs += 1; secs += 0.01;
ss << "Vessel\n" << vessel << "\n"; ss << "Vessel\n" << vessel << "\n";
@ -129,6 +138,16 @@ int main()
reactor.toggle_selected(); reactor.toggle_selected();
break; break;
} }
long now = get_now();
while(clock + 10000 > now)
{
usleep(clock + 10000 - now);
now = get_now();
}
clock += 10000;
} }
return 0; return 0;

View File

@ -19,17 +19,7 @@ void control_rod::display(std::ostream& o) const
double control_rod::get_k(val_t type) const double control_rod::get_k(val_t type) const
{ {
switch(type) return 0.5;
{
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 control_rod::set_reactivity(double a) void control_rod::set_reactivity(double a)

View File

@ -7,7 +7,7 @@ void heater::update(double secs)
{ {
update_rod(secs); update_rod(secs);
vals[val_t::HEAT] += rate * secs; vals_in[val_t::HEAT] += rate * secs;
} }
void heater::update_selected(double a) void heater::update_selected(double a)

View File

@ -25,7 +25,7 @@ void pipe::update(double secs)
vals[val_t::HEAT] = v; vals[val_t::HEAT] = v;
v = vals[val_t::N_FAST]; v = vals[val_t::N_FAST];
vals[val_t::N_FAST] -= v; vals_in[val_t::N_FAST] -= v;
vals[val_t::N_SLOW] += v; vals_in[val_t::N_SLOW] += v;
} }

View File

@ -56,7 +56,6 @@ std::ostream& operator<<(std::ostream& o, const vessel& v)
o << "Steam: " << v.get_steam() << " g\n"; o << "Steam: " << v.get_steam() << " g\n";
o << "Heat: " << v.get_heat() << " C\n"; o << "Heat: " << v.get_heat() << " C\n";
o << "Pressure: " << v.get_pressure() << " Pa\n"; o << "Pressure: " << v.get_pressure() << " Pa\n";
o << "Vapor Pressure: " << v.fluid.vapor_pressure.calc_p(v.get_heat()) << " Pa\n";
return o; return o;
} }

View File

@ -17,17 +17,7 @@ void fuel_rod::display(std::ostream& o) const
double fuel_rod::get_k(val_t type) const double fuel_rod::get_k(val_t type) const
{ {
switch(type) return 0.5;
{
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 fuel_rod::update(double secs) void fuel_rod::update(double secs)
@ -36,9 +26,9 @@ 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(); vals_in[val_t::HEAT] += s.extract_energy();
vals[val_t::N_FAST] += s.extract_fast_neutrons(); vals_in[val_t::N_FAST] += s.extract_fast_neutrons();
vals[val_t::N_SLOW] = 0; vals_in[val_t::N_SLOW] -= vals[val_t::N_SLOW];
s.update(secs); s.update(secs);
} }