Add turbocharged twin scenario and cross-platform test harness
This commit is contained in:
51
tests/intake_regression.cpp
Normal file
51
tests/intake_regression.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "FluidSim/Scenario.hpp"
|
||||
#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);
|
||||
}
|
||||
void run(FourStrokeTwinScenario &s, float seconds, float pedal) {
|
||||
s.throttle = pedal;
|
||||
for (int i = 0; i < int(std::lround(seconds * 44100)); ++i) {
|
||||
const auto audio = s.process();
|
||||
check(std::isfinite(audio.left) && std::isfinite(audio.right), "nonfinite transient audio");
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
int main() {
|
||||
FourStrokeTwinScenario s;
|
||||
run(s, 3, 0);
|
||||
run(s, .5f, .8f);
|
||||
run(s, 4.5f, 0);
|
||||
const float idle_map = s.intake_plenum.pressure();
|
||||
check(idle_map > 20000 && idle_map < 80000, "idle MAP did not recover after first blip");
|
||||
run(s, 1, 1);
|
||||
const float open_map = s.intake_plenum.pressure();
|
||||
const float open_temperature = s.intake_plenum.temperature();
|
||||
const auto inlet = s.pipes.front().state(0);
|
||||
const float inlet_temperature = inlet.pressure / (inlet.rho * gas_constant);
|
||||
check(open_map > 75000 && open_map > idle_map + 20000,
|
||||
"opening throttle did not relieve manifold vacuum");
|
||||
check(open_temperature > 250 && open_temperature < 400,
|
||||
"fresh charge heats progressively after repeated blips");
|
||||
check(inlet_temperature > 280 && inlet_temperature < 320,
|
||||
"inlet no longer supplies near-ambient fresh air");
|
||||
check(std::abs(s.intake_atmosphere.port.temperature - 300) < .01f, "reservoir temperature drift");
|
||||
check(std::abs(s.intake_atmosphere.port.air_fraction - 1) < 1e-6, "reservoir admits exhaust composition");
|
||||
run(s, 7, 0);
|
||||
const auto recovered = s.snapshot();
|
||||
check(recovered.rpm > 1000 && recovered.rpm < 2600, "engine did not recover idle after second blip");
|
||||
check(recovered.intake_pressure > 20000 && recovered.intake_pressure < 80000,
|
||||
"manifold remains evacuated after idle recovery");
|
||||
for (const auto &p : s.pipes)
|
||||
check(p.positivity_repairs == 0, "intake transient required positivity repairs");
|
||||
std::cout << "Intake regression passed: idle_MAP=" << idle_map / 1000
|
||||
<< " kPa, open_MAP=" << open_map / 1000 << " kPa, open_T=" << open_temperature
|
||||
<< " K, inlet_T=" << inlet_temperature
|
||||
<< " K, recovered_MAP=" << recovered.intake_pressure / 1000
|
||||
<< " kPa, recovered_RPM=" << recovered.rpm << '\n';
|
||||
}
|
||||
Reference in New Issue
Block a user