NAG FL Interface
d03edf (dim2_​ellip_​mgrid)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

d03edf solves seven-diagonal systems of linear equations which arise from the discretization of an elliptic partial differential equation on a rectangular region. This routine uses a multigrid technique.

2 Specification

Fortran Interface
Subroutine d03edf ( ngx, ngy, lda, a, rhs, ub, maxit, acc, us, u, iout, numit, ifail)
Integer, Intent (In) :: ngx, ngy, lda, maxit, iout
Integer, Intent (Inout) :: ifail
Integer, Intent (Out) :: numit
Real (Kind=nag_wp), Intent (In) :: acc
Real (Kind=nag_wp), Intent (Inout) :: a(lda,7), rhs(lda), ub(ngx*ngy)
Real (Kind=nag_wp), Intent (Out) :: us(lda), u(lda)
C Header Interface
#include <nag.h>
void  d03edf_ (const Integer *ngx, const Integer *ngy, const Integer *lda, double a[], double rhs[], double ub[], const Integer *maxit, const double *acc, double us[], double u[], const Integer *iout, Integer *numit, Integer *ifail)
The routine may be called by the names d03edf or nagf_pde_dim2_ellip_mgrid.

3 Description

d03edf solves, by multigrid iteration, the seven-point scheme
Ai,j6ui-1,j+1 + Ai,j7ui,j+1 + Ai,j3ui-1,j + Ai,j4uij + Ai,j5ui+1,j + Ai,j1ui,j-1 + Ai,j2ui+1,j-1=fij,  i=1,2,,nx​ and ​j=1,2,,ny,  
which arises from the discretization of an elliptic partial differential equation of the form
α (x,y)Uxx+β (x,y)Uxy+γ (x,y)Uyy+δ (x,y)Ux+ε (x,y)Uy+ϕ (x,y)U=ψ (x,y)  
and its boundary conditions, defined on a rectangular region. This we write in matrix form as
Au=f.  
The algorithm is described in separate reports by Wesseling (1982a), Wesseling (1982b) and McCarthy (1983).
Systems of linear equations, matching the seven-point stencil defined above, are solved by a multigrid iteration. An initial estimate of the solution must be provided by you. A zero guess may be supplied if no better approximation is available.
A ‘smoother’ based on incomplete Crout decomposition is used to eliminate the high frequency components of the error. A restriction operator is then used to map the system on to a sequence of coarser grids. The errors are then smoothed and prolongated (mapped onto successively finer grids). When the finest cycle is reached, the approximation to the solution is corrected. The cycle is repeated for maxit iterations or until the required accuracy, acc, is reached.
d03edf will automatically determine the number l of possible coarse grids, ‘levels’ of the multigrid scheme, for a particular problem. In other words, d03edf determines the maximum integer l so that nx and ny can be expressed in the form
nx = m2l-1 + 1 ,   ny = n2l-1 + 1 ,   with   m2 ​ and ​ n2 .  
It should be noted that the rate of convergence improves significantly with the number of levels used (see McCarthy (1983)), so that nx and ny should be carefully chosen so that nx-1 and ny-1 have factors of the form 2l, with l as large as possible. For good convergence the integer l should be at least 2.
d03edf has been found to be robust in application, but being an iterative method the problem of divergence can arise. For a strictly diagonally dominant matrix A
|Aij4| > k4 |Aijk| ,   i=1,2,,nx ​ and ​ j=1,2,,ny  
no such problem is foreseen. The diagonal dominance of A is not a necessary condition, but should this condition be strongly violated then divergence may occur. The quickest test is to try the routine.

4 References

McCarthy G J (1983) Investigation into the multigrid code MGD1 Report AERE-R 10889 Harwell
Wesseling P (1982a) MGD1 – a robust and efficient multigrid method Multigrid Methods. Lecture Notes in Mathematics 960 614–630 Springer–Verlag
Wesseling P (1982b) Theoretical aspects of a multigrid method SIAM J. Sci. Statist. Comput. 3 387–407

5 Arguments

