# Grid dynamics

About a month ago I sat down and attempted to write down equations which govern grid dynamics. That is, how power comes out of the wall. Why is another story, but it turned out to be quite complicated. Additionally, I never found a concise explanation online so I have decided to write this blog in case any other traveler in cyberspace needs to know the physics or mathematics of the electrical grid.

First I will signpost all the different parts, then give plain English explanations, then equations. If the stars align I may eventually provide a github repo with a basic demo.

Like in any electrical circuit, currents are more or less instant responses to voltages, so we need a mechanism to solve for currents. Then we need to compute the time dependent aspects, which fall into passive and active components.

I just found out WordPress supports $\LaTeX$ so hold on to your hat.

## Oh My God, It’s So Parallel

The counterintuitive thing about the grid is that everything is extremely parallel. On the load (consumer) side, adding a load to the grid reduces its total resistance. That is, plugging in a toaster adds another path from active to neutral, reducing the overall resistance of the grid.

The grid is full of transformers so that less power is lost in transmission, but for the purposes of this analysis I’m going to pretend that generation, transmission, and load all occurs at the same voltage and that wires have no resistance at all. This is a safe assumption for the dynamics I’m attempting to capture, provided we pick sensible values for load resistance and inductance.

To get a feeling for how grid resistance works in practice, consider a 100W light bulb. Operating at 110V (RMS), this bulb has a resistance of about 100 $\Omega$, which is quite a lot! Now consider the power grid of a small town, which consumes a peak of 500MW. The effective resistance of that grid is V^2/P = 20 $\mu \Omega$, which is less than a lump of copper!

Electricity demand varies throughout the day, traditionally peaking in the late afternoon and falling in the early morning, often varying by a factor of two or three. Although individual consumers operating switches are discrete events, over a large area power demand, or effective grid resistance, is not only pretty continuous, it’s also very predictable. Traditionally, power has been dispatched a day in advance, with a blindingly fast 30 minute market for followup. In markets with lots of wind and solar this has become problematic, but only because of less predictable variations on the supply side, not the demand side.

The grid operates on AC power at ideally constant frequency and voltage. The effect of lowered grid resistance is higher current flow. Current flowing through the generator produces a dragging torque, which is overcome by (typically) a turbine or other prime mover. Operating a grid, then, is a delicate dance to match grid demand with turbine-generated torque, keeping voltage and frequency stable.

## Okay, Now Parallelize

This is all reasonably straight forward. In practice, however, most grids have more than one generator. My area of interest is in how dozens of different types of power plant coordinate and compete when connected to the same grid without breaking everything.

While the voltages produced by the generators are essentially a function of their rotation speed, the currents, which generate the drag force, need to be computed.

## Step One – Resolve Grid Currents

I will use a somewhat contrived example consisting of a series of $N$ generators in parallel. Each parallel string contains, in series, an AC voltage generator (function of frequency $\omega$ and phase $\phi$), an inductor $L$ and resistor $R$. One could add capacitors but the electrical grid is dominated by resistive and inductive elements.

Each string, labelled by numeral subscript $j$, generates a current $i_j$ defined to flow from neutral to active, i.e. upwards.

In order to solve for the $i_j$, we need a set of $N$ conditions. These are that the sum over the $i_j$ is zero, and that all the voltages are equal in complex amplitude at any given time. In this formulation, that means that this difference between any two voltages is also zero.

That is,

$\sigma_{j=1}^N i_j = 0,$

and

$v_i - v_j = 0,$

where

$v_i = \frac{w_i V_0}{w_0} e^{j (\omega_i t + \phi_i)} - j L_i \omega_i i_i - R_i i_i,$

or

$v_i = \varepsilon_i - X_i i_i,$

splitting the EMF and reactive components, and

$j^2 = -1.$

Fortunately, this can be expressed compactly in matrix form, e.g.

$\bf{A} . \bf{i} = \bf{v},$

where (alas we have reached the limits of WordPress’s $\LaTeX$ parser…)

$\bf{A} =$
$\left(\begin{array}{ccccc}1&1&1&\hdots&1\end{array}\right)$
$\left(\begin{array}{ccccc}X_1&-X_2&0&\hdots&0\end{array}\right)$
$\left(\begin{array}{ccccc}0&X_2&-X_3&\hdots&0\end{array}\right)$
$\left(\begin{array}{ccccc}\vdots&\vdots&\vdots&\ddots&\vdots\end{array}\right)$
$\left(\begin{array}{ccccc}0&0&0&\hdots&-X_N\end{array}\right),$

$\bf{i} = \left(\begin{array}{c}i_1\\ i_2\\i_3\\ \vdots\\i_N \end{array}\right),$

and

$\bf{v} =$
$\left(\begin{array}{c}0 \end{array}\right)$
$\left(\begin{array}{c}\varepsilon_1-\varepsilon_2 \end{array}\right)$
$\left(\begin{array}{c}\varepsilon_2-\varepsilon_3 \end{array}\right)$
$\left(\begin{array}{c}\vdots \end{array}\right)$
$\left(\begin{array}{c}\varepsilon_{N-1}-\varepsilon_N \end{array}\right).$

Note that A is nearly upper diagonal, meaning a solution is easily computed, if not trivial to typeset. The addition of a load to this formalism is trivial, if slightly inelegant – simply set the voltage contribution (or frequency, equivalently) of one of the generators to zero.

