diff --git a/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/CustomerInformationFile_0_9/AbstractCustomerReport.cs b/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/CustomerInformationFile_0_9/AbstractCustomerReport.cs index 1d440574bc42aeaa6c09983c2b9ccb22d717f70d..dcd3e97da3a9c9b7520fe6ac04165b7cae419d0b 100644 --- a/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/CustomerInformationFile_0_9/AbstractCustomerReport.cs +++ b/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/CustomerInformationFile_0_9/AbstractCustomerReport.cs @@ -72,11 +72,11 @@ namespace TUGraz.VectoCore.OutputData.XML.DeclarationReports.CustomerInformation public XDocument Report { get; protected set; } - protected List<IResultEntry> results = new List<IResultEntry>(); + protected List<IResultEntry> _results = new List<IResultEntry>(); public void WriteResult(IResultEntry resultValue) { - results.Add(resultValue); + _results.Add(resultValue); } public void GenerateReport(XElement resultSignature) @@ -115,7 +115,7 @@ namespace TUGraz.VectoCore.OutputData.XML.DeclarationReports.CustomerInformation Vehicle, InputDataIntegrity, new XElement(Cif_0_9 + XMLNames.Report_ManufacturerRecord_Signature, resultSignature), - Results.GenerateResults(results), + Results.GenerateResults(_results), XMLHelper.GetApplicationInfo(Cif_0_9) }; } diff --git a/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/CustomerInformationFile_0_9/CustomerInformationFile/CustomerInformationFile.cs b/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/CustomerInformationFile_0_9/CustomerInformationFile/CustomerInformationFile.cs index 3db79d1e1d8dc9004b57a6ee502df77b38114f45..5eb51e5b5e9858d424cb4e755650a3159b851bb3 100644 --- a/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/CustomerInformationFile_0_9/CustomerInformationFile/CustomerInformationFile.cs +++ b/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/CustomerInformationFile_0_9/CustomerInformationFile/CustomerInformationFile.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,6 +11,7 @@ using TUGraz.VectoCommon.Resources; using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.Simulation.Impl; using TUGraz.VectoCore.OutputData.XML.DeclarationReports.Common; +using TUGraz.VectoCore.OutputData.XML.DeclarationReports.ManufacturerReport; using TUGraz.VectoCore.OutputData.XML.DeclarationReports.ManufacturerReport.ManufacturerReport_0_9.ManufacturerReport; using TUGraz.VectoCore.OutputData.XML.DeclarationReports.ManufacturerReport.ManufacturerReport_0_9.ManufacturerReportXMLTypeWriter; using TUGraz.VectoCore.Utils; @@ -241,18 +243,20 @@ namespace TUGraz.VectoCore.OutputData.XML.DeclarationReports.CustomerInformation ManufacturerReportIntegrityPrimaryVehicle, InputDataIntegrity, new XElement(Cif_0_9 + XMLNames.Report_ManufacturerRecord_Signature, resultSignature), - Results.GenerateResults(results), + Results.GenerateResults(_results), XMLHelper.GetApplicationInfo(Cif_0_9) }; } #region Implementation of IXMLCustomerReportCompletedBus - public void WriteResult(IResultEntry genericResult, IResultEntry specificResult, IResult primaryResult) + public void WriteResult(IResultEntry genericResult, IResultEntry specificResult, IResult primaryResult, Func<IResultEntry, IResultEntry, IResult, IResultEntry> getCompletedResult) { _allSuccess &= genericResult.Status == VectoRun.Status.Success; _allSuccess &= specificResult.Status == VectoRun.Status.Success; _resultCount++; + + _results.Add(getCompletedResult(genericResult, specificResult, primaryResult)); //Results.Add( // genericResult.Status == VectoRun.Status.Success && specificResult.Status == VectoRun.Status.Success // ? GetSuccessResultEntry(genericResult, specificResult, primaryResult) diff --git a/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/IXMLCustomerReport.cs b/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/IXMLCustomerReport.cs index 48316e9377ccaa0c23102a20da4391280d001616..a9e3f5534a9407bb0f7570b76906e89625adbce6 100644 --- a/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/IXMLCustomerReport.cs +++ b/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/IXMLCustomerReport.cs @@ -1,8 +1,10 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Xml.Linq; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.OutputData.XML.DeclarationReports.ManufacturerReport; namespace TUGraz.VectoCore.OutputData.XML.DeclarationReports.CustomerInformationFile { @@ -16,7 +18,15 @@ namespace TUGraz.VectoCore.OutputData.XML.DeclarationReports.CustomerInformation public interface IXMLCustomerReportCompletedBus { - void WriteResult(IResultEntry genericResult, - IResultEntry specificResult, IResult primaryResult); + /// <summary> + /// + /// </summary> + /// <param name="genericResult"></param> + /// <param name="specificResult"></param> + /// <param name="primaryResult"></param> + /// <param name="getCompletedResult">IResultEntry GetCompletedResult(IResultEntry generic, + // IResultEntry specific, IResult primary);</param></param> + void WriteResult(IResultEntry genericResult, + IResultEntry specificResult, IResult primaryResult, Func<IResultEntry, IResultEntry, IResult, IResultEntry> getCompletedResult); } } \ No newline at end of file diff --git a/VectoCore/VectoCore/OutputData/XML/DeclarationReports/ManufacturerReport/IXMLManufacturerReport.cs b/VectoCore/VectoCore/OutputData/XML/DeclarationReports/ManufacturerReport/IXMLManufacturerReport.cs index 31f77a85b8137692855dbe5997679e28af85f043..ead1f2729d3a81d851999c4b5984022dedf06f9c 100644 --- a/VectoCore/VectoCore/OutputData/XML/DeclarationReports/ManufacturerReport/IXMLManufacturerReport.cs +++ b/VectoCore/VectoCore/OutputData/XML/DeclarationReports/ManufacturerReport/IXMLManufacturerReport.cs @@ -1,4 +1,5 @@ -using System.Xml.Linq; +using System; +using System.Xml.Linq; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCore.Models.Simulation.Data; @@ -15,7 +16,19 @@ namespace TUGraz.VectoCore.OutputData.XML.DeclarationReports.ManufacturerReport public interface IXMLManufacturerReportCompletedBus { - void WriteResult(XMLDeclarationReport.ResultEntry genericResult, - XMLDeclarationReport.ResultEntry specificResult, IResult primaryResult); + //Not supported in C# 7.3 + //delegate IResultEntry GetCompletedResult(IResultEntry generic, + // IResultEntry specific, IResult primary); + + /// <summary> + /// Adds a result to the report, the functor getCompletedResult determines how the result is calculated + /// </summary> + /// <param name="genericResult"></param> + /// <param name="specificResult"></param> + /// <param name="primaryResult"></param> + /// <param name="getCompletedResult">IResultEntry GetCompletedResult(IResultEntry generic, + // IResultEntry specific, IResult primary);</param> + void WriteResult(IResultEntry genericResult, + IResultEntry specificResult, IResult primaryResult, Func<IResultEntry, IResultEntry, IResult, IResultEntry> getCompletedResult); } } \ No newline at end of file diff --git a/VectoCore/VectoCore/OutputData/XML/DeclarationReports/ManufacturerReport/ManufacturerReport_0_9/ManufacturerReport/CompletedBusManufacturerReport.cs b/VectoCore/VectoCore/OutputData/XML/DeclarationReports/ManufacturerReport/ManufacturerReport_0_9/ManufacturerReport/CompletedBusManufacturerReport.cs index f8daf58789c4bd3198af3a5e8578654d8905ae49..520952be6b3ebd99b53a4caad0c36284d9a80d05 100644 --- a/VectoCore/VectoCore/OutputData/XML/DeclarationReports/ManufacturerReport/ManufacturerReport_0_9/ManufacturerReport/CompletedBusManufacturerReport.cs +++ b/VectoCore/VectoCore/OutputData/XML/DeclarationReports/ManufacturerReport/ManufacturerReport_0_9/ManufacturerReport/CompletedBusManufacturerReport.cs @@ -24,134 +24,8 @@ namespace TUGraz.VectoCore.OutputData.XML.DeclarationReports.ManufacturerReport. internal abstract class CompletedBusManufacturerReportBase : AbstractManufacturerReport, IXMLManufacturerReportCompletedBus { - private class CompletedBusResult : IResultEntry - { - #region Implementation of IResultEntry - - public void Initialize(VectoRunData vectoRunData) - { - throw new NotImplementedException(); - } - - public VectoRunData VectoRunData { get; } - public VectoRun.Status Status { get; set; } - public OvcHevMode OVCMode { get; set; } - public MissionType Mission { get; set; } - public LoadingType LoadingType { get; } - public int FuelMode { get; } - public IList<IFuelProperties> FuelData { get; set; } - public MeterPerSecond AverageSpeed { get; set; } - public MeterPerSecond AverageDrivingSpeed { get; set; } - public MeterPerSecond MaxSpeed { get; set; } - public MeterPerSecond MinSpeed { get; set; } - public MeterPerSquareSecond MaxDeceleration { get; set; } - public MeterPerSquareSecond MaxAcceleration { get; set; } - public PerSecond EngineSpeedDrivingMin { get; set; } - public PerSecond EngineSpeedDrivingAvg { get; set; } - public PerSecond EngineSpeedDrivingMax { get; set; } - public double AverageGearboxEfficiency { get; set; } - public double AverageAxlegearEfficiency { get; set; } - public Scalar FullLoadPercentage { get; set; } - public Scalar GearshiftCount { get; set; } - public Meter Distance { get; set; } - - - public Dictionary<FuelType, IFuelConsumptionCorrection> CorrectedFinalFuelConsumption = - new Dictionary<FuelType, IFuelConsumptionCorrection>(); - public IFuelConsumptionCorrection FuelConsumptionFinal(FuelType fuelType) - { - return CorrectedFinalFuelConsumption.ContainsKey(fuelType) ? CorrectedFinalFuelConsumption[fuelType] : null; - } - - public WattSecond ElectricEnergyConsumption { get; set; } - public Kilogram CO2Total { get; set; } - public Kilogram Payload { get; set; } - public Kilogram TotalVehicleMass { get; set; } - public CubicMeter CargoVolume { get; } - public double? PassengerCount { get; set; } - public VehicleClass VehicleClass { get; set; } - public Watt MaxChargingPower { get; } - public double WeightingFactor { get; } - public Meter ActualChargeDepletingRange { get; set; } - public Meter EquivalentAllElectricRange { get; set; } - public Meter ZeroCO2EmissionsRange { get; set; } - public IFuelProperties AuxHeaterFuel { get; set; } - public Kilogram ZEV_FuelConsumption_AuxHtr { get; set; } - public Kilogram ZEV_CO2 { get; set; } - - public void SetResultData(VectoRunData runData, IModalDataContainer data, double weightingFactor) - { - throw new NotImplementedException(); - } - - public string Error => throw new NotImplementedException(); - public string StackTrace => throw new NotImplementedException(); - public BatterySystemData BatteryData - { - get; - set; - } - - #endregion - } - private class CompletedBusFuelConsumption : IFuelConsumptionCorrection - { - #region Implementation of IFuelConsumptionCorrection - - public IFuelProperties Fuel { get; set; } - - public KilogramPerWattSecond EngineLineCorrectionFactor => throw new NotImplementedException(); - - public KilogramPerWattSecond VehicleLine => throw new NotImplementedException(); - - public KilogramPerSecond FC_ESS_H => throw new NotImplementedException(); - - public KilogramPerSecond FC_ESS_CORR_H => throw new NotImplementedException(); - - public KilogramPerSecond FC_BusAux_PS_CORR_H => throw new NotImplementedException(); - - public KilogramPerSecond FC_BusAux_ES_CORR_H => throw new NotImplementedException(); - - public KilogramPerSecond FC_WHR_CORR_H => throw new NotImplementedException(); - - public KilogramPerSecond FC_AUXHTR_H => throw new NotImplementedException(); - - public KilogramPerSecond FC_AUXHTR_H_CORR => throw new NotImplementedException(); - - public KilogramPerSecond FC_REESS_SOC_H => throw new NotImplementedException(); - - public KilogramPerSecond FC_REESS_SOC_CORR_H => throw new NotImplementedException(); - - public KilogramPerSecond FC_FINAL_H => throw new NotImplementedException(); - - public KilogramPerMeter FC_WHR_CORR_KM => throw new NotImplementedException(); - - public KilogramPerMeter FC_BusAux_PS_CORR_KM => throw new NotImplementedException(); - - public KilogramPerMeter FC_BusAux_ES_CORR_KM => throw new NotImplementedException(); - - public KilogramPerMeter FC_AUXHTR_KM => throw new NotImplementedException(); - - public KilogramPerMeter FC_AUXHTR_KM_CORR => throw new NotImplementedException(); - - public KilogramPerMeter FC_REESS_SOC_KM => throw new NotImplementedException(); - - public KilogramPerMeter FC_REESS_SOC_CORR_KM => throw new NotImplementedException(); - - public KilogramPerMeter FC_ESS_KM => throw new NotImplementedException(); - - public KilogramPerMeter FC_ESS_CORR_KM => throw new NotImplementedException(); - - public KilogramPerMeter FC_FINAL_KM => throw new NotImplementedException(); - - public VolumePerMeter FuelVolumePerMeter => throw new NotImplementedException(); - - public Kilogram TotalFuelConsumptionCorrected => EnergyDemand / Fuel.LowerHeatingValueVecto; - - public Joule EnergyDemand { get; set; } + - #endregion - } protected XNamespace _mrf = XNamespace.Get("urn:tugraz:ivt:VectoAPI:DeclarationOutput:v0.9"); @@ -178,7 +52,7 @@ namespace TUGraz.VectoCore.OutputData.XML.DeclarationReports.ManufacturerReport. #region Implementation of IXMLManufacturerReportCompletedBus - public double CalculateFactor<T>( + private double CalculateFactor<T>( (XMLDeclarationReport.ResultEntry genericResult, XMLDeclarationReport.ResultEntry specificResult) results, Func<XMLDeclarationReport.ResultEntry, T> access) @@ -194,119 +68,122 @@ namespace TUGraz.VectoCore.OutputData.XML.DeclarationReports.ManufacturerReport. - public virtual void WriteResult(XMLDeclarationReport.ResultEntry genericResult, - XMLDeclarationReport.ResultEntry specificResult, IResult primaryResult) + + public virtual void WriteResult(IResultEntry genericResult, + IResultEntry specificResult, IResult primaryResult,Func<IResultEntry, IResultEntry, IResult, IResultEntry> getCompletedResult) { _allSuccess &= genericResult.Status == VectoRun.Status.Success; _allSuccess &= specificResult.Status == VectoRun.Status.Success; - + _results.Add(getCompletedResult(genericResult, specificResult, primaryResult)); + return; - var result = new CompletedBusResult { - Status = VectoRun.Status.Success, - }; - result.Status = genericResult.Status != VectoRun.Status.Success ? genericResult.Status : result.Status; - result.Status = specificResult.Status != VectoRun.Status.Success ? specificResult.Status : result.Status; - result.OVCMode = specificResult.OVCMode; - if (genericResult.OVCMode != specificResult.OVCMode) { - throw new VectoException($"generic OVC Mode must be equal to specific OVC Mode! but was gen_ovc = {genericResult.OVCMode} != {specificResult.OVCMode} = spec_ovc"); - } - result.BatteryData = specificResult.BatteryData; - result.Mission = genericResult.Mission; - result.Distance = genericResult.Distance; - result.TotalVehicleMass = specificResult.TotalVehicleMass; - result.Payload = specificResult.Payload; - result.PassengerCount = specificResult.PassengerCount; - result.VehicleClass = primaryResult.VehicleGroup; + + //var result = new CompletedBusResult { + // Status = VectoRun.Status.Success, + //}; + //result.Status = genericResult.Status != VectoRun.Status.Success ? genericResult.Status : result.Status; + //result.Status = specificResult.Status != VectoRun.Status.Success ? specificResult.Status : result.Status; + //result.OVCMode = specificResult.OVCMode; + //if (genericResult.OVCMode != specificResult.OVCMode) { + // throw new VectoException($"generic OVC Mode must be equal to specific OVC Mode! but was gen_ovc = {genericResult.OVCMode} != {specificResult.OVCMode} = spec_ovc"); + //} + //result.BatteryData = specificResult.BatteryData; + //result.Mission = genericResult.Mission; + //result.Distance = genericResult.Distance; + //result.TotalVehicleMass = specificResult.TotalVehicleMass; + //result.Payload = specificResult.Payload; + //result.PassengerCount = specificResult.PassengerCount; + //result.VehicleClass = primaryResult.VehicleGroup; - ///Factor for each fuel - /// Factor for electric Energy Consumption + /////Factor for each fuel + ///// Factor for electric Energy Consumption - //TODO: Add primary bus group to writer + ////TODO: Add primary bus group to writer - //TODO: - var combinedResults = (genericResult, specificResult); - //var speedFactor = CalculateFactor(combinedResults, r => r.AverageSpeed); - //result.AverageSpeed = primaryResult. + ////TODO: + //var combinedResults = (genericResult, specificResult); + ////var speedFactor = CalculateFactor(combinedResults, r => r.AverageSpeed); + ////result.AverageSpeed = primaryResult. - //Info not available in Primary Results -> no factor method - result.AverageSpeed = specificResult.AverageSpeed; - result.AverageDrivingSpeed = specificResult.AverageDrivingSpeed; - result.MinSpeed = specificResult.MinSpeed; - result.MaxSpeed = specificResult.MaxSpeed; + ////Info not available in Primary Results -> no factor method + //result.AverageSpeed = specificResult.AverageSpeed; + //result.AverageDrivingSpeed = specificResult.AverageDrivingSpeed; + //result.MinSpeed = specificResult.MinSpeed; + //result.MaxSpeed = specificResult.MaxSpeed; - result.MaxDeceleration = specificResult.MaxDeceleration; - result.MaxAcceleration = specificResult.MaxAcceleration; - result.FullLoadPercentage = specificResult.FullLoadPercentage; - result.GearshiftCount = specificResult.GearshiftCount; - result.EngineSpeedDrivingAvg = specificResult.EngineSpeedDrivingAvg; - result.EngineSpeedDrivingMin = specificResult.EngineSpeedDrivingMin; - result.EngineSpeedDrivingMax = specificResult.EngineSpeedDrivingMax; - result.AverageGearboxEfficiency = specificResult.AverageGearboxEfficiency; - result.AverageAxlegearEfficiency = specificResult.AverageAxlegearEfficiency; + //result.MaxDeceleration = specificResult.MaxDeceleration; + //result.MaxAcceleration = specificResult.MaxAcceleration; + //result.FullLoadPercentage = specificResult.FullLoadPercentage; + //result.GearshiftCount = specificResult.GearshiftCount; + //result.EngineSpeedDrivingAvg = specificResult.EngineSpeedDrivingAvg; + //result.EngineSpeedDrivingMin = specificResult.EngineSpeedDrivingMin; + //result.EngineSpeedDrivingMax = specificResult.EngineSpeedDrivingMax; + //result.AverageGearboxEfficiency = specificResult.AverageGearboxEfficiency; + //result.AverageAxlegearEfficiency = specificResult.AverageAxlegearEfficiency; - //Fuels - result.FuelData = specificResult.FuelData; - var co2Sum = 0.SI<Kilogram>(); + ////Fuels + //result.FuelData = specificResult.FuelData; + //var co2Sum = 0.SI<Kilogram>(); - foreach (var fuel in genericResult.CorrectedFinalFuelConsumption.Keys) { + //foreach (var fuel in genericResult.CorrectedFinalFuelConsumption.Keys) { - var fuelFactor = CalculateFactor(combinedResults, r => r.FuelConsumptionFinal(fuel).TotalFuelConsumptionCorrected); - var completedFuelConsumption = - fuelFactor * (primaryResult.EnergyConsumption[fuel] * specificResult.Distance); - var fuelConsumption = new CompletedBusFuelConsumption() { - Fuel = specificResult.FuelData.Single(f => f.FuelType == fuel), - EnergyDemand = completedFuelConsumption, - }; - co2Sum += fuelConsumption.TotalFuelConsumptionCorrected * fuelConsumption.Fuel.CO2PerFuelWeight; - result.CorrectedFinalFuelConsumption.Add(fuel, fuelConsumption); - } - result.CO2Total = co2Sum; - - - result.ElectricEnergyConsumption = null; + // var fuelFactor = CalculateFactor(combinedResults, r => r.FuelConsumptionFinal(fuel).TotalFuelConsumptionCorrected); + // var completedFuelConsumption = + // fuelFactor * (primaryResult.EnergyConsumption[fuel] * specificResult.Distance); + // var fuelConsumption = new CompletedBusFuelConsumption() { + // Fuel = specificResult.FuelData.Single(f => f.FuelType == fuel), + // EnergyDemand = completedFuelConsumption, + // }; + // co2Sum += fuelConsumption.TotalFuelConsumptionCorrected * fuelConsumption.Fuel.CO2PerFuelWeight; + // result.CorrectedFinalFuelConsumption.Add(fuel, fuelConsumption); + //} + //result.CO2Total = co2Sum; + + + // result.ElectricEnergyConsumption = null; - if (!(primaryResult.ElectricEnergyConsumption?.IsEqual(0) ?? true)){ - var electricEnergyFactor = CalculateFactor(combinedResults, - r => r.ElectricEnergyConsumption); - result.ElectricEnergyConsumption = - electricEnergyFactor * primaryResult.ElectricEnergyConsumption * specificResult.Distance; + //if (!(primaryResult.ElectricEnergyConsumption?.IsEqual(0) ?? true)){ + // var electricEnergyFactor = CalculateFactor(combinedResults, + // r => r.ElectricEnergyConsumption); + // result.ElectricEnergyConsumption = + // electricEnergyFactor * primaryResult.ElectricEnergyConsumption * specificResult.Distance; - } + // } - if (specificResult.ZEV_FuelConsumption_AuxHtr?.IsGreaterOrEqual(0) ?? false) { - result.ZEV_FuelConsumption_AuxHtr = specificResult.ZEV_FuelConsumption_AuxHtr; - var auxHeaterFuel = specificResult.AuxHeaterFuel; + //if (specificResult.ZEV_FuelConsumption_AuxHtr?.IsGreaterOrEqual(0) ?? false) { + // result.ZEV_FuelConsumption_AuxHtr = specificResult.ZEV_FuelConsumption_AuxHtr; + // var auxHeaterFuel = specificResult.AuxHeaterFuel; - result.AuxHeaterFuel = auxHeaterFuel; - result.FuelData.Add(auxHeaterFuel); + // result.AuxHeaterFuel = auxHeaterFuel; + // result.FuelData.Add(auxHeaterFuel); - result.ZEV_CO2 = result.ZEV_FuelConsumption_AuxHtr * auxHeaterFuel.CO2PerFuelWeight; - } + // result.ZEV_CO2 = result.ZEV_FuelConsumption_AuxHtr * auxHeaterFuel.CO2PerFuelWeight; + //} - if (genericResult.VectoRunData.JobType.IsOneOf(VectoSimulationJobType.BatteryElectricVehicle, - VectoSimulationJobType.IEPC_E)) { - var elRanges = DeclarationData.CalculateElectricRangesPEVCompletedBus(batteryData: result.BatteryData, - result.ElectricEnergyConsumption, result.Distance); + //if (genericResult.VectoRunData.JobType.IsOneOf(VectoSimulationJobType.BatteryElectricVehicle, + // VectoSimulationJobType.IEPC_E)) { + // var elRanges = DeclarationData.CalculateElectricRangesPEVCompletedBus(batteryData: result.BatteryData, + // result.ElectricEnergyConsumption, result.Distance); - result.EquivalentAllElectricRange = elRanges.EquivalentAllElectricRange; - result.ActualChargeDepletingRange = elRanges.ActualChargeDepletingRange; - result.ZeroCO2EmissionsRange = elRanges.ZeroCO2EmissionsRange; - } + // result.EquivalentAllElectricRange = elRanges.EquivalentAllElectricRange; + // result.ActualChargeDepletingRange = elRanges.ActualChargeDepletingRange; + // result.ZeroCO2EmissionsRange = elRanges.ZeroCO2EmissionsRange; + //} - _results.Add(result); + // _results.Add(result); } #endregion } diff --git a/VectoCore/VectoCore/OutputData/XML/XMLDeclarationReportCompletedVehicle.cs b/VectoCore/VectoCore/OutputData/XML/XMLDeclarationReportCompletedVehicle.cs index fcd9e4c1369febdfbeef31ab7f1edbfadb3eec6a..4eb0d953a7cc1c6b470ad73502d69fa9133045d0 100644 --- a/VectoCore/VectoCore/OutputData/XML/XMLDeclarationReportCompletedVehicle.cs +++ b/VectoCore/VectoCore/OutputData/XML/XMLDeclarationReportCompletedVehicle.cs @@ -2,12 +2,17 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using TUGraz.VectoCommon.BusAuxiliaries; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.Interfaces; using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Models.Simulation.Impl; +using TUGraz.VectoCore.Models.SimulationComponent.Data.ElectricComponents.Battery; +using TUGraz.VectoCore.OutputData.ModDataPostprocessing; using TUGraz.VectoCore.OutputData.XML.DeclarationReports.CustomerInformationFile; using TUGraz.VectoCore.OutputData.XML.DeclarationReports.CustomerInformationFile.CustomerInformationFile_0_9; using TUGraz.VectoCore.OutputData.XML.DeclarationReports.ManufacturerReport; @@ -50,6 +55,8 @@ namespace TUGraz.VectoCore.OutputData.XML iepc, ihpc); + + CustomerRpt = _cifFactory.GetCustomerReport( inputData.JobInputData.ConsolidateManufacturingStage.Vehicle.VehicleCategory, inputData.JobInputData.JobType, @@ -58,6 +65,7 @@ namespace TUGraz.VectoCore.OutputData.XML iepc, ihpc); + } public override void InitializeReport(VectoRunData modelData) { @@ -120,8 +128,8 @@ namespace TUGraz.VectoCore.OutputData.XML genericResult.VehicleClass, genericResult.Mission, genericResult.Payload); } - (ManufacturerRpt as IXMLManufacturerReportCompletedBus)?.WriteResult(genericResult, specificResult, primaryResult); - (CustomerRpt as IXMLCustomerReportCompletedBus)?.WriteResult(genericResult, specificResult, primaryResult); + (ManufacturerRpt as IXMLManufacturerReportCompletedBus)?.WriteResult(genericResult, specificResult, primaryResult, GetCompletedResult); + (CustomerRpt as IXMLCustomerReportCompletedBus)?.WriteResult(genericResult, specificResult, primaryResult, GetCompletedResult); } GenerateReports(); @@ -131,6 +139,272 @@ namespace TUGraz.VectoCore.OutputData.XML OutputReports(); } } + private double CalculateFactor<T>( + (IResultEntry genericResult, + IResultEntry specificResult) results, + Func<IResultEntry, T> access) + { + dynamic spec = access(results.specificResult); + dynamic gen = access(results.genericResult); + dynamic factor = spec / gen; + if (factor is Scalar sc) + { + return sc.Value(); + } + return (double)factor; + } + + + + private IResultEntry GetCompletedResult(IResultEntry generic, IResultEntry specific, IResult primary) + { + + var result = new CompletedBusResult + { + Status = VectoRun.Status.Success, + }; + result.Status = generic.Status != VectoRun.Status.Success ? generic.Status : result.Status; + result.Status = specific.Status != VectoRun.Status.Success ? specific.Status : result.Status; + result.OVCMode = specific.OVCMode; + if (generic.OVCMode != specific.OVCMode) + { + throw new VectoException($"generic OVC Mode must be equal to specific OVC Mode! but was gen_ovc = {generic.OVCMode} != {specific.OVCMode} = spec_ovc"); + } + result.BatteryData = specific.BatteryData; + result.Mission = generic.Mission; + result.Distance = generic.Distance; + result.TotalVehicleMass = specific.TotalVehicleMass; + result.Payload = specific.Payload; + result.PassengerCount = specific.PassengerCount; + result.VehicleClass = primary.VehicleGroup; + + + ///Factor for each fuel + /// Factor for electric Energy Consumption + + //TODO: Add primary bus group to writer + + + //TODO: + var combinedResults = (generic, specific); + //var speedFactor = CalculateFactor(combinedResults, r => r.AverageSpeed); + //result.AverageSpeed = primaryResult. + + //Info not available in Primary Results -> no factor method + result.AverageSpeed = specific.AverageSpeed; + result.AverageDrivingSpeed = specific.AverageDrivingSpeed; + result.MinSpeed = specific.MinSpeed; + result.MaxSpeed = specific.MaxSpeed; + + + + result.MaxDeceleration = specific.MaxDeceleration; + result.MaxAcceleration = specific.MaxAcceleration; + result.FullLoadPercentage = specific.FullLoadPercentage; + result.GearshiftCount = specific.GearshiftCount; + result.EngineSpeedDrivingAvg = specific.EngineSpeedDrivingAvg; + result.EngineSpeedDrivingMin = specific.EngineSpeedDrivingMin; + result.EngineSpeedDrivingMax = specific.EngineSpeedDrivingMax; + result.AverageGearboxEfficiency = specific.AverageGearboxEfficiency; + result.AverageAxlegearEfficiency = specific.AverageAxlegearEfficiency; + + + + //Fuels + result.FuelData = specific.FuelData; + var co2Sum = 0.SI<Kilogram>(); + + foreach (var fuel in generic.FuelData.Select(f => f.FuelType)) + { + + var fuelFactor = CalculateFactor(combinedResults, r => r.FuelConsumptionFinal(fuel).TotalFuelConsumptionCorrected); + var completedFuelConsumption = + fuelFactor * (primary.EnergyConsumption[fuel] * specific.Distance); + var fuelConsumption = new CompletedBusFuelConsumption() + { + Fuel = specific.FuelData.Single(f => f.FuelType == fuel), + EnergyDemand = completedFuelConsumption, + }; + co2Sum += fuelConsumption.TotalFuelConsumptionCorrected * fuelConsumption.Fuel.CO2PerFuelWeight; + result.CorrectedFinalFuelConsumption.Add(fuel, fuelConsumption); + } + result.CO2Total = co2Sum; + + + result.ElectricEnergyConsumption = null; + + if (!(primary.ElectricEnergyConsumption?.IsEqual(0) ?? true)) + { + var electricEnergyFactor = CalculateFactor(combinedResults, + r => r.ElectricEnergyConsumption); + result.ElectricEnergyConsumption = + electricEnergyFactor * primary.ElectricEnergyConsumption * specific.Distance; + + } + + + + if (specific.ZEV_FuelConsumption_AuxHtr?.IsGreaterOrEqual(0) ?? false) + { + result.ZEV_FuelConsumption_AuxHtr = specific.ZEV_FuelConsumption_AuxHtr; + var auxHeaterFuel = specific.AuxHeaterFuel; + + result.AuxHeaterFuel = auxHeaterFuel; + result.FuelData.Add(auxHeaterFuel); + + result.ZEV_CO2 = result.ZEV_FuelConsumption_AuxHtr * auxHeaterFuel.CO2PerFuelWeight; + } + + + + + if (generic.VectoRunData.JobType.IsOneOf(VectoSimulationJobType.BatteryElectricVehicle, + VectoSimulationJobType.IEPC_E)) + { + var elRanges = DeclarationData.CalculateElectricRangesPEVCompletedBus(batteryData: result.BatteryData, + result.ElectricEnergyConsumption, result.Distance); + + result.EquivalentAllElectricRange = elRanges.EquivalentAllElectricRange; + result.ActualChargeDepletingRange = elRanges.ActualChargeDepletingRange; + result.ZeroCO2EmissionsRange = elRanges.ZeroCO2EmissionsRange; + } + + return result; + } + + + + + private class CompletedBusResult : IResultEntry + { + #region Implementation of IResultEntry + + public void Initialize(VectoRunData vectoRunData) + { + throw new NotImplementedException(); + } + + public VectoRunData VectoRunData { get; } + public VectoRun.Status Status { get; set; } + public OvcHevMode OVCMode { get; set; } + public MissionType Mission { get; set; } + public LoadingType LoadingType { get; } + public int FuelMode { get; } + public IList<IFuelProperties> FuelData { get; set; } + public MeterPerSecond AverageSpeed { get; set; } + public MeterPerSecond AverageDrivingSpeed { get; set; } + public MeterPerSecond MaxSpeed { get; set; } + public MeterPerSecond MinSpeed { get; set; } + public MeterPerSquareSecond MaxDeceleration { get; set; } + public MeterPerSquareSecond MaxAcceleration { get; set; } + public PerSecond EngineSpeedDrivingMin { get; set; } + public PerSecond EngineSpeedDrivingAvg { get; set; } + public PerSecond EngineSpeedDrivingMax { get; set; } + public double AverageGearboxEfficiency { get; set; } + public double AverageAxlegearEfficiency { get; set; } + public Scalar FullLoadPercentage { get; set; } + public Scalar GearshiftCount { get; set; } + public Meter Distance { get; set; } + + + public Dictionary<FuelType, IFuelConsumptionCorrection> CorrectedFinalFuelConsumption = + new Dictionary<FuelType, IFuelConsumptionCorrection>(); + public IFuelConsumptionCorrection FuelConsumptionFinal(FuelType fuelType) + { + return CorrectedFinalFuelConsumption.ContainsKey(fuelType) ? CorrectedFinalFuelConsumption[fuelType] : null; + } + + public WattSecond ElectricEnergyConsumption { get; set; } + public Kilogram CO2Total { get; set; } + public Kilogram Payload { get; set; } + public Kilogram TotalVehicleMass { get; set; } + public CubicMeter CargoVolume { get; } + public double? PassengerCount { get; set; } + public VehicleClass VehicleClass { get; set; } + public Watt MaxChargingPower { get; } + public double WeightingFactor { get; } + public Meter ActualChargeDepletingRange { get; set; } + public Meter EquivalentAllElectricRange { get; set; } + public Meter ZeroCO2EmissionsRange { get; set; } + public IFuelProperties AuxHeaterFuel { get; set; } + public Kilogram ZEV_FuelConsumption_AuxHtr { get; set; } + public Kilogram ZEV_CO2 { get; set; } + + public void SetResultData(VectoRunData runData, IModalDataContainer data, double weightingFactor) + { + throw new NotImplementedException(); + } + + public string Error => throw new NotImplementedException(); + public string StackTrace => throw new NotImplementedException(); + public BatterySystemData BatteryData + { + get; + set; + } + + #endregion + } + + private class CompletedBusFuelConsumption : IFuelConsumptionCorrection + { + #region Implementation of IFuelConsumptionCorrection + + public IFuelProperties Fuel { get; set; } + + public KilogramPerWattSecond EngineLineCorrectionFactor => throw new NotImplementedException(); + + public KilogramPerWattSecond VehicleLine => throw new NotImplementedException(); + + public KilogramPerSecond FC_ESS_H => throw new NotImplementedException(); + + public KilogramPerSecond FC_ESS_CORR_H => throw new NotImplementedException(); + + public KilogramPerSecond FC_BusAux_PS_CORR_H => throw new NotImplementedException(); + + public KilogramPerSecond FC_BusAux_ES_CORR_H => throw new NotImplementedException(); + + public KilogramPerSecond FC_WHR_CORR_H => throw new NotImplementedException(); + + public KilogramPerSecond FC_AUXHTR_H => throw new NotImplementedException(); + + public KilogramPerSecond FC_AUXHTR_H_CORR => throw new NotImplementedException(); + + public KilogramPerSecond FC_REESS_SOC_H => throw new NotImplementedException(); + + public KilogramPerSecond FC_REESS_SOC_CORR_H => throw new NotImplementedException(); + + public KilogramPerSecond FC_FINAL_H => throw new NotImplementedException(); + + public KilogramPerMeter FC_WHR_CORR_KM => throw new NotImplementedException(); + + public KilogramPerMeter FC_BusAux_PS_CORR_KM => throw new NotImplementedException(); + + public KilogramPerMeter FC_BusAux_ES_CORR_KM => throw new NotImplementedException(); + + public KilogramPerMeter FC_AUXHTR_KM => throw new NotImplementedException(); + + public KilogramPerMeter FC_AUXHTR_KM_CORR => throw new NotImplementedException(); + + public KilogramPerMeter FC_REESS_SOC_KM => throw new NotImplementedException(); + + public KilogramPerMeter FC_REESS_SOC_CORR_KM => throw new NotImplementedException(); + + public KilogramPerMeter FC_ESS_KM => throw new NotImplementedException(); + + public KilogramPerMeter FC_ESS_CORR_KM => throw new NotImplementedException(); + + public KilogramPerMeter FC_FINAL_KM => throw new NotImplementedException(); + + public VolumePerMeter FuelVolumePerMeter => throw new NotImplementedException(); + + public Kilogram TotalFuelConsumptionCorrected => EnergyDemand / Fuel.LowerHeatingValueVecto; + + public Joule EnergyDemand { get; set; } + + #endregion + } + - } + } } \ No newline at end of file