calculate_PTDF() always gives zero for first bus, regardless which bus is slack

24 views
Skip to first unread message

Tom Adams

unread,
Jun 14, 2024, 2:02:21 AMJun 14
to pypsa
When I use the function calculate_PTDF() on a subnetwork it returns a numpy array. Running a few tests, it looks like the dimensions are subnetwork.branches_i  () x  subnetwork.buses_i(). Can anyone confirm this?

However, the first column is always zero - regardless of whether the first bus is the slack bus or not. I would expect zeros for the slack bus, as an injection of power there would be taken up by the slack generator, but not for any other bus. Is the order of columns in the numpy array different to  subnetwork.buses_i(), or is there some other reason the first column is always zero?

Toy example, three buses with slack generator at Bus 2, and a load at Bus 1. 1MW at Bus 0 should increase flow along Line 01. 1MW at Bus1 should increase flow towards slack, on Line 12. 1MW at Bus2 should have no effect (slack). But this is not what you get!

import pypsa
import pandas as pd

n = pypsa.Network()

n.add("Bus", "Bus 0")
n.add("Bus", "Bus 1")
n.add("Bus", "Bus 2")
n.add("Line","Line 01", bus0 = "Bus 0", bus1 = "Bus 1", x=0.1, s_nom=50)
n.add("Line","Line 12", bus0 = "Bus 1", bus1 = "Bus 2", x=0.1, s_nom=50)

n.add("Generator", "Gen 3",
            bus=f"Bus 2",
            p_nom=100,
            marginal_cost=10,
            control = 'Slack',
)

n.add("Load", "Load 1",
            bus="Bus 1",
            p_set=50,
            )
 
n.determine_network_topology()
sn = n.sub_networks.obj['0']

sn.slack_bus
 'Bus 2'
sn.calculate_PTDF()
sn.branches()
pd.DataFrame(sn.PTDF, index = sn.branches_i(), columns = sn.buses_i())
BusBus 0Bus 1Bus 2
typename
LineLine 010.01.00.0
Line 120.01.01.0

Cheers
Tom Adams

Fabian Hofmann

unread,
Jun 14, 2024, 3:21:19 AMJun 14
to py...@googlegroups.com

Hey Tom,


this indeed looks a bit suspicious. Would you be so kind and post this as an issue on Github?


Best wishes

Fabian Hofmann

--
You received this message because you are subscribed to the Google Groups "pypsa" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pypsa+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/pypsa/CAOGMRcZ9s696LxzbSGKtOGsLxCGuGEUfutwSR13jSkbEAgf8mg%40mail.gmail.com.
-- 
Fabian Hofmann 

Postdoctoral Researcher
Institute of Energy Technology
Technische Universität Berlin
http://fabianhofmann.org/

Group website: https://www.tu.berlin/ensys

Tom Adams

unread,
Jun 17, 2024, 11:59:51 PMJun 17
to Fabian Hofmann, py...@googlegroups.com
Just to confirm, calculate_PTDF does indeed shuffle the busses so the slack bus is at first column

You can just uses subnetwork.buses_o as a column index instead of subnetwork.buses_i(), e.g.
n.determine_network_topology()
sn = n.sub_networks.obj['0']
sn.calculate_PTDF()
sn.branches()
pd.DataFrame(sn.PTDF, index = sn.branches_i(), columns = sn.buses_o)
 
Tom

Reply all
Reply to author
Forward
0 new messages