Example #1
0
def plot_theory(v0, mass_ratio):
    alpha = np.linspace(0, 5, num=200)
    if v0 > 5.0:
        print('v0 should be <= 5.0')
        return
    #rmass=1.0/100.0
    rmass = mass_ratio
    #v0=3.0

    growth_rate = osiris.buneman_growth_rate(alpha, rmass)

    growth_rate_func = interp1d(alpha, np.abs(growth_rate), kind='cubic')

    karray = np.arange(0.01, 1.0, 0.01)
    nk = 49
    growth_rate = np.zeros(nk)
    growth_rate = growth_rate_func(karray * v0)
    maxgr = max(growth_rate)
    print("Max growth rate is {:.3f}, occurring at k = {:.2f}".format(
        maxgr, karray[np.argmax(growth_rate)]))
    print("Instability edge is at k = {:.2f}".format(
        karray[np.where(growth_rate < 0.001)[0]][0]))
    plt.figure(figsize=(8, 5))
    plt.plot(karray,
             growth_rate,
             label='Theory: $v_0 = ' + repr(v0) + '$,\n' +
             'mass ratio $m/M = ' + repr(rmass) + '$')

    plt.xlabel('Wavenumber [$1/\Delta x$]', **axis_font)
    plt.ylabel('Growth Rate [$\omega_{pe}$]', **axis_font)
    plt.legend()
    plt.show()
Example #2
0
def plot_theory(v0=10.0, density_ratio=1 / 100):
    alpha = np.linspace(0, 20, num=200)
    rmass = density_ratio
    growth_rate = osiris.buneman_growth_rate(alpha, rmass)

    growth_rate_func = interp1d(alpha, np.abs(growth_rate), kind='cubic')

    #v0=10.0

    c = rmass

    karray = np.arange(0.0005, 1, 0.005)
    nk = 49
    growth_rate = np.zeros(nk)
    growth_rate = growth_rate_func(karray * v0)
    plt.figure(figsize=(8, 5))
    plt.plot(karray,
             growth_rate,
             label='Theory: $v_0 = ' + repr(v0) + '$,\n' +
             'den ratio $n_b/n_0 = ' + repr(c) + '$')

    plt.xlabel('Wavenumber [$1/\Delta x$]', **axis_font)
    plt.ylabel('Growth Rate [$\omega_{pe}$]', **axis_font)
    plt.legend()
    plt.show()
Example #3
0
def get_theory(v0, mass_ratio):
    alpha = np.linspace(0, 5, num=200)
    if v0 > 5.0:
        print('v0 should be <= 5.0')
        return
    #rmass=1.0/100.0
    rmass = mass_ratio
    #v0=3.0

    growth_rate = osiris.buneman_growth_rate(alpha, rmass)

    growth_rate_func = interp1d(alpha, np.abs(growth_rate), kind='cubic')

    karray = np.arange(0.01, 1.0, 0.01)
    nk = 49
    growth_rate = np.zeros(nk)
    growth_rate = growth_rate_func(karray * v0)
    maxgr = max(growth_rate)

    return maxgr, karray[np.argmax(growth_rate)], karray[np.where(
        growth_rate < 0.001)[0]][0]
Example #4
0
def compare_sim_with_theory(output_directory, v0, mode, mass_ratio):

    alpha = np.arange(0, 2.0, 0.01)
    rmass = mass_ratio

    growth_rate = osiris.buneman_growth_rate(alpha, rmass)

    growth_rate_func = interp1d(alpha, np.abs(growth_rate), kind='cubic')

    workdir = os.getcwd()
    dirname = output_directory
    filename = workdir + '/' + dirname + '/Ex.h5'
    test4 = h5_utilities.read_hdf(filename)

    k_data = np.fft.fft(test4.data, axis=1)

    test4.data = np.abs(k_data)
    test4.axes[0].axis_max = 2.0 * 3.1415926

    nx = test4.data.shape[1]
    nt = test4.data.shape[0]

    dk = 2 * 3.1415926 / nx

    display_mode = mode
    bracket = False

    #v0=3.0

    alpha = v0 * dk * (display_mode)
    # growth_rate = 0.0
    # if (alpha<np.sqrt(2)):

    growth_rate = growth_rate_func(alpha)[()]

    taxis = np.linspace(0, test4.axes[1].axis_max, nt)
    stream_theory = np.zeros(nt)
    stream_theory_plus = np.zeros(nt)
    stream_theory_minus = np.zeros(nt)
    init_amplitude = 1e-7
    for it in range(0, nt):
        stream_theory[it] = init_amplitude * np.exp(growth_rate * taxis[it])
        stream_theory_plus[it] = init_amplitude * np.exp(
            1.15 * growth_rate * taxis[it])
        stream_theory_minus[it] = init_amplitude * np.exp(
            0.85 * growth_rate * taxis[it])

    plt.figure(figsize=(8, 6))
    plt.semilogy(taxis,
                 test4.data[:, display_mode],
                 label='PIC simulation, mode =' + repr(display_mode))
    plt.semilogy(taxis,
                 stream_theory,
                 'r',
                 label='theory, growth rate =' + '%.3f' % growth_rate)

    if (bracket):
        plt.semilogy(taxis, stream_theory_plus, 'g.')

        plt.semilogy(taxis, stream_theory_minus, 'g.')

    plt.ylim((1e-7, 1000))
    plt.legend()
    plt.xlabel('Time $[1/\omega_{pe}]$', **axis_font)
    plt.ylabel('Time History [a.u.]', **axis_font)

    plt.show()
Example #5
0
def compare_sim_with_theory(output_directory, v0, mode, density_ratio):

    alpha = np.linspace(0, 20, num=200)
    rmass = density_ratio
    growth_rate = osiris.buneman_growth_rate(alpha, rmass)

    growth_rate_func = interp1d(alpha, np.abs(growth_rate), kind='cubic')

    workdir = os.getcwd()
    dirname = output_directory
    filename = workdir + '/' + dirname + '/Ex.h5'
    # print(filename)
    test4 = h5_utilities.read_hdf(filename)
    # here we fourier analyze the data in space
    #
    # k_data=np.fft.fft(test.data,axis=1)
    k_data = np.fft.fft(test4.data, axis=1)
    # k_data_2=np.fft.fft(k_data,axis=0)

    test4.data = np.abs(k_data)

    test4.axes[0].axis_max = 2.0 * 3.1415926

    nx = test4.data.shape[1]
    nt = test4.data.shape[0]
    # print(repr(nt))
    dk = 2 * 3.1415926 / nx
    # print('Delta k = '+repr(dk))

    # To compare with theory, just specify the mode you want to look at here
    #
    display_mode = mode
    bracket = False
    #
    #

    #v0=10.0

    alpha = v0 * dk * (display_mode)
    # growth_rate = 0.0
    # if (alpha<np.sqrt(2)):
    growth_rate = growth_rate_func(alpha)[()]

    taxis = np.linspace(0, test4.axes[1].axis_max, nt)
    stream_theory = np.zeros(nt)
    stream_theory_plus = np.zeros(nt)
    stream_theory_minus = np.zeros(nt)
    init_amplitude = 1e-7
    for it in range(0, nt):
        stream_theory[it] = init_amplitude * np.exp(growth_rate * taxis[it])
        stream_theory_plus[it] = init_amplitude * np.exp(
            1.15 * growth_rate * taxis[it])
        stream_theory_minus[it] = init_amplitude * np.exp(
            0.85 * growth_rate * taxis[it])

    plt.figure(figsize=(8, 5))
    plt.semilogy(taxis,
                 test4.data[:, display_mode],
                 label='PIC simulation, mode =' + repr(display_mode))
    plt.semilogy(taxis,
                 stream_theory,
                 'r',
                 label='theory, growth rate =' + '%.3f' % growth_rate)

    if (bracket):
        plt.semilogy(taxis, stream_theory_plus, 'g.')

        plt.semilogy(taxis, stream_theory_minus, 'g.')

    plt.ylim((1e-7, 1000))
    plt.legend()
    plt.xlabel('Time $[1/\omega_{pe}]$', **axis_font)
    plt.ylabel('Mode amplitude [a.u.]', **axis_font)

    plt.show()