44 lines
2.6 KiB
C++
44 lines
2.6 KiB
C++
#include "FluidSim/Scenario.hpp"
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
using namespace fluidsim::port;
|
|
namespace {
|
|
void check(bool condition, const char* message) { if (!condition) throw std::runtime_error(message); }
|
|
}
|
|
int main() {
|
|
TurboTwinScenario s;
|
|
double maximum_speed = 0, maximum_charge = 0, maximum_turbine_pressure = 0;
|
|
double maximum_gate = 0, peak_audio = 0, coast_speed = 0;
|
|
for (int sample = 0; sample < 7*44100; ++sample) {
|
|
// Idle, accelerate/limiter operation, abrupt pedal release, then recover.
|
|
s.set_controls(sample >= 44100 && sample < 4*44100 ? .7f : 0, 0, 1);
|
|
const auto audio = s.process();
|
|
check(std::isfinite(audio.left) && std::isfinite(audio.right), "nonfinite turbo twin audio");
|
|
peak_audio = std::max({peak_audio, double(std::abs(audio.left)), double(std::abs(audio.right))});
|
|
const auto t = s.turbo->snapshot();
|
|
check(t.rpm >= 0 && std::isfinite(t.rpm) && t.charge_temperature > 0 &&
|
|
t.turbine_inlet_pressure > 0 && t.turbine_outlet_pressure > 0,
|
|
"turbo twin developed nonphysical turbo state");
|
|
maximum_speed = std::max(maximum_speed, t.rpm);
|
|
maximum_charge = std::max(maximum_charge, t.charge_pressure);
|
|
maximum_turbine_pressure = std::max(maximum_turbine_pressure, t.turbine_inlet_pressure);
|
|
maximum_gate = std::max(maximum_gate, t.wastegate_lift);
|
|
if (sample == 5*44100) coast_speed = t.rpm;
|
|
}
|
|
const auto final = s.turbo->snapshot();
|
|
check(maximum_speed > 50000 && maximum_charge > 120000, "turbo did not spool and generate boost");
|
|
check(maximum_turbine_pressure > maximum_charge, "twin has no turbine backpressure");
|
|
check(maximum_gate > 0, "wastegate never opened under boost");
|
|
check(final.rpm < coast_speed, "turbo did not coast down after throttle release");
|
|
check(final.limited_transfers == 0, "turbo twin depleted its internal volumes");
|
|
check(std::abs(final.energy_residual) < .1, "turbo twin accumulated excessive energy residual");
|
|
check(peak_audio < 1, "turbo twin audio exceeds device range");
|
|
for (const auto& p : s.pipes) check(p.positivity_repairs == 0, "turbo twin required pipe repairs");
|
|
std::cout << "Turbo twin passed: max_rpm=" << maximum_speed << ", max_charge=" << maximum_charge/1000
|
|
<< " kPa, max_turbine_pressure=" << maximum_turbine_pressure/1000 << " kPa, gate=" << maximum_gate*1000
|
|
<< " mm, final_rpm=" << final.rpm << ", peak_audio=" << peak_audio
|
|
<< ", energy_residual=" << final.energy_residual << " J\n";
|
|
}
|