\chapter{\textit{OPAL}-env} The \textit{OPAL-e} Envelope Tracker is an algorithm used to solve the envelope equations of a beam propagating through external fields and under the influence of its own space charge. The algorithm is based on the multi-slice analysis approach used in the theory of emittance compensation \ref{bib:JBong}. The space charge model used can be switched between an analytic model derived and used in HOMDYN \ref{bib:HOMY} and a similar model developed at PSI called Beam Envelope Tracker (BET). \subsection{Envelope Equation without Dispersion For Long Beams} The equation for the propagation of a general beam enveloped given here follows the work of Sacherer \ref{Sach}. Using the variables $x$ and $p_x$ as the phase space variables, the equation of motion for $\sigma_x = \langle x^2\rangle^{1/2}$ is found by differentiating with respect to time: % \begin{eqnarray} \dot\sigma_x = \frac{\langle x\dot x \rangle}{\sigma},\hspace{1cm} \ddot\sigma_x = \frac{1}{\sigma_x^3}\left[\langle x^2\rangle \langle \dot x^2\rangle-\langle x\dot x\rangle^2\right]+\frac{\langle x\ddot x\rangle}{\sigma_x} \end{eqnarray} % Noting that $\dot x = p_x/m\gamma$, the above equations become % \begin{eqnarray} \ddot\sigma_x = \frac{1}{\sigma_x^3}\left(\frac{c\epsilon_n}{\gamma}\right)^2+\frac{\langle x\ddot x\rangle}{\sigma_x}, \end{eqnarray} % where the normalized emittance is defined as $\epsilon_{n,x} = \frac{1}{mc}\sqrt{\langle x^2\rangle \langle p_x^2\rangle-\langle xp_x\rangle^2}$. The last term in this equation is expanded using $\ddot x = -\gamma^2\beta\dot\beta \dot x + F_x/m\gamma$: % \begin{eqnarray} \ddot\sigma_x = \left[-\gamma^2\beta\dot\beta\right]\dot\sigma_x + \frac{\langle xF_x\rangle}{m\gamma\sigma_x}+\left(\frac{c\epsilon_n}{\gamma}\right)^2\frac{1}{\sigma_x^3}, \end{eqnarray} % The force is split into a (linear) external part and the self-fields: $F_x(t,x) = -K_x(t)x + F_{x,s}$. Plugging this into the envelope equation gives % \begin{eqnarray} \ddot\sigma_x + \left[\gamma^2\beta\dot\beta\right]\dot\sigma_x + \left[\frac{K}{m\gamma}\right]\sigma_x = \left[\frac{\langle xF_{x,s}\rangle}{m\gamma}\right]\frac{1}{\sigma_x}+\left(\frac{c\epsilon_n}{\gamma}\right)^2\frac{1}{\sigma_x^3}. \end{eqnarray} % Following Sacherer \ref{Sach}, the term $\langle xF_{x,s}\rangle$ can be interpreted as the linear part of the space charge field (in a least squares sense). The linear part of the field is defined by $F_{x,s}^{(1)}$, such that the quantity % \begin{eqnarray} D = \langle (F_{x,s}^{(1)}x-F_{x,s})^2\rangle = \int (F_{x,s}^{(1)}x-F_{x,s})^2\rho_x\;\mathrm{d}x, \end{eqnarray} % is minimized in a least squares sense. This is accomplished by setting $\pdifferential{}D / \pdifferential{} F_{x,s}^{(1)} = 0$, which implies \ref{Sach}: % \begin{eqnarray} F_{x,s}^{(1)}x = \frac{\langle xF_{x,s}\rangle}{\sigma_x^2}x. \end{eqnarray} % This gives the general form of the envelope equation % \begin{eqnarray} \ddot\sigma_x + \left[\gamma^2\beta\dot\beta\right]\dot\sigma_x + \left[\frac{K}{m\gamma}\right]\sigma_x &=& \left[\frac{F_{x,s}^{(1)}}{m\gamma}\right]\sigma_x+\left(\frac{c\epsilon_n}{\gamma}\right)^2\frac{1}{\sigma_x^3}, \\ \sigma_x\nprimed{2} + \left[\frac{\gamma\primed}{\beta^2\gamma}\right]\sigma_x\primed + \left[\frac{K}{mc^2\beta p_n}\right]\sigma_x &=& \left[\frac{F_{x,s}^{(1)}}{mc^2\beta p_n}\right]\sigma_x+\left(\frac{\epsilon_n}{p_n}\right)^2\frac{1}{\sigma_x^3}. \end{eqnarray} % In this equation $p_n = \beta\gamma$ is the normalized momentum. A general form for the fields can be now introduced. For a long beam, the linear part of the fields (in the beam rest frame) are given by % \begin{eqnarray} E_x=\left( \left.\diffp{E_x}{x}\right|_{0}\right)x,\hspace{1cm}E_y= \left(\left.\diffp{E_y}{y}\right|_{0}\right)y. \end{eqnarray} % These fields must then be boosted back to the laboratory frame according to % \begin{eqnarray} \textbf{E}&=&\gamma(\textbf{E}\primed-\mathbf{\mathbf{\beta}}\times c\textbf{B}\primed)-\frac{\gamma^2}{1+\gamma}\mathbf{\beta}(\mathbf{\beta}\cdot \textbf{E}\primed), \\ \textbf{B}&=&\gamma(\textbf{B}\primed+\mathbf{\mathbf{\beta}}\times \textbf{E}\primed/c)-\frac{\gamma^2}{1+\gamma}\mathbf{\beta}(\mathbf{\beta}\cdot \textbf{B}\primed),\label{eq:FieldTrans} \end{eqnarray} % For a beam moving along the $z$-axis with speed $c\beta$, the fields are given by % \begin{eqnarray} \mathbf{E} = \gamma E_x\primed\hat{\mathbf{x}} + \gamma E_y\primed\hat{\mathbf{y}}, \hspace{2cm} \mathbf{B} = \frac{\gamma\beta}{c}(-E_y\primed\hat{\mathbf{x}} + E_x\primed\hat{\mathbf{y}}). \end{eqnarray} % Here the primes label the field components in the lab frame. Assuming these components are proportional to the line charge density $\lambda\primed$ the fields can be written in a form that takes into account the Lorentz contraction of the current density: % \begin{eqnarray} E_x = \gamma E_x\primed = \gamma\lambda\primed\diffp{E_x\primed}{\lambda\primed}=\lambda\diffp{E_x\primed}{\lambda\primed}. \end{eqnarray} % The linearized force equation then takes the form %\begin{eqnarray} %\mathbf{F} = e(E_r-\beta c B_{\theta})\hat{\mathbf{r}} = \frac{e\lambda}{\gamma^2}\left(\diffp{E_r\primed}{{r}{\lambda\primed}}\right) r\hat{\mathbf{r}} %\end{eqnarray} % \begin{eqnarray} \mathbf{F} &=& e(E_x-\beta c B_{y})\hat{\mathbf{x}} + e(E_y + \beta c B_{x})\hat{\mathbf{y}} %\\ %&=& = \frac{e\lambda}{\gamma^2} \left[ \left(\diffp{E_x\primed}{{x}{\lambda\primed}}\right) x \hat{\mathbf{x}}+ \left(\diffp{E_y\primed}{{y}{\lambda\primed}}\right) y \hat{\mathbf{y}} \right]. \end{eqnarray} % With this, the envelope equations become % \begin{eqnarray} \ddot\sigma_i + \left[\gamma^2\beta\dot\beta\right]\dot\sigma_i + \left[\frac{K_i}{m\gamma}\right]\sigma_i &=& \left[\frac{e\lambda}{m\gamma^3}\left(\diffp{E_i\primed}{{x_i}{\lambda\primed}}\right)\right]\sigma_i+\left(\frac{c\epsilon_{n,i}}{\gamma}\right)^2\frac{1}{\sigma_i^3}. % %\\ %\sigma_i\nprimed{2} + \left[\frac{\gamma\primed}{\beta^2\gamma}\right]\sigma_i\primed + \left[\frac{K_i}{mc^2\beta p_n}\right]\sigma_i &=& \left[\frac{e\lambda}{mc^2\beta^2 \gamma^3}\left(\diffp{E_i\primed}{{x_i}{\lambda\primed}}\right)\right]\sigma_i+\left(\frac{\epsilon_{n,i}}{p_n}\right)^2\frac{1}{\sigma_i^3}. \label{eq:GenEnv} \end{eqnarray} So far this derivation has assumed that there is no coupling between $x$ and $y$ in both the external and self forces. In the presence of solenoids this is no longer the case for the external fields. If the beam and external fields are cylindrical symmetric then the previous analysis can be performed in the Larmor frame. Working in the Larmor frame, the equations of motion for $\sigma_x =\sigma_y =\sigma_L$ decouple and the envelope equation is given by % \begin{eqnarray} \ddot\sigma_L + \left[\gamma^2\beta\dot\beta\right]\dot\sigma_L + \left[\frac{K}{m\gamma}+(\dot\theta_r)^2\right]\sigma_L &=& \left[\frac{e\lambda}{m \gamma^3}\left(\diffp{E_r\primed}{{r}{\lambda\primed}}\right)\right]\sigma_L+\left(\frac{c\epsilon_n}{\gamma}\right)^2\frac{1}{\sigma_L^3}. %\\ %\sigma\nprimed{2} + \left[\frac{\gamma\primed}{\beta^2\gamma}\right]\sigma\primed %+ \left[\frac{K}{mc^2\beta p_n} + (\theta_r\primed)^2\right]\sigma &=& %\left[\frac{e\lambda}{mc^2\beta^2 \gamma^3}\left(\diffp{E_r\primed}{{r}{\lambda\primed}}\right)\right]\sigma+\left(\frac{\epsilon_n}{p_n}\right)^2\frac{1}{\sigma^3}. \end{eqnarray} % In this expression, $\theta_r$ is the Larmor angle, and is given by % \begin{eqnarray} \theta_r = -\int\left(\frac{eB_z}{2m\gamma }\right)\;\mathrm{d}t = -\int\left(\frac{eB_z}{2m\gamma \beta c}\right)\;\mathrm{d}z. \end{eqnarray} \subsubsection{Long Uniform Cylindrical Beam} The envelope equation for a cylindrical beam is now explicitly derived. Assuming cylindrical symmetric fields and working in the Larmor frame then $\sigma_x = \sigma_y = \sigma_L$. It is important to distinguish this parameter from $\sigma_r = R/\sqrt{2}$. In fact, $\sigma_L = R/2$ for a circular beam. The electric in the lab frame can be easily computed from Gauss's law: % \begin{eqnarray} E_r\primed = \frac{1}{8\pi\epsilon_0}\frac{\lambda\primed}{\sigma^2}r \hspace{1cm} (r