dINESH AHMT Assignment 1
dINESH AHMT Assignment 1
Computer Assignment – 1
Question 1:
Solution:
import numpy as np
import matplotlib.pyplot as plt
# Domain parameters
L = 1.0
H = 0.5
nx = 4
ny = 4
dx = L / (nx - 1)
dy = H / (ny - 1)
To refine the grid, you doubled the number of grid points in both dimensions:
nx =2×3+1=7
ny =2×3+1=7
So we, changed the the nx and ny value in the previous code to get the coarser grid and
the run the code to get the temperature values at the nodes.
import numpy as np
import matplotlib.pyplot as plt
plt.figure(figsize=(10, 8))
plt.grid()
plt.colorbar(contour_filled, label='Temperature (°C)')
plt.show()
T1 146.7275 143.5165
T2 164.623 164.9451
T3 210.9705 205.0549
T4 228.866 226.4835
So, we can see that the analytical solution and the numerical solution are almost
the same. The slight difference between two solutions can be reduced by mesh
size.
Question 2:
Solution :
import numpy as np
import matplotlib.pyplot as plt
# Given data
L=1
H = 0.5
nx = 4
ny = 4
dx = L / (nx - 1)
dy = H / (ny - 1)
alpha = 10**-4
dt = 0.1 # time step size in seconds
F = (alpha * dt) / (dx * dy) # Fourier number
beta = dy / dx
# Boundary condition
T = 400 * np.ones((ny, nx)) # temperature array
# Set boundary temperatures (except the corner nodes)
T[0, :] = 100 # top boundary
T[-1, :] = 300 # bottom boundary
T[:, 0] = 50 # left boundary
T[:, -1] = 200 # right boundary
# Convergence criteria
tolerance = 10**-4 # timestep criteria
delta = 5 # initial delta
# Calculation
timestep = 0
time = 0
Tovertime = np.zeros((5, 160)) # stores temperature over time
temperature_snapshots = [] # list to store temperature distributions at specific times
snapshot_times = [25,225, 425, 625, 825] # times to plot
Comparison between steady state temperature at the nodes with those in problem 1
Steady State Temperature Temperature in Problem 1
T1 143.7382 143.5165
T2 165.1653 164.9451
T3 205.2766 205.0549
T4 226.7037 226.4835
So, the steady state temperature at the nodes with those in problem 1 is the same.