#include "FluidSim/Scenario.hpp" #include #include #include using namespace fluidsim::port; void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } int main() { Ecu ecu; ecu.boost_control_enabled = true; ecu.step(.001f, 1, 3500); for (int i=0;i<1000;++i) ecu.control_boost(.001f,1,3500,110000,115000); check(ecu.wastegate_duty()>0 && ecu.wastegate_duty()<=.85f,"no spool duty"); ecu.control_boost(.001f,1,3500,190000,190000); check(ecu.fuel_cut() && ecu.wastegate_duty()==0,"overboost protection failed"); ecu.control_boost(.001f,1,3500,140000,140000); check(!ecu.fuel_cut(),"overboost recovery failed"); ecu.control_boost(.001f,0,3500,100000,100000); check(ecu.wastegate_duty()==0 && ecu.boost_target()==0,"lift-off did not restore spring control"); ecu.control_boost(.001f,1,3500,NAN,100000); check(ecu.fuel_cut() && ecu.wastegate_duty()==0,"boost sensor fail-safe failed"); FourStrokeScenario s(44100,FourStrokePreset::SaabB205,true); check(s.pipes.size()==12 && s.turbo && s.ecu.boost_control_enabled,"Saab turbo topology missing"); double peak_rpm=0, peak_map=0, peak_audio=0, settled_pressure=0; for(int second=0;second<10;++second) { for(int i=0;i<44100;++i) { s.throttle = second>=1 && second<7 ? 1.f : 0.f; if(second<7) s.crankshaft.omega=3500*2*pi/60; const auto a=s.process(); if(second>=4 && second<7) settled_pressure+=s.intake_plenum.pressure()/(3.*44100); check(std::isfinite(a.left) && std::isfinite(a.right),"nonfinite audio"); peak_audio=std::max(peak_audio,double(std::abs(a.left))); } auto t=s.turbo->snapshot(); peak_rpm=std::max(peak_rpm,t.rpm); peak_map=std::max(peak_map,double(s.intake_plenum.pressure())); check(std::isfinite(t.rpm) && std::abs(t.energy_residual)<.1,"turbo energy balance failed"); check(t.limited_transfers==0,"housing donor limit hit"); std::cout<snapshot().rpm