NAG AD Library
d02bj (ivp_rk_zero_simple)

Settings help

AD Name Style:


AD Specification Language:

1 Purpose

d02bj is the AD Library version of the primal routine d02bjf. Based (in the C++ interface) on overload resolution, d02bj can be used for primal, tangent and adjoint evaluation. It supports tangents and adjoints of first and second order.

2 Specification

Fortran Interface
Subroutine d02bj_AD_f ( ad_handle, x, xend, n, y, fcn, tol, relabs, output, g, w, ifail)
Integer, Intent (In) :: n
Integer, Intent (Inout) :: ifail
External :: g, fcn, output
ADTYPE, Intent (In) :: xend, tol
ADTYPE, Intent (Inout) :: x, y(n)
ADTYPE, Intent (Out) :: w(20*n)
Character (1), Intent (In) :: relabs
Type (c_ptr), Intent (Inout) :: ad_handle
Corresponding to the overloaded C++ function, the Fortran interface provides five routines with names reflecting the type used for active real arguments. The actual subroutine and type names are formed by replacing AD and ADTYPE in the above as follows:
when ADTYPE is Real(kind=nag_wp) then AD is p0w
when ADTYPE is Type(nagad_a1w_w_rtype) then AD is a1w
when ADTYPE is Type(nagad_t1w_w_rtype) then AD is t1w
when ADTYPE is Type(nagad_a1t1w_w_rtype) then AD is a1t1w
when ADTYPE is Type(nagad_t2w_w_rtype) then AD is t2w
C++ Header Interface
#include <dco.hpp>
#include <nagad.h>
namespace nag {
namespace ad {
void d02bj ( void *&ad_handle, ADTYPE &x, const ADTYPE &xend, const Integer &n, ADTYPE y[],
void (NAG_CALL fcn)(void *&ad_handle, const ADTYPE &x, const ADTYPE y[], ADTYPE f[]),
const ADTYPE &tol, const char *relabs,
void (NAG_CALL output)(void *&ad_handle, ADTYPE &xsol, const ADTYPE y[]),
void (NAG_CALL g)(void *&ad_handle, const ADTYPE &x, const ADTYPE y[], ADTYPE &retval),
ADTYPE w[], Integer &ifail)
}
}
The function is overloaded on ADTYPE which represents the type of active arguments. ADTYPE may be any of the following types:
double,
dco::ga1s<double>::type,
dco::gt1s<double>::type,
dco::gt1s<dco::gt1s<double>::type>::type,
dco::ga1s<dco::gt1s<double>::type>::type,
Note: this function can be used with AD tools other than dco/c++. For details, please contact NAG.

3 Description

d02bj is the AD Library version of the primal routine d02bjf.
d02bjf integrates a system of first-order ordinary differential equations over an interval with suitable initial conditions, using a fixed order Runge–Kutta method, until a user-specified function, if supplied, of the solution is zero, and returns the solution at points specified by you, if desired. For further information see Section 3 in the documentation for d02bjf.

4 References

Shampine L F (1994) Numerical solution of ordinary differential equations Chapman and Hall

5 Arguments

