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

Skip to content
Snippets Groups Projects
Commit fef1a3f7 authored by Michael KRISPER's avatar Michael KRISPER
Browse files

added fields for vehicle mass and vehicle loading in sum file

parent 249efe1f
No related branches found
No related tags found
No related merge requests found
......@@ -2,15 +2,19 @@
namespace TUGraz.VectoCore.Models.Simulation.Cockpit
{
/// <summary>
/// Defines a method to access shared data of the vehicle.
/// </summary>
public interface IVehicleCockpit
{
/// <summary>
/// Returns the current vehicle speed.
/// </summary>
/// <returns></returns>
MeterPerSecond VehicleSpeed();
}
/// <summary>
/// Defines a method to access shared data of the vehicle.
/// </summary>
public interface IVehicleCockpit
{
/// <summary>
/// Returns the current vehicle speed.
/// </summary>
/// <returns></returns>
MeterPerSecond VehicleSpeed();
double VehicleMass();
double VehicleLoading();
}
}
\ No newline at end of file
......@@ -9,7 +9,10 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
/// <param name="jobFileName">Name of the job file.</param>
/// <param name="jobName">Name of the job.</param>
/// <param name="cycleFileName">Name of the cycle file.</param>
void Write(IModalDataWriter data, string jobFileName, string jobName, string cycleFileName);
/// <param name="vehicleMass">The vehicle mass.</param>
/// <param name="vehicleLoading">The vehicle loading.</param>
void Write(IModalDataWriter data, string jobFileName, string jobName, string cycleFileName, double vehicleMass,
double vehicleLoading);
/// <summary>
/// Writes the data to the sum file.
......
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Collections.Generic;
using TUGraz.VectoCore.Utils;
using System.Linq;
using System.Data;
namespace TUGraz.VectoCore.Models.Simulation.Data
{
......@@ -11,6 +10,10 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
private readonly DataTable _table;
private readonly string _sumFileName;
/// <summary>
/// Initializes a new instance of the <see cref="SummaryFileWriter"/> class.
/// </summary>
/// <param name="sumFileName">Name of the sum file.</param>
public SummaryFileWriter(string sumFileName)
{
_sumFileName = sumFileName;
......@@ -51,8 +54,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
_table.Columns.Add("pStop [%]", typeof(double));
}
public void Write(IModalDataWriter data, string jobFileName, string jobName, string cycleFileName)
public void Write(IModalDataWriter data, string jobFileName, string jobName, string cycleFileName, double vehicleMass,
double vehicleLoading)
{
var row = _table.NewRow();
row["Job [-]"] = jobName;
......@@ -88,25 +91,15 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
//}
//todo get data from vehicle file
//row["Mass [kg]"] = Container.VehicleMass();
//row["Loading [kg]"] = Container.LoadingMass();
row["Mass [kg]"] = vehicleMass;
row["Loading [kg]"] = vehicleLoading;
var dtValues = data.GetValues<double>(ModalResultField.simulationInterval).ToList();
var accValues = data.GetValues<double?>(ModalResultField.acc);
var accelerations = CalculateAverageOverSeconds(dtValues, accValues).ToList();
row["a [m/s2]"] = accelerations.Average();
var acceleration3SecondAverage = new List<double>();
if (accelerations.Count >= 3) {
var runningAverage = (accelerations[0] + accelerations[1] + accelerations[2]) / 3.0;
for (var i = 2; i < accelerations.Count() - 1; i++) {
runningAverage -= accelerations[i - 2] / 3;
runningAverage += accelerations[i + 1] / 3;
acceleration3SecondAverage.Add(runningAverage);
}
}
var acceleration3SecondAverage = Calculate3SecondAverage(accelerations).ToList();
row["a_pos [m/s2]"] = acceleration3SecondAverage.Where(x => x > 0.125).DefaultIfEmpty(0).Average();
row["a_neg [m/s2]"] = acceleration3SecondAverage.Where(x => x < -0.125).DefaultIfEmpty(0).Average();
......@@ -115,15 +108,30 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
row["pCruise [%]"] = 100.0 * acceleration3SecondAverage.Count(x => x < 0.125 && x > -0.125) /
acceleration3SecondAverage.Count;
var velocity = data.GetValues<double?>(ModalResultField.v_act).ToList();
var timeSum = dtValues.Sum();
//todo pStop
row["pStop [%]"] = 100.0 * timeSum / (double)data.Compute("Max(time)", "");
var pStopTime = data.GetValues<double?>(ModalResultField.v_act)
.Zip(dtValues, (velocity, dt) => new { velocity, dt })
.Where(x => x.velocity < 0.1)
.Sum(x => x.dt);
row["pStop [%]"] = 100.0 * pStopTime / dtValues.Sum();
_table.Rows.Add(row);
}
private IEnumerable<double> CalculateAverageOverSeconds(IEnumerable<double> dtValues, IEnumerable<double?> accValues)
private static IEnumerable<double> Calculate3SecondAverage(List<double> accelerations)
{
if (accelerations.Count >= 3) {
var runningAverage = (accelerations[0] + accelerations[1] + accelerations[2]) / 3.0;
for (var i = 2; i < accelerations.Count() - 1; i++) {
runningAverage -= accelerations[i - 2] / 3.0;
runningAverage += accelerations[i + 1] / 3.0;
yield return runningAverage;
}
}
}
private static IEnumerable<double> CalculateAverageOverSeconds(IEnumerable<double> dtValues,
IEnumerable<double?> accValues)
{
var dtSum = 0.0;
var accSum = 0.0;
......
using TUGraz.VectoCore.Models.Simulation.Cockpit;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.SimulationComponent;
namespace TUGraz.VectoCore.Models.Simulation
......
......@@ -14,6 +14,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
private readonly IList<VectoSimulationComponent> _components = new List<VectoSimulationComponent>();
private IEngineCockpit _engine;
private IGearboxCockpit _gearbox;
private IVehicleCockpit _vehicle;
private ILog _logger;
private ISummaryDataWriter _sumWriter;
private IModalDataWriter _dataWriter;
......@@ -49,7 +50,17 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
public MeterPerSecond VehicleSpeed()
{
throw new VectoException("no vehicle available!");
return _vehicle != null ? _vehicle.VehicleSpeed() : 0.SI<MeterPerSecond>();
}
public double VehicleMass()
{
return _vehicle != null ? _vehicle.VehicleMass() : 0;
}
public double VehicleLoading()
{
return _vehicle != null ? _vehicle.VehicleLoading() : 0;
}
#endregion
......@@ -73,7 +84,6 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
{
_components.Add(component);
// TODO: refactor the following to use polymorphism?
var engine = component as IEngineCockpit;
if (engine != null) {
_engine = engine;
......@@ -83,6 +93,11 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
if (gearbox != null) {
_gearbox = gearbox;
}
var vehicle = component as IVehicleCockpit;
if (vehicle != null) {
_vehicle = vehicle;
}
}
......@@ -103,7 +118,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
_logger.Info("VehicleContainer finishing simulation.");
_dataWriter.Finish();
_sumWriter.Write(_dataWriter, _jobFileName, _jobName, _cycleFileName);
_sumWriter.Write(_dataWriter, _jobFileName, _jobName, _cycleFileName, VehicleMass(), VehicleLoading());
}
#endregion
......
......@@ -25,14 +25,6 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation
Assert.AreEqual(560.RPMtoRad(), container.EngineSpeed());
Assert.AreEqual(0U, container.Gear());
try {
container.VehicleSpeed();
Assert.Fail(
"Access to Vehicle speed should fail, because there should be no vehicle in EngineOnly Mode.");
} catch (VectoException ex) {
Assert.AreEqual(ex.Message, "no vehicle available!", "Vehicle speed wrong exception message.");
}
}
......@@ -124,26 +116,24 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation
jobContainer.RunJobs();
// compare results
// check sum file
var expectedSumFile = @"TestData\Results\EngineOnlyCycles\24t Coach.vsum";
var sumFile = @"TestData\Jobs\24t Coach.vsum";
Assert.IsTrue(File.Exists(sumFile), "sum file is missing: " + sumFile);
Assert.AreEqual(File.ReadAllLines(sumFile).Length, File.ReadAllLines(expectedSumFile).Length,
string.Format("sum file row count differs. Expected File: {0}, Actual File: {1}", expectedSumFile, sumFile));
// check vmod files
var expectedResultFiles = new[] {
@"TestData\Results\EngineOnlyCycles\24t Coach_Engine Only1.vmod",
@"TestData\Results\EngineOnlyCycles\24t Coach_Engine Only2.vmod",
@"TestData\Results\EngineOnlyCycles\24t Coach_Engine Only3.vmod"
};
var expectedSumFile = @"TestData\Results\EngineOnlyCycles\24t Coach.vsum";
var sumFile = @"TestData\Jobs\24t Coach.vsum";
var resultFiles = expectedResultFiles.Select(x => Path.GetFileName(x));
Assert.IsTrue(File.Exists(sumFile), "sum file is missing: " + sumFile);
foreach (var result in resultFiles) {
Assert.IsTrue(File.Exists(result), "vmod file is missing: " + result);
}
Assert.AreEqual(File.ReadAllLines(sumFile).Length, File.ReadAllLines(expectedSumFile).Length,
"sum file row count differs.");
var resultFileIt = resultFiles.GetEnumerator();
foreach (var expectedResultFile in expectedResultFiles) {
......@@ -151,7 +141,9 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation
var results = ModalResults.ReadFromFile(resultFileIt.Current);
var expectedResults = ModalResults.ReadFromFile(expectedResultFile);
Assert.AreEqual(expectedResults.Rows.Count, results.Rows.Count, "Moddata: Row count differs.");
Assert.AreEqual(expectedResults.Rows.Count, results.Rows.Count,
string.Format("Moddata: Row count differs. Expected File: {0}, Actual File: {1}", expectedResultFile,
resultFileIt.Current));
}
}
}
......
......@@ -4,7 +4,8 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation
{
public class TestSumWriter : ISummaryDataWriter
{
public void Write(IModalDataWriter data, string jobFileName, string jobName, string cycleFileName) {}
public void Write(IModalDataWriter data, string jobFileName, string jobName, string cycleFileName, double vehicleMass,
double vehicleLoading) {}
public void Finish() {}
}
......
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