diff --git a/Generic Vehicles/Engineering Mode/24t Coach/24t Coach_AAux.vecto b/Generic Vehicles/Engineering Mode/24t Coach/24t Coach_AAux.vecto index 54e911f56ca0533de129945faf3d82e81bbe022e..5edf2dfd8e07a6b8e405ef177b46875e9bad501d 100644 --- a/Generic Vehicles/Engineering Mode/24t Coach/24t Coach_AAux.vecto +++ b/Generic Vehicles/Engineering Mode/24t Coach/24t Coach_AAux.vecto @@ -1,7 +1,7 @@ { "Header": { "CreatedBy": " ()", - "Date": "06.04.2016 15:08:33", + "Date": "03.05.2016 08:08:42", "AppVersion": "2.2", "FileVersion": 2 }, @@ -11,6 +11,10 @@ "EngineFile": "24t Coach.veng", "GearboxFile": "24t Coach.vgbx", "Cycles": [ + "Interurban_Bus.vdri", + "Citybus_Heavy_Urban.vdri", + "Citybus_Suburban.vdri", + "Citybus_Urban.vdri", "Coach.vdri" ], "AuxiliaryAssembly": "BusAuxiliaries", diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs b/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs index 08b903660c87d6b9b439227fc57d4a9dcadef229..734fd8905b1c92c5e821f4abc8e8b06c82e7fa93 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs @@ -29,9 +29,11 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; +using System.Linq; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; @@ -47,7 +49,9 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl { public class VehicleContainer : LoggingObject, IVehicleContainer { - internal readonly IList<VectoSimulationComponent> Components = new List<VectoSimulationComponent>(); + internal readonly IList<Tuple<VectoSimulationComponent, int>> Components = + new List<Tuple<VectoSimulationComponent, int>>(); + internal IEngineInfo Engine; internal IGearboxInfo Gearbox; internal IVehicleInfo Vehicle; @@ -192,19 +196,33 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl public virtual void AddComponent(VectoSimulationComponent component) { - Components.Add(component); + var commitPriority = 0; component.Switch() - .If<IEngineInfo>(c => Engine = c) + .If<IEngineInfo>(c => { + Engine = c; + commitPriority = 2; + }) .If<IDriverInfo>(c => Driver = c) - .If<IGearboxInfo>(c => Gearbox = c) - .If<IVehicleInfo>(c => Vehicle = c) + .If<IGearboxInfo>(c => { + Gearbox = c; + commitPriority = 4; + }) + .If<IVehicleInfo>(c => { + Vehicle = c; + commitPriority = 5; + }) .If<ISimulationOutPort>(c => Cycle = c) .If<IMileageCounter>(c => MilageCounter = c) .If<IBrakes>(c => Brakes = c) .If<IRoadLookAhead>(c => Road = c) .If<IClutchInfo>(c => Clutch = c) - .If<IDrivingCycleInfo>(c => DrivingCycle = c); + .If<IDrivingCycleInfo>(c => { + DrivingCycle = c; + commitPriority = 3; + }); + + Components.Add(Tuple.Create(component, commitPriority)); } @@ -212,7 +230,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl { Log.Info("VehicleContainer committing simulation. time: {0}, dist: {1}, speed: {2}", time, ExecutionMode == ExecutionMode.EngineOnly ? null : Distance, VehicleSpeed); - foreach (var component in Components) { + + foreach (var component in Components.OrderBy(x => x.Item2).Reverse().Select(x => x.Item1)) { component.CommitSimulationStep(ModData); } @@ -237,7 +256,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl public IReadOnlyCollection<VectoSimulationComponent> SimulationComponents() { - return new ReadOnlyCollection<VectoSimulationComponent>(Components); + return new ReadOnlyCollection<VectoSimulationComponent>(Components.Select(x => x.Item1).ToList()); } public Meter Distance diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Brakes.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Brakes.cs index aa2fb87f4f781b696dabec69ae6ce051a84bec71..99ee2a05293a640aadacf90c8ab8f52a284878fa 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Brakes.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Brakes.cs @@ -77,7 +77,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl // but this could lead to extrapolation of loss maps (in axlegear and gear). // solution: we check here if the angularVelocity is 0 the first time and brake away all the torque if it is. // afterwards the vehicle is standing and other mechanisms take over (Driver.DriveTimeInterval) - if (DataBus.DriverBehavior == DrivingBehavior.Braking && !PreviousState.OutAngularVelocity.IsEqual(0) && + if (DataBus.ClutchClosed(absTime) && DataBus.DriverBehavior == DrivingBehavior.Braking && !PreviousState.OutAngularVelocity.IsEqual(0) && angularVelocity.IsEqual(0)) { brakeTorque = -torque; if (!dryRun) { diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs index 252eb519fdeccbe8a62afebd951be38878dcfae2..78914d7ddcea0601e677a0a6ba6c90a93492e034 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs @@ -220,6 +220,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl retVal.Acceleration = operatingPoint.Acceleration; retVal.SimulationInterval = operatingPoint.SimulationInterval; + retVal.OperatingPoint = operatingPoint; return retVal; } @@ -287,11 +288,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl OperatingPoint searchedOperatingPoint; try { searchedOperatingPoint = SearchOperatingPoint(absTime, requestedOperatingPoint.SimulationDistance, gradient, - requestedOperatingPoint.Acceleration, initialResponse, coasting: true); + requestedOperatingPoint.Acceleration, initialResponse, coastingOrRoll: true); } catch (VectoEngineSpeedTooLowException) { // in case of an exception during search the engine-speed got too low - gear disengaged --> try again with disengaged gear. searchedOperatingPoint = SearchOperatingPoint(absTime, requestedOperatingPoint.SimulationDistance, gradient, - requestedOperatingPoint.Acceleration, initialResponse, coasting: true); + requestedOperatingPoint.Acceleration, initialResponse, coastingOrRoll: true); } if (!ds.IsEqual(searchedOperatingPoint.SimulationDistance)) { @@ -302,7 +303,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Source = this, MaxDistance = searchedOperatingPoint.SimulationDistance, Acceleration = searchedOperatingPoint.Acceleration, - SimulationInterval = searchedOperatingPoint.SimulationInterval + SimulationInterval = searchedOperatingPoint.SimulationInterval, + OperatingPoint = searchedOperatingPoint }; return CurrentState.Response; } @@ -325,6 +327,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl response.SimulationInterval = limitedOperatingPoint.SimulationInterval; response.Acceleration = limitedOperatingPoint.Acceleration; + response.OperatingPoint = limitedOperatingPoint; response.Switch(). Case<ResponseSuccess>(). @@ -413,6 +416,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl CurrentState.Response = retVal; retVal.Acceleration = operatingPoint.Acceleration; retVal.SimulationInterval = operatingPoint.SimulationInterval; + retVal.OperatingPoint = operatingPoint; return retVal; } @@ -455,6 +459,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl CurrentState.Response = retVal; retVal.Acceleration = operatingPoint.Acceleration; retVal.SimulationInterval = operatingPoint.SimulationInterval; + retVal.OperatingPoint = operatingPoint; return retVal; } @@ -548,7 +553,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } protected OperatingPoint SearchOperatingPoint(Second absTime, Meter ds, Radian gradient, - MeterPerSquareSecond acceleration, IResponse initialResponse, bool coasting = false) + MeterPerSquareSecond acceleration, IResponse initialResponse, bool coastingOrRoll = false) { IterationStatistics.Increment(this, "SearchOperatingPoint", 0); @@ -565,7 +570,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } else { initialResponse.Switch(). Case<ResponseOverload>(r => origDelta = r.Delta). // search operating point in drive action after overload - Case<ResponseDryRun>(r => origDelta = coasting ? r.DeltaDragLoad : r.DeltaFullLoad). + Case<ResponseDryRun>(r => origDelta = coastingOrRoll ? r.DeltaDragLoad : r.DeltaFullLoad). Default(r => { throw new UnexpectedResponseException("Unknown response type.", r); }); } var delta = origDelta; @@ -574,7 +579,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Constants.SimulationSettings.OperatingPointInitialSearchIntervalAccelerating, getYValue: response => { var r = (ResponseDryRun)response; - return actionRoll ? r.GearboxPowerRequest : (coasting ? r.DeltaDragLoad : r.DeltaFullLoad); + return actionRoll ? r.GearboxPowerRequest : (coastingOrRoll ? r.DeltaDragLoad : r.DeltaFullLoad); }, evaluateFunction: acc => { @@ -600,7 +605,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } var r = (ResponseDryRun)response; - delta = actionRoll ? r.GearboxPowerRequest : (coasting ? r.DeltaDragLoad : r.DeltaFullLoad); + delta = actionRoll ? r.GearboxPowerRequest : (coastingOrRoll ? r.DeltaDragLoad : r.DeltaFullLoad); return delta.Value(); }, abortCriterion: @@ -610,7 +615,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return false; } - return coasting && !ds.IsEqual(r.OperatingPoint.SimulationDistance); + return !actionRoll && !ds.IsEqual(r.OperatingPoint.SimulationDistance); }); } catch (VectoSearchAbortedException) { // search aborted, try to go ahead with the last acceleration @@ -761,7 +766,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// <returns></returns> public IResponse DrivingActionHalt(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient) { - if (!targetVelocity.IsEqual(0) || !DataBus.VehicleSpeed.IsEqual(0, 1e-3)) { + if (!targetVelocity.IsEqual(0) || !DataBus.VehicleStopped) { Log.Error("TargetVelocity ({0}) and VehicleVelocity ({1}) must be zero when vehicle is halting!", targetVelocity, DataBus.VehicleSpeed); throw new VectoSimulationException( diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs index 3419189712d6091f6ad9c8985bafad53e70e26b0..227de3d7bd5a5134c13698479d51d575dcaa1a71 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs @@ -138,7 +138,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var dt = Constants.SimulationSettings.TargetTimeInterval; // MK 2016-02-10: SI doesn't allow inifinity anymore -- therefore simply a very negative value is used. - _engageTime = -1e10.SI<Second>(); //double.NegativeInfinity.SI<Second>(); + _engageTime = -double.MaxValue.SI<Second>(); //double.NegativeInfinity.SI<Second>(); if (Disengaged) { Gear = _strategy.InitGear(absTime, dt, outTorque, outAngularVelocity); @@ -329,7 +329,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl if (dryRun) { if ((DataBus.DriverBehavior == DrivingBehavior.Braking || DataBus.DriverBehavior == DrivingBehavior.Coasting) && - inAngularVelocity < DataBus.EngineIdleSpeed && DataBus.VehicleSpeed < Constants.SimulationSettings.VehicleStopClutchDisengageSpeed) { + inAngularVelocity < DataBus.EngineIdleSpeed && + DataBus.VehicleSpeed < Constants.SimulationSettings.VehicleStopClutchDisengageSpeed) { Disengaged = true; _engageTime = absTime + dt; _strategy.Disengage(absTime, dt, outTorque, outAngularVelocity); @@ -350,7 +351,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl if (shiftRequired) { _engageTime = absTime + ModelData.TractionInterruption; - Log.Debug("Gearbox is shifting. absTime: {0}, dt: {1}, interuptionTime: {2}, out: ({3}, {4}), in: ({5}, {6})", absTime, + Log.Debug("Gearbox is shifting. absTime: {0}, dt: {1}, interuptionTime: {2}, out: ({3}, {4}), in: ({5}, {6})", + absTime, dt, _engageTime, outTorque, outAngularVelocity, inTorque, inAngularVelocity); Disengaged = true; @@ -430,7 +432,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } } } - + if (DataBus.VehicleStopped) { + Disengaged = false; + _engageTime = -double.MaxValue.SI<Second>(); + } AdvanceState(); } diff --git a/VectoCore/VectoCore/Utils/DelaunayMap.cs b/VectoCore/VectoCore/Utils/DelaunayMap.cs index 9782d4d6f9c3bca202e2b4f6c204a5a9910adb74..57c98eb3120f32cfd7f012ad2fec971c58858c04 100644 --- a/VectoCore/VectoCore/Utils/DelaunayMap.cs +++ b/VectoCore/VectoCore/Utils/DelaunayMap.cs @@ -133,7 +133,7 @@ namespace TUGraz.VectoCore.Utils } } - DrawGraph(pointCount, triangles, superTriangle, xmin, xmax, ymin, ymax); + //DrawGraph(pointCount, triangles, superTriangle, xmin, xmax, ymin, ymax); _convexHull = triangles.FindAll(t => t.SharesVertexWith(superTriangle)). SelectMany(t => t.GetEdges()). diff --git a/VectoCore/VectoCore/Utils/Validation.cs b/VectoCore/VectoCore/Utils/Validation.cs index 7aca0922916cb2e7973462348bfbe94cb7a349fd..ade2ded943a22ef3d43c56bb16cfe11bab077c4e 100644 --- a/VectoCore/VectoCore/Utils/Validation.cs +++ b/VectoCore/VectoCore/Utils/Validation.cs @@ -57,8 +57,9 @@ namespace TUGraz.VectoCore.Utils var results = new List<ValidationResult>(); Validator.TryValidateObject(entity, new ValidationContext(entity), results, true); - const BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | - BindingFlags.FlattenHierarchy; + const BindingFlags flags = + BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | + BindingFlags.FlattenHierarchy; var properties = entity.GetType().GetProperties(flags); foreach (var p in properties) { @@ -95,16 +96,22 @@ namespace TUGraz.VectoCore.Utils private static IEnumerable<T> GetAttributes<T>(this MemberInfo m, Type obj) where T : Attribute { var attributes = Enumerable.Empty<T>(); - - const BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.FlattenHierarchy; + + const BindingFlags flags = + BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | + BindingFlags.FlattenHierarchy; var prop = obj.GetProperty(m.Name, flags); if (prop != null) { - attributes = prop.GetCustomAttributes(typeof(T)).Cast<T>().Concat(obj.GetInterfaces().SelectMany(m.GetAttributes<T>)); + attributes = prop.GetCustomAttributes(typeof(T)) + .Cast<T>() + .Concat(obj.GetInterfaces().SelectMany(m.GetAttributes<T>)); } var field = obj.GetField(m.Name, flags); if (field != null) { - attributes = attributes.Concat(field.GetCustomAttributes(typeof(T)).Cast<T>().Concat(obj.GetInterfaces().SelectMany(m.GetAttributes<T>))); + attributes = + attributes.Concat( + field.GetCustomAttributes(typeof(T)).Cast<T>().Concat(obj.GetInterfaces().SelectMany(m.GetAttributes<T>))); } return attributes; @@ -155,10 +162,14 @@ namespace TUGraz.VectoCore.Utils } } else { var results = value.Validate(); - if (results.Any()) { - return new ValidationResult( - string.Format("{{{0}}} invalid: {1}", validationContext.DisplayName, string.Join("\n", results))); + if (!results.Any()) { + return ValidationResult.Success; + } + if (validationContext.MemberName == "Container" || validationContext.MemberName == "RunData") { + return new ValidationResult(string.Join("\n", results)); } + return new ValidationResult( + string.Format("{{{0}}} invalid: {1}", validationContext.DisplayName, string.Join("\n", results))); } return ValidationResult.Success; diff --git a/VectoCore/VectoCoreTest/Integration/FullCycleDeclarationTest.cs b/VectoCore/VectoCoreTest/Integration/FullCycleDeclarationTest.cs index e6b89ff920545cf99edfe1b13a719e0b914e617d..abe918ab5ef49d60b61ed3f6f88cc9c5ba45b52a 100644 --- a/VectoCore/VectoCoreTest/Integration/FullCycleDeclarationTest.cs +++ b/VectoCore/VectoCoreTest/Integration/FullCycleDeclarationTest.cs @@ -50,6 +50,9 @@ namespace TUGraz.VectoCore.Tests.Integration public const string DeliveryTruckDeclarationJob = @"TestData\Integration\DeclarationMode\12t Truck\12t Delivery Truck.vecto"; + public const string DeliveryTruck8GearDeclarationJob = + @"TestData\Integration\DeclarationMode\12t Truck\12t Delivery Truck_8gear.vecto"; + [TestMethod] public void Truck40t_LongHaulCycle_RefLoad() { @@ -186,5 +189,27 @@ namespace TUGraz.VectoCore.Tests.Integration Assert.IsTrue(jobContainer.Runs.All(r => r.Success), string.Concat(jobContainer.Runs.Select(r => r.ExecException))); } + + [TestMethod, TestCategory("LongRunning")] + public void Truck12t8Gear_DeclarationTest() + { + var inputData = JSONInputDataFactory.ReadJsonJob(DeliveryTruck8GearDeclarationJob); + var fileWriter = new FileOutputWriter(DeliveryTruck8GearDeclarationJob); + var factory = new SimulatorFactory(ExecutionMode.Declaration, inputData, fileWriter) { + WriteModalResults = true + }; + var sumData = new SummaryDataContainer(fileWriter); + var jobContainer = new JobContainer(sumData); + jobContainer.AddRuns(factory); + + var runs = jobContainer.Runs; + + //runs[8].Run.Run(); + + jobContainer.Execute(); + jobContainer.WaitFinished(); + + Assert.IsTrue(jobContainer.Runs.All(r => r.Success), string.Concat(jobContainer.Runs.Select(r => r.ExecException))); + } } } \ No newline at end of file diff --git a/VectoCore/VectoCoreTest/VectoCoreTest.csproj b/VectoCore/VectoCoreTest/VectoCoreTest.csproj index e82aba9749d65345bc5b1b1b59317a29b58b5dda..b1b6acdba2f98d7afc784f51c7b208a6ffa1dfa7 100644 --- a/VectoCore/VectoCoreTest/VectoCoreTest.csproj +++ b/VectoCore/VectoCoreTest/VectoCoreTest.csproj @@ -484,6 +484,9 @@ <None Include="TestData\Integration\DeclarationMode\12t Truck\12t Delivery Truck.vveh"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> + <None Include="TestData\Integration\DeclarationMode\12t Truck\12t Delivery Truck_8gear.vecto"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> <None Include="TestData\Integration\DeclarationMode\12t Truck\12t Delivery Truck_LongHaulEmptyLoading.vmod"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> @@ -514,6 +517,9 @@ <None Include="TestData\Integration\DeclarationMode\12t Truck\Axle.vtlm"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> + <None Include="TestData\Integration\DeclarationMode\12t Truck\Decl_8spd.vgbx"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> <None Include="TestData\Integration\DeclarationMode\12t Truck\Direct Gear.vtlm"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None>