NAG Library Function Document

nag_dae_ivp_dassl_gen (d02nec)

 Contents

    1  Purpose
    7  Accuracy

1
Purpose

nag_dae_ivp_dassl_gen (d02nec) is a function for integrating stiff systems of implicit ordinary differential equations coupled with algebraic equations.

2
Specification

#include <nag.h>
#include <nagd02.h>
void  nag_dae_ivp_dassl_gen (Integer neq, double *t, double tout, double y[], double ydot[], double rtol[], double atol[], Integer *itask,
void (*res)(Integer neq, double t, const double y[], const double ydot[], double r[], Integer *ires, Nag_Comm *comm),
void (*jac)(Integer neq, double t, const double y[], const double ydot[], double pd[], double cj, Nag_Comm *comm),
Integer icom[], double com[], Integer lcom, Nag_Comm *comm, NagError *fail)

3
Description

nag_dae_ivp_dassl_gen (d02nec) is a general purpose function for integrating the initial value problem for a stiff system of implicit ordinary differential equations with coupled algebraic equations written in the form
F t,y,y = 0 .  
nag_dae_ivp_dassl_gen (d02nec) 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 (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 Ft,y,ydot=0). The function solves the system from t=t to t=tout.
An outline of a typical calling program for nag_dae_ivp_dassl_gen (d02nec) is given below. It calls the DASSL implementation of the BDF integrator setup function nag_dae_ivp_dassl_setup (d02mwc) and the banded matrix setup function nag_dae_ivp_dassl_linalg (d02npc) (if required), and, if the integration needs to proceed, calls nag_dae_ivp_dassl_cont (d02mcc) before continuing the integration.
/* declarations */
   EXTERN res, jac
        .
        .
        .
/* Initialize the integrator */
   nag_dae_ivp_dassl_setup(...);
/* Is the Jacobian matrix banded? */
   if (banded) {nag_dae_ivp_dassl_linalg(...);}

/* Set dt to the required temporal resolution */
/* Set tend to the final time */
/* Call the integrator for each temporal value */
   itask = 0;
   while (tout<tend && itask>-1) {
     nag_dae_ivp_dassl_gen (...);
     if (itask != 1)
        tout = MIN(tout+dt,tend);
        /* Print the solution */
   }
       .
       .
       .

4
References

None.

5
Arguments

1:     neq IntegerInput
On entry: the number of differential-algebraic equations to be solved.
Constraint: neq1.
2:     t double *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:     tout doubleInput
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: toutt.
4:     y[neq] doubleInput/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.
On final exit: the computed solution vector, evaluated at t (usually t=tout).
5:     ydot[neq] doubleInput/Output
On initial entry: ydot must contain approximations to the time derivatives y' of the vector y evaluated at the initial value of the independent variable.
On exit: the time derivatives y' of the vector y at the last integration point.
6:     rtol[dim] doubleInput/Output
Note: the dimension, dim, of the array rtol depends on the value of vector_tol as set in nag_dae_ivp_dassl_setup (d02mwc); it  must be at least
  • neq when vector_tol=Nag_TRUE;
  • 1 when vector_tol=Nag_FALSE.
On entry: the relative local error tolerance.
Constraint: rtol[i-1]0.0, for i=1,2,,n
where n=neq when vector_tol=Nag_TRUE and n=1 otherwise.
On exit: rtol remains unchanged unless nag_dae_ivp_dassl_gen (d02nec) exits with fail.code= NE_ODE_TOL in which case the values may have been increased to values estimated to be appropriate for continuing the integration.
7:     atol[dim] doubleInput/Output
Note: the dimension, dim, of the array atol depends on the value of vector_tol as set in nag_dae_ivp_dassl_setup (d02mwc); it  must be at least
  • neq when vector_tol=Nag_TRUE;
  • 1 when vector_tol=Nag_FALSE.
