Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 1dafac78 authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

SI Class comparison: tolerance has to have same SI unit

parent 73850979
No related branches found
No related tags found
No related merge requests found
...@@ -104,7 +104,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -104,7 +104,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
IResponse ITnOutPort.Request(Second absTime, Second dt, NewtonMeter torque, PerSecond angularVelocity, bool dryRun) IResponse ITnOutPort.Request(Second absTime, Second dt, NewtonMeter torque, PerSecond angularVelocity, bool dryRun)
{ {
Log.Debug("Engine Power Request: torque: {0}, angularVelocity: {1}, power: {2}", torque, angularVelocity, torque * angularVelocity); Log.Debug("Engine Power Request: torque: {0}, angularVelocity: {1}, power: {2}", torque, angularVelocity,
torque * angularVelocity);
return DoHandleRequest(absTime, dt, torque, angularVelocity, dryRun); return DoHandleRequest(absTime, dt, torque, angularVelocity, dryRun);
} }
...@@ -550,7 +551,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -550,7 +551,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var response = (ResponseDryRun)RequestPort.Request(absTime, dt, torque, nextAngularSpeed, true); var response = (ResponseDryRun)RequestPort.Request(absTime, dt, torque, nextAngularSpeed, true);
delta = response.DeltaDragLoad; delta = response.DeltaDragLoad;
debug.Add(new { engineSpeed = nextAngularSpeed, searchInterval, delta }); debug.Add(new { engineSpeed = nextAngularSpeed, searchInterval, delta });
if (delta.IsEqual(0, Constants.SimulationSettings.EnginePowerSearchTolerance)) { if (delta.IsEqual(0.SI<Watt>(), Constants.SimulationSettings.EnginePowerSearchTolerance)) {
Log.Debug("found operating point in {0} iterations. engine speed: {1}, delta: {2}", retryCount, nextAngularSpeed, Log.Debug("found operating point in {0} iterations. engine speed: {1}, delta: {2}", retryCount, nextAngularSpeed,
delta); delta);
return RequestPort.Request(absTime, dt, torque, nextAngularSpeed); return RequestPort.Request(absTime, dt, torque, nextAngularSpeed);
......
...@@ -55,7 +55,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -55,7 +55,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
nextAction = GetNextDrivingAction(currentDistance); nextAction = GetNextDrivingAction(currentDistance);
if (nextAction != null) { if (nextAction != null) {
if (currentDistance.IsEqual(nextAction.ActionDistance, if (currentDistance.IsEqual(nextAction.ActionDistance,
Constants.SimulationSettings.DriverActionDistanceTolerance.Value())) { Constants.SimulationSettings.DriverActionDistanceTolerance)) {
CurrentDrivingMode = DrivingMode.DrivingModeBrake; CurrentDrivingMode = DrivingMode.DrivingModeBrake;
DrivingModes[CurrentDrivingMode].ResetMode(); DrivingModes[CurrentDrivingMode].ResetMode();
Log.Debug("Switching to DrivingMode BRAKE"); Log.Debug("Switching to DrivingMode BRAKE");
...@@ -111,7 +111,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -111,7 +111,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
// if the distance at the end of the simulation interval is smaller than the new ActionDistance // if the distance at the end of the simulation interval is smaller than the new ActionDistance
// we are safe - go ahead... // we are safe - go ahead...
if ((Driver.DataBus.Distance + ds).IsSmallerOrEqual(nextAction.TriggerDistance - coastingDistance, if ((Driver.DataBus.Distance + ds).IsSmallerOrEqual(nextAction.TriggerDistance - coastingDistance,
Constants.SimulationSettings.DriverActionDistanceTolerance.Value())) { Constants.SimulationSettings.DriverActionDistanceTolerance)) {
return retVal; return retVal;
} }
......
...@@ -368,7 +368,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -368,7 +368,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
operatingPoint = SearchBrakingPower(absTime, operatingPoint.SimulationDistance, gradient, operatingPoint = SearchBrakingPower(absTime, operatingPoint.SimulationDistance, gradient,
operatingPoint.Acceleration, response); operatingPoint.Acceleration, response);
if (!ds.IsEqual(operatingPoint.SimulationDistance, 1E-15)) { if (!ds.IsEqual(operatingPoint.SimulationDistance, 1E-15.SI<Meter>())) {
Log.Info( Log.Info(
"SearchOperatingPoint Breaking reduced the max. distance: {0} -> {1}. Issue new request from driving cycle!", "SearchOperatingPoint Breaking reduced the max. distance: {0} -> {1}. Issue new request from driving cycle!",
operatingPoint.SimulationDistance, ds); operatingPoint.SimulationDistance, ds);
...@@ -488,7 +488,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -488,7 +488,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
NextComponent.Request(absTime, operatingPoint.SimulationInterval, operatingPoint.Acceleration, gradient, true); NextComponent.Request(absTime, operatingPoint.SimulationInterval, operatingPoint.Acceleration, gradient, true);
delta = DataBus.ClutchClosed(absTime) ? response.DeltaDragLoad : response.GearboxPowerRequest; delta = DataBus.ClutchClosed(absTime) ? response.DeltaDragLoad : response.GearboxPowerRequest;
if (delta.IsEqual(0, Constants.SimulationSettings.EnginePowerSearchTolerance)) { if (delta.IsEqual(0.SI<Watt>(), Constants.SimulationSettings.EnginePowerSearchTolerance)) {
LogManager.EnableLogging(); LogManager.EnableLogging();
Log.Debug("found operating point in {0} iterations, delta: {1}", debug.Count, delta); Log.Debug("found operating point in {0} iterations, delta: {1}", debug.Count, delta);
return operatingPoint; return operatingPoint;
...@@ -602,7 +602,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -602,7 +602,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
(ResponseDryRun)NextComponent.Request(absTime, retVal.SimulationInterval, retVal.Acceleration, gradient, true); (ResponseDryRun)NextComponent.Request(absTime, retVal.SimulationInterval, retVal.Acceleration, gradient, true);
delta = actionRoll ? response.GearboxPowerRequest : (coasting ? response.DeltaDragLoad : response.DeltaFullLoad); delta = actionRoll ? response.GearboxPowerRequest : (coasting ? response.DeltaDragLoad : response.DeltaFullLoad);
if (delta.IsEqual(0, Constants.SimulationSettings.EnginePowerSearchTolerance)) { if (delta.IsEqual(0.SI<Watt>(), Constants.SimulationSettings.EnginePowerSearchTolerance)) {
LogManager.EnableLogging(); LogManager.EnableLogging();
Log.Debug("found operating point in {0} iterations. Engine Power req: {2}, Gearbox Power req: {3} delta: {1}", Log.Debug("found operating point in {0} iterations. Engine Power req: {2}, Gearbox Power req: {3} delta: {1}",
debug.Count, delta, response.EnginePowerRequest, response.GearboxPowerRequest); debug.Count, delta, response.EnginePowerRequest, response.GearboxPowerRequest);
......
...@@ -232,7 +232,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -232,7 +232,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
}; };
} }
if (outTorque.IsGreater(0, Constants.SimulationSettings.EnginePowerSearchTolerance)) { if ((outTorque * outAngularVelocity).IsGreater(0.SI<Watt>(), Constants.SimulationSettings.EnginePowerSearchTolerance)) {
return new ResponseOverload { return new ResponseOverload {
Source = this, Source = this,
Delta = outTorque * outAngularVelocity, Delta = outTorque * outAngularVelocity,
...@@ -240,7 +240,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -240,7 +240,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
}; };
} }
if (outTorque.IsSmaller(0, Constants.SimulationSettings.EnginePowerSearchTolerance)) { if ((outTorque * outAngularVelocity).IsSmaller(0.SI<Watt>(), Constants.SimulationSettings.EnginePowerSearchTolerance)) {
return new ResponseUnderload { return new ResponseUnderload {
Source = this, Source = this,
Delta = outTorque * outAngularVelocity, Delta = outTorque * outAngularVelocity,
......
...@@ -149,7 +149,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -149,7 +149,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
Log.Warn("distance field is not set!"); Log.Warn("distance field is not set!");
} else { } else {
var distance = (SI)writer[ModalResultField.dist]; var distance = (SI)writer[ModalResultField.dist];
if (!distance.IsEqual(_currentState.Distance, 1e-12)) { if (!distance.IsEqual(_currentState.Distance, 1e-12.SI<Meter>())) {
Log.Warn("distance diverges: {0}, distance: {1}", (distance - _currentState.Distance).Value(), distance); Log.Warn("distance diverges: {0}, distance: {1}", (distance - _currentState.Distance).Value(), distance);
} }
} }
......
...@@ -1599,9 +1599,10 @@ namespace TUGraz.VectoCore.Utils ...@@ -1599,9 +1599,10 @@ namespace TUGraz.VectoCore.Utils
/// <param name="si">The si.</param> /// <param name="si">The si.</param>
/// <param name="tolerance">The tolerance.</param> /// <param name="tolerance">The tolerance.</param>
/// <returns></returns> /// <returns></returns>
public bool IsEqual(SI si, double tolerance = DoubleExtensionMethods.Tolerance) public bool IsEqual(SI si, SI tolerance = null)
{ {
return HasEqualUnit(si) && Val.IsEqual(si.Val, tolerance); return (tolerance == null || HasEqualUnit(tolerance)) && HasEqualUnit(si) &&
Val.IsEqual(si.Val, tolerance == null ? DoubleExtensionMethods.Tolerance : tolerance.Value());
} }
/// <summary> /// <summary>
...@@ -1621,9 +1622,10 @@ namespace TUGraz.VectoCore.Utils ...@@ -1621,9 +1622,10 @@ namespace TUGraz.VectoCore.Utils
/// <param name="si">The si.</param> /// <param name="si">The si.</param>
/// <param name="tolerance">The tolerance.</param> /// <param name="tolerance">The tolerance.</param>
/// <returns></returns> /// <returns></returns>
public bool IsSmaller(SI si, double tolerance = DoubleExtensionMethods.Tolerance) public bool IsSmaller(SI si, SI tolerance = null)
{ {
return HasEqualUnit(si) && Val.IsSmaller(si.Val, tolerance); return (tolerance == null || HasEqualUnit(tolerance)) && HasEqualUnit(si) &&
Val.IsSmaller(si.Val, tolerance == null ? DoubleExtensionMethods.Tolerance : tolerance.Value());
} }
/// <summary> /// <summary>
...@@ -1632,9 +1634,10 @@ namespace TUGraz.VectoCore.Utils ...@@ -1632,9 +1634,10 @@ namespace TUGraz.VectoCore.Utils
/// <param name="si">The si.</param> /// <param name="si">The si.</param>
/// <param name="tolerance">The tolerance.</param> /// <param name="tolerance">The tolerance.</param>
/// <returns></returns> /// <returns></returns>
public bool IsSmallerOrEqual(SI si, double tolerance = DoubleExtensionMethods.Tolerance) public bool IsSmallerOrEqual(SI si, SI tolerance = null)
{ {
return HasEqualUnit(si) && Val.IsSmallerOrEqual(si.Val, tolerance); return (tolerance == null || HasEqualUnit(tolerance)) && HasEqualUnit(si) &&
Val.IsSmallerOrEqual(si.Val, tolerance == null ? DoubleExtensionMethods.Tolerance : tolerance.Value());
} }
/// <summary> /// <summary>
...@@ -1643,9 +1646,10 @@ namespace TUGraz.VectoCore.Utils ...@@ -1643,9 +1646,10 @@ namespace TUGraz.VectoCore.Utils
/// <param name="si">The si.</param> /// <param name="si">The si.</param>
/// <param name="tolerance">The tolerance.</param> /// <param name="tolerance">The tolerance.</param>
/// <returns></returns> /// <returns></returns>
public bool IsGreater(SI si, double tolerance = DoubleExtensionMethods.Tolerance) public bool IsGreater(SI si, SI tolerance = null)
{ {
return HasEqualUnit(si) && Val.IsGreater(si.Val, tolerance); return (tolerance == null || HasEqualUnit(tolerance)) && HasEqualUnit(si) &&
Val.IsGreater(si.Val, tolerance == null ? DoubleExtensionMethods.Tolerance : tolerance.Value());
} }
/// <summary> /// <summary>
...@@ -1654,9 +1658,10 @@ namespace TUGraz.VectoCore.Utils ...@@ -1654,9 +1658,10 @@ namespace TUGraz.VectoCore.Utils
/// <param name="si">The si.</param> /// <param name="si">The si.</param>
/// <param name="tolerance">The tolerance.</param> /// <param name="tolerance">The tolerance.</param>
/// <returns></returns> /// <returns></returns>
public bool IsGreaterOrEqual(SI si, double tolerance = DoubleExtensionMethods.Tolerance) public bool IsGreaterOrEqual(SI si, SI tolerance = null)
{ {
return HasEqualUnit(si) && Val.IsGreaterOrEqual(si.Val, tolerance); return (tolerance == null || HasEqualUnit(tolerance)) && HasEqualUnit(si) &&
Val.IsGreaterOrEqual(si.Val, tolerance == null ? DoubleExtensionMethods.Tolerance : tolerance.Value());
} }
/// <summary> /// <summary>
......
...@@ -73,7 +73,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent ...@@ -73,7 +73,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent
Assert.AreEqual(4.9812, vehicleContainer.VehicleSpeed.Value(), Tolerance); Assert.AreEqual(4.9812, vehicleContainer.VehicleSpeed.Value(), Tolerance);
Assert.AreEqual(0.2004, response.SimulationInterval.Value(), Tolerance); Assert.AreEqual(0.2004, response.SimulationInterval.Value(), Tolerance);
Assert.AreEqual(engine.PreviousState.FullDragPower.Value(), engine.PreviousState.EnginePower.Value(), Assert.AreEqual(engine.PreviousState.FullDragPower.Value(), engine.PreviousState.EnginePower.Value(),
Constants.SimulationSettings.EnginePowerSearchTolerance); Constants.SimulationSettings.EnginePowerSearchTolerance.Value());
while (vehicleContainer.VehicleSpeed > 1) { while (vehicleContainer.VehicleSpeed > 1) {
response = driver.DrivingActionCoast(absTime, 1.SI<Meter>(), velocity, 0.SI<Radian>()); response = driver.DrivingActionCoast(absTime, 1.SI<Meter>(), velocity, 0.SI<Radian>());
...@@ -132,7 +132,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent ...@@ -132,7 +132,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent
Assert.AreEqual(4.9812, vehicleContainer.VehicleSpeed.Value(), Tolerance); Assert.AreEqual(4.9812, vehicleContainer.VehicleSpeed.Value(), Tolerance);
Assert.AreEqual(0.2004, response.SimulationInterval.Value(), Tolerance); Assert.AreEqual(0.2004, response.SimulationInterval.Value(), Tolerance);
Assert.AreEqual(engine.PreviousState.FullDragPower.Value(), engine.PreviousState.EnginePower.Value(), Assert.AreEqual(engine.PreviousState.FullDragPower.Value(), engine.PreviousState.EnginePower.Value(),
Constants.SimulationSettings.EnginePowerSearchTolerance); Constants.SimulationSettings.EnginePowerSearchTolerance.Value());
while (vehicleContainer.VehicleSpeed > 1) { while (vehicleContainer.VehicleSpeed > 1) {
response = driver.DrivingActionCoast(absTime, 1.SI<Meter>(), velocity, gradient); response = driver.DrivingActionCoast(absTime, 1.SI<Meter>(), velocity, gradient);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment