Term Paper
Term Paper
May 8, 2025
Solving I
∂ 2T ∂ 2T
+ =0
∂x2 ∂y 2
1
Using separation of variables, let T = f (x)g(y):
1 d2 f 1 d2 g
= − = −λ2 (due to periodicity in x)
f dx2 g dy 2
1. x = 0, y, T = 0
f (0) = 0 =⇒ c2 = 0
2. x = L, y, T = 0
nπ
f (L) = 0 =⇒ c1 sin λL = 0 =⇒ λn = , n = 1, 2, . . .
L
3. y = 0, x, T = 0
g(0) = 0 =⇒ c3 + c4 = 0 =⇒ c4 = −c3
nπx nπy
T = c1 sin · 2c3 sinh
L L
∞
X nπx nπy
T = An sin sinh
n=1
L L
Boundary: y = w, θ = h(x):
∞
X nπw nπx
h(x) = An sinh sin
n=1
L L
2
Let Z L mπx
Im = h(x) sin dx
0 L
∞
X nπw L
Im = An sinh δmn
n=1
L 2
∞
X nπw
2Im /L = An sinh δmn
n=1
L
mπw
2Im /L = Am sinh
L
2Im
Am =
L sinh mπw
L
Final solution for I:
∞
2X In nπx nπy
T1 = sin sinh
L n=1 sinh nπw
L
L L
3
Solving II
∂ 2T ∂ 2T
+ = Sc
∂x2 ∂y 2
X nπ 2 mπ 2 nπx mπy
⇒ − + Anm sin sin = Sc
n,m
L w L w
jπx kπy
Multiply both sides by sin L
sin w
and integrate:
X nπ 2 mπ 2 Z L nπx Z w
jπx mπy kπy
− + Anm sin sin dx sin sin dy
n,m
L w 0 L L 0 w w
Z L Z w
jπx kπy
= Sc sin dx sin dy
0 L 0 w
X nπ 2 mπ 2 Lw (1 − (−1)j ) (1 − (−1)k )
− + Anm δnj δmk = ScLw
n,m
L w 4 jπ kπ
" 2 2 #
(1 − (−1)j )(1 − (−1)k )
jπ kπ Lw
+ Ajk = −ScLw
L w 4 jkπ 2
4
X 4Sc (1 − (−1)m )(1 − (−1)n ) nπx mπy
T2 = − h i sin sin
n,m
π 2 mn nπ 2
+ mπ
2 L w
L w
Final solution:
T = T1 + T2
∞
2X In nπx nπy
T = sin sinh
L n=1 sinh nπw L
L L
X 4Sc (1 − (−1)m )(1 − (−1)n ) nπx mπy
− h i sin sin (1)
n,m
π 2 mn nπ 2
+ mπ 2 L w
L w
5
Numerical Solution Strategy
The code numerically solves the 2D Poisson equation:
∂2T ∂2T
+ = Sc
∂x2 ∂y 2
on a rectangular domain with Dirichlet boundary conditions.
Discretization
The domain is divided into a uniform grid with spacing h in both x and y
directions. The Laplacian is approximated using central differences:
Ti+1,j − 2Ti,j + Ti−1,j Ti,j+1 − 2Ti,j + Ti,j−1
+ = Sc
h2 h2
Rearranged for Ti,j :
1
Ti+1,j + Ti−1,j + Ti,j+1 + Ti,j−1 − h2 Sc
Ti,j =
4
Convergence
Iterations continue until the change between successive iterations is below a set
tolerance ϵ:
∥T (k+1) − T (k) ∥2 < ϵ
1
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# Domain parameters
L, W = 1.0, 1.0
Sc = 1.0
Nx, Ny = 50, 50
dx, dy = L/(Nx-1), W/(Ny-1)
# Boundary conditions
x = np.linspace(0, L, Nx)
T[:, -1] = np.sin(np.pi * x/L) # Top boundary (y=W)
for k in range(max_iter):
T_new = T.copy()
for i in range(1, Nx-1):
for j in range(1, Ny-1):
T_new[i,j] = (T[i+1,j] + T[i-1,j] + T[i,j+1] + T[i,j-1] +
Sc*dx**2)/4
residual = np.linalg.norm(T_new - T)
residuals.append(residual)
T = T_new
# Plotting
X, Y = np.meshgrid(np.linspace(0, L, Nx), np.linspace(0, W, Ny))
plt.figure(figsize=(12, 5))
# 3D Surface Plot
ax1 = plt.subplot(121, projection='3d')
ax1.plot_surface(X, Y, T.T, cmap='viridis')
ax1.set_title('Temperature Distribution')
ax1.set_xlabel('X')
ax1.set_ylabel('Y')
# 2D Heatmap
plt.subplot(122)
plt.imshow(T.T, extent=[0, L, 0, W], origin='lower', cmap='hot')
plt.colorbar(label='Temperature')
plt.title('2D Heatmap')
plt.xlabel('X')
plt.ylabel('Y')
plt.tight_layout()
# Convergence Plot
plt.figure()
plt.semilogy(residuals)
plt.title('Convergence History')
plt.xlabel('Iteration')
plt.ylabel('Residual')
plt.grid(True)
plt.show()