In this section
- Kuiper Programs render · globalgrid2050 / kuiper-grid/i0083/cartridges/007800000000-kuiper-programs.js lines 512–1211
Kuiper Programs
A JavaScript module in the cartridges folder of GlobalGrid2050 covering cables, solar, substations and transformers, using IEC 62446-1 and SHA-256, and uses data from the faraday repository.
renderglobalgrid2050 / kuiper-grid/i0083/cartridges/007800000000-kuiper-programs.js · lines 512–1211 of 3254 (continued from section 1345) · Not reached from any entry point (candidate for review) · pattern stringComponent (shared by 18 files)
- What it does
- It draws cables, solar, substations and transformers. Defines 193 functions or classes, including reFire, closestPair, blackSky, nameInLines, makeBody. Side effects: changes the web page (DOM); reads or writes files; makes network requests.
- Why it exists in the grid workflow
- Domain stage agent_infra (path word 'kuiper'): AI-agent memory, coordination and code audit (the multi-agent journey named in Ventus Ltd's brief). Domain terms in the code: cables, solar, substations, transformers, 400kV, 1500V.
- Inputs & outputs
- In: data source: faraday data; JSON file current.json. Out: canvas drawing. Voltage levels named: 400kV, 1500V.
- What it achieves
- It makes body (`makeBody`), sets tag (`setTag`) and merges menu (`mergeMenu`). A cartridge of the Kuiper shell. Its code works with 352 kVA, 295 kVA and 320 kVA. It responds to click, keydown and pointerdown events.
- Why it matters
- No other file in the estate was found to import it.
- Application
- globalgrid2050 · kuiper-grid/i0083/cartridges · JavaScript module
- Uses
- Faraday — Index Page (estate URL), Wafer Development Environment — Proof S0004 Page (estate URL), ./fire.js
- Used by
- none found
- Produces
- reFire, closestPair, blackSky, nameInLines, makeBody, bodyTo, labels, bodyJump, bodyMove, bodyDrawnDiameter, bodyDotPx, sheet
- Defines here
- rnd, run, rnd, LAYOUT_WORDS, build, extraAfter, rowOf0, turned, x0, ptAt, minusPt, minus, inRow, run, run, r, p2, dist, polyLength, dedupe, stringComponent, buildBlock, st, provisional, push
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 kuiper-grid/i0083/cartridges/007800000000-kuiper-programs.js:512-1211 · blob 6d2a91cc3007a5774bb0fe55f2a2650e3247b7af · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom, filesystem, network · domain stage: agent_infra · users: ai_agent · canonical: unreached_review
const kids = {}; for (const n of Object.keys(parent)) if (parent[n] !== null) (kids[parent[n]] = kids[parent[n]] || []).push(n);
const order = ['grid']; for (let i = 0; i < order.length; i++) order.push(...(kids[order[i]] || []));
let V = {}; for (const n of order) V[n] = [vb, 0]; let rounds = 0, J;
for (;;) {
rounds++; J = {}; for (const n of order) J[n] = S[n] ? conj(div(S[n], V[n])) : [0, 0];
for (let i = order.length - 1; i >= 0; i--) { const n = order[i]; if (parent[n] !== null) J[parent[n]] = add(J[parent[n]], J[n]); }
const nv = { grid: [vb, 0] }; for (let i = 1; i < order.length; i++) { const n = order[i]; nv[n] = sub(nv[parent[n]], mul(J[n], Z[n])); }
let step = 0; for (const n of order) step = Math.max(step, mag(sub(nv[n], V[n]))); V = nv;
if (step < tol || rounds > 300) break;
}
const sPoc = scale(mul(V.poc, conj(J.poc)), 3);
let loss = 0; for (let i = 1; i < order.length; i++) loss += mag(J[order[i]]) ** 2 * Z[order[i]][0]; loss *= 3;
let netP = 0; for (const n of Object.keys(S)) netP += S[n][0]; netP *= 3;
const source = mul(V.grid, conj(J.poc))[0] * 3;
let tx = -Infinity, amps = -Infinity; const txEach = {}, ampsEach = {}, vEach = {};
for (const n of Object.keys(kva)) { txEach[n] = mag(scale(mul(V[n], conj(J[n])), 3)) / 1000 / kva[n] * 100; tx = Math.max(tx, txEach[n]); }
for (let i = 1; i < order.length; i++) { const n = order[i]; if (!(n in kva)) { ampsEach[n] = mag(J[n]); amps = Math.max(amps, ampsEach[n]); } }
let vmax = -Infinity, vmin = Infinity; for (const n of order) { const v = mag(V[n]) / vb; vEach[n] = v; vmax = Math.max(vmax, v); vmin = Math.min(vmin, v); }
return { p: sPoc[0] / 1000, q: sPoc[1] / 1000, loss: loss / 1000, vmax, vmin, tx, amps, rounds, balance: Math.abs(source - netP - loss) / Math.max(Math.abs(netP), 1.0),
each: { volts: vEach, tx: txEach, amps: ampsEach }, parent };
}
const rnd = (x, d) => Number(x.toFixed(d));
function run(i) {
if (i.seed === undefined) throw new Error('this command needs "seed" (any whole number: each one is a different network)');
const net = i.network || network(i.seed, i.variant || 0), ps = i.solar === undefined ? 1 : i.solar, g = i.generator === undefined ? 0 : i.generator, ls = i.load === undefined ? 1 : i.load;
const r = solve(net, ps, !!g, ls), c = C, exp = Math.max(0, -r.p), over = Math.max(0, exp - net.export_limit_kw), flags = [];
if (r.rounds > 300 || r.balance >= 1e-6) flags.push('THE SWEEP DID NOT CONVERGE: this network is beyond the method, and no number here should be used');
if (over > 0) flags.push('export ' + exp.toFixed(0) + ' kW is ' + over.toFixed(0) + ' kW over the ' + net.export_limit_kw + ' kW limit');
if (r.vmax > c.volts_high_pu) flags.push('highest voltage ' + r.vmax.toFixed(3) + ' is over ' + c.volts_high_pu);
if (r.vmin < c.volts_low_pu) flags.push('lowest voltage ' + r.vmin.toFixed(3) + ' is under ' + c.volts_low_pu);
if (r.tx > 100) flags.push('a transformer is at ' + r.tx.toFixed(0) + '% of its rating');
const pv = net.subs.reduce((t, s) => t + s.pv_kw, 0), load = net.subs.reduce((t, s) => t + s.load_kw, 0);
return { numbers: { substations: net.subs.length, load_kw: rnd(load * ls, 0), solar_kw: rnd(pv * ps, 0), generator_kw: g ? net.generator_kw : 0, export_limit_kw: net.export_limit_kw,
connection_point_kw: rnd(r.p, 1), connection_point_kvar: rnd(r.q, 1), losses_kw: rnd(r.loss, 2), highest_volts_pu: rnd(r.vmax, 4), lowest_volts_pu: rnd(r.vmin, 4),
worst_transformer_pct: rnd(r.tx, 1), busiest_cable_amps: rnd(r.amps, 1), rounds: r.rounds },
said: 'A ' + net.shape + ' of ' + net.subs.length + ' substations behind a ' + net.fault_mva + ' MVA connection: ' + (r.p < 0 ? 'exports ' : 'imports ') + Math.abs(r.p).toFixed(0) + ' kW; volts ' + r.vmin.toFixed(3) + ' to ' + r.vmax.toFixed(3) +
'; busiest transformer ' + r.tx.toFixed(0) + '%; ' + (flags.length ? flags.join('; ') : 'inside every limit'),
how: 'network number ' + net.seed + ' from a stated generator (no real site); two pulses per round until the volts stop moving; every figure a CANDIDATE. An estimate, not a study.', net, solved: r };
}
const F = root.FIRE || (typeof require !== 'undefined' ? require('./fire.js') : null);
if (!F) throw new Error('fire_topo.js needs fire.js loaded first');
F.register('network', 'NETWORKS', run);
F.topo = { network, solve, CASES, C };
})(typeof window !== 'undefined' ? window : globalThis);
// ===== ONE SOLAR STRING, WIRED TWO WAYS: fire string {"wiring":"leapfrog"} =======================
// A row of modules in series. SEQUENTIAL joins each module to the next and needs one more cable the length of the row to bring the
// far end home. LEAPFROG joins every other module on the way out and the ones between on the way back, so both ends finish at the
// near end and that cable is not laid: the return travels in the modules' own leads. Whether the leads REACH is geometry: the two
// junction boxes sit a stated distance apart on every module, so a link on the way out is two pitches LESS that distance and a link
// on the way back is two pitches MORE. Every length here is counted from stated inputs; every figure is an estimate. No real site.
(function (root) {
const F = root.FIRE; if (!F) return;
const R20 = { 2.5: 8.21, 4: 5.09, 6: 3.39, 10: 1.95 }; // milliohm per metre at 20 C, tinned copper, class 5
const DEF = { modules: 30, width_m: 1.303, module_height_m: 2.384, cell_cols: 6, cell_rows: 22, module_vmp: 38.1, module_voc: 45.9,
// THE TABLE ITSELF. One module high in portrait on a fixed tilt is the old row, exactly.
mounting: 'fixed', orientation: 'portrait', modules_high: 1, routing: '', view: 'wiring', sheet: 0,
// A RETURN TIER IS MOUNTED THE OTHER WAY ROUND, and that is not a detail. Going back along
// the upper row, the + box of one module has to reach the - box of the one to its LEFT, so
// the link is a pitch PLUS the box spacing instead of a pitch minus it: 2.16 m where 0.48 m
// was expected. Turning every module in the return rows end for end puts it back to 0.48 m,
// and that is what is actually done on a table. It is an input because it is a decision.
turn_alternate_rows: 0,
// A JUMPER IS WHAT IS REALLY DONE when two leads do not meet: a short cable is made up on
// site and spliced between them, which closes the circuit and costs cable and one more
// mated pair at that link. Without this the model says the string is open, which is the
// truth about the LEADS and not about the finished job. Off by default, because a jumper
// is a decision somebody has to take and pay for.
jumpers: 0,
gap_up_m: 0.02, ridge_gap_m: 0.15, tube_gap_m: 0.12,
gap_m: 0.02, box_spacing_m: 0.84, wiring: 'leapfrog', turn_every_second: 0,
leads: 'reach', lead_slack_m: 0.20, lead_plus_m: null, lead_minus_m: null, lead_mm2: 4, cable_mm2: 6, near_end_m: 59, amps: 17.35,
// TWO CONDUCTORS IN TWO PLACES AT TWO TEMPERATURES. A module lead is clipped to the back of a
// module in the sun; the site cable is in a tray or a trench. One figure for both was always a
// simplification, and it flattered whichever of the two was hotter. conductor_c is kept as the
// NAME FOR BOTH: give it and both take it, so every command ever written still means what it
// said, and equal temperatures reproduce the old model to the digit.
conductor_c: null, t_lead_c: 80, t_site_c: 55, rating_c: 90,
// HOW FAR APART THE TWO HOME RUNS ARE LAID. The array's own loop is one thing; the pair of
// cables running back to the inverter is another, and on a long home run it is the bigger of
// the two. It has NO DEFAULT, on purpose: nobody can know from a drawing whether that pair
// was bundled or run in two trays, and the difference moves the answer more than the wiring
// choice does. Until it is given, the home run loop and the total are NOT REPORTED. A model
// that guesses a number like that is worse than a model that says it does not know.
home_separation_m: null,
// SLACK AT EVERY LINK. A lead is not a straight line: it is clipped, it drops and it comes
// back. The distance a link has to span is the straight distance between the two boxes PLUS
// whatever allowance the installer is told to leave. Zero is the geometric case.
slack_m: 0,
contact_milliohm: 0.35, return_offset_m: 0.3, lead_gap_m: 0.05 };
const rnd = (x, n) => { const k = Math.pow(10, n); return Math.round(x * k) / k; };
const ROUTE_WORDS = { 'one-after-another':'one after another, with a cable to bring the far end home',
'serpentine':'along and back, out along one row and back along the next',
'leapfrog':'leapfrog inside each row', 'zigzag':'zigzag between two rows' };
const LAYOUT_WORDS = g => { const o = g.port ? 'portrait' : 'landscape';
const m = g.mount === 'east-west' ? 'east and west facing, ' + g.high + ' in ' + o + ' on each face'
: g.mount === 'tracker' ? 'a tracker, ' + g.rows + ' in ' + o
: 'fixed tilt, ' + g.rows + ' in ' + o + (g.rows > 1 ? ' high' : '');
return m; };
// ===== THE TABLE. A string is not a row; a row is a table one module high. =====================
// A module's two boxes sit at MID LENGTH OF ITS LONG SIDE, spread along its SHORT axis. That is one
// rule and it settles both orientations without a special case: in PORTRAIT the long side is upright,
// so the - and the + sit side by side ALONG the table; in LANDSCAPE the module is turned a quarter
// turn, the long side is now horizontal, and the two boxes sit one ABOVE the other. Everything else -
// where the modules are, how far a link has to reach, what is laid on site - follows from that and
// from the grid. A table one module high in portrait reproduces the old row model to the digit, which
// is asserted rather than hoped for.
function build(inp) {
const c = Object.assign({}, DEF, inp || {}), N = Math.max(2, Math.min(60, Math.round(c.modules)));
const port = String(c.orientation || 'portrait').toLowerCase() !== 'landscape';
const wX = port ? c.width_m : c.module_height_m, wY = port ? c.module_height_m : c.width_m;
const pitch = wX + c.gap_m, pitchY = wY + c.gap_up_m;
const mount = String(c.mounting || 'fixed').toLowerCase();
const high = Math.max(1, Math.min(6, Math.round(c.modules_high)));
const faces = mount === 'east-west' ? 2 : 1, rows = high * faces;
const cols = Math.max(1, Math.ceil(N / rows));
// WHAT STANDS BETWEEN TWO ROWS: nothing on a plain table, the ridge on an east west table, the torque
// tube down the middle of a tracker.
const extraAfter = r => (faces === 2 && r === high - 1) ? c.ridge_gap_m
: (mount === 'tracker' && r === Math.floor(rows / 2) - 1) ? c.tube_gap_m : 0;
const rowY = []; { let yy = 0; for (let r = 0; r < rows; r++) { rowY.push(yy); yy += pitchY + extraAfter(r); } }
// ROUTING is what the old "wiring" input was asking, and it is kept as a name for it.
let routing = String(c.routing || '').toLowerCase();
if (!routing) routing = String(c.wiring).toLowerCase() === 'sequential' ? 'one-after-another' : 'leapfrog';
if (routing === 'along-and-back' || routing === 'sequential-u') routing = 'serpentine';
if (routing === 'sequential') routing = 'one-after-another';
if (routing === 'zigzag' && rows < 2) routing = 'one-after-another';
if (routing === 'serpentine' && rows < 2) routing = 'one-after-another';
c.routing = routing;
const leap = routing === 'leapfrog';
// THE DEFAULT STRING IS A COMPLETE STRING. Nobody builds an array and leaves half its links open;
// a drawing that opens by default is a drawing of a mistake. So unless a lead length is typed, the
// leads are THE PAIR THAT REACHES for the wiring chosen - the longest link plus the slack allowance
// - and the answer says what pair that is, to be ordered against what the module is supplied with.
// Ask for "supplied" instead and you get the factory portrait leads and, with them, the shortfall.
const leadsAre = String(c.leads || 'reach').toLowerCase();
const typedLeads = c.lead_plus_m !== null || c.lead_minus_m !== null;
if (leadsAre === 'supplied' && !typedLeads) { c.lead_plus_m = 0.35; c.lead_minus_m = 0.28; }
const rowOf0 = k => Math.min(rows - 1, Math.floor((k - 1) / cols)), colOf = k => (k - 1) % cols;
const turned = k => (!!c.turn_every_second && k % 2 === 0) !== (!!c.turn_alternate_rows && rowOf0(k) % 2 === 1);
const rowOf = rowOf0;
const x0 = k => colOf(k) * pitch, y0 = k => rowY[rowOf(k)];
const s2 = c.box_spacing_m / 2;
const ptAt = (k, want, t) => { const cxm = x0(k) + wX / 2, cym = y0(k) + wY / 2, d = (want === '+' ? 1 : -1) * (t ? -1 : 1) * s2;
return port ? [cxm + d, cym] : [cxm, cym + d]; };
const minusPt = k => ptAt(k, '-', turned(k)), plusPt = k => ptAt(k, '+', turned(k));
const minus = k => minusPt(k)[0], plus = k => plusPt(k)[0]; // the drawing reads x from these
// THE ORDER THE STRING IS WIRED IN, over the grid of modules. The modules themselves never move.
const inRow = r => { const out = []; for (let k = 1; k <= N; k++) if (rowOf(k) === r) out.push(k); return out; };
const order = [];
if (routing === 'leapfrog') { for (let r = 0; r < rows; r++) { const q = inRow(r); if (!q.length) continue;
const fwd = r % 2 === 0 ? q : q.slice().reverse();
for (let i = 0; i < fwd.length; i += 2) order.push(fwd[i]);
for (let i = (fwd.length % 2 ? fwd.length - 2 : fwd.length - 1); i >= 1; i -= 2) order.push(fwd[i]); } }
else if (routing === 'serpentine') { for (let r = 0; r < rows; r++) { const q = inRow(r); if (!q.length) continue;
order.push(...(r % 2 === 0 ? q : q.slice().reverse())); } }
else if (routing === 'zigzag') { const a0 = inRow(0), a1 = inRow(1);
for (let i = 0; i < Math.max(a0.length, a1.length); i++) { const up = i % 2 === 0;
if (up) { if (a0[i] !== undefined) order.push(a0[i]); if (a1[i] !== undefined) order.push(a1[i]); }
else { if (a1[i] !== undefined) order.push(a1[i]); if (a0[i] !== undefined) order.push(a0[i]); } }
for (let r = 2; r < rows; r++) { const q = inRow(r); order.push(...(r % 2 === 0 ? q : q.slice().reverse())); } }
else for (let k = 1; k <= N; k++) order.push(k);
// HOW FAR EACH LINK HAS TO REACH IS GEOMETRY, and it does not depend on what lead is fitted: so the
// needs are measured first, and only then is the lead pair settled.
const links = [];
for (let i = 0; i + 1 < order.length; i++) { const from = order[i], to = order[i + 1];
const A = plusPt(from), B = minusPt(to);
const need = Math.hypot(A[0] - B[0], A[1] - B[1]) + (+c.slack_m || 0);
links.push({ from, to, need, back: to < from, cross: rowOf(from) !== rowOf(to),
x_from: A[0], x_to: B[0], y_from: A[1], y_to: B[1] }); }
const longest = links.length ? Math.max(...links.map(l => l.need)) : 0;
if (c.lead_plus_m === null || c.lead_minus_m === null) {
const want = longest + (c.lead_slack_m === undefined ? 0.20 : +c.lead_slack_m);
// the + lead keeps the box spacing it really has and the - lead makes up the rest, which is how
// a module maker quotes an unequal pair
const lpWant = Math.min(want * 0.5, c.box_spacing_m);
if (c.lead_plus_m === null) c.lead_plus_m = Math.round(lpWant * 1000) / 1000;
if (c.lead_minus_m === null) c.lead_minus_m = Math.round((want - c.lead_plus_m) * 1000) / 1000; }
const pair = c.lead_plus_m + c.lead_minus_m;
for (const l of links) { l.reaches = pair + 1e-9 >= l.need;
l.jumper = !l.reaches && !!c.jumpers ? l.need - pair : 0; }
const last = order[order.length - 1], row = cols * pitch;
// HOW FAR A FREE END IS FROM THE NEAR CORNER, along the structure: a cable is clipped to steel, it
// does not fly. Both ends land at the near end when the + end is in the near half of the table.
const yBase = rowY[0] + wY / 2;
const run = q => Math.abs(q[0]) + Math.abs(q[1] - yBase);
const endRun = run(plusPt(last)), bothNear = endRun <= row / 2;
const ret = bothNear ? 0 : endRun;
// conductor_c, when it is given, is the name for both: it sets the lead and the site cable together.
if (c.conductor_c !== null && c.conductor_c !== undefined && c.conductor_c !== '') { c.t_lead_c = +c.conductor_c; c.t_site_c = +c.conductor_c; }
const fLead = 1 + 0.00393 * (c.t_lead_c - 20), fSite = 1 + 0.00393 * (c.t_site_c - 20);
// A JUMPER IS SITE CABLE AND ONE MORE MATED PAIR, at the link it is spliced into.
const jumpers = links.filter(l => l.jumper > 0), jumper_m = jumpers.reduce((t, l) => t + l.jumper, 0);
const lead_m = N * pair, field_m = 2 * c.near_end_m + run(minusPt(order[0])) + endRun + jumper_m;
const pairs = links.length + 2 + (bothNear ? 0 : 1) + jumpers.length;
// A SITE MADE END is a connector fitted to a cut cable by a person on the table: the two home runs
// always, and the far end return cable's two, when one is laid.
const siteEnds = 2 + (bothNear ? 0 : 2);
const ohmLead = (R20[c.lead_mm2] || 5.09) * lead_m * fLead / 1000;
const ohmSite = (R20[c.cable_mm2] || 3.39) * field_m * fSite / 1000;
const ohm = ohmLead + ohmSite + pairs * c.contact_milliohm / 1000;
const short = links.filter(l => !l.reaches && !l.jumper), needs = links.map(l => l.need);
// THREE LOOPS, NOT ONE. The array's own loop is what the wiring choice changes; the home run pair is
// its own loop and on a long run it is the larger; a nearby stroke couples into the SUM of them.
const arrayLoop = bothNear ? row * c.lead_gap_m : row * c.return_offset_m;
const sep = (c.home_separation_m === null || c.home_separation_m === undefined || c.home_separation_m === '') ? null : +c.home_separation_m;
const homeLoop = sep === null ? null : c.near_end_m * sep;
const loop = homeLoop === null ? null : arrayLoop + homeLoop;
// A CONDUCTOR OVER ITS RATING IS SAID IN WORDS AND NEVER QUIETLY COSTED.
const hot = [];
if (c.t_lead_c > c.rating_c) hot.push('the module leads at ' + c.t_lead_c + ' C are over the ' + c.rating_c + ' C the cable is rated for');
if (c.t_site_c > c.rating_c) hot.push('the site cable at ' + c.t_site_c + ' C is over the ' + c.rating_c + ' C it is rated for');
// WHAT IS NOT LAID ON SITE, against ONE stated baseline: the same row wired one after another, no
// module turned, with its far end brought home. Closed form, so it can be checked by hand:
// plain leapfrog saves (N-2) pitches; turning every second module saves (N-2) pitches and the box
// spacing as well, because the last module's + box has moved to the near side of its own module.
const baseEnd = Math.abs(ptAt(N, '+', false)[0]) + Math.abs(ptAt(N, '+', false)[1] - yBase);
const baseField = 2 * c.near_end_m + Math.abs(ptAt(1, '-', false)[0]) + Math.abs(ptAt(1, '-', false)[1] - yBase) + baseEnd;
const saved = baseField - field_m;
const smallest = needs.length ? Math.max(...needs) : 0;
return { c, N, pitch, pitchY, wX, wY, port, rows, cols, rowY, mount, high, faces, routing, leap, order, links,
row, pair, lead_m, field_m, pairs, siteEnds, ohm, ohmLead, ohmSite, bothNear, endRun, ret,
short, needs, smallest, jumpers, jumper_m, loop, arrayLoop, homeLoop, sep, saved, hot, fLead, fSite,
minusPt, plusPt, minus, plus, rowOf, colOf, x0, y0, turned };
}
function run(inp) {
const g = build(inp), c = g.c, worst = g.short.length ? Math.max(...g.short.map(l => l.need - g.pair)) : 0;
const name = LAYOUT_WORDS(g) + ', ' + (ROUTE_WORDS[g.routing] || g.routing)
+ (c.turn_every_second ? ', every second module turned end for end' : '');
// A SERIES CIRCUIT IS OPEN OR IT IS NOT. One pair of connectors that does not meet and the whole
// string carries nothing: not a warm link, not a derated string, NOTHING, anywhere in it.
const open = g.short.length > 0, amps = open ? 0 : c.amps;
// AN OPEN STRING IS NOT A DEAD STRING. No current flows, and that is the whole of what "open" means;
// the modules go on making their open circuit voltage, so the full string voltage stands across a
// break, and an open connector under that voltage is exactly where a direct current arc begins.
const voc = g.N * c.module_voc;
const order = g.order.map(k => 'M' + k).join(' → ');
const hotWords = g.hot.length ? ' RATING CHECK FAILED: ' + g.hot.join('; ') + '. ' : '';
const loopWords = g.sep === null
? ' The whole loop needs the home run separation: it moves the answer more than the wiring does, so only the array loop is given.'
: ' Loop ' + g.loop.toFixed(1) + ' m2 in all, of which the home run pair is ' + g.homeLoop.toFixed(1) + ' m2.';
const said = hotWords + name + ': ' + g.N + ' modules over ' + g.rows + (g.rows === 1 ? ' row' : ' rows') + ' of ' + g.cols + ', ' + g.links.length + ' links from ' + Math.min(...g.needs).toFixed(2) + ' to ' + Math.max(...g.needs).toFixed(2) + ' m against a lead pair of ' + g.pair.toFixed(2) + ' m; '
+ (g.bothNear ? 'both free ends land at the near end, so no return cable is laid; ' : 'a return cable of ' + g.ret.toFixed(1) + ' m brings the far end home; ')
+ (g.jumpers.length ? g.jumpers.length + (g.jumpers.length === 1 ? ' link is' : ' links are') + ' made up with a jumper spliced in on site, ' + g.jumper_m.toFixed(1) + ' m of cable and ' + g.jumpers.length + ' more mated pairs; ' : '')
+ (open ? 'THE CIRCUIT IS OPEN AND BOTH ENDS ARE LIVE: ' + g.short.length + ' links do not reach (short by up to ' + worst.toFixed(2) + ' m), so no current flows anywhere, but up to '
+ voc.toFixed(0) + ' V stands across a break and an open connector at that voltage is where a direct current arc starts'
: 'every link reaches, so the loop closes and ' + c.amps + ' A flows all the way round it')
+ '; ' + g.lead_m.toFixed(1) + ' m of module lead and ' + g.field_m.toFixed(1) + ' m of cable laid on site; '
+ loopWords + ' '
+ (open ? g.ohm.toFixed(3) + ' ohm IF IT WERE CLOSED, and ' + (c.amps * c.amps * g.ohm).toFixed(0) + ' W lost at ' + c.amps + ' A: nothing is lost in it now because nothing flows in it'
: g.ohm.toFixed(3) + ' ohm, ' + (amps * amps * g.ohm).toFixed(0) + ' W lost at ' + amps + ' A');
// THE CONNECTION LIST, in the order the current runs, terminal by terminal. It is the same walk the
// checks make, so what a reader sees in words is what the drawing was built from.
const connections = [{ from:'INV\u2212', to:'M' + g.order[0] + '\u2212', metres:c.near_end_m, home:true, node:'home-' }];
g.links.forEach((l, i) => connections.push({ node:'L' + i, from:'M' + l.from + '+', to:'M' + l.to + '\u2212',
needed:rnd(l.need, 2), pair:rnd(g.pair, 2), reaches:l.reaches, jumper:rnd(l.jumper || 0, 2) }));
connections.push({ from:'M' + g.order[g.order.length - 1] + '+', to:'INV+', metres:c.near_end_m, home:true, node:'home+' });
return { connections, numbers: { circuit: open ? 'OPEN, both ends live' : 'closed', current_a: rnd(amps, 2),
open_circuit_volts_at_25c: rnd(voc, 0), volts_across_a_break: open ? rnd(voc, 0) : 0, links: g.links.length,
shortest_link_m: rnd(Math.min(...g.needs), 3), longest_link_m: rnd(Math.max(...g.needs), 3), lead_pair_m: rnd(g.pair, 3),
links_that_do_not_reach: g.short.length, worst_shortfall_m: rnd(worst, 3), module_lead_m: rnd(g.lead_m, 1), cable_laid_on_site_m: rnd(g.field_m, 1),
total_conductor_m: rnd(g.lead_m + g.field_m, 1), connector_pairs: g.pairs, string_resistance_ohm: rnd(g.ohm, 4), loss_w: rnd(amps * amps * g.ohm, 1),
volt_drop_v: rnd(amps * g.ohm, 2), row_length_m: rnd(g.row, 2), string_volts_at_vmp: rnd(g.N * c.module_vmp, 0),
loss_w_if_it_were_closed: rnd(c.amps * c.amps * g.ohm, 1),
volts_to_earth_each_end: '−' + rnd(g.N * c.module_vmp / 2, 0) + ' to +' + rnd(g.N * c.module_vmp / 2, 0),
routing: g.routing, rows_of_modules: g.rows, columns_of_modules: g.cols,
modules_in_the_last_column: g.N - (g.cols - 1) * g.rows > 0 ? Math.min(g.rows, g.N - (g.cols - 1) * g.rows) : g.rows,
both_ends_at_the_near_end: g.bothNear, return_cable_m: rnd(g.ret, 2),
smallest_lead_pair_that_reaches_m: rnd(g.smallest, 3),
lead_pair_to_order_m: rnd(g.pair, 3),
connectors_fitted_on_site: g.siteEnds + 2 * g.jumpers.length,
jumpers_made_on_site: g.jumpers.length, jumper_cable_m: rnd(g.jumper_m, 2),
array_loop_m2_rough: rnd(g.arrayLoop, 2),
home_run_loop_m2_rough: g.homeLoop === null ? null : rnd(g.homeLoop, 2),
total_loop_m2_rough: g.loop === null ? null : rnd(g.loop, 2),
site_cable_saved_m: rnd(g.saved, 2),
lead_resistance_ohm: rnd(g.ohmLead, 4), site_cable_resistance_ohm: rnd(g.ohmSite, 4),
rating_check: g.hot.length ? 'FAILED: ' + g.hot.join('; ') : 'passed, both conductors at or under ' + c.rating_c + ' C' },
said, electrical_order: order,
how: 'geometry only: module ' + c.width_m + ' m wide by ' + c.module_height_m + ' m tall in portrait, ' + c.cell_cols + ' by ' + c.cell_rows
+ ' half cells, junction boxes ' + c.box_spacing_m + ' m apart at mid height, a link is the distance between the boxes it joins; leads ' + c.lead_mm2 + ' mm2, site cable ' + c.cable_mm2
+ ' mm2, copper, the leads at ' + c.t_lead_c + ' C and the site cable at ' + c.t_site_c + ' C (give conductor_c and both take that figure); near end ' + c.near_end_m + ' m from the inverter. '
+ 'The site cable temperature is an assumption and it matters: buried is about 30 C, clipped along the structure is near the lead temperature; ' + c.t_site_c + ' C was used here. '
+ 'A link has to span the STRAIGHT DISTANCE IN THE PLANE between the two boxes plus the slack allowance, ' + (+c.slack_m || 0) + ' m here. '
+ 'The boxes sit at mid length of the module\u2019s long side, spread along its short axis, so in portrait they are side by side along the table and in landscape one above the other. '
+ 'A cable to a free end is counted along the structure, not across the diagonal. '
+ 'The loop is in two parts, both rough: the ARRAY loop is the row length times a stated gap, and the HOME RUN loop is the run times how far apart the two cables are laid. '
+ 'Bundling the home run pair shrinks the loop more than the wiring choice does, for either wiring. '
+ 'Site cable not laid, against the same row wired one after another with no module turned and its far end brought home: ' + g.saved.toFixed(2) + ' m. '
+ 'Electrical order ' + order + '. Colour is the POTENTIAL RELATIVE TO THE MINUS TERMINAL, not to earth: the array floats, so either terminal may sit at up to half the '
+ 'array voltage with respect to earth, and a black line does not mean an earthed one. The line does not thicken or thin along the string, because a series circuit carries one current. '
+ 'The moving highlight is the INSTANT THE CIRCUIT CLOSES; after that the current is the same all the way round and nothing travels along the wire. An open string carries no current and is NOT safe: up to '
+ rnd(voc, 0) + ' V at 25 C stands across a break, more when it is cold. '
+ 'Every input can be changed. An estimate, not a study.', string: g, inputs_used: Object.assign({}, c) };
}
// WHAT A READER MAY TURN, in plain words with its unit. The window makes a box out of each of these.
const BOXES = [
{ key:'mounting', label:'mounting', kind:'choice', choices:[['fixed', 'fixed tilt'], ['east-west', 'east and west facing'], ['tracker', 'single axis tracker']] },
{ key:'orientation', label:'modules', kind:'choice', choices:[['portrait', 'portrait'], ['landscape', 'landscape']] },
{ key:'modules_high', label:'modules high (each face)', kind:'number', min:1, max:6, step:1 },
{ key:'turn_alternate_rows', label:'return rows turned round', kind:'choice', choices:[[0, 'no'], [1, 'yes']] },
{ key:'jumpers', label:'jumper where leads fall short', kind:'choice', choices:[[0, 'no, say it is open'], [1, 'yes, splice one in']] },
{ key:'view', label:'drawn as', kind:'choice', choices:[['wiring', 'the back, wiring'], ['scale', 'modules to scale']] },
{ key:'sheet', label:'on', kind:'choice', choices:[[0, 'the night sky'], [1, 'a drawing sheet']] },
{ key:'routing', label:'routing', kind:'choice', choices:[
['one-after-another', 'one after another, with a return cable'],
['serpentine', 'along and back, no return cable'],
['leapfrog', 'leapfrog inside each row'],
['zigzag', 'zigzag between two rows']] },
{ key:'turn_every_second', label:'every second module turned', kind:'choice', choices:[[0, 'no'], [1, 'yes']] },
{ key:'modules', label:'modules', kind:'number', min:2, max:40, step:1 },
{ key:'width_m', label:'module width', unit:'m', kind:'number', min:0.4, max:3, step:0.001 },
{ key:'module_height_m', label:'module height', unit:'m', kind:'number', min:0.4, max:4, step:0.001 },
{ key:'gap_m', label:'gap along the table', unit:'m', kind:'number', min:0, max:1, step:0.005 },
{ key:'gap_up_m', label:'gap up the table', unit:'m', kind:'number', min:0, max:1, step:0.005 },
{ key:'ridge_gap_m', label:'gap at the ridge', unit:'m', kind:'number', min:0, max:2, step:0.01 },
{ key:'tube_gap_m', label:'gap at the torque tube', unit:'m', kind:'number', min:0, max:2, step:0.01 },
{ key:'box_spacing_m', label:'junction boxes apart', unit:'m', kind:'number', min:0.05, max:2, step:0.01 },
{ key:'leads', label:'leads', kind:'choice', choices:[['reach', 'the pair that reaches'], ['supplied', 'as supplied, portrait']] },
{ key:'lead_slack_m', label:'slack in the lead pair', unit:'m', kind:'number', min:0, max:2, step:0.01 },
{ key:'lead_plus_m', label:'+ lead', unit:'m', kind:'number', min:0.05, max:8, step:0.01 },
{ key:'lead_minus_m', label:'− lead', unit:'m', kind:'number', min:0.05, max:8, step:0.01 },
{ key:'lead_mm2', label:'lead size', unit:'mm2', kind:'choice', choices:[[2.5, '2.5'], [4, '4'], [6, '6'], [10, '10']] },
{ key:'cable_mm2', label:'site cable', unit:'mm2', kind:'choice', choices:[[4, '4'], [6, '6'], [10, '10']] },
{ key:'near_end_m', label:'near end from the inverter', unit:'m', kind:'number', min:0, max:400, step:1 },
{ key:'amps', label:'current', unit:'A', kind:'number', min:0.1, max:40, step:0.01 },
{ key:'t_lead_c', label:'module lead temperature', unit:'C', kind:'number', min:-25, max:140, step:1 },
{ key:'t_site_c', label:'site cable temperature', unit:'C', kind:'number', min:-25, max:140, step:1,
hint:'buried is about 30, clipped along the structure is near the lead temperature' },
{ key:'rating_c', label:'cable rated for', unit:'C', kind:'number', min:60, max:140, step:5 },
{ key:'home_separation_m', label:'home run cables apart', unit:'m', kind:'number', min:0, max:2, step:0.01,
optional:true, hint:'bundled about 0.02, separate trays about 0.3' },
{ key:'slack_m', label:'slack allowed at each link', unit:'m', kind:'number', min:0, max:2, step:0.01 },
{ key:'module_vmp', label:'module at most power', unit:'V', kind:'number', min:5, max:100, step:0.1 },
{ key:'module_voc', label:'module open circuit', unit:'V', kind:'number', min:5, max:120, step:0.1 },
// ROOM LEFT HERE, deliberately, for inputs already agreed and not yet built: how far apart the two
// home runs are laid (which decides the home run's own loop area separately from the array's), and
// the lead temperature and the site cable temperature as two figures, with the single conductor
// temperature kept as the name for both.
{ key:'cell_cols', label:'cells across', kind:'number', min:1, max:24, step:1 },
{ key:'cell_rows', label:'cells up', kind:'number', min:2, max:48, step:2 }
];
F.register('string', 'STRINGS', run, BOXES);
F.string = { build, DEF };
})(typeof window !== 'undefined' ? window : globalThis);
// ===== ONE COMPLETE INVERTER BLOCK: fire block ==================================================
// 24 x strings of 30 modules in series x 24 strings per inverter. ALL STRINGS SHOW PER INVERTER:
// 24 of 24, 720 modules, 48 home runs, each landing on its OWN named inverter input terminal.
// THE MATHS AND THE GEOMETRY BELOW ARE COPIED, NOT REWRITTEN, from the tested library
// E:\kuiper-iterations\LIB\solar-block\block.mjs (solar-block/1.0.0, 68 of 68 assertions pass in
// its own test.mjs). Copied verbatim, with the ES module `export` keywords removed so a classic
// script can carry them: r/p2/dist/polyLength/dedupe, MODULE_CLASSES, ARRANGEMENTS,
// INVERTER_CLASS, INPUTS, DEFAULTS, PRESETS, stringComponent, buildBlock. Nothing in them is
// changed here; what is new is blockDrawing(), which turns that library's output into this
// engine's shape data, and nothing else.
(function (root) {
const F = root.FIRE; if (!F) return;
/* ---- copied from block.mjs: helpers ---- */
const r = (v, n = 3) => Math.round(v * 10 ** n) / 10 ** n;
const p2 = (n) => String(n).padStart(2, '0');
const dist = (a, b) => Math.hypot(b[0] - a[0], b[1] - a[1]);
function polyLength(pts) { let L = 0; for (let i = 1; i < pts.length; i++) L += dist(pts[i - 1], pts[i]); return L; }
function dedupe(pts) { const out = [];
for (const q of pts) { const last = out[out.length - 1];
if (!last || Math.abs(last[0] - q[0]) > 1e-9 || Math.abs(last[1] - q[1]) > 1e-9) out.push(q); }
return out; }
/* ---- copied from block.mjs: module classes ---- */
const MODULE_CLASSES = {
C495: { id:'C495', label:'495 W class bifacial module, 166 mm half-cell, 144 cells', wp:495,
Voc_V:45.9, Vmp_V:38.1, Imp_A:12.98, Isc_A:13.65, beta_Voc_pct_per_K:-0.25, gamma_Vmp_pct_per_K:-0.34,
alpha_Isc_pct_per_K:0.045, Ir_A:20, width_m:1.038, length_m:2.094, bifaciality:0.7 },
C660: { id:'C660', label:'660 W class bifacial module, 210 mm half-cell, 132 cells', wp:660,
Voc_V:45.3, Vmp_V:38.0, Imp_A:17.37, Isc_A:18.4, beta_Voc_pct_per_K:-0.25, gamma_Vmp_pct_per_K:-0.34,
alpha_Isc_pct_per_K:0.045, Ir_A:30, width_m:1.303, length_m:2.384, bifaciality:0.8 },
};
/* ---- copied from block.mjs: inverter DC arrangements ---- */
const ARRANGEMENTS = {
'12x2': { id:'12x2', label:'12 trackers x 2 inputs = 24 strings', trackers:12, inputs_per_tracker:2,
inputs:24, A_per_tracker:40, A_per_input:30, Isc_per_tracker_A:60, strings_in_parallel_per_tracker:2,
fuse_words:'At two strings in parallel on one tracker the worst-case fault current into a faulted ' +
'string is (2-1) x 1.25 x Isc, which sits below the module reverse-current rating. ' +
'STRING FUSES ARE NOT REQUIRED in this arrangement - but only on the parallel-string ' +
'term. The inverter backfeed contribution is not published anywhere, so the verdict is ' +
'conditional and the check is returned twice: once with the inputs blocking reverse ' +
'current and once without.' },
'6x5': { id:'6x5', label:'6 trackers x 5 inputs = 30 strings', trackers:6, inputs_per_tracker:5,
inputs:30, A_per_tracker:75, A_per_input:30, Isc_per_tracker_A:125, strings_in_parallel_per_tracker:5,
fuse_words:'STRING FUSES ARE REQUIRED in this arrangement. Five strings in parallel on one tracker ' +
'drive (5-1) x 1.25 x Isc into a faulted string - about 68 A on the default class - which ' +
'is far above any module reverse-current rating. Every string needs its own fuse, or a ' +
'fused combiner, before the tracker.' },
};
/* ---- copied from block.mjs: the inverter class ---- */
const INVERTER_CLASS = { id:'INV352', label:'352 kVA class 1500 V string inverter', S_kVA_at_30C:352,
S_kVA_at_40C:320, S_kVA_at_50C:295, max_pv_input_voltage_V:1500, mppt_min_V:500, mppt_max_V:1500,
startup_V:550, width_m:1.136, depth_m:0.361 };
/* ---- copied from block.mjs: every declared input ---- */
const INPUTS = [
{ key:'block_id', label:'block id', kind:'text', default:'B1' },
{ key:'module_class', label:'module class', kind:'choice', choices:['C495', 'C660'], default:'C495' },
{ key:'strings_per_inverter', label:'strings per inverter', unit:'strings', kind:'int', min:1, max:30, step:1, default:24 },
{ key:'modules_per_string', label:'modules per string', unit:'modules', kind:'int', min:1, max:40, step:1, default:30 },
{ key:'arrangement', label:'inverter DC arrangement', kind:'choice', choices:['12x2', '6x5', 'auto'], default:'auto' },
{ key:'table_format', label:'table format', kind:'choice', choices:['1-string-2-tier', '1-string-1-tier', '2-string-2-tier'], default:'1-string-2-tier' },
{ key:'tables_per_row', label:'tables per row', unit:'tables', kind:'int', min:1, max:12, step:1, default:4 },
{ key:'row_pitch_m', label:'row pitch', unit:'m', kind:'number', min:3, max:20, step:0.1, default:9.0 },
{ key:'table_gap_m', label:'gap between tables in a row', unit:'m', kind:'number', min:0, max:10, step:0.1, default:1.0 },
{ key:'module_gap_m', label:'gap between modules', unit:'m', kind:'number', min:0, max:0.2, step:0.005, default:0.02 },
{ key:'tier_gap_m', label:'gap between tiers', unit:'m', kind:'number', min:0, max:0.5, step:0.005, default:0.02 },
{ key:'inverter_position', label:'inverter position', kind:'choice', choices:['west-centre', 'east-centre', 'south-centre', 'north-centre', 'west-quarter', 'typed'], default:'west-centre' },
{ key:'inverter_xy', label:'inverter x,y when typed', unit:'m', kind:'pair', default:null },
{ key:'inverter_standoff_m', label:'inverter standoff from the block', unit:'m', kind:'number', min:1, max:60, step:0.5, default:6.0 },
{ key:'corridor_offset_m', label:'gathering corridor offset from the row ends', unit:'m', kind:'number', min:0.5, max:20, step:0.5, default:3.0 },
{ key:'corridor_lane_pitch_m', label:'lane pitch in the gathering corridor', unit:'m', kind:'number', min:0, max:1, step:0.01, default:0.12 },
{ key:'pairing', label:'string pairing on a tracker', kind:'choice', choices:['long-short', 'sequential'], default:'long-short' },
{ key:'home_separation_m', label:'separation of the two home-run conductors', unit:'m', kind:'number', min:0, max:1, step:0.01, default:0.1 },
{ key:'ambient_min_C', label:'lowest expected ambient', unit:'C', kind:'number', min:-40, max:20, step:0.5, default:-10 },
{ key:'cold_allowance_K', label:'allowance added to the lowest ambient for the cold design temperature', unit:'K', kind:'number', min:0, max:20, step:1, default:10 },
{ key:'hot_cell_C', label:'hot design cell temperature', unit:'C', kind:'number', min:40, max:90, step:1, default:70 },
{ key:'bifacial_factor', label:'bifacial current factor on Isc', kind:'number', min:1, max:1.3, step:0.01, default:1.1 },
{ key:'design_current_factor', label:'design current factor on Isc', kind:'number', min:1, max:1.5, step:0.05, default:1.25 },
{ key:'module_max_series_fuse_A', label:'module maximum series fuse rating', unit:'A', kind:'number', min:5, max:40, step:1, default:30 },
{ key:'inputs_block_reverse_current', label:'inverter inputs confirmed to block reverse current', kind:'choice', choices:['yes','unconfirmed'], default:'unconfirmed' },
];
const DEFAULTS = Object.fromEntries(INPUTS.map((i) => [i.key, i.default]));
/* ---- copied from block.mjs: the single-string component ---- */
function stringComponent(cfg) {
const { modules_per_string, tiers, cols, mod, module_gap_m, tier_gap_m } = cfg;
const pitchX = mod.width_m + module_gap_m;
const pitchY = mod.length_m + tier_gap_m;
const modules = [];
for (let j = 0; j < modules_per_string; j++) {
const tier = tiers === 1 ? 0 : Math.floor(j / cols);
const within = j - tier * cols;
const col = tier % 2 === 0 ? within : cols - 1 - within;
const x = col * pitchX;
const y = tier * pitchY;
modules.push({ j, tier, col,
rect: [r(x), r(y), r(mod.width_m), r(mod.length_m)],
box: { minus: [r(x + mod.width_m * 0.35), r(y + mod.length_m * 0.5)],
plus: [r(x + mod.width_m * 0.65), r(y + mod.length_m * 0.5)] } });
}
const links = [];
for (let j = 0; j < modules_per_string - 1; j++) links.push({ j, from: modules[j].box.plus, to: modules[j + 1].box.minus });
return { modules, links, start: modules[0].box.minus, end: modules[modules_per_string - 1].box.plus,
width_m: r((cols - 1) * pitchX + mod.width_m), depth_m: r((tiers - 1) * pitchY + mod.length_m) };
}
/* ---- copied from block.mjs: the build ---- */
function buildBlock(typed = {}) {
const typedKeys = new Set(Object.keys(typed).filter((k) => typed[k] !== undefined && typed[k] !== null));
const I = { ...DEFAULTS, ...Object.fromEntries([...typedKeys].map((k) => [k, typed[k]])) };
const st = (...keys) => (keys.every((k) => typedKeys.has(k)) ? 'TYPED' : 'ASSUMED');
const B = I.block_id;
const mod = MODULE_CLASSES[I.module_class];
if (!mod) throw new Error(`unknown module class ${I.module_class}`);
const N = I.strings_per_inverter;
const M = I.modules_per_string;
const arrKey = I.arrangement === 'auto' ? (N <= 24 ? '12x2' : '6x5') : I.arrangement;
const arr = ARRANGEMENTS[arrKey];
if (!arr) throw new Error(`unknown arrangement ${arrKey}`);
if (N > arr.inputs) throw new Error(`${N} strings will not fit ${arr.label}`);
const fmt = I.table_format;
const stringsPerTable = fmt === '2-string-2-tier' ? 2 : 1;
const tiers = fmt === '1-string-1-tier' ? 1 : 2;
const colsPerString = fmt === '1-string-2-tier' ? Math.ceil(M / 2) : M;
const tiersPerString = fmt === '1-string-2-tier' ? 2 : 1;
const comp = stringComponent({ modules_per_string: M, tiers: tiersPerString, cols: colsPerString,
mod, module_gap_m: I.module_gap_m, tier_gap_m: I.tier_gap_m });
const pitchY = mod.length_m + I.tier_gap_m;
const tableWidth = comp.width_m;
const tableDepth = (tiers - 1) * pitchY + mod.length_m;
const nTables = Math.ceil(N / stringsPerTable);
const tablesPerRow = Math.min(I.tables_per_row, nTables);
const nRows = Math.ceil(nTables / tablesPerRow);
const rowPitch = Math.max(I.row_pitch_m, tableDepth + 0.5);
const strings = [];
for (let i = 0; i < N; i++) {
const t = Math.floor(i / stringsPerTable);
const slotInTable = i % stringsPerTable;
const row = Math.floor(t / tablesPerRow);
const col = t % tablesPerRow;
const ox = col * (tableWidth + I.table_gap_m);
const oy = row * rowPitch + (stringsPerTable === 2 ? slotInTable * pitchY : 0);
strings.push({ i, table: t, row, col, ox, oy, tierBase: stringsPerTable === 2 ? slotInTable : 0 });
}
const blockX0 = 0;
const blockX1 = tablesPerRow * tableWidth + (tablesPerRow - 1) * I.table_gap_m;
const blockY0 = 0;
const blockY1 = (nRows - 1) * rowPitch + tableDepth;
const midX = (blockX0 + blockX1) / 2;
const midY = (blockY0 + blockY1) / 2;
const so = I.inverter_standoff_m;
let inv;
switch (I.inverter_position) {
case 'east-centre': inv = [blockX1 + so, midY]; break;
case 'south-centre': inv = [midX, blockY0 - so]; break;
case 'north-centre': inv = [midX, blockY1 + so]; break;
case 'west-quarter': inv = [blockX0 - so, blockY0 + (blockY1 - blockY0) * 0.25]; break;
case 'typed': inv = I.inverter_xy ? [I.inverter_xy[0], I.inverter_xy[1]] : [blockX0 - so, midY]; break;
default: inv = [blockX0 - so, midY];
}
const [invX, invY] = inv;
const corridorX = invX <= midX ? blockX0 - I.corridor_offset_m : blockX1 + I.corridor_offset_m;
const invW = INVERTER_CLASS.width_m;
const invD = INVERTER_CLASS.depth_m;
const faceY = invY - invD / 2;
const nInputs = arr.inputs;
const trackers = [];
const inputsById = new Map();
for (let t = 0; t < arr.trackers; t++) {
const tr = { id: `${B}.INV.T${p2(t + 1)}`, t, inputs: [] };
for (let a = 0; a < arr.inputs_per_tracker; a++) {
const idx = a * arr.trackers + t;
const x = invX - invW / 2 + ((idx + 1) * invW) / (nInputs + 1);
const id = `${tr.id}.in${a + 1}`;
const input = { id, tracker: t, a, order: idx,
terminals: { plus: { id: `${id}+`, xy: [r(x + 0.012), r(faceY)] },
minus: { id: `${id}-`, xy: [r(x - 0.012), r(faceY)] } },
used_by: null, lod: 'box' };
tr.inputs.push(input);
inputsById.set(id, input);
}
trackers.push(tr);
}
const slots = [];
for (let a = 0; a < arr.inputs_per_tracker; a++) for (let t = 0; t < arr.trackers; t++) slots.push(trackers[t].inputs[a]);
const provisional = (s) => { const bx = s.ox + comp.start[0], by = s.oy + comp.start[1];
return Math.abs(corridorX - bx) + Math.abs(invY - by) + Math.abs(invX - corridorX); };
for (const s of strings) s.prov = provisional(s);
const order = [...strings];
if (I.pairing === 'long-short') order.sort((a, b) => b.prov - a.prov || a.i - b.i);
let lo = 0, hi = order.length - 1;
const taken = [];
for (let k = 0; k < slots.length && lo <= hi; k++) {
const a = slots[k].a;
const s = I.pairing === 'long-short' && a % 2 === 1 ? order[hi--] : order[lo++];
taken.push([slots[k], s]);
}
for (const [slot, s] of taken) { slot.used_by = `${B}.S${p2(s.i + 1)}`; s.input = slot; }
const modules = [];
const conductors = [];
const outStrings = [];
for (const s of strings) {
const sid = `${B}.S${p2(s.i + 1)}`;
const sMods = comp.modules.map((m) => {
const mid = `${sid}.M${p2(m.j + 1)}`;
const rec = { id: mid, string: s.i, j: m.j, tier: m.tier + s.tierBase, col: m.col,
rect: [r(s.ox + m.rect[0]), r(s.oy + m.rect[1]), m.rect[2], m.rect[3]],
box: { id: `${mid}.box`,
plus: { id: `${mid}.box+`, xy: [r(s.ox + m.box.plus[0]), r(s.oy + m.box.plus[1])] },
minus: { id: `${mid}.box-`, xy: [r(s.ox + m.box.minus[0]), r(s.oy + m.box.minus[1])] } },
alias: `block.string[${s.i}].module[${m.j}]`, lod: 'module' };
modules.push(rec); return rec; });
for (const l of comp.links) {
const from = sMods[l.j].box.plus, to = sMods[l.j + 1].box.minus;
const pts = dedupe([from.xy, to.xy]);
conductors.push({ id: `${sid}.L${p2(l.j + 1)}`, kind: 'link', string: s.i, from: from.id, to: to.id,
polyline: pts, length_m: r(polyLength(pts)), reach: r(dist(from.xy, to.xy)),
alias: `block.string[${s.i}].link[${l.j}]`, lod: 'string' });
}
const laneSign = corridorX <= midX ? -1 : +1;
const laneX = corridorX + laneSign * s.input.order * I.corridor_lane_pitch_m;
const sep = I.home_separation_m / 2;
const ends = [
{ pole: 'plus', sign: '+', box: sMods[M - 1].box.plus, term: s.input.terminals.plus, off: +sep },
{ pole: 'minus', sign: '-', box: sMods[0].box.minus, term: s.input.terminals.minus, off: -sep },
];
const homeRuns = [];
for (const e of ends) {
const [bx, by] = e.box.xy, [tx, ty] = e.term.xy, gx = laneX + e.off;
const pts = dedupe([[bx, by], [r(gx), by], [r(gx), r(ty)], [tx, ty]]);
const hr = { id: `${sid}.HR${e.sign}`, kind: 'home_run', pole: e.pole, string: s.i,
from: e.box.id, to: e.term.id, input: s.input.id, tracker: s.input.tracker,
polyline: pts, length_m: r(polyLength(pts)), reach: r(dist([bx, by], [tx, ty])),
alias: `block.string[${s.i}].home.${e.pole}`, lod: 'block' };
conductors.push(hr); homeRuns.push(hr);
}
outStrings.push({ id: sid, index: s.i, alias: `block.string[${s.i}]`,
placement: { table: s.table, row: s.row, col: s.col, tier_base: s.tierBase, tiers: tiersPerString,
cols: colsPerString, origin: [r(s.ox), r(s.oy)],
outline: [r(s.ox), r(s.oy), comp.width_m, r(comp.depth_m)] },
tracker: s.input.tracker, input: s.input.id, modules: sMods.map((m) => m.id),
home_runs: homeRuns.map((h) => h.id),
home_run_length_m: r(homeRuns[0].length_m + homeRuns[1].length_m), lod: 'string' });
}
const T_cold = I.ambient_min_C + I.cold_allowance_K;
const T_hot = I.hot_cell_C;
const bVoc = mod.beta_Voc_pct_per_K / 100;
const gVmp = mod.gamma_Vmp_pct_per_K / 100;
const Voc_stc = M * mod.Voc_V;
const Voc_cold = M * mod.Voc_V * (1 + bVoc * (T_cold - 25));
const Vmp_stc = M * mod.Vmp_V;
const Vmp_hot = M * mod.Vmp_V * (1 + gVmp * (T_hot - 25));
const Imp = mod.Imp_A, Isc = mod.Isc_A;
const I_design = I.design_current_factor * I.bifacial_factor * Isc;
const P_string = M * mod.Vmp_V * mod.Imp_A;
const P_block = N * P_string;
const perTracker = new Map();
for (let t = 0; t < arr.trackers; t++) perTracker.set(t, 0);
for (const s of outStrings) perTracker.set(s.tracker, perTracker.get(s.tracker) + 1);
const maxStringsOnATracker = Math.max(...perTracker.values());
const minStringsOnATracker = Math.min(...perTracker.values());
const I_tracker = maxStringsOnATracker * I_design;
const Isc_tracker = maxStringsOnATracker * I.bifacial_factor * Isc;
/* Fuses rest on the strings ACTUALLY paralleled on the fullest tracker, never on the
nominal strings-in-parallel of the arrangement. */
const Np = maxStringsOnATracker;
const Np_nominal = arr.strings_in_parallel_per_tracker;
const fuseRating = I.module_max_series_fuse_A;
const faultNoBackfeed = (Np - 1) * I.design_current_factor * Isc;
const countRuleFires = Np >= 3;
const currentRuleFires = faultNoBackfeed > fuseRating;
const fusesRequired = countRuleFires || currentRuleFires;
const fuseRuleFired = countRuleFires ? (currentRuleFires ? 'count and current' : 'count') : (currentRuleFires ? 'current' : 'none');
const backfeedUnconfirmed = I.inputs_block_reverse_current !== 'yes';
const faultTerm = `(${Np} - 1) x ${I.design_current_factor} x Isc = ${r(faultNoBackfeed, 2)} A`;
const askMaker = backfeedUnconfirmed
? ' The inverter inputs are NOT confirmed to block reverse current, so the backfeed contribution to a faulted string is unknown and no maker publishes it: ASK THE INVERTER MAKER. That term is separate from the parallel-string term above and can only make the case for fuses stronger, never weaker.'
: ' The inverter inputs are declared to block reverse current, so the parallel-string term above is the whole of the fault current.';
const fuseWords = (countRuleFires
? `STRING FUSES ARE REQUIRED. ${Np} strings sit in parallel on the fullest tracker and the COUNT rule fires at three or more: the healthy strings can drive ${faultTerm} into a faulted one, against a ${fuseRating} A module maximum series fuse rating. Every string needs its own fuse, or a fused combiner, ahead of the tracker.` + (currentRuleFires ? ' The CURRENT rule fires on the same block.' … [line shortened here: 405 characters; full line on GitHub]
: currentRuleFires
? `STRING FUSES ARE NOT REQUIRED by the count rule - only ${Np} strings are paralleled on the fullest tracker - but the CURRENT rule fires: ${faultTerm} is above the ${fuseRating} A module maximum series fuse rating, so fuses are needed on that term.`
: `STRING FUSES ARE NOT REQUIRED on the parallel-string term. ${Np} strings are paralleled on the fullest tracker, so the count rule (three or more) does not fire, and ${faultTerm} stays at or below the ${fuseRating} A module maximum series fuse rating, so the current rule does not fire either.`)
+ (Np === Np_nominal ? '' : ` The ${arr.label} arrangement would nominally hold ${Np_nominal} strings on a tracker; this block only fills ${Np}, and the verdict follows the actual count.`)
+ askMaker;
const otherKey = arrKey === '12x2' ? '6x5' : '12x2';
const otherArr = ARRANGEMENTS[otherKey];
const faultOther = (otherArr.strings_in_parallel_per_tracker - 1) * I.design_current_factor * Isc;
const kWp = P_block / 1000;
const insulation = { clause: 'IEC 62446-1:2016, 6.7.2 and Table 3', value_Mohm: 1, test_V: 500 };
const V = [];
const push = (label, value, unit, limit, verdict, status, note) =>
V.push({ label, value: typeof value === 'number' ? r(value, 2) : value, unit, limit, verdict, status, note });
push('string Voc at STC', Voc_stc, 'V', INVERTER_CLASS.max_pv_input_voltage_V,
Voc_stc <= 1500 ? 'pass' : 'fail', st('modules_per_string', 'module_class'), `${M} x ${mod.Voc_V} V`);
push(`string Voc at the cold design temperature (${r(T_cold, 1)} C)`, Voc_cold, 'V',
INVERTER_CLASS.max_pv_input_voltage_V, Voc_cold <= 1500 ? 'pass' : 'fail',
st('ambient_min_C', 'cold_allowance_K', 'modules_per_string'),
`lowest ambient ${I.ambient_min_C} C plus a ${I.cold_allowance_K} K allowance; beta_Voc ${mod.beta_Voc_pct_per_K} %/K`);
push('margin to the 1500 V limit at the cold design temperature', 1500 - Voc_cold, 'V', 0,
1500 - Voc_cold >= 0 ? 'pass' : 'fail', st('ambient_min_C', 'cold_allowance_K'), null);
push('string Vmp at STC', Vmp_stc, 'V', `${INVERTER_CLASS.mppt_min_V}-${INVERTER_CLASS.mppt_max_V}`,
Vmp_stc >= 500 && Vmp_stc <= 1500 ? 'pass' : 'fail', st('modules_per_string', 'module_class'), null);
push(`string Vmp at the hot design cell temperature (${T_hot} C)`, Vmp_hot, 'V',
INVERTER_CLASS.mppt_min_V, Vmp_hot >= INVERTER_CLASS.mppt_min_V ? 'pass' : 'fail',
st('hot_cell_C', 'modules_per_string'), 'against the MPPT minimum');
push('string Imp at STC', Imp, 'A', null, null, st('module_class'), null);
push('string Isc at STC', Isc, 'A', null, null, st('module_class'), null);
push('string design current, factor x bifacial factor x Isc', I_design, 'A', null, null,
st('design_current_factor', 'bifacial_factor', 'module_class'),
`${I.design_current_factor} x ${I.bifacial_factor} x ${Isc} A`);
push('current into each inverter input', I_design, 'A', arr.A_per_input,
I_design <= arr.A_per_input ? 'pass' : 'fail', st('design_current_factor', 'bifacial_factor'), 'one string per input');
push('current into each tracker', I_tracker, 'A', arr.A_per_tracker,
I_tracker <= arr.A_per_tracker ? 'pass' : 'fail', st('design_current_factor', 'bifacial_factor'),
`${maxStringsOnATracker} strings on the fullest tracker`);
push('Isc into each tracker', Isc_tracker, 'A', arr.Isc_per_tracker_A,
Isc_tracker <= arr.Isc_per_tracker_A ? 'pass' : 'fail', st('bifacial_factor'), null);
push('DC power per string at STC', P_string / 1000, 'kW', null, null, st('module_class', 'modules_per_string'), null);
push('DC power of the block at STC', kWp, 'kW', null, null,
st('module_class', 'modules_per_string', 'strings_per_inverter'),
`${N} strings x ${M} modules x ${r(mod.Vmp_V * mod.Imp_A, 3)} W`);
push('DC/AC ratio against 352 kVA at 30 C', kWp / INVERTER_CLASS.S_kVA_at_30C, 'ratio', null, null,
st('module_class', 'strings_per_inverter'), null);
push('DC/AC ratio against 320 kVA at 40 C', kWp / INVERTER_CLASS.S_kVA_at_40C, 'ratio', null, null,
st('module_class', 'strings_per_inverter'), null);
push('DC/AC ratio against 295 kVA at 50 C', kWp / INVERTER_CLASS.S_kVA_at_50C, 'ratio', null, null,
st('module_class', 'strings_per_inverter'), null);
push('strings in parallel on the fullest tracker', Np, 'strings', Np_nominal, null,
st('strings_per_inverter', 'arrangement'),
`actual count on this block; the ${arr.label} arrangement would nominally hold ${Np_nominal}`);
push('fault current into one string, inputs DO block reverse current', faultNoBackfeed, 'A', fuseRating,
faultNoBackfeed <= fuseRating ? 'pass' : 'fail', st('module_max_series_fuse_A', 'design_current_factor'),
`(${Np} - 1) x ${I.design_current_factor} x Isc against the ${fuseRating} A module maximum series fuse rating; rule fired: ${fuseRuleFired}`);
push('fault current into one string, inputs do NOT block reverse current', faultNoBackfeed, 'A', fuseRating,
backfeedUnconfirmed ? null : (faultNoBackfeed <= fuseRating ? 'pass' : 'fail'),
st('inputs_block_reverse_current'),
backfeedUnconfirmed
? 'the inverter backfeed contribution must be added and no maker publishes it, so the verdict is null by rule rather than invented: ASK THE INVERTER MAKER.'
: 'the inputs are declared to block reverse current, so this equals the term above.');
push(`the same check in the ${otherArr.label} world`, faultOther, 'A', mod.Ir_A,
faultOther <= mod.Ir_A ? 'pass' : 'fail', 'ASSUMED', otherArr.fuse_words);
push('insulation resistance threshold for this block', insulation.value_Mohm, 'Mohm', insulation.value_Mohm,
null, 'ASSUMED',
`${insulation.clause}: system voltage above 500 V, test at ${insulation.test_V} V d.c. ` +
`Block is ${r(kWp, 2)} kWp; the clause is measured per string or sub-array, not across the block.`);
const hrs = conductors.filter((c) => c.kind === 'home_run');
const hrLen = hrs.map((h) => h.length_m);
push('total home-run conductor', hrLen.reduce((a, b) => a + b, 0), 'm', null, null, st('inverter_position'), null);
push('longest home run', Math.max(...hrLen), 'm', null, null, st('inverter_position'), null);
push('shortest home run', Math.min(...hrLen), 'm', null, null, st('inverter_position'), null);
return {