diff --git a/VectoCore/Models/Connector/Ports/IDriverDemandPort.cs b/VectoCore/Models/Connector/Ports/IDriverDemandPort.cs index 5468b6fb1aa417076ea85b6e1d7e12358ab491f5..e6a7d6c7eaecf2915e13e3ac12a0b66e300f99e8 100644 --- a/VectoCore/Models/Connector/Ports/IDriverDemandPort.cs +++ b/VectoCore/Models/Connector/Ports/IDriverDemandPort.cs @@ -53,6 +53,6 @@ namespace TUGraz.VectoCore.Models.Connector.Ports /// <param name="dt">[s]</param> /// <param name="acceleration">[m/s^2]</param> /// <param name="gradient">[rad]</param> - IResponse Request(TimeSpan absTime, TimeSpan dt, MeterPerSquareSecond acceleration, Radian gradient); + IResponse Request(Second absTime, Second dt, MeterPerSquareSecond acceleration, Radian gradient); } } \ No newline at end of file diff --git a/VectoCore/Models/Connector/Ports/IDrivingCyclePort.cs b/VectoCore/Models/Connector/Ports/IDrivingCyclePort.cs index ab4f7669e93b6d37e64b09963cb8b57aaa39ba18..37ffe6ac786aa6fbd850cfba2b4d1664fbc6573e 100644 --- a/VectoCore/Models/Connector/Ports/IDrivingCyclePort.cs +++ b/VectoCore/Models/Connector/Ports/IDrivingCyclePort.cs @@ -54,7 +54,7 @@ namespace TUGraz.VectoCore.Models.Connector.Ports /// <param name="ds"></param> /// <param name="targetVelocity">[m/s]</param> /// <param name="gradient">[rad]</param> - IResponse Request(TimeSpan absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient); + IResponse Request(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient); /// <summary> /// Requests the outport to simulate the given time interval @@ -64,6 +64,6 @@ namespace TUGraz.VectoCore.Models.Connector.Ports /// <param name="targetVelocity"></param> /// <param name="gradient"></param> /// <returns></returns> - IResponse Request(TimeSpan absTime, TimeSpan dt, MeterPerSecond targetVelocity, Radian gradient); + IResponse Request(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient); } } \ No newline at end of file diff --git a/VectoCore/Models/Connector/Ports/IFvPort.cs b/VectoCore/Models/Connector/Ports/IFvPort.cs index 70f633b5767a9f3339713534f6c8e35c9b273192..9589457820ac3a790f3efa56885efe9d68b3d32d 100644 --- a/VectoCore/Models/Connector/Ports/IFvPort.cs +++ b/VectoCore/Models/Connector/Ports/IFvPort.cs @@ -53,6 +53,6 @@ namespace TUGraz.VectoCore.Models.Connector.Ports /// <param name="dt">[s]</param> /// <param name="force">[N]</param> /// <param name="velocity">[m/s]</param> - IResponse Request(TimeSpan absTime, TimeSpan dt, Newton force, MeterPerSecond velocity); + IResponse Request(Second absTime, Second dt, Newton force, MeterPerSecond velocity); } } \ No newline at end of file diff --git a/VectoCore/Models/Connector/Ports/IResponse.cs b/VectoCore/Models/Connector/Ports/IResponse.cs index 7cf8de2e0331861e65bb88199f0e8955a6ea80b5..c1cf346e863b1a53c01369b83d6515732e347c80 100644 --- a/VectoCore/Models/Connector/Ports/IResponse.cs +++ b/VectoCore/Models/Connector/Ports/IResponse.cs @@ -1,5 +1,6 @@ using System; using System.Security.Cryptography.X509Certificates; +using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Connector.Ports { @@ -18,7 +19,7 @@ namespace TUGraz.VectoCore.Models.Connector.Ports /// </summary> public interface IResponse { - TimeSpan SimulationInterval { get; set; } + Second SimulationInterval { get; set; } ResponseType ResponseType { get; } } diff --git a/VectoCore/Models/Connector/Ports/ISimulationPort.cs b/VectoCore/Models/Connector/Ports/ISimulationPort.cs index 1e58ab5011cfaff2a4a24b72278a9b6886f9d23b..77026657a8d436728b82122bcdd2b57c64ec6c01 100644 --- a/VectoCore/Models/Connector/Ports/ISimulationPort.cs +++ b/VectoCore/Models/Connector/Ports/ISimulationPort.cs @@ -28,9 +28,9 @@ namespace TUGraz.VectoCore.Models.Connector.Ports /// <param name="absTime">The absolute time of the simulation.</param> /// <param name="ds"></param> /// <returns></returns> - IResponse Request(TimeSpan absTime, Meter ds); + IResponse Request(Second absTime, Meter ds); - IResponse Request(TimeSpan absTime, TimeSpan dt); + IResponse Request(Second absTime, Second dt); IResponse Initialize(); } diff --git a/VectoCore/Models/Connector/Ports/ITnPort.cs b/VectoCore/Models/Connector/Ports/ITnPort.cs index 5ee9f5deeb2c4080d8509777f0f80afa4fc2bdc2..c3d74a248578763231e774a85865c8d01c074d7c 100644 --- a/VectoCore/Models/Connector/Ports/ITnPort.cs +++ b/VectoCore/Models/Connector/Ports/ITnPort.cs @@ -54,6 +54,6 @@ namespace TUGraz.VectoCore.Models.Connector.Ports /// <param name="dt">[s]</param> /// <param name="torque">[Nm]</param> /// <param name="angularVelocity">[rad/s]</param> - IResponse Request(TimeSpan absTime, TimeSpan dt, NewtonMeter torque, PerSecond angularVelocity); + IResponse Request(Second absTime, Second dt, NewtonMeter torque, PerSecond angularVelocity); } } \ No newline at end of file diff --git a/VectoCore/Models/Connector/Ports/Impl/Response.cs b/VectoCore/Models/Connector/Ports/Impl/Response.cs index 191fc3b711dbcf6c4b768194549636966a6f9d62..9367b94861ad9293619edbbd5a6fe04acce79e26 100644 --- a/VectoCore/Models/Connector/Ports/Impl/Response.cs +++ b/VectoCore/Models/Connector/Ports/Impl/Response.cs @@ -5,7 +5,7 @@ namespace TUGraz.VectoCore.Models.Connector.Ports.Impl { public abstract class AbstractResponse : IResponse { - public TimeSpan SimulationInterval { get; set; } + public Second SimulationInterval { get; set; } public abstract ResponseType ResponseType { get; } } @@ -51,7 +51,7 @@ namespace TUGraz.VectoCore.Models.Connector.Ports.Impl /// </summary> public class ResponseFailTimeInterval : AbstractResponse { - public TimeSpan DeltaT { get; set; } + public Second DeltaT { get; set; } public override ResponseType ResponseType { diff --git a/VectoCore/Models/Simulation/IVehicleContainer.cs b/VectoCore/Models/Simulation/IVehicleContainer.cs index b904c3216409dbccb0bc3d591c7ed9c5e22f9626..e7d4517f390df922d7d6fd50e1a33040f871069a 100644 --- a/VectoCore/Models/Simulation/IVehicleContainer.cs +++ b/VectoCore/Models/Simulation/IVehicleContainer.cs @@ -1,6 +1,7 @@ using TUGraz.VectoCore.Models.Connector.Ports; using TUGraz.VectoCore.Models.Simulation.Cockpit; using TUGraz.VectoCore.Models.SimulationComponent; +using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Simulation { @@ -21,7 +22,7 @@ namespace TUGraz.VectoCore.Models.Simulation /// <summary> /// Commits the current simulation step. /// </summary> - void CommitSimulationStep(double time, double simulationInterval); + void CommitSimulationStep(Second time, Second simulationInterval); /// <summary> /// Finishes the simulation. diff --git a/VectoCore/Models/Simulation/Impl/DistanceRun.cs b/VectoCore/Models/Simulation/Impl/DistanceRun.cs index f3169bf39aabc38a1c3ff300dc2e376097871506..ca3294473eefdbb642a734c055a6cd989e8663cb 100644 --- a/VectoCore/Models/Simulation/Impl/DistanceRun.cs +++ b/VectoCore/Models/Simulation/Impl/DistanceRun.cs @@ -21,7 +21,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl ds = Constants.SimulationSettings.DriveOffDistance; } - var response = CyclePort.Request(AbsTime, ds); + var response = CyclePort.Request((Second)AbsTime, ds); //while (response is ResponseFailTimeInterval) { // _dt = (response as ResponseFailTimeInterval).DeltaT; @@ -32,7 +32,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl return response; } - AbsTime = (AbsTime + TimeSpan.FromTicks(response.SimulationInterval.Ticks / 2)); + AbsTime = (AbsTime + response.SimulationInterval / 2); dt = response.SimulationInterval; return response; } diff --git a/VectoCore/Models/Simulation/Impl/VectoRun.cs b/VectoCore/Models/Simulation/Impl/VectoRun.cs index dfe20a3abbe323cd42a3a744ae3d584ef6f0f1a0..354c2d296bd3200bac64f7ce68d1ee9d1d6c7a46 100644 --- a/VectoCore/Models/Simulation/Impl/VectoRun.cs +++ b/VectoCore/Models/Simulation/Impl/VectoRun.cs @@ -3,6 +3,7 @@ using Common.Logging; using TUGraz.VectoCore.Models.Connector.Ports; using TUGraz.VectoCore.Models.Connector.Ports.Impl; using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Simulation.Impl { @@ -11,9 +12,9 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl /// </summary> public abstract class VectoRun : IVectoRun { - protected TimeSpan AbsTime = new TimeSpan(seconds: 0, minutes: 0, hours: 0); + protected Second AbsTime = 0.SI<Second>(); - protected TimeSpan dt = new TimeSpan(seconds: 1, minutes: 0, hours: 0); + protected Second dt = 1.SI<Second>(); public VectoRun(IVehicleContainer container) { @@ -44,7 +45,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl do { response = DoSimulationStep(); - Container.CommitSimulationStep(AbsTime.TotalSeconds, dt.TotalSeconds); + Container.CommitSimulationStep(AbsTime, dt); // set _dt to difference to next full second. AbsTime += dt; diff --git a/VectoCore/Models/Simulation/Impl/VehicleContainer.cs b/VectoCore/Models/Simulation/Impl/VehicleContainer.cs index e3fc54da14e0ad6a1d2bd486cc197db6ed8ec286..0a2ea160d761ebaf7cf21190dd90e3ca37fa65e0 100644 --- a/VectoCore/Models/Simulation/Impl/VehicleContainer.cs +++ b/VectoCore/Models/Simulation/Impl/VehicleContainer.cs @@ -112,7 +112,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl } - public void CommitSimulationStep(double time, double simulationInterval) + public void CommitSimulationStep(Second time, Second simulationInterval) { _logger.Info("VehicleContainer committing simulation."); foreach (var component in _components) { diff --git a/VectoCore/Models/SimulationComponent/Data/AuxiliaryCycleDataAdapter.cs b/VectoCore/Models/SimulationComponent/Data/AuxiliaryCycleDataAdapter.cs index 3bcf89c03e8286439eabb474a390ff9d3cbabf9b..8a78c7296bac83d5797ff0745cecd787c3ed2c3b 100644 --- a/VectoCore/Models/SimulationComponent/Data/AuxiliaryCycleDataAdapter.cs +++ b/VectoCore/Models/SimulationComponent/Data/AuxiliaryCycleDataAdapter.cs @@ -31,9 +31,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data protected DrivingCycleData.DrivingCycleEntry CurrentCycleEntry { get; set; } - public Watt GetPowerDemand(TimeSpan absTime, TimeSpan dt) + public Watt GetPowerDemand(Second absTime, Second dt) { - if (_nextCycleEntry.Current.Time <= absTime.TotalSeconds) { + if (_nextCycleEntry.Current.Time <= absTime) { CurrentCycleEntry = _nextCycleEntry.Current; _nextCycleEntry.MoveNext(); } diff --git a/VectoCore/Models/SimulationComponent/Data/DrivingCycleData.cs b/VectoCore/Models/SimulationComponent/Data/DrivingCycleData.cs index c333385350ee7e7aa31dfeb5a109451471cba0d7..22015239868f7de42cd10ec3ade470484ed2caaa 100644 --- a/VectoCore/Models/SimulationComponent/Data/DrivingCycleData.cs +++ b/VectoCore/Models/SimulationComponent/Data/DrivingCycleData.cs @@ -439,7 +439,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data public IEnumerable<DrivingCycleEntry> Parse(DataTable table) { ValidateHeader(table.Columns.Cast<DataColumn>().Select(col => col.ColumnName).ToArray()); - var absTime = new TimeSpan(0, 0, 0); + var absTime = 0.SI<Second>(); foreach (DataRow row in table.Rows) { var entry = new DrivingCycleEntry { @@ -464,8 +464,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data entry.EngineSpeed); } } - entry.Time = absTime.TotalSeconds.SI<Second>(); - absTime += new TimeSpan(0, 0, 1); + entry.Time = absTime; + absTime += 1.SI<Second>(); yield return entry; } diff --git a/VectoCore/Models/SimulationComponent/Data/IAuxiliaryCycleData.cs b/VectoCore/Models/SimulationComponent/Data/IAuxiliaryCycleData.cs index e1d731f84a10f235cf4fbe88af541498324b1e64..c0b3e098b1380e02baf6b5e628719d44ae33b84b 100644 --- a/VectoCore/Models/SimulationComponent/Data/IAuxiliaryCycleData.cs +++ b/VectoCore/Models/SimulationComponent/Data/IAuxiliaryCycleData.cs @@ -5,6 +5,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data { public interface IAuxiliaryCycleData { - Watt GetPowerDemand(TimeSpan absTime, TimeSpan dt); + Watt GetPowerDemand(Second absTime, Second dt); } } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs b/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs index fef09efc429072c6873311256356436be821294b..d85153b4c853ab3afb0bb74f2fca14dec5048009 100644 --- a/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs +++ b/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs @@ -32,7 +32,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _nextComponent = other; } - public IResponse Request(TimeSpan absTime, TimeSpan dt, NewtonMeter torque, PerSecond angularVelocity) + public IResponse Request(Second absTime, Second dt, NewtonMeter torque, PerSecond angularVelocity) { return _nextComponent.Request(absTime, dt, _gearData.LossMap.GearboxInTorque(angularVelocity * _gearData.Ratio, torque), diff --git a/VectoCore/Models/SimulationComponent/Impl/Clutch.cs b/VectoCore/Models/SimulationComponent/Impl/Clutch.cs index e3ca6549408f6b27884ead7011f8a67184178369..1cd9c264c06704b52b2cb9ceb5646228f54d3fba 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Clutch.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Clutch.cs @@ -57,7 +57,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return this; } - public IResponse Request(TimeSpan absTime, TimeSpan dt, NewtonMeter torque, PerSecond angularVelocity) + public IResponse Request(Second absTime, Second dt, NewtonMeter torque, PerSecond angularVelocity) { var torqueIn = torque; var engineSpeedIn = angularVelocity; diff --git a/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs b/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs index e92c09c005bd2dc0cef73c948dc99fea6fb4a283..1aca930d9bc122a0ee739c406ccb06a0df7ef080 100644 --- a/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs +++ b/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs @@ -32,7 +32,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl private const double MaxPowerExceededThreshold = 1.05; private const double ZeroThreshold = 0.0001; private const double FullLoadMargin = 0.01; - [NonSerialized] private readonly List<TimeSpan> _enginePowerCorrections = new List<TimeSpan>(); + [NonSerialized] private readonly List<Second> _enginePowerCorrections = new List<Second>(); /// <summary> /// Current state is computed in request method @@ -50,7 +50,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _previousState.OperationMode = EngineOperationMode.Idle; _previousState.EnginePower = 0.SI<Watt>(); _previousState.EngineSpeed = _data.IdleSpeed; - _previousState.dt = TimeSpan.FromSeconds(0.1); + _previousState.dt = 1.SI<Second>(); } #region IEngineCockpit @@ -73,7 +73,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #region ITnOutPort - IResponse ITnOutPort.Request(TimeSpan absTime, TimeSpan dt, NewtonMeter torque, PerSecond engineSpeed) + IResponse ITnOutPort.Request(Second absTime, Second dt, NewtonMeter torque, PerSecond engineSpeed) { _currentState.dt = dt; _currentState.EngineSpeed = engineSpeed; @@ -132,7 +132,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl .ConvertTo() .Gramm.Per.Hour; } catch (VectoException ex) { - Log.WarnFormat("t: {0} - {1} n: {2} Tq: {3}", _currentState.AbsTime.TotalSeconds, ex.Message, + Log.WarnFormat("t: {0} - {1} n: {2} Tq: {3}", _currentState.AbsTime, ex.Message, _currentState.EngineSpeed, _currentState.EngineTorque); writer[ModalResultField.FC] = double.NaN; } @@ -226,9 +226,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// <param name="gear"></param> /// <param name="angularVelocity">[rad/s]</param> /// <param name="dt">[s]</param> - protected void ComputeFullLoadPower(uint gear, PerSecond angularVelocity, TimeSpan dt) + protected void ComputeFullLoadPower(uint gear, PerSecond angularVelocity, Second dt) { - if (dt.Ticks == 0) { + if (dt.IsEqual(0)) { throw new VectoException("ComputeFullLoadPower cannot compute for simulation interval length 0."); } @@ -245,7 +245,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var tStarPrev = pt1 * Math.Log(1 / (1 - (_previousState.EnginePower / _currentState.StationaryFullLoadPower).Value()), Math.E) .SI<Second>(); - var tStar = tStarPrev + _previousState.dt.TotalSeconds.SI<Second>(); + var tStar = tStarPrev + _previousState.dt; var dynFullPowerCalculated = _currentState.StationaryFullLoadPower * (1 - Math.Exp((-tStar / pt1).Value())); _currentState.DynamicFullLoadPower = (dynFullPowerCalculated < _currentState.StationaryFullLoadPower) ? dynFullPowerCalculated @@ -282,7 +282,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// <summary> /// [s] /// </summary> - public TimeSpan AbsTime { get; set; } + public Second AbsTime { get; set; } /// <summary> /// [W] @@ -334,7 +334,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// </summary> public NewtonMeter EngineTorque { get; set; } - public TimeSpan dt { get; set; } + public Second dt { get; set; } #region Equality members diff --git a/VectoCore/Models/SimulationComponent/Impl/DirectAuxiliary.cs b/VectoCore/Models/SimulationComponent/Impl/DirectAuxiliary.cs index 8d18267e03f3076e0d0f18fde14fa3ed4aabc3b4..2ea6f21c06629f08cbd8d2f884774c49e14fde5e 100644 --- a/VectoCore/Models/SimulationComponent/Impl/DirectAuxiliary.cs +++ b/VectoCore/Models/SimulationComponent/Impl/DirectAuxiliary.cs @@ -49,13 +49,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #region ITnOutPort - IResponse ITnOutPort.Request(TimeSpan absTime, TimeSpan dt, NewtonMeter torque, PerSecond engineSpeed) + IResponse ITnOutPort.Request(Second absTime, Second dt, NewtonMeter torque, PerSecond engineSpeed) { if (_outPort == null) { Log.ErrorFormat("{0} cannot handle incoming request - no outport available", absTime); throw new VectoSimulationException( string.Format("{0} cannot handle incoming request - no outport available", - absTime.TotalSeconds)); + absTime)); } _powerDemand = _demand.GetPowerDemand(absTime, dt); diff --git a/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs b/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs index cfe6fcae25e6876bc7cd750f72903d72d6afa4be..9821ec7e20a6fa154547e9171363165dd9e81a51 100644 --- a/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs @@ -65,7 +65,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #region ISimulationOutPort - IResponse ISimulationOutPort.Request(TimeSpan absTime, Meter ds) + IResponse ISimulationOutPort.Request(Second absTime, Meter ds) { var retVal = DoHandleRequest(absTime, ds); @@ -75,7 +75,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return retVal; } - private IResponse DoHandleRequest(TimeSpan absTime, Meter ds) + private IResponse DoHandleRequest(Second absTime, Meter ds) { //var currentCycleEntry = Data.Entries[_previousState.CycleIndex]; //var nextCycleEntry = Data.Entries[_previousState.CycleIndex + 1]; @@ -83,15 +83,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl if (CycleIntervalIterator.LeftSample.Distance.IsEqual(PreviousState.Distance.Value())) { // exactly on an entry in the cycle... if (!CycleIntervalIterator.LeftSample.StoppingTime.IsEqual(0) - && CycleIntervalIterator.LeftSample.StoppingTime.Value() > PreviousState.WaitTime.TotalSeconds) { + && CycleIntervalIterator.LeftSample.StoppingTime > PreviousState.WaitTime) { // stop for certain time unless we've already waited long enough... if (!CycleIntervalIterator.LeftSample.VehicleTargetSpeed.IsEqual(0)) { Log.WarnFormat("Stopping Time requested in cycle but target-velocity not zero. distance: {0}, target speed: {1}", CycleIntervalIterator.LeftSample.StoppingTime, CycleIntervalIterator.LeftSample.VehicleTargetSpeed); throw new VectoSimulationException("Stopping Time only allowed when target speed is zero!"); } - var dt = TimeSpan.FromSeconds(CycleIntervalIterator.LeftSample.StoppingTime.Value()) - - PreviousState.WaitTime; + var dt = CycleIntervalIterator.LeftSample.StoppingTime.Value() - PreviousState.WaitTime; return DriveTimeInterval(absTime, dt); } } @@ -108,16 +107,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return DriveDistance(absTime, ds); } - private IResponse DriveTimeInterval(TimeSpan absTime, TimeSpan dt) + private IResponse DriveTimeInterval(Second absTime, Second dt) { CurrentState.AbsTime = PreviousState.AbsTime + dt; CurrentState.WaitTime = PreviousState.WaitTime + dt; - return _outPort.Request(absTime, dt, + return _outPort.Request((Second)absTime, (Second)dt, CycleIntervalIterator.LeftSample.VehicleTargetSpeed, ComputeGradient()); } - private IResponse DriveDistance(TimeSpan absTime, Meter ds) + private IResponse DriveDistance(Second absTime, Meter ds) { CurrentState.Distance = PreviousState.Distance + ds; @@ -143,7 +142,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return gradient; } - IResponse ISimulationOutPort.Request(TimeSpan absTime, TimeSpan dt) + IResponse ISimulationOutPort.Request(Second absTime, Second dt) { throw new NotImplementedException(); } @@ -152,8 +151,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { var first = Data.Entries.First(); PreviousState = new DrivingCycleState() { - AbsTime = TimeSpan.FromSeconds(0), - WaitTime = TimeSpan.FromSeconds(0), + AbsTime = 0.SI<Second>(), + WaitTime = 0.SI<Second>(), Distance = first.Distance, Altitude = first.Altitude, }; @@ -178,7 +177,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl CurrentState = CurrentState.Clone(); if (!CycleIntervalIterator.LeftSample.StoppingTime.IsEqual(0) && - CycleIntervalIterator.LeftSample.StoppingTime.IsEqual(CurrentState.WaitTime.TotalSeconds)) { + CycleIntervalIterator.LeftSample.StoppingTime.IsEqual(CurrentState.WaitTime)) { // we needed to stop at the current interval in the cycle and have already waited enough time, move on.. CycleIntervalIterator.MoveNext(); } @@ -261,16 +260,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl VehicleTargetSpeed = VehicleTargetSpeed, Altitude = Altitude, // WaitTime is not cloned on purpose! - WaitTime = TimeSpan.FromSeconds(0), + WaitTime = 0.SI<Second>(), Response = null }; } - public TimeSpan AbsTime; + public Second AbsTime; public Meter Distance; - public TimeSpan WaitTime; + public Second WaitTime; public MeterPerSecond VehicleTargetSpeed; diff --git a/VectoCore/Models/SimulationComponent/Impl/Driver.cs b/VectoCore/Models/SimulationComponent/Impl/Driver.cs index a1a392853edd601057afac4dfc54a487c9a516ea..85dcacac6eb46f6ec8f8b7dd574af61447e84e4f 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Driver.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Driver.cs @@ -35,7 +35,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Next = other; } - public IResponse Request(TimeSpan absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient) + public IResponse Request(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient) { var retVal = DoHandleRequest(absTime, ds, targetVelocity, gradient); @@ -46,7 +46,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } - public IResponse Request(TimeSpan absTime, TimeSpan dt, MeterPerSecond targetVelocity, Radian gradient) + public IResponse Request(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient) { var retVal = DoHandleRequest(absTime, dt, targetVelocity, gradient); @@ -57,7 +57,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } - protected IResponse DoHandleRequest(TimeSpan absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient) + protected IResponse DoHandleRequest(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient) { var currentSpeed = Cockpit.VehicleSpeed(); @@ -73,24 +73,29 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl requiredAcceleration = maxAcceleration.Deceleration; } - var solutions = VectoMath.QuadraticEquationSolver(requiredAcceleration.Value() / 2.0, currentSpeed.Value(), - -ds.Value()); - solutions = solutions.Where(x => x >= 0).ToList(); - - if (solutions.Count == 0) { - Log.WarnFormat( - "Could not find solution for computing required time interval to drive distance {0}. currentSpeed: {1}, targetSpeed: {2}, acceleration: {3}", - ds, currentSpeed, targetVelocity, requiredAcceleration); - return new ResponseFailTimeInterval(); + var dt = (ds / currentSpeed).Cast<Second>(); + if (!requiredAcceleration.IsEqual(0)) { + // we need to accelerate / decelerate. solve quadratic equation... + // ds = acceleration / 2 * dt^2 + currentSpeed * dt => solve for dt + var solutions = VectoMath.QuadraticEquationSolver(requiredAcceleration.Value() / 2.0, currentSpeed.Value(), + -ds.Value()); + solutions = solutions.Where(x => x >= 0).ToList(); + + if (solutions.Count != 1) { + Log.WarnFormat( + "Could not find single solution for computing required time interval to drive distance {0}. currentSpeed: {1}, targetSpeed: {2}, acceleration: {3}", + ds, currentSpeed, targetVelocity, requiredAcceleration); + return new ResponseFailTimeInterval(); + } + dt = solutions.First().SI<Second>(); } - var dt = TimeSpan.FromSeconds(solutions.First()); var retVal = Next.Request(absTime, dt, requiredAcceleration, gradient); retVal.SimulationInterval = dt; return retVal; } - protected IResponse DoHandleRequest(TimeSpan absTime, TimeSpan dt, MeterPerSecond targetVelocity, Radian gradient) + protected IResponse DoHandleRequest(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient) { if (!targetVelocity.IsEqual(0) || !Cockpit.VehicleSpeed().IsEqual(0)) { throw new NotImplementedException("TargetVelocity or VehicleVelocity is not zero!"); diff --git a/VectoCore/Models/SimulationComponent/Impl/EngineOnlyDrivingCycle.cs b/VectoCore/Models/SimulationComponent/Impl/EngineOnlyDrivingCycle.cs index 50427f190bbd191f3863d717f08a16c75f9bb026..4417e28d1d8522f5fdb3807919431fa3dc582d38 100644 --- a/VectoCore/Models/SimulationComponent/Impl/EngineOnlyDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/EngineOnlyDrivingCycle.cs @@ -43,15 +43,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #region ISimulationOutPort - public IResponse Request(TimeSpan absTime, Meter ds) + public IResponse Request(Second absTime, Meter ds) { throw new VectoSimulationException("Engine-Only Simulation can not handle distance request"); } - IResponse ISimulationOutPort.Request(TimeSpan absTime, TimeSpan dt) + IResponse ISimulationOutPort.Request(Second absTime, Second dt) { //todo: change to variable time steps - var index = (int)Math.Floor(absTime.TotalSeconds); + var index = (int)Math.Floor(absTime.Value()); if (index >= Data.Entries.Count) { return new ResponseCycleFinished(); } diff --git a/VectoCore/Models/SimulationComponent/Impl/EngineOnlyGearbox.cs b/VectoCore/Models/SimulationComponent/Impl/EngineOnlyGearbox.cs index 90c9a925a6c32d97d7278d2c3949708e643e24b0..8b50b510be505c8ddac485c94711c64998f6ce8d 100644 --- a/VectoCore/Models/SimulationComponent/Impl/EngineOnlyGearbox.cs +++ b/VectoCore/Models/SimulationComponent/Impl/EngineOnlyGearbox.cs @@ -51,13 +51,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #region ITnOutPort - IResponse ITnOutPort.Request(TimeSpan absTime, TimeSpan dt, NewtonMeter torque, PerSecond engineSpeed) + IResponse ITnOutPort.Request(Second absTime, Second dt, NewtonMeter torque, PerSecond engineSpeed) { if (_outPort == null) { Log.ErrorFormat("{0} cannot handle incoming request - no outport available", absTime); throw new VectoSimulationException( string.Format("{0} cannot handle incoming request - no outport available", - absTime.TotalSeconds)); + absTime)); } return _outPort.Request(absTime, dt, torque, engineSpeed); } diff --git a/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs index cf7cc9e5a9a318c460fb7c88556643344268e9df..5c59ce99a3450fdd70336d349a1651fc45dc5c33 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs @@ -48,7 +48,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #region ITnOutPort - IResponse ITnOutPort.Request(TimeSpan absTime, TimeSpan dt, NewtonMeter torque, PerSecond engineSpeed) + IResponse ITnOutPort.Request(Second absTime, Second dt, NewtonMeter torque, PerSecond engineSpeed) { throw new NotImplementedException(); } diff --git a/VectoCore/Models/SimulationComponent/Impl/MappingAuxiliary.cs b/VectoCore/Models/SimulationComponent/Impl/MappingAuxiliary.cs index ac73e3a75f60c38c9ed37a39f0cf840a9bfd5b60..22d8eb3036d7e45a83fb9e97ab0943e547d16cca 100644 --- a/VectoCore/Models/SimulationComponent/Impl/MappingAuxiliary.cs +++ b/VectoCore/Models/SimulationComponent/Impl/MappingAuxiliary.cs @@ -68,13 +68,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #region ITnOutPort - IResponse ITnOutPort.Request(TimeSpan absTime, TimeSpan dt, NewtonMeter torque, PerSecond angularVelocity) + IResponse ITnOutPort.Request(Second absTime, Second dt, NewtonMeter torque, PerSecond angularVelocity) { if (_outPort == null) { Log.ErrorFormat("{0} cannot handle incoming request - no outport available", absTime); throw new VectoSimulationException( string.Format("{0} cannot handle incoming request - no outport available", - absTime.TotalSeconds)); + absTime)); } var power_supply = _demand.GetPowerDemand(absTime, dt); diff --git a/VectoCore/Models/SimulationComponent/Impl/Retarder.cs b/VectoCore/Models/SimulationComponent/Impl/Retarder.cs index 073594c0a3a28495c5f41e3138f00ff32b3e63f7..bbbc828e4d3e9167a1354a45ef99c306d9929825 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Retarder.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Retarder.cs @@ -43,7 +43,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _nextComponent = other; } - public IResponse Request(TimeSpan absTime, TimeSpan dt, NewtonMeter torque, PerSecond angularVelocity) + public IResponse Request(Second absTime, Second dt, NewtonMeter torque, PerSecond angularVelocity) { var retarderTorqueLoss = _lossMap.RetarderLoss(angularVelocity); //_retarderLoss = Formulas.TorqueToPower(torqueLoss, angularVelocity); diff --git a/VectoCore/Models/SimulationComponent/Impl/TimeBasedDrivingCycle.cs b/VectoCore/Models/SimulationComponent/Impl/TimeBasedDrivingCycle.cs index d0a74358fafb273557a041176e5b2251bb54e11c..212f545b5b9e0bdf3185d6e53f9807eb4d0249eb 100644 --- a/VectoCore/Models/SimulationComponent/Impl/TimeBasedDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/TimeBasedDrivingCycle.cs @@ -43,22 +43,22 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #region ISimulationOutPort - IResponse ISimulationOutPort.Request(TimeSpan absTime, Meter ds) + IResponse ISimulationOutPort.Request(Second absTime, Meter ds) { throw new NotImplementedException(); } - public IResponse Request(TimeSpan absTime, TimeSpan dt) + public IResponse Request(Second absTime, Second dt) { //todo: change to variable time steps - var index = (int)Math.Floor(absTime.TotalSeconds); + var index = (int)Math.Floor(absTime.Value()); if (index >= Data.Entries.Count) { return new ResponseCycleFinished(); } // TODO!! var dx = 0.SI<Meter>(); - return _outPort.Request(absTime, dx, Data.Entries[index].VehicleTargetSpeed, + return _outPort.Request((Second)absTime, dx, Data.Entries[index].VehicleTargetSpeed, Data.Entries[index].RoadGradient); } diff --git a/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs b/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs index ab2de0796d8735d0cac2aea15876b76e50c7d6b2..40d056871fe62dc20fc6ef7711e679004a5b8fc3 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs @@ -54,10 +54,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _currentState = new VehicleState(); } - public IResponse Request(TimeSpan absTime, TimeSpan dt, MeterPerSquareSecond accelleration, Radian gradient) + public IResponse Request(Second absTime, Second dt, MeterPerSquareSecond accelleration, Radian gradient) { - _currentState.Velocity = _previousState.Velocity + - (accelleration * (dt.TotalSeconds / 2.0).SI<Second>()).Cast<MeterPerSecond>(); + _currentState.Velocity = _previousState.Velocity + (accelleration * (dt / 2.0)).Cast<MeterPerSecond>(); // DriverAcceleration = vehicleAccelerationForce - RollingResistance - AirDragResistance - SlopeResistance var vehicleAccelerationForce = DriverAcceleration(accelleration) + RollingResistance(gradient) + diff --git a/VectoCore/Models/SimulationComponent/Impl/Wheels.cs b/VectoCore/Models/SimulationComponent/Impl/Wheels.cs index 5aa16543c08deb351762e4be4c01551e66c7b43f..1d998f4f69d14dd85aaf14a083ba760b5e20b58a 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Wheels.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Wheels.cs @@ -37,7 +37,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl #region IFvOutPort - IResponse IFvOutPort.Request(TimeSpan absTime, TimeSpan dt, Newton force, MeterPerSecond velocity) + IResponse IFvOutPort.Request(Second absTime, Second dt, Newton force, MeterPerSecond velocity) { var torque = force * _dynamicWheelRadius; var angularVelocity = velocity / _dynamicWheelRadius; diff --git a/VectoCoreTest/Integration/EngineOnlyCycle/EngineOnlyCycleTest.cs b/VectoCoreTest/Integration/EngineOnlyCycle/EngineOnlyCycleTest.cs index 96f73a4d2e9fc62fa83ff7ad713727c1d7e77d1f..5d1148a29280adcbb58e91339d0a24c1566287ba 100644 --- a/VectoCoreTest/Integration/EngineOnlyCycle/EngineOnlyCycleTest.cs +++ b/VectoCoreTest/Integration/EngineOnlyCycle/EngineOnlyCycleTest.cs @@ -41,8 +41,8 @@ namespace TUGraz.VectoCore.Tests.Integration.EngineOnlyCycle // IVectoJob job = SimulationFactory.CreateTimeBasedEngineOnlyRun(TestContext.DataRow["EngineFile"].ToString(), // TestContext.DataRow["CycleFile"].ToString(), "test2.csv"); - var absTime = new TimeSpan(seconds: 0, minutes: 0, hours: 0); - var dt = new TimeSpan(seconds: 1, minutes: 0, hours: 0); + var absTime = 0.SI<Second>(); + var dt = 1.SI<Second>(); var dataWriter = new TestModalDataWriter(); @@ -100,8 +100,8 @@ namespace TUGraz.VectoCore.Tests.Integration.EngineOnlyCycle gearbox.InPort().Connect(engine.OutPort()); - var absTime = new TimeSpan(); - var dt = TimeSpan.FromSeconds(1); + var absTime = 0.SI<Second>(); + var dt = 1.SI<Second>(); var angularVelocity = 644.4445.RPMtoRad(); var power = 2329.973.SI<Watt>(); diff --git a/VectoCoreTest/Models/Simulation/DrivingCycleTests.cs b/VectoCoreTest/Models/Simulation/DrivingCycleTests.cs index 31ba15de08dba48583fad26b1f3bf60c1e5465f5..25b0266dbd856c7f08be5f698dd62091495f8216 100644 --- a/VectoCoreTest/Models/Simulation/DrivingCycleTests.cs +++ b/VectoCoreTest/Models/Simulation/DrivingCycleTests.cs @@ -28,14 +28,14 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation inPort.Connect(outPort); - var absTime = new TimeSpan(); - var dt = TimeSpan.FromSeconds(1); + var absTime = 0.SI<Second>(); + var dt = 1.SI<Second>(); var response = cycleOut.Request(absTime, dt); Assert.IsInstanceOfType(response, typeof(ResponseSuccess)); - var time = (absTime + TimeSpan.FromTicks(dt.Ticks / 2)).TotalSeconds; - var simulationInterval = dt.TotalSeconds; + var time = absTime + dt / 2; + var simulationInterval = dt; container.CommitSimulationStep(time, simulationInterval); Assert.AreEqual(absTime, outPort.AbsTime); @@ -57,18 +57,18 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation inPort.Connect(outPort); - var absTime = TimeSpan.FromSeconds(10); - var dt = TimeSpan.FromSeconds(1); + var absTime = 10.SI<Second>(); + var dt = 1.SI<Second>(); var response = cycle.OutPort().Request(absTime, dt); Assert.IsInstanceOfType(response, typeof(ResponseFailTimeInterval)); - dt = TimeSpan.FromSeconds(0.25); + dt = 0.25.SI<Second>(); response = cycle.OutPort().Request(absTime, dt); Assert.IsInstanceOfType(response, typeof(ResponseSuccess)); var dataWriter = new TestModalDataWriter(); - container.CommitSimulationStep(absTime.TotalSeconds, dt.TotalSeconds); + container.CommitSimulationStep(absTime, dt); Assert.AreEqual(absTime, outPort.AbsTime); Assert.AreEqual(dt, outPort.Dt); @@ -77,19 +77,19 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation // ======================== - dt = TimeSpan.FromSeconds(1); - absTime = TimeSpan.FromSeconds(500); - response = cycle.OutPort().Request(absTime, dt); + dt = 1.SI<Second>(); + absTime = 500.SI<Second>(); + response = cycle.OutPort().Request((Second)absTime, (Second)dt); Assert.IsInstanceOfType(response, typeof(ResponseFailTimeInterval)); - dt = TimeSpan.FromSeconds(0.25); + dt = 0.25.SI<Second>(); for (int i = 0; i < 2; i++) { - response = cycle.OutPort().Request(absTime, dt); + response = cycle.OutPort().Request((Second)absTime, (Second)dt); Assert.IsInstanceOfType(response, typeof(ResponseSuccess)); dataWriter = new TestModalDataWriter(); - container.CommitSimulationStep(absTime.TotalSeconds, dt.TotalSeconds); + container.CommitSimulationStep(absTime, dt); Assert.AreEqual(absTime, outPort.AbsTime); Assert.AreEqual(dt, outPort.Dt); @@ -118,8 +118,8 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation inPort.Connect(outPort); - var absTime = new TimeSpan(); - var dt = TimeSpan.FromSeconds(1); + var absTime = 0.SI<Second>(); + var dt = 1.SI<Second>(); var response = cycleOut.Request(absTime, dt); Assert.IsInstanceOfType(response, typeof(ResponseSuccess)); @@ -146,15 +146,15 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation inPort.Connect(outPort); var dataWriter = new TestModalDataWriter(); - var absTime = new TimeSpan(); - var dt = TimeSpan.FromSeconds(1); + var absTime = 0.SI<Second>(); + var dt = 1.SI<Second>(); while (cycleOut.Request(absTime, dt) is ResponseSuccess) { Assert.AreEqual(absTime, outPort.AbsTime); Assert.AreEqual(dt, outPort.Ds); - var time = (absTime + TimeSpan.FromTicks(dt.Ticks / 2)).TotalSeconds; - var simulationInterval = dt.TotalSeconds; + var time = absTime + dt / 2; + var simulationInterval = dt; container.CommitSimulationStep(time, simulationInterval); absTime += dt; diff --git a/VectoCoreTest/Models/SimulationComponent/ClutchTest.cs b/VectoCoreTest/Models/SimulationComponent/ClutchTest.cs index 0d928530059fc860de382f2ce1d9b0eba283a659..964f96cb773f009669d72aee19fc35d63513c479 100644 --- a/VectoCoreTest/Models/SimulationComponent/ClutchTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/ClutchTest.cs @@ -33,21 +33,21 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent //Test - Clutch slipping gearbox.CurrentGear = 1; - clutchOutPort.Request(new TimeSpan(), new TimeSpan(), 100.SI<NewtonMeter>(), 30.SI<PerSecond>()); + clutchOutPort.Request(0.SI<Second>(), 0.SI<Second>(), 100.SI<NewtonMeter>(), 30.SI<PerSecond>()); Assert.AreEqual(48.293649, (double)outPort.Torque, 0.001); Assert.AreEqual(62.119969, (double)outPort.AngularVelocity, 0.001); //Test - Clutch opened gearbox.CurrentGear = 0; - clutchOutPort.Request(new TimeSpan(), new TimeSpan(), 100.SI<NewtonMeter>(), 30.SI<PerSecond>()); + clutchOutPort.Request(0.SI<Second>(), 0.SI<Second>(), 100.SI<NewtonMeter>(), 30.SI<PerSecond>()); Assert.AreEqual(0, (double)outPort.Torque, 0.001); Assert.AreEqual((double)engineData.IdleSpeed, (double)outPort.AngularVelocity, 0.001); //Test - Clutch closed gearbox.CurrentGear = 1; - clutchOutPort.Request(new TimeSpan(), new TimeSpan(), 100.SI<NewtonMeter>(), 80.SI<PerSecond>()); + clutchOutPort.Request(0.SI<Second>(), 0.SI<Second>(), 100.SI<NewtonMeter>(), 80.SI<PerSecond>()); Assert.AreEqual(100.0, (double)outPort.Torque, 0.001); Assert.AreEqual(80.0, (double)outPort.AngularVelocity, 0.001); diff --git a/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs b/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs index 769647c0e1558768079ca4fa3c266aedd464d04a..59edcaf7f454834c2d1e4d9de0bc66d83a8ea26e 100644 --- a/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs @@ -66,8 +66,8 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var port = engine.OutPort(); - var absTime = new TimeSpan(seconds: 0, minutes: 0, hours: 0); - var dt = new TimeSpan(seconds: 1, minutes: 0, hours: 0); + var absTime = 0.SI<Second>(); + var dt = 1.SI<Second>(); var torque = 400.SI<NewtonMeter>(); var engineSpeed = 1500.RPMtoRad(); @@ -83,8 +83,8 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var gearbox = new EngineOnlyGearbox(vehicle); var port = engine.OutPort(); - var absTime = new TimeSpan(seconds: 0, minutes: 0, hours: 0); - var dt = new TimeSpan(seconds: 1, minutes: 0, hours: 0); + var absTime = 0.SI<Second>(); + var dt = 1.SI<Second>(); var torque = 0.SI<NewtonMeter>(); var engineSpeed = 600.RPMtoRad(); @@ -163,10 +163,10 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var angularSpeed = Double.Parse(TestContext.DataRow["rpm"].ToString()).RPMtoRad(); - var t = TimeSpan.FromSeconds(0); - var dt = TimeSpan.FromSeconds(0.1); + var t = 0.SI<Second>(); + var dt = 0.1.SI<Second>(); - for (; t.TotalSeconds < 2; t += dt) { + for (; t < 2; t += dt) { requestPort.Request(t, dt, Formulas.PowerToTorque(idlePower, angularSpeed), angularSpeed); engine.CommitSimulationStep(modalData); } @@ -176,17 +176,17 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent // dt = TimeSpan.FromSeconds(expectedResults.Rows[i].ParseDouble(0)) - t; var engineLoadPower = engineData.GetFullLoadCurve(0).FullLoadStationaryPower(angularSpeed); idlePower = Double.Parse(TestContext.DataRow["finalIdleLoad"].ToString()).SI<Watt>(); - for (; t.TotalSeconds < 25; t += dt, i++) { - dt = TimeSpan.FromSeconds(expectedResults.Rows[i + 1].ParseDouble(0) - expectedResults.Rows[i].ParseDouble(0)); - if (t >= TimeSpan.FromSeconds(10)) { + for (; t < 25; t += dt, i++) { + dt = (expectedResults.Rows[i + 1].ParseDouble(0) - expectedResults.Rows[i].ParseDouble(0)).SI<Second>(); + if (t >= 10.SI<Second>()) { engineLoadPower = idlePower; } requestPort.Request(t, dt, Formulas.PowerToTorque(engineLoadPower, angularSpeed), angularSpeed); - modalData[ModalResultField.time] = t.TotalSeconds; - modalData[ModalResultField.simulationInterval] = dt.TotalSeconds; + modalData[ModalResultField.time] = t.Value(); + modalData[ModalResultField.simulationInterval] = dt.Value(); engine.CommitSimulationStep(modalData); // todo: compare results... - Assert.AreEqual(expectedResults.Rows[i].ParseDouble(0), t.TotalSeconds, 0.001, "Time"); + Assert.AreEqual(expectedResults.Rows[i].ParseDouble(0), t.Value(), 0.001, "Time"); Assert.AreEqual(expectedResults.Rows[i].ParseDouble(1), modalData.GetDouble(ModalResultField.Pe_full), 0.1, String.Format("Load in timestep {0}", t)); modalData.CommitSimulationStep(); diff --git a/VectoCoreTest/Models/SimulationComponent/DistanceBasedDrivingCycleTest.cs b/VectoCoreTest/Models/SimulationComponent/DistanceBasedDrivingCycleTest.cs index 4903148bb5a74f37d183867d31ad1c76b5a7016b..e6185d855d03df7d8f7d3bb9e175a8389318c1bb 100644 --- a/VectoCoreTest/Models/SimulationComponent/DistanceBasedDrivingCycleTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/DistanceBasedDrivingCycleTest.cs @@ -33,20 +33,20 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent cycle.OutPort().Initialize(); var startDistance = cycleData.Entries.First().Distance.Value(); - var absTime = TimeSpan.FromSeconds(0); + var absTime = 0.SI<Second>(); var response = cycle.OutPort().Request(absTime, 1.SI<Meter>()); Assert.IsInstanceOfType(response, typeof(ResponseSuccess)); Assert.AreEqual(0, driver.LastRequest.TargetVelocity.Value(), Tolerance); Assert.AreEqual(0.028416069495827, driver.LastRequest.Gradient.Value(), 1E-12); - Assert.AreEqual(40, driver.LastRequest.dt.TotalSeconds, Tolerance); + Assert.AreEqual(40, driver.LastRequest.dt.Value(), Tolerance); - vehicleContainer.CommitSimulationStep(absTime.TotalSeconds, response.SimulationInterval.TotalSeconds); + vehicleContainer.CommitSimulationStep(absTime, response.SimulationInterval); absTime += response.SimulationInterval; - response = cycle.OutPort().Request(absTime, 1.SI<Meter>()); + response = cycle.OutPort().Request((Second)absTime, 1.SI<Meter>()); Assert.IsInstanceOfType(response, typeof(ResponseSuccess)); @@ -54,11 +54,11 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent Assert.AreEqual(0.02667562971628240, driver.LastRequest.Gradient.Value(), 1E-12); Assert.AreEqual(1 + startDistance, cycle.CurrentState.Distance.Value(), Tolerance); - vehicleContainer.CommitSimulationStep(absTime.TotalSeconds, response.SimulationInterval.TotalSeconds); + vehicleContainer.CommitSimulationStep(absTime, response.SimulationInterval); absTime += response.SimulationInterval; - response = cycle.OutPort().Request(absTime, 1.SI<Meter>()); + response = cycle.OutPort().Request((Second)absTime, 1.SI<Meter>()); Assert.IsInstanceOfType(response, typeof(ResponseSuccess)); @@ -66,11 +66,11 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent Assert.AreEqual(0.02667562971628240, driver.LastRequest.Gradient.Value(), 1E-12); Assert.AreEqual(2 + startDistance, cycle.CurrentState.Distance.Value(), Tolerance); - vehicleContainer.CommitSimulationStep(absTime.TotalSeconds, response.SimulationInterval.TotalSeconds); + vehicleContainer.CommitSimulationStep(absTime, response.SimulationInterval); absTime += response.SimulationInterval; - response = cycle.OutPort().Request(absTime, 300.SI<Meter>()); + response = cycle.OutPort().Request((Second)absTime, 300.SI<Meter>()); Assert.IsInstanceOfType(response, typeof(ResponseDrivingCycleDistanceExceeded)); var tmp = response as ResponseDrivingCycleDistanceExceeded; @@ -81,20 +81,20 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent Assert.AreEqual(2 + startDistance, cycle.CurrentState.Distance.Value(), Tolerance); try { - vehicleContainer.CommitSimulationStep(absTime.TotalSeconds, response.SimulationInterval.TotalSeconds); + vehicleContainer.CommitSimulationStep(absTime, response.SimulationInterval); absTime += response.SimulationInterval; Assert.Fail(); } catch (VectoSimulationException e) { Assert.AreEqual("Previous request did not succeed!", e.Message); } - response = cycle.OutPort().Request(absTime, tmp.MaxDistance); + response = cycle.OutPort().Request((Second)absTime, tmp.MaxDistance); Assert.AreEqual(5.SI<MeterPerSecond>().Value(), driver.LastRequest.TargetVelocity.Value(), Tolerance); Assert.AreEqual(0.02667562971628240, driver.LastRequest.Gradient.Value(), 1E-12); Assert.AreEqual(38 + startDistance, cycle.CurrentState.Distance.Value(), Tolerance); - vehicleContainer.CommitSimulationStep(absTime.TotalSeconds, response.SimulationInterval.TotalSeconds); + vehicleContainer.CommitSimulationStep(absTime, response.SimulationInterval); absTime += response.SimulationInterval; } } diff --git a/VectoCoreTest/Models/SimulationComponent/DriverTest.cs b/VectoCoreTest/Models/SimulationComponent/DriverTest.cs index 882212f1fbcd5df6898dfd30aef17f6d318f4e75..03f979aecd61dd196a34d1288a7f15bd65b94934 100644 --- a/VectoCoreTest/Models/SimulationComponent/DriverTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/DriverTest.cs @@ -28,7 +28,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent driver.Connect(vehicle.OutPort()); vehicle.MyVehicleSpeed = 0.SI<MeterPerSecond>(); - var absTime = TimeSpan.FromSeconds(0); + var absTime = 0.SI<Second>(); var ds = 1.SI<Meter>(); var gradient = 0.SI<Radian>(); @@ -50,25 +50,24 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent Assert.IsInstanceOfType(tmpResponse, typeof(ResponseSuccess)); Assert.AreEqual(Math.Round(accelerations[i], 4), vehicle.LastRequest.acceleration.Value(), Tolerance); - Assert.AreEqual(Math.Round(simulationIntervals[i], 4), tmpResponse.SimulationInterval.TotalSeconds, Tolerance); + Assert.AreEqual(Math.Round(simulationIntervals[i], 4), tmpResponse.SimulationInterval.Value(), Tolerance); - vehicleContainer.CommitSimulationStep(absTime.TotalSeconds, tmpResponse.SimulationInterval.TotalSeconds); + vehicleContainer.CommitSimulationStep(absTime, tmpResponse.SimulationInterval); absTime += tmpResponse.SimulationInterval; - vehicle.MyVehicleSpeed += - (tmpResponse.SimulationInterval.TotalSeconds.SI<Second>() * vehicle.LastRequest.acceleration).Cast<MeterPerSecond>(); + vehicle.MyVehicleSpeed += (tmpResponse.SimulationInterval * vehicle.LastRequest.acceleration).Cast<MeterPerSecond>(); } // full acceleration would exceed target velocity, driver should limit acceleration such that target velocity is reached... var response = driver.OutPort().Request(absTime, ds, targetVelocity, gradient); Assert.IsInstanceOfType(response, typeof(ResponseSuccess)); - Assert.AreEqual(0.8923 /*0.899715479*/, vehicle.LastRequest.acceleration.Value(), Tolerance); - Assert.AreEqual(0.203734517, response.SimulationInterval.TotalSeconds, Tolerance); + Assert.AreEqual(0.899715479, vehicle.LastRequest.acceleration.Value(), Tolerance); + Assert.AreEqual(0.203734517, response.SimulationInterval.Value(), Tolerance); - vehicleContainer.CommitSimulationStep(absTime.TotalSeconds, response.SimulationInterval.TotalSeconds); + vehicleContainer.CommitSimulationStep(absTime, response.SimulationInterval); absTime += response.SimulationInterval; vehicle.MyVehicleSpeed += - (response.SimulationInterval.TotalSeconds.SI<Second>() * vehicle.LastRequest.acceleration).Cast<MeterPerSecond>(); + (response.SimulationInterval * vehicle.LastRequest.acceleration).Cast<MeterPerSecond>(); Assert.AreEqual(targetVelocity.Value(), vehicle.MyVehicleSpeed.Value(), Tolerance); @@ -79,7 +78,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent Assert.IsInstanceOfType(response, typeof(ResponseSuccess)); Assert.AreEqual(0, vehicle.LastRequest.acceleration.Value(), Tolerance); - Assert.AreEqual(0.2, response.SimulationInterval.TotalSeconds, Tolerance); + Assert.AreEqual(0.2, response.SimulationInterval.Value(), Tolerance); } } } \ No newline at end of file diff --git a/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs b/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs index 77db5e33089ef5997947a8f4a5818894c5e2e50e..1b93b951bb9d547e7710916af0cc0bba576bc661 100644 --- a/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs @@ -27,8 +27,8 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var mockPort = new MockTnOutPort(); axleGear.InPort().Connect(mockPort); - var absTime = TimeSpan.FromSeconds(0); - var dt = TimeSpan.FromSeconds(1); + var absTime = 0.SI<Second>(); + var dt = 1.SI<Second>(); var rdyn = 520; var speed = 20.320; diff --git a/VectoCoreTest/Models/SimulationComponent/RetarderTest.cs b/VectoCoreTest/Models/SimulationComponent/RetarderTest.cs index 522ff647526cf2f99e7b67c5ae117684d11674b6..0adcb3e64171a6bb6b1e1e11225d96c4c8894c8d 100644 --- a/VectoCoreTest/Models/SimulationComponent/RetarderTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/RetarderTest.cs @@ -26,8 +26,8 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent retarder.InPort().Connect(nextRequest); var outPort = retarder.OutPort(); - var absTime = TimeSpan.FromSeconds(0); - var dt = TimeSpan.FromSeconds(0); + var absTime = 0.SI<Second>(); + var dt = 0.SI<Second>(); // -------- outPort.Request(absTime, dt, 0.SI<NewtonMeter>(), 10.RPMtoRad()); diff --git a/VectoCoreTest/Models/SimulationComponent/VehicleTest.cs b/VectoCoreTest/Models/SimulationComponent/VehicleTest.cs index 2b26d8a344d09d64bf3c4d8d6009143963b5525f..b046f240518a452273cee0b9de8d299cc3a21684 100644 --- a/VectoCoreTest/Models/SimulationComponent/VehicleTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/VehicleTest.cs @@ -30,8 +30,8 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var requestPort = vehicle.OutPort(); - var absTime = TimeSpan.FromSeconds(0); - var dt = TimeSpan.FromSeconds(1); + var absTime = 0.SI<Second>(); + var dt = 1.SI<Second>(); var accell = -0.256231159.SI<MeterPerSquareSecond>(); var gradient = Math.Atan(0.00366547048).SI<Radian>(); diff --git a/VectoCoreTest/Models/SimulationComponent/WheelsTest.cs b/VectoCoreTest/Models/SimulationComponent/WheelsTest.cs index e599f1691278fb82adcc2ac7b2d75f4b73edeebb..b5176c1f8835c2785d19aeb799aa20564373f3d8 100644 --- a/VectoCoreTest/Models/SimulationComponent/WheelsTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/WheelsTest.cs @@ -28,8 +28,8 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var requestPort = wheels.OutPort(); - var absTime = TimeSpan.FromSeconds(0); - var dt = TimeSpan.FromSeconds(1); + var absTime = 0.SI<Second>(); + var dt = 1.SI<Second>(); var force = 5000.SI<Newton>(); var velocity = 20.SI<MeterPerSecond>(); diff --git a/VectoCoreTest/Utils/DummyGearbox.cs b/VectoCoreTest/Utils/DummyGearbox.cs index 89e5c47c63e22724f05aef3bb4cbb6bd0729181a..cdd3e105bc0f2f463742521c98404f0283657667 100644 --- a/VectoCoreTest/Utils/DummyGearbox.cs +++ b/VectoCoreTest/Utils/DummyGearbox.cs @@ -35,7 +35,7 @@ namespace TUGraz.VectoCore.Tests.Utils _outPort = other; } - public IResponse Request(TimeSpan absTime, TimeSpan dt, NewtonMeter torque, PerSecond engineSpeed) + public IResponse Request(Second absTime, Second dt, NewtonMeter torque, PerSecond engineSpeed) { throw new NotImplementedException(); } diff --git a/VectoCoreTest/Utils/MockDriver.cs b/VectoCoreTest/Utils/MockDriver.cs index 4077d31095938640bc67dccba0eab0bff7cba6a3..26d22e38499ecee4d745103bd6ecf1708e9f7f80 100644 --- a/VectoCoreTest/Utils/MockDriver.cs +++ b/VectoCoreTest/Utils/MockDriver.cs @@ -34,19 +34,20 @@ namespace TUGraz.VectoCore.Tests.Utils return this; } - public IResponse Request(TimeSpan absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient) + public IResponse Request(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient) { LastRequest = new RequestData() { AbsTime = absTime, ds = ds, Gradient = gradient, TargetVelocity = targetVelocity }; var acc = 0.SI<MeterPerSquareSecond>(); - var dt = TimeSpan.FromSeconds(1); - return new ResponseSuccess() {SimulationInterval = dt}; //_next.Request(absTime, TimeSpan.FromSeconds(0), acc, 0.SI<Radian>()); + var dt = 1.SI<Second>(); + return new ResponseSuccess() { SimulationInterval = dt }; + //_next.Request(absTime, TimeSpan.FromSeconds(0), acc, 0.SI<Radian>()); } - public IResponse Request(TimeSpan absTime, TimeSpan dt, MeterPerSecond targetVelocity, Radian gradient) + public IResponse Request(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient) { LastRequest = new RequestData() { AbsTime = absTime, dt = dt, Gradient = gradient, TargetVelocity = targetVelocity }; var acc = 0.SI<MeterPerSquareSecond>(); - return new ResponseSuccess() {SimulationInterval = dt}; //_next.Request(absTime, dt, acc, gradient); + return new ResponseSuccess() { SimulationInterval = dt }; //_next.Request(absTime, dt, acc, gradient); } public void Connect(IDriverDemandOutPort other) @@ -56,9 +57,9 @@ namespace TUGraz.VectoCore.Tests.Utils public class RequestData { - public TimeSpan AbsTime; + public Second AbsTime; public Meter ds; - public TimeSpan dt; + public Second dt; public MeterPerSecond TargetVelocity; public Radian Gradient; } diff --git a/VectoCoreTest/Utils/MockPorts.cs b/VectoCoreTest/Utils/MockPorts.cs index a960a9f1402a34973135f81b05ad36b25f92c430..ea50b025d8b53ed208c63b53fb4893533ba0e934 100644 --- a/VectoCoreTest/Utils/MockPorts.cs +++ b/VectoCoreTest/Utils/MockPorts.cs @@ -8,12 +8,12 @@ namespace TUGraz.VectoCore.Tests.Utils { public class MockTnOutPort : ITnOutPort { - public TimeSpan AbsTime { get; set; } - public TimeSpan Dt { get; set; } + public Second AbsTime { get; set; } + public Second Dt { get; set; } public NewtonMeter Torque { get; set; } public PerSecond AngularVelocity { get; set; } - public IResponse Request(TimeSpan absTime, TimeSpan dt, NewtonMeter torque, PerSecond angularVelocity) + public IResponse Request(Second absTime, Second dt, NewtonMeter torque, PerSecond angularVelocity) { AbsTime = absTime; Dt = dt; @@ -27,14 +27,14 @@ namespace TUGraz.VectoCore.Tests.Utils public class MockDrivingCycleOutPort : IDrivingCycleOutPort { - public TimeSpan AbsTime { get; set; } + public Second AbsTime { get; set; } public Meter Ds { get; set; } - public TimeSpan Dt { get; set; } + public Second Dt { get; set; } public MeterPerSecond Velocity { get; set; } public Radian Gradient { get; set; } - public IResponse Request(TimeSpan absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient) + public IResponse Request(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient) { AbsTime = absTime; Ds = ds; @@ -45,7 +45,7 @@ namespace TUGraz.VectoCore.Tests.Utils return new ResponseSuccess(); } - public IResponse Request(TimeSpan absTime, TimeSpan dt, MeterPerSecond targetVelocity, Radian gradient) + public IResponse Request(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient) { AbsTime = absTime; Dt = dt; @@ -59,13 +59,13 @@ namespace TUGraz.VectoCore.Tests.Utils public class MockFvOutPort : IFvOutPort { - public TimeSpan AbsTime { get; set; } - public TimeSpan Dt { get; set; } + public Second AbsTime { get; set; } + public Second Dt { get; set; } public Newton Force { get; set; } public MeterPerSecond Velocity { get; set; } - public IResponse Request(TimeSpan absTime, TimeSpan dt, Newton force, MeterPerSecond velocity) + public IResponse Request(Second absTime, Second dt, Newton force, MeterPerSecond velocity) { AbsTime = absTime; Dt = dt; diff --git a/VectoCoreTest/Utils/MockVehicle.cs b/VectoCoreTest/Utils/MockVehicle.cs index c0c5c6f6cf7f57a8578e785a02e24d9622ce39de..c49232b881b01a96b65a9df7839f90ed7874c132 100644 --- a/VectoCoreTest/Utils/MockVehicle.cs +++ b/VectoCoreTest/Utils/MockVehicle.cs @@ -55,7 +55,7 @@ namespace TUGraz.VectoCore.Tests.Utils NextComponent = other; } - public IResponse Request(TimeSpan absTime, TimeSpan dt, MeterPerSquareSecond acceleration, Radian gradient) + public IResponse Request(Second absTime, Second dt, MeterPerSquareSecond acceleration, Radian gradient) { LastRequest = new RequestData() { abstime = absTime, @@ -68,8 +68,8 @@ namespace TUGraz.VectoCore.Tests.Utils public class RequestData { - public TimeSpan abstime; - public TimeSpan dt; + public Second abstime; + public Second dt; public MeterPerSquareSecond acceleration; public Radian gradient; } diff --git a/VectoCoreTest/Utils/TestModalDataWriter.cs b/VectoCoreTest/Utils/TestModalDataWriter.cs index a9e4d8ccc6f0de77b9b61d9e2889ce1886b54c78..a4805e878c9e3544d6b2e2850057c0063d556108 100644 --- a/VectoCoreTest/Utils/TestModalDataWriter.cs +++ b/VectoCoreTest/Utils/TestModalDataWriter.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Tests.Utils { @@ -46,11 +47,10 @@ namespace TUGraz.VectoCore.Tests.Utils set { CurrentRow[key.GetName()] = value; } } - public void CommitSimulationStep(TimeSpan absTime, TimeSpan simulationInterval) + public void CommitSimulationStep(Second absTime, Second simulationInterval) { - CurrentRow[ModalResultField.time.GetName()] = - (absTime + TimeSpan.FromTicks(simulationInterval.Ticks / 2)).TotalSeconds; - CurrentRow[ModalResultField.simulationInterval.GetName()] = simulationInterval.TotalSeconds; + CurrentRow[ModalResultField.time.GetName()] = (absTime + simulationInterval / 2).Value(); + CurrentRow[ModalResultField.simulationInterval.GetName()] = simulationInterval.Value(); CommitSimulationStep(); }