Skip to content

Commit e9495bb

Browse files
authored
Merge pull request #309 from jgray-19/ptcmodel_fixes
Add ptcmodel flags in Sbend and Rbend
2 parents f6f7597 + 0925d76 commit e9495bb

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/madl_etrck.mad

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ local function track_sbend (elm, m, e1_, e2_)
362362

363363
if model == 'DKD' then -- curved thin
364364
inter, thick, kick = DKD[method], curex_drift , curex_kick
365-
elseif m.nmul == 1 and ksl[1] == 0 then -- curved thick only
365+
elseif m.nmul == 1 and ksl[1] == 0 and not m.ptcmodel then -- curved thick only
366366
inter, thick, kick = thickonly , sbend_thick , fnil
367367
else -- if abs(knl[2]) < minstr then -- curved thick
368368
inter, thick, kick = TKT[method], sbend_thick , sbend_kick
@@ -374,16 +374,16 @@ local function track_sbend (elm, m, e1_, e2_)
374374
end
375375

376376
local function track_rbend (elm, m)
377-
local angle, e1, e2, true_rbend in elm
377+
local angle, e1, e2, true_rbend, truerbend, ptcrbend in elm
378378

379379
m.mang = 0
380-
if not true_rbend then -- checked
380+
if not (true_rbend or truerbend or ptcrbend) then -- checked
381381
return track_sbend(elm, m, e1+angle/2, e2+angle/2)
382382
end
383383

384384
get_mult(elm, m, 3) -- unchecked
385385

386-
local ds, tdir, nmul, knl, ksl in m
386+
local ds, tdir, nmul, knl, ksl, ptcmodel in m
387387
local k0, k0s, k1, k1s, k2, k2s in elm
388388

389389
if abs(ds) < minlen then
@@ -396,15 +396,16 @@ local function track_rbend (elm, m)
396396
m.eld = ds
397397
m.elc = arc2cord(ds, angle)
398398

399-
if e1 and e2 then -- Will require m.ptcmodel
400-
m.e1, m.e2 = e1, e2
399+
if not ptcmodel and e1 and e2
400+
or ptcmodel and (e1==0 and e2==0 or e1~=0 and e2~=0) then
401+
m.e1, m.e2 = e1+angle/2, e2+angle/2
401402
m.el = m.elc
402-
else -- True parallel situation
403-
if e1 then -- Will require m.ptcmodel
403+
else -- True parallel
404+
if not ptcmodel and e1 or ptcmodel and e2==0 then
404405
m.e1, m.e2, m.etp_dir = e1, angle - e1, -1
405406
m.el = m.elc * cos(angle/2 - e1)
406407
else
407-
m.e1, m.e2, m.etp_dir = angle - e2, e2, 1 -- edge true parallel dir decides when patch is performed.
408+
m.e1, m.e2, m.etp_dir = angle - e2, e2, ptcmodel and -1 or 1 -- dir -> patch side.
408409
m.el = m.elc * cos(angle/2 - e2)
409410
end
410411
m.mang = m.e2
@@ -424,7 +425,7 @@ local function track_rbend (elm, m)
424425

425426
if model == 'DKD' then
426427
inter, thick, kick = DKD[method], strex_drift, strex_kick
427-
elseif m.nmul == 1 and ksl[1] == 0 then
428+
elseif m.nmul == 1 and ksl[1] == 0 and not ptcmodel then
428429
inter, thick, kick = thickonly , rbend_thick , fnil
429430
else
430431
inter, thick, kick = TKT[method], rbend_thick, rbend_kick
@@ -438,7 +439,7 @@ end
438439
local function track_quadrupole (elm, m)
439440
get_mult(elm, m, 2)
440441

441-
local ds, edir, tdir, nmul, knl, ksl in m
442+
local ds, edir, tdir, nmul, knl, ksl, ptcmodel in m
442443
local angle, k0, k0s, k1, k1s in elm
443444
local l = abs(ds)
444445

@@ -457,22 +458,22 @@ local function track_quadrupole (elm, m)
457458
local no_k1 = abs(knl[2]) < minstr
458459
local no_k1s = abs(ksl[2]) < minstr
459460
local no_ang = abs(angle) < minang
460-
local no_tlt = m.ptcmodel and not no_k1s and (abs(knl[1]) > minstr or nmul > 2 or elm.fringe > 0)
461-
local inter = m.ptcmodel and KMK[method] or TKT[method]
461+
local no_tlt = ptcmodel and not no_k1s and (abs(knl[1]) > minstr or nmul > 2 or elm.fringe > 0)
462+
local inter = ptcmodel and KMK[method] or TKT[method]
462463
local thick, kick
463464

464465
if model == 'DKD' or no_k1 and no_k1s and no_ang then
465466
inter, thick, kick = DKD[method], strex_drift, strex_kick
466467
elseif no_k1s and no_ang or no_tlt then -- normal thick
467468
m.k1 = knl[2]/ds*edir
468-
thick, kick = quad_thick, m.ptcmodel and quad_kick or quad_kick_ysh
469+
thick, kick = quad_thick, ptcmodel and quad_kick or quad_kick_ysh
469470
elseif no_ang then -- skew thick
470471
local a = -0.5*atan2(ksl[2], knl[2])
471472
m.k1, m.ca, m.sa = sqrt(knl[2]^2 + ksl[2]^2)/ds*edir, cos(a), sin(a)
472-
thick, kick = quad_thicks, m.ptcmodel and quad_kicks or quad_kicks_ysh
473+
thick, kick = quad_thicks, ptcmodel and quad_kicks or quad_kicks_ysh
473474
else -- combined thick -- unchecked
474475
m.eh = angle/ds*tdir
475-
thick, kick = quad_thickh, m.ptcmodel and quad_kickh or quad_kickh_ysh
476+
thick, kick = quad_thickh, ptcmodel and quad_kickh or quad_kickh_ysh
476477
end
477478

478479
local track = #elm == 0 and trackelm or tracksub

0 commit comments

Comments
 (0)