コード例 #1
0
def calc_reconnection_rate(base_dir):
    """Calculate reconnection rate.

    Args:
        base_dir: the directory base.
    """
    pic_info = pic_information.get_pic_info(base_dir)
    ntf = pic_info.ntf
    phi = np.zeros(ntf)
    fname = base_dir + 'data/Ay.gda'
    for ct in range(ntf):
        kwargs = {"current_time": ct, "xl": 0, "xr": 200, "zb": -1, "zt": 1}
        x, z, Ay = read_2d_fields(pic_info, fname, **kwargs)
        nz, = z.shape
        # max_ay = np.max(np.sum(Ay[nz/2-1:nz/2+1, :], axis=0)/2)
        # min_ay = np.min(np.sum(Ay[nz/2-1:nz/2+1, :], axis=0)/2)
        max_ay = np.max(Ay[nz / 2 - 1:nz / 2 + 1, :])
        min_ay = np.min(Ay[nz / 2 - 1:nz / 2 + 1, :])
        phi[ct] = max_ay - min_ay
    nk = 3
    phi = signal.medfilt(phi, kernel_size=nk)
    dtwpe = pic_info.dtwpe
    dtwce = pic_info.dtwce
    dtwci = pic_info.dtwci
    mime = pic_info.mime
    dtf_wpe = pic_info.dt_fields * dtwpe / dtwci
    reconnection_rate = np.gradient(phi) / dtf_wpe
    b0 = pic_info.b0
    va = dtwce * math.sqrt(1.0 / mime) / dtwpe
    reconnection_rate /= b0 * va
    reconnection_rate[-1] = reconnection_rate[-2]
    tfields = pic_info.tfields

    return (tfields, reconnection_rate)
コード例 #2
0
    def __init__(self, **kwargs):
        self.var_field = kwargs['var_field']
        self.var_name = kwargs['var_name']
        self.ct = kwargs['ct']
        self.field_range = kwargs['field_range']
        self.pic_info = pic_information.get_pic_info('../../')
        self.read_field_data()
        self.nptl = kwargs['nptl']
        self.iptl = kwargs['iptl']
        self.species = kwargs['species']
        self.traj_names = kwargs['traj_names']
        self.emin = kwargs['emin']
        self.emax = kwargs['emax']
        self.ymin = kwargs['ymin']
        self.ymax = kwargs['ymax']
        self.indicator_color = kwargs['indicator_color']
        self.ptl = read_traj_data(self.traj_names[self.iptl])
        self.smime = math.sqrt(self.pic_info.mime)
        self.ct_ptl = np.zeros(3, dtype='int')
        for i in range(3):
            self.ct_ptl[i] = self.ct[i] * \
                    self.pic_info.fields_interval / self.pic_info.trace_interval
        self.lx_di = self.pic_info.lx_di
        self.ly_di = self.pic_info.ly_di
        self.xmax1 = np.max(self.x1)
        self.zmax1 = np.max(self.z1)
        self.xmin1 = np.min(self.x1)
        self.zmin1 = np.min(self.z1)
        self.xmax2 = np.max(self.x2)
        self.zmax2 = np.max(self.z2)
        self.xmin2 = np.min(self.x2)
        self.zmin2 = np.min(self.z2)
        self.xmax3 = np.max(self.x3)
        self.zmax3 = np.max(self.z3)
        self.xmin3 = np.min(self.x3)
        self.zmin3 = np.min(self.z3)
        self.calc_derived_particle_info()
        self.get_particle_current_time()

        if self.species == 'e':
            self.threshold_ene = 0.5
        else:
            self.threshold_ene = 0.05

        # For saving figures
        if not os.path.isdir('../img/'):
            os.makedirs('../img/')
        self.fig_dir = '../img/img_traj_apj/'
        if not os.path.isdir(self.fig_dir):
            os.makedirs(self.fig_dir)

        self.fig_width = 7
        self.energy_plot()
        self.energy_plot_indicator()
        self.save_figures()
コード例 #3
0
def save_particle_number():
    """Save PIC information and particle number information
    """
    root_dir = '/net/scratch3/xiaocanli/herts/tether_potential_tests/'
    # run_names = ['v50', 'v100', 'v150', 'v200']
    run_names = ['v200_b0_wce']
    mkdir_p('../data/pic_info/')
    mkdir_p('../data/particle_number/')
    for run_name in run_names:
        fdir = root_dir + run_name + '/'
        pic_info = pic_information.get_pic_info(fdir)
        pic_info_json = data_to_json(pic_info)
        fname = '../data/pic_info/pic_info_' + run_name + '.json'
        with open(fname, 'w') as f:
            json.dump(pic_info_json, f)
        t, ntot = read_particle_number(fdir, pic_info)
        fname = '../data/particle_number/nptl_' + run_name + '.dat'
        data = np.column_stack((t, ntot))
        np.savetxt(fname, data)
コード例 #4
0
def traj_sigma1():
    """
    """
    # base_directory = '../../'
    base_directory = '/net/scratch2/guofan/sigma1-mime25-beta001/'
    pic_info = pic_information.get_pic_info(base_directory)
    ntp = pic_info.ntp
    vthe = pic_info.vthe
    particle_interval = pic_info.particle_interval
    pos = [pic_info.lx_di / 10, 0.0, 2.0]
    corners, mpi_ranks = set_mpi_ranks(pic_info, pos)
    ct = 5 * particle_interval
    get_particle_distribution(base_directory, pic_info, ct, corners, mpi_ranks)
    smime = math.sqrt(pic_info.mime)
    lx_de = pic_info.lx_di * smime
    center = [0.5 * lx_de, 0, 0]
    sizes = [256, 1, 256]
    kwargs = {
        'center': center,
        'sizes': sizes,
        'nbins': 64,
        'vmax': 2.0,
        'vmin': 0,
        'tframe': 10,
        'species': 'e'
    }
    # get_spectrum_vdist(pic_info, **kwargs)
    species = 'e'
    ct = 10
    fpath = base_directory + 'pic_analysis/' + 'vdistributions/'
    fname_1d = 'vdist_1d-' + species + '.' + str(ct)
    fname_2d = 'vdist_2d-' + species + '.' + str(ct)
    fvel = read_velocity_distribution('e', ct, pic_info, fname_1d, fname_2d,
                                      fpath)
    fpath = base_directory + 'pic_analysis/' + 'spectrum/'
    fname_ene = 'spectrum-' + species + '.' + str(ct)
    fene = read_energy_distribution('e', ct, pic_info, fname_ene, fpath)
    plot_ptl_vdist('e', pic_info, base_directory)
コード例 #5
0
        ax.text(0.05,
                0.8,
                tags[i],
                color='k',
                fontsize=20,
                horizontalalignment='left',
                verticalalignment='center',
                transform=ax.transAxes)
        ys -= h1 + gap
    ax.set_xlabel(r'$t\Omega_{ci}$', fontdict=font, fontsize=20)
    if not os.path.isdir('../img/'):
        os.makedirs('../img/')
    fig_dir = '../img/img_traj_apj/'
    if not os.path.isdir(fig_dir):
        os.makedirs(fig_dir)
    fname = fig_dir + 'tene_i.eps'
    fig.savefig(fname)
    plt.show()


if __name__ == "__main__":
    pic_info = pic_information.get_pic_info('../../')
    ntp = pic_info.ntp
    vthe = pic_info.vthe
    print("Number of field frames: %d" % pic_info.ntf)
    fnames_e, fnames_i = get_file_names()
    # plot_electron_trajectory(fnames_e, 'e', pic_info)
    # plot_ion_trajectory(fnames_i, 'i', pic_info)
    plot_particle_energies(fnames_e, 'e', pic_info)
    # plot_ions_energies(fnames_i, 'e', pic_info)
コード例 #6
0
import os.path
import struct

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import rc
from matplotlib.colors import LogNorm
from matplotlib.ticker import MaxNLocator
from mpl_toolkits.axes_grid1 import make_axes_locatable
from mpl_toolkits.mplot3d import Axes3D

import pic_information

rc('font', **{'family': 'serif', 'serif': ['Computer Modern']})
mpl.rc('text', usetex=True)
mpl.rcParams['text.latex.preamble'] = [r"\usepackage{amsmath}"]

font = {
    'family': 'serif',
    #'color'  : 'darkred',
    'color': 'black',
    'weight': 'normal',
    'size': 24,
}

if __name__ == "__main__":
    pic_info = pic_information.get_pic_info()
    ntp = pic_info.ntp
    vthe = pic_info.ntp
