TExcelTAD

Gauss–Seidel Load Flow

The load-flow equations are nonlinear because loads and generators are given as powers. The oldest practical way to solve them, used on the first digital computers in the 1950s, is to guess every voltage and then sweep through the buses, correcting one voltage at a time with the latest values of its neighbours. That is the Gauss–Seidel method (Jacobi and Gauss–Seidel Iteration) applied to S=VI∗S = VI^*. It is simple, needs almost no memory, and still serves as a teaching method and as a starter for Newton–Raphson; its weakness is slow convergence on large systems.

Safety. The network is a 132 kV132\ \text{kV} system, so this lesson is calculation and simulation only. The bench analogue at the end is a 12 V12\ \text{V} resistor grid on a current-limited supply.

The update for a PQ bus

From Si∗=Vi∗∑kYikVkS_i^* = \mathbf{V}_i^* \sum_k Y_{ik}\mathbf{V}_k, solve for the term with Vi\mathbf{V}_i:

Vi←1Yii(Pi−jQiVi∗−∑k≠iYikVk)\mathbf{V}_i \leftarrow \frac{1}{Y_{ii}}\left( \frac{P_i - jQ_i}{\mathbf{V}_i^*} - \sum_{k \ne i} Y_{ik}\mathbf{V}_k \right)

The right-hand side uses the newest voltages available: buses already updated in this sweep, old values for the rest. A flat start sets every unknown voltage to 1∠0∘ pu1\angle 0^\circ\ \text{pu} (PV buses at their setpoint), which is close to any normal operating point.

PV buses

At a PV bus, QiQ_i is unknown but ∣Vi∣\lvert V_i \rvert is fixed. Each sweep:

  1. compute Qi=−Im⁡(Vi∗∑kYikVk)Q_i = -\operatorname{Im}\left( \mathbf{V}_i^* \sum_k Y_{ik}\mathbf{V}_k \right) from the present voltages,
  2. update Vi\mathbf{V}_i with the formula above using that QiQ_i,
  3. keep the new angle but scale the magnitude back to the setpoint.

If QiQ_i goes beyond the generator's reactive limit, the generator can no longer hold its voltage: fix QiQ_i at the limit and treat the bus as a PQ bus from then on (a production program also checks whether it can switch back later).

Acceleration

The plain update often creeps towards the solution. Over-relaxation takes a larger step, Vi←Vi+α (ViGS−Vi)\mathbf{V}_i \leftarrow \mathbf{V}_i + \alpha\,(\mathbf{V}_i^\text{GS} - \mathbf{V}_i) with an acceleration factor α\alpha between 1 and 2. Textbooks often quote α≈1.6\alpha \approx 1.6 for large systems, but the best value depends on the network: for N4 it is about 1.21.2 to 1.31.3 (11 sweeps at 1.21.2, 9 at 1.251.25), and 1.81.8 is much worse than no acceleration at all. The number of iterations of Gauss–Seidel grows roughly in proportion to the number of buses, which is why Newton–Raphson replaced it for real grids.

Worked example: the first sweep by hand

Given: N4 (The Load-Flow Problem), flat start V=(1.04, 1.02, 1, 1) pu\mathbf{V} = (1.04,\ 1.02,\ 1,\ 1)\ \text{pu}, α=1\alpha = 1.

Find: the first estimates of Q2Q_2, V2\mathbf{V}_2 and V3\mathbf{V}_3.

Solve: with Y21=−3.846+j19.231Y_{21} = -3.846 + j19.231, Y22=10.709−j46.617Y_{22} = 10.709 - j46.617 and the other entries from the Y-bus, the current injected at bus 2 at the flat start is ∑kY2kVk\sum_k Y_{2k}\mathbf{V}_k, and

Q2=−Im⁡(V2∗∑kY2kVk)=0.1001 puV2←1.0198+j0.0187=1.02∠1.05∘ pu(magnitude reset to 1.02)V3←1Y33(−1.5+j0.61−Y31(1.04)−Y32V2−Y34(1))=0.9982−j0.0271 pu\begin{aligned} Q_2 &= -\operatorname{Im}\left( \mathbf{V}_2^* \sum_k Y_{2k}\mathbf{V}_k \right) = 0.1001\ \text{pu} \\ \mathbf{V}_2 &\leftarrow 1.0198 + j0.0187 = 1.02\angle 1.05^\circ\ \text{pu} \quad (\text{magnitude reset to } 1.02) \\ \mathbf{V}_3 &\leftarrow \frac{1}{Y_{33}}\left( \frac{-1.5 + j0.6}{1} - Y_{31}(1.04) - Y_{32}\mathbf{V}_2 - Y_{34}(1) \right) = 0.9982 - j0.0271\ \text{pu} \end{aligned}

