AgentFEM-Pipe-Components / source /check_all_browser.cjs
HaomingLuo's picture
Release validated Pipe Assembly Lab v1.0
55acf7a verified
Raw History Blame Contribute Delete
1.52 kB
const fs=require('node:fs'),path=require('node:path'),{solve}=require('../web/solver.js');
const root=path.join(__dirname,'..'),rows=['development','heldout_spatial'].flatMap(s=>fs.readFileSync(path.join(root,'data/assemblies',s+'.jsonl'),'utf8').trim().split('\n').map(JSON.parse));
const cache={},get=id=>cache[id]||(cache[id]=JSON.parse(fs.readFileSync(path.join(root,'web/data',id+'.json'))));
let maxF=0,maxQ=0,maxR=0,maxTime=0;const times=[];
for(const row of rows){const r=solve({components:row.component_ids.map(get),rolls:row.rolls_rad,deltaT:row.delta_temperature_K,gravity:row.gravity_m_s2,supports:row.supports});
const fq=Math.max(...r.frequency.map((v,i)=>Math.abs(v/row.frequencies_Hz[i]-1)));
const qe=Math.hypot(...r.q.map((v,i)=>v-row.port_displacements_SI[i]))/Math.max(1e-12,Math.hypot(...row.port_displacements_SI));
maxF=Math.max(maxF,fq);maxQ=Math.max(maxQ,qe);maxR=Math.max(maxR,r.residual);maxTime=Math.max(maxTime,r.elapsedMs);times.push(r.elapsedMs);
if(fq>1e-6||qe>1e-6)throw Error(JSON.stringify({id:row.id,fq,qe,js:r.frequency,py:row.frequencies_Hz}));}
times.sort((a,b)=>a-b);
const report={cases:rows.length,frequency_max_relative_error:maxF,displacement_max_relative_error:maxQ,max_equilibrium_residual:maxR,median_ms:times[Math.floor(times.length/2)],p95_ms:times[Math.floor(times.length*.95)],max_ms:maxTime,runtime:process.version,platform:process.platform,passed:true};
fs.writeFileSync(path.join(root,'reports/browser_campaign.json'),JSON.stringify(report,null,2));console.log(report);