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, 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.
- 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.
- 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:
z (
float)e_spats (
Collection[Callable[[float],float]])phi (
float)phi_0s (
Collection[float])scaling_factors (
Collection[float])
- Return type:
- 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:
z (
float)e_spats (
Collection[Callable[[float],float]])phi (
float)phi_0s (
Collection[float])scaling_factors (
Collection[float])
- Return type:
- z_drift(gamma_in, delta_s, omega_0_bunch, n_steps=1, **kwargs)[source]
Calculate the transfer matrix of a drift.
- 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.
- 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.
- 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_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, 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 \(\mathrm{m}\).omega0_rf (
float) – Pulsation of the cavity.scaled_e_middle (
complex)omega_0_bunch (
float)
- Return type:
- Returns:
Transfer matrix of the thin lense.
- 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 (
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.
- Return type:
- Returns:
Transfer matrix of the thin lense.
- 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 (
ndarray) – gamma and phase at the thin acceleration drift.half_dz (
float) – Half a spatial step in m.delta_gamma_m_maxs (
Collection[float]) – Max gamma increase if the cos(phi + phi_0) of the acc. field is 1.phi_0s (
Collection[float]) – Input phases of the elements.omega0_rf (
float) – Pulsation of the elements.omega_0_bunch (
float) – Bunch pulsation.
- Return type:
- Returns:
Transfer matrix of the thin lense.
- 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_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)\]