From 93ab1617a3a1d3c25af1760975d0111cfca8cb36 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Thu, 22 Jul 2021 15:30:31 +0200
Subject: [PATCH] make min-speed for downshift polygon a parameter

---
 VECTO/Input Files/Gearbox.vb                         |  6 ++++++
 .../VectoCommon/InputData/EngineeringInputData.cs    |  1 +
 .../InputData/FileIO/JSON/JSONGearboxData.cs         |  1 +
 .../VectoCore/InputData/FileIO/JSON/JSONTCUData.cs   | 12 ++++++++++++
 .../DataProvider/XMLEngineeringGearshiftData.cs      |  1 +
 .../DataObjectAdapter/EngineeringDataAdapter.cs      |  4 ++++
 .../Impl/EngineeringModeVectoRunDataFactory.cs       |  8 +++++---
 .../VectoCore/Models/Declaration/DeclarationData.cs  |  4 ++--
 .../Simulation/Data/ShiftStrategyParameters.cs       |  2 ++
 .../SimulationComponent/Impl/PEVAMTShiftStrategy.cs  |  9 +++++----
 10 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/VECTO/Input Files/Gearbox.vb b/VECTO/Input Files/Gearbox.vb
index 6557266cd2..6837d30156 100644
--- a/VECTO/Input Files/Gearbox.vb	
+++ b/VECTO/Input Files/Gearbox.vb	
@@ -714,6 +714,12 @@ Public Class Gearbox
     End Get
     End Property
 
+    Public ReadOnly Property PEV_DownshiftMinSpeedFactor As Double? Implements IGearshiftEngineeringInputData.PEV_DownshiftMinSpeedFactor
+    get
+        Return Nothing
+    End Get
+    End Property
+
     Public Overridable ReadOnly Property LoadStageShiftLines As TableData _
         Implements IGearshiftEngineeringInputData.LoadStageShiftLines
         Get
diff --git a/VectoCommon/VectoCommon/InputData/EngineeringInputData.cs b/VectoCommon/VectoCommon/InputData/EngineeringInputData.cs
index 60f3d8ee3f..9bad37f2c1 100644
--- a/VectoCommon/VectoCommon/InputData/EngineeringInputData.cs
+++ b/VectoCommon/VectoCommon/InputData/EngineeringInputData.cs
@@ -345,6 +345,7 @@ namespace TUGraz.VectoCommon.InputData
 		double? PEV_TargetSpeedBrakeNorm { get; }
 
 		double? PEV_DeRatingDownshiftSpeedFactor { get; }
+		double? PEV_DownshiftMinSpeedFactor { get; }
 	}
 
 	public interface ITorqueConverterEngineeringShiftParameterInputData
diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONGearboxData.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONGearboxData.cs
index bcd78e9aa5..6fb42f0531 100644
--- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONGearboxData.cs
+++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONGearboxData.cs
@@ -373,6 +373,7 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON
 		public double[][] ShiftSpeedsTCToLocked => null;
 		public double? PEV_TargetSpeedBrakeNorm => null;
 		public double? PEV_DeRatingDownshiftSpeedFactor => null;
+		public double? PEV_DownshiftMinSpeedFactor => null;
 
 		public double? VeloictyDropFactor => null;
 
diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONTCUData.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONTCUData.cs
index bc8163614b..29ff6cda9a 100644
--- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONTCUData.cs
+++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONTCUData.cs
@@ -277,6 +277,18 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON
 			}
 		}
 
+		public double? PEV_DownshiftMinSpeedFactor
+		{
+			get
+			{
+				if (Body["PEV_DownshiftMinSpeedFactor"] != null) {
+					return Body.GetEx<double>("PEV_DownshiftMinSpeedFactor");
+				}
+
+				return null;
+			}
+		}
+
 		public TableData LoadStageShiftLines
 		{
 			get {
diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/DataProvider/XMLEngineeringGearshiftData.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/DataProvider/XMLEngineeringGearshiftData.cs
index 0b2f7cb8a9..9ad57f3e2e 100644
--- a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/DataProvider/XMLEngineeringGearshiftData.cs
+++ b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/DataProvider/XMLEngineeringGearshiftData.cs
@@ -123,6 +123,7 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering.DataProvider
 		public double[][] ShiftSpeedsTCToLocked => null;
 		public double? PEV_TargetSpeedBrakeNorm => null;
 		public double? PEV_DeRatingDownshiftSpeedFactor => null;
+		public double? PEV_DownshiftMinSpeedFactor => null;
 
 		public double? AccelerationFactor => null;
 
diff --git a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/EngineeringDataAdapter.cs b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/EngineeringDataAdapter.cs
index 3de3e8c687..57845fede5 100644
--- a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/EngineeringDataAdapter.cs
+++ b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/EngineeringDataAdapter.cs
@@ -699,6 +699,10 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter
 				retVal.PEV_TargetSpeedBrakeNorm = gsInputData.PEV_TargetSpeedBrakeNorm.Value;
 			}
 
+			if (gsInputData.PEV_DownshiftMinSpeedFactor != null) {
+				retVal.PEV_DownshiftMinSpeedFactor = gsInputData.PEV_DownshiftMinSpeedFactor.Value;
+			}
+
 			return retVal;
 		}
 
diff --git a/VectoCore/VectoCore/InputData/Reader/Impl/EngineeringModeVectoRunDataFactory.cs b/VectoCore/VectoCore/InputData/Reader/Impl/EngineeringModeVectoRunDataFactory.cs
index 09ada9253a..2334d59154 100644
--- a/VectoCore/VectoCore/InputData/Reader/Impl/EngineeringModeVectoRunDataFactory.cs
+++ b/VectoCore/VectoCore/InputData/Reader/Impl/EngineeringModeVectoRunDataFactory.cs
@@ -96,12 +96,16 @@ namespace TUGraz.VectoCore.InputData.Reader.Impl
 				AngledriveData angledriveData = null;
 				if (electricMachinesData.Any(x => x.Item1 == PowertrainPosition.BatteryElectricE2)) {
 					// gearbox required!
+					gearshiftParams = dao.CreateGearshiftData(
+						InputDataProvider.JobInputData.Vehicle.Components.GearboxInputData.Type, InputDataProvider.DriverInputData.GearshiftInputData,
+						axlegearData.AxleGear.Ratio * (angledriveData?.Angledrive.Ratio ?? 1.0), null);
 					var tmpRunData = new VectoRunData() {
 						JobType = VectoSimulationJobType.BatteryElectricVehicle,
 						ShiftStrategy = InputDataProvider.JobInputData.ShiftStrategy,
 						GearboxData = new GearboxData() {
 							Type = vehicle.Components.GearboxInputData.Type,
 						},
+						GearshiftParameters = gearshiftParams
 						//ElectricMachinesData = electricMachinesData,
 						//VehicleData = dao.CreateVehicleData(vehicle)
 					};
@@ -115,9 +119,7 @@ namespace TUGraz.VectoCore.InputData.Reader.Impl
 							ElectricMachinesData = electricMachinesData
 						}, tmpStrategy);
 					angledriveData = dao.CreateAngledriveData(vehicle.Components.AngledriveInputData);
