GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Automation and CI / ventus-grid-engine / proofs

Electrification Model Proof and 3 more files

A JavaScript module in the proofs folder of Ventus Grid Engine. It is built from the check step (`check`), the near step (`near`) and the throws step (`throws`).

695 lines of JavaScript from ventus-grid-engine, in 4 files. Topic: Automation and CI. Section 1873 of 2044.

Cut 2026-12-06T03:07:51+00:00. A copy for reading; the repository at the stated commit is the source.

In the State lines below, domain stage, users and canonical status are rule-based first approximations from code and path evidence (rules explore-agent-rules-v1), not observed facts: the rules.

In this section

  1. Electrical Distance Proof geodesy · ventus-grid-engine / proofs/electrical-distance.proof.mjs lines 1–148
  2. Electrification Demand Proof energy-data · ventus-grid-engine / proofs/electrification-demand.proof.mjs lines 1–189
  3. Electrification Model Proof other · ventus-grid-engine / proofs/electrification-model.proof.mjs lines 1–219
  4. Firm Capacity Proof energy-data · ventus-grid-engine / proofs/firm-capacity.proof.mjs lines 1–139

Electrical Distance Proof

A JavaScript module in the proofs folder of Ventus Grid Engine covering overhead lines (OHL) and transformers. It is built from the check step (`check`).

geodesyventus-grid-engine / proofs/electrical-distance.proof.mjs · lines 1–148 of 148 · Not reached from any entry point (candidate for review)

What it does
Defines check. Side effects: starts processes.
Why it exists in the grid workflow
Domain stage upstream_foresight (voltage levels 400kV, 132kV (all 132kV or above)): upstream engineering foresight over GB transmission and distribution topology (TSO/DNO, 132kV and above, the REPD pipeline, data centres), which Ventus Ltd states it models for foresight. Domain terms in the code: overhead lines (OHL), transformers, 400kV, 132kV.
Inputs & outputs
Voltage levels named: 400kV, 132kV.
What it achieves
How far a substation is in the network operator's own published circuits, not in kilometres. Its code works with 132 kV and 400 kV.
Why it matters
No other file in the estate was found to import it.
Application
ventus-grid-engine · proofs · JavaScript module
Uses
Network Topology (import), Electrical Distance (import)
Used by
none found
Produces
check
Defines here
check
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
ventus-grid-engine@ad566356a44e006682e956483d569f31ddbb9630 proofs/electrical-distance.proof.mjs:1-148 · blob e12aea1a1aea6e7a0b359381d9c31e36acaab7fb · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: unknown · effects: process · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: unreached_review
/* electrical-distance.proof.mjs — how far a substation is in the network
 * operator's own published circuits, not in kilometres. Two claims matter:
 *
 *   1. A genuine multi-hop path is found, shortest-first, over real hops.
 *   2. A circuit whose two ends carry different declared voltages is
 *      REFUSED unless it is a transformer — walking it would invent a
 *      voltage change the data never asserts.
 *
 * Uses the same COWL/DIDC/STRA/ISLE/PLCH fixture as
 * network-topology.proof.mjs, so a reader can cross-check both proofs
 * against one network.
 *
 * Run: node proofs/electrical-distance.proof.mjs
 */

import { ACCEPTS, index } from '../engine/network-topology.js';
import { between, within, schema, requires, NOT_A_DISTANCE, NOT_A_CAPACITY }
    from '../engine/electrical-distance.js';

const failures = [];
let passed = 0;
const check = (name, condition) => {
    if (condition) passed += 1;
    else failures.push(name);
};

const PRODUCT = {
    schema: ACCEPTS,
    sites: [
        { code: 'COWL', name: 'Cowley', transmission_owner: 'NGET', voltages_kv: [400, 132] },
        { code: 'DIDC', name: 'Didcot', transmission_owner: 'NGET', voltages_kv: [400] },
        { code: 'STRA', name: 'Strand', transmission_owner: 'NGET', voltages_kv: [400] },
        { code: 'ISLE', name: 'Isolated', transmission_owner: 'NGET', voltages_kv: [132] },
        { code: 'PLCH', name: 'Placeholder', transmission_owner: 'NGET', voltages_kv: [400] }
    ],
    nodes: [
        { node: 'COWL4', site_code: 'COWL', voltage_kv: 400, voltage_consistent_with_site: true },
        { node: 'COWL1', site_code: 'COWL', voltage_kv: 132, voltage_consistent_with_site: true },
        { node: 'DIDC4', site_code: 'DIDC', voltage_kv: 400, voltage_consistent_with_site: true },
        { node: 'STRA4', site_code: 'STRA', voltage_kv: 400, voltage_consistent_with_site: true },
        { node: 'ISLE1', site_code: 'ISLE', voltage_kv: 132, voltage_consistent_with_site: true },
        { node: 'PLCH4', site_code: 'PLCH', voltage_kv: 400, voltage_consistent_with_site: true }
    ],
    circuits: [
        { node_1: 'COWL4', node_2: 'DIDC4', circuit_type: 'OHL', transmission_owner: 'NGET',
          winter_mva: 1200, spring_mva: 1100, summer_mva: 900, autumn_mva: 1150,
          r_pct_100mva: 0.5, x_pct_100mva: 5, b_pct_100mva: 10, ohl_km: 20 },
        { node_1: 'DIDC4', node_2: 'STRA4', circuit_type: 'OHL', transmission_owner: 'NGET',
          winter_mva: 800, spring_mva: 750, summer_mva: 600, autumn_mva: 700, ohl_km: 15 },
        { node_1: 'COWL4', node_2: 'ISLE1', circuit_type: 'OHL', transmission_owner: 'NGET',
          winter_mva: 500, spring_mva: 480, summer_mva: 400, autumn_mva: 450 },
        { node_1: 'COWL4', node_2: 'PLCH4', circuit_type: 'OHL', transmission_owner: 'NGET',
          winter_mva: 9999, spring_mva: 100, summer_mva: 90, autumn_mva: 95 }
    ],
    transformers: [
        { node_1: 'COWL4', node_2: 'COWL1', rating_mva: 240, transmission_owner: 'NGET' }
    ],
    planned_changes: [
        { node_1: 'STRA4', node_2: 'FUTR1', year: 2029, status: 'proposed', asset: 'new circuit' }
    ]
};

