element_envelope1d_parameters module

Define a class to hold solver parameters for Envelope1D.

This module holds ElementEnvelope1DParameters, that inherits from the Abstract Base Class ElementBeamCalculatorParameters. It holds the transfer matrix function that is used, according to the solver (Runge-Kutta or leapfrog) and their version (Python or Cython), as well as the meshing in accelerating elements.

The Element objects with a transfer matrix are DRIFT, SOLENOID, QUAD, FIELD_MAP, BEND.

class ElementEnvelope1DParameters(length_m: float, n_steps: int, beam_kwargs: dict[str, Any], transf_mat_function: Callable | None = None, **kwargs: str | int)

Bases: ElementBeamCalculatorParameters

Hold the parameters to compute beam propagation in an Element.

has and get method inherited from ElementBeamCalculatorParameters parent class.

__init__(length_m: float, n_steps: int, beam_kwargs: dict[str, Any], transf_mat_function: Callable | None = None, **kwargs: str | int) None

Set the actually useful parameters.

set_absolute_meshes(pos_in: float, s_in: int) tuple[float, int]

Set the absolute indexes and arrays, depending on previous elem.

re_set_for_broken_cavity() None

Change solver parameters for efficiency purposes.

transfer_matrix_kw(*args, **kwargs) dict[str, Any]

Give the element parameters necessary to compute transfer matrix.

transf_mat_function_wrapper(w_kin: float, phi_0_rel: float | None = None, cavity_settings: Any = None, **kwargs) dict

Calculate beam propagation in the Element.

kwargs can be cavity_settings rf_field

_transfer_matrix_results_to_dict(r_zz: ndarray, gamma_phi: ndarray, integrated_field: float | None) dict

Convert the results given by the transf_mat function to dict.

_proper_transfer_matrix_func(element_nature: str, method: Literal['RK4', 'leapfrog'] | None = None) Callable

Get the proper transfer matrix function.

_abc_impl = <_abc._abc_data object at 0x7f36f92f9000>
class DriftEnvelope1DParameters(elt: Element, beam_kwargs: dict[str, Any], n_steps: int = 1, **kwargs: str | int)

Bases: ElementEnvelope1DParameters

Hold the properties to compute transfer matrix of a Drift.

As this is 1D, it is also used for Solenoid, Quad, broken FieldMap.

__init__(elt: Element, beam_kwargs: dict[str, Any], n_steps: int = 1, **kwargs: str | int) None

Create the specific parameters for a drift.

_abc_impl = <_abc._abc_data object at 0x7f36f9557d00>
class FieldMapEnvelope1DParameters(elt: FieldMap, method: Literal['RK4', 'leapfrog'], n_steps_per_cell: int, solver_id: str, beam_kwargs: dict[str, Any], phi_s_model: Literal['historical', 'lagniel'] = 'historical', **kwargs: str | int)

Bases: ElementEnvelope1DParameters

Hold the properties to compute transfer matrix of a FieldMap.

Non-accelerating cavities will use DriftEnvelope1DParameters instead.

__init__(elt: FieldMap, method: Literal['RK4', 'leapfrog'], n_steps_per_cell: int, solver_id: str, beam_kwargs: dict[str, Any], phi_s_model: Literal['historical', 'lagniel'] = 'historical', **kwargs: str | int) None

Create the specific parameters for a field map.

transfer_matrix_kw(w_kin: float, cavity_settings: CavitySettings, *args, phi_0_rel: float | None = None, **kwargs) dict[str, Any]

Give the element parameters necessary to compute transfer matrix.

Parameters:
  • w_kin (float) – Kinetic energy at the entrance of cavity in \(\mathrm{MeV}\).

  • cavity_settings (CavitySettings) – Object holding the cavity parameters that can be changed.

  • phi_0_rel (float | None) – Relative entry phase of the cavity. When provided, it means that we are trying to find the \(\phi_{0,\,\mathrm{rel}}\) matching a given \(\phi_s\). The default is None.

