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 21053391 authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

Merge branch 'develop' of...

Merge branch 'develop' of https://webgate.ec.europa.eu/CITnet/stash/scm/vecto/vecto-sim into feature/VECTO-54-implement-software-tests-for-engine

Conflicts:
	VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs
	VectoCoreTest/Models/SimulationComponent/CombustionEngineTest.cs
parents 5d196067 b2ebad99
No related branches found
No related tags found
No related merge requests found
Showing
with 110 additions and 200 deletions
using System;
namespace TUGraz.VectoCore.Models.Connector.Ports
{
public interface IDriverDemandInPort
{
void Connect(IDriverDemandOutPort other);
}
}
namespace TUGraz.VectoCore.Models.Connector.Ports
{
public interface IDriverDemandInProvider
{
IDriverDemandInPort InPort();
}
}
\ No newline at end of file
using System;
namespace TUGraz.VectoCore.Models.Connector.Ports
{
public interface IDriverDemandOutPort
{
void Request(TimeSpan absTime, TimeSpan dt, double velocity, double gradient);
}
}
namespace TUGraz.VectoCore.Models.Connector.Ports
{
public interface IDriverDemandOutProvider
{
IDriverDemandOutPort OutPort();
}
}
using TUGraz.VectoCore.Models.SimulationComponent;
namespace TUGraz.VectoCore.Models.Connector.Ports
namespace TUGraz.VectoCore.Models.Connector.Ports
{
public interface IInPort
{
void Connect(IOutPort other);
}
}
\ No newline at end of file
namespace TUGraz.VectoCore.Models.SimulationComponent
namespace TUGraz.VectoCore.Models.Connector.Ports
{
public interface IOutPort
{
......
namespace TUGraz.VectoCore.Models.Connector.Ports
{
public interface ITnInPort : ITnPort, IInPort
{
void Connect(ITnOutPort other);
}
}
\ No newline at end of file
using System;
namespace TUGraz.VectoCore.Models.Connector.Ports
{
public interface ITnOutPort : ITnPort, IOutPort
{
void Request(TimeSpan absTime, TimeSpan dt, double torque, double engineSpeed);
}
}
\ No newline at end of file
using System;
using TUGraz.VectoCore.Models.SimulationComponent;
namespace TUGraz.VectoCore.Models.Connector.Ports
namespace TUGraz.VectoCore.Models.Connector.Ports
{
public interface ITnPort
{
}
public interface ITnInPort : ITnPort, IInPort
{
void Connect(ITnOutPort other);
}
public interface ITnOutPort : ITnPort, IOutPort
{
void Request(TimeSpan absTime, TimeSpan dt, double torque, double engineSpeed);
}
}
namespace TUGraz.VectoCore.Models.Connector.Ports.Impl
{
abstract class Port
{
}
}
namespace TUGraz.VectoCore.Models.Connector.Ports.Impl
{
/* public class TnInPort : InPort, ITnInPort
{
}
*/
}
using System;
using TUGraz.VectoCore.Models.SimulationComponent;
namespace TUGraz.VectoCore.Models.Connector.Ports.Impl
{
public class TnOutPort : OutPort, ITnOutPort
{
private VectoSimulationComponent _component;
public TnOutPort(VectoSimulationComponent component)
{
_component = component;
}
public void Request(TimeSpan absTime, TimeSpan dt, double torque, double engineSpeed)
{
throw new NotImplementedException();
}
}
}
using System;
using System.Collections.Generic;
using System.Data;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.Simulation.Data
{
/// <summary>
/// Class for representation of one EngineOnly Driving Cycle
/// </summary>
/// <remarks>
/// The driving cylce (.vdri) must contain:
/// <n> Engine speed
/// <Me>|<Pe> Engine torque or engine power at clutch.
///
/// Optional:
/// <Padd> Additional power demand (aux)
///
/// To explicitly define motoring operation use the <DRAG> keyword, see below.
/// VECTO replaces the keyword with the motoring torque/power from the .vfld file during calculation.
/// </remarks>
public class EngineOnlyDrivingCycle
{
private static class Fields
{
public const string PowerEngine = "Pe";
public const string PowerAuxilaries = "Padd";
public const string Torque = "Me";
public const string EngineSpeed = "n";
}
/// <summary>
/// Engine Speed
/// </summary>
public double EngineSpeed { get; set; }
/// <summary>
/// Torque
/// </summary>
/// <remarks>Column "Me" in data file.</remarks>
public double Torque { get; set; }
/// <summary>
/// Engine power
/// </summary>
public double PowerEngine
{
get { return 2.0 * Math.PI / 60.0 * Torque * EngineSpeed; }
set { Torque = 60.0 / (2.0 * Math.PI) * value / EngineSpeed; }
}
/// <summary>
/// Additional power demand (aux) (Optional).
/// </summary>
public double PowerAuxilaries { get; set; }
public static List<EngineOnlyDrivingCycle> ReadFromFile(string fileName)
{
var data = VectoCSVFile.Read(fileName);
var cycles = new List<EngineOnlyDrivingCycle>();
//todo: catch exceptions if value format is wrong.
foreach (DataRow row in data.Rows)
{
var cycle = new EngineOnlyDrivingCycle();
cycle.EngineSpeed = row.GetDouble(Fields.EngineSpeed);
if (data.Columns.Contains(Fields.PowerEngine))
cycle.PowerEngine = row.GetDouble(Fields.PowerEngine);
else
cycle.Torque = row.GetDouble(Fields.Torque);
if (data.Columns.Contains(Fields.PowerAuxilaries))
cycle.PowerAuxilaries = row.GetDouble(Fields.PowerAuxilaries);
cycles.Add(cycle);
}
return cycles;
}
}
}
namespace TUGraz.VectoCore.Models.Simulation.Data
using System;
namespace TUGraz.VectoCore.Models.Simulation.Data
{
public interface IModalDataWriter
{
......
using System;
using System.Data;
using TUGraz.VectoCore.Utils;
......@@ -18,8 +19,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
public string FileName { get; set; }
public void CommitSimulationStep()
{
public void CommitSimulationStep()
{
Data.Rows.Add(CurrentRow);
CurrentRow = Data.NewRow();
}
......
using System;
using System.ComponentModel;
using System.Data;
using System.Reflection;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.Simulation.Data
{
[DesignerCategory("")] // to disable design view in VisualStudio
[System.ComponentModel.DesignerCategory("")] // Full qualified attribute needed to disable design view in VisualStudio
public class ModalResults : DataTable
{
public ModalResults()
......@@ -37,7 +36,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
if (col.ColumnName == ModalResultField.FC.GetName() && row.Field<string>(col) == "ERROR")
continue;
newRow.SetField(col.ColumnName, row.GetDouble(col.ColumnName));
newRow.SetField(col.ColumnName, row.ParseDouble(col.ColumnName));
}
modalResults.Rows.Add(newRow);
......@@ -59,10 +58,17 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
{
/// <summary>
/// Time step [s].
/// Midpoint of the simulated interval.
/// </summary>
[ModalResultField(typeof(double), caption: "time [s]")]
time,
/// <summary>
/// Simulation interval around the current time step. [s]
/// </summary>
[ModalResultField(typeof(double), caption: "simulation_interval [s]")]
simulationInterval,
/// <summary>
/// Engine speed [1/min].
/// </summary>
......
using TUGraz.VectoCore.Models.Simulation.Cockpit;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.SimulationComponent;
namespace TUGraz.VectoCore.Models.Simulation
......@@ -6,5 +7,7 @@ namespace TUGraz.VectoCore.Models.Simulation
public interface IVehicleContainer : ICockpit
{
void AddComponent(VectoSimulationComponent component);
void CommitSimulationStep(IModalDataWriter dataWriter);
void FinishSimulation(IModalDataWriter dataWriter);
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using TUGraz.VectoCore.Models.Simulation.Data;
namespace TUGraz.VectoCore.Models.Simulation.Impl
{
public class EngineOnlyTimeBasedVectoJob : TimeBasedVectoJob
{
private List<EngineOnlyDrivingCycle> _cycles;
private IModalDataWriter _dataWriter;
public EngineOnlyTimeBasedVectoJob(VehicleContainer container, List<EngineOnlyDrivingCycle> cycles, IModalDataWriter dataWriter)
: base(container)
{
_cycles = cycles;
_dataWriter = dataWriter;
}
public override void Run()
{
var port = Container.GetEngineOnlyStartPort();
var absTime = new TimeSpan(seconds: 0, minutes: 0, hours: 0);
var dt = new TimeSpan(seconds: 1, minutes: 0, hours: 0);
foreach (var cycle in _cycles)
{
port.Request(absTime, dt, cycle.Torque, cycle.EngineSpeed);
Container.CommitSimulationStep(_dataWriter);
absTime += dt;
}
Container.FinishSimulation(_dataWriter);
}
}
}
\ No newline at end of file
using System;
using Common.Logging;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.Models.SimulationComponent.Impl;
using EngineOnlyDrivingCycle = TUGraz.VectoCore.Models.SimulationComponent.Impl.EngineOnlyDrivingCycle;
namespace TUGraz.VectoCore.Models.Simulation.Impl
{
......@@ -8,20 +11,32 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
{
public static IVectoJob CreateTimeBasedEngineOnlyJob(string engineFile, string cycleFile, string resultFile)
{
Action<string> debug = LogManager.GetLogger<SimulationFactory>().Debug;
debug("SimulationFactory creating VehicleContainer.");
var container = new VehicleContainer();
debug("SimulationFactory creating engine.");
var engineData = CombustionEngineData.ReadFromFile(engineFile);
var engine = new CombustionEngine(container, engineData);
debug("SimulationFactory creating gearbox.");
var gearBox = new EngineOnlyGearbox(container);
var engineOutShaft = engine.OutShaft();
var gearBoxInShaft = gearBox.InShaft();
debug("SimulationFactory creating cycle.");
var cycleData = DrivingCycleData.ReadFromFileEngineOnly(cycleFile);
var cycle = new EngineOnlyDrivingCycle(container, cycleData);
debug("SimulationFactory connecting gearbox with engine.");
gearBox.InShaft().Connect(engine.OutShaft());
gearBoxInShaft.Connect(engineOutShaft);
debug("SimulationFactory connecting cycle with gearbox.");
cycle.InShaft().Connect(gearBox.OutShaft());
var cycles = EngineOnlyDrivingCycle.ReadFromFile(cycleFile.ToString());
var dataWriter = new ModalDataWriter(resultFile);
var job = new EngineOnlyTimeBasedVectoJob(container, cycles, dataWriter);
debug("SimulationFactory creating VectoJob.");
var job = new VectoJob(container, cycle, dataWriter);
return job;
}
......
using Common.Logging;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.SimulationComponent;
namespace TUGraz.VectoCore.Models.Simulation.Impl
{
public abstract class VectoJob : IVectoJob
public class VectoJob : IVectoJob
{
protected VehicleContainer Container { get; set; }
protected VectoJob(VehicleContainer container)
{
Container = container;
}
protected IEngineOnlyDrivingCycle Cycle { get; set; }
protected IModalDataWriter DataWriter { get; set; }
protected IVehicleContainer Container { get; set; }
public abstract void Run();
public IVehicleContainer GetContainer()
{
return Container;
}
}
public abstract class DistanceBasedVectoJob : VectoJob
{
protected DistanceBasedVectoJob(VehicleContainer container)
: base(container)
public VectoJob(IVehicleContainer container, IEngineOnlyDrivingCycle cycle, IModalDataWriter dataWriter)
{
Container = container;
Cycle = cycle;
DataWriter = dataWriter;
}
}
public abstract class TimeBasedVectoJob : VectoJob
{
protected TimeBasedVectoJob(VehicleContainer container)
: base(container)
public void Run()
{
LogManager.GetLogger(GetType()).Info("VectoJob started running.");
while (Cycle.DoSimulationStep())
{
Container.CommitSimulationStep(DataWriter);
}
Container.FinishSimulation(DataWriter);
LogManager.GetLogger(GetType()).Info("VectoJob finished.");
}
}
}
\ No newline at end of file
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