1. Introduction
In the design of any fusion device, the preliminary step is the computation of a plasma equilibrium state with the desired geometry. A plasma in an equilibrium state can be described by the ideal magnetohydrodynamic (MHD) equilibrium model:
where $\boldsymbol {B}$ is the magnetic field, $\boldsymbol {J}$ is the current density, $p$ is the scalar pressure and $\mu _0$ is the permeability of free space. The satisfying of these equations implies that the plasma is in perfect force balance, i.e.
everywhere in the plasma, and the plasma state also coincides with a stationary state in the plasma potential energy,
where $V$ is the plasma volume and $\gamma$ is the adiabatic index.
In tokamaks, the plasma is typically taken to be axisymmetric, allowing the MHD equilibrium to be described by the Grad–Shafranov equation, for which there exist analytic solutions (Cerfon & Freidberg Reference Cerfon and Freidberg2010; Guazzotto & Freidberg Reference Guazzotto and Freidberg2021) and efficient codes to numerically solve for equilibria (Lao et al. Reference Lao, John, Stambaugh, Kellman and Pfeiffer1985). However, the problem becomes much more difficult without the assumption of axisymmetry, making stellarator equilibria more challenging to compute. Adding to the challenge are the singular currents predicted by ideal MHD to form at rational surfaces in three-dimensional (3-D) geometries (Helander Reference Helander2014). While this is an important topic to note, it is not elaborated upon in this work and is left to future endeavours.
Very few analytical solutions to the general 3-D equilibrium problem are known (Rosenbluth, Dagazian & Rutherford Reference Rosenbluth, Dagazian and Rutherford1973), and so typically 3-D equilibria must be found numerically. Thus, a fast, robust and accurate 3-D equilibrium solver is necessary for stellarator optimization studies. The current workhorse code for 3-D equilibria is VMEC (Variational Moments Equilibrium Code) (Hirshman & Whitson Reference Hirshman and Whitson1983), which is integrated into all current stellarator optimization workflows (Spong et al. Reference Spong, Hirshman, Whitson, Batchelor, Carreras, Lynch and Rome1998; Drevlak et al. Reference Drevlak, Beidler, Geiger, Helander and Turkin2019; Lazerson et al. Reference Lazerson, Schmitt, Zhu and Breslau2020; Landreman et al. Reference Landreman, Medasani, Wechsung, Giuliani, Jorge and Zhu2021). While a relatively robust and widely used code, VMEC still suffers from shortcomings stemming from its issues at the axis and its radial discretization, as well as its legacy design. A new 3-D stellarator equilibrium code, DESC (Dudt & Kolemen Reference Dudt and Kolemen2020; Dudt et al. Reference Dudt, Conlin, Panici, Unalmis, Kim and Kolemen2022), has been developed which can overcome these issues.
In this first part of a three-part series on DESC, a comparison of DESC and VMEC equilibria is conducted to show the advantages of DESC's equilibrium solver. Section 2 reviews the existing 3-D equilibrium codes, while section 3 details the two codes compared in this paper, VMEC and DESC. Section 4 defines the method of comparison and accuracy metrics used and section 5 presents the results of the comparison of accuracy in terms of equilibrium solution and stability calculations.
Part 2 (Conlin et al. Reference Conlin, Dudt, Panici and Kolemen2023) of the three-part series presents a novel perturbation and continuation method used by the DESC code for solving and optimizing stellarator equilibria. The efficiency and utility of the method are shown in the computation of complicated equilibria, highlighting the benefits of automatic differentiation. Part 3 (Dudt et al. Reference Dudt, Conlin, Panici and Kolemen2023) presents DESC's unique stellarator optimization capabilities made possible by the efficient equilibrium solver and the perturbation method described in the earlier parts, resulting in a speed-up in optimization by orders of magnitude. These advantages are shown in the context of quasi-symmetry optimization, where results are compared with conventional tools (Spong et al. Reference Spong, Hirshman, Whitson, Batchelor, Carreras, Lynch and Rome1998; Lazerson et al. Reference Lazerson, Schmitt, Zhu and Breslau2020). Three different quasi-symmetry objective formulations are also shown, with the relative advantages of each compared, highlighting the flexibility of DESC as an optimization code.
2. Literature review
Kruskal & Kulsrud (Reference Kruskal and Kulsrud1958) first formulated solutions to the ideal MHD equilibrium problem as a variational principle, and showed that solutions to (1.1) are toroidal equilibria with nested flux surfaces and with pressure as a flux function. The earliest 3-D equilibrium codes utilized this principle, and discretized the spatial coordinates using finite difference schemes (Betancourt & Garabedian Reference Betancourt and Garabedian1976). The BETA code used an inverse coordinate mapping and second-order finite differences motivated by the variational principle to minimize energy and calculate equilibria (Bauer, Betancourt & Garabedian Reference Bauer, Betancourt and Garabedian1978). Later, Chodura & Schlüter (Reference Chodura and Schlüter1981) found equilibria numerically by minimizing $W$ on an Eulerian cylindrical grid.
Eventually, spectral codes (using Fourier series representations in the poloidal and toroidal angles) were employed, which were shown to be substantially more efficient in calculating equilibria than pure difference methods. Schwenn (Reference Schwenn1984) created FIT as a spectral upgrade of the TUBE equilibrium code. Bhattacharjee, Wiley & Dewar (Reference Bhattacharjee, Wiley and Dewar1984) derived a variational method with a spectral Fourier series in angle and Hermite cubic B-splines in the radial direction, and used both a conventional inverse mapping and a mixed coordinate mapping. Hender's NEAR code (Hender et al. Reference Hender, Carreras, Garcia, Rome and Lynch1985) used the same methodology as that of Chodura & Schlüter (Reference Chodura and Schlüter1981), but replaced the cylindrical coordinate system with vacuum flux coordinates and Fourier-decomposed the problem in both angles. Hirshman & Whitson (Reference Hirshman and Whitson1983) detailed the VMEC code, which also solved the inverse equilibrium problem based on the variational principle and using poloidal and toroidal Fourier series. VMEC is widely used in the stellarator community for the improvement its formulation had over existing equilibrium codes, although the radial discretization can lead to inaccuracy near the axis, and is discussed more in section 3.1. Additionally, an updated version of VMEC, GVEC, is currently being developed (Bañón Navarro et al. Reference Bañón Navarro, Merlo, Plunk, Xanthopoulos, von Stechow, Di Siena, Maurer, Hindenlang, Wilms and Jenko2020; Hudson et al. Reference Hudson, Loizu, Zhu, Qu, Nührenberg, Lazerson, Smiet and Hole2020). DESC (Dudt & Kolemen Reference Dudt and Kolemen2020; Dudt et al. Reference Dudt, Conlin, Panici, Unalmis, Kim and Kolemen2022) is a recent pseudospectral code which employs a spectral Fourier–Zernike basis in all three coordinates, and finds equilibria by satisfying the MHD force balance (1.1a) directly at collocation nodes. This choice of spectral basis automatically satisfies the necessary constraints at the axis for analytic functions, and the code is explained more in section 3.2. Each of these codes assumes nested flux surfaces, so multiple magnetic axes (i.e. islands) cannot be represented in their equilibrium representation.
Other 3-D equilibrium codes have been created which are able to handle islands and even chaotic regions. PIES (Reiman & Greenside Reference Reiman and Greenside1986) solves for the equilibrium magnetic field by iteratively evolving pressure-driven currents and re-solving for $\boldsymbol {B}$ with Ampere's law, solving the differential equations by angular Fourier decomposition and finite differences for the radial discretization. The BETA code was rewritten as the spectral (in angles) BETAS code (Betancourt Reference Betancourt1988), which used a coordinate system capable of representing non-nested flux surfaces, and later was the basis of the NSTAB (Taylor Reference Taylor1994) 3-D equilibrium and stability code. NSTAB used a method of finding the magnetic axis location using a residue condition obtained from the variational principle, as opposed to constraining the axis location based on linear interpolation or Taylor expansion as done by previous codes. SIESTA (Hirshman, Sanchez & Cook Reference Hirshman, Sanchez and Cook2011) is an iterative equilibrium solver, similar to PIES but based on the energy principle, which can handle more complicated magnetic field topologies than BETAS, and relies on a VMEC solution for initialization of the solving procedure. The HINT2 code (Suzuki et al. Reference Suzuki, Nakajima, Watanabe, Nakamura and Hayashi2006) solves the MHD equilibrium problem by introducing artificial viscosity and resistivity to the resistive MHD equations and relaxing to an equilibrium state on an Eulerian grid, without any assumption of nested flux surfaces. SPEC (Hudson et al. Reference Hudson, Dewar, Dennis, Hole, McGann, von Nessi and Lazerson2012) also uses a relaxation method, but in the MRxMHD framework, solving for equilibria using stepped, discontinuous pressure profiles. This method allows for very complicated magnetic field topology, but at the expense of requiring input profiles that may not be realistic. SPEC has recently implemented Zernike polynomials as their radial basis at the magnetic axis, which effectively handles the coordinate singularity present there, similar to DESC (Hudson et al. Reference Hudson, Loizu, Zhu, Qu, Nührenberg, Lazerson, Smiet and Hole2020; Qu et al. Reference Qu, Pfefferlé, Hudson, Baillod, Kumar, Dewar and Hole2020).
3. Code descriptions
3.1. VMEC
The most widely used 3-D equilibrium code in the stellarator community at present is VMEC (Hirshman & Whitson Reference Hirshman and Whitson1983). VMEC constructs equilibria by minimizing the MHD energy (1.3) through a variational principle. The base geometry is a cylindrical coordinate system $\boldsymbol {x} = (R,\phi,Z)$. VMEC uses as its computational grid the coordinates $\boldsymbol {\alpha } = (s,u,v)$, with $s$ being a radial coordinate proportional to the normalized toroidal flux, $u$ a poloidal-like angle and $v$ is the geometric toroidal angle (i.e. same as cylindrical $\phi$):
where $\psi$ is the toroidal flux enclosed by a flux surface, normalized by $2{\rm \pi}$, $\psi _a$ is the normalized toroidal flux enclosed by the plasma boundary (i.e. at $s=1$), $N_{FP}$ is the number of field periods in the configuration and $\lambda (s,u,v)$ is a function periodic in $(u,v)$ that converts $u$ to a magnetic poloidal angle $\theta ^*$ (Helander Reference Helander2014).
VMEC solves the so-called inverse equilibrium problem, where the flux surface positions are taken to be functions of the computational coordinates, and the equilibrium is found by solving for the mappings $R = R(s,u,v), Z = Z(s,u,v)$ and the stream function $\lambda (s,u,v)$. These functions are expanded in a Fourier series in poloidal and toroidal angles as
where $X = \{R,Z,\lambda \}$. Coefficients $R_{mn,c}(s)$, $R_{mn,s}(s)$, $Z_{mn,c}(s)$ and $Z_{mn,s}(s)$ are the Fourier coefficients of the flux surface at normalized toroidal flux $s$. The $c,s$ subscripts denote $\cos$ and $\sin$ coefficients, respectively. Numbers $m,n$ are the poloidal and toroidal mode numbers, $M,N$ are the poloidal and toroidal resolutions, with $0\leq m \leq M$ and $-N \leq n \leq N$. Many solutions of interest exhibit stellarator symmetry, that is, $R(s,-u,-v) = R(s,u,v),~Z(s,-u,-v) = -Z(s,u,v)$, and in these symmetric cases the $Z_{mn,c},R_{mn,s},\lambda _{mn,c}$ terms can be dropped from the representation, reducing the computational workload. With this Fourier decomposition, the spectral width is defined as (Hirshman & Breslau Reference Hirshman and Breslau1998)
where $p \geq 0,q>0$ and $R_{mn},Z_{mn}$ are the Fourier coefficients for poloidal mode $m$ and toroidal mode $n$. Here $\lambda$ is chosen so as to create the most efficient Fourier representation of the surfaces, in the sense that it minimizes the spectral width (Hirshman & Breslau Reference Hirshman and Breslau1998).
Due to the spectral expansion being only in the angular coordinates, any radial derivatives necessary are calculated using first-order finite differences between neighbouring flux surfaces.
Through Gauss's law and with the assumptions of nested flux surfaces ($\boldsymbol {B} \boldsymbol {\cdot } \boldsymbol {\nabla } s = 0$) and pressure as a flux function ($p = p(s)$), the magnetic field can be written in contravariant form as
where $\chi (s)$ is the poloidal flux enclosed by the flux surface labelled $s$ normalized by $2{\rm \pi}$. Vectors $\boldsymbol {e}_{\alpha _i} = {\partial \boldsymbol {x}}/{\partial \alpha _i}$ are the covariant basis vectors. The contravariant basis vectors are $\boldsymbol {e}^{\alpha _i} = \boldsymbol {\nabla } \alpha _i$, and are related to the covariant basis by
where the Jacobian $\sqrt {g}$ is given by
The contravariant components of the magnetic field are then
where the prime denotes a radial derivative $\partial / \partial s$. Inserting this definition of $\boldsymbol {B}$ into (1.1) yields
with the two independent force components:
and the vector $\boldsymbol {\beta }$ in the helical direction:
The current density contravariant components are given as
With these vector fields defined, VMEC then constructs a minimization scheme by taking the variation of the MHD energy in (1.3). This ultimately yields an equation for the variation of $W$ (Hirshman & Whitson Reference Hirshman and Whitson1983):
where $F^{mn}_j$ is the Fourier components of the covariant force components $F_j = (F_R,F_{\lambda },F_Z)$ and $X_{mn,j}$ being the corresponding Fourier coefficients of $(R,\lambda,Z)$. The direction of steepest descent is given by
yielding the partial differential equations to be solved, as making ${{\rm d}W}/{{\rm d}t}=0$ means that a minimum in energy, and an equilibrium configuration, has been found. In the VMEC code, the above time operator is replaced by a second-order Richardson scheme (Hirshman & Whitson Reference Hirshman and Whitson1983):
where $\tau$ is chosen to be on the time scale of the least damped eigenmode. VMEC, in fixed-boundary mode, then takes as inputs the pressure and either the rotational transform or the net toroidal current profile as flux functions (the rotational transform is given by $\iota (s) = \chi '/\psi '$), along with the Fourier series describing the desired boundary shape, $R_b(u,v), Z_b(u,v)$.
3.2. DESC
DESC (Dudt & Kolemen Reference Dudt and Kolemen2020), another 3-D equilibrium code developed recently, is a pseudospectral code that finds equilibria by minimizing the MHD force balance error (1.2) directly at collocation nodes, as opposed to minimizing energy through a variational principle. Similar to VMEC, the base geometry is a cylindrical coordinate system $\boldsymbol {x} = (R,\phi,Z)$. DESC uses as its computational grid the coordinates $\boldsymbol {\alpha }_{{\rm DESC}} = (\rho,\theta,\zeta )$, with $\rho$ being a radial coordinate proportional to the square root of the normalized toroidal flux, $\theta$ a poloidal angle and $\zeta$ is the geometric toroidal angle, the same angles as are used by VMEC (note that this is different from the original publication (Dudt & Kolemen Reference Dudt and Kolemen2020), which used the straight-field-line $\theta ^*$ in the computational domain):
where, similar to VMEC, $\lambda (\rho,\theta,\zeta )$ is a function periodic in $(\theta,\zeta )$ that converts $\theta$ to a magnetic poloidal angle $\theta ^*$ (Helander Reference Helander2014).
DESC, like VMEC, solves the inverse equilibrium problem. Unlike VMEC, DESC expands $R(\rho,\theta,\zeta ),Z(\rho,\theta,\zeta ),\lambda (\rho,\theta,\zeta )$ in spectral bases in all three coordinates, using a Fourier series toroidally and Zernike polynomials in the radial and poloidal directions (Zernike & Stratton Reference Zernike and Stratton1934; Sakai & Redekopp Reference Sakai and Redekopp2009):
where $\mathscr {Z}_l^m$ is the Zernike polynomial of radial degree $l$ and poloidal degree $m$, defined as
With the radial function $\mathscr {R}_l^{|m|}$ as the shifted Jacobi polynomial:
And $\mathscr {F}$ is the typical Fourier series in $\zeta$:
The basis vector and Jacobian definitions given in (3.6) and (3.7) have obvious analogues with the DESC coordinate system, with $(s \rightarrow \rho, u \rightarrow \theta, v \rightarrow \zeta )$. It is worth noting that the choice of Zernike polynomials in the spectral basis ensures analyticity at the magnetic axis. Any analytic function when expanded in a Fourier series near the origin of a disk must have a radial structure that goes as (Lewis & Bellan Reference Lewis and Bellan1990)
where $a_{m,i}$ is the $i$th term in a Taylor series expansion of the $m$th poloidal Fourier coefficient $a_m(\rho )$. With the Zernike basis, any spectral coefficient with poloidal mode number $m$ necessarily has a radial dependence that scales as $\rho ^m$, thus inherently satisfying this constraint and ensuring only physical modes are included in the spectrum of $R$ and $Z$. DESC employs the same nested flux surfaces assumption as VMEC to arrive at a similar contravariant form of the magnetic field:
with contravariant components given by
The MHD force balance equation is
with the two independent force components:
and the vector $\boldsymbol {\beta _{{\rm DESC}}}$ in the helical direction:
which is the same direction as the VMEC $\boldsymbol {\beta }$, but without the factor of $\sqrt {g}$. The current density components are found with (3.12), with DESC coordinates $\alpha _i = (\rho,\theta,\zeta )$. By weighting the force components by volume, one can obtain a system of equations for the total MHD force balance error in the plasma volume (Dudt & Kolemen Reference Dudt and Kolemen2020):
As a pseudospectral code, DESC solves for the equilibrium by solving the force balance error equations (3.28), evaluated on a collocation grid. DESC solves the resulting nonlinear system of equations $\boldsymbol {f}(\boldsymbol {x}) = [f_{\rho },f_{\beta }](\boldsymbol {x})=\boldsymbol {0}$, where $\boldsymbol {x} = [R_{lmn},Z_{lmn},\lambda _{lmn}]$ are the coefficients of the spectral representation (given in (3.17)) of the flux surface positions and the stream function $\lambda$. Newton–Raphson-type methods from Scipy (Virtanen et al. Reference Virtanen, Gommers, Oliphant, Haberland, Reddy, Halchenko and Vázquez-Baeza2020) such as Levenberg–Marquadt are employed as the nonlinear equation solver in DESC, which can achieve quadratic convergence near the solution (Press Reference Press1996). It is worth noting that DESC is flexible enough to find equilibria by minimizing different objective functions, such as MHD energy, but it has been found in extensive testing that using force error is faster (by a factor of two in some cases) and yields better convergence in solving for MHD equilibria in DESC, and so force error minimization is used for the DESC results in this paper. Force is believed to be a better objective for solving equilibria with DESC's pseudospectral formulation because it allows the code to take advantage of local information afforded by the force balance equation, which is already evaluated on the collocation nodes due to the pseudospectral approach. Finally, DESC is similar to VMEC in that, in fixed-boundary mode, it takes as inputs the pressure profile and either the rotational transform or the net toroidal current profile as flux functions (the rotational transform is given by $\iota (\rho ) = \chi '/\psi '$), along with the Fourier series describing the desired boundary shape, $R_b(\theta,\zeta ), Z_b(\theta,\zeta )$.
4. Comparison methods
In order to compare the two equilibrium codes, a common metric must be used. VMEC explicitly minimizes MHD energy using a gradient descent method, while DESC minimizes MHD force error in the plasma volume. To compare the two code results, the resulting solution MHD force balance error is shown, as well as time to solution. To verify the correlation of low force error with accurate calculations of interesting physics metrics, Mercier stability calculated with both codes and compared with asymptotic near-axis formulas (Landreman & Jorge Reference Landreman and Jorge2020) is also shown in section 5.4.
VMEC does not output the force balance error in real space, so it was calculated from the VMEC-outputted Fourier coefficients of $R,Z,\lambda$. The derivation of the equations used for VMEC force balance is given in Appendix A. Once the force error at each point in $(s,u,v)$ space was calculated, both volumetric and flux-surface averages were calculated. The volume average was calculated as
where the radial integration does not include the axis or edge to avoid sensitivities of the force error calculation at these locations. It should be noted that DESC solutions did not have this limitation, and are integrated throughout the entire volume, while the VMEC solutions are only integrated through the above range. This difference could make the VMEC calculations appear to have lower error than the full volume integration would otherwise yield. The flux-surface average at a given radial position $s$ was calculated as
Then to yield a normalized, unitless error metric, the above quantities are divided by the volume average of the pressure gradient magnitude:
With the above normalized error metrics defined, both codes were ran in fixed-boundary, fixed-iota mode to solve equilibria for a W7-X standard configuration, finite beta ($\beta \approx 2\,\%$) equilibrium (Sunn Pedersen et al. Reference Sunn Pedersen, Andreeva, Bosch, Bozhenkov, Effenberg, Endler, Feng, Gates, Geiger and Hartmann2015). The equilibrium used in this paper had the following rotational transform and pressure profiles (given as a power series in $\rho = \sqrt {s} = \sqrt {{\psi }/{\psi _a}}$):
These profiles are plotted in figure 1. The full base input files for VMEC and DESC on which the runs in this paper are based are available in the DESC Github repository (Dudt et al. Reference Dudt, Conlin, Panici, Unalmis, Kim and Kolemen2022), which include the boundary shape Fourier series, which goes up to $M=N=12$.
4.1. VMEC radial derivative
In VMEC, the outputs $(R_{mn},Z_{mn},L_{mn})$, from which derived quantities of magnetic field, current density and ultimately force balance error can be calculated, are given on a discrete radial grid. To calculate the force balance error (1.2), derivatives of $R,Z$ up to second order in each of $(s,u,v)$ are necessary, and in the radial direction these derivatives must be found numerically. A comparison of different numerical derivative methods was carried out to see the sensitivity of the resulting force balance error to the method used. The radial derivatives were carried out on the Fourier coefficients $(R_{mn},Z_{mn},L_{mn})$.
Figure 2 shows the normalized flux-surface-averaged force balance error calculated for a VMEC W7-X equilibrium with $M=N=16$ angular resolution and $ns=1024$ flux surfaces using several different numerical derivative methods: finite difference (second-order and fourth-order central differences; Collatz Reference Collatz1960) and cubic and quintic interpolating splines. It can be seen that the numerical method used does not impact the calculated force error in the majority of the plasma, and mainly changes the calculated force error near the magnetic axis. As there is such a large sensitivity in the force error at the axis to the numerical method used, for all volume averages of force error from VMEC, the radial integration is limited to $s = 0.1 \rightarrow 0.99$, in order to avoid including this sensitive portion of the calculation.
Additionally, there are noticeable spikes observed in the calculated force error of these solutions near the edge, which stem from spikes in the VMEC current densities at those locations. These spikes were observed to appear at locations in $s$ corresponding to coarser grids used in the continuation method (i.e. NS_ARRAY = [16, 32, 64, 128, 256, 512, 1024], and the spikes are at locations corresponding to the ${\rm NS}=32$ grid). They appear as discontinuous jumps and spikes in the first and second radial derivative of the $R,Z$ Fourier coefficients, which propagate to the current density and force error. It is speculated that these are due to convergence issues with the highly shaped equilibrium. These are not due to issues at rational surfaces, as figure 3 plots the parallel current density versus $s$ along $u=v=0$, along with low-order rationals. This figure shows that the spikes do not line up with the rational surfaces, and so are not due to the rational surfaces. Shown in figure 19 in Appendix B are results of running VMEC with increased solver tolerance, and figure 20 shows VMEC runs with higher angular resolution, neither of which completely alleviate the issue. However, for the purposes of this comparison, the spikes are localized enough that they do not significantly affect the volume-averaged error.
5. Results
5.1. Spectral properties
To compare the spectral representations of the two codes, the radial dependence of the spectral coefficients of $R$ and the spectral width defined in (3.3) were calculated and compared. Figure 4 shows the amplitude of each $R_{mn}$ Fourier coefficient factored by its $\rho ^m$ dependence (the DESC solution was transformed here from a global Fourier–Zernike to a Fourier basis on discrete flux surfaces to compare directly with the VMEC solution). The DESC coordinate $\rho = \sqrt {{\psi }/{\psi _a}}$ was factored out from both codes’ coefficients because this radial variable is proportional to the typical polar radius $r$. It can be seen from the figure that while the DESC Fourier coefficient amplitudes are relatively constant with $\rho$, indicative of the correct scaling necessary for analyticity at the origin, the VMEC higher-order mode amplitudes tend to diverge near $\rho =0$. This is evidence of possibly unphysical modes existing near the axis in the VMEC Fourier spectrum.
As a further point of comparison, figure 5 shows the spectral width metric calculated for a DESC and a VMEC W7-X-like finite-beta solution. The spectral width is essentially the same for each code, which is indicative of the stream function $\lambda$ being chosen so as to optimize the Fourier spectrum representation of the flux surfaces. VMEC does this through the Hirshman–Breslau constraint (Hirshman & Breslau Reference Hirshman and Breslau1998), while DESC lets $\lambda$ vary through the course of solving, and the optimization routines arrive at an optimal $\lambda$.
5.2. Numerical convergence
To compare the convergence of the VMEC and DESC codes with respect to radial resolution, a convergence study with each code was carried out using an axisymmetric D-shaped equilibrium similar to that in Hirshman & Whitson (Reference Hirshman and Whitson1983) and Dudt & Kolemen (Reference Dudt and Kolemen2020). The equilibrium used in this paper had the following rotational transform and pressure profiles (given as a power series in $\rho = \sqrt {s} = \sqrt {{\psi }/{\psi _a}}$):
These profiles are plotted in figure 6. The boundary shape and enclosed flux (in Wb) are given by
The full D-shaped input files for VMEC and DESC on which the runs in this section are based are available in the DESC Github repository (Dudt et al. Reference Dudt, Conlin, Panici, Unalmis, Kim and Kolemen2022).
Both the VMEC and the DESC codes use a spectral representation for the angular dependence of their solutions. Consequently, we would expect, assuming a smooth solution, that the error convergence will be exponential with increasing angular resolution (Boyd Reference Boyd2001). However, the codes differ in the radial direction, as VMEC's solution is explicitly represented only on a finite grid and the code employs a first-order finite difference scheme, while DESC's spectral representation describes the solution radially as well as in angle. Thus, we would expect that the radial finite differences in VMEC would limit the radial convergence to be first order, while in DESC we should still see exponential convergence with increasing radial resolution (again, given a smooth solution). This is summarized in table 1.
Figure 7 shows the average normalized force error of a D-shaped solution found with VMEC versus increasing radial resolution. The poloidal resolution for these runs was kept fixed at $M=16$ in both codes. Plotted on a log–log scale, the best-fit line's slope of $-1.02$ clearly shows the first-order convergence of VMEC with increasing radial resolution, as expected. Figure 8 shows the average normalized force error in a DESC D-shaped solution for increasing radial spectral resolution $L$, for fixed poloidal resolution $M=16$. Note that here the plot is now a log–linear scale, where the linear dependence of error on resolution indicates that the error convergence of the DESC solution is exponential with increasing radial resolution, as shown in the legend of the exponential fit of the error to the radial resolution. Through its Fourier–Zernike spectral basis, the DESC code is able to achieve exponential convergence with increasing radial resolution, a scaling unattainable with the limitations imposed by the radial first-order finite differences in the VMEC code. Figure 9 shows the agreement of the flux surfaces between the VMEC solution with $ns=1024$ and the DESC solution with $L=16$, indicating that both codes resolve the same solution qualitatively.
5.3. Comparison of W7-X solution
5.3.1. Flux surface comparison
The flux surfaces of the W7-X equilibrium solution found by DESC ($L=M=N=16$, in red) and VMEC ($ns=1024$, $M=N=16$, in blue) are shown in figure 10. The overlap of the surfaces shows the agreement of the two codes, indicating that they resolve qualitatively similar solutions to the equilibrium problem.
5.3.2. Force error
The normalized force error flux-surface average is compared directly between DESC and VMEC in figure 11. Here, the VMEC solutions noticeably have their largest force error as they approach the axis, while the DESC solutions maintain accuracy in satisfying force balance near the axis. This inaccuracy of the VMEC solutions near axis could be attributed to the modes in its Fourier spectrum which lack the correct radial scaling (shown earlier in figure 4). The oscillations seen in the higher-resolution DESC solutions correspond to the collocation points – lower force balance errors are expected on the surfaces where the residuals were minimized.
Additionally, the average normalized force error and time to solution for an aggregation of a number of DESC and VMEC solutions to the W7-X-like equilibrium run at a range of resolutions are shown in figure 12. The resolution scan ranges are shown in table 2. It is clear that for a given time to solution, DESC is able to achieve a lower average normalized force error than VMEC, indicating that DESC is able to achieve more accurate solutions than VMEC as measured by the force error metric. Often the DESC error is an order of magnitude lower than the VMEC error, as shown by the best-fit lines plotted in the figure. It should be noted that as DESC is written in Python, there is a certain amount of overhead associated with running the code versus a compiled Fortran code like VMEC. While the DESC code employs the JAX (Bradbury et al. Reference Bradbury, Frostig, Hawkins, Johnson, Leary, Maclaurin, Necula, Paszke, VanderPlas and Wanderman-Milne2018) package, which provides just-in-time compilation of code to improve performance, the code must first be called and compiled by JAX before the performance gains are seen. As such, the DESC solutions shown do not have runtimes lower than 2 minutes. However, pre-compilation is a planned future improvement to the JAX package, which will allow the DESC code to avoid costly just-in-time compilation during equilibrium solves, leading to lower initialization times.
5.4. Mercier stability comparison
High-accuracy solutions to the MHD equilibrium equations are crucial for further analyses such as stability. This is well known in the tokamak community, where when solving the Grad–Shafranov equation for an equilibrium reconstruction, EFIT (Lao et al. Reference Lao, John, Stambaugh, Kellman and Pfeiffer1985) Picard iteration errors below $10^{-4}$ (Jiang et al. Reference Jiang, Sabbagh, Park, Berkery, Ahn, Riquezes, Bak, Ko, Ko and Lee2021; Xing et al. Reference Xing, Eldon, Nelson, Roelofs, Eggert, Izacard, Glasser, Logan, Meneghini and Smith2021) have been conventionally accepted as thresholds for reliable MHD stability analyses (Glasser Reference Glasser2016, Reference Glasser2020). These iteration error levels correspond to a similar magnitude of normalized (by the source terms) Grad–Shafranov force error. Note that the previously shown D-shaped tokamak equilibrium solved with DESC passes the required error threshold (in terms of normalized force error) of $10^{-4}$ as shown in figure 8, while the VMEC solution fails to meet this threshold even at high radial resolution, as shown in figure 7.
While no such rule of thumb exists for 3-D equilibria in the stellarator community, VMEC's inaccuracy near the magnetic axis has been found to cause issues when conducting ideal MHD stability analyses near the axis (A.H. Glasser, personal communication 2021).
As an example of higher-accuracy equilibria translating to more accurate stability calculations, the Mercier stability of a configuration described near equation (4.25) of the work by Landreman & Jorge (Reference Landreman and Jorge2020) is calculated, with the same equilibrium solved using the DESC and VMEC codes, and compared with asymptotic formulas from near-axis expansion theory from the same work. The internal routines from DESC are used to calculate its stability metrics, while for VMEC the $D_{{\rm Merc}}$ quantity that is calculated from its own internal routines and stored in its output file is used. The equilibrium is a finite-beta quasi-helically symmetric configuration with an aspect ratio of $\sim$20, and was solved in VMEC at two radial resolutions $ns=[65,801]$. The same equilibrium was also solved using DESC with radial resolution $L=12$ and ANSI spectral indexing. Both codes used a poloidal resolution of $M=12$ and a toroidal resolution of $N=10$. Instead of a fixed rotational transform profile, the equilibria were solved with a zero net toroidal current constraint in each code. The quasi-helical equilibrium used had the following pressure profile (given as a power series in $\rho = \sqrt {s} = \sqrt {{\psi }/{\psi _a}}$):
The pressure profile and the final rotational transform profile from the DESC equilibrium are plotted in figure 13, and the flux surfaces are shown in figure 14, which shows qualitative agreement in the equilibrium solution of the two codes. However, this qualitative agreement does not necessarily lead to quantitative agreement of stability metrics, as shown by the comparison of Mercier stability in this section. Mercier stability (Mercier Reference Mercier1964; Mercier & Luc Reference Mercier and Luc1974) is a measure of an ideal MHD equilibrium's stability to localized interchange perturbations about a rational surface, and the criterion for stability against such perturbations can be defined as (Bauer, Betancourt & Garabedian Reference Bauer, Betancourt and Garabedian1984)
where
Here, $I(\psi )$ and $G(\psi )$ are the Boozer coordinate profile functions (Boozer Reference Boozer1981) and $s_g=\pm 1$ and $s_{\psi } = \pm 1$ are the signs of $G(\psi )$ and of the normalized toroidal flux $\psi$. Furthermore, $\varXi = \mu _0 \boldsymbol {J} - I'(\psi ) \boldsymbol {B}$, $V(\psi )$ is the volume enclosed by the flux surface labelled by $\psi$, and the surface integrals are taken over the given flux surface so that $dS = |\boldsymbol {\nabla } \psi \|\sqrt {g}|\,{\rm d}{\vartheta }\,{{\rm d}\varphi }$. The above equations were used to calculate Mercier stability of the equilibrium solutions from DESC and VMEC.
As a verification exercise, near-axis theory provides asymptotic expressions for the different components of Mercier stability that should match the full expressions above when $\epsilon = r/{R_{{\rm scale}}}$ is small, where here $R_{{\rm scale}} \sim {1}/{\kappa }$ is the scale length of the magnetic axis, $\kappa$ being the axis curvature, $r$ is the effective minor radius, $2{\rm \pi} \psi = {\rm \pi}r^2 \bar {B}$ and $\bar {B}$ is a constant reference magnetic field strength. Regardless of aspect ratio or scale length, the expansion is accurate close to the magnetic axis since $r \rightarrow 0$, and with higher aspect ratio the expansion becomes valid over a larger portion of the plasma volume. In Landreman & Jorge (Reference Landreman and Jorge2020) the asymptotic expressions for $D_{\mathrm {Geod}}$ and $D_{\text {Well}}$, the leading-order (in $\epsilon$) terms of $D_{{\rm Merc}}$, have been derived for quasi-symmetric equilibria:
where (Landreman & Sengupta Reference Landreman and Sengupta2019) $G_0$ is the zeroth-order term of the expansion of the Boozer profile function $G$ in a power series in effective minor radius $r$, $B_0$ is the zeroth-order term in the power series expansion of the magnetic field strength $B$ in $r$, $p_2$ is the second-order term in the power series expansion of $p$ in $r$, $\bar {\eta }$ is a measure of the magnetic field strength variation, $\iota _{N0} = \iota _0 - N$, where $\iota _0$ is the zeroth-order term of the expansion of $\iota$ in $r$ and $N$ is a constant integer, and $\sigma$ is a solution to the ordinary differential equation defined in equation (2.14) of Landreman & Sengupta (Reference Landreman and Sengupta2019).
Thus to leading order, the Mercier stability of a quasi-symmetric stellarator calculated by the full expressions in (5.8) should agree with the sum of (5.9) and (5.10) at small $\epsilon$. Any deviation from agreement in a high-aspect-ratio equilibrium, especially near the magnetic axis, would then indicate an inaccuracy in the underlying equilibrium, as the calculated stability fails to agree with the asymptotic expression in the region where it is most valid.
Figure 15 shows $D_{{\rm Merc}}$ (made negative for the sake of plotting on a log scale, as the equilibrium is Mercier-unstable) of the two equilibria computed with VMEC in red, while that calculated from the DESC equilibrium is in cyan. Plotted as well is the value of $D_{{\rm Merc}}$ given by the asymptotic expressions. It can be seen that the stability computed from the DESC equilibrium agrees well with the asymptotic expression across the entirety of the plasma volume, but most importantly near the magnetic axis, indicating the equilibrium is sufficiently well resolved for accurate Mercier stability calculation. The VMEC equilibrium requires high radial resolution to agree with the asymptotic expression inside of $\rho < 0.5$, and even then differs from the asymptotic value nearer to the magnetic axis, indicating a failure to accurately satisfy the ideal MHD equilibrium equations there. Upon inspection of the individual terms in the $D_{{\rm Merc}}$ sum, the $D_{{\rm Geod}}$ term is the most significant part of $D_{{\rm Merc}}$ in the core of the equilibrium, and it is this dominant term which is responsible for the large deviation in $D_{{\rm Merc}}$ from the asymptotically derived values near the axis. The lack of convergence of $D_{{\rm Geod}}$ in VMEC with increasing resolution has been seen by previous work (Landreman & Jorge Reference Landreman and Jorge2020). This deviation is roughly correlated with the radial position where the force error in each VMEC solution begins to increase sharply nearing the axis, shown in figure 16.
One possible explanation for such a difference in accuracy between the DESC and VMEC solutions is that DESC's 3-D spectral basis results in more accurate radial derivatives as compared with VMEC's finite differencing. Of the two leading-order terms in $D_{{\rm Merc}}$ near the axis, the $D_{{\rm Geod}}$ term requires higher-order radial derivatives of the coordinates $R,Z$, due to the presence of the current density $\boldsymbol {J}$ in the expression. So, an inaccuracy in the radial derivatives would most strongly affect this term, leading to the lack of agreement with the asymptotic result at the axis. This inaccuracy in radial derivatives also manifests itself in worse force error. This shows the importance of accurate equilibria, especially near the axis, as VMEC's lack of accuracy leads to disagreement with asymptotic theory in the region where the theory is most valid, while DESC's accurate treatment of the axis results in accurate Mercier stability calculations as well.
6. Conclusions
In conclusion, a comparison of the VMEC and DESC codes was carried out. DESC was shown to have more accurate equilibrium solutions than VMEC as measured by force balance error, and to have faster runtimes for a given solution accuracy. DESC was also shown to have improved radial convergence as compared with VMEC, owing to its spectral basis in all three coordinates. Further, inaccuracies of VMEC solutions near the axis were seen, which could be tied to the unphysical modes in the VMEC Fourier spectrum that do not scale correctly with radius near the axis. DESC solutions, on the other hand, do not have this problem, and were shown to be accurate near the axis. Solution accuracy is necessary in order to accurately calculate stability metrics, and this is explicitly shown for a Mercier stability calculation, where the DESC solution is found to better agree with the asymptotic expansion near the axis than the VMEC solution. Future plans for development of the DESC code with regards to computation speed include implementing message passing interface parallelization to better take advantage of CPUs and benchmarking the code's graphics processing unit (GPU) capabilities. Pre-compilation of functions with JAX is also foreseen, which should aid in reducing initialization times. Additionally, further DESC verification can include comparing results with other equilibrium codes such as SPEC, and the effect of solution accuracy can be investigated in other metrics such as fast particle confinement.
Acknowledgements
The authors gratefully acknowledge helpful discussions with Matt Landreman concerning near-axis expansion theory and Mercier stability.
Editor Per Helander thanks the referees for their advice in evaluating this article.
Funding
This work was supported by the US Department of Energy under contract numbers DE-AC02-09CH11466 and DE-SC0022005 and Field Work Proposal No. 1019. The United States Government retains a non-exclusive, paid-up, irrevocable, world-wide licence to publish or reproduce the published form of this paper, or allow others to do so, for United States Government purposes.
Declaration of interests
The authors report no conflict of interest.
Data availability statement
The data and scripts used in this paper are freely available on Zenodo (Panici Reference Panici2022) at https://doi.org/10.5281/zenodo.6539680.
Appendix A. Force balance error from VMEC $R,Z,\lambda$ Fourier coefficients
With the cylindrical coordinate system $\boldsymbol {x} = (R,\phi,Z)$, VMEC uses as its computational coordinates $\boldsymbol {\alpha } = (s,u,v)$, with $s$ being a radial coordinate proportional to the normalized toroidal flux, $u$ a poloidal-like angle and $v$ is the geometric toroidal angle for one field period:
where $\psi _a$ is the toroidal flux enclosed by the plasma boundary (at $s=1$) that is normalized by $2{\rm \pi}$, $\lambda (s,u,v)$ is a function periodic in $(u,v)$ that converts $u$ to a straight-field-line poloidal angle $\theta ^*$, $N_{FP}$ is the number of field periods in the device and $\phi$ is the usual geometric toroidal angle coordinate.
The covariant basis vectors $\boldsymbol {e}_{i} = {\partial \boldsymbol {x}}/{\partial \alpha _i}$ for the $\alpha =(s,u,v)$ coordinate system are
and the notation ${\boldsymbol e}_{\alpha \gamma }$ is used as a shorthand for $\partial _\gamma ( {\boldsymbol e}_{\alpha } )$. The Jacobian and its partial derivatives are calculated from the basis vectors as
Contravariant basis vectors $\boldsymbol {e}^{i} = \boldsymbol {\nabla }\alpha _i$ are given by
The metric tensor components are given by
Recall that the magnetic field can be written in the form
and that in the VMEC coordinate system the contravariant components of the field are given by (Hirshman & Whitson Reference Hirshman and Whitson1983, p. 3)
where $2{\rm \pi} \chi (s)$ and $2{\rm \pi} \psi (s)$ are the poloidal and toroidal magnetic fluxes, respectively, the prime denotes a radial derivative $\partial / \partial s$ and $\lambda$ is a function periodic in $u,v$ with zero average over a magnetic surface, $\iint \,{\rm d}u\,{\rm d}v\lambda = 0$.
The MHD force balance equilibrium is given by
The magnetic field can be written as
where $\theta ^* = u + \lambda (s,u,v)$ is a straight-field-line poloidal angle. Inserting (A9a) into (A8a) yields
where
where $\beta = \sqrt {g}(B^v \boldsymbol {\nabla } u - B^u \boldsymbol {\nabla } v)$ and $J^i = \boldsymbol {J} \boldsymbol {\cdot } \boldsymbol {\nabla } \alpha _i = \mu _0^{-1} \boldsymbol {\nabla } \boldsymbol {\cdot } (\boldsymbol {B} \times \boldsymbol {\nabla } \alpha _i)$.
Contravariant components of $\boldsymbol {J}$ can be written with the derivatives of covariant $B$ components $\boldsymbol {B} = B_i e^i$:
The covariant components of $B$ are
The partial derivatives of the contravariant components of $B$ are for $B^u$
and for $B^v$
With these defined, and using (A13), the partial derivatives of the covariant components of $B$ are then
With these, all of the required derivatives to evaluate the force components $F_s$ and $F_\beta$ are known. The magnitudes of the directions of each component are
The magnitude of force balance error is then
Now $R$, $Z$ and $\lambda$ are explicitly known analytically only in $u,v$ on discrete flux surfaces on the radial grid $s$. Function $\lambda$ also is calculated on a half-mesh offset from the main radial grid, and must be interpolated onto the main radial grid first. So, numerical derivatives are used for all of the radial derivatives $\partial _s$ of $R$, $Z$ and $\lambda$ necessary to calculate $\boldsymbol {F}$. The derivatives are carried out on the Fourier coefficients RMNC, ZMNS and LMNS (to get the Fourier coefficients of the derivatives, e.g. ${\partial {\rm RMNC}}/{\partial s}|_{s_i} = {\rm RSMNC} = ({{\rm RMNC}(s_{i+1}) -{\rm RMNC}(s_{i})})/{\Delta s}$).
Appendix B. VMEC force error spikes
In the W7-X finite-beta equilibria computed here, spikes are observed in the calculated force error flux-surface average.
These spikes correspond to discontinuous jumps in the radial derivatives of the Fourier coefficients for $R,Z$, shown in figures 17 and 18 for the $m=3,n=1$ mode of $R_{mnc}$ (chosen only as a representative example; this is seen in other mode numbers as well). Note that these spikes do not correspond to any low-order rationals, plotted in figure 18, so they do not stem from current singularities at rational surfaces. This is further supported by the parallel current density not exhibiting singular behaviour at the rational surfaces plotted, shown in figure 3. Plotted are all rationals $N/M$ in the ranges $M=(1,19),~N=(1,18)$ that lie in the iota profile (the profile is plotted in figure 1).
Running the same equilibrium with higher solver tolerances (shown in figure 19) and with higher angular resolution (such as in figure 20) does not completely eliminate these spikes. Increasing the FTOL parameter past $1\times 10^{-14}$ resulted in the equilibrium solve taking prohibitively long (longer than 24 h when run with 32 GB RAM on a single AMD EPYC 7281 CPU), so the tolerance scan at ${\rm NS}=1024$, $M=N=16$ was not carried out past ${\rm FTOL}=1\times 10^{-14}$.
Appendix C. VMEC and DESC convergence scans
In computing solutions for the comparison in this paper, convergence scans were carried out with each code, the results of which are compiled here. In figure 21, the results for running VMEC at an angular resolution of $M=N=16$ (512 Fourier modes per surface) for increasing number of radial surfaces are shown. It can be seen that after ${\rm NS}=1024$, the normalized force error does not decrease appreciably across most of the volume, and the spikes in error near the edge become much more pronounced with ${\rm NS}=2048$.
Next, a scan over angular resolution was carried out in VMEC, and shown in figure 20. The force error is seen to decrease with increasing angular resolution across the whole volume until $M=N=20$, where it begins to stagnate and not uniformly decrease. A similar scan was carried out in DESC, and shown in figure 22. In DESC, due to the Fourier–Zernike basis, the poloidal and radial modes are coupled, so increasing the poloidal resolution $M$ also increases the radial resolution $L$. It can be seen that around $L=M=N=16$, the normalized force error begins to not decrease uniformly across the plasma volume. The minima in the force error flux-surface averages here correspond to collocation points.
Among the parameters scanned over for the VMEC solutions shown in this paper was the FTOL solver tolerance parameter. Shown in figure 23 are results of running the W7-X-like equilibrium at different angular and radial resolutions, and at a range of FTOL values. It can be seen that at low angular resolutions (lower than the boundary Fourier series resolution of $M=N=12$), the FTOL parameter does not affect the solution accuracy much. This is likely because the limiting factor in the solution accuracy is the low angular resolution being unable to match the flux surfaces to the boundary Fourier series. At higher angular resolutions, it can be seen that the FTOL parameter being too low limits the accuracy of the solution, as expected as it terminates the solver prematurely. The difference in the solutions found using ${\rm FTOL}=1\times 10^{-8}$ and ${\rm FTOL}=1\times 10^{-12}$ becomes larger as the angular resolution of the solution is increased.