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

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

Adapting Auxiliary to work with Units class

parent c5a19943
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ using System.Linq;
using System.Security.Cryptography.X509Certificates;
using Common.Logging;
using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.SimulationComponent.Data
{
......@@ -24,15 +25,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
}
}
public double GetPowerDemand(TimeSpan absTime, TimeSpan dt)
public Watt GetPowerDemand(TimeSpan absTime, TimeSpan dt)
{
var entry = _drivingCycle.Entries.FindIndex(x => x.Time > absTime.TotalSeconds);
var entry = _drivingCycle.Entries.FindLastIndex(x => x.Time <= absTime.TotalSeconds);
//if (entry == null) {
// Log.ErrorFormat("could not find entry in driving cycle for time {0}", absTime.TotalSeconds);
// return 0;
//}
Log.ErrorFormat("Found Entry at index {0}", entry);
return _auxiliaryId == null ? _drivingCycle.Entries[entry].AdditionalAuxPowerDemand * 1000 : _drivingCycle.Entries[entry].AuxiliarySupplyPower[_auxiliaryId] * 1000;
return _auxiliaryId == null ? _drivingCycle.Entries[entry].AdditionalAuxPowerDemand : _drivingCycle.Entries[entry].AuxiliarySupplyPower[_auxiliaryId];
}
}
......
......@@ -122,7 +122,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
/// Auxiliary. ID's are not case sensitive and must not contain
/// space or special characters.
/// </summary>
public Dictionary<string, double> AuxiliarySupplyPower { get; set; }
public Dictionary<string, Watt> AuxiliarySupplyPower { get; set; }
/// <summary>
/// [rad/s] If "n" is defined VECTO uses that instead of the
......@@ -223,12 +223,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
/// <summary>
/// [W]. Reads Auxiliary Supply Power (defined by Fields.AuxiliarySupplyPower-Prefix).
/// </summary>
public static Dictionary<string, double> Read(DataRow row)
public static Dictionary<string, Watt> Read(DataRow row)
{
return row.Table.Columns.Cast<DataColumn>().
Where(col => col.ColumnName.StartsWith(Fields.AuxiliarySupplyPower)).
ToDictionary(col => col.ColumnName.Substring(Fields.AuxiliarySupplyPower.Length - 1),
col => (double)row.ParseDouble(col).SI().Kilo.Watt);
col => row.ParseDouble(col).SI().Kilo.Watt.To<Watt>());
}
}
......@@ -366,6 +366,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
public IEnumerable<DrivingCycleEntry> Parse(DataTable table)
{
ValidateHeader(table.Columns.Cast<DataColumn>().Select(col => col.ColumnName).ToArray());
TimeSpan absTime = new TimeSpan(hours: 0, minutes:0, seconds: 0);
foreach (DataRow row in table.Rows)
{
......@@ -390,6 +391,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
entry.EngineTorque = Formulas.PowerToTorque(row.ParseDouble(Fields.EnginePower).SI().Kilo.Watt.To<Watt>(),
entry.EngineSpeed);
}
entry.Time = absTime.TotalSeconds;
absTime += new TimeSpan(hours: 0, minutes: 0, seconds: 1);
yield return entry;
}
}
......
......@@ -12,7 +12,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{
private ITnOutPort _outPort;
private AuxiliariesDemandAdapter _demand;
private double _powerDemand;
private Watt _powerDemand;
public EngineOnlyAuxiliary(IVehicleContainer container, AuxiliariesDemandAdapter demand) : base(container)
......@@ -35,7 +35,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
_outPort = other;
}
public void Request(TimeSpan absTime, TimeSpan dt, double torque, double engineSpeed)
public void Request(TimeSpan absTime, TimeSpan dt, NewtonMeter torque, RadianPerSecond engineSpeed)
{
if (_outPort == null)
{
......@@ -43,13 +43,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
throw new VectoSimulationException(String.Format("{0} cannot handle incoming request - no outport available", absTime.TotalSeconds));
}
_powerDemand = _demand.GetPowerDemand(absTime, dt);
var tq = VectoMath.ConvertPowerRpmToTorque(_powerDemand, engineSpeed);
_outPort.Request(absTime, dt, torque + tq, engineSpeed);
var tq = Formulas.PowerToTorque(_powerDemand, engineSpeed);
_outPort.Request(absTime, dt, (torque + tq).To<NewtonMeter>(), engineSpeed);
}
public override void CommitSimulationStep(IModalDataWriter writer)
{
writer[ModalResultField.Paux] = _powerDemand;
writer[ModalResultField.Paux] = (double)_powerDemand;
}
}
}
\ No newline at end of file
......@@ -27,7 +27,7 @@ namespace TUGraz.VectoCore.Tests.Utils
public void CommitSimulationStep(TimeSpan absTime, TimeSpan simulationInterval)
{
CurrentRow[ModalResultField.time.GetName()] = (absTime - TimeSpan.FromTicks(simulationInterval.Ticks / 2)).TotalSeconds;
CurrentRow[ModalResultField.time.GetName()] = (absTime + TimeSpan.FromTicks(simulationInterval.Ticks / 2)).TotalSeconds;
CurrentRow[ModalResultField.simulationInterval.GetName()] = simulationInterval.TotalSeconds;
CommitSimulationStep();
}
......
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