NAG Library Routine Document
D02NEF
1 Purpose
D02NEF is a routine for integrating stiff systems of implicit ordinary differential equations coupled with algebraic equations.
2 Specification
SUBROUTINE D02NEF ( |
NEQ, T, TOUT, Y, YDOT, RTOL, ATOL, ITASK, RES, JAC, ICOM, COM, LCOM, IUSER, RUSER, IFAIL) |
INTEGER |
NEQ, ITASK, ICOM(50+NEQ), LCOM, IUSER(*), IFAIL |
REAL (KIND=nag_wp) |
T, TOUT, Y(NEQ), YDOT(NEQ), RTOL(*), ATOL(*), COM(LCOM), RUSER(*) |
EXTERNAL |
RES, JAC |
|
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) and
(
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
). The routine solves the system from
to
.
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 Parameters
- 1: NEQ – INTEGERInput
On entry: the number of differential-algebraic equations to be solved.
Constraint:
.
- 2: T – REAL (KIND=nag_wp)Input/Output
On initial entry: the initial value of the independent variable, .
On intermediate exit:
, the current value of the independent variable.
On final exit: the value of the independent variable at which the computed solution
is returned (usually at
TOUT).
- 3: TOUT – REAL (KIND=nag_wp)Input
On entry: the next value of 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:
.
- 4: Y(NEQ) – REAL (KIND=nag_wp) arrayInput/Output
On initial entry: the vector of initial values of the dependent variables .
On intermediate exit:
the computed solution vector, , evaluated at .
On final exit: the computed solution vector, evaluated at (usually ).
- 5: YDOT(NEQ) – REAL (KIND=nag_wp) arrayInput/Output
On initial entry:
YDOT must contain approximations to the time derivatives
of the vector
evaluated at the initial value of the independent variable.
On exit: the time derivatives of the vector at the last integration point.
- 6: RTOL() – 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
if
and at least
if
.
On entry: the relative local error tolerance.
Constraint:
, for
where when and otherwise.
On exit:
RTOL remains unchanged unless D02NEF exits with
in which case the values may have been increased to values estimated to be appropriate for continuing the integration.
- 7: ATOL() – 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
if
and at least
if
.
On entry: the absolute local error tolerance.
Constraint:
, for
where when and otherwise.
On exit:
ATOL remains unchanged unless D02NEF exits with
in which case the values may have been increased to values estimated to be appropriate for continuing the integration.
- 8: 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.
- The integration to TOUT was successfully completed () by stepping exactly to TOUT.
- The integration to TOUT was successfully completed () by stepping past TOUT. Y and YDOT are obtained by interpolation.
- 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: RES – SUBROUTINE, supplied by the user.External Procedure
RES must evaluate the residual
The specification of
RES is:
INTEGER |
NEQ, IRES, IUSER(*) |
REAL (KIND=nag_wp) |
T, Y(NEQ), YDOT(NEQ), R(NEQ), RUSER(*) |
|
- 1: NEQ – INTEGERInput
On entry: the number of differential-algebraic equations being solved.
- 2: T – REAL (KIND=nag_wp)Input
On entry: , the current value of the independent variable.
- 3: Y(NEQ) – REAL (KIND=nag_wp) arrayInput
On entry: , for , the current solution component.
- 4: YDOT(NEQ) – REAL (KIND=nag_wp) arrayInput
On entry: the derivative of the solution at the current point .
- 5: R(NEQ) – REAL (KIND=nag_wp) arrayOutput
On exit:
must contain the
th component of
, for
where
- 6: 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
; D02NEF will then attempt to resolve the problem so that illegal values of
Y are not encountered.
IRES should be set to
if you wish to return control to the calling (sub)routine; this will cause D02NEF to exit with
.
- 7: IUSER() – INTEGER arrayUser Workspace
- 8: RUSER() – REAL (KIND=nag_wp) arrayUser Workspace
-
RES is called with the parameters
IUSER and
RUSER as supplied to D02NEF. You are free to use the arrays
IUSER and
RUSER to supply information to
RES as an alternative to using COMMON global variables.
RES must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02NEF is called. Parameters denoted as
Input must
not be changed by this procedure.
- 10: JAC – SUBROUTINE, supplied by the NAG Library or the user.External Procedure
Evaluates the matrix of partial derivatives,
, 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 parameter
JCEVAL appropriately in a call to the setup routine
D02MWF.
The specification of
JAC is:
INTEGER |
NEQ, IUSER(*) |
REAL (KIND=nag_wp) |
T, Y(NEQ), YDOT(NEQ), PD(*), CJ, RUSER(*) |
|
- 1: NEQ – INTEGERInput
On entry: the number of differential-algebraic equations being solved.
- 2: T – REAL (KIND=nag_wp)Input
On entry: , the current value of the independent variable.
- 3: Y(NEQ) – REAL (KIND=nag_wp) arrayInput
On entry: , for , the current solution component.
- 4: YDOT(NEQ) – REAL (KIND=nag_wp) arrayInput
On entry: the derivative of the solution at the current point .
- 5: PD() – 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
, for
and
; if the Jacobian is banded then
, for
; (see also in
F07BDF (DGBTRF)).
- 6: CJ – REAL (KIND=nag_wp)Input
On entry:
CJ is a scalar constant which will be defined in D02NEF.
- 7: IUSER() – INTEGER arrayUser Workspace
- 8: RUSER() – REAL (KIND=nag_wp) arrayUser Workspace
-
JAC is called with the parameters
IUSER and
RUSER as supplied to D02NEF. You are free to use the arrays
IUSER and
RUSER to supply information to
JAC as an alternative to using COMMON global variables.
JAC must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02NEF is called. Parameters denoted as
Input must
not be changed by this procedure.
- 11: ICOM() – 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:
- The order of the method to be attempted on the next step.
- The order of the method used on the last step.
- The number of steps taken so far.
- The number of calls to RES so far.
- The number of evaluations of the matrix of partial derivatives needed so far.
- The total number of error test failures so far.
- The total number of convergence test failures so far.
- 12: COM(LCOM) – 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:
- The step size to be attempted on the next step.
- 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 ().
- 13: LCOM – INTEGERInput
On entry: the dimension of the array
COM as declared in the (sub)program from which D02NEF is called.
Constraint:
where
is the maximum order that can be used by the integration method (see
MAXORD in
D02MWF);
when the Jacobian is full and
when the Jacobian is banded; and,
when the Jacobian is to be evaluated numerically and
otherwise.
- 14: IUSER() – INTEGER arrayUser Workspace
- 15: RUSER() – 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 as an alternative to using COMMON global variables.
- 16: IFAIL – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. 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
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, because for this routine the values of the output parameters may be useful even if
on exit, the recommended value is
.
When the value is used it is essential to test the value of IFAIL on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
or
, 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:
On entry, | , |
or | TOUT is too close to T to start integration, |
or | TOUT is behind T in the direction of H0 (see D02MWF), |
On entry, | , for , where when and otherwise, |
or | for all relevant . |
On entry, | , for , where when and otherwise. |
On entry, | a previous call to this routine returned and , but no appropriate action was taken. For example, if a call returns with () then a call to D02MCF must be made prior to making a continuation call to D02NEF. |
Either the initialization routine
D02MWF has not been called prior to the first call of this routine or one of the communication arrays
ICOM,
COM has become corrupted.
On entry, | , and the Jacobian is full; |
or | , and the Jacobian is banded, |
where is the maximum order of the integration method to be used, and when the Jacobian is to be evaluated numerically and otherwise.
The maximum number of steps (
) has been taken on this call and the integration has not reached
TOUT. The integration can proceed by calling
D02MCF prior to calling D02NEF again; this will reset the step counter to zero.
Too much accuracy was requested for the precision of the machine. On output
RTOL and
ATOL were increased by an appropriate scale factor to prevent this error exit. Try running the problem again with these scaled tolerances.
A purely relative tolerance was selected for a given solution component, but that solution component has become zero and a pure relative error test is impossible for this component. Perhaps an absolute tolerance requirement is also necessary for this component.
The error test failed repeatedly using the minimum stepsize and so the integration could not proceed. If a (nonzero) minimum stepsize was specified in a call to
D02MWF then either a reduction in this minimum stepsize or in the specified tolerances should be considered.
The corrector step to obtain the approximate solution at the next time step repeatedly failed to converge using the minimum stepsize. This may be due to an inconsistency between the system of equations to be solved and initial conditions.
The iteration matrix (Jacobian) has become singular. Please check the Jacobian evaluations when this is performed analytically. Also check for invalid solution values in the call to
RES; these should be flagged by returning
. This is probably due to an error in the analytic evaluation of the Jacobian.
The corrector step could not converge and the error test failed repeatedly.
IRES was set to
during a call to
RES and the problem could not be resolved.
IRES was set to
during a call to
RES.
The initial
YDOT could not be computed. This could happen because the initial approximation to
YDOT was very poor or because no
YDOT exists that is consistent with the initial
.
Repeated occurrences of input constraint violations have been detected. This could result in a potential infinite loop.
7 Accuracy
The accuracy of the numerical solution may be controlled by a careful choice of the parameters
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
with
small but positive).
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 , while for full systems the cost is proportional to
. Note however that for moderately sized problems which are only mildly nonlinear the cost may be dominated by factors proportional to and respectively.
9 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 well-known stiff Robertson problem written in implicit form
with initial conditions
and
over the range
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 from (where ) to .
9.1 Program Text
Program Text (d02nefe.f90)
9.2 Program Data
Program Data (d02nefe.d)
9.3 Program Results
Program Results (d02nefe.r)