18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 03:52:52 +01:00

refactor(physics): the compressed air supply and the pipes keep their state to themselves

The compressor, the main reservoir and the pipes along the train
(physics/components/airsupply.h) become classes, as the parts of the main
circuit: the definition in `config`, the state behind queries and operations.

The step of the compressor (the programmer of a unit, its supply and its start
delay, the governor and its lock, the venting over the top pressure) moves into
AirCompressor::Update(), with what it needs from the vehicle as plain values
(CompressorInputs); the vehicle follows the step up as before (the switching
delay, the counter of the debug panel, the sound of the relay). The leaks and
the pressure of the main reservoir move into AirSupply, and the reservoir is
filled and drawn through it.

The fault of the compressor the scenery can set no longer adds 100000001 to its
pressures from TDynamicObject::Damage(): AirCompressor::SetFault() does the same
arithmetic, so a fault behaves exactly as it did.

No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
This commit is contained in:
2026-11-29 10:14:37 +01:00
parent 160ffe2147
commit bc2af26dd5
60 changed files with 731 additions and 603 deletions
+34 -34
View File
@@ -26,7 +26,7 @@ vehicle compressor_vehicle(double const Delay, std::string const &Power = "Main"
definition.set("Brake", "CompressorStartDelay", Delay);
}
vehicle vehicle{definition};
vehicle->air.compressedVolume = 0.0;
vehicle->air.Fill(0.0);
vehicle->LastSwitchingTime = 10.0; // nothing was switched lately
return vehicle;
}
@@ -45,11 +45,11 @@ void run_compressor(vehicle &Vehicle, double const Seconds) {
TEST_CASE("compressor: without a start delay the compressor starts with its power") {
auto vehicle{compressor_vehicle(0.0)};
run_compressor(vehicle, 1.0);
REQUIRE_FALSE(vehicle->air.compressor.running); // no power, no compressor
REQUIRE_FALSE(vehicle->air.compressor.IsRunning()); // no power, no compressor
vehicle->lineBreaker.Close();
run_compressor(vehicle, step);
CHECK(vehicle->air.compressor.running);
CHECK(vehicle->air.compressor.IsRunning());
}
TEST_CASE("compressor: the compressor starts the delay after getting its power") {
@@ -57,94 +57,94 @@ TEST_CASE("compressor: the compressor starts the delay after getting its power")
vehicle->lineBreaker.Close();
run_compressor(vehicle, 4.9);
CHECK_FALSE(vehicle->air.compressor.running);
CHECK(vehicle->air.mainReservoirPressure == doctest::Approx(0.0));
CHECK_FALSE(vehicle->air.compressor.IsRunning());
CHECK(vehicle->air.MainReservoirPressure() == doctest::Approx(0.0));
run_compressor(vehicle, 0.2);
CHECK(vehicle->air.compressor.running);
CHECK(vehicle->air.compressor.IsRunning());
run_compressor(vehicle, 10.0);
CHECK(vehicle->air.mainReservoirPressure > 0.0); // and fills the reservoir
CHECK(vehicle->air.MainReservoirPressure() > 0.0); // and fills the reservoir
}
TEST_CASE("compressor: the delay starts over once the power is gone") {
auto vehicle{compressor_vehicle(5.0)};
vehicle->lineBreaker.Close();
run_compressor(vehicle, 10.0);
REQUIRE(vehicle->air.compressor.running);
REQUIRE(vehicle->air.compressor.IsRunning());
vehicle->lineBreaker.Open(); // the engine stopped
run_compressor(vehicle, 1.0);
CHECK_FALSE(vehicle->air.compressor.running);
CHECK_FALSE(vehicle->air.compressor.IsRunning());
vehicle->lineBreaker.Close(); // and started again
run_compressor(vehicle, 4.9);
CHECK_FALSE(vehicle->air.compressor.running);
CHECK_FALSE(vehicle->air.compressor.IsRunning());
run_compressor(vehicle, 0.2);
CHECK(vehicle->air.compressor.running);
CHECK(vehicle->air.compressor.IsRunning());
}
TEST_CASE("compressor: a compressor fed from the low voltage waits from the low voltage coming on") {
auto vehicle{compressor_vehicle(5.0, "")}; // the default supply: the converter, the 110 V
vehicle->lineBreaker.Close(); // which alone doesn't feed it
run_compressor(vehicle, 10.0);
REQUIRE_FALSE(vehicle->air.compressor.running);
REQUIRE_FALSE(vehicle->air.compressor.IsRunning());
vehicle->lowVoltage.Set110vAvailableForTest(true);
run_compressor(vehicle, 4.9);
CHECK_FALSE(vehicle->air.compressor.running);
CHECK_FALSE(vehicle->air.compressor.IsRunning());
run_compressor(vehicle, 0.2);
CHECK(vehicle->air.compressor.running);
CHECK(vehicle->air.compressor.IsRunning());
}
TEST_CASE("compressor: the pressure switch stops the compressor above the cut-out pressure") {
auto vehicle{compressor_vehicle(0.0)};
vehicle->lineBreaker.Close();
vehicle->air.compressedVolume = 8.5; // over MaxCP, in the reservoir of 1 m3
vehicle->air.Fill(8.5); // over MaxCP, in the reservoir of 1 m3
run_compressor(vehicle, step);
CHECK(vehicle->air.compressor.governorLock);
CHECK_FALSE(vehicle->air.compressor.running);
CHECK(vehicle->air.compressor.IsGovernorLocked());
CHECK_FALSE(vehicle->air.compressor.IsRunning());
}
TEST_CASE("compressor: without a pressure switch the air over the cut-out pressure is vented") {
auto vehicle{compressor_vehicle(0.0, "Main", 8.0)}; // MinCP the same as MaxCP: no pressure switch
vehicle->lineBreaker.Close();
vehicle->air.compressedVolume = 8.5;
vehicle->air.Fill(8.5);
run_compressor(vehicle, step);
REQUIRE(vehicle->air.compressor.running); // nothing stops it
CHECK(vehicle->air.compressedVolume < 8.5 * 0.81); // a fifth of the air let out
REQUIRE(vehicle->air.compressor.IsRunning()); // nothing stops it
CHECK(vehicle->air.CompressedVolume() < 8.5 * 0.81); // a fifth of the air let out
}
TEST_CASE("compressor: an engine stopped before the delay passed counts the whole delay again") {
auto vehicle{compressor_vehicle(30.0)};
vehicle->lineBreaker.Close(); // engine started
run_compressor(vehicle, 20.0);
REQUIRE_FALSE(vehicle->air.compressor.running);
REQUIRE_FALSE(vehicle->air.compressor.IsRunning());
vehicle->lineBreaker.Open(); // engine stopped, 10 s short of the delay
run_compressor(vehicle, 1.0);
vehicle->lineBreaker.Close();
run_compressor(vehicle, 15.0); // 36 s since the first start, but only 15 s since this one
CHECK_FALSE(vehicle->air.compressor.running);
CHECK_FALSE(vehicle->air.compressor.IsRunning());
run_compressor(vehicle, 15.1);
CHECK(vehicle->air.compressor.running);
CHECK(vehicle->air.compressor.IsRunning());
}
TEST_CASE("compressor: the start delay holds back a compressor switched on by hand too") {
auto vehicle{compressor_vehicle(30.0)};
vehicle->air.compressor.start = start_t::manual;
vehicle->air.compressor.allow = true; // switch in the cabinet on before the engine start
vehicle->air.compressor.config.start = start_t::manual;
vehicle->air.compressor.Allow(true); // switch in the cabinet on before the engine start
vehicle->lineBreaker.Close();
run_compressor(vehicle, 29.9);
CHECK_FALSE(vehicle->air.compressor.running);
CHECK_FALSE(vehicle->air.compressor.IsRunning());
run_compressor(vehicle, 0.2);
CHECK(vehicle->air.compressor.running);
CHECK(vehicle->air.compressor.IsRunning());
}
TEST_CASE("compressor: the start delay is read from the brake section") {
auto const delay{[](std::string const &Section) {
return vehicle{definition::load("wagon").set(Section, "CompressorStartDelay", 30)}->air.compressor.startDelay;
return vehicle{definition::load("wagon").set(Section, "CompressorStartDelay", 30)}->air.compressor.config.startDelay;
}};
CHECK(delay("Brake") == doctest::Approx(30.0));
CHECK(delay("Cntrl") == doctest::Approx(0.0)); // the key isn't taken from the control section
@@ -174,7 +174,7 @@ definition generator_vehicle(double const ConverterDelay, double const Compresso
TEST_CASE("compressor: fed from the converter it waits for the converter start delay") {
vehicle loco{generator_vehicle(30.0, 0.0)};
REQUIRE(loco->air.compressor.supply == physics::CompressorSupply::converter);
REQUIRE(loco->air.compressor.config.supply == physics::CompressorSupply::converter);
REQUIRE(loco->converter.config.startDelay == doctest::Approx(30.0));
loco.run(1.0); // engine off
@@ -183,23 +183,23 @@ TEST_CASE("compressor: fed from the converter it waits for the converter start d
loco->lineBreaker.Close(); // engine started
loco.run(25.0);
CHECK_FALSE(loco->lowVoltage.Is110vAvailable());
CHECK_FALSE(loco->air.compressor.running);
CHECK_FALSE(loco->air.compressor.IsRunning());
loco.run(10.0);
CHECK(loco->lowVoltage.Is110vAvailable());
CHECK(loco->air.compressor.running);
CHECK(loco->air.compressor.IsRunning());
}
TEST_CASE("compressor: fed from the converter the start delay counts from the converter voltage") {
vehicle loco{generator_vehicle(20.0, 10.0)};
REQUIRE(loco->air.compressor.startDelay == doctest::Approx(10.0));
REQUIRE(loco->air.compressor.config.startDelay == doctest::Approx(10.0));
loco.run(1.0); // engine off
loco->lineBreaker.Close(); // engine started
loco.run(25.0);
REQUIRE(loco->lowVoltage.Is110vAvailable()); // the converter is up
CHECK_FALSE(loco->air.compressor.running); // but the compressor waits for its own delay as well
CHECK_FALSE(loco->air.compressor.IsRunning()); // but the compressor waits for its own delay as well
loco.run(10.0);
CHECK(loco->air.compressor.running);
CHECK(loco->air.compressor.IsRunning());
}