From 1c5b96d6c944412c906d12d688dd034d467b9d83 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Mon, 15 Mar 2021 16:52:32 +0100
Subject: [PATCH] avoid high torque for engine ramp up when starting during
 driving (keep virtually at gearbox input speed), correct for ramp-up in
 postprocessing

---
 .../Impl/StopStartCombustionEngine.cs         | 33 +++++++++++++++----
 .../SimulationComponent/SwitchableClutch.cs   |  2 +-
 .../ModalDataPostprocessingCorrection.cs      |  4 +--
 3 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/StopStartCombustionEngine.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/StopStartCombustionEngine.cs
index d8e180f18f..2692cde071 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/StopStartCombustionEngine.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/StopStartCombustionEngine.cs
@@ -56,11 +56,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl {
 						Engine = {
 							TorqueOutDemand = outTorque,
 							TotalTorqueDemand = outTorque,
-							PowerRequest = outTorque * outAngularVelocity,
+							PowerRequest = outTorque * 0.RPMtoRad(), //outAngularVelocity,
 							DynamicFullLoadPower = 0.SI<Watt>(),
 							DragPower = 0.SI<Watt>(),
 							DragTorque = 0.SI<NewtonMeter>(),
-							EngineSpeed = outAngularVelocity, // 0.RPMtoRad(),
+							EngineSpeed =  0.RPMtoRad(), // outAngularVelocity, //
 							AuxiliariesPowerDemand = 0.SI<Watt>(),
 						},
 						DeltaEngineSpeed = 0.RPMtoRad(),
@@ -73,7 +73,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl {
 					: (AbstractResponse)new ResponseUnderload(this) { Delta = outTorque * ModelData.IdleSpeed };
 				retVal.Engine.TotalTorqueDemand = outTorque;
 				retVal.Engine.TorqueOutDemand = outTorque;
-				retVal.Engine.PowerRequest = outTorque * outAngularVelocity;
+				retVal.Engine.PowerRequest = outTorque * 0.RPMtoRad(); // outAngularVelocity;
 				retVal.Engine.DynamicFullLoadPower = 0.SI<Watt>();
 				retVal.Engine.DragPower = 0.SI<Watt>();
 				retVal.Engine.DragTorque = 0.SI<NewtonMeter>();
@@ -84,7 +84,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl {
 				//throw new VectoSimulationException("Combustion engine cannot supply outtorque when switched off (T_out: {0})", outTorque);
 			}
 			CurrentState.EngineOn = false;
-			CurrentState.EngineSpeed = ModelData.IdleSpeed;
+			CurrentState.EngineSpeed = outAngularVelocity; //ModelData.IdleSpeed;
 			CurrentState.EngineTorque = 0.SI<NewtonMeter>();
 			CurrentState.EngineTorqueOut = 0.SI<NewtonMeter>();
 			CurrentState.EnginePower = 0.SI<Watt>();
@@ -101,10 +101,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl {
 					DeltaFullLoadTorque = 0.SI<NewtonMeter>(),
 					Engine = {
 						TorqueOutDemand = outTorque,
-						PowerRequest = outTorque * outAngularVelocity,
+						PowerRequest = outTorque * 0.RPMtoRad(), // outAngularVelocity,
 						DynamicFullLoadPower = 0.SI<Watt>(),
 						DragPower = 0.SI<Watt>(),
-						EngineSpeed = outAngularVelocity, // 0.RPMtoRad(),
+						EngineSpeed = 0.RPMtoRad(), // outAngularVelocity, // 0.RPMtoRad(),
 						AuxiliariesPowerDemand = 0.SI<Watt>(),
 						TotalTorqueDemand = 0.SI<NewtonMeter>(),
 						DragTorque = 0.SI<NewtonMeter>()
@@ -133,7 +133,26 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl {
 			if (CombustionEngineOn) {
 				base.DoWriteModalResults(time, simulationInterval, container);
 				var engineStart = !PreviousState.EngineOn && CurrentState.EngineOn;
-				container[ModalResultField.P_ice_start] = engineStart ? EngineStartEnergy / CurrentState.dt : 0.SI<Watt>();
+
+				//var engineRampUpEnergy = Formulas.InertiaPower(modelData.IdleSpeed, 0.RPMtoRad(), modelData.Inertia, modelData.EngineStartTime) * modelData.EngineStartTime;
+				//var engineDragEnergy = VectoMath.Abs(modelData.FullLoadCurves[0].DragLoadStationaryTorque(modelData.IdleSpeed)) *
+				//	modelData.IdleSpeed / 2.0 * modelData.EngineStartTime;
+
+				if (engineStart) {
+					var engineRampUpEnergy = Formulas.InertiaPower(PreviousState.EngineSpeed, ModelData.IdleSpeed,
+						ModelData.Inertia, ModelData.EngineStartTime) * ModelData.EngineStartTime;
+					var avgRampUpSpeed = (ModelData.IdleSpeed + PreviousState.EngineSpeed) / 2.0;
+					var engineDragEnergy =
+						VectoMath.Abs(ModelData.FullLoadCurves[0].DragLoadStationaryPower(avgRampUpSpeed)) *
+						avgRampUpSpeed * 0.5.SI<Second>();
+
+					container[ModalResultField.P_ice_start] =
+						(EngineStartEnergy + (engineRampUpEnergy + engineDragEnergy) * EngineStopStartUtilityFactor) /
+						CurrentState.dt;
+				} else {
+					container[ModalResultField.P_ice_start] =  0.SI<Watt>();
+				}
+
 				container[ModalResultField.P_aux_ESS_mech_ice_off] = 0.SI<Watt>();
 				container[ModalResultField.P_aux_ESS_mech_ice_on] = 0.SI<Watt>();
 			} else {
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/SwitchableClutch.cs b/VectoCore/VectoCore/Models/SimulationComponent/SwitchableClutch.cs
index bbba27d282..8b7e9d3ab5 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/SwitchableClutch.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/SwitchableClutch.cs
@@ -89,7 +89,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent
 			}
 
 			var inAngularVelocity = 0.RPMtoRad();
-			var retVal = NextComponent.Request(absTime, dt, outTorque, inAngularVelocity, dryRun);
+			var retVal = NextComponent.Request(absTime, dt, outTorque, outAngularVelocity, dryRun);
 
 			//if (retVal is ResponseEngineSpeedTooLow)
 			//{
diff --git a/VectoCore/VectoCore/OutputData/ModalDataPostprocessingCorrection.cs b/VectoCore/VectoCore/OutputData/ModalDataPostprocessingCorrection.cs
index b604c0740c..2ba8a0a2fd 100644
--- a/VectoCore/VectoCore/OutputData/ModalDataPostprocessingCorrection.cs
+++ b/VectoCore/VectoCore/OutputData/ModalDataPostprocessingCorrection.cs
@@ -216,7 +216,7 @@ namespace TUGraz.VectoCore.OutputData
 		public WattSecond EnergyAuxICEOffStandstill { get; set; }
 		public WattSecond EnergyAuxICEOnStandstill { get; set; }
 		public Watt AvgAuxPowerICEOnStandstill {
-			get { return EnergyAuxICEOnStandstill / ICEOffTimeStandstill; }
+			get { return ICEOffTimeStandstill.IsEqual(0) ? 0.SI<Watt>() : EnergyAuxICEOnStandstill / ICEOffTimeStandstill; }
 		}
 
 
@@ -225,7 +225,7 @@ namespace TUGraz.VectoCore.OutputData
 		public WattSecond EnergyPowerICEOnDriving { get; set; }
 		public Watt AvgAuxPowerICEOnDriving
 		{
-			get { return EnergyPowerICEOnDriving / ICEOffTimeDriving; }
+			get { return ICEOffTimeDriving.IsEqual(0) ? 0.SI<Watt>() : EnergyPowerICEOnDriving / ICEOffTimeDriving; }
 		}
 
 		public WattSecond EnergyDCDCMissing { get; set; }
-- 
GitLab