diff --git a/VectoCore/Models/Simulation/Data/ModalDataWriter.cs b/VectoCore/Models/Simulation/Data/ModalDataWriter.cs index 1bf238d03dae259d7c53755e838e89b1053e09fd..91062a3c768f3b87b340f8e9be0403812be272c4 100644 --- a/VectoCore/Models/Simulation/Data/ModalDataWriter.cs +++ b/VectoCore/Models/Simulation/Data/ModalDataWriter.cs @@ -31,8 +31,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Data public object this[ModalResultField key] { - get { return CurrentRow[key.GetName()]; } - set { CurrentRow[key.GetName()] = value; } + get { return CurrentRow[(int)key]; } + set { CurrentRow[(int)key] = value; } } } } \ No newline at end of file diff --git a/VectoCore/Models/SimulationComponent/Data/AuxiliariesDemandAdapter.cs b/VectoCore/Models/SimulationComponent/Data/AuxiliariesDemandAdapter.cs index 308719bfae171d9fb84c07db65ed7e53d3963946..e529511241ab74124aea69c7f31b1195e20ea820 100644 --- a/VectoCore/Models/SimulationComponent/Data/AuxiliariesDemandAdapter.cs +++ b/VectoCore/Models/SimulationComponent/Data/AuxiliariesDemandAdapter.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Security.Cryptography.X509Certificates; using Common.Logging; @@ -10,14 +11,21 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data public class AuxiliariesDemandAdapter { private readonly DrivingCycleData _drivingCycle; + private IEnumerator<DrivingCycleData.DrivingCycleEntry> _nextCycleEntry; private readonly string _auxiliaryId; + protected DrivingCycleData.DrivingCycleEntry CurrentCycleEntry { get; set; } + //protected DrivingCycleData.DrivingCycleEntry NextCycleEntry { get { return _nextCycleEntry.Current; } } + private ILog Log; public AuxiliariesDemandAdapter(DrivingCycleData inputData, string column = null) { Log = LogManager.GetLogger(this.GetType()); _drivingCycle = inputData; + _nextCycleEntry = _drivingCycle.Entries.GetEnumerator(); + _nextCycleEntry.MoveNext(); + CurrentCycleEntry = _drivingCycle.Entries.First(); _auxiliaryId = column; if (_auxiliaryId != null && !_drivingCycle.Entries.First().AuxiliarySupplyPower.ContainsKey(_auxiliaryId)) { Log.ErrorFormat("driving cycle data does not contain column {0}", column); @@ -27,16 +35,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data public Watt GetPowerDemand(TimeSpan absTime, TimeSpan dt) { - 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; - //} - if (entry == -1) { - Log.ErrorFormat("time: {0} could not find power demand for auxiliary {1}", absTime.TotalSeconds, _auxiliaryId); - throw new VectoSimulationException(String.Format("time: {0} could not find power demand for auxiliary {1}", absTime.TotalSeconds, _auxiliaryId)); + if (_nextCycleEntry.Current.Time <= absTime.TotalSeconds) { + CurrentCycleEntry = _nextCycleEntry.Current; + _nextCycleEntry.MoveNext(); } - return _auxiliaryId == null ? _drivingCycle.Entries[entry].AdditionalAuxPowerDemand : _drivingCycle.Entries[entry].AuxiliarySupplyPower[_auxiliaryId]; + return String.IsNullOrEmpty(_auxiliaryId) ? CurrentCycleEntry.AdditionalAuxPowerDemand : CurrentCycleEntry.AuxiliarySupplyPower[_auxiliaryId]; } } diff --git a/VectoCore/Models/SimulationComponent/Data/CombustionEngineData.cs b/VectoCore/Models/SimulationComponent/Data/CombustionEngineData.cs index c2f521590c0a5705a56154bb08209aa4ddafb314..42e3d3b31f267508b9bc5954a448419b0c3715ad 100644 --- a/VectoCore/Models/SimulationComponent/Data/CombustionEngineData.cs +++ b/VectoCore/Models/SimulationComponent/Data/CombustionEngineData.cs @@ -310,7 +310,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data /// </summary> public SI Inertia { - get { return _data.Body.Inertia.SI().Kilo.Gramm.Square.Meter.To().Kilo.Gramm.Square.Meter.Value(); } + get { return _data.Body.Inertia.SI().Kilo.Gramm.Square.Meter; } protected set { _data.Body.Inertia = (double)value.To().Kilo.Gramm.Square.Meter; } }