整理 Buck 与 PMSM 完整源码、离线构建、校核测试和使用说明,采用 MIT 许可。 增加页首开源链接,支持推送 main 后自动测试、构建并发布到原计算器网址。
58 lines
3.6 KiB
JavaScript
58 lines
3.6 KiB
JavaScript
'use strict';
|
|
const test=require('node:test'),assert=require('node:assert/strict');
|
|
const accuracy=require('../src/buck-accuracy-engine.js');
|
|
|
|
// Frozen independent ngspice 46 fixtures, ideal synchronous Buck, Cout=2200 uF.
|
|
// Finest transient maximum step T/8192; error = calculator / SPICE - 1.
|
|
const fixtures=[
|
|
{id:'BV0238',input:{vin:15.458206322975457,fsw:135434.65583067952,L:2.772909819523137e-6,iavg:.6706499610693777,D:.16843321004416784,R:.011389252466845913,Ls:3.7991307740620917e-7,C:2.4599129374100604e-5},spicePp:.18100548398990135,calcPp:.1804832103684394,tier:1},
|
|
{id:'BV0360',input:{vin:23.77819098740816,fsw:10035.339421220124,L:2.204827760955319e-6,iavg:19.8589220456779,D:.1514770519249142,R:.0010550204811617732,Ls:1.0700912377331405e-5,C:.0005755906970465806},spicePp:3.053802599064099,calcPp:2.968762009731835,tier:3},
|
|
{id:'BV0393',input:{vin:23.58033286370337,fsw:19871.921402215958,L:7.643392540351488e-5,iavg:4.9898645399138335,D:.49259504235815255,R:.00546036210656166,Ls:9.357682751957326e-7,C:8.576272778451178e-6},spicePp:13.181964585282248,calcPp:12.71537067643087,tier:5},
|
|
{id:'BV0361',input:{vin:24.396451610997318,fsw:19865.651639178395,L:7.361992243747226e-5,iavg:5.05084116840735,D:.4983758472558111,R:.004618875935208053,Ls:1.0216104176826775e-6,C:2.269806856434103e-6},spicePp:16.564026064395136,calcPp:17.784641844026524,tier:'above5'}
|
|
];
|
|
function reference(input,options){return accuracy.reference({...input,drop:input.vin*(1-input.D),target:1},input,options);}
|
|
|
|
test('complete periodic reference agrees with independent SPICE across all four error bands',()=>{
|
|
for(const f of fixtures){
|
|
const ref=reference(f.input),estimate=accuracy.estimate(f.input,f.calcPp);
|
|
assert.equal(ref.valid,true,f.id);assert.ok(ref.closure<1e-10,f.id);
|
|
const observed=100*(f.calcPp/f.spicePp-1);
|
|
assert.ok(Math.abs(estimate.errorPercent-observed)<.05,f.id);
|
|
assert.equal(estimate.tier||(estimate.aboveFive?'above5':null),f.tier,f.id);
|
|
assert.equal(Math.sign(estimate.errorPercent),Math.sign(observed),f.id);
|
|
}
|
|
});
|
|
|
|
test('reference extrema converge and scale linearly when voltages and currents scale together',()=>{
|
|
for(const f of fixtures){
|
|
const coarse=reference(f.input),fine=reference(f.input,{samples:8192});
|
|
assert.ok(Math.abs(fine.pp/coarse.pp-1)<1e-6,f.id);
|
|
const scaled=reference({...f.input,vin:f.input.vin*1.2,iavg:f.input.iavg*1.2});
|
|
assert.ok(Math.abs(scaled.pp/(coarse.pp*1.2)-1)<1e-8,f.id);
|
|
}
|
|
});
|
|
|
|
test('coverage and invalid CCM references cannot produce an error band',()=>{
|
|
const input=fixtures[0].input;
|
|
for(const [key,[low,high]] of Object.entries(accuracy.limits)){
|
|
for(const value of [low*.99,high*1.01,NaN]){
|
|
const changed={...input,[key]:value};
|
|
assert.ok(accuracy.coverage(changed).includes(key));
|
|
assert.equal(accuracy.estimate(changed).tier,null);
|
|
}
|
|
}
|
|
const invalid={vin:24,fsw:20000,L:75e-6,iavg:5,D:.5,R:.001,Ls:10e-6,C:6.332573977646111e-6};
|
|
assert.equal(reference(invalid).valid,false);
|
|
assert.equal(accuracy.estimate(invalid).tier,null);
|
|
assert.throws(()=>reference({...input,R:0}));
|
|
assert.throws(()=>reference(input,{samples:128}));
|
|
});
|
|
|
|
test('guard margin assigns conservative bands and leaves the 5% boundary uncertain',()=>{
|
|
const input=fixtures[0].input,pp=reference(input).pp;
|
|
for(const sign of [-1,1])for(const [error,expected] of [[.94,1],[.98,3],[2.98,5],[4.9,5],[4.98,'boundary'],[5.02,'boundary'],[5.1,'above5']]){
|
|
const estimate=accuracy.estimate(input,pp*(1+sign*error/100));
|
|
assert.equal(estimate.tier||(estimate.aboveFive?'above5':estimate.boundary?'boundary':null),expected);
|
|
}
|
|
});
|