factory module

Define an object to create ListOfElements.

Its main goal is to initialize ListOfElements with the proper input synchronous particle and beam properties. whole_list_run() is called within the Accelerator and generate a full ListOfElements from scratch.

subset_list_run() is called within Fault and generates a ListOfElements that contains only a fraction of the linac.

Todo

Also handle DST file in subset_list_run().

Todo

Maybe it will be necessary to handle cases where the synch particle is not perfectly on the axis?

Todo

Find a smart way to sublass ListOfElementsFactory according to the BeamCalculator… Loading field maps not necessary with TraceWin for example.

Todo

The elements_to_dump key should be in the configuration file

class ListOfElementsFactory(is_3d, is_multipart, default_field_map_folder, load_fields, beam_kwargs, field_maps_in_3d=False, load_cython_field_maps=False, elements_to_dump=())[source]

Bases: object

Factory class to create list of elements from different contexts.

Parameters:
__init__(is_3d, is_multipart, default_field_map_folder, load_fields, beam_kwargs, field_maps_in_3d=False, load_cython_field_maps=False, elements_to_dump=())[source]

Declare and create some mandatory factories.

Note

For now, we have only one input_beam parameters, we create only one ListOfElements. Hence we create in the most general way possible. We instantiate InitialBeamParametersFactory with is_3d=True and is_multipart=True because it will work with all the BeamCalculator objects – some phase-spaces may be created but never used though.

Parameters:
  • is_3d (bool) – Whether simulation is in 3D. This is currently not used, as we always generate 3D InitialBeamParameters.

  • is_multipart (bool) – Whether simulation is multiparticle. This is currently not used, as we always generate multiparticle InitialBeamParameters.

  • default_field_map_folder (Path) – Where to look for field map files.

  • beam_kwargs (BeamKwargs) – Arguments to instantiate InitialBeamParameters.

  • load_field_maps – If field maps should be loaded; this is not necessary with TraceWin.

  • field_maps_in_3d (bool, default: False) – If the given field map files are 3D.

  • load_cython_field_maps (bool, default: False) – If the solver is implemented in cython.

  • elements_to_dump (ABCMeta | tuple[ABCMeta, ...], default: ()) – Explicit list of Element that can be safely ignored.

  • load_fields (bool)

whole_list_run(dat_file, accelerator_path, sigma_in, w_kin, phi_abs, z_in, instructions_to_insert=())[source]

Create a new ListOfElements, encompassing a full linac.

Factory function called from within the Accelerator object.

Parameters:
  • dat_file (Path) – Absolute path to the DAT file.

  • accelerator_path (Path) – Absolute path where results for each BeamCalculator will be stored.

  • sigma_in (ndarray[tuple[Any, ...], dtype[double]]) – \(\sigma\) beam matrix at the entrance of the linac.

  • w_kin (float) – Kinetic energy of the beam in \(\mathrm{MeV}\).

  • phi_abs (float) – Absolute beam phase in \(\mathrm{rad}\).

  • z_in (float) – Absolute entry position of the linac in \(\mathrm{m}\).

  • instructions_to_insert (Collection[Instruction | DatLine], default: ()) – Some elements or commands that are not present in the DAT file but that you want to add. The default is an empty tuple.

  • kwargs – Arguments to instantiate the input particle and beam properties.

Return type:

ListOfElements

Returns:

Contains all the Element of the linac, as well as the proper particle and beam properties at its entry.

subset_list_run(elts, simulation_output, files_from_full_list_of_elements)[source]

Create a ListOfElements as subset of a previous one.

Factory function used during the fitting process, called by a Fault object. During this optimisation process, we compute the propagation of the beam only on the smallest possible subset of the linac.

It creates the proper ParticleInitialState and BeamParameters objects. In contrary to whole_list_run(), the BeamParameters must contain information on the transverse plane if beam propagation is performed with TraceWin.

Parameters:
Return type:

ListOfElements

Returns:

Contains all the elements that will be recomputed during the optimisation, as well as the proper particle and beam properties at its entry.

_subset_files_dictionary(elts, files_from_full_list_of_elements, folder=PosixPath('tmp'), dat_name=PosixPath('tmp.dat'))[source]

Set the new DAT file containing only elements of elts.

Parameters:
Return type:

FilesInfo

_delta_phi_for_tracewin(phi_at_entry_of_compensation_zone)[source]

Give new absolute phases for TraceWin.

In TraceWin, the absolute phase at the entrance of the compensation zone is 0, while it is not in the rest of the code. Hence we must rephase the cavities in the subset.

Parameters:

phi_at_entry_of_compensation_zone (float)

Return type:

float

_get_initial_element(elts, simulation_output)[source]

Set the element from which we should take energy, phase, etc.

Parameters:
Return type:

tuple[Element | str, str]

_subset_input_particle(simulation_output, **kwargs)[source]

Create input particle for subset of list of elements.

Parameters:
Return type:

ParticleInitialState

from_existing_list(elts, *, instructions_to_insert=(), append_stem='', which_phase='phi_0_rel')[source]

Create new list of elements, based on an exising one.

This method is used for beauty pass: we already have fixed the linac, but we want to add DIAG/ADJUST TraceWin commands to perform a second optimisation.

Todo

Maybe gather some things with the subset?

Parameters:
Return type:

ListOfElements