fixed a math issue

This commit is contained in:
Jay Robson 2024-01-16 23:36:11 +11:00
parent 77b1af8bd2
commit 69b97b23dd
7 changed files with 90 additions and 26 deletions

View File

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

View File

@ -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<W, H> 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;

View File

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

View File

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

View File

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

View File

@ -12,7 +12,7 @@ class vessel
{
double level; // litres
double heat = 0; // celcius
double steam = 0; // moles
double steam = 0; // grams
public:

View File

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