beam_calculation.tracewin.simulation_output_factory module

Define a class to easily generate the SimulationOutput.

class SimulationOutputFactoryTraceWin(_is_3d: bool, _is_multipart: bool, _solver_id: str, out_folder: Path, _filename: Path, beam_calc_parameters_factory: ElementTraceWinParametersFactory)

Bases: SimulationOutputFactory

A class for creating simulation outputs for TraceWin.

__init__(_is_3d: bool, _is_multipart: bool, _solver_id: str, out_folder: Path, _filename: Path, beam_calc_parameters_factory: ElementTraceWinParametersFactory) None
__post_init__() None

Set filepath-related attributes and create 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().

_abc_impl = <_abc._abc_data object>
property _beam_parameters_factory_class: ABCMeta

Give the class of the beam parameters factory.

_create_cavity_parameters(path_cal: Path, n_elts: int, filename: Path = PosixPath('Cav_set_point_res.dat')) dict[str, list[float | None]]

Load and format a dict containing v_cav and phi_s.

It has the same format as Envelope1D solver format.

Parameters:
  • path_cal (Path) – Path to the folder where the cavity parameters file is stored.

  • n_elts (int) – Number of elements under study.

  • filename (Path, optional) – The name of the cavity parameters file produced by TraceWin. The default is Path(‘Cav_set_point_res.dat’).

Returns:

cavity_param – Contains the cavity parameters. Keys are 'v_cav_mv' and 'phi_s'.

Return type:

dict[str, list[float | None]]

_create_main_results_dictionary(path_cal: Path, input_particle: ParticleInitialState) dict[str, ndarray]

Load the TraceWin results, compute common interest quantities.

_filename: Path
_save_tracewin_meshing_in_elements(elts: ListOfElements, elt_numbers: ndarray, z_abs: ndarray) None

Take output files to determine where are evaluated w_kin

property _transfer_matrix_factory_class: ABCMeta

Give the class of the transfer matrix factory.

beam_calc_parameters_factory: ElementTraceWinParametersFactory
out_folder: Path
run(elts: ListOfElements, path_cal: Path, exception: bool, set_of_cavity_settings: SetOfCavitySettings) SimulationOutput

Create an object holding all relatable simulation results.

Parameters:
  • elts (ListOfElements) – Contains all elements or only a fraction or all the elements.

  • path_cal (Path) – Path to results folder.

  • exception (bool) – Indicates if the run was unsuccessful or not.

Returns:

simulation_output – Holds all relatable data in a consistent way between the different BeamCalculator objects.

Return type:

SimulationOutput

_0_to_NaN(data: ndarray) ndarray

Replace 0 by np.nan in given array.

_add_dummy_data(filepath: Path, elts: ListOfElements) None

Add dummy data at the end of the .out to reach end of linac.

We also round the column ‘z’, to avoid a too big mismatch between the z column and what we should have.

Todo

another possibly unbound error to handle

_cavity_parameters_uniform_with_envelope1d(cavity_parameters: dict[str, ndarray], n_elts: int) list[None | dict[str, float]]

Transform the dict so we have the same format as Envelope1D.

_load_cavity_parameters(path_cal: Path, filename: Path) dict[str, ndarray]

Get the cavity parameters calculated by TraceWin.

Parameters:
  • path_cal (Path) – Path to the folder where the cavity parameters file is stored.

  • filename (Path) – The name of the cavity parameters file produced by TraceWin.

Returns:

cavity_param – Contains the cavity parameters.

Return type:

dict[float, np.ndarray]

_load_results_generic(filename: Path, path_cal: Path) dict[str, ndarray]

Load the TraceWin results.

This function is not called directly. Instead, every instance of TraceWin object has a load_results() method which calls this function with a default filename argument. The value of filename depends on the TraceWin simulation that was run: multiparticle or envelope.

Parameters:
  • filename (Path) – Results file produced by TraceWin.

  • path_cal (Path) – Folder where the results file is located.

Returns:

results – Dictionary containing the raw outputs from TraceWin.

Return type:

dict[str, np.ndarray]

_remove_incomplete_line(filepath: Path) None

Remove incomplete line from .out file.

Todo

fix possible unbound error for n_columns.

_remove_invalid_values(results: dict[str, ndarray]) dict[str, ndarray]

Remove invalid values that appear when exception is True.

Compute the energy from gama-1 column.

Parameters:

results (dict[str, np.ndarray]) – Dictionary holding the TraceWin results.

Returns:

results – Same as input, but with gamma, w_kin, beta keys defined.

Return type:

dict[str, np.ndarray]

Compute the phases, pos, frequencies.

Also shift position and phase if ListOfElements under study does not start at the beginning of the linac.

TraceWin always starts with z=0 and phi_abs=0, even when we are not at the beginning of the linac (sub .dat).

Parameters:
  • results (dict[str, np.ndarray]) – Dictionary holding the TraceWin results.

  • z_in (float) – Absolute position in the linac of the beginning of the linac portion under study (can be 0.).

  • phi_in (float) – Absolute phase of the synch particle at the beginning of the linac portion under study (can be 0.).

Returns:

results – Same as input, but with lambda and phi_abs keys defined. phi_abs and z(m) keys are modified in order to be 0. at the beginning of the linac, not at the beginning of the ListOfElements under study.

Return type:

dict[str, np.ndarray]