# Three-Dimensional, Time-Dependent Analysis of High- and Low-\(Q\) Free-Electron Laser Oscillators
## 2 Numerical Formulation
### The MINERVA Simulation Code
Within the slowly varying phase and amplitude approximation, the evolution of the normalized mode amplitudes \(\delta a_{l,n,h}^{(i,j)}(z,t)\) is given by  
\[\frac{d}{dz} \begin{pmatrix}\delta a_{l,n,h}^{(1,j)}(z,t)\\ \delta a_{l,n,h}^{(2,j)}(z,t)\end{pmatrix} +K_{l,n,h}^{(j)}(z) \begin{pmatrix} \delta a_{l,n,h}^{(2,j)}(z,t)\\ -\delta a_{l,n,h}^{(1,j)}(z,t)\end{pmatrix} = \begin{pmatrix}S_{l,n,h}^{(1,j)}( z,t)\\ S_{l,n,h}^{(2,j)}(z,t)\end{pmatrix} , \tag{5}\]where \(d/dz\) is the convective derivative and \(K^{(j)}_{l,n,h}(z,t)\) is given by  
\[K^{(j)}_{l,n,h}(z,t)=(1+l+n)\left[\frac{\alpha_{h}^{(j)}(z,t)}{w_{h}^{(j)}(z,t)} \frac{dw_{h}^{(j)}(z,t)}{dz}-\frac{1}{2}\frac{d\alpha_{h}^{(j)}(z,t)}{dz}-\frac{ 1+(\alpha_{h}^{(j)}(z,t))^{2}}{k_{0}(w_{h}^{(j)}(z,t))^{2}}\right]. \tag{6}\]  
The source terms \(S^{(i,j)}_{l,n,h}(z,t)\) in Equation (5) are given by  
\[ \begin{pmatrix}S^{(1,j)}_{l,n,h}(z,t)\\ S^{(2,j)}_{l,n,h}(z,t)\end{pmatrix} =\frac{1}{\pi}\frac{\omega_{b}^{2}}{k_{0}c^{ 2}}\frac{1}{2^{l+n-1}}\frac{1}{l!n! }\frac{1}{(w_{0,h}^{(j)})^{2}}\Bigg{\langle} e^{(j)}_{l,n,h}(\mathbf{x})\frac{v_{j}(z,t)}{|v_{z}(z,t)|} \begin{pmatrix}- \cos(\varphi_{h}^{(j)}(z,t))\\ \sin(\varphi_{h}^{(j)}(z,t))\end{pmatrix} \Bigg{\rangle}, \tag{7}\]  
where \(\omega_{b}\) is the nominal plasma frequency, \(v_{j}\) is the component of the electron velocity in direction \(j\), \(v_{z}\) is the longitudinal velocity component and \(\langle(\dots)\rangle\) is an average over the electron distribution given by  
\[ \begin{split}\langle(\dots)\rangle=\\ \int_{0}^{2\pi}\frac{d\psi_{0}}{2\pi}\int_{1}^{\infty}\frac{d \gamma_{0}}{\sqrt{\pi/2}\Delta\gamma}\frac{e^{-(\gamma_{0}-\gamma_{\rm avg})^{ 2}/2\Delta\gamma^{2}}}{1+\text{erf}(\gamma_{\rm avg}/\sqrt{2}\Delta\gamma)} \iint\frac{dx_{0}dy_{0}}{2\pi\sigma_{r}^{2}}\iint\frac{dp_{x0}dp_{y0}}{2\pi \sigma_{p}^{2}}e^{-r^{2}\Delta\tau_{r}^{2}}e^{-p_{\perp 0}^{2}/2\sigma_{p}^{2}}( \dots).\end{split}  \tag{8}\]  
In Equation (8), \(\gamma_{\rm avg}\) and \(\Delta\gamma\) are the relativistic factors corresponding to the initial average electron energy and energy spread, and \(\sigma_{r}\) and \(\sigma_{p}\) describe the width of the initial distribution function in transverse and momentum phase space, respectively. The particle distribution described by Equation (8) is supplemented in the simulation code MINERVA, with methods to import 6-dimensional particle distributions which may be obtained from various sources, such as electron beam transport models, and this allows full start-to-end simulation capabilities. To minimize the number of modes required to accurately describe the amplified optical field within the undulators, the so-called source dependent expansion [193] is used. Within this approximation, the spot size and curvature of the eigenmodes for each of the polarization directions \(j=x,y\) are allowed to evolve according to  
\[\frac{dw_{h}^{(j)}(z,t)}{dz}=\frac{2\alpha_{h}^{(j)}(z,t)}{hk_{0}w_{h}^{(j)}(z, t)}-w_{h}^{(j)}(z,t)Y_{h}^{(j)}(z,t) \tag{9}\]  
and  
\[\frac{1}{2}\frac{d\alpha_{h}^{(j)}(z,t)}{dz}=\frac{1+(\alpha_{h}^{(j)}(z,t))^{ 2}}{hk_{0}(w_{h}^{(j)}(z,t))^{2}}-X_{h}^{(j)}(z,t)-\alpha_{h}^{(j)}(z,t)Y_{h}^ {(j)}(z,t), \tag{10}\]  
where  
\[ \begin{split}& X_{h}^{(j)}(z,t)=\\ &\frac{2}{(\delta a_{0,0,h}^{(j)}(z,t))^{2}}\Big{[}\Big{(}S^{(1,j) }_{2,0,h}(z,t)+S^{(1,j)}_{0,2,h}(z,t)\Big{)}\delta a_{0,0,h}^{(1,j)}(z,t)- \Big{(}S^{(2,j)}_{2,0,h}(z,t)+S^{(2,j)}_{0,2,h}(z,t)\Big{)}\delta a_{0,0,h}^{( 2,j)}(z,t)\Big{]}\\ &\qquad\qquad\text{and}\\ & Y_{h}^{(j)}(z,t)=\\ &-\frac{2}{(\delta a_{0,0,h}^{(j)}(z,t))^{2}}\Big{[}\Big{(}S^{(1,j )}_{2,0,h}(z,t)+S^{(1,j)}_{0,2,h}(z,t)\Big{)}\delta a_{0,0,h}^{(1,j)}(z,t)+ \Big{(}S^{(2,j)}_{2,0,h}(z,t)+S^{(2,j)}_{0,2,h}(z,t)\Big{)}\delta a_{0,0,h}^{( 2,j)}(z,t)\Big{]}.\end{split}  \tag{11}\]Furthermore, in Equations (11) and (12), \((a_{0,0,h}^{(j)}(z,t))^{2}=(a_{0,0,h}^{(1,j)}(z,t))^{2}+(a_{0,0,h}^{(2,j)}(z,t))^{2}\).