added basic file saving
This commit is contained in:
parent
8c8bcf3e87
commit
825195c086
|
@ -3,10 +3,10 @@ cmake_minimum_required(VERSION 3.25)
|
|||
project(FastNuclearSim VERSION 1.0)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 26)
|
||||
set(CMAKE_CXX_FLAGS "-g -I/usr/include/freetype2")
|
||||
set(CMAKE_CXX_FLAGS "-g -O3 -I/usr/include/freetype2")
|
||||
|
||||
file(GLOB_RECURSE SOURCES src/*.cpp)
|
||||
|
||||
add_executable(FastNuclearSim ${SOURCES})
|
||||
target_link_libraries(FastNuclearSim PUBLIC stdc++ m GLEW glfw GL freetype assimp)
|
||||
target_link_libraries(FastNuclearSim PUBLIC stdc++ m GLEW glfw GL freetype assimp jsoncpp)
|
||||
|
||||
|
|
|
@ -24,4 +24,13 @@ void condenser::update(double secs)
|
|||
update_base(secs);
|
||||
}
|
||||
|
||||
condenser::operator Json::Value() const
|
||||
{
|
||||
Json::Value node(fluid_holder::operator::Json::Value());
|
||||
|
||||
node["height"] = height;
|
||||
node["diameter"] = diameter;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ public:
|
|||
condenser(fluid_t type, double height, double diameter, double mass, double level);
|
||||
|
||||
void update(double dt);
|
||||
|
||||
virtual operator Json::Value() const;
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
condenser_secondary(condenser* primary, evaporator* source, double volume);
|
||||
|
||||
virtual double add_heat(double m, double t) { return source->add_heat(m, t); }
|
||||
virtual void add_gas(double steam, double gas, double t) { return source->add_gas(steam, gas, t); }
|
||||
virtual void add_gas(double steam, double gas, double t, double e) { return source->add_gas(steam, gas, t, e); }
|
||||
virtual double extract_fluid(double amount) { return source->extract_fluid(amount); }
|
||||
|
||||
virtual double add_fluid(double amount, double heat);
|
||||
|
|
|
@ -45,3 +45,14 @@ void evaporator::update(double dt)
|
|||
update_base(dt);
|
||||
}
|
||||
|
||||
evaporator::operator Json::Value() const
|
||||
{
|
||||
Json::Value node(fluid_holder::operator::Json::Value());
|
||||
|
||||
node["height"] = height;
|
||||
node["diameter"] = diameter;
|
||||
node["steam_output"] = steam_output;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ public:
|
|||
|
||||
evaporator(fluid_t type, double height, double diameter, double mass, double level);
|
||||
|
||||
virtual operator Json::Value() const;
|
||||
|
||||
double get_steam_output();
|
||||
void update(double dt);
|
||||
};
|
||||
|
|
|
@ -69,7 +69,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 fluid_holder::add_gas(double m_s2, double m_a2, double t_2, double e_2)
|
||||
{
|
||||
double m_2 = m_a2 + m_s2;
|
||||
double m_1 = get_thermal_mass();
|
||||
|
@ -111,6 +111,22 @@ double fluid_holder::get_gas_density() const
|
|||
return v > 0 ? get_gas() / v : 0;
|
||||
}
|
||||
|
||||
fluid_holder::operator Json::Value() const
|
||||
{
|
||||
Json::Value node;
|
||||
|
||||
node["level"] = level;
|
||||
node["steam"] = steam;
|
||||
node["air"] = air;
|
||||
node["heat"] = heat;
|
||||
|
||||
node["volume"] = volume;
|
||||
node["extra_mass"] = extra_mass;
|
||||
node["fluid"] = fluid;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
void fluid_holder::update_base(double secs)
|
||||
{
|
||||
double mass = get_thermal_mass();
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <json/json.h>
|
||||
|
||||
#include "fluid_t.hpp"
|
||||
#include "../conversions/temperature.hpp"
|
||||
|
||||
|
@ -28,7 +30,7 @@ public:
|
|||
virtual double extract_fluid(double amount);
|
||||
|
||||
virtual double add_fluid(double amount, double heat);
|
||||
virtual void add_gas(double steam, double air, double t);
|
||||
virtual void add_gas(double steam, double air, double heat, double energy);
|
||||
|
||||
virtual double get_volume() const { return volume; } // litres
|
||||
virtual double get_level() const { return level; } // litres
|
||||
|
@ -43,6 +45,8 @@ public:
|
|||
virtual double get_pressure() const; // pascals
|
||||
virtual double get_gas_density() const; // g/L
|
||||
|
||||
virtual operator Json::Value() const;
|
||||
|
||||
static double calc_pressure(double heat, double pressure, double mol);
|
||||
static double calc_pressure_mol(double heat, double pressure, double volume);
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <json/json.h>
|
||||
|
||||
#include "vapor_pressure.hpp"
|
||||
|
||||
namespace sim::coolant
|
||||
|
@ -11,18 +13,29 @@ struct fluid_t
|
|||
const double gPl; // g/L
|
||||
const double gPmol; // g/mol
|
||||
const double jPg; // J/g latent heat of vaporisation
|
||||
const double bubble_speed; // m/s
|
||||
|
||||
const coolant::vapor_pressure vapor_pressure;
|
||||
|
||||
constexpr fluid_t(double gPl, double gPmol, double jPg, double bubble_speed, coolant::vapor_pressure vapor_pressure) :
|
||||
constexpr fluid_t(double gPl, double gPmol, double jPg, coolant::vapor_pressure vapor_pressure) :
|
||||
gPl(gPl), gPmol(gPmol), jPg(jPg),
|
||||
vapor_pressure(vapor_pressure),
|
||||
bubble_speed(bubble_speed)
|
||||
vapor_pressure(vapor_pressure)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
operator Json::Value() const
|
||||
{
|
||||
Json::Value node;
|
||||
|
||||
node["gPl"] = gPl;
|
||||
node["gPmol"] = gPmol;
|
||||
node["jPg"] = jPg;
|
||||
|
||||
node["vapor_pressure"] = vapor_pressure;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
constexpr double g_to_mol(double g) const { return g / gPmol; }
|
||||
constexpr double mol_to_g(double mol) const { return mol * gPmol; }
|
||||
constexpr double g_to_l(double g) const { return g / gPl; }
|
||||
|
@ -31,7 +44,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, 4.1816, {8.07131 + 2.124903, 1730.63, 233.426 - 273.15});
|
||||
constexpr const fluid_t WATER = fluid_t(1000, 18, 2257, {8.07131 + 2.124903, 1730.63, 233.426 - 273.15});
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ void pump::update(double dt)
|
|||
double src_heat = src->get_heat();
|
||||
double p_diff_1 = dst->get_pressure() - src->get_pressure();
|
||||
|
||||
double max_volume = ignore_dst_level ? src->get_level() : std::min(src->get_level(), dst->get_volume() - dst->get_level());
|
||||
double max_volume = std::min(src->get_level(), dst->get_volume() - dst->get_level());
|
||||
double src_volume = src->extract_fluid(std::min(get_flow_target() * dt, max_volume));
|
||||
double dst_volume = dst->add_fluid(src_volume, src_heat);
|
||||
|
||||
|
@ -104,3 +104,35 @@ void pump::update(double dt)
|
|||
flow = dst_volume / dt;
|
||||
}
|
||||
|
||||
pump::operator Json::Value() const
|
||||
{
|
||||
Json::Value node;
|
||||
|
||||
node["pid"] = pid;
|
||||
node["flow"] = flow;
|
||||
node["velocity"] = velocity;
|
||||
node["power"] = power;
|
||||
node["mass"] = mass;
|
||||
node["radius"] = radius;
|
||||
node["l_per_rev"] = l_per_rev;
|
||||
node["friction"] = friction;
|
||||
node["max_power"] = max_power;
|
||||
node["target"] = target;
|
||||
node["powered"] = powered;
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
case mode_t::SRC:
|
||||
node["mode"] = "SRC";
|
||||
break;
|
||||
case mode_t::DST:
|
||||
node["mode"] = "DST";
|
||||
break;
|
||||
case mode_t::NONE:
|
||||
node["mode"] = "NONE";
|
||||
break;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@ public:
|
|||
const double max_power; // W
|
||||
const double target; // L
|
||||
|
||||
bool ignore_dst_level = false;
|
||||
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);
|
||||
|
@ -47,6 +46,8 @@ public:
|
|||
double get_rpm() const; // rev/min
|
||||
double get_power() const; // W
|
||||
|
||||
operator Json::Value() const;
|
||||
|
||||
const char* get_state_string();
|
||||
void update(double dt);
|
||||
};
|
||||
|
|
|
@ -75,9 +75,21 @@ void valve::update(double dt)
|
|||
double heat1 = src->get_heat(); // C
|
||||
double heat2 = dst->get_heat();
|
||||
|
||||
src->add_gas(-mass_s, mass_a, heat2);
|
||||
dst->add_gas(mass_s, mass_a, heat1);
|
||||
src->add_gas(-mass_s, mass_a, heat2, 0);
|
||||
dst->add_gas(mass_s, mass_a, heat1, 0);
|
||||
|
||||
this->flow = (mass_s + mass_a) / dt;
|
||||
}
|
||||
|
||||
valve::operator Json::Value() const
|
||||
{
|
||||
Json::Value node;
|
||||
|
||||
node["max"] = max;
|
||||
node["speed"] = speed;
|
||||
node["state"] = state;
|
||||
node["flow"] = flow;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ public:
|
|||
void add_open_speed(double v);
|
||||
void clear_open_speed();
|
||||
|
||||
operator Json::Value() const;
|
||||
|
||||
constexpr double get_state() const { return state; }
|
||||
constexpr double get_flow() const { return flow; }
|
||||
};
|
||||
|
|
|
@ -15,3 +15,14 @@ double vapor_pressure::calc_t(double p) const
|
|||
return B / (A - std::log(p) / std::log(10)) - C;
|
||||
}
|
||||
|
||||
vapor_pressure::operator Json::Value() const
|
||||
{
|
||||
Json::Value node;
|
||||
|
||||
node["A"] = A;
|
||||
node["B"] = B;
|
||||
node["C"] = C;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <json/json.h>
|
||||
|
||||
namespace sim::coolant
|
||||
{
|
||||
|
||||
|
@ -10,6 +12,8 @@ struct vapor_pressure
|
|||
|
||||
constexpr vapor_pressure(double A, double B, double C) : A(A), B(B), C(C) { }
|
||||
|
||||
operator Json::Value() const;
|
||||
|
||||
double calc_p(double t) const;
|
||||
double calc_t(double p) const;
|
||||
};
|
||||
|
|
|
@ -21,13 +21,24 @@ turbine::turbine(coolant::fluid_t type, coolant::condenser* condenser, double le
|
|||
|
||||
}
|
||||
|
||||
void turbine::update(double secs)
|
||||
void turbine::update(double dt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void turbine::add_gas(double steam, double air, double t)
|
||||
void turbine::add_gas(double steam, double air, double t, double e)
|
||||
{
|
||||
condenser->add_gas(steam, air, t);
|
||||
condenser->add_gas(steam, air, t, e);
|
||||
}
|
||||
|
||||
turbine::operator Json::Value() const
|
||||
{
|
||||
Json::Value node(fluid_holder::operator::Json::Value());
|
||||
|
||||
node["length"] = length;
|
||||
node["diameter"] = diameter;
|
||||
node["velocity"] = velocity;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@ class turbine : public sim::coolant::fluid_holder
|
|||
const double length;
|
||||
const double diameter;
|
||||
|
||||
double velocity = 0; // m/s
|
||||
|
||||
public:
|
||||
|
||||
turbine(coolant::fluid_t type, coolant::condenser* condenser, double length, double diameter, double mass);
|
||||
|
@ -23,7 +25,7 @@ public:
|
|||
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 add_fluid(double amount, double heat) { return condenser->add_fluid(amount, heat); }
|
||||
virtual void add_gas(double steam, double gas, double t);
|
||||
virtual void add_gas(double steam, double gas, double t, double e);
|
||||
|
||||
virtual double get_volume() const { return condenser->get_volume(); }
|
||||
virtual double get_level() const { return condenser->get_level(); }
|
||||
|
@ -37,6 +39,8 @@ public:
|
|||
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_gas_density() const { return condenser->get_gas_density(); } // g/L
|
||||
|
||||
virtual operator Json::Value() const;
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -20,6 +20,36 @@ static glm::vec<3, double> pos(0, 0, 2);
|
|||
static glm::vec<3, double> velocity(0);
|
||||
static glm::mat4 camera_mat;
|
||||
|
||||
Json::Value camera::serialize()
|
||||
{
|
||||
Json::Value node;
|
||||
|
||||
node["on_ground"] = on_ground;
|
||||
node["yaw"] = yaw;
|
||||
node["pitch"] = pitch;
|
||||
node["pos"]["x"] = pos[0];
|
||||
node["pos"]["y"] = pos[1];
|
||||
node["pos"]["z"] = pos[2];
|
||||
node["velocity"]["x"] = velocity[0];
|
||||
node["velocity"]["y"] = velocity[1];
|
||||
node["velocity"]["z"] = velocity[2];
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
void camera::load(const Json::Value& node)
|
||||
{
|
||||
on_ground = node["on_ground"].asBool();
|
||||
yaw = node["yaw"].asDouble();
|
||||
pitch = node["pitch"].asDouble();
|
||||
pos[0] = node["pos"]["x"].asDouble();
|
||||
pos[1] = node["pos"]["y"].asDouble();
|
||||
pos[2] = node["pos"]["z"].asDouble();
|
||||
velocity[0] = node["velocity"]["x"].asDouble();
|
||||
velocity[1] = node["velocity"]["y"].asDouble();
|
||||
velocity[2] = node["velocity"]["z"].asDouble();
|
||||
}
|
||||
|
||||
void camera::rotate(double y, double p)
|
||||
{
|
||||
yaw += y * 0.05;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <glm/matrix.hpp>
|
||||
#include <json/json.h>
|
||||
|
||||
#include "../system.hpp"
|
||||
|
||||
|
@ -12,6 +13,9 @@ glm::mat4 get_matrix();
|
|||
glm::vec<3, double> get_normal();
|
||||
glm::vec<3, double> get_pos();
|
||||
|
||||
Json::Value serialize();
|
||||
void load(const Json::Value& node);
|
||||
|
||||
void rotate(double pitch, double yaw);
|
||||
void move(double x, double y, double z);
|
||||
void update(double dt);
|
||||
|
|
|
@ -46,6 +46,9 @@ static void cb_keypress(GLFWwindow* win, int key, int sc, int action, int mods)
|
|||
case GLFW_KEY_6:
|
||||
sim::system::active.speed = 43200; // 12 h/s
|
||||
break;
|
||||
case GLFW_KEY_O:
|
||||
sim::system::active.save();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,9 @@ 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) :
|
||||
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),
|
||||
height(height), diameter(diameter)
|
||||
height(height), diameter(diameter), bubble_hl(bubble_hl)
|
||||
{
|
||||
this->level = level;
|
||||
}
|
||||
|
@ -48,11 +48,6 @@ double vessel::get_void_ratio() const
|
|||
return s / m;
|
||||
}
|
||||
|
||||
double vessel::get_bubble_hl() const
|
||||
{
|
||||
return (level / volume) * height * 0.5 / fluid.bubble_speed;
|
||||
}
|
||||
|
||||
void vessel::update(double secs)
|
||||
{
|
||||
double steam_last = steam;
|
||||
|
@ -60,19 +55,26 @@ void vessel::update(double secs)
|
|||
update_base(secs);
|
||||
|
||||
double diff = steam - steam_last;
|
||||
double hl = get_bubble_hl();
|
||||
|
||||
steam_last = steam;
|
||||
steam_suspended += diff;
|
||||
steam_suspended *= reactor::fuel::half_life::get(secs, bubble_hl);
|
||||
|
||||
if(hl > 0)
|
||||
{
|
||||
steam_suspended *= reactor::fuel::half_life::get(secs, get_bubble_hl());
|
||||
}
|
||||
|
||||
if(hl <= 0 || steam_suspended < 0)
|
||||
if(steam_suspended < 0)
|
||||
{
|
||||
steam_suspended = 0;
|
||||
}
|
||||
}
|
||||
|
||||
vessel::operator Json::Value() const
|
||||
{
|
||||
Json::Value node(fluid_holder::operator::Json::Value());
|
||||
|
||||
node["height"] = height;
|
||||
node["diameter"] = diameter;
|
||||
node["bubble_hl"] = bubble_hl;
|
||||
node["steam_suspended"] = steam_suspended;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,16 +14,19 @@ public:
|
|||
|
||||
const double height; // meters
|
||||
const double diameter; // meters
|
||||
const double bubble_hl; // seconds
|
||||
|
||||
double steam_suspended = 0; // grams
|
||||
|
||||
vessel(sim::coolant::fluid_t fluid, double height, double diameter, double mass, double level);
|
||||
vessel(sim::coolant::fluid_t fluid, double height, double diameter, double mass, double level, double bubble_hl);
|
||||
|
||||
double get_steam_suspended() const; // grams
|
||||
double get_void_ratio() const;
|
||||
double get_bubble_hl() const;
|
||||
|
||||
void update(double secs);
|
||||
|
||||
virtual operator Json::Value() const;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& o, const vessel& v)
|
||||
{
|
||||
o << "Volume: " << v.get_volume() << " L\n";
|
||||
|
|
|
@ -239,3 +239,38 @@ void reactor::get_stats(rod::val_t type, double& min, double& max)
|
|||
}
|
||||
}
|
||||
|
||||
reactor::operator Json::Value() const
|
||||
{
|
||||
Json::Value node;
|
||||
|
||||
node["cell_width"] = cell_width;
|
||||
node["cell_height"] = cell_height;
|
||||
node["width"] = width;
|
||||
node["height"] = height;
|
||||
node["size"] = size;
|
||||
node["rod_speed"] = rod_speed;
|
||||
node["cursor"] = cursor;
|
||||
|
||||
Json::Value j_rods;
|
||||
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
int x = i % width;
|
||||
int y = i / width;
|
||||
|
||||
if(rods[i]->get_id() == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Json::Value j_rod(*rods[i]);
|
||||
j_rod["pos"]["x"] = x;
|
||||
j_rod["pos"]["y"] = y;
|
||||
j_rods.append(std::move(j_rod));
|
||||
}
|
||||
|
||||
node["rods"] = std::move(j_rods);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,8 @@ struct reactor
|
|||
int move_cursor(int d);
|
||||
void toggle_selected();
|
||||
|
||||
operator Json::Value() const;
|
||||
|
||||
private:
|
||||
|
||||
void update_tile(double secs, int i, int x, int y);
|
||||
|
|
|
@ -82,3 +82,24 @@ void rod::update_rod(double secs)
|
|||
}
|
||||
}
|
||||
|
||||
rod::operator Json::Value() const
|
||||
{
|
||||
Json::Value node;
|
||||
Json::Value j_vals;
|
||||
|
||||
for(int i = 0; i < VAL_N; i++)
|
||||
{
|
||||
Json::Value j_val;
|
||||
|
||||
j_val.append(vals[i]);
|
||||
j_val.append(vals_n[i]);
|
||||
j_vals.append(std::move(j_val));
|
||||
}
|
||||
|
||||
node["selected"] = selected;
|
||||
node["vals"] = std::move(j_vals);
|
||||
node["id"] = get_id();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <json/json.h>
|
||||
|
||||
#include <ostream>
|
||||
#include <glm/vec4.hpp>
|
||||
#include <memory>
|
||||
|
@ -14,7 +16,7 @@ public:
|
|||
|
||||
bool selected = false;
|
||||
void* reactor = nullptr;
|
||||
static const int VAL_N = 4;
|
||||
static const int VAL_N = 3;
|
||||
|
||||
enum val_t
|
||||
{
|
||||
|
@ -60,6 +62,8 @@ public:
|
|||
return o;
|
||||
}
|
||||
|
||||
operator Json::Value() const;
|
||||
|
||||
protected:
|
||||
|
||||
double vals[VAL_N] = {0};
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
|
||||
#include "system.hpp"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "reactor/builder.hpp"
|
||||
#include "reactor/control/boron_rod.hpp"
|
||||
#include "reactor/fuel/fuel_rod.hpp"
|
||||
#include "reactor/coolant/pipe.hpp"
|
||||
#include "reactor/coolant/heater.hpp"
|
||||
#include "graphics/camera.hpp"
|
||||
|
||||
using namespace sim;
|
||||
|
||||
|
@ -35,8 +38,8 @@ system::system()
|
|||
" C C C C "
|
||||
};
|
||||
|
||||
vessel = std::make_unique<reactor::coolant::vessel>(sim::coolant::WATER, 8, 10, 6e6, 5e5);
|
||||
reactor = std::make_unique<reactor::reactor>(sim::reactor::builder(19, 19, 1.0 / 4.0, 4, reactor::fuel::fuel_rod(0.5), vessel.get(), layout));
|
||||
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);
|
||||
|
||||
|
@ -89,3 +92,36 @@ void system::update(double dt)
|
|||
condenser_secondary->update(dt);
|
||||
}
|
||||
|
||||
system::operator Json::Value() const
|
||||
{
|
||||
Json::Value node;
|
||||
|
||||
node["vessel"] = *vessel;
|
||||
node["turbine"] = *turbine;
|
||||
node["condenser"] = *condenser;
|
||||
node["evaporator"] = *evaporator;
|
||||
node["primary_pump"] = *primary_pump;
|
||||
node["secondary_pump"] = *secondary_pump;
|
||||
node["freight_pump"] = *freight_pump;
|
||||
node["turbine_inlet_valve"] = *turbine_inlet_valve;
|
||||
node["turbine_bypass_valve"] = *turbine_bypass_valve;
|
||||
node["camera"] = graphics::camera::serialize();
|
||||
node["reactor"] = *reactor;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
void system::save()
|
||||
{
|
||||
Json::Value root(*this);
|
||||
|
||||
Json::StreamWriterBuilder builder;
|
||||
builder["commentStyle"] = "None";
|
||||
builder["indentation"] = "";
|
||||
|
||||
std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
|
||||
std::ofstream savefile("savefile.json");
|
||||
writer->write(root, &savefile);
|
||||
savefile.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <json/json.h>
|
||||
|
||||
#include "reactor/coolant/vessel.hpp"
|
||||
#include "reactor/reactor.hpp"
|
||||
|
@ -45,6 +46,9 @@ struct system
|
|||
system(const system& o) = delete;
|
||||
|
||||
void update(double dt);
|
||||
void save();
|
||||
|
||||
operator Json::Value() const;
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -28,6 +28,22 @@ using namespace std;
|
|||
using namespace sim::util;
|
||||
|
||||
|
||||
PID::operator Json::Value() const
|
||||
{
|
||||
Json::Value node;
|
||||
|
||||
node["max"] = _max;
|
||||
node["min"] = _min;
|
||||
node["Kp"] = _Kp;
|
||||
node["Ki"] = _Ki;
|
||||
node["Kd"] = _Kd;
|
||||
node["pre_error"] = _pre_error;
|
||||
node["integral"] = _integral;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation
|
||||
*/
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <json/json.h>
|
||||
|
||||
namespace sim::util
|
||||
{
|
||||
|
||||
|
@ -42,6 +44,8 @@ class PID
|
|||
// pv - current process value
|
||||
double calculate( double dt, double sp, double pv );
|
||||
|
||||
operator Json::Value() const;
|
||||
|
||||
private:
|
||||
double _max;
|
||||
double _min;
|
||||
|
|
Loading…
Reference in New Issue