From e1d106a9eb101f073847ddff8857efd1540edbe3 Mon Sep 17 00:00:00 2001 From: Michael Krisper <michael.krisper@gmail.com> Date: Fri, 6 Mar 2015 13:53:25 +0100 Subject: [PATCH] Reading FullLoadCurves --- .../Data/Engine/FullLoadCurve.cs | 59 +++++++++++++------ .../Data/EngineOnlyDrivingCycle.cs | 28 +++++++-- .../Data/VectoCSVReader.cs | 11 +++- VectoCore/Utils/DataRowExtensionMethods.cs | 12 ++++ 4 files changed, 84 insertions(+), 26 deletions(-) create mode 100644 VectoCore/Utils/DataRowExtensionMethods.cs diff --git a/VectoCore/Models/SimulationComponent/Data/Engine/FullLoadCurve.cs b/VectoCore/Models/SimulationComponent/Data/Engine/FullLoadCurve.cs index c245c3f1f3..ad1e2b3df5 100644 --- a/VectoCore/Models/SimulationComponent/Data/Engine/FullLoadCurve.cs +++ b/VectoCore/Models/SimulationComponent/Data/Engine/FullLoadCurve.cs @@ -1,26 +1,47 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Data; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine { - public class FullLoadCurve - { - public static FullLoadCurve ReadFromFile(string fileName) - { - return ReadFromJson(File.ReadAllText(fileName)); - } + /// <summary> + /// Four columns + /// One header line + /// At least two lines with numeric values (below file header) + /// Columns: + /// * n engine speed [1/min] + /// * Mfull full load torque [Nm] + /// * Mdrag motoring torque [Nm] + /// * PT1 PT1 time constant [s] - public static FullLoadCurve ReadFromJson(string json) - { - //todo: implement ReadFromJson - throw new NotImplementedException(); - return new FullLoadCurve(); - } + /// </summary> + public class FullLoadCurve + { + private class FullLoadCurveEntry + { + public double n { get; set; } + public double Mfull { get; set; } + public double Mdrag { get; set; } + public double PT1 { get; set; } + } - } + private List<FullLoadCurveEntry> entries; + + public FullLoadCurve(string fileName) + { + var data = VectoCSVReader.Read(fileName); + entries = new List<FullLoadCurveEntry>(); + + //todo: catch exceptions if value format is wrong. + foreach (DataRow row in data.Rows) + { + var entry = new FullLoadCurveEntry(); + entry.n = row.GetDouble("n"); + entry.Mfull = row.GetDouble("Mfull"); + entry.Mdrag = row.GetDouble("Mdrag"); + entry.PT1 = row.GetDouble("PT1"); + entries.Add(entry); + } + } + } } diff --git a/VectoCore/Models/SimulationComponent/Data/EngineOnlyDrivingCycle.cs b/VectoCore/Models/SimulationComponent/Data/EngineOnlyDrivingCycle.cs index a0f56e66a1..878970d14e 100644 --- a/VectoCore/Models/SimulationComponent/Data/EngineOnlyDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/Data/EngineOnlyDrivingCycle.cs @@ -1,12 +1,24 @@ using System; using System.Collections.Generic; using System.Data; +using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Data { /// <summary> /// Class for representation of one EngineOnly Driving Cycle /// </summary> + /// <remarks> + /// The driving cylce (.vdri) must contain: + /// <n> Engine speed + /// <Me>|<Pe> Engine torque or engine power at clutch. + /// + /// Optional: + /// <Padd> Additional power demand (aux) + /// + /// To explicitly define motoring operation use the <DRAG> keyword, see below. + /// VECTO replaces the keyword with the motoring torque/power from the .vfld file during calculation. + /// </remarks> public class EngineOnlyDrivingCycle { /// <summary> @@ -29,6 +41,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data set { T = 60.0 / (2.0 * Math.PI) * value / n; } } + /// <summary> + /// Additional power demand (aux) (Optional). + /// </summary> + public double Padd { get; set; } + public static List<EngineOnlyDrivingCycle> Read(string fileName) { var data = VectoCSVReader.Read(fileName); @@ -39,15 +56,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data foreach (DataRow row in data.Rows) { var cycle = new EngineOnlyDrivingCycle(); - cycle.n = double.Parse(row.Field<string>("n")); + cycle.n = row.GetDouble("n"); if (data.Columns.Contains("Pe")) - cycle.Pe = double.Parse(row.Field<string>("Pe")); + cycle.Pe = row.GetDouble("Pe"); else - cycle.T = double.Parse(row.Field<string>("Me")); + cycle.T = row.GetDouble("Me"); + + if (data.Columns.Contains("Padd")) + cycle.Padd = row.GetDouble("Padd"); + cycles.Add(cycle); } - return cycles; } } diff --git a/VectoCore/Models/SimulationComponent/Data/VectoCSVReader.cs b/VectoCore/Models/SimulationComponent/Data/VectoCSVReader.cs index ff65311709..d22b334d27 100644 --- a/VectoCore/Models/SimulationComponent/Data/VectoCSVReader.cs +++ b/VectoCore/Models/SimulationComponent/Data/VectoCSVReader.cs @@ -13,9 +13,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data /// <param name="fileName"></param> /// <returns>A DataTable which represents the CSV File.</returns> /// <remarks> - /// Header: All Combinations between max-format and min-format possible. Only "id"-field is used. - /// max: <id> (name) [unit], <id> (name) [unit], ... - /// min: id,id,... + /// The following format applies to all CSV (Comma-separated values) Input Files used in VECTO: + /// List Separator: Comma "," + /// Decimal-Mark: Dot "." + /// Comments: "#" at the beginning of the comment line. Number and position of comment lines is not limited. + /// Header: One header line (not a comment line) at the beginning of the file. + /// All Combinations between max-format and min-format possible. Only "id"-field is used. + /// max: <id> (name) [unit], <id> (name) [unit], ... + /// min: id,id,... /// </remarks> public static DataTable Read(string fileName) { diff --git a/VectoCore/Utils/DataRowExtensionMethods.cs b/VectoCore/Utils/DataRowExtensionMethods.cs new file mode 100644 index 0000000000..3c35077ae1 --- /dev/null +++ b/VectoCore/Utils/DataRowExtensionMethods.cs @@ -0,0 +1,12 @@ +using System.Data; + +namespace TUGraz.VectoCore.Utils +{ + public static class DataRowExtensionMethods + { + public static double GetDouble(this DataRow row, string columnName) + { + return double.Parse(row.Field<string>(columnName)); + } + } +} \ No newline at end of file -- GitLab