\documentclass[letterpaper,  %a4paper
               %boxit,
               %titlepage,   % separate title page
               %refpage      % separate references
              ]{jacow}
%
% CHANGE SEQUENCE OF GRAPHICS EXTENSION TO BE EMBEDDED
% ----------------------------------------------------
% test for XeTeX where the sequence is by default eps-> pdf, jpg, png, pdf, ...
%    and the JACoW template provides JACpic2v3.eps and JACpic2v3.jpg which
%    might generates errors, therefore PNG and JPG first
%
\makeatletter%
	\ifboolexpr{bool{xetex}}
	 {\renewcommand{\Gin@extensions}{.pdf,%
	                    .png,.jpg,.bmp,.pict,.tif,.psd,.mac,.sga,.tga,.gif,%
	                    .eps,.ps,%
	                    }}{}
\makeatother

% CHECK FOR XeTeX/LuaTeX BEFORE DEFINING AN INPUT ENCODING
% --------------------------------------------------------
%   utf8  is default for XeTeX/LuaTeX 
%   utf8  in LaTeX only realizes a small portion of codes
%
\ifboolexpr{bool{xetex} or bool{luatex}} % test for XeTeX/LuaTeX
 {}                                      % input encoding is utf8 by default
 {\usepackage[utf8]{inputenc}}           % switch to utf8

\usepackage[USenglish]{babel}			 

\usepackage[final]{pdfpages}
\usepackage{multirow}
\usepackage{ragged2e}

%
% if BibLaTeX is used
%
\ifboolexpr{bool{jacowbiblatex}}%
 {%
  \addbibresource{jacow-test.bib}
  \addbibresource{biblatex-examples.bib}
 }{}
\listfiles

