meshfree computation of electrostatics and related boundary value problems · 2017-06-16 ·...

8
COMPUTATIONAL PHYSICS The Computational Physics Section publishes articles that help students and their instructors learn about the physics and the computational tools used in contemporary research. Most articles will be solicited, but interested authors should email a proposal to the editors of the Section, Jan Tobochnik ([email protected]) or Harvey Gould ([email protected]). Summarize the physics and the algorithm you wish to include in your submission and how the material would be accessible to advanced undergraduates or beginning graduate students. Meshfree computation of electrostatics and related boundary value problems J. Wang a) and Y. Hao Department of Physics, University of Massachusetts Dartmouth, North Dartmouth, Massachusetts 02747 (Received 19 March 2017; accepted 29 March 2017) We discuss a meshfree method for solving boundary value problems in physics. The method uses random data interpolation and radial basis functions that depend on the distance, instead of the usual basis functions that depend on the position. As an example, we apply this method to the electrostatic problem of two parallel plates inside a conducting cylinder and discuss its convergence and robustness. The method is shown to be robust and flexible and can be an efficient alternative to mesh-based methods for solving computational problems involving irregular domains. V C 2017 American Association of Physics Teachers. [http://dx.doi.org/10.1119/1.4980147] I. INTRODUCTION There is a frequent need to solve problems that are described by partial differential equations 1 and to find numerical solu- tions that are unavailable analytically. 2 For example, we encounter partial differential equations in electromagnetism, including Poisson’s equation for the electrostatic potential given a charge distribution, and Maxwell’s equations describ- ing the propagation of electromagnetic waves. In quantum mechanics, it is almost impossible to avoid partial differential equations such as the time-dependent Schrodinger equation. Many problems can also be expressed as ordinary differential equations, but it is usually much more challenging to solve partial differential equations because they have at least two independent variables whereas an ordinary differential equa- tion has only one. There are systematic methods, such as Euler’s method, Runge–Kutta, and symplectic solvers, for solving many initial value problems involving ordinary differ- ential equations. However, few widely applicable approaches exist for partial differential equations. The appropriate method depends on the problem being investigated and the type of boundary conditions. 3 There are two common computational approaches for solving partial differential equations, mesh-based and mesh- free methods. In a mesh-based method, the domain is divided into small grids and the partial differential equation (opera- tors and solutions) is discretized over the domain. Finite dif- ference methods are the most familiar in this category. In contrast, meshfree methods represent the operators and solu- tions smoothly over a continuous domain without discretiza- tion. One such meshfree approach is exemplified by the basis expansion method where the solution is expanded in a com- plete (orthogonal) basis set and the operators are represented within the set, usually as matrices. This method is often employed in quantum mechanical problems. 4,5 Another similar approach is the Galerkin method, 6 which does not require a complete basis set. There are also hybrid methods combining mesh-based and meshfree frameworks using both domain discretization and basis functions. For instance, the finite element method divides the domain into small patches, represents the solution in terms of simple basis functions (incomplete basis), and constructs the opera- tor in an integral form (also called the “weak” form). 7,8 Mesh-based and meshfree methods are complementary and can be used where appropriate. Mesh-based methods such as the finite difference method are simpler, more direct, and easier to use for regular domains where uniform mesh generation is straightforward. It becomes more chal- lenging to scale these methods to higher dimensions or where the domain becomes irregular. The meshfree basis expansion method can be more robust and efficient when a complete basis set can be found. However, sometimes no good basis sets exist as is the case for an irregular polygo- nal domain. See, for example, Ref. 9. The lack of a good basis set can lead to poor convergence and loss of accuracy. A remedy to this situation is to use a truncated basis set instead, as long as the solution can be adequately repre- sented. Such approaches have proven to be effective. For example, the use of the Sturmian basis in place of a com- plete hydrogenic basis converges faster and yields accurate results in atomic calculations. 10 In this paper, we discuss a meshfree approach that is akin to a truncated basis set and is based on the use of radial basis functions. Unlike standard basis functions, a radial basis function usually has a simple functional form controlled by a shape parameter and centered at a point called a node. 11 A radial basis function depends only on the radial distance to the node and is independent of direction. A number of nodes are scattered randomly throughout the domain, and the solu- tion is interpolated using the radial basis functions, one for 542 Am. J. Phys. 85 (7), July 2017 http://aapt.org/ajp V C 2017 American Association of Physics Teachers 542

Upload: others

Post on 14-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Meshfree computation of electrostatics and related boundary value problems · 2017-06-16 · problems J. Wanga) and Y. Hao Department of Physics, University of Massachusetts Dartmouth,

COMPUTATIONAL PHYSICS

The Computational Physics Section publishes articles that help students and their instructors learn about

the physics and the computational tools used in contemporary research. Most articles will be solicited, but

interested authors should email a proposal to the editors of the Section, Jan Tobochnik ([email protected])

or Harvey Gould ([email protected]). Summarize the physics and the algorithm you wish to include in

your submission and how the material would be accessible to advanced undergraduates or beginning

graduate students.

Meshfree computation of electrostatics and related boundary valueproblems

J. Wanga) and Y. HaoDepartment of Physics, University of Massachusetts Dartmouth, North Dartmouth, Massachusetts 02747

(Received 19 March 2017; accepted 29 March 2017)

We discuss a meshfree method for solving boundary value problems in physics. The method uses

random data interpolation and radial basis functions that depend on the distance, instead of the

usual basis functions that depend on the position. As an example, we apply this method to the

electrostatic problem of two parallel plates inside a conducting cylinder and discuss its

convergence and robustness. The method is shown to be robust and flexible and can be an efficient

alternative to mesh-based methods for solving computational problems involving irregular

domains. VC 2017 American Association of Physics Teachers.

[http://dx.doi.org/10.1119/1.4980147]

I. INTRODUCTION

There is a frequent need to solve problems that are describedby partial differential equations1 and to find numerical solu-tions that are unavailable analytically.2 For example, weencounter partial differential equations in electromagnetism,including Poisson’s equation for the electrostatic potentialgiven a charge distribution, and Maxwell’s equations describ-ing the propagation of electromagnetic waves. In quantummechanics, it is almost impossible to avoid partial differentialequations such as the time-dependent Schr€odinger equation.Many problems can also be expressed as ordinary differentialequations, but it is usually much more challenging to solvepartial differential equations because they have at least twoindependent variables whereas an ordinary differential equa-tion has only one. There are systematic methods, such asEuler’s method, Runge–Kutta, and symplectic solvers, forsolving many initial value problems involving ordinary differ-ential equations. However, few widely applicable approachesexist for partial differential equations. The appropriate methoddepends on the problem being investigated and the type ofboundary conditions.3

There are two common computational approaches forsolving partial differential equations, mesh-based and mesh-free methods. In a mesh-based method, the domain is dividedinto small grids and the partial differential equation (opera-tors and solutions) is discretized over the domain. Finite dif-ference methods are the most familiar in this category. Incontrast, meshfree methods represent the operators and solu-tions smoothly over a continuous domain without discretiza-tion. One such meshfree approach is exemplified by the basisexpansion method where the solution is expanded in a com-plete (orthogonal) basis set and the operators are representedwithin the set, usually as matrices. This method is oftenemployed in quantum mechanical problems.4,5

Another similar approach is the Galerkin method,6 whichdoes not require a complete basis set. There are also hybridmethods combining mesh-based and meshfree frameworksusing both domain discretization and basis functions. Forinstance, the finite element method divides the domain intosmall patches, represents the solution in terms of simplebasis functions (incomplete basis), and constructs the opera-tor in an integral form (also called the “weak” form).7,8

Mesh-based and meshfree methods are complementaryand can be used where appropriate. Mesh-based methodssuch as the finite difference method are simpler, moredirect, and easier to use for regular domains where uniformmesh generation is straightforward. It becomes more chal-lenging to scale these methods to higher dimensions orwhere the domain becomes irregular. The meshfree basisexpansion method can be more robust and efficient when acomplete basis set can be found. However, sometimes nogood basis sets exist as is the case for an irregular polygo-nal domain. See, for example, Ref. 9. The lack of a goodbasis set can lead to poor convergence and loss of accuracy.A remedy to this situation is to use a truncated basis setinstead, as long as the solution can be adequately repre-sented. Such approaches have proven to be effective. Forexample, the use of the Sturmian basis in place of a com-plete hydrogenic basis converges faster and yields accurateresults in atomic calculations.10

In this paper, we discuss a meshfree approach that is akinto a truncated basis set and is based on the use of radial basisfunctions. Unlike standard basis functions, a radial basisfunction usually has a simple functional form controlled by ashape parameter and centered at a point called a node.11 Aradial basis function depends only on the radial distance tothe node and is independent of direction. A number of nodesare scattered randomly throughout the domain, and the solu-tion is interpolated using the radial basis functions, one for

542 Am. J. Phys. 85 (7), July 2017 http://aapt.org/ajp VC 2017 American Association of Physics Teachers 542

Page 2: Meshfree computation of electrostatics and related boundary value problems · 2017-06-16 · problems J. Wanga) and Y. Hao Department of Physics, University of Massachusetts Dartmouth,

each node. The goal is to determine the interpolationcoefficients.12

Just as central field potentials possess unique properties,radial basis functions have advantageous properties that canbe very useful in computation. In the following, we will dis-cuss these properties and show how they can be used to effi-ciently solve partial differential equations by the collocationmethod. By way of introduction, we discuss an electrostaticproblem to illustrate that this method is one of the simplestto use. Radial basis function methods are being used in anincreasing number of computational problems13,14 and haveimportant applications to complex problems, including quan-tum few-body problems15 and artificial neural networks.16

In Sec. II, we introduce radial basis functions and discussthe important role of the shape parameter in radial basisfunction interpolation. We discuss in Sec. III the general col-location method of solving partial differential equations interms of radial basis functions. We apply the method to elec-trostatic problems in Sec. IV and discuss the results in termsof convergence and robustness. In Sec. V, we propose sev-eral possible projects for further exploration and concludewith a brief summary.

II. RADIAL BASIS FUNCTION INTERPOLATION

The use of basis functions is common. For instance, inquantum mechanics we use the superposition principle toexpand the initial wave function in terms of all possible sta-tionary states, a complete basis set in Hilbert space.17 Thereare similar applications of basis sets such as the Bessel func-tions and the spherical harmonics in electrostatics and acous-tics.18 In atomic, molecular, and optical physics, some of themost accurate calculations are performed with basis expan-sion methods, sometimes involving tens of thousands ormore terms for moderate to large atomic systems and mole-cules.19 Traditional basis functions are single-centered (usu-ally at the origin) and their values depend on the positions ofthe variables from the origin.

A direct way to introduce another type of basis function,such as the radial basis function, is through data interpola-tion. Suppose we have a set of N random data points in adomain and wish to find a function (solution) so that thesolution can be found at any point by interpolating betweenthe random points. To do so, we assume a basis set /ið~rÞ andwrite the interpolant (solution) u as an expansion in the basisset

uð~rÞ ¼XN

i¼1

ai/ið~rÞ; (1)

where the ai are the expansion coefficients. The goal is tofind the ai such that the interpolant yields known values atthe random data points.12,20 Away from these points, weassume that Eq. (1) is an accurate approximation to theactual solution. The accuracy depends on the choice of thebasis set.

In a traditional approach, the basis set may be linear func-tions, polynomials, or some other function of position with acommon origin. Instead, we place a basis function centeredat each random data point, for a total of N basis functions.Instead of treating each center as the origin, we stipulate thatthe value of the basis function be positive definite anddepends on the Euclidean distance from the location of the

random data point only. What we have described is coverageof the domain by radial basis functions.

There are many possible functional forms for /i.12 Two

common radial basis functions are the Gaussian and the mul-tiquadric functions

/ið~rÞ ¼ e��2j~r�~r ij2 ðGaussianÞ; (2)

/ið~rÞ ¼ffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi1þ �2j~r �~rij2

qðMultiquadricÞ; (3)

where � is the shape (control) parameter and~ri are the nodes(centers) randomly scattered over the domain of interest. Theshape parameter determines the sharpness of the radial basisfunction. The larger the value of �, the sharper the radialbasis function, and the smaller the value of �, the flatter theradial basis function. As we will discuss, � is a free parame-ter that should be chosen with care. Note that /i in Eqs. (2)and (3) has a simple form, is positive definite, and dependsonly on the radial distance j~r �~rij.

We can use Eq. (1) for random data interpolation.Suppose we have N random data points ui at~ri, i¼ 1 to N. Atpoint j, we require that uð~rjÞ ¼ uj. That is,

XN

i¼1

ai/ið~rjÞ ¼ uj; (4)

where we have taken the nodes to coincide with the randomdata points. (We will use the terms “node” and “random datapoints” interchangeably.) There are N coupled equations inEq. (4), one for each node. The coefficients ai can be deter-mined by solving for them simultaneously.

We can express the result in a more compact matrix form

/1ð~r1Þ /2ð~r1Þ � � � /Nð~r1Þ/1ð~r2Þ /2ð~r2Þ � � � /Nð~r2Þ

..

. ... . .

. ...

/1ð~rNÞ /2ð~rNÞ � � � /Nð~rNÞ

2666664

3777775

a1

a2

..

.

aN

2666664

3777775¼

u1

u2

..

.

uN

2666664

3777775:

(5)

The elements in the matrix are defined by the radial basisfunction collocation method. This method requires that acontinuous solution (interpolant) is constructed such that thesolution is exact at a chosen set of nodes. The matrix ele-ments are given by

/ið~rjÞ ¼ /ðj~ri �~rjjÞ ¼ /jð~riÞ � /ij; (6)

where / is given by Eqs. (2) or (3). Equation (5) is a systemof linear equations and can be solved for the expansion coef-ficients provided that the matrix /ij can be inverted. Becausethe radial basis functions depend on the radial distance rij ¼j~ri �~rjj from the nodes, the system matrix is symmetric,positive definite, and generally well-conditioned.21

As an example, consider the test function f ðxÞ ¼ xðL� xÞexp½�ðx� L=3Þ2� defined in the interval 0 � x � L. We firstchoose N nodes at random locations xj with uj ¼ f ðxjÞ. Usingthese known values, we determine the expansion coefficientsfrom Eq. (5). We can assess the accuracy of the interpolation bycalculating the average error between the function f(x) and the

interpolant [Eq. (1)] defined as D ¼ M�1PM

k¼1 jf ðxkÞ � uðxkÞj

543 Am. J. Phys., Vol. 85, No. 7, July 2017 J. Wang and Y. Hao 543

Page 3: Meshfree computation of electrostatics and related boundary value problems · 2017-06-16 · problems J. Wanga) and Y. Hao Department of Physics, University of Massachusetts Dartmouth,

at a set of check points xk. These points xk can be chosenarbitrarily except that they should not concide with thenodes.

In Fig. 1, we show the results of the average interpolationerror versus the number of nodes N (the number of radialbasis functions). Gaussian radial basis functions are used fortwo values of �. For comparison, we show the result using atraditional basis expansion method, with the basis set com-posed of the eigenfunctions for a particle in a box,wkðxÞ ¼

ffiffiffiffiffiffiffiffi2=L

psinðkpx=LÞ. In this case, N is equal to the

number of basis functions included in the interpolant, k¼ 1to N. The nodes are uniformly distributed between 0 �x=L � 1 for simplicity. For each N � 3; M ¼ N � 1 checkpoints xj are chosen by shifting the nodes by an amountsmaller than the gap between two neighboring nodes suchthat they interleave each other. Because there are fluctuationsin the error depending on the particular set of check points,the error is calculated by averaging over several sets of dif-ferent amounts of the shift for each value of �.

We see that the error initially rapidly decreases withincreasing N. We expect the interpolation to improve withmore nodes and the result to be a more accurate representa-tion. However, for radial basis functions there is a certainnumber of nodes, NL, for which the error reaches a minimumand increases slightly afterward. The value of NL (marked byarrows in Fig. 1) depends on �. There is no benefit to begained by using N > NL. Regardless, the results show thatthe value of � can affect the accuracy significantly. (In thisexample, much better results close to machine accuracy canbe obtained with an optimal shape parameter on the order ofunity, see Project 1 in Sec. V.) In comparison, the basisexpansion method result does not show saturation, and theerror decreases slowly, but monotonically. However, theerror associated with the basis expansion method is muchgreater than the error associated with the radial basis func-tions for �¼ 2 in the range of N shown. Given the shallowslope, the basis expansion method would require roughly tentimes the number of nodes to achieve an accuracy compara-ble to the smallest error of the radial basis functions at N �20 (and �¼ 2). We conclude that the radial basis functioninterpolation method can be more efficient than a traditionalbasis expansion method, provided an adequate shape param-eter is used.

Maximizing efficiency is even more important in higherdimensions because the number of nodes needed for ade-quate accuracy is expected to scale as Nd, where d is thespatial dimension. Figure 2(a) shows an example in twodimensions in which the landscape is accurately repre-sented with only 36 nodes. Finding the interpolant is simi-lar to what is done for the one-dimensional case byreplacing the nodes xi by its vector equivalent ~ri (seeProject 1 in Sec. V). The reduced representation from thefour most dominant Gaussian radial basis functions isshown separately [see Fig. 2(b)]. As we expect, each peakcorresponds to one dominant radial basis function centerednear its center. This example also illustrates that if thelandscape is uneven or sharply peaked, more nodes can beconcentrated (an adaptive procedure) near these regions soas to better represent those features. The same idea appliesto irregularly shaped boundaries.

Fig. 1. The average interpolation error versus the number of nodes N. For

the radial basis functions (RBF), the arrows indicate the smallest error for a

given value of �. The basis expansion method (BEM) result uses the eigen-

functions for a particle in a box.

Fig. 2. (a) A full radial basis function interpolation of a surface and (b) the reduced surface by the four most dominant radial basis functions.

544 Am. J. Phys., Vol. 85, No. 7, July 2017 J. Wang and Y. Hao 544

Page 4: Meshfree computation of electrostatics and related boundary value problems · 2017-06-16 · problems J. Wanga) and Y. Hao Department of Physics, University of Massachusetts Dartmouth,

It can be shown that the determinant of the matrix in Eq.(5) is invariant under exchange of any pair of nodes becausethe scalar distances rij remain the same.14 Therefore, irre-spective of the locations of the nodes, the matrix is well-conditioned, and the solution is ensured to be nonsingular.However, if the basis functions are position (rather than dis-tance) based, these properties would no longer hold in gen-eral. In this respect, randomly scattered data interpolation byradial basis functions has unique advantages.

Now that we have seen that radial basis function interpola-tion can accurately and efficiently represent the solution toan example problem, we discuss how it can be used to solvepartial differential equations.

III. RADIAL BASIS FUNCTION SOLUTIONS OF

PARTIAL DIFFERENTIAL EQUATIONS

The form of the linear partial differential equations wetypically encounter in physics is

Luð~rÞ ¼ qð~rÞ; (7)

where L ¼ r2 þ~p � r þ q is a linear operator and q is thesource term. Equation (7) reduces to the Poisson equation if~p ¼ 0 and q¼ 0, with q the charge density. We assume thata system can be described by Eq. (7) over the interior of adomain, a region surrounded by an arbitrary boundary. Thetask is to find a solution satisfying the given boundaryconditions.

As discussed in Sec. II, we propose a solution that isexpressed in terms of a radial basis function interpolant, Eq.(1), and solve the partial differential equation by the colloca-tion method. Let N be the total number of random nodes. Ofthese, we assume that the number of internal nodes is n, andthe number of boundary nodes is N – n. The radial basisfunction collocation method finds the solution that satisfiesEq. (7) at the internal nodes and the boundary values at theboundary nodes. The key step is to construct the differentia-tion operator matrix13,20 based on differentiating the radialbasis function interpolant.

As an example, we use the collocation method to solve thetwo-dimensional Poisson equation with radial basis functions(the method is equally applicable to three dimensions). Todo so, we substitute the interpolant Eq. (1) into the partialdifferential equation Eq. (7) and obtain

Lu ¼X

i

aiL/ið~rÞ ¼ qð~rÞ: (8)

The collocation method, also known as Kansa’s method,22

stipulates that the approximate equation Eq. (8) be satisfiedat the internal nodes ~rj; j 2 ½1; n�, and the boundary condi-tions be satisfied at the boundary nodes~rj; j 2 ½nþ 1;N�.

For simplicity, we assume Dirichlet boundary conditions.The application of the collocation method leads to

Xi

aiL/ið~rÞj~r¼~r j¼ qð~rjÞ ð1 � j � nÞ; (9a)

Xi

ai/ið~rjÞ ¼ bj ðnþ 1 � j � NÞ; (9b)

where bj ¼ uð~rjÞ are the boundary values at the boundarynodes. By rewriting Eq. (9) in the matrix form, we obtain

Aa ¼ b; (10)

where a ¼ ½a1; a2;…; aN�T is a column vector to be solvedfor, and

A ¼

L11 L12 � � � L1N

..

. ... . .

. ...

Ln1 Ln2 � � � LnN

/nþ1;1 /nþ1;2 � � � /nþ1;N

..

. ... . .

. ...

/N1 /N2 � � � /NN

2666666666664

3777777777775

; b ¼

q1

..

.

qn

bnþ1

..

.

bN

2666666666664

3777777777775

:

(11)

The charge density qj ¼ qð~rjÞ is the source term at node j.The differential operator and radial basis function values aredefined as

Lij ¼ L/ið~rÞ� �

j~r¼~r j; /ij � /ið~rjÞ: (12)

Part of the system matrix A comes from the linear differen-tial operator and the other part from the radial basis functionsthemselves, so it is no longer symmetric. Other constraintscan be imposed to satisfy additional requirements in a mannersimilar to the treatment of boundary conditions.23

The algorithm for the collocation method consists of threestraightforward steps: generate the nodes and prepare thevector b from the source term and boundary values; con-struct the system matrix A according to the specific radialbasis functions (Gaussian or multiquadric) and the nodes;and invert the linear system Eq. (10) using a standard matrixsolver8,24 to find the solution, a ¼ A�1b. We next discuss anexample.

IV. ELECTROSTATIC PROBLEM: THE LAPLACE

EQUATION

We follow the method described in Sec. III to solve a spe-cial case of Eq. (7), ~p ¼ 0; q ¼ q ¼ 0. This case is just theLaplace equation, L ¼ r2; r2u ¼ 0. It is a classic problemfor which much insight has been gained from several algo-rithms including a random-walk probabilistic interpretation.3

To be definite, we find the electrostatic potential withinthe domain of a unit circle using the multiquadric radial basisfunctions in Eq. (3). We assume that the circumference(wall) is grounded at zero potential. Inside the wall, we placetwo parallel plates of width ‘ and separation d. The upperplate is held at a positive potential (þ 1) and the lower plateat a negative potential (–1). This problem can be thought ofas two long strips inside a conducting cylinder. Because ithas cylindrical symmetry, we can solve the Laplace equationas a two-dimensional problem. A sample cross sectionalview is illustrated in Fig. 3.

Inside the circle, internal nodes are distributed over thedomain according to a Halton sequence.25 The Haltonsequences are series of pseudorandom numbers generatedfrom repeatedly subdividing the unit interval by a primenumber. They are known to produce low-discrepancy distri-butions,20 which means that, on average, a Halton sequencecan cover a given range more uniformly than pseudorandomnumbers, which can form dense clusters. We use a Halton

545 Am. J. Phys., Vol. 85, No. 7, July 2017 J. Wang and Y. Hao 545

Page 5: Meshfree computation of electrostatics and related boundary value problems · 2017-06-16 · problems J. Wanga) and Y. Hao Department of Physics, University of Massachusetts Dartmouth,

sequence to avoid a node collision where two nodes very closeto each other can cause the system matrix to be singular. Witha sufficient number of nodes generated from the Haltonsequences, the domain can be adequately covered and be freeof node collisions (see Fig. 3). The boundary nodes on the par-allel plates are distributed equidistantly. On the wall, bound-ary nodes are placed at uniform angular displacements.

The placement of nodes right on the wall (or any curvedboundary) would be difficult to do in a simple mesh-basedgrid such as in the finite difference method. One could havea denser grid to increase proximity to the circumference, butthat would increase the number of grid points at the expenseof efficiency. With the radial basis function method, irregu-larities in the shape of the boundary pose no such difficulty.Care should be taken to avoid internal-boundary node colli-sions as well.

We next prepare the vector matrix b. The first n rows arezero because the charge density is zero at the internal nodes.If the boundary nodes are on the wall, the correspondingrows are also set to zero. On the upper and lower plates, the

boundary nodes are set to þ1 and �1, respectively. In prac-tice, the matrix b is usually filled while the nodes are beinggenerated (see the example program in Ref. 26). These con-siderations complete step one of the method.

Next, we construct the system matrix A. According to Eq.(12), the basic differential operator with the multiquadricfunction is

Lij ¼ r2/i ~rð Þ� �

j~r¼~r j¼hr2

ffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi1þ �2j~r �~rij2

q i���~r¼~r j

¼ �21þ /2

ij

/3ij

;

