@@ -36,8 +36,9 @@ local fnil, bind3rd in MAD.gfunc
36
36
local errorf in MAD.utility
37
37
local minlen, minang in MAD.constant
38
38
local is_implicit in element.drift
39
+ local arc2cord in MAD.gmath
39
40
40
- local abs in math
41
+ local abs, sin in math
41
42
42
43
-- integrator schemes ---------------------------------------------------------o
43
44
@@ -192,23 +193,23 @@ end
192
193
-- rbend special --------------------------------------------------------------o
193
194
194
195
local function fng_e1 (e, m, s)
195
- local e1, e2, sdir in m
196
+ local e1, e2, elc, sdir in m
196
197
local d = s*sdir
197
198
if d == -1 then
198
- local e_ = {name=e.name, dx=m. elc*sin((e2-e1)/2), dy=0, ds=0}
199
- yrotation(e2, m, -1)
200
- translate(e_, m, s )
199
+ local e_ = {name=e.name, dx=elc*sin((e2-e1)/2), dy=0, ds=0}
200
+ yrotation(e2, m, -1) -- translation independant of direction
201
+ translate(e_, m, -1 )
201
202
elseif e1 ~= 0 then
202
203
yrotation(e1, m, -1)
203
204
end
204
205
end
205
206
206
207
local function fng_e2 (e, m, s)
207
- local e1, e2, sdir in m
208
+ local e1, e2, elc, sdir in m
208
209
local d = s*sdir
209
210
if d == 1 then
210
- local e_ = {name=e.name, dx=m. elc*sin((e2-e1)/2), dy=0, ds=0}
211
- translate(e_, m, s)
211
+ local e_ = {name=e.name, dx=elc*sin((e2-e1)/2), dy=0, ds=0}
212
+ translate(e_, m, -1) -- translation independant of direction
212
213
yrotation(e1, m, -1)
213
214
elseif e2 ~= 0 then
214
215
yrotation(e2 , m, -1)
@@ -221,18 +222,23 @@ local function track_rbend (elm, m)
221
222
local fng = nil -- default: curved rbend aka sbend with parallel pole faces
222
223
223
224
if elm.true_rbend then -- true rbend
224
- local e1, e2 in elm
225
- -- compute correct E1 and E2 from the slides.
226
- if e1 and e2 then
225
+ local e1, e2, angle, l in elm
226
+ if e1 and e2 then -- MAD-like Wedge rbend
227
227
fng = fng_e
228
- elseif e1 then
229
- fng = fng_e1
230
- else
231
- fng = fng_e2
228
+ else -- true parallel rbend
229
+ m.elc = arc2cord(l, angle)
230
+ if e1 then
231
+ m.e1, m.e2 = e1, angle - e1
232
+ fng = fng_e1
233
+ else
234
+ m.e1, m.e2 = angle - e2, e2
235
+ fng = fng_e2
236
+ end
232
237
end
233
238
end
234
239
235
240
track_thick(elm, m, fng)
241
+ m.e1, m.e2, m.elc = nil, nil, nil
236
242
end
237
243
238
244
-- load maps into elements ----------------------------------------------------o
0 commit comments