2024-02-02 22:03:47 +11:00
|
|
|
|
|
|
|
#include "fluid_holder.hpp"
|
2024-02-06 01:08:44 +11:00
|
|
|
#include "../util/constants.hpp"
|
2024-02-02 22:03:47 +11:00
|
|
|
#include "../conversions/temperature.hpp"
|
|
|
|
#include "../reactor/fuel/half_life.hpp"
|
|
|
|
|
|
|
|
#include <cmath>
|
2024-02-03 23:35:59 +11:00
|
|
|
#include <iostream>
|
2024-02-10 15:58:06 +11:00
|
|
|
#include <complex>
|
2024-02-02 22:03:47 +11:00
|
|
|
|
|
|
|
using namespace sim::coolant;
|
|
|
|
|
2024-02-10 15:58:06 +11:00
|
|
|
typedef std::complex<double> complex;
|
|
|
|
|
2024-02-05 18:33:31 +11:00
|
|
|
fluid_holder::fluid_holder(fluid_t fluid, double volume, double extra_mass) : fluid(fluid), volume(volume), extra_mass(extra_mass)
|
2024-02-02 22:03:47 +11:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
double fluid_holder::add_heat(double m1, double t1)
|
|
|
|
{
|
|
|
|
double t2 = get_heat();
|
|
|
|
double t = t1 - t2;
|
2024-02-05 18:33:31 +11:00
|
|
|
double m2 = get_thermal_mass();
|
2024-02-02 22:03:47 +11:00
|
|
|
double m = m1 + m2;
|
2024-02-03 23:35:59 +11:00
|
|
|
|
|
|
|
if(m1 == 0 || m2 == 0)
|
|
|
|
return t1;
|
2024-02-02 22:03:47 +11:00
|
|
|
|
|
|
|
heat = t1 - t * m2 / m;
|
2024-02-03 23:35:59 +11:00
|
|
|
|
2024-02-02 22:03:47 +11:00
|
|
|
return heat;
|
|
|
|
}
|
|
|
|
|
|
|
|
double fluid_holder::add_fluid(double v2, double t2)
|
|
|
|
{
|
2024-02-13 15:28:39 +11:00
|
|
|
if(level + v2 <= 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-02-07 16:04:22 +11:00
|
|
|
if(level + v2 > volume - 1e-3)
|
2024-02-02 22:03:47 +11:00
|
|
|
{
|
2024-02-07 16:04:22 +11:00
|
|
|
v2 = volume - level - 1e-3;
|
2024-02-02 22:03:47 +11:00
|
|
|
}
|
|
|
|
|
2024-02-07 16:04:22 +11:00
|
|
|
double m1 = get_thermal_mass();
|
|
|
|
double m2 = fluid.l_to_g(v2);
|
2024-02-05 18:33:31 +11:00
|
|
|
|
|
|
|
double t1 = get_heat();
|
|
|
|
double t = t1 - t2;
|
|
|
|
|
|
|
|
heat = t1 - t * m2 / (m1 + m2);
|
2024-02-02 22:03:47 +11:00
|
|
|
level += v2;
|
|
|
|
|
|
|
|
return v2;
|
|
|
|
}
|
|
|
|
|
|
|
|
double fluid_holder::extract_fluid(double amount)
|
|
|
|
{
|
2024-02-07 16:04:22 +11:00
|
|
|
if(amount < level - 1e-3)
|
2024-02-02 22:03:47 +11:00
|
|
|
{
|
2024-02-07 16:04:22 +11:00
|
|
|
level -= amount - 1e-3;
|
2024-02-02 22:03:47 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
amount = level;
|
|
|
|
level = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return amount;
|
|
|
|
}
|
|
|
|
|
2024-02-04 23:22:15 +11:00
|
|
|
void fluid_holder::add_steam(double m2, double t2)
|
2024-02-02 22:03:47 +11:00
|
|
|
{
|
2024-02-05 18:33:31 +11:00
|
|
|
double m1 = get_thermal_mass();
|
2024-02-04 23:22:15 +11:00
|
|
|
double t1 = heat;
|
|
|
|
double m = m1 + m2;
|
2024-02-02 22:03:47 +11:00
|
|
|
|
2024-02-04 23:22:15 +11:00
|
|
|
if(m > 0)
|
2024-02-02 22:03:47 +11:00
|
|
|
{
|
2024-02-05 18:33:31 +11:00
|
|
|
heat = t1 - (t1 - t2) * m2 / (m1 + m2);
|
2024-02-02 22:03:47 +11:00
|
|
|
}
|
|
|
|
|
2024-02-05 18:33:31 +11:00
|
|
|
steam += m2;
|
2024-02-02 22:03:47 +11:00
|
|
|
}
|
|
|
|
|
2024-02-07 16:04:22 +11:00
|
|
|
double fluid_holder::calc_pressure(double heat, double volume, double mol)
|
2024-02-02 22:03:47 +11:00
|
|
|
{
|
2024-02-07 16:04:22 +11:00
|
|
|
double V = volume * 0.001;
|
2024-02-05 18:33:31 +11:00
|
|
|
|
2024-02-13 15:28:39 +11:00
|
|
|
return V == 0 ? 0 : (mol * heat * constants::R) / V;
|
2024-02-07 16:04:22 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
double fluid_holder::calc_pressure_mol(double heat, double volume, double pressure)
|
|
|
|
{
|
|
|
|
double V = volume * 0.001;
|
|
|
|
|
2024-02-13 15:28:39 +11:00
|
|
|
return (pressure * V) / (constants::R * heat);
|
2024-02-09 21:31:36 +11:00
|
|
|
}
|
|
|
|
|
2024-02-07 16:04:22 +11:00
|
|
|
double fluid_holder::get_pressure() const
|
|
|
|
{
|
2024-02-13 15:28:39 +11:00
|
|
|
return calc_pressure(conversions::temperature::c_to_k(heat), get_steam_volume(), fluid.g_to_mol(steam));
|
2024-02-02 22:03:47 +11:00
|
|
|
}
|
|
|
|
|
2024-02-05 18:33:31 +11:00
|
|
|
double fluid_holder::get_steam_density() const
|
|
|
|
{
|
|
|
|
double v = get_steam_volume();
|
2024-02-06 01:08:44 +11:00
|
|
|
return v > 0 ? steam / v : 0;
|
2024-02-05 18:33:31 +11:00
|
|
|
}
|
|
|
|
|
2024-02-13 15:28:39 +11:00
|
|
|
constexpr double calc_extra_steam(double K, double P, double L_m, double J_m, double n_g, double n_l, double V_t)
|
|
|
|
{
|
|
|
|
double R = sim::constants::R * 1000;
|
|
|
|
double n = (P * (V_t - n_l * L_m)) / (R * K) - n_g;
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fluid_holder::update_base(double secs)
|
2024-02-02 22:03:47 +11:00
|
|
|
{
|
2024-02-05 18:33:31 +11:00
|
|
|
double mass = get_thermal_mass();
|
2024-02-02 22:03:47 +11:00
|
|
|
|
2024-02-04 23:22:15 +11:00
|
|
|
if(mass > 0)
|
2024-02-02 22:03:47 +11:00
|
|
|
{
|
2024-02-13 15:28:39 +11:00
|
|
|
double K = conversions::temperature::c_to_k(heat); // K
|
|
|
|
double P = fluid.vapor_pressure.calc_p(K); // Pa
|
|
|
|
double R = sim::constants::R; // J/K/mol
|
|
|
|
|
|
|
|
double J_m = fluid.jPg * fluid.gPmol; // J/mol
|
|
|
|
double n_g = fluid.g_to_mol(steam); // mol
|
|
|
|
double V_g = (volume - level) * 0.001; // m^3
|
2024-02-10 15:58:06 +11:00
|
|
|
|
2024-02-13 15:28:39 +11:00
|
|
|
double n = (P * V_g) / (R * K) - n_g; // mol
|
|
|
|
double l = level - fluid.mol_to_l(n); // L
|
2024-02-04 23:22:15 +11:00
|
|
|
|
2024-02-10 15:58:06 +11:00
|
|
|
if(l < 0)
|
|
|
|
{
|
|
|
|
n -= fluid.l_to_mol(l);
|
|
|
|
l = 0;
|
|
|
|
}
|
2024-02-13 15:28:39 +11:00
|
|
|
|
|
|
|
steam += fluid.mol_to_g(n);
|
2024-02-04 23:22:15 +11:00
|
|
|
|
2024-02-13 15:28:39 +11:00
|
|
|
if(steam < 0)
|
|
|
|
{
|
|
|
|
l -= fluid.g_to_l(steam);
|
|
|
|
n += fluid.g_to_mol(steam);
|
|
|
|
steam = 0;
|
|
|
|
}
|
|
|
|
|
2024-02-10 15:58:06 +11:00
|
|
|
level = l;
|
|
|
|
heat -= n * J_m / mass;
|
2024-02-02 22:03:47 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|