diff --git a/VectoCore/ModelbasedTests/DriverStrategy/CoastingTests.cs b/VectoCore/ModelbasedTests/DriverStrategy/CoastingTests.cs index 0436931ed9e47461b4fa91cc3cd47a27968b24e9..2807b7d7ba355e6adeb7baebfad9ccc2f5749875 100644 --- a/VectoCore/ModelbasedTests/DriverStrategy/CoastingTests.cs +++ b/VectoCore/ModelbasedTests/DriverStrategy/CoastingTests.cs @@ -5,7 +5,6 @@ using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Tests.Integration; using TUGraz.VectoCore.Tests.Utils; -using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert; namespace TUGraz.VectoCore.ModelbasedTests.DriverStrategy { @@ -16,11 +15,11 @@ namespace TUGraz.VectoCore.ModelbasedTests.DriverStrategy public void DisableLogging() { //LogManager.DisableLogging(); -//#if TRACE +#if TRACE GraphWriter.Enable(); -//#else -// GraphWriter.Disable(); -//#endif +#else + GraphWriter.Disable(); +#endif GraphWriter.Xfields = new[] { ModalResultField.dist }; diff --git a/VectoCore/ModelbasedTests/DriverStrategy/SimpleCycles.cs b/VectoCore/ModelbasedTests/DriverStrategy/SimpleCycles.cs new file mode 100644 index 0000000000000000000000000000000000000000..a9edbb1a1a17559dab3fde2b0e60954cd5d38256 --- /dev/null +++ b/VectoCore/ModelbasedTests/DriverStrategy/SimpleCycles.cs @@ -0,0 +1,133 @@ +/* +* This file is part of VECTO. +* +* Copyright © 2012-2016 European Union +* +* Developed by Graz University of Technology, +* Institute of Internal Combustion Engines and Thermodynamics, +* Institute of Technical Informatics +* +* VECTO is licensed under the EUPL, Version 1.1 or - as soon they will be approved +* by the European Commission - subsequent versions of the EUPL (the "Licence"); +* You may not use VECTO except in compliance with the Licence. +* You may obtain a copy of the Licence at: +* +* https://joinup.ec.europa.eu/community/eupl/og_page/eupl +* +* Unless required by applicable law or agreed to in writing, VECTO +* distributed under the Licence is distributed on an "AS IS" basis, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the Licence for the specific language governing permissions and +* limitations under the Licence. +* +* Authors: +* Stefan Hausberger, hausberger@ivt.tugraz.at, IVT, Graz University of Technology +* Christian Kreiner, christian.kreiner@tugraz.at, ITI, Graz University of Technology +* Michael Krisper, michael.krisper@tugraz.at, ITI, Graz University of Technology +* Raphael Luz, luz@ivt.tugraz.at, IVT, Graz University of Technology +* Markus Quaritsch, markus.quaritsch@tugraz.at, IVT, Graz University of Technology +* Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology +*/ + +using System; +using System.Globalization; +using NUnit.Framework; +using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Tests.Integration; +using TUGraz.VectoCore.Tests.Utils; + +namespace TUGraz.VectoCore.ModelbasedTests.DriverStrategy +{ + [TestFixture] + public class SimpleCycles + { + [TestFixtureSetUp] + public void Init() + { + //LogManager.DisableLogging(); +#if TRACE + GraphWriter.Enable(); +#else + GraphWriter.Disable(); +#endif + GraphWriter.Xfields = new[] { ModalResultField.time, ModalResultField.dist }; + + GraphWriter.Yfields = new[] { + ModalResultField.v_act, ModalResultField.acc, ModalResultField.n_eng_avg, ModalResultField.Gear, + ModalResultField.P_eng_out, ModalResultField.T_eng_fcmap, ModalResultField.FCMap + }; + GraphWriter.Series1Label = "Vecto 3"; + } + + private static string GetSlopeString(double slope) + { + var slopeStr = slope > 0 + ? Math.Abs(slope).ToString("uphill_#") + : slope < 0 + ? Math.Abs(slope).ToString("downhill_#") + : "level"; + return slopeStr; + } + + [ + TestCase(0, 80), TestCase(80, 0), TestCase(80, 80), + TestCase(0, 60), TestCase(60, 0), TestCase(60, 60), + TestCase(0, 40), TestCase(40, 0), TestCase(40, 40), + TestCase(0, 20), TestCase(20, 0), TestCase(20, 20), + ] + public void Truck_AllSlopes(double v1, double v2) + { + var slopes = new[] { 25, 20, 15, 10, 5, 3, 1, 0, -1, -3, -5, -10, -15, -20, -25 }; + + foreach (var slope in slopes) { + try { + var cycle = string.Format(CultureInfo.InvariantCulture, "0, {0}, {1}, {2}\n1000, {3}, {4}, {5}", v1, slope, + v1.IsEqual(0) ? 2 : 0, v2, slope, v2.IsEqual(0) ? 2 : 0); + + var modFileName = string.Format(CultureInfo.InvariantCulture, "Truck_{0}_{1}_{2}.vmod", v1, v2, + GetSlopeString(slope)); + var cycleData = SimpleDrivingCycles.CreateCycleData(cycle); + var run = Truck40tPowerTrain.CreateEngineeringRun(cycleData, modFileName); + + run.Run(); + + Assert.IsTrue(run.FinishedWithoutErrors, "Truck Run (v1: {0}, v2: {1}, slope: {2}) failed.", v1, v2, slope); + GraphWriter.Write(modFileName); + } catch (Exception ex) { + Assert.Fail("Truck Run (v1: {0}, v2: {1}, slope: {2}) failed: {3}", v1, v2, slope, ex); + } + } + } + + [ + TestCase(0, 80), TestCase(80, 0), TestCase(80, 80), + TestCase(0, 60), TestCase(60, 0), TestCase(60, 60), + TestCase(0, 40), TestCase(40, 0), TestCase(40, 40), + TestCase(0, 20), TestCase(20, 0), TestCase(20, 20), + ] + public void Coach_AllSlopes(double v1, double v2) + { + var slopes = new[] { 25, 20, 15, 12, 10, 7, 5, 3, 1, 0, -1, -3, -5, -7, -10, -12, -15, -20, -25 }; + + foreach (var slope in slopes) { + try { + var cycle = string.Format(CultureInfo.InvariantCulture, "0, {0}, {1}, {2}\n1000, {3}, {4}, {5}", v1, slope, + v1.IsEqual(0) ? 2 : 0, v2, slope, v2.IsEqual(0) ? 2 : 0); + + var modFileName = string.Format(CultureInfo.InvariantCulture, "Coach_{0}_{1}_{2}.vmod", v1, v2, + GetSlopeString(slope)); + var cycleData = SimpleDrivingCycles.CreateCycleData(cycle); + var run = CoachPowerTrain.CreateEngineeringRun(cycleData, modFileName); + + run.Run(); + + Assert.IsTrue(run.FinishedWithoutErrors, "Truck Run (v1: {0}, v2: {1}, slope: {2}) failed.", v1, v2, slope); + GraphWriter.Write(modFileName); + } catch (Exception ex) { + Assert.Fail("Truck Run (v1: {0}, v2: {1}, slope: {2}) failed: {3}", v1, v2, slope, ex); + } + } + } + } +} \ No newline at end of file diff --git a/VectoCore/ModelbasedTests/ModelbasedTests.csproj b/VectoCore/ModelbasedTests/ModelbasedTests.csproj index aca9ac333b1ac8ef49a48e3e4a3ca1cca9286958..400fd4975093a97b041e26decfa0c7071d727082 100644 --- a/VectoCore/ModelbasedTests/ModelbasedTests.csproj +++ b/VectoCore/ModelbasedTests/ModelbasedTests.csproj @@ -57,6 +57,7 @@ </Choose> <ItemGroup> <Compile Include="DriverStrategy\CoastingTests.cs" /> + <Compile Include="DriverStrategy\SimpleCycles.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> <ItemGroup> diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs index 58397a0eab0f5b1b58cf49ea80e66cec919e63bf..9d48e23020c90499680c81c65eaf994473510998 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs @@ -30,7 +30,6 @@ */ using System; -using System.Collections.Generic; using System.Linq; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Models; @@ -38,9 +37,9 @@ using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.Models.Connector.Ports; using TUGraz.VectoCore.Models.Connector.Ports.Impl; +using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.Simulation.DataBus; -using TUGraz.VectoCore.Models.Simulation.Impl; using TUGraz.VectoCore.OutputData; using TUGraz.VectoCore.Utils; using DriverData = TUGraz.VectoCore.Models.SimulationComponent.Data.DriverData; @@ -56,18 +55,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public DriverData DriverData { get; protected set; } protected IDriverStrategy DriverStrategy; - private Dictionary<string, object> _coastData = new Dictionary<string, object>(20); public string CurrentAction = ""; - //public MeterPerSquareSecond LookaheadDeceleration { get; protected set; } - - public Driver(VehicleContainer container, DriverData driverData, IDriverStrategy strategy) : base(container) + public Driver(IVehicleContainer container, DriverData driverData, IDriverStrategy strategy) : base(container) { DriverData = driverData; DriverStrategy = strategy; strategy.Driver = this; - - //LookaheadDeceleration = DeclarationData.Driver.LookAhead.Deceleration; } public IDriverDemandInPort InPort() @@ -110,8 +104,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var retVal = DriverStrategy.Request(absTime, ds, targetVelocity, gradient); - _coastData = ((DefaultDriverStrategy)DriverStrategy).LookAheadCoasting(ds); - CurrentState.Response = retVal; retVal.SimulationInterval = CurrentState.dt; retVal.Acceleration = CurrentState.Acceleration; diff --git a/VectoCore/VectoCoreTest/VectoCoreTest.csproj b/VectoCore/VectoCoreTest/VectoCoreTest.csproj index 3809b81cb4de2e784ddef214cd7d502f7b747e8a..8f662269234d87115de9c31fc8d4c3fb8a473761 100644 --- a/VectoCore/VectoCoreTest/VectoCoreTest.csproj +++ b/VectoCore/VectoCoreTest/VectoCoreTest.csproj @@ -85,7 +85,6 @@ <Compile Include="Integration\BusAuxiliaries\AAuxTests.cs" /> <Compile Include="Integration\CoachAdvancedAuxPowertrain.cs" /> <Compile Include="Integration\CoachPowerTrain.cs" /> - <Compile Include="Integration\DriverStrategy\CoastingTests.cs" /> <Compile Include="Integration\DriverStrategy\SimpleCycles.cs" /> <Compile Include="Integration\FullCycleDeclarationTest.cs"> <SubType>Code</SubType>