Example #1
0
def numerical_loop(real_time, pos, vel, Ie, W_elec, idx, B, E_int, q_dens, Ji,
                   Ve, Te, DT, max_inc, data_iter, ch_flag):
    '''
    Does the number crunching for a short snippet. Logs number of time variable changes in ch_flag as powers of 2
    (-1 = half, 2 = 4 times slower)
    
    Array values are mutable: Don't have to be returned. Only integer values
    '''

    qq = 0
    while qq < data_iter:
        # Check timestep used for this iteration
        vel, qq, DT, max_inc, data_iter, ch_flag = aux.check_timestep(
            qq, DT, pos, vel, B, E_int, q_dens, Ie, W_elec, max_inc, data_iter,
            idx)

        # Add timestep to counter
        real_time += DT

        # 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 = fields.push_B(B, E_int, DT)
        E_half, Ve, Te = fields.calculate_E(B, Ji, q_dens)
        q_dens = q_dens_adv.copy()

        # Predictor-Corrector: Advance fields to start of next timestep
        E_int, B = fields.predictor_corrector(B, E_int, E_half, pos, vel,
                                              q_dens_adv, Ie, W_elec, idx, DT)

        # Increment loop variable
        qq += 1
    return DT, ch_flag, max_inc, data_iter, real_time
Example #2
0
    part = init.initialize_particles()
    B, E = init.initialize_magnetic_field()

    DT, max_inc, data_dump_iter, plot_dump_iter = aux.set_timestep(part)

    if generate_data == 1:
        pas.store_run_parameters(DT, data_dump_iter)

    print('Loading initial state...\n')
    part, dns_int, dns_half, J_plus, J_minus, G, L = sources.init_collect_moments(
        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)
Example #3
0
    DT, max_inc, data_iter = aux.set_timestep(vel)
    print 'Timestep: %.4fs, %d iterations total' % (DT, max_inc)
    if generate_data == 1:
        save.store_run_parameters(DT, data_iter)

    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
        vel, qq, DT, max_inc, data_iter, ch_flag \
        = aux.check_timestep(qq, DT, pos, vel, B, E_int, q_dens, Ie, W_elec, max_inc, data_iter, idx)

        if ch_flag == 1:
            print 'Timestep halved. Syncing particle velocity with DT = {}'.format(
                DT)
        elif ch_flag == 2:
            print 'Timestep Doubled. Syncing particle velocity with DT = {}'.format(
                DT)

        # 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 = fields.push_B(B, E_int, DT)
        E_half, Ve, Te = fields.calculate_E(B, Ji, q_dens)
        q_dens = q_dens_adv.copy()
Example #4
0
    print('Loading initial state...\n')
    sources.init_collect_moments(pos, vel, Ie, W_elec, idx, ni_init, nu_init,
                                 ni, nu_plus, rho_int, rho_half, J, J_plus, L,
                                 G, 0.5 * DT)

    # Put init into qq = 0 and save as usual, qq = 1 will be at t = dt
    qq = 0
    print('Starting loop...')
    while qq < max_inc:
        ############################
        ##### EXAMINE TIMESTEP #####
        ############################
        if adaptive_timestep == 1:
            qq, DT, max_inc, part_save_iter, field_save_iter, change_flag, subcycles =\
                aux.check_timestep(qq, DT, pos, vel, Ie, W_elec, B, E, rho_int, max_inc, part_save_iter, field_save_iter, subcycles)

            # Collect new moments and desync position and velocity
            if change_flag == 1:
                sources.init_collect_moments(pos, vel, Ie, W_elec, idx,
                                             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[:, :]
# =============================================================================
Example #5
0
    B, E                      = init.initialize_fields()

    DT, max_inc, part_save_iter, field_save_iter, subcycles = aux.set_timestep(vel)

    print('Loading initial state...\n')
    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)
                                               #J_init?? Should be J
    qq      = 0
    print('Starting loop...')
    while qq < max_inc:
        #print('Timestep', qq)
        ############################
        ##### EXAMINE TIMESTEP #####
        ############################
        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)
