NAG Library Routine Document
D03UBF
1 Purpose
D03UBF performs at each call one iteration of the Strongly Implicit Procedure. It is used to calculate on successive calls a sequence of approximate corrections to the current estimate of the solution when solving a system of simultaneous algebraic equations for which the iterative update matrix is of sevenpoint molecule form on a threedimensional topologicallyrectangular mesh. (‘Topological’ means that a polar grid $\left(r,\theta \right)$, for example, can be used as it is equivalent to a rectangular box.)
2 Specification
SUBROUTINE D03UBF ( 
N1, N2, N3, LDA, SDA, A, B, C, D, E, F, G, APARAM, IT, R, WRKSP1, WRKSP2, WRKSP3, IFAIL) 
INTEGER 
N1, N2, N3, LDA, SDA, IT, IFAIL 
REAL (KIND=nag_wp) 
A(LDA,SDA,N3), B(LDA,SDA,N3), C(LDA,SDA,N3), D(LDA,SDA,N3), E(LDA,SDA,N3), F(LDA,SDA,N3), G(LDA,SDA,N3), APARAM, R(LDA,SDA,N3), WRKSP1(LDA,SDA,N3), WRKSP2(LDA,SDA,N3), WRKSP3(LDA,SDA,N3) 

3 Description
Given a set of simultaneous equations
(which could be nonlinear) derived, for example, from a finite difference representation of a threedimensional elliptic partial differential equation and its boundary conditions, the solution
$t$ may be obtained iteratively from a starting approximation
${t}^{\left(1\right)}$ by the formulae
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.
D03UBF determines the approximate change vector
$s$ corresponding to a given residual
$r$, i.e., it determines an approximate solution to a set of equations
where
$M$ is a square
$\left({n}_{1}\times {n}_{2}\times {n}_{3}\right)$ by
$\left({n}_{1}\times {n}_{2}\times {n}_{3}\right)$ matrix and
$r$ is a known vector of length
$\left({n}_{1}\times {n}_{2}\times {n}_{3}\right)$. The set of equations
(2) must be of sevendiagonal form
for
$i=1,2,\dots ,{n}_{1}$,
$j=1,2,\dots ,{n}_{2}$ and
$k=1,2,\dots ,{n}_{3}$, provided that
${d}_{ijk}\ne 0.0$. Indeed, if
${d}_{ijk}=0.0$, then the equation is assumed to be
The calling program supplies the current residual
$r$ at each iteration and the coefficients of the sevenpoint molecule system of equations on which the update procedure is based. The routine performs one iteration, using the approximate
$LU$ factorization of the Strongly Implicit Procedure with the necessary acceleration parameter adjustment, to calculate the approximate solution
$s$ of the set of equations
(2). The change
$s$ overwrites the residual array for return to the calling program. The calling program must combine this change stored in
$r$ with the old approximation to obtain the new approximate solution for
$t$. It must then recalculate the residuals and, if the accuracy requirements have not been satisfied, commence the next iterative cycle.
Clearly there is no requirement that the iterative update matrix passed in the form of the sevendiagonal element arrays
A,
B,
C,
D,
E,
F and
G is the same as that used to calculate the residuals, and therefore the one governing the problem. However, the convergence may be impaired if they are not equal. Indeed, if the system of equations
(1) is not precisely of the sevendiagonal form illustrated above but has a few additional terms, then the methods of deferred or defect correction can be employed. The residual is calculated by the calling program using the full system of equations, but the update formula is based on a sevendiagonal system
(2) of the form given above. For example, the solution of a system of elevendiagonal equations each involving the combination of terms with
${t}_{i\pm 1,j\pm 1,k},{t}_{i\pm 1,j,k},{t}_{i,j\pm 1,k},{t}_{i,j,k\pm 1}$ and
${t}_{ijk}$ could use the sevendiagonal coefficients on which to base the update, provided these incorporate the major features of the equations.
Problems in topologically nonrectangular boxshaped regions can be solved using the routine by surrounding the region with a circumscribing topologically rectangular box. The equations for the nodal values external to the region of interest are set to zero (i.e., ${d}_{ijk}={r}_{ijk}=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, one can use an array of all zeros as the initial approximation from which the first set of residuals are determined.
The routine can be used to solve linear elliptic equations in which case the arrays
A,
B,
C,
D,
E,
F and
G and the quantities
$q$ will be unchanged during the iterative cycles, or for solving nonlinear elliptic equations in which case some or all of these arrays may require updating as each new approximate solution is derived. Depending on the nonlinearity, some underrelaxation of the coefficients and/or source terms may be needed during their recalculation using the new estimates of the solution (see
Jacobs (1972)).
The routine can also be used to solve each step of a timedependent parabolic equation in three 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 positivedefiniteness, of the matrix
$M$ or of the update matrix formed from the arrays
A,
B,
C,
D,
E,
F and
G 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 Poisson's equation with all Neumann boundary conditions), the calling program should subtract a typical nodal value from the whole solution $t$ at every iteration to keep rounding errors to a minimum for those cases when convergence is slow. For such problems there is generally an associated compatibility condition. For the example mentioned this compatibility condition equates the total net source within the region (i.e., the source integrated over the region) with the total net outflow across the boundaries defined by the Neumann conditions (i.e., the normal derivative integrated along the whole boundary). It is very important that the algebraic equations derived to model such a problem accurately implement the compatibility condition. If they do not, a net source or sink is very likely to be represented by the set of algebraic equations and no steadystate solution of the equations exists.
4 References
Ames W F (1977) Nonlinear Partial Differential Equations in Engineering (2nd Edition) Academic Press
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 multidimensional partial differential equations SIAM J. Numer. Anal. 5 530–558
Weinstein H G, Stone H L and Kwan T V (1969) Iterative procedure for solution of systems of parabolic and elliptic equations in three dimensions Industrial and Engineering Chemistry Fundamentals 8 281–287
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: N3 – INTEGERInput
On entry: the number of nodes in the third coordinate direction, ${n}_{3}$.
Constraint:
${\mathbf{N3}}>1$.
 4: LDA – INTEGERInput
On entry: the first dimension of the arrays
A,
B,
C,
D,
E,
F,
G,
R,
WRKSP1,
WRKSP2 and
WRKSP3 as declared in the (sub)program from which D03UBF is called.
Constraint:
${\mathbf{LDA}}\ge {\mathbf{N1}}$.
 5: SDA – INTEGERInput
On entry: the second dimension of the arrays
A,
B,
C,
D,
E,
F,
G,
R,
WRKSP1,
WRKSP2 and
WRKSP3 as declared in the (sub)program from which D03UBF is called.
Constraint:
${\mathbf{SDA}}\ge {\mathbf{N2}}$.
 6: A(LDA,SDA,N3) – REAL (KIND=nag_wp) arrayInput
On entry:
${\mathbf{A}}\left(i,j,k\right)$ must contain the coefficient of
${s}_{ij,k1}$ in the
$\left(i,j,k\right)$th equation of the system
(2), for
$\mathit{i}=1,2,\dots ,{\mathbf{N1}}$,
$\mathit{j}=1,2,\dots ,{\mathbf{N2}}$ and
$\mathit{k}=1,2,\dots ,{\mathbf{N3}}$. The elements of
A, for
$k=1$, must be zero after incorporating the boundary conditions, since they involve nodal values from outside the box.
 7: B(LDA,SDA,N3) – REAL (KIND=nag_wp) arrayInput
On entry:
${\mathbf{B}}\left(i,j,k\right)$ must contain the coefficient of
${s}_{i,j1,k}$ in the
$\left(i,j,k\right)$th equation of the system
(2), for
$\mathit{i}=1,2,\dots ,{\mathbf{N1}}$,
$\mathit{j}=1,2,\dots ,{\mathbf{N2}}$ and
$\mathit{k}=1,2,\dots ,{\mathbf{N3}}$. The elements of
B, for
$j=1$, must be zero after incorporating the boundary conditions, since they involve nodal values from outside the box.
 8: C(LDA,SDA,N3) – REAL (KIND=nag_wp) arrayInput
On entry:
${\mathbf{C}}\left(\mathit{i},\mathit{j},\mathit{k}\right)$ must contain the coefficient of
${s}_{\mathit{i}1,\mathit{j},\mathit{k}}$ in the
$\left(\mathit{i},\mathit{j},\mathit{k}\right)$th equation of the system
(2), for
$\mathit{i}=1,2,\dots ,{\mathbf{N1}}$,
$\mathit{j}=1,2,\dots ,{\mathbf{N2}}$ and
$\mathit{k}=1,2,\dots ,{\mathbf{N3}}$. The elements of
C, for
$i=1$, must be zero after incorporating the boundary conditions, since they involve nodal values from outside the box.
 9: D(LDA,SDA,N3) – REAL (KIND=nag_wp) arrayInput
On entry:
${\mathbf{D}}\left(\mathit{i},\mathit{j},\mathit{k}\right)$ must contain the coefficient of
${s}_{\mathit{i}\mathit{j}\mathit{k}}$, the ‘central’ term, in the
$\left(\mathit{i},\mathit{j},\mathit{k}\right)$th equation of the system
(2), for
$\mathit{i}=1,2,\dots ,{\mathbf{N1}}$,
$\mathit{j}=1,2,\dots ,{\mathbf{N2}}$ and
$\mathit{k}=1,2,\dots ,{\mathbf{N3}}$. The elements of
D are checked to ensure that they are nonzero. If any element is found to be zero, the corresponding algebraic equation is assumed to be
${s}_{\mathit{i}\mathit{j}\mathit{k}}={r}_{\mathit{i}\mathit{j}\mathit{k}}$. 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{D}}\left(\mathit{i},\mathit{j},\mathit{k}\right)=0.0$ at appropriate points. The corresponding value of
${r}_{\mathit{i}\mathit{j}\mathit{k}}$ is set equal to the appropriate value, namely the difference between the prescribed value of
${t}_{\mathit{i}\mathit{j}\mathit{k}}$ and the current value in the Dirichlet case, or zero at an external point.
 10: E(LDA,SDA,N3) – REAL (KIND=nag_wp) arrayInput
On entry:
${\mathbf{E}}\left(\mathit{i},\mathit{j},\mathit{k}\right)$ must contain the coefficient of
${s}_{\mathit{i}+1,\mathit{j},\mathit{k}}$ in the
$\left(\mathit{i},\mathit{j},\mathit{k}\right)$th equation of the system
(2), for
$\mathit{i}=1,2,\dots ,{\mathbf{N1}}$,
$\mathit{j}=1,2,\dots ,{\mathbf{N2}}$ and
$\mathit{k}=1,2,\dots ,{\mathbf{N3}}$. The elements of
E, for
$i={\mathbf{N1}}$, must be zero after incorporating the boundary conditions, since they involve nodal values from outside the box.
 11: F(LDA,SDA,N3) – REAL (KIND=nag_wp) arrayInput
On entry:
${\mathbf{F}}\left(\mathit{i},\mathit{j},\mathit{k}\right)$ must contain the coefficient of
${s}_{\mathit{i},\mathit{j}+1,\mathit{k}}$ in the
$\left(\mathit{i},\mathit{j},\mathit{k}\right)$th equation of the system
(2), for
$\mathit{i}=1,2,\dots ,{\mathbf{N1}}$,
$\mathit{j}=1,2,\dots ,{\mathbf{N2}}$ and
$\mathit{k}=1,2,\dots ,{\mathbf{N3}}$. The elements of
F, for
$j={\mathbf{N2}}$, must be zero after incorporating the boundary conditions, since they involve nodal values from outside the box.
 12: G(LDA,SDA,N3) – REAL (KIND=nag_wp) arrayInput
