From ee2bb22c806436e71f7e2f5b3c4e00a8cda0892b Mon Sep 17 00:00:00 2001 From: Stefanos Doumpoulakis <dubulak@gmail.com> Date: Wed, 12 Oct 2022 19:21:10 +0300 Subject: [PATCH] a)bugfix in reading NCVs, b)added check: fuel types match cycle data --- .../InputData/FileIO/JSON/JSONInputData.cs | 15 ++++++----- .../DeclarationVTPModeVectoRunDataFactory.cs | 27 +++++++++++++++---- .../EngineeringVTPModeVectoRunDataFactory.cs | 4 ++- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs index f0168d53b6..56947d5ee5 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs @@ -908,13 +908,16 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON fuelNCVs.Add(new FuelNCVData() { Type = matches.First(), NCV = (ncv * Constants.Mega).SI<JoulePerKilogramm>() }); } - var fuels = JobInputData.Vehicle.Components.EngineInputData.EngineModes.First().Fuels; + var fuelsPerMode = JobInputData.Vehicle.Components.EngineInputData.EngineModes.Select( + x => x.Fuels.Select(f => DeclarationData.FuelData.Lookup(f.FuelType, JobInputData.Vehicle.TankSystem))); - foreach (var fuel in fuels) { - if (fuelNCVs.Count(x => x.Type == fuel.FuelType) == 0) { - throw new Exception($"Job input data: {JsonKeys.Job_FuelNCVs}: missing {JsonKeys.Job_FuelNCV_Type}: {fuel.FuelType.GetLabel()}"); - } - } + foreach (var fuels in fuelsPerMode) { + foreach (var fuel in fuels) { + if (fuelNCVs.Count(x => x.Type == fuel.FuelType) == 0) { + throw new Exception($"Job input data: {JsonKeys.Job_FuelNCVs}: missing {JsonKeys.Job_FuelNCV_Type}: {fuel.FuelType.GetLabel()}"); + } + } + } return fuelNCVs; } diff --git a/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationVTPModeVectoRunDataFactory.cs b/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationVTPModeVectoRunDataFactory.cs index 377c6043bf..7bf0fd47d2 100644 --- a/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationVTPModeVectoRunDataFactory.cs +++ b/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationVTPModeVectoRunDataFactory.cs @@ -42,6 +42,7 @@ using TUGraz.VectoCore.InputData.Reader.ComponentData; using TUGraz.VectoCore.InputData.Reader.DataObjectAdapter; using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Models.SimulationComponent; using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.OutputData; @@ -208,8 +209,8 @@ namespace TUGraz.VectoCore.InputData.Reader.Impl throw new VectoException("no VTP-Cycle provided!"); } var drivingCycle = DrivingCycleDataReader.ReadFromDataTable(vtpCycle.CycleData, vtpCycle.Name, false); - - ValidateFanTypeMatchesInputData(drivingCycle); + ValidateFanTypeMatchesCycleData(drivingCycle); + ValidateFuelTypesMatchCycleData(drivingCycle); // Loading is not relevant as we use P_wheel var vtpRunData = CreateVectoRunData(Segment, Segment.Missions.First(), 0.SI<Kilogram>()); @@ -243,14 +244,30 @@ namespace TUGraz.VectoCore.InputData.Reader.Impl yield return vtpRunData; } - protected void ValidateFanTypeMatchesInputData(DrivingCycleData cycle) + protected void ValidateFuelTypesMatchCycleData(DrivingCycleData drivingCycle) + { + var fuelsPerMode = JobInputData.Vehicle.Components.EngineInputData.EngineModes.Select( + x => x.Fuels.Select(f => DeclarationData.FuelData.Lookup(f.FuelType, JobInputData.Vehicle.TankSystem))); + + foreach (var fuels in fuelsPerMode) { + foreach (var fuel in fuels) { + if ((drivingCycle.Entries.First().Fuelconsumption != null) + && !drivingCycle.Entries.First().Fuelconsumption.ContainsKey(fuel.FuelType)) { + + throw new VectoException($"Cycle {drivingCycle.Name} is missing {fuel.FuelType} input data."); + } + } + } + } + + protected void ValidateFanTypeMatchesCycleData(DrivingCycleData drivingCycle) { var fan = JobInputData.Vehicle.Components.AuxiliaryInputData.Auxiliaries.First(x => x.Type == AuxiliaryType.Fan); var fanFullyElectric = DeclarationData.Fan.FullyElectricTechnologies().Contains(fan.Technology.First()); - var cycleHasFanElectricalPower = cycle.Entries.First().FanElectricalPower != null; + var cycleHasFanElectricalPower = drivingCycle.Entries.First().FanElectricalPower != null; if (fanFullyElectric ^ cycleHasFanElectricalPower) { - throw new VectoException($"Fan is{(fanFullyElectric ? "" : " not")} electric, while cycle has{(cycleHasFanElectricalPower ? "" : " no")} input for fan electrical power"); + throw new VectoException($"Fan is{(fanFullyElectric ? "" : " not")} electric, while cycle has{(cycleHasFanElectricalPower ? "" : " no")} input for fan electrical power."); } } diff --git a/VectoCore/VectoCore/InputData/Reader/Impl/EngineeringVTPModeVectoRunDataFactory.cs b/VectoCore/VectoCore/InputData/Reader/Impl/EngineeringVTPModeVectoRunDataFactory.cs index 00500d3623..119e4bf62d 100644 --- a/VectoCore/VectoCore/InputData/Reader/Impl/EngineeringVTPModeVectoRunDataFactory.cs +++ b/VectoCore/VectoCore/InputData/Reader/Impl/EngineeringVTPModeVectoRunDataFactory.cs @@ -61,7 +61,9 @@ namespace TUGraz.VectoCore.InputData.Reader.Impl return JobInputData.Cycles.Select( cycle => { var drivingCycle = DrivingCycleDataReader.ReadFromDataTable(cycle.CycleData, cycle.Name, false); - ValidateFanTypeMatchesInputData(drivingCycle); + ValidateFanTypeMatchesCycleData(drivingCycle); + ValidateFuelTypesMatchCycleData(drivingCycle); + // loading is not relevant as we use P_wheel var runData = CreateVectoRunData(Segment, Segment.Missions.First(), 0.SI<Kilogram>()); runData.Cycle = new DrivingCycleProxy(drivingCycle, cycle.Name); -- GitLab