Spaces:
Running
Running
Download static/compare/recommend.js from minjiechen/OpenPELS: direct link, hf CLI and curl.
- Browser
- Download file 24.2 kB
-
https://huggingface.co/spaces/minjiechen/OpenPELS/resolve/main/static/compare/recommend.js
- Command line
-
hf download hf://spaces/minjiechen/OpenPELS/static/compare/recommend.js
-
curl -L -o recommend.js https://huggingface.co/spaces/minjiechen/OpenPELS/resolve/main/static/compare/recommend.js
24.2 kB
| /* Constraint screening and width optimization within the verified analytical library. */ | |
| (function(root){'use strict'; | |
| const specs=Object.freeze({buck_stacked:{ratio:2,caps:1,windings:2,magnetics:'inverse-coupled'},si2:{ratio:2,caps:1,windings:2,magnetics:'inverse-coupled'},buck2:{ratio:2,caps:0,windings:2,magnetics:'inverse-coupled'},rsc2:{ratio:2,caps:2,windings:2,magnetics:'uncoupled resonant'},sp2:{ratio:2,caps:2,windings:0,magnetics:'none'},xfly2p:{ratio:4,caps:2,windings:2,magnetics:'coupled'},xfly4p:{ratio:4,caps:4,windings:2,magnetics:'coupled'},'3lbuck':{ratio:4,ratios:[2,4],caps:2,windings:2,magnetics:'coupled'},'2sbuck':{ratio:4,caps:4,windings:2,magnetics:'coupled'},buck:{ratio:2,caps:0,windings:2,magnetics:'coupled'}}); | |
| const excitation=Object.freeze({buck2:{level:1,pulses:1},buck:{level:1,pulses:1},xfly2p:{level:.5,pulses:1},xfly4p:{level:.5,pulses:2},'3lbuck':{level:.5,pulses:2},'2sbuck':{level:.5,pulses:1}}); | |
| function familyIds(ratio){return Object.keys(excitation).filter(id=>(specs[id].ratios??[specs[id].ratio]).includes(ratio))} | |
| // Dedicated reference eligibility; the winding-based optimizer keeps its own domain. | |
| function referenceFamilyIds(ratio){const ids=familyIds(ratio);return ratio===2?[...ids,'sp2','rsc2','si2','buck_stacked']:ids} | |
| function ripplePoint(id,p){const ldm=p.lk_nh*1e-9+2*p.lm_uh*1e-6;if(id==='3lbuck'&&p.ratio===2)return {ripple_model:'ideal_midpoint_hold',phase_ripple_pp:0,phase_ripple_percent:0,effective_duty:1,gate_duty:.5,effective_frequency:0,ldm,residual_ripple_unmodeled:true,condition:'Ideal balanced flying capacitor holds winding input at Vin/2 = Vout; ideal winding voltage and ripple are zero. Real capacitor-voltage ripple, mismatch and timing effects are not quantified; coupling is not the cause of this ideal cancellation.'};const e=excitation[id],pp=p.vin*e.level/(4*p.fs_mhz*1e6*e.pulses*ldm);return {ripple_model:'complementary_excitation',phase_ripple_pp:pp,phase_ripple_percent:100*pp/(p.io/2),effective_duty:.5,effective_frequency:p.fs_mhz*1e6*e.pulses,ldm,condition:'Balanced 0/Vstep winding inputs, complementary 50% effective duty, matched inverse coupling; first-order phase-current ripple, not measured zero ripple.'}} | |
| const defaults={ratio:4,vin:3.3,vout:null,voltage_mode:'input_output',load_mode:'current',io:2,pout_w:1.65,fs_mhz:10,vgs:3.3,budget_mode:'area',width_mm:360,die_mm2:1,utilization:.5,ron_area_mohm_mm2:1,cap_uf:4,max_caps:4,max_windings:2,rc_mohm:20,rl_mohm:38,max_drop_percent:10,lk_nh:50,lm_uh:1,max_phase_ripple_percent:5,objective:'loss'}; | |
| function operatingPoint(input){const p={...defaults,...input};if(!['input_output','output_ratio'].includes(p.voltage_mode))throw Error('Choose a valid voltage-input mode');if(p.vout==null)p.vout=p.vin/p.ratio;if(p.voltage_mode==='output_ratio')p.vin=p.ratio*p.vout;for(const k of ['vin','vout','ratio'])if(!Number.isFinite(p[k])||p[k]<=0)throw Error(k+' must be positive');if(!['current','power'].includes(p.load_mode))throw Error('Choose current or power as the output-load input');if(p.load_mode==='power'){if(!Number.isFinite(p.pout_w)||p.pout_w<=0)throw Error('Output load power must be positive');p.io=p.pout_w/p.vout}if(!Number.isFinite(p.io)||p.io<=0)throw Error('Output load current must be positive');p.pout_w=p.vout*p.io;const nominal=p.vin/p.ratio;return {parameters:p,requested_vout:p.vout,output_current:p.io,output_power:p.pout_w,load_resistance:p.vout/p.io,nominal_vout:nominal,requested_ratio:p.vin/p.vout,voltage_ratio_match:Math.abs(p.vout-nominal)<=1e-6*Math.max(p.vout,nominal)}} | |
| function availableWidth(p,technology){ | |
| if(p.budget_mode==='width')return p.width_mm; | |
| if(!Number.isFinite(p.ron_area_mohm_mm2)||p.ron_area_mohm_mm2<=0)return null; | |
| return technology.reference.ron*p.die_mm2*p.utilization/(p.ron_area_mohm_mm2*1e-3); | |
| } | |
| function droopReason(limit){return 'Estimated open-loop droop exceeds '+limit+'% even at full FET budget'} | |
| function optimizeWidth(at, maxWidth, maxDropPercent) { | |
| // Search total width on the existing four-decade grid, including the full budget. | |
| const grid = Array.from({length:65}, (_,i) => maxWidth*10**(-4+4*i/64)); | |
| let best = at(grid[0]), bestIndex = 0; | |
| for (let i=1; i<grid.length; i++) { | |
| const point = at(grid[i]); | |
| if (point.loss < best.loss) { | |
| best = point; | |
| bestIndex = i; | |
| } | |
| } | |
| let lo = Math.log(grid[Math.max(0,bestIndex-1)]); | |
| let hi = Math.log(grid[Math.min(64,bestIndex+1)]); | |
| for (let i=0; i<50; i++) { | |
| const a = lo+(hi-lo)/3, b = hi-(hi-lo)/3; | |
| const left = at(Math.exp(a)), right = at(Math.exp(b)); | |
| if (left.loss < best.loss) best = left; | |
| if (right.loss < best.loss) best = right; | |
| if (left.loss < right.loss) hi = b; | |
| else lo = a; | |
| } | |
| if (best.drop_percent <= maxDropPercent) return {best,meetsDroop:true}; | |
| // For these models increasing width reduces droop. Find the smallest | |
| // feasible width above the unconstrained optimum. | |
| if (at(maxWidth).drop_percent > maxDropPercent) return {best,meetsDroop:false}; | |
| let lower = best.width_mm, upper = maxWidth; | |
| for (let i=0; i<60; i++) { | |
| const mid = (lower+upper)/2; | |
| if (at(mid).drop_percent > maxDropPercent) lower = mid; | |
| else upper = mid; | |
| } | |
| return {best:at(upper),meetsDroop:true}; | |
| } | |
| function optimizeFeasibleWidth(at, width, valid) { | |
| // Find and refine feasible sections when droop and operating constraints | |
| // may create multiple intervals in the width domain. | |
| const grid = Array.from({length:257}, (_,i) => at(width*10**(-4+4*i/256))); | |
| let best = null; | |
| const consider = r => { if (valid(r) && (!best || r.loss<best.loss)) best=r; }; | |
| grid.forEach(consider); | |
| for (let i=1; i<grid.length; i++) { | |
| const left=grid[i-1], right=grid[i]; | |
| if (valid(left)===valid(right)) continue; | |
| let a=left.width_mm,b=right.width_mm; | |
| for(let j=0;j<40;j++) { | |
| const r=at((a+b)/2); | |
| if(valid(r)===valid(left)) a=r.width_mm; else b=r.width_mm; | |
| } | |
| consider(at(valid(left)?a:b)); | |
| } | |
| for(let i=1;i<grid.length-1;i++) { | |
| if(grid[i].loss>Math.min(grid[i-1].loss,grid[i+1].loss)) continue; | |
| let a=grid[i-1].width_mm,b=grid[i+1].width_mm; | |
| for(let j=0;j<40;j++) { | |
| const l=at(a+(b-a)/3),r=at(b-(b-a)/3); | |
| consider(l); consider(r); | |
| if(l.loss<r.loss)b=r.width_mm;else a=l.width_mm; | |
| } | |
| } | |
| return {best:best??grid.at(-1),meetsDroop:!!best}; | |
| } | |
| function recommendSwitchedCap(input, settings, base, meta, technology) { | |
| const op = operatingPoint(input), p = op.parameters; | |
| const resonant = meta.id === 'rsc2', spec = specs[meta.id]; | |
| if (p.ratio !== 2) throw Error('SP-SC is qualified at fixed 2:1 only.'); | |
| if (!['area','width'].includes(p.budget_mode) || !(resonant?['loss','capacitors','magnetics']:['loss','capacitors']).includes(p.objective)) throw Error('Choose a supported silicon budget and priority.'); | |
| if (p.budget_mode === 'area' && !(p.die_mm2 > 0 && p.utilization > 0 && p.utilization <= 1 && p.ron_area_mohm_mm2 > 0)) | |
| throw Error('Enter positive die area and Ron × area, and a usable transistor fraction greater than 0 and at most 1.'); | |
| const width = availableWidth(p,technology); | |
| if (!Number.isFinite(width) || width <= 0) throw Error('Enter a positive silicon budget.'); | |
| if (!Number.isInteger(p.max_caps) || p.max_caps < 0 || !Number.isFinite(p.max_drop_percent) || p.max_drop_percent < 0) | |
| throw Error('Enter a nonnegative integer capacitor limit and a nonnegative droop limit.'); | |
| const rsBudget = technology.reference.ron * 12 / width; | |
| const row = {id:meta.id, name:meta.name, short:meta.short, asset:meta.asset, native_ratio:2, | |
| reference_match:true, allocation_reference_ratio:2, capacitors:spec.caps, windings:spec.windings, | |
| magnetics:spec.magnetics, status:'excluded', reasons:[], available_width_mm:width, | |
| reference_note:'Fixed 2:1, 50% duty, matched flying capacitors and equal eight-device allocation.'}; | |
| if (row.capacitors > p.max_caps) row.reasons.push('Requires '+row.capacitors+' flying capacitors; limit is '+p.max_caps); | |
| if (resonant && (!Number.isInteger(p.max_windings) || p.max_windings<0 || !Number.isFinite(p.tank_nh) || p.tank_nh<=0)) | |
| throw Error('Enter positive tank inductance and a nonnegative integer winding limit.'); | |
| if (resonant && p.max_windings<spec.windings) row.reasons.push('Requires two uncoupled inductors.'); | |
| if (!(p.cap_uf > 0)) row.reasons.push('A positive flying-capacitor budget is required.'); | |
| let deviceReport = null; | |
| if (p.cap_uf > 0) { | |
| const deviceInputs = {...settings, vin:p.vin, io:p.io, fs_mhz:p.fs_mhz, | |
| cap_uf:p.cap_uf, rc_mohm:p.rc_mohm, rl_mohm:resonant?p.rl_mohm:0, ...(resonant?{tank_nh:p.tank_nh}:{})}; | |
| function at(usedWidth) { | |
| const t = technology.example([base],{...deviceInputs,width_mm:usedWidth}); | |
| const r = t.rows[0]; | |
| return {width_mm:usedWidth, loss:r.partial_loss, drop_percent:100*p.io*r.req/r.vx, tank:r.tank}; | |
| } | |
| // A constant capacitor count leaves the width minimizer unchanged under either priority. | |
| const {best,meetsDroop} = resonant ? optimizeFeasibleWidth(at,width,r=>r.tank.damping_ratio<.8 && r.drop_percent<=p.max_drop_percent) : optimizeWidth(at,width,p.max_drop_percent); | |
| if (!meetsDroop) row.reasons.push(resonant?'No width within the budget meets the droop and damping limits.':droopReason(p.max_drop_percent)); | |
| if (resonant) { | |
| const clockRatio = p.fs_mhz*1e6/best.tank.natural_frequency_hz; | |
| if (clockRatio < .65 || clockRatio > 1.35) | |
| row.reasons.push('Set the clock within 0.65–1.35 times the LC natural frequency.'); | |
| row.sizing_constraint = 'Equal-area constrained optimum'; | |
| row.reference_note = 'Matched series-RLC legs with 50% commands. The width search keeps all eight device areas equal. Core and commutation losses require device-specific data.'; | |
| } | |
| deviceReport = technology.example([base],{...deviceInputs,width_mm:best.width_mm}); | |
| const r = deviceReport.rows[0], delivered = r.vo*p.io; | |
| // The technology example describes one representative phase. Export both | |
| // identical phases to match the eight-device allocation in the workbench. | |
| const representativePhase = r.device; | |
| r.device = ['S','Q'].flatMap(prefix => representativePhase.map((device,i) => ({ | |
| ...device, id:prefix+(i+1), | |
| }))); | |
| r.delivered_w = delivered > 0 ? delivered : null; | |
| r.efficiency = delivered > 0 ? delivered/(delivered+r.partial_loss) : null; | |
| r.efficiency_includes_coss = r.poss !== null; | |
| if (r.efficiency === null) row.reasons.push('No positive delivered-voltage estimate at the entered load.'); | |
| Object.assign(row,best,{rs:deviceReport.rs, req:r.req, rout:r.req, req_pu:r.req/rsBudget, | |
| req_used_width_pu:r.req/deviceReport.rs, rout_over_rload:r.req/op.load_resistance, | |
| estimated_open_loop_vout:r.vo, cf:r.cf, ...(r.sp2_loss?{sp2_loss:r.sp2_loss}:{}), parts:{fet:r.fet,cap:r.cap,ind:r.ind,fsl:resonant?r.req:r.fet+r.cap,ssl:r.ssl,hc:r.hc}, | |
| conduction_power:r.conduction_power, gate_power:deviceReport.gate_power, coss_power:r.poss, | |
| efficiency:r.efficiency, delivered_w:r.delivered_w, device:r.device, | |
| used_die_mm2:p.budget_mode==='area'?best.width_mm*p.ron_area_mohm_mm2*1e-3/technology.reference.ron:null}); | |
| } | |
| const eligible = row.reasons.length ? [] : [Object.assign(row,{status:'eligible',rank:1})]; | |
| return {parameters:{...p,...settings,rl_mohm:resonant?p.rl_mohm:null}, available_width_mm:width, rs_budget:rsBudget, calibrated:true, | |
| requested_vout:op.requested_vout, output_current:op.output_current, output_power:op.output_power, load_resistance:op.load_resistance, | |
| requested_ratio:op.requested_ratio, voltage_ratio_match:op.voltage_ratio_match, nominal_vout:op.nominal_vout, | |
| rows:[row], eligible, winner:eligible[0]??null, native_models:1, deviceReport, | |
| operating_point:deviceReport?.rows[0]?.operating_point??null, | |
| scope:resonant?'Fixed 2:1 resonant SC. Exact matched periodic RLC. Equal-area constrained optimum within droop and damping limits.':'Fixed 2:1 SP-SC reference. Exact periodic RC; matched flying capacitors, ideal timing and equal per-switch allocation. Total width is optimized subject to the budget and droop ceiling. The capacitance goes to two flying capacitors. Coss requires effective energy data. Driver quiescent power, Cin/Cout ESR, dead time, overlap, reverse recovery, and layout parasitics are outside the model.'}; | |
| } | |
| function recommendSwitchedInductor(input, settings, base, meta, technology) { | |
| const p={...defaults,voltage_mode:'duty_cycle',...input}; | |
| if (!['output_voltage','duty_cycle'].includes(p.voltage_mode) || | |
| ![p.vin,p.io].every(v=>Number.isFinite(v)&&v>0) || | |
| (p.voltage_mode==='output_voltage' ? p.si_duty!=null || !(p.si_target_v>0) : p.si_target_v!=null)) | |
| throw Error('Enter positive Vin and load, with only the selected voltage target or duty command.'); | |
| if (p.ratio!==2 || !['loss','capacitors','magnetics'].includes(p.objective)) | |
| throw Error('Choose a priority for the 2:1 switched inductor reference.'); | |
| const width=availableWidth(p,technology); | |
| if (!['width','area'].includes(p.budget_mode) || !Number.isFinite(width) || width<=0 || | |
| (p.budget_mode==='area' && !(p.utilization>0 && p.utilization<=1))) | |
| throw Error('Enter a positive silicon budget and a usable transistor fraction in (0, 1].'); | |
| if (!(p.si_coupling>=0 && p.si_coupling<=.85 && | |
| p.si_l_nh>0 && p.cap_uf>0 && p.fs_mhz>0 && p.rc_mohm>=0 && p.rl_mohm>=0 && | |
| p.max_drop_percent>=0 && p.max_phase_ripple_percent>=0) || | |
| !['max_caps','max_windings'].every(k=>Number.isInteger(p[k])&&p[k]>=0)) | |
| throw Error('Check duty, coupling, positive component values and nonnegative design limits.'); | |
| const deviceInputs={...settings,vin:p.vin,io:p.io,fs_mhz:p.fs_mhz,cap_uf:p.cap_uf, | |
| rc_mohm:p.rc_mohm,rl_mohm:p.rl_mohm,si_duty:p.si_duty,si_target_v:p.si_target_v, | |
| voltage_mode:p.voltage_mode,si_l_nh:p.si_l_nh,si_coupling:p.si_coupling}; | |
| const stacked = meta.id === 'buck_stacked'; | |
| const bounded = p.voltage_mode==='output_voltage'; | |
| const calculate = width_mm => technology.example([base],{...deviceInputs,width_mm}); | |
| const isFeasible = point => point?.operating_point.solver.valid | |
| && 200*point.si.phase_ripple_per_amp<=p.max_phase_ripple_percent; | |
| const at=width_mm=>{ | |
| try { | |
| const report=calculate(width_mm), r=report.rows[0]; | |
| const drop_percent=100*p.io*r.si.droop_resistance/r.vx; | |
| const feasible=(!bounded || isFeasible(r)) && drop_percent<=p.max_drop_percent; | |
| return {width_mm,loss:r.partial_loss,drop_percent,report,feasible}; | |
| } catch (error) { | |
| if (!bounded || !(error instanceof RangeError)) throw error; | |
| return {width_mm,loss:Infinity,drop_percent:Infinity,feasible:false}; | |
| } | |
| }; | |
| let {best,meetsDroop}=bounded?optimizeFeasibleWidth(at,width,r=>r.feasible):optimizeWidth(at,width,p.max_drop_percent); | |
| const targetFeasible=!!best?.feasible; | |
| if (bounded&&!best.report) { | |
| const fullReport=calculate(width),r=fullReport.rows[0]; | |
| best={width_mm:width,loss:r.partial_loss,drop_percent:100*(r.vx-r.vo)/r.vx,report:fullReport}; | |
| } | |
| if (bounded&&!targetFeasible) meetsDroop=best.drop_percent<=p.max_drop_percent; | |
| const deviceReport=best.report, r=deviceReport.rows[0], si=r.si, command=r.operating_point; | |
| const requested=command.target??r.vx, rsBudget=technology.reference.ron*12/width; | |
| const phasePercent=200*si.phase_ripple_per_amp; | |
| const reasons=[]; | |
| if (p.max_caps<1) reasons.push('Requires one output capacitor.'); | |
| if (p.max_windings<2) reasons.push('Requires two inverse-coupled windings.'); | |
| if (si.min_phase_per_amp<=0) reasons.push('The predicted winding current crosses zero. Positive-current CCM is required.'); | |
| if (phasePercent>p.max_phase_ripple_percent) reasons.push('Predicted phase ripple exceeds the entered limit.'); | |
| if (!meetsDroop) reasons.push(droopReason(p.max_drop_percent)); | |
| r.delivered_w=r.vo>0?r.vo*p.io:null; | |
| r.efficiency=r.delivered_w===null||si.min_phase_per_amp<=0?null:r.delivered_w/(r.delivered_w+r.partial_loss); | |
| r.efficiency_includes_coss=r.poss!==null; | |
| if (r.vo<=0) reasons.push('The first-order model predicts nonpositive delivered voltage.'); | |
| if (bounded&&!targetFeasible&&!reasons.length) reasons.push('No reachable positive-current CCM design fits the selected constraints.'); | |
| const row={id:meta.id,name:meta.name,short:meta.short,asset:meta.asset,native_ratio:2,reference_match:true, | |
| ...specs[meta.id],status:reasons.length?'excluded':'eligible',reasons,rank:reasons.length?null:1, | |
| width_mm:best.width_mm,available_width_mm:width,rs:deviceReport.rs,req:r.req,rout:r.req,req_pu:r.req/rsBudget, | |
| req_used_width_pu:r.req/deviceReport.rs,rout_over_rload:r.req/(requested/p.io),drop_percent:best.drop_percent,droop_resistance:si.droop_resistance, | |
| loss:best.loss,parts:{fet:r.fet,cap:r.cap,ind:r.ind,fsl:r.req,ssl:0,hc:0},cf:r.cf,si, | |
| conduction_power:r.conduction_power,gate_power:deviceReport.gate_power,coss_power:r.poss, | |
| efficiency:r.efficiency,...(stacked?{efficiency_includes_coss:r.efficiency_includes_coss}:{}),delivered_w:r.delivered_w,device:r.device,estimated_open_loop_vout:r.vo, | |
| phase_ripple_pp:p.io*si.phase_ripple_per_amp,phase_ripple_percent:phasePercent, | |
| operating_waveforms:{ | |
| winding_average_a:p.io/2,winding_rms_a:p.io*Math.sqrt(si.winding_weight), | |
| winding_valley_a:p.io*si.min_phase_per_amp, | |
| channel_rms_a:(stacked?[si.high_weight,si.high_weight,si.low_weight,si.low_weight,si.high_weight,si.high_weight,si.low_weight,si.low_weight]:[si.high_weight,si.low_weight,si.high_weight,si.low_weight]).map(w=>p.io*Math.sqrt(w)), | |
| channel_average_a:(stacked?[command.duty,command.duty,command.duty-1,command.duty-1,command.duty,command.duty,command.duty-1,command.duty-1]:[command.duty,command.duty-1,command.duty,command.duty-1]).map(d=>d*p.io/2), | |
| output_cap_rms_a:p.io*Math.sqrt(si.capacitor_weight), | |
| ideal_winding_voltage_v:[(1-command.duty)*p.vin,-command.duty*p.vin], | |
| ideal_switch_blocking_v:stacked?p.vin/2:p.vin, | |
| }, | |
| capacitor_ripple_vpp:p.io*si.output_ripple_per_amp/(16*p.fs_mhz*1e6*r.cf), | |
| used_die_mm2:p.budget_mode==='area'?best.width_mm*p.ron_area_mohm_mm2*1e-3/technology.reference.ron:null}; | |
| const eligible=reasons.length?[]:[row]; | |
| return {parameters:{...p,...settings},available_width_mm:width,rs_budget:rsBudget,calibrated:true, | |
| input_voltage:p.vin,requested_vout:requested,output_current:p.io,output_power:requested*p.io, | |
| load_resistance:requested/p.io,requested_ratio:p.vin/requested,voltage_ratio_match:true, | |
| nominal_vout:p.vin/p.ratio,nominal_ratio:p.ratio, | |
| loaded_ratio:command.loadedGain>0?1/command.loadedGain:null,operating_point:command,rows:[row],eligible,winner:eligible[0]??null,native_models:1,deviceReport, | |
| scope:stacked?'Eight-device stacked buck. Half-input effective gate swing and Coss energy. Positive winding-current CCM.':'Two-phase inverse-coupled buck. Duty-regulated positive-current CCM with piecewise-linear winding currents and first-order loss.'}; | |
| } | |
| function recommend(input,data,engine,technology){const op=operatingPoint(input),p=op.parameters;for(const k of ['ratio','vin','io','fs_mhz','vgs','width_mm','die_mm2','lk_nh','lm_uh'])if(!Number.isFinite(p[k])||p[k]<=0)throw Error(k+' must be positive');for(const k of ['cap_uf','max_caps','max_windings','rc_mohm','rl_mohm','max_drop_percent','max_phase_ripple_percent'])if(!Number.isFinite(p[k])||p[k]<0)throw Error(k+' must be nonnegative');if(![2,4,6,8,16].includes(p.ratio))throw Error('Choose a supported ratio');if(!['width','area'].includes(p.budget_mode)||!['loss','capacitors','magnetics'].includes(p.objective))throw Error('Choose a budget mode and objective');if(!Number.isInteger(p.max_caps)||!Number.isInteger(p.max_windings))throw Error('Component limits must be integers');if(!Number.isFinite(p.utilization)||p.utilization<=0||p.utilization>1)throw Error('Usable die fraction must be in (0,1]'); | |
| const calibrated=p.budget_mode==='width'||Number.isFinite(p.ron_area_mohm_mm2)&&p.ron_area_mohm_mm2>0,Wmax=availableWidth(p,technology),fs=p.fs_mhz*1e6,m=1/p.ratio,vo=p.vin*m; | |
| if(calibrated&&(!Number.isFinite(Wmax)||Wmax<=0))throw Error('Invalid area/width budget'); | |
| const rows=data.catalog.filter(c=>familyIds(p.ratio).includes(c.id)).map(c=>{const s=specs[c.id],r={id:c.id,name:c.name,short:c.short,native_ratio:p.ratio,reference_match:true,asset:c.asset,allocation_reference_ratio:['buck2','sp2'].includes(c.id)?2:4,status:'excluded',reasons:[]};if(!s){r.status='unmodeled';r.reasons=['No verified loss model for recommendation'];return r}Object.assign(r,{capacitors:s.caps,windings:s.windings,magnetics:s.magnetics},ripplePoint(c.id,p));if(r.phase_ripple_percent>=200)r.reasons.push('Predicted phase-current ripple leaves the assumed CCM region');if(r.phase_ripple_percent>p.max_phase_ripple_percent)r.reasons.push('Predicted phase ripple exceeds '+p.max_phase_ripple_percent+'% of average phase current');if(!engine.valid(c.id,m))r.reasons.push(c.id==='sp2'?'Fixed 2:1 conversion only':'Outside the verified duty range');if(s.windings>p.max_windings)r.reasons.push('Requires '+s.windings+' power windings; limit is '+p.max_windings);if(s.caps>p.max_caps)r.reasons.push('Requires '+s.caps+' flying/clamp capacitors; limit is '+p.max_caps);if(s.caps&&p.cap_uf<=0)r.reasons.push('A positive flying/clamp capacitor budget is required');if(!calibrated)r.reasons.push('Enter positive Ron × area (mΩ·mm²)');if(r.reasons.length)return r; | |
| if(!op.voltage_ratio_match)r.reasons.push('Requested Vout does not match Vin/'+p.ratio+' at the cancellation point');if(r.reasons.length)return r; | |
| const cf=s.caps?p.cap_uf*1e-6/s.caps:null; | |
| function at(width){const rs=technology.reference.ron*12/width,v=engine.evaluate(c.id,m,{rs,rc:p.rc_mohm/1000,rl:p.rl_mohm/1000,cf:cf??1,fs}),gate=p.vgs*fs*technology.fom.gate*width/technology.reference.ron,loss=p.io*p.io*v.total+gate;return {width_mm:width,rs,req:v.total,rout:v.total,rout_over_rload:v.total/op.load_resistance,req_pu:v.total/(technology.reference.ron*12/Wmax),req_used_width_pu:v.total/rs,conduction_power:p.io*p.io*v.total,gate_power:gate,loss,drop_percent:100*p.io*v.total/vo,estimated_open_loop_vout:vo-p.io*v.total,cf,parts:v}} | |
| const {best,meetsDroop}=optimizeWidth(at,Wmax,p.max_drop_percent); | |
| if(!meetsDroop)r.reasons.push(droopReason(p.max_drop_percent)); | |
| Object.assign(r,best,{used_die_mm2:p.budget_mode==='area'?best.width_mm*p.ron_area_mohm_mm2*1e-3/technology.reference.ron:null,available_width_mm:Wmax,reference_note:'Nominal coupled-inductor cancellation point at '+p.ratio+':1; loss allocation remains fixed at '+(['buck2','sp2'].includes(c.id)?2:4)+':1'});r.status=r.reasons.length?'excluded':'eligible';return r}); | |
| const eligible=rows.filter(r=>r.status==='eligible');eligible.sort((a,b)=>{if(p.objective==='capacitors'&&a.capacitors!==b.capacitors)return a.capacitors-b.capacitors;if(p.objective==='magnetics'&&a.windings!==b.windings)return a.windings-b.windings;return a.loss-b.loss});eligible.forEach((r,i)=>r.rank=i+1);return {parameters:p,available_width_mm:Wmax,rs_budget:calibrated?technology.reference.ron*12/Wmax:null,calibrated,requested_vout:op.requested_vout,output_current:op.output_current,output_power:op.output_power,load_resistance:op.load_resistance,requested_ratio:op.requested_ratio,voltage_ratio_match:op.voltage_ratio_match,nominal_vout:vo,eligible,rows,winner:eligible[0]??null,native_models:rows.filter(r=>r.reference_match).length,scope:'Coupled-inductor cancellation-point shortlist only. First-order phase ripple is screened with Ldm=Lk+2Lm, balanced complementary 50% effective excitation or the ideal 3L 2:1 midpoint-hold state. Finite capacitor ripple, mismatch, losses and timing errors can break ideal cancellation. Loss ranking remains flat-current FSL/SSL plus gate drive; Coss, ripple-loss corrections, core loss, saturation, layout, startup and control/headroom are not qualified. Fixed per-device allocations; total width optimized. One gate-charge event per device per period assumed. Budgets cover power FETs, flying/clamp capacitors and power windings; drivers/Cin/Cout are outside these budgets.'};} | |
| const api={recommend,recommendSwitchedCap,recommendSwitchedInductor,specs,defaults,excitation,familyIds,referenceFamilyIds,availableWidth,ripplePoint,operatingPoint};root.OpenPELSRecommendation=api;if(typeof module!=='undefined')module.exports=api; | |
| })(typeof window!=='undefined'?window:globalThis); | |