const idx = index(PRODUCT);

/* ── Contract gates ───────────────────────────────────────────────────── */

check('between() and within() refuse an index that exposes no graph(), '
    + 'rather than throwing on a missing method',
    between({}, 'COWL', 'DIDC') === null && within({}, 'COWL') === null
    && between(null, 'COWL', 'DIDC') === null);

check('between() refuses an unknown site on either end',
    between(idx, 'NOWHERE', 'DIDC') === null && between(idx, 'COWL', 'NOWHERE') === null);

check('the module identifies itself and the graph schema it requires',
    schema === 'gridatlas.module.electrical-distance.v1'
    && requires === 'gridatlas.module.network-topology.graph.v1');

/* ── The real two-hop path: COWL -> DIDC -> STRA ─────────────────────────── */

const cowlToStra = between(idx, 'COWL', 'STRA');

check('the shortest published path from Cowley to Strand is two hops, via '
    + 'Didcot — this is a real breadth-first result on the fixture graph, '
    + 'not a fixed number asserted without reference to it',
    cowlToStra.reached === true && cowlToStra.hops === 2 && cowlToStra.path.length === 2);

check('the path visits Didcot in the middle, in the right direction',
    cowlToStra.path[0].from_node === 'COWL4' && cowlToStra.path[0].to_node === 'DIDC4'
    && cowlToStra.path[1].from_node === 'DIDC4' && cowlToStra.path[1].to_node === 'STRA4');

check('same-site queries are zero hops without a search',
    between(idx, 'COWL', 'Cowley').reached === true
    && between(idx, 'COWL', 'Cowley').hops === 0);

/* ── The refusal: a circuit cannot change voltage, only a transformer can ── */

check('the direct 400kV-132kV circuit from Cowley to Isolated is REFUSED, '
    + 'not walked — a circuit is not allowed to change declared voltage',
    cowlToStra.refusals.some(r => r.to_node === 'ISLE1' && r.kind === 'circuit'));

const cowlToIsle = between(idx, 'COWL', 'ISLE');
check('with the illegal circuit refused and no other published path, '
    + 'Isolated is UNREACHABLE from Cowley — the refusal is not silently '
    + 'routed around',
    cowlToIsle.reached === false && cowlToIsle.hops === null
    && cowlToIsle.refusals.length === 1 && cowlToIsle.refusals[0].to_node === 'ISLE1');

check('no impedance is summed anywhere in a returned path — R, X, B are '
    + 'carried per hop exactly as published, never combined into a total',
    cowlToStra.path.every(h => h.parameters_pct_100mva === null
        || (typeof h.parameters_pct_100mva === 'object' && !('total' in h.parameters_pct_100mva))));

/* ── within(): every site reached inside a hop budget ────────────────────── */

const within1 = within(idx, 'COWL', { hops: 1 });
check('within one hop of Cowley: Didcot and Placeholder, not Strand (two '
    + 'hops away) and not Isolated (refused)',
    within1.sites.map(s => s.code).sort().join(',') === 'DIDC,PLCH'
    && within1.refusals.some(r => r.to_node === 'ISLE1'));

const within2 = within(idx, 'COWL', { hops: 2 });
check('within two hops of Cowley: Strand now appears, at hop depth 2, '
    + 'while Didcot and Placeholder stay at depth 1',
    within2.sites.find(s => s.code === 'STRA').hops === 2
    && within2.sites.find(s => s.code === 'DIDC').hops === 1
    && within2.counts.by_hop['1'] === 2 && within2.counts.by_hop['2'] === 1);

check('an unknown site returns null from within(), not an empty-but-real '
    + 'looking result',
    within(idx, 'NOWHERE') === null);

/* ── The module never claims to be a distance or a spare capacity ───────── */

check('the module states plainly, in its own exported strings, that a hop '
    + 'count is not a kilometre distance and a path is not a spare-capacity '
    + 'claim',
    /not a distance/i.test(NOT_A_DISTANCE) && /not.*flow|spare|capacity/i.test(NOT_A_CAPACITY));

/* ── Report ─────────────────────────────────────────────────────────────── */

if (failures.length) {
    console.error('electrical-distance proof FAILED (' + failures.length + ' of '
        + (failures.length + passed) + '):\n- ' + failures.join('\n- '));
    process.exit(1);
}
console.log('electrical-distance proof PASS — ' + passed + ' checks');
export default { status: 'PASS', checks: passed };

