Example #1
0
def set_timestep(vel):
    gyperiod = (2*np.pi) / const.gyfreq               # Gyroperiod within uniform field (s)         
    ion_ts   = const.orbit_res * gyperiod             # Timestep to resolve gyromotion
    vel_ts   = const.dx / (2 * np.max(vel[0, :]))     # Timestep to satisfy CFL condition: Fastest particle doesn't traverse more than half a cell in one time step

    DT       = min(ion_ts, vel_ts)
    max_time = const.max_rev * gyperiod               # Total runtime in seconds
    max_inc  = int(max_time / DT) + 1                 # Total number of time steps

    if const.plot_res == 0:                           # Decide plot and data increments (if enabled)
        plot_iter = 1
    else:
        plot_iter = int(const.plot_res*gyperiod / DT)

    if const.data_res == 0:
        data_iter = 1
    else:
        data_iter = int(const.data_res*gyperiod / DT)
    
    print 'Timestep: %.4fs, %d iterations total' % (DT, max_inc)
    
    if const.adaptive_subcycling == True:
        k_max           = np.pi / const.dx
        dispfreq        = (k_max ** 2) * const.B0 / (const.mu0 * const.ne * const.q)            # Dispersion frequency
        dt_sc           = const.freq_res * 1./dispfreq
        subcycles       = int(DT / dt_sc + 1)
        print 'Number of subcycles required: {}'.format(subcycles)
    else:
        subcycles = const.subcycles
        print 'Number of subcycles set at default: {}'.format(subcycles)
    
    if const.generate_data == 1:
        pas.store_run_parameters(DT, data_iter)
        
    return DT, max_inc, data_iter, plot_iter, subcycles
Example #2
0
def set_timestep(vel):
    gyperiod = (2 *
                np.pi) / const.gyfreq  # Gyroperiod within uniform field (s)
    k_max = np.pi / const.dx
    ion_ts = const.orbit_res * gyperiod  # Timestep to resolve gyromotion
    vel_ts = 0.5 * const.dx / np.max(
        vel[0, :]
    )  # Timestep to satisfy CFL condition: Fastest particle doesn't traverse more than half a cell in one time step

    if const.account_for_dispersion == True:
        dispfreq = (k_max**2) * (const.B0 / (const.mu0 * const.ne)
                                 )  # Dispersion frequency
        disp_ts = const.dispersion_allowance * const.freq_res / dispfreq
    else:
        disp_ts = ion_ts

    DT = min(ion_ts, vel_ts, disp_ts)
    max_time = const.max_rev * gyperiod  # Total runtime in seconds
    max_inc = int(max_time / DT) + 1  # Total number of time steps

    if const.plot_res == 0:  # Decide plot and data increments (if enabled)
        plot_iter = 1
    else:
        plot_iter = int(const.plot_res * gyperiod / DT)

    if const.data_res == 0:
        data_iter = 1
    else:
        data_iter = int(const.data_res * gyperiod / DT)

    print('Timestep: %.4fs, %d iterations total' % (DT, max_inc))

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

    return DT, max_inc, data_iter, plot_iter
Example #3
0
import sources_1D as sources
import plot_and_save as pas
import diagnostics as diag

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))