diff --git a/VectoCore/InputData/Reader/DataObjectAdaper/AbstractSimulationDataAdapter.cs b/VectoCore/InputData/Reader/DataObjectAdaper/AbstractSimulationDataAdapter.cs index 0933ecb6cd90efda8ab3c81330bfa8e37909135f..4a95a42f7e3c09ea2cd55444bc584eb48ba77632 100644 --- a/VectoCore/InputData/Reader/DataObjectAdaper/AbstractSimulationDataAdapter.cs +++ b/VectoCore/InputData/Reader/DataObjectAdaper/AbstractSimulationDataAdapter.cs @@ -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 diff --git a/VectoCoreTest/Integration/SimpleDrivingCycles.cs b/VectoCoreTest/Integration/SimpleDrivingCycles.cs index 4b1d3c06f7d5c058fd8d0604ed18d614cd5b7a83..80ca9514393add548e54057d0241e9d28145c2dc 100644 --- a/VectoCoreTest/Integration/SimpleDrivingCycles.cs +++ b/VectoCoreTest/Integration/SimpleDrivingCycles.cs @@ -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 diff --git a/VectoCoreTest/Models/SimulationComponentData/GearboxDataTest.cs b/VectoCoreTest/Models/SimulationComponentData/GearboxDataTest.cs index ccc6bff1cd77eb1689235a006dc5ed891df7bd3c..9a6ec8b0ccd4435684fc122f2d616a709ebad38b 100644 --- a/VectoCoreTest/Models/SimulationComponentData/GearboxDataTest.cs +++ b/VectoCoreTest/Models/SimulationComponentData/GearboxDataTest.cs @@ -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();