NAG FL Interface
d03eef (dim2_ellip_discret)
1
Purpose
d03eef discretizes a second-order elliptic partial differential equation (PDE) on a rectangular region.
2
Specification
Fortran Interface
Subroutine d03eef ( |
xmin, xmax, ymin, ymax, pdef, bndy, ngx, ngy, lda, a, rhs, scheme, ifail) |
Integer, Intent (In) |
:: |
ngx, ngy, lda |
Integer, Intent (Inout) |
:: |
ifail |
Real (Kind=nag_wp), Intent (In) |
:: |
xmin, xmax, ymin, ymax |
Real (Kind=nag_wp), Intent (Inout) |
:: |
a(lda,7) |
Real (Kind=nag_wp), Intent (Out) |
:: |
rhs(lda) |
Character (1), Intent (In) |
:: |
scheme |
External |
:: |
pdef, bndy |
|
C Header Interface
#include <nag.h>
void |
d03eef_ (const double *xmin, const double *xmax, const double *ymin, const double *ymax, void (NAG_CALL *pdef)(const double *x, const double *y, double *alpha, double *beta, double *gamma, double *delta, double *epslon, double *phi, double *psi), void (NAG_CALL *bndy)(const double *x, const double *y, double *a, double *b, double *c, const Integer *ibnd), const Integer *ngx, const Integer *ngy, const Integer *lda, double a[], double rhs[], const char *scheme, Integer *ifail, const Charlen length_scheme) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
d03eef_ (const double &xmin, const double &xmax, const double &ymin, const double &ymax, void (NAG_CALL *pdef)(const double &x, const double &y, double &alpha, double &beta, double &gamma, double &delta, double &epslon, double &phi, double &psi), void (NAG_CALL *bndy)(const double &x, const double &y, double &a, double &b, double &c, const Integer &ibnd), const Integer &ngx, const Integer &ngy, const Integer &lda, double a[], double rhs[], const char *scheme, Integer &ifail, const Charlen length_scheme) |
}
|
The routine may be called by the names d03eef or nagf_pde_dim2_ellip_discret.
3
Description
d03eef discretizes a second-order linear elliptic partial differential equation of the form
on a rectangular region
subject to boundary conditions of the form
where
denotes the outward pointing normal derivative on the boundary. Equation
(1) is said to be elliptic if
for all points in the rectangular region. The linear equations produced are in a form suitable for passing directly to the multigrid routine
d03edf.
The equation is discretized on a rectangular grid, with
grid points in the
-direction and
grid points in the
-direction. The grid spacing used is therefore
and the coordinates of the grid points
are
At each grid point
six neighbouring grid points are used to approximate the partial differential equation, so that the equation is discretized on the seven-point stencil shown in
Figure 1.
For convenience the approximation to the exact solution is denoted by , and the neighbouring approximations are labelled according to points of the compass as shown. Where numerical labels for the seven points are required, these are also shown.
The following approximations are used for the second derivatives:
Two possible schemes may be used to approximate the first derivatives:
Central differences are more accurate than upwind differences, but upwind differences may lead to a more diagonally dominant matrix for those problems where the coefficients of the first derivatives are significantly larger than the coefficients of the second derivatives.
The approximations used for the first derivatives may be written in a more compact form as follows:
where
and
for upwind differences, and
for central differences.
At all points in the rectangular domain, including the boundary, the coefficients in the partial differential equation are evaluated by calling
pdef, and applying the approximations. This leads to a seven-diagonal system of linear equations of the form:
where the coefficients are given by
These equations then have to be modified to take account of the boundary conditions. These may be Dirichlet (where the solution is given), Neumann (where the derivative of the solution is given), or mixed (where a linear combination of solution and derivative is given).
If the boundary conditions are Dirichlet, there are an infinity of possible equations which may be applied:
If
d03edf is used to solve the discretized equations, it turns out that the choice of
can have a dramatic effect on the rate of convergence, and the obvious choice
is not the best. Some choices may even cause the multigrid method to fail altogether. In practice it has been found that a value of the same order as the other diagonal elements of the matrix is best, and the following value has been found to work well in practice:
If the boundary conditions are either mixed or Neumann (i.e.,
on return from
bndy), then one of the points in the seven-point stencil lies outside the domain. In this case the normal derivative in the boundary conditions is used to eliminate the ‘fictitious’ point,
:
It should be noted that if the boundary conditions are Neumann and , then there is no unique solution. The routine returns with in this case, and the seven-diagonal matrix is singular.
The four corners are treated separately.
bndy is called twice, once along each of the edges meeting at the corner. If both boundary conditions at this point are Dirichlet and the prescribed solution values agree, then this value is used in an equation of the form
(2). If the prescribed solution is discontinuous at the corner, then the average of the two values is used. If one boundary condition is Dirichlet and the other is mixed, then the value prescribed by the Dirichlet condition is used in an equation of the form given above. Finally, if both conditions are mixed or Neumann, then two ‘fictitious’ points are eliminated using two equations of the form
(3).
It is possible that equations for which the solution is known at all points on the boundary, have coefficients which are not defined on the boundary. Since this routine calls
pdef at
all points in the domain, including boundary points, arithmetic errors may occur in
pdef which this routine cannot trap. If you have an equation with Dirichlet boundary conditions (i.e.,
at all points on the boundary), but with PDE coefficients which are singular on the boundary, then
d03edf could be called directly only using interior grid points at your discretization.
After the equations have been set up as described above, they are checked for diagonal dominance. That is to say,
If this condition is not satisfied then the routine returns with
. The multigrid routine
d03edf may still converge in this case, but if the coefficients of the first derivatives in the partial differential equation are large compared with the coefficients of the second derivative, you should consider using upwind differences (
).
Since this routine is designed primarily for use with
d03edf, this document should be read in conjunction with the document for that routine.
4
References
Wesseling P (1982) MGD1 – a robust and efficient multigrid method Multigrid Methods. Lecture Notes in Mathematics 960 614–630 Springer–Verlag
5
Arguments
-
1:
– Real (Kind=nag_wp)
Input
-
2:
– Real (Kind=nag_wp)
Input
-
On entry: the lower and upper coordinates of the rectangular region respectively, and .
Constraint:
.
-
3:
– Real (Kind=nag_wp)
Input
-
4:
– Real (Kind=nag_wp)
Input
-
On entry: the lower and upper coordinates of the rectangular region respectively, and .
Constraint:
.
-
5:
– Subroutine, supplied by the user.
External Procedure
-
pdef must evaluate the functions
,
,
,
,
,
and
which define the equation at a general point
.
The specification of
pdef is:
Fortran Interface
Real (Kind=nag_wp), Intent (In) |
:: |
x, y |
Real (Kind=nag_wp), Intent (Out) |
:: |
alpha, beta, gamma, delta, epslon, phi, psi |
|
C++ Header Interface
#include <nag.h> extern "C" {
}
|
-
1:
– Real (Kind=nag_wp)
Input
-
2:
– Real (Kind=nag_wp)
Input
-
On entry: the and coordinates of the point at which the coefficients of the partial differential equation are to be evaluated.
-
3:
– Real (Kind=nag_wp)
Output
-
4:
– Real (Kind=nag_wp)
Output
-
5:
– Real (Kind=nag_wp)
Output
-
6:
– Real (Kind=nag_wp)
Output
-
7:
– Real (Kind=nag_wp)
Output
-
8:
– Real (Kind=nag_wp)
Output
-
9:
– Real (Kind=nag_wp)
Output
-
On exit:
alpha,
beta,
gamma,
delta,
epslon,
phi and
psi must be set to the values of
,
,
,
,
,
and
respectively at the point specified by
x and
y.
pdef must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
d03eef is called. Arguments denoted as
Input must
not be changed by this procedure.
Note: pdef should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
d03eef. If your code inadvertently
does return any NaNs or infinities,
d03eef is likely to produce unexpected results.
-
6:
– Subroutine, supplied by the user.
External Procedure
-
bndy must evaluate the functions
,
, and
involved in the boundary conditions.
The specification of
bndy is:
Fortran Interface
Integer, Intent (In) |
:: |
ibnd |
Real (Kind=nag_wp), Intent (In) |
:: |
x, y |
Real (Kind=nag_wp), Intent (Out) |
:: |
a, b, c |
|
C Header Interface
void |
bndy_ (const double *x, const double *y, double *a, double *b, double *c, const Integer *ibnd) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
bndy_ (const double &x, const double &y, double &a, double &b, double &c, const Integer &ibnd) |
}
|
-
1:
– Real (Kind=nag_wp)
Input
-
2:
– Real (Kind=nag_wp)
Input
-
On entry: the and coordinates of the point at which the boundary conditions are to be evaluated.
-
3:
– Real (Kind=nag_wp)
Output
-
4:
– Real (Kind=nag_wp)
Output
-
5:
– Real (Kind=nag_wp)
Output
-
On exit:
a,
b and
c must be set to the values of the functions appearing in the boundary conditions.
-
6:
– Integer
Input
-
On entry: specifies on which boundary the point lies. , , or according as the point lies on the bottom, right, top or left boundary.
bndy must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
d03eef is called. Arguments denoted as
Input must
not be changed by this procedure.
Note: bndy should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
d03eef. If your code inadvertently
does return any NaNs or infinities,
d03eef is likely to produce unexpected results.
-
7:
– Integer
Input
-
8:
– Integer
Input
-
On entry: the number of interior grid points in the
- and
-directions respectively,
and
. If the seven-diagonal equations are to be solved by
d03edf,
and
should preferably be divisible by as high a power of
as possible.
-
9:
– Integer
Input
-
On entry: the first dimension of the array
a and the dimension of the array
rhs as declared in the (sub)program from which
d03eef is called.
Constraint:
if only the seven-diagonal equations are required,
. If a call to this routine is to be followed by a call to
d03edf to solve the seven-diagonal linear equations,
.
Note: this routine only checks the former condition.
d03edf, if called, will check the latter condition.
-
10:
– Real (Kind=nag_wp) array
Output
-
On exit:
, for
and
, contains the seven-diagonal linear equations produced by the discretization described above. If
, the remaining elements are not referenced by the routine, but if
then the array
a can be passed directly to
d03edf, where these elements are used as workspace.
-
11:
– Real (Kind=nag_wp) array
Output
-
On exit: the first
elements contain the right-hand sides of the seven-diagonal linear equations produced by the discretization described above. If
, the remaining elements are not referenced by the routine, but if
then the array
rhs can be passed directly to
d03edf, where these elements are used as workspace.
-
12:
– Character(1)
Input
-
On entry: the type of approximation to be used for the first derivatives which occur in the partial differential equation.
- Central differences are used.
- Upwind differences are used.
Constraint:
or
.
Note: generally speaking, if at least one of the coefficients multiplying the first derivatives (
delta or
epslon as returned by
pdef) are large compared with the coefficients multiplying the second derivatives, then upwind differences may be more appropriate. Upwind differences are less accurate than central differences, but may result in more rapid convergence for strongly convective equations. The easiest test is to try both schemes.
-
13:
– Integer
Input/Output
-
On entry:
ifail must be set to
,
or
to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value
or
is recommended. If message printing is undesirable, then the value
is recommended. Otherwise, the value
is recommended since useful values can be provided in some output arguments even when
on exit.
When the value or is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
Note: in some cases d03eef may return useful information.
-
On entry, .
Constraint: .
On entry,
and
.
Constraint:
lda must be at least
.
On entry, .
Constraint: .
On entry, .
Constraint: or .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
-
Mixed derivative in equation and derivative in boundary condition at bottom boundary. .
Mixed derivative in equation and derivative in boundary condition at bottom left boundary. .
Mixed derivative in equation and derivative in boundary condition at bottom right boundary. .
Mixed derivative in equation and derivative in boundary condition at left boundary. .
Mixed derivative in equation and derivative in boundary condition at right boundary. .
Mixed derivative in equation and derivative in boundary condition at top boundary. .
Mixed derivative in equation and derivative in boundary condition at top left boundary. .
Mixed derivative in equation and derivative in boundary condition at top right boundary. .
-
Null boundary condition at bottom boundary, left end. .
Null boundary condition at bottom boundary, right end. .
Null boundary condition at bottom boundary. .
Null boundary condition at left boundary, bottom end. .
Null boundary condition at left boundary, top end. .
Null boundary condition at left boundary. .
Null boundary condition at right boundary, bottom end. .
Null boundary condition at right boundary, top end. .
Null boundary condition at right boundary. .
Null boundary condition at top boundary, left end. .
Null boundary condition at top boundary, right end. .
Null boundary condition at top boundary. .
-
Equation not elliptic at some point.
-
There is no unique solution with Neumann Boundary conditions.
-
The linear equations were not diagonally dominant.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See
Section 9 in the Introduction to the NAG Library FL Interface for further information.
7
Accuracy
Not applicable.
8
Parallelism and Performance
d03eef is not threaded in any implementation.
If this routine is used as a preprocessor to the multigrid routine
d03edf it should be noted that the rate of convergence of that routine is strongly dependent upon the number of levels in the multigrid scheme, and thus the choice of
ngx and
ngy is very important.
10
Example
The program solves the elliptic partial differential equation
on the unit square
,
, with boundary conditions
- given on and ,
- given on and .
The function and the exact form of the boundary conditions are derived from the exact solution .
The equation is first solved using central differences. Since the coefficients of the first derivatives are large, the linear equations are not diagonally dominated, and convergence is slow. The equation is solved a second time with upwind differences, showing that convergence is more rapid, but the solution is less accurate.
10.1
Program Text
10.2
Program Data
10.3
Program Results