3 Description

D02NBF is a general purpose routine for integrating the initial value problem for a stiff system of explicit ordinary differential equations,

y′=gt,y.

It is designed specifically for the case where the Jacobian ∂g∂y is a full matrix.

Both interval and step oriented modes of operation are available and also modes designed to permit intermediate output within an interval oriented mode.

An outline of a typical calling program for D02NBF is given below. It calls the full matrix linear algebra setup routine D02NSF, the Backward Differentiation Formula (BDF) integrator setup routine D02NVF, and its diagnostic counterpart D02NYF.

The linear algebra setup routine D02NSF and one of the integrator setup routines, D02NVF or D02NWF, must be called prior to the call of D02NBF. The integrator diagnostic routine D02NYF may be called after the call to D02NBF. There is also a routine, D02NZF, designed to permit you to change step size on a continuation call to D02NBF without restarting the integration process.

4 References

5 Parameters

On entry: a bound on the maximum number of differential equations to be solved during the integration.

Constraint:
LDYSAV≥NEQ.

3: T – REAL (KIND=nag_wp)Input/Output

On entry: t, the value of the independent variable. The input value of T is used only on the first call as the initial point of the integration.

On exit: the value at which the computed solution y is returned (usually at TOUT).

4: TOUT – REAL (KIND=nag_wp)Input

On entry: the next value of t at which a computed solution is desired. For the initial t, the input value of TOUT is used to determine the direction of integration. Integration is permitted in either direction (see also ITASK).

On entry: a value to indicate the form of the local error test. ITOL indicates to D02NBF whether to interpret either or both of RTOL or ATOL as a vector or a scalar. The error test to be satisfied is ei/wi<1.0, where wi is defined as follows:

On exit: you may set IRES as follows to indicate certain conditions in FCN to the integrator:

IRES=1

Indicates a normal return from FCN, that is IRES has not been altered by you and integration continues.

IRES=2

Indicates to the integrator that control should be passed back immediately to the calling (sub)program with the error indicator set to IFAIL=11.

IRES=3

Indicates to the integrator that an error condition has occurred in the solution vector, its time derivative or in the value of t. The integrator will use a smaller time step to try to avoid this condition. If this is not possible the integrator returns to the calling (sub)program with the error indicator set to IFAIL=7.

IRES=4

Indicates to the integrator to stop its current operation and to enter MONITR immediately with parameter IMON=-2.

FCN must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02NBF is called. Parameters denoted as Input must not be changed by this procedure.

On entry: the second dimension of the array YSAV as declared in the (sub)program from which D02NBF is called. An appropriate value for SDYSAV is described in the specification of the integrator setup routines D02NVF and D02NWF. This value must be the same as that supplied to the integrator setup routine.

15: JAC – SUBROUTINE, supplied by the NAG Library or the user.External Procedure

JAC must evaluate the Jacobian of the system. If this option is not required, the actual argument for JAC must be the dummy routine D02NBZ. (D02NBZ is included in the NAG Library.) You must indicate to the integrator whether this option is to be used by setting the parameter JCEVAL appropriately in a call to the full linear algebra setup routine D02NSF.

First we must define the system of nonlinear equations which is solved internally by the integrator. The time derivative, y′, generated internally, has the form

y′=y-z/hd,

where h is the current step size and d is a parameter that depends on the integration method in use. The vector y is the current solution and the vector z depends on information from previous time steps. This means that ddy′​ ​=hdddy​ ​. The system of nonlinear equations that is solved has the form

y′-gt,y=0

but it is solved in the form

rt,y=0,

where r is the function defined by

rt,y=hdy-z/hd-gt,y.

It is the Jacobian matrix ∂r∂y that you must supply in JAC as follows:

On entry: with IMON=1, ACORi1 contains the weight used for the ith equation when the norm is evaluated, and ACORi2 contains the estimated local error for the ith equation. The scaled local error at the end of a timestep may be obtained by calling the real function D02ZAF as follows:

On entry: a flag indicating under what circumstances MONITR was called:

IMON=-2

Entry from the integrator after IRES=4 (set in FCN) caused an early termination (this facility could be used to locate discontinuities).

IMON=-1

The current step failed repeatedly.

IMON=0

Entry after a call to the internal nonlinear equation solver (see INLN).

IMON=1

The current step was successful.

On exit: may be reset to determine subsequent action in D02NBF.

IMON=-2

Integration is to be halted. A return will be made from the integrator to the calling (sub)program with IFAIL=12.

IMON=-1

Allow the integrator to continue with its own internal strategy. The integrator will try up to three restarts unless IMON is set ≠-1 on exit.

IMON=0

Return to the internal nonlinear equation solver, where the action taken is determined by the value of INLN (see INLN).

IMON=1

Normal exit to the integrator to continue integration.

IMON=2

Restart the integration at the current time point. The integrator will restart from order 1 when this option is used. The solution Y, provided by MONITR, will be used for the initial conditions.

IMON=3

Try to continue with the same step size and order as was to be used before the call to MONITR. HMIN and HMAX may be altered if desired.

IMON=4

Continue the integration but using a new value of HNEXT and possibly new values of HMIN and HMAX.

12: INLN – INTEGEROutput

On exit: the action to be taken by the internal nonlinear equation solver when MONITR is exited with IMON=0. By setting INLN=3 and returning to the integrator, the residual vector is evaluated and placed in the array R, and then MONITR is called again. At present this is the only option available: INLN must not be set to any other value.

13: HMIN – REAL (KIND=nag_wp)Input/Output

On entry: the minimum step size to be taken on the next step.

On exit: the minimum step size to be used. If this is different from the input value, then IMON must be set to 3 or 4.

14: HMAX – REAL (KIND=nag_wp)Input/Output

On entry: the maximum step size to be taken on the next step.

On exit: the maximum step size to be used. If this is different from the input value, then IMON must be set to 3 or 4. If HMAX is set to zero, no limit is assumed.

15: NQU – INTEGERInput

On entry: the order of the integrator used on the last step. This is supplied to enable you to carry out interpolation using either of the routines D02XJF or D02XKF.

MONITR must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02NBF is called. Parameters denoted as Input must not be changed by this procedure.

19: ITASK – INTEGERInput

On entry: the task to be performed by the integrator.

ITASK=1

Normal computation of output values of yt at t=TOUT (by overshooting and interpolating).

ITASK=2

Take one step only and return.

ITASK=3

Stop at the first internal integration point at or beyond t=TOUT and return.

ITASK=4

Normal computation of output values of yt at t=TOUT but without overshooting t=TCRIT (e.g., see D02MVF). TCRIT must be specified as an option in one of the integrator setup routines before the first call to the integrator, or specified in the optional input routine before a continuation call. TCRIT may be equal to or beyond TOUT, but not before it, in the direction of integration.

ITASK=5

Take one step only and return, without passing TCRIT (e.g., see D02MVF). TCRIT must be specified as under ITASK=4.

Constraint:
ITASK=1, 2, 3, 4 or 5.

20: ITRACE – INTEGERInput

On entry: the level of output that is printed by the integrator. ITRACE may take the value -1, 0, 1, 2 or 3.

ITRACE<-1

-1 is assumed and similarly if ITRACE>3, then 3 is assumed.

ITRACE=-1

No output is generated.

ITRACE=0

Only warning messages are printed on the current error message unit (see X04AAF).

ITRACE>0

Warning messages are printed as above, and on the current advisory message unit (see X04ABF) output is generated which details Jacobian entries, the nonlinear iteration and the time integration. The advisory messages are given in greater detail the larger the value of ITRACE.

21: 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 IFAIL≠0 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).

Errors or warnings detected by the routine:

IFAIL=1

An illegal input was detected on entry, or after an internal call to MONITR. If ITRACE>-1, then the form of the error will be detailed on the current error message unit (see X04AAF).

IFAIL=2

The maximum number of steps specified has been taken (see the description of optional inputs in the integrator setup routines and the optional input continuation routine, D02NZF).

IFAIL=3

With the given values of RTOL and ATOL no further progress can be made across the integration range from the current point T. The components Y1,Y2,…,YNEQ contain the computed values of the solution at the current point T.

IFAIL=4

There were repeated error test failures on an attempted step, before completing the requested task, but the integration was successful as far as T. The problem may have a singularity, or the local error requirements may be inappropriate.

IFAIL=5

There were repeated convergence test failures on an attempted step, before completing the requested task, but the integration was successful as far as T. This may be caused by an inaccurate Jacobian matrix or one which is incorrectly computed.

IFAIL=6

Some error weight wi became zero during the integration (see the description of ITOL). Pure relative error control (ATOLi=0.0) was requested on a variable (the ith) which has now vanished. The integration was successful as far as T.

IFAIL=7

FCN set its error flag (IRES=3) continually despite repeated attempts by the integrator to avoid this.

IFAIL=8

Not used for this integrator.

IFAIL=9

A singular Jacobian ∂r∂y has been encountered. This error exit is unlikely to be taken when solving explicit ordinary differential equations. You should check the problem formulation and Jacobian calculation.

IFAIL=10

An error occurred during Jacobian formulation or back-substitution (a more detailed error description may be directed to the current error message unit, see X04AAF).

IFAIL=11

FCN signalled the integrator to halt the integration and return (IRES=2). Integration was successful as far as T.

IFAIL=12

MONITR set IMON=-2 and so forced a return but the integration was successful as far as T.

IFAIL=13

The requested task has been completed, but it is estimated that a small change in RTOL and ATOL is unlikely to produce any change in the computed solution. (Only applies when you are not operating in one step mode, that is when ITASK≠2 or 5.)

IFAIL=14

The values of RTOL and ATOL are so small that D02NBF is unable to start the integration.

IFAIL=15

The linear algebra setup routine D02NSF was not called prior to calling D02NBF.

7 Accuracy

The accuracy of the numerical solution may be controlled by a careful choice of the parameters RTOL and ATOL, and to a much lesser extent by the choice of norm. You are advised to use scalar error control unless the components of the solution are expected to be poorly scaled. For the type of decaying solution typical of many stiff problems, relative error control with a small absolute error threshold will be most appropriate (that is, you are advised to choose ITOL=1 with ATOL1 small but positive).

8 Further Comments

The cost of computing a solution depends critically on the size of the differential system and to a lesser extent on the degree of stiffness of the problem. For D02NBF the cost is proportional to NEQ3, though for problems which are only mildly nonlinear the cost may be dominated by factors proportional to NEQ2 except for very large problems.

In general, you are advised to choose the Backward Differentiation Formula option (setup routine D02NVF) but if efficiency is of great importance and especially if it is suspected that ∂g∂y has complex eigenvalues near the imaginary axis for some part of the integration, you should try the BLEND option (setup routine D02NWF).

9 Example

This example solves the well-known stiff Robertson problem

a′=-0.04a+1.0E4bcb′=0.04a-1.0E4bc-3.0E7⁢b2c′=3.0E7⁢b2

over the range 0,10 with initial conditions a=1.0 and b=c=0.0 using scalar error control (ITOL=1) and computation of the solution at TOUT=10.0 with TCRIT (e.g., see D02MVF) set to 10.0 (ITASK=4). D02NBY is used for MONITR, a BDF integrator (setup routine D02NVF) is used and a modified Newton method is selected. This example illustrates the use of both a numerical and an analytical Jacobian.