---
title: "Machine dynamics lab: dq simulation, run-up and short circuits"
heading: Simulating an induction motor in the dq frame and checking it against the equivalent circuit, the torque pulsations and run-up time of a direct-on-line start, a synchronous generator's short-circuit current with its DC offset, and the dq0 transformation's power invariance
eyebrow: S12 · Lesson 44 · Machine dynamics lab
xp: 60
---

::: hook
The equivalent circuits of lessons 20 to 24 describe machines in steady state. Starting a motor, or shorting a generator, is anything but: fluxes have to build or collapse, and the currents carry transients at line frequency and decaying offsets. The dq model of lesson 39 handles both. In this lab you'll write an induction motor's dq equations, check that they reproduce the equivalent circuit's torque exactly, then let the motor start from rest and watch its torque swing above the static breakdown value before it settles. You'll finish with a generator's short-circuit current and a check on the dq0 transformation itself.
:::

::: play
- The curve is a generator's phase-a short-circuit current in per unit after a fault at a voltage zero (α = 0), with lesson 40's reactances and time constants: subtransient and transient AC components plus a DC offset decaying with the armature time constant on the slider.
- The first peak, half a cycle in, nearly doubles the symmetrical subtransient peak.
- A shorter armature time constant lets the offset fade within a few cycles.
:::

```sim plot
view: graph
x: t = 0..0.2
y: i = -15..15
slider: T = 0.02..0.4 = 0.15
plot: sqrt(2)*((1/1.8 + (1/0.328 - 1/1.8)*exp(-t/1.2) + (1/0.189 - 1/0.328)*exp(-t/0.035))*cos(2*pi*60*t) - exp(-t/T)/0.189) | label: phase-a current, pu
```

::: predict
## Lesson 20's 460 V motor (4 poles, 0.1 kg·m² of inertia, no load) is switched straight onto the line. Its static breakdown torque is 446 N·m. What peak torque does it actually develop during the start?

- [ ] Never more than 446 N·m
- [x] About 520 N·m, in the first cycles
- [ ] About 146 N·m, its static starting torque
- [ ] About 2000 N·m

::: reveal
The static curve assumes the air-gap flux is already established and rotating. At switch-on it has to build, and the stator's transient currents make the torque oscillate at line frequency around its static value, swinging up to 521 N·m in the dq simulation of task 2. Shafts and couplings must be designed for these peaks, which for large motors can reach several times the rated torque.
:::
:::

::: nameit
## The induction machine in the stationary frame

With flux linkages as states and the rotor shorted (all rotor quantities referred to the stator), in a frame fixed to the stator:
$$\frac{d\psi_{qs}}{dt} = v_{qs} - R_si_{qs}, \qquad \frac{d\psi_{ds}}{dt} = v_{ds} - R_si_{ds}$$
$$\frac{d\psi_{qr}}{dt} = -R_ri_{qr} + \omega_r\psi_{dr}, \qquad \frac{d\psi_{dr}}{dt} = -R_ri_{dr} - \omega_r\psi_{qr}$$
with $\psi_s = L_si_s + L_mi_r$ and $\psi_r = L_ri_r + L_mi_s$ on each axis ($L_s = L_{ls} + L_m$, $L_r = L_{lr} + L_m$), so the currents follow from the fluxes by inverting a 2 × 2 matrix. The torque is $T_e = \frac32\frac P2(\psi_{ds}i_{qs} - \psi_{qs}i_{ds})$ and $J\,d\omega_m/dt = T_e - T_L$, with $\omega_r = \frac P2\omega_m$. A balanced supply of peak $\hat V$ is $v_{qs} = \hat V\cos\omega t$, $v_{ds} = -\hat V\sin\omega t$.

## The short-circuit current

From open circuit at 1 pu, the phase-a current after a fault at angle α is
$$i_a = \sqrt2\left[I_\text{ac}(t)\cos(\omega t + \alpha) - \frac{\cos\alpha}{X''_d}e^{-t/T_a}\right]$$
with $I_\text{ac}(t)$ the RMS envelope of lesson 40.

## Power in dq0

With the amplitude-invariant transformation, $v_ai_a + v_bi_b + v_ci_c = \frac32(v_di_d + v_qi_q) + 3v_0i_0$ at every instant.
:::

::: check
kind: python

## Write `im_torque_at_slip(s, T=1.0, dt=1e-4)`: simulate lesson 20's motor (460 V, 60 Hz, 4 poles, $R_s$ = 0.2, $R_r$ = 0.15, $X_{ls} = X_{lr}$ = 0.5, $X_m$ = 20 Ω) in the stationary dq frame with its rotor held at slip s, by RK4 from zero flux, and return the average torque over the last 0.2 s.

```python starter
def im_torque_at_slip(s, T=1.0, dt=1e-4):
    return 0.0
```