/ij ¼ffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi1þ �2j~rj �~rij2

q: (13)

Given Lij and /ij in Eq. (13), the system matrix A in Eq. (11)is readily formed.

Finally, we call a standard linear system solver to obtainthe coefficients a1;…; aN . The value of u at any point in thedomain can be found from the interpolant Eq. (1).

We show in Fig. 4 the electrostatic potential for two paral-lel plates within a cylinder of unit radius (the Python pro-gram we used is available as supplementary material26). Thetwo parallel plates are centered on the axis. Their width is‘ ¼ 4=5 and the separation between them is d ¼ 2=5.Between the plates, we see a flat surface showing a linearslope of the potential. This behavior is confirmed from thenearly straight and equidistant contour lines [see Fig. 4(b)].As a result, the electric field computed from the gradient ofthe potential is uniform within the parallel plates to a goodapproximation, consistent with the ideal case in which theseparation is assumed to be very small compared to platesize (that is, infinite parallel plates), even though the separa-tion is only half the width in the problem.

Outside the plates, the potential differs considerably fromthe ideal case because of the finite plate size and the circlebeing grounded. Near the edges of the plates, there are largevariations in the potential and large fringe fields. Away fromthe plates, the electric field is much smaller but nonzero. Thecalculation well preserves reflection symmetry, including thezero potential line going through the middle between the par-allel plates.

The results in Fig. 4 are computed with the multiquadricradial basis function and the shape parameter �¼ 20. As dis-cussed, the value of � can affect the accuracy significantly, at

Fig. 3. Sample domain of a unit circle (grounded) and two parallel plates

held at constant potentials. The internal nodes are denoted by () and the

boundary nodes by (•). The boundary values are zero on the circumference

and 61 on the upper and lower plates, respectively.

Fig. 4. (a) The potential surface and (b) equipotential contours overlaid with the electric field of two parallel plates centered in a cylinder.

546 Am. J. Phys., Vol. 85, No. 7, July 2017 J. Wang and Y. Hao 546

Page 6: Meshfree computation of electrostatics and related boundary value problems · 2017-06-16 · problems J. Wanga) and Y. Hao Department of Physics, University of Massachusetts Dartmouth,

least for the test case using radial basis function interpolation(see Fig. 1). Given the choice of the type of radial basis func-tion, the optimal shape parameter depends also on the aver-age spacing and location of the nodes.13 The number anddensity of nodes should be sufficiently large to achieve ade-quate coverage. If we consider the characteristic width of themultiquadric radial basis function to be of the order 1=�, thecoverage is sufficient if the average spacing between neigh-boring nodes h is equal to the width h � 1=�; that is,

�h ’ 1: (14)

According to Eq. (14), if there are N nodes per unit length,h � 1=N, then a good trial shape parameter is � � aN, wherea is a factor on the order of one. We tested values ofa ’ 0:5–1, and all produced well converged results. For theresults of Fig. 4, a value of a � 0:6 was used based on thenearest neighbor spacing of the Halton points (see the pro-gram in Ref. 26). The results are in good agreement with theresults from other methods, including relaxation and finiteelement methods.27 Note that the condition (14) and thevalue of a should be chosen more conservatively if Gaussianradial basis functions are involved because their sharpnessfor large � could cause an ill-conditioned system matrix.

To test the robustness of the method, we can compute thepotential for different boundary conditions or charge distri-butions with the same approach. We need only to modify theinitialization part of the program so the nodes and the vectorb reflect the change in the source and boundary values. Forexample, if the parallel plates are offset from the center, howwill the potential change? In Fig. 5, we show the resultswhen they are off center by ð�1=4;�1=10Þ. Compared tothe centered plates, the field is shifted overall in the directionof the offset, but the contour lines are deformed, beingsqueezed on the side near the wall and stretched on the otherside. We also see stronger electric fields where the contourlines are denser. Inside the plates, the electric field remainsuniform and unaffected to a large extent, showing that theideal case of infinite plates is a very good approximationeven in nonideal situations. Although difficult to see in Fig.

5, the electric field near the wall is perpendicular to it asexpected no matter how the plates are placed. We see thatthe method produces stable solutions with only appropriatechanges in the initialization.

V. DISCUSSION AND EXPLORATION

We have introduced radial basis functions and randomdata interpolation and discussed an example in which theinterpolant accurately represents the test function. Weshowed that radial basis function interpolation can be moreefficient with much fewer nodes than traditional position-based function interpolation, provided a proper shape param-eter is chosen. We also illustrated that radial basis functioninterpolation can be easily generalized to higher dimensions.The potential efficiency gain in high-dimensional problemsmakes radial basis function methods more attractive to suchapplications.

We then discussed a radial basis function collocationmethod of solving partial differential equations. The colloca-tion method consists of three steps, namely, generating nodesand boundary values, constructing the differential operatorbetween the nodes (collocation), and solving the resultinglinear system with a standard matrix solver. The radial basisfunction collocation method is perhaps the simplest meshfreemethod for solving a partial differential equation.

We suggest the following problems for the interestedreader.

