How the GG calculation works¶
This page summarizes the mathematics behind gg_fit. The field-expansion table
is linear in the GG functions and their s-derivatives, which makes the fit a
(weighted) linear least-squares problem.
The field expansion¶
For each field component \(c \in \{B_x, B_y, B_s\}\),
where each coefficient is a polynomial in the transverse coordinates,
and the derivative towers are \(b_{(n,m)} = \mathrm{d}^m b_n/\mathrm{d}z^m\), \(a_{(n,m)} = \mathrm{d}^m a_n/\mathrm{d}z^m\), and \(bs_{(m)} = \mathrm{d}^{m+1} a_0/\mathrm{d}z^{m+1}\).
Plane-by-plane least squares¶
The unknowns at a base plane \(z_0\) are the function values and their derivatives \(f_{(n,m)}(z_0)\) for \(m = 0 \ldots m_{\max}\). The field on a neighbouring plane at offset \(\mathrm{d}z = z - z_0\) is obtained by Taylor-extrapolating each derivative,
which makes the model linear in the base-plane unknowns. Each base plane is then
solved by weighted linear least squares over all field points lying within
n_planes_add planes of it. Adding planes (m_max = 2·n_planes_add) lets the
fit resolve higher derivatives and smooths the result; past some point, using
more planes makes the polynomial approximation less accurate, so there is an
optimum.
The merit function and weights¶
For a base plane, the merit function minimized is
with a per-point weight that factors as \(\text{weight}(x,y,\mathrm{d}z) = w_{\text{core}}(x,y)\, w_{\text{plane}}(\mathrm{d}z)\):
core_weight = 1 (the default) weights all transverse points equally; a value
1 favours near-axis points, which is usually desirable since a beam spends most of its time near the core.
outer_plane_weight = 1weights all planes equally; a value below 1 (but non-negative) down-weights the outer planes. Whenn_planes_add = 0(so \(\mathrm{d}z_{\max} = 0\)), \(w_{\text{plane}}\) is taken to be 1.
Conversion to Bmad’s convention¶
Bmad’s gen_grad_map uses azimuthal-harmonic gradients \(C_{m,\alpha}(z)\),
\(\alpha \in \{\sin, \cos\}\), rather than this project’s midplane-derivative GGs.
Equating the two expansions on the midplane gives exact recursions (solved in
order of increasing \(m\)):
where \(x^{[j]} \equiv \mathrm{d}^j x/\mathrm{d}s^j\) is supplied directly by the
fit. The full derivation, including the mixing weights \(W_n\), \(W_c\), and \(U_s\),
is in the write_bmad_gg_fit docstring (see the API Reference).
References¶
S. Van der Schueren et al., “Magnetic Field Modelling and Symplectic Integration of Magnetic Fields on Curved Reference Frames for Improved Synchrotron Design: First Steps” (copy in the
papers/directory).D. Sagan, IPAC’23 — the Venturini–Dragt azimuthal-harmonic field expansion used by Bmad.