%
% command for typesetting a \section like word
%
\newcommand\SEC[1]{\textbf{\uppercase{#1}}}

%%
%%   Lengths for the spaces in the title
%%   \setlength\titleblockstartskip{..}  %before title, default 3pt
%%   \setlength\titleblockmiddleskip{..} %between title + author, default 1em
%%   \setlength\titleblockendskip{..}    %afterauthor, default 1em

%\copyrightspace %default 1cm. arbitrary size with e.g. \copyrightspace[2cm]

% testing to fill the copyright space
%\usepackage{eso-pic}
%\AddToShipoutPictureFG*{\AtTextLowerLeft{\textcolor{red}{COPYRIGHTSPACE}}}

\begin{document}

\title{Production of Low Cost, High Field Quality Halbach Magnets}

\author{S.J. Brooks\thanks{sbrooks@bnl.gov}, G. Mahler, J. Cintorino, A.K. Jain,\\ Brookhaven National Laboratory, Upton, Long Island, New York}
	
\maketitle

%
\begin{abstract}
A shimming method has been developed at BNL that can improve the integrated field linearity of Halbach magnets to roughly 1 unit (1 part in $10^4$) at r=10mm.  Two sets of magnets have been produced: six quadrupoles of strength 23.62T/m and six combined-function (asymmetrical) Halbach magnets of 19.12T/m with a central field of 0.377T.  These were assembled using a 3D printed plastic mould inside an aluminium tube for strength.  A shim holder, which is also 3D printed, is fitted within the magnet bore and holds iron wires of particular masses that cancel the multipole errors measured using a rotating coil on the unshimmed magnet.  A single iteration of shimming reduces error multipoles by a factor of 4 on average.  This assembly and shimming method results in a high field quality magnet at low cost, without stringent tolerance requirements or machining work.  Applications of these magnets include compact FFAG beamlines such as FFAG proton therapy gantries, or any bending channel requiring a $\sim$4x momentum acceptance.  The design and shimming method can also be generalised to produce custom nonlinear fields, such as those for scaling FFAGs.
\end{abstract}


\section{Requirements}

The magnets were designed as prototypes for an earlier version of the CBETA \cite{CBETA} lattice, a non-scaling FFAG arc of radius $\sim$5m transmitting 67--250MeV electrons.  Table~\ref{params} shows the required fields and sizes.  The CBETA magnets were going to be twice the length of these prototypes with two layers of permanent magnets (PMs) longitudinally.
% Could explain QF and BD and fact they are centered around beams
\begin{table}[hbt]
   \centering
   \caption{Parameters of the Two Magnet Types}
   \begin{tabular}{lccc}
       \toprule
       \textbf{Parameter} & \textbf{QF} & \textbf{BD} & \textbf{units} \\
       \midrule
Length&57.44&61.86&mm\\
Dipole $B_y(x=0)$&0&0.37679&T\\
Quadrupole $dB_y/dx$&23.624&-19.119&T/m\\
Bore radius to PMs&37.20&30.70&mm\\
...to shim holder&34.70&27.60&mm\\
Max field at PMs&0.879&0.964&T\\
Max field at r=1cm&0.236&0.568&T\\
Outer radius of PMs&62.45&59.43&mm\\
...of tubular support&76.2&76.2&mm\\
       \bottomrule
   \end{tabular}
   \label{params}
\end{table}
% These are parameters for the prototypes including the "Hall probe sign error", this is consistent with the figures

\section{Magnet Design}
The magnets are based on a 16-segment Halbach design (Fig.~\ref{magQF}).  For the combined-function magnet `BD' (Fig.~\ref{magBD}), the wedge thicknesses and magnetisation angles were optimised to give the combined field directly.  This uses less PM material than nesting a Halbach dipole and quadrupole.

\begin{figure}[!htb]
   \centering
   \includegraphics*[width=\linewidth]{THPIK007f1}
   \caption{Cross-section of the quadrupole `QF' magnet.  Blue arrows show magnetisation direction of the PM blocks.  The orange line graphs the mid-plane field $B_y(x,0)$, with green highlighting the good field region and red showing the beam position range in the FFAG.  The grid has 1cm spacing.}
   \label{magQF}
\end{figure}

\begin{figure}[!htb]
   \centering
   \includegraphics*[width=\linewidth]{THPIK007f2}
   \caption{Cross-section of the BD magnet.}
   \label{magBD}
\end{figure}

\newcommand{\B}{\mathbf B}
\newcommand{\Jv}{\mathbf J}
\newcommand{\jv}{\mathbf j}
\newcommand{\M}{\mathbf M}
\newcommand{\Div}{\nabla\cdot}
\newcommand{\curl}{\nabla\times}
\newcommand{\nhat}{\hat{\mathbf n}}
\newcommand{\vectwo}[2]{\left[\begin{array}{c}#1\\#2\end{array}\right]}
The field calculation for this design starts with Maxwell's magnetostatic equations in a material:
\[ \Div\B=0 \qquad \curl\B=\mu_0(\Jv+\curl\M). \]
It is approximated that the magnetisation $\M$ does not vary with applied field, i.e. that the PM material has $\mu_r=1$.  It is also assumed that each PM block has a constant $\M$ vector.  This means that on a boundary with outward unit normal $\nhat$, the magnetisation is equivalent to a surface current
\[ \jv_s = -\nhat\times\M. \]
Each edge of a polygonal PM block therefore produces a sheet current, which in the 2D approximation extends infinitely in $z$.  Such a sheet with current $j_s$ travelling from $(0,0)$ to $(a,0)$ produces a field 
\[ \B(x,y)=\frac{\mu_0j_s}{2\pi}\vectwo
{-\arctan(x/y)+\arctan((x-a)/y)}
{\frac12(\log(x^2+y^2)-\log((x-a)^2+y^2))}, \]
which can be rotated and summed over all PM block edges.

The strength is set via $\mu_0|\M|=B_{r1}$, where $B_{r1}$ is an approximation to the true remnant field $B_r$ of the material.  A value $B_{r1}<B_r$ is used to compensate for the fact that $\mu_r\simeq1.02$--$1.05$ in reality, which reduces $|\M|$.  This tuning was done by benchmarking against an OPERA-3D simulation using the manufacturer's B-H curve.  The magnet was made using AllStar Magnetics grade N35SH, which is quoted to have $B_r=1.17$--$1.22$T and simulations used $B_{r1}=1.1939$T.

\subsection{Multipole Cancellation with Iron Wires}
When an iron `wire', infinite in $z$ with a small circular cross-section, is inserted into a locally uniform magnetic field $\B_0$, it becomes magnetised with $\M=2\B_0$, assuming perfect iron with $\mu_r=\infty$.  The equivalent surface currents are that of a ``$\cos\theta$'' dipole, so the external field generated is
\[ \B_\mathrm{wire}(x,y)=\frac{r_\mathrm{wire}^2}{(x^2+y^2)^2}\vectwo
{B_{0x}(x^2-y^2)+B_{0y}2xy}
{B_{0x}2xy+B_{0y}(y^2-x^2)}. \]
Assembled magnets such as those in Figs. \ref{photoQF} and \ref{photoBD} were measured on BNL's rotating coil and the observed errors added on to the 2D field model.  Then between 32 and 64 iron wires were added to the simulation just inside the magnet bore and their radii optimised in order to reduce the harmonic errors to zero again, which was achieved almost exactly when wires up to 63mil (1.6mm) diameter were allowed.

The optimiser (for both the wedges in the BD magnet and the iron wire radii) is based on an SVD decomposition of the linear response matrix of the simulated harmonic errors to small changes in the magnet.  The note \cite{SVDnote} describes how to pseudo-invert such a rectangular matrix with a parameter to control the `level of detail' of the inversion, from a local gradient descent to a full inverse.  This parameter was chosen at each iteration to give the biggest improvement in field harmonics after a line search.  By choosing different goal harmonics, magnets with nonlinear fields such as those for scaling FFAGs can be produced by the same process.

%\begin{figure}[!htb]
%   \centering
%   \includegraphics*[width=\linewidth]{fig25}
%   \caption{/**/}
%   \label{magexotic}
%\end{figure}

\section{Magnet Construction}
The PM wedges were hammered in to a 3D printed mould of the outer shape of each magnet, which in turn was fitted inside a 6'' OD/$\frac14$'' thick aluminium pipe, since the PLA plastic would warp slightly without extra support.  On the inside, the wedges jam to form a self-supporting `circular arch', so no additional support is needed (Figs. \ref{photoQF} and \ref{photoBD}).

\begin{figure}[!htb]
   \centering
   \includegraphics*[width=\linewidth]{THPIK007f3}
   \caption{QF magnet without iron wires.}
   \label{photoQF}
\end{figure}

\begin{figure}[!htb]
   \centering
   \includegraphics*[width=\linewidth]{THPIK007f4}
   \caption{BD magnet without iron wires.}
   \label{photoBD}
\end{figure}

The iron wires were 1006-1008 carbon steel supplied in 1ft straight lengths.  Once the desired radii were calculated, they were converted to lengths of the next largest wire grade (from 14, 18, 35, 41, 63mil) having the same volume as an ideal-radius wire the full length of the magnet.  3D printing was also used to produce a holder to confine the wires, which was fitted inside the magnet bore (see Fig.~\ref{ironwires}).

\begin{figure}[!htb]
   \centering
   \includegraphics*[width=\linewidth]{THPIK007f5}
   \caption{QF with iron wires and plastic holder inserted.}
   \label{ironwires}
\end{figure}

The QF and BD magnets cost \$1,070 and \$779 each respectively, as broken down in Table~\ref{cost}.

\begin{table}[hbt]
   \centering
   \caption{Cost of Magnet Components}
   \begin{tabular}{lcc}
       \toprule
       \textbf{Cost per magnet} & \textbf{QF} & \textbf{BD} \\
       \midrule
PM pieces & \$1,052.67 & \$758.00 \\
3D printer plastic & \$3.71 & \$6.19 \\
Iron wires (max.)& \$3.42 & \$3.68 \\
Aluminium tube& \$10.53 & \$11.34 \\
       \midrule
       \textbf{One-time costs} & & \textbf{Brand/supplier} \\
       \midrule
3D printer & \$2,499.00 & Ultimaker 2+ \\
1kg plastic spool & \$34.00 & 3D Universe PLA \\
Iron wire batch & \$54.64 & McMaster-Carr \\
1ft aluminium tube & \$55.88 & OnlineMetals.com \\
       \bottomrule
   \end{tabular}
   \label{cost}
\end{table}

\section{Field Quality}
Many field harmonics can be present in a magnet, so an overall figure of merit (FOM) $\sqrt{\sum_{n\ge\mathrm{sextupole}}a_n^2+b_n^2}$ was defined, which is at least as large as any nonlinear multipole error.  The coil gave readings at a standard radius of 10mm and the FOMs are plotted in Fig.~\ref{FOMs}.  The shimmed QF magnets ranged from 1.22--3.41 units and the shimmed BDs from 3.50--8.68.  The actual FFAG beam orbits would be up to R$\simeq$20mm in QF, where the FOMs are 5.9--13.8 units.  Fig.~\ref{FOMs} also shows an earlier R\&D PM quadrupole magnet ``5A'', where the iron wires were calculated a second time based on the measured harmonics of the first iteration.  The continued improvement suggests the other magnets could also approach the 1 unit ($10^{-4}$) level.

%? example rotating coil result?

\begin{figure}[!htb]
   \centering
   \includegraphics*[width=\linewidth]{THPIK007f6}
   \caption{Total multipole errors of the magnets at R=10mm.}
   \label{FOMs}
\end{figure}

Fig.~\ref{quaderrors} shows the absolute strength of the quadrupole component of the magnets relative to the intended value.  

The NdFeB material has a temperature coefficient of $-1.1\times10^{-3}$ and no attempt was made to temperature control the magnet or measurement area, so variations on this few $10^{-3}$ scale are as expected.  Water cooling will be used to stabilise the temperature of this type of magnet in CBETA.

\begin{figure}[!htb]
   \centering
   \includegraphics*[width=\linewidth]{THPIK007f7}
   \caption{Errors in quadrupole strength relative to design.}
   \label{quaderrors}
\end{figure}


\section{Conclusion}
The magnets described are compact, lightweight, cheap, easy to produce, have improving field quality and require no power supply.  The disadvantages are the temperature coefficient and demagnetisation if subjected to high radiation.  Finding a scheme to add Ni-Fe alloy to cancel the temperature coefficient is an interesting line of future study.
% Radiation less of an issue if use SmCo


\begin{thebibliography}{9} % Use for 1-9 references
\bibitem{CBETA} I.~Bazarov \emph{et al.}, ``The Cornell-BNL FFAG-ERL Test Accelerator: White Paper,'' arXiv:1504.00588 [physics.acc-ph].
\bibitem{SVDnote} S.J.~Brooks, ``Bounded Approximate Solutions of Linear Systems using SVD,'' note available from \url{http://stephenbrooks.org/ap/report/2015-3/svdboundedsolve.pdf}
\\
\end{thebibliography}


\end{document}
	