Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 3d3fc06e authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

Merge branch 'feature/VECTO-53-read-and-write-datafiles' of...

Merge branch 'feature/VECTO-53-read-and-write-datafiles' of https://webgate.ec.europa.eu/CITnet/stash/scm/~emkrispmi/vecto-sim into feature/VECTO-54-implement-software-tests-for-engine

Conflicts:
	VectoCore/Models/SimulationComponent/Data/CombustionEngineData.cs
parents 2bb3908c 2ddc7694
No related branches found
No related tags found
No related merge requests found
Showing
with 312 additions and 144 deletions
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net.Mime; using System.Net.Mime;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using Newtonsoft.Json; using Newtonsoft.Json;
using NLog.Layouts;
using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine; using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine;
...@@ -43,95 +45,178 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data ...@@ -43,95 +45,178 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
/// </code> /// </code>
public class CombustionEngineData : SimulationComponentData public class CombustionEngineData : SimulationComponentData
{ {
private readonly Dictionary<string, FullLoadCurve> _fullLoadCurves = new Dictionary<string, FullLoadCurve>(); public class Data
{
public static CombustionEngineData ReadFromFile(string fileName) public class DataHeader
{ {
//todo: file exception handling: file not readable, wrong file format [JsonProperty(Required = Required.Always)]
return ReadFromJson(File.ReadAllText(fileName)); public string CreatedBy;
[JsonProperty(Required = Required.Always)]
public DateTime Date;
[JsonProperty(Required = Required.Always)]
public string AppVersion;
[JsonProperty(Required = Required.Always)]
public double FileVersion;
} }
public static CombustionEngineData ReadFromJson(string json) [JsonProperty(Required = Required.Always)]
public DataHeader Header;
public class DataBody
{
public class DataFullLoadCurve
{ {
CombustionEngineData engine = new CombustionEngineData(); [JsonProperty(Required = Required.Always)]
var results = JsonConvert.DeserializeObject<dynamic>(json); public string Gears;
//todo: handle error when fields not exist [JsonProperty(Required = Required.Always)]
if (results["Header"] == null) { public string Path;
throw new InvalidFileFormatException("could not find 'Header' Section");
} }
var header = results["Header"];
if (header["FileVersion"] > 2) [JsonProperty(Required = Required.Always)]
throw new UnsupportedFileVersionException("Unsupported Version of .veng file. Got Version: " + header["FileVersion"]); public IList<DataFullLoadCurve> FullLoadCurves;
var body = results["Body"]; [JsonProperty("SavedInDeclMode")]
public bool SavedInDeclarationMode;
if (header["FileVersion"] > 1) [JsonProperty(Required = Required.Always)]
engine.SavedInDeclarationMode = body["SavedInDeclMode"]; public string ModelName;
engine.ModelName = body["ModelName"]; [JsonProperty(Required = Required.Always)]
engine.Displacement = body["Displacement"]; public double Displacement;
engine.IdleSpeed = body["IdlingSpeed"];
engine.Inertia = body["Inertia"];
// engine.GetType().GetProperty("Inertia").SetValue(engine, body["Inerita"]); [JsonProperty("IdlingSpeed", Required = Required.Always)]
public double IdleSpeed;
foreach (dynamic loadCurve in body["FullLoadCurves"]) [JsonProperty(Required = Required.Always)]
engine._fullLoadCurves[loadCurve["Gears"].Value] = FullLoadCurve.ReadFromFile(loadCurve["Path"].Value); public double Inertia;
engine.ConsumptionMap = FuelConsumptionMap.ReadFromFile(body["FuelMap"].Value); [JsonProperty(Required = Required.Always)]
public string FuelMap;
if (body["WHTC-Urban"] != null) [JsonProperty("WHTC-Urban")]
engine.WHTCUrban = body["WHTC-Urban"].Value; public double WHTCUrban;
if (body["WHTC-Rural"] != null) [JsonProperty("WHTC-Rural")]
engine.WHTCRural = body["WHTC-Rural"].Value; public double WHTCRural;
if (body["WHTC-Motorway"] != null) [JsonProperty("WHTC-Motorway")]
engine.WHTCMotorway = body["WHTC-Motorway"].Value; public double WHTCMotorway;
return engine;
} }
public double WHTCMotorway { get; set; } [JsonProperty(Required = Required.Always)]
public DataBody Body;
}
public double WHTCRural { get; set; } private Data _data;
public double WHTCUrban { get; set; } public bool SavedInDeclarationMode
{
get { return _data.Body.SavedInDeclarationMode; }
protected set { _data.Body.SavedInDeclarationMode = value; }
}
public bool SavedInDeclarationMode { get; set; } public string ModelName
{
get { return _data.Body.ModelName; }
protected set { _data.Body.ModelName = value; }
}
/// <summary> public double Displacement
/// Engine description (e.g., mode, type, etc. {
/// </summary> get { return _data.Body.Displacement; }
public String ModelName { get; set; } protected set { _data.Body.Displacement = value; }
}
/// <summary> public double IdleSpeed
/// Engine displacement [ccm] {
/// </summary> get { return _data.Body.IdleSpeed; }
public double Displacement { get; set; } protected set { _data.Body.IdleSpeed = value; }
}
public double IdleSpeed { get; set; } public double Inertia
{
get { return _data.Body.Inertia; }
protected set { _data.Body.Inertia = value; }
}
public double RatedSpeed { get; set; } 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; } 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) 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) if (low <= gear)
{ {
var high = uint.Parse(gear_range.Split('-').Last().Trim()); var high = uint.Parse(gearRange.Split('-').Last().Trim());
if (high >= gear) if (high >= gear)
return _fullLoadCurves[gear_range]; return _fullLoadCurves[gearRange];
} }
} }
throw new KeyNotFoundException(string.Format("Gear '{0}' was not found in the FullLoadCurves.", gear)); throw new KeyNotFoundException(string.Format("Gear '{0}' was not found in the FullLoadCurves.", gear));
......
...@@ -18,6 +18,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine ...@@ -18,6 +18,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine
/// </summary> /// </summary>
public class FuelConsumptionMap 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 private class FuelConsumptionEntry
{ {
public double EngineSpeed { get; set; } public double EngineSpeed { get; set; }
...@@ -25,24 +32,27 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine ...@@ -25,24 +32,27 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine
public double FuelConsumption { get; set; } 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); var data = VectoCSVReader.Read(fileName);
fuelConsumptionMap.entries = new List<FuelConsumptionEntry>(); entries = new List<FuelConsumptionEntry>();
//todo: catch exceptions if value format is wrong. //todo: catch exceptions if value format is wrong.
foreach (DataRow row in data.Rows) foreach (DataRow row in data.Rows)
{ {
var entry = new FuelConsumptionEntry(); var entry = new FuelConsumptionEntry();
entry.EngineSpeed = row.GetDouble("engine speed"); entry.EngineSpeed = row.GetDouble(Fields.EngineSpeed);
entry.Torque = row.GetDouble("torque"); entry.Torque = row.GetDouble(Fields.Torque);
entry.FuelConsumption = row.GetDouble("fuel consumption"); entry.FuelConsumption = row.GetDouble(Fields.FuelConsumption);
fuelConsumptionMap.entries.Add(entry); entries.Add(entry);
}
} }
return fuelConsumptionMap;
public static FuelConsumptionMap ReadFromFile(string fileName)
{
return new FuelConsumptionMap(fileName);
} }
} }
} }
...@@ -17,6 +17,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine ...@@ -17,6 +17,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine
/// </summary> /// </summary>
public class FullLoadCurve 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 private class FullLoadCurveEntry
{ {
public double EngineSpeed { get; set; } public double EngineSpeed { get; set; }
...@@ -37,10 +46,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine ...@@ -37,10 +46,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine
foreach (DataRow row in data.Rows) foreach (DataRow row in data.Rows)
{ {
var entry = new FullLoadCurveEntry(); var entry = new FullLoadCurveEntry();
entry.EngineSpeed = row.GetDouble("n"); entry.EngineSpeed = row.GetDouble(Fields.EngineSpeed);
entry.TorqueFullLoad = row.GetDouble("Mfull"); entry.TorqueFullLoad = row.GetDouble(Fields.TorqueFullLoad);
entry.TorqueDrag = row.GetDouble("Mdrag"); entry.TorqueDrag = row.GetDouble(Fields.TorqueDrag);
entry.PT1 = row.GetDouble("PT1"); entry.PT1 = row.GetDouble(Fields.PT1);
fullLoadCurve.entries.Add(entry); fullLoadCurve.entries.Add(entry);
} }
return fullLoadCurve; return fullLoadCurve;
......
...@@ -21,6 +21,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data ...@@ -21,6 +21,14 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
/// </remarks> /// </remarks>
public class EngineOnlyDrivingCycle 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> /// <summary>
/// Engine Speed /// Engine Speed
/// </summary> /// </summary>
...@@ -56,15 +64,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data ...@@ -56,15 +64,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
foreach (DataRow row in data.Rows) foreach (DataRow row in data.Rows)
{ {
var cycle = new EngineOnlyDrivingCycle(); var cycle = new EngineOnlyDrivingCycle();
cycle.EngineSpeed = row.GetDouble("n"); cycle.EngineSpeed = row.GetDouble(Fields.n);
if (data.Columns.Contains("Pe")) if (data.Columns.Contains(Fields.Pe))
cycle.PowerEngine = row.GetDouble("Pe"); cycle.PowerEngine = row.GetDouble(Fields.Pe);
else else
cycle.Torque = row.GetDouble("Me"); cycle.Torque = row.GetDouble(Fields.Me);
if (data.Columns.Contains("Padd")) if (data.Columns.Contains(Fields.Padd))
cycle.Padd = row.GetDouble("Padd"); cycle.Padd = row.GetDouble(Fields.Padd);
cycles.Add(cycle); cycles.Add(cycle);
} }
......
using System; using System;
using System.Collections.Generic;
using System.Data; using System.Data;
using System.Diagnostics.Eventing.Reader;
using System.Reflection; using System.Reflection;
namespace TUGraz.VectoCore.Models.SimulationComponent.Data namespace TUGraz.VectoCore.Models.SimulationComponent.Data
{ {
[System.ComponentModel.DesignerCategory("")] // to disable design view in VisualStudio
public class ModalResults : DataTable public class ModalResults : DataTable
{ {
public ModalResults() public ModalResults()
{ {
foreach (ModalResult value in Enum.GetValues(typeof(ModalResult))) foreach (ModalResultField value in Enum.GetValues(typeof(ModalResultField)))
Columns.Add(value.ToString(), value.GetDataType()); 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> /// <summary>
/// Enum with field definitions of the Modal Results File (.vmod). /// Enum with field definitions of the Modal Results File (.vmod).
/// </summary> /// </summary>
public enum ModalResult public enum ModalResultField
{ {
[ModalResultFieldAttr(typeof(double))] time, // [s] Time step. [ModalResultField(typeof(double))] time, // [s] Time step.
[ModalResultFieldAttr(typeof(double))] dist, // [km] Travelled distance. [ModalResultField(typeof(double))] n, // [1/min] Engine speed.
[ModalResultFieldAttr(typeof(double))] v_act, // [km/h] Actual vehicle speed. [ModalResultField(typeof(double))] Tq_eng, // [Nm] Engine torque.
[ModalResultFieldAttr(typeof(double))] v_targ, // [km/h] Target vehicle speed. [ModalResultField(typeof(double))] Tq_clutch, // [Nm] Torque at clutch (before clutch, engine-side)
[ModalResultFieldAttr(typeof(double))] acc, // [m/s2] Vehicle acceleration. [ModalResultField(typeof(double))] Tq_full, // [Nm] Full load torque
[ModalResultFieldAttr(typeof(double))] grad, // [%] Road gradient. [ModalResultField(typeof(double))] Tq_drag, // [Nm] Motoring torque
[ModalResultFieldAttr(typeof(double))] n, // [1/min] Engine speed. [ModalResultField(typeof(double))] Pe_eng, // [kW] Engine power.
[ModalResultFieldAttr(typeof(double))] Tq_eng, // [Nm] Engine torque. [ModalResultField(typeof(double))] Pe_full, // [kW] Engine full load power.
[ModalResultFieldAttr(typeof(double))] Tq_clutch, // [Nm] Torque at clutch (before clutch, engine-side) [ModalResultField(typeof(double))] Pe_drag, // [kW] Engine drag power.
[ModalResultFieldAttr(typeof(double))] Tq_full, // [Nm] Full load torque [ModalResultField(typeof(double))] Pe_clutch, // [kW] Engine power at clutch (equals Pe minus loss due to rotational inertia Pa Eng).
[ModalResultFieldAttr(typeof(double))] Tq_drag, // [Nm] Motoring torque [ModalResultField(typeof(double), "Pa")] PaEng, // [kW] Rotational acceleration power: Engine.
[ModalResultFieldAttr(typeof(double))] Pe_eng, // [kW] Engine power. [ModalResultField(typeof(double))] Paux, // [kW] Total auxiliary power demand .
[ModalResultFieldAttr(typeof(double))] Pe_full, // [kW] Engine full load power. [ModalResultField(typeof(double))] FC, // [g/h] Fuel consumption from FC map..
[ModalResultFieldAttr(typeof(double))] Pe_drag, // [kW] Engine drag power. [ModalResultField(typeof(double), "FC-AUXc")] FCAUXc, // [g/h] Fuel consumption after Auxiliary-Start/Stop Correction. (Based on FC.)
[ModalResultFieldAttr(typeof(double))] Pe_clutch, // [kW] Engine power at clutch (equals Pe minus loss due to rotational inertia Pa Eng). [ModalResultField(typeof(double), "FC-WHTCc")] FCWHTCc, // [g/h] Fuel consumption after WHTC Correction. (Based on FC-AUXc.)
[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. [ModalResultField(typeof(double))] dist, // [km] Travelled distance.
[ModalResultFieldAttr(typeof(double))] PlossRetarder, // [kW] Retarder losses. [ModalResultField(typeof(double))] v_act, // [km/h] Actual vehicle speed.
[ModalResultFieldAttr(typeof(double))] PaEng, // [kW] Rotational acceleration power: Engine. [ModalResultField(typeof(double))] v_targ, // [km/h] Target vehicle speed.
[ModalResultFieldAttr(typeof(double))] PaGB, // [kW] Rotational acceleration power: Gearbox. [ModalResultField(typeof(double))] acc, // [m/s2] Vehicle acceleration.
[ModalResultFieldAttr(typeof(double))] PaVeh, // [kW] Vehicle acceleration power. [ModalResultField(typeof(double))] grad, // [%] Road gradient.
[ModalResultFieldAttr(typeof(double))] Proll, // [kW] Rolling resistance power demand. [ModalResultField(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))] Pair, // [kW] Air resistance power demand. [ModalResultField(typeof(double), "Ploss GB")] PlossGB, // [kW] Gearbox losses.
[ModalResultFieldAttr(typeof(double))] Pgrad, // [kW] Power demand due to road gradient. [ModalResultField(typeof(double), "Ploss Diff")] PlossDiff, // [kW] Losses in differential / axle transmission.
[ModalResultFieldAttr(typeof(double))] Paux, // [kW] Total auxiliary power demand . [ModalResultField(typeof(double), "Ploss Retarder")] PlossRetarder, // [kW] Retarder losses.
[ModalResultFieldAttr(typeof(double))] Pwheel, // [kW] Total power demand at wheel = sum of rolling, air, acceleration and road gradient resistance. [ModalResultField(typeof(double), "Pa GB")] PaGB, // [kW] Rotational acceleration power: Gearbox.
[ModalResultFieldAttr(typeof(double))] Pbrake, // [kW] Brake power. Drag power is included in Pe. [ModalResultField(typeof(double), "Pa Veh")] PaVeh, // [kW] Vehicle acceleration power.
[ModalResultFieldAttr(typeof(double))] Paux_xxx, // [kW] Power demand of Auxiliary with ID xxx. See also Aux Dialog and Driving Cycle. [ModalResultField(typeof(double))] Proll, // [kW] Rolling resistance power demand.
[ModalResultFieldAttr(typeof(double))] FC, // [g/h] Fuel consumption from FC map.. [ModalResultField(typeof(double))] Pair, // [kW] Air resistance power demand.
[ModalResultFieldAttr(typeof(double))] FC_AUXc, // [g/h] Fuel consumption after Auxiliary-Start/Stop Correction. (Based on FC.) [ModalResultField(typeof(double))] Pgrad, // [kW] Power demand due to road gradient.
[ModalResultFieldAttr(typeof(double))] FC_WHTCc, // [g/h] Fuel consumption after WHTC Correction. (Based on FC-AUXc.) [ModalResultField(typeof(double))] Pwheel, // [kW] Total power demand at wheel = sum of rolling, air, acceleration and road gradient resistance.
[ModalResultFieldAttr(typeof(double))] TCν, // [-] Torque converter speed ratio [ModalResultField(typeof(double))] Pbrake, // [kW] Brake power. Drag power is included in Pe.
[ModalResultFieldAttr(typeof(double))] TCmu, // [-] Torque converter torque ratio //[ModalResultField(typeof(double))] Paux_xxx, // [kW] Power demand of Auxiliary with ID xxx. See also Aux Dialog and Driving Cycle.
[ModalResultFieldAttr(typeof(double))] TC_M_Out, // [Nm] Torque converter output torque [ModalResultField(typeof(double))] TCν, // [-] Torque converter speed ratio
[ModalResultFieldAttr(typeof(double))] TC_n_Out, // [1/min] Torque converter output speed [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 Type FieldType { get; private set; }
public string Name { get; private set; }
} }
public static class ModalResultFieldExtensions public static class ModalResultFieldExtensions
{ {
public static Type GetDataType(this ModalResult field) public static Type GetDataType(this ModalResultField field)
{ {
return GetAttr(field).FieldType; 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));
} }
} }
} }
...@@ -9,7 +9,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent ...@@ -9,7 +9,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent
/// </summary> /// </summary>
/// <param name="key"></param> /// <param name="key"></param>
/// <returns></returns> /// <returns></returns>
object this[ModalResult key] { get; set; } object this[ModalResultField key] { get; set; }
/// <summary> /// <summary>
/// Commits the data of the current simulation step. /// Commits the data of the current simulation step.
......
...@@ -19,9 +19,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -19,9 +19,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public override void CommitSimulationStep(IModalDataWriter writer) public override void CommitSimulationStep(IModalDataWriter writer)
{ {
writer[ModalResult.FC] = 1; writer[ModalResultField.FC] = 1;
writer[ModalResult.FC_AUXc] = 2; writer[ModalResultField.FCAUXc] = 2;
writer[ModalResult.FC_WHTCc] = 3; writer[ModalResultField.FCWHTCc] = 3;
} }
public void Request(TimeSpan absTime, TimeSpan dt, double torque, double engineSpeed) public void Request(TimeSpan absTime, TimeSpan dt, double torque, double engineSpeed)
......
...@@ -69,9 +69,7 @@ ...@@ -69,9 +69,7 @@
<Compile Include="Models\Connector\Ports\IOutShaft.cs" /> <Compile Include="Models\Connector\Ports\IOutShaft.cs" />
<Compile Include="Models\Connector\Ports\ITnPort.cs" /> <Compile Include="Models\Connector\Ports\ITnPort.cs" />
<Compile Include="Models\SimulationComponent\Data\EngineOnlyDrivingCycle.cs" /> <Compile Include="Models\SimulationComponent\Data\EngineOnlyDrivingCycle.cs" />
<Compile Include="Models\SimulationComponent\Data\ModalResult.cs"> <Compile Include="Models\SimulationComponent\Data\ModalResult.cs" />
<SubType>Component</SubType>
</Compile>
<Compile Include="Models\SimulationComponent\Data\CombustionEngineData.cs" /> <Compile Include="Models\SimulationComponent\Data\CombustionEngineData.cs" />
<Compile Include="Models\SimulationComponent\Data\Engine\FuelConsumptionMap.cs" /> <Compile Include="Models\SimulationComponent\Data\Engine\FuelConsumptionMap.cs" />
<Compile Include="Models\SimulationComponent\Data\Engine\FullLoadCurve.cs" /> <Compile Include="Models\SimulationComponent\Data\Engine\FullLoadCurve.cs" />
......
using System; using System;
using System.Data;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using TUGraz.VectoCore.Models.Connector.Ports;
using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.Models.SimulationComponent.Impl; using TUGraz.VectoCore.Models.SimulationComponent.Impl;
using TUGraz.VectoCore.Tests.Utils; using TUGraz.VectoCore.Tests.Utils;
...@@ -69,9 +67,9 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent ...@@ -69,9 +67,9 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent
engine.CommitSimulationStep(dataWriter); engine.CommitSimulationStep(dataWriter);
//todo: test with correct output values, add other fields to test //todo: test with correct output values, add other fields to test
Assert.AreEqual(dataWriter[ModalResult.FC], 13000); Assert.AreEqual(dataWriter[ModalResultField.FC], 13000);
Assert.AreEqual(dataWriter[ModalResult.FC_AUXc], 14000); Assert.AreEqual(dataWriter[ModalResultField.FCAUXc], 14000);
Assert.AreEqual(dataWriter[ModalResult.FC_WHTCc], 15000); Assert.AreEqual(dataWriter[ModalResultField.FCWHTCc], 15000);
} }
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\TestData\\EngineTests.csv", "EngineTests#csv", DataAccessMethod.Sequential)] [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\TestData\\EngineTests.csv", "EngineTests#csv", DataAccessMethod.Sequential)]
...@@ -98,15 +96,15 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent ...@@ -98,15 +96,15 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent
absTime += dt; absTime += dt;
//todo: test with correct output values, add other fields to test //todo: test with correct output values, add other fields to test
Assert.AreEqual(dataWriter[ModalResult.FC], 13000); Assert.AreEqual(dataWriter[ModalResultField.FC], 13000);
Assert.AreEqual(dataWriter[ModalResult.FC_AUXc], 14000); Assert.AreEqual(dataWriter[ModalResultField.FCAUXc], 14000);
Assert.AreEqual(dataWriter[ModalResult.FC_WHTCc], 15000); Assert.AreEqual(dataWriter[ModalResultField.FCWHTCc], 15000);
} }
//todo: test with correct output values, add other fields to test //todo: test with correct output values, add other fields to test
Assert.AreEqual(dataWriter[ModalResult.FC], 13000); Assert.AreEqual(dataWriter[ModalResultField.FC], 13000);
Assert.AreEqual(dataWriter[ModalResult.FC_AUXc], 14000); Assert.AreEqual(dataWriter[ModalResultField.FCAUXc], 14000);
Assert.AreEqual(dataWriter[ModalResult.FC_WHTCc], 15000); Assert.AreEqual(dataWriter[ModalResultField.FCWHTCc], 15000);
} }
......
...@@ -25,7 +25,7 @@ namespace TUGraz.VectoCore.Tests.Utils ...@@ -25,7 +25,7 @@ namespace TUGraz.VectoCore.Tests.Utils
CurrentRow = Data.NewRow(); CurrentRow = Data.NewRow();
} }
public object this[ModalResult key] public object this[ModalResultField key]
{ {
get { return CurrentRow[key.ToString()]; } get { return CurrentRow[key.ToString()]; }
set { CurrentRow[key.ToString()] = value; } set { CurrentRow[key.ToString()] = value; }
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <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> </configuration>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment