diff --git a/VectoCore/Models/Simulation/Impl/VectoRun.cs b/VectoCore/Models/Simulation/Impl/VectoRun.cs index 5998189ca76fdad7f4561a7929bff53d9f63dba3..33a149b988207fbefa68bcd74a10056d66a84d87 100644 --- a/VectoCore/Models/Simulation/Impl/VectoRun.cs +++ b/VectoCore/Models/Simulation/Impl/VectoRun.cs @@ -17,6 +17,7 @@ using System; using System.ComponentModel; using System.ComponentModel.DataAnnotations; +using NLog; using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.Models.Connector.Ports; using TUGraz.VectoCore.Models.Connector.Ports.Impl; @@ -116,13 +117,24 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl Container.RunStatus = Status.Aborted; Container.FinishSimulation(); throw new VectoSimulationException("{6} - absTime: {0}, distance: {1}, dt: {2}, v: {3}, Gear: {4} | {5}", e, AbsTime, - Container.Distance, dt, Container.VehicleSpeed, Container.Gear, e.Message, RunIdentifier); + Container.Distance, dt, Container.VehicleSpeed, TryCatch<VectoException>(() => Container.Gear), e.Message, + RunIdentifier); } Container.RunStatus = Status.Success; Container.FinishSimulation(); Log.Info("VectoJob finished."); } + private static object TryCatch<T>(Func<object> action) where T : Exception + { + try { + return action(); + } catch (T e) { + LogManager.GetLogger(typeof(VectoRun).FullName).Info(e); + return null; + } + } + protected abstract IResponse DoSimulationStep(); protected abstract IResponse Initialize(); diff --git a/VectoCore/Models/SimulationComponent/Impl/PowertrainDrivingCycle.cs b/VectoCore/Models/SimulationComponent/Impl/PowertrainDrivingCycle.cs index 891fd62905e0d751142dd8a1be6d979c43b690df..d18281dd9890c2eea04fb3081c6c8b6d992f28cc 100644 --- a/VectoCore/Models/SimulationComponent/Impl/PowertrainDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/PowertrainDrivingCycle.cs @@ -83,19 +83,19 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl IResponse ISimulationOutPort.Request(Second absTime, Second dt) { + // cycle finished (no more entries in cycle) + if (RightSample.Current == null) { + return new ResponseCycleFinished { Source = this }; + } + // interval exceeded if ((absTime + dt).IsGreater(RightSample.Current.Time)) { return new ResponseFailTimeInterval { Source = this, - DeltaT = RightSample.Current.Time - absTime + DeltaT = (absTime + dt) - RightSample.Current.Time }; } - // cycle finished (no more entries in cycle) - if (RightSample.Current == null) { - return new ResponseCycleFinished { Source = this }; - } - var request = NextComponent.Request(absTime, dt, LeftSample.Current.Torque, LeftSample.Current.AngularVelocity); request.Switch() .Case<ResponseSuccess>(() => { @@ -146,7 +146,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl protected override void DoCommitSimulationStep() { - if (AbsTime.IsGreaterOrEqual(RightSample.Current.Time)) { + if (AbsTime.IsGreater(RightSample.Current.Time)) { RightSample.MoveNext(); LeftSample.MoveNext(); } diff --git a/VectoCoreTest/Models/Simulation/PwheelModeTests.cs b/VectoCoreTest/Models/Simulation/PwheelModeTests.cs index 92f3c2d7241452198c11eceac4fe865433dac886..9aee2e5f7bc42f82124596a3a5cd847802935551 100644 --- a/VectoCoreTest/Models/Simulation/PwheelModeTests.cs +++ b/VectoCoreTest/Models/Simulation/PwheelModeTests.cs @@ -2,6 +2,7 @@ using System.Text; using TUGraz.VectoCore.Utils; using System.Collections.Generic; +using System.Data; using TUGraz.VectoCore.OutputData; using TUGraz.VectoCore.Tests.Utils; using TUGraz.VectoCore.InputData.Reader; @@ -10,7 +11,10 @@ using TUGraz.VectoCore.OutputData.FileIO; using TUGraz.VectoCore.InputData.FileIO.JSON; using TUGraz.VectoCore.Models.Simulation.Impl; using Microsoft.VisualStudio.TestTools.UnitTesting; +using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine; +using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox; using TUGraz.VectoCore.Models.SimulationComponent.Impl; namespace TUGraz.VectoCore.Tests.Models.Simulation @@ -26,9 +30,7 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation public void Pwheel_ReadCycle_Test() { IVehicleContainer container = new VehicleContainer(); - var inputData = @"<t>,<Pwheel>,<Gear>,<n>,<Padd> -1,89,2,1748,1.300 -2,120,2,1400,0.4"; + var inputData = "<t>,<Pwheel>,<Gear>,<n>,<Padd>\n1,89,2,1748,1.300\n2,120,2,1400,0.4"; Stream cycleFile = new MemoryStream(Encoding.UTF8.GetBytes(inputData)); var drivingCycle = DrivingCycleDataReader.ReadFromStream(cycleFile, CycleType.PWheel); @@ -60,33 +62,48 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation [TestMethod] public void Pwheel_CreatePowertrain_Test() { - var jobFile = @"TestData\Jobs\Pwheel.vecto"; - var fileWriter = new FileOutputWriter(jobFile); - var sumWriter = new SummaryDataContainer(fileWriter); - var jobContainer = new JobContainer(sumWriter); + // prepare input data + var inputData = "<t>,<Pwheel>,<Gear>,<n>,<Padd>\n1,89,2,1748,1.300\n2,120,2,1400,0.4"; - var inputData = JSONInputDataFactory.ReadJsonJob(jobFile); - var runsFactory = new SimulatorFactory(ExecutionMode.Engineering, inputData, fileWriter); - - jobContainer.AddRuns(runsFactory); - } + Stream cycleFile = new MemoryStream(Encoding.UTF8.GetBytes(inputData)); + var drivingCycle = DrivingCycleDataReader.ReadFromStream(cycleFile, CycleType.PWheel); - /// <summary> - /// Tests if the simulation runs a Pwheel mode. - /// </summary> - /// <remarks>VECTO-177</remarks> - [TestMethod] - public void Pwheel_Simulate_Test() - { - Assert.Fail("Test not implemented"); + var fuelConsumption = new DataTable(); + fuelConsumption.Columns.Add(""); + fuelConsumption.Columns.Add(""); + fuelConsumption.Columns.Add(""); + fuelConsumption.Rows.Add("1", "1", "1"); + fuelConsumption.Rows.Add("2", "2", "2"); + fuelConsumption.Rows.Add("3", "3", "3"); + + var fullLoad = new DataTable(); + fullLoad.Columns.Add("Engine speed"); + fullLoad.Columns.Add("max torque"); + fullLoad.Columns.Add("drag torque"); + fullLoad.Columns.Add("PT1"); + fullLoad.Rows.Add("0", "5000", "-5000", "0"); + fullLoad.Rows.Add("3000", "5000", "-5000", "0"); + + var fullLoadCurve = EngineFullLoadCurve.Create(fullLoad); + var data = new VectoRunData { + Cycle = drivingCycle, + AxleGearData = new AxleGearData { Ratio = 2.3 }, + EngineData = new CombustionEngineData() { IdleSpeed = 560.RPMtoRad(), FullLoadCurve = fullLoadCurve }, + GearboxData = new GearboxData { Gears = new Dictionary<uint, GearData> { { 2, new GearData { Ratio = 3.5 } } } }, + Retarder = new RetarderData(), + }; + + // call builder (actual test) + var builder = new PowertrainBuilder(null); + var jobContainer = builder.Build(data); } /// <summary> - /// Tests if the modfile is correct in Pwheel mode. + /// Tests if the simulation works and the modfile and sumfile are correct in Pwheel mode. /// </summary> /// <remarks>VECTO-177</remarks> [TestMethod] - public void Pwheel_Output_Modfile_Test() + public void Pwheel_Run_Test() { var jobFile = @"TestData\Jobs\Pwheel.vecto"; var fileWriter = new FileOutputWriter(jobFile);