NAG Library Routine Document
D02NNF
1 Purpose
D02NNF is a reverse communication routine for integrating stiff systems of implicit ordinary differential equations coupled with algebraic equations.
2 Specification
SUBROUTINE D02NNF ( 
NEQ, LDYSAV, T, TOUT, Y, YDOT, RWORK, RTOL, ATOL, ITOL, INFORM, YSAV, SDYSAV, WKJAC, NWKJAC, JACPVT, NJCPVT, IMON, INLN, IRES, IREVCM, LDERIV, ITASK, ITRACE, IFAIL) 
INTEGER 
NEQ, LDYSAV, ITOL, INFORM(23), SDYSAV, NWKJAC, JACPVT(NJCPVT), NJCPVT, IMON, INLN, IRES, IREVCM, ITASK, ITRACE, IFAIL 
REAL (KIND=nag_wp) 
T, TOUT, Y(NEQ), YDOT(NEQ), RWORK(50+4*NEQ), RTOL(*), ATOL(*), YSAV(LDYSAV,SDYSAV), WKJAC(NWKJAC) 
LOGICAL 
LDERIV(2) 

3 Description
D02NNF is a general purpose routine for integrating the initial value problem for a stiff system of implicit ordinary differential equations coupled with algebraic equations, written in the form
An outline of a typical calling program is given below:
! Declarations
call linear algebra setup routine
call integrator setup routine
IREVCM=0
1000 CALL D02NNF(NEQ, NEQMAX, T, TOUT, Y, YDOT, RWORK, RTOL,
ATOL, ITOL, INFORM, YSAVE, NY2DIM, WKJAC, NWKJAC, JACPVT,
NJCPVT, IMON, INLN, IRES, IREVCM, LDERIV,
ITASK, ITRACE, IFAIL)
IF (IREVCM.GT.0) THEN
IF (IREVCM.GT.7 .AND. IREVCM.LT.11) THEN
IF (IREVCM.EQ.8) THEN
supply the Jacobian matrix (i)
ELSE IF (IREVCM.EQ.9) THEN
perform monitoring tasks requested by the user (ii)
ELSE IF (IREVCM.EQ.10) THEN
indicates an unsuccessful step
END IF
ELSE
evaluate the residual (iii)
ENDIF
GO TO 1000
END IF
! post processing (optional linear algebra diagnostic call
! (sparse case only), optional integrator diagnostic call)
STOP
END
There are three major operations that may be required of the calling subroutine on an intermediate return (
${\mathbf{IREVCM}}\ne 0$) from D02NNF; these are denoted
(i),
(ii) and
(iii).
The following sections describe in greater detail exactly what is required of each of these operations.
(i) 
Supply the Jacobian matrix
You need only provide this facility if the argument ${\mathbf{JCEVAL}}=\text{'A'}$ (or ${\mathbf{JCEVAL}}=\text{'F'}$ if using sparse matrix linear algebra) in a call to the linear algebra setup routine (see JCEVAL in D02NUF). If the Jacobian matrix is to be evaluated numerically by the integrator, then the remainder of section (i) can be ignored. We must define the system of nonlinear equations which is solved internally by the integrator. The time derivative, ${y}^{\prime}$, has the form
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 $\frac{d}{d{y}^{\prime}}\left(\text{}\right)=\left(hd\right)\frac{d}{dy}\left(\text{}\right)$.
The system of nonlinear equations that is solved has the form
but is solved in the form
where $f$ is the function defined by
It is the Jacobian matrix $\frac{\partial r}{\partial y}$ that you must supply as follows:
where $t$, $h$ and $d$ are located in ${\mathbf{RWORK}}\left(19\right)$, ${\mathbf{RWORK}}\left(16\right)$ and ${\mathbf{RWORK}}\left(20\right)$ respectively and the arrays Y and YDOT contain the current solution and time derivatives respectively. Only the nonzero elements of the Jacobian need be set, since the locations where it is to be stored are preset to zero.
Hereafter in this document this operation will be referred to as JAC. 
(ii) 
Perform tasks requested by you
This operation is essentially a monitoring function and additionally provides the opportunity of changing the current values of Y, YDOT, HNEXT (the step size that the integrator proposes to take on the next step), HMIN (the minimum step size to be taken on the next step), and HMAX (the maximum step size to be taken on the next step).
The scaled local error at the end of a time step may be obtained by calling the real function D02ZAF as follows:
IFAIL = 1
ERRLOC = D02ZAF(NEQ,ROWK(51+NEQMAX),RWORK(51),IFAIL)
! CHECK IFAIL BEFORE PROCEEDING
The following gives details of the location within the array RWORK of variables that may be of interest to you:
Variable 
Specification 
Location 
TCURR 
the current value of the independent variable 
${\mathbf{RWORK}}\left(19\right)$ 
HLAST 
last step size successfully used by the integrator 
${\mathbf{RWORK}}\left(15\right)$ 
HNEXT 
step size that the integrator proposes to take on the next step 
${\mathbf{RWORK}}\left(16\right)$ 
HMIN 
minimum step size to be taken on the next step 
${\mathbf{RWORK}}\left(17\right)$ 
HMAX 
maximum step size to be taken on the next step 
${\mathbf{RWORK}}\left(18\right)$ 
NQU 
the order of the integrator used on the last step 
${\mathbf{RWORK}}\left(10\right)$ 
You are advised to consult the description of
MONITR in D02NGF
for details on what optional input can be made.
If either Y or YDOT are changed, then IMON must be set to $2$ before return to D02NNF. If either of the values HMIN or HMAX are changed, then IMON must be set $\text{}\ge 3$ before return to D02NNF. If HNEXT is changed, then IMON must be set to $4$ before return to D02NNF.
In addition you can force D02NNF to evaluate the residual vector
by setting ${\mathbf{IMON}}=0$ and ${\mathbf{INLN}}=3$ and then returning to D02NNF; on return to this monitoring operation the residual vector will be stored in
${\mathbf{RWORK}}\left(50+2\times {\mathbf{NEQ}}+\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{NEQ}}$.
Hereafter in this document this operation will be referred to as MONITR. 
(iii) 
Evaluate the residual
This operation must evaluate the residual
in one case and the reduced residual
in another, where $t$ is located in ${\mathbf{RWORK}}\left(19\right)$. The form of the residual that is returned is determined by the value of IRES returned by D02NNF. If ${\mathbf{IRES}}=1$, then the residual defined by equation (2) above must be returned; if ${\mathbf{IRES}}=1$, then the residual returned by equation (1) above must be returned.
Hereafter in this document this operation will be referred to as RESID. 
4 References
5 Arguments
Note: this routine uses
reverse communication. Its use involves an initial entry, intermediate exits and reentries, and a final exit, as indicated by the argument
IREVCM. Between intermediate exits and reentries,
all arguments other than YDOT, RWORK, WKJAC, IMON, INLN and IRES must remain unchanged.
 1: $\mathrm{NEQ}$ – INTEGERInput