コード例 #7
0
    def __init__(self, nptl, iptl, x, y, fdata, Ay, init_ft, var_field,
                 var_name, species, traj_names):
        """
        Args:
            nptl: number of particles.
            x, y: the x, y coordinates for the 2D fields.
            fdata: the field data array.
            Ay: y component of the vector potential.
            init_ft: the initial field time frame.
            var_field: the name of the field data for reading.
            var_name: the name of the field for labeling.
            species: particle species.
            traj_names: the names of the trajectory files.
            iptl: particle index for current plot.
        """
        self.x = x
        self.y = y
        self.fdata = fdata
        self.Ay = Ay
        self.nptl = nptl
        self.ct = init_ft
        self.iptl = iptl
        self.var_field = var_field
        self.var_name = var_name
        self.species = species
        self.traj_names = traj_names
        self.ptl = read_traj_data(self.traj_names[self.iptl])
        self.pic_info = pic_information.get_pic_info('../../')
        self.smime = math.sqrt(self.pic_info.mime)
        self.ct_ptl = self.ct * \
                self.pic_info.fields_interval / self.pic_info.trace_interval
        self.lx_di = self.pic_info.lx_di
        self.ly_di = self.pic_info.ly_di
        self.xmax = np.max(self.x)
        self.ymax = np.max(self.y)
        self.xmin = np.min(self.x)
        self.ymin = np.min(self.y)
        self.calc_derived_particle_info()
        self.get_particle_current_time()

        if self.species == 'e':
            self.threshold_ene = 0.5
        else:
            self.threshold_ene = 0.05

        # For saving figures
        if not os.path.isdir('../img/'):
            os.makedirs('../img/')
        self.fig_dir = '../img/img_traj_' + species + '/'
        if not os.path.isdir(self.fig_dir):
            os.makedirs(self.fig_dir)
        self.fig_dir_energetic = '../img/img_traj_energetic_' + species + '/'
        if not os.path.isdir(self.fig_dir_energetic):
            os.makedirs(self.fig_dir_energetic)

        self.fig_width = 10
        self.energy_plot()
        self.energy_plot_indicator()
        # self.fields_plot()
        # self.jdote_plot()
        self.save_figures()
コード例 #8
0
        interpolation='bicubic')
    divider = make_axes_locatable(ax)
    cax = divider.append_axes("right", size="5%", pad=0.05)
    cbar = fig.colorbar(p1, cax=cax)
    cbar.ax.tick_params(labelsize=16)
    ax.set_ylabel(r'$y/d_i$', fontdict=font, fontsize=20)
    ax.set_xlabel(r'$x/d_i$', fontdict=font, fontsize=20)
    ax.tick_params(labelsize=16)
    fname = r'$t\omega_{pe} = ' + str(tindex) + '$'
    cbar.ax.set_ylabel(
        r'$\boldsymbol{j}\cdot\boldsymbol{E}$', fontdict=font, fontsize=20)


if __name__ == "__main__":
    root_dir = '../../'
    pic_info = pic_information.get_pic_info(root_dir)
    fint = pic_info.fields_interval
    ny = pic_info.ny
    ct = fint * 10
    ntf = pic_info.ntf
    print ntf
    itf = 25
    for ct in range(itf, itf + 1):
        # for ct in range(ntf):
        print ct
        tindex = ct * fint
        # fname = root_dir + 'data/jz_' + str(tindex) + '.gda'
        # # plot_3d_fields(pic_info, fname, ny/2, tindex)
        plot_vsingle(pic_info, root_dir, ny / 2, tindex, fint)
        plot_j_jdote(pic_info, root_dir, ny / 2, tindex, fint)
        # if not os.path.isdir('../img/'):
コード例 #9
0
    dmin = -100.0
    dmax = 100.0
    nb = 1000
    print np.sum(field_data)
    bins = np.linspace(dmin, dmax, nb)
    hist, bin_edges = np.histogram(field_data, bins)
    print np.sum(hist)
    print 'Maximum and Minimum of the field: ', dmax, dmin
    fig = plt.figure(figsize=[7, 5])
    width = 0.8
    height = 0.8
    ax = fig.add_axes([0.12, 0.15, width, height])
    hist_f = np.array(hist, dtype=np.float64)
    hist_f /= np.max(hist_f)
    p1 = ax.semilogy(bins[:nb - 1], hist_f, linewidth=2)
    ax.tick_params(labelsize=16)
    ax.set_xlabel(var_name, fontdict=font, fontsize=20)
    qname = r'$f($' + var_name + '$)$'
    ax.set_ylabel(qname, fontdict=font, fontsize=20)
    plt.show()


if __name__ == "__main__":
    pic_info = pic_information.get_pic_info("../../")
    kwargs = {"current_time": 40, "xl": 0, "xr": 400, "zb": -100, "zt": 100}
    #histogram_field(pic_info, r'$n_e$', "../data/ne.gda", **kwargs)
    #histogram_field(pic_info, r'$|\mathbf{B}|$', "../data/absB.gda", **kwargs)
    # histogram_field(pic_info, r'$A_e$', "../data1/agyrotropy00_e.gda", **kwargs)
    histogram_field(pic_info, r'$A_e$', "../../data1/jpolar_dote00_e.gda",
                    **kwargs)