You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/madl_dynmap.mad
+66-43Lines changed: 66 additions & 43 deletions
Original file line number
Diff line number
Diff line change
@@ -1777,21 +1777,33 @@ function bend_face (elm, m, lw, h) -- [NEWFACE] --
1777
1777
px = px + k0hq*x^2
1778
1778
end
1779
1779
1780
-
-- This is still not fully revesible in 3rd and 4th order, due to self dependance of px
1781
-
local dpp = 1 + 2/beta*pt + pt^2
1782
-
local _pt2 = 1/(dpp - px^2)
1783
-
local xi = 2*k0hq*sqrt(dpp)*_pt2
1784
-
local dxi_px = 2*px*xi *_pt2
1785
-
local dxi_ddel = -2 *xi*(1+pt) *_pt2
1786
-
local y2 = y^2
1787
-
1788
-
x = x / (1-dxi_px*y2) -- this affects reversibility also, for py
1789
-
px = px - xi*y2
1790
-
py = py - 2*xi*x*y
1791
-
t = t + dxi_ddel*x*y2
1792
-
1793
-
if sdir == -1 then -- to insure reversal symmetry; horizontal wedge (only sdir) -> PTC uses edir, and if we do this, reversing edir does not give the same result
1794
-
px = px + k0hq*x^2
1780
+
-- This is still not fully revesible in 4th order, due to dependancy of x on px and vice versa.
1781
+
local dpp = 1 + 2/beta*pt + pt^2
1782
+
local y2 = y^2
1783
+
local _pt2 = 1/(dpp - px^2)
1784
+
local xi = 2*k0hq*sqrt(dpp)*_pt2
1785
+
local dxi_px = 2*px*xi *_pt2
1786
+
1787
+
if sdir == -1 then
1788
+
local npx = px - xi*y2
1789
+
_pt2 = 1/(dpp - npx^2)
1790
+
xi = 2*k0hq*sqrt(dpp)*_pt2
1791
+
dxi_px = 2*npx*xi *_pt2
1792
+
end
1793
+
1794
+
local dxi_ddel = -2*xi*(1+pt)*_pt2
1795
+
1796
+
if sdir == 1 then
1797
+
x = x / (1-dxi_px*y2)
1798
+
px = px - xi*y2
1799
+
py = py - 2*xi*x*y
1800
+
t = t + dxi_ddel*x*y2
1801
+
else
1802
+
t = t + dxi_ddel*x*y2
1803
+
py = py - 2*xi*x*y
1804
+
1805
+
x = x / (1-dxi_px*y2)
1806
+
px = px - xi*y2 + k0hq*x^2
1795
1807
end
1796
1808
1797
1809
m[i].x = x
@@ -1863,6 +1875,34 @@ function bend_wedge (elm, m, lw_, e) -- [WEDGE] see also [sr]bend_thick --
1863
1875
m.atdebug(elm, m, 'bend_wedge:1')
1864
1876
end
1865
1877
1878
+
local function bend_fringe_param (dpp, px, py, c2, b0, tfac, only_ky)
1879
+
-- This map could do with some cleaning, use of pz, _pz and _pz2 is inconsistent
1880
+
local pz = sqrt(dpp - px^2 - py^2)
1881
+
local _pz = 1/pz
1882
+
local _pz2 = _pz^2
1883
+
1884
+
local xp, yp = px/pz, py/pz
1885
+
local xyp, yp2 = xp*yp, 1+yp^2
1886
+
local xp2,_yp2 = xp^2 , 1/yp2
1887
+
1888
+
local fi0 = atan((xp*_yp2)) - c2*(1 + xp2*(1+yp2))*pz
1889
+
local co2 = b0/cos(fi0)^2
1890
+
local co1 = co2/(1 + (xp*_yp2)^2)*_yp2
1891
+
local co3 = co2*c2
1892
+
1893
+
local fi1 = co1 - co3*2*xp*(1+yp2)*pz
1894
+
local fi2 = -2*co1*xyp*_yp2 - co3*2*xp*xyp *pz
1895
+
local fi3 = - co3*(1 + xp2*(1+yp2))
1896
+
1897
+
local ky = fi1*xyp*_pz + fi2*yp2*_pz - fi3*yp
1898
+
if only_ky then return fi0, nil, ky, nil end -- only ky is needed, speed up calculation
1899
+
1900
+
local kx = fi1*(1+xp2)*_pz + fi2*xyp*_pz - fi3*xp
1901
+
local kz = fi1*tfac*xp*_pz2 + fi2*tfac*yp*_pz2 - fi3*tfac*_pz
1902
+
return fi0, kx, ky, kz
1903
+
end
1904
+
1905
+
1866
1906
function bend_fringe (elm, m, lw) -- [FRINGE_DIPOLE] -- checked
1867
1907
if abs(m.knl[1]) < minang then return end
1868
1908
m.atdebug(elm, m, 'bend_fringe:0')
@@ -1884,46 +1924,29 @@ function bend_fringe (elm, m, lw) -- [FRINGE_DIPOLE] --
1884
1924
local c2 = b0*fh*2
1885
1925
1886
1926
local dpp = 1 + 2/beta*pt + pt^2
1887
-
local pz = sqrt(dpp - px^2 - py^2)
1888
-
local _pz = 1/pz
1889
-
local _pz2 = _pz^2
1890
1927
local relp = invsqrt(dpp)
1891
1928
local tfac = -(1/beta + pt)
1892
1929
local c3 = b0^2*fsad*relp
1893
1930
1894
-
local xp, yp = px/pz, py/pz
1895
-
local xyp, yp2 = xp*yp, 1+yp^2
1896
-
local xp2,_yp2 = xp^2 , 1/yp2
1897
-
1898
-
local fi0 = atan((xp*_yp2)) - c2*(1 + xp2*(1+yp2))*pz
1899
-
local co2 = b0/cos(fi0)^2
1900
-
local co1 = co2/(1 + (xp*_yp2)^2)*_yp2
1901
-
local co3 = co2*c2
1902
-
1903
-
local fi1 = co1 - co3*2*xp*(1+yp2)*pz
1904
-
local fi2 = -2*co1*xyp*_yp2 - co3*2*xp*xyp *pz
1905
-
local fi3 = - co3*(1 + xp2*(1+yp2))
1906
-
1907
-
local kx = fi1*(1+xp2)*_pz + fi2*xyp*_pz - fi3*xp
1908
-
local ky = fi1*xyp*_pz + fi2*yp2*_pz - fi3*yp
1909
-
local kz = fi1*tfac*xp*_pz2 + fi2*tfac*yp*_pz2 - fi3*tfac*_pz
1910
-
1931
+
local fi0, kx, ky, kz = bend_fringe_param(dpp, px, py, c2, b0, tfac, sdir==-1) -- this method is not perfect.
1932
+
local ny = 2*y / (1 + sqrt(1-2*ky*y))
1911
1933
if sdir == 1 then
1912
-
y = 2*y / (1 + sqrt(1-2*ky*y))
1913
-
local y2 = y^2
1934
+
local ny2 = ny^2
1914
1935
1915
-
m[i].x = x + 0.5*kx*y2
1916
-
m[i].py = py - (4*c3*y2 + b0*tan(fi0))*y
1917
-
m[i].t = t + (0.5*kz + c3*y2*relp^2*tfac)*y2
1918
-
m[i].y = y
1936
+
m[i].x = x + 0.5*kx*ny2
1937
+
m[i].py = py - (4*c3*ny2 + b0*tan(fi0))*ny
1938
+
m[i].t = t + (0.5*kz + c3*ny2*relp^2*tfac)*ny2
1939
+
m[i].y = ny
1919
1940
else -- need to reverse y-dependence
1920
-
-- This is still not fully revesible in 3rd and 4th order, due to self dependance of y
1941
+
-- This is still not fully revesible in 5thand 6th order, due to self dependance of py -> results in max error of 1e-11 and 2e-9 for 5th and 6th order respectively
1942
+
local npy = py + (4*c3*ny^2 + b0*tan(fi0))*ny
1943
+
fi0, kx, ky, kz = bend_fringe_param(dpp, px, npy, c2, b0, tfac) -- this method is not perfect.
0 commit comments