D03RAF (PDF version)
D03 Chapter Contents
D03 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

D03RAF

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.

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

D03RAF integrates a system of linear or nonlinear, time-dependent partial differential equations (PDEs) in two space dimensions on a rectangular domain. The method of lines is employed to reduce the PDEs to a system of ordinary differential equations (ODEs) which are solved using a backward differentiation formula (BDF) method. The resulting system of nonlinear equations is solved using a modified Newton method and a Bi-CGSTAB iterative linear solver with ILU preconditioning. Local uniform grid refinement is used to improve the accuracy of the solution. D03RAF originates from the VLUGR2 package (see Blom and Verwer (1993) and Blom et al. (1996)).

2  Specification

SUBROUTINE D03RAF ( NPDE, TS, TOUT, DT, XMIN, XMAX, YMIN, YMAX, NX, NY, TOLS, TOLT, PDEDEF, BNDARY, PDEIV, MONITR, OPTI, OPTR, RWK, LENRWK, IWK, LENIWK, LWK, LENLWK, ITRACE, IND, IFAIL)
INTEGER  NPDE, NX, NY, OPTI(4), LENRWK, IWK(LENIWK), LENIWK, LENLWK, ITRACE, IND, IFAIL
REAL (KIND=nag_wp)  TS, TOUT, DT(3), XMIN, XMAX, YMIN, YMAX, TOLS, TOLT, OPTR(3,NPDE), RWK(LENRWK)
LOGICAL  LWK(LENLWK)
EXTERNAL  PDEDEF, BNDARY, PDEIV, MONITR

3  Description

D03RAF integrates the system of PDEs:
Fjt,x,y,u,ut,ux,uy,uxx,uxy,uyy=0,  j=1,2,,NPDE, (1)
for x and y in the rectangular domain xminxxmax, yminyymax, and time interval t0ttout, where the vector u is the set of solution values
ux,y,t=u1x,y,t,,uNPDEx,y,tT,
and ut denotes partial differentiation with respect to t, and similarly for ux etc.
The functions Fj must be supplied by you in PDEDEF. Similarly the initial values of the functions ux,y,t must be specified at t=t0 in PDEIV.
Note that whilst complete generality is offered by the master equations (1), D03RAF is not appropriate for all PDEs. In particular, hyperbolic systems should not be solved using this routine. Also, at least one component of ut must appear in the system of PDEs.
The boundary conditions must be supplied by you in BNDARY in the form
Gj t,x,y,u,ut,ux,uy = 0 , (2)
for all y when xmin  or xmax  and for all x when y=ymin  or y=ymax  and j=1,2,,NPDE
The domain is covered by a uniform coarse base grid of size nx×ny specified by you, and nested finer uniform subgrids are subsequently created in regions with high spatial activity. The refinement is controlled using a space monitor which is computed from the current solution and a user-supplied space tolerance TOLS. A number of optional parameters, e.g., the maximum number of grid levels at any time, and some weighting factors, can be specified in the arrays OPTI and OPTR. Further details of the refinement strategy can be found in Section 8.
The system of PDEs and the boundary conditions are discretized in space on each grid using a standard second-order finite difference scheme (centred on the internal domain and one-sided at the boundaries), and the resulting system of ODEs is integrated in time using a second-order, two-step, implicit BDF method with variable step size. The time integration is controlled using a time monitor computed at each grid level from the current solution and a user-supplied time tolerance TOLT, and some further optional user-specified weighting factors held in OPTR (see Section 8 for details). The time monitor is used to compute a new step size, subject to restrictions on the size of the change between steps, and (optional) user-specified maximum and minimum step sizes held in DT. The step size is adjusted so that the remaining integration interval is an integer number times Δt. In this way a solution is obtained at t=tout.
A modified Newton method is used to solve the nonlinear equations arising from the time integration. You may specify (in OPTI) the maximum number of Newton iterations to be attempted. A Jacobian matrix is calculated at the beginning of each time step. If the Newton process diverges or the maximum number of iterations is exceeded, a new Jacobian is calculated using the most recent iterates and the Newton process is restarted. If convergence is not achieved after the (optional) user-specified maximum number of new Jacobian evaluations, the time step is retried with Δt=Δt/4. The linear systems arising from the Newton iteration are solved using a Bi-CGSTAB iterative method, in combination with ILU preconditioning. The maximum number of iterations can be specified by you in OPTI.
The solution at all grid levels is stored in the workspace arrays, along with other information needed for a restart (i.e., a continuation call). It is not intended that you extract the solution from these arrays, indeed the necessary information regarding these arrays is not included. The user-supplied monitor MONITR should be used to obtain the solution at particular levels and times. MONITR is called at the end of every time step, with the last step being identified via the input parameter TLAST.
Within PDEIV, PDEDEF, BNDARY and MONITR the data structure is as follows. Each point on a particular grid is given an index (ranging from 1 to the total number of points on the grid) and all coordinate or solution information is stored in arrays according to this index, e.g., Xi and Yi contain the x- and y coordinate of point i, and Uij contains the jth solution component uj at point i.
Further details of the underlying algorithm can be found in Section 8 and in Blom and Verwer (1993) and Blom et al. (1996) and the references therein.

4  References

Adjerid S and Flaherty J E (1988) A local refinement finite element method for two-dimensional parabolic systems SIAM J. Sci. Statist. Comput. 9 792–811
Blom J G, Trompert R A and Verwer J G (1996) Algorithm 758. VLUGR2: A vectorizable adaptive grid solver for PDEs in 2D Trans. Math. Software 22 302–328
Blom J G and Verwer J G (1993) VLUGR2: A vectorized local uniform grid refinement code for PDEs in 2D Report NM-R9306 CWI, Amsterdam
Brown P N, Hindmarsh A C and Petzold L R (1994) Using Krylov methods in the solution of large scale differential-algebraic systems SIAM J. Sci. Statist. Comput. 15 1467–1488
Trompert R A (1993) Local uniform grid refinement and systems of coupled partial differential equations Appl. Numer. Maths 12 331–355
Trompert R A and Verwer J G (1993) Analysis of the implicit Euler local uniform grid refinement method SIAM J. Sci. Comput. 14 259–278

5  Parameters

1:     NPDE – INTEGERInput
On entry: the number of PDEs in the system.
Constraint: NPDE1.
2:     TS – REAL (KIND=nag_wp)Input/Output
On entry: the initial value of the independent variable t.
On exit: the value of t which has been reached. Normally TS=TOUT.
Constraint: TS<TOUT.
3:     TOUT – REAL (KIND=nag_wp)Input
On entry: the final value of t to which the integration is to be carried out.
4:     DT(3) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the initial, minimum and maximum time step sizes respectively.
DT1
Specifies the initial time step size to be used on the first entry, i.e., when IND=0. If DT1=0.0 then the default value DT1=0.01×TOUT-TS is used. On subsequent entries (IND=1), the value of DT1 is not referenced.
DT2
Specifies the minimum time step size to be attempted by the integrator. If DT2=0.0 the default value DT2=10.0×machine precision is used.
DT3
Specifies the maximum time step size to be attempted by the integrator. If DT3=0.0 the default value DT3=TOUT-TS is used.
On exit: DT1 contains the time step size for the next time step. DT2 and DT3 are unchanged or set to their default values if zero on entry.
Constraints:
  • if IND=0, DT10.0;
  • if IND=0 and DT1>0.0, 10.0×machine precision×maxTS,TOUTDT1TOUT-TS and DT2DT1DT3, where the values of DT2 and DT3 will have been reset to their default values if zero on entry;
  • 0 DT2 DT3 .
5:     XMIN – REAL (KIND=nag_wp)Input
6:     XMAX – REAL (KIND=nag_wp)Input
On entry: the extents of the rectangular domain in the x-direction, i.e., the x coordinates of the left and right boundaries respectively.
Constraint: XMIN<XMAX and XMAX must be sufficiently distinguishable from XMIN for the precision of the machine being used.
7:     YMIN – REAL (KIND=nag_wp)Input
8:     YMAX – REAL (KIND=nag_wp)Input
On entry: the extents of the rectangular domain in the y-direction, i.e., the y coordinates of the lower and upper boundaries respectively.
Constraint: YMIN<YMAX and YMAX must be sufficiently distinguishable from YMIN for the precision of the machine being used.
9:     NX – INTEGERInput
On entry: the number of grid points in the x-direction (including the boundary points).
Constraint: NX4.
10:   NY – INTEGERInput
On entry: the number of grid points in the y-direction (including the boundary points).
Constraint: NY4.
11:   TOLS – REAL (KIND=nag_wp)Input
On entry: the space tolerance used in the grid refinement strategy (σ in equation (4)). See Section 8.2.
Constraint: TOLS>0.0.
12:   TOLT – REAL (KIND=nag_wp)Input
On entry: the time tolerance used to determine the time step size (τ in equation (7)). See Section 8.3.
Constraint: TOLT>0.0.
13:   PDEDEF – SUBROUTINE, supplied by the user.External Procedure
PDEDEF must evaluate the functions Fj, for j=1,2,,NPDE, in equation (1) which define the system of PDEs (i.e., the residuals of the resulting ODE system) at all interior points of the domain. Values at points on the boundaries of the domain are ignored and will be overwritten by BNDARY. PDEDEF is called for each subgrid in turn.
The specification of PDEDEF is:
SUBROUTINE PDEDEF ( NPTS, NPDE, T, X, Y, U, UT, UX, UY, UXX, UXY, UYY, RES)
INTEGER  NPTS, NPDE
REAL (KIND=nag_wp)  T, X(NPTS), Y(NPTS), U(NPTS,NPDE), UT(NPTS,NPDE), UX(NPTS,NPDE), UY(NPTS,NPDE), UXX(NPTS,NPDE), UXY(NPTS,NPDE), UYY(NPTS,NPDE), RES(NPTS,NPDE)
1:     NPTS – INTEGERInput
On entry: the number of grid points in the current grid.
2:     NPDE – INTEGERInput
On entry: the number of PDEs in the system.
3:     T – REAL (KIND=nag_wp)Input
On entry: the current value of the independent variable t.
4:     X(NPTS) – REAL (KIND=nag_wp) arrayInput
On entry: Xi contains the x coordinate of the ith grid point, for i=1,2,,NPTS.
5:     Y(NPTS) – REAL (KIND=nag_wp) arrayInput
On entry: Yi contains the y coordinate of the ith grid point, for i=1,2,,NPTS.
6:     U(NPTS,NPDE) – REAL (KIND=nag_wp) arrayInput
On entry: Uij contains the value of the jth PDE component at the ith grid point, for i=1,2,,NPTS and j=1,2,,NPDE.
7:     UT(NPTS,NPDE) – REAL (KIND=nag_wp) arrayInput
On entry: UTij contains the value of u t  for the jth PDE component at the ith grid point, for i=1,2,,NPTS and j=1,2,,NPDE.
8:     UX(NPTS,NPDE) – REAL (KIND=nag_wp) arrayInput
On entry: UXij contains the value of u x  for the jth PDE component at the ith grid point, for i=1,2,,NPTS and j=1,2,,NPDE.
9:     UY(NPTS,NPDE) – REAL (KIND=nag_wp) arrayInput
On entry: UYij contains the value of u y  for the jth PDE component at the ith grid point, for i=1,2,,NPTS and j=1,2,,NPDE.
10:   UXX(NPTS,NPDE) – REAL (KIND=nag_wp) arrayInput
On entry: UXXij contains the value of 2u x2  for the jth PDE component at the ith grid point, for i=1,2,,NPTS and j=1,2,,NPDE.
11:   UXY(NPTS,NPDE) – REAL (KIND=nag_wp) arrayInput
On entry: UXYij contains the value of 2u xy  for the jth PDE component at the ith grid point, for i=1,2,,NPTS and j=1,2,,NPDE.
12:   UYY(NPTS,NPDE) – REAL (KIND=nag_wp) arrayInput
On entry: UYYij contains the value of 2u y2  for the jth PDE component at the ith grid point, for i=1,2,,NPTS and j=1,2,,NPDE.
13:   RES(NPTS,NPDE) – REAL (KIND=nag_wp) arrayOutput
On exit: RESij must contain the value of Fj, for j=1,2,,NPDE, at the ith grid point, for i=1,2,,NPTS, although the residuals at boundary points will be ignored (and overwritten later on) and so they need not be specified here.
PDEDEF must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D03RAF is called. Parameters denoted as Input must not be changed by this procedure.
14:   BNDARY – SUBROUTINE, supplied by the user.External Procedure
BNDARY must evaluate the functions Gj, for j=1,2,,NPDE, in equation (2) which define the boundary conditions at all boundary points of the domain. Residuals at interior points must not be altered by this subroutine.
The specification of BNDARY is:
SUBROUTINE BNDARY ( NPTS, NPDE, T, X, Y, U, UT, UX, UY, NBPTS, LBND, RES)
INTEGER  NPTS, NPDE, NBPTS, LBND(NBPTS)
REAL (KIND=nag_wp)  T, X(NPTS), Y(NPTS), U(NPTS,NPDE), UT(NPTS,NPDE), UX(NPTS,NPDE), UY(NPTS,NPDE), RES(NPTS,NPDE)
1:     NPTS – INTEGERInput
On entry: the number of grid points in the current grid.
2:     NPDE – INTEGERInput
On entry: the number of PDEs in the system.
3:     T – REAL (KIND=nag_wp)Input
On entry: the current value of the independent variable t.
4:     X(NPTS) – REAL (KIND=nag_wp) arrayInput
On entry: Xi contains the x coordinate of the ith grid point, for i=1,2,,NPTS.
5:     Y(NPTS) – REAL (KIND=nag_wp) arrayInput
On entry: Yi contains the y coordinate of the ith grid point, for i=1,2,,NPTS.
6:     U(NPTS,NPDE) – REAL (KIND=nag_wp) arrayInput
On entry: Uij contains the value of the jth PDE component at the ith grid point, for i=1,2,,NPTS and j=1,2,,NPDE.
7:     UT(NPTS,NPDE) – REAL (KIND=nag_wp) arrayInput
On entry: UTij contains the value of u t  for the jth PDE component at the ith grid point, for i=1,2,,NPTS and j=1,2,,NPDE.
8:     UX(NPTS,NPDE) – REAL (KIND=nag_wp) arrayInput
On entry: UXij contains the value of u x  for the jth PDE component at the ith grid point, for i=1,2,,NPTS and j=1,2,,NPDE.
9:     UY(NPTS,NPDE) – REAL (KIND=nag_wp) arrayInput
On entry: UYij contains the value of u y  for the jth PDE component at the ith grid point, for i=1,2,,NPTS and j=1,2,,NPDE.
10:   NBPTS – INTEGERInput
On entry: the number of boundary points in the grid.
11:   LBND(NBPTS) – INTEGER arrayInput
On entry: LBNDi contains the grid index for the ith boundary point, for i=1,2,,NBPTS. Hence the ith boundary point has coordinates XLBNDi and YLBNDi, and the corresponding solution values are ULBNDiNPDE, etc.
12:   RES(NPTS,NPDE) – REAL (KIND=nag_wp) arrayInput/Output
On entry: RESij contains the value of Fj, for i=1,2,,NPDE, at the ith grid point, for i=1,2,,NPTS, as returned by PDEDEF. The residuals at the boundary points will be overwritten and so need not have been set by PDEDEF.
On exit: RESLBNDij must contain the value of Gj, for j=1,2,,NPDE, at the ith boundary point, for i=1,2,,NBPTS.
Note: elements of RES corresponding to interior points must not be altered.
BNDARY must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D03RAF is called. Parameters denoted as Input must not be changed by this procedure.
15:   PDEIV – SUBROUTINE, supplied by the user.External Procedure
PDEIV must specify the initial values of the PDE components u at all points in the grid. PDEIV is not referenced if, on entry, IND=1.
The specification of PDEIV is:
SUBROUTINE PDEIV ( NPTS, NPDE, T, X, Y, U)
INTEGER  NPTS, NPDE
REAL (KIND=nag_wp)  T, X(NPTS), Y(NPTS), U(NPTS,NPDE)
1:     NPTS – INTEGERInput
On entry: the number of grid points in the grid.
2:     NPDE – INTEGERInput
On entry: the number of PDEs in the system.
3:     T – REAL (KIND=nag_wp)Input
On entry: the (initial) value of the independent variable t.
4:     X(NPTS) – REAL (KIND=nag_wp) arrayInput
On entry: Xi contains the x coordinate of the ith grid point, for i=1,2,,NPTS.
5:     Y(NPTS) – REAL (KIND=nag_wp) arrayInput
On entry: Yi contains the y coordinate of the ith grid point, for i=1,2,,NPTS.
6:     U(NPTS,NPDE) – REAL (KIND=nag_wp) arrayOutput
On exit: Uij must contain the value of the jth PDE component at the ith grid point, for i=1,2,,NPTS and j=1,2,,NPDE.
PDEIV must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D03RAF is called. Parameters denoted as Input must not be changed by this procedure.
16:   MONITR – SUBROUTINE, supplied by the user.External Procedure
MONITR is called by D03RAF at the end of every successful time step, and may be used to examine or print the solution or perform other tasks such as error calculations, particularly at the final time step, indicated by the parameter TLAST. The input arguments contain information about the grid and solution at all grid levels used.
MONITR can also be used to force an immediate tidy termination of the solution process and return to the calling program.
The specification of MONITR is:
SUBROUTINE MONITR ( NPDE, T, DT, DTNEW, TLAST, NLEV, NGPTS, XPTS, YPTS, LSOL, SOL, IERR)
INTEGER  NPDE, NLEV, NGPTS(NLEV), LSOL(NLEV), IERR
REAL (KIND=nag_wp)  T, DT, DTNEW, XPTS(*), YPTS(*), SOL(*)
LOGICAL  TLAST
1:     NPDE – INTEGERInput
On entry: the number of PDEs in the system.
2:     T – REAL (KIND=nag_wp)Input
On entry: the current value of the independent variable t, i.e., the time at the end of the integration step just completed.
3:     DT – REAL (KIND=nag_wp)Input
On entry: the current time step size Δt, i.e., the time step size used for the integration step just completed.
4:     DTNEW – REAL (KIND=nag_wp)Input
On entry: the step size that will be used for the next time step.
5:     TLAST – LOGICALInput
On entry: indicates if intermediate or final time step. TLAST=.FALSE. for an intermediate step, TLAST=.TRUE. for the last call to MONITR before returning to your program.
6:     NLEV – INTEGERInput
On entry: the number of grid levels used at time T.
7:     NGPTS(NLEV) – INTEGER arrayInput
On entry: NGPTSl contains the number of grid points at level l, for l=1,2,,NLEV.
8:     XPTS(*) – REAL (KIND=nag_wp) arrayInput
On entry: contains the x coordinates of the grid points in each level in turn, i.e., Xi, for i=1,2,,NGPTSl and l=1,2,,NLEV.
So for level l, Xi=XPTSk+i, where k=NGPTS1+NGPTS2++NGPTSl-1, for i=1,2,,NGPTSl and l=1,2,,NLEV.
9:     YPTS(*) – REAL (KIND=nag_wp) arrayInput
On entry: contains the y coordinates of the grid points in each level in turn, i.e., Yi, for i=1,2,,NGPTSl and l=1,2,,NLEV.
So for level l, Yi=YPTSk+i, where k=NGPTS1+NGPTS2++NGPTSl-1, for i=1,2,,NGPTSl and l=1,2,,NLEV.
10:   LSOL(NLEV) – INTEGER arrayInput
On entry: LSOLl contains the pointer to the solution in SOL at grid level l and time T. (LSOLl actually contains the array index immediately preceding the start of the solution in SOL.)
11:   SOL(*) – REAL (KIND=nag_wp) arrayInput
On entry: contains the solution UNGPTSlNPDE at time T for each grid level l in turn, positioned according to LSOL, i.e., for level l, Uij=SOLLSOLl+j-1×NGPTSl+i, for i=1,2,,NGPTSl, j=1,2,,NPDE and l=1,2,,NLEV.
12:   IERR – INTEGERInput/Output
On entry: will be set to 0.
On exit: should be set to 1 to force a tidy termination and an immediate return to the calling program with IFAIL=4. IERR should remain unchanged otherwise.
MONITR must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D03RAF is called. Parameters denoted as Input must not be changed by this procedure.
17:   OPTI(4) – INTEGER arrayInput
On entry: may be set to control various options available in the integrator.
OPTI1=0
All the default options are employed.
OPTI1>0
The default value of OPTIi, for i=2,3,4, can be obtained by setting OPTIi=0.
OPTI1
Specifies the maximum number of grid levels allowed (including the base grid). OPTI10. The default value is OPTI1=3.
OPTI2
Specifies the maximum number of Jacobian evaluations allowed during each nonlinear equations solution. OPTI20. The default value is OPTI2=2.
OPTI3
Specifies the maximum number of Newton iterations in each nonlinear equations solution. OPTI30. The default value is OPTI3=10.
OPTI4
Specifies the maximum number of iterations in each linear equations solution. OPTI40. The default value is OPTI4=100.
Constraint: OPTI10 and if OPTI1>0, OPTIi0, for i=2,3,4.
18:   OPTR(3,NPDE) – REAL (KIND=nag_wp) arrayInput
On entry: may be used to specify the optional vectors umax, ws and wt in the space and time monitors (see Section 8).
If an optional vector is not required then all its components should be set to 1.0.
OPTR1j, for j=1,2,,NPDE, specifies ujmax, the approximate maximum absolute value of the jth component of u, as used in (4) and (7). OPTR1j>0.0, for j=1,2,,NPDE.
OPTR2j, for j=1,2,,NPDE, specifies wjs, the weighting factors used in the space monitor (see (4)) to indicate the relative importance of the jth component of u on the space monitor. OPTR2j0.0, for j=1,2,,NPDE.
OPTR3j, for j=1,2,,NPDE, specifies wjt, the weighting factors used in the time monitor (see (6)) to indicate the relative importance of the jth component of u on the time monitor. OPTR3j0.0, for j=1,2,,NPDE.
Constraints:
  • OPTR1j>0.0, for j=1,2,,NPDE;
  • OPTRij0.0, for i=2,3 and j=1,2,,NPDE.
