From 9d314d6936e910e53dbbe5ec7c76cceafef10a16 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <quaritsch@ivt.tugraz.at>
Date: Fri, 17 Feb 2023 11:46:02 +0100
Subject: [PATCH] fix testcases, change update componens in vehicle container

---
 .../VectoCore/Models/Declaration/DeclarationData.cs    |  1 -
 .../Models/GenericModelData/GenericBusBatteryData.cs   |  8 ++++----
 .../Models/GenericModelData/GenericRatedPointHelper.cs |  4 ++--
 .../VectoCore/Models/Simulation/IVehicleContainer.cs   |  2 ++
 .../Models/Simulation/Impl/VehicleContainer.cs         | 10 ++++++++--
 5 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/VectoCore/VectoCore/Models/Declaration/DeclarationData.cs b/VectoCore/VectoCore/Models/Declaration/DeclarationData.cs
index 38cdcafb7a..235b355f3b 100644
--- a/VectoCore/VectoCore/Models/Declaration/DeclarationData.cs
+++ b/VectoCore/VectoCore/Models/Declaration/DeclarationData.cs
@@ -35,7 +35,6 @@ using System.IO;
 using System.Linq;
 using Newtonsoft.Json.Linq;
 using System.Collections.Concurrent;
-using Castle.DynamicProxy.Generators.Emitters.SimpleAST;
 using TUGraz.VectoCommon.BusAuxiliaries;
 using TUGraz.VectoCommon.Exceptions;
 using TUGraz.VectoCommon.InputData;
diff --git a/VectoCore/VectoCore/Models/GenericModelData/GenericBusBatteryData.cs b/VectoCore/VectoCore/Models/GenericModelData/GenericBusBatteryData.cs
index 3097eed69b..613baf2654 100644
--- a/VectoCore/VectoCore/Models/GenericModelData/GenericBusBatteryData.cs
+++ b/VectoCore/VectoCore/Models/GenericModelData/GenericBusBatteryData.cs
@@ -111,10 +111,10 @@ namespace TUGraz.VectoCore.Models.GenericModelData
 						secIndex = i;
 					}
 
-					var fstSoC = sortedOcvData[fstIndex].ParseDouble(XMLNames.REESS_OCV_SoC);
-					var secSoC = sortedOcvData[secIndex].ParseDouble(XMLNames.REESS_OCV_SoC);
-					var fstOCV = sortedOcvData[fstIndex].ParseDouble(XMLNames.REESS_OCV_OCV);
-					var secOCV = sortedOcvData[secIndex].ParseDouble(XMLNames.REESS_OCV_OCV);
+					var fstSoC = sortedOcvData[fstIndex].ParseDouble(BatterySOCReader.Fields.StateOfCharge);
+					var secSoC = sortedOcvData[secIndex].ParseDouble(BatterySOCReader.Fields.StateOfCharge);
+					var fstOCV = sortedOcvData[fstIndex].ParseDouble(BatterySOCReader.Fields.BatteryVoltage);
+					var secOCV = sortedOcvData[secIndex].ParseDouble(BatterySOCReader.Fields.BatteryVoltage);
 
 					return VectoMath.Interpolate(fstSoC, secSoC, fstOCV, secOCV, 50).SI<Volt>();
 				}
diff --git a/VectoCore/VectoCore/Models/GenericModelData/GenericRatedPointHelper.cs b/VectoCore/VectoCore/Models/GenericModelData/GenericRatedPointHelper.cs
index df96a1fed9..ed97809858 100644
--- a/VectoCore/VectoCore/Models/GenericModelData/GenericRatedPointHelper.cs
+++ b/VectoCore/VectoCore/Models/GenericModelData/GenericRatedPointHelper.cs
@@ -1,6 +1,6 @@
 using System;
 using System.Collections.Generic;
-using Castle.Core.Internal;
+using System.Linq;
 using TUGraz.VectoCommon.InputData;
 using TUGraz.VectoCommon.Utils;
 using TUGraz.VectoCore.Utils;
@@ -117,7 +117,7 @@ namespace TUGraz.VectoCore.Models.GenericModelData
 				var slopeValue = (fullLoadCurveEntries[r].PowerDrive.Value() - fullLoadCurveEntries[r - 1].PowerDrive.Value()) /
 								 (fullLoadCurveEntries[r].MotorSpeed.Value() - fullLoadCurveEntries[r - 1].MotorSpeed.Value());
 
-				var deltaValue = slopeValue / (slopeValueEntries.IsNullOrEmpty() ? slopeValue  : slopeValueEntries[0].Slope ) -1;
+				var deltaValue = slopeValue / (!slopeValueEntries.Any() ? slopeValue  : slopeValueEntries[0].Slope ) -1;
 
 				slopeValueEntries.Add(new SlopeValueEntry(slopeValue, deltaValue));
 			}
diff --git a/VectoCore/VectoCore/Models/Simulation/IVehicleContainer.cs b/VectoCore/VectoCore/Models/Simulation/IVehicleContainer.cs
index 3d3cf62f75..8d3971da6e 100644
--- a/VectoCore/VectoCore/Models/Simulation/IVehicleContainer.cs
+++ b/VectoCore/VectoCore/Models/Simulation/IVehicleContainer.cs
@@ -83,5 +83,7 @@ namespace TUGraz.VectoCore.Models.Simulation
 		IEnumerable<ISimulationPreprocessor> GetPreprocessingRuns { get; }
 		ISumData SumData { get; }
 		void AddPreprocessor(ISimulationPreprocessor simulationPreprocessor);
+
+		IReadOnlyList<VectoSimulationComponent> Components { get; }
 	}
 }
\ No newline at end of file
diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs b/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs
index d600d724a0..6e5d61c6c2 100644
--- a/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs
+++ b/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs
@@ -218,12 +218,16 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
 					target.UpdateFrom(source);
 				}
 			} else {
+				var realComponents = (realContainer as IVehicleContainer)?.Components;
+				if (realComponents == null) {
+					throw new VectoException("RealContainer has to implement IVehicleContainer interface!");
+				}
 				foreach (var (_, c) in _components) {
 #if DEBUG
 					var found = false;
 #endif
 					if (c is IUpdateable target) {
-						foreach (var (_, source) in (realContainer as VehicleContainer)._components) {
+						foreach (var source in realComponents) {
 							if (target.UpdateFrom(source)) {
 								ComponentUpdateList.Add((target, source));
 #if DEBUG
@@ -242,7 +246,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
 				
 #if DEBUG
 				var sourceList = ComponentUpdateList.Select(st => st.Item2).ToArray();
-				foreach (var (_, source) in (realContainer as VehicleContainer)._components) {
+				foreach (var source in realComponents) {
 					if (!sourceList.Contains(source)){
 						Console.WriteLine("Real Component is not used for update: " + source.GetType());
 					}
@@ -290,6 +294,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
 			Preprocessors.Add(simulationPreprocessor);
 		}
 
+		public IReadOnlyList<VectoSimulationComponent> Components => _components.Select(x => x.Item2).ToList();
+
 		public virtual void StartSimulationRun()
 		{
 			ModData?.Reset();
-- 
GitLab