transfer_matrices module

Define every element longitudinal transfer matrix.

Units are taken exactly as in TraceWin, i.e. first line is z (m) and second line is dp/p.

Todo

Possible to use only lists here. May speed up the code, especially in _c. But numpy is fast, no?

Todo

send beta as argument to avoid recomputing it each time

Todo

electric field interpolated twice: a first time for acceleration, and a second time to iterate itg_field. Maybe this could be done only once.

e_func(z, e_spat, phi, phi_0)[source]

Give the electric field at position z and phase phi.

The field is normalized and should be multiplied by k_e.

Parameters:
Return type:

float

e_func_complex(z, e_spat, phi, phi_0)[source]

Give the complex electric field at position z and phase phi.

The field is normalized and should be multiplied by k_e.

Parameters:
Return type:

complex

e_funcs_scaled(z, e_spats, phi, phi_0s, scaling_factors)[source]

Give the electric field at position z and phase phi w/ several maps.

Note

In contrary to e_func(), it is mandatory to give the field maps scaling factors here.

Parameters:
Return type:

float

e_funcs_scaled_complex(z, e_spats, phi, phi_0s, scaling_factors)[source]

Give complex electric field at position z and phase phi w/ several maps.

Note

In contrary to e_func(), it is mandatory to give the field maps scaling factors here.

Parameters:
Return type:

complex

z_drift(gamma_in, delta_s, omega_0_bunch, n_steps=1, **kwargs)[source]

Calculate the transfer matrix of a drift.

Parameters:
Return type:

tuple[ndarray, ndarray, None]

z_field_map_rk4(gamma_in, d_z, n_steps, omega0_rf, k_e, phi_0_rel, e_spat, q_adim, inv_e_rest_mev, omega_0_bunch, **kwargs)[source]

Calculate the transfer matrix of a FIELD_MAP using Runge-Kutta.

Parameters:
Return type:

tuple[ndarray, ndarray, complex]

z_superposed_field_maps_rk4(gamma_in, d_z, n_steps, omega0_rf, k_es, phi_0_rels, e_spats, omega_0_bunch, q_adim, inv_e_rest_mev, **kwargs)[source]

Calculate the transfer matrix of superposed FIELD_MAP using RK.

Parameters:
Return type:

tuple[ndarray, ndarray, complex]

z_field_map_leapfrog(d_z, gamma_in, n_steps, omega0_rf, k_e, phi_0_rel, e_spat, q_adim, inv_e_rest_mev, gamma_init, omega_0_bunch, **kwargs)[source]

Calculate the transfer matrix of a FIELD_MAP using leapfrog.

Todo

clean, fix, separate leapfrog integration in dedicated module

This method is less precise than RK4. However, it is much faster.

Classic leapfrog method: speed(i+0.5) = speed(i-0.5) + accel(i) * dt pos(i+1) = pos(i) + speed(i+0.5) * dt

Here, dt is not fixed but dz. z(i+1) += dz t(i+1) = t(i) + dz / (c beta(i+1/2)) (time and space variables are on whole steps) beta calculated from W(i+1/2) = W(i-1/2) + qE(i)dz (speed/energy is on half steps)

Parameters:
Return type:

tuple[ndarray, ndarray, float]

z_thin_lense_new(scaled_e_middle, gamma_in, gamma_out, gamma_middle, half_dz, omega0_rf, omega_0_bunch, **kwargs)[source]

Thin lense approximation: drift-acceleration-drift.

Parameters:
  • gamma_in (float) – gamma at entrance of first drift.

  • gamma_out (float) – gamma at exit of first drift.

  • gamma_middle (float) – gamma at the thin acceleration drift.

  • half_dz (float) – Half a spatial step in m.

  • omega0_rf (float) – Pulsation of the cavity.

  • scaled_e_middle (complex)

  • omega_0_bunch (float)

Returns:

r_zz_array – Transfer matrix of the thin lense.

Return type:

numpy.ndarray

z_thin_lense(gamma_in, gamma_out, gamma_phi_m, half_dz, delta_gamma_m_max, phi_0, omega0_rf, omega_0_bunch, **kwargs)[source]

Thin lense approximation: drift-acceleration-drift.

Parameters:
  • gamma_in (float) – gamma at entrance of first drift.

  • gamma_out (float) – gamma at exit of first drift.

  • gamma_phi_m (numpy.ndarray) – gamma and phase at the thin acceleration drift.

  • half_dz (float) – Half a spatial step in m.

  • delta_gamma_m_max (float) – Max gamma increase if the cos(phi + phi_0) of the acc. field is 1.

  • phi_0 (float) – Input phase of the cavity.

  • omega0_rf (float) – Pulsation of the cavity.

  • omega_0_bunch (float) – Pulsation of the beam.

Returns:

r_zz_array – Transfer matrix of the thin lense.

Return type:

numpy.ndarray

z_thin_lense_superposed(gamma_in, gamma_out, gamma_phi_m, half_dz, delta_gamma_m_maxs, phi_0s, omega0_rf, omega_0_bunch, **kwargs)[source]

Compute trajectory with thin lense approximation: drift-acceleration-drift.

Parameters:
  • gamma_in (float) – gamma at entrance of first drift.

  • gamma_out (float) – gamma at exit of first drift.

  • gamma_phi_m (numpy.ndarray) – gamma and phase at the thin acceleration drift.

  • half_dz (float) – Half a spatial step in m.

  • delta_gamma_m_maxs (float) – Max gamma increase if the cos(phi + phi_0) of the acc. field is 1.

  • phi_0s (float) – Input phases of the elements.

  • omega0_rf (float) – Pulsation of the elements.

  • omega_0_bunch (float) – Bunch pulsation.

Returns:

r_zz_array – Transfer matrix of the thin lense.

Return type:

numpy.ndarray

z_bend(gamma_in, delta_s, factor_1, factor_2, factor_3, omega_0_bunch, **kwargs)[source]

Compute the longitudinal transfer matrix of a bend.

factor_1 is:

\[\frac{-h^2\Delta s}{k_x^2}\]

factor_2 is:

\[\frac{h^2 \sin{(k_x\Delta s)}}{k_x^3}\]

factor_3 is:

\[\Delta s \left(1 - \frac{h^2}{k_x^2}\right)\]
Parameters:
Return type:

tuple[ndarray, ndarray, None]