Newton-Raphson Power Flow¶
In this example, we are going to create a network with three nodes, three lines, one load, and one generator with given setpoints. We then solve the non-linear power flow equations using the Newton-Raphson method applied in n.pf().
In [ ]:
Copied!
import numpy as np
import pypsa
n = pypsa.Network()
N_BUSES = 3
import numpy as np
import pypsa
n = pypsa.Network()
N_BUSES = 3
Add three buses:
In [ ]:
Copied!
for i in range(N_BUSES):
n.add("Bus", f"My bus {i}", v_nom=20)
n.buses
for i in range(N_BUSES):
n.add("Bus", f"My bus {i}", v_nom=20)
n.buses
Add three lines in a ring
In [ ]:
Copied!
for i in range(N_BUSES):
n.add(
"Line",
f"My line {i}",
bus0=f"My bus {i}",
bus1=f"My bus {(i + 1) % N_BUSES}",
x=0.1,
r=0.01,
)
n.lines
for i in range(N_BUSES):
n.add(
"Line",
f"My line {i}",
bus0=f"My bus {i}",
bus1=f"My bus {(i + 1) % N_BUSES}",
x=0.1,
r=0.01,
)
n.lines
Add a generator at bus 0
In [ ]:
Copied!
n.add("Generator", "My gen", bus="My bus 0", p_set=100, control="PQ")
n.generators
n.add("Generator", "My gen", bus="My bus 0", p_set=100, control="PQ")
n.generators
Add a load at bus 1
In [ ]:
Copied!
n.add("Load", "My load", bus="My bus 1", p_set=100, q_set=100)
n.loads
n.add("Load", "My load", bus="My bus 1", p_set=100, q_set=100)
n.loads
Do a Newton-Raphson power flow
In [ ]:
Copied!
n.pf()
n.pf()
Alright, it converged! Now, what is the active power flow on the lines?
In [ ]:
Copied!
n.lines_t.p0
n.lines_t.p0
...and what are the voltage angles on the buses?
In [ ]:
Copied!
n.buses_t.v_ang * 180 / np.pi
n.buses_t.v_ang * 180 / np.pi
...and their mangitudes?
In [ ]:
Copied!
n.buses_t.v_mag_pu
n.buses_t.v_mag_pu