NAG FL Interface
d03ebf (dim2_​ellip_​fd)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

d03ebf uses the Strongly Implicit Procedure to calculate the solution to a system of simultaneous algebraic equations of five-point molecule form on a two-dimensional topologically-rectangular mesh. (‘Topological’ means that a polar grid, for example (r,θ), can be used, being equivalent to a rectangular box.)

2 Specification

Fortran Interface
Subroutine d03ebf ( n1, n2, lda, a, b, c, d, e, q, t, aparam, itmax, itcoun, itused, ndir, ixn, iyn, conres, conchn, resids, chngs, wrksp1, wrksp2, wrksp3, ifail)
Integer, Intent (In) :: n1, n2, lda, itmax, ndir, ixn, iyn
Integer, Intent (Inout) :: itcoun, ifail
Integer, Intent (Out) :: itused
Real (Kind=nag_wp), Intent (In) :: a(lda,n2), b(lda,n2), c(lda,n2), d(lda,n2), e(lda,n2), q(lda,n2), aparam, conres, conchn
Real (Kind=nag_wp), Intent (Inout) :: t(lda,n2), wrksp1(lda,n2), wrksp2(lda,n2), wrksp3(lda,n2)
Real (Kind=nag_wp), Intent (Out) :: resids(itmax), chngs(itmax)
C Header Interface
#include <nag.h>
void  d03ebf_ (const Integer *n1, const Integer *n2, const Integer *lda, const double a[], const double b[], const double c[], const double d[], const double e[], const double q[], double t[], const double *aparam, const Integer *itmax, Integer *itcoun, Integer *itused, const Integer *ndir, const Integer *ixn, const Integer *iyn, const double *conres, const double *conchn, double resids[], double chngs[], double wrksp1[], double wrksp2[], double wrksp3[], Integer *ifail)
The routine may be called by the names d03ebf or nagf_pde_dim2_ellip_fd.

3 Description

Given a set of simultaneous equations
Mt=q (1)
(which could be nonlinear) derived, for example, from a finite difference representation of a two-dimensional elliptic partial differential equation and its boundary conditions, the routine determines the values of the dependent variable t. q is a known vector of length n1×n2 and M is a square (n1×n2)×(n1×n2) matrix.
The equations must be of five-diagonal form:
aijti,j-1+bijti-1,j+cijtij+dijti+1,j+eijti,j+1=qij  
for i=1,2,,n1 and j=1,2,,n2, provided cij0.0. Indeed, if cij=0.0, then the equation is assumed to be
tij=qij.  
For example, if n1=3 and n2=2, the equations take the form:
[ c11 d11 e11 b21 c21 d21 e21 b31 c31 e31 a12 c12 d12 a22 b22 c22 d22 a32 b32 c32 ] [ t11 t21 t31 t12 t22 t32 ]=[ q11 q21 q31 q12 q22 q32 ] .  
The system is solved iteratively, from a starting approximation t (1) , by the formulae
r (n) =q-Mt(n) Ms(n) =r (n) t (n+1) =t (n) +s (n) .  
Thus r (n) is the residual of the nth approximate solution t (n) , and s (n) is the update change vector. The calling program supplies an initial approximation for the values of the dependent variable in the array t, the coefficients of the five-point molecule system of equations in the arrays a, b, c, d and e, and the source terms in the array q. The routine derives the residual of the latest approximate solution and then uses the approximate LU factorization of the Strongly Implicit Procedure with the necessary acceleration argument adjustment by calling d03uaf at each iteration. d03ebf combines the newly derived change with the old approximation to obtain the new approximate solution for t. The new solution is checked for convergence against the user-supplied convergence criteria and if these have not been achieved the iterative cycle is repeated. Convergence is based on both the maximum absolute normalized residuals (calculated with reference to the previous approximate solution as these are calculated at the commencement of each iteration) and on the maximum absolute change made to the values of t.
Problems in topologically non-rectangular regions can be solved using the routine by surrounding the region by a circumscribing topological rectangle. The equations for the nodal values external to the region of interest are set to zero (i.e., cij=tij=0) and the boundary conditions are incorporated into the equations for the appropriate nodes.
If there is no better initial approximation when starting the iterative cycle, an array of all zeros can be used as the initial approximation.
The routine can be used to solve linear elliptic equations in which case the arrays a, b, c, d, e and q are constants and for which a single call provides the required solution. It can also be used to solve nonlinear elliptic equations in which case some or all of these arrays may require updating during the progress of the iterations as more accurate solutions are derived. The routine will then have to be called repeatedly in an outer iterative cycle. Dependent on the nonlinearity, some under relaxation of the coefficients and/or source terms may be needed during their recalculation using the new estimates of the solution.
The routine can also be used to solve each step of a time-dependent parabolic equation in two space dimensions. The solution at each time step can be expressed in terms of an elliptic equation if the Crank–Nicolson or other form of implicit time integration is used.
Neither diagonal dominance, nor positive-definiteness, of the matrix M formed from the arrays a, b, c, d, e is necessary to ensure convergence.
For problems in which the solution is not unique in the sense that an arbitrary constant can be added to the solution, for example Laplace's equation with all Neumann boundary conditions, an argument is incorporated so that the solution can be rescaled by subtracting a specified nodal value from the whole solution t after the completion of every iteration to keep rounding errors to a minimum for those cases when the convergence is slow.

