Skip to content

Commit dcba580

Browse files
authored
Improve backtracking for bend_face
1 parent f32d167 commit dcba580

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/madl_dynmap.mad

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ function M.curex_fringe (elm, m, lw_) -- [FRINGE_TEAPOT] --
16491649
if sdir*lw == 1 then
16501650
-- print(lw == 1 and 'forward entry' or 'backward exit')
16511651
yrotation (-e, m, 1)
1652-
bend_face ( h, m )
1652+
bend_face ( h, m, 1)
16531653
if m.frng ~= 0 then
16541654
if ftst(m.frng, fringe.bend) then bend_fringe(elm, m, 1) end
16551655
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] --
16661666
if ftst(m.frng, fringe.mult) then mult_fringe(elm, m, -1) end
16671667
if ftst(m.frng, fringe.bend) then bend_fringe(elm, m, -1) end
16681668
end
1669-
bend_face ( h, m )
1669+
bend_face ( h, m, -1)
16701670
yrotation ( e, m, -1)
16711671
end
16721672

@@ -1735,40 +1735,42 @@ end
17351735

17361736
-- fringes helpers ------------------------------------------------------------o
17371737

1738-
function bend_face (h, m) -- [NEWFACE] -- checked
1738+
function bend_face (h, m, lw) -- [NEWFACE] -- checked
17391739
if h == 0 then return end
17401740
local el, eld, knl in m
17411741
if abs(el) < minlen or abs(knl[1]) < minstr then return end
17421742

1743-
m.atdebug(h, m, 'bend_face:0')
1743+
m.atdebug(h, m, lw, 'bend_face:0')
17441744

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
17471748
local chg = beam.charge
17481749
local _beta = 1/beam.beta
17491750

17501751
for i=1,m.npar do
17511752
local x, px, y, py, t, pt, beam in m[i]
17521753
local _beta = beam and 1/beam.beta or _beta
17531754
local chg = beam and beam.charge or chg
1755+
local k0hq = k0h*chg -- k0hq must be weighted by bdir
17541756

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
17571759
end
17581760

17591761
local dpp = 1 + 2*pt*_beta + pt^2
17601762
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
17641766

17651767
x = x / (1-dxi_px*y^2)
17661768
px = px - xi*y^2
17671769
py = py - 2*xi*x*y
17681770
t = t - dxi_ddel*x*y^2
17691771

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
17721774
end
17731775

17741776
m[i].x = x
@@ -1777,7 +1779,7 @@ function bend_face (h, m) -- [NEWFACE] -- chec
17771779
m[i].t = t
17781780
end
17791781

1780-
m.atdebug(h, m, 'bend_face:1')
1782+
m.atdebug(h, m, lw, 'bend_face:1')
17811783
end
17821784

17831785
function mad8_wedge (e, m, lw_, wc) -- [FRINGE_TEAPOT:MAD8_WEDGE] -- checked

0 commit comments

Comments
 (0)