!Read transfer matrix (T_0) from start of injection line to inflector exit (3cm upstream of IBMS1 to inflector exit. See email from Bryn 9/22) !Read d_dx and ddx'. These derivatives are evaluated at some point near the start of the injection line (the reference point). !Read distance from reference point for derivatives to start of injection line. Create transfer matrix (T_R from reference point to start of line) !Read twiss parameters 10cm upstream from IBMS1. !Propagate twiss parameters at point 10cm upstream IBMS1 to reference point for derivatives program propagate_dphi_dx use parameters_bmad use muon_mod use muon_interface implicit none type (g2twiss_struct) twiss_IBMS, twiss_R, twiss_E !twiss at IBMS and reference point and exit real(rp) T0(6,6), T(6,6), T03(6,6), T10(6,6) !transfer matrix of the line. Transf mat from reference point to end of line real(rp) T_R(6,6), T_I(6,6), T_Rinv(6,6) !T_R is from reference point to start of line, T_I from IBMS1 to start, T_Rinv is inverse of T_R real(rp) T_IR(6,6) !10 cm upstream of IBMS1 to reference point real(rp) M_ba(2,2) !propagate dphi/dx vector from reference point to end of line real(rp) d_r0, d_I0 !distance from reference point to start of line and from 10cm upstream of IBMS1 to start of line real(rp) phi_R(2), phi_E(2) !dphi/dix, dhpi/dxp at reference point and at inflector exit real(rp) dx_dxp, dxp_dx real(rp) identity(6,6) integer i,j integer ir/0/ print '(a,$)',' Dphi/dx reference: at end of Q025 (1) or 33 mm downstream of IBMS1 (2) ?' read(5,*)ir ! d_r0 is the distance from the dphi/dx reference point to the start of the line ! 26 Q023 7.388535 0.000000 0.000000 7.388535 0.000000 0.444690 0.000000 0.000000 0.435000 ! 27 Q023 7.823535 0.000000 0.000000 7.823535 0.000000 0.444690 0.000000 0.000000 0.435000 ! 38 IQ024 9.169735 0.000000 0.000000 9.169735 0.000000 0.000000 0.000000 0.000000 0.000000 ! 39 Q024 9.604735 0.000000 0.000000 9.604735 0.000000 -0.576314 0.000000 0.000000 0.435000 ! 40 Q024 10.039735 0.000000 0.000000 10.039735 0.000000 -0.576314 0.000000 0.000000 0.435000 ! 51 IQ025 11.309735 0.000000 0.000000 11.309735 0.000000 0.000000 0.000000 0.000000 0.000000 ! 52 Q025 11.633335 0.000000 0.000000 11.633335 0.000000 0.609075 0.000000 0.000000 0.323600 ! 53 Q025 11.956935 0.000000 0.000000 11.956935 0.000000 0.609075 0.000000 0.000000 0.323600 ! !from bmad_m5_to_ring. !Q025_end at 11.756935, Q023_mid at 7.388535. Q023 mid to end of line = 9.8773. IBMS1 to start of line -0.03. Start of line to end of line = 4.4 ! => distance from end of !025 to start of line is 9.8773 - (11.956935-7.388535) -4.4 = ! | < 9.8773 > | ! | < > | | < 4.4 > | ! | | ! Q023-mid Q025-end start IBMS1 end ! if(ir == 1) d_r0= 9.8773 - (11.956935-7.388535) -4.4 if(ir == 2) d_r0 = 4.397-0.033 - 4.4 !IBMS1 is 3cm downstream from start of injection channel print '(a,es12.4,a)','Dphi/dx reference point is',d_r0,' meters from start of injection channel' d_I0 = 0.097 !distance from twiss reference point 10cm upstream from IBMS1 to start of line identity=0 do i=1,6 identity(i,i)=1 end do ! transfer matrix from 3mm upstream of IBMS1 to inflector exit !transfer matrix from 10cm upstream of IBMS1 to inflector exit T10(1,1)= 2.4149E+00; T10(1,2)= 8.3462E+00 T10(2,1)= 9.9594E-01; T10(2,2)= 3.8563E+00 T10(3,3)=-5.2008E-02; T10(3,4)= 1.5884E+00 T10(4,3)= 6.0265E-01; T10(4,4)= -8.22 !if using transfer matrix T10, d_I0=0, d_r0 = d_r0-0.097 T0=T10 d_r0=d_r0-0.097 d_I0=0 !dphi_R - Crnkovic phi_R(1) = -0.25 phi_R(2) = 0.77 !transfer from reference point to start of line T_R = identity T_R(1,2)=d_r0 T_R(3,4)=d_r0 T_Rinv = identity T_Rinv(1,2) = -T_R(1,2) T_Rinv(3,4) = -T_R(3,4) T = matmul(T0,T_R) !reference point to inflector exit !transfer from twiss reference point 10 cm upstream of IBMS1 to start of line T_I = identity T_I(1,2)=d_I0 T_I(3,4)=d_I0 T_IR = matmul(T_Rinv,T_I) !transfer from 10 cm upstream IBMS1 to reference point !twiss 10cm upstream of IBMS1 (Brynn email 9/22) twiss_IBMS%betax = 25.6 twiss_IBMS%alphax = 7.0 twiss_IBMS%betay = 3.0 twiss_IBMS%alphay = 2.5 call prop_phase_space(T_IR,twiss_IBMS, twiss_R) !propagate twiss at 10cm upstream IBMS1 to reference point. call prop_phase_space(T,twiss_R, twiss_E) !propagate twiss at reference point to end. !twiss_R%alphax = -twiss_R%alphax ! change direction !twiss_R%alphay = -twiss_R%alphay ! change direction dxp_dx = -twiss_R%alphax/twiss_R%betax dx_dxp = -twiss_R%alphax* twiss_R%betax/(1+twiss_R%alphax**2) M_ba(1,1) = T(1,1) + T(1,2) * dxp_dx M_ba(1,2) = T(1,1) * dx_dxp + T(1,2) M_ba(2,1) = T(2,1) + T(2,2) * dxp_dx M_ba(2,2) = T(2,1) * dx_dxp + T(2,2) print '(/,a)','M_ba - matrix for transport of dphi_dx, dphi_dx' print '(2es12.4)',((M_ba(i,j),j=1,2),i=1,2) phi_E = matmul(M_ba,phi_R) print '(a)','T0 - transfer matrix for the line' print '(2es12.4)',((T0(i,j),j=1,2),i=1,2) print '(/,a)','T_R - transfer matrix from reference to start' print '(2es12.4)',((T_R(i,j),j=1,2),i=1,2) print '(/,a)','T_Rinv - transfer matrix from reference to start' print '(2es12.4)',((T_Rinv(i,j),j=1,2),i=1,2) print '(/,a)','T - transfer matrix from reference to exit' print '(2es12.4)',((T(i,j),j=1,2),i=1,2) print '(/,a)','T_IR - transfer matrix from 10cm upstream IBMS1 to reference' print '(2es12.4)',((T_IR(i,j),j=1,2),i=1,2) print '(/,10x,3a19 )','10cm upstream IBMS1','reference point', 'End' print '(a10,3(7x,es12.4))', 'betax', twiss_IBMS%betax,twiss_R%betax, twiss_E%betax print '(a10,3(7x,es12.4))', 'alphax', twiss_IBMS%alphax,twiss_R%alphax, twiss_E%alphax print '(a10,3(7x,es12.4))', 'betay', twiss_IBMS%betay,twiss_R%betay, twiss_E%betay print '(a10,3(7x,es12.4))', 'alphay', twiss_IBMS%alphay,twiss_R%alphay, twiss_E%alphay print '(/,(15x,2a12))','dphi/dx','dphi/dxp' print '(a15,2es12.4)','reference point', phi_R print '(a15,2es12.4)','Exit', phi_E end