TExcelTAD

Newton–Raphson Load Flow

Gauss–Seidel needs 19 sweeps for N4 and hundreds to thousands for a real grid. Every industrial load-flow program today (and every optimal power flow, contingency analysis and state estimator built on it) uses Newton–Raphson instead: it linearises all the equations at once around the present guess and solves for the whole correction in one step. Its convergence is quadratic: the number of correct digits roughly doubles every iteration, and three to five iterations suffice whether the network has four buses or forty thousand.

Safety. The network is a 132 kV132\ \text{kV} system: calculation and simulation only. The bench analogue at the end uses a current-limited 12 V12\ \text{V} supply and an electronic load.

The method itself is in Newton's Method for Systems; here it is applied to the power-flow equations.

Mismatches and the Jacobian

Collect the unknowns in a vector x=(θ,∣V∣)x = (\theta, \lvert V \rvert): the angles of all PV and PQ buses and the magnitudes of the PQ buses. The mismatches are specified minus calculated powers:

ΔPi=Pisp−Pi(θ,∣V∣),ΔQi=Qisp−Qi(θ,∣V∣)\Delta P_i = P_i^\text{sp} - P_i(\theta, \lvert V \rvert), \qquad \Delta Q_i = Q_i^\text{sp} - Q_i(\theta, \lvert V \rvert)

with one ΔP\Delta P for every non-slack bus and one ΔQ\Delta Q for every PQ bus. Newton's step solves the linearised equations

[ΔPΔQ]=[J1J2J3J4][ΔθΔ∣V∣],J1=∂P∂θ, J2=∂P∂∣V∣, J3=∂Q∂θ, J4=∂Q∂∣V∣\begin{bmatrix} \Delta P \\ \Delta Q \end{bmatrix} = \begin{bmatrix} J_1 & J_2 \\ J_3 & J_4 \end{bmatrix} \begin{bmatrix} \Delta\theta \\ \Delta\lvert V \rvert \end{bmatrix}, \qquad J_1 = \frac{\partial P}{\partial \theta},\ J_2 = \frac{\partial P}{\partial \lvert V \rvert},\ J_3 = \frac{\partial Q}{\partial \theta},\ J_4 = \frac{\partial Q}{\partial \lvert V \rvert}

and updates θ←θ+Δθ\theta \leftarrow \theta + \Delta\theta, ∣V∣←∣V∣+Δ∣V∣\lvert V \rvert \leftarrow \lvert V \rvert + \Delta\lvert V \rvert. From the polar power equations, with θik=θi−θk\theta_{ik} = \theta_i - \theta_k, the off-diagonal elements (i≠ki \ne k) are

∂Pi∂θk=∣ViVk∣(Giksin⁡θik−Bikcos⁡θik),∂Pi∂∣Vk∣=∣Vi∣(Gikcos⁡θik+Biksin⁡θik)∂Qi∂θk=−∣ViVk∣(Gikcos⁡θik+Biksin⁡θik),∂Qi∂∣Vk∣=∣Vi∣(Giksin⁡θik−Bikcos⁡θik)\begin{aligned} \frac{\partial P_i}{\partial \theta_k} &= \lvert V_i V_k \rvert \left( G_{ik}\sin\theta_{ik} - B_{ik}\cos\theta_{ik} \right), & \frac{\partial P_i}{\partial \lvert V_k \rvert} &= \lvert V_i \rvert \left( G_{ik}\cos\theta_{ik} + B_{ik}\sin\theta_{ik} \right) \\ \frac{\partial Q_i}{\partial \theta_k} &= -\lvert V_i V_k \rvert \left( G_{ik}\cos\theta_{ik} + B_{ik}\sin\theta_{ik} \right), & \frac{\partial Q_i}{\partial \lvert V_k \rvert} &= \lvert V_i \rvert \left( G_{ik}\sin\theta_{ik} - B_{ik}\cos\theta_{ik} \right) \end{aligned}

and the diagonal elements can be written neatly with the calculated injections:

∂Pi∂θi=−Qi−Bii∣Vi∣2,∂Pi∂∣Vi∣=Pi∣Vi∣+Gii∣Vi∣,∂Qi∂θi=Pi−Gii∣Vi∣2,∂Qi∂∣Vi∣=Qi∣Vi∣−Bii∣Vi∣\frac{\partial P_i}{\partial \theta_i} = -Q_i - B_{ii}\lvert V_i \rvert^2, \quad \frac{\partial P_i}{\partial \lvert V_i \rvert} = \frac{P_i}{\lvert V_i \rvert} + G_{ii}\lvert V_i \rvert, \quad \frac{\partial Q_i}{\partial \theta_i} = P_i - G_{ii}\lvert V_i \rvert^2, \quad \frac{\partial Q_i}{\partial \lvert V_i \rvert} = \frac{Q_i}{\lvert V_i \rvert} - B_{ii}\lvert V_i \rvert

