A description of the full-particle-orbit-following SPIRAL code for simulating fast-ion experiments in tokamaks

The numerical methods used in the full particle-orbit following SPIRAL code are described and a number of physics studies performed with the code are presented to illustrate its capabilities. The SPIRAL code is a test-particle code and is a powerful numerical tool to interpret and plan fast-ion experiments in tokamaks. Gyro-orbit effects are important for fast ions in low-field machines such as NSTX and to a lesser extent in DIII-D. A number of physics studies are interlaced between the description of the code to illustrate its capabilities. Results on heat loads generated by a localized error-field on the DIII-D wall are compared with measurements. The enhanced Triton losses caused by the same localized error-field are calculated and compared with measured neutron signals. Magnetohydrodynamic (MHD) activity such as tearing modes and toroidicity-induced Alfvén eigenmodes (TAEs) have a profound effect on the fast-ion content of tokamak plasmas and SPIRAL can calculate the effects of MHD activity on the confined and lost fast-ion population as illustrated for a burst of TAE activity in NSTX. The interaction between ion cyclotron range of frequency (ICRF) heating and fast ions depends solely on the gyro-motion of the fast ions and is captured exactly in the SPIRAL code. A calculation of ICRF absorption on beam ions in ITER is presented. The effects of high harmonic fast wave heating on the beam-ion slowing-down distribution in NSTX is also studied.


Introduction
In toroidal fusion devices the motion of the particles is determined by the Lorentz equations. The particle motion consists of the fast gyro-motion with typical frequencies in the MHz range for ions, the drift motion with typical frequencies in the range of up to a few hundred kHz for ions, and the precessional motion which is typically on the order of a few kHz for ions. The fast gyro-motion is often neglected and the orbits are calculated at the center of the gyro-orbit because the inclusion of the gyro-motion makes the calculations very expensive in CPU time [1][2][3][4]. In the guiding center approximation the magnetic moment of the particles, which is an adiabatic invariant [5,6], is taken to be conserved while the magnetic and electric fields and other relevant plasma properties are calculated at the guiding center location. The assumption made in guiding center theory is that the gyroorbit is small compared with the characteristic scale length of the fields, a condition that is usually met for thermal ions in present day large tokamaks. Fast ions, however, can have substantially larger Larmor radii that can become comparable to the characteristic scale lengths of the plasma profiles, turbulence and magnetohydrodynamic (MHD) structures such as Alfvén eigen modes and therefore, the guiding center approximation is not valid anymore [7]. This is especially the case in spherical tokamaks such as NSTX with their low toroidal fields. Another consequence of averaging over the fast gyro-motion in the guiding center approximation is that the interaction between ion cyclotron waves (ICRF) and the ions is not captured in guiding center calculations although efforts have been made to approximate the ICRF-particle interaction in guiding center codes with kick operators [8,9] but only a full-orbit treatment of the particle motion can capture the interaction between particles and ICRF.
With the advance of high-speed parallel computers it has become possible to follow the full orbits of fast ions in toroidal geometry and use statistically relevant ensembles of test particles to study the interaction between waves and particles without the limitations imposed in guiding center theory. The motion of charged particles in electromagnetic fields is governed by the Lorentz equations: (1) with m the mass, q is the charge, r is the position and v is the velocity of the particle while B and E are the magnetic and the electrical fields at the particle position. Apart from the electromagnetic forces the fast ions are also affected by the thermal plasma through which they move. At high energies the fast ions suffer drag from thermal electrons that slow them down without a significant change in direction while less frequent collisions with thermal ions are responsible for changes in the travel direction of the fast ions, known as pitch-angle scattering.
In this paper, a description of the SPIRAL code is given and is interlaced with results from physics studies to illustrate the code capabilities.
The SPIRAL code is written in the C language [10] and it makes use of the Numerical Algorithms Group (NAG) library routine: nag ode ivp adams gen (d02cjc) [11] which is a highly accurate, variable order, variable step size modified Adams method for solving the differential equations. When particles are followed in static magnetic fields only for ∼50 ms, their energies are usually conserved better than 10 −5 . Due to the nature of the problem, following a large number of independent test particles on their paths through the plasma, parallel processing of individual orbits is straightforward and we have used the MPI package [12] to handle the parallel processing. The execution time increases linearly with the number of test particles and scales inversely with the number of CPUs on which the code is running. Great care has been taken that (partial) results are stored on disk as soon as they they are available and can be monitored during the run. When a computer failure occurs during a run, the SPIRAL code can very easily be restarted from that point, avoiding loss of CPU time. In the output file a large number of variables is written for access with a post-processor code so that the results can be studied in detail. Moreover, realistic first walls for different machines can be selected in the code so that particle losses and heat loads to the first wall can be studied accurately. The calculation of the intersection of particle orbits with the wall are handled by the used NAG routine which will stop when the particle intersects the wall.
In section 2 the implementation of the equilibrium magnetic fields is discussed. Equilibrium solvers usually give the relevant fields on a discrete spatial mesh and a robust interpolation routine is presented that obtains the fields between the mesh points under the condition that Maxwell's equations are satisfied. In this section single particle orbits in NSTX and DIII-D are studied and it is shown that gyro-motion effects are significant in NSTX while they are small in DIII-D.
Slowing-down and pitch-angle scattering are discussed in section 3 and 3D equivalents of the 2D equations for pitch angle and slowing-down as given in [13] are derived.
For an accurate comparison between simulations and experimental results it is important to use realistic fast-ion distribution functions that reflect the ones present in the experiments. It is (almost) impossible to measure the full spatial and velocity distribution of the fast ions. Therefore, the SPIRAL code has the capability to either read a given fast-ion distribution or generate it internally as discussed in section 4 and a study in NSTX is presented on the effects of a tearing mode on the beam-ion distribution.
Toroidal-symmetry breaking fields are ubiquitous in tokamaks. They arise from the finite number of toroidal field coils, from ferritic steel that is needed for strength, or they can be induced deliberately with external field coils for shaping the plasma edge and suppressing edge-localized modes (ELMs) while losses induced by toroidally localized RF antennas can create hot spots [14]. In section 5 the numerical techniques are discussed that were used to implement those error fields in the SPIRAL code in such a way that Maxwell's equations are satisfied accurately. Instead of using a Fourier harmonic decomposition of the ripple fields we have chosen to specify the ripple fields on a cylindrical mesh so that highly localized perturbations, which are poorly described by a finite number of Fourier harmonics, can be included as well as conventional toroidal ripples. In this section, two cases are presented. In the first case the effects of a highly localized magnetic perturbation from a scaled mock-up Test Blanket Module (TBM) for ITER in DIII-D on the neutral beam ions and on the 1 MeV tritium population are simulated and compared with observations. In the second study the effects of resonant magnetic field perturbations (RMPs) on the beam ion confinement in NSTX are simulated to investigate whether the effects are large enough to observe RMP-enhanced beam-ion losses and/or changes in the confined fast-ion population that can be measured with the Fast Ion D α (FIDA) diagnostic [15].
In section 6 the implementation of MHD modes and RF waves in the SPIRAL code is discussed. MHD activity can have large effects on the fast-ion population via resonant interactions. Resonances between fast ions and a reversed shear Alfvén eigenmode (RSAE) in DIII-D are studied. In addition, the effects of short (<1 ms) bursts of torodicityinduced Alfvén eigenmode activity, which are often observed in NBI-heated discharges in NSTX, on the neutral-beam slowing-down distribution are investigated (section 6.1).
One of the major heating schemes proposed for ITER is ion cyclotron range of frequency (ICRF) heating where RF waves interact with the gyro-motion of the ions. Because this interaction involves the gyromotion of the particles it cannot be calculated with particle-orbit following codes that use the guiding center approximation which neglects the gyro-motion. Because the full gyro-motion is retained in the SPIRAL code, the interaction between the ICRF waves and ions appears naturally in the simulations. Two studies in ICRF absorption by fast ions are discussed in section 6.3. The first one is a study for ITER in which an estimate is calculated for the parasitic absorption of ICRF on the deuterium beam-ion slowing-down distribution (section 6.3). As a second example the interaction between high harmonic fast waves (HHFWs) and neutral beam ions in NSTX are studied. Because of NSTX's low magnetic field a large number of harmonic ICRF resonances are present in the NSTX plasma and particles can interact with several of those along their drift orbits. A preliminary study is presented of HHFW effects on a beam-ion slowing-down distribution showing that a significant fraction of the energetic beam ions is lost due to the HHFW (section 6.3). Conclusions are drawn in section 7. Where possible, comparisons between full orbit and guiding center calculations will be made but an exhaustive study between the two calculations is beyond the scope of this paper.

Equilibrium magnetic and electrical fields
For an accurate calculation of charged particle orbits in plasmas, the magnetic and electric fields should be known accurately in the region where the particle moves. The equilibrium magnetic fields in tokamaks are usually calculated on a discrete mesh with equilibrium codes such as EFIT [16] and q-solver. SPIRAL can read the output from those codes, which consist of the poloidal flux function, p (R, Z), and the diamagnetic correction to the toroidal magnetic field. The radial and vertical components of the poloidal magnetic field are obtained by taking the derivatives of p with respect to R, and Z: Taking accurate numerical derivatives from a function that is given on a finite mesh is difficult because it has to preserve the divergence-free condition as dictated by Maxwell's equations which translates in this case to ∂ R B R (R, Z)+∂ Z B Z (R, Z) = 0 because of the toroidal symmetry. In SPIRAL we have solved this problem by fitting a 2D Chebyshev polynomial expansion [17] to the given discrete points of the poloidal flux function: Once a good fit is obtained (usually 15-30 radial and vertical terms are needed), derivatives can be obtained analytically by rearranging the expansion coefficients (see appendix A). It can be shown easily that the magnetic field obtained in this way is divergence free as required by Maxwell's equations up to the computer accuracy over the entire region where the Chebyshev expansion is valid.
We will now study two single particle orbits in the equilibrium fields of NSTX and DIII-D and find that full-orbit effects are significant in NSTX while in DIII-D the effects are minimal. The particle orbit in a typical equilibrium field for NSTX is shown in figure 1 where a 90 keV deuteron, which is the maximum NBI injection energy in NSTX, was launched at R = 1.4 m and Z = 0.0 m with a pitch, v /v, of one which means for NSTX that the particle velocity is anti-parallel to the local magnetic field. (The parallel component, v , of the particle pitch, v /v, is parallel to the local magnetic field whereby the sign of v is defined to be positive when the particle moves in the direction of the plasma current which is opposite to the toroidal magnetic field direction in NSTX). Both the full orbit (in red) and guiding center orbit (in blue) are shown, where the latter is obtained from the full orbit by evaluating the instantaneous guiding center which is given as where B is taken at R p , the particle location. There are two things noteworthy about this orbit. First, the gyro-frequency is only 12 times higher than the drift frequency which violates the assumption made in guiding center theory that the gyrofrequency is much higher than the drift frequency. Second, it can be seen from figure 1 that the full orbit has excursions of up to 3.7 cm away from the guiding center orbit which can be understood as follows: at the launch point the Lorentz force is zero because particle velocity is parallel to the magnetic field ( figure 1(b)). Only when a perpendicular velocity component develops ( figure 1(c)), a magnetic force arises and pulls the particle back onto its poloidal orbit. When this orbit is calculated with the guiding center equations [18] the projection of the orbit onto the poloidal plane is virtually the same as the instantaneous guiding center  (equation (4)) with deviations between the two orbits of less than 1 mm. Notably in the guiding center calculation the parallel velocity of this particle remains constant along the orbit because its magnetic moment was chosen to be zero at the start. As a consequence, a poloidal transit of the guiding center in the guiding center calculation is completed slightly faster than one transit in the full-orbit calculation. This difference is reflected in the poloidal transit frequency which is 388.2 kHz for the full-orbit calculation and 398.6 kHz in the guiding center approximation, a difference of more than 10 kHz (or 2.6%). This difference is not caused by numerical differences in the magnetic fields because the same parametrization of the magnetic fields was used in the guiding center and full-orbit calculations.
The orbit for an 80 keV deuteron in DIII-D is shown in figure 2 where the particle was launched at the LFS midplane at R = 2.12 m with its velocity anti-parallel to the local magnetic field line (pitch: v /v = 1.0 because the plasma current is opposite to the toroidal magnetic field direction). In this case the gyro-frequency is more than two hundred times higher than than the drift frequency and therefore, guiding center theory is more accurate than in the NSTX case. This is also reflected in the difference between the full orbit and guiding center orbit where the maximum difference between the two orbits is 1.2 mm which is indistinguishable in figure 2(a). The perpendicular velocity that the particle develops in this case is a very small fraction (less than 4%) of the initial parallel velocity as can be seen in figures 2(b) and (c) and therefore, the poloidal transit frequency difference between the full-orbit calculation (66.378 kHz) and the guiding center calculation (66.430 kHz) is small, 52 Hz.
Key-particle-orbit frequencies, such as the poloidal transit frequency, and toroidal transit and precession frequencies, which are quintessential for wave-particle interaction studies, are determined in the SPIRAL code using a two-dimensional Fourier transform of the poloidal and toroidal projection of the particle orbit. For the poloidal frequencies the radial   and vertical coordinates are treated as real and imaginary quantities, respectively, for the complex fast Fourier transform. The output is a spectrum with the bounce frequency and its harmonics centered close to zero frequency while the cyclotron frequency and its harmonics form broad structures at higher frequencies. The broadening is caused by the varying magnetic field along the particle orbit. In a similar way the toroidal frequencies are obtained from the projection of the particle orbit in the mid-plane.
Poloidal and toroidal spectra for the orbit depicted in figure 3 are shown in figure 4. The orbit is for an 80 keV deuteron launched at the mid-plane at x = 2.12 m, y = 0.0 m with a pitch of 0.8. The fundamental cyclotron frequency is clearly visible between ±12 and 18 MHz while the second and third harmonic cyclotron harmonics are visible at twice Static electrical fields in plasma equilibria arise from plasma rotation and pressure gradients: with v plasma the bulk plasma toroidal velocity, p is the plasma pressure, q is the charge of the fast ion and B is the equilibrium magnetic field. These static electrical fields can be included in SPIRAL calculations as an electrical potential function ( p ).

Slowing-down and pitch-angle scattering
Before discussing perturbative fields that are included in SPIRAL we will first discuss slowing-down and pitch-angle scattering in 3D geometry and the particle distributions that can be included in the code. On their journey through the plasma the fast ions lose energy to the background thermal plasma. At high fastion velocities the energy loss is mainly to the electrons without substantial scattering but when the fast ions approach thermal velocity the interaction with the thermal ions becomes important and the ion interaction gives rise to pitch-angle scattering.
Traditionally, slowing-down and pitch-angle scattering are written in guiding center formalism [19] as a collision operator, C, for a distribution of energetic particles, f : with v = |v|, λ = v /v the particle pitch, ν the collision rate given by where n e is the electron density and the Coulomb logarithm, ln , is given by = 12πn e λ 3 D with λ D the Debye radius [20,21] and ν d is the pitch-angle scattering rate given by where the critical velocity, v c is calculated as with m e , (m i , m f ) the electron (plasma, fast-ion) mass, q f is the charge of the fast ion and T e is the electron temperature. The first term of the right-hand side of equation (6) describes the pitch-angle scattering while the second term describes the slowing down whereby the v 3 term is due to fast-ion-electron interactions while the v 3 c comes from fast-ion-ion interactions. From the collision operator (equation (6)) the slowing-down equation: can be obtained. This equation is valid in both the guiding center formalism with v = (v , v ⊥ ) and in full-orbit formalism with v = (v x , v y , v z ) and it is valid for velocities above the thermal velocity of the bulk plasma. When no precaution is taken the fast ions can slow down to zero velocity in simulations where the particles are followed for several slowing-down times as can be seen from equation (10). In long simulations one can avoid this unphysical situation by marking the particle lost to the thermal bulk when the particle energy is close to the local plasma temperature or by switching off the slowing-down acceleration are as follows: with erf(x) the error function and E f = 1 2 m i v 2 is the fast-ion energy. When particle energy is much higher than the thermal energy the error function is one and the particle slows down as usual as can be seen in figure 5(a) while near the thermal velocity the error function goes to zero and the de-acceleration is stopped. In SPIRAL one can either stop following the particle when it reaches thermal velocity or following it to the requested end-time with the slowing-down force turned off as describe above.
The slowing-down time quantifies the time it takes to thermalize the particle and one can specify the velocity slowing-down time, τ v , or the energy slowing-down time, τ E which is half the velocity slowing-down time. The velocity slowing-down time can be calculated from equation (10) as In the high energy limit (v v c ) this becomes τ s = 1/ν but when the velocity is near the critical velocity the energy slowing-down time shortens as is shown in figure 5(b). In SPIRAL measured electron temperature and density profiles are used. Therefore, the scattering rates and critical velocities are dependent on the location of the particle in the plasma.
Pitch-angle scattering in guiding center theory has been derived in [13] for an ensemble of fast ions. The new pitch, λ n , is calculated from the old one, λ o , at discrete time steps, t, as where the time step is chosen in such a way that ν d t 1 and the ± sign is determined randomly at each time step. This operator fulfills the condition that |λ n | 1 − ν d t. In fact, this constraint is slightly too restrictive because it can be shown that there is a small region in pitch space close to |λ n | = 1 that cannot be reached by the particle. This region is given by |λ n | > 1 − ν d t and can be removed by ignoring the factor of two in the first term of equation (13). Removing this factor does not influence the random-walk process due to the pitchangle scattering because the random process is governed by the second term in equation (13).
In contrast to pitch-angle scattering in the guiding center approximation with two velocity components, the full-orbit treatment requires scattering in three dimensions. In this section, we derive the full 3D pitch-angle scattering from geometrical considerations and obtain the 3D equivalent of equation (13). We will also derive the 2D pitch-angle scattering equation (equation (13)) without the extra factor of two in the first term.
In the 3D equivalent of pitch-angle scattering as depicted in figure 6, the fast ion is scattered over a small angle, θ, into a velocity cone around its original velocity, v old . The location on the cone, indicated with φ, is in this case the random variable and averaging is performed by taking a large number of small scattering time steps along the particle orbit.
For the 3D pitch-angle scattering we can choose without the loss of generality the following coordinate system: (p 0 = v o , p 1 =v ⊥o , p 2 = p 0 × p 1 ) withv o andv ⊥o unit vectors defined by the particle velocity parallel and perpendicular to the magnetic field before scattering. The parallel and perpendicular scatter angles are now given by: θ = θ sin(φ) and θ ⊥ = θ cos(φ). From figure 6 it can be seen that the new parallel velocity after scattering becomes Figure 6. Pitch-angle scattering in 3D parallel/perpendicular space.
while the new perpendicular velocities along the p 1 -and which corresponds to a rotation of the old velocity vector over an angle pair ( θ , θ ⊥ ) and therefore, the new pitch, |λ n |, after scattering is naturally restricted to equal or less than one.
Using now the fact that | θ| 1 and expanding the geometrical functions in equations (14) and (15) we obtain the following expressions for the three velocity components: (16) These equations are implemented in the SPIRAL code where the angle, φ, is drawn from a uniform distribution between 0 and 2π .
We can recover the Monte Carlo collision operator (equation (13)) from the 3D results of equation (16) by noting that the expectation of the parallel scattering angle is < θ 2 > φ = θ 2 /2 where < · > φ stands for averaging over φ along the full circle while averaging over the perpendicular scattering angle gives < θ ⊥ > φ = 0. After substituting those values in equation (16) we obtain for the parallel component: where the ± sign which arises from the square root of θ 2 /2 acts as the random variable in the scattering process. If we now identify which is the same result as in equation (13) except for the factor two in the v o term.
The spread in pitch of an ensemble of particles that is initialized at the same location and with the same pitch angle should follow a square-root behavior with time. Both the guiding center and the 3D formulation follow that behavior and are in excellent agreement with each other as can be seen from figure 7 where the spread in pitch of an ensemble of 2500 particles, initialized with zero pitch was followed in time.
There is an important difference in pitch-angle scattering between the guiding center and full-orbit formalism that can affect the calculated orbits. In the guiding center formalism, the orbit of the guiding center is continuous during the scattering while the particle orbit has (small) discontinuous jumps because v ⊥ changes discontinuously when the particle scatters. This can be seen from the expression for the gyroradius, ρ = v ⊥ /ω c . Those discontinuities in the particle orbit are physically unrealistic. In full 3D geometry, the scattering takes place at the particle location and therefore, the orbit of the particle is continuous which is physically correct while the guiding center orbit has discontinuous jumps at each scatter.

Particle distributions
Single-particle-orbit studies are useful to gain insight in the details of the particle-plasma interaction but statistically significant ensembles of particles are needed for fast-ion transport studies. A number of fast-ion distributions can be generated by SPIRAL such as a fusion alpha birth profile and two-temperature Maxwellian distributions. Fast-ion distributions can also be read from an external file. This option is very useful to import the distribution functions as calculated with other codes such as the TRANSP/NUBEAM [22,23] package.
Ensembles of fusion-born alpha particles can be generated by SPIRAL from a given alpha-particle birth profile which is a flux function. The test particles are drawn from that distribution and placed uniformly toroidally and poloidally on the flux surface. The particle pitch is drawn from a uniform pitch distribution, the alpha particle energy is set to its birth energy of 3.5 MeV, and the gyro-phase is drawn from a uniform distribution between 0 • and 360 • .
Maxwellian fast-ion distributions of test particles can be generated from a fast-ion density profile in combination with a parallel and perpendicular temperature profile whereby the profiles are given as flux functions. The parallel temperature can differ from the perpendicular one. In a similar way as fusion-born alpha particle ensembles, Maxwellian ensembles are drawn from the given fast-ion density profile and placed uniformly on its flux surface. The particle energy and pitch are now obtained from the requested local parallel and perpendicular temperatures while the gyro-phase is drawn from a uniform distribution between 0 • and 360 • .
The most flexible way of specifying the fast-ion distribution is to read the distribution from an external file on which the particle birth locations and velocities are written and this option will be exploited in simulations reported in this paper.

Effects of a tearing mode on a beam-ion distribution
The SPIRAL code has been used to calculate accurate statistical representations of the beam-ion slowing-down distributions in an NSTX discharge with and without the presence of a magnetic fluctuations. This study was motivated by the observation of a low-frequency mode that caused a substantial changes in measured FIDA signals. The changes in the FIDA signals are indicative of changes of fast ion distribution function. SPIRAL was used to determine the fastion redistribution associated with modes of tearing or ideal kink nature. Here we report results from the tearing mode case, while the detailed analysis of the ideal kink effect is discussed in [24].
The TRANSP/NUBEAM package was used to generate the beam-ion birth profile for the SPIRAL simulations from the three beam sources that operated at 90 kV acceleration voltage. In figure 8 the distribution of the Larmor radii at the particle birth time for the three energy components of the beam is shown. Larmor radii of up to 19 cm are present at birth which should be compared with the characteristic radial size of the mode (see figure 9(a)) which is on the order of 2 cm on the low-field side and around 10 cm at the high-field side. Because the Larmor radii are larger or comparable to the characteristic mode structure the guiding center approximation is not valid here and a full-orbit treatment of the wave-particle interaction is needed. (Only at thermal energies well below 1 keV the deuterium gyro-radius becomes comparable or smaller then the characteristic mode structure at the low-field side). Moreover, the Larmor radii are also significant compared with the characteristic scale length of the equilibrium field (∼0.5 m) which is outside the validity of guiding center theory. In the calculations 30 000 particles were taken from the 3D beam-ion birth profile as calculated by the TRANSP/NUBEAM package and distributed uniformly in time between 0 and 25 ms. All of the particles were then followed until they reached 25 ms which is more than twice as long as the average energy slowing-down time. Two runs were made. In both runs the toroidal ripple, the radial electrical field from the plasma rotation, slowing-down, and pitch-angle scattering were included but only in the second run the tearing mode was included along the lines explained in section 6. We have used an m/n = 4/1 mode as shown in figure 9(a) with an amplitude ofB r /B = 8 × 10 −3 based on observations, and a mode frequency of 10 kHz. When the mode was taken into account the beam-ion losses increase from 17% to 23%. The calculated slowing-down distribution of the confined particles for the case without the mode is shown in figure 9(b) while in figure 9(c) effects of the mode on the distribution are taken into account. In figure 9(d) the difference between the distribution with and without the mode is shown. From this figure it can be seen that the mode mainly affects the distribution below 35 keV with pitches between 0 and 0.5 which corresponds to mainly trapped ions, while the distribution at higher energies and a more parallel pitch is hardly affected by the tearing mode. The FIDA system of NSTX which registered clear changes in the fast ion distribution in the experiment is not sensitive to the part phase space where the calculated changes occur due to the tearing mode. When a kink mode was used as was reported in [24] changes in phase space were found that were compatible with the FIDA measurements.

Static perturbed magnetic fields
Toroidal ripple and error fields are common phenomena in tokamaks and it has been shown that those fields can contribute significantly to fast-ion losses [25]. Harmonic expansions in the toroidal angle are frequently used in particle-orbit following codes to include those ripple fields [26]. For ripples generated by a finite number of toroidal field coils such an approach works well but in some cases a toroidally and poloidally localized perturbation is created which cannot be decomposed adequately with a manageable number of harmonics. Such highly localized perturbations are expected in front of the TBM in ITER because of the significant amount of ferritic steel that is used in those modules [27]. Two examples of toroidal ripple fields are shown in figure 10 where a conventional ripple induced by a finite number of toroidal field coils is shown for NSTX while a localized ripple in DIII-D that was deliberately induced by a set of coils to create the expected (scaled) fields in ITER induced by one pair of TBMs. The fields in DIII-D were used to study the impact of such localized perturbed fields on the plasma performance [28] and first wall heat loads [29].
In order to include both the harmonic and localized ripples accurately in the SPIRAL code, the radial, b R (R, ϕ, Z), and vertical, b Z (R, ϕ, Z), components of the ripple field are given at a number of toroidally equally spaced planes on an unstructured mesh in (R, Z). On each toroidal plane a 2D Chebyshev polynomial fit is made for the b R and b Z while the toroidal component of the ripple field, b ϕ (R, ϕ, Z), is computed from the condition that the magnetic field is divergence free. For the interpolation in the toroidal direction we have used a quadratic polynomial around each given toroidal plane: with x either R or Z, and i the index of the ith plane. We demand further that the radial and vertical fields and their derivatives are continuous half way between two adjacent planes. In order to calculate the toroidal field we expand the functions b i x (R, Z), u i x (R, Z) and v i x (R, Z) of equation (19) into a finite sum of Chebyshev polynomials and from the condition that the magnetic field is divergence free we can solve the unknown Chebyshev coefficients of the functions u i x and v i x . This involves differentiating the expansions of b i x , u i x and v i x with respect to R and Z, summing the various components, integrating with respect to ϕ and making use of the facts that the field is periodic in ϕ and that the Chebyshev polynomials are orthogonal. All those operations are performed analytically using the Chebyshev expansion coefficients and therefore, the ripple field is guaranteed to be divergence free in the calculations down to the numerical precision of the computer. In most ripple calculations it is sufficient to include about 10-15 coefficients in the radial and vertical direction to describe the ripple fields accurately as is shown in figure 10 for a conventional toroidal ripple in NSTX and a localized perturbation in DIII-D created by the TBM mock-up coils. In this figure it can be seen that the reconstructed toroidal field perturbation in SPIRAL is in excellent agreement with the one that was given.
Three examples of SPIRAL calculations with static magnetic fields are given here. In the first example heat loads on the TBM surface are calculated and compared with measured temperatures. Full-orbit effects in this case only become apparent near the wall at the point where they are lost [29]. In the second example simulated triton losses are compared with neutron signals that were measured during the TBM mock-up experiments in DIII-D [28]. Full-orbit simulations are needed in this case because the tritons are born in the plasma at 1 MeV and have gyro-radii of up to 0.2 m in the DIII-D magnetic fields. In the third simulation the effect of RMPs on the beam-ion confinement is studied for optimizing measurable signals in the planning phase of NSTX experiments. Because of the low magnetic fields in NSTX only full-orbit calculations can give accurate predictions for those experiments.

TBM-induced heat load simulations
Heat loads on the carbon tiles that protect the TBM mockup coils in DIII-D were calculated in the presence of the highly localized TBM error fields as shown in figure 11. Tile temperature rises were then calculated from the simulated heat loads and compared favorably with measured tile temperature rises. Details of this experiment are given in [28,29]. The heat load was caused by 60-80 keV beam ions that are lost shortly after injection before the ions have time to slow down significantly. In order to calculate accurately the location where the particle impacts the wall, it is important to take into account the full-particle orbit because the Larmor radius, in this case up to about 4 cm at the point of impact, is comparable or larger than the characteristic TBM field gradient scale lengths near the tile surfaces. The heat loads from the SPIRAL simulations reproduce the measured temperature increase at the back of the 2.5 cm thick protective carbon tiles in the TBM experiments as was reported in [29].

TBM-induced triton losses
When NBI is injected in DIII-D, a small fraction of the fast deuterium beam ions react with the thermal deuterium plasma: D beam + D plasma → 3 He + n(2.56 MeV)50%, P + T(1.01 MeV)50%.
By measuring the 2.56 MeV neutron signal one can deduce the 1.01 MeV triton birth rate in the plasma because of the equal branching ratios of the two reactions. In DIII-D those 1.01 MeV tritons have a large Larmor radii ( figure 12), up to 20 cm, they are marginally confined, and the orbits of the confined tritons are very sensitive to perturbations of the magnetic field. The confined tritons slow down and react with the thermal deuterium to form 4 He and a 14.1 MeV neutron. Therefore, the ratio between the 2.56 and 14.1 MeV neutrons can be used as a sensitive measure for the triton confinement. In the DIII-D TBM experiments it was found that this ratio decreased by 33 ± 5% [28] when the TBM error fields were engaged.
For a SPIRAL simulation of the triton burn-up measurements we have simulated a typical DIII-D H-mode discharge (pulse 140153) with 5.8 MW of NBI power injected in which the TBM fields were applied. The triton birth profile was obtained from a TRANSP run for this shot. Two SPIRAL runs were made, one without and one with the TBM fields present. In both cases 5000 test particles were followed seen in figure 13. The large majority of the particles that are lost immediately are born on trapped orbits with large banana widths. In fact, after 0.1 ms all the trapped particles are lost and only passing particles are confined. In the simulations without the TBM fields another 0.6% of the initial tritons is lost due to pitch-angle scattering resulting in a confined triton population fraction of 45.6% after 100 ms. When the TBM fields are present, significant losses occur after 0.1 ms. Those losses vanish at around 100 ms as can be seen in figure 13. There are two reasons for the vanishing loss rate: (i) the region of phase space where TBM-induced losses can come from is depleted and because the tritons are well above the critical energy, the depleted phase-space region at high triton energies is not refilled by pitch-angle scattering of low-energy tritons and (ii) the effect of slowing-down on the drift orbits is a shift of the orbits to the plasma center and hence co-going particles move away from the low-field side plasma edge where the TBM error fields are located. At the end of the simulation with the TBM fields only 30.6% of the original triton population is still in the plasma which is a reduction of 33% compared with the run without TBM fields present. This reduction compares very well with the observed value of 33 ± 5% as reported in [28].

RMP-induced beam-ion losses
RMPs can be beneficial for controlling ELM activity but they can have a detrimental effect on the fast-ion confinement, leading to increased losses and fast-ion redistribution. The SPIRAL code has been used in the planning phase of the experiments to investigate at which RMP field amplitudes the effects of fast-ion loss and redistribution become observable in NSTX experiments.
For this study a standard NSTX high-density H-mode discharge was used. The fast-ion beam-birth profile was obtained from TRANSP/NUBEAM for beam source C with a tangency radius of 0.49 m ( figure 14). Particle starting times were distributed uniformly between zero and 25 ms and all the 10 000 particles were then followed until they got lost or reached 25 ms. Slowing-down and pitch-angle scattering were included in the calculations where the energy slowing-down time varied from 23 ms in the core to less than 12 ms near the edge. When the vacuum-field amplitude of the non-resonant RMPs which were added perturbatively to the equilibrium magnetic fields was varied the beam ion losses increased as can be seen in figure 15. The RMP field is expressed as coil current where a coil current of 1.5 kA gives a radial magnetic perturbation of 3 mT at the LFS plasma edge as can be seen in figure 16(a). The RMP-induced losses are concentrated just below the mid-plane at the LFS. When we integrate the losses to the low-field side wall between the mid-plane and 0.5 m below the mid-plane as a function of toroidal angle we can clearly see that the loss pattern is modulated with the n = 3 RMP as is shown in figure 16(b) for the 1.5 kA calculation. Peak heat loads in that region of up to 200 kW m −2 for a 1 MW beam are predicted when the RMPs are present while the heat loads are less than 20 kW m −2 for a 1 MW beam without the RMPs present. The minimum heat load that an infrared camera which is installed on NSTX can detect is less than 100 kW m −2 so it is concluded that RMP generated heat loads can be detected.
With the FIDA diagnostic the confined beam-ion population can be measured [15]. The interpretation of the FIDA signals is not straightforward because of its complicated weighting function in phase space. In the FIDA system on NSTX vertical viewing cords are used which favor lowpitch particles (|v /v| < 0.6) in an energy range between 30 and 60 keV. For a quantitative interpretation of the FIDA signals, fast-ion distributions from amongst others TRANSP  and SPIRAL can be used in the FIDASIM code [30] to calculate the FIDA response to those distributions. For the RMP loss study we have used the fast-ion distribution as calculated with SPIRAL ( figure 17(a)) in the FIDASIM code to predict the FIDA light that is observable as shown in figure 17(b). From this figure it can be seen that the RMPs decrease the confined beam-ion population sufficiently to detect changes in the FIDA light. Therefore, based on the SPIRAL simulations, it was concluded that enhanced RMP induced beam-ion losses can be detected experimentally on NSTX from both temperature measurements of the first wall for the lost ions and FIDA measurements for the confined fast ions.

Time-varying magnetic and electric fields
Simulating the interaction between electromagnetic waves and fast ions is of paramount importance to understand the fast-ion transport in tokamaks and therefore, a spectrum of electromagnetic waves can be included in SPIRAL calculations where we have made a distinction between ideal MHD waves that have no electrical field component in the direction of the local magnetic field and radio-frequency (RF) waves in the ICRF that are launched into the plasma for heating and/or current drive purposes. In general, RF waves have an electrical field component parallel to the magnetic field. In SPIRAL the electromagnetic waves are taken as harmonic waves in the toroidal direction (see [31]): with e(R, Z) and b(R, Z) the complex fields that describe the poloidal distribution of the wave fields, n is the toroidal mode number and ω is the mode frequency. The electric fieldẼ and magnetic fieldB are related to each other by Maxwell's laws.
Ideal MHD codes such as NOVA [31,32] calculate amongst other quantities the plasma displacement, ξ , on a mesh inside the plasma. The plasma displacement can be used to obtain the electrical and magnetic wave fields for the mode fromẼ Evaluating theẼ from ξ and B can be done accurately. However, extractingB from equation (21) is numerically highly inaccurate because the curl operator requires the subtraction of large but almost equal terms. These terms have to be known with a very high precision to calculateB accurately. Ideal MHD codes usually give as an output the fluctuating magnetic field which is calculated accurately inside NOVA. We have used the plasma displacement together with magnetic fields as calculated by NOVA as input of the MHD fluctuations for SPIRAL. The plasma displacement and fluctuating magnetic fields are given by NOVA on a discrete mesh and we have used again Chebyshev polynomial expansions to interpolate those quantities. The fluctuating electrical field is obtained from the plasma displacement and equilibrium magnetic field followed by a Chebyshev polynomial expansion: Depending on the size of the structures in the MHD fields, 50-100 basis functions are needed for each coordinate. The ideal MHD condition,Ẽ · B = 0 is fulfilled automatically in this way and tests have shown that the fitted electrical fields satisfy this condition better than 10 −4 . The accuracy of the ideal MHD condition was improved further during the orbit calculations by adding tiny corrections to the fluctuating electrical field that forces the parallel electrical field to zero. This correction forẼ is usually less than 0.1 V m −1 whileẼ ⊥ is typically 10 3 V m −1 or higher for TAEs. In a similar manner the radial,B R , and vertical,B Z , components of the magnetic field as calculated by NOVA are interpolated with Chebyshev polynomials and the toroidal field component,B ϕ , is calculated analytically from the divergence free condition imposed by Maxwell's equations and the Chebyshev coefficients ofB R andB Z . The integration over the toroidal angle is analytically simple because of its harmonic dependence (equation (20)). Numerically, the procedure for obtaining the toroidal field component is robust because it does not depend on subtle cancellations of large terms as was the case with the curl operator. When following a particle through the plasma we have to evaluate now two complex fluctuating fields,Ẽ(R, Z) andB(R, Z), which can be done efficiently at each (R, Z) location: the Chebyshev basis functions are evaluated once followed by the multiplication of the coefficients for each of the twelve field components. The complex fields are then multiplied by the toroidal and harmonic dependence, exp(−i(nϕ + ωt)) and the real part is used in the orbit-following calculations.
Fitting the fluctuating electrical and magnetic fields independently that were obtained in accordance with Maxwell's equations by NOVA does not guarantee that the fitted fields obey Maxwell's laws but where possible comparisons were made and the fitted fields were consistent. Moreover, It can be seen from equation (21)   electrical field fluctuation amplitude is proportional to the mode frequency while the magnetic fluctuation amplitude is independent of the mode frequency. Hence, for low-frequency MHD activity the perturbed magnetic fields are dominant while at high frequencies the perturbed electrical fields become dominant. Therefore, small deviations of the independently fitted fields from the constraints of Maxwell's equations are tolerable because usually only the magnetic or the electrical field fluctuations are dominant. The alternative, evaluating the curl operator in equation (21), is less accurate as discussed earlier.

Single partice resonances
A reversed shear Alfvén eigenmode as calculated with the NOVA code is shown in figure 18 where the radial (a), surface (b), and the parallel (c) components of the fluctuating magnetic field are shown together with the radial (d) and surface (e) components of the electrical field. The parallel electrical field is zero within the numerical accuracy of the calculation. In figure 18(f ) a deuteron orbit is shown where the deuteron was followed for 1 ms. During this time interval the mode frequency increased linearly from 67.5 to 93.5 kHz. The particle was launched on the mid-plane at a major radius of 1.95 m with an initial energy of 74 keV. After a number of poloidal passages the particle starts to resonate with the mode during a number of poloidal transits as can be seen from the velocity and energy traces in figure 19. It quickly gains energy (figure 19(c)) with a significant change in perpendicular velocity ( figure 19(a)) while the parallel velocity is not affected ( figure 19(b)) and its orbit shrinks by about 3 cm as can be seen in figure 19(d).
Resonant interactions between MHD modes and fast particles are important for fast-ion transport in plasmas where the linear resonances are given by with ω MHD the frequency and n is the toroidal mode number of the mode, ω t is the particle poloidal transit frequency, ω φ is the toroidal transit frequency and p is the bounce harmonic number [33][34][35]. At a given location, the transit frequencies depend on the energy and pitch. The resonances can be determined in energy-pitch phase space by scanning the energy and pitch at a fixed initial location as is shown in the red diamonds in figure 20 for the RSAE of figure 18 at 85 kHz where the poloidal and   figure 18 for particles launched at the mid-plane at a major radius of 1.95 m. The red diamonds were determined from the toroidal and poloidal transit frequencies while the blue curves are a measure for the energy exchange between the particle and the mode where an excursion of 0.1 in pitch corresponds to a change in energy of 1 keV. toroidal transit frequencies were determined with the Fourier method as discussed above.
The resonance condition, however, does not give information on the strength of the interaction between the particle and the wave. This information can be obtained by studying the energy exchange between the mode and the particle. As a numerical experiment, we have launched particles at the mid-plane at a major radius of 1.95 m, scanned the pitch and energy, and recorded the minimum and maximum energy excursion that the particle makes during a 3 ms time interval due to the RSAE where we have used a very low RSAE amplitude with a maximum density fluctuation ofñ/n = 10 −4 to obtain only the linear resonances as given by equation (23). From figure 20 it can be seen that the locations where the mode exchanges energy with the RSAE coincide very well with the resonances as calculated from equation (23). A good coupling between the particle and the mode occurs for resonances with a pitch between −0.25 and 0.05 and 0.25 and 0.75. Outside those pitch ranges the interaction between wave and particle becomes weak.
When we increase the RSAE amplitude to an experimentally more realistic value ofñ/n = 4 · 10 −3 , the resonances broaden as can be seen in figure 21 and new fractional resonances appear due to the non-linear interaction between the particle drift orbit and the mode as explained in [36]. The effect of the increased number of resonances and the broadening is that the resonances can overlap more easily, leading to chaotic particle orbits and enhanced fast-ion transport [36,37].

