added semifunctional turbine :)
This commit is contained in:
parent
18e05450b4
commit
ebde378e10
|
@ -18,8 +18,8 @@ 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, double e) { return source->add_gas(steam, gas, t, e); }
|
||||
virtual double extract_fluid(double amount) { return source->extract_fluid(amount); }
|
||||
virtual void add_gas(double steam, double gas, double t) { return source->add_gas(steam, gas, t); }
|
||||
|
||||
virtual double add_fluid(double amount, double heat);
|
||||
|
||||
|
|
|
@ -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, double e_2)
|
||||
void fluid_holder::add_gas(double m_s2, double m_a2, double t_2)
|
||||
{
|
||||
double m_2 = m_a2 + m_s2;
|
||||
double m_1 = get_thermal_mass();
|
||||
|
|
|
@ -31,7 +31,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 heat, double energy);
|
||||
virtual void add_gas(double steam, double air, double heat);
|
||||
|
||||
virtual double get_volume() const { return volume; } // litres
|
||||
virtual double get_level() const { return level; } // litres
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
#include "pump.hpp"
|
||||
#include "../util/math.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
@ -53,18 +54,6 @@ const char* pump::get_state_string()
|
|||
return "On";
|
||||
}
|
||||
|
||||
static double calc_work(double j, double mass)
|
||||
{
|
||||
double m = 1;
|
||||
|
||||
if(j < 0)
|
||||
{
|
||||
m = -1;
|
||||
}
|
||||
|
||||
return m * std::sqrt(m * j / (mass * 0.001));
|
||||
}
|
||||
|
||||
void pump::update(double dt)
|
||||
{
|
||||
if(powered)
|
||||
|
@ -82,7 +71,7 @@ void pump::update(double dt)
|
|||
break;
|
||||
}
|
||||
|
||||
velocity += calc_work(dt * power * max_power, mass);
|
||||
velocity += util::calc_work(dt * power * max_power, mass);
|
||||
}
|
||||
|
||||
else
|
||||
|
@ -99,9 +88,9 @@ void pump::update(double dt)
|
|||
|
||||
double p_diff_2 = dst->get_pressure() - src->get_pressure();
|
||||
double p_diff = (p_diff_1 + p_diff_2) / 2;
|
||||
double work = p_diff * dst_volume * 0.001 + get_rpm() * 60 * dt * friction;
|
||||
double work = p_diff * dst_volume * 0.001 + get_rpm() / 60 * dt * friction;
|
||||
|
||||
velocity = std::max(velocity - calc_work(work, mass), 0.0);
|
||||
velocity = std::max(velocity - util::calc_work(work, mass), 0.0);
|
||||
flow = dst_volume / dt;
|
||||
}
|
||||
|
||||
|
|
|
@ -75,8 +75,8 @@ void valve::update(double dt)
|
|||
double heat1 = src->get_heat(); // C
|
||||
double heat2 = dst->get_heat();
|
||||
|
||||
src->add_gas(-mass_s, mass_a, heat2, 0);
|
||||
dst->add_gas(mass_s, mass_a, heat1, 0);
|
||||
src->add_gas(-mass_s, mass_a, heat2);
|
||||
dst->add_gas(mass_s, mass_a, heat1);
|
||||
|
||||
this->flow = (mass_s + mass_a) / dt;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
#include "turbine.hpp"
|
||||
#include "../system.hpp"
|
||||
#include "../util/math.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
@ -25,6 +26,7 @@ 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)
|
||||
{
|
||||
velocity = node["velocity"].asDouble();
|
||||
|
@ -32,12 +34,20 @@ turbine::turbine(const Json::Value& node, coolant::condenser* condenser) :
|
|||
|
||||
void turbine::update(double dt)
|
||||
{
|
||||
|
||||
double work = get_rpm() / 60 * dt * friction;
|
||||
velocity = std::max(velocity - work, 0.0);
|
||||
}
|
||||
|
||||
void turbine::add_gas(double steam, double air, double t, double e)
|
||||
double turbine::get_rpm() const
|
||||
{
|
||||
condenser->add_gas(steam, air, t, e);
|
||||
return velocity / (M_PI * extra_mass * 0.001 * diameter * diameter * 0.25);
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -47,6 +57,7 @@ turbine::operator Json::Value() const
|
|||
node["length"] = length;
|
||||
node["diameter"] = diameter;
|
||||
node["velocity"] = velocity;
|
||||
node["friction"] = friction;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ class turbine : public sim::coolant::fluid_holder
|
|||
|
||||
const double length;
|
||||
const double diameter;
|
||||
const double friction = 1;
|
||||
|
||||
double velocity = 0; // m/s
|
||||
|
||||
|
@ -22,11 +23,13 @@ public:
|
|||
turbine(const Json::Value& node, coolant::condenser* condenser);
|
||||
|
||||
void update(double dt);
|
||||
double get_rpm() const;
|
||||
|
||||
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, double e);
|
||||
|
||||
virtual void add_gas(double steam, double gas, double t);
|
||||
|
||||
virtual double get_volume() const { return condenser->get_volume(); }
|
||||
virtual double get_level() const { return condenser->get_level(); }
|
||||
|
|
|
@ -136,6 +136,22 @@ void focus::update(double dt)
|
|||
}
|
||||
}
|
||||
|
||||
void focus::render_ui()
|
||||
{
|
||||
if(state)
|
||||
{
|
||||
state->render_ui();
|
||||
}
|
||||
}
|
||||
|
||||
void focus::render()
|
||||
{
|
||||
if(state)
|
||||
{
|
||||
state->render();
|
||||
}
|
||||
}
|
||||
|
||||
bool focus::is_focused()
|
||||
{
|
||||
return (state != nullptr);
|
||||
|
|
|
@ -17,6 +17,8 @@ struct focus_t
|
|||
virtual void on_cursor_pos(double x, double y) { }
|
||||
virtual void on_charcode(unsigned int c) { }
|
||||
virtual void update(double dt) { }
|
||||
virtual void render_ui() { }
|
||||
virtual void render() { }
|
||||
};
|
||||
|
||||
bool is_focused();
|
||||
|
@ -32,6 +34,8 @@ void on_mouse_button(int button, int action, int mods);
|
|||
void on_cursor_pos(double x, double y);
|
||||
void on_charcode(unsigned int c);
|
||||
void update(double dt);
|
||||
void render_ui();
|
||||
void render();
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -101,6 +101,13 @@ void mesh::load_text(const char* text, double size)
|
|||
float x = 0, y = size;
|
||||
unsigned int at = 0;
|
||||
|
||||
if(text[0] == '\0')
|
||||
{
|
||||
this->vertices.clear();
|
||||
this->indices.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; text[i] != '\0'; i++)
|
||||
{
|
||||
char c = text[i];
|
||||
|
@ -139,7 +146,7 @@ void mesh::load_text(const char* text, double size)
|
|||
x += ch.advance * size;
|
||||
}
|
||||
|
||||
set_vertices(&vertices[0], vertices.size());
|
||||
set_indices(&indices[0], indices.size());
|
||||
this->vertices = std::move(vertices);
|
||||
this->indices = std::move(indices);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "helpers.hpp"
|
||||
#include "turbine.hpp"
|
||||
#include "../locations.hpp"
|
||||
#include "../../system.hpp"
|
||||
#include "../../coolant/valve.hpp"
|
||||
#include "../input/focus.hpp"
|
||||
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace sim::graphics;
|
||||
using namespace sim::graphics::monitor;
|
||||
|
||||
turbine::turbine()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void turbine::init()
|
||||
{
|
||||
mesh1.model_matrix = locations::monitors[4];
|
||||
mesh2.model_matrix = glm::translate(mesh1.model_matrix, glm::vec3(0.5, 0, 0));
|
||||
|
||||
mesh1.colour_matrix = mesh2.colour_matrix = {
|
||||
1, 1, 1, 1,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0
|
||||
};
|
||||
|
||||
std::stringstream ss;
|
||||
sim::graphics::mesh rmesh;
|
||||
|
||||
ss << "Turbine\n\n";
|
||||
ss << "Heat\nPressure\nSpeed\n\n";
|
||||
|
||||
rmesh.load_text(ss.str().c_str(), 0.04);
|
||||
mesh1.bind();
|
||||
mesh1.set(rmesh, GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
void turbine::update(double dt)
|
||||
{
|
||||
system& sys = sim::system::active;
|
||||
clock_now += dt;
|
||||
|
||||
if(clock_at + 1.0/30.0 < clock_now)
|
||||
{
|
||||
std::stringstream ss;
|
||||
sim::graphics::mesh rmesh;
|
||||
clock_at += 1.0/30.0;
|
||||
|
||||
ss << "\n\n";
|
||||
ss << show( sys.turbine->get_heat() ) << " C\n";
|
||||
ss << show( sys.turbine->get_pressure() / 1000 ) << " kPa\n";
|
||||
ss << show( sys.turbine->get_rpm() ) << " r/min\n";
|
||||
|
||||
rmesh.load_text(ss.str().c_str(), 0.04);
|
||||
mesh2.bind();
|
||||
mesh2.set(rmesh, GL_DYNAMIC_DRAW);
|
||||
}
|
||||
}
|
||||
|
||||
void turbine::render()
|
||||
{
|
||||
mesh1.bind();
|
||||
mesh1.uniform();
|
||||
mesh1.render();
|
||||
|
||||
mesh2.bind();
|
||||
mesh2.uniform();
|
||||
mesh2.render();
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../mesh/glmesh.hpp"
|
||||
|
||||
namespace sim::graphics::monitor
|
||||
{
|
||||
|
||||
class turbine
|
||||
{
|
||||
sim::graphics::glmesh mesh1, mesh2;
|
||||
double clock_at = 0, clock_now = 0;
|
||||
|
||||
public:
|
||||
|
||||
turbine();
|
||||
void init();
|
||||
void update(double dt);
|
||||
void render();
|
||||
};
|
||||
|
||||
};
|
||||
|
|
@ -21,7 +21,7 @@ using namespace sim::graphics::widget;
|
|||
void clock::update(double dt)
|
||||
{
|
||||
mesh m;
|
||||
double at = 3600 * 12 + system::active.clock;
|
||||
double at = system::active.clock;
|
||||
glm::vec2 wsize(resize::get_size() / 2);
|
||||
std::stringstream ss;
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "mesh/arrays.hpp"
|
||||
#include "input/keyboard.hpp"
|
||||
#include "input/mouse.hpp"
|
||||
#include "input/focus.hpp"
|
||||
#include "camera.hpp"
|
||||
#include "resize.hpp"
|
||||
#include "window.hpp"
|
||||
|
@ -22,6 +23,7 @@
|
|||
#include "monitor/core.hpp"
|
||||
#include "monitor/primary_loop.hpp"
|
||||
#include "monitor/secondary_loop.hpp"
|
||||
#include "monitor/turbine.hpp"
|
||||
#include "mesh/texture.hpp"
|
||||
#include "ui.hpp"
|
||||
|
||||
|
@ -35,6 +37,7 @@ 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;
|
||||
|
||||
glm::mat4 window::projection_matrix;
|
||||
|
||||
|
@ -116,6 +119,7 @@ void window::create()
|
|||
monitor_vessel.init();
|
||||
monitor_primary_loop.init();
|
||||
monitor_secondary_loop.init();
|
||||
monitor_turbine.init();
|
||||
|
||||
glfwShowWindow(win);
|
||||
glViewport(0, 0, 800, 600);
|
||||
|
@ -129,6 +133,7 @@ void window::update(double dt)
|
|||
monitor_vessel.update(dt);
|
||||
monitor_primary_loop.update(dt);
|
||||
monitor_secondary_loop.update(dt);
|
||||
monitor_turbine.update(dt);
|
||||
|
||||
ui::update(dt);
|
||||
}
|
||||
|
@ -152,8 +157,11 @@ void window::render()
|
|||
monitor_vessel.render();
|
||||
monitor_primary_loop.render();
|
||||
monitor_secondary_loop.render();
|
||||
monitor_turbine.render();
|
||||
|
||||
focus::render();
|
||||
ui::render();
|
||||
focus::render_ui();
|
||||
|
||||
glfwSwapBuffers(win);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ struct system
|
|||
std::unique_ptr<sim::coolant::valve> turbine_inlet_valve;
|
||||
|
||||
double speed = 1;
|
||||
double clock = 0;
|
||||
double clock = 3600 * 12;
|
||||
|
||||
system();
|
||||
system(const Json::Value& node);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <glm/matrix.hpp>
|
||||
#include <ostream>
|
||||
#include <cmath>
|
||||
|
||||
template <int N, typename T>
|
||||
std::ostream& operator<<(std::ostream& o, const glm::vec<N, T>& v)
|
||||
|
@ -18,3 +19,20 @@ std::ostream& operator<<(std::ostream& o, const glm::vec<N, T>& v)
|
|||
return o;
|
||||
}
|
||||
|
||||
namespace sim::util
|
||||
{
|
||||
|
||||
constexpr double calc_work(double j, double mass)
|
||||
{
|
||||
double m = 1;
|
||||
|
||||
if(j < 0)
|
||||
{
|
||||
m = -1;
|
||||
}
|
||||
|
||||
return m * std::sqrt(m * j / (mass * 0.001));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue