diff --git a/Generic Vehicles/Declaration Mode/12t Delivery Truck/12t Delivery Truck.vsum b/Generic Vehicles/Declaration Mode/12t Delivery Truck/12t Delivery Truck.vsum deleted file mode 100644 index fd4d9a5bc0e942d3080f5f245f9f827e387458e2..0000000000000000000000000000000000000000 --- a/Generic Vehicles/Declaration Mode/12t Delivery Truck/12t Delivery Truck.vsum +++ /dev/null @@ -1,10 +0,0 @@ -Job [-],Input File [-],Cycle [-],Status,Mass [kg],Loading [kg],time [s],distance [km],speed [km/h],altitudeDelta [m],FC-Map [g/h],FC-Map [g/km],FC-AUXc [g/h],FC-AUXc [g/km],FC-WHTCc [g/h],FC-WHTCc [g/km],FC-AAUX [g/h],FC-AAUX [g/km],FC-Final [g/h],FC-Final [g/km],FC-Final [l/100km],FC-Final [l/100tkm],CO2 [g/km],CO2 [g/tkm],P_wheel_in_pos [kW],P_brake_loss [kW],P_eng_out_pos [kW],P_eng_out_neg [kW],E_aux_FAN [kWh],E_aux_STP [kWh],E_aux_AC [kWh],E_aux_PS [kWh],E_aux_ES [kWh],E_aux_sum [kWh],E_air [kWh],E_roll [kWh],E_grad [kWh],E_inertia [kWh],E_brake [kWh],E_gbx_axl_loss [kWh],E_ret_loss [kWh],E_tc_loss [kWh],E_eng_out_pos [kWh],E_eng_out_neg [kWh],a [m/s^2],a_pos [m/s^2],a_neg [m/s^2],AccelerationTimeShare [%],DecelerationTimeShare [%],CruiseTimeShare [%],StopTimeShare [%] -2-0,12t Delivery Truck,LongHaul.vdri,Success,7750.0000,0.0000,4544.7743,100.1850,79.3584,-2.5494,14928.1995,188.1112,14928.1995,188.1112,15044.6394,189.5784,15044.6394,189.5784,15044.6394,189.5784,22.7859,,599.0678,,57.9544,0.8532,75.6554,-16.3708,0.8435,0.4672,0.2525,1.4900,2.2368,5.2901,50.6334,20.0004,-0.0512,0.0000,1.0772,15.9289,0.0000,0.0000,88.4933,-0.8804,0.0000,0.4627,-0.4662,4.3794,4.3134,0.0000,1.4742 -2-1,12t Delivery Truck,LongHaul.vdri,Success,7750.0000,4150.0000,4574.5666,100.1850,78.8416,-2.5494,16547.5682,209.8838,16547.5682,209.8838,16676.6392,211.5209,16676.6392,211.5209,16676.6392,211.5209,25.4232,6.1261,668.4060,161.0617,66.6100,2.4444,86.0351,-15.8558,0.8490,0.4703,0.2542,1.4998,2.2515,5.3247,50.3756,29.4211,-0.0786,0.0000,3.1061,16.1961,0.0000,0.0000,100.0772,-1.0250,0.0000,0.4200,-0.4759,4.6568,4.0446,0.0000,1.4646 -2-2,12t Delivery Truck,LongHaul.vdri,Success,7750.0000,4150.0000,4574.5666,100.1850,78.8416,-2.5494,16547.5682,209.8838,16547.5682,209.8838,16676.6392,211.5209,16676.6392,211.5209,16676.6392,211.5209,25.4232,6.1261,668.4060,161.0617,66.6100,2.4444,86.0351,-15.8558,0.8490,0.4703,0.2542,1.4998,2.2515,5.3247,50.3756,29.4211,-0.0786,0.0000,3.1061,16.1961,0.0000,0.0000,100.0772,-1.0250,0.0000,0.4200,-0.4759,4.6568,4.0446,0.0000,1.4646 -2-3,12t Delivery Truck,RegionalDelivery.vdri,Success,7750.0000,0.0000,1580.7711,25.8360,58.8381,0.0101,10796.3012,183.4916,10796.3012,183.4916,10802.7790,183.6017,10802.7790,183.6017,10802.7790,183.6017,22.0675,,580.1814,,40.4898,2.2577,64.7531,-8.3571,0.3167,0.1406,0.0878,0.5622,0.6620,1.7693,10.7354,5.1202,-0.0001,0.0000,0.9913,4.0827,0.0000,0.0000,21.3940,-0.4322,0.0000,0.4901,-0.5314,13.9241,12.7848,0.0000,7.2117 -2-4,12t Delivery Truck,RegionalDelivery.vdri,Success,7750.0000,2983.8900,1583.3376,25.8360,58.7427,0.0101,11907.2364,202.7014,11907.2364,202.7014,11914.3807,202.8230,11914.3807,202.8230,11914.3807,202.8230,24.3778,8.1698,640.9207,214.7937,46.7806,3.7696,75.9980,-11.2300,0.3172,0.1408,0.0880,0.5631,0.6631,1.7722,10.6922,6.8643,-0.0002,0.0000,1.6579,4.1756,0.0000,0.0000,24.1477,-0.7165,0.0000,0.4665,-0.5103,14.9810,13.4640,0.0000,7.2000 -2-5,12t Delivery Truck,RegionalDelivery.vdri,Success,7750.0000,4150.0000,1584.9491,25.8360,58.6830,0.0101,12325.0194,210.0270,12325.0194,210.0270,12332.4144,210.1530,12332.4144,210.1530,12332.4144,210.1530,25.2588,6.0865,664.0836,160.0201,49.1906,4.3746,80.4332,-11.8038,0.3175,0.1409,0.0881,0.5637,0.6637,1.7740,10.6534,7.5320,-0.0002,0.0000,1.9260,4.2116,0.0000,0.0000,25.1871,-0.8189,0.0000,0.4431,-0.4858,15.9722,14.2677,0.0000,7.1927 -2-6,12t Delivery Truck,UrbanDelivery.vdri,Aborted,7750.0000,0.0000,906.0032,4.9742,19.7651,-7.4125,4408.4726,223.0431,4408.4726,223.0431,4367.9147,220.9911,4367.9147,220.9911,4367.9147,220.9911,26.5614,,698.3320,,13.1643,5.0283,37.3407,-6.9963,0.1551,0.0781,0.0378,0.3324,0.3504,0.9537,0.5806,0.9857,-0.1559,0.0295,1.2655,0.8116,0.0000,0.0000,3.8777,-0.2921,0.0076,0.5538,-0.6160,20.9945,17.6796,0.0000,29.8428 -2-7,12t Delivery Truck,UrbanDelivery.vdri,Aborted,7750.0000,2983.8900,686.4355,4.4473,23.3240,-6.5605,5871.9648,251.7561,5871.9648,251.7561,5817.9427,249.4399,5817.9427,249.4399,5817.9427,249.4399,29.9808,10.0475,788.2302,264.1620,20.5155,9.2052,50.6685,-7.5826,0.1175,0.0592,0.0286,0.2519,0.2655,0.7227,0.5563,1.1816,-0.1911,0.0290,1.7552,0.7508,0.0000,0.0000,4.4481,-0.2784,0.0100,0.5367,-0.6031,24.2336,20.0000,0.0000,21.4150 -2-8,12t Delivery Truck,UrbanDelivery.vdri,Aborted,7750.0000,4150.0000,1995.5984,12.2235,22.0509,-7.3852,5664.0624,256.8634,5664.0624,256.8634,5611.9530,254.5002,5611.9530,254.5002,5611.9530,254.5002,30.5890,7.3708,804.2207,193.7881,19.8581,8.2179,52.3756,-8.3023,0.3416,0.1719,0.0832,0.7319,0.7715,2.1000,1.4655,3.5633,-0.2384,0.0294,4.5554,2.0750,0.0000,0.0000,12.5032,-0.8591,0.0035,0.5393,-0.5926,21.1028,18.7469,0.0000,25.9163 diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/DistanceRun.cs b/VectoCore/VectoCore/Models/Simulation/Impl/DistanceRun.cs index 37cf822ed2ed4590396fdee4c92c94613127b989..da5dc761a03bf8698a83fd0cb022a2e750810d4c 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/DistanceRun.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/DistanceRun.cs @@ -44,6 +44,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl protected override IResponse DoSimulationStep() { + IterationStatistics.StartIteration(); + // estimate distance to be traveled within the next TargetTimeInterval var ds = Container.VehicleSpeed.IsEqual(0) ? Constants.SimulationSettings.DriveOffDistance @@ -52,6 +54,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl var loopCount = 0; IResponse response; do { + IterationStatistics.Increment(this, "Iterations"); + Container.BrakePower = 0.SI<Watt>(); response = CyclePort.Request(AbsTime, ds); response.Switch(). @@ -72,6 +76,9 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl } } while (!(response is ResponseSuccess || response is ResponseCycleFinished)); + IterationStatistics.Increment(this, "Distance", Container.Distance.Value()); + IterationStatistics.Increment(this, "Time", AbsTime.Value()); + IterationStatistics.FinishIteration(AbsTime); return response; } diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/VectoRun.cs b/VectoCore/VectoCore/Models/Simulation/Impl/VectoRun.cs index a1282979aed6ca9db29d8a6bbeb63e54509594ce..b7d6f8b432093f8b38a19666a75633e9e18281b4 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/VectoRun.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/VectoRun.cs @@ -145,6 +145,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl } Container.RunStatus = Status.Success; Container.FinishSimulation(); + + IterationStatistics.FinishSimulation(RunName + CycleName + RunSuffix + RunIdentifier); Log.Info("VectoJob finished."); } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs index 2a265f4044196ecc5cc23034d54c16145336f3b7..5f62d5b69dd5a83b2181118f0be3f04c2c985c19 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs @@ -144,6 +144,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl IResponse ITnOutPort.Request(Second absTime, Second dt, NewtonMeter torque, PerSecond angularVelocity, bool dryRun) { + IterationStatistics.Increment(this, "Requests"); + Log.Debug("Engine Powertrain Power Request: torque: {0}, angularVelocity: {1}, power: {2}", torque, angularVelocity, torque * angularVelocity); diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs index 6aca5126b25f98939ae94959c074603f326102ce..098b6828d80a4eaa07d103f67abc79f01c07f28f 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs @@ -32,6 +32,7 @@ using System; using System.Diagnostics; using System.Linq; +using iTextSharp.text.pdf; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; @@ -101,6 +102,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public IResponse Request(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient) { + IterationStatistics.Increment(this, "Requests"); + + VehicleStopped = false; Log.Debug("==== DRIVER Request (distance) ===="); Log.Debug( @@ -120,6 +124,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public IResponse Request(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient) { + IterationStatistics.Increment(this, "Requests"); + VehicleStopped = true; Log.Debug("==== DRIVER Request (time) ===="); Log.Debug( @@ -152,6 +158,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public IResponse DrivingActionAccelerate(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient, IResponse previousResponse = null) { + IterationStatistics.Increment(this, "Accelerate"); + Log.Debug("DrivingAction Accelerate"); var operatingPoint = ComputeAcceleration(ds, targetVelocity); @@ -229,6 +237,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// <returns></returns> public IResponse DrivingActionCoast(Second absTime, Meter ds, MeterPerSecond maxVelocity, Radian gradient) { + IterationStatistics.Increment(this, "Coast"); Log.Debug("DrivingAction Coast"); return CoastOrRollAction(absTime, ds, maxVelocity, gradient, false); @@ -244,6 +253,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// <returns></returns> public IResponse DrivingActionRoll(Second absTime, Meter ds, MeterPerSecond maxVelocity, Radian gradient) { + IterationStatistics.Increment(this, "Roll"); + Log.Debug("DrivingAction Roll"); var retVal = CoastOrRollAction(absTime, ds, maxVelocity, gradient, true); @@ -345,6 +356,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public IResponse DrivingActionBrake(Second absTime, Meter ds, MeterPerSecond nextTargetSpeed, Radian gradient, IResponse previousResponse = null, Meter targetDistance = null) { + IterationStatistics.Increment(this, "Brake"); Log.Debug("DrivingAction Brake"); IResponse retVal = null; @@ -509,6 +521,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Default(r => { throw new UnexpectedResponseException("cannot use response for searching braking power!", r); }); try { + var iterations = 0; DataBus.BrakePower = SearchAlgorithm.Search(DataBus.BrakePower, deltaPower, deltaPower.Abs(), getYValue: result => { var response = (ResponseDryRun)result; @@ -524,8 +537,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var response = (ResponseDryRun)result; var delta = DataBus.ClutchClosed(absTime) ? response.DeltaDragLoad : response.GearboxPowerRequest; return delta.Value(); - }); + }, + iterationCount: ref iterations); + + IterationStatistics.Increment(this, "SearchBrakingPower", iterations); return operatingPoint; + } catch (Exception) { Log.Error("Failed to find operating point for braking power! absTime: {0}", absTime); throw; @@ -554,6 +571,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var delta = origDelta; try { + var iterations = 0; retVal.Acceleration = SearchAlgorithm.Search(acceleration, delta, Constants.SimulationSettings.OperatingPointInitialSearchIntervalAccelerating, getYValue: response => { @@ -583,13 +601,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var r = (ResponseDryRun)response; delta = actionRoll ? r.GearboxPowerRequest : (coasting ? r.DeltaDragLoad : r.DeltaFullLoad); return delta.Value(); - }); + }, + iterationCount: ref iterations); if ( !retVal.Acceleration.IsBetween(DriverData.AccelerationCurve.MaxDeceleration(), DriverData.AccelerationCurve.MaxAcceleration())) { Log.Info("Operating Point outside driver acceleration limits: a: {0}", retVal.Acceleration); } + + IterationStatistics.Increment(this, "SearchOperatingPoint", iterations); return ComputeTimeInterval(retVal.Acceleration, retVal.SimulationDistance); } catch (Exception) { diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs index dd8b26b9579fb6d8fab77155c588f2c641e105f6..e49691392eec6e46757daec8620ac7bf367ee594 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs @@ -215,10 +215,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// </returns> public IResponse Request(Second absTime, Second dt, NewtonMeter torque, PerSecond angularVelocity, bool dryRun) { + IterationStatistics.Increment(this, "Requests"); + Log.Debug("Gearbox Power Request: torque: {0}, angularVelocity: {1}", torque, angularVelocity); if (DataBus.VehicleStopped) { _engageTime = absTime; } + IResponse retVal; // TODO: MQ 2016/03/10: investigate further the effects of having the condition angularvelocity != 0 if (ClutchClosed(absTime) /* && !angularVelocity.IsEqual(0) */) { diff --git a/VectoCore/VectoCore/Utils/IterationStatistics.cs b/VectoCore/VectoCore/Utils/IterationStatistics.cs new file mode 100644 index 0000000000000000000000000000000000000000..86d86424efc2bcae2f3923724e4e3c4dd4177e51 --- /dev/null +++ b/VectoCore/VectoCore/Utils/IterationStatistics.cs @@ -0,0 +1,129 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.IO; +using System.Runtime.CompilerServices; +using System.Threading; +using TUGraz.VectoCommon.Utils; + +namespace TUGraz.VectoCore.Utils +{ + public static class IterationStatistics + { + private static readonly ThreadLocal<List<DataEntry>> DataLocal = new ThreadLocal<List<DataEntry>>(() => new List<DataEntry>()); + public static List<DataEntry> Data{get { return DataLocal.Value; }} + + private static readonly ThreadLocal<Stopwatch> TimerLocal = new ThreadLocal<Stopwatch>(Stopwatch.StartNew); + private static Stopwatch Timer{get { return TimerLocal.Value; }} + + private static readonly ThreadLocal<Dictionary<string, Dictionary<string, double>>> CurrentLocal = + new ThreadLocal<Dictionary<string, Dictionary<string, double>>>( + () => new Dictionary<string, Dictionary<string, double>>()); + + private static Dictionary<string, Dictionary<string, double>> Current + { + get { return CurrentLocal.Value; } + set { CurrentLocal.Value = value; } + } + + [Conditional("TRACE")] + public static void Increment<T>(T o, string key, double? value = null) + { + var t = typeof(T).Name; + + if (!Current.ContainsKey(t)) + Current[t] = new Dictionary<string, double>(); + + if (Current[t].ContainsKey(key)) + if (value.HasValue) + Current[t][key] += value.Value; + else + Current[t][key]++; + + else { + if (value.HasValue) + Current[t][key] = value.Value; + else + Current[t][key] = 1; + } + } + + + public static void StartIteration() + { + Timer.Restart(); + } + + + [Conditional("TRACE"), MethodImpl(MethodImplOptions.Synchronized)] + public static void FinishIteration(Second absTime) + { + Timer.Stop(); + Data.Add(new DataEntry(absTime, Timer.Elapsed, Current)); + Current = new Dictionary<string, Dictionary<string, double>>(); + } + + [Conditional("TRACE")] + public static void FinishSimulation(string runName) + { + var table = new DataTable(); + table.Columns.Add("Distance", typeof(double)); + table.Columns.Add("Time", typeof(double)); + table.Columns.Add("StepDuration", typeof(double)); + table.Columns.Add("StepIterationCount", typeof(double)); + table.Columns.Add("NumDriverRequests", typeof(double)); + table.Columns.Add("NumAccelActions", typeof(double)); + table.Columns.Add("NumBrakeActions", typeof(double)); + table.Columns.Add("NumCoastActions", typeof(double)); + table.Columns.Add("NumRollActions", typeof(double)); + table.Columns.Add("SearchOPIterations", typeof(double)); + table.Columns.Add("SearchBrakeIterations", typeof(double)); + table.Columns.Add("NumGearboxRequests", typeof(double)); + table.Columns.Add("NumEngineRequests", typeof(double)); + + foreach (var entry in Data) { + var row = table.NewRow(); + row["StepDuration"] = entry.Duration.TotalMilliseconds; + + if (entry.Values.ContainsKey("DistanceRun")) { + row["Distance"] = entry.Values["DistanceRun"].ContainsKey("Distance") ? entry.Values["DistanceRun"]["Distance"] : 0; + row["Time"] = entry.Values["DistanceRun"].ContainsKey("Time") ? entry.Values["DistanceRun"]["Time"] : 0; + row["StepIterationCount"] = entry.Values["DistanceRun"].ContainsKey("Iterations") ? entry.Values["DistanceRun"]["Iterations"] : 0; + } + if (entry.Values.ContainsKey("Driver")) { + row["NumDriverRequests"] = entry.Values["Driver"].ContainsKey("Requests") ? entry.Values["Driver"]["Requests"] : 0; + row["NumAccelActions"] = entry.Values["Driver"].ContainsKey("Accelerate") ? entry.Values["Driver"]["Accelerate"] : 0; + row["NumBrakeActions"] = entry.Values["Driver"].ContainsKey("Brake") ? entry.Values["Driver"]["Brake"] : 0; + row["NumCoastActions"] = entry.Values["Driver"].ContainsKey("Coast") ? entry.Values["Driver"]["Coast"] : 0; + row["NumRollActions"] = entry.Values["Driver"].ContainsKey("Roll") ? entry.Values["Driver"]["Roll"] : 0; + row["SearchOPIterations"] = entry.Values["Driver"].ContainsKey("SearchOperatingPoint") ? entry.Values["Driver"]["SearchOperatingPoint"] : 0; + row["SearchBrakeIterations"] = entry.Values["Driver"].ContainsKey("SearchBrakingPower") ? entry.Values["Driver"]["SearchBrakingPower"] : 0; + } + if (entry.Values.ContainsKey("Gearbox")) { + row["NumGearboxRequests"] = entry.Values["Gearbox"].ContainsKey("Requests") ? entry.Values["Gearbox"]["Requests"] : 0; + } + if (entry.Values.ContainsKey("CombustionEngine")) { + row["NumEngineRequests"] = entry.Values["CombustionEngine"].ContainsKey("Requests") ? entry.Values["CombustionEngine"]["Requests"] : 0; + } + table.Rows.Add(row); + } + var writer = new StreamWriter("statistics_" + runName + ".csv"); + VectoCSVFile.Write(writer, table); + } + + public sealed class DataEntry + { + public readonly TimeSpan Duration; + public readonly Second Time; + public readonly Dictionary<string, Dictionary<string, double>> Values; + + public DataEntry(Second time, TimeSpan duration, Dictionary<string, Dictionary<string, double>> values) + { + Time = time; + Duration = duration; + Values = values; + } + } + } +} \ No newline at end of file diff --git a/VectoCore/VectoCore/VectoCore.csproj b/VectoCore/VectoCore/VectoCore.csproj index 234c180e84da1e67305c4f78206db6fe8bc931eb..39ab18b62e537e8c3677f0fdc6cc2d9af269c306 100644 --- a/VectoCore/VectoCore/VectoCore.csproj +++ b/VectoCore/VectoCore/VectoCore.csproj @@ -202,6 +202,7 @@ </Compile> <Compile Include="Utils\DataTableExtensionMethods.cs" /> <Compile Include="Utils\DateTimeFallbackDeserializer.cs" /> + <Compile Include="Utils\IterationStatistics.cs" /> <Compile Include="Utils\RessourceHelper.cs" /> <Compile Include="Models\Declaration\Segment.cs" /> <Compile Include="Models\Declaration\Axle.cs" />