-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHEAT 2D
57 lines (39 loc) · 1.38 KB
/
HEAT 2D
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#How to create a heat map
#Why are we doing it , it's just a nice partial derivative to solve
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
#Just like all numerical problem we must descritise our problem
#We can choose a small dx for better precision, but we must choose dt to resepct certain parameters , namely
#dt <= 0.5 * dx^2/alpha
a = 110
length = 10 #mm
time = 4 #seconds
nodes = 50
#Need to define the temperature at the boundaries of our rod
#When prefomrming in 2D we simply just add another y dimension partial derivative
dx = length / nodes
dy = length / nodes
dt = 0.3 * dx*dy/a
u = np.zeros((nodes, nodes)) +20 #PLate is initially at 20 degrees C
#Boundary conditions (This gives all the corners equal to 100)
u[0, :]= 100
u[-1, :] = 100
#Visualisng the sim
fig, axis = plt.subplots()
pcm = axis.pcolormesh(u, cmap=plt.cm.jet, vmin=0 , vmax=100)
plt.colorbar(pcm, ax=axis)
#simulating
counter = 0
while counter < time :
w = u.copy()
for i in range(1, nodes - 1):
for j in range(1, nodes -1 ):
dd_ux = (w[i-1, j] - 2*w[i, j] +w[i+1, j])/dx**2
dd_uy = (w[i, j-1] - 2 * w[i, j] + w[i, j+1]) / dy ** 2
u[i, j] = dt * a * (dd_ux + dd_uy) + w[i, j]
counter += dt
pcm.set_array(u)
axis.set_title("Distribution at t: {:.3f} [s].".format(counter))
plt.pause(0.01)
plt.show()