transfer_matrix module
Hold the transfer matrix along the linac.
Todo
Check if it can be more efficient. Maybe store R_xx, R_yy, R_zz separately?
Todo
Maybe transfer matrices should always be (6, 6)??
Todo
_init_from methods in factory???
Todo
The SimulationOutput.get method with transfer matrix components fails with
TraceWin solver.
- class TransferMatrix(is_3d, first_cumulated_transfer_matrix, element_to_index, individual=None, cumulated=None)[source]
Bases:
objectHold the (n, 6, 6) transfer matrix along the linac.
Note
When the simulation is in 1D only, the values corresponding to the transverse planes are filled with np.nan.
- Parameters:
individual (
ndarray[tuple[int,...],dtype[float64]] |None, default:None) – Individual transfer matrices along the linac. Not defined if not provided at initialisation.cumulated (
ndarray[tuple[int,...],dtype[float64]] |None, default:None) – Cumulated transfer matrices along the linac.is_3d (
bool)first_cumulated_transfer_matrix (
ndarray[tuple[int,...],dtype[float64]])element_to_index (
Callable[[str|Element,str|None],int|slice])
- __init__(is_3d, first_cumulated_transfer_matrix, element_to_index, individual=None, cumulated=None)[source]
Create the object and compute the cumulated transfer matrix.
- Parameters:
is_3d (
bool) – If the simulation is in 3d or not.first_cumulated_transfer_matrix (
ndarray[tuple[int,...],dtype[float64]]) – First transfer matrix.individual (
ndarray[tuple[int,...],dtype[float64]] |None, default:None) – Individual transfer matrices. The default is None, in which case thecumulatedtransfer matrix must be provided directly.cumulated (
ndarray[tuple[int,...],dtype[float64]] |None, default:None) – Cumulated transfer matrices. The default is None, in which case theindividualtransfer matrices must be given.element_to_index (
Callable[[str|Element,str|None],int|slice]) – to doc
- get(*keys, elt=None, pos=None, **kwargs)[source]
Get attributes from this class or its attributes.
- Parameters:
*keys (
Literal['cumulated','individual','n_points','r_xx','r_yy','r_zdelta','r_zz']) – Name of the desired attributes.to_numpy – If you want the list output to be converted to a
NDArray[np.float64].none_to_nan – To convert None to np.nan.
elt (
Element|None, default:None) – If provided, return the attributes only at the considered Element.pos (
Literal['in','out'] |None, default:None) – If you want the attribute at the entry, exit, or in the whole Element.**kwargs (
Any) – Other arguments passed to recursive getter.
- Returns:
out – Attribute(s) value(s). Will be floats if only one value is returned (
eltis given,posis in('in', 'out')).- Return type:
- _init_from_individual(individual, first_cumulated_transfer_matrix)[source]
Compute cumulated transfer matrix from individual.
- Parameters:
individual (
ndarray[tuple[int,...],dtype[float64]]) – Individual transfer matrices along the linac.first_cumulated_transfer_matrix (
ndarray[tuple[int,...],dtype[float64]] |None) – First transfer matrix. It should be None if we study a linac from the start (z_pos == 0.), and should be the cumulated transfer matrix of the previous linac portion otherwise.
- Return type:
- Returns:
n_points – Number of mesh points along the linac.
cumulated – Cumulated transfer matrices.
- _init_from_cumulated(cumulated, first_cumulated_transfer_matrix, tol=1e-08)[source]
Check that the given cumulated matrix is valid.
- Parameters:
cumulated (
ndarray[tuple[int,...],dtype[float64]] |None) – Cumulated transfer matrices along the linac.first_cumulated_transfer_matrix (
ndarray[tuple[int,...],dtype[float64]]) – The first of the cumulated transfer matrices.tol (
float, default:1e-08) – The max allowed difference betweencumulatedandfirst_cumulated_transfer_matrixwhen determining if they are the same or not.
- Return type:
- Returns:
n_points – Number of mesh points along the linac.
cumulated – Cumulated transfer matrices.
- _compute_cumulated(first_cumulated_transfer_matrix, shape, is_3d, n_points)[source]
Compute cumulated transfer matrix from individual.
- Parameters:
first_cumulated_transfer_matrix (
ndarray[tuple[int,...],dtype[float64]]) – First transfer matrix. It should be eye matrix if we study a linac from the start (z_pos == 0.), and should be the cumulated transfer matrix of the previous linac portion otherwise.shape (
tuple[int,int,int]) – Shape of the outputcumulatedarray.is_3d (
bool) – If the simulation is in 3D or not.n_points (
int) – Number of mesh points along the linac.
- Return type:
- Returns:
cumulated – Cumulated transfer matrix.
.. todo:: – I think the 3D/1D handling may be smarter?
- property r_xx: ndarray[tuple[int, ...], dtype[float64]]
Return the transfer matrix of \([x-x']\) plane.
- property r_yy: ndarray[tuple[int, ...], dtype[float64]]
Return the transfer matrix of \([y-y']\) plane.