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:
objectFactory 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_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:
is_3d (
bool) – Whether simulation is in 3D. This is currently not used, as we always generate 3DInitialBeamParameters.is_multipart (
bool) – Whether simulation is multiparticle. This is currently not used, as we always generate multiparticleInitialBeamParameters.default_field_map_folder (
Path) – Where to look for field map files.beam_kwargs (
BeamKwargs) – Arguments to instantiateInitialBeamParameters.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 ofElementthat 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
Acceleratorobject.- Parameters:
dat_file (
Path) – Absolute path to theDATfile.accelerator_path (
Path) – Absolute path where results for eachBeamCalculatorwill 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 theDATfile but that you want to add. The default is an empty tuple.kwargs – 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.
- 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.
- _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: