NAG Library Routine Document
d02nef (dae_dassl_gen)
1
Purpose
d02nef is a routine for integrating stiff systems of implicit ordinary differential equations coupled with algebraic equations.
2
Specification
Fortran Interface
Subroutine d02nef ( 
neq, t, tout, y, ydot, rtol, atol, itask, res, jac, icom, com, lcom, iuser, ruser, ifail) 
Integer, Intent (In)  ::  neq, lcom  Integer, Intent (Inout)  ::  itask, icom(50+neq), iuser(*), ifail  Real (Kind=nag_wp), Intent (In)  ::  tout  Real (Kind=nag_wp), Intent (Inout)  ::  t, y(neq), ydot(neq), rtol(*), atol(*), com(lcom), ruser(*)  External  ::  res, jac 

C Header Interface
#include nagmk26.h
void 
d02nef_ (const Integer *neq, double *t, const double *tout, double y[], double ydot[], double rtol[], double atol[], Integer *itask, void (NAG_CALL *res)(const Integer *neq, const double *t, const double y[], const double ydot[], double r[], Integer *ires, Integer iuser[], double ruser[]), void (NAG_CALL *jac)(const Integer *neq, const double *t, const double y[], const double ydot[], double pd[], const double *cj, Integer iuser[], double ruser[]), Integer icom[], double com[], const Integer *lcom, Integer iuser[], double ruser[], Integer *ifail) 

3
Description
d02nef is a general purpose routine for integrating the initial value problem for a stiff system of implicit ordinary differential equations with coupled algebraic equations written in the form
d02nef uses the DASSL implementation of the Backward Differentiation Formulae (BDF) of orders one to five to solve a system of the above form for
$y$ (
y) and
${y}^{\prime}$ (
ydot). Values for
y and
ydot at the initial time must be given as input. These values must be consistent, (i.e., if
t,
y,
ydot are the given initial values, they must satisfy
$F\left({\mathbf{t}},{\mathbf{y}},{\mathbf{ydot}}\right)=0$). The routine solves the system from
$t={\mathbf{t}}$ to
$t={\mathbf{tout}}$.
An outline of a typical calling program for
d02nef is given below. It calls the DASSL implementation of the BDF integrator setup routine
d02mwf and the banded matrix setup routine
d02npf (if required), and, if the integration needs to proceed, calls
d02mcf before continuing the integration.
! Declarations
External res, jac
.
.
.
! Initialize the integrator
Call d02mwf(...)
! Is the Jacobian matrix banded?
If (banded) Call d02npf(...)
! Set dt to the required temporal resolution
! Set tend to the final time
! Call the integrator for each temporal value:
1000 Call d02nef(...,res,jac,...)
! Continue integration?
If (tout.lt.tend .and. itask.ge.0) Then
If (itask.ne.1) tout = min(tout+dt,tend)
! Print solution
Call d02mcf(...)
Go To 1000
Endif
.
.
.
4
References
None.
5
Arguments
 1: $\mathbf{neq}$ – IntegerInput

On entry: the number of differentialalgebraic equations to be solved.
Constraint:
${\mathbf{neq}}\ge 1$.
 2: $\mathbf{t}$ – Real (Kind=nag_wp)Input/Output

On initial entry: the initial value of the independent variable, $t$.
On intermediate exit:
$t$, the current value of the independent variable.
On final exit: the value of the independent variable at which the computed solution
$y$ is returned (usually at
tout).
 3: $\mathbf{tout}$ – Real (Kind=nag_wp)Input

On entry: the next value of $t$ at which a computed solution is desired.
On initial entry:
tout is used to determine the direction of integration. Integration is permitted in either direction (see also
itask).
Constraint:
${\mathbf{tout}}\ne {\mathbf{t}}$.
 4: $\mathbf{y}\left({\mathbf{neq}}\right)$ – Real (Kind=nag_wp) arrayInput/Output

On initial entry: the vector of initial values of the dependent variables $y$.
On intermediate exit:
the computed solution vector, $y$, evaluated at $t=T$.
On final exit: the computed solution vector, evaluated at $t$ (usually $t={\mathbf{tout}}$).
 5: $\mathbf{ydot}\left({\mathbf{neq}}\right)$ – Real (Kind=nag_wp) arrayInput/Output

On initial entry:
ydot must contain approximations to the time derivatives
$y\text{'}$ of the vector
$y$ evaluated at the initial value of the independent variable.
On exit: the time derivatives $y\text{'}$ of the vector $y$ at the last integration point.
 6: $\mathbf{rtol}\left(*\right)$ – Real (Kind=nag_wp) arrayInput/Output

Note: the dimension of the array
rtol depends on the value of
itol as set in
d02mwf; it
must be at least
${\mathbf{neq}}$ if
${\mathbf{itol}}=\mathrm{.TRUE.}$ and at least
$1$ if
${\mathbf{itol}}=\mathrm{.FALSE.}$.
On entry: the relative local error tolerance.
Constraint:
${\mathbf{rtol}}\left(\mathit{i}\right)\ge 0.0$, for
$\mathit{i}=1,2,\dots ,n$where $n={\mathbf{neq}}$ when ${\mathbf{itol}}=\mathrm{.TRUE.}$ and $n=1$ otherwise.
On exit:
rtol remains unchanged unless
d02nef exits with
${\mathbf{ifail}}={\mathbf{16}}$ in which case the values may have been increased to values estimated to be appropriate for continuing the integration.
 7: $\mathbf{atol}\left(*\right)$ – Real (Kind=nag_wp) arrayInput/Output

Note: the dimension of the array
atol depends on the value of
itol as set in
d02mwf; it
must be at least
${\mathbf{neq}}$ if
${\mathbf{itol}}=\mathrm{.TRUE.}$ and at least
$1$ if
${\mathbf{itol}}=\mathrm{.FALSE.}$.
On entry: the absolute local error tolerance.
Constraint:
${\mathbf{atol}}\left(\mathit{i}\right)\ge 0.0$, for
$\mathit{i}=1,2,\dots ,n$where $n={\mathbf{neq}}$ when ${\mathbf{itol}}=\mathrm{.TRUE.}$ and $n=1$ otherwise.
On exit:
atol remains unchanged unless
d02nef exits with
${\mathbf{ifail}}={\mathbf{16}}$ in which case the values may have been increased to values estimated to be appropriate for continuing the integration.
 8: $\mathbf{itask}$ – IntegerInput/Output

On initial entry: need not be set.
On exit: the task performed by the integrator on successful completion or an indicator that a problem occurred during integration.
 ${\mathbf{itask}}=2$
 The integration to tout was successfully completed (${\mathbf{t}}={\mathbf{tout}}$) by stepping exactly to tout.
 ${\mathbf{itask}}=3$
 The integration to tout was successfully completed (${\mathbf{t}}={\mathbf{tout}}$) by stepping past tout. y and ydot are obtained by interpolation.
 ${\mathbf{itask}}<0$
 Different negative values of itask returned correspond to different failure exits. ifail should always be checked in such cases and the corrective action taken where appropriate.
itask must remain
unchanged between calls to
d02nef.
 9: $\mathbf{res}$ – Subroutine, supplied by the user.External Procedure

res must evaluate the residual
The specification of
res is:
Fortran Interface
Integer, Intent (In)  ::  neq  Integer, Intent (Inout)  ::  ires, iuser(*)  Real (Kind=nag_wp), Intent (In)  ::  t, y(neq), ydot(neq)  Real (Kind=nag_wp), Intent (Inout)  ::  ruser(*)  Real (Kind=nag_wp), Intent (Out)  ::  r(neq) 

C Header Interface
#include nagmk26.h
void 
res (const Integer *neq, const double *t, const double y[], const double ydot[], double r[], Integer *ires, Integer iuser[], double ruser[]) 

 1: $\mathbf{neq}$ – IntegerInput

On entry: the number of differentialalgebraic equations being solved.
 2: $\mathbf{t}$ – Real (Kind=nag_wp)Input

On entry: $t$, the current value of the independent variable.
 3: $\mathbf{y}\left({\mathbf{neq}}\right)$ – Real (Kind=nag_wp) arrayInput

On entry: ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{neq}}$, the current solution component.
 4: $\mathbf{ydot}\left({\mathbf{neq}}\right)$ – Real (Kind=nag_wp) arrayInput

On entry: the derivative of the solution at the current point $t$.
 5: $\mathbf{r}\left({\mathbf{neq}}\right)$ – Real (Kind=nag_wp) arrayOutput

On exit:
${\mathbf{r}}\left(\mathit{i}\right)$ must contain the
$\mathit{i}$th component of
$R$, for
$\mathit{i}=1,2,\dots ,{\mathbf{neq}}$ where
 6: $\mathbf{ires}$ – IntegerInput/Output

On entry: is always equal to zero.
On exit:
ires should normally be left unchanged. However, if an illegal value of
y is encountered,
ires should be set to
$1$;
d02nef will then attempt to resolve the problem so that illegal values of
y are not encountered.
ires should be set to
$2$ if you wish to return control to the calling (sub)routine; this will cause
d02nef to exit with
${\mathbf{ifail}}={\mathbf{23}}$.
 7: $\mathbf{iuser}\left(*\right)$ – Integer arrayUser Workspace
 8: $\mathbf{ruser}\left(*\right)$ – Real (Kind=nag_wp) arrayUser Workspace

res is called with the arguments
iuser and
ruser as supplied to
d02nef. You should use the arrays
iuser and
ruser to supply information to
res.
res must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
d02nef is called. Arguments denoted as
Input must
not be changed by this procedure.
Note: res should not return floatingpoint NaN (Not a Number) or infinity values, since these are not handled by
d02nef. If your code inadvertently
does return any NaNs or infinities,
d02nef is likely to produce unexpected results.
 10: $\mathbf{jac}$ – Subroutine, supplied by the NAG Library or the user.External Procedure

Evaluates the matrix of partial derivatives,
$J$, where
If this option is not required, the actual argument for
jac must be the dummy routine d02nez. (d02nez 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 setup routine
d02mwf.
The specification of
jac is:
Fortran Interface
Integer, Intent (In)  ::  neq  Integer, Intent (Inout)  ::  iuser(*)  Real (Kind=nag_wp), Intent (In)  ::  t, y(neq), ydot(neq), cj  Real (Kind=nag_wp), Intent (Inout)  ::  pd(*), ruser(*) 

C Header Interface
#include nagmk26.h
void 
jac (const Integer *neq, const double *t, const double y[], const double ydot[], double pd[], const double *cj, Integer iuser[], double ruser[]) 

 1: $\mathbf{neq}$ – IntegerInput

On entry: the number of differentialalgebraic equations being solved.
 2: $\mathbf{t}$ – Real (Kind=nag_wp)Input

On entry: $t$, the current value of the independent variable.
 3: $\mathbf{y}\left({\mathbf{neq}}\right)$ – Real (Kind=nag_wp) arrayInput

On entry: ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{neq}}$, the current solution component.
 4: $\mathbf{ydot}\left({\mathbf{neq}}\right)$ – Real (Kind=nag_wp) arrayInput

On entry: the derivative of the solution at the current point $t$.
 5: $\mathbf{pd}\left(*\right)$ – Real (Kind=nag_wp) arrayInput/Output

On entry:
pd is preset to zero before the call to
jac.
On exit: if the Jacobian is full then
${\mathbf{pd}}\left(\left(\mathit{j}1\right)\times {\mathbf{neq}}+\mathit{i}\right)={J}_{\mathit{i}\mathit{j}}$, for
$\mathit{i}=1,2,\dots ,{\mathbf{neq}}$ and
$\mathit{j}=1,2,\dots ,{\mathbf{neq}}$; if the Jacobian is banded then
${\mathbf{pd}}\left(\left(j1\right)\times \left(2{\mathbf{ml}}+{\mathbf{mu}}+1\right)+{\mathbf{ml}}+{\mathbf{mu}}+ij+1\right)={J}_{ij}$, for
$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,j{\mathbf{mu}}\right)\le i\le \mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(n,j+{\mathbf{ml}}\right)$; (see also in
f07bdf (dgbtrf)).
 6: $\mathbf{cj}$ – Real (Kind=nag_wp)Input

On entry:
cj is a scalar constant which will be defined in
d02nef.
 7: $\mathbf{iuser}\left(*\right)$ – Integer arrayUser Workspace
 8: $\mathbf{ruser}\left(*\right)$ – Real (Kind=nag_wp) arrayUser Workspace

jac is called with the arguments
iuser and
ruser as supplied to
d02nef. You should use the arrays
iuser and
ruser to supply information to
jac.
jac must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
d02nef is called. Arguments denoted as
Input must
not be changed by this procedure.
Note: jac should not return floatingpoint NaN (Not a Number) or infinity values, since these are not handled by
d02nef. If your code inadvertently
does return any NaNs or infinities,
d02nef is likely to produce unexpected results.
 11: $\mathbf{icom}\left(50+{\mathbf{neq}}\right)$ – Integer arrayCommunication Array

icom contains information which is usually of no interest, but is necessary for subsequent calls. However you may find the following useful:
 ${\mathbf{icom}}\left(22\right)$
 The order of the method to be attempted on the next step.
 ${\mathbf{icom}}\left(23\right)$
 The order of the method used on the last step.
 ${\mathbf{icom}}\left(26\right)$
 The number of steps taken so far.
 ${\mathbf{icom}}\left(27\right)$
 The number of calls to res so far.
 ${\mathbf{icom}}\left(28\right)$
 The number of evaluations of the matrix of partial derivatives needed so far.
 ${\mathbf{icom}}\left(29\right)$
 The total number of error test failures so far.
 ${\mathbf{icom}}\left(30\right)$
 The total number of convergence test failures so far.
 12: $\mathbf{com}\left({\mathbf{lcom}}\right)$ – Real (Kind=nag_wp) arrayCommunication Array

com contains information which is usually of no interest, but is necessary for subsequent calls. However you may find the following useful:
 ${\mathbf{com}}\left(3\right)$
 The step size to be attempted on the next step.
 ${\mathbf{com}}\left(4\right)$
 The current value of the independent variable, i.e., the farthest point integration has reached. This will be different from t only when interpolation has been performed (${\mathbf{itask}}=3$).
 13: $\mathbf{lcom}$ – IntegerInput

On entry: the dimension of the array
com as declared in the (sub)program from which
d02nef is called.
Constraint:
${\mathbf{lcom}}\ge 40+\left(\mathit{maxorder}+4\right)\times {\mathbf{neq}}+{\mathbf{neq}}\times p+q$ where
$\mathit{maxorder}$ is the maximum order that can be used by the integration method (see
maxord in
d02mwf);
$p={\mathbf{neq}}$ when the Jacobian is full and
$p=\left(2\times {\mathbf{ml}}+{\mathbf{mu}}+1\right)$ when the Jacobian is banded; and,
$q=\left({\mathbf{neq}}/\left({\mathbf{ml}}+{\mathbf{mu}}+1\right)\right)+1$ when the Jacobian is to be evaluated numerically and
$q=0$ otherwise.
 14: $\mathbf{iuser}\left(*\right)$ – Integer arrayUser Workspace
 15: $\mathbf{ruser}\left(*\right)$ – Real (Kind=nag_wp) arrayUser Workspace

iuser and
ruser are not used by
d02nef, but are passed directly to
res and
jac and may be used to pass information to these routines.
 16: $\mathbf{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).
Note: d02nef may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
 ${\mathbf{ifail}}=1$

On entry, ${\mathbf{neq}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{neq}}\ge 1$.
 ${\mathbf{ifail}}=3$

On entry, ${\mathbf{t}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{tout}}\ne {\mathbf{t}}$.
tout is behind
t in the direction of
$h$:
${\mathbf{tout}}{\mathbf{t}}=\u2329\mathit{\text{value}}\u232a$,
$h=\u2329\mathit{\text{value}}\u232a$.
tout is too close to
t to start integration:
${\mathbf{tout}}{\mathbf{t}}=\u2329\mathit{\text{value}}\u232a$:
$\mathit{hmin}=\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{ifail}}=6$

Some element of
rtol is less than zero.
 ${\mathbf{ifail}}=7$

Some element of
atol is less than zero.
 ${\mathbf{ifail}}=8$

A previous call to this routine returned with ${\mathbf{itask}}=\u2329\mathit{\text{value}}\u232a$ and no appropriate action was taken.
 ${\mathbf{ifail}}=11$

Either the initialization routine has not been called prior to the first call of this routine or a communication array has become corrupted.
 ${\mathbf{ifail}}=12$

Either the initialization routine has not been called prior to the first call of this routine or a communication array has become corrupted.
 ${\mathbf{ifail}}=13$

