You are on page 1of 12

The Astrophysical Journal, 583:296–307, 2003 January 20

# 2003. The American Astronomical Society. All rights reserved. Printed in U.S.A.

A FAST ALGORITHM FOR SOLVING THE POISSON EQUATION ON A NESTED GRID


Tomoaki Matsumoto
Department of Humanity and Environment, Hosei University, Fujimi, Chiyoda-ku, Tokyo 102-8160, Japan; matsu@i.hosei.ac.jp
and
Tomoyuki Hanawa
Department of Astrophysics, School of Science, Nagoya University, Chikusa-ku, Nagoya 464-8602, Japan;
hanawa@a.phys.nagoya-u.ac.jp
Received 2002 May 14; accepted 2002 October 2

ABSTRACT
We present a numerical method for solving the Poisson equation on a nested grid. A nested grid consists of
uniform grids having different grid spacing and is designed to cover the space closer to the center with a finer
grid. Thus, our numerical method is suitable for computing the gravity of a centrally condensed object. It
consists of two parts: the difference scheme for the Poisson equation on the nested grid and the multigrid
iteration algorithm. It has three advantages: accuracy, fast convergence, and scalability. First, it computes
the gravitational potential of a close binary accurately up to the quadrupole moment, even when the binary is
resolved only in the fine grids. Second, the residual decreases by a factor of 300 or more with each iteration.
We confirmed experimentally that the iteration always converges to the exact solution of the difference
equation. Third, the computation load of the iteration is proportional to the total number of the cells in the
nested grid. Thus, our method gives a good solution at a minimum expense when the nested grid is large. The
difference scheme is applicable also to adaptive mesh refinement, in which cells of different sizes are used to
cover a domain of computation.
Subject headings: binaries: general — hydrodynamics — ISM: clouds — methods: numerical —
stars: formation

1. INTRODUCTION Some recent numerical simulations of star formation


and cosmology apply either AMR or nested grids to
Astronomical objects such as stars, clouds, and galaxies achieve high spatial resolution. Truelove et al. (1997)
have enormous dynamic range both in density and in size. studied gravitational collapse of a molecular cloud core
To illustrate this enormous dynamic range, we consider star with AMR to resolve fragmentation of the highly con-
formation as an example. Stars form in molecular clouds of densed cloud core. Since then, AMR has frequently been
which the mean density is 103 atoms cm3 . The molecular used in numerical simulations of fragmentation during
clouds contain condensations called ‘‘ molecular cloud gravitational collapse (Truelove et al. 1998; Boss et al.
cores,’’ from which stars form because of self-gravity. The 2000). Using nested grids, Burkert & Bodenheimer (1993,
molecular cloud cores have a typical size of 1017 cm and a 1996) studied fragmentation of a centrally condensed pro-
typical density of 105 atoms cm3 . On the other hand, the tostar. They succeeded in resolving spiral arms formed by
central density of a star is 1011 atoms cm3 at the very begin- the self-gravitational instability in the protoplanetary
ning of its protostellar stage, and the present Sun has a cen- disk. Also using nested grids, Tomisaka (1998) computed
tral density of 1026 atoms cm3 . The radius of a protostar is the gravitational collapse of a rotating magnetized gas
1014 cm when the central density is 1012 atoms cm3 . As the cloud and found magnetohydrodynamically driven out-
central density increases, the radius decreases down to 1010– flow emanating from a very compact central disk. Nor-
1012 cm until the star reaches its main-sequence (hydrogen man & Bryan (1999) have reviewed application of AMR
burning) stage. to cosmological simulations.
This enormous dynamic range restricts us to achieving Though simulations based on AMR and nested grids
high spatial resolution only in small regions of interest. To are successful, some technical problems still remain. One
generate finer grids in the region of interest, various mesh of them is a numerical algorithm for solving the Poisson
generation methods have been developed. Adaptive mesh equation on a grid in which a cell faces several smaller
refinement (AMR) and nested grids are typical of the mesh cells. In other words, difficulty arises at boundaries
generation methods developed in the past decade. AMR between the regions covered with different size cells. For
and nested grids generate finer grids hierarchically in the later convenience, we name these boundaries ‘‘ the grid-
region of interest. AMR was invented by Berger & Oliger level boundaries.’’ In most AMR and nested grids of
(1984) and has been advanced by many researchers. Nested three dimensions, a parent cell faces four child cells at
grids are variants of AMR and generate only one subgrid at each grid-level boundary.
each hierarchical level, while AMR has no restriction on the When cells are uniform on a grid, a simple central dif-
number of subgrids. AMR and nested grids have succeeded ference scheme gives us second-order accuracy, and the
in simulations of star formation and galaxy formation, in difference equation can be solved fast with the multigrid
which compact objects form by condensation of diffuse iteration or some other methods. Since the simple central
clouds. difference breaks down at the grid-level boundary, we
296
POISSON EQUATION SOLVER 297

need some modifications at the boundaries. An ideal define the ranges of i, j, k, and l as
scheme should provide an accurate solution and require
N N
minimum computation load. As shown below, some i  1; ð4Þ
schemes published in recent literature are lacking in 2 2
accuracy. N N
j  1; ð5Þ
One might think that we could obtain a good solution by 2 2
relatively small computation cost if we solved the Poisson N N
equation successively from coarse grids to fine grids. One k  1; ð6Þ
2 2
can solve the Poisson equation on the coarsest grid if an 1l  lmax ð7Þ
appropriate boundary is given at the boundary of the grid.
Then the solution gives boundary conditions for the subgrid in this paper. Thus, our nested grid has lmax  N 3 cells in
if we interpolate it appropriately. Thus, we can solve the total. To use the multigrid iteration effectively, we take
Poisson equation on the subgrid and repeat the same proce- N ¼ 2n in our computation. The coarsest grid covers the
dure down to the finest grid. This algorithm requires a volume of L3 , where L ¼ Nh. The finest grid has grid spac-
rather small computation load, but the solution is not ing of 2lmax 1 h. Since all these grids are concentric, central
accurate enough. regions are covered multiply with these grids. When a vol-
To illustrate the problem of the algorithm mentioned ume is covered with different size cells, we adopt a quantity
above, we consider binary or multiple stars, the separa- in the smallest cell in the final solution. Figure 1 illustrates
tion of which is too short to resolve in a coarse grid. For cell distribution in our nested grid. It denotes the cross sec-
simplicity, we assume that binary or multiple stars domi- tion in two dimensions for simplicity.
nate the gravity. At a large distance from them, the grav- The gravitational potential is evaluated at the cell center
ity is approximately the sum of the point-mass gravity and is labeled as
and the quadrupole moment of gravity. If we compute  ðlÞ ðlÞ ðlÞ 
ðlÞ
the gravity with a coarse grid without any knowledge of i; j; k ¼  xi ; yj ; zk : ð8Þ
the fine structure, we miss the quadrupole moment of
gravity. Although it is smaller than the point-mass grav- Also, the cell-averaged density is labeled as
ity, the quadrupole moment of gravity is the leading term ðlÞ  ðlÞ ðlÞ ðlÞ 
in the gravitational torque. We need to take account of i; j; k ¼  xi ; yj ; zk : ð9Þ
mass distribution in a fine grid to evaluate the gravita-
The Poisson equation,
tional torque.
In this paper we present a difference equation for the Pois- 4G ¼
D
xg ; ð10Þ
son equation on a nested grid. The solution of this difference D
equation is accurate enough in the sense that it reproduces g¼ ; ð11Þ
the quadrupole moment of gravity quantitatively even in a
coarse grid. Moreover, the difference equation can be solved relates the gravitational potential and density, where g
fast with the multigrid iteration. The computation load is denotes the gravity. When a cell is surrounded by cells of the
scalable, i.e., proportional to the total number of cells
involved in the nested grid.
The above difference equation is also applicable to AMR.
The difference equation is likely to be solved fast also with a
multigrid iteration.
In x 2 we describe our difference equation. In x 3 we
denote our algorithm for solving the difference equation.
In x 4 we show the performance of our scheme with
emphasis on the accuracy of the solution and speed of
computation. In x 5 we discuss the reasons for the suc-
cess of our difference equation in reproducing the quad-
rupole moment of gravity. We also discuss the extension
of our method to AMR.

2. DIFFERENCE EQUATION
First, we introduce our nested grid and define the coordi-
nates. The nested grid consists of uniform grids, each of
which has cubic cells. The center of each cell is located at
ðlÞ
xi ¼ 2lþ1 ði þ 12 Þh ; ð1Þ
ðlÞ
yj ¼ 2lþ1 ðj þ 1
2 Þh ; ð2Þ
ðlÞ
zk ¼ 2lþ1 ðk þ 12 Þh ; ð3Þ
where i, j, k, and l are integers and labels. The symbol h Fig. 1.—Cross section of our nested grid. The lines denote the cell
denotes the grid spacing in the coarsest grid at the level of boundaries. The region closer to the center is covered with smaller cells.
l ¼ 1. As l increases by 1, the grid spacing reduces by 12. We This nested grid has the parameters N ¼ 8 and lmax ¼ 5.
298 MATSUMOTO & HANAWA Vol. 583

same size, we obtain the discrete Poisson equation of the coarse cell surface. The result depends little on the inter-
second-order accuracy, polation adopted. The cell number at both ends of the diag-
ðlÞ ðlÞ
onal depends on the even-odd parity of j and k. Equation
ðlÞ
gx;iþ1=2;j;k  gx;i1=2;j;k (19) should be modified appropriately when either j or k are
4Gi;j;k ¼ even.
2lþ1 h
ðlÞ ðlÞ Equations (13)–(15) are central difference equations, and
gy;i;jþ1=2;k  gy;i;j1=2;k our difference equations are of second-order accuracy,
þ
2lþ1 h except across the grid-level boundaries. Since equations (18)
ðlÞ ðlÞ
gz;i;j;kþ1=2  gz;i;j;k1=2 and (19) are of first-order accuracy, our difference equations
þ ; ð12Þ are only first-order accurate across the boundaries.
2lþ1 h We need the gravity at the cell center in the hydrodynamic
ðlÞ
iþ1;j;k  i;j;k
ðlÞ computation. The gravity at the cell center is evaluated to be
ðlÞ the average of those at the opposing cell surfaces; e.g.,
gx;iþ1=2;j;k ¼ ; ð13Þ
2lþ1 h  ðlÞ 
ðlÞ ðlÞ
ðlÞ ðlÞ
i;jþ1;k  i;j;k gx;i;j;k ¼ 12 gx;iþ1=2;j;k þ gx;i1=2;j;k : ð20Þ
ðlÞ
gy;i;jþ1=2;k ¼ ; ð14Þ
2lþ1 h We examine the accuracy of the gravity at the cell center
ðlÞ ðlÞ
ðlÞ i;j;kþ1  i;j;k in x 4.
gz;i;j;kþ1=2 ¼ ; ð15Þ
2lþ1 h
by the central difference as in the case of the uniform grid. 3. ITERATIVE METHOD FOR SOLVING THE
Note that the gravity is evaluated on the cell surface. DIFFERENCE EQUATION
Equations (13)–(15) need to be modified near the grid Our difference equation can be solved with a simple point
boundary. We set the condition that the gravity evaluated in Jacobi iteration or red-black Gauss-Seidel iteration, but
the coarse grid is equal to the average gravity on the smaller with too many iterations of the order of N 2 . Thus, we adopt
cell surfaces; e.g., the multigrid iteration to accelerate the convergence. We
ðlÞ  ðlþ1Þ ðlþ1Þ employ the full multigrid (FMG) scheme, i.e., the algorithm
gx;iþ1=2;j;k ¼ 14 gx;2iþ3=2;2j;2k þ gx;2iþ3=2;2j;2kþ1
shown in Press & Teukolsky (1991), in our paper. Our
ðlþ1Þ ðlþ1Þ  numerical procedures are rather complicated, partly
þ gx;2iþ3=2;2jþ1;2k þ gx;2iþ3=2;2jþ1;2kþ1 : ð16Þ
because the FMG scheme is complicated and partly because
This ensures that our solution satisfies Gauss’s theorem. our nested grid is complex. Thus, we first outline our scheme
When we sum up the normal component of the gravity over in the following. Detailed numerical procedures are shown
the surface of a given volume, it equals the mass contained later.
in the volume multiplied by 4G: The essence of the multigrid iteration is to obtain a better
X X initial guess for finer grids from approximate solutions on
g x dS ¼ 4G  dV : ð17Þ coarser grids (see, e.g., Wesseling 1992; Briggs, Henson, &
surface volume McCormick 2000, for the basics of multigrid iteration).
When grids are coarse, the computation cost is less. When
In other words, the ‘‘ gravitational field line ’’ never ends
interpolated for a fine grid, the solution on a coarse grid is a
at the grid-level boundary. This is also equivalent to setting
good initial guess, and a better solution on the fine grid is
the Neumann condition at the grid-level boundary.
obtained by only a few iterations.
When the cell surface is on the grid-level boundary, we
As a coarse grid, we use another nested grid that covers
interpolate  in the coarse grid to evaluate the gravity across
the same computation volume with fewer N and larger h.
the cell surface. As an example, we show the interpolation
More specifically, we use the nested grids of
formula for computing the gravity in the x-direction in the
ðN; hÞ ¼ ð2n1 ; 2h0 Þ, ð2n2 ; 22 h0 Þ, . . ., and ð22 ; 2n2 h0 Þ as
following. When i ¼ N=2  1, we evaluate
temporarily working nested grids for computation on the
ðlÞ ðlÞ nested grid of ðN; hÞ ¼ ð2n ; h0 Þ (see Briggs et al. 2000, pp.
ðlÞ
iþ3=2;j;k  i;j;k
gx;iþ1=2;j;k ¼ ; ð18Þ 163–175, for the reasoning on our choice of coarsening).
ð3=2Þ2lþ1 h Furthermore, we introduce two uniform grids, one of which
ðlÞ has 23 cells and the other of which has only one cell. Both of
where iþ3=2;j;k denotes the gravitational potential at
the uniform grids cover the whole computation domain,
ðlÞ ðl1Þ
ðx; y; zÞ ¼ ðxiþ3=2  xðiþ1Þ=2 ; yj ; zk Þ :
ðlÞ ðlÞ which is covered only with the largest grid in the nested grid.
Introduction of these temporarily working grids increases
This is obtained by the interpolation on the diagonal in the the total number of cells in our computation by only a factor
coarse cell surface. When j and k are odd numbers, this is of 8/7. Accordingly, the computation on these working
evaluated to be nested grids is only a minor fraction.
We start from an exact solution on the uniform grid hav-
ðlÞ ðl1Þ ing only one cell. The solution is used as an initial value to
iþ3=2;j;k ¼ 34 ðiþ1Þ=2;ðj1Þ=2;ðk1Þ=2
obtain the solution on the other uniform grid. The obtained
ðl1Þ
þ 14 ðiþ1Þ=2;ðjþ1Þ=2;ðkþ1Þ=2 : ð19Þ solution is used to obtain the solution on the nested grid of
ðN; hÞ ¼ ð22 ; 2n2 h0 Þ. This solution is obtained by succes-
Equation (19) uses the gravitational potential at both ends sive overrelaxation (SOR; see, e.g., Press et al. 1986 for the
of the diagonal for the linear interpolation. This interpola- basics of SOR). The computation cost is very small since
tion is not unique; we can use the bilinear interpolation in this nested grid contains only 64lmax cells. We obtained a
No. 1, 2003 POISSON EQUATION SOLVER 299

N = 32 G
16 G G G
8 G G G G G G G
4 G S S G S G S G S G S
2 G G G G G G G G G G G G G G G
1 E E E E E E E E E

Fig. 2.—Schematic diagram of the FMG scheme. The symbols G, S, and E denote the red-black Gauss-Seidel iteration, SOR, and solving an exact solution,
respectively. The arrows pointing right upward and right downward denote interpolation and restriction, respectively. In the shaded levels, the operations are
done only in l ¼ lmax .

