GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Cables and conductors / energy-transition-simulator / prototype/mod/engine

Cable IEC and 3 more files (part 1)

A JavaScript module in the engine folder of Energy Transition Simulator that works with cables, solar and 33kV, using IEC 60287 and IEC 60287-1-1.

651 lines of JavaScript from energy-transition-simulator, in 4 files. Topic: Cables and conductors. Section 8 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. Cable IEC electrical · energy-transition-simulator / prototype/mod/engine/cable-iec.mjs lines 1–259
  2. Cable Rating electrical · energy-transition-simulator / prototype/mod/engine/cable-rating.mjs lines 1–96
  3. Cable Route electrical · energy-transition-simulator / prototype/mod/engine/cable-route.mjs lines 1–209
  4. Cmd Grammar Trench ingest · energy-transition-simulator / prototype/mod/engine/cmd-grammar-trench.mjs lines 1–87

Cable IEC

A JavaScript module in the engine folder of Energy Transition Simulator that works with cables, solar and 33kV, using IEC 60287 and IEC 60287-1-1.

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

Evidence
  • line-jaccard 0.9898 to globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-design-studio/202609271740-site-world/world/cable-iec.mjs:1-257 c218e4b046496efdb568f5a03e1b45bc8c92466a
  • sha256 2489b2937520f15b481efe16d0e9a0e6afccbe90b5193104e026d77e25676c15
  • target sha256 4ebfde6251f5cb1945d2486e1679dae595943271df97f0c5cff311e02d030360
  • group of 3 (identity.json near-copy edges >= 0.9)
  • canonical rule: reachable, newest stamp, core repo, most lines

electricalenergy-transition-simulator / prototype/mod/engine/cable-iec.mjs · lines 1–259 of 259 · Not reached from any entry point (candidate for review) · pattern screenLossFactors (shared by 3 files)

