Select Git revision
ModalResult.cs
Forked from
VECTO / VECTO Sim
10544 commits behind the upstream repository.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
ModalResult.cs 12.37 KiB
/*
* This file is part of VECTO.
*
* Copyright © 2012-2016 European Union
*
* Developed by Graz University of Technology,
* Institute of Internal Combustion Engines and Thermodynamics,
* Institute of Technical Informatics
*
* VECTO is licensed under the EUPL, Version 1.1 or - as soon they will be approved
* by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use VECTO except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* https://joinup.ec.europa.eu/community/eupl/og_page/eupl
*
* Unless required by applicable law or agreed to in writing, VECTO
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*
* Authors:
* Stefan Hausberger, hausberger@ivt.tugraz.at, IVT, Graz University of Technology
* Christian Kreiner, christian.kreiner@tugraz.at, ITI, Graz University of Technology
* Michael Krisper, michael.krisper@tugraz.at, ITI, Graz University of Technology
* Raphael Luz, luz@ivt.tugraz.at, IVT, Graz University of Technology
* Markus Quaritsch, markus.quaritsch@tugraz.at, IVT, Graz University of Technology
* Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology
*/
using System;
using System.ComponentModel;
using System.Data;
using System.Reflection;
using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Utils;
// ReSharper disable InconsistentNaming
namespace TUGraz.VectoCore.Models.Simulation.Data
{
[DesignerCategory("")] // Full qualified attribute needed to disable design view in VisualStudio
public class ModalResults : DataTable
{
public static class ExtendedPropertyNames
{
public const string Decimals = "decimals";
public const string OutputFactor = "outputFactor";
public const string ShowUnit = "showUnit";
}
public ModalResults()
{
foreach (var value in EnumHelper.GetValues<ModalResultField>()) {
var col = new DataColumn(value.GetName(), value.GetAttribute().DataType) { Caption = value.GetCaption() };
col.ExtendedProperties[ExtendedPropertyNames.Decimals] = value.GetAttribute().Decimals;
col.ExtendedProperties[ExtendedPropertyNames.OutputFactor] = value.GetAttribute().OutputFactor;
col.ExtendedProperties[ExtendedPropertyNames.ShowUnit] = value.GetAttribute().ShowUnit;
Columns.Add(col);
}
}
public static ModalResults ReadFromFile(string fileName)
{
var modalResults = new ModalResults();
var data = VectoCSVFile.Read(fileName);
foreach (DataRow row in data.Rows) {
try {
var newRow = modalResults.NewRow();
foreach (DataColumn col in row.Table.Columns) {
// In cols FC-AUXc and FC-WHTCc can be a "-"
if (row.Field<string>(col) == "-"
&& (col.ColumnName == ModalResultField.FCAUXc.GetName() || col.ColumnName == ModalResultField.FCWHTCc.GetName())) {
continue;
}
// In col FC can sometimes be a "ERROR"
if (row.Field<string>(col) == "ERROR" && col.ColumnName == ModalResultField.FCMap.GetName()) {
continue;
}
if (col.ColumnName.StartsWith(ModalResultField.P_aux_.ToString()) &&
!modalResults.Columns.Contains(col.ColumnName)) {
modalResults.Columns.Add(col.ColumnName, typeof(SI));
}
if (typeof(SI).IsAssignableFrom(modalResults.Columns[col.ColumnName].DataType)) {
newRow.SetField(col.ColumnName, row.ParseDoubleOrGetDefault(col.ColumnName).SI());
} else {
newRow.SetField(col.ColumnName, row.ParseDoubleOrGetDefault(col.ColumnName));
}
}
modalResults.Rows.Add(newRow);
} catch (VectoException ex) {
throw new VectoException(string.Format("Row {0}: {1}", data.Rows.IndexOf(row), ex.Message), ex);
}
}
return modalResults;
}
public void WriteToFile(string fileName)
{
VectoCSVFile.Write(fileName, this);
}
}
/// <summary>
/// Enum with field definitions of the Modal Results File (.vmod).
/// </summary>
public enum ModalResultField
{
/// <summary>
/// Time step [s].
/// Midpoint of the simulated interval.
/// </summary>
[ModalResultField(typeof(SI), caption: "time [s]")] time,
/// <summary>
/// Simulation interval around the current time step. [s]
/// </summary>
[ModalResultField(typeof(SI), "simulation_interval", "dt [s]")] simulationInterval,
/// <summary>
/// Engine speed [1/min].
/// </summary>
[ModalResultField(typeof(SI), caption: "n_eng_avg [1/min]", outputFactor: 60 / (2 * Math.PI))] n_eng_avg,
/// <summary>
/// [Nm] Engine torque.
/// </summary>
[ModalResultField(typeof(SI), caption: "T_eng_fcmap [Nm]")] T_eng_fcmap,
/// <summary>
/// [Nm] Full load torque
/// </summary>
[ModalResultField(typeof(SI), caption: "Tq_full [Nm]")] Tq_full,
/// <summary>
/// [Nm] Motoring torque
/// </summary>
[ModalResultField(typeof(SI), caption: "Tq_drag [Nm]")] Tq_drag,
/// <summary>
/// [kW] Engine power.
/// </summary>
[ModalResultField(typeof(SI), caption: "P_eng_out [kW]", outputFactor: 1e-3)] P_eng_out,
/// <summary>
/// [kW] Engine full load power.
/// </summary>
[ModalResultField(typeof(SI), caption: "P_eng_full [kW]", outputFactor: 1e-3)] P_eng_full,
/// <summary>
/// [kW] Engine drag power.
/// </summary>
[ModalResultField(typeof(SI), caption: "P_eng_drag [kW]", outputFactor: 1e-3)] P_eng_drag,
/// <summary>
/// [kW] Engine power at clutch (equals Pe minus loss due to rotational inertia Pa Eng).
/// </summary>
[ModalResultField(typeof(SI), caption: "P_clutch_out [kW]", outputFactor: 1e-3)] P_clutch_out,
/// <summary>
/// [kW] Rotational acceleration power: Engine.
/// </summary>
[ModalResultField(typeof(SI), name: "P_eng_inertia", caption: "P_eng_inertia [kW]", outputFactor: 1e-3)] P_eng_inertia,
/// <summary>
/// [kW] Total auxiliary power demand .
/// </summary>
[ModalResultField(typeof(SI), caption: "P_aux [kW]", outputFactor: 1e-3)] P_aux,
/// <summary>
/// [g/h] Fuel consumption from FC map..
/// </summary>
[ModalResultField(typeof(SI), name: "FC-Map", caption: "FC-Map [g/h]", outputFactor: 3600 * 1000)] FCMap,
/// <summary>
/// [g/h] Fuel consumption after Auxiliary-Start/Stop Correction. (Based on FC.)
/// </summary>
[ModalResultField(typeof(SI), name: "FC-AUXc", caption: "FC-AUXc [g/h]", outputFactor: 3600 * 1000)] FCAUXc,
/// <summary>
/// [g/h] Fuel consumption after WHTC Correction. (Based on FC-AUXc.)
/// </summary>
[ModalResultField(typeof(SI), name: "FC-WHTCc", caption: "FC-WHTCc [g/h]", outputFactor: 3600 * 1000)] FCWHTCc,
/// <summary>
/// [km] Travelled distance.
/// </summary>
[ModalResultField(typeof(SI), caption: "dist [m]")] dist,
/// <summary>
/// [km/h] Actual vehicle speed.
/// </summary>
[ModalResultField(typeof(SI), caption: "v_act [km/h]", outputFactor: 3.6)] v_act,
/// <summary>
/// [km/h] Target vehicle speed.
/// </summary>
[ModalResultField(typeof(SI), caption: "v_targ [km/h]", outputFactor: 3.6)] v_targ,
/// <summary>
/// [m/s2] Vehicle acceleration.
/// </summary>
[ModalResultField(typeof(SI), caption: "acc [m/s^2]")] acc,
/// <summary>
/// [%] Road gradient.
/// </summary>
[ModalResultField(typeof(SI), caption: "grad [%]")] grad,
/// <summary>
/// [-] GearData. "0" = clutch opened / neutral. "0.5" = lock-up clutch is open (AT with torque converter only, see
/// Gearbox)
/// </summary>
[ModalResultField(typeof(uint), caption: "Gear [-]")] Gear,
/// <summary>
/// [kW] Gearbox losses.
/// </summary>
[ModalResultField(typeof(SI), name: "Ploss GB", caption: "P_gbx_loss GB [kW]", outputFactor: 1e-3)] P_gbx_loss,
/// <summary>
/// [kW] Losses in differential / axle transmission.
/// </summary>
[ModalResultField(typeof(SI), name: "Ploss Diff", caption: "P_axle_loss [kW]", outputFactor: 1e-3)] P_axle_loss,
/// <summary>
/// [kW] Retarder losses.
/// </summary>
[ModalResultField(typeof(SI), name: "Ploss Retarder", caption: "Ploss Retarder [kW]", outputFactor: 1e-3)] P_ret_loss,
/// <summary>
/// [kW] Rotational acceleration power: Gearbox.
/// </summary>
[ModalResultField(typeof(SI), name: "Pa GB", caption: "Pa GB [kW]", outputFactor: 1e-3)] P_gbx_inertia,
/// <summary>
/// [kW] Vehicle acceleration power.
/// </summary>
[ModalResultField(typeof(SI), name: "Pa Veh", caption: "Pa Veh [kW]", outputFactor: 1e-3)] P_veh_inertia,
/// <summary>
/// [kW] Rolling resistance power demand.
/// </summary>
[ModalResultField(typeof(SI), caption: "P_roll [kW]", outputFactor: 1e-3)] P_roll,
/// <summary>
/// [kW] Air resistance power demand.
/// </summary>
[ModalResultField(typeof(SI), caption: "P_air [kW]", outputFactor: 1e-3)] P_air,
/// <summary>
/// [kW] Power demand due to road gradient.
/// </summary>
[ModalResultField(typeof(SI), caption: "P_slope [kW]", outputFactor: 1e-3)] P_slope,
/// <summary>
/// [kW] Total power demand at wheel = sum of rolling, air, acceleration and road gradient resistance.
/// </summary>
[ModalResultField(typeof(SI), caption: "P_wheel_in [kW]", outputFactor: 1e-3)] P_wheel_in,
/// <summary>
/// [kW] Brake power. Drag power is included in Pe.
/// </summary>
[ModalResultField(typeof(SI), caption: "P_brake_loss [kW]", outputFactor: 1e-3)] P_brake_loss,
[ModalResultField(typeof(SI), caption: "P_wheel_inertia [kW]", outputFactor: 1e-3)] P_wheel_inertia,
[ModalResultField(typeof(SI), caption: "P_brake_in [kW]", outputFactor: 1e-3)] P_brake_in,
[ModalResultField(typeof(SI), caption: "P_axle_in [kW]", outputFactor: 1e-3)] P_axle_in,
[ModalResultField(typeof(SI), caption: "P_ret_in [kW]", outputFactor: 1e-3)] P_retarder_in,
[ModalResultField(typeof(SI), caption: "P_gbx_in [kW]", outputFactor: 1e-3)] P_gbx_in,
[ModalResultField(typeof(SI), caption: "P_clutch_loss [kW]", outputFactor: 1e-3)] P_clutch_loss,
[ModalResultField(typeof(SI), caption: "P_trac [kW]", outputFactor: 1e-3)] P_trac,
[ModalResultField(typeof(SI), caption: "P_eng_fcmap [kW]", outputFactor: 1e-3)] P_eng_fcmap,
/// <summary>
/// [kW] Power demand of Auxiliary with ID xxx. See also Aux Dialog and Driving Cycle.
/// </summary>
[ModalResultField(typeof(SI), outputFactor: 1e-3)] P_aux_,
/// <summary>
/// [-] Torque converter speed ratio
/// </summary>
[ModalResultField(typeof(SI), name: "TCnu")] TCv,
/// <summary>
/// [-] Torque converter torque ratio
/// </summary>
[ModalResultField(typeof(SI), name: "TCmu")] TCmu,
/// <summary>
/// [Nm] Torque converter output torque
/// </summary>
[ModalResultField(typeof(SI))] TC_M_Out,
/// <summary>
/// [1/min] Torque converter output speed
/// </summary>
[ModalResultField(typeof(SI))] TC_n_Out,
/// <summary>
/// [m] Altitude
/// </summary>
[ModalResultField(typeof(SI))] altitude,
[ModalResultField(typeof(SI), name: "ds [m]")] simulationDistance
}
[AttributeUsage(AttributeTargets.Field)]
public class ModalResultFieldAttribute : Attribute
{
internal ModalResultFieldAttribute(Type dataType, string name = null, string caption = null, uint decimals = 4,
double outputFactor = 1, bool showUnit = false)
{
DataType = dataType;
Name = name;
Caption = caption;
Decimals = decimals;
OutputFactor = outputFactor;
ShowUnit = showUnit;
}
public bool ShowUnit { get; private set; }
public double OutputFactor { get; private set; }
public uint Decimals { get; private set; }
public Type DataType { get; private set; }
public string Name { get; private set; }
public string Caption { get; private set; }
}
public static class ModalResultFieldExtensionMethods
{
public static string GetName(this ModalResultField field)
{
return GetAttribute(field).Name ?? field.ToString();
}
public static string GetCaption(this ModalResultField field)
{
return GetAttribute(field).Caption ?? GetAttribute(field).Name ?? field.ToString();
}
public static ModalResultFieldAttribute GetAttribute(this ModalResultField field)
{
return (ModalResultFieldAttribute)Attribute.GetCustomAttribute(ForValue(field), typeof(ModalResultFieldAttribute));
}
private static MemberInfo ForValue(ModalResultField field)
{
return typeof(ModalResultField).GetField(Enum.GetName(typeof(ModalResultField), field));
}
}
}