diff --git a/VectoCore/Models/SimulationComponent/Data/AuxiliariesDemandAdapter.cs b/VectoCore/Models/SimulationComponent/Data/AuxiliariesDemandAdapter.cs index 87b5ae473213559bcf6cf9888255e06868307bae..e4933fddb28c0a6d7e2b4941e1b92f07c328de6b 100644 --- a/VectoCore/Models/SimulationComponent/Data/AuxiliariesDemandAdapter.cs +++ b/VectoCore/Models/SimulationComponent/Data/AuxiliariesDemandAdapter.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Security.Cryptography.X509Certificates; using Common.Logging; using TUGraz.VectoCore.Exceptions; +using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Data { @@ -24,15 +25,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data } } - public double GetPowerDemand(TimeSpan absTime, TimeSpan dt) + public Watt GetPowerDemand(TimeSpan absTime, TimeSpan dt) { - var entry = _drivingCycle.Entries.FindIndex(x => x.Time > absTime.TotalSeconds); + var entry = _drivingCycle.Entries.FindLastIndex(x => x.Time <= absTime.TotalSeconds); //if (entry == null) { // Log.ErrorFormat("could not find entry in driving cycle for time {0}", absTime.TotalSeconds); // return 0; //} Log.ErrorFormat("Found Entry at index {0}", entry); - return _auxiliaryId == null ? _drivingCycle.Entries[entry].AdditionalAuxPowerDemand * 1000 : _drivingCycle.Entries[entry].AuxiliarySupplyPower[_auxiliaryId] * 1000; + return _auxiliaryId == null ? _drivingCycle.Entries[entry].AdditionalAuxPowerDemand : _drivingCycle.Entries[entry].AuxiliarySupplyPower[_auxiliaryId]; } } diff --git a/VectoCore/Models/SimulationComponent/Data/DrivingCycleData.cs b/VectoCore/Models/SimulationComponent/Data/DrivingCycleData.cs index 0a7fe2db96852e3543735f383cb0fd34092412e8..277a38b10817e9243cee2232d7257b1db731c318 100644 --- a/VectoCore/Models/SimulationComponent/Data/DrivingCycleData.cs +++ b/VectoCore/Models/SimulationComponent/Data/DrivingCycleData.cs @@ -122,7 +122,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data /// Auxiliary. ID's are not case sensitive and must not contain /// space or special characters. /// </summary> - public Dictionary<string, double> AuxiliarySupplyPower { get; set; } + public Dictionary<string, Watt> AuxiliarySupplyPower { get; set; } /// <summary> /// [rad/s] If "n" is defined VECTO uses that instead of the @@ -223,12 +223,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data /// <summary> /// [W]. Reads Auxiliary Supply Power (defined by Fields.AuxiliarySupplyPower-Prefix). /// </summary> - public static Dictionary<string, double> Read(DataRow row) + public static Dictionary<string, Watt> Read(DataRow row) { return row.Table.Columns.Cast<DataColumn>(). Where(col => col.ColumnName.StartsWith(Fields.AuxiliarySupplyPower)). ToDictionary(col => col.ColumnName.Substring(Fields.AuxiliarySupplyPower.Length - 1), - col => (double)row.ParseDouble(col).SI().Kilo.Watt); + col => row.ParseDouble(col).SI().Kilo.Watt.To<Watt>()); } } @@ -366,6 +366,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data public IEnumerable<DrivingCycleEntry> Parse(DataTable table) { ValidateHeader(table.Columns.Cast<DataColumn>().Select(col => col.ColumnName).ToArray()); + TimeSpan absTime = new TimeSpan(hours: 0, minutes:0, seconds: 0); foreach (DataRow row in table.Rows) { @@ -390,6 +391,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data entry.EngineTorque = Formulas.PowerToTorque(row.ParseDouble(Fields.EnginePower).SI().Kilo.Watt.To<Watt>(), entry.EngineSpeed); } + entry.Time = absTime.TotalSeconds; + absTime += new TimeSpan(hours: 0, minutes: 0, seconds: 1); + yield return entry; } } diff --git a/VectoCore/Models/SimulationComponent/Impl/EngineOnlyAuxiliary.cs b/VectoCore/Models/SimulationComponent/Impl/EngineOnlyAuxiliary.cs index 9c699ce448b03d1e8162e6db4912ab4189746426..4d550f39eb6f6144e0f845a28beff8c7ba452b6a 100644 --- a/VectoCore/Models/SimulationComponent/Impl/EngineOnlyAuxiliary.cs +++ b/VectoCore/Models/SimulationComponent/Impl/EngineOnlyAuxiliary.cs @@ -12,7 +12,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { private ITnOutPort _outPort; private AuxiliariesDemandAdapter _demand; - private double _powerDemand; + private Watt _powerDemand; public EngineOnlyAuxiliary(IVehicleContainer container, AuxiliariesDemandAdapter demand) : base(container) @@ -35,7 +35,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _outPort = other; } - public void Request(TimeSpan absTime, TimeSpan dt, double torque, double engineSpeed) + public void Request(TimeSpan absTime, TimeSpan dt, NewtonMeter torque, RadianPerSecond engineSpeed) { if (_outPort == null) { @@ -43,13 +43,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl throw new VectoSimulationException(String.Format("{0} cannot handle incoming request - no outport available", absTime.TotalSeconds)); } _powerDemand = _demand.GetPowerDemand(absTime, dt); - var tq = VectoMath.ConvertPowerRpmToTorque(_powerDemand, engineSpeed); - _outPort.Request(absTime, dt, torque + tq, engineSpeed); + var tq = Formulas.PowerToTorque(_powerDemand, engineSpeed); + _outPort.Request(absTime, dt, (torque + tq).To<NewtonMeter>(), engineSpeed); } public override void CommitSimulationStep(IModalDataWriter writer) { - writer[ModalResultField.Paux] = _powerDemand; + writer[ModalResultField.Paux] = (double)_powerDemand; } } } \ No newline at end of file diff --git a/VectoCoreTest/Utils/TestModalDataWriter.cs b/VectoCoreTest/Utils/TestModalDataWriter.cs index 2f1edf2a3ed2952fabff8b8b9a17f3bb2c841249..4c88770ec8a85c842e6293c3c4a0236ba4ad221b 100644 --- a/VectoCoreTest/Utils/TestModalDataWriter.cs +++ b/VectoCoreTest/Utils/TestModalDataWriter.cs @@ -27,7 +27,7 @@ namespace TUGraz.VectoCore.Tests.Utils public void CommitSimulationStep(TimeSpan absTime, TimeSpan simulationInterval) { - CurrentRow[ModalResultField.time.GetName()] = (absTime - TimeSpan.FromTicks(simulationInterval.Ticks / 2)).TotalSeconds; + CurrentRow[ModalResultField.time.GetName()] = (absTime + TimeSpan.FromTicks(simulationInterval.Ticks / 2)).TotalSeconds; CurrentRow[ModalResultField.simulationInterval.GetName()] = simulationInterval.TotalSeconds; CommitSimulationStep(); }