4 References

Jacobs D A H (1972) The strongly implicit procedure for the numerical solution of parabolic and elliptic partial differential equations Note RD/L/N66/72 Central Electricity Research Laboratory
Stone H L (1968) Iterative solution of implicit approximations of multi-dimensional partial differential equations SIAM J. Numer. Anal. 5 530–558

5 Arguments

1: n1 Integer Input
On entry: the number of nodes in the first coordinate direction, n1.
Constraint: n1>1.
2: n2 Integer Input
On entry: the number of nodes in the second coordinate direction, n2.
Constraint: n2>1.
3: lda Integer Input
On entry: the first dimension of the arrays a, b, c, d, e, q, t, wrksp1, wrksp2 and wrksp3 as declared in the (sub)program from which d03ebf is called.
Constraint: ldan1.
4: a(lda,n2) Real (Kind=nag_wp) array Input
On entry: a(i,j) must contain the coefficient of the ‘southerly’ term involving ti,j-1 in the (i,j)th equation of the system (1), for i=1,2,,n1 and j=1,2,,n2. The elements of a, for j=1, must be zero after incorporating the boundary conditions, since they involve nodal values from outside the rectangle.
5: b(lda,n2) Real (Kind=nag_wp) array Input
On entry: b(i,j) must contain the coefficient of the ‘westerly’ term involving ti-1,j in the (i,j)th equation of the system (1), for i=1,2,,n1 and j=1,2,,n2. The elements of b, for i=1, must be zero after incorporating the boundary conditions, since they involve nodal values from outside the rectangle.
6: c(lda,n2) Real (Kind=nag_wp) array Input
On entry: c(i,j) must contain the coefficient of the ‘central’ term involving tij in the (i,j)th equation of the system (1), for i=1,2,,n1 and j=1,2,,n2. The elements of c are checked to ensure that they are nonzero. If any element is found to be zero, the corresponding algebraic equation is assumed to be tij=qij. This feature can be used to define the equations for nodes at which, for example, Dirichlet boundary conditions are applied, or for nodes external to the problem of interest, by setting c(i,j)=0.0 at appropriate points, and the corresponding value of q(i,j) to the appropriate value, namely the prescribed value of t(i,j) in the Dirichlet case or zero at an external point.
7: d(lda,n2) Real (Kind=nag_wp) array Input
On entry: d(i,j) must contain the coefficient of the ‘easterly’ term involving ti+1,j in the (i,j)th equation of the system (1), for i=1,2,,n1 and j=1,2,,n2. The elements of d, for i=n1, must be zero after incorporating the boundary conditions, since they involve nodal values from outside the rectangle.
8: e(lda,n2) Real (Kind=nag_wp) array Input
On entry: e(i,j) must contain the coefficient of the ‘northerly’ term involving ti,j+1 in the (i,j)th equation of the system (1), for i=1,2,,n1 and j=1,2,,n2. The elements of e, for j=n2 must be zero after incorporating the boundary conditions, since they involve nodal values from outside the rectangle.
9: q(lda,n2) Real (Kind=nag_wp) array Input
On entry: q(i,j) must contain qij, for i=1,2,,n1 and j=1,2,,n2, i.e., the source term values at the nodal points for the system (1).
10: t(lda,n2) Real (Kind=nag_wp) array Input/Output
On entry: t(i,j) must contain the element tij of the approximate solution to the equations supplied by the calling program as an initial starting value, for i=1,2,,n1 and j=1,2,,n2.
If no better approximation is known, an array of zeros can be used.
On exit: the solution derived by the routine.
11: aparam Real (Kind=nag_wp) Input
On entry: the iteration acceleration factor. A value of 1.0 is adequate for most typical problems. However, if convergence is slow, the value can be reduced, typically to 0.2 or 0.1. If divergence is obtained, the value can be increased, typically to 2.0, 5.0 or 10.0.
Constraint: 0.0<aparam( (n1-1) 2+ (n2-1) 2)/2.0.
12: itmax Integer Input
On entry: the maximum number of iterations to be used by the routine in seeking the solution. A reasonable value might be 30 if n1=n2=10 or 100 if n1=n2=50.
13: itcoun Integer Input/Output
On entry: on the first call of d03ebf, itcoun must be set to 0. On subsequent entries, its value must be unchanged from the previous call.
On exit: its value is increased by the number of iterations used on this call (namely itused). It, therefore, stores the accumulated number of iterations actually used. For subsequent calls for the same problem, i.e., with the same n1 and n2 but possibly different coefficients and/or source terms, as occur with nonlinear systems or with time-dependent systems, itcoun is the accumulated number of iterations. This applies to the second and subsequent calls to d03ebf. In this way a suitable cycling of the sequence of iteration arguments is obtained in the calls to d03uaf.
14: itused Integer Output
On exit: the number of iterations actually used on that call.
15: ndir Integer Input
On entry: indicates whether or not the system of equations has a unique solution. For systems which have a unique solution, ndir must be set to any nonzero value. For systems derived from, for example, Laplace's equation with all Neumann boundary conditions, i.e., problems in which an arbitrary constant can be added to the solution, ndir should be set to 0 and the values of the next two arguments must be specified. For such problems the routine subtracts the value of the function derived at the node (ixn, iyn) from the whole solution after each iteration to reduce the possibility of large rounding errors. You must also ensure that for such problems the appropriate consistency condition on the source terms q is satisfied.
16: ixn Integer Input
On entry: is ignored unless ndir is equal to zero, in which case it must specify the first index of the nodal point at which the solution is to be set to zero. The node should not correspond to a corner node, or to a node external to the region of interest.
17: iyn Integer Input
On entry: is ignored unless ndir is equal to zero, in which case it must specify the second index of the nodal point at which the solution is to be set to zero. The node should not correspond to a corner node, or to a node external to the region of interest.
18: conres Real (Kind=nag_wp) Input
On entry: the convergence criterion to be used on the maximum absolute value of the normalized residual vector components. The latter is defined as the residual of the algebraic equation divided by the central coefficient when the latter is not equal to 0.0, and defined as the residual when the central coefficient is zero.
Clearly conres should not be less than a reasonable multiple of the machine precision.
19: conchn Real (Kind=nag_wp) Input
On entry: the convergence criterion to be used on the maximum absolute value of the change made at each iteration to the elements of the array t, namely the dependent variable. Clearly conchn should not be less than a reasonable multiple of the machine precision multiplied by the maximum value of t attained.
Convergence is achieved when both the convergence criteria are satisfied. You can, therefore, set convergence on either the residual or on the change, or (as is recommended) on a requirement that both are below prescribed limits.
20: resids(itmax) Real (Kind=nag_wp) array Output
On exit: the maximum absolute value of the residuals calculated at the ith iteration, for i=1,2,,itused. If you want to know the maximum absolute residual of the solution which is returned you must calculate this in the calling program. The sequence of values resids indicates the rate of convergence.
21: chngs(itmax) Real (Kind=nag_wp) array Output
On exit: the maximum absolute value of the changes made to the components of the dependent variable t at the ith iteration, for i=1,2,,itused. The sequence of values chngs indicates the rate of convergence.
22: wrksp1(lda,n2) Real (Kind=nag_wp) array Workspace
23: wrksp2(lda,n2) Real (Kind=nag_wp) array Workspace
24: wrksp3(lda,n2) Real (Kind=nag_wp) array Workspace
25: 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, n1=value.
Constraint: n1>1.
On entry, n2=value.
Constraint: n2>1.
ifail=2
On entry, lda=value and n1=value.
Constraint: ldan1.
ifail=3
On entry, aparam=value.
Constraint: aparam>0.0.
ifail=4
On entry, aparam=value, n1=value and n2=value.
Constraint: aparam((n1-1)2+(n2-1)2)/2.
ifail=5
Convergence not achieved in itmax iterations: itmax=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

