D03 Chapter Contents
D03 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentD03EBF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 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 $\left(r,\theta \right)$, can be used, being equivalent to a rectangular box.)

## 2  Specification

 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 N1, N2, LDA, ITMAX, ITCOUN, ITUSED, NDIR, IXN, IYN, IFAIL REAL (KIND=nag_wp) A(LDA,N2), B(LDA,N2), C(LDA,N2), D(LDA,N2), E(LDA,N2), Q(LDA,N2), T(LDA,N2), APARAM, CONRES, CONCHN, RESIDS(ITMAX), CHNGS(ITMAX), WRKSP1(LDA,N2), WRKSP2(LDA,N2), WRKSP3(LDA,N2)

## 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 ${n}_{1}×{n}_{2}$ and $M$ is a square $\left({n}_{1}×{n}_{2}\right)$ by $\left({n}_{1}×{n}_{2}\right)$ 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,\dots ,{n}_{1}$ and $j=1,2,\dots ,{n}_{2}$, provided ${c}_{ij}\ne 0.0$. Indeed, if ${c}_{ij}=0.0$, then the equation is assumed to be
 $tij=qij.$
For example, if ${n}_{1}=3$ and ${n}_{2}=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}^{\left(1\right)}$, by the formulae
 $r n =q-Mtn Msn =r n t n+1 =t n +s n .$
Thus ${r}^{\left(n\right)}$ is the residual of the $n$th approximate solution ${t}^{\left(n\right)}$, and ${s}^{\left(n\right)}$ 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 parameter 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., ${c}_{ij}={t}_{ij}=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, a parameter 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  Parameters

