simulation_output_factory module

Define a class to easily generate the SimulationOutput.

_0_to_NaN(data)[source]

Replace 0 by np.nan in given array.

Parameters:

data (ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]])

Return type:

ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]

_remove_invalid_values(results)[source]

Remove invalid values that appear when exception is True.

Parameters:

results (dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]])

Return type:

dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]

_load_results_generic(filename, path_cal)[source]

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.

Return type:

dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]

Returns:

Dictionary containing the raw outputs from TraceWin.

Compute the energy from gama-1 column.

Parameters:
Return type:

dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]

Returns:

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

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, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]) – 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.).

Return type:

dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]

Returns:

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

_remove_incomplete_line(filepath)[source]

Remove incomplete line from OUT file.

Todo

fix possible unbound error for n_columns.

Parameters:

filepath (Path)

Return type:

None

_add_dummy_data(filepath, elts)[source]

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

Parameters:
Return type:

None

_load_parameters_of_cavities(path_cal, filename)[source]

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, generally Cav_set_point_res.dat.

Return type:

dict[str, ndarray[tuple[Any, ...], dtype[double]]]

Returns:

Contains the cavity parameters. The keys should be:

  • "Cav#"

  • "SyncPhase_Ref[°]"

  • "SyncPhase[°]"

  • "Voltage_ref[MV]"

  • "Voltage[MV]"

  • "RF_phase[°]"

_uniformize_parameters_of_cavities(parameters, n_elts)[source]

Transform the dict so we have consistent format with other solvers.

Parameters:
Return type:

CavParams

class SimulationOutputFactoryTraceWin(is_multipart, beam_calculator_id, beam_kwargs, filename, beam_calc_parameters_factory)[source]

Bases: SimulationOutputFactory

A class for creating simulation outputs for TraceWin.

Parameters:
_is_3d: bool = True
__init__(is_multipart, beam_calculator_id, beam_kwargs, filename, beam_calc_parameters_factory)[source]

Create the object.

Parameters:
  • is_multipart (bool) – If SimulationOutput are obtained with a multiparticle solver.

  • beam_calculator_id (str) – ID of solver that created this object. Also used as the name of the subdirectory where results should be saved. Typically, "0_Envelope1D" or "1_TraceWin".

  • beam_kwargs (BeamKwargs) – Beam properties.

  • filename (Path)

  • beam_calc_parameters_factory (ElementTraceWinParametersFactory)

Return type:

None

property _transfer_matrix_factory_class: ABCMeta

Give the class of the transfer matrix factory.

property _beam_parameters_factory_class: ABCMeta

Give the class of the beam parameters factory.

create(accelerator_id, elts, path_cal, exception, set_of_cavity_settings)[source]

Create an object holding all relatable simulation results.

Parameters:
  • accelerator_id (str) – Associated Accelerator.id. Looks like: 0000001_Solution.

  • 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.

  • set_of_cavity_settings (SetOfCavitySettings)

Return type:

SimulationOutput

Returns:

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

_create_main_results_dictionary(path_cal, input_particle)[source]

Load the TraceWin results, compute common interest quantities.

Parameters:
Return type:

dict[str, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]

_save_tracewin_meshing_in_elements(elts, elt_numbers, z_abs)[source]

Take output files to determine where are evaluated w_kin

Parameters:
Return type:

None

_get_cav_params(path_cal, n_elts, filename=PosixPath('Cav_set_point_res.dat'))[source]

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, default: PosixPath('Cav_set_point_res.dat')) – The name of the cavity parameters file produced by TraceWin. The default is Path('Cav_set_point_res.dat').

Return type:

CavParams

Returns:

Contains the cavity parameters. Keys are "v_cav_mv", "phi_s", "phi_0".

_abc_impl = <_abc._abc_data object at 0x7318f9d28400>