def find_elem_m66(elem, orbit=None, **kwargs): """ Numerically find the 6x6 transfer matrix of a single element INPUT elem AT element KEYWORDS orbit=None closed orbit at the entrance of the element, default: 0.0 XYStep=6.055e-6 transverse step for numerical computation DPStep=6.055e-6 longitudinal step for numerical computation OUTPUT m66 (6, 6) transfer matrix """ xy_step = kwargs.pop('XYStep', XYDEFSTEP) dp_step = kwargs.pop('DPStep', DPSTEP) if orbit is None: orbit = numpy.zeros((6, )) # Construct matrix of plus and minus deltas scaling = numpy.array( [xy_step, xy_step, xy_step, xy_step, dp_step, dp_step]) dg = numpy.asfortranarray(0.5 * numpy.diag(scaling)) dmat = numpy.concatenate((dg, -dg), axis=1) in_mat = orbit.reshape(6, 1) + dmat element_pass(elem, in_mat) m66 = (in_mat[:, :6] - in_mat[:, 6:]) / scaling.reshape((1, 6)) return m66
def find_elem_m66(elem, orbit=None, **kwargs): """ Numerically find the 6x6 transfer matrix of a single element INPUT elem AT element KEYWORDS orbit=None closed orbit at the entrance of the element, default: 0.0 XYStep=1.e-8 transverse step for numerical computation OUTPUT m66 (6, 6) transfer matrix """ xy_step = kwargs.pop('XYStep', DConstant.XYStep) if orbit is None: orbit = numpy.zeros((6,)) # Construct matrix of plus and minus deltas # scaling = 2*xy_step*numpy.array([1.0, 0.1, 1.0, 0.1, 1.0, 1.0]) scaling = xy_step * numpy.array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0]) dg = numpy.asfortranarray(0.5 * numpy.diag(scaling)) dmat = numpy.concatenate((dg, -dg), axis=1) in_mat = orbit.reshape(6, 1) + dmat element_pass(elem, in_mat) m66 = (in_mat[:, :6] - in_mat[:, 6:]) / scaling return m66
def test_exact_hamiltonian_pass_with_dls_dipole(rin): bend = elements.Multipole('rb', 0.15, [0, 0, 0, 0], [-0.0116333, 3.786786, 0, 0]) bend.Type = 1 bend.PassMethod = 'ExactHamiltonianPass' bend.BendingAngle = -0.001745 bend.Energy = 3.5e9 bend.MaxOrder = 3 element_pass(bend, rin) # Results from Matlab expected = numpy.array([9.23965e-9, 1.22319e-5, 0, 0, 0, -4.8100e-10]).reshape(6, 1) numpy.testing.assert_allclose(rin, expected, rtol=1e-5, atol=1e-6)
def test_pydrift(): pydrift = elements.Drift('drift', 1.0, PassMethod='pyDriftPass') cdrift = elements.Drift('drift', 1.0, PassMethod='DriftPass') pyout = element_pass(pydrift, numpy.zeros(6) + 1.0e-6) cout = element_pass(cdrift, numpy.zeros(6) + 1.0e-6) numpy.testing.assert_equal(pyout, cout) shift_elem(pydrift, 1.0e-3, 1.0e-3) shift_elem(cdrift, 1.0e-3, 1.0e-3) pyout = element_pass(pydrift, numpy.zeros(6) + 1.0e-6) cout = element_pass(cdrift, numpy.zeros(6) + 1.0e-6) numpy.testing.assert_equal(pyout, cout) tilt_elem(pydrift, 1.0e-3, 1.0e-3) tilt_elem(cdrift, 1.0e-3, 1.0e-3) pyout = element_pass(pydrift, numpy.zeros(6) + 1.0e-6) cout = element_pass(cdrift, numpy.zeros(6) + 1.0e-6) numpy.testing.assert_equal(pyout, cout) # Multiple particles pyout = element_pass(pydrift, numpy.zeros((6, 2)) + 1.0e-6) cout = element_pass(cdrift, numpy.zeros((6, 2)) + 1.0e-6) numpy.testing.assert_equal(pyout, cout)
def test_bndstrmpole_symplectic_4_pass(rin): bend = elements.Dipole('b', 1.0) bend.PassMethod = 'BndStrMPoleSymplectic4Pass' element_pass(bend, rin)
def test_gwig_symplectic_pass(rin, passmethod): # Parameters copied from one of the Diamond wigglers. wiggler = elements.Wiggler('w', 1.15, 0.05, 0.8, 3e9) wiggler.PassMethod = passmethod element_pass(wiggler, rin)
def test_exact_hamiltonian_pass(rin): drift = elements.Multipole('m1', 1, [0, 0, 0, 0], [0, 0, 0, 0]) drift.Type = 0 drift.PassMethod = 'ExactHamiltonianPass' drift.BendingAngle = 0 element_pass(drift, rin)