Power Grid Simulator, Explained

After reading this you will understand why grid frequency drifts from 50 Hz, how the swing equation turns a generation surplus into a speed-up, and why one overloaded line can black out a country.

What the simulator does and one thing to watch first

You run a small national grid through 24 hours. Every minute, demand asks for a certain number of megawatts and you decide which plants supply it. The single number that tells you whether you are winning is the grid frequency. On a healthy European-style grid it sits at 50.00 Hz. If your plants make more power than the load draws, the grid speeds up above 50 Hz. If they make less, it slows down.

Here is the hook. Suppose load jumps from 2000 MW to 2100 MW when a heat wave switches on the air conditioning, and your generation stays at 2000 MW. That 100 MW deficit does not cause a blackout instantly. Instead the spinning turbines give up some of their rotational energy to cover the gap, and the frequency starts sliding down. On a grid with typical inertia, that slide is roughly 0.1 Hz per second. You have a few seconds to add 100 MW before protection relays at 49.2 Hz start disconnecting plants and making the deficit worse.

When this model helps and when it misleads

Use the simulator to build intuition for three real behaviors: merit-order dispatch, frequency as a running balance signal, and cascading line failures. These are the mechanics that decide whether the lights stay on, and they are hard to feel from equations alone.

Do not read the numbers as engineering truth. A real interconnection has thousands of buses, AC power flow with reactive power, voltage collapse, and governor droop curves tuned per plant. This model collapses the whole country into one frequency and a handful of lines. It is a teaching model, honest about direction and rough magnitude, wrong about the third decimal place.

Real operators do not chase frequency by hand. Automatic generation control adjusts plant output every few seconds. The manual dispatch here compresses that loop so you can see cause and effect on a human timescale.

The swing equation, the heartbeat of the grid

Frequency changes because rotating generators store kinetic energy. When generation and load disagree, that stored energy makes up the difference and the machines change speed. The relationship is the swing equation:

\frac{df}{dt} = \frac{f_0}{2 H \cdot S} \left( P_{gen} - P_{load} \right)

Here f is the grid frequency in Hz and f_0 = 50 Hz is the nominal value. P_{gen} and P_{load} are total generation and load in MW. S is the total rated capacity of spinning machines in MW, and H is the inertia constant in seconds, typically 4 to 6 s, which says how many seconds of full output the stored kinetic energy could supply.

The intuition is direct. The term P_{gen} - P_{load} is your power imbalance. Divide it by the inertia and you get a rate of change of frequency. More inertia (a bigger H \cdot S) means the same imbalance moves frequency more slowly, buying you time. That is exactly why grids with many wind and solar plants, which spin no heavy turbine, add synthetic inertia: without it, the same 100 MW error swings frequency two or three times faster.

Reproducing the demo: a 100 MW deficit

Run the demo with its default plants and let the morning ramp create a shortfall. Take a snapshot where load is 2100 MW, generation is 2000 MW, spinning capacity is S = 2500 MW, and inertia is H = 5 s.

  1. Compute the imbalance: P_{gen} - P_{load} = 2000 - 2100 = -100 MW.
  2. Compute the coefficient: \frac{f_0}{2 H S} = \frac{50}{2 \cdot 5 \cdot 2500} = \frac{50}{25000} = 0.002 Hz per MW per second.
  3. Multiply: \frac{df}{dt} = 0.002 \times (-100) = -0.2 Hz per second.
  4. Project forward: after 4 seconds with no action, frequency falls by 0.2 \times 4 = 0.8 Hz, from 50.0 to 49.2 Hz, the first relay threshold.

So you have about four seconds. Dispatch 100 MW of fast gas and the imbalance returns to zero, \frac{df}{dt} goes to 0, and frequency stops falling. It stays wherever it landed until you push a small surplus to climb back to 50 Hz.

Frequency falls at 0.2 Hz/s until the deficit is covered at second 8, then a small surplus walks it back to 50 Hz. The shaded band is below the 49.2 Hz relay line.

With H=5 s and S=2500 MW, a 100 MW deficit changes frequency at 0.2 Hz/s. Halving inertia to H=2.5 s doubles that rate to 0.4 Hz/s, so you hit the 49.2 Hz relay in 2 seconds instead of 4.

Merit order: why the cheap plants run flat out

You never dispatch plants randomly. You stack them by marginal cost, cheapest first, and fill demand from the bottom of the stack. This is the merit order, and it matches how real electricity markets clear.

A typical merit stack for the demo grid
Plant typeMarginal cost ($/MWh)Ramp speedRole
Nuclear10Very slowBaseload, runs flat
Wind / solar0Not controllableTake all available
Coal35SlowMid-merit
Hydro15FastFlexible balancing
Gas peaker80Very fastFills spikes