19:   RWK(LENRWK) – REAL (KIND=nag_wp) arrayCommunication Array
20:   LENRWK – INTEGERInput
On entry: the dimension of the array RWK as declared in the (sub)program from which D03RAF is called.
The required value of LENRWK cannot be determined exactly in advance, but a suggested value is
LENRWK=maxpts×NPDE×5×l+18×NPDE+9+2×maxpts,
where l=OPTI1 if OPTI10 and l=3 otherwise, and maxpts is the expected maximum number of grid points at any one level. If during the execution the supplied value is found to be too small then the routine returns with IFAIL=3 and an estimated required size is printed on the current error message unit (see X04AAF).
Constraint: LENRWKNX×NY×NPDE×14+18×NPDE+2×NX×NY (the required size for the initial grid).
21:   IWK(LENIWK) – INTEGER arrayCommunication Array
On entry: if IND=0, IWK need not be set. Otherwise IWK must remain unchanged from a previous call to D03RAF.
On exit: the following components of the array IWK concern the efficiency of the integration. Here, m is the maximum number of grid levels allowed (m=OPTI1 if OPTI1>1 and m=3 otherwise), and l is a grid level taking the values l=1,2,,nl, where nl is the number of levels used.
IWK1
Contains the number of steps taken in time.
IWK2
Contains the number of rejected time steps.
IWK2+l
Contains the total number of residual evaluations performed (i.e., the number of times PDEDEF was called) at grid level l.
IWK2+m+l
Contains the total number of Jacobian evaluations performed at grid level l.
IWK2+2×m+l
Contains the total number of Newton iterations performed at grid level l.
IWK2+3×m+l
Contains the total number of linear solver iterations performed at grid level l.
IWK2+4×m+l
Contains the maximum number of Newton iterations performed at any one time step at grid level l.
IWK2+5×m+l
Contains the maximum number of linear solver iterations performed at any one time step at grid level l.
Note: the total and maximum numbers are cumulative over all calls to D03RAF. If the specified maximum number of Newton or linear solver iterations is exceeded at any stage, then the maximums above are set to the specified maximum plus one.
22:   LENIWK – INTEGERInput
On entry: the dimension of the array IWK as declared in the (sub)program from which D03RAF is called.
The required value of LENIWK cannot be determined exactly in advance, but a suggested value is
LENIWK=maxpts×14+5×m+7×m+2,
where maxpts is the expected maximum number of grid points at any one level and m=OPTI1 if OPTI1>0 and m=3 otherwise. If during the execution the supplied value is found to be too small then the routine returns with IFAIL=3 and an estimated required size is printed on the current error message unit (see X04AAF).
Constraint: LENIWK19×NX×NY+9 (the required size for the initial grid).
23:   LWK(LENLWK) – LOGICAL arrayWorkspace
24:   LENLWK – INTEGERInput
On entry: the dimension of the array LWK as declared in the (sub)program from which D03RAF is called.
The required value of LENLWK cannot be determined exactly in advanced, but a suggested value is
LENLWK=maxpts+1,
where maxpts is the expected maximum number of grid points at any one level. If during the execution the supplied value is found to be too small then the routine returns with IFAIL=3 and an estimated required size is printed on the current error message unit (see X04AAF).
Constraint: LENLWKNX×NY+1 (the required size for the initial grid).
25:   ITRACE – INTEGERInput
On entry: the level of trace information required from D03RAF. ITRACE may take the value -1, 0, 1, 2 or 3.
ITRACE=-1
No output is generated.
ITRACE=0
Only warning messages are printed.
ITRACE>0
Output from the underlying solver is printed on the current advisory message unit (see X04ABF). This output contains details of the time integration, the nonlinear iteration and the linear solver.
If ITRACE<-1, then -1 is assumed and similarly if ITRACE>3, then 3 is assumed.
The advisory messages are given in greater detail as ITRACE increases. Setting ITRACE=1 allows you to monitor the progress of the integration without possibly excessive information.
26:   IND – INTEGERInput/Output
On entry: must be set to 0 or 1.
IND=0
Starts the integration in time.
IND=1
Continues the integration after an earlier exit from the routine. In this case, only the following parameters may be reset between calls to D03RAF: TOUT, DT2, DT3, TOLS, TOLT, OPTI, OPTR, ITRACE and IFAIL.
Constraint: 0IND1.
On exit: IND=1.
Note:  for users of the NAG Library for SMP & Multicore only, additional values of IND are allowed. See Section 2.2.3 in the Introduction to the NAG Library for SMP & Multicore for further details.
27:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ 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​ 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 -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).
Errors or warnings detected by the routine:
IFAIL=1
On entry,NPDE<1,
orTOUTTS,
orTOUT is too close to TS,
orIND=0 and DT1<0.0,
or DTi<0.0, for i=2​ or ​3,
orDT2>DT3,
orIND=0 and 0.0<DT1<10×machine precision×maxTS,TOUT,
orIND=0 and DT1>TOUT-TS,
orIND=0 and DT1<DT2 or DT1>DT3,
orXMINXMAX,
orXMAX too close to XMIN,
orYMINYMAX,
orYMAX too close to YMIN,
orNX or NY<4,
orTOLS or TOLT0.0,
orOPTI1<0,
or OPTI1>0 and OPTIj<0, for j=2, 3 or 4,
orOPTR1j0.0, for some j=1,2,,NPDE,
orOPTR2j<0.0, for some j=1,2,,NPDE,
orOPTR3j<0.0, for some j=1,2,,NPDE,
orLENRWK, LENIWK or LENLWK too small for initial grid level,
orIND0 or 1,
orIND=1 on initial entry to D03RAF.
IFAIL=2
The time step size to be attempted is less than the specified minimum size. This may occur following time step failures and subsequent step size reductions caused by one or more of the following:
  • the requested accuracy could not be achieved, i.e., TOLT is too small,
  • the maximum number of linear solver iterations, Newton iterations or Jacobian evaluations is too small,
  • ILU decomposition of the Jacobian matrix could not be performed, possibly due to singularity of the Jacobian.
Setting ITRACE to a higher value may provide further information.
In the latter two cases you are advised to check their problem formulation in PDEDEF and/or BNDARY, and the initial values in PDEIV if appropriate.
IFAIL=3
One or more of the workspace arrays is too small for the required number of grid points. An estimate of the required sizes for the current stage is output, but more space may be required at a later stage.
IFAIL=4
IERR was set to 1 in MONITR, forcing control to be passed back to calling program. Integration was successful as far as T=TS.
IFAIL=5
The integration has been completed but the maximum number of levels specified in OPTI1 was insufficient at one or more time steps, meaning that the requested space accuracy could not be achieved. To avoid this warning either increase the value of OPTI1 or decrease the value of TOLS.

7  Accuracy

There are three sources of error in the algorithm: space and time discretization, and interpolation (linear) between grid levels. The space and time discretization errors are controlled separately using the parameters TOLS and TOLT described in the following section, and you should test the effects of varying these parameters. Interpolation errors are generally implicitly controlled by the refinement criterion since in areas where interpolation errors are potentially large, the space monitor will also be large. It can be shown that the global spatial accuracy is comparable to that which would be obtained on a uniform grid of the finest grid size. A full error analysis can be found in Trompert and Verwer (1993).

8  Further Comments

8.1  Algorithm Outline

