Пример #1
0
def init_fields(sim, w, ctau, k0, z0, zf, E0, m=1):
    """
    Imprints the appropriate profile on the fields of the simulation.

    Parameters
    ----------
    sim: Simulation object from fbpic

    w : float
       The initial waist of the laser (in microns)

    ctau : float
       The initial temporal waist of the laser (in microns)

    k0 : flat
       The central wavevector of the laser (in microns^-1)

    z0 : float
       The position of the centroid on the z axis

    zf : float
       The position of the focal plane

    E0 : float
       The initial E0 of the pulse

    m: int, optional
        The mode on which to imprint the profile
        For m = 1 : gaussian profile, linearly polarized beam
        For m = 0 : annular profile, polarized in E_theta
    """

    # Initialize the fields with the right value and phase
    if m == 1:
        add_laser(sim,
                  E0 * e / (m_e * c**2 * k0),
                  w,
                  ctau,
                  z0,
                  zf=zf,
                  lambda0=2 * np.pi / k0)
    if m == 0:
        fld = sim.fld
        z = fld.interp[m].z
        r = fld.interp[m].r
        profile = annular_pulse(z, r, w, ctau, k0, z0, E0)
        fld.interp[m].Et[:, :] = profile
        fld.interp[m].Br[:, :] = -1. / c * profile
Пример #2
0
                               m_e,
                               bunch_gamma,
                               bunch_n,
                               bunch_zmin,
                               bunch_zmax,
                               0,
                               bunch_rmax,
                               boost=boost)
    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),
Пример #3
0
def run_and_check_laser_antenna(gamma_b,
                                show,
                                write_files,
                                z0,
                                v=0,
                                forward_propagating=True):
    """
    Generic function, which runs and check the laser antenna for
    both boosted frame and lab frame

    Parameters
    ----------
    gamma_b: float or None
        The Lorentz factor of the boosted frame

    show: bool
        Whether to show the images of the laser as pop-up windows

    write_files: bool
        Whether to output openPMD data of the laser

    v: float (m/s)
        Speed of the laser antenna
    """
    # Initialize the simulation object
    sim = Simulation(Nz,
                     zmax,
                     Nr,
                     rmax,
                     Nm,
                     dt,
                     p_zmin=0,
                     p_zmax=0,
                     p_rmin=0,
                     p_rmax=0,
                     p_nz=2,
                     p_nr=2,
                     p_nt=2,
                     n_e=0.,
                     zmin=zmin,
                     use_cuda=use_cuda,
                     boundaries='open',
                     gamma_boost=gamma_b)

    # 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
    Nz_half = int(sim.fld.interp[1].Nz / 2) + 2
    z = sim.fld.interp[1].z[Nz_half:-(sim.comm.n_guard+sim.comm.n_damp+\
                            sim.comm.n_inject)]
    r = sim.fld.interp[1].r
    # Loop through the different fields
    for fieldtype, info_in_real_part, factor in [ ('Er', True, 2.), \
                ('Et', False, 2.), ('Br', False, 2.*c), ('Bt', True, 2.*c) ]:
        # factor correspond to the factor that has to be applied
        # in order to get a value which is comparable to an electric field
        # (Because of the definition of the interpolation grid, the )
        field = getattr(sim.fld.interp[1], fieldtype)\
                            [Nz_half:-(sim.comm.n_guard+sim.comm.n_damp+\
                             sim.comm.n_inject)]
        print('Checking %s' % fieldtype)
        check_fields(factor * field, z, r, info_in_real_part, z0, gamma_b,
                     forward_propagating)
        print('OK')
Пример #4
0
                               p_nr=p_nr,
                               p_nt=p_nt,
                               p_zmin=p_zmin)

    # Activate ionization of He ions (for levels above 1).
    # Store the created electrons in the species `elec`
    atoms_He.make_ionizable('He', target_species=elec, level_start=1)

    # Activate ionization of N ions (for levels above 5).
    # Store the created electrons in a new dedicated electron species that
    # does not contain any macroparticles initially
    elec_from_N = sim.add_new_species(q=-e, m=m_e)
    atoms_N.make_ionizable('N', target_species=elec_from_N, level_start=5)

    # Add a laser to the fields of the simulation
    add_laser(sim, a0, w0, ctau, z0, zf=z_foc)

    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),
Пример #5
0
                     p_zmax,
                     p_rmin,
                     p_rmax,
                     p_nz,
                     p_nr,
                     p_nt,
                     n_e,
                     dens_func=dens_func,
                     zmin=zmin,
                     boundaries='open',
                     n_order=n_order,
                     use_cuda=use_cuda)

    # Load initial fields
    # 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:
            sim.ptcl[0].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),
    # Create the plasma electrons
    elec = sim.add_new_species(q=-e,
                               m=m_e,
                               n=n_e,
                               dens_func=dens_func,
                               p_zmin=p_zmin,
                               p_zmax=p_zmax,
                               p_rmax=p_rmax,
                               p_nz=p_nz,
                               p_nr=p_nr,
                               p_nt=p_nt)

    # Load initial fields
    # Add a laser to the fields of the simulation
    add_laser(sim, a0, w0, ctau, z0, lambda0=lambda0, zf=zfoc)

    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(dt_period / sim.dt, sim.fld, comm=sim.comm),