Add turbocharged twin scenario and cross-platform test harness

This commit is contained in:
2026-10-23 02:27:03 +02:00
parent a859740a95
commit 589d22aa5e
63 changed files with 4903 additions and 771 deletions

View File

@@ -0,0 +1,62 @@
#include "FluidSim/PulseTestScenario.hpp"
#include "FluidSim/Scenario.hpp"
#include <chrono>
#include <iostream>
#include <string>
using namespace fluidsim::port;
int main(int argc, char **argv) {
// Track the hot-engine cost over time; a one-second benchmark misses it.
if (argc > 1 && std::string(argv[1]) == "--soak") {
const int seconds = argc > 2 ? std::stoi(argv[2]) : 12;
for (float pedal : {0.0f, 1.0f}) {
FourStrokeTwinScenario scenario;
scenario.throttle = pedal;
for (int second = 0; second < seconds; ++second) {
const auto before = scenario.snapshot();
const auto start = std::chrono::steady_clock::now();
for (int sample = 0; sample < 44100; ++sample)
scenario.process();
const double wall =
std::chrono::duration<double>(std::chrono::steady_clock::now() - start).count();
const auto after = scenario.snapshot();
std::cout << "pedal=" << pedal << " second=" << second + 1 << " wall_seconds=" << wall
<< " rpm=" << after.rpm
<< " substeps/frame=" << (after.solver_substeps - before.solver_substeps) / 44100.0
<< " boundary_iterations/frame="
<< (after.boundary_iterations - before.boundary_iterations) / 44100.0 << std::endl;
}
}
return 0;
}
int samples = argc > 1 ? std::stoi(argv[1]) : 44100;
for (int n : {64, 256, 1024}) {
Pipe1D p(.001f, 2.f, n);
p.damping_multiplier = 0;
p.energy_relaxation_rate = 0;
double sum = 0;
auto t = std::chrono::steady_clock::now();
for (int i = 0; i < samples; i++) {
auto l = p.state(0), r = p.state(n - 1);
l.velocity = -l.velocity;
r.velocity = -r.velocity;
p.left_ghost = l;
p.right_ghost = r;
p.advance(0.0000005f);
sum += p.state(n / 2).pressure;
}
double sec = std::chrono::duration<double>(std::chrono::steady_clock::now() - t).count();
std::cout << "pipe cells=" << n << " steps=" << samples << " seconds=" << sec
<< " Mcells/s=" << n * double(samples) / sec / 1e6 << " checksum=" << sum << '\n';
}
FourStrokeTwinScenario s;
s.throttle = .35f;
double sum = 0;
auto t = std::chrono::steady_clock::now();
for (int i = 0; i < samples; i++) {
auto a = s.process();
sum += a.left;
}
double sec = std::chrono::duration<double>(std::chrono::steady_clock::now() - t).count();
std::cout << "twin seconds=" << sec << " realtime_factor=" << samples / 44100.0 / sec
<< " checksum=" << sum << '\n';
}