Electrification Demand Proof

A JavaScript module in the proofs folder of Ventus Grid Engine. It is built from the check step (`check`), the near step (`near`) and the throws step (`throws`).

energy-dataventus-grid-engine / proofs/electrification-demand.proof.mjs · lines 1–189 of 189 · Not reached from any entry point (candidate for review) · pattern throws (shared by 12 files)

What it does
It lists and searches its content. Defines check, near, throws. Side effects: starts processes.
What it achieves
The arithmetic of electrification, checked against the worked examples in the paper it implements, against the definitions it claims to be exact, and against the errors it exists to make impossible. Its code works with 1 GW, 109.6 GW and 120 GW.
Why it matters
No other file in the estate was found to import it.
Application
ventus-grid-engine · proofs · JavaScript module
Uses
Electrification Demand (import)
Used by
mentioned in Standalone (comment link)
Produces
check, near, throws
Defines here
check, near, throws
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
ventus-grid-engine@ad566356a44e006682e956483d569f31ddbb9630 proofs/electrification-demand.proof.mjs:1-189 · blob ba6217c6b0cd641230542b9444e9157086fdde52 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: unknown · effects: process · domain stage: unknown · users: none · canonical: duplicate_candidate
/* electrification-demand.proof.mjs — the arithmetic of electrification,
 * checked against the worked examples in the paper it implements, against the
 * definitions it claims to be exact, and against the errors it exists to make
 * impossible.
 *
 * Three kinds of check here, in order of what they are worth:
 *
 *   1. Identity. Where a relation is a definition, the round trip must return
 *      the input. These cannot drift; if one fails, the arithmetic is wrong.
 *   2. Worked examples. Every figure in the paper is recomputed. If the module
 *      and the paper disagree, one of them is wrong and both are published.
 *   3. Refusals. The functions that must NOT exist, and the inputs that must
 *      be rejected. A percentage passed where a fraction is required is the
 *      error most likely to reach a published number quietly.
 *
 * Run: node proofs/electrification-demand.proof.mjs
 */

import * as mod from '../engine/electrification-demand.js';
const {
    schema, HOURS_PER_YEAR, HOURS_TWH_TO_GW, NOT_COMPUTED,
    averagePowerGw, peakFromLoadFactorGw, loadFactorFromPeak,
    nameplateFromCapacityFactorGw, electricityForDisplacedFuelTwh
} = mod;

const failures = [];
let passed = 0;
const check = (name, condition) => {
    if (condition) passed += 1;
    else failures.push(name);
};
/* Compared to a tolerance because the paper rounds its published figures for
   reading. The tolerance is stated per check rather than global, so a loose
   one cannot hide behind a tight one. */
const near = (a, b, tol) => Math.abs(a - b) <= tol;
const throws = (fn, pattern) => {
    try { fn(); return false; } catch (e) { return pattern.test(e.message); }
};

/* ── 1. Definitions. These are exact. ───────────────────────────────────── */

check('a year is 8,760 hours and the TWh->GW divisor follows from it',
    HOURS_PER_YEAR === 8760 && HOURS_TWH_TO_GW === 8.76);

check('schema is declared',
    schema === 'ventus-grid-engine.electrification-demand.v1');

/* 8.76 TWh is exactly 1 GW held for a year. If this is not exact, nothing
   below can be trusted. */
check('8.76 TWh a year is exactly 1 GW average',
    averagePowerGw({ annualTwh: 8.76 }).value === 1);

/* Round trip: average -> peak at a load factor -> load factor back. */
{
    const avg = averagePowerGw({ annualTwh: 480 }).value;
    const peak = peakFromLoadFactorGw({ averageGw: avg, loadFactor: 0.6 }).value;
    const lf = loadFactorFromPeak({ averageGw: avg, peakGw: peak }).value;
    check('peak and load factor are exact inverses of one another',
        near(lf, 0.6, 1e-12));
}

/* Round trip: energy -> nameplate at a capacity factor -> energy back. */
{
    const cap = nameplateFromCapacityFactorGw({ annualTwh: 480, capacityFactor: 0.4 }).value;
    check('nameplate at a capacity factor returns the annual energy it was derived from',
        near(cap * HOURS_TWH_TO_GW * 0.4, 480, 1e-9));
}

/* ── 2. The paper's worked examples, recomputed. ────────────────────────── */

check('480 TWh is 54.8 GW average (paper: 54.8)',
    near(averagePowerGw({ annualTwh: 480 }).value, 54.8, 0.05));

check('300 TWh is 34.2 GW average (paper: 34.2)',
    near(averagePowerGw({ annualTwh: 300 }).value, 34.2, 0.05));

/* The three load-factor sensitivities the paper prints for the 480 TWh case.
   These are the numbers most likely to be quoted onward, so they are checked
   to a tenth of a gigawatt. */
{
    const avg = averagePowerGw({ annualTwh: 480 }).value;
    check('480 TWh at 70% load factor is 78.3 GW peak (paper: 78.3)',
        near(peakFromLoadFactorGw({ averageGw: avg, loadFactor: 0.7 }).value, 78.3, 0.1));
    check('480 TWh at 60% load factor is 91.3 GW peak (paper: 91.3)',
        near(peakFromLoadFactorGw({ averageGw: avg, loadFactor: 0.6 }).value, 91.3, 0.1));
    check('480 TWh at 50% load factor is 109.6 GW peak (paper: 109.6)',
        near(peakFromLoadFactorGw({ averageGw: avg, loadFactor: 0.5 }).value, 109.6, 0.1));
}

check('480 TWh at a 40% capacity factor needs about 137 GW nameplate (paper: ~137)',
    near(nameplateFromCapacityFactorGw({ annualTwh: 480, capacityFactor: 0.4 }).value, 137, 0.5));

/* The three displaced-fuel examples. The third is the important one: where
   both routes are already efficient, electrification barely reduces the
   energy, and any rule of thumb that assumes it does is wrong. */
check('100 TWh of boiler fuel at 90% into a COP 3 heat pump is 30.0 TWh (paper: 30.0)',
    near(electricityForDisplacedFuelTwh({ fuelTwh: 100, oldEfficiency: 0.9, newPerformance: 3.0 }).value, 30.0, 0.01));

check('100 TWh of road fuel at 25% into an 80%-efficient EV is 31.25 TWh (paper: 31.25)',
    near(electricityForDisplacedFuelTwh({ fuelTwh: 100, oldEfficiency: 0.25, newPerformance: 0.8 }).value, 31.25, 0.01));

check('100 TWh of industrial heat at 90% into a 95%-efficient electrical route is 94.74 TWh (paper: 94.74)',
    near(electricityForDisplacedFuelTwh({ fuelTwh: 100, oldEfficiency: 0.9, newPerformance: 0.95 }).value, 94.74, 0.01));

/* NESO's three published 2050 pathways, checked the honest direction: derive
   the load factor from the published peak rather than assuming one. These are
   the figures that show why a single national multiplier cannot be right —
   Hydrogen Evolution has the LARGEST annual demand and a LOWER peak than
   Electric Engagement. */
{
    const pathways = [
        ['Holistic Transition', 705, 120],
        ['Electric Engagement', 785, 144],
        ['Hydrogen Evolution', 797, 122]
    ];
    const factors = pathways.map(([, twh, peak]) =>
        loadFactorFromPeak({ averageGw: averagePowerGw({ annualTwh: twh }).value, peakGw: peak }).value);
    check('NESO pathway load factors land between 0.62 and 0.75',
        factors.every(f => f > 0.62 && f < 0.75));
    check('Hydrogen Evolution has more annual energy than Electric Engagement but a lower peak, '
        + 'so no single national peak-to-average ratio can describe both',
        797 > 785 && 122 < 144);
    /* The specific trap: applying today's ratio forward. A peak-to-average of
       1.83, taken from an inferred present peak against a rounded reference,
       would put Holistic Transition at ~147 GW against a published 120. */
    const htAvg = averagePowerGw({ annualTwh: 705 }).value;
    check('applying a 1.83 peak-to-average ratio to Holistic Transition overshoots '
        + 'NESO\'s published 120 GW peak by more than 20%',
        peakFromLoadFactorGw({ averageGw: htAvg, loadFactor: 1 / 1.83 }).value > 120 * 1.2);
}

/* ── 3. Refusals and input discipline. ──────────────────────────────────── */

/* The error this module exists to catch: 40 passed where 0.4 was meant. A
   silent acceptance returns a number 100x wrong in a plausible-looking unit. */
check('a load factor of 40 is refused, and the message says to pass 0.4',
    throws(() => peakFromLoadFactorGw({ averageGw: 54.8, loadFactor: 40 }), /must be a fraction.*0\.4/s));

check('a capacity factor above one is refused',
    throws(() => nameplateFromCapacityFactorGw({ annualTwh: 480, capacityFactor: 40 }), /fraction/));

/* A heat pump legitimately exceeds unity. This must NOT be refused, or the
   module cannot express the case that matters most. */
check('a heat-pump COP above one is accepted, because a heat pump moves heat rather than making it',
    electricityForDisplacedFuelTwh({ fuelTwh: 100, oldEfficiency: 0.9, newPerformance: 3.5 }).value > 0);

check('a negative or zero energy is refused',
    throws(() => averagePowerGw({ annualTwh: 0 }), /greater than zero/)
    && throws(() => averagePowerGw({ annualTwh: -5 }), /greater than zero/));

check('a non-numeric input is refused by type, not coerced',
    throws(() => averagePowerGw({ annualTwh: '480' }), /finite number/));

check('a peak below the average it contains is refused as physically impossible',
    throws(() => loadFactorFromPeak({ averageGw: 54.8, peakGw: 30 }), /cannot be lower than the mean/));

/* Every returned figure carries its unit and the assumption it rests on. A
   value alone is how a sensitivity becomes a forecast in the retelling. */
{
    const r = peakFromLoadFactorGw({ averageGw: 54.8, loadFactor: 0.6 });
    check('a returned figure carries its unit, its inputs and its basis',
        r.unit === 'GW' && typeof r.basis === 'string' && r.basis.length > 40
        && r.from.loadFactor === 0.6);
    check('the peak figure says in words that it is a sensitivity and not a published peak',
        /sensitivity/i.test(r.basis) && /not a published peak/i.test(r.basis));
}

/* The absent functions. Anything matching these names would be the module
   quietly becoming a connection-assessment tool. */
{
    const callable = Object.keys(mod).filter(k => typeof mod[k] === 'function');
    check('no function computes headroom, spare capacity or connection availability',
        callable.every(n => !/headroom|spare|available|availability|uplift|adequacy/i.test(n)));
    check('the refusals are stated as readable reasons a card can print',
        Object.values(NOT_COMPUTED).every(v => typeof v === 'string' && v.length > 40));
    check('the refusals name headroom, connection availability, per-site uplift and adequacy',
        ['headroom', 'connectionAvailability', 'perSiteUplift', 'adequacy']
            .every(k => k in NOT_COMPUTED));
}

/* ── Report ─────────────────────────────────────────────────────────────── */

if (failures.length) {
    console.error('electrification-demand proof FAILED (' + failures.length + ' of '
        + (failures.length + passed) + '):\n- ' + failures.join('\n- '));
    process.exit(1);
}
console.log('electrification-demand proof PASS — ' + passed + ' checks');
export default { status: 'PASS', checks: passed };

Electrification Model Proof

A JavaScript module in the proofs folder of Ventus Grid Engine. It is built from the check step (`check`), the near step (`near`) and the throws step (`throws`).

otherventus-grid-engine / proofs/electrification-model.proof.mjs · lines 1–219 of 219 · Not reached from any entry point (candidate for review) · pattern throws (shared by 12 files)

What it does
Defines check, near, throws. Side effects: starts processes.
What it achieves
The module exists because a published report had to be corrected for conflating a heat pump's thermal output with its electrical input, and both were written in kilowatts. Its code works with 3.5 kW, 1.7 kW and 100 GW.
Why it matters
No other file in the estate was found to import it.
Application
ventus-grid-engine · proofs · JavaScript module
Uses
Electrification Model (import)
Used by
none found
Produces
check, near, throws
Defines here
check, near, throws
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
ventus-grid-engine@ad566356a44e006682e956483d569f31ddbb9630 proofs/electrification-model.proof.mjs:1-219 · blob bd98f4818f54687668663f2cff44d1effd846a12 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: unknown · effects: process · domain stage: unknown · users: none · canonical: unreached_review
/* electrification-model.proof.mjs — the module exists because a published
 * report had to be corrected for conflating a heat pump's thermal output with
 * its electrical input, and both were written in kilowatts. Most of these
 * checks are therefore about meanings rather than arithmetic: the arithmetic
 * here is division, and the errors in this field are substitutions.
 *
 * Run: node proofs/electrification-model.proof.mjs
 */

import {
    schema, MEANING, NOT_COMPUTED, NEVER_ADDED, NOT_A_FORECAST,
    quantity, electricalInputFromHeat, heatFromElectricalInput,
    fleetDemand, combinedPeak, primaryEnergyForWork
} from '../engine/electrification-model.js';

const failures = [];
let passed = 0;
const check = (name, condition) => { condition ? passed++ : failures.push(name); };
const near = (a, b, tol) => Math.abs(a - b) <= tol;
const throws = (fn, Kind) => { try { fn(); return false; } catch (e) { return e instanceof Kind; } };

/* ── the correction this module exists to prevent ────────────────────────── */

const heat = quantity(12.25, 'kW', MEANING.THERMAL_OUTPUT);
const elec = electricalInputFromHeat({ thermal: heat, scop: 3.5 });

check('12.25 kW of heat at a seasonal coefficient of performance of 3.5 needs '
    + '3.5 kW of electricity, the exact pair the published correction turned on',
    near(elec.value, 3.5, 1e-12) && elec.unit === 'kW');

check('the answer carries the meaning ELECTRICAL_INPUT, so it cannot later be '
    + 'read back as heat',
    elec.meaning === MEANING.ELECTRICAL_INPUT && heat.meaning === MEANING.THERMAL_OUTPUT);

check('the conversion REFUSES a quantity that carries the wrong meaning: '
    + 'handing it an electrical input where heat is expected throws, rather '
    + 'than dividing a number that is already electricity',
    throws(() => electricalInputFromHeat({
        thermal: quantity(3.5, 'kW', MEANING.ELECTRICAL_INPUT), scop: 3.5 }), RangeError));

check('the refusal message says why, naming the two kilowatts that are not the '
    + 'same quantity',
    (() => { try { electricalInputFromHeat({ thermal: quantity(3.5, 'kW', MEANING.ELECTRICAL_INPUT), scop: 3.5 }); }
             catch (e) { return /kilowatt/i.test(e.message) && /not the same/i.test(e.message); }
             return false; })());

check('the round trip is exact: heat to electricity and back returns the heat',
    near(heatFromElectricalInput({ electrical: elec, scop: 3.5 }).value, 12.25, 1e-12));

check('a coefficient of performance of 1 or less is refused, because a machine '
    + 'that returns no more heat than the electricity it eats is a resistance '
    + 'heater and calling it a heat pump hides that',
    throws(() => electricalInputFromHeat({ thermal: heat, scop: 1 }), RangeError)
    && throws(() => electricalInputFromHeat({ thermal: heat, scop: 0.9 }), RangeError));

check('the published range is named but never applied: no coefficient of '
    + 'performance is carried in the module',
    /3\.5 to 5/.test(NOT_COMPUTED.coefficientOfPerformance));

/* ── the fleet: a stress test and a planning number are different answers ── */

const pumps = fleetDemand({
    units: 28_000_000,
    perUnitNameplate: quantity(3.5, 'kW', MEANING.ELECTRICAL_INPUT),
    perUnitAfterDiversity: quantity(1.7, 'kW', MEANING.AFTER_DIVERSITY)
});

