particleflow.compute module

Convenience functions for computing various simulation related quantities.

particleflow.compute.orm(lattice: particleflow.elements.Segment, *, kickers: Union[str, Pattern, Type[Union[Element, AlignmentError]], Sequence[Union[int, str, Element, AlignmentError, Tuple[Union[str, Pattern, Type[Union[Element, AlignmentError]]], int]]]], monitors: Union[str, Pattern, Type[Union[Element, AlignmentError]], Sequence[Union[int, str, Element, AlignmentError, Tuple[Union[str, Pattern, Type[Union[Element, AlignmentError]]], int]]]], kicks: Tuple[float, float] = (-0.001, 0.001)) → Tuple[<MagicMock name='mock.Tensor' id='140244238396048'>, <MagicMock name='mock.Tensor' id='140244238396048'>]

Compute the orbit response matrix (ORM) for the given lattice, kickers and monitors.

Parameters
  • lattice (Segment) –

  • kickers (MultiElementSelector or list of SingleElementSelector) – Can be an identifier for selecting multiple kickers, or a list of identifiers each selecting a single kicker.

  • monitors (MultiElementSelector or list of SingleElementSelector) – Can be an identifier for selecting multiple monitors, or a list of identifiers each selecting a single monitor.

  • kicks (2-tuple of float) – The kick strengths to be used for measuring the orbit response.

Returns

orm_x, orm_y – Shape len(kickers), len(monitors).

Return type

torch.Tensor

particleflow.compute.closed_orbit(lattice: particleflow.elements.Segment, *, order: int = 1, max_iter: int = None, tolerance: float = 1e-09) → <MagicMock name='mock.Tensor' id='140244238396048'>

Closed orbit search for a given order on the given lattice.

The given lattice may contain Element`s as well as `AlignmentError`s. Alignment errors are treated as additional elements that wrap the actual element: entrance transformations coming before the element, in order, and exit transformations being placed after, in reverse order. The closed orbit search is a first-order iterative procedure with where each update :math:`x_{Delta} is computed as the solution of the following set of linear equations:

.. math:: \left[\mathbb{1} - R\right]\, x_{\Delta} = x_1 - x_0

where \(R\) is the one-turn transfer matrix and \(x_1\) is the orbit after one turn when starting from \(x_0\). \(R\) represents the Jacobian of the orbit w.r.t. itself.

Parameters
  • lattice (Segment) –

  • order (int) – The order at which transport maps are truncated (e.g. linear = 1).

  • max_iter (int, optional) – Maximum number of iterations.

  • tolerance (float, optional) – Maximum L2 distance between initial orbit and tracked orbit after one turn for convergence.

Returns

closed_orbit – Tensor of shape (6,) containing the closed orbit in the transverse coordinates and zeros for the longitudinal coordinates.

Return type

torch.Tensor

Raises

ConvergenceError – If the closed orbit search did not converge within the specified number of iterations for the given tolerance.

particleflow.compute.linear_closed_orbit(lattice: particleflow.elements.Segment) → <MagicMock name='mock.Tensor' id='140244238396048'>

Compute the linear closed orbit for the given lattice.

The given lattice may contain Element`s as well as `AlignmentError`s. Alignment errors are treated as additional elements that wrap the actual element: entrance transformations coming before the element, in order, and exit transformations being placed after, in reverse order. Hence all parts of the lattice can be described as a chain of linear transformations and the linear closed orbit is given as the solution to the following system of equations (in the transverse coordinates, for a total of :math:`n elements (actual elements and error transformations)):

\[\left[\mathbb{1} - \bar{R}_0\right]\, x_{co} = \sum_{i=1}^{n}\bar{R}_i\,d_i\]

where \(\bar{R}_i\) is given by:

\[\begin{split}\bar{R}_i \equiv \prod_{j=n\\j\rightarrow j-1}^{i+1}R_j\end{split}\]

and \(R_k, d_k\) are, respectively, the first and zero order term of the k-th element.

Parameters

lattice (Segment) –

Returns

linear_closed_orbit – Tensor of shape (6,) containing the closed orbit in the transverse coordinates and zeros for the longitudinal coordinates.

Return type

torch.Tensor

particleflow.compute.sectormaps(lattice: particleflow.elements.Segment, *, accumulate: bool = True) → Iterator[Tuple[str, <MagicMock name='mock.Tensor' id='140244238396048'>]]

Compute the transfer maps along the lattice.

Parameters
  • lattice (Segment) –

  • accumulate (bool, optional) – If true then the transfer maps are accumulated along the lattice (i.e. representing the compound transfer maps up to respective point along the lattice), otherwise the transfer maps belong to each single element.

Yields
  • label (str)

  • transfer_map (torch.Tensor)