예제 #1
0
def make_beam(bm):
    parts0 = np.zeros((6, bm['Np']))
    parts0[0] = bm['Rx'] * np.random.randn(bm['Np'])
    parts0[1] = bm['Ox'] * np.random.randn(bm['Np'])
    parts0[2] = bm['Ry'] * np.random.randn(bm['Np'])
    parts0[3] = bm['Oy'] * np.random.randn(bm['Np'])
    parts0[4] = bm['Lz'] * np.random.randn(bm['Np'])
    parts0[5] = bm['dE'] * np.random.randn(bm['Np'])
    p_array_init = oclt.ParticleArray()
    p_array_init.particles = parts0.T.flatten()
    p_array_init.E = bm['E']
    p_array_init.s = 0.0
    if 'Q' in bm:
        p_array_init.q_array = (bm['Q'] / bm['Np']) * np.ones(bm['Np'])
    else:
        p_array_init.q_array = np.ones(bm['Np'])
    return p_array_init
예제 #2
0
def make_beam(bm):
    """
    Makes a beam with Gaussian phase distributions

    Parameters
    ----------
    bm : dictionary
      beam input parameters (in SI units):
        Np -- full number of particles
        Lz, Rx, Ry -- spatial dimensions of the beam
        dE, Ox, Oy -- normalized momenta dispersions
        E -- beam mean energy (in GeV)
        Q -- full beam charge (in C)

    Returns
    -------
    p_array : an oclt.ParticleArray object

    """

    p_array = oclt.ParticleArray(n=bm['Np'])

    if 'Features' not in bm:
        bm['Features'] = {}
    if 'RandomSeed' not in bm['Features']:
        bm['Features']['RandomSeed'] = int(np.random.rand()*1e7)
    rnd = np.random.RandomState(seed = bm['Features']['RandomSeed'])

    if 'X0' not in bm: bm['X0'] = 0.
    if 'Y0' not in bm: bm['Y0'] = 0.
    if 'Z0' not in bm: bm['Z0'] = 0.

    parts0 = np.zeros((6, bm['Np']))

    if 'FlatX' in bm['Features']:
        parts0[0] = bm['X0'] + bm['Rx']*(2*rnd.rand(bm['Np'])-1)
    else:
        parts0[0] = bm['X0'] + bm['Rx']*rnd.randn(bm['Np'])

    if 'FlatY' in bm['Features']:
        parts0[2] = bm['Y0'] + bm['Ry']*(2*rnd.rand(bm['Np'])-1)
    else:
        parts0[2] = bm['Y0'] + bm['Ry']*rnd.randn(bm['Np'])

    if 'FlatZ' in bm['Features']:
        parts0[4] = bm['Z0'] + bm['Lz']*(2*rnd.rand(bm['Np'])-1)
    else:
        parts0[4] = bm['Z0'] + bm['Lz']*rnd.randn(bm['Np'])

    parts0[1] = bm['Ox'] * rnd.randn(bm['Np'])
    parts0[3] = bm['Oy'] * rnd.randn(bm['Np'])
    parts0[5] = bm['dE'] * rnd.randn(bm['Np'])

    p_array.rparticles = parts0 #.T.flatten()
    p_array.E = bm['E']
    p_array.s = 0.0

    p_array.x_c = 0.0
    p_array.y_c = 0.0
    p_array.z_c = 0.0

    if 'Q' in bm:
        p_array.q_array = (bm['Q']/bm['Np']) * np.ones(bm['Np'])
    else:
        p_array.q_array = np.ones(bm['Np'])

    return p_array
예제 #3
0
def make_beam_contin(bm, div_chirp=None):
    """
    Makes a beam with Gaussian phase distributions,
    except for energy spread which is flat-top

    Parameters
    ----------
    bm : dictionary
      beam input parameters as in make_beam except for:
        bm['E'] = (E1,E2) -- range of electron energies (in GeV)

    Returns
    -------
    p_array : an oclt.ParticleArray object

    See Also
    --------
      make_beam

    """
    p_array = oclt.ParticleArray()

    if 'Features' not in bm:
        bm['Features'] = {}
    if 'RandomSeed' not in bm['Features']:
        bm['Features']['RandomSeed'] = int(np.random.rand()*1e7)
    rnd = np.random.RandomState(seed=bm['Features']['RandomSeed'])

    E1 = bm['E'][0]
    E2 = bm['E'][1]
    dE = (E2-E1) / (E2+E1)
    p_array.E = 0.5 * (E2+E1)

    if 'X0' not in bm: bm['X0'] = 0.
    if 'Y0' not in bm: bm['Y0'] = 0.
    if 'Z0' not in bm: bm['Z0'] = 0.

    parts0 = np.zeros((6, bm['Np']))

    if 'FlatX' in bm['Features']:
        parts0[0] = bm['X0'] + bm['Rx']*(2*rnd.rand(bm['Np'])-1)
    else:
        parts0[0] = bm['X0'] + bm['Rx']*rnd.randn(bm['Np'])

    if 'FlatY' in bm['Features']:
        parts0[2] = bm['Y0'] + bm['Ry']*(2*rnd.rand(bm['Np'])-1)
    else:
        parts0[2] = bm['Y0'] + bm['Ry']*rnd.randn(bm['Np'])

    if 'FlatZ' in bm['Features']:
        parts0[4] = bm['Z0'] + bm['Lz']*(2*rnd.rand(bm['Np'])-1)
    else:
        parts0[4] = bm['Z0'] + bm['Lz']*rnd.randn(bm['Np'])

    parts0[5] = dE * (2*rnd.rand(bm['Np'])-1)

    if div_chirp != None:
        pz0 = np.sqrt( (div_chirp/mc2_GeV)**2-1. )
        pz = (p_array.E/mc2_GeV) * (1+parts0[5])

#       px =  bm['Ox']*pz0*rnd.randn(bm['Np'])
#       py =  bm['Oy']*pz0*rnd.randn(bm['Np'])

        parts0[1] = bm['Ox'] * rnd.randn(bm['Np']) * (pz0/pz)**0.75
        parts0[3] = bm['Oy'] * rnd.randn(bm['Np']) * (pz0/pz)**0.75

    else:
        parts0[1] = bm['Ox'] * rnd.randn(bm['Np'])
        parts0[3] = bm['Oy'] * rnd.randn(bm['Np'])

    p_array.rparticles = parts0 #.T.flatten()
    p_array.s = 0.0
    if 'Q' in bm:
        p_array.q_array = (bm['Q']/bm['Np']) * np.ones(bm['Np'])
    else:
        p_array.q_array = np.ones(bm['Np'])

    p_array.x_c = 0.0
    p_array.y_c = 0.0
    p_array.z_c = 0.0

    return p_array