def plot_error_comparison(solvers, time_steps, final_errors, **kwargs): fig = plt.figure(figsize = (7, 7 * 2 / 3), dpi = 600) fig.set_tight_layout(True) axis = plt.subplot(111) for solver in solvers: plt.plot(time_steps, final_errors[solver], label = solver.method) axis.set_yscale('log') axis.set_xscale('log') title = axis.set_title(r'Error in $y_{\mathrm{numeric}}(t=1)$ vs. time step', fontsize = 15) title.set_y(1.05) axis.set_xlabel(r'$\Delta t$', fontsize = 15) axis.set_ylabel(r'$\left| y_{\mathrm{analytic}}(t=1) - y_{\mathrm{numeric}}(t=1) \right|$', fontsize = 15) axis.set_xlim(time_steps[0], time_steps[-1]) axis.grid(True, color = 'black', linestyle = '--') axis.tick_params(axis = 'both', which = 'major', labelsize = 10) axis.legend(loc = 'best', fontsize = 12) utils.save_current_figure(name = 'error_comparison', img_format = 'pdf', **kwargs) plt.close()
def plot_solution_comparison(solutions, analytic, **kwargs): fig = plt.figure(figsize = (7, 7 * 2 / 3), dpi = 600) fig.set_tight_layout(True) axis = plt.subplot(111) for sol in solutions: sol.attach_y_vs_t_to_axis(axis) dense_t = np.linspace(sol.t[0], sol.t[-1], 10 * len(sol.t)) line, = plt.plot(dense_t, analytic(dense_t), label = 'Analytic', linestyle = '--', color = 'orange') title = axis.set_title(r'$y$ vs. $t$, with $\Delta t = {}$'.format(sol.delta_t), fontsize = 15) title.set_y(1.05) axis.set_xlabel(r'$t$', fontsize = 15) axis.set_ylabel(r'$y$', fontsize = 15) axis.set_xlim(sol.t[0], sol.t[-1]) axis.grid(True, color = 'black', linestyle = ':') axis.tick_params(axis = 'both', which = 'major', labelsize = 10) axis.legend(loc = 'best', fontsize = 12) utils.save_current_figure(name = 'solution_comparison_dt{}'.format(sol.delta_t), img_format = 'pdf', **kwargs) plt.close()
def plot(self, **kwargs): plt.figure(figsize = (7, 7), dpi = 600) con = plt.contour(self.x_mesh, self.y_mesh, self.u, levels = [1] ) plt.title(r'$u(x,y)$ at $t = {}$'.format(np.around(self.t, 7)), fontsize = 20) plt.xlabel(r'$x$', fontsize = 16) plt.ylabel(r'$y$', fontsize = 16) plt.grid(True) utils.save_current_figure(name = 'u_{}'.format(self.t_counter), **kwargs) plt.close()
def plot_uv_vs_t(self, time_index=0, **kwargs): fig = plt.figure(figsize=(7, 7 * 2 / 3), dpi=600) fig.set_tight_layout(True) axis = plt.subplot(111) t = self.time(time_index) plt.plot(self.x, self.u[time_index], color='blue', label='$u_{\mathrm{numeric}}$') plt.plot(self.x, self.u_analytic(self.x, t), color='teal', label='$u_{\mathrm{analytic}}$') plt.plot(self.x, self.v[time_index], color='red', label='$v_{\mathrm{numeric}}$') plt.plot(self.x, self.v_analytic(self.x, t), color='orange', label='$v_{\mathrm{analytic}}$') axis.set_xlim(self.x[0], self.x[-1]) axis.set_ylim(-2, 2) axis.set_xlabel(r'$x$', fontsize=15) axis.set_ylabel(r'$u(x, t), \, v(x, t)$', fontsize=15) title = axis.set_title(r'Solution at $t = {}$'.format(round(t, 3)), fontsize=15) title.set_y(1.05) axis.grid(True, color='gray', linestyle=':', alpha=0.9) axis.tick_params(axis='both', which='major', labelsize=10) axis.legend(loc='best', fontsize=12) utils.save_current_figure(name='{}_i={}_t={}'.format( self.method, time_index, round(t, 3)), **kwargs) plt.close()
def plot_y_vs_t(self, **kwargs): fig = plt.figure(figsize = (7, 7 * 2 / 3), dpi = 600) fig.set_tight_layout(True) axis = plt.subplot(111) self.attach_y_vs_t_to_axis(axis) title = axis.set_title(r'y vs. t, using {} with $\Delta t = {}$'.format(self.method, self.delta_t), fontsize = 15) title.set_y(1.05) axis.set_xlabel(r't', fontsize = 15) axis.set_ylabel(r'y', fontsize = 15) axis.set_xlim(self.t[0], self.t[-1]) axis.grid(True, color = 'black', linestyle = ':') axis.tick_params(axis = 'both', which = 'major', labelsize = 10) # axis.legend(loc = 'best', fontsize = 12) utils.save_current_figure(**kwargs) plt.close()
def plot_u_vs_x_vs_t(self, t_indices = (0, 20, 40, 60, 80, 100), **kwargs): fig = plt.figure(figsize = (7, 7 * 2 / 3), dpi = 600) fig.set_tight_layout(True) axis = plt.subplot(111) for t_index in t_indices: self.attach_u_vs_x_to_axis(axis, t_index = t_index) title = axis.set_title(r'$u(x, t)$ vs. $x$, using {} with $\Delta t = {}$'.format(self.method, self.delta_t), fontsize = 15) title.set_y(1.05) axis.set_xlabel(r'$x$', fontsize = 15) axis.set_ylabel(r'$u(x)$', fontsize = 15) axis.set_xlim(self.t[0], self.t[-1]) axis.grid(True, color = 'black', linestyle = ':') axis.tick_params(axis = 'both', which = 'major', labelsize = 10) plt.legend(loc = 'best', fontsize = 10) utils.save_current_figure(**kwargs) plt.close()
def plot_u(self, colormesh=False, postfix='', **kwargs): fig = plt.figure(figsize=(7, 7 * .75), dpi=600) fig.set_tight_layout(True) axis = plt.subplot(111) contour = axis.contour(self.x_mesh, self.y_mesh, self.u, levels=[0], colors='green') plt.clabel(contour, inline=1, fontsize=10) if colormesh: vmin = min(np.min(self.u), -1) vmax = max(np.max(self.u), 1) color = axis.pcolormesh(self.x_mesh, self.y_mesh, self.u, cmap=plt.get_cmap('gray'), shading='gouraud', vmin=vmin, vmax=vmax) cbar = plt.colorbar(color) postfix += '_colormesh' axis.set_xlabel(r'$x$', fontsize=15) axis.set_ylabel(r'$y$', fontsize=15) title = axis.set_title(r'$u(x,y, t = {})$'.format( np.around(self.t[self.time_index], 4)), fontsize=15) title.set_y(1.05) utils.save_current_figure('RDSO_u' + postfix, **kwargs) plt.close()
def plot_u_vs_x(self, t_index = 0, overlay_analytic = True, **kwargs): fig = plt.figure(figsize = (7, 7 * 2 / 3), dpi = 600) fig.set_tight_layout(True) axis = plt.subplot(111) self.attach_u_vs_x_to_axis(axis, t_index = t_index) if overlay_analytic: axis.plot(self.x_dense, self.u_analytic(self.x_dense, self.t[t_index]), linestyle = '--', label = r'$u_{\mathrm{analytic}}$') title = axis.set_title(r'$u(t={})$ vs. $x$, using {} with $\Delta t = {}$'.format(np.around(self.t[t_index], 3), self.method, self.delta_t), fontsize = 15) title.set_y(1.05) axis.set_xlabel(r'$x$', fontsize = 15) axis.set_ylabel(r'$u(t={})$'.format(np.around(self.t[t_index], 3)), fontsize = 15) axis.set_xlim(self.t[0], self.t[-1]) axis.grid(True, color = 'black', linestyle = ':') axis.tick_params(axis = 'both', which = 'major', labelsize = 10) if overlay_analytic: plt.legend(loc = 'best') utils.save_current_figure(**kwargs) plt.close()