NAG C Library Function Document

nag_pde_parab_1d_coll (d03pdc)

1
Purpose

nag_pde_parab_1d_coll (d03pdc) integrates a system of linear or nonlinear parabolic partial differential equations (PDEs) in one space variable. The spatial discretization is performed using a Chebyshev C0 collocation method, and the method of lines is employed to reduce the PDEs to a system of ordinary differential equations (ODEs). The resulting system is solved using a backward differentiation formula method.

2
Specification

#include <nag.h>
#include <nagd03.h>
void  nag_pde_parab_1d_coll (Integer npde, Integer m, double *ts, double tout,
void (*pdedef)(Integer npde, double t, const double x[], Integer nptl, const double u[], const double ux[], double p[], double q[], double r[], Integer *ires, Nag_Comm *comm),
void (*bndary)(Integer npde, double t, const double u[], const double ux[], Integer ibnd, double beta[], double gamma[], Integer *ires, Nag_Comm *comm),
double u[], Integer nbkpts, const double xbkpts[], Integer npoly, Integer npts, double x[],
void (*uinit)(Integer npde, Integer npts, const double x[], double u[], Nag_Comm *comm),
double acc, double rsave[], Integer lrsave, Integer isave[], Integer lisave, Integer itask, Integer itrace, const char *outfile, Integer *ind, Nag_Comm *comm, Nag_D03_Save *saved, NagError *fail)

3
Description

nag_pde_parab_1d_coll (d03pdc) integrates the system of parabolic equations:
j=1npdePi,j Uj t +Qi=x-m x xmRi,  i=1,2,,npde,  axb,tt0, (1)
where Pi,j, Qi and Ri depend on x, t, U, Ux and the vector U is the set of solution values
U x,t = U 1 x,t ,, U npde x,t T , (2)
and the vector Ux is its partial derivative with respect to x. Note that Pi,j, Qi and Ri must not depend on U t .
The integration in time is from t0 to tout, over the space interval axb, where a=x1 and b=xnbkpts are the leftmost and rightmost of a user-defined set of break-points x1,x2,,xnbkpts. The coordinate system in space is defined by the value of m; m=0 for Cartesian coordinates, m=1 for cylindrical polar coordinates and m=2 for spherical polar coordinates.
The system is defined by the functions Pi,j, Qi and Ri which must be specified in pdedef.
The initial values of the functions Ux,t must be given at t=t0, and must be specified in uinit.
The functions Ri, for i=1,2,,npde, which may be thought of as fluxes, are also used in the definition of the boundary conditions for each equation. The boundary conditions must have the form
βix,tRix,t,U,Ux=γix,t,U,Ux,  i=1,2,,npde, (3)
where x=a or x=b.
The boundary conditions must be specified in bndary. Thus, the problem is subject to the following restrictions:
(i) t0<tout, so that integration is in the forward direction;
(ii) Pi,j, Qi and the flux Ri must not depend on any time derivatives;
(iii) the evaluation of the functions Pi,j, Qi and Ri is done at both the break-points and internally selected points for each element in turn, that is Pi,j, Qi and Ri are evaluated twice at each break-point. Any discontinuities in these functions must therefore be at one or more of the break-points x1,x2,,xnbkpts;
(iv) at least one of the functions Pi,j must be nonzero so that there is a time derivative present in the problem;
(v) if m>0 and x1=0.0, which is the left boundary point, then it must be ensured that the PDE solution is bounded at this point. This can be done by either specifying the solution at x=0.0 or by specifying a zero flux there, that is βi=1.0 and γi=0.0. See also Section 9.
The parabolic equations are approximated by a system of ODEs in time for the values of Ui at the mesh points. This ODE system is obtained by approximating the PDE solution between each pair of break-points by a Chebyshev polynomial of degree npoly. The interval between each pair of break-points is treated by nag_pde_parab_1d_coll (d03pdc) as an element, and on this element, a polynomial and its space and time derivatives are made to satisfy the system of PDEs at npoly-1 spatial points, which are chosen internally by the code and the break-points. In the case of just one element, the break-points are the boundaries. The user-defined break-points and the internally selected points together define the mesh. The smallest value that npoly can take is one, in which case, the solution is approximated by piecewise linear polynomials between consecutive break-points and the method is similar to an ordinary finite element method.
In total there are nbkpts-1×npoly+1 mesh points in the spatial direction, and npde×nbkpts-1×npoly+1 ODEs in the time direction; one ODE at each break-point for each PDE component and (npoly-1) ODEs for each PDE component between each pair of break-points. The system is then integrated forwards in time using a backward differentiation formula method.

