0hmX/am3352
This code suite comprises TypeScript scripts that analyze, verify, and assemble complex DDR memory interface hardware, focusing on physical routing, via and pad placement, electrical clearance, and physical constraints, often involving precise geometric calculations and consistent provenance tracking.
- Version
- 1.0.5
- License
- unset
- Stars
- 0
scripts/experiment-ddr-d3-merged-antipad.ts
/** Existing Flatten BooleanOperations subtraction permits merged antipads; no new polygon algorithm. */
import F from '@flatten-js/core'
import{readFileSync,writeFileSync,mkdirSync}from'node:fs'
import{resolve}from'node:path'
import{objectHash}from'./improve-ddr-a9-power-launches'
import{verifyDdrSystemCopper}from'./check-ddr-system-copper'
import{refreshDdrPlaneContacts}from'./ddr-plane-contact-audit'
const parent=resolve('dist/ddr-twelve-byte0-partial-timing'),out=resolve('dist/ddr-d3-merged-antipad-experiment'),read=(n:string)=>JSON.parse(readFileSync(`${parent}/${n}`,'utf8')),c=read('candidate.circuit.json'),report=read('report.json'),host=read('host-bundle.json'),input=read('routing-input.json'),power=c.find((e:any)=>e.type==='pcb_copper_pour'&&e.layer==='inner3'),poly=(vs:any[])=>new F.Polygon(vs.map(p=>[p.x,p.y])),vertices=(f:any)=>[...f.edges].map((e:any)=>({x:e.start.x,y:e.start.y})),oldRegion=poly(power.brep_shape.outer_ring.vertices)
if(objectHash(c)!==report.candidateCircuitSha256)throw Error('Parent changed')
for(const h of power.brep_shape.inner_rings){const points=h.vertices.map((p:any)=>new F.Point(p.x,p.y));if([...poly(h.vertices).faces][0]!.orientation()!==1)points.reverse();oldRegion.addFace(points)}
const trials:any[]=[],start=Date.now();let accepted:any=null
for(const radius of[.65,.75]){for(const index of[5,6,9,10]){if(Date.now()-start>55000)break;const x=1.29+radius*Math.cos(index*Math.PI/8),y=-4.8+radius*Math.sin(index*Math.PI/8),r=(.4572/2+.1016)/Math.cos(Math.PI/64),cut=poly(Array.from({length:64},(_,i)=>({x:x+r*Math.cos(i*Math.PI/32),y:y+r*Math.sin(i*Math.PI/32)}))),trial:any={x,y,radius};trials.push(trial);try{
const region=F.BooleanOperations.subtract(oldRegion,cut),faces=[...region.faces],outers=faces.filter(f=>f.orientation()===-1),holes=faces.filter(f=>f.orientation()===1),newHole=holes.find(f=>poly(vertices(f)).contains(new F.Point(x,y)));trial.outerComponents=outers.length;trial.holeCount=holes.length;trial.newVoidFound=!!newHole;if(outers.length!==1||!newHole)throw Error('Fragmented plane or missing new void')
const merged=poly(vertices(newHole)),otherHoles=holes.filter(f=>f!==newHole);const gaps=otherHoles.map(f=>merged.distanceTo(poly(vertices(f)))[0]);const outerBoundary=new F.Polygon();outerBoundary.addFace(vertices(outers[0]).map(p=>new F.Point(p.x,p.y)));const edgeGap=Math.min(...[...outerBoundary.edges].map(e=>merged.distanceTo(e.shape)[0]));trial.minimumNewVoidWebMm=Math.min(edgeGap,...gaps);if(trial.minimumNewVoidWebMm<.1524-1e-7)throw Error('Merged void leaves insufficient web to distinct boundary')
const nextPlane={...power,brep_shape:{outer_ring:{vertices:vertices(outers[0])},inner_rings:holes.map(f=>({vertices:vertices(f)}))}},next=c.map((e:any)=>e===power?nextPlane:e),via={type:'pcb_via',pcb_via_id:'d3_merged_antipad_ground_stitch',source_net_id:'source_net_346',x,y,outer_diameter:.4572,hole_diameter:.254,from_layer:'top',to_layer:'bottom',layers:['top','inner1','inner2','inner3','inner4','inner5','inner6','inner7','inner8','bottom']},probe={type:'pcb_trace',pcb_trace_id:'d3_ground_stitch_probe',source_net_id:'source_net_346',route:[{route_type:'via',x,y,from_layer:'top',to_layer:'bottom',via_diameter:.4572,via_hole_diameter:.254}]},physical=verifyDdrSystemCopper(next,[probe],input.connections,{},50);trial.physical=physical;trial.oldHoleCount=power.brep_shape.inner_rings.length;trial.newHoleCount=holes.length;trial.outerComponents=outers.length
if(physical.errors.length||physical.violations.length)continue
const candidate=[...next,via],prior=report.planeAudit.map((a:any)=>a.source_net_id==='source_net_346'?{...a,viaContacts:[...a.viaContacts,{id:via.pcb_via_id,x,y,annulusSamplesInPlane:32,total:32}],uniqueViaCount:a.uniqueViaCount+1}:a),planeAudit=refreshDdrPlaneContacts(prior,candidate.filter((e:any)=>e.type==='pcb_copper_pour'),candidate);accepted={candidate,planeAudit,via,planeReplacement:{before:power,after:nextPlane,beforeSha256:objectHash(power),afterSha256:objectHash(nextPlane)}};break
}catch(e){trial.reason=String(e)}}if(accepted||Date.now()-start>55000)break}
mkdirSync(out,{recursive:true});const write=(n:string,v:any)=>writeFileSync(`${out}/${n}`,JSON.stringify(v,null,2)+'\n');write('report.json',{captureHash:report.captureHash,parentDirectory:parent,parentCircuitSha256:objectHash(c),hostTracesSha256:objectHash(host.traces),trials,elapsedMs:Date.now()-start,legalProbe:accepted?.via??null,scope:'Bounded merged power-antipad experiment using existing @flatten-js/core BooleanOperations.subtract. Existing voids preserved by subtraction, one outer copper component required, new merged void retains .1524mm separation to other voids/boundary. No SI qualification; accepted probe still requires selfcontained assembly/power and host audits.'});if(accepted){write('probe.circuit.json',accepted.candidate);write('probe-plane-audit.json',accepted.planeAudit);write('probe-manifest.json',{captureHash:report.captureHash,parentCircuitSha256:objectHash(c),candidateCircuitSha256:objectHash(accepted.candidate),replacements:[accepted.planeReplacement],additions:[accepted.via]})}if(objectHash(read('candidate.circuit.json'))!==objectHash(c))throw Error('Parent changed during experiment');console.log(JSON.stringify({out,trials:trials.length,accepted:accepted?.via??null,elapsed:Date.now()-start}))