i can now make the core stable! :)
This commit is contained in:
parent
cf0046cde2
commit
8c8bcf3e87
|
@ -18,7 +18,7 @@ public:
|
||||||
condenser_secondary(condenser* primary, evaporator* source, double volume);
|
condenser_secondary(condenser* primary, evaporator* source, double volume);
|
||||||
|
|
||||||
virtual double add_heat(double m, double t) { return source->add_heat(m, t); }
|
virtual double add_heat(double m, double t) { return source->add_heat(m, t); }
|
||||||
virtual void add_steam(double amount, double t) { return source->add_steam(amount, t); }
|
virtual void add_gas(double steam, double gas, double t) { return source->add_gas(steam, gas, t); }
|
||||||
virtual double extract_fluid(double amount) { return source->extract_fluid(amount); }
|
virtual double extract_fluid(double amount) { return source->extract_fluid(amount); }
|
||||||
|
|
||||||
virtual double add_fluid(double amount, double heat);
|
virtual double add_fluid(double amount, double heat);
|
||||||
|
@ -27,11 +27,13 @@ public:
|
||||||
virtual double get_level() const { return source->get_level(); }
|
virtual double get_level() const { return source->get_level(); }
|
||||||
virtual double get_heat() const { return source->get_heat(); } // celsius
|
virtual double get_heat() const { return source->get_heat(); } // celsius
|
||||||
virtual double get_steam() const { return source->get_steam(); } // grams
|
virtual double get_steam() const { return source->get_steam(); } // grams
|
||||||
virtual double get_steam_volume() const { return source->get_steam_volume(); } // litres
|
virtual double get_air() const { return source->get_air(); } // grams
|
||||||
|
virtual double get_gas() const { return source->get_gas(); } // grams
|
||||||
|
virtual double get_gas_volume() const { return source->get_gas_volume(); } // litres
|
||||||
virtual double get_mass() const { return source->get_mass(); } // grams
|
virtual double get_mass() const { return source->get_mass(); } // grams
|
||||||
virtual double get_thermal_mass() const { return source->get_thermal_mass(); } // grams
|
virtual double get_thermal_mass() const { return source->get_thermal_mass(); } // grams
|
||||||
virtual double get_pressure() const { return source->get_pressure(); } // pascals
|
virtual double get_pressure() const { return source->get_pressure(); } // pascals
|
||||||
virtual double get_steam_density() const { return source->get_steam_density(); } // g/L
|
virtual double get_gas_density() const { return source->get_gas_density(); } // g/L
|
||||||
|
|
||||||
void update(double dt);
|
void update(double dt);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
#include "evaporator.hpp"
|
#include "evaporator.hpp"
|
||||||
|
#include "../util/constants.hpp"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -28,6 +29,19 @@ double evaporator::get_steam_output()
|
||||||
|
|
||||||
void evaporator::update(double dt)
|
void evaporator::update(double dt)
|
||||||
{
|
{
|
||||||
|
steam_output = steam / dt;
|
||||||
|
steam = 0;
|
||||||
|
|
||||||
|
double P = 10000; // Pa
|
||||||
|
double K = conversions::temperature::c_to_k(heat); // K
|
||||||
|
double R = sim::constants::R; // J/K/mol
|
||||||
|
|
||||||
|
double n_g = air / constants::M_air; // mol
|
||||||
|
double V_g = (volume - level) * 0.001; // m^3
|
||||||
|
|
||||||
|
double n = (P * V_g) / (R * K); // mol
|
||||||
|
|
||||||
|
air = n * constants::M_air;
|
||||||
update_base(dt);
|
update_base(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,9 @@
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <complex>
|
|
||||||
|
|
||||||
using namespace sim::coolant;
|
using namespace sim::coolant;
|
||||||
|
|
||||||
typedef std::complex<double> complex;
|
|
||||||
|
|
||||||
fluid_holder::fluid_holder(fluid_t fluid, double volume, double extra_mass) : fluid(fluid), volume(volume), extra_mass(extra_mass)
|
fluid_holder::fluid_holder(fluid_t fluid, double volume, double extra_mass) : fluid(fluid), volume(volume), extra_mass(extra_mass)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -72,18 +69,21 @@ double fluid_holder::extract_fluid(double amount)
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fluid_holder::add_steam(double m2, double t2)
|
void fluid_holder::add_gas(double m_s2, double m_a2, double t_2)
|
||||||
{
|
{
|
||||||
double m1 = get_thermal_mass();
|
double m_2 = m_a2 + m_s2;
|
||||||
double t1 = heat;
|
double m_1 = get_thermal_mass();
|
||||||
double m = m1 + m2;
|
double t_1 = heat;
|
||||||
|
|
||||||
|
double m = m_1 + m_2;
|
||||||
|
|
||||||
if(m > 0)
|
if(m > 0)
|
||||||
{
|
{
|
||||||
heat = t1 - (t1 - t2) * m2 / (m1 + m2);
|
heat = t_1 - (t_1 - t_2) * m_2 / m;
|
||||||
}
|
}
|
||||||
|
|
||||||
steam += m2;
|
steam += m_s2;
|
||||||
|
air += m_a2;
|
||||||
}
|
}
|
||||||
|
|
||||||
double fluid_holder::calc_pressure(double heat, double volume, double mol)
|
double fluid_holder::calc_pressure(double heat, double volume, double mol)
|
||||||
|
@ -102,21 +102,13 @@ double fluid_holder::calc_pressure_mol(double heat, double volume, double pressu
|
||||||
|
|
||||||
double fluid_holder::get_pressure() const
|
double fluid_holder::get_pressure() const
|
||||||
{
|
{
|
||||||
return calc_pressure(conversions::temperature::c_to_k(heat), get_steam_volume(), fluid.g_to_mol(steam));
|
return calc_pressure(conversions::temperature::c_to_k(heat), get_gas_volume(), fluid.g_to_mol(steam) + air / constants::M_air);
|
||||||
}
|
}
|
||||||
|
|
||||||
double fluid_holder::get_steam_density() const
|
double fluid_holder::get_gas_density() const
|
||||||
{
|
{
|
||||||
double v = get_steam_volume();
|
double v = get_gas_volume();
|
||||||
return v > 0 ? steam / v : 0;
|
return v > 0 ? get_gas() / v : 0;
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
void fluid_holder::update_base(double secs)
|
||||||
|
@ -130,7 +122,7 @@ void fluid_holder::update_base(double secs)
|
||||||
double R = sim::constants::R; // J/K/mol
|
double R = sim::constants::R; // J/K/mol
|
||||||
|
|
||||||
double J_m = fluid.jPg * fluid.gPmol; // J/mol
|
double J_m = fluid.jPg * fluid.gPmol; // J/mol
|
||||||
double n_g = fluid.g_to_mol(steam); // mol
|
double n_g = fluid.g_to_mol(steam) + air / constants::M_air; // mol
|
||||||
double V_g = (volume - level) * 0.001; // m^3
|
double V_g = (volume - level) * 0.001; // m^3
|
||||||
|
|
||||||
double n = (P * V_g) / (R * K) - n_g; // mol
|
double n = (P * V_g) / (R * K) - n_g; // mol
|
||||||
|
@ -146,8 +138,8 @@ void fluid_holder::update_base(double secs)
|
||||||
|
|
||||||
if(steam < 0)
|
if(steam < 0)
|
||||||
{
|
{
|
||||||
l -= fluid.g_to_l(steam);
|
l += fluid.g_to_l(steam);
|
||||||
n += fluid.g_to_mol(steam);
|
n -= fluid.g_to_mol(steam);
|
||||||
steam = 0;
|
steam = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ class fluid_holder
|
||||||
|
|
||||||
double level = 0; // litres
|
double level = 0; // litres
|
||||||
double steam = 0; // grams
|
double steam = 0; // grams
|
||||||
|
double air = 0; // grams
|
||||||
double heat = 0; // celsius
|
double heat = 0; // celsius
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -27,18 +28,20 @@ public:
|
||||||
virtual double extract_fluid(double amount);
|
virtual double extract_fluid(double amount);
|
||||||
|
|
||||||
virtual double add_fluid(double amount, double heat);
|
virtual double add_fluid(double amount, double heat);
|
||||||
virtual void add_steam(double amount, double t);
|
virtual void add_gas(double steam, double air, double t);
|
||||||
|
|
||||||
virtual double get_volume() const { return volume; } // litres
|
virtual double get_volume() const { return volume; } // litres
|
||||||
virtual double get_level() const { return level; } // litres
|
virtual double get_level() const { return level; } // litres
|
||||||
virtual double get_heat() const { return heat; } // celsius
|
virtual double get_heat() const { return heat; } // celsius
|
||||||
virtual double get_heat_k() const { return conversions::temperature::c_to_k(get_heat()); } // kelvin
|
virtual double get_heat_k() const { return conversions::temperature::c_to_k(get_heat()); } // kelvin
|
||||||
virtual double get_steam() const { return steam; } // grams
|
virtual double get_steam() const { return steam; } // grams
|
||||||
virtual double get_steam_volume() const { return get_volume() - get_level(); } // litres
|
virtual double get_gas() const { return steam + air; } // grams
|
||||||
virtual double get_mass() const { return fluid.l_to_g(get_level()) + get_steam(); } // grams
|
virtual double get_air() const { return air; } // grams
|
||||||
|
virtual double get_gas_volume() const { return get_volume() - get_level(); } // litres
|
||||||
|
virtual double get_mass() const { return fluid.l_to_g(get_level()) + steam + air; } // grams
|
||||||
virtual double get_thermal_mass() const { return get_mass() + extra_mass; } // grams
|
virtual double get_thermal_mass() const { return get_mass() + extra_mass; } // grams
|
||||||
virtual double get_pressure() const; // pascals
|
virtual double get_pressure() const; // pascals
|
||||||
virtual double get_steam_density() const; // g/L
|
virtual double get_gas_density() const; // g/L
|
||||||
|
|
||||||
static double calc_pressure(double heat, double pressure, double mol);
|
static double calc_pressure(double heat, double pressure, double mol);
|
||||||
static double calc_pressure_mol(double heat, double pressure, double volume);
|
static double calc_pressure_mol(double heat, double pressure, double volume);
|
||||||
|
|
|
@ -71,7 +71,7 @@ void pump::update(double dt)
|
||||||
switch(mode)
|
switch(mode)
|
||||||
{
|
{
|
||||||
case mode_t::SRC:
|
case mode_t::SRC:
|
||||||
power = pid.calculate(dt, target, src->get_steam_volume());
|
power = pid.calculate(dt, target, src->get_gas_volume());
|
||||||
break;
|
break;
|
||||||
case mode_t::DST:
|
case mode_t::DST:
|
||||||
power = pid.calculate(dt, target, dst->get_level());
|
power = pid.calculate(dt, target, dst->get_level());
|
||||||
|
|
|
@ -30,7 +30,7 @@ void valve::update(double dt)
|
||||||
if(state > 1) state = 1;
|
if(state > 1) state = 1;
|
||||||
if(state < 0) state = 0;
|
if(state < 0) state = 0;
|
||||||
|
|
||||||
if(src->get_steam_volume() == 0 || dst->get_steam_volume() == 0)
|
if(src->get_gas_volume() == 0 || dst->get_gas_volume() == 0 || (src->get_gas() == 0 && dst->get_gas() == 0))
|
||||||
{
|
{
|
||||||
flow = 0;
|
flow = 0;
|
||||||
return;
|
return;
|
||||||
|
@ -43,26 +43,41 @@ void valve::update(double dt)
|
||||||
double diff = (pressure1 - pressure2);
|
double diff = (pressure1 - pressure2);
|
||||||
double remove = diff - diff * std::pow(1 - m, dt);
|
double remove = diff - diff * std::pow(1 - m, dt);
|
||||||
|
|
||||||
double mol, mass;
|
double ratio_a, ratio_s;
|
||||||
|
double mass_a, mass_s;
|
||||||
|
double mol;
|
||||||
|
|
||||||
if(remove < 0)
|
if(remove < 0)
|
||||||
{
|
{
|
||||||
mol = fluid_holder::calc_pressure_mol(src->get_heat_k(), src->get_steam_volume(), pressure1 - remove);
|
ratio_a = src->get_air() / src->get_gas();
|
||||||
mass = src->get_steam() - src->fluid.mol_to_g(mol);
|
ratio_s = src->get_steam() / src->get_gas();
|
||||||
|
|
||||||
|
mol = fluid_holder::calc_pressure_mol(src->get_heat_k(), src->get_gas_volume(), pressure1 - remove);
|
||||||
|
|
||||||
|
mass_a = src->get_air() - mol / constants::M_air;
|
||||||
|
mass_s = src->get_steam() - src->fluid.mol_to_g(mol);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mol = fluid_holder::calc_pressure_mol(dst->get_heat_k(), dst->get_steam_volume(), pressure2 - remove);
|
ratio_a = dst->get_air() / dst->get_gas();
|
||||||
mass = dst->get_steam() - dst->fluid.mol_to_g(mol);
|
ratio_s = dst->get_steam() / dst->get_gas();
|
||||||
|
|
||||||
|
mol = fluid_holder::calc_pressure_mol(dst->get_heat_k(), dst->get_gas_volume(), pressure2 - remove);
|
||||||
|
|
||||||
|
mass_a = dst->get_air() - mol / constants::M_air;
|
||||||
|
mass_s = dst->get_steam() - dst->fluid.mol_to_g(mol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mass_a *= ratio_a;
|
||||||
|
mass_s *= ratio_s;
|
||||||
|
|
||||||
double heat1 = src->get_heat(); // C
|
double heat1 = src->get_heat(); // C
|
||||||
double heat2 = dst->get_heat();
|
double heat2 = dst->get_heat();
|
||||||
|
|
||||||
src->add_steam(-mass, heat2);
|
src->add_gas(-mass_s, mass_a, heat2);
|
||||||
dst->add_steam(mass, heat1);
|
dst->add_gas(mass_s, mass_a, heat1);
|
||||||
|
|
||||||
this->flow = mass / dt;
|
this->flow = (mass_s + mass_a) / dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,8 @@ void turbine::update(double secs)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void turbine::add_steam(double amount, double t)
|
void turbine::add_gas(double steam, double air, double t)
|
||||||
{
|
{
|
||||||
condenser->add_steam(amount, t);
|
condenser->add_gas(steam, air, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,17 +23,20 @@ public:
|
||||||
virtual double add_heat(double m, double t) { return condenser->add_heat(m, t); }
|
virtual double add_heat(double m, double t) { return condenser->add_heat(m, t); }
|
||||||
virtual double extract_fluid(double amount) { return condenser->extract_fluid(amount); }
|
virtual double extract_fluid(double amount) { return condenser->extract_fluid(amount); }
|
||||||
virtual double add_fluid(double amount, double heat) { return condenser->add_fluid(amount, heat); }
|
virtual double add_fluid(double amount, double heat) { return condenser->add_fluid(amount, heat); }
|
||||||
virtual void add_steam(double amount, double t);
|
virtual void add_gas(double steam, double gas, double t);
|
||||||
|
|
||||||
virtual double get_volume() const { return condenser->get_volume(); }
|
virtual double get_volume() const { return condenser->get_volume(); }
|
||||||
virtual double get_level() const { return condenser->get_level(); }
|
virtual double get_level() const { return condenser->get_level(); }
|
||||||
virtual double get_heat() const { return condenser->get_heat(); } // celsius
|
virtual double get_heat() const { return condenser->get_heat(); } // celsius
|
||||||
|
virtual double get_heat_k() const { return condenser->get_heat_k(); } // kelvin
|
||||||
virtual double get_steam() const { return condenser->get_steam(); } // grams
|
virtual double get_steam() const { return condenser->get_steam(); } // grams
|
||||||
virtual double get_steam_volume() const { return condenser->get_steam_volume(); } // litres
|
virtual double get_gas() const { return condenser->get_gas(); } // grams
|
||||||
|
virtual double get_air() const { return condenser->get_air(); } // grams
|
||||||
|
virtual double get_gas_volume() const { return condenser->get_gas_volume(); } // litres
|
||||||
virtual double get_mass() const { return condenser->get_mass(); } // grams
|
virtual double get_mass() const { return condenser->get_mass(); } // grams
|
||||||
virtual double get_thermal_mass() const { return condenser->get_thermal_mass(); } // grams
|
virtual double get_thermal_mass() const { return condenser->get_thermal_mass(); } // grams
|
||||||
virtual double get_pressure() const { return condenser->get_pressure(); } // pascals
|
virtual double get_pressure() const { return condenser->get_pressure(); } // pascals
|
||||||
virtual double get_steam_density() const { return condenser->get_steam_density(); } // g/L
|
virtual double get_gas_density() const { return condenser->get_gas_density(); } // g/L
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,7 +30,7 @@ double vessel::get_steam_suspended() const
|
||||||
|
|
||||||
double vessel::get_void_ratio() const
|
double vessel::get_void_ratio() const
|
||||||
{
|
{
|
||||||
double density = get_steam_density();
|
double density = get_gas_density();
|
||||||
|
|
||||||
if(density == 0)
|
if(density == 0)
|
||||||
{
|
{
|
||||||
|
@ -70,7 +70,7 @@ void vessel::update(double secs)
|
||||||
steam_suspended *= reactor::fuel::half_life::get(secs, get_bubble_hl());
|
steam_suspended *= reactor::fuel::half_life::get(secs, get_bubble_hl());
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
if(hl <= 0 || steam_suspended < 0)
|
||||||
{
|
{
|
||||||
steam_suspended = 0;
|
steam_suspended = 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue