-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupwind.py
More file actions
36 lines (26 loc) · 893 Bytes
/
upwind.py
File metadata and controls
36 lines (26 loc) · 893 Bytes
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
from __future__ import division
from numpy import array, zeros
def trasporto_upwind(M, N, xmin, xmax, tinz, tfin, vel, ic):
dx = (xmax - xmin) / M
dt = (tfin - tinz) / N
x = xmin + array(range(0, M + 1)) * dx
t = array(range(0, N + 1)) * dt
u = zeros([M + 1, N + 1])
a = zeros([M + 1, N + 1])
u[:, 0] = ic(x)
for n in range(0, N + 1):
a[0:M + 1, n] = vel(x, t[n])
# CFL
cfl = abs(a).max() * dt / dx
if cfl > 1:
print "CFL " + str(cfl)
raise ArithmeticError
else:
for n in range(0, N):
for j in range(1, M):
nu = a[j, n] * dt / dx
u[j, n + 1] = u[j, n] - 0.5 * nu * (u[j + 1, n] - u[j - 1, n]) + \
0.5 * abs(nu) * (u[j + 1, n] - 2 * u[j, n] + u[j - 1, n])
u[0, n + 1] = 0.0
u[M, N] = 0.0
return u, x, t