PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_pde_1d_parab_fd (d03pc)
Purpose
nag_pde_1d_parab_fd (d03pc) integrates a system of linear or nonlinear parabolic partial differential equations (PDEs) in one space variable. The spatial discretization is performed using finite differences, 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,
rsave,
isave,
ind,
user,
cwsav,
lwsav,
iwsav,
rwsav,
ifail] = d03pc(
m,
ts,
tout,
pdedef,
bndary,
u,
x,
acc,
rsave,
isave,
itask,
itrace,
ind,
cwsav,
lwsav,
iwsav,
rwsav, 'npde',
npde, 'npts',
npts, 'user',
user)
[
ts,
u,
rsave,
isave,
ind,
user,
cwsav,
lwsav,
iwsav,
rwsav,
ifail] = nag_pde_1d_parab_fd(
m,
ts,
tout,
pdedef,
bndary,
u,
x,
acc,
rsave,
isave,
itask,
itrace,
ind,
cwsav,
lwsav,
iwsav,
rwsav, 'npde',
npde, 'npts',
npts, 'user',
user)
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 22: |
lrsave and lisave were removed from the interface |
Description
nag_pde_1d_parab_fd (d03pc) integrates the system of parabolic equations:
where
,
and
depend on
,
,
,
and the vector
is the set of solution values
and the vector
is its partial derivative with respect to
. Note that
,
and
must not depend on
.
The integration in time is from to , over the space interval , where and are the leftmost and rightmost points of a user-defined mesh . The coordinate system in space is defined by the value of ;
for Cartesian coordinates,
for cylindrical polar coordinates and for spherical polar coordinates. The mesh should be chosen in accordance with the expected behaviour of the solution.
The system is defined by the functions
,
and
which must be specified in
pdedef.
The initial values of the functions
must be given at
. The functions
, for
, 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
where
or
.
The boundary conditions must be specified in
bndary.
The problem is subject to the following restrictions:
(i) |
, so that integration is in the forward direction; |
(ii) |
,
and the flux must not depend on any time derivatives; |
(iii) |
the evaluation of the functions ,
and is done at the mid-points of the mesh intervals by calling the pdedef for each mid-point in turn. Any discontinuities in these functions must therefore be at one or more of the mesh points ; |
(iv) |
at least one of the functions must be nonzero so that there is a time derivative present in the problem; and |
(v) |
if and , 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 or by specifying a zero flux there, that is and . See also Further Comments. |
The parabolic equations are approximated by a system of ODEs in time for the values of at mesh points. For simple problems in Cartesian coordinates, this system is obtained by replacing the space derivatives by the usual central, three-point finite difference formula. However, for polar and spherical problems, or problems with nonlinear coefficients, the space derivatives are replaced by a modified three-point formula which maintains second-order accuracy. In total there are ODEs in the time direction. This 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, Dew P M and Furzeland R M (1989) Developing software for time-dependent problems using the method of lines and differential-algebraic integrators Appl. Numer. Math. 5 375–397
Dew P M and Walsh J (1981) A set of library routines for solving parabolic equations in one space variable ACM Trans. Math. Software 7 295–314
Skeel R D and Berzins M (1990) A method for the spatial discretization of parabolic equations in one space variable SIAM J. Sci. Statist. Comput. 11(1) 1–32
Parameters
Compulsory Input Parameters
- 1:
– int64int32nag_int scalar
-
The coordinate system used:
- Indicates Cartesian coordinates.
- Indicates cylindrical polar coordinates.
- Indicates spherical polar coordinates.
Constraint:
, or .
- 2:
– double scalar
-
The initial value of the independent variable .
Constraint:
.
- 3:
– double scalar
-
The final value of to which the integration is to be carried out.
- 4:
– function handle or string containing name of m-file
-
pdedef must compute the functions
,
and
which define the system of PDEs.
pdedef is called approximately midway between each pair of mesh points in turn by
nag_pde_1d_parab_fd (d03pc).
[p, q, r, ires, user] = pdedef(npde, t, x, u, ux, ires, user)
Input Parameters
- 1:
– int64int32nag_int scalar
-
The number of PDEs in the system.
- 2:
– double scalar
-
The current value of the independent variable .
- 3:
– double scalar
-
The current value of the space variable .
- 4:
– double array
-
contains the value of the component , for .
- 5:
– double array
-
contains the value of the component , for .
- 6:
– int64int32nag_int scalar
-
Set to .
- 7:
– Any MATLAB object
pdedef is called from
nag_pde_1d_parab_fd (d03pc) with the object supplied to
nag_pde_1d_parab_fd (d03pc).
Output Parameters
- 1:
– double array
-
must be set to the value of , for and .
- 2:
– double array
-
must be set to the value of , for .
- 3:
– double array
-
must be set to the value of , for .
- 4:
– int64int32nag_int scalar
-
Should usually remain unchanged. However, you may set
ires to force the integration function to take certain actions as described below:
- Indicates to the integrator that control should be passed back immediately to the calling (sub)routine with the error indicator set to .
- Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set when a physically meaningless input or output value has been generated. If you consecutively set , then nag_pde_1d_parab_fd (d03pc) returns to the calling function with the error indicator set to .
- 5:
– Any MATLAB object
- 5:
– function handle or string containing name of m-file
-
bndary must compute the functions
and
which define the boundary conditions as in equation
(3).
[beta, gamma, ires, user] = bndary(npde, t, u, ux, ibnd, ires, user)
Input Parameters
- 1:
– int64int32nag_int scalar
-
The number of PDEs in the system.
- 2:
– double scalar
-
The current value of the independent variable .
- 3:
– double array
-
contains the value of the component
at the boundary specified by
ibnd, for
.
- 4:
– double array
-
contains the value of the component
at the boundary specified by
ibnd, for
.
- 5:
– int64int32nag_int scalar
-
Determines the position of the boundary conditions.
- bndary must set up the coefficients of the left-hand boundary, .
- Indicates that bndary must set up the coefficients of the right-hand boundary, .
- 6:
– int64int32nag_int scalar
-
Set to .
- 7:
– Any MATLAB object
bndary is called from
nag_pde_1d_parab_fd (d03pc) with the object supplied to
nag_pde_1d_parab_fd (d03pc).
Output Parameters
- 1:
– double array
-
must be set to the value of
at the boundary specified by
ibnd, for
.
- 2:
– double array
-
must be set to the value of
at the boundary specified by
ibnd, for
.
- 3:
– int64int32nag_int scalar
-
Should usually remain unchanged. However, you may set
ires to force the integration function to take certain actions as described below:
- Indicates to the integrator that control should be passed back immediately to the calling (sub)routine with the error indicator set to .
- Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set when a physically meaningless input or output value has been generated. If you consecutively set , then nag_pde_1d_parab_fd (d03pc) returns to the calling function with the error indicator set to .
- 4:
– Any MATLAB object
- 6:
– double array
-
The initial values of at and the mesh points
, for .
- 7:
– double array
-
The mesh points in the spatial direction. must specify the left-hand boundary, , and must specify the right-hand boundary, .
Constraint:
.
- 8:
– double scalar
-
A positive quantity for controlling the local error estimate in the time integration. If
is the estimated error for
at the
th mesh point, the error test is:
Constraint:
.
- 9:
– double array
-
lrsave, the dimension of the array, must satisfy the constraint
.
If
,
rsave need not be set on entry.
If
,
rsave must be unchanged from the previous call to the function because it contains required information about the iteration.
- 10:
– int64int32nag_int array
-
lisave, the dimension of the array, must satisfy the constraint
.
If
,
isave need not be set on entry.
If
,
isave must be unchanged from the previous call to the function because it contains required information about the iteration. In particular:
- Contains the number of steps taken in time.
- 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.
- Contains the number of Jacobian evaluations performed by the time integrator.
- Contains the order of the last backward differentiation formula method used.
- 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 decomposition of the Jacobian matrix.
- 11:
– int64int32nag_int scalar
-
Specifies the task to be performed by the ODE integrator.
- Normal computation of output values u at .
- One step and return.
- Stop at first internal integration point at or beyond .
Constraint:
, or .
- 12:
– int64int32nag_int scalar
-
The level of trace information required from
nag_pde_1d_parab_fd (d03pc) and the underlying ODE solver.
itrace may take the value
,
,
,
or
.
- No output is generated.
- Only warning messages from the PDE solver are printed on the current error message unit (see nag_file_set_unit_error (x04aa)).
- 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 , then is assumed and similarly if , then is assumed.
The advisory messages are given in greater detail as
itrace increases. You are advised to set
, unless you are experienced with
Sub-chapter D02M–N.
- 13:
– int64int32nag_int scalar
-
Indicates whether this is a continuation call or a new integration.
- Starts or restarts the integration in time.
- Continues the integration after an earlier exit from the function. In this case, only the arguments tout and ifail should be reset between calls to nag_pde_1d_parab_fd (d03pc).
Constraint:
or .
- 14:
– cell array of strings
-
If
,
cwsav need not be set on entry.
If
,
cwsav must be unchanged from the previous call to the function.
- 15:
– logical array
-
If
,
lwsav need not be set on entry.
If
,
lwsav must be unchanged from the previous call to the function.
- 16:
– int64int32nag_int array
-
If
,
iwsav need not be set on entry.
If
,
iwsav must be unchanged from the previous call to the function.
- 17:
– double array
-
If
,
rwsav need not be set on entry.
If
,
rwsav must be unchanged from the previous call to the function.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the first dimension of the array
u.
The number of PDEs in the system to be solved.
Constraint:
.
- 2:
– int64int32nag_int scalar
-
Default:
the dimension of the array
x and the second dimension of the array
u. (An error is raised if these dimensions are not equal.)
The number of mesh points in the interval .
Constraint:
.
- 3:
– Any MATLAB object
user is not used by
nag_pde_1d_parab_fd (d03pc), but is passed to
pdedef and
bndary. 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.
Output Parameters
- 1:
– double scalar
-
The value of
corresponding to the solution values in
u. Normally
.
- 2:
– double array
-
will contain the computed solution at .
- 3:
– double array
-
If
,
rsave must be unchanged from the previous call to the function because it contains required information about the iteration.
- 4:
– int64int32nag_int array
-
If
,
isave must be unchanged from the previous call to the function because it contains required information about the iteration. In particular:
- Contains the number of steps taken in time.
- 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.
- Contains the number of Jacobian evaluations performed by the time integrator.
- Contains the order of the last backward differentiation formula method used.
- 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 decomposition of the Jacobian matrix.
- 5:
– int64int32nag_int scalar
-
.
- 6:
– Any MATLAB object
- 7:
– cell array of strings
-
If
,
cwsav must be unchanged from the previous call to the function.
- 8:
– logical array
-
If
,
lwsav must be unchanged from the previous call to the function.
- 9:
– int64int32nag_int array
-
If
,
iwsav must be unchanged from the previous call to the function.
- 10:
– double array
-
If
,
rwsav must be unchanged from the previous call to the function.
- 11:
– int64int32nag_int scalar
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.
-
-
On entry, | , |
or | is too small, |
or | , or , |
or | , or , |
or | and , |
or | are not ordered, |
or | , |
or | , |
or | , |
or | or , |
or | lrsave is too small, |
or | lisave is too small. |
- W
-
The underlying ODE solver cannot make any further progress across the integration range from the current point
with the supplied value of
acc. The components of
u contain the computed values at the current point
.
- W
-
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
.
-
-
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
in at least
pdedef or
bndary, when the residual in the underlying ODE solver was being evaluated.
-
-
In solving the ODE system, a singular Jacobian has been encountered. You should check your problem formulation.
- W
-
When evaluating the residual in solving the ODE system,
ires was set to
in at least
pdedef or
bndary. Integration was successful as far as
.
-
-
The value of
acc is so small that the function is unable to start the integration in time.
-
-
In one of
pdedef or
bndary,
ires was set to an invalid value.
- (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 arguments and array dimensions. Setting
may provide more information. If the problem persists, contact
NAG.
- W
-
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
.)
-
-
An error occurred during Jacobian formulation of the ODE system (a more detailed error description may be directed to the current error message unit).
-
-
Not applicable.
-
-
Not applicable.
-
-
The flux function was detected as depending on time derivatives, which is not permissible.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
nag_pde_1d_parab_fd (d03pc) controls the accuracy of the integration in the time direction but not the accuracy of the approximation in space. The spatial accuracy depends on both the number of mesh 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.
Further Comments
nag_pde_1d_parab_fd (d03pc) is designed to solve parabolic systems (possibly including some 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. It may be advisable in such cases to reduce the whole system to first-order and to use the Keller box scheme function
nag_pde_1d_parab_keller (d03pe).
The time taken depends on the complexity of the parabolic system and on the accuracy requested.
Example
We use the example given in
Dew and Walsh (1981) which consists of an elliptic-parabolic pair of PDEs. The problem was originally derived from a single third-order in space PDE. The elliptic equation is
and the parabolic equation is
where
. The boundary conditions are given by
and
The first of these boundary conditions implies that the flux term in the second PDE,
, is zero at .
The initial conditions at
are given by
The value
was used in the problem definition. A mesh of
points was used with a circular mesh spacing to cluster the points towards the right-hand side of the spatial interval,
.
Open in the MATLAB editor:
d03pc_example
function d03pc_example
fprintf('d03pc example results\n\n');
global alpha;
npde = 2;
npts = 20;
intpts = 6;
itype = int64(1);
neqn = npde*npts;
lisave = neqn + 24;
nwk = (10 + 6*npde)*neqn;
lrsave = nwk + (21 + 3*npde)*npde + 7*npts + 54;
rsave = zeros(lrsave, 1);
u = zeros(npde, npts);
uinterp = zeros(npde, intpts, itype);
x = zeros(npts, 1);
isave = zeros(lisave, 1, 'int64');
cwsav = {''; ''; ''; ''; ''; ''; ''; ''; ''; ''};
lwsav = false(100, 1);
iwsav = zeros(505, 1, 'int64');
rwsav = zeros(1100, 1);
xinterp = [0.0 0.4 0.6 0.8 0.9 1.0];
acc = 1.0e-3;
alpha = 1;
itrace = int64(0);
itask = int64(1);
m = int64(1);
niter = [5, 28];
tsav = zeros(niter(2), 1);
usav = zeros(2, niter(2), npts);
isav = 0;
for icalc = 1:2
piby2 = pi/2;
hx = piby2/(npts-1);
x = sin(0:hx:piby2);
ts = 0;
tout = 1e-5;
[u] = uinit(x, npts);
ind = int64(0);
isav = 0;
for iter = 1:niter(icalc)
%Set the endpoint.
if icalc == 1
tout = 10.0*tout;
else
if iter < 10
tout = 2*tout;
else
if iter == 10
tout = 0.01;
else
if iter < 20
tout = tout + 0.01;
else
tout = tout + 0.1;
end
end
end
end
[ts, u, rsave, isave, ind, user, cwsav, lwsav, iwsav, rwsav, ifail] = ...
d03pc(...
m, ts, tout, @pdedef, @bndary, u, x, acc, rsave, isave, itask, ...
itrace, ind, cwsav, lwsav, iwsav, rwsav);
if icalc == 1
if iter == 1
fprintf([' accuracy requirement = %12.5e\n', ...
' parameter alpha = %12.3e\n'], acc, alpha);
fprintf(' t / x ');
fprintf('%8.4f', xinterp(1:intpts));
fprintf('\n\n');
end
[uinterp, ifail] = d03pz( ...
m, u, x, xinterp, itype);
fprintf('%7.4f u(1)', tout);
fprintf('%8.4f', uinterp(1,1:intpts,1));
fprintf('\n%13s','u(2)');
fprintf('%8.4f', uinterp(2,1:intpts,1));
fprintf('\n\n');
else
isav = isav+1;
tsav(isav) = ts;
usav(1:2,isav,1:npts) = u(1:2,1:npts);
end
end
if icalc == 1
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
fig1 = figure;
plot_results(x, tsav, squeeze(usav(1,:,:)), 'u_1');
fig2 = figure;
plot_results(x, tsav, squeeze(usav(2,:,:)), 'u_2');
end
end
function [p, q, r, ires, user] = pdedef(npde, t, x, u, ux, ires, user)
global alpha;
p = zeros(npde,npde);
q = zeros(npde,1);
r = zeros(npde,1);
q(1) = 4*alpha*(u(2) + x*ux(2));
r(1) = x*ux(1);
r(2) = ux(2) - u(1)*u(2);
p(2,2) = 1 - x*x;
function [beta, gamma, ires, user] = bndary(npde, t, u, ux, ibnd, ires, user)
if (ibnd == 0)
beta(1) = 0;
beta(2) = 1;
gamma(1) = u(1);
gamma(2) = -u(1)*u(2);
else
beta(1) = 1;
beta(2) = 0;
gamma(1) = -u(1);
gamma(2) = u(2);
end
function [u] = uinit(x, npts)
global alpha;
for i = 1:npts
u(1,i) = 2*alpha*x(i);
u(2,i) = 1;
end
function plot_results(x, t, u, ident)
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');
xlabel('x');
ylabel('t');
zlabel([ident,'(x,t)']);
title({['Solution ',ident,' of elliptic-parabolic pair'], ...
'using method of lines and BDF'});
title(['Solution ',ident,' of elliptic-parabolic pair']);
axis([x(1) x(end) t(1) t(end)]);
view(-125, 30);
d03pc example results
accuracy requirement = 1.00000e-03
parameter alpha = 1.000e+00
t / x 0.0000 0.4000 0.6000 0.8000 0.9000 1.0000
0.0001 u(1) 0.0000 0.8008 1.1988 1.5990 1.7958 1.8485
u(2) 0.9997 0.9995 0.9994 0.9988 0.9663 -0.0000
0.0010 u(1) 0.0000 0.7982 1.1940 1.5841 1.7179 1.6734
u(2) 0.9969 0.9952 0.9937 0.9484 0.6385 -0.0000
0.0100 u(1) 0.0000 0.7676 1.1239 1.3547 1.3635 1.2830
u(2) 0.9627 0.9495 0.8754 0.5537 0.2908 -0.0000
0.1000 u(1) 0.0000 0.3908 0.5007 0.5297 0.5120 0.4744
u(2) 0.5468 0.4299 0.2995 0.1479 0.0724 -0.0000
1.0000 u(1) 0.0000 0.0007 0.0008 0.0008 0.0008 0.0007
u(2) 0.0010 0.0007 0.0005 0.0002 0.0001 -0.0000
Number of integration steps in time = 78
Number of function evaluations = 378
Number of Jacobian evaluations = 25
Number of iterations = 190
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015