def make_fields(PD): # Instantiate field data fld_data = field_data.field_data(PD['Z'], PD['R'], PD['n_r'], PD['n_z']) # Give mode Ps and Qs normalized values of '1' fld_data.mode_coords = np.ones((PD['n_r'], PD['n_z'], 2)) return fld_data
def make_fields(PD, particles): '''Create test field array''' #Instantiate field data fields = field_data.field_data(_PD['R'], _PD['Z'], _PD['n_r'], _PD['n_z']) #Give mode Ps and Qs normalized values of '1' fields.omega_coords = particles.mc[0] * np.ones((fields.n_modes_z, fields.n_modes_r, 2)) fields.dc_coords = np.zeros((fields.n_modes_z, fields.n_modes_r, 2)) return fields
def vary_rz_modes(mode_pair, PD, ns=1e2): ''' Simulate ns number of steps of size ss using npart particles and a number of modes specified by mode_pair. Arguments: mode_pair (tuple): [n_r,n_z] PD (dict): dictionary of other fixed parameters ns (Optional[int]) : number of steps to run. Defaults to 100. Returns: timing (float): number of seconds/macroparticle/mode ''' num_steps = ns PD['n_r'] = mode_pair[0] PD['n_z'] = mode_pair[1] num_modes = mode_pair[0] + mode_pair[1] PD['n_macro'] = PD['np_mode'] * num_modes num_particles = PD['n_macro'] PD['weight'] = PD['n_e'] / PD['n_macro'] # create fields, particles, integrator particles = particle_data.particle_data(PD['n_macro'], PD['charge'], PD['mass'], PD['weight']) fields = field_data.field_data(PD['Z'], PD['R'], PD['n_z'], PD['n_r']) create_init_conds(particles, fields, PD) my_integrator = integrator.integrator(PD['dt'], fields) step = 0 #print "Running {} total modes and {} particles".format(num_modes, num_particles) #t0 = time.time() while step < num_steps: my_integrator.second_order_step(particles, fields) step = step + 1 return
'n_z': n_z_modes, # number of longitudinal modes 'charge': charge, # 1 esu 'mass': mass, # mass in m_e 'n_e': n_electrons, #electron density 'n_macro': n_macro_ptcls, #total number of macro particles 'weight': n_electrons / n_macro_ptcls, #20, # macroparticle weighting 'R': l_r, #4./(k_p/(2.*np.pi)), #cm 4., # maximum R value 'PR': 0.5, # maximum PR value 'Z': l_z, #2./(k_p/(2.*np.pi)), #cm #10., # maximum z value 'V': np.pi * l_r * l_r * l_z, #volume 'num_steps': 100, # number of steps to perform 'n_r_max': 64, # maximum number of radial modes 'n_z_max': 64 } max_fields = field_data.field_data(_PD['Z'], _PD['R'], _PD['n_r_max'], _PD['n_z_max']) dt_max = .1 * 2. * np.pi / np.amax( max_fields.omega) #set timestep as 1/10 of period for largest mode _PD['dt'] = dt_max ######################################## #User defined functions ######################################## def create_init_conds(particles, fields, PD): '''Instantiate particle data''' fields.omega_coords = particles.mc[0] * np.ones( (fields.n_modes_z, fields.n_modes_r, 2)) fields.dc_coords = np.zeros((fields.n_modes_z, fields.n_modes_r, 2))
from rssympim.sympim_rz.data import particle_data, field_data from rssympim.sympim_rz.integrators import integrator import numpy as np from matplotlib import pyplot as plt import time n_ptcls = 1000 n_r = 10 n_z = 10 ptcl_data = particle_data.particle_data(n_ptcls, 1., 1.3, 33.5) fld_data = field_data.field_data(5., 2., n_r, n_z) fld_data.mode_coords = np.ones((n_r, n_z, 2)) ptcl_data.r = np.ones(n_ptcls) for idx in range(0, n_ptcls): ptcl_data.r[idx] *= idx*(4.)/n_ptcls + .01 ptcl_data.pr = ptcl_data.mc*np.arange(0.,.5,.5/n_ptcls) ptcl_data.ell = ptcl_data.r*ptcl_data.pr*.1 ptcl_data.z = np.zeros(n_ptcls) ptcl_data.pz = ptcl_data.mc*np.arange(0.,10.,10./n_ptcls) dt = .1/np.amax(fld_data.omega) my_integrator = integrator.integrator(dt, fld_data)
l_z = plasma_lengths*2.*np.pi/k_p # cm volume = np.pi*l_r*l_r*l_z # Domain parameters n_electrons = n0*volume # Simulation parameters n_r_modes = plasma_widths*modes_per_r n_z_modes = plasma_lengths*modes_per_z n_macro_ptcls = ppm*n_r_modes*n_z_modes macro_weight = n_electrons/n_macro_ptcls # Create simulation objects ptcl_data = particle_data.particle_data(n_macro_ptcls, charge, mass, macro_weight) fld_data = field_data.field_data(l_z, l_r, n_z_modes, n_r_modes) # Ten steps per fastest frequency dt = 0.1*2*np.pi/np.amax(fld_data.omega) # run for ten plasma periods run_time = 50*dt #4.*np.pi/k_p # Set the diagnostics compute_energy = False my_integrator = integrator.integrator(dt, fld_data.omega) # Initial conditions for ptcl_idx in range(0, n_macro_ptcls): # Uniform distribution in space
from rssympim.sympim_rz.data import field_data import numpy as np # The field data class has a special implementation of J_0. This tests those implementations. my_field_data = field_data.field_data(1., 2., 10, 10) x_test = np.arange(0., 10., 1.) j0_return = my_field_data.my_j0(x_test) j0_answer = np.array([ 1., 0.76519769, 0.22389078, -0.26005195, -0.39714981, -0.17759677, 0.15064526, 0.30007927, 0.17165081, -0.09033361 ]) int_j0_return = my_field_data.int_my_j0(x_test) int_j0_answer = np.array([ 0., 0.91973, 1.42577, 1.38757, 1.02473, 0.715312, 0.706221, 0.95464, 1.21075, 1.25227 ]) # Test for relative errors greater than a part in 10^2 tol = 1.e-2 test_j0 = np.abs(j0_return - j0_answer) test_int_j0 = np.abs(int_j0_return - int_j0_answer) msg = "Test results: \n" j0_results = test_j0 > tol
from rssympim.sympim_rz.data import field_data, particle_data from rssympim.sympim_rz.integrators import integrator import numpy as np import timeit n_ptcls = 40000 n_r = 40 n_z = 100 my_fields = field_data.field_data(1., 1., n_r, n_z) my_ptcls = particle_data.particle_data(n_ptcls, 1., 1., 1.) my_ptcls.r = np.ones(n_ptcls) for idx in range(0, n_ptcls): my_ptcls.r[idx] *= idx * (4.) / n_ptcls + .01 my_ptcls.pr = -my_ptcls.mc * np.arange(0., .5, .5 / n_ptcls) my_ptcls.ell = my_ptcls.r * my_ptcls.pr my_ptcls.z = np.zeros(n_ptcls) my_ptcls.pz = my_ptcls.mc * np.arange(0., 10., 10. / n_ptcls) my_integrator = integrator.integrator(.01, my_fields.omega) my_time = timeit.timeit('my_integrator.single_step(my_ptcls, my_fields)') print my_time
electrons = particle_data.particle_data(n_macro, charge, mass, weight) electrons.r = r electrons.z = z electrons.pr = pr electrons.pz = pz electrons.ell = pl electrons.weight = weight # field data second n_modes_z, n_modes_r, L, R, P_omega, Q_omega, P_dc, Q_dc = \ fld_io.read_field(fields_file) fields = field_data.field_data(L, R, n_modes_z, n_modes_r) field_data.omega_coords[:, :, 0] = P_omega[:, :] field_data.omega_coords[:, :, 1] = Q_omega[:, :] field_data.dc_coords[:, :, 0] = P_dc[:, :] field_data.dc_coords[:, :, 1] = Q_dc[:, :] # # Create the integrator # # eight steps per fastest frequency dt = (1. / 8.) * (2. * np.pi / np.max(fields.omega)) my_integrator = integrator.integrator(dt, fields)
#Construct the indices for the sectioned arrays inc = 0 end = np.zeros(size) ind = np.zeros(size) for i in range(size): if i < n_left: inc += 1 end[i] += n_ptcls_per_core * (i + 1) end[i] += inc if i + 1 < size: ind[i + 1] += n_ptcls_per_core * (i + 1) ind[i + 1] += inc fld_data = field_data.field_data(length, radius, n_modes_z, n_modes_r) ptcl_data = particle_data.particle_data(n_ptcls_per_core, charge, mass, macro_weight, n_total=n_macro_ptcls, end=end, ind=ind) dtau = 0.1 * 2. * np.pi / np.max(fld_data.omega) # Initial condition for a plasma wave fld_data.omega_coords[0, 0, 0] = plasma_wave_amplitude * fld_data.mode_mass[0, 0]