adding vapor pressure stuff
This commit is contained in:
parent
929b14a21d
commit
77b1af8bd2
|
@ -0,0 +1,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
namespace sim::constants
|
||||
{
|
||||
constexpr const double R = 8.31446261815324; // molar gas constant, J/Kmol
|
||||
};
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
namespace sim::conversions::pressure
|
||||
{
|
||||
|
||||
constexpr double torr_to_pa(double t) { return t * 133.322; }
|
||||
constexpr double pa_to_torr(double p) { return p / 133.322; }
|
||||
|
||||
};
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
namespace sim::conversions::temperature
|
||||
{
|
||||
|
||||
constexpr double k_to_c(double k) { return k - 273.15; }
|
||||
constexpr double c_to_k(double c) { return c + 273.15; }
|
||||
|
||||
};
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "vapor_pressure.hpp"
|
||||
|
||||
namespace sim::coolant
|
||||
{
|
||||
|
||||
struct fluid_t
|
||||
{
|
||||
const double gPl; // g/L
|
||||
const double gPmol; // g/mol
|
||||
const coolant::vapor_pressure vapor_pressure;
|
||||
|
||||
constexpr fluid_t(double gPl, double gPmol, coolant::vapor_pressure vapor_pressure) : gPl(gPl), gPmol(gPmol), vapor_pressure(vapor_pressure) { }
|
||||
|
||||
constexpr double g_to_mol(double g) const { return g / gPmol; }
|
||||
constexpr double mol_to_g(double mol) const { return mol * gPmol; }
|
||||
constexpr double g_to_l(double g) const { return g / gPl; }
|
||||
constexpr double l_to_g(double l) const { return l * gPl; }
|
||||
constexpr double mol_to_l(double mol) const { return g_to_l(mol_to_g(mol)); }
|
||||
constexpr double l_to_mol(double l) const { return g_to_mol(l_to_g(l)); }
|
||||
};
|
||||
|
||||
constexpr const fluid_t WATER = fluid_t(1000, 18, {8.07131, 1730.63, 233.426});
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
#include "vapor_pressure.hpp"
|
||||
#include "../conversions/temperature.hpp"
|
||||
#include "../conversions/pressure.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
using namespace sim::coolant;
|
||||
using namespace sim::conversions;
|
||||
|
||||
double vapor_pressure::calc_p(double t) const
|
||||
{
|
||||
return pressure::torr_to_pa(std::pow(10, A - B / ( C + t ) ));
|
||||
}
|
||||
|
||||
double vapor_pressure::calc_t(double p) const
|
||||
{
|
||||
return B / ( A - std::log(pressure::pa_to_torr(p)) / std::log(10) ) - C;
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
namespace sim::coolant
|
||||
{
|
||||
|
||||
struct vapor_pressure
|
||||
{
|
||||
const double A, B, C;
|
||||
|
||||
constexpr vapor_pressure(double A, double B, double C) : A(A), B(B), C(C) { }
|
||||
|
||||
double calc_p(double t) const;
|
||||
double calc_t(double p) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
#include "reactor/fuel/fuel_rod.hpp"
|
||||
#include "reactor/coolant/pipe.hpp"
|
||||
#include "reactor/coolant/vessel.hpp"
|
||||
#include "coolant/fluid_t.hpp"
|
||||
#include "display.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
@ -20,10 +21,10 @@ int main()
|
|||
nodelay(stdscr, TRUE);
|
||||
curs_set(0);
|
||||
|
||||
sim::reactor::coolant::vessel vessel(100, 400);
|
||||
sim::reactor::coolant::vessel vessel(200, 400, sim::coolant::WATER);
|
||||
sim::reactor::reactor<5, 5> reactor = sim::reactor::builder<5, 5>(
|
||||
sim::reactor::fuel::fuel_rod(100, 400),
|
||||
sim::reactor::control::control_rod(1000, 1),
|
||||
sim::reactor::fuel::fuel_rod(1000, 4000),
|
||||
sim::reactor::control::control_rod(10000, 1),
|
||||
sim::reactor::coolant::pipe(vessel), {
|
||||
"## ##",
|
||||
"#FCF#",
|
||||
|
|
|
@ -9,11 +9,6 @@ pipe::pipe(coolant::vessel& v)
|
|||
this->steam = 0;
|
||||
}
|
||||
|
||||
void pipe::display(std::ostream& o) const
|
||||
{
|
||||
o << "Steam: +" << steam << "\n";
|
||||
}
|
||||
|
||||
double pipe::get_k(val_t type) const
|
||||
{
|
||||
return vessel->get_level() / vessel->get_volume();
|
||||
|
@ -25,7 +20,7 @@ void pipe::update(double secs)
|
|||
|
||||
update_rod(secs);
|
||||
|
||||
v = vessel->add_steam(vals[val_t::HEAT]);
|
||||
v = vessel->add_heat(vals[val_t::HEAT]);
|
||||
steam = vals[val_t::HEAT] - v;
|
||||
vals[val_t::HEAT] = v;
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ 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"; }
|
||||
virtual void display(std::ostream& o) const;
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -1,31 +1,37 @@
|
|||
|
||||
#include "vessel.hpp"
|
||||
#include "../../constants.hpp"
|
||||
#include "../../conversions/temperature.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
using namespace sim::reactor::coolant;
|
||||
|
||||
vessel::vessel(double level, double volume)
|
||||
vessel::vessel(double level, double volume, sim::coolant::fluid_t fluid) : volume(volume), fluid(fluid)
|
||||
{
|
||||
this->level = level;
|
||||
this->volume = volume;
|
||||
}
|
||||
|
||||
void vessel::update()
|
||||
{
|
||||
level += level_in;
|
||||
steam += steam_in;
|
||||
level_in = 0;
|
||||
steam_in = 0;
|
||||
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);
|
||||
|
||||
if(sc_l > level) sc_l = level;
|
||||
|
||||
steam += fluid.l_to_mol(sc_l);
|
||||
level -= sc_l;
|
||||
}
|
||||
|
||||
double vessel::add_steam(double amount)
|
||||
double vessel::add_heat(double amount)
|
||||
{
|
||||
double th = get_pressure();
|
||||
double th = get_heat();
|
||||
|
||||
if(amount > th)
|
||||
{
|
||||
amount -= th;
|
||||
steam_in += amount;
|
||||
level_in -= amount;
|
||||
heat += amount / level;
|
||||
|
||||
return th;
|
||||
}
|
||||
|
@ -33,11 +39,21 @@ double vessel::add_steam(double amount)
|
|||
return amount;
|
||||
}
|
||||
|
||||
void vessel::display(std::ostream& o) const
|
||||
double vessel::get_pressure() const
|
||||
{
|
||||
o << "Volume: " << volume << "\n";
|
||||
o << "Level: " << level << "\n";
|
||||
o << "Steam: " << steam << "\n";
|
||||
o << "Pressure: " << get_pressure() << "\n";
|
||||
return (steam * conversions::temperature::c_to_k(heat) * constants::R) / (volume - level);
|
||||
}
|
||||
|
||||
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 << "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";
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,38 +3,36 @@
|
|||
|
||||
#include <ostream>
|
||||
|
||||
#include "../../coolant/fluid_t.hpp"
|
||||
|
||||
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;
|
||||
double level; // litres
|
||||
double heat = 0; // celcius
|
||||
double steam = 0; // moles
|
||||
|
||||
public:
|
||||
|
||||
const double volume; //litres
|
||||
const sim::coolant::fluid_t fluid;
|
||||
|
||||
vessel(double level, double volume);
|
||||
vessel(double level, double volume, sim::coolant::fluid_t fluid);
|
||||
|
||||
void update();
|
||||
double add_steam(double amount);
|
||||
double add_heat(double amount);
|
||||
|
||||
constexpr double get_volume() const { return volume; }
|
||||
constexpr double get_level() const { return level; }
|
||||
constexpr double get_heat() const { return heat; }
|
||||
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;
|
||||
}
|
||||
|
||||
double get_pressure() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& o, const sim::reactor::coolant::vessel& v);
|
||||
|
||||
|
|
Loading…
Reference in New Issue