A Super-Fast Free-Electron Laser Simulation Code for Online Optimization

: The X-ray free-electron lasers (FELs) have stimulated the growing interest of researchers in different ﬁelds. This gives rise to an increasing simulation work of design and optimization of FEL facilities and demonstrations of novel FEL ideas. Most of the multi-dimensional simulation codes in use require large computational resources, while one-dimensional simulation codes can merely give an acceptable description of the FEL ampliﬁcation process. This paper presents the development of a super-fast time-dependent FEL simulation code, which is mainly designed for seeded FEL and its application on a seed FEL facility. The diffraction factors have been introduced in order to model the effects of radiation ﬁeld diffraction and drastically simpliﬁed the working equations. Meanwhile, a specially designed module for seeded FEL has been added in order to study the laser-electron beam interactions with arbitrarily parameters. The code can also provide a fairly accurate, quasi-real-time assistant tool for online optimization.


Introduction
The X-ray free-electron laser (FEL) has been recognized as a unique X-ray source of choice for experts when exploring the structures and dynamics of atomic and molecular systems at femtosecond time scales. It has been widely adopted in the fields of physics [1], chemistry [2], and biology [3], due to its ultra-high intensity and ultra-fast time structure. With growing interests in FEL applications, increasing FEL facilities have been constructed and novel FEL ideas have been proposed in the last decades, leading to a growing demand for FEL simulations.
An increasing number of numerical models and simulation codes of the FEL have been developed since the late 1990s. The commonly used multi-dimensional FEL codes can be roughly categorized as slowly varying envelope approximation (SVEA) simulation codes (GENESIS 1.3 [4], GINGER [5], FAST [6], RON [7], SIMPLEX [8], MINERVA [9]), and particle-in-cell (PIC) simulation codes (Puffin [10]). The SVEA assumes that the radiation field is represented by a slowly-varying amplitude and phase with a fast oscillatory term. The averaging of the field envelope will obviate the need for calculating this rapid sinusoidal oscillation and simplifying the field equation. In contrast, the PIC codes do not average the Maxwell's equation over the undulator period. Instead, it integrates the Newton-Lorentz equations for the particles and it is considered to be a more fundamental model of FEL physics. It is capable of analyzing effects with a broader bandwidth that cannot be modelled easily in SVEA, but it requires more computational resources.
While these codes have been used successfully to model the FEL process and they have been extensively benchmarked against each other and experiments [11][12][13], nearly all of them are rather time-consuming when optimizing FEL performances with the method of advanced optimization algorithms [14,15]. These methods require performing FEL simulations over ten thousand times, which would take couple of days or even longer when time-dependent results are expected. SIMPLEX is comparatively fast and user-friendly, but it is still somewhat of inconvenient since it is packaged.
Some one-dimensional (1D) simulation codes have been developed in order to reduce computation time (Perave [16], Perseo [17], AURORA [18], and so on [19,20]). Nevertheless, most of them omit significant effects of the diffraction of radiation, leading to an unacceptable increase of FEL power.
In this paper, the development of a super-fast time-dependent FEL simulation code, named FALCON, and its applications on the Shanghai soft X-ray FEL facility (SXFEL), have been reported. The code is especially designed for seeded FEL. The radiation field is calculated by 1D equation with the consideration of diffraction effects. This significantly reduces the computing requirements and it still gives an acceptable description of the FEL amplification process. Another important motivation in this code is to model different FEL schemes. Specifically, the laser-electron beam interaction module enables simulations for various kinds of seeded FEL schemes with arbitrary user-defined laser parameters, such as the incidence angle, transverse, and longitudinal distributions. The time-dependence effects are analyzed using the 'slice' model and the electron slips one wavelength behind the EM wave while traveling one undulator period.
It should be noted that the primal aim for this simulation code is to provide a fairly accurate, flexible, and computational-time-saving tool that can be used to give guidance on the online optimization of FEL facilities or fast optimization of FEL parameters and to give an estimation of the FEL performance for theoretical researches.

The Initial Particle Generation from Shot-Noise
Macro particles are introduced in order to represent the electron beam in all dimensions of the 6D phase space (x, y, p x , p y , θ, γ). For convenience, the transverse momenta are normalized to mc while assuming v z = c.
Although a random distribution would be the most straightforward way to generate initial particles, a loading strategy is typically used to reduce the number of macro particles. It can reduce the computing time while keeping the numerical noise under the acceptable level.
The initial particle phase space is generated by the Hammersley sequences [21]. The electron phase is uniformly generated, while the electron energy and transverse variables are subject to Gaussian distribution by adopting the 'Box-Muller' transformation [22]. With this method, the correlation between the longitudinal variables, electron phase (θ), and electron energy (γ) has been completely removed.
In order to correctly simulate the initial fluctuation in the longitudinal position, special care has to be taken for the modification of electron phase θ [23][24][25]. The most common method is to group several macro particles into a beamlet. Subsequently, a small variation in the evenly distributed longitudinal position θ is applied. In this simulation code, the quite loading algorithm is implemented, as in Equation (1) θ n = θ n,ini + A n sin(θ n,ini + φ n ). (1) The indices presentted in θ n on the right side of the equation represent the initial electron phase before introducing the loading strategy. A random shot-noise of its amplitude and phase, for the nth beamlet, is obtained by A n = 2 − ln(x n )/N and φ n = 2πy n , where x n and y n are independent uniform random numbers and N denotes the total number of electrons.

The FODO Lattice and Undulator Tapering
Although the full FODO dynamics can be incorporated into numerical simulations, some additional approximations are made in order to simplify the integration process and improve the algorithmic efficiency.
The true dynamics in the FODO lattice can be satisfied by approximating the particle trajectories by the simply harmonic motion for smooth focusing, as implied by the fact that the transverse motion is governed by the second-order differential equations. For this reason, the effect of FODO lattice is approximated by a smooth focusing field whose focusing strength (oscillator frequency) k β equals to 1/β x [26], where the β is the average beta-function that is defined by the FODO structure. Although the electron trajectories under such an approximation can only roughly mimic those of the FODO lattice, it can give quite accurate predictions in terms of FEL radiation characteristics [26]. This is because these radiation characteristics rarely depend on a single electron, but rather on the average features of the entire electron beam.
The undulator tapering is another issue when it comes to the FEL simulations. Linear taper, quadratic taper, and fully customized taper are provided in FALCON.

Modulator and Dispersion Section
FALCON provides two methods for analyzing the energy modulation: 'Fast sinusoidal modulation' and 'single-particle tracking modulation'. The latter one makes it possible to model the laser-electron beam interaction with an arbitrary incidence angle and field distributions.

Fast Sinusoidal Modulation
The effects of modulation and dispersion section on the phase space are specified as Equation (2) [27]: where p j = (γ j − γ 0 )/σ γ 0 denotes the dimensionless energy deviation of jth particle, ζ j = 2πθ j is the dimensionless longitudinal coordinate for jth particle, and A = ∆E/σ E and B = (R 56 ω s σ γ )/(cγ 0 ) denote the energy modulation amplitude and dimensionless dispersion strength, respectively.

Single-Particle Tracking Modulation
A special modulator section has been introduced in order to model the laser-electron beam interaction with arbitrary parameters. The energy exchange due to the electron-radiation interaction can be calculated as where β and E s are the normalized velocity of the electron beam and the transverse electric field of seed laser, respectively. The instantaneous change of electron velocity that is caused by Lorentz force is where B u and B s are the undulator magnetic field and transverse magnetic field of seed laser, respectively. The general electric field of seed laser is E s = E x i x + E y i y . The transverse components, E x and E y , can be written as [28]: where Φ x = k s (z 0 cosφ + y 0 sinφ), Φ y = k s (z 0 cosφ + x 0 sinφ), and φ denotes the oblique incidence angle of the seed laser. Instead of averaging over the undulator period, each undulator period has been divided into N n steps. Integrating over the entire undulator length with the Equations (3)-(5), various kinds of seeded FEL schemes with arbitrary user-defined laser parameters, such as the incidence angle [28], transverse, and longitudinal distributions (that are especially important for the modulation with few-cycle laser pulses), can be performed.

Radiation Diffraction
The main three-dimensional (3D) effect that tends to inhibit the FEL gain process over those in one-dimensional (1D) simulation is the radiation field diffraction. Because this code is mainly designed for seeded FEL, a simple algorithm has been implemented to solve this problem in FALCON.
For seeded FELs, the transverse distribution of the radiation field is generally Gaussian. The electric field in phasor notation is given by: where E 0 denotes the original field amplitude that is calculated by the input power of radiation field, ω 0 is the beam radius, R(z) denotes the radius of curvature of the beam wavefronts at z, and ω(z) is the beam width at z, which is shown as Equation (7): and z R = πω 2 0 /λ s is the Rayleigh length of the seeding radiation field. When the radiation field propagating one integration step size ∆z, no field is generated by electrons and, therefore, the field propagates in free space. The field radius should increase by a factor of χ r , while the amplitude is expected to decrease by a factor of χ amp . The two factors are equivalent to where ).
The bending of the wavefronts is another factor that worth mentioning during the field propagation. A numerical calculation has been carried out based on Equation (6). For typical FEL simulations, the electron beam radius is less than 100 µm and the FEL Pierce parameter, denoted as ρ, is less than 0.001. Taking the SXFEL as an example, the radiation wavelength and the undulator period are 8.8 nm and 2.35 cm. respectively. The Rayleigh length is 15 m and the FEL gain length, denoted as L gain , can be approximated by λ µ /4π √ 3ρ. The field phase difference between the central and edge of the electron beam at z = L gain is 1.9 • . Normally, the electron beam radius is smaller than 100 µm and the field phase difference will drastically decrease as the electron beam radius decreases. Various examples have been considered and it is safe to conclude that the field phase difference between the central and the edge of the electron beam after one FEL gain length is smaller than 3 • . Therefore, practically, the field phase differences that are caused by the bending of the wavefronts can be ignored in this research.
In FALCON, the factors χ r and χ amp are involved in modifying the radiation field in every integration step. Such modifications can partially solve the diffraction effects in the FEL process. Figure 1 shows the FEL power gain curves with and without these diffraction modifications under the conditions of different electron beam energies and corresponding FEL wavelengths. In this figure, the blue lines and red lines represent the FEL power with and without diffraction modifications, respectively. The black stars indicate the saturation points that are calculated by Xie's formulas [29]. The errors of saturation power and saturation length are approximately 10%, showing significant improvements as compared to those without diffraction modifications.
Additionally, the radiation field equation that is based on SVEA can be derived from Ref. [30]: In FALCON, the diffraction effect is modelled, as described in Section 2.4, and the diffraction term, ∇ 2 ⊥ , has been accordingly dropped to simplify the radiation field equation and increase the computation efficiency. Therefore, the radiation field equation is simplified as where I 0 denotes the beam current, A tr is the beam cross section that equals to 2πσ 2 e , and µ 0 is the vacuum permeability. After each integration step, the amplitude of radiation field has been modified by the diffraction factor, χ amp . It is worth noting that there is no explicit dependence on t in the differential equation. The time-dependence effects are analyzed while using the 'slice' model.  Table 1 shows the simulation parameters. The electron beam energy is 15 GeV with a relative slice energy spread of 10 −4 . The normalized emittance of the electron beam is about 0.3 mm · mrad and the peak current is about 4000 A. The electron bunch length is approximately 60 fs (FWHM). The undulator period is 3 cm with a normalised undulator parameter of 2.178. The FEL radiation wavelength is 0.1 nm.  The emitted pulse energies are about 1.83 mJ in GENESIS and 1.47 mJ in FALCON at the first saturation points. The difference in the power level of these codes seems apparent. The saturation length of FALCON is shorter than that of GENESIS, while the saturation powers are in line with each other. According to the assumption proposed in Section 2.4, a lack of mode competition process is probably responsible for the shortening of saturation length. Although FALCON is mainly designed for seeded FELs, the longitudinal properties for the SASE mode show good consistency between these two codes. Significantly, the simulation time is approximately 200 times longer in GENESIS 1.3 (more than 4 h) than in FALCON (less than 2 min) while using the same computer (Inter(R) Core(TM) i7-6700 CPU@3.4GHz).

Example Simulations
The echo-enabled harmonic generation (EEHG) [27] is chosen as an example to show the typical simulation capabilities of FALCON. The example is not exhaustive at all. However, FALCON can be easily modified and extended to meet researchers' various requirements. Table 2 lists the simulation parameters. The electron beam energy is 840 MeV, with a slice energy spread of about 50 keV. The normalized emittance is 1.5 mm · mrad and the peak current is 800 A. The FEL radiation wavelength is 8.8 nm, which is the 30th harmonic of the seed laser. The seed laser pulse that is used in the simulation is about 1 ps (FWHM), which is much longer than the electron bunch length of about 320 fs (FWHM). The energy modulation amplitudes in the modulator 1 and 2 are chosen to be A 1 = 4 and A 2 = 2, respectively. The optimized dispersion strengths for the 30th harmonic are found to be B 1 = 16.35 and B 2 = 0.56, corresponding to R (1) 56 = 11.58 mm and R (2) 56 = 0.40 mm, respectively. The undulator period is 23.5 cm with a normalised undulator parameter of 1.012.
The bunching factor at 30th harmonic of the seed is around 12% at the entrance of the radiator. Figure 3 shows the FEL power along radiator, FEL power profile, and spectrum at saturation. The pulse energies at saturation are 108.62 µJ and 118.88 µJ in GENESIS and FALCON, respectively.
For the seeded FEL operation mode, the seed laser should propagate co-axially with the electron beam in the modulator in order to ensure the formation of the desired microbunch. However, the drift of laser incident angle due to the mechanical vibration or the transverse position instability of the seed laser will bring about a small angle between the propagation direction of seed laser and electron beam. Such obliquely incident laser brings not only energy modulations, but also angular modulations [28]. Figure 4a,b demonstrate the transverse divergences (∆y ) and energy deviations (∆δ = ∆γ/γ) after the first modulator with incident angle of 1 mrad in the z − y plane. Figure 4c illustrates the influences of seed laser incident angle on the bunching factor and saturation power. For simplicity, the vertical laser angular drifts in both modulators are assumed to be the same. It can be seen from Figure 4c that the bunching factor at the entrance of the radiator and the saturation power decrease drastically as the incident angle increases.

