Skip to content
This repository was archived by the owner on Jul 25, 2023. It is now read-only.

Commit 8fc8c76

Browse files
author
Jordi
committed
Update files
1 parent bc860b4 commit 8fc8c76

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

day_8/Convection/ConvectionDiffusion1D_limiters renamed to day_8/Convection/ConvectionDiffusion1D_limiters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
beta = 1
3232

3333
"Number of points"
34-
N = 256
34+
N = 32
3535
Dx = 1/N
3636
x = np.linspace(0,1,N+1)
3737

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,22 @@
5050
nt = np.size(time)
5151

5252
"Initialize solution variable"
53-
U = np.zeros((N+2,nt))
53+
U = np.zeros((N+1,nt))
5454

5555

5656
for it in range(nt-1):
5757

5858
"System matrix and RHS term"
5959
"Diffusion term"
60-
Diff = nu*(1/Dx**2)*(2*np.diag(np.ones(N+2)) - np.diag(np.ones(N+1),-1) - np.diag(np.ones(N+1),1))
60+
Diff = nu*(1/Dx**2)*(2*np.diag(np.ones(N+1)) - np.diag(np.ones(N),-1) - np.diag(np.ones(N),1))
6161

6262
"Advection term:"
6363

6464
"Sensor"
6565
U0 = U[:,it]
66-
uaux = np.concatenate(([U0[0]],U0,[U0[N+1]]))
67-
Du = uaux[1:N+4] - uaux[0:N+3] + 1e-8
68-
r = Du[0:N+2]/Du[1:N+3]
66+
uaux = np.concatenate(([U0[0]], U0,[U0[N]]))
67+
Du = uaux[1:N+3] - uaux[0:N+2] + 1e-8
68+
r = Du[0:N+1]/Du[1:N+2]
6969

7070
"Limiter"
7171
if beta>0:
@@ -74,8 +74,8 @@
7474
else:
7575
phi = 2*r/(r**2 + 1)
7676

77-
phim = phi[0:N+1]
78-
phip = phi[1:N+2]
77+
phim = phi[0:N]
78+
phip = phi[1:N+1]
7979

8080

8181
"Upwind scheme"
@@ -97,25 +97,25 @@
9797
"Source term"
9898
sine = np.sin(2*pi*time[it+1])
9999
sineplus = 0.5*(sine + np.abs(sine))
100-
F = 100*np.exp(-((xN-0.8)/0.01)**2)*sineplus
100+
F = 100*np.exp(-((x-0.8)/0.01)**2)*sineplus
101101

102102
"Temporal terms"
103-
A = A + (1/dt)*np.diag(np.ones(N+2))
103+
A = A + (1/dt)*np.diag(np.ones(N+1))
104104
F = F + U0/dt
105105

106106
"Boundary condition at x=0"
107-
A[0,:] = (1/Dx)*np.concatenate(([-1, 0, 1],np.zeros(N-1)))
107+
A[0,:] = (1/Dx)*np.concatenate(([1.5, -2, 0.5],np.zeros(N-2)))
108108
F[0] = 0
109109

110110
"Boundary condition at x=1"
111-
A[N+1,:] = np.concatenate((np.zeros(N+1),[1]))
112-
F[N+1] = u0
111+
A[N,:] = np.concatenate((np.zeros(N),[1]))
112+
F[N] = u0
113113

114114

115115
"Solution of the linear system AU=F"
116116
u = np.linalg.solve(A,F)
117117
U[:,it+1] = u
118-
u = u[1:N+2]
118+
u = u[0:N+1]
119119

120120

121121
"Animation of the results"
@@ -128,17 +128,18 @@
128128

129129
def animate(i):
130130

131-
u = U[1:N+2,i]
131+
u = U[0:N+1,i]
132132
plt.plot(x,u)
133133
myAnimation.set_data(x, u)
134134
return myAnimation,
135135

136136
anim = animation.FuncAnimation(fig,animate,frames=range(1,nt),blit=True,repeat=False)
137137

138138

139-
"Peclet number"
140-
P = np.abs(c*Dx/nu)
141-
print("Pe number Pe=%g\n" % P);
139+
if nu>0:
140+
"Peclet number"
141+
P = np.abs(c*Dx/nu)
142+
print("Pe number Pe=%g\n" % P);
142143

143144
"CFL number"
144145
CFL = np.abs(c*dt/Dx)

0 commit comments

Comments
 (0)