TAE-induced fast-ion redistribution
TAEs appear regularly in NSTX as short (less than 2 ms as shown in figure 22(b) bursts when NBI heating is applied. Those modes reach large transient amplitudes and the mode frequency is changing rapidly as can be see in figure 22(a). The curves shown in figures 22(a) and (b) are polynomial fits to the measurements that are used in the SPIRAL simulations whereby the mode amplitude was determined from reflectometer measurements and the frequencies were measured with Mirnov coils. Those modes affect the fast-ion population and in the following we will show how the SPIRAL code can model the fast-ion redistribution in the presence of those TAE bursts.
In the time period preceding the TAE bursts the plasma was quiescent while 6 MW of NBI was injected from all three beam sources so that the fast-ion distribution at the onset of the TAE burst can be described well as slowing-down distribution. This slowing-down distribution was calculated with SPIRAL from the NBI-birth profile as obtained from the TRANSP/NUBEAM codes by loading 30 000 particles from all three energy components uniformly in time between 0 and 50 ms. Those particles were then followed with SPIRAL until 50 ms where slowing-down and pitch-angle scattering were included. Particles that approach the thermal energy, in this case set at twice the local temperature, before they reached 50 ms were not followed any longer and marked as thermalized. The location of the particles in the parallel and perpendicular velocity phase space is shown in figure 23(a).
This distribution was then modified by the burst of TAEs after 2 ms as shown in figure 23(b) while particles were being added from the birth profile with the same rate as during the first 50 ms (i.e. the beams continued to fuel the plasma during the TAE bursts with the same rate as before). The mode amplitudes and frequencies varied continuously with time in the simulations according to curves shown in figures 22(a) and (b). It can be seen in figure 23(b) that some particles get accelerated in both the parallel and perpendicular direction to above the beam-injection energy and that a fraction of the particles, mainly with low pitch (v /v) values get lost to the plasma boundary. The lost particle rate clearly coincides with the onset and growth of the modes as can be seen in figure 22(c) and in total 18% of the fast ions are expelled in 2 ms.
The modes have also a significant effect on the confined fast-ion distribution as is depicted in figure 24 where we show the evolution of the confined fast ions between −25 and 25 cm around the mid-plane. When the n = 2 TAEs amplitude increases after 0.2 ms and the n = 4 and 6 TAEs appear, the fast-ion profile collapses and broadens toward the high-field side. This is shown more clearly in figure 22(d) where the mid-plane distribution minus the distribution at the on-set of the TAEs is shown. The collapse of the peak is visible as a The change in the distribution is a reflection of changes in the different particle classes as shown in figure 25. When the TAEs become active a fraction of particles on stagnation orbits which are located on the low-field side are changed into passing orbits which traverse the high-field side. This explains the broadening of the distribution. The particle population on stagnation orbits is also found to be sensitive to getting lost which contributes significantly to the flatting of the distribution as shown in figure 24. The fraction of trapped particles and particles on potato orbits is only slightly affected by the burst of TAE activity as can be seen in figure 25.

ICRF fields
In contrast to ideal MHD modes, externally launched RF fields for plasma heating and current drive have in general an electrical field component parallel to the magnetic field direction. The full-wave code TORIC [38] can calculate the ICRF fields in tokamaks and its output routines were adapted to create an output file with RF fields that can be read directly by SPIRAL. In SPIRAL the TORIC fields are fitted in the same way as for the MHD modes but without the restriction of a vanishing parallel electrical field component. Because SPIRAL is a full-orbit code, the interaction between the gyro-motion of the particle and ICRF fields is included naturally. This is different from guiding center codes where a kick-operator has to be constructed to include the RF interaction [8,9]. In this section, we will show results from two simulations in which RF fields are included. The first one is a study of ICRF absorption by NBI ions in ITER in which only the fundamental resonance layer exists in the plasma [39]. In the second study results are presented for HHFWs in NSTX where multiple overlapping resonances are present in the plasma [40].
In the TORIC calculations that were used below, the effects of the fast-ion currents generated on the dielectric tensor were calculated from a Maxwellian distribution. As it will be shown below, the fast-ion distribution is highly anisotropic. For an accurate comparison between the simulations and experiments the TORIC should include those non-Maxwellian distributions.

ICRF heating in ITER
One of the plasma heating schemes for ITER is a 20 MW ICRF system. This system can be tuned to 52.5 MHz which is the on-axis fundamental resonance frequency of 3 He minority plasma species ( figure 26(a)). The 3 He should absorb most of the power but the 52.5 MHz deuterium resonance is also present in the plasma near a major radius of 5.2 m as shown in figure 26(a) and deuterium ions which form a slowing-down distribution from the 1 MeV beams can absorb some of the ICRF power thereby reducing the heating efficiency of the on-axis 3 He minority heating. In figure 26(a) an orbit of a deeply trapped 500 keV deuterium particle is shown that passes through the resonance layer. The energy of this particle during one poloidal transit is shown in figure 26(b) together with the  local deuterium cyclotron frequency at the particle location (figure 26(c)) and its parallel velocity ( figure 26(d)). From figure 26(b) it can be seen that the particle gets a kick in energy when it crosses the Doppler shifted resonance layer where the duration of one kick is about 1 µs or 50 gyro-periods as can be seen in figure 27. Note also that away from the resonance a beat wave between the gyro-motion of the particle and the ICRF frequency can be seen. The Doppler effects on highenergy particles are significant; in this case the resonance is shifted from 52.5 to 50 MHz on the outer leg while resonance occurs at 54 MHz on the inner leg. From figure 26(a) it can be seen that the 50 and 54 MHz resonance layers are some 20-30 cm away from the 52.5 MHz layer and therefore, it can be concluded that the ICRF resonance layers for energetic beam ions in ITER can be substantially broadened due to Doppler effects. For a high 3 He minority heating energy efficiency the deuterium beam ions should not absorb energy from the ICRF field. We have calculated the energy exchange between the ICRF waves and the beam ions by following 10 000 particles drawn from the beam-ion deuterium slowing distribution as obtained from TRANSP for 1 ms in SPIRAL with the 20 MW RF field as modeled with TORIC. From the energy gain of this ensemble the total absorbed power for the beam ions was calculated as 0.08 MW which is small compared with the 20 MW input power from ICRF and so it can be concluded that ICRF power absorption on beam ions in ITER is not important. The 0.08 MW compares well with the 0.06 MW as found with the TORIC code in which the fast-ion distribution was approximated by a Maxwellian distribution.

HHFW heating in NSTX
In contrast to conventional tokamaks, multiple resonances for HHFW heating are present in spherical tokamaks like NSTX as can be seen in figure 28(a) where all the resonances between the second and the 11th harmonic are present. The drift orbits of the particles usually intersect more than one resonance and therefore, the particles can interact with multiple resonances. In figure 28(a) the orbit of a 20 keV deuteron is shown that was launched at the upper turning point on the 5th harmonic resonance layer. Despite crossing all of the harmonic layers between five and eleven, it only exchanges energy at the 5th harmonic layer (figures 28(b) and (c)) where it bounces and its parallel velocity is zero as can be seen in figure 28(d). The duration of the kick in this case is about 3 µs or 18 gyroperiods. At the other resonance layers the particle lingers for much shorter periods, often less than one or two gyro-periods, and therefore, it does not interact effectively with those layers.
Similar to the ITER case, the HHFW can couple to a population of fast ions that is created with NBI heating in NSTX and reduce the HHFW heating efficiency. We have used the SPIRAL code to estimate the amount of power that is absorbed by the beam ions. For this study we calculated the fast-ion slowing-down distribution from the beam deposition profile by loading 20 000 particles uniformly over a 50 ms time interval. Those particles were then followed to 50 ms without the RF fields present resulting in the slowing-down distribution shown in figure 29(a). This distribution was then followed from 50 to 51 ms in the presence of the 1 MW of HHFW power. During this interval beam ions from the birth profile were also loaded with the same rate as in the first 50 ms to simulate the continued beam fueling. The resulting distribution in parallel/perpendicular phase space is shown in figure 29(b) where the black dots represent particles that were confined  at 51 ms while the particles that were lost during the 1 ms HHFW heating phase are marked with orange dots. From this figure it can be seen that the particles only gain perpendicular velocity from the HHFW in contrast to interactions with MHD activity where both parallel and perpendicular velocity changed ( figure 23).
The parallel and perpendicular energy distribution spectra ( figure 30) show the formation of a high-energy tail in the perpendicular energy ( figure 30(a)).
The majority of the accelerated ions are lost during the 1 ms HHFW heating interval while the parallel confined energy distribution ( figure 30(b)) is hardly changed by the HHFW. The lost ions, however, have gained parallel energy which can be understood from their orbits. The parallel energy of trapped particles varies between zero at the bounce points to a maximum on its outer leg as can be derived from the velocity trace shown in figure 28(d). The HHFW increases the perpendicular particle energy near the bounce point. This increases the size of the drift orbit and the maximum parallel energy of the particle at its largest major radius. Those accelerated particles then get lost at the LFS near the mid-plane with an increase in parallel energy that was obtained from HHFW at the bounce point.
From the 1 MW of HHFW power that was used in this simulation 21 kW (or 2.1% of the injected HHFW power) was absorbed by the fast ions and 16 kW of that power was lost to the wall. Although a small amount of HHFW power is carried away by the accelerated fast ions, the impact of the waves is very severe for the fast-ion population. In the 1 ms when the HHFW are present 13% of the fast particles are lost. In a separate run where NBI injection into a HHFW heated plasma was simulated for 5 ms it was found that up to 53% of the injected particles were lost while in the absence of the HHFW power only 13% of the ions were lost as first-orbit losses. Therefore, HHFW heating in combination with NBI heating seems to lead to a decreased plasma performance in NSTX.
The perpendicular energy gain is also reflected in the increase in Larmor radii as shown in figure 31. The separation between the different HHFW harmonics ( figure 28(a)), about 16 cm in this simulation, is comparable or smaller that the gyro-radii of the high-energy particles and therefore, particles can interact with two resonance layers at one gyro-orbit. The effects of this harmonic overlap is currently being investigated theoretically [41].
In order to model the interaction between HHFW and NBI accurately, the effects of the fast-ion currents generated by the NBI and HHFW on the dielectric tensor must be included in the calculation of the HHFW fields. In the TORIC code the dielectric tensor is currently calculated from a Maxwellian distribution. For an accurate comparison between the simulations and experiments the TORIC code is being modified to include non-Maxwellian distributions in the calculation of the dielectric tensor [42]. Because the RF waves modify the fast ion distribution which in its turn modifies the dielectric tensor and hence the TF fields in the plasma, an iterative procedure between SPIRAL and TORIC is being developed to study the HHFW-induced modifications of the fast-ion distribution and its feedback to the RF fields in the plasma for detailed comparison between simulations and experiments.
The HHFW couples most efficiently to the high-energy particles from the slowing-down distribution and not to the bulk thermal plasma as can be seen in figure 32 where particles with initial energies above 10 keV get accelerated significantly. The thermal plasma temperature in the center used in the simulations was 1.5 keV while the distribution above 10 keV is part of the non-Maxwellian beam-ion slowingdown distribution. This again highlights the point that non-Maxwellian distribution functions should be taken into account in the RF-field calculations for a detailed comparison with experiments.  Figure 32. Energy gain as function of the particle energy at the start of the 1 ms HHFW heating for an NBI slowing-down distribution as shown in figure 29. The black marks represent particles that are confined after 1 ms while the orange dots represent the lost particles.

Conclusion
In this paper, we have given a description of the numerical methods used in the full-particle-orbit following SPIRAL code together with a number of physics studies performed with the code to illustrate its capabilities. Full-orbit effects are important for fast-ion experiments in low-field machines such as NSTX. The SPIRAL code is written as a tool to be used in the analysis and interpretation of fast particle experiments and it is also useful in the planning phase of experiments to investigate their feasibility.
Apart from the toroidally symmetric equilibrium magnetic fields, time independent toroidal ripple fields, electric fields arising from the plasma rotation, and time dependent magnetic electric fields from MHD modes and ICRF antennas can be included in the SPIRAL code. Pitch-angle scattering in 3D and slowing-down effects, which are important for fast-ion transport studies are also included in the code. Realistic first walls for different machines can be selected in the code so that particle losses and heat loads in the first wall can be studied accurately. A large number of variables is written in the output file (appendix B) for access with a post-processor code so that the results can be studied in detail and routines are available to explore the output further with the Interactive Data Language (IDL) [43].
In this paper, we have shown some results of studies performed with the SPIRAL code where full-orbit effects play a role. The exact location of hot spots created by fast-ion losses depends on the gyro-radius, especially in combination with strong magnetic field gradients which are present close to the wall in the TBM experiments in DIII-D. Finite gyroorbit effects are also dominant for the calculation of the 1 MeV tritium burn-up experiments in the presence of the TBM fields.
Fast-ion gyro-radii in NSTX are large because of its low magnetic field while the typical scale of TAEs are on the order or smaller than those gyro-radii which justified a full-orbit treatment for the interaction between TAEs and fast ions. It was found that a short burst of TAEs can redistribute the fast ions and induce significant losses.
The interaction between ICRF and/or HHFW and fast ions depends solely on the gyro-motion of the fast ions. We have shown for an ITER plasma that the wave-particle interaction occurs naturally in the SPIRAL calculations while in a preliminary study for NSTX we found that the HHFWs couple efficiently to the energetic beam ions. The beam ions got accelerated where their gyro-and drift-orbits increase so that they do not fit into the machine any more and get lost to the wall.
Although, where possible, comparisons between full-orbit and guiding-center calculations were made, an exhaustive study between the two calculations is beyond the scope of this paper. For unambiguously studying the differences between the two approaches one has to make sure that the differences do not arise from small differences in the magnetic and/or electrical fields in the different codes.