From 0e7dfc5e58db74de54b5bb540fc2c0bf084cda3b Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Mon, 15 Mar 2021 13:38:24 +0100
Subject: [PATCH] add correction for missing dcdc converter energy, bugfixes

---
 .../OutputData/IModalDataContainer.cs         |  1 +
 .../ModalDataPostprocessingCorrection.cs      | 43 ++++++++++++++++---
 2 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/VectoCore/VectoCore/OutputData/IModalDataContainer.cs b/VectoCore/VectoCore/OutputData/IModalDataContainer.cs
index 083c390a2f..78de9f4350 100644
--- a/VectoCore/VectoCore/OutputData/IModalDataContainer.cs
+++ b/VectoCore/VectoCore/OutputData/IModalDataContainer.cs
@@ -160,6 +160,7 @@ namespace TUGraz.VectoCore.OutputData
 		WattSecond WorkBusAuxPSCorr { get; }
 		WattSecond WorkBusAuxESMech { get; }
 		WattSecond WorkBusAuxCorr { get; }
+		WattSecond EnergyDCDCMissing { get; }
 		Joule AuxHeaterDemand { get; }
 
 		IFuelConsumptionCorrection FuelConsumptionCorrection(IFuelProperties fuel);
diff --git a/VectoCore/VectoCore/OutputData/ModalDataPostprocessingCorrection.cs b/VectoCore/VectoCore/OutputData/ModalDataPostprocessingCorrection.cs
index 67ff32e026..b604c0740c 100644
--- a/VectoCore/VectoCore/OutputData/ModalDataPostprocessingCorrection.cs
+++ b/VectoCore/VectoCore/OutputData/ModalDataPostprocessingCorrection.cs
@@ -38,13 +38,13 @@ namespace TUGraz.VectoCore.OutputData
 				IceOn = x.Field<bool>(ModalResultField.ICEOn.GetName())
 			}).Where(x => !x.v.IsEqual(0) && !x.IceOn).ToList();
 
-			r.ICEOffTimeStandstill = entriesAuxICEStandstill.Sum(x => x.dt);
-			r.EnergyAuxICEOffStandstill = entriesAuxICEStandstill.Sum(x => x.P_off * x.dt); 
-			r.EnergyAuxICEOnStandstill = entriesAuxICEStandstill.Sum(x => x.P_on * x.dt);
+			r.ICEOffTimeStandstill = entriesAuxICEStandstill.Sum(x => x.dt) ?? 0.SI<Second>();
+			r.EnergyAuxICEOffStandstill = entriesAuxICEStandstill.Sum(x => x.P_off * x.dt) ?? 0.SI<WattSecond>(); 
+			r.EnergyAuxICEOnStandstill = entriesAuxICEStandstill.Sum(x => x.P_on * x.dt) ?? 0.SI<WattSecond>();
 				
-			r.ICEOffTimeDriving = entriesAuxICEDriving.Sum(x => x.dt);
-			r.EnergyAuxICEOffDriving = entriesAuxICEDriving.Sum(x => x.P_off * x.dt);
-			r.EnergyPowerICEOnDriving = entriesAuxICEDriving.Sum(x => x.P_on * x.dt);
+			r.ICEOffTimeDriving = entriesAuxICEDriving.Sum(x => x.dt) ?? 0.SI<Second>();
+			r.EnergyAuxICEOffDriving = entriesAuxICEDriving.Sum(x => x.P_off * x.dt) ?? 0.SI<WattSecond>();
+			r.EnergyPowerICEOnDriving = entriesAuxICEDriving.Sum(x => x.P_on * x.dt) ?? 0.SI<WattSecond>();
 
 			
 			r.WorkWHREl = modData.TimeIntegral<WattSecond>(ModalResultField.P_WHR_el_corr);
@@ -75,6 +75,28 @@ namespace TUGraz.VectoCore.OutputData
 				(current, fuel) => current + modData.TotalFuelConsumption(ModalResultField.FCFinal, fuel) *
 					fuel.LowerHeatingValueVecto);
 
+			r.EnergyDCDCMissing = 0.SI<WattSecond>();
+			if (runData.BusAuxiliaries != null && runData.BusAuxiliaries.ElectricalUserInputsConfig.ConnectESToREESS) {
+				// either case C1, C2a, or C3a
+				var missingDCDCEnergy = modData.TimeIntegral<WattSecond>(ModalResultField.P_DCDC_missing);
+				if (runData.BusAuxiliaries.ElectricalUserInputsConfig.AlternatorType == AlternatorType.Smart) {
+					// case C3a
+					if (runData.ElectricMachinesData.Count != 1) {
+						throw new VectoException("exactly 1 electric machine is required. got {0} ({1})",
+							runData.ElectricMachinesData.Count,
+							string.Join(",", runData.ElectricMachinesData.Select(x => x.Item1.ToString())));
+					}
+					var emPos = runData.ElectricMachinesData.First().Item1;
+					var averageEmEfficiencyCharging = modData.ElectricMotorEfficiencyGenerate(emPos);
+					r.EnergyDCDCMissing = missingDCDCEnergy /
+										runData.BusAuxiliaries.ElectricalUserInputsConfig.DCDCEfficiency /
+										averageEmEfficiencyCharging;
+				} else {
+					// case C1, C2a
+					r.EnergyDCDCMissing = missingDCDCEnergy / DeclarationData.AlternaterEfficiency;
+				}
+			}
+
 			r.AuxHeaterDemand = modData.AuxHeaterDemandCalc == null
 				? 0.SI<Joule>()
 				: modData.AuxHeaterDemandCalc(duration, engineWasteheatSum);
@@ -108,6 +130,8 @@ namespace TUGraz.VectoCore.OutputData
 											essParams.UtilityFactorDriving;
 				f.FcESS_AuxDriving_ICEOff = fcIceOnAuxDriving * r.ICEOffTimeDriving *
 											(1 - essParams.UtilityFactorDriving);
+				f.FcESS_DCDCMissing =
+					r.EnergyDCDCMissing * f.EngineLineCorrectionFactor * essParams.UtilityFactorStandstill;
 
 				f.FcBusAuxPs = f.EngineLineCorrectionFactor * r.WorkBusAuxPSCorr;
 				f.FcBusAuxEs =  f.EngineLineCorrectionFactor * r.WorkBusAuxESMech;
@@ -204,6 +228,8 @@ namespace TUGraz.VectoCore.OutputData
 			get { return EnergyPowerICEOnDriving / ICEOffTimeDriving; }
 		}
 
+		public WattSecond EnergyDCDCMissing { get; set; }
+
 		#endregion
 	}
 
@@ -222,9 +248,11 @@ namespace TUGraz.VectoCore.OutputData
 		public Kilogram FcESS_AuxDriving_ICEOn { get; set; }
 		public Kilogram FcESS_AuxDriving_ICEOff { get; set; }
 
+		public Kilogram FcESS_DCDCMissing { get; set; }
+
 		public Kilogram FcESS =>
 			FcESS_EngineStart + FcESS_AuxStandstill_ICEOff + FcESS_AuxStandstill_ICEOn
-			+ FcESS_AuxDriving_ICEOn + FcESS_AuxDriving_ICEOff;
+			+ FcESS_AuxDriving_ICEOn + FcESS_AuxDriving_ICEOff + FcESS_DCDCMissing;
 
 		public Kilogram FcBusAuxPs { get; set; }
 		public Kilogram FcBusAuxEs { get; set; }
@@ -280,6 +308,7 @@ namespace TUGraz.VectoCore.OutputData
 			get { return FcFinal * Fuel.LowerHeatingValueVecto; }
 		}
 
+
 		#endregion
 	}
 
-- 
GitLab