beam_calculation.simulation_output.factory module

Define a class to easily generate the SimulationOutput.

This class should be subclassed by every BeamCalculator to match its own specific outputs.

class SimulationOutputFactory(_is_3d: bool, _is_multipart: bool, _solver_id: str)

Bases: ABC

A base class for creation of SimulationOutput.

__init__(_is_3d: bool, _is_multipart: bool, _solver_id: str) None
__post_init__() None

Create the factories.

The created factories are TransferMatrixFactory and BeamParametersFactory. The sub-class that is used is declared in _transfer_matrix_factory_class() and _beam_parameters_factory_class().

_abc_impl = <_abc._abc_data object>
abstract property _beam_parameters_factory_class: ABCMeta

Declare the class of the beam parameters factory.

_generate_element_to_index_func(elts: ListOfElements) Callable[[Element, str | None], int | slice]

Create the func to easily get data at proper mesh index.

_is_3d: bool
_is_multipart: bool
_solver_id: str
abstract property _transfer_matrix_factory_class: ABCMeta

Declare the class of the transfer matrix factory.

abstract run(elts: ListOfElements, *args, **kwargs) SimulationOutput

Create the SimulationOutput.

_element_to_index(_elts: ListOfElements, _shift: int, _solver_id: str, elt: Element | str, pos: str | None = None, return_elt_idx: bool = False) int | slice

Convert elt and pos into a mesh index.

This way, you can call get('w_kin', elt='FM5', pos='out') and systematically get the energy at the exit of FM5, whatever the BeamCalculator or the mesh size is.

Todo

different functions, for different outputs. At least, an _element_to_index and a _element_to_indexes. And also a different function for when the index element is desired.

Parameters:
  • _elts (ListOfElements) – List of Element where elt should be. Must be set by a functools.partial().

  • _shift (int) – Mesh index of first Element. Used when the first Element of _elts is not the first of the Accelerator. Must be set by functools.partial().

  • _solver_id (str) – Name of the solver, to identify and take the proper SingleElementBeamParameters.

  • elt (Element | str) – Element of which you want the index.

  • pos ({'in', 'out} | None, optional) – Index of entry or exit of the Element. If None, return full indexes array. The default is None.

  • return_elt_idx (bool, optional) – If True, the returned index is the position of the element in _elts.

Returns:

Index of range of indexes where elt is.

Return type:

int | slice