def _plot_velocity(self): from pysph.tools.interpolator import Interpolator from pysph.solver.utils import load from pysph.examples.ghia_cavity_data import get_u_vs_y, get_v_vs_x # interpolated velocities _x = np.linspace(0, 1, 101) xx, yy = np.meshgrid(_x, _x) # take the last solution data fname = self.output_files[-1] data = load(fname) tf = data['solver_data']['t'] interp = Interpolator(list(data['arrays'].values()), x=xx, y=yy) ui = np.zeros_like(xx) vi = np.zeros_like(xx) # Average out the velocities over the last n_avg timesteps for fname in self.output_files[-self.n_avg:]: data = load(fname) tf = data['solver_data']['t'] interp.update_particle_arrays(list(data['arrays'].values())) _u = interp.interpolate('u') _v = interp.interpolate('v') _u.shape = 101, 101 _v.shape = 101, 101 ui += _u vi += _v ui /= self.n_avg vi /= self.n_avg # velocity magnitude self.vmag = vmag = np.sqrt(ui**2 + vi**2) import matplotlib.pyplot as plt f = plt.figure() plt.streamplot( xx, yy, ui, vi, density=(2, 2), #linewidth=5*vmag/vmag.max(), color=vmag) plt.xlim(0, 1) plt.ylim(0, 1) plt.colorbar() plt.xlabel('$x$') plt.ylabel('$y$') plt.title('Streamlines at %s seconds' % tf) fig = os.path.join(self.output_dir, 'streamplot.png') plt.savefig(fig, dpi=300) f = plt.figure() ui_c = ui[:, 50] vi_c = vi[50] s1 = plt.subplot(211) s1.plot(ui_c, _x, label='Computed') y, data = get_u_vs_y() if self.re in data: s1.plot(data[self.re], y, 'o', fillstyle='none', label='Ghia et al.') s1.set_xlabel(r'$v_x$') s1.set_ylabel(r'$y$') s1.legend() s2 = plt.subplot(212) s2.plot(_x, vi_c, label='Computed') x, data = get_v_vs_x() if self.re in data: s2.plot(x, data[self.re], 'o', fillstyle='none', label='Ghia et al.') s2.set_xlabel(r'$x$') s2.set_ylabel(r'$v_y$') s2.legend() fig = os.path.join(self.output_dir, 'centerline.png') plt.savefig(fig, dpi=300) return _x, ui, vi, ui_c, vi_c
data = np.load(file_loc) ui, vi, t = data['u'], data['v'], data['t'] vmag = np.sqrt(ui**2 + vi**2) tf = t[-1] ui_c = ui[:, 50] vi_c = vi[50] if cnt == 0: y, data = get_u_vs_y() if re in data: s1.plot(data[re], y, 'o', fillstyle='none', label='Ghia et al.') s1.plot(ui_c, _x, label=sph_schm_legend[schm]) if cnt == 0: x, data = get_v_vs_x() if re in data: s2.plot(x, data[re], 'o', fillstyle='none', label='Ghia et al.') cnt = 1 s2.plot(_x, vi_c, label=sph_schm_legend[schm]) s1.set_xlabel(r'$v_x$') s1.set_ylabel(r'$y$') s1.legend() s2.set_xlabel(r'$x$') s2.set_ylabel(r'$v_y$') s2.legend() tle = file_base + '/centerline' + savefig_additional + '.png' plt.savefig(tle, dpi=400) ################################################################################