18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 19:57:06 +01:00
Files
maszyna/tests/unit/test_compressor.cpp
T
Hirek 89258eb72c refactor(physics): the low voltage, the train heating and the electrodynamic brake as components
The rest of the electrics of physics::Vehicle beside the traction motors
becomes components, with English names:

  lowVoltage (LowVoltageSupply,   Battery batteryOn, BatteryVoltage,
  physics/components/lowvoltage.h) NominalBatteryVoltage, BatteryStart,
                                  Power110vIsAvailable / Power24vIsAvailable /
                                  Power24vVoltage power110vAvailable /
                                  power24vAvailable / power24vVoltage, the
                                  battery button of the cab: batteryButtonFired,
                                  batteryButtonImpulse, batteryButtonHeld,
                                  batteryButtonHoldTime
  trainHeating (TrainHeating)     Heating on, HeatingAllow allow,
                                  HeatingSwitchImpulse switchImpulse,
                                  HeatingPower power, EngineHeatingRPM engineRpm
  brakes.electrodynamic           the DynamicBrake* fields: type, ammeters,
  (ElectrodynamicBrake,           controllerPositions, controllerPosition,
  physics/components/braking.h)   resistance(1, 2), on, emuWorking;
                                  SplitEDPneumaticBrake splitFromPneumatic;
                                  the fans of the braking resistor (BRVentilators,
                                  BRVto, BRVtimer, Imaxrpc): resistorFansRunning,
                                  resistorFansSustain, resistorFansTimer,
                                  resistorPassiveMaxCurrent

The diesel-electric dynamic brake (DEDynamicBrake) and the currents of the
traction circuit (Im, Itot, EngineVoltage ...) stay for the traction stage.

No string literal changed (checked over all the changed files).

No change in behaviour: 1149/1149 tests, golden traces exact against staging
62f7a29b.
2026-11-29 03:15:56 +01:00

206 lines
7.7 KiB
C++

#include "stdafx.h"
#include "doctest.h"
#include "vehicle.h"
using test::definition;
using test::vehicle;
// the compressor waiting a while after getting its power before it starts (CompressorStartDelay,
// MaSzyna-EU07/maszyna#67): in a diesel it starts some time after the engine, rather than with it
namespace {
double const step{0.01};
// a compressor which starts on its own, fed from the main circuit unless given another Power, its pressure
// switch between MinCP and MaxCP, and an empty main reservoir for it to fill
vehicle compressor_vehicle(double const Delay, std::string const &Power = "Main", double const MinCP = 6.5) {
auto definition{definition::load("wagon")};
definition.set("Brake", "Vv", 1.0).set("Brake", "MinCP", MinCP).set("Brake", "MaxCP", 8.0);
definition.set("Brake", "CompressorSpeed", 0.01);
if (false == Power.empty()) {
definition.set("Brake", "CompressorPower", Power);
}
definition.set("Cntrl", "CompressorStart", "Automatic");
if (Delay > 0.0) {
definition.set("Brake", "CompressorStartDelay", Delay);
}
vehicle vehicle{definition};
vehicle->air.compressedVolume = 0.0;
vehicle->LastSwitchingTime = 10.0; // nothing was switched lately
return vehicle;
}
// runs the compressor for Seconds, the main circuit as it is, the time since the last switching going on as in
// ComputeTotalForce()
void run_compressor(vehicle &Vehicle, double const Seconds) {
for (auto i{std::lround(Seconds / step)}; i > 0; --i) {
Vehicle->LastSwitchingTime += step;
Vehicle->CompressorCheck(step);
}
}
} // namespace
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
vehicle->lineBreaker.closed = true;
run_compressor(vehicle, step);
CHECK(vehicle->air.compressor.running);
}
TEST_CASE("compressor: the compressor starts the delay after getting its power") {
auto vehicle{compressor_vehicle(5.0)};
vehicle->lineBreaker.closed = true;
run_compressor(vehicle, 4.9);
CHECK_FALSE(vehicle->air.compressor.running);
CHECK(vehicle->air.mainReservoirPressure == doctest::Approx(0.0));
run_compressor(vehicle, 0.2);
CHECK(vehicle->air.compressor.running);
run_compressor(vehicle, 10.0);
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.closed = true;
run_compressor(vehicle, 10.0);
REQUIRE(vehicle->air.compressor.running);
vehicle->lineBreaker.closed = false; // the engine stopped
run_compressor(vehicle, 1.0);
CHECK_FALSE(vehicle->air.compressor.running);
vehicle->lineBreaker.closed = true; // and started again
run_compressor(vehicle, 4.9);
CHECK_FALSE(vehicle->air.compressor.running);
run_compressor(vehicle, 0.2);
CHECK(vehicle->air.compressor.running);
}
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.closed = true; // which alone doesn't feed it
run_compressor(vehicle, 10.0);
REQUIRE_FALSE(vehicle->air.compressor.running);
vehicle->lowVoltage.power110vAvailable = true;
run_compressor(vehicle, 4.9);
CHECK_FALSE(vehicle->air.compressor.running);
run_compressor(vehicle, 0.2);
CHECK(vehicle->air.compressor.running);
}
TEST_CASE("compressor: the pressure switch stops the compressor above the cut-out pressure") {
auto vehicle{compressor_vehicle(0.0)};
vehicle->lineBreaker.closed = true;
vehicle->air.compressedVolume = 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);
}
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.closed = true;
vehicle->air.compressedVolume = 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
}
TEST_CASE("compressor: an engine stopped before the delay passed counts the whole delay again") {
auto vehicle{compressor_vehicle(30.0)};
vehicle->lineBreaker.closed = true; // engine started
run_compressor(vehicle, 20.0);
REQUIRE_FALSE(vehicle->air.compressor.running);
vehicle->lineBreaker.closed = false; // engine stopped, 10 s short of the delay
run_compressor(vehicle, 1.0);
vehicle->lineBreaker.closed = true;
run_compressor(vehicle, 15.0); // 36 s since the first start, but only 15 s since this one
CHECK_FALSE(vehicle->air.compressor.running);
run_compressor(vehicle, 15.1);
CHECK(vehicle->air.compressor.running);
}
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->lineBreaker.closed = true;
run_compressor(vehicle, 29.9);
CHECK_FALSE(vehicle->air.compressor.running);
run_compressor(vehicle, 0.2);
CHECK(vehicle->air.compressor.running);
}
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;
}};
CHECK(delay("Brake") == doctest::Approx(30.0));
CHECK(delay("Cntrl") == doctest::Approx(0.0)); // the key isn't taken from the control section
}
namespace {
// 401Da: the compressor runs from the 110 V of the auxiliary generator driven by the engine, here the converter
// started with the main circuit, which gets up to voltage the converter start delay after the engine start
definition generator_vehicle(double const ConverterDelay, double const CompressorDelay) {
return definition::load("cab_vehicle")
.set("Param", "PWR", 370)
.set("Light", "Light", "Generator")
.set("Light", "LMaxVoltage", 110)
.set("Brake", "Vv", 0.6)
.set("Brake", "MinCP", 6.5)
.set("Brake", "MaxCP", 8.0)
.set("Brake", "CompressorSpeed", 0.003)
.set("Brake", "CompressorPower", "Converter")
.set("Brake", "CompressorStartDelay", CompressorDelay)
.set("Cntrl", "CompressorStart", "Automatic")
.set("Cntrl", "ConverterStart", "Automatic")
.set("Cntrl", "ConverterStartDelay", ConverterDelay);
}
} // namespace
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->converter.startDelay == doctest::Approx(30.0));
loco.run(1.0); // engine off
CHECK_FALSE(loco->lowVoltage.power110vAvailable);
loco->lineBreaker.closed = true; // engine started
loco.run(25.0);
CHECK_FALSE(loco->lowVoltage.power110vAvailable);
CHECK_FALSE(loco->air.compressor.running);
loco.run(10.0);
CHECK(loco->lowVoltage.power110vAvailable);
CHECK(loco->air.compressor.running);
}
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));
loco.run(1.0); // engine off
loco->lineBreaker.closed = true; // engine started
loco.run(25.0);
REQUIRE(loco->lowVoltage.power110vAvailable); // the converter is up
CHECK_FALSE(loco->air.compressor.running); // but the compressor waits for its own delay as well
loco.run(10.0);
CHECK(loco->air.compressor.running);
}