diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/VelocitySpeedGearshiftPreprocessor.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/VelocitySpeedGearshiftPreprocessor.cs index 767400bf9cda3cc9ba65553db5fcd8995259b24e..7d433038feec3e3285215707430a7ec4ce52ce42 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/VelocitySpeedGearshiftPreprocessor.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/VelocitySpeedGearshiftPreprocessor.cs @@ -77,6 +77,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl if (gearForSpeed == 0) { continue; } + for (var grad = MinGradient; grad <= MaxGradient; grad += GradientStep) { var gradient = VectoMath.InclinationToAngle(grad / 100.0); gearbox.Disengaged = false; @@ -100,48 +101,46 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl protected MeterPerSecond SimulateRollingVehicle( Vehicle vehicle, Radian gradient, IVehicleContainer container) { - var simulationInterval = Constants.SimulationSettings.TargetTimeInterval; + var simulationInterval = TractionInterruption; var acceleration = 0.SI<MeterPerSquareSecond>(); var absTime = 0.SI<Second>(); - while (absTime < TractionInterruption) { - var initialResponse = vehicle.Request(absTime, simulationInterval, acceleration, gradient); - var delta = initialResponse.GearboxPowerRequest; - try { - var time = absTime; - acceleration = SearchAlgorithm.Search( - acceleration, delta, Constants.SimulationSettings.OperatingPointInitialSearchIntervalAccelerating, - getYValue: response => { - var r = (ResponseDryRun)response; - return r.GearboxPowerRequest; - }, - evaluateFunction: acc => { - var response = vehicle.Request(time, simulationInterval, acc, gradient, true); - response.Acceleration = acc; - return response; - }, - criterion: response => { - var r = (ResponseDryRun)response; - return r.GearboxPowerRequest.Value(); - }, - abortCriterion: (response, cnt) => { - var r = (ResponseDryRun)response; - return r != null && (vehicle.VehicleSpeed + r.Acceleration * simulationInterval) < 0.KMPHtoMeterPerSecond(); - } - ); - var step = vehicle.Request(absTime, simulationInterval, acceleration, gradient); - if (!(step is ResponseSuccess)) { - throw new VectoSimulationException("failed to find acceleration for rolling"); + var initialResponse = vehicle.Request(absTime, simulationInterval, acceleration, gradient); + var delta = initialResponse.GearboxPowerRequest; + try { + var time = absTime; + acceleration = SearchAlgorithm.Search( + acceleration, delta, Constants.SimulationSettings.OperatingPointInitialSearchIntervalAccelerating, + getYValue: response => { + var r = (ResponseDryRun)response; + return r.GearboxPowerRequest; + }, + evaluateFunction: acc => { + var response = vehicle.Request(time, simulationInterval, acc, gradient, true); + response.Acceleration = acc; + return response; + }, + criterion: response => { + var r = (ResponseDryRun)response; + return r.GearboxPowerRequest.Value() * 100; + }, + abortCriterion: (response, cnt) => { + var r = (ResponseDryRun)response; + return r != null && (vehicle.VehicleSpeed + r.Acceleration * simulationInterval) < 0.KMPHtoMeterPerSecond(); } - - absTime += simulationInterval; - } catch (VectoSearchAbortedException) { - return 0.KMPHtoMeterPerSecond(); + ); + var step = vehicle.Request(absTime, simulationInterval, acceleration, gradient); + if (!(step is ResponseSuccess)) { + throw new VectoSimulationException("failed to find acceleration for rolling"); } - container.CommitSimulationStep(absTime, simulationInterval); + absTime += simulationInterval; + } catch (VectoSearchAbortedException) { + return 0.KMPHtoMeterPerSecond(); } + container.CommitSimulationStep(absTime, simulationInterval); + return vehicle.VehicleSpeed; } diff --git a/VectoCore/VectoCore/Utils/Interpolate2D.cs b/VectoCore/VectoCore/Utils/Interpolate2D.cs index 8d3f2f81da85542d637a6c46fd422d044c59e08d..c83fdc79c2ed248f137221d5999f5c6fd0741410 100644 --- a/VectoCore/VectoCore/Utils/Interpolate2D.cs +++ b/VectoCore/VectoCore/Utils/Interpolate2D.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Data; +using System.Diagnostics; using System.Linq; using TUGraz.VectoCommon.Utils; @@ -19,6 +20,7 @@ namespace TUGraz.VectoCore.Utils protected void SetData(TEntry[] entries) { + var stop = Stopwatch.StartNew(); _data = new DataTable(); var xEntries = new List<KeyValuePair<TKeyX, int>>(); var idx = 0; @@ -27,7 +29,7 @@ namespace TUGraz.VectoCore.Utils xEntries.Add(new KeyValuePair<TKeyX, int>(xValue, idx++)); } - entriesX = xEntries.OrderBy(x => x.Key).ToArray(); + entriesX = xEntries.ToArray(); idx = 0; var yEntries = new List<KeyValuePair<TKeyY, int>>(); @@ -37,13 +39,15 @@ namespace TUGraz.VectoCore.Utils yEntries.Add(new KeyValuePair<TKeyY, int>(yValue, idx++)); } - entriesY = yEntries.OrderBy(x => x.Key).ToArray(); + entriesY = yEntries.ToArray(); foreach (var entry in entries) { var col = entriesX.First(x => x.Key.IsEqual(GetXValue(entry))); var row = entriesY.First(x => x.Key.IsEqual(GetYValue(entry))); _data.Rows[row.Value][col.Value] = GetZValue(entry); } + stop.Stop(); + Console.WriteLine("setData: {0}", stop.ElapsedMilliseconds); } protected abstract TKeyX GetXValue(TEntry entry);