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

Skip to content
Snippets Groups Projects
Commit b2fc09b3 authored by Markus QUARITSCH's avatar Markus QUARITSCH
Browse files

remove old electric motor map reader, rename new reader

parent 574e4c9f
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,7 @@ using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.InputData.Reader.ComponentData {
public static class ElectricMotorMapReaderNew
public static class ElectricMotorMapReader
{
public static EfficiencyMap Create(Stream data, int count)
{
......@@ -87,68 +87,5 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData {
}
public static class ElectricMotorMapReader
{
public static EfficiencyMap Create(Stream data, int count)
{
return Create(VectoCSVFile.ReadStream(data), count);
}
public static EfficiencyMap Create(DataTable data, int count)
{
var headerValid = HeaderIsValid(data.Columns);
if (!headerValid)
{
LoggingObject.Logger<FuelConsumptionMap>().Warn(
"Efficiency Map: Header Line is not valid. Expected: '{0}, {1}, {2}', Got: {3}. Falling back to column index.",
Fields.MotorSpeed,
Fields.Torque,
Fields.PowerElectrical,
data.Columns.Cast<DataColumn>().Select(c => c.ColumnName).Join());
data.Columns[0].ColumnName = Fields.MotorSpeed;
data.Columns[1].ColumnName = Fields.Torque;
data.Columns[2].ColumnName = Fields.PowerElectrical;
}
var delaunayMap = new DelaunayMap("ElectricMotorEfficiencyMap Mechanical to Electric");
foreach (DataRow row in data.Rows)
{
try
{
var entry = CreateEntry(row);
delaunayMap.AddPoint(-entry.Torque.Value() * count,
entry.MotorSpeed.Value(),
-entry.PowerElectrical.Value() * count);
}
catch (Exception e)
{
throw new VectoException($"EfficiencyMap - Line {data.Rows.IndexOf(row)}: {e.Message}", e);
}
}
delaunayMap.Triangulate();
return new EfficiencyMap(delaunayMap);
}
private static EfficiencyMap.Entry CreateEntry(DataRow row)
{
return new EfficiencyMap.Entry(
speed: row.ParseDouble(Fields.MotorSpeed).RPMtoRad(),
torque: row.ParseDouble(Fields.Torque).SI<NewtonMeter>(),
powerElectrical: row.ParseDouble(Fields.PowerElectrical).SI(Unit.SI.Kilo.Watt).Cast<Watt>());
}
private static bool HeaderIsValid(DataColumnCollection columns)
{
return columns.Contains(Fields.MotorSpeed) && columns.Contains(Fields.Torque) &&
columns.Contains(Fields.PowerElectrical);
}
public static class Fields
{
public const string MotorSpeed = "n";
public const string Torque = "T";
public const string PowerElectrical = "P_el";
}
}
}
\ No newline at end of file
......@@ -75,11 +75,11 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData {
[TestCase(@"TestData\Components\ElectricMotor\vem_P_inverter_DC_90_fine.vemo", 0.8999, 0.9001),
TestCase(@"TestData\Components\ElectricMotor\vem_P_inverter_DC_90_coarse.vemo", 0.8999, 0.9001),
TestCase(@"TestData\Components\ElectricMotor\vem_P_inverter_DC_std.vemo", 0, 1)]
public void TestInterpolationMethod_Proposal2(string filename, double etaMin, double etaMax)
public void TestInterpolationMethod_PowerMap(string filename, double etaMin, double etaMax)
{
EfficiencyMap emMap;
using (var fs = File.OpenRead(filename)) {
emMap = ElectricMotorMapReaderNew.Create(fs, 1);
emMap = ElectricMotorMapReader.Create(fs, 1);
}
var efficiencies = new List<double>();
......@@ -108,39 +108,6 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData {
Assert.IsTrue(efficiencies.All(x => x.IsBetween(etaMin, etaMax)), $"{efficiencies.Min()} - {efficiencies.Max()}");
}
[TestCase(@"TestData\Components\ElectricMotor\vem_P_inverter_DC_90_fine.vemo", 0.8999, 0.9001),
TestCase(@"TestData\Components\ElectricMotor\vem_P_inverter_DC_90_coarse.vemo", 0.8999, 0.9001),
TestCase(@"TestData\Components\ElectricMotor\vem_P_inverter_DC_std.vemo", 0, 1)]
public void TestInterpolationMethod_Current(string filename, double etaMin, double etaMax)
{
EfficiencyMap emMap;
using (var fs = File.OpenRead(filename)) {
emMap = ElectricMotorMapReader.Create(fs, 1);
}
var efficiencies = new List<double>();
for (var n = 10.RPMtoRad(); n < 4000.RPMtoRad(); n += 10.RPMtoRad()) {
for (var tq = -2800.SI<NewtonMeter>(); tq <= 2800.SI<NewtonMeter>(); tq += 100.SI<NewtonMeter>()) {
if (tq.IsEqual(0)) {
continue;
}
try {
var pwr = emMap.LookupElectricPower(n, tq);
if (pwr.ElectricalPower == null) {
continue;
}
Console.WriteLine($"{pwr.Speed.AsRPM}, {pwr.Torque.Value()}, {pwr.ElectricalPower.Value()}, {pwr.Extrapolated}, {(n * tq).Value()}");
var efficiency = tq < 0
? pwr.Speed * pwr.Torque / pwr.ElectricalPower
: pwr.ElectricalPower / (pwr.Speed * pwr.Torque);
// set efficiencies close to 0 to exactly 0 because later assertion uses sharp bounds without tolerance
efficiencies.Add(efficiency.IsEqual(0) ? 0.0 : efficiency);
} catch (Exception e) {
Console.WriteLine(e.Message);
}
}
}
Assert.IsTrue(efficiencies.All(x => x.IsBetween(etaMin, etaMax)), $"{efficiencies.Min()} - {efficiencies.Max()}");
}
}
}
\ 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