simulation_output_factory module
Define a class to easily generate the SimulationOutput.
- class SimulationOutputFactoryTraceWin(_is_3d: bool, _is_multipart: bool, _solver_id: str, _beam_kwargs: dict[str, Any], out_folder: Path, _filename: Path, beam_calc_parameters_factory: ElementTraceWinParametersFactory)
Bases:
SimulationOutputFactoryA class for creating simulation outputs for
TraceWin.- beam_calc_parameters_factory: ElementTraceWinParametersFactory
- __post_init__() None
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().
- 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 (pathlib.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
BeamCalculatorobjects.- Return type:
- _create_main_results_dictionary(path_cal: Path, input_particle: ParticleInitialState) dict[str, ndarray]
Load the TraceWin results, compute common interest quantities.
- _save_tracewin_meshing_in_elements(elts: ListOfElements, elt_numbers: ndarray, z_abs: ndarray) None
Take output files to determine where are evaluated
w_kin…
- _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
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: bool, _is_multipart: bool, _solver_id: str, _beam_kwargs: dict[str, Any], out_folder: Path, _filename: Path, beam_calc_parameters_factory: ElementTraceWinParametersFactory) None
- _abc_impl = <_abc._abc_data object at 0x7f36f84b16c0>
- _remove_invalid_values(results: dict[str, ndarray]) dict[str, ndarray]
Remove invalid values that appear when
exceptionis True.
- _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
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: Path) None
Remove incomplete line from
.outfile.Todo
fix possible unbound error for
n_columns.
- _add_dummy_data(filepath: Path, elts: ListOfElements) None
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
- _load_cavity_parameters(path_cal: Path, filename: Path) dict[str, ndarray]
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: