NAG Library Routine Document

d02tkf  (withdraw_bvp_coll_nlin)

 Contents

    1  Purpose
    7  Accuracy

1
Purpose

d02tkf solves a general two-point boundary value problem for a nonlinear mixed order system of ordinary differential equations.

2
Specification

Fortran Interface
Subroutine d02tkf ( ffun, fjac, gafun, gbfun, gajac, gbjac, guess, rcomm, icomm, ifail)
Integer, Intent (Inout):: icomm(*), ifail
Real (Kind=nag_wp), Intent (Inout):: rcomm(*)
External:: ffun, fjac, gafun, gbfun, gajac, gbjac, guess
C Header Interface
#include nagmk26.h
void  d02tkf_ (
void (NAG_CALL *ffun)( const double *x, const double y[], const Integer *neq, const Integer m[], double f[]),
void (NAG_CALL *fjac)( const double *x, const double y[], const Integer *neq, const Integer m[], double dfdy[]),
void (NAG_CALL *gafun)( const double ya[], const Integer *neq, const Integer m[], const Integer *nlbc, double ga[]),
void (NAG_CALL *gbfun)( const double yb[], const Integer *neq, const Integer m[], const Integer *nrbc, double gb[]),
void (NAG_CALL *gajac)( const double ya[], const Integer *neq, const Integer m[], const Integer *nlbc, double dgady[]),
void (NAG_CALL *gbjac)( const double yb[], const Integer *neq, const Integer m[], const Integer *nrbc, double dgbdy[]),
void (NAG_CALL *guess)( const double *x, const Integer *neq, const Integer m[], double y[], double dym[]),
double rcomm[], Integer icomm[], Integer *ifail)

3
Description

d02tkf and its associated routines (d02tvf, d02txf, d02tyf and d02tzf) solve the two-point boundary value problem for a nonlinear mixed order system of ordinary differential equations
y1m1 x = f1 x,y1,y11,,y1m1-1,y2,,ynmn-1 y2m2 x = f2 x,y1,y11,,y1m1-1,y2,,ynmn-1 ynmn x = fn x,y1,y11,,y1m1-1,y2,,ynmn-1  
over an interval a,b subject to p (>0) nonlinear boundary conditions at a and q (>0) nonlinear boundary conditions at b, where p+q = i=1 n mi . Note that yi m x is the mth derivative of the ith solution component. Hence yi 0 x=yix. The left boundary conditions at a are defined as
gizya=0,  i=1,2,,p,  
and the right boundary conditions at b as
g-jzyb=0,  j=1,2,,q,  
where y=y1,y2,,yn and
zyx = y1x, y11 x ,, y1m1-1 x ,y2x,, ynmn-1 x .  
First, d02tvf must be called to specify the initial mesh, error requirements and other details. Note that the error requirements apply only to the solution components y1,y2,,yn and that no error control is applied to derivatives of solution components. (If error control is required on derivatives then the system must be reduced in order by introducing the derivatives whose error is to be controlled as new variables. See Section 9 in d02tvf.) Then, d02tkf can be used to solve the boundary value problem. After successful computation, d02tzf can be used to ascertain details about the final mesh and other details of the solution procedure, and d02tyf can be used to compute the approximate solution anywhere on the interval a,b.
A description of the numerical technique used in d02tkf is given in Section 3 in d02tvf.
d02tkf can also be used in the solution of a series of problems, for example in performing continuation, when the mesh used to compute the solution of one problem is to be used as the initial mesh for the solution of the next related problem. d02txf should be used in between calls to d02tkf in this context.
See Section 9 in d02tvf for details of how to solve boundary value problems of a more general nature.
The routines are based on modified versions of the codes COLSYS and COLNEW (see Ascher et al. (1979) and Ascher and Bader (1987)). A comprehensive treatment of the numerical solution of boundary value problems can be found in Ascher et al. (1988) and Keller (1992).

4
References

Ascher U M and Bader G (1987) A new basis implementation for a mixed order boundary value ODE solver SIAM J. Sci. Stat. Comput. 8 483–500
Ascher U M, Christiansen J and Russell R D (1979) A collocation solver for mixed order systems of boundary value problems Math. Comput. 33 659–679
Ascher U M, Mattheij R M M and Russell R D (1988) Numerical Solution of Boundary Value Problems for Ordinary Differential Equations Prentice–Hall
Keller H B (1992) Numerical Methods for Two-point Boundary-value Problems Dover, New York

5
Arguments

1:     ffun – Subroutine, supplied by the user.External Procedure
ffun must evaluate the functions fi for given values x,zyx.
The specification of ffun is:
Fortran Interface
Subroutine ffun ( x, y, neq, m, f)
Integer, Intent (In):: neq, m(neq)
Real (Kind=nag_wp), Intent (In):: x, y(neq,0:*)
Real (Kind=nag_wp), Intent (Out):: f(neq)
C Header Interface
#include nagmk26.h
void  ffun ( const double *x, const double y[], const Integer *neq, const Integer m[], double f[])
1:     x – Real (Kind=nag_wp)Input
On entry: x, the independent variable.
2:     yneq0:* – Real (Kind=nag_wp) arrayInput
On entry: yij contains yi j x, for i=1,2,,neq and j=0,1,,mi-1.
Note:  yi 0 x=yix.
3:     neq – IntegerInput
On entry: the number of differential equations.
4:     mneq – Integer arrayInput
On entry: mi contains mi, the order of the ith differential equation, for i=1,2,,neq.
5:     fneq – Real (Kind=nag_wp) arrayOutput
On exit: fi must contain fi, for i=1,2,,neq.
ffun must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d02tkf is called. Arguments denoted as Input must not be changed by this procedure.
Note: ffun should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02tkf. If your code inadvertently does return any NaNs or infinities, d02tkf is likely to produce unexpected results.
2:     fjac – Subroutine, supplied by the user.External Procedure
fjac must evaluate the partial derivatives of fi with respect to the elements of
zyx=y1x,y11x,,y1 m1-1 x,y2x,,yn mn-1 x.
The specification of fjac is:
Fortran Interface
Subroutine fjac ( x, y, neq, m, dfdy)
Integer, Intent (In):: neq, m(neq)
Real (Kind=nag_wp), Intent (In):: x, y(neq,0:*)
Real (Kind=nag_wp), Intent (Inout):: dfdy(neq,neq,0:*)
C Header Interface
#include nagmk26.h
void  fjac ( const double *x, const double y[], const Integer *neq, const Integer m[], double dfdy[])
1:     x – Real (Kind=nag_wp)Input
On entry: x, the independent variable.
2:     yneq0:* – Real (Kind=nag_wp) arrayInput
On entry: yij contains yi j x, for i=1,2,,neq and j=0,1,,mi-1.
Note:  yi 0 x=yix.
3:     neq – IntegerInput
On entry: the number of differential equations.
4:     mneq – Integer arrayInput
On entry: mi contains mi, the order of the ith differential equation, for i=1,2,,neq.
5:     dfdyneqneq0:* – Real (Kind=nag_wp) arrayInput/Output
On entry: set to zero.
On exit: dfdyijk must contain the partial derivative of fi with respect to yj k , for i=1,2,,neq, j=1,2,,neq and k=0,1,,mj-1. Only nonzero partial derivatives need be set.
fjac must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d02tkf is called. Arguments denoted as Input must not be changed by this procedure.
Note: fjac should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02tkf. If your code inadvertently does return any NaNs or infinities, d02tkf is likely to produce unexpected results.
3:     gafun – Subroutine, supplied by the user.External Procedure
gafun must evaluate the boundary conditions at the left-hand end of the range, that is functions gizya for given values of zya.
The specification of gafun is:
Fortran Interface
Subroutine gafun ( ya, neq, m, nlbc, ga)
Integer, Intent (In):: neq, m(neq), nlbc
Real (Kind=nag_wp), Intent (In):: ya(neq,0:*)
Real (Kind=nag_wp), Intent (Out):: ga(nlbc)
C Header Interface
#include nagmk26.h
void  gafun ( const double ya[], const Integer *neq, const Integer m[], const Integer *nlbc, double ga[])
1:     yaneq0:* – Real (Kind=nag_wp) arrayInput
On entry: yaij contains yi j a, for i=1,2,,neq and j=0,1,,mi-1.
Note:  yi 0 a=yia.
2:     neq – IntegerInput
On entry: the number of differential equations.
3:     mneq – Integer arrayInput
On entry: mi contains mi, the order of the ith differential equation, for i=1,2,,neq.
4:     nlbc – IntegerInput
On entry: the number of boundary conditions at a.
5:     ganlbc – Real (Kind=nag_wp) arrayOutput
On exit: gai must contain gizya, for i=1,2,,nlbc.
gafun must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d02tkf is called. Arguments denoted as Input must not be changed by this procedure.
Note: gafun should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02tkf. If your code inadvertently does return any NaNs or infinities, d02tkf is likely to produce unexpected results.
4:     gbfun – Subroutine, supplied by the user.External Procedure
gbfun must evaluate the boundary conditions at the right-hand end of the range, that is functions g-izyb for given values of zyb.
The specification of gbfun is:
Fortran Interface
Subroutine gbfun ( yb, neq, m, nrbc, gb)
Integer, Intent (In):: neq, m(neq), nrbc
Real (Kind=nag_wp), Intent (In):: yb(neq,0:*)
Real (Kind=nag_wp), Intent (Out):: gb(nrbc)
C Header Interface
#include nagmk26.h
void  gbfun ( const double yb[], const Integer *neq, const Integer m[], const Integer *nrbc, double gb[])
1:     ybneq0:* – Real (Kind=nag_wp) arrayInput
On entry: ybij contains yi j b, for i=1,2,,neq and j=0,1,,mi-1.
Note:  yi 0 b=yib.
2:     neq – IntegerInput
On entry: the number of differential equations.
3:     mneq – Integer arrayInput
On entry: mi contains mi, the order of the ith differential equation, for i=1,2,,neq.
4:     nrbc – IntegerInput
On entry: the number of boundary conditions at b.
5:     gbnrbc – Real (Kind=nag_wp) arrayOutput
On exit: gbi must contain g-izyb, for i=1,2,,nrbc.
gbfun must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d02tkf is called. Arguments denoted as Input must not be changed by this procedure.
Note: gbfun should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02tkf. If your code inadvertently does return any NaNs or infinities, d02tkf is likely to produce unexpected results.
5:     gajac – Subroutine, supplied by the user.External Procedure
gajac must evaluate the partial derivatives of gizya with respect to the elements of zya=y1a,y11a,,y1 m1-1 a,y2a,,yn mn-1 a.
The specification of gajac is:
Fortran Interface
Subroutine gajac ( ya, neq, m, nlbc, dgady)
Integer, Intent (In):: neq, m(neq), nlbc
Real (Kind=nag_wp), Intent (In):: ya(neq,0:*)
Real (Kind=nag_wp), Intent (Inout):: dgady(nlbc,neq,0:*)
C Header Interface
#include nagmk26.h
void  gajac ( const double ya[], const Integer *neq, const Integer m[], const Integer *nlbc, double dgady[])
1:     yaneq0:* – Real (Kind=nag_wp) arrayInput
On entry: yaij contains yi j a, for i=1,2,,neq and j=0,1,,mi-1.
Note:  yi 0 a=yia.
2:     neq – IntegerInput
On entry: the number of differential equations.
3:     mneq – Integer arrayInput
On entry: mi contains mi, the order of the ith differential equation, for i=1,2,,neq.
4:     nlbc – IntegerInput
On entry: the number of boundary conditions at a.
5:     dgadynlbcneq0:* – Real (Kind=nag_wp) arrayInput/Output
On entry: set to zero.
On exit: dgadyijk must contain the partial derivative of gizya with respect to yj k a, for i=1,2,,nlbc, j=1,2,,neq and k=0,1,,mj-1. Only nonzero partial derivatives need be set.
gajac must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d02tkf is called. Arguments denoted as Input must not be changed by this procedure.
Note: gajac should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02tkf. If your code inadvertently does return any NaNs or infinities, d02tkf is likely to produce unexpected results.
6:     gbjac – Subroutine, supplied by the user.External Procedure
gbjac must evaluate the partial derivatives of g-izyb with respect to the elements of zyb=y1b,y11b,,y1 m1-1 b,y2b,,yn mn-1 b.
The specification of gbjac is:
Fortran Interface
Subroutine gbjac ( yb, neq, m, nrbc, dgbdy)
Integer, Intent (In):: neq, m(neq), nrbc
Real (Kind=nag_wp), Intent (In):: yb(neq,0:*)
Real (Kind=nag_wp), Intent (Inout):: dgbdy(nrbc,neq,0:*)
C Header Interface
#include nagmk26.h
void  gbjac ( const double yb[], const Integer *neq, const Integer m[], const Integer *nrbc, double dgbdy[])
1:     ybneq0:* – Real (Kind=nag_wp) arrayInput
On entry: ybij contains yi j b, for i=1,2,,neq and j=0,1,,mi-1.
Note:  yi 0 b=yib.
2:     neq – IntegerInput
On entry: the number of differential equations.
3:     mneq – Integer arrayInput
On entry: mi contains mi, the order of the ith differential equation, for i=1,2,,neq.
4:     nrbc – IntegerInput
On entry: the number of boundary conditions at b.
5:     dgbdynrbcneq0:* – Real (Kind=nag_wp) arrayInput/Output
On entry: set to zero.
On exit: dgbdyijk must contain the partial derivative of g-izyb with respect to yj k b, for i=1,2,,nrbc, j=1,2,,neq and k=0,1,,mj-1. Only nonzero partial derivatives need be set.
gbjac must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d02tkf is called. Arguments denoted as Input must not be changed by this procedure.
Note: gbjac should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02tkf. If your code inadvertently does return any NaNs or infinities, d02tkf is likely to produce unexpected results.
7:     guess – Subroutine, supplied by the user.External Procedure
guess must return initial approximations for the solution components yi j  and the derivatives yi mi , for i=1,2,,neq and j=0,1,,mi-1. Try to compute each derivative yi mi  such that it corresponds to your approximations to y i j , for j=0,1,,mi-1. You should not call ffun to compute yi mi .
If d02tkf is being used in conjunction with d02txf as part of a continuation process, guess is not called by d02tkf after the call to d02txf.
The specification of guess is:
Fortran Interface
Subroutine guess ( x, neq, m, y, dym)
Integer, Intent (In):: neq, m(neq)
Real (Kind=nag_wp), Intent (In):: x
Real (Kind=nag_wp), Intent (Inout):: y(neq,0:*)
Real (Kind=nag_wp), Intent (Out):: dym(neq)
C Header Interface
#include nagmk26.h
void  guess ( const double *x, const Integer *neq, const Integer m[], double y[], double dym[])
1:     x – Real (Kind=nag_wp)Input
On entry: x, the independent variable; xa,b.
2:     neq – IntegerInput
On entry: the number of differential equations.
3:     mneq – Integer arrayInput
On entry: mi contains mi, the order of the ith differential equation, for i=1,2,,neq.
4:     yneq0:* – Real (Kind=nag_wp) arrayOutput
On exit: yij must contain yi j x, for i=1,2,,neq and j=0,1,,mi-1.
Note:  yi 0 x=yix.
5:     dymneq – Real (Kind=nag_wp) arrayOutput
On exit: dymi must contain yi mi x, for i=1,2,,neq.
guess must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d02tkf is called. Arguments denoted as Input must not be changed by this procedure.
Note: guess should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02tkf. If your code inadvertently does return any NaNs or infinities, d02tkf is likely to produce unexpected results.
8:     rcomm* – Real (Kind=nag_wp) arrayCommunication Array
On entry: this must be the same array as supplied to d02tvf and must remain unchanged between calls.
On exit: contains information about the solution for use on subsequent calls to associated routines.
9:     icomm* – Integer arrayCommunication Array
On entry: this must be the same array as supplied to d02tvf and must remain unchanged between calls.
On exit: contains information about the solution for use on subsequent calls to associated routines.
10:   ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1​ or ​1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, because for this routine the values of the output arguments may be useful even if ifail0 on exit, the recommended value is -1. When the value -1​ or ​1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6
Error Indicators and Warnings

If on entry ifail=0 or -1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Note: d02tkf may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
ifail=1
On entry, an invalid call was made to d02tkf, for example, without a previous call to the setup routine d02tvf.
ifail=2
Numerical singularity has been detected in the Jacobian used in the underlying Newton iteration. No meaningful results have been computed. You should check carefully how you have coded fjac, gajac and gbjac. If the user-supplied routines have been coded correctly then supplying a different initial approximation to the solution in guess might be appropriate. See also Section 9.
ifail=3
The nonlinear iteration has failed to converge. At no time during the computation was convergence obtained and no meaningful results have been computed. You should check carefully how you have coded procedures fjac, gajac and gbjac. If the procedures have been coded correctly then supplying a better initial approximation to the solution in guess might be appropriate. See also Section 9.
ifail=4
The nonlinear iteration has failed to converge. At some earlier time during the computation convergence was obtained and the corresponding results have been returned for diagnostic purposes and may be inspected by a call to d02tzf. Nothing can be said regarding the suitability of these results for use in any subsequent computation for the same problem. You should try to provide a better mesh and initial approximation to the solution in guess. See also Section 9.
ifail=5
The expected number of sub-intervals required exceeds the maximum number specified by the argument mxmesh in the setup routine d02tvf. Results for the last mesh on which convergence was obtained have been returned. Nothing can be said regarding the suitability of these results for use in any subsequent computation for the same problem. An indication of the error in the solution on the last mesh where convergence was obtained can be obtained by calling d02tzf. The error requirements may need to be relaxed and/or the maximum number of mesh points may need to be increased. See also Section 9.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

7
Accuracy

The accuracy of the solution is determined by the argument tols in the prior call to d02tvf (see Sections 3 and 9 in d02tvf for details and advice). Note that error control is applied only to solution components (variables) and not to any derivatives of the solution. An estimate of the maximum error in the computed solution is available by calling d02tzf.

8
Parallelism and Performance

d02tkf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
d02tkf 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.

9
Further Comments

If d02tkf returns with ifail=2, 3, 4 or 5 and the call to d02tkf was a part of some continuation procedure for which successful calls to d02tkf have already been made, then it is possible that the adjustment(s) to the continuation argument(s) between calls to d02tkf is (are) too large for the problem under consideration. More conservative adjustment(s) to the continuation argument(s) might be appropriate.

10
Example

The following example is used to illustrate the treatment of a high-order system, control of the error in a derivative of a component of the original system, and the use of continuation. See also d02tvf, d02txf, d02tyf and d02tzf, for the illustration of other facilities.
Consider the steady flow of an incompressible viscous fluid between two infinite coaxial rotating discs. See Ascher et al. (1979) and the references therein. The governing equations are
1R f+ff+gg = 0 1R g+fg-fg = 0  
subject to the boundary conditions
f0=f0= 0,   g0=Ω0,   f1=f1= 0,   g1=Ω1,  
where R is the Reynolds number and Ω0,Ω1 are the angular velocities of the disks.
We consider the case of counter-rotation and a symmetric solution, that is Ω0=1, Ω1=-1. This problem is more difficult to solve, the larger the value of R. For illustration, we use simple continuation to compute the solution for three different values of R (=106,108,1010). However, this problem can be addressed directly for the largest value of R considered here. Instead of the values suggested in Section 5 in d02txf for nmesh, ipmesh and mesh in the call to d02txf prior to a continuation call, we use every point of the final mesh for the solution of the first value of R, that is we must modify the contents of ipmesh. For illustrative purposes we wish to control the computed error in f and so recast the equations as
y1 = y2 y2 = -Ry1y2+y3y3 y3 = Ry2y3-y1y3  
subject to the boundary conditions
y10=y20= 0,   y30=Ω,   y11=y21= 0,   y31=-Ω,   Ω=1.  
For the symmetric boundary conditions considered, there exists an odd solution about x=0.5. Hence, to satisfy the boundary conditions, we use the following initial approximations to the solution in guess:
y1x = -x2x-12 x-1 2 y2x = -xx-15x2-5x+1 y3x = -8Ω x-12 3.  

10.1
Program Text

Program Text (d02tkfe.f90)

10.2
Program Data

Program Data (d02tkfe.d)

10.3
Program Results

Program Results (d02tkfe.r)

GnuplotProduced by GNUPLOT 4.6 patchlevel 3 −0.1 −0.05 0 0.05 0.1 0.15 0.2 0 0.2 0.4 0.6 0.8 1 −1 −0.5 0 0.5 1 f and f' g X Example Program Incompressible Fluid Flow between Coaxial Rotating Discs Solutions for Reynold's Number 1,000,000 f f' g gnuplot_plot_1 gnuplot_plot_2 gnuplot_plot_3
GnuplotProduced by GNUPLOT 4.6 patchlevel 3 −0.02 0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0 0.2 0.4 0.6 0.8 1 −1 −0.5 0 0.5 1 f and f' g X Incompressible Fluid Flow between Coaxial Rotating Discs Solutions for Reynold's Number 100,000,000 f f' g gnuplot_plot_1 gnuplot_plot_2 gnuplot_plot_3
GnuplotProduced by GNUPLOT 4.6 patchlevel 3 −0.02 0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0 0.2 0.4 0.6 0.8 1 −1 −0.5 0 0.5 1 f and f' g X Incompressible Fluid Flow between Coaxial Rotating Discs Solutions for Reynold's Number 10,000,000,000 f f' g gnuplot_plot_1 gnuplot_plot_2 gnuplot_plot_3
© The Numerical Algorithms Group Ltd, Oxford, UK. 2017