-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathheat1D.py
More file actions
50 lines (41 loc) · 1.37 KB
/
heat1D.py
File metadata and controls
50 lines (41 loc) · 1.37 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
"""Module solves heat equation in 1D using finite difference method and nengo_pde."""
from nengo_pde import Solver1D
import matplotlib.pyplot as plt
def feedback_connection(u):
return - (K/dx**2) * 2*u
def lateral_connection(u):
return K/dx**2 * u
# Nengo simulation
t_steps = 80 # Number of time steps
x_steps = 8 # Number of x steps
neurons = 500 # Number of neurons
radius = 100 # Radius of neurons
boundaries = [-50, 50] # Constant boundary conditions
solver = Solver1D(feedback_connection, lateral_connection)
# Grid properties
K = 4.2
x_len = 20 # mm
dx = x_len/x_steps
dt = dx**2/(2*K**2) # dt chosen for stability
# Run finite difference method simulation
solver.run_FDM_order1(dt, t_steps, x_steps, boundaries)
fig, ax = solver.plot_population(dt, False)
ax.set_xlabel('Time (s)')
ax.set_ylabel('Temperature ($^{\circ}$C)')
plt.show()
fig, ax = solver.plot_grid(t_steps, False)
ax.set_xlabel('Time (s)')
ax.set_ylabel('Temperature ($^{\circ}$C)')
plt.show()
solver.animate(nframes=t_steps)
# Run nengo_pde simulation
solver.run_nengo_order1(dt, t_steps, x_steps, boundaries, neurons, radius)
fig, ax = solver.plot_population(0.001, False)
ax.set_xlabel('Time (s)')
ax.set_ylabel('Temperature ($^{\circ}$C)')
plt.show()
fig, ax = solver.plot_grid(t_steps, False)
ax.set_xlabel('Time (s)')
ax.set_ylabel('Temperature ($^{\circ}$C)')
plt.show()
solver.animate(nframes=t_steps)