On entry: the absolute local error tolerance.
Constraint: atol[i-1]0.0, for i=1,2,,n
where n=neq when vector_tol=Nag_TRUE and n=1 otherwise.
On exit: atol remains unchanged unless nag_dae_ivp_dassl_gen (d02nec) exits with fail.code= NE_ODE_TOL in which case the values may have been increased to values estimated to be appropriate for continuing the integration.
8:     itask Integer *Input/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.
itask=2
The integration to tout was successfully completed (t=tout) by stepping exactly to tout.
itask=3
The integration to tout was successfully completed (t=tout) by stepping past tout. y and ydot are obtained by interpolation.
itask<0
Different negative values of itask returned correspond to different failure exits. fail should always be checked in such cases and the corrective action taken where appropriate.
itask must remain unchanged between calls to nag_dae_ivp_dassl_gen (d02nec).
9:     res function, supplied by the userExternal Function
res must evaluate the residual
R = F t,y,y .  
The specification of res is:
void  res (Integer neq, double t, const double y[], const double ydot[], double r[], Integer *ires, Nag_Comm *comm)
1:     neq IntegerInput
On entry: the number of differential-algebraic equations being solved.
2:     t doubleInput
On entry: t, the current value of the independent variable.
3:     y[neq] const doubleInput
On entry: yi, for i=1,2,,neq, the current solution component.
4:     ydot[neq] const doubleInput
On entry: the derivative of the solution at the current point t.
5:     r[neq] doubleOutput
On exit: r[i-1] must contain the ith component of R, for i=1,2,,neq where
R = F t,y,ydot .  
6:     ires Integer *Input/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; nag_dae_ivp_dassl_gen (d02nec) 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 function; this will cause nag_dae_ivp_dassl_gen (d02nec) to exit with fail.code= NE_RES_FLAG.
7:     comm Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to res.
userdouble *
iuserInteger *
pPointer 
The type Pointer will be void *. Before calling nag_dae_ivp_dassl_gen (d02nec) you may allocate memory and initialize these pointers with various quantities for use by res when called from nag_dae_ivp_dassl_gen (d02nec) (see Section 3.3.1.1 in How to Use the NAG Library and its Documentation).
Note: res should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by nag_dae_ivp_dassl_gen (d02nec). If your code inadvertently does return any NaNs or infinities, nag_dae_ivp_dassl_gen (d02nec) is likely to produce unexpected results.
10:   jac function, supplied by the userExternal Function
Evaluates the matrix of partial derivatives, J, where
J ij = Fi yj + cj × Fi yj ,  i,j=1,2,,neq .  
If this option is not required, the actual argument for jac may be specified as NULLFN. 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 function nag_dae_ivp_dassl_setup (d02mwc).
The specification of jac is:
void  jac (Integer neq, double t, const double y[], const double ydot[], double pd[], double cj, Nag_Comm *comm)
1:     neq IntegerInput
On entry: the number of differential-algebraic equations being solved.
2:     t doubleInput
On entry: t, the current value of the independent variable.
3:     y[neq] const doubleInput
On entry: yi, for i=1,2,,neq, the current solution component.
4:     ydot[neq] const doubleInput
On entry: the derivative of the solution at the current point t.
5:     pd[dim] doubleInput/Output
Note: the dimension of the array pd will be neq×neq when the Jacobian is full and will be 2×ml+mu+1×neq when the Jacobian is banded (that is, a prior call to nag_dae_ivp_dassl_linalg (d02npc) has been made).
On entry: pd is preset to zero before the call to jac.
On exit: if the Jacobian is full then pd[j-1×neq+i-1]=Jij, for i=1,2,,neq and j=1,2,,neq; if the Jacobian is banded then pd[j-1×2ml+mu+1+ml+mu+i-j]=Jij, for max1,j-muiminn,j+ml; (see also in nag_dgbtrf (f07bdc)).
6:     cj doubleInput
On entry: cj is a scalar constant which will be defined in nag_dae_ivp_dassl_gen (d02nec).
7:     comm Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to jac.
userdouble *
iuserInteger *
pPointer 
The type Pointer will be void *. Before calling nag_dae_ivp_dassl_gen (d02nec) you may allocate memory and initialize these pointers with various quantities for use by jac when called from nag_dae_ivp_dassl_gen (d02nec) (see Section 3.3.1.1 in How to Use the NAG Library and its Documentation).
Note: jac should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by nag_dae_ivp_dassl_gen (d02nec). If your code inadvertently does return any NaNs or infinities, nag_dae_ivp_dassl_gen (d02nec) is likely to produce unexpected results.
11:   icom[50+neq] IntegerCommunication Array
icom contains information which is usually of no interest, but is necessary for subsequent calls. However you may find the following useful:
icom[21]
The order of the method to be attempted on the next step.
icom[22]
The order of the method used on the last step.
icom[25]
The number of steps taken so far.
icom[26]
The number of calls to res so far.
icom[27]
The number of evaluations of the matrix of partial derivatives needed so far.
icom[28]
The total number of error test failures so far.
icom[29]
The total number of convergence test failures so far.
12:   com[lcom] doubleCommunication Array
com contains information which is usually of no interest, but is necessary for subsequent calls. However you may find the following useful:
com[2]
The step size to be attempted on the next step.
com[3]
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 (itask=3).
13:   lcom IntegerInput
On entry: the dimension of the array com.
Constraint: lcom40+maxorder+4×neq+neq×p+q where maxorder is the maximum order that can be used by the integration method (see maxord in nag_dae_ivp_dassl_setup (d02mwc)); p=neq when the Jacobian is full and p=2×ml+mu+1 when the Jacobian is banded; and, q=neq/ml+mu+1+1 when the Jacobian is to be evaluated numerically and q=0 otherwise.
14:   comm Nag_Comm *
The NAG communication argument (see Section 3.3.1.1 in How to Use the NAG Library and its Documentation).
15:   fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

