all of the changes
This commit is contained in:
@@ -9,8 +9,10 @@
|
||||
#include "FluidSim/OutdoorExhaustReverb.hpp"
|
||||
#include "FluidSim/HelmholtzScenario.hpp"
|
||||
#include "FluidSim/PulseTestScenario.hpp"
|
||||
#include "FluidSim/ThreadLoadTracker.hpp"
|
||||
#include "FluidSim/Units.hpp"
|
||||
#include "FluidSim/Desktop/PedalControl.hpp"
|
||||
#include "FluidSim/Desktop/PipePath.hpp"
|
||||
#include "FluidSim/Desktop/PressurePalette.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
@@ -28,7 +30,64 @@ void require(bool condition, const char* message) {
|
||||
int main() {
|
||||
using namespace fluidsim::port;
|
||||
|
||||
Ecu fixed_idle;
|
||||
fixed_idle.idle_control=Ecu::IdleControl::FixedOpening;
|
||||
fixed_idle.idle_base_opening=.049f;
|
||||
fixed_idle.overrun_fuel_cut_enabled=false;
|
||||
for(float rpm : {0.f,500.f,3000.f,9000.f}) {
|
||||
for(int i=0;i<4410;++i) fixed_idle.step(1.f/44100,0,rpm);
|
||||
require(std::abs(fixed_idle.throttle_opening()-.049f)<1e-5f,
|
||||
"fixed carb idle must not vary with RPM");
|
||||
}
|
||||
for(int i=0;i<4410;++i) fixed_idle.step(1.f/44100,.2f,3000);
|
||||
require(std::abs(fixed_idle.throttle_opening()-.2f)<1e-5f,"pedal must open above carb stop");
|
||||
for(int i=0;i<4410;++i) fixed_idle.step(1.f/44100,.01f,3000);
|
||||
require(std::abs(fixed_idle.throttle_opening()-.049f)<1e-5f,"release must return to carb stop");
|
||||
for(auto preset : {FourStrokePreset::Twin,FourStrokePreset::SaabB205,FourStrokePreset::AmericanV8}) {
|
||||
FourStrokeScenario starter(44100,preset);
|
||||
starter.crankshaft.omega=0;
|
||||
starter.set_starter(true);
|
||||
starter.process();
|
||||
require(starter.crankshaft.omega>0,"starter must turn every four-stroke crank from rest");
|
||||
starter.set_starter(false);
|
||||
require(!starter.starter_engaged,"starter release must disengage");
|
||||
}
|
||||
{
|
||||
TwoStrokeConfig config; config.idle_slide_opening=.071f;
|
||||
TwoStrokeScenario starter(44100,config);
|
||||
require(starter.ecu.idle_base_opening==.071f,"scenario must configure carb idle stop");
|
||||
starter.crankshaft.omega=0; starter.set_starter(true); starter.process();
|
||||
require(starter.crankshaft.omega>0,"starter must turn two-stroke crank from rest");
|
||||
starter.set_starter(false);
|
||||
}
|
||||
|
||||
desktop::PedalControl pedal;
|
||||
for(int i=0;i<100;++i)pedal.advance(.0025f,true,false);
|
||||
require(std::abs(pedal.value()-.5f)<1e-5f,"W pedal travel must be halfway after 0.25 seconds");
|
||||
for(int i=0;i<100;++i)pedal.advance(.0025f,true,false);
|
||||
require(std::abs(pedal.value()-1)<1e-5f,"W must reach full pedal in 0.5 seconds");
|
||||
for(int i=0;i<200;++i)pedal.advance(.0025f,false,false);
|
||||
require(pedal.value()<1e-5f,"keyboard release must return pedal in 0.5 seconds");
|
||||
pedal.set(.8f);
|
||||
for(int i=0;i<200;++i)pedal.advance(.0025f,false,true);
|
||||
require(pedal.value()==0,"S must release pedal");
|
||||
desktop::PipePath path({{0,{0,0,0}},{.25f,{.2f,.1f,0}},{1,{1,0,.1f}}});
|
||||
auto knot=path.position(.25f),direction=path.tangent(.25f);
|
||||
require(std::abs(knot.x-.2f)<1e-6f && std::abs(knot.y-.1f)<1e-6f,"pipe path must interpolate its metre-referenced control point");
|
||||
require(std::abs(direction.x*direction.x+direction.y*direction.y+direction.z*direction.z-1)<1e-4f,"pipe path tangent must be normalized");
|
||||
auto atm=desktop::pressure_tint(101325),vac=desktop::pressure_tint(0),peak=desktop::pressure_tint(1000000);
|
||||
require(atm.y>.8f && vac.z>.99f && peak.x>.99f,"pressure palette must show atmosphere green, vacuum blue, spikes red");
|
||||
Ecu fast_actuator;
|
||||
for(int i=0;i<230;++i)fast_actuator.step(1.f/44100,1,5000);
|
||||
require(fast_actuator.throttle_opening()>.99f,"throttle actuator must settle within about 5 ms");
|
||||
for(int i=0;i<230;++i)fast_actuator.step(1.f/44100,0,5000);
|
||||
require(fast_actuator.throttle_opening()<.01f,"throttle actuator must close within about 5 ms");
|
||||
Ecu idle_actuator;
|
||||
for(int i=0;i<441;++i)idle_actuator.step(1.f/44100,0,1000);
|
||||
require(idle_actuator.idle_active() && idle_actuator.throttle_opening()>0,"zero UI pedal must retain ECU idle authority");
|
||||
|
||||
Ecu controller;
|
||||
controller.throttle_time_constant=.08f;controller.throttle_rate=2;
|
||||
constexpr float ecu_dt = 1.0f / 44100.0f;
|
||||
controller.step(ecu_dt, 1.0f, 2000.0f);
|
||||
require(controller.throttle_opening() > 0.0f && controller.throttle_opening() <= 2.0f * ecu_dt,
|
||||
@@ -98,21 +157,6 @@ int main() {
|
||||
"dyno bins must retain their peak power and torque");
|
||||
dyno_curve.reset();
|
||||
require(dyno_curve.bins().empty(), "dyno reset must clear accumulated history");
|
||||
RadiationSource propagation;
|
||||
int first_arrival = -1;
|
||||
for (int i = 0; i < 240; ++i) {
|
||||
const auto frame = propagation.process(i == 0 ? 0.001f : 0.0f);
|
||||
if (first_arrival < 0 && (frame.left != 0.0f || frame.right != 0.0f)) first_arrival = i;
|
||||
}
|
||||
require(first_arrival >= 190 && first_arrival <= 195,
|
||||
"1.5 m propagation must delay sound about 193 samples at 44.1 kHz");
|
||||
|
||||
ThreadLoadTracker thread_load;
|
||||
thread_load.record(1.0, 2.0);
|
||||
require(std::abs(thread_load.load_percent() - 2.5) < 1e-9 &&
|
||||
std::abs(thread_load.last_step_microseconds() - 1000.0) < 1e-9,
|
||||
"thread load tracker must report EMA budget use and last-step time");
|
||||
|
||||
Crankshaft crank;
|
||||
FourStrokeCylinder cylinder;
|
||||
cylinder.initialize(crank);
|
||||
@@ -264,14 +308,11 @@ int main() {
|
||||
require(idle_state.throttle > 0.0f && idle_state.pedal == 0.0f,
|
||||
"idle control must open the butterfly independently of the pedal");
|
||||
|
||||
scenario.toggle_mechanical_sound();
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
const AudioFrame frame = scenario.process();
|
||||
require(std::isfinite(frame.left) && std::isfinite(frame.right),
|
||||
"the integrated mechanical/reverb audio path must remain finite");
|
||||
"the integrated fluid-derived audio path must remain finite");
|
||||
}
|
||||
require(scenario.snapshot().mechanical_sound_enabled,
|
||||
"mechanical-noise toggle must be reflected in the scenario snapshot");
|
||||
|
||||
std::cout << "FluidSim C++ physics tests passed\n";
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user