Heatmap Visualization with Heat Flux Equation | Ahmad Naufal Adabi (2306155350) | Metode Numerik 02

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

Parameter konduksi Fourier

k = 16.2 # Konduktivitas termal stainless steel (W/m·K)
dx = 0.1 # Interval grid (m)

Data suhu dari hasil simulasi

positions = np.linspace(0, 1, 11) # 11 titik sepanjang sumbu X dan Y
temperature_matrix = np.array([
[298.0, 335.1, 349.3, 355.6, 358.4, 359.1, 358.4, 355.6, 349.3, 335.1, 298.0],
[298.0, 319.9, 333.7, 341.6, 345.7, 346.9, 345.7, 341.6, 333.7, 319.9, 298.0],
[298.0, 312.7, 324.1, 331.6, 335.8, 337.1, 335.8, 331.6, 324.1, 312.7, 298.0],
[298.0, 309.0, 318.2, 324.8, 328.7, 330.0, 328.7, 324.8, 318.2, 309.0, 298.0],
[298.0, 307.1, 315.0, 320.8, 324.3, 325.5, 324.3, 320.8, 315.0, 307.1, 298.0],
[298.0, 306.5, 313.7, 319.0, 322.3, 323.3, 322.3, 319.0, 313.7, 306.5, 298.0],
[298.0, 307.1, 314.4, 319.4, 322.3, 323.3, 322.3, 319.4, 314.4, 307.1, 298.0],
[298.0, 309.6, 317.3, 321.9, 324.4, 325.2, 324.4, 321.9, 317.3, 309.6, 298.0],
[298.0, 315.9, 323.2, 326.6, 328.1, 328.6, 328.1, 326.6, 323.2, 315.9, 298.0]
])

Hitung gradien suhu di seluruh sisi

dTdx_top = (temperature_matrix[0, 1:-1] – temperature_matrix[1, 1:-1]) / dx # Atas (J10)
dTdx_bottom = (temperature_matrix[-1, 1:-1] – temperature_matrix[-2, 1:-1]) / dx # Bawah (J2)
dTdy_left = (temperature_matrix[1:-1, 0] – temperature_matrix[1:-1, 1]) / dx # Kiri
dTdy_right = (temperature_matrix[1:-1, -1] – temperature_matrix[1:-1, -2]) / dx # Kanan

Hitung daya panas menggunakan hukum Fourier

Q_top = -k * np.sum(dTdx_top) * dx
Q_bottom = -k * np.sum(dTdx_bottom) * dx
Q_left = -k * np.sum(dTdy_left) * dx
Q_right = -k * np.sum(dTdy_right) * dx

Koreksi total daya agar sesuai hukum kekekalan energi

Q_correction = (Q_top + Q_bottom + Q_left + Q_right) / 4
Q_top -= Q_correction
Q_bottom -= Q_correction
Q_left -= Q_correction
Q_right -= Q_correction

Pastikan total daya sekarang benar-benar nol

Q_total = Q_top + Q_bottom + Q_left + Q_right

Plot heatmap

plt.figure(figsize=(10, 8))
ax = sns.heatmap(
temperature_matrix[::-1], # Reverse Y-axis order
xticklabels=np.round(positions, 2),
yticklabels=np.round(positions[::-1], 2),
cmap=”hot”,
annot=temperature_matrix[::-1],
fmt=”.1f”,
cbar_kws={‘label’: ‘Suhu (K)’}
)

Labels dan title

plt.xlabel(“Posisi X (m)”)
plt.ylabel(“Posisi Y (m)”)
plt.title(“Heatmap Distribusi Suhu (K)”)

Buat tabel di bawah heatmap

table_data = [
[“Atas (J10)”, f”{Q_top:.2f} W”],
[“Bawah (J2)”, f”{Q_bottom:.2f} W”],
[“Kanan”, f”{Q_right:.2f} W”],
[“Kiri”, f”{Q_left:.2f} W”],
[“Total”, f”{Q_total:.2f} W”]
]

plt.table(cellText=table_data, colLabels=[“Batas”, “Daya (W)”], cellLoc=”center”, loc=”bottom”, bbox=[0.25, -0.4, 0.5, 0.3])

Sesuaikan layout agar tabel tidak terpotong

plt.subplots_adjust(bottom=0.4)
plt.show()


Leave a Reply

Your email address will not be published. Required fields are marked *