Merge branch 'critical' into graphics
This commit is contained in:
commit
263543ea4f
|
@ -12,9 +12,18 @@ struct fluid_t
|
||||||
const double gPmol; // g/mol
|
const double gPmol; // g/mol
|
||||||
const double jPg; // J/g latent heat of vaporisation
|
const double jPg; // J/g latent heat of vaporisation
|
||||||
const double jPgk; // J/g/K heat capacity
|
const double jPgk; // J/g/K heat capacity
|
||||||
|
const double bubble_speed; // m/s
|
||||||
|
|
||||||
const coolant::vapor_pressure vapor_pressure;
|
const coolant::vapor_pressure vapor_pressure;
|
||||||
|
|
||||||
constexpr fluid_t(double gPl, double gPmol, double jPg, double jPgk, coolant::vapor_pressure vapor_pressure) : gPl(gPl), gPmol(gPmol), jPg(jPg), jPgk(jPgk), vapor_pressure(vapor_pressure) { }
|
constexpr fluid_t(double gPl, double gPmol, double jPg, double jPgk, double bubble_speed, coolant::vapor_pressure vapor_pressure) :
|
||||||
|
gPl(gPl), gPmol(gPmol),
|
||||||
|
jPg(jPg), jPgk(jPgk),
|
||||||
|
vapor_pressure(vapor_pressure),
|
||||||
|
bubble_speed(bubble_speed)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
constexpr double g_to_mol(double g) const { return g / gPmol; }
|
constexpr double g_to_mol(double g) const { return g / gPmol; }
|
||||||
constexpr double mol_to_g(double mol) const { return mol * gPmol; }
|
constexpr double mol_to_g(double mol) const { return mol * gPmol; }
|
||||||
|
@ -24,7 +33,7 @@ struct fluid_t
|
||||||
constexpr double l_to_mol(double l) const { return g_to_mol(l_to_g(l)); }
|
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, 2257, 4.1816, {8.07131, 1730.63, 233.426});
|
constexpr const fluid_t WATER = fluid_t(1000, 18, 2257, 4.1816, 0.3, {8.07131, 1730.63, 233.426});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,12 @@ static bool win_should_close = false;
|
||||||
static mesh MeshScene, MeshText;
|
static mesh MeshScene, MeshText;
|
||||||
|
|
||||||
void GLAPIENTRY cb_debug_message(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam)
|
void GLAPIENTRY cb_debug_message(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam)
|
||||||
|
{
|
||||||
|
if(severity != GL_DEBUG_SEVERITY_NOTIFICATION)
|
||||||
{
|
{
|
||||||
std::cout << "GL CALLBACK: " << message << "\n";
|
std::cout << "GL CALLBACK: " << message << "\n";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void window::create()
|
void window::create()
|
||||||
{
|
{
|
||||||
|
@ -90,10 +93,10 @@ void window::create()
|
||||||
glViewport(0, 0, 800, 600);
|
glViewport(0, 0, 800, 600);
|
||||||
}
|
}
|
||||||
|
|
||||||
void window::loop()
|
void window::loop(const char* str)
|
||||||
{
|
{
|
||||||
MeshText.bind();
|
MeshText.bind();
|
||||||
font::generate(MeshText, "Hello, World!\nThis is cool!\n=)", 0.1);
|
font::generate(MeshText, str, 0.1);
|
||||||
|
|
||||||
glm::mat4 mat_projection = glm::perspective(glm::radians(90.0f), 1.0f, 0.01f, 20.f);
|
glm::mat4 mat_projection = glm::perspective(glm::radians(90.0f), 1.0f, 0.01f, 20.f);
|
||||||
glUniformMatrix4fv(shader::gl_projection, 1, false, &mat_projection[0][0]);
|
glUniformMatrix4fv(shader::gl_projection, 1, false, &mat_projection[0][0]);
|
||||||
|
|
|
@ -8,7 +8,7 @@ namespace sim::graphics::window
|
||||||
|
|
||||||
void create();
|
void create();
|
||||||
bool should_close();
|
bool should_close();
|
||||||
void loop();
|
void loop(const char* str);
|
||||||
void destroy();
|
void destroy();
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
|
|
28
src/main.cpp
28
src/main.cpp
|
@ -2,7 +2,7 @@
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <iostream>
|
#include <sstream>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include "reactor/builder.hpp"
|
#include "reactor/builder.hpp"
|
||||||
|
@ -32,6 +32,21 @@ int main()
|
||||||
std::random_device rd;
|
std::random_device rd;
|
||||||
std::mt19937 rand(rd());
|
std::mt19937 rand(rd());
|
||||||
|
|
||||||
|
sim::reactor::coolant::vessel vessel(8, 10, 300, sim::coolant::WATER);
|
||||||
|
sim::reactor::reactor<5, 5> reactor = sim::reactor::builder<5, 5>(
|
||||||
|
sim::reactor::fuel::fuel_rod(2000, 4000),
|
||||||
|
sim::reactor::control::control_rod(vessel, 10000, 1),
|
||||||
|
sim::reactor::coolant::pipe(vessel), {
|
||||||
|
"#C#C#",
|
||||||
|
"CFCFC",
|
||||||
|
"#C#C#",
|
||||||
|
"CFCFC",
|
||||||
|
"#C#C#"
|
||||||
|
});
|
||||||
|
|
||||||
|
sim::coolant::valve<sim::reactor::coolant::vessel> valve(vessel, 1, 500);
|
||||||
|
sim::coolant::pump<sim::reactor::coolant::vessel> pump(vessel, 1e4, 15);
|
||||||
|
|
||||||
graphics::window::create();
|
graphics::window::create();
|
||||||
|
|
||||||
long clock = get_now();
|
long clock = get_now();
|
||||||
|
@ -43,8 +58,17 @@ int main()
|
||||||
double dt = (double)passed / 1e6;
|
double dt = (double)passed / 1e6;
|
||||||
clock += passed;
|
clock += passed;
|
||||||
|
|
||||||
|
std::stringstream ss;
|
||||||
|
|
||||||
|
reactor.update(rand, dt);
|
||||||
|
pump.update(dt);
|
||||||
|
valve.update(dt);
|
||||||
|
vessel.update(dt);
|
||||||
|
|
||||||
|
ss << "Reactor Vessel\n\n" << vessel;
|
||||||
|
|
||||||
graphics::camera::update(dt);
|
graphics::camera::update(dt);
|
||||||
graphics::window::loop();
|
graphics::window::loop(ss.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
graphics::window::destroy();
|
graphics::window::destroy();
|
||||||
|
|
|
@ -11,7 +11,7 @@ pipe::pipe(coolant::vessel& v)
|
||||||
|
|
||||||
double pipe::get_k(val_t type) const
|
double pipe::get_k(val_t type) const
|
||||||
{
|
{
|
||||||
return vessel->get_level() / vessel->get_volume() * 0.5;
|
return vessel->get_level() / vessel->get_volume() * (1 - vessel->get_void_ratio()) * 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pipe::update(double secs)
|
void pipe::update(double secs)
|
||||||
|
|
|
@ -2,17 +2,31 @@
|
||||||
#include "vessel.hpp"
|
#include "vessel.hpp"
|
||||||
#include "../../constants.hpp"
|
#include "../../constants.hpp"
|
||||||
#include "../../conversions/temperature.hpp"
|
#include "../../conversions/temperature.hpp"
|
||||||
|
#include "../fuel/half_life.hpp"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
using namespace sim::reactor::coolant;
|
using namespace sim::reactor::coolant;
|
||||||
|
|
||||||
vessel::vessel(double level, double volume, sim::coolant::fluid_t fluid) : volume(volume), fluid(fluid)
|
constexpr static double calc_cylinder(double h, double d)
|
||||||
{
|
{
|
||||||
this->level = level;
|
double r = d / 2;
|
||||||
|
|
||||||
|
return M_PI * r * r * h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vessel::update()
|
vessel::vessel(double height, double diameter, double level, sim::coolant::fluid_t fluid) :
|
||||||
|
height(height),
|
||||||
|
diameter(diameter),
|
||||||
|
volume(calc_cylinder(height, diameter)),
|
||||||
|
fluid(fluid),
|
||||||
|
level(level),
|
||||||
|
bubble_hl(height * 0.5 / fluid.bubble_speed)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void vessel::update(double secs)
|
||||||
{
|
{
|
||||||
double V = (volume - level) * 0.001;
|
double V = (volume - level) * 0.001;
|
||||||
double P = fluid.vapor_pressure.calc_p(heat);
|
double P = fluid.vapor_pressure.calc_p(heat);
|
||||||
|
@ -46,6 +60,9 @@ void vessel::update()
|
||||||
steam = s;
|
steam = s;
|
||||||
level = fluid.g_to_l(l);
|
level = fluid.g_to_l(l);
|
||||||
heat -= diff * fluid.jPg / (fluid.l_to_g(level) + steam) / fluid.jPgk;
|
heat -= diff * fluid.jPg / (fluid.l_to_g(level) + steam) / fluid.jPgk;
|
||||||
|
|
||||||
|
if(diff > 0) steam_suspended += diff;
|
||||||
|
steam_suspended *= fuel::half_life::get(secs, bubble_hl);
|
||||||
}
|
}
|
||||||
|
|
||||||
double vessel::add_heat(double t1)
|
double vessel::add_heat(double t1)
|
||||||
|
@ -116,6 +133,7 @@ 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() * 0.001) << " kPa\n";
|
o << "Pressure: " << (v.get_pressure() * 0.001) << " kPa\n";
|
||||||
|
o << "Void Ratio: " << (v.get_void_ratio() * 100) << " %\n";
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,26 +13,34 @@ class vessel
|
||||||
double level; // litres
|
double level; // litres
|
||||||
double heat = 0; // celcius
|
double heat = 0; // celcius
|
||||||
double steam = 0; // grams
|
double steam = 0; // grams
|
||||||
|
double steam_suspended = 0; // grams
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
const double height; // meters
|
||||||
|
const double diameter; // meters
|
||||||
const double volume; // litres
|
const double volume; // litres
|
||||||
|
const double bubble_hl; // seconds
|
||||||
|
|
||||||
const sim::coolant::fluid_t fluid;
|
const sim::coolant::fluid_t fluid;
|
||||||
|
|
||||||
vessel(double level, double volume, sim::coolant::fluid_t fluid);
|
vessel(double height, double diameter, double level, sim::coolant::fluid_t fluid);
|
||||||
|
|
||||||
void update();
|
void update(double secs);
|
||||||
double add_heat(double amount);
|
double add_heat(double amount);
|
||||||
double add_fluid(double amount, double heat);
|
double add_fluid(double amount, double heat);
|
||||||
double extract_steam(double dt, double a, double p2);
|
double extract_steam(double dt, double a, double p2);
|
||||||
|
|
||||||
constexpr double get_volume() const { return volume; }
|
constexpr double get_volume() const { return volume; } // litres
|
||||||
constexpr double get_level() const { return level; }
|
constexpr double get_level() const { return level; } // litres
|
||||||
constexpr double get_heat() const { return heat; }
|
constexpr double get_heat() const { return heat; } // celsius
|
||||||
constexpr double get_steam() const { return steam; }
|
constexpr double get_steam() const { return steam; } // grams
|
||||||
constexpr double get_mass() const { return fluid.l_to_g(level) + steam; }
|
constexpr double get_mass() const { return fluid.l_to_g(level) + steam; } // grams
|
||||||
|
constexpr double get_steam_density() const { return steam / (volume - level); } // g/L
|
||||||
|
constexpr double get_steam_suspended() const { return steam_suspended; } // grams
|
||||||
|
constexpr double get_void_ratio() const { double s = steam_suspended / get_steam_density(); return s / (level + s); }
|
||||||
|
|
||||||
double get_pressure() const;
|
double get_pressure() const; // pascals
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue