Esempio n. 1
0
def trailer_gen():
    n0_per_cc = 5.0334e15
    N = int(2e5)
    z = np.linspace(.8, 1.9, 128)
    current = trailer_profile(z)
    samp_generator = beam_gen.DistGen(z, current)
    sample_z = samp_generator.sample_gen_direct(N * 1.01)
    hist, z_bins = np.histogram(sample_z, bins=len(z))
    hist = hist * (np.max(current) / hist.max())
    plt.plot(z_bins[:-1], hist, 'r--')

    k0 = np.sqrt(4 * constants.pi *
                 constants.physical_constants['classical electron radius'][0] *
                 n0_per_cc * 1e6)
    sample_z = sample_z / k0  # Transform to meter

    beam_generator = beam_gen.BeamGen(sig_x=8.8e-6,
                                      sig_y=8.8e-6,
                                      n_emit_x=100.e-6,
                                      n_emit_y=100.e-6,
                                      gamma0=19569.5,
                                      sig_gamma=10.,
                                      n_macroparticles=N,
                                      zf_x=0.,
                                      zf_y=0.,
                                      z_array=sample_z)
    beam_generator.beam_gen(save_h5_name='./trailer.h5',
                            sim_bound=[[0., 12.5], [-6., 6.], [-6., 6.]],
                            nx=[512, 512, 512],
                            n0_per_cc=n0_per_cc,
                            Q_beam=-0.87e-9 / 2)
    beam_generator.plot_hist2D(xaxis='z', yaxis='x')
    plt.show()
Esempio n. 2
0
def var_driver_gen():
    # Driver with varing emittance
    n0_per_cc = 5.0334e15
    N = int(2e7)
    z = np.linspace(5., 13., 128)
    current = driver_profile(z)
    samp_generator = beam_gen.DistGen(z, current)
    sample_z = samp_generator.sample_gen_direct(N * 1.01)
    sample_z = sample_z[:N]  # discard extra particles
    hist, z_bins = np.histogram(sample_z, bins=len(z))
    hist = hist * (np.max(current) / hist.max())
    plt.plot(z_bins[:-1], hist, 'k.-')

    n_emit0 = 20.e-6  # emittance at beam head in SI units
    # varying emittance
    z_max = sample_z.max()
    z_min = sample_z.min()
    #n_emit = ((z_max - sample_z)/(z_max - z_min)*99.+1.)*n_emit0
    z_trans = z_max - (z_max - z_min) * 0.05
    n_emit = np.piecewise(sample_z, [sample_z < z_trans], [
        lambda sample_z: ((z_trans - sample_z) /
                          (z_trans - z_min) * 99. + 1.) * n_emit0, n_emit0
    ])

    k0 = np.sqrt(4 * constants.pi *
                 constants.physical_constants['classical electron radius'][0] *
                 n0_per_cc * 1e6)
    gamma_beam = 19569.5
    # Matched beam size
    sig_r = sqrt(sqrt(2. / gamma_beam) / k0) * np.sqrt(n_emit)

    sample_z = sample_z / k0  # Transform to meter

    beam_generator = beam_gen.BeamGen(sig_x=sig_r,
                                      sig_y=sig_r,
                                      n_emit_x=n_emit,
                                      n_emit_y=n_emit,
                                      gamma0=gamma_beam,
                                      sig_gamma=1.,
                                      n_macroparticles=N,
                                      zf_x=0.,
                                      zf_y=0.,
                                      z_array=sample_z)
    beam_generator.beam_gen()
    #beam_generator.x_array *= (z_max - beam_generator.z_array)/ratio +1.
    #beam_generator.y_array *= (z_max - beam_generator.z_array)/ratio +1.
    #beam_generator.beam_symmetrization()
    beam_generator.h5_file_name = './driver.h5'
    #beam_generator.h5_file_name = './driver_symmetric.h5'
    beam_generator.save_sample_h5(sim_bound=[[0., 13.], [-6., 6.], [-6., 6.]],
                                  nx=[512, 512, 512],
                                  n0_per_cc=n0_per_cc,
                                  Q_beam=-6.e-9)
    beam_generator.plot_hist2D(xaxis='z', yaxis='x')
    plt.show()
Esempio n. 3
0
def driver_gen():
    n0_per_cc = 5.0334e15
    N = int(1e6)
    z = np.linspace(5., 13., 128)
    current = driver_profile(z)
    samp_generator = beam_gen.DistGen(z, current)
    sample_z = samp_generator.sample_gen_direct(N * 1.01)
    hist, z_bins = np.histogram(sample_z, bins=len(z))
    hist = hist * (np.max(current) / hist.max())
    plt.plot(z_bins[:-1], hist, 'k.-')

    k0 = np.sqrt(4 * constants.pi *
                 constants.physical_constants['classical electron radius'][0] *
                 n0_per_cc * 1e6)
    sample_z = sample_z / k0  # Transform to meter

    beam_generator = beam_gen.BeamGen(sig_x=6.e-6,
                                      sig_y=6.e-6,
                                      n_emit_x=20.e-6,
                                      n_emit_y=20.e-6,
                                      gamma0=19569.5,
                                      sig_gamma=10.,
                                      n_macroparticles=N,
                                      zf_x=0.,
                                      zf_y=0.,
                                      z_array=sample_z)
    beam_generator.beam_gen()
    # varying beam size
    z_max = np.max(beam_generator.z_array)
    z_min = np.min(beam_generator.z_array)
    ratio = z_max - z_min
    #beam_generator.x_array *= (z_max - beam_generator.z_array)/ratio +1.
    #beam_generator.y_array *= (z_max - beam_generator.z_array)/ratio +1.
    beam_generator.h5_file_name = './driver.h5'
    beam_generator.save_sample_h5(sim_bound=[[0., 13.], [-6., 6.], [-6., 6.]],
                                  nx=[512, 512, 512],
                                  n0_per_cc=n0_per_cc,
                                  Q_beam=-6.e-9)
    beam_generator.plot_hist2D(xaxis='z', yaxis='x')
    plt.show()
Esempio n. 4
0
def damper_gen():
    n0_per_cc = 5.0334e15
    N = int(5e7 * .5)
    z = np.linspace(6.8, 12.1, 256)
    current = driver_profile(z)
    samp_generator = beam_gen.DistGen(z, current)
    sample_z = samp_generator.sample_gen_direct(N * 1.01)
    hist, z_bins = np.histogram(sample_z, bins=len(z))
    hist = hist * (np.max(current) / hist.max())
    plt.plot(z_bins[:-1], hist, 'k.-')

    k0 = np.sqrt(4 * constants.pi *
                 constants.physical_constants['classical electron radius'][0] *
                 n0_per_cc * 1e6)
    gamma0 = 19569.5 * .5
    n_emit = 20.e-6
    sig_r = sqrt(sqrt(2. / gamma0) / k0) * np.sqrt(n_emit)
    print('sig_r = ', sig_r)
    sample_z = sample_z / k0  # Transform to meter

    beam_generator = beam_gen.BeamGen(sig_x=sig_r,
                                      sig_y=sig_r,
                                      n_emit_x=n_emit,
                                      n_emit_y=n_emit,
                                      gamma0=gamma0,
                                      sig_gamma=10.,
                                      n_macroparticles=N,
                                      zf_x=0.,
                                      zf_y=0.,
                                      z_array=sample_z)
    beam_generator.beam_gen()
    #beam_generator.beam_symmetrization(insert_method=1)
    beam_generator.h5_file_name = './damper_short_half.h5'
    beam_generator.save_sample_h5(sim_bound=[[0., 12.5], [-6., 6.], [-6., 6.]],
                                  nx=[512, 512, 512],
                                  n0_per_cc=n0_per_cc,
                                  Q_beam=-2.4e-9 * .5)
    beam_generator.plot_hist2D(xaxis='z', yaxis='x')
    plt.show()