mbtrack2.tracking.wakepotential module

This module defines the WakePotential and LongRangeResistiveWall classes which deal with the single bunch and multi-bunch wakes.

class WakePotential(ring: Synchrotron, wakefield: WakeField, n_bin: int = 80, interp_on_position: bool = True)[source]

Bases: Element

Compute a wake potential from uniformly sampled wake functions by performing a convolution with a bunch charge profile.

Two different time bases are used. The first one is controled by the n_bin parameter and is used to compute the bunch profile. Then the bunch profile is interpolated on the wake function time base which is used to perform the convolution to get the wake potential.

Parameters

ring : Synchrotron object wakefield : Wakefield object

Wakefield object which contains the wake functions to be used. The wake functions must be uniformly sampled!

n_binint, optional

Number of bins for constructing the longitudinal bunch profile.

interp_on_positionbool, optional

If True, the computed wake potential is interpolated on the exact particle location. If False, the wake potential is interpolated on the bin center and each particle of the bin get the same value. Default is True.

Attributes

rhoarray of shape (n_bin, )

Bunch charge density profile in the unit [1/s].

Wparray

Wake potential profile.

Wp_interparray of shape (mp_number, )

Wake potential, obtained from interpolating Wp, exerted on each macro-particle.

Methods

charge_density(bunch)

Compute bunch charge density profile in [1/s].

dipole_moment(bunch, plane, tau0)

Return the dipole moment of the bunch computed on the same time array as the wake function.

prepare_wakefunction(wake_type)

Prepare the wake function of a given wake_type to be used for the wake potential computation.

get_wakepotential(bunch, wake_type)

Return the wake potential computed on the wake function time array limited to the bunch profile.

track(bunch)

Tracking method for the element.

plot_last_wake(wake_type)

Plot the last wake potential of a given type computed during the last call of the track method.

reference_loss(bunch)

Calculate the loss factor and kick factor from the wake potential and compare it to a reference value assuming a Gaussian bunch computed in the frequency domain.

check_sampling()

Check if the wake function sampling is uniform.

reduce_sampling(factor)

Reduce wake function samping by an integer factor.

__init__(ring: Synchrotron, wakefield: WakeField, n_bin: int = 80, interp_on_position: bool = True)[source]
_interp_regular_numpy(x_new: ndarray[tuple[int, ...], dtype[_ScalarType_co]], x_min: float, dx: float, y: ndarray[tuple[int, ...], dtype[_ScalarType_co]]) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

Linear interpolation funtion for uniformly sampled input data.

Parameters

x_newarray

New interpolation base.

x_minfloat

Minimum value of the original interpolant base.

dxfloat

Step of the original interpolant base.

yarray

Data to interpolate.

Returns

resultarray of len(x_new)

Data interpolated on x_new coordinates.

charge_density(bunch: Bunch)[source]

Compute bunch charge density profile in [1/s].

Parameters

bunch : Bunch object

dipole_moment(bunch: Bunch, plane: str, tau0: ndarray[tuple[int, ...], dtype[_ScalarType_co]]) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

Return the dipole moment of the bunch computed on the same time array as the wake function.

Parameters

bunch : Bunch object plane : str

Plane on which the dipole moment is computed, “x” or “y”.

tau0array

Time array on which the dipole moment will be interpolated, in [s].

Returns

dipolearray

Dipole moment of the bunch.

prepare_wakefunction(wake_type: str, tau: ndarray[tuple[int, ...], dtype[_ScalarType_co]], save_data: bool = True) tuple[ndarray[tuple[int, ...], dtype[_ScalarType_co]], float, ndarray[tuple[int, ...], dtype[_ScalarType_co]]][source]

Prepare the wake function of a given wake_type to be used for the wake potential computation.

The new time array keeps the same sampling time as given in the WakeFunction definition but is restricted to the bunch profile time array.

Parameters

wake_typestr

Type of the wake function to prepare: “Wlong”, “Wxdip”, …

tauarray

Time domain array of the bunch profile in [s].

save_databool, optional

If True, the results are saved as atributes.

Returns

tau0array

Time base of the wake function in [s].

dtau0float

Difference between two points of the wake function time base in [s].

W0array

