1 Introduction

Basic properties of the solar coronal magnetic field such as its strength, direction, and three-dimensional structure, cannot be determined by observation at present, and this motivates modeling of the coronal magnetic field. In the corona the pressure and gravity forces are too weak above active regions to balance the magnetic (Lorentz) force (Metcalf et al. 1995; Gary 2001), therefore it is common to model the coronal magnetic field as force-free, i.e. a magnetic field where the Lorentz force is equal to zero, and electric currents flow along magnetic-field lines (Sturrock 1994). Force-free models of the corona were reviewed by Sakurai (1989) and Wiegelmann and Sakurai (2012).

A force-free magnetic field satisfies (Sturrock 1994)

$$ \nabla\times\mathbf{B} = \alpha(\mathbf{r}) \mathbf{B}, $$
(1)

and

$$ \nabla\cdot\mathbf{B} = 0, $$
(2)

where the scalar field α(r) is related to the electric current density in the volume J by

$$ \mathbf{J} = \alpha(\mathbf{r}) \mathbf{B}/\mu_0. $$
(3)

Equations (1) and (2) require boundary conditions to determine a solution, and this defines the force-free boundary value problem. The correct boundary conditions for a well-posed formulation of the problem were outlined by Grad and Rubin (1958). In the Grad–Rubin formulation the boundary conditions are the normal component of the magnetic field, B n , and the value of α over one polarity of the field in the boundary, i.e. values of α are specified over points in the boundary where B n <0, or where B n >0. To model the coronal magnetic field the boundary conditions are assumed at the photosphere and the model is solved in the coronal volume. In theoretical studies the boundary conditions usually have an analytic form (e.g. Régnier 2009; Régnier 2012), and in observation-based studies the boundary conditions are typically derived from spectro-polarimetric observations of the photospheric magnetic field (e.g. Schrijver et al. 2008; De Rosa et al. 2009, and see also the references in Wiegelmann and Sakurai 2012).

The force-free boundary value problem is nonlinear in the general case, where α is a function of position. When α is constant, the equations are linear and closed-form analytic solutions can be found (Nakagawa and Raadu 1972; Alissandrakis 1981). However, the linear model is unphysical in that the solutions in general have unbounded energy in an unbounded space (Alissandrakis 1981). For the nonlinear problem, analytic solutions can be found using the generating function method (Sturrock 1994) for particular symmetries, for example for rotational symmetry (Low and Lou 1990). The general nonlinear problem has no known analytic solution and must be treated numerically. For this purpose a number of methods have been developed. These methods differ in their formulation of the boundary value problem and their choice of solution method (for reviews see Wiegelmann (2008) and Wiegelmann and Sakurai (2012)).

Most of the force-free methods in use solve the force-free equations in Cartesian geometry, with the corona corresponding to the half-space z>0 and the photosphere represented by the z=0 plane (Sakurai 1981; Wu et al. 1990; Wheatland, Sturrock, and Roumeliotis 2000; Wiegelmann 2004; Wheatland 2007; Valori, Kliem, and Keppens 2005). This introduces two problems into the modeling. The first problem is that the Cartesian approximation, which assumes that the curvature of the Sun is negligible, becomes inaccurate when considering large regions on the Sun (Gary and Hagyard 1990). Full-disk spectro-polarimetric observations of the photospheric magnetic field are now available from the Helioseismic and Magnetic Imager (HMI: Schou et al. 2012) onboard the Solar Dynamics Observatory (SDO: Pesnell, Thompson, and Chamberlin 2012). Coronal field modeling based on these data must use spherical coordinates. The second problem concerns the assumption of boundary conditions on the transverse boundaries of the Cartesian domain. In practice, the infinite half-space is replaced by a finite numerical domain, meaning boundary conditions are required on the top and side boundaries of the volume in addition to the z=0 plane. In general, ad hoc boundary conditions are used, such as assuming periodicity, or assuming that no magnetic flux leaves the top or side boundaries. These boundary conditions are artificial and do not necessarily represent physical conditions in the corona. Spherical modeling avoids this problem, because a spherical domain can encompass the entire corona with no transverse boundaries, in which case ad hoc boundary conditions are not required.

Modeling the entire corona avoids the need for boundary conditions apart from those at the photosphere, but introduces other difficulties. The description of the polar field presents difficulties both observationally and numerically. The observational difficulties are two-fold. Firstly, due to the Sun’s tilt, only one pole is observed from Earth at a time. Secondly, spectro-polarimetrically derived magnetic-field values may be inaccurate near the poles where there may be significant unresolved mixed-polarity magnetic flux. This can lead to partial cancellation of the polarization signal at each pixel. Quiet-Sun regions also contain mixed polarity flux, but the problem is very likely to be worse close to the poles because of line-of-sight effects. For these reasons the polar field is usually interpolated from observations at lower latitudes (e.g. Sun et al. 2011). The co-ordinate singularities in the spherical polar system that occur at the poles also pose a problem for numerical methods. For finite difference methods the coordinate poles require special treatment, and with spectral methods specific grids are required to avoid problems (Boyd 2001).