The Jacobian has the same sparsity as Ybus\mathbf{Y}_\text{bus}, so sparse LU factorisation keeps each iteration cheap. On transmission networks J1J_1 and J4J_4 dominate (because B≫GB \gg G and angles are small): PP depends on angles, QQ on magnitudes, the coupling the reactive-power lesson found. Dropping J2J_2 and J3J_3 and freezing the rest gives the fast decoupled load flow (Stott and Alsac, 1974), which needs a few more iterations but factorises its matrices only once.

Worked example: one diagonal element by hand

Given: N4 at the flat start (∣V∣=1.04,1.02,1,1\lvert V \rvert = 1.04, 1.02, 1, 1, all angles 0), Y33=9.216−j36.788 puY_{33} = 9.216 - j36.788\ \text{pu}.

Find: the calculated Q3Q_3 and the Jacobian element ∂P3/∂θ3\partial P_3/\partial\theta_3.

Solve: at the flat start all angles are zero, so Q3=−∣V3∣∑k∣Vk∣B3k=−(11.765⋅1.04+15.686⋅1.02+9.412⋅1−36.788⋅1)Q_3 = -\lvert V_3 \rvert \sum_k \lvert V_k \rvert B_{3k} = -(11.765 \cdot 1.04 + 15.686 \cdot 1.02 + 9.412 \cdot 1 - 36.788 \cdot 1):

Q3=−(12.235+16.000+9.412−36.788)=−0.859 pu∂P3∂θ3=−Q3−B33∣V3∣2=0.859+36.788=37.647 pu/rad\begin{aligned} Q_3 &= -(12.235 + 16.000 + 9.412 - 36.788) = -0.859\ \text{pu} \\ \frac{\partial P_3}{\partial \theta_3} &= -Q_3 - B_{33}\lvert V_3 \rvert^2 = 0.859 + 36.788 = 37.647\ \text{pu/rad} \end{aligned}

Check: the element is close to −B33=36.8-B_{33} = 36.8, the "short-circuit" susceptance at bus 3, as the DC load flow will assume. A positive ∂P3/∂θ3\partial P_3/\partial\theta_3 means advancing bus 3's angle pushes power out of the bus into the network. The calculated Q3Q_3 at the flat start is negative because the higher voltages at buses 1 and 2 already push reactive power into bus 3 through the lines.

In Python: Newton–Raphson with the analytic Jacobian

python · try it yourself
import numpy as np

lines = [(1, 2, 0.01, 0.05, 0.04), (1, 3, 0.02, 0.08, 0.05), (2, 3, 0.015, 0.06, 0.04),
         (2, 4, 0.02, 0.08, 0.05), (3, 4, 0.025, 0.10, 0.06)]
n = 4
Y = np.zeros((n, n), dtype=complex)
for i, k, r, x, b in lines:
    i, k = i - 1, k - 1
    y = 1 / complex(r, x)
    Y[i, i] += y + 0.5j * b; Y[k, k] += y + 0.5j * b
    Y[i, k] -= y; Y[k, i] -= y
G, B = Y.real, Y.imag

Psp = np.array([0.0, 1.0, -1.5, -1.0])     # specified injections, pu
Qsp = np.array([0.0, 0.0, -0.6, -0.4])
pv, pq = [1], [2, 3]                       # 0-based: bus 2 is PV, buses 3 and 4 PQ
ang = pv + pq                              # buses with unknown angle

def injections(Vm, th):
    V = Vm * np.exp(1j * th)
    S = V * np.conj(Y @ V)
    return S.real, S.imag

def jacobian(Vm, th):
    P, Q = injections(Vm, th)
    J1 = np.zeros((n, n)); J2 = np.zeros((n, n)); J3 = np.zeros((n, n)); J4 = np.zeros((n, n))
    for i in range(n):
        for k in range(n):
            t = th[i] - th[k]
            if i != k:
                J1[i, k] = Vm[i] * Vm[k] * (G[i, k] * np.sin(t) - B[i, k] * np.cos(t))   # dP/dtheta
                J2[i, k] = Vm[i] * (G[i, k] * np.cos(t) + B[i, k] * np.sin(t))           # dP/d|V|
                J3[i, k] = -Vm[i] * Vm[k] * (G[i, k] * np.cos(t) + B[i, k] * np.sin(t))  # dQ/dtheta
                J4[i, k] = Vm[i] * (G[i, k] * np.sin(t) - B[i, k] * np.cos(t))           # dQ/d|V|
        J1[i, i] = -Q[i] - B[i, i] * Vm[i] ** 2
        J2[i, i] = P[i] / Vm[i] + G[i, i] * Vm[i]
        J3[i, i] = P[i] - G[i, i] * Vm[i] ** 2
        J4[i, i] = Q[i] / Vm[i] - B[i, i] * Vm[i]
    return np.block([[J1[np.ix_(ang, ang)], J2[np.ix_(ang, pq)]],
                     [J3[np.ix_(pq, ang)], J4[np.ix_(pq, pq)]]])

Vm = np.array([1.04, 1.02, 1.0, 1.0])      # flat start
th = np.zeros(n)
for it in range(10):
    P, Q = injections(Vm, th)
    mis = np.r_[Psp[ang] - P[ang], Qsp[pq] - Q[pq]]
    print(f"iteration {it}: largest mismatch {np.abs(mis).max():.3e} pu")
    if np.abs(mis).max() < 1e-8:
        break
    dx = np.linalg.solve(jacobian(Vm, th), mis)
    th[ang] += dx[:len(ang)]
    Vm[pq] += dx[len(ang):]

for i in range(n):
    print(f"bus {i+1}: |V| = {Vm[i]:.4f} pu, angle {np.degrees(th[i]):7.3f} deg")

V = Vm * np.exp(1j * th)
print("line flows (sending end) and losses:")
total = 0
for i, k, r, x, b in lines:
    a, c = i - 1, k - 1
    y = 1 / complex(r, x)
    Iik = (V[a] - V[c]) * y + V[a] * 0.5j * b       # current leaving bus i into the line
    Iki = (V[c] - V[a]) * y + V[c] * 0.5j * b
    Sik, Ski = V[a] * np.conj(Iik), V[c] * np.conj(Iki)
    total += (Sik + Ski).real
    print(f"  {i}-{k}: {100*Sik.real:7.2f} MW {100*Sik.imag:+7.2f} Mvar, loss {100*(Sik+Ski).real:.2f} MW")
print(f"total losses {100*total:.2f} MW")
iteration 0: largest mismatch 1.304e+00 pu
iteration 1: largest mismatch 3.927e-02 pu
iteration 2: largest mismatch 8.504e-05 pu
iteration 3: largest mismatch 5.924e-10 pu
bus 1: |V| = 1.0400 pu, angle   0.000 deg
bus 2: |V| = 1.0200 pu, angle  -1.439 deg
bus 3: |V| = 0.9916 pu, angle  -3.791 deg
bus 4: |V| = 0.9792 pu, angle  -4.826 deg
line flows (sending end) and losses:
  1-2:   59.37 MW  +28.23 Mvar, loss 0.41 MW
  1-3:   95.67 MW  +39.07 Mvar, loss 2.02 MW
  2-3:   76.78 MW  +28.37 Mvar, loss 0.98 MW
  2-4:   82.17 MW  +31.03 Mvar, loss 1.52 MW
  3-4:   19.45 MW   +4.65 Mvar, loss 0.11 MW
total losses 5.04 MW

The mismatch falls from 1.31.3 to 4×10−24 \times 10^{-2}, 9×10−59 \times 10^{-5}, 6×10−106 \times 10^{-10}: the exponent roughly doubles each time, the signature of quadratic convergence. The answer is the one Gauss–Seidel found. The line table is the useful engineering output: line 1–3 carries 95.7 MW95.7\ \text{MW} and loses 2.0 MW2.0\ \text{MW}, the most of any line, so it would be the first candidate for reinforcement; line 3–4 is almost idle. The total loss, 5.04 MW5.04\ \text{MW} or 2 %2\ \% of the 250 MW250\ \text{MW} load, is what the slack generator supplies on top of its share.

Guided lab: a constant-power load on a DC grid

Hand calculation. Take the bench DC grid of the previous lessons (12 V12\ \text{V} at node 1; 5050, 8080, 6060, 8080, 100 Ω100\ \Omega lines; 360 Ω360\ \Omega at node 4) and replace the 240 Ω240\ \Omega at node 3 by a constant-power load of 0.4 W0.4\ \text{W}. Node 3's equation becomes ∑kG3kVk+0.4/V3=0\sum_k G_{3k}V_k + 0.4/V_3 = 0: nonlinear, like the AC load flow. Write the 3×33 \times 3 Jacobian (it is G\mathbf{G} with −0.4/V32-0.4/V_3^2 added to the node-3 diagonal).