Wake function array in [V/C] or [V/C/m].

get_wakepotential(bunch: Bunch, wake_type: str) tuple[ndarray[tuple[int, ...], dtype[_ScalarType_co]], ndarray[tuple[int, ...], dtype[_ScalarType_co]]][source]

Return the wake potential computed on the wake function time array limited to the bunch profile.

Parameters

bunch : Bunch object wake_type : str

Wake function type: “Wlong”, “Wxdip”, …

Returns

tau0array

Time base.

Wparray

Wake potential.

track(bunch: Bunch | Beam)[source]

Tracking method for the element. No bunch to bunch interaction, so written for Bunch objects and @Element.parallel is used to handle Beam objects.

Parameters

bunch : Bunch or Beam object.

plot_last_wake(wake_type: str, plot_rho: bool = True, plot_dipole: bool = False, plot_wake_function: bool = True, ax: Axes | None = None) Axes[source]

Plot the last wake potential of a given type computed during the last call of the track method.

Parameters

wake_typestr

Type of the wake to plot: “Wlong”, “Wxdip”, …

plot_rhobool, optional

Plot the normalised bunch profile. The default is True.

plot_dipolebool, optional

Plot the normalised dipole moment. The default is False.

plot_wake_functionbool, optional

Plot the normalised wake function. The default is True.

axAxes, optional

Axes where the plot is displayed. If None, a new figure is created.

Returns

ax : Axes

get_gaussian_wakepotential(sigma: float, wake_type: str, dipole: float = 0.001) tuple[ndarray[tuple[int, ...], dtype[_ScalarType_co]], ndarray[tuple[int, ...], dtype[_ScalarType_co]], ndarray[tuple[int, ...], dtype[_ScalarType_co]], ndarray[tuple[int, ...], dtype[_ScalarType_co]], ndarray[tuple[int, ...], dtype[_ScalarType_co]]][source]

Return the wake potential computed using a perfect gaussian profile.

Parameters

sigmafloat

RMS bunch length in [s].

wake_typestr

Wake function type: “Wlong”, “Wxdip”, …

dipolefloat, optional

Dipole moment to consider in [m], (uniform dipole moment).

Returns

tau0array

Time base in [s].

W0array

Wake function.

Wparray

Wake potential.

profile0array

Gaussian bunch profile.

dipole0array

Dipole moment.

plot_gaussian_wake(sigma: float, wake_type: str, dipole: float = 0.001, plot_rho: bool = True, plot_dipole: bool = False, plot_wake_function: bool = True, ax: Axes | None = None) Axes[source]

Plot the wake potential of a given type for a perfect gaussian bunch.

Parameters

sigmafloat

RMS bunch length in [s].

wake_typestr

Type of the wake to plot: “Wlong”, “Wxdip”, …

dipolefloat, optional

Dipole moment to consider in [m], (uniform dipole moment).

plot_rhobool, optional

Plot the normalised bunch profile. The default is True.

plot_dipolebool, optional

Plot the normalised dipole moment. The default is False.

plot_wake_functionbool, optional

Plot the normalised wake function. The default is True.

axAxes, optional

Axes where the plot is displayed. If None, a new figure is created.

Returns

ax : Axes

reference_loss(bunch: Bunch) DataFrame[source]

Calculate the loss factor and kick factor from the wake potential and compare it to a reference value assuming a Gaussian bunch computed in the frequency domain.

Parameters

bunch : Bunch object

Returns

loss_dataDataFrame

An output showing the loss/kick factors compared to the reference values.

check_sampling()[source]

Check if the wake function sampling is uniform.

Raises

ValueError

reduce_sampling(factor: int)[source]

Reduce wake function samping by an integer factor.

Used to reduce computation time for long bunches.

Parameters

factor : int

_set_wakefunction_max_frequency()[source]
property wakefunction_max_frequency: float

Return the wake function maximum frequency in [Hz].

property binning_max_frequency: float

Return the binning maximum frequency in [Hz].

property wakepotential_max_frequency: float

Return the wake potential maximum frequency in [Hz].

_abc_impl = <_abc._abc_data object>
class LongRangeResistiveWall(ring: Synchrotron, beam: Beam, length: float, rho: float, radius: float, types: list[str] = ['Wlong', 'Wxdip', 'Wydip'], nt: int = 50, x3: float | None = None, y3: float | None = None, x3_quad: float | None = None, y3_quad: float | None = None, average_beta: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | None = None)[source]

Bases: Element

Element to deal with multi-bunch and multi-turn wakes from resistive wall using the algorithm defined in [1].

Main approximations:
  • Bunches are treated as point charge.

  • Assymptotic expression for the resistive wall wake functions are

used. - Multi-turn wakes are limited to nt turns.

Self-bunch interaction is not included in this element and should be dealed with the WakePotential class.

Parameters

ring : Synchrotron object beam : Beam object length : float

Length of the resistive pipe to consider in [m].

rhofloat

Effective resistivity to consider in [ohm.m] as in [1].

radiusfloat

Beam pipe radius to consider in [m].

typesstr or list, optional

Wake types to consider. Available types are: “Wlong”,”Wxdip”,”Wydip”,”Wxquad”,”Wyquad”. The default is [“Wlong”,”Wxdip”,”Wydip”].

ntint or float, optional

Number of turns to consider for the long range wakes. The default is 50.

x3float, optional

Horizontal effective radius of the 3rd power in [m], as Eq.27 in [1]. The default is radius.

y3float, optional

Vertical effective radius of the 3rd power in [m], as Eq.27 in [1]. The default is radius.

x3_quadfloat, optional

Quadrupolar wake horizontal effective radius of the 3rd power in [m]. As given by ResistiveWallModel.resistive_wall_effective_radius_yokoya. The quadrupolar radius can be either be positive (defocusing) or negative (focusing). The default is None.

y3_quadfloat, optional

Quadrupolar wake vertical effective radius of the 3rd power in [m]. As given by ResistiveWallModel.resistive_wall_effective_radius_yokoya. The quadrupolar radius can be either be positive (defocusing) or negative (focusing). The default is None.

average_betaarray-like of shape (2,), optional

Average beta function used for kick normalization in [m]. The transverse kick is normalized by average_beta / local_beta. If None and an AT lattice is loaded, average_beta is computed from the lattice. If None and an AT lattice is not loaded, average_beta is taken to be equal to local_beta, i.e. no normalization. The default is None.

References

[1] : Skripka, Galina, et al. “Simultaneous computation of intrabunch and interbunch collective beam motions in storage rings.” NIM.A (2016).

__init__(ring: Synchrotron, beam: Beam, length: float, rho: float, radius: float, types: list[str] = ['Wlong', 'Wxdip', 'Wydip'], nt: int = 50, x3: float | None = None, y3: float | None = None, x3_quad: float | None = None, y3_quad: float | None = None, average_beta: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | None = None)[source]
Wlong(t: float) float[source]

Approxmiate expression for the longitudinal resistive wall wake function - Eq.24 of [1].

Parameters

tfloat

Time in [s].

Returns

wlfloat

Wake function in [V/C].

Wdip(t: float, plane: str) float[source]

Approxmiate expression for the transverse resistive wall wake function - Eq.26 of [1].

Parameters

tfloat

Time in [s].

planestr

“x” or “y”.

Returns

wdipfloat

Wake function in [V/C/m].

update_tables(beam: Beam)[source]

Update tables.

Table tau[i,j] is defined as the time difference of the bunch i center of mass with respect to center of the RF bucket number 0 at turn j. Turn 0 corresponds to the tracked turn.

Positive time corresponds to past events and negative time to future events.

Parameters

beam : Beam object

Returns

None.

_abc_impl = <_abc._abc_data object>
get_kick(rank: int, wake_type: float) float[source]

Compute the wake kick to apply.

Parameters

rankint

Rank of the bunch, as defined in Mpi class.

wake_typefloat

Type of the wake to compute.

Returns

sum_kickfloat

Sum of the kicks from the different bunches at different turns.

track_bunch(bunch: Bunch, rank: int)[source]

Track a bunch.

Should only be used within the track method and not standalone.

Parameters

bunch : Bunch object rank : int

Rank of the bunch, as defined in Mpi class.

Returns

None.

track(beam: Beam)[source]

Track a beam.

Parameters

beam : Beam object

Returns

None.