The local uniform grid refinement method is summarised as follows:
  1. Initialize the course base grid, an initial solution and an initial time step.
  2. Solve the system of PDEs on the current grid with the current time step.
  3. If the required accuracy in space and the maximum number of grid levels have not yet been reached:
    (a) Determine new finer grid at forward time level.
    (b) Get solution values at previous time level(s) on new grid.
    (c) Interpolate internal boundary values from old grid at forward time.
    (d) Get initial values for the Newton process at forward time.
    (e) Go to 2.
  4. Update the coarser grid solution using the finer grid values.
  5. Estimate error in time integration. If time error is acceptable advance time level.
  6. Determine new step size then go to 2 with coarse base as current grid.

8.2  Refinement Strategy

For each grid point i a space monitor μis is determined by
μ i s = max j=1,NPDE γ j Δ x 2 2 x 2 u j x i , y i ,t + Δ y 2 2 y 2 u j x i , y i ,t , (3)
where Δx and Δy are the grid widths in the x and y directions; and xi, yi are the x and y coordinates at grid point i. The parameter γj is obtained from
γj=wjs ujmax σ , (4)
where σ is the user-supplied space tolerance; wjs is a weighting factor for the relative importance of the jth PDE component on the space monitor; and ujmax is the approximate maximum absolute value of the jth component. A value for σ must be supplied by you. Values for wjs and ujmax must also be supplied but may be set to the value 1.0 if little information about the solution is known.
A new level of refinement is created if
maxiμis>0.9  or  1.0, (5)
depending on the grid level at the previous step in order to avoid fluctuations in the number of grid levels between time steps. If (5) is satisfied then all grid points for which μis>0.25 are flagged and surrounding cells are quartered in size.
No derefinement takes place as such, since at each time step the solution on the base grid is computed first and new finer grids are then created based on the new solution. Hence derefinement occurs implicitly. See Section 8.1.

