main
John Lauer
Add readable heat-flow section toggle and refine thermal viewer framing
9f3135b
from pathlib import Path
import json
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.collections import PolyCollection
R=Path(__file__).resolve().parents[1];O=R/'docs/cooling-volume';A=R/'analysis/cooling-volume';s=json.loads((A/'summary.json').read_text())['results']
plt.style.use('dark_background')
fig,ax=plt.subplots(figsize=(9,4.6))
for name,title in [('preferred50','50 mm low-profile'),('chipset40','40 mm tall-fin'),('pi5','Pi 5 blower concept')]:
r=[x for x in s if x['id']==name and x['pitchMm']==2];ax.plot([x['h'] for x in r],[x['conditionalLoadW'] for x in r],'-o',label=title)
ax.axhline(5,color='white',linestyle=':',label='Existing 5 W target');ax.set(xlabel='Assumed convection h (W/m²K); not measured fan airflow',ylabel='Conditional load ceiling (W)',title='3D conduction model • 40°C ambient / retained 55°C screen');ax.legend();ax.grid(alpha=.2);fig.tight_layout();fig.savefig(O/'power-comparison.png',dpi=170,bbox_inches='tight');plt.close(fig)
for name in ['preferred50','chipset40','pi5']:
p=json.loads((A/f'{name}-h100-p1/thermal3d.json').read_text());cells=p['cells'];bb=np.array([c['boundsMm'] for c in cells]);cent=(bb[:,:3]+bb[:,3:])/2;t=np.array([c['temperatureC'] for c in cells]);q1=next(c['boundsMm'] for c in cells if c['body']==0);ymid=(min(b[1] for b,c in zip(bb,cells) if c['body']==0)+max(b[4] for b,c in zip(bb,cells) if c['body']==0))/2
yvals=sorted(set(cent[:,1]));ys=min(yvals,key=lambda x:abs(x-ymid));mask=np.isclose(cent[:,1],ys);indices=np.where(mask)[0]
fig,axes=plt.subplots(1,2,figsize=(11,4.4));verts=[[(bb[i,0],bb[i,2]),(bb[i,3],bb[i,2]),(bb[i,3],bb[i,5]),(bb[i,0],bb[i,5])] for i in indices]
pc=PolyCollection(verts,array=t[indices],cmap='turbo',clim=(40,55),edgecolors='none');axes[0].add_collection(pc);axes[0].autoscale();axes[0].set_aspect('equal');fig.colorbar(pc,ax=axes[0],label='Cell temperature (°C)');axes[0].set_title('Temperature cross-section')
flux=np.zeros((len(cells),3));count=np.zeros((len(cells),3))
for f in p['conductiveFaces']:
for i in [f['from'],f['to']]:flux[i,f['axis']]+=f['fluxWm2'];count[i,f['axis']]+=1
flux/=np.maximum(count,1);mag=np.linalg.norm(flux,axis=1)
pc2=PolyCollection(verts,array=np.log10(np.maximum(mag[indices],1)),cmap='magma',edgecolors='none');axes[1].add_collection(pc2);axes[1].autoscale();axes[1].set_aspect('equal');fig.colorbar(pc2,ax=axes[1],label='log₁₀ heat flux magnitude (W/m²)')
sample=indices[::max(1,len(indices)//90)];norm=np.maximum(np.linalg.norm(flux[sample][:,[0,2]],axis=1),1e-9);axes[1].quiver(cent[sample,0],cent[sample,2],flux[sample,0]/norm,flux[sample,2]/norm,color='#83fff1',scale=25,width=.004);axes[1].set_title('Solved heat flow • arrows show direction')
for ax in axes:ax.set(xlabel='X (mm)',ylabel='Z (mm)')
fig.suptitle(f'{name} • 5.5 W Q1 • assumed h=100 • section Y={ys:.2f} mm\nEquivalent Q1 case at bottom; no die-level heat-density claim',fontsize=11);fig.tight_layout();fig.savefig(O/f'{name}-section.png',dpi=170,bbox_inches='tight');plt.close(fig)