Returns:

Keyword arguments that will be passed to the 1D transfer matrix function defined in envelope_1d.transfer_matrices.

Return type:

dict[str, Any]

_transfer_matrix_results_to_dict(r_zz: ndarray, gamma_phi: ndarray, integrated_field: float | None) dict

Convert the results given by the transf_mat function to a dict.

Overrides the default method defined in the ABC.

re_set_for_broken_cavity() Callable

Make beam calculator call Drift func instead of FieldMap.

_broken_transfer_matrix_results_to_dict(r_zz: ndarray, gamma_phi: ndarray, integrated_field: float | None) dict

Convert the results given by the transf_mat function to a dict.

_broken_transfer_matrix_kw(*args, **kwargs) dict[str, Any]

Give the element parameters necessary to compute transfer matrix.

_abc_impl = <_abc._abc_data object at 0x7f36f9557ec0>
_get_phi_0_rel(cavity_settings: CavitySettings) float

Get the phase from the object.

class SuperposedFieldMapEnvelope1DParameters(elt: SuperposedFieldMap, method: Literal['RK4'], n_steps_per_cell: int, solver_id: str, beam_kwargs: dict[str, Any], phi_s_model: Literal['historical', 'lagniel'] = 'historical', **kwargs: str | int)

Bases: ElementEnvelope1DParameters

Hold properties to compute transfer matrix of SuperposedFieldMap.

__init__(elt: SuperposedFieldMap, method: Literal['RK4'], n_steps_per_cell: int, solver_id: str, beam_kwargs: dict[str, Any], phi_s_model: Literal['historical', 'lagniel'] = 'historical', **kwargs: str | int) None

Create the specific parameters for a field map.

transfer_matrix_kw(w_kin: float, cavity_settings: Sequence[CavitySettings], *args, **kwargs) dict[str, Any]

Give the element parameters necessary to compute transfer matrix.

_transfer_matrix_results_to_dict(r_zz: ndarray, gamma_phi: ndarray, integrated_field: float | None) dict

Convert the results given by the transf_mat function to a dict.

Overrides the default method defined in the ABC.

re_set_for_broken_cavity() None

Make beam calculator call Drift func instead of FieldMap.

_abc_impl = <_abc._abc_data object at 0x7f36f9557dc0>
class BendEnvelope1DParameters(elt: Bend, beam_kwargs: dict[str, Any], n_steps: int = 1, **kwargs: str | int)

Bases: ElementEnvelope1DParameters

Hold the specific parameters to compute Bend transfer matrix.

In particular, we define factor_1, factor_2 and factor_3 to speed-up calculations.

__init__(elt: Bend, beam_kwargs: dict[str, Any], n_steps: int = 1, **kwargs: str | int) None

Instantiate object and pre-compute some parameters for speed.

Parameters:
  • transf_mat_module (types.ModuleType) – Module where the transfer matrix function is defined.

  • elt (Bend) – BEND element.

  • beam_kwargs (dict[str, Any]) – Configuration dict holding all initial beam properties.

  • n_steps (int, optional) – Number of integration steps. The default is 1.

_pre_compute_factors_for_transfer_matrix(length_m: float, h_squared: float, k_x: float, index_is_lower_than_unity: bool) tuple[float, float, float]

Compute factors to speed up the transfer matrix calculation.

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}\]

if \(n \leq 1\). Else:

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

factor_3 is:

\[\Delta s \left(1 - \frac{h^2}{k_x^2}\right)\]
transfer_matrix_kw(*args, **kwargs) dict[str, Any]

Give the element parameters necessary to compute transfer matrix.

_abc_impl = <_abc._abc_data object at 0x7f36f9557e00>
_add_cavities_phases(solver_id: str, w_kin_in: float, cavities_settings: Collection[CavitySettings], rf_parameters_as_dict: dict[str, list[Callable] | int | float | list[float]]) None

Set reference phase and function to compute \(\phi_s\).