SAD の最も基本的な構成要素(原子 Atom)には次のものがあります。
これらの原子は次のように入力されます。
通常の表記法のほかに、FORTRANやCのように E あるいは eで 10 の冪乗を表わすことができます。なお、複素数は原子ではなく、2 + 3 * I などのように虚数単位をあらわすシンボル Iを用いた式で表わします。また、現在の仕様では実数と整数の区別はなく、演算の結果はすべて実数になるので丸め誤差に注意しなければなりません。
文字列は""で囲みます。""の中で\を使うと特殊な入力が可能です。
\による特殊な入力
| \e | escape |
| \n | 改行 |
| \r | return |
| \t | tab |
| \\ | backslash |
| \nnn | ASCIIコードが 8進数で nnn の文字 |
| \その他の文字 | その他の文字 |
| 行末の\ | 次の行に続く、改行文字は含まれない |
SAD には要素の複合体である複合要素、あるいは式と呼ばれるものがあります。式は、一般には 要素0[要素1, 要素2, ...]
のような格好をしています。要素の数はいくつでもかまいません。各要素は原子でもよいし、別の式でもかまいません。例えば a[b, ...][c, ...]...[d, ...] の様な形も式のひとつです。また、要素0をこの式の頭部 headと呼びます。
上のような式のままでも既に SAD の言語構造はすべて表現可能で、実際内部の処理はそうなっています。これが SAD もそれに属するところの「関数構文言語」の特徴です。つまり、この言語にはこれ以上特別な構文は存在しないという利点があります。例えば Mathematica や acs-lisp など幅広く利用されている言語の中にも関数構文言語は存在します。
しかし、上の格好のままでは単純な数式を書くのにも伝統的な表記法からはかけ離れてしまい、読み書きが難しくなります。そこで SAD では上の 要素0 が特別なシンポルの場合に伝統的な演算子による表記が可能になっています。例えば a + b * c は Plus[a, Times[b, c]]
と同値です。ここで問題になるのは演算子の優先順位です。次の2つの表は SAD で使われる演算子とその優先順位を示しています。この表で上にくるものほど優先的に評価されます。横線で区切られた範囲のものは同一の優先度をもち、その場合は式の左側から演算されます。
演算子とその優先順位
| 演算子 | 全表現 | グループ化 | |
| () | |||
| #シンボル | Slot[シンボル] | ||
| %正整数 | Out[正整数] | ||
| _ を含むシンボル | |||
| 式1 :: 式2 | MessageName[式1, 式2] | ||
| 式1 ? 式2 | PatternTest[式1, 式2] | ||
| {式1, 式2, ... } | List[式1, 式2, ... ] | ||
| 式1[式2, ... ] | 式1[式2, ... ] | (式1[式2])[式3] | |
| 式1[[式2, ... ]] | Part[式1, 式2, ... ] | (式1[ [式2] ])[ [式3] ] | |
| 式++ | Increment[式] | a++ increments a by 1, returning the old value of a. ++a increments a by 1, returning the new value of a. | |
| 式-- | Decrent[式] | ||
| ++式 | Incrent[Null, 式] | ||
| --式 | Decrent[Null, 式] | ||
| 式1 @ 式2 | 式1[式2] | 式1[ 式2[式3] ] | f@a refers the member a of an instance or a class f. Otherwise it is same as f[a]. f@g@h means (f@g)@h, and f@g[h] (f@g)[h]. |
| 式1 /@ 式2 | Map[式1, 式2] | 式1 /@ (式2 /@ 式3) | f/@a maps function f to subexpressions of a. f/@[a,level] specifies a levelspec of map by level. |
| 式1 //@ 式2 | MapAll[式1, 式2] | 式1 //@ (式2 //@ 式3) | f//@a maps function f to all subexpressions of a. f//@[a,Heads->True] maps including the heads of a and its subexpressions. |
| 式1 @@ 式2 | Apply[式1, 式2] | 式1 @@ (式2 @@ 式3) | |
| 式1 // 式2 // 式3 | StringJoin[式1, 式2, 式3] | ||
| 式1 . 式2 . 式3 | Dot[式1, 式2, 式3] | ||
| 式1 ^式2 | Power[式1, 式2] | 式1 ^1 (式2 ^1 式3) | |
| -式 | Times[-1, 式] | ||
| +式 | 式 | ||
| 式1 / 式2 | 式1 * 式2 ^-1 | ||
| 式1 * 式2 * 式3 | Times[式1, 式2, 式3] | ||
| (式1 式2 式3) | Times[式1, 式2, 式3] | ||
| 式1 + 式2 + 式3 | Plus[式1, 式2, 式3] | ||
| 式1 - 式2 | 式1 + (-1 * 式2) | ||
| 式1 == 式2 | Equal[式1, 式2] | ||
| 式1 <> 式2 | Unequal[式1, 式2] | ||
| 式1 >< 式2 | Unequal[式1, 式2] | ||
| 式1 > 式2 | Greater[式1, 式2] | ||
| 式1 >= 式2 | GreaterEqual[式1, 式2] | ||
| 式1 => 式2 | GreaterEqual[式1, 式2] | ||
| 式1 < 式2 | Less[式1, 式2] | ||
| 式1 <= 式2 | LessEqual[式1, 式2] | ||
| 式1 =< 式2 | LessEqual[式1, 式2] | ||
| 式1 === 式2 | SameQ[式1, 式2] | ||
| 式1 <=> 式2 | UnsameQ[式1, 式2] | ||
| ~ 式 | Not[式] | ||
| 式1 && 式2 && 式3 | And[式1, 式2, 式3] | ||
| 式1 || 式2 || 式3 | Or[式1, 式2, 式3] | ||
| 式 .. | Repeated[式] | ||
| 式 ... | RepeatedNull[式] | ||
| 式1 | 式2 | 式3 | Alternatives[式1, 式2, 式3] | ||
| シンボル1:式 | Pattern[シンボル1, 式] | ||
| 式1 -> 式2 | Rule[式1, 式2] | 式1 -> (式2 -> 式3) | |
| 式1 :> 式2 | RuleDelayed[式1, 式2] | 式1 :> (式2 :> 式3) | |
| 式1 /.1 式2 | ReplaceAll[式1, 式2] | ||
| 式1 //. 式2 | ReplaceRepeated[式1, 式2] | ||
| 式1 += 式2 | AddTo[式1, 式2] | ||
| 式1 -= 式2 | SubtractFrom[式1, 式2] | ||
| 式1 *= 式2 | TimesBy[式1, 式2] | ||
| 式1 /= 式2 | DivideBy[式1, 式2] | ||
| 式 & | Function[式] | ||
| シンボル1/: 式1 | TagSet[シンボル1, 式1] | ||
| 式1 = 式2 | Set[式1, 式2] | 式1 = (式2 = 式3) | |
| 式1 := 式2 | SetDelayed[式1, 式2] | ||
| 式1 ^1= 式2 | UpSet[式1, 式2] | ||
| 式1 ^1:= 式2 | UpSetDelayed[式1, 式2] | ||
| 式 =. | UnSet[式] | ||
| 式1 ; 式2 ; 式3 | CompoundExpression[式1, 式2, 式3] | ||
| 式1 ; 式2 ; | CompoundExpression[式1, 式2, Null] |
シンボルの間、或いは式の間の空白は、前の式が完結しないうちは、Times (*)とみなされます。
連続した関係演算子で結ばれた式、例えば a <= b < c などは Inequality[a, LessEqual, b, Less, c]と変換されます。これにより中央の式が重複して評価されるのが防がれます。ここで、関係演算子とは、Equal(==), Unequal(<>), Less(<), LessEqual(<=), Greater(>), GreaterEqual(>=), SameQ(===), 及び UnsameQ(<=>) です。
ある式 の頭部は Headという関数によって取り出します。f[x, y, ...] の頭部は f です。また、原子についてもHeadは次のような値を返します。
Head[f[x, y]] Out[1]:= f Head[1] Out[2]:= Real Head["abc"] Out[3]:= String Head[abc] Out[4]:= Symbol Head[abc_] Out[5]:= Pattern
ちなみに複素数の頭部は Complexです。
ある式の持つ意味はほとんどの場合その頭部によって決まります。式はある場合には関数の引用であり、評価されると何かの作用を起こしつつ、形の違う式を結果として返します。また、別の場合にはある種のデータの集合体とみなされ、そのような場合には評価されても形は変わりません。
関数 Part にはもう少し特殊な使い方がありますが、それはリストの項で説明します。
シンボルは SAD のなかではある原子、式、或いは関数を割り当てるために用います。シンボルは何も割り当てがない場合にはシンボルそれ自身が割り当てられていると考えられます。したがって、割り当てなしでいきなり使うこともできます。
一度 On[General::newsym] としておけば、以後、新しいシンボルの生成を検出することができます。
いくつかのシンボルにはシステムが前もって定義を与えています。例えば、組込みの関数がそれです。このようなシンボルはその名前を構成する各語の先頭が大文字、他が小文字で表記されています。
シンボルに値を割り当てるには関数 Set (演算子 =) を用います。
このほか、後述のように、Set はリストの要素への値の割り当てや関数の定義にも用いられます。
SAD にはシンボルの現在の値にある演算をして、またその結果を同じシンボルに再び割り当てるという関数(演算子)があります。表にそれらを列挙します。
シンボルの再割り当てを行う関数。
| 関数 | 演算子表記 | 等価な式 |
| AddTo | シンボル += 式 | シンボル = シンボル + 式 |
| SubtractFrom | シンボル -= 式 | シンボル = シンボル - 式 |
| TimesBy | シンボル *= 式 | シンボル = シンボル * 式 |
| DivideBy | シンボル /= 式 | シンボル = シンボル / 式 |
| AppendTo | シンボル = Append[シンボル, 式] | |
| PrependTo | シンボル = Prepend[シンボル, 式] |
Many commands and functions accept the wildcards as a specification for the name of elements or components. The valid wildcards are:
| * | matches any zero or more characters |
| % | matches one character |
| {..} | matches any character enclosed |
| {^..} | matches any character not enclosed |
| ..|.. | alternative pattern |
表のシンボル達はシステムがあらかじめ定数値を割り当てているものです。これらのシンボルには属性 Constant が与えられており、入力時に直ちに評価されます。
特別な定数シンボル
| シンボル | 値 | 意味 |
| True | 1 | 真 |
| False | 0 | 偽 |
| Infinity | (INF) | IEEE754 無限大 |
| INF | (INF) | IEEE754 無限大 |
| NaN | (NaN) | IEEE754 Not a Number |
| I | Complex[0, 1] | 虚数単位 |
| Pi | 2 * ArcSin[1] | 円周率 |
| E | Exp[1] | ネイピア数 e |
| EulerGamma | 0.57721566490153286061d0 | オイラー・マスケローニ定数 γ |
| SpeedOfLight | 299792458 | 光速(m/s) [定義値] |
| MKSAMu0 | Pi * 4.d-7 | 真空の透磁率(H/m, N/A^2) [定義値] |
| MKSAEpsilon0 | 1.d0 / (MKSAMu0 * SpeedOfLight^2) | 真空の誘電率(F/m, N/V^2) [定義より導出] |
| SIMu0 | Pi * 4.d-7 | MKSAMu0 |
| SIEpsilon0 | 1.d0 / (SIMu0 * SppedOfLight^2) | MKSAEpsilon0 |
| ElectronCharge | 1.602176487d-19 | 素電荷(C) [実験値: CODATA 2006] |
| FineStructureConstatnt | 1.d0 / 137.035999679d0 | 微細構造定数 [実験値 CODATA 2006] |
| ElectronMass | 0.510998910d6 | 電子静止質量(eV) [実験値 CODATA2006] |
| ElectronRadius | 2.8179402894d-15 | 電子古典半径(m) [実験値 CODATA2006] |
| ProtonMass | 938.272013d6 | 陽子静止質量(eV) [実験値 CODATA 2006] |
| ProtonRadius | ElectronCharge * SpeedOfLight^2 * 1.d-7 / ProtonMass | 陽子古典半径(m) [実験値より導出] |
| GoldenRatio | (1 + Sqrt[2]) / 5 | 黄金比 |
| Degree | Pi / 180 | 1度(rad) |
シンボル定義はsrc/tfinitn.f及びPackages/init.n、値は、src/inc/MACMATH.inc、src/inc/MACPHYS.inc(amorita branchでは、src/macmath.f とsrc/macphys.f)にて定義されています。
あるシンボルに対する値の割り当てを解除したい場合はClear や Unset (=.) を用います。
SAD は式を次の様に評価します。
FFS Levelで既に予約された特別な変数が存在します。 そのうちのいくつかはMAIN Levelからも用いることが出来ます。
beta function
Maximum value of beta function
Dispersion function
Maximum value of dispersion function
Derivative of dispersion function
$FORM is a character-string to specify the format of the output of a real number.
Usage: $FORM="w.f"
$FORM="Sw.f"
$FORM="Fw.f"
$FORM="Mw.f"
where w is the width of the output, and f is the length of the fractions. If S is attached, trailing zeroes are omitted. If F is attached, it becomes same as FORTRAN's F-format. If M is attached, the exponent is expressed as 10^n. If w and f are omitted, 17.15 is assumed. The default is S17.15 .
CASE is a character-string to be attached with TITLE to issue the CASE command of TopDrawer in DRAW or GEO commands.
CHARGE contains the charge of the particle. The default is +1. Currently many parameters such as VOLT, BZ, etc. are not consistent with CHARGE<>1 . Do not change CHARGE.
CONVERGENCE is the goal of the convergence(==MatchingResidual) in the matching. If MatchingResidual becomes smaller than CONVERGENCE times the effective number of the conditions, the matching by GO terminates. The flag CONV is set when MatchingResidual is smaller than CONVERGENCE after GO or CALCULATE(CAL). The default value is 10^-9.
DAPWIDTH is the width of the x-amplitudes to quit the tracking to judge the aperture is enough.
DP represents the relative momentum spread of the beam. It is automatically set by the keyword DP of the MARK element at the beginning of the beam line. The value of EMITY affects the default weight of variables in the matching. In the off-momentum matching, the range DP0 - DP < dp/p0 < DP0 + DP is used for the matching. The assumed momentum-distribution in the BEAMSIZE(BEAM), MEASURE(MEA), etc. commands, is Gaussian with the standard deviation DP and the mean DP0 if the flag GAUSS is on, otherwise uniform (square) in the range DP0 - DP < dp/p0 < DP0 + DP.
DP0 represents the central value of the relative momentum offset in the optics calculation, or the center of the momentum distribution of the beam. The on-momentum optics has the relative momentum deviation dp/p0 == DP0, and the off-momentum calculation is done in the range DP0 - DP < dp/p0 < DP0 + DP.
Shift of the origin of z of the closed orbit (default: 0). Set by EMITTANCE or Emittance[]. Effective with RING only.
Ratio of (effective voltage)/(Sum[VOLT_k,{k}]) (default: 1), where effective voltage V_eff is defined as
V_eff = Sqrt[(Sum[VOLT_k Cos[PHI_k],{k}])^2 + (Sum[VOLT_k Sin[PHI_k],{k}])^2] .
EFFVCRATIO is set by EMITTANCE(EMIT) or Emittance[]. Effective with RING only.
EMITX is a real variable used as the horizontal physical emittance. It is automatically set by the keyword EMITX of the MARK element at the beginning of the beam line. The EMITTANCE(EMIT) command returns its calculated value in EMITX. The value of EMITX affects the default weight of variables in the matching. Accessible in MAIN.
EMITY is a real variable used as the vertical physical emittance. It is automatically set by the keyword EMITY of the MARK element at the beginning of the beam line. The EMITTANCE(EMIT) command returns its calculated value in EMITY. The value of EMITY affects the default weight of variables in the matching. Accessible in MAIN.
FitFunction is a symbol to assign user-defined functions for matching by GO command.
Usage:
FitFunction := fun
where fun is a function that returns a real number or a list of real numbers to be nullified by GO. The goal of GO is make fun zero or list of zeros, as well as built-in matching conditions. Sum of fun^2 is added to MatchingResidual. GO also evaluates FitFunction to obtain the derivatives numerically. The function fun can refer the value of variables by Element or LINE functions, and the optical functions at DP0 by Twiss. The algorithm of matching is same as that for built-in conditions, but it is slower because of the numerical differentiation, when the beam line is big and the number of variables large.
Example:
FitFunction := {Twiss["BX","$$$"]-20, Twiss["BY","$$$"]-20};
which puts the same goal as
FIT $$$ BX 20 BY 20
FSHIFT is the relative shift df/f0 of the revolution (or rf) frequency in a ring. This is only valid in EMITTANCE(EMIT) or the particle-tracking. In the optics calculation DP0 should be used instead.
GCUT specifies the cut-off value of Gaussian distribution in unit of the standard deviation. Accessible in MAIN.
Geometrical-functions.
Available geometrical-functions are:
| GX | geometrical coordinate xi |
| GY | geometrical coordinate eta |
| GZ | geometrical coordinate zeta |
| CHI1 | geometrical rotation angle chi_1 |
| CHI2 | geometrical rotation angle chi_2 |
| CHI3 | geometrical rotation angle chi_3 |
The geometrical coordinate {xi, eta, zeta} is set by the ORG command. Its default origin is at the entrance of the beam line and the default directions are xi in s-direction, eta in -(x-direction) and zeta in -(y-direction) at the entrance. The set {xi, eta, zeta} forms a right-handed system.
The rotation angles are defined so as to give the local {x,y,s} is written as
{x,y,s}_local
=rotate[s,chi3] rotate[x,chi2] rotate[y,-chi1]{x,y,s}_origin,
where rotate[a,b] reads "rotate around the new a vector by b right-handedly".
Usage:
InitialOrbits = { {x1, px1, y1, py1, z1, dp1}, ...};
or
InitialOrbits = { {ax1, bx1, nx1, ay1, by1, ny1,
ex1, epx1, ey1, epy1, r11, r21, r31, r41,
x1, px1, y1, py1, z1, dp1, 0, 0, 0, 0, 0, 0, 0}, ...};
specifies initial conditions of a number of orbits for the optics calculation by CALCULATE(CAL) and GO. Those coordinates are offset from the central orbit. If six numbers are given, only the offsets of the orbits are affected. If 27 numbers are given, all Twiss parameters are set (values for non-orbit params are used directly. Orbits are giving offsets.)
If InitialOrbits are given, the off-momentum matching and finite-amplitude matching is disabled. InitialOrbits is also necessary to calculate optics with wake field.
orbit length.
LOSSAMPL is the transverse amplitude beyond which a particle is judged to have been lost. The default is 1 m. Accessible in MAIN.
LOSSDZ is the longitudinal position z beyond which a particle is judged to have been lost. The default is 100 m. Accessible in MAIN. LOSSDZ is effective only when SPAC is ON.
MatchingAmplitude is a list of amplitudes for the finite-amplitude matching.
Usage:
MatchingAmplitude := { {dp1,x1,y1}, ..};
where dp1 is the momentum deviation to be matched, x1 and y1 are the horizontal and vertical amplitudes at the beginning of the beam line, normalized by Sqrt of the sum of the emittance, i.e., Sqrt[(EMITX+EMITY)]. Three orbits are chosen in each dimension. The initial conditions of the orbit is chosen as
{X,Px,Y,Py} =
{ {x1,0,0,0}, {-x1/2,Sqrt[3]/2 x1,0,0}, {-x1/2,-Sqrt[3]/2 x1,0,0},
{0,0,y1,0}, {0,0,-y1/2,Sqrt[3]/2 y1}, {0,0,-y1/2,Sqrt[3]/2 y1} },
and when x1==0 or y1==0 corresponding orbits are excluded. The above are labeled {x1,x2,x3,y1,y2,y3} in the output of CALCULATE(CAL) or GO, and also labeled 1 to 6 in the second element of FFS["CALC"] and FFS["GO"].
This matching is done when dp1 is within the off-momentum range given by DP, i.e., Abs[dp1] < DP. If dp1 is in the range, the nearest zero-amplitude optics is chosen. The maching conditions for the finite-amplitude optics are same as those for the zero-amplitude one.
The orbit with finte initial condition never close after one revolution, but FFS simply ignores it and obtain the periodic optics around the open orbit.
MatchingResidual holds the convergence in the last GO or CALCULATE(CAL) commands. It is calculated by
sw*(Sum[(w_i*df_i)^ExponentOfResidual,{i}]/sw)^(2/ExponentOfResidual)+penalty
where w_i is the weight of the i-th condition, df_i is the difference of the i-th function from the goal, penalty is an additional big number (typically 10), when the optics is unstable or closed orbit is not found in the case of CELL. The parameter sw is defined as
sw=Sum[(OffMomentumWeight/2/woff)^2,{i}]
with
woff = 1 for on-momentum optics
= Sqrt[number-of-momentum-points] for off-momentum optics.
The weight of the function is lighter in the case of off-momentum-matching so that all off-momentum deviations functions weight equal to the on-momentum one. However, the relative weight for the off-momentum part can be changed by setting OffMomentumWeight. The weight of each function at each point with each momentum can be specified by defining the FitWeight function.
MASS is the rest mass of the particle. The default is electron mass. "MASS" should be capital.
Usage:
MASS = 0.938260E0 GeV;
MINCOUP is the minimum emittance ratio (EMITY/EMITX) to be assumed in the calculation of intra-beam effects in EMITTANCE(EMIT). Accessible in MAIN.
MOMENTUM is the nominal momentum of the beam line at the entrance in eV. Accessible in MAIN.
Usage:
MOMENTUM = 30.924E0 GeV;
Wake functionを計算するためのバンチ数。 MAIN Levelからも利用可能です。
トラッキングをする際に用いる粒子数。 MAIN Levelからも利用可能です。
トラッキングにおいて並列化する数。 現時点ではPSPAC/WSPAC, ExternalMap[], RAD/FLUCと共には用いることが出来ない。
Horizontal, Vertical, tune
Relative weight of the off-momentum deviation for the off-momentum matching. The default is 1.
リングにおいて周回周波数を表す。 定義は 2*Pi*SpeedOfLight/LINE["S","$$$"] です。 MAIN Levelからも利用可能です。
OpticsEpilog is a variable to assign a user-defined function which is to be executed everytime after an optics calculation is done in CALCULATE(CAL) or GO commands. In GO, OpticsEpilog is called at the end of each iteration. This function is useful, for instance, for setting parameters which depends on the result of optics calculation.
OpticsProlog is a variable to assign a user-defined function which is to be executed everytime before an optics calculation is done in CALCULATE(CAL) or GO commands. In GO, OpticsProlog is called at the beginning of each iteration. This function is useful, for instance, for setting parameters which depends on the result of optics calculation.
出力する際のページ幅。 デフォルトでは、
GetEnv["WIDTH"]
で環境変数からセットされる。
PBUNCH is the number of particles/bunch for the calculation of the intra-beam and space charge effects in EMITTANCE(EMIT), and WakeFunction. Accessible in MAIN.
When PHOTONS is ON (default is OFF), TrackParticles generates a list of all photons radiated through the tracking. The list is assigned to a symbol PhotonList. PhotonList is a list of {en, gx, gy, gz, nx, ny, nz, xi1, xi2, xi3, np, nele}
where
The probability of each polarization is given by each Stokes' parameter as (1+xi)/2 . TrackParticles always updates PhotonList. The length of PhtonList is the number of emitted photons.
Remember that the {GX, GY, GZ} = {0, 0, 0} and their directions are {z, -x, -y} at the entrance of the beam line by default. It is changeable by the GEO command anyway.
Shift of cavity phase PHI when variation exists among cavities (default: 0). Set by EMITTANCE(EMIT) or Emittance[] as
{Cos[PHICAV], Sin[PHICAV]} == {Sum[VOLT_k Cos[PHI_k],{k}], Sum[VOLT_k Sin[PHI_k],{k}]} .
Effective with RING only.
SpeedOfLight is 299792458.
SADScript interpreterでのスタックサイズ。 FFSを最初に呼び出す前に、MAIN Level上でユーザーがセットすることが可能です。 デフォルトは200000です。
TITLE is a character-string to make the title of the plot in DRAW or GEO commands.
WakeFunction[Longitudinal, comp]={{z1, wl1}, ..., {zn, wln}};
WakeFunction[Transverse, comp]={{z1, wt1}, ..., {zn, wtn}};
specify logitudinal and transverse dipole wake functions at a component comp (string). Each functions is a list of {z, w} where z is the distance (z>=0) and w is the value of the wake, in unit of either V/C or V/C/m.
The wake funcitons are applied at the componet comp, giving kicks to each orbit whose initial conditions are give by InitialOrbits. The sufficient number of orbits depends on the situation.
WakeFunction is valid only when TRPT and INS, and also either TWAKE or LWAKE is ON.