From 8e9ba8e43d4ee2cfc245c837666815bec19b7dff Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Tue, 1 Dec 2020 13:10:17 +0100
Subject: [PATCH] bugfix max speed calculation for e-motor, further fixes for
 PEV revert changes in velocity gearshift preprocessor correct name of
 generated file in testcase

---
 .../Models/SimulationComponent/Impl/ElectricMotor.cs | 12 +++++++++---
 .../Impl/VelocitySpeedGearshiftPreprocessor.cs       |  4 ++--
 .../BatteryElectric/BatteryElectricTest.cs           |  2 +-
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ElectricMotor.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ElectricMotor.cs
index d84db22b5d..156332e54c 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ElectricMotor.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ElectricMotor.cs
@@ -56,7 +56,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 		public PowertrainPosition Position { get; }
 		public PerSecond MaxSpeed
 		{
-			get { return _maxSpeed ?? (_maxSpeed = ModelData.FullLoadCurve.FullLoadEntries.MaxBy(x => x.MotorSpeed).MotorSpeed) / ModelData.Ratio; }
+			get { return _maxSpeed ?? (_maxSpeed = (ModelData.FullLoadCurve.FullLoadEntries.MaxBy(x => x.MotorSpeed).MotorSpeed) / ModelData.Ratio); }
 		}
 
 		public Watt DragPower(PerSecond electricMotorSpeed)
@@ -192,6 +192,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 				emTorque = 0.SI<NewtonMeter>();
 			}
 
+			if (Position == PowertrainPosition.BatteryElectricE2 && !DataBus.GearboxInfo.GearEngaged(absTime)) {
+				// electric motor is after the gearbox but no gear engaged - ignore inertia and drag...
+				emTorqueDt = 0.SI<NewtonMeter>();
+				emTorque = 0.SI<NewtonMeter>();
+			}
+
 			if (ElectricPower == null || emTorqueDt == null) {
 				// no electric system or EM shall be off - apply drag only
 				// if EM is off, calculate EM drag torque 'forward' to be applied on drivetrain
@@ -218,8 +224,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 
 			var electricSupplyResponse =
 				ElectricPower.Request(absTime, dt, electricPower, dryRun);
-			if (!dryRun && !(electricSupplyResponse is ElectricSystemResponseSuccess)) {
-				if (!emOff && DataBus.HybridControllerInfo != null && !avgEmSpeed.IsEqual(DataBus.HybridControllerInfo.ElectricMotorSpeed(Position))) {
+			if (!dryRun && !emOff && !(electricSupplyResponse is ElectricSystemResponseSuccess)) {
+				if (DataBus.HybridControllerInfo != null && !avgEmSpeed.IsEqual(DataBus.HybridControllerInfo.ElectricMotorSpeed(Position))) {
 					return new ResponseInvalidOperatingPoint(this);
 				}
 				throw new VectoException(
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/VelocitySpeedGearshiftPreprocessor.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/VelocitySpeedGearshiftPreprocessor.cs
index efdc23d265..45b4997ec4 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/VelocitySpeedGearshiftPreprocessor.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/VelocitySpeedGearshiftPreprocessor.cs
@@ -155,7 +155,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 					acceleration, delta, Constants.SimulationSettings.OperatingPointInitialSearchIntervalAccelerating,
 					getYValue: response => {
 						var r = (ResponseDryRun)response;
-						return r.Clutch.PowerRequest;
+						return r.Gearbox.PowerRequest;
 					},
 					evaluateFunction: acc => {
 						var response = vehicle.Request(time, simulationInterval, acc, gradient, true);
@@ -164,7 +164,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 					},
 					criterion: response => {
 						var r = (ResponseDryRun)response;
-						return r.Clutch.PowerRequest.Value() * 100;
+						return r.Gearbox.PowerRequest.Value() * 100;
 					},
 					abortCriterion: (response, cnt) => {
 						var r = (ResponseDryRun)response;
diff --git a/VectoCore/VectoCoreTest/Integration/BatteryElectric/BatteryElectricTest.cs b/VectoCore/VectoCoreTest/Integration/BatteryElectric/BatteryElectricTest.cs
index 624940ba9d..2bb7c1795b 100644
--- a/VectoCore/VectoCoreTest/Integration/BatteryElectric/BatteryElectricTest.cs
+++ b/VectoCore/VectoCoreTest/Integration/BatteryElectric/BatteryElectricTest.cs
@@ -496,7 +496,7 @@ namespace TUGraz.VectoCore.Tests.Integration.BatteryElectric
 
 			const bool largeMotor = true;
 
-			var modFilename = string.Format("SimpleParallelHybrid-B2_cycle_{0}-{1}_{2}_{3}", declarationMission, initialSoC, payload, pAuxEl);
+			var modFilename = string.Format("SimpleBatteryElectric-B2_cycle_{0}-{1}_{2}_{3}", declarationMission, initialSoC, payload, pAuxEl);
 			const PowertrainPosition pos = PowertrainPosition.BatteryElectricE2;
 			var job = CreateEngineeringRun(
 				cycle, modFilename, initialSoC, pos, 2, 2, largeMotor: true);
-- 
GitLab