Example #1
0
def calc_lifetimes(accelerator, n=None, coupling=None, pressure_profile=None, twiss=None, eq_parameters=None):

    parameters, twiss = _process_args(accelerator, twiss, eq_parameters, n, coupling, pressure_profile)

    # Acceptances
    energy_acceptance = parameters['rf_energy_acceptance']
    accepx, accepy, *_ = _optics.get_transverse_acceptance(accelerator, twiss, energy_offset=0.0)
    transverse_acceptances = [min(accepx), min(accepy)]

    # Average pressure
    s, pressure  = pressure_profile
    avg_pressure = _np.trapz(pressure,s)/(s[-1]-s[0])

    # Loss rates
    spos        = _lattice.find_spos(accelerator)
    e_rate_spos = _mp.beam_lifetime.calc_elastic_loss_rate(transverse_acceptances, avg_pressure, z=7, temperature=300, **parameters)
    e_rate      = _np.trapz(e_rate_spos,spos)/(spos[-1]-spos[0])
    i_rate      = _mp.beam_lifetime.calc_inelastic_loss_rate(energy_acceptance, avg_pressure, z=7, temperature=300)
    q_rate      = sum(_mp.beam_lifetime.calc_quantum_loss_rates(transverse_acceptances, energy_acceptance, coupling, **parameters))
    tous_lt     = _mp.beam_lifetime.calc_touschek_loss_rate([-energy_acceptance,energy_acceptance], twiss, coupling, n, **parameters)

    # Lifetimes
    e_lifetime = float("inf") if e_rate == 0.0 else 1.0/e_rate
    i_lifetime = float("inf") if i_rate == 0.0 else 1.0/i_rate
    q_lifetime = float("inf") if q_rate == 0.0 else 1.0/q_rate
    t_coeff    = tous_lt['ave_rate']

    return e_lifetime, i_lifetime, q_lifetime, t_coeff
Example #2
0
def get_radiation_integrals(accelerator,
                          twiss=None,
                          m66=None,
                          closed_orbit=None):
    """Calculate radiation integrals for periodic systems"""

    if twiss is None or m66 is None:
        fixed_point = closed_orbit if closed_orbit is None else closed_orbit[:,0]
        twiss, m66 = calc_twiss(accelerator, fixed_point=fixed_point)

    spos = _lattice.find_spos(accelerator)

    # # Old get twiss
    # etax,etapx,betax,alphax = twiss,('etax','etapx','betax','alphax'))

    etax, etapx, betax, alphax = twiss.etax, twiss.etapx, twiss.betax, twiss.alphax

    if len(spos) != len(accelerator) + 1:
        spos = _np.resize(spos,len(accelerator)+1); spos[-1] = spos[-2] + accelerator[-1].length
        etax = _np.resize(etax,len(accelerator)+1); etax[-1] = etax[0]
        etapx = _np.resize(etapx,len(accelerator)+1); etapx[-1] = etapx[0]
        betax = _np.resize(betax,len(accelerator)+1); betax[-1] = betax[0]
        alphax = _np.resize(alphax,len(accelerator)+1); alphax[-1] = alphax[0]
    gammax = (1+alphax**2)/betax
    n = len(accelerator)
    angle, angle_in, angle_out, K = _np.zeros((4,n))
    for i in range(n):
        angle[i] = accelerator._accelerator.lattice[i].angle
        angle_in[i] = accelerator._accelerator.lattice[i].angle_in
        angle_out[i] = accelerator._accelerator.lattice[i].angle_out
        K[i] = accelerator._accelerator.lattice[i].polynom_b[1]
    idx, *_ = _np.nonzero(angle)
    leng = spos[idx+1]-spos[idx]
    rho  = leng/angle[idx]
    angle_in = angle_in[idx]
    angle_out = angle_out[idx]
    K = K[idx]
    etax_in, etax_out = etax[idx], etax[idx+1]
    etapx_in, etapx_out = etapx[idx], etapx[idx+1]
    betax_in, betax_out = betax[idx], betax[idx+1]
    alphax_in, alphax_out = alphax[idx], alphax[idx+1]
    gammax_in, gammax_out = gammax[idx], gammax[idx+1]
    H_in = betax_in*etapx_in**2 + 2*alphax_in*etax_in*etapx_in+gammax_in*etax_in**2
    H_out = betax_out*etapx_out**2 + 2*alphax_out*etax_out*etapx_out+gammax_out*etax_out**2

    etax_avg = 0.5*(etax_in+etax_out)
    rho2, rho3 = rho**2, rho**3
    rho3abs = _np.abs(rho3)

    integrals = [0.0]*6
    integrals[0] = _np.dot(etax_avg/rho, leng)
    integrals[1] = _np.dot(1/rho2, leng)
    integrals[2] = _np.dot(1/rho3abs, leng)
    integrals[3] = sum((etax_in/rho2)*_np.tan(angle_in)) + \
                   sum((etax_out/rho2)*_np.tan(angle_out)) + \
                   _np.dot((etax_avg/rho3)*(1+2*rho2*K), leng)
    integrals[4] = _np.dot(0.5*(H_in+H_out)/rho3abs, leng)
    integrals[5] = _np.dot((K*etax_avg)**2, leng)

    return integrals, twiss, m66
