simulation_output_factory module
Define a class to easily generate the SimulationOutput.
- class SimulationOutputFactoryTraceWin(_is_3d, _is_multipart, _solver_id, _beam_kwargs, out_folder, _filename, beam_calc_parameters_factory)[source]
Bases:
SimulationOutputFactoryA class for creating simulation outputs for
TraceWin.- Parameters:
-
beam_calc_parameters_factory:
ElementTraceWinParametersFactory
- __post_init__()[source]
Set filepath-related attributes and create factories.
The created factories are
TransferMatrixFactoryandBeamParametersFactory. The sub-class that is used is declared in_transfer_matrix_factory_class()and_beam_parameters_factory_class().- Return type:
- run(elts, path_cal, exception, set_of_cavity_settings)[source]
Create an object holding all relatable simulation results.
- Parameters:
elts (ListOfElements) – Contains all elements or only a fraction or all the elements.
path_cal (pathlib.Path) – Path to results folder.
exception (bool) – Indicates if the run was unsuccessful or not.
set_of_cavity_settings (
SetOfCavitySettings)
- Returns:
simulation_output – Holds all relatable data in a consistent way between the different
BeamCalculatorobjects.- Return type:
- _create_main_results_dictionary(path_cal, input_particle)[source]
Load the TraceWin results, compute common interest quantities.
- Parameters:
path_cal (
Path)input_particle (
ParticleInitialState)
- Return type:
- _save_tracewin_meshing_in_elements(elts, elt_numbers, z_abs)[source]
Take output files to determine where are evaluated
w_kin…- Parameters:
elts (
ListOfElements)elt_numbers (
ndarray)z_abs (
ndarray)
- Return type:
- _create_cavity_parameters(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
Envelope1Dsolver format.- Parameters:
path_cal (pathlib.Path) – Path to the folder where the cavity parameters file is stored.
n_elts (int) – Number of elements under study.
filename (pathlib.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:
- __init__(_is_3d, _is_multipart, _solver_id, _beam_kwargs, out_folder, _filename, beam_calc_parameters_factory)
- _abc_impl = <_abc._abc_data object at 0x73dca7df0a40>
- _load_results_generic(filename, path_cal)[source]
Load the TraceWin results.
This function is not called directly. Instead, every instance of
TraceWinobject has aload_resultsmethod which calls this function with a defaultfilenameargument. The value offilenamedepends on the TraceWin simulation that was run: multiparticle or envelope.- Parameters:
filename (pathlib.Path) – Results file produced by TraceWin.
path_cal (pathlib.Path) – Folder where the results file is located.
- Returns:
results – Dictionary containing the raw outputs from TraceWin.
- Return type:
Compute the energy from
gama-1column.- Parameters:
results (dict[str, numpy.ndarray]) – Dictionary holding the TraceWin results.
beam_kwargs (dict[str, Any]) – Holds beam constants such as
q_over_more_rest.
- Returns:
results – Same as input, but with
gamma,w_kin,betakeys defined.- Return type:
Compute the phases, pos, frequencies.
Also shift position and phase if
ListOfElementsunder study does not start at the beginning of the linac.TraceWin always starts with
z=0andphi_abs=0, even when we are not at the beginning of the linac (sub.dat).- Parameters:
results (dict[str, numpy.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
lambdaandphi_abskeys defined.phi_absandz(m)keys are modified in order to be 0. at the beginning of the linac, not at the beginning of theListOfElementsunder study.- Return type:
- _remove_incomplete_line(filepath)[source]
Remove incomplete line from
.outfile.Todo
fix possible unbound error for
n_columns.
- _add_dummy_data(filepath, elts)[source]
Add dummy data at the end of the
.outto 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:
filepath (
Path)elts (
ListOfElements)
- Return type:
- _load_cavity_parameters(path_cal, filename)[source]
Get the cavity parameters calculated by TraceWin.
- Parameters:
path_cal (pathlib.Path) – Path to the folder where the cavity parameters file is stored.
filename (pathlib.Path) – The name of the cavity parameters file produced by TraceWin.
- Returns:
cavity_param – Contains the cavity parameters.
- Return type: