def error_plot(dtvec, dxvec, which, tmax): ''' helper function to create the 3d-plot that is made for the error analysis. ''' dt, dx = np.meshgrid(dtvec, dxvec) res = np.zeros_like(dt) for i, DT in enumerate(dtvec): for j, DX in enumerate(dxvec): ival = initialValues( [None, 1.0, int(1 / DX), int(tmax / DT), DT, 'periodic']) obj = simulation(ival, hopfTable, which) obj.simulate(10 * ival.HopfFunc, 1.0) res[i,j] = np.sqrt(np.sum(( 10*advection_exact_periodic(ival.xvec,ival.N_T*ival.DELTA_T,1.0)- \ obj.result)**2)) return dt, dx, res
def error_plot(dtvec, dxvec, which, tmax): ''' helper function to create the 3d-plot that is made for the error analysis. Logarithmic scaling of all axes. ''' dt, dx = np.meshgrid(dtvec, dxvec) res = np.zeros_like(dt) for i, DT in enumerate(dtvec): for j, DX in enumerate(dxvec): ival = initialValues( [None, 1.0, int(1 / DX), int(tmax / DT), DT, 'reflecting']) obj = simulation(ival, diffusionTable, which) obj.simulate(ival.DiffFunc, 1.0) res[i,j] = np.sqrt(np.sum(( diffusionExact['reflecting'](ival.xvec,ival.N_T*ival.DELTA_T,1.0)- \ obj.result)**2)) return np.log10(dt), np.log10(dx), np.log(res)
def get_ival(n_t, delta_t, n_x, bdy): ''' small helper function for the initial values used. merely useful. ''' obj = initialValues([None, 1.0, 51, n_t, delta_t, bdy]) return obj
y = Y[ind] z = Z[ind] ax.plot(x, z) ax.set_xlabel('$\\mathrm{log_{10}}(\\Delta t)$') ax.set_ylabel('$\\mathrm{log}(\\mathsf{TE})$') ax.set_title( 'Truncation Error ($\\mathsf{TE}$) for the explicit {\\scshape Euler}-scheme; $\\mathsf{CLF} = 1/6$' ) plt.grid() plt.tight_layout() fig_eu_e_16.savefig(prefix + 'eu_e_ERRORS16.pdf') T = 1000 eps = 5e-3 DT = 1e-6 ival = initialValues([None, 1.0, 701, T, DT, 'periodic'], eps=eps) u_init = eps / np.pi / ((ival.xvec - 0.5)**2 + eps**2) # general check for the cr_n_Dfun-simulation. if False: cnsd = simulation(ival, diffusionTable, 'cr_n_D') cnsd.simulate(eps / np.pi / ((ival.xvec - 0.5)**2 + eps**2), 1.0) cnsd.plot_init(plot_default=False) plt.plot(ival.xvec, cnsd.result, label='simulated') plt.plot(ival.xvec, exact_dfun(ival.xvec, T * DT, ival.DiffStep, x0=0.5), label='exact') plt.grid() plt.xlabel('$x$') plt.ylabel('$u(x,t)/\\mathrm{[a.u.]}$') plt.title('Step profile, mathematical comparison') plt.legend()
'im_c': implicit_centered, 'lax_f': lax_friedrichs, 'lax_w': lax_wendroff, 'lax_w_h': lax_wendroff_hopfeq } if False: # dummy if, only used to not execute this part which was used to generate # the plots for the hopf equation a = 0.1 dt = 0.001 maxslope_anti = np.sqrt(np.exp(1)) * a my_T = (int(maxslope_anti / dt) - 1) * dt ival = initialValues( [None, 1.0, 301, int(maxslope_anti / dt) - 1, dt, 'periodic']) up = simulation(ival, hopfTable, 'lax_w_h') u_i = +np.exp(-(ival.xvec - 0.5)**2 / 2 / a**2) + 1 up.simulate(u_i, 1.0) up.plot_init('$t=0$') up.plot_final('$t=%.3f$' % my_T, 'Breakdown: $a = %.3f$' % a) #up.fig.savefig('hopfBreakdown2.pdf') plt.show() # some human-readable output definitely is nice. schemeNames = { 'up': 'upwind scheme', 'down': 'downwind scheme', 'ex_c': 'explicit centered scheme', 'im_c': 'implicit centered scheme',