```python solution
import math

W = 2 * math.pi * 60
RS, RR = 0.2, 0.15
LLS = LLR = 0.5 / W
LM = 20 / W
LS, LR = LLS + LM, LLR + LM
PP = 2
VPK = 460 / math.sqrt(3) * math.sqrt(2)
DET = LS * LR - LM * LM

def derivs(t, x, wr, J=None, TL=0.0):
    qs, ds, qr, dr, wm = x
    if J is not None:
        wr = PP * wm
    iqs = (LR * qs - LM * qr) / DET
    ids = (LR * ds - LM * dr) / DET
    iqr = (LS * qr - LM * qs) / DET
    idr = (LS * dr - LM * ds) / DET
    te = 1.5 * PP * (ds * iqs - qs * ids)
    vqs, vds = VPK * math.cos(W * t), -VPK * math.sin(W * t)
    dwm = 0.0 if J is None else (te - TL) / J
    return [vqs - RS * iqs, vds - RS * ids, -RR * iqr + wr * dr, -RR * idr - wr * qr, dwm], te

def step(t, x, dt, wr, J=None):
    k1, te = derivs(t, x, wr, J)
    k2, _ = derivs(t + dt / 2, [a + dt / 2 * b for a, b in zip(x, k1)], wr, J)
    k3, _ = derivs(t + dt / 2, [a + dt / 2 * b for a, b in zip(x, k2)], wr, J)
    k4, _ = derivs(t + dt, [a + dt * b for a, b in zip(x, k3)], wr, J)
    return [a + dt / 6 * (b + 2 * c + 2 * d + e) for a, b, c, d, e in zip(x, k1, k2, k3, k4)], te

def im_torque_at_slip(s, T=1.0, dt=1e-4):
    x, t, acc, n = [0.0] * 5, 0.0, 0.0, 0
    for _ in range(int(round(T / dt))):
        x, te = step(t, x, dt, (1 - s) * W)
        t += dt
        if t > T - 0.2:
            acc += te
            n += 1
    return acc / n
```

```python tests
assert abs(im_torque_at_slip(0.02) - 133.28) < 0.05, "At 2% slip: 133.3 N·m, as the equivalent circuit says."
assert abs(im_torque_at_slip(0.149) - 445.85) < 0.1, "At the breakdown slip: 446 N·m."
```

::: right
Right. In steady state the dq model and the equivalent circuit are the same machine; the dq model also knows what happens in between.
:::
:::

::: check
kind: python

## Using the same model, write `free_start(J, dt=1e-4)`: start the motor from rest and zero flux with no load, and return (time to reach 95% of synchronous speed, peak torque during the run).

```python starter
def free_start(J, dt=1e-4):
    return 0.0, 0.0
```

```python solution
import math

W = 2 * math.pi * 60
RS, RR = 0.2, 0.15
LLS = LLR = 0.5 / W
LM = 20 / W
LS, LR = LLS + LM, LLR + LM
PP = 2
VPK = 460 / math.sqrt(3) * math.sqrt(2)
DET = LS * LR - LM * LM

def derivs(t, x, J):
    qs, ds, qr, dr, wm = x
    wr = PP * wm
    iqs = (LR * qs - LM * qr) / DET
    ids = (LR * ds - LM * dr) / DET
    iqr = (LS * qr - LM * qs) / DET
    idr = (LS * dr - LM * ds) / DET
    te = 1.5 * PP * (ds * iqs - qs * ids)
    vqs, vds = VPK * math.cos(W * t), -VPK * math.sin(W * t)
    return [vqs - RS * iqs, vds - RS * ids, -RR * iqr + wr * dr, -RR * idr - wr * qr, te / J], te

def free_start(J, dt=1e-4):
    x, t, peak = [0.0] * 5, 0.0, 0.0
    while PP * x[4] < 0.95 * W and t < 10:
        k1, te = derivs(t, x, J)
        k2, _ = derivs(t + dt / 2, [a + dt / 2 * b for a, b in zip(x, k1)], J)
        k3, _ = derivs(t + dt / 2, [a + dt / 2 * b for a, b in zip(x, k2)], J)
        k4, _ = derivs(t + dt, [a + dt * b for a, b in zip(x, k3)], J)
        x = [a + dt / 6 * (b + 2 * c + 2 * d + e) for a, b, c, d, e in zip(x, k1, k2, k3, k4)]
        t += dt
        peak = max(peak, te)
    return t, peak
```

```python tests
t, pk = free_start(0.1)
assert abs(t - 0.090) < 0.002, "95% of synchronous speed after 90 ms."
assert abs(pk - 520.8) < 2, "Peak torque 521 N·m, above the 446 N·m static breakdown."
t1, pk1 = free_start(1.0)
assert abs(t1 - 0.7745) < 0.005, "Ten times the inertia: 0.77 s."
```

::: right
Right. The static torque curve would predict 74 and 739 ms; the flux's build-up and the transients make the real start a little slower, most noticeably for a light rotor.
:::
:::

::: check
kind: python

## Write `short_circuit(t, Xd, Xd1, Xd2, Td1, Td2, Ta, f, alpha)`: the phase-a short-circuit current in per unit from 1 pu open circuit, and `first_peak(...)` with the same parameters: its largest magnitude in the first cycle, sampled every microsecond.

```python starter
def short_circuit(t, Xd, Xd1, Xd2, Td1, Td2, Ta, f, alpha):
    return 0.0

def first_peak(Xd, Xd1, Xd2, Td1, Td2, Ta, f, alpha):
    return 0.0
```

```python solution
import math

def short_circuit(t, Xd, Xd1, Xd2, Td1, Td2, Ta, f, alpha):
    w = 2 * math.pi * f
    env = 1 / Xd + (1 / Xd1 - 1 / Xd) * math.exp(-t / Td1) + (1 / Xd2 - 1 / Xd1) * math.exp(-t / Td2)
    return math.sqrt(2) * (env * math.cos(w * t + alpha) - math.cos(alpha) / Xd2 * math.exp(-t / Ta))

def first_peak(Xd, Xd1, Xd2, Td1, Td2, Ta, f, alpha):
    n = int(1e6 / f)
    return max(abs(short_circuit(k * 1e-6, Xd, Xd1, Xd2, Td1, Td2, Ta, f, alpha)) for k in range(n))
```

```python tests
import math
args = (1.8, 0.328, 0.189, 1.2, 0.035, 0.15, 60)
assert abs(first_peak(*args, 0.0) - 13.87) < 0.01, "Worst instant: 13.9 pu, about 8.2 ms in."
assert abs(short_circuit(0.0, *args, 0.0)) < 1e-9, "The current starts from zero."
assert first_peak(*args, math.pi / 2) < 8.0, "At the other extreme there's no offset: about the symmetrical peak."
```

::: right
Right. The instant of the fault decides the offset; breakers are rated for the worst case.
:::
:::

::: check
kind: python

## Write `dq0(a, b, c, theta)` (amplitude-invariant Park transformation, returning (d, q, 0)) and `power_abc_dq0(va, vb, vc, ia, ib, ic, theta)` returning the instantaneous power computed both ways.

```python starter
def dq0(a, b, c, theta):
    return a, b, c

def power_abc_dq0(va, vb, vc, ia, ib, ic, theta):
    return 0.0, 0.0
```

```python solution
import math

def dq0(a, b, c, theta):
    s = 2 * math.pi / 3
    d = 2 / 3 * (a * math.cos(theta) + b * math.cos(theta - s) + c * math.cos(theta + s))
    q = -2 / 3 * (a * math.sin(theta) + b * math.sin(theta - s) + c * math.sin(theta + s))
    z = (a + b + c) / 3
    return d, q, z

def power_abc_dq0(va, vb, vc, ia, ib, ic, theta):
    vd, vq, v0 = dq0(va, vb, vc, theta)
    i_d, iq, i0 = dq0(ia, ib, ic, theta)
    return va * ia + vb * ib + vc * ic, 1.5 * (vd * i_d + vq * iq) + 3 * v0 * i0
```

```python tests
import math
d, q, z = dq0(10, -5, -5, 0.0)
assert abs(d - 10) < 1e-12 and abs(q) < 1e-12 and abs(z) < 1e-12, "Lesson 39's example: d = 10, q = 0."
p1, p2 = power_abc_dq0(300, -120, -150, 12, -3, -2, 0.7)
assert abs(p1 - p2) < 1e-9, "Power is the same in both frames, with the 3/2 and 3 factors."
s = 2 * math.pi / 3
d2, q2, _ = dq0(math.cos(1.0), math.cos(1.0 - s), math.cos(1.0 + s), 1.0)
assert abs(d2 - 1) < 1e-12 and abs(q2) < 1e-12, "A balanced set seen from its own angle is a constant d value."
```

::: right
Right. The 3/2 factor is the price of keeping amplitudes unchanged; a power-invariant scaling would remove it.
:::
:::

::: explain
## Why does an induction motor's torque briefly exceed its static breakdown torque when it is switched onto the line?

::: model
The static torque–speed curve assumes the machine is in sinusoidal steady state, with its air-gap flux already rotating at full strength. At the instant of switching, the fluxes are zero and must build up, and since flux can't change instantly, the stator currents contain decaying DC components alongside the AC ones. Those DC components create a stationary field that interacts with the rotating one, producing a torque that oscillates at line frequency around the steady value and decays with the machine's electrical time constants. The peaks of that oscillation can exceed the breakdown torque, which is why shafts, couplings and driven equipment must be designed for the starting transient, not just the static curve.
:::
:::
