hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_pde_1d_parab_coll (d03pd)

Purpose

nag_pde_1d_parab_coll (d03pd) integrates a system of linear or nonlinear parabolic partial differential equations (PDEs) in one space variable. The spatial discretization is performed using a Chebyshev C0C0 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.

Syntax

[ts, u, x, rsave, isave, ind, user, cwsav, lwsav, iwsav, rwsav, ifail] = d03pd(m, ts, tout, pdedef, bndary, u, xbkpts, npoly, uinit, acc, rsave, isave, itask, itrace, ind, cwsav, lwsav, iwsav, rwsav, 'npde', npde, 'nbkpts', nbkpts, 'npts', npts, 'user', user)
[ts, u, x, rsave, isave, ind, user, cwsav, lwsav, iwsav, rwsav, ifail] = nag_pde_1d_parab_coll(m, ts, tout, pdedef, bndary, u, xbkpts, npoly, uinit, acc, rsave, isave, itask, itrace, ind, cwsav, lwsav, iwsav, rwsav, 'npde', npde, 'nbkpts', nbkpts, 'npts', npts, 'user', user)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 22: lrsave, lisave have been removed from the interface
.

Description

nag_pde_1d_parab_coll (d03pd) integrates the system of parabolic equations:
npde
Pi,j(Uj)/(t) + Qi = xm()/(x)(xmRi),  i = 1,2,,npde,  axb,tt0,
j = 1
j=1npdePi,j Uj t +Qi=x-m x (xmRi),  i=1,2,,npde,  axb,tt0,
(1)
where Pi,jPi,j, QiQi and RiRi depend on xx, tt, UU, UxUx and the vector UU is the set of solution values
U (x,t) = [ U1 (x,t) ,, Unpde (x,t) ]T ,
U (x,t) = [ U 1 (x,t) ,, U npde (x,t) ] T ,
(2)
and the vector UxUx is its partial derivative with respect to xx. Note that Pi,jPi,j, QiQi and RiRi must not depend on (U)/(t) U t .
The integration in time is from t0t0 to touttout, over the space interval axbaxb, where a = x1a=x1 and b = xnbkptsb=xnbkpts are the leftmost and rightmost of a user-defined set of break points x1,x2,,xnbkptsx1,x2,,xnbkpts. The coordinate system in space is defined by the value of mm; m = 0m=0 for Cartesian coordinates, m = 1m=1 for cylindrical polar coordinates and m = 2m=2 for spherical polar coordinates.
The system is defined by the functions Pi,jPi,j, QiQi and RiRi which must be specified in pdedef.
The initial values of the functions U(x,t)U(x,t) must be given at t = t0t=t0, and must be specified in uinit.
The functions RiRi, for i = 1,2,,npdei=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
βi(x,t)Ri(x,t,U,Ux) = γi(x,t,U,Ux),  i = 1,2,,npde,
βi(x,t)Ri(x,t,U,Ux)=γi(x,t,U,Ux),  i=1,2,,npde,
(3)
where x = ax=a or x = bx=b.
The boundary conditions must be specified in bndary. Thus, the problem is subject to the following restrictions:
(i) t0 < toutt0<tout, so that integration is in the forward direction;
(ii) Pi,jPi,j, QiQi and the flux RiRi must not depend on any time derivatives;
(iii) the evaluation of the functions Pi,jPi,j, QiQi and RiRi is done at both the break points and internally selected points for each element in turn, that is Pi,jPi,j, QiQi and RiRi 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,,xnbkptsx1,x2,,xnbkpts;
(iv) at least one of the functions Pi,jPi,j must be nonzero so that there is a time derivative present in the problem;
(v) if m > 0m>0 and x1 = 0.0x1=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.0x=0.0 or by specifying a zero flux there, that is βi = 1.0βi=1.0 and γi = 0.0γi=0.0. See also Section [Further Comments].
The parabolic equations are approximated by a system of ODEs in time for the values of UiUi 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_1d_parab_coll (d03pd) as an element, and on this element, a polynomial and its space and time derivatives are made to satisfy the system of PDEs at npoly1npoly-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 (nbkpts1) × npoly + 1(nbkpts-1)×npoly+1 mesh points in the spatial direction, and npde × ((nbkpts1) × npoly + 1)npde×((nbkpts-1)×npoly+1) ODEs in the time direction; one ODE at each break point for each PDE component and (npoly1npoly-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.

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

Parameters

Compulsory Input Parameters

1:     m – int64int32nag_int scalar
The coordinate system used:
m = 0m=0
Indicates Cartesian coordinates.
m = 1m=1
Indicates cylindrical polar coordinates.
m = 2m=2
Indicates spherical polar coordinates.
Constraint: m = 0m=0, 11 or 22.
2:     ts – double scalar
The initial value of the independent variable tt.
Constraint: ts < toutts<tout.
3:     tout – double scalar
The final value of tt to which the integration is to be carried out.
4:     pdedef – function handle or string containing name of m-file
pdedef must compute the values of the functions Pi,jPi,j, QiQi and RiRi which define the system of PDEs. The functions may depend on xx, tt, UU and UxUx and must be evaluated at a set of points.
[p, q, r, ires, user] = pdedef(npde, t, x, nptl, u, ux, ires, user)

Input Parameters

1:     npde – int64int32nag_int scalar
The number of PDEs in the system.
2:     t – double scalar
The current value of the independent variable tt.
3:     x(nptl) – double array
Contains a set of mesh points at which Pi,jPi,j, QiQi and RiRi are to be evaluated. x(1)x1 and x(nptl)xnptl contain successive user-supplied break points and the elements of the array will satisfy x(1) < x(2) < < x(nptl)x1<x2<<xnptl.
4:     nptl – int64int32nag_int scalar
The number of points at which evaluations are required (the value of npoly + 1npoly+1).
5:     u(npde,nptl) – double array
u(i,j)uij contains the value of the component Ui(x,t)Ui(x,t) where x = x(j)x=xj, for i = 1,2,,npdei=1,2,,npde and j = 1,2,,nptlj=1,2,,nptl.
6:     ux(npde,nptl) – double array
ux(i,j)uxij contains the value of the component (Ui(x,t))/(x) Ui(x,t) x  where x = x(j)x=xj, for i = 1,2,,npdei=1,2,,npde and j = 1,2,,nptlj=1,2,,nptl.
7:     ires – int64int32nag_int scalar
Set to 1​ or ​1-1​ or ​1.
8:     user – Any MATLAB object
pdedef is called from nag_pde_1d_parab_coll (d03pd) with the object supplied to nag_pde_1d_parab_coll (d03pd).

Output Parameters

1:     p(npde,npde,nptl) – double array
p(i,j,k)pijk must be set to the value of Pi,j(x,t,U,Ux)Pi,j(x,t,U,Ux) where x = x(k)x=xk, for i = 1,2,,npdei=1,2,,npde, j = 1,2,,npdej=1,2,,npde and k = 1,2,,nptlk=1,2,,nptl.
2:     q(npde,nptl) – double array
q(i,j)qij must be set to the value of Qi(x,t,U,Ux)Qi(x,t,U,Ux) where x = x(j)x=xj, for i = 1,2,,npdei=1,2,,npde and j = 1,2,,nptlj=1,2,,nptl.
3:     r(npde,nptl) – double array
r(i,j)rij must be set to the value of Ri(x,t,U,Ux)Ri(x,t,U,Ux) where x = x(j)x=xj, for i = 1,2,,npdei=1,2,,npde and j = 1,2,,nptlj=1,2,,nptl.
4:     ires – int64int32nag_int scalar
Should usually remain unchanged. However, you may set ires to force the integration function to take certain actions as described below:
ires = 2ires=2
Indicates to the integrator that control should be passed back immediately to the calling (sub)routine with the error indicator set to ifail = 6ifail=6.
ires = 3ires=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 = 3ires=3 when a physically meaningless input or output value has been generated. If you consecutively set ires = 3ires=3, then nag_pde_1d_parab_coll (d03pd) returns to the calling function with the error indicator set to ifail = 4ifail=4.
5:     user – Any MATLAB object
5:     bndary – function handle or string containing name of m-file
bndary must compute the functions βiβi and γiγi which define the boundary conditions as in equation (3).
[beta, gamma, ires, user] = bndary(npde, t, u, ux, ibnd, ires, user)

Input Parameters

1:     npde – int64int32nag_int scalar
The number of PDEs in the system.
2:     t – double scalar
The current value of the independent variable tt.
3:     u(npde) – double array
u(i)ui contains the value of the component Ui(x,t)Ui(x,t) at the boundary specified by ibnd, for i = 1,2,,npdei=1,2,,npde.
4:     ux(npde) – double array
ux(i)uxi contains the value of the component (Ui(x,t))/(x) Ui(x,t) x  at the boundary specified by ibnd, for i = 1,2,,npdei=1,2,,npde.
5:     ibnd – int64int32nag_int scalar
Specifies which boundary conditions are to be evaluated.
ibnd = 0ibnd=0
bndary must set up the coefficients of the left-hand boundary, x = ax=a.
ibnd0ibnd0
bndary must set up the coefficients of the right-hand boundary, x = bx=b.
6:     ires – int64int32nag_int scalar
Set to 1​ or ​1-1​ or ​1.
7:     user – Any MATLAB object
bndary is called from nag_pde_1d_parab_coll (d03pd) with the object supplied to nag_pde_1d_parab_coll (d03pd).

Output Parameters

1:     beta(npde) – double array
beta(i)betai must be set to the value of βi(x,t)βi(x,t) at the boundary specified by ibnd, for i = 1,2,,npdei=1,2,,npde.
2:     gamma(npde) – double array
gamma(i)gammai must be set to the value of γi(x,t,U,Ux)γi(x,t,U,Ux) at the boundary specified by ibnd, for i = 1,2,,npdei=1,2,,npde.
3:     ires – int64int32nag_int scalar
Should usually remain unchanged. However, you may set ires to force the integration function to take certain actions as described below:
ires = 2ires=2
Indicates to the integrator that control should be passed back immediately to the calling (sub)routine with the error indicator set to ifail = 6ifail=6.
ires = 3ires=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 = 3ires=3 when a physically meaningless input or output value has been generated. If you consecutively set ires = 3ires=3, then nag_pde_1d_parab_coll (d03pd) returns to the calling function with the error indicator set to ifail = 4ifail=4.
4:     user – Any MATLAB object
6:     u(npde,npts) – double array
npde, the first dimension of the array, must satisfy the constraint npde1npde1.
If ind = 1ind=1 the value of u must be unchanged from the previous call.
7:     xbkpts(nbkpts) – double array
nbkpts, the dimension of the array, must satisfy the constraint nbkpts2nbkpts2.
The values of the break points in the space direction. xbkpts(1)xbkpts1 must specify the left-hand boundary, aa, and xbkpts(nbkpts)xbkptsnbkpts must specify the right-hand boundary, bb.
Constraint: xbkpts(1) < xbkpts(2) < < xbkpts(nbkpts)xbkpts1<xbkpts2<<xbkptsnbkpts.
8:     npoly – int64int32nag_int scalar
The degree of the Chebyshev polynomial to be used in approximating the PDE solution between each pair of break points.
Constraint: 1npoly491npoly49.
9:     uinit – function handle or string containing name of m-file
uinit must compute the initial values of the PDE components Ui(xj,t0)Ui(xj,t0), for i = 1,2,,npdei=1,2,,npde and j = 1,2,,nptsj=1,2,,npts.
[u, user] = uinit(npde, npts, x, user)

Input Parameters

1:     npde – int64int32nag_int scalar
The number of PDEs in the system.
2:     npts – int64int32nag_int scalar
The number of mesh points in the interval [a,b][a,b].
3:     x(npts) – double array
x(j)xj, contains the values of the jjth mesh point, for j = 1,2,,nptsj=1,2,,npts.
4:     user – Any MATLAB object
uinit is called from nag_pde_1d_parab_coll (d03pd) with the object supplied to nag_pde_1d_parab_coll (d03pd).

Output Parameters

1:     u(npde,npts) – double array
u(i,j)uij must be set to the initial value Ui(xj,t0)Ui(xj,t0), for i = 1,2,,npdei=1,2,,npde and j = 1,2,,nptsj=1,2,,npts.
2:     user – Any MATLAB object
10:   acc – double scalar
A positive quantity for controlling the local error estimate in the time integration. If E(i,j)E(i,j) is the estimated error for UiUi at the jjth mesh point, the error test is:
|E(i,j)| = acc × (1.0 + |u(i,j)|).
|E(i,j)|=acc×(1.0+|uij|).
Constraint: acc > 0.0acc>0.0.
11:   rsave(lrsave) – double array
lrsave, the dimension of the array, must satisfy the constraint lrsave11 × npde × npts + 50 + nwkres + lenodelrsave11×npde×npts+50+nwkres+lenode.
If ind = 0ind=0, rsave need not be set on entry.
If ind = 1ind=1, rsave must be unchanged from the previous call to the function because it contains required information about the iteration.
12:   isave(lisave) – int64int32nag_int array
lisave, the dimension of the array, must satisfy the constraint lisavenpde × npts + 24lisavenpde×npts+24.
If ind = 0ind=0, isave need not be set on entry.
If ind = 1ind=1, isave must be unchanged from the previous call to the function because it contains required information about the iteration. In particular:
isave(1)isave1
Contains the number of steps taken in time.
isave(2)isave2
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(3)isave3
Contains the number of Jacobian evaluations performed by the time integrator.
isave(4)isave4
Contains the order of the last backward differentiation formula method used.
isave(5)isave5
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 LULU decomposition of the Jacobian matrix.
13:   itask – int64int32nag_int scalar
Specifies the task to be performed by the ODE integrator.
itask = 1itask=1
Normal computation of output values u at t = toutt=tout.
itask = 2itask=2
One step and return.
itask = 3itask=3
Stop at first internal integration point at or beyond t = toutt=tout.
Constraint: itask = 1itask=1, 22 or 33.
14:   itrace – int64int32nag_int scalar
The level of trace information required from nag_pde_1d_parab_coll (d03pd) and the underlying ODE solver. itrace may take the value 1-1, 00, 11, 22 or 33.
itrace = 1itrace=-1
No output is generated.
itrace = 0itrace=0
Only warning messages from the PDE solver are printed on the current error message unit (see nag_file_set_unit_error (x04aa)).
itrace > 0itrace>0
Output from the underlying ODE solver is printed on the current advisory message unit (see nag_file_set_unit_advisory (x04ab)). This output contains details of Jacobian entries, the nonlinear iteration and the time integration during the computation of the ODE system.
If itrace < 1itrace<-1, then 1-1 is assumed and similarly if itrace > 3itrace>3, then 33 is assumed.
The advisory messages are given in greater detail as itrace increases. You are advised to set itrace = 0itrace=0, unless you are experienced with sub-chapter D02M–N.
15:   ind – int64int32nag_int scalar
Indicates whether this is a continuation call or a new integration.
ind = 0ind=0
Starts or restarts the integration in time.
ind = 1ind=1
Continues the integration after an earlier exit from the function. In this case, only the parameters tout and ifail should be reset between calls to nag_pde_1d_parab_coll (d03pd).
Constraint: ind = 0ind=0 or 11.
16:   cwsav(1010) – cell array of strings
17:   lwsav(100100) – logical array
18:   iwsav(505505) – int64int32nag_int array
19:   rwsav(11001100) – double array

Optional Input Parameters

1:     npde – int64int32nag_int scalar
Default: The first dimension of the array u.
The number of PDEs in the system to be solved.
Constraint: npde1npde1.
2:     nbkpts – int64int32nag_int scalar
Default: The dimension of the array xbkpts.
The number of break points in the interval [a,b][a,b].
Constraint: nbkpts2nbkpts2.
3:     npts – int64int32nag_int scalar
Default: The second dimension of the array u.
The number of mesh points in the interval [a,b][a,b].
Constraint: npts = (nbkpts1) × npoly + 1npts=(nbkpts-1)×npoly+1.
4:     user – Any MATLAB object
user is not used by nag_pde_1d_parab_coll (d03pd), but is passed to pdedef, bndary and uinit. Note that for large objects it may be more efficient to use a global variable which is accessible from the m-files than to use user.

Input Parameters Omitted from the MATLAB Interface

lrsave lisave iuser ruser

Output Parameters

1:     ts – double scalar
The value of tt corresponding to the solution values in u. Normally ts = toutts=tout.
2:     u(npde,npts) – double array
u(i,j)uij will contain the computed solution at t = tst=ts.
3:     x(npts) – double array
The mesh points chosen by nag_pde_1d_parab_coll (d03pd) in the spatial direction. The values of x will satisfy x(1) < x(2) < < x(npts)x1<x2<<xnpts.
4:     rsave(lrsave) – double array
If ind = 1ind=1, rsave must be unchanged from the previous call to the function because it contains required information about the iteration.
5:     isave(lisave) – int64int32nag_int array
If ind = 1ind=1, isave must be unchanged from the previous call to the function because it contains required information about the iteration. In particular:
isave(1)isave1
Contains the number of steps taken in time.
isave(2)isave2
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(3)isave3
Contains the number of Jacobian evaluations performed by the time integrator.
isave(4)isave4
Contains the order of the last backward differentiation formula method used.
isave(5)isave5
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 LULU decomposition of the Jacobian matrix.
6:     ind – int64int32nag_int scalar
ind = 1ind=1.
7:     user – Any MATLAB object
8:     cwsav(1010) – cell array of strings
9:     lwsav(100100) – logical array
10:   iwsav(505505) – int64int32nag_int array
11:   rwsav(11001100) – double array
12:   ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

  ifail = 1ifail=1
On entry,touttstoutts,
ortouttstout-ts is too small,
oritask1itask1, 22 or 33,
orm0m0, 11 or 22,
orm > 0m>0 and xbkpts(1) < 0.0xbkpts1<0.0,
ornpde < 1npde<1,
ornbkpts < 2nbkpts<2,
ornpoly < 1npoly<1 or npoly > 49npoly>49,
ornpts(nbkpts1) × npoly + 1npts(nbkpts-1)×npoly+1,
oracc0.0acc0.0,
orind0ind0 or 11,
orbreak points xbkpts(i)xbkptsi are not ordered,
orlrsave is too small,
orlisave is too small.
W ifail = 2ifail=2
The underlying ODE solver cannot make any further progress across the integration range from the current point t = tst=ts with the supplied value of acc. The components of u contain the computed values at the current point t = tst=ts.
W ifail = 3ifail=3
In the underlying ODE solver, there were repeated errors or corrector convergence test failures on an attempted step, before completing the requested task. The problem may have a singularity or acc is too small for the integration to continue. Integration was successful as far as t = tst=ts.
  ifail = 4ifail=4
In setting up the ODE system, the internal initialization function was unable to initialize the derivative of the ODE system. This could be due to the fact that ires was repeatedly set to 33 in at least pdedef or bndary, when the residual in the underlying ODE solver was being evaluated.
  ifail = 5ifail=5
In solving the ODE system, a singular Jacobian has been encountered. You should check your problem formulation.
W ifail = 6ifail=6
When evaluating the residual in solving the ODE system, ires was set to 22 in at least pdedef or bndary. Integration was successful as far as t = tst=ts.
  ifail = 7ifail=7
The value of acc is so small that the function is unable to start the integration in time.
  ifail = 8ifail=8
In one of pdedef or bndary, ires was set to an invalid value.
  ifail = 9ifail=9 (nag_ode_ivp_stiff_imp_revcom (d02nn))
A serious error has occurred in an internal call to the specified function. Check the problem specification and all parameters and array dimensions. Setting itrace = 1itrace=1 may provide more information. If the problem persists, contact NAG.
W ifail = 10ifail=10
The required task has been completed, but it is estimated that a small change in acc is unlikely to produce any change in the computed solution. (Only applies when you are not operating in one step mode, that is when itask2itask2.)
  ifail = 11ifail=11
An error occurred during Jacobian formulation of the ODE system (a more detailed error description may be directed to the current error message unit).
  ifail = 12ifail=12
Not applicable.
  ifail = 13ifail=13
Not applicable.
  ifail = 14ifail=14
The flux function RiRi was detected as depending on time derivatives, which is not permissible.

Accuracy

nag_pde_1d_parab_coll (d03pd) 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 parameter, acc.

Further Comments

nag_pde_1d_parab_coll (d03pd) is designed to solve parabolic systems (possibly including elliptic equations) with second-order derivatives in space. The parameter 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.

Example

The problem consists of a fourth-order PDE which can be written as a pair of second-order elliptic-parabolic PDEs for U1(x,t)U1(x,t) and U2(x,t)U2(x,t),
0 = (2U1)/(x2)U2
0= 2U1 x2 -U2
(4)
(U2)/(t) = (2U2)/(x2) + U2(U1)/(x)U1(U2)/(x)
U2 t = 2U2 x2 +U2 U1 x -U1 U2 x
(5)
where 1x1-1x1 and t0t0. 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.
U1 x =0  and  U1=1  at ​x=-1,   and U1 x =0  and  U1=-1  at ​x=1.
The initial conditions at t = 0t=0 are given by
U1 = sin(πx)/2  and  U2 = (π2)/4sin(πx)/2.
U1=-sinπx2  and  U2=π24sinπx2.
The absence of boundary conditions for U2(x,t)U2(x,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) U1 x . The conditions on U1(x,t)U1(x,t) at the boundaries are assigned to the second PDE by setting β2 = 0.0β2=0.0 in equation (3) and placing the Dirichlet boundary conditions on U1(x,t)U1(x,t) in the function γ2γ2.
function nag_pde_1d_parab_coll_example

% Solution of an elliptic-parabolic pair of PDEs
% (derived from a fourth-order PDE).

% Set values for problem parameters.
npde = 2;

% Number of points on interpolated mesh, number of break points.
intpts = 6;
nbkpts = 10;

% Order of Chebyshev polynomial.
npoly = 3;

itype = 1;

nel = nbkpts - 1;
npts = nel*npoly + 1;
mu = npde*(npoly + 1) - 1;
neqn = npde*npts;
lisave = neqn + 24;
npl1 = npoly + 1;
nwkres = 3*npl1*npl1 + npl1*(npde*npde + 6*npde+nbkpts+1) + 13*npde + 5;
lenode = (3*mu + 1)*neqn;
lrsave = 11*neqn + 50 + nwkres + lenode;

% Define some arrays.
rsave = zeros(lrsave, 1);
u = zeros(npde, npts);
uinterp = zeros(npde, intpts, itype);
x = zeros(npts, 1);
xbkpts = zeros(nbkpts, 1);

isave = zeros(lisave, 1, 'int64');
cwsav = {''; ''; ''; ''; ''; ''; ''; ''; ''; ''};
lwsav = false(100, 1);
iwsav = zeros(505, 1, 'int64');
rwsav = zeros(1100, 1);

% Set up the points on the interpolation grid.
xinterp = [-1.0 -0.6 -0.2 0.2 0.6 1.0];

acc = 1.0e-4;

itrace = 0;
itask = 1;
m = 0; % Use cartesian coordinates.

% We run through the calculation twice; once to output the interpolated
% results, and once to store the results for plotting.
niter = [5, 20];

% Prepare to store plotting results.
tsav = zeros(niter(2), 1);
usav = zeros(2, niter(2), npts);
isav = 0;

fprintf(' nag_pde_1d_parab_coll example program results\n');
for icalc = 1:2

    % Set the break points.
    if icalc == 1
        hx = 2.0/(nbkpts-1.0);
        xbkpts(1) = -1.0;
        xbkpts(nbkpts) = 1.0;
        for i = 2:nbkpts-1
            xbkpts(i) = xbkpts(i-1) + hx;
        end
    else
        for i = 1:nbkpts
            xbkpts(i) = -1.0 + (i - 1.0)*2.0/(nbkpts - 1.0);
        end
    end

    % Set initial conditions.
    ts = 0.0;
    tout = 0.1e-4;
    alpha = -log(tout)/(niter(2)-1.0);

    % Start the integration in time.
    ind = 0;

    % Loop over endpoints for the integration.  We've set itask = 1, which
    % gives normal computation of output values at t = tout.
    for iter = 1:niter(icalc)

        %Set the endpoint.
        if icalc == 1
            tout = 10.0*tout;
        else
            tout = exp(alpha*(iter - niter(icalc)));
        end

        % Calling this routine here, we always have ind set to 0, which
        % (re)starts the integration in time - otherwise, the output x
        % array is set to zero.
        [ts, u, x, rsave, isave, indOut, user, cwsav, lwsav, iwsav, ...
            rwsav, ifail] = nag_pde_1d_parab_coll(int64(m), ts, tout, @pdedef, ...
            @bndary, u, xbkpts, int64(npoly), @uinit, ...
            acc, rsave, isave, int64(itask), int64(itrace), int64(ind), ...
            cwsav, lwsav, iwsav, rwsav);
        if ifail ~= 0
            % Parameters out of range, or convergence problems.
            % Print message and exit.
            fprintf('Warning: nag_pde_1d_parab_coll returned with ifail = %1d \n\n',ifail);
            return;
        end

        if icalc == 1
            % Output interpolation points first time through.
            if iter == 1
                fprintf([' polynomial degree = %4d', ...
                    '    no. of elements = %4d\n'], npoly, nel);
                fprintf([' accuracy requirement = %10.3e', ...
                    '    number of points = %5d\n\n'], acc, npts);
                fprintf(' t / x       ');
                for i = 1:intpts
                    fprintf('%8.4f', xinterp(i));
                end
                fprintf('\n\n');
            end

            % Call nag_pde_1d_parab_coll_interp to do interpolation of results
            % onto coarser grid.
            [uinterp, rsave, ifail] = nag_pde_1d_parab_coll_interp(u, ...
                          xbkpts, int64(npoly), xinterp, int64(itype), rsave);
            if ifail ~= 0
                % Parameters out of range, or convergence problems.
                % Print message and exit.
                fprintf(['Warning: nag_pde_1d_parab_coll_interp returned with ifail = ', ...
                    '%1d \n\n'], ifail);
                return;
            end

            % Output interpolated results for this time step.
            fprintf('%7.4f  u(1)', ts);
            for i = 1:intpts
                fprintf('%8.4f', uinterp(1,i,1));
            end
            fprintf('\n');
            fprintf('         u(2)');
            for i = 1:intpts
                fprintf('%8.4f', uinterp(2,i,1));
            end
            fprintf('\n\n');
        else
            % Save this timestep, and this set of results.
            isav = isav+1;
            tsav(isav) = ts;
            for ipt = 1:npts
                for isol = 1:2
                    usav(isol,isav,ipt) = u(isol,ipt);
                end
            end
        end
    end

    if icalc == 1
        % Output some statistics.
        fprintf([' Number of integration steps in time = %6d\n', ...
            ' Number of function evaluations = %6d\n', ...
            ' Number of Jacobian evaluations = %6d\n', ...
            ' Number of iterations = %6d\n'], isave(1), isave(2), ...
            isave(3), isave(5));
    else
        % Plot results.
        fig1 = figure('Number', 'off');
        plot_results(x, tsav, squeeze(usav(1,:,:)), 'U1');
        fig2 = figure('Number', 'off');
        plot_results(x, tsav, squeeze(usav(2,:,:)), 'U2');
    end
end

function [p, q, r, ires, user] = pdedef(npde, t, x, nptl, u, ux, ires, user)
  p = zeros(npde, npde, nptl);
  q = zeros(npde, nptl);
  r = zeros(npde, nptl);

  for i = 1:double(nptl)
    q(1,i) = u(2,i);
    q(2,i) = u(1,i)*ux(2,i) - ux(1,i)*u(2,i);
    r(1,i) = ux(1,i);
    r(2,i) = ux(2,i);
    p(1,1,i) = 0;
    p(1,2,i) = 0;
    p(2,1,i) = 0;
    p(2,2,i) = 1;
  end;

function [beta, gamma, ires, user] = bndary(npde, t, u, ux, ibnd, ires, user)
  beta = zeros(npde, 1);
  gamma = zeros(npde, 1);

  if (ibnd == 0)
    beta(1) = 1;
    gamma(1) = 0;
    beta(2) = 0;
    gamma(2) = u(1) - 1;
  else
    beta(1) = 1;
    gamma(1) = 0;
    beta(2) = 0;
    gamma(2) = u(1) + 1;
  end

function [u, user] = uinit(npde, npts, x, user)
  u = zeros(npde, npts);

  piby2 = pi/2;
  for i = 1:double(npts)
    u(1,i) = -sin(piby2*x(i));
    u(2,i) = -piby2*piby2*u(1,i);
  end

function plot_results(x, t, u, ident)
  % Formatting for title and axis labels.
  titleFmt = {'FontName', 'Helvetica', 'FontWeight', 'Bold', 'FontSize', 14};
  labFmt = {'FontName', 'Helvetica', 'FontWeight', 'Bold', 'FontSize', 13};
  set(gca, 'FontSize', 13); % for legend, axis tick labels, etc.

  % Plot array as a mesh.
  mesh(x, t, u);
  set(gca, 'YScale', 'log');
  set(gca, 'YTick', [0.00001 0.0001 0.001 0.01 0.1 1]);
  set(gca, 'YMinorGrid', 'off');
  set(gca, 'YMinorTick', 'off');

  % Label the axes, and set the title.
  xlabel('x', labFmt{:});
  ylabel('t', labFmt{:});
  zlabel([ident,'(x,t)'], labFmt{:});
  title({['Solution ',ident,' of elliptic-parabolic pair'], ...
      'using Chebyshev Collocation and BDF'}, titleFmt{:});

  % Set the axes limits tight to the x and y range.
  axis([x(1) x(end) t(1) t(end)]);

  % Set the view to something nice (determined empirically).
  view(-165, 44);
 
 nag_pde_1d_parab_coll example program results
 polynomial degree =    3    no. of elements =    9
 accuracy requirement =  1.000e-04    number of points =    28

 t / x        -1.0000 -0.6000 -0.2000  0.2000  0.6000  1.0000

 0.0001  u(1)  1.0000  0.8090  0.3090 -0.3090 -0.8090 -1.0000
         u(2) -2.4850 -1.9957 -0.7623  0.7623  1.9957  2.4850

 0.0010  u(1)  1.0000  0.8086  0.3088 -0.3088 -0.8086 -1.0000
         u(2) -2.5548 -1.9918 -0.7608  0.7608  1.9918  2.5548

 0.0100  u(1)  1.0000  0.8055  0.3070 -0.3070 -0.8055 -1.0000
         u(2) -2.6867 -1.9527 -0.7457  0.7457  1.9527  2.6867

 0.1000  u(1)  1.0000  0.7955  0.2988 -0.2988 -0.7955 -1.0000
         u(2) -2.8966 -1.8365 -0.6393  0.6393  1.8365  2.8966

 1.0000  u(1)  1.0000  0.7939  0.2972 -0.2972 -0.7939 -1.0000
         u(2) -2.9233 -1.8247 -0.6120  0.6120  1.8247  2.9233

 Number of integration steps in time =     41
 Number of function evaluations =    275
 Number of Jacobian evaluations =     11
 Number of iterations =     97

function d03pd_example

% Solution of an elliptic-parabolic pair of PDEs
% (derived from a fourth-order PDE).

% Set values for problem parameters.
npde = 2;

% Number of points on interpolated mesh, number of break points.
intpts = 6;
nbkpts = 10;

% Order of Chebyshev polynomial.
npoly = 3;

itype = 1;

nel = nbkpts - 1;
npts = nel*npoly + 1;
mu = npde*(npoly + 1) - 1;
neqn = npde*npts;
lisave = neqn + 24;
npl1 = npoly + 1;
nwkres = 3*npl1*npl1 + npl1*(npde*npde + 6*npde+nbkpts+1) + 13*npde + 5;
lenode = (3*mu + 1)*neqn;
lrsave = 11*neqn + 50 + nwkres + lenode;

% Define some arrays.
rsave = zeros(lrsave, 1);
u = zeros(npde, npts);
uinterp = zeros(npde, intpts, itype);
x = zeros(npts, 1);
xbkpts = zeros(nbkpts, 1);

isave = zeros(lisave, 1, 'int64');
cwsav = {''; ''; ''; ''; ''; ''; ''; ''; ''; ''};
lwsav = false(100, 1);
iwsav = zeros(505, 1, 'int64');
rwsav = zeros(1100, 1);

% Set up the points on the interpolation grid.
xinterp = [-1.0 -0.6 -0.2 0.2 0.6 1.0];

acc = 1.0e-4;

itrace = 0;
itask = 1;
m = 0; % Use cartesian coordinates.

% We run through the calculation twice; once to output the interpolated
% results, and once to store the results for plotting.
niter = [5, 20];

% Prepare to store plotting results.
tsav = zeros(niter(2), 1);
usav = zeros(2, niter(2), npts);
isav = 0;

fprintf(' d03pd example program results\n');
for icalc = 1:2

    % Set the break points.
    if icalc == 1
        hx = 2.0/(nbkpts-1.0);
        xbkpts(1) = -1.0;
        xbkpts(nbkpts) = 1.0;
        for i = 2:nbkpts-1
            xbkpts(i) = xbkpts(i-1) + hx;
        end
    else
        for i = 1:nbkpts
            xbkpts(i) = -1.0 + (i - 1.0)*2.0/(nbkpts - 1.0);
        end
    end

    % Set initial conditions.
    ts = 0.0;
    tout = 0.1e-4;
    alpha = -log(tout)/(niter(2)-1.0);

    % Start the integration in time.
    ind = 0;

    % Loop over endpoints for the integration.  We've set itask = 1, which
    % gives normal computation of output values at t = tout.
    for iter = 1:niter(icalc)

        %Set the endpoint.
        if icalc == 1
            tout = 10.0*tout;
        else
            tout = exp(alpha*(iter - niter(icalc)));
        end

        % Calling this routine here, we always have ind set to 0, which
        % (re)starts the integration in time - otherwise, the output x
        % array is set to zero.
        [ts, u, x, rsave, isave, indOut, user, cwsav, lwsav, iwsav, ...
            rwsav, ifail] = d03pd(int64(m), ts, tout, @pdedef, ...
            @bndary, u, xbkpts, int64(npoly), @uinit, ...
            acc, rsave, isave, int64(itask), int64(itrace), int64(ind), ...
            cwsav, lwsav, iwsav, rwsav);
        if ifail ~= 0
            % Parameters out of range, or convergence problems.
            % Print message and exit.
            fprintf('Warning: d03pd returned with ifail = %1d \n\n',ifail);
            return;
        end

        if icalc == 1
            % Output interpolation points first time through.
            if iter == 1
                fprintf([' polynomial degree = %4d', ...
                    '    no. of elements = %4d\n'], npoly, nel);
                fprintf([' accuracy requirement = %10.3e', ...
                    '    number of points = %5d\n\n'], acc, npts);
                fprintf(' t / x       ');
                for i = 1:intpts
                    fprintf('%8.4f', xinterp(i));
                end
                fprintf('\n\n');
            end

            % Call d03py to do interpolation of results onto coarser grid.
            [uinterp, rsave, ifail] = d03py(u, xbkpts, int64(npoly), ...
                xinterp, int64(itype), rsave);
            if ifail ~= 0
                % Parameters out of range, or convergence problems.
                % Print message and exit.
                fprintf(['Warning: d03py returned with ifail = ', ...
                    '%1d \n\n'], ifail);
                return;
            end

            % Output interpolated results for this time step.
            fprintf('%7.4f  u(1)', ts);
            for i = 1:intpts
                fprintf('%8.4f', uinterp(1,i,1));
            end
            fprintf('\n');
            fprintf('         u(2)');
            for i = 1:intpts
                fprintf('%8.4f', uinterp(2,i,1));
            end
            fprintf('\n\n');
        else
            % Save this timestep, and this set of results.
            isav = isav+1;
            tsav(isav) = ts;
            for ipt = 1:npts
                for isol = 1:2
                    usav(isol,isav,ipt) = u(isol,ipt);
                end
            end
        end
    end

    if icalc == 1
        % Output some statistics.
        fprintf([' Number of integration steps in time = %6d\n', ...
            ' Number of function evaluations = %6d\n', ...
            ' Number of Jacobian evaluations = %6d\n', ...
            ' Number of iterations = %6d\n'], isave(1), isave(2), ...
            isave(3), isave(5));
    else
        % Plot results.
        fig1 = figure('Number', 'off');
        plot_results(x, tsav, squeeze(usav(1,:,:)), 'U1');
        fig2 = figure('Number', 'off');
        plot_results(x, tsav, squeeze(usav(2,:,:)), 'U2');
    end
end

function [p, q, r, ires, user] = pdedef(npde, t, x, nptl, u, ux, ires, user)
  p = zeros(npde, npde, nptl);
  q = zeros(npde, nptl);
  r = zeros(npde, nptl);

  for i = 1:double(nptl)
    q(1,i) = u(2,i);
    q(2,i) = u(1,i)*ux(2,i) - ux(1,i)*u(2,i);
    r(1,i) = ux(1,i);
    r(2,i) = ux(2,i);
    p(1,1,i) = 0;
    p(1,2,i) = 0;
    p(2,1,i) = 0;
    p(2,2,i) = 1;
  end;

function [beta, gamma, ires, user] = bndary(npde, t, u, ux, ibnd, ires, user)
  beta = zeros(npde, 1);
  gamma = zeros(npde, 1);

  if (ibnd == 0)
    beta(1) = 1;
    gamma(1) = 0;
    beta(2) = 0;
    gamma(2) = u(1) - 1;
  else
    beta(1) = 1;
    gamma(1) = 0;
    beta(2) = 0;
    gamma(2) = u(1) + 1;
  end

function [u, user] = uinit(npde, npts, x, user)
  u = zeros(npde, npts);

  piby2 = pi/2;
  for i = 1:double(npts)
    u(1,i) = -sin(piby2*x(i));
    u(2,i) = -piby2*piby2*u(1,i);
  end

function plot_results(x, t, u, ident)
  % Formatting for title and axis labels.
  titleFmt = {'FontName', 'Helvetica', 'FontWeight', 'Bold', 'FontSize', 14};
  labFmt = {'FontName', 'Helvetica', 'FontWeight', 'Bold', 'FontSize', 13};
  set(gca, 'FontSize', 13); % for legend, axis tick labels, etc.

  % Plot array as a mesh.
  mesh(x, t, u);
  set(gca, 'YScale', 'log');
  set(gca, 'YTick', [0.00001 0.0001 0.001 0.01 0.1 1]);
  set(gca, 'YMinorGrid', 'off');
  set(gca, 'YMinorTick', 'off');

  % Label the axes, and set the title.
  xlabel('x', labFmt{:});
  ylabel('t', labFmt{:});
  zlabel([ident,'(x,t)'], labFmt{:});
  title({['Solution ',ident,' of elliptic-parabolic pair'], ...
      'using Chebyshev Collocation and BDF'}, titleFmt{:});

  % Set the axes limits tight to the x and y range.
  axis([x(1) x(end) t(1) t(end)]);

  % Set the view to something nice (determined empirically).
  view(-165, 44);
 
 d03pd example program results
 polynomial degree =    3    no. of elements =    9
 accuracy requirement =  1.000e-04    number of points =    28

 t / x        -1.0000 -0.6000 -0.2000  0.2000  0.6000  1.0000

 0.0001  u(1)  1.0000  0.8090  0.3090 -0.3090 -0.8090 -1.0000
         u(2) -2.4850 -1.9957 -0.7623  0.7623  1.9957  2.4850

 0.0010  u(1)  1.0000  0.8086  0.3088 -0.3088 -0.8086 -1.0000
         u(2) -2.5548 -1.9918 -0.7608  0.7608  1.9918  2.5548

 0.0100  u(1)  1.0000  0.8055  0.3070 -0.3070 -0.8055 -1.0000
         u(2) -2.6867 -1.9527 -0.7457  0.7457  1.9527  2.6867

 0.1000  u(1)  1.0000  0.7955  0.2988 -0.2988 -0.7955 -1.0000
         u(2) -2.8966 -1.8365 -0.6393  0.6393  1.8365  2.8966

 1.0000  u(1)  1.0000  0.7939  0.2972 -0.2972 -0.7939 -1.0000
         u(2) -2.9233 -1.8247 -0.6120  0.6120  1.8247  2.9233

 Number of integration steps in time =     41
 Number of function evaluations =    275
 Number of Jacobian evaluations =     11
 Number of iterations =     97


PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013