Commit ceefbb2e by Jigyasa Watwani

Nx larger

parent c6647133
......@@ -44,8 +44,8 @@ def advection_diffusion(Nx, L, Nt, tmax, D):
return c_array
# parameters
Nx, L, D, tmax = 32, 1, 0.1, 0.25
nt_array = np.array([5, 10, 15, 20, 25, 50, 100, 200, 400, 800, 1600])
Nx, L, D, tmax = 256, 1, 0.1, 0.25
nt_array = np.array([2, 3, 4, 5, 10, 15, 20, 25, 50, 100, 200, 400, 800, 1600])
dt_array = tmax/nt_array
mesh = df.IntervalMesh(Nx, 0, L)
x = mesh.coordinates()[:, 0]
......@@ -63,7 +63,7 @@ for i in range(0, len(nt_array)):
c = advection_diffusion(Nx, L, nt_array[i], tmax, D)
error[i] = np.max(np.abs(c[-1] - c_exact[-1]))
print('dt,t,error=', tmax/400, tmax, error[-3])
print('dt,t,error=', tmax/800, tmax, error[-2])
popt, pcov = curve_fit(linear_func, np.log(dt_array), np.log(error))
print('The slope of the graph of log(error) vs log(dt) is', popt[0])
fig, ax = plt.subplots(1)
......@@ -72,3 +72,6 @@ ax.loglog(dt_array, error, 'bo')
ax.set_xlabel('log(dt)')
ax.set_ylabel('log(error)')
plt.show()
# |u_{exact} - u_{Nt}| < |u_{exact} - u_{Nx}| + |u_{Nx} - u_{Nt}| + floating point errors
# to get the correct error in time, ensure first term small. That can be done by taking Nx large enough
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment