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, _is_multipart, _solver_id, _beam_kwargs)[source]

Bases: ABC

A base class for creation of SimulationOutput.

Parameters:
_is_3d: bool
_is_multipart: bool
_solver_id: str
_beam_kwargs: BeamKwargs
__post_init__()[source]

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().

Return type:

None

abstract property _transfer_matrix_factory_class: ABCMeta

Declare the class of the transfer matrix factory.

abstract property _beam_parameters_factory_class: ABCMeta

Declare the class of the beam parameters factory.

abstract run(elts, *args, **kwargs)[source]

Create the SimulationOutput.

Parameters:

elts (ListOfElements)

Return type:

SimulationOutput

_generate_element_to_index_func(elts)[source]

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

Parameters:

elts (ListOfElements)

Return type:

ELEMENT_TO_INDEX_T

__init__(_is_3d, _is_multipart, _solver_id, _beam_kwargs)
Parameters:
_abc_impl = <_abc._abc_data object at 0x70e253aefc40>
_element_to_index(_elts, _shift, _solver_id, elt, pos=None, return_elt_idx=False, handle_missing_elt=False)[source]

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 ElementBeamCalculatorParameters.

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

  • pos (Literal['in', 'out'] | None, default: None) – Index of entry or exit of the Element. If None, return full indexes array.

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

  • handle_missing_elt (bool, default: False) – Look for an equivalent element when elt is not in _elts.

Returns:

Index of range of indexes where elt is.

Return type:

int | slice