The routine may be called by the names d02nef or nagf_ode_dae_dassl_gen.
3Description
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
.
.
.
4References
None.
5Arguments
1: – IntegerInput
On entry: the number of differential-algebraic equations to be solved.
Constraint:
.
2: – 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: – 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: – 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: – 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: – 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 was set in d02mwf and at least if was set in d02mwf.
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: – 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 was set in d02mwf and at least if was set in d02mwf.
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: – 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: – Subroutine, supplied by the user.External Procedure
On entry: the number of differential-algebraic equations being solved.
2: – Real (Kind=nag_wp)Input
On entry: , the current value of the independent variable.
3: – Real (Kind=nag_wp) arrayInput
On entry: , for , the current solution component.
4: – Real (Kind=nag_wp) arrayInput
On entry: the derivative of the solution at the current point .
5: – Real (Kind=nag_wp) arrayOutput
On exit: must contain the th component of , for where
6: – 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: – Integer arrayUser Workspace
8: – 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 floating-point 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: – 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 argument jceval appropriately in a call to the setup routine d02mwf.
On entry: the number of differential-algebraic equations being solved.
2: – Real (Kind=nag_wp)Input
On entry: , the current value of the independent variable.
3: – Real (Kind=nag_wp) arrayInput
On entry: , for , the current solution component.
4: – Real (Kind=nag_wp) arrayInput
On entry: the derivative of the solution at the current point .
5: – 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 .
6: – Real (Kind=nag_wp)Input
On entry: cj is a scalar constant which will be defined in d02nef.
7: – Integer arrayUser Workspace
8: – 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 floating-point 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: – 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 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: – 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: – 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: – Integer arrayUser Workspace
15: – 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: – IntegerInput/Output
On entry: ifail must be set to , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended since useful values can be provided in some output arguments even when on exit. When the value or 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).
6Error Indicators and Warnings
If on entry or , explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
Note: in some cases d02nef may return useful information.
Maximum number of steps taken on this call before reaching tout: , maximum number of steps .
Too much accuracy requested for precision of machine. rtol and atol were increased by scale factor . Try running again with these scaled tolerances. , .
A solution component has become zero when a purely relative tolerance (zero absolute tolerance) was selected for that component. , for component .
The error test failed repeatedly with . . Stepsize .
The corrector repeatedly failed to converge with . . Stepsize .
The iteration matrix is singular. . Stepsize .
The corrector could not converge and the error test failed repeatedly. . Stepsize .
ires was set to during a call to res and could not be resolved. . Stepsize .
ires was set to during a call to res. . Stepsize .
The initial ydot could not be computed. . Stepsize .
Repeated occurrences of input constraint violations have been detected. This could result in a potential infinite loop: . Current violation corresponds to exit with .
An unexpected error has been triggered by this routine. Please
contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
7Accuracy
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 with small but positive).
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
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 implementation-specific information.
9Further 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 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.
10Example
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 d02mwfandd02npf).
Example 2 (EX2)
This example illustrates the use of d02nef to solve a simple algebraic problem by continuation. The equation from (where ) to .