naginterfaces.library.pde.dim2_gen_order2_rectilinear¶
- naginterfaces.library.pde.dim2_gen_order2_rectilinear(ts, tout, dt, tols, tolt, inidom, pdedef, bndary, pdeiv, monitr, opti, optr, comm, itrace, ind, lenrwk=None, leniwk=None, lenlwk=None, data=None, io_manager=None, spiked_sorder='C')[source]¶
dim2_gen_order2_rectilinear
integrates a system of linear or nonlinear, time-dependent partial differential equations (PDEs) in two space dimensions on a rectilinear domain. The method of lines is employed to reduce the PDEs to a system of ordinary differential equations (ODEs) which are solved using a backward differentiation formula (BDF) method. The resulting system of nonlinear equations is solved using a modified Newton method and a BI-CGSTAB iterative linear solver with ILU preconditioning. Local uniform grid refinement is used to improve the accuracy of the solution.dim2_gen_order2_rectilinear
originates from the VLUGR2 package (see Blom and Verwer (1993) and Blom et al. (1996)).For full information please refer to the NAG Library document for d03rb
https://support.nag.com/numeric/nl/nagdoc_30.1/flhtml/d03/d03rbf.html
- Parameters
- tsfloat
The initial value of the independent variable .
- toutfloat
The final value of to which the integration is to be carried out.
- dtfloat, array-like, shape
The initial, minimum and maximum time step sizes respectively.
Specifies the initial time step size to be used on the first entry, i.e., when . If then the default value is used. On subsequent entries (), the value of is not referenced.
Specifies the minimum time step size to be attempted by the integrator. If the default value is used.
Specifies the maximum time step size to be attempted by the integrator. If the default value is used.
- tolsfloat
The space tolerance used in the grid refinement strategy ( in equation (4)). See Further Comments.
- toltfloat
The time tolerance used to determine the time step size ( in equation (7)). See Time Integration.
- inidomcallable (xmin, xmax, ymin, ymax, nx, ny, npts, nrows, nbnds, nbpts, lrow, irow, icol, llbnd, ilbnd, lbnd, ierr) = inidom(maxpts, ierr, data=None)
must specify the base grid in terms of the data structure described in Notes. is not referenced if, on entry, .
Note: the boundaries of the base grid should consist of as many points as are necessary to employ second-order space discretization, i.e., a boundary enclosing the internal part of the domain must include at least grid points including the corners. If Neumann boundary conditions are to be applied the minimum is .
- Parameters
- maxptsint
The maximum number of base grid points allowed by the available workspace.
- ierrint
Will be initialized by
dim2_gen_order2_rectilinear
to some value prior to internal calls to .- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- Returns
- xminfloat
The extents of the virtual grid in the -direction, i.e., the coordinates of the left and right boundaries respectively.
- xmaxfloat
The extents of the virtual grid in the -direction, i.e., the coordinates of the left and right boundaries respectively.
- yminfloat
The extents of the virtual grid in the -direction, i.e., the coordinates of the left and right boundaries respectively.
- ymaxfloat
The extents of the virtual grid in the -direction, i.e., the coordinates of the left and right boundaries respectively.
- nxint
The number of virtual grid points in the - and -direction respectively (including the boundary points).
- nyint
The number of virtual grid points in the - and -direction respectively (including the boundary points).
- nptsint
The total number of points in the base grid. If the required number of points is greater than then must be exited immediately with set to to avoid overwriting memory.
- nrowsint
The total number of rows of the virtual grid that contain base grid points. This is the maximum base row index.
- nbndsint
The total number of physical boundaries and corners in the base grid.
- nbptsint
The total number of boundary points in the base grid.
- lrowint, array-like, shape
, for , must contain the base grid index of the first grid point in base grid row .
- irowint, array-like, shape
, for , must contain the virtual row number that corresponds to base grid row .
- icolint, array-like, shape
, for , must contain the virtual column number that contains base grid point .
- llbndint, array-like, shape
, for , must contain the element of corresponding to the start of the th boundary or corner.
Note: the order of the boundaries and corners in must be first all the boundaries and then all the corners. The end points of a boundary (i.e., the adjacent corner points) must not be included in the list of points on that boundary. Also, if a corner is shared by two pairs of physical boundaries then it has two types and must, therefore, be treated as two corners.
- ilbndint, array-like, shape
, for , must contain the type of the th boundary (or corner), as given in Notes.
- lbndint, array-like, shape
, for , must contain the grid index of the th boundary point. The order of the boundaries is as specified in , but within this restriction the order of the points in is arbitrary.
- ierrint
If the required number of grid points is larger than , must be set to to force a termination of the integration and an immediate return to the calling program with = 3. Otherwise, should remain unchanged.
- pdedefcallable res = pdedef(t, x, y, u, ut, ux, uy, uxx, uxy, uyy, data=None)
must evaluate the functions , for , in equation (1) which define the system of PDEs (i.e., the residuals of the resulting ODE system) at all interior points of the domain.
Values at points on the boundaries of the domain are ignored and will be overwritten by . is called for each subgrid in turn.
- Parameters
- tfloat
The current value of the independent variable .
- xfloat, ndarray, shape
contains the coordinate of the th grid point, for .
- yfloat, ndarray, shape
contains the coordinate of the th grid point, for .
- ufloat, ndarray, shape
contains the value of the th PDE component at the th grid point, for , for .
- utfloat, ndarray, shape
contains the value of for the th PDE component at the th grid point, for , for .
- uxfloat, ndarray, shape
contains the value of for the th PDE component at the th grid point, for , for .
- uyfloat, ndarray, shape
contains the value of for the th PDE component at the th grid point, for , for .
- uxxfloat, ndarray, shape
contains the value of for the th PDE component at the th grid point, for , for .
- uxyfloat, ndarray, shape
contains the value of for the th PDE component at the th grid point, for , for .
- uyyfloat, ndarray, shape
contains the value of for the th PDE component at the th grid point, for , for .
- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- Returns
- resfloat, array-like, shape
must contain the value of , for , at the th grid point, for , although the residuals at boundary points will be ignored (and overwritten later on) and so they need not be specified here.
- bndarycallable res = bndary(t, x, y, u, ut, ux, uy, llbnd, ilbnd, lbnd, res, data=None)
must evaluate the functions , for , in equation (2) which define the boundary conditions at all boundary points of the domain.
Residuals at interior points must not be altered by this function.
- Parameters
- tfloat
The current value of the independent variable .
- xfloat, ndarray, shape
contains the coordinate of the th grid point, for .
- yfloat, ndarray, shape
contains the coordinate of the th grid point, for .
- ufloat, ndarray, shape
contains the value of the th PDE component at the th grid point, for , for .
- utfloat, ndarray, shape
contains the value of for the th PDE component at the th grid point, for , for .
- uxfloat, ndarray, shape
contains the value of for the th PDE component at the th grid point, for , for .
- uyfloat, ndarray, shape
contains the value of for the th PDE component at the th grid point, for , for .
- llbndint, ndarray, shape
, for , contains the element of corresponding to the start of the th boundary (or corner).
- ilbndint, ndarray, shape
, for , contains the type of the th boundary, as given in Notes.
- lbndint, ndarray, shape
, contains the grid index of the th boundary point, where the order of the boundaries is as specified in . Hence the th boundary point has coordinates and , and the corresponding solution values are , for , for .
- resfloat, ndarray, shape
Contains function values returned by .
- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- Returns
- resfloat, array-like, shape
must contain the value of , for , at the th boundary point, for .
Note: elements of corresponding to interior points, i.e., points not included in , must not be altered.
- pdeivcallable u = pdeiv(npde, t, x, y, data=None)
must specify the initial values of the PDE components at all points in the base grid. is not referenced if, on entry, .
- Parameters
- npdeint
The number of PDEs in the system.
- tfloat
The (initial) value of the independent variable .
- xfloat, ndarray, shape
contains the coordinate of the th grid point, for .
- yfloat, ndarray, shape
contains the coordinate of the th grid point, for .
- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- Returns
- ufloat, array-like, shape
must contain the value of the th PDE component at the th grid point, for , for .
- monitrcallable ierr = monitr(npde, t, dt, dtnew, tlast, xmin, ymin, dxb, dyb, lgrid, istruc, lsol, sol, ierr, data=None)
is called by
dim2_gen_order2_rectilinear
at the end of every successful time step, and may be used to examine or print the solution or perform other tasks such as error calculations, particularly at the final time step, indicated by the argument .The input arguments contain information about the grid and solution at all grid levels used.
dim2_gen_order2_rectilinear_extractgrid()
should be called from in order to extract the number of points and their coordinates on a particular grid.can also be used to force an immediate tidy termination of the solution process and return to the calling program.
- Parameters
- npdeint
The number of PDEs in the system.
- tfloat
The current value of the independent variable , i.e., the time at the end of the integration step just completed.
- dtfloat
The current time step size , i.e., the time step size used for the integration step just completed.
- dtnewfloat
The time step size that will be used for the next time step.
- tlastbool
Indicates if intermediate or final time step. for an intermediate step, for the last call to before returning to your program.
- xminfloat
The coordinates of the lower-left corner of the virtual grid.
- yminfloat
The coordinates of the lower-left corner of the virtual grid.
- dxbfloat
The sizes of the base grid spacing in the - and -direction respectively.
- dybfloat
The sizes of the base grid spacing in the - and -direction respectively.
- lgridint, ndarray, shape
Contains pointers to the start of the grid structures in , and must be passed unchanged to
dim2_gen_order2_rectilinear_extractgrid()
in order to extract the grid information.- istrucint, ndarray, shape
Contains the grid structures for each grid level and must be passed unchanged to
dim2_gen_order2_rectilinear_extractgrid()
in order to extract the grid information.- lsolint, ndarray, shape
contains the pointer to the solution in at grid level and time . ( actually contains the array index immediately preceding the start of the solution in .)
- solfloat, ndarray, shape
Contains the solution at time for each grid level in turn, positioned according to . More precisely
represents the th component of the solution at the th grid point in the th level, for , for , for , where is the number of grid points at level (obtainable by a call to
dim2_gen_order2_rectilinear_extractgrid()
).- ierrint
Will be initialized by
dim2_gen_order2_rectilinear
to some value prior to internal calls to .- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- Returns
- ierrint
Should be set to to force a termination of the integration and an immediate return to the calling program with = 4. should remain unchanged otherwise.
- optiint, array-like, shape
May be set to control various options available in the integrator.
All the default options are employed.
The default value of , for , can be obtained by setting .
Specifies the maximum number of grid levels allowed (including the base grid). . The default value is .
Specifies the maximum number of Jacobian evaluations allowed during each nonlinear equations solution. . The default value is .
Specifies the maximum number of Newton iterations in each nonlinear equations solution. . The default value is .
Specifies the maximum number of iterations in each linear equations solution. . The default value is .
- optrfloat, array-like, shape
May be used to specify the optional vectors , and in the space and time monitors (see Further Comments).
If an optional vector is not required then all its components should be set to .
, for , specifies , the approximate maximum absolute value of the th component of , as used in (4) and (7). , for .
, for , specifies , the weighting factors used in the space monitor (see (4)) to indicate the relative importance of the th component of on the space monitor. , for .
, for , specifies , the weighting factors used in the time monitor (see (6)) to indicate the relative importance of the th component of on the time monitor. , for .
- commdict, communication object, modified in place
Communication structure.
On initial entry: need not be set.
- itraceint
The level of trace information required from
dim2_gen_order2_rectilinear
. may take the value , , , or .No output is generated.
Only warning messages are printed.
Output from the underlying solver is printed. This output contains details of the time integration, the nonlinear iteration and the linear solver.
If , is assumed and similarly if , is assumed.
The advisory messages are given in greater detail as increases.
Setting allows you to monitor the progress of the integration without possibly excessive information.
- indint
Must be set to or , alternatively or .
Starts the integration in time. is assumed to be serial.
Continues the integration after an earlier exit from the function. In this case, only the following parameters may be reset between calls to
dim2_gen_order2_rectilinear
: , , , , , , and . is assumed to be serial.Starts the integration in time. is assumed to have been parallelized by you, as described in Parallelism and Performance. In all other respects, this is equivalent to .
Continues the integration after an earlier exit from the function. In this case, only the following parameters may be reset between calls to
dim2_gen_order2_rectangle()
: , , , , , , and . is assumed to have been parallelized by you, as described in Parallelism and Performance. In all other respects, this is equivalent to .- lenrwkNone or int, optional
Note: if this argument is None then a default value will be used, determined as follows: .
The required value of cannot be determined exactly in advance, but a suggested value is
where if and otherwise, and is the expected maximum number of grid points at any one level.
If during the execution the supplied value is found to be too small then the function returns with = 3 and an estimated required size is printed on the current error message unit (see
FileObjManager
).Note: the size of cannot be checked upon initial entry to
dim2_gen_order2_rectilinear
since the number of grid points on the base grid is not known.- leniwkNone or int, optional
Note: if this argument is None then a default value will be used, determined as follows: .
The required value of cannot be determined exactly in advance, but a suggested value is
where is the expected maximum number of grid points at any one level and if and otherwise.
If during the execution the supplied value is found to be too small then the function returns with = 3 and an estimated required size is printed on the current error message unit (see
FileObjManager
).Note: the size of cannot be checked upon initial entry to
dim2_gen_order2_rectilinear
since the number of grid points on the base grid is not known.- lenlwkNone or int, optional
Note: if this argument is None then a default value will be used, determined as follows: .
The required value of cannot be determined exactly in advance, but a suggested value is
where is the expected maximum number of grid points at any one level.
If during the execution the supplied value is found to be too small then the function returns with = 3 and an estimated required size is printed.
Note: the size of cannot be checked upon initial entry to
dim2_gen_order2_rectilinear
since the number of grid points on the base grid is not known.- dataarbitrary, optional
User-communication data for callback functions.
- io_managerFileObjManager, optional
Manager for I/O in this routine.
- spiked_sorderstr, optional
If is spiked (i.e., has unit extent in all but one dimension, or has size ), selects the storage order to associate with it in the NAG Engine:
- spiked_sorder =
row-major storage will be used;
- spiked_sorder =
column-major storage will be used.
Two-dimensional arrays returned from callback functions in this routine must then use the same storage order.
- Returns
- tsfloat
The value of which has been reached. Normally .
- dtfloat, ndarray, shape
contains the time step size for the next time step. and are unchanged or set to their default values if zero on entry.
- indint
, if on input was or , or , if on input was or .
- Raises
- NagValueError
- (errno )
On entry, is not equal to or : .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, and . Note that was reset to default if zero on entry.
Constraint: if , .
- (errno )
On entry, and . Note that was reset to default if zero on entry.
Constraint: if , .
- (errno )
On entry, and too large: and .
- (errno )
On entry, and too small: and .
- (errno )
On entry, .
Constraint: if , .
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, , and .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, , and .
Constraint: if , .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, too small: .
- (errno )
On entry, and .
Constraint: .
- (errno )
Attempted time-step smaller than specified minimum. Check problem formulation in , and . Try increasing for more information.
- (errno )
One or more of the workspace arrays are too small. Try increasing for more information.
- (errno )
Invalid output argument from .
- Warns
- NagAlgorithmicWarning
- (errno )
set to in . Integration completed as far as : .
- (errno )
Integration completed, but maximum number of levels too small for required accuracy.
- Notes
No equivalent traditional C interface for this routine exists in the NAG Library.
dim2_gen_order2_rectilinear
integrates the system of PDEs:where is an arbitrary rectilinear domain, i.e., a domain bounded by perpendicular straight lines. If the domain is rectangular then it is recommended that
dim2_gen_order2_rectangle()
is used.The vector is the set of solution values
and denotes partial differentiation with respect to , and similarly for , etc.
The functions must be supplied by you in . Similarly the initial values of the functions for must be specified at in .
Note that whilst complete generality is offered by the master equations (1),
dim2_gen_order2_rectilinear
is not appropriate for all PDEs. In particular, hyperbolic systems should not be solved using this function. Also, at least one component of must appear in the system of PDEs.The boundary conditions must be supplied by you in in the form
The domain is covered by a uniform coarse base grid specified by you, and nested finer uniform subgrids are subsequently created in regions with high spatial activity. The refinement is controlled using a space monitor which is computed from the current solution and a user-supplied space tolerance . A number of options, e.g., the maximum number of grid levels at any time, and some weighting factors, can be specified in the arrays and . Further details of the refinement strategy can be found in Further Comments.
The system of PDEs and the boundary conditions are discretized in space on each grid using a standard second-order finite difference scheme (centred on the internal domain and one-sided at the boundaries), and the resulting system of ODEs is integrated in time using a second-order, two-step, implicit BDF method with variable step size. The time integration is controlled using a time monitor computed at each grid level from the current solution and a user-supplied time tolerance , and some further optional user-specified weighting factors held in (see Further Comments for details). The time monitor is used to compute a new step size, subject to restrictions on the size of the change between steps, and (optional) user-specified maximum and minimum step sizes held in . The step size is adjusted so that the remaining integration interval is an integer number times . In this way a solution is obtained at .
A modified Newton method is used to solve the nonlinear equations arising from the time integration. You may specify (in ) the maximum number of Newton iterations to be attempted. A Jacobian matrix is calculated at the beginning of each time step. If the Newton process diverges or the maximum number of iterations is exceeded, a new Jacobian is calculated using the most recent iterates and the Newton process is restarted. If convergence is not achieved after the (optional) user-specified maximum number of new Jacobian evaluations, the time step is retried with . The linear systems arising from the Newton iteration are solved using a BI-CGSTAB iterative method, in combination with ILU preconditioning. The maximum number of iterations can be specified by you in .
In order to define the base grid you must first specify a virtual uniform rectangular grid which contains the entire base grid. The position of the virtual grid in physical space is given by the coordinates of its boundaries. The number of points and in the and directions must also be given, corresponding to the number of columns and rows respectively. This is sufficient to determine precisely the coordinates of all virtual grid points. Each virtual grid point is then referred to by integer coordinates , where corresponds to the lower-left corner and corresponds to the upper-right corner. and are also referred to as the virtual column and row indices respectively.
The base grid is then specified with respect to the virtual grid, with each base grid point coinciding with a virtual grid point. Each base grid point must be given an index, starting from , and incrementing row-wise from the leftmost point of the lowest row. Also, each base grid row must be numbered consecutively from the lowest row in the grid, so that row contains grid point .
As an example, consider the domain consisting of the two separate squares shown in Figure [label omitted]. The left-hand diagram shows the virtual grid and its integer coordinates (i.e., its column and row indices), and the right-hand diagram shows the base grid point indices and the base row indices (in brackets).
[figure omitted]
Hence the base grid point with index say is in base row , virtual column 4, and virtual row , i.e., virtual grid integer coordinates ; and the base grid point with index say is in base row , virtual column 2, and virtual row , i.e., virtual grid integer coordinates .
The base grid must then be defined in by specifying the number of base grid rows, the number of base grid points, the number of boundaries, the number of boundary points, and the following integer arrays:
contains the base grid indices of the starting points of the base grid rows;
contains the virtual row numbers of the base grid rows;
contains the virtual column numbers of the base grid points;
contains the grid indices of the boundary edges (without corners) and corner points;
contains the starting elements of the boundaries and corners in .
Finally, contains the types of the boundaries and corners, as follows:
Boundaries:
1 – lower boundary
2 – left boundary
3 – upper boundary
4 – right boundary
External corners ():
12 – lower-left corner
23 – upper-left corner
34 – upper-right corner
41 – lower-right corner
Internal corners ():
21 – lower-left corner
32 – upper-left corner
43 – upper-right corner
14 – lower-right corner
Figure [label omitted] shows the boundary types of a domain with a hole. Notice the logic behind the labelling of the corners: each one includes the types of the two adjacent boundary edges, in a clockwise fashion (outside the domain).
[figure omitted]
As an example, consider the domain shown in Figure [label omitted]. The left-hand diagram shows the physical domain and the right-hand diagram shows the base and virtual grids. The numbers outside the base grid are the indices of the left and rightmost base grid points, and the numbers inside the base grid are the boundary or corner numbers, indicating the order in which the boundaries are stored in .
[figure omitted]
For this example we would
set to
set to
set to
set to
set to the vector
set to the vector
set to the vector
set to the vector
set to the vector
set to the vector
Subgrids are stored internally using the same data structure, and solution information is communicated to you in , and in arrays according to the grid index on the particular level, e.g., and contain the coordinates of grid point , and contains the th solution component at grid point .
The grid data and the solutions at all grid levels are stored in the workspace arrays, along with other information needed for a restart (i.e., a continuation call). It is not intended that you extract the solution from these arrays, indeed the necessary information regarding these arrays is not provided. The user-supplied monitor () should be used to obtain the solution at particular levels and times. is called at the end of every time step, with the last step being identified via the input argument . The function
dim2_gen_order2_rectilinear_extractgrid()
should be called from to obtain grid information at a particular level.Further details of the underlying algorithm can be found in Further Comments and in Blom and Verwer (1993) and Blom et al. (1996) and the references therein.
- References
Blom, J G, Trompert, R A and Verwer, J G, 1996, Algorithm 758. VLUGR2: A vectorizable adaptive grid solver for PDEs in 2D, Trans. Math. Software (22), 302–328
Blom, J G and Verwer, J G, 1993, VLUGR2: A vectorized local uniform grid refinement code for PDEs in 2D, Report NM-R9306, CWI, Amsterdam
Trompert, R A, 1993, Local uniform grid refinement and systems of coupled partial differential equations, Appl. Numer. Maths (12), 331–355
Trompert, R A and Verwer, J G, 1993, Analysis of the implicit Euler local uniform grid refinement method, SIAM J. Sci. Comput. (14), 259–278