tracewin module
Define a BeamCalculator that will call TraceWin from cmd line.
It inherits from BeamCalculator base class. It solves the motion of
the particles in envelope or multipart, in 3D. In contrary to
Envelope1D solver, it is not a real solver but an interface with
TraceWin which must be installed on your machine.
Warning
For now, TraceWin behavior with relative phases is undetermined.
You should ensure that you are working with absolute phases, i.e. that
last argument of FIELD_MAP commands is 1.
You can run a simulation with Envelope1D solver and
flag_phi_abs=True. The .dat file created in the 000001_ref
folder should be the original .dat but converted to absolute phases.
Todo
This absolute phase thing should be fixed now. Check this.
- class TraceWin(executable, ini_path, base_kwargs, out_folder, default_field_map_folder, beam_kwargs, flag_phi_abs=False, cal_file=None, **kwargs)[source]
Bases:
BeamCalculatorHold a TraceWin beam calculator.
- Parameters:
executable (
Path) – Path to the TraceWin executable.ini_path (
Path) – Path to the.iniTraceWin file.base_kwargs (
dict[str,str|int|float|bool|None]) – TraceWin optional arguments. Override what is defined in.ini, but overriden by arguments fromListOfElementsandSimulationOutput._tracewin_command – Attribute to hold the value of the base command to call TraceWin.
out_folder (
Path|str) – Name of the results folder (not a complete path, just a folder name).path_cal – Name of the results folder. Updated at every call of the
init_solver_parameters()method, usingAccelerator.accelerator_pathandself.out_folderattributes.dat_file – Base name for the
.datfile. ??beam_kwargs (
BeamKwargs)flag_phi_abs (
bool, default:False)kwargs (
Any)
- __init__(executable, ini_path, base_kwargs, out_folder, default_field_map_folder, beam_kwargs, flag_phi_abs=False, cal_file=None, **kwargs)[source]
Define some other useful methods, init variables.
- _set_up_specific_factories()[source]
Set up the factories specific to the
BeamCalculator.This method is called in the
BeamCalculator.__init__(), hence it appears only in the baseBeamCalculator.- Return type:
- _tracewin_base_command(accelerator_path, **kwargs)[source]
Define the ‘base’ command for TraceWin.
This part of the command is the same for every
ListOfElementsand everyFault. It sets the TraceWin executable, the.inifile. It also definesbase_kwargs, which should be the same for every calculation. Finally, it setspath_cal. But this path is moreListOfElementsdependent…Accelerator.accelerator_path+out_folder(+fault_optimisation_tmp_folder)
- _tracewin_full_command(elts, set_of_cavity_settings, **kwargs)[source]
Set the full TraceWin command.
It contains the ‘base’ command, which includes every argument that is common to every calculation with this
BeamCalculator: path to.inifile, to executable…It contains the
ListOfElementscommand: path to the.datfile, initial energy and beam properties.It can contain some
SetOfCavitySettingscommands:elearguments to modify some cavities tuning.- Parameters:
elts (
ListOfElements)set_of_cavity_settings (
SetOfCavitySettings|None)
- Return type:
- run(elts, update_reference_phase=False, **specific_kwargs)[source]
Run TraceWin.
- Parameters:
elts (
ListOfElements) – List of elements in which the beam must be propagated.update_reference_phase (
bool, default:False) – To change the reference phase of cavities when it is different from the one asked in the.toml. To use after the first calculation, ifBeamCalculator.flag_phi_absdoes not correspond toCavitySettings.reference. The default is False.specific_kwargs –
TraceWinoptional arguments. Overrides what is defined inbase_kwargsand.ini.
- Returns:
simulation_output – Holds energy, phase, transfer matrices (among others) packed into a single object.
- Return type:
- run_with_this(set_of_cavity_settings, elts, use_a_copy_for_nominal_settings=True, **specific_kwargs)[source]
Perform a simulation with new cavity settings.
Calling it with
set_of_cavity_settings = Noneis the same as calling the plainrun()method.- Parameters:
set_of_cavity_settings (
SetOfCavitySettings|None) – The new cavity settings to try. If it is None, then the cavity settings are taken from the FieldMap objects.elts (
ListOfElements) – List of elements in which the beam should be propagated.use_a_copy_for_nominal_settings (
bool, default:True) – To copy the nominalCavitySettingsand avoid altering their nominal counterpart. Set it to True during optimisation, to False when you want to keep the current settings. The default is True.
- Returns:
simulation_output – Holds energy, phase, transfer matrices (among others) packed into a single object.
- Return type:
- post_optimisation_run_with_this(optimized_cavity_settings, full_elts, **specific_kwargs)[source]
Run TraceWin with optimized cavity settings.
After the optimisation, we want to re-run TraceWin with the new settings. However, we need to tell it that the linac is bigger than during the optimisation. Concretely, it means:
Rephasing the cavities in the compensation zone.
Updating the
indexnof the cavities in theele[n][v]command.
Note that at this point, the
.dathas not been updated yet.- Parameters:
optimized_cavity_settings (
SetOfCavitySettings) – Optimized parameters.full_elts (
ListOfElements) – Contains the full linac.
- Returns:
simulation_output – Necessary information on the run.
- Return type:
- init_solver_parameters(accelerator)[source]
Set the
path_calvariable.We also set the
_tracewin_commandattribute to None, as it must be updated whenpath_calchanges.Note
In contrary to
Envelope1DandEnvelope3D, this routine does not set parameters for theBeamCalculator. As a matter of a fact, TraceWin is a standalone code and does not need out solver parameters. However, if we want to save the meshing used by TraceWin, we will have to use theElementTraceWinParametersFactorylater.- Parameters:
accelerator (
Accelerator)- Return type:
- property is_a_multiparticle_simulation: bool
Tell if you should buy Bitcoins now or wait a few months.
- _save_cavities_entry_phases(set_of_cavity_settings, cavities, simulation_output)[source]
Store the synchronous particle entry phase.
This quantity is required to switch between the different definitions of the phase. Note that, with
Envelope1DandEnvelope3D, it is done during the propagation of the beam, in thefor elt in eltsloop.Todo
Maybe I should also store the synchronous phase?
- Parameters:
set_of_cavity_settings (
SetOfCavitySettings|None)simulation_output (
SimulationOutput)
- Return type:
- _abc_impl = <_abc._abc_data object at 0x73df423d8800>