D02 Chapter Contents
D02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentD02QWF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

D02QWF is a setup routine which must be called prior to the first call of either of the integrators D02QFF and D02QGF and may be called prior to any continuation call to these routines.

## 2  Specification

 SUBROUTINE D02QWF ( STATEF, NEQF, VECTOL, ATOL, LATOL, RTOL, LRTOL, ONESTP, CRIT, TCRIT, HMAX, MAXSTP, NEQG, ALTERG, SOPHST, RWORK, LRWORK, IWORK, LIWORK, IFAIL)
 INTEGER NEQF, LATOL, LRTOL, MAXSTP, NEQG, LRWORK, IWORK(LIWORK), LIWORK, IFAIL REAL (KIND=nag_wp) ATOL(LATOL), RTOL(LRTOL), TCRIT, HMAX, RWORK(LRWORK) LOGICAL VECTOL, ONESTP, CRIT, ALTERG, SOPHST CHARACTER(1) STATEF

## 3  Description

D02QWF permits initialization of the integration method and setting of optional inputs prior to any call of D02QFF or D02QGF. It must be called before the first call of either of the routines D02QFF or D02QGF and it may be called before any continuation call of either of the routines D02QFF or D02QGF.

None.

## 5  Parameters

1:     STATEF – CHARACTER(1)Input/Output
On entry: specifies whether the integration routine (D02QFF or D02QGF) is to start a new system of ordinary differential equations, restart a system or continue with a system.
${\mathbf{STATEF}}=\text{'S'}$
Start integration with a new differential system.
${\mathbf{STATEF}}=\text{'R'}$
Restart integration with the current differential system.
${\mathbf{STATEF}}=\text{'C'}$
Continue integration with the current differential system.
Constraint: ${\mathbf{STATEF}}=\text{'S'}$, $\text{'R'}$ or $\text{'C'}$.
On exit: is set to 'C', except that if an error is detected, STATEF is unchanged.
2:     NEQF – INTEGERInput
On entry: the number of ordinary differential equations to be solved by the integration routine. NEQF must remain unchanged on subsequent calls to D02QWF with ${\mathbf{STATEF}}=\text{'C'}$ or $\text{'R'}$.
Constraint: ${\mathbf{NEQF}}\ge 1$.
3:     VECTOL – LOGICALInput
On entry: specifies whether vector or scalar error control is to be employed for the local error test in the integration.
If ${\mathbf{VECTOL}}=\mathrm{.TRUE.}$, then vector error control will be used and you must specify values of ${\mathbf{RTOL}}\left(\mathit{i}\right)$ and ${\mathbf{ATOL}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{NEQF}}$.
Otherwise scalar error control will be used and you must specify values of just ${\mathbf{RTOL}}\left(1\right)$ and ${\mathbf{ATOL}}\left(1\right)$.
The error test to be satisfied is of the form
 $∑i=1NEQF eiwi 2≤1.0.$
where ${w}_{i}$ is defined as follows:
 VECTOL ${w}_{i}$ .TRUE. ${\mathbf{RTOL}}\left(i\right)×\left|{y}_{i}\right|+{\mathbf{ATOL}}\left(i\right)$ .FALSE. ${\mathbf{RTOL}}\left(1\right)×\left|{y}_{i}\right|+{\mathbf{ATOL}}\left(1\right)$
and ${e}_{i}$ is an estimate of the local error in ${y}_{i}$, computed internally. VECTOL must remain unchanged on subsequent calls to D02QWF with ${\mathbf{STATEF}}=\text{'C'}$ or $\text{'R'}$.
4:     ATOL(LATOL) – REAL (KIND=nag_wp) arrayInput
On entry: the absolute local error tolerance (see VECTOL).
Constraint: ${\mathbf{ATOL}}\left(i\right)\ge 0.0$.
5:     LATOL – INTEGERInput
On entry: the dimension of the array ATOL as declared in the (sub)program from which D02QWF is called.
Constraints:
• if ${\mathbf{VECTOL}}=\mathrm{.TRUE.}$, ${\mathbf{LATOL}}\ge {\mathbf{NEQF}}$;
• if ${\mathbf{VECTOL}}=\mathrm{.FALSE.}$, ${\mathbf{LATOL}}\ge 1$.
6:     RTOL(LRTOL) – REAL (KIND=nag_wp) arrayInput
On entry: the relative local error tolerance (see VECTOL).
Constraints:
• ${\mathbf{RTOL}}\left(i\right)\ge 0.0$;
• if ${\mathbf{ATOL}}\left(i\right)=0.0$, .
7:     LRTOL – INTEGERInput
On entry: the dimension of the array RTOL as declared in the (sub)program from which D02QWF is called.
Constraints:
• if ${\mathbf{VECTOL}}=\mathrm{.TRUE.}$, ${\mathbf{LRTOL}}\ge {\mathbf{NEQF}}$;
• if ${\mathbf{VECTOL}}=\mathrm{.FALSE.}$, ${\mathbf{LRTOL}}\ge 1$.
8:     ONESTP – LOGICALInput
On entry: the mode of operation of the integration routine. If ${\mathbf{ONESTP}}=\mathrm{.TRUE.}$, the integration routine will operate in one-step mode, that is it will return after each successful step. Otherwise the integration routine will operate in interval mode, that is it will return at the end of the integration interval.
9:     CRIT – LOGICALInput
On entry: specifies whether or not there is a value for the independent variable beyond which integration is not to be attempted. Setting ${\mathbf{CRIT}}=\mathrm{.TRUE.}$ indicates that there is such a point, whereas ${\mathbf{CRIT}}=\mathrm{.FALSE.}$ indicates that there is no such restriction.
10:   TCRIT – REAL (KIND=nag_wp)Input
On entry: with ${\mathbf{CRIT}}=\mathrm{.TRUE.}$, TCRIT must be set to a value of the independent variable beyond which integration is not to be attempted. Otherwise TCRIT is not referenced.
11:   HMAX – REAL (KIND=nag_wp)Input
On entry: if ${\mathbf{HMAX}}\ne 0.0$, a bound on the absolute step size during the integration is taken to be $\left|{\mathbf{HMAX}}\right|$.
If ${\mathbf{HMAX}}=0.0$, no bound is assumed on the step size during the integration.
A bound may be required if there are features of the solution on very short ranges of integration which may be missed. You should try ${\mathbf{HMAX}}=0.0$ first.
Note:  this parameter only affects the step size if the option ${\mathbf{CRIT}}=\mathrm{.TRUE.}$ is being used.
12:   MAXSTP – INTEGERInput
On entry: a bound on the number of attempted steps in any one call to the integration routine. If ${\mathbf{MAXSTP}}\le 0$ on entry, a value of $1000$ is used.
13:   NEQG – INTEGERInput
On entry: specifies whether or not root-finding is required in D02QFF or D02QGF.
${\mathbf{NEQG}}\le 0$
No root-finding is attempted.
${\mathbf{NEQG}}>0$
Root-finding is required and NEQG event functions will be specified for the integration routine.
14:   ALTERG – LOGICALInput/Output
On entry: specifies whether or not the event functions have been redefined. ALTERG need not be set if ${\mathbf{STATEF}}=\text{'S'}$. On subsequent calls to D02QWF, if NEQG has been set positive, then ${\mathbf{ALTERG}}=\mathrm{.FALSE.}$ specifies that the event functions remain unchanged, whereas ${\mathbf{ALTERG}}=\mathrm{.TRUE.}$ specifies that the event functions have changed. Because of the expense in reinitializing the root searching procedure, ALTERG should be set to .TRUE. only if the event functions really have been altered. ALTERG need not be set if the root-finding option is not used.
On exit: is set to .FALSE..
15:   SOPHST – LOGICALInput
On entry: the type of search technique to be used in the root-finding. If ${\mathbf{SOPHST}}=\mathrm{.TRUE.}$ then a sophisticated and reliable but expensive technique will be used, whereas for ${\mathbf{SOPHST}}=\mathrm{.FALSE.}$ a simple but less reliable technique will be used. If ${\mathbf{NEQG}}\le 0$, SOPHST is not referenced.
16:   RWORK(LRWORK) – REAL (KIND=nag_wp) arrayCommunication Array
This must be the same parameter RWORK supplied to the integration routine. It is used to pass information to the integration routine and therefore the contents of this array must not be changed before calling the integration routine.
17:   LRWORK – INTEGERInput
On entry: the dimension of the array RWORK as declared in the (sub)program from which D02QWF is called.
Constraint: ${\mathbf{LRWORK}}\ge 21×\left(1+{\mathbf{NEQF}}\right)+2×\mathit{J}+\mathit{K}×{\mathbf{NEQG}}+2$, where
 $J= NEQF if ​VECTOL=.TRUE. 1 if ​VECTOL=.FALSE.$
and
 $K= 14 if ​ SOPHST=.TRUE. 5 if ​ SOPHST=.FALSE.$
.
18:   IWORK(LIWORK) – INTEGER arrayCommunication Array
This must be the same parameter IWORK supplied to the integration routine. It is used to pass information to the integration routine and therefore the contents of this array must not be changed before calling the integration routine.
19:   LIWORK – INTEGERInput
On entry: the dimension of the array IWORK as declared in the (sub)program from which D02QWF is called.
Constraints:
• if ${\mathbf{SOPHST}}=\mathrm{.TRUE.}$, ${\mathbf{LIWORK}}\ge 21+4×{\mathbf{NEQG}}$;
• if ${\mathbf{SOPHST}}=\mathrm{.FALSE.}$, ${\mathbf{LIWORK}}\ge 21+{\mathbf{NEQG}}$.
20:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. 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 $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{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}}={\mathbf{0}}$ or $-{\mathbf{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$
Illegal input detected.

Not applicable.

## 8  Further Comments

Prior to a continuation call of the integration routine, you may reset any of the optional parameters by calling D02QWF with ${\mathbf{STATEF}}=\text{'C'}$. You may reset:
 HMAX to alter the maximum step size selection; RTOL, ATOL to change the error requirements; MAXSTP to increase or decrease the number of attempted steps before an error exit is returned; ONESTP to change the operation mode of the integration routine; CRIT, TCRIT to alter the point beyond which integration must not be attempted; and NEQG, ALTERG, SOPHST to alter the number and type of event functions, and also the search method.
If the behaviour of the system of differential equations has altered and you wish to restart the integration method from the value of T output from the integration routine (see D02QFF and D02QGF), then STATEF should be set to ${\mathbf{STATEF}}=\text{'R'}$ and any of the optional parameters may be reset also. If you want to redefine the system of differential equations or start a new integration problem, then STATEF should be set to ${\mathbf{STATEF}}=\text{'S'}$. Resetting ${\mathbf{STATEF}}=\text{'R'}$ or $\text{'S'}$ on normal continuation calls causes a restart in the integration process, which is very inefficient when not needed.

## 9  Example

See Section 9 in D02QFF and D02QGF.