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

mapping auxiliary data (delauney map)

parent 65d5700a
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,7 @@ namespace TUGraz.VectoCore.Models.Declaration
public NewtonMeter LookupTorque(double nu, PerSecond angularSpeedIn, PerSecond referenceSpeed)
{
var sec = Data.GetSection(kv => kv.Key < nu);
var sec = Data.GetSamples(kv => kv.Key < nu);
if (nu < sec.Item1.Key || sec.Item2.Key < nu) {
Log.Warn(string.Format("TCextrapol: nu = {0} [n_out/n_in]", nu));
......@@ -37,7 +37,7 @@ namespace TUGraz.VectoCore.Models.Declaration
public double LookupMu(double nu)
{
var sec = Data.GetSection(kv => kv.Key < nu);
var sec = Data.GetSamples(kv => kv.Key < nu);
if (nu < sec.Item1.Key || sec.Item2.Key < nu) {
Log.Warn(string.Format("TCextrapol: nu = {0} [n_out/n_in]", nu));
......
using System;
using System.Collections.Generic;
using System.Linq;
using Common.Logging;
using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Models.Connector.Ports;
......@@ -13,6 +12,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{
public class Auxiliary : VectoSimulationComponent, IAuxiliary, ITnInPort, ITnOutPort
{
public const string DirectAuxiliaryId = "";
private readonly Dictionary<string, Func<PerSecond, Watt>> _auxDict = new Dictionary<string, Func<PerSecond, Watt>>();
private readonly Dictionary<string, Watt> _powerDemands = new Dictionary<string, Watt>();
......@@ -88,7 +89,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public void AddDirect(IDrivingCycleCockpit cycle)
{
_auxDict[""] = ignored => cycle.CycleData().LeftSample.AdditionalAuxPowerDemand;
_auxDict[DirectAuxiliaryId] = ignored => cycle.CycleData().LeftSample.AdditionalAuxPowerDemand;
}
public void AddMapping(string auxId, IDrivingCycleCockpit cycle, MappingAuxiliaryData data)
......@@ -102,8 +103,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
_auxDict[auxId] = speed => {
var powerSupply = cycle.CycleData().LeftSample.AuxiliarySupplyPower[auxId];
var powerAuxOut = powerSupply / data.EfficiencyToSupply;
var nAuxiliary = speed * data.TransitionRatio;
var powerAuxOut = powerSupply / data.EfficiencyToSupply;
var powerAuxIn = data.GetPowerDemand(nAuxiliary, powerAuxOut);
return powerAuxIn / data.EfficiencyToEngine;
};
......
using System;
using System.Data;
using System.IO;
using System.Linq;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
......@@ -9,16 +11,39 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public double TransitionRatio { get; set; }
public double EfficiencyToEngine { get; set; }
private readonly DelauneyMap _map = new DelauneyMap();
public Watt GetPowerDemand(PerSecond nAuxiliary, Watt powerAuxOut)
{
//todo GetPowerDemand
throw new NotImplementedException();
return _map.Interpolate(nAuxiliary.Value(), powerAuxOut.Value()).SI<Watt>();
}
public static MappingAuxiliaryData ReadFromFile(string filePath)
public static MappingAuxiliaryData ReadFromFile(string fileName)
{
//todo ReadFromFile
throw new NotImplementedException();
var auxData = new MappingAuxiliaryData();
var stream = new StreamReader(fileName);
stream.ReadLine(); // skip header "Transmission ration to engine rpm [-]"
auxData.TransitionRatio = stream.ReadLine().ToDouble();
stream.ReadLine(); // skip header "Efficiency to engine [-]"
auxData.EfficiencyToEngine = stream.ReadLine().ToDouble();
stream.ReadLine(); // skip header "Efficiency auxiliary to supply [-]"
auxData.EfficiencyToSupply = stream.ReadLine().ToDouble();
var table = VectoCSVFile.ReadStream(stream.BaseStream);
var data = table.Rows.Cast<DataRow>().Select(row => new {
AuxiliarySpeed = row.ParseDouble("Auxiliary speed").RPMtoRad(),
MechanicalPower = row.ParseDouble("Mechanical power").SI().Kilo.Watt.Cast<Watt>(),
SupplyPower = row.ParseDouble("Supply power").SI().Kilo.Watt.Cast<Watt>()
});
foreach (var d in data) {
auxData._map.AddPoint(d.AuxiliarySpeed.Value(), d.SupplyPower.Value(), d.MechanicalPower.Value());
}
auxData._map.Triangulate();
return auxData;
}
}
}
\ No newline at end of file
......@@ -111,7 +111,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
private double AirDragInterpolate(IEnumerable<Point> curve, MeterPerSecond x)
{
var p = curve.GetSection(c => c.X < x);
var p = curve.GetSamples(c => c.X < x);
if (x < p.Item1.X || p.Item2.X < x) {
Log.Error(_data.CrossWindCorrectionMode == CrossWindCorrectionMode.VAirBeta
......@@ -151,7 +151,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var vAir = VectoMath.Sqrt<MeterPerSecond>(vAirX * vAirX + vAirY * vAirY);
var beta = Math.Atan((vAirY / vAirX).Value()).ToDegree();
var sec = betaValues.GetSection(b => b.Key < beta);
var sec = betaValues.GetSamples(b => b.Key < beta);
var deltaCdA = VectoMath.Interpolate(sec.Item1.Key, sec.Item2.Key, sec.Item1.Value, sec.Item2.Value, beta);
var cdA = cdA0Actual + deltaCdA;
......
......@@ -29,7 +29,7 @@ namespace TUGraz.VectoCore.Utils
/// Get the two adjacent items where the predicate is true.
/// If the predicate never gets true, the last 2 elements are returned.
/// </summary>
public static Tuple<T, T> GetSection<T>(this IEnumerable<T> self, Func<T, bool> skip, out int index)
public static Tuple<T, T> GetSamples<T>(this IEnumerable<T> self, Func<T, bool> skip, out int index)
{
var list = self.ToList();
var skipList = list.Select((arg1, i) => new { skip = skip(arg1) && i < list.Count - 1, i, value = arg1 });
......@@ -42,10 +42,10 @@ namespace TUGraz.VectoCore.Utils
/// Get the two adjacent items where the predicate is true.
/// If the predicate never gets true, the last 2 elements are returned.
/// </summary>
public static Tuple<T, T> GetSection<T>(this IEnumerable<T> self, Func<T, bool> predicate)
public static Tuple<T, T> GetSamples<T>(this IEnumerable<T> self, Func<T, bool> predicate)
{
int unused;
return self.GetSection(predicate, out unused);
return self.GetSamples(predicate, out unused);
}
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Data;
using System.Linq;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Tests.Utils
{
......@@ -40,6 +41,8 @@ namespace TUGraz.VectoCore.Tests.Utils
return Data.Rows.Cast<DataRow>().Select(x => x.Field<T>((int)key));
}
public Dictionary<string, Watt> Auxiliaries { get; set; }
public object this[ModalResultField key]
{
get { return CurrentRow[key.GetName()]; }
......
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