-					gearshiftParams = dao.CreateGearshiftData(
-						gearboxData.Type, InputDataProvider.DriverInputData.GearshiftInputData,
-						axlegearData.AxleGear.Ratio * (angledriveData?.Angledrive.Ratio ?? 1.0),null);
+					
 				}
 
 				if (gearshiftParams == null) {
diff --git a/VectoCore/VectoCore/Models/Declaration/DeclarationData.cs b/VectoCore/VectoCore/Models/Declaration/DeclarationData.cs
index a60b1be4fd..31ea13e776 100644
--- a/VectoCore/VectoCore/Models/Declaration/DeclarationData.cs
+++ b/VectoCore/VectoCore/Models/Declaration/DeclarationData.cs
@@ -622,7 +622,7 @@ namespace TUGraz.VectoCore.Models.Declaration
 
 			public static ShiftPolygon ComputeElectricMotorShiftPolygon(int gearIdx,
 				ElectricMotorFullLoadCurve fullLoadCurve, double emRatio, IList<ITransmissionInputData> gears,
-				double axlegearRatio, Meter dynamicTyreRadius, PerSecond downshiftMaxSpeed = null)
+				double axlegearRatio, Meter dynamicTyreRadius, PerSecond downshiftMaxSpeed = null, PerSecond downshiftMinSpeed = null)
 			{
 				if (gears.Count < 2) {
 					throw new VectoException("ComputeShiftPolygon needs at least 2 gears. {0} gears given.", gears.Count);
@@ -632,7 +632,7 @@ namespace TUGraz.VectoCore.Models.Declaration
 				var upShift = new List<ShiftPolygon.ShiftPolygonEntry>();
 				if (gearIdx > 0) {
 					var nMax = downshiftMaxSpeed ?? fullLoadCurve.NP80low;
-					var nMin = 0.1 * fullLoadCurve.RatedSpeed;
+					var nMin = downshiftMinSpeed ?? 0.1 * fullLoadCurve.RatedSpeed;
 
 					downShift.AddRange(DownshiftLineDrive(fullLoadCurve, nMin, nMax));
 					downShift.AddRange(DownshiftLineDrag(fullLoadCurve, nMin, nMax));
diff --git a/VectoCore/VectoCore/Models/Simulation/Data/ShiftStrategyParameters.cs b/VectoCore/VectoCore/Models/Simulation/Data/ShiftStrategyParameters.cs
index bc6264d349..ce834f26fe 100644
--- a/VectoCore/VectoCore/Models/Simulation/Data/ShiftStrategyParameters.cs
+++ b/VectoCore/VectoCore/Models/Simulation/Data/ShiftStrategyParameters.cs
@@ -10,6 +10,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Data {
 	{
 		public ShiftStrategyParameters()
 		{
+			PEV_DownshiftMinSpeedFactor = 0.1;
 			PEV_TargetSpeedBrakeNorm = 0.7;
 			PEV_DeRatedDownshiftSpeedFactor = 1;
 		}
@@ -109,5 +110,6 @@ namespace TUGraz.VectoCore.Models.Simulation.Data {
 		public double[][] ShiftSpeedsTCToLocked { get; set; }
 		public double PEV_TargetSpeedBrakeNorm { get; set; }
 		public double PEV_DeRatedDownshiftSpeedFactor { get; set; }
+		public double PEV_DownshiftMinSpeedFactor { get; set; }
 	}
 }
\ No newline at end of file
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PEVAMTShiftStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PEVAMTShiftStrategy.cs
index b0f63c7da7..f9db0338a6 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PEVAMTShiftStrategy.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PEVAMTShiftStrategy.cs
@@ -114,18 +114,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			ElectricMotorData electricMotorData = null)
 		{
 			return ComputeDeclarationShiftPolygon(i, gearboxGears, axlegearRatio, dynamicTyreRadius, electricMotorData,
-				null);
+				null, shiftStrategyParameters.PEV_DownshiftMinSpeedFactor * electricMotorData.EfficiencyData.VoltageLevels.First().FullLoadCurve.RatedSpeed);
 		}
 
 
 		public ShiftPolygon ComputeDeclarationShiftPolygon(int i,
 			IList<ITransmissionInputData> gearboxGears, double axlegearRatio,
 			Meter dynamicTyreRadius,
-			ElectricMotorData electricMotorData , PerSecond downshiftMaxSpeed )
+			ElectricMotorData electricMotorData, PerSecond downshiftMaxSpeed, PerSecond downshiftMinSpeed)
 		{
 			return DeclarationData.Gearbox.ComputeElectricMotorShiftPolygon(i,
 				electricMotorData.EfficiencyData.VoltageLevels.First().FullLoadCurve, electricMotorData.RatioADC,
-				gearboxGears, axlegearRatio, dynamicTyreRadius, downshiftMaxSpeed);
+				gearboxGears, axlegearRatio, dynamicTyreRadius, downshiftMaxSpeed, downshiftMinSpeed);
 		}
 
 		#endregion
@@ -160,7 +160,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			for (var i = 0u; i < gearData.Count; i++) {
 				var shiftPolygon = ComputeDeclarationShiftPolygon((int)i,
 					gearData, axleGearRatio,
-					rDyn,  limitedEm, shiftStrategyParameters.PEV_DeRatedDownshiftSpeedFactor * emFld.RatedSpeed);
+					rDyn, limitedEm, shiftStrategyParameters.PEV_DeRatedDownshiftSpeedFactor * emFld.RatedSpeed,
+					shiftStrategyParameters.PEV_DownshiftMinSpeedFactor * emFld.RatedSpeed);
 				retVal[i + 1] = shiftPolygon;
 			}
 
-- 
GitLab