Skip to content

Commit 24247b9

Browse files
authored
Merge pull request #293 from jgray-19/fix_sbend_face
Adjust MAD-NG bend face to match PTC
2 parents 7f27bda + 8381d8c commit 24247b9

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/madl_dynmap.mad

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,33 +1773,35 @@ function bend_face (h, m, lw) -- [NEWFACE] --
17731773

17741774
m.atdebug(h, m, lw, 'bend_face:0')
17751775

1776-
local edir, beam in m
1777-
local k0h = 0.5*h * knl[1]/(eld or el)*edir
1776+
local edir, sdir, tdir, beam in m
1777+
! h is weighted by tdir, el is weighted by sdir, so to get tdir back, we need to multiply by sdir
1778+
local k0h = 0.5*h * knl[1]/(eld or el) * sdir
17781779
local chg = beam.charge
17791780
local _beta = 1/beam.beta
17801781

17811782
for i=1,m.npar do
17821783
local x, px, y, py, t, pt, beam in m[i]
17831784
local _beta = beam and 1/beam.beta or _beta
17841785
local chg = beam and beam.charge or chg
1786+
local k0hq = k0h*chg -- k0hq must be weighted by bdir
17851787

1786-
if lw == 1 then -- to insure reversal symmetry ; horizontal wedge (only dir)
1787-
px = px + chg*k0h*x^2
1788+
if tdir == 1 then -- to insure reversal symmetry ; horizontal wedge (only tdir)
1789+
px = px + k0hq*x^2
17881790
end
17891791

17901792
local dpp = 1 + 2*pt*_beta + pt^2
17911793
local _pt2 = 1/(dpp - px^2)
1792-
local xi = 2*k0h*lw*sqrt(dpp)*_pt2
1793-
local dxi_px = 2*px*xi *_pt2
1794-
local dxi_ddel = -2 *xi*(1+pt) *_pt2
1794+
local xi = 2*k0hq*sqrt(dpp)*_pt2
1795+
local dxi_px = 2*px*xi *_pt2
1796+
local dxi_ddel = -2 *xi*(1+pt) *_pt2
17951797

17961798
x = x / (1-dxi_px*y^2)
17971799
px = px - xi*y^2
17981800
py = py - 2*xi*x*y
1799-
t = t - dxi_ddel*x*y^2
1801+
t = t + dxi_ddel*x*y^2
18001802

1801-
if lw == -1 then -- to insure reversal symmetry; horizontal wedge (only dir)
1802-
px = px - chg*k0h*x^2
1803+
if tdir == -1 then -- to insure reversal symmetry; horizontal wedge (only tdir)
1804+
px = px + k0hq*x^2
18031805
end
18041806

18051807
m[i].x = x

0 commit comments

Comments
 (0)