Chemistry Reference
In-Depth Information
the convergence rate relative to SOR on a single level. The code is available
upon request. 156
SOME ADVICE ON WRITING MULTIGRID SOLVERS
It may be helpful to share a few lessons we have learned in writing grid-
based codes. The first advice is to start with very simple problems; a good
place to start in fact is with the Poisson equation in one dimension, with a
finite domain (see Fig. 5). The potential can be fixed at 0 on the edges of
the domain, and if a single-point charge is placed somewhere in the domain,
the solution
is in the shape of a V (oriented normally or upside down
depending on the charge). The first step is to write a relaxation code and
test it on a modest-sized domain: say 65 grid points including the boundary
points. The relaxations will converge to the exact numerical answer rather
quickly. (Hundreds or even thousands of iterations may be required but,
with such a small number of grid points, the calculation is, nonetheless, fast.)
There are two measures of error in a numerical grid solution. 108 One is
the error between the current approximation on the grid and the exact grid
result. That difference is a measure of the progress to the numerical solution.
The other error measure is the difference between the exact numerical solution
and the analytical solution (where that exists). There is no reason to converge
the numerical solution beyond the point where the first error is smaller than
the second. It is useful at the initial stages, however, to make sure the grid
equations are correct and the code is error free by continuing iterations until
machine precision zero is obtained for the residual.
It is then best to write a two-level MG-FAS code. This involves writing
new routines for calculation of the defect correction and the interpolation and
restriction operations. For the Poisson problem, if Gauss-Seidel iteration is
employed on each level, and only a few relaxations are performed, the residual
should decrease by roughly one order of magnitude per full V-cycle. With only
two levels, the residual reduction will likely be smaller than this theoretical
expectation. It is recommended to allow for repeated V-cycles as in Figure 4
to test whether the code can converge the residual to machine precision zero.
Once a two-level code is written, most of the important steps are in place, and
it is easy to go to many levels. As discussed earlier, an additional term is
required in the defect correction for levels two or more removed from the fin-
est level. For the Poisson problem, it is good to use a coarsest grid with only
one central point.
One key recommendation for writing MG codes is to make the code as
modular as possible, with separate routines for each operation. Once relaxation,
restriction, defect correction, and interpolation codes are developed, these can
be used repeatedly for a wide range of problems. Also, preplanning and organi-
zation before starting to write the code can save a great deal of time and effort.
f ð
x
Þ
Search WWH ::




Custom Search