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 65d5700a authored by Michael KRISPER's avatar Michael KRISPER
Browse files

removed DirectAuxiliary and MappingAuxiliary, added Auxiliary which combines both

parent 980687da
No related branches found
No related tags found
No related merge requests found
Showing
with 153 additions and 164 deletions
using System.Collections.Generic;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.Simulation.Data
{
......@@ -23,5 +24,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
object Compute(string expression, string filter);
IEnumerable<T> GetValues<T>(ModalResultField key);
Dictionary<string, Watt> Auxiliaries { get; set; }
}
}
\ No newline at end of file
......@@ -18,6 +18,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
HasTorqueConverter = false;
ModFileName = modFileName;
Data = new ModalResults();
Auxiliaries = new Dictionary<string, Watt>();
CurrentRow = Data.NewRow();
_engineOnly = engineOnly;
}
......@@ -105,5 +106,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
get { return CurrentRow[(int)key]; }
set { CurrentRow[(int)key] = value; }
}
public Dictionary<string, Watt> Auxiliaries { get; set; }
}
}
\ No newline at end of file
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.Simulation.Data
{
[SuppressMessage("Microsoft.Usage", "CA2237:MarkISerializableTypesWithSerializable")]
[DesignerCategory("")] // Full qualified attribute needed to disable design view in VisualStudio
public class ModalResults : DataTable
{
......
......@@ -60,21 +60,24 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
// gearbox --> clutch
tmp = AddComponent(tmp, new Clutch(_container, data.EngineData));
// clutch --> direct aux --> ... --> aux_XXX --> directAux
if (data.Aux != null) {
var aux = new Auxiliary(_container);
foreach (var auxData in data.Aux) {
switch (auxData.DemandType) {
case AuxiliaryDemandType.Constant:
tmp = AddComponent(tmp, new DirectAuxiliary(_container, new AuxiliaryDemand(auxData.PowerDemand)));
aux.AddConstant(auxData.ID, auxData.PowerDemand);
break;
case AuxiliaryDemandType.Direct:
tmp = AddComponent(tmp, new DirectAuxiliary(_container, new AuxiliaryDemand(cycle)));
aux.AddDirect(cycle);
break;
case AuxiliaryDemandType.Mapping:
tmp = AddComponent(tmp, new MappingAuxiliary(_container, new AuxiliaryDemand(cycle, auxData.ID), auxData.Data));
aux.AddMapping(auxData.ID, cycle, auxData.Data);
break;
}
}
tmp = AddComponent(tmp, aux);
}
// connect aux --> engine
......@@ -140,7 +143,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
cycle.InPort().Connect(gearbox.OutPort());
var directAux = new DirectAuxiliary(_container, new AuxiliaryDemand(cycle));
var directAux = new Auxiliary(_container);
directAux.AddDirect(cycle);
gearbox.InPort().Connect(directAux.OutPort());
var engine = new CombustionEngine(_container, data.EngineData);
......
using System;
using Common.Logging;
using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.SimulationComponent.Data
{
public class AuxiliaryDemand : IAuxiliaryDemand
{
private readonly Func<Watt> _getPower;
/// <summary>
/// Creates a demand adapter which takes a specific aux column data from the cycle as base.
/// </summary>
/// <param name="drivingCycle"></param>
/// <param name="auxiliaryId"></param>
public AuxiliaryDemand(IDrivingCycleCockpit drivingCycle, string auxiliaryId)
{
if (!drivingCycle.CycleData().LeftSample.AuxiliarySupplyPower.ContainsKey(auxiliaryId)) {
var error = string.Format("driving cycle does not contain column for auxiliary: {0}", auxiliaryId);
LogManager.GetLogger(GetType()).ErrorFormat(error);
throw new VectoException(error);
}
_getPower = () => drivingCycle.CycleData().LeftSample.AuxiliarySupplyPower[auxiliaryId];
}
/// <summary>
/// Creates a demand adapter which takes the single Additional Aux Power Demand Data as base.
/// </summary>
/// <param name="drivingCycle"></param>
public AuxiliaryDemand(IDrivingCycleCockpit drivingCycle)
{
_getPower = () => drivingCycle.CycleData().LeftSample.AdditionalAuxPowerDemand;
}
/// <summary>
/// Creates a demand adapter which uses a constant power value as base.
/// </summary>
/// <param name="constantPowerDemand"></param>
public AuxiliaryDemand(Watt constantPowerDemand)
{
_getPower = () => constantPowerDemand;
}
public Watt GetPowerDemand()
{
return _getPower();
}
}
}
\ No newline at end of file
using TUGraz.VectoCore.Models.Connector.Ports;
namespace TUGraz.VectoCore.Models.SimulationComponent
namespace TUGraz.VectoCore.Models.SimulationComponent.Data
{
/// <summary>
/// Defines interfaces for auxiliary components.
......
using System;
using System.Collections.Generic;
using System.Linq;
using Common.Logging;
using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Models.Connector.Ports;
using TUGraz.VectoCore.Models.Simulation;
......@@ -8,17 +11,15 @@ using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{
public class DirectAuxiliary : VectoSimulationComponent, IAuxiliary, ITnInPort, ITnOutPort
public class Auxiliary : VectoSimulationComponent, IAuxiliary, ITnInPort, ITnOutPort
{
private readonly IAuxiliaryDemand _demand;
private readonly Dictionary<string, Func<PerSecond, Watt>> _auxDict = new Dictionary<string, Func<PerSecond, Watt>>();
private readonly Dictionary<string, Watt> _powerDemands = new Dictionary<string, Watt>();
private ITnOutPort _outPort;
private Watt _powerDemand;
public DirectAuxiliary(IVehicleContainer container, IAuxiliaryDemand demand)
: base(container)
{
_demand = demand;
}
public Auxiliary(IVehicleContainer container) : base(container) {}
#region ITnInProvider
......@@ -51,16 +52,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
IResponse ITnOutPort.Request(TimeSpan absTime, TimeSpan dt, NewtonMeter torque, PerSecond engineSpeed)
{
if (_outPort == null) {
Log.ErrorFormat("{0} cannot handle incoming request - no outport available", absTime);
throw new VectoSimulationException(
string.Format("{0} cannot handle incoming request - no outport available",
absTime.TotalSeconds));
_powerDemands.Clear();
var powerDemand = 0.SI<Watt>();
foreach (var kv in _auxDict) {
var demand = kv.Value(engineSpeed);
powerDemand += demand;
_powerDemands[kv.Key] = demand;
}
_powerDemand = _demand.GetPowerDemand();
var tq = Formulas.PowerToTorque(_powerDemand, engineSpeed);
return _outPort.Request(absTime, dt, torque + tq, engineSpeed);
return _outPort.Request(absTime, dt, torque + powerDemand * engineSpeed, engineSpeed);
}
#endregion
......@@ -69,9 +70,43 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public override void CommitSimulationStep(IModalDataWriter writer)
{
writer[ModalResultField.Paux] = (double)_powerDemand;
foreach (var kv in _powerDemands) {
if (string.IsNullOrWhiteSpace(kv.Key)) {
writer[ModalResultField.Paux] = kv.Value;
} else {
writer.Auxiliaries[kv.Key] = kv.Value;
}
}
}
#endregion
public void AddConstant(string auxId, Watt powerDemand)
{
_auxDict[auxId] = ignored => powerDemand;
}
public void AddDirect(IDrivingCycleCockpit cycle)
{
_auxDict[""] = ignored => cycle.CycleData().LeftSample.AdditionalAuxPowerDemand;
}
public void AddMapping(string auxId, IDrivingCycleCockpit cycle, MappingAuxiliaryData data)
{
if (!cycle.CycleData().LeftSample.AuxiliarySupplyPower.ContainsKey(auxId)) {
var error = string.Format("driving cycle does not contain column for auxiliary: {0}", auxId);
LogManager.GetLogger(GetType()).ErrorFormat(error);
throw new VectoException(error);
}
_auxDict[auxId] = speed => {
var powerSupply = cycle.CycleData().LeftSample.AuxiliarySupplyPower[auxId];
var powerAuxOut = powerSupply / data.EfficiencyToSupply;
var nAuxiliary = speed * data.TransitionRatio;
var powerAuxIn = data.GetPowerDemand(nAuxiliary, powerAuxOut);
return powerAuxIn / data.EfficiencyToEngine;
};
}
}
}
\ No newline at end of file
using System;
using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Models.Connector.Ports;
using TUGraz.VectoCore.Models.Simulation;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{
public class MappingAuxiliary : VectoSimulationComponent, IAuxiliary, ITnInPort, ITnOutPort
{
private readonly IAuxiliaryDemand _demand;
private MappingAuxiliaryData _data;
private ITnOutPort _outPort;
private Watt _powerDemand;
public MappingAuxiliary(IVehicleContainer container, IAuxiliaryDemand demand, MappingAuxiliaryData data)
: base(container)
{
_demand = demand;
_data = data;
}
#region ITnInProvider
public ITnInPort InPort()
{
return this;
}
#endregion
#region ITnOutProvider
public ITnOutPort OutPort()
{
return this;
}
#endregion
#region ITnInPort
void ITnInPort.Connect(ITnOutPort other)
{
_outPort = other;
}
#endregion
#region ITnOutPort
IResponse ITnOutPort.Request(TimeSpan absTime, TimeSpan dt, NewtonMeter torque, PerSecond angularVelocity)
{
if (_outPort == null) {
Log.ErrorFormat("{0} cannot handle incoming request - no outport available", absTime);
throw new VectoSimulationException(
string.Format("{0} cannot handle incoming request - no outport available",
absTime.TotalSeconds));
}
var power_supply = _demand.GetPowerDemand();
var power_aux_out = power_supply / _data.EfficiencyToSupply;
var n_auxiliary = angularVelocity * _data.TransitionRatio;
var power_aux_in = _data.GetPowerDemand(n_auxiliary, power_aux_out);
var power_aux = power_aux_in / _data.EfficiencyToEngine;
_powerDemand = power_aux;
var torque_aux = Formulas.PowerToTorque(power_aux, angularVelocity);
return _outPort.Request(absTime, dt, torque + torque_aux, angularVelocity);
}
#endregion
#region VectoSimulationComponent
public override void CommitSimulationStep(IModalDataWriter writer)
{
writer[ModalResultField.Paux_xxx] = (double)_powerDemand;
}
#endregion
}
}
\ No newline at end of file
......@@ -11,11 +11,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public Watt GetPowerDemand(PerSecond nAuxiliary, Watt powerAuxOut)
{
//todo GetPowerDemand
throw new NotImplementedException();
}
public static MappingAuxiliaryData ReadFromFile(string filePath)
{
//todo ReadFromFile
throw new NotImplementedException();
}
}
......
......@@ -123,7 +123,6 @@
<Compile Include="FileIO\Reader\DataObjectAdaper\DeclarationDataAdapter.cs" />
<Compile Include="FileIO\Reader\DataObjectAdaper\EngineeringDataAdapter.cs" />
<Compile Include="FileIO\Reader\Impl\AbstractSimulationDataReader.cs" />
<Compile Include="FileIO\Reader\Impl\AuxiliaryTypeHelper.cs" />
<Compile Include="FileIO\Reader\Impl\DeclarationModeSimulationDataReader.cs" />
<Compile Include="FileIO\Reader\Impl\EngineeringModeSimulationDataReader.cs" />
<Compile Include="FileIO\Reader\Impl\EngineOnlySimulationDataReader.cs" />
......@@ -166,7 +165,6 @@
<Compile Include="Utils\EnumHelper.cs" />
<Compile Include="Utils\RessourceHelper.cs" />
<Compile Include="Models\Declaration\Segment.cs" />
<Compile Include="Models\SimulationComponent\Data\AuxiliaryDemandAdapter.cs" />
<Compile Include="Models\Declaration\Axle.cs" />
<Compile Include="Models\Declaration\AxleConfiguration.cs" />
<Compile Include="Models\SimulationComponent\Data\CombustionEngineData.cs" />
......@@ -188,7 +186,6 @@
<Compile Include="Models\SimulationComponent\IEngineOnlyDrivingCycle.cs" />
<Compile Include="Models\SimulationComponent\IDrivingCycle.cs" />
<Compile Include="Models\SimulationComponent\IDriver.cs" />
<Compile Include="Models\SimulationComponent\Impl\MappingAuxiliary.cs" />
<Compile Include="Models\SimulationComponent\Impl\Vehicle.cs" />
<Compile Include="Models\SimulationComponent\IVehicle.cs" />
<Compile Include="Models\SimulationComponent\Impl\Clutch.cs" />
......@@ -211,7 +208,7 @@
<Compile Include="Models\SimulationComponent\IGearbox.cs" />
<Compile Include="Models\Connector\Ports\ISimulationPort.cs" />
<Compile Include="Models\SimulationComponent\Impl\DistanceBasedDrivingCycle.cs" />
<Compile Include="Models\SimulationComponent\Impl\DirectAuxiliary.cs" />
<Compile Include="Models\SimulationComponent\Impl\Auxiliary.cs" />
<Compile Include="Models\SimulationComponent\Impl\TimeBasedDrivingCycle.cs" />
<Compile Include="Models\SimulationComponent\Impl\CombustionEngine.cs" />
<Compile Include="Models\SimulationComponent\Impl\EngineOnlyGearbox.cs" />
......
......@@ -22,13 +22,15 @@ namespace TUGraz.VectoCore.Tests.Integration.EngineOnlyCycle
public void TestEngineOnlyDrivingCycle()
{
var data = DrivingCycleData.ReadFromFileEngineOnly(TestContext.DataRow["CycleFile"].ToString());
var cycle = new MockDrivingCycle(data);
var expectedResults = ModalResults.ReadFromFile(TestContext.DataRow["ModalResultFile"].ToString());
var vehicle = new VehicleContainer();
var engineData =
EngineeringModeSimulationDataReader.CreateEngineDataFromFile(TestContext.DataRow["EngineFile"].ToString());
var aux = new DirectAuxiliary(vehicle, new MockAuxiliaryDemand(data));
var aux = new Auxiliary(vehicle);
aux.AddDirect(cycle);
var gearbox = new EngineOnlyGearbox(vehicle);
......@@ -48,8 +50,8 @@ namespace TUGraz.VectoCore.Tests.Integration.EngineOnlyCycle
ModalResultField.n, ModalResultField.PaEng, ModalResultField.Tq_drag, ModalResultField.Pe_drag,
ModalResultField.Pe_eng, ModalResultField.Tq_eng, ModalResultField.Tq_full, ModalResultField.Pe_full
};
foreach (var cycle in data.Entries) {
port.Request(absTime, dt, cycle.EngineTorque, cycle.EngineSpeed);
foreach (var cycleEntry in data.Entries) {
port.Request(absTime, dt, cycleEntry.EngineTorque, cycleEntry.EngineSpeed);
foreach (var sc in vehicle.SimulationComponents()) {
sc.CommitSimulationStep(dataWriter);
}
......@@ -60,8 +62,7 @@ namespace TUGraz.VectoCore.Tests.Integration.EngineOnlyCycle
for (var j = 0; j < results.Length; j++) {
var field = results[j];
Assert.AreEqual((double)row[field.GetName()], dataWriter.GetDouble(field),
0.0001,
string.Format("t: {0} field: {1}", i, field));
0.0001, string.Format("t: {0} field: {1}", i, field));
}
if (row[ModalResultField.FC.GetName()] is double &&
!double.IsNaN(double.Parse(row[ModalResultField.FC.GetName()].ToString()))) {
......
using System.Collections.Generic;
using TUGraz.VectoCore.Models.SimulationComponent;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Tests.Utils
{
public class MockAuxiliaryDemand : IAuxiliaryDemand
public class MockDrivingCycle : IDrivingCycleCockpit
{
private List<DrivingCycleData.DrivingCycleEntry>.Enumerator _it;
private List<DrivingCycleData.DrivingCycleEntry>.Enumerator _left;
private List<DrivingCycleData.DrivingCycleEntry>.Enumerator _right;
public MockAuxiliaryDemand(DrivingCycleData data)
public MockDrivingCycle(DrivingCycleData data)
{
_it = data.Entries.GetEnumerator();
_left = data.Entries.GetEnumerator();
_right = data.Entries.GetEnumerator();
_right.MoveNext();
}
public Watt GetPowerDemand()
public CycleData CycleData()
{
_it.MoveNext();
return _it.Current.AdditionalAuxPowerDemand;
_left.MoveNext();
_right.MoveNext();
return new CycleData {
AbsTime = 0.SI<Second>(),
AbsDistance = 0.SI<Meter>(),
LeftSample = _left.Current,
RightSample = _right.Current
};
}
}
}
\ 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