def test_init_collect_moments(): # E_nodes = (np.arange(const.NX + 3) - 0.5) #* const.dx # B_nodes = (np.arange(const.NX + 3) - 1.0) #* const.dx dt = 0.1 velocity = np.array([[0.3 * const.dx / dt, 0.0], [0., 0.0], [0., 0.0]]) position = np.array([16.5, 16.5]) * const.dx idx = np.array([0, 0]) left_node, weights = particles.assign_weighting_TSC(position, E_nodes=True) position, left_node, weights, rho_0, rho, J_plus, J_init, G, L = sources.init_collect_moments( position, velocity, left_node, weights, idx, dt) return
from simulation_parameters_1D import generate_data, generate_plots if __name__ == '__main__': start_time = timer() 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)
vel = init.gaussian_distribution() else: pos, vel, idx = init.quiet_start() B[:, 0] = Bc[0] # Set Bx initial B[:, 1] = Bc[1] # Set By initial B[:, 2] = Bc[2] # Set Bz initial particles.assign_weighting_TSC(pos, Ie, W_elec) DT, max_inc, part_save_iter, field_save_iter, subcycles = aux.set_timestep( vel) 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:
import pdb, sys #import diagnostics as diag from simulation_parameters_1D import adaptive_timestep, save_particles, save_fields if __name__ == '__main__': start_time = timer() pos, vel, Ie, W_elec, idx = init.initialize_particles() 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: