Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

editoast, front, core: remove gamma type #9887

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ public interface PhysicsRollingStock {
/** The maximum speed the train can reach, in m/s */
double getMaxSpeed();

/** The type of gamma input of the train */
GammaType getGammaType();

/** The resistance to movement at a given speed, in newtons */
double getRollingResistance(double speed);

Expand Down Expand Up @@ -56,14 +53,6 @@ static double getMaxEffort(double speed, TractiveEffortPoint[] tractiveEffortCur
/** The maximum constant deceleration, in m/s^2 */
double getDeceleration();

/** The maximum braking force which can be applied at a given speed, in newtons */
double getMaxBrakingForce(double speed);

/** The maximum acceleration, in m/s^2, which can be applied at a given speed, in m/s */
record TractiveEffortPoint(double speed, double maxEffort) {}

enum GammaType {
CONST,
MAX
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ private IntegrationStep step(double timeStep, double initialLocation, double ini

private IntegrationStep step(double timeStep, double position, double speed) {
double tractionForce = 0;
double brakingForce = 0;
var tractiveEffortCurve = tractiveEffortCurveMap.get(Math.min(Math.max(0, position), path.getLength()));
assert tractiveEffortCurve != null;
double maxTractionForce = PhysicsRollingStock.getMaxEffort(speed, tractiveEffortCurve);
Expand All @@ -75,7 +74,7 @@ private IntegrationStep step(double timeStep, double position, double speed) {

if (action == Action.ACCELERATE) tractionForce = maxTractionForce;

if (action == Action.BRAKE) brakingForce = rollingStock.getMaxBrakingForce(speed);
boolean isBraking = (action == Action.BRAKE);

if (action == Action.MAINTAIN) {
tractionForce = rollingResistance - weightForce;
Expand All @@ -84,7 +83,7 @@ private IntegrationStep step(double timeStep, double position, double speed) {
}

double acceleration = computeAcceleration(
rollingStock, rollingResistance, weightForce, speed, tractionForce, brakingForce, directionSign);
rollingStock, rollingResistance, weightForce, speed, tractionForce, isBraking, directionSign);
return newtonStep(timeStep, speed, acceleration, directionSign);
}

Expand All @@ -108,33 +107,31 @@ public static double computeAcceleration(
double weightForce,
double currentSpeed,
double tractionForce,
double brakingForce,
boolean isBraking,
double directionSign) {

assert brakingForce >= 0.;
assert tractionForce >= 0.;

if (brakingForce > 0 && rollingStock.getGammaType() == PhysicsRollingStock.GammaType.CONST)
if (isBraking) {
return rollingStock.getDeceleration();
}

// the sum of forces that always go the direction opposite to the train's movement
double oppositeForce = rollingResistance + brakingForce;
if (currentSpeed == 0 && directionSign > 0) {
// If we are stopped and if the forces are not enough to compensate the opposite force,
// the rolling resistance and braking force don't apply and the speed stays at 0
// Unless we integrate backwards, then we need the speed to increase
var totalOtherForce = tractionForce + weightForce;
if (Math.abs(totalOtherForce) < oppositeForce) return 0.0;
if (Math.abs(totalOtherForce) < rollingResistance) return 0.0;
}

// as the oppositeForces are reaction forces, they need to be adjusted to be opposed to the
// other forces
if (currentSpeed >= 0.0) {
// if the train is moving forward or still, the opposite forces are negative
return (tractionForce + weightForce - oppositeForce) / rollingStock.getInertia();
return (tractionForce + weightForce - rollingResistance) / rollingStock.getInertia();
} else {
// if the train is moving backwards, the opposite forces are positive
return (tractionForce + weightForce + oppositeForce) / rollingStock.getInertia();
return (tractionForce + weightForce + rollingResistance) / rollingStock.getInertia();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void testAccelerateAndCoast() {
double rollingResistance = testRollingStock.getRollingResistance(speed);
double weightForce = getWeightForce(testRollingStock, testPath, position);
var acceleration = TrainPhysicsIntegrator.computeAcceleration(
testRollingStock, rollingResistance, weightForce, speed, 500000.0, 0, +1);
testRollingStock, rollingResistance, weightForce, speed, 500000.0, false, +1);
var step = newtonStep(TIME_STEP, speed, acceleration, +1);
position += step.positionDelta;
speed = step.endSpeed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@ public class SimpleRollingStock implements PhysicsRollingStock {
public final double B; // in newtons / (m/s)
public final double C; // in newtons / (m/s^2)

/**
* the kind of deceleration input of the train. It can be: a constant value the maximum possible
* deceleration value
*/
public final GammaType gammaType;

/** the deceleration of the train, in m/s^2 */
public final double gamma;
public final double constGamma;

/** the length of the train, in meters. */
public final double length;
Expand Down Expand Up @@ -50,8 +44,7 @@ public SimpleRollingStock(
double b,
double c,
double maxSpeed,
double gamma,
GammaType gammaType) {
double constGamma) {
this.length = length;
this.mass = mass;
this.inertiaCoefficient = inertiaCoefficient;
Expand All @@ -60,8 +53,7 @@ public SimpleRollingStock(
this.B = b;
this.C = c;
this.maxSpeed = maxSpeed;
this.gamma = gamma;
this.gammaType = gammaType;
this.constGamma = constGamma;
}

@Override
Expand All @@ -84,11 +76,6 @@ public double getMaxSpeed() {
return maxSpeed;
}

@Override
public GammaType getGammaType() {
return gammaType;
}

@Override
public double getRollingResistance(double speed) {
speed = Math.abs(speed);
Expand All @@ -105,12 +92,7 @@ public double getRollingResistanceDeriv(double speed) {

@Override
public double getDeceleration() {
return -gamma;
}

@Override
public double getMaxBrakingForce(double speed) {
return gamma * inertia;
return -constGamma;
}

/**
Expand Down Expand Up @@ -157,7 +139,7 @@ public static ImmutableRangeMap<Double, TractiveEffortPoint[]> createEffortCurve
* ======================================================== Constant rolling stocks and curves
* ===========================================================
*/
public static SimpleRollingStock build(double length, double gamma, GammaType gammaType) {
public static SimpleRollingStock build(double length, double constGamma) {
double trainMass = 850000; // in kilos
return new SimpleRollingStock(
length,
Expand All @@ -167,8 +149,7 @@ public static SimpleRollingStock build(double length, double gamma, GammaType ga
((0.008 * trainMass) / 100) * 3.6,
(((0.00012 * trainMass) / 100) * 3.6) * 3.6,
MAX_SPEED,
gamma,
gammaType);
constGamma);
}

public static final ImmutableRangeMap<Double, TractiveEffortPoint[]> LINEAR_EFFORT_CURVE_MAP =
Expand All @@ -177,9 +158,9 @@ public static SimpleRollingStock build(double length, double gamma, GammaType ga
public static final ImmutableRangeMap<Double, TractiveEffortPoint[]> HYPERBOLIC_EFFORT_CURVE_MAP =
createEffortCurveMap(MAX_SPEED, CurveShape.HYPERBOLIC);

public static final SimpleRollingStock SHORT_TRAIN = SimpleRollingStock.build(1, .5, GammaType.CONST);
public static final SimpleRollingStock SHORT_TRAIN = SimpleRollingStock.build(1, .5);

public static final SimpleRollingStock STANDARD_TRAIN = SimpleRollingStock.build(400, .5, GammaType.CONST);
public static final SimpleRollingStock STANDARD_TRAIN = SimpleRollingStock.build(400, .5);

public static final SimpleRollingStock MAX_DEC_TRAIN = SimpleRollingStock.build(400, .95, GammaType.MAX);
public static final SimpleRollingStock MAX_DEC_TRAIN = SimpleRollingStock.build(400, .95);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.squareup.moshi.Json;
import com.squareup.moshi.JsonAdapter;
import com.squareup.moshi.Moshi;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import fr.sncf.osrd.railjson.schema.common.Identified;
import java.util.Map;

Expand Down Expand Up @@ -58,8 +57,9 @@ public class RJSRollingStock implements Identified {
@Json(name = "comfort_acceleration")
public double comfortAcceleration = Double.NaN;

/** The braking deceleration coefficient can be the max or constant (depends on type field). */
public RJSGamma gamma = null;
/** The constant gamma braking coefficient used when NOT circulating under ETCS/ERTMS signaling system in m/s^2 */
@Json(name = "const_gamma")
public double constGamma = Double.NaN;

/**
* Inertia coefficient. The mass alone isn't sufficient to compute accelerations, as the wheels
Expand Down Expand Up @@ -87,17 +87,6 @@ public class RJSRollingStock implements Identified {
@Json(name = "supported_signaling_systems")
public String[] supportedSignalingSystems = new String[0];

public enum GammaType {
CONST,
MAX
}

@SuppressFBWarnings("UWF_NULL_FIELD")
public static final class RJSGamma {
public double value = Double.NaN;
public GammaType type = null;
}

@Override
public String getID() {
return name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ else if (!rjsRollingStock.railjsonVersion.equals(RJSRollingStock.CURRENT_VERSION
if (Double.isNaN(rjsRollingStock.comfortAcceleration))
throw OSRDError.newMissingRollingStockFieldError("comfort_acceleration");

if (rjsRollingStock.gamma == null) throw OSRDError.newMissingRollingStockFieldError("gamma");
if (Double.isNaN(rjsRollingStock.constGamma)) throw OSRDError.newMissingRollingStockFieldError("const_gamma");

if (Double.isNaN(rjsRollingStock.inertiaCoefficient))
throw OSRDError.newMissingRollingStockFieldError("inertia_coefficient");
Expand All @@ -85,12 +85,6 @@ else if (!rjsRollingStock.railjsonVersion.equals(RJSRollingStock.CURRENT_VERSION

var rollingResistance = parseRollingResistance(rjsRollingStock.rollingResistance);

var gammaType =
switch (rjsRollingStock.gamma.type) {
case MAX -> RollingStock.GammaType.MAX;
case CONST -> RollingStock.GammaType.CONST;
};

return new RollingStock(
rjsRollingStock.getID(),
rjsRollingStock.length,
Expand All @@ -103,8 +97,7 @@ else if (!rjsRollingStock.railjsonVersion.equals(RJSRollingStock.CURRENT_VERSION
rjsRollingStock.startUpTime,
rjsRollingStock.startUpAcceleration,
rjsRollingStock.comfortAcceleration,
rjsRollingStock.gamma.value,
gammaType,
rjsRollingStock.constGamma,
rjsRollingStock.loadingGauge,
modes,
rjsRollingStock.effortCurves.defaultMode,
Expand Down
33 changes: 6 additions & 27 deletions core/src/main/java/fr/sncf/osrd/train/RollingStock.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,8 @@ public final class RollingStock implements PhysicsRollingStock {
public final double B; // in newtons / (m/s)
public final double C; // in newtons / (m/s^2)

/**
* the kind of deceleration input of the train. It can be: a constant value the maximum possible
* deceleration value
*/
public final GammaType gammaType;

/** the deceleration of the train, in m/s^2 */
public final double gamma;
public final double constGamma;

/** the length of the train, in meters. */
public final double length;
Expand Down Expand Up @@ -126,16 +120,6 @@ public double getRollingResistanceDeriv(double speed) {
return B + 2 * C * speed;
}

@Override
public double getMaxBrakingForce(double speed) {
return gamma * inertia;
}

@Override
public GammaType getGammaType() {
return gammaType;
}

public record ModeEffortCurves(
boolean isElectric, TractiveEffortPoint[] defaultCurve, ConditionalEffortCurve[] curves) {}

Expand All @@ -160,9 +144,8 @@ protected record CurveAndCondition(TractiveEffortPoint[] curve, InfraConditions
public record CurvesAndConditions(
RangeMap<Double, TractiveEffortPoint[]> curves, RangeMap<Double, InfraConditions> conditions) {}

/** Returns Gamma */
public double getDeceleration() {
return -gamma;
return -constGamma;
}

/**
Expand Down Expand Up @@ -291,8 +274,7 @@ public RollingStock(
double startUpTime,
double startUpAcceleration,
double comfortAcceleration,
double gamma,
GammaType gammaType,
double constGamma,
RJSLoadingGaugeType loadingGaugeType,
Map<String, ModeEffortCurves> modes,
String defaultMode,
Expand All @@ -310,8 +292,7 @@ public RollingStock(
startUpTime,
startUpAcceleration,
comfortAcceleration,
gamma,
gammaType,
constGamma,
loadingGaugeType,
modes,
defaultMode,
Expand All @@ -335,8 +316,7 @@ public RollingStock(
double startUpTime,
double startUpAcceleration,
double comfortAcceleration,
double gamma,
GammaType gammaType,
double constGamma,
RJSLoadingGaugeType loadingGaugeType,
Map<String, ModeEffortCurves> modes,
String defaultMode,
Expand All @@ -354,8 +334,7 @@ public RollingStock(
this.startUpTime = startUpTime;
this.startUpAcceleration = startUpAcceleration;
this.comfortAcceleration = comfortAcceleration;
this.gamma = gamma;
this.gammaType = gammaType;
this.constGamma = constGamma;
this.mass = mass;
this.inertiaCoefficient = inertiaCoefficient;
this.modes = modes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ fun parseRawRollingStock(

val rollingResistance = parseRollingResistance(rawRollingStock.rollingResistance)

val gammaType = rawRollingStock.gamma.gammaType

return RollingStock(
"placeholder_name",
rawRollingStock.length.distance.meters,
Expand All @@ -45,8 +43,7 @@ fun parseRawRollingStock(
rawRollingStock.startupTime.seconds,
rawRollingStock.startupAcceleration,
rawRollingStock.comfortAcceleration,
rawRollingStock.gamma.value,
gammaType,
rawRollingStock.constGamma,
loadingGaugeType,
modes,
rawRollingStock.effortCurves.defaultMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import fr.sncf.osrd.api.api_v2.DirectionalTrackRange
import fr.sncf.osrd.api.api_v2.RangeValues
import fr.sncf.osrd.conflicts.TravelledPath
import fr.sncf.osrd.envelope_sim.PhysicsRollingStock.GammaType
import fr.sncf.osrd.railjson.schema.rollingstock.Comfort
import fr.sncf.osrd.railjson.schema.rollingstock.RJSEffortCurves.RJSModeEffortCurve
import fr.sncf.osrd.railjson.schema.rollingstock.RJSRollingResistance
Expand Down Expand Up @@ -66,7 +65,7 @@ class PhysicsRollingStockModel(
@Json(name = "startup_time") val startupTime: Duration,
@Json(name = "startup_acceleration") val startupAcceleration: Double,
@Json(name = "comfort_acceleration") val comfortAcceleration: Double,
val gamma: Gamma,
@Json(name = "const_gamma") val constGamma: Double,
@Json(name = "inertia_coefficient") val inertiaCoefficient: Double,
val mass: Long, // kg
@Json(name = "rolling_resistance") val rollingResistance: RJSRollingResistance,
Expand All @@ -75,11 +74,6 @@ class PhysicsRollingStockModel(
@Json(name = "raise_pantograph_time") val raisePantographTime: Duration?,
)

class Gamma(
@Json(name = "type") val gammaType: GammaType,
val value: Double,
)

class EffortCurve(
val modes: Map<String, RJSModeEffortCurve>,
@Json(name = "default_mode") val defaultMode: String,
Expand Down
Loading
Loading