def Generalized_Ohm(sdfdata, axis, species=None): grid = sdfdata.__dict__["Grid_Grid_mid"].data # grid = sdfdata.__dict__["Grid_Grid"].data x = grid[0] y = grid[1] dx = grid[0][1] - grid[0][0] dy = grid[1][1] - grid[1][0] p_pos = sdfdata.__dict__[get_varname("Grid_Particles", species)].data vx = sdfdata.__dict__[get_varname("Particles_Vx", species)].data vy = sdfdata.__dict__[get_varname("Particles_Vy", species)].data vz = sdfdata.__dict__[get_varname("Particles_Vz", species)].data w = sdfdata.__dict__[get_varname("Particles_Weight", species)].data v_3 = (np.sqrt(vx**2 + vy**2 + vz**2))**3 v_5 = (np.sqrt(vx**2 + vy**2 + vz**2))**5 p_list = list(zip(p_pos[0], p_pos[1])) v_3_dist = first_order_weight_2d(x, y, dx, dy, p_list, weight=w, values=v_3) v_5_dist = first_order_weight_2d(x, y, dx, dy, p_list, weight=w, values=v_5) const = -sc.m_e / (6 * sc.e) grad_num = np.gradient(v_5_dist, dx, dy)[axis] # grad_num_y = np.gradient(v_5_dist, dx, dy)[1] return const * np.divide(grad_num, v_3_dist, where=v_3_dist!=0.0)
def Generalized_Ohm_radavg(sdfdata, species=None): # grid = sdfdata.__dict__["Grid_Grid_mid"].data grid = sdfdata.__dict__["Grid_Grid"].data x = grid[0] y = grid[1] dx = grid[0][1] - grid[0][0] dy = grid[1][1] - grid[1][0] p_pos = sdfdata.__dict__[get_varname("Grid_Particles", species)].data vx = sdfdata.__dict__[get_varname("Particles_Vx", species)].data vy = sdfdata.__dict__[get_varname("Particles_Vy", species)].data vz = sdfdata.__dict__[get_varname("Particles_Vz", species)].data w = sdfdata.__dict__[get_varname("Particles_Weight", species)].data v_3 = (np.sqrt(vx**2 + vy**2 + vz**2))**3 v_5 = (np.sqrt(vx**2 + vy**2 + vz**2))**5 p_list = list(zip(p_pos[0], p_pos[1])) v_3_dist = first_order_weight_2d(x, y, dx, dy, p_list, weight=w, values=v_3) v_5_dist = first_order_weight_2d(x, y, dx, dy, p_list, weight=w, values=v_5) # ax = plt.subplot(1, 2, 1) # im = ax.pcolormesh(v_3_dist, cmap=cm.coolwarm) # ax = plt.subplot(1, 2, 2) # im = ax.pcolormesh(v_5_dist, cmap=cm.coolwarm) # plt.savefig('v5.png', dpi=600, bbox_inches="tight") avg_3, dummy_r, dummy_t = reproject_image_into_polar(v_3_dist, origin=None, Jacobian=False, dr=1, dt=None) o_ma = np.ma.masked_equal(avg_3, 0.) avg_3 = np.average(o_ma, axis=1) avg_5, dummy_r, dummy_t = reproject_image_into_polar(v_5_dist, origin=None, Jacobian=False, dr=1, dt=None) o_ma = np.ma.masked_equal(avg_5, 0.) avg_5 = np.average(o_ma, axis=1) const = -sc.m_e / (6 * sc.e) grad_num = np.gradient(avg_5, dx) #TODO: what to use for grid spacing radially return const * np.divide(grad_num, avg_3, where=avg_3!=0.0)
def __map_particle_to_grid(sdfdata, p_var_name, species=None): grid = sdfdata.__dict__["Grid_Grid_mid"].data x = grid[0] y = grid[1] dx = grid[0][1] - grid[0][0] dy = grid[1][1] - grid[1][0] p_pos = sdfdata.__dict__[get_varname("Grid_Particles", species)].data p_list = list(zip(p_pos[0], p_pos[1])) w = sdfdata.__dict__[get_varname("Particles_Weight", species)].data p_var = sdfdata.__dict__[p_var_name].data return first_order_weight_2d(x, y, dx, dy, p_list, values=p_var, weight=w)
def main(): species = "Electron" path = "/scratch/lsa_flux/diiorios/2d_run/" fnums = ["0200"] fname = [] for n in fnums: fname.append(path + n + ".sdf") for i in range(len(fname)): sdfdata = sdf.read(fname[i]) print(sdfdata.Header['time']) grid = sdfdata.__dict__["Grid_Grid"].data x = grid[0] y = grid[1] dx = grid[0][1] - grid[0][0] dy = grid[1][1] - grid[1][0] p_pos = sdfdata.__dict__[get_varname("Grid_Particles", species)].data p_list = list(zip(p_pos[0], p_pos[1])) p_list[:] = [p for p in p_list if in_domain(p, x, y)] w = sdfdata.__dict__[get_varname("Particles_Weight", species)].data v = sdfdata.__dict__[get_varname("Particles_Px", species)].data grid = first_order_weight_2d(x, y, dx, dy, p_list, values=v, weight=w) # p = (2 - (-2)) * np.random.rand(500,2) - 2#np.array([[0., 0.],[0.5,0.5],[-1,-1],[-2,-2],[-1.8,-1.5]]) # grid = first_order_weight_2d(x, y, dx, dy, p, values=None, weight=None) cmap = shiftedColorMap(cm.coolwarm, np.amin(grid), np.amax(grid)) plt.figure() plt.pcolormesh(grid, cmap=cmap) cbar = plt.colorbar() plt.savefig('w.png') return
def main(): species = "Electron" path = "/scratch/lsa_flux/diiorios/2d_run/" fnums = ["0100"] fname = [] for n in fnums: fname.append(path + n + ".sdf") x_axis_num = 0 y_axis_num = 1 z_axis_num = 2 fig, axarr = plt.subplots(len(fname), sharex=True, sharey=True) # only have a single file to plot, so we so this little hack since # axarr does not come out in an array in this case if not isinstance(axarr, np.ndarray): axarr = np.array([axarr]) axarr[0].set_title(species + " files " + str(fnums)) for i in range(len(fname)): sdfdata = sdf.read(fname[i]) print(sdfdata.Header['time']) grid = sdfdata.__dict__["Grid_Grid_mid"].data # grid = sdfdata.__dict__["Grid_Grid"].data x = grid[0] y = grid[1] dx = grid[0][1] - grid[0][0] dy = grid[1][1] - grid[1][0] p_pos = sdfdata.__dict__[get_varname("Grid_Particles", species)].data vx = sdfdata.__dict__[get_varname("Particles_Vx", species)].data vy = sdfdata.__dict__[get_varname("Particles_Vy", species)].data vz = sdfdata.__dict__[get_varname("Particles_Vz", species)].data w = sdfdata.__dict__[get_varname("Particles_Weight", species)].data v_3 = (np.sqrt(vx**2 + vy**2 + vz**2))**3 v_5 = (np.sqrt(vx**2 + vy**2 + vz**2))**5 p_list = list(zip(p_pos[0], p_pos[1])) # p_list = list(zip(p_pos[0], p_pos[1], w, vx, vy, vz)) # pack everything together so we remove all the right values # p_list[:] = [p for p in p_list if in_domain(p, x, y)] # x_pos, y_pos, w, vx, vy, vz = zip(*p_list) # p_list = list(zip(x_pos, y_pos)) v_3_dist = first_order_weight_2d(x, y, dx, dy, p_list, weight=w, values=v_3) # v_3_dist = np.divide(v_3_dist, ne, where=ne!=0.0) v_5_dist = first_order_weight_2d(x, y, dx, dy, p_list, weight=w, values=v_5) # v_5_dist = np.divide(v_5_dist, ne, where=ne!=0.0) const = -sc.m_e / (6 * sc.e) grad_num_x = np.gradient(v_5_dist, dx, dy)[0] grad_num_y = np.gradient(v_5_dist, dx, dy)[1] term_x = const * np.divide(grad_num_x, v_3_dist, where=v_3_dist!=0.0) term_y = const * np.divide(grad_num_y, v_3_dist, where=v_3_dist!=0.0) # limit = 1E10 plt.figure() plt.pcolormesh(v_5_dist, cmap=cm.coolwarm)#, vmin=-limit, vmax=limit) cbar = plt.colorbar() plt.savefig('den.png') return
def cart_higher_order_y(sdfdata, species=None): # grid = sdfdata.__dict__["Grid_Grid_mid"].data grid = sdfdata.__dict__["Grid_Grid"].data x = grid[0] y = grid[1] dx = grid[0][1] - grid[0][0] dy = grid[1][1] - grid[1][0] p_pos = sdfdata.__dict__[get_varname("Grid_Particles", species)].data vx = sdfdata.__dict__[get_varname("Particles_Vx", species)].data vy = sdfdata.__dict__[get_varname("Particles_Vy", species)].data vz = sdfdata.__dict__[get_varname("Particles_Vz", species)].data w = sdfdata.__dict__[get_varname("Particles_Weight", species)].data v_3 = (np.sqrt(vx**2 + vy**2 + vz**2))**3 p_list = list(zip(p_pos[0], p_pos[1])) v_3_dist = first_order_weight_2d(x, y, dx, dy, p_list, weight=w, values=v_3) vx_dist = first_order_weight_2d(x, y, dx, dy, p_list, weight=w, values=vx) vy_dist = first_order_weight_2d(x, y, dx, dy, p_list, weight=w, values=vy) limit = 1e108 term1 = np.multiply(vy_dist, vx_dist) term1 = np.multiply(term1, v_3_dist) fig4, ax4 = plt.subplots() im4 = ax4.pcolormesh(term1, vmin=-1e102, vmax=1e102) fig4.colorbar(im4) fig4.savefig('term1_carty_before_grad.png', dpi=600, bbox_inches="tight") plt.close(fig4) term1 = np.gradient(term1, dx, axis=0) fig5, ax5 = plt.subplots() im5 = ax5.pcolormesh(term1, vmin=-limit, vmax=limit) fig5.colorbar(im5) fig5.savefig('term1_carty.png', dpi=600, bbox_inches="tight") plt.close(fig5) term2 = np.multiply(vy_dist, vy_dist) term2 = np.multiply(term2, v_3_dist) fig6, ax6 = plt.subplots() im6 = ax6.pcolormesh(term2, vmin=-1e102, vmax=1e102) fig6.colorbar(im6) fig6.savefig('term2_carty_before_grad.png', dpi=600, bbox_inches="tight") plt.close(fig6) term2 = np.gradient(term2, dy, axis=1) fig7, ax7 = plt.subplots() im7 = ax7.pcolormesh(term2, vmin=-limit, vmax=limit) fig7.colorbar(im7) fig7.savefig('term2_carty.png', dpi=600, bbox_inches="tight") plt.close(fig7) div_num = term1 + term2 const = -sc.m_e / (2 * sc.e) final = const * np.divide(div_num, v_3_dist, where=v_3_dist != 0.0) fig8, ax8 = plt.subplots() im8 = ax8.pcolormesh(final, vmin=-1e53, vmax=1e53) fig8.colorbar(im8) fig8.savefig('final_carty.png', dpi=600, bbox_inches="tight") plt.close(fig8) return final
def higher_order(sdfdata, species=None): # grid = sdfdata.__dict__["Grid_Grid_mid"].data grid = sdfdata.__dict__["Grid_Grid"].data x = grid[0] y = grid[1] dx = grid[0][1] - grid[0][0] dy = grid[1][1] - grid[1][0] p_pos = sdfdata.__dict__[get_varname("Grid_Particles", species)].data vx = sdfdata.__dict__[get_varname("Particles_Vx", species)].data vy = sdfdata.__dict__[get_varname("Particles_Vy", species)].data vz = sdfdata.__dict__[get_varname("Particles_Vz", species)].data w = sdfdata.__dict__[get_varname("Particles_Weight", species)].data p_list = list(zip(p_pos[0], p_pos[1])) limit = 1e20 v_r = np.sqrt(vx**2 + vy**2)# + vz**2) #NOTE: might need to get rid of vz. can then use cart2polar for v_r and v_t v_r_dist = first_order_weight_2d(x, y, dx, dy, p_list, weight=w, values=v_r) avg_r, r, dummy_t = reproject_image_into_polar(v_r_dist, origin=None, Jacobian=False, dr=1, dt=None) o_ma = np.ma.masked_equal(avg_r, 0.) avg_r = np.average(o_ma, axis=1) fig1, ax1 = plt.subplots(2, sharex=True) ax1[0].plot(avg_r) ax1[1].plot(np.clip(avg_r, -limit, limit)) fig1.savefig('vr.png', dpi=600, bbox_inches="tight") plt.close(fig1) v_t = np.arctan2(vx, vy) v_t_dist = first_order_weight_2d(x, y, dx, dy, p_list, weight=w, values=v_t) avg_t, r, t = reproject_image_into_polar(v_t_dist, origin=None, Jacobian=False, dr=1, dt=None) o_ma = np.ma.masked_equal(avg_t, 0.) avg_t = np.average(o_ma, axis=1) fig2, ax2 = plt.subplots(2, sharex=True) ax2[0].plot(avg_t) ax2[1].plot(np.clip(avg_t, -limit, limit)) fig2.savefig('vt.png', dpi=600, bbox_inches="tight") plt.close(fig2) v_3 = (np.sqrt(vx**2 + vy**2 + vz**2))**3 v_3_dist = first_order_weight_2d(x, y, dx, dy, p_list, weight=w, values=v_3) avg_3, r, t = reproject_image_into_polar(v_3_dist, origin=None, Jacobian=False, dr=1, dt=None) o_ma = np.ma.masked_equal(avg_3, 0.) avg_3 = np.average(o_ma, axis=1) fig3, ax3 = plt.subplots(2, sharex=True) ax3[0].plot(avg_3) ax3[1].plot(np.clip(avg_3, -limit, limit)) fig3.savefig('avg_v3.png', dpi=600, bbox_inches="tight") plt.close(fig3) r = np.linspace(0.0, np.max(np.sqrt(x**2 + y**2)), num=avg_r.size) num_1 = np.multiply(r, avg_3) num_1 = np.multiply(avg_r, num_1) num_1 = np.multiply(avg_r, num_1) fig4, ax4 = plt.subplots(2, sharex=True) ax4[0].plot(num_1) ax4[1].plot(np.clip(num_1, -limit, limit)) fig4.savefig('num1_before_grad', dpi=600, bbox_inches="tight") plt.close(fig4) num_1 = np.gradient(num_1, dx) #TODO: what to use for grid spacing radially fig5, ax5 = plt.subplots(2, sharex=True) ax5[0].plot(num_1) ax5[1].plot(np.clip(num_1, -limit, limit)) fig5.savefig('num1.png', dpi=600, bbox_inches="tight") plt.close(fig5) num_2 = np.multiply(avg_r, avg_t) num_2 = np.multiply(avg_3, num_2) fig6, ax6 = plt.subplots(2, sharex=True) ax6[0].plot(num_2) ax6[1].plot(np.clip(num_2, -limit, limit)) fig6.savefig('num2_before_grad.png', dpi=600, bbox_inches="tight") plt.close(fig6) num_2 = np.gradient(num_2, max(x.size, y.size)) #TODO: what to use for grid spacing theta fig7, ax7 = plt.subplots(2, sharex=True) ax7[0].plot(num_2) ax7[1].plot(np.clip(num_2, -limit, limit)) fig7.savefig('num2.png', dpi=600, bbox_inches="tight") plt.close(fig7) # num = np.divide(num_1 + num_2, r, where=r!=0.0) num = np.divide(num_1, r, where=r!=0.0) fig8, ax8 = plt.subplots(2, sharex=True) ax8[0].plot(num) ax8[1].plot(np.clip(num, -limit, limit)) fig8.savefig('num.png', dpi=600, bbox_inches="tight") plt.close(fig8) const = -sc.m_e / (2 * sc.e) final = const * np.divide(num, avg_3, where=avg_3!=0.0) fig9, ax9 = plt.subplots(2, sharex=True) ax9[0].plot(final) ax9[1].plot(np.clip(final, -limit, limit)) fig9.savefig('final.png', dpi=600, bbox_inches="tight") plt.close(fig9) return final#const * np.divide(num, avg_3, where=avg_3!=0.0)