core.beam_parameters.factory module
Define a factory for the BeamParameters
.
- class BeamParametersFactory(is_3d: bool, is_multipart: bool)
Bases:
ABC
Declare factory method, that returns the
BeamParameters
.Subclassed by every
BeamCalculator
.- __init__(is_3d: bool, is_multipart: bool) None
Initialize the class.
- _abc_impl = <_abc._abc_data object>
- _check_and_set_arrays(z_abs: ndarray | float, gamma_kin: ndarray | float) tuple[ndarray, ndarray, ndarray]
Ensure that inputs are arrays with proper shape, compute beta.
- _check_sigma_in(sigma_in: ndarray) ndarray
Change shape of
sigma_in
if necessary.
- _determine_phase_spaces(is_3d: bool, is_multipart: bool) tuple[str, ...]
- _set_from_other_phase_space(beam_parameters: BeamParameters, other_phase_space_name: str, phase_space_names: Sequence[str], gamma_kin: ndarray, beta_kin: ndarray) None
Instantiate a phase space from another one.
- Parameters:
beam_parameters (BeamParameters) – Object holding the beam parameters in different phase spaces.
other_phase_space_name ({'zdelta'}) – Name of the phase space from which the new phase space will be initialized.
phase_space_names (Sequence[{'phiw', 'z'}]) – Name of the phase spaces that will be created.
gamma_kin (np.ndarray) – Lorentz gamma factor.
beta_kin (np.ndarray) – Lorentz beta factor.
- _set_from_sigma(beam_parameters: BeamParameters, phase_space_names: Sequence[str], sigmas: Iterable[ndarray], gamma_kin: ndarray, beta_kin: ndarray) None
Initialize transfer matrices from \(\sigma\) beam matrix.
- _set_from_transfer_matrix(beam_parameters: BeamParameters, phase_space_names: Sequence[str], transfer_matrices: Sequence[ndarray], gamma_kin: ndarray, beta_kin: ndarray) None
Initialize phase spaces from their transfer matrices.
- Parameters:
beam_parameters (BeamParameters) – Object holding the different phase spaces.
phase_space_names (Sequence[str]) – Names of the phase spaces to initialize.
transfer_matrices (Sequence[np.ndarray]) – Transfer matrix corresponding to each phase space.
gamma_kin (np.ndarray) – Lorentz gamma factor.
beta_kin (np.ndarray) – Lorentz beta factor.
- _set_only_emittance(beam_parameters: BeamParameters, phase_space_names: Sequence[str], emittances: Iterable[ndarray]) None
Set only the emittance.
- _set_transverse_from_x_and_y(beam_parameters: BeamParameters, other_phase_space_names: tuple[str, str], phase_space_name: str) None
Initialize
t
(transverse) phase space.- Parameters:
beam_parameters (BeamParameters) – Object already holding the beam parameters in the
x
andy
phase spaces.
- abstract factory_method(*args, **kwargs) BeamParameters
Create the
BeamParameters
object.
- class InitialBeamParametersFactory(is_3d: bool, is_multipart: bool)
Bases:
ABC
This is used when creating new
ListOfElements
.This factory is not subclassed. Only one instance should be created.
Todo
Remove the
is_3d
,is_multipart
as I always create the same object withTrue
,True
. Alsoself._determine_phase_spaces()
is useless.- __init__(is_3d: bool, is_multipart: bool) None
Create factory and list of phase spaces to generate.
- Parameters:
is_3d (bool) – If the simulation is in 3D.
is_multipart (bool) – If the simulation is a multiparticle.
- _abc_impl = <_abc._abc_data object>
- _initial_beam_parameters_kw(simulation_output: SimulationOutput, get_kw: dict[str, Element | str | bool | None]) dict[str, float]
Generate the kw to instantiate the
InitialBeamParameters
.- Parameters:
simulation_output (SimulationOutput) – Object from which the initial beam will be taken.
get_kw (dict[str, Element | str | bool | None]) – Keyword argument to
get
args
at proper position.
- Returns:
Dictionary of keyword arguments for
InitialBeamParameters
.- Return type:
dict[str, float]
- _initial_phase_space_beam_parameters_kw(original_beam_parameters: BeamParameters, phase_space_names: Sequence[str], get_kw: dict[str, Element | str | bool | None], skip_missing_phase_spaces: bool) dict[str, dict[str, float | ndarray]]
Get all beam data at proper position and store it in a dict.
- Parameters:
original_beam_parameters (BeamParameters) – Object holding original beam parameters.
get_kw (dict[str, Element | str | bool | None]) – dict that can be passed to the
get
method and that will return the data at the beginning of the linac portion.skip_missing_phase_spaces (bool) – To handle when a phase space from :var:`self.phase_spaces` is not defined in
original_beam_parameters
, and is therefore not initializable. If True, we just skip it. If False and such a case happens, anAttributeError
will be raised.
- Returns:
initial_phase_spaces_kw – Keys are the name of the phase spaces. The values are other dictionaries, which keys-values are
PhaseSpaceInitialBeamParameters
attributes.- Return type:
dict[str, dict[str, float | np.ndarray]]
- _set_from_other_phase_space(initial_beam_parameters: InitialBeamParameters, other_phase_space_name: str, phase_space_names: Sequence[str]) None
Instantiate a phase space from another one.
- Parameters:
initial_beam_parameters (InitialBeamParameters) – Object holding the beam parameters in different phase spaces.
other_phase_space_name ({'zdelta'}) – Name of the phase space from which the new phase space will be initialized.
phase_space_names (Sequence[{'phiw', 'z'}]) – Name of the phase spaces that will be created.
gamma_kin (float) – Lorentz gamma factor.
beta_kin (float) – Lorentz beta factor.
- _set_from_sigma(initial_beam_parameters: InitialBeamParameters, phase_space_names: Sequence[str], sigmas: Iterable[ndarray]) None
Initialize transfer matrices from \(\sigma\) beam matrix.
- factory_new(sigma_in: ndarray, w_kin: float, z_abs: float = 0.0) InitialBeamParameters
Create the beam parameters for the beginning of the linac.
- Parameters:
sigma_in (np.ndarray) – \(\sigma\) beam matrix.
w_kin (float) – Kinetic energy in MeV.
z_abs (float, optional) – Absolute position of the linac start. Should be 0, which is the default.
- Returns:
Beam parameters at the start of the linac.
- Return type:
- factory_subset(simulation_output: SimulationOutput, get_kw: dict[str, Element | str | bool | None]) InitialBeamParameters
Generate
InitialBeamParameters
for a linac portion.- Parameters:
simulation_output (SimulationOutput) – Object from which the beam parameters data will be taken.
get_kw (dict[str, Element | str | bool | None]) – dict that can be passed to the
get
method and that will return the data at the beginning of the linac portion.
- Returns:
Holds information on the beam at the beginning of the linac portion.
- Return type: