:mod:`ocelot.cpbd.optics` ========================= .. py:module:: ocelot.cpbd.optics Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: ocelot.cpbd.optics.SecondOrderMult ocelot.cpbd.optics.TransferMap ocelot.cpbd.optics.SecondTM ocelot.cpbd.optics.CorrectorTM ocelot.cpbd.optics.PulseTM ocelot.cpbd.optics.MultipoleTM ocelot.cpbd.optics.CavityTM ocelot.cpbd.optics.CouplerKickTM ocelot.cpbd.optics.KickTM ocelot.cpbd.optics.UndulatorTestTM ocelot.cpbd.optics.RungeKuttaTM ocelot.cpbd.optics.RungeKuttaTrTM ocelot.cpbd.optics.TWCavityTM ocelot.cpbd.optics.MethodTM ocelot.cpbd.optics.ProcessTable ocelot.cpbd.optics.Navigator Functions ~~~~~~~~~ .. autoapisummary:: ocelot.cpbd.optics.transform_vec_ent ocelot.cpbd.optics.transform_vec_ext ocelot.cpbd.optics.transfer_maps_mult_py ocelot.cpbd.optics.transfer_map_rotation ocelot.cpbd.optics.sym_matrix ocelot.cpbd.optics.unsym_matrix ocelot.cpbd.optics.lattice_transfer_map ocelot.cpbd.optics.trace_z ocelot.cpbd.optics.trace_obj ocelot.cpbd.optics.periodic_twiss ocelot.cpbd.optics.twiss ocelot.cpbd.optics.twiss_fast ocelot.cpbd.optics.get_map ocelot.cpbd.optics.merge_maps ocelot.cpbd.optics.fodo_parameters .. data:: __author__ :annotation: = Sergey .. data:: _logger .. data:: _logger_navi .. data:: nb_flag :annotation: = True .. py:class:: SecondOrderMult The class includes three different methods for transforming the particle coordinates: 1. NUMBA module - DEACTIVATED, because new numpy implementation shows higher performance. Slightly faster than NUMPY for simulations with a large number of time steps. Uses full matrix multiplication. 2. NUMPY module Base method to be used. Uses full matrix multiplication. .. method:: numba_apply(self, X, R, T) .. method:: numpy_apply(self, X, R, T) .. function:: transform_vec_ent(X, dx, dy, tilt) .. function:: transform_vec_ext(X, dx, dy, tilt) .. function:: transfer_maps_mult_py(Ra, Ta, Rb, Tb) cell = [A, B] Rc = Rb * Ra :param Ra: :param Ta: :param Rb: :param Tb: :param sym_flag: :return: .. data:: transfer_maps_mult .. function:: transfer_map_rotation(R, T, tilt) .. py:class:: TransferMap TransferMap is a basic linear transfer map for all elements. .. method:: map_x_twiss(self, tws0) .. method:: mul_p_array(self, rparticles, energy=0.0) .. method:: __mul__(self, m) :param m: TransferMap, Particle or Twiss :return: TransferMap, Particle or Twiss Ma = {Ba, Ra, Ta} Mb = {Bb, Rb, Tb} X1 = R*(X0 - dX) + dX = R*X0 + B B = (E - R)*dX .. method:: apply(self, prcl_series) :param prcl_series: can be list of Particles [Particle_1, Particle_2, ... ] or ParticleArray :return: None .. method:: __call__(self, s) .. py:class:: SecondTM(r_z_no_tilt, t_mat_z_e) Bases: :class:`ocelot.cpbd.optics.TransferMap` TransferMap is a basic linear transfer map for all elements. .. method:: t_apply(self, R, T, X, dx, dy, tilt, U5666=0.0) .. method:: __call__(self, s) .. py:class:: CorrectorTM(angle_x=0.0, angle_y=0.0, r_z_no_tilt=None, t_mat_z_e=None) Bases: :class:`ocelot.cpbd.optics.SecondTM` TransferMap is a basic linear transfer map for all elements. .. method:: kick_b(self, z, l, angle_x, angle_y) .. method:: kick(self, X, z, l, angle_x, angle_y, energy) .. method:: __call__(self, s) .. py:class:: PulseTM(kn) Bases: :class:`ocelot.cpbd.optics.TransferMap` TransferMap is a basic linear transfer map for all elements. .. method:: mul_parray(self, rparticles, energy=0.0) .. py:class:: MultipoleTM(kn) Bases: :class:`ocelot.cpbd.optics.TransferMap` TransferMap is a basic linear transfer map for all elements. .. method:: kick(self, X, kn) .. method:: __call__(self, s) .. py:class:: CavityTM(v=0, freq=0.0, phi=0.0) Bases: :class:`ocelot.cpbd.optics.TransferMap` TransferMap is a basic linear transfer map for all elements. .. method:: map4cav(self, X, E, V, freq, phi, z=0) .. method:: __call__(self, s) .. py:class:: CouplerKickTM(v=0, freq=0.0, phi=0.0, vx=0.0, vy=0.0) Bases: :class:`ocelot.cpbd.optics.TransferMap` TransferMap is a basic linear transfer map for all elements. .. method:: kick_b(self, v, phi, energy) .. method:: kick(self, X, v, phi, energy) .. method:: __call__(self, s) .. py:class:: KickTM(angle=0.0, k1=0.0, k2=0.0, k3=0.0, nkick=1) Bases: :class:`ocelot.cpbd.optics.TransferMap` TransferMap is a basic linear transfer map for all elements. .. method:: kick(self, X, l, angle, k1, k2, k3, energy, nkick=1) does not work for dipole .. method:: kick_apply(self, X, l, angle, k1, k2, k3, energy, nkick, dx, dy, tilt) .. method:: __call__(self, s) .. py:class:: UndulatorTestTM(lperiod, Kx, ax=0, ndiv=10) Bases: :class:`ocelot.cpbd.optics.TransferMap` TransferMap is a basic linear transfer map for all elements. .. method:: map4undulator(self, u, z, lperiod, Kx, ax, energy, ndiv) .. method:: __call__(self, s) .. py:class:: RungeKuttaTM(s_start=0, npoints=200) Bases: :class:`ocelot.cpbd.optics.TransferMap` TransferMap is a basic linear transfer map for all elements. .. method:: __call__(self, s) .. py:class:: RungeKuttaTrTM(s_start=0, npoints=200) Bases: :class:`ocelot.cpbd.optics.RungeKuttaTM` THe same method as RungeKuttaTM but only transverse dynamics is included, longitudinal dynamics is skipped .. py:class:: TWCavityTM(l=0, v=0, phi=0, freq=0) Bases: :class:`ocelot.cpbd.optics.TransferMap` TransferMap is a basic linear transfer map for all elements. .. method:: tw_cavity_R_z(self, z, V, E, freq, phi=0.0) :param z: length :param de: delta E :param f: frequency :param E: initial energy :return: matrix .. method:: f_entrance(self, z, V, E, phi=0.0) .. method:: f_exit(self, z, V, E, phi=0.0) .. method:: __call__(self, s) .. py:class:: MethodTM(params=None) The class creates a transfer map for elements that depend on user-defined parameters ("parameters"). By default, the parameters = {"global": TransferMap}, which means that all elements will have linear transfer maps. You can also specify different transfer maps for any type of element. Example: -------- # use linear matrices for all elements except Sextupole which will have nonlinear kick map (KickTM) method = MethodTM() method.global_method = TransferMap method.params[Sextupole] = KickTM # All elements are assigned matrices of the second order. # For elements for which there are no matrices of the second order are assigned default matrices, e.g. linear matrices. method2 = MethodTM() method2.global_method = SecondTM .. method:: create_tm(self, element) .. method:: set_tm(self, element, method) .. function:: sym_matrix(T) .. function:: unsym_matrix(T) .. function:: lattice_transfer_map(lattice, energy) Function calculates transfer maps, the first and second orders (R, T), for the whole lattice. Second order matrices are attached to lattice object: lattice.T_sym - symmetric second order matrix lattice.T - second order matrix lattice.R - linear R matrix :param lattice: MagneticLattice :param energy: the initial electron beam energy [GeV] :return: R - matrix .. function:: trace_z(lattice, obj0, z_array) Z-dependent tracer (twiss(z) and particle(z)) usage: twiss = trace_z(lattice,twiss_0, [1.23, 2.56, ...]) , to calculate Twiss params at 1.23m, 2.56m etc. .. function:: trace_obj(lattice, obj, nPoints=None) track object through the lattice obj must be Twiss or Particle .. function:: periodic_twiss(tws, R) initial conditions for a periodic Twiss solution .. function:: twiss(lattice, tws0=None, nPoints=None) twiss parameters calculation :param lattice: lattice, MagneticLattice() object :param tws0: initial twiss parameters, Twiss() object. If None, try to find periodic solution. :param nPoints: number of points per cell. If None, then twiss parameters are calculated at the end of each element. :return: list of Twiss() objects .. function:: twiss_fast(lattice, tws0=None) twiss parameters calculation :param lattice: lattice, MagneticLattice() object :param tws0: initial twiss parameters, Twiss() object. If None, try to find periodic solution. :param nPoints: number of points per cell. If None, then twiss parameters are calculated at the end of each element. :return: list of Twiss() objects .. py:class:: ProcessTable(lattice) .. method:: searching_kick_proc(self, physics_proc, elem1) function finds kick physics process. Kick physics process applies kick only once between two elements with zero length (e.g. Marker) or at the beginning of the element if it is the same element, others physics processes are applied during finite lengths. :return: .. method:: add_physics_proc(self, physics_proc, elem1, elem2) .. py:class:: Navigator(lattice) Navigator defines step (dz) of tracking and which physical process will be applied during each step. lattice - MagneticLattice Attributes: unit_step = 1 [m] - unit step for all physics processes Methods: add_physics_proc(physics_proc, elem1, elem2) physics_proc - physics process, can be CSR, SpaceCharge or Wake, elem1 and elem2 - first and last elements between which the physics process will be applied. .. method:: reset_position(self) method to reset Navigator position. :return: .. method:: go_to_start(self) .. method:: get_phys_procs(self) method return list of all physics processes which were added :return: list, list of PhysProc(s) .. method:: add_physics_proc(self, physics_proc, elem1, elem2) Method adds Physics Process. :param physics_proc: PhysicsProc, e.g. SpaceCharge, CSR, Wake ... :param elem1: the element in the lattice where to start applying the physical process. :param elem2: the element in the lattice where to stop applying the physical process, can be the same as starting element. :return: .. method:: activate_apertures(self, start=None, stop=None) activate apertures if thea exist in the lattice from :param start: element, activate apertures starting form element 'start' element :param stop: element, activate apertures up to 'stop' element :return: .. method:: check_overjump(self, dz, processes, phys_steps) .. method:: get_proc_list(self) .. method:: hard_edge_step(self, dz) .. method:: check_proc_bounds(self, dz, proc_list, phys_steps, active_process) .. method:: remove_used_processes(self, processes) in case physics processes are applied and do not more needed they are removed from table :param processes: list of processes are about to apply :return: None .. method:: get_next(self) .. function:: get_map(lattice, dz, navi) .. function:: merge_maps(t_maps) .. function:: fodo_parameters(betaXmean=36.0, L=10.0, verbose=False)