plt.xlabel(r'Distance $(m)$') plt.ylabel(r'Concentration $ \frac{kg}{m} $') plt.pause(3) plt.close(1) # ============================================================================== # Entering the time loop # ============================================================================== for t in range(1, npt + 1): # Generating analytical solution Ca = AN.difuana(M, L, Dx, x, xo, T0 + t * dT) # Explicit internal part C1 = C + dT * AUX.FDev_sp(C, Dx, dx) # Imposing boundary conditions C1[0] = Ca[0] C1[N - 1] = Ca[N - 1] # Estimating error err = np.abs(C1 - Ca) ert[t] = np.linalg.norm(err) # Plotting numerical solution and comparison with analytical plt.clf() plt.subplot(2, 2, 1) plt.plot(x, C1, 'b') plt.xlim([X0, XL])
plt.subplot(1, 1, 1) plt.plot(x, C) plt.title('Initial condition') plt.xlabel(r'Distance $(m)$') plt.ylabel(r'Concentration $ \frac{kg}{m} $') plt.pause(3) plt.close(1) # ============================================================================== # Entering the time loop # ============================================================================== # First time step Ca = AN.difuana(M, L, Dx, x, xo, T0 + dT) spa = AUX.FDev_sp(C, Dx, dx) C1 = C + dT * spa C1[0] = Ca[0] C1[N - 1] = Ca[N - 1] # Starting plot plt.ion() plt.figure(1, figsize=(11, 8.5)) style.use('ggplot') plt.subplot(1, 1, 1) plt.plot(x, C) plt.title('Initial condition 2') plt.xlabel(r'Distance $(m)$')