split CalculateEnergyFlow into 3 functions

This commit is contained in:
ig 2023-08-31 11:44:24 +02:00
parent 5bcb46f841
commit cc2ab03d01
2 changed files with 100 additions and 114 deletions

View File

@ -106,52 +106,12 @@ internal static class Program
var pvOnDc = amptDevice.Read(); var pvOnDc = amptDevice.Read();
var battery = batteryDevices.Read(); var battery = batteryDevices.Read();
// ┌────┐ ┌────┐ var pvOnAcGrid = new AcPowerDevice { Power = 0 }; // TODO
// │ Pv │ │ Pv │ ┌────┐ var pvOnAcIsland = new AcPowerDevice { Power = 0 }; // TODO
// └────┘ └────┘ │ Pv │
// V V └────┘
// V V V
// (b) 0 W (e) 0 W V
// V V (i) 13.2 kW ┌────────────┐
// V V V │ Battery │
// ┌─────────┐ ┌──────────┐ ┌────────────┐ ┌─────────┐ V ├────────────┤
// │ Grid │ │ Grid Bus │ │ Island Bus │ │ AC/DC │ ┌────────┐ ┌───────┐ │ 52.3 V │
// ├─────────┤ -10.3 kW ├──────────┤ -11.7 kW ├────────────┤ -11.7 kW ├─────────┤ -11.7 kW │ Dc Bus │ 1008 W │ DC/DC │ 1008 W │ 99.1 % │
// │ -3205 W │<<<<<<<<<<│ 244 V │<<<<<<<<<<│ 244 V │<<<<<<<<<<│ -6646 W │<<<<<<<<<<├────────┤>>>>>>>>>>├───────┤>>>>>>>>>>│ 490 mA │
// │ -3507 W │ (a) │ 244 V │ (d) │ 244 V │ (g) │ -5071 W │ (h) │ 776 V │ (k) │ 56 V │ (l) │ 250 °C │
// │ -3605 W │ K1 │ 246 V │ K2 │ 246 V │ K3 └─────────┘ └────────┘ └───────┘ │ 445 A │
// └─────────┘ └──────────┘ └────────────┘ V │ 0 Warnings │
// V V V │ 0 Alarms │
// V V (j) 0 W └────────────┘
// (c) 1400 W (f) 0 W V
// V V V
// V V ┌──────┐
// ┌──────┐ ┌──────┐ │ Load │
// │ Load │ │ Load │ └──────┘
// └──────┘ └──────┘
var gridBusToIslandBus = Topology.CalculateGridBusToIslandBusPower(pvOnAcIsland, loadOnAcIsland, acDc);
// AC side var gridBusLoad = Topology.CalculateGridBusLoad(gridMeter, pvOnAcGrid, gridBusToIslandBus);
// a + b - c - d = 0 [eq1] var dcLoad = Topology.CalculateDcLoad(acDc, pvOnDc, dcDc);
// d + e - f - g = 0 [eq2]
//
// c & d are not measured!
//
// d = f + g - e [eq2]
// c = a + b - d [eq1]
//
// DC side
// h + i - j - k = 0 [eq3]
//
// g = h assuming no losses in ACDC
// k = l assuming no losses in DCDC
// j = h + i - k [eq3]
var pvOnAcGrid = new AcPowerDevice { Power = 0 };
var pvOnAcIsland = new AcPowerDevice { Power = 0 };
var flow = Topology.CalculateEnergyFlow(gridMeter, pvOnAcGrid, pvOnAcIsland, loadOnAcIsland, acDc, pvOnDc, dcDc);
return new StatusRecord return new StatusRecord
{ {
@ -165,10 +125,10 @@ internal static class Program
PvOnAcIsland = pvOnAcIsland, PvOnAcIsland = pvOnAcIsland,
PvOnDc = pvOnDc, PvOnDc = pvOnDc,
AcGridToAcIsland = flow.acGridToAcIsland, AcGridToAcIsland = gridBusToIslandBus,
LoadOnAcGrid = flow.loadOnAcGrid, LoadOnAcGrid = gridBusLoad,
LoadOnAcIsland = loadOnAcIsland, LoadOnAcIsland = loadOnAcIsland,
LoadOnDc = flow.dcPowerDevice, LoadOnDc = dcLoad,
StateMachine = StateMachine.Default, StateMachine = StateMachine.Default,
EssControl = EssControl.Default, EssControl = EssControl.Default,

View File

@ -10,7 +10,6 @@ using InnovEnergy.Lib.Units;
using InnovEnergy.Lib.Units.Power; using InnovEnergy.Lib.Units.Power;
using InnovEnergy.Lib.Utils; using InnovEnergy.Lib.Utils;
using Ac3Bus = InnovEnergy.Lib.Units.Composite.Ac3Bus; using Ac3Bus = InnovEnergy.Lib.Units.Composite.Ac3Bus;
using AcPower = InnovEnergy.Lib.Units.Composite.AcPower;
namespace InnovEnergy.App.SaliMax; namespace InnovEnergy.App.SaliMax;
@ -39,27 +38,32 @@ namespace InnovEnergy.App.SaliMax;
// └──────┘ └──────┘ // └──────┘ └──────┘
// Calculated values: c,d & h
// ==========================
//
//
// AC side
// a + b - c - d = 0 [eq1]
// d + e - f - g = 0 [eq2]
//
// c & d are not measured!
//
// d = f + g - e [eq2]
// c = a + b - d [eq1]
//
// DC side
// h + i - j - k = 0 [eq3]
//
// g = h assuming no losses in ACDC
// k = l assuming no losses in DCDC
// j = h + i - k [eq3]
public static class Topology public static class Topology
{ {
public static TextBlock CreateTopologyTextBlock(this StatusRecord status) public static TextBlock CreateTopologyTextBlock(this StatusRecord status)
{ {
// AC side
// a + b - c - d = 0 [eq1]
// d + e - f - g = 0 [eq2]
//
// c & d are not measured!
//
// d = f + g - e [eq2]
// c = a + b - d [eq1]
//
// DC side
// h + i - j - k = 0 [eq3]
//
// g = h assuming no losses in ACDC
// k = l assuming no losses in DCDC
// j = h + i - k [eq3]
var a = status.GridMeter?.Ac.Power.Active; var a = status.GridMeter?.Ac.Power.Active;
var b = status.PvOnAcGrid?.Power.Active; var b = status.PvOnAcGrid?.Power.Active;
var e = status.PvOnAcIsland?.Power.Active; var e = status.PvOnAcIsland?.Power.Active;
@ -93,9 +97,6 @@ public static class Topology
dcDc, dcDc,
batteries batteries
); );
// 730 V
} }
private static TextBlock CreateGridColumn(this StatusRecord status, ActivePower? a) private static TextBlock CreateGridColumn(this StatusRecord status, ActivePower? a)
@ -464,57 +465,82 @@ public static class Topology
: Flow.Horizontal(power); : Flow.Horizontal(power);
} }
public static (AcPowerDevice? acGridToAcIsland, AcPowerDevice? loadOnAcGrid, DcPowerDevice? dcPowerDevice)
CalculateEnergyFlow(EmuMeterRegisters? gridMeter, public static AcPowerDevice? CalculateGridBusLoad(EmuMeterRegisters? gridMeter, AcPowerDevice? pvOnAcGrid, AcPowerDevice? gridBusToIslandBusPower)
AcPowerDevice pvOnAcGrid,
AcPowerDevice pvOnAcIsland,
EmuMeterRegisters? loadOnAcIsland,
AcDcDevicesRecord acDc,
AmptStatus? pvOnDc,
DcDcDevicesRecord dcDc)
{ {
var gridPower = gridMeter?.Ac.Power.Active; var a = gridMeter ?.Ac.Power;
var islandLoadPower = loadOnAcIsland?.Ac.Power.Active; var b = pvOnAcGrid ?.Power;
var inverterAcPower = acDc.Ac.Power.Active; var d = gridBusToIslandBusPower?.Power;
var inverterDcPower = acDc.Dc.Power;
var a = gridPower; if (a is null || b is null || d is null)
var b = pvOnAcGrid.Power.Active; return null;
var e = pvOnAcIsland.Power.Active;
var f = islandLoadPower; var c = a + b - d; // [eq1]
var g = inverterAcPower;
var h = inverterDcPower; return new AcPowerDevice { Power = c };
}
public static AcPowerDevice? CalculateGridBusToIslandBusPower(AcPowerDevice? pvOnAcIsland, EmuMeterRegisters? loadOnAcIsland, AcDcDevicesRecord? acDc)
{
var e = pvOnAcIsland ?.Power;
var f = loadOnAcIsland?.Ac.Power;
var g = acDc ?.Ac.Power;
if (e is null || f is null || g is null)
return null;
var d = f + g - e; // [eq2]
return new AcPowerDevice { Power = d };
}
public static DcPowerDevice? CalculateDcLoad(AcDcDevicesRecord? acDc, AmptStatus? pvOnDc, DcDcDevicesRecord? dcDc)
{
var h = acDc?.Dc.Power;
var i = pvOnDc?.Dc.Power; var i = pvOnDc?.Dc.Power;
var k = dcDc.Dc.Link.Power; var k = dcDc?.Dc.Link.Power;
var l = k;
var j = Sum(h, i, -k);
var d = Sum(f, g, -e);
var c = Sum(a, b, -d);
if (h is null || i is null || k is null)
var acGridToAcIsland = d is null ? null : new AcPowerDevice { Power = AcPower.FromActiveReactive(d, 0) };
var loadOnAcGrid = c is null ? null : new AcPowerDevice { Power = AcPower.FromActiveReactive(c, 0) };
var dcPowerDevice = j is null ? null : new DcPowerDevice { Power = j };
return (acGridToAcIsland, loadOnAcGrid, dcPowerDevice);
}
private static ActivePower? Sum(ActivePower? e, ActivePower? f, ActivePower? g)
{
if (e is null || f is null || g is null)
return null; return null;
return f + g + e; var j = h + i - k; // [eq3]
return new DcPowerDevice { Power = j};
} }
private static DcPower? Sum(DcPower? e, DcPower? f, DcPower? g) // public static (AcPowerDevice? acGridToAcIsland, AcPowerDevice? loadOnAcGrid, DcPowerDevice? dcPowerDevice)
{ //
if (e is null || f is null || g is null) // CalculateEnergyFlow(EmuMeterRegisters? gridMeter,
return null; // AcPowerDevice pvOnAcGrid,
// AcPowerDevice pvOnAcIsland,
// EmuMeterRegisters? loadOnAcIsland,
// AcDcDevicesRecord acDc,
// AmptStatus? pvOnDc,
// DcDcDevicesRecord dcDc)
// {
// var gridPower = gridMeter?.Ac.Power.Active;
// var islandLoadPower = loadOnAcIsland?.Ac.Power.Active;
// var inverterAcPower = acDc.Ac.Power.Active;
// var inverterDcPower = acDc.Dc.Power;
//
// var a = gridPower;
// var b = pvOnAcGrid.Power.Active;
// var e = pvOnAcIsland.Power.Active;
// var f = islandLoadPower;
// var g = inverterAcPower;
// var h = inverterDcPower;
// var i = pvOnDc?.Dc.Power;
// var k = dcDc.Dc.Link.Power;
// var j = Sum(h, i, -k);
// var d = Sum(f, g, -e);
// var c = Sum(a, b, -d);
//
// var acGridToAcIsland = d is null ? null : new AcPowerDevice { Power = d.Value };
// var loadOnAcGrid = c is null ? null : new AcPowerDevice { Power = c.Value };
// var dcPowerDevice = j is null ? null : new DcPowerDevice { Power = j };
//
// return (acGridToAcIsland, loadOnAcGrid, dcPowerDevice);
// }
return f + g + e;
}
} }