On initial entry: the number of equations to be solved.
Constraint:
${\mathbf{NEQ}}\ge 1$.
 2: $\mathrm{LDYSAV}$ – INTEGERInput

On initial entry: a bound on the maximum number of equations to be solved during the integration.
Constraint:
${\mathbf{LDYSAV}}\ge {\mathbf{NEQ}}$.
 3: $\mathrm{T}$ – REAL (KIND=nag_wp)Input/Output

On initial 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 final exit: the value at which the computed solution
$y$ is returned (usually at
TOUT).
 4: $\mathrm{TOUT}$ – REAL (KIND=nag_wp)Input/Output

On initial 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:
${\mathbf{TOUT}}\ne {\mathbf{T}}$.
On exit: is unaltered unless
${\mathbf{ITASK}}=6$ and
${\mathbf{LDERIV}}\left(2\right)=\mathrm{.TRUE.}$ on entry (see also
ITASK and
LDERIV) in which case
TOUT will be set to the result of taking a small step at the start of the integration.
 5: $\mathrm{Y}\left({\mathbf{NEQ}}\right)$ – REAL (KIND=nag_wp) arrayInput/Output

On initial 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 final exit: the computed solution vector evaluated at
T (usually
$t={\mathbf{TOUT}}$).
 6: $\mathrm{YDOT}\left({\mathbf{NEQ}}\right)$ – REAL (KIND=nag_wp) arrayInput/Output

