-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisk_heat.py
More file actions
96 lines (73 loc) · 3.61 KB
/
Copy pathdisk_heat.py
File metadata and controls
96 lines (73 loc) · 3.61 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import numpy as np
from numba import jit
import matplotlib.pyplot as plt
import time
"""
Here is an example of solving heat diffusion equation on a uniform disk in radial coordinates.
dT/dt = alpha*del^2(T) + heating/(rho*Cp) (https://en.wikipedia.org/wiki/Heat_equation)
Temperature is fixed at the edge. Initial tempearture is uniform.
Heat is generated within a disk with gaussian distribution.
"""
# input parameters
#----------------------------------------------------------------------------------------------------------------------------
rho = 4.826 # density, g/cm^3
Cp = 0.3369 # specific heat capacity, J/(g*K)
alpha = 0.123 # thermal diffusivity, cm^2/s
R = 10.*10**(-4) # radius of the disk, cm
nr = 1024 # number of the radial slices
dr = R/nr # delta r
dr2 = dr**2
rv = np.arange(0.,R, dr) # radius values
dt = dr**2./(4*alpha) # time step, s. in order for solution to be stable, must be smaller than dr**2./(2*alpha)
Ndt = 3*10**6 # number of time steps to calculate the solution for
Ns = 100 # store the data once in Ns*dt time
Ndata = int(Ndt/Ns) # number of the time steps to store the data for
Tcool = 300. # initial temperature, K. And boundary condition at the edge, e.g. keep the edge at Tcool tempearature
u0 = np.ones(nr)*Tcool # initial temperature distribution
power = 1. # total power of the heat source, W
sigmahs = 0.05*R # standard deviation of the heat source as a fraction of disk radius
# heat source distribution
#----------------------------------------------------------------------------------------------------------------------------
heating = power*(1./(sigmahs**2*2*np.pi))*np.exp(-(rv**2)/(2*sigmahs**2)) # volumetric heat source, W/cm^2
heatsource = heating/(rho*Cp)
# solution
#----------------------------------------------------------------------------------------------------------------------------
D0 = 2*alpha*dt/(dr2)
D1 = alpha*dt*(rv[1:-1] + dr/2.)/(dr2*rv[1:-1])
D2 = 1. - 2*alpha*dt/(dr2)
D3 = alpha*dt*(rv[1:-1] - dr/2.)/(dr2*rv[1:-1])
Heatscld = heatsource[1:-1]*dt
Heatscld0 = heatsource[0]*dt
#@jit # comment this line for no jit option
def timestep(u): # calculates next in time temperature distribution based on input temperature dstribution u
u[0] = u[0] + D0*(u[1] - u[0]) + Heatscld0 # boundary condition at the center
u[1:-1] = D1*u[2:] + D2*u[1:-1] + D3*u[:-2] + Heatscld
u[-1] = Tcool # boundary conditions at the edge
return u.copy()
# main loop
#----------------------------------------------------------------------------------------------------------------------------
temp_center = np.zeros(Ndata)
u = u0
stime = time.time() # strat time of the main loop, for performance measurement
for i in range(Ndt):
u = timestep(u)
if i%Ns==0:
temp_center[i/Ns] = u[0]
timetaken = time.time() - stime
print "Calculation finished ... "
print "time taken = %1.3f"%timetaken, ' seconds'
print "%1.4e seconds per iteration"%(timetaken/Ndt)
print "Last simulation time, ", Ndt*dt, ' seconds'
# plot the results
#----------------------------------------------------------------------------------------------------------------------------
times = np.arange(Ndata)*dt*Ns
plt.plot(times*10**6, temp_center)
plt.xlabel('Time (us)')
plt.ylabel('Temperature (K)')
plt.title("Temperature at the center of the disk")
plt.figure()
plt.plot(rv*10**4, u)
plt.title("Final temperature dstribution ")
plt.xlabel('Radius (um)')
plt.ylabel('Temperature (K)')
plt.show()