4
References

Berzins M (1990) Developments in the NAG Library software for parabolic equations Scientific Software Systems (eds J C Mason and M G Cox) 59–72 Chapman and Hall
Berzins M and Dew P M (1991) Algorithm 690: Chebyshev polynomial software for elliptic-parabolic systems of PDEs ACM Trans. Math. Software 17 178–206
Zaturska N B, Drazin P G and Banks W H H (1988) On the flow of a viscous fluid driven along a channel by a suction at porous walls Fluid Dynamics Research 4

5
Arguments

1:     npde IntegerInput
On entry: the number of PDEs in the system to be solved.
Constraint: npde1.
2:     m IntegerInput
On entry: the coordinate system used:
m=0
Indicates Cartesian coordinates.
m=1
Indicates cylindrical polar coordinates.
m=2
Indicates spherical polar coordinates.
Constraint: m=0, 1 or 2.
3:     ts double *Input/Output
On entry: the initial value of the independent variable t.
On exit: the value of t corresponding to the solution values in u. Normally ts=tout.
Constraint: ts<tout.
4:     tout doubleInput
On entry: the final value of t to which the integration is to be carried out.
5:     pdedef function, supplied by the userExternal Function
pdedef must compute the values of the functions Pi,j, Qi and Ri which define the system of PDEs. The functions may depend on x, t, U and Ux and must be evaluated at a set of points.
The specification of pdedef is:
void  pdedef (Integer npde, double t, const double x[], Integer nptl, const double u[], const double ux[], double p[], double q[], double r[], Integer *ires, Nag_Comm *comm)
1:     npde IntegerInput
On entry: the number of PDEs in the system.
2:     t doubleInput
On entry: the current value of the independent variable t.
3:     x[dim] const doubleInput
On entry: contains a set of mesh points at which Pi,j, Qi and Ri are to be evaluated. x[0] and x[nptl-1] contain successive user-supplied break-points and the elements of the array will satisfy x[0]<x[1]<<x[nptl-1].
4:     nptl IntegerInput
On entry: the number of points at which evaluations are required (the value of npoly+1).
5:     u[npde×nptl] const doubleInput
Note: the i,jth element of the matrix U is stored in u[j-1×npde+i-1].
On entry: u[j-1×npde+i-1] contains the value of the component Uix,t where x=x[j-1], for i=1,2,,npde and j=1,2,,nptl.
6:     ux[npde×nptl] const doubleInput
Note: the i,jth element of the matrix is stored in ux[j-1×npde+i-1].
On entry: ux[j-1×npde+i-1] contains the value of the component Uix,t x  where x=x[j-1], for i=1,2,,npde and j=1,2,,nptl.
7:     p[dim] doubleOutput
Note: the dimension, dim, of the array p is npde×npde×nptl.
Where Pi,j,k appears in this document, it refers to the array element p[k-1×npde×npde+j-1×npde+i-1].
On exit: p[ npde×npde×k-1+ npde×j-1+ i-1] must be set to the value of Pi,jx,t,U,Ux where x=x[k-1], for i=1,2,,npde, j=1,2,,npde and k=1,2,,nptl.
8:     q[npde×nptl] doubleOutput
Note: the i,jth element of the matrix Q is stored in q[j-1×npde+i-1].
On exit: q[j-1×npde+i-1] must be set to the value of Qix,t,U,Ux where x=x[j-1], for i=1,2,,npde and j=1,2,,nptl.
9:     r[npde×nptl] doubleOutput
Note: the i,jth element of the matrix R is stored in r[j-1×npde+i-1].
On exit: r[j-1×npde+i-1] must be set to the value of Rix,t,U,Ux where x=x[j-1], for i=1,2,,npde and j=1,2,,nptl.
10:   ires Integer *Input/Output
On entry: set to -1 or 1.
On exit: should usually remain unchanged. However, you may set ires to force the integration function to take certain actions as described below:
ires=2
Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to fail.code= NE_USER_STOP.
ires=3
Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set ires=3 when a physically meaningless input or output value has been generated. If you consecutively set ires=3, nag_pde_parab_1d_coll (d03pdc) returns to the calling function with the error indicator set to fail.code= NE_FAILED_DERIV.
11:   comm Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to pdedef.
userdouble *
iuserInteger *
pPointer 
The type Pointer will be void *. Before calling nag_pde_parab_1d_coll (d03pdc) you may allocate memory and initialize these pointers with various quantities for use by pdedef when called from nag_pde_parab_1d_coll (d03pdc) (see Section 3.3.1.1 in How to Use the NAG Library and its Documentation).
Note: pdedef should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by nag_pde_parab_1d_coll (d03pdc). If your code inadvertently does return any NaNs or infinities, nag_pde_parab_1d_coll (d03pdc) is likely to produce unexpected results.
6:     bndary function, supplied by the userExternal Function
bndary must compute the functions βi and γi which define the boundary conditions as in equation (3).
The specification of bndary is:
void  bndary (Integer npde, double t, const double u[], const double ux[], Integer ibnd, double beta[], double gamma[], Integer *ires, Nag_Comm *comm)
1:     npde IntegerInput
On entry: the number of PDEs in the system.
2:     t doubleInput
On entry: the current value of the independent variable t.
3:     u[npde] const doubleInput
On entry: u[i-1] contains the value of the component Uix,t at the boundary specified by ibnd, for i=1,2,,npde.
4:     ux[npde] const doubleInput
On entry: ux[i-1] contains the value of the component Uix,t x  at the boundary specified by ibnd, for i=1,2,,npde.
5:     ibnd IntegerInput
On entry: specifies which boundary conditions are to be evaluated.
ibnd=0
bndary must set up the coefficients of the left-hand boundary, x=a.
ibnd0
bndary must set up the coefficients of the right-hand boundary, x=b.
6:     beta[npde] doubleOutput
On exit: beta[i-1] must be set to the value of βix,t at the boundary specified by ibnd, for i=1,2,,npde.
7:     gamma[npde] doubleOutput
On exit: gamma[i-1] must be set to the value of γix,t,U,Ux at the boundary specified by ibnd, for i=1,2,,npde.
8:     ires Integer *Input/Output
On entry: set to -1 or 1.
On exit: should usually remain unchanged. However, you may set ires to force the integration function to take certain actions as described below:
ires=2
Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to fail.code= NE_USER_STOP.
ires=3
Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set ires=3 when a physically meaningless input or output value has been generated. If you consecutively set ires=3, nag_pde_parab_1d_coll (d03pdc) returns to the calling function with the error indicator set to fail.code= NE_FAILED_DERIV.
9:     comm Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to bndary.
userdouble *
iuserInteger *
pPointer 
The type Pointer will be void *. Before calling nag_pde_parab_1d_coll (d03pdc) you may allocate memory and initialize these pointers with various quantities for use by bndary when called from nag_pde_parab_1d_coll (d03pdc) (see Section 3.3.1.1 in How to Use the NAG Library and its Documentation).
Note: bndary should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by nag_pde_parab_1d_coll (d03pdc). If your code inadvertently does return any NaNs or infinities, nag_pde_parab_1d_coll (d03pdc) is likely to produce unexpected results.
7:     u[npde×npts] doubleInput/Output
Note: the i,jth element of the matrix U is stored in u[j-1×npde+i-1].
On entry: if ind=1 the value of u must be unchanged from the previous call.
On exit: u[j-1×npde+i-1] will contain the computed solution at t=ts.
8:     nbkpts IntegerInput
On entry: the number of break-points in the interval a,b.
Constraint: nbkpts2.
9:     xbkpts[nbkpts] const doubleInput
On entry: the values of the break-points in the space direction. xbkpts[0] must specify the left-hand boundary, a, and xbkpts[nbkpts-1] must specify the right-hand boundary, b.
Constraint: xbkpts[0]<xbkpts[1]<<xbkpts[nbkpts-1].
10:   npoly IntegerInput
On entry: the degree of the Chebyshev polynomial to be used in approximating the PDE solution between each pair of break-points.
Constraint: 1npoly49.
11:   npts IntegerInput
On entry: the number of mesh points in the interval a,b.
Constraint: npts=nbkpts-1×npoly+1.
12:   x[npts] doubleOutput
On exit: the mesh points chosen by nag_pde_parab_1d_coll (d03pdc) in the spatial direction. The values of x will satisfy x[0]<x[1]<<x[npts-1].
13:   uinit function, supplied by the userExternal Function
uinit must compute the initial values of the PDE components Uixj,t0, for i=1,2,,npde and j=1,2,,npts.
The specification of uinit is:
void  uinit (Integer npde, Integer npts, const double x[], double u[], Nag_Comm *comm)
1:     npde IntegerInput
On entry: the number of PDEs in the system.
2:     npts IntegerInput
On entry: the number of mesh points in the interval a,b.
3:     x[npts] const doubleInput
On entry: x[j-1], contains the values of the jth mesh point, for j=1,2,,npts.
4:     u[npde×npts] doubleOutput
Note: the i,jth element of the matrix U is stored in u[j-1×npde+i-1].
On exit: u[j-1×npde+i-1] must be set to the initial value Uixj,t0, for i=1,2,,npde and j=1,2,,npts.
5:     comm Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to uinit.
userdouble *
iuserInteger *
pPointer 
The type Pointer will be void *. Before calling nag_pde_parab_1d_coll (d03pdc) you may allocate memory and initialize these pointers with various quantities for use by uinit when called from nag_pde_parab_1d_coll (d03pdc) (see Section 3.3.1.1 in How to Use the NAG Library and its Documentation).
Note: uinit should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by nag_pde_parab_1d_coll (d03pdc). If your code inadvertently does return any NaNs or infinities, nag_pde_parab_1d_coll (d03pdc) is likely to produce unexpected results.
14:   acc doubleInput
On entry: a positive quantity for controlling the local error estimate in the time integration. If Ei,j is the estimated error for Ui at the jth mesh point, the error test is:
Ei,j=acc×1.0+u[j-1×npde+i-1].  
Constraint: acc>0.0.
15:   rsave[lrsave] doubleCommunication Array
If ind=0, rsave need not be set on entry.
If ind=1, rsave must be unchanged from the previous call to the function because it contains required information about the iteration.
16:   lrsave IntegerInput
On entry: the dimension of the array rsave.
Constraint: lrsave11×npde×npts+50+nwkres+lenode.
17:   isave[lisave] IntegerCommunication Array
If ind=0, isave need not be set on entry.
If ind=1, isave must be unchanged from the previous call to the function because it contains required information about the iteration. In particular:
isave[0]
Contains the number of steps taken in time.
isave[1]
Contains the number of residual evaluations of the resulting ODE system used. One such evaluation involves computing the PDE functions at all the mesh points, as well as one evaluation of the functions in the boundary conditions.
isave[2]
Contains the number of Jacobian evaluations performed by the time integrator.
isave[3]
Contains the order of the last backward differentiation formula method used.
isave[4]
Contains the number of Newton iterations performed by the time integrator. Each iteration involves an ODE residual evaluation followed by a back-substitution using the LU decomposition of the Jacobian matrix.
18:   lisave IntegerInput
On entry: the dimension of the array isave.
Constraint: lisavenpde×npts+24.
19:   itask IntegerInput
On entry: specifies the task to be performed by the ODE integrator.
itask=1
Normal computation of output values u at t=tout.
itask=2
One step and return.
itask=3
Stop at first internal integration point at or beyond t=tout.
Constraint: itask=1, 2 or 3.
20:   itrace IntegerInput
On entry: the level of trace information required from nag_pde_parab_1d_coll (d03pdc) and the underlying ODE solver. itrace may take the value -1, 0, 1, 2 or 3.
itrace=-1
No output is generated.
itrace=0
Only warning messages from the PDE solver are printed.
itrace>0
Output from the underlying ODE solver is printed. This output contains details of Jacobian entries, the nonlinear iteration and the time integration during the computation of the ODE system.
If itrace<-1, -1 is assumed and similarly if itrace>3, 3 is assumed.
The advisory messages are given in greater detail as itrace increases.
21:   outfile const char *Input
On entry: the name of a file to which diagnostic output will be directed. If outfile is NULL the diagnostic output will be directed to standard output.
22:   ind Integer *Input/Output
On entry: indicates whether this is a continuation call or a new integration.
ind=0
Starts or restarts the integration in time.
ind=1
Continues the integration after an earlier exit from the function. In this case, only the arguments tout and fail should be reset between calls to nag_pde_parab_1d_coll (d03pdc).
Constraint: ind=0 or 1.
On exit: ind=1.
23:   comm Nag_Comm *
The NAG communication argument (see Section 3.3.1.1 in How to Use the NAG Library and its Documentation).
24:   saved Nag_D03_Save *Communication Structure
saved must remain unchanged following a previous call to a Chapter d03 function and prior to any subsequent call to a Chapter d03 function.
25:   fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

6
Error Indicators and Warnings

NE_ACC_IN_DOUBT
Integration completed, but a small change in acc is unlikely to result in a changed solution. acc=value.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_FAILED_DERIV
In setting up the ODE system an internal auxiliary was unable to initialize the derivative. This could be due to your setting ires=3 in pdedef or bndary.
NE_FAILED_START
acc was too small to start integration: acc=value.
NE_FAILED_STEP
Error during Jacobian formulation for ODE system. Increase itrace for further details.
Repeated errors in an attempted step of underlying ODE solver. Integration was successful as far as ts: ts=value.
Underlying ODE solver cannot make further progress from the point ts with the supplied value of acc. ts=value, acc=value.
NE_INCOMPAT_PARAM
On entry, m=value and xbkpts[0]=value.
Constraint: m0 or xbkpts[0]0.0 
NE_INT
ires set to an invalid value in call to pdedef or bndary.
On entry, ind=value.
Constraint: ind=0 or 1.
On entry, itask=value.
Constraint: itask=1, 2 or 3.
On entry, m=value.
Constraint: m=0, 1 or 2.
On entry, nbkpts=value.
Constraint: nbkpts2.
On entry, npde=value.
Constraint: npde1.
On entry, npoly=value.
Constraint: 1npoly49.
On entry, npoly=value.
Constraint: npoly49.
On entry, npoly=value.
Constraint: npoly1.
On entry, on initial entry ind=1.
Constraint: on initial entry ind=0.
NE_INT_2
On entry, lisave=value.
Constraint: lisavevalue.
On entry, lrsave=value.
Constraint: lrsavevalue.
NE_INT_3
On entry, npts=value, nbkpts=value and npoly=value.
Constraint: npts=nbkpts-1×npoly+1.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
Serious error in internal call to an auxiliary. Increase itrace for further details.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_NOT_CLOSE_FILE
Cannot close file value.
NE_NOT_STRICTLY_INCREASING
On entry, i=value, xbkpts[i-1]=value, j=value and xbkpts[j-1]=value.
Constraint: xbkpts[0]<xbkpts[1]<<xbkpts[nbkpts-1].
NE_NOT_WRITE_FILE
Cannot open file value for writing.
NE_REAL
On entry, acc=value.
Constraint: acc>0.0.
NE_REAL_2
On entry, tout=value and ts=value.
Constraint: tout>ts.
On entry, tout-ts is too small: tout=value and ts=value.
NE_SING_JAC
Singular Jacobian of ODE system. Check problem formulation.
NE_TIME_DERIV_DEP
Flux function appears to depend on time derivatives.
NE_USER_STOP
In evaluating residual of ODE system, ires=2 has been set in pdedef or bndary. Integration is successful as far as ts: ts=value.

7
Accuracy

nag_pde_parab_1d_coll (d03pdc) controls the accuracy of the integration in the time direction but not the accuracy of the approximation in space. The spatial accuracy depends on the degree of the polynomial approximation npoly, and on both the number of break-points and on their distribution in space. In the time integration only the local error over a single step is controlled and so the accuracy over a number of steps cannot be guaranteed. You should therefore test the effect of varying the accuracy argument, acc.

8
Parallelism and Performance

nag_pde_parab_1d_coll (d03pdc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_pde_parab_1d_coll (d03pdc) 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 function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9
Further Comments

nag_pde_parab_1d_coll (d03pdc) is designed to solve parabolic systems (possibly including elliptic equations) with second-order derivatives in space. The argument specification allows you to include equations with only first-order derivatives in the space direction but there is no guarantee that the method of integration will be satisfactory for such systems. The position and nature of the boundary conditions in particular are critical in defining a stable problem.
The time taken depends on the complexity of the parabolic system and on the accuracy requested.

10
Example

The problem consists of a fourth-order PDE which can be written as a pair of second-order elliptic-parabolic PDEs for U1x,t and U2x,t,
0= 2U1 x2 -U2 (4)
U2 t = 2U2 x2 +U2 U1 x -U1 U2 x (5)
where -1x1 and t0. The boundary conditions are given by
U1 x =0  and  U1=1  at ​x=-1,   and U1 x =0  and  U1=-1  at ​x=1.  
The initial conditions at t=0 are given by
U1=-sinπx2  and  U2=π24sinπx2.  
The absence of boundary conditions for U2x,t does not pose any difficulties provided that the derivative flux boundary conditions are assigned to the first PDE (4) which has the correct flux, U1 x . The conditions on U1x,t at the boundaries are assigned to the second PDE by setting β2=0.0 in equation (3) and placing the Dirichlet boundary conditions on U1x,t in the function γ2.

10.1
Program Text

Program Text (d03pdce.c)

10.2
Program Data

None.

10.3
Program Results

Program Results (d03pdce.r)

GnuplotProduced by GNUPLOT 5.0 patchlevel 0 Example Program Solution, U(1,x,t), of Elliptic-parabolic Pair using Chebyshev Collocation and BDF U(1,x,t) gnuplot_plot_1 gnuplot_plot_2 0.000010 0.000100 0.001000 0.010000 0.100000 1.000000 Time (logscale) −1 −0.5 0 0.5 1 x −1 −0.5 0 0.5 1
GnuplotProduced by GNUPLOT 5.0 patchlevel 0 Solution, U(2,x,t), of Elliptic-parabolic Pair using Chebyshev Collocation and BDF U(2,x,t) gnuplot_plot_1 gnuplot_plot_2 0.000010 0.000100 0.001000 0.010000 0.100000 1.000000 Time (logscale) −1 −0.5 0 0.5 1 x −3 −2 −1 0 1 2 3