Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

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

use type-safe calculation of expected internal resistance boundaries

use double division instead of integer division for map lookup
do not expect that RI map contains CoC 50%, check all rows
parent 38cc3b91
Branches
Tags
No related merge requests found
......@@ -1354,6 +1354,20 @@ namespace TUGraz.VectoCommon.Utils
public double AsMilliOhm => Val * 1000;
}
public class SpecificResistance : SIBase<SpecificResistance>
{
private static readonly int[] Units = { 1, 2, -3 + 1, -2 + 1, 0, 0, 0 };
private SpecificResistance(double val) : base(val, Units) { }
public override string UnitString => "ΩAs";
public static Ohm operator /(SpecificResistance spr, AmpereSecond amps)
{
return SIBase<Ohm>.Create(spr.Val / amps.Value());
}
}
public class Farad : SIBase<Farad>
{
private static readonly int[] Units = { -1, -2, 4, 2, 0, 0, 0 };
......
......@@ -324,34 +324,35 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider
const int SoC = 50;
var mapSoC = BatterySOCReader.Create(VoltageCurve);
if (!mapSoC.ContainsSoC(SoC / 100))
if (!mapSoC.ContainsSoC(SoC / 100.0))
{
throw new VectoException($"Battery SoC map does not contain entry with SoC: {SoC}");
}
var vNom = mapSoC.Lookup(SoC / 100);
var vNom = mapSoC.Lookup(SoC / 100.0);
var minCells = vNom / 4.0.SI<Volt>();
var maxCells = vNom / 3.0.SI<Volt>();
var resistances = base.GetInternalResistanceCurve();
var specificResistanceData = _specificResistances.Lookup(BatteryType);
DataRow rowSoC = resistances.AsEnumerable().First(x => x.ParseDouble(0) == SoC);
for (var i = 1; i < resistances.Columns.Count; i++)
{
var resistance = rowSoC.ParseDouble(i);
//var rowSoC = resistances.AsEnumerable().First();
foreach (DataRow rowSoC in resistances.AsEnumerable()) {
var soc = rowSoC.ParseDouble(0);
for (var i = 1; i < resistances.Columns.Count; i++) {
var resistance = rowSoC.ParseDouble(i).SI(Unit.SI.Milli.Ohm).Cast<Ohm>();
var resistanceName = resistances.Columns[i].ColumnName;
var specificResistance = specificResistanceData.GetValue(resistanceName);
var cellResistance = specificResistance / Capacity.AsAmpHour;
var cellResistance = specificResistance / Capacity;
var minResistance = cellResistance * minCells.Value();
var maxResistance = cellResistance * maxCells.Value();
if ((resistance < minResistance) || (resistance > maxResistance))
{
Log.Warn($@"Battery {resistanceName}: {resistance}, for SoC: {SoC}, out of range [{minResistance.ToString("N2")}, {maxResistance.ToString("N2")}]");
if ((resistance < minResistance) || (resistance > maxResistance)) {
Log.Warn(
$@"Battery {resistanceName}: {resistance.AsMilliOhm}, for SoC: {soc}, out of range [{minResistance.AsMilliOhm.ToString("N2")}, {maxResistance.AsMilliOhm.ToString("N2")}]");
}
}
}
......
......@@ -18,12 +18,12 @@ namespace TUGraz.VectoCore.Models.Declaration
public struct SpecificResistancesData
{
public double Ri_2;
public double Ri_10;
public double Ri_20;
public double Ri_120;
public SpecificResistance Ri_2; // mOhm x Ah
public SpecificResistance Ri_10;
public SpecificResistance Ri_20;
public SpecificResistance Ri_120;
public double GetValue(string variable)
public SpecificResistance GetValue(string variable)
{
var modifiedVariable = variable.Replace('-', '_');
......@@ -51,10 +51,10 @@ namespace TUGraz.VectoCore.Models.Declaration
{
var val = new SpecificResistancesData()
{
Ri_2 = row.ParseDouble(nameof(SpecificResistancesData.Ri_2).ToLower()),
Ri_10 = row.ParseDouble(nameof(SpecificResistancesData.Ri_10).ToLower()),
Ri_20 = row.ParseDouble(nameof(SpecificResistancesData.Ri_20).ToLower()),
Ri_120 = !row.IsNull(ri120) && !String.IsNullOrWhiteSpace(row[ri120].ToString()) ? row.ParseDouble(ri120) : double.NaN
Ri_2 = row.ParseDouble(nameof(SpecificResistancesData.Ri_2).ToLower()).SI(Unit.SI.Milli.Ohm.Ampere.Hour).Cast<SpecificResistance>(),
Ri_10 = row.ParseDouble(nameof(SpecificResistancesData.Ri_10).ToLower()).SI(Unit.SI.Milli.Ohm.Ampere.Hour).Cast<SpecificResistance>(),
Ri_20 = row.ParseDouble(nameof(SpecificResistancesData.Ri_20).ToLower()).SI(Unit.SI.Milli.Ohm.Ampere.Hour).Cast<SpecificResistance>(),
Ri_120 = !row.IsNull(ri120) && !String.IsNullOrWhiteSpace(row[ri120].ToString()) ? row.ParseDouble(ri120).SI(Unit.SI.Milli.Ohm.Ampere.Hour).Cast<SpecificResistance>() : null
};
var type = (BatteryType)Enum.Parse(typeof(BatteryType), row["type"].ToString());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment