NAG Library Routine Document

d02nbf  (ivp_stiff_exp_fulljac)

 Contents

    1  Purpose
    7  Accuracy

1
Purpose

d02nbf is a direct communication routine for integrating stiff systems of explicit ordinary differential equations when the Jacobian is a full matrix.

2
Specification

Fortran Interface
Subroutine d02nbf ( neq, ldysav, t, tout, y, ydot, rwork, rtol, atol, itol, inform, fcn, ysav, sdysav, jac, wkjac, nwkjac, monitr, itask, itrace, ifail)
Integer, Intent (In):: neq, ldysav, itol, sdysav, nwkjac, itask, itrace
Integer, Intent (Inout):: inform(23), ifail
Real (Kind=nag_wp), Intent (In):: tout, rtol(*), atol(*)
Real (Kind=nag_wp), Intent (Inout):: t, y(neq), rwork(50+4*neq), ysav(ldysav,sdysav), wkjac(nwkjac)
Real (Kind=nag_wp), Intent (Out):: ydot(neq)
External:: fcn, jac, monitr
C Header Interface
#include nagmk26.h
void  d02nbf_ ( const Integer *neq, const Integer *ldysav, double *t, const double *tout, double y[], double ydot[], double rwork[], const double rtol[], const double atol[], const Integer *itol, Integer inform[],
void (NAG_CALL *fcn)( const Integer *neq, const double *t, const double y[], double f[], Integer *ires),
double ysav[], const Integer *sdysav,
void (NAG_CALL *jac)( const Integer *neq, const double *t, const double y[], const double *h, const double *d, double p[]),
double wkjac[], const Integer *nwkjac,
void (NAG_CALL *monitr)( const Integer *neq, const Integer *ldysav, const double *t, const double *hlast, double *hnext, double y[], const double ydot[], const double ysav[], const double r[], const double acor[], Integer *imon, Integer *inln, double *hmin, double *hmax, const Integer *nqu),
const Integer *itask, const Integer *itrace, Integer *ifail)

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.
!     Declarations

      External fcn, jac, monitr
          .
          .
          .
      ifail = 0
      Call d02nvf(...,ifail)
      Call d02nsf(neq, ldysav, jceval, nwkjac, rwork, ifail)
      ifail = -1
      Call d02nbf(neq, ldysav, t, tout, y, ydot, rwork, rtol,       &
        atol, itol, inform, fcn, ysave, sdysav, jac, wkjac, nwkjac, &
        monitr, itask, itrace, ifail)
      If (ifail.eq.1 .or. ifail.ge.14) Stop
      ifail = 0
      Call d02nyf(...)
          .
          .
          .
      Stop
      End
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

See the D02M–N Sub-chapter Introduction.

5
Arguments

1:     neq – IntegerInput
On entry: the number of differential equations to be solved.
Constraint: neq1.
2:     ldysav – IntegerInput
On entry: a bound on the maximum number of differential equations to be solved during the integration.
Constraint: ldysavneq.
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).
Constraint: toutt.
5:     yneq – Real (Kind=nag_wp) arrayInput/Output
On entry: the values of the dependent variables (solution). On the first call the first neq elements of y must contain the vector of initial values.
On exit: the computed solution vector, evaluated at t (usually t=tout).
6:     ydotneq – Real (Kind=nag_wp) arrayOutput
On exit: the time derivatives y of the vector y at the last integration point.
7:     rwork50+4×neq – Real (Kind=nag_wp) arrayCommunication Array
8:     rtol* – Real (Kind=nag_wp) arrayInput
Note: the dimension of the array rtol must be at least 1 if itol=1 or 2, and at least neq otherwise.
On entry: the relative local error tolerance.
Constraint: rtoli0.0 for all relevant i (see itol).
9:     atol* – Real (Kind=nag_wp) arrayInput
Note: the dimension of the array atol must be at least 1 if itol=1 or 3, and at least neq otherwise.
On entry: the absolute local error tolerance.
Constraint: atoli0.0 for all relevant i (see itol).
10:   itol – IntegerInput
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:
itol rtol atol wi
1 scalar scalar rtol1×yi+atol1
2 scalar vector rtol1×yi+atoli
3 vector scalar rtoli×yi+atol1
4 vector vector rtoli×yi+atoli
ei is an estimate of the local error in yi, computed internally, and the choice of norm to be used is defined by a previous call to an integrator setup routine.
Constraint: itol=1, 2, 3 or 4.
11:   inform23 – Integer arrayCommunication Array
12:   fcn – Subroutine, supplied by the user.External Procedure
fcn must evaluate the derivative vector for the explicit ordinary differential equation system, defined by y=gt,y.
The specification of fcn is:
Fortran Interface
Subroutine fcn ( neq, t, y, f, ires)
Integer, Intent (In):: neq
Integer, Intent (Inout):: ires
Real (Kind=nag_wp), Intent (In):: t, y(neq)
Real (Kind=nag_wp), Intent (Out):: f(neq)
C Header Interface
#include nagmk26.h
void  fcn ( const Integer *neq, const double *t, const double y[], double f[], Integer *ires)
1:     neq – IntegerInput
On entry: the number of differential equations being solved.
2:     t – Real (Kind=nag_wp)Input
On entry: t, the current value of the independent variable.
3:     yneq – Real (Kind=nag_wp) arrayInput
On entry: the value of yi, for i=1,2,,neq.
4:     fneq – Real (Kind=nag_wp) arrayOutput
On exit: the value yi, given by yi=git,y, for i=1,2,,neq.
5:     ires – IntegerInput/Output
On entry: ires=1.
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 argument imon=-2.
fcn must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d02nbf is called. Arguments denoted as Input must not be changed by this procedure.
Note: fcn should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02nbf. If your code inadvertently does return any NaNs or infinities, d02nbf is likely to produce unexpected results.
13:   ysavldysavsdysav – Real (Kind=nag_wp) arrayCommunication Array
14:   sdysav – IntegerInput
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 argument 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 an argument 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 d dy ​ ​ = hd d dy ​ ​ . The system of nonlinear equations that is solved has the form
y - g t,y = 0  
but it is solved in the form
r t,y = 0 ,  
where r is the function defined by
r t,y =hd y-z / hd - g t,y .  
It is the Jacobian matrix r y  that you must supply in jac as follows:
ri yj =1-hd gi yj , if ​i=j, ri yj = -hd gi yj , otherwise.  
The specification of jac is:
Fortran Interface
Subroutine jac ( neq, t, y, h, d, p)
Integer, Intent (In):: neq
Real (Kind=nag_wp), Intent (In):: t, y(neq), h, d
Real (Kind=nag_wp), Intent (Inout):: p(neq,neq)
C Header Interface
#include nagmk26.h
void  jac ( const Integer *neq, const double *t, const double y[], const double *h, const double *d, double p[])
1:     neq – IntegerInput
On entry: the number of differential equations being solved.
2:     t – Real (Kind=nag_wp)Input
On entry: t, the current value of the independent variable.
3:     yneq – Real (Kind=nag_wp) arrayInput
On entry: yi, for i=1,2,,neq, the current solution component.
4:     h – Real (Kind=nag_wp)Input
On entry: the current step size.
5:     d – Real (Kind=nag_wp)Input
On entry: the argument d which depends on the integration method.
6:     pneqneq – Real (Kind=nag_wp) arrayInput/Output
On entry: is set to zero.
On exit: pij must contain ri yj , for i=1,2,,neq and j=1,2,,neq.
Only the nonzero elements of this array need be set, since it is preset to zero before the call to jac.
jac must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d02nbf is called. Arguments denoted as Input must not be changed by this procedure.
Note: jac should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02nbf. If your code inadvertently does return any NaNs or infinities, d02nbf is likely to produce unexpected results.
16:   wkjacnwkjac – Real (Kind=nag_wp) arrayCommunication Array
17:   nwkjac – IntegerInput
On entry: the dimension of the array wkjac as declared in the (sub)program from which d02nbf is called. This value must be the same as that supplied to the linear algebra setup routine d02nsf.
Constraint: nwkjacldysav×ldysav+1.
18:   monitr – Subroutine, supplied by the NAG Library or the user.External Procedure
monitr performs tasks requested by you. If this option is not required, the actual argument for monitr must be the dummy routine d02nby. (d02nby is included in the NAG Library.)
The specification of monitr is:
Fortran Interface
Subroutine monitr ( neq, ldysav, t, hlast, hnext, y, ydot, ysav, r, acor, imon, inln, hmin, hmax, nqu)
Integer, Intent (In):: neq, ldysav, nqu
Integer, Intent (Inout):: imon
Integer, Intent (Out):: inln
Real (Kind=nag_wp), Intent (In):: t, hlast, ydot(neq), ysav(ldysav,*), r(neq), acor(neq,2)
Real (Kind=nag_wp), Intent (Inout):: hnext, y(neq), hmin, hmax
C Header Interface
#include nagmk26.h
void  monitr ( const Integer *neq, const Integer *ldysav, const double *t, const double *hlast, double *hnext, double y[], const double ydot[], const double ysav[], const double r[], const double acor[], Integer *imon, Integer *inln, double *hmin, double *hmax, const Integer *nqu)
1:     neq – IntegerInput
On entry: the number of differential equations being solved.
2:     ldysav – IntegerInput
On entry: an upper bound on the number of differential equations to be solved.
3:     t – Real (Kind=nag_wp)Input
On entry: the current value of the independent variable.
4:     hlast – Real (Kind=nag_wp)Input
On entry: the last step size successfully used by the integrator.
5:     hnext – Real (Kind=nag_wp)Input/Output
On entry: the step size that the integrator proposes to take on the next step.
On exit: the next step size to be used. If this is different from the input value, imon must be set to 4.
6:     yneq – Real (Kind=nag_wp) arrayInput/Output
On entry: y, the values of the dependent variables evaluated at t.
On exit: these values must not be changed unless imon is set to 2.
7:     ydotneq – Real (Kind=nag_wp) arrayInput
On entry: the time derivatives y of the vector y.
8:     ysavldysav* – Real (Kind=nag_wp) arrayInput
Note: the second dimension of ysav is sdysav as in the call of d02nbf.
On entry: workspace to enable you to carry out interpolation using either of the routines d02xjf or d02xkf.
9:     rneq – Real (Kind=nag_wp) arrayInput
On entry: if imon=0 and inln=3, the first neq elements contain the residual vector, y-gt,y.
10:   acorneq2 – Real (Kind=nag_wp) arrayInput
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:
ifail = 1
errloc = d02zaf(neq, acor(1,2), acor(1,1), ifail)
! CHECK IFAIL BEFORE PROCEEDING
11:   imon – IntegerInput/Output
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, 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, 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. Arguments denoted as Input must not be changed by this procedure.
Note: monitr should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02nbf. If your code inadvertently does return any NaNs or infinities, d02nbf is likely to produce unexpected results.
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, 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 argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation 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 arguments 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).
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, 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 itask2 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.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

7
Accuracy

The accuracy of the numerical solution may be controlled by a careful choice of the arguments 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
Parallelism and Performance

d02nbf is not thread safe and should not be called from a multithreaded user program. Please see Section 3.12.1 in How to Use the NAG Library and its Documentation for more information on thread safety.
d02nbf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
d02nbf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9
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).

10
Example

This example solves the well-known stiff Robertson problem
a = -0.04a + 1.0E4bc b = 0.04a - 1.0E4bc - 3.0E7b2 c = 3.0E7b2  
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.

10.1
Program Text

Program Text (d02nbfe.f90)

10.2
Program Data

Program Data (d02nbfe.d)

10.3
Program Results

Program Results (d02nbfe.r)

GnuplotProduced by GNUPLOT 4.6 patchlevel 3 0 0.2 0.4 0.6 0.8 1 1e−10 1e−08 1e−06 0.0001 0.01 1 -1e−05 0 1e−05 2e−05 3e−05 4e−05 5e−05 6e−05 Solution (a,c) Solution (b) x(logscale) Example Program Stiff Explicit ODE, Full Jacobian Stiff Robertson Problem (BDF integrator) a b c gnuplot_plot_1 gnuplot_plot_2 gnuplot_plot_3
© The Numerical Algorithms Group Ltd, Oxford, UK. 2017