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 d76ab585 authored by Michael KRISPER's avatar Michael KRISPER
Browse files

Added classes for PTOLossMap and GearboxAuxiliary, Changed Auxiliary:...

Added classes for PTOLossMap and GearboxAuxiliary, Changed Auxiliary: AddConstant, AddCycle, AddMapping, Add
parent 77554dc9
Branches
Tags
No related merge requests found
...@@ -16,7 +16,7 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData ...@@ -16,7 +16,7 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData
/// </summary> /// </summary>
/// <param name="fileName"></param> /// <param name="fileName"></param>
/// <returns></returns> /// <returns></returns>
public static PTOIdleLossMap ReadFromFile(string fileName) public static PTOLossMap ReadFromFile(string fileName)
{ {
try { try {
return Create(VectoCSVFile.Read(fileName)); return Create(VectoCSVFile.Read(fileName));
...@@ -28,7 +28,7 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData ...@@ -28,7 +28,7 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData
/// <summary> /// <summary>
/// Create the pto idle loss map from an appropriate datatable. (2 columns: Engine Speed, PTO Torque) /// Create the pto idle loss map from an appropriate datatable. (2 columns: Engine Speed, PTO Torque)
/// </summary> /// </summary>
public static PTOIdleLossMap Create(DataTable data) public static PTOLossMap Create(DataTable data)
{ {
if (data.Columns.Count != 2) { if (data.Columns.Count != 2) {
throw new VectoException("PTO Idle LossMap Data File must consist of 2 columns: {0}, {1}", Fields.EngineSpeed, throw new VectoException("PTO Idle LossMap Data File must consist of 2 columns: {0}, {1}", Fields.EngineSpeed,
...@@ -47,8 +47,8 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData ...@@ -47,8 +47,8 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData
Fields.EngineSpeed, Fields.PTOTorque, ", ".Join(data.Columns.Cast<DataColumn>().Select(c => c.ColumnName))); Fields.EngineSpeed, Fields.PTOTorque, ", ".Join(data.Columns.Cast<DataColumn>().Select(c => c.ColumnName)));
} }
return new PTOIdleLossMap(data.Rows.Cast<DataRow>() return new PTOLossMap(data.Rows.Cast<DataRow>()
.Select(row => new PTOIdleLossMap.Entry { .Select(row => new PTOLossMap.Entry {
EngineSpeed = row.ParseDouble(Fields.EngineSpeed).RPMtoRad(), EngineSpeed = row.ParseDouble(Fields.EngineSpeed).RPMtoRad(),
PTOTorque = row.ParseDouble(Fields.PTOTorque).SI<NewtonMeter>() PTOTorque = row.ParseDouble(Fields.PTOTorque).SI<NewtonMeter>()
}).OrderBy(e => e.EngineSpeed).ToArray()); }).OrderBy(e => e.EngineSpeed).ToArray());
......
namespace TUGraz.VectoCore.Models.SimulationComponent.Data
{
public class PTOTransmissionData : SimulationComponentData
{
public string TransmissionType;
public ILossMap LossMap;
}
}
\ No newline at end of file
...@@ -41,13 +41,13 @@ using TUGraz.VectoCore.OutputData; ...@@ -41,13 +41,13 @@ using TUGraz.VectoCore.OutputData;
namespace TUGraz.VectoCore.Models.SimulationComponent.Impl namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{ {
public class EngineAuxiliary : StatefulVectoSimulationComponent<EngineAuxiliary.EngineAuxState>, IAuxInProvider, public class EngineAuxiliary : StatefulVectoSimulationComponent<EngineAuxiliary.State>, IAuxInProvider,
IAuxPort IAuxPort
{ {
public const string DirectAuxiliaryId = ""; private const string DirectAuxiliaryId = "";
private readonly Dictionary<string, Func<PerSecond, Watt>> _auxDict = new Dictionary<string, Func<PerSecond, Watt>>(); private readonly Dictionary<string, Func<PerSecond, Watt>> _auxiliaries =
private Dictionary<string, Watt> _powerDemands = new Dictionary<string, Watt>(); new Dictionary<string, Func<PerSecond, Watt>>();
public EngineAuxiliary(IVehicleContainer container) : base(container) {} public EngineAuxiliary(IVehicleContainer container) : base(container) {}
...@@ -56,6 +56,38 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -56,6 +56,38 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
return this; return this;
} }
public void AddConstant(string auxId, Watt powerDemand)
{
Add(auxId, _ => powerDemand);
}
public void AddCycle()
{
Add(DirectAuxiliaryId, _ => DataBus.CycleData.LeftSample.AdditionalAuxPowerDemand);
}
public void AddMapping(string auxId, AuxiliaryData data)
{
if (!DataBus.CycleData.LeftSample.AuxiliarySupplyPower.ContainsKey("Aux_" + auxId)) {
var error = string.Format("driving cycle does not contain column for auxiliary: {0}", auxId);
Log.Error(error);
throw new VectoException(error);
}
Add(auxId, speed => {
var powerSupply = DataBus.CycleData.LeftSample.AuxiliarySupplyPower["Aux_" + auxId];
var nAuxiliary = speed * data.TransmissionRatio;
var powerAuxOut = powerSupply / data.EfficiencyToSupply;
var powerAuxIn = data.GetPowerDemand(nAuxiliary, powerAuxOut);
return powerAuxIn / data.EfficiencyToEngine;
});
}
public void Add(string auxId, Func<PerSecond, Watt> powerLoss)
{
_auxiliaries[auxId] = powerLoss;
}
public NewtonMeter PowerDemand(Second absTime, Second dt, NewtonMeter torquePowerTrain, NewtonMeter torqueEngine, public NewtonMeter PowerDemand(Second absTime, Second dt, NewtonMeter torquePowerTrain, NewtonMeter torqueEngine,
PerSecond angularSpeed, bool dryRun = false) PerSecond angularSpeed, bool dryRun = false)
{ {
...@@ -72,18 +104,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -72,18 +104,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
private Watt ComputePowerDemand(PerSecond engineSpeed) private Watt ComputePowerDemand(PerSecond engineSpeed)
{ {
_powerDemands = _auxDict.ToDictionary(kv => kv.Key, kv => kv.Value(engineSpeed)); CurrentState.PowerDemands = _auxiliaries.ToDictionary(kv => kv.Key, kv => kv.Value(engineSpeed));
return _powerDemands.Values.Sum(p => p); return CurrentState.PowerDemands.Values.Sum(p => p);
} }
protected override void DoWriteModalResults(IModalDataContainer container) protected override void DoWriteModalResults(IModalDataContainer container)
{ {
foreach (var kv in _powerDemands.Where(kv => !string.IsNullOrWhiteSpace(kv.Key))) { foreach (var kv in CurrentState.PowerDemands.Where(kv => !string.IsNullOrWhiteSpace(kv.Key))) {
container[kv.Key] = kv.Value; container[kv.Key] = kv.Value;
} }
if (container[ModalResultField.P_aux] == null || container[ModalResultField.P_aux] == DBNull.Value) { if (container[ModalResultField.P_aux] == null || container[ModalResultField.P_aux] == DBNull.Value) {
// don't overwrite if someone else already wrote the total aux power // don't overwrite if someone else already wrote the total aux power
container[ModalResultField.P_aux] = _powerDemands.Values.Sum(p => p); container[ModalResultField.P_aux] = CurrentState.PowerDemands.Values.Sum(p => p);
} }
} }
...@@ -92,36 +124,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ...@@ -92,36 +124,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
AdvanceState(); AdvanceState();
} }
public void AddConstant(string auxId, Watt powerDemand) public class State
{
_auxDict[auxId] = speed => powerDemand;
}
public void AddDirect()
{
_auxDict[DirectAuxiliaryId] = speed => DataBus.CycleData.LeftSample.AdditionalAuxPowerDemand;
}
public void AddMapping(string auxId, AuxiliaryData data)
{
if (!DataBus.CycleData.LeftSample.AuxiliarySupplyPower.ContainsKey("Aux_" + auxId)) {
var error = string.Format("driving cycle does not contain column for auxiliary: {0}", auxId);
Log.Error(error);
throw new VectoException(error);
}
_auxDict[auxId] = speed => {
var powerSupply = DataBus.CycleData.LeftSample.AuxiliarySupplyPower["Aux_" + auxId];
var nAuxiliary = speed * data.TransmissionRatio;
var powerAuxOut = powerSupply / data.EfficiencyToSupply;
var powerAuxIn = data.GetPowerDemand(nAuxiliary, powerAuxOut);
return powerAuxIn / data.EfficiencyToEngine;
};
}
public class EngineAuxState
{ {
public PerSecond AngularSpeed; public PerSecond AngularSpeed;
public Dictionary<string, Watt> PowerDemands;
} }
} }
} }
\ No newline at end of file
using TUGraz.VectoCore.Models.Simulation;
using TUGraz.VectoCore.OutputData;
namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{
public class GearboxAuxiliary : EngineAuxiliary
{
public GearboxAuxiliary(IVehicleContainer container) : base(container) {}
protected override void DoWriteModalResults(IModalDataContainer container)
{
//todo mk-2016-08-17: write gearbox auxiliaries to mod file?
}
}
}
\ No newline at end of file
...@@ -33,6 +33,7 @@ using System; ...@@ -33,6 +33,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Models;
using TUGraz.VectoCore.Models.Connector.Ports; using TUGraz.VectoCore.Models.Connector.Ports;
using TUGraz.VectoCore.Models.Declaration;
using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Simulation;
using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.Simulation.Impl; using TUGraz.VectoCore.Models.Simulation.Impl;
...@@ -102,9 +103,15 @@ namespace TUGraz.VectoCore.Utils ...@@ -102,9 +103,15 @@ namespace TUGraz.VectoCore.Utils
return next; return next;
} }
public static IPowerTrainComponent AddRetarderAndGearbox(this IPowerTrainComponent prev, RetarderData data, public static IPowerTrainComponent AddComponent(this IPowerTrainComponent prev, IGearbox gearbox, RetarderData data,
IGearbox gearbox, IVehicleContainer container) PTOTransmissionData pto, IVehicleContainer container)
{ {
if (pto != null) {
var aux = new GearboxAuxiliary(container);
aux.AddConstant("PTO_TRANSM", DeclarationData.PTOTransmission.Lookup(pto.TransmissionType));
aux.Add("PTO_IDLE", n => pto.LossMap.GetTorqueLoss(n) * n);
}
switch (data.Type) { switch (data.Type) {
case RetarderType.TransmissionOutputRetarder: case RetarderType.TransmissionOutputRetarder:
return prev.AddComponent(new Retarder(container, data.LossMap, data.Ratio)).AddComponent(gearbox); return prev.AddComponent(new Retarder(container, data.LossMap, data.Ratio)).AddComponent(gearbox);
......
...@@ -44,14 +44,14 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation ...@@ -44,14 +44,14 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation
[TestCase] [TestCase]
public void PTOIdleLosses_FixPoints() public void PTOIdleLosses_FixPoints()
{ {
var entryList = new List<PTOIdleLossMap.Entry>(); var entryList = new List<PTOLossMap.Entry>();
for (var i = 0; i < 2000; i += 200) { for (var i = 0; i < 2000; i += 200) {
entryList.Add(new PTOIdleLossMap.Entry { entryList.Add(new PTOLossMap.Entry {
EngineSpeed = i.RPMtoRad(), EngineSpeed = i.RPMtoRad(),
PTOTorque = (Math.Sqrt(i) / 10).SI<NewtonMeter>() PTOTorque = (Math.Sqrt(i) / 10).SI<NewtonMeter>()
}); });
} }
var pto = new PTOIdleLossMap(entryList.ToArray()); var pto = new PTOLossMap(entryList.ToArray());
foreach (var entry in entryList) { foreach (var entry in entryList) {
Assert.AreEqual(entry.PTOTorque, pto.GetTorqueLoss(entry.EngineSpeed)); Assert.AreEqual(entry.PTOTorque, pto.GetTorqueLoss(entry.EngineSpeed));
...@@ -61,14 +61,14 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation ...@@ -61,14 +61,14 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation
[TestCase] [TestCase]
public void PTOIdleLosses_Interpolate() public void PTOIdleLosses_Interpolate()
{ {
var entryList = new List<PTOIdleLossMap.Entry>(); var entryList = new List<PTOLossMap.Entry>();
for (var i = 0; i < 2000; i += 200) { for (var i = 0; i < 2000; i += 200) {
entryList.Add(new PTOIdleLossMap.Entry { entryList.Add(new PTOLossMap.Entry {
EngineSpeed = i.RPMtoRad(), EngineSpeed = i.RPMtoRad(),
PTOTorque = (Math.Sqrt(i) / 10).SI<NewtonMeter>() PTOTorque = (Math.Sqrt(i) / 10).SI<NewtonMeter>()
}); });
} }
var pto = new PTOIdleLossMap(entryList.ToArray()); var pto = new PTOLossMap(entryList.ToArray());
for (var i = 1; i < entryList.Count; i++) { for (var i = 1; i < entryList.Count; i++) {
var v1 = entryList[i - 1]; var v1 = entryList[i - 1];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment