GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Solar and storage design / solar-electrical-topology-analysis-engine-text-based / v8-leapfrog

Solar Electrical Topology Analysis Engine Text Based — V8 Leapfrog

A JavaScript file that reads inputs (`readInputs`), sets input (`setInputValues`) and groups bands (`groupBands`) (units: Ω, kW), covering leapfrog cable comparison and cables. Served with the page at https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v8-leapfrog/.

700 lines of JavaScript from solar-electrical-topology-analysis-engine-text-based, in 1 file. Topic: Solar and storage design. Section 249 of 2044.

Cut 2026-12-06T03:07:51+00:00. A copy for reading; the repository at the stated commit is the source.

In the State lines below, domain stage, users and canonical status are rule-based first approximations from code and path evidence (rules explore-agent-rules-v1), not observed facts: the rules.

In this section

  1. Solar Electrical Topology Analysis Engine Text Based — V8 Leapfrog electrical · solar-electrical-topology-analysis-engine-text-based / v8-leapfrog/app.js lines 446–1145

Solar Electrical Topology Analysis Engine Text Based — V8 Leapfrog

A JavaScript file that reads inputs (`readInputs`), sets input (`setInputValues`) and groups bands (`groupBands`) (units: Ω, kW), covering leapfrog cable comparison and cables. Served with the page at https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v8-leapfrog/.

electricalsolar-electrical-topology-analysis-engine-text-based / v8-leapfrog/app.js · lines 446–1145 of 1260 (continued from section 248) · Entry point · pattern clearError (shared by 2 files)

What it does
It draws leapfrog cable comparison and cables. Defines 40 functions or classes, including $, fmt, available, setText, readInputs. Side effects: changes the web page (DOM).
Why it exists in the grid workflow
Domain stage sub33kv_design (repository name word 'solar'): 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.
Inputs & outputs
Out: JSON file v8-leapfrog-cable-comparison.json; downloaded file v8-leapfrog-cable-comparison.json.
Downstream impact
Used directly by 2 files: Solar Electrical Topology Analysis Engine Text Based — V8 Leapfrog Page (solar-electrical-topology-analysis-engine-text-based, https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v8-leapfrog/); V8 Tests Workflow (solar-electrical-topology-analysis-engine-text-based). Reached from 127 other entry points, including GlobalGrid2050 Historical Builds (globalgrid2050, https://globalgrid2050.com/historical_builds.html); GlobalGrid2050 Homepage Before Four Nests (globalgrid2050, https://globalgrid2050.com/homepage-before-four-nests-20260925.html); Homepage V002 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v002.html). It is itself an entry point, published at https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v8-leapfrog/.
What it achieves
It sets text (`setText`), reads inputs (`readInputs`) and sets input (`setInputValues`). Defines `fmt`, `available`, `setText` and 36 more. It responds to click, input and change events.
Why it matters
Loaded by the page of the same name at https://ventusltd.github.io/solar-electrical-topology-analysis-engine-text-based/v8-leapfrog/. Checked by V8 Tests Workflow.
Application
solar-electrical-topology-analysis-engine-text-based · v8-leapfrog · script
Uses
none found
Used by
loaded by Solar Electrical Topology Analysis Engine Text Based — V8 Leapfrog Page (script src), run by V8 Tests Workflow (workflow run)
Produces
$, fmt, available, setText, readInputs, setInputValues, groupBands, renderFeasibilityBanner, renderMetrics, renderLeadScreen, renderBandSchedule, renderStringSchedule
Defines here
svgPath, cablePath, svgText, buildSequentialSequence, buildLeapfrogSequence, sequenceConnections, moduleGeometry, terminalPoint, moduleRowHtml, connectionArc, externalCable, drawInverter, renderSequentialGeometry, renderLeapfrogGeometry, renderDiagram, renderTrace, renderSummary, renderComparison, geometrySelfTests, renderSelfTests, showError, clearError, render
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
solar-electrical-topology-analysis-engine-text-based@d3b4c497144c2c9b3e8f0e82117e7e9abe4672b9 v8-leapfrog/app.js:446-1145 · blob 7c796bc6748cf14500cc7786248eabdb53db4f0f · GitHub at these lines
State
achieves: name · context: readme_derived · stage: output · effects: dom · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
              1
            )}
          </td>
          <td class="warning-cell">
            ${fmt(
              scenario.theoreticalSavingMPerArchetypeInverter,
              1
            )}
          </td>
          <td class="good-cell">
            ${available(
              scenario.availableSavingMPerArchetypeInverter,
              '',
              1
            )}
          </td>
          <td class="good-cell">
            ${available(scenario.availableSiteSavingKm, '', 1)}
          </td>
          <td class="good-cell">
            ${available(
              scenario.availablePowerLossSavingKWPerArchetypeInverter,
              '',
              3
            )}
          </td>
        </tr>
      `)
      .join('');
  }

  function svgPath(path, className, width, extra = '') {
    return (
      `<path d="${path}" class="${className}" ` +
      `stroke-width="${width}" ${extra}/>`
    );
  }

  function cablePath(path, width = 3, extra = '') {
    return (
      svgPath(path, 'svg-cable-halo', width + 3, extra) +
      svgPath(path, 'svg-cable', width, extra)
    );
  }

  function svgText(x, y, text, className = 'svg-label', size = 12) {
    return (
      `<text x="${x}" y="${y}" class="${className}" ` +
      `font-size="${size}">${text}</text>`
    );
  }

  function buildSequentialSequence(count) {
    return Array.from({ length: count }, (_, index) => index + 1);
  }

  function buildLeapfrogSequence(count) {
    if (count <= 1) {
      return [1];
    }

    const outward = [];
    const returning = [];

    for (let module = 1; module <= count; module += 2) {
      outward.push(module);
    }

    let returnStart = count % 2 === 0 ? count : count - 1;

    for (; returnStart >= 2; returnStart -= 2) {
      returning.push(returnStart);
    }

    return outward.concat(returning);
  }

  function sequenceConnections(sequence) {
    return sequence.slice(0, -1).map((from, index) => ({
      from,
      to: sequence[index + 1]
    }));
  }

  function moduleGeometry(count, x0, y, moduleWidth, moduleHeight, gap) {
    const modules = new Map();

    for (let number = 1; number <= count; number += 1) {
      const x = x0 + (number - 1) * (moduleWidth + gap);
      const centreX = x + moduleWidth / 2;
      const terminalY = y + 30;

      modules.set(number, {
        number,
        x,
        y,
        centreX,
        terminalY,
        negativeX: centreX - 11,
        positiveX: centreX + 11
      });
    }

    return modules;
  }

  function terminalPoint(modules, moduleNumber, polarity) {
    const module = modules.get(moduleNumber);

    return {
      x: polarity === '+' ? module.positiveX : module.negativeX,
      y: module.terminalY
    };
  }

  function moduleRowHtml(modules, moduleWidth, moduleHeight) {
    let html = '';

    modules.forEach((module) => {
      html += `
        <g data-module="M${module.number}">
          <rect
            x="${module.x}"
            y="${module.y}"
            width="${moduleWidth}"
            height="${moduleHeight}"
            rx="2"
            class="svg-module-east"
          />
          <rect
            x="${module.negativeX - 7}"
            y="${module.terminalY - 7}"
            width="14"
            height="14"
            rx="2"
            fill="#0a0e12"
            stroke="#eef7ff"
            stroke-width="1"
          />
          <rect
            x="${module.positiveX - 7}"
            y="${module.terminalY - 7}"
            width="14"
            height="14"
            rx="2"
            fill="#0a0e12"
            stroke="#eef7ff"
            stroke-width="1"
          />
          <text
            x="${module.negativeX}"
            y="${module.terminalY + 4}"
            text-anchor="middle"
            class="svg-label"
            font-size="11"
          >−</text>
          <text
            x="${module.positiveX}"
            y="${module.terminalY + 4}"
            text-anchor="middle"
            class="svg-label"
            font-size="11"
          >+</text>
          <text
            x="${module.centreX}"
            y="${module.y + moduleHeight + 18}"
            text-anchor="middle"
            class="svg-label"
            font-size="12"
          >M${module.number}</text>
        </g>
      `;
    });

    return html;
  }

  function connectionArc(modules, connection, rowY, side, index) {
    const start = terminalPoint(modules, connection.from, '+');
    const end = terminalPoint(modules, connection.to, '−');
    const distance = Math.abs(end.x - start.x);
    const direction = side === 'above' ? -1 : 1;
    const lane = Math.min(42, 22 + distance * 0.12 + (index % 2) * 3);
    const controlY = rowY + 30 + direction * lane;
    const path =
      `M ${start.x} ${start.y} ` +
      `C ${start.x} ${controlY}, ${end.x} ${controlY}, ` +
      `${end.x} ${end.y}`;

    return cablePath(path, 2.4);
  }

  function externalCable(start, endX, endY, laneY) {
    const path =
      `M ${start.x} ${start.y} ` +
      `L ${start.x} ${laneY} ` +
      `L ${endX} ${laneY} ` +
      `L ${endX} ${endY}`;

    return cablePath(path, 4);
  }

  function drawInverter(x, y, height, negativeY, positiveY) {
    return `
      <rect
        x="${x}"
        y="${y}"
        width="74"
        height="${height}"
        rx="4"
        class="svg-inverter"
      />
      ${svgText(x + 8, y + 22, 'INVERTER', 'svg-label', 13)}
      <circle
        cx="${x + 74}"
        cy="${negativeY}"
        r="5"
        fill="#05070a"
        stroke="#eef7ff"
        stroke-width="2"
      />
      <circle
        cx="${x + 74}"
        cy="${positiveY}"
        r="5"
        fill="#05070a"
        stroke="#eef7ff"
        stroke-width="2"
      />
      ${svgText(x + 48, negativeY + 4, '−', 'svg-label', 14)}
      ${svgText(x + 48, positiveY + 4, '+', 'svg-label', 14)}
    `;
  }

  function renderSequentialGeometry(options) {
    const {
      count,
      modules,
      rowY,
      inverterX,
      inverterY,
      moduleWidth,
      moduleHeight,
      study
    } = options;
    const sequence = buildSequentialSequence(count);
    const connections = sequenceConnections(sequence);
    const freeNegative = terminalPoint(modules, sequence[0], '−');
    const freePositive = terminalPoint(
      modules,
      sequence[sequence.length - 1],
      '+'
    );
    const inverterNegativeY = rowY + 18;
    const inverterPositiveY = rowY + 58;
    const returnLaneY = rowY + moduleHeight + 48;
    let html = '';

    html += drawInverter(
      inverterX,
      inverterY,
      126,
      inverterNegativeY,
      inverterPositiveY
    );
    html += moduleRowHtml(modules, moduleWidth, moduleHeight);

    connections.forEach((connection, index) => {
      html += connectionArc(modules, connection, rowY, 'above', index);
    });

    html += externalCable(
      freeNegative,
      inverterX + 74,
      inverterNegativeY,
      rowY + 4
    );
    html += externalCable(
      freePositive,
      inverterX + 74,
      inverterPositiveY,
      returnLaneY
    );
    html += svgText(
      freeNegative.x - 16,
      freeNegative.y - 16,
      'FREE − M1−',
      'svg-label',
      12
    );
    html += svgText(
      freePositive.x - 30,
      returnLaneY - 8,
      `FREE + M${count}+`,
      'svg-label',
      12
    );
    html += svgText(
      modules.get(1).x,
      rowY + moduleHeight + 82,
      `Additional far-end return ≈ ${fmt(study.geometry.rowSpanM, 2)} m`,
      'svg-label',
      14
    );

    return html;
  }

  function renderLeapfrogGeometry(options) {
    const {
      count,
      modules,
      rowY,
      inverterX,
      inverterY,
      moduleWidth,
      moduleHeight,
      study
    } = options;
    const sequence = buildLeapfrogSequence(count);
    const connections = sequenceConnections(sequence);
    const freeNegative = terminalPoint(modules, sequence[0], '−');
    const freePositive = terminalPoint(
      modules,
      sequence[sequence.length - 1],
      '+'
    );
    const inverterNegativeY = rowY + 18;
    const inverterPositiveY = rowY + 58;
    let html = '';

    html += drawInverter(
      inverterX,
      inverterY,
      126,
      inverterNegativeY,
      inverterPositiveY
    );
    html += moduleRowHtml(modules, moduleWidth, moduleHeight);

    connections.forEach((connection, index) => {
      const isOutward = connection.from % 2 === 1 && connection.to % 2 === 1;
      const isTurnaround =
        Math.abs(connection.from - connection.to) === 1 &&
        Math.max(connection.from, connection.to) === count;
      const side = isOutward ? 'above' : 'below';

      html += connectionArc(modules, connection, rowY, side, index);

      if (isTurnaround) {
        const start = terminalPoint(modules, connection.from, '+');
        const end = terminalPoint(modules, connection.to, '−');
        const labelX = (start.x + end.x) / 2;

        html += svgText(
          labelX - 72,
          rowY - 42,
          `TURNAROUND M${connection.from}+ → M${connection.to}−`,
          'svg-label',
          12
        );
      }
    });

    html += externalCable(
      freeNegative,
      inverterX + 74,
      inverterNegativeY,
      rowY + 4
    );
    html += externalCable(
      freePositive,
      inverterX + 74,
      inverterPositiveY,
      rowY + moduleHeight + 42
    );
    html += svgText(
      freeNegative.x - 18,
      freeNegative.y - 17,
      'FREE − M1−',
      'svg-label',
      12
    );
    html += svgText(
      freePositive.x - 20,
      rowY + moduleHeight + 68,
      'FREE + M2+',
      'svg-label',
      12
    );
    html += svgText(
      modules.get(1).x,
      rowY + moduleHeight + 96,
      'Same physical M1–M30 row. Only the connection order changes.',
      'svg-label',
      14
    );
    html += svgText(
      modules.get(1).x,
      rowY + moduleHeight + 120,
      `Electrical order: ${sequence.map((item) => `M${item}`).join(' → ')}`,
      'svg-muted',
      11
    );
    html += svgText(
      modules.get(1).x,
      rowY + moduleHeight + 143,
      `Feasibility: ${study.feasibility.status} · required reach ` +
        `${fmt(study.feasibility.requiredReachM, 3)} m`,
      'svg-muted',
      12
    );

    return html;
  }

  function renderDiagram(study) {
    const svg = $('topologyDiagram');

    if (!svg) {
      return;
    }

    const count = Math.min(study.input.modulesPerString, 30);
    const moduleHeightM = 2.384;
    const scale = 42;
    const moduleWidth = study.input.moduleWidthM * scale;
    const moduleHeight = moduleHeightM * scale;
    const gap = Math.max(5, study.input.alongRowGapM * scale);
    const x0 = 180;
    const inverterX = 28;
    const sequentialY = 88;
    const leapfrogY = 445;
    const sequentialModules = moduleGeometry(
      count,
      x0,
      sequentialY,
      moduleWidth,
      moduleHeight,
      gap
    );
    const leapfrogModules = moduleGeometry(
      count,
      x0,
      leapfrogY,
      moduleWidth,
      moduleHeight,
      gap
    );
    const rowWidth =
      count * moduleWidth + Math.max(0, count - 1) * gap;
    const viewWidth = Math.max(1280, x0 + rowWidth + 90);
    const viewHeight = 760;
    let html = '';

    html += svgText(
      28,
      30,
      'PHYSICAL MODULE POSITIONS ARE IDENTICAL IN BOTH VIEWS',
      'svg-label',
      18
    );
    html += svgText(
      28,
      55,
      'M1, M2, M3 … M30 stay fixed left-to-right. The panels do not move.',
      'svg-muted',
      13
    );
    html += svgText(28, 82, 'SEQUENTIAL', 'svg-label', 18);
    html += renderSequentialGeometry({
      count,
      modules: sequentialModules,
      rowY: sequentialY,
      inverterX,
      inverterY: sequentialY - 12,
      moduleWidth,
      moduleHeight,
      study
    });
    html += svgText(28, 438, 'LEAPFROG', 'svg-label', 18);
    html += renderLeapfrogGeometry({
      count,
      modules: leapfrogModules,
      rowY: leapfrogY,
      inverterX,
      inverterY: leapfrogY - 12,
      moduleWidth,
      moduleHeight,
      study
    });

    svg.setAttribute('viewBox', `0 0 ${viewWidth} ${viewHeight}`);
    svg.setAttribute('width', String(viewWidth));
    svg.setAttribute('height', String(viewHeight));
    svg.style.width = `${viewWidth}px`;
    svg.style.minWidth = `${viewWidth}px`;
    svg.style.maxWidth = 'none';
    svg.innerHTML = html;

    window.__V8_GEOMETRY__ = {
      physicalOrder: Array.from({ length: count }, (_, index) => index + 1),
      sequentialOrder: buildSequentialSequence(count),
      leapfrogOrder: buildLeapfrogSequence(count),
      moduleWidthM: study.input.moduleWidthM,
      moduleHeightM,
      moduleGapM: study.input.alongRowGapM,
      panelsMove: false
    };
  }

  function renderTrace(study) {
    const totals = study.totals;
    const trace = [
      `MODEL VERSION = ${study.modelVersion}`,
      `FORMULA ID = ${study.formulaId}`,
      `MODULE PITCH = width + gap = ` +
        `${fmt(study.geometry.modulePitchM, 3)} m`,
      'PHYSICAL MODULE ORDER = M1, M2, M3 ... M30',
      'LEAPFROG CHANGES CONNECTION ORDER ONLY; PANELS DO NOT MOVE',
      'LEAPFROG REACH = 2 × module pitch, unless measured override',
      `REQUIRED REACH = ${fmt(study.feasibility.requiredReachM, 3)} m`,
      `AVAILABLE FACTORY LEAD = ` +
        `${fmt(study.feasibility.availableLeadReachM, 3)} m`,
      `LEAD MARGIN = ${fmt(study.feasibility.marginM, 3)} m`,
      `FEASIBILITY = ${study.feasibility.status}`,
      'ROW SPAN R = N × module width + (N − 1) × gap',
      `R = ${fmt(study.geometry.rowSpanM, 3)} m`,
      'SEQUENTIAL PER STRING = 2(D + O) + R',
      'LEAPFROG PER STRING = 2(D + O)',
      'THEORETICAL DIFFERENCE PER STRING = R',
      `ARCHETYPE STRINGS = ${totals.stringsPerArchetypeInverter}`,
      `ACTUAL SITE STRINGS = ${totals.totalSiteStringCount}`,
      `AVERAGE SITE STRINGS/INVERTER = ` +
        `${fmt(totals.averageSiteStringsPerInverter, 3)}`,
      `THEORETICAL SITE DIFFERENCE = ` +
        `${fmt(totals.theoreticalSiteSavingKm, 3)} km`,
      `AVAILABLE SITE DIFFERENCE = ` +
        `${available(totals.availableSiteSavingKm, ' km', 3)}`,
      'Fleet values use actual site strings, not 24 × inverter count.'
    ];

    setText('calculationTrace', trace.join('\n'));
  }

  function renderSummary(study) {
    const text = [
      'V8.2 sequential versus leapfrog cable comparison',
      'Physical panels remain M1 to M30 from left to right.',
      'Leapfrog changes electrical connection order only.',
      `Module pitch: ${fmt(study.geometry.modulePitchM, 3)} m`,
      `Row span: ${fmt(study.geometry.rowSpanM, 2)} m`,
      `Lead screen: ${study.feasibility.status}`,
      `Required reach: ${fmt(study.feasibility.requiredReachM, 3)} m`,
      `Available lead: ` +
        `${fmt(study.feasibility.availableLeadReachM, 3)} m`,
      `Archetype strings/inverter: ` +
        `${study.totals.stringsPerArchetypeInverter}`,
      `Actual site strings: ${study.totals.totalSiteStringCount}`,
      `Sequential external cable/archetype: ` +
        `${fmt(
          study.totals.sequentialExternalMPerArchetypeInverter,
          1
        )} m`,
      `Theoretical leapfrog external cable/archetype: ` +
        `${fmt(
          study.totals.leapfrogExternalMPerArchetypeInverter,
          1
        )} m`,
      `Available site saving: ` +
        `${available(study.totals.availableSiteSavingKm, ' km', 2)}`,
      'Reliance: indicative screening only.'
    ].join('\n');

    const element = $('plainSummary');

    if (element) {
      element.value = text;
    }

    return text;
  }

  function renderComparison() {
    setText(
      'v6Comparison',
      'V6 remains the complete-circuit geometry and electrical ' +
        'workbench, including module leads, connectors, loop area, ' +
        'inductance and capacitance.'
    );
    setText(
      'v7Comparison',
      'V7 remains the electromagnetic foundations workbench, ' +
        'separating propagation inductance from low-frequency ' +
        'internal inductance and exposing evidence status.'
    );
    setText(
      'v8Comparison',
      'V8 owns the sequential-versus-leapfrog external cable ' +
        'comparison, fixed physical module geometry, lead feasibility ' +
        'gate, actual site string count and all-string schedule.'
    );
  }

  function geometrySelfTests() {
    const sequence = buildLeapfrogSequence(30);
    const connections = sequenceConnections(sequence);
    const physical = Array.from({ length: 30 }, (_, index) => index + 1);

    return [
      {
        name: 'Physical modules remain M1 to M30',
        pass: physical.every((item, index) => item === index + 1)
      },
      {
        name: 'Thirty modules create twenty-nine series connections',
        pass: connections.length === 29
      },
      {
        name: 'Leapfrog turnaround is M29+ to M30−',
        pass: connections.some(
          (connection) => connection.from === 29 && connection.to === 30
        )
      },
      {
        name: 'Leapfrog return begins M30+ to M28−',
        pass: connections.some(
          (connection) => connection.from === 30 && connection.to === 28
        )
      },
      {
        name: 'Leapfrog free terminals are M1− and M2+',
        pass: sequence[0] === 1 && sequence[sequence.length - 1] === 2
      }
    ];
  }

  function renderSelfTests() {
    const modelTests = Model.runGoldenTests();
    const geometryTests = geometrySelfTests();
    const geometryPassed = geometryTests.filter((test) => test.pass).length;
    const passed = modelTests.passed + geometryPassed;
    const total = modelTests.total + geometryTests.length;
    const allPassed = modelTests.allPassed &&
      geometryTests.every((test) => test.pass);
    const status = $('selfTestStatus');

    if (status) {
      status.textContent = `${passed}/${total} TESTS PASSED`;
      status.className = allPassed
        ? 'status-badge testing'
        : 'status-badge error';
    }

    window.__V8_GEOMETRY_TESTS__ = geometryTests;

    return {
      modelTests,
      geometryTests,
      passed,
      total,
      allPassed
    };
  }

  function showError(error) {
    const box = $('runtimeError');
    const status = $('runtimeStatus');

    if (box) {
      box.classList.add('visible');
      box.textContent = `${error.name || 'Error'}: ${error.message || error}`;
    }

    if (status) {
      status.textContent = 'RUNTIME ERROR';
      status.className = 'status-badge error';
    }
  }

  function clearError() {
    const box = $('runtimeError');
    const status = $('runtimeStatus');

    if (box) {
      box.classList.remove('visible');
      box.textContent = '';
    }

    if (status) {
      status.textContent = `V${Model.VERSION} LIVE`;
      status.className = 'status-badge';
    }
  }

  function render() {
    try {
      clearError();

      const raw = readInputs();