D03ECF (PDF version)
D03 Chapter Contents
D03 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

D03ECF

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.

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

D03ECF uses the Strongly Implicit Procedure to calculate the solution to a system of simultaneous algebraic equations of seven-point molecule form on a three-dimensional topologically-rectangular mesh. (‘Topological’ means that a polar grid, for example, can be used if it is equivalent to a rectangular box.)

2  Specification

SUBROUTINE D03ECF ( N1, N2, N3, LDA, SDA, A, B, C, D, E, F, G, Q, T, APARAM, ITMAX, ITCOUN, ITUSED, NDIR, IXN, IYN, IZN, CONRES, CONCHN, RESIDS, CHNGS, WRKSP1, WRKSP2, WRKSP3, WRKSP4, IFAIL)
INTEGER  N1, N2, N3, LDA, SDA, ITMAX, ITCOUN, ITUSED, NDIR, IXN, IYN, IZN, 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), Q(LDA,SDA,N3), T(LDA,SDA,N3), APARAM, CONRES, CONCHN, RESIDS(ITMAX), CHNGS(ITMAX), WRKSP1(LDA,SDA,N3), WRKSP2(LDA,SDA,N3), WRKSP3(LDA,SDA,N3), WRKSP4(LDA,SDA,N3)

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 three-dimensional elliptic partial differential equation and its boundary conditions, the routine determines the values of the dependent variable t. M is a square n1×n2×n3 by n1×n2×n3 matrix and q is a known vector of length n1×n2×n3.
The equations must be of seven-diagonal form:
aijktij,k-1+bijkti,j-1,k+cijkti-1,jk+dijktijk+eijkti+1,jk+fijkti,j+1,k+gijktij,k+1=qijk
for i=1,2,,n1, j=1,2,,n2 and k=1,2,,n3, provided that dijk0.0.
Indeed, if dijk=0.0, then the equation is assumed to be:
tijk=qijk.
The system is solved iteratively from a starting approximation t 1  by the formulae:
r n = q-Mtn Msn = 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 seven-point molecule system of equations in the arrays A, B, C, D, E, F and G, 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 D03UBF at each iteration. D03ECF 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 satisfied, 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-box-shaped regions can be solved using the routine by surrounding the region by a circumscribing topologically rectangular box. The equations for the nodal values external to the region of interest are set to zero (i.e., dijk=tijk=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 zeros as the initial approximation.
The routine can be used to solve linear elliptic equations in which case the arrays A, B, C, D, E, F, G and Q remain constant 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 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 positive-definiteness, of the matrix M 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), a parameter is incorporated so that the solution can be rescaled. A specified nodal value is subtracted from the whole solution t after the completion of every iteration. This keeps 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 implement accurately 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 steady-state solution of the equations exists.

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
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, n1.
Constraint: N1>1.
2:     N2 – INTEGERInput
On entry: the number of nodes in the second coordinate direction, n2.
Constraint: N2>1.
3:     N3 – INTEGERInput
On entry: the number of nodes in the third coordinate direction, n3.
Constraint: N3>1.
4:     LDA – INTEGERInput
On entry: the first dimension of the arrays A, B, C, D, E, F, G, Q, T, WRKSP1, WRKSP2, WRKSP3 and WRKSP4 as declared in the (sub)program from which D03ECF is called.
Constraint: LDAN1.
5:     SDA – INTEGERInput
On entry: the second dimension of the arrays A, B, C, D, E, F, G, Q, T, WRKSP1, WRKSP2, WRKSP3 and WRKSP4 as declared in the (sub)program from which D03ECF is called.
Constraint: SDAN2.
6:     A(LDA,SDA,N3) – REAL (KIND=nag_wp) arrayInput
On entry: Ai,j,k must contain the coefficient of tij,k-1 in the i,j,kth equation of the system (1), for i=1,2,,N1, j=1,2,,N2 and k=1,2,,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: Bi,j,k must contain the coefficient of ti,j-1,k in the i,j,kth equation of the system (1), for i=1,2,,N1, j=1,2,,N2 and k=1,2,,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: Ci,j,k must contain the coefficient of ti-1,jk in the i,j,kth equation of the system (1), for i=1,2,,N1, j=1,2,,N2 and k=1,2,,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: Di,j,k must contain the coefficient of tijk (the ‘central’ term) in the i,j,kth equation of the system (1), for i=1,2,,N1, j=1,2,,N2 and k=1,2,,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 tijk=qijk. 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. Setting Di,j,k=0.0 at appropriate points, and the corresponding value of Qi,j,k to the appropriate value, namely the prescribed value of Ti,j,k in the Dirichlet case, or to zero at an external point.
10:   E(LDA,SDA,N3) – REAL (KIND=nag_wp) arrayInput
On entry: Ei,j,k must contain the coefficient of ti+1,jk in the i,j,kth equation of the system (1), for i=1,2,,N1, j=1,2,,N2 and k=1,2,,N3. The elements of E, for i=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: Fi,j,k must contain the coefficient of ti,j+1,k in the i,j,kth equation of the system (1), , for i=1,2,,N1, j=1,2,,N2 and k=1,2,,N3. The elements of F, for j=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: Gi,j,k must contain the coefficient of tij,k+1 in the i,j,kth equation of the system (1), for i=1,2,,N1, j=1,2,,N2 and k=1,2,,N3. The elements of G, for k=N3, must be zero after incorporating the boundary conditions, since they involve nodal values from outside the box.
13:   Q(LDA,SDA,N3) – REAL (KIND=nag_wp) arrayInput
On entry: Qi,j,k must contain qijk, for i=1,2,,N1, j=1,2,,N2 and k=1,2,,N3, i.e., the source-term values at the nodal points of the system (1).
14:   T(LDA,SDA,N3) – REAL (KIND=nag_wp) arrayInput/Output
On entry: Ti,j,k must contain the element tijk of an approximate solution to the equations, for i=1,2,,N1, j=1,2,,N2 and k=1,2,,N3.
If no better approximation is known, an array of zeros can be used.
On exit: the solution derived by the routine.
15:   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<APARAMN1-12+N2-12+N3-12/3.0.
16:   ITMAX – INTEGERInput
On entry: the maximum number of iterations to be used by the routine in seeking the solution. A reasonable value might be 20 for a problem with 3000 nodes and convergence criteria of about 10-3 of the original residual and change.
17:   ITCOUN – INTEGERInput/Output
On entry: on the first call of D03ECF, 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, N2 and N3 but possibly different coefficients and/or source terms, as occur with nonlinear systems or with time-dependent systems, ITCOUN should not be reset, i.e., it must contain the accumulated number of iterations. In this way a suitable cycling of the sequence of iteration parameters is obtained in the calls to D03UBF.
18:   ITUSED – INTEGEROutput
On exit: the number of iterations actually used on that call.
19:   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 problems to which an arbitrary constant can be added to the solution, for example Poisson's equation with all Neumann boundary conditions, NDIR should be set to 0 and the values of the next three parameters must be specified. For such problems the routine subtracts the value of the function derived at the node (IXN, IYN, IZN) from the whole solution after each iteration to reduce the possibility of large rounding errors. You must also ensure for such problems that the appropriate compatibility condition on the source terms Q is satisfied. See the comments at the end of Section 3.
20:   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.
21:   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.
22:   IZN – INTEGERInput
On entry: is ignored unless NDIR is equal to zero, in which case it must specify the third 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.
23:   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.
CONRES should not be less than a reasonable multiple of the machine precision.
24:   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. CONCHN should not be less than a reasonable multiple of the machine accuracy 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.
25:   RESIDS(ITMAX) – REAL (KIND=nag_wp) arrayOutput
On exit: the maximum absolute value of the residuals calculated at the ith iteration, for i=1,2,,ITUSED. If the residual of the solution is sought you must calculate this in the subroutine from which D03ECF is called. The sequence of values RESIDS indicates the rate of convergence.
26:   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 ith iteration, for i=1,2,,ITUSED. The sequence of values CHNGS indicates the rate of convergence.
27:   WRKSP1(LDA,SDA,N3) – REAL (KIND=nag_wp) arrayWorkspace
28:   WRKSP2(LDA,SDA,N3) – REAL (KIND=nag_wp) arrayWorkspace
29:   WRKSP3(LDA,SDA,N3) – REAL (KIND=nag_wp) arrayWorkspace
30:   WRKSP4(LDA,SDA,N3) – REAL (KIND=nag_wp) arrayWorkspace
31:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ 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​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, because for this routine the values of the output parameters may be useful even if IFAIL0 on exit, the recommended value is -1. 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).
Note: D03ECF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
IFAIL=1
On entry,N1<2,
orN2<2,
orN3<2.
IFAIL=2
On entry,LDA<N1,
orSDA<N2.
IFAIL=3
On entry,APARAM0.0.
IFAIL=4
On entry,APARAM>N1-12+N2-12+N3-12/3.0.
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 seven-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. The final accuracy obtained may be judged approximately from the rate of convergence determined from the sequence of values returned in the arrays RESIDS and CHNGS and the magnitude of the maximum absolute value of the change vector on the last iteration stored in CHNGSITUSED.

8  Further Comments

The time taken per iteration is approximately proportional to N1×N2×N3.
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 rectangular box with a non-uniform 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
e1.0+x/yn2×cos2y/yn2×e-1.0-z/yn2.
Note that this is the same problem as that solved in the example for D03UBF. 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 (d03ecfe.f90)

9.2  Program Data

Program Data (d03ecfe.d)

9.3  Program Results

Program Results (d03ecfe.r)

Produced by GNUPLOT 4.4 patchlevel 0 Example Program Solution in Y-Z Planes for x=6 u(x=6,y,z) 0 2 4 6 8 10 y 0 5 10 15 z 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Produced by GNUPLOT 4.4 patchlevel 0 0 0.5 1 1.5 2 0 2 4 6 8 10 u(x=X,y,z=0) y Solution Profiles u(x=X,y,z=0) for Four Values X= 0,1,3,6 z=0 x=0 x=1 x=3 x=6
Produced by GNUPLOT 4.4 patchlevel 0 0 0.1 0.2 0.3 0.4 0.5 0 2 4 6 8 10 u(x=X,y,z=0) y Solution Profiles u(x=X,y,z=15) for Four Values X=0,1,3,6 z=15 x=6 x=3 x=1 x=0

D03ECF (PDF version)
D03 Chapter Contents
D03 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012