A numerical procedure to solve Poisson’s equation in spherical coordinates

This paper sets out to present a numerical procedure that solves Poisson’s equation in a spherical coordinate system. To discretize this equation, integration techniques at the interfaces between different regions have been carried out allowing the calculation of both the potential and the corresponding field inside and outside a charge distribution. The Gauss-Seidel method is adopted to determine the potential in each region and the results, whenever compared with the analytical solutions found in the literature, come out very satisfactory, with errors less than 1% for distances of the order of 1 × 10−14 m and, for larger distances, they never reach 4%. keywords: Charge distribution, Gauss-Seidel method, electrostatic potential and field, numerical solution.


Introduction
Poisson's equation is an elliptic partial differential equation with a known non-trivial source term. This equation has a wide application in several areas of Physics and Engineering, such as Electrodynamics, Mechanics, Fluid Dynamics and the study of topological deffects. In Mechanics, for example, it is used to study the gravitational potential of mass distributions. In this case, it is referred to as Poisson's equation for gravity. Similarly, in Maxwellian Electromagnetism, it allows the computation of the scalar and vector potentials generated by charge and current distributions over space-time.
In the specific literature, several analytic solutions to Poisson's equation may be found in different coordinate systems. The simplest cases are the one-and twodimensional systems described in Cartesian coordinates. It is however important to mention that, in other coordinate systems, such as cylindrical or spherical coordinates, analytic solutions may not be found for generic source distributions. However, numerical solutions may always be attained with the help of some specific methods. Different numerical techniques to solve Poisson's equation to obtain electrostatic potentials are found in the literature of Computational Physics and Applied Mathematics, which use Fourier series [1], approximate analytic solutions [2] and finite difference discretization scheme [3]. In many situations, to simplify the problem, one assumes a homogeneous medium and the absence of * Correspondence email address: asilva@nuclear.ufrj.br electric charges, which reduces the problem to solving the Laplace equation.
This paper focus on solving Poisson's equation for problems that involve a uniform spherical charge distribution. To do that, azimuthal symmetry with respect to the φ-coordinate is invoked, yielding the electrostatic potential as a function of the r-and θ-coordinates, V (r, θ). Next, by taking the gradient of the latter, one readily computes the electrostatic field over all the space, inside and outside the charge distribution.
In addition, we next contemplate a non-homogeneous medium, where more than one region is involved. The best method we have found to tackle this problem consists in using integration techniques, which means discretizing Poisson's equation and integrating it numerically over an arbitrary volume element. As a step further, in this method, we can perform an integration on an interface region between the distinct media to have a complete answer.
This technique, known as point-(or interface-) centered scheme [4], allows an arbitrary number of regions to be considered, as long as they are physically acceptable. This is possible by using Uniqueness theorem [5], which states that the potential and its derivative are both continuous at the interface between two different media. (We should however notice that the presence of a superficial density of charges at the interface would prevent us from using the continuity of the derivative of the potential). As an outcome, the numerical procedure to solve Poisson's equation we present here, namely, based on the use of integration techniques, opens up the possibility to carry out field calculation for different geometries.

Poisson's Equation
The Poisson's equation for the electrostatic potential in spherical coordinates with azimuthal symmetry, so that the potential is φ-independent [5], is written as where ρ(r) is the charge density distribution, ε o is the electric permittivity of the vacuum and V (r, θ) is the potential we are searching for. The regions of interest are bounded as follows: r 0 and 0 • θ 180 • . An analytic solution may be obtained to Eq. (1), if it is assumed that the potential is only r-dependent, that is, the potential is a function V (r). Thus, the angular dependence represents the projection of the electric potential radial solution for different angles within the domain [0 • , 180 • ]. In this paper, an analytical solution is going to be derived in order to validate the numerical method that we shall implement further on.

The analytic solution
The Poisson's equation written in spherical coordinates for the r-dependent electrostatic potential reads as follows below: The purpose is to obtain solutions inside, (r R), and outside, (r > R), the charged sphere. The analytic solution to Eq. (2) is obtained by using differential equation techniques, which leads to the solutions in both regions. To do that, we take the charge density as given in what follows: Inside the charged sphere, where the density is constant, the electric potential can be obtained by Eq. (2) upon a direct integration, which results in where V in (r) is the solution for r R. Similarly, for the external region, where the charge density is zero, the solution takes the form where V out (r) is the potential for r > R. The coefficients of these solutions are fixed by imposing the following conditions: (i) The potential is continuous in R, such that ii) The derivative of the potential is continuous in R, The potential is zero at infinity, such that (iv) The derivative of the potential vanishes at r = 0, where have The electric field E(r) can then be readily attained: finally, These analytic solutions shall be, later on, compared with the numerical solutions, which are going to be worked out in the next Section.

Getting the numerical solution
The numerical solution to the electric potential in spherical coordinates is now presented. For this, the Finite difference method [6], to discretize the Eq. (1) using techniques of integration at the interface, has been used. This procedure approximates the derivative of a function, f (u), for consecutive points [u, u + ∆u] as given below: This allows us to approximate the function f (u) in the interval with a truncation error, Θ(∆u), where u = [r, θ]. So, the smaller the interval, more negligeable will be the error, rendering the numerical solution considerably close to the analytical solution. In the limit in which ∆u tends to zero in Eq. (10), we have the exact definition of the derivative of a function.
As this system involves different types of regions, the best form to approach the problem is by integrating numerically Eq. (1) in the volume of a sphere in the interval [r i− 1 2 , r i+ 1 2 ] and [θ j− 1 2 , θ j+ 1 2 ], as shown in Figure 1, such that Notice that the 2π factor appears in the equation as a result of the integral over the coordinate φ. That can be simplified by dividing the equation by 2π. Integrating this equation, we arrive at where each term is described below.
(i) The derivatives of the potential in the points r i+ 1 2 and r i− 1 2 are given by and (13b) We can now integrate these results. This yields: (ii) Similarly, the derivatives of the potential in θ j+ 1 and (iii) The integral of the charge density involves the regions i − 1 and i. So, we split the integral to simplify the calculation, The charge density depends on the region, so the integral of [r i− 1 2 , r − i ] is related to the region i − 1 and the integral of [r + i , r i+ 1 2 ] is related to the region i, resulting in where ρ o,i−1 and ρ o,i are, respectively, the charge densities in the regions i − 1 and i and the radius The reason for the use of integration techniques at the interface between different regions is that it already includes the continuity condition and derivative of the function at the interface. Combining the results obtained above in (i), (ii) and (iii): which can be rewritten as follows, where 0 i I and 0 j J. I and J is the total number of regions. It is important to stress that we have I, J regions and I + 1, J + 1 points calculation. To simplify the notation, we have defined V i,j ≡ V (r i , θ j ). The mesh will be defined according to the size of the region of calculation, such that, ∆r = R I /I e ∆θ = θ J /J. The coefficients of Eq. (20) and the source term will be defined as follows, In general, Eq. (20) is the numerical solution to Eq. (1) using the finite difference method, whose precision is directly related to the dimensions of the regions of calculation ∆r i = r i+1 − r i and ∆θ j = θ j+1 − θ j . The method proposed for numericalling solve this equation is known as Gauss-Seidel method [6] which is an iterative method developed to solve systems of linear equations. There are other methods of solution, such as the Jacobi method [6], that follows the same criteria of convergence as the Gauss-Seidel method, and non-iterative matrix methods, e.g., LU [6] factorization. The Gauss-Seidel method is generally used in problems involving diagonally dominant matrices, which is a necessary condition to ensure convergence.
The iteration of the Gauss-Seidel method to pentadiagonal matrices, as represented by Eq. (20), becomes i+1,j and in front V t−1 i,j+1 , we refer the reader to the diagram depicted in Figure 1.) This is the great advantage of the Gauss-Seidel method when compared to the Jacobi method. The iterative process is over when one or more convergence criteria are reached. These criteria are obtained from the percentage relative errors of the potential between the current and previous iterations.
Once the discretized equation for the potential is known, the boundary conditions for this problem can be imposed.

Boundary condition
There are two possibilities to express the boundary conditions. The first one is to assume that the potential is zero on the boundary; the second one is to use a symmetry condition to simplify the problem. In this case, due to the azimuthal symmetry, the electric potential will be calculated in regions r 0. In the literature, a more general condition is known as Albedo boundary condition [7], given by where u = [r, θ] and u n are the boundary regions, whereas u 0 and u N are, respectively, left and right boundaries. The Eq. (28) shows that, if α = 0, the derivative of the potential is zero at the boundary point, representing the symmetry condition or singularity at the origin. Now, β = 0 implies that the potential is zero at a boundary point.

Vanishing potential
We are assuming that the potential is zero on the right boundary, i.e., V (r I , θ j ) = 0. This is the simplest case, since that the potential is calculated in i = 0, . . . , I − 1 e j = 0, . . . , J.

