Here, we are going to create a network with three nodes, three lines and one generator. We then solve the non-linear power flow using a Newton-Raphson.
import pypsa
import numpy as np
network = pypsa.Network()
Add three buses
n_buses = 3
for i in range(n_buses):
network.add("Bus", "My bus {}".format(i), v_nom=20.0)
network.buses
Add three lines in a ring
for i in range(n_buses):
network.add(
"Line",
"My line {}".format(i),
bus0="My bus {}".format(i),
bus1="My bus {}".format((i + 1) % n_buses),
x=0.1,
r=0.01,
)
network.lines
Add a generator at bus 0
network.add("Generator", "My gen", bus="My bus 0", p_set=100, control="PQ")
network.generators
network.generators.p_set
Add a load at bus 1
network.add("Load", "My load", bus="My bus 1", p_set=100)
network.loads
network.loads.p_set
Fix the reactive power of the load
network.loads.q_set = 100.0
Do a Newton-Raphson power flow
network.pf()
Alright, it converged! Now, what is the active power flow on the lines?
network.lines_t.p0
...and what are the voltage angles on the buses?
network.buses_t.v_ang * 180 / np.pi
...and their mangitudes?
network.buses_t.v_mag_pu