In this paper we outline an implementation of the Grad–Rubin method for solving the nonlinear force-free model in spherical geometry. Our method is applicable both to the entire Sun and to regions with restricted angular extent. Other methods for solving the force-free model in spherical geometry have been developed. Wiegelmann (2007) presented a generalization of the optimization method, and Amari et al. (2013) presented a finite-difference implementation of the Grad–Rubin method. Our method differs from both of these and features a new spectral method for computing the magnetic field based on an expansion of the field in terms of global basis functions. This solution can be applied to a spherical region of the corona of arbitrary angular size, in which case explicit assumptions about the magnetic field on the transverse boundaries of the spherical region are not required, even for a spherical wedge with restricted extent. However, for the latter case we impose additional constraints on the boundary conditions at the photosphere. Specifically, we assume that the radial component of the field and the electric current density vanish at the photosphere outside the wedge. We present the application of our method to a simple test case with analytic boundary conditions to demonstrate the convergence of the method and the self-consistency of the solution.

This paper is structured as follows: In Section 2 we outline the specific form of the force-free boundary value problem that we solve, and we outline the Grad–Rubin iteration method. In Section 3 we present the details of our implementation of the Grad–Rubin method, including the spectral solution for the magnetic field that is used. In Section 4 we describe the test case that we used and show the results of applying the code to the test case. Finally, in Section 5 we present a discussion of the results and a conclusion.

2 Theory

In this section we outline the two boundary value problems that we solve, and give a brief description of the Grad–Rubin method. We consider solutions of the nonlinear force-free Equations (1) and (2) in two domains. The first domain is the entire corona, and the second is a spherical wedge of limited angular extent.

2.1 Boundary Value Problems

We first consider the domain Ωglobal, which is defined as the set of points with spherical polar coordinates

$$ \Omega_{\mathrm{global}} = \bigl\{(r,\theta,\phi) \,| \,r\in[R_{\odot }, \infty), \theta\in(0,\pi),\phi\in[0,2\pi) \bigr\}, $$
(4)

where θ is the polar angle, ϕ is the azimuthal angle, r is the radius, and R is the radius of the Sun. We refer to this domain as global because it covers a complete 4π steradians, and its lower boundary is the entire photosphere.

It is necessary to specify boundary conditions on the force-free equations at the photosphere. Following the prescription of Grad and Rubin (1958), the appropriate boundary conditions are the radial component of B,

$$ \mathbf{B} \cdot\hat{\mathbf{r}} |_{r=R_{\odot}} = B_n(\theta,\phi), $$
(5)

and the force-free parameter

$$ \alpha|_{r=R_{\odot}} = \alpha_0(\theta,\phi) $$
(6)

over one polarity of B n , i.e. values of α 0 are specified either where B n <0 or where B n >0. It is also assumed that the magnetic field vanishes for large r, i.e.

$$ \lim_{r \rightarrow\infty} \mathbf{B} = 0. $$
(7)

This asymptotic boundary condition matches that used by some Cartesian codes (Wheatland 2007).

In some cases B n and α 0 may only be nonzero over a small range of θ and ϕ. In this situation it is unnecessary to use a global domain. A more appropriate choice is

$$ \Omega_{\mathrm{wedge}} = \bigl\{(r,\theta,\phi) \,|\, r\in[R_{\odot}, \infty), \theta\in[\theta_{\min},\theta_{\max}], \phi\in[ \phi_{\min},\phi_{\max}] \bigr\}, $$
(8)

i.e. a domain external to a sphere, but restricted in angular extent. We refer to this as a spherical wedge. In principle, it is necessary to prescribe boundary conditions at the transverse boundaries of this domain, but in Section 3 we explain how to obtain solutions for which this is unnecessary. This approach assumes that B n and α 0 are zero everywhere outside the domain Ωwedge.

Here we are using the Grad–Rubin boundary conditions, which assume α 0 over a single polarity of B n , but observational data provides α 0 over both (Landi Degl’Innocenti and Landolfi 2004). This means that two possible solutions can in principle be found for a given data set, corresponding to the two choices of polarity. If the data are consistent with the force-free model, then the two solutions will be the same. However, in practice it is found that the two solutions differ significantly (e.g. Schrijver et al. 2008). This may be attributed to the departure of the photospheric field from the force-free state due to significant pressure and gravity forces (Metcalf et al. 1995). Wheatland and Régnier (2009) presented a method, based on an implementation of the Grad–Rubin method in Cartesian coordinates, for using the data from both polarities to construct a single self-consistent force-free solution. Here we present only the basic Grad–Rubin method, but in principle the Wheatland and Régnier (2009) self-consistency procedure may be applied here also.

2.2 Grad–Rubin Iteration

