From a4eb89aba24b5630e66633d067c907eb6ef7cb1f Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Wed, 7 Sep 2022 09:08:00 +0200
Subject: [PATCH] bugfix in initializing gear in case of P2 or P2.5 hybrids:
 initialize engine with correct beforehand to avoid unreasonaable high inertia
 torque

---
 .../VectoCore/Models/SimulationComponent/Impl/Gearbox.cs  | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
index 86c5c945cb..ddee69f230 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs
@@ -29,7 +29,9 @@
 *   Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology
 */
 
+using System.Linq;
 using TUGraz.VectoCommon.Exceptions;
+using TUGraz.VectoCommon.InputData;
 using TUGraz.VectoCommon.Models;
 using TUGraz.VectoCommon.Utils;
 using TUGraz.VectoCore.Configuration;
@@ -139,9 +141,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			Gear = gear;
 			var inAngularVelocity = outAngularVelocity * ModelData.Gears[gear.Gear].Ratio;
 			var torqueLossResult = ModelData.Gears[gear.Gear].LossMap.GetTorqueLoss(outAngularVelocity, outTorque);
+			
 			CurrentState.TorqueLossResult = torqueLossResult;
 			var inTorque = outTorque / ModelData.Gears[gear.Gear].Ratio + torqueLossResult.Value;
 
+			if (DataBus.PowertrainInfo.ElectricMotorPositions.Any(x => x.IsOneOf(PowertrainPosition.HybridP2, PowertrainPosition.HybridP2_5))) {
+				// if there is an electric motor after the transmission, initialize the EM first
+				NextComponent.Initialize(inTorque, inAngularVelocity);
+			}
+
 			if (!inAngularVelocity.IsEqual(0)) {
 				var alpha = ModelData.Inertia.IsEqual(0)
 					? 0.SI<PerSquareSecond>()
-- 
GitLab