diff --git a/VectoCore/Models/SimulationComponent/Data/Engine/FuelConsumptionMap.cs b/VectoCore/Models/SimulationComponent/Data/Engine/FuelConsumptionMap.cs index 64bb14330ac052c23f5bfcc33294fd6d62ec63fb..b1d7c50f28f168b4fd28cdcff3eba24e6828dcc4 100644 --- a/VectoCore/Models/SimulationComponent/Data/Engine/FuelConsumptionMap.cs +++ b/VectoCore/Models/SimulationComponent/Data/Engine/FuelConsumptionMap.cs @@ -1,20 +1,48 @@ using System; +using System.Collections.Generic; +using System.Data; using System.IO; +using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine { + /// <summary> + /// Three columns + /// One header line + /// At least four lines with numeric values (below file header) + /// The map must cover the full engine range between full load and motoring curve. Extrapolation is not possible! + /// Columns: + /// * engine speed [1/min] + /// * engine torque [Nm] + /// * Fuel Consumption [g/h] + /// </summary> public class FuelConsumptionMap { - public static FuelConsumptionMap ReadFromFile(string fileName) + private class FuelConsumptionEntry { - return ReadFromJson(File.ReadAllText(fileName)); + public double EngineSpeed { get; set; } + public double Torque { get; set; } + public double FuelConsumption { get; set; } } - public static FuelConsumptionMap ReadFromJson(string json) + private List<FuelConsumptionEntry> entries; + + public FuelConsumptionMap ReadFromFile(string fileName) { - //todo implement ReadFromJson - throw new NotImplementedException(); - return new FuelConsumptionMap(); + var fuelConsumptionMap = new FuelConsumptionMap(); + var data = VectoCSVReader.Read(fileName); + fuelConsumptionMap.entries = new List<FuelConsumptionEntry>(); + + //todo: catch exceptions if value format is wrong. + foreach (DataRow row in data.Rows) + { + var entry = new FuelConsumptionEntry(); + entry.EngineSpeed = row.GetDouble("engine speed"); + entry.Torque = row.GetDouble("engine torque"); + entry.FuelConsumption = row.GetDouble("fuel consumption"); + fuelConsumptionMap.entries.Add(entry); + } + return fuelConsumptionMap; } } } diff --git a/VectoCore/Models/SimulationComponent/Data/Engine/FullLoadCurve.cs b/VectoCore/Models/SimulationComponent/Data/Engine/FullLoadCurve.cs index ad1e2b3df5708e3fe80942e046e86abba2b2a4ed..f5e24621febd91e47bf7501393b859d074bbb5c3 100644 --- a/VectoCore/Models/SimulationComponent/Data/Engine/FullLoadCurve.cs +++ b/VectoCore/Models/SimulationComponent/Data/Engine/FullLoadCurve.cs @@ -27,10 +27,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine private List<FullLoadCurveEntry> entries; - public FullLoadCurve(string fileName) + public FullLoadCurve ReadFromFile(string fileName) { + var fullLoadCurve = new FullLoadCurve(); var data = VectoCSVReader.Read(fileName); - entries = new List<FullLoadCurveEntry>(); + fullLoadCurve.entries = new List<FullLoadCurveEntry>(); //todo: catch exceptions if value format is wrong. foreach (DataRow row in data.Rows) @@ -40,8 +41,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine entry.Mfull = row.GetDouble("Mfull"); entry.Mdrag = row.GetDouble("Mdrag"); entry.PT1 = row.GetDouble("PT1"); - entries.Add(entry); + fullLoadCurve.entries.Add(entry); } + return fullLoadCurve; } } } diff --git a/VectoCore/Models/SimulationComponent/Data/EngineOnlyDrivingCycle.cs b/VectoCore/Models/SimulationComponent/Data/EngineOnlyDrivingCycle.cs index 878970d14e1c9043dd6e5aa1f5dab27f603a45c3..dde6c58ce6d6b28cc76be8341bd295b679023c5d 100644 --- a/VectoCore/Models/SimulationComponent/Data/EngineOnlyDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/Data/EngineOnlyDrivingCycle.cs @@ -46,7 +46,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data /// </summary> public double Padd { get; set; } - public static List<EngineOnlyDrivingCycle> Read(string fileName) + public static List<EngineOnlyDrivingCycle> ReadFromFile(string fileName) { var data = VectoCSVReader.Read(fileName); diff --git a/VectoCore/VectoCore.csproj b/VectoCore/VectoCore.csproj index 1f028bf6cf65af0f282c8f23894c1bccbf88a0b6..db298318d91b6fb208737e28928c61c691158322 100644 --- a/VectoCore/VectoCore.csproj +++ b/VectoCore/VectoCore.csproj @@ -86,6 +86,7 @@ <Compile Include="Models\SimulationComponent\SimulationComponentData.cs" /> <Compile Include="Models\SimulationComponent\VectoSimulationComponent.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="Utils\DataRowExtensionMethods.cs" /> </ItemGroup> <ItemGroup> <None Include="packages.config" /> diff --git a/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs b/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs index cd4a23f0894658ddb2feb411f232619365e0eff6..747b49cb2f0eac5864f78528eb5ad31038ba190c 100644 --- a/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs @@ -85,7 +85,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var engine = new CombustionEngine(engineData); var port = engine.OutShaft(); - var data = EngineOnlyDrivingCycle.Read("Coach Engine Only.vdri"); + var data = EngineOnlyDrivingCycle.ReadFromFile("Coach Engine Only.vdri"); var absTime = new TimeSpan(seconds: 0, minutes: 0, hours: 0); var dt = new TimeSpan(seconds: 1, minutes: 0, hours: 0);