def advance_particles_and_moments(pos, vel, Ie, W_elec, Ib, W_mag, idx, \ B, E, DT, q_dens_adv, Ji, ni, nu, temp1D, pc=0): ''' Helper function to group the particle advance and moment collection functions ''' velocity_update(pos, vel, Ie, W_elec, Ib, W_mag, idx, B, E, DT) position_update(pos, vel, idx, DT, Ie, W_elec) collect_moments(vel, Ie, W_elec, idx, q_dens_adv, Ji, ni, nu, temp1D) return
def advance_particles_and_moments(pos, vel, Ie, W_elec, Ib, W_mag, idx, Ep, Bp, v_prime, S, T, temp_N,\ B, E, DT, q_dens_adv, Ji, ni, nu, mp_flux, pc=0): ''' Helper function to group the particle advance and moment collection functions ''' velocity_update(pos, vel, Ie, W_elec, Ib, W_mag, idx, Ep, Bp, B, E, v_prime, S, T, temp_N, DT) position_update(pos, vel, idx, DT, Ie, W_elec, mp_flux) collect_moments(vel, Ie, W_elec, idx, q_dens_adv, Ji, ni, nu) return
def advance_particles_and_moments(pos, vel, Ie, W_elec, Ib, W_mag, idx, Ep, Bp, v_prime, S, T, temp_N,\ B, E, DT, q_dens, Ji, ni, nu, pc=0): ''' Helper function to group the particle advance and moment collection functions Note: use pc = 1 for predictor corrector to not collect new density. Actually, E_pred at N + 3/2 (used to get E(N+1) by averaging at 1/2, 3/2) requires density at N + 3/2 to be known, so density at N + 2 is still required (and so second position push also still required). Maybe maths this later on? How did Verbonceur (2005) get around this? ''' velocity_update(pos, vel, Ie, W_elec, Ib, W_mag, idx, Ep, Bp, B, E, v_prime, S, T, temp_N, DT) position_update(pos, vel, idx, Ep, DT, Ie, W_elec) collect_moments(vel, Ie, W_elec, idx, q_dens, Ji, ni, nu) return
def advance_particles_and_moments(pos, vel, Ie, W_elec, idx, B, E, DT): ''' Helper function to group the particle advance and moment collection functions ''' vel = velocity_update(pos, vel, Ie, W_elec, idx, B, E, DT) pos, Ie, W_elec = position_update(pos, vel, DT) q_dens, Ji = collect_moments(vel, Ie, W_elec, idx) return pos, vel, Ie, W_elec, q_dens, Ji
def initialize(): pos, vel, Ie, W_elec, idx = init.initialize_particles() B, E_int = init.initialize_fields() DT, max_inc, data_iter = aux.set_timestep(vel) if data_iter == 0: data_iter = max_inc 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) return pos, vel, Ie, W_elec, idx, B, E_int, q_dens, Ji, Ve, Te, DT, max_inc, data_iter
if __name__ == '__main__': start_time = timer() # Initialize simulation: Allocate memory and set time parameters print('Initializing arrays...') pos, vel, Ie, W_elec, Ib, W_mag, idx, Ep, Bp, temp_N = init.initialize_particles( ) B, E_int, E_half, Ve, Te, Te0 = init.initialize_fields() q_dens, q_dens_adv, Ji, ni, nu = init.initialize_source_arrays() old_particles, old_fields, temp3De, temp3Db, temp1D,\ v_prime, S, T, mp_flux = init.initialize_tertiary_arrays() print('Collecting initial moments...') # Collect initial moments and save initial state sources.collect_moments(vel, Ie, W_elec, idx, q_dens, Ji, ni, nu) if te0_equil == 1: init.set_equilibrium_te0(q_dens, Te0) DT, max_inc, part_save_iter, field_save_iter, B_damping_array, E_damping_array\ = init.set_timestep(vel, Te0) fields.calculate_E(B, Ji, q_dens, E_int, Ve, Te, Te0, temp3De, temp3Db, temp1D, E_damping_array, 0, DT, 0) print('Saving initial conditions...') if save_particles == 1: save.save_particle_data(0, DT, part_save_iter, 0, pos, vel, idx) if save_fields == 1:
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 pas.create_figure_and_save(part, J, B, dns_int, qq, DT, plot_dump_iter) if (qq + 1) % 10 == 0: print('Timestep {} of {} complete'.format(qq + 1, max_inc))
import save_routines as save from simulation_parameters_1D import generate_data, NX if __name__ == '__main__': start_time = timer() pos, vel, Ie, W_elec, idx = init.initialize_particles() B, E_int = init.initialize_fields() 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:
####################### ###### 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 J = 0.5 * (J_plus + J_minus) fields.cyclic_leapfrog(B, B2, rho_int, J, temp3d, DT, subcycles) E, Ve, Te = fields.calculate_E(B, J, rho_int) # This one's just for output ######################## ##### OUTPUT DATA ##### ######################## if qq % part_save_iter == 0 and save_particles == 1: # Save data, if flagged save.save_particle_data(DT, part_save_iter, qq, pos, vel)
####################### ###### 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) E, Ve, Te = fields.calculate_E(B, J, dns_int) # This one's just for output ######################## ##### OUTPUT DATA ##### ######################## if qq%part_save_iter == 0 and save_particles == 1: # Save data, if flagged save.save_particle_data(DT, part_save_iter, qq, pos, vel) if qq%field_save_iter == 0 and save_fields == 1: # Save data, if flagged