mbtrack2.tracking.emfields module

A package dealing with particles electromagnetic fields. For example, it can be applied to space charge, beam-beam force, electron lenses or beam-ion instabilities. This is largely adapted from a fork of PyHEADTAIL https://github.com/gubaidulinvadim/PyHEADTAIL. Only the fastest Fadeeva implementation of the error function is used here. See Oeftiger, A., de Maria, R., Deniau, L., Li, K., McIntosh, E., Moneta, L., Hegglin, S., Aviral, A. (2016). Review of CPU and GPU Faddeeva Implementations. https://cds.cern.ch/record/2207430/files/wepoy044.pdf

_wofz(x: ndarray[tuple[int, ...], dtype[_ScalarType_co]], y: ndarray[tuple[int, ...], dtype[_ScalarType_co]]) tuple[ndarray[tuple[int, ...], dtype[_ScalarType_co]], ndarray[tuple[int, ...], dtype[_ScalarType_co]]][source]

Compute the Faddeeva function w(z) = exp(-z^2) * erfc(-i*z).

Parameters

xfloat

Real part of the argument.

yfloat

Imaginary part of the argument.

Returns

tuple

Real and imaginary parts of the Faddeeva function.

_sqrt_sig(sig_x: float, sig_y: float) float[source]

Compute the square root of the difference between the squared transverse rms and vertical rms.

Parameters

sig_xfloat

Transverse rms of the distribution.

sig_yfloat

Vertical rms of the distribution.

Returns

float

Square root of the difference between the squared transverse rms and vertical rms.

_efieldn_mit(x: ndarray[tuple[int, ...], dtype[_ScalarType_co]], y: ndarray[tuple[int, ...], dtype[_ScalarType_co]], sig_x: float, sig_y: float) tuple[ndarray[tuple[int, ...], dtype[_ScalarType_co]], ndarray[tuple[int, ...], dtype[_ScalarType_co]]][source]

Returns electromagnetic fields as E_x/Q, E_y/Q in (V/m/Coulomb).

Parameters

xnp.ndarray

x coordinates in meters.

ynp.ndarray

y coordinates in meters.

sig_xfloat

Transverse rms of the distribution in meters.

sig_yfloat

Vertical rms of the distribution in meters.

Returns

tuple

Normalized electromagnetic fields Ex/Q, Ey/Q in the units of (V/m/Coulomb).

efieldn_gauss_round(x: ndarray[tuple[int, ...], dtype[_ScalarType_co]], y: ndarray[tuple[int, ...], dtype[_ScalarType_co]], sig_r: float, sig_r2: None = None) tuple[ndarray[tuple[int, ...], dtype[_ScalarType_co]], ndarray[tuple[int, ...], dtype[_ScalarType_co]]][source]

Computes the electromagnetic field of a round Gaussian distribution.

Parameters

xnp.ndarray

x coordinates in meters.

ynp.ndarray

y coordinates in meters.

sig_rfloat

Transverse rms of the distribution in meters.

Returns

tuple

Normalized electromagnetic fields Ex/Q, Ey/Q in the units of (V/m/Coulomb).

_efieldn_linearized(x: ndarray[tuple[int, ...], dtype[_ScalarType_co]], y: ndarray[tuple[int, ...], dtype[_ScalarType_co]], sig_x: float, sig_y: float) tuple[ndarray[tuple[int, ...], dtype[_ScalarType_co]], ndarray[tuple[int, ...], dtype[_ScalarType_co]]][source]

Computes linearized electromagnetic field.

Parameters

xnp.ndarray

x coordinate in meters.

ynp.ndarray

y coordinate in meters.

sig_xfloat

Vertical rms of the distribution in meters.

sig_yfloat

Vertical rms of the distribution in meters.

Returns

tuple

Normalized electromagnetic fields Ex/Q, Ey/Q in the units of (V/m/Coulomb).

add_sigma_check(efieldn: Callable) Callable[source]

Wrapper for a normalized electromagnetic field function. Adds the following actions before calculating the field: 1) Exchange x and y quantities if sig_x < sig_y. 2) Apply round beam field formula when sig_x is close to sig_y.

Parameters

efieldnfunction

Function to calculate normalized electromagnetic field.

Returns

function

Wrapped function, including round beam and inverted sig_x/sig_y.

get_displaced_efield(efieldn: Callable, xr: ndarray[tuple[int, ...], dtype[_ScalarType_co]], yr: ndarray[tuple[int, ...], dtype[_ScalarType_co]], sig_x: float, sig_y: float, mean_x: float, mean_y: float) tuple[ndarray[tuple[int, ...], dtype[_ScalarType_co]], ndarray[tuple[int, ...], dtype[_ScalarType_co]]][source]

Compute the charge-normalized electric field components of a two-dimensional Gaussian charge distribution.

Parameters

efieldnfunction

Calculates electromagnetic field of a given distribution of charges.

xrnp.array

x coordinates in meters.

yrnp.array

y coordinates in meters.

sig_xfloat

Horizontal rms size in meters.

sig_yfloat

Vertical rms size in meters.

mean_xfloat

Horizontal mean of the distribution in meters.

mean_yfloat

Vertical mean of the distribution in meters.

Returns

tuple

Charge-normalized electromagnetic fields with a displaced center of the distribution.