6
Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
NE_ARRAY_INPUT
All elements of rtol and atol are zero.
Some element of atol is less than zero.
Some element of rtol is less than zero.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_CONV_CONT
The corrector could not converge and the error test failed repeatedly. t=value. Stepsize h=value.
The corrector repeatedly failed to converge with h=hmin. t=value. Stepsize h=value.
NE_CONV_JACOBG
The iteration matrix is singular. t=value. Stepsize h=value.
NE_CONV_ROUNDOFF
The error test failed repeatedly with h=hmin. t=value. Stepsize h=value.
NE_INITIALIZATION
Either the initialization function has not been called prior to the first call of this function or a communication array has become corrupted.
NE_INT
A previous call to this function returned with itask=value and no appropriate action was taken.
NE_INT_2
com array is of insufficient length; length required =value; actual length lcom=value.
NE_INT_ARG_LT
On entry, neq=value.
Constraint: neq1.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_MAX_STEP
Maximum number of steps taken on this call before reaching tout: t=value, maximum number of steps =value.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_ODE_TOL
A solution component has become zero when a purely relative tolerance (zero absolute tolerance) was selected for that component. t=value, y[I-1]=value for component I=value.
Too much accuracy requested for precision of machine. rtol and atol were increased by scale factor R. Try running again with these scaled tolerances. t=value, R=value.
NE_REAL_2
tout is behind t in the direction of h: tout-t=value, h=value.
tout is too close to t to start integration: tout-t=value: hmin=value.
NE_REAL_ARG_EQ
On entry, t=value.
Constraint: toutt.
NE_RES_FLAG
ires was set to -1 during a call to res and could not be resolved. t=value. Stepsize h=value.
ires was set to -2 during a call to res. t=value. Stepsize =value.
Repeated occurrences of input constraint violations have been detected. This could result in a potential infinite loop: itask=value. Current violation corresponds to exit with fail.code=value.
NE_SINGULAR_POINT
The initial ydot could not be computed. t=value. Stepsize h=value.

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 vector_tol=Nag_FALSE with atol[0] small but positive).

8
Parallelism and Performance

nag_dae_ivp_dassl_gen (d02nec) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_dae_ivp_dassl_gen (d02nec) 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 function. 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 banded systems the cost is proportional to neq× ml+ mu+1 2 , while for full systems the cost is proportional to neq3. Note however that for moderately sized problems which are only mildly nonlinear the cost may be dominated by factors proportional to neq×ml+mu+1 and neq2 respectively.

10
Example

This example solves the well-known stiff Robertson problem written in implicit form
r1 = -0.04a + 1.0E4bc - a r2 = 0.04a - 1.0E4bc - 3.0E7b2 - b r3 = 3.0E7b2 - c  
with initial conditions a=1.0 and b=c=0.0 over the range 0,0.1 the BDF method (setup function nag_dae_ivp_dassl_setup (d02mwc) and nag_dae_ivp_dassl_linalg (d02npc)).

10.1
Program Text

Program Text (d02nece.c)

10.2
Program Data

None.

10.3
Program Results

Program Results (d02nece.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017