Example #3
0
def get_radiation_integrals(accelerator,
                            twiss=None,
                            m66=None,
                            closed_orbit=None):
    """Calculate radiation integrals for periodic systems"""

    if twiss is None or m66 is None:
        fixed_point = closed_orbit if closed_orbit is None else closed_orbit[:,
                                                                             0]
        twiss, m66 = calc_twiss(accelerator, fixed_point=fixed_point)

    spos = _lattice.find_spos(accelerator)

    # # Old get twiss
    # etax,etapx,betax,alphax = twiss,('etax','etapx','betax','alphax'))

    etax, etapx, betax, alphax = twiss.etax, twiss.etapx, twiss.betax, twiss.alphax

    if len(spos) != len(accelerator) + 1:
        spos = _np.resize(spos,
                          len(accelerator) + 1)
        spos[-1] = spos[-2] + accelerator[-1].length
        etax = _np.resize(etax,
                          len(accelerator) + 1)
        etax[-1] = etax[0]
        etapx = _np.resize(etapx,
                           len(accelerator) + 1)
        etapx[-1] = etapx[0]
        betax = _np.resize(betax,
                           len(accelerator) + 1)
        betax[-1] = betax[0]
        alphax = _np.resize(alphax,
                            len(accelerator) + 1)
        alphax[-1] = alphax[0]
    gammax = (1 + alphax**2) / betax
    n = len(accelerator)
    angle, angle_in, angle_out, K = _np.zeros((4, n))
    for i in range(n):
        angle[i] = accelerator._accelerator.lattice[i].angle
        angle_in[i] = accelerator._accelerator.lattice[i].angle_in
        angle_out[i] = accelerator._accelerator.lattice[i].angle_out
        K[i] = accelerator._accelerator.lattice[i].polynom_b[1]
    idx, *_ = _np.nonzero(angle)
    leng = spos[idx + 1] - spos[idx]
    rho = leng / angle[idx]
    angle_in = angle_in[idx]
    angle_out = angle_out[idx]
    K = K[idx]
    etax_in, etax_out = etax[idx], etax[idx + 1]
    etapx_in, etapx_out = etapx[idx], etapx[idx + 1]
    betax_in, betax_out = betax[idx], betax[idx + 1]
    alphax_in, alphax_out = alphax[idx], alphax[idx + 1]
    gammax_in, gammax_out = gammax[idx], gammax[idx + 1]
    H_in = betax_in * etapx_in**2 + 2 * alphax_in * etax_in * etapx_in + gammax_in * etax_in**2
    H_out = betax_out * etapx_out**2 + 2 * alphax_out * etax_out * etapx_out + gammax_out * etax_out**2

    etax_avg = 0.5 * (etax_in + etax_out)
    rho2, rho3 = rho**2, rho**3
    rho3abs = _np.abs(rho3)

    integrals = [0.0] * 6
    integrals[0] = _np.dot(etax_avg / rho, leng)
    integrals[1] = _np.dot(1 / rho2, leng)
    integrals[2] = _np.dot(1 / rho3abs, leng)
    integrals[3] = sum((etax_in/rho2)*_np.tan(angle_in)) + \
                   sum((etax_out/rho2)*_np.tan(angle_out)) + \
                   _np.dot((etax_avg/rho3)*(1+2*rho2*K), leng)
    integrals[4] = _np.dot(0.5 * (H_in + H_out) / rho3abs, leng)
    integrals[5] = _np.dot((K * etax_avg)**2, leng)

    return integrals, twiss, m66