Esempio n. 1
0
def test_CAM_CL():
    
    grids  = [16, 32, 64, 128, 256, 512, 1024]
    errors = np.zeros(len(grids))
    
    NX   = 32      #const.NX
    xmin = 0.0     #const.xmin
    xmax = 2*np.pi #const.xmax
    k    = 1.0
    marker_size = 20
    
    #for NX, ii in zip(grids, range(len(grids))):
    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
        
    B       = np.zeros((NX + 3, 3))
    n_i     = np.ones((NX + 3)) 
    J_i     = np.ones((NX + 3, 3))
    
    DT        = 1.0
    subcycles = 25
    
    new_B = fields.cyclic_leapfrog(B, n_i, J_i, DT, subcycles)
    
    return
Esempio n. 2
0
def test_CAM_CL():
    NX      = 32
    B       = np.zeros((NX + 3, 3))
    rho_i   = np.ones((NX + 3)) 
    J_i     = np.zeros((NX + 3, 3))
    
    DT        = 0.1
    subcycles = 8
    
    E, V, T = fields.calculate_E(B, J_i, rho_i)

    B, E_half, Ve_half, Te_half = fields.cyclic_leapfrog(B, rho_i, J_i, DT, subcycles, half_cycle=True)

    return
Esempio n. 3
0
        part, 0.5 * DT)

    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)
Esempio n. 4
0
                                             ni_init, nu_init, ni, nu_plus,
                                             rho_int, rho_half, J, J_plus, L,
                                             G, 0.5 * DT)

        # Debug: Test if everything is the same if J is replaced with J_minus at each loop.
        # Yes it is after loop 0 and loop 1 up until collect_moments()
        # Disable this at some point and see if it improves (or even changes) anything.
# =============================================================================
#         if qq > 0:
#             J[:, :] = J_minus[:, :]
# =============================================================================

#######################
###### MAIN LOOP ######
#######################
        fields.cyclic_leapfrog(B, B2, rho_int, J, temp3d, DT, subcycles)
        E, Ve, Te = fields.calculate_E(B, J, rho_half)

        sources.push_current(J_plus, J, E, B, L, G, DT)
        E, Ve, Te = fields.calculate_E(B, J, rho_half)

        particles.velocity_update(pos, vel, Ie, W_elec, Ib, W_mag, idx, Ep, Bp,
                                  B, E, v_prime, S, T, temp_N, DT)

        # Store pc(1/2) here while pc(3/2) is collected
        rho_int[:] = rho_half[:]
        sources.collect_moments(pos, vel, Ie, W_elec, idx, ni, nu_plus,
                                nu_minus, rho_half, J_minus, J_plus, L, G, DT)

        rho_int += rho_half
        rho_int /= 2.0
Esempio n. 5
0
    DT, max_inc, data_iter, plot_iter, subcycles = aux.set_timestep(vel)

    q_dens, Ji    = sources.collect_moments(vel, Ie, W_elec, idx)
    E_int, Ve, Te = fields.calculate_E(B, Ji, q_dens)
    vel           = particles.velocity_update(pos, vel, Ie, W_elec, idx, B, E_int, -0.5*DT)
    
    qq      = 0
    while qq < max_inc:
        # Check timestep
        pos, vel, qq, DT, max_inc, data_iter, plot_iter, subcycles \
        = aux.check_timestep(qq, DT, pos, vel, B, E_int, q_dens, Ie, W_elec, max_inc, data_iter, plot_iter, subcycles, idx)
        
        # Main loop
        pos, vel, Ie, W_elec, q_dens_adv, Ji = particles.advance_particles_and_moments(pos, vel, Ie, W_elec, idx, B, E_int, DT)
        q_dens                               = 0.5 * (q_dens + q_dens_adv)
        B, E_half, Ve, Te                    = fields.cyclic_leapfrog(B, q_dens, Ji, DT, subcycles)
        q_dens                               = q_dens_adv.copy()
        
        # Predictor-Corrector: Advance fields to start of next timestep
        E_int = fields.predictor_corrector(B, E_int, E_half, pos, vel, q_dens_adv, Ie, W_elec, idx, DT, subcycles)
        
        if qq%data_iter == 0 and generate_data == 1:
            pas.save_data(DT, data_iter, qq, pos, vel, Ji, E_int, B, Ve, Te, q_dens)

        if qq%plot_iter == 0 and generate_plots == 1:
            pas.create_figure_and_save(pos, vel, E_int, B, q_dens, qq, DT, plot_iter)

        if (qq + 1)%25 == 0:
            print('Timestep {} of {} complete'.format(qq + 1, max_inc))

        qq += 1
Esempio n. 6
0
        ############################
        if adaptive_timestep == 1:
            pos, qq, DT, max_inc, part_save_iter, field_save_iter, change_flag, subcycles = aux.check_timestep(qq, DT, pos, vel, B, E, dns_int, max_inc, part_save_iter, field_save_iter, subcycles)
    
            if change_flag == 1:
                print('Timestep halved. Syncing particle velocity/position with DT = {}'.format(DT))
                pos, Ie, W_elec, dns_int, dns_half, J_plus, J_minus, G, L   = sources.init_collect_moments(pos, vel, Ie, W_elec, idx, 0.5*DT)
            elif change_flag == 2:
                print('Timestep doubled. Syncing particle velocity/position with DT = {}'.format(DT))
                pos, Ie, W_elec, dns_int, dns_half, J_plus, J_minus, G, L   = sources.init_collect_moments(pos, vel, Ie, W_elec, idx, 0.5*DT)
                                                        
        
        #######################
        ###### MAIN LOOP ######
        #######################
        B         = fields.cyclic_leapfrog(B, dns_int, J_minus, DT, subcycles)
        E, Ve, Te = fields.calculate_E(B, J_minus, dns_half)

        J         = sources.push_current(J_plus, E, B, L, G, DT)
        E, Ve, Te = fields.calculate_E(B, J, dns_half)
        
        vel = particles.velocity_update(pos, vel, Ie, W_elec, idx, B, E, J, DT)

        # Store pc(1/2) here while pc(3/2) is collected
        dns_int = dns_half          
        pos, Ie, W_elec, dns_half, J_plus, J_minus, G, L = sources.collect_moments(pos, vel, Ie, W_elec, idx, 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, subcycles)