Simulation. A ten-line NR program started from 12 V12\ \text{V} converges in 5 iterations to V2=10.29V_2 = 10.29, V3=9.36V_3 = 9.36, V4=8.79 VV_4 = 8.79\ \text{V}. Started from 1 V1\ \text{V} it finds a second, low-voltage solution: V3=1.75 VV_3 = 1.75\ \text{V}, with a large current at a small voltage. Both satisfy the equations; only the high-voltage one is a normal operating point. That second root is the seed of voltage collapse.

What you would measure. Set a bench electronic load to constant-power mode at 0.4 W0.4\ \text{W} (check its minimum operating voltage, typically about 1 V1\ \text{V}), supply 12.0 V12.0\ \text{V} with the current limit at 150 mA150\ \text{mA}. Expect node voltages within about ±1 %\pm 1\ \% of the prediction and a load current of 0.4/9.36=43 mA0.4/9.36 = 43\ \text{mA}. Load regulators settle in milliseconds; read after a second.

Hazards and safe setup. 12 V12\ \text{V} DC, current-limited, 1 %1\ \% resistors: 0.25 W0.25\ \text{W} parts for the lines (each below 0.1 W0.1\ \text{W}), 0.5 W0.5\ \text{W} for the 360 Ω360\ \Omega load, which dissipates about 0.21 W0.21\ \text{W}. Never turn the load's power setting up to the point where the voltage collapses with a supply that is not current-limited.

Pitfalls

  • Including the slack bus in the unknowns, or a ΔQ\Delta Q equation for a PV bus: the Jacobian becomes singular or wrong.
  • Degrees and radians. The Jacobian is per radian; convert only for printing.
  • Sign of the mismatch. Specified minus calculated, and +Δx+\Delta x; flipping one sign makes the iteration diverge.
  • Trusting the first converged answer. A flat start almost always reaches the normal solution, but near the loadability limit Newton–Raphson can converge to the low-voltage root or not at all.
  • Ignoring PV-bus QQ limits (as in Gauss–Seidel): check after convergence, switch to PQ, and repeat.

Practice

  1. How many equations and unknowns does N4's Newton–Raphson have? What would they be if bus 2 were a PQ bus?
  2. At the solution, which line carries the most reactive power, and why might bus 1's generator be the one supplying it?
  3. A 1000-bus system has 100 PV buses and one slack. What is the size of its Jacobian?
Answer
  1. Five: ΔP2,ΔP3,ΔP4,ΔQ3,ΔQ4\Delta P_2, \Delta P_3, \Delta P_4, \Delta Q_3, \Delta Q_4 for θ2,θ3,θ4,∣V3∣,∣V4∣\theta_2, \theta_3, \theta_4, \lvert V_3 \rvert, \lvert V_4 \rvert. With bus 2 as PQ, six (add ΔQ2\Delta Q_2 and ∣V2∣\lvert V_2 \rvert).
  2. Line 1–3 with 39.1 Mvar39.1\ \text{Mvar}: bus 1 has the highest voltage (1.04 pu1.04\ \text{pu}) and reactive power flows from high to low voltage, towards the biggest load at bus 3.
  3. 999999 angle unknowns plus 899899 magnitude unknowns: 1898×18981898 \times 1898, with only a few nonzeros per row.

Test yourself

Newton–Raphson load flow converges…

  1. linearly, like Gauss–Seidel
  2. quadratically near the solution: correct digits roughly double each iteration
  3. in exactly one iteration
  4. only for radial networks

Which Jacobian blocks dominate on a high-voltage transmission network?

  1. ∂P/∂θ\partial P/\partial\theta and ∂Q/∂∣V∣\partial Q/\partial\lvert V \rvert
  2. ∂P/∂∣V∣\partial P/\partial\lvert V \rvert and ∂Q/∂θ\partial Q/\partial\theta
  3. all are equal
  4. only ∂Q/∂θ\partial Q/\partial\theta

For a PV bus, the Newton–Raphson equations include…

  1. ΔP\Delta P and ΔQ\Delta Q
  2. only ΔP\Delta P (its angle is unknown, its magnitude is fixed)
  3. only ΔQ\Delta Q
  4. nothing

Why is the Jacobian cheap to factorise for a large grid?

  1. it is diagonal
  2. it has the sparsity pattern of the Y-bus
  3. it is always positive definite
  4. it is computed only once