solution on the coarsest grid after 4lmax iterations in a typi- 4. Compute the residual in the red (i þ j þ k ¼ odd) cells
cal model. The iterations should reduce the residual by a and update the data there.
factor of 103 , since 4pN1 =3 iterations reduce the residual 5. Repeat procedures 1–3.
by a factor of 10p in SOR (Press et al. 1986) when the grid 6. Compute the residual in the black (i þ j þ k ¼ even)
has N1 cells in one dimension. By interpolating the solution, cells and update the data there.
we obtain the initial data for iteration on the grid of
The above procedures are counted as a cycle of the red-
ðN; hÞ ¼ ð23 ; 2n3 h0 Þ. After a few (typically two) red-black
black Gauss-Seidel iteration.
Gauss-Seidel iterations, we obtain an approximate solution
The boundary condition was set only on the boundaries
on the fine grid.
of the largest grid. We can use either the Dirichlet boundary
We obtain an approximate solution on a finer nested grid
(setting  on the boundary) or the Neumann boundary (set-
successively by a combination of interpolation, the red-
ting g). In the following, we use the Neumann boundary.
black Gauss-Seidel iteration, and restriction (averaging).
The gravity on the boundary was computed by multipole
We use the bilinear formula to interpolate the solution on a
expansion.
coarse grid to that on a fine grid. On the other hand, we use
the full weighting (the simple volume average) to restrict the
solution on a fine grid to that on a coarse grid. We perform
4. SAMPLE COMPUTATION
these operations on the order of the FMG. The schedule of
the operations is schematically shown in Figure 2. The We evaluate the efficiency of the above described algo-
arrows pointing right upward denote interpolation, while rithm with emphasis on the accuracy, convergence, and
those pointing right downward denote restriction. The sym- computation time (load). In our numerical computation, we
bol G denotes the red-black Gauss-Seidel iteration, while take the unit G ¼ 1 for convenience. All of the numerical
the symbol S denotes SOR. At the points of the symbol E, computations were done with double precision.
an exact solution is given. The red-black Gauss-Seidel
iteration is performed twice, after both interpolation and 4.1. Accuracy
restriction in a typical model. In other words, the number of First, we present an example in which two uniform-
pre- and postiterations is two in our computation. density spheres are placed near the center of the nested grid.
Each restriction is performed by simply taking the aver- The central positions, radii, and masses of the spheres are
age in the cells involved in a coarse cell. Restriction is done listed in Table 1. We obtained the gravitational potential for
from fine (l ¼ lmax ) to coarse (l ¼ 1). this mass distribution with the method mentioned in the
Each interpolation is performed using the following previous sections. We used a nested grid of N ¼ 64, L ¼ 1,
procedures: and lmax ¼ 5. This example provides us with the accuracy of
1. Fill the data in the region covered with a finer grid by our scheme.
the average value in the finer grid. This averaging is per- We started the computation from the initial guess,  ¼ 0.
formed successively from l ¼ lmax  1 to l ¼ 1. The residual decreased by more than a factor of several hun-
2. Perform linear interpolation of three-dimensional data dred with each FMG iteration. After five iterations, the
successively from l ¼ 1 to l ¼ lmax . The data on the boun- residual was of the order of the round-off error (1015
dary are given from the coarser grid. in the potential), as is shown in x 4.2. The obtained
Each red-black iteration is performed using the following
procedures:
TABLE 1
1. Obtain the gravitational potential just outside the Mass Distribution in Model Shown in Figure 3
grid-level boundary using equation (19).
2. Evaluate the gravity g on the cell boundary using n xc;n yc;n zc;n rc;n Mn
equations (13), (14), (15), and (18).
1.............. 12/1024 0 0 6/1024 1
3. Replace the gravity at the grid-level boundary with the
2.............. 12/1024 0 0 6/1024 2
fine grid using equation (16).
300 MATSUMOTO & HANAWA Vol. 583

0.03
0.10
0
2 .0
0.02
50
1.

2.
00
0.05
0.01

2.00
2.50

0.00 0.00

1.50
y
y

-0.01
-0.05

-0.02 1.5
0 0
2.0
-0.10
-0.03
-0.03 -0.02 -0.01 0.00 0.01 0.02 0.03 -0.10 -0.05 0.00 0.05 0.10
x x

Fig. 3a Fig. 3b

0.4

1.00

0.2
1.50

0.0
y

-0.2
1.0
0

-0.4

-0.4 -0.2 0.0 0.2 0.4


x

Fig. 3c
Fig. 3.—Example of our numerical solution for the gravitational potential of binary stars. Each component star of the binary is assumed to be a sphere of
uniform density. The centers, radii, and densities are summarized in Table 1. The contours denote the computed gravitational potential. This is measured
(a) in the plane of z ¼ 1=2048 at the level of l ¼ 5, (b) in the plane of z ¼ 1=512 at the level of l ¼ 3, and (c) in the plane of z ¼ 1=128 at the level of l ¼ 1.
The contours are set in equal intervals in the logarithmic scale, D log jj ¼ 0:1. The labels denote the values of log jj.

gravitational potential is shown in Figures 3a–3c. Each ure 3. We do not show the difference in the region covered
panel denotes the contours of the gravitational potential with a finer grid, since the numerical solution has no practi-
measured in the midplane. As shown in Figure 3a, the gravi- cal use there. Our numerically obtained  has an arbitrary
tational potential  has two local minima, the centers of offset, since we used the Neumann boundary. The offset was
which are close to those of the two spheres. This is well chosen to minimize the difference between the numerical
approximated by the 1=r potential in the region far from and analytic solutions at z ¼ 1023=2048. On a grid of l ¼ 5,
these spheres. These features ensure that the obtained solu- the difference is large (jDj ¼ 0:6) in the cells located near
tion is qualitatively correct. the surfaces of the spheres, as shown in Figure 4a. This error
We compare the above solution with the exact analytic is inevitable since it is due to the finiteness of our grids.
solution to examine the accuracy of our difference scheme. It is, however, much smaller than the absolute value of
Figures 4a–4c denote the difference between the numerical the gravitational potential, of which the maximum is
and analytic exact solutions for the example shown in Fig- max jj ¼ 552:0. The difference from the exact solution is
No. 1, 2003 POISSON EQUATION SOLVER 301

0.03 φ-φex φ-φex

0.00
0.6
0.10
0.00
0.02
0.4
0.05 -0.01

0
0.01 0

0.0
0.000
0.0
0.2

0.00 0.00 -0.02

y
y

0.0

0.000
0
-0.01 0.0 -0.03

00
-0.05

0.0
-0.2
0 .0
0

-0.02

0.00
-0.04

0
-0.10
0.00 -0.4
-0.03 -0.05
-0.03 -0.02 -0.01 0.00 0.01 0.02 0.03 -0.10 -0.05 0.00 0.05 0.10
x x

Fig. 4a Fig. 4b

φ-φex
0.010
00

0.4
-0.01

0.005

0.0100
-0.0100
0.2

0.000

0.0
y

0.0000
-0.0100

-0.005

-0.2
-0.0100
-0.010
-0.0100

100
0.000

-0.4
0.0

-0.015

-0.4 -0.2 0.0 0.2 0.4


x

Fig. 4c
Fig. 4.—Errors of gravitational potential due to the difference scheme for the example shown in Fig. 3. The gray scale and contours denote the difference
from the analytic solution (D ¼   ex ). (a) Difference for z ¼ 1=2048 in the grid level of l ¼ 5. (b) Difference for z ¼ 1=1024 and 1/512 in the grid levels of
l ¼ 4 and 3, respectively. (c) Differences for z ¼ 1=256 and 1/128 in the grid levels of l ¼ 2 and 1, respectively.

typically as large as jDj ¼ 0:1 in the region covered with a tribution on the coarse grid of l ¼ 1. Thus, even the dipole
grid of l ¼ 5. moment is seriously underestimated in this example. This
The difference from the analytic solution is less than underestimation is dominant in the error on the coarse grid
jDj < 0:016 in the region covered with a grid of l ¼ 3, as l ¼ 1. The quadrupole and octopole moments are
shown in Figure 4b. The difference is relatively large near practically not taken into account on the boundary in the
the grid-level boundary between l ¼ 3 and 4. This is most example. If we apply a better outer boundary condition, the
likely due to the evaluation of the gravity at the grid-level error will be reduced.
boundary. Our numerical scheme is second-order accurate Next, we examine the accuracy of the gravity at the cell
except at the grid-level boundaries, since we employ the cen- center, gi;j;k , defined by equation (20). Figure 5 is the same
ter difference. The gravity at the grid-level boundary is only as Figure 4, but for the relative error jg  gex j=jgex j, where
first-order accurate (see eqs. [18] and [19]). gex denotes the exact gravity obtained analytically. The rela-
On a grid of l ¼ 1, the error is global; it is negative on the tive error is large (0.1) in the cells located on the surfaces
left (x < 0) and positive on the right (x > 0). This error of the spheres. It is much less than 102 in most cells. This
comes from the boundary condition. We applied the Neu- small error ensures that our scheme reproduces not only the
mann condition for the outer boundary. The gravity at the 1=r potential but also the quadrupole moment of the binary.
boundary is evaluated with the multipole expansion, in The error is moderately large (0.02) in the cells adjacent to
which we take account of the dipole, quadrupole, and octo- the grid-level boundary. It is fairly small except in the cells
pole moments, as well as the total mass. These higher order located on the surfaces of the spheres. The large errors on
moments and total mass are evaluated from the density dis- the surfaces of the spheres are due to the fact that even the
302 MATSUMOTO & HANAWA

0.03

-4.0

-3.00
-3.0 -1.0
-4.
0.10

-3.0
0 -2.5
0.02 -1.5
-3.0
0.05

-3.0
0.01 -2.0 -3.0
-3.00

-3.00

0
log |g-gex|/|gex|

log |g-gex|/|gex|
-2.0

-2.5

-2.0
0.00 -3. 0.00
y

y
0

-3.
-3.5

-2.

0
-2.0

-3.0
0
-3.0 -3.0
-3.00
-0.01
-0.05
-3.5 -4.0

-0.02
-3.0

-3.

-4.0

-3.00
-0.10
0

-4
-4.5
-3.0
-4.0

.0
-0.03 -4.5
-0.03 -0.02 -0.01 0.00 0.01 0.02 0.03 -0.10 -0.05 0.00 0.05 0.10
x x

Fig. 5a Fig. 5b

0.4

-3.0
0.2 .0
-3.0

-3

log |g-gex|/|gex|
0.0
y

-3. -3.5
-3 0 -3.0
.0

-0.2 -3
.0

-4.0

-0.4

-0.4 -0.2 0.0 0.2 0.4


x

Fig. 5c
Fig. 5.—Same as Fig. 4, but for relative errors of gravitational force (jg  gex j=jgex j) in logarithmic scale

finest grid is too coarse to resolve the surface sharply and as large as the simple average. The maximum value is only 3
are not serious in practical use. In most hydrodynamic sim- times larger than the simple average at the levels of l ¼ 1, 2,
ulations, a self-gravitating gas has a more or less smooth 3, and 4. It is a factor of 10 larger than the simple average at
density distribution in the finest grid. l ¼ 5. These results confirm that our scheme gives the
To evaluate the relative error in the gravity quantita- second-order accurate gravity in the cells neither adjacent to
tively, we measured the simple average, the rms average, the grid-level boundary nor lying on the sharp edge of the
and the maximum value. Figure 6 shows these as a function density distribution.
of N. The average and maximum are computed separately In the cells adjacent to the grid-level boundary, the rela-
for cells adjacent to the grid-level boundary and for the rest tive error decreases in proportion to N 1 except at l ¼ 1.
of the cells. Each curve denotes the value at the grid of each This is because our scheme is only first-order accurate at the
level. Figures 6b, 6d, and 6f are for the cells adjacent to the grid-level boundary. This does not mean that the error is
grid-level boundary, while Figures 6a, 6c, and 6e are for the always large only at the grid-level boundary. Note that the
rest of the cells. Figures 6a–6b show the simple average. average relative error is more or less the same between
Figures 6c–6d show the rms average. Figures 6e–6f show the cells adjacent to the grid-level boundary and the rest of
the maximum. The shallower dashed lines denote the cells when N  32. Only when N is sufficiently large is
jg  gex j=jgex j ¼ 100:5 N 1 for comparison between panels. the error appreciably large at the grid-level boundary.
The steeper dashed lines denote jg  gex j=jgex j ¼ 10N 2 . At l ¼ 1, the relative error decreases rapidly with increase
In the cells not adjacent to the grid-level boundary, the in N. When N  128, the binary is resolved even in the grid
simple average and rms average of the relative error in the of l ¼ 1. Then the dipole and quadrupole moments of the
gravity are proportional to N 2 . The rms average is nearly gravity are evaluated with a good accuracy, and the outer
0 0

-1 -1

log <|∆g|/|gex|>
log <|∆g|/|gex|>

-2 -2

-3 -3
5
2,3,4

-4 5 -4

l=1,2,3,4 l=1

-5 -5
0.5 1.0 1.5 2.0 2.5 3.0 0.5 1.0 1.5 2.0 2.5 3.0
log N log N

Fig. 6a Fig. 6b

0 0

-1 -1
log <(|∆g|/|gex|)2>

log <(|∆g|/|gex|)2>

-2 -2

-3 -3 5
2,3,4
5

-4 -4
l=1,2,3,4 l=1

-5 -5
0.5 1.0 1.5 2.0 2.5 3.0 0.5 1.0 1.5 2.0 2.5 3.0
log N log N

Fig. 6c Fig. 6d

0 0

-1 -1
5
log (|∆g|/|gex|)max

log (|∆g|/|gex|)max

-2 -2

2,3,4,5

-3 -3
4
3
l=1,2 l=1
-4 -4

-5 -5
0.5 1.0 1.5 2.0 2.5 3.0 0.5 1.0 1.5 2.0 2.5 3.0
log N log N

Fig. 6e Fig. 6f
Fig. 6.—Errors of gravitational force as a function of N. The errors are evaluated as (a–b) simple averages, (c–d ) rms, and (e–f ) maximum values of relative
errors of gravitational force (jg  gex j=jgex j). Panels b, d, and f denote the errors for cells on grid-level boundaries, while panels a, c, and e denote the errors for
the other cells. Each solid curve denotes the error for each grid level (l ¼ 1  lmax ) as labeled in the panels. The dashed lines denote 100:5 N 1 and 10N 2 for
comparison.
304 MATSUMOTO & HANAWA Vol. 583

Fig. 7a Fig. 7b
Fig. 7.—Gravitational potential computed for the density distribution in which four uniform-density gas spheres are placed near the center of the
computation grid. Two of them have positive mass, and the other two have negative mass, so that the gravitational field is well approximated by the
quadrupole in the region far from the center. The location and size of the four gas spheres are listed in Table 2. The contours are set in equal intervals in the
logarithmic scale at the level of  ¼ 10n and 0, where n denotes an arbitrary integer.

boundary condition is improved greatly. Accordingly, the residual remains constant after five FMG iterations. The
relative error is small at l ¼ 1 when N  128. Remember remaining residual is due to the round-off error in the gravi-
that the error due to the outer boundary condition domi- tational potential. The residual is proportional to the
nates at l ¼ 1. inverse square of the cell size in Figure 8 since the second
We made another example to confirm that our scheme derivative is plotted. The round-off error is extremely small
can reproduce not only the 1=r gravity but also the quadru- and is negligible compared with the discretization error dis-
pole moment of the gravity accurately. Figure 7 shows the cussed in x 4.1.
second example, in which four uniform-density spheres are Trying several model density distributions, we have con-
placed near the center of the grid. The centers, radii, and firmed that the reduction depends little on the spatial distri-
masses of the spheres are listed in Table 2. Note that the bution of the residual. When we increase the number of
total mass is 0. When measured in the coarse grid of l  2, Gauss-Seidel iterations during a cycle of the multigrid itera-
the cell average density vanishes in all the cells since N ¼ 64 tion, we get a higher reduction in the residual per cycle at
in this example. In other words, there are no source terms in
the discrete Poisson equation at the level of l ¼ 1. Neverthe-
less, the quadrupole moment of gravity is reproduced in 5 5
Figure 7. This proves that equation (16) connects the gravi-
4
tational potential between the coarse and fine grids. 3
2
4.2. Convergence 0 l=1

We measured reduction in the residual, the difference in


log (ρ-∇2φ)max

the right- and left-hand sides of equation (12), to evaluate


the efficiency of the iteration. Figure 8 shows the residual as -5
a function of the number of FMG iteration cycles for the
sample problem for the binary shown in x 4.1. The absolute
value of the residual reduces by a factor of 300 per cycle of
multigrid iteration in the first four FMG iterations. The -10

TABLE 2
Mass Distribution in Model Shown in Figure 7
-15
0 2 4 6 8
n xc;n yc;n zc;n rc;n Mn NFMG
1.............. 2/1024 2/1024 0 2/1024 1
2.............. 2/1024 6/1024 0 2/1024 1 Fig. 8.—Residual of the Poisson equation (  r2 ) as a function of
3.............. 6/1024 2/1024 0 2/1024 1 the number of the FMG iteration cycle (NFMG ). Each curve denotes the
4.............. 6/1024 6/1024 0 2/1024 1 maximum residual measured in the grid of each level. The dashed lines
denote the relationships of   r2  / 102NFMG and 103NFMG , respectively.
No. 1, 2003 POISSON EQUATION SOLVER 305

