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, iuser, ruser, ifail)
Integer, Intent (In) :: n
Integer, Intent (Inout) :: iuser(*), ifail
External :: g, fcn, output
ADTYPE, Intent (In) :: xend, tol
ADTYPE, Intent (Inout) :: x, y(n), ruser(*)
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++ Interface
#include <dco.hpp>
#include <nagad.h>
namespace nag {
namespace ad {
template <typename FCN_T, typename OUTPUT_T, typename G_T>
void d02bj ( handle_t &ad_handle, ADTYPE &x, const ADTYPE &xend, const Integer &n, ADTYPE y[], FCN_T &&fcn, const ADTYPE &tol, const char *relabs, OUTPUT_T &&output, G_T &&g, 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_handlenag::ad::handle_t Input/Output
On entry: a configuration object that holds information on the differentiation strategy. Details on setting the AD strategy are described in AD handle object in the NAG AD Library Introduction.
2: xADTYPE Input/Output
Please consult Overwriting of Inputs in the NAG AD Library Introduction.
3: xendADTYPE Input
4: n – Integer Input
5: y(n) – ADTYPE array Input/Output
Please consult Overwriting of Inputs in the NAG AD Library Introduction.
6: fcn – Callable Input
fcn needs to be callable with the specification listed below. This can be a C++ lambda, a functor or a (static member) function pointer. If using a lambda, parameters can be captured safely by reference. No copies of the callable are made internally.
The specification of fcn is:
Fortran Interface
Subroutine fcn ( ad_handle, x, y, f, iuser, ruser)
Integer, Intent (Inout) :: iuser(*)
ADTYPE, Intent (In) :: x, y(*)
ADTYPE, Intent (Inout) :: f(*), ruser(*)
Type (c_ptr), Intent (Inout) :: ad_handle
C++ Interface
auto fcn = [&]( const handle_t &ad_handle, const ADTYPE &x, const ADTYPE y[], ADTYPE f[])
1: ad_handlenag::ad::handle_t Input/Output
On entry: a handle to the AD handle object.
2: xADTYPE Input
3: yADTYPE array Input
4: fADTYPE array Output
*: iuser(*) – Integer array User Workspace
*: ruser(*)ADTYPE array User Workspace
7: tolADTYPE Input
8: relabs – character Input
9: output – Callable Input
output needs to be callable with the specification listed below. This can be a C++ lambda, a functor or a (static member) function pointer. If using a lambda, parameters can be captured safely by reference. No copies of the callable are made internally.
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, iuser, ruser)
Integer, Intent (Inout) :: iuser(*)
ADTYPE, Intent (In) :: y(*)
ADTYPE, Intent (Inout) :: xsol, ruser(*)
Type (c_ptr), Intent (Inout) :: ad_handle
C++ Interface
auto output = [&]( const handle_t &ad_handle, ADTYPE &xsol, const ADTYPE y[])
1: ad_handlenag::ad::handle_t Input/Output
On entry: a handle to the AD handle object.
2: xsolADTYPE Input/Output
3: yADTYPE array Input
*: iuser(*) – Integer array User Workspace
*: ruser(*)ADTYPE array User Workspace
10: g – Callable Input
g needs to be callable with the specification listed below. This can be a C++ lambda, a functor or a (static member) function pointer. If using a lambda, parameters can be captured safely by reference. No copies of the callable are made internally.
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.
Note that g is a subroutine in this interface, returning the function value via the additional output parameter retval.
The specification of g is:
Fortran Interface
Subroutine g ( ad_handle, x, y, retval, iuser, ruser)
Integer, Intent (Inout) :: iuser(*)
ADTYPE, Intent (In) :: x, y(*)
ADTYPE, Intent (Inout) :: ruser(*)
ADTYPE, Intent (Out) :: retval
Type (c_ptr), Intent (Inout) :: ad_handle
C++ Interface
auto g = [&]( const handle_t &ad_handle, const ADTYPE &x, const ADTYPE y[], ADTYPE &retval)
1: ad_handlenag::ad::handle_t Input/Output
On entry: a handle to the AD handle object.
2: xADTYPE Input
3: yADTYPE array Input
4: retvalADTYPE Output
On exit: the value of g(x,y) at the specified point.
*: iuser(*) – Integer array User Workspace
*: ruser(*)ADTYPE array User Workspace
11: w(20×n) – ADTYPE array Workspace
*: iuser(*) – Integer array User Workspace
User workspace.
*: ruser(*) – ADTYPE array User Workspace
User 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 Error Handling in the NAG AD Library Introduction for further information.
ifail=-199
The routine was called using a strategy that has not yet been implemented.
See AD Strategies in the NAG AD Library Introduction for further information.
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 Error Handling 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_a1t1w_fe.f90 d02bj_a1t1w_fe.d d02bj_a1t1w_fe.r
Fortran d02bj_a1w_fe.f90 d02bj_a1w_fe.d d02bj_a1w_fe.r
C++ d02bj_a1_algo_dcoe.cpp None d02bj_a1_algo_dcoe.r
C++ d02bj_a1t1_algo_dcoe.cpp None d02bj_a1t1_algo_dcoe.r

10.2 Tangent modes

Language Source File Data Results
Fortran d02bj_t1w_fe.f90 d02bj_t1w_fe.d d02bj_t1w_fe.r
Fortran d02bj_t2w_fe.f90 d02bj_t2w_fe.d d02bj_t2w_fe.r
C++ d02bj_t1_algo_dcoe.cpp None d02bj_t1_algo_dcoe.r
C++ d02bj_t2_algo_dcoe.cpp None d02bj_t2_algo_dcoe.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_passive_dcoe.cpp None d02bj_passive_dcoe.r