diff --git a/assets/unbaked/scene.blend b/assets/unbaked/scene.blend index c93032a..e494480 100644 --- a/assets/unbaked/scene.blend +++ b/assets/unbaked/scene.blend @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6d07ecf8050cb85754bd38a6d12225547cdb90f570f3993dacc048fb202d52e1 -size 10498676 +oid sha256:1587ff7bddced24a85b012ddf5db02580b67ae1852003fae8f10df9367d64221 +size 10470560 diff --git a/src/coolant/condenser.cpp b/src/coolant/condenser.cpp index d77aae7..b80ac56 100644 --- a/src/coolant/condenser.cpp +++ b/src/coolant/condenser.cpp @@ -10,7 +10,7 @@ constexpr static double calc_cylinder(double h, double d) { double r = d / 2; - return M_PI * r * r * h; + return M_PI * r * r * h * 1000; } condenser::condenser(fluid_t type, double height, double diameter, double mass, double level) : diff --git a/src/coolant/condenser_secondary.cpp b/src/coolant/condenser_secondary.cpp index 2a9e56f..1f4042b 100644 --- a/src/coolant/condenser_secondary.cpp +++ b/src/coolant/condenser_secondary.cpp @@ -1,17 +1,20 @@ #include "condenser_secondary.hpp" +#include "../conversions/temperature.hpp" +#include "../util/constants.hpp" +#include "../system.hpp" using namespace sim::coolant; -condenser_secondary::condenser_secondary(condenser* primary, double volume, double level) : - primary(primary), fluid_holder(primary->fluid, volume, 0) +condenser_secondary::condenser_secondary(condenser* primary, evaporator* source) : + primary(primary), source(source), fluid_holder(primary->fluid, 0, 0) { - this->level = level; + } -void condenser_secondary::update(double dt) +double condenser_secondary::add_fluid(double amount, double heat) { - ((fluid_holder*)this)->update(dt); - heat = primary->add_heat(get_thermal_mass(), heat); + heat = primary->add_heat(fluid.l_to_g(amount), heat); + return source->add_fluid(amount, heat); } diff --git a/src/coolant/condenser_secondary.hpp b/src/coolant/condenser_secondary.hpp index f9ba891..72fad7c 100644 --- a/src/coolant/condenser_secondary.hpp +++ b/src/coolant/condenser_secondary.hpp @@ -2,6 +2,7 @@ #pragma once #include "fluid_holder.hpp" +#include "evaporator.hpp" #include "condenser.hpp" namespace sim::coolant @@ -10,12 +11,27 @@ namespace sim::coolant class condenser_secondary : public fluid_holder { condenser* const primary; + evaporator* const source; public: - condenser_secondary(condenser* primary, double volume, double level); + condenser_secondary(condenser* primary, evaporator* source); - void update(double dt); + virtual double add_heat(double m, double t) { return source->add_heat(m, t); } + virtual void add_steam(double amount, double t) { return source->add_steam(amount, t); } + virtual double extract_fluid(double amount) { return source->extract_fluid(amount); } + + virtual double add_fluid(double amount, double heat); + + virtual double get_volume() const { return source->get_volume(); } + virtual double get_level() const { return source->get_level(); } + virtual double get_heat() const { return source->get_heat(); } // celsius + virtual double get_steam() const { return source->get_steam(); } // grams + virtual double get_steam_volume() const { return source->get_steam_volume(); } // litres + virtual double get_mass() const { return source->get_mass(); } // grams + virtual double get_thermal_mass() const { return source->get_thermal_mass(); } // grams + virtual double get_pressure() const { return source->get_pressure(); } // pascals + virtual double get_steam_density() const { return source->get_steam_density(); } // g/L }; }; diff --git a/src/coolant/evaporator.cpp b/src/coolant/evaporator.cpp index f7413a8..de72c7a 100644 --- a/src/coolant/evaporator.cpp +++ b/src/coolant/evaporator.cpp @@ -2,6 +2,7 @@ #include "evaporator.hpp" #include +#include using namespace sim::coolant; @@ -9,12 +10,30 @@ constexpr static double calc_cylinder(double h, double d) { double r = d / 2; - return M_PI * r * r * h; + return M_PI * r * r * h * 1000; } evaporator::evaporator(fluid_t type, double height, double diameter, double mass, double level) : - height(height), diameter(diameter), fluid_holder(type, calc_cylinder(height, diameter), mass) + height(height), + diameter(diameter), + fluid_holder(type, calc_cylinder(height, diameter), mass) { this->level = level; } +double evaporator::get_steam_output() +{ + return steam_output; +} + +void evaporator::update(double dt) +{ + ((fluid_holder*)this)->update(dt); +/* + double m = std::pow(0.5, dt / 3600); + double steam_out = steam * (1 - m); + steam *= m; + + steam_output = steam_out / dt;*/ +} + diff --git a/src/coolant/evaporator.hpp b/src/coolant/evaporator.hpp index da9610a..226f599 100644 --- a/src/coolant/evaporator.hpp +++ b/src/coolant/evaporator.hpp @@ -10,10 +10,15 @@ class evaporator : public fluid_holder { const double height; const double diameter; + + double steam_output = 0; public: evaporator(fluid_t type, double height, double diameter, double mass, double level); + + double get_steam_output(); + void update(double dt); }; }; diff --git a/src/coolant/fluid_holder.cpp b/src/coolant/fluid_holder.cpp index e58454f..c58d1d8 100644 --- a/src/coolant/fluid_holder.cpp +++ b/src/coolant/fluid_holder.cpp @@ -31,13 +31,13 @@ double fluid_holder::add_heat(double m1, double t1) double fluid_holder::add_fluid(double v2, double t2) { - if(level + v2 > volume) + if(level + v2 > volume - 1e-3) { - v2 = volume - level; + v2 = volume - level - 1e-3; } - int m1 = get_thermal_mass(); - int m2 = fluid.l_to_g(v2); + double m1 = get_thermal_mass(); + double m2 = fluid.l_to_g(v2); double t1 = get_heat(); double t = t1 - t2; @@ -50,9 +50,9 @@ double fluid_holder::add_fluid(double v2, double t2) double fluid_holder::extract_fluid(double amount) { - if(amount < level) + if(amount < level - 1e-3) { - level -= amount; + level -= amount - 1e-3; } else @@ -78,18 +78,25 @@ void fluid_holder::add_steam(double m2, double t2) steam += m2; } -double fluid_holder::get_pressure() const +double fluid_holder::calc_pressure(double heat, double volume, double mol) { double T = conversions::temperature::c_to_k(heat); - double V = get_steam_volume() * 0.001; - double n = fluid.g_to_mol(steam); + double V = volume * 0.001; - if(V == 0) - { - return 0; - } - - return (n * T * constants::R) / V; + return V == 0 ? 0 : (mol * T * constants::R) / V; +} + +double fluid_holder::calc_pressure_mol(double heat, double volume, double pressure) +{ + double T = conversions::temperature::c_to_k(heat); + double V = volume * 0.001; + + return (V * pressure) / (T * constants::R); +} + +double fluid_holder::get_pressure() const +{ + return calc_pressure(heat, get_steam_volume(), fluid.g_to_mol(get_steam())); } double fluid_holder::get_steam_density() const diff --git a/src/coolant/fluid_holder.hpp b/src/coolant/fluid_holder.hpp index 8272f5c..e2ca96c 100644 --- a/src/coolant/fluid_holder.hpp +++ b/src/coolant/fluid_holder.hpp @@ -37,6 +37,9 @@ public: virtual double get_thermal_mass() const { return get_mass() + extra_mass; } // grams virtual double get_pressure() const; // pascals virtual double get_steam_density() const; // g/L + + static double calc_pressure(double temp, double volume, double mass); + static double calc_pressure_mol(double temp, double volume, double pressure); void update(double dt); }; diff --git a/src/coolant/pump.cpp b/src/coolant/pump.cpp index b959f21..0a43748 100644 --- a/src/coolant/pump.cpp +++ b/src/coolant/pump.cpp @@ -6,14 +6,16 @@ using namespace sim::coolant; -pump::pump(fluid_holder* src, fluid_holder* dst, double mass, double radius, double power, double l_per_rev, double friction) : +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) : src(src), dst(dst), mass(mass), radius(radius), l_per_rev(l_per_rev), friction(friction), - max_power(power) + max_power(power), + mode(mode), + target(target) { } @@ -66,21 +68,34 @@ void pump::update(double dt) { if(powered) { - power = pid.calculate(dt, src->get_volume() / 2, src->get_steam_volume()); + switch(mode) + { + case mode_t::SRC: + power = pid.calculate(dt, target, src->get_steam_volume()); + break; + case mode_t::DST: + power = pid.calculate(dt, target, dst->get_level()); + break; + case mode_t::NONE: + power = 1; + break; + } + velocity += calc_work(dt * power * max_power, mass); } - - fluid_holder fh_src(*src); - fluid_holder fh_dst(*dst); + else + { + power = 0; + } + double src_heat = src->get_heat(); double p_diff_1 = dst->get_pressure() - src->get_pressure(); - double src_volume = fh_src.extract_fluid(get_flow_target() * dt); - double dst_volume = fh_dst.add_fluid(src_volume, src_heat); - src->extract_fluid(dst_volume); - dst->add_fluid(dst_volume, src_heat); - + double max_volume = std::min(src->get_level(), 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); + 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; diff --git a/src/coolant/pump.hpp b/src/coolant/pump.hpp index 66fc4f4..68bc16d 100644 --- a/src/coolant/pump.hpp +++ b/src/coolant/pump.hpp @@ -19,16 +19,26 @@ class pump double power = 0; public: + + enum mode_t + { + SRC, + DST, + NONE + }; + + const mode_t mode; const double mass; // grams const double radius; // meters const double l_per_rev; // litres const double friction; // J/rev const double max_power; // W + const double target; // L bool powered = false; - pump(fluid_holder* src, fluid_holder* dst, double mass, double radius, double power, double l_per_rev, double friction); + pump(fluid_holder* src, fluid_holder* dst, double mass, double radius, double power, double l_per_rev, double friction, mode_t mode, double target); double get_flow() const; // L/s double get_flow_target() const; // L/s diff --git a/src/coolant/sink.cpp b/src/coolant/sink.cpp index 0cf22c5..4548aca 100644 --- a/src/coolant/sink.cpp +++ b/src/coolant/sink.cpp @@ -7,8 +7,8 @@ sink::sink(fluid_t type, double heat, double pressure, double steam_density) : heat(heat), pressure(pressure), steam_density(steam_density), - fluid_holder(type, 1, 1) + fluid_holder(type, 2e9, 0) { - + level = 1e9; } diff --git a/src/coolant/valve.cpp b/src/coolant/valve.cpp index 53cb9a9..1fa80ba 100644 --- a/src/coolant/valve.cpp +++ b/src/coolant/valve.cpp @@ -39,48 +39,18 @@ void valve::update(double dt) double pressure1 = src->get_pressure(); // Pa double pressure2 = dst->get_pressure(); - int overshoots = 0; - double m = max * state * dt; - double temp, mass; + double m = max * state; + double diff = (pressure1 - pressure2); + double remove = diff - diff * std::pow(1 - m, dt); - for(;;) - { - double diff = (pressure1 - pressure2) * m; // L + double mol = fluid_holder::calc_pressure_mol(src->get_heat(), src->get_steam_volume(), pressure1 - remove); + double mass = src->get_steam() - src->fluid.mol_to_g(mol); + + double heat1 = src->get_heat(); // C + double heat2 = dst->get_heat(); - if(diff > 0) - { - temp = src->get_heat(); - mass = std::min(diff * src->get_steam_density(), src->get_steam()); - } - - else - { - temp = dst->get_heat(); - mass = std::min(diff * dst->get_steam_density(), dst->get_steam()); - } - - fluid_holder fh_src(*src); - fluid_holder fh_dst(*dst); - - fh_src.add_steam(-mass, temp); - fh_dst.add_steam(mass, temp); - -// if((pressure1 > fh_dst.get_pressure()) == (pressure2 < fh_src.get_pressure())) - { - break; - } - - overshoots += 1; - m *= 0.5; - } - - if(overshoots > 0) - { - std::cout << "Warning: overshot " << overshoots << " times\n"; - } - - src->add_steam(-mass, temp); - dst->add_steam(mass, temp); + src->add_steam(-mass, heat2); + dst->add_steam(mass, heat1); this->flow = mass / dt; } diff --git a/src/electric/turbine.cpp b/src/electric/turbine.cpp index 1eb5a3d..6e72f7e 100644 --- a/src/electric/turbine.cpp +++ b/src/electric/turbine.cpp @@ -11,7 +11,7 @@ constexpr static double calc_cylinder(double h, double d) { double r = d / 2; - return M_PI * r * r * h; + return M_PI * r * r * h * 1000; } turbine::turbine(coolant::fluid_t type, coolant::condenser* condenser, double length, double diameter, double mass) : diff --git a/src/graphics/monitor/primary_loop.cpp b/src/graphics/monitor/primary_loop.cpp index c57ee41..798a92e 100644 --- a/src/graphics/monitor/primary_loop.cpp +++ b/src/graphics/monitor/primary_loop.cpp @@ -83,12 +83,12 @@ void primary_loop::init() ss << "Turbine Inlet Valve\n\n"; ss << "Opened\nFlow\n\n"; ss << "Primary Pump\n\n"; - ss << "State\nPower\nSpeed\nFlow\n\n"; + ss << "Power\nSpeed\nFlow\n\n"; ss << "Condenser\n\n"; ss << "Heat\n"; ss << "Steam\n"; ss << "Pressure\n"; - ss << "Level\n\n"; + ss << "Level\n"; rmesh.load_text(ss.str().c_str(), 0.04); mesh1.bind(); @@ -116,15 +116,14 @@ void primary_loop::update(double dt) ss << show( sys.turbine_inlet_valve->get_state() * 100 ) << " %\n"; ss << show( sys.turbine_inlet_valve->get_flow() / 1000 ) << " kg/s\n"; ss << "\n\n\n"; - ss << sys.primary_pump->get_state_string() << "\n"; - ss << show( sys.primary_pump->get_power() / 1000 ) << " kW\n"; + ss << show( sys.primary_pump->get_power() * 100 ) << " %\n"; ss << show( sys.primary_pump->get_rpm() ) << " r/min\n"; ss << show( sys.primary_pump->get_flow_mass() / 1000 ) << " kg/s\n"; ss << "\n\n\n"; ss << show( sys.condenser->get_heat() ) << " C\n"; ss << show( sys.condenser->get_steam() ) << " g\n"; ss << show( sys.condenser->get_pressure() / 1000 ) << " kPa\n"; - ss << show( sys.condenser->get_level() ) << " / " << show( sys.condenser->get_volume() ) << " L\n"; + ss << show( sys.condenser->get_level() / 1000 ) << " / " << show( sys.condenser->get_volume() / 1000 ) << " kL\n"; rmesh.load_text(ss.str().c_str(), 0.04); mesh2.bind(); diff --git a/src/graphics/monitor/secondary_loop.cpp b/src/graphics/monitor/secondary_loop.cpp index 1d3a8c8..0c89ec3 100644 --- a/src/graphics/monitor/secondary_loop.cpp +++ b/src/graphics/monitor/secondary_loop.cpp @@ -23,18 +23,16 @@ secondary_loop::secondary_loop() void secondary_loop::toggle_secondary_pump() { system& sys = sim::system::active; - static bool state = false; - state = !state; -// sys.secondary_pump->powered = state = !sys.secondary_pump->powered; + bool state = false; + sys.secondary_pump->powered = state = !sys.secondary_pump->powered; gm_switch_2.model_matrix = glm::translate(glm::mat4(1), glm::vec3(0, state ? 0.07 : 0, 0)); } void secondary_loop::toggle_freight_pump() { system& sys = sim::system::active; - static bool state = false; - state = !state; -// sys.freight_pump->powered = state = !sys.freight_pump->powered; + bool state = false; + sys.freight_pump->powered = state = !sys.freight_pump->powered; gm_switch_3.model_matrix = glm::translate(glm::mat4(1), glm::vec3(0, state ? 0.07 : 0, 0)); } @@ -53,7 +51,12 @@ void secondary_loop::init() std::stringstream ss; sim::graphics::mesh rmesh; - ss << "Secondary Loop\n"; + ss << "Cooling Tower\n\n"; + ss << "Heat\nSteam\nPressure\nLevel\n\n"; + ss << "Secondary Pump\n\n"; + ss << "Power\nSpeed\nFlow\n\n"; + ss << "Freight Pump\n\n"; + ss << "Power\nSpeed\nFlow\n\n"; rmesh.load_text(ss.str().c_str(), 0.04); mesh1.bind(); @@ -79,8 +82,19 @@ void secondary_loop::update(double dt) sim::graphics::mesh rmesh; system& sys = sim::system::active; - //TODO - ss << "TODO\n"; + ss << "\n\n\n"; + ss << show( sys.evaporator->get_heat() ) << " C\n"; + ss << show( sys.evaporator->get_steam_output() ) << " g/s\n"; + ss << show( sys.evaporator->get_pressure() ) << " Pa\n"; + ss << show( sys.evaporator->get_level() / 1000 ) << " / " << show( sys.evaporator->get_volume() / 1000 ) << " kL\n"; + ss << "\n\n\n"; + ss << show( sys.secondary_pump->get_power() * 100 ) << " %\n"; + ss << show( sys.secondary_pump->get_rpm() ) << " r/min\n"; + ss << show( sys.secondary_pump->get_flow_mass() / 1000 ) << " kg/s\n"; + ss << "\n\n\n"; + ss << show( sys.freight_pump->get_power() * 100 ) << " %\n"; + ss << show( sys.freight_pump->get_rpm() ) << " r/min\n"; + ss << show( sys.freight_pump->get_flow_mass() / 1000 ) << " kg/s\n"; rmesh.load_text(ss.str().c_str(), 0.04); mesh2.bind(); diff --git a/src/graphics/monitor/vessel.cpp b/src/graphics/monitor/vessel.cpp index 0ed310b..491c960 100644 --- a/src/graphics/monitor/vessel.cpp +++ b/src/graphics/monitor/vessel.cpp @@ -89,7 +89,7 @@ void vessel::update(double dt) ss << show( sys.vessel->get_heat() ) << " C\n"; ss << show( sys.vessel->get_steam() ) << " g\n"; ss << show( sys.vessel->get_pressure() * 0.001 ) << " kPa\n"; - ss << show( sys.vessel->get_level() ) << " / " << show( sys.vessel->get_volume() ) << " L\n"; + ss << show( sys.vessel->get_level() / 1000 ) << " / " << show( sys.vessel->get_volume() / 1000 ) << " kL\n"; ss << show( sys.vessel->get_void_ratio() * 100 ) << " %\n\n\n\n"; ss << show( sys.reactor->get_energy_output() * 0.001 ) << " kW\n"; ss << show( sys.reactor->get_flux() ) << " n/cm2/s\n\n\n"; diff --git a/src/main.cpp b/src/main.cpp index 3b316f9..4600df8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,6 +18,7 @@ #include "graphics/camera.hpp" #include "system.hpp" +#include "tests.hpp" using namespace sim; @@ -32,6 +33,9 @@ int main() { feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); +// tests::run(); +// return 0; + graphics::window::create(); long clock = get_now(); diff --git a/src/reactor/coolant/vessel.cpp b/src/reactor/coolant/vessel.cpp index a3dcc96..78db76a 100644 --- a/src/reactor/coolant/vessel.cpp +++ b/src/reactor/coolant/vessel.cpp @@ -13,7 +13,7 @@ constexpr static double calc_cylinder(double h, double d) { double r = d / 2; - return M_PI * r * r * h; + return M_PI * r * r * h * 1000; } vessel::vessel(sim::coolant::fluid_t fluid, double height, double diameter, double mass, double level) : diff --git a/src/system.cpp b/src/system.cpp index 6cc8909..8d2e757 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -35,14 +35,21 @@ system::system() " C C C C " }; - vessel = std::make_unique(sim::coolant::WATER, 8, 10, 6e6, 500); + vessel = std::make_unique(sim::coolant::WATER, 8, 10, 6e6, 5e5); reactor = std::make_unique(sim::reactor::builder(19, 19, 1.0 / 4.0, 4, reactor::fuel::fuel_rod(0.5), vessel.get(), layout)); - condenser = std::make_unique(sim::coolant::WATER, 8, 6, 3e6, 0); + condenser = std::make_unique(sim::coolant::WATER, 6, 4, 3e6, 0); turbine = std::make_unique(sim::coolant::WATER, condenser.get(), 6, 3, 2e6); - turbine_inlet_valve = std::make_unique(vessel.get(), turbine.get(), 0, 1e-2); - turbine_bypass_valve = std::make_unique(vessel.get(), condenser.get(), 0, 1e-2); - primary_pump = std::make_unique(condenser.get(), vessel.get(), 1e5, 1, 1e4, 0.1, 10); + sink = std::make_unique(sim::coolant::WATER, 11, 0, 0); + evaporator = std::make_unique(sim::coolant::WATER, 2, 30, 0, 1000); + condenser_secondary = std::make_unique(condenser.get(), evaporator.get()); + + turbine_inlet_valve = std::make_unique(vessel.get(), turbine.get(), 0, 0.5); + turbine_bypass_valve = std::make_unique(vessel.get(), condenser.get(), 0, 0.5); + + primary_pump = std::make_unique(condenser.get(), vessel.get(), 1e5, 1, 1e4, 0.1, 10, coolant::pump::mode_t::SRC, 35000); + secondary_pump = std::make_unique(evaporator.get(), condenser_secondary.get(), 1e5, 1, 1e4, 0.1, 10, coolant::pump::mode_t::NONE, 0); + freight_pump = std::make_unique(sink.get(), evaporator.get(), 1e5, 1, 1e4, 0.1, 10, coolant::pump::mode_t::DST, 1e6); } system::system(system&& o) @@ -51,9 +58,17 @@ system::system(system&& o) reactor = std::move(o.reactor); condenser = std::move(o.condenser); turbine = std::move(o.turbine); + + sink = std::move(o.sink); + condenser_secondary = std::move(o.condenser_secondary); + evaporator = std::move(o.evaporator); + turbine_bypass_valve = std::move(o.turbine_bypass_valve); turbine_inlet_valve = std::move(o.turbine_inlet_valve); + primary_pump = std::move(o.primary_pump); + secondary_pump = std::move(o.secondary_pump); + freight_pump = std::move(o.freight_pump); } void system::update(double dt) @@ -68,6 +83,12 @@ void system::update(double dt) turbine->update(dt); condenser->update(dt); - primary_pump->update(dt); + +// evaporator->update(dt); +// condenser_secondary->update(dt); + +// primary_pump->update(dt); +// secondary_pump->update(dt); +// freight_pump->update(dt); } diff --git a/src/system.hpp b/src/system.hpp index f2aa8ba..e18c4e8 100644 --- a/src/system.hpp +++ b/src/system.hpp @@ -8,6 +8,9 @@ #include "coolant/pump.hpp" #include "coolant/valve.hpp" #include "coolant/condenser.hpp" +#include "coolant/condenser_secondary.hpp" +#include "coolant/evaporator.hpp" +#include "coolant/sink.hpp" #include "electric/turbine.hpp" #include "graphics/mesh/mesh.hpp" @@ -20,11 +23,20 @@ struct system std::unique_ptr reactor; std::unique_ptr vessel; + + std::unique_ptr sink; std::unique_ptr condenser; + std::unique_ptr condenser_secondary; + std::unique_ptr evaporator; std::unique_ptr turbine; + std::unique_ptr primary_pump; + std::unique_ptr secondary_pump; + std::unique_ptr freight_pump; + std::unique_ptr turbine_bypass_valve; std::unique_ptr turbine_inlet_valve; + sim::graphics::mesh scene; double speed = 1; diff --git a/src/tests.cpp b/src/tests.cpp new file mode 100644 index 0000000..03cf3ac --- /dev/null +++ b/src/tests.cpp @@ -0,0 +1,44 @@ + +#include "tests.hpp" +#include "coolant/valve.hpp" +#include "coolant/fluid_holder.hpp" + +#include +#include + +using namespace sim; +using namespace sim::coolant; + +std::ostream& operator<<(std::ostream& o, const fluid_holder& fh) +{ + o << "Fluid Holder\n"; + o << "Heat " << fh.get_heat() << " C\n"; + o << "Steam " << fh.get_steam() << " g\n"; + o << "Pressure " << fh.get_pressure() << " Pa\n"; + o << "Volume " << fh.get_level() / 1000 << " / " << fh.get_volume() / 1000 << " kL\n\n"; + + return o; +} + +void tests::run() +{ + fluid_holder src(WATER, 1e6, 0); + fluid_holder dst(WATER, 1e6, 0); + + src.add_fluid(1e5, 11); + + valve v(&src, &dst, 1, 0.5); + double dt = 0.001; + double at = 0; + + for(int i = 0; i < 10000; i++) + { + src.update(dt); + dst.update(dt); + v.update(dt); + + std::cout << at << "\t" << src.get_pressure() << "\t" << dst.get_pressure() << "\n"; + at += dt; + } +} + diff --git a/src/tests.hpp b/src/tests.hpp new file mode 100644 index 0000000..e8b2408 --- /dev/null +++ b/src/tests.hpp @@ -0,0 +1,10 @@ + +#pragma once + +namespace sim::tests +{ + +void run(); + +}; +