(1) Radial basis function interpolation. To test radial basisfunction interpolation, start with a simple one-dimensional function, compute the interpolation coeffi-cients using the Gaussian radial basis functions, and thenplot the interpolant Eq. (1) and the function and comparethe two. Also calculate the average error as in Fig. 1 (sayover ten sets excluding two highs and lows at both ends).Change the shape parameter (for example, �¼ 1), switchthe radial basis function type to multiquadric, and repeatyour calculations. Once it works in one dimension, mod-ify your program to interpolate a function in two dimen-sions. For instance, try a test function similar to the oneshown in Fig. 2, f ðx; yÞ ¼ expð�x2yÞ sin2ð2pxÞ sin2ð2pyÞover the unit square. Examine the leading terms with thelargest coefficients ai.

(2) Electric fields. Compute the electric field from the poten-tial, ~E ¼ � ~ru ¼ �

Pai~r/i. Add a function to the pro-

gram (see Ref. 26) that returns the electric field given theposition. Predict what Ey would be across a horizontalline. Then, compute and plot it inside the plates, forexample, at y¼ 0 or 6d=4. Compare with the ideal caseof ~E ¼ �ð2=dÞy.

(3) The potential for off-centered plates. Modify your pro-gram to compute the potential for off-centered plates(see Fig. 5). You need to change only the initializationfunction in the program to add an offset ðDx;DyÞ to thelocation of the plates. Study how the fields change fordifferent offsets.

(4) Poisson’s equation. Compute the potential and fieldwhen the plates carry positive and negative surfacecharges, respectively, instead of being held at constantpotentials; that is, solve the Poisson equation. Modifythe initialization function in your program to change theboundary nodes on the plates to internal nodes. Alsochange the corresponding rows in the matrix b so they

Fig. 5. The equipotential contours overlaid with the electric field of two par-

allel plates off-centered within a cylinder.

547 Am. J. Phys., Vol. 85, No. 7, July 2017 J. Wang and Y. Hao 547

Page 7: Meshfree computation of electrostatics and related boundary value problems · 2017-06-16 · problems J. Wanga) and Y. Hao Department of Physics, University of Massachusetts Dartmouth,

are set to charge densities (61). Predict what the poten-tial will look like. Do the calculation and compare withyour predictions.

(5) The capacitance of coaxial cylinders. Consider twocoaxial cylinders as shown in Fig. 6(a). Change the ini-tialization part of the program to replace the plates withan inner circle of radius a, set the boundary value to 1 onit, and exclude any nodes within it. First calculate theelectric field as described in Project 2 at M points (say30) on a circle of radius r around the axis with a< r<R(with R being the outer radius). Compare the computedvalues of the electric field with the exact value ofEr ¼ ½lnðR=aÞr��1

. The electric flux per unit length isgiven by 2pr �E, where �E ¼

PkEk=M. The charge from

Gauss’ law is Q ¼ e02pr �E (e0 is the permittivity con-stant), and hence, the capacitance is C ¼ Q=V ¼ e02pr �Ebecause V¼ 1 in our calculation. The suggested parame-ters are a¼ 0.5, N¼ 40 nodes across the outer diameter,� ¼ 6:5, and r¼ 0.75. This radius should not be too closeto either the inner or outer walls because the calculationof the electric fields is sensitive to small variations in thepotential. Compare the numerical capacitance with theexact result e02p=lnðR=aÞ.

(6) For an added challenge, predict what happens to the fieldand capacitance if the inner cylinder is off-centered [seeFig. 6(b)]. Will C increase or decrease? Move the innercylinder off center slightly, and compute the field andcapacitance. Note the latter is nontrivial because for anyappreciable offset, the magnitude of the electric fieldwill not be constant on a circle, and its direction will notbe perpendicular to it at all points. Lastly, instead ofusing the Halton random sequences in the interior, do thecalculation with a uniform grid and equidistant nodespacing, and describe your observations.

In summary, the meshfree radial basis function method iscomplementary to traditional methods and is sometimesadvantageous. With its simplicity and power, the method isespecially useful for solving problems that are simple todefine but nontrivial to explore computationally. For instance,both the radial basis function and finite element methods cantreat irregular boundaries easily,28,29 but the latter is muchmore involved to implement. Other possible applicationsinclude solving time-dependent problems such as vibration,

wave propagation, quantum few-body dynamics, and eveneigenvalue problems. Ongoing research in adaptive radialbasis function methods in which the nodes are allocateddynamically can potentially help shed new light on manycomputationally challenging problems in physics.15,30

ACKNOWLEDGMENT

The authors are grateful to Alfa Heryudono for usefuldiscussions.

a)Eectronic mail: [email protected]; URL: http://www.faculty.umassd.

edu/j.wang1S. M. Lea, Mathematics for Physicists (Thomson Brooks/Cole, Belmont,

CA, 2004).2N. Giordano and H. Nakanishi, Computational Physics, 2nd ed. (Benjamin

Cummings, New York, 2005).3H. Gould, J. Tobochnik, and W. Christian, An Introduction to ComputerSimulation Methods: Applications to Physical Systems, 3rd ed. (Addison-

Wesley, New York, 2007).4M. Belloni and W. Christian, “Time development in quantum mechanics