Renewables have zero fuel cost, so you take every megawatt they offer. Nuclear is cheap but cannot ramp, so it sits at a constant output all day. Gas peakers are expensive but respond in seconds, so you hold them in reserve for the morning ramp and for the moment a plant trips. If you cover a 100 MW spike with a peaker for one hour, that costs 100 \times 80 = 8000 dollars. Cover the same spike with hydro and it costs 100 \times 15 = 1500 dollars, but you spend a limited water reserve you may need later.

Cascading failure, the signature blackout

Transmission lines carry power between regions and each has a thermal limit. Push more than the limit and the line heats, sags, and trips offline to protect itself. The trouble is what happens next. The power that line carried does not vanish. It reroutes over the remaining lines, and if any of them was already near its limit, the extra load tips it over too.

Suppose three parallel corridors each carry 400 MW toward a city, with a limit of 500 MW each. Total flow is 1200 MW, comfortably under the 1500 MW combined capacity. Now corridor A trips. Its 400 MW splits over B and C, which now carry 600 MW each, over their 500 MW limit. B trips. Its 600 MW piles onto C, which fails instantly. In three steps the city is dark, and the whole sequence took less time than any operator could react. This is the mechanism behind the 2003 Northeast blackout that cut power to 55 million people.

The dangerous state is not a single overload. It is a grid running with no margin, where every line sits near its limit. A grid at 60% loading absorbs a trip. A grid at 95% loading turns one trip into a cascade. Keep headroom on your corridors even when it costs more to dispatch around them.

Each corridor's limit is 500 MW. Before the trip all three sit at 400 MW. After A trips, B and C jump to 600 MW, both over the limit, and the cascade continues.

Reading the day and keeping cost low

Two curves tell the story of a run: frequency over the day, and cumulative cost. A good run keeps frequency inside a tight band, roughly 49.9 to 50.1 Hz, with only brief excursions during ramps and trips. Deep dips toward 49.2 Hz mean you dispatched too slowly. Sustained flight above 50.1 Hz means you left too much generation online after demand fell.

Cost accumulates every minute as output times marginal cost. If your day totals 2000 MW average for 24 hours at a blended 25 dollars per MWh, that is 2000 \times 24 \times 25 = 1{,}200{,}000 dollars. Every hour you run a peaker unnecessarily adds thousands. The skill is meeting the same demand curve while keeping the expensive plants idle, using batteries to shift cheap night energy into the evening peak, and shedding load only as a genuine last resort because a blackout is the most expensive outcome of all.

Common mistakes

The first mistake is chasing frequency with baseload. When frequency dips you may be tempted to ramp coal or nuclear, but they respond over minutes. By the time they move, the relays have tripped. Use fast plants (hydro, gas, batteries) for the fast correction and slow plants for the steady trend.

The second is running with no reserve. If your generation exactly equals load, the next plant trip has nothing to cover it. Hold spinning reserve equal to your largest single plant, so losing that plant does not immediately swing frequency.

The third is ignoring line headroom while celebrating a cheap dispatch. The cheapest dispatch often routes maximum power over the cheapest corridor, leaving it near its limit. That saves dollars until the first contingency turns it into a cascade.

Related simulators

If you want to see where the electricity actually flows, the Circuit Simulator builds the analog picture at the component level with batteries, resistors and capacitors. For the plant behind the baseload, the Nuclear Reactor Simulator shows why a reactor cannot ramp quickly, with control rods and xenon poisoning. For another dispatch problem where you allocate limited fast resources against a spiky demand pattern, try the Elevator Dispatch Simulator, which is the same scheduling idea in a building. And the Bridge Builder & Truss Simulator shows the same "one member fails, load reroutes, neighbor fails" cascade in a mechanical structure.

Frequently asked questions

Why is 50 Hz the target instead of some other number?

It is a historical standard, chosen so that synchronous clocks and motors run at the right speed. North America uses 60 Hz. The exact value matters less than holding it steady: every clock, motor and synchronized generator on the grid depends on it staying near constant.

Why does adding renewables make frequency harder to control?

Wind and solar connect through power electronics and spin no heavy turbine, so they add no natural inertia. With less inertia the term 2 H S in the swing equation shrinks, so the same imbalance moves frequency faster. Halving inertia doubles the rate of frequency change, cutting your reaction time in half.

What does load shedding actually do?

It disconnects blocks of customers to cut P_{load} instantly. If you are 200 MW short and cannot ramp fast enough, shedding 200 MW of load rebalances the equation and stops the frequency slide. It is a controlled partial blackout used to prevent a total one.

Can a battery replace a peaker plant?

For the fast frequency correction, yes and better: a battery responds in milliseconds and can both absorb surplus and cover deficits. Its limit is energy, not power. A 100 MW battery with two hours of storage covers a 100 MW gap for two hours, then it is empty. A gas peaker runs as long as you feed it fuel.

Is the single-frequency model realistic?

It captures the whole-system average well, which is what governs the overall balance. It misses regional frequency differences during a fault and it ignores voltage and reactive power entirely. Treat the frequency number as the grid-wide average, accurate in direction and rough magnitude.