What it does
It calculates cables, solar and 33kV. Defines 16 functions or classes, including makeCable, rdcAt, skinY, acResistance, dielectricLoss.
Why it exists in the grid workflow
Domain stage experimental (path word 'prototype'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow. Domain terms in the code: cables, solar, 33kV, 1.5kV, 1kV.
Inputs & outputs
Voltage levels named: 33kV, 1.5kV, 1kV.
Downstream impact
Used directly by 2 files: Cmd Trench (energy-transition-simulator); Trench Plan (energy-transition-simulator).
What it achieves
It makes cable (`makeCable`) and is built from the rdc at helper (`rdcAt`) and the skin y helper (`skinY`). One buried single-core cable by the IEC 60287 thermal method: its build, losses and thermal resistances. Its code works with 33 kV, 1 kV and 1.5 kV.
Why it matters
Imported by Cmd Trench and Trench Plan.
Application
energy-transition-simulator · prototype/mod/engine · JavaScript module
Uses
none found
Used by
imported by Cmd Trench (import), imported by Trench Plan (import), mentioned in Standalone (comment link)
Produces
METAL, THERMAL_RHO, DEFAULTS, makeCable, PRESETS, rdcAt, acResistance, dielectricLoss, screenLossFactors, internalThermal, selfG, mutualG
Defines here
makeCable, rdcAt, skinY, acResistance, dielectricLoss, screenLossFactors, eddy, internalThermal, selfG, mutualG, trefoilTouchingG, cyclicSelfG, airGapT4, bundleDiameter, solarDayProfile, lossLoadFactor
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
energy-transition-simulator@a165ce6d56cb22271828874d68d570e8fa5e428a prototype/mod/engine/cable-iec.mjs:1-259 · blob 7d408b8454c414b507770d1de82240cb15577346 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: experimental · users: none · canonical: duplicate_candidate
// COPIED UNCHANGED from the v12 world (web/world/cable-iec.mjs) at v12 commit 3adcee9 (file last changed 3012c07). Modular star family: public #148197 makeCable.
// Do not edit here: change the source and re-copy. Everything below this header is byte-identical to the source.
// cable-iec.mjs: one buried single-core cable by the IEC 60287 thermal method: its build, losses and thermal resistances.
// Laid direct or in ducts, by the steady-state thermal method of the IEC 60287 family. The group model that rates
// many cables together is cable-group-iec.mjs.
//
// Method references, by number only (no text, tables or figures of any standard are reproduced here):
//   IEC 60287-1-1  clause 1.4 (rating equation), 2.1 (AC resistance, skin and proximity), 2.2 (dielectric loss),
//                  2.3 (screen and sheath loss: circulating and eddy currents, solid and single-point bonding)
//   IEC 60287-2-1  clause 4.1 (internal thermal resistances T1, T3), 4.2 (external T4: single buried cable,
//                  touching trefoil, groups by superposition of images, cables in ducts: air gap, duct wall, ground)
//   IEC 60853-1/-2 (cyclic rating) is the standard route for daily cycles; this file uses the published
//                  1957 loss-factor approach instead, see cyclicGround().
//
// Our own code and our own words. The equations of the method are implemented in our own code; no tabulated data is
// shipped (not the duct U, V, Y constants, not the material tables). Every material constant below is a physical
// property or a stated engineering assumption. The duct air gap is computed from heat-transfer physics; a user may
// pass the standard's duct constants from their own licensed copy.
//
// Indicative engineering only: a real design uses the cable maker's data, measured soil resistivity and a checked
// rating study. Units: SI inside (m, ohm/m, W/m, K.m/W); cable dimensions in mm at the API.
// Pure: no imports, no DOM.

const PI = Math.PI;
const SIGMA = 5.670374419e-8;            // radiation constant, W/m2K4
const G = 9.80665;

/** Conductor and screen metals: resistivity at 20 C (ohm.m) and temperature coefficient at 20 C (1/K). Physics. */
export const METAL = Object.freeze({
  Cu: Object.freeze({ rho20: 1.7241e-8, alpha20: 3.93e-3 }),
  Al: Object.freeze({ rho20: 2.8264e-8, alpha20: 4.03e-3 })
});

/**
 * Thermal resistivities of materials (K.m/W) = 1 / conductivity. Own assumptions from typical polymer
 * conductivities: XLPE ~0.29 W/mK, PE ~0.29, PVC ~0.17, HDPE duct ~0.40, PVC duct ~0.17.
 */
export const THERMAL_RHO = Object.freeze({ XLPE: 3.5, PE: 3.5, PVC: 6.0, HDPE: 2.5, PVCduct: 6.0, EPR: 3.5 });

export const DEFAULTS = Object.freeze({
  freq: 50, ambientC: 15, soilKmW: 1.2, thetaMaxC: 90,
  diffusivityM2h: 0.0018,                 // soil thermal diffusivity (about 5e-7 m2/s), for the cyclic option
  mu: 1,                                  // loss-load factor: 1 = continuous
  dryZone: null,                          // { rhoDry: 2.5, critRiseK: 35 } two-zone drying option (60287-1-1 1.4.2)
  ductAirUVY: null                        // [U, V, Y] from the user's licensed copy of 60287-2-1; null = own physics
});

// ---------------------------------------------------------------- cable build ----

/**
 * makeCable(spec) -> a frozen cable type with its geometry in mm.
 * spec = { kind: 'ac'|'dc', u0Kv, thetaMaxC,
 *   cond: { mat, area, fill=0.9, kR=1.10, r20OhmKm?, ks=1, kp=1 },
 *   ins: { tMm, condScreenMm=0, insScreenMm=0, rhoT, epsR=2.5, tanDelta=0.004 },
 *   screen: null | { mat='Cu', areaMm2, wireMm=1.0 },
 *   sheath: { tMm, rhoT }, odMm? }
 * kR scales the ideal solid-metal resistance up for stranding, lay and tolerance (own conservative assumption;
 * pass r20OhmKm from the maker's data or the conductor standard to replace it). ks, kp default 1 (conservative).
 */
export function makeCable(spec) {
  const c = spec.cond, i = spec.ins, sc = spec.screen || null, sh = spec.sheath;
  const metal = METAL[c.mat]; if (!metal) throw new Error(`cable-rating-iec: unknown metal ${c.mat}`);
  const dc = c.dcMm || Math.sqrt(4 * c.area / (PI * (c.fill || 0.9)));
  const dcs = dc + 2 * (i.condScreenMm || 0);                 // over conductor screen
  const dins = dcs + 2 * i.tMm;                                // over insulation
  const di = dins + 2 * (i.insScreenMm || 0);                  // over insulation screen
  const ds = sc ? di + 2 * (sc.wireMm || 1.0) : di;            // over metallic screen
  const od = spec.odMm || ds + 2 * sh.tMm;
  const r20 = c.r20OhmKm ? c.r20OhmKm / 1000 : metal.rho20 / (c.area * 1e-6) * (c.kR || 1.10);
  return Object.freeze({
    kind: spec.kind || 'ac', u0Kv: spec.u0Kv || 0, thetaMaxC: spec.thetaMaxC || 90, name: spec.name || '',
    cond: Object.freeze({ mat: c.mat, area: c.area, r20, alpha: metal.alpha20, ks: c.ks ?? 1, kp: c.kp ?? 1 }),
    ins: Object.freeze({ rhoT: i.rhoT ?? THERMAL_RHO.XLPE, epsR: i.epsR ?? 2.5, tanDelta: i.tanDelta ?? 0.004,
      t1Mm: (i.condScreenMm || 0) + i.tMm + (i.insScreenMm || 0) }),
    screen: sc ? Object.freeze({ mat: sc.mat || 'Cu', areaMm2: sc.areaMm2, ...METAL[sc.mat || 'Cu'],
      dMeanMm: (di + ds) / 2, tEqMm: sc.areaMm2 / (PI * (di + ds) / 2), dOutMm: ds }) : null,
    sheath: Object.freeze({ tMm: (od - ds) / 2, rhoT: sh.rhoT ?? THERMAL_RHO.PE }),
    dc, dcs, dins, di, ds, od
  });
}

/**
 * Generic builds for the owner's cases. Estimates, not catalogue data: replace with the maker's datasheet.
 * lvAl(area): 0.6/1 kV single-core Al XLPE, no metallic screen or armour.
 * mvAl(area): 19/33 kV single-core Al XLPE, Cu wire screen, PE oversheath.
 * dcCu(area): 1.5 kV DC single-core fine-stranded tinned Cu, cross-linked insulation and sheath (solar string cable).
 */
export const PRESETS = Object.freeze({
  lvAl: (area, o = {}) => makeCable({ kind: 'ac', u0Kv: 0.6, name: `LV ${area} Al`,
    cond: { mat: 'Al', area, ...o.cond }, ins: { tMm: area >= 300 ? 2.4 : 1.8, rhoT: THERMAL_RHO.XLPE },
    sheath: { tMm: area >= 300 ? 2.2 : 1.8, rhoT: THERMAL_RHO.PVC }, ...o }),
  mvAl: (area, o = {}) => makeCable({ kind: 'ac', u0Kv: 19, name: `33 kV ${area} Al`,
    cond: { mat: 'Al', area, ...o.cond },
    ins: { tMm: 8.0, condScreenMm: 0.8, insScreenMm: 1.0, rhoT: THERMAL_RHO.XLPE, epsR: 2.5, tanDelta: 0.004 },
    screen: { mat: 'Cu', areaMm2: area >= 630 ? 50 : 35, wireMm: 1.0 },
    sheath: { tMm: area >= 630 ? 3.6 : 3.2, rhoT: THERMAL_RHO.PE }, ...o }),
  dcCu: (area, o = {}) => makeCable({ kind: 'dc', u0Kv: 0, name: `DC ${area} Cu`,
    cond: { mat: 'Cu', area, kR: 1.18, fill: 0.78, ...o.cond }, ins: { tMm: 0.7, rhoT: THERMAL_RHO.XLPE },
    sheath: { tMm: 0.8, rhoT: THERMAL_RHO.XLPE }, ...o })
});

// ---------------------------------------------------------------- losses (60287-1-1 clause 2) ----

/** DC resistance per metre at theta (C). */
export const rdcAt = (cable, theta) => cable.cond.r20 * (1 + cable.cond.alpha * (theta - 20));

function skinY(x2) {                    // x2 = xs squared; three ranges of the published skin-effect method
  const x = Math.sqrt(x2);
  if (x <= 2.8) { const x4 = x2 * x2; return x4 / (192 + 0.8 * x4); }
  if (x <= 3.8) return -0.136 - 0.0177 * x + 0.0563 * x2;
  return 0.354 * x - 0.733;
}

/**
 * AC resistance per metre at theta: R = R'(1 + ys + yp). sMm = axial spacing between phase conductors
 * (for flat formation pass the geometric mean spacing). DC cables return R'.
 */
export function acResistance(cable, theta, sMm, freq = 50) {
  const r = rdcAt(cable, theta);
  if (cable.kind === 'dc') return { R: r, rdc: r, ys: 0, yp: 0 };
  const base = 8 * PI * freq / r * 1e-7;
  const ys = skinY(base * cable.cond.ks);
  const xp2 = base * cable.cond.kp, xp4 = xp2 * xp2, F = xp4 / (192 + 0.8 * xp4);
  const q = cable.dc / sMm;
  const yp = F * q * q * (0.312 * q * q + 1.18 / (F + 0.27));
  return { R: r * (1 + ys + yp), rdc: r, ys, yp };
}

/** Dielectric loss per phase, W/m: omega C U0^2 tan(delta), C from the insulation diameters. Zero for DC and LV. */
export function dielectricLoss(cable, freq = 50) {
  if (cable.kind === 'dc' || cable.u0Kv < 3) return 0;
  const C = cable.ins.epsR / (18 * Math.log(cable.dins / cable.dcs)) * 1e-9;
  return 2 * PI * freq * C * (cable.u0Kv * 1000) ** 2 * cable.ins.tanDelta;
}

/**
 * Screen loss factors lambda1 for each cable position of a three-phase single-core circuit.
 * formation: 'trefoil' | 'flat'; bonding: 'solid' (both ends) | 'single-point' | 'cross' (ideal cross-bonding);
 * sMm = axial spacing between adjacent phases; R = conductor AC resistance (ohm/m); thetaS = screen temperature.
 * Returns an array of 3 lambda1 (for flat: [outer lagging, middle, outer leading]).
 */
export function screenLossFactors(cable, { R, sMm, formation = 'trefoil', bonding = 'solid', thetaS = 70, freq = 50 }) {
  const sc = cable.screen;
  if (!sc || cable.kind === 'dc') return [0, 0, 0];
  const w = 2 * PI * freq;
  const Rs = sc.rho20 / (sc.areaMm2 * 1e-6) * (1 + sc.alpha20 * (thetaS - 20));
  const d = sc.dMeanMm;
  if (bonding === 'solid') {
    const X = 2 * w * 1e-7 * Math.log(2 * sMm / d);
    if (formation === 'trefoil') { const l = Rs / R / (1 + (Rs / X) ** 2); return [l, l, l]; }
    // Flat, not transposed: unequal circulating currents in the three screens (60287-1-1 2.3.1, 2.3.2 approach).
    const Xm = 2 * w * 1e-7 * Math.log(2), P = X + Xm, Q = X - Xm / 3, rs2 = Rs * Rs;
    const common = 0.75 * P * P / (rs2 + P * P) + 0.25 * Q * Q / (rs2 + Q * Q);
    const cross = 2 * Rs * P * Q * Xm / (Math.sqrt(3) * (rs2 + P * P) * (rs2 + Q * Q));
    const mid = Rs / R * Q * Q / (rs2 + Q * Q);
    return [Rs / R * (common + cross), mid, Rs / R * (common - cross)];
  }
  // Single-point or cross-bonded: no circulating current; eddy current loss only (60287-1-1 2.3.6).
  const m = w / Rs * 1e-7, r = d / (2 * sMm), m2 = m * m, base = m2 / (1 + m2);
  const beta1 = Math.sqrt(4 * PI * w / (1e7 * sc.rho20 * (1 + sc.alpha20 * (thetaS - 20))));
  const ts = sc.tEqMm, Ds = sc.dOutMm;
  const gs = 1 + (ts / Ds) ** 1.74 * (beta1 * Ds * 1e-3 - 1.6);
  const tail = (beta1 * ts) ** 4 / 12e12;
  const eddy = (l0, d1, d2) => Rs / R * (gs * l0 * (1 + d1 + d2) + tail);
  if (formation === 'trefoil') {
    const l0 = 3 * base * r * r, d1 = (1.14 * m ** 2.45 + 0.33) * r ** (0.92 * m + 1.66);
    const l = Math.max(0, eddy(l0, d1, 0)); return [l, l, l];
  }
  const lag = eddy(1.5 * base * r * r, -0.74 * (m + 2) * Math.sqrt(m) / (2 + (m - 0.3) ** 2) * r ** (m + 1),
    0.92 * m ** 3.7 * r ** (m + 2));
  const mid = eddy(6 * base * r * r, 0.86 * m ** 3.08 * r ** (1.4 * m + 0.7), 0);
  const lead = eddy(1.5 * base * r * r, 4.7 * m ** 0.7 * r ** (0.16 * m + 2), 21 * m ** 3.3 * r ** (1.47 * m + 5.06));
  return [lag, mid, lead].map((x) => Math.max(0, x));
}

// ---------------------------------------------------------------- thermal resistances (60287-2-1 clause 4) ----

/** Internal thermal resistances of a single-core cable, K.m/W: T1 insulation (with semicons), T3 oversheath. */
export function internalThermal(cable) {
  const T1 = cable.ins.rhoT / (2 * PI) * Math.log(1 + 2 * cable.ins.t1Mm / cable.dc);
  const T3 = cable.sheath.rhoT / (2 * PI) * Math.log(1 + 2 * cable.sheath.tMm / cable.ds);
  return { T1, T2: 0, T3 };
}

/** Self term of an isolated buried source: ln(u + sqrt(u^2 - 1)), u = 2L/De (image method, isothermal surface). */
export const selfG = (Lm, DeMm) => { const u = 2 * Lm / (DeMm / 1000); return Math.log(u + Math.sqrt(u * u - 1)); };

/** Mutual term between two buried sources: ln(d'/d), d' to the image of the other source above ground. */
export function mutualG(a, b) {
  const dx = a.x - b.x, d = Math.hypot(dx, a.y - b.y), di = Math.hypot(dx, a.y + b.y);
  return Math.log(di / d);
}

/**
 * Touching trefoil, equally loaded, direct in ground, hottest cable (60287-2-1 4.2.4 approach), as a multiple of
 * rho/(2 pi): 3 [ln(2u) - 0.630]; L to the trefoil centre. Returned as {near, far} so the cyclic option can weight it.
 */
export function trefoilTouchingG(Lm, DeMm) {
  const u = 2 * Lm / (DeMm / 1000);
  return 3 * (Math.log(2 * u) - 0.630);
}

/**
 * Cyclic ground term (the published 1957 loss-factor method): the soil inside diameter Dx sees the peak loss, beyond it the mean
 * (loss-load factor mu). Dx = 1.02 sqrt(24 h * diffusivity). Returns the self G to use in place of selfG.
 */
export function cyclicSelfG(Lm, DeMm, mu, diffusivityM2h) {
  if (mu >= 1) return selfG(Lm, DeMm);
  const Dx = 1.02 * Math.sqrt(24 * diffusivityM2h) * 1000;       // mm
  if (Dx <= DeMm) return mu * selfG(Lm, DeMm);
  return Math.log(Dx / DeMm) + mu * Math.log(4 * Lm * 1000 / Dx);
}

/**
 * Air gap between a cable (or a bundle of equivalent diameter DeMm) and the duct bore DbMm, K.m/W, for total heat
 * W (W/m) at mean air temperature thetaM. Own physics: conduction with natural convection in a horizontal annulus
 * (a published effective-conductivity correlation for a horizontal annulus) in parallel with grey-body radiation. If uvy = [U, V, Y] is given (the
 * user's licensed constants for 60287-2-1 4.2.7.1) the empirical form U / (1 + 0.1 (V + Y thetaM) De) is used.
 */
export function airGapT4(DeMm, DbMm, W, thetaM, uvy = null, eps = 0.9) {
  if (uvy) return uvy[0] / (1 + 0.1 * (uvy[1] + uvy[2] * thetaM) * DeMm);
  const Di = DeMm / 1000, Do = DbMm / 1000;
  if (Do <= Di * 1.0001) return 0;
  const Tk = thetaM + 273.15, k = 0.02414 + 7.4e-5 * thetaM, nu = 1.34e-5 + 9.2e-8 * thetaM, Pr = 0.71;
  const alpha = nu / Pr, Lc = (Do - Di) / 2, lnr = Math.log(Do / Di);
  const Grad = 4 * SIGMA * Tk ** 3 * PI * Di / (1 / eps + Di / Do * (1 / eps - 1));
  let T = lnr / (2 * PI * k);
  for (let it = 0; it < 12; it++) {
    const dT = Math.max(0.05, W * T);
    const RaL = G * (1 / Tk) * dT * Lc ** 3 / (nu * alpha);
    const Rac = lnr ** 4 / (Lc ** 3 * (Di ** -0.6 + Do ** -0.6) ** 5) * RaL;
    const keff = k * Math.max(1, 0.386 * (Pr / (0.861 + Pr)) ** 0.25 * Rac ** 0.25);
    const Tnew = 1 / (2 * PI * keff / lnr + Grad);
    if (Math.abs(Tnew - T) < 1e-6) { T = Tnew; break; }
    T = 0.5 * (T + Tnew);
  }
  return T;
}

/** Diameter of the circle that holds n touching cables of diameter d in a ring (own geometry). */
export const bundleDiameter = (n, d) => (n <= 1 ? d : d * (1 + 1 / Math.sin(PI / n)));

// ---------------------------------------------------------------- solar day ----

/** Per-unit current over 24 h for a solar plant: half-sine between sunrise and sunset, clipped at `clip`. */
export function solarDayProfile({ sunrise = 6, sunset = 18, clip = 1, stepH = 0.25 } = {}) {
  const out = [];
  for (let t = 0; t < 24; t += stepH) {
    const x = (t + stepH / 2 - sunrise) / (sunset - sunrise);
    out.push(x > 0 && x < 1 ? Math.min(clip, Math.sin(PI * x)) / clip : 0);
  }
  return out;
}

/** Loss-load factor mu = mean of (I / Imax)^2 over the day. */
export function lossLoadFactor(profile) {
  const m = Math.max(...profile); if (!(m > 0)) return 0;
  return profile.reduce((s, p) => s + (p / m) ** 2, 0) / profile.length;
}

Cable Rating

A JavaScript module in the engine folder of Energy Transition Simulator that works with cables and 33kV, using IEC 60287-1-1 and IEC 60287-2-1.

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

Evidence
  • line-jaccard 0.9744 to globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-design-studio/202609271740-site-world/world/cable-rating.mjs:1-94 95370a608d9286348dd20bc1ec55d68ded9084c7
  • sha256 7645f7ada8634a8fde11aae33ced7aa92b4fbde343303433764be979ad22cfb7
  • target sha256 d6b73ce4f65b11d0dc719312da35a6e43cf34bb8f36087452e148e3179862199
  • group of 3 (identity.json near-copy edges >= 0.9)
  • canonical rule: reachable, newest stamp, core repo, most lines

electricalenergy-transition-simulator / prototype/mod/engine/cable-rating.mjs · lines 1–96 of 96 · Not reached from any entry point (candidate for review) · pattern impedance (shared by 4 files)

What it does
It calculates cables and 33kV. Defines 7 functions or classes, including alR20, cuR20, build, rating, impedance.
Why it exists in the grid workflow
Domain stage experimental (path word 'prototype'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow. Domain terms in the code: cables, 33kV.
Inputs & outputs
Voltage levels named: 33kV.
Downstream impact
Used directly by 7 files: Cmd Trench (energy-transition-simulator); Plant Feeders (energy-transition-simulator); Single-Line Diagram (SLD) Rules (energy-transition-simulator); Block Build (energy-transition-simulator); and 3 more.
What it achieves
It is built from the al r20 helper (`alR20`), the cu r20 helper (`cuR20`) and the build step (`build`). Continuous current rating of a 33kV single-core aluminium XLPE cable laid direct in trefoil, by the steady-state method of IEC 60287-1-1 (losses) and IEC 60287-2-1 (thermal resistances), and the size a feeder segment needs for the load it carries. Its code works with 33 kV.
Why it matters
Imported by 7 files, including Cmd Trench, Plant Feeders and Single-Line Diagram (SLD) Rules.
Application
energy-transition-simulator · prototype/mod/engine · JavaScript module
VEDIC
PERCENT (GG2050-VEDIC-000025): Ventus Grid Engine / voltage-drop · Electrical engineering / Applied mathematics. drop_volts, nominal_volts → drop_percent
Uses
none found
Used by
imported by Cmd Trench (import), imported by Plant Feeders (import), imported by Single-Line Diagram (SLD) Rules (import), imported by Block Build (import), imported by Block MV (import), imported by Connect Here (import), imported by Plant Template (import)
Produces
SIZES, AL_RHO20, alR20, CU_RHO20, cuR20, RATING_DEFAULTS, build, rating, impedance, dropPercent, sizeFor
Defines here
alR20, cuR20, build, rating, impedance, dropPercent, sizeFor
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
energy-transition-simulator@a165ce6d56cb22271828874d68d570e8fa5e428a prototype/mod/engine/cable-rating.mjs:1-96 · blob 31f3d8e97ac35ba259120da0af8d5ad30799346c · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: experimental · users: none · canonical: duplicate_candidate
// COPIED UNCHANGED from the v12 world (web/world/cable-rating.mjs) at v12 commit 3adcee9 (file last changed 604729d). 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.
// cable-rating.mjs: continuous current rating of a 33 kV single-core aluminium XLPE cable laid direct in trefoil,
// by the steady-state method of IEC 60287-1-1 (losses) and IEC 60287-2-1 (thermal resistances), and the size a
// feeder segment needs for the load it carries.
//
// Indicative only: a real design uses the manufacturer's data and a rating study. The cable build is estimated
// (conductor from its area, 8 mm insulation for 19/33 kV, a 35 mm2 copper wire screen) unless an OD is given.
// Soil thermal resistivity is an input: default 1.2 K.m/W native ground, ground at 15 C, conductor 90 C.
// Pure: no imports, no DOM.

// Nominal aluminium conductor sizes (mm2) this world offers. Resistance at 20 C is worked out from the resistivity of
// aluminium with a stated allowance for stranding and compaction (own estimate, conservative), not taken from any
// standard's table: pass r20OhmKm from the maker's data to replace it. IEC 60228 is cited by number only.
export const SIZES = Object.freeze([35, 50, 70, 95, 120, 150, 185, 240, 300, 400, 500, 630, 800, 1000]);
export const AL_RHO20 = 2.8264e-8, AL_ALPHA20 = 0.00403, STRAND_ALLOWANCE = 1.10;   // ohm.m, 1/K, ratio
/** Resistance at 20 C in ohm per km of an aluminium conductor of `area` mm2 (physical estimate). */
export const alR20 = area => AL_RHO20 / (area * 1e-6) * STRAND_ALLOWANCE * 1000;
// Copper the same way: R20 = rho20 / A x k, k the same stated allowance (own estimate, not a standard's table).
export const CU_RHO20 = 1.7241e-8, CU_ALPHA20 = 0.00393;                             // ohm.m (annealed copper), 1/K
/** Resistance at 20 C in ohm per km of a copper conductor of `area` mm2 (physical estimate). */
export const cuR20 = area => CU_RHO20 / (area * 1e-6) * STRAND_ALLOWANCE * 1000;

export const RATING_DEFAULTS = Object.freeze({
  kv: 33, u0Kv: 19, freq: 50, conductorMaxC: 90, groundC: 15, soilKmW: 1.2, depthM: 0.8,
  insulationMm: 8.0, semiconMm: 1.8, screenMm2: 35, screenMm: 1.0, sheathMm: 3.2,
  xlpeKmW: 3.5, sheathKmW: 3.5, epsR: 2.5, tanDelta: 0.004, bonding: 'both-ends', groupFactor: 1
});

const PI = Math.PI;

// Cable build from the conductor area (mm); a given OD sets the oversheath instead.
export function build(area, p = RATING_DEFAULTS, odMm = null) {
  const dc = Math.sqrt(4 * area / (PI * 0.9));               // compacted stranded conductor
  const di = dc + 2 * (p.insulationMm + p.semiconMm);       // over the insulation screen
  const ds = di + 2 * p.screenMm;                            // over the wire screen
  const od = odMm || ds + 2 * p.sheathMm;
  return { dc, di, ds, od, sheath: (od - ds) / 2 };
}

/** rating(area, opts) -> { amps, mva, R, T1, T3, T4, lambda1, Wd, build } */
export function rating(area, opts = {}) {
  const p = { ...RATING_DEFAULTS, ...opts };
  if (!(area > 0)) throw new Error(`cable-rating: no conductor of ${area} mm2`);
  const b = build(area, p, opts.odMm || null), w = 2 * PI * p.freq;
  // AC resistance at the maximum temperature: DC resistance, then skin and proximity (IEC 60287-1-1 2.1).
  const rdc = (opts.r20OhmKm || alR20(area)) / 1000 * (1 + AL_ALPHA20 * (p.conductorMaxC - 20));
  const xs4 = (8 * PI * p.freq / rdc * 1e-7) ** 2, ys = xs4 / (192 + 0.8 * xs4);
  const ratio = b.dc / b.od, yf = xs4 / (192 + 0.8 * xs4);
  const yp = yf * ratio ** 2 * (0.312 * ratio ** 2 + 1.18 / (yf + 0.27));
  const R = rdc * (1 + ys + yp);
  // Dielectric loss (small at 33 kV, kept for completeness).
  const C = p.epsR / (18 * Math.log(b.di / b.dc)) * 1e-9;
  const Wd = w * C * (p.u0Kv * 1000) ** 2 * p.tanDelta;
  // Screen loss factor: bonded both ends, trefoil, circulating current (IEC 60287-1-1 2.3.1).
  const rs = 1.7241e-8 / (p.screenMm2 * 1e-6) * STRAND_ALLOWANCE * (1 + 0.00393 * 50);   // copper wires: resistivity x allowance
  const dMean = (b.di + b.ds) / 2, X = 2 * w * 1e-7 * Math.log(2 * b.od / dMean);
  const lambda1 = p.bonding === 'both-ends' ? rs / R / (1 + (rs / X) ** 2) : 0;
  // Thermal resistances (IEC 60287-2-1): insulation, oversheath, and ground for touching trefoil.
  const T1 = p.xlpeKmW / (2 * PI) * Math.log(1 + 2 * (p.insulationMm + p.semiconMm) / b.dc);
  const T3 = p.sheathKmW / (2 * PI) * Math.log(1 + 2 * b.sheath / b.ds);
  const L = p.depthM + b.od / 1000 * (0.5 + Math.sqrt(3) / 4), u = 2 * L / (b.od / 1000);
  const T4 = 1.5 / PI * p.soilKmW * (Math.log(2 * u) - 0.630);
  const dT = p.conductorMaxC - p.groundC - Wd * (0.5 * T1 + T3 + T4);
  const amps = Math.sqrt(dT / (R * T1 + R * (1 + lambda1) * (T3 + T4))) * p.groupFactor;
  return { area, amps, mva: Math.sqrt(3) * p.kv * amps / 1000, R, T1, T3, T4, lambda1, Wd, build: b };
}

/** Series impedance per metre of a trefoil circuit: { r, x } ohm/m at the rated temperature. */
export function impedance(area, opts = {}) {
  const p = { ...RATING_DEFAULTS, ...opts }, rr = rating(area, p);
  const gmr = 0.39 * rr.build.dc, s = rr.build.od;
  return { r: rr.R, x: 2 * PI * p.freq * 2e-7 * Math.log(s / gmr) };
}

/** Voltage drop in % over a length for a three-phase load in MVA at power factor pf. */
export function dropPercent(area, lengthM, mva, { pf = 0.95, ...opts } = {}) {
  const p = { ...RATING_DEFAULTS, ...opts }, z = impedance(area, p);
  const I = mva * 1e6 / (Math.sqrt(3) * p.kv * 1000), sin = Math.sqrt(1 - pf * pf);
  return Math.sqrt(3) * I * lengthM * (z.r * pf + z.x * sin) / (p.kv * 1000) * 100;
}

/**
 * sizeFor(mva, opts) -> the smallest size whose rating carries the load: { area, amps, loadAmps, utilisation }
 * or null when even the largest will not (the load needs another feeder).
 */
export function sizeFor(mva, opts = {}) {
  const p = { ...RATING_DEFAULTS, ...opts }, loadAmps = mva * 1e6 / (Math.sqrt(3) * p.kv * 1000);
  const min = opts.minArea || 0;
  for (const a of SIZES) {
    if (a < min) continue;
    const r = rating(a, p);
    if (r.amps >= loadAmps) return { area: a, amps: r.amps, loadAmps, utilisation: loadAmps / r.amps };
  }
  return null;
}

Cable Route

A JavaScript module in the engine folder of Energy Transition Simulator that works with cables. It routes cable (`routeCable`) and draws lines (`drawLines`).

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

Evidence
  • line-jaccard 0.9877 to globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-design-studio/202609270005-site-world-v3/world/cable-route.mjs:1-207 265884bcbba42955a68f34d40a35abe73c8845cc
  • sha256 53b1e0276f425dba092ea512d43c74a75b074144b2943a6607b2260fb7d96c14
  • target sha256 789555abe8618c46dcdc632271d9d715c670509530e6c9d511739022e0d9831b
  • group of 3 (identity.json near-copy edges >= 0.9)
  • canonical rule: reachable, newest stamp, core repo, most lines

electricalenergy-transition-simulator / prototype/mod/engine/cable-route.mjs · lines 1–209 of 209 · Not reached from any entry point (candidate for review) · pattern bendRadiusAt (shared by 3 files)

What it does
It calculates cables. Defines 13 functions or classes, including sub, norm, unit, turn, planSegments.
Why it exists in the grid workflow
Domain stage experimental (path word 'prototype'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow. Domain terms in the code: cables.
Downstream impact
Used directly by 1 file: Connect Here (energy-transition-simulator).
What it achieves
A buried cable laid along a plan polyline.
Why it matters
Imported by Connect Here.
Application
energy-transition-simulator · prototype/mod/engine · JavaScript module
Uses
none found
Used by
imported by Connect Here (import)
Produces
routeCable
Defines here
sub, norm, unit, turn, planSegments, line, at, coreOffsets, routeCable, zAt, walk, bendRadiusAt, drawLines
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
energy-transition-simulator@a165ce6d56cb22271828874d68d570e8fa5e428a prototype/mod/engine/cable-route.mjs:1-209 · blob edbfb4abfeeb94c18dad0af1d88d414d99c6893d · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: none found · domain stage: experimental · users: none · canonical: duplicate_candidate
// COPIED UNCHANGED from the v12 world (web/world/cable-route.mjs) at v12 commit 3adcee9 (file last changed 04b1c72). Modular star family: public #144725 routeCable.
// Do not edit here: change the source and re-copy. Everything below this header is byte-identical to the source.
// Cable route: a buried cable laid along a plan polyline. Pure: no imports, no DOM, no WebGL.
// Local east (x), north (y), up (z), metres, as camera.mjs.
//
// routeCable({ points, minBendRadius, depthBelowGround, groundAt, formation, spacing, step })
//   points          [[x, y], ...] plan vertices (at least two)
//   minBendRadius   every corner is replaced by a circular arc of this radius (a fillet)
//   depthBelowGround the centreline sits this far below groundAt(x, y)
//   groundAt        (x, y) -> ground height; default flat at 0
//   formation       'flat' (three cores side by side, centre to centre = spacing) or
//                   'trefoil' (three touching cores, centre to centre = spacing = core diameter)
//   step            sampling interval along the route, metres (default 1)
//
// A corner whose legs are too short for the requested radius is still filleted, with the largest radius the
// legs allow, and reported in violations: { index, requestedRadius, available }. Nothing is silently accepted.
// length2d is exact (straights plus arcs). length3d walks the samples with the exact plan distance between
// them and the ground-following height change, so on flat ground length3d equals length2d.

const EPS = 1e-9;

function sub(a, b) { return [a[0] - b[0], a[1] - b[1]]; }
function norm(v) { return Math.hypot(v[0], v[1]); }
function unit(v) { const l = norm(v); return [v[0] / l, v[1] / l]; }

// Signed turn from direction d1 to d2, radians, left (anticlockwise) positive.
function turn(d1, d2) { return Math.atan2(d1[0] * d2[1] - d1[1] * d2[0], d1[0] * d2[0] + d1[1] * d2[1]); }

// Build the plan geometry: straights and arcs, with fitted radii and violations.
function planSegments(pts, R) {
  const n = pts.length;
  const legs = [];
  for (let k = 0; k < n - 1; k++) {
    const v = sub(pts[k + 1], pts[k]);
    legs.push({ len: norm(v), dir: norm(v) > EPS ? unit(v) : null });
  }
  // Requested tangent length at each vertex (0 at the ends and at straight-through vertices).
  const theta = new Array(n).fill(0);
  const want = new Array(n).fill(0);
  for (let i = 1; i < n - 1; i++) {
    const a = legs[i - 1].dir, b = legs[i].dir;
    if (!a || !b) continue;
    theta[i] = turn(a, b);
    const half = Math.abs(theta[i]) / 2;
    if (half < EPS) continue;
    want[i] = Math.PI / 2 - half < EPS ? Infinity : R * Math.tan(half);
  }
  // Each leg must hold the tangents of both its ends; share a short leg in proportion to what each end asks.
  const cap = want.slice();
  for (let k = 0; k < n - 1; k++) {
    const t0 = want[k], t1 = want[k + 1], len = legs[k].len;
    if (t0 + t1 <= len) continue;
    if (!isFinite(t0) && !isFinite(t1)) { cap[k] = Math.min(cap[k], len / 2); cap[k + 1] = Math.min(cap[k + 1], len / 2); continue; }
    const f0 = !isFinite(t0) ? 1 : !isFinite(t1) ? 0 : t0 / (t0 + t1);
    cap[k] = Math.min(cap[k], len * f0);
    cap[k + 1] = Math.min(cap[k + 1], len * (1 - f0));
  }
  const violations = [];
  const corners = [];
  for (let i = 1; i < n - 1; i++) {
    if (want[i] === 0) continue;
    const half = Math.abs(theta[i]) / 2;
    const reversal = Math.PI / 2 - half < EPS;
    const t = reversal ? 0 : cap[i];
    const r = reversal ? 0 : t / Math.tan(half);
    if (r < R * (1 - 1e-9)) violations.push({ index: i, requestedRadius: R, available: r });
    if (r > EPS) corners.push({ index: i, t, r, theta: theta[i] });
  }
  // Walk the route: straight to each tangent point, arc round, carry on.
  const segs = [];
  let cur = pts[0].slice(0, 2), s = 0;
  const line = (a, b) => {
    const len = norm(sub(b, a));
    if (len < EPS) return;
    segs.push({ type: 'line', a, b, dir: unit(sub(b, a)), len, s0: s, s1: s + len });
    s += len;
  };
  for (const c of corners) {
    const d1 = legs[c.index - 1].dir, d2 = legs[c.index].dir, p = pts[c.index];
    const A = [p[0] - d1[0] * c.t, p[1] - d1[1] * c.t];
    const B = [p[0] + d2[0] * c.t, p[1] + d2[1] * c.t];
    line(cur, A);
    const side = Math.sign(c.theta);
    const centre = [A[0] - d1[1] * c.r * side, A[1] + d1[0] * c.r * side];
    const a0 = Math.atan2(A[1] - centre[1], A[0] - centre[0]);
    const len = c.r * Math.abs(c.theta);
    segs.push({ type: 'arc', centre, r: c.r, a0, theta: c.theta, h0: Math.atan2(d1[1], d1[0]), len, s0: s, s1: s + len, index: c.index });
    s += len;
    cur = B;
  }
  line(cur, pts[n - 1].slice(0, 2));
  return { segs, violations, length2d: s };
}

// Point and heading at parameter u in [0, 1] along a segment.
function at(seg, u) {
  if (seg.type === 'line') {
    return { x: seg.a[0] + (seg.b[0] - seg.a[0]) * u, y: seg.a[1] + (seg.b[1] - seg.a[1]) * u, h: Math.atan2(seg.dir[1], seg.dir[0]) };
  }
  const ang = seg.a0 + seg.theta * u;
  return { x: seg.centre[0] + seg.r * Math.cos(ang), y: seg.centre[1] + seg.r * Math.sin(ang), h: seg.h0 + seg.theta * u };
}

// Lateral (left of travel) and vertical offsets of the three cores from the centreline.
function coreOffsets(formation, spacing) {
  if (formation === 'trefoil') {
    const rc = spacing / Math.sqrt(3); // circumradius of the touching triangle
    return [[0, rc], [-spacing / 2, -rc / 2], [spacing / 2, -rc / 2]];
  }
  return [[spacing, 0], [0, 0], [-spacing, 0]];
}

export function routeCable({
  points, minBendRadius = 0, depthBelowGround = 0, groundAt = () => 0,
  formation = 'flat', spacing = 0, step = 1,
} = {}) {
  if (!Array.isArray(points) || points.length < 2) throw Error('routeCable needs at least two points');
  if (formation !== 'flat' && formation !== 'trefoil') throw Error(`unknown formation: ${formation}`);
  if (!(step > 0)) throw Error('step must be positive');
  const R = Math.max(0, minBendRadius);
  const { segs, violations, length2d } = planSegments(points, R);
  const zAt = (x, y) => groundAt(x, y) - depthBelowGround;

  // Samples along the centreline: plan point, heading, chainage, and the segment they belong to.
  const samples = [];
  segs.forEach((seg, si) => {
    let pieces = Math.max(1, Math.ceil(seg.len / step));
    if (seg.type === 'arc') pieces = Math.max(pieces, Math.ceil(Math.abs(seg.theta) / (Math.PI / 36)));
    for (let j = si === 0 ? 0 : 1; j <= pieces; j++) {
      const u = j / pieces;
      samples.push({ ...at(seg, u), s: seg.s0 + seg.len * u, seg: si });
    }
  });
  if (!samples.length) { const p = points[0]; samples.push({ x: p[0], y: p[1], h: 0, s: 0, seg: -1 }); }

  // Walk one line of samples, offset laterally by `lat` and vertically by `vert`, measuring as we go.
  const walk = (lat, vert) => {
    const poly = [];
    let len2 = 0, len3 = 0;
    for (let k = 0; k < samples.length; k++) {
      const q = samples[k];
      const x = q.x - Math.sin(q.h) * lat, y = q.y + Math.cos(q.h) * lat;
      const z = zAt(q.x, q.y) + vert;
      if (k > 0) {
        const prev = samples[k - 1], seg = segs[q.seg];
        // Exact plan distance: an offset arc has radius r - lat for a left turn, r + lat for a right turn.
        const scale = seg.type === 'arc' ? (seg.r - Math.sign(seg.theta) * lat) / seg.r : 1;
        const ds = (q.s - prev.s) * scale, dz = z - poly[k - 1][2];
        len2 += ds; len3 += Math.hypot(ds, dz);
      }
      poly.push([x, y, z]);
    }
    return { polyline: poly, length2d: len2, length3d: len3 };
  };

  const centre = walk(0, 0);
  const names = formation === 'trefoil' ? ['top', 'left', 'right'] : ['left', 'centre', 'right'];
  const cores = coreOffsets(formation, spacing).map(([lat, vert], i) => {
    const w = walk(lat, vert);
    return { name: names[i], lateral: lat, vertical: vert, polyline: w.polyline, length2d: w.length2d, length3d: w.length3d };
  });

  // A core on the inside of a bend whose offset exceeds the bend radius would fold back on itself.
  const maxLat = Math.max(...cores.map((c) => Math.abs(c.lateral)));
  for (const seg of segs) {
    if (seg.type === 'arc' && seg.r <= maxLat && !violations.some((v) => v.index === seg.index)) {
      violations.push({ index: seg.index, requestedRadius: R, available: seg.r, reason: 'inner core offset exceeds bend radius' });
    }
  }
  violations.sort((a, b) => a.index - b.index);

  const bendRadiusAt = (chainage) => {
    for (const seg of segs) {
      if (chainage >= seg.s0 - EPS && chainage <= seg.s1 + EPS && seg.type === 'arc') return seg.r;
    }
    return Infinity;
  };

  const drawLines = ({ includeCores = true, includeCentreline = true } = {}) => {
    const lines = [];
    if (includeCentreline) lines.push(centre.polyline);
    if (includeCores) for (const c of cores) lines.push(c.polyline);
    let count = 0;
    for (const l of lines) count += Math.max(0, l.length - 1);
    const out = new Float32Array(count * 6);
    let o = 0;
    for (const l of lines) {
      for (let k = 1; k < l.length; k++) {
        out[o++] = l[k - 1][0]; out[o++] = l[k - 1][1]; out[o++] = l[k - 1][2];
        out[o++] = l[k][0]; out[o++] = l[k][1]; out[o++] = l[k][2];
      }
    }
    return out;
  };

  return {
    centreline: centre.polyline,
    segments: segs.map((g) => (g.type === 'arc'
      ? { type: 'arc', centre: g.centre, radius: g.r, turn: g.theta, s0: g.s0, s1: g.s1, index: g.index }
      : { type: 'line', from: g.a, to: g.b, s0: g.s0, s1: g.s1 })),
    violations,
    length2d,
    length3d: centre.length3d,
    formation,
    cores,
    bendRadiusAt,
    drawLines,
  };
}

Cmd Grammar Trench

A JavaScript module in the engine folder of Energy Transition Simulator covering cables, solar and 33kV. It parses trench (`parseTrench`) and is built from the is num helper (`isNum`).

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

Evidence
  • line-jaccard 0.9714 to globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-design-studio/202609271740-site-world/world/cmd-grammar-trench.mjs:1-85 7bfe43d5cd0e2c5f71806a066f61f59e60c009d6
  • sha256 2bf93db743d2d638af7339f1f1b6517703eeb08b38a7f91a8fdcb6bdc63aeb5a
  • target sha256 f193cbf79545a8e0ff60ca0b80ba8fcb80b91acd12a5433d957c43dd737c30c5
  • group of 3 (identity.json near-copy edges >= 0.9)
  • canonical rule: reachable, newest stamp, core repo, most lines

ingestenergy-transition-simulator / prototype/mod/engine/cmd-grammar-trench.mjs · lines 1–87 of 87 · Not reached from any entry point (candidate for review) · pattern parseTrench (shared by 3 files)

What it does
It lists and searches cables, solar and 33kV. Defines isNum, parseTrench.
Why it exists in the grid workflow
Domain stage experimental (path word 'prototype'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow. Domain terms in the code: cables, solar, 33kV.
Inputs & outputs
Voltage levels named: 33kV.
Downstream impact
Used directly by 1 file: Cmd Grammar (energy-transition-simulator).
What it achieves
The trench and cable words of the command line (trench, cable, load, xray), split out of `cmd-grammar.mjs` to keep each cartridge under 400 lines. Its code works with 33 kV.
Why it matters
Imported by Cmd Grammar.
Application
energy-transition-simulator · prototype/mod/engine · JavaScript module
Uses
none found
Used by
imported by Cmd Grammar (import)
Produces
TRENCH_KEYS_TYPED, SPLIT_KINDS, COVER_KINDS, TRENCH_COMMANDS, TRENCH_VOCAB, parseTrench
Defines here
isNum, parseTrench
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
energy-transition-simulator@a165ce6d56cb22271828874d68d570e8fa5e428a prototype/mod/engine/cmd-grammar-trench.mjs:1-87 · blob aaa6b2093de2bbedb26e5445b46b64cc67b8615d · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: experimental · users: EPC_contractor · canonical: duplicate_candidate
// COPIED UNCHANGED from the v12 world (web/world/cmd-grammar-trench.mjs) at v12 commit 3adcee9 (file last changed 4c57503). Modular star family: public #148229 parseTrench.
// Do not edit here: change the source and re-copy. Everything below this header is byte-identical to the source.
// cmd-grammar-trench.mjs: the trench and cable words of the command line (trench, cable, load, xray), split out of
// cmd-grammar.mjs to keep each cartridge under 400 lines. Pure: parse() hands each verb here with its words and helpers.

// Typed settings for the block's trenches sized by rating (cmd-trench.mjs), checked like the grammar's KEYS.
export const TRENCH_KEYS_TYPED = Object.freeze({
  soil: { label: 'soil thermal resistivity', unit: 'K.m/W', min: 0.5, max: 3.5 },
  load: { label: 'load profile', choices: ['continuous', 'solar-day'] },
  splitDc: { label: 'DC trenches side by side', unit: '', min: 0, max: 6, int: true },
  splitBranch: { label: 'AC branch trenches side by side', unit: '', min: 0, max: 6, int: true },
  splitCollector: { label: 'collector trenches side by side', unit: '', min: 0, max: 6, int: true },
  splitMv: { label: '33 kV trenches side by side', unit: '', min: 0, max: 6, int: true },
  coverDc: { label: 'DC cover', unit: 'm', min: 0.3, max: 2 },
  coverLv: { label: 'LV AC cover', unit: 'm', min: 0.3, max: 2 },
  coverMv: { label: '33 kV cover', unit: 'm', min: 0.3, max: 2 },
  drumM: { label: 'cable drum length', unit: 'm', min: 100, max: 3000 },
  ring: { label: '33 kV ring rating case', choices: ['n-1', 'normal'] }
});
/** trench split <kind> N and trench cover <kind> N: the kind named and the setting it sets. */
export const SPLIT_KINDS = Object.freeze({ dc: 'splitDc', branch: 'splitBranch', collector: 'splitCollector', mv: 'splitMv' });
export const COVER_KINDS = Object.freeze({ dc: 'coverDc', lv: 'coverLv', ac: 'coverLv', mv: 'coverMv' });

export const TRENCH_COMMANDS = Object.freeze([
  { verb: 'trench', usage: 'trench depth 1.1  ·  trench width 0.6  ·  trench ac trefoil|flat  ·  trench design  ·  trench split collector 4'
    + '  ·  trench cover dc 0.91  ·  trench drum 800  ·  trench ring n-1|normal',
    words: 'cable trench cover containment sized rating width options side by side drum joint ring outage' },
  { verb: 'cable', usage: 'cable 400 al  ·  cable rate 400 al 28 circuits  ·  cable rate 400 al 28 circuits pitch 0.25',
    words: 'conductor size aluminium copper rating ampacity grouping current' },
  { verb: 'load', usage: 'load continuous  ·  load solar-day', words: 'load profile cyclic daily solar day rating loss factor' },
  { verb: 'xray', usage: 'xray on  ·  xray off', words: 'x-ray as built buried see through ground trenches ducts cables backfill' }
]);
export const TRENCH_VOCAB = Object.freeze({
  trench: ['depth', 'width', 'ac', 'trefoil', 'flat', 'design', 'split', 'cover', 'dc', 'lv', 'mv', 'branch', 'collector', 'drum', 'ring', 'n-1', 'normal'],
  cable: ['al', 'cu', 'rate', 'circuits', 'circuit', 'pitch', 'lv', 'mv', 'dc'], load: ['continuous', 'solar-day'], xray: ['on', 'off'] });

const isNum = t => t && typeof t === 'object' && Number.isFinite(t.n);

/** parseTrench(v, rest, out, { has, after, num, put, bad, guard }): fills out.set / out.act / out.arg, or pushes refusals on bad. */
export function parseTrench(v, rest, out, { has, after, num, put, bad, guard }) {
  if (v === 'trench') {
    if (has('design')) { out.act = 'trench-design'; return; }
    if (has('split')) {
      const k = Object.keys(SPLIT_KINDS).find(w => has(w));
      if (!k) bad.push(`trench split names the kind: trench split collector 4 (${Object.keys(SPLIT_KINDS).join(', ')}; 0 lets the rating choose)`);
      else num(rest.indexOf(k) + 1, SPLIT_KINDS[k]);
      out.act = 'trench-design'; return;
    }
    if (has('cover')) {
      const k = ['dc', 'lv', 'mv', 'ac'].find(w => has(w));
      if (!k) bad.push('trench cover names the kind: trench cover dc 0.91 (dc, lv or mv)');
      else num(rest.indexOf(k) + 1, COVER_KINDS[k], ['m']);
      out.act = 'trench-design'; return;
    }
    if (has('drum')) { num(after('drum'), 'drumM', ['m']); out.act = 'trench-design'; return; }
    if (has('ring')) {
      const w = rest.find(x => x === 'n-1' || x === 'normal');
      if (w) put('ring', w); else bad.push('trench ring is n-1 (rated with one ring end out) or normal');
      out.act = 'trench-design'; return;
    }
    if (after('depth') > 0) num(after('depth'), 'depth', ['m']);
    if (after('width') > 0) num(after('width'), 'width', ['m']);
    if (has('trefoil')) put('formation', 'trefoil');
    if (has('flat')) put('formation', 'flat');
    if (!Object.keys(out.set).length && !bad.length) bad.push('trench takes depth, width or a formation: trench depth 1.1, trench width 0.6, trench ac trefoil');
    return;
  }
  if (v === 'cable') {
    if (has('rate')) {
      const nums = rest.filter(isNum), ic = rest.indexOf('circuits') >= 0 ? rest.indexOf('circuits') : rest.indexOf('circuit'), ip = after('pitch');
      const size = nums[0], count = ic > 0 && isNum(rest[ic - 1]) ? rest[ic - 1].n : 1, pitch = ip > 0 && isNum(rest[ip]) ? rest[ip].n : null;
      const kind = has('mv') ? 'mv' : has('dc') ? 'dc' : 'lv';
      if (!size) bad.push('cable rate needs a size, such as cable rate 400 al 28 circuits');
      else if (kind !== 'dc' && guard('size', size.n)) bad.push(guard('size', size.n));
      if (!(count >= 1 && count <= 60 && Math.round(count) === count)) bad.push(`circuits must be a whole number from 1 to 60; you typed ${count}`);
      if (pitch !== null && !(pitch >= 0.05 && pitch <= 3)) bad.push(`pitch between circuits must be 0.05 to 3 m; you typed ${pitch}`);
      out.act = 'rate'; out.arg = { size: size?.n, metal: has('cu') ? 'cu' : 'al', circuits: count, pitchM: pitch, kind };
      return;
    }
    const n = rest.find(isNum);
    if (n) put('size', n.n); else bad.push('cable needs a size in mm², such as cable 400 al');
    put('metal', has('cu') ? 'cu' : 'al');
    return;
  }
  if (v === 'load') { const w = rest.find(x => x === 'continuous' || x === 'solar-day'); if (w) put('load', w); else bad.push('load is continuous or solar-day'); return; }
  if (v === 'xray') { out.act = 'xray'; out.arg = { on: !has('off') }; }
}