lwbro/chip_temp_dynamic_3d_simulator
0
1 2import gradio as gr3import numpy as np4import matplotlib.pyplot as plt5from mpl_toolkits.mplot3d import Axes3D6 7def simulate_dynamic_heat(Lx_cm, Ly_cm, k_material, q_max_factor, sigma_factor, sim_time, time_steps):8 Lx = Lx_cm / 1009 Ly = Ly_cm / 10010 q_max = q_max_factor * 1e811 nx = ny = 5112 T_boundary = 300.013 tau_0 = 1e-914 alpha_delay = 0.00415 T_ref = T_boundary16 dt = sim_time / time_steps17 18 dx = Lx / (nx - 1)19 dy = Ly / (ny - 1)20 h = dx21 alpha = k_material / (1.75e6) # Thermal diffusivity (approx. c*rho)22 23 x0, y0 = Lx / 2, Ly / 224 sigma_source = sigma_factor * Lx25 26 x = np.linspace(0, Lx, nx)27 y = np.linspace(0, Ly, ny)28 X, Y = np.meshgrid(x, y)29 30 T = np.full((ny, nx), T_boundary)31 T_new = T.copy()32 q_source = q_max * np.exp(-((X - x0)**2 + (Y - y0)**2) / (2 * sigma_source**2))33 34 for _ in range(int(time_steps)):35 T_old = T.copy()36 for i in range(1, ny - 1):37 for j in range(1, nx - 1):38 T_new[i, j] = T_old[i, j] + alpha * dt / h**2 * (39 T_old[i+1, j] + T_old[i-1, j] + T_old[i, j+1] + T_old[i, j-1] - 4 * T_old[i, j]) + dt * q_source[i, j] / (1.75e6)40 T_new[0, :], T_new[-1, :], T_new[:, 0], T_new[:, -1] = T_boundary, T_boundary, T_boundary, T_boundary41 T = T_new.copy()42 43 delay = tau_0 * (1 + alpha_delay * (T - T_ref))44 X_mm, Y_mm = X * 1000, Y * 100045 46 fig3d = plt.figure(figsize=(12, 6))47 ax1 = fig3d.add_subplot(121, projection='3d')48 ax1.plot_surface(X_mm, Y_mm, T, cmap='hot', edgecolor='none')49 ax1.set_title('3D Temperature Surface')50 ax1.set_xlabel('X (mm)')51 ax1.set_ylabel('Y (mm)')52 ax1.set_zlabel('Temperature (K)')53 ax1.view_init(elev=30, azim=135)54 55 ax2 = fig3d.add_subplot(122, projection='3d')56 ax2.plot_surface(X_mm, Y_mm, delay * 1e9, cmap='viridis', edgecolor='none')57 ax2.set_title('3D Delay Surface')58 ax2.set_xlabel('X (mm)')59 ax2.set_ylabel('Y (mm)')60 ax2.set_zlabel('Delay (ns)')61 ax2.view_init(elev=30, azim=135)62 63 return fig3d64 65demo = gr.Interface(66 fn=simulate_dynamic_heat,67 inputs=[68 gr.Slider(0.5, 2.0, value=1.0, label="Chip Length X (cm)"),69 gr.Slider(0.5, 2.0, value=1.0, label="Chip Length Y (cm)"),70 gr.Slider(50, 500, value=150, label="Thermal Conductivity (W/m·K)"),71 gr.Slider(1, 10, value=5, label="Heat Source Intensity (×1e8 W/m³)"),72 gr.Slider(0.02, 0.2, value=0.1, label="Heat Spread Factor (σ)"),73 gr.Slider(0.1, 5.0, value=2.0, step=0.1, label="Simulation Time (s)"),74 gr.Slider(10, 500, value=100, step=10, label="Time Steps")75 ],76 outputs=gr.Plot(label="Time-Evolved 3D Simulation"),77 title="Dynamic Chip Heat + Delay Simulation (Interactive 3D)"78)79 80if __name__ == "__main__":81 demo.launch()82 