"normalize" DcBus

This commit is contained in:
ig 2023-08-31 14:16:09 +02:00
parent 6c2360f0ad
commit be452d190c
12 changed files with 85 additions and 68 deletions

View File

@ -62,7 +62,11 @@ public class AmptDevices
var busVoltage = nStringOptimizers == 0 ? 0 : soStati.Average(r => r.Voltage);
var busCurrent = nStringOptimizers == 0 ? 0 : soStati.Sum (r => r.Current);
var dc = DcBus.FromVoltageCurrent(busVoltage, busCurrent);
var dc = new DcBus
{
Voltage = busVoltage,
Current = busCurrent,
};
// flatten the 2 strings of each SO into one array
var strings = soStati.SelectMany(GetStrings).ToArray(nStrings);
@ -80,8 +84,16 @@ public class AmptDevices
{
// hardcoded: every SO has 2 strings (produced like this by AMPT)
yield return DcBus.FromVoltageCurrent(r.String1Voltage, r.String1Current);
yield return DcBus.FromVoltageCurrent(r.String2Voltage, r.String2Current);
yield return new()
{
Voltage = r.String1Voltage,
Current = r.String1Current,
};
yield return new()
{
Voltage = r.String2Voltage,
Current = r.String2Current,
};
}

View File

@ -35,11 +35,11 @@ public class Battery48TlRecords
HeatingPower = records.Sum(b => b.HeatingPower),
TimeToToc = records.Min(r => r.TimeToTOC),
Dc = DcBus.FromVoltageCurrent
(
records.Average(r => r.Dc.Voltage),
records.Sum(r => r.Dc.Current)
)
Dc = new()
{
Voltage = records.Average(r => r.Dc.Voltage),
Current = records.Sum(r => r.Dc.Current),
}
};
}

View File

@ -72,11 +72,11 @@ public class AcDcDevicesRecord
var p = Ac.Power.Active.Value;
var i = u == 0 ? 0 : p / u;
return DcBus.FromVoltageCurrent
(
voltage: u,
current: i
);
return new()
{
Voltage = u,
Current = i,
};
}
}
}

View File

@ -6,7 +6,11 @@ namespace InnovEnergy.Lib.Devices.Trumpf.TruConvertDc;
public class DcDcDevicesRecord
{
private static readonly DcBus NoDevice = DcBus.FromVoltageCurrent(0, 0);
private static readonly DcBus NoDevice = new()
{
Voltage = 0,
Current = 0,
};
public DcDcDevicesRecord(SystemControlRegisters? systemControl, IReadOnlyList<DcDcRecord> devices)
{
@ -14,15 +18,15 @@ public class DcDcDevicesRecord
Devices = devices;
}
public DcStatus Dc => new DcStatus
public DcStatus Dc => new()
{
Battery = Devices.Count == 0
? NoDevice
: DcBus.FromVoltageCurrent
(
Devices.Average(r => r.Status.Dc.Battery.Voltage.Value),
Devices.Sum(r => r.Status.Dc.Battery.Current.Value)
),
: new()
{
Voltage = Devices.Average(r => r.Status.Dc.Battery.Voltage.Value),
Current = Devices.Sum(r => r.Status.Dc.Battery.Current.Value),
},
Link = Devices.Count == 0
? NoDevice

View File

@ -24,16 +24,16 @@ public class DcDcStatus
return new()
{
Link = DcBus.FromVoltageCurrent
(
voltage: _Self.DcLinkVoltage,
current: -linkCurrent // TODO: review sign is reversed
),
Battery = DcBus.FromVoltageCurrent
(
voltage: _Self.BatteryVoltage,
current: -batteryCurrent // TODO: review sign is reversed
)
Link = new()
{
Voltage = _Self.DcLinkVoltage,
Current = -linkCurrent,
},
Battery = new()
{
Voltage = _Self.BatteryVoltage,
Current = -batteryCurrent,
}
};
}
}

View File

@ -1,5 +1,4 @@
using InnovEnergy.Lib.StatusApi.Connections;
using InnovEnergy.Lib.Units.Composite;
namespace InnovEnergy.Lib.StatusApi.DeviceTypes;

View File

@ -1,6 +1,5 @@
using InnovEnergy.Lib.StatusApi.Connections;
using InnovEnergy.Lib.Units;
using InnovEnergy.Lib.Units.Composite;
namespace InnovEnergy.Lib.StatusApi.DeviceTypes;

View File

@ -6,7 +6,7 @@ namespace InnovEnergy.Lib.StatusApi.DeviceTypes;
public interface IDcDc
{
DcBus DcLeft { get; }
DcBus DcLeft { get; }
DcBus DcRight { get; }
}

View File

@ -0,0 +1,7 @@
using InnovEnergy.Lib.StatusApi.Connections;
namespace InnovEnergy.Lib.StatusApi.DeviceTypes;
public interface IDcMeter : IDcConnection
{
}

View File

@ -2,9 +2,6 @@ namespace InnovEnergy.Lib.Units.Composite;
public sealed class Ac1Bus
{
private Ac1Bus()
{}
public required Voltage Voltage { get; init; }
public required Current Current { get; init; }
public required AcPower Power { get; init; }

View File

@ -6,6 +6,8 @@ namespace InnovEnergy.Lib.Units.Composite;
public sealed class AcPower
{
private AcPower(){}
public required ApparentPower Apparent { get; init; }
public required ActivePower Active { get; init; }
public required ReactivePower Reactive { get; init; }
@ -82,28 +84,23 @@ public sealed class AcPower
};
}
public static AcPower operator +(AcPower left, AcPower right)
{
return FromActiveReactive
(
left.Active + right.Active,
left.Reactive + right.Reactive
);
}
public static AcPower operator +(AcPower left, AcPower right) => FromActiveReactive
(
left.Active + right.Active,
left.Reactive + right.Reactive
);
public static AcPower operator -(AcPower left, AcPower right)
{
return left + -right;
}
public static AcPower operator -(AcPower left, AcPower right) => FromActiveReactive
(
left.Active - right.Active,
left.Reactive - right.Reactive
);
public static AcPower operator -(AcPower p)
{
return FromActiveReactive
(
-p.Active,
-p.Reactive
);
}
public static AcPower operator -(AcPower p) => FromActiveReactive
(
-p.Active,
-p.Reactive
);
public static implicit operator AcPower(Double p) => FromActiveReactive(p, 0);

View File

@ -4,18 +4,20 @@ namespace InnovEnergy.Lib.Units.Composite;
public sealed class DcBus
{
private DcBus() {}
public required Voltage Voltage { get; init; }
public required Current Current { get; init; }
public required Voltage Voltage { get; init; }
public required Current Current { get; init; }
public required DcPower Power { get; init; }
public DcPower Power => Voltage * Current;
public static DcBus FromVoltageCurrent(Voltage voltage, Current current) => new()
{
Voltage = voltage,
Current = current,
Power = current.Value * voltage.Value,
};
public static DcBus Null => FromVoltageCurrent(0, 0);
public static DcBus Null => new()
{
Voltage = 0,
Current = 0,
};
}