From 6bf458434e745ff61d53c00267a9d9682083c8b4 Mon Sep 17 00:00:00 2001
From: Michael Krisper <michael.krisper@tugraz.at>
Date: Wed, 3 Feb 2016 17:30:15 +0100
Subject: [PATCH] added pWheelClutch for controlling the engine speed with the
 cycle

---
 .../Simulation/Impl/PowertrainBuilder.cs      |  3 +-
 .../Models/SimulationComponent/Impl/Clutch.cs | 34 ++++++++++++++-----
 2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs b/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs
index f208b051ea..d3f52686a9 100644
--- a/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs
+++ b/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs
@@ -97,9 +97,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
 					throw new ArgumentOutOfRangeException();
 			}
 
-			// pWheel: pt1 disabled!!
 			var engine = new CombustionEngine(_container, data.EngineData, pt1Disabled: true);
-			var clutch = new Clutch(_container, data.EngineData, engine.IdleController);
+			var clutch = new PWheelClutch(_container, engine.IdleController);
 
 			// gearbox --> clutch
 			tmp = AddComponent(tmp, clutch);
diff --git a/VectoCore/Models/SimulationComponent/Impl/Clutch.cs b/VectoCore/Models/SimulationComponent/Impl/Clutch.cs
index 160eb959d3..04d80b2d3f 100644
--- a/VectoCore/Models/SimulationComponent/Impl/Clutch.cs
+++ b/VectoCore/Models/SimulationComponent/Impl/Clutch.cs
@@ -37,9 +37,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 		private NewtonMeter _requiredTorque;
 
 
-		public Clutch(IVehicleContainer cockpit, CombustionEngineData engineData,
+		protected Clutch(IVehicleContainer container) : base(container) {}
+
+
+		public Clutch(IVehicleContainer container, CombustionEngineData engineData,
 			ICombustionEngineIdleController idleController)
-			: base(cockpit)
+			: base(container)
 		{
 			_idleSpeed = engineData.IdleSpeed;
 			_ratedSpeed = engineData.FullLoadCurve.RatedSpeed;
@@ -68,7 +71,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			return this;
 		}
 
-
 		public ITnOutPort OutPort()
 		{
 			return this;
@@ -120,7 +122,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			NextComponent = other;
 		}
 
-		private void AddClutchLoss(NewtonMeter torque, PerSecond angularVelocity, out NewtonMeter torqueIn,
+		protected virtual void AddClutchLoss(NewtonMeter torque, PerSecond angularVelocity, out NewtonMeter torqueIn,
 			out PerSecond engineSpeedIn)
 		{
 			Log.Debug("from Wheels: torque: {0}, angularVelocity: {1}, power {2}", torque, angularVelocity,
@@ -133,8 +135,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 				engineSpeedIn = _idleSpeed;
 				torqueIn = 0.SI<NewtonMeter>();
 			} else {
-				var engineSpeedNorm = (angularVelocity - _idleSpeed) /
-									(_ratedSpeed - _idleSpeed);
+				var engineSpeedNorm = (angularVelocity - _idleSpeed) / (_ratedSpeed - _idleSpeed);
 				if (engineSpeedNorm < Constants.SimulationSettings.CluchNormSpeed) {
 					_clutchState = ClutchState.ClutchSlipping;
 
@@ -142,8 +143,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 					var clutchSpeedNorm = Constants.SimulationSettings.CluchNormSpeed /
 										((_idleSpeed + Constants.SimulationSettings.CluchNormSpeed * (_ratedSpeed - _idleSpeed)) / _ratedSpeed);
 					engineSpeedIn =
-						((clutchSpeedNorm * engineSpeed0 / _ratedSpeed) * (_ratedSpeed - _idleSpeed) + _idleSpeed).Radian
-							.Cast<PerSecond>();
+						((clutchSpeedNorm * engineSpeed0 / _ratedSpeed) * (_ratedSpeed - _idleSpeed) + _idleSpeed).Radian.Cast<PerSecond>();
 
 					torqueIn = (torque * angularVelocity) / ClutchEff / engineSpeedIn;
 				} else {
@@ -154,4 +154,22 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 				Formulas.TorqueToPower(torqueIn, engineSpeedIn));
 		}
 	}
+
+	/// <summary>
+	/// Clutch without losses and slipping behaviour for PWheel driving cycle.
+	/// </summary>
+	public class PWheelClutch : Clutch
+	{
+		public PWheelClutch(IVehicleContainer container, ICombustionEngineIdleController idleController) : base(container)
+		{
+			IdleController = idleController;
+		}
+
+		protected override void AddClutchLoss(NewtonMeter torque, PerSecond angularVelocity, out NewtonMeter torqueIn,
+			out PerSecond engineSpeedIn)
+		{
+			torqueIn = torque;
+			engineSpeedIn = angularVelocity;
+		}
+	}
 }
\ No newline at end of file
-- 
GitLab