How to use the fbpic.openpmd_diag.ParticleDiagnostic function in fbpic

To help you get started, we’ve selected a few fbpic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fbpic / fbpic / tests / unautomated / test_envelope_non_linearity.py View on Github external
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)
    if show:
github fbpic / fbpic / tests / test_linear_wakefield_envelope.py View on Github external
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)
github fbpic / fbpic / tests / test_compton.py View on Github external
print( 'Initialized electron bunch' )
    # Add a photon species
    photons = sim.add_new_species( q=0, m=0 )
    print( 'Initialized photons' )

    # Activate Compton scattering for electrons of the bunch
    elec.activate_compton( target_species=photons,
        laser_energy=laser_energy, laser_wavelength=laser_wavelength,
        laser_waist=laser_waist, laser_ctau=laser_ctau,
        laser_initial_z0=laser_initial_z0, ratio_w_electron_photon=50,
        boost=boost )
    print( 'Activated Compton' )

    # Add diagnostics
    if write_hdf5:
        sim.diags = [ ParticleDiagnostic( diag_period,
            species={'electrons': elec, 'photons': photons}, comm=sim.comm ) ]

    # Get initial total momentum
    initial_total_elec_px = (elec.w*elec.ux).sum() * m_e * c
    initial_total_elec_py = (elec.w*elec.uy).sum() * m_e * c
    initial_total_elec_pz = (elec.w*elec.uz).sum() * m_e * c

    ### Run the simulation
    for species in sim.ptcl:
        species.send_particles_to_gpu()

    for i_step in range( N_step ):
        for species in sim.ptcl:
            species.push_x( 0.5*sim.dt )
        elec.handle_elementary_processes( sim.time + 0.5*sim.dt )
        for species in sim.ptcl:
github fbpic / fbpic / docs / source / example_input / lwfa_script.py View on Github external
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('')
github fbpic / fbpic / docs / source / example_input / parametric_script.py View on Github external
add_laser( sim, a0, w0, ctau, z0 )

    if use_restart is True:
        # 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 a field diagnostic
    # Parametric scan: each MPI rank should output its data to a
    # different directory
    write_dir = 'diags_a0_%.2f' %a0
    sim.diags = [ FieldDiagnostic( diag_period, sim.fld,
                    comm=sim.comm, write_dir=write_dir ),
                ParticleDiagnostic( diag_period, {"electrons" : sim.ptcl[0]},
                    select={"uz" : [1., None ]},
                    comm=sim.comm, write_dir=write_dir ) ]

    # 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('')
github fbpic / fbpic / docs / source / example_input / boosted_frame_script.py View on Github external
# Add an electron bunch
    add_elec_bunch( sim, bunch_gamma, bunch_n, bunch_zmin,
                bunch_zmax, 0, bunch_rmax, boost=boost )
    if track_bunch:
        sim.ptcl[2].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=gamma_boost )

    # Configure the moving window
    sim.set_moving_window( v=v_window, gamma_boost=gamma_boost )

    # Add a field diagnostic
    sim.diags = [ FieldDiagnostic(diag_period, sim.fld, sim.comm ),
                 ParticleDiagnostic(diag_period,
                     {"electrons":sim.ptcl[0], "bunch":sim.ptcl[2]}, sim.comm),
                 BoostedFieldDiagnostic( zmin, zmax, c,
                    dt_snapshot_lab, Ntot_snapshot_lab, gamma_boost,
                    period=diag_period, fldobject=sim.fld, comm=sim.comm),
                BoostedParticleDiagnostic( zmin, zmax, c, dt_snapshot_lab,
                    Ntot_snapshot_lab, gamma_boost, diag_period, sim.fld,
                    select={'uz':[0.,None]}, species={'electrons':sim.ptcl[2]},
                    comm=sim.comm )
                    ]

    ### Run the simulation
    sim.step( N_step, use_true_rho=True )
    print('')
github fbpic / fbpic / fbpic / picmi / simulation.py View on Github external
period=diagnostic.period,
                    fldobject=self.fbpic_sim.fld,
                    comm=self.fbpic_sim.comm,
                    fieldtypes=diagnostic.data_list,
                    write_dir=diagnostic.write_dir,
                    iteration_min=iteration_min,
                    iteration_max=iteration_max)
        # Register particle diagnostic
        elif type(diagnostic) == PICMI_ParticleDiagnostic:
            species_dict = {}
            for s in diagnostic.species:
                if s.name is None:
                    raise ValueError('When using a species in a diagnostic, '
                                      'its name must be set.')
                species_dict[s.name] = s.fbpic_species
            diag = ParticleDiagnostic(
                    period=diagnostic.period,
                    species=species_dict,
                    comm=self.fbpic_sim.comm,
                    particle_data=diagnostic.data_list,
                    write_dir=diagnostic.write_dir,
                    iteration_min=iteration_min,
                    iteration_max=iteration_max)

        # Add it to the FBPIC simulation
        self.fbpic_sim.diags.append( diag )
github fbpic / fbpic / docs / source / example_input / boosted_frame_script.py View on Github external
# 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
    N_step = int(T_interact/sim.dt)