The Grad–Rubin method is an iterative method for solving the nonlinear force-free equations (Grad and Rubin 1958). The method has previously been implemented in Cartesian coordinates (Sakurai 1981; Amari, Boulmezaoud, and Mikic 1999; Wheatland 2007) and in spherical coordinates (Amari et al. 2013). It replaces the nonlinear Equations (1) and (2) with a pair of linear equations that are solved repeatedly in a sequence of iterations. We denote a quantity after n Grad–Rubin iterations using a superscript in square brackets, e.g. B [n]. One Grad–Rubin iteration may be written

$$ \nabla\alpha^{[n+1]} \cdot\mathbf{B}^{[n]} = 0, $$
(9)

and

$$ \nabla\times\mathbf{B}^{[n+1]} = \alpha^{[n+1]} \mathbf{B}^{[n]}. $$
(10)

Equation (9) updates the force-free parameter α in the volume subject to boundary conditions on α. Equation (10) updates the magnetic field in the volume using the new α values together with the magnetic field from the previous iteration subject to the boundary conditions on the normal component of the field. Equations (9) and (10) are repeatedly solved until the magnetic field B [n] and the force-free parameter α [n] converge at all points in the volume. The iteration is initiated using a potential field B 0 constructed from the boundary conditions on B n . We present the details of our method for solving Equations (9) and (10) numerically in two spherical domains in Section 3.

3 Numerical Implementation

In this section we outline our implementation of the Grad–Rubin method in code. The Grad–Rubin method requires an initial potential field, a method for solving Equation (9) to update α, and a method for solving Equation (10) to update the magnetic field.

The numerical grid used is a spherical polar grid with N r points in the r direction, N θ points in the θ direction, and N ϕ points in the ϕ direction. The ϕ and r grids are uniformly spaced. The θ grid is either a Gauss–Legendre grid or is uniform (Press et al. 2007). The Gauss–Legendre grid is required to accurately represent the solution near the poles and is only necessary for constructing solutions in the global domain. The grid is finite in the radial direction, and has a maximum r value that we call R max.

3.1 Spectral Solution for the Potential Field

An initial potential field is calculated as a starting point for the Grad–Rubin iteration. We used a spherical harmonic solution for the potential field. The spherical harmonics are global basis functions, meaning they are orthogonal over the domain Ωglobal. It can be shown that, in terms of spherical harmonics Y lm (θ,ϕ), the components of the potential field satisfying the boundary condition Equation (7) at infinity are (Altschuler and Newkirk 1969)

$$\begin{aligned} B_r =& \sum_{l=0}^{\infty} \sum _{m=-l}^{l} a_{lm} \biggl(\frac{R_{\odot}}{r} \biggr)^{(l+2)} Y_{lm}(\theta,\phi), \end{aligned}$$
(11)
$$\begin{aligned} B_{\theta} =& \sum _{l=0}^{\infty} \sum _{m=-l}^{l} -\frac{a_{lm} }{l+1} \biggl( \frac{R_{\odot}}{r} \biggr)^{(l+2)} \frac{\partial Y_{lm}(\theta,\phi)}{\partial\theta} \end{aligned}$$
(12)

and

$$ B_{\phi} = \sum _{l=0}^{\infty} \sum _{m=-l}^{l} -\frac{\mathrm{i}ma_{lm} }{l+1} \biggl( \frac{R_{\odot}}{r} \biggr)^{(l+2)} \frac{Y_{lm}(\theta,\phi)}{\sin\theta}, $$
(13)

where the coefficients a lm are given by

$$ a_{lm} = \int _0 ^{2\pi} \int _0^{\pi} B_n(\theta ,\phi) Y^{*}_{lm}(\theta,\phi) \sin \theta \,\mathrm {d}\theta \,\mathrm {d}\phi, $$
(14)

and where i2=−1. These equations are complex valued and the physical magnetic field is the real part. Equations (11) – (14) can be obtained from the well-known potential source-surface solution (Altschuler and Newkirk 1969) by considering that solution in the limit where the source surface is located at infinity.

In practice, the series must be truncated after a finite number of terms. We truncate the series at a finite l value that we call L, i.e. we perform the summation over all the spherical harmonics with lL and |m|≤l. This approach results in a truncation error in B that is position independent (Boyd 2001). The series is a Fourier series in ϕ, so it is natural to choose L to correspond to the Nyquist frequency (Boyd 2001),

$$ L = \frac{\pi}{\Delta\phi}, $$
(15)

where Δϕ is the uniform spacing of points in ϕ. In practice, the right-hand side of Equation (15) is rounded to the nearest integer.

Equations (11) – (14) provide the magnetic field at all points in the global domain Ωglobal. The solution in the restricted domain Ωwedge can be found by evaluating the global solution only at points contained in Ωwedge. This allows the solution in Ωwedge to be found without assuming specific boundary conditions on the transverse boundaries of Ωwedge. Since we assume that B n is zero outside Ωwedge, the integral in Equation (14) need only be computed over the restricted domain.

