diff --git a/VectoCore/Models/SimulationComponent/Data/CombustionEngineData.cs b/VectoCore/Models/SimulationComponent/Data/CombustionEngineData.cs index ad2abdeb9b4301e9129b6781ada10c2b9f60acef..47eec3714334dd6804e96e8b01d080c47c0078a5 100644 --- a/VectoCore/Models/SimulationComponent/Data/CombustionEngineData.cs +++ b/VectoCore/Models/SimulationComponent/Data/CombustionEngineData.cs @@ -1,11 +1,13 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Net.Mime; using System.Runtime.CompilerServices; using Newtonsoft.Json; +using NLog.Layouts; using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine; @@ -43,95 +45,178 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data /// </code> public class CombustionEngineData : SimulationComponentData { - private readonly Dictionary<string, FullLoadCurve> _fullLoadCurves = new Dictionary<string, FullLoadCurve>(); - - public static CombustionEngineData ReadFromFile(string fileName) + public class Data { - //todo: file exception handling: file not readable, wrong file format - return ReadFromJson(File.ReadAllText(fileName)); - } + public class DataHeader + { + [JsonProperty(Required = Required.Always)] + public string CreatedBy; - public static CombustionEngineData ReadFromJson(string json) - { - CombustionEngineData engine = new CombustionEngineData(); - var results = JsonConvert.DeserializeObject<dynamic>(json); + [JsonProperty(Required = Required.Always)] + public DateTime Date; - //todo: handle error when fields not exist - if (results["Header"] == null) { - throw new InvalidFileFormatException("could not find 'Header' Section"); - } - var header = results["Header"]; + [JsonProperty(Required = Required.Always)] + public string AppVersion; - if (header["FileVersion"] > 2) - throw new UnsupportedFileVersionException("Unsupported Version of .veng file. Got Version: " + header["FileVersion"]); + [JsonProperty(Required = Required.Always)] + public double FileVersion; + } - var body = results["Body"]; + [JsonProperty(Required = Required.Always)] + public DataHeader Header; - if (header["FileVersion"] > 1) - engine.SavedInDeclarationMode = body["SavedInDeclMode"]; + public class DataBody + { + public class DataFullLoadCurve + { + [JsonProperty(Required = Required.Always)] + public string Gears; - engine.ModelName = body["ModelName"]; - engine.Displacement = body["Displacement"]; - engine.IdleSpeed = body["IdlingSpeed"]; - engine.Inertia = body["Inertia"]; + [JsonProperty(Required = Required.Always)] + public string Path; + } + + [JsonProperty(Required = Required.Always)] + public IList<DataFullLoadCurve> FullLoadCurves; - // engine.GetType().GetProperty("Inertia").SetValue(engine, body["Inerita"]); + [JsonProperty("SavedInDeclMode")] + public bool SavedInDeclarationMode; - foreach (dynamic loadCurve in body["FullLoadCurves"]) - engine._fullLoadCurves[loadCurve["Gears"].Value] = FullLoadCurve.ReadFromFile(loadCurve["Path"].Value); + [JsonProperty(Required = Required.Always)] + public string ModelName; - engine.ConsumptionMap = FuelConsumptionMap.ReadFromFile(body["FuelMap"].Value); + [JsonProperty(Required = Required.Always)] + public double Displacement; - if (body["WHTC-Urban"] != null) - engine.WHTCUrban = body["WHTC-Urban"].Value; + [JsonProperty("IdlingSpeed", Required = Required.Always)] + public double IdleSpeed; - if (body["WHTC-Rural"] != null) - engine.WHTCRural = body["WHTC-Rural"].Value; + [JsonProperty(Required = Required.Always)] + public double Inertia; - if (body["WHTC-Motorway"] != null) - engine.WHTCMotorway = body["WHTC-Motorway"].Value; + [JsonProperty(Required = Required.Always)] + public string FuelMap; - return engine; - } + [JsonProperty("WHTC-Urban")] + public double WHTCUrban; - public double WHTCMotorway { get; set; } + [JsonProperty("WHTC-Rural")] + public double WHTCRural; - public double WHTCRural { get; set; } + [JsonProperty("WHTC-Motorway")] + public double WHTCMotorway; + } - public double WHTCUrban { get; set; } + [JsonProperty(Required = Required.Always)] + public DataBody Body; + } - public bool SavedInDeclarationMode { get; set; } + private Data _data; - /// <summary> - /// Engine description (e.g., mode, type, etc. - /// </summary> - public String ModelName { get; set; } + public bool SavedInDeclarationMode + { + get { return _data.Body.SavedInDeclarationMode; } + protected set { _data.Body.SavedInDeclarationMode = value; } + } - /// <summary> - /// Engine displacement [ccm] - /// </summary> - public double Displacement { get; set; } + public string ModelName + { + get { return _data.Body.ModelName; } + protected set { _data.Body.ModelName = value; } + } - public double IdleSpeed { get; set; } + public double Displacement + { + get { return _data.Body.Displacement; } + protected set { _data.Body.Displacement = value; } + } - public double RatedSpeed { get; set; } + public double IdleSpeed + { + get { return _data.Body.IdleSpeed; } + protected set { _data.Body.IdleSpeed = value; } + } + + public double Inertia + { + get { return _data.Body.Inertia; } + protected set { _data.Body.Inertia = value; } + } + + public double WHTCUrban + { + get { return _data.Body.WHTCUrban; } + protected set { _data.Body.WHTCUrban = value; } + } - public double Inertia { get; set; } + public double WHTCRural + { + get { return _data.Body.WHTCRural; } + protected set { _data.Body.WHTCRural = value; } + } - public double MaxPower { get; set; } + public double WHTCMotorway + { + get { return _data.Body.WHTCMotorway; } + protected set { _data.Body.WHTCMotorway = value; } + } public FuelConsumptionMap ConsumptionMap { get; set; } + private readonly Dictionary<string, FullLoadCurve> _fullLoadCurves = new Dictionary<string, FullLoadCurve>(); + + + + + + public static CombustionEngineData ReadFromFile(string fileName) + { + //todo: file exception handling: file not readable + return ReadFromJson(File.ReadAllText(fileName), Path.GetDirectoryName(fileName)); + } + + public static CombustionEngineData ReadFromJson(string json, string basePath = "") + { + var combustionEngineData = new CombustionEngineData(); + //todo handle conversion errors + var d = JsonConvert.DeserializeObject<Data>(json); + combustionEngineData._data = d; + + if (d.Header.FileVersion > 2) + throw new UnsupportedFileVersionException("Unsupported Version of .veng file. Got Version: " + d.Header.FileVersion); + + combustionEngineData.ConsumptionMap = FuelConsumptionMap.ReadFromFile(Path.Combine(basePath, d.Body.FuelMap)); + + foreach (var loadCurve in d.Body.FullLoadCurves) + { + var fullLoadCurve = FullLoadCurve.ReadFromFile(Path.Combine(basePath, loadCurve.Path)); + combustionEngineData._fullLoadCurves[loadCurve.Gears] = fullLoadCurve; + } + + return combustionEngineData; + } + + public string WriteToJson() + { + _data.Header.Date = DateTime.Now; + _data.Header.FileVersion = 2; + _data.Header.AppVersion = "3.0.0"; // todo: get current app version! + _data.Header.CreatedBy = ""; // todo: get current user + _data.Body.SavedInDeclarationMode = false; //todo: get declaration mode setting + return JsonConvert.SerializeObject(_data); + } + + public FullLoadCurve GetFullLoadCurve(uint gear) { - foreach (var gear_range in _fullLoadCurves.Keys) + foreach (var gearRange in _fullLoadCurves.Keys) { - var low = uint.Parse(gear_range.Split('-').First().Trim()); + var low = uint.Parse(gearRange.Split('-').First().Trim()); if (low <= gear) { - var high = uint.Parse(gear_range.Split('-').Last().Trim()); + var high = uint.Parse(gearRange.Split('-').Last().Trim()); if (high >= gear) - return _fullLoadCurves[gear_range]; + return _fullLoadCurves[gearRange]; } } throw new KeyNotFoundException(string.Format("Gear '{0}' was not found in the FullLoadCurves.", gear)); diff --git a/VectoCore/Models/SimulationComponent/Data/Engine/FuelConsumptionMap.cs b/VectoCore/Models/SimulationComponent/Data/Engine/FuelConsumptionMap.cs index 439e5c3f0730cea31d2ce0bb486ccb62bdeec4c5..c80db07eb799d3822082d111b06357a791f816bc 100644 --- a/VectoCore/Models/SimulationComponent/Data/Engine/FuelConsumptionMap.cs +++ b/VectoCore/Models/SimulationComponent/Data/Engine/FuelConsumptionMap.cs @@ -18,6 +18,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine /// </summary> public class FuelConsumptionMap { + private static class Fields + { + public const string EngineSpeed = "engine speed"; + public const string Torque = "torque"; + public const string FuelConsumption = "fuel consumption"; + }; + private class FuelConsumptionEntry { public double EngineSpeed { get; set; } @@ -25,24 +32,27 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine public double FuelConsumption { get; set; } } - private List<FuelConsumptionEntry> entries; + private IList<FuelConsumptionEntry> entries; - public static FuelConsumptionMap ReadFromFile(string fileName) + public FuelConsumptionMap(string fileName) { - var fuelConsumptionMap = new FuelConsumptionMap(); var data = VectoCSVReader.Read(fileName); - fuelConsumptionMap.entries = new List<FuelConsumptionEntry>(); + 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("torque"); - entry.FuelConsumption = row.GetDouble("fuel consumption"); - fuelConsumptionMap.entries.Add(entry); + entry.EngineSpeed = row.GetDouble(Fields.EngineSpeed); + entry.Torque = row.GetDouble(Fields.Torque); + entry.FuelConsumption = row.GetDouble(Fields.FuelConsumption); + entries.Add(entry); } - return fuelConsumptionMap; + } + + public static FuelConsumptionMap ReadFromFile(string fileName) + { + return new FuelConsumptionMap(fileName); } } } diff --git a/VectoCore/Models/SimulationComponent/Data/Engine/FullLoadCurve.cs b/VectoCore/Models/SimulationComponent/Data/Engine/FullLoadCurve.cs index d4169f07e2c1c7fac63ee39594cd74106200895e..646b4944a78e0ea47cf6bb387ac68c4a6e9ac3a8 100644 --- a/VectoCore/Models/SimulationComponent/Data/Engine/FullLoadCurve.cs +++ b/VectoCore/Models/SimulationComponent/Data/Engine/FullLoadCurve.cs @@ -17,6 +17,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine /// </summary> public class FullLoadCurve { + private static class Fields + { + public const string EngineSpeed = "n"; + public const string TorqueFullLoad = "Mfull"; + public const string TorqueDrag = "Mdrag"; + public const string PT1 = "PT1"; + } + + private class FullLoadCurveEntry { public double EngineSpeed { get; set; } @@ -37,10 +46,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine foreach (DataRow row in data.Rows) { var entry = new FullLoadCurveEntry(); - entry.EngineSpeed = row.GetDouble("n"); - entry.TorqueFullLoad = row.GetDouble("Mfull"); - entry.TorqueDrag = row.GetDouble("Mdrag"); - entry.PT1 = row.GetDouble("PT1"); + entry.EngineSpeed = row.GetDouble(Fields.EngineSpeed); + entry.TorqueFullLoad = row.GetDouble(Fields.TorqueFullLoad); + entry.TorqueDrag = row.GetDouble(Fields.TorqueDrag); + entry.PT1 = row.GetDouble(Fields.PT1); fullLoadCurve.entries.Add(entry); } return fullLoadCurve; diff --git a/VectoCore/Models/SimulationComponent/Data/EngineOnlyDrivingCycle.cs b/VectoCore/Models/SimulationComponent/Data/EngineOnlyDrivingCycle.cs index 34493133b70cd6edbc186b3227bf2dd8c5a684a7..c52472262d02af4787f02ec2fcc9641c0086f194 100644 --- a/VectoCore/Models/SimulationComponent/Data/EngineOnlyDrivingCycle.cs +++ b/VectoCore/Models/SimulationComponent/Data/EngineOnlyDrivingCycle.cs @@ -21,6 +21,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data /// </remarks> public class EngineOnlyDrivingCycle { + private static class Fields + { + public const string Pe = "Pe"; + public const string Padd = "Padd"; + public const string Me = "Me"; + public const string n = "n"; + } + /// <summary> /// Engine Speed /// </summary> @@ -56,15 +64,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data foreach (DataRow row in data.Rows) { var cycle = new EngineOnlyDrivingCycle(); - cycle.EngineSpeed = row.GetDouble("n"); + cycle.EngineSpeed = row.GetDouble(Fields.n); - if (data.Columns.Contains("Pe")) - cycle.PowerEngine = row.GetDouble("Pe"); + if (data.Columns.Contains(Fields.Pe)) + cycle.PowerEngine = row.GetDouble(Fields.Pe); else - cycle.Torque = row.GetDouble("Me"); + cycle.Torque = row.GetDouble(Fields.Me); - if (data.Columns.Contains("Padd")) - cycle.Padd = row.GetDouble("Padd"); + if (data.Columns.Contains(Fields.Padd)) + cycle.Padd = row.GetDouble(Fields.Padd); cycles.Add(cycle); } diff --git a/VectoCore/Models/SimulationComponent/Data/ModalResult.cs b/VectoCore/Models/SimulationComponent/Data/ModalResult.cs index 952f447ea567743f9e1500cf9bad40a959ebc146..b3e148b6b3e02d40ee4305b87d4fde4894f1fc33 100644 --- a/VectoCore/Models/SimulationComponent/Data/ModalResult.cs +++ b/VectoCore/Models/SimulationComponent/Data/ModalResult.cs @@ -1,86 +1,116 @@ using System; +using System.Collections.Generic; using System.Data; +using System.Diagnostics.Eventing.Reader; using System.Reflection; namespace TUGraz.VectoCore.Models.SimulationComponent.Data { + [System.ComponentModel.DesignerCategory("")] // to disable design view in VisualStudio public class ModalResults : DataTable { public ModalResults() { - foreach (ModalResult value in Enum.GetValues(typeof(ModalResult))) - Columns.Add(value.ToString(), value.GetDataType()); + foreach (ModalResultField value in Enum.GetValues(typeof(ModalResultField))) + Columns.Add(value.GetName(), value.GetDataType()); + } + + public ModalResults ReadFromFile(string fileName) + { + var modalResults = new ModalResults(); + var data = VectoCSVReader.Read(fileName); + foreach (DataRow row in data.Rows) + { + var new_row = modalResults.NewRow(); + foreach (DataColumn col in row.Table.Columns) + { + new_row.SetField(col, row.Field<object>(col)); + } + modalResults.Rows.Add(new_row); + } + modalResults.Load(data.CreateDataReader()); + return modalResults; } } /// <summary> /// Enum with field definitions of the Modal Results File (.vmod). /// </summary> - public enum ModalResult - { - [ModalResultFieldAttr(typeof(double))] time, // [s] Time step. - [ModalResultFieldAttr(typeof(double))] dist, // [km] Travelled distance. - [ModalResultFieldAttr(typeof(double))] v_act, // [km/h] Actual vehicle speed. - [ModalResultFieldAttr(typeof(double))] v_targ, // [km/h] Target vehicle speed. - [ModalResultFieldAttr(typeof(double))] acc, // [m/s2] Vehicle acceleration. - [ModalResultFieldAttr(typeof(double))] grad, // [%] Road gradient. - [ModalResultFieldAttr(typeof(double))] n, // [1/min] Engine speed. - [ModalResultFieldAttr(typeof(double))] Tq_eng, // [Nm] Engine torque. - [ModalResultFieldAttr(typeof(double))] Tq_clutch, // [Nm] Torque at clutch (before clutch, engine-side) - [ModalResultFieldAttr(typeof(double))] Tq_full, // [Nm] Full load torque - [ModalResultFieldAttr(typeof(double))] Tq_drag, // [Nm] Motoring torque - [ModalResultFieldAttr(typeof(double))] Pe_eng, // [kW] Engine power. - [ModalResultFieldAttr(typeof(double))] Pe_full, // [kW] Engine full load power. - [ModalResultFieldAttr(typeof(double))] Pe_drag, // [kW] Engine drag power. - [ModalResultFieldAttr(typeof(double))] Pe_clutch, // [kW] Engine power at clutch (equals Pe minus loss due to rotational inertia Pa Eng). - [ModalResultFieldAttr(typeof(double))] Gear, // [-] Gear. "0" = clutch opened / neutral. "0.5" = lock-up clutch is open (AT with torque converter only, see Gearbox) - [ModalResultFieldAttr(typeof(double))] PlossGB, // [kW] Gearbox losses. - [ModalResultFieldAttr(typeof(double))] PlossDiff, // [kW] Losses in differential / axle transmission. - [ModalResultFieldAttr(typeof(double))] PlossRetarder, // [kW] Retarder losses. - [ModalResultFieldAttr(typeof(double))] PaEng, // [kW] Rotational acceleration power: Engine. - [ModalResultFieldAttr(typeof(double))] PaGB, // [kW] Rotational acceleration power: Gearbox. - [ModalResultFieldAttr(typeof(double))] PaVeh, // [kW] Vehicle acceleration power. - [ModalResultFieldAttr(typeof(double))] Proll, // [kW] Rolling resistance power demand. - [ModalResultFieldAttr(typeof(double))] Pair, // [kW] Air resistance power demand. - [ModalResultFieldAttr(typeof(double))] Pgrad, // [kW] Power demand due to road gradient. - [ModalResultFieldAttr(typeof(double))] Paux, // [kW] Total auxiliary power demand . - [ModalResultFieldAttr(typeof(double))] Pwheel, // [kW] Total power demand at wheel = sum of rolling, air, acceleration and road gradient resistance. - [ModalResultFieldAttr(typeof(double))] Pbrake, // [kW] Brake power. Drag power is included in Pe. - [ModalResultFieldAttr(typeof(double))] Paux_xxx, // [kW] Power demand of Auxiliary with ID xxx. See also Aux Dialog and Driving Cycle. - [ModalResultFieldAttr(typeof(double))] FC, // [g/h] Fuel consumption from FC map.. - [ModalResultFieldAttr(typeof(double))] FC_AUXc, // [g/h] Fuel consumption after Auxiliary-Start/Stop Correction. (Based on FC.) - [ModalResultFieldAttr(typeof(double))] FC_WHTCc, // [g/h] Fuel consumption after WHTC Correction. (Based on FC-AUXc.) - [ModalResultFieldAttr(typeof(double))] TCν, // [-] Torque converter speed ratio - [ModalResultFieldAttr(typeof(double))] TCmu, // [-] Torque converter torque ratio - [ModalResultFieldAttr(typeof(double))] TC_M_Out, // [Nm] Torque converter output torque - [ModalResultFieldAttr(typeof(double))] TC_n_Out, // [1/min] Torque converter output speed + public enum ModalResultField + { + [ModalResultField(typeof(double))] time, // [s] Time step. + [ModalResultField(typeof(double))] n, // [1/min] Engine speed. + [ModalResultField(typeof(double))] Tq_eng, // [Nm] Engine torque. + [ModalResultField(typeof(double))] Tq_clutch, // [Nm] Torque at clutch (before clutch, engine-side) + [ModalResultField(typeof(double))] Tq_full, // [Nm] Full load torque + [ModalResultField(typeof(double))] Tq_drag, // [Nm] Motoring torque + [ModalResultField(typeof(double))] Pe_eng, // [kW] Engine power. + [ModalResultField(typeof(double))] Pe_full, // [kW] Engine full load power. + [ModalResultField(typeof(double))] Pe_drag, // [kW] Engine drag power. + [ModalResultField(typeof(double))] Pe_clutch, // [kW] Engine power at clutch (equals Pe minus loss due to rotational inertia Pa Eng). + [ModalResultField(typeof(double), "Pa")] PaEng, // [kW] Rotational acceleration power: Engine. + [ModalResultField(typeof(double))] Paux, // [kW] Total auxiliary power demand . + [ModalResultField(typeof(double))] FC, // [g/h] Fuel consumption from FC map.. + [ModalResultField(typeof(double), "FC-AUXc")] FCAUXc, // [g/h] Fuel consumption after Auxiliary-Start/Stop Correction. (Based on FC.) + [ModalResultField(typeof(double), "FC-WHTCc")] FCWHTCc, // [g/h] Fuel consumption after WHTC Correction. (Based on FC-AUXc.) + + + [ModalResultField(typeof(double))] dist, // [km] Travelled distance. + [ModalResultField(typeof(double))] v_act, // [km/h] Actual vehicle speed. + [ModalResultField(typeof(double))] v_targ, // [km/h] Target vehicle speed. + [ModalResultField(typeof(double))] acc, // [m/s2] Vehicle acceleration. + [ModalResultField(typeof(double))] grad, // [%] Road gradient. + [ModalResultField(typeof(double))] Gear, // [-] Gear. "0" = clutch opened / neutral. "0.5" = lock-up clutch is open (AT with torque converter only, see Gearbox) + [ModalResultField(typeof(double), "Ploss GB")] PlossGB, // [kW] Gearbox losses. + [ModalResultField(typeof(double), "Ploss Diff")] PlossDiff, // [kW] Losses in differential / axle transmission. + [ModalResultField(typeof(double), "Ploss Retarder")] PlossRetarder, // [kW] Retarder losses. + [ModalResultField(typeof(double), "Pa GB")] PaGB, // [kW] Rotational acceleration power: Gearbox. + [ModalResultField(typeof(double), "Pa Veh")] PaVeh, // [kW] Vehicle acceleration power. + [ModalResultField(typeof(double))] Proll, // [kW] Rolling resistance power demand. + [ModalResultField(typeof(double))] Pair, // [kW] Air resistance power demand. + [ModalResultField(typeof(double))] Pgrad, // [kW] Power demand due to road gradient. + [ModalResultField(typeof(double))] Pwheel, // [kW] Total power demand at wheel = sum of rolling, air, acceleration and road gradient resistance. + [ModalResultField(typeof(double))] Pbrake, // [kW] Brake power. Drag power is included in Pe. + //[ModalResultField(typeof(double))] Paux_xxx, // [kW] Power demand of Auxiliary with ID xxx. See also Aux Dialog and Driving Cycle. + [ModalResultField(typeof(double))] TCν, // [-] Torque converter speed ratio + [ModalResultField(typeof(double), "TCµ")] TCmu, // [-] Torque converter torque ratio + [ModalResultField(typeof(double))] TC_M_Out, // [Nm] Torque converter output torque + [ModalResultField(typeof(double))] TC_n_Out, // [1/min] Torque converter output speed } - [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] - class ModalResultFieldAttr : Attribute + + [AttributeUsage(AttributeTargets.Field)] + class ModalResultFieldAttribute : Attribute { - internal ModalResultFieldAttr(Type fieldType) + internal ModalResultFieldAttribute(Type fieldType, string name=null) { - this.FieldType = fieldType; + FieldType = fieldType; + Name = name; } public Type FieldType { get; private set; } + public string Name { get; private set; } } public static class ModalResultFieldExtensions { - public static Type GetDataType(this ModalResult field) + public static Type GetDataType(this ModalResultField field) { return GetAttr(field).FieldType; } - private static ModalResultFieldAttr GetAttr(ModalResult field) + public static string GetName(this ModalResultField field) + { + return GetAttr(field).Name ?? field.ToString(); + } + + private static ModalResultFieldAttribute GetAttr(ModalResultField field) { - return (ModalResultFieldAttr)Attribute.GetCustomAttribute(ForValue(field), typeof (ModalResultFieldAttr)); + return (ModalResultFieldAttribute)Attribute.GetCustomAttribute(ForValue(field), typeof (ModalResultFieldAttribute)); } - private static MemberInfo ForValue(ModalResult field) + private static MemberInfo ForValue(ModalResultField field) { - return typeof (ModalResult).GetField(Enum.GetName(typeof (ModalResult), field)); + return typeof (ModalResultField).GetField(Enum.GetName(typeof (ModalResultField), field)); } } } diff --git a/VectoCore/Models/SimulationComponent/IModalDataWriter.cs b/VectoCore/Models/SimulationComponent/IModalDataWriter.cs index 0b7b917d2398cf204d2e16f2226814f35af1d0e2..0cb5568d12c507cd051ef1de2a7a9cdf234f5315 100644 --- a/VectoCore/Models/SimulationComponent/IModalDataWriter.cs +++ b/VectoCore/Models/SimulationComponent/IModalDataWriter.cs @@ -9,7 +9,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent /// </summary> /// <param name="key"></param> /// <returns></returns> - object this[ModalResult key] { get; set; } + object this[ModalResultField key] { get; set; } /// <summary> /// Commits the data of the current simulation step. diff --git a/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs b/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs index 49b218259da1f468e40bdab8f537dd4089f97082..422ec67ffe10fbd93636a4b4b55d54028d270166 100644 --- a/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs +++ b/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs @@ -19,9 +19,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public override void CommitSimulationStep(IModalDataWriter writer) { - writer[ModalResult.FC] = 1; - writer[ModalResult.FC_AUXc] = 2; - writer[ModalResult.FC_WHTCc] = 3; + writer[ModalResultField.FC] = 1; + writer[ModalResultField.FCAUXc] = 2; + writer[ModalResultField.FCWHTCc] = 3; } public void Request(TimeSpan absTime, TimeSpan dt, double torque, double engineSpeed) diff --git a/VectoCore/VectoCore.csproj b/VectoCore/VectoCore.csproj index fe4c49b887724a81ce1dfd3dd0cf5f36a8cd82da..49269220eb1f6d3a3e684b80264f6c63592a6a1c 100644 --- a/VectoCore/VectoCore.csproj +++ b/VectoCore/VectoCore.csproj @@ -69,9 +69,7 @@ <Compile Include="Models\Connector\Ports\IOutShaft.cs" /> <Compile Include="Models\Connector\Ports\ITnPort.cs" /> <Compile Include="Models\SimulationComponent\Data\EngineOnlyDrivingCycle.cs" /> - <Compile Include="Models\SimulationComponent\Data\ModalResult.cs"> - <SubType>Component</SubType> - </Compile> + <Compile Include="Models\SimulationComponent\Data\ModalResult.cs" /> <Compile Include="Models\SimulationComponent\Data\CombustionEngineData.cs" /> <Compile Include="Models\SimulationComponent\Data\Engine\FuelConsumptionMap.cs" /> <Compile Include="Models\SimulationComponent\Data\Engine\FullLoadCurve.cs" /> diff --git a/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs b/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs index 5a2b3841fe4c399bf545ca4f08e7114c13f7b183..5820bfe45adce9b51f967d81007b92f7a6f5cf46 100644 --- a/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs @@ -1,9 +1,7 @@ using System; -using System.Data; using System.IO; using System.Reflection; using Microsoft.VisualStudio.TestTools.UnitTesting; -using TUGraz.VectoCore.Models.Connector.Ports; using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Models.SimulationComponent.Impl; using TUGraz.VectoCore.Tests.Utils; @@ -69,9 +67,9 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent engine.CommitSimulationStep(dataWriter); //todo: test with correct output values, add other fields to test - Assert.AreEqual(dataWriter[ModalResult.FC], 13000); - Assert.AreEqual(dataWriter[ModalResult.FC_AUXc], 14000); - Assert.AreEqual(dataWriter[ModalResult.FC_WHTCc], 15000); + Assert.AreEqual(dataWriter[ModalResultField.FC], 13000); + Assert.AreEqual(dataWriter[ModalResultField.FCAUXc], 14000); + Assert.AreEqual(dataWriter[ModalResultField.FCWHTCc], 15000); } [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\TestData\\EngineTests.csv", "EngineTests#csv", DataAccessMethod.Sequential)] @@ -98,15 +96,15 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent absTime += dt; //todo: test with correct output values, add other fields to test - Assert.AreEqual(dataWriter[ModalResult.FC], 13000); - Assert.AreEqual(dataWriter[ModalResult.FC_AUXc], 14000); - Assert.AreEqual(dataWriter[ModalResult.FC_WHTCc], 15000); + Assert.AreEqual(dataWriter[ModalResultField.FC], 13000); + Assert.AreEqual(dataWriter[ModalResultField.FCAUXc], 14000); + Assert.AreEqual(dataWriter[ModalResultField.FCWHTCc], 15000); } //todo: test with correct output values, add other fields to test - Assert.AreEqual(dataWriter[ModalResult.FC], 13000); - Assert.AreEqual(dataWriter[ModalResult.FC_AUXc], 14000); - Assert.AreEqual(dataWriter[ModalResult.FC_WHTCc], 15000); + Assert.AreEqual(dataWriter[ModalResultField.FC], 13000); + Assert.AreEqual(dataWriter[ModalResultField.FCAUXc], 14000); + Assert.AreEqual(dataWriter[ModalResultField.FCWHTCc], 15000); } diff --git a/VectoCoreTest/Utils/TestModalDataWriter.cs b/VectoCoreTest/Utils/TestModalDataWriter.cs index 34e706427021729bf3e4b7285da693f58aa8df1f..53a0ffaf5638be836323790c5340f901ae536386 100644 --- a/VectoCoreTest/Utils/TestModalDataWriter.cs +++ b/VectoCoreTest/Utils/TestModalDataWriter.cs @@ -25,7 +25,7 @@ namespace TUGraz.VectoCore.Tests.Utils CurrentRow = Data.NewRow(); } - public object this[ModalResult key] + public object this[ModalResultField key] { get { return CurrentRow[key.ToString()]; } set { CurrentRow[key.ToString()] = value; } diff --git a/VectoCoreTest/app.config b/VectoCoreTest/app.config index 49cc43e1d8f54e541889767ccf34bebecdf5255f..bc9afdc70595b19cb2fc8459c09c07dd10c8f09d 100644 --- a/VectoCoreTest/app.config +++ b/VectoCoreTest/app.config @@ -1,3 +1,33 @@ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> <configuration> + <configSections> + <sectionGroup name="common"> + <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" /> + </sectionGroup> + <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" /> + </configSections> + <runtime> + <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> + <dependentAssembly> + <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" /> + </dependentAssembly> + </assemblyBinding> + </runtime> + <common> + <logging> + <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog31"> + <arg key="configType" value="INLINE" /> + </factoryAdapter> + </logging> + </common> + <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <targets> + <target xsi:type="Console" name="ConsoleLogger" error="true" /> + <target xsi:type="File" name="LogFile" filename="${basedir}/logs/log.txt" layout="${longdate} [${processid}@${machinename}] ${callsite} ${level:uppercase=true}: ${message}" /> + </targets> + <rules> + <logger name="*" minlevel="Info" writeTo="LogFile" /> + </rules> + </nlog> </configuration> \ No newline at end of file