The improvement in accuracy for each iteration depends on the size of the system and on the condition of the update matrix characterised by the five-diagonal coefficient arrays. The ultimate accuracy obtainable depends on the above factors and on the machine precision. The rate of convergence obtained with the Strongly Implicit Procedure is not always smooth because of the cyclic use of nine acceleration arguments. The convergence may become slow with very large problems, for example when n1=n2=60. The final accuracy may be judged approximately from the rate of convergence determined from the sequence of values returned in chngs and the magnitude of the maximum absolute value of the change vector on the last iteration stored in chngs(itused).

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
d03ebf is not threaded in any implementation.

9 Further Comments

The time taken per iteration is approximately proportional to n1×n2.
Convergence may not always be obtained when the problem is very large and/or the coefficients of the equations have widely disparate values. The latter case is often associated with a near ill-conditioned matrix.

10 Example

This example solves Laplace's equation in a rectangle with a non-uniform grid spacing in the x and y coordinate directions and with Dirichlet boundary conditions specifying the function on the perimeter of the rectangle equal to
e(1.0+x)/y(n2)×cos(y/y(n2)).  

10.1 Program Text

Program Text (d03ebfe.f90)

10.2 Program Data

Program Data (d03ebfe.d)

10.3 Program Results

Program Results (d03ebfe.r)
GnuplotProduced by GNUPLOT 5.4 patchlevel 6 gnuplot_plot_1 gnuplot_plot_2 0 5 10 15 20 25 30 35 40 45 Y 0 2 4 6 8 10 12 14 16 X 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 1.4 1.5 U Example Program Solution to Laplace's Equation using the Strongly Implicit Procedure on a Five-point Molecule Discretisation