main
John Lauer Board34 R10 nominal cooling and probe-clearance verification; refreshed prototype assets and native export checks 5460526
#!/usr/bin/env python3
"""Original nominal CAD for side-fan cooling; preserves baseline and marks open qualifications."""
from pathlib import Path
import copy, json, math, hashlib, struct
import cadquery as cq
from glb_shape_helpers import read_glb,write_glb,add_shape
R=Path(__file__).resolve().parents[1]
import argparse
parser=argparse.ArgumentParser()
parser.add_argument('--board-glb',default='probing-flow/design-candidate/probing-board.glb')
parser.add_argument('--board',default='probing-flow/design-candidate/interface-candidate.kicad_pcb')
parser.add_argument('--out',default='mechanical/passive-side-fan-r10')
parser.add_argument('--clear-board34-bodies',action='store_true')
parser.add_argument('--original-render-profile',action='store_true',help='Build an original simplified fin profile from measured dimensions; no vendor STEP required or redistributed')
parser.add_argument('--rear-sink-support',action='store_true',help='Leave the front contact/test bank open; rear cantilever candidate')
args=parser.parse_args()
O=R/args.out;O.mkdir(exist_ok=True)
g,blob=read_glb(R/args.board_glb)
# Join source fan buffers while retaining the rotor-only animation and its hierarchy.
def join(path):
 s,b=read_glb(path);keys=['bufferViews','accessors','materials','meshes','nodes','animations'];off={k:len(g.get(k,[])) for k in keys}
 blob.extend(b'\0'*(-len(blob)%4));bo=len(blob);blob.extend(b)
 for v in s.get('bufferViews',[]):v['byteOffset']=v.get('byteOffset',0)+bo
 for a in s.get('accessors',[]):
  if 'bufferView' in a:a['bufferView']+=off['bufferViews']
 for m in s.get('meshes',[]):
  for p in m['primitives']:
   p['attributes']={k:v+off['accessors'] for k,v in p['attributes'].items()}
   if 'indices' in p:p['indices']+=off['accessors']
   if 'material' in p:p['material']+=off['materials']
   if 'KHR_draco_mesh_compression' in p.get('extensions',{}):p['extensions']['KHR_draco_mesh_compression']['bufferView']+=off['bufferViews']
 for n in s['nodes']:
  if 'mesh' in n:n['mesh']+=off['meshes']
  if 'children' in n:n['children']=[i+off['nodes'] for i in n['children']]
 for a in s.get('animations',[]):
  for t in a['samplers']:t['input']+=off['accessors'];t['output']+=off['accessors']
  for t in a['channels']:t['target']['node']+=off['nodes']
 for k in keys:g.setdefault(k,[]).extend(s.get(k,[]))
 for k in ['extensionsUsed','extensionsRequired']:g[k]=sorted(set(g.get(k,[])+s.get(k,[])))
 roots=[i+off['nodes'] for i in s['scenes'][s.get('scene',0)]['nodes']];g['scenes'][g.get('scene',0)]['nodes'].extend(roots)
 return roots
roots=join(R/'mechanical/scaffold-stack-study/fan/source/fan-animated.glb')
# Source fan local Z becomes board +X; fan entirely outside the PCB outline.
g['nodes'][roots[0]]['matrix']=[0,1,0,0,0,0,1,0,1,0,0,0,.107,.024,.0286,1]
root=len(g['nodes']);g['nodes'].append({'name':'SideFan.CoolingCandidate','children':[]});g['scenes'][0]['nodes'].append(root)
assy=cq.Assembly(name='SideFan_Candidate_mm');parts=[]
def box(x,y,z,X,Y,Z):return cq.Workplane('XY').box(X-x,Y-y,Z-z,centered=(False,False,False)).translate((x,y,z)).val()
def cyl(rad,h,x,y,z,axis=(0,0,1)):return cq.Solid.makeCylinder(rad,h,cq.Vector(x,y,z),cq.Vector(*axis))
def add(name,s,c,kind='structure'):
 assert s.isValid(),name
 add_shape(g,blob,s,name,c,root,name+' | nominal candidate; not fabrication qualified');assy.add(s,name=name.replace('.','_'),color=cq.Color(*c));parts.append((name,s,kind))
