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 battery = batteryDevices.Read();
// ┌────┐ ┌────┐
// │ Pv │ │ Pv │ ┌────┐
// └────┘ └────┘ │ 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 pvOnAcGrid = new AcPowerDevice { Power = 0 }; // TODO
var pvOnAcIsland = new AcPowerDevice { Power = 0 }; // TODO
// 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 pvOnAcGrid = new AcPowerDevice { Power = 0 };
var pvOnAcIsland = new AcPowerDevice { Power = 0 };
var flow = Topology.CalculateEnergyFlow(gridMeter, pvOnAcGrid, pvOnAcIsland, loadOnAcIsland, acDc, pvOnDc, dcDc);
var gridBusToIslandBus = Topology.CalculateGridBusToIslandBusPower(pvOnAcIsland, loadOnAcIsland, acDc);
var gridBusLoad = Topology.CalculateGridBusLoad(gridMeter, pvOnAcGrid, gridBusToIslandBus);
var dcLoad = Topology.CalculateDcLoad(acDc, pvOnDc, dcDc);
return new StatusRecord
{
@ -165,10 +125,10 @@ internal static class Program
PvOnAcIsland = pvOnAcIsland,
PvOnDc = pvOnDc,
AcGridToAcIsland = flow.acGridToAcIsland,
LoadOnAcGrid = flow.loadOnAcGrid,
AcGridToAcIsland = gridBusToIslandBus,
LoadOnAcGrid = gridBusLoad,
LoadOnAcIsland = loadOnAcIsland,
LoadOnDc = flow.dcPowerDevice,
LoadOnDc = dcLoad,
StateMachine = StateMachine.Default,
EssControl = EssControl.Default,

View File

@ -10,7 +10,6 @@ using InnovEnergy.Lib.Units;
using InnovEnergy.Lib.Units.Power;
using InnovEnergy.Lib.Utils;
using Ac3Bus = InnovEnergy.Lib.Units.Composite.Ac3Bus;
using AcPower = InnovEnergy.Lib.Units.Composite.AcPower;
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 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 b = status.PvOnAcGrid?.Power.Active;
var e = status.PvOnAcIsland?.Power.Active;
@ -93,9 +97,6 @@ public static class Topology
dcDc,
batteries
);
// 730 V
}
private static TextBlock CreateGridColumn(this StatusRecord status, ActivePower? a)
@ -464,57 +465,82 @@ public static class Topology
: Flow.Horizontal(power);
}
public static (AcPowerDevice? acGridToAcIsland, AcPowerDevice? loadOnAcGrid, DcPowerDevice? dcPowerDevice)
CalculateEnergyFlow(EmuMeterRegisters? gridMeter,
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;
public static AcPowerDevice? CalculateGridBusLoad(EmuMeterRegisters? gridMeter, AcPowerDevice? pvOnAcGrid, AcPowerDevice? gridBusToIslandBusPower)
{
var a = gridMeter ?.Ac.Power;
var b = pvOnAcGrid ?.Power;
var d = gridBusToIslandBusPower?.Power;
if (a is null || b is null || d is null)
return null;
var c = a + b - d; // [eq1]
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 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);
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 };
var k = dcDc?.Dc.Link.Power;
return (acGridToAcIsland, loadOnAcGrid, dcPowerDevice);
}
private static ActivePower? Sum(ActivePower? e, ActivePower? f, ActivePower? g)
{
if (e is null || f is null || g is null)
if (h is null || i is null || k is 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)
{
if (e is null || f is null || g is null)
return null;
return f + g + e;
}
// public static (AcPowerDevice? acGridToAcIsland, AcPowerDevice? loadOnAcGrid, DcPowerDevice? dcPowerDevice)
//
// CalculateEnergyFlow(EmuMeterRegisters? gridMeter,
// 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);
// }
}