1: ngx Integer Input
On entry: the number of interior grid points in the x-direction, nx. ngx-1 should preferably be divisible by as high a power of 2 as possible.
Constraint: ngx3.
2: ngy Integer Input
On entry: the number of interior grid points in the y-direction, ny. ngy-1 should preferably be divisible by as high a power of 2 as possible.
Constraint: ngy3.
3: lda Integer Input
On entry: the first dimension of the array a, which must also be a lower bound for the dimension of the arrays rhs, us and u as declared in the (sub)program from which d03edf is called. It is always sufficient to set lda(4×(ngx+1)×(ngy+1))/3, but slightly smaller values may be permitted, depending on the values of ngx and ngy. If on entry, lda is too small, an error message gives the minimum permitted value. (lda must be large enough to allow space for the coarse-grid approximations.)
4: a(lda,7) Real (Kind=nag_wp) array Input/Output
On entry: a(i+(j-1)×ngx,k) must be set to aijk, for i=1,2,,ngx, j=1,2,,ngy and k=1,2,,7.
On exit: is overwritten.
5: rhs(lda) Real (Kind=nag_wp) array Input/Output
On entry: rhs(i+(j-1)×ngx) must be set to fij, for i=1,2,,ngx and j=1,2,,ngy.
On exit: the first ngx×ngy elements are unchanged and the rest of the array is used as workspace.
6: ub(ngx×ngy) Real (Kind=nag_wp) array Input/Output
On entry: ub(i+(j-1)×ngx) must be set to the initial estimate for the solution uij.
On exit: the corresponding component of the residual r=f-au.
7: maxit Integer Input
On entry: the maximum permitted number of multigrid iterations. If maxit=0, no multigrid iterations are performed, but the coarse-grid approximations and incomplete Crout decompositions are computed, and may be output if iout is set accordingly.
Constraint: maxit0.
8: acc Real (Kind=nag_wp) Input
On entry: the required tolerance for convergence of the residual 2-norm:
r2=k=1 ngx×ngy (rk) 2  
where r=f-Au and u is the computed solution. Note that the norm is not scaled by the number of equations. The routine will stop after fewer than maxit iterations if the residual 2-norm is less than the specified tolerance. (If maxit>0, at least one iteration is always performed.)
If on entry acc=0.0, the machine precision is used as a default value for the tolerance; if acc>0.0, but acc is less than the machine precision, the routine will stop when the residual 2-norm is less than the machine precision and ifail will be set to 4.
Constraint: acc0.0.
9: us(lda) Real (Kind=nag_wp) array Output
On exit: the residual 2-norm, stored in element us(1).
10: u(lda) Real (Kind=nag_wp) array Output
On exit: the computed solution uij is returned in u(i+(j-1)×ngx), for i=1,2,,ngx and j=1,2,,ngy.
11: iout Integer Input
On entry: controls the output of printed information to the current advisory message unit (see x04abf):
iout=0
No output.
iout=1
The solution uij, for i=1,2,,ngx and j=1,2,,ngy.
iout=2
The residual 2-norm after each iteration, with the reduction factor over the previous iteration.
iout=3
As for iout=1 and iout=2.
iout=4
As for iout=3, plus the final residual (as returned in ub).
iout=5
As for iout=4, plus the initial elements of a and rhs.
iout=6
As for iout=5, plus the Galerkin coarse grid approximations.
iout=7
As for iout=6, plus the incomplete Crout decompositions.
iout=8
As for iout=7, plus the residual after each iteration.
The elements a(p,k), the Galerkin coarse grid approximations and the incomplete Crout decompositions are output in the format:
  • Y-index =j
  • X-index =ia(p,1)a(p,2)a(p,3)a(p,4)a(p,5)a(p,6)a(p,7)
  • where p=i+(j-1)×ngx, for i=1,2,,ngx and j=1,2,,ngy.
The vectors u(p), ub(p), rhs(p) are output in matrix form with ngy rows and ngx columns. Where ngx>10, the ngx values for a given j value are produced in rows of 10. Values of iout>4 may yield considerable amounts of output.
Constraint: 0iout8.
12: numit Integer Output
On exit: the number of iterations performed.
13: ifail Integer Input/Output
On entry: ifail must be set to 0, -1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of -1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value -1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry ifail=0 or -1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
ifail=1
On entry, acc=value.
Constraint: acc0.0.
On entry, iout=value.
Constraint: 0iout8.
On entry, lda=value.
Constraint: lda must be at least value.
On entry, maxit=value.
Constraint: maxit0.
On entry, ngx=value.
Constraint: ngx3.
On entry, ngy=value.
Constraint: ngy3.
ifail=2
After maxit iterations the residual norm is not less than the tolerance maxit=value, residual norm =value, tolerance =value. The residual norm has decreased at each iteration after the first.
ifail=3
After maxit iterations the residual norm is not less than the tolerance maxit=value, residual norm =value, tolerance =value. The residual norm increased at one or more iterations after the first.
ifail=4
On entry, acc is less than machine precision. The routine terminated because the residual norm is less than machine precision. residual norm =value, machine precision =value and acc=value.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

See acc (Section 5).

8 Parallelism and Performance

d03edf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9 Further Comments

The rate of convergence of this routine is strongly dependent upon the number of levels, l, in the multigrid scheme, and thus the choice of ngx and ngy is very important. You are advised to experiment with different values of ngx and ngy to see the effect they have on the rate of convergence; for example, using a value such as ngx=65 (=26+1) followed by ngx=64 (for which l=1).

10 Example

The program solves the elliptic partial differential equation
Uxx-αUxy+Uyy=-4,  α=1.7  
on the unit square 0x,y1, with boundary conditions
U=0 ​ on ​ { x=0, (0y1) y=0, (0x1) y=1, (0x1) U=1​ on ​x=1,  0y1.  
For the equation to be elliptic, α must be less than 2.
The equation is discretized on a square grid with mesh spacing h in both directions using the following approximations:
Figure 1
Figure 1
Uxx 1h2(UE-2UO+UW) Uyy 1h2(UN-2UO+US) Uxy 12h2 (UN-UNW+UE-2UO+UW-USE+US).  
Thus the following equations are solved:
12α ui- 1,j+ 1 + (1-12α)ui,j+ 1 + (1-12α)ui+ 1,j + (-4+α)uij + (1-12α)ui+ 1,j + (1-12α)ui,j- 1 + 12α ui+ 1,j- 1=-4h2  

10.1 Program Text

Program Text (d03edfe.f90)

10.2 Program Data

Program Data (d03edfe.d)

10.3 Program Results

Program Results (d03edfe.r)
GnuplotProduced by GNUPLOT 4.6 patchlevel 3 Example Program Solution of Elliptic PDE using Multigrid Iteration on System Resulting from Seven-point Stencil gnuplot_plot_1 gnuplot_plot_2 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 x 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 y 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 U