On initial entry: if
${\mathbf{LDERIV}}\left(1\right)=\mathrm{.TRUE.}$,
YDOT must contain approximations to the time derivatives
${y}^{\prime}$ of the vector
$y$. If
${\mathbf{LDERIV}}\left(1\right)=\mathrm{.FALSE.}$, then
YDOT need not be set on entry.
On final exit: contains the time derivatives ${y}^{\prime}$ of the vector $y$ at the last integration point.
 7: $\mathrm{RWORK}\left(50+4\times {\mathbf{NEQ}}\right)$ – REAL (KIND=nag_wp) arrayCommunication Array

On initial entry: must be the same array as used by one of the method setup routines
D02MVF,
D02NVF or
D02NWF, and by one of the storage setup routines
D02NSF,
D02NTF or
D02NUF. The contents of
RWORK must not be changed between any call to a setup routine and the first call to D02NNF.
On intermediate reentry: must contain residual evaluations as described under the argument
IREVCM.
On intermediate exit:
contains information for JAC, RESID and MONITR operations as described under
Section 3 and the argument
IREVCM.
 8: $\mathrm{RTOL}\left(*\right)$ – REAL (KIND=nag_wp) arrayInput

Note: the dimension of the array
RTOL
must be at least
$1$ if
${\mathbf{ITOL}}=1$ or
$2$, and at least
${\mathbf{NEQ}}$ otherwise.
On initial entry: the relative local error tolerance.
Constraint:
${\mathbf{RTOL}}\left(i\right)\ge 0.0$ for all relevant
$i$ (see
ITOL).
 9: $\mathrm{ATOL}\left(*\right)$ – REAL (KIND=nag_wp) arrayInput

Note: the dimension of the array
ATOL
must be at least
$1$ if
${\mathbf{ITOL}}=1$ or
$3$, and at least
${\mathbf{NEQ}}$ otherwise.
On initial entry: the absolute local error tolerance.
Constraint:
${\mathbf{ATOL}}\left(i\right)\ge 0.0$ for all relevant
$i$ (see
ITOL).
 10: $\mathrm{ITOL}$ – INTEGERInput

On initial entry: a value to indicate the form of the local error test.
ITOL indicates to D02NNF whether to interpret either or both of
RTOL or
ATOL as a vector or a scalar. The error test to be satisfied is
$\Vert {e}_{i}/{w}_{i}\Vert <1.0$, where
${w}_{i}$ is defined as follows:
ITOL  RTOL  ATOL  ${w}_{i}$ 
1  scalar  scalar  ${\mathbf{RTOL}}\left(1\right)\times \left{y}_{i}\right+{\mathbf{ATOL}}\left(1\right)$ 
2  scalar  vector  ${\mathbf{RTOL}}\left(1\right)\times \left{y}_{i}\right+{\mathbf{ATOL}}\left(i\right)$ 
3  vector  scalar  ${\mathbf{RTOL}}\left(i\right)\times \left{y}_{i}\right+{\mathbf{ATOL}}\left(1\right)$ 
4  vector  vector  ${\mathbf{RTOL}}\left(i\right)\times \left{y}_{i}\right+{\mathbf{ATOL}}\left(i\right)$ 
${e}_{i}$ is an estimate of the local error in ${y}_{i}$, computed internally, and the choice of norm to be used is defined by a previous call to an integrator setup routine.
Constraint:
${\mathbf{ITOL}}=1$, $2$, $3$ or $4$.
 11: $\mathrm{INFORM}\left(23\right)$ – INTEGER arrayCommunication Array

 12: $\mathrm{YSAV}\left({\mathbf{LDYSAV}},{\mathbf{SDYSAV}}\right)$ – REAL (KIND=nag_wp) arrayCommunication Array

 13: $\mathrm{SDYSAV}$ – INTEGERInput

On initial entry: the second dimension of the array
YSAV as declared in the (sub)program from which D02NNF is called. An appropriate value for
SDYSAV is described in the specifications of the integrator setup routines
D02MVF,
D02NVF and
D02NWF. This value must be the same as that supplied to the integrator setup routine.
 14: $\mathrm{WKJAC}\left({\mathbf{NWKJAC}}\right)$ – REAL (KIND=nag_wp) arrayInput/Output

On intermediate reentry: elements of the Jacobian as defined under the description of
IREVCM. If a numerical Jacobian was requested then
WKJAC is used for workspace.
On intermediate exit:
the Jacobian is overwritten.
 15: $\mathrm{NWKJAC}$ – INTEGERInput

On initial entry: the dimension of the array
WKJAC as declared in the (sub)program from which D02NNF is called. The actual size depends on the linear algebra method used. An appropriate value for
NWKJAC is described in the specifications of the linear algebra setup routines
D02NSF,
D02NTF and
D02NUF for full, banded and sparse matrix linear algebra respectively. This value must be the same as that supplied to the linear algebra setup routine.
 16: $\mathrm{JACPVT}\left({\mathbf{NJCPVT}}\right)$ – INTEGER arrayCommunication Array
 17: $\mathrm{NJCPVT}$ – INTEGERInput

On initial entry: the dimension of the array
JACPVT as declared in the (sub)program from which D02NNF is called. The actual size depends on the linear algebra method used. An appropriate value for
NJCPVT is described in the specifications of the linear algebra setup routines
D02NTF and
D02NUF for banded and sparse matrix linear algebra respectively. This value must be the same as that supplied to the linear algebra setup routine. When full matrix linear algebra is chosen, the array
JACPVT is not used and hence
NJCPVT should be set to
$1$.
 18: $\mathrm{IMON}$ – INTEGERInput/Output

On intermediate exit:
used to pass information between D02NNF and the MONITR operation (see
Section 3). With
${\mathbf{IREVCM}}=9$,
IMON contains a flag indicating under what circumstances the return from D02NNF occurred:
 ${\mathbf{IMON}}=2$
 Exit from D02NNF after ${\mathbf{IRES}}=4$ (set in the RESID operation (see Section 3) caused an early termination (this facility could be used to locate discontinuities).
 ${\mathbf{IMON}}=1$
 The current step failed repeatedly.
 ${\mathbf{IMON}}=0$
 Exit from D02NNF after a call to the internal nonlinear equation solver.
 ${\mathbf{IMON}}=1$
 The current step was successful.
On intermediate reentry: may be reset to determine subsequent action in D02NNF.
 ${\mathbf{IMON}}=2$
 Integration is to be halted. A return will be made from D02NNF to the calling (sub)program with ${\mathbf{IFAIL}}={\mathbf{12}}$.
 ${\mathbf{IMON}}=1$
 Allow D02NNF to continue with its own internal strategy. The integrator will try up to three restarts unless ${\mathbf{IMON}}\ne 1$.
 ${\mathbf{IMON}}=0$
 Return to the internal nonlinear equation solver, where the action taken is determined by the value of INLN.
 ${\mathbf{IMON}}=1$
 Normal exit to D02NNF to continue integration.
 ${\mathbf{IMON}}=2$
 Restart the integration at the current time point. The integrator will restart from order $1$ when this option is used. The internal initialization module solves for new values of $y$ and ${y}^{\prime}$ by using the values supplied in Y and YDOT by the MONITR operation (see Section 3) as initial estimates.
 ${\mathbf{IMON}}=3$
 Try to continue with the same step size and order as was to be used before entering the MONITR operation (see Section 3). HMIN and HMAX may be altered if desired.
 ${\mathbf{IMON}}=4$
 Continue the integration but using a new value of HNEXT and possibly new values of HMIN and HMAX.
 19: $\mathrm{INLN}$ – INTEGERInput/Output

On intermediate reentry: with
${\mathbf{IMON}}=0$ and
${\mathbf{IREVCM}}=9$,
INLN specifies the action to be taken by the internal nonlinear equation solver. By setting
${\mathbf{INLN}}=3$ and returning to D02NNF, the residual vector is evaluated and placed in
${\mathbf{RWORK}}\left(50+2\times {\mathbf{NEQ}}+\mathit{i}\right)$, for
$\mathit{i}=1,2,\dots ,{\mathbf{NEQ}}$ and then the MONITR operation (see
Section 3) is invoked again. At present this is the only option available:
INLN must not be set to any other value.
On intermediate exit:
contains a flag indicating the action to be taken, if any, by the internal nonlinear equation solver.
 20: $\mathrm{IRES}$ – INTEGERInput/Output

On intermediate exit:
with
${\mathbf{IREVCM}}=1$,
$2$,
$3$,
$4$,
$5$,
$6$,
$7$ or
$11$,
IRES specifies the form of the residual to be returned by the RESID operation (see
Section 3).
If ${\mathbf{IRES}}=1$, then $r=g\left(t,y\right)A\left(t,y\right){y}^{\prime}$ must be returned.
If ${\mathbf{IRES}}=1$, then $\hat{r}=A\left(t,y\right){y}^{\prime}$ must be returned.
On intermediate reentry: should be unchanged unless one of the following actions is required of D02NNF in which case
IRES should be set accordingly.
 ${\mathbf{IRES}}=2$
 Indicates to D02NNF that control should be passed back immediately to the calling (sub)program with the error indicator set to ${\mathbf{IFAIL}}={\mathbf{11}}$.
 ${\mathbf{IRES}}=3$
 Indicates to D02NNF 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 D02NNF returns to the calling (sub)program with the error indicator set to ${\mathbf{IFAIL}}={\mathbf{7}}$.
 ${\mathbf{IRES}}=4$
 Indicates to D02NNF to stop its current operation and to enter the MONITR operation (see Section 3) immediately.
 21: $\mathrm{IREVCM}$ – INTEGERInput/Output

On initial entry: must contain $0$.
On intermediate reentry: should remain unchanged.
On intermediate exit:
indicates what action you must take before reentering D02NNF. The possible exit values of
IREVCM are
$1$,
$2$,
$3$,
$4$,
$5$,
$6$,
$7$,
$8$,
$9$,
$10$ or
$11$ which should be interpreted as follows:
 ${\mathbf{IREVCM}}=1$, $2$, $3$, $4$, $5$, $6$, $7$ or $11$
 Indicates that a RESID operation (see Section 3) is required: you must supply the residual of the system. For each of these values of IREVCM,
${y}_{\mathit{i}}$ is located in ${\mathbf{Y}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{NEQ}}$.
For ${\mathbf{IREVCM}}=1$, $3$, $6$ or $11$,
${y}_{\mathit{i}}^{\prime}$ is located in ${\mathbf{YDOT}}\left(\mathit{i}\right)$ and ${r}_{\mathit{i}}$ should be stored in ${\mathbf{RWORK}}\left(50+2\times {\mathbf{NEQ}}+\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{NEQ}}$.
For ${\mathbf{IREVCM}}=2$,
${y}_{\mathit{i}}^{\prime}$ is located in ${\mathbf{RWORK}}\left(50+{\mathbf{NEQ}}+\mathit{i}\right)$ and ${r}_{\mathit{i}}$ should be stored in ${\mathbf{RWORK}}\left(50+2\times {\mathbf{NEQ}}+\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{NEQ}}$.
For ${\mathbf{IREVCM}}=4$ or $7$,
${y}_{\mathit{i}}^{\prime}$ is located in ${\mathbf{YDOT}}\left(\mathit{i}\right)$ and ${r}_{\mathit{i}}$ should be stored in ${\mathbf{RWORK}}\left(50+{\mathbf{NEQ}}+\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{NEQ}}$.
For ${\mathbf{IREVCM}}=5$,
${y}_{\mathit{i}}^{\prime}$ is located in ${\mathbf{RWORK}}\left(50+2\times {\mathbf{NEQ}}+\mathit{i}\right)$ and ${r}_{\mathit{i}}$ should be stored in ${\mathbf{YDOT}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{NEQ}}$.
 ${\mathbf{IREVCM}}=8$
 Indicates that a JAC operation (see Section 3) is required: you must supply the Jacobian matrix.
If full matrix linear algebra is being used, then the $\left(i,j\right)$th element of the Jacobian must be stored in ${\mathbf{WKJAC}}\left(\left(j1\right)\times {\mathbf{NEQ}}+i\right)$.
If banded matrix linear algebra is being used, then the $\left(i,j\right)$th element of the Jacobian
must be stored in ${\mathbf{WKJAC}}\left(\left(i1\right)\times {m}_{B}+k\right)$, where ${m}_{B}={m}_{L}+{m}_{U}+1$ and $k=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({m}_{L}i+1,0\right)+j$; here ${m}_{L}$ and ${m}_{U}$ are the number of subdiagonals and superdiagonals, respectively, in the band.
If sparse matrix linear algebra is being used, then
D02NRF must be called to determine which column of the Jacobian is required and where it should be stored.
CALL D02NRF(J, IPLACE, INFORM)
will return in
J the number of the column of the Jacobian that is required and will set
${\mathbf{IPLACE}}=1$ or
$2$ (see
D02NRF). If
${\mathbf{IPLACE}}=1$, you must store the nonzero element
$\left(i,j\right)$ of the Jacobian in
${\mathbf{RWORK}}\left(50+2\times {\mathbf{NEQ}}+i\right)$; otherwise it must be stored in
${\mathbf{RWORK}}\left(50+{\mathbf{NEQ}}+i\right)$.
 ${\mathbf{IREVCM}}=9$
 Indicates that a MONITR operation (see Section 3) can be performed.
 ${\mathbf{IREVCM}}=10$
 Indicates that the current step was not successful, due to error test failure or convergence test failure. The only information supplied to you on this return is the current value of the variable $t$, located in ${\mathbf{RWORK}}\left(19\right)$. No values must be changed before reentering D02NNF; this facility enables you to determine the number of unsuccessful steps.
On final exit:
${\mathbf{IREVCM}}=0$ indicating that the userspecified task has been completed or an error has been encountered (see the descriptions for
ITASK and
IFAIL).
Constraint:
$0\le {\mathbf{IREVCM}}\le 11$.
 22: $\mathrm{LDERIV}\left(2\right)$ – LOGICAL arrayInput/Output

On initial entry:
${\mathbf{LDERIV}}\left(1\right)$ must be set to .TRUE. if you have supplied both an initial
$y$ and an initial
${y}^{\prime}$.
${\mathbf{LDERIV}}\left(1\right)$ must be set to .FALSE. if only the initial
$y$ has been supplied.
${\mathbf{LDERIV}}\left(2\right)$ must be set to .TRUE. if the integrator is to use a modified Newton method to evaluate the initial
$y$ and
${y}^{\prime}$. Note that
$y$ and
${y}^{\prime}$, if supplied, are used as initial estimates. This method involves taking a small step at the start of the integration, and if
${\mathbf{ITASK}}=6$ on entry,
T and
TOUT will be set to the result of taking this small step.
${\mathbf{LDERIV}}\left(2\right)$ must be set to .FALSE. if the integrator is to use functional iteration to evaluate the initial
$y$ and
${y}^{\prime}$, and if this fails a modified Newton method will then be attempted.
${\mathbf{LDERIV}}\left(2\right)=\mathrm{.TRUE.}$ is recommended if there are implicit equations or the initial
$y$ and
${y}^{\prime}$ are zero.
On final exit:
${\mathbf{LDERIV}}\left(1\right)$ is normally unchanged. However if
${\mathbf{ITASK}}=6$ and internal initialization was successful then
${\mathbf{LDERIV}}\left(1\right)=\mathrm{.TRUE.}$.
${\mathbf{LDERIV}}\left(2\right)=\mathrm{.TRUE.}$, if implicit equations were detected. Otherwise ${\mathbf{LDERIV}}\left(2\right)=\mathrm{.FALSE.}$.
 23: $\mathrm{ITASK}$ – INTEGERInput

On initial entry: the task to be performed by the integrator.
 ${\mathbf{ITASK}}=1$
 Normal computation of output values of $y\left(t\right)$ at $t={\mathbf{TOUT}}$ (by overshooting and interpolating).
 ${\mathbf{ITASK}}=2$
 Take one step only and return.
 ${\mathbf{ITASK}}=3$
 Stop at the first internal integration point at or beyond $t={\mathbf{TOUT}}$ and return.
 ${\mathbf{ITASK}}=4$
 Normal computation of output values of $y\left(t\right)$ at $t={\mathbf{TOUT}}$ but without overshooting $t={\mathbf{TCRIT}}$. 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 (e.g., see D02NVF) may be equal to or beyond TOUT, but not before it in the direction of integration.
 ${\mathbf{ITASK}}=5$
 Take one step only and return, without passing TCRIT (e.g., see D02NVF). TCRIT must be specified under ${\mathbf{ITASK}}=4$.
 ${\mathbf{ITASK}}=6$
 The integrator will solve for the initial values of $y$ and ${y}^{\prime}$ only and then return to the calling (sub)program without doing the integration. This option can be used to check the initial values of $y$ and ${y}^{\prime}$. Functional iteration or a ‘small’ backward Euler method used in conjunction with a damped Newton iteration is used to calculate these values (see LDERIV). Note that if a backward Euler step is used then the value of $t$ will have been advanced a short distance from the initial point.
Note: if D02NNF is recalled with a different value of
ITASK (and
TOUT altered) then the initialization procedure is repeated, possibly leading to different initial conditions.
Constraint:
$1\le {\mathbf{ITASK}}\le 6$.
 24: $\mathrm{ITRACE}$ – INTEGERInput

On initial entry: the level of output that is printed by the integrator.
ITRACE may take the value
$1$,
$0$,
$1$,
$2$ or
$3$.
 ${\mathbf{ITRACE}}<1$
 $1$ is assumed and similarly if ${\mathbf{ITRACE}}>3$, then $3$ is assumed.
 ${\mathbf{ITRACE}}=1$
 No output is generated.
 ${\mathbf{ITRACE}}=0$
 Only warning messages are printed on the current error message unit (see X04AAF).
 ${\mathbf{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.
 25: $\mathrm{IFAIL}$ – INTEGERInput/Output

On entry:
IFAIL must be set to
$0$,
$1\text{ 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\text{ 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
${\mathbf{IFAIL}}\ne {\mathbf{0}}$ on exit, the recommended value is
$1$.
When the value $\mathbf{1}\text{ or}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}}=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:
 ${\mathbf{IFAIL}}=1$

On entry, the integrator detected an illegal input, or that a linear algebra and/or integrator setup routine has not been called prior to the call to the integrator. If
${\mathbf{ITRACE}}\ge 0$, the form of the error will be detailed on the current error message unit (see
X04AAF).
 ${\mathbf{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).
 ${\mathbf{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
${\mathbf{Y}}\left(1\right),{\mathbf{Y}}\left(2\right),\dots ,{\mathbf{Y}}\left({\mathbf{NEQ}}\right)$ contain the computed values of the solution at the current point
T.
 ${\mathbf{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.
 ${\mathbf{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.
 ${\mathbf{IFAIL}}=6$

Some error weight
${w}_{i}$ became zero during the integration (see the description of
ITOL). Pure relative error control (
${\mathbf{ATOL}}\left(i\right)=0.0$) was requested on a variable (the
$i$th) which has now vanished. The integration was successful as far as
T.
 ${\mathbf{IFAIL}}=7$

The RESID operation (see
Section 3) set the error flag
${\mathbf{IRES}}=3$ continually despite repeated attempts by the integrator to avoid this.
 ${\mathbf{IFAIL}}=8$

${\mathbf{LDERIV}}\left(1\right)=\mathrm{.FALSE.}$ on entry but the internal initialization routine was unable to initialize
${y}^{\prime}$ (more detailed information may be directed to the current error message unit, see
X04AAF).
 ${\mathbf{IFAIL}}=9$

A singular Jacobian $\frac{\partial r}{\partial y}$ has been encountered. You should check the problem formulation and Jacobian calculation.
 ${\mathbf{IFAIL}}=10$

An error occurred during Jacobian formulation or backsubstitution (a more detailed error description may be directed to the current error message unit, see
X04AAF).
 ${\mathbf{IFAIL}}=11$

The RESID operation (see
Section 3) signalled the integrator to halt the integration and return by setting
${\mathbf{IRES}}=2$. Integration was successful as far as
T.
 ${\mathbf{IFAIL}}=12$

The MONITR operation (see
Section 3) set
${\mathbf{IMON}}=2$ and so forced a return but the integration was successful as far as
T.
 ${\mathbf{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
${\mathbf{ITASK}}\ne 2$ or
$5$.)
 ${\mathbf{IFAIL}}=14$

The values of
RTOL and
ATOL are so small that D02NNF is unable to start the integration.
 ${\mathbf{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.
 ${\mathbf{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.
 ${\mathbf{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
${\mathbf{ITOL}}=1$ with
${\mathbf{ATOL}}\left(1\right)$ small but positive).
8 Parallelism and Performance
D02NNF 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.
D02NNF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
D02NNF 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 implementationspecific information.
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; also on the type of linear algebra being used. For further details see
Section 9 in
D02NGF,
D02NHF and
D02NJF of the documents for
D02NGF (full matrix),
D02NHF (banded matrix) or
D02NJF (sparse matrix).
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
$\frac{\partial}{\partial y}\left({A}^{1}g\right)$ has complex eigenvalues near the imaginary axis for some part of the integration, you should try the BLEND option (setup routine
D02NWF).
10 Example
We solve the wellknown stiff Robertson problem written as a differential system in implicit form
over the range
$\left[0,10\right]$ with initial conditions
$a=1.0$ and
$b=c=0.0$ and with scalar error control (
${\mathbf{ITOL}}=1$). We integrate to the first internal integration point past
${\mathbf{TOUT}}=10.0$ (
${\mathbf{ITASK}}=3$), using a BDF method (setup routine
D02MVF) and a modified Newton method. We treat the Jacobian as sparse (setup routine
D02NUF) and we calculate it analytically. In this program we also illustrate the monitoring of step failures (
${\mathbf{IREVCM}}=10$) and the forcing of a return when the component falls below
$0.9$ in the evaluation of the residual by setting
${\mathbf{IRES}}=2$.
10.1 Program Text
Program Text (d02nnfe.f90)
10.2 Program Data
Program Data (d02nnfe.d)
10.3 Program Results
Program Results (d02nnfe.r)