beam_calculation.envelope_1d.transfer_matrices_p 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

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.

z_bend(gamma_in: float, delta_s: float, factor_1: float, factor_2: float, factor_3: float) tuple[ndarray, ndarray, None]

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)\]
z_drift(gamma_in: float, delta_s: float, n_steps: int = 1) tuple[ndarray, ndarray, None]

Calculate the transfer matrix of a drift.

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], **kwargs) tuple[ndarray, ndarray, float]

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)

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], **kwargs) tuple[ndarray, ndarray, complex]

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

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) 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 (np.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.

Returns:

r_zz_array – Transfer matrix of the thin lense.

Return type:

np.ndarray