com array is of insufficient length; length required
$\text{}=\u2329\mathit{\text{value}}\u232a$; actual length
${\mathbf{lcom}}=\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{ifail}}=14$

All elements of
rtol and
atol are zero.
 ${\mathbf{ifail}}=15$

Maximum number of steps taken on this call before reaching
tout:
${\mathbf{t}}=\u2329\mathit{\text{value}}\u232a$, maximum number of steps
$\text{}=\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{ifail}}=16$

Too much accuracy requested for precision of machine.
rtol and
atol were increased by scale factor
$R$. Try running again with these scaled tolerances.
${\mathbf{t}}=\u2329\mathit{\text{value}}\u232a$,
$R=\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{ifail}}=17$

A solution component has become zero when a purely relative tolerance (zero absolute tolerance) was selected for that component. ${\mathbf{t}}=\u2329\mathit{\text{value}}\u232a$, ${\mathbf{y}}\left(\mathit{I}\right)=\u2329\mathit{\text{value}}\u232a$ for component $\mathit{I}=\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{ifail}}=18$

The error test failed repeatedly with $\lefth\right=\mathit{hmin}$. ${\mathbf{t}}=\u2329\mathit{\text{value}}\u232a$. Stepsize $h=\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{ifail}}=19$

The corrector repeatedly failed to converge with $\lefth\right=\mathit{hmin}$. ${\mathbf{t}}=\u2329\mathit{\text{value}}\u232a$. Stepsize $h=\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{ifail}}=20$

The iteration matrix is singular. ${\mathbf{t}}=\u2329\mathit{\text{value}}\u232a$. Stepsize $h=\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{ifail}}=21$

The corrector could not converge and the error test failed repeatedly. ${\mathbf{t}}=\u2329\mathit{\text{value}}\u232a$. Stepsize $h=\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{ifail}}=22$

ires was set to
$1$ during a call to
res and could not be resolved.
${\mathbf{t}}=\u2329\mathit{\text{value}}\u232a$. Stepsize
$h=\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{ifail}}=23$

ires was set to
$2$ during a call to
res.
${\mathbf{t}}=\u2329\mathit{\text{value}}\u232a$. Stepsize
$\text{}=\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{ifail}}=24$

The initial
ydot could not be computed.
${\mathbf{t}}=\u2329\mathit{\text{value}}\u232a$. Stepsize
$h=\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{ifail}}=25$

Repeated occurrences of input constraint violations have been detected. This could result in a potential infinite loop: ${\mathbf{itask}}=\u2329\mathit{\text{value}}\u232a$. Current violation corresponds to exit with ${\mathbf{ifail}}=\u2329\mathit{\text{value}}\u232a$.
 ${\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. 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}}=0$ with
${\mathbf{atol}}\left(1\right)$ small but positive).
8
Parallelism and Performance
d02nef is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
d02nef 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. For banded systems the cost is proportional to ${\mathbf{neq}}\times {\left({\mathbf{ml}}+{\mathbf{mu}}+1\right)}^{2}$, while for full systems the cost is proportional to
${{\mathbf{neq}}}^{3}$. Note however that for moderately sized problems which are only mildly nonlinear the cost may be dominated by factors proportional to ${\mathbf{neq}}\times \left({\mathbf{ml}}+{\mathbf{mu}}+1\right)$ and ${{\mathbf{neq}}}^{2}$ respectively.
10
Example
For this routine two examples are presented. There is a single example program for d02nef, with a main program and the code to solve the two example problems given in Example 1 (EX1) and Example 2 (EX2).
Example 1 (EX1)
This example solves the wellknown stiff Robertson problem written in implicit form
with initial conditions
$a=1.0$ and
$b=c=0.0$ over the range
$\left[0,0.1\right]$ the BDF method (setup routine
d02mwf and
d02npf).
Example 2 (EX2)
This example illustrates the use of d02nef to solve a simple algebraic problem by continuation. The equation $42y+0.1{e}^{y}t=0$ from $t=0$ (where $y=2$) to $t=1$.
10.1
Program Text
Program Text (d02nefe.f90)
10.2
Program Data
Program Data (d02nefe.d)
10.3
Program Results
Program Results (d02nefe.r)