On entry:
${\mathbf{G}}\left(\mathit{i},\mathit{j},\mathit{k}\right)$ must contain the coefficient of
${s}_{\mathit{i},\mathit{j},\mathit{k}+1}$ in the
$\left(\mathit{i},\mathit{j},\mathit{k}\right)$th equation of the system
(2), for
$\mathit{i}=1,2,\dots ,{\mathbf{N1}}$,
$\mathit{j}=1,2,\dots ,{\mathbf{N2}}$ and
$\mathit{k}=1,2,\dots ,{\mathbf{N3}}$. The elements of
G, for
$k={\mathbf{N3}}$, must be zero after incorporating the boundary conditions, since they involve nodal values from outside the box.
 13: 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}+{\left({\mathbf{N3}}1\right)}^{2}\right)/3.0$.
 14: IT – INTEGERInput
On entry: the iteration number. It must be initialized, but not necessarily to
$1$, before the first call, and should be incremented by one in the calling program for each subsequent call. The routine uses this counter to select the appropriate acceleration parameter from a sequence of nine, each one being used twice in succession. (Note that the acceleration parameter depends on the value of
APARAM.)
 15: R(LDA,SDA,N3) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the current residual
${r}_{\mathit{i}\mathit{j}\mathit{k}}$ on the righthand side of the
$\left(\mathit{i},\mathit{j},\mathit{k}\right)$th equation of the system
(2), for
$\mathit{i}=1,2,\dots ,{\mathbf{N1}}$,
$\mathit{j}=1,2,\dots ,{\mathbf{N2}}$ and
$\mathit{k}=1,2,\dots ,{\mathbf{N3}}$.
On exit: these residuals are overwritten by the corresponding components of the solution
$s$ of the system
(2), i.e., the changes to be made to the vector
$t$ to reduce the residuals supplied.
 16: WRKSP1(LDA,SDA,N3) – REAL (KIND=nag_wp) arrayWorkspace
 17: WRKSP2(LDA,SDA,N3) – REAL (KIND=nag_wp) arrayWorkspace
 18: WRKSP3(LDA,SDA,N3) – REAL (KIND=nag_wp) arrayWorkspace
 19: 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$, 
or  ${\mathbf{N3}}<2$. 
 ${\mathbf{IFAIL}}=2$
On entry,  ${\mathbf{LDA}}<{\mathbf{N1}}$, 
or  ${\mathbf{SDA}}<{\mathbf{N2}}$. 
 ${\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}+{\left({\mathbf{N3}}1\right)}^{2}\right)/3.0$. 
7 Accuracy
The improvement in accuracy for each iteration, i.e., on each call, depends on the size of the system and on the condition of the update matrix characterised by the sevendiagonal coefficient arrays. The ultimate accuracy obtainable depends on the above factors and on the machine precision. However, since D03UBF works with residuals and the update vector, the calling program can, in most cases where at each iteration all the residuals are usually of about the same size, calculate the residuals from extended precision values of the function, source term and equation coefficients if greater accuracy is required. 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. The final accuracy obtained can be judged approximately from the rate of convergence determined from the changes to the dependent variable $t$ and in particular the change on the last iteration.
The time taken is approximately proportional to ${\mathbf{N1}}\times {\mathbf{N2}}\times {\mathbf{N3}}$ for each call.
When used with deferred or defect correction, the residual is calculated in the calling program from a different system of equations to those represented by the sevenpoint molecule coefficients used by D03UBF as the basis of the iterative update procedure. When using deferred correction the overall rate of convergence depends not only on the items detailed in
Section 7 but also on the difference between the two coefficient matrices used.
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 may be associated with an illconditioned matrix.
9 Example
This example solves Laplace's equation in a rectangular box with a nonuniform grid spacing in the
$x$,
$y$ and
$z$ coordinate directions and with Dirichlet boundary conditions specifying the function on the surfaces of the box equal to
Note that this is the same problem as that solved in the example for
D03ECF. The differences in the maximum residuals obtained at each iteration between the two test runs are explained by the fact that in
D03ECF the residual at each node is normalized by dividing by the central coefficient, whereas this normalization has not been used in the example program for D03UBF.
9.1 Program Text
Program Text (d03ubfe.f90)
9.2 Program Data
Program Data (d03ubfe.d)
9.3 Program Results
Program Results (d03ubfe.r)