## Step Two – Compute Torque

With current in hand, it is a simple matter to compute the torque experienced by the generator’s armature and balanced by, eg, steam flowing through a turbine. I will employ the rotational version of $F = ma$.

$\tau = I \alpha,$

or torque equals moment of inertia times angular acceleration.

$\tau = \tau_T - i_i \bf{l} \times \bf{B},$

where $\tau_T$ is the turbine’s power, set by some sort of throttle or governor, and the drag term is due to Lorentz force. Practically speaking, the drag force is proportional to the current (which varies), the magnetic field in the generator (which is typically fixed if produced by permanent magnets) and geometric quantities, the most salient of which is the relative phase angle between the current and the magnetic field.

Consider the simplest example, that of a single wire loop rotating in a uniform magnetic field. The peak EMF coincides with the maximum change of flux, meaning that the current flow peaks coincide with the magnetic field peaks, maximizing drag. The inductive component of the circuit’s reactance, however, delays the current peak by some acute angle, slightly reducing the torque drag.

A full explanation of AC generators and phasor diagrams is beyond the scope of this blog, but here are a few YouTube videos I found that explain the basic concepts, and here is a website with a thorough explanation of the underlying theory.

In actual generators, current is generated in three phases carefully designed to provide constant drag force with armature angle, minimizing ripple.

The most important part of this section is showing how multiple generators operating in lockstep are generally stable.

Consider a special case where there are a large number of generators all in phase, and one small one that has somehow gotten out of phase by a small factor $\delta \phi$, perhaps due to a loss of steam. That is, the physical phase of its armature is $\delta \phi$ ahead or behind that of the other generators.

One consequence of solving the matrix equation in part one is that for many generators in parallel, the current that flows through them is the sum of the current contributions of every generator. That means that even though the troublesome generator is out of phase, the current it carried is still in phase, because the individual contribution of that generator is rather small in the grand scheme of things.

In words, an armature that has fallen behind has a greater angular mismatch between its coils and the peak magnetic field and experiences less torque, while one that has gotten ahead has a smaller angular mismatch between its coils and the peak magnetic field, and experiences greater torque. The consequence of this variation is that the perturbations are self-correcting and do not lead to growth.

Mathematically,

$I \alpha = \tau_T-i \bf{l} \times \bf{B},$
$I \alpha = \tau_T - i l B \cos(\phi),$
where
$\phi = \phi_0 + \delta \phi = -\arctan(\omega L/R) + \delta \phi.$

In the case where $\delta \phi = 0$, then $I \alpha = 0$, i.e. in steady state. The easiest way to analyze this is to take a Taylor expansion around $\phi_0$.

$I \alpha = \tau_T - i l B \cos(\phi_0+\delta \phi),$
$I \alpha = \tau_T - i l B (\cos(\phi_0) - \sin(\phi_0) \delta \phi),$
$I \alpha = i l B \sin(\phi_0) \delta \phi,$

which has the appropriate behavior provided $\phi_0$ is negative, that is, the circuit is dominated by inductive rather than capacitive loads.

In practice, a lack of inductance in the circuit reduces the amplitude of the correcting impulse, leading to slowed perturbation recovery and ultimately instability in the grid. Traditionally, some utilities have operated turbines well below capacity purely for inductive ballast. In the future, grid scale batteries can easily correct wobbles in real time.

Finally, a large perturbation will eventually overcome the region of stability and lead to severe problems – so physical generators in this situation will trip their breaker and disconnect from the circuit.

## Step Three – Droop Speed Control

With the above machinery we can calculate how a mass of parallel generators and loads generate currents, and how each individual generator physically provides the torque necessary to shove electrons down wires and vice versa. The only missing part of the picture is how the grid ramps up and down each day in response to demand.

This is performed using droop speed control. The Wikipedia article is a bit opaque so I’ll include a summary here.

Consider a single generator powering a load that slowly varies over time. If the load resistance decreases due to an addition of appliances to the grid, such as everyone turning on their television, then the current flowing through the grid increases. An increase in current increases the drag torque the generator experiences. This slows the armature and reduces the grid frequency.

In response to the reduction of frequency, the speed control on the generator increases power to the turbine, matching the drag torque with an addition of power. The same process works in reverse, when the load diminishes and the turbine’s powering torque is reduced.

Droop speed control dictates by what fraction power is altered to the generator as a function of frequency variation. Droop percentages of about 4% are conventional in the industry. This means that if the frequency decreases (droops) by 4%, then the governor will open to 100%. A more typical frequency reduction of, say, 0.01% will result in the governor opening by 0.25%.

Provided that all the generators in the grid are wired with this (or a very similar) proportionality constant, they will all respond to demand and frequency variation in the same way, ensuring that load is shared among generators of different sizes in accordance with their capacity.

## Conclusion

I believe that the physics captured above is adequate to describe the dynamics of large electrical grids at a granular level of detail. My intention in getting started on this was to build a agent-based model to simulate the behavior of grid participants in a world defined by these laws. This model also has a financial layer based on how utilities pay for generation services and price electricity. The grid is the single most complex and indispensable system ever built by humans, and after a half-century of business as usual it is now evolving rapidly as traditional fossil-fueled steam turbines are rapidly displaced by wind, solar, and batteries. What makes it interesting is that it all has to be backwards compatible and never turned off!