diff --git a/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs b/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs index 88716cb13e034a92a1996e60e50cbf0d21e96303..33ca3d940e479b53a530cf29a5139ccc1f00ed25 100644 --- a/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs +++ b/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs @@ -104,7 +104,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl 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); } @@ -550,7 +551,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var response = (ResponseDryRun)RequestPort.Request(absTime, dt, torque, nextAngularSpeed, true); delta = response.DeltaDragLoad; 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, delta); return RequestPort.Request(absTime, dt, torque, nextAngularSpeed); diff --git a/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs b/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs index ec6f6416aa9b40494223b31c3e7d5849dbf0d5a4..cf98e2d3eddfcf6552e87dbab282a8ac81e642e8 100644 --- a/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs +++ b/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs @@ -55,7 +55,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl nextAction = GetNextDrivingAction(currentDistance); if (nextAction != null) { if (currentDistance.IsEqual(nextAction.ActionDistance, - Constants.SimulationSettings.DriverActionDistanceTolerance.Value())) { + Constants.SimulationSettings.DriverActionDistanceTolerance)) { CurrentDrivingMode = DrivingMode.DrivingModeBrake; DrivingModes[CurrentDrivingMode].ResetMode(); Log.Debug("Switching to DrivingMode BRAKE"); @@ -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 // we are safe - go ahead... if ((Driver.DataBus.Distance + ds).IsSmallerOrEqual(nextAction.TriggerDistance - coastingDistance, - Constants.SimulationSettings.DriverActionDistanceTolerance.Value())) { + Constants.SimulationSettings.DriverActionDistanceTolerance)) { return retVal; } diff --git a/VectoCore/Models/SimulationComponent/Impl/Driver.cs b/VectoCore/Models/SimulationComponent/Impl/Driver.cs index 732d008c3f914825735b988c0c05b088fba2e9a4..af45a2cd3af45e967f0b8f256d1f9e8a97b00055 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Driver.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Driver.cs @@ -368,7 +368,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl operatingPoint = SearchBrakingPower(absTime, operatingPoint.SimulationDistance, gradient, operatingPoint.Acceleration, response); - if (!ds.IsEqual(operatingPoint.SimulationDistance, 1E-15)) { + if (!ds.IsEqual(operatingPoint.SimulationDistance, 1E-15.SI<Meter>())) { Log.Info( "SearchOperatingPoint Breaking reduced the max. distance: {0} -> {1}. Issue new request from driving cycle!", operatingPoint.SimulationDistance, ds); @@ -488,7 +488,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl NextComponent.Request(absTime, operatingPoint.SimulationInterval, operatingPoint.Acceleration, gradient, true); 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(); Log.Debug("found operating point in {0} iterations, delta: {1}", debug.Count, delta); return operatingPoint; @@ -602,7 +602,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl (ResponseDryRun)NextComponent.Request(absTime, retVal.SimulationInterval, retVal.Acceleration, gradient, true); 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(); 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); diff --git a/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs index 258cbb63c7057b0fbf57ab2d265a89e9cb3ba82b..8a64ff02d9b830eb838a2cfaeddcf394cd3e2c92 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs @@ -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 { Source = this, Delta = outTorque * outAngularVelocity, @@ -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 { Source = this, Delta = outTorque * outAngularVelocity, diff --git a/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs b/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs index 6b676356b388fbf83ce66187727194fe0eb34fcd..5f61519d806775de8e2ac2b3f4924139c33a3466 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs @@ -149,7 +149,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Log.Warn("distance field is not set!"); } else { 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); } } diff --git a/VectoCore/Utils/SI.cs b/VectoCore/Utils/SI.cs index bef29889a3e2b9bd180f3517704207afdf0096c3..7d3b876fcb4f5798c9320198a585fce41904eba9 100644 --- a/VectoCore/Utils/SI.cs +++ b/VectoCore/Utils/SI.cs @@ -1599,9 +1599,10 @@ namespace TUGraz.VectoCore.Utils /// <param name="si">The si.</param> /// <param name="tolerance">The tolerance.</param> /// <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> @@ -1621,9 +1622,10 @@ namespace TUGraz.VectoCore.Utils /// <param name="si">The si.</param> /// <param name="tolerance">The tolerance.</param> /// <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> @@ -1632,9 +1634,10 @@ namespace TUGraz.VectoCore.Utils /// <param name="si">The si.</param> /// <param name="tolerance">The tolerance.</param> /// <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> @@ -1643,9 +1646,10 @@ namespace TUGraz.VectoCore.Utils /// <param name="si">The si.</param> /// <param name="tolerance">The tolerance.</param> /// <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> @@ -1654,9 +1658,10 @@ namespace TUGraz.VectoCore.Utils /// <param name="si">The si.</param> /// <param name="tolerance">The tolerance.</param> /// <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> diff --git a/VectoCoreTest/Models/SimulationComponent/DriverTest.cs b/VectoCoreTest/Models/SimulationComponent/DriverTest.cs index 1a8d15854c387a7bb09cd080096b6652c427e4f1..03e87a4fb4f8612d731277af1a94071462cd793a 100644 --- a/VectoCoreTest/Models/SimulationComponent/DriverTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/DriverTest.cs @@ -73,7 +73,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent Assert.AreEqual(4.9812, vehicleContainer.VehicleSpeed.Value(), Tolerance); Assert.AreEqual(0.2004, response.SimulationInterval.Value(), Tolerance); Assert.AreEqual(engine.PreviousState.FullDragPower.Value(), engine.PreviousState.EnginePower.Value(), - Constants.SimulationSettings.EnginePowerSearchTolerance); + Constants.SimulationSettings.EnginePowerSearchTolerance.Value()); while (vehicleContainer.VehicleSpeed > 1) { response = driver.DrivingActionCoast(absTime, 1.SI<Meter>(), velocity, 0.SI<Radian>()); @@ -132,7 +132,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent Assert.AreEqual(4.9812, vehicleContainer.VehicleSpeed.Value(), Tolerance); Assert.AreEqual(0.2004, response.SimulationInterval.Value(), Tolerance); Assert.AreEqual(engine.PreviousState.FullDragPower.Value(), engine.PreviousState.EnginePower.Value(), - Constants.SimulationSettings.EnginePowerSearchTolerance); + Constants.SimulationSettings.EnginePowerSearchTolerance.Value()); while (vehicleContainer.VehicleSpeed > 1) { response = driver.DrivingActionCoast(absTime, 1.SI<Meter>(), velocity, gradient);