8.3  Time Integration

The time integration is controlled using a time monitor calculated at each level l up to the maximum level used, given by
μlt=1Nj=1NPDEwjti=1 NGPTSl Δtαij utxi,yi,t 2 (6)
where NGPTSl is the total number of points on grid level l; N=NGPTSl×NPDE; Δt is the current time step; ut is the time derivative of u which is approximated by first-order finite differences; wjt is the time equivalent of the space weighting factor wjs; and αij is given by
αij=τ ujmax100+uxi,yi,t (7)
where ujmax is as before, and τ is the user-specified time tolerance.
An integration step is rejected and retried at all levels if
maxlμlt>1.0. (8)

9  Example

Note: a modified example is supplied with the NAG Library for SMP & Multicore and links have been supplied in the following subsections.
For this routine two examples are presented, with a main program and two example problems given in Example 1 (EX1) and Example 2 (EX2).
Example 1 (EX1)
This example stems from combustion theory and is a model for a single, one-step reaction of a mixture of two chemicals (see Adjerid and Flaherty (1988)). The PDE for the temperature of the mixture u is
u t =d 2u x2 + 2u y2 +D1+α-u exp-δu
for 0x,y1 and t0, with initial conditions ux,y,0=1 for 0x,y1, and boundary conditions
ux 0,y,t = 0, u 1,y,t = 1   for ​ 0y1,
uy x,0,t = 0, u x,1,t = 1   for ​ 0x 1.
The heat release parameter α=1, the Damkohler number D=Rexpδ/αδ, the activation energy δ=20, the reaction rate R=5, and the diffusion parameter d=0.1.
For small times the temperature gradually increases in a circular region about the origin, and at about t=0.24 ‘ignition’ occurs causing the temperature to suddenly jump from near unity to 1+α, and a reaction front forms and propagates outwards, becoming steeper. Thus during the solution, just one grid level is used up to the ignition point, then two levels, and then three as the reaction front steepens.
Example 2 (EX2)
This example is taken from a multispecies food web model, in which predator-prey relationships in a spatial domain are simulated (see Brown et al. (1994)). In this example there is just one species each of prey and predator, and the two PDEs for the concentrations c1 and c2 of the prey and the predator respectively are
c1 t =c1b1+a11c1+a12c2+d1 2c1 x2 + 2c1 y2 ,
0=c2 b2+a21c1+a22c2+d2 2 c2 x2 + 2 c2 y2 ,
with
a11=a22=-1, a12=-0.5×10-6, and a21=104, and b1=1+αxy+βsin4πxsin4πy,
where α=50 and β=300, and b2=-b1.
The initial conditions are taken to be simple peaked functions which satisfy the boundary conditions and very nearly satisfy the PDEs:
c1=10+16x1-xy1-y2,
c2=b2+a21c1,
and the boundary conditions are of Neumann type, i.e., zero normal derivatives everywhere.
During the solution a number of peaks and troughs develop across the domain, and so the number of levels required increases with time. Since the solution varies rapidly in space across the whole of the domain, refinement at intermediate levels tends to occur at all points of the domain.