the expense of longer computation time. The reduction per dynamic equation on the same nested grid. This CPU time
unit computation load is higher when the Gauss-Seidel iter- is not scalable to the number of cells since the super-
ation is performed several times each. computer has vector processors and its CPU time is not
We tried the SOR instead of the Gauss-Seidel iteration to proportional to the computation load.
accelerate the convergence, but failed. When SOR is used as
the pre- and postrelaxation in our multigrid iteration, the
residual increases sometimes, depending on the initial guess. 5. DISCUSSION
SOR works well only when we use one level of the grid, i.e., As shown in the previous section, our numerical method
when the grid is not nested. provides an accurate solution with a reasonably small com-
We also tried to improve the interpolation formula, equa- putation cost. The computation load is scalable in the sense
tion (18), for a higher order accuracy. We found that our that it is proportional to the number of the cells contained
iteration did not converge when we used a higher order in the nested grid. Our discrete Poisson equation is robust in
interpolation formula. Though we cannot deny existence of the sense that it can be applied also to AMR as far as a
a successful interpolation formula, we could not find it. parent cell is subdivided into two in one dimension. We dis-
cuss the strength of our scheme while comparing with other
schemes given in the literature.
4.3. Computation Time Suisalu & Saar (1995) took another approach when solv-
We evaluated the computation load of our multigrid ing the Poisson equation in their AMR computation. They
algorithm by measuring the computation time. A UNIX adopted a cubic interpolation formula at the grid-level
workstation, SGI O2 (MIPS R10000 250 MHz), was used boundary to ensure the continuity of the solution. They
for the measurement. The computation time was measured noticed that a linear interpolation ensures only the continu-
with the subroutine DTIME. ity in the potential and not that in the gravitational force.
Figure 9 shows the execution time per FMG cycle. The Discontinuity in the force may cause a spurious feature
abscissa denotes the effective total number Ncell ¼ lmax N 3 in across the grid-level boundary. Although not mentioned
the logarithmic scale. The ordinate denotes the logarithm of explicitly in Suisalu & Saar (1995), the discontinuity causes
the computation time t. The dashed line denotes the relation a more serious problem: it introduces spurious mass on the
CPU time / Ncell . We made this plot by changing lmax and grid-level boundary. If the gravity g has different values at
N in the range of 2  l  10 and 8  N  128. the grid-level boundary, the solution does not satisfy
As shown in Figure 9, the computation load is propor- Gauss’s theorem. The spurious mass on the grid boundary
tional to Ncell when N  32. This means that our algorithm gives a serious error on the solution in a long range. The
is scalable for medium and large nested grids. error decreases only inversely proportional to the distance
We also measured the computation time with the Fujitsu from the spurious mass. This error dominates over the grav-
VPP5000 supercomputer at the National Astronomical itational torque, which decreases more steeply.
Observatory, Japan. When N ¼ 256 and lmax ¼ 5, the CPU Compared with adoption of a higher order interpolation
time is 0.21 s per FMG cycle. This CPU time is reasonably formula at the grid-level boundary, our scheme has several
small compared with the CPU time for solving the hydro- advantages. First, our approach ensures the absence of a
spurious mass on the grid-level boundary, which is not guar-
anteed in a higher order interpolation formula. Second, a
1 higher order interpolation formula increases computation
load. Third, higher order interpolation may slow down effi-
(128, 2)
ciency of convergence. In our experience, a simple multigrid
0 iteration does not work when equations (18) and (19) are
replaced with a higher order interpolation formula. We dis-
log Computation time [sec]

(N, lmax) = (64, 2)


cuss the third point further in the following.
-1 Our discrete Poisson equation has the following favorable
characteristic. When it is rewritten in the form
(32, 2)
X
i ¼ ai;j j ; ð21Þ
-2
j

(16, 2) the coefficient ai;j is always positive except for i ¼ j. Here


-3 symbols i and j denote the cell number after sorting in one
(8, 2) dimension. This property ensures that the Gauss-Seidel iter-
ation converges always since it always underestimates the
-4 correction. In other words, the convergence of the Gauss-
3 4 5 6 7 Seidel iteration is ensured since the matrix ai;j is diagonally
log Number of cells (Ncell) dominant:
X
Fig. 9.—Computation time as a function of the number of the cells in the jai;j j  jai;i j : ð22Þ
nested grid. The squares denote the computation time measured with the i6¼j
UNIX workstation, SGI O2 (MIPS R10000 250 MHz). The ordinate
denotes the computation time t in units of seconds in the logarithmic scale. When we use a higher order interpolation formula, this
The abscissa denotes the total number of the cells used in the nested grid,
i.e., Ncell ¼ lmax N 3 , in the logarithmic scale. The parameters of the grid
dominance of the diagonal element (eq. [22]) is lost. The
(N, lmax ) are labeled by the filled squares. The relation of t ¼ 106 Ncell is coefficient ai;j is no longer always positive. Then the Gauss-
shown by the dashed lines for comparison. Seidel iteration may overestimate the correction and may
306 MATSUMOTO & HANAWA Vol. 583

not converge. If we apply successive underrelaxation, the We adopted the principle that the difference equations
convergence slows down. should be consistent with the global properties, i.e., Gauss’s
Ricker, Dodelson, & Lamb (2000) have proposed another theorem and Stoke’s theorem. We were satisfied with the
idea for solving the Poisson equation in a nonuniform grid. first-order accuracy at the grid-level boundaries. In other
They have used a nonuniform grid in which the spacing in a words, we gave priority to the global properties over higher
certain direction varies, but only in that direction. For order accuracy at a given point. As a result, we succeeded in
example, the spacing in the x-direction varies with x but not computing the gravity of a close binary and in reproducing
in the y- and z-directions. Consequently, each cell is rectan- the quadrupole moment. This success is analogous to that
gular and may have different side lengths. Each cell has a of a total variation diminishing (TVD) scheme for wave
neighboring cell in each direction and faces six neighboring equations and that of a symplectic integrator for a
cells in total except for a cell located on the grid. They eval- Hamiltonian system (Yoshida 1990). The TVD scheme
uated the gravity on the cell surface using a second-order gives priority to monotonicity of the solution over local
interpolation. Their Poisson equation can be rewritten as accuracy (see, e.g., Hirsch 1990, p. 528). The solution is free
gx;iþ1=2;j;k  gx;i1=2;j;k gy;i;jþ1=2;k  gy;i;j1=2;k from numerical oscillations. A symplectic integrator gives a
þ solution that satisfies the conservation of the volume in
Dxi Dyj phase space. As a result, there is no secular change in the
gz;i;j;kþ1=2  gz;i1=2;j;k1=2 total energy, even though it is not conserved at each time
þ ¼ 4Gi;j;k ; ð23Þ
Dzk step because of the limited accuracy. These examples con-
firm that the global properties are more important than the
where
higher order accuracy.
gx;iþ1=2;j;k ¼ F2;i iþ2;j;k þ F1;i iþ1;j;k þ F0;i i;j;k ; ð24Þ An alternative method was proposed by Truelove et al.
(1998). Their numerical scheme is based on that of Almgren
2ðDxi  Dxiþ1 Þ et al. (1998), who solved the dynamics of an incompressible
F2;i ¼ ; ð25Þ
ðDxi þ Dxiþ1 þ Dxiþ2 ÞðDxiþ1 þ Dxiþ2 Þ fluid with AMR. They evaluated the gravitational potential
h i  not on the cell centers but on the vertexes. While they
F1;i ¼  2 Dx2i  3Dxiþ1 ðDxiþ1 þ Dxiþ2 Þ  Dx2iþ2 applied the cell-centered difference to the hydrodynamic
h equations, they applied the vertex-centered difference to the
 ðDxi þ Dxiþ1 þ Dxiþ2 Þ Poisson equation. This method has the advantage that the