Tóth, van der Holst, and Huang (2011) reported the nonconvergence of the spectral series given by Equations (12) – (13). The nonconvergence results in erroneous magnetic-field values (particularly near the poles) for large L. The problem occurs because the numerical grid used by Tóth, van der Holst, and Huang (2011) is not sufficiently dense near the poles to accurately represent the rapid variation of the spherical harmonics. For calculations in Ωglobal we use a Gauss–Legendre grid that accurately represents the spherical harmonics near the poles (Boyd 2001). For calculations in Ωwedge, we use a uniform grid in θ, which is rotated such that the region of interest is isolated from the poles, and does not encounter this problem.

The Gibbs phenomenon (ringing produced in representing discontinuous changes) is a problem for all spectral methods (Boyd 2001). The problem is significant when spectral potential field solutions are calculated from observational data (Tóth, van der Holst, and Huang 2011). Including more terms in the series improves the situation but does not eliminate the problem. It is important to note this particular caveat when applying and interpreting results produced by spectral methods. It should be noted that finite-difference methods also become inaccurate at locations with steep gradients in the field that is represented.

A parallel code is used to sum the spectral series. The coefficients a lm are calculated using Equation (14), and then Equations (11) – (13) are evaluated with the sums performed using partial sums, i.e. each series is broken into a number of subseries, each of which is summed independently, and then the final result is obtained by adding the partial sums. The parallel implementation is written for a distributed memory multiprocessor. The method uses a combination of the Message Passing Interface (MPI) (Snir, Otto, and Huss-Lederman 1998) and OpenMP (Chandra et al. 2001) and is described in Appendix B.

3.2 Field-Line-Tracing Solution for the Current-Update Step

To solve Equation (9) we employ the field-line-tracing method that has been used in Grad–Rubin implementations in Cartesian coordinates (Amari, Boulmezaoud, and Mikic 1999; Wheatland 2007), and in spherical coordinates (Amari et al. 2013). According to Equation (9), α [n+1] is constant along magnetic-field lines. The field-line-tracing method determines α [n+1] in the volume by tracing the field line threading each grid point until it crosses the lower boundary, and the value of α 0 at the crossing point in the boundary is assigned to the grid point. The field line is traced in the forward direction if boundary values for α 0 are chosen where B n <0, and is traced in the backward direction if boundary values for α 0 are chosen where B n >0. Points in the volume connected to field lines that leave the domain through the outer boundary r=R max are assigned α [n+1]=0 at the point in the volume. In addition, points in the volume threaded by field lines that leave the transverse boundaries of Ωwedge are assigned α [n+1]=0 at the point in the volume. The tracing is performed using fourth-order Runge–Kutta integration (Press et al. 2007), and trilinear interpolation is used to determine B [n] at points along the field line that do not coincide with a grid point.

3.3 Spectral Solution to Ampere’s Law for the Field-Update Step

To solve Equation (10) we use a spectral solution. The magnetic field is decomposed into the sum of a potential field and a nonpotential field, i.e.

$$ \mathbf{B}^{[n+1]} = \mathbf{B}_0 + \mathbf{B}^{[n+1]}_c, $$
(16)

where \(\mathbf{B}^{[n+1]}_{c}\) satisfies

$$ \nabla\times\mathbf{B}^{[n+1]}_c=\mathbf{J}^{[n+1]}, $$
(17)

with

$$ \mathbf{J}^{[n+1]}=\alpha^{[n+1]}\mathbf{B}^{[n]}/ \mu_0, $$
(18)

and where B 0 is the potential field matching the boundary conditions on B n calculated using the method of Section 3.1. It is only necessary to update \(\mathbf{B}^{[n+1]}_{c}\) at each iteration as B 0 does not change. Also, since B 0 satisfies the boundary conditions on the normal component of the field at r=R , it follows that

$$ \mathbf{B}^{[n+1]}_c\big|_{r=R_{\odot}} = 0, $$
(19)

and from Equation (7) we require

$$ \lim_{r \rightarrow\infty} \mathbf{B}^{[n+1]}_c = 0. $$
(20)

Equations (19) and (20) define the boundary conditions on \(\mathbf{B}^{[n+1]}_{c}\).

We use a spectral solution to Equation (17) that is analogous to the spherical harmonic solution for the potential field. We express \(\mathbf{B}^{[n+1]}_{c}\) as a series using the vector spherical harmonics (Morse and Feshbach 1953), i.e.

$$ \mathbf{B}^{[n+1]}_c = \sum _{l=0}^{\infty} \sum _{m=-l}^{l} B^{(1)}_{lm}(r) \mathbf{Y}_{lm} + B^{(2)}_{lm}(r) \boldsymbol{ \Psi}_{lm} + B^{(3)}_{lm}(r) \boldsymbol{ \Phi}_{lm}, $$
(21)

where Y lm , Ψ lm , and Φ lm are the complete set of orthogonal vector basis functions defined by