1:     N1 – INTEGERInput
On entry: the number of nodes in the first coordinate direction, ${n}_{1}$.
Constraint: ${\mathbf{N1}}>1$.
2:     N2 – INTEGERInput
On entry: the number of nodes in the second coordinate direction, ${n}_{2}$.
Constraint: ${\mathbf{N2}}>1$.
3:     LDA – INTEGERInput
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: ${\mathbf{LDA}}\ge {\mathbf{N1}}$.
4:     A(LDA,N2) – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{A}}\left(\mathit{i},\mathit{j}\right)$ must contain the coefficient of the ‘southerly’ term involving ${t}_{\mathit{i},\mathit{j}-1}$ in the $\left(\mathit{i},\mathit{j}\right)$th equation of the system (1), for $\mathit{i}=1,2,\dots ,{\mathbf{N1}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{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) arrayInput
On entry: ${\mathbf{B}}\left(\mathit{i},\mathit{j}\right)$ must contain the coefficient of the ‘westerly’ term involving ${t}_{i-1,j}$ in the $\left(i,j\right)$th equation of the system (1), for $\mathit{i}=1,2,\dots ,{\mathbf{N1}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{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) arrayInput
On entry: ${\mathbf{C}}\left(\mathit{i},\mathit{j}\right)$ must contain the coefficient of the ‘central’ term involving ${t}_{\mathit{i}\mathit{j}}$ in the $\left(\mathit{i},\mathit{j}\right)$th equation of the system (1), for $\mathit{i}=1,2,\dots ,{\mathbf{N1}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{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 ${t}_{\mathit{i}\mathit{j}}={q}_{\mathit{i}\mathit{j}}$. 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 ${\mathbf{C}}\left(\mathit{i},\mathit{j}\right)=0.0$ at appropriate points, and the corresponding value of ${\mathbf{Q}}\left(\mathit{i},\mathit{j}\right)$ to the appropriate value, namely the prescribed value of ${\mathbf{T}}\left(\mathit{i},\mathit{j}\right)$ in the Dirichlet case or zero at an external point.
7:     D(LDA,N2) – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{D}}\left(\mathit{i},\mathit{j}\right)$ must contain the coefficient of the ‘easterly’ term involving ${t}_{\mathit{i}+1,\mathit{j}}$ in the $\left(\mathit{i},\mathit{j}\right)$th equation of the system (1), for $\mathit{i}=1,2,\dots ,{\mathbf{N1}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{N2}}$. The elements of D, for $i={\mathbf{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) arrayInput
On entry: ${\mathbf{E}}\left(\mathit{i},\mathit{j}\right)$ must contain the coefficient of the ‘northerly’ term involving ${t}_{\mathit{i},\mathit{j}+1}$ in the $\left(\mathit{i},\mathit{j}\right)$th equation of the system (1), for $\mathit{i}=1,2,\dots ,{\mathbf{N1}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{N2}}$. The elements of E, for $j={\mathbf{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) arrayInput
On entry: ${\mathbf{Q}}\left(\mathit{i},\mathit{j}\right)$ must contain ${q}_{\mathit{i}\mathit{j}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{N1}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{N2}}$, i.e., the source term values at the nodal points for the system (1).
10:   T(LDA,N2) – REAL (KIND=nag_wp) arrayInput/Output
On entry: ${\mathbf{T}}\left(\mathit{i},\mathit{j}\right)$ must contain the element ${t}_{\mathit{i}\mathit{j}}$ of the approximate solution to the equations supplied by the calling program as an initial starting value, for $\mathit{i}=1,2,\dots ,{\mathbf{N1}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{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<{\mathbf{APARAM}}\le \left({\left({\mathbf{N1}}-1\right)}^{2}+{\left({\mathbf{N2}}-1\right)}^{2}\right)/2.0$.
12:   ITMAX – INTEGERInput
On entry: the maximum number of iterations to be used by the routine in seeking the solution. A reasonable value might be $30$ if ${\mathbf{N1}}={\mathbf{N2}}=10$ or $100$ if ${\mathbf{N1}}={\mathbf{N2}}=50$.
13:   ITCOUN – INTEGERInput/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 parameters is obtained in the calls to D03UAF.
14:   ITUSED – INTEGEROutput
On exit: the number of iterations actually used on that call.
15:   NDIR – INTEGERInput
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 parameters 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 – INTEGERInput
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 – INTEGERInput
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) arrayOutput
On exit: the maximum absolute value of the residuals calculated at the $\mathit{i}$th iteration, for $\mathit{i}=1,2,\dots ,{\mathbf{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) arrayOutput
On exit: the maximum absolute value of the changes made to the components of the dependent variable T at the $\mathit{i}$th iteration, for $\mathit{i}=1,2,\dots ,{\mathbf{ITUSED}}$. The sequence of values CHNGS indicates the rate of convergence.
22:   WRKSP1(LDA,N2) – REAL (KIND=nag_wp) arrayWorkspace
23:   WRKSP2(LDA,N2) – REAL (KIND=nag_wp) arrayWorkspace
24:   WRKSP3(LDA,N2) – REAL (KIND=nag_wp) arrayWorkspace
25:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{N1}}<2$, or ${\mathbf{N2}}<2$.
${\mathbf{IFAIL}}=2$
 On entry, ${\mathbf{LDA}}<{\mathbf{N1}}$.
${\mathbf{IFAIL}}=3$
 On entry, ${\mathbf{APARAM}}\le 0.0$.
${\mathbf{IFAIL}}=4$
 On entry, ${\mathbf{APARAM}}>\left({\left({\mathbf{N1}}-1\right)}^{2}+{\left({\mathbf{N2}}-1\right)}^{2}\right)/2.0$.
${\mathbf{IFAIL}}=5$
Convergence was not achieved after ITMAX iterations.

## 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 parameters. The convergence may become slow with very large problems, for example when ${\mathbf{N1}}={\mathbf{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 ${\mathbf{CHNGS}}\left({\mathbf{ITUSED}}\right)$.

The time taken per iteration is approximately proportional to ${\mathbf{N1}}×{\mathbf{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.

## 9  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
 $e1.0+x/yn2×cosy/yn2.$

### 9.1  Program Text

Program Text (d03ebfe.f90)

### 9.2  Program Data

Program Data (d03ebfe.d)

### 9.3  Program Results

Program Results (d03ebfe.r)