From 00445bf795edb8c9b9c2faea9659c927041d8d82 Mon Sep 17 00:00:00 2001 From: Michael Krisper <michael.krisper@tugraz.at> Date: Mon, 14 Feb 2022 09:26:15 +0100 Subject: [PATCH] Corrected some compile errors due to different TargetFrameworks --- .../Utils/EnumerableExtensionMethods.cs | 9 ++ .../Integration/ADAS/ADASTestsConventional.cs | 2 +- .../Integration/ADAS/ADASTestsHEV.cs | 2 +- .../Integration/ADAS/ADASTestsPEV.cs | 2 +- .../BatteryElectric/BatteryElectricTest.cs | 55 +++++---- .../Declaration/EngineInputDataTests.cs | 3 +- .../Integration/TorqueLimitsTest.cs | 2 +- .../EngineeringModeBusAuxTest.cs | 114 +++++++++--------- .../Reports/ModDataPostprocessingTest.cs | 2 +- .../VectoCoreTest/Reports/ModDataTest.cs | 20 +-- VectoCore/VectoCoreTest/Utils/GraphWriter.cs | 35 ++++-- .../Utils/MockModalDataContainer.cs | 28 ++--- .../VectoCoreTest/Utils/ResultFileHelper.cs | 4 +- .../VectoCoreTest/Utils/ShiftPolygonDrawer.cs | 12 +- VectoCore/VectoCoreTest/VectoCoreTest.csproj | 7 +- 15 files changed, 159 insertions(+), 138 deletions(-) diff --git a/VectoCommon/VectoCommon/Utils/EnumerableExtensionMethods.cs b/VectoCommon/VectoCommon/Utils/EnumerableExtensionMethods.cs index 944d7f53e4..ac41e30a9a 100644 --- a/VectoCommon/VectoCommon/Utils/EnumerableExtensionMethods.cs +++ b/VectoCommon/VectoCommon/Utils/EnumerableExtensionMethods.cs @@ -96,6 +96,15 @@ namespace TUGraz.VectoCommon.Utils yield return item; } + /// <summary> + /// Zips all elements of two enumerable together. If the enumerables dont have the same length an exception is thrown. + /// </summary> + /// <exception cref="System.InvalidOperationException">Enumeration already finished. Thrown if the enumerables dont have the same length.</exception> + public static IEnumerable<(TFirst,TSecond)> ZipAll<TFirst, TSecond>(this IEnumerable<TFirst> firstEnumerable, + IEnumerable<TSecond> secondEnumerable) => + firstEnumerable.ZipAll(secondEnumerable, ValueTuple.Create); + + /// <summary> /// Zips all elements of two enumerable together. If the enumerables dont have the same length an exception is thrown. /// </summary> diff --git a/VectoCore/VectoCoreTest/Integration/ADAS/ADASTestsConventional.cs b/VectoCore/VectoCoreTest/Integration/ADAS/ADASTestsConventional.cs index 454bd2d120..615ed911f1 100644 --- a/VectoCore/VectoCoreTest/Integration/ADAS/ADASTestsConventional.cs +++ b/VectoCore/VectoCoreTest/Integration/ADAS/ADASTestsConventional.cs @@ -1466,7 +1466,7 @@ namespace TUGraz.VectoCore.Tests.Integration.ADAS var pccStates = pccCol.Values<PCCStates>(); var driverAction = driverActionCol.Values<DrivingAction>(); var distances = sCol.Values<Meter>(); - var sections = GetDistancesOfStateChanges(pccStates.Zip(driverAction), distances).ToArray(); + var sections = GetDistancesOfStateChanges(pccStates.ZipAll(driverAction), distances).ToArray(); Console.WriteLine("Start-End Segments:"); if (sections.Any()) { diff --git a/VectoCore/VectoCoreTest/Integration/ADAS/ADASTestsHEV.cs b/VectoCore/VectoCoreTest/Integration/ADAS/ADASTestsHEV.cs index d9b380b163..1505f8e736 100644 --- a/VectoCore/VectoCoreTest/Integration/ADAS/ADASTestsHEV.cs +++ b/VectoCore/VectoCoreTest/Integration/ADAS/ADASTestsHEV.cs @@ -1337,7 +1337,7 @@ namespace TUGraz.VectoCore.Tests.Integration.ADAS var pccStates = pccCol.Values<PCCStates>(); var driverAction = driverActionCol.Values<DrivingAction>(); var distances = sCol.Values<Meter>(); - var sections = GetDistancesOfStateChanges(pccStates.Zip(driverAction), distances).ToArray(); + var sections = GetDistancesOfStateChanges(pccStates.ZipAll(driverAction), distances).ToArray(); Console.WriteLine("Start-End Segments:"); if (sections.Any()) { diff --git a/VectoCore/VectoCoreTest/Integration/ADAS/ADASTestsPEV.cs b/VectoCore/VectoCoreTest/Integration/ADAS/ADASTestsPEV.cs index ca5eb8b89c..82fd237e32 100644 --- a/VectoCore/VectoCoreTest/Integration/ADAS/ADASTestsPEV.cs +++ b/VectoCore/VectoCoreTest/Integration/ADAS/ADASTestsPEV.cs @@ -773,7 +773,7 @@ namespace TUGraz.VectoCore.Tests.Integration.ADAS var pccStates = pccCol.Values<PCCStates>(); var driverAction = driverActionCol.Values<DrivingAction>(); var distances = sCol.Values<Meter>(); - var sections = GetDistancesOfStateChanges(pccStates.Zip(driverAction), distances).ToArray(); + var sections = GetDistancesOfStateChanges(pccStates.ZipAll(driverAction), distances).ToArray(); Console.WriteLine("Start-End Segments:"); if (sections.Any()) { diff --git a/VectoCore/VectoCoreTest/Integration/BatteryElectric/BatteryElectricTest.cs b/VectoCore/VectoCoreTest/Integration/BatteryElectric/BatteryElectricTest.cs index 191d30d59a..3b812fb659 100644 --- a/VectoCore/VectoCoreTest/Integration/BatteryElectric/BatteryElectricTest.cs +++ b/VectoCore/VectoCoreTest/Integration/BatteryElectric/BatteryElectricTest.cs @@ -73,7 +73,7 @@ namespace TUGraz.VectoCore.Tests.Integration.BatteryElectric //#else //graphWriter.Disable(); //#endif - + var Yfields = new[] { ModalResultField.v_act, ModalResultField.altitude, ModalResultField.acc, ModalResultField.Gear, @@ -196,8 +196,8 @@ namespace TUGraz.VectoCore.Tests.Integration.BatteryElectric if (slope.IsSmallerOrEqual(0) && vmax > 30) { ((ModalDataContainer)((VehicleContainer)run.GetContainer()).ModData).Data = modData; var selected = ((VehicleContainer)run.GetContainer()).ModData.GetValues(r => new { - speed = r.Field<SI>(ModalResultField.v_act.GetName()), - brakePwr = r.Field<SI>(ModalResultField.P_brake_loss.GetName()) + speed = (SI)r[ModalResultField.v_act.GetName()], + brakePwr = (SI)r[ModalResultField.P_brake_loss.GetName()] }).Where(x => x.speed.IsSmaller(7.KMPHtoMeterPerSecond()) && x.speed.IsGreater(0)); Assert.IsTrue(selected.All(x => x.brakePwr.IsGreater(0))); } @@ -350,7 +350,7 @@ namespace TUGraz.VectoCore.Tests.Integration.BatteryElectric Assert.IsTrue(run.FinishedWithoutErrors); Assert.IsTrue(modData.Rows.Count > 0); - + var graphWriter = GetGraphWriter(new[] { ModalResultField.P_electricMotor_mech_B3 }); graphWriter.Write(modFilename + ".vmod"); } @@ -386,8 +386,8 @@ namespace TUGraz.VectoCore.Tests.Integration.BatteryElectric if (slope.IsSmallerOrEqual(0) && vmax > 30) { ((ModalDataContainer)((VehicleContainer)run.GetContainer()).ModData).Data = modData; var selected = ((VehicleContainer)run.GetContainer()).ModData.GetValues(r => new { - speed = r.Field<SI>(ModalResultField.v_act.GetName()), - brakePwr = r.Field<SI>(ModalResultField.P_brake_loss.GetName()) + speed = (SI)r[ModalResultField.v_act.GetName()], + brakePwr = (SI)r[ModalResultField.P_brake_loss.GetName()] }).Where(x => x.speed.IsSmaller(7.KMPHtoMeterPerSecond()) && x.speed.IsGreater(0)); Assert.IsTrue(selected.All(x => x.brakePwr.IsGreater(0))); } @@ -432,7 +432,7 @@ namespace TUGraz.VectoCore.Tests.Integration.BatteryElectric job.WaitFinished(); Assert.IsTrue(run.FinishedWithoutErrors); Assert.IsTrue(modData.Rows.Count > 0); - + var graphWriter = GetGraphWriter(new[] { ModalResultField.P_electricMotor_mech_B3 }); graphWriter.Write(modFilename + ".vmod"); } @@ -616,8 +616,8 @@ namespace TUGraz.VectoCore.Tests.Integration.BatteryElectric graphWriter.Write(modFilename + ".vmod"); } - [ - TestCase(BEV_E2_Job, 0, TestName = "PEV E2 Job LongHaul"), + [ + TestCase(BEV_E2_Job, 0, TestName = "PEV E2 Job LongHaul"), TestCase(BEV_E2_Job, 1, TestName = "PEV E2 Job Coach"), TestCase(BEV_E2_Job, 2, TestName = "PEV E2 Job Construction"), TestCase(BEV_E2_Job, 3, TestName = "PEV E2 Job HeavyUrban"), @@ -689,7 +689,7 @@ namespace TUGraz.VectoCore.Tests.Integration.BatteryElectric } - + // ================================================= @@ -701,8 +701,8 @@ namespace TUGraz.VectoCore.Tests.Integration.BatteryElectric var sumData = new SummaryDataContainer(fileWriter); var jobContainer = new JobContainer(sumData); var container = CreateBatteryElectricPowerTrain( - cycleData, modFileName, fileWriter, sumData, initialSoc, count, ratio, largeMotor, pAuxEl, pos, payload); - + cycleData, modFileName, fileWriter, sumData, initialSoc, count, ratio, largeMotor, pAuxEl, pos, payload); + var run = new DistanceRun(container); jobContainer.AddRun(run); return jobContainer; @@ -724,11 +724,11 @@ namespace TUGraz.VectoCore.Tests.Integration.BatteryElectric MockSimulationDataFactory.CreateElectricMotorData(MotorFile, count, pos, ratio / (pos == PowertrainPosition.BatteryElectricE3 ? 2.59 : 1.0), 0.97); var batteryData = MockSimulationDataFactory.CreateBatteryData(BatFile, initialBatCharge); - + //var engineData = MockSimulationDataFactory.CreateEngineDataFromFile( - //Truck40tPowerTrain.EngineFile, gearboxData.Gears.Count); + //Truck40tPowerTrain.EngineFile, gearboxData.Gears.Count); + - var runData = new VectoRunData() { JobRunId = 0, @@ -750,8 +750,7 @@ namespace TUGraz.VectoCore.Tests.Integration.BatteryElectric }; var modDataFilter = new IModalDataFilter[] { }; //new IModalDataFilter[] { new ActualModalDataFilter(), }; - var modData = new ModalDataContainer(runData, fileWriter, null, modDataFilter) - { + var modData = new ModalDataContainer(runData, fileWriter, null, modDataFilter) { WriteModalResults = true, }; if (pos == PowertrainPosition.BatteryElectricE3) { @@ -762,13 +761,13 @@ namespace TUGraz.VectoCore.Tests.Integration.BatteryElectric runData.AxleGearData = axleGearData; runData.GearboxData = gearboxData; } - + var container = new VehicleContainer( ExecutionMode.Engineering, modData, x => { sumData?.Write(x, 1, 1, runData); }) { RunData = runData }; - + var es = new ElectricSystem(container); var battery = new BatterySystem(container, batteryData); @@ -794,11 +793,11 @@ namespace TUGraz.VectoCore.Tests.Integration.BatteryElectric switch (pos) { case PowertrainPosition.HybridPositionNotSet: throw new VectoException("invalid powertrain position"); - case PowertrainPosition.HybridP0: + case PowertrainPosition.HybridP0: case PowertrainPosition.HybridP1: - case PowertrainPosition.HybridP2: - case PowertrainPosition.HybridP3: - case PowertrainPosition.HybridP4: + case PowertrainPosition.HybridP2: + case PowertrainPosition.HybridP3: + case PowertrainPosition.HybridP4: throw new VectoException("testcase does not support parallel powertrain configurations"); case PowertrainPosition.BatteryElectricE4: powertrain.AddComponent( @@ -829,7 +828,7 @@ namespace TUGraz.VectoCore.Tests.Integration.BatteryElectric GetElectricMachine(PowertrainPosition.BatteryElectricE2, runData.ElectricMachinesData, container, es, ctl)); new ATClutchInfo(container); break; - //throw new VectoException("Battery Electric configuration B2 currently not supported"); + //throw new VectoException("Battery Electric configuration B2 currently not supported"); default: throw new ArgumentOutOfRangeException(nameof(pos), pos, null); } @@ -868,7 +867,7 @@ namespace TUGraz.VectoCore.Tests.Integration.BatteryElectric Ratio = ratio, //ShiftPolygon = shiftStrategy.ComputeDeclarationShiftPolygon(GearboxType.AMT, i, null, ) })).ToDictionary(k => k.Item1 + 1, v => v.Item2), - + Inertia = 0.SI<KilogramSquareMeter>(), TractionInterruption = 1.SI<Second>(), InputData = new DummyGearboxData() { @@ -986,7 +985,7 @@ namespace TUGraz.VectoCore.Tests.Integration.BatteryElectric RatingFactorCurrentGear = gbx.Type.AutomaticTransmission() ? DeclarationData.GearboxTCU.RatingFactorCurrentGearAT : DeclarationData.GearboxTCU.RatingFactorCurrentGear, - + //-------------------- RatioEarlyUpshiftFC = DeclarationData.GearboxTCU.RatioEarlyUpshiftFC / axleRatio, RatioEarlyDownshiftFC = DeclarationData.GearboxTCU.RatioEarlyDownshiftFC / axleRatio, @@ -1003,7 +1002,7 @@ namespace TUGraz.VectoCore.Tests.Integration.BatteryElectric LoadStageThresoldsUp = DeclarationData.GearboxTCU.LoadStageThresholdsUp, LoadStageThresoldsDown = DeclarationData.GearboxTCU.LoadStageThresoldsDown, //ShiftSpeedsTCToLocked = DeclarationData.GearboxTCU.ShiftSpeedsTCToLocked - //.Select(x => x.Select(y => y + engineIdlingSpeed.AsRPM).ToArray()).ToArray(), + //.Select(x => x.Select(y => y + engineIdlingSpeed.AsRPM).ToArray()).ToArray(), }; return retVal; @@ -1056,5 +1055,5 @@ namespace TUGraz.VectoCore.Tests.Integration.BatteryElectric public bool EngineOn => true; } - + } diff --git a/VectoCore/VectoCoreTest/Integration/Declaration/EngineInputDataTests.cs b/VectoCore/VectoCoreTest/Integration/Declaration/EngineInputDataTests.cs index 551d979585..e8f925e3bf 100644 --- a/VectoCore/VectoCoreTest/Integration/Declaration/EngineInputDataTests.cs +++ b/VectoCore/VectoCoreTest/Integration/Declaration/EngineInputDataTests.cs @@ -98,8 +98,7 @@ namespace TUGraz.VectoCore.Tests.Integration.Declaration var modData = ((ModalDataContainer)first.GetContainer().ModalData).Data; first.Run(); - Assert.AreEqual(expectedFc, modData.AsEnumerable().Sum(r => r.Field<SI>(ModalResultField.FCFinal.GetName()).Value()), 1e-3); - + Assert.AreEqual(expectedFc, modData.Sum(r => ((SI)r[ModalResultField.FCFinal.GetName()]).Value()), 1e-3); } } } diff --git a/VectoCore/VectoCoreTest/Integration/TorqueLimitsTest.cs b/VectoCore/VectoCoreTest/Integration/TorqueLimitsTest.cs index 22eea5b739..9c704400e0 100644 --- a/VectoCore/VectoCoreTest/Integration/TorqueLimitsTest.cs +++ b/VectoCore/VectoCoreTest/Integration/TorqueLimitsTest.cs @@ -259,7 +259,7 @@ 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.Fields.SORT, DataViewRowState.CurrentRows).ToTable(); - Console.WriteLine(string.Join("; ", view.AsEnumerable().Select(x => x[string.Format(SummaryDataContainer.Fields.FCMAP_KM, "")].ToString().ToDouble()))); + Console.WriteLine(string.Join("; ", view.Rows.Cast<DataRow>().Select(x => x[string.Format(SummaryDataContainer.Fields.FCMAP_KM, "")].ToString().ToDouble()))); //201.361576994368; 239.289343483313; 169.755876536437; 182.846813110234; 219.963573213321; 251.22381935842 Assert.AreEqual(201.36157, view.Rows[0][string.Format(SummaryDataContainer.Fields.FCMAP_KM, "")].ToString().ToDouble(), 1e-3); Assert.AreEqual(239.28934, view.Rows[1][string.Format(SummaryDataContainer.Fields.FCMAP_KM, "")].ToString().ToDouble(), 1e-3); diff --git a/VectoCore/VectoCoreTest/Models/EngineeringMode/EngineeringModeBusAuxTest.cs b/VectoCore/VectoCoreTest/Models/EngineeringMode/EngineeringModeBusAuxTest.cs index 49af5d5c62..7acbd28b72 100644 --- a/VectoCore/VectoCoreTest/Models/EngineeringMode/EngineeringModeBusAuxTest.cs +++ b/VectoCore/VectoCoreTest/Models/EngineeringMode/EngineeringModeBusAuxTest.cs @@ -227,8 +227,8 @@ namespace TUGraz.VectoCore.Tests.Models.EngineeringMode Assert.IsFalse(container.RunData.BusAuxiliaries.ElectricalUserInputsConfig.ConnectESToREESS); TestBusAux_Cases(container, drivingBehavior, iceOn, batterySoC, double.NaN, - P_auxMech_expected, P_busAux_ES_gen_expected, double.NaN, P_busAux_ES_consumer_sum_expected, P_busAux_ES_mech, - Nl_PS_gen_expected, Nl_PS_consumer_expected, P_PS_expected, double.NaN, + P_auxMech_expected, P_busAux_ES_gen_expected, double.NaN, P_busAux_ES_consumer_sum_expected, P_busAux_ES_mech, + Nl_PS_gen_expected, Nl_PS_consumer_expected, P_PS_expected, double.NaN, P_aux_ESS_mech_ICE_off_expected, P_aux_ESS_mech_ICE_on_expected, null, null, null); } @@ -264,11 +264,11 @@ namespace TUGraz.VectoCore.Tests.Models.EngineeringMode 0, 0, 0, P_ES_ICEOff_stop, 0, P_aux_m_ICEOff_st, P_aux_m_Base + (P_ES_base - P_ES_ICEOff_stop) / AlternatorEfficiency, 0, Nl_PS, 0, TestName = "BusAux Case B (8); standstill, ICE off, battery empty")] - [TestCase(DrivingBehavior.Braking, true, 0.5, + [TestCase(DrivingBehavior.Braking, true, 0.5, P_aux_m_Base + P_PS_1000 + MaxAlternatorPower / AlternatorEfficiency, MaxAlternatorPower, P_ES_base - MaxAlternatorPower, P_ES_base, MaxAlternatorPower / AlternatorEfficiency, 0, 0, Nl_PS, Nl_PS, P_PS_1000, TestName = "BusAux Case B (9); braking, ICE on, battery not full")] - [TestCase(DrivingBehavior.Braking, true, 1, + [TestCase(DrivingBehavior.Braking, true, 1, P_aux_m_Base + P_PS_1000 + P_ES_base / AlternatorEfficiency, P_ES_base, 0, P_ES_base, P_ES_base / AlternatorEfficiency, 0, 0, Nl_PS, Nl_PS, P_PS_1000, TestName = "BusAux Case B (10); braking, ICE on, battery full")] @@ -279,7 +279,7 @@ namespace TUGraz.VectoCore.Tests.Models.EngineeringMode double Nl_PS_gen_expected, double Nl_PS_consumer_expected, double P_PS_expected) { var container = CreatePowerTrain(AlternatorType.Smart, batterySoC, null, false); - + // check powertrain architecture and config Assert.NotNull(container.Components.FirstOrDefault(x => x is StopStartCombustionEngine)); @@ -295,37 +295,37 @@ namespace TUGraz.VectoCore.Tests.Models.EngineeringMode Assert.IsFalse(container.RunData.BusAuxiliaries.ElectricalUserInputsConfig.ConnectESToREESS); TestBusAux_Cases(container, drivingBehavior, iceOn, batterySoC, double.NaN, - P_auxMech_expected, P_busAux_ES_gen_expected, -P_bat_P0, P_busAux_ES_consumer_sum_expected, P_busAux_ES_mech, + P_auxMech_expected, P_busAux_ES_gen_expected, -P_bat_P0, P_busAux_ES_consumer_sum_expected, P_busAux_ES_mech, Nl_PS_gen_expected, Nl_PS_consumer_expected, P_PS_expected, double.NaN, P_aux_ESS_mech_ICE_off_expected, P_aux_ESS_mech_ICE_on_expected, null, null, null); } // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . - [TestCase(DrivingBehavior.Driving, true, 0.5, + [TestCase(DrivingBehavior.Driving, true, 0.5, P_aux_m_Base + P_PS_1000, 0, P_ES_base, 0, 0, 0, P_ES_base, 0, 0, Nl_PS, Nl_PS, P_PS_1000, TestName = "BusAux Case C1 (1); driving, ICE on, REESS not empty")] [TestCase(DrivingBehavior.Driving, true, REESS_MinSoC, P_aux_m_Base + P_PS_1000, 0, P_ES_base, 0, 0, 0, 0, P_ES_base, 0, Nl_PS, Nl_PS, P_PS_1000, TestName = "BusAux Case C1 (2); driving, ICE on, REESS empty")] [TestCase(DrivingBehavior.Driving, false, 0.5, - 0, 0, P_ES_ICEOff_dr, 0, P_aux_m_ICEOff_dr , P_aux_m_Base , P_ES_ICEOff_dr, 0, 0, 0, Nl_PS, 0, + 0, 0, P_ES_ICEOff_dr, 0, P_aux_m_ICEOff_dr, P_aux_m_Base, P_ES_ICEOff_dr, 0, 0, 0, Nl_PS, 0, TestName = "BusAux Case C1 (3); driving, ICE off, REESS not empty")] [TestCase(DrivingBehavior.Driving, false, REESS_MinSoC, - 0, 0, P_ES_ICEOff_dr, 0, P_aux_m_ICEOff_dr , P_aux_m_Base, 0, P_ES_ICEOff_dr, P_ES_base - P_ES_ICEOff_dr, 0, Nl_PS, 0, + 0, 0, P_ES_ICEOff_dr, 0, P_aux_m_ICEOff_dr, P_aux_m_Base, 0, P_ES_ICEOff_dr, P_ES_base - P_ES_ICEOff_dr, 0, Nl_PS, 0, TestName = "BusAux Case C1 (4); driving, ICE off, REESS empty")] [TestCase(DrivingBehavior.Halted, true, 0.5, P_aux_m_Base + P_PS_600, 0, P_ES_base, 0, 0, 0, P_ES_base, 0, 0, Nl_PS, Nl_PS, P_PS_600, TestName = "BusAux Case C1 (5); standstill, ICE on, REESS not empty")] - [TestCase(DrivingBehavior.Halted, true, REESS_MinSoC, + [TestCase(DrivingBehavior.Halted, true, REESS_MinSoC, P_aux_m_Base + P_PS_600, 0, P_ES_base, 0, 0, 0, 0, P_ES_base, 0, Nl_PS, Nl_PS, P_PS_600, TestName = "BusAux Case C1 (6); standstill, ICE on, REESS empty")] [TestCase(DrivingBehavior.Halted, false, 0.5, - 0, 0, P_ES_ICEOff_stop, 0, P_aux_m_ICEOff_st , P_aux_m_Base , P_ES_ICEOff_stop, 0, 0, 0, Nl_PS, 0, + 0, 0, P_ES_ICEOff_stop, 0, P_aux_m_ICEOff_st, P_aux_m_Base, P_ES_ICEOff_stop, 0, 0, 0, Nl_PS, 0, TestName = "BusAux Case C1 (7); standstill, ICE off, REESS not empty")] [TestCase(DrivingBehavior.Halted, false, REESS_MinSoC, - 0, 0, P_ES_ICEOff_stop, 0, P_aux_m_ICEOff_st , P_aux_m_Base , 0, P_ES_ICEOff_stop, P_ES_base - P_ES_ICEOff_stop, 0, Nl_PS, 0, + 0, 0, P_ES_ICEOff_stop, 0, P_aux_m_ICEOff_st, P_aux_m_Base, 0, P_ES_ICEOff_stop, P_ES_base - P_ES_ICEOff_stop, 0, Nl_PS, 0, TestName = "BusAux Case C1 (8); standstill, ICE off, REESS empty")] [TestCase(DrivingBehavior.Braking, true, 0.5, @@ -335,10 +335,10 @@ namespace TUGraz.VectoCore.Tests.Models.EngineeringMode P_aux_m_Base + P_PS_1000, 0, P_ES_base, 0, 0, 0, 0, P_ES_base, 0, Nl_PS, Nl_PS, P_PS_1000, TestName = "BusAux Case C1 (10); braking, ICE on, REESS empty")] [TestCase(DrivingBehavior.Braking, false, 0.5, - 0, 0, P_ES_ICEOff_dr, 0, P_aux_m_ICEOff_dr , P_aux_m_Base , P_ES_ICEOff_dr, 0, 0, 0, Nl_PS, 0, + 0, 0, P_ES_ICEOff_dr, 0, P_aux_m_ICEOff_dr, P_aux_m_Base, P_ES_ICEOff_dr, 0, 0, 0, Nl_PS, 0, TestName = "BusAux Case C1 (11); braking, ICE off, REESS not empty")] [TestCase(DrivingBehavior.Braking, false, REESS_MinSoC, - 0, 0, P_ES_ICEOff_dr, 0, P_aux_m_ICEOff_dr , P_aux_m_Base , 0, P_ES_ICEOff_dr, P_ES_base - P_ES_ICEOff_dr, 0, Nl_PS, 0, + 0, 0, P_ES_ICEOff_dr, 0, P_aux_m_ICEOff_dr, P_aux_m_Base, 0, P_ES_ICEOff_dr, P_ES_base - P_ES_ICEOff_dr, 0, Nl_PS, 0, TestName = "BusAux Case C1 (12); braking, ICE off, REESS empty")] public void TestBusAux_Case_C1(DrivingBehavior drivingBehavior, bool iceOn, double reessSoC, double P_auxMech_expected, double P_busAux_ES_gen_expected, double P_busAux_ES_consumer_sum_expected, @@ -347,7 +347,7 @@ namespace TUGraz.VectoCore.Tests.Models.EngineeringMode double Nl_PS_gen_expected, double Nl_PS_consumer_expected, double P_PS_expected) { var container = CreatePowerTrain(AlternatorType.None, double.NaN, reessSoC, true); - + // check powertrain architecture and config Assert.NotNull(container.Components.FirstOrDefault(x => x is StopStartCombustionEngine)); Assert.NotNull(container.Components.FirstOrDefault(x => x is BusAuxiliariesAdapter)); @@ -362,7 +362,7 @@ namespace TUGraz.VectoCore.Tests.Models.EngineeringMode Assert.IsTrue(container.RunData.BusAuxiliaries.ElectricalUserInputsConfig.ConnectESToREESS); TestBusAux_Cases(container, drivingBehavior, iceOn, double.NaN, reessSoC, - P_auxMech_expected, P_busAux_ES_gen_expected, double.NaN, P_busAux_ES_consumer_sum_expected, P_busAux_ES_mech, + P_auxMech_expected, P_busAux_ES_gen_expected, double.NaN, P_busAux_ES_consumer_sum_expected, P_busAux_ES_mech, Nl_PS_gen_expected, Nl_PS_consumer_expected, P_PS_expected, double.NaN, P_aux_ESS_mech_ICE_off_expected, P_aux_ESS_mech_ICE_on_expected, P_DCDC_out_expected, P_DCDC_missing_expected, P_DCDC_missing_ESS_ICE_on); @@ -416,7 +416,7 @@ namespace TUGraz.VectoCore.Tests.Models.EngineeringMode double Nl_PS_gen_expected, double Nl_PS_consumer_expected, double P_PS_expected) { var container = CreatePowerTrain(AlternatorType.Conventional, double.NaN, reessSoC, true); - + // check powertrain architecture and config Assert.NotNull(container.Components.FirstOrDefault(x => x is StopStartCombustionEngine)); Assert.NotNull(container.Components.FirstOrDefault(x => x is BusAuxiliariesAdapter)); @@ -443,8 +443,8 @@ namespace TUGraz.VectoCore.Tests.Models.EngineeringMode [TestCase(DrivingBehavior.Driving, true, 0, P_aux_m_Base + P_PS_1000 + P_ES_base / AlternatorEfficiency, P_ES_base, P_ES_base, P_ES_base / AlternatorEfficiency, 0, 0, Nl_PS, Nl_PS, P_PS_1000, TestName = "BusAux Case C2b (1); driving, ICE on")] - [TestCase(DrivingBehavior.Driving, false, 0, - 0, 0, P_ES_ICEOff_dr, 0, P_aux_m_ICEOff_dr , + [TestCase(DrivingBehavior.Driving, false, 0, + 0, 0, P_ES_ICEOff_dr, 0, P_aux_m_ICEOff_dr, P_aux_m_Base + (P_ES_base - P_ES_ICEOff_dr) / AlternatorEfficiency, 0, Nl_PS, 0, TestName = "BusAux Case C2b (2); driving, ICE off")] [TestCase(DrivingBehavior.Halted, true, 0, @@ -465,7 +465,7 @@ namespace TUGraz.VectoCore.Tests.Models.EngineeringMode double P_aux_ESS_mech_ICE_off_expected, double P_aux_ESS_mech_ICE_on_expected, double Nl_PS_gen_expected, double Nl_PS_consumer_expected, double P_PS_expected) { var container = CreatePowerTrain(AlternatorType.Conventional, batterySoC, 0.5, false); - + // check powertrain architecture and config Assert.NotNull(container.Components.FirstOrDefault(x => x is StopStartCombustionEngine)); Assert.NotNull(container.Components.FirstOrDefault(x => x is BusAuxiliariesAdapter)); @@ -602,7 +602,7 @@ namespace TUGraz.VectoCore.Tests.Models.EngineeringMode double Nl_PS_gen_expected, double Nl_PS_consumer_expected, double P_PS_expected) { var container = CreatePowerTrain(AlternatorType.Smart, batterySoC, reessSoC, true); - + // check powertrain architecture and config Assert.NotNull(container.Components.FirstOrDefault(x => x is StopStartCombustionEngine)); @@ -630,7 +630,7 @@ namespace TUGraz.VectoCore.Tests.Models.EngineeringMode P_aux_m_Base + P_PS_1000, 0, P_ES_base, P_ES_base, 0, 0, 0, Nl_PS, Nl_PS, P_PS_1000, TestName = "BusAux Case C3b (1); driving, ICE on, P0 battery not empty")] [TestCase(DrivingBehavior.Driving, true, 0, double.NaN, - P_aux_m_Base + P_PS_1000 + P_ES_base / AlternatorEfficiency, P_ES_base, 0, P_ES_base, P_ES_base / AlternatorEfficiency, 0, 0, Nl_PS, Nl_PS, P_PS_1000, + P_aux_m_Base + P_PS_1000 + P_ES_base / AlternatorEfficiency, P_ES_base, 0, P_ES_base, P_ES_base / AlternatorEfficiency, 0, 0, Nl_PS, Nl_PS, P_PS_1000, TestName = "BusAux Case C3b (2); driving, ICE on, P0 battery empty")] [TestCase(DrivingBehavior.Driving, false, 0.5, double.NaN, 0, 0, P_ES_ICEOff_dr, P_ES_ICEOff_dr, 0, P_aux_m_ICEOff_dr, P_aux_m_Base + (P_ES_base - P_ES_ICEOff_dr) / AlternatorEfficiency, 0, Nl_PS, 0, @@ -725,7 +725,7 @@ namespace TUGraz.VectoCore.Tests.Models.EngineeringMode double Nl_gen_expected, double Nl_consumed_expected, double P_PS_m_expected, double P1_recup_Pct, double P_aux_ESS_mech_ICE_off_expected, double P_aux_ESS_mech_ICE_on_expected, double? P_DCDC_out_expected, - double? P_DCDC_missing_expected, double? P_DCDC_missing_ESS_ICE_on) + double? P_DCDC_missing_expected, double? P_DCDC_missing_ESS_ICE_on) { container.VehicleStopped = drivingBehavior == DrivingBehavior.Halted; container.VehicleSpeed = drivingBehavior == DrivingBehavior.Halted @@ -774,7 +774,7 @@ namespace TUGraz.VectoCore.Tests.Models.EngineeringMode Assert.NotNull(response); Assert.IsAssignableFrom<ResponseSuccess>(response); - + container.CommitSimulationStep(absTime, dt); modData.CommitSimulationStep(); @@ -782,22 +782,22 @@ namespace TUGraz.VectoCore.Tests.Models.EngineeringMode var row = modData.Data.Rows[0]; - Assert.AreEqual(iceOn, row.Field<bool>(ModalResultField.ICEOn.GetName()), ModalResultField.ICEOn.GetName()); - Assert.AreEqual(P_auxMech_expected, row.Field<SI>(ModalResultField.P_aux_mech.GetName()).Value(), 1e-3, ModalResultField.P_aux_mech.GetName()); - Assert.AreEqual(P_busAux_ES_gen_expected, row.Field<SI>(ModalResultField.P_busAux_ES_generated.GetName()).Value(), 1e-3, ModalResultField.P_busAux_ES_generated.GetName()); - Assert.AreEqual(P_busAux_ES_consumer_sum_expected, row.Field<SI>(ModalResultField.P_busAux_ES_consumer_sum.GetName()).Value(), 1e-3, ModalResultField.P_busAux_ES_consumer_sum.GetName()); - Assert.AreEqual(P_busAux_ES_consumer_sum_expected, row.Field<SI>(ModalResultField.P_busAux_ES_other.GetName()).Value(), 1e-3, ModalResultField.P_busAux_ES_other.GetName()); - Assert.AreEqual(P_busAux_ES_mech, row.Field<SI>(ModalResultField.P_busAux_ES_sum_mech.GetName()).Value(), 1e-3, ModalResultField.P_busAux_ES_sum_mech.GetName()); + Assert.AreEqual(iceOn, (bool)row[ModalResultField.ICEOn.GetName()], ModalResultField.ICEOn.GetName()); + Assert.AreEqual(P_auxMech_expected, ((SI)row[ModalResultField.P_aux_mech.GetName()]).Value(), 1e-3, ModalResultField.P_aux_mech.GetName()); + Assert.AreEqual(P_busAux_ES_gen_expected, ((SI)row[ModalResultField.P_busAux_ES_generated.GetName()]).Value(), 1e-3, ModalResultField.P_busAux_ES_generated.GetName()); + Assert.AreEqual(P_busAux_ES_consumer_sum_expected, ((SI)row[ModalResultField.P_busAux_ES_consumer_sum.GetName()]).Value(), 1e-3, ModalResultField.P_busAux_ES_consumer_sum.GetName()); + Assert.AreEqual(P_busAux_ES_consumer_sum_expected, ((SI)row[ModalResultField.P_busAux_ES_other.GetName()]).Value(), 1e-3, ModalResultField.P_busAux_ES_other.GetName()); + Assert.AreEqual(P_busAux_ES_mech, ((SI)row[ModalResultField.P_busAux_ES_sum_mech.GetName()]).Value(), 1e-3, ModalResultField.P_busAux_ES_sum_mech.GetName()); - Assert.AreEqual(Nl_consumed_expected, row.Field<SI>(ModalResultField.Nl_busAux_PS_consumer.GetName()).Value(), 1e-3, ModalResultField.Nl_busAux_PS_consumer.GetName()); - Assert.AreEqual(Nl_gen_expected, row.Field<SI>(ModalResultField.Nl_busAux_PS_generated.GetName()).Value(), 1e-3, ModalResultField.Nl_busAux_PS_generated.GetName()); - Assert.AreEqual(P_PS_m_expected, row.Field<SI>(ModalResultField.P_busAux_PS_generated.GetName()).Value(), 1e-3, ModalResultField.P_busAux_PS_generated.GetName()); + Assert.AreEqual(Nl_consumed_expected, ((SI)row[ModalResultField.Nl_busAux_PS_consumer.GetName()]).Value(), 1e-3, ModalResultField.Nl_busAux_PS_consumer.GetName()); + Assert.AreEqual(Nl_gen_expected, ((SI)row[ModalResultField.Nl_busAux_PS_generated.GetName()]).Value(), 1e-3, ModalResultField.Nl_busAux_PS_generated.GetName()); + Assert.AreEqual(P_PS_m_expected, ((SI)row[ModalResultField.P_busAux_PS_generated.GetName()]).Value(), 1e-3, ModalResultField.P_busAux_PS_generated.GetName()); - Assert.AreEqual(P_aux_ESS_mech_ICE_off_expected, row.Field<SI>(ModalResultField.P_aux_ESS_mech_ice_off.GetName()).Value(), 1e-3, ModalResultField.P_aux_ESS_mech_ice_off.GetName()); - Assert.AreEqual(P_aux_ESS_mech_ICE_on_expected, row.Field<SI>(ModalResultField.P_aux_ESS_mech_ice_on.GetName()).Value(), 1e-3, ModalResultField.P_aux_ESS_mech_ice_on.GetName()); + Assert.AreEqual(P_aux_ESS_mech_ICE_off_expected, ((SI)row[ModalResultField.P_aux_ESS_mech_ice_off.GetName()]).Value(), 1e-3, ModalResultField.P_aux_ESS_mech_ice_off.GetName()); + Assert.AreEqual(P_aux_ESS_mech_ICE_on_expected, ((SI)row[ModalResultField.P_aux_ESS_mech_ice_on.GetName()]).Value(), 1e-3, ModalResultField.P_aux_ESS_mech_ice_on.GetName()); if (!double.IsNaN(P_bat_P0)) { - Assert.AreEqual(P_bat_P0, row.Field<SI>(ModalResultField.P_busAux_bat.GetName()).Value(), 1e-3, ModalResultField.P_busAux_bat.GetName()); + Assert.AreEqual(P_bat_P0, ((SI)row[ModalResultField.P_busAux_bat.GetName()]).Value(), 1e-3, ModalResultField.P_busAux_bat.GetName()); } else { Assert.IsTrue(container.Components.Any(x => x is NoBattery)); } @@ -809,9 +809,9 @@ namespace TUGraz.VectoCore.Tests.Models.EngineeringMode // 'consumed' and 'missing' electric energy is applied in next simulation step - read out directly and perform additional step if (reessSoC.IsEqual(REESS_MinSoC)) { Assert.AreEqual(P_DCDC_missing_expected.Value, (dcdcConverter.PreviousState.ConsumedEnergy / dt).Value(), 1e-3, ModalResultField.P_DCDC_missing.GetName()); - } else { - Assert.AreEqual(P_busAux_ES_consumer_sum_expected, (dcdcConverter.PreviousState.ConsumedEnergy / dt).Value(), 1e-3, ModalResultField.P_DCDC_Out.GetName()); - } + } else { + Assert.AreEqual(P_busAux_ES_consumer_sum_expected, (dcdcConverter.PreviousState.ConsumedEnergy / dt).Value(), 1e-3, ModalResultField.P_DCDC_Out.GetName()); + } var dcdcDemand = dcdcConverter.PowerDemand(absTime, dt, false); @@ -825,12 +825,12 @@ namespace TUGraz.VectoCore.Tests.Models.EngineeringMode dcdcConverter.CommitSimulationStep(absTime, dt, modData); modData.CommitSimulationStep(); var row1 = modData.Data.Rows[1]; - - Assert.AreEqual(P_DCDC_missing_expected.Value, row1.Field<SI>(ModalResultField.P_DCDC_missing.GetName()).Value(), 1e-3, ModalResultField.P_DCDC_missing.GetName()); - - Assert.AreEqual(P_DCDC_out_expected.Value, row1.Field<SI>(ModalResultField.P_DCDC_Out.GetName()).Value(), 1e-3, ModalResultField.P_DCDC_Out.GetName()); - Assert.AreEqual(P_DCDC_out_expected.Value / DCDCEfficiency, row1.Field<SI>(ModalResultField.P_DCDC_In.GetName()).Value(), 1e-3, ModalResultField.P_DCDC_In.GetName()); - + + Assert.AreEqual(P_DCDC_missing_expected.Value, ((SI)row1[ModalResultField.P_DCDC_missing.GetName()]).Value(), 1e-3, ModalResultField.P_DCDC_missing.GetName()); + + Assert.AreEqual(P_DCDC_out_expected.Value, ((SI)row1[ModalResultField.P_DCDC_Out.GetName()]).Value(), 1e-3, ModalResultField.P_DCDC_Out.GetName()); + Assert.AreEqual(P_DCDC_out_expected.Value / DCDCEfficiency, ((SI)row1[ModalResultField.P_DCDC_In.GetName()]).Value(), 1e-3, ModalResultField.P_DCDC_In.GetName()); + // TODO: Assertion P_DCDC_missing_ESS_ICE_on } @@ -843,17 +843,17 @@ namespace TUGraz.VectoCore.Tests.Models.EngineeringMode { //var gearboxData = CreateGearboxData(); var engineData = MockSimulationDataFactory.CreateEngineDataFromFile(EngineFileHigh, 6); - //var axleGearData = CreateAxleGearData(); - var vehicleData = CreateVehicleData(3300.SI<Kilogram>()); - //var airdragData = CreateAirdragData(); - //var driverData = CreateDriverData(AccelerationFile); + //var axleGearData = CreateAxleGearData(); + var vehicleData = CreateVehicleData(3300.SI<Kilogram>()); + //var airdragData = CreateAirdragData(); + //var driverData = CreateDriverData(AccelerationFile); - var cycleData = DrivingCycleDataReader.ReadFromStream("s,v,grad,stop\n0,0,0,10\n10,20,0,0\n20,21,0,0\n30,22,0,0\n40,23,0,0\n50,24,0,0\n60,25,0,0\n70,26,0,0\n80,27,0,0\n90,28,0,0\n100,29,0,0".ToStream(), CycleType.DistanceBased, "DummyCycle", false); + var cycleData = DrivingCycleDataReader.ReadFromStream("s,v,grad,stop\n0,0,0,10\n10,20,0,0\n20,21,0,0\n30,22,0,0\n40,23,0,0\n50,24,0,0\n60,25,0,0\n70,26,0,0\n80,27,0,0\n90,28,0,0\n100,29,0,0".ToStream(), CycleType.DistanceBased, "DummyCycle", false); var runData = new VectoRunData() { JobRunId = 0, - VehicleData = vehicleData, - EngineData = engineData, + VehicleData = vehicleData, + EngineData = engineData, ElectricMachinesData = new List<Tuple<PowertrainPosition, ElectricMotorData>>(), SimulationType = SimulationType.DistanceCycle, Cycle = cycleData, @@ -867,16 +867,16 @@ namespace TUGraz.VectoCore.Tests.Models.EngineeringMode }; var container = new MockVehicleContainer() { - CycleData = new CycleData() { LeftSample = cycleData.Entries.First()}, - ModalData = modData, + CycleData = new CycleData() { LeftSample = cycleData.Entries.First() }, + ModalData = modData, HasCombustionEngine = true, HasElectricMotor = false, RunData = runData }; var engine = new StopStartCombustionEngine(container, engineData); - + container.EngineInfo = engine; - + var conventionalAux = CreateAuxiliaries(runData.Aux, container); var aux = new BusAuxiliariesAdapter(container, runData.BusAuxiliaries, conventionalAux); @@ -1075,7 +1075,7 @@ namespace TUGraz.VectoCore.Tests.Models.EngineeringMode return retVal; } - + private static VehicleData CreateVehicleData(Kilogram loading) { diff --git a/VectoCore/VectoCoreTest/Reports/ModDataPostprocessingTest.cs b/VectoCore/VectoCoreTest/Reports/ModDataPostprocessingTest.cs index b5fa9cc8fb..e3d45137c2 100644 --- a/VectoCore/VectoCoreTest/Reports/ModDataPostprocessingTest.cs +++ b/VectoCore/VectoCoreTest/Reports/ModDataPostprocessingTest.cs @@ -885,7 +885,7 @@ namespace TUGraz.VectoCore.Tests.Reports fuel.ConsumptionMap.GetFuelConsumption(0.SI<NewtonMeter>(), runData.EngineData.IdleSpeed).Value .Value() * fuel.FuelConsumptionCorrectionFactor; - var dts = modData.GetValues(x => x.Field<Second>(ModalResultField.simulationInterval.GetName())).ToArray(); + var dts = modData.GetValues(x => (Second)x[ModalResultField.simulationInterval.GetName()]).ToArray(); var time = modData.GetValues<Second>(ModalResultField.time).ToArray(); diff --git a/VectoCore/VectoCoreTest/Reports/ModDataTest.cs b/VectoCore/VectoCoreTest/Reports/ModDataTest.cs index 01364b48d3..fa280cfa5e 100644 --- a/VectoCore/VectoCoreTest/Reports/ModDataTest.cs +++ b/VectoCore/VectoCoreTest/Reports/ModDataTest.cs @@ -278,15 +278,15 @@ namespace TUGraz.VectoCore.Tests.Reports Second tracStart = null; foreach (DataRow row in modData.Rows) { - var velocity = row.Field<MeterPerSecond>(ModalResultField.v_act.GetName()); + var velocity = (MeterPerSecond)row[ModalResultField.v_act.GetName()]; if (velocity.IsEqual(0)) { tracStart = null; continue; } - var gear = row.Field<uint>(ModalResultField.Gear.GetName()); - var absTime = row.Field<Second>(ModalResultField.time.GetName()); - var dt = row.Field<Second>(ModalResultField.simulationInterval.GetName()); + var gear = (uint)row[ModalResultField.Gear.GetName()]; + var absTime = (Second)row[ModalResultField.time.GetName()]; + var dt = (Second)row[ModalResultField.simulationInterval.GetName()]; if (gear == 0 && tracStart == null) { tracStart = absTime - dt / 2.0; } @@ -553,8 +553,8 @@ namespace TUGraz.VectoCore.Tests.Reports { Assert.IsTrue(modData.Rows.Count > 0); - var ptoTransmissionColumn = auxKeys.GetValueOrDefault(Constants.Auxiliaries.IDs.PTOTransmission); - var ptoConsumerColumn = auxKeys.GetValueOrDefault(Constants.Auxiliaries.IDs.PTOConsumer); + var ptoTransmissionColumn = auxKeys.GetVECTOValueOrDefault(Constants.Auxiliaries.IDs.PTOTransmission); + var ptoConsumerColumn = auxKeys.GetVECTOValueOrDefault(Constants.Auxiliaries.IDs.PTOConsumer); foreach (DataRow row in modData.Rows) { if (distanceBased && totalDistance.IsEqual(((Meter)row[ModalResultField.dist.GetName()]).Value())) { continue; @@ -686,8 +686,8 @@ namespace TUGraz.VectoCore.Tests.Reports { Assert.IsTrue(modData.Rows.Count > 0); - var ptoTransmissionColumn = auxKeys.GetValueOrDefault(Constants.Auxiliaries.IDs.PTOTransmission); - var ptoConsumerColumn = auxKeys.GetValueOrDefault(Constants.Auxiliaries.IDs.PTOConsumer); + var ptoTransmissionColumn = auxKeys.GetVECTOValueOrDefault(Constants.Auxiliaries.IDs.PTOTransmission); + var ptoConsumerColumn = auxKeys.GetVECTOValueOrDefault(Constants.Auxiliaries.IDs.PTOConsumer); var p1OutColumn = modData.Columns[string.Format(ModalResultField.P_EM_out_.GetCaption(), PowertrainPosition.HybridP1.GetName())]; @@ -889,8 +889,8 @@ namespace TUGraz.VectoCore.Tests.Reports { Assert.IsTrue(modData.Rows.Count > 0); - var ptoTransmissionColumn = auxKeys.GetValueOrDefault(Constants.Auxiliaries.IDs.PTOTransmission); - var ptoConsumerColumn = auxKeys.GetValueOrDefault(Constants.Auxiliaries.IDs.PTOConsumer); + var ptoTransmissionColumn = auxKeys.GetVECTOValueOrDefault(Constants.Auxiliaries.IDs.PTOTransmission); + var ptoConsumerColumn = auxKeys.GetVECTOValueOrDefault(Constants.Auxiliaries.IDs.PTOConsumer); foreach (DataRow row in modData.Rows) { if (totalDistance.IsEqual(((Meter)row[ModalResultField.dist.GetName()]))) { continue; diff --git a/VectoCore/VectoCoreTest/Utils/GraphWriter.cs b/VectoCore/VectoCoreTest/Utils/GraphWriter.cs index c34ae728ea..138d96bcf7 100644 --- a/VectoCore/VectoCoreTest/Utils/GraphWriter.cs +++ b/VectoCore/VectoCoreTest/Utils/GraphWriter.cs @@ -35,14 +35,14 @@ using System.Data; using System.IO; using System.Drawing; using System.Linq; +#if !NET5_0_OR_GREATER using System.Windows.Forms.DataVisualization.Charting; +#endif using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Utils; -// ReSharper disable UnusedVariable - namespace TUGraz.VectoCore.Tests.Utils { public class GraphWriter @@ -51,9 +51,11 @@ namespace TUGraz.VectoCore.Tests.Utils private Size _diagramSize = new Size(2000, 440); +#if !NET5_0_OR_GREATER private readonly Font AxisLabelFont = new Font("Consolas", 10); private readonly Font AxisTitleFont = new Font("Verdana", 12); private readonly Font LegendFont = new Font("Verdana", 14); +#endif public string Series2Label { get; set; } @@ -79,6 +81,7 @@ namespace TUGraz.VectoCore.Tests.Utils public void Write(string fileNameV3, string fileNameV22 = null) { +#if !NET5_0_OR_GREATER if (!_enabled) { return; } @@ -214,6 +217,7 @@ namespace TUGraz.VectoCore.Tests.Utils chart.Invalidate(); chart.SaveImage(Path.Combine(Path.GetDirectoryName(fileNameV3) ?? "", fileName), ChartImageFormat.Png); } +#endif } private string TranslateFieldname(ModalResultField modalResultField) @@ -236,6 +240,7 @@ namespace TUGraz.VectoCore.Tests.Utils public bool WriteDistanceSlice(string fileNameV3, string fileNameV22, double start, double end) { +#if !NET5_0_OR_GREATER if (!_enabled) { return true; } @@ -245,10 +250,10 @@ namespace TUGraz.VectoCore.Tests.Utils // RowFilter = string.Format(@"dist > {0} AND dist < {1}", start, end) //}; //var modDataV3 = modDataV3View.ToTable(); - var modDataV3Tmp = modDataV3Iput.AsEnumerable().Where(row => { + var modDataV3Tmp = modDataV3Iput.Rows.Cast<DataRow>().Where(row => { var s = row.ParseDouble("dist"); return s >= start && s <= end; - }); + }).ToList(); if (!File.Exists(fileNameV22)) { //LogManager.GetCurrentClassLogger().Error("Modfile V2.2 not found: " + fileNameV22); @@ -261,20 +266,25 @@ namespace TUGraz.VectoCore.Tests.Utils //var modDataV22View = new DataView(modDataV22Input) { // RowFilter = string.Format(@"dist > {0} AND dist < {1}", start, end) //}; - var modDataV22Tmp = modDataV22Input.AsEnumerable().Where(row => { + var modDataV22Tmp = modDataV22Input.Rows.Cast<DataRow>().Where(row => { var s = row.ParseDouble("dist"); return s >= start && s <= end; - }); + }).ToList(); if (!(modDataV3Tmp.Any() || modDataV22Tmp.Any())) { return false; } - modDataV22 = modDataV22Tmp.CopyToDataTable(); + + var d = new DataTable(); + modDataV22Tmp.ForEach(r => d.Rows.Add(r)); + modDataV22 = d; } else { if (!modDataV3Tmp.Any()) { return false; } } - var modDataV3 = modDataV3Tmp.CopyToDataTable(); + + var modDataV3 = new DataTable(); + modDataV3Tmp.ForEach(r => modDataV3.Rows.Add(r)); //var xfields = new[] { ModalResultField.dist }; var xfield = ModalResultField.dist; @@ -351,9 +361,11 @@ namespace TUGraz.VectoCore.Tests.Utils chart.Invalidate(); chart.SaveImage(fileName, ChartImageFormat.Png); } +#endif return true; } +#if !NET5_0_OR_GREATER private static void AddTitle(Chart chart, string titleText, string dockToChartArea) { var title = new Title { @@ -369,14 +381,14 @@ namespace TUGraz.VectoCore.Tests.Utils { var field = string.Format(fieldA, ""); return modDataV3.Rows.Cast<DataRow>() - .Select(v => v.Field<string>(field).Length == 0 + .Select(v => ((string)v[field]).Length == 0 ? double.NaN - : v.Field<string>(field).ToDouble()) + : ((string)v[field]).ToDouble()) .ToArray(); } private static double[] LoadDataMapped(DataTable modDataV3, string field, Dictionary<string, double> mapping) => - modDataV3.Rows.Cast<DataRow>().Select(x => mapping.GetValueOrDefault(x.Field<string>(field), double.NaN)).ToArray(); + modDataV3.Rows.Cast<DataRow>().Select(x => mapping.GetValueOrDefault(((string)x[field]), double.NaN)).ToArray(); private static void AlignChart(Chart chart, string chartToAlign, string chartToAlignWith) { @@ -460,5 +472,6 @@ namespace TUGraz.VectoCore.Tests.Utils chart.Series[series1.Name].Points.DataBindXY(x, y); return series1; } +#endif } } \ No newline at end of file diff --git a/VectoCore/VectoCoreTest/Utils/MockModalDataContainer.cs b/VectoCore/VectoCoreTest/Utils/MockModalDataContainer.cs index e657b2bc76..187ddf2d5b 100644 --- a/VectoCore/VectoCoreTest/Utils/MockModalDataContainer.cs +++ b/VectoCore/VectoCoreTest/Utils/MockModalDataContainer.cs @@ -183,37 +183,25 @@ namespace TUGraz.VectoCore.Tests.Utils public bool WriteModalResults { get; set; } - public IEnumerable<T> GetValues<T>(ModalResultField key) - { - return Data.Rows.Cast<DataRow>().Select(x => x.Field<T>((int)key)); - } + public IEnumerable<T> GetValues<T>(ModalResultField key) => + Data.Rows.Cast<DataRow>().Select(x => (T)x[(int)key]); - public IEnumerable<T> GetValues<T>(DataColumn col) - { - return Data.Rows.Cast<DataRow>().Select(x => x.Field<T>(col)); - } + public IEnumerable<T> GetValues<T>(DataColumn col) => + Data.Rows.Cast<DataRow>().Select(x => (T)x[col]); - public IEnumerable<T> GetValues<T>(Func<DataRow, T> selectorFunc) - { + public IEnumerable<T> GetValues<T>(Func<DataRow, T> selectorFunc) => throw new NotImplementedException(); - } - public T TimeIntegral<T>(ModalResultField field, Func<SI, bool> filter = null) where T : SIBase<T> - { + public T TimeIntegral<T>(ModalResultField field, Func<SI, bool> filter = null) where T : SIBase<T> => throw new NotImplementedException(); - } - public T TimeIntegral<T>(string field, Func<SI, bool> filter = null) where T : SIBase<T> - { + public T TimeIntegral<T>(string field, Func<SI, bool> filter = null) where T : SIBase<T> => throw new NotImplementedException(); - } public Dictionary<string, DataColumn> Auxiliaries { get; set; } - public void SetDataValue(string fieldName, object value) - { + public void SetDataValue(string fieldName, object value) => throw new NotImplementedException(); - } public void AddAuxiliary(string id, string columnName = null) { diff --git a/VectoCore/VectoCoreTest/Utils/ResultFileHelper.cs b/VectoCore/VectoCoreTest/Utils/ResultFileHelper.cs index 1502ea3b16..6075287c61 100644 --- a/VectoCore/VectoCoreTest/Utils/ResultFileHelper.cs +++ b/VectoCore/VectoCoreTest/Utils/ResultFileHelper.cs @@ -60,7 +60,7 @@ namespace TUGraz.VectoCore.Tests.Utils var actual = VectoCSVFile.Read(result.actualFile); if (actual.Columns.Contains(ModalResultField.v_act.GetShortCaption()) && - !double.IsNaN(actual.Rows[0].Field<string>(ModalResultField.v_act.GetShortCaption()).ToDouble(double.NaN))) { + !double.IsNaN(((string)actual.Rows[0][ModalResultField.v_act.GetShortCaption()]).ToDouble(double.NaN))) { // test v_act >= 0 Assert.IsTrue(actual.Rows.Cast<DataRow>() .All(r => r.ParseDouble(ModalResultField.v_act.GetShortCaption()).IsGreaterOrEqual(0)), @@ -73,7 +73,7 @@ namespace TUGraz.VectoCore.Tests.Utils } if (actual.Columns.Contains(ModalResultField.dist.GetShortCaption()) && - !double.IsNaN(actual.Rows[0].Field<string>(ModalResultField.dist.GetShortCaption()).ToDouble(double.NaN))) { + !double.IsNaN(((string)actual.Rows[0][ModalResultField.dist.GetShortCaption()]).ToDouble(double.NaN))) { // test distance monotonous increasing var distPrev = actual.Rows[0].ParseDouble(ModalResultField.dist.GetShortCaption()); diff --git a/VectoCore/VectoCoreTest/Utils/ShiftPolygonDrawer.cs b/VectoCore/VectoCoreTest/Utils/ShiftPolygonDrawer.cs index c4895538f5..fb45cac245 100644 --- a/VectoCore/VectoCoreTest/Utils/ShiftPolygonDrawer.cs +++ b/VectoCore/VectoCoreTest/Utils/ShiftPolygonDrawer.cs @@ -33,7 +33,9 @@ using System; using System.Collections.Generic; using System.Drawing; using System.Linq; +#if !NET5_0_OR_GREATER using System.Windows.Forms.DataVisualization.Charting; +#endif using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine; @@ -44,17 +46,20 @@ namespace TUGraz.VectoCore.Tests.Utils { public class ShiftPolygonDrawer { +#if !NET5_0_OR_GREATER private static readonly Font AxisLabelFont = new Font("Consolas", 10); private static readonly Font AxisTitleFont = new Font("Verdana", 12); private static readonly Font LegendFont = new Font("Verdana", 14); - +#endif private static Size _diagramSize = new Size(1000, 800); + public static void DrawShiftPolygons(string title, Dictionary<uint, EngineFullLoadCurve> engineFld, List<ShiftPolygon> polygons, string imageFileName, PerSecond speed85kmh, List<List<Point>> upshiftOrig = null, List<List<Point>> downshiftTransformed = null, List<List<Point>> downshiftOrig = null) { +#if !NET5_0_OR_GREATER var numRows = Math.Ceiling(polygons.Count / 4.0); var numCols = Math.Ceiling(polygons.Count / numRows); @@ -70,7 +75,7 @@ namespace TUGraz.VectoCore.Tests.Utils var chartArea = AddChartArea(chart, "Gear " + (i + 1), "Engine Speed", "Torque", 0, maxX); PlotPower(engineFld[(uint)(i + 1)], chartArea, chart, "engine power " + i); - PlotFLD(engineFld[(uint)(i +1)], speed85kmh, chartArea, chart, "Engine Full Load " + i); + PlotFLD(engineFld[(uint)(i + 1)], speed85kmh, chartArea, chart, "Engine Full Load " + i); if (upshiftOrig != null && i < upshiftOrig.Count) { PlotShiftLine("UpshiftOrig " + i, chartArea, chart, Color.Gray, @@ -99,8 +104,10 @@ namespace TUGraz.VectoCore.Tests.Utils AddTitle(chart, title); chart.Invalidate(); chart.SaveImage(imageFileName, ChartImageFormat.Png); +#endif } +#if !NET5_0_OR_GREATER private static void PlotPower(EngineFullLoadCurve engineFld, ChartArea chartArea, Chart chart, string name) { var series = new Series { @@ -389,5 +396,6 @@ namespace TUGraz.VectoCore.Tests.Utils }); chart.Legends.Add(legend); } +#endif } } \ No newline at end of file diff --git a/VectoCore/VectoCoreTest/VectoCoreTest.csproj b/VectoCore/VectoCoreTest/VectoCoreTest.csproj index 0580331a0e..4416e66636 100644 --- a/VectoCore/VectoCoreTest/VectoCoreTest.csproj +++ b/VectoCore/VectoCoreTest/VectoCoreTest.csproj @@ -4,7 +4,7 @@ <RootNamespace>TUGraz.VectoCore.Tests</RootNamespace> <AssemblyName>VectoCoreTest</AssemblyName> <DefineConstants /> - <TargetFrameworks>net5.0</TargetFrameworks> + <TargetFrameworks>net45;net5.0</TargetFrameworks> </PropertyGroup> @@ -18,6 +18,11 @@ <PackageReference Include="NLog" Version="4.7.13" /> </ItemGroup> + <ItemGroup Condition="'$(TargetFramework)' == 'net45' or '$(TargetFramework)' == 'net48'"> + <Reference Include="System.Windows.Forms" /> + <Reference Include="System.Windows.Forms.DataVisualization" /> + </ItemGroup> + <ItemGroup> <ProjectReference Include="..\..\VectoCommon\VectoCommon\VectoCommon.csproj" /> <ProjectReference Include="..\..\VectoCommon\VectoHashing\VectoHashing.csproj" /> -- GitLab