Condition of symmetry and singularity
The symmetry conditions [8] are applied to the left boundary for the angle θ = 0 • and right boundary for the angles θ = 90 • , 180 • . In this case, we impose that, The singularity [3] is applied at the origin, r = 0. In this case, it is assumed that the derivative of the potential is zero, i.e., Eq. (19), in its simplified form given in Eq. (20), corresponds to the numerical solution of Eq. (1) for regions distant from the boundary. Now, to treat the condition of singularity and implement the symmetry, a new set of equations must be obtained to represent these regions we now wish to include. To meet our target, we believe it is more pedagogical to split the procedure in six steps, which altogether describe how we must work to include these new regions. The mentioned six steps are cast below: (i) The potential V (0, 0) is determined by integrating Eq. (1) over the interval [r 0 , r 0+ 1 2 ] and [θ 0 , θ 0+ 1 2 ]. Thus, we solve the problem of the singularity at the origin, as well as the left symmetry for a null angle. (ii) The potential V (0, θ j ) is determined by integrating Eq. (1) over the interval [r 0 , r 0+ 1 2 ] and [θ j− 1 2 , θ j+ 1 2 ]. In this case, we treat the singularity at the origin. (iii) The potential V (0, θ J ) is determined by integrating Eq. (1) over the interval [r 0 , r 0+ 1 2 ] and [θ J− 1 2 , θ J ]. As shown above, we solve the problem of the singularity and right symmetry for the angles 90 • or 180 • . (iv) The potential V (r i , 0) is determined by integrating Eq. (1) over the interval [r i− 1 2 , r i+ 1 2 ] and [θ 0 , θ 0+ 1 2 ]. Thus, we treat the problem of left symmetry for a null angle.
(v) The potential V (r i , θ j ) is given by Eq. (19). (vi) The potential V (r i , θ J ) is determined by integrating Eq. (1) over the interval [r i− 1 2 , r i+ 1 2 ] and [θ J− 1 2 , θ J ]. The right symmetry for the angles 90 • or 180 • has been treated in a similar way .

Results
The comparison between the results obtained by the numerical and analytic solutions to the Poisson's equation shall be now presented. In these calculations, it has been assumed ∆r = 10 −16 m and ∆θ = 0.5 • . The potential has been calculated in the domain of the electron radius. The electric charge density has been obtained by means of the following relation, where Q = 1.6 × 10 −19 C is the electron charge and R e 3.0×10 −15 m the electron radius. The convergence criteria of = 10 −6 for the calculation of the electric potential has been used.
The numerical method works with finite boundary conditions. Eq. (7) was obtained by using the condition that the potential outside the charged sphere is zero at infinity. So, to compare the numerical results with this analytic solution, we must assume a finite physical boundary for analytic solution and recalculate the coefficients of the solution. Notice that the solutions for the electric potential inside and outside the charged sphere, given by Eqs. (4) and (5), remain unchanged. The result obtained with the numerical solution for θ = 180 • is cast in Figure 2.
The comparison between the results obtained by the analytic and numerical solutions for the electric  potential is depicted in Figure 3. From the solution to the electric potential, the numerical solution to the electric field is readily attained. This has been calculated by approximating the derivative of Eq. (8) by finite differences, such that Once again, a comparison between the analytic and numerical solutions to the radial component was established in terms of the electric field ( Figure 4). Figures 3 and 4 show a qualitative comparison between the solutions. To quantify such a comparison, the percentage relative errors have been calculated using the following equation, where R a and R n represent the analytic and numerical results, respectively. For a better assessment, the resulting potential and radial component of the electric field and their relative errors are summarized in Table 1.
The maximum percentage relative error obtained in the calculation of the electric potential was 3.9%.

Concluding Comments
In this contribution, our major effort consisted in setting up a formulation to solve numerically Poisson's equation in spherical coordinates; continuity conditions on the function and its derivative at the interface between nonhomogeneous media have been imposed. By following this procedure, the electrostatic potential and field have been determined in the inner and external regions, and also compared with the analytic solution of the problem to give confidence that the method is reliable. For this, a program has been developed that allows to define spatial meshes with different sizes in each region. The accuracy of the method is directly related to the sizes of the meshes of the regions appearing in the calculations. We may therefore refine the spatial meshes to obtain more accurate results, since the angular mesh expands the radial solution at different angles within the angular domain, not affecting the radial solution of the problem. Fortran 90 has been adopted to develop this code. By integrating numerically the Poisson's equation, the singularity problem and symmetry have been treated and the electric potential has been written down in all radial and angular regions. Both qualitative and quantitative comparisons between the numerical and analytic solutions show a very satisfactory result of the numerical method, with relative errors less than 1% for distances of the order of 1 × 10 −14 m from the electric charge and always less than 4% for larger distances. We conclude by stating that this method is very helpful for the determination of the electrostatic potential in different non-homogeneous regions. Therefore, with the validation we have ascertained in the previous Sections, the method can be reliably applied to solve problems of a greater complexity. As a natural follow-up of the method and the results presented in this contribution, it would be advisable to consider the case of a non-spherically symmetric charge density, by contemplating the situation of a θ-dependent charge distribution. We shall endeavour this study and we shall be presenting our results in a forthcoming paper.