minjiechen commited on
Commit
9a4ea8c
·
verified ·
1 Parent(s): f9845e9

Publish OpenPELS workspace

Browse files
README.md CHANGED
@@ -11,18 +11,19 @@ license: agpl-3.0
11
 
12
  # OpenPELS: Open Source Power Electronics Librarian Systems
13
 
14
- Editable power-electronics schematics and a loss-mechanism scoreboard.
15
- Circuit editing, analytical comparison and integrated NGSpice simulation.
 
16
 
17
- Start from coupled buck, XFLY6S or XFLY8S; edit components and wires, undo,
18
- and download portable projects, SVG and SPICE design netlists. Compare
19
- curated 2:1 / 4:1 topology models with die-area and passive constraints.
20
- 6:1, 8:1 and 16:1 numerical models remain explicitly pending.
 
21
 
22
- The Simulator tab runs one selected XFLY6S, XFLY8S or C3L model
23
- with NGSpice and displays voltage/current/capacitor waveforms, measurements,
24
- and executed-circuit downloads within the same workbench. Simulator controls
25
- are independent of canvas edits and analytical comparison inputs.
26
 
27
  The integrated runtime has no foundry PDK. Generic
28
  MOSFET starters describe connectivity; the scoreboard is a reference model,
 
11
 
12
  # OpenPELS: Open Source Power Electronics Librarian Systems
13
 
14
+ Browse supported power-electronics topologies as a gallery, filter by conversion
15
+ ratio, then select a circuit for detailed analysis and single-topology simulation.
16
+ Selection and output voltage/current carry through the workflow.
17
 
18
+ The library contains qualified coupled-magnetic references in the 2:1 and 4:1
19
+ families. 6:1, 8:1 and 16:1 remain explicitly unvalidated. Cards identify
20
+ analysis-only topologies and available simulation presets. NGSpice currently
21
+ supports XFLY6S, XFLY8S and C3L in the 4:1 family, with waveforms, measurements
22
+ and executed-file downloads.
23
 
24
+ The native schematic editor retains portable project import/export, undo,
25
+ SVG and SPICE design-netlist exports for its supplied starters. Selecting a
26
+ gallery card does not overwrite an edited project.
 
27
 
28
  The integrated runtime has no foundry PDK. Generic
29
  MOSFET starters describe connectivity; the scoreboard is a reference model,
simulator_bridge.js CHANGED
@@ -79,7 +79,74 @@ window.addEventListener("DOMContentLoaded", () => {
79
  document.getElementById("sweepStatus").textContent =
80
  "Optional · enable in the controls before running.";
81
  }
82
- select.addEventListener("change", updateTopology);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  updateTopology();
84
  parent.postMessage({ type: "pe:simulator-ready" }, location.origin);
85
  });
 
79
  document.getElementById("sweepStatus").textContent =
80
  "Optional · enable in the controls before running.";
81
  }
82
+ function reportPoint() {
83
+ if (pendingReference || select.disabled) return;
84
+ parent.postMessage(
85
+ {
86
+ type: "pe:simulation-point",
87
+ topology: select.value,
88
+ vout: Number(document.getElementById("targetVout").value),
89
+ iout: Number(document.getElementById("iout").value),
90
+ },
91
+ location.origin,
92
+ );
93
+ }
94
+ select.addEventListener("change", () => {
95
+ updateTopology();
96
+ reportPoint();
97
+ });
98
+ document.getElementById("targetVout").addEventListener("input", reportPoint);
99
+ document.getElementById("iout").addEventListener("input", reportPoint);
100
+ let pendingReference = null;
101
+ function applyReference() {
102
+ if (!pendingReference || select.disabled) return;
103
+ const next = pendingReference;
104
+ pendingReference = null;
105
+ select.value = next.topology;
106
+ updateTopology();
107
+ document.getElementById("targetVout").value = next.vout;
108
+ document.getElementById("iout").value = next.iout;
109
+ document.getElementById("vin").value = next.ratio * next.vout;
110
+ updateLabels();
111
+ parent.postMessage(
112
+ {
113
+ type: "pe:reference-applied",
114
+ topology: next.topology,
115
+ ratio: next.ratio,
116
+ vout: next.vout,
117
+ iout: next.iout,
118
+ },
119
+ location.origin,
120
+ );
121
+ }
122
+ window.addEventListener("message", (event) => {
123
+ if (
124
+ event.origin !== location.origin ||
125
+ event.source !== parent ||
126
+ event.data?.type !== "pe:select-topology"
127
+ )
128
+ return;
129
+ const next = event.data;
130
+ if (
131
+ !Object.hasOwn(frequencies, next.topology) ||
132
+ next.ratio !== 4 ||
133
+ !Number.isFinite(next.vout) ||
134
+ next.vout < 0.3 ||
135
+ next.vout > 1.1 ||
136
+ !Number.isFinite(next.iout) ||
137
+ next.iout < 0.1 ||
138
+ next.iout > 40
139
+ )
140
+ return;
141
+ pendingReference = next;
142
+ if (select.disabled)
143
+ parent.postMessage({ type: "pe:simulator-busy" }, location.origin);
144
+ applyReference();
145
+ });
146
+ new MutationObserver(applyReference).observe(select, {
147
+ attributes: true,
148
+ attributeFilter: ["disabled"],
149
+ });
150
  updateTopology();
151
  parent.postMessage({ type: "pe:simulator-ready" }, location.origin);
152
  });
simulator_frame.py CHANGED
@@ -5,6 +5,8 @@ def simulator_html(original):
5
  html = original.replace('<title>Xfly / C3L Comparison GUI - Chen / Kudva</title>', '<title>OpenPELS · NGSpice simulator</title>')
6
  html = html.replace('Xfly6S / Xfly8S / C3L NGSpice Comparison - Chen / Kudva', 'NGSpice simulator')
7
  html = html.replace('src="/assets/', 'src="/simulator/assets/')
 
 
8
  selector = '''<div class="control">
9
  <label for="topologySelect">Topology</label>
10
  <select id="topologySelect" name="topology">
@@ -63,8 +65,8 @@ def simulator_html(original):
63
  html = html.replace('<table id="metricsTable" hidden>', '<div class="metrics-scroll"><table id="metricsTable" hidden>').replace('</table>', '</table></div>', 1)
64
  html = html.replace('<main>', '<div id="runArtifacts" class="run-artifacts"></div>\n<main>', 1)
65
  html = html.replace('<script>\n const form', '<script src="/simulator/bridge.js"></script>\n <script>\n const form', 1)
66
- html = html.replace(' runButton.disabled = true;', " runButton.disabled = true;\n document.getElementById('topologySelect').disabled = true;\n openpelsRenderArtifacts({artifacts:[]});")
67
- html = html.replace(' runButton.disabled = false;', " runButton.disabled = false;\n document.getElementById('topologySelect').disabled = false;")
68
  html = html.replace('Efficiency (%)', 'Modeled efficiency (%)').replace('Best Efficiency', 'Modeled efficiency')
69
  html = html.replace('</head>', '''<style>
70
  body{background:#f5f6f8}header{position:static;padding:14px 22px}h1{font-size:17px}
 
5
  html = original.replace('<title>Xfly / C3L Comparison GUI - Chen / Kudva</title>', '<title>OpenPELS · NGSpice simulator</title>')
6
  html = html.replace('Xfly6S / Xfly8S / C3L NGSpice Comparison - Chen / Kudva', 'NGSpice simulator')
7
  html = html.replace('src="/assets/', 'src="/simulator/assets/')
8
+ html = html.replace('max="1.10" step="0.01"', 'max="1.10" step="any"')
9
+ html = html.replace('Number(targetVout.value).toFixed(2)', 'Number(targetVout.value).toFixed(3)')
10
  selector = '''<div class="control">
11
  <label for="topologySelect">Topology</label>
12
  <select id="topologySelect" name="topology">
 
65
  html = html.replace('<table id="metricsTable" hidden>', '<div class="metrics-scroll"><table id="metricsTable" hidden>').replace('</table>', '</table></div>', 1)
66
  html = html.replace('<main>', '<div id="runArtifacts" class="run-artifacts"></div>\n<main>', 1)
67
  html = html.replace('<script>\n const form', '<script src="/simulator/bridge.js"></script>\n <script>\n const form', 1)
68
+ html = html.replace(' runButton.disabled = true;', " runButton.disabled = true;\n document.getElementById('topologySelect').disabled = true;\n document.getElementById('targetVout').disabled = true;\n document.getElementById('iout').disabled = true;\n openpelsRenderArtifacts({artifacts:[]});")
69
+ html = html.replace(' runButton.disabled = false;', " runButton.disabled = false;\n document.getElementById('topologySelect').disabled = false;\n document.getElementById('targetVout').disabled = false;\n document.getElementById('iout').disabled = false;")
70
  html = html.replace('Efficiency (%)', 'Modeled efficiency (%)').replace('Best Efficiency', 'Modeled efficiency')
71
  html = html.replace('</head>', '''<style>
72
  body{background:#f5f6f8}header{position:static;padding:14px 22px}h1{font-size:17px}
static/analysis.js ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /** Carry the selected reference into the existing analytical workbench. */
2
+ export function createAnalysis(report, onPoint) {
3
+ const frame = document.querySelector("#comparison");
4
+ let ready = false,
5
+ selection = null;
6
+ function deliver() {
7
+ if (ready && selection)
8
+ frame.contentWindow.postMessage(
9
+ { type: "pe:topology", ...selection },
10
+ location.origin,
11
+ );
12
+ }
13
+ window.addEventListener("message", (event) => {
14
+ if (
15
+ event.origin !== location.origin ||
16
+ event.source !== frame.contentWindow
17
+ )
18
+ return;
19
+ if (event.data?.type === "pe:analysis-ready") {
20
+ ready = true;
21
+ deliver();
22
+ }
23
+ if (event.data?.type === "pe:analysis-point") onPoint(event.data);
24
+ if (event.data?.type === "pe:analysis-error") report(event.data.message);
25
+ });
26
+ function show(next) {
27
+ if (next) selection = next;
28
+ if (!frame.getAttribute("src")) frame.src = frame.dataset.src;
29
+ deliver();
30
+ }
31
+ return { show };
32
+ }
static/compare/app.js CHANGED
@@ -107,7 +107,7 @@ function lossScoreboard(t){const data=t.loss_scoreboard;if(!data.rows.length)ret
107
  return `<section class="loss-scoreboard" aria-label="Loss mechanism scoreboard"><div class="scoreboard-intro"><b>THE LOSS LINEUP</b><span>Higher score = lower modeled loss · actual values in mW</span></div><div class="scoreboard-scroll"><table style="--teams:${data.rows.length}"><thead><tr><th class="mechanism-heading">Compare the same<br>mechanism across circuits</th>${data.rows.map(d=>{const r=byId[d.id];return `<th class="team-heading"><span class="team-family">${r.native_ratio}:1 FAMILY</span><h3>${esc(r.short)}</h3><img src="./assets/${r.asset.replace('.svg','-candidate.svg')}" alt="${esc(r.name)} topology"><div class="team-total">${fmt(d.total*1e3,1)} <small>mW</small></div><span class="team-total-label">TOTAL MODELED LOSS</span><div class="loss-mix" aria-label="Loss composition">${data.mechanisms.map(m=>`<span style="width:${d.total?d.powers[m.id]/d.total*100:0}%;background:${m.color}" title="${m.name}: ${fmt(d.powers[m.id]*1e3,2)} mW"></span>`).join('')}</div><span class="team-rout">Rout ${fmt(r.rout*1e3,2)} mΩ</span></th>`}).join('')}</tr></thead><tbody>${data.mechanisms.map(m=>`<tr data-loss-mechanism="${m.id}"><th><span class="mechanism-symbol" style="color:${m.color}">${m.symbol}</span><span>${m.name}</span>${m.id==='charging'?'<small>Finite-charge addition only</small>':''}</th>${data.rows.map(d=>`<td data-score-team="${d.id}" data-score-value="${d.ratings[m.id]??''}"><div class="mechanism-stat"><span class="mechanism-rating ${tone(d.ratings[m.id])}">${rating(d.ratings[m.id])}</span><strong>${fmt(d.powers[m.id]*1e3,2)} <small>mW</small></strong></div><div class="attribute-track"><span class="${tone(d.ratings[m.id])}" style="width:${d.ratings[m.id]??0}%"></span></div></td>`).join('')}</tr>`).join('')}<tr class="unquantified-row"><th>Coss / core / ripple<small>Outside the current loss model</small></th>${data.rows.map(()=>'<td>Not quantified<span>No score assigned</span></td>').join('')}</tr><tr class="tradeoff-row"><th>PRO / TRADEOFF<small>Against the other displayed circuits</small></th>${data.rows.map(d=>`<td><p class="score-pro">+ ${esc(d.pro)}${d.pro_delta!=null?`<small>${fmt(d.pro_delta*1e3,2)} mW less than others’ mean</small>`:''}</p><p class="score-con">↔ ${esc(d.con)}${d.con_delta!=null?`<small>${fmt(d.con_delta*1e3,2)} mW more than others’ mean</small>`:''}</p><p class="score-resources">${byId[d.id].capacitors} caps · ${byId[d.id].windings} windings<br>${fmt(byId[d.id].width_mm,1)} mm FET width</p><button data-inspect-design="${d.id}">Inspect circuit →</button></td>`).join('')}</tr></tbody></table></div><p class="scoreboard-note">${esc(data.scale)} Unknown losses are not scored as zero. The stacked color strip shows each mechanism’s share of modeled loss; ratings compare mechanisms separately.</p><details class="scoreboard-method"><summary>What is included in each loss?</summary><p>Switch = Iout² RFET; capacitor = Iout² RCAP; winding = Iout² RIND; charging = Iout² (Req − RFSL); gate = the FOM-based gate-drive demand. These five terms sum to the displayed modeled total. The raw RSSL asymptote is not added again. Coss, core and ripple corrections remain unquantified. Pros and tradeoffs identify the largest mW difference versus the mean of the other displayed circuits; ratings are recalculated when this comparison set changes.</p></details></section>`;
108
  }
109
  function setComparisonView(view){comparisonView=view;$('#loss-scoreboard-view').hidden=view!=='scoreboard';$('#candidate-cards-view').hidden=view!=='circuits';$$('[data-comparison-view]').forEach(b=>{b.classList.toggle('active',b.dataset.comparisonView===view);b.setAttribute('aria-pressed',String(b.dataset.comparisonView===view))})}
110
- function renderRecommendation(){if(!catalog.length)return;try{recommendationReport=OpenPELSRecommendation.recommend(designParameters(),{catalog},OpenPELSEngine,OpenPELSTechnology);recommendationReport.loss_scoreboard=OpenPELSScores.build(recommendationReport);$('#design-error').textContent='';$('#recommend-design').textContent='Update candidates';$('#export-recommendation').disabled=false;const t=recommendationReport,p=t.parameters,native=t.native_models;
111
  $('#family-context').textContent=native?`${ratio}:1 cancellation family · ${native} coupled-inductor candidates. Complementary winding excitation or ideal midpoint hold is admitted; estimated phase ripple must satisfy the entered limit.`:`${ratio}:1 · no verified coupled-inductor cancellation-point model in the current library. Off-duty and uncoupled circuits are omitted.`;
112
  $('#candidate-status').textContent=t.eligible.length?`${t.eligible.length} candidates meet the current limits · Rload = ${fmt(t.load_resistance,4)} Ω. Inspect any panel to review its model.`:!native?'No qualified coupled-inductor cancellation-point model is available for this ratio.':!t.voltage_ratio_match?'The requested output voltage does not match this ratio’s nominal cancellation point.':'No candidate passes the current constraints. Expand the excluded candidates below for reasons.';
113
  const candidatePanel=r=>{
@@ -121,7 +121,71 @@ if(t.eligible.length){setComparisonView(comparisonView);$$('[data-comparison-vie
121
  }catch(e){recommendationReport=null;$('#design-error').textContent=e.message;$('#candidate-status').textContent='Check the design inputs to calculate the candidates.';$('#shortlist-results').innerHTML=''}}
122
  $('#design-fields').addEventListener('input',()=>{updateLoadSummary();$('#design-error').textContent='Inputs changed — update the recommendation.';$('#recommend-design').textContent='Update candidates';$('#export-recommendation').disabled=true;$$('[data-inspect-design]').forEach(b=>b.disabled=true)});$('#recommend-design').onclick=renderRecommendation;$('#export-recommendation').onclick=()=>{if(recommendationReport)download('openpels-design-shortlist.json',JSON.stringify(recommendationReport,null,2),'application/json')};
123
  let resizeTimer;window.addEventListener('resize',()=>{clearTimeout(resizeTimer);resizeTimer=setTimeout(()=>{if($('#sweep-section').open)drawSweep()},200)});
124
- (async()=>{try{catalog=await api('/api/catalog');selected=new Set(OpenPELSRecommendation.familyIds(ratio));picker();await update()}catch(e){toast(e.message)}})();
125
 
126
- // Same-origin OpenPELS host selects a reference family, never arbitrary circuits.
127
- window.addEventListener('message',e=>{if(e.origin!==location.origin||e.source!==parent||e.data?.type!=='pe:family'||![2,4,6,8,16].includes(e.data.ratio))return;document.querySelector(`[data-ratio="${e.data.ratio}"]`)?.click()});
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  return `<section class="loss-scoreboard" aria-label="Loss mechanism scoreboard"><div class="scoreboard-intro"><b>THE LOSS LINEUP</b><span>Higher score = lower modeled loss · actual values in mW</span></div><div class="scoreboard-scroll"><table style="--teams:${data.rows.length}"><thead><tr><th class="mechanism-heading">Compare the same<br>mechanism across circuits</th>${data.rows.map(d=>{const r=byId[d.id];return `<th class="team-heading"><span class="team-family">${r.native_ratio}:1 FAMILY</span><h3>${esc(r.short)}</h3><img src="./assets/${r.asset.replace('.svg','-candidate.svg')}" alt="${esc(r.name)} topology"><div class="team-total">${fmt(d.total*1e3,1)} <small>mW</small></div><span class="team-total-label">TOTAL MODELED LOSS</span><div class="loss-mix" aria-label="Loss composition">${data.mechanisms.map(m=>`<span style="width:${d.total?d.powers[m.id]/d.total*100:0}%;background:${m.color}" title="${m.name}: ${fmt(d.powers[m.id]*1e3,2)} mW"></span>`).join('')}</div><span class="team-rout">Rout ${fmt(r.rout*1e3,2)} mΩ</span></th>`}).join('')}</tr></thead><tbody>${data.mechanisms.map(m=>`<tr data-loss-mechanism="${m.id}"><th><span class="mechanism-symbol" style="color:${m.color}">${m.symbol}</span><span>${m.name}</span>${m.id==='charging'?'<small>Finite-charge addition only</small>':''}</th>${data.rows.map(d=>`<td data-score-team="${d.id}" data-score-value="${d.ratings[m.id]??''}"><div class="mechanism-stat"><span class="mechanism-rating ${tone(d.ratings[m.id])}">${rating(d.ratings[m.id])}</span><strong>${fmt(d.powers[m.id]*1e3,2)} <small>mW</small></strong></div><div class="attribute-track"><span class="${tone(d.ratings[m.id])}" style="width:${d.ratings[m.id]??0}%"></span></div></td>`).join('')}</tr>`).join('')}<tr class="unquantified-row"><th>Coss / core / ripple<small>Outside the current loss model</small></th>${data.rows.map(()=>'<td>Not quantified<span>No score assigned</span></td>').join('')}</tr><tr class="tradeoff-row"><th>PRO / TRADEOFF<small>Against the other displayed circuits</small></th>${data.rows.map(d=>`<td><p class="score-pro">+ ${esc(d.pro)}${d.pro_delta!=null?`<small>${fmt(d.pro_delta*1e3,2)} mW less than others’ mean</small>`:''}</p><p class="score-con">↔ ${esc(d.con)}${d.con_delta!=null?`<small>${fmt(d.con_delta*1e3,2)} mW more than others’ mean</small>`:''}</p><p class="score-resources">${byId[d.id].capacitors} caps · ${byId[d.id].windings} windings<br>${fmt(byId[d.id].width_mm,1)} mm FET width</p><button data-inspect-design="${d.id}">Inspect circuit →</button></td>`).join('')}</tr></tbody></table></div><p class="scoreboard-note">${esc(data.scale)} Unknown losses are not scored as zero. The stacked color strip shows each mechanism’s share of modeled loss; ratings compare mechanisms separately.</p><details class="scoreboard-method"><summary>What is included in each loss?</summary><p>Switch = Iout² RFET; capacitor = Iout² RCAP; winding = Iout² RIND; charging = Iout² (Req − RFSL); gate = the FOM-based gate-drive demand. These five terms sum to the displayed modeled total. The raw RSSL asymptote is not added again. Coss, core and ripple corrections remain unquantified. Pros and tradeoffs identify the largest mW difference versus the mean of the other displayed circuits; ratings are recalculated when this comparison set changes.</p></details></section>`;
108
  }
109
  function setComparisonView(view){comparisonView=view;$('#loss-scoreboard-view').hidden=view!=='scoreboard';$('#candidate-cards-view').hidden=view!=='circuits';$$('[data-comparison-view]').forEach(b=>{b.classList.toggle('active',b.dataset.comparisonView===view);b.setAttribute('aria-pressed',String(b.dataset.comparisonView===view))})}
110
+ function renderRecommendation(){if(!catalog.length)return;try{recommendationReport=focusRecommendation(OpenPELSRecommendation.recommend(designParameters(),{catalog},OpenPELSEngine,OpenPELSTechnology));recommendationReport.loss_scoreboard=OpenPELSScores.build(recommendationReport);$('#design-error').textContent='';$('#recommend-design').textContent='Update candidates';$('#export-recommendation').disabled=false;const t=recommendationReport,p=t.parameters,native=t.native_models;
111
  $('#family-context').textContent=native?`${ratio}:1 cancellation family · ${native} coupled-inductor candidates. Complementary winding excitation or ideal midpoint hold is admitted; estimated phase ripple must satisfy the entered limit.`:`${ratio}:1 · no verified coupled-inductor cancellation-point model in the current library. Off-duty and uncoupled circuits are omitted.`;
112
  $('#candidate-status').textContent=t.eligible.length?`${t.eligible.length} candidates meet the current limits · Rload = ${fmt(t.load_resistance,4)} Ω. Inspect any panel to review its model.`:!native?'No qualified coupled-inductor cancellation-point model is available for this ratio.':!t.voltage_ratio_match?'The requested output voltage does not match this ratio’s nominal cancellation point.':'No candidate passes the current constraints. Expand the excluded candidates below for reasons.';
113
  const candidatePanel=r=>{
 
121
  }catch(e){recommendationReport=null;$('#design-error').textContent=e.message;$('#candidate-status').textContent='Check the design inputs to calculate the candidates.';$('#shortlist-results').innerHTML=''}}
122
  $('#design-fields').addEventListener('input',()=>{updateLoadSummary();$('#design-error').textContent='Inputs changed — update the recommendation.';$('#recommend-design').textContent='Update candidates';$('#export-recommendation').disabled=true;$$('[data-inspect-design]').forEach(b=>b.disabled=true)});$('#recommend-design').onclick=renderRecommendation;$('#export-recommendation').onclick=()=>{if(recommendationReport)download('openpels-design-shortlist.json',JSON.stringify(recommendationReport,null,2),'application/json')};
123
  let resizeTimer;window.addEventListener('resize',()=>{clearTimeout(resizeTimer);resizeTimer=setTimeout(()=>{if($('#sweep-section').open)drawSweep()},200)});
124
+ (async()=>{try{catalog=await api('/api/catalog');selected=new Set(OpenPELSRecommendation.familyIds(ratio));picker();await update();announceAnalysisReady()}catch(e){toast(e.message)}})();
125
 
126
+ // Appended inside the preserved analytical UI's scope.
127
+ let focusedTopology = null;
128
+ function focusRecommendation(result) {
129
+ if (!focusedTopology) return result;
130
+ const rows = result.rows.filter((row) => row.id === focusedTopology);
131
+ const eligible = result.eligible.filter((row) => row.id === focusedTopology);
132
+ return {
133
+ ...result,
134
+ rows,
135
+ eligible,
136
+ winner: eligible[0] ?? null,
137
+ native_models: rows.filter((row) => row.reference_match).length,
138
+ };
139
+ }
140
+ function reportOperatingPoint() {
141
+ if (!focusedTopology) return;
142
+ parent.postMessage(
143
+ {
144
+ type: "pe:analysis-point",
145
+ id: focusedTopology,
146
+ ratio,
147
+ vout: Number(document.querySelector("#design-vout").value),
148
+ iout: Number(document.querySelector("#design-io").value),
149
+ },
150
+ location.origin,
151
+ );
152
+ }
153
+ window.addEventListener("message", (event) => {
154
+ if (
155
+ event.origin !== location.origin ||
156
+ event.source !== parent ||
157
+ event.data?.type !== "pe:topology"
158
+ )
159
+ return;
160
+ const next = event.data;
161
+ if (
162
+ ![2, 4, 6, 8, 16].includes(next.ratio) ||
163
+ !OpenPELSRecommendation.familyIds(next.ratio).includes(next.id)
164
+ )
165
+ return;
166
+ if (!catalog.some((entry) => entry.id === next.id)) return;
167
+ ratio = next.ratio;
168
+ focusedTopology = next.id;
169
+ selected = new Set([next.id]);
170
+ if (Number.isFinite(next.vout) && next.vout > 0)
171
+ document.querySelector("#design-vout").value = next.vout;
172
+ if (Number.isFinite(next.iout) && next.iout > 0)
173
+ document.querySelector("#design-io").value = next.iout;
174
+ document.body.classList.add("focused-topology");
175
+ document.querySelector("#analysis-workbench").open = true;
176
+ document
177
+ .querySelectorAll("[data-ratio]")
178
+ .forEach((button) =>
179
+ button.classList.toggle("active", Number(button.dataset.ratio) === ratio),
180
+ );
181
+ updateLoadSummary();
182
+ picker();
183
+ update();
184
+ reportOperatingPoint();
185
+ });
186
+ document
187
+ .querySelector("#design-fields")
188
+ .addEventListener("input", reportOperatingPoint);
189
+ function announceAnalysisReady() {
190
+ parent.postMessage({ type: "pe:analysis-ready" }, location.origin);
191
+ }
static/compare/style.css CHANGED
@@ -29,4 +29,4 @@ main{max-width:1560px;padding-top:32px}.intro{margin-bottom:26px}.intro p{font-s
29
  .tradeoff-row .score-pro small,.tradeoff-row .score-con small{display:block;font-size:8px;color:#8c9984;margin:3px 0 0 11px}
30
 
31
  /* Embedded OpenPELS comparison workspace. */
32
- header{display:none}main{max-width:1450px;padding-top:26px}h1{font-size:25px}
 
29
  .tradeoff-row .score-pro small,.tradeoff-row .score-con small{display:block;font-size:8px;color:#8c9984;margin:3px 0 0 11px}
30
 
31
  /* Embedded OpenPELS comparison workspace. */
32
+ header{display:none}main{max-width:1450px;padding-top:26px}h1{font-size:25px}.focused-topology #ratios,.focused-topology #topology-picker{display:none}
static/gallery.js ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import "./compare/recommend.js";
2
+
3
+ export const FAMILY_RATIOS = [2, 4, 6, 8, 16];
4
+ const presets = {
5
+ xfly2p: {
6
+ name: "XFLY6S",
7
+ image: "xfly6s-candidate.svg",
8
+ starter: "xfly6s",
9
+ simulator: "xfly6s",
10
+ },
11
+ xfly4p: {
12
+ name: "XFLY8S",
13
+ image: "xfly4p-candidate.svg",
14
+ starter: "xfly8s",
15
+ simulator: "xfly8s",
16
+ simulationRelation: "related",
17
+ simulationNote:
18
+ "Related simulation and editor preset: two cross-linked capacitors, no clamp capacitors. The analytical circuit includes Cc1 and Cc2.",
19
+ },
20
+ "3lbuck": {
21
+ name: "Three-level buck",
22
+ image: "3lbuck-candidate.svg",
23
+ simulator: "c3l",
24
+ },
25
+ "2sbuck": { name: "Capacitor-clamped buck", image: "2sbuck-candidate.svg" },
26
+ buck: { name: "Stacked synchronous buck", image: "buck-candidate.svg" },
27
+ buck2: {
28
+ name: "Two-phase coupled buck",
29
+ image: "buck2-candidate.svg",
30
+ starter: "buck2",
31
+ },
32
+ };
33
+ export function createGallery({ onSelect, report }) {
34
+ let entries = [],
35
+ filter = null,
36
+ selected = null;
37
+ const list = document.querySelector("#gallery-cards");
38
+ const filters = document.querySelector("#gallery-ratios");
39
+ function render() {
40
+ list.replaceChildren();
41
+ const matches = entries.filter(
42
+ (entry) => filter === null || entry.ratios.includes(filter),
43
+ );
44
+ document.querySelector("#gallery-count").textContent =
45
+ `${matches.length} ${matches.length === 1 ? "topology" : "topologies"}${filter ? ` for ${filter}:1` : " in the library"}`;
46
+ document.querySelector("#gallery-empty").hidden = matches.length > 0;
47
+ document.querySelector("#gallery-empty-text").textContent =
48
+ `Qualified coupled-inductor candidates are not yet validated for ${filter}:1. Choose 2:1 or 4:1 to explore the supported families.`;
49
+ filters.querySelectorAll("button").forEach((button) => {
50
+ const active =
51
+ button.dataset.family === (filter === null ? "all" : String(filter));
52
+ button.classList.toggle("active", active);
53
+ button.setAttribute("aria-pressed", String(active));
54
+ });
55
+ for (const entry of matches) {
56
+ const button = document.createElement("button");
57
+ button.className =
58
+ "topology-tile" + (selected === entry.id ? " selected" : "");
59
+ button.dataset.topologyId = entry.id;
60
+ const ratio = filter ?? (entry.ratios.includes(4) ? 4 : entry.ratios[0]);
61
+ const heading = document.createElement("div");
62
+ heading.className = "tile-heading";
63
+ const name = document.createElement("strong");
64
+ name.textContent = entry.name;
65
+ const tag = document.createElement("span");
66
+ tag.textContent = entry.ratios.map((value) => `${value}:1`).join(" · ");
67
+ heading.append(name, tag);
68
+ const image = document.createElement("img");
69
+ image.src = "./compare/assets/" + entry.image;
70
+ image.alt = entry.name + " circuit schematic";
71
+ const meta = document.createElement("div");
72
+ meta.className = "tile-meta";
73
+ meta.textContent = `${entry.switches} switches · coupled magnetics`;
74
+ const capability = document.createElement("span");
75
+ capability.className = "tile-capability";
76
+ capability.textContent =
77
+ entry.simulator && ratio === 4
78
+ ? entry.simulationRelation === "related"
79
+ ? "Analysis · related simulation"
80
+ : "Analysis + simulation"
81
+ : "Analytical model";
82
+ const action = document.createElement("span");
83
+ action.className = "tile-action";
84
+ action.textContent = "Explore topology →";
85
+ button.append(heading, image, meta, capability, action);
86
+ button.onclick = () => {
87
+ selected = entry.id;
88
+ render();
89
+ onSelect(entry, ratio);
90
+ };
91
+ list.append(button);
92
+ }
93
+ }
94
+ for (const [value, label] of [
95
+ [null, "All topologies"],
96
+ ...FAMILY_RATIOS.map((ratio) => [ratio, `${ratio}:1`]),
97
+ ]) {
98
+ const button = document.createElement("button");
99
+ button.textContent = label;
100
+ button.dataset.family = value === null ? "all" : String(value);
101
+ button.onclick = () => {
102
+ filter = value;
103
+ render();
104
+ };
105
+ filters.append(button);
106
+ }
107
+ async function load() {
108
+ try {
109
+ const response = await fetch("./compare/models-data.json");
110
+ if (!response.ok) throw Error("Topology gallery unavailable");
111
+ const data = await response.json();
112
+ entries = data.catalog
113
+ .filter((meta) => presets[meta.id])
114
+ .map((meta) => ({
115
+ ...meta,
116
+ ...presets[meta.id],
117
+ ratios: FAMILY_RATIOS.filter((ratio) =>
118
+ window.OpenPELSRecommendation.familyIds(ratio).includes(meta.id),
119
+ ),
120
+ }))
121
+ .filter((entry) => entry.ratios.length);
122
+ render();
123
+ return entries;
124
+ } catch (error) {
125
+ report(error.message);
126
+ throw error;
127
+ }
128
+ }
129
+ return {
130
+ load,
131
+ get: (id) => entries.find((entry) => entry.id === id),
132
+ forSimulator: (id) => entries.find((entry) => entry.simulator === id),
133
+ highlight(id) {
134
+ selected = id;
135
+ render();
136
+ },
137
+ };
138
+ }
static/index.html CHANGED
@@ -21,11 +21,12 @@
21
  ></a
22
  >
23
  <nav aria-label="Workspace">
24
- <button class="active" data-view="design">Schematic</button
25
- ><button data-view="simulator">Simulator</button
26
- ><button data-view="compare">Loss scoreboard <span>↗</span></button>
 
27
  </nav>
28
- <div class="file-actions">
29
  <button id="open-project">Open project</button
30
  ><button class="primary" id="save-project" disabled>
31
  ↓ Save project</button
@@ -38,7 +39,60 @@
38
  </div>
39
  </header>
40
  <div id="message" role="status" aria-live="polite"></div>
41
- <main id="design-view" class="design-layout">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  <aside class="library">
43
  <div class="eyebrow">START WITH A CIRCUIT</div>
44
  <h1>From topology<br />to tradeoffs.</h1>
@@ -110,7 +164,7 @@
110
  new analytical model from arbitrary rewiring.
111
  </p>
112
  <button id="compare-reference" class="wide primary" disabled>
113
- Compare reference family →
114
  </button>
115
  <div class="section-label assumptions-title">WHAT YOU CAN COMPARE</div>
116
  <ul class="mechanisms">
@@ -147,10 +201,10 @@
147
  </main>
148
  <section id="compare-view" hidden>
149
  <div class="compare-caption">
150
- <strong>Same resources. Different loss mechanisms.</strong
151
  ><span id="compare-context"
152
  >Curated reference circuits · independent of canvas edits</span
153
- ><button id="back-design">← Back to schematic</button>
154
  </div>
155
  <iframe
156
  id="comparison"
 
21
  ></a
22
  >
23
  <nav aria-label="Workspace">
24
+ <button class="active" data-view="gallery">Gallery</button>
25
+ <button data-view="compare" disabled>Analysis</button>
26
+ <button data-view="simulator" disabled>Simulator</button>
27
+ <button data-view="design">Schematic</button>
28
  </nav>
29
+ <div class="file-actions" hidden>
30
  <button id="open-project">Open project</button
31
  ><button class="primary" id="save-project" disabled>
32
  ↓ Save project</button
 
39
  </div>
40
  </header>
41
  <div id="message" role="status" aria-live="polite"></div>
42
+ <section id="gallery-view" aria-label="Topology gallery">
43
+ <div class="gallery-hero">
44
+ <div class="eyebrow">THE POWER ELECTRONICS LIBRARY</div>
45
+ <h1>
46
+ Find your topology.<br /><span>Explore what makes it work.</span>
47
+ </h1>
48
+ <p>
49
+ Choose a conversion ratio, explore matching circuits, and open a
50
+ topology for detailed analysis and simulation.
51
+ </p>
52
+ <div class="workflow-steps">
53
+ <span><b>01</b> Choose a ratio</span><i>→</i
54
+ ><span><b>02</b> Select a topology</span><i>→</i
55
+ ><span><b>03</b> Analyze &amp; simulate</span>
56
+ </div>
57
+ </div>
58
+ <div class="gallery-toolbar">
59
+ <div>
60
+ <h2>Topology gallery</h2>
61
+ <p id="gallery-count">Loading supported topologies…</p>
62
+ </div>
63
+ <div
64
+ id="gallery-ratios"
65
+ class="gallery-ratios"
66
+ aria-label="Filter by conversion ratio"
67
+ ></div>
68
+ </div>
69
+ <div id="gallery-cards" class="gallery-cards"></div>
70
+ <div id="gallery-empty" class="gallery-empty" hidden>
71
+ <span>More families ahead</span>
72
+ <h2>This family is awaiting validation.</h2>
73
+ <p id="gallery-empty-text"></p>
74
+ </div>
75
+ <p class="gallery-note">
76
+ Families follow the qualified coupled-inductor reference models.
77
+ Simulation availability is shown on each card.
78
+ </p>
79
+ </section>
80
+ <section id="selection-bar" hidden aria-label="Selected topology">
81
+ <button id="back-gallery">← Gallery</button
82
+ ><img id="selected-image" alt="" />
83
+ <div class="selected-identity">
84
+ <small id="selected-ratio"></small>
85
+ <h1 id="selected-name"></h1>
86
+ <p>Curated reference · independent of canvas edits</p>
87
+ </div>
88
+ <div class="selection-actions">
89
+ <button id="selected-analysis">Detailed analysis</button
90
+ ><button id="selected-simulate" class="primary">Simulate →</button
91
+ ><button id="selected-edit">Edit schematic</button>
92
+ </div>
93
+ <p id="selected-availability" role="status"></p>
94
+ </section>
95
+ <main id="design-view" class="design-layout" hidden>
96
  <aside class="library">
97
  <div class="eyebrow">START WITH A CIRCUIT</div>
98
  <h1>From topology<br />to tradeoffs.</h1>
 
164
  new analytical model from arbitrary rewiring.
165
  </p>
166
  <button id="compare-reference" class="wide primary" disabled>
167
+ Analyze reference topology →
168
  </button>
169
  <div class="section-label assumptions-title">WHAT YOU CAN COMPARE</div>
170
  <ul class="mechanisms">
 
201
  </main>
202
  <section id="compare-view" hidden>
203
  <div class="compare-caption">
204
+ <strong>Detailed topology analysis</strong
205
  ><span id="compare-context"
206
  >Curated reference circuits · independent of canvas edits</span
207
+ ><button id="back-design">← Back to gallery</button>
208
  </div>
209
  <iframe
210
  id="comparison"
static/openpels-source.zip CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:7dc4b892ec7eafe503de4cfcc65bed3ff45158d93150e0b3d246f1c3bc8c7ef2
3
- size 24796218
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:09d18d8bf3e62bf6c6e1640273c83a4c54431d3e6e6261bf53d29341b9b50067
3
+ size 24806417
static/pe.css CHANGED
@@ -604,3 +604,306 @@ footer a + a {
604
  min-width: 0;
605
  }
606
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
604
  min-width: 0;
605
  }
606
  }
607
+
608
+ /* Browse a ratio-qualified library, then follow one reference through the workbench. */
609
+ [hidden] {
610
+ display: none !important;
611
+ }
612
+ #gallery-view {
613
+ max-width: 1380px;
614
+ margin: auto;
615
+ padding: 48px 34px 30px;
616
+ min-height: calc(100vh - 114px);
617
+ }
618
+ .gallery-hero {
619
+ padding: 20px 0 37px;
620
+ border-bottom: 1px solid var(--line);
621
+ }
622
+ .gallery-hero h1 {
623
+ font:
624
+ 800 43px/1.18 Manrope,
625
+ Arial;
626
+ letter-spacing: -1.7px;
627
+ margin: 17px 0;
628
+ }
629
+ .gallery-hero h1 span {
630
+ color: #8793a0;
631
+ }
632
+ .gallery-hero > p {
633
+ max-width: 640px;
634
+ color: #778592;
635
+ font-size: 14px;
636
+ line-height: 1.8;
637
+ }
638
+ .workflow-steps {
639
+ display: flex;
640
+ align-items: center;
641
+ gap: 23px;
642
+ margin-top: 28px;
643
+ font-size: 12px;
644
+ color: #6e7b88;
645
+ }
646
+ .workflow-steps b {
647
+ font-size: 10px;
648
+ color: var(--accent);
649
+ margin-right: 9px;
650
+ }
651
+ .workflow-steps i {
652
+ font-style: normal;
653
+ color: #bac1c7;
654
+ }
655
+ .gallery-toolbar {
656
+ display: flex;
657
+ align-items: center;
658
+ justify-content: space-between;
659
+ gap: 24px;
660
+ padding: 28px 0 22px;
661
+ }
662
+ .gallery-toolbar h2 {
663
+ font:
664
+ 700 19px Manrope,
665
+ Arial;
666
+ margin: 0 0 8px;
667
+ }
668
+ .gallery-toolbar p {
669
+ font-size: 11px;
670
+ color: #8995a0;
671
+ margin: 0;
672
+ }
673
+ .gallery-ratios {
674
+ display: flex;
675
+ gap: 7px;
676
+ flex-wrap: wrap;
677
+ }
678
+ .gallery-ratios button {
679
+ border-radius: 30px;
680
+ padding: 10px 16px;
681
+ background: transparent;
682
+ font-size: 11px;
683
+ }
684
+ .gallery-ratios button.active {
685
+ background: #25313f;
686
+ color: white;
687
+ border-color: #25313f;
688
+ }
689
+ .gallery-cards {
690
+ display: grid;
691
+ grid-template-columns: repeat(3, minmax(0, 1fr));
692
+ gap: 20px;
693
+ }
694
+ .topology-tile {
695
+ display: block;
696
+ text-align: left;
697
+ padding: 20px;
698
+ background: white;
699
+ border: 1px solid var(--line);
700
+ border-radius: 11px;
701
+ overflow: hidden;
702
+ transition:
703
+ transform 0.15s,
704
+ border-color 0.15s;
705
+ }
706
+ .topology-tile:hover {
707
+ transform: translateY(-3px);
708
+ border-color: #e8a188;
709
+ color: inherit;
710
+ box-shadow: 0 9px 22px #26314208;
711
+ }
712
+ .topology-tile.selected {
713
+ border-color: var(--accent);
714
+ }
715
+ .tile-heading {
716
+ display: flex;
717
+ align-items: center;
718
+ justify-content: space-between;
719
+ gap: 12px;
720
+ }
721
+ .tile-heading strong {
722
+ font:
723
+ 700 15px Manrope,
724
+ Arial;
725
+ color: #263442;
726
+ }
727
+ .tile-heading > span {
728
+ font-size: 10px;
729
+ color: #8a96a1;
730
+ white-space: nowrap;
731
+ }
732
+ .topology-tile img {
733
+ width: 100%;
734
+ height: 205px;
735
+ object-fit: contain;
736
+ margin: 17px 0 10px;
737
+ }
738
+ .tile-meta {
739
+ font-size: 10px;
740
+ color: #8c98a2;
741
+ margin-bottom: 15px;
742
+ }
743
+ .tile-capability {
744
+ font-size: 10px;
745
+ background: #f1f4f7;
746
+ color: #698071;
747
+ padding: 6px 8px;
748
+ border-radius: 4px;
749
+ }
750
+ .tile-action {
751
+ float: right;
752
+ color: #bf5837;
753
+ font-size: 10px;
754
+ padding: 6px 0;
755
+ }
756
+ .gallery-note {
757
+ font-size: 11px;
758
+ color: #8c97a1;
759
+ margin: 24px 0 0;
760
+ }
761
+ .gallery-empty {
762
+ text-align: center;
763
+ background: white;
764
+ border: 1px dashed #d5dce2;
765
+ border-radius: 10px;
766
+ padding: 55px 25px;
767
+ }
768
+ .gallery-empty > span {
769
+ font-size: 10px;
770
+ text-transform: uppercase;
771
+ letter-spacing: 1.7px;
772
+ color: #ba7257;
773
+ }
774
+ .gallery-empty h2 {
775
+ font:
776
+ 700 23px Manrope,
777
+ Arial;
778
+ }
779
+ .gallery-empty p {
780
+ font-size: 12px;
781
+ color: #8995a1;
782
+ line-height: 1.8;
783
+ }
784
+ #selection-bar {
785
+ display: flex;
786
+ align-items: center;
787
+ gap: 20px;
788
+ padding: 17px 25px;
789
+ background: #fff;
790
+ border-bottom: 1px solid var(--line);
791
+ flex-wrap: wrap;
792
+ }
793
+ #selected-image {
794
+ width: 68px;
795
+ height: 58px;
796
+ object-fit: contain;
797
+ }
798
+ .selected-identity {
799
+ flex: 1;
800
+ min-width: 160px;
801
+ }
802
+ .selected-identity small {
803
+ color: #bc6140;
804
+ font-size: 10px;
805
+ }
806
+ .selected-identity h1 {
807
+ font:
808
+ 700 18px Manrope,
809
+ Arial;
810
+ margin: 4px 0;
811
+ }
812
+ .selected-identity p {
813
+ font-size: 10px;
814
+ color: #8c98a1;
815
+ margin: 0;
816
+ }
817
+ .selection-actions {
818
+ display: flex;
819
+ gap: 8px;
820
+ flex-wrap: wrap;
821
+ }
822
+ .selection-actions button {
823
+ font-size: 11px;
824
+ }
825
+ #selected-availability {
826
+ width: 100%;
827
+ margin: 0;
828
+ text-align: right;
829
+ font-size: 10px;
830
+ color: #8a96a1;
831
+ }
832
+ #selected-availability:empty {
833
+ display: none;
834
+ }
835
+ @media (max-width: 1050px) {
836
+ .gallery-cards {
837
+ grid-template-columns: repeat(2, minmax(0, 1fr));
838
+ }
839
+ .gallery-toolbar {
840
+ align-items: flex-start;
841
+ flex-direction: column;
842
+ }
843
+ #selection-bar {
844
+ gap: 12px;
845
+ }
846
+ .selection-actions {
847
+ width: 100%;
848
+ }
849
+ .selected-identity {
850
+ min-width: 100px;
851
+ }
852
+ }
853
+ @media (max-width: 600px) {
854
+ #gallery-view {
855
+ padding: 26px 15px;
856
+ }
857
+ .gallery-hero {
858
+ padding-top: 6px;
859
+ }
860
+ .gallery-hero h1 {
861
+ font-size: 31px;
862
+ letter-spacing: -1px;
863
+ }
864
+ .gallery-hero > p {
865
+ font-size: 12px;
866
+ }
867
+ .workflow-steps {
868
+ gap: 8px;
869
+ flex-wrap: wrap;
870
+ font-size: 10px;
871
+ }
872
+ .workflow-steps i {
873
+ display: none;
874
+ }
875
+ .workflow-steps b {
876
+ margin-right: 5px;
877
+ }
878
+ .gallery-cards {
879
+ grid-template-columns: 1fr;
880
+ gap: 15px;
881
+ }
882
+ .gallery-ratios {
883
+ gap: 6px;
884
+ }
885
+ .gallery-ratios button {
886
+ padding: 9px 12px;
887
+ }
888
+ .topology-tile img {
889
+ height: 190px;
890
+ }
891
+ .gallery-toolbar {
892
+ padding-top: 22px;
893
+ }
894
+ .selected-identity h1 {
895
+ font-size: 16px;
896
+ }
897
+ #selection-bar {
898
+ padding: 14px;
899
+ }
900
+ .selection-actions button {
901
+ flex: 1;
902
+ white-space: nowrap;
903
+ padding: 9px 7px;
904
+ font-size: 10px;
905
+ }
906
+ #selected-availability {
907
+ text-align: left;
908
+ }
909
+ }
static/pe.js CHANGED
@@ -1,8 +1,9 @@
1
  import { createSimulator } from "./simulator.js";
 
 
2
  const $ = (s) => document.querySelector(s),
3
  $$ = (s) => [...document.querySelectorAll(s)];
4
- const editor = $("#editor"),
5
- comparison = $("#comparison");
6
  const STORAGE = "openpels-current-v1";
7
  const PREVIOUS_STORAGE = ["pe", "canvas", "current", "v1"].join("-");
8
  const sentLoads = new Map();
@@ -20,7 +21,108 @@ function notify(message) {
20
  $("#message").textContent = message;
21
  $("#message").classList.toggle("visible", !!message);
22
  }
23
- const simulator = createSimulator(notify);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  function saveLocal() {
25
  if (!current) return;
26
  try {
@@ -96,18 +198,33 @@ async function openStarter(s) {
96
  }
97
  }
98
  function showView(view) {
99
- const compare = view === "compare";
 
 
 
100
  $("#design-view").hidden = view !== "design";
101
- $("#compare-view").hidden = !compare;
102
  $("#simulator-view").hidden = view !== "simulator";
103
- if (view === "simulator") void simulator.show();
104
- $$("[data-view]").forEach((b) =>
105
- b.classList.toggle("active", b.dataset.view === view),
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  );
107
- if (compare && !comparison.src) comparison.src = comparison.dataset.src;
108
  }
109
  $$("[data-view]").forEach((b) => (b.onclick = () => showView(b.dataset.view)));
110
- $("#back-design").onclick = () => showView("design");
111
  $$("[data-ratio]").forEach(
112
  (b) =>
113
  (b.onclick = () => {
@@ -116,20 +233,8 @@ $$("[data-ratio]").forEach(
116
  }),
117
  );
118
  $("#compare-reference").onclick = () => {
119
- showView("compare");
120
- $("#compare-context").textContent =
121
- `Reference family for ${active?.name ?? "custom circuit"} · canvas is not simulated`;
122
- const sync = () =>
123
- comparison.contentWindow.postMessage(
124
- { type: "pe:family", ratio: active?.ratio ?? ratio },
125
- location.origin,
126
- );
127
- if (
128
- comparison.contentDocument?.URL !== "about:blank" &&
129
- comparison.contentDocument?.readyState === "complete"
130
- )
131
- sync();
132
- else comparison.addEventListener("load", sync, { once: true });
133
  };
134
  window.addEventListener("message", (event) => {
135
  if (event.origin !== location.origin || event.source !== editor.contentWindow)
@@ -225,6 +330,7 @@ $("#project-file").onchange = async (event) => {
225
  const f = event.target.files[0];
226
  event.target.value = "";
227
  if (!f) return;
 
228
  if (f.size > 10_000_000) {
229
  notify("This project exceeds the 10 MB browser import limit.");
230
  return;
@@ -280,6 +386,9 @@ const greet = () =>
280
  editor.addEventListener("load", greet);
281
  greet();
282
 
283
- if (location.hash === "#testbenches")
 
284
  history.replaceState(null, "", "#simulator");
285
- if (location.hash === "#simulator") showView("simulator");
 
 
 
1
  import { createSimulator } from "./simulator.js";
2
+ import { createGallery } from "./gallery.js";
3
+ import { createAnalysis } from "./analysis.js";
4
  const $ = (s) => document.querySelector(s),
5
  $$ = (s) => [...document.querySelectorAll(s)];
6
+ const editor = $("#editor");
 
7
  const STORAGE = "openpels-current-v1";
8
  const PREVIOUS_STORAGE = ["pe", "canvas", "current", "v1"].join("-");
9
  const sentLoads = new Map();
 
21
  $("#message").textContent = message;
22
  $("#message").classList.toggle("visible", !!message);
23
  }
24
+ let selectedTopology = null,
25
+ selectedRatio = 4,
26
+ currentView = "gallery";
27
+ let operatingPoint = { vout: 0.8, iout: 2 };
28
+ const gallery = createGallery({
29
+ report: notify,
30
+ onSelect: (entry, family) => chooseTopology(entry, family),
31
+ });
32
+ const analysis = createAnalysis(notify, (point) => {
33
+ if (
34
+ currentView !== "compare" ||
35
+ point.id !== selectedTopology?.id ||
36
+ point.ratio !== selectedRatio ||
37
+ !Number.isFinite(point.vout) ||
38
+ !Number.isFinite(point.iout)
39
+ )
40
+ return;
41
+ operatingPoint = { vout: point.vout, iout: point.iout };
42
+ renderSelection();
43
+ });
44
+ const simulator = createSimulator(notify, (topology, point) => {
45
+ if (currentView !== "simulator") return;
46
+ const entry = gallery.forSimulator(topology);
47
+ if (entry) {
48
+ selectedTopology = entry;
49
+ selectedRatio = 4;
50
+ if (
51
+ Number.isFinite(point.vout) &&
52
+ Number.isFinite(point.iout) &&
53
+ point.vout > 0 &&
54
+ point.iout > 0
55
+ )
56
+ operatingPoint = { vout: point.vout, iout: point.iout };
57
+ gallery.highlight(entry.id);
58
+ renderSelection();
59
+ }
60
+ });
61
+ function simulationAvailable() {
62
+ return (
63
+ !!selectedTopology?.simulator &&
64
+ selectedRatio === 4 &&
65
+ operatingPoint.vout >= 0.3 &&
66
+ operatingPoint.vout <= 1.1 &&
67
+ operatingPoint.iout >= 0.1 &&
68
+ operatingPoint.iout <= 40
69
+ );
70
+ }
71
+ function renderSelection() {
72
+ const entry = selectedTopology;
73
+ document.querySelector('[data-view="compare"]').disabled = !entry;
74
+ document.querySelector('[data-view="simulator"]').disabled =
75
+ !simulationAvailable();
76
+ if (!entry) return;
77
+ $("#selected-name").textContent = entry.name;
78
+ $("#selected-ratio").textContent =
79
+ `${selectedRatio}:1 reference · Vout ${operatingPoint.vout} V · Iout ${operatingPoint.iout} A`;
80
+ $("#selected-image").src = "./compare/assets/" + entry.image;
81
+ $("#selected-image").alt = entry.name + " circuit schematic";
82
+ $("#selected-simulate").disabled = !simulationAvailable();
83
+ $("#selected-simulate").textContent =
84
+ entry.simulationRelation === "related"
85
+ ? "Related simulation →"
86
+ : "Simulate →";
87
+ $("#selected-edit").disabled = !entry.starter;
88
+ $("#selected-edit").textContent =
89
+ entry.simulationRelation === "related"
90
+ ? "Edit related schematic"
91
+ : "Edit schematic";
92
+ $("#selected-availability").textContent = !entry.simulator
93
+ ? "Analytical model available. A validated NGSpice preset is not yet available for this topology."
94
+ : selectedRatio !== 4
95
+ ? "This preset currently supports simulation in the 4:1 family; the selected ratio has an analytical model."
96
+ : !simulationAvailable()
97
+ ? "This simulation preset supports 0.30–1.10 V output and 0.1–40 A. Adjust the analysis operating point to use it."
98
+ : (entry.simulationNote ?? "");
99
+ }
100
+ function chooseTopology(entry, family, view = "compare") {
101
+ if (!entry || !entry.ratios.includes(family)) {
102
+ notify("This topology has no qualified model for the selected ratio.");
103
+ return;
104
+ }
105
+ selectedTopology = entry;
106
+ selectedRatio = family;
107
+ gallery.highlight(entry.id);
108
+ renderSelection();
109
+ showView(view);
110
+ }
111
+ function referenceSelection() {
112
+ return { id: selectedTopology.id, ratio: selectedRatio, ...operatingPoint };
113
+ }
114
+ $("#back-gallery").onclick = () => showView("gallery");
115
+ $("#selected-analysis").onclick = () => showView("compare");
116
+ $("#selected-simulate").onclick = () => showView("simulator");
117
+ $("#selected-edit").onclick = () => {
118
+ const starter = starters.find(
119
+ (item) => item.id === selectedTopology?.starter,
120
+ );
121
+ if (starter) {
122
+ openStarter(starter);
123
+ showView("design");
124
+ }
125
+ };
126
  function saveLocal() {
127
  if (!current) return;
128
  try {
 
198
  }
199
  }
200
  function showView(view) {
201
+ if ((view === "compare" || view === "simulator") && !selectedTopology) return;
202
+ if (view === "simulator" && !simulationAvailable()) return;
203
+ currentView = view;
204
+ $("#gallery-view").hidden = view !== "gallery";
205
  $("#design-view").hidden = view !== "design";
206
+ $("#compare-view").hidden = view !== "compare";
207
  $("#simulator-view").hidden = view !== "simulator";
208
+ $("#selection-bar").hidden =
209
+ !selectedTopology || view === "gallery" || view === "design";
210
+ $(".file-actions").hidden = view !== "design";
211
+ if (view === "compare") {
212
+ $("#compare-context").textContent =
213
+ `${selectedTopology.name} · ${selectedRatio}:1 · selected reference model`;
214
+ analysis.show(referenceSelection());
215
+ }
216
+ if (view === "simulator")
217
+ simulator.show({
218
+ topology: selectedTopology.simulator,
219
+ ratio: selectedRatio,
220
+ ...operatingPoint,
221
+ });
222
+ $$("[data-view]").forEach((button) =>
223
+ button.classList.toggle("active", button.dataset.view === view),
224
  );
 
225
  }
226
  $$("[data-view]").forEach((b) => (b.onclick = () => showView(b.dataset.view)));
227
+ $("#back-design").onclick = () => showView("gallery");
228
  $$("[data-ratio]").forEach(
229
  (b) =>
230
  (b.onclick = () => {
 
233
  }),
234
  );
235
  $("#compare-reference").onclick = () => {
236
+ const entry = gallery.get(active?.model);
237
+ if (entry) chooseTopology(entry, active.ratio);
 
 
 
 
 
 
 
 
 
 
 
 
238
  };
239
  window.addEventListener("message", (event) => {
240
  if (event.origin !== location.origin || event.source !== editor.contentWindow)
 
330
  const f = event.target.files[0];
331
  event.target.value = "";
332
  if (!f) return;
333
+ showView("design");
334
  if (f.size > 10_000_000) {
335
  notify("This project exceeds the 10 MB browser import limit.");
336
  return;
 
386
  editor.addEventListener("load", greet);
387
  greet();
388
 
389
+ await gallery.load();
390
+ if (["#simulator", "#testbenches"].includes(location.hash)) {
391
  history.replaceState(null, "", "#simulator");
392
+ chooseTopology(gallery.get("xfly2p"), 4, "simulator");
393
+ } else if (location.hash === "#schematic") showView("design");
394
+ else showView(currentView);
static/simulator.js CHANGED
@@ -1,22 +1,61 @@
1
- /** One workbench, with an isolated same-origin view of the NGSpice controls. */
2
- export function createSimulator(report) {
3
  const frame = document.querySelector("#simulator");
4
  const status = document.querySelector("#simulator-status");
5
  let ready = false,
6
- starting = null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  window.addEventListener("message", (event) => {
8
  if (
9
  event.origin !== location.origin ||
10
  event.source !== frame.contentWindow
11
  )
12
  return;
13
- if (event.data?.type === "pe:simulator-ready") {
 
14
  ready = true;
15
  status.textContent = "";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  }
17
  });
18
- async function show() {
19
- if (ready) return;
 
 
 
 
20
  if (starting) return starting;
21
  status.textContent = "Connecting to NGSpice…";
22
  starting = (async () => {
 
1
+ /** Carry one selected gallery reference into the same-origin NGSpice controls. */
2
+ export function createSimulator(report, onSelection = () => {}) {
3
  const frame = document.querySelector("#simulator");
4
  const status = document.querySelector("#simulator-status");
5
  let ready = false,
6
+ starting = null,
7
+ pending = null,
8
+ sentKey = null,
9
+ awaitingKey = null;
10
+ const key = (value) =>
11
+ JSON.stringify([value.topology, value.ratio, value.vout, value.iout]);
12
+ function deliver() {
13
+ if (!ready || !pending || key(pending) === sentKey) return;
14
+ sentKey = key(pending);
15
+ awaitingKey = sentKey;
16
+ frame.contentWindow.postMessage(
17
+ { type: "pe:select-topology", ...pending },
18
+ location.origin,
19
+ );
20
+ }
21
  window.addEventListener("message", (event) => {
22
  if (
23
  event.origin !== location.origin ||
24
  event.source !== frame.contentWindow
25
  )
26
  return;
27
+ const data = event.data;
28
+ if (data?.type === "pe:simulator-ready") {
29
  ready = true;
30
  status.textContent = "";
31
+ deliver();
32
+ }
33
+ if (data?.type === "pe:simulator-busy")
34
+ status.textContent =
35
+ "Finishing the current run; your selected topology is next.";
36
+ if (data?.type === "pe:reference-applied" && key(data) === awaitingKey) {
37
+ awaitingKey = null;
38
+ status.textContent = "";
39
+ }
40
+ if (data?.type === "pe:simulation-point") {
41
+ if (awaitingKey !== null) return;
42
+ const reference = {
43
+ topology: data.topology,
44
+ ratio: 4,
45
+ vout: data.vout,
46
+ iout: data.iout,
47
+ };
48
+ pending = reference;
49
+ sentKey = key(reference);
50
+ onSelection(data.topology, reference);
51
  }
52
  });
53
+ async function show(reference = null) {
54
+ if (reference) pending = reference;
55
+ if (ready) {
56
+ deliver();
57
+ return;
58
+ }
59
  if (starting) return starting;
60
  status.textContent = "Connecting to NGSpice…";
61
  starting = (async () => {