Skip to content

Adjust MAD-NG bend face to match PTC #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/madl_dynmap.mad
Original file line number Diff line number Diff line change
Expand Up @@ -1742,33 +1742,35 @@ function bend_face (h, m, lw) -- [NEWFACE] --

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

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

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

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

local dpp = 1 + 2*pt*_beta + pt^2
local _pt2 = 1/(dpp - px^2)
local xi = 2*k0h*lw*sqrt(dpp)*_pt2
local dxi_px = 2*px*xi *_pt2
local dxi_ddel = -2 *xi*(1+pt) *_pt2
local xi = 2*k0hq*sqrt(dpp)*_pt2
local dxi_px = 2*px*xi *_pt2
local dxi_ddel = -2 *xi*(1+pt) *_pt2

x = x / (1-dxi_px*y^2)
px = px - xi*y^2
py = py - 2*xi*x*y
t = t - dxi_ddel*x*y^2
t = t + dxi_ddel*x*y^2

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

m[i].x = x
Expand Down