9.1  Program Text

Program Text (d03rafe.f90)

Program Text (d03rafe_smp.f90)

9.2  Program Data

Program Data (d03rafe.d)

Program Data (d03rafe_smp.d)

9.3  Program Results

Program Results (d03rafe.r)

Program Results (d03rafe_smp.r)

Produced by GNUPLOT 4.4 patchlevel 0 Example Program 1 Model for a Single, One-step Reaction of a Mixture of Two Chemicals U(x,y,t) t = 0.001 t = 0.228 t = 0.240 t = 0.25 0 0.2 0.4 0.6 0.8 1 y 0 0.2 0.4 0.6 0.8 1 x 1 1.2 1.4 1.6 1.8 2
Produced by GNUPLOT 4.4 patchlevel 0 Example Program 2 Multispecies Food Web Model Concentrations of Predator Predator Concentration t = 0.0005 t = 0.0076 t = 0.0173 t = 0.025 0 0.2 0.4 0.6 0.8 1 y 0 0.2 0.4 0.6 0.8 1 x 0 20 40 60 80 100 120 140
Produced by GNUPLOT 4.4 patchlevel 0 Multispecies Food Web Model Concentrations of Prey Prey Concentration t = 0.0005 t = 0.0076 t = 0.0173 t = 0.025 0 0.2 0.4 0.6 0.8 1 y 0 0.2 0.4 0.6 0.8 1 x 0 200000 400000 600000 800000 1e+06 1.2e+06 1.4e+06

D03RAF (PDF version)
D03 Chapter Contents
D03 Chapter Introduction
NAG Library Manual

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