Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

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

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

Merge pull request #112 in VECTO/vecto-sim from ~EMQUARIMA/vecto-sim:bugfix/VECTO-185-intersection-of-gear-fullloadcurve to develop

* commit '50f5c329':
  add further assertions to check that intersected curve contains the correct values
  adapt intersection of full-load curves: use dedicated equality comparer for fullloadentries
  testcase for bug when intersecting full-load curves.
parents 7ff55f64 50f5c329
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@
* limitations under the Licence.
*/
using System.Collections.Generic;
using System.Linq;
using TUGraz.VectoCore.Models;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
......@@ -141,13 +142,13 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdaper
return engineCurve;
}
var entries = gearCurve.FullLoadEntries.Concat(engineCurve.FullLoadEntries)
.Select(entry => entry.EngineSpeed)
.OrderBy(engineSpeed => engineSpeed)
.Distinct()
.Select(engineSpeed => new FullLoadCurve.FullLoadCurveEntry {
EngineSpeed = engineSpeed,
.OrderBy(x => x.EngineSpeed)
.Distinct(new FullLoadEntryEqualityComparer())
.Select(x => new FullLoadCurve.FullLoadCurveEntry {
EngineSpeed = x.EngineSpeed,
TorqueFullLoad =
VectoMath.Min(engineCurve.FullLoadStationaryTorque(engineSpeed), gearCurve.FullLoadStationaryTorque(engineSpeed))
VectoMath.Min(engineCurve.FullLoadStationaryTorque(x.EngineSpeed),
gearCurve.FullLoadStationaryTorque(x.EngineSpeed))
});
var flc = new EngineFullLoadCurve {
......@@ -157,5 +158,18 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdaper
};
return flc;
}
internal class FullLoadEntryEqualityComparer : IEqualityComparer<FullLoadCurve.FullLoadCurveEntry>
{
public bool Equals(FullLoadCurve.FullLoadCurveEntry x, FullLoadCurve.FullLoadCurveEntry y)
{
return x.EngineSpeed.Value().IsEqual(y.EngineSpeed.Value());
}
public int GetHashCode(FullLoadCurve.FullLoadCurveEntry obj)
{
return obj.EngineSpeed.Value().GetHashCode();
}
}
}
}
\ No newline at end of file
......@@ -28,16 +28,22 @@ namespace TUGraz.VectoCore.Tests.Integration
public class SimpleDrivingCycles
{
public static DrivingCycleData CreateCycleData(string[] entries)
{
var cycleData = InputDataAsStream("<s>,<v>,<grad>,<stop>", entries);
return DrivingCycleDataReader.ReadFromStream(cycleData, CycleType.DistanceBased);
}
public static MemoryStream InputDataAsStream(string header, string[] entries)
{
var cycleData = new MemoryStream();
var writer = new StreamWriter(cycleData);
writer.WriteLine("<s>,<v>,<grad>,<stop>");
writer.WriteLine(header);
foreach (var entry in entries) {
writer.WriteLine(entry);
}
writer.Flush();
cycleData.Seek(0, SeekOrigin.Begin);
return DrivingCycleDataReader.ReadFromStream(cycleData, CycleType.DistanceBased);
return cycleData;
}
#region Accelerate
......
......@@ -21,8 +21,11 @@ using System.Data;
using System.Globalization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.InputData.Reader.DataObjectAdaper;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine;
using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox;
using TUGraz.VectoCore.Tests.Integration;
using TUGraz.VectoCore.Tests.Utils;
using TUGraz.VectoCore.Utils;
......@@ -267,9 +270,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData
AssertHelper.AreRelativeEqual(25, map.GetOutTorque(120.RPMtoRad(), 50.SI<NewtonMeter>(), true));
// test extrapolation not allowed
AssertHelper.Exception<VectoException>(() => {
map.GetOutTorque(120.RPMtoRad(), 50.SI<NewtonMeter>());
});
AssertHelper.Exception<VectoException>(() => { map.GetOutTorque(120.RPMtoRad(), 50.SI<NewtonMeter>()); });
}
[TestMethod]
......@@ -280,6 +281,40 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData
Assert.Inconclusive("test another file which is not correct");
}
[TestMethod]
public void TestFullLoadCurveIntersection()
{
var engineFLDString = new[] {
"560, 1180, -149",
"600, 1282, -148",
"800, 1791, -149",
"1000, 2300, -160",
"1200, 2300, -179",
"1400, 2300, -203",
"1600, 2079, -235",
"1800, 1857, -264",
"2000, 1352, -301",
"2100, 1100, -320",
};
var gbxFLDString = new[] {
"560, 2500",
"2100, 2500"
};
var dataEng =
VectoCSVFile.ReadStream(SimpleDrivingCycles.InputDataAsStream("n [U/min],Mfull [Nm],Mdrag [Nm]", engineFLDString));
var engineFLD = EngineFullLoadCurve.Create(dataEng, true);
var dataGbx = VectoCSVFile.ReadStream(SimpleDrivingCycles.InputDataAsStream("n [U/min],Mfull [Nm]", gbxFLDString));
var gbxFLD = FullLoadCurve.Create(dataGbx, true);
var fullLoadCurve = AbstractSimulationDataAdapter.IntersectFullLoadCurves(engineFLD, gbxFLD);
Assert.AreEqual(10, fullLoadCurve.FullLoadEntries.Count);
Assert.AreEqual(1180.0, fullLoadCurve.FullLoadStationaryTorque(560.RPMtoRad()).Value());
Assert.AreEqual(1100.0, fullLoadCurve.FullLoadStationaryTorque(2100.RPMtoRad()).Value());
}
protected PerSecond SpeedToAngularSpeed(double v, double r)
{
return ((60 * v) / (2 * r * Math.PI / 1000)).RPMtoRad();
......
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