2024-02-02 22:03:47 +11:00
|
|
|
|
|
|
|
#include "valve.hpp"
|
|
|
|
|
2024-02-04 23:22:15 +11:00
|
|
|
#include <cmath>
|
|
|
|
#include <iostream>
|
|
|
|
|
2024-02-02 22:03:47 +11:00
|
|
|
using namespace sim::coolant;
|
|
|
|
|
2024-02-03 18:12:18 +11:00
|
|
|
valve::valve(fluid_holder* src, fluid_holder* dst, double max) : src(src), dst(dst), max(max)
|
2024-02-02 22:03:47 +11:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-02-03 18:12:18 +11:00
|
|
|
void valve::add_open_speed(double v)
|
2024-02-02 22:03:47 +11:00
|
|
|
{
|
2024-02-04 23:22:15 +11:00
|
|
|
speed += v;
|
2024-02-02 22:03:47 +11:00
|
|
|
}
|
|
|
|
|
2024-02-03 18:12:18 +11:00
|
|
|
void valve::clear_open_speed()
|
2024-02-02 22:03:47 +11:00
|
|
|
{
|
2024-02-04 23:22:15 +11:00
|
|
|
speed = 0;
|
2024-02-02 22:03:47 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
void valve::update(double dt)
|
|
|
|
{
|
2024-02-04 23:22:15 +11:00
|
|
|
state += speed * dt;
|
|
|
|
|
2024-02-03 18:12:18 +11:00
|
|
|
if(state > 1) state = 1;
|
|
|
|
if(state < 0) state = 0;
|
2024-02-04 23:22:15 +11:00
|
|
|
|
|
|
|
double r = max * state; // L
|
|
|
|
double m = r * dt;//1 - std::pow(0.5, dt * -std::log2(1 - r));
|
|
|
|
|
|
|
|
double pressure1 = src->get_pressure();
|
|
|
|
double pressure2 = dst->get_pressure();
|
|
|
|
double density1 = src->get_steam_density(); // g/L
|
|
|
|
double density2 = dst->get_steam_density(); // g/L
|
|
|
|
double diff = (pressure1 - pressure2) * m;
|
|
|
|
double temp, mass;
|
|
|
|
|
|
|
|
if(diff > 0)
|
|
|
|
{
|
|
|
|
temp = src->get_heat();
|
|
|
|
mass = diff * src->get_steam_density();
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
temp = dst->get_heat();
|
|
|
|
mass = diff * dst->get_steam_density();
|
|
|
|
}
|
|
|
|
|
|
|
|
src->add_steam(-mass, temp);
|
|
|
|
dst->add_steam(mass, temp);
|
|
|
|
|
|
|
|
this->flow = mass / dt;
|
2024-02-02 22:03:47 +11:00
|
|
|
}
|
|
|
|
|