Skip to content

Commit 3d1d563

Browse files
committed
core: core format and check
Signed-off-by: Erashin <[email protected]>
1 parent 4131a40 commit 3d1d563

File tree

7 files changed

+161
-112
lines changed

7 files changed

+161
-112
lines changed

core/envelope-sim/src/main/java/fr/sncf/osrd/envelope_sim/EnvelopeSimPath.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,18 @@ public double getMinGrade(double begin, double end) {
113113
var lowestGradient = gradeValues[indexBegin];
114114
for (int i = indexBegin; i < indexEnd; i++) {
115115
var grad = gradeValues[i];
116-
if (grad < lowestGradient)
117-
lowestGradient = grad;
116+
if (grad < lowestGradient) lowestGradient = grad;
118117
}
119118
return lowestGradient;
120119
}
121120

122121
/** For a given position, return the index of the position just before in gradePositions */
123122
public int getIndexBeforePos(double position) {
124-
if (position <= gradePositions[0])
125-
return 0;
126-
if (position >= gradePositions[gradePositions.length - 1])
127-
return gradePositions.length - 1;
123+
if (position <= gradePositions[0]) return 0;
124+
if (position >= gradePositions[gradePositions.length - 1]) return gradePositions.length - 1;
128125
for (int i = 0; i < gradePositions.length; i++) {
129126
var pos = gradePositions[i];
130-
if (pos > position)
131-
return i - 1;
127+
if (pos > position) return i - 1;
132128
}
133129
return gradePositions.length - 1;
134130
}

core/envelope-sim/src/main/java/fr/sncf/osrd/envelope_sim/PhysicsRollingStock.java

+3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ public interface PhysicsRollingStock {
2020
double getRollingResistanceDeriv(double speed);
2121

2222
double getTractionCutOff();
23+
2324
double getTBs1();
25+
2426
double getTBs2();
27+
2528
double getTBe();
2629

2730
/** The emergency braking acceleration which can be applied at a given speed, in m/s^2 */

core/envelope-sim/src/main/java/fr/sncf/osrd/envelope_sim/TrainPhysicsIntegrator.java

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package fr.sncf.osrd.envelope_sim;
22

3-
import com.google.common.collect.RangeMap;
4-
import fr.sncf.osrd.envelope_sim.etcs.BrakingType;
5-
63
import static fr.sncf.osrd.envelope_sim.PhysicsRollingStock.getGradientAcceleration;
74
import static fr.sncf.osrd.envelope_sim.PhysicsRollingStock.getMaxEffort;
85
import static fr.sncf.osrd.envelope_sim.etcs.ConstantsKt.mRotatingMax;
96
import static fr.sncf.osrd.envelope_sim.etcs.ConstantsKt.mRotatingMin;
107

8+
import com.google.common.collect.RangeMap;
9+
import fr.sncf.osrd.envelope_sim.etcs.BrakingType;
10+
1111
/**
1212
* A utility class to help simulate the train, using numerical integration. It's used when
1313
* simulating the train, and it is passed to speed controllers so they can take decisions about what
@@ -39,8 +39,7 @@ private TrainPhysicsIntegrator(
3939
Action action,
4040
double directionSign,
4141
RangeMap<Double, PhysicsRollingStock.TractiveEffortPoint[]> tractiveEffortCurveMap,
42-
BrakingType brakingType
43-
) {
42+
BrakingType brakingType) {
4443
this.rollingStock = rollingStock;
4544
this.path = path;
4645
this.action = action;
@@ -86,8 +85,7 @@ private IntegrationStep step(double timeStep, double initialLocation, double ini
8685
}
8786

8887
private IntegrationStep step(double timeStep, double position, double speed) {
89-
if (action == Action.BRAKE)
90-
return newtonStep(timeStep, speed, getDeceleration(speed, position), directionSign);
88+
if (action == Action.BRAKE) return newtonStep(timeStep, speed, getDeceleration(speed, position), directionSign);
9189

9290
double tractionForce = 0;
9391
var tractiveEffortCurve = tractiveEffortCurveMap.get(Math.min(Math.max(0, position), path.getLength()));
@@ -104,24 +102,24 @@ private IntegrationStep step(double timeStep, double position, double speed) {
104102
}
105103

106104
if (action == Action.ACCELERATE) tractionForce = maxTractionForce;
107-
double acceleration = computeAcceleration(
108-
rollingStock, rollingResistance, weightForce, speed, tractionForce, directionSign);
105+
double acceleration =
106+
computeAcceleration(rollingStock, rollingResistance, weightForce, speed, tractionForce, directionSign);
109107
return newtonStep(timeStep, speed, acceleration, directionSign);
110108
}
111109

112110
private double getDeceleration(double speed, double position) {
113-
assert(action == Action.BRAKE);
114-
if (brakingType == BrakingType.CONSTANT)
115-
return rollingStock.getDeceleration();
116-
//TODO: check if we want min or max grade
111+
assert (action == Action.BRAKE);
112+
if (brakingType == BrakingType.CONSTANT) return rollingStock.getDeceleration();
113+
// TODO: check if we want min or max grade
117114
var grade = getMinGrade(rollingStock, path, position);
118115
var mRotating = grade >= 0 ? mRotatingMax : mRotatingMin;
119116
var gradientAcceleration = getGradientAcceleration(grade, mRotating);
120117
return switch (brakingType) {
121118
case ETCS_EBD -> -rollingStock.getSafeBrakingAcceleration(speed) + gradientAcceleration;
122119
case ETCS_SBD -> -rollingStock.getServiceBrakingAcceleration(speed) + gradientAcceleration;
123-
case ETCS_GUI -> -rollingStock.getNormalServiceBrakingAcceleration(speed) + gradientAcceleration
124-
+ rollingStock.getGradientAccelerationCorrection(gradientAcceleration, speed);
120+
case ETCS_GUI -> -rollingStock.getNormalServiceBrakingAcceleration(speed)
121+
+ gradientAcceleration
122+
+ rollingStock.getGradientAccelerationCorrection(gradientAcceleration, speed);
125123
default -> throw new UnsupportedOperationException("Braking type not supported: " + brakingType);
126124
};
127125
}

core/envelope-sim/src/main/java/fr/sncf/osrd/envelope_sim/overlays/EnvelopeDeceleration.java

+11-13
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99
public class EnvelopeDeceleration {
1010
/** Generate a deceleration curve overlay */
1111
public static void decelerate(
12-
EnvelopeSimContext context,
13-
double startPosition,
14-
double startSpeed,
15-
InteractiveEnvelopePartConsumer consumer,
16-
double direction,
17-
BrakingType brakingType
18-
) {
12+
EnvelopeSimContext context,
13+
double startPosition,
14+
double startSpeed,
15+
InteractiveEnvelopePartConsumer consumer,
16+
double direction,
17+
BrakingType brakingType) {
1918
if (!consumer.initEnvelopePart(startPosition, startSpeed, direction)) return;
2019
double position = startPosition;
2120
double speed = startSpeed;
@@ -28,12 +27,11 @@ public static void decelerate(
2827
}
2928

3029
public static void decelerate(
31-
EnvelopeSimContext context,
32-
double startPosition,
33-
double startSpeed,
34-
InteractiveEnvelopePartConsumer consumer,
35-
double direction
36-
) {
30+
EnvelopeSimContext context,
31+
double startPosition,
32+
double startSpeed,
33+
InteractiveEnvelopePartConsumer consumer,
34+
double direction) {
3735
decelerate(context, startPosition, startSpeed, consumer, direction, BrakingType.CONSTANT);
3836
}
3937
}

0 commit comments

Comments
 (0)