$$\begin{aligned} \mathbf{Y}_{lm} =& Y_{lm}\hat{\mathbf{r}}, \end{aligned}$$
(22)
$$\begin{aligned} \boldsymbol{\Psi}_{lm} =& \frac{r \nabla Y_{lm}}{\sqrt{l(l+1)}}, \end{aligned}$$
(23)

and

$$ \boldsymbol{\Phi}_{lm} = \frac{\mathbf{r} \times\nabla Y_{lm}}{\sqrt{l(l+1)}}. $$
(24)

These functions are mutually perpendicular, i.e.

$$ \mathbf{Y}_{lm} \cdot\boldsymbol{\Psi}_{lm} = \mathbf{Y}_{lm} \cdot \boldsymbol{\Phi}_{lm} = \boldsymbol{ \Psi}_{lm} \cdot\boldsymbol{\Phi}_{lm} = 0, $$
(25)

and orthonormal, e.g.

$$ \int_0^{\pi} \int_0^{2\pi} \mathbf{Y}_{lm}(\theta ,\phi)\cdot\mathbf{Y}_{l'm'}^{*}( \theta,\phi) \,\mathrm {d}\theta \,\mathrm {d}\phi= \delta_{l l'}\delta_{m m'}, $$
(26)

where δ lm is the Kronecker deltaFootnote 1. The vector spherical harmonics have previously been applied to magnetostatic problems (e.g. Barrera, Estévez, and Giraldo 1985; Dennis and Quartapelle 1985), but have not been used in this context.

The spectral coefficients \(B^{(i)}_{lm}\) with i=1,2,3 are determined by the distribution of currents in the volume and by the boundary conditions. We show in Appendix A that for the problem at hand the spectral coefficients for the magnetic field are

$$\begin{aligned} B^{(1)}_{lm} =& \frac{\sqrt{l(l+1)}}{r} \biggl[ -R_{\odot}^l \biggl( \frac{R_{\odot}}{r} \biggr)^{l+1} I_0 + I_2(r) + I_3(r) \biggr], \end{aligned}$$
(27)
$$\begin{aligned} B^{(2)}_{lm} =& \frac{1}{r} \biggl[ R_{\odot}^l \biggl(\frac{R_{\odot }}{r} \biggr)^{l+1}I_0 - lI_1(r) + (l+1)I_2(r) \biggr], \end{aligned}$$
(28)

and

$$ B^{(3)}_{lm} = \frac{r J^{(1)}_{lm}}{\sqrt{l(l+1)}}, $$
(29)

where

$$\begin{aligned} I_0 =& \frac{\mu_0}{2l+1} \int^{\infty}_{R_{\odot}} s^{1-l} J^{(3)}_{lm}(s)\,\mathrm {d}s, \end{aligned}$$
(30)
$$\begin{aligned} I_1(r) =& \frac{\mu_0}{2l+1} \int^{r}_{R_{\odot}} s \biggl( \frac{s}{r} \biggr)^{l+1}J^{(3)}_{lm}(s)\,\mathrm {d}s, \end{aligned}$$
(31)

and

$$ I_2(r) = \frac{\mu_0}{2l+1} \int^{\infty}_{r} s \biggl( \dfrac{r}{s} \biggr)^l J^{(3)}_{lm}(s)\,\mathrm {d}s. $$
(32)

The coefficients \(J_{lm}^{(i)}\) are the spectral coefficients of the current distribution defined by

$$\begin{aligned} J_{lm}^{(1)}(r) =& \int\mathbf{J}^{[n+1]} \cdot \mathbf{Y}^{*}_{lm}\,\mathrm {d}\Omega, \end{aligned}$$
(33)
$$\begin{aligned} J_{lm}^{(2)}(r) =& \int\mathbf{J}^{[n+1]} \cdot \boldsymbol{\Psi}^{*}_{lm}\,\mathrm {d}\Omega, \end{aligned}$$
(34)

and

$$ J_{lm}^{(3)}(r) = \int\mathbf{J}^{[n+1]} \cdot \boldsymbol{\Phi} ^{*}_{lm}\,\mathrm {d}\Omega, $$
(35)

where J [n+1] is the volume current density defined by Equation (18). The spectral solution is computed in three steps: i) \(J^{(i)}_{lm}\) is computed from J [n+1] using Equations (33) – (35); ii) spectral coefficients for the magnetic field are computed from Equations (27) – (29); iii) the spectral series is summed to a maximum order L. A parallel summation method is used, as described in Appendix B (the method is described for the potential field calculation, but the same approach is also used for the nonpotential component of the field).

The integrals I 0, I 1, and I 2 [Equations (30), (31), and (32)] are evaluated using the trapezoidal rule. The integrals are expressed in such a way as to avoid numerical overflow for high values of l. Although the integrals in Equations (30) and (32) are written as extending to infinite radius, in the numerical solution the maximum radius is R max, and an error is introduced by this approximation if J [n+1]≠0 at r=R max. Therefore it is necessary to make R max sufficiently large to encompass all the significant currents.

4 Application to Test Cases

In this section we apply our code to two test cases with analytic boundary conditions to demonstrate the method. We establish the convergence of the method and quantify the self-consistency of the solution.

4.1 Two Bipolar Test Cases

The first test case is a simple model with analytic boundary conditions, representing the field due to a bipolar active region with Gaussian sunspots calculated in the global domain Ωglobal. A small nonzero patch of α is included around one of the spots. The second test case has the same boundary conditions, on a smaller spatial scale, and the field is calculated in a restricted domain Ωwedge. For each test case we demonstrate the convergence of the Grad–Rubin iteration, and we measure the self-consistency of the solution by verifying that the Lorentz force in the model corona is zero, i.e. that the electric current is parallel to the magnetic field.

For both test cases, the boundary conditions on the magnetic field are

$$ B_n(\theta,\phi) = B_{\mathrm{s}} \bigl( \mathrm {e}^{-s_1^2/\sigma^2} - \mathrm {e}^{-s_2^2/\sigma^2} \bigr), $$
(36)

where B s is a scale constant that is chosen such that max(|B n |)=B s, and σ is a parameter that determines the size of the spots. The two functions s 1 and s 2 are distances to the centers of each spot as measured on the sphere, and may be written

$$ s_i(\theta,\phi) = R_{\odot} \tan^{-1} \biggl[ \frac{\sqrt{(\sin \theta\sin\Delta\lambda)^2 + (\sin\theta_i\cos\theta-\cos\theta\sin\theta_i\cos\Delta \lambda)^2}}{ \cos\theta_i\cos\theta+\sin\theta\sin\theta_i\cos\Delta \lambda} \biggr], $$
(37)

where Δλ=ϕ i ϕ, and with (θ 1,ϕ 1) being the coordinates of the center of the spot with positive polarity, and with (θ 2,ϕ 2) being the coordinates of the center of the spot with negative polarity. For the boundary conditions on α 0 we consider an isolated spot with a locally constant value of α around the center of the positive spot, i.e.