# Outboard perimeter beams, with a clear USB cable lane at board-local y=57.
# Lower shoes are separate through-bolted clamps, never load-bearing thin snap tabs.
teal=(.08,.40,.43);steel=(.55,.59,.62);blue=(.10,.28,.53)
left=box(-15,-12,1.0,-5,108,9.0)
right=box(69,-12,1.0,80,48,9.0).fuse(box(69,68,1.0,80,108,9.0))
front=box(-15,-12,1.0,80,-5,9.0)
rear=box(-15,101,1.0,80,108,9.0)
base=left.fuse(right).fuse(front).fuse(rear)
# Outboard bolt holes through substantial bosses, with washers and nuts rather than printed threads.
for x in [-10,75]:
 for y in [-8,104]:
  if (x,y)!=(75,104):base=base.cut(cyl(1.7,12,x,y,0))

# Four clamping feet engage only the outermost 1 mm of the PCB edge; not the pin head.
for i,(x,y,side) in enumerate([(-10,4,'left'),(-10,92,'left'),(75,4,'right'),(75,92,'right')]):
 xlo,xhi=(-15,-3) if side=='left' else (67,80)
 # Front fan-side clamp bolt sits ahead of the gusset, on an extended clamp ear.
 by=y-8 if i==2 else y+8 if i==3 else y; ylo=y-12 if i==2 else y-4; yhi=y+12 if i==3 else y+4
 lower=box(xlo,ylo,1,xhi,yhi,3.8).cut(cyl(1.7,12,x,by,0))
 upper=box(xlo,ylo,5.9,xhi,yhi,9.9).cut(cyl(1.7,12,x,by,0))
 if i==2:upper=upper.cut(cyl(3.8,4.7,75.4,8,12.6,(1,0,0)))
 base=base.fuse(lower).cut(box(xlo,ylo,5.9,xhi,yhi,10.0)).cut(cyl(1.7,14,x,by,0))
 # Captive M3 nut loaded from below; 2.4 mm nut, 2.5 mm material above pocket.
 pocket=cq.Workplane('XY').polygon(6,5.7/math.cos(math.pi/6)).extrude(2.5).translate((x,by,.9)).val()
 base=base.cut(pocket)
 add(f'Carrier.ClampCap{i}',upper,(.13,.48,.5))
 px0,px1=(-4,-3) if side=='left' else (67,68)
 add(f'Carrier.CompliantLowerPad{i}',box(px0,y-4,3.8,px1,y+4,4.0),(.15,.15,.17),'pad')
 add(f'Carrier.CompliantUpperPad{i}',box(px0,y-4,5.6,px1,y+4,5.9),(.15,.15,.17),'pad')
 add(f'Carrier.M3x10_ClampBolt{i}',cyl(1.5,10,x,by,.4).fuse(cyl(2.75,3,x,by,10.4)),steel,'fastener')
 add(f'Carrier.M3_ClampWasher{i}',cyl(3.5,.5,x,by,9.9).cut(cyl(1.6,.7,x,by,9.8)),steel,'fastener')
 nut=cq.Workplane('XY').polygon(6,5.5/math.cos(math.pi/6)).extrude(2.4).translate((x,by,1)).val().cut(cyl(1.5,2.6,x,by,.9))
 add(f'Carrier.M3_CaptiveNut{i}',nut,steel,'fastener')
