Add turbocharged twin scenario and cross-platform test harness
This commit is contained in:
48
tools/turbo_benchmark.cpp
Normal file
48
tools/turbo_benchmark.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "FluidSim/Scenario.hpp"
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
using namespace fluidsim::port;
|
||||
int main() {
|
||||
std::cout << "engine_rpm,turbo,MAP_kPa,exhaust_kPa,shaft_kW,turbo_rpm,charge_kPa,charge_K,turbine_power_ripple_W,gate_mm,limited,energy_residual_J,substeps_per_frame,iterations_per_frame,wall_s,cpu_s\n";
|
||||
for (float rpm : {4000.f, 7000.f}) {
|
||||
for (bool enabled : {false, true}) {
|
||||
FourStrokeScenario s(44100, FourStrokePreset::Twin, enabled);
|
||||
s.throttle = .7f;
|
||||
double map = 0, exhaust = 0, power = 0, turbo_rpm = 0, charge_p = 0, charge_t = 0, gate = 0;
|
||||
double min_power = 1e30, max_power = -1e30;
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
const auto cpu_start = std::clock();
|
||||
for (int i = 0; i < 2*44100; ++i) {
|
||||
// Ideal speed-holding dyno. The turbo remains completely free.
|
||||
s.crankshaft.omega = rpm*2*pi/60;
|
||||
s.process();
|
||||
if (i >= 3*44100/2) {
|
||||
constexpr double samples = 22050;
|
||||
map += s.intake_plenum.pressure()/samples/1000;
|
||||
exhaust += s.exhaust_collector.pressure()/samples/1000;
|
||||
power += s.crankshaft.average_power/samples/1000;
|
||||
if (s.turbo) {
|
||||
const auto t = s.turbo->snapshot();
|
||||
turbo_rpm += t.rpm/samples;
|
||||
charge_p += t.charge_pressure/samples/1000;
|
||||
charge_t += t.charge_temperature/samples;
|
||||
gate += t.wastegate_lift/samples*1000;
|
||||
min_power = std::min(min_power, t.turbine_power);
|
||||
max_power = std::max(max_power, t.turbine_power);
|
||||
}
|
||||
}
|
||||
}
|
||||
const auto t = s.turbo ? s.turbo->snapshot() : TurboSnapshot{};
|
||||
const auto state = s.snapshot();
|
||||
const double cpu = double(std::clock()-cpu_start)/CLOCKS_PER_SEC;
|
||||
const auto wall = std::chrono::duration<double>(std::chrono::steady_clock::now()-start).count();
|
||||
std::cout << rpm << ',' << enabled << ',' << map << ',' << exhaust << ',' << power << ','
|
||||
<< turbo_rpm << ',' << charge_p << ',' << charge_t << ','
|
||||
<< (enabled ? max_power-min_power : 0) << ',' << gate << ',' << t.limited_transfers
|
||||
<< ',' << t.energy_residual << ',' << state.solver_substeps/88200.0 << ','
|
||||
<< state.boundary_iterations/88200.0 << ',' << wall << ',' << cpu << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user