@@ -1649,7 +1649,7 @@ function M.curex_fringe (elm, m, lw_) -- [FRINGE_TEAPOT] --
1649
1649
if sdir*lw == 1 then
1650
1650
-- print(lw == 1 and 'forward entry' or 'backward exit')
1651
1651
yrotation (-e, m, 1)
1652
- bend_face ( h, m )
1652
+ bend_face ( h, m, 1 )
1653
1653
if m.frng ~= 0 then
1654
1654
if ftst(m.frng, fringe.bend) then bend_fringe(elm, m, 1) end
1655
1655
if ftst(m.frng, fringe.mult) then mult_fringe(elm, m, 1) end
@@ -1666,7 +1666,7 @@ function M.curex_fringe (elm, m, lw_) -- [FRINGE_TEAPOT] --
1666
1666
if ftst(m.frng, fringe.mult) then mult_fringe(elm, m, -1) end
1667
1667
if ftst(m.frng, fringe.bend) then bend_fringe(elm, m, -1) end
1668
1668
end
1669
- bend_face ( h, m )
1669
+ bend_face ( h, m, -1 )
1670
1670
yrotation ( e, m, -1)
1671
1671
end
1672
1672
@@ -1735,40 +1735,42 @@ end
1735
1735
1736
1736
-- fringes helpers ------------------------------------------------------------o
1737
1737
1738
- function bend_face (h, m) -- [NEWFACE] -- checked
1738
+ function bend_face (h, m, lw ) -- [NEWFACE] -- checked
1739
1739
if h == 0 then return end
1740
1740
local el, eld, knl in m
1741
1741
if abs(el) < minlen or abs(knl[1]) < minstr then return end
1742
1742
1743
- m.atdebug(h, m, 'bend_face:0')
1743
+ m.atdebug(h, m, lw, 'bend_face:0')
1744
1744
1745
- local edir, tdir, beam in m
1746
- local k0h = 0.5*h * knl[1]/(eld or el)*edir
1745
+ local edir, sdir, beam in m
1746
+ ! h is weighted by tdir, el is weighted by sdir, so to get tdir back, we need to multiply by sdir
1747
+ local k0h = 0.5*h * knl[1]/(eld or el) * sdir
1747
1748
local chg = beam.charge
1748
1749
local _beta = 1/beam.beta
1749
1750
1750
1751
for i=1,m.npar do
1751
1752
local x, px, y, py, t, pt, beam in m[i]
1752
1753
local _beta = beam and 1/beam.beta or _beta
1753
1754
local chg = beam and beam.charge or chg
1755
+ local k0hq = k0h*chg -- k0hq must be weighted by bdir
1754
1756
1755
- if tdir == 1 then -- to insure reversal symmetry ; horizontal wedge (only dir )
1756
- px = px + chg*k0h *x^2
1757
+ if sdir == 1 then -- to insure reversal symmetry ; horizontal wedge (only sdir )
1758
+ px = px + k0hq *x^2
1757
1759
end
1758
1760
1759
1761
local dpp = 1 + 2*pt*_beta + pt^2
1760
1762
local _pt2 = 1/(dpp - px^2)
1761
- local xi = 2*k0h*tdir *sqrt(dpp)*_pt2
1762
- local dxi_px = 2*px*xi *_pt2
1763
- local dxi_ddel = -2 *xi*(1+pt) *_pt2
1763
+ local xi = 2*k0hq *sqrt(dpp)*_pt2
1764
+ local dxi_px = 2*px*xi *_pt2
1765
+ local dxi_ddel = -2 *xi*(1+pt) *_pt2
1764
1766
1765
1767
x = x / (1-dxi_px*y^2)
1766
1768
px = px - xi*y^2
1767
1769
py = py - 2*xi*x*y
1768
1770
t = t - dxi_ddel*x*y^2
1769
1771
1770
- if tdir == -1 then -- to insure reversal symmetry; horizontal wedge (only dir )
1771
- px = px - chg*k0h *x^2
1772
+ if sdir == -1 then -- to insure reversal symmetry; horizontal wedge (only sdir )
1773
+ px = px + k0hq *x^2
1772
1774
end
1773
1775
1774
1776
m[i].x = x
@@ -1777,7 +1779,7 @@ function bend_face (h, m) -- [NEWFACE] -- chec
1777
1779
m[i].t = t
1778
1780
end
1779
1781
1780
- m.atdebug(h, m, 'bend_face:1')
1782
+ m.atdebug(h, m, lw, 'bend_face:1')
1781
1783
end
1782
1784
1783
1785
function mad8_wedge (e, m, lw_, wc) -- [FRINGE_TEAPOT:MAD8_WEDGE] -- checked
0 commit comments