 *** Welcome to SAD Ver.1.4.4.2k64 built at 2026-10-19 14:46:59 +0900 ***
 *** Today: 22:48:08 Monday 11/16/2026 ***
 OFF LOG;ON ECHO;READ 77 ;           1
!********************************************************************
!*
!*   ASTRID2 - THE ULTIMATE SYNCHROTRON RADIATION SOURCE
!*   http://www.isa.au.dk/facilities/astrid2/astrid2.asp
!*
!********************************************************************

MOMENTUM= 0.58 GEV;

MARK
	MKS   =()
	MKE   =()
;

MONI
	PM     =()
;

CAVI
	CAVI=(VOLT= 50000 FREQ = 104950000)
;

BEND
	PV = ( L = 0    K0 = 0     ROTATE =-90 DEG )
	PH = ( L = 0    K0 = 0  )
;

QUAD
	QF3 = ( L =0.1800 K1 =5.939500*0.1800 )
	QF2 = ( L =0.1800 K1 =6.070000*0.1800 )
;

SEXT
	SF = ( L =0.0750   K2 =   125.62*0.0750 )
	SD = ( L =0.1500   K2 =   -81.93*0.15 )
;

BEND
	BH = (L = 0.8500 ANGLE = 0.523599 K1 = -1.678200*0.8500  E1=0 E2=0)
;

DRIFT
	D14837    = (L = 1.4837 )
	D0100     = (L = 0.1000 )
	D0180     = (L = 0.1800 )
	D0190     = (L = 0.1900 )
	D0120     = (L = 0.1200 )
;

LINE
	HV    = (PH PV)
	NCELL
	=(MKS
	  D14837 PM D0100 QF3  D0180 HV D0180
          BH
          D0190 SD D0120 QF2 D0120 SF
          PM
	  SF D0120 QF2 D0120 SD D0190
          BH D0180 HV D0180 QF3 D0100 PM D14837
          MKE)

	RING = (3*NCELL CAVI 3*NCELL)
        RINGMPW = (3*NCELL CAVI 3*NCELL)
!	RING = (6*CELL)
;
 SEXT   SD      =(L =.15  K2 =-11.729486011842393 )
        SF      =(L =.075 K2 =8.681418961367605 )
 ;
!+
!  運動量依存チューンシフト: DP0 を -2% から +4% まで (点の中心が 0 だと PolynomialFit が SAD の癖で別の点まわりの展開を返すので、非対称にした) 0.5% 刻みで変えて CALC
!  6 極 ON (設計値) と OFF (S* 0) の 2 通り。多項式フィットで ξ1 ξ2 を出す。
!-
ON LOG RFSW RADCOD RAD COD;
OFF FLUC;
FFS;
 *** SADScript Initialization: /mnt/d/work/SAD-master/SAD-master/Packages/init.n ***
 *** Run time Environment:     /mnt/d/work/SAD-master/SAD-master/Packages/init.local.n ***
 RFSW RADCOD RAD  FLUC  INTRA POL   COD  DAPER EMIOU K64   FOURI SMEAR
   T     T     T     F     F     F     T     F     F     T     F     T
   $FORM = "12.8";
   PageWidth = 1999;
 
 USE RING;
Out[1]:= USE
   cell calc;
 Matched. (  0.000    ) DP = 0.01000  DP0 = 0.00000  ExponentOfResidual = 2.0  OffMomentumWeight =   1.000  CALEXP  
$$$       f AX    #######  #  2.050E-13 $$$       f BX    #######  #   3.891569 $$$       f NX    #######  #   5.179990 $$$       f AY    #######  #  4.047E-14 $$$       f BY    #######  #   1.622525 $$$       f NY    #######  #   2.140178
$$$       f LENG  #######  #  45.704400
   DP = 0;
   tx = {}; ty = {};
   dlist = Range[-0.02, 0.04, 0.005];
   Do[
       DP0 = dlist[i];
       FFS["cell calc"];
       nx = Twiss["NX","$$$"]/2/Pi; ny = Twiss["NY","$$$"]/2/Pi;
       tx = Append[tx, {dlist[i], nx}];
       ty = Append[ty, {dlist[i], ny}];
       Print["SEXT-ON  ", dlist[i], " ", nx, " ", ny];
   ,{i,1,Length[dlist]}];
SEXT-ON    -.02000000   5.19428162   2.15723388
SEXT-ON    -.01500000   5.18814235   2.14983966
SEXT-ON    -.01000000   5.18367023   2.14450701
SEXT-ON    -.00500000   5.18092632   2.14127044
SEXT-ON     .00000000   5.17998990   2.14017760
SEXT-ON     .00500000   5.18096210   2.14129178
SEXT-ON     .01000000   5.18397158   2.14469590
SEXT-ON     .01500000   5.18918302   2.15049865
SEXT-ON     .02000000   5.19680945   2.15884271
SEXT-ON     .02500000   5.20713184   2.16991815
SEXT-ON     .03000000   5.22053000   2.18398309
SEXT-ON     .03500000   5.23753462   2.20139770
SEXT-ON     .04000000   5.25891982   2.22268356
   cx = PolynomialFit[tx,3]; cy = PolynomialFit[ty,3];
   Print["SEXT-ON fit x: ", cx];
SEXT-ON fit x: {{  5.18000832,  -.05145168, 38.20013482, 302.0907184},{Residual-> 3.275768E-4}}
   Print["SEXT-ON fit y: ", cy];
SEXT-ON fit y: {{  2.14018905,  -.03598714, 44.17827830, 201.4569551},{Residual-> 2.268802E-4}}
 
   DP0 = 0;
   FFS["cell calc"];
   ! 6 極の寄与を式 (1/4pi) sum(+-) K2 EX B で数える (薄肉、要素の中点の値) 
   sp = LINE["POSITION","S*"];
   xsx = 0; xsy = 0;
   Do[
       k2 = LINE["K2", sp[i]];
       ex = Twiss["EX", sp[i]+0.5];
       xsx = xsx + k2*ex*Twiss["BX", sp[i]+0.5];
       xsy = xsy - k2*ex*Twiss["BY", sp[i]+0.5];
   ,{i,1,Length[sp]}];
   Print["sextupole xi_x, xi_y from formula = ", xsx/4/Pi, " ", xsy/4/Pi, "   (#sext = ", Length[sp], ")"];
sextupole xi_x, xi_y from formula =   6.31219114  11.94536303   (#sext =  24.00000000)
   S* 0;
   tx = {}; ty = {};
   Do[
       DP0 = dlist[i];
       FFS["cell calc"];
       nx = Twiss["NX","$$$"]/2/Pi; ny = Twiss["NY","$$$"]/2/Pi;
       tx = Append[tx, {dlist[i], nx}];
       ty = Append[ty, {dlist[i], ny}];
       Print["SEXT-OFF ", dlist[i], " ", nx, " ", ny];
   ,{i,1,Length[dlist]}];
SEXT-OFF   -.02000000   5.31804004   2.41167654
SEXT-OFF   -.01500000   5.28034225   2.33480396
SEXT-OFF   -.01000000   5.24510098   2.26524133
SEXT-OFF   -.00500000   5.21176870   2.20080318
SEXT-OFF    .00000000   5.17998988   2.14017757
SEXT-OFF    .00500000   5.14951991   2.08251135
SEXT-OFF    .01000000   5.12018244   2.02721587
SEXT-OFF    .01500000   5.09184528   1.97386582
SEXT-OFF    .02000000   5.06440605   1.92214211
SEXT-OFF    .02500000   5.03778326   1.87179765
SEXT-OFF    .03000000   5.01191051   1.82263579
SEXT-OFF    .03500000   4.98673257   1.77449616
SEXT-OFF    .04000000   4.96220276   1.72724503
   cx = PolynomialFit[tx,3]; cy = PolynomialFit[ty,3];
   Print["SEXT-OFF fit x: ", cx];
SEXT-OFF fit x: {{  5.17989210, -6.25386500, 27.91330381, -194.401591},{Residual-> 2.181410E-4}}
   Print["SEXT-OFF fit y: ", cy];
SEXT-OFF fit y: {{  2.13977455, -11.9405381, 66.23455483, -653.237320},{Residual-> 8.410578E-4}}
 Exit;
 FFS                  end:  CPU time =     0.071 sec
 Design orbit length =   1.0000000000000000     
 RFSW RADCOD RAD  FLUC  INTRA POL   COD  DAPER EMIOU K64   FOURI SMEAR
   T     T     T     F     F     F     T     F     F     T     F     T
 In[2]:=  ???-getbuf-end of input stream