$$ \alpha_0 = \left \{ \begin{array}{l@{\quad}l} \Lambda& B_n \ge B_{\mathrm{th}}, \\ 0 & 0 < B_n < B_{\mathrm{th}}, \end{array} \right . $$
(38)

where Λ is a constant, and B th is a threshold value. Note that the boundary conditions on α 0 are only defined over one polarity of B n (as per the Grad–Rubin formulation). We have chosen to define α 0 over the positive polarity of B n , i.e. where B n >0.

It is known that force-free fields can be unstable when

$$ \alpha_{\mathrm{s}} L_{\mathrm{s}} > 1 $$
(39)

(Molodensky 1974), where α s is a characteristic value for α, and L s is the characteristic scale length. For the bipolar test case we take the scale length to be the distance along the photosphere between the two spots, and we take α s=Λ. For both test cases we choose these values such that

$$ \alpha_{\mathrm{s}} L_{\mathrm{s}} = 1, $$
(40)

corresponding to a current matching the approximate maximum.

4.2 Measures of Convergence

To measure the convergence of the iteration we employ two metrics. The first is the total magnetic energy at each iteration n,

$$ E_n = \frac{1}{2\mu_0} \int \big|{\mathbf{B}^{[n]}} \big|^2 \,\mathrm {d}V, $$
(41)

where the integral is over the entire computational volume. We expect the energy to converge to a fixed value with Grad–Rubin iteration. The second metric is the average absolute difference in the magnetic field at successive Grad–Rubin iterations,

$$ A_{\mathrm{mean}} = \bigl\langle\big|\mathbf{B}^{[n]}-\mathbf{B}^{[n-1]}\big| \bigr\rangle, $$
(42)

where 〈…〉 denotes the average over the computational volume. We expect A mean to approach zero with repeated iteration.

To measure the self-consistency of the solution, we consider the maximum angle between J and B. The angle is defined by

$$ \theta_{\max} = {\rm max} \biggl[ \frac{|\mathbf{J}^{[n]} \times \mathbf{B}^{[n]}|}{|\mathbf{B}^{[n]}||\mathbf{J}^{[n]}|} \biggr], $$
(43)

where the maximum is calculated over all grid points.

We also examine the self-consistency qualitatively by drawing the field lines of B [n] and streamlines of the current density J [n]. For an exact force-free solution we expect that these two sets of field lines will coincide corresponding to θ max=0. This provides quite a stringent test, because the error in the paths of the field lines is the result of the local truncation error in the solution integrated along the paths, which is in general greater than the local error.

4.3 Test Case One: The Bipole in the Global Domain

The first test case described in Section 4.1 considers a bipolar active region covering a significant fraction of the photosphere. This region provides a test for the method in the domain Ωglobal. The parameters used for this test are shown in Table 1, and the dimensions of the grid are summarized in Table 2. We performed 40 Grad–Rubin iterations starting from a potential field. The computation took approximately 15 minutes on a computer with an eight-core CPU.

Table 1 Parameters used for the bipolar test cases involving the domain Ωglobal (case 1), and the wedge-shaped region Ωwedge (case 2). Distances are quoted in units of the solar radius, and magnetic-field strengths are relative to the scale constant B s. Units are given in square brackets.
Table 2 Size of the grids used for test cases. Both the physical sizes and the sizes of the numerical grids are shown.

The left panel of Figure 1 illustrates the energy (in units of the energy of the potential field E 0) as a function of iteration number. The energy converged to an approximately constant value after about six Grad–Rubin iterations. The left panel of Figure 2 shows the absolute average change in the field, A mean, as a function of iteration number. The scale on the y-axis is logarithmic. This figure shows that A mean decreases exponentially before becoming roughly constant. The behavior of the two metrics E/E 0 and A mean establishes the convergence of the Grad–Rubin procedure for this case.

Figure 1
figure 1

Energy (in units of the energy of the potential field E 0) as a function of iteration number. The left panel shows E/E 0 for the first test case in the global domain Ωglobal, the right panel shows the same for the second test case, involving a calculation in the domain Ωwedge. In both cases the energy converges to an approximately constant value after about six iterations.

Figure 2
figure 2

The average absolute change in the field, A mean, as a function of iteration number for the first test case (left panel) and the second test case (right panel). The vertical scale is logarithmic.

We also demonstrate the self-consistency of the numerical solution. Figure 3 shows the field lines of B (in blue) and the streamlines of J (in red). The left panel shows the results after one Grad–Rubin iteration. In this panel there is a significant discrepancy between the two sets of lines. The right panel shows the field lines after 40 Grad–Rubin iterations. In this case the two sets of lines almost coincide, indicating that the numerical solution is close to being force-free. Some discrepancy is observed for long field lines because of the need to interpolate values of J and B between grid points in order to draw field lines. At each grid point J×B is very small (as discussed below), but higher values are obtained between grid points when J and B are interpolated. The field lines that show the largest discrepancy occur close to the boundary separating zero and nonzero values of α 0, where the interpolation is least accurate.

Figure 3
figure 3

Field lines (blue) and streamlines of current density (red) for test case one. The left panel is after the first Grad–Rubin iteration. The right is after 40 Grad–Rubin iterations. In the left panel there is a clear difference between the two sets of lines, and in the right the two sets of lines coincide, indicating that a force-free solution has been found. The discrepancy between the two sets of lines is due to the interpolation of field values between grid points necessary to draw the lines (see the discussion in Section 4.3).

The left panel of Figure 4 shows θ max as a function of iteration number. After the first iteration the maximum angle between J and B is approximately 20 degrees, and θ max decreases approximately exponentially over the 40 iterations to a final value of order 10−3 degrees. This confirms that a force-free solution is found.

Figure 4
figure 4

The maximum angle between J and B over the solution domain as a function of iteration number. The left panel shows θ max for the first test case in Ωglobal, the right panel shows θ max for the second test case in Ωwedge. The vertical scale is logarithmic.

4.4 Results for Test Case Two: The Bipole in the Restricted Domain

The second test case described in Section 4.1 considers the bipolar test case in the domain Ωwedge. We chose a domain that spans 20 in latitude and 20 in longitude. The size and the dimensions of the numerical grid are summarized in Table 2. In this case, the separation between the spots is an order of magnitude smaller than for the first test case, therefore we increased α s by an order of magnitude so that the product L s α s matches test case one. This provided a bipole with the same amount of twist. The parameters for this test case are summarized in Table 2. We again applied 40 Grad–Rubin iterations, which took 1.6 hours to run on a computer with an eight-core CPU.

The right panel of Figure 1 shows the energy (in units of the energy of the potential field E 0) as a function of iteration number. The energy converges to a constant value after approximately four Grad–Rubin iterations. The right panel of Figure 2 shows A mean as a function of iteration number. The scale on the y axis is logarithmic, and the figure shows that A mean decreases approximately exponentially, to a final value of the order of machine precision. The behavior of E/E 0 and A mean as a function of iteration confirm the convergence of the Grad–Rubin iteration procedure.

The left panel of Figure 5 shows the field lines of the magnetic field and the streamlines of the current density after the first iteration (left panel) and after the last iteration (right panel). The magnetic field is shown in blue and the current density in red. In the left panel there is a clear difference between the two sets of lines, and in the right panel the two sets of lines closely coincide, indicating that a force-free solution is found. Some disagreement is observed between the two sets of lines for longer field lines; this is explained in Section 4.3.

Figure 5
figure 5

Field lines (blue) and streamlines of current density (red) for test case two. The left panel is after the first Grad–Rubin iteration. The right is after 40 Grad–Rubin iterations. In the left panel there is a clear difference between the two sets of lines, and in the right the two sets of lines coincide, indicating that a force-free solution has been found. The discrepancy between the two sets of lines is due to the interpolation of field values between grid points necessary to draw the lines (see the discussion in Section 4.3).

The right panel of Figure 4 shows θ max as a function of iteration number. After the first iteration the maximum angle between J and B is approximately 20 degrees, and θ max decreases approximately exponentially with iteration, to a final value of the order of 10−9 degrees.

5 Discussion and Conclusion

We presented an implementation of the Grad–Rubin method (Grad and Rubin 1958) for solving the force-free boundary value problem in spherical polar geometry with the aim of modeling the solar coronal magnetic field. The method is applicable to either the entire corona or a wedge with restricted angular extent.

We applied our code to two test cases with analytic boundary conditions, representing a current-carrying bipole, to demonstrate the convergence of the Grad–Rubin iteration and the self-consistency of the final numerical solution. For the first case we computed a solution in a domain that encompassed the entire corona, and in the second we computed a solution in a spherical wedge. We found that in both cases the Grad–Rubin iteration converged, and the resulting solution is force free to a very good approximation, by which we mean that the angle between J and B is small.

The bipolar test case we considered is simple, but served to illustrate the basic correctness of the method. We were unable to identify a suitable exact analytic equilibrium with which to test the code. The Low and Lou (1990) field has often been used for testing force-free codes (Amari, Boulmezaoud, and Mikic 1999; Wiegelmann 2007), but it proved difficult to reproduce this solution without imposing analytic boundary conditions on an outer shell located at a finite radius from the photosphere. Using the asymptotic boundary condition defined by Equation (7) requires a very large domain to encompass all the significant currents for the Low and Lou (1990) problem. Hence it is difficult to calculate accurate solutions without resorting to the use of exact boundary conditions at a finite outer shell. The lack of an exact analytic test case means that we cannot determine how the numerical error scales as a function of grid resolution. We also note that our test case has smooth boundary conditions. In practice, we expect observational data to contain significant gradients, in particular due to noise that is present in the data. The effect of the Gibbs phenomenon produced by the spectral method applied to these steep gradients has not yet been investigated.

We note that the code took 1.6 hours to run for the test case in the spherical wedge, for a grid with 643 points. By comparison, the calculation in the global domain took 15 minutes for a 128×64×128 grid. The difference in speed occurs because the spherical harmonics must be summed to large orders when Δϕ is small. In the first case L=64 and in the second case L=567. In practice it may not be necessary to use an L value of a given size for all values of r. We expect that as the field becomes smoother with increasing r, higher-order terms may be ignored and a reduction in L as a function of r may increase the speed of the code. We also expect that it may be possible to increase the speed of the code by improving details of the technique used for calculating the nonpotential field. These improvements will be implemented in future work.

As mentioned in Section 3.1, Tóth, van der Holst, and Huang (2011) reported the nonconvergence of the spherical harmonics spectral series for large L, for the calculation of potential field models. The grid used by Tóth, van der Holst, and Huang (2011) is uniform in cosθ. However, near the poles, the associated Legendre polynomials are rapidly varying functions of cosθ, and the rapid variations are not accurately represented on the given grid. This results in the nonconvergence of the series. For our calculations in Ωwedge, we used a grid uniform in θ. Tóth, van der Holst, and Huang (2011) reported that such a grid does not cause convergence problems. Furthermore, the region considered in Section 4.4 is sufficiently isolated from the poles that convergence problems are unlikely to occur regardless of the grid used. When considering larger regions that cannot be isolated from the poles, or for calculations in Ωglobal, we used a Gauss–Legendre grid that is dense at the poles and accurately represents the rapid variations in the associated Legendre polynomials.

Other developments to the code are also planned. At present, the code uses a uniform grid in r, but this could be changed to a nonuniform grid. A nonuniform grid is expected to be more efficient because the grid can be chosen to be dense close to the photosphere where the magnetic field is structured on small scales, and sparse far from the photosphere where the field is smooth. At present the method assumes the asymptotic boundary condition Equation (7), but this could be changed to accommodate boundary conditions at an outer “source surface” analogous to the potential source-surface model. Finally, the method currently only uses α 0 over a single polarity, which is probably problematic when using observational data because of the inconsistency of the data with the force-free model (Schrijver et al. 2008). In future work we will modify our method to implement the self-consistency procedure of Wheatland and Régnier (2009).

The method and code outlined in this paper are designed for application to solar data, but we have not yet attempted this. In future work we will test the code on vector magnetogram data derived from observations by the Helioseismic and Magnetic Imager onboard the Solar Dynamics Observatory (SDO/HMI). The SDO/HMI instrument provides data for the whole solar disk, which demands spherical modeling. We hope to be able to develop the code presented here into a practical tool for modeling of the coronal magnetic field from SDO/HMI data, and for application to other, future data sets.