check('28 million heat pumps at 3.5 kW each, all at once, is 98 GW — the stress '
    + 'test figure in the report',
    near(pumps.simultaneous.value / 1e6, 98, 1e-9));

check('the same fleet after diversity at 1.7 kW is 47.6 GW, which is the number '
    + 'a network planner uses',
    near(pumps.diversified.value / 1e6, 47.6, 1e-9));

check('the stress test is labelled a stress test in the result itself, not in a '
    + 'footnote someone can drop when quoting it',
    /stress test/.test(pumps.simultaneous.label) && /not an expectation/.test(pumps.simultaneous.label));

check('the two figures carry different meanings, so nothing downstream can add '
    + 'them',
    pumps.simultaneous.meaning === MEANING.NAMEPLATE
    && pumps.diversified.meaning === MEANING.AFTER_DIVERSITY
    && pumps.never_added === NEVER_ADDED);

check('diversity is reported as a ratio so the assumption is visible: 1.7 of '
    + '3.5 is about 49 percent',
    near(pumps.diversified.ratio, 1.7 / 3.5, 1e-12));

check('an after-diversity figure LARGER than nameplate is refused, because that '
    + 'can only mean the two have been swapped',
    throws(() => fleetDemand({ units: 100,
        perUnitNameplate: quantity(1.7, 'kW', MEANING.ELECTRICAL_INPUT),
        perUnitAfterDiversity: quantity(3.5, 'kW', MEANING.AFTER_DIVERSITY) }), RangeError));

check('a nameplate passed where an after-diversity figure is expected is '
    + 'refused by meaning, even though both are kilowatts',
    throws(() => fleetDemand({ units: 100,
        perUnitNameplate: quantity(3.5, 'kW', MEANING.ELECTRICAL_INPUT),
        perUnitAfterDiversity: quantity(1.7, 'kW', MEANING.NAMEPLATE) }), RangeError));

check('with no diversity factor supplied, only the stress test is answered and '
    + 'the absence is stated',
    (() => { const f = fleetDemand({ units: 100, perUnitNameplate: quantity(3.5, 'kW', MEANING.NAMEPLATE) });
             return f.diversified === null && /diversity/i.test(f.not_computed); })());

check('a fractional number of units is refused: half a heat pump is not a fleet',
    throws(() => fleetDemand({ units: 1.5, perUnitNameplate: quantity(3.5, 'kW', MEANING.NAMEPLATE) }), RangeError));

const evs = fleetDemand({
    units: 20_000_000,
    perUnitNameplate: quantity(7.4, 'kW', MEANING.ELECTRICAL_INPUT),
    perUnitAfterDiversity: quantity(1.5, 'kW', MEANING.AFTER_DIVERSITY)
});

check('20 million vehicles charging at 7.4 kW simultaneously is 148 GW, the '
    + 'second stress test figure in the report',
    near(evs.simultaneous.value / 1e6, 148, 1e-9));

check('the two stress tests together are the 246 GW the report quotes, and that '
    + 'number is the sum of two figures the module refuses to add for you',
    near((pumps.simultaneous.value + evs.simultaneous.value) / 1e6, 246, 1e-9));

/* ── combining fleets: an assumption about time, stated ──────────────────── */

const both = combinedPeak({ fleets: [pumps, evs] });

check('combining the two diversified fleets gives 77.6 GW, well inside the 90 to '
    + '100 GW ceiling the report calls manageable, and far from 246',
    near(both.value / 1e6, 47.6 + 30, 1e-9));

check('the combination states the assumption it cannot check: that both peaks '
    + 'fall in the same hour',
    /same hour/.test(both.assumes) && /no clock/.test(both.assumes));

check('combining fleets REFUSES a fleet that has no diversity figure, because '
    + 'adding stress tests across fleets multiplies one fiction by another',
    throws(() => combinedPeak({ fleets: [pumps,
        fleetDemand({ units: 10, perUnitNameplate: quantity(3, 'kW', MEANING.NAMEPLATE) })] }), RangeError));

check('combining fleets in different units is refused rather than silently '
    + 'converted',
    throws(() => combinedPeak({ fleets: [pumps, fleetDemand({ units: 10,
        perUnitNameplate: quantity(3, 'MW', MEANING.ELECTRICAL_INPUT),
        perUnitAfterDiversity: quantity(1, 'MW', MEANING.AFTER_DIVERSITY) })] }), RangeError));

/* ── the efficiency case, which is the whole argument ────────────────────── */

const car = primaryEnergyForWork({
    usefulWork: quantity(100, 'TWh', MEANING.USEFUL_WORK),
    incumbentEfficiency: 0.25,
    electrifiedEfficiency: 0.70
});

check('the same motion from a 25 percent engine and a 70 percent drivetrain '
    + 'needs 400 TWh against 142.9 TWh',
    near(car.before.value, 400, 1e-9) && near(car.after.value, 100 / 0.7, 1e-9));

check('that is a 64.3 percent reduction in primary energy for the same work, '
    + 'which is the shape of the claim the report makes',
    near(car.reductionRatio, 1 - (100 / 0.7) / 400, 1e-12) && car.reductionRatio > 0.64);

const boiler = primaryEnergyForWork({
    usefulWork: quantity(100, 'TWh', MEANING.USEFUL_WORK),
    incumbentEfficiency: 0.85,
    electrifiedEfficiency: 3.5
});

check('the same heat from an 85 percent boiler and a heat pump at 3.5 needs '
    + '117.6 TWh against 28.6 TWh, a 75.7 percent reduction',
    near(boiler.before.value, 100 / 0.85, 1e-9) && near(boiler.after.value, 100 / 3.5, 1e-9)
    && boiler.reductionRatio > 0.75);

check('the result says what is NOT in the reduction: no behaviour change, no '
    + 'fabric improvement, no generation mix',
    /no behaviour change/.test(car.basis) && /generation mix/.test(car.basis));

check('a useful-work quantity is required; primary energy passed in its place '
    + 'is refused, because dividing primary energy by an efficiency again is '
    + 'the double-counting this whole area is prone to',
    throws(() => primaryEnergyForWork({
        usefulWork: quantity(100, 'TWh', MEANING.PRIMARY_ENERGY),
        incumbentEfficiency: 0.25, electrifiedEfficiency: 0.7 }), RangeError));

check('every result declares it is arithmetic on supplied assumptions and not a '
    + 'forecast',
    car.not_a_forecast === NOT_A_FORECAST && pumps.not_a_forecast === NOT_A_FORECAST
    && /not a prediction/.test(NOT_A_FORECAST));

check('no emissions figure is produced anywhere, and the module says why',
    /carbon intensity/.test(NOT_COMPUTED.emissions)
    && !('emissions' in car) && !('co2' in car));

/* ── the quantity type itself ────────────────────────────────────────────── */

check('a quantity is frozen, so a caller cannot relabel a number after the '
    + 'module has typed it',
    Object.isFrozen(heat) && Object.isFrozen(MEANING) && Object.isFrozen(NOT_COMPUTED));

check('an unknown meaning is refused rather than accepted as a free-text note',
    throws(() => quantity(1, 'kW', 'power'), RangeError)
    && throws(() => quantity(1, 'kW', 'THERMAL_OUTPUT'), RangeError));

check('there are seven declared meanings and three of them are powers, which is '
    + 'why a unit check alone cannot protect this arithmetic',
    Object.keys(MEANING).length === 7);

check('the schema names this module and this version',
    schema === 'ventus-grid-engine.electrification-model.v1');

/* ── report ─────────────────────────────────────────────────────────────── */

if (failures.length) {
    console.error('electrification-model proof FAILED (' + failures.length + ' of '
        + (failures.length + passed) + '):\n- ' + failures.join('\n- '));
    process.exit(1);
}
console.log('electrification-model proof PASS — ' + passed + ' checks');
export default { status: 'PASS', checks: passed };

Firm Capacity Proof

A JavaScript module in the proofs folder of Ventus Grid Engine covering transformers and substations.

energy-dataventus-grid-engine / proofs/firm-capacity.proof.mjs · lines 1–139 of 139 · Not reached from any entry point (candidate for review) · pattern throws (shared by 12 files)

What it does
It lists and searches transformers and substations. Defines check, near, throws. Side effects: starts processes.
Why it exists in the grid workflow
Domain terms in the code: transformers, substations.
What it achieves
It is built from the check step (`check`), the near step (`near`) and the throws step (`throws`). The N-1 arithmetic, and the boundary between what it may say and what it may not. Its code works with 30 MVA, 42 MVA and 100 MW.
Why it matters
No other file in the estate was found to import it.
Application
ventus-grid-engine · proofs · JavaScript module
Uses
Firm Capacity (import)
Used by
none found
Produces
check, near, throws
Defines here
check, near, throws
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
ventus-grid-engine@ad566356a44e006682e956483d569f31ddbb9630 proofs/firm-capacity.proof.mjs:1-139 · blob 8152a91e9b4f5f886bc11a1b57b37674f33061e3 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: unknown · effects: process · domain stage: unknown · users: none · canonical: unreached_review
/* firm-capacity.proof.mjs — the N-1 arithmetic, and the boundary between what
 * it may say and what it may not.
 *
 * The worked case is the one in the electrification paper: a substation with
 * two 30 MVA units, whose peak grows from 24 to 42 MVA. Installed capacity
 * never changes and never looks stressed; firm capacity is exceeded well
 * before installed is, and that is the whole point of the module.
 *
 * Run: node proofs/firm-capacity.proof.mjs
 */

import * as mod from '../engine/firm-capacity.js';
const { schema, NOT_COMPUTED, apparentPowerMva, firmCapacityMva,
    utilisationAgainstRating, assessAgainstFirm } = mod;

const failures = [];
let passed = 0;
const check = (name, condition) => { condition ? passed += 1 : failures.push(name); };
const near = (a, b, tol) => Math.abs(a - b) <= tol;
const throws = (fn, pattern) => {
    try { fn(); return false; } catch (e) { return pattern.test(e.message); }
};

check('schema is declared', schema === 'ventus-grid-engine.firm-capacity.v1');

/* ── Apparent power. The paper's data-centre case. ──────────────────────── */

check('100 MW at 0.95 power factor is 105.3 MVA (paper: 105 MVA)',
    near(apparentPowerMva({ mw: 100, powerFactor: 0.95 }).value, 105.26, 0.01));

check('unity power factor leaves the figure unchanged',
    apparentPowerMva({ mw: 100, powerFactor: 1 }).value === 100);

