Load engines from TOML and improve scenario audio and carb tuning

Migrate 32 engine definitions into validated startup-loaded TOML files and separate configuration and snapshots from scenario assembly. Add camera-based stereo propagation from shared pipe geometry, preserve exhaust character, tune carburetor mixtures and idle, use ignition cuts for carb engines, and support returning to the scenario menu.

Validation: full Windows build and all 14 CTest checks passed.
This commit is contained in:
max
2026-10-24 03:24:35 +02:00
parent 5607dcf2b5
commit bf8621ad39
82 changed files with 24084 additions and 648 deletions

View File

@@ -1,5 +1,7 @@
#pragma once
#include "FluidSim/Silencer.hpp"
#include "FluidSim/EngineConfig.hpp"
#include "FluidSim/ScenarioSnapshot.hpp"
#include "FluidSim/Carburetor.hpp"
#include <string>
#include "FluidSim/Junction.hpp"
@@ -19,85 +21,24 @@
#include <vector>
namespace fluidsim::port {
struct ScenarioExample;
enum class ScenarioKind { Twin, TwoStroke, SaabB205, AmericanV8 };
enum class FourStrokePreset { Twin, SaabB205, AmericanV8 };
enum class EngineLayout { Inline, V, Boxer };
struct EngineConfig {
int cylinders{}; // zero selects the existing preset
EngineLayout layout{EngineLayout::Inline};
float bank_angle{60}, bore{.086f}, stroke{.086f}, rod{.145f}, compression{10};
float idle_rpm{1000}, rev_limit{7000}, idle_opening{.045f};
bool carbureted{};
float carb_pilot_scale{1.f};
float carb_jet_scale{1.f}; // multiplier on displacement-scaled effective jet diameters
std::array<float,12> phase_degrees{}; // used when custom_phases is true
bool custom_phases{};
};
struct V8ExhaustConfig {
float primary_length{.75f}, primary_diameter{.038f};
bool h_pipe{true};
float junction_volume{50e-6f}; // m3, 50 cc per fitting
};
struct ScenarioSnapshot {
std::string example_name;
EngineLayout layout{EngineLayout::Inline};
float bank_angle{};
bool v8_headers{};
PipeSolver pipe_solver{PipeSolver::Rusanov};
int cylinder_count{2};
float rev_limit_rpm{10000};
std::array<float, 12> cylinder_angles{};
std::array<float, 12> cylinder_pressures{}, piston_fractions{}, intake_areas{}, exhaust_areas{};
std::uint64_t solver_substeps{}, boundary_iterations{}, pipe_positivity_repairs{};
float rpm{}, speed_kmh{}, kinetic_energy{}, average_power{}, average_torque{};
float cylinder_pressure1{}, cylinder_pressure2{};
float cylinder_temperature1{}, cylinder_temperature2{};
float cylinder_piston_fraction1{}, cylinder_piston_fraction2{};
float valve1_intake_area{}, valve1_exhaust_area{}, valve2_intake_area{}, valve2_exhaust_area{};
float intake_pressure{}, exhaust_pressure{}, second_bank_pressure{};
std::array<float,2> crossover_pressures{};
float throttle{}, pedal{}, target_afr{}, clutch{}, intake_flow{}, exhaust_flow{};
bool idle_control{}, fuel_cut{}, two_stroke{}, reed_open{};
bool racing_exhaust{};
bool silencers{}, h_pipe{};
ExhaustConfig exhaust_config{};
float crankcase_pressure{};
OutdoorScene audio_scene{OutdoorScene::Wall};
int gear{};
bool rev_limit1{}, rev_limit2{};
std::array<std::vector<GasState>, 32> pipe_states;
std::array<std::vector<float>, 32> pipe_areas, pipe_lengths;
void capture_pipes(const std::vector<Pipe1D>& pipes) {
for (std::size_t k = 0; k < pipes.size(); ++k) {
pipe_positivity_repairs += pipes[k].positivity_repairs;
pipe_areas[k] = pipes[k].cell_areas;
pipe_lengths[k] = pipes[k].cell_lengths;
pipe_states[k].reserve(pipes[k].cells.size());
for (std::size_t i = 0; i < pipes[k].cells.size(); ++i)
pipe_states[k].push_back(pipes[k].state(static_cast<int>(i)));
}
}
};
// Shared four-stroke topology: independent runners/headers and shared plenums.
// Presets include a 600 cc twin, B205-sized inline-four and American 5.0 V8.
// Calibrated four-stroke assembly with independent runners and shared plenums.
class FourStrokeScenario : public MotorcycleTest {
public:
explicit FourStrokeScenario(int sample_rate = 44100, FourStrokePreset preset = FourStrokePreset::Twin, ExhaustConfig exhaust = {}, V8ExhaustConfig v8_exhaust = {}, EngineConfig engine = {});
const FourStrokePreset preset;
explicit FourStrokeScenario(int sample_rate = 44100, FourStrokePreset preset = FourStrokePreset::Twin);
FourStrokeScenario(int sample_rate, const ScenarioExample& definition);
FourStrokeScenario(int sample_rate, EngineConfig engine, ExhaustConfig exhaust = {}, JunctionConfig junctions = {});
const ExhaustConfig exhaust_config;
const V8ExhaustConfig v8_exhaust_config;
const JunctionConfig junction_config;
const EngineConfig engine_config;
int cylinder_count() const { return engine_config.cylinders ? engine_config.cylinders : preset == FourStrokePreset::AmericanV8 ? 8 : preset == FourStrokePreset::SaabB205 ? 4 : 2; }
int cylinder_count() const { return engine_config.cylinders; }
std::array<FourStrokeCylinder*, 12> cylinders() { return {&cylinder1, &cylinder2, &cylinder3, &cylinder4,
&cylinder5, &cylinder6, &cylinder7, &cylinder8,&cylinder9,&cylinder10,&cylinder11,&cylinder12}; }
AudioFrame process();
void set_controls(float throttle_value, float load_value, float clutch_value);
void set_audio_scene(OutdoorScene scene);
void set_listener(AudioListener listener);
void set_pipe_solver(PipeSolver solver);
void set_monitor_filter(bool enabled);
void set_starter(bool engaged);
@@ -115,8 +56,8 @@ public:
FourStrokeCylinder cylinder1{}, cylinder2{}, cylinder3{}, cylinder4{};
FourStrokeCylinder cylinder5{}, cylinder6{}, cylinder7{}, cylinder8{};
FourStrokeCylinder cylinder9{}, cylinder10{}, cylinder11{}, cylinder12{};
Volume0D intake_plenum{1.0e-3f, 101325.0f, 300.0f};
Junction exhaust_collector{0.15e-3f, 101325.0f, 700.0f};
Volume0D intake_plenum;
Junction exhaust_collector;
std::vector<Pipe1D> pipes;
float intake_flow{}, exhaust_flow{};
std::uint64_t sample_count{};
@@ -134,7 +75,7 @@ private:
Port* throttle_port_{};
static float area_for_diameter(float diameter);
static std::vector<Pipe1D> create_pipes(FourStrokePreset preset, const ExhaustConfig& exhaust, const V8ExhaustConfig& v8_exhaust, const EngineConfig& engine);
static std::vector<Pipe1D> create_pipes(const EngineConfig& engine, const ExhaustConfig& exhaust);
};
using FourStrokeTwinScenario = FourStrokeScenario;