Professional Documents
Culture Documents
Jeron Young
MMAE 517 Computational Fluid Dynamics PS #2
Problem 1
In [28]: # Gauss-Seidel Iteration with SOR
N = 51
dx = 1/(N-1)
dy = 1/(N-1)
del_bar = (dx/dy)**2
x = np.linspace(0, 1, N)
y= np.linspace(0, 1, N)
m = 1
n = 1
In [29]: print(x)
print(dx)
print (del_bar)
[0. 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2 0.22 0.24 0.26
0.28 0.3 0.32 0.34 0.36 0.38 0.4 0.42 0.44 0.46 0.48 0.5 0.52 0.54
0.56 0.58 0.6 0.62 0.64 0.66 0.68 0.7 0.72 0.74 0.76 0.78 0.8 0.82
0.02
1.0
-1. ]
-0.99802673]
-0.9921147 ]
...
0.9921147 ]
0.99802673]
1. ]]
In [32]: b.shape
In [34]: print(phi)
...
In [35]: phi.shape
count = count + 1
print(count)
print(convergence)
Problem 2
In [43]: #Alternating-Direction-Implict (ADI) using Thomas alg
In [46]: np.shape(x)
Out[46]: (51,)
In [73]: a = np.zeros(N)
b = np.zeros(N)
c = np.zeros(N)
d = np.zeros(N)
g = np.zeros(N)
f = np.zeros((N, N))
In [74]: np.shape(a)
Out[74]: (51,)
F = np.zeros(N)
delta = np.zeros(N)
theta = np.zeros(N)
# Forward elimination
F[0] = c[0]/b[0]
delta[0] = d[0]/b[0]
# Back substitution
theta[N-1] = delta[N-1]
for k in range(N-2,-1,-1):
theta[k] = delta[k] - F[k]*theta[k+1]
return theta
In [90]:
In [91]: print(a)
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.
1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.
1. 1. 2.]
In [92]: count = 0
# if j = 0 then d[0]
#slide 181 (points outside of the domain) -> u[1,j] = u[2,j]
if j == 0:
for i in range (0, N):
d[0] = dx**2*f[i, j] - d_bar*(phi[i, j+1] - (2 - sigma/d_ba
elif j == N-1:
for i in range (0, N):
d[N-1] = dx**2*f[i, j] - d_bar*(phi[i, j-1] - (2 - sigma/d_
else:
for i in range (0, N):
#from slide 189 -> J line iterations (Y-lines)
#eqn. 5.35
phi[:,j] = theta0
if i == 0:
for j in range (0, N):
d[0] = dx**2*f[i, j] - (phi[i+1, j] - (2-sigma)*phi[i, j] +
elif i == N-1:
for j in range (0, N):
d[N-1] = dx**2*f[i, j] - (phi[i-1, j] - (2-sigma)*phi[i, j]
else:
for j in range (0, N):
#from slide 193 -> I line iterations (X-lines)
#eqn. 5.36
d[j] = dx**2*f[i, j] - (phi[i+1, j] - (2-sigma)*phi[i, j] +
phi[i,:] = theta1
count = count + 1
print(count)
print(convergence)
1
-0.004054612543562862
In [100]: print(phi)
-0.43669493]
-0.43353448]
-0.4301613 ]
...
-0.43690064]
-0.43723749]
-0.43749393]]
Problem 3
In [15]: #ADI w/ dirichelt boundary conditions
In [16]: N = 51
l = 1
x = np.linspace(0, 1, N)
y = np.linspace(0, 1, N)
dx = l/(N-1)
dy = l/(N-1)
d_bar = (dx/dy)**2
In [17]: # Iterations
I = 50
J = 50
#Acceleration Parameter -> slide 194
R = max(I +1, J + 1)
sigma = 2*np.cos(np.pi/R)
In [18]: print(sigma)
1.9962066574740882
[[0. 0. 0. ... 0. 0. 0. ]
...
F = np.zeros(N)
delta = np.zeros(N)
theta = np.zeros(N)
# Forward elimination
F[0] = c[0]/b[0]
delta[0] = d[0]/b[0]
# Back substitution
theta[N-1] = delta[N-1]
for k in range(N-2,-1,-1):
theta[k] = delta[k] - F[k]*theta[k+1]
return theta
In [22]: a = np.zeros(N)
b = np.zeros(N)
c = np.zeros(N)
d = np.zeros(N)
g = np.zeros(N)
f = np.zeros((N, N))
In [25]: #ADI
epsilon =10**-4
count = 0
convergence = 1
#for q in range(0, 250):
psi[:,j] = theta0
psi[i,:] = theta1
count = count + 1
print(count)
print(convergence)
9.904490812648326e-05
In [11]: X, Y = np.meshgrid(x, y)
PSI = X*Y
In [ ]: