GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Cables and conductors / globalgrid2050 / solar-design-studio/202609271552-site-world/world

Cable IEC and 3 more files (part 2)

A JavaScript module in the world folder of GlobalGrid2050 that works with cables, solar and 33kV, using IEC 60287 and IEC 60287-1-1.

678 lines of JavaScript from globalgrid2050, in 4 files. Topic: Cables and conductors. Section 23 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 Checks electrical · globalgrid2050 / solar-design-studio/202609271552-site-world/world/cable-checks.mjs lines 1–113
  2. Cable Group IEC electrical · globalgrid2050 / solar-design-studio/202609271740-site-world/world/cable-group-iec.mjs lines 1–214
  3. Cable IEC electrical · globalgrid2050 / solar-design-studio/202609271740-site-world/world/cable-iec.mjs lines 1–257
  4. Cable Rating electrical · globalgrid2050 / solar-design-studio/202609271740-site-world/world/cable-rating.mjs lines 1–94

Cable Checks

A JavaScript module in the world folder of GlobalGrid2050 that works with cables and solar. It parses checks (`parseChecks`) and checks line (`checkLine`).

electricalglobalgrid2050 / solar-design-studio/202609271552-site-world/world/cable-checks.mjs · lines 1–113 of 113 · version 2026-09-27 15:52 · Not reached from any entry point (candidate for review) · pattern defaultChoice (shared by 2 files)

What it does
It calculates cables and solar. Defines 16 functions or classes, including valueWords, loadingWords, num, rTheta, round.
Why it exists in the grid workflow
Domain stage sub33kv_design (path word 'cable'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary. Domain terms in the code: cables, solar.
Downstream impact
Used directly by 1 file: Block UI (globalgrid2050).
What it achieves
The Solar block's cable schedule as illustrative checks (Design > Plant > Solar block > Cable checks).
Why it matters
Imported by Block UI.
Application
globalgrid2050 · solar-design-studio/202609271552-site-world/world · JavaScript module
Uses
none found
Used by
imported by Block UI (dynamic import)
Produces
CHECK_LABEL, AXES, AXIS_WORDS, valueWords, loadingWords, parseChecks, defaultChoice, caseFor, acChecks, dcChecks, summarise, tableRow
Defines here
valueWords, loadingWords, num, rTheta, round, parseChecks, rows, defaultChoice, caseFor, acChecks, dcChecks, summarise, stat, tableRow, checkLine, part
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-design-studio/202609271552-site-world/world/cable-checks.mjs:1-113 · blob 8f4e30d5af21ff441ea296cd666cadfe0b0bb9fb · 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: unreached_review
// cable-checks.mjs: the Solar block's cable schedule as illustrative checks (Design > Plant > Solar block > Cable checks).
// Per circuit: voltage drop and loading, worked out again from the staged schedule (tools/stage-cable-schedule.mjs)
// at the assumptions chosen in the panel. Every property, rating, factor, spacing and power factor is ASSUMED; the
// numbers are an illustrative check, not a design and not a calculation to any standard. A loading over 100 % is
// said in neutral words ("above 100% at these assumptions"): it is a question about the assumptions, never a verdict.
// Pure: no DOM, no fetch.
//
//   voltage drop, DC string cable   I x L x R(theta)                     (one conductor; % of the string's Vmp)
//   voltage drop, AC phase cable    sqrt(3) x I x L x (R(theta) cos(phi) + X sin(phi))           (% of line volts)
//   R(theta) = R20 x (1 + alpha (theta - 20))
//   loading, AC                     design current / rating of the chosen case (GPU-rated sweep, one rating per case)
//   loading, DC                     design current / (assumed rating in duct x assumed grouping factor), as scheduled

export const CHECK_LABEL = 'Illustrative check, assumptions editable.';
export const AXES = ['size', 'mat', 'inst', 'rho', 'depth', 'nper', 'spacing', 'layers', 'load'];
export const AXIS_WORDS = Object.freeze({
  size: 'Conductor size, mm²', mat: 'Material', inst: 'Installation', rho: 'Soil thermal resistivity, K·m/W', depth: 'Depth to the circuit centres, m',
  nper: 'Circuits per trench', spacing: 'Spacing between circuits, m', layers: 'Layers of circuits', load: 'Load profile'
});
const VALUE_WORDS = { Al: 'aluminium', Cu: 'copper', 'trefoil-direct': 'trefoil, laid direct', 'trefoil-ducted': 'trefoil, each circuit in a duct',
  'flat-spaced': 'flat, one cable width apart', continuous: 'full current all day', solar: 'a solar day (daily cycle)' };
export const valueWords = v => VALUE_WORDS[v] ?? String(v);

// Neutral words for a loading: the only two things this page ever says about one.
export const loadingWords = pct => (!Number.isFinite(pct) ? 'not worked out at these assumptions'
  : pct > 100 ? 'above 100% at these assumptions' : 'within 100% at these assumptions');

const num = v => (typeof v === 'number' && Number.isFinite(v) ? v : NaN);
const rTheta = (r20, alpha, theta) => r20 * (1 + alpha * (theta - 20));
const round = (x, d) => Math.round(x * 10 ** d) / 10 ** d;

// The staged file, checked for shape; throws with a plain reason.
export function parseChecks(doc) {
  if (!doc || doc.schema !== 'world.cable-checks.v1') throw Error('not a cable-checks file (world.cable-checks.v1)');
  for (const k of ['dc', 'ac']) if (!Array.isArray(doc[k]?.rows) || !Array.isArray(doc[k]?.columns)) throw Error(`no ${k} circuits`);
  const a = doc.assumed;
  if (!a?.dc || !a?.ac) throw Error('no assumed cable data');
  const rows = k => doc[k].rows.map(r => Object.fromEntries(doc[k].columns.map((c, i) => [c, r[i]])));
  const cases = doc.cases && AXES.every(k => Array.isArray(doc.cases.axes?.[k])) && Array.isArray(doc.cases.rating_A) ? doc.cases : null;
  return { dc: rows('dc'), ac: rows('ac'), assumed: a, cases, illustrative: String(doc.illustrative || CHECK_LABEL),
    lengths: String(doc.lengths || ''), standards: (doc.standards || []).map(String), sources: doc.sources || [] };
}

// The panel's starting assumptions: the sweep's own baseline, else the first value of every axis; power factor as assumed.
export function defaultChoice(checks) {
  const c = checks.cases, base = c?.baseline || {};
  const out = Object.fromEntries(AXES.map(k => [k, c ? (c.axes[k].includes(base[k]) ? base[k] : c.axes[k][0]) : null]));
  out.size ??= checks.assumed.ac.area_mm2; out.mat ??= checks.assumed.ac.material;
  return { ...out, pf: num(checks.assumed.ac.pf) || 1 };
}

// The rated case for a choice: { rating_A, width_m } or null when the sweep has no such case.
export function caseFor(cases, choice) {
  if (!cases) return null;
  let i = 0;
  for (const k of AXES) {
    const j = cases.axes[k].indexOf(choice[k]);
    if (j < 0) return null;
    i = i * cases.axes[k].length + j;
  }
  const rating = num(cases.rating_A[i]);
  return Number.isFinite(rating) && rating > 0 ? { rating_A: rating, width_m: num(cases.width_m?.[i]) } : null;
}

// AC phase cables at a choice: per circuit length, voltage drop (V and % of line volts) and loading.
export function acChecks(checks, choice) {
  const a = checks.assumed.ac, r20 = num(a.r20_ohm_km?.[choice.mat]?.[choice.size]), alpha = num(a.alpha?.[choice.mat]);
  const pf = Math.min(1, Math.max(0.5, num(choice.pf) || 1)), sin = Math.sqrt(1 - pf * pf);
  const R = rTheta(r20, alpha, num(a.theta_C)), X = num(a.x_ohm_km) || 0, rated = caseFor(checks.cases, choice);
  const circuits = checks.ac.map(c => {
    const vd = Math.sqrt(3) * num(c.current_A) * num(c.length_m) / 1000 * (R * pf + X * sin);
    const loading = rated ? 100 * num(c.design_current_A) / rated.rating_A : NaN;
    return { id: c.id, inverter: c.inverter, phase: c.phase, length_m: num(c.length_m), vd_V: vd, vd_pct: 100 * vd / num(a.volts), loading_pct: loading };
  });
  return { rating_A: rated?.rating_A ?? NaN, width_m: rated?.width_m ?? NaN, r_ohm_km: R, circuits, summary: summarise(circuits) };
}

// DC string cables as scheduled: per circuit voltage drop (% of the string's Vmp) and loading.
export function dcChecks(checks) {
  const d = checks.assumed.dc, R = rTheta(num(d.r20_ohm_km), num(d.alpha), num(d.theta_C)), vmp = num(checks.assumed.string_vmp_V);
  const circuits = checks.dc.map(c => {
    const vd = num(c.current_A) * num(c.length_m) / 1000 * R;
    return { id: c.id, inverter: c.inverter, string: c.string, length_m: num(c.length_m), vd_V: vd, vd_pct: 100 * vd / vmp,
      loading_pct: 100 * num(c.design_current_A) / num(c.rating_A) };
  });
  // A string's drop is both its conductors' (NEG and POS together).
  const strings = new Map();
  for (const c of circuits) { const k = `${c.inverter}:${c.string}`; strings.set(k, (strings.get(k) || 0) + c.vd_pct); }
  const perString = summarise([...strings.values()].map(vd_pct => ({ vd_pct, loading_pct: NaN }))).vd_pct;
  return { r_ohm_km: R, circuits, summary: { ...summarise(circuits), strings: perString } };
}

// Min, median and max of voltage drop and loading, and how many circuits are above 100 % at these assumptions.
export function summarise(circuits) {
  const stat = k => {
    const v = circuits.map(c => c[k]).filter(Number.isFinite).sort((x, y) => x - y);
    return v.length ? { min: v[0], median: v[Math.floor(v.length / 2)], max: v[v.length - 1] } : null;
  };
  return { count: circuits.length, vd_pct: stat('vd_pct'), loading_pct: stat('loading_pct'),
    above100: circuits.filter(c => c.loading_pct > 100).length };
}

// Rows for a table, numbers rounded for the screen.
export const tableRow = c => [c.id, round(c.length_m, 1), round(c.vd_V, 2), round(c.vd_pct, 2), Number.isFinite(c.loading_pct) ? round(c.loading_pct, 1) : null];

// One line for the block's main readout (user test H6): AC and DC loading at the starting assumptions, in the same
// neutral words as the Cable checks fold; no verdict.
export function checkLine(checks, choice = defaultChoice(checks)) {
  const A = acChecks(checks, choice).summary, D = dcChecks(checks).summary, n = x => (Math.round(x * 10) / 10).toFixed(1);
  const part = (what, s) => (s.loading_pct ? `${what} ${n(s.loading_pct.max)} % at most, ${loadingWords(s.loading_pct.max)}`
    + (s.above100 ? ` (${s.above100} of ${s.count})` : '') : `${what} ${loadingWords(NaN)}`);
  return `${part('AC cables', A)} · ${part('DC cables', D)}. Change the assumptions under Cable checks.`;
}

Cable Group IEC

A JavaScript module in the world folder of GlobalGrid2050 that works with cables, using IEC 60287 and IEC 60287-2-1. It builds model (`buildModel`) and groups rating (`groupRating`).

electricalglobalgrid2050 / solar-design-studio/202609271740-site-world/world/cable-group-iec.mjs · lines 1–214 of 214 · version 2026-09-27 17:40 · Not reached from any entry point (candidate for review) · pattern buildModel (shared by 2 files)

What it does
It calculates cables. Defines 12 functions or classes, including expand, buildModel, temperatures, trefoilCentreOffset, cyclicTrefoilG.
Why it exists in the grid workflow
Domain stage sub33kv_design (path word 'cable'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary. Domain terms in the code: cables.
What it achieves
Continuous and cyclic current rating of buried single-core cables in groups (AC LV, AC MV, DC), laid direct or in ducts, by the steady-state thermal method of the IEC 60287 family.
Why it matters
No other file in the estate was found to import it.
Application
globalgrid2050 · solar-design-studio/202609271740-site-world/world · JavaScript module
Uses
Cable IEC (import)
Used by
none found
Produces
buildModel, temperatures, groupRating, circuitRating, rowLayout, pitchForLoad, soilProblem
Defines here
expand, buildModel, temperatures, trefoilCentreOffset, cyclicTrefoilG, groupRating, excess, circuitRating, rowLayout, pitchForLoad, ok, soilProblem
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-design-studio/202609271740-site-world/world/cable-group-iec.mjs:1-214 · blob 26a6968e42f32aee92760bce8ac58cec9e5f1df7 · 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: unreached_review
// cable-group-iec.mjs: continuous and cyclic current rating of buried single-core cables in groups (AC LV, AC MV, DC),
// laid direct or in ducts, by the steady-state thermal method of the IEC 60287 family: every cable heats every other
// through the ground by superposition of image sources (IEC 60287-2-1 clause 4.2, groups), rated at the hottest.
// Cable builds, losses and thermal resistances are in cable-iec.mjs. Standards cited by number and clause only; no
// table, figure or text of any standard is reproduced. Indicative: a real design uses the maker's data and a study.
// Pure: no DOM.

import { DEFAULTS, THERMAL_RHO, acResistance, screenLossFactors, internalThermal, dielectricLoss, trefoilTouchingG, cyclicSelfG,
  mutualG, airGapT4, bundleDiameter } from './cable-iec.mjs';

const PI = Math.PI;
// ---------------------------------------------------------------- layout ----

/**
 * A circuit: { id, cable (from makeCable), formation: 'trefoil'|'flat'|'pair'|'single', x (m), depth (m, to the
 * centre of the group), spacingMm (axial, flat/pair; default touching), touching (trefoil, default true),
 * bonding, load (A, weight for the group scale; default 1), duct: null | { odMm, boreMm, rhoT, mode: 'each'|'shared' } }
 */
function expand(c, k) {
  const cab = c.cable, form = c.formation || (cab.kind === 'dc' ? 'pair' : 'trefoil');
  const duct = c.duct || null, each = duct && (duct.mode || 'each') === 'each';
  const unit = each ? duct.odMm : cab.od;                      // what touches what
  const s = (c.spacingMm || unit) / 1000, x = c.x || 0, y = c.depth;
  let pts;
  if (form === 'trefoil') {
    const a = (c.spacingMm || unit) / 1000;
    pts = [[x, y - a / Math.sqrt(3)], [x - a / 2, y + a / (2 * Math.sqrt(3))], [x + a / 2, y + a / (2 * Math.sqrt(3))]];
  } else if (form === 'flat') pts = [[x - s, y], [x, y], [x + s, y]];
  else if (form === 'pair') pts = [[x - s / 2, y], [x + s / 2, y]];
  else pts = [[x, y]];
  const sPhaseMm = form === 'flat' ? (c.spacingMm || unit) * 2 ** (1 / 3) : (c.spacingMm || unit);
  return { circuit: k, form, pts, duct, each, sPhaseMm, adjMm: c.spacingMm || unit,
    touchingTrefoil: form === 'trefoil' && !duct && !c.spacingMm };
}

/** Build the model: cables (conductors) and elements (heat sources in the soil: a cable or a duct). */
export function buildModel(circuits, opts = {}) {
  const o = { ...DEFAULTS, ...opts }, cables = [], elements = [];
  circuits.forEach((c, k) => {
    const g = expand(c, k), cab = c.cable;
    const ac = acResistance(cab, cab.thetaMaxC, g.sPhaseMm, o.freq);
    const lam = g.form === 'trefoil' || g.form === 'flat'
      ? screenLossFactors(cab, { R: ac.R, sMm: g.adjMm, formation: g.form, bonding: c.bonding || 'solid',
        thetaS: cab.thetaMaxC - 20, freq: o.freq }) : [0, 0, 0];
    const internal = internalThermal(cab), Wd = dielectricLoss(cab, o.freq);
    const members = g.pts.map((p, j) => {
      const idx = cables.length;
      cables.push({ circuit: k, j, x: p[0], y: p[1], cable: cab, R: ac.R, ac, lambda1: lam[j] || 0, Wd, ...internal,
        weight: c.load ?? 1, bonding: c.bonding || 'solid', form: g.form, adjMm: g.adjMm });
      return idx;
    });
    if (g.duct) {
      const need = g.each ? cab.od : bundleDiameter(members.length, cab.od);
      if (need >= g.duct.boreMm) throw new Error(`cable-rating-iec: circuit ${c.id ?? k}: cables (${need.toFixed(0)} mm) do not fit the ${g.duct.boreMm} mm duct bore`);
    }
    if (g.duct && !g.each) {
      elements.push({ x: c.x || 0, y: c.depth, De: g.duct.odMm, members, duct: g.duct,
        bundleMm: bundleDiameter(members.length, cab.od), circuit: k });
    } else {
      members.forEach((idx) => elements.push({ x: cables[idx].x, y: cables[idx].y, De: g.duct ? g.duct.odMm : cab.od,
        members: [idx], duct: g.duct, bundleMm: cab.od, circuit: k, trefoil: g.touchingTrefoil }));
    }
  });
  elements.forEach((e, i) => e.members.forEach((m) => { cables[m].element = i; }));
  return { cables, elements, opts: o };
}

/**
 * Temperatures of every conductor with each circuit current = scale * load. Losses use the conductor resistance
 * at its maximum temperature (the standard's convention); screen losses follow the screen temperature, duct
 * air-gap resistance follows the air temperature, both by fixed-point iteration.
 */
export function temperatures(model, scale) {
  const { cables, elements, opts: o } = model;
  const rho = o.soilKmW, k2p = rho / (2 * PI);
  let thS = cables.map((c) => c.cable.thetaMaxC - 15), thM = elements.map(() => o.ambientC + 20);
  let out;
  for (let it = 0; it < 8; it++) {
    const W = cables.map((c, i) => {
      const I = scale * c.weight, Wc = I * I * c.R;
      let lam = c.lambda1;
      if (c.cable.screen && c.lambda1 > 0) {
        // Screen losses scale with screen resistance: re-evaluate at the current screen temperature.
        const l = screenLossFactors(c.cable, { R: c.R, sMm: c.adjMm, formation: c.form, bonding: c.bonding,
          thetaS: thS[i], freq: o.freq });
        lam = l[c.j] ?? l[0];
      }
      return { I, Wc, lam, Wtot: Wc * (1 + lam) + c.Wd };
    });
    const We = elements.map((e) => e.members.reduce((s, m) => s + W[m].Wtot, 0));
    const dTg = elements.map((e, i) => {
      let G0;
      if (e.trefoil) G0 = o.mu >= 1 ? trefoilTouchingG(e.y + trefoilCentreOffset(e, cables), cables[e.members[0]].cable.od)
        : cyclicTrefoilG(e, cables, o);
      else G0 = cyclicSelfG(e.y, e.De, o.mu, o.diffusivityM2h);
      let sum = We[i] * G0;
      elements.forEach((f, j) => {
        if (j === i) return;
        if (e.trefoil && f.trefoil && f.circuit === e.circuit) return;   // inside the trefoil formula already
        sum += o.mu * We[j] * mutualG(e, f);
      });
      let dt = k2p * sum;
      if (o.dryZone && dt > o.dryZone.critRiseK) {
        const v = o.dryZone.rhoDry / rho; dt = v * dt - (v - 1) * o.dryZone.critRiseK;
      }
      return dt;
    });
    const ductParts = elements.map((e, i) => {
      if (!e.duct) return { wall: 0, air: 0 };
      const bore = e.duct.boreMm, rhoD = e.duct.rhoT ?? THERMAL_RHO.HDPE;
      const wall = We[i] * rhoD / (2 * PI) * Math.log(e.duct.odMm / bore);
      const air = We[i] * airGapT4(e.bundleMm, bore, We[i], thM[i], o.ductAirUVY);
      return { wall, air };
    });
    out = cables.map((c, i) => {
      const e = c.element, w = W[i];
      const surface = o.ambientC + dTg[e] + ductParts[e].wall + ductParts[e].air;
      const dT3 = (w.Wc * (1 + w.lam) + c.Wd) * c.T3;
      const thetaS = surface + dT3;
      const theta = thetaS + (w.Wc + 0.5 * c.Wd) * c.T1;
      return { circuit: c.circuit, j: c.j, I: w.I, W: w.Wtot, lambda1: w.lam, ground: dTg[e], surface, thetaS, theta };
    });
    const nextS = out.map((r) => r.thetaS);
    const nextM = elements.map((e, i) => o.ambientC + dTg[i] + ductParts[i].wall + 0.5 * ductParts[i].air);
    const conv = nextS.every((t, i) => Math.abs(t - thS[i]) < 1e-4) && nextM.every((t, i) => Math.abs(t - thM[i]) < 1e-4);
    thS = nextS; thM = nextM;
    if (conv) break;
  }
  return out;
}

// Trefoil formula wants L to the trefoil centre; elements hold the cable centre, so recover the centroid depth.
function trefoilCentreOffset(e, cables) {
  const c = cables[e.members[0]], ys = cables.filter((x) => x.circuit === c.circuit).map((x) => x.y);
  return ys.reduce((a, b) => a + b, 0) / ys.length - e.y;
}
function cyclicTrefoilG(e, cables, o) {
  const De = cables[e.members[0]].cable.od, L = e.y + trefoilCentreOffset(e, cables);
  const Dx = 1.02 * Math.sqrt(24 * o.diffusivityM2h) * 1000;
  if (Dx <= De) return o.mu * trefoilTouchingG(L, De);
  return 3 * (Math.log(Dx / De) - 0.630) + 3 * o.mu * Math.log(4 * L * 1000 / Dx);
}

/**
 * groupRating(circuits, opts) -> { scale, perCircuit: [{ id, amps, load, utilisation }], hottest, cables, model }
 * scale = the factor on every circuit's `load` that brings the hottest conductor to its maximum temperature. With
 * load in amps, utilisation = 1/scale (above 1 = overloaded). With no loads, scale is the equal-current rating in A.
 */
export function groupRating(circuits, opts = {}) {
  const model = buildModel(circuits, opts);
  const excess = (s) => {
    const t = temperatures(model, s);
    return Math.max(...t.map((r, i) => r.theta - model.cables[i].cable.thetaMaxC));
  };
  let lo = 0, hi = 1;
  if (excess(0) > 0) return { scale: 0, perCircuit: [], hottest: null, cables: temperatures(model, 0), model,
    note: 'dielectric and ambient heat alone exceed the limit' };
  while (excess(hi) < 0 && hi < 1e5) hi *= 2;
  for (let i = 0; i < 60; i++) { const m = (lo + hi) / 2; if (excess(m) < 0) lo = m; else hi = m; }
  const t = temperatures(model, lo);
  let h = 0; t.forEach((r, i) => { if (r.theta > t[h].theta) h = i; });
  return {
    scale: lo,
    perCircuit: circuits.map((c, k) => ({ id: c.id ?? k, amps: lo * (c.load ?? 1), load: c.load ?? null,
      utilisation: c.load ? 1 / lo : null })),
    hottest: { circuit: t[h].circuit, cable: t[h].j, theta: t[h].theta }, cables: t, model
  };
}

/** Rating in amps of one circuit alone. */
export function circuitRating(circuit, opts = {}) {
  return groupRating([{ ...circuit, load: undefined, x: 0 }], opts).scale;
}

/**
 * Row of n identical circuits at pitch (m), in `rows` layers `rowGapM` apart; the first layer at depth.
 * Returns circuits ready for groupRating.
 */
export function rowLayout({ n, pitchM, depth, rows = 1, rowGapM = 0.3, ...circuit }) {
  const perRow = Math.ceil(n / rows), out = [];
  for (let i = 0; i < n; i++) {
    const r = Math.floor(i / perRow), k = i % perRow, inRow = Math.min(perRow, n - r * perRow);
    out.push({ ...circuit, id: i, x: (k - (inRow - 1) / 2) * pitchM, depth: depth + r * rowGapM });
  }
  return out;
}

/**
 * Smallest pitch (m) at which n identical circuits in a row carry `load` amps each; width adds the group's own
 * footprint and an edge clearance each side. Returns null if even maxPitchM will not carry the load.
 */
export function pitchForLoad({ n, load, maxPitchM = 2, edgeM = 0.1, ...rest }, opts = {}) {
  const ok = (p) => groupRating(rowLayout({ n, pitchM: p, ...rest, load }), opts).scale >= 1;
  const unit = (rest.duct ? rest.duct.odMm : rest.cable.od) / 1000 * (rest.formation === 'flat' ? 3 : 2);
  if (!ok(maxPitchM)) return null;
  let lo = unit, hi = maxPitchM;
  if (ok(lo)) hi = lo;
  else for (let i = 0; i < 40; i++) { const m = (lo + hi) / 2; if (ok(m)) hi = m; else lo = m; }
  const rows = rest.rows || 1, perRow = Math.ceil(n / rows);
  return { pitchM: hi, widthM: (perRow - 1) * hi + unit + 2 * edgeM };
}

/** Export of the soil problem at a rating, for the numerical pair check: element centres, diameters, losses. */
export function soilProblem(result) {
  const { model, cables } = result, o = model.opts;
  return {
    soilKmW: o.soilKmW, ambientC: o.ambientC,
    elements: model.elements.map((e, i) => {
      const W = e.members.reduce((s, m) => s + cables[m].W, 0);
      return { x: e.x, y: e.y, De: e.De / 1000, W, trefoil: !!e.trefoil, circuit: e.circuit,
        groundRiseJs: cables[e.members[0]].ground };
    })
  };
}

Cable IEC

A JavaScript module in the world folder of GlobalGrid2050 that works with cables, solar and 33kV, using IEC 60287 and IEC 60287-1-1.

electricalglobalgrid2050 / solar-design-studio/202609271740-site-world/world/cable-iec.mjs · lines 1–257 of 257 · version 2026-09-27 17:40 · 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 sub33kv_design (path word 'cable'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary. 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 3 files: Cable Group IEC (globalgrid2050); Cmd Trench (globalgrid2050); Trench Plan (globalgrid2050). Reached from 2 other entry points, including Solar Design Studio — Site World Page (globalgrid2050, https://globalgrid2050.com/solar-design-studio/202609271853-site-world/); Substrate (globalgrid2050).
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 Cable Group IEC, Cmd Trench and Trench Plan.
Application
globalgrid2050 · solar-design-studio/202609271740-site-world/world · JavaScript module
Uses
none found
Used by
imported by Cable Group IEC (import), imported by Cmd Trench (import), imported by Trench Plan (import)
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
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-design-studio/202609271740-site-world/world/cable-iec.mjs:1-257 · blob c218e4b046496efdb568f5a03e1b45bc8c92466a · 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: production_core
// 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 world folder of GlobalGrid2050 that works with cables and 33kV, using IEC 60287-1-1 and IEC 60287-2-1.

electricalglobalgrid2050 / solar-design-studio/202609271740-site-world/world/cable-rating.mjs · lines 1–94 of 94 · version 2026-09-27 17:40 · 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 sub33kv_design (path word 'cable'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary. Domain terms in the code: cables, 33kV.
Inputs & outputs
Voltage levels named: 33kV.
Downstream impact
Used directly by 9 files: Cmd Trench (globalgrid2050); Block MV (globalgrid2050); Single-Line Diagram (SLD) Graph (globalgrid2050); Single-Line Diagram (SLD) Plant (globalgrid2050); and 5 more. Reached from 2 other entry points, including Solar Design Studio — Site World Page (globalgrid2050, https://globalgrid2050.com/solar-design-studio/202609271853-site-world/); Substrate (globalgrid2050).
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 9 files, including Cmd Trench, Block MV and Single-Line Diagram (SLD) Graph.
Application
globalgrid2050 · solar-design-studio/202609271740-site-world/world · 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 Block MV (import), imported by Single-Line Diagram (SLD) Graph (import), imported by Single-Line Diagram (SLD) Plant (import), imported by Block Build (import), imported by Plant Feeders (import), imported by Earth Study (import), imported by Plant Template (import), and 1 more
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
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-design-studio/202609271740-site-world/world/cable-rating.mjs:1-94 · blob 95370a608d9286348dd20bc1ec55d68ded9084c7 · 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: production_core
// 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;
}