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
Use e_func_complex() in z_field_map_rk4()?
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: float, e_spat: Callable[[float], float], phi: float, phi_0: float) float
Give the electric field at position z and phase phi.
The field is normalized and should be multiplied by k_e.
- e_func_complex(z: float, e_spat: Callable[[float], float], phi: float, phi_0: float) complex
Give the complex electric field at position z and phase phi.
The field is normalized and should be multiplied by k_e.
- e_funcs_scaled(z: float, e_spats: Collection[Callable[[float], float]], phi: float, phi_0s: Collection[float], scaling_factors: Collection[float]) float
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.
- e_funcs_scaled_complex(z: float, e_spats: Collection[Callable[[float], float]], phi: float, phi_0s: Collection[float], scaling_factors: Collection[float]) complex
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.
- z_drift(gamma_in: float, delta_s: float, omega_0_bunch: float, n_steps: int = 1, **kwargs) tuple[ndarray, ndarray, None]
Calculate the transfer matrix of a drift.
- z_field_map_rk4(gamma_in: float, d_z: float, n_steps: int, omega0_rf: float, k_e: float, phi_0_rel: float, e_spat: Callable[[float], float], q_adim: float, inv_e_rest_mev: float, omega_0_bunch: float, **kwargs) tuple[ndarray, ndarray, complex]
Calculate the transfer matrix of a FIELD_MAP using Runge-Kutta.
- z_superposed_field_maps_rk4(gamma_in: float, d_z: float, n_steps: int, omega0_rf: float, k_es: Collection[float], phi_0_rels: Collection[float], e_spats: Collection[Callable[[float], float]], omega_0_bunch: float, q_adim: float, inv_e_rest_mev: float, **kwargs) tuple[ndarray, ndarray, complex]
Calculate the transfer matrix of superposed FIELD_MAP using RK.
- z_field_map_leapfrog(d_z: float, gamma_in: float, n_steps: int, omega0_rf: float, k_e: float, phi_0_rel: float, e_spat: Callable[[float], float], q_adim: float, inv_e_rest_mev: float, gamma_init: float, omega_0_bunch: float, **kwargs) tuple[ndarray, ndarray, float]
Calculate the transfer matrix of a
FIELD_MAPusing 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)
- z_thin_lense_new(scaled_e_middle: complex, gamma_in: float, gamma_out: float, gamma_middle: float, half_dz: float, omega0_rf: float, omega_0_bunch: float, **kwargs) ndarray
Thin lense approximation: drift-acceleration-drift.
- Parameters:
- Returns:
r_zz_array – Transfer matrix of the thin lense.
- Return type:
- z_thin_lense(gamma_in: float, gamma_out: float, gamma_phi_m: ndarray, half_dz: float, delta_gamma_m_max: float, phi_0: float, omega0_rf: float, omega_0_bunch: float, **kwargs) ndarray
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:
- z_thin_lense_superposed(gamma_in: float, gamma_out: float, gamma_phi_m: ndarray, half_dz: float, delta_gamma_m_maxs: Collection[float], phi_0s: Collection[float], omega0_rf: float, omega_0_bunch: float, **kwargs) ndarray
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:
- z_bend(gamma_in: float, delta_s: float, factor_1: float, factor_2: float, factor_3: float, omega_0_bunch: float, **kwargs) tuple[ndarray, ndarray, None]
Compute the longitudinal transfer matrix of a bend.
factor_1is:\[\frac{-h^2\Delta s}{k_x^2}\]factor_2is:\[\frac{h^2 \sin{(k_x\Delta s)}}{k_x^3}\]factor_3is:\[\Delta s \left(1 - \frac{h^2}{k_x^2}\right)\]