\documentclass[a4paper,11pt]{article}
\parskip=1.5ex
\usepackage{geometry,verbatim,a4margins}

\newcommand{\dd}[2]{\frac{\mathrm d #1}{\mathrm d #2}}
\newcommand{\ddh}[2]{\mathrm d #1/\mathrm d #2}
\newcommand{\dds}[2]{\frac{\mathrm d^2 #1}{{\mathrm d #2}^2}}
\newcommand{\ddhp}[3]{\mathrm d^{#3} #1/{\mathrm d #2}^{#3}}
\newcommand{\pdd}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\pdds}[2]{\frac{\partial^2 #1}{\partial{#2}^2}}
\newcommand{\pddd}[3]{\frac{\partial^2 #1}{\partial #2\partial #3}}

\newcommand{\rowfour}[4]{\left[\begin{array}{cccc}#1&#2&#3&#4\end{array}\right]}
\newcommand{\vectwo}[2]{\left[\begin{array}{c}#1\\#2\end{array}\right]}
\newcommand{\vecthree}[3]{\left[\begin{array}{c}#1\\#2\\#3\end{array}\right]}
\newcommand{\mxtwo}[4]{\left[\begin{array}{cc}#1&#2\\#3&#4\end{array}\right]}

\newcommand{\sq}[1]{\left(#1\right)^2}

\newcommand{\B}{\mathbf B}
\newcommand{\F}{\mathbf F}
\newcommand{\x}{\mathbf x}
\newcommand{\p}{\mathbf p}
\newcommand{\vv}{\mathbf v}
\newcommand{\uv}{\mathbf u}

\begin{document}

\title{Maxwellian Fields for a Ring derived from Multipole End Fields}
\author{Stephen Brooks}
\date{November 12, 2024}
\maketitle

\section{Turning an End Field on its Side}
A previous note derived the following expression for a magnetic field that is order $n$ rotationally symmetric about the $z$ axis: 
\[ \B = \sum_{j=0}^{\infty} C_{nj} r^{n+2j-1} 
\vecthree{((n+j)\sin((n-1)\theta+\psi)+j\sin((n+1)\theta+\psi)) f^{(2j)}(z)}{((n+j)\cos((n-1)\theta+\psi)-j\cos((n+1)\theta+\psi)) f^{(2j)}(z)}{r \sin(n\theta+\psi) f^{(2j+1)}(z)}. \]
Here, $r=\sqrt{x^2+y^2}$,
\[ C_{nj} = \prod_{i=1}^j \frac{-1}{(n+2i)^2-n^2} = \prod_{i=1}^j \frac{-1}{4(n+i)i} = \frac{(-\frac14)^j n!}{(n+j)!j!} \]
and $f(z)$ is proportional to the strength variation of the $2n$-pole along the $z$ axis.  $\psi=0$ gives normal orientation and $\psi=\frac\pi2$ the skew orientation.

The idea of this note is to reinterpret $(x,y)$ as the plane of a ring with superperiodicity $n$, making $z$ the `vertical' or out-of-plane axis.  The vertical $B_z$ component is oscillatory but can be supplemented by a constant field in that direction, producing something similar to `field flutter' in cyclotrons, including the alternating gradients that keep the beam stable.  Normally it is desired that the $z=0$ ring plane only has field perpendicular to it, meaning $B_x=B_y=0$ there.  This can be guaranteed by making $f(z)$ an odd function, so that $f^{(2j)}(0)=0$ for all $j$.

\section{$f$ with Order 1}
The simplest case with $f(z)$ an odd polynomial is $f(z)=az$.  As $f''$ and all higher derivatives are zero, only the $j=0$ term is nonzero.  Note that $C_{n0}=1$ and then
\[ \B = r^{n-1} \vecthree{n\sin((n-1)\theta+\psi) az}{n\cos((n-1)\theta+\psi) az}{r \sin(n\theta+\psi) a}. \]
The peak strength of the dipole field on the midplane is $ar^n$ and the peak gradient is $anr^{n-1}$.

This field model has the advantage of being very simple.  It is also the field of a scaling FFA with field index $k=n$ and a cell with sinusoidally-varying focussing (not a very efficient machine as the reverse bending nearly equals the bending).  If more complex cells are desired, terms replacing $n$ with $2n$, $3n$, etc. can add longitudinal harmonics to the periodic cell.

One disadvantage of this field model for larger beams is that it also has a sextupole $\dds{B_z}{r}$ of peak strength $an(n-1)r^{n-2}$ that leads to nonlinear beam transport.

% Could also try removing DIPOLE and just leave quadrupole flutter

\section{$f$ with Order 3}
The second simplest case is $f(z)=az+bz^3$.  Now the $j=0,1$ terms are the only nonzero ones.  $C_{n1}=\frac{-1}{4(n+1)}$ and 
\[ \B = r^{n-1} \vecthree{n\sin((n-1)\theta+\psi)(az+bz^3)}{n\cos((n-1)\theta+\psi)(az+bz^3)}{r \sin(n\theta+\psi)(a+3bz^2)} \]
\[ + \frac{-1}{4(n+1)} r^{n+1} \vecthree{((n+1)\sin((n-1)\theta+\psi)+\sin((n+1)\theta+\psi)) 6bz}{((n+1)\cos((n-1)\theta+\psi)-\cos((n+1)\theta+\psi)) 6bz}{r \sin(n\theta+\psi) 6b}. \]
The peak strength of the dipole field on the midplane is now $ar^n-\frac{6b}{4(n+1)}r^{n+2}$.  The peak gradient is $anr^{n-1}-\frac{3b(n+2)}{2(n+1)}r^{n+1}$ and the peak sextupole $\dds{B_z}{r}$ is $an(n-1)r^{n-2}-\frac{3b(n+2)}{2}r^n$.  To make the sextupole zero at radius $r=R$, it is required that
\[ an(n-1)=\frac{3b(n+2)}{2}R^2 \qquad \Rightarrow \qquad b=\frac{2n(n-1)}{3(n+2)R^2}a. \]
This makes the peak dipole field at radius $r=R$ equal to
\[ aR^n-\frac{6}{4(n+1)}\frac{2n(n-1)}{3(n+2)R^2}aR^{n+2}
 = \left(1-\frac{n(n-1)}{(n+1)(n+2)}\right)aR^n \]
and the peak gradient at $r=R$ equal to
\[ anR^{n-1}-\frac{3(n+2)}{2(n+1)}\frac{2n(n-1)}{3(n+2)R^2}aR^{n+1} 
= \left(1-\frac{n-1}{n+1}\right)anR^{n-1}. \]

% The effective focussing from rapidly oscillating gradients is roughly <amplitude^2>, also look at dB(x,y)/dz on Cartesian axes (bunch isn't rotating)

\section{General Case}
Higher order polynomials may be useful for cancelling octupole and higher nonlinearities.  For odd $f(z)$, the field on the midplane is
\[ B_z(z=0) = \sum_{j=0}^{\infty} C_{nj} r^{n+2j} \sin(n\theta+\psi) f^{(2j+1)}(0). \]
The peak $i^\mathrm{th}$ radial derivative field is then
\[ B^{(i)}_{z,peak} = \sum_{j=0}^{\infty} C_{nj} \frac{(n+2j)!}{(n+2j-i)!} r^{n+2j-i} f^{(2j+1)}(0). \]
If $f(z)=\sum_{k=0}^K a_{2k+1}z^{2k+1}$ then $f^{(2j+1)}(0)=(2j+1)!a_{2j+1}$ for $j\le K$ and zero otherwise, giving
\[ B^{(i)}_{z,peak} = \sum_{j=0}^K C_{nj} \frac{(n+2j)!}{(n+2j-i)!} r^{n+2j-i} (2j+1)!a_{2j+1}. \]
Typically a radius $r=R$ will be chosen at which several ($K+1$) of the $B^{(i)}_{z,peak}$ are specified (e.g. nonzero gradient $i=1$, some higher multipoles zero).  The values of $R^n a_{2j+1}$ can be obtained by solving the linear system
\[ B^{(i)}_{z,peak} = \sum_{j=0}^K  \frac{(-\frac14)^j n!}{(n+j)!j!} \frac{(n+2j)!}{(n+2j-i)!}  R^{2j-i} (2j+1)!(R^na_{2j+1}). \]
The factor $R^n$ can be too large for the computer precision, so is included in the coefficient value.  The field can then be calculated with the rescaled formula
\[ \B = \left(\frac{r}{R}\right)^n \sum_{j=0}^{\infty} C_{nj} r^{2j-1} 
\vecthree{((n+j)\sin((n-1)\theta+\psi)+j\sin((n+1)\theta+\psi)) R^nf^{(2j)}(z)}{((n+j)\cos((n-1)\theta+\psi)-j\cos((n+1)\theta+\psi)) R^nf^{(2j)}(z)}{r \sin(n\theta+\psi) R^nf^{(2j+1)}(z)}. \]

\end{document}