-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1D_nonLinear.py
59 lines (42 loc) · 1.06 KB
/
1D_nonLinear.py
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
from cProfile import label
from distutils.file_util import write_file
from unicodedata import ucd_3_2_0
import numpy as np
from matplotlib import pyplot
l=2 #in meter
nx=41
dx=(l/(nx-1))
ny=nx
dy=(l/(ny-1))
nt=5
sigma=0.3
dt=sigma * dx
x=np.linspace(0,l,nx)
y=np.linspace(0,l,ny)
u=np.zeros((ny,nx))
v=np.zeros((ny,nx))
un=np.zeros((ny,nx))
vn=np.zeros((ny,nx))
u[int(0.5/dy):int(1/dy+1),int(0.5/dx):int(1/dx+1)]=2 #IC
v[int(0.5/dy):int(1/dy+1),int(0.5/dx):int(1/dx+1)]=2 #IC
un=np.ones(nx)
print(u)
for n in range(nt):
un=u.copy() #updateing un
for j in range(1,ny-1):
for i in range(1,nx-1):
u[j,i]=un[j,i] - (un[j,i]*dt/dx) * (un[j,i] - un[j,i-1]) -(vn[j,i]*dt/dy) * (un[j,i] - un[j,i-1])
u[0, :] = 1
u[-1, :] = 1
u[:, 0] = 1
u[:, -1] = 1
v[0, :] = 1
v[-1, :] = 1
v[:, 0] = 1
v[:, -1] = 1
fig = pyplot.figure(figsize=(11, 7), dpi=100)
ax = fig.gca(projection='3d')
X, Y = np.meshgrid(x, y)
ax.plot_surface(X, Y, u, cmap=cm.viridis, rstride=2, cstride=2)
ax.set_xlabel('$x$')
ax.set_ylabel('$y$');