From 083247b4a0db97bc69ede1691f3a9f8b6a203a18 Mon Sep 17 00:00:00 2001
From: "VKMTHD\\haraldmartini" <harald.martini@student.tugraz.at>
Date: Mon, 10 Oct 2022 14:19:16 +0200
Subject: [PATCH] added PTO cycle to EPTO component instead of updating the
 driving cycle

---
 .../SimulationComponents/PTODataAdapter.cs    |  3 +--
 .../Simulation/Impl/PowertrainBuilder.cs      |  6 +++---
 .../Impl/DistanceBasedDrivingCycle.cs         |  6 +-----
 .../Models/SimulationComponent/Impl/EPTO.cs   | 10 +++++++++-
 .../Impl/IdleControllerSwitcher.cs            |  5 +++--
 .../Impl/PTOCycleController.cs                | 20 ++++++++-----------
 6 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/SimulationComponents/PTODataAdapter.cs b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/SimulationComponents/PTODataAdapter.cs
index 5e12fb5e2c..56a663a2d3 100644
--- a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/SimulationComponents/PTODataAdapter.cs
+++ b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/SimulationComponents/PTODataAdapter.cs
@@ -37,7 +37,6 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter.SimulationComponen
 				return new PTOData
 				{
 					TransmissionPowerDemand = powerDemand,
-					//TransmissionPowerDemandElectrical = 
 					TransmissionType = pto.PTOTransmissionType,
 					LossMap = PTOIdleLossMapReader.GetZeroLossMap(),
 				};
@@ -53,7 +52,7 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter.SimulationComponen
 		{
 			return new PTOData()
 			{
-				TransmissionType = DeclarationData.PTO.DefaultPTOTechnology, //Consider vehicles with transmission ? 
+				TransmissionType = DeclarationData.PTO.DefaultPTOTechnology,
 				LossMap = PTOIdleLossMapReader.GetZeroLossMap(),
 				PTOCycle =
 					DrivingCycleDataReader.ReadFromStream(RessourceHelper.ReadStream(DeclarationData.PTO.DefaultE_PTOActivationCycle),
diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs b/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs
index 68e8dd780a..0d7c738aa8 100644
--- a/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs
+++ b/VectoCore/VectoCore/Models/Simulation/Impl/PowertrainBuilder.cs
@@ -782,9 +782,9 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
 			
 
 				if (data.PTO?.PTOCycle != null) {
-					cycle.IdleController = GetPEVIdleController(data.PTO, container);
-					
-					elAux.AddAuxiliary(new EPTO());
+					var pevPTOController =  GetPEVIdleController(data.PTO, container);
+					cycle.IdleController = pevPTOController;
+					elAux.AddAuxiliary(new EPTO(pevPTOController));
 				}
 
 
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs
index d82096ce3b..57f46260cf 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs
@@ -481,17 +481,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 		public CycleData CycleData {
 			get
 			{
-				var cycleData = new CycleData
+				return new CycleData
 				{
 					AbsTime = CurrentState.AbsTime,
 					AbsDistance = CurrentState.Distance,
 					LeftSample = Left,
 					RightSample = CycleIntervalIterator.RightSample,
 				};
-				IdleController?.UpdateCycleEntry(cycleData);
-				
-
-				return cycleData;
 			}
 		}
 			
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/EPTO.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/EPTO.cs
index ea7183e969..72ec7f7ad4 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/EPTO.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/EPTO.cs
@@ -8,17 +8,25 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 {
 	public class EPTO : IAuxDemand
 	{
+		private readonly IPTOCycleController _ptoCycleController;
+
+		public EPTO(IPTOCycleController cycleController)
+		{
+			_ptoCycleController = cycleController;
+		}
+
 		#region Implementation of IAuxDemand
 		public Watt PowerDemand(IDataBus dataBus)
 		{
 			
 			if (dataBus.DrivingCycleInfo.PTOActive) {
-				return dataBus.DrivingCycleInfo.CycleData.LeftSample.PTOElectricalPowerDemand ?? 0.SI<Watt>();
+				return _ptoCycleController.CycleData.LeftSample.PTOElectricalPowerDemand ?? 0.SI<Watt>();
 			}
 
 			return 0.SI<Watt>();
 		}
 
+
 		public string AuxID => Constants.Auxiliaries.IDs.PTOConsumer;
 
 		#endregion
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/IdleControllerSwitcher.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/IdleControllerSwitcher.cs
index 9ee61b1a52..ed276ae4d0 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/IdleControllerSwitcher.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/IdleControllerSwitcher.cs
@@ -111,6 +111,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			}
 		}
 
+
 		public Second Duration
 		{
 			get {
@@ -121,9 +122,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			}
 		}
 
-		public void UpdateCycleEntry(CycleData cycleData)
+		public CycleData CycleData
 		{
-			//Do nothing
+			get => throw new NotImplementedException();
 		}
 	}
 }
\ No newline at end of file
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PTOCycleController.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PTOCycleController.cs
index 1a16915cb5..a6eeec66df 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PTOCycleController.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PTOCycleController.cs
@@ -48,8 +48,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 		void CommitSimulationStep(Second time, Second simulationInterval, IModalDataContainer container);
 		Second GetNextCycleTime();
 		Second Duration { get; }
-
-		void UpdateCycleEntry(CycleData entry);
+		CycleData CycleData { get; }
 	}
 
 	public class PTOCycleController : PowertrainDrivingCycle, IIdleController
@@ -142,6 +141,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			AbsTime = -1.SI<Second>();
 		}
 
+		public CycleData CycleData
+		{
+			get => new CycleData() {
+				LeftSample = _ptoActive ? CycleIterator.LeftSample : new DrivingCycleData.DrivingCycleEntry(),
+			};
+		} 
+
 
 		public void CommitSimulationStep(Second time, Second simulationInterval, IModalDataContainer container)
 		{
@@ -166,16 +172,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			CycleIterator.Reset();
 		}
 
-		public void UpdateCycleEntry(CycleData cycleData)
-		{
-			if (_ptoActive)
-			{
-				cycleData.LeftSample.PTOElectricalPowerDemand = CycleIterator.LeftSample.PTOElectricalPowerDemand;
-			}
-		}
-
-
-
 		#region Implementation of IIdleControllerSwitcher
 
 		public void ActivatePTO()
-- 
GitLab