This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Notebooks · lib/power/contingency

N-1 contingency analysis by AC re-solves and DC distribution factors

A transmission network is planned to survive the loss of any one element (NERC TPL-001, category P1): with a line, a transformer or a generator out of service, every branch must stay within its emergency rating and every bus voltage within its emergency band. n1_ac checks that the slow way and the exact way: for each outage it takes the element out, solves the AC power flow again by Newton's method starting from the base-case voltages (a warm start, two or three iterations each), and lists every limit the solution breaks.

Each branch's loading is the larger of the apparent powers entering its two ends, |S| in MVA, held to rate A in the base case and rate B after an outage (MATPOWER's columns RATE_A and RATE_B; a rating of 0 is no limit). Voltages are held to [vmin, vmax] before and [vmin_post, vmax_post] after.

An outage that splits the network leaves the buses no longer joined to the reference bus without supply: they are taken out (type 4), with their loads and generators, and counted as islanded. A lost generator's power is made up by the reference bus's generator, as in a power flow; when the lost generator was the reference's, the first remaining PV bus takes over.

dc_factors gives the linear sensitivities of the DC model (MATPOWER's makePTDF and makeLODF):

  • PTDF[l, j]: the change in the flow of branch l per unit of power injected at bus j and withdrawn at the reference bus;
  • LODF[l, k]: the share of branch k's pre-outage flow that moves onto branch l when k is taken out, H[l, k] / (1 - H[k, k]) with H[l, k] = PTDF[l, f_k] - PTDF[l, t_k] (and -1 on the diagonal).

With them, dc_screen estimates every post-outage flow in one matrix product and flags the ones above a fraction of rate B, the screening that decides which outages earn a full AC solve. A branch whose outage islands part of the network has 1 - H[k, k] = 0; its LODF column is left at zero and the branch is reported as a bridge.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

This program declares a record type (Limits), and records run only in compiled C for now, so the Run buttons here are off. Open it in the workbench and use its C tab to compile it.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 41–573