From 7de44bc92ca83160b3ef9dab6a503952924addf1 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Tue, 20 Dec 2016 13:52:10 +0100
Subject: [PATCH] compute shift losses for measured speed mode with gear

---
 .../Models/SimulationComponent/Impl/CycleGearbox.cs   | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CycleGearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CycleGearbox.cs
index 514a67e4cc..8f46996432 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CycleGearbox.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CycleGearbox.cs
@@ -228,10 +228,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 				return dryRunResponse;
 			}
 
-			// this code has to be _after_ the check for a potential gear-shift!
-			// (the above block issues dry-run requests and thus may update the CurrentState!)
 			CurrentState.TransmissionTorqueLoss = inTorque - (outTorque / effectiveRatio);
 
+			if (Gear != PreviousState.Gear &&
+				ConsiderShiftLosses(new GearInfo(Gear, torqueConverterLocked), outTorque)) {
+				CurrentState.PowershiftLosses = ComputeShiftLosses(dt, outTorque, outAngularVelocity);
+			}
+			inTorque += CurrentState.PowershiftLosses ?? 0.SI<NewtonMeter>();
 			CurrentState.SetState(inTorque, inAngularVelocity, outTorque, outAngularVelocity);
 			CurrentState.Gear = Gear;
 			// end critical section
@@ -339,6 +342,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 
 			if (ModelData.Type.AutomaticTransmission()) {
 				container[ModalResultField.TC_Locked] = !CurrentState.TorqueConverterActive;
+				container[ModalResultField.P_gbx_shift_loss] = CurrentState.PowershiftLosses == null
+					? 0.SI<Watt>()
+					: CurrentState.PowershiftLosses * avgInAngularSpeed;
 			}
 			// torque converter fields are written by TorqueConverter (if present), called from Vehicle container 
 		}
@@ -382,6 +388,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 		public class CycleGearboxState : GearboxState
 		{
 			public bool TorqueConverterActive;
+			public NewtonMeter PowershiftLosses { get; set; }
 		}
 
 		public class CycleShiftStrategy : IShiftStrategy
-- 
GitLab