Self-consistent calculation of transient beam loading in electron storage rings with passive harmonic cavities

The ongoing trend towards synchrotron light storage rings with ultralow emittance lattices leads to greater challenges to achieve beam stability, sufficient Touschek lifetime, low heating of machine components, and conservation of the emittance at high bunch charge. One solution to meet these challenges is to lengthen the electron bunches with harmonic cavities. Many upgrade proposals therefore include harmonic cavities to enhance the machine performance. This is also the case for the MAX IV 3 GeV storage ring, which employs passive third harmonic cavities to achieve up to five times bunch lengthening. Unfortunately, the performance of the harmonic cavities is reduced if a gap in the fill pattern is required. In this paper, the effect on synchronous phase and bunch length due to a gap in the fill pattern for rings with passive harmonic cavities is calculated in a self-consistent way including the bunch form factor. The aim is to achieve faster simulation of various schemes for compensating a gap compared to multiparticle tracking. A new semianalytical method based on an iterative matrix formulation is presented, as well as a singleparticle tracking code including the bunch form factor. The results from these methods are compared to both results from a multiparticle tracking code and measurements at the MAX IV 3 GeV storage ring. The importance of including the bunch form factor in simulations is evaluated and discussed.


I. INTRODUCTION
In new and planned upgrades of synchrotron light storage rings around the world, there is a trend towards lattices that achieve ultralow horizontal emittance, thus pushing the limit for diffraction-limited light up to keV x-ray energies [1].The MAX IV 3 GeV storage ring, with its seven-bend achromat lattice resulting in a transverse emittance of 328 pm rad [2], is the first of this new generation of machines [3].Common to these machines is a lattice with strong focusing, resulting in smaller dynamic aperture and the need for narrow vacuum chambers to achieve the required magnet gradients [4].It is therefore a greater challenge to achieve beam stability, sufficient Touschek lifetime, and low heating of machine components [2].In addition, for medium-energy rings, low transverse emittance at high bunch charge gives rise to strong intrabeam scattering (IBS) that blows up the emittance [4].One solution to meet these challenges is to lengthen the electron bunches with cavities operated close to an harmonic of the main rf system.Longer bunches lead to reduced IBS, increased Touschek lifetime [4] and lower heat load [2].In addition, harmonic cavities increase the synchrotron frequency spread, resulting in increased damping of instabilities [5].Many designs for new machines and upgrades to existing machines therefore include harmonic cavities to enhance the machine performance, e.g., [6][7][8].This is also the case for the MAX IV 3 GeV storage ring, where bunch lengthening is an essential part of the design, and the ring is designed with passive third harmonic cavities [9] to achieve bunch lengths around five times the natural length [2].Studies have shown that the performance of the harmonic cavities is critical for both stability [10] and to conserve the ultralow emittance at the design current of 500 mA [11].
Many synchrotron light storage rings have demand for serving both high-brilliance users requesting multibunch operation and timing users with specific demands on light repetition rates.Timing users usually require repetition rates in the kHz-few MHz range [12], which is below the rate provided by the ring rf system when operating with a multibunch fill pattern.To serve both user groups, many storage rings today operate with fill patterns with gaps of sufficient length for beamline choppers or gated detectors.For conventional choppers and detectors this is a few hundred ns [13].For rings that employ passive harmonic cavities, such fill patterns are not favorable.Studies performed at several facilities operating or planning for passive harmonic cavities, e.g.[6,7,[14][15][16], show that fill patterns with gaps give rise to transient effects that decrease the average bunch lengthening and cause a variation over the bunch train.For ultralow emittance rings it is therefore not trivial to serve timing users by introducing a gap in the fill pattern while maintaining the performance of the machine for high-brilliance users.There could also be other reasons for introducing a gap in the fill pattern, such as ionclearing or to operate a pseudo-single-bunch mode with a kicker that is not sufficiently fast to kick only one bunch out of a multibunch train [17].The required length for such gaps is, however, usually shorter.Different schemes can be considered to compensate for a gap in the fill pattern when operating with passive harmonic cavities.Common to them is the need for simulation studies since the steady-state solution for these cases is not trivial to solve analytically.
This paper focuses on simulations of steady-state transient beam loading effects for rings operating with passive harmonic cavities, but the same considerations are important for schemes with active harmonic cavities, such as the one employed in the BESSY-VSR upgrade [18], if highbrilliance and timing users are to be served simultaneously.The methods presented in this paper could be extended to treat such cases.Previous work on the topic include semianalytical methods as well as single and multiparticle tracking.A semianalytical calculation for different fill patterns has been presented by Yamamoto et al. [8], but this method includes active compensation in the harmonic cavities and neglects the phase shifts of the bunches as well as the bunch profiles since the bunches are approximated as point charges.Single particle tracking as described by Byrd et al. [14] includes the phase shift of the bunches, but also in this method the bunches are approximated as point charges.Implementations based on this approach have been presented by both Milas et al. [15] and Ruprecht et al. [19].Single particle tracking approximating the bunches as Gaussian has been presented by Phimsen et al. [20], but otherwise multiparticle tracking has so far been the only method to fully include both phase shifts and bunch profiles in the simulation, e.g., as presented by Bassi et al. [16], Borland et al. [7], and Byrd et al. [6].
In this paper, the effect on synchronous phase and bunch length due to a gap in the fill pattern for rings with passive harmonic cavities is calculated in a self-consistent way including the effect from the bunch profiles by introducing a bunch form factor for every bunch.The approach is based on previous work by Tavares et al. [21] to simulate bunch lengthening in the MAX IV 3 GeV storage ring in a selfconsistent way for uniform fill patterns.The aim is to achieve faster simulation of various compensation schemes compared to multiparticle tracking, and thus facilitate design studies.The paper presents a new semianalytical method based on an iterative matrix formulation, as well as a single-particle tracking code that includes self-consistent calculation of the bunch form factor.The results from these methods are compared to results from a multiparticle tracking code and measurements at the MAX IV 3 GeV storage ring.Finally, the importance of including the bunch form factor in simulations is evaluated and discussed.

A. Beam loading
An extensive description of the theory of beam loading using phasor notation was done by Wilson and can be found in [22], but the most important results will be repeated here to describe the notations used in this paper and the expansions necessary to apply the theory to arbitrary fill patterns.
A charged particle passing an rf cavity induces a voltage in the cavity.If a bunch is approximated as a point charge, the induced voltage is given by where k is a loss factor and q the absolute value of the bunch charge.The loss factor is given by where ω r is the angular resonance frequency of the cavity, R L the loaded shunt impedance, and Q L the loaded quality factor [22].For multiple bunches passing the cavity, the induced voltage is added to the voltage already present in the cavity from the previous bunches, as displayed in Fig. 1.
The voltage in the cavity immediately after bunch i þ 1 has passed is given by the phasor Ṽb;iþ1 ¼ Ṽb;i e ðjδ−τÞ þ Ṽ0 ¼ Ṽb;i e ðjδ−τÞ − 2kq; ð3Þ where Ṽb;i is the voltage after the previous bunch, which decays exponentially as  and slips in phase by [22].The time between the two bunches is given by where Δϕ is the phase difference between the bunches with respect to the main rf, N b the number of rf buckets between them and ω rf the angular rf frequency [14].
The bunch itself, however, only sees half of the voltage it induces, i.e., Ṽb;iþ1 þ kq, which, as will be shown in Sec.III has to be taken into account when simulating the voltage seen by individual bunches in a bunch train.
The charge distribution of a bunch can be taken into account by including a form factor which relates the voltage induced by a charge distribution to the voltage induced by a point charge [22].The form factor at the nth harmonic of the rf frequency is given by the Fourier component at that frequency normalized to the DC component [21] Fn ¼ F n e jϕ F;n ¼ F ½ρðtÞ ω¼nω rf jF ½ρðtÞ ω¼0 j ; where [22].This results in a modification of the induced beam loading voltage in Eq. (1) where n is the rf harmonic that is closest to resonance frequency of the cavity.For a completely symmetric bunch the phase of the form factor is zero, resulting in a scalar form factor, but an asymmetric bunch will induce a rotation ϕ F;n of Ṽ0 in the phasor addition described by Eq. (3), and thus a complex form factor is required for asymmetric bunches.

B. Double rf systems
A double rf system consisting of main and harmonic cavities was initially described by Hofmann and Myers in [23].The voltage seen in a double rf system by a particle with phase φ in bunch i is given by the sum of the cavity voltages where V mc;i is the peak main cavity voltage, ϕ s;i the synchronous phase (i.e., the phase where there is no net energy gain per turn), V hc;i the peak harmonic cavity voltage, n the harmonic of the cavity, and ϕ h;i the phase of the harmonic field relative to the main rf field at the synchronous phase of the bunch [23].The variable φ denotes the phase offset from the synchronous phase, whereas the index i indicates that in the case of an uneven fill pattern, different bunches have different equilibrium voltages and phases due to the beam loading.An example of the phasors describing the voltages seen by a bunch i are shown in Fig. 2. Beam loading in the main cavities can be taken into account by calculating V mc;i as the sum of a generator-voltage phasor and a beam-loading phasor.
The voltage gives rise to a potential where α is the momentum compaction, E 0 the nominal beam energy, T 0 the revolution period, e 0 the absolute value of the electron charge, and U 0 the energy loss per turn.The bunch profile can then be determined as where ρ 0;i is a normalization constant and σ e the relative energy spread [21].The bunch length is given by the RMS of the bunch profile.An example of voltages and bunch profiles for different bunches in the case of a gap in the fill pattern is displayed in Fig. 3.
FIG. 2. Phasors for main and harmonic cavity voltages.The dashed line indicates the build up of the beam loading in a passive harmonic cavity and that a steady-state solution will eventually be reached after many passes through the cavity.The sign of the angles are indicated by arrows where counterclockwise corresponds to positive angle.
For a uniform, multibunch fill pattern, the bunch length can be maximized (without getting bunches that are asymmetric or have a double-hump structure) by tailoring the harmonic voltage amplitude and phase such that the first and second derivatives of the voltage become zero at the synchronous phase [23].This forms a quartic potential well and the conditions at which this occurs are therefore referred to as flat potential conditions [21].The bunch length achieved at these conditions will be used for comparisons between fill patterns with and without a gap in this paper.
For passive harmonic cavities, the harmonic voltage amplitude and phase cannot be set independently, but are given by the beam loading due to the detuning of the harmonic cavity.A self-consistent calculation of the beam loading can be achieved by calculating the voltage seen by every bunch using phasor addition including an individual form factor for every bunch calculated from the bunch profiles.By iterating the calculation, a steady-state solution for the fields and profiles of the bunches can eventually be found.

A. Matrix formulation
A new semianalytical method based on an iterative matrix formulation has been developed and is presented here.It can be used to calculate the steady-state solution for the transient in a nonuniform fill pattern in a self-consistent way, taking into account both the phase shift of the bunches and their form factors.The voltage seen by bunch i due to beam loading from bunch l can be calculated by summing the beam loading phasor from bunch l over infinite turns N.This gives where the time between the two bunches is given by and τ i;l and δ i;l are otherwise defined according to Eq. ( 4) and ( 5), respectively.The derivative of the voltage with respect to the phase of bunch i becomes Starting from an initial estimate of the equilibrium phases of the bunches, a linear correction δϕ s;i can be estimated using the matrix equation, where the main cavity voltage and the contributions from each bunch have been expanded in a Taylor series to first order, δ il is the Kronicker delta, and the voltage contribution from the bunch itself has been included.Here, the main cavities are assumed to be ideal (V mc;i ¼ V rf ), meaning the voltage in them is given by the generator voltage, but the beam loading in the main cavities could be taken into account by including it in V b .Equation ( 16) can be iterated, each time, recalculating the voltage with updated equilibrium phases.The form factors can also be updated every iteration according to Eq. ( 8).In this way, a self-consistent solution for the transient can be evaluated.An additional, convenient way of approximating the form factors is to calculate the angular frequency ω s of FIG. 3. Example of voltages and bunch profiles for bunch 1, 77, and 156 in the bunch train for a fill pattern with a 210 ns gap in the MAX IV 3 GeV storage ring.
incoherent synchrotron oscillation from the derivative of the potential.
The bunch length can then be calculated from the energy spread using the usual expression and the form factor can be calculated assuming a Gaussian distribution: This method is significantly faster than calculating the form factor from a precise bunch profile according to Eq. ( 12) and determining the Fourier component numerically.However, it is only valid for weak harmonic cavity fields as it assumes a linear voltage around the synchronous phase.This assumption is justified for some transients because the gap in the fill results in a large drop in harmonic cavity voltage.It can also be used for the first few iterations only before obtaining the final result more precisely.

B. Single-particle tracking
A single particle tracking code named FILLPATTERNSIM was developed to simulate the transient beam loading for various fill patterns including the bunch form factor.The code is based on a previous implementation by Milas [15] according to the model presented in [14], but also includes the form factor.The code describes every bunch as a single particle and every turn the induced cavity fields are calculated using phasor addition.The phase ϕ i and energy deviation ε i of every bunch i for turn N þ 1 is then updated according to the equations of motion where is the voltage seen by the bunch, λ ¼ 1 τ s f 0 with τ s the longitudinal damping time and f 0 the revolution frequency [14].If the steady-state solution for the cavity fields has not yet been found, the energy deviations of the particles will oscillate, resulting in new phase deviations, until the phases of the particles are such that the cavity fields will be reproduced every turn and all the particles find an individual synchronous phase ϕ s;i where the energy loss is compensated.
For single-particle tracking, convergence might be an issue.Especially, this is the case for simulations close to flat potential conditions where small changes of the phases of the particles might have a large effect on the result.It is, however, possible to improve the convergence and, at the same time, reduce the execution time by applying tricks as long as they do not affect the steadystate solution.For the simulations presented in this paper, this was achieved by first only calculating and updating the form factor of every bunch every 1000th turn.Convergence could then be achieved for the scalar form factor by increasing the damping term to λ ¼ 1  2 .This was not sufficient when including the complex form factor, where an amplification M of the momentum compaction had to be introduced in the phase equation.This resulted in the equations of motion An amplification of M ¼ 100 improved the convergence without affecting the steady-state solution, but it is likely that the required amplification is machine dependent.

C. Multiparticle tracking
The multiparticle tracking code MBTRACK is described in [24] and a detailed description will therefore not be repeated here.The code puts the particles into bins according to their phase offset and simulates the induced voltage in the cavities by binwise phasor addition.The phase and energy deviation of every particle is then updated every turn according to the equations of motion, analogous to the single-particle tracking.For the purpose of the studies in this paper, the possibility to define arbitrary fill patterns was implemented in the code.

IV. TRANSIENT EFFECTS AT NOMINAL SETTINGS A. Nominal settings
The nominal parameters of the MAX IV 3 GeV storage ring can be found in Table I.The design current of the ring is 500 mA, but several different settings of the cavities could be considered for operation at this current.The settings used for the comparisons in this paper are also displayed in Table I.It corresponds to the design 4.5% momentum acceptance with harmonic cavity parameters according to theoretical flat potential conditions for a bare lattice without insertion devices.The main cavities were assumed to be ideal, thus no transient in their voltage due to a gap in the fill pattern.At the nominal settings, this assumption is justified since at high harmonic voltage the transients generated by the main cavities tend to be much smaller than those generated by the harmonic cavities.

B. Case with form factor 1
Simulations were first performed with only one particle in MBTRACK and the form factor set to 1 in the other methods.To avoid overstretching the bunches, the shunt impedance was reduced to the required impedance to achieve flat potential conditions with form factor 1 (2.17826MΩ).The synchronous phase and harmonic field for this case are displayed in Fig. 4. As shown, there is excellent agreement between the three methods.
For single-particle tracking in MBTRACK no bunch lengths can be calculated, but a comparison between the bunch lengths obtained with the matrix formulation and FILLPATTERNSIM is also displayed in Fig. 4. A large reduction of the average bunch length can be seen already for a small gap.In addition, for short gaps the bunch lengths are longer in the ends of the train, whereas as the gap length increases the bunches start to become longer in the middle of the train instead.In between, there is a gap length when the bunch length variation over the train is minimized.

C. Case with scalar form factor
Simulations were performed with 10 000 particles per bunch in MBTRACK and including the form factor amplitude in the two other methods.To compare with MBTRACK, the center-of-mass of the bunch profiles given by the two other methods were calculated.Figure 5 displays the phase of the center-of-mass, the harmonic voltage and the harmonic phase at the center-of-mass for the three methods.It is evident that the harmonic voltages differ between MBTRACK and the other methods, but that for long gaps 2P Þ. b Calculated in a self-consistent way including the bunch form factor using the code presented in [21].FIG. 4. Synchronous phase, harmonic field and bunch length for different gaps when the form factor has been set to 1 for the matrix formulation (solid) and FILLPATTERNSIM (dashed).The MBTRACK results (dotted) and the analytical values for a uniform fill pattern (black dashed) are shown for comparison.The mean and RMS of the deviations from the MBTRACK results are displayed for the case with 164 bunches.Note that no bunch lengths are obtained from MBTRACK when only having one particle in the simulation.
the phases start to agree.Figure 5 also displays the bunch lengths calculated by the different methods.For long gaps, all three methods give similar results, but the results for MBTRACK start to differ as the gap length decreases.

D. Case with complex form factor
Finally, simulations were performed including both the form factor amplitude and phase in the matrix formulation and FILLPATTERNSIM.Figure 6 displays the phase of the FIG. 5. Center-of-mass, harmonic field and bunch length for different gaps including scalar form factor for the matrix formulation (solid) and FILLPATTERNSIM (dashed).The MBTRACK results (dotted) and the analytical values for a uniform fill pattern (black dashed) are shown for comparison.The mean and RMS of the deviations from the MBTRACK results are displayed for the case with 164 bunches.
6. Center-of-mass, harmonic field and bunch length for different gaps including complex form factor for the matrix formulation (solid) and FILLPATTERNSIM (dashed).The MBTRACK results (dotted) and the analytical values for a uniform fill pattern (black dashed) are shown for comparison.The mean and RMS of the deviations from the MBTRACK results are displayed for the case with 164 bunches.center-of-mass of the bunch profiles, the harmonic voltage, and the harmonic phase at the center-of-mass for the three codes.Comparison with Fig. 5 clearly concludes that the phase of the form factor has to be included in the simulations to achieve agreement with multiparticle tracking for all gap lengths.

V. EFFECT OF THE BUNCH FORM FACTOR
Figure 7 displays a comparison of the average bunch length and variation over the bunch train as a function of number of filled buckets for MBTRACK and the matrix formulation for the different cases of the form factor.For long gaps (above 200 ns, corresponding to 157 bunches) the average bunch length is similar for MBTRACK and the matrix formulation independent of the approximation of the form factor. 1 The bunch length in this case is around 130 ps, corresponding to 3.25 times bunch lengthening.For shorter gaps, the phase of the form factor has to be included in the simulation to achieved similar average bunch lengthening as with multiparticle tracking.The variation over the bunch train, however, differs between MBTRACK and the matrix formulation as long as the phase of the form factor is not included in the simulation.It can also be noted that there exists a gap length where the variation over the bunch train is minimized.
The results show that for simulations of long gaps (when the average bunch lengthening is reduced to below 3 times) the average bunch length can be estimated by approximating the bunch form factor to 1 and reducing the shunt impedance accordingly, but to fully estimate the bunch length variation over the bunch train the complex form factor has to be included in the simulation.For simulation of short gaps, the complex form factor has to be included both to be able to estimate the average bunch length and the variation over the train.The reason for this can be noted in Fig. 8, which displays a comparison of the bunch profiles for fill patterns with 173, 164, and 155 filled buckets.For short gaps the bunch profiles in the beginning and end of the bunch train become significantly asymmetric and then it is not valid to neglect the phase of the form factor in the simulation.For longer gaps, however, good agreement for the bunch profile can be achieved by only including the amplitude of the form factor in the simulation.

VI. EXPERIMENTAL RESULTS
The synchronous-phase transient when operating with a gap in the fill pattern was compared to measurements in the MAX IV 3 GeV storage ring.The ring has three harmonic cavities, but they are currently under commissioning and therefore the measurements had to be performed at lower harmonic voltage than required to achieve design bunch lengthening.The harmonic cavity detuning was calculated from measured cavity fields at uniform fill assuming a form factor of 1, which at the achievable voltages was an acceptable approximation.The total main cavity voltage was determined by measuring the synchrotron frequency at low current and assuming design parameters for beam energy, momentum compaction and energy loss per turn.The simulations were conducted for a range of main cavity voltages between 988.3 kV and 1026 kV to account for the uncertainty inherent in determining the voltage in this way.The main cavity detuning was assumed to be the optimal detuning to minimize the reflected power since the detuning is controlled by a feedback for this purpose.At the time of the measurements, only five out of the maximum six main cavities were installed in the machine, of which one was not powered and detuned to only have a small effect on the beam.Nevertheless, the effect was measurable so this cavity also had to be included in the simulations.The detuning of this cavity was determined by calibrating the potentiometer of the tuning mechanism to measurements of the cavity resonance frequency.The synchronous phase transient was measured with a Dimtel bunch-by-bunch feedback system [25] where the phase shift was calibrated by moving the main cavity rf phase relative to the local oscillator of the phase detector.
Figure 9 displays the measured synchronous phase transient together with the results from FILLPATTERNSIM FIG. 7. Average (top) and variation (bottom) of the bunch length as a function of number of filled buckets for MBTRACK and the matrix formulation for different cases of the form factor.The results for 173, 164, and 155 bunches in the fill pattern are indicated (black dashed).The natural bunch length for the simulated case is 40 ps.
for one of the measurements.Results were also obtained using the other two methods but they are not displayed for clarity since the results were too similar to distinguish.During the analysis it was concluded that the beam loading in the main cavities could not be neglected because of to the low harmonic fields during the measurements.As well as the passive harmonic cavity and the one passive main cavity, the simulations therefore included active main cavities with feedback compensating the beam loading.The possibility to do this was already implemented in MBTRACK, and a similar scheme was implemented in FILLPATTERNSIM.The compensation is based on the approach in [26], but updated after a given number of turns to account for changes in the induced voltage due to the form factor.The generator voltages obtained with FILLPATTERNSIM was used as input into the matrix method.As shown, the measurement agrees well with the simulation.It can also be noted that the transient has a stable oscillation.This oscillation is expected to be caused by a higher order mode in the cavities.
To evaluate the phase transient as a function of the number of filled buckets, the measured transients were fitted with third degree polynomials and the phase deviation over the bunch train calculated from the fits.A third degree polynomial fit was chosen due to better agreement with the shape of the transient in simulations than a linear fit. Figure 10 displays a comparison between the phase deviation over the bunch train for two different measurement series, obtained on different days, and corresponding simulations.The differences between the measurements and the simulations are within the expected error due to uncertainties in the cavity fields and the phase calibration.The simulations are, therefore, of sufficient accuracy to evaluate real-world scenarios.

VII. APPLICATION TO SIMULATION OF COMPENSATION SCHEMES
Different methods can be considered for compensating the reduced bunch lengthening due to a gap in the fill pattern.Examples of results for the matrix formulation and FILLPATTERNSIM are presented here in comparison with FIG. 9. Measured and simulated synchronous phase shift as function of bucket number for 100 mA average current and 131 filled buckets.The simulation result is plotted for a main cavity range between 988.3 kV (upper limit) and 1026 kV (lower limit).The error bars on the measurement corresponds to the error in the fit of the phase calibration.FIG. 8. Bunch profiles for beginning (left), middle (center), and end (right) of the bunch train for fill patterns with 173 (top), 164 (center), and 155 (bottom) filled buckets.The colors are in accordance with Fig. 7, MBTRACK (blue), form factor 1 (orange), scalar form factor (green), and complex form factor (red).
results from MBTRACK to show the capabilities of the methods to simulate such schemes.
The most straightforward method to compensate for a gap in the fill pattern is to tune in the harmonic cavities further.This, however, increases the risk for Robinson instability and will also lead to a larger variation of the bunch lengths over the bunch train.A smaller variation of the bunch lengths can be obtained by tuning out the cavities instead.Figure 11 displays the results for nominal settings for different tunings of the harmonic cavities.The MBTRACK results begin to be unstable below a detuning of 45 kHz, indicating Robinson instability.The stability cannot be studied with the matrix formulation because it assumes a steady-state solution in its formulation, whereas FILLPATTERNSIM in principle can simulate dynamic effects such as instabilities, but is not able to do so while maintaining convergence when including the form factor, as described in Sec.III B.
Another method proposed by several facilities, e.g., [14,15], is to tailor the bunch charge in the fill pattern.The disadvantage with this method is that the bunch charge will vary along the bunch train.The consequences for the users have to be evaluated as well as the bunch charge limitations.Figure 12 displays the results when the fill pattern has been tailored in two different ways to compensate for the missing bunches while maintaining the average current of 500 mA.The first case has 10 bunches on both sides of the gap with 2 times nominal charge, whereas the second case has 25 bunches on both sides of the gap with 1.4 times nominal charge.It can be noted that the bunches with highest charge will also have the shortest bunch length, which might limit the feasibility of such schemes.To demonstrate the importance of including the complex form factor in the simulations, for the case with 10 bunches on both sides with higher charge, the bunch lengths become 155 AE 12 ps when the form factor has been approximated to 1 (with reduced shunt impedance as described previously), 157 AE 16 ps with the scalar form factor and 176 AE 17 ps with the complex form factor.This corresponds to roughly 11% reduction of the average bunch length when only including the scalar form factor compared to a fully selfconsistent solution including the complex form factor, and 12% when using a form factor of 1.Neither of these differences is negligible.FIG. 10.Measured and simulated transient as function of number of filled bucket for two different measurement series with 100 mA and 90 mA average current, respectively.The simulation results are plotted for a main cavity range between 988.3 kV (upper limit) and 1026 kV (lower limit).The error bars on the measurement corresponds to the error in the fit of the phase calibration as well as error in the fit of the transient.FIG.11.Bunch length for a fill with 156 bunches for different tunings of the harmonic cavities for the matrix formulation (solid), FILLPATTERNSIM (dashed), and MBTRACK (dotted).The detuning of 49.361 kHz corresponds to flat potential conditions for a uniform fill.The analytical value for a uniform fill pattern (black dashed) is shown for comparison.FIG.12. Bunch length for a fill with 156 bunches for two different charge distributions (10 bunches on both sides of the gap with 2 times nominal charge and 25 bunches on both sides of the gap with 1.4 times nominal charge) for the matrix formulation (solid), FILLPATTERNSIM (dashed), and MBTRACK (dotted).The analytical value for a uniform fill pattern (black dashed) is shown for comparison.

VIII. CONCLUSIONS AND OUTLOOK
In this paper, two methods to simulate the effect on synchronous phase and bunch length due to a gap in the fill pattern for rings with passive harmonic cavities were presented and evaluated.The results show that the matrix formulation and FILLPATTERNSIM have the capability to calculate the bunch profiles caused by a gap in the fill pattern in a self-consistent way, and thus simulate various schemes for compensating the gap.Furthermore, they require significantly less computing resources than a multiparticle tracking code such as MBTRACK.As an example, for the case with 156 filled buckets and an harmonic-cavity detuning of 45 kHz, an MBTRACK simulation with 10 000 particles per bunch takes 28 minutes on 20 cores to achieve convergence to below the percent level, whereas both FILLPATTERNSIM and the matrix formulation can achieve this in 5.5 minutes running on a laptop.
The results show that the complex form factor has to be included in the simulations to fully evaluate the bunch lengthening over the bunch train for cases with high harmonic voltage.This is especially important for short gaps where the bunches become significantly asymmetric.To approximate the form factor as 1 or only include the scalar form factor is only sufficient in cases with low harmonic voltage or long gaps, and then perhaps still only to estimate the average bunch length and not the variation over the bunch train.
The results also show that for short gaps the bunch length is longest in the ends of the train, whereas for long gaps the bunch length is longest in the middle.In between, there exists a gap length where the bunch length variation over the train is minimized.As lifetime is dependent on the bunch length, this could be an optimum condition for facilities where it is not feasible to run top-up injection of individual bunches.
The three simulation methods were compared to measurements at the MAX IV 3 GeV storage ring for cases with low harmonic voltage.As the commissioning of the harmonic cavities progresses, similar comparisons can be performed at high harmonic voltage, where the bunch form factor becomes important, and the variation of the bunch length over the train becomes large enough to measure and include in the comparison.
So far both methods have only been implemented for passive harmonic cavities, but the presented approaches could be extended to rings employing active harmonic cavities.For future development it is also of interest to study convergence and execution times for rings with a higher number of bunches than the MAX IV 3 GeV storage ring since multiparticle tracking including beam loading is more demanding for such cases.

TABLE I .
Nominal bare lattice parameters of the MAX IV 3 GeV ring and harmonic cavity parameters used in this paper.