Initial condition
The maze starts with a uniform concentration distribution of the gas of 0. At t = 0, c(i, j) = 0 for all i and j except at the inlet.
Boundary conditions
The diffusion coefficient at the inlet is 1e-1 and at the inlet and outlet. The diffusion coefficient at the maze walls is 1e-8.
dt = 0.0005
Concentration after 2000 steps
(1 second)
Concentration after 1e4 steps
(5 seconds)
Concentration after 3e4 steps
(15 seconds)
Concentration after 1e5 steps
(50 seconds)
Using only pure diffusion from the inlet, the following code was used to plot the concentration of each cell:
for i in range(1, N + 1):
for j in range(1, N + 1):
ae = a_vert[i, j] <------- Diffusion coefficients at each cell
aw = a_vert[i - 1, j]
an = a_hor [i, j]
as_ = a_hor [i, j - 1]
coeff_p = 1.0 - (ae + aw + an + as_) * dt / dx**2 <-------- Part of numerical diffusion coefficient
c[i, j] = ( <------- Full concentration update equation
coeff_p * c_old[i, j]
+ ae * dt/dx**2 * c_old[i + 1, j]
+ aw * dt/dx**2 * c_old[i - 1, j]
+ an * dt/dx**2 * c_old[i, j + 1]
+ as_ * dt/dx**2 * c_old[i, j - 1]
)
These plots are computationally heavy, not the most efficient way to solve a maze. However, it can be seen that after 1e5 steps (the last plot) that the concentration gradient is highest in the direction of the exit. This is because closed off paths eventually reach uniform concentration as the concentration cannot escape. By plotting the concentration gradient inside of the maze after a long time (steady state), the exit of the maze could be analytically mapped and found. The following plots (Same plot, different colours) of the concentration gradient are made after 1e5 steps: