DC power flow analysis for power systems. Use when computing power flows using DC approximation, building susceptance matrices, calculating line flows and loading percentages, or performing sensitivity analysis on transmission networks.
name dc-power-flow description DC power flow analysis for power systems. Use when computing power flows using DC approximation, building susceptance matrices, calculating line flows and loading percentages, or performing sensitivity analysis on transmission networks. DC Power Flow DC power flow is a linearized approximation of AC power flow, suitable for economic dispatch and contingency analysis. DC Approximations Lossless lines
bus_num_to_idx = { int (buses[i, 0 ]): i for i in range (n_bus)}
f = bus_num_to_idx[ int (br[ 0 ])]
t = bus_num_to_idx[ int (br[ 1 ])] Susceptance Matrix (B) Build from branch reactances using bus number mapping:
bus_num_to_idx = { int (buses[i, 0 ]): i for i in range (n_bus)} B = np.zeros((n_bus, n_bus)) for br in branches: f = bus_num_to_idx[ int (br[ 0 ])]
t = bus_num_to_idx[ int (br[ 1 ])] x = br[ 3 ]
if x != 0 : b = 1.0 / x B[f, f] += b B[t, t] += b B[f, t] -= b B[t, f] -= b Power Balance Equation At each bus: Pg - Pd = B[i, :] @ θ Where: Pg = generation at bus (pu) Pd = load at bus (pu) θ = vector of bus angles (radians) Slack Bus One bus must have θ = 0 as reference. Find slack bus (type=3): slack_idx = None for i in range (n_bus): if buses[i, 1 ] == 3 : slack_idx = i break constraints.append(theta[slack_idx] == 0 ) Line Flow Calculation Flow on branch from bus f to bus t (use bus number mapping): f = bus_num_to_idx[ int (br[ 0 ])] t = bus_num_to_idx[ int (br[ 1 ])] b = 1.0 / br[ 3 ]
flow_pu = b * (theta[f] - theta[t]) flow_MW = flow_pu * baseMVA Line Loading Percentage loading_pct = abs (flow_MW) / rating_MW * 100 Where rating_MW = branch[5] (RATE_A column). Branch Susceptances for Constraints Store susceptances when building constraints: branch_susceptances = [] for br in branches: x = br[ 3 ] b = 1.0 / x if x != 0 else 0 branch_susceptances.append(b) Line Flow Limits (for OPF) Enforce thermal limits as linear constraints:
flow = b * (theta[f] - theta[t]) * baseMVA constraints.append(flow <= rate) constraints.append(flow >= -rate)