Check: bus 3 drops below 1 pu1\ \text{pu} and lags, as a load bus should. Bus 2's angle starts positive and only turns negative over later sweeps, once the loads at buses 3 and 4 have pulled their angles down: Gauss–Seidel moves information one neighbour per sweep, which is why it is slow. The converged values are in the program's output: ∣V3∣=0.9916\lvert V_3 \rvert = 0.9916, θ3=−3.791∘\theta_3 = -3.791^\circ.

In Python: Gauss–Seidel with PV buses, acceleration and a QQ limit

python · try it yourself
import numpy as np
import matplotlib.pyplot as plt

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

P = np.array([0.0, 1.0, -1.5, -1.0])     # specified injections (pu); bus 1 = slack
Qs = np.array([0.0, 0.0, -0.6, -0.4])
pv = {1: 1.02}                           # bus index (0-based): voltage setpoint

def gauss_seidel(alpha=1.0, qmax=None, tol=1e-6, maxit=500, hist=None):
    V = np.array([1.04, 1.02, 1.0, 1.0], dtype=complex)    # flat start
    Q = Qs.copy()
    is_pv = dict(pv)
    for it in range(1, maxit + 1):
        dmax = 0.0
        for i in range(1, n):
            if i in is_pv:                                  # PV bus: Q from the present voltages
                Q[i] = -np.imag(np.conj(V[i]) * (Y[i] @ V))
                if qmax is not None and Q[i] > qmax:        # limit hit: becomes a PQ bus
                    Q[i] = qmax
                    del is_pv[i]
            sigma = Y[i] @ V - Y[i, i] * V[i]
            Vgs = ((P[i] - 1j * Q[i]) / np.conj(V[i]) - sigma) / Y[i, i]
            Vnew = V[i] + alpha * (Vgs - V[i])
            if i in is_pv:
                Vnew *= is_pv[i] / abs(Vnew)                # hold |V| at the setpoint
            dmax = max(dmax, abs(Vnew - V[i]))
            V[i] = Vnew
        if hist is not None:
            hist.append(dmax)
        if dmax < tol:
            return V, Q, it
    return V, Q, maxit

for a in [1.0, 1.2, 1.4, 1.6, 1.8]:
    V, Q, it = gauss_seidel(alpha=a)
    print(f"alpha = {a:.1f}: converged in {it:3d} iterations")

V, Q, it = gauss_seidel(alpha=1.2)
S = V * np.conj(Y @ V)
for i in range(n):
    print(f"bus {i+1}: |V| = {abs(V[i]):.4f} pu, angle = {np.degrees(np.angle(V[i])):7.3f} deg")
print(f"slack: P = {S[0].real:.4f}, Q = {S[0].imag:.4f} pu; bus 2 Q = {S[1].imag:.4f} pu; losses {S.real.sum():.4f} pu")

V, Q, it = gauss_seidel(alpha=1.2, qmax=0.25)
print(f"with Q2 <= 0.25 pu: bus 2 is PQ, |V2| = {abs(V[1]):.4f}, |V3| = {abs(V[2]):.4f}, |V4| = {abs(V[3]):.4f} pu")

for a in [1.0, 1.2, 1.6]:
    h = []
    gauss_seidel(alpha=a, hist=h)
    plt.semilogy(range(1, len(h) + 1), h, marker="o", ms=3, label=f"alpha = {a}")
plt.xlabel("iteration"); plt.ylabel("largest voltage change (pu)")
plt.title("Gauss-Seidel on N4"); plt.legend(); plt.grid(True, which="both", alpha=0.3)
plt.show()
alpha = 1.0: converged in  19 iterations
alpha = 1.2: converged in  11 iterations
alpha = 1.4: converged in  13 iterations
alpha = 1.6: converged in  23 iterations
alpha = 1.8: converged in  54 iterations
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
slack: P = 1.5504, Q = 0.6731 pu; bus 2 Q = 0.2897 pu; losses 0.0504 pu
with Q2 <= 0.25 pu: bus 2 is PQ, |V2| = 1.0186, |V3| = 0.9907, |V4| = 0.9780 pu

At α=1.2\alpha = 1.2 the method converges (largest change below 10−6 pu10^{-6}\ \text{pu}) in 11 sweeps. The slack generator supplies 155.0 MW155.0\ \text{MW} and 67.3 Mvar67.3\ \text{Mvar}, bus 2 produces 29.0 Mvar29.0\ \text{Mvar} to hold its 1.02 pu1.02\ \text{pu}, and the lines lose 5.04 MW5.04\ \text{MW}. If bus 2's generator can give only 25 Mvar25\ \text{Mvar}, its voltage falls to 1.0186 pu1.0186\ \text{pu} and every load bus sags a little with it. The plot shows the convergence: nearly a straight line on the log scale (linear convergence, a constant factor per sweep), steepest for α=1.2\alpha = 1.2.

Guided lab: iterate a resistor grid by hand

Hand calculation. The DC resistor grid of the previous lesson (12 V12\ \text{V} at node 1; 5050, 8080, 6060, 8080, 100 Ω100\ \Omega for lines 1–2, 1–3, 2–3, 2–4, 3–4; loads 240 Ω240\ \Omega at node 3 and 360 Ω360\ \Omega at node 4) is the linear version of the same problem: Vi←−∑k≠iGikVk/GiiV_i \leftarrow -\sum_{k \ne i} G_{ik}V_k/G_{ii}. Starting from 12 V12\ \text{V} everywhere, the first sweep gives V2=12.00V_2 = 12.00, V3=10.85V_3 = 10.85, V4=10.22 VV_4 = 10.22\ \text{V}, the second 11.1611.16, 10.1110.11, 9.52 V9.52\ \text{V}. Do these two sweeps by hand.

Simulation. Adapt the program (real conductances, no PV bus): it needs 15 sweeps to settle within 0.1 mV0.1\ \text{mV} at 10.35610.356, 9.4939.493 and 8.877 V8.877\ \text{V}, the values the netlist lab in the previous lesson shows.

What you would measure. On the breadboard grid (1 %1\ \% resistors, supply 12.0 V12.0\ \text{V}, current limit 100 mA100\ \text{mA}), a DMM reads the node voltages within about ±1 %\pm 1\ \%, i.e. ±0.1 V\pm 0.1\ \text{V}: the iteration's answer, not its intermediate sweeps, is what the circuit "computes" instantly. In a real control room, the equivalent check is comparing the load-flow result with SCADA measurements: VT and transducer chains are accurate to roughly 0.50.5 to 1 %1\ \%, and the mismatch is handled by the state estimator.

Hazards and safe setup. 12 V12\ \text{V} DC with a current limit; check resistor values before switching on, since a wrong low value across the supply overheats. The load resistors dissipate about 0.38 W0.38\ \text{W} (240 Ω240\ \Omega) and 0.22 W0.22\ \text{W} (360 Ω360\ \Omega): use 0.5 W0.5\ \text{W} or larger parts there (the line resistors stay below 0.1 W0.1\ \text{W}).

Pitfalls

  • Forgetting to reset the PV magnitude after each update: the bus then drifts like a PQ bus with QQ from the last sweep.
  • Using the conjugate wrongly. The update needs (P−jQ)/V∗(P - jQ)/\mathbf{V}^*.
  • Ignoring QQ limits. A generator that "holds" 1.02 pu1.02\ \text{pu} with more reactive power than it can produce is a fiction; the voltages it supports are optimistic.
  • Too much acceleration. Over-relaxation beyond the optimum slows convergence and can make it diverge.
  • A loose tolerance. A change below 10−3 pu10^{-3}\ \text{pu} per sweep does not mean the voltages are within 10−310^{-3} of the answer when convergence is slow; check the power mismatches at the end.

Practice

  1. Why does the slack bus never get updated?
  2. What is Q2Q_2 at the converged solution, and is the generator producing or absorbing reactive power?
  3. Gauss–Seidel takes 19 sweeps on N4 without acceleration. Roughly how would that scale for a 1000-bus network?
Answer
  1. Its voltage magnitude and angle are both specified; its PP and QQ are computed once at the end from the converged voltages.
  2. Q2=0.2897 pu=29.0 MvarQ_2 = 0.2897\ \text{pu} = 29.0\ \text{Mvar}, positive in the generator convention: it produces reactive power (over-excited).
  3. Roughly in proportion to the number of buses, so hundreds to thousands of sweeps; this is why Newton–Raphson, whose iteration count barely depends on size, took over.

Test yourself

In a Gauss–Seidel sweep, the update of bus ii uses…

  1. only the voltages from the previous sweep
  2. the newest available voltages, including those already updated in this sweep
  3. only the slack voltage
  4. the Jacobian matrix

At a PV bus, after computing the new complex voltage, the method…

  1. keeps it as is
  2. keeps its magnitude and resets the angle to zero
  3. keeps its angle and rescales the magnitude to the setpoint
  4. discards it

A generator at a PV bus reaches its reactive power limit. The load flow should…

  1. stop with an error
  2. fix QQ at the limit and treat the bus as PQ
  3. raise its voltage setpoint
  4. make it the slack bus

For N4, which acceleration factor converged fastest?

  1. 1.0
  2. 1.2
  3. 1.6
  4. 1.8