def main(): """business logic for when running this module as the primary one!""" args = get_cmd_args() run_name = args.run_name run_dir = args.run_dir picinfo_fname = '../data/pic_info/pic_info_' + run_name + '.json' pic_info = read_data_from_json(picinfo_fname) coords = get_coordinates(pic_info) # runs_root_dir = "/net/scratch3/xiaocanli/reconnection/mime400/" # run_names = ["mime400_beta002_bg00", # "mime400_beta002_bg02", # "mime400_beta002_bg04", # "mime400_beta002_bg08"] runs_root_dir = "/net/scratch3/xiaocanli/reconnection/frequent_dump/" run_names = ["mime25_beta002_guide00_frequent_dump", "mime25_beta002_guide02_frequent_dump", "mime25_beta002_guide05_frequent_dump", "mime25_beta002_guide10_frequent_dump"] if args.multi_runs: ncores = multiprocessing.cpu_count() ncores = 4 Parallel(n_jobs=ncores)(delayed(process_input)(runs_root_dir, run_name, coords) for run_name in run_names) else: calc_exb(run_dir, run_name, 10, coords)
def main(): """business logic for when running this module as the primary one!""" args = get_cmd_args() run_name = args.run_name run_dir = args.run_dir picinfo_fname = '../data/pic_info/pic_info_' + run_name + '.json' pic_info = read_data_from_json(picinfo_fname) coords = get_coordinates(pic_info) # runs_root_dir = "/net/scratch3/xiaocanli/reconnection/mime400/" # run_names = ["mime400_beta002_bg00", # "mime400_beta002_bg02", # "mime400_beta002_bg04", # "mime400_beta002_bg08"] runs_root_dir = "/net/scratch3/xiaocanli/reconnection/frequent_dump/" run_names = [ "mime25_beta002_guide00_frequent_dump", "mime25_beta002_guide02_frequent_dump", "mime25_beta002_guide05_frequent_dump", "mime25_beta002_guide10_frequent_dump" ] if args.multi_runs: ncores = multiprocessing.cpu_count() ncores = 4 Parallel(n_jobs=ncores)( delayed(process_input)(runs_root_dir, run_name, coords) for run_name in run_names) else: calc_exb(run_dir, run_name, 10, coords)
def process_input(runs_root_dir, run_name, coords): """process one PIC run""" picinfo_fname = '../data/pic_info/pic_info_' + run_name + '.json' pic_info = read_data_from_json(picinfo_fname) tframes = range(pic_info.ntf) run_dir = runs_root_dir + run_name + '/' for tframe in tframes: calc_exb(run_dir, run_name, tframe, coords)
def processInput(run_efield): run_name = run_efield["run_name"] picinfo_fname = '../data/pic_info/pic_info_' + run_name + '.json' pic_info = read_data_from_json(picinfo_fname) coords = get_coordinates(pic_info) tframes = range(pic_info.ntf) efield_name = run_efield["efield_name"] print("Run name and electric field name: %s %s" % (run_name, efield_name)) run_dir = runs_root_dir + run_name + '/' for tframe in tframes: # smooth_interp_emf(run_dir, pic_info, efield_name, tframe, coords) smooth_emf(run_dir, pic_info, efield_name, tframe, coords)
def calc_exb(run_dir, run_name, tframe, coords): """Calculate ExB drift velocity Args: run_dir: PIC run directory run_name: PIC run name trame: time frame coords: coordinates for different fields """ picinfo_fname = '../data/pic_info/pic_info_' + run_name + '.json' pic_info = read_data_from_json(picinfo_fname) nx = pic_info.nx nz = pic_info.nz kwargs = {"current_time": tframe, "xl": 0, "xr": pic_info.lx_di, "zb": -0.5 * pic_info.lz_di, "zt": 0.5 * pic_info.lz_di} size_one_frame = pic_info.nx * pic_info.nz * 4 sigma = 3 fname = run_dir + "data/bx.gda" _, _, bx = read_2d_fields(pic_info, fname, **kwargs) f = MultilinearInterpolator(coords["smin_ez_bx"], coords["smax_ez_bx"], coords["orders"], dtype=np.float32) f.set_values(np.atleast_2d(np.transpose(bx).flatten())) bx = np.transpose(f(coords["coord"]).reshape((nx, nz))) fname = run_dir + "data/by.gda" _, _, by = read_2d_fields(pic_info, fname, **kwargs) f = MultilinearInterpolator(coords["smin_by"], coords["smax_by"], coords["orders"], dtype=np.float32) f.set_values(np.atleast_2d(np.transpose(by).flatten())) by = np.transpose(f(coords["coord"]).reshape((nx, nz))) fname = run_dir + "data/bz.gda" _, _, bz = read_2d_fields(pic_info, fname, **kwargs) f = MultilinearInterpolator(coords["smin_ex_bz"], coords["smax_ex_bz"], coords["orders"], dtype=np.float32) f.set_values(np.atleast_2d(np.transpose(bz).flatten())) bz = np.transpose(f(coords["coord"]).reshape((nx, nz))) fname = run_dir + "data/ex.gda" _, _, ex = read_2d_fields(pic_info, fname, **kwargs) ex = gaussian_filter(ex, sigma) f = MultilinearInterpolator(coords["smin_ex_bz"], coords["smax_ex_bz"], coords["orders"], dtype=np.float32) f.set_values(np.atleast_2d(np.transpose(ex).flatten())) ex = np.transpose(f(coords["coord"]).reshape((nx, nz))) fname = run_dir + "data/ey.gda" _, _, ey = read_2d_fields(pic_info, fname, **kwargs) ey = gaussian_filter(ey, sigma) f = MultilinearInterpolator(coords["smin_h"], coords["smax_h"], coords["orders"], dtype=np.float32) f.set_values(np.atleast_2d(np.transpose(ey).flatten())) ey = np.transpose(f(coords["coord"]).reshape((nx, nz))) fname = run_dir + "data/ez.gda" _, _, ez = read_2d_fields(pic_info, fname, **kwargs) ez = gaussian_filter(ez, sigma) f = MultilinearInterpolator(coords["smin_ez_bx"], coords["smax_ez_bx"], coords["orders"], dtype=np.float32) f.set_values(np.atleast_2d(np.transpose(ez).flatten())) ez = np.transpose(f(coords["coord"]).reshape((nx, nz))) ib2 = 1.0 / (bx**2 + by**2 + bz**2) exb_x = (ey * bz - ez * by) * ib2 exb_y = (ez * bx - ex * bz) * ib2 exb_z = (ex * by - ey * bx) * ib2 fname = run_dir + "data/exb_x.gda" with open(fname, 'a+') as f: offset = size_one_frame * tframe f.seek(offset, os.SEEK_SET) exb_x.tofile(f) fname = run_dir + "data/exb_y.gda" with open(fname, 'a+') as f: offset = size_one_frame * tframe f.seek(offset, os.SEEK_SET) exb_y.tofile(f) fname = run_dir + "data/exb_z.gda" with open(fname, 'a+') as f: offset = size_one_frame * tframe f.seek(offset, os.SEEK_SET) exb_z.tofile(f)
fig_dir = '../img/img_power_spectrum_du/' + run_name + '/' mkdir_p(fig_dir) fname = fig_dir + '/ps_comp_' + species + str(ct).zfill(3) + '.jpg' fig.savefig(fname, dpi=200) plt.close() # plt.show() if __name__ == "__main__": # base_dir = '/net/scratch3/xiaocanli/2D-90-Mach4-sheet4-multi/' # run_name = '2D-90-Mach4-sheet4-multi' base_dir = '/net/scratch2/guofan/for_Senbei/2D-90-Mach4-sheet6-2/' run_name = '2D-90-Mach4-sheet6-2' picinfo_fname = '../data/pic_info/pic_info_' + run_name + '.json' pic_info = read_data_from_json(picinfo_fname) ct = pic_info.ntf - 2 # ct = 200 cts = range(10, pic_info.ntf - 1) xmin, xmax = 0, pic_info.lx_di xmin, xmax = 0, 105 zmin, zmax = -0.5 * pic_info.lz_di, 0.5 * pic_info.lz_di # kwargs = {"current_time":ct, "xl":xmin, "xr":xmax, "zb":zmin, "zt":zmax} # fname = base_dir + 'data1/vex.gda' # x, z, vel = read_2d_fields(pic_info, fname, **kwargs) kwargs = { "current_time": 0, "xl": xmin, "xr": xmax, "zb": zmin,
def plot_energy_conversion_fraction(): """Plot energy evolution for multiple runs. """ dir = '../data/pic_info/' if not os.path.isdir('../img/'): os.makedirs('../img/') odir = '../img/ene_evolution/' if not os.path.isdir(odir): os.makedirs(odir) fnames = list_pic_info_dir(dir) print fnames # run_id = [2, 5, 1, 6, 7, 8, 0, 4] run_id = [2, 8, 1, 9, 10, 12, 0, 7] nrun = len(run_id) ene_fraction = np.zeros(nrun) dke_dki = np.zeros(nrun) irun = 0 i = 0 for fname in fnames: print i, fname i += 1 for i in run_id: fname = fnames[i] print fname rname = fname.replace(".json", ".eps") oname = rname.replace("pic_info", "enes") oname = odir + oname fname = dir + fname pic_info = read_data_from_json(fname) tenergy = pic_info.tenergy ene_magnetic = pic_info.ene_magnetic kene_e = pic_info.kene_e kene_i = pic_info.kene_i dke = kene_e[-1] - kene_e[0] dki = kene_i[-1] - kene_i[0] enorm = ene_magnetic[0] ene_fraction[irun] = 1.0 - ene_magnetic[-1] / enorm dke_dki[irun] = dke / dki irun += 1 x = np.arange(8) fig = plt.figure(figsize=[7, 5]) xs, ys = 0.16, 0.13 w1, h1 = 0.7, 0.8 ax = fig.add_axes([xs, ys, w1, h1]) ax.plot( x, ene_fraction, color='r', marker='o', markersize=10, linestyle='', markeredgecolor='r') labels = [r'R6', r'R1', r'R4', r'R2', r'R5', r'R3', r'R7', r'R8'] ax.set_xticks(x) ax.set_xticklabels(labels) ax.set_xlim([-0.5, 7.5]) ax.set_ylabel( r'$|\Delta\varepsilon_b|/\varepsilon_{b0}$', color='r', fontdict=font, fontsize=24) ax.tick_params(labelsize=20) ax.text( 0.4, 0.15, r'$m_i/m_e=100$', color='k', fontsize=20, bbox=dict( facecolor='none', alpha=1.0, edgecolor='none', pad=10.0), horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) for tl in ax.get_yticklabels(): tl.set_color('r') ax1 = ax.twinx() ax1.plot( x, dke_dki, color='b', marker='v', markersize=10, linestyle='', markeredgecolor='b') ax1.set_xlim([-0.5, 7.5]) ax1.set_ylabel( r'$\Delta K_e/\Delta K_i$', color='b', fontdict=font, fontsize=24) ax1.tick_params(labelsize=20) for tl in ax1.get_yticklabels(): tl.set_color('b') if not os.path.isdir('../img/'): os.makedirs('../img/') dir = '../img/img_dpp/' if not os.path.isdir(dir): os.makedirs(dir) fname = dir + 'ene_fraction_.eps' fig.savefig(fname) plt.show()
def plot_compression_time_temp(species): """ Plot time evolution of compression and shear heating for runs with different plasma temperature Args: species: particle species """ dir = '../data/compression/' dir_jdote = '../data/jdote_data/' if not os.path.isdir('../img/'): os.makedirs('../img/') odir = '../img/compression/' if not os.path.isdir(odir): os.makedirs(odir) base_dirs, run_names = ApJ_long_paper_runs() fig = plt.figure(figsize=[7, 5]) w1, h1 = 0.8, 0.27 xs, ys = 0.96 - w1, 0.97 - h1 gap = 0.02 nrun = len(run_names) ylim1 = np.zeros((nrun, 2)) if species == 'e': ylim1[0, :] = -0.05, 0.15 ylim1[1, :] = -0.3, 1.1 ylim1[2, :] = -1.0, 5 ylim1[3, :] = -10.0, 30.0 ylim1[4, :] = -2.0, 5.0 ylim1[5, :] = -0.1, 0.2 ylim1[6, :] = -0.5, 1.1 ylim1[7, :] = -3.0, 6.0 ylim1[8, :] = -1.0, 5.0 else: ylim1[0, :] = -0.1, 0.25 ylim1[1, :] = -0.6, 2.2 ylim1[2, :] = -2.0, 10 ylim1[3, :] = -20.0, 60.0 ylim1[4, :] = -4.0, 13.0 ylim1[5, :] = -0.2, 0.4 ylim1[6, :] = -1.0, 2.2 ylim1[7, :] = -5.0, 15.0 ylim1[8, :] = -3.0, 7.0 runs = [5, 6, 2] axs = [] for i in runs: run_name = run_names[i] base_dir = base_dirs[i] picinfo_fname = '../data/pic_info/pic_info_' + run_name + '.json' jdote_fname = dir_jdote + 'jdote_' + run_name + '_' + species + '.json' pic_info = read_data_from_json(picinfo_fname) jdote_data = read_data_from_json(jdote_fname) fpath_comp = '../data/compression/' + run_name + '/' b0 = pic_info.b0 ylim2 = ylim1 * b0**2 ax = fig.add_axes([xs, ys, w1, h1]) axs.append(ax) compression_time(pic_info, species, jdote_data, ylim2[i, :], ax, fpath_comp) ys -= h1 + gap for ax in axs: ax.set_xlim([0, 1200]) if species == 'e': axs[0].set_yticks(np.arange(0, 0.007, 0.002)) axs[1].set_yticks(np.arange(0, 0.025, 0.01)) axs[2].set_yticks(np.arange(0, 0.09, 0.02)) else: axs[0].set_yticks(np.arange(0, 0.021, 0.005)) axs[1].set_yticks(np.arange(0, 0.07, 0.02)) axs[2].set_yticks(np.arange(0, 0.17, 0.04)) axs[-1].tick_params(axis='x', labelbottom='on') axs[-1].set_xlabel(r'$t\Omega_{ci}$', fontdict=font, fontsize=20) label1 = r'$-p\nabla\cdot\mathbf{u}$' label2 = r'$-(p_\parallel - p_\perp)b_ib_j\sigma_{ij}$' axs[0].text( 0.4, 0.2, label1, color='red', fontsize=20, bbox=dict( facecolor='none', alpha=1.0, edgecolor='none', pad=10.0), horizontalalignment='left', verticalalignment='center', transform=axs[0].transAxes) axs[0].text( 0.6, 0.2, label2, color='green', fontsize=20, bbox=dict( facecolor='none', alpha=1.0, edgecolor='none', pad=10.0), horizontalalignment='left', verticalalignment='center', transform=axs[0].transAxes) axs[0].text( 0.05, 0.8, r'$v_\text{the}/c=0.045$', color='black', fontsize=20, bbox=dict( facecolor='none', alpha=1.0, edgecolor='none', pad=10.0), horizontalalignment='left', verticalalignment='center', transform=axs[0].transAxes) axs[1].text( 0.05, 0.8, r'$v_\text{the}/c=0.08$', color='black', fontsize=20, bbox=dict( facecolor='none', alpha=1.0, edgecolor='none', pad=10.0), horizontalalignment='left', verticalalignment='center', transform=axs[1].transAxes) axs[2].text( 0.05, 0.8, r'$v_\text{the}/c=0.14$', color='black', fontsize=20, bbox=dict( facecolor='none', alpha=1.0, edgecolor='none', pad=10.0), horizontalalignment='left', verticalalignment='center', transform=axs[2].transAxes) if not os.path.isdir('../img/'): os.makedirs('../img/') dir = '../img/img_dpp/' if not os.path.isdir(dir): os.makedirs(dir) fname = dir + 'comp_temp_' + species + '.eps' fig.savefig(fname) plt.show()
def plot_jpara_dote_fraction(): """Plot energy evolution from the parallel and perpendicular directions. """ dir = '../data/jdote_data/' if not os.path.isdir('../img/'): os.makedirs('../img/') odir = '../img/jdote/' if not os.path.isdir(odir): os.makedirs(odir) base_dirs, run_names = ApJ_long_paper_runs() run_id = [3, 2, 6, 7, 4, 5, 1, 0] nrun = len(run_id) fraction_jpara_e = np.zeros(nrun) fraction_jpara_i = np.zeros(nrun) fraction_jperp_e = np.zeros(nrun) fraction_jperp_i = np.zeros(nrun) irun = 0 for i in run_id: run_name = run_names[i] picinfo_fname = '../data/pic_info/pic_info_' + run_name + '.json' jdote_e_fname = '../data/jdote_data/jdote_' + run_name + '_e.json' jdote_i_fname = '../data/jdote_data/jdote_' + run_name + '_i.json' pic_info = read_data_from_json(picinfo_fname) kene_e = pic_info.kene_e kene_i = pic_info.kene_i dkene_e = kene_e[-1] - kene_e[0] dkene_i = kene_i[-1] - kene_i[0] jdote_e = read_data_from_json(jdote_e_fname) jdote_i = read_data_from_json(jdote_i_fname) jpara_dote_e = jdote_e.jqnupara_dote_int jperp_dote_e = jdote_e.jqnuperp_dote_int jpara_dote_i = jdote_i.jqnupara_dote_int jperp_dote_i = jdote_i.jqnuperp_dote_int fraction_jpara_e[irun] = jpara_dote_e[-1] / dkene_e fraction_jperp_e[irun] = jperp_dote_e[-1] / dkene_e fraction_jpara_i[irun] = jpara_dote_i[-1] / dkene_i fraction_jperp_i[irun] = jperp_dote_i[-1] / dkene_i irun += 1 x = np.arange(8) fig = plt.figure(figsize=[7, 5]) xs, ys = 0.18, 0.13 w1, h1 = 0.78, 0.8 ax = fig.add_axes([xs, ys, w1, h1]) ax.plot(x, fraction_jpara_e[:8], color='r', marker='o', markersize=10, linestyle='') ax.plot(x, fraction_jpara_i[:8], color='b', marker='o', markersize=10, linestyle='') labels = [r'R6', r'R1', r'R2', r'R4', r'R5', r'R3', r'R7', r'R8'] ax.set_xticks(x) ax.set_xticklabels(labels) ax.set_xlim([-0.5, 7.5]) ax.set_ylabel(r'Fraction of Parallel Acceleration', fontdict=font, fontsize=24) ax.tick_params(labelsize=20) ax.text(0.05, 0.15, r'Electron', color='r', fontsize=24, bbox=dict(facecolor='none', alpha=1.0, edgecolor='none', pad=10.0), horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) ax.text(0.05, 0.25, r'Ion', color='b', fontsize=24, bbox=dict(facecolor='none', alpha=1.0, edgecolor='none', pad=10.0), horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) if not os.path.isdir('../img/'): os.makedirs('../img/') dir = '../img/img_dpp/' if not os.path.isdir(dir): os.makedirs(dir) fname = dir + 'para_acc_fraction.eps' fig.savefig(fname) plt.show()
def calc_exb(run_dir, run_name, tframe, coords): """Calculate ExB drift velocity Args: run_dir: PIC run directory run_name: PIC run name trame: time frame coords: coordinates for different fields """ picinfo_fname = '../data/pic_info/pic_info_' + run_name + '.json' pic_info = read_data_from_json(picinfo_fname) nx = pic_info.nx nz = pic_info.nz kwargs = { "current_time": tframe, "xl": 0, "xr": pic_info.lx_di, "zb": -0.5 * pic_info.lz_di, "zt": 0.5 * pic_info.lz_di } size_one_frame = pic_info.nx * pic_info.nz * 4 sigma = 3 fname = run_dir + "data/bx.gda" _, _, bx = read_2d_fields(pic_info, fname, **kwargs) f = MultilinearInterpolator(coords["smin_ez_bx"], coords["smax_ez_bx"], coords["orders"], dtype=np.float32) f.set_values(np.atleast_2d(np.transpose(bx).flatten())) bx = np.transpose(f(coords["coord"]).reshape((nx, nz))) fname = run_dir + "data/by.gda" _, _, by = read_2d_fields(pic_info, fname, **kwargs) f = MultilinearInterpolator(coords["smin_by"], coords["smax_by"], coords["orders"], dtype=np.float32) f.set_values(np.atleast_2d(np.transpose(by).flatten())) by = np.transpose(f(coords["coord"]).reshape((nx, nz))) fname = run_dir + "data/bz.gda" _, _, bz = read_2d_fields(pic_info, fname, **kwargs) f = MultilinearInterpolator(coords["smin_ex_bz"], coords["smax_ex_bz"], coords["orders"], dtype=np.float32) f.set_values(np.atleast_2d(np.transpose(bz).flatten())) bz = np.transpose(f(coords["coord"]).reshape((nx, nz))) fname = run_dir + "data/ex.gda" _, _, ex = read_2d_fields(pic_info, fname, **kwargs) ex = gaussian_filter(ex, sigma) f = MultilinearInterpolator(coords["smin_ex_bz"], coords["smax_ex_bz"], coords["orders"], dtype=np.float32) f.set_values(np.atleast_2d(np.transpose(ex).flatten())) ex = np.transpose(f(coords["coord"]).reshape((nx, nz))) fname = run_dir + "data/ey.gda" _, _, ey = read_2d_fields(pic_info, fname, **kwargs) ey = gaussian_filter(ey, sigma) f = MultilinearInterpolator(coords["smin_h"], coords["smax_h"], coords["orders"], dtype=np.float32) f.set_values(np.atleast_2d(np.transpose(ey).flatten())) ey = np.transpose(f(coords["coord"]).reshape((nx, nz))) fname = run_dir + "data/ez.gda" _, _, ez = read_2d_fields(pic_info, fname, **kwargs) ez = gaussian_filter(ez, sigma) f = MultilinearInterpolator(coords["smin_ez_bx"], coords["smax_ez_bx"], coords["orders"], dtype=np.float32) f.set_values(np.atleast_2d(np.transpose(ez).flatten())) ez = np.transpose(f(coords["coord"]).reshape((nx, nz))) ib2 = 1.0 / (bx**2 + by**2 + bz**2) exb_x = (ey * bz - ez * by) * ib2 exb_y = (ez * bx - ex * bz) * ib2 exb_z = (ex * by - ey * bx) * ib2 fname = run_dir + "data/exb_x.gda" with open(fname, 'a+') as f: offset = size_one_frame * tframe f.seek(offset, os.SEEK_SET) exb_x.tofile(f) fname = run_dir + "data/exb_y.gda" with open(fname, 'a+') as f: offset = size_one_frame * tframe f.seek(offset, os.SEEK_SET) exb_y.tofile(f) fname = run_dir + "data/exb_z.gda" with open(fname, 'a+') as f: offset = size_one_frame * tframe f.seek(offset, os.SEEK_SET) exb_z.tofile(f)
def plot_particle_number(): """ """ temp = 0.73 l0 = 0.13 # length in meter potentials = [50, 100, 150, 200, 200] run_names = ['v50', 'v100', 'v150', 'v200', 'v200_b0_wce'] nes = [1.4E6, 1.45E6, 1.48E6, 1.48E6, 1.48E6] # in cm^-3 lnames = ['50 V', '100 V', '150 V', '200 V', '200 V, B=0'] fig = plt.figure(figsize=[7, 5]) xs, ys = 0.13, 0.13 w1, h1 = 0.8, 0.8 ax = fig.add_axes([xs, ys, w1, h1]) tmax = 0 current_mean = [] for potential, ne, run_name, lname in zip(potentials, nes, run_names, lnames): # run_name = 'v' + str(potential) picinfo_fname = '../data/pic_info/pic_info_' + run_name + '.json' pic_info = read_data_from_json(picinfo_fname) fname = '../data/particle_number/nptl_' + run_name + '.dat' data = np.genfromtxt(fname) t = data[:, 0] dt = t[1] - t[0] ntot = data[:, 1:] dne = np.gradient(ntot[:, 0], axis=0) wpe = 1.78E9 * math.sqrt(ne / n0) # ne is normalized by n0 dt /= wpe ntot = pic_info.nx * pic_info.nz * pic_info.nppc smime = math.sqrt(pic_info.mime) lx_de = pic_info.lx_di * smime lz_de = pic_info.lz_di * smime de = c0 * 1E3 / wpe vol = lx_de * lz_de * de**2 # assume the third dimension is 1 meter dne_real = dne * ne * 1E6 * vol / ntot current = -dne_real * qe / dt current *= 1E3 # A -> mA lname = str(potential) + 'V' ax.plot(t, current * l0, linewidth=2, label=lname) tmax = max(t.max(), tmax) current_mean.append(np.mean(current[-20:])) ax.tick_params(labelsize=16) ax.set_xlabel(r'$t\omega_{pe}$', fontdict=font, fontsize=20) ax.set_ylabel(r'$I$/mA', fontdict=font, fontsize=20) leg = ax.legend( loc=1, prop={'size': 20}, ncol=1, shadow=False, fancybox=False, frameon=False) ax.set_xlim([0, tmax]) ax.set_ylim([0, 1]) fig.savefig('../img/current_time.eps') fig.savefig('../img/current_time.jpg', dpi=300) r0 = 0.0925E-2 # in meter area = 2 * math.pi * r0 # Assume 1m length current_mean = np.asarray(current_mean) current_mean /= area current_thermal = np.asarray([29.9, 31.2, 31.8, 31.8, 31.8]) # mA/m^2 potential = np.asarray([50, 100, 150, 200, 200]) fig = plt.figure(figsize=[7, 5]) xs, ys = 0.13, 0.13 w1, h1 = 0.8, 0.8 ax = fig.add_axes([xs, ys, w1, h1]) current_norm = current_mean / current_thermal ax.plot( potential / temp, current_norm, linewidth=2, marker='o', markersize=10) ax.tick_params(labelsize=16) ax.set_xlabel( 'body bias / electron temperature', fontdict=font, fontsize=20) ax.set_ylabel( 'collected current / thermal current', fontdict=font, fontsize=20) fig.savefig('../img/current_potential.eps') fig.savefig('../img/current_potential.jpg', dpi=300) plt.show()
def plot_energy_conversion_fraction(): """Plot energy evolution for multiple runs. """ dir = '../data/pic_info/' if not os.path.isdir('../img/'): os.makedirs('../img/') odir = '../img/ene_evolution/' if not os.path.isdir(odir): os.makedirs(odir) fnames = list_pic_info_dir(dir) print fnames # run_id = [2, 5, 1, 6, 7, 8, 0, 4] run_id = [2, 8, 1, 9, 10, 12, 0, 7] nrun = len(run_id) ene_fraction = np.zeros(nrun) dke_dki = np.zeros(nrun) irun = 0 i = 0 for fname in fnames: print i, fname i += 1 for i in run_id: fname = fnames[i] print fname rname = fname.replace(".json", ".eps") oname = rname.replace("pic_info", "enes") oname = odir + oname fname = dir + fname pic_info = read_data_from_json(fname) tenergy = pic_info.tenergy ene_magnetic = pic_info.ene_magnetic kene_e = pic_info.kene_e kene_i = pic_info.kene_i dke = kene_e[-1] - kene_e[0] dki = kene_i[-1] - kene_i[0] enorm = ene_magnetic[0] ene_fraction[irun] = 1.0 - ene_magnetic[-1] / enorm dke_dki[irun] = dke / dki irun += 1 x = np.arange(8) fig = plt.figure(figsize=[7, 5]) xs, ys = 0.16, 0.13 w1, h1 = 0.7, 0.8 ax = fig.add_axes([xs, ys, w1, h1]) ax.plot(x, ene_fraction, color='r', marker='o', markersize=10, linestyle='', markeredgecolor='r') labels = [r'R6', r'R1', r'R4', r'R2', r'R5', r'R3', r'R7', r'R8'] ax.set_xticks(x) ax.set_xticklabels(labels) ax.set_xlim([-0.5, 7.5]) ax.set_ylabel(r'$|\Delta\varepsilon_b|/\varepsilon_{b0}$', color='r', fontdict=font, fontsize=24) ax.tick_params(labelsize=20) ax.text(0.4, 0.15, r'$m_i/m_e=100$', color='k', fontsize=20, bbox=dict(facecolor='none', alpha=1.0, edgecolor='none', pad=10.0), horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) for tl in ax.get_yticklabels(): tl.set_color('r') ax1 = ax.twinx() ax1.plot(x, dke_dki, color='b', marker='v', markersize=10, linestyle='', markeredgecolor='b') ax1.set_xlim([-0.5, 7.5]) ax1.set_ylabel(r'$\Delta K_e/\Delta K_i$', color='b', fontdict=font, fontsize=24) ax1.tick_params(labelsize=20) for tl in ax1.get_yticklabels(): tl.set_color('b') if not os.path.isdir('../img/'): os.makedirs('../img/') dir = '../img/img_dpp/' if not os.path.isdir(dir): os.makedirs(dir) fname = dir + 'ene_fraction_.eps' fig.savefig(fname) plt.show()
def plot_compression_time_temp(species): """ Plot time evolution of compression and shear heating for runs with different plasma temperature Args: species: particle species """ dir = '../data/compression/' dir_jdote = '../data/jdote_data/' if not os.path.isdir('../img/'): os.makedirs('../img/') odir = '../img/compression/' if not os.path.isdir(odir): os.makedirs(odir) base_dirs, run_names = ApJ_long_paper_runs() fig = plt.figure(figsize=[7, 5]) w1, h1 = 0.8, 0.27 xs, ys = 0.96 - w1, 0.97 - h1 gap = 0.02 nrun = len(run_names) ylim1 = np.zeros((nrun, 2)) if species == 'e': ylim1[0, :] = -0.05, 0.15 ylim1[1, :] = -0.3, 1.1 ylim1[2, :] = -1.0, 5 ylim1[3, :] = -10.0, 30.0 ylim1[4, :] = -2.0, 5.0 ylim1[5, :] = -0.1, 0.2 ylim1[6, :] = -0.5, 1.1 ylim1[7, :] = -3.0, 6.0 ylim1[8, :] = -1.0, 5.0 else: ylim1[0, :] = -0.1, 0.25 ylim1[1, :] = -0.6, 2.2 ylim1[2, :] = -2.0, 10 ylim1[3, :] = -20.0, 60.0 ylim1[4, :] = -4.0, 13.0 ylim1[5, :] = -0.2, 0.4 ylim1[6, :] = -1.0, 2.2 ylim1[7, :] = -5.0, 15.0 ylim1[8, :] = -3.0, 7.0 runs = [5, 6, 2] axs = [] for i in runs: run_name = run_names[i] base_dir = base_dirs[i] picinfo_fname = '../data/pic_info/pic_info_' + run_name + '.json' jdote_fname = dir_jdote + 'jdote_' + run_name + '_' + species + '.json' pic_info = read_data_from_json(picinfo_fname) jdote_data = read_data_from_json(jdote_fname) fpath_comp = '../data/compression/' + run_name + '/' b0 = pic_info.b0 ylim2 = ylim1 * b0**2 ax = fig.add_axes([xs, ys, w1, h1]) axs.append(ax) compression_time(pic_info, species, jdote_data, ylim2[i, :], ax, fpath_comp) ys -= h1 + gap for ax in axs: ax.set_xlim([0, 1200]) if species == 'e': axs[0].set_yticks(np.arange(0, 0.007, 0.002)) axs[1].set_yticks(np.arange(0, 0.025, 0.01)) axs[2].set_yticks(np.arange(0, 0.09, 0.02)) else: axs[0].set_yticks(np.arange(0, 0.021, 0.005)) axs[1].set_yticks(np.arange(0, 0.07, 0.02)) axs[2].set_yticks(np.arange(0, 0.17, 0.04)) axs[-1].tick_params(axis='x', labelbottom='on') axs[-1].set_xlabel(r'$t\Omega_{ci}$', fontdict=font, fontsize=20) label1 = r'$-p\nabla\cdot\mathbf{u}$' label2 = r'$-(p_\parallel - p_\perp)b_ib_j\sigma_{ij}$' axs[0].text(0.4, 0.2, label1, color='red', fontsize=20, bbox=dict(facecolor='none', alpha=1.0, edgecolor='none', pad=10.0), horizontalalignment='left', verticalalignment='center', transform=axs[0].transAxes) axs[0].text(0.6, 0.2, label2, color='green', fontsize=20, bbox=dict(facecolor='none', alpha=1.0, edgecolor='none', pad=10.0), horizontalalignment='left', verticalalignment='center', transform=axs[0].transAxes) axs[0].text(0.05, 0.8, r'$v_\text{the}/c=0.045$', color='black', fontsize=20, bbox=dict(facecolor='none', alpha=1.0, edgecolor='none', pad=10.0), horizontalalignment='left', verticalalignment='center', transform=axs[0].transAxes) axs[1].text(0.05, 0.8, r'$v_\text{the}/c=0.08$', color='black', fontsize=20, bbox=dict(facecolor='none', alpha=1.0, edgecolor='none', pad=10.0), horizontalalignment='left', verticalalignment='center', transform=axs[1].transAxes) axs[2].text(0.05, 0.8, r'$v_\text{the}/c=0.14$', color='black', fontsize=20, bbox=dict(facecolor='none', alpha=1.0, edgecolor='none', pad=10.0), horizontalalignment='left', verticalalignment='center', transform=axs[2].transAxes) if not os.path.isdir('../img/'): os.makedirs('../img/') dir = '../img/img_dpp/' if not os.path.isdir(dir): os.makedirs(dir) fname = dir + 'comp_temp_' + species + '.eps' fig.savefig(fname) plt.show()
def plot_energy_conversion_fraction_beta(): """Plot energy evolution for multiple runs with different beta """ picinfo_dir = '../data/pic_info/' mkdir_p(picinfo_dir) odir = '../img/ene_evolution/' mkdir_p(odir) run_names = [ 'sigma1-mime25-beta0002', 'mime25_beta0007', 'mime25_beta002', 'mime25_beta007', 'mime25_beta02' ] labels = [ 'R7\n 0.0002', 'R6\n 0.007', 'R1\n 0.02', 'R7\n 0.07', 'R8\n 0.2' ] run_label = r'$\beta_e = $' fname = 'ene_fraction_beta.eps' # run_names = ['mime25_beta002', 'mime25_beta002_sigma033', # 'mime25_beta002_sigma01'] # labels = ['R1\n $1.0$', 'R2\n $\sqrt{3}$', 'R3\n $\sqrt{10}$'] # run_label = r'$\omega_{pe} / \Omega_{ce} = $' # fname = 'ene_fraction_wpe_wce.eps' nrun = len(run_names) ene_fraction = np.zeros(nrun) dke_dki = np.zeros(nrun) irun = 0 for run_name in run_names: print run_name rname = run_name.replace(".json", ".eps") oname = rname.replace("pic_info", "enes") oname = odir + oname picinfo_fname = picinfo_dir + 'pic_info_' + run_name + '.json' pic_info = read_data_from_json(picinfo_fname) tenergy = pic_info.tenergy ene_magnetic = pic_info.ene_magnetic kene_e = pic_info.kene_e kene_i = pic_info.kene_i dke = kene_e[-1] - kene_e[0] dki = kene_i[-1] - kene_i[0] enorm = ene_magnetic[0] ene_fraction[irun] = 1.0 - ene_magnetic[-1] / enorm dke_dki[irun] = dke / dki irun += 1 x = np.arange(nrun) fig = plt.figure(figsize=[7, 5]) xs, ys = 0.16, 0.13 w1, h1 = 0.7, 0.8 ax = fig.add_axes([xs, ys, w1, h1]) ax.plot(x, ene_fraction, color='r', marker='o', markersize=10, linestyle='', markeredgecolor='r') ax.set_xticks(x) ax.set_xticklabels(labels) ax.set_xlim([-0.5, nrun - 0.5]) ax.set_ylabel(r'$|\Delta\varepsilon_b|/\varepsilon_{b0}$', color='r', fontdict=font, fontsize=24) ax.tick_params(labelsize=20) ax.text(-0.12, -0.12, run_label, color='k', fontsize=20, bbox=dict(facecolor='none', alpha=1.0, edgecolor='none', pad=10.0), horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) for tl in ax.get_yticklabels(): tl.set_color('r') ax1 = ax.twinx() ax1.plot(x, dke_dki, color='b', marker='D', markersize=10, linestyle='', markeredgecolor='b') ax1.set_xlim([-0.5, nrun - 0.5]) ax1.set_ylabel(r'$\Delta K_e/\Delta K_i$', color='b', fontdict=font, fontsize=24) ax1.tick_params(labelsize=20) for tl in ax1.get_yticklabels(): tl.set_color('b') img_dir = '../img/img_dpp/' mkdir_p(img_dir) fig.savefig(img_dir + fname) plt.show()
def plot_jpara_dote_fraction(): """Plot energy evolution from the parallel and perpendicular directions. """ dir = '../data/jdote_data/' if not os.path.isdir('../img/'): os.makedirs('../img/') odir = '../img/jdote/' if not os.path.isdir(odir): os.makedirs(odir) base_dirs, run_names = ApJ_long_paper_runs() run_id = [3, 2, 6, 7, 4, 5, 1, 0] nrun = len(run_id) fraction_jpara_e = np.zeros(nrun) fraction_jpara_i = np.zeros(nrun) fraction_jperp_e = np.zeros(nrun) fraction_jperp_i = np.zeros(nrun) irun = 0 for i in run_id: run_name = run_names[i] picinfo_fname = '../data/pic_info/pic_info_' + run_name + '.json' jdote_e_fname = '../data/jdote_data/jdote_' + run_name + '_e.json' jdote_i_fname = '../data/jdote_data/jdote_' + run_name + '_i.json' pic_info = read_data_from_json(picinfo_fname) kene_e = pic_info.kene_e kene_i = pic_info.kene_i dkene_e = kene_e[-1] - kene_e[0] dkene_i = kene_i[-1] - kene_i[0] jdote_e = read_data_from_json(jdote_e_fname) jdote_i = read_data_from_json(jdote_i_fname) jpara_dote_e = jdote_e.jqnupara_dote_int jperp_dote_e = jdote_e.jqnuperp_dote_int jpara_dote_i = jdote_i.jqnupara_dote_int jperp_dote_i = jdote_i.jqnuperp_dote_int fraction_jpara_e[irun] = jpara_dote_e[-1] / dkene_e fraction_jperp_e[irun] = jperp_dote_e[-1] / dkene_e fraction_jpara_i[irun] = jpara_dote_i[-1] / dkene_i fraction_jperp_i[irun] = jperp_dote_i[-1] / dkene_i irun += 1 x = np.arange(8) fig = plt.figure(figsize=[7, 5]) xs, ys = 0.18, 0.13 w1, h1 = 0.78, 0.8 ax = fig.add_axes([xs, ys, w1, h1]) ax.plot( x, fraction_jpara_e[:8], color='r', marker='o', markersize=10, linestyle='') ax.plot( x, fraction_jpara_i[:8], color='b', marker='o', markersize=10, linestyle='') labels = [r'R6', r'R1', r'R2', r'R4', r'R5', r'R3', r'R7', r'R8'] ax.set_xticks(x) ax.set_xticklabels(labels) ax.set_xlim([-0.5, 7.5]) ax.set_ylabel( r'Fraction of Parallel Acceleration', fontdict=font, fontsize=24) ax.tick_params(labelsize=20) ax.text( 0.05, 0.15, r'Electron', color='r', fontsize=24, bbox=dict( facecolor='none', alpha=1.0, edgecolor='none', pad=10.0), horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) ax.text( 0.05, 0.25, r'Ion', color='b', fontsize=24, bbox=dict( facecolor='none', alpha=1.0, edgecolor='none', pad=10.0), horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) if not os.path.isdir('../img/'): os.makedirs('../img/') dir = '../img/img_dpp/' if not os.path.isdir(dir): os.makedirs(dir) fname = dir + 'para_acc_fraction.eps' fig.savefig(fname) plt.show()
def plot_energy_conversion_fraction_beta(): """Plot energy evolution for multiple runs with different beta """ picinfo_dir = '../data/pic_info/' mkdir_p(picinfo_dir) odir = '../img/ene_evolution/' mkdir_p(odir) run_names = [ 'sigma1-mime25-beta0002', 'mime25_beta0007', 'mime25_beta002', 'mime25_beta007', 'mime25_beta02' ] labels = [ 'R7\n 0.0002', 'R6\n 0.007', 'R1\n 0.02', 'R7\n 0.07', 'R8\n 0.2' ] run_label = r'$\beta_e = $' fname = 'ene_fraction_beta.eps' # run_names = ['mime25_beta002', 'mime25_beta002_sigma033', # 'mime25_beta002_sigma01'] # labels = ['R1\n $1.0$', 'R2\n $\sqrt{3}$', 'R3\n $\sqrt{10}$'] # run_label = r'$\omega_{pe} / \Omega_{ce} = $' # fname = 'ene_fraction_wpe_wce.eps' nrun = len(run_names) ene_fraction = np.zeros(nrun) dke_dki = np.zeros(nrun) irun = 0 for run_name in run_names: print run_name rname = run_name.replace(".json", ".eps") oname = rname.replace("pic_info", "enes") oname = odir + oname picinfo_fname = picinfo_dir + 'pic_info_' + run_name + '.json' pic_info = read_data_from_json(picinfo_fname) tenergy = pic_info.tenergy ene_magnetic = pic_info.ene_magnetic kene_e = pic_info.kene_e kene_i = pic_info.kene_i dke = kene_e[-1] - kene_e[0] dki = kene_i[-1] - kene_i[0] enorm = ene_magnetic[0] ene_fraction[irun] = 1.0 - ene_magnetic[-1] / enorm dke_dki[irun] = dke / dki irun += 1 x = np.arange(nrun) fig = plt.figure(figsize=[7, 5]) xs, ys = 0.16, 0.13 w1, h1 = 0.7, 0.8 ax = fig.add_axes([xs, ys, w1, h1]) ax.plot( x, ene_fraction, color='r', marker='o', markersize=10, linestyle='', markeredgecolor='r') ax.set_xticks(x) ax.set_xticklabels(labels) ax.set_xlim([-0.5, nrun - 0.5]) ax.set_ylabel( r'$|\Delta\varepsilon_b|/\varepsilon_{b0}$', color='r', fontdict=font, fontsize=24) ax.tick_params(labelsize=20) ax.text( -0.12, -0.12, run_label, color='k', fontsize=20, bbox=dict( facecolor='none', alpha=1.0, edgecolor='none', pad=10.0), horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) for tl in ax.get_yticklabels(): tl.set_color('r') ax1 = ax.twinx() ax1.plot( x, dke_dki, color='b', marker='D', markersize=10, linestyle='', markeredgecolor='b') ax1.set_xlim([-0.5, nrun - 0.5]) ax1.set_ylabel( r'$\Delta K_e/\Delta K_i$', color='b', fontdict=font, fontsize=24) ax1.tick_params(labelsize=20) for tl in ax1.get_yticklabels(): tl.set_color('b') img_dir = '../img/img_dpp/' mkdir_p(img_dir) fig.savefig(img_dir + fname) plt.show()
vi = np.fromfile(fname, dtype=np.float32) vs = (ve * ne + vi * ni * mime) * inrho vs.tofile(fdir + 'vy.gda') fname = run_dir + 'data/vez.gda' ve = np.fromfile(fname, dtype=np.float32) fname = run_dir + 'data/viz.gda' vi = np.fromfile(fname, dtype=np.float32) vs = (ve * ne + vi * ni * mime) * inrho vs.tofile(fdir + 'vz.gda') if __name__ == "__main__": cmdargs = sys.argv if (len(cmdargs) > 2): run_dir = cmdargs[1] run_name = cmdargs[2] else: run_dir = '/net/scratch3/xiaocanli/reconnection/mime25-sigma1-beta002-guide00-200-100/' run_name = 'mime25_beta002_guide00' picinfo_fname = '../data/pic_info/pic_info_' + run_name + '.json' pic_info = read_data_from_json(picinfo_fname) mime = pic_info.mime calc_vsingle(run_dir, mime) def processInput(job_id): print job_id ncores = multiprocessing.cpu_count() # Parallel(n_jobs=ncores)(delayed(processInput)(rank) for rank in ranks)
def plot_particle_number(): """ """ temp = 0.73 l0 = 0.13 # length in meter potentials = [50, 100, 150, 200, 200] run_names = ['v50', 'v100', 'v150', 'v200', 'v200_b0_wce'] nes = [1.4E6, 1.45E6, 1.48E6, 1.48E6, 1.48E6] # in cm^-3 lnames = ['50 V', '100 V', '150 V', '200 V', '200 V, B=0'] fig = plt.figure(figsize=[7, 5]) xs, ys = 0.13, 0.13 w1, h1 = 0.8, 0.8 ax = fig.add_axes([xs, ys, w1, h1]) tmax = 0 current_mean = [] for potential, ne, run_name, lname in zip(potentials, nes, run_names, lnames): # run_name = 'v' + str(potential) picinfo_fname = '../data/pic_info/pic_info_' + run_name + '.json' pic_info = read_data_from_json(picinfo_fname) fname = '../data/particle_number/nptl_' + run_name + '.dat' data = np.genfromtxt(fname) t = data[:, 0] dt = t[1] - t[0] ntot = data[:, 1:] dne = np.gradient(ntot[:, 0], axis=0) wpe = 1.78E9 * math.sqrt(ne / n0) # ne is normalized by n0 dt /= wpe ntot = pic_info.nx * pic_info.nz * pic_info.nppc smime = math.sqrt(pic_info.mime) lx_de = pic_info.lx_di * smime lz_de = pic_info.lz_di * smime de = c0 * 1E3 / wpe vol = lx_de * lz_de * de**2 # assume the third dimension is 1 meter dne_real = dne * ne * 1E6 * vol / ntot current = -dne_real * qe / dt current *= 1E3 # A -> mA lname = str(potential) + 'V' ax.plot(t, current * l0, linewidth=2, label=lname) tmax = max(t.max(), tmax) current_mean.append(np.mean(current[-20:])) ax.tick_params(labelsize=16) ax.set_xlabel(r'$t\omega_{pe}$', fontdict=font, fontsize=20) ax.set_ylabel(r'$I$/mA', fontdict=font, fontsize=20) leg = ax.legend(loc=1, prop={'size': 20}, ncol=1, shadow=False, fancybox=False, frameon=False) ax.set_xlim([0, tmax]) ax.set_ylim([0, 1]) fig.savefig('../img/current_time.eps') fig.savefig('../img/current_time.jpg', dpi=300) r0 = 0.0925E-2 # in meter area = 2 * math.pi * r0 # Assume 1m length current_mean = np.asarray(current_mean) current_mean /= area current_thermal = np.asarray([29.9, 31.2, 31.8, 31.8, 31.8]) # mA/m^2 potential = np.asarray([50, 100, 150, 200, 200]) fig = plt.figure(figsize=[7, 5]) xs, ys = 0.13, 0.13 w1, h1 = 0.8, 0.8 ax = fig.add_axes([xs, ys, w1, h1]) current_norm = current_mean / current_thermal ax.plot(potential / temp, current_norm, linewidth=2, marker='o', markersize=10) ax.tick_params(labelsize=16) ax.set_xlabel('body bias / electron temperature', fontdict=font, fontsize=20) ax.set_ylabel('collected current / thermal current', fontdict=font, fontsize=20) fig.savefig('../img/current_potential.eps') fig.savefig('../img/current_potential.jpg', dpi=300) plt.show()