mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 15:17:08 +01:00
309926bb05
The air of physics::Vehicle becomes components of their own, with the fields
named in English (physics/components/airsupply.h):
air (AirSupply) the compressor and the main reservoir:
compressor (AirCompressor) MinCompressor, MaxCompressor and those of each
cab, CabDependentCompressor, CompressorSpeed,
CompressorPower, CompressorStartDelay,
CompressorTankValve, CompressorStart, the
CompressorList programmer and its switch, and
the state: CompressorFlag running,
CompressorAllow(Local) allow(Local),
CompressorGovernorLock, CompressorPowerTime
VeselVolume mainReservoirVolume
Compressor mainReservoirPressure
CompressedVolume compressedVolume
AirLeakRate leakRate
brakePipe, mainPipe the two pipes along the train, of one type,
(TrainPipe) TrainPipe: reservoir, pressure, couplersPending
(Pipe, PipePress, PipeCouplersPending and Pipe2,
ScndPipePress, ScndPipeCouplersPending before)
CompressorPower, a number 0 to 5, is the enum CompressorSupply (mainCircuit,
converterManual, converter, engine, frontUnitConverter, rearUnitConverter),
read from the same words of the .fiz. The CompressorList table is a
std::array of the same ints.
The exchange of air through the hoses (pneumatics.cpp) takes the pipe as one
TrainPipe of the vehicle instead of three member pointers.
No change in behaviour: 1149/1149 tests, golden traces exact against staging
62f7a29b.
176 lines
6.5 KiB
C++
176 lines
6.5 KiB
C++
#include "stdafx.h"
|
|
#include "doctest.h"
|
|
|
|
#include "physics/vehicle.h"
|
|
#include "physics/brakes.h"
|
|
#include "consist.h"
|
|
#include "vehicle.h"
|
|
|
|
// the air exchange through the main reservoir hoses between the vehicles of a train (physics::Vehicle::UpdatePipeCouplers()).
|
|
// taken in one explicit step of 0.01 s, a hose carried about 1.5 times the air which evens out the pipes on its ends,
|
|
// and the vehicles' own main reservoirs fed the pipe in the same step: the pipes of the middle vehicles of a multiple
|
|
// unit, or of locomotives in multiple traction, kept jumping 0.8 bar to and fro between the steps, with the main
|
|
// reservoirs all at the same pressure
|
|
|
|
namespace {
|
|
|
|
using test::definition;
|
|
|
|
// an EN57 of Units units, driven from the front cab
|
|
void en57(test::consist &Train, int const Units) {
|
|
for (int i = 0; i < Units; ++i) {
|
|
Train.add(definition::fiz("en57_v1/5bgb"), i == 0 ? 1 : 0);
|
|
Train.add(definition::fiz("en57_v1/6ba_840"));
|
|
Train.add(definition::fiz("en57_v1/5bgb"));
|
|
}
|
|
}
|
|
|
|
// Count SM40 shunters in multiple traction, driven from the first
|
|
void sm40(test::consist &Train, int const Count) {
|
|
for (int i = 0; i < Count; ++i) {
|
|
Train.add(definition::fiz("sm40_v1/sm40"), i == 0 ? 1 : 0);
|
|
}
|
|
}
|
|
|
|
// a locomotive and Cars passenger cars, whose main reservoir pipe only the locomotive feeds
|
|
void passenger_train(test::consist &Train, int const Cars) {
|
|
Train.add(definition::fiz("ep09_v2/104e"));
|
|
for (int i = 0; i < Cars; ++i) {
|
|
Train.add(definition::fiz("11xa_v2/93a"));
|
|
}
|
|
Train[0].hold_brake_pipe(5.0);
|
|
}
|
|
|
|
// the largest difference [bar] of a main reservoir pipe of the train from Pressure, over Seconds of steps of Dt
|
|
double off_pressure(test::consist &Train, double const Pressure, double const Seconds, double const Dt = 0.01) {
|
|
auto off{0.0};
|
|
auto const steps{static_cast<int>(std::lround(Seconds / Dt))};
|
|
for (int step = 0; step < steps; ++step) {
|
|
Train.step({}, Dt);
|
|
for (std::size_t i = 0; i < Train.size(); ++i) {
|
|
off = std::max(off, std::abs(Train[i]->mainPipe.pressure - Pressure));
|
|
}
|
|
}
|
|
return off;
|
|
}
|
|
|
|
struct evening_out {
|
|
double time{60.0}; // [s] until the main reservoirs of the train's ends are within 0.05 bar
|
|
double zigzag{0.0}; // [bar] the largest step of a main reservoir pipe back and forth, between steps the other way
|
|
};
|
|
|
|
// the train standing, the main reservoir of its first vehicle Pressure [bar], those of the rest 1 bar below, stepping
|
|
// by Dt until they even out through the main reservoir pipe
|
|
template <typename Builder>
|
|
evening_out even_out(Builder Train, int const Count, double const Pressure, double const Dt) {
|
|
test::consist train;
|
|
Train(train, Count);
|
|
for (std::size_t i = 0; i < train.size(); ++i) {
|
|
auto &physics{train[i].physics()};
|
|
REQUIRE(physics.air.mainReservoirVolume > 0.0);
|
|
auto const pressure{i == 0 ? Pressure : Pressure - 1.0};
|
|
physics.air.compressedVolume = pressure * physics.air.mainReservoirVolume;
|
|
physics.air.mainReservoirPressure = pressure;
|
|
physics.mainPipe.reservoir->CreatePress(pressure);
|
|
physics.mainPipe.reservoir->Act();
|
|
physics.mainPipe.pressure = pressure;
|
|
}
|
|
evening_out result;
|
|
auto const &first{train[0].physics()};
|
|
auto const &last{train[train.size() - 1].physics()};
|
|
std::vector<double> previous(train.size());
|
|
std::vector<double> change(train.size());
|
|
for (std::size_t i = 0; i < train.size(); ++i) {
|
|
previous[i] = train[i]->mainPipe.pressure;
|
|
}
|
|
auto time{0.0};
|
|
while (time < 60.0) {
|
|
train.step({}, Dt);
|
|
time += Dt;
|
|
for (std::size_t i = 0; i < train.size(); ++i) {
|
|
auto const step{train[i]->mainPipe.pressure - previous[i]};
|
|
if (step * change[i] < 0.0) {
|
|
// turned back
|
|
result.zigzag = std::max(result.zigzag, std::min(std::abs(step), std::abs(change[i])));
|
|
}
|
|
change[i] = step;
|
|
previous[i] = train[i]->mainPipe.pressure;
|
|
}
|
|
if (std::abs(first.air.mainReservoirPressure - last.air.mainReservoirPressure) < 0.05) {
|
|
result.time = time;
|
|
break;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// the time [s] until the main reservoir pipe of the train's last vehicle, emptied with all the others which have no
|
|
// main reservoir of their own, is within 0.2 bar of the first vehicle's, which holds its main reservoir at Pressure [bar]
|
|
template <typename Builder>
|
|
double charging_time(Builder Train, int const Count, double const Pressure, double const Dt) {
|
|
test::consist train;
|
|
Train(train, Count);
|
|
train[0].hold_main_reservoir(Pressure);
|
|
for (std::size_t i = 1; i < train.size(); ++i) {
|
|
auto &physics{train[i].physics()};
|
|
REQUIRE(physics.air.mainReservoirVolume == 0.0);
|
|
physics.mainPipe.reservoir->CreatePress(0.0);
|
|
physics.mainPipe.reservoir->Act();
|
|
physics.mainPipe.pressure = 0.0;
|
|
}
|
|
auto const &first{train[0].physics()};
|
|
auto const &last{train[train.size() - 1].physics()};
|
|
auto time{0.0};
|
|
while ((last.mainPipe.pressure < 1.0 || std::abs(last.mainPipe.pressure - first.mainPipe.pressure) > 0.2) && time < 60.0) {
|
|
train.step({}, Dt);
|
|
time += Dt;
|
|
}
|
|
return time;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("main reservoir pipe: the pipes of a three unit EN57 stand at the pressure of its main reservoirs") {
|
|
test::consist train;
|
|
en57(train, 3);
|
|
for (std::size_t i = 0; i < train.size(); ++i) {
|
|
train[i].hold_main_reservoir(7.0);
|
|
}
|
|
// the pipes filling up from the reservoirs
|
|
train.run(60.0);
|
|
CHECK(off_pressure(train, 7.0, 1.0) < 0.01);
|
|
// the exchange through the hoses of the 21 m cars takes 2 sub-steps of a step of 0.01 s
|
|
CHECK(train[1]->ScndPipeCouplersSubsteps(0.01) == 2);
|
|
}
|
|
|
|
TEST_CASE("main reservoir pipe: the pipes of locomotives in multiple traction stand at the pressure of their main reservoirs") {
|
|
test::consist train;
|
|
sm40(train, 3);
|
|
for (std::size_t i = 0; i < train.size(); ++i) {
|
|
train[i].hold_main_reservoir(7.5);
|
|
}
|
|
train.run(60.0);
|
|
CHECK(off_pressure(train, 7.5, 1.0) < 0.01);
|
|
}
|
|
|
|
TEST_CASE("main reservoir pipe: the main reservoirs of a multiple unit even out as with a short step") {
|
|
auto const converged{even_out(en57, 3, 7.0, 0.001)};
|
|
auto const usual{even_out(en57, 3, 7.0, 0.01)};
|
|
CAPTURE(converged.time);
|
|
CAPTURE(usual.time);
|
|
CAPTURE(usual.zigzag);
|
|
CHECK(converged.time < 60.0);
|
|
CHECK(usual.time == doctest::Approx(converged.time).epsilon(0.1));
|
|
// the pipes go along with the reservoirs, without jumping to and fro between the steps
|
|
CHECK(usual.zigzag < 0.05);
|
|
}
|
|
|
|
TEST_CASE("main reservoir pipe: a passenger train, whose exchange was stable in one step, fills its pipe as with a short step") {
|
|
auto const converged{charging_time(passenger_train, 10, 9.0, 0.001)};
|
|
auto const usual{charging_time(passenger_train, 10, 9.0, 0.01)};
|
|
CAPTURE(converged);
|
|
CAPTURE(usual);
|
|
CHECK(converged < 60.0);
|
|
CHECK(usual == doctest::Approx(converged).epsilon(0.05));
|
|
}
|