Add turbocharged twin scenario and cross-platform test harness
This commit is contained in:
33
src/main.cpp
33
src/main.cpp
@@ -15,20 +15,34 @@ int main(int argc, char** argv) {
|
||||
float duration_seconds = 1.0f;
|
||||
float throttle = 0.35f;
|
||||
std::string scenario_name = "twin";
|
||||
TwoStrokeConfig two_stroke_config;
|
||||
bool turbo_enabled = false;
|
||||
for (int i = 1; i + 1 < argc; ++i) {
|
||||
const std::string option = argv[i];
|
||||
if (option == "--seconds") duration_seconds = std::max(0.0f, std::strtof(argv[++i], nullptr));
|
||||
else if (option == "--throttle") throttle = std::clamp(std::strtof(argv[++i], nullptr), 0.0f, 1.0f);
|
||||
else if (option == "--scenario") scenario_name = argv[++i];
|
||||
else if (option == "--turbo") {
|
||||
const std::string value = argv[++i];
|
||||
if (value != "none" && value != "vz21") { std::cerr << "Choose none or vz21 turbo\n"; return 2; }
|
||||
turbo_enabled = value == "vz21";
|
||||
}
|
||||
else if (option == "--exhaust") {
|
||||
const std::string value = argv[++i];
|
||||
if (value == "racing") two_stroke_config.exhaust = TwoStrokeExhaust::Racing;
|
||||
else if (value == "straight") two_stroke_config.exhaust = TwoStrokeExhaust::Straight;
|
||||
else { std::cerr << "Choose racing or straight exhaust\n"; return 2; }
|
||||
}
|
||||
}
|
||||
|
||||
if (turbo_enabled && scenario_name != "twin") { std::cerr << "The turbo test preset uses --scenario twin\n"; return 2; }
|
||||
constexpr int sample_rate = 44100;
|
||||
const auto total_samples = static_cast<std::uint64_t>(duration_seconds * sample_rate);
|
||||
const auto report_interval = static_cast<std::uint64_t>(sample_rate / 10);
|
||||
if (scenario_name == "twin") {
|
||||
FourStrokeTwinScenario scenario;
|
||||
if (scenario_name == "twin" || scenario_name == "b205") {
|
||||
FourStrokeScenario scenario(sample_rate, scenario_name == "b205" ? FourStrokePreset::SaabB205 : FourStrokePreset::Twin, turbo_enabled);
|
||||
scenario.throttle = throttle;
|
||||
std::cout << "FluidSimCpp | 600 cc parallel twin | throttle " << std::fixed << std::setprecision(0)
|
||||
std::cout << (scenario_name == "b205" ? "FluidSimCpp | Saab B205 / 9-5 wagon (no turbo) | throttle " : "FluidSimCpp | 600 cc parallel twin | throttle ") << std::fixed << std::setprecision(0)
|
||||
<< throttle * 100.0f << "%\n";
|
||||
for (std::uint64_t i = 0; i < total_samples; ++i) {
|
||||
scenario.process();
|
||||
@@ -41,11 +55,18 @@ int main(int argc, char** argv) {
|
||||
<< " cyl=" << scenario.cylinder1.pressure / 1000.0f << "/"
|
||||
<< scenario.cylinder2.pressure / 1000.0f << " kPa"
|
||||
<< " intake=" << scenario.intake_plenum.pressure() / 1000.0f << " kPa"
|
||||
<< " exhaust=" << scenario.exhaust_collector.pressure() / 1000.0f << " kPa\n";
|
||||
<< " exhaust=" << scenario.exhaust_collector.pressure() / 1000.0f << " kPa";
|
||||
if (scenario.turbo) {
|
||||
const auto turbo = scenario.turbo->snapshot();
|
||||
std::cout << " turbo_rpm=" << turbo.rpm << " CPR=" << turbo.compressor_pressure_ratio
|
||||
<< " turbine_in=" << turbo.turbine_inlet_pressure/1000 << " kPa"
|
||||
<< " charge_T=" << turbo.charge_temperature << " K";
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
}
|
||||
} else if (scenario_name == "two-stroke") {
|
||||
TwoStrokeScenario scenario;
|
||||
TwoStrokeScenario scenario(sample_rate, two_stroke_config);
|
||||
scenario.set_throttle(throttle);
|
||||
std::cout << "FluidSimCpp | 125 cc crankcase-scavenged two-stroke | throttle "
|
||||
<< std::fixed << std::setprecision(0) << throttle * 100.0f << "%\n";
|
||||
@@ -88,7 +109,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
} else {
|
||||
std::cerr << "Unknown scenario '" << scenario_name
|
||||
<< "'. Choose twin, two-stroke, helmholtz, or pulse.\n";
|
||||
<< "'. Choose twin, two-stroke, b205, helmholtz, or pulse.\n";
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user