i1 different level cells share the same gravitational potential
 ðDxiþ1 þ Dxiþ2 ÞðDxi þ Dxiþ1 Þ ; ð26Þ automatically. In other words, this method ensures the con-
tinuity of the gravitational potential between the grids of
2ð2Dxiþ1 þ Dxiþ2 Þ different levels. This method, however, does not satisfy
F0;i ¼ : ð27Þ Gauss’s theorem and accordingly does not ensure the con-
ðDxi þ Dxiþ1 þ Dxiþ2 ÞðDxi þ Dxiþ1 Þ
tinuity of the gravity g.
The symbols Dxi , Dyj , and Dzj denote the side length of each The method of Truelove et al. (1998) has another disad-
cell. We omitted the interpolation formula for gy and gz to vantage in that it underestimates gravity. This disadvantage
save space. Integrating equation (23) over the whole vol- is due to the averaging used to evaluate the vertex-centered
ume, we obtain density. They evaluated the density at the vertex since the
X X Poisson equation is evaluated on the vertex center. Averag-
i;j;k Dxi Dyj Dzk ¼ Hi;j;k i;j;k ; ð28Þ ing lowers the peak density and broadens the density distri-
i;j;k i;j;k bution. Thus, the gravitational potential evaluated at the
vertex is shallower than that evaluated at the cell center.
where Hi;j;k does not vanish in a nonuniform grid. This
This difference is seriously large when the gas is concen-
means that i;j;k does not necessarily vanish even when
trated in a few cells.
i;j;k ¼ 0. In other words, equation (23) has multiple solu-
We have applied our Poisson equation solver to numeri-
tions for a given density distribution and boundary condi-
cal simulations of binary star formation. The results will be
tions. This is a serious problem.
published in the near future.
As shown above, the approach based on a higher order
interpolation formula has some fundamental problems.
Although our scheme is only first-order accurate at the grid We thank the anonymous referee for his/her comments
boundaries, it gives a quantitatively good solution. This is on an earlier version of this manuscript. These comments
likely due to the fact that our difference scheme satisfies greatly helped us to improve this manuscript. We thank the
global conditions for the proper Poisson equation to satisfy. Astronomical Data Analysis Center of the National Astro-
First, our scheme satisfies Gauss’s theorem, as mentioned nomical Society of Japan for allowing us to use the Fujitsu
repeatedly. Second, our scheme ensures Stokes’ theorem, VPP5000. This study is financially supported in part by
I Grants-in-Aid for the Encouragement of Young Scientists
g x ds ¼ 0 : ð29Þ (12740123 and 14740134) and for Scientific Research (C)
(13640237) of the Japan Society for the Promotion of
Equation (18) is equivalent to Science. It is also supported in part by a Grant-in-Aid for
Z 2
Scientific Research on Priority Areas (A) (13011204) of the
ðr1 Þ ¼ ðr2 Þ þ g x dr : ð30Þ Ministry of Education, Culture, Sports, Science, and
1 Technology.
No. 1, 2003 POISSON EQUATION SOLVER 307

REFERENCES
Almgren, A. S., Bell, J. B., Colella, P., Howell, L. H., & Welcome, M. L. Press, W. H., Flannery, B. P., Teukolsky, S. A., & Vetterling, W. T. 1986,
1998, J. Comput. Phys., 142, 1 Numerical Recipes (Cambridge: Cambridge Univ. Press)
Berger, M. J., & Oliger, J. 1984, J. Comput. Phys., 53, 484 Press, W. H., & Teukolsky, S. A. 1991, Comput. Phys. Commun., 5, 514
Boss, A. P., Fisher, R. T., Klein, R. I., & McKee, C. F. 2000, ApJ, 528, 325 Ricker, P. M., Dodelson, S., & Lamb, D. Q. 2000, ApJ, 536, 122
Briggs, W. L., Henson, V. E., & McCormick, S. F. 2000, A Multigrid Suisalu, I., & Saar, E. 1995, MNRAS, 274, 287
Tutorial (2d ed.; Philadelphia: SIAM) Tomisaka, K. 1998, ApJ, 502, L163
Burkert, A., & Bodenheimer, P. 1993, MNRAS, 264, 798 Truelove, J. K., Klein, R. I., McKee, C. F., Holliman, J. H., II, Howell,
———. 1996, MNRAS, 280, 1190 L. H., & Greenough, J. A. 1997, ApJ, 489, L179
Hirsh, C. 1990, Numerical Computation of Internal and External Flows, Truelove, J. K., Klein, R. I., McKee, C. F., Holliman, J. H., II, Howell,
Vol. 2 (Chichester: Wiley) L. H., Greenough, J. A., & Woods, D. T. 1998, ApJ, 495, 821
Norman, M. L., & Bryan, G. L. 1999, in Numerical Astrophysics, ed. S. M. Wesseling, P. 1992, An Introduction to Multigrid Methods (Chichester:
Miyama, K. Tomisaka, & T. Hanawa (Astrophys. & Space Sci. Library Wiley)
240; Dordrecht: Kluwer), 19 Yoshida, H. 1990, Phys. Lett. A, 150, 262

You might also like