From 75e1810ef030dad08663e39f4e51ea5d8fddf799 Mon Sep 17 00:00:00 2001
From: "VKMTHD\\haraldmartini" <harald.martini@student.tugraz.at>
Date: Tue, 27 Sep 2022 11:22:30 +0200
Subject: [PATCH] switch electric steering pump off if vehicle stands still
 (only works if sp is connected to reess), updated DCDC converter

---
 .../AuxiliaryDataAdapter.cs                   | 14 +++++++++---
 .../Models/Simulation/Data/VectoRunData.cs    |  2 +-
 .../SimulationComponent/DCDCConverter.cs      | 22 ++++++++++++++-----
 .../Impl/ElectricAuxiliaries.cs               |  2 +-
 4 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/SimulationComponents/AuxiliaryDataAdapter.cs b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/SimulationComponents/AuxiliaryDataAdapter.cs
index b501b01430..01a86deb2b 100644
--- a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/SimulationComponents/AuxiliaryDataAdapter.cs
+++ b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/SimulationComponents/AuxiliaryDataAdapter.cs
@@ -233,10 +233,10 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter.SimulationComponen
 					throw new VectoException("Should not be created for conventional vehicles");
 				case VectoSimulationJobType.BatteryElectricVehicle:
 				case VectoSimulationJobType.SerialHybridVehicle:
-					aux.PowerDemandDataBusFunc = powerDemandFunc;
+					aux.PowerDemandElectricDataBusFunc = powerDemandFunc;
 					break;
 				case VectoSimulationJobType.ParallelHybridVehicle:
-					aux.PowerDemandDataBusFunc = parallelHybridPowerDemand;
+					aux.PowerDemandElectricDataBusFunc = parallelHybridPowerDemand;
 					break;
 				case VectoSimulationJobType.EngineOnlySimulation:
 				case VectoSimulationJobType.IEPC_E:
@@ -348,7 +348,7 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter.SimulationComponen
 				{
 					var spElectric = new VectoRunData.AuxData
 					{
-						DemandType = AuxiliaryDemandType.Constant,
+						DemandType = AuxiliaryDemandType.Dynamic,
 						Technology = auxData.Technology.Where(tech => DeclarationData.SteeringPump.IsFullyElectric(tech))
 							.ToList(),
 						IsFullyElectric = true,
@@ -356,6 +356,14 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter.SimulationComponen
 						ID = Constants.Auxiliaries.IDs.SteeringPump_el,
 						PowerDemandElectric = powerDemand.electricPumps * alternatorEfficiency,
 						PowerDemandMech = powerDemand.electricPumps,
+
+						PowerDemandElectricDataBusFunc = (db) => {
+							if (db.VehicleInfo.VehicleStopped) {
+								return 0.SI<Watt>();
+							} else {
+								return powerDemand.electricPumps;
+							}
+						},
 						MissionType = mission,
 					};
 
diff --git a/VectoCore/VectoCore/Models/Simulation/Data/VectoRunData.cs b/VectoCore/VectoCore/Models/Simulation/Data/VectoRunData.cs
index 7a57e9e9b8..3928f2ba0f 100644
--- a/VectoCore/VectoCore/Models/Simulation/Data/VectoRunData.cs
+++ b/VectoCore/VectoCore/Models/Simulation/Data/VectoRunData.cs
@@ -190,7 +190,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
 			[JsonIgnore]
 			public Func<DrivingCycleData.DrivingCycleEntry, Watt> PowerDemandMechCycleFunc;
 
-			[JsonIgnore] public Func<IDataBus, Watt> PowerDemandDataBusFunc;
+			[JsonIgnore] public Func<IDataBus, Watt> PowerDemandElectricDataBusFunc;
 
 
 
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/DCDCConverter.cs b/VectoCore/VectoCore/Models/SimulationComponent/DCDCConverter.cs
index 6235dba057..1b308554ad 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/DCDCConverter.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/DCDCConverter.cs
@@ -46,18 +46,26 @@ namespace TUGraz.VectoCore.Models.SimulationComponent
 			var electricConsumersPower =
 				_electricConsumers.Sum(aux => aux.PowerDemand(absTime, dt, dryRun)).DefaultIfNull(0);
 
+			var powerDemand = PreviousState.ConsumedEnergy / dt * efficiency + electricConsumersPower / Efficiency;
+
+			
+
 			if (!dryRun) {
 				CurrentState.ElectricAuxPower = electricConsumersPower;
 			}
 
-
-			if ((PreviousState.ConsumedEnergy * efficiency).IsBetween(chargeEnergy, dischargeEnergy)) {
-				return (PreviousState.ConsumedEnergy / dt * efficiency) + electricConsumersPower;
+			if (powerDemand.IsBetween(chargeEnergy, dischargeEnergy))
+			{
+				return powerDemand;
 			}
 
+			//if ((PreviousState.ConsumedEnergy * efficiency).IsBetween(chargeEnergy, dischargeEnergy)) {
+			//	return (PreviousState.ConsumedEnergy / dt * efficiency) + electricConsumersPower / Efficiency;
+			//}
+
 			// write in mod-file for post-processing correction
 			if (!dryRun) {
-				CurrentState.MissingEnergy = PreviousState.ConsumedEnergy + electricConsumersPower * dt;
+				CurrentState.MissingEnergy = powerDemand * dt;
 			}
 
 			return 0.SI<Watt>();
@@ -72,11 +80,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent
 		protected override void DoWriteModalResults(Second time, Second simulationInterval, IModalDataContainer container)
 		{
 			if (CurrentState.MissingEnergy.IsEqual(0)) {
+				var consumedEnergy =
+					(PreviousState.ConsumedEnergy / simulationInterval) + CurrentState.ElectricAuxPower;
 				container[ModalResultField.P_DCDC_In] =
-					PreviousState.ConsumedEnergy / simulationInterval / Efficiency;
+					consumedEnergy / Efficiency;
 					
 				container[ModalResultField.P_DCDC_Out] =
-					PreviousState.ConsumedEnergy / simulationInterval;
+					consumedEnergy;
 				
 
 			} else {
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ElectricAuxiliaries.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ElectricAuxiliaries.cs
index ad9ce93cf4..52b5d72854 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ElectricAuxiliaries.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ElectricAuxiliaries.cs
@@ -73,7 +73,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 				if (aux.DemandType == AuxiliaryDemandType.Constant) {
 					powerDemand = aux.PowerDemandElectric;
 				} else if(aux.DemandType == AuxiliaryDemandType.Dynamic) {
-					powerDemand = aux.PowerDemandDataBusFunc(DataBus);
+					powerDemand = aux.PowerDemandElectricDataBusFunc(DataBus);
 				}
 
 
-- 
GitLab