Example #6
0
    DT, max_inc, data_iter, plot_iter = aux.set_timestep(vel)

    q_dens, Ji = particles.advance_particles_and_moments(
        pos, vel, idx, B, E_int, 0)
    E_int, Ve, Te = fields.calculate_E(B, Ji, q_dens)

    particles.sync_velocities(pos, vel, idx, B, E_int, -0.5 * DT)

    qq = 0
    max_inc = 10
    while qq < max_inc:

        # TIMESTEP CHECK
        if adaptive_timestep == True:
            qq, DT, max_inc, data_iter, plot_iter \
        = aux.check_timestep(qq, DT, pos, vel, B, E_int, q_dens, max_inc, data_iter, plot_iter, idx)

        # MAIN LOOP
        q_dens_adv, Ji = particles.advance_particles_and_moments(
            pos, vel, idx, B, E_int, DT)

        q_dens = 0.5 * (q_dens + q_dens_adv)
        B = fields.push_B(B, E_int, DT)
        E_half, Ve, Te = fields.calculate_E(B, Ji, q_dens)
        q_dens = q_dens_adv.copy()

        E_int, B = fields.predictor_corrector(B, E_int, E_half, pos, vel,
                                              q_dens, idx, DT)

        # OUTPUT
        if qq % data_iter == 0 and generate_data == 1:
Example #7
0
    print('Retarding velocity...')
    particles.velocity_update(pos, vel, Ie, W_elec, Ib, W_mag, idx, Ep, Bp, B,
                              E_int, v_prime, S, T, temp_N, -0.5 * DT)
    print('<< Initialization Complete >>\n')
    if True:
        qq = 1
        sim_time = DT
        print('Starting main loop...')
        while qq < max_inc:
            ###########################
            ####### MAIN LOOP #########
            ###########################

            # Check timestep
            qq, DT, max_inc, part_save_iter, field_save_iter, damping_array \
            = aux.check_timestep(pos, vel, B, E_int, q_dens, Ie, W_elec, Ib, W_mag, temp3De, Ep, Bp, v_prime, S, T,temp_N,\
                             qq, DT, max_inc, part_save_iter, field_save_iter, idx, B_damping_array)

            # Move particles, collect moments, delete or inject new particles
            particles.advance_particles_and_moments(pos, vel, Ie, W_elec, Ib, W_mag, idx, Ep, Bp, v_prime, S, T,temp_N,\
                                                    B, E_int, DT, q_dens_adv, Ji, ni, nu, flux_rem)

            # Average N, N + 1 densities (q_dens at N + 1/2)
            q_dens *= 0.5
            q_dens += 0.5 * q_dens_adv

            if disable_waves == False:
                # Push B from N to N + 1/2
                fields.push_B(B,
                              E_int,
                              temp3Db,
                              DT,
Example #8
0
    if save_fields == 1:
        save.save_field_data(DT, field_save_iter, 0, Ji, E_int, B, Ve, Te,
                             q_dens)

    vel = particles.velocity_update(pos, vel, Ie, W_elec, idx, B, E_int,
                                    -0.5 * DT)

    qq = 1
    print('Starting main loop...')
    while qq < max_inc:
        ############################
        ##### EXAMINE TIMESTEP #####
        ############################
        vel, qq, DT, max_inc, part_save_iter, field_save_iter \
        = aux.check_timestep(qq, DT, pos, vel, B, E_int, q_dens, Ie, W_elec, max_inc, part_save_iter, field_save_iter, 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 = fields.push_B(B, E_int, DT)

        E_half, Ve, Te = fields.calculate_E(B, Ji, q_dens)

        q_dens = q_dens_adv.copy()

        E_int, B = fields.predictor_corrector(B, E_int, E_half, pos, vel,
Example #9
0
    pos, vel, Ie, W_elec, idx = init.initialize_particles()
    B, E                      = init.initialize_fields()

    DT, max_inc, data_iter, plot_iter, subcycles = aux.set_timestep(vel)

    print 'Loading initial state...\n'
    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)

    qq      = 0
    while qq < max_inc:

        ############################
        ##### EXAMINE TIMESTEP #####
        ############################
        if adaptive_timestep == 1:
            pos, qq, DT, max_inc, data_iter, plot_iter, change_flag, subcycles = aux.check_timestep(qq, DT, pos, vel, B, E, dns_int, max_inc, data_iter, plot_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)