Notes on the Numerical Methods for the PFSS Solver#
This page was originally a Latex file that was converted to RST. The author is A. R. Yeates from the Department of Mathematical Sciences, Durham University, UK.
Basic Equations#
The sunkit_magex.pfss
code solves the for a magnetic field satisfying
in a spherical shell \(1 \leq r \leq R_{ss}\), given boundary conditions
The function \(g(\theta,\phi)\) is specified by the user.
Numerical Grid#
The solver uses a rectilinear grid that is equally spaced in \(\rho\), \(s\), \(\phi\), where
in terms of spherical coordinates \((r,\theta\,\phi)\). The coordinate scale factors \(|\mathrm{d}\boldsymbol r/\mathrm{d}\rho|\), \(|\mathrm{d}\boldsymbol r/\mathrm{d}s|\), \(|\mathrm{d}\boldsymbol r/\mathrm{d}\phi|\) are
The grid is illustrated in Fig. 1. Note that the longitudinal cell size goes to zero at the poles; these points are treated specially in the calculation of \(\boldsymbol{B}\). Note also that, since \(s\) is a decreasing function of \(\theta\), the components of a vector \(\boldsymbol{v}\) in \((\rho,s,\phi)\) are \(v_\rho = v_r\) but \(v_s = -v_\theta\).
We define the number of grid cells \(n_\rho\), \(n_s\), \(n_\phi\), with corresponding uniform spacings
Note that the boundaries in \(s\) are at the poles \(s=\pm1\), at which points \(h_\phi\) is not defined. The solution is periodic in the longitudinal (\(\phi\)) direction.
Numerical method#
Overall strategy#
Rather than writing \(\boldsymbol{B}= \nabla\chi\) and solving \(\nabla^2\chi=0\), we write instead \(\boldsymbol{A}= \nabla\times\big(\psi \,\mathrm{e}_\rho\big)\). Then accounting for the unusual coordinates we get
This will take the curl-free form \(\boldsymbol{B}= \nabla\big(\tfrac1{h_\rho}\partial_\rho\psi\big)\) provided that
so our strategy is to solve Equation (1) for \(\psi\), then reconstruct \(\boldsymbol{A}\) and \(\boldsymbol{B}\). The reason for doing it this way is that it allows us to compute \(\boldsymbol{A}\) as well as \(\boldsymbol{B}\) (again, for legacy reasons).
Numerical solution#
We follow the method described in [Ballegooijen], except that we modify the finite-difference discretization to suit our particular coordinates.
The discretization is chosen so that we will have \(\nabla\times\boldsymbol{B}=0\) to machine precision on a staggered grid, when the curl is taken using central differences. This property of essentially zero current density is required when using the PFSS solution to, e.g., initialize non-potential simulations. It would not typically be achieved by interpolating a spherical harmonic solution onto the numerical grid. However, we will see that the discrete solution effectively computes discrete approximations of the spherical harmonics, tailored to our particular difference formula.
In the following subsections, we describe the numerical solution in more detail.
Variables#
Let the coordinate grid points be defined by
In the code the first two arrays are called rg
and sg
(that for pg
is not required). There are also arrays rc
, sc
and pc
corresponding to the cell centres, i.e. \(\rho^{k+1/2}\), \(s^{j+1/2}\) and \(\phi^{i+1/2}\).
To deal with the curvilinear coordinates, we define the edge lengths
Here we used the fact that \(\Delta_\rho\), \(\Delta_s\) and \(\Delta_\phi\) are constant, and used the shorthand
Similarly we define the areas of the cell faces
In the code the face areas are stored in arrays Sbr
, Sbs
and Sbp
(with only the dimensions required).
In the code the magnetic field \(\boldsymbol{B}\) is defined staggered on the face centres, so \(B_\rho^{k,j+\frac{1}{2},i+\frac{1}{2}}\), \(B_s^{k+\frac{1}{2},j,i+\frac{1}{2}}\), \(B_\phi^{k+\frac{1}{2},j+\frac{1}{2},i}\).
These variables are called br
, bs
and bp
.
The vector potential is located on the corresponding cell edges, so \(A_\rho^{k+\frac{1}{2},j,i}\),
\(A_s^{k,j+\frac{1}{2},i+\frac{1}{2}}\), \(A_\phi^{k,j,i+\frac{1}{2}}\).
In fact, these values are never required on their own, only multiplied by the corresponding edge lengths.
So the variables alr
, als
and alp
correspond to the products \(L_\rho A_\rho\), \(L_sA_s\) and \(L_\phi A_\phi\), respectively.
Finally, the potential \(\psi\) is located on the \(\rho\)-faces (like \(B_\rho\)), so \(\psi^{k,j+\frac{1}{2},i+\frac{1}{2}}\). It is stored in the variable psi
.
Derivatives#
Firstly, we have \(\boldsymbol{A}= \nabla\times\big(\psi\,\mathrm{e}_\rho\big)\). Numerically, this is approximated by
The magnetic field \(\boldsymbol{B}= \nabla\times\boldsymbol{A}\) is then approximated by
These formulae correspond to Stokes’ Theorem applied to the cell face. The condition \(\nabla\times\boldsymbol{B}=0\) may be expressed similarly as
Note that the factors \(L_\rho\), \(L_s\), \(L_\phi\) here are defined normal to the cell faces, not on the edges. But they have the same formulae.
In fact, condition (6) is automatically satisfied. This may be shown using equations (2) to (5), together with our formulae for \(L_s\), \(L_\phi\), \(S_s\) and \(S_\phi\).
Below, we will discretize (1) in such a way that conditions (7) and (8) are also satisfied exactly (up to rounding error).
Boundary conditions for \(\boldsymbol{B}\)#
Boundary conditions are needed when br
, bs
, bp
are averaged to the grid points for output.
We use a layer of “ghost cells”, whose values are set by the following boundary conditions:
In \(\phi\),
br
andbs
are simply periodic.At the outer boundary \(\rho=\log(R_{ss})\), ghost values of
bs
andbp
are set assuming constant gradient in \(\rho\).At the inner boundary, \(\rho=0\), ghost values of
bs
andbp
are set using equations (7) and (8) (effectively assuming zero horizontal current density).At the polar boundaries, the ghost value of
br
is set to the polemost interior value from the opposite side of the grid. Similarly,bp
is set to minus the polemost interior value from the opposite side of the grid. The values ofbs
at the poles are not meaningful as the cell faces have zero area. However, they are set to the average of the two neighboring interior values at that longitude (with the opposite one being reversed in sign).
Some of these conditions are chosen for compatibility with other codes, and are not necessarily the most straightforward option for a pure PFSS solver.
Discretization of Equation (1)#
First, we approximate the two-dimensional Laplacian \(\nabla^2_\perp\psi\) by
As shorthand we define the quantities
noting that these both depend on \(j\) only.
In the code these are called Uc
and Vg
. Then we can write our discretization as
This is the left-hand side of (1).
To discretize the right-hand side of (1), we use the approximation
where
Combining this with (9), we arrive at
The reader may verify algebraically that conditions (7) and (8) follow if this finite-difference equation is satisfied.
Method of solution#
Equation (10), together with the appropriate boundary conditions, yields a large (but sparse) system of \(n_\rho n_sn_\phi\times n_\rho n_sn_\phi\) linear equations to solve. Fortunately, following [Ballegooijen], we can reduce this to a series of symmetric tridiagonal eigenvalue problems, if we look for eigenfunctions of the form
Here the \(k\) in \(f^k\) is a power, not an index, and \(I\) is the square root of \(-1\) (since we already used \(i\) and \(j\) for indices). This reduction will enable very efficient solution of the linear system.
Substituting (11) in Equation (10) gives
The right-hand side can be simplified since the dependence on \(k\) cancels out. This leaves the tridiagonal eigenvalue problem
where \(f\) is determined from the eigenvalues \(\lambda_{lm}\) by solving the quadratic relation
This may be rearranged into the form
with two solutions for each \(l\), \(m\) given by
In the code, the eigenvalues are called lam
and the corresponding
matrix of eigenvectors is Q
. The solutions \(f_{lm}^+\) and
\(f_{lm}^-\) are called ffp
and ffm
respectively.
The solution may then be written as a sum of these two sets of radial eigenfunctions:
The coefficients \(c_{lm}\) and \(d_{lm}\) are then determined by the radial boundary conditions:
At the inner boundary \(\rho = 0\), where \(k=0\), we want \(B_\rho = -\nabla^2_\perp\psi\) to match our given distribution \(g^{j+\frac{1}{2},i+\frac{1}{2}}\). We have
\[B_\rho^{k,j+\frac{1}{2},i+\frac{1}{2}} = \sum_{l=0}^{n_s-1}\sum_{m=0}^{n_\phi-1}\frac{\lambda_{lm}}{\mathrm{e}^{2\rho^k}}\Big[c_{lm}(f_{lm}^+)^k + d_{lm}(f_{lm}^-)^k) \Big] Q_{lm}^{j+\frac{1}{2}}\mathrm{e}^{2\pi I mi/n_\phi},\]so
\[g^{j+\frac{1}{2},i+\frac{1}{2}} = \sum_{l=0}^{n_s-1}\sum_{m=0}^{n_\phi-1}\frac{\lambda_{lm}}{\mathrm{e}^{2\rho^0}}\Big[c_{lm} + d_{lm}\Big] Q_{lm}^{j+\frac{1}{2}}\mathrm{e}^{2\pi I mi/n_\phi}.\]We take the discrete Fourier transform of \(g^{j+\frac{1}{2},i+\frac{1}{2}}\) in \(i\), so that (noting \(\,\mathrm{e}^{\rho^0}=1\)),
\[\sum_{l=0}^{n_s-1}\sum_{m=0}^{n_\phi-1}\lambda_{lm} \Big[c_{lm} + d_{lm}\Big] Q_{lm}^{j+\frac{1}{2}}\,\mathrm{e}^{2\pi I mi/n_\phi} = \sum_{m=0}^{n_\phi-1}b_m^{j+\frac{1}{2}}\,\mathrm{e}^{2\pi I mi/n_\phi}.\]Then the orthonormality of \(Q_{lm}^{j+\frac{1}{2}}\) for different \(l\) allows us to determine
(12)#\[ c_{lm} + d_{lm} = \frac{1}{\lambda_{lm}}\sum_{j=0}^{n_s-1}b_m^{j+\frac{1}{2}}Q_{lm}^{j+\frac{1}{2}}.\]At the source (outer) surface \(\rho=\ln(R_{ss})\), where \(k=n_\rho\), there are two options.
Radial field - We impose \(\partial_\rho\psi = 0\), in the form \(\psi^{n_\rho,j+\frac{1}{2},i+\frac{1}{2}}=\psi^{n_\rho-1,j+\frac{1}{2},i+\frac{1}{2}}\), which gives
(13)#\[ \frac{d_{lm}}{c_{lm}} = \frac{(f_{lm}^+)^{n_\rho} - (f_{lm}^+)^{n_\rho-1}}{(f_{lm}^-)^{n_\rho-1} - (f_{lm}^-)^{n_\rho}}.\](Numerically it is better to compute this ratio the other way up, to prevent overflow.)
Imposed \(B_r\) - In this case the boundary condition is treated similarly to the inner boundary. We require
\[\hat{g}^{j+\frac{1}{2},i+\frac{1}{2}} = \sum_{l=0}^{n_s-1}\sum_{m=0}^{n_\phi-1}\frac{\lambda_{lm}}{\mathrm{e}^{2\rho^{n_\rho}}}\Big[c_{lm}(f_{lm}^+)^{n_\rho} + d_{lm}(f_{lm}^-)^{n_\rho}\Big] Q_{lm}^{j+\frac{1}{2}}\mathrm{e}^{2\pi I mi/n_\phi},\]so we may again take the discrete Fourier transform to end up with
(14)#\[ c_{lm}(f_{lm}^+)^{n_\rho} + d_{lm}(f_{lm}^-)^{n_\rho} = \frac{\mathrm{e}^{2\rho^{n_\rho}}}{\lambda_{lm}}\sum_{j=0}^{n_s-1}\hat{b}_m^{j+\frac{1}{2}}Q_{lm}^{j+\frac{1}{2}},\]
Solving (13) simultaneously with either (12) or (14) gives \(c_{lm}\) and \(d_{lm}\).
These are called clm
and dlm
in the code.
Remark: as we increase the grid resolution, the eigenfunctions \(Q_{lm}^{j+\frac{1}{2}}\), which are functions of \(\theta\), should converge to the corresponding associated Legendre polynomials \(P_l^m(\cos\theta)\), up to normalization. This is illustrated in Fig. 2.
References