using a reduced Hilbert space approach,” Am. J. Phys. 76, 385–392 (2008).5J. Wang and J. D. Champagne, “Simulation of quantum systems with the

coupled channel method,” Am. J. Phys. 76, 493–497 (2008).6D. Dubin, Numerical and Analytical Methods for Scientists and Engineersusing Mathematica (John Wiley & Sons, New York, 2003).

7J. N. Reddy, An Introduction to the Finite Element Method (McGraw-Hill,

New York, 1993).8J. Wang, Computational Modeling and Visualization of Physical Systemswith Python (John Wiley & Sons, New York, 2016).

9D. L. Kaufman, I. Kosztin, and K. Schulten, “Expansion method for sta-

tionary states of quantum billiards,” Am. J. Phys. 67, 133–141 (1999).10Y. Qiu, J. Z. Tang, J. Burgd€orfer, and J. Wang, “Double photoionization

of helium from threshold to high energies,” Phys. Rev. A 57,

R1489–R1492 (1998).11M. D. Buhmann, Radial Basis Functions: Theory and Implementations

(Cambridge U.P., Cambridge, 2003).12H. Wendland, Scattered Data Approximation (Cambridge U.P.,

Cambridge, 2005).13E. Larsson and B. Fornberg, “A numerical study of some radial basis func-

tion based solution methods for elliptic PDEs,” Comput. Math. Appl. 46,

891–902 (2003).14N. Flyer and B. Fornberg, “Radial basis functions: Developments and

applications to planetary scale flows,” Comput. Fluids 46, 23–32 (2011).15N. F. Johnson, “Quantum dots: Few-body, low-dimensional systems,”

J. Phys.: Condens. Matter 7, 965–989 (1995).16S. O. Haykin, Neural Networks and Learning Machines, 3rd ed. (Pearson

Prentice Hall, Upper Saddle River, NJ, 2009), Sec. 5.4, Radial basis func-

tion networks.

Fig. 6. (a) The domains of coaxial cylinders and (b) off-axial cylinders.

548 Am. J. Phys., Vol. 85, No. 7, July 2017 J. Wang and Y. Hao 548

Page 8: Meshfree computation of electrostatics and related boundary value problems · 2017-06-16 · problems J. Wanga) and Y. Hao Department of Physics, University of Massachusetts Dartmouth,

17D. J. Griffiths, Introduction to Quantum Physics, 2nd ed. (Pearson Prentice

Hall, Upper Saddle River, NJ, 2005).18G. B. Arfken and H. J. Weber, Mathematical Methods for Physicists, 7th

ed. (Academic Press, New York, 2012).19J. Almlof and P. R. Taylor, “Atomic natural orbital (ANO) basis sets for

quantum chemical calculations,” Adv. Quantum Chem. 22, 301–373 (1991).20G. E. Fasshauer, Meshfree Approximation Methods with MATLAB (World

Scientific, Hackensack, NJ, 2007).21R. Schaback, “Limit problems for interpolation by analytic radial basis

functions,” Comput. Appl. Math. 212, 127–149 (2008).22E. J. Kansa, “Multiquadrics—A scattered data approximation scheme with

applications to computational fluid dynamics II: Solutions to parabolic,

hyperbolic, and elliptic partial differential equations,” Comput. Math.

Appl. 19, 147–161 (1990).23B. Fornberg and N. Flyer, “Solving PDEs with radial basis functions,”

Acta Numer. 24, 215–258 (2015).24W. H. Press, S. A. Teukolsky, W. T. Vetterling, and B. P. Flannery,

Numerical Recipes: The Art of Scientific Computing, 3rd ed. (Cambridge

U.P., Cambridge, 2007).25For more information on the Halton sequence, see for instance Ref. 20.

There appears to be no general rules about node distribution, other than

that they should offer adequate coverage, be sufficiently dense where the

solution varies wildly and where a boundary turns sharply, and not so close

as to make the system matrix singular. Nonetheless, the locations of the

nodes may represent a potential degree of freedom that can be exploited to

our advantage. A case in point is the abscissa placement in Gaussian inte-

gration.18 It is sometimes assumed that some other independent way (such

as equilibrium points or standing wave nodes) may foretell a set of good

nodes from bad ones, proof again that sometimes numerical computing is

more of an art form instead of science than perhaps comfortably wished.26See supplementary material at http://dx.doi.org/10.1119/1.4980147 for

the Python program and Jupyter notebook; they can also be downloaded

from <http://www.faculty.umassd.edu/j.wang/ajp/>.27A treatment using the finite element method is discussed in Ref. 8, Chap.

7.28P. Niraula, Y. Han, and J. Wang, “Comparison of meshfree and mesh-

based methods for boundary value problems in physics,” J. Phys.: Conf.

Ser. 640, 012067 (2015).29J. Golde, J. Shertzer, and P. Oxley, “Finite element solution of Laplace’s

equation for ion-atom chambers,” Am. J. Phys. 77, 81–86 (2009).30G. Carleo and M. Troyer, “Solving the quantum many-body problem with

artificial neural networks,” Science 355, 602–606 (2017).

549 Am. J. Phys., Vol. 85, No. 7, July 2017 J. Wang and Y. Hao 549