diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs index 2af103d1b421b2ae625610ee093cd670549ac693..94d3d8bab43761a9d847a0d2bfc625887494c983 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs @@ -181,7 +181,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _engageTime = absTime + dt; } - var gear = NextGear.Gear; + if (ClutchClosed(absTime) && Disengaged && !outAngularVelocity.IsEqual(0)) { + ReEngageGear(absTime, dt, outTorque, outAngularVelocity); + Log.Debug("Gearbox engaged gear {0}", Gear); + } + + var gear = Disengaged ? NextGear.Gear : Gear; var avgOutAngularVelocity = (PreviousState.OutAngularVelocity + outAngularVelocity) / 2.0; var inTorqueLossResult = ModelData.Gears[gear].LossMap.GetTorqueLoss(avgOutAngularVelocity, outTorque); if (avgOutAngularVelocity.IsEqual(0, 1e-9)) { @@ -189,7 +194,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } var inAngularVelocity = outAngularVelocity * ModelData.Gears[gear].Ratio; - var inTorque = outTorque / ModelData.Gears[gear].Ratio + inTorqueLossResult.Value; + var avgInAngularVelocity = (PreviousState.InAngularVelocity + inAngularVelocity) / 2.0; + var inTorque = !avgInAngularVelocity.IsEqual(0) + ? outTorque * (avgOutAngularVelocity / avgInAngularVelocity) + : outTorque / ModelData.Gears[Gear].Ratio; + inTorque += inTorqueLossResult.Value; + //var inTorque = outTorque / ModelData.Gears[gear].Ratio + inTorqueLossResult.Value; + var inertiaTorqueLossOut = !inAngularVelocity.IsEqual(0) ? Formulas.InertiaPower(outAngularVelocity, PreviousState.OutAngularVelocity, ModelData.Inertia, dt) / avgOutAngularVelocity @@ -197,7 +208,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl inTorque += inertiaTorqueLossOut / ModelData.Gears[gear].Ratio; var halted = DataBus.DrivingAction == DrivingAction.Halt; - var driverDeceleratingNegTorque = DataBus.DriverBehavior == DrivingBehavior.Braking && + var driverDeceleratingNegTorque = DataBus.DriverBehavior == DrivingBehavior.Braking && DataBus.DrivingAction == DrivingAction.Brake && (DataBus.BrakePower.IsGreater(0) || inTorque.IsSmaller(0)); var vehiclespeedBelowThreshold = DataBus.VehicleSpeed.IsSmaller(Constants.SimulationSettings.ClutchDisengageWhenHaltingSpeed); @@ -313,13 +324,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl //{ // Gear = _strategy.InitGear(absTime, dt, outTorque, outAngularVelocity); //} - if (Disengaged && !outAngularVelocity.IsEqual(0)) { - ReEngageGear(absTime, dt, outTorque, outAngularVelocity); - Log.Debug("Gearbox engaged gear {0}", Gear); - } var inAngularVelocity = outAngularVelocity * ModelData.Gears[Gear].Ratio; - + if (dryRun) { var dryRunResponse = NextComponent.Request(absTime, dt, inTorque, inAngularVelocity, true); dryRunResponse.GearboxPowerRequest = outTorque * (PreviousState.OutAngularVelocity + outAngularVelocity) / 2.0; diff --git a/VectoCore/VectoCoreTest/Integration/CoachAdvancedAuxPowertrain.cs b/VectoCore/VectoCoreTest/Integration/CoachAdvancedAuxPowertrain.cs index e85dda0689b2847f816e082ca53ed9c29fc39d4f..88666ee92da983e7f72b228afb91a7fb2a15c771 100644 --- a/VectoCore/VectoCoreTest/Integration/CoachAdvancedAuxPowertrain.cs +++ b/VectoCore/VectoCoreTest/Integration/CoachAdvancedAuxPowertrain.cs @@ -100,7 +100,8 @@ namespace TUGraz.VectoCore.Tests.Integration AirdragData = airdragData, GearboxData = gearboxData, EngineData = engineData, - SimulationType = SimulationType.DistanceCycle + SimulationType = SimulationType.DistanceCycle, + Cycle = cycleData }; container.RunData = runData; cycle.AddComponent(new Driver(container, driverData, new DefaultDriverStrategy())) diff --git a/VectoCore/VectoCoreTest/Integration/Declaration/EngineInputDataTests.cs b/VectoCore/VectoCoreTest/Integration/Declaration/EngineInputDataTests.cs index df6189b37a2a06810a60e1ddd804152b5be584a0..ad992367d915b82212b9e952cb0b12d1a084c54e 100644 --- a/VectoCore/VectoCoreTest/Integration/Declaration/EngineInputDataTests.cs +++ b/VectoCore/VectoCoreTest/Integration/Declaration/EngineInputDataTests.cs @@ -58,10 +58,10 @@ namespace TUGraz.VectoCore.Tests.Integration.Declaration Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); } - [TestCase(null, 1.0, 45.5309587), - TestCase("CFRegPer", 1.2, 45.5309587 * 1.2), - TestCase("BFColdHot", 1.2, 45.5309587 * 1.2), - TestCase("CFNCV", 1.2, 45.5309587) // has no influence - only for documentation purpose + [TestCase(null, 1.0, 45.52476184, TestName = "Engine CF - NONE"), + TestCase("CFRegPer", 1.2, 45.52476184 * 1.2, TestName = "Engine CF - CFRegPer"), + TestCase("BFColdHot", 1.2, 45.52476184 * 1.2, TestName = "Engine CF - BFColdHod"), + TestCase("CFNCV", 1.2, 45.52476184, TestName = "Engine CF - CFNCV") // has no influence - only for documentation purpose ] public void TestEngineCorrectionFactors(string correctionFactor, double value, double expectedFc) { diff --git a/VectoCore/VectoCoreTest/Integration/Declaration/NaturalGasVehicles.cs b/VectoCore/VectoCoreTest/Integration/Declaration/NaturalGasVehicles.cs index 5b5b2483e3f3d1b3c06e0e5a94585ba9fdcdaf83..869ac7fbb18ca3346dfa6b56f9e203fc466a17fc 100644 --- a/VectoCore/VectoCoreTest/Integration/Declaration/NaturalGasVehicles.cs +++ b/VectoCore/VectoCoreTest/Integration/Declaration/NaturalGasVehicles.cs @@ -32,10 +32,10 @@ namespace TUGraz.VectoCore.Tests.Integration.Declaration [ - TestCase(Class5NG, 2, TankSystem.Liquefied, 253.7, 702.4), - TestCase(Class5NG, 2, TankSystem.Compressed, 259.4, 697.7), - TestCase(Class5NG, 6, TankSystem.Liquefied, 252.7, 699.8), - TestCase(Class5NG, 6, TankSystem.Compressed, 258.4, 695.4), + TestCase(Class5NG, 2, TankSystem.Liquefied, 253.7, 702.8, TestName = "Class5 LNG 2"), + TestCase(Class5NG, 2, TankSystem.Compressed, 259.5, 698.1, TestName = "Class5 CNG 2"), + TestCase(Class5NG, 6, TankSystem.Liquefied, 252.8, 700.4, TestName = "Class5 LNG 6"), + TestCase(Class5NG, 6, TankSystem.Compressed, 258.6, 695.7, TestName = "Class5 CNG 6"), ] public void NaturalGasTankSystemTest(string filename, int runIdx, TankSystem tankSystem, double expectedFc, double expectedCo2) { diff --git a/VectoCore/VectoCoreTest/Integration/DriverStrategy/SimpleCycles.cs b/VectoCore/VectoCoreTest/Integration/DriverStrategy/SimpleCycles.cs index 0fae5ebdca22ac5529c0dedde165c60574e3f95b..863a4b492877be9fef326025b173bd1a087c8fec 100644 --- a/VectoCore/VectoCoreTest/Integration/DriverStrategy/SimpleCycles.cs +++ b/VectoCore/VectoCoreTest/Integration/DriverStrategy/SimpleCycles.cs @@ -62,8 +62,8 @@ namespace TUGraz.VectoCore.Tests.Integration.DriverStrategy GraphWriter.Series1Label = "Vecto 3"; GraphWriter.Series2Label = "Vecto 2.2"; - Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); - } + Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); + } private static string GetSlopeString(double slope) { diff --git a/VectoCore/VectoCoreTest/Integration/FuelTypesTest.cs b/VectoCore/VectoCoreTest/Integration/FuelTypesTest.cs index 3db15189ec8d9256fd1bf90e30074af2c002b2ea..46175a7e039a206a00604509594548d8a58c53e5 100644 --- a/VectoCore/VectoCoreTest/Integration/FuelTypesTest.cs +++ b/VectoCore/VectoCoreTest/Integration/FuelTypesTest.cs @@ -58,40 +58,40 @@ namespace TUGraz.VectoCore.Tests.Integration [Category("Integration")] [TestCase(FuelType.DieselCI, null, @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2\Class2_RigidTruck_DECL.vecto", 0, - 0.0002199424, 0.0002199424, 26.311041667, 0.0006886, 9392.305166, + 0.0002199424, 0.0002199424, 26.3060719, 0.0006886, 9390.531125, TestName = "Diesel LH Low"), TestCase(FuelType.EthanolCI, null, @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2\Class2_RigidTruck_DECL.vecto", 0, - 0.0002199424, 0.0002225401, 27.1412517, 0.000402797, 5652.9799242, + 0.0002199424, 0.0002225401, 27.136125, 0.000402797, 5651.912176, TestName = "Ethanol/CI LH Low"), TestCase(FuelType.DieselCI, null, @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2\Class2_RigidTruck_DECL.vecto", 1, - 0.0002547295, 0.0002547295, 30.4604632, 0.0007971, 10873.5324987, + 0.0002547295, 0.0002547295, 30.4611849, 0.0007971, 10873.790098, TestName = "Diesel LH Ref"), TestCase(FuelType.EthanolCI, null, @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2\Class2_RigidTruck_DECL.vecto", 1, - 0.0002547295, 0.000257738, 31.421602924, 0.00046650, 6544.4914570, + 0.0002547295, 0.000257738, 31.4223473, 0.00046650, 6544.646499, TestName = "Ethanol/CI LH Ref"), TestCase(FuelType.EthanolPI, null, @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2\Class2_RigidTruck_DECL.vecto", 1, - 0.0002547295, 0.00025299078, 32.177003992, 0.0005312806, 7410.299665, + 0.0002547295, 0.00025299078, 32.17776628, 0.0005312806, 7410.475219, TestName = "Ethanol/PI LH Ref"), TestCase(FuelType.PetrolPI, null, @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2\Class2_RigidTruck_DECL.vecto", 1, - 0.0002547295, 0.00025472954, 34.04404719, 0.0007743778, 10567.9531310, + 0.0002547295, 0.00025472954, 34.0448537, 0.0007743778, 10568.203491, TestName = "Petrol/PI LH Ref"), TestCase(FuelType.LPGPI, null, @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2\Class2_RigidTruck_DECL.vecto", 1, - 0.0002547295, 0.0002547295, double.NaN, 0.00076928, 11713.8757597, + 0.0002547295, 0.0002547295, double.NaN, 0.00076928, 11714.1532673, TestName = "LPG/PI LH Ref"), TestCase(FuelType.NGPI, TankSystem.Liquefied, @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2\Class2_RigidTruck_DECL.vecto", 1, - 0.0002547295, 0.00023397765, double.NaN, 0.00064811809, 11484.69123399, + 0.0002547295, 0.00023397765, double.NaN, 0.00064811809, 11484.963312, TestName = "LNG/PI LH Ref"), TestCase(FuelType.NGPI, TankSystem.Compressed, @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2\Class2_RigidTruck_DECL.vecto", 1, - 0.0002547295, 0.0002393396, double.NaN, 0.000643823, 11484.69123399, + 0.0002547295, 0.0002393396, double.NaN, 0.000643823, 11484.963312, TestName = "CNG/PI LH Ref"), ] public void TestFuelTypesCO2(FuelType fuelType, TankSystem? tankSystem, string jobName, int runIdx, diff --git a/VectoCore/VectoCoreTest/Integration/TorqueLimitsTest.cs b/VectoCore/VectoCoreTest/Integration/TorqueLimitsTest.cs index b57287d849de805ec7b9f071f361d9973b268f88..1aedb2dd045d98a72e5f17086cf40a0af250b962 100644 --- a/VectoCore/VectoCoreTest/Integration/TorqueLimitsTest.cs +++ b/VectoCore/VectoCoreTest/Integration/TorqueLimitsTest.cs @@ -29,6 +29,7 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ +using System; using System.Data; using System.IO; using System.Linq; @@ -253,12 +254,13 @@ namespace TUGraz.VectoCore.Tests.Integration Assert.IsTrue(jobContainer.Runs.All(r => r.Success), string.Concat(jobContainer.Runs.Select(r => r.ExecException))); var view = new DataView(sumData.Table, "", SummaryDataContainer.SORT, DataViewRowState.CurrentRows).ToTable(); - Assert.AreEqual(201.3972, view.Rows[0][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); - Assert.AreEqual(239.2911, view.Rows[1][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); - Assert.AreEqual(170.1334, view.Rows[2][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); - Assert.AreEqual(183.0126, view.Rows[3][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); - Assert.AreEqual(224.1216, view.Rows[4][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); - Assert.AreEqual(254.3299, view.Rows[5][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); + Console.WriteLine(string.Join("; ", view.AsEnumerable().Select(x => x[SummaryDataContainer.FCMAP_KM].ToString().ToDouble()))); + Assert.AreEqual(201.39195, view.Rows[0][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); + Assert.AreEqual(239.28546, view.Rows[1][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); + Assert.AreEqual(170.11718, view.Rows[2][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); + Assert.AreEqual(183.02680, view.Rows[3][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); + Assert.AreEqual(224.07271, view.Rows[4][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); + Assert.AreEqual(254.35646, view.Rows[5][SummaryDataContainer.FCMAP_KM].ToString().ToDouble(), 1e-3); } [TestCase(EngineSpeedLimitJobATDecl)] diff --git a/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxPowertrainTest.cs b/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxPowertrainTest.cs index eac6e6d63ed3a70c2d4401e805ad4b6d843116d8..22a7eb5537e8e416239976ba6015c24732cadc77 100644 --- a/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxPowertrainTest.cs +++ b/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxPowertrainTest.cs @@ -29,6 +29,7 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ +using System.IO; using NUnit.Framework; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Models.Connector.Ports.Impl; @@ -40,6 +41,13 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent [TestFixture] public class GearboxPowertrainTest { + + [OneTimeSetUp] + public void RunBeforeAnyTests() + { + Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); + } + [TestCase] public void Gearbox_Initialize_Empty() { diff --git a/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs b/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs index 4bd32375a629848bf95e0b145f5078d0b3c22b16..62770b0e4711aa6d305b8f96ba666414e3493a1b 100644 --- a/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs +++ b/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs @@ -448,7 +448,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent TestCase(2, 50, 600, 9.096, typeof(ResponseSuccess)), TestCase(2, 2050, 1200, 52.132, typeof(ResponseSuccess)), TestCase(2, 850, 600, 25.096, typeof(ResponseSuccess)), - TestCase(1, 850, 0, 22.06, typeof(ResponseSuccess)), + TestCase(1, 850, 0, 0, typeof(ResponseSuccess)), // torque loss is 0 if speed is 0 ] public void Gearbox_Request_engaged(int gear, double t, double n, double loss, Type responseType) { @@ -488,12 +488,10 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var response = gearbox.OutPort().Request(absTime, dt, outTorque, angularVelocity); Assert.IsTrue(response.GetType() == responseType); - if (responseType == typeof(ResponseSuccess)) { - AssertHelper.AreRelativeEqual(absTime, port.AbsTime); - AssertHelper.AreRelativeEqual(dt, port.Dt); - AssertHelper.AreRelativeEqual(expectedN, port.AngularVelocity); - AssertHelper.AreRelativeEqual(t, port.Torque, toleranceFactor: 1e-5); - } + AssertHelper.AreRelativeEqual(absTime, port.AbsTime); + AssertHelper.AreRelativeEqual(dt, port.Dt); + AssertHelper.AreRelativeEqual(expectedN, port.AngularVelocity); + AssertHelper.AreRelativeEqual(t, port.Torque, toleranceFactor: 1e-5); } [TestCase(8, 7, 1800, 750, typeof(ResponseGearShift)),