check('the under-count from sizing on MW is stated as a percentage',
    /5\.3%/.test(apparentPowerMva({ mw: 100, powerFactor: 0.95 }).basis));

/* ── Firm capacity. ─────────────────────────────────────────────────────── */

check('two 30 MVA units give 60 MVA installed and 30 MVA firm (paper)',
    firmCapacityMva({ units: [30, 30] }).value === 30
    && firmCapacityMva({ units: [30, 30] }).from.installedMva === 60);

check('three 30 MVA units give 90 installed and 60 firm',
    firmCapacityMva({ units: [30, 30, 30] }).value === 60);

/* Asymmetric banks are where the "less the largest" rule bites hardest. */
check('an asymmetric bank loses its LARGEST unit, not an average one',
    firmCapacityMva({ units: [90, 30] }).value === 30);

/* The answer that matters most and is most often mis-handled. */
{
    const single = firmCapacityMva({ units: [30] });
    check('a single transformer has ZERO firm capacity, returned as an answer not an error',
        single.value === 0);
    check('the single-unit basis says losing it loses the site',
        /NO firm capacity/i.test(single.basis) && /loses the site/i.test(single.basis));
}

/* ── The paper's worked substation, across its growth. ──────────────────── */
{
    const units = [30, 30];
    const before = assessAgainstFirm({ units, demandMva: 24 });
    const after = assessAgainstFirm({ units, demandMva: 42 });

    check('at 24 MVA the site is inside firm capacity',
        before.withinFirm === true && before.shortfallMva === 0);

    check('at 42 MVA the site is beyond firm but still inside installed — the gap that decides connections',
        after.withinFirm === false && after.withinInstalled === true);

    check('the shortfall against firm is reported as 12 MVA',
        near(after.shortfallMva, 12, 1e-9));

    /* The trap this module exists to expose: on installed capacity the site
       looks 70% loaded and unremarkable. On firm it is already 40% over. */
    check('installed utilisation looks comfortable at 70% while firm utilisation is 140%',
        near(after.utilisationOfInstalled, 0.7, 1e-9) && near(after.utilisationOfFirm, 1.4, 1e-9));

    check('the paper\'s 75% demand growth is what moves it across the firm boundary',
        near((42 - 24) / 24, 0.75, 1e-9));

    const beyond = assessAgainstFirm({ units, demandMva: 65 });
    check('a demand beyond installed capacity is reported as such',
        beyond.withinInstalled === false);
}

/* ── Utilisation against a stated rating. ───────────────────────────────── */
{
    const u = utilisationAgainstRating({ demandMva: 42, ratingMva: 30 });
    check('42 MVA on a 30 MVA rating is 140% and flagged as exceeding',
        near(u.percent, 140, 1e-9) && u.exceedsRating === true);
    check('the excess is quantified in MVA',
        /12\.00 MVA/.test(u.basis));
    check('the basis refuses the words spare capacity and names where the real constraint may sit',
        /not spare capacity/i.test(u.basis)
        && /upstream circuit/i.test(u.basis) && /fault level/i.test(u.basis));
    check('a demand inside the rating is not flagged as exceeding',
        utilisationAgainstRating({ demandMva: 20, ratingMva: 30 }).exceedsRating === false);
}

/* ── Input discipline. ──────────────────────────────────────────────────── */

check('a power factor of 95 is refused, and the message says to pass 0.95',
    throws(() => apparentPowerMva({ mw: 100, powerFactor: 95 }), /fraction.*0\.95/s));

check('an empty or absent transformer list is refused',
    throws(() => firmCapacityMva({ units: [] }), /non-empty array/)
    && throws(() => firmCapacityMva({ units: 30 }), /non-empty array/));

check('a zero or negative transformer rating is refused, naming the index',
    throws(() => firmCapacityMva({ units: [30, 0] }), /units\[1\].*greater than zero/s));

check('a non-numeric rating is refused by type rather than coerced',
    throws(() => firmCapacityMva({ units: [30, '30'] }), /units\[1\].*finite number/s));

/* ── Refusals. ──────────────────────────────────────────────────────────── */
{
    const callable = Object.keys(mod).filter(k => typeof mod[k] === 'function');
    check('no function returns spare capacity, headroom or connection availability',
        callable.every(n => !/headroom|spare|available|availability/i.test(n)));
    check('no function invents a cyclic or emergency rating',
        callable.every(n => !/cyclic|emergency|overload/i.test(n)));
    check('the refusals name spare capacity, connection availability, cyclic rating and security compliance',
        ['spareCapacity', 'connectionAvailability', 'cyclicAndEmergencyRating', 'securityCompliance']
            .every(k => k in NOT_COMPUTED));
    check('each refusal is a readable reason, not a label',
        Object.values(NOT_COMPUTED).every(v => typeof v === 'string' && v.length > 60));
    check('the firm-capacity basis says plainly that this is not a P2/7 security study',
        /not a security study/i.test(firmCapacityMva({ units: [30, 30] }).basis)
        && /P2\/7/.test(firmCapacityMva({ units: [30, 30] }).basis));
}

if (failures.length) {
    console.error('firm-capacity proof FAILED (' + failures.length + ' of '
        + (failures.length + passed) + '):\n- ' + failures.join('\n- '));
    process.exit(1);
}
console.log('firm-capacity proof PASS — ' + passed + ' checks');
export default { status: 'PASS', checks: passed };