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 0c682611 authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

reading gearboxdata, first testcase

parent 44e488ef
Branches
Tags
No related merge requests found
...@@ -169,7 +169,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Data ...@@ -169,7 +169,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
[ModalResultField(typeof (double))] grad, [ModalResultField(typeof (double))] grad,
/// <summary> /// <summary>
/// [-] Gear. "0" = clutch opened / neutral. "0.5" = lock-up clutch is open (AT with torque converter only, see /// [-] GearData. "0" = clutch opened / neutral. "0.5" = lock-up clutch is open (AT with torque converter only, see
/// Gearbox) /// Gearbox)
/// </summary> /// </summary>
[ModalResultField(typeof (double))] Gear, [ModalResultField(typeof (double))] Gear,
......
...@@ -169,7 +169,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data ...@@ -169,7 +169,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
{ {
var curve = _fullLoadCurves.FirstOrDefault(kv => kv.Key.Contains(gear)); var curve = _fullLoadCurves.FirstOrDefault(kv => kv.Key.Contains(gear));
if (curve.Key.Equals(null)) { if (curve.Key.Equals(null)) {
throw new KeyNotFoundException(string.Format("Gear '{0}' was not found in the FullLoadCurves.", gear)); throw new KeyNotFoundException(string.Format("GearData '{0}' was not found in the FullLoadCurves.", gear));
} }
return curve.Value; return curve.Value;
...@@ -235,7 +235,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data ...@@ -235,7 +235,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
/// <summary> /// <summary>
/// Multiple Full Load and Drag Curves (.vfld) can be defined and assigned to different gears. /// Multiple Full Load and Drag Curves (.vfld) can be defined and assigned to different gears.
/// Gear "0" must be assigned for idling and Engine Only Mode. /// GearData "0" must be assigned for idling and Engine Only Mode.
/// </summary> /// </summary>
public class DataFullLoadCurve public class DataFullLoadCurve
{ {
......
...@@ -103,7 +103,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data ...@@ -103,7 +103,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
public const string EngineSpeed = "n"; public const string EngineSpeed = "n";
/// <summary> /// <summary>
/// [-] Gear input. Overwrites the gear shift model. /// [-] GearData input. Overwrites the gear shift model.
/// </summary> /// </summary>
public const string Gear = "gear"; public const string Gear = "gear";
...@@ -181,7 +181,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data ...@@ -181,7 +181,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
public PerSecond EngineSpeed { get; set; } public PerSecond EngineSpeed { get; set; }
/// <summary> /// <summary>
/// [-] Gear input. Overwrites the gear shift model. /// [-] GearData input. Overwrites the gear shift model.
/// </summary> /// </summary>
public double Gear { get; set; } public double Gear { get; set; }
......
namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox
{ {
public class Gear public class GearData
{ {
public ShiftPolygon ShiftPolygon { get; protected set; } public ShiftPolygon ShiftPolygon { get; protected set; }
...@@ -10,7 +10,10 @@ ...@@ -10,7 +10,10 @@
public bool TorqueConverterActive { get; protected set; } // TODO: think about refactoring... public bool TorqueConverterActive { get; protected set; } // TODO: think about refactoring...
public Gear(TransmissionLossMap lossMap, Gearbox.ShiftPolygon shiftPolygon, double ratio, bool torqueconverterActive) public double AverageEfficiency { get; set; }
public GearData(TransmissionLossMap lossMap, Gearbox.ShiftPolygon shiftPolygon, double ratio,
bool torqueconverterActive)
{ {
LossMap = lossMap; LossMap = lossMap;
ShiftPolygon = shiftPolygon; ShiftPolygon = shiftPolygon;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Messaging; using System.Runtime.Remoting.Messaging;
using Common.Logging; using Common.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
...@@ -12,7 +13,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox ...@@ -12,7 +13,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox
{ {
public class TransmissionLossMap public class TransmissionLossMap
{ {
[JsonProperty] private List<GearLossMapEntry> _entries; [JsonProperty] private readonly List<GearLossMapEntry> _entries;
private readonly DelauneyMap _lossMap; // Input Speed, Output Torque (to Wheels) => Input Torque (Engine)
private readonly DelauneyMap _reverseLossMap; // Input Speed, Input Torque (Engine) => Output Torque (Wheels)
public static TransmissionLossMap ReadFromFile(string fileName) public static TransmissionLossMap ReadFromFile(string fileName)
{ {
...@@ -39,7 +43,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox ...@@ -39,7 +43,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox
entries = CreateFromColumIndizes(data); entries = CreateFromColumIndizes(data);
} }
return new TransmissionLossMap { _entries = entries };
return new TransmissionLossMap(entries);
} }
private static bool HeaderIsValid(DataColumnCollection columns) private static bool HeaderIsValid(DataColumnCollection columns)
...@@ -75,6 +80,45 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox ...@@ -75,6 +80,45 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox
}).ToList(); }).ToList();
} }
private TransmissionLossMap(List<GearLossMapEntry> entries)
{
_entries = entries;
_lossMap = new DelauneyMap();
_reverseLossMap = new DelauneyMap();
foreach (var entry in _entries) {
_lossMap.AddPoint(entry.InputSpeed.Double(), entry.InputTorque.Double() - entry.TorqueLoss.Double(),
entry.InputTorque.Double());
_reverseLossMap.AddPoint(entry.InputSpeed.Double(), entry.InputTorque.Double(),
entry.InputTorque.Double() - entry.TorqueLoss.Double());
}
_lossMap.Triangulate();
_reverseLossMap.Triangulate();
}
/// <summary>
/// Compute the required torque at the input of the gearbox (from engine)
/// </summary>
/// <param name="angularVelocity">[1/s] angular speed of the shaft</param>
/// <param name="gbxOutTorque">[Nm] torque requested by the previous componend (towards the wheels)</param>
/// <returns>[Nm] torque requested from the next component (towards the engine)</returns>
public NewtonMeter GearboxInTorque(PerSecond angularVelocity, NewtonMeter gbxOutTorque)
{
// TODO: extrapolate!
return _lossMap.Interpolate(angularVelocity.Double(), gbxOutTorque.Double()).SI<NewtonMeter>();
}
/// <summary>
/// Compute the available torque at the output of the gearbox (towards wheels)
/// </summary>
/// <param name="angularVelocity">[1/s] angular speed of the shaft</param>
/// <param name="gbxInTorque">[Nm] torque provided by the engine at the gearbox' input shaft</param>
/// <returns>[Nm] torque provided to the next component (towards the wheels)</returns>
public NewtonMeter GearboxOutTorque(PerSecond angularVelocity, NewtonMeter gbxInTorque)
{
// TODO extrapolate!
return _reverseLossMap.Interpolate(angularVelocity.Double(), gbxInTorque.Double()).SI<NewtonMeter>();
}
public GearLossMapEntry this[int i] public GearLossMapEntry this[int i]
{ {
get { return _entries[i]; } get { return _entries[i]; }
......
...@@ -46,7 +46,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data ...@@ -46,7 +46,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
/// }, /// },
/// { /// {
/// "Ratio": 6.38, /// "Ratio": 6.38,
/// "LossMap": "Indirect Gear.vtlm", /// "LossMap": "Indirect GearData.vtlm",
/// "TCactive": false, /// "TCactive": false,
/// "ShiftPolygon": "ShiftPolygon.vgbs" /// "ShiftPolygon": "ShiftPolygon.vgbs"
/// }, /// },
...@@ -65,9 +65,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data ...@@ -65,9 +65,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
} }
[DataMember] [DataMember]
public Gear AxleGear { get; protected set; } public GearData AxleGearData { get; protected set; }
[DataMember] private Dictionary<int, Gear> _gearData = new Dictionary<int, Gear>(); //private double _axleGearEfficiency;
[DataMember] private Dictionary<uint, GearData> _gearData = new Dictionary<uint, GearData>();
//private Dictionary<uint, double> _gearEfficiency = new Dictionary<uint, double>();
[DataMember] private Data _data; [DataMember] private Data _data;
...@@ -80,6 +84,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data ...@@ -80,6 +84,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
public static GearboxData ReadFromJson(string json, string basePath = "") public static GearboxData ReadFromJson(string json, string basePath = "")
{ {
var lossMaps = new Dictionary<string, TransmissionLossMap>();
var gearboxData = new GearboxData(); var gearboxData = new GearboxData();
var d = JsonConvert.DeserializeObject<Data>(json); var d = JsonConvert.DeserializeObject<Data>(json);
...@@ -89,16 +95,24 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data ...@@ -89,16 +95,24 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
gearboxData._data = d; gearboxData._data = d;
for (var i = 0; i < d.Body.Gears.Count; i++) { for (uint i = 0; i < d.Body.Gears.Count; i++) {
//foreach (var gearSettings in d.Body.Gears) { var gearSettings = d.Body.Gears[(int) i];
var gearSettings = d.Body.Gears[i]; var lossMapPath = Path.Combine(basePath, gearSettings.LossMap);
var lossMap = TransmissionLossMap.ReadFromFile(Path.Combine(basePath, gearSettings.LossMap)); TransmissionLossMap lossMap;
if (lossMaps.ContainsKey(lossMapPath)) {
lossMap = lossMaps[lossMapPath];
lossMaps.Add(lossMapPath, lossMap);
} else {
lossMap = TransmissionLossMap.ReadFromFile(lossMapPath);
}
var shiftPolygon = !String.IsNullOrEmpty(gearSettings.ShiftPolygon) var shiftPolygon = !String.IsNullOrEmpty(gearSettings.ShiftPolygon)
? ShiftPolygon.ReadFromFile(Path.Combine(basePath, gearSettings.ShiftPolygon)) ? ShiftPolygon.ReadFromFile(Path.Combine(basePath, gearSettings.ShiftPolygon))
: null; : null;
var gear = new Gear(lossMap, shiftPolygon, gearSettings.Ratio, gearSettings.TCactive);
var gear = new GearData(lossMap, shiftPolygon, gearSettings.Ratio, gearSettings.TCactive);
if (i == 0) { if (i == 0) {
gearboxData.AxleGear = gear; gearboxData.AxleGearData = gear;
} else { } else {
gearboxData._gearData.Add(i, gear); gearboxData._gearData.Add(i, gear);
} }
...@@ -121,12 +135,62 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data ...@@ -121,12 +135,62 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
return gearboxData; return gearboxData;
} }
public void CalculateAverageEfficiency(CombustionEngineData engineData)
{
var angularVelocityStep = (2.0 / 3.0) * (engineData.GetFullLoadCurve(0).RatedSpeed() - engineData.IdleSpeed) / 10.0;
var axleGearEfficiencySum = 0.0;
var axleGearSumCount = 0;
foreach (var gearEntry in _gearData) {
var gearEfficiencySum = 0.0;
var gearSumCount = 0;
for (var angularVelocity = engineData.IdleSpeed + angularVelocityStep;
angularVelocity < engineData.GetFullLoadCurve(0).RatedSpeed();
angularVelocity += angularVelocityStep) {
var fullLoadStationaryTorque = engineData.GetFullLoadCurve(gearEntry.Key).FullLoadStationaryTorque(angularVelocity);
var torqueStep = (2.0 / 3.0) * fullLoadStationaryTorque / 10.0;
for (var engineOutTorque = (1.0 / 3.0) * fullLoadStationaryTorque;
engineOutTorque < fullLoadStationaryTorque;
engineOutTorque += torqueStep) {
var engineOutPower = Formulas.TorqueToPower(engineOutTorque, angularVelocity);
var gearboxOutPower =
Formulas.TorqueToPower(
gearEntry.Value.LossMap.GearboxOutTorque(angularVelocity, engineOutTorque), angularVelocity);
if (gearboxOutPower > engineOutPower) {
gearboxOutPower = engineOutPower;
}
gearEfficiencySum += ((engineOutPower - gearboxOutPower) / engineOutPower).Double();
gearSumCount += 1;
// axle gear
var angularVelocityAxleGear = angularVelocity / gearEntry.Value.Ratio;
var axlegearOutPower =
Formulas.TorqueToPower(
AxleGearData.LossMap.GearboxOutTorque(angularVelocityAxleGear,
Formulas.PowerToTorque(engineOutPower, angularVelocityAxleGear)),
angularVelocityAxleGear);
if (axlegearOutPower > engineOutPower) {
axlegearOutPower = engineOutPower;
}
axleGearEfficiencySum += (axlegearOutPower / engineOutPower).Double();
axleGearSumCount += 1;
}
}
gearEntry.Value.AverageEfficiency = gearEfficiencySum / gearSumCount;
}
AxleGearData.AverageEfficiency = axleGearEfficiencySum / axleGearSumCount;
}
public int GearsCount() public int GearsCount()
{ {
return _data.Body.Gears.Count; return _data.Body.Gears.Count;
} }
public Gear this[int i] public GearData this[uint i]
{ {
get { return _gearData[i]; } get { return _gearData[i]; }
} }
......
using System;
using TUGraz.VectoCore.Models.Connector.Ports;
using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{
public class AxleGear : IPowerTrainComponent, ITnInPort, ITnOutPort
{
private ITnOutPort _nextComponent;
private GearData _gearDataData;
public AxleGear(GearData gearDataData)
{
_gearDataData = gearDataData;
}
public ITnInPort InShaft()
{
return this;
}
public ITnOutPort OutShaft()
{
return this;
}
public void Connect(ITnOutPort other)
{
_nextComponent = other;
}
public IResponse Request(TimeSpan absTime, TimeSpan dt, NewtonMeter torque, PerSecond angularVelocity)
{
return _nextComponent.Request(absTime, dt, torque, angularVelocity);
}
}
}
\ No newline at end of file
...@@ -123,7 +123,7 @@ ...@@ -123,7 +123,7 @@
<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" />
<Compile Include="Models\SimulationComponent\Data\GearboxData.cs" /> <Compile Include="Models\SimulationComponent\Data\GearboxData.cs" />
<Compile Include="Models\SimulationComponent\Data\Gearbox\Gear.cs" /> <Compile Include="Models\SimulationComponent\Data\Gearbox\GearData.cs" />
<Compile Include="Models\SimulationComponent\Data\Gearbox\TransmissionLossMap.cs" /> <Compile Include="Models\SimulationComponent\Data\Gearbox\TransmissionLossMap.cs" />
<Compile Include="Models\SimulationComponent\Data\Gearbox\ShiftPolygon.cs" /> <Compile Include="Models\SimulationComponent\Data\Gearbox\ShiftPolygon.cs" />
<Compile Include="Models\SimulationComponent\Data\Gearbox\TorqueConverterData.cs" /> <Compile Include="Models\SimulationComponent\Data\Gearbox\TorqueConverterData.cs" />
...@@ -132,6 +132,7 @@ ...@@ -132,6 +132,7 @@
<Compile Include="Models\SimulationComponent\IClutch.cs" /> <Compile Include="Models\SimulationComponent\IClutch.cs" />
<Compile Include="Models\SimulationComponent\IEngineOnlyDrivingCycle.cs" /> <Compile Include="Models\SimulationComponent\IEngineOnlyDrivingCycle.cs" />
<Compile Include="Models\SimulationComponent\IDriverDemandDrivingCycle.cs" /> <Compile Include="Models\SimulationComponent\IDriverDemandDrivingCycle.cs" />
<Compile Include="Models\SimulationComponent\Impl\AxleGear.cs" />
<Compile Include="Models\SimulationComponent\Impl\Clutch.cs" /> <Compile Include="Models\SimulationComponent\Impl\Clutch.cs" />
<Compile Include="Models\SimulationComponent\Impl\Retarder.cs" /> <Compile Include="Models\SimulationComponent\Impl\Retarder.cs" />
<Compile Include="Models\SimulationComponent\IPowerTrainComponent.cs" /> <Compile Include="Models\SimulationComponent\IPowerTrainComponent.cs" />
......
using Microsoft.VisualStudio.TestTools.UnitTesting; using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.Utils; using TUGraz.VectoCore.Utils;
...@@ -18,7 +19,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData ...@@ -18,7 +19,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData
Assert.AreEqual(1.0, gbxData.TractionInterruption.Double(), 0.0001); Assert.AreEqual(1.0, gbxData.TractionInterruption.Double(), 0.0001);
Assert.AreEqual(9, gbxData.GearsCount()); Assert.AreEqual(9, gbxData.GearsCount());
Assert.AreEqual(3.240355, gbxData.AxleGear.Ratio, 0.0001); Assert.AreEqual(3.240355, gbxData.AxleGearData.Ratio, 0.0001);
Assert.AreEqual(1.0, gbxData[7].Ratio, 0.0001); Assert.AreEqual(1.0, gbxData[7].Ratio, 0.0001);
Assert.AreEqual(-400, gbxData[1].ShiftPolygon[0].Torque.Double(), 0.0001); Assert.AreEqual(-400, gbxData[1].ShiftPolygon[0].Torque.Double(), 0.0001);
...@@ -29,5 +30,24 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData ...@@ -29,5 +30,24 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData
Assert.AreEqual(-350, gbxData[1].LossMap[15].InputTorque.Double(), 0.0001); Assert.AreEqual(-350, gbxData[1].LossMap[15].InputTorque.Double(), 0.0001);
Assert.AreEqual(13.072, gbxData[1].LossMap[15].TorqueLoss.Double(), 0.0001); Assert.AreEqual(13.072, gbxData[1].LossMap[15].TorqueLoss.Double(), 0.0001);
} }
[TestMethod]
public void TestInterpolation()
{
var gbxData = GearboxData.ReadFromFile(GearboxFile);
var v = 11.72958;
var rdyn = 520;
var angSpeed = ((60 * v) / (2 * rdyn * Math.PI / 1000) * gbxData.AxleGearData.Ratio).SI<PerSecond>();
var PvD = 169640.7.SI<Watt>();
var torqueToWheels = Formulas.PowerToTorque(PvD, angSpeed);
var torqueFromEngine = gbxData.AxleGearData.LossMap.GearboxOutTorque(angSpeed, torqueToWheels);
var powerEngine = Formulas.TorqueToPower(torqueFromEngine, angSpeed);
var loss = powerEngine - PvD;
Assert.AreEqual(5551.5799, loss.Double(), 0.0001);
}
} }
} }
\ 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