In addition to the arguments present in the interface of the primal routine, d02bj includes some arguments specific to AD.
A brief summary of the AD specific arguments is given below. For the remainder, links are provided to the corresponding argument from the primal routine. A tooltip popup for all arguments can be found by hovering over the argument name in Section 2 and in this section.
1: ad_handle – Pointer to AD Data Input/Output
On entry: a handle to the AD configuration data object, as created by x10aa.
2: xADTYPE Input/Output
3: xendADTYPE Input
4: n – Integer Input
5: y(n) – ADTYPE array Input/Output
6: fcn – Subroutine External Procedure
The specification of fcn is:
Fortran Interface
Subroutine fcn ( ad_handle, x, y, f)
ADTYPE, Intent (In) :: x, y(*)
ADTYPE, Intent (Inout) :: f(*)
Type (c_ptr), Intent (Inout) :: ad_handle
C++ Header Interface
void fcn ( void *&ad_handle, const ADTYPE &x, const ADTYPE y[], ADTYPE f[])
1: ad_handle – Pointer to AD Data Input/Output
On entry: a handle to the AD configuration data object.
2: xADTYPE Input
3: yADTYPE array Input
4: fADTYPE array Output
7: tolADTYPE Input
8: relabs – character Input
9: output – Subroutine External Procedure
If a null pointer is used as the argument, then a NAG supplied routine will be used as the argument for this parameter (C++ only). For the Fortran interface, the NAG supplied routine d02bj_AD_x may be used as the actual argument for this parameter.
The specification of output is:
Fortran Interface
Subroutine output ( ad_handle, xsol, y)
ADTYPE, Intent (In) :: y(*)
ADTYPE, Intent (Inout) :: xsol
Type (c_ptr), Intent (Inout) :: ad_handle
C++ Header Interface
void output ( void *&ad_handle, ADTYPE &xsol, const ADTYPE y[])
1: ad_handle – Pointer to AD Data Input/Output
On entry: a handle to the AD configuration data object.
2: xsolADTYPE Input/Output
3: yADTYPE array Input
10: g – Subroutine External Procedure
Note that g is a subroutine in this interface, returning the function value via the additional output parameter retval. If a null pointer is used as the argument, then a NAG supplied routine will be used as the argument for this parameter (C++ only). For the Fortran interface, the NAG supplied routine d02bj_AD_w may be used as the actual argument for this parameter.
The specification of g is:
Fortran Interface
Subroutine g ( ad_handle, x, y, retval)
ADTYPE, Intent (In) :: x, y(*)
ADTYPE, Intent (Out) :: retval
Type (c_ptr), Intent (Inout) :: ad_handle
C++ Header Interface
void g ( void *&ad_handle, const ADTYPE &x, const ADTYPE y[], ADTYPE &retval)
1: ad_handle – Pointer to AD Data Input/Output
On entry: a handle to the AD configuration data object.
2: xADTYPE Input
3: yADTYPE array Input
4: retvalADTYPE Output
On exit: the value of g(x,y) at the specified point.
11: w(20×n) – ADTYPE array Workspace
12: ifail – Integer Input/Output

6 Error Indicators and Warnings

d02bj preserves all error codes from d02bjf and in addition can return:
ifail=-89
An unexpected AD error has been triggered by this routine. Please contact NAG.
See Section 4.8.2 in the NAG AD Library Introduction for further information.
ifail=-199
The routine was called using a mode that has not yet been implemented.
ifail=-443
On entry: ad_handle is nullptr.
This check is only made if the overloaded C++ interface is used with arguments not of type double.
ifail=-444
A C++ exception was thrown.
The error message will show the details of the C++ exception text.
ifail=-899
Dynamic memory allocation failed for AD.
See Section 4.8.1 in the NAG AD Library Introduction for further information.

7 Accuracy

Not applicable.

8 Parallelism and Performance

d02bj is not threaded in any implementation.

9 Further Comments

None.

10 Example

The following examples are variants of the example for d02bjf, modified to demonstrate calling the NAG AD Library.
Description of the primal example.
This example illustrates the solution of four different problems. In each case the differential system (for a projectile) is
y=tanϕ v= -0.032tanϕv- 0.02v cosϕ ϕ= -0.032v2  
over an interval x=0.0 to xend=10.0 starting with values y=0.5, v=0.5 and ϕ=π/5. We solve each of the following problems with local error tolerances 1.0E−4 and 1.0E−5.
  1. (i)To integrate to x=10.0 producing intermediate output at intervals of 2.0 until a root is encountered where y=0.0.
  2. (ii)As (i) but with no intermediate output.
  3. (iii)As (i) but with no termination on a root-finding condition.
  4. (iv)As (i) but with no intermediate output and no root-finding termination condition.

10.1 Adjoint modes

Language Source File Data Results
Fortran d02bj_a1w_fe.f90 d02bj_a1w_fe.d d02bj_a1w_fe.r
C++ d02bj_a1w_hcppe.cpp None d02bj_a1w_hcppe.r

10.2 Tangent modes

Language Source File Data Results
Fortran d02bj_t1w_fe.f90 d02bj_t1w_fe.d d02bj_t1w_fe.r
C++ d02bj_t1w_hcppe.cpp None d02bj_t1w_hcppe.r

10.3 Passive mode

Language Source File Data Results
Fortran d02bj_p0w_fe.f90 d02bj_p0w_fe.d d02bj_p0w_fe.r
C++ d02bj_p0w_hcppe.cpp None d02bj_p0w_hcppe.r