GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Electricity markets and data pipelines / globalgrid2050 / energy-transition-simulator/202609280014/mod/engine

Station and 5 more files

A JavaScript module in the engine folder of GlobalGrid2050 that works with transformers, cables and solar.

592 lines of JavaScript from globalgrid2050, in 6 files. Topic: Electricity markets and data pipelines. Section 850 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. Station transform · globalgrid2050 / energy-transition-simulator/202609280014/mod/engine/station.mjs lines 1–262
  2. String Design transform · globalgrid2050 / energy-transition-simulator/202609280014/mod/engine/string-design.mjs lines 1–60
  3. Structure Presets transform · globalgrid2050 / energy-transition-simulator/202609280014/mod/engine/structure-presets.mjs lines 1–74
  4. Structures ingest · globalgrid2050 / energy-transition-simulator/202609280014/mod/engine/structures.mjs lines 1–136
  5. Sub Grammar ingest · globalgrid2050 / energy-transition-simulator/202609280014/mod/engine/sub-grammar.mjs lines 1–21
  6. GPU Rows render · globalgrid2050 / energy-transition-simulator/202609280014/mod/gpu-rows.js lines 1–39

Station

A JavaScript module in the engine folder of GlobalGrid2050 that works with transformers, cables and solar.

Set aside from the main view: 99% of its lines are the same as solar-design-studio/202609270220-site-world-v3/world/station.mjs (globalgrid2050), which stays. (near-copy-of, proposed by families.py). 98% of lines shared with Station; read that one first. All set-aside files, with reasons. Nothing was deleted.

Evidence
  • line-jaccard 0.9899 to globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-design-studio/202609270220-site-world-v3/world/station.mjs:1-260 de97067e14359e65a6bd855026887ddfe01fc199
  • sha256 b061b20437191dc40fb89ba658ce631d971f6da5df78252e994855f4d73b542a
  • target sha256 cf707bb6184ac41829533ac5edad5ef9c07f6ca41d8e47203c7e06d656029a6f
  • group of 3 (identity.json near-copy edges >= 0.9)
  • canonical rule: reachable, newest stamp, core repo, most lines

transformglobalgrid2050 / energy-transition-simulator/202609280014/mod/engine/station.mjs · lines 1–262 of 262 · version 2026-09-28 00:14 · Not reached from any entry point (candidate for review) · pattern stationInventory (shared by 3 files)

What it does
It calculates transformers, cables and solar. Defines 20 functions or classes, including cfg, tableShape, tableOrigin, stringsPerTable, tableStrings.
Why it exists in the grid workflow
Domain stage upstream_foresight (topic 'markets-data'): 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: transformers, cables, solar.
Downstream impact
Used directly by 5 files: Block Trenches (globalgrid2050); Cmd Trench (globalgrid2050); MV Network (globalgrid2050); Block Build (globalgrid2050); and 1 more.
What it achieves
It is built from the cfg step (`cfg`), the table shape helper (`tableShape`) and the table origin helper (`tableOrigin`). Solar station library: paired tables, pole inverters, DC home cables in ducts, AC trenches, 2 x 5MVA. Its code works with 5 MVA.
Why it matters
Imported by 5 files, including Block Trenches, Cmd Trench and MV Network.
Application
globalgrid2050 · energy-transition-simulator/202609280014/mod/engine · JavaScript module
Uses
none found
Used by
imported by Block Trenches (import), imported by Cmd Trench (import), imported by MV Network (import), imported by Block Build (import), imported by Plant Central (import)
Produces
STATION_DEFAULTS, tableShape, tableOrigin, stringsPerTable, tableStrings, dcOrder, seriesLinks, inverterSite, dcDucts, dcHomeRoutes, acRoute, acTrenches
Defines here
cfg, tableShape, tableOrigin, stringsPerTable, tableStrings, p, dcOrder, seriesLinks, inverterSite, dcDucts, dcHomeRoutes, acRoute, acTrenches, compoundBox, stationSolids, stationInventory, placer, point, box, station
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 energy-transition-simulator/202609280014/mod/engine/station.mjs:1-262 · blob eecf0f23540218834b3ab82fc59d9da7927d245d · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: duplicate_candidate
// COPIED UNCHANGED from world/v12 station.mjs at v12 commit 3adcee9 (file last changed e22776b). Modular star family: public #145809 tableShape.
// Do not edit here: change the source and re-copy. Everything below this header is byte-identical to the source.
// Solar station library: paired tables, pole inverters, DC home cables in ducts, AC trenches, 2 x 5 MVA.
// The world draws it through block-build.mjs (Design > Solar block): placed on the measured ground, built in sequence.
//
// Source: graphics-engines-open-source, web/explore.mjs at commit 826c0df4e94b46d9b96c5fb9bfcffab52851f03a
// (branch improve/20260926, 26 Sept 2026; the explorer file there equals the working tree). Lifted lines:
//   L82  dcLayout / blockLayout defaults       L87  stationTableOrigin      L88 defaultInverterSite
//   L92  blockPosition                         L93  blockStrings (stationMode branch: index < 672, 24 per inverter)
//   L95  dcOrder (sequential / leapfrog)       L96  ridgeHeight             L97 dcDucts (4 per inverter)
//   L101 drawPoleInverter (box and pole)       L100 drawTransformer (4 x 4 x 3 m, 12 x 10 m pad)
//   L118 acLayout (28 inverters, 14 per transformer, trefoil, 0.9 m)      L120-121 collectorX / acRoute, L123 acTrenches
//   L127-128 compoundBox / drawCompound (12 m margin, 2.4 m fence)        L143 stationInventory
//   L8   stationTransformers [[155,320,1.5],[155,345,1.5]]
// The same functions sit at L68-74 and L106-108 on origin/main 037e2f79a1493a3ef422807b274c6c22ef7dc9a7.
//
// Pure functions, no globals. Geometry is local east/north/up metres. station() places it relative to a
// placement point and a heading (radians, compass: 0 = the station's +y points north, pi/2 = east).
// Labels are the source's own: equipment positions, cable routes and duct size are assumed/illustrative,
// not surveyed, and no isolators are modelled.

const RAD = Math.PI / 180;

export const STATION_DEFAULTS = Object.freeze({
  // startStation() settings (explorer L142)
  height: 1.2, tilt: 10, tables: 23, columns: 90, rows: 5, moduleWidth: 1.303, moduleLength: 2.384, moduleGap: 0.02,
  // blockLayout (L82)
  rowGap: 8, aisleGap: 10, ridgeGap: 0.5,
  // electrical (L80, L143)
  moduleW: 660, modulesPerString: 30, stringsPerInverter: 24, inverters: 28, invertersPerTransformer: 14,
  inverterKVA: 352, transformerMVA: 5, transformers: [[155, 320, 1.5], [155, 345, 1.5]],
  // dcLayout (L82); duct diameter is flagged as assumed by the source (dcWiring: ductDiameterAssumed)
  wiring: 'sequential', dcDepth: 0.6, ductDiameter: 0.09, ductsPerInverter: 4, ductSpacing: 0.12,
  // acLayout (L118); cable 400 mm2 Al, 800 V (acRoute labels)
  acDepth: 0.9, formation: 'trefoil', acDiameter: 0.0374, acAreaMm2: 400, acVolts: 800, collectorOffset: 15,
  // world-only: the underside of a table solid. Assumed, not from the source: the lowest module edge sits
  // at `height`; purlins and rails are taken to hang 0.3 m below it. A drone flies under, a walker does not.
  tableUnderside: 0.9
});

const cfg = p => ({ ...STATION_DEFAULTS, ...(p || {}) });

// Table cross-section: the run of one face up the slope, its plan depth, span along y, ridge height.
export function tableShape(params) {
  const s = cfg(params), run = s.rows * (s.moduleLength + s.moduleGap) - s.moduleGap;
  return {
    run, depth: run * Math.cos(s.tilt * RAD), span: s.columns * (s.moduleWidth + s.moduleGap) - s.moduleGap,
    ridge: s.height + run * Math.sin(s.tilt * RAD), halfRidgeGap: s.ridgeGap / 2
  };
}

// blockPosition / stationTableOrigin (L87, L92): four paired tables across, then the next aisle.
export function tableOrigin(n, params) {
  const s = cfg(params), { depth, span } = tableShape(s);
  return [(n % 4) * (2 * depth + s.ridgeGap + s.rowGap), Math.floor(n / 4) * (span + s.aisleGap)];
}

export const stringsPerTable = params => { const s = cfg(params); return 2 * s.rows * Math.ceil(s.columns / s.modulesPerString); };

// blockStrings (L93), station branch: every face-row is cut into 30-module strings; the first
// inverters x stringsPerInverter strings in build order are connected, the rest are spare (assigned elsewhere).
export function tableStrings(params, { corners = true } = {}) {
  const s = cfg(params), t = s.tilt * RAD, { depth, halfRidgeGap: g } = tableShape(s), out = [];
  const connectedLimit = s.inverters * s.stringsPerInverter, groups = Math.ceil(s.columns / s.modulesPerString);
  for (let n = 0; n < s.tables; n++) {
    const [x, y] = tableOrigin(n, s);
    for (const side of [-1, 1]) for (let r = 0; r < s.rows; r++) for (let group = 0; group < groups; group++) {
      const modules = [];
      for (let c = group * s.modulesPerString; c < Math.min(s.columns, (group + 1) * s.modulesPerString); c++) {
        const v = (side === 1 ? s.rows - 1 - r : r) * (s.moduleLength + s.moduleGap), u = c * (s.moduleWidth + s.moduleGap);
        const p = (dv, du) => [x + side * (g + depth - (v + dv) * Math.cos(t)), y + u + du, s.height + (v + dv) * Math.sin(t)];
        const m = { terminal: p(s.moduleLength / 2, s.moduleWidth / 2), minus: p(s.moduleLength / 2, s.moduleWidth / 2 - 0.42), plus: p(s.moduleLength / 2, s.moduleWidth / 2 + 0.42) };
        if (corners) m.corners = [p(0, 0), p(s.moduleLength, 0), p(s.moduleLength, s.moduleWidth), p(0, s.moduleWidth)];
        modules.push(m);
      }
      const index = out.length, connected = index < connectedLimit;
      out.push({ index, table: n, side, row: r, group, connected, inverter: connected ? Math.floor(index / s.stringsPerInverter) : null, modules });
    }
  }
  return out;
}

// dcOrder (L95): the order modules are linked in series. Leapfrog runs out on evens, back on odds.
export function dcOrder(n, wiring = 'sequential') {
  if (wiring === 'sequential') return Array.from({ length: n }, (_, i) => i);
  const a = [];
  for (let i = 0; i < n; i += 2) a.push(i);
  for (let i = n % 2 ? n - 2 : n - 1; i >= 1; i -= 2) a.push(i);
  return a;
}

// Series links of one string as polylines (module + to next module -, dropped 8 cm onto a rail; L94).
export function seriesLinks(string, wiring = 'sequential') {
  const order = dcOrder(string.modules.length, wiring), links = [];
  for (let i = 1; i < order.length; i++) {
    const a = string.modules[order[i - 1]].plus, b = string.modules[order[i]].minus, dx = order[i] > order[i - 1] ? 0.05 : -0.05;
    links.push([a, [a[0] + dx, a[1], a[2] - 0.08], [b[0] + dx, b[1], b[2] - 0.08], b]);
  }
  return links;
}

// defaultInverterSite (L88): one pole per 24 strings, at the end (y - 1 m) of the table that feeds it;
// shifted 1.2 m when the inverter's first string starts 24 strings into a 30-string table. Top at ridge height.
export function inverterSite(k, params) {
  const s = cfg(params), spt = stringsPerTable(s), first = k * s.stringsPerInverter;
  const [x, y] = tableOrigin(Math.floor(first / spt), s);
  return [x + (first % spt === s.stringsPerInverter ? 1.2 : 0), y - 1, tableShape(s).ridge];
}

// dcDucts (L97): four ducts per inverter, 0.12 m apart, 2 m run at DC depth then up the pole to top - 0.9 m.
// Each duct carries up to 6 strings, a + and a - home cable each (dcWiring: L112 of origin/main).
export function dcDucts(sites, params) {
  const s = cfg(params), per = Math.ceil(s.stringsPerInverter / s.ductsPerInverter);
  return sites.flatMap((p, i) => Array.from({ length: s.ductsPerInverter }, (_, d) => {
    const x = p[0] + (d - (s.ductsPerInverter - 1) / 2) * s.ductSpacing, strings = Math.min(per, Math.max(0, s.stringsPerInverter - d * per));
    return { inverter: i + 1, duct: d + 1, diameter: s.ductDiameter, diameterAssumed: true, strings, positiveCables: strings, negativeCables: strings,
      points: [[x, p[1] - 2, -s.dcDepth], [x, p[1], -s.dcDepth], [x, p[1], p[2] - 0.9]] };
  }));
}

// updateBlockRoutes (explorer, station branch): each connected string's two home cables, in string order. From the
// end module's terminal onto the rail (8 cm down), along the rail to the table end (y - 1), down to DC depth, along
// to the inverter's duct (6 strings a duct, 4 ducts), 2 m past the pole and back, up the pole to top - 0.9 m.
export function dcHomeRoutes(strings, sites, params) {
  const s = cfg(params), count = new Map(), out = [];
  strings.filter(x => x.connected).forEach((string, i) => {
    const slot = count.get(string.inverter) || 0;
    count.set(string.inverter, slot + 1);
    if (slot >= s.stringsPerInverter || string.modules.length > s.modulesPerString) throw Error('too many strings for one inverter');
    const order = dcOrder(string.modules.length, s.wiring), dest = sites[string.inverter], duct = Math.floor(slot / 6);
    const [, ty] = tableOrigin(string.table, s), ductX = dest[0] + (duct - 1.5) * s.ductSpacing, d = s.dcDepth;
    for (const end of [0, 1]) {
      const p = end ? string.modules[order.at(-1)].plus : string.modules[order[0]].minus;
      const offset = ((slot % 6) * 2 + end - 5.5) * 0.004, railZ = p[2] - 0.08, x = ductX + offset, y = dest[1];
      const points = [p, [p[0] + offset, p[1], railZ], [p[0] + offset, ty - 1, railZ], [p[0] + offset, ty - 1, -d], [x, ty - 1, -d],
        [x, y - 2, -d], [x, y, -d], [x, y, dest[2] - 0.9], [dest[0], y, dest[2] - 0.9]]
        .filter((q, j, a) => !j || Math.hypot(q[0] - a[j - 1][0], q[1] - a[j - 1][1], q[2] - a[j - 1][2]) > 1e-8);
      out.push({ id: `S${String(i + 1).padStart(2, '0')}-${end ? 'POS' : 'NEG'}`, string: string.index, inverter: string.inverter, slot,
        duct: duct + 1, polarity: end ? '+' : '-', points });
    }
  });
  return out;
}

// collectorX / acRoute (L120-121): down the pole, east in a branch trench to the collector 15 m west of the
// transformer, along the main trench, then in. Three phases, trefoil or flat.
export function acRoute(p, t, id, label, params) {
  const s = cfg(params), d = s.acDiameter, cx = t[0] - s.collectorOffset;
  return [0, 1, 2].map(phase => {
    const o = s.formation === 'flat' ? (phase - 1) * d : phase === 0 ? -d / 2 : phase === 1 ? d / 2 : 0;
    const z = -s.acDepth + 0.05 + d / 2 + (s.formation === 'trefoil' && phase === 2 ? Math.sqrt(3) * d / 2 : 0);
    const points = [[p[0] + o, p[1], p[2] - 0.9], [p[0] + o, p[1], z], [cx + o, p[1], z], [cx + o, t[1], z], [t[0] + o, t[1], z], [t[0] + o, t[1], 1]]
      .filter((q, j, a) => !j || Math.hypot(q[0] - a[j - 1][0], q[1] - a[j - 1][1], q[2] - a[j - 1][2]) > 1e-8);
    return { id: `${id}-L${phase + 1}`, label, areaMm2: s.acAreaMm2, volts: s.acVolts, points };
  });
}

// acTrenches (L123): branch 0.35 m wide, main 2.6 m wide, depth acDepth.
export function acTrenches(sites, transformers, params) {
  const s = cfg(params), out = [];
  sites.forEach((p, i) => {
    const t = transformers[Math.floor(i / s.invertersPerTransformer)], cx = t[0] - s.collectorOffset;
    out.push({ from: [p[0], p[1]], to: [cx, p[1]], width: 0.35, depth: s.acDepth, kind: 'branch' },
      { from: [cx, p[1]], to: [cx, t[1]], width: 2.6, depth: s.acDepth, kind: 'main' },
      { from: [cx, t[1]], to: [t[0], t[1]], width: 2.6, depth: s.acDepth, kind: 'main' });
  });
  return out;
}

// compoundBox (L127): 12 m round the transformers; drawCompound fence 2.4 m high.
export function compoundBox(transformers) {
  const xs = transformers.map(p => p[0]), ys = transformers.map(p => p[1]);
  return [Math.min(...xs) - 12, Math.min(...ys) - 12, Math.max(...xs) + 12, Math.max(...ys) + 12];
}

// Solids in station-local metres, before placement: { min, max, kind, id }.
export function stationSolids(params, sites, transformers) {
  const s = cfg(params), { depth, span, ridge, halfRidgeGap: g } = tableShape(s), out = [];
  for (let n = 0; n < s.tables; n++) {
    const [x, y] = tableOrigin(n, s);
    out.push({ kind: 'table', id: n + 1, min: [x - g - depth, y, s.tableUnderside], max: [x + g + depth, y + span, ridge + 0.05] });
  }
  sites.forEach((p, i) => {
    out.push({ kind: 'inverter', id: i + 1, min: [p[0] - 0.5, p[1] - 0.25, p[2] - 1], max: [p[0] + 0.5, p[1] + 0.25, p[2]] },
      { kind: 'pole', id: i + 1, min: [p[0] - 0.06, p[1] + 0.24, 0], max: [p[0] + 0.06, p[1] + 0.36, p[2]] });
  });
  transformers.forEach((p, i) => out.push({ kind: 'transformer', id: i + 1, min: [p[0] - 2, p[1] - 2, 0], max: [p[0] + 2, p[1] + 2, 3] }));
  const [x0, y0, x1, y1] = compoundBox(transformers), w = 0.05, h = 2.4;
  out.push({ kind: 'fence', id: 1, min: [x0, y0 - w, 0], max: [x1, y0 + w, h] }, { kind: 'fence', id: 2, min: [x0, y1 - w, 0], max: [x1, y1 + w, h] },
    { kind: 'fence', id: 3, min: [x0 - w, y0, 0], max: [x0 + w, y1, h] }, { kind: 'fence', id: 4, min: [x1 - w, y0, 0], max: [x1 + w, y1, h] });
  return out;
}

// stationInventory (L143), computed rather than typed, so it moves with the parameters.
export function stationInventory(params, strings = tableStrings(params, { corners: false })) {
  const s = cfg(params), connected = strings.filter(x => x.connected), tableModules = s.rows * s.columns * 2;
  const connectedModules = connected.reduce((n, x) => n + x.modules.length, 0);
  const perInverter = Array.from({ length: s.inverters }, (_, i) => connected.filter(x => x.inverter === i).length);
  return {
    illustrative: true, tables: s.tables, modulesPerTable: tableModules, stringsPerTable: stringsPerTable(s),
    tableKwp: tableModules * s.moduleW / 1000, installedModules: strings.reduce((n, x) => n + x.modules.length, 0),
    connectedModules, totalStrings: strings.length, connectedStrings: connected.length, spareStrings: strings.length - connected.length,
    modulesPerString: s.modulesPerString, stringKwp: s.modulesPerString * s.moduleW / 1000,
    maxInverterDCKwp: s.stringsPerInverter * s.modulesPerString * s.moduleW / 1000, connectedDCKwp: connectedModules * s.moduleW / 1000,
    seriesLinks: connected.reduce((n, x) => n + x.modules.length - 1, 0),
    inverters: s.inverters, stringsPerInverter: perInverter, inverterKVA: s.inverterKVA, aggregateInverterMVA: s.inverters * s.inverterKVA / 1000,
    dcHomeCables: connected.length * 2, ductsPerInverter: s.ductsPerInverter, ducts: s.inverters * s.ductsPerInverter,
    acPhaseCables: s.inverters * 3, acAreaMm2: s.acAreaMm2, invertersPerTransformer: s.invertersPerTransformer,
    transformers: s.transformers.length, transformerMVA: s.transformerMVA, aggregateTransformerMVA: s.transformers.length * s.transformerMVA,
    wiring: s.wiring, dcDepth: s.dcDepth, ductDiameter: s.ductDiameter, ductDiameterAssumed: true, acDepth: s.acDepth, formation: s.formation
  };
}

// Placement: rotate station-local (x, y) by the compass heading, then add the placement point.
export function placer(at = [0, 0, 0], heading = 0) {
  const c = Math.cos(heading), s = Math.sin(heading), z0 = at[2] || 0;
  const point = ([x, y, z = 0]) => [at[0] + x * c + y * s, at[1] - x * s + y * c, z0 + z];
  const box = b => {
    const q = [[b.min[0], b.min[1]], [b.max[0], b.min[1]], [b.max[0], b.max[1]], [b.min[0], b.max[1]]].map(([x, y]) => point([x, y, 0]));
    const xs = q.map(p => p[0]), ys = q.map(p => p[1]);
    return { ...b, min: [Math.min(...xs), Math.min(...ys), z0 + b.min[2]], max: [Math.max(...xs), Math.max(...ys), z0 + b.max[2]], quad: q.map(p => [p[0], p[1]]) };
  };
  return { point, box };
}

// The whole station, placed. opts.corners = false skips the 4 corners of each of the 20,700 modules.
export function station(params, { at = [0, 0, 0], heading = 0, corners = true } = {}) {
  const s = cfg(params), P = placer(at, heading), pts = a => a.map(P.point);
  const localSites = Array.from({ length: s.inverters }, (_, k) => inverterSite(k, s));
  const localTx = s.transformers.map(p => [...p]);
  const strings = tableStrings(s, { corners });
  const inventory = stationInventory(s, strings);
  const { depth, span, ridge, halfRidgeGap: g } = tableShape(s);
  const tables = Array.from({ length: s.tables }, (_, n) => {
    const [x, y] = tableOrigin(n, s);
    return { id: n + 1, faces: [-1, 1].map(side => pts([[x + side * (g + depth), y, s.height], [x + side * g, y, ridge],
      [x + side * g, y + span, ridge], [x + side * (g + depth), y + span, s.height]])) };
  });
  const placedStrings = strings.map(x => ({ ...x, modules: x.modules.map(m => {
    const o = { terminal: P.point(m.terminal), minus: P.point(m.minus), plus: P.point(m.plus) };
    if (m.corners) o.corners = pts(m.corners);
    return o;
  }) }));
  const acCables = localSites.flatMap((p, i) => {
    const t = localTx[Math.floor(i / s.invertersPerTransformer)];
    return acRoute(p, t, `ST-INV-${i + 1}`, `Inverter ${i + 1} to transformer ${Math.floor(i / s.invertersPerTransformer) + 1}; ${s.acAreaMm2} mm2 Al; ${s.acVolts} V; illustrative`, s)
      .map(c => ({ ...c, points: pts(c.points) }));
  });
  return {
    note: 'Illustrative station geometry: equipment positions, cable routes and duct size assumed, not surveyed; no isolators modelled.',
    at: [...at], heading, params: s, tables, strings: placedStrings,
    inverters: localSites.map((p, i) => ({ id: i + 1, point: P.point(p), transformer: Math.floor(i / s.invertersPerTransformer) + 1,
      kva: s.inverterKVA, label: 'pole-mounted; port positions illustrative' })),
    transformers: localTx.map((p, i) => ({ id: i + 1, point: P.point(p), mva: s.transformerMVA })),
    compound: (([x0, y0, x1, y1]) => pts([[x0, y0], [x1, y0], [x1, y1], [x0, y1]]))(compoundBox(localTx)),
    ducts: dcDucts(localSites, s).map(d => ({ ...d, points: pts(d.points) })),
    acCables,
    acTrenches: acTrenches(localSites, localTx, s).map(t => ({ ...t, from: P.point(t.from).slice(0, 2), to: P.point(t.to).slice(0, 2) })),
    solids: stationSolids(s, localSites, localTx).map(P.box),
    inventory
  };
}

String Design

A JavaScript module in the engine folder of GlobalGrid2050 that works with typed class (`typedClass`) (units: °C).

Set aside from the main view: 96% of its lines are the same as solar-design-studio/202609271740-site-world/world/string-design.mjs (globalgrid2050), which stays. (near-copy-of, proposed by families.py). 95% of lines shared with String Design; read that one first. All set-aside files, with reasons. Nothing was deleted.

Evidence
  • line-jaccard 0.9556 to globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-design-studio/202609271740-site-world/world/string-design.mjs:1-58 d546c518116dbddd97a8676a80a03c575efc7cec
  • sha256 36824ebcfafd489072b1f09eebc9bb83149f7b3298a847bcb6f8dee01ff0c757
  • target sha256 94527560345a3d73b2d880f0947156cbd4c85f3459e9d23e8774ba513b6107ab
  • group of 3 (identity.json near-copy edges >= 0.9)
  • canonical rule: reachable, newest stamp, core repo, most lines

transformglobalgrid2050 / energy-transition-simulator/202609280014/mod/engine/string-design.mjs · lines 1–60 of 60 · version 2026-09-28 00:14 · Not reached from any entry point (candidate for review) · pattern stringCounts (shared by 3 files)

What it does
It calculates its inputs. Defines 6 functions or classes, including num, stringDesign, stringLine, stringWords, typedClass.
Why it exists in the grid workflow
Domain stage sub33kv_design (path word 'design'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary.
Downstream impact
Used directly by 1 file: Cmd Model (globalgrid2050).
What it achieves
It is built from the num step (`num`), the string design helper (`stringDesign`) and the string line helper (`stringLine`). The string voltage of the solar block, worked out in the open.
Why it matters
Imported by Cmd Model.
Application
globalgrid2050 · energy-transition-simulator/202609280014/mod/engine · JavaScript module
Uses
Module Catalogue (import)
Used by
imported by Cmd Model (import)
Produces
STRING_ADVICE, ILLUSTRATIVE, BORDERLINE_PCT, stringDesign, stringLine, stringWords, typedClass, stringCounts
Defines here
num, stringDesign, stringLine, stringWords, typedClass, stringCounts
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 energy-transition-simulator/202609280014/mod/engine/string-design.mjs:1-60 · blob 6a2cb152d9d94f7d9c4efc283b87b43d31fbb0b4 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: duplicate_candidate
// COPIED UNCHANGED from world/v12 string-design.mjs at v12 commit 3adcee9 (file last changed 8903e78). Modular star family: public #148079 stringDesign.
// Do not edit here: change the source and re-copy. Everything below this header is byte-identical to the source.
// string-design.mjs: the string voltage of the solar block, worked out in the open. Owner's instruction (27 Sept): show
// the truth, don't expose people. Modules in series and the site's coldest cell temperature are the owner's to change
// (typed "string 28", "temp min -10", or the block panel); the cold open-circuit voltage is worked out for every power
// bin of the module class (any bin may be delivered, so the string is judged on the highest), with the headroom under
// the system voltage said in volts. Illustrative: early design, no warranty; the advisory below always goes with it.
// Pure: no DOM, no fetch.

import { coldVocOf, highestVoc, VOC_FACTOR } from './module-catalogue.mjs';

export const STRING_ADVICE = 'Study string voltages in detail: get module-maker and inverter-maker sign-off, or a chartered engineer\'s '
  + 'review if borderline, or use fewer modules in series for over-voltage headroom.';
export const ILLUSTRATIVE = 'Illustrative — early design, no warranty; confirm with a qualified engineer.';
export const BORDERLINE_PCT = 3; // headroom under this share of the system voltage is called borderline (an assumption, editable)

const num = v => (v === null || v === undefined || v === '' ? NaN : Number(v));

/**
 * stringDesign({ cls, cat, mps, tempMinC, systemV }) -> { mps, tempMinC, systemV, bins, worst, stringV, headroomV, ok, borderline, most }
 * cls: a module class (module-catalogue.mjs); cat: the catalogue (coldest_cell_C, system_voltage_V are its defaults).
 */
export function stringDesign({ cls, cat = {}, mps, tempMinC, systemV } = {}) {
  if (!cls || !(mps > 0)) return null;
  const t = Number.isFinite(num(tempMinC)) ? num(tempMinC) : cat.coldest_cell_C ?? -10, V = num(systemV) > 0 ? num(systemV) : cat.system_voltage_V || 1500;
  // Each bin two ways (the coldest cell, and Voc x 1.15); the stricter is the sizing value (module-catalogue.mjs coldVocOf).
  const bins = cls.electrical.bins.map(b => { const c = coldVocOf({ voc: b.voc, coeffPctPerK: cls.temp_coeff.voc, tC: t });
    return { pmax: b.pmax, voc: b.voc, vocCold: c.v, byTemp: c.byTemp, byFactor: c.byFactor, rule: c.rule, stringV: c.v * mps }; });
  const hi = highestVoc(cls), worst = bins.find(b => b.pmax === hi.pmax && b.voc === hi.voc), stringV = worst.stringV, headroomV = V - stringV;
  return { mps, tempMinC: t, systemV: V, bins, worst, stringV, headroomV, ok: stringV <= V, borderline: stringV <= V && headroomV < V * BORDERLINE_PCT / 100,
    most: Math.floor(V / worst.vocCold + 1e-9), rule: worst.rule };
}

/** The HUD line: red when over, neutral with the headroom when under. */
export function stringLine(d) {
  const v = Math.round(d.stringV), tail = `@ ${d.rule === `Voc × ${VOC_FACTOR}` ? `VOC × ${VOC_FACTOR} (STRICTER THAN ${d.tempMinC}°C)` : `${d.tempMinC}°C`}`
    + ` · ${d.worst.pmax} W BIN · ${d.mps} MOD`;
  return d.ok ? `STRING VOC ${v} V · ${Math.floor(d.headroomV)} V HEADROOM${d.borderline ? ' (BORDERLINE)' : ''} ${tail}`
    : `STRING VOC ${v} V > ${d.systemV} V ${tail}`;
}

/** The block readout's words: every bin's cold Voc, the string, the headroom, the most in series. */
export function stringWords(d) {
  const bins = d.bins.map(b => `${b.pmax} W ${b.vocCold.toFixed(1)} V`).join(' · ');
  return {
    bins: `one module, the stricter of ${d.tempMinC} °C and Voc × ${VOC_FACTOR} (${d.rule} governs): ${bins}`,
    string: `${d.mps} in series: ${Math.round(d.stringV)} V (highest bin, ${d.worst.pmax} W) against ${d.systemV} V · `
      + (d.ok ? `${Math.floor(d.headroomV)} V headroom${d.borderline ? ', borderline' : ''}` : `OVER by ${Math.ceil(-d.headroomV)} V`)
      + ` · at most ${d.most} in series on this rule`
  };
}

/** A one-bin module class from typed values (a plant with a typed module Voc and power), for stringDesign. */
export const typedClass = ({ wp, voc, coeffPctPerK }) => ({ id: 'typed', electrical: { bins: [{ pmax: wp, voc }], nominal_W: wp }, temp_coeff: { voc: coeffPctPerK } });

/** Strings and inverters for a count of modules: whole strings, modules left over, inverters to connect every string. */
export function stringCounts({ modules, mps, stringsPerInverter = 24, inverters = null }) {
  const strings = Math.floor(modules / mps), need = Math.ceil(strings / stringsPerInverter);
  return { strings, leftover: modules - strings * mps, invertersNeeded: need, spare: inverters === null ? null : Math.max(0, strings - inverters * stringsPerInverter) };
}

Structure Presets

A JavaScript module in the engine folder of GlobalGrid2050 that works with solar and transformers.

Set aside from the main view: 97% of its lines are the same as solar-design-studio/202609271853-site-world/world/structure-presets.mjs (globalgrid2050), which stays. (near-copy-of, proposed by families.py). 97% of lines shared with Structure Presets; read that one first. All set-aside files, with reasons. Nothing was deleted.

Evidence
  • line-jaccard 0.9706 to globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-design-studio/202609271853-site-world/world/structure-presets.mjs:1-72 a95aa3b87591ba199e38b3379e91c1ec324126f2
  • sha256 340a02e1ad5b60277754b94d8675cca7e09780df526e419f9f1a47b04a747c78
  • target sha256 e896d7831c15e470f6b52448d906e9fd56c0d80a12072a5bbc2d572e47b60c12
  • group of 3 (identity.json near-copy edges >= 0.9)
  • canonical rule: reachable, newest stamp, core repo, most lines

transformglobalgrid2050 / energy-transition-simulator/202609280014/mod/engine/structure-presets.mjs · lines 1–74 of 74 · version 2026-09-28 00:14 · Not reached from any entry point (candidate for review) · pattern presetById (shared by 3 files)

What it does
It calculates solar and transformers. Defines presetById, presetText.
Why it exists in the grid workflow
Domain stage upstream_foresight (topic 'markets-data'): 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: solar, transformers.
Downstream impact
Used directly by 3 files: Cmd Grammar Plant (globalgrid2050); Cmd Grammar (globalgrid2050); Cmd Model (globalgrid2050).
What it achieves
It is built from the preset by id helper (`presetById`) and the preset text helper (`presetText`). Generic plant presets from an open-data study of large operational UK solar farms, typed as "preset " (or "structure "). Its code works with 3 MVA, 3 MW and 300 kVA.
Why it matters
Imported by Cmd Grammar Plant, Cmd Grammar and Cmd Model.
Application
globalgrid2050 · energy-transition-simulator/202609280014/mod/engine · JavaScript module
Uses
none found
Used by
imported by Cmd Grammar Plant (import), imported by Cmd Grammar (import), imported by Cmd Model (import)
Produces
PRESET_NOTE, PRESETS, PRESET_IDS, presetById, presetText
Defines here
presetById, presetText
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 energy-transition-simulator/202609280014/mod/engine/structure-presets.mjs:1-74 · blob 08a9df5576a1285e1d02b09d25312463ad43eeca · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: duplicate_candidate
// COPIED UNCHANGED from world/v12 structure-presets.mjs at v12 commit 3adcee9 (file last changed a83209f). Modular star family: not known to star-find.
// Do not edit here: change the source and re-copy. Everything below this header is byte-identical to the source.
// structure-presets.mjs: generic plant presets from an open-data study of large operational UK solar farms, typed as
// "preset <id>" (or "structure <id>"). Each sets typed values the owner can change afterwards; none sets the Solar
// block (its defaults are the owner's and stay as they are).
//
// The study measured rows as built from open 1 m LiDAR (a GPU pair with a CPU witness) at a few older plants, and read
// public planning and trade records at the others. Every preset says its evidence tier: measured (as built), public
// design (planning or public counts), or hypothesis (consistent but not resolved). Sites are not named, and no preset
// reproduces any one plant: module classes are generic and the values sit inside the ranges found.
// Measured distribution behind the defaults: row pitch 8.0-9.3 m as built at four plants (the v09 default was 11.97 m);
// plan cover (GCR) 0.41-0.52 at 2 portrait plants and 0.63-0.70 at 6-high landscape plants; tilt 15-25°.
// Pure: no DOM, no imports.

export const PRESET_NOTE = 'Generic preset from open-data studies of operational UK plants; illustrative class values, not a design for any site.';

// set: typed values (cmd-grammar KEYS). moduleLong/moduleShort are generic module classes (60-cell about 1.65 x 0.99 m).
export const PRESETS = Object.freeze([
  { id: 'central-6l-20', label: 'Central inverters, landscape 6-high tables, about 20°, dense',
    set: { layout: 'south', tiers: 6, orient: 'landscape', tableCols: null, tilt: 20, gcr: 0.65, edge: 0.7, moduleLong: 1.65, moduleShort: 0.99,
      wp: 260, voc: 38, inverterClass: 'central', inverterKVA: 2000, invertersPerStation: 1, packing: 'fields' },
    ranges: 'tilt 18-20°; lowest edge 0.65-0.8 m; top 2.35-3.0 m; slant 6.0-6.5 m; pitch 9.1-9.2 m; GCR 0.63-0.66; row runs 140-150 m',
    evidence: 'measured as built at two plants (6-high landscape chosen over 3P, 4L and 2P by slant length and by row length x public module count)' },
  { id: 'central-deep-15', label: 'Central inverter skids of about 3 MVA, deep 6-7 m tables, 15°, flat drained levels',
    set: { layout: 'south', tiers: 6, orient: 'landscape', tableCols: null, tilt: 15, gcr: 0.66, edge: 0.6, moduleLong: 2.0, moduleShort: 1.0,
      wp: 380, voc: 48, inverterClass: 'central', inverterKVA: 3000, invertersPerStation: 1, packing: 'fields' },
    ranges: 'pitch 9.3 m; plan GCR about 0.7; high edge about 2.1 m; tilt at least 14°',
    evidence: 'rows measured as built (pitch, depth), skid class public; the table form (3P, 4P or 6L) is a hypothesis' },
  { id: 'central-2p-22', label: 'Central inverters with string combiners, 2 portrait, 22°, one spine with pad pairs',
    set: { layout: 'south', tiers: 2, orient: 'portrait', tableCols: null, tilt: 22, gcr: 0.41, edge: 0.96, moduleLong: 1.65, moduleShort: 0.99,
      wp: 255, voc: 38, inverterClass: 'central', inverterKVA: 1500, invertersPerStation: 2, packing: 'fields', bandM: 2000, runM: 280 },
    ranges: 'tilt 21-24°; plan depth 3.2-3.35 m; pitch 8.0 m; GCR 0.41; rows unbroken up to about 280 m; one spine, no east-west tracks',
    evidence: 'measured as built at one plant (rows, pitch, spine, pad pairs); inverter class public' },
  { id: 'central-4l-25', label: 'Container central stations, landscape 4-high (full and half tables), 25°, pitch follows the slope',
    set: { layout: 'south', tiers: 4, orient: 'landscape', tableCols: 26, tilt: 25, gcr: 0.53, edge: 0.8, moduleLong: 2.28, moduleShort: 1.13,
      wp: 550, voc: 50, inverterClass: 'central', inverterKVA: 2250, invertersPerStation: 2, packing: 'fields', rowGap: 'slope' },
    ranges: 'full 4 x 26 and half 4 x 13 tables; top about 2.9 m; pitch 8.66-12.69 m stretched on north-falling ground',
    evidence: 'public design at one plant (planning drawings); a slope-following fill matched its planning module count within 1 %' },
  { id: 'central-3l-25', label: 'Central inverters in pairs at switchgear stations, landscape 3-high, 25°, 3 m height cap',
    set: { layout: 'south', tiers: 3, orient: 'landscape', tableCols: null, tilt: 25, gcr: 0.4, edge: 1.0, postMax: 3,
      inverterClass: 'central', inverterKVA: 1700, invertersPerStation: 2, packing: 'fields' },
    ranges: 'clear gap between rows about 5.4 m; highest point 3 m',
    evidence: 'hypothesis (a planning drawing reference, not seen); the built capacity may need 4L or 2P' },
  { id: 'container-2p', label: 'Container inverter and transformer stations of about 3 MW at zone centres, 2 portrait, 20°',
    set: { layout: 'south', tiers: 2, orient: 'portrait', tableCols: null, tilt: 20, gcr: 0.5, edge: 0.85,
      inverterClass: 'string', inverterKVA: 300, invertersPerStation: 10, packing: 'fields' },
    ranges: 'tilt 10-30°; lowest edge 0.8-0.9 m; top at most 3 m; row gap 2-6 m; 20 ft or 40 ft containers',
    evidence: 'public design at three plants; the inverter class is not stated publicly (string inverters assumed here)' },
  { id: 'string-ew-bifacial', label: 'String inverters, east-west bifacial, tight gap, large field transformers',
    set: { layout: 'east-west', tiers: 1, orient: 'portrait', tableCols: null, tiltEw: 10, pitch: 6, moduleLong: 2.38, moduleShort: 1.3,
      wp: 660, voc: 46, inverterClass: 'string', inverterKVA: 300, invertersPerStation: 30, packing: 'fields' },
    ranges: 'gap between tables about 1 m; pitch about 6 m; two-sided cover about 0.79',
    evidence: 'public design at one plant; the 1 m gap was fitted, not measured' },
  { id: 'string-2p-modern', label: 'String inverters, 2 portrait bifacial, 690 W class, GCR about 0.5',
    set: { layout: 'south', tiers: 2, orient: 'portrait', tableCols: null, tilt: 22, gcr: 0.52, moduleLong: 2.38, moduleShort: 1.3,
      wp: 690, voc: 48, inverterClass: 'string', inverterKVA: 300, invertersPerStation: 20, packing: 'fields' },
    ranges: 'tilt 20-25°; GCR about 0.52; about 170 string inverters of 300 kVA for 50 MW',
    evidence: 'public counts at one plant; the table geometry is assumed' },
  { id: 'early-2p', label: 'Early small plant, 2 portrait, shallow pitch',
    set: { layout: 'south', tiers: 2, orient: 'portrait', tableCols: null, tilt: 20, gcr: 0.45, moduleLong: 1.65, moduleShort: 0.99, wp: 250, voc: 38 },
    ranges: 'tilt 16-22°; plan depth 2.0-4.1 m; pitch 4.9-6.3 m',
    evidence: 'measured as built at two small arrays' },
  { id: 'uk-dense', label: 'UK practice default: south, GCR 0.5-0.55, 15-20°, 5 m setback',
    set: { layout: 'south', tiers: 2, orient: 'portrait', tableCols: null, tilt: 18, gcr: 0.52, fence: 5, packing: 'fields' },
    ranges: 'GCR 0.5-0.55; tilt 15-20°; fence setback 5 m',
    evidence: 'fitted: brings capacity within about 3-11 % of public DC figures at four plants (capacity match only, not geometry)' }
]);
export const PRESET_IDS = PRESETS.map(s => s.id);
export const presetById = id => PRESETS.find(s => s.id === id) || null;

/** The presets in words (typed "preset" alone). */
export function presetText() {
  return ['Presets (type preset <name>):', ...PRESETS.map(s => `${s.id}: ${s.label}. ${s.ranges}. Evidence: ${s.evidence}.`), PRESET_NOTE].join('\n');
}

Structures

A JavaScript module in the engine folder of GlobalGrid2050 that parses format (`parseFormat`) and formats name (`formatName`) and refusal (`formatRefusal`) (units: kVA), using IEC 62548-1.

Set aside from the main view: 98% of its lines are the same as solar-design-studio/202609271853-site-world/world/structures.mjs (globalgrid2050), which stays. (near-copy-of, proposed by families.py). 98% of lines shared with Structures; read that one first. All set-aside files, with reasons. Nothing was deleted.

Evidence
  • line-jaccard 0.982 to globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-design-studio/202609271853-site-world/world/structures.mjs:1-134 0e94499cf3f8a12465ef87a0cd2163fc888b37db
  • sha256 019b7e48d4df56c440f55ab1c3e23e6b923ec7369750eb5779192a6d21ecec6e
  • target sha256 28df7560ddaba67cee4be69399be63a1b43b399032a5640b588a0b51c9a5a295
  • group of 3 (identity.json near-copy edges >= 0.9)
  • canonical rule: reachable, newest stamp, core repo, most lines

ingestglobalgrid2050 / energy-transition-simulator/202609280014/mod/engine/structures.mjs · lines 1–136 of 136 · version 2026-09-28 00:14 · Not reached from any entry point (candidate for review) · pattern structureChecks (shared by 3 files)

What it does
It lists and searches its content. Defines 11 functions or classes, including parseFormat, formatName, formatRefusal, tableShape, halfCols.
Why it exists in the grid workflow
Domain stage upstream_foresight (topic 'markets-data'): 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.
Downstream impact
Used directly by 3 files: Cmd Grammar (globalgrid2050); Cmd Model (globalgrid2050); Plant Layout (globalgrid2050).
What it achieves
It parses format (`parseFormat`), formats name (`formatName`) and formats refusal (`formatRefusal`). The mounting structures the typed bar can build, and the structure checks they raise.
Why it matters
Imported by Cmd Grammar, Cmd Model and Plant Layout.
Application
globalgrid2050 · energy-transition-simulator/202609280014/mod/engine · JavaScript module
Uses
none found
Used by
imported by Cmd Grammar (import), imported by Cmd Model (import), imported by Plant Layout (import)
Produces
STRUCTURE_NOTE, parseFormat, formatName, FORMATS, DEFAULT_COLS, formatRefusal, tableShape, halfCols, pitchStretch, winterNoonDeg, STRUCTURES, structureById
Defines here
parseFormat, formatName, formatRefusal, tableShape, halfCols, pitchStretch, winterNoonDeg, structureById, catalogueText, mpptCap, structureChecks
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 energy-transition-simulator/202609280014/mod/engine/structures.mjs:1-136 · blob 8c2a10d531afe45be87b784b6c5c0068d3fb1d99 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: duplicate_candidate
// COPIED UNCHANGED from world/v12 structures.mjs at v12 commit 3adcee9 (file last changed f52e11f). Modular star family: public #148673 parseFormat.
// Do not edit here: change the source and re-copy. Everything below this header is byte-identical to the source.
// structures.mjs: the mounting structures the typed bar can build, and the structure checks they raise. Pure: no DOM, no imports.
//
// TABLE FORMATS  "kPn" or "kLn": k modules high up the slope (tiers), portrait (P) or landscape (L), n modules along
//   each tier. South-facing fixed tilt takes 2P, 3P, 4P and landscape 3L, 4L, 5L, 6L (the landscape tables of UK
//   central-inverter plants, measured as built 4 and 6 high); east-west takes 1P (one portrait module each side of
//   the ridge); trackers take 1P or 2P across the torque tube, with 1 to 4 strings along a row. Half tables (half the
//   modules along each tier) fill the ends of rows where a full table does not fit (plant-packing.mjs).
// CATALOGUE  five generic structure classes from the structure study (27 Sept): class ranges only, generic labels; no
//   product, maker, site or person is named, no datasheet text or table copied. Each preset sets typed values the
//   owner can change afterwards; every figure is illustrative and to be replaced by the chosen product's datasheet,
//   the project spec and the geotechnical report.
// CHECKS
//   slope-aware row gap  on ground falling to the north at s (m/m), the winter-noon shadow reaches further: the
//     no-shade pitch is (depth tan(el) + rise) / (tan(el) - s). The typed pitch is stretched by the ratio of that pitch
//     to its flat-ground value, so a north-facing row is shaded no more than the typed pitch shades on the flat.
//     Never shrunk on south-facing ground. Where tan(el) <= s no pitch clears the shadow: the stretch is capped.
//   tracker cross slope  slope across a tracker row (east-west): over the review line the row is kept and flagged for
//     the maker's review; over the exclusion line the row is left out.
//   post height          the post reveal against a hard maximum (a tall rear post at a steep tilt), flagged on the HUD.
//   MPPT cap             strings per inverter at most MPPT inputs x strings per input; with short strings the cap
//     can hold DC/AC under the target, which is said.

export const STRUCTURE_NOTE = 'Illustrative class ranges, generic; replace with the chosen product\'s datasheet, the project spec and the geotechnical report.';

/** "3P12" -> { tiers: 3, orient: 'portrait', cols: 12 }; "4L" -> { tiers: 4, orient: 'landscape', cols: null }; else null. */
export function parseFormat(w) {
  const m = /^(\d)([pl])(\d*)$/i.exec(String(w || ''));
  return m ? { tiers: Number(m[1]), orient: m[2].toLowerCase() === 'l' ? 'landscape' : 'portrait', cols: m[3] ? Number(m[3]) : null } : null;
}
export const formatName = (tiers, orient, cols) => `${tiers}${orient === 'landscape' ? 'L' : 'P'}${cols || ''}`;

// Formats each layout builds; anything else is refused in words.
export const FORMATS = Object.freeze({ south: ['2P', '3P', '4P', '3L', '4L', '5L', '6L'], 'east-west': ['1P'], tracker: ['1P', '2P'] });
export const DEFAULT_COLS = 12; // 3P, 4P and landscape tables when no count is typed (the study's example tables)

/** Refusal in words when a format does not suit a layout, else null. */
export function formatRefusal(layout, tiers, orient) {
  const f = formatName(tiers, orient), ok = FORMATS[layout] || [];
  if (ok.includes(f)) return null;
  const where = Object.entries(FORMATS).filter(([, v]) => v.includes(f)).map(([k]) => k);
  return `${f} tables are ${where.length ? `built for ${where.join(' and ')} layouts` : 'not built here'}; ${layout} takes ${ok.join(', ')}`;
}

/**
 * The table's shape from its format: { tiers, orient, along, up, cols, slope } with along = module side along the row,
 * up = side up the slope, slope = the slant (tiers x up + gaps). p: { moduleLongM, moduleShortM, moduleGapM, tiers, orient, tableCols }.
 */
export function tableShape(p, mps, layout) {
  const tracker = layout === 'tracker', ew = layout === 'east-west';
  const tiers = ew ? 1 : Math.max(1, Math.round(p.tiers || (tracker ? 1 : 2)));
  const orient = !tracker && !ew && p.orient === 'landscape' ? 'landscape' : 'portrait';
  const along = orient === 'landscape' ? p.moduleLongM : p.moduleShortM, up = orient === 'landscape' ? p.moduleShortM : p.moduleLongM;
  const slope = tiers * up + (tiers - 1) * p.moduleGapM;
  let cols;
  if (tracker) cols = Math.ceil((p.trackerStrings || 2) * mps / tiers);
  else if (ew) cols = mps;
  else cols = p.tableCols || (tiers === 2 && orient === 'portrait' ? mps : DEFAULT_COLS);
  return { tiers, orient, along, up, slope, cols, modules: tiers * cols * (ew ? 2 : 1) };
}
/** Columns of a half table: half the modules along each tier (rounded up), at least one. */
export const halfCols = cols => Math.max(1, Math.ceil(cols / 2));

// ---- slope-aware row gap ----
/** Pitch stretch for ground falling to the north at s (m/m; negative = rising): >= 1, capped at maxStretch. */
export function pitchStretch({ depth, rise, elevDeg, fallN, maxStretch = 2 }) {
  const t = Math.tan(elevDeg * Math.PI / 180);
  if (!(fallN > 0) || !(t > 0)) return 1;
  if (fallN >= t * 0.98) return maxStretch;
  const flat = (depth * t + rise) / t, slopeP = (depth * t + rise) / (t - fallN);
  return Math.min(maxStretch, Math.max(1, slopeP / flat));
}
export const winterNoonDeg = latDeg => 90 - latDeg - 23.44;

// ---- the catalogue ----
// set: typed values (cmd-grammar KEYS) the preset puts in; ranges: the class's range figures in words.
export const STRUCTURES = Object.freeze([
  { id: 'fixed-2p', study: 's1', label: 'Fixed tilt, south facing, 2P portrait (3P and 3L/4L variants; one or two post lines)',
    set: { layout: 'south', tiers: 2, orient: 'portrait', tableCols: null, posts: 2, tilt: 25, gcr: 0.4, edge: 0.8, postMax: 3.0 },
    ranges: 'tilt 15-35° (2P), 5-20° (3P); GCR 0.3-0.5; lowest edge 0.5-1.2 m; post spacing 3-7.5 m; slope 15 % along, 20 % across; twist 3°' },
  { id: 'east-west', study: 's2', label: 'Fixed east-west low-tilt ridge, 1P each face',
    set: { layout: 'east-west', tiers: 1, orient: 'portrait', tableCols: null, posts: 2, tiltEw: 10, edge: 0.8, postMax: 3.0 },
    ranges: 'tilt 8-15°; gap between ridges 2-4 m; ridge gap 0.1-0.5 m; lowest edge 0.5-1.0 m piled; slope 20 % along, 15 % across' },
  { id: 'tracker-1p', study: 's3', label: 'Single-axis tracker, 1P portrait, independent rows',
    set: { layout: 'tracker', tiers: 1, orient: 'portrait', tableCols: null, trackerStrings: 2, gcr: 0.35, postMax: 3.0 },
    ranges: 'GCR 0.28-0.5; hub 1.2-1.6 m; rotation 45-60°; 2-4 strings a row; post spacing 6-12 m; 8.5-15 % along; across the row: maker review over 7 %, left out over 10 %' },
  { id: 'tracker-2p', study: 's4', label: 'Single-axis tracker, 2P portrait, independent rows',
    set: { layout: 'tracker', tiers: 2, orient: 'portrait', tableCols: null, trackerStrings: 4, gcr: 0.38, postMax: 3.0 },
    ranges: 'GCR 0.30-0.50; hub 2.1-2.6 m; rotation 50-60°; 4 strings a row; post spacing 7-10.5 m; 10 % along' },
  { id: 'high-clearance', study: 's5', label: 'High-clearance agrivoltaic, fixed tilt, 2P portrait (the special classes compared: dual-row tracker, vertical bifacial)',
    set: { layout: 'south', tiers: 2, orient: 'portrait', tableCols: null, posts: 2, tilt: 20, gcr: 0.3, edge: 2.5, postMax: 5.0 },
    ranges: 'clear height at least 2.1 m after tolerance (4-4.5 m for tractors); tilt 10-30°; GCR 0.2-0.35; post spacing 6-12 m; reveal warn 4.3 m, fail 5 m' }
]);
export const structureById = id => STRUCTURES.find(s => s.id === id) || null;
export const STRUCTURE_IDS = STRUCTURES.map(s => s.id);

/** The catalogue in words (typed "structure" alone). */
export function catalogueText() {
  return ['Structures (type structure <name>):', ...STRUCTURES.map(s => `${s.id}: ${s.label}. ${s.ranges}.`), STRUCTURE_NOTE].join('\n');
}

// ---- MPPT cap ----
/** Strings per inverter the MPPTs allow: inputs x strings per input. */
export const mpptCap = ({ mppts = 12, stringsPerMppt = 2 } = {}) => mppts * stringsPerMppt;

/**
 * The structure checks of a laid-out plant, for the HUD: facts { piles summary, rules, skipped, crossReview, table,
 * template counts and params, stretched }. Returns [{ id, failed, line, inputs, standard }].
 */
export function structureChecks(f = {}) {
  const out = [], s = f.piles, R = f.rules || {};
  if (s && Number.isFinite(s.revealFail)) {
    const max = R.revealFailM ?? 3;
    out.push({ id: 'post-height', failed: s.revealFail > 0, line: `${s.revealFail} POSTS OVER ${max.toFixed(1)} M${f.tiltDeg ? ` · TILT ${Math.round(f.tiltDeg)}°` : ''}`,
      inputs: [['Posts over the maximum', s.revealFail], ['Maximum reveal', `${max} m (editable: structure preset or piles rules)`],
        ['Tallest post once graded', `${(s.finishedP?.[2] ?? s.revealP?.[2] ?? NaN).toFixed(2)} m`], ['Posts in all', s.piles]],
      standard: 'EN 1993-5 and EN 1997-1 (piles in bending and embedment); lower tilt, fewer tiers or grading lower the posts' });
  }
  if (f.tracker && f.skipped) {
    const n = f.crossReview || 0, x = f.skipped.cross || 0;
    out.push({ id: 'tracker-cross', failed: n > 0 || x > 0, line: `TRACKER CROSS SLOPE: ${n} ROWS OVER ${f.crossReviewPct ?? 7}% (REVIEW) · ${x} LEFT OUT OVER ${f.crossMaxPct ?? 10}%`,
      inputs: [['Rows kept, over the review line', n], ['Rows left out', x], ['Review line', `${f.crossReviewPct ?? 7} %`], ['Exclusion line', `${f.crossMaxPct ?? 10} %`]],
      standard: 'Tracker maker\'s slope limits (manufacturer data, generic); slope-aware backtracking studied per site' });
  }
  const c = f.counts, P = f.params;
  if (c && P && P.inverterClass !== 'central') {      // central inverters take strings through combiner boxes: no MPPT cap
    const cap = mpptCap(P), stringKWp = c.modulesPerString * P.moduleWp / 1000, dcac = c.stringsPerInverter * stringKWp / P.inverterKVA;
    const capped = c.stringsPerInverter >= cap && dcac < (P.dcAcRatio ?? 1.25) - 0.05;
    out.push({ id: 'mppt-cap', failed: capped, line: `DC/AC ${dcac.toFixed(2)} · STRINGS PER INVERTER CAPPED AT ${cap} (${P.mppts ?? 12} MPPT × ${P.stringsPerMppt ?? 2})`,
      inputs: [['Strings per inverter', c.stringsPerInverter], ['MPPT inputs × strings each', `${P.mppts ?? 12} × ${P.stringsPerMppt ?? 2} = ${cap}`],
        ['String', `${c.modulesPerString} × ${P.moduleWp} W = ${stringKWp.toFixed(1)} kWp`], ['Inverter', `${P.inverterKVA} kVA`], ['DC/AC target', P.dcAcRatio ?? 1.25]],
      standard: 'IEC 62548-1 (array design: string and sub-array connection); inverter MPPT limits from the chosen inverter\'s data', quiet: !capped });
  }
  return out;
}

Sub Grammar

A JavaScript module in the engine folder of GlobalGrid2050 that parses sub command (`parseSubCommand`), covering substations and the Renewable Energy Planning Database (REPD) register. It parses sub command (`parseSubCommand`).

ingestglobalgrid2050 / energy-transition-simulator/202609280014/mod/engine/sub-grammar.mjs · lines 1–21 of 21 · version 2026-09-28 00:14 · Not reached from any entry point (candidate for review) · pattern parseSubCommand (shared by 2 files)

What it does
Defines parseSubCommand.
Why it exists in the grid workflow
Domain stage upstream_foresight (topic 'markets-data'): 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: substations, the REPD register.
Downstream impact
Used directly by 1 file: Cmd Grammar (globalgrid2050).
What it achieves
The typed words for the journey's first step (go substation 132 · next substation), kept out of `cmd-grammar.mjs` (as `repd-grammar.mjs` is) so that file stays under the line cap.
Why it matters
Imported by Cmd Grammar.
Application
globalgrid2050 · energy-transition-simulator/202609280014/mod/engine · JavaScript module
Uses
Journey (import)
Used by
imported by Cmd Grammar (import)
Produces
SUB_COMMANDS, parseSubCommand
Defines here
parseSubCommand
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 energy-transition-simulator/202609280014/mod/engine/sub-grammar.mjs:1-21 · blob 4e8d9fd5732a00af7c51bf72f9cb04d817fbcf1a · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: unreached_review
// COPIED UNCHANGED from world/v12 sub-grammar.mjs at v12 commit 3adcee9 (file last changed fda2061). Modular star family: not known to star-find.
// Do not edit here: change the source and re-copy. Everything below this header is byte-identical to the source.
// sub-grammar.mjs: the typed words for the journey's first step (go substation 132 · next substation), kept out of
// cmd-grammar.mjs (as repd-grammar.mjs is) so that file stays under the line cap. The words themselves are read by
// journey.mjs parseJourney; this file only turns its answer into a command. cmd-grammar.mjs asks parseSubCommand(line)
// BEFORE parseRepd: "next substation" would otherwise be refused by the REPD words ("next takes solar, bess or roof").

import { parseJourney } from './journey.mjs';

// A further 'go' entry for help and search (as REPD_COMMANDS adds its own).
export const SUB_COMMANDS = Object.freeze([
  { verb: 'go', usage: 'go substation 132  ·  next substation', words: 'fly substation journey kv next nearest compound fence' }
]);

/** parseSubCommand(line) -> null | { ok: true, verb: 'go', act: 'journey', set: {}, arg, line } | { ok: false, why, line } */
export function parseSubCommand(line) {
  const j = parseJourney(line);
  if (!j) return null;
  const text = String(line).trim();
  return j.error ? { ok: false, why: j.error, line: text } : { ok: true, verb: 'go', set: {}, act: 'journey', arg: j, line: text };
}

GPU Rows

A JavaScript file in GlobalGrid2050. It is built from the run step (`run`) and the init step (`init`).

renderglobalgrid2050 / energy-transition-simulator/202609280014/mod/gpu-rows.js · lines 1–39 of 39 · version 2026-09-28 00:14 · Not reached from any entry point (candidate for review)

What it does
It fetches data. Defines run, init. Side effects: changes the web page (DOM); makes network requests.
Why it exists in the grid workflow
Domain stage upstream_foresight (topic 'markets-data'): 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.
Inputs & outputs
In: JSON file gpu-rows-6502.json. Coordinate systems named: WGS84 / EPSG:4326.
What it achieves
Panel rows detected OFFLINE on the GPU (CuPy, NumPy witness: (local path)) from Esri z17 imagery, saved as lon/lat polylines (`mod/gpu-rows-6502.json`).
Why it matters
No other file in the estate was found to import it.
Application
globalgrid2050 · energy-transition-simulator/202609280014/mod · script
Uses
none found
Used by
none found
Produces
run, init
Defines here
run, init
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 energy-transition-simulator/202609280014/mod/gpu-rows.js:1-39 · blob 8e317d82dc4088bef02f3658472dcf44436a282e · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom, network · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: unreached_review
// gpu-rows: panel rows detected OFFLINE on the GPU (CuPy, NumPy witness: (local path))
// from Esri z17 imagery, saved as lon/lat polylines (mod/gpu-rows-6502.json), placed here in real coordinates through
// place-frame (WGS84 -> anchor tangent-plane metres) and revealed west to east as ten blocks, each with ONE buffer
// built once. Everything is an ESTIMATE from imagery, not a survey. Plain script; attaches to window.SIM.
(function () {
  'use strict';
  const BASE = (document.currentScript && document.currentScript.src.replace(/[^/]*$/, '')) || 'mod/';
  const H = 2.2, GROUPS = 10, STEP_MS = 350;
  let busy = false;
  async function run(btn) {
    const S = window.SIM, PF = window.__pf && window.__pf.PF; if (!S || !PF || busy) return; busy = true;
    try {
      btn.textContent = 'GPU rows: loading...';
      const doc = await (await fetch(BASE + 'gpu-rows-6502.json')).json();
      S.removeWhere(b => b.gpuRows);
      const [clon, clat] = doc.centre, an = PF.placeKey(clat, clon);
      const segs = doc.rows.map(([[lo0, la0], [lo1, la1]]) => { const a = PF.toLocal(an, la0, lo0, 0), b = PF.toLocal(an, la1, lo1, 0); return [a.x, a.y, b.x, b.y]; });
      let x0 = Infinity, x1 = -Infinity; for (const s of segs) { x0 = Math.min(x0, s[0]); x1 = Math.max(x1, s[0]); }
      const groups = Array.from({ length: GROUPS }, () => []);
      for (const [ax, ay, bx, by] of segs) {
        const g = groups[Math.min(GROUPS - 1, Math.floor((ax - x0) / (x1 - x0 + 1e-9) * GROUPS))];
        g.push([ax, ay, H, bx, by, H], [ax, ay, 0, ax, ay, H], [bx, by, 0, bx, by, H]);
      }
      S.map.easeTo({ center: [clon, clat], zoom: 15.6, pitch: 60, bearing: -30, duration: 1500 });
      S.info(`Panel rows ESTIMATED from satellite imagery (not measured): ${segs.length} runs, rows about ${doc.row_azimuth_deg_from_east.toFixed(1)} deg from east, ` +
        `repeat about ${doc.row_pitch_m} m (estimate). Detected on the GPU, NumPy witness identical (${doc.agreement.runs_cpu} = ${doc.agreement.runs_gpu} runs). ${doc.source}.`);
      for (let i = 0; i < GROUPS; i++) {
        const L = groups[i]; if (L.length) S.addBlock({ lon: an.lon, lat: an.lat, anchor: an, lines: L, buf: PF.wireBuffer(an, L), gpuRows: true, sat: true });
        btn.textContent = `GPU rows ${i + 1}/${GROUPS}`;
        await new Promise(r => setTimeout(r, STEP_MS));
      }
      S.map.easeTo({ bearing: 60, duration: 6000 });
      btn.textContent = `GPU rows (${segs.length})`;
    } catch (e) { btn.textContent = 'GPU rows: failed'; console.error(e); }
    busy = false;
  }
  function init() { if (!window.SIM) return setTimeout(init, 200); const b = window.SIM.addButton ? window.SIM.addButton('GPU rows', () => run(b)) : null; window.__gpuRows = () => run(b || { textContent: '' }); }
  init();
})();