big code refactor

This commit is contained in:
Jay Robson 2024-02-16 16:51:25 +11:00
parent 4753489a2b
commit c76e6b9a7a
70 changed files with 544 additions and 483 deletions

61
input.yaml Normal file
View File

@ -0,0 +1,61 @@
- QualifiedName: sim::reactor::reactor
NewName: Reactor
- QualifiedName: sim::reactor::rod
NewName: Rod
- QualifiedName: sim::reactor::fuel::fuel_rod
NewName: FuelRod
- QualifiedName: sim::reactor::fuel::sample
NewName: Sample
- QualifiedName: sim::reactor::fuel::waste
NewName: Waste
- QualifiedName: sim::reactor::coolant::heater
NewName: Heater
- QualifiedName: sim::reactor::coolant::pipe
NewName: Pipe
- QualifiedName: sim::reactor::coolant::vessel
NewName: Vessel
- QualifiedName: sim::reactor::control::boron_rod
NewName: BoronRod
- QualifiedName: sim::reactor::control::graphite_rod
NewName: GraphiteRod
- QualifiedName: sim::graphics::monitor::core
NewName: Core
- QualifiedName: sim::graphics::monitor::primary_loop
NewName: PrimaryLoop
- QualifiedName: sim::graphics::monitor::secondary_loop
NewName: SecondaryLoop
- QualifiedName: sim::graphics::monitor::turbine
NewName: Turbine
- QualifiedName: sim::graphics::monitor::vessel
NewName: Vessel
- QualifiedName: sim::graphics::mesh
NewName: Mesh
- QualifiedName: sim::graphics::glmesh
NewName: GLMesh
- QualifiedName: sim::graphics::focus::focus_t
NewName: Focus
- QualifiedName: sim::electric::turbine
NewName: Turbine
- QualifiedName: sim::coolant::condenser
NewName: Condenser
- QualifiedName: sim::coolant::condenser_secondary
NewName: CondenserSecondary
- QualifiedName: sim::coolant::evaporator
NewName: Evaporator
- QualifiedName: sim::coolant::fluid_holder
NewName: FluidHolder
- QualifiedName: sim::coolant::fluid_t
NewName: Fluid
- QualifiedName: sim::coolant::pump
NewName: Pump
- QualifiedName: sim::coolant::valve
NewName: Valve
- QualifiedName: sim::coolant::sink
NewName: Sink
- QualifiedName: sim::coolant::vapor_pressure
NewName: VaporPressure
- QualifiedName: sim::graphics::widget::clock
NewName: Clock
- QualifiedName: sim::system
NewName: System

View File

@ -13,28 +13,28 @@ constexpr static double calc_cylinder(double h, double d)
return M_PI * r * r * h * 1000;
}
condenser::condenser(fluid_t type, double height, double diameter, double mass, double level) :
height(height), diameter(diameter), fluid_holder(type, calc_cylinder(height, diameter), mass)
Condenser::Condenser(Fluid type, double height, double diameter, double mass, double level) :
height(height), diameter(diameter), FluidHolder(type, calc_cylinder(height, diameter), mass)
{
this->level = level;
}
condenser::condenser(const Json::Value& node) :
Condenser::Condenser(const Json::Value& node) :
height(node["height"].asDouble()),
diameter(node["diameter"].asDouble()),
fluid_holder(node)
FluidHolder(node)
{
}
void condenser::update(double secs)
void Condenser::update(double secs)
{
update_base(secs);
}
condenser::operator Json::Value() const
Condenser::operator Json::Value() const
{
Json::Value node(fluid_holder::operator::Json::Value());
Json::Value node(FluidHolder::operator::Json::Value());
node["height"] = height;
node["diameter"] = diameter;

View File

@ -6,15 +6,15 @@
namespace sim::coolant
{
class condenser : public fluid_holder
class Condenser : public FluidHolder
{
const double height;
const double diameter;
public:
condenser(fluid_t type, double height, double diameter, double mass, double level);
condenser(const Json::Value& node);
Condenser(Fluid type, double height, double diameter, double mass, double level);
Condenser(const Json::Value& node);
void update(double dt);

View File

@ -6,19 +6,19 @@
using namespace sim::coolant;
condenser_secondary::condenser_secondary(condenser* primary, evaporator* source, double volume) :
primary(primary), source(source), fluid_holder(primary->fluid, volume, 0)
CondenserSecondary::CondenserSecondary(Condenser* primary, Evaporator* source, double volume) :
primary(primary), source(source), FluidHolder(primary->fluid, volume, 0)
{
}
double condenser_secondary::add_fluid(double amount, double heat)
double CondenserSecondary::add_fluid(double amount, double heat)
{
heat = primary->add_heat(fluid.l_to_g(amount), heat);
return source->add_fluid(amount, heat);
}
void condenser_secondary::update(double dt)
void CondenserSecondary::update(double dt)
{
heat = primary->add_heat(fluid.l_to_g(level), heat);
}

View File

@ -8,14 +8,14 @@
namespace sim::coolant
{
class condenser_secondary : public fluid_holder
class CondenserSecondary : public FluidHolder
{
condenser* const primary;
evaporator* const source;
Condenser* const primary;
Evaporator* const source;
public:
condenser_secondary(condenser* primary, evaporator* source, double volume);
CondenserSecondary(Condenser* primary, Evaporator* source, double volume);
virtual double add_heat(double m, double t) { return source->add_heat(m, t); }
virtual double extract_fluid(double amount) { return source->extract_fluid(amount); }

View File

@ -14,28 +14,28 @@ constexpr static double calc_cylinder(double h, double d)
return M_PI * r * r * h * 1000;
}
evaporator::evaporator(fluid_t type, double height, double diameter, double mass, double level) :
Evaporator::Evaporator(Fluid type, double height, double diameter, double mass, double level) :
height(height),
diameter(diameter),
fluid_holder(type, calc_cylinder(height, diameter), mass)
FluidHolder(type, calc_cylinder(height, diameter), mass)
{
this->level = level;
}
evaporator::evaporator(const Json::Value& node) :
Evaporator::Evaporator(const Json::Value& node) :
height(node["height"].asDouble()),
diameter(node["diameter"].asDouble()),
fluid_holder(node)
FluidHolder(node)
{
steam_output = node["steam_output"].asDouble();
}
double evaporator::get_steam_output()
double Evaporator::get_steam_output()
{
return steam_output;
}
void evaporator::update(double dt)
void Evaporator::update(double dt)
{
steam_output = steam / dt;
steam = 0;
@ -53,9 +53,9 @@ void evaporator::update(double dt)
update_base(dt);
}
evaporator::operator Json::Value() const
Evaporator::operator Json::Value() const
{
Json::Value node(fluid_holder::operator::Json::Value());
Json::Value node(FluidHolder::operator::Json::Value());
node["height"] = height;
node["diameter"] = diameter;

View File

@ -6,7 +6,7 @@
namespace sim::coolant
{
class evaporator : public fluid_holder
class Evaporator : public FluidHolder
{
const double height;
const double diameter;
@ -15,8 +15,8 @@ class evaporator : public fluid_holder
public:
evaporator(fluid_t type, double height, double diameter, double mass, double level);
evaporator(const Json::Value& node);
Evaporator(Fluid type, double height, double diameter, double mass, double level);
Evaporator(const Json::Value& node);
operator Json::Value() const;

View File

@ -8,22 +8,22 @@
namespace sim::coolant
{
struct fluid_t
struct Fluid
{
const double gPl; // g/L
const double gPmol; // g/mol
const double jPg; // J/g latent heat of vaporisation
const coolant::vapor_pressure vapor_pressure;
const coolant::VaporPressure vapor_pressure;
constexpr fluid_t(double gPl, double gPmol, double jPg, coolant::vapor_pressure vapor_pressure) :
constexpr Fluid(double gPl, double gPmol, double jPg, coolant::VaporPressure vapor_pressure) :
gPl(gPl), gPmol(gPmol), jPg(jPg),
vapor_pressure(vapor_pressure)
{
}
fluid_t(const Json::Value& node) :
Fluid(const Json::Value& node) :
gPl(node["gPl"].asDouble()),
gPmol(node["gPmol"].asDouble()),
jPg(node["jPg"].asDouble()),
@ -53,7 +53,7 @@ struct fluid_t
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, {8.07131 + 2.124903, 1730.63, 233.426 - 273.15});
constexpr const Fluid WATER = Fluid(1000, 18, 2257, {8.07131 + 2.124903, 1730.63, 233.426 - 273.15});
}

View File

@ -9,12 +9,12 @@
using namespace sim::coolant;
fluid_holder::fluid_holder(fluid_t fluid, double volume, double extra_mass) : fluid(fluid), volume(volume), extra_mass(extra_mass)
FluidHolder::FluidHolder(Fluid fluid, double volume, double extra_mass) : fluid(fluid), volume(volume), extra_mass(extra_mass)
{
}
fluid_holder::fluid_holder(const Json::Value& node) : fluid(node["fluid"]), volume(node["volume"].asDouble()), extra_mass(node["extra_mass"].asDouble())
FluidHolder::FluidHolder(const Json::Value& node) : fluid(node["fluid"]), volume(node["volume"].asDouble()), extra_mass(node["extra_mass"].asDouble())
{
level = node["level"].asDouble();
steam = node["steam"].asDouble();
@ -22,7 +22,7 @@ fluid_holder::fluid_holder(const Json::Value& node) : fluid(node["fluid"]), volu
heat = node["heat"].asDouble();
}
double fluid_holder::add_heat(double m1, double t1)
double FluidHolder::add_heat(double m1, double t1)
{
double t2 = get_heat();
double t = t1 - t2;
@ -37,7 +37,7 @@ double fluid_holder::add_heat(double m1, double t1)
return heat;
}
double fluid_holder::add_fluid(double v2, double t2)
double FluidHolder::add_fluid(double v2, double t2)
{
if(level + v2 <= 0)
{
@ -61,7 +61,7 @@ double fluid_holder::add_fluid(double v2, double t2)
return v2;
}
double fluid_holder::extract_fluid(double amount)
double FluidHolder::extract_fluid(double amount)
{
if(amount < level - 1e-3)
{
@ -77,7 +77,7 @@ double fluid_holder::extract_fluid(double amount)
return amount;
}
void fluid_holder::add_gas(double m_s2, double m_a2, double t_2)
void FluidHolder::add_gas(double m_s2, double m_a2, double t_2)
{
double m_2 = m_a2 + m_s2;
double m_1 = get_thermal_mass();
@ -94,32 +94,32 @@ void fluid_holder::add_gas(double m_s2, double m_a2, double t_2)
air += m_a2;
}
double fluid_holder::calc_pressure(double heat, double volume, double mol)
double FluidHolder::calc_pressure(double heat, double volume, double mol)
{
double V = volume * 0.001;
return V == 0 ? 0 : (mol * heat * util::constants::R) / V;
}
double fluid_holder::calc_pressure_mol(double heat, double volume, double pressure)
double FluidHolder::calc_pressure_mol(double heat, double volume, double pressure)
{
double V = volume * 0.001;
return (pressure * V) / (util::constants::R * heat);
}
double fluid_holder::get_pressure() const
double FluidHolder::get_pressure() const
{
return calc_pressure(conversions::temperature::c_to_k(heat), get_gas_volume(), fluid.g_to_mol(steam) + air / util::constants::M_air);
}
double fluid_holder::get_gas_density() const
double FluidHolder::get_gas_density() const
{
double v = get_gas_volume();
return v > 0 ? get_gas() / v : 0;
}
fluid_holder::operator Json::Value() const
FluidHolder::operator Json::Value() const
{
Json::Value node;
@ -135,7 +135,7 @@ fluid_holder::operator Json::Value() const
return node;
}
void fluid_holder::update_base(double secs)
void FluidHolder::update_base(double secs)
{
double mass = get_thermal_mass();

View File

@ -3,13 +3,13 @@
#include <json/json.h>
#include "fluid_t.hpp"
#include "fluid.hpp"
#include "../conversions/temperature.hpp"
namespace sim::coolant
{
class fluid_holder
class FluidHolder
{
public://protected:
@ -20,10 +20,10 @@ class fluid_holder
public:
fluid_holder(fluid_t fluid, double volume, double extra_mass);
fluid_holder(const Json::Value& node);
FluidHolder(Fluid fluid, double volume, double extra_mass);
FluidHolder(const Json::Value& node);
const fluid_t fluid;
const Fluid fluid;
const double volume; // litres
const double extra_mass; // grams

View File

@ -8,7 +8,7 @@
using namespace sim::coolant;
pump::pump(fluid_holder* src, fluid_holder* dst, double mass, double radius, double power, double l_per_rev, double friction, mode_t mode, double target) :
Pump::Pump(FluidHolder* src, FluidHolder* dst, double mass, double radius, double power, double l_per_rev, double friction, mode_t mode, double target) :
src(src),
dst(dst),
mass(mass),
@ -22,39 +22,39 @@ pump::pump(fluid_holder* src, fluid_holder* dst, double mass, double radius, dou
}
double pump::get_flow_target() const
double Pump::get_flow_target() const
{
return l_per_rev * get_rpm() * 60;
}
double pump::get_flow() const
double Pump::get_flow() const
{
return flow;
}
double pump::get_flow_mass() const
double Pump::get_flow_mass() const
{
return src->fluid.l_to_g(flow);
}
double pump::get_rpm() const
double Pump::get_rpm() const
{
return velocity / (M_PI * mass * 0.001 * radius * radius);
}
double pump::get_power() const
double Pump::get_power() const
{
return power;
}
const char* pump::get_state_string()
const char* Pump::get_state_string()
{
if(!powered) return "Off";
if(power == 0) return "Idle";
return "On";
}
void pump::update(double dt)
void Pump::update(double dt)
{
if(powered)
{
@ -94,17 +94,17 @@ void pump::update(double dt)
flow = dst_volume / dt;
}
static pump::mode_t get_mode(std::string mode)
static Pump::mode_t get_mode(std::string mode)
{
if(mode == "SRC")
return pump::mode_t::SRC;
return Pump::mode_t::SRC;
if(mode == "DST")
return pump::mode_t::DST;
return Pump::mode_t::DST;
return pump::mode_t::NONE;
return Pump::mode_t::NONE;
}
pump::pump(const Json::Value& node, fluid_holder* src, fluid_holder* dst) :
Pump::Pump(const Json::Value& node, FluidHolder* src, FluidHolder* dst) :
mode(get_mode(node["mode"].asString())),
mass(node["mass"].asDouble()),
radius(node["radius"].asDouble()),
@ -122,7 +122,7 @@ pump::pump(const Json::Value& node, fluid_holder* src, fluid_holder* dst) :
powered = node["powered"].asBool();
}
pump::operator Json::Value() const
Pump::operator Json::Value() const
{
Json::Value node;

View File

@ -7,10 +7,10 @@
namespace sim::coolant
{
class pump
class Pump
{
fluid_holder* const src;
fluid_holder* const dst;
FluidHolder* const src;
FluidHolder* const dst;
util::PID pid {1, 0, 100, 0, 0};
@ -38,8 +38,8 @@ public:
bool powered = false;
pump(fluid_holder* src, fluid_holder* dst, double mass, double radius, double power, double l_per_rev, double friction, mode_t mode, double target);
pump(const Json::Value& node, fluid_holder* src, fluid_holder* dst);
Pump(FluidHolder* src, FluidHolder* dst, double mass, double radius, double power, double l_per_rev, double friction, mode_t mode, double target);
Pump(const Json::Value& node, FluidHolder* src, FluidHolder* dst);
double get_flow() const; // L/s
double get_flow_target() const; // L/s

View File

@ -3,11 +3,11 @@
using namespace sim::coolant;
sink::sink(fluid_t type, double heat, double pressure, double steam_density) :
Sink::Sink(Fluid type, double heat, double pressure, double steam_density) :
heat(heat),
pressure(pressure),
steam_density(steam_density),
fluid_holder(type, 2e9, 0)
FluidHolder(type, 2e9, 0)
{
level = 1e9;
}

View File

@ -10,7 +10,7 @@
namespace sim::coolant
{
class sink : public fluid_holder
class Sink : public FluidHolder
{
public:
@ -18,7 +18,7 @@ public:
double pressure;
double steam_density;
sink(fluid_t type, double heat, double pressure, double steam_density);
Sink(Fluid type, double heat, double pressure, double steam_density);
virtual double add_heat(double m, double t) { return t; }
virtual double extract_fluid(double amount) { return amount; }

View File

@ -8,27 +8,27 @@
using namespace sim::coolant;
valve::valve(fluid_holder* src, fluid_holder* dst, double state, double max) : src(src), dst(dst), max(max)
Valve::Valve(FluidHolder* src, FluidHolder* dst, double state, double max) : src(src), dst(dst), max(max)
{
this->state = state;
}
void valve::add_open_speed(double v)
void Valve::add_open_speed(double v)
{
speed += v;
}
void valve::clear_open_speed()
void Valve::clear_open_speed()
{
speed = 0;
}
void valve::toggle_auto()
void Valve::toggle_auto()
{
set_auto(!auto_on);
}
void valve::set_auto(bool state)
void Valve::set_auto(bool state)
{
if(state)
{
@ -44,7 +44,7 @@ void valve::set_auto(bool state)
speed = 0;
}
void valve::update(double dt)
void Valve::update(double dt)
{
if(auto_on)
{
@ -82,7 +82,7 @@ void valve::update(double dt)
ratio_a = src->get_air() / src->get_gas();
ratio_s = src->get_steam() / src->get_gas();
mol = fluid_holder::calc_pressure_mol(src->get_heat_k(), src->get_gas_volume(), pressure1 - remove);
mol = FluidHolder::calc_pressure_mol(src->get_heat_k(), src->get_gas_volume(), pressure1 - remove);
mass_a = src->get_air() - mol / util::constants::M_air;
mass_s = src->get_steam() - src->fluid.mol_to_g(mol);
@ -93,7 +93,7 @@ void valve::update(double dt)
ratio_a = dst->get_air() / dst->get_gas();
ratio_s = dst->get_steam() / dst->get_gas();
mol = fluid_holder::calc_pressure_mol(dst->get_heat_k(), dst->get_gas_volume(), pressure2 - remove);
mol = FluidHolder::calc_pressure_mol(dst->get_heat_k(), dst->get_gas_volume(), pressure2 - remove);
mass_a = dst->get_air() - mol / util::constants::M_air;
mass_s = dst->get_steam() - dst->fluid.mol_to_g(mol);
@ -111,7 +111,7 @@ void valve::update(double dt)
this->flow = (mass_s + mass_a) / dt;
}
valve::valve(const Json::Value& node, fluid_holder* src, fluid_holder* dst) : src(src), dst(dst), max(node["max"].asDouble()), pid(node["pid"])
Valve::Valve(const Json::Value& node, FluidHolder* src, FluidHolder* dst) : src(src), dst(dst), max(node["max"].asDouble()), pid(node["pid"])
{
state = node["state"].asDouble();
flow = node["flow"].asDouble();
@ -119,7 +119,7 @@ valve::valve(const Json::Value& node, fluid_holder* src, fluid_holder* dst) : sr
auto_on = node["auto_on"].asBool();
}
valve::operator Json::Value() const
Valve::operator Json::Value() const
{
Json::Value node;

View File

@ -7,12 +7,12 @@
namespace sim::coolant
{
class valve
class Valve
{
const double max;
fluid_holder* const src;
fluid_holder* const dst;
FluidHolder* const src;
FluidHolder* const dst;
double speed = 0;
double state = 0;
@ -25,8 +25,8 @@ class valve
public:
valve(fluid_holder* src, fluid_holder* dst, double state, double max);
valve(const Json::Value& node, fluid_holder* src, fluid_holder* dst);
Valve(FluidHolder* src, FluidHolder* dst, double state, double max);
Valve(const Json::Value& node, FluidHolder* src, FluidHolder* dst);
void update(double secs);
void add_open_speed(double v);

View File

@ -5,17 +5,17 @@
using namespace sim::coolant;
double vapor_pressure::calc_p(double t) const
double VaporPressure::calc_p(double t) const
{
return t > -C ? std::pow(10, A - B / (C + t)) : 0;
}
double vapor_pressure::calc_t(double p) const
double VaporPressure::calc_t(double p) const
{
return B / (A - std::log(p) / std::log(10)) - C;
}
vapor_pressure::vapor_pressure(const Json::Value& node) :
VaporPressure::VaporPressure(const Json::Value& node) :
A(node["A"].asDouble()),
B(node["B"].asDouble()),
C(node["C"].asDouble())
@ -23,7 +23,7 @@ vapor_pressure::vapor_pressure(const Json::Value& node) :
}
vapor_pressure::operator Json::Value() const
VaporPressure::operator Json::Value() const
{
Json::Value node;

View File

@ -6,13 +6,13 @@
namespace sim::coolant
{
struct vapor_pressure
struct VaporPressure
{
const double A, B, C;
constexpr vapor_pressure(double A, double B, double C) : A(A), B(B), C(C) { }
constexpr VaporPressure(double A, double B, double C) : A(A), B(B), C(C) { }
vapor_pressure(const Json::Value& node);
VaporPressure(const Json::Value& node);
operator Json::Value() const;
double calc_p(double t) const;

View File

@ -15,26 +15,26 @@ constexpr static double calc_cylinder(double h, double d)
return M_PI * r * r * h * 1000;
}
turbine::turbine(coolant::fluid_t type, coolant::condenser* condenser, double length, double diameter, double mass) :
Turbine::Turbine(coolant::Fluid type, coolant::Condenser* condenser, double length, double diameter, double mass) :
length(length), diameter(diameter), condenser(condenser),
sim::coolant::fluid_holder(type, calc_cylinder(length, diameter), mass)
sim::coolant::FluidHolder(type, calc_cylinder(length, diameter), mass)
{
}
turbine::turbine(const Json::Value& node, coolant::condenser* condenser) :
Turbine::Turbine(const Json::Value& node, coolant::Condenser* condenser) :
condenser(condenser),
length(node["length"].asDouble()),
diameter(node["diameter"].asDouble()),
friction(node["friction"].asDouble()),
sim::coolant::fluid_holder(node)
sim::coolant::FluidHolder(node)
{
velocity = node["velocity"].asDouble();
phase = node["phase"].asDouble();
breaker_closed = node["breaker_closed"].asBool();
}
void turbine::update(double dt)
void Turbine::update(double dt)
{
double work = get_rpm() / 60 * dt * friction;
phase = std::fmod(phase + util::map( get_rpm(), 0, 60, 0, 2 * M_PI ) * dt, 2 * M_PI);
@ -61,27 +61,27 @@ void turbine::update(double dt)
}
double turbine::get_rpm() const
double Turbine::get_rpm() const
{
return velocity / (M_PI * extra_mass * 0.001 * diameter * diameter * 0.25);
}
double turbine::get_phase_diff() const
double Turbine::get_phase_diff() const
{
double phase_g = std::fmod(system::active.clock * 60, 1) * 2 * M_PI;
double phase_g = std::fmod(System::active.clock * 60, 1) * 2 * M_PI;
return util::mod(phase - phase_g + M_PI, 2*M_PI) - M_PI;
}
void turbine::add_gas(double steam, double air, double t)
void Turbine::add_gas(double steam, double air, double t)
{
double joules = (steam + air) * fluid.jPg;
velocity = std::max(velocity + util::calc_work(joules, extra_mass), 0.0);
condenser->add_gas(steam, air, t);
}
turbine::operator Json::Value() const
Turbine::operator Json::Value() const
{
Json::Value node(fluid_holder::operator::Json::Value());
Json::Value node(FluidHolder::operator::Json::Value());
node["length"] = length;
node["diameter"] = diameter;

View File

@ -7,9 +7,9 @@
namespace sim::electric
{
class turbine : public sim::coolant::fluid_holder
class Turbine : public sim::coolant::FluidHolder
{
coolant::condenser* const condenser;
coolant::Condenser* const condenser;
const double length;
const double diameter;
@ -23,8 +23,8 @@ public:
bool breaker_closed = false;
turbine(coolant::fluid_t type, coolant::condenser* condenser, double length, double diameter, double mass);
turbine(const Json::Value& node, coolant::condenser* condenser);
Turbine(coolant::Fluid type, coolant::Condenser* condenser, double length, double diameter, double mass);
Turbine(const Json::Value& node, coolant::Condenser* condenser);
void update(double dt);
double get_rpm() const;

View File

@ -19,7 +19,7 @@ static bool on_ground = false;
static double yaw = 0, pitch = 0;
static glm::vec<3, double> pos(0, 0, 2);
static glm::vec<3, double> velocity(0);
static mesh collision_scene;
static Mesh collision_scene;
static glm::mat4 camera_mat;
Json::Value camera::serialize()

View File

@ -19,8 +19,8 @@ using namespace sim::graphics;
static glm::vec<3, double> trigger_near;
static glm::vec<3, double> trigger_far;
static std::vector<std::unique_ptr<focus::focus_t>> stack;
static std::unique_ptr<focus::focus_t> state = nullptr;
static std::vector<std::unique_ptr<focus::Focus>> stack;
static std::unique_ptr<focus::Focus> state = nullptr;
static bool mouse_visible = false;
static bool mouse_locked = false;
static bool triggered = false;
@ -179,7 +179,7 @@ void focus::clear_mouse_locked()
clear_focus();
}
void focus::set(std::unique_ptr<focus_t> f)
void focus::set(std::unique_ptr<Focus> f)
{
if(state != nullptr)
{

View File

@ -8,9 +8,9 @@
namespace sim::graphics::focus
{
struct focus_t
struct Focus
{
virtual ~focus_t() { }
virtual ~Focus() { }
virtual bool cursor_is_visible() { return true; }
virtual void on_keypress(int key, int sc, int action, int mods) { }
virtual void on_mouse_button(int button, int action, int mods) { }
@ -28,7 +28,7 @@ bool is_mouse_locked();
void clear_mouse_locked();
glm::vec<3, double> get_trigger_near();
glm::vec<3, double> get_trigger_far();
void set(std::unique_ptr<focus_t> f);
void set(std::unique_ptr<Focus> f);
void on_keypress(int key, int sc, int action, int mods);
void on_mouse_button(int button, int action, int mods);
void on_cursor_pos(double x, double y);

View File

@ -29,28 +29,28 @@ static void cb_keypress(GLFWwindow* win, int key, int sc, int action, int mods)
switch(key)
{
case GLFW_KEY_1:
sim::system::active.speed = 1; // 1 s/s
sim::System::active.speed = 1; // 1 s/s
break;
case GLFW_KEY_2:
sim::system::active.speed = 10; // 10 s/s
sim::System::active.speed = 10; // 10 s/s
break;
case GLFW_KEY_3:
sim::system::active.speed = 60; // 1 min/s
sim::System::active.speed = 60; // 1 min/s
break;
case GLFW_KEY_4:
sim::system::active.speed = 600; // 10 min/s
sim::System::active.speed = 600; // 10 min/s
break;
case GLFW_KEY_5:
sim::system::active.speed = 3600; // 1 h/s
sim::System::active.speed = 3600; // 1 h/s
break;
case GLFW_KEY_6:
sim::system::active.speed = 43200; // 12 h/s
sim::System::active.speed = 43200; // 12 h/s
break;
case GLFW_KEY_O:
sim::system::save();
sim::System::save();
break;
case GLFW_KEY_L:
sim::system::load();
sim::System::load();
break;
}
}

View File

@ -93,7 +93,7 @@ void font::init()
FT_Done_FreeType(ft);
}
void mesh::load_text(const char* text, double size)
void Mesh::load_text(const char* text, double size)
{
std::vector<arrays::vertex> vertices;
std::vector<unsigned int> indices;

View File

@ -9,7 +9,7 @@
using namespace sim::graphics;
constexpr static void init(glmesh* m)
constexpr static void init(GLMesh* m)
{
if(m->vao != 0)
{
@ -27,7 +27,7 @@ constexpr static void init(glmesh* m)
arrays::vertex_attrib_pointers();
}
glmesh::glmesh(glmesh&& o)
GLMesh::GLMesh(GLMesh&& o)
{
vbo = o.vbo;
ebo = o.ebo;
@ -41,14 +41,14 @@ glmesh::glmesh(glmesh&& o)
o.vao = 0;
}
glmesh::~glmesh()
GLMesh::~GLMesh()
{
if(vbo) glDeleteBuffers(1, &vbo);
if(ebo) glDeleteBuffers(1, &ebo);
if(vao) glDeleteVertexArrays(1, &vao);
}
void glmesh::bind()
void GLMesh::bind()
{
init(this);
@ -57,25 +57,25 @@ void glmesh::bind()
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
}
void glmesh::uniform()
void GLMesh::uniform()
{
glUniformMatrix4fv(shader::gl_model, 1, false, &model_matrix[0][0]);
glUniformMatrix4fv(shader::gl_tex_mat, 1, false, &colour_matrix[0][0]);
}
void glmesh::set(const mesh& m, int mode)
void GLMesh::set(const Mesh& m, int mode)
{
glBufferData(GL_ARRAY_BUFFER, m.vertices.size() * sizeof(m.vertices[0]), &m.vertices[0], mode);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, m.indices.size() * sizeof(m.indices[0]), &m.indices[0], mode);
this->size = m.indices.size();
}
void glmesh::render()
void GLMesh::render()
{
render(GL_TRIANGLES);
}
void glmesh::render(int type)
void GLMesh::render(int type)
{
glDrawElements(type, size, GL_UNSIGNED_INT, 0);
}

View File

@ -11,22 +11,22 @@
namespace sim::graphics
{
struct glmesh
struct GLMesh
{
unsigned int vao = 0, vbo = 0, ebo = 0, size = 0;
glm::mat4 model_matrix {1.0f};
glm::mat4 colour_matrix {1.0f};
constexpr glmesh() { }
constexpr GLMesh() { }
glmesh(glmesh&& o);
glmesh(const glmesh& o) = delete;
~glmesh();
GLMesh(GLMesh&& o);
GLMesh(const GLMesh& o) = delete;
~GLMesh();
void bind();
void uniform();
void set(const mesh& m, int mode);
void set(const Mesh& m, int mode);
void render(int type);
void render();
};

View File

@ -10,7 +10,7 @@
using namespace sim::graphics;
void mesh::add(const mesh& o, glm::mat4 mat)
void Mesh::add(const Mesh& o, glm::mat4 mat)
{
unsigned int off = vertices.size();
glm::mat3 mat3(mat);
@ -32,7 +32,7 @@ void mesh::add(const mesh& o, glm::mat4 mat)
}
}
void mesh::set_vertices(const arrays::vertex* data, size_t size)
void Mesh::set_vertices(const arrays::vertex* data, size_t size)
{
vertices.clear();
vertices.reserve(size);
@ -43,7 +43,7 @@ void mesh::set_vertices(const arrays::vertex* data, size_t size)
}
}
void mesh::set_indices(const unsigned int* data, size_t size)
void Mesh::set_indices(const unsigned int* data, size_t size)
{
indices.clear();
indices.reserve(size);
@ -96,7 +96,7 @@ bool ray_intersects_triangle(vec3 ray_origin,
return false;
}
bool mesh::check_focus(double len) const
bool Mesh::check_focus(double len) const
{
auto near = focus::get_trigger_near();
auto far = focus::get_trigger_far();
@ -104,12 +104,12 @@ bool mesh::check_focus(double len) const
return focus::is_triggered() && check_intersect(near, glm::normalize(far - near) * len);
}
bool mesh::check_focus() const
bool Mesh::check_focus() const
{
return check_focus(2.5);
}
bool mesh::check_intersect(vec3 pos, vec3 path) const
bool Mesh::check_intersect(vec3 pos, vec3 path) const
{
double l = glm::length(path);
@ -145,7 +145,7 @@ bool mesh::check_intersect(vec3 pos, vec3 path) const
return false;
}
vec3 mesh::calc_intersect(vec3 pos, vec3 path) const
vec3 Mesh::calc_intersect(vec3 pos, vec3 path) const
{
vec3 normal_last(0);
return calc_intersect(pos, path, normal_last);
@ -187,7 +187,7 @@ static bool calc_intercept_vert(vec3 v[3], vec3 pos, vec3& path, vec3& path_n, v
return true;
}
vec3 mesh::calc_intersect(vec3 pos, vec3 path, vec3& normal_last) const
vec3 Mesh::calc_intersect(vec3 pos, vec3 path, vec3& normal_last) const
{
double l = glm::length(path);
@ -237,9 +237,9 @@ vec3 mesh::calc_intersect(vec3 pos, vec3 path, vec3& normal_last) const
return path;
}
mesh mesh::to_lines() const
Mesh Mesh::to_lines() const
{
mesh m;
Mesh m;
m.vertices = vertices;
for(int i = 0; i < indices.size(); i += 3)

View File

@ -13,21 +13,21 @@
namespace sim::graphics
{
struct mesh
struct Mesh
{
std::vector<arrays::vertex> vertices;
std::vector<unsigned int> indices;
constexpr mesh() { }
constexpr Mesh() { }
void set_vertices(const arrays::vertex* data, size_t size);
void set_indices(const unsigned int* data, size_t size);
void load_model(std::string base, std::string path);
void load_model(std::string path) { load_model(".", path); }
void load_text(const char* text, double size);
void add(const mesh& o, glm::mat4 mat);
void add(const Mesh& o, glm::mat4 mat);
mesh to_lines() const;
Mesh to_lines() const;
bool check_focus() const;
bool check_focus(double len) const;
bool check_intersect(glm::vec<3, double> pos, glm::vec<3, double> path) const;

View File

@ -143,7 +143,7 @@ static unsigned int proc_embedded_texture(aiTexture* tex)
return texture::load_mem((unsigned char*)tex->pcData, tex->mWidth, tex->mHeight, 4);
}
void mesh::load_model(std::string base, std::string filename)
void Mesh::load_model(std::string base, std::string filename)
{
proc_state state {.base = base};
std::string path = base + "/" + filename;

View File

@ -20,9 +20,9 @@ using namespace sim::graphics::monitor;
static void set_all(bool state)
{
for(int i = 0; i < sim::system::active.reactor->rods.size(); i++)
for(int i = 0; i < sim::System::active.reactor->rods.size(); i++)
{
sim::reactor::rod* r = sim::system::active.reactor->rods[i].get();
sim::reactor::Rod* r = sim::System::active.reactor->rods[i].get();
if(r->should_select())
{
@ -31,7 +31,7 @@ static void set_all(bool state)
}
}
struct core_monitor : public focus::focus_t
struct core_monitor : public focus::Focus
{
virtual void on_keypress(int key, int sc, int action, int mods)
{
@ -40,7 +40,7 @@ struct core_monitor : public focus::focus_t
return;
}
sim::system& sys = sim::system::active;
sim::System& sys = sim::System::active;
switch(key)
{
@ -72,16 +72,16 @@ struct core_monitor : public focus::focus_t
}
};
struct core_joystick : public focus::focus_t
struct core_joystick : public focus::Focus
{
virtual void on_cursor_pos(double x, double y)
{
sim::system::active.reactor->add_rod_speed(y * 1e-6);
sim::System::active.reactor->add_rod_speed(y * 1e-6);
}
virtual ~core_joystick()
{
sim::system::active.reactor->reset_rod_speed();
sim::System::active.reactor->reset_rod_speed();
}
virtual void on_mouse_button(int button, int action, int mods)
@ -98,16 +98,16 @@ struct core_joystick : public focus::focus_t
}
};
core::core()
Core::Core()
{
}
void core::init()
void Core::init()
{
mesh1.model_matrix = locations::monitors[2];
mesh1.colour_matrix = arrays::colour({1, 1, 1, 1});
sim::graphics::mesh rmesh;
sim::graphics::Mesh rmesh;
rmesh.load_text("Reactor Core", 0.04);
mesh1.bind();
@ -140,9 +140,9 @@ void core::init()
m_scram.load_model("../assets/model/", "reactor_core_scram.stl");
}
void core::update(double dt)
void Core::update(double dt)
{
sim::system& sys = sim::system::active;
sim::System& sys = sim::System::active;
if(m_monitor.check_focus())
focus::set(std::make_unique<core_monitor>());
@ -168,9 +168,9 @@ void core::update(double dt)
sys.reactor->move_cursor(sys.reactor->height);
}
void core::render()
void Core::render()
{
sim::system& sys = sim::system::active;
sim::System& sys = sim::System::active;
double step = 1 / (sys.vessel->diameter / sys.reactor->cell_width * 0.8);
double sx = 0.5 - (sys.reactor->width - 1) * step / 2.0;
@ -195,7 +195,7 @@ void core::render()
double ox = sx + x * step;
double oy = sy + y * step;
reactor::rod* r = sys.reactor->rods[i].get();
reactor::Rod* r = sys.reactor->rods[i].get();
if(!r->should_display())
{

View File

@ -6,18 +6,18 @@
namespace sim::graphics::monitor
{
class core
class Core
{
sim::graphics::glmesh mesh1, mesh2;
sim::graphics::GLMesh mesh1, mesh2;
sim::graphics::mesh m_monitor;
sim::graphics::mesh m_buttons[9];
sim::graphics::mesh m_joystick;
sim::graphics::mesh m_scram;
sim::graphics::Mesh m_monitor;
sim::graphics::Mesh m_buttons[9];
sim::graphics::Mesh m_joystick;
sim::graphics::Mesh m_scram;
public:
core();
Core();
void init();
void update(double dt);
void render();

View File

@ -15,11 +15,11 @@
using namespace sim::graphics;
using namespace sim::graphics::monitor;
struct valve_joystick : public focus::focus_t
struct valve_joystick : public focus::Focus
{
sim::coolant::valve* active;
sim::coolant::Valve* active;
valve_joystick(sim::coolant::valve* v) : active(v)
valve_joystick(sim::coolant::Valve* v) : active(v)
{
}
@ -49,12 +49,12 @@ struct valve_joystick : public focus::focus_t
};
primary_loop::primary_loop()
PrimaryLoop::PrimaryLoop()
{
}
void primary_loop::init()
void PrimaryLoop::init()
{
mesh1.model_matrix = locations::monitors[3];
mesh2.model_matrix = glm::translate(mesh1.model_matrix, glm::vec3(0.5, 0, 0));
@ -67,7 +67,7 @@ void primary_loop::init()
};
std::stringstream ss;
sim::graphics::mesh rmesh;
sim::graphics::Mesh rmesh;
ss << "Turbine Bypass Valve\n\n";
ss << "Opened\nFlow\nSetpoint\n\n";
@ -104,15 +104,15 @@ void primary_loop::init()
m_switch_inlet.load_model("../assets/model", "turbine_valve_inlet_switch_click.stl");
}
void primary_loop::update(double dt)
void PrimaryLoop::update(double dt)
{
system& sys = sim::system::active;
System& sys = sim::System::active;
clock_now += dt;
if(clock_at + 1.0/30.0 < clock_now)
{
std::stringstream ss;
sim::graphics::mesh rmesh;
sim::graphics::Mesh rmesh;
clock_at += 1.0/30.0;
ss << "\n\n";
@ -174,7 +174,7 @@ void primary_loop::update(double dt)
gm_switch_pump.model_matrix = glm::translate(glm::mat4(1), glm::vec3(0, sys.primary_pump->powered ? 0.07 : 0, 0));
}
void primary_loop::render()
void PrimaryLoop::render()
{
mesh1.bind();
mesh1.uniform();

View File

@ -6,25 +6,25 @@
namespace sim::graphics::monitor
{
class primary_loop
class PrimaryLoop
{
glmesh mesh1, mesh2;
GLMesh mesh1, mesh2;
double clock_at = 0, clock_now = 0;
glmesh gm_switch_pump;
glmesh gm_switch_bypass;
glmesh gm_switch_inlet;
GLMesh gm_switch_pump;
GLMesh gm_switch_bypass;
GLMesh gm_switch_inlet;
mesh m_joystick_turbine_bypass;
mesh m_joystick_turbine_inlet;
Mesh m_joystick_turbine_bypass;
Mesh m_joystick_turbine_inlet;
mesh m_switch_pump;
mesh m_switch_bypass;
mesh m_switch_inlet;
Mesh m_switch_pump;
Mesh m_switch_bypass;
Mesh m_switch_inlet;
public:
primary_loop();
PrimaryLoop();
void init();
void update(double dt);
void render();

View File

@ -15,12 +15,12 @@
using namespace sim::graphics;
using namespace sim::graphics::monitor;
secondary_loop::secondary_loop()
SecondaryLoop::SecondaryLoop()
{
}
void secondary_loop::init()
void SecondaryLoop::init()
{
mesh1.model_matrix = locations::monitors[5];
mesh2.model_matrix = glm::translate(mesh1.model_matrix, glm::vec3(0.5, 0, 0));
@ -33,7 +33,7 @@ void secondary_loop::init()
};
std::stringstream ss;
sim::graphics::mesh rmesh;
sim::graphics::Mesh rmesh;
ss << "Cooling Tower\n\n";
ss << "Heat\nSteam\nPressure\nLevel\n\n";
@ -60,15 +60,15 @@ void secondary_loop::init()
m_switch_3.load_model("../assets/model", "pump_switch_click_3.stl");
}
void secondary_loop::update(double dt)
void SecondaryLoop::update(double dt)
{
system& sys = sim::system::active;
System& sys = sim::System::active;
clock_now += dt;
if(clock_at + 1.0/30.0 < clock_now)
{
std::stringstream ss;
sim::graphics::mesh rmesh;
sim::graphics::Mesh rmesh;
clock_at += 1.0/30.0;
ss << "\n\n";
@ -99,7 +99,7 @@ void secondary_loop::update(double dt)
gm_switch_3.model_matrix = glm::translate(glm::mat4(1), glm::vec3(0, sys.freight_pump->powered ? 0.07 : 0, 0));
}
void secondary_loop::render()
void SecondaryLoop::render()
{
mesh1.bind();
mesh1.uniform();

View File

@ -6,22 +6,22 @@
namespace sim::graphics::monitor
{
class secondary_loop
class SecondaryLoop
{
sim::graphics::glmesh mesh1, mesh2;
sim::graphics::GLMesh mesh1, mesh2;
double clock_at = 0, clock_now = 0;
sim::graphics::glmesh gm_switch_2;
sim::graphics::glmesh gm_switch_3;
sim::graphics::GLMesh gm_switch_2;
sim::graphics::GLMesh gm_switch_3;
sim::graphics::mesh m_joystick_turbine_bypass;
sim::graphics::mesh m_joystick_turbine_inlet;
sim::graphics::mesh m_switch_2;
sim::graphics::mesh m_switch_3;
sim::graphics::Mesh m_joystick_turbine_bypass;
sim::graphics::Mesh m_joystick_turbine_inlet;
sim::graphics::Mesh m_switch_2;
sim::graphics::Mesh m_switch_3;
public:
secondary_loop();
SecondaryLoop();
void init();
void update(double dt);
void render();

View File

@ -15,12 +15,12 @@
using namespace sim::graphics;
using namespace sim::graphics::monitor;
turbine::turbine()
Turbine::Turbine()
{
}
void turbine::init()
void Turbine::init()
{
mesh1.model_matrix = mesh2.model_matrix = locations::monitors[4];
mesh1.colour_matrix = mesh2.colour_matrix = {
@ -31,7 +31,7 @@ void turbine::init()
};
std::stringstream ss;
sim::graphics::mesh rmesh, rmesh2;
sim::graphics::Mesh rmesh, rmesh2;
ss << "Turbine\n\n";
ss << "Heat\nPressure\nSpeed\n\n";
@ -54,15 +54,15 @@ void turbine::init()
m_switch_breaker.load_model("../assets/model", "turbine_breaker_switch_click.stl");
}
void turbine::update(double dt)
void Turbine::update(double dt)
{
system& sys = sim::system::active;
System& sys = sim::System::active;
clock_now += dt;
if(clock_at + 1.0/30.0 < clock_now)
{
std::stringstream ss;
sim::graphics::mesh rmesh, rmesh2;
sim::graphics::Mesh rmesh, rmesh2;
clock_at += 1.0/30.0;
ss << "\n\n";
@ -111,7 +111,7 @@ void turbine::update(double dt)
gm_switch_breaker.model_matrix = glm::translate(glm::mat4(1), glm::vec3(0, sys.turbine->breaker_closed ? 0.07 : 0, 0));
}
void turbine::render()
void Turbine::render()
{
mesh1.bind();
mesh1.uniform();
@ -121,7 +121,7 @@ void turbine::render()
mesh2.uniform();
mesh2.render();
double rpm = system::active.turbine->get_rpm();
double rpm = System::active.turbine->get_rpm();
if(rpm > 3570 && rpm < 3630)
{

View File

@ -6,18 +6,18 @@
namespace sim::graphics::monitor
{
class turbine
class Turbine
{
sim::graphics::glmesh mesh1, mesh2;
sim::graphics::GLMesh mesh1, mesh2;
double clock_at = 0, clock_now = 0;
sim::graphics::glmesh gm_synchroscope_dial;
sim::graphics::glmesh gm_switch_breaker;
sim::graphics::mesh m_switch_breaker;
sim::graphics::GLMesh gm_synchroscope_dial;
sim::graphics::GLMesh gm_switch_breaker;
sim::graphics::Mesh m_switch_breaker;
public:
turbine();
Turbine();
void init();
void update(double dt);
void render();

View File

@ -14,12 +14,12 @@
using namespace sim::graphics::monitor;
vessel::vessel()
Vessel::Vessel()
{
}
void vessel::init()
void Vessel::init()
{
mesh1.model_matrix = locations::monitors[1];
mesh2.model_matrix = glm::translate(mesh1.model_matrix, glm::vec3(0.5, 0, 0));
@ -32,7 +32,7 @@ void vessel::init()
};
std::stringstream ss;
sim::graphics::mesh rmesh;
sim::graphics::Mesh rmesh;
ss << "Reactor Vessel\n\n";
ss << "Heat\n";
@ -51,11 +51,11 @@ void vessel::init()
mesh1.set(rmesh, GL_STATIC_DRAW);
}
void vessel::update(double dt)
void Vessel::update(double dt)
{
std::stringstream ss;
sim::graphics::mesh rmesh;
sim::system& sys = sim::system::active;
sim::graphics::Mesh rmesh;
sim::System& sys = sim::System::active;
clock_now += dt;
if(clock_at + 1.0/30.0 > clock_now)
@ -67,18 +67,18 @@ void vessel::update(double dt)
double crod_min = INFINITY, crod_max = -INFINITY;
clock_at += 1.0/30.0;
sys.reactor->get_stats(sim::reactor::rod::val_t::HEAT, temp_min, temp_max);
sys.reactor->get_stats(sim::reactor::Rod::val_t::HEAT, temp_min, temp_max);
for(int i = 0; i < sys.reactor->size; i++)
{
sim::reactor::rod* r = sys.reactor->rods[i].get();
sim::reactor::Rod* r = sys.reactor->rods[i].get();
if(r->get_id() != 5)
{
continue;
}
auto br = (sim::reactor::control::boron_rod*)r;
auto br = (sim::reactor::control::BoronRod*)r;
double v = br->get_inserted();
if(v > crod_max)
@ -113,7 +113,7 @@ void vessel::update(double dt)
mesh2.set(rmesh, GL_DYNAMIC_DRAW);
}
void vessel::render()
void Vessel::render()
{
mesh1.bind();
mesh1.uniform();

View File

@ -6,14 +6,14 @@
namespace sim::graphics::monitor
{
class vessel
class Vessel
{
sim::graphics::glmesh mesh1, mesh2;
sim::graphics::GLMesh mesh1, mesh2;
double clock_at = 0, clock_now = 0;
public:
vessel();
Vessel();
void init();
void update(double dt);
void render();

View File

@ -18,12 +18,12 @@
using namespace sim::graphics;
static glmesh StaticMeshData;
static widget::clock WidgetClock;
static GLMesh StaticMeshData;
static widget::Clock WidgetClock;
void ui::init()
{
mesh m;
Mesh m;
unsigned int handle = texture::handle_white;
const unsigned int indices[] = {0, 1, 3, 0, 3, 2};

View File

@ -18,10 +18,10 @@
using namespace sim::graphics::widget;
void clock::update(double dt)
void Clock::update(double dt)
{
mesh m;
double at = system::active.clock;
Mesh m;
double at = System::active.clock;
glm::vec2 wsize(resize::get_size() / 2);
std::stringstream ss;
@ -42,7 +42,7 @@ void clock::update(double dt)
data.set(m, GL_DYNAMIC_DRAW);
}
void clock::render()
void Clock::render()
{
data.bind();
data.uniform();

View File

@ -6,9 +6,9 @@
namespace sim::graphics::widget
{
struct clock
struct Clock
{
glmesh data;
GLMesh data;
void update(double dt);
void render();

View File

@ -32,12 +32,12 @@ using namespace sim::graphics;
static GLFWwindow* win;
static bool win_should_close = false;
static glmesh mesh_scene;
static monitor::vessel monitor_vessel;
static monitor::core monitor_core;
static monitor::primary_loop monitor_primary_loop;
static monitor::secondary_loop monitor_secondary_loop;
static monitor::turbine monitor_turbine;
static GLMesh mesh_scene;
static monitor::Vessel monitor_vessel;
static monitor::Core monitor_core;
static monitor::PrimaryLoop monitor_primary_loop;
static monitor::SecondaryLoop monitor_secondary_loop;
static monitor::Turbine monitor_turbine;
glm::mat4 window::projection_matrix;
@ -108,8 +108,8 @@ void window::create()
shader::init_program();
sim::system& sys = sim::system::active;
mesh m, m2;
sim::System& sys = sim::System::active;
Mesh m, m2;
m.load_model("../assets", "scene-baked.glb");
m2.load_model("../assets/model", "monitor_graphics.stl");

View File

@ -6,7 +6,7 @@
#include <cfenv>
#include "reactor/coolant/vessel.hpp"
#include "coolant/fluid_t.hpp"
#include "coolant/fluid.hpp"
#include "coolant/valve.hpp"
#include "coolant/pump.hpp"
@ -42,9 +42,9 @@ int main()
long passed = now - clock;
double dt = (double)passed / 1e6;
clock += passed;
at += dt * sim::system::active.speed;
at += dt * sim::System::active.speed;
sim::system::active.update(dt);
sim::System::active.update(dt);
graphics::camera::update(dt);
graphics::window::update(dt);

View File

@ -11,62 +11,62 @@
using namespace sim::reactor;
sim::reactor::reactor sim::reactor::builder(const int W, const int H, const double CW, const double CH, fuel::fuel_rod fr, coolant::vessel* v, const char** lines)
sim::reactor::Reactor sim::reactor::builder(const int W, const int H, const double CW, const double CH, fuel::FuelRod fr, coolant::Vessel* v, const char** lines)
{
std::vector<std::unique_ptr<rod>> arr(W * H);
std::vector<std::unique_ptr<Rod>> arr(W * H);
for(int y = 0; y < H; y++)
for(int x = 0; x < W; x++)
{
char c = lines[y][x];
std::unique_ptr<rod> r;
std::unique_ptr<Rod> r;
switch(c)
{
case 'F':
r = std::make_unique<fuel::fuel_rod>(fr);
r = std::make_unique<fuel::FuelRod>(fr);
break;
case 'C':
r = std::make_unique<control::boron_rod>(v);
r = std::make_unique<control::BoronRod>(v);
break;
case 'G':
r = std::make_unique<control::graphite_rod>();
r = std::make_unique<control::GraphiteRod>();
break;
case 'H':
r = std::make_unique<coolant::heater>();
r = std::make_unique<coolant::Heater>();
break;
case 'P':
r = std::make_unique<coolant::pipe>(v);
r = std::make_unique<coolant::Pipe>(v);
break;
default:
r = std::make_unique<rod>();
r = std::make_unique<Rod>();
break;
}
arr[y * W + x] = std::move(r);
}
return reactor(&arr[0], W, H, CW, CH);
return Reactor(&arr[0], W, H, CW, CH);
}
std::unique_ptr<rod> sim::reactor::load_rod(const Json::Value& node, coolant::vessel* v)
std::unique_ptr<Rod> sim::reactor::load_rod(const Json::Value& node, coolant::Vessel* v)
{
int id = node["id"].asInt();
switch(id)
{
case 1:
return std::make_unique<fuel::fuel_rod>(node);
return std::make_unique<fuel::FuelRod>(node);
case 2:
return std::make_unique<coolant::pipe>(node, v);
return std::make_unique<coolant::Pipe>(node, v);
case 3:
return std::make_unique<coolant::heater>(node);
return std::make_unique<coolant::Heater>(node);
case 4:
return std::make_unique<control::graphite_rod>(node);
return std::make_unique<control::GraphiteRod>(node);
case 5:
return std::make_unique<control::boron_rod>(node, v);
return std::make_unique<control::BoronRod>(node, v);
}
return std::make_unique<rod>();
return std::make_unique<Rod>();
}

View File

@ -11,8 +11,8 @@
namespace sim::reactor
{
reactor builder(const int W, const int H, const double CW, const double CH, fuel::fuel_rod fr, coolant::vessel* v, const char** lines);
std::unique_ptr<rod> load_rod(const Json::Value& node, coolant::vessel* v);
Reactor builder(const int W, const int H, const double CW, const double CH, fuel::FuelRod fr, coolant::Vessel* v, const char** lines);
std::unique_ptr<Rod> load_rod(const Json::Value& node, coolant::Vessel* v);
};

View File

@ -9,26 +9,26 @@ constexpr double boron_density = 2340000; // g/m^3
constexpr double boron_molar_mass = 10; // g/mol
constexpr double boron_molar_density = boron_density / boron_molar_mass; // mol/m^3
boron_rod::boron_rod(const Json::Value& node, coolant::vessel* v) : coolant::pipe(node, v)
BoronRod::BoronRod(const Json::Value& node, coolant::Vessel* v) : coolant::Pipe(node, v)
{
inserted = node["inserted"].asDouble();
absorbed = node["absorbed"].asDouble();
}
Json::Value boron_rod::serialize() const
Json::Value BoronRod::serialize() const
{
Json::Value node(coolant::pipe::serialize());
Json::Value node(coolant::Pipe::serialize());
node["inserted"] = inserted;
node["absorbed"] = absorbed;
return node;
}
boron_rod::boron_rod(coolant::vessel* v) : coolant::pipe(v)
BoronRod::BoronRod(coolant::Vessel* v) : coolant::Pipe(v)
{
}
void boron_rod::display(std::ostream& o) const
void BoronRod::display(std::ostream& o) const
{
double limit = get_volume() * boron_molar_density;
@ -36,18 +36,18 @@ void boron_rod::display(std::ostream& o) const
o << "Use: " << (absorbed * limit) << " / " << limit << "\n";
};
void boron_rod::set_reactivity(double a)
void BoronRod::set_reactivity(double a)
{
inserted = 1 - a;
}
glm::vec4 boron_rod::get_colour() const
glm::vec4 BoronRod::get_colour() const
{
double v = inserted * 0.75 + 0.25;
return {v, v, v, 1};
}
void boron_rod::update(double secs)
void BoronRod::update(double secs)
{
double limit = get_volume() * boron_molar_density;
@ -62,7 +62,7 @@ void boron_rod::update(double secs)
update_pipe(secs);
}
void boron_rod::update_selected(double a)
void BoronRod::update_selected(double a)
{
inserted -= a;

View File

@ -6,7 +6,7 @@
namespace sim::reactor::control
{
class boron_rod : public coolant::pipe
class BoronRod : public coolant::Pipe
{
double inserted = 1;
double absorbed = 0;
@ -18,8 +18,8 @@ class boron_rod : public coolant::pipe
public:
boron_rod(coolant::vessel* v);
boron_rod(const Json::Value& node, coolant::vessel* v);
BoronRod(coolant::Vessel* v);
BoronRod(const Json::Value& node, coolant::Vessel* v);
virtual Json::Value serialize() const;
virtual void update(double secs);
@ -29,7 +29,7 @@ public:
virtual bool should_display() const { return true; }
virtual bool should_select() const { return true; }
virtual void update_selected(double a);
virtual std::unique_ptr<rod> clone() const { return std::make_unique<boron_rod>(*this); }
virtual std::unique_ptr<Rod> clone() const { return std::make_unique<BoronRod>(*this); }
};
}

View File

@ -5,42 +5,42 @@
using namespace sim::reactor::control;
graphite_rod::graphite_rod(const Json::Value& node) : rod(node)
GraphiteRod::GraphiteRod(const Json::Value& node) : Rod(node)
{
inserted = node["inserted"].asDouble();
}
Json::Value graphite_rod::serialize() const
Json::Value GraphiteRod::serialize() const
{
Json::Value node(rod::serialize());
Json::Value node(Rod::serialize());
node["inserted"] = inserted;
return node;
}
void graphite_rod::display(std::ostream& o) const
void GraphiteRod::display(std::ostream& o) const
{
o << "Inserted: " << (inserted * 100) << "%\n";
};
glm::vec4 graphite_rod::get_colour() const
glm::vec4 GraphiteRod::get_colour() const
{
double v = inserted * 0.75 + 0.25;
return {v, v, v, 1};
}
double graphite_rod::get_k(val_t type) const
double GraphiteRod::get_k(val_t type) const
{
if(type == val_t::HEAT) return 0.5;
return inserted * 0.5;
}
void graphite_rod::set_reactivity(double a)
void GraphiteRod::set_reactivity(double a)
{
inserted = a;
}
void graphite_rod::update(double secs)
void GraphiteRod::update(double secs)
{
update_rod(secs);
@ -48,7 +48,7 @@ void graphite_rod::update(double secs)
vals[val_t::N_FAST] = 0;
}
void graphite_rod::update_selected(double a)
void GraphiteRod::update_selected(double a)
{
inserted += a;

View File

@ -6,7 +6,7 @@
namespace sim::reactor::control
{
class graphite_rod : public sim::reactor::rod
class GraphiteRod : public sim::reactor::Rod
{
double inserted = 0;
@ -20,9 +20,9 @@ class graphite_rod : public sim::reactor::rod
public:
constexpr graphite_rod() {}
constexpr GraphiteRod() {}
graphite_rod(const Json::Value& node);
GraphiteRod(const Json::Value& node);
virtual Json::Value serialize() const;
virtual void update(double secs);
@ -31,7 +31,7 @@ public:
virtual bool should_display() const { return true; }
virtual bool should_select() const { return true; }
virtual void update_selected(double a);
virtual std::unique_ptr<rod> clone() const { return std::make_unique<graphite_rod>(*this); }
virtual std::unique_ptr<Rod> clone() const { return std::make_unique<GraphiteRod>(*this); }
};
}

View File

@ -3,31 +3,31 @@
using namespace sim::reactor::coolant;
heater::heater(const Json::Value& node) : rod(node)
Heater::Heater(const Json::Value& node) : Rod(node)
{
rate = node["rate"].asDouble();
}
Json::Value heater::serialize() const
Json::Value Heater::serialize() const
{
Json::Value node(rod::serialize());
Json::Value node(Rod::serialize());
node["rate"] = rate;
return node;
}
void heater::update(double secs)
void Heater::update(double secs)
{
update_rod(secs);
vals[val_t::HEAT] += rate * secs;
}
void heater::update_selected(double a)
void Heater::update_selected(double a)
{
rate += a;
}
void heater::display(std::ostream& o) const
void Heater::display(std::ostream& o) const
{
o << "Rate: " << rate << " C/s\n";
}

View File

@ -6,7 +6,7 @@
namespace sim::reactor::coolant
{
class heater : public sim::reactor::rod
class Heater : public sim::reactor::Rod
{
double rate = 0;
@ -19,16 +19,16 @@ class heater : public sim::reactor::rod
public:
constexpr heater() {}
constexpr Heater() {}
heater(const Json::Value& node);
Heater(const Json::Value& node);
virtual Json::Value serialize() const;
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);
virtual std::unique_ptr<rod> clone() const { return std::make_unique<heater>(*this); }
virtual std::unique_ptr<Rod> clone() const { return std::make_unique<Heater>(*this); }
};
};

View File

@ -4,38 +4,38 @@
using namespace sim::reactor::coolant;
pipe::pipe(coolant::vessel* v)
Pipe::Pipe(coolant::Vessel* v)
{
this->vessel = v;
this->steam = 0;
}
pipe::pipe(const Json::Value& node, coolant::vessel* v) : vessel(v)
Pipe::Pipe(const Json::Value& node, coolant::Vessel* v) : vessel(v)
{
steam = node["steam"].asDouble();
}
Json::Value pipe::serialize() const
Json::Value Pipe::serialize() const
{
Json::Value node(rod::serialize());
Json::Value node(Rod::serialize());
node["steam"] = steam;
return node;
}
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;
}
void pipe::update(double secs)
void Pipe::update(double secs)
{
update_rod(secs);
update_pipe(secs);
}
void pipe::update_pipe(double secs)
void Pipe::update_pipe(double secs)
{
sim::reactor::reactor* r = (sim::reactor::reactor*)reactor;
sim::reactor::Reactor* r = (sim::reactor::Reactor*)reactor;
double m_heat = r->cell_width * r->cell_width * r->cell_height * 1e6;
vals[val_t::HEAT] = vessel->add_heat(m_heat, vals[val_t::HEAT]);

View File

@ -7,14 +7,14 @@
namespace sim::reactor::coolant
{
class pipe : public sim::reactor::rod
class Pipe : public sim::reactor::Rod
{
protected:
coolant::vessel* vessel;
coolant::Vessel* vessel;
double steam;
virtual double get_k(sim::reactor::rod::val_t type) const;
virtual double get_k(sim::reactor::Rod::val_t type) const;
virtual const char* get_name() const { return "Coolant"; }
virtual int get_id() const { return 2; }
@ -22,11 +22,11 @@ protected:
public:
pipe(coolant::vessel* v);
pipe(const Json::Value& node, coolant::vessel* v);
Pipe(coolant::Vessel* v);
Pipe(const Json::Value& node, coolant::Vessel* v);
virtual Json::Value serialize() const;
virtual std::unique_ptr<rod> clone() const { return std::make_unique<pipe>(*this); }
virtual std::unique_ptr<Rod> clone() const { return std::make_unique<Pipe>(*this); }
virtual bool should_display() const { return true; }
virtual void update(double secs);

View File

@ -16,15 +16,15 @@ constexpr static double calc_cylinder(double h, double d)
return M_PI * r * r * h * 1000;
}
vessel::vessel(sim::coolant::fluid_t fluid, double height, double diameter, double mass, double level, double bubble_hl) :
sim::coolant::fluid_holder(fluid, calc_cylinder(height, diameter), mass),
Vessel::Vessel(sim::coolant::Fluid fluid, double height, double diameter, double mass, double level, double bubble_hl) :
sim::coolant::FluidHolder(fluid, calc_cylinder(height, diameter), mass),
height(height), diameter(diameter), bubble_hl(bubble_hl)
{
this->level = level;
}
vessel::vessel(const Json::Value& node) :
sim::coolant::fluid_holder(node),
Vessel::Vessel(const Json::Value& node) :
sim::coolant::FluidHolder(node),
height(node["height"].asDouble()),
diameter(node["diameter"].asDouble()),
bubble_hl(node["bubble_hl"].asDouble())
@ -32,12 +32,12 @@ vessel::vessel(const Json::Value& node) :
steam_suspended = node["steam_suspended"].asDouble();
}
double vessel::get_steam_suspended() const
double Vessel::get_steam_suspended() const
{
return steam_suspended;
}
double vessel::get_void_ratio() const
double Vessel::get_void_ratio() const
{
double density = get_gas_density();
@ -57,7 +57,7 @@ double vessel::get_void_ratio() const
return s / m;
}
void vessel::update(double secs)
void Vessel::update(double secs)
{
double steam_last = steam;
@ -75,9 +75,9 @@ void vessel::update(double secs)
}
}
vessel::operator Json::Value() const
Vessel::operator Json::Value() const
{
Json::Value node(fluid_holder::operator::Json::Value());
Json::Value node(FluidHolder::operator::Json::Value());
node["height"] = height;
node["diameter"] = diameter;

View File

@ -8,7 +8,7 @@
namespace sim::reactor::coolant
{
class vessel : public sim::coolant::fluid_holder
class Vessel : public sim::coolant::FluidHolder
{
public:
@ -18,8 +18,8 @@ public:
double steam_suspended = 0; // grams
vessel(sim::coolant::fluid_t fluid, double height, double diameter, double mass, double level, double bubble_hl);
vessel(const Json::Value& node);
Vessel(sim::coolant::Fluid fluid, double height, double diameter, double mass, double level, double bubble_hl);
Vessel(const Json::Value& node);
double get_steam_suspended() const; // grams
double get_void_ratio() const;
@ -28,7 +28,7 @@ public:
operator Json::Value() const;
friend std::ostream& operator<<(std::ostream& o, const vessel& v)
friend std::ostream& operator<<(std::ostream& o, const Vessel& v)
{
o << "Volume: " << v.get_volume() << " L\n";
o << "Level: " << v.get_level() << " L\n";

View File

@ -10,24 +10,24 @@ constexpr double fuel_molar_mass = 238.029; // g/mol
constexpr double fuel_molar_density = fuel_density / fuel_molar_mass; // mol/m^3
constexpr double energy_density = 165e11; // J/mol
fuel_rod::fuel_rod(double fuel) : s(fuel)
FuelRod::FuelRod(double fuel) : s(fuel)
{
}
fuel_rod::fuel_rod(const Json::Value& node) : s(node["sample"]), rod(node)
FuelRod::FuelRod(const Json::Value& node) : s(node["sample"]), Rod(node)
{
}
Json::Value fuel_rod::serialize() const
Json::Value FuelRod::serialize() const
{
Json::Value node(rod::serialize());
Json::Value node(Rod::serialize());
node["sample"] = s;
return node;
}
void fuel_rod::display(std::ostream& o) const
void FuelRod::display(std::ostream& o) const
{
double mol = fuel_molar_density * get_volume();
@ -38,14 +38,14 @@ void fuel_rod::display(std::ostream& o) const
o << "Xenon: " << (s.get_xe_135() * mol) << " mol\n";
}
double fuel_rod::get_energy_output() const
double FuelRod::get_energy_output() const
{
double mol = fuel_molar_density * get_volume();
return s.get_energy() * mol * energy_density;
}
void fuel_rod::update(double secs)
void FuelRod::update(double secs)
{
update_rod(secs);

View File

@ -7,9 +7,9 @@
namespace sim::reactor::fuel
{
class fuel_rod : public sim::reactor::rod
class FuelRod : public sim::reactor::Rod
{
sample s;
Sample s;
virtual double get_k(val_t type) const { return 0.5; }
virtual void display(std::ostream& o) const;
@ -21,11 +21,11 @@ class fuel_rod : public sim::reactor::rod
public:
fuel_rod(double fuel);
fuel_rod(const Json::Value& node);
FuelRod(double fuel);
FuelRod(const Json::Value& node);
virtual Json::Value serialize() const;
virtual std::unique_ptr<rod> clone() const { return std::make_unique<fuel_rod>(*this); }
virtual std::unique_ptr<Rod> clone() const { return std::make_unique<FuelRod>(*this); }
virtual bool should_display() const { return true; }
virtual void update(double secs);
};

View File

@ -8,14 +8,14 @@ using namespace sim::reactor::fuel;
constexpr double NEUTRON_BG = 1e-30;
sample::sample(double fuel)
Sample::Sample(double fuel)
{
this->fuel = fuel;
this->u_238 = 1 - fuel;
this->mass = 1;
}
sample::sample(const Json::Value& node) : waste(node["waste"])
Sample::Sample(const Json::Value& node) : waste(node["waste"])
{
fuel = node["fuel"].asDouble();
i_135 = node["i_135"].asDouble();
@ -30,7 +30,7 @@ sample::sample(const Json::Value& node) : waste(node["waste"])
efficiency = node["efficiency"].asDouble();
}
sample::operator Json::Value() const
Sample::operator Json::Value() const
{
Json::Value node;
@ -50,7 +50,7 @@ sample::operator Json::Value() const
return node;
}
void sample::update(double secs)
void Sample::update(double secs)
{
double m;
@ -98,7 +98,7 @@ void sample::update(double secs)
waste.add_fissile(neutrons_fuel * 6);
}
void sample::display(std::ostream& o) const
void Sample::display(std::ostream& o) const
{
o << "Fuel: " << fuel << "\n";
o << "Mass: " << mass << "\n";

View File

@ -8,11 +8,11 @@
namespace sim::reactor::fuel
{
class sample
class Sample
{
constexpr static const double Xe_135_M = 1e6;
sim::reactor::fuel::waste waste;
sim::reactor::fuel::Waste waste;
// mol
double fuel = 0;
@ -32,8 +32,8 @@ class sample
public:
sample(double fuel);
sample(const Json::Value& node);
Sample(double fuel);
Sample(const Json::Value& node);
operator Json::Value() const;
@ -55,7 +55,7 @@ public:
constexpr void clear_slow_neutrons() { slow_neutrons = 0; }
constexpr void add_slow_neutrons(double a) { slow_neutrons += a; }
friend std::ostream& operator<<(std::ostream& o, const sample& s)
friend std::ostream& operator<<(std::ostream& o, const Sample& s)
{
s.display(o);
return o;

View File

@ -4,7 +4,7 @@
using namespace sim::reactor::fuel;
waste::waste(const Json::Value& node)
Waste::Waste(const Json::Value& node)
{
const Json::Value& j_ladder = node["ladder"];
@ -18,7 +18,7 @@ waste::waste(const Json::Value& node)
energy = node["energy"].asDouble();
}
waste::operator Json::Value() const
Waste::operator Json::Value() const
{
Json::Value node;
Json::Value j_ladder;
@ -38,12 +38,12 @@ waste::operator Json::Value() const
return node;
}
void waste::update(double secs)
void Waste::update(double secs)
{
double next[waste::N - 1] = {0};
double next[Waste::N - 1] = {0};
double hl = 1;
for(int i = 0; i < waste::N - 1; hl *= 2, i++)
for(int i = 0; i < Waste::N - 1; hl *= 2, i++)
{
double m = 1 - half_life::get(secs, hl);
double h = high[i] * m;
@ -57,31 +57,31 @@ void waste::update(double secs)
energy += h + l;
}
for(int i = 0; i < waste::N - 1; i++)
for(int i = 0; i < Waste::N - 1; i++)
{
low[i + 1] += next[i];
}
}
void waste::add_fissile(double amount)
void Waste::add_fissile(double amount)
{
double m = 0.5;
for(int i = 0; i < waste::N; i++)
for(int i = 0; i < Waste::N; i++)
{
high[i] += amount * m;
m *= 0.5;
}
}
double waste::extract_neutrons()
double Waste::extract_neutrons()
{
double v = neutrons;
neutrons = 0;
return v;
}
double waste::extract_energy()
double Waste::extract_energy()
{
double v = energy;
energy = 0;

View File

@ -6,7 +6,7 @@
namespace sim::reactor::fuel
{
class waste
class Waste
{
static const int N = 64;
@ -17,9 +17,9 @@ class waste
public:
constexpr waste() { };
constexpr Waste() { };
waste(const Json::Value& node);
Waste(const Json::Value& node);
operator Json::Value() const;

View File

@ -7,9 +7,9 @@
using namespace sim::reactor;
reactor::reactor(std::unique_ptr<rod>* rods, int w, int h, double cw, double ch) : cell_width(cw), cell_height(ch), width(w), height(h), size(w * h)
Reactor::Reactor(std::unique_ptr<Rod>* rods, int w, int h, double cw, double ch) : cell_width(cw), cell_height(ch), width(w), height(h), size(w * h)
{
this->rods = std::vector<std::unique_ptr<rod>>(w * h);
this->rods = std::vector<std::unique_ptr<Rod>>(w * h);
this->cursor = w * h;
for(int i = 0; i < size; i++)
@ -19,7 +19,7 @@ reactor::reactor(std::unique_ptr<rod>* rods, int w, int h, double cw, double ch)
}
}
reactor::reactor(reactor&& o) : cell_width(o.cell_width), cell_height(o.cell_height), width(o.width), height(o.height), size(o.size)
Reactor::Reactor(Reactor&& o) : cell_width(o.cell_width), cell_height(o.cell_height), width(o.width), height(o.height), size(o.size)
{
rods = std::move(o.rods);
cursor = o.cursor;
@ -30,24 +30,24 @@ reactor::reactor(reactor&& o) : cell_width(o.cell_width), cell_height(o.cell_hei
}
}
reactor::reactor(const reactor& o) : cell_width(o.cell_width), cell_height(o.cell_height), width(o.width), height(o.height), size(o.size)
Reactor::Reactor(const Reactor& o) : cell_width(o.cell_width), cell_height(o.cell_height), width(o.width), height(o.height), size(o.size)
{
rods = std::vector<std::unique_ptr<rod>>(width * height);
rods = std::vector<std::unique_ptr<Rod>>(width * height);
cursor = o.cursor;
for(int i = 0; i < size; i++)
{
rods[i] = std::unique_ptr<rod>(o.rods[i]->clone());
rods[i] = std::unique_ptr<Rod>(o.rods[i]->clone());
rods[i]->reactor = this;
}
}
void reactor::reset_rod_speed()
void Reactor::reset_rod_speed()
{
rod_speed = 0;
}
void reactor::add_rod_speed(double a)
void Reactor::add_rod_speed(double a)
{
rod_speed -= a;
@ -57,7 +57,7 @@ void reactor::add_rod_speed(double a)
rod_speed = 0.2;
}
void reactor::scram()
void Reactor::scram()
{
rod_speed = -0.2;
@ -70,13 +70,13 @@ void reactor::scram()
}
}
void reactor::update(double secs)
void Reactor::update(double secs)
{
int rods_lookup[size];
double temp_min, temp_max;
double flux_initial = get_flux();
get_stats(rod::val_t::HEAT, temp_min, temp_max);
get_stats(Rod::val_t::HEAT, temp_min, temp_max);
if(temp_max > 360)
{
@ -111,11 +111,11 @@ void reactor::update(double secs)
}
}
void reactor::update_selected(double dt)
void Reactor::update_selected(double dt)
{
for(int i = 0; i < size; i++)
{
rod* r = rods[i].get();
Rod* r = rods[i].get();
if(r->selected)
{
@ -124,7 +124,7 @@ void reactor::update_selected(double dt)
}
}
int reactor::move_cursor(int d)
int Reactor::move_cursor(int d)
{
goto logic;
@ -144,7 +144,7 @@ logic: cursor = (cursor + d) % (size + 1);
return cursor;
}
void reactor::toggle_selected()
void Reactor::toggle_selected()
{
if(cursor < size && rods[cursor]->should_select())
{
@ -152,7 +152,7 @@ void reactor::toggle_selected()
}
}
void reactor::update_tile(double secs, int i, int x, int y)
void Reactor::update_tile(double secs, int i, int x, int y)
{
int nb_lookup[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
std::shuffle(nb_lookup, &nb_lookup[3], util::random::gen);
@ -169,7 +169,7 @@ void reactor::update_tile(double secs, int i, int x, int y)
}
}
void reactor::update_interactions(int* rods_lookup, double secs)
void Reactor::update_interactions(int* rods_lookup, double secs)
{
std::shuffle(rods_lookup, &rods_lookup[size - 1], util::random::gen);
@ -186,7 +186,7 @@ void reactor::update_interactions(int* rods_lookup, double secs)
}
}
double reactor::get_total(rod::val_t type)
double Reactor::get_total(Rod::val_t type)
{
double v = 0;
@ -198,12 +198,12 @@ double reactor::get_total(rod::val_t type)
return v;
}
double reactor::get_average(rod::val_t type)
double Reactor::get_average(Rod::val_t type)
{
return get_total(type) / size;
}
double reactor::get_flux()
double Reactor::get_flux()
{
double v = 0;
@ -215,7 +215,7 @@ double reactor::get_flux()
return v / size;
}
double reactor::get_energy_output()
double Reactor::get_energy_output()
{
double v = 0;
@ -227,7 +227,7 @@ double reactor::get_energy_output()
return v;
}
void reactor::get_stats(rod::val_t type, double& min, double& max)
void Reactor::get_stats(Rod::val_t type, double& min, double& max)
{
min = INFINITY;
max = -INFINITY;
@ -246,7 +246,7 @@ void reactor::get_stats(rod::val_t type, double& min, double& max)
}
}
reactor::reactor(const Json::Value& node, coolant::vessel* v) :
Reactor::Reactor(const Json::Value& node, coolant::Vessel* v) :
cell_width(node["cell_width"].asDouble()),
cell_height(node["cell_height"].asDouble()),
width(node["width"].asInt()),
@ -260,14 +260,14 @@ reactor::reactor(const Json::Value& node, coolant::vessel* v) :
for(int i = 0; i < size; i++)
{
std::unique_ptr<rod> r = load_rod(j_rods[i], v);
std::unique_ptr<Rod> r = load_rod(j_rods[i], v);
r->reactor = this;
rods.push_back(std::move(r));
}
}
reactor::operator Json::Value() const
Reactor::operator Json::Value() const
{
Json::Value node;

View File

@ -11,7 +11,7 @@
namespace sim::reactor
{
struct reactor
struct Reactor
{
const double cell_width;
const double cell_height;
@ -20,27 +20,27 @@ struct reactor
const int height;
const int size;
std::vector<std::unique_ptr<rod>> rods;
std::vector<std::unique_ptr<Rod>> rods;
double flux_rate = 0;
double rod_speed = 0;
int cursor;
reactor(std::unique_ptr<rod>* rods, int width, int height, double cell_width, double cell_height);
reactor(const Json::Value& node, coolant::vessel* v);
reactor(const reactor& r);
reactor(reactor&& r);
Reactor(std::unique_ptr<Rod>* rods, int width, int height, double cell_width, double cell_height);
Reactor(const Json::Value& node, coolant::Vessel* v);
Reactor(const Reactor& r);
Reactor(Reactor&& r);
void scram();
void reset_rod_speed();
void add_rod_speed(double a);
void update(double secs);
void get_stats(rod::val_t type, double& min, double& max);
void get_stats(Rod::val_t type, double& min, double& max);
void get_rod_stats(int type, double& min, double& max);
double get_flux();
double get_energy_output();
double get_average(rod::val_t type);
double get_total(rod::val_t type);
double get_average(Rod::val_t type);
double get_total(Rod::val_t type);
int move_cursor(int d);
void toggle_selected();

View File

@ -10,17 +10,17 @@ using namespace sim::reactor;
// Avogadro's Number
static double N_a = 6.02214076e23;
double rod::get(val_t type) const
double Rod::get(val_t type) const
{
return vals[type];
}
void rod::add(val_t type, double v)
void Rod::add(val_t type, double v)
{
vals[type] += v;
}
double rod::extract(val_t type, double s, double k, double o)
double Rod::extract(val_t type, double s, double k, double o)
{
k *= get_k(type);
@ -38,9 +38,9 @@ double rod::extract(val_t type, double s, double k, double o)
return v;
}
void rod::interact(rod* o, double secs)
void Rod::interact(Rod* o, double secs)
{
for(int i = 0; i < rod::VAL_N; i++)
for(int i = 0; i < Rod::VAL_N; i++)
{
val_t t = (val_t)i;
double v = o->extract(t, secs, get_k(t), get(t));
@ -52,7 +52,7 @@ void rod::interact(rod* o, double secs)
}
}
glm::vec4 rod::get_heat_colour() const
glm::vec4 Rod::get_heat_colour() const
{
double temp = vals[val_t::HEAT];
@ -90,24 +90,24 @@ glm::vec4 rod::get_heat_colour() const
return {1, 0, 0, 1};
}
double rod::get_flux() const
double Rod::get_flux() const
{
return (vals_n[val_t::N_FAST] + vals_n[val_t::N_SLOW]) * N_a / (get_side_area() * 10000) / 4;
}
double rod::get_volume() const
double Rod::get_volume() const
{
auto r = (sim::reactor::reactor*)reactor;
auto r = (sim::reactor::Reactor*)reactor;
return r->cell_width * r->cell_width * r->cell_height;
}
double rod::get_side_area() const
double Rod::get_side_area() const
{
auto r = (sim::reactor::reactor*)reactor;
auto r = (sim::reactor::Reactor*)reactor;
return r->cell_width * r->cell_height;
}
void rod::update_rod(double secs)
void Rod::update_rod(double secs)
{
// decay the free neutrons
double m = std::pow(0.5, secs / 879.4);
@ -115,13 +115,13 @@ void rod::update_rod(double secs)
vals[val_t::N_SLOW] *= m;
// clear data
for(int i = 0; i < rod::VAL_N; i++)
for(int i = 0; i < Rod::VAL_N; i++)
{
vals_n[(val_t)i] = 0;
}
}
rod::rod(const Json::Value& node)
Rod::Rod(const Json::Value& node)
{
const Json::Value& j_vals = node["vals"];
@ -134,7 +134,7 @@ rod::rod(const Json::Value& node)
}
}
Json::Value rod::serialize() const
Json::Value Rod::serialize() const
{
Json::Value node;
Json::Value j_vals;

View File

@ -10,7 +10,7 @@
namespace sim::reactor
{
class rod
class Rod
{
public:
@ -25,16 +25,16 @@ public:
N_FAST = 2,
};
constexpr rod() {};
rod(const Json::Value& node);
constexpr Rod() {};
Rod(const Json::Value& node);
virtual ~rod() {};
virtual void interact(rod* o, double secs);
virtual ~Rod() {};
virtual void interact(Rod* o, double secs);
virtual void update(double secs) { }
virtual void add(val_t type, double v);
virtual double extract(val_t type, double s, double k, double o);
virtual double get(val_t type) const;
virtual std::unique_ptr<rod> clone() const { return std::make_unique<rod>(*this); }
virtual std::unique_ptr<Rod> clone() const { return std::make_unique<Rod>(*this); }
virtual double get_energy_output() const { return 0; }
virtual int get_id() const { return 0; }
@ -52,7 +52,7 @@ public:
constexpr void toggle_selected() { selected = !selected; }
friend std::ostream& operator<<(std::ostream& o, const rod& r)
friend std::ostream& operator<<(std::ostream& o, const Rod& r)
{
if(!r.should_display()) return o;

View File

@ -12,9 +12,9 @@
using namespace sim;
sim::system system::active;
sim::System System::active;
system::system()
System::System()
{
const char* layout[] = {
" C C C C ",
@ -38,45 +38,45 @@ system::system()
" C C C C "
};
vessel = std::make_unique<reactor::coolant::vessel>(sim::coolant::WATER, 8, 10, 6e6, 5e5, 10);
reactor = std::make_unique<reactor::reactor>(sim::reactor::builder(19, 19, 1.0 / 4.0, 4, reactor::fuel::fuel_rod(0.2), vessel.get(), layout));
condenser = std::make_unique<coolant::condenser>(sim::coolant::WATER, 6, 4, 3e6, 30000);
turbine = std::make_unique<electric::turbine>(sim::coolant::WATER, condenser.get(), 6, 3, 2e6);
vessel = std::make_unique<reactor::coolant::Vessel>(sim::coolant::WATER, 8, 10, 6e6, 5e5, 10);
reactor = std::make_unique<reactor::Reactor>(sim::reactor::builder(19, 19, 1.0 / 4.0, 4, reactor::fuel::FuelRod(0.2), vessel.get(), layout));
condenser = std::make_unique<coolant::Condenser>(sim::coolant::WATER, 6, 4, 3e6, 30000);
turbine = std::make_unique<electric::Turbine>(sim::coolant::WATER, condenser.get(), 6, 3, 2e6);
sink = std::make_unique<coolant::sink>(sim::coolant::WATER, 11, 0, 0);
evaporator = std::make_unique<coolant::evaporator>(sim::coolant::WATER, 2, 30, 0, 1000);
condenser_secondary = std::make_unique<coolant::condenser_secondary>(condenser.get(), evaporator.get(), 1000);
sink = std::make_unique<coolant::Sink>(sim::coolant::WATER, 11, 0, 0);
evaporator = std::make_unique<coolant::Evaporator>(sim::coolant::WATER, 2, 30, 0, 1000);
condenser_secondary = std::make_unique<coolant::CondenserSecondary>(condenser.get(), evaporator.get(), 1000);
turbine_inlet_valve = std::make_unique<coolant::valve>(vessel.get(), turbine.get(), 0, 0.5);
turbine_bypass_valve = std::make_unique<coolant::valve>(vessel.get(), condenser.get(), 0, 0.5);
turbine_inlet_valve = std::make_unique<coolant::Valve>(vessel.get(), turbine.get(), 0, 0.5);
turbine_bypass_valve = std::make_unique<coolant::Valve>(vessel.get(), condenser.get(), 0, 0.5);
primary_pump = std::make_unique<coolant::pump>(condenser.get(), vessel.get(), 1e5, 1, 1e5, 0.1, 10, coolant::pump::mode_t::SRC, 35000);
secondary_pump = std::make_unique<coolant::pump>(evaporator.get(), condenser_secondary.get(), 1e5, 1, 1e4, 0.1, 1, coolant::pump::mode_t::NONE, 0);
freight_pump = std::make_unique<coolant::pump>(sink.get(), evaporator.get(), 1e5, 1, 1e4, 0.1, 10, coolant::pump::mode_t::DST, 1e6);
primary_pump = std::make_unique<coolant::Pump>(condenser.get(), vessel.get(), 1e5, 1, 1e5, 0.1, 10, coolant::Pump::mode_t::SRC, 35000);
secondary_pump = std::make_unique<coolant::Pump>(evaporator.get(), condenser_secondary.get(), 1e5, 1, 1e4, 0.1, 1, coolant::Pump::mode_t::NONE, 0);
freight_pump = std::make_unique<coolant::Pump>(sink.get(), evaporator.get(), 1e5, 1, 1e4, 0.1, 10, coolant::Pump::mode_t::DST, 1e6);
}
system::system(const Json::Value& node)
System::System(const Json::Value& node)
{
clock = node["clock"].asDouble();
vessel = std::make_unique<reactor::coolant::vessel>(node["vessel"]);
reactor = std::make_unique<reactor::reactor>(node["reactor"], vessel.get());
condenser = std::make_unique<coolant::condenser>(node["condenser"]);
turbine = std::make_unique<electric::turbine>(node["turbine"], condenser.get());
vessel = std::make_unique<reactor::coolant::Vessel>(node["vessel"]);
reactor = std::make_unique<reactor::Reactor>(node["reactor"], vessel.get());
condenser = std::make_unique<coolant::Condenser>(node["condenser"]);
turbine = std::make_unique<electric::Turbine>(node["turbine"], condenser.get());
evaporator = std::make_unique<coolant::evaporator>(node["evaporator"]);
sink = std::make_unique<coolant::sink>(evaporator->fluid, 11, 0, 0);
condenser_secondary = std::make_unique<coolant::condenser_secondary>(condenser.get(), evaporator.get(), 1000);
evaporator = std::make_unique<coolant::Evaporator>(node["evaporator"]);
sink = std::make_unique<coolant::Sink>(evaporator->fluid, 11, 0, 0);
condenser_secondary = std::make_unique<coolant::CondenserSecondary>(condenser.get(), evaporator.get(), 1000);
turbine_inlet_valve = std::make_unique<coolant::valve>(node["valve"]["turbine"]["inlet"], vessel.get(), turbine.get());
turbine_bypass_valve = std::make_unique<coolant::valve>(node["valve"]["turbine"]["bypass"], vessel.get(), condenser.get());
turbine_inlet_valve = std::make_unique<coolant::Valve>(node["valve"]["turbine"]["inlet"], vessel.get(), turbine.get());
turbine_bypass_valve = std::make_unique<coolant::Valve>(node["valve"]["turbine"]["bypass"], vessel.get(), condenser.get());
primary_pump = std::make_unique<coolant::pump>(node["pump"]["primary"], condenser.get(), vessel.get());
secondary_pump = std::make_unique<coolant::pump>(node["pump"]["secondary"], evaporator.get(), condenser_secondary.get());
freight_pump = std::make_unique<coolant::pump>(node["pump"]["freight"], sink.get(), evaporator.get());
primary_pump = std::make_unique<coolant::Pump>(node["pump"]["primary"], condenser.get(), vessel.get());
secondary_pump = std::make_unique<coolant::Pump>(node["pump"]["secondary"], evaporator.get(), condenser_secondary.get());
freight_pump = std::make_unique<coolant::Pump>(node["pump"]["freight"], sink.get(), evaporator.get());
}
void system::update(double dt)
void System::update(double dt)
{
dt *= speed;
clock += dt;
@ -95,7 +95,7 @@ void system::update(double dt)
condenser_secondary->update(dt);
}
system::operator Json::Value() const
System::operator Json::Value() const
{
Json::Value node;
@ -114,7 +114,7 @@ system::operator Json::Value() const
return node;
}
void system::save()
void System::save()
{
Json::Value root(active);
root["camera"] = graphics::camera::serialize();
@ -129,14 +129,14 @@ void system::save()
savefile.close();
}
void system::load()
void System::load()
{
Json::Value root;
std::ifstream savefile("savefile.json");
savefile >> root;
savefile.close();
system sys(root);
System sys(root);
graphics::camera::load(root["camera"]);
active = std::move(sys);
}

View File

@ -17,31 +17,31 @@
namespace sim
{
struct system
struct System
{
static system active;
static System active;
std::unique_ptr<sim::reactor::reactor> reactor;
std::unique_ptr<sim::reactor::coolant::vessel> vessel;
std::unique_ptr<sim::reactor::Reactor> reactor;
std::unique_ptr<sim::reactor::coolant::Vessel> vessel;
std::unique_ptr<sim::coolant::sink> sink;
std::unique_ptr<sim::coolant::condenser> condenser;
std::unique_ptr<sim::coolant::condenser_secondary> condenser_secondary;
std::unique_ptr<sim::coolant::evaporator> evaporator;
std::unique_ptr<sim::electric::turbine> turbine;
std::unique_ptr<sim::coolant::Sink> sink;
std::unique_ptr<sim::coolant::Condenser> condenser;
std::unique_ptr<sim::coolant::CondenserSecondary> condenser_secondary;
std::unique_ptr<sim::coolant::Evaporator> evaporator;
std::unique_ptr<sim::electric::Turbine> turbine;
std::unique_ptr<sim::coolant::pump> primary_pump;
std::unique_ptr<sim::coolant::pump> secondary_pump;
std::unique_ptr<sim::coolant::pump> freight_pump;
std::unique_ptr<sim::coolant::Pump> primary_pump;
std::unique_ptr<sim::coolant::Pump> secondary_pump;
std::unique_ptr<sim::coolant::Pump> freight_pump;
std::unique_ptr<sim::coolant::valve> turbine_bypass_valve;
std::unique_ptr<sim::coolant::valve> turbine_inlet_valve;
std::unique_ptr<sim::coolant::Valve> turbine_bypass_valve;
std::unique_ptr<sim::coolant::Valve> turbine_inlet_valve;
double speed = 1;
double clock = 3600 * 12;
system();
system(const Json::Value& node);
System();
System(const Json::Value& node);
void update(double dt);