In this section
- Single-Line Diagram (SLD) Calc electrical · globalgrid2050 / solar-design-studio/202609271552-site-world/world/sld-calc.mjs lines 1–136
- Single-Line Diagram (SLD) Connect electrical · globalgrid2050 / solar-design-studio/202609271552-site-world/world/sld-connect.mjs lines 1–55
- Single-Line Diagram (SLD) Graph electrical · globalgrid2050 / solar-design-studio/202609271552-site-world/world/sld-graph.mjs lines 1–128
- Single-Line Diagram (SLD) Plant electrical · globalgrid2050 / solar-design-studio/202609271552-site-world/world/sld-plant.mjs lines 1–128
- Single-Line Diagram (SLD) Source electrical · globalgrid2050 / solar-design-studio/202609271552-site-world/world/sld-source.mjs lines 1–91
Single-Line Diagram (SLD) Calc
A JavaScript module in the world folder of GlobalGrid2050 that works with transformers, using IEC 60909. It sets taps (`setTaps`) and checks graph (`checkGraph`).
electricalglobalgrid2050 / solar-design-studio/202609271552-site-world/world/sld-calc.mjs · lines 1–136 of 136 · version 2026-09-27 15:52 · Not reached from any entry point (candidate for review) · pattern solve (shared by 72 files)
- What it does
- It calculates transformers. Defines 7 functions or classes, including treeOf, solve, iBaseKA, readouts, setTaps.
- Why it exists in the grid workflow
- Domain stage sub33kv_design (path word 'design'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary. Domain terms in the code: transformers.
- Downstream impact
- Used directly by 4 files: Single-Line Diagram (SLD) Graph (globalgrid2050); Hud Drops (globalgrid2050); Single-Line Diagram (SLD) Follow (globalgrid2050); Single-Line Diagram (SLD) Mount (globalgrid2050).
- What it achieves
- The tree: BFS from GRID over closed branches.
- Why it matters
- Imported by 4 files, including Single-Line Diagram (SLD) Graph, Hud Drops and Single-Line Diagram (SLD) Follow.
- Application
- globalgrid2050 · solar-design-studio/202609271552-site-world/world · JavaScript module
- Uses
- Single-Line Diagram (SLD) Rules (import)
- Used by
- imported by Single-Line Diagram (SLD) Graph (import), imported by Hud Drops (import), imported by Single-Line Diagram (SLD) Follow (import), imported by Single-Line Diagram (SLD) Mount (import)
- Produces
- treeOf, solve, RISE_FLAG_PCT, RISE_NOTE, readouts, setTaps, tracePath, checkGraph
- Defines here
- treeOf, solve, iBaseKA, readouts, setTaps, tracePath, checkGraph
- 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/sld-calc.mjs:1-136 · blob bb0ed1d712db989c7325d47d4e272df0da6202f4 · 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
// sld-calc.mjs: load flow, fault level and readouts on the single-line network (sld-graph.mjs), in the page.
//
// The network runs radially (open ties and open ring hops carry nothing), so it is solved by a back/forward sweep
// from the grid source: inverters inject their rated output at the export power factor; the back sweep adds the
// currents up towards the grid; the forward sweep walks the voltages out from the source, until they settle.
// Fault level at each node by the simple impedance method (IEC 60909 style: c = 1.1, pre-fault load and the inverters'
// own contribution neglected): Zth = source + the series impedance on the path to the grid. The GPU pair
// (tools/gpu/sld_pair.py) solves the same graph two other ways; the tests hold these readouts to them.
// Every value is illustrative, not a design for any site. Pure.
import { C } from './sld-rules.mjs';
/** The tree: BFS from GRID over closed branches. Throws on a closed loop; lists nodes the grid cannot reach. */
export function treeOf(g) {
const adj = new Map(g.nodes.map(n => [n.id, []]));
for (const b of g.branches) if (!b.open) { adj.get(b.from).push(b); adj.get(b.to).push(b); }
const parent = new Map([['GRID', null]]), via = new Map(), order = ['GRID'], depth = new Map([['GRID', 0]]);
for (let i = 0; i < order.length; i++) {
const u = order[i];
for (const b of adj.get(u)) {
if (b === via.get(u)) continue;
const v = b.from === u ? b.to : b.from;
if (parent.has(v)) throw Error(`sld: closed loop through ${b.id}`);
parent.set(v, u); via.set(v, b); depth.set(v, depth.get(u) + 1); order.push(v);
}
}
const unreached = g.nodes.map(n => n.id).filter(id => !parent.has(id));
return { parent, via, order, depth, unreached };
}
/**
* solve(g) -> { V: Map id -> [re, im] pu, J: Map branchId -> current pu towards the grid (grid side of any tap),
* Zth: Map id -> [r, x], iterations }. A branch with tap t (an on-load tap changer at its lower-voltage end, the
* `to` node) is an ideal 1:t ratio behind its series impedance: V_to = t (V_from + z t J), J_from = t J.
*/
export function solve(g, { tol = 1e-12, maxIter = 100 } = {}) {
const t = treeOf(g), S = new Map(g.nodes.map(n => [n.id, n.s])), V = new Map(t.order.map(id => [id, [1, 0]]));
const J = new Map(), Zth = new Map([['GRID', [0, 0]]]), tap = id => t.via.get(id).tap || 1;
for (const id of t.order.slice(1)) { const k = tap(id); Zth.set(id, C.mul([k * k, 0], C.add(Zth.get(t.parent.get(id)), t.via.get(id).z))); }
let it = 0;
for (; it < maxIter; it++) {
const acc = new Map();
for (let i = t.order.length - 1; i > 0; i--) { // back sweep: injections summed towards the grid
const id = t.order[i], s = S.get(id), own = s[0] || s[1] ? C.conj(C.div(s, V.get(id))) : [0, 0];
const I = C.mul([tap(id), 0], C.add(own, acc.get(id) || [0, 0])), up = t.parent.get(id);
J.set(t.via.get(id).id, I); acc.set(up, C.add(acc.get(up) || [0, 0], I));
}
let worst = 0;
for (const id of t.order.slice(1)) { // forward sweep: export raises the far end
const v = C.mul([tap(id), 0], C.add(V.get(t.parent.get(id)), C.mul(t.via.get(id).z, J.get(t.via.get(id).id))));
worst = Math.max(worst, C.abs(C.sub(v, V.get(id)))); V.set(id, v);
}
if (worst < tol) break;
}
for (const b of g.branches) if (b.open) J.set(b.id, [0, 0]);
return { V, J, Zth, iterations: it + 1, tree: t };
}
const iBaseKA = (sb, kv) => sb / (Math.sqrt(3) * kv);
// The grid transformers' on-load taps hold the MV boards near 1.0 pu; station transformer taps are off-load and left at
// nominal, so a node more than this far above the landing is still flagged (inverters trip near 1.1 pu).
export const RISE_FLAG_PCT = 5;
export const RISE_NOTE = 'more than 5 % above the landing: station off-load taps (left at nominal here) would be set to bring it down';
/**
* readouts(g, sol) -> { nodes: Map id -> {...}, branches: Map id -> {...} }, all illustrative:
* node: kv, vPu, riseToLandingPct (above the landing, as the plant exports), faultKA, faultMVA
* branch: loadMVA, currentA, areaMm2, lengthM, dropPct (along it, towards the grid), ratingA, utilisation
*/
export function readouts(g, sol) {
const sb = g.params.sBaseMVA, c = g.params.c, vl = C.abs(sol.V.get('LAND')), nodes = new Map(), branches = new Map();
for (const n of g.nodes) {
const v = sol.V.get(n.id), z = sol.Zth.get(n.id), f = z && C.abs(z) > 0 ? c / C.abs(z) : Infinity;
nodes.set(n.id, { kv: n.kv, vPu: v ? C.abs(v) : null, riseToLandingPct: v ? (C.abs(v) - vl) * 100 : null,
faultKA: v ? f * iBaseKA(sb, n.kv) : null, faultMVA: v ? f * sb : null, label: n.label,
high: !!v && (C.abs(v) - vl) * 100 > RISE_FLAG_PCT });
}
for (const b of g.branches) {
const j = sol.J.get(b.id) || [0, 0], down = sol.tree.parent.get(b.to) === b.from ? b.to : b.from, up = down === b.to ? b.from : b.to;
const vd = sol.V.get(down), vu = sol.V.get(up), I = C.abs(j) * iBaseKA(sb, b.kv) * 1000;
branches.set(b.id, { kv: b.kv, open: b.open, loadMVA: vd ? C.abs(vd) * C.abs(j) / (b.tap || 1) * sb : 0, tap: b.tap ?? null, currentA: I, areaMm2: b.areaMm2 ?? null,
lengthM: b.lengthM ?? null, dropPct: vd && vu && !b.open ? (C.abs(vd) - C.abs(vu)) * 100 : 0, ratingA: b.ratingA ?? null,
utilisation: b.ratingA ? I / b.ratingA : null, label: b.label || b.kind, down, up });
}
return { nodes, branches };
}
/**
* setTaps(g): each branch with an on-load tap changer (oltc: { range, step, target }) gets the tap, in whole steps
* within its range, that holds its lower-voltage end nearest the target (the MV board at 1.0 pu). Written to b.tap.
*/
export function setTaps(g) {
const list = g.branches.filter(b => b.oltc);
for (const b of list) b.tap = 1;
for (let pass = 0; list.length && pass < 12; pass++) {
const sol = solve(g);
let moved = false;
for (const b of list) {
const { range, step, target } = b.oltc, vInt = C.abs(sol.V.get(b.to)) / b.tap;
const k = Math.max(-Math.round(range / step), Math.min(Math.round(range / step), Math.round((target / vInt - 1) / step)));
const next = Math.round((1 + k * step) * 1e6) / 1e6;
if (next !== b.tap) { b.tap = next; moved = true; }
}
if (!moved) break;
}
return g;
}
/** The path from a node up to the landing: [{ node, branch }] from the node itself to LAND (branch into each node). */
export function tracePath(g, sol, id) {
const t = sol.tree, out = [];
if (!t.parent.has(id)) return out;
for (let u = id; u && u !== 'GRID'; u = t.parent.get(u)) out.push({ node: u, branch: u === 'LAND' ? null : t.via.get(u).id });
return out;
}
/**
* checkGraph(g) -> { ok, problems, stations, reachOnce } : every station's inverters reach the landing over exactly one
* closed path (a tree, no loops, nothing stranded), every ring has exactly one open hop, every tie is open.
*/
export function checkGraph(g) {
const problems = [];
let t = null;
try { t = treeOf(g); } catch (e) { problems.push(e.message); }
if (t && t.unreached.length) problems.push(`not connected: ${t.unreached.slice(0, 5).join(', ')}`);
const feeders = new Map();
for (const b of g.branches.filter(x => x.kind === 'feeder-cable')) { const f = feeders.get(b.feeder) || { open: 0, hops: 0 }; f.hops++; f.open += b.open; feeders.set(b.feeder, f); }
const rings = [...feeders].filter(([, f]) => f.open);
for (const [id, f] of rings) if (f.open !== 1) problems.push(`${id}: ${f.open} open hops`);
if (g.branches.some(b => b.kind === 'bus-tie' && !b.open)) problems.push('a bus tie is closed');
const inv = g.nodes.filter(n => n.kind === 'inverter');
const reachOnce = t ? inv.every(n => { let k = 0; for (let u = n.id; u; u = t.parent.get(u)) if (u === 'LAND') k++; return k === 1; }) : false;
if (!reachOnce) problems.push('an inverter does not reach the landing exactly once');
return { ok: !problems.length, problems, stations: g.nodes.filter(n => n.kind === 'rmu').length, inverters: inv.length, reachOnce,
rings: rings.length };
}Single-Line Diagram (SLD) Connect
A JavaScript module in the world folder of GlobalGrid2050 that works with cables, substations, overhead lines (OHL) and 132kV.
electricalglobalgrid2050 / solar-design-studio/202609271552-site-world/world/sld-connect.mjs · lines 1–55 of 55 · version 2026-09-27 15:52 · pattern chooseConnection (shared by 3 files)
- What it does
- It calculates cables, substations, overhead lines (OHL) and 132kV. Defines nearest, km, kvForMW, chooseConnection.
- Why it exists in the grid workflow
- Domain stage sub33kv_design (path word 'design'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary. Domain terms in the code: cables, substations, overhead lines (OHL), 132kV, 400kV, 275kV.
- Inputs & outputs
- Voltage levels named: 400kV, 275kV, 132kV, 33kV.
- Downstream impact
- Used directly by 3 files: Cmd Trench (globalgrid2050); Block UI (globalgrid2050); Single-Line Diagram (SLD) Mount (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 is built from the nearest step (`nearest`), the kV for MW helper (`kvForMW`) and the choose connection helper (`chooseConnection`). Which grid connection a plant gets, from its size and what is near it. Its code works with 132 kV, 400 kV and 275 kV.
- Why it matters
- Imported by Cmd Trench, Block UI and Single-Line Diagram (SLD) Mount.
- Application
- globalgrid2050 · solar-design-studio/202609271552-site-world/world · JavaScript module
- Uses
- none found
- Used by
- imported by Cmd Trench (import), imported by Block UI (import), imported by Single-Line Diagram (SLD) Mount (import)
- Produces
- CONNECT_RULES, CONNECT_LABEL, kvForMW, chooseConnection
- Defines here
- nearest, km, kvForMW, chooseConnection
- 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/sld-connect.mjs:1-55 · blob 6c117c539568a4cdba17bdd8f65174c16f6068a5 · 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
// sld-connect.mjs: which grid connection a plant gets, from its size and what is near it. Editable, illustrative rules;
// the network operator decides the real connection. One connection object serves the solar block, the single-line
// diagram and Follow (user test H4).
// The voltage follows the plant's size: up to smallMaxMW at 33 kV, up to dnoMaxMW at 132 kV, up to midMaxMW at 275 kV,
// above that 400 kV (a block with its own grid transformer connects at 132 kV at least).
// 275 and 400 kV: only through a bay at a substation of that voltage (within transSearchM), by fully ducted, unjointed
// HV cable; never a tee into a transmission line.
// 132 kV and below: a cable to the nearest network operator substation of that voltage (within dnoSearchM); else a
// tee into a line of that voltage within teeM (teeMaxKv at most); else no nearby connection (an assumed landing that
// says so).
// Pure.
export const CONNECT_RULES = Object.freeze({ smallMaxMW: 30, dnoMaxMW: 150, midMaxMW: 400, teeM: 3000, teeMaxKv: 132, dnoSearchM: 30000,
transSearchM: 40000 });
export const CONNECT_LABEL = 'Connection chosen by illustrative rules (size and distance); the network operator decides the real one.';
const nearest = (list, at, ok) => list.filter(x => ok(x) && Number.isFinite(x.e) && Number.isFinite(x.n))
.map(x => ({ ...x, d: Math.hypot(x.e - at[0], x.n - at[1]) })).sort((a, b) => a.d - b.d)[0] || null;
const km = m => `${(m / 1000).toFixed(1)} km`;
/** The connection voltage for a plant of mw: 33, 132, 275 or 400 kV; minKv raises it (132 for a block with its own grid transformer). */
export function kvForMW(mw, { minKv = 0, rules = {} } = {}) {
const R = { ...CONNECT_RULES, ...rules };
const kv = mw <= R.smallMaxMW ? 33 : mw <= R.dnoMaxMW ? 132 : mw <= R.midMaxMW ? 275 : 400;
return [33, 132, 275, 400].find(v => v >= Math.max(kv, minKv)) || 400;
}
/**
* chooseConnection({ mw, at: [e, n], subs: [{ e, n, kv }], towers: [{ e, n, kv }], kv?, minKv?, rules }) ->
* { rule, text, kv, connection: 'cable' | 'ohl-tee' | 'none', route: 'cable' | 'overhead line' | null,
* landing: { e, n, kv, real, kind: 'gis-bay' | 'dno-sub' | 'tower' } | null }
* kv: the voltage already fixed (the placed block's grid transformer); else by size.
*/
export function chooseConnection({ mw, at, subs = [], towers = [], kv: fixed = null, minKv = 0, rules = {} }) {
const R = { ...CONNECT_RULES, ...rules }, kv = fixed || kvForMW(mw, { minKv, rules });
const size = `${Math.round(mw)} MW`;
if (kv >= 275) {
const s = nearest(subs, at, x => x.kv === kv);
if (s && s.d <= R.transSearchM) return { rule: `bay-${kv}`, kv, connection: 'cable', route: 'cable',
text: `${size} at ${kv} kV: ducted, unjointed HV cable to a bay at the ${kv} kV substation ${km(s.d)} away (no tee at transmission voltage)`,
landing: { e: s.e, n: s.n, kv, real: true, kind: 'gis-bay' } };
return { rule: 'none', kv, connection: 'none', route: null, landing: null,
text: `${size} at ${kv} kV: no ${kv} kV substation within ${km(R.transSearchM)}; the landing shown is an assumed point, not a substation` };
}
const s = nearest(subs, at, x => x.kv === kv);
if (s && s.d <= R.dnoSearchM) return { rule: `dno-${kv}`, kv, connection: 'cable', route: 'cable',
text: `${size} at ${kv} kV: cable to the nearest ${kv} kV network operator substation, ${km(s.d)} away`,
landing: { e: s.e, n: s.n, kv, real: true, kind: 'dno-sub' } };
const t = kv <= R.teeMaxKv ? nearest(towers, at, x => x.kv === kv) : null;
if (t && t.d <= R.teeM) return { rule: `tee-${kv}`, kv, connection: 'ohl-tee', route: 'overhead line',
text: `${size} at ${kv} kV: no ${kv} kV substation within ${km(R.dnoSearchM)}; overhead tee into the ${kv} kV line ${km(t.d)} away (illustrative)`,
landing: { e: t.e, n: t.n, kv, real: true, kind: 'tower' } };
return { rule: 'none', kv, connection: 'none', route: null, landing: null,
text: `${size} at ${kv} kV: no nearby connection at ${kv} kV; the landing shown is an assumed point, not a substation` };
}Single-Line Diagram (SLD) Graph
A JavaScript module in the world folder of GlobalGrid2050 that works with transformers, cables, overhead lines (OHL) and 33kV.
electricalglobalgrid2050 / solar-design-studio/202609271552-site-world/world/sld-graph.mjs · lines 1–128 of 128 · version 2026-09-27 15:52 · Not reached from any entry point (candidate for review) · pattern round (shared by 53 files)
- What it does
- It calculates transformers, cables, overhead lines (OHL) and 33kV. Defines 11 functions or classes, including zb, buildGraph, node, branch, bus.
- Why it exists in the grid workflow
- Domain stage sub33kv_design (path word 'design'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary. Domain terms in the code: transformers, cables, overhead lines (OHL), 33kV, 0.8kV.
- Inputs & outputs
- Voltage levels named: 33kV, 0.8kV.
- Downstream impact
- Used directly by 2 files: Hud Drops (globalgrid2050); Single-Line Diagram (SLD) Mount (globalgrid2050).
- What it achieves
- It builds graph (`buildGraph`) and is built from the node step (`node`) and the branch step (`branch`). The network graph behind the single-line diagram, the 3D symbols, the readouts and Follow. Its code works with 33 kV, 0.8 kV and 100 MVA.
- Why it matters
- Imported by Hud Drops and Single-Line Diagram (SLD) Mount.
- Application
- globalgrid2050 · solar-design-studio/202609271552-site-world/world · JavaScript module
- Uses
- Cable Rating (import), Single-Line Diagram (SLD) Rules (import), Single-Line Diagram (SLD) Calc (import)
- Used by
- imported by Hud Drops (import), imported by Single-Line Diagram (SLD) Mount (import)
- Produces
- buildGraph, graphJson
- Defines here
- zb, buildGraph, node, branch, bus, cablePu, txPu, rmuOf, kvLvOf, round, graphJson
- 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/sld-graph.mjs:1-128 · blob 6ff7b924fed05bb4d94ac3f78386639af3b74908 · 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
// sld-graph.mjs: the network graph behind the single-line diagram, the 3D symbols, the readouts and Follow.
//
// buildGraph(source) turns a plant source (sld-plant.mjs for a generic plant, sld-source.mjs for a placed block or
// layout) into nodes and branches with per-unit impedances on a 100 MVA base:
// GRID (ideal source) -source impedance- LAND (the bay at the operator's substation, or a tower on the tee option)
// -HV cable- HVP (plant-end HV busbar) -bay: disconnector, earth switch, surge arresters- GTg.hv -GTg- GTg.a/b (33 kV)
// -incomer- MVBs (board section; earthing transformer + NER, spare, storage and filter ways) -feeder cables- Sk.R (RMU)
// -transformer way- Sk.T (station transformer) -LV winding- Sk.Ta (LV board) -breaker, AC cable- Sk.I7 (inverter)
// Bus ties between board sections and a ring's open hop are branches with open: true (drawn, never carrying load).
// Every closed branch is kept once; the solvers (sld-calc.mjs, tools/gpu/sld_pair.py) orient the tree themselves.
// Illustrative, not a design for any site. Pure: imports only the cable rating and the shared rules.
import { impedance, rating, alR20 } from './cable-rating.mjs';
import { SLD_DEFAULTS, DEVICES, zOf, SLD_LABEL } from './sld-rules.mjs';
import { setTaps } from './sld-calc.mjs';
const zb = (kv, sb) => kv * kv / sb;
/**
* buildGraph(source, opts) -> { nodes, branches, params, label }
* nodes: { id, kind, kv, label, at: [e, n] | null, s: [p, q] per unit injected (export positive), devices, meta }
* branches: { id, from, to, kind, kv, z: [r, x] per unit, open, lengthM, areaMm2, ratingA, devices, label, path }
*/
export function buildGraph(src, opts = {}) {
const p = { ...SLD_DEFAULTS, ...(src.params || {}), ...opts }, sb = p.sBaseMVA, nodes = [], branches = [];
const node = (id, kind, kv, label, extra = {}) => { nodes.push({ id, kind, kv, label, at: null, s: [0, 0], devices: [], ...extra }); return id; };
const branch = (id, from, to, kind, kv, z, extra = {}) => branches.push({ id, from, to, kind, kv, z, open: false, devices: [], ...extra });
const bus = () => [...p.busPu];
const cablePu = (area, L, kv, g = 1) => { const z = impedance(area, { kv }); return { z: [z.r * L / zb(kv, sb), z.x * L / zb(kv, sb)],
ratingA: rating(area, { kv, groupFactor: g }).amps }; };
const txPu = (pct, xr, mva) => zOf(pct / 100 * sb / mva, xr);
const sin = Math.sqrt(Math.max(0, 1 - p.powerFactor ** 2));
const hv = src.hv, kvHv = hv.kv;
// ---- grid source, landing and the HV connection ----
const Ik = p.sourceKA || p.sourceKAByKv[kvHv] || 40, Sk = Math.sqrt(3) * kvHv * Ik;
p.sourceKA = Ik;
node('GRID', 'grid', kvHv, `Grid source, ${Ik} kA at ${kvHv} kV (assumed)`);
const land = hv.landing || {}, kind = land.kind || 'gis-bay';
const words = { tower: `${kvHv} kV line tower (overhead tee)`, 'gis-bay': `Gas-insulated bay at the ${kvHv} kV substation`,
'dno-sub': `${kvHv} kV network operator substation bay`, none: `No nearby connection at ${kvHv} kV (assumed landing)` };
node('LAND', kind, kvHv, words[kind] || words['gis-bay'], { at: land.e != null ? [land.e, land.n] : null,
devices: kind === 'tower' || kind === 'none' ? [] : DEVICES['gis-bay'], meta: { real: !!land.real, distanceM: land.distanceM ?? null, rule: hv.rule || null,
ruleText: hv.ruleText || null } });
branch('SRC', 'GRID', 'LAND', 'source', kvHv, zOf(p.c * sb / Sk, p.sourceXR), { label: 'Grid source impedance (assumed fault level)' });
node('HVP', 'hv-bus', kvHv, `${kvHv} kV plant-end busbar`, { at: hv.plantAt || null });
const ohl = hv.connection === 'ohl-tee', z33 = impedance(630, { kv: 33 }), L = hv.lengthM / 1000;
const perKm = ohl ? p.ohlOhmKm : kvHv <= 33 ? [z33.r * 1000, z33.x * 1000] : p.hvCableOhmKm;
branch('HVC', 'LAND', 'HVP', ohl ? 'ohl-tee' : 'hv-cable', kvHv, [perKm[0] * L / zb(kvHv, sb), perKm[1] * L / zb(kvHv, sb)], { lengthM: hv.lengthM,
label: ohl ? `Overhead tee, ${Math.round(hv.lengthM)} m` : `${kvHv} kV cable, ${Math.round(hv.lengthM)} m, fully ducted, unjointed, ${hv.protection || 'tiles'} over`,
path: hv.path || null });
// ---- grid transformers, board sections, earthing, ties ----
for (const g of src.grid) {
node(`${g.id}.hv`, 'hv-bay', kvHv, `${g.id} HV bay`, { at: g.at || null, devices: DEVICES['hv-bay'] });
branch(`${g.id}.bay`, 'HVP', `${g.id}.hv`, 'hv-bay', kvHv, bus(), { devices: DEVICES['hv-bay'], label: `${g.id} bay: disconnector, earth switch, surge arresters` });
for (let w = 0; w < g.lvWindings; w++) {
const wid = `${g.id}.${'ab'[w]}`;
node(wid, 'gt-lv', 33, `${g.id} LV winding ${'ab'[w]}`, { at: g.at || null });
branch(`${g.id}.${'ab'[w]}.tx`, `${g.id}.hv`, wid, 'gt', kvHv, txPu(g.zPct, g.xr, g.mva / g.lvWindings),
{ label: `Grid transformer ${g.id}: ${g.mva} MVA ${kvHv}/33 kV ${g.vector}, HV neutral ${g.hvNeutral}, on-load taps ±${p.tapRange * 100} %`,
mva: g.mva, oltc: { range: p.tapRange, step: p.tapStep, target: p.tapTarget } });
}
}
src.sections.forEach((s, i) => {
node(s.id, 'mv-board', 33, `33 kV board section ${s.id.slice(3)}`, { at: s.at || null, meta: { spareWays: s.spareWays } });
branch(`${s.id}.inc`, src.grid.length ? `${s.gt}.${s.winding}` : 'HVP', s.id, 'mv-incomer', 33, bus(), { devices: DEVICES['mv-incomer'] });
node(`${s.id}.NET`, 'earthing', 33, `Earthing transformer + NER, ${p.nerA} A (assumed)`, { at: s.at || null, devices: DEVICES.earthing });
branch(`${s.id}.net`, s.id, `${s.id}.NET`, 'earthing', 33, bus(), { devices: DEVICES['mv-way'] });
for (const [on, id, kind, label] of [[s.storageWay, 'BESS', 'storage-way', 'Storage way (optional)'], [s.harmonicFilter, 'HF', 'harmonic-filter', 'Harmonic filter (optional)']]) {
if (!on) continue;
node(`${s.id}.${id}`, kind, 33, label);
branch(`${s.id}.${id.toLowerCase()}`, s.id, `${s.id}.${id}`, kind, 33, bus(), { devices: DEVICES['mv-way'] });
}
if (i) branch(`TIE${i}`, src.sections[i - 1].id, s.id, 'bus-tie', 33, bus(), { open: true, devices: DEVICES['bus-tie'], label: 'Bus tie, normally open' });
});
// ---- stations: RMU, transformer way, transformer unit(s), LV winding boards, inverters ----
const rmuOf = id => (id.startsWith('MVB') ? id : `${id}.R`);
for (const st of src.stations) {
node(`${st.id}.R`, 'rmu', 33, `Ring main unit ${st.id.slice(1)}`, { at: st.rmuAt || st.at || null, meta: { station: st.id },
devices: ['incomer: ' + DEVICES['rmu-in'][0], 'outgoer: ' + DEVICES['rmu-out'][0], 'transformer: ' + DEVICES['rmu-tx'].slice(0, 2).join(', ')] });
st.units.forEach((u, k) => {
const tid = `${st.id}.${u.id}`;
node(tid, 'st-hv', 33, `Station ${st.id.slice(1)} transformer ${u.id}: ${round(u.mva)} MVA 33/0.8 kV ${u.vector}, ${u.zPct} %, taps ${u.taps}`,
{ at: u.at || st.at || null, meta: { station: st.id, mva: u.mva } });
branch(`${tid}.cb`, `${st.id}.R`, tid, 'rmu-tx', 33, bus(), { devices: DEVICES['rmu-tx'], label: 'RMU transformer way (circuit breaker)' });
for (const w of u.windings) {
const lv = `${tid}${w.id}`, kvLv = (p.acVolts || 800) / 1000;
node(lv, 'lv-board', kvLv, `Station ${st.id.slice(1)} LV board ${u.id}${w.id}`, { at: u.at || st.at || null, devices: DEVICES['lv-main'],
meta: { station: st.id } });
branch(`${lv}.tx`, tid, lv, 'st-tx', 33, txPu(u.zPct, u.xr, u.mva * w.kva / Math.max(1, u.windings.reduce((t, x) => t + x.kva, 0))),
{ label: `Transformer ${u.id} winding ${w.id}` });
for (const inv of w.inverters) {
const iid = `${st.id}.${inv.id}`, mva = inv.kva / 1000, Lm = inv.acLengthM;
const r = alR20(inv.acAreaMm2) / 1000 * (1 + 0.00403 * 70), zbl = zb(kvLv, sb);
node(iid, 'inverter', kvLv, `Inverter ${inv.id.slice(1)}, ${inv.kva} kVA`, { at: inv.at || null, s: [mva * p.powerFactor / sb, mva * sin / sb],
meta: { station: st.id, kva: inv.kva } });
branch(`${iid}.ac`, lv, iid, 'ac-cable', kvLv, [r * Lm / zbl, p.lvXOhmKm / 1000 * Lm / zbl], { lengthM: Lm, areaMm2: inv.acAreaMm2,
devices: DEVICES['lv-way'], label: `AC cable 3 × ${inv.acAreaMm2} mm² Al, ${Math.round(Lm)} m, no local isolator`, path: inv.acPath || null });
}
}
if (k === 0) {
node(`${st.id}.AUX`, 'aux', 0.4, `Auxiliary transformer ${st.id.slice(1)}`, { at: st.at || null });
branch(`${st.id}.aux`, `${tid}${u.windings[0].id}`, `${st.id}.AUX`, 'aux', kvLvOf(p), txPu(4, 3, 0.1), { label: 'Auxiliary supply' });
}
});
}
for (const f of src.feeders) f.hops.forEach((h, i) => {
const from = h.from === 'board' ? f.section : h.from, to = h.to === 'board' ? f.sectionB : h.to;
const c = cablePu(h.areaMm2, h.lengthM, 33, h.group || 1);
branch(`${f.id}.${i + 1}`, rmuOf(from), rmuOf(to), 'feeder-cable', 33, c.z, { open: !!h.open, lengthM: h.lengthM, areaMm2: h.areaMm2,
ratingA: c.ratingA, group: h.group || 1, feeder: f.id, path: h.path || null,
devices: [from.startsWith('MVB') ? 'board: ' + DEVICES['mv-way'][0] : 'RMU outgoer', to.startsWith('MVB') ? 'board way' : 'RMU incomer'],
label: `${f.id} ${h.open ? 'normally-open link' : 'feeder cable'}, ${h.areaMm2} mm² Al, ${Math.round(h.lengthM)} m${h.group < 1 ? `, group factor ${h.group}` : ''}` });
});
return setTaps({ nodes, branches, params: p, label: SLD_LABEL, kind: src.kind, mw: src.mw ?? null, connection: src.hv.rule || null });
}
const kvLvOf = p => (p.acVolts || 800) / 1000;
const round = x => Math.round(x * 1000) / 1000;
/** The graph as plain JSON for the GPU pair (tools/sld-export.mjs): what the solvers need, in a stable order. */
export function graphJson(g) {
return { schema: 'sld-graph/1', label: g.label, kind: g.kind, mw: g.mw, sBaseMVA: g.params.sBaseMVA, c: g.params.c,
nodes: g.nodes.map(n => ({ id: n.id, kind: n.kind, kv: n.kv, s: n.s })),
branches: g.branches.map(b => ({ id: b.id, from: b.from, to: b.to, kind: b.kind, kv: b.kv, z: b.z, open: b.open, ...(b.tap ? { tap: b.tap } : {}) })) };
}Single-Line Diagram (SLD) Plant
A JavaScript module in the world folder of GlobalGrid2050 that works with transformers, solar and cables, using IEC 60909.
electricalglobalgrid2050 / solar-design-studio/202609271552-site-world/world/sld-plant.mjs · lines 1–128 of 128 · version 2026-09-27 15:52 · Not reached from any entry point (candidate for review) · pattern spread (shared by 2 files)
- What it does
- It calculates transformers, solar and cables. Defines 8 functions or classes, including up, spread, stationSplit, sldPlant, check.
- Why it exists in the grid workflow
- Domain stage sub33kv_design (path word 'design'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary. Domain terms in the code: transformers, solar, cables, 400kV.
- Inputs & outputs
- Voltage levels named: 400kV.
- What it achieves
- It sizes chain (`sizeChain`) and is built from the spread step (`spread`) and the station split helper (`stationSplit`). A whole solar plant as a single-line network, from generic rules, for the diagram and the load flow. Its code works with 20 kA, 400 kV and 400 kVA.
- Why it matters
- No other file in the estate was found to import it.
- Application
- globalgrid2050 · solar-design-studio/202609271552-site-world/world · JavaScript module
- Uses
- Cable Rating (import), Plant Template (import), Single-Line Diagram (SLD) Rules (import)
- Used by
- none found
- Produces
- PLANT_DEFAULTS, stationSplit, sldPlant
- Defines here
- up, spread, stationSplit, sldPlant, check, sizeChain, side, drop
- 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/sld-plant.mjs:1-128 · blob 6dfedb7b91da18de7c157e4c25989b3c1026d331 · 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
// sld-plant.mjs: a whole solar plant as a single-line network, from generic rules, for the diagram and the load flow.
//
// The same rules as plant-template.mjs, with the diagram's refinements:
// inverters counted at unity power factor (100-400 kVA each) and spread evenly across stations (counts differ by at
// most one); a remainder of half a station or less becomes one half-size station, never a tiny one;
// each station transformer is one unit with a list of LV windings (two on a full station, one on a half station),
// rated at the sum of its inverters, with its vector group, impedance and taps;
// MV board sections = grid transformers x their LV windings (two above a size threshold), equal feeders per section,
// each section with its own earthing transformer and NER, spare ways, and optional storage way and harmonic filter;
// feeders radial chains by default (rings optional, with one normally-open point); each segment sized from the load
// it carries with the group factor of the circuits leaving the board together, not below the fault minimum (from the
// computed board fault level plus the inverters' contribution, not the switchgear rating), then an
// economic step over a small size palette, then upsized until the 0.5 % drop is met;
// the connection a short, fully ducted, unjointed HV cable to a gas-insulated bay at the operator's substation, with
// a disconnector, earth switch and surge arresters at the plant end (an overhead tee is an option, off by default).
// Lengths are placeholders until a layout sets them. Illustrative, not a design for any site. Pure.
import { sizeFor, dropPercent, SIZES } from './cable-rating.mjs';
import { gridChoice, faultMinArea, GRID_MVA } from './plant-template.mjs';
import { groupFactor, economicSize, PALETTE, SLD_DEFAULTS, SLD_LABEL } from './sld-rules.mjs';
export const PLANT_DEFAULTS = Object.freeze({
inverterKVA: 300, invertersPerStation: 20, feederLimitMVA: 25, stationsPerFeederMax: 4, maxUtilisation: 0.9,
vdropLimitPct: 0.5, faultKA: 20, faultS: 1, soilKmW: 1.2, gridFactor: 1.1, spareWays: 1, storageWay: false,
harmonicFilter: false, topology: 'radial', pocKv: 400, connection: 'cable', hvLengthM: 1500, headLengthM: 1500,
headStepM: 250, linkLengthM: 300, acAreaMm2: 400, acSpacingM: 25, linkRingM: 300
});
const up = (steps, v) => steps.find(s => s >= v - 1e-9) ?? steps.at(-1);
const spread = (total, parts) => Array.from({ length: parts }, (_, i) => Math.floor(total / parts) + (i < total % parts ? 1 : 0));
/** Inverters per station: balanced full stations, plus one half-size station for a remainder of half a station or less. */
export function stationSplit(inverters, perMax) {
const full = Math.floor(inverters / perMax), rem = inverters - full * perMax;
if (!rem) return spread(inverters, full).map(n => ({ inverters: n, half: false }));
if (!full || rem > perMax / 2) return spread(inverters, full + 1).map(n => ({ inverters: n, half: false }));
const half = Math.round(inverters * 0.5 / (full + 0.5));
return [...spread(inverters - half, full).map(n => ({ inverters: n, half: false })), { inverters: half, half: true }];
}
/** sldPlant({ targetMW, ...choices }) -> the plant as a network source (see sld-graph.mjs), with counts and checks. */
export function sldPlant(opts = {}) {
const p = { ...PLANT_DEFAULTS, ...SLD_DEFAULTS, ...opts }, mw = Number(p.targetMW);
if (!(mw > 0 && mw <= 5000)) throw Error('sld plant: targetMW must be between 0 and 5000');
if (!(p.inverterKVA >= 100 && p.inverterKVA <= 400)) throw Error('sld plant: inverterKVA must be 100 to 400');
if (!(p.invertersPerStation >= 8 && p.invertersPerStation <= 30)) throw Error('sld plant: invertersPerStation must be 8 to 30');
if (![132, 275, 400].includes(p.pocKv)) throw Error('sld plant: connection at 132, 275 or 400 kV');
const inverters = Math.ceil(mw * 1000 / p.inverterKVA - 1e-9);
let invNo = 0;
const stations = stationSplit(inverters, p.invertersPerStation).map((s, i) => {
const id = `S${i + 1}`, kva = s.inverters * p.inverterKVA, nW = s.half ? 1 : 2;
const windings = spread(s.inverters, nW).map((k, w) => ({ id: 'ab'[w], kva: k * p.inverterKVA,
inverters: Array.from({ length: k }, (_, j) => ({ id: `I${++invNo}`, kva: p.inverterKVA, acAreaMm2: p.acAreaMm2,
acLengthM: p.acSpacingM * (1 + Math.floor(j / 2)) })) }));
return { id, at: null, rmuAt: null, half: s.half, inverters: s.inverters, kva,
units: [{ id: 'T', mva: kva / 1000, zPct: p.stZPct, xr: p.stXR, vector: nW === 2 ? p.stVector : 'Dy11', taps: '±2 × 2.5 %', windings }] };
});
// Feeders, then grid transformers and board sections; the feeder count is rounded up to fill every section equally.
const stMax = Math.max(...stations.map(s => s.kva / 1000));
const per = Math.max(1, Math.min(p.stationsPerFeederMax, Math.floor(p.feederLimitMVA / stMax)));
const n0 = Math.ceil(stations.length / per);
const loads0 = spread(stations.length, n0).map(k => ({ loadMVA: k * stMax }));
const g0 = gridChoice(mw, mw * p.gridFactor, null, loads0);
const lvW = g0.mva >= p.gtTwoLvFromMVA ? 2 : 1;
let S = g0.units * lvW, nF = Math.ceil(n0 / S) * S;
if (nF > stations.length) { nF = Math.max(n0, Math.min(stations.length, nF)); S = Math.min(S, nF); }
// Fault minimum from the computed board level (grid source + one grid transformer winding, IEC 60909 c = 1.1) plus the
// inverters' own contribution (about 1.2 x rated current, assumed), not from the switchgear's rated 20 kA.
const kvHv = p.pocKv, zs = p.c * p.sBaseMVA / (Math.sqrt(3) * kvHv * p.sourceKA), zt = p.gtZPct / 100 * p.sBaseMVA / (g0.mva / lvW);
const boardKA = p.c / (zs + zt) * p.sBaseMVA / (Math.sqrt(3) * 33) + 1.2 * mw / (Math.sqrt(3) * 33);
const perSection = Math.ceil(nF / S), counts = spread(stations.length, nF), minArea = faultMinArea(Math.min(p.faultKA, boardKA), p.faultS);
const opt = { soilKmW: p.soilKmW, kv: 33, pf: p.powerFactor };
const feeders = [];
for (let f = 0, k = 0; f < nF; f++) {
const chain = stations.slice(k, k + counts[f]); k += counts[f];
const section = `MVB${Math.floor(f / perSection) + 1}`, inSection = f % perSection;
feeders.push(sizeChain({ id: `F${f + 1}`, section, chain, head: p.headLengthM + inSection * p.headStepM,
group: groupFactor(Math.min(perSection, nF - Math.floor(f / perSection) * perSection)), p, opt, minArea }));
}
const sections = Array.from({ length: S }, (_, s) => ({ id: `MVB${s + 1}`, gt: `GT${Math.floor(s / lvW) + 1}`, winding: 'ab'[s % lvW],
spareWays: p.spareWays, storageWay: !!p.storageWay, harmonicFilter: !!p.harmonicFilter }));
const gtLoad = new Map();
for (const f of feeders) { const gt = sections.find(s => s.id === f.section).gt; gtLoad.set(gt, (gtLoad.get(gt) || 0) + f.loadMVA); }
const units = Math.ceil(S / lvW), gtMVA = Math.max(g0.mva, up(GRID_MVA, Math.max(...gtLoad.values())));
const grid = Array.from({ length: units }, (_, g) => ({ id: `GT${g + 1}`, mva: gtMVA, zPct: p.gtZPct, xr: p.gtXR, vector: p.gtVector,
hvNeutral: p.gtHvNeutral, lvWindings: lvW, at: null }));
const hv = { kv: p.pocKv, connection: p.connection, rule: 'assumed', ruleText: 'generic plant, no map: connection assumed', lengthM: p.hvLengthM, ducted: true, unjointed: true, protection: 'tiles',
landing: { kind: p.connection === 'ohl-tee' ? 'tower' : 'gis-bay', e: null, n: null, kv: p.pocKv, real: false, distanceM: p.hvLengthM } };
const check = (name, value, max, min = -Infinity) => ({ name, value, min, max, ok: value <= max + 1e-9 && value >= min - 1e-9 });
const invCounts = stations.filter(s => !s.half).map(s => s.inverters);
const checks = [
check('inverters per full station differ by at most one', Math.max(...invCounts) - Math.min(...invCounts), 1),
check('feeder load MVA', Math.max(...feeders.map(f => f.loadMVA)), p.feederLimitMVA),
check('MV voltage drop % (worst feeder)', Math.max(...feeders.map(f => f.dropPct)), p.vdropLimitPct),
check('solar feeders per board section', perSection, 6),
check('load on each grid transformer', Math.max(...gtLoad.values()) / gtMVA, 1)
];
return { kind: 'template', label: SLD_LABEL, mw, pocKv: p.pocKv, params: p, stations, feeders, sections, grid, hv, checks,
boardFaultKA: boardKA, minAreaMm2: minArea, ok: checks.every(c => c.ok), counts: { inverters, stations: stations.length, halfStations: stations.filter(s => s.half).length,
feeders: nF, sections: S, gridTransformers: units, gtLvWindings: lvW, perFeeder: per },
note: `Generic single-line network from rating rules; lengths are placeholders until a layout sets them. ${SLD_LABEL}` };
}
// A radial chain: each segment from the load it carries (group factor at the head), fault minimum, economic step, drop.
function sizeChain({ id, section, chain, head, group, p, opt, minArea }) {
// A ring (topology 'ring', the same shape as block-mv.mjs) runs back to its board with one normally-open hop in the
// middle; every hop is sized for the whole ring load (one end out), and the drop is checked for normal running.
const ring = p.topology === 'ring', total = chain.reduce((t, x) => t + x.kva / 1000, 0), open = ring ? Math.ceil(chain.length / 2) : -1;
const ends = ring ? [...chain, null] : chain, sum = (a, b) => chain.slice(a, b).reduce((t, x) => t + x.kva / 1000, 0);
const hops = ends.map((s, k) => {
const loadMVA = ring ? total : sum(k), g = k && s ? 1 : group, lengthM = k && s ? p.linkLengthM : head;
const tech = (sizeFor(loadMVA / p.maxUtilisation, { ...opt, minArea, groupFactor: g }) || { area: SIZES.at(-1) }).area;
return { from: k ? chain[k - 1].id : section, to: s ? s.id : section, loadMVA, lengthM, group: g, technical: tech, open: k === open,
running: ring ? (k < open ? sum(k, open) : k > open ? sum(open, k) : 0) : loadMVA, areaMm2: economicSize(tech, loadMVA, lengthM, opt) };
});
const side = hs => hs.reduce((t, h) => t + dropPercent(h.areaMm2, h.lengthM, h.running, opt), 0);
const drop = () => (ring ? Math.max(side(hops.slice(0, open)), side(hops.slice(open + 1))) : side(hops));
for (let guard = 0; drop() > p.vdropLimitPct && guard < 60; guard++) {
const can = hops.filter(h => h.areaMm2 < SIZES.at(-1)).sort((a, b) => b.running * b.lengthM - a.running * a.lengthM)[0];
if (!can) break;
if (ring) for (const h of hops) h.areaMm2 = PALETTE.find(a => a > h.areaMm2) ?? SIZES.at(-1); // a ring keeps one size
else can.areaMm2 = PALETTE.find(a => a > can.areaMm2) ?? SIZES.at(-1); // the next size in the palette
}
return { id, section, sectionB: section, topology: ring ? 'ring' : 'radial', openAt: ring ? hops[open].from : null, hops,
loadMVA: total, dropPct: drop() };
}Single-Line Diagram (SLD) Source
A JavaScript module in the world folder of GlobalGrid2050 that works with transformers, cables, solar and 33kV.
electricalglobalgrid2050 / solar-design-studio/202609271552-site-world/world/sld-source.mjs · lines 1–91 of 91 · version 2026-09-27 15:52 · Not reached from any entry point (candidate for review) · pattern polyLen (shared by 44 files)
- What it does
- It calculates transformers, cables, solar and 33kV. Defines 6 functions or classes, including polyLen, hvOf, sourceFromBlock, sourceFromLayout, hops.
- Why it exists in the grid workflow
- Domain stage sub33kv_design (path word 'design'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary. Domain terms in the code: transformers, cables, solar, 33kV, 400kV.
- Inputs & outputs
- Voltage levels named: 400kV, 33kV.
- Downstream impact
- Used directly by 2 files: Hud Drops (globalgrid2050); Single-Line Diagram (SLD) Mount (globalgrid2050).
- What it achieves
- It is built from the poly len helper (`polyLen`), the HV of helper (`hvOf`) and the source from block helper (`sourceFromBlock`). The plant in the world as a network source for `sld-graph.mjs`, with national-grid positions. Its code works with 33 kV, 400 kV and 5 MVA.
- Why it matters
- Imported by Hud Drops and Single-Line Diagram (SLD) Mount.
- Application
- globalgrid2050 · solar-design-studio/202609271552-site-world/world · JavaScript module
- Uses
- Single-Line Diagram (SLD) Rules (import)
- Used by
- imported by Hud Drops (import), imported by Single-Line Diagram (SLD) Mount (import)
- Produces
- sourceFromBlock, sourceFromLayout
- Defines here
- polyLen, hvOf, sourceFromBlock, sourceFromLayout, hops, txOf
- 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/sld-source.mjs:1-91 · blob be855e8cd8e9abdff167fd4b81a6fab07945ad11 · 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
// sld-source.mjs: the plant in the world as a network source for sld-graph.mjs, with national-grid positions.
// sourceFromBlock(built, anchor, landing) the owner's solar block (block-build.mjs): his two 5 MVA transformers
// per station, 14 inverters each on 3 x 400 mm2 Al AC cables along his routes, the 33 kV feeders as routed;
// sourceFromLayout(result, landing) a plant laid out in a boundary (plant-layout.mjs), feeders as routed.
// conn: the connection sld-connect.mjs chose (cable to a 400 kV bay, a tee, or a 132 / 33 kV operator substation); null: assumed.
// Illustrative, not a design for any site. Pure.
import { SLD_DEFAULTS, SLD_LABEL } from './sld-rules.mjs';
const polyLen = pts => pts.reduce((t, q, i) => (i ? t + Math.hypot(q[0] - pts[i - 1][0], q[1] - pts[i - 1][1], (q[2] ?? 0) - (pts[i - 1][2] ?? 0)) : 0), 0);
// The connection from the plant-end bay to the landing (sld-connect.mjs chooses it): a straight, fully ducted,
// unjointed cable, or an overhead tee; with no connection chosen, an assumed point 1.5 km away that says so.
function hvOf(conn, kvDefault, plantAt, assumedM = 1500) {
const c = conn || { rule: 'assumed', kv: kvDefault, connection: 'cable', landing: null,
text: `no grid data loaded here: a ${kvDefault} kV cable to an assumed landing` };
const real = !!(c.landing && Number.isFinite(c.landing.e)), kv = c.kv;
const L = real ? Math.hypot(c.landing.e - plantAt[0], c.landing.n - plantAt[1]) : assumedM;
const at = real ? [c.landing.e, c.landing.n] : [plantAt[0] + assumedM, plantAt[1]];
const kind = real ? c.landing.kind : c.connection === 'none' ? 'none' : kv >= 275 ? 'gis-bay' : 'dno-sub';
return { kv, connection: c.connection === 'ohl-tee' ? 'ohl-tee' : 'cable', rule: c.rule, ruleText: c.text, lengthM: Math.max(20, L),
ducted: true, unjointed: true, protection: 'tiles', plantAt, path: [plantAt, at], landing: { kind, e: at[0], n: at[1], kv, real, distanceM: L } };
}
/** The placed solar block as a network source. built: buildBlock(...), anchor: [E, N]. */
export function sourceFromBlock(built, anchor, conn = null) {
const [E, N] = anchor, mv = built.mv, st = built.station, s = st.params;
const acLen = new Map(), acPath = new Map();
st.acCables.forEach((c, i) => { if (i % 3 === 0) { acLen.set(i / 3, polyLen(c.points)); acPath.set(i / 3, c.points); } });
const stations = mv.stations.map(S => {
const [ox, oy] = S.offset, at = [E + ox + s.transformers[0][0], N + oy + (s.transformers[0][1] + s.transformers.at(-1)[1]) / 2];
const units = st.transformers.map((t, k) => ({ id: `T${k + 1}`, mva: t.mva, zPct: SLD_DEFAULTS.stZPct, xr: SLD_DEFAULTS.stXR, vector: 'Dy11',
taps: '±2 × 2.5 %', at: [E + ox + t.point[0], N + oy + t.point[1]],
windings: [{ id: 'a', kva: st.inverters.filter(i => i.transformer === k + 1).reduce((a, i) => a + i.kva, 0),
inverters: st.inverters.filter(i => i.transformer === k + 1).map(i => ({ id: `I${i.id}`, kva: i.kva, acAreaMm2: s.acAreaMm2,
acLengthM: acLen.get(i.id - 1), at: [E + ox + i.point[0], N + oy + i.point[1]],
acPath: acPath.get(i.id - 1).map(q => [E + ox + q[0], N + oy + q[1], q[2]]) })) }] }));
return { id: S.id, at, rmuAt: [E + S.rmu[0], N + S.rmu[1]], half: false, inverters: st.inverters.length, kva: st.inventory.aggregateInverterMVA * 1000,
units, offset: [ox, oy] };
});
const mvPath = new Map((built.cables?.mv || []).map(c => [c.id, c.points]));
const feeders = mv.rings.map(r => ({ id: r.id, section: r.boardA, sectionB: r.boardB, topology: r.topology || (r.openAt ? 'ring' : 'radial'), openAt: r.openAt,
hops: r.hops.map((h, i) => ({ from: h.from, to: h.to, areaMm2: h.areaMm2 ?? r.areaMm2, lengthM: h.lengthM, open: i === r.open,
group: h.group || 1, path: mvPath.get(`${r.id}-${i + 1}`) || null })) }));
const C = mv.compound, boardAt = [E + mv.board[0], N + mv.board[1]];
const sections = Array.from({ length: mv.sections }, (_, k) => ({ id: `MVB${k + 1}`, gt: `GT${(k % mv.grid.units) + 1}`, winding: 'a',
spareWays: 1, storageWay: false, harmonicFilter: false, at: [boardAt[0], boardAt[1] - 6 + 4 * k] }));
const grid = mv.grid.at.map(([x, y], g) => ({ id: `GT${g + 1}`, mva: mv.grid.mva, zPct: SLD_DEFAULTS.gtZPct, xr: SLD_DEFAULTS.gtXR,
vector: SLD_DEFAULTS.gtVector, hvNeutral: SLD_DEFAULTS.gtHvNeutral, lvWindings: 1, at: [E + x, N + y] }));
const plantAt = [E + mv.poc.at[0], N + mv.poc.at[1]];
const hv = hvOf(conn, mv.poc.kv, plantAt);
return { kind: 'block', label: SLD_LABEL, mw: mv.exportMW, pocKv: hv.kv, params: { acVolts: s.acVolts }, stations, feeders, sections,
grid: hv.kv === 33 ? [] : grid,
hv, compound: { at: [E + C.x, N + C.y], w: C.w, d: C.d, boardAt } };
}
/** A laid-out plant (plant-layout.mjs result) as a network source: its template stations, feeders routed on its roads. */
export function sourceFromLayout(r, conn = null, { acSpacingM = 25 } = {}) {
const tpl = r.template, F = r.frame, en = (u, v) => F.en(u, v), P = tpl.params;
const byId = new Map(r.stations.map(s => [s.id, s]));
let invNo = 0;
const stations = tpl.nodes.filter(n => n.kind === 'station').map(n => {
const s = byId.get(n.id), at = s ? en(s.u, s.v) : null, k = n.rating.inverters, half = [Math.ceil(k / 2), Math.floor(k / 2)];
const windings = half.filter(x => x > 0).map((m, w) => ({ id: 'ab'[w], kva: m * P.inverterKVA,
inverters: Array.from({ length: m }, (_, j) => ({ id: `I${++invNo}`, kva: P.inverterKVA, acAreaMm2: 400, acLengthM: acSpacingM * (1 + Math.floor(j / 2)) })) }));
return { id: n.id, at, rmuAt: at, half: false, inverters: k, kva: n.rating.kva,
units: [{ id: 'T', mva: n.rating.kva / 1000, zPct: SLD_DEFAULTS.stZPct, xr: SLD_DEFAULTS.stXR, vector: windings.length > 1 ? 'Dy11y11' : 'Dy11',
taps: '±2 × 2.5 %', windings }] };
});
const routed = new Map((r.electrical?.feeders || []).map(f => [f.id, f]));
const feeders = tpl.feeders.map((f, i) => {
const e = routed.get(`F${i + 1}`);
const hops = (e ? e.hops : f.segments.map((sg, k) => ({ from: k ? f.chain[k - 1].id : f.board, to: f.chain[k].id, areaMm2: sg.area, lengthM: sg.lengthM })))
.map(h => ({ from: h.from, to: h.to, areaMm2: h.areaMm2, lengthM: h.lengthM, open: false, group: 1 }));
return { id: `F${i + 1}`, section: f.board, sectionB: f.board, topology: 'radial', openAt: null, hops };
});
const cm = r.compound, cAt = en(cm.u, cm.v), boards = tpl.nodes.filter(n => n.kind === 'switchboard');
const gts = tpl.nodes.filter(n => n.kind === 'grid-transformer');
const txOf = b => (tpl.links.find(l => l.to === b.id && l.kind === 'mv-bus')?.from) || 'GT1';
const sections = boards.map((b, k) => ({ id: b.id, gt: gts.length ? txOf(b) : 'GT1', winding: 'a', spareWays: P.spareWays, storageWay: false,
harmonicFilter: false, at: en(cm.u - cm.w / 4, cm.v - 6 + 4 * k) }));
const grid = (gts.length ? gts : [{ id: 'GT1', rating: { mva: Math.max(20, tpl.params.targetMW * 1.1) } }]).map((g, k) => ({ id: g.id, mva: g.rating.mva,
zPct: SLD_DEFAULTS.gtZPct, xr: SLD_DEFAULTS.gtXR, vector: SLD_DEFAULTS.gtVector, hvNeutral: SLD_DEFAULTS.gtHvNeutral, lvWindings: 1,
at: en(cm.u + 4 + (k % 2) * 14 - 2, cm.v - cm.d / 4 + Math.floor(k / 2) * 10) }));
const kv = [132, 275, 400].includes(tpl.ratings.pocKv) ? tpl.ratings.pocKv : 400;
const plantAt = en(cm.u + cm.w / 2 - 8, cm.v);
const hv = hvOf(conn, kv, plantAt);
return { kind: 'layout', label: SLD_LABEL, mw: tpl.params.targetMW, pocKv: hv.kv, params: {}, stations, feeders, sections,
grid: hv.kv === 33 ? [] : grid,
hv, compound: { at: cAt, w: cm.w, d: cm.d, boardAt: sections[0]?.at || cAt } };
}