-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBurgerFlow.py
More file actions
90 lines (61 loc) · 2.36 KB
/
BurgerFlow.py
File metadata and controls
90 lines (61 loc) · 2.36 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
import numpy as np
import matplotlib.pyplot as plt
import time
# Initial conditions
n = 20 # width of the simulation box
m = 20 # height of the box
timesteps = 1000 # number of timesteps
dt = 0.2
dx = 1
dy = 1
visc = 0.5
u = np.zeros ((m,n)) # x direction velocities
v = np.zeros ((m,n)) # y direction velocities
u[3:-3,9] = 2
v[5, 8:-8] = 2
# Boundary Conditions : Entry
u[1:-1,0] = 1
# Drawing the fluid
fig = plt.figure (1, figsize = (14,14))
ax = fig.add_subplot (111)
#im = ax.quiver(u, v, scale=10)
im = ax.imshow (u+v)
fig.show()
im.axes.figure.canvas.draw()
def onclick(event):
print('%s click: button=%d, x=%d, y=%d, xdata=%f, ydata=%f' %
('double' if event.dblclick else 'single', event.button,
event.x, event.y, event.xdata, event.ydata))
x = int(event.xdata)
y = int(event.ydata)
u[y,x] = 1
v[y,x] = 1
cid = fig.canvas.mpl_connect('button_press_event', onclick)
for t in range (timesteps):
un = u # u at the previous timestep n
vn = v
for i in range (1,m-1):
for j in range (1,n-1):
# negative if du goes out of volume, positive if it goes in
dux = dt * un[i,j]*(un[i,j+1] - un[i,j])/(dx)
dupx = -dt * un[i,j-1]*(un[i,j] - un[i,j-1])/(dx) # previous coming into the current volume
duy = dt * vn[i,j]*(un[i+1,j] - un[i,j])/(dy)
dupy = -dt * vn[i-1,j]*(un[i,j] - un[i-1,j])/(dy)
du = dupx + dux + dupy + duy
fuv = visc * dt * ((un[i,j-1] - 2*un[i,j] + un[i, j+1])/dx**2 + (un[i-1,j] - 2*un[i,j] + un[i+1, j])/dy**2)
u[i,j] = un[i,j] + du + fuv
# same for velocity in y direction
dvx = dt * un[i,j]*(vn[i,j+1] - vn[i,j])/(dx)
dvpx = -dt * un[i,j-1]*(vn[i,j] - vn[i,j-1])/(dx)
dvy = dt * vn[i,j]*(vn[i+1,j] - vn[i,j])/(dy)
dvpy = -dt * vn[i-1,j]*(vn[i,j] - vn[i-1,j])/(dy)
dv = dvpx + dvx + dvpy + dvy
fvv = visc * dt * ((vn[i,j-1] - 2*vn[i,j] + vn[i, j+1])/dx**2 + (vn[i-1,j] - 2*vn[i,j] + vn[i+1, j])/dy**2)
v[i,j] = vn[i,j] + dv + fvv
ax.set_title("Current time: " + str(t*dt))
#im.set_UVC(u, v)
im.set_data(u+v)
im.axes.figure.canvas.draw()
#time.sleep(0.1)
plt.waitforbuttonpress (timeout=0.01)
plt.show()