Code development platform for open source projects from the European Union institutions

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

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

Merge pull request #615 in VECTO/vecto-sim from ~EMQUARIMA/vecto-sim:bugfix/VECTO-700-errorr-in-simulation-with-0-stop-time-at-the-beginning-of-the-cycle to develop

* commit '2ff51842':
  update user manual
  DrivingCycle Reader: add stop time for first entry if stop-time is 0, duplicate entries with stop-time = 0
  adding testcase: cycle with 0 stopping time at the beginning
parents 65325ada 2ff51842
No related branches found
No related tags found
No related merge requests found
......@@ -78,6 +78,9 @@ Header: **\<s>, \<v>, \<stop>***\[, \<Padd>]\[, \<grad>]\[, \<PTO>]\[, \<vair\_r
**Bold columns** are mandatory. *Italic columns* are optional. Only the listed columns are allowed (no other columns!).<br />
Units are optional and are enclosed in [square-brackets] after the header-column. Comments may be written with a preceding hash-sign "#".
**Note:** if the cycle starts with a target speed of 0 km/h and the stop-time for the first entry is 0, VECTO sets the stop-time to 1s automatically.
| Identifier | Unit | Description |
|-------------|--------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **s** | [m] | Traveled distance. Must always be increasing. |
......
......@@ -5430,6 +5430,7 @@ CycleTime,UnknownCycleName,3600</code></pre>
<p>This driving cycle defines the target speed over distance. Vecto tries to achieve and maintain this target speed.</p>
<p>Header: <strong>&lt;s&gt;, &lt;v&gt;, &lt;stop&gt;</strong><em>[, &lt;Padd&gt;][, &lt;grad&gt;][, &lt;PTO&gt;][, &lt;vair_res&gt;, &lt;vair_beta&gt;][, &lt;Aux_ID&gt;]</em></p>
<p><strong>Bold columns</strong> are mandatory. <em>Italic columns</em> are optional. Only the listed columns are allowed (no other columns!).<br /> Units are optional and are enclosed in [square-brackets] after the header-column. Comments may be written with a preceding hash-sign “#”.</p>
<p><strong>Note:</strong> if the cycle starts with a target speed of 0 km/h and the stop-time for the first entry is 0, VECTO sets the stop-time to 1s automatically.</p>
<table style="width:100%;">
<colgroup>
<col width="4%"></col>
......@@ -213,6 +213,9 @@ namespace TUGraz.VectoCore.InputData.Reader
var altitude = current.Altitude;
for (var i = 0; i < entries.Count; i++) {
var entry = entries[i];
if (i == 0 && entry.VehicleTargetSpeed.IsEqual(0) && entry.StoppingTime.IsEqual(0)) {
entry.StoppingTime = 1.SI<Second>();
}
if (!entry.StoppingTime.IsEqual(0) && !entry.VehicleTargetSpeed.IsEqual(0)) {
throw new VectoException(
"Error in DrivingCycle: stop time specified but target-speed > 0! Distance: {0}, stop-time: {1}, target speed: {2}",
......@@ -233,7 +236,7 @@ namespace TUGraz.VectoCore.InputData.Reader
filtered.Add(entry);
current = entry;
}
if (!entry.StoppingTime.IsEqual(0) && entry.VehicleTargetSpeed.IsEqual(0)) {
if (entry.VehicleTargetSpeed.IsEqual(0)) {
// vehicle stops. duplicate current distance entry with 0 waiting time
var tmp = new DrivingCycleData.DrivingCycleEntry(entry) {
StoppingTime = 0.SI<Second>(),
......
......@@ -30,16 +30,16 @@
*/
using System;
using System.Collections.Generic;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{
public sealed class DrivingCycleEnumerator : IEnumerator<DrivingCycleData.DrivingCycleEntry>
{
private int _currentCycleIndex;
private readonly IDrivingCycleData _data;
using System.Collections.Generic;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{
public sealed class DrivingCycleEnumerator : IEnumerator<DrivingCycleData.DrivingCycleEntry>
{
private int _currentCycleIndex;
private readonly IDrivingCycleData _data;
public DrivingCycleEnumerator(IDrivingCycleData data)
{
_currentCycleIndex = 0;
......@@ -52,59 +52,59 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var retVal = new DrivingCycleEnumerator(_data);
retVal._currentCycleIndex = Math.Max(0, _currentCycleIndex - 1);
return retVal;
}
public DrivingCycleEnumerator Clone()
{
return new DrivingCycleEnumerator(_data) {
_currentCycleIndex = _currentCycleIndex,
LastEntry = LastEntry
};
}
public DrivingCycleData.DrivingCycleEntry Current
{
get { return LeftSample; }
}
public DrivingCycleData.DrivingCycleEntry LeftSample
{
get { return _data.Entries[_currentCycleIndex]; }
}
public DrivingCycleData.DrivingCycleEntry RightSample
{
get { return _currentCycleIndex + 1 >= _data.Entries.Count ? null : _data.Entries[_currentCycleIndex + 1]; }
}
public bool LastEntry { get; private set; }
object System.Collections.IEnumerator.Current
{
get { return LeftSample; }
}
public bool MoveNext()
{
// cycleIndex has to be max. next to last (so that rightSample is still valid.
if (_currentCycleIndex >= _data.Entries.Count - 2) {
LastEntry = true;
return false;
}
_currentCycleIndex++;
if (_currentCycleIndex == _data.Entries.Count - 2) {
LastEntry = true;
}
return true;
}
public void Reset()
{
_currentCycleIndex = 0;
LastEntry = false;
}
public void Dispose() {}
}
}
public DrivingCycleEnumerator Clone()
{
return new DrivingCycleEnumerator(_data) {
_currentCycleIndex = _currentCycleIndex,
LastEntry = LastEntry
};
}
public DrivingCycleData.DrivingCycleEntry Current
{
get { return LeftSample; }
}
public DrivingCycleData.DrivingCycleEntry LeftSample
{
get { return _data.Entries[_currentCycleIndex]; }
}
public DrivingCycleData.DrivingCycleEntry RightSample
{
get { return _currentCycleIndex + 1 >= _data.Entries.Count ? null : _data.Entries[_currentCycleIndex + 1]; }
}
public bool LastEntry { get; private set; }
object System.Collections.IEnumerator.Current
{
get { return LeftSample; }
}
public bool MoveNext()
{
// cycleIndex has to be max. next to last (so that rightSample is still valid.
if (_currentCycleIndex >= _data.Entries.Count - 2) {
LastEntry = true;
return false;
}
_currentCycleIndex++;
if (_currentCycleIndex == _data.Entries.Count - 2) {
LastEntry = true;
}
return true;
}
public void Reset()
{
_currentCycleIndex = 0;
LastEntry = false;
}
public void Dispose() {}
}
}
\ No newline at end of file
......@@ -79,8 +79,8 @@ namespace TUGraz.VectoCore.OutputData
public bool WriteAdvancedAux { get; set; }
public ModalDataContainer(string runName, FuelType fuel, IModalDataWriter writer, bool writeEngineOnly = false)
: this(0, runName, "", fuel, "", writer, _ => { }, writeEngineOnly) {}
public ModalDataContainer(string runName, FuelType fuel, IModalDataWriter writer, bool writeEngineOnly = false, params IModalDataFilter[] filters)
: this(0, runName, "", fuel, "", writer, _ => { }, writeEngineOnly, filters) {}
public ModalDataContainer(VectoRunData runData, IModalDataWriter writer, Action<ModalDataContainer> addReportResult,
bool writeEngineOnly, params IModalDataFilter[] filter)
......
......@@ -29,16 +29,21 @@
* Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology
*/
using System.Globalization;
using System.IO;
using NUnit.Framework;
using TUGraz.VectoCommon.Exceptions;
using TUGraz.VectoCommon.Models;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Configuration;
using TUGraz.VectoCore.InputData.FileIO.JSON;
using TUGraz.VectoCore.InputData.Reader;
using TUGraz.VectoCore.Models.Connector.Ports.Impl;
using TUGraz.VectoCore.Models.Simulation.Impl;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.Models.SimulationComponent.Impl;
using TUGraz.VectoCore.OutputData;
using TUGraz.VectoCore.OutputData.FileIO;
using TUGraz.VectoCore.Tests.Integration;
using TUGraz.VectoCore.Tests.Utils;
......@@ -51,6 +56,11 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent
public const double Tolerance = 0.0001;
[OneTimeSetUp]
public void RunBeforeAnyTests()
{
Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory);
}
[TestCase]
public void TestLimitRequst()
......@@ -219,5 +229,46 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent
container.CommitSimulationStep(absTime, response.SimulationInterval);
absTime += response.SimulationInterval;
}
[TestCase]
public void CycleStartsWithNoStopTime()
{
var data = new string[] {
// <s>,<v>,<grad>,<stop>
" 0, 0, 0, 0",
" 10, 50, 0, 0",
"100, 50, 0, 0"
};
var cycleData = SimpleDrivingCycles.CreateCycleData(data);
var modFileName = string.Format(CultureInfo.InvariantCulture, "CyccleStartWithoutStop.vmod");
var run = Truck40tPowerTrain.CreateEngineeringRun(cycleData, modFileName);
run.Run();
Assert.IsTrue(run.FinishedWithoutErrors, "Cycle start witout stoptime FAILED");
}
[TestCase]
public void CycleWithZeroStopTime()
{
var data = new string[] {
// <s>,<v>,<grad>,<stop>
" 0, 0, 0, 2",
"100, 50, 0, 0",
"120, 0, 0, 0",
"200, 50, 0, 0"
};
var cycleData = SimpleDrivingCycles.CreateCycleData(data);
var modFileName = string.Format(CultureInfo.InvariantCulture, "CyccleWithZeroStoptime.vmod");
var run = Truck40tPowerTrain.CreateEngineeringRun(cycleData, modFileName);
run.Run();
Assert.IsTrue(run.FinishedWithoutErrors, "Cycle start witout stoptime FAILED");
}
}
}
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