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, beam_kwargs, load_field_maps=True, field_maps_in_3d=False, load_cython_field_maps=False, elements_to_dump=())[source]
Bases:
objectFactory class to create list of elements from different contexts.
- Parameters:
- __init__(is_3d, is_multipart, default_field_map_folder, beam_kwargs, load_field_maps=True, 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_beamparameters, we create only oneListOfElements. Hence we create in the most general way possible. We instantiateInitialBeamParametersFactorywithis_3d=Trueandis_multipart=Truebecause it will work with all theBeamCalculatorobjects – some phase-spaces may be created but never used though.- Parameters:
phi_s_definition – Definition for the synchronous phases that will be used. Allowed values are in
PHI_S_MODELS. The default is'historical'.is_3d (
bool)is_multipart (
bool)default_field_map_folder (
Path)beam_kwargs (
BeamKwargs)load_field_maps (
bool, default:True)field_maps_in_3d (
bool, default:False)load_cython_field_maps (
bool, default:False)elements_to_dump (
ABCMeta|tuple[ABCMeta,...], default:())
- whole_list_run(dat_file, accelerator_path, instructions_to_insert=(), **kwargs)[source]
Create a new
ListOfElements, encompassing a full linac.Factory function called from within the
Acceleratorobject.- Parameters:
dat_file (
Path) – Absolute path to theDATfile.accelerator_path (
Path) – Absolute path where results for eachBeamCalculatorwill be stored.instructions_to_insert (
Collection[Instruction|DatLine], default:()) – Some elements or commands that are not present in theDATfile but that you want to add. The default is an empty tuple.kwargs (
Any) – Arguments to instantiate the input particle and beam properties.
- Return type:
- Returns:
Contains all the
Elementof the linac, as well as the proper particle and beam properties at its entry.
- _whole_list_input_particle(w_kin, phi_abs, z_in, **kwargs)[source]
Create a
ParticleInitialStatefor full list of elts.- Parameters:
- Return type:
- subset_list_run(elts, simulation_output, files_from_full_list_of_elements)[source]
Create a
ListOfElementsas subset of a previous one.Factory function used during the fitting process, called by a
Faultobject. During this optimisation process, we compute the propagation of the beam only on the smallest possible subset of the linac.It creates the proper
ParticleInitialStateandBeamParametersobjects. In contrary towhole_list_run(), theBeamParametersmust contain information on the transverse plane if beam propagation is performed withTraceWin.- Parameters:
elts (
list[Element]) – A plain list containing the elements objects that the object should contain.simulation_output (
SimulationOutput) – Holds the results of the pre-existing list of elements.files_from_full_list_of_elements (
FilesInfo) – Thefilesattribute ofListOfElementsfrom the fullListOfElements.
- Return type:
- Returns:
Contains all the elements that will be recomputed during the optimisation, as well as the proper particle and beam properties at its entry.
- _shift_entry_phase(cavities, delta_phi)[source]
Shift the entry phase in the given cavities.
This is mandatory for TraceWin solver, as the absolute phase at the entrance of the first element is always 0.0.
- _subset_files_dictionary(elts, files_from_full_list_of_elements, folder=PosixPath('tmp'), dat_name=PosixPath('tmp.dat'))[source]
Set the new
DATfile containing only elements ofelts.
- _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.
- _get_initial_element(elts, simulation_output)[source]
Set the element from which we should take energy, phase, etc.
- _subset_input_particle(simulation_output, **kwargs)[source]
Create input particle for subset of list of elements.
- Parameters:
simulation_output (
SimulationOutput)kwargs (
Any)
- Return type:
- 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:
elts (
ListOfElements)instructions_to_insert (
Collection[Instruction], default:())append_stem (
str, default:'')which_phase (
str, default:'phi_0_rel')
- Return type: