Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Remove the particles
sim.ptcl = []
# Add the laser
add_laser( sim, a0, w0, ctau, z0, zf=zf, method='antenna',
z0_antenna=z0_antenna, v_antenna=v, gamma_boost=gamma_b,
fw_propagating=forward_propagating )
# Calculate the number of steps between each output
N_step = int( round( Ntot_step/N_show ) )
# Add diagnostic
if write_files:
sim.diags = [
FieldDiagnostic( N_step, sim.fld, comm=None,
fieldtypes=["rho", "E", "B", "J"] )
]
# Loop over the iterations
print('Running the simulation...')
for it in range(N_show) :
print( 'Diagnostic point %d/%d' %(it, N_show) )
# Advance the Maxwell equations
sim.step( N_step, show_progress=False )
# Plot the fields during the simulation
if show==True:
show_fields( sim.fld.interp[1], 'Er' )
# Finish the remaining iterations
sim.step( Ntot_step - N_show*N_step, show_progress=False )
# Check the transverse E and B field
use_cuda = False
elif hardware=='gpu':
use_cuda = True
# Initialize the simulation object
sim = Simulation( Nz, zmax, Nr, rmax, Nm, dt,
zmin=zmin, use_cuda=use_cuda, particle_shape=particle_shape )
sim.ptcl = []
# Add an electron bunch (set the random seed first)
np.random.seed(0)
add_elec_bunch_gaussian(
sim, sig_r, sig_z, n_emit, gamma0, sig_gamma, Q, N )
# Add a field diagnostic
sim.diags = [ FieldDiagnostic( diag_period, sim.fld,
fieldtypes=['rho', 'J'], comm=sim.comm,
write_dir=os.path.join('tests',hardware) )]
### Run the simulation
sim.step( N_step )
# Check that the results are identical
ts_cpu = OpenPMDTimeSeries('tests/cpu/hdf5')
ts_gpu = OpenPMDTimeSeries('tests/gpu/hdf5')
for iteration in ts_cpu.iterations:
for field, coord in [('rho',''), ('J','x'), ('J','z')]:
# Jy is not tested because it is zero
print('Testing %s at iteration %d' %(field+coord, iteration))
F_cpu, info = ts_cpu.get_field( field, coord, iteration=iteration )
F_gpu, info = ts_gpu.get_field( field, coord, iteration=iteration )
tolerance = 1.e-13*( abs(F_cpu).max() + abs(F_gpu).max() )
dt = 0.06e-6/c
print(c*dt)
print(L_prop)
print(L_prop / c / dt)
sim = Simulation( Nz, zmax, Nr, rmax, Nm, dt,
p_zmin=p_zmin, p_zmax=p_zmax, p_rmin=p_rmin, p_rmax=p_rmax, p_nz=p_nz,
p_nr=p_nr, p_nt=Nm+1, n_e=n_e, n_order=n_order, zmin=zmin,
boundaries='open', v_comoving=0.999*c, use_galilean=True, initialize_ions=True,
use_cuda=use_cuda, use_envelope=True )
sim.set_moving_window(v=c)
tau = ctau/c
lambda0 = 2*np.pi/k0
# Create the relevant laser profile
z0 = 0
sim.diags = [ FieldDiagnostic( diag_period, sim.fld, comm=sim.comm, fieldtypes = ["a", "rho", "E"] ),
ParticleDiagnostic(diag_period, {'electrons': sim.ptcl[0]}, sim.comm )]
profile = GaussianLaser( a0=a0, waist=w0, tau=tau,
lambda0=lambda0, z0=z0, zf=zf )
add_laser_pulse( sim, profile, method = 'direct_envelope' )
Ntot_step_init = int( round( L_prop/(c*dt) ) )
k_iter = 1
kz = sim.fld.envelope_spect[0].kz
kr = sim.fld.envelope_spect[0].kr
for it in range(k_iter):
sim.step( Ntot_step_init//k_iter, show_progress=True)
# Create the relevant laser profile
if Nm == 1:
profile = GaussianLaser(a0=a0, waist=w0, tau=tau, z0=z0,
theta_pol=np.pi/2 )
elif Nm == 3:
profile = LaguerreGaussLaser(0, 1, a0=a0, waist=w0, tau=tau, z0=z0,
theta_pol=np.pi/2)
add_laser_pulse( sim, profile, method = 'direct_envelope' )
# Configure the moving window
sim.set_moving_window( v=c )
# Add diagnostics
if write_fields:
sim.diags.append( FieldDiagnostic(diag_period, sim.fld, sim.comm,
fieldtypes=["rho", "E", "B", "J","a"]) )
if write_particles:
sim.diags.append( ParticleDiagnostic(diag_period,
{'electrons': sim.ptcl[0]}, sim.comm ) )
# Prevent current correction for MPI simulation
if sim.comm.size > 1:
correct_currents=False
else:
correct_currents=True
# Run the simulation
sim.step(N_step, correct_currents=correct_currents)
# Compare the fields
compare_fields(sim, Nm, show)
+ LaguerreGaussLaser( 0, 1, a0=a0, waist=w0, tau=tau, z0=z0,
theta_pol=0., theta0=-np.pi/2 )
elif Nm == 2:
profile = GaussianLaser(a0=a0, waist=w0, tau=tau, z0=z0,
theta_pol=np.pi/2 )
elif Nm == 3:
profile = LaguerreGaussLaser(0, 1, a0=a0, waist=w0, tau=tau, z0=z0,
theta_pol=np.pi/2 )
add_laser_pulse( sim, profile )
# Configure the moving window
sim.set_moving_window( v=c )
# Add diagnostics
if write_fields:
sim.diags.append( FieldDiagnostic(diag_period, sim.fld, sim.comm ) )
if write_particles:
sim.diags.append( ParticleDiagnostic(diag_period,
{'electrons': sim.ptcl[0]}, sim.comm ) )
# Prevent current correction for MPI simulation
if sim.comm.size > 1:
correct_currents=False
else:
correct_currents=True
# Run the simulation
sim.step(N_step, correct_currents=correct_currents)
# Compare the fields
compare_fields(sim, Nm, show)
if track_bunch:
bunch.track( sim.comm )
# Add a laser to the fields of the simulation
add_laser( sim, a0, w0, ctau, z0, lambda0=lambda0,
zf=zfoc, gamma_boost=boost.gamma0 )
# Convert parameter to boosted frame
v_window_boosted, = boost.velocity( [ v_window ] )
# Configure the moving window
sim.set_moving_window( v=v_window_boosted )
# Add a field diagnostic
sim.diags = [
# Diagnostics in the boosted frame
FieldDiagnostic( dt_period=dt_boosted_diag_period,
fldobject=sim.fld, comm=sim.comm ),
ParticleDiagnostic( dt_period=dt_boosted_diag_period,
species={"electrons":plasma_elec, "bunch":bunch},
comm=sim.comm),
# Diagnostics in the lab frame (back-transformed)
BackTransformedFieldDiagnostic( zmin, zmax, v_window,
dt_lab_diag_period, N_lab_diag, boost.gamma0,
fieldtypes=['rho','E','B'], period=write_period,
fldobject=sim.fld, comm=sim.comm ),
BackTransformedParticleDiagnostic( zmin, zmax, v_window,
dt_lab_diag_period, N_lab_diag, boost.gamma0,
write_period, sim.fld, select={'uz':[0.,None]},
species={'bunch':bunch}, comm=sim.comm )
]
# Number of iterations to perform
# Add a laser to the fields of the simulation
add_laser( sim, a0, w0, ctau, z0 )
if use_restart is False:
# Track electrons if required (species 0 correspond to the electrons)
if track_electrons:
elec.track( sim.comm )
else:
# Load the fields and particles from the latest checkpoint file
restart_from_checkpoint( sim )
# Configure the moving window
sim.set_moving_window( v=v_window )
# Add diagnostics
sim.diags = [ FieldDiagnostic( diag_period, sim.fld, comm=sim.comm ),
ParticleDiagnostic( diag_period, {"electrons" : elec},
select={"uz" : [1., None ]}, comm=sim.comm ) ]
# Add checkpoints
if save_checkpoints:
set_periodic_checkpoint( sim, checkpoint_period )
# Number of iterations to perform
N_step = int(T_interact/sim.dt)
### Run the simulation
sim.step( N_step )
print('')