base=base.fuse(box(80,0,1,101,48,9))
add('Carrier.Perimeter_8mm_ribs',base,teal)
# Sunon D04114960G-01 p6: four 4.3 mm holes on 32 mm pitch, M4 screws.
# Keep Q1's insulated M3 hardware separate from this fan mounting specification.
plate=box(101,0,4.6,107,48,52.6).cut(cyl(19,8,100,24,28.6,(1,0,0)))
for y in [8,40]:
 for z in [12.6,44.6]:plate=plate.cut(cyl(2.15,8,100,y,z,(1,0,0)))
add('Carrier.FanPlate_6mm',plate,teal)
# Triangular side webs: 6 mm thick, 28 mm deep, support both top and bottom plate corners.
for y in [0,42]:
 s=cq.Workplane('XZ').polyline([((69 if y==0 else 97),9),(107,9),(107,48)]).close().extrude(6).val()
 b=s.BoundingBox();s=s.translate((0,y-b.ymin,0))
 for hy in [8,40]:
  for hz in [12.6,44.6]:s=s.cut(cyl(3.8,4.7,96.4,hy,hz,(1,0,0)))
 add('Carrier.Gusset_'+str(y),s,teal)
# Local-only manufacturer geometry study: 76.2 mm cut, fins along fan axis X.
# Vendor source and derivatives are not part of the public Wiki push.
hole=cyl(1.7,45,27.46,34.66,0)
if args.original_render_profile:
 profile=json.loads((R/'mechanical/passive-side-fan-r10/profile-dimensions.json').read_text())
 source=box(0,0,0,76.0984,7.112,76.2)
 for low,mid,top in zip(*(row['finIntervalsMm'] for row in profile['sections'])):
  poly=[(low[0],7.112),(low[1],7.112),(mid[1],25),(top[1],50.8),(top[0],50.8),(mid[0],25)]
  fin=cq.Workplane('XY').polyline(poly).close().extrude(76.2).val();source=source.fuse(fin)
else:
 source=cq.importers.importStep(str(R/'mechanical/vendor/125319_125320_125321.STEP')).val()
 sb=source.BoundingBox();source=source.translate((-sb.xmin,-sb.ymin,-sb.zmin))
sink=source.intersect(box(-1,-1,0,78,52,76.2)).rotate((0,0,0),(1,0,0),90).rotate((0,0,0),(0,0,1),90).translate((20,19,12.85))
# M3 blind threaded hole shown at nominal major diameter; threads not modeled.
# 6.1 mm nominal depth in 7.112 mm base; actual drill/tap process requires review.
sink=sink.cut(cyl(1.5,6.1,27.46,34.66,12.85))
# Open rear-edge access notch for the large corner machine pin, including vertical tool path.
sink=sink.cut(cyl(6,55,64,96,12))
add(('Heatsink.Wakefield125319_3inch_NOMINAL_RENDER' if args.original_render_profile else 'Heatsink.Wakefield125319_3inch_LOCAL_STUDY'),sink,blue,'heatsink')
# Independent support: two substantial side saddles into right beam; left foot on front perimeter.
for i,y in enumerate([20]):
 add(f'Carrier.SinkSaddle{i}',box(68,y,9,80,y+4,12.85),teal)
add('Carrier.SinkRearCrossbeam',box((-9 if args.clear_board34_bodies else -5),52,(9 if args.clear_board34_bodies else 5),24,60,12.85),teal)
# Front cantilever has 8x10 section; its contact only supports the sink's edge.
if args.rear_sink_support:
 # Long section is 8x8mm; only the final 10mm tip steps down to the sink base.
 support=box(40,95.0984,9,48,108,17).fuse(box(40,91.0984,9,48,95.0984,12.85)).fuse(box(40,101,1,48,108,17))
 add('Carrier.SinkRearCantilever',support,teal)
else:
 add('Carrier.SinkFrontSupport',box(17,-8,8,25,12,12.85).fuse(box(17,-12,1,25,-5,12.85)),teal)
# Preserve known tab-up Q1 interface Z datum: ceramic then copper spacer, no air gap.
x,y=27.46,34.66;tab=10.055
aln=box(x-7,y-15,tab+.02,x+7,y+5,tab+.655).cut(hole)
cu=box(x-7,y-15,tab+.675,x+7,y+5,12.83).cut(hole)
add('Q1.AlN_0_635mm',aln,(.86,.86,.81),'interface');add('Q1.CopperSpreader_2_10mm',cu,(.68,.36,.18),'interface')
# A proposed insulated through-fastener, not a blind tap in an unspecified thin sink base.
add('Q1.PEEK_M3x10_proposed',cyl(1.5,10,x,y,8.785).fuse(cyl(2.75,2,x,y,6.785)),(.5,.34,.18),'fastener')
# Q1 uses the blind thread; no nut or fin-removal tool corridor.
# Fan guard and bolts on the outer face, away from the probes. Nominal ring shape only.
for rad in [8,14,18]:
 ring=cq.Solid.makeTorus(rad,.8,cq.Vector(128,24,28.6),cq.Vector(1,0,0));add('Fan.GuardRing'+str(rad),ring,steel,'guard')
for dy,dz in [(-16,-16),(-16,16),(16,-16),(16,16)]:
 length=math.hypot(dy,dz);spoke=cq.Solid.makeCylinder(.8,length,cq.Vector(128,24,28.6),cq.Vector(0,dy/length,dz/length));add('Fan.GuardSpoke_'+str(dy)+'_'+str(dz),spoke,steel,'guard')
 # Nominal M4x35 through bolt: 5.2 mm extends beyond the nut (M4x30 left only .2 mm).
 by,bz=24+dy,28.6+dz
 add('Fan.M4x35_Bolt_'+str(dy)+'_'+str(dz),cyl(2,35,101,by,bz,(1,0,0)).fuse(cyl(3.5,4,97,by,bz,(1,0,0))),steel,'fastener')
 washer=cyl(4.5,.8,128.8,by,bz,(1,0,0)).cut(cyl(2.15,1,128.7,by,bz,(1,0,0)))
 add('Fan.M4_Washer_'+str(dy)+'_'+str(dz),washer,steel,'fastener')
 nut=cq.Workplane('YZ').polygon(6,7/math.cos(math.pi/6)).extrude(3.2).val().translate((129.6,by,bz)).cut(cyl(2,3.4,129.5,by,bz,(1,0,0)))
 add('Fan.M4_Nut_'+str(dy)+'_'+str(dz),nut,steel,'fastener')
# Bind the harness and mating plug to the actual J9 placement in this PCB.
import sexp
pcb=sexp.parse((R/args.board).read_text())
j9=next(f for f in sexp.find(pcb,'footprint') if any(q[1:3]==['Reference','J9'] for q in sexp.find(f,'property')))
ja=sexp.first(j9,'at');jx,jy=float(ja[1])-100,100-float(ja[2]);ja=float(ja[3]) if len(ja)>3 else 0
jdelta=ja-(-90);jr=math.radians(jdelta)
def mate_point(x,y,z):
 dx,dy=x-54.6,y-2
 return (jx+dx*math.cos(jr)-dy*math.sin(jr),jy+dx*math.sin(jr)+dy*math.cos(jr),z)
# Three guarded spline leads routed at the front perimeter into the mating plug.
for i,(sig,c) in enumerate([('5V',(.7,.04,.025)),('GND',(.06,.06,.07)),('TACH',(.9,.7,.03))]):
 end=mate_point(54.6-i*2.54,2,22.14)
 pts=[(117,7,16+i*1.5),(108,-1-i*2,17),(73,-2-i*2,18),(end[0]+2.5,end[1]-2.5,20),end]
 e=cq.Edge.makeSpline([cq.Vector(*p) for p in pts]);wire=cq.Workplane(cq.Plane(origin=cq.Vector(*pts[0]),normal=e.tangentAt(0))).circle(.6).sweep(cq.Wire.assembleEdges([e]),isFrenet=True).val();add('Fan.Harness.'+sig,wire,c,'wire')
# Reuse real mating geometry; omit the old over-board fan and old long wire path.
from step_geometry import load_step
old=load_step(R/'mechanical/scaffold-stack-study/fan/installed-connection.step').Solids()
for i,s in enumerate(old[3:]):add('Fan.HarwinMate.'+str(i),s.rotate((54.6,2,0),(54.6,2,1),jdelta).translate((jx-54.6,jy-2,2.8)),(.18,.19,.20),'connector')
# Structural geometry reports and a reproducible beam sensitivity, not material qualification.
rows=[]
for n,s,k in parts:
 b=s.BoundingBox();rows.append({'name':n,'kind':k,'boundsMm':[b.xmin,b.ymin,b.zmin,b.xmax,b.ymax,b.zmax],'volumeMm3':s.Volume(),'valid':s.isValid()})
g['asset']['extras']['scope']=('Original simplified R10 render model; exact stock extrusion profile is defined by supplier drawing; not fabrication qualified' if args.original_render_profile else 'LOCAL ONLY R10 passive sink study with relocated tach fan; supplier CAD derivative, not adopted or released')
from style_assembly_glb import style
style(g)
from batch_glb_primitives import batch
blob, batching_report = batch(g,blob)
write_glb(O/'side-fan-assembly.glb',g,blob);assy.save(str(O/'mechanical-candidate.step'))
carrier=base
for n,s,k in parts:
 if k=='structure' and n!='Carrier.Perimeter_8mm_ribs' and 'ClampCap' not in n:carrier=carrier.fuse(s)
assert carrier.isValid()
assert len(carrier.Solids()) == 1, 'Carrier must be one connected printable solid; clamp caps are separate parts'
cq.exporters.export(carrier,str(O/'reinforced-carrier.step'))
cq.exporters.export(carrier,str(O/'reinforced-carrier.stl'))
# Save separate printable trial geometry, explicitly unqualified; one-piece base and separate fan plate.
for name,s in [('carrier-base',base),('fan-plate',plate)]:cq.exporters.export(s,str(O/(name+'.step')))
review={'status':'local-only-unadopted-mechanical-study','board':args.board,'boardSha256':hashlib.sha256((R/args.board).read_bytes()).hexdigest(),'parts':rows,'fanEnvelopeMm':[107,4,8.6,127,44,48.6],'sinkEnvelopeMm':[20,19,12.85,96.2,95.0984,63.65],'fanAxis':'X, parallel to extrusion channels; physical airflow direction unverified','carrierSolidCount':len(carrier.Solids()),'sourceModel':'mechanical/vendor/125319_125320_125321.STEP','sourceSha256':'36dcc825a910b650bf2c12be41f6444eca9b9f72b9219cf96ee97aea5e16883d','originalRenderProfile':args.original_render_profile,'profileDimensionsSha256':hashlib.sha256((R/'mechanical/passive-side-fan-r10/profile-dimensions.json').read_bytes()).hexdigest(),'Q1Mount':'Nominal PEEK M3x10 in 6.1mm blind M3 hole, 7.112mm sink base; thread geometry/torque/engagement unqualified','limitations':['LOCAL ONLY supplier CAD derivative; no redistribution permission established.','AlN outline and mounting-hole drawing unresolved; current 20x14x.635 is nominal.','Carrier retention, machining, thread depth, preload, PEEK creep and printed material unqualified.','Catalog thermal resistance is not installed acceptance.','Support and probe/fastener/body clearance checks pending.']}
if args.original_render_profile:
 review['status']='original-nominal-prototype-model'
 review['limitations'][0]='Original simplified fin geometry: envelope, base and eight fins represented; serrations, fillets and supplier tooling details omitted. Vendor STEP is not redistributed.'
(O/'review.json').write_text(json.dumps(review,indent=2)+'\n');print(json.dumps({k:v for k,v in review.items() if k!='parts'},indent=2))