Implementation at SXFEL
The primal target of this simulation code is to provide an assistant optimization tool at the Shanghai Soft X-ray FEL facility (SXFEL) [31], which aims at generating the soft X-ray radiation from a conventional seed laser through the frequency up-conversion scheme. An X-band RF deflector and a dipole magnet have been installed downstream of the undulator section, which provide a diagnostic tool for obtaining the image of time-energy longitudinal phase space of the electron beam [32]. In this section, the experiment and simulation results for the HGHG scheme at the SXFEL have been shown to demonstrate the feasibility of FALCON as an assistant online optimization tool.
The electron beam parameters can be acquired by FALCON through various diagnostic tools in real time. This enables FALCON to provide real-time predictions on the FEL performance and make comparisons between the measurements and simulations in order to analyze the experimental phenomena. The "lasing-off" longitudinal phase space images from the experiment are collected by turning off the seed laser. An example is shown in Figure 5, with the x-axis corresponding to energy and y-axis corresponding to time. The beam current (red line), central energy (black line), and energy spread (orange line) along the time axis can be derived from the image, as shown in the figure. These parameters combined with calibrated time can be used in order to generate realistic electron beam input file for FALCON. Figure 6 shows one of the possible applications of FALCON. The longitudinal phase spaces on the screen after lasing through the experiment, GENESIS simulations, and FALCON simulations are presented in Figure 6a-c. The induced additional energy spread leaves a conspicuous imprint of the FEL radiation on the longitudinal phase space. Shouldering the main peak, there are two small sidebands that have been observed during the experiment and simulations. By analyzing the real-time simulation results, this part of electron beam developed very strong microbunching after lasing in the radiator, which was overbunched by the following chicane and emitted 266 nm coherent radiation in the downstream magnets. With these phase spaces, the longitudinal proprieties of FEL pulses can be determined by the method that was proposed in Refs. [33,34]. Figure 6d shows the reconstructed and simulated power profiles of FEL pulses. The pulse energies are about 16.22 µJ, 16.58 µJ and 17.71 µJ in experiment, GENESIS, and FALCON, respectively.  It is notable that the way we use FALCON for on-line optimization is not to calculating every single shot. Instead, it plays a useful role in commissioning and operating the FEL machine under specific circumstances. FALCON can help researchers to simultaneously estimate some FEL properties (like pulse energy and spectrum) with the realistic parameters of the electron beam (import from the emittance and longitudinal phase space measurements) and give the correlation analysis. Moreover, FALCON can give some valuable information, even without the specific diagnostics tools. For example, the code can be applied in order to estimate the possible longitudinal phase space after lasing when a combination of the RF deflector and dipole magnet installed downstream the undulator is unavailable. Additionally, FALCON can help the researchers to understand the physics behind the experiment phenomena, such as the sidebands that are discussed above. These can give the operators and researchers more information about the FEL evolution process and the machine commissioning. The fairly accurate simulation results and greatly-improved computing efficiency have made it possible for FALCON to give guidance on the commissioning of the FEL.

Conclusions
This paper gives an introduction to a super-fast time-dependent simulation code, named FALCON, and its applications on a seeded FEL facility. A special care has been taken for the evolution of the radiation field envelope. The introduction of the radius factor (χ r ) and amplitude factor (χ amp ) has simplified the field equation and drastically reduced the required computational resources. The special designed modulation section removes the constraints on the laser-electron beam interaction with arbitrarily parameters. The present code is capable of simulating different FEL schemes within several minutes, which is about two orders of magnitude less than the time that is required by GENESIS 1.3. The validation of FALCON against GENESIS 1.3 has shown quite acceptable simulation results. FALCON shows a great potential as a fast optimization tool for FEL studies and machine operations due to the relatively high accuracy and computation efficiency.