Code development platform for open source projects from the European Union institutions

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

Merge pull request #64 in VECTO/vecto-sim from...

Merge pull request #64 in VECTO/vecto-sim from ~EMKRISPMI/vecto-sim:feature/VECTO-102-auxiliaries-identification to develop

* commit 'de5adb01':
  compileable again
  auxiliary tests, adjusted electrical system (included mapping for alternator efficiency)
  additional auxiliary tests (file missing, column missing, wrong configurations)
  added files overview
parents 27d81d19 de5adb01
No related branches found
No related tags found
No related merge requests found
Showing
with 260 additions and 336 deletions
Technology ,Long haul,Regional delivery,Urban delivery,Municipal utility,Construction,Heavy Urban,Urban,Suburban,Interurban,Coach
Standard alternator,0.7 ,0.7 ,0.7 ,0.7 ,0.7 ,1 ,1 ,1 ,1 ,1
\ No newline at end of file
......@@ -212,7 +212,7 @@ namespace TUGraz.VectoCore.FileIO.Reader.DataObjectAdaper
foreach (var auxData in auxList) {
var aux = new VectoRunData.AuxData { DemandType = AuxiliaryDemandType.Constant };
switch (aux.Type) {
switch (auxData.Type) {
case AuxiliaryType.Fan:
aux.PowerDemand = DeclarationData.Fan.Lookup(mission, auxData.Technology);
aux.ID = Constants.Auxiliaries.IDs.Fan;
......
......@@ -33,6 +33,7 @@ namespace TUGraz.VectoCore.FileIO.Reader.Impl
var driverdata = dao.CreateDriverData(Job);
driverdata.AccelerationCurve = AccelerationCurveData.ReadFromStream(segment.AccelerationFile);
foreach (var mission in segment.Missions) {
var cycle = DrivingCycleDataReader.ReadFromStream(mission.CycleFile, DrivingCycleData.CycleType.DistanceBased);
foreach (var loading in mission.Loadings) {
var engineData = dao.CreateEngineData(Engine);
......@@ -41,10 +42,11 @@ namespace TUGraz.VectoCore.FileIO.Reader.Impl
EngineData = engineData,
GearboxData = dao.CreateGearboxData(Gearbox, engineData),
Aux = dao.CreateAuxiliaryData(Aux, mission.MissionType, segment.VehicleClass),
Cycle = DrivingCycleDataReader.ReadFromStream(mission.CycleFile, DrivingCycleData.CycleType.DistanceBased),
Cycle = cycle,
DriverData = driverdata,
IsEngineOnly = IsEngineOnly,
JobFileName = Job.JobFile
JobFileName = Job.JobFile,
BasePath = ""
};
simulationRunData.VehicleData.VehicleClass = segment.VehicleClass;
yield return simulationRunData;
......
......@@ -9,6 +9,7 @@ using TUGraz.VectoCore.FileIO.EngineeringFile;
using TUGraz.VectoCore.FileIO.Reader.DataObjectAdaper;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.Models.SimulationComponent.Impl;
using TUGraz.VectoCore.Utils;
[assembly: InternalsVisibleTo("VectoCoreTest")]
......@@ -57,7 +58,8 @@ namespace TUGraz.VectoCore.FileIO.Reader.Impl
ID = a.ID,
Technology = a.Technology,
TechList = a.TechList.DefaultIfNull(Enumerable.Empty<string>()).ToArray(),
DemandType = AuxiliaryDemandType.Mapping
DemandType = AuxiliaryDemandType.Mapping,
Data = AuxiliaryData.ReadFromFile(Path.Combine(Job.BasePath, a.Path))
});
// add a direct auxiliary
......
......@@ -7,6 +7,8 @@ namespace TUGraz.VectoCore.Models.Declaration
{
public class ElectricSystem : LookupData<MissionType, string[], Watt>
{
private readonly Alternator _alternator = new Alternator();
private const string BaseLine = "Baseline electric power consumption";
private readonly Dictionary<Tuple<MissionType, string>, Watt> _data =
......@@ -26,7 +28,7 @@ namespace TUGraz.VectoCore.Models.Declaration
foreach (DataRow row in table.Rows) {
var name = row.Field<string>("Technology");
foreach (MissionType mission in Enum.GetValues(typeof (MissionType))) {
foreach (MissionType mission in Enum.GetValues(typeof(MissionType))) {
_data[Tuple.Create(mission, name)] = row.ParseDouble(mission.ToString().ToLower()).SI<Watt>();
}
}
......@@ -36,15 +38,54 @@ namespace TUGraz.VectoCore.Models.Declaration
{
var sum = _data[Tuple.Create(missionType, BaseLine)];
foreach (var s in technologies) {
Watt w;
if (_data.TryGetValue(Tuple.Create(missionType, s), out w)) {
sum += w;
} else {
Log.Error(string.Format("electric system technology not found: {0}", s));
if (technologies != null) {
foreach (var s in technologies) {
Watt w;
if (_data.TryGetValue(Tuple.Create(missionType, s), out w)) {
sum += w;
} else {
Log.Error(string.Format("electric system technology not found: {0}", s));
}
}
}
return sum;
return sum / _alternator.Lookup(missionType, null);
}
private class Alternator : LookupData<MissionType, string, double>
{
private const string Default = "Standard alternator";
private readonly Dictionary<Tuple<MissionType, string>, double> _data =
new Dictionary<Tuple<MissionType, string>, double>();
protected string ResourceId = "TUGraz.VectoCore.Resources.Declaration.VAUX.ALT-Tech.csv";
public Alternator()
{
ParseData(ReadCsvResource(ResourceId));
}
protected override void ParseData(DataTable table)
{
NormalizeTable(table);
foreach (DataRow row in table.Rows) {
var name = row.Field<string>("Technology");
foreach (MissionType mission in Enum.GetValues(typeof(MissionType))) {
_data[Tuple.Create(mission, name)] = row.ParseDouble(mission.ToString().ToLower());
}
}
}
public override double Lookup(MissionType missionType, string technology)
{
if (string.IsNullOrWhiteSpace(technology)) {
technology = Default;
}
return _data[Tuple.Create(missionType, technology)];
}
}
}
}
\ No newline at end of file
......@@ -35,7 +35,7 @@ namespace TUGraz.VectoCore.Models.Declaration
public override Watt Lookup(MissionType mission, string technology)
{
if (string.IsNullOrWhiteSpace(technology.Trim())) {
if (string.IsNullOrWhiteSpace(technology)) {
technology = DefaultTechnology;
}
return _data[Tuple.Create(mission, technology)];
......
using System.Collections.Generic;
using System.Data;
using System.Linq;
using TUGraz.VectoCore.Models.Simulation.Impl;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.Simulation.Data
{
public class ModalDataWriter : IModalDataWriter
{
private readonly bool _engineOnly;
private readonly SimulatorFactory.FactoryMode _mode;
private ModalResults Data { get; set; }
private DataRow CurrentRow { get; set; }
private string ModFileName { get; set; }
public ModalDataWriter(string modFileName, bool engineOnly)
public ModalDataWriter(string modFileName, SimulatorFactory.FactoryMode mode)
{
HasTorqueConverter = false;
ModFileName = modFileName;
Data = new ModalResults();
Auxiliaries = new Dictionary<string, DataColumn>();
CurrentRow = Data.NewRow();
_engineOnly = engineOnly;
_mode = mode;
}
public bool HasTorqueConverter { get; set; }
......@@ -35,7 +36,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
{
var dataColumns = new List<ModalResultField> { ModalResultField.time };
if (!_engineOnly) {
if (_mode != SimulatorFactory.FactoryMode.EngineOnlyMode) {
dataColumns.AddRange(new[] {
ModalResultField.simulationInterval,
ModalResultField.dist,
......@@ -60,7 +61,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
ModalResultField.Paux
});
if (!_engineOnly) {
if (_mode != SimulatorFactory.FactoryMode.EngineOnlyMode) {
dataColumns.AddRange(new[] {
ModalResultField.Gear,
ModalResultField.PlossGB,
......@@ -89,7 +90,9 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
.Concat((Auxiliaries.Values.Select(c => c.ColumnName)))
.Concat(new[] { ModalResultField.FCMap, ModalResultField.FCAUXc, ModalResultField.FCWHTCc }.Select(x => x.GetName()));
VectoCSVFile.Write(ModFileName, new DataView(Data).ToTable(false, strCols.ToArray()));
if (_mode != SimulatorFactory.FactoryMode.DeclarationMode) {
VectoCSVFile.Write(ModFileName, new DataView(Data).ToTable(false, strCols.ToArray()));
}
}
......@@ -120,13 +123,19 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
public void AddAuxiliary(string id)
{
var col = Data.Columns.Add(ModalResultField.Paux_ + id, typeof(SI));
col.ExtendedProperties[ModalResults.ExtendedPropertyNames.Decimals] = ModalResultField.Paux_.GetAttribute().Decimals;
col.ExtendedProperties[ModalResults.ExtendedPropertyNames.OutputFactor] =
ModalResultField.Paux_.GetAttribute().OutputFactor;
col.ExtendedProperties[ModalResults.ExtendedPropertyNames.ShowUnit] = ModalResultField.Paux_.GetAttribute().ShowUnit;
Auxiliaries[id] = col;
if (!string.IsNullOrWhiteSpace(id)) {
if (!Auxiliaries.ContainsKey(id)) {
var col = Data.Columns.Add(ModalResultField.Paux_ + id, typeof(SI));
col.ExtendedProperties[ModalResults.ExtendedPropertyNames.Decimals] =
ModalResultField.Paux_.GetAttribute().Decimals;
col.ExtendedProperties[ModalResults.ExtendedPropertyNames.OutputFactor] =
ModalResultField.Paux_.GetAttribute().OutputFactor;
col.ExtendedProperties[ModalResults.ExtendedPropertyNames.ShowUnit] =
ModalResultField.Paux_.GetAttribute().ShowUnit;
Auxiliaries[id] = col;
}
}
}
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Utils;
......@@ -108,14 +109,15 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
private void WriteAuxiliaries(IModalDataWriter data, DataRow row)
{
_auxColumns = _auxColumns.Union(data.Auxiliaries.Select(kv => "Eaux_" + kv.Key + " [kwh]")).ToList();
_auxColumns = _auxColumns.Union(data.Auxiliaries.Select(kv => "Eaux_" + kv.Key + " [kWh]")).ToList();
var sum = 0.SI<Watt>();
foreach (var aux in data.Auxiliaries) {
var colName = "Eaux_" + aux.Key + " [kWh]";
if (!_table.Columns.Contains(colName)) {
try {
_table.Columns.Add(colName, typeof(SI));
}
} catch (DuplicateNameException) {}
var currentSum = data.Sum(aux.Value);
row[colName] = currentSum;
......
......@@ -45,7 +45,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
public string[] TechList;
public Watt PowerDemand;
public AuxiliaryDemandType DemandType;
public MappingAuxiliaryData Data;
public AuxiliaryData Data;
}
public class StartStopData
......
......@@ -91,9 +91,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
return _container;
}
protected
IGearbox GetGearbox
(VehicleContainer container, GearboxData data)
protected IGearbox GetGearbox(VehicleContainer container, GearboxData data)
{
switch (data.Type) {
case GearboxData.GearboxType.AT:
......@@ -105,59 +103,44 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
}
}
protected virtual
IDriver AddComponent
(IDrivingCycle prev, IDriver next)
protected virtual IDriver AddComponent(IDrivingCycle prev, IDriver next)
{
prev.InPort().Connect(next.OutPort());
return next;
}
protected virtual
IVehicle AddComponent
(IDriver prev, IVehicle next)
protected virtual IVehicle AddComponent(IDriver prev, IVehicle next)
{
prev.InPort().Connect(next.OutPort());
return next;
}
protected virtual
IWheels AddComponent
(IFvInProvider prev, IWheels next)
protected virtual IWheels AddComponent(IFvInProvider prev, IWheels next)
{
prev.InPort().Connect(next.OutPort());
return next;
}
protected virtual
IPowerTrainComponent AddComponent
(IWheels prev, IPowerTrainComponent next)
protected virtual IPowerTrainComponent AddComponent(IWheels prev, IPowerTrainComponent next)
{
prev.InPort().Connect(next.OutPort());
return next;
}
protected virtual
IPowerTrainComponent AddComponent
(IPowerTrainComponent prev, IPowerTrainComponent next)
protected virtual IPowerTrainComponent AddComponent(IPowerTrainComponent prev, IPowerTrainComponent next)
{
prev.InPort().Connect(next.OutPort());
return next;
}
protected virtual
void AddComponent
(IPowerTrainComponent prev, ITnOutProvider next)
protected virtual void AddComponent(IPowerTrainComponent prev, ITnOutProvider next)
{
prev.InPort().Connect(next.OutPort());
}
private
VehicleContainer BuildEngineOnly
(VectoRunData
data)
private VehicleContainer BuildEngineOnly(VectoRunData data)
{
var cycle = new EngineOnlySimulation(_container, data.Cycle);
......
......@@ -65,14 +65,10 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
{
var i = 0;
foreach (var data in DataReader.NextRun()) {
IModalDataWriter modWriter = null;
if (_mode != FactoryMode.DeclarationMode) {
var modFileName = Path.Combine(data.BasePath,
data.JobFileName.Replace(Constants.FileExtensions.VectoJobFile, "") + "_{0}" +
Constants.FileExtensions.ModDataFile);
modWriter = new ModalDataWriter(string.Format(modFileName, data.Cycle.Name), DataReader.IsEngineOnly);
}
var modFileName = Path.Combine(data.BasePath,
data.JobFileName.Replace(Constants.FileExtensions.VectoJobFile, "") + "_{0}" +
Constants.FileExtensions.ModDataFile);
IModalDataWriter modWriter = new ModalDataWriter(string.Format(modFileName, data.Cycle.Name), _mode);
var jobName = string.Format("{0}-{1}", JobNumber, i++);
var sumWriterDecorator = DecorateSumWriter(data.IsEngineOnly, SumWriter, data.JobFileName, jobName, data.Cycle.Name);
var builder = new PowertrainBuilder(modWriter, sumWriterDecorator, DataReader.IsEngineOnly);
......
......@@ -107,7 +107,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
_auxDict[DirectAuxiliaryId] = speed => cycle.CycleData().LeftSample.AdditionalAuxPowerDemand;
}
public void AddMapping(string auxId, IDrivingCycleInfo cycle, MappingAuxiliaryData data)
public void AddMapping(string auxId, IDrivingCycleInfo cycle, AuxiliaryData data)
{
if (!cycle.CycleData().LeftSample.AuxiliarySupplyPower.ContainsKey("Aux_" + auxId)) {
var error = string.Format("driving cycle does not contain column for auxiliary: {0}", auxId);
......
using System;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{
public class AuxiliaryData
{
public double EfficiencyToSupply { get; set; }
public double TransitionRatio { get; set; }
public double EfficiencyToEngine { get; set; }
private readonly DelauneyMap _map = new DelauneyMap();
public Watt GetPowerDemand(PerSecond nAuxiliary, Watt powerAuxOut)
{
return _map.Interpolate(nAuxiliary.Value(), powerAuxOut.Value()).SI<Watt>();
}
public static AuxiliaryData ReadFromFile(string fileName)
{
var auxData = new AuxiliaryData();
try {
var stream = new StreamReader(fileName);
stream.ReadLine(); // skip header "Transmission ration to engine rpm [-]"
auxData.TransitionRatio = stream.ReadLine().ToDouble();
stream.ReadLine(); // skip header "Efficiency to engine [-]"
auxData.EfficiencyToEngine = stream.ReadLine().ToDouble();
stream.ReadLine(); // skip header "Efficiency auxiliary to supply [-]"
auxData.EfficiencyToSupply = stream.ReadLine().ToDouble();
var m = new MemoryStream(Encoding.UTF8.GetBytes(stream.ReadToEnd()));
var table = VectoCSVFile.ReadStream(m);
var data = table.Rows.Cast<DataRow>().Select(row => new {
AuxiliarySpeed = row.ParseDouble("Auxiliary speed").RPMtoRad(),
MechanicalPower = row.ParseDouble("Mechanical power").SI().Kilo.Watt.Cast<Watt>(),
SupplyPower = row.ParseDouble("Supply power").SI().Kilo.Watt.Cast<Watt>()
});
foreach (var d in data) {
auxData._map.AddPoint(d.AuxiliarySpeed.Value(), d.SupplyPower.Value(), d.MechanicalPower.Value());
}
auxData._map.Triangulate();
return auxData;
} catch (FileNotFoundException e) {
throw new VectoException("Auxiliary file not found: " + fileName, e);
}
}
}
}
\ No newline at end of file
using System;
using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Models.Connector.Ports;
using TUGraz.VectoCore.Models.Simulation;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{
public class DirectAuxiliary : VectoSimulationComponent, IAuxiliary, ITnInPort, ITnOutPort
{
private readonly IAuxiliaryCycleData _demand;
private ITnOutPort _outPort;
private Watt _powerDemand;
public DirectAuxiliary(IVehicleContainer container, IAuxiliaryCycleData demand)
: base(container)
{
_demand = demand;
}
#region ITnInProvider
public ITnInPort InPort()
{
return this;
}
#endregion
#region ITnOutProvider
public ITnOutPort OutPort()
{
return this;
}
#endregion
#region ITnInPort
void ITnInPort.Connect(ITnOutPort other)
{
_outPort = other;
}
#endregion
#region ITnOutPort
IResponse ITnOutPort.Request(Second absTime, Second dt, NewtonMeter torque, PerSecond engineSpeed, bool dryRun)
{
if (_outPort == null) {
Log.ErrorFormat("{0} cannot handle incoming request - no outport available", absTime);
throw new VectoSimulationException(
string.Format("{0} cannot handle incoming request - no outport available",
absTime));
}
_powerDemand = _demand.GetPowerDemand(absTime, dt);
var tq = Formulas.PowerToTorque(_powerDemand, engineSpeed);
return _outPort.Request(absTime, dt, torque + tq, engineSpeed, dryRun);
}
public IResponse Initialize(NewtonMeter torque, PerSecond engineSpeed)
{
_powerDemand = _demand.GetPowerDemand(0.SI<Second>(), 0.SI<Second>());
var tq = Formulas.PowerToTorque(_powerDemand, engineSpeed);
return _outPort.Initialize(torque + tq, engineSpeed);
}
#endregion
#region VectoSimulationComponent
protected override void DoWriteModalResults(IModalDataWriter writer)
{
writer[ModalResultField.Paux] = _powerDemand;
}
protected override void DoCommitSimulationStep() {}
#endregion
}
}
\ No newline at end of file
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Linq;
using TUGraz.VectoCore.Configuration;
......@@ -8,7 +7,6 @@ using TUGraz.VectoCore.Models.Connector.Ports;
using TUGraz.VectoCore.Models.Connector.Ports.Impl;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.Simulation.Impl;
using TUGraz.VectoCore.Models.SimulationComponent;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.Utils;
......@@ -95,7 +93,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{
var exceeded = new List<double>();
var acceleration = new List<double>();
var searchInterval = CurrentState.Acceleration.Value() / 2.0;
var searchInterval = CurrentState.Acceleration / 2.0;
do {
var delta = 0.0;
......
using System;
using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Models.Connector.Ports;
using TUGraz.VectoCore.Models.Simulation;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{
public class AuxiliaryData
{
public double EfficiencyToSupply { get; set; }
public double TransitionRatio { get; set; }
public double EfficiencyToEngine { get; set; }
public Watt GetPowerDemand(PerSecond nAuxiliary, Watt powerAuxOut)
{
throw new NotImplementedException();
}
public static AuxiliaryData ReadFromFile(string filePath)
{
throw new NotImplementedException();
}
}
public class MappingAuxiliary : VectoSimulationComponent, IAuxiliary, ITnInPort, ITnOutPort
{
private readonly IAuxiliaryCycleData _demand;
private AuxiliaryData _data;
private ITnOutPort _outPort;
private Watt _powerDemand;
public MappingAuxiliary(IVehicleContainer container, IAuxiliaryCycleData demand, AuxiliaryData data)
: base(container)
{
_demand = demand;
_data = data;
}
#region ITnInProvider
public ITnInPort InPort()
{
return this;
}
#endregion
#region ITnOutProvider
public ITnOutPort OutPort()
{
return this;
}
#endregion
#region ITnInPort
void ITnInPort.Connect(ITnOutPort other)
{
_outPort = other;
}
#endregion
#region ITnOutPort
IResponse ITnOutPort.Request(Second absTime, Second dt, NewtonMeter torque, PerSecond angularVelocity, bool dryRun)
{
if (_outPort == null) {
Log.ErrorFormat("{0} cannot handle incoming request - no outport available", absTime);
throw new VectoSimulationException(
string.Format("{0} cannot handle incoming request - no outport available",
absTime));
}
var torqueAux = GetPowerDemand(absTime, dt, angularVelocity);
return _outPort.Request(absTime, dt, torque + torqueAux, angularVelocity);
}
private NewtonMeter GetPowerDemand(Second absTime, Second dt, PerSecond angularVelocity)
{
var powerSupply = _demand.GetPowerDemand(absTime, dt);
var powerAuxOut = powerSupply / _data.EfficiencyToSupply;
var nAuxiliary = angularVelocity * _data.TransitionRatio;
var powerAuxIn = _data.GetPowerDemand(nAuxiliary, powerAuxOut);
var powerAux = powerAuxIn / _data.EfficiencyToEngine;
_powerDemand = powerAux;
var torqueAux = Formulas.PowerToTorque(powerAux, angularVelocity);
return torqueAux;
}
public IResponse Initialize(NewtonMeter torque, PerSecond angularVelocity)
{
var torqueAux = GetPowerDemand(0.SI<Second>(), 0.SI<Second>(), angularVelocity);
return _outPort.Initialize(torque + torqueAux, angularVelocity);
}
#endregion
#region VectoSimulationComponent
protected override void DoWriteModalResults(IModalDataWriter writer)
{
writer[ModalResultField.Paux_xxx] = _powerDemand;
}
protected override void DoCommitSimulationStep() {}
#endregion
}
}
\ No newline at end of file
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{
public class MappingAuxiliaryData
{
public double EfficiencyToSupply { get; set; }
public double TransitionRatio { get; set; }
public double EfficiencyToEngine { get; set; }
private readonly DelauneyMap _map = new DelauneyMap();
public Watt GetPowerDemand(PerSecond nAuxiliary, Watt powerAuxOut)
{
return _map.Interpolate(nAuxiliary.Value(), powerAuxOut.Value()).SI<Watt>();
}
public static MappingAuxiliaryData ReadFromFile(string fileName)
{
var auxData = new MappingAuxiliaryData();
var stream = new StreamReader(fileName);
stream.ReadLine(); // skip header "Transmission ration to engine rpm [-]"
auxData.TransitionRatio = stream.ReadLine().ToDouble();
stream.ReadLine(); // skip header "Efficiency to engine [-]"
auxData.EfficiencyToEngine = stream.ReadLine().ToDouble();
stream.ReadLine(); // skip header "Efficiency auxiliary to supply [-]"
auxData.EfficiencyToSupply = stream.ReadLine().ToDouble();
var m = new MemoryStream(Encoding.UTF8.GetBytes(stream.ReadToEnd()));
var table = VectoCSVFile.ReadStream(m);
var data = table.Rows.Cast<DataRow>().Select(row => new {
AuxiliarySpeed = row.ParseDouble("Auxiliary speed").RPMtoRad(),
MechanicalPower = row.ParseDouble("Mechanical power").SI().Kilo.Watt.Cast<Watt>(),
SupplyPower = row.ParseDouble("Supply power").SI().Kilo.Watt.Cast<Watt>()
});
foreach (var d in data) {
auxData._map.AddPoint(d.AuxiliarySpeed.Value(), d.SupplyPower.Value(), d.MechanicalPower.Value());
}
auxData._map.Triangulate();
return auxData;
}
}
}
\ No newline at end of file
Technology ,Long haul,Regional delivery,Urban delivery,Municipal utility,Construction,Heavy Urban,Urban,Suburban,Interurban,Coach
Standard alternator,0.7 ,0.7 ,0.7 ,0.7 ,0.7 ,1 ,1 ,1 ,1 ,1
\ No newline at end of file
......@@ -29,31 +29,77 @@ namespace TUGraz.VectoCore.Utils
return self.Val;
}
/// <summary>
/// Implements the operator +.
/// </summary>
/// <param name="si1">The si1.</param>
/// <param name="si2">The si2.</param>
/// <returns>
/// The result of the operator.
/// </returns>
[DebuggerHidden]
public static Scalar operator +(Scalar si1, Scalar si2)
{
return new Scalar(si1.Val + si2.Val);
}
[DebuggerHidden]
public static Scalar operator +(Scalar si1, double si2)
{
return new Scalar(si1.Val + si2);
}
/// <summary>
/// Implements the operator +.
/// </summary>
/// <param name="si1">The si1.</param>
/// <param name="si2">The si2.</param>
/// <returns>
/// The result of the operator.
/// </returns>
[DebuggerHidden]
public static Scalar operator +(double si1, Scalar si2)
{
return new Scalar(si1 + si2.Val);
}
/// <summary>
/// Implements the operator -.
/// </summary>
/// <param name="si1">The si1.</param>
/// <param name="si2">The si2.</param>
/// <returns>
/// The result of the operator.
/// </returns>
[DebuggerHidden]
public static Scalar operator -(Scalar si1, Scalar si2)
{
return new Scalar(si1.Val - si2.Val);
}
/// <summary>
/// Implements the operator -.
/// </summary>
/// <param name="si1">The si1.</param>
/// <param name="si2">The si2.</param>
/// <returns>
/// The result of the operator.
/// </returns>
[DebuggerHidden]
public static Scalar operator -(Scalar si1, double si2)
{
return new Scalar(si1.Val - si2);
}
/// <summary>
/// Implements the operator -.
/// </summary>
/// <param name="si1">The si1.</param>
/// <param name="si2">The si2.</param>
/// <returns>
/// The result of the operator.
/// </returns>
[DebuggerHidden]
public static Scalar operator -(double si1, Scalar si2)
{
return new Scalar(si1 - si2.Val);
......@@ -73,6 +119,15 @@ namespace TUGraz.VectoCore.Utils
[JsonConstructor]
private Newton(double val) : base(new SI(val).Newton) {}
/// <summary>
/// Implements the operator *.
/// </summary>
/// <param name="newton">The newton.</param>
/// <param name="meter">The meter.</param>
/// <returns>
/// The result of the operator.
/// </returns>
[DebuggerHidden]
public static NewtonMeter operator *(Newton newton, Meter meter)
{
return ((newton as SI) * meter).Cast<NewtonMeter>();
......@@ -230,11 +285,29 @@ namespace TUGraz.VectoCore.Utils
[JsonConstructor]
private Watt(double val) : base(new SI(val).Watt) {}
/// <summary>
/// Implements the operator /.
/// </summary>
/// <param name="watt">The watt.</param>
/// <param name="newtonMeter">The newton meter.</param>
/// <returns>
/// The result of the operator.
/// </returns>
[DebuggerHidden]
public static PerSecond operator /(Watt watt, NewtonMeter newtonMeter)
{
return ((watt as SI) / newtonMeter).Cast<PerSecond>();
}
/// <summary>
/// Implements the operator /.
/// </summary>
/// <param name="watt">The watt.</param>
/// <param name="perSecond">The per second.</param>
/// <returns>
/// The result of the operator.
/// </returns>
[DebuggerHidden]
public static NewtonMeter operator /(Watt watt, PerSecond perSecond)
{
return ((watt as SI) / perSecond).Cast<NewtonMeter>();
......@@ -268,7 +341,15 @@ namespace TUGraz.VectoCore.Utils
[JsonConstructor]
private MeterPerSecond(double val) : base(new SI(val).Meter.Per.Second) {}
/// <summary>
/// Implements the operator /.
/// </summary>
/// <param name="meterPerSecond">The meter per second.</param>
/// <param name="meter">The meter.</param>
/// <returns>
/// The result of the operator.
/// </returns>
[DebuggerHidden]
public static PerSecond operator /(MeterPerSecond meterPerSecond, Meter meter)
{
return ((meterPerSecond as SI) / meter).Cast<PerSecond>();
......@@ -302,21 +383,25 @@ namespace TUGraz.VectoCore.Utils
[JsonConstructor]
private NewtonMeter(double val) : base(new SI(val).Newton.Meter) {}
[DebuggerHidden]
public static Watt operator *(NewtonMeter newtonMeter, PerSecond perSecond)
{
return ((newtonMeter as SI) * perSecond).Cast<Watt>();
}
[DebuggerHidden]
public static Watt operator *(PerSecond perSecond, NewtonMeter newtonMeter)
{
return ((perSecond as SI) * newtonMeter).Cast<Watt>();
}
[DebuggerHidden]
public static Second operator /(NewtonMeter newtonMeter, Watt watt)
{
return ((newtonMeter as SI) / watt).Cast<Second>();
}
[DebuggerHidden]
public static Newton operator /(NewtonMeter newtonMeter, Meter meter)
{
return ((newtonMeter as SI) / meter).Cast<Newton>();
......
......@@ -35,12 +35,13 @@ namespace TUGraz.VectoCore.Utils
/// </summary>
/// <param name="fileName"></param>
/// <param name="ignoreEmptyColumns"></param>
/// <param name="fullHeader"></param>
/// <exception cref="FileIOException"></exception>
/// <returns>A DataTable which represents the CSV File.</returns>
public static DataTable Read(string fileName, bool ignoreEmptyColumns = false)
public static DataTable Read(string fileName, bool ignoreEmptyColumns = false, bool fullHeader = false)
{
try {
return ReadData(File.ReadAllLines(fileName), ignoreEmptyColumns);
return ReadData(File.ReadAllLines(fileName), ignoreEmptyColumns, fullHeader);
} catch (Exception e) {
throw new VectoException(string.Format("File {0}: {1}", fileName, e.Message));
}
......@@ -68,11 +69,11 @@ namespace TUGraz.VectoCore.Utils
}
}
private static DataTable ReadData(string[] data, bool ignoreEmptyColumns = false)
private static DataTable ReadData(string[] data, bool ignoreEmptyColumns = false, bool fullHeader = false)
{
var lines = RemoveComments(data);
var validColumns = GetValidHeaderColumns(lines.First());
var validColumns = GetValidHeaderColumns(lines.First(), fullHeader).ToArray();
if (validColumns.Length > 0) {
// Valid Columns found => header was valid => skip header line
......@@ -108,22 +109,24 @@ namespace TUGraz.VectoCore.Utils
return table;
}
private static string[] GetValidHeaderColumns(string line)
private static IEnumerable<string> GetValidHeaderColumns(string line, bool fullHeader = false)
{
Contract.Requires(line != null);
double test;
var validColumns = GetColumns(line).
var validColumns = GetColumns(line, fullHeader).
Where(col => !double.TryParse(col, NumberStyles.Any, CultureInfo.InvariantCulture, out test));
return validColumns.ToArray();
}
private static IEnumerable<string> GetColumns(string line)
private static IEnumerable<string> GetColumns(string line, bool fullHeader = false)
{
Contract.Requires(line != null);
line = Regex.Replace(line, @"\[.*?\]", "");
line = line.Replace("<", "");
line = line.Replace(">", "");
if (!fullHeader) {
line = Regex.Replace(line, @"\[.*?\]", "");
line = line.Replace("<", "");
line = line.Replace(">", "");
}
return line.Split(Delimiter).Select(col => col.Trim());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment