示例#1
0
def test_current_push():
    NX   = 32      #const.NX
    xmin = 0.0     #const.xmin
    xmax = 2*np.pi #const.xmax
    k    = 1.0
    marker_size = 20
    
    dx      = xmax / NX
    x       = np.arange(xmin, xmax, dx/100.)
    E_nodes = (np.arange(NX + 3) - 0.5) * dx
    B_nodes = (np.arange(NX + 3) - 1.0) * dx
        
    E_in    = np.zeros((NX + 3, 3))
    J_in    = np.zeros((NX + 3, 3))
    L_in    = np.ones((NX + 3))         # Charge-like  (const.)
    G_in    = np.ones((NX + 3, 3))      # Current-like (const.)
    
    Be       = np.zeros((NX + 3, 3))
    Be[:, 0] = np.sin(1.0*E_nodes*k)
    Be[:, 1] = np.sin(2.0*E_nodes*k)
    Be[:, 2] = np.sin(3.0*E_nodes*k)
    
    B       = np.zeros((NX + 3, 3))
    B[:, 0] = np.sin(1.0*B_nodes*k)
    B[:, 1] = np.sin(2.0*B_nodes*k)
    B[:, 2] = np.sin(3.0*B_nodes*k)
    
    DT        = 2.0
    
    J_out = sources.push_current(J_in, E_in, B, L_in, G_in, DT)
    
    J_an       = np.zeros((NX + 3, 3))
    J_an[:, 0] = Be[:, 2] - Be[:, 1]
    J_an[:, 1] = Be[:, 0] - Be[:, 2]
    J_an[:, 2] = Be[:, 1] - Be[:, 0]

    if True:
        plt.figure()
        plt.scatter(E_nodes, J_an[:, 0], s=marker_size, c='k', marker='o')
        plt.scatter(E_nodes, J_an[:, 1], s=marker_size, c='k', marker='o')
        plt.scatter(E_nodes, J_an[:, 2], s=marker_size, c='k', marker='o')
    
        plt.scatter(E_nodes, J_out[:, 0], s=marker_size, c='r', marker='x')
        plt.scatter(E_nodes, J_out[:, 1], s=marker_size, c='r', marker='x')
        plt.scatter(E_nodes, J_out[:, 2], s=marker_size, c='r', marker='x')
    
        for kk in range(NX + 3):
            plt.axvline(E_nodes[kk], linestyle='--', c='r', alpha=0.2)
            plt.axvline(B_nodes[kk], linestyle='--', c='b', alpha=0.2)
            
            plt.axvline(xmin, linestyle='-', c='k', alpha=0.2)
            plt.axvline(xmax, linestyle='-', c='k', alpha=0.2)
        
        plt.xlim(xmin - 1.5*dx, xmax + 2*dx)
        plt.legend()
    return
示例#2
0
文件: main_1D.py 项目: cycle13/hybrid
    qq = 0
    while qq < max_inc:
        part, qq, DT, max_inc, data_dump_iter, plot_dump_iter, change_flag = aux.check_timestep(
            qq, DT, part, B, E, dns_int, max_inc, data_dump_iter,
            plot_dump_iter)

        if change_flag == 1:
            print(
                'Timestep halved. Syncing particle velocity/position with DT = {}'
                .format(DT))
            part, dns_int, dns_half, J_plus, J_minus, G, L = sources.init_collect_moments(
                part, 0.5 * DT)

        B = fields.cyclic_leapfrog(B, dns_int, J_minus, DT)
        E = fields.calculate_E(B, J_minus, dns_half)
        J = sources.push_current(J_plus, E, B, L, G, DT)
        E = fields.calculate_E(B, J, dns_half)

        part = particles.velocity_update(part, B, E, DT)

        part, dns_int, J_plus, J_minus, G, L = sources.collect_moments(
            part, DT)

        dns_int = 0.5 * (dns_int + dns_half)
        J = 0.5 * (J_plus + J_minus)
        B = fields.cyclic_leapfrog(B, dns_int, J, DT)

        if qq % data_dump_iter == 0 and generate_data == 1:  # Save data, if flagged
            pas.save_data(DT, data_dump_iter, qq, part, J, E, B, dns_int)

        if